(gdb-var-set-format-regexp): New constant.
[emacs.git] / lisp / progmodes / vhdl-mode.el
blob13686695f8ddb33c3e62902067c6dfe9755f08f6
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Authors: Reto Zimmermann <reto@gnu.org>
7 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
8 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
9 ;; Keywords: languages vhdl
10 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
12 (defconst vhdl-version "3.33.6"
13 "VHDL Mode version number.")
15 (defconst vhdl-time-stamp "2005-08-30"
16 "VHDL Mode time stamp for last update.")
18 ;; This file is part of GNU Emacs.
20 ;; GNU Emacs is free software; you can redistribute it and/or modify
21 ;; it under the terms of the GNU General Public License as published by
22 ;; the Free Software Foundation; either version 3, or (at your option)
23 ;; any later version.
25 ;; GNU Emacs is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;; GNU General Public License for more details.
30 ;; You should have received a copy of the GNU General Public License
31 ;; along with GNU Emacs; see the file COPYING. If not, write to the
32 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
33 ;; Boston, MA 02110-1301, USA.
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36 ;;; Commentary:
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;; This package provides an Emacs major mode for editing VHDL code.
40 ;; It includes the following features:
42 ;; - Syntax highlighting
43 ;; - Indentation
44 ;; - Template insertion (electrification)
45 ;; - Insertion of file headers
46 ;; - Insertion of user-specified models
47 ;; - Port translation / testbench generation
48 ;; - Structural composition
49 ;; - Configuration generation
50 ;; - Sensitivity list updating
51 ;; - File browser
52 ;; - Design hierarchy browser
53 ;; - Source file compilation (syntax analysis)
54 ;; - Makefile generation
55 ;; - Code hiding
56 ;; - Word/keyword completion
57 ;; - Block commenting
58 ;; - Code fixing/alignment/beautification
59 ;; - Postscript printing
60 ;; - VHDL'87/'93 and VHDL-AMS supported
61 ;; - Comprehensive menu
62 ;; - Fully customizable
63 ;; - Works under GNU Emacs (recommended) and XEmacs
65 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66 ;; Documentation
68 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
71 ;; Emacs Versions
73 ;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
74 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77 ;; Installation
79 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
81 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
82 ;; or into an arbitrary directory that is added to the load path by the
83 ;; following line in your Emacs start-up file `.emacs':
85 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
87 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
88 ;; directory. Otherwise, byte-compile the source file:
89 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
90 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
92 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
93 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
94 ;; (not required in Emacs 20.X):
96 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
97 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
99 ;; More detailed installation instructions are included in the official
100 ;; VHDL Mode distribution.
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
103 ;; Acknowledgements
105 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
106 ;; and Steve Grout.
108 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
109 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
111 ;; Many thanks to all the users who sent me bug reports and enhancement
112 ;; requests.
113 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
114 ;; enhancement suggestions and the fruitful discussions.
115 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
116 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
118 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
119 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
120 ;; giving me the opportunity to develop this code.
121 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
122 ;; of the Swiss Government.
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126 ;;; Code:
128 ;; XEmacs handling
129 (defconst vhdl-xemacs (string-match "XEmacs" emacs-version)
130 "Non-nil if XEmacs is used.")
131 ;; Emacs 21+ handling
132 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not vhdl-xemacs))
133 "Non-nil if GNU Emacs 21, 22, ... is used.")
134 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not vhdl-xemacs))
135 "Non-nil if GNU Emacs 22, ... is used.")
137 (defvar compilation-file-regexp-alist)
138 (defvar conf-alist)
139 (defvar conf-entry)
140 (defvar conf-key)
141 (defvar ent-alist)
142 (defvar itimer-version)
143 (defvar lazy-lock-defer-contextually)
144 (defvar lazy-lock-defer-on-scrolling)
145 (defvar lazy-lock-defer-on-the-fly)
146 (defvar speedbar-attached-frame)
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150 ;;; Variables
151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
153 ;; help function for user options
154 (defun vhdl-custom-set (variable value &rest functions)
155 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
156 (if (fboundp 'custom-set-default)
157 (custom-set-default variable value)
158 (set-default variable value))
159 (while functions
160 (when (fboundp (car functions)) (funcall (car functions)))
161 (setq functions (cdr functions))))
163 (defun vhdl-widget-directory-validate (widget)
164 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
165 '/' or is empty)."
166 (let ((val (widget-value widget)))
167 (unless (string-match "^\\(\\|.*/\\)$" val)
168 (widget-put widget :error "Invalid directory entry: must end with '/'")
169 widget)))
171 ;; help string for user options
172 (defconst vhdl-name-doc-string "
174 FROM REGEXP is a regular expression matching the original name:
175 \".*\" matches the entire string
176 \"\\(...\\)\" matches a substring
177 TO STRING specifies the string to be inserted as new name:
178 \"\\&\" means substitute entire matched text
179 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
180 Examples:
181 \".*\" \"\\&\" inserts original string
182 \".*\" \"\\&_i\" attaches \"_i\" to original string
183 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
184 \".*\" \"foo\" inserts constant string \"foo\"
185 \".*\" \"\" inserts empty string")
187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
188 ;; User variables
190 (defgroup vhdl nil
191 "Customizations for VHDL Mode."
192 :prefix "vhdl-"
193 :group 'languages
194 ; :version "21.2" ; comment out for XEmacs
197 (defgroup vhdl-mode nil
198 "Customizations for modes."
199 :group 'vhdl)
201 (defcustom vhdl-electric-mode t
202 "*Non-nil enables electrification (automatic template generation).
203 If nil, template generators can still be invoked through key bindings and
204 menu. Is indicated in the modeline by \"/e\" after the mode name and can be
205 toggled by `\\[vhdl-electric-mode]'."
206 :type 'boolean
207 :group 'vhdl-mode)
209 (defcustom vhdl-stutter-mode t
210 "*Non-nil enables stuttering.
211 Is indicated in the modeline by \"/s\" after the mode name and can be toggled
212 by `\\[vhdl-stutter-mode]'."
213 :type 'boolean
214 :group 'vhdl-mode)
216 (defcustom vhdl-indent-tabs-mode nil
217 "*Non-nil means indentation can insert tabs.
218 Overrides local variable `indent-tabs-mode'."
219 :type 'boolean
220 :group 'vhdl-mode)
223 (defgroup vhdl-compile nil
224 "Customizations for compilation."
225 :group 'vhdl)
227 (defcustom vhdl-compiler-alist
229 ;; Cadence Leapfrog: cv -file test.vhd
230 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
231 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
232 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
233 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
234 ("\\1/entity" "\\2/\\1" "\\1/configuration"
235 "\\1/package" "\\1/body" downcase))
236 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
237 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
238 ;; (PLL_400X_TOP) is not declared [10.3].
239 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
240 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
241 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
242 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
243 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
244 ;; Ikos Voyager: analyze test.vhd
245 ;; analyze test.vhd
246 ;; E L4/C5: this library unit is inaccessible
247 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
248 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
249 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
250 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
251 nil)
252 ;; ModelSim, Model Technology: vcom test.vhd
253 ;; ERROR: test.vhd(14): Unknown identifier: positiv
254 ;; WARNING[2]: test.vhd(85): Possible infinite loop
255 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
256 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
257 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
258 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
259 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
260 "\\1/_primary.dat" "\\1/body.dat" downcase))
261 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
262 ;; test.vhd:34: error message
263 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
264 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
265 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
266 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
267 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
268 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
269 ;; ERROR: test.vhd(24): near "dnd": expecting: END
270 ;; WARNING[4]: test.vhd(30): A space is required between ...
271 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
272 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
273 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
274 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
275 "\\1/_primary.dat" "\\1/body.dat" downcase))
276 ;; Savant: scram -publish-cc test.vhd
277 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
278 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
279 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
280 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
281 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
282 "\\1_config.vhdl" "\\1_package.vhdl"
283 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
284 ;; Simili: vhdlp -work test.vhd
285 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
286 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
287 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
288 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
289 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
290 "\\1/prim.var" "\\1/_body.var" downcase))
291 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
292 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
293 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
294 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
295 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
296 nil)
297 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
298 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
299 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
300 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
301 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
302 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
303 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
304 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
305 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
306 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
307 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
308 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
309 ;; Synplify:
310 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
311 ("Synplify" "n/a" "n/a" "make" "-f \\1"
312 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
313 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
314 nil)
315 ;; Vantage: 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 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
319 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
320 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
321 ("^ *Compiling \"\\(.+\\)\" " 1)
322 nil)
323 ;; VeriBest: vc vhdl test.vhd
324 ;; (no file name printed out!)
325 ;; 32: Z <= A and BitA ;
326 ;; ^^^^
327 ;; [Error] Name BITA is unknown
328 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
329 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
330 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
331 nil)
332 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
333 ;; Compiling "test.vhd" line 1...
334 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
335 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
336 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
337 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
338 ("^ *Compiling \"\\(.+\\)\" " 1)
339 nil)
341 "*List of available VHDL compilers and their properties.
342 Each list entry specifies the following items for a compiler:
343 Compiler:
344 Compiler name : name used in option `vhdl-compiler' to choose compiler
345 Compile command : command used for source file compilation
346 Compile options : compile options (\"\\1\" inserts library name)
347 Make command : command used for compilation using a Makefile
348 Make options : make options (\"\\1\" inserts Makefile name)
349 Generate Makefile: use built-in function or command to generate a Makefile
350 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
351 Library command : command to create library directory \(\"\\1\" inserts
352 library directory, \"\\2\" inserts library name)
353 Compile directory: where compilation is run and the Makefile is placed
354 Library directory: directory of default library
355 Makefile name : name of Makefile (default is \"Makefile\")
356 ID string : compiler identification string (see `vhdl-project-alist')
357 Error message:
358 Regexp : regular expression to match error messages (*)
359 File subexp index: index of subexpression that matches the file name
360 Line subexp index: index of subexpression that matches the line number
361 Column subexp idx: index of subexpression that matches the column number
362 File message:
363 Regexp : regular expression to match a file name message
364 File subexp index: index of subexpression that matches the file name
365 Unit-to-file name mapping: mapping of library unit names to names of files
366 generated by the compiler (used for Makefile generation)
367 To string : string a name is mapped to (\"\\1\" inserts the unit name,
368 \"\\2\" inserts the entity name for architectures)
369 Case adjustment : adjust case of inserted unit names
371 \(*) The regular expression must match the error message starting from the
372 beginning of the line (but not necessarily to the end of the line).
374 Compile options allows insertion of the library name (see `vhdl-project-alist')
375 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
377 For Makefile generation, the built-in function can be used (requires
378 specification of the unit-to-file name mapping). Alternatively, an
379 external command can be specified. Work directory allows specification of
380 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
381 used for Makefile generation). To use another library name than \"work\",
382 customize `vhdl-project-alist'. The library command is inserted in Makefiles
383 to automatically create the library directory if not existent.
385 Compile options, compile directory, library directory, and Makefile name are
386 overwritten by the project settings if a project is defined (see
387 `vhdl-project-alist'). Directory paths are relative to the source file
388 directory.
390 Some compilers do not include the file name in the error message, but print
391 out a file name message in advance. In this case, set \"File Subexp Index\"
392 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
393 If no file name at all is printed out, set both \"File Message\" entries to 0
394 \(a default file name message will be printed out instead, does not work in
395 XEmacs).
397 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
398 assigning its name to option `vhdl-compiler'.
400 Please send any missing or erroneous compiler properties to the maintainer for
401 updating.
403 NOTE: Activate new error and file message regexps and reflect the new setting
404 in the choice list of option `vhdl-compiler' by restarting Emacs."
405 :type '(repeat
406 (list :tag "Compiler" :indent 2
407 (string :tag "Compiler name ")
408 (string :tag "Compile command ")
409 (string :tag "Compile options " "-work \\1")
410 (string :tag "Make command " "make")
411 (string :tag "Make options " "-f \\1")
412 (choice :tag "Generate Makefile "
413 (const :tag "Built-in function" nil)
414 (string :tag "Command" "vmake \\2 > \\1"))
415 (string :tag "Library command " "mkdir \\1")
416 (directory :tag "Compile directory "
417 :validate vhdl-widget-directory-validate "./")
418 (directory :tag "Library directory "
419 :validate vhdl-widget-directory-validate "work/")
420 (file :tag "Makefile name " "Makefile")
421 (string :tag "ID string ")
422 (list :tag "Error message" :indent 4
423 (regexp :tag "Regexp ")
424 (integer :tag "File subexp index")
425 (integer :tag "Line subexp index")
426 (integer :tag "Column subexp idx"))
427 (list :tag "File message" :indent 4
428 (regexp :tag "Regexp ")
429 (integer :tag "File subexp index"))
430 (choice :tag "Unit-to-file name mapping"
431 :format "%t: %[Value Menu%] %v\n"
432 (const :tag "Not defined" nil)
433 (list :tag "To string" :indent 4
434 (string :tag "Entity " "\\1.vhd")
435 (string :tag "Architecture " "\\2_\\1.vhd")
436 (string :tag "Configuration " "\\1.vhd")
437 (string :tag "Package " "\\1.vhd")
438 (string :tag "Package Body " "\\1_body.vhd")
439 (choice :tag "Case adjustment "
440 (const :tag "None" identity)
441 (const :tag "Upcase" upcase)
442 (const :tag "Downcase" downcase))))))
443 :set (lambda (variable value)
444 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
445 :group 'vhdl-compile)
447 (defcustom vhdl-compiler "ModelSim"
448 "*Specifies the VHDL compiler to be used for syntax analysis.
449 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
450 :type (let ((alist vhdl-compiler-alist) list)
451 (while alist
452 (setq list (cons (list 'const (caar alist)) list))
453 (setq alist (cdr alist)))
454 (append '(choice) (nreverse list)))
455 :group 'vhdl-compile)
457 (defcustom vhdl-compile-use-local-error-regexp t
458 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
459 In this case, only error message regexps for VHDL compilers are active if
460 compilation is started from a VHDL buffer. Otherwise, the error message
461 regexps are appended to the predefined global regexps, and all regexps are
462 active all the time. Note that by doing that, the predefined global regexps
463 might result in erroneous parsing of error messages for some VHDL compilers.
465 NOTE: Activate the new setting by restarting Emacs."
466 :type 'boolean
467 :group 'vhdl-compile)
469 (defcustom vhdl-makefile-generation-hook nil
470 "*Functions to run at the end of Makefile generation.
471 Allows to insert user specific parts into a Makefile.
473 Example:
474 \(lambda nil
475 \(re-search-backward \"^# Rule for compiling entire design\")
476 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
477 :type 'hook
478 :group 'vhdl-compile)
480 (defcustom vhdl-default-library "work"
481 "*Name of default library.
482 Is overwritten by project settings if a project is active."
483 :type 'string
484 :group 'vhdl-compile)
487 (defgroup vhdl-project nil
488 "Customizations for projects."
489 :group 'vhdl)
491 (defcustom vhdl-project-alist
492 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
493 "~/example1/" ("src/system/" "src/components/") ""
494 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
495 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
496 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
497 ("Example 2" "Individual source files, multiple compilers in different directories"
498 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
499 nil "\\1/" "work" "\\1/work/" "Makefile" "")
500 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
501 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
502 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
503 -------------------------------------------------------------------------------
504 -- This is a multi-line project description
505 -- that can be used as a project dependent part of the file header.
507 "*List of projects and their properties.
508 Name : name used in option `vhdl-project' to choose project
509 Title : title of project (single-line string)
510 Default directory: default project directory (absolute path)
511 Sources : a) source files : path + \"/\" + file name
512 b) directory : path + \"/\"
513 c) directory tree: \"-r \" + path + \"/\"
514 Exclude regexp : matches file/directory names to be excluded as sources
515 Compile options : project-specific options for each compiler
516 Compiler name : name of compiler for which these options are valid
517 Compile options: project-specific compiler options
518 (\"\\1\" inserts library name, \"\\2\" default options)
519 Make options: project-specific make options
520 (\"\\1\" inserts Makefile name, \"\\2\" default options)
521 Exceptions : file-specific exceptions
522 File name regexp: matches file names for which exceptions are valid
523 - Options : file-specific compiler options string
524 (\"\\1\" inserts library name, \"\\2\" default options,
525 \"\\3\" project-specific options)
526 - Do not compile: do not compile this file (in Makefile)
527 Compile directory: where compilation is run and the Makefile is placed
528 \(\"\\1\" inserts compiler ID string)
529 Library name : name of library (default is \"work\")
530 Library directory: path to library (\"\\1\" inserts compiler ID string)
531 Makefile name : name of Makefile
532 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
533 Description : description of project (multi-line string)
535 Project title and description are used to insert into the file header (see
536 option `vhdl-file-header').
538 The default directory must have an absolute path (use `M-TAB' for completion).
539 All other paths can be absolute or relative to the default directory. All
540 paths must end with '/'.
542 The design units found in the sources (files and directories) are shown in the
543 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
544 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
545 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
546 specified, the default directory is taken as source directory. Otherwise,
547 the default directory is only taken as source directory if there is a sources
548 entry with the empty string or \"./\". Exclude regexp allows to filter out
549 specific file and directory names from the list of sources (e.g. CVS
550 directories).
552 Files are compiled in the compile directory. Makefiles are also placed into
553 the compile directory. Library directory specifies which directory the
554 compiler compiles into (used to generate the Makefile).
556 Since different compile/library directories and Makefiles may exist for
557 different compilers within one project, these paths and names allow the
558 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
559 Compile options, compile directory, library directory, and Makefile name
560 overwrite the settings of the current compiler.
562 File-specific compiler options (highest priority) overwrite project-specific
563 options which overwrite default options (lowest priority). Lower priority
564 options can be inserted in higher priority options. This allows to reuse
565 default options (e.g. \"-file\") in project- or file-specific options (e.g.
566 \"-93 -file\").
568 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
569 by restarting Emacs."
570 :type `(repeat
571 (list :tag "Project" :indent 2
572 (string :tag "Name ")
573 (string :tag "Title ")
574 (directory :tag "Default directory"
575 :validate vhdl-widget-directory-validate
576 ,(abbreviate-file-name default-directory))
577 (repeat :tag "Sources " :indent 4
578 (directory :format " %v" "./"))
579 (regexp :tag "Exclude regexp ")
580 (repeat
581 :tag "Compile options " :indent 4
582 (list :tag "Compiler" :indent 6
583 ,(let ((alist vhdl-compiler-alist) list)
584 (while alist
585 (setq list (cons (list 'const (caar alist)) list))
586 (setq alist (cdr alist)))
587 (append '(choice :tag "Compiler name")
588 (nreverse list)))
589 (string :tag "Compile options" "\\2")
590 (string :tag "Make options " "\\2")
591 (repeat
592 :tag "Exceptions " :indent 8
593 (cons :format "%v"
594 (regexp :tag "File name regexp ")
595 (choice :format "%[Value Menu%] %v"
596 (string :tag "Options" "\\3")
597 (const :tag "Do not compile" nil))))))
598 (directory :tag "Compile directory"
599 :validate vhdl-widget-directory-validate "./")
600 (string :tag "Library name " "work")
601 (directory :tag "Library directory"
602 :validate vhdl-widget-directory-validate "work/")
603 (file :tag "Makefile name " "Makefile")
604 (string :tag "Description: (type `C-j' for newline)"
605 :format "%t\n%v\n")))
606 :set (lambda (variable value)
607 (vhdl-custom-set variable value
608 'vhdl-update-mode-menu
609 'vhdl-speedbar-refresh))
610 :group 'vhdl-project)
612 (defcustom vhdl-project nil
613 "*Specifies the default for the current project.
614 Select a project name from the ones defined in option `vhdl-project-alist'.
615 Is used to determine the project title and description to be inserted in file
616 headers and the source files/directories to be scanned in the hierarchy
617 browser. The current project can also be changed temporarily in the menu."
618 :type (let ((alist vhdl-project-alist) list)
619 (while alist
620 (setq list (cons (list 'const (caar alist)) list))
621 (setq alist (cdr alist)))
622 (append '(choice (const :tag "None" nil) (const :tag "--"))
623 (nreverse list)))
624 :group 'vhdl-project)
626 (defcustom vhdl-project-file-name '("\\1.prj")
627 "*List of file names/paths for importing/exporting project setups.
628 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
629 replaced by the user name (allows to have user-specific project setups).
630 The first entry is used as file name to import/export individual project
631 setups. All entries are used to automatically import project setups at
632 startup (see option `vhdl-project-auto-load'). Projects loaded from the
633 first entry are automatically made current. Hint: specify local project
634 setups in first entry, global setups in following entries; loading a local
635 project setup will make it current, while loading the global setups
636 is done without changing the current project.
637 Names can also have an absolute path (i.e. project setups can be stored
638 in global directories)."
639 :type '(repeat (string :tag "File name" "\\1.prj"))
640 :group 'vhdl-project)
642 (defcustom vhdl-project-auto-load '(startup)
643 "*Automatically load project setups from files.
644 All project setup files that match the file names specified in option
645 `vhdl-project-file-name' are automatically loaded. The project of the
646 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
647 entry is activated.
648 A project setup file can be obtained by exporting a project (see menu).
649 At startup: project setup file is loaded at Emacs startup"
650 :type '(set (const :tag "At startup" startup))
651 :group 'vhdl-project)
653 (defcustom vhdl-project-sort t
654 "*Non-nil means projects are displayed in alphabetical order."
655 :type 'boolean
656 :group 'vhdl-project)
659 (defgroup vhdl-style nil
660 "Customizations for coding styles."
661 :group 'vhdl
662 :group 'vhdl-template
663 :group 'vhdl-port
664 :group 'vhdl-compose)
666 (defcustom vhdl-standard '(87 nil)
667 "*VHDL standards used.
668 Basic standard:
669 VHDL'87 : IEEE Std 1076-1987
670 VHDL'93 : IEEE Std 1076-1993
671 Additional standards:
672 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
673 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
675 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
676 \"Activate Options\"."
677 :type '(list (choice :tag "Basic standard"
678 (const :tag "VHDL'87" 87)
679 (const :tag "VHDL'93" 93))
680 (set :tag "Additional standards" :indent 2
681 (const :tag "VHDL-AMS" ams)
682 (const :tag "Math packages" math)))
683 :set (lambda (variable value)
684 (vhdl-custom-set variable value
685 'vhdl-template-map-init
686 'vhdl-mode-abbrev-table-init
687 'vhdl-template-construct-alist-init
688 'vhdl-template-package-alist-init
689 'vhdl-update-mode-menu
690 'vhdl-words-init 'vhdl-font-lock-init))
691 :group 'vhdl-style)
693 (defcustom vhdl-basic-offset 2
694 "*Amount of basic offset used for indentation.
695 This value is used by + and - symbols in `vhdl-offsets-alist'."
696 :type 'integer
697 :group 'vhdl-style)
699 (defcustom vhdl-upper-case-keywords nil
700 "*Non-nil means convert keywords to upper case.
701 This is done when typed or expanded or by the fix case functions."
702 :type 'boolean
703 :set (lambda (variable value)
704 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
705 :group 'vhdl-style)
707 (defcustom vhdl-upper-case-types nil
708 "*Non-nil means convert standardized types to upper case.
709 This is done when expanded or by the fix case functions."
710 :type 'boolean
711 :set (lambda (variable value)
712 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
713 :group 'vhdl-style)
715 (defcustom vhdl-upper-case-attributes nil
716 "*Non-nil means convert standardized attributes to upper case.
717 This is done when expanded or by the fix case functions."
718 :type 'boolean
719 :set (lambda (variable value)
720 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
721 :group 'vhdl-style)
723 (defcustom vhdl-upper-case-enum-values nil
724 "*Non-nil means convert standardized enumeration values to upper case.
725 This is done when expanded or by the fix case functions."
726 :type 'boolean
727 :set (lambda (variable value)
728 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
729 :group 'vhdl-style)
731 (defcustom vhdl-upper-case-constants t
732 "*Non-nil means convert standardized constants to upper case.
733 This is done when expanded."
734 :type 'boolean
735 :set (lambda (variable value)
736 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
737 :group 'vhdl-style)
739 (defcustom vhdl-use-direct-instantiation 'standard
740 "*Non-nil means use VHDL'93 direct component instantiation.
741 Never : never
742 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
743 Always : always"
744 :type '(choice (const :tag "Never" never)
745 (const :tag "Standard" standard)
746 (const :tag "Always" always))
747 :group 'vhdl-style)
750 (defgroup vhdl-naming nil
751 "Customizations for naming conventions."
752 :group 'vhdl)
754 (defcustom vhdl-entity-file-name '(".*" . "\\&")
755 (concat
756 "*Specifies how the entity file name is obtained.
757 The entity file name can be obtained by modifying the entity name (e.g.
758 attaching or stripping off a substring). The file extension is automatically
759 taken from the file name of the current buffer."
760 vhdl-name-doc-string)
761 :type '(cons (regexp :tag "From regexp")
762 (string :tag "To string "))
763 :group 'vhdl-naming
764 :group 'vhdl-compose)
766 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
767 (concat
768 "*Specifies how the architecture file name is obtained.
769 The architecture file name can be obtained by modifying the entity
770 and/or architecture name (e.g. attaching or stripping off a substring). The
771 file extension is automatically taken from the file name of the current
772 buffer. The string that is matched against the regexp is the concatenation
773 of the entity and the architecture name separated by a space. This gives
774 access to both names (see default setting as example)."
775 vhdl-name-doc-string)
776 :type '(cons (regexp :tag "From regexp")
777 (string :tag "To string "))
778 :group 'vhdl-naming
779 :group 'vhdl-compose)
781 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
782 (concat
783 "*Specifies how the configuration file name is obtained.
784 The configuration file name can be obtained by modifying the configuration
785 name (e.g. attaching or stripping off a substring). The file extension is
786 automatically taken from the file name of the current buffer."
787 vhdl-name-doc-string)
788 :type '(cons (regexp :tag "From regexp")
789 (string :tag "To string "))
790 :group 'vhdl-naming
791 :group 'vhdl-compose)
793 (defcustom vhdl-package-file-name '(".*" . "\\&")
794 (concat
795 "*Specifies how the package file name is obtained.
796 The package file name can be obtained by modifying the package name (e.g.
797 attaching or stripping off a substring). The file extension is automatically
798 taken from the file name of the current buffer. Package files can be created
799 in a different directory by prepending a relative or absolute path to the
800 file name."
801 vhdl-name-doc-string)
802 :type '(cons (regexp :tag "From regexp")
803 (string :tag "To string "))
804 :group 'vhdl-naming
805 :group 'vhdl-compose)
807 (defcustom vhdl-file-name-case 'identity
808 "*Specifies how to change case for obtaining file names.
809 When deriving a file name from a VHDL unit name, case can be changed as
810 follows:
811 As Is: case is not changed (taken as is)
812 Lower Case: whole name is changed to lower case
813 Upper Case: whole name is changed to upper case
814 Capitalize: first letter of each word in name is capitalized"
815 :type '(choice (const :tag "As Is" identity)
816 (const :tag "Lower Case" downcase)
817 (const :tag "Upper Case" upcase)
818 (const :tag "Capitalize" capitalize))
819 :group 'vhdl-naming
820 :group 'vhdl-compose)
823 (defgroup vhdl-template nil
824 "Customizations for electrification."
825 :group 'vhdl)
827 (defcustom vhdl-electric-keywords '(vhdl user)
828 "*Type of keywords for which electrification is enabled.
829 VHDL keywords: invoke built-in templates
830 User keywords: invoke user models (see option `vhdl-model-alist')"
831 :type '(set (const :tag "VHDL keywords" vhdl)
832 (const :tag "User model keywords" user))
833 :set (lambda (variable value)
834 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
835 :group 'vhdl-template)
837 (defcustom vhdl-optional-labels 'process
838 "*Constructs for which labels are to be queried.
839 Template generators prompt for optional labels for:
840 None : no constructs
841 Processes only: processes only (also procedurals in VHDL-AMS)
842 All constructs: all constructs with optional labels and keyword END"
843 :type '(choice (const :tag "None" none)
844 (const :tag "Processes only" process)
845 (const :tag "All constructs" all))
846 :group 'vhdl-template)
848 (defcustom vhdl-insert-empty-lines 'unit
849 "*Specifies whether to insert empty lines in some templates.
850 This improves readability of code. Empty lines are inserted in:
851 None : no constructs
852 Design units only: entities, architectures, configurations, packages only
853 All constructs : also all constructs with BEGIN...END parts
855 Replaces option `vhdl-additional-empty-lines'."
856 :type '(choice (const :tag "None" none)
857 (const :tag "Design units only" unit)
858 (const :tag "All constructs" all))
859 :group 'vhdl-template
860 :group 'vhdl-port
861 :group 'vhdl-compose)
863 (defcustom vhdl-argument-list-indent nil
864 "*Non-nil means indent argument lists relative to opening parenthesis.
865 That is, argument, association, and port lists start on the same line as the
866 opening parenthesis and subsequent lines are indented accordingly.
867 Otherwise, lists start on a new line and are indented as normal code."
868 :type 'boolean
869 :group 'vhdl-template
870 :group 'vhdl-port
871 :group 'vhdl-compose)
873 (defcustom vhdl-association-list-with-formals t
874 "*Non-nil means write association lists with formal parameters.
875 Templates prompt for formal and actual parameters (ports/generics).
876 When pasting component instantiations, formals are included.
877 If nil, only a list of actual parameters is entered."
878 :type 'boolean
879 :group 'vhdl-template
880 :group 'vhdl-port
881 :group 'vhdl-compose)
883 (defcustom vhdl-conditions-in-parenthesis nil
884 "*Non-nil means place parenthesis around condition expressions."
885 :type 'boolean
886 :group 'vhdl-template)
888 (defcustom vhdl-zero-string "'0'"
889 "*String to use for a logic zero."
890 :type 'string
891 :group 'vhdl-template)
893 (defcustom vhdl-one-string "'1'"
894 "*String to use for a logic one."
895 :type 'string
896 :group 'vhdl-template)
899 (defgroup vhdl-header nil
900 "Customizations for file header."
901 :group 'vhdl-template
902 :group 'vhdl-compose)
904 (defcustom vhdl-file-header "\
905 -------------------------------------------------------------------------------
906 -- Title : <title string>
907 -- Project : <project>
908 -------------------------------------------------------------------------------
909 -- File : <filename>
910 -- Author : <author>
911 -- Company : <company>
912 -- Created : <date>
913 -- Last update: <date>
914 -- Platform : <platform>
915 -- Standard : <standard>
916 <projectdesc>-------------------------------------------------------------------------------
917 -- Description: <cursor>
918 <copyright>-------------------------------------------------------------------------------
919 -- Revisions :
920 -- Date Version Author Description
921 -- <date> 1.0 <login>\tCreated
922 -------------------------------------------------------------------------------
925 "*String or file to insert as file header.
926 If the string specifies an existing file name, the contents of the file is
927 inserted, otherwise the string itself is inserted as file header.
928 Type `C-j' for newlines.
929 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
930 if the header needs to be version controlled.
932 The following keywords for template generation are supported:
933 <filename> : replaced by the name of the buffer
934 <author> : replaced by the user name and email address
935 \(`user-full-name',`mail-host-address', `user-mail-address')
936 <login> : replaced by user login name (`user-login-name')
937 <company> : replaced by contents of option `vhdl-company-name'
938 <date> : replaced by the current date
939 <year> : replaced by the current year
940 <project> : replaced by title of current project (`vhdl-project')
941 <projectdesc> : replaced by description of current project (`vhdl-project')
942 <copyright> : replaced by copyright string (`vhdl-copyright-string')
943 <platform> : replaced by contents of option `vhdl-platform-spec'
944 <standard> : replaced by the VHDL language standard(s) used
945 <... string> : replaced by a queried string (\"...\" is the prompt word)
946 <title string>: replaced by file title in automatically generated files
947 <cursor> : final cursor position
949 The (multi-line) project description <projectdesc> can be used as a project
950 dependent part of the file header and can also contain the above keywords."
951 :type 'string
952 :group 'vhdl-header)
954 (defcustom vhdl-file-footer ""
955 "*String or file to insert as file footer.
956 If the string specifies an existing file name, the contents of the file is
957 inserted, otherwise the string itself is inserted as file footer (i.e. at
958 the end of the file).
959 Type `C-j' for newlines.
960 The same keywords as in option `vhdl-file-header' can be used."
961 :type 'string
962 :group 'vhdl-header)
964 (defcustom vhdl-company-name ""
965 "*Name of company to insert in file header.
966 See option `vhdl-file-header'."
967 :type 'string
968 :group 'vhdl-header)
970 (defcustom vhdl-copyright-string "\
971 -------------------------------------------------------------------------------
972 -- Copyright (c) <year> <company>
974 "*Copyright string to insert in file header.
975 Can be multi-line string (type `C-j' for newline) and contain other file
976 header keywords (see option `vhdl-file-header')."
977 :type 'string
978 :group 'vhdl-header)
980 (defcustom vhdl-platform-spec ""
981 "*Specification of VHDL platform to insert in file header.
982 The platform specification should contain names and versions of the
983 simulation and synthesis tools used.
984 See option `vhdl-file-header'."
985 :type 'string
986 :group 'vhdl-header)
988 (defcustom vhdl-date-format "%Y-%m-%d"
989 "*Specifies the date format to use in the header.
990 This string is passed as argument to the command `format-time-string'.
991 For more information on format strings, see the documentation for the
992 `format-time-string' command (C-h f `format-time-string')."
993 :type 'string
994 :group 'vhdl-header)
996 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
997 "*Prefix string of modification date in VHDL file header.
998 If actualization of the modification date is called (menu,
999 `\\[vhdl-template-modify]'), this string is searched and the rest
1000 of the line replaced by the current date."
1001 :type 'string
1002 :group 'vhdl-header)
1004 (defcustom vhdl-modify-date-on-saving t
1005 "*Non-nil means update the modification date when the buffer is saved.
1006 Calls function `\\[vhdl-template-modify]').
1008 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1009 \"Activate Options\"."
1010 :type 'boolean
1011 :group 'vhdl-header)
1014 (defgroup vhdl-sequential-process nil
1015 "Customizations for sequential processes."
1016 :group 'vhdl-template)
1018 (defcustom vhdl-reset-kind 'async
1019 "*Specifies which kind of reset to use in sequential processes."
1020 :type '(choice (const :tag "None" none)
1021 (const :tag "Synchronous" sync)
1022 (const :tag "Asynchronous" async))
1023 :group 'vhdl-sequential-process)
1025 (defcustom vhdl-reset-active-high nil
1026 "*Non-nil means reset in sequential processes is active high.
1027 Otherwise, reset is active low."
1028 :type 'boolean
1029 :group 'vhdl-sequential-process)
1031 (defcustom vhdl-clock-rising-edge t
1032 "*Non-nil means rising edge of clock triggers sequential processes.
1033 Otherwise, falling edge triggers."
1034 :type 'boolean
1035 :group 'vhdl-sequential-process)
1037 (defcustom vhdl-clock-edge-condition 'standard
1038 "*Syntax of the clock edge condition.
1039 Standard: \"clk'event and clk = '1'\"
1040 Function: \"rising_edge(clk)\""
1041 :type '(choice (const :tag "Standard" standard)
1042 (const :tag "Function" function))
1043 :group 'vhdl-sequential-process)
1045 (defcustom vhdl-clock-name ""
1046 "*Name of clock signal to use in templates."
1047 :type 'string
1048 :group 'vhdl-sequential-process)
1050 (defcustom vhdl-reset-name ""
1051 "*Name of reset signal to use in templates."
1052 :type 'string
1053 :group 'vhdl-sequential-process)
1056 (defgroup vhdl-model nil
1057 "Customizations for user models."
1058 :group 'vhdl)
1060 (defcustom vhdl-model-alist
1061 '(("Example Model"
1062 "<label> : process (<clock>, <reset>)
1063 begin -- process <label>
1064 if <reset> = '0' then -- asynchronous reset (active low)
1065 <cursor>
1066 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1067 if <enable> = '1' then -- synchronous load
1069 end if;
1070 end if;
1071 end process <label>;"
1072 "e" ""))
1073 "*List of user models.
1074 VHDL models (templates) can be specified by the user in this list. They can be
1075 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1076 electrification (i.e. overriding existing or creating new keywords, see
1077 option `vhdl-electric-keywords').
1078 Name : name of model (string of words and spaces)
1079 String : string or name of file to be inserted as model (newline: `C-j')
1080 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1081 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1082 Keyword : keyword to invoke model
1084 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1085 A prompt that appears several times is queried once and replaced throughout
1086 the model. Special prompts are:
1087 <clock> : name specified in `vhdl-clock-name' (if not empty)
1088 <reset> : name specified in `vhdl-reset-name' (if not empty)
1089 <cursor>: final cursor position
1090 File header prompts (see variable `vhdl-file-header') are automatically
1091 replaced, so that user models can also be used to insert different types of
1092 headers.
1094 If the string specifies an existing file name, the contents of the file is
1095 inserted, otherwise the string itself is inserted.
1096 The code within the models should be correctly indented.
1097 Type `C-j' for newlines.
1099 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1100 \"Activate Options\"."
1101 :type '(repeat (list :tag "Model" :indent 2
1102 (string :tag "Name ")
1103 (string :tag "String : (type `C-j' for newline)"
1104 :format "%t\n%v")
1105 (sexp :tag "Key binding" x)
1106 (string :tag "Keyword " :format "%t: %v\n")))
1107 :set (lambda (variable value)
1108 (vhdl-custom-set variable value
1109 'vhdl-model-map-init
1110 'vhdl-model-defun
1111 'vhdl-mode-abbrev-table-init
1112 'vhdl-update-mode-menu))
1113 :group 'vhdl-model)
1116 (defgroup vhdl-compose nil
1117 "Customizations for structural composition."
1118 :group 'vhdl)
1120 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1121 (concat
1122 "*Specifies how the component architecture name is obtained.
1123 The component architecture name can be obtained by modifying the entity name
1124 \(e.g. attaching or stripping off a substring).
1125 If TO STRING is empty, the architecture name is queried."
1126 vhdl-name-doc-string)
1127 :type '(cons (regexp :tag "From regexp")
1128 (string :tag "To string "))
1129 :group 'vhdl-compose)
1131 (defcustom vhdl-compose-configuration-name
1132 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1133 (concat
1134 "*Specifies how the configuration name is obtained.
1135 The configuration name can be obtained by modifying the entity and/or
1136 architecture name (e.g. attaching or stripping off a substring). The string
1137 that is matched against the regexp is the concatenation of the entity and the
1138 architecture name separated by a space. This gives access to both names (see
1139 default setting as example)."
1140 vhdl-name-doc-string)
1141 :type '(cons (regexp :tag "From regexp")
1142 (string :tag "To string "))
1143 :group 'vhdl-compose)
1145 (defcustom vhdl-components-package-name
1146 '((".*" . "\\&_components") . "components")
1147 (concat
1148 "*Specifies how the name for the components package is obtained.
1149 The components package is a package containing all component declarations for
1150 the current design. Its name can be obtained by modifying the project name
1151 \(e.g. attaching or stripping off a substring). If no project is defined, the
1152 DIRECTORY entry is chosen."
1153 vhdl-name-doc-string)
1154 :type '(cons (cons :tag "Project" :indent 2
1155 (regexp :tag "From regexp")
1156 (string :tag "To string "))
1157 (string :tag "Directory:\n String "))
1158 :group 'vhdl-compose)
1160 (defcustom vhdl-use-components-package nil
1161 "*Non-nil means use a separate components package for component declarations.
1162 Otherwise, component declarations are inserted and searched for in the
1163 architecture declarative parts."
1164 :type 'boolean
1165 :group 'vhdl-compose)
1167 (defcustom vhdl-compose-include-header t
1168 "*Non-nil means include a header in automatically generated files."
1169 :type 'boolean
1170 :group 'vhdl-compose)
1172 (defcustom vhdl-compose-create-files 'single
1173 "*Specifies whether new files should be created for the new component.
1174 The component's entity and architecture are inserted:
1175 None : in current buffer
1176 Single file : in new single file
1177 Separate files: in two separate files
1178 The file names are obtained from variables `vhdl-entity-file-name' and
1179 `vhdl-architecture-file-name'."
1180 :type '(choice (const :tag "None" none)
1181 (const :tag "Single file" single)
1182 (const :tag "Separate files" separate))
1183 :group 'vhdl-compose)
1185 (defcustom vhdl-compose-configuration-create-file nil
1186 "*Specifies whether a new file should be created for the configuration.
1187 If non-nil, a new file is created for the configuration.
1188 The file name is obtained from variable `vhdl-configuration-file-name'."
1189 :type 'boolean
1190 :group 'vhdl-compose)
1192 (defcustom vhdl-compose-configuration-hierarchical t
1193 "*Specifies whether hierarchical configurations should be created.
1194 If non-nil, automatically created configurations are hierarchical and include
1195 the whole hierarchy of subcomponents. Otherwise the configuration only
1196 includes one level of subcomponents."
1197 :type 'boolean
1198 :group 'vhdl-compose)
1200 (defcustom vhdl-compose-configuration-use-subconfiguration t
1201 "*Specifies whether subconfigurations should be used inside configurations.
1202 If non-nil, automatically created configurations use configurations in binding
1203 indications for subcomponents, if such configurations exist. Otherwise,
1204 entities are used in binding indications for subcomponents."
1205 :type 'boolean
1206 :group 'vhdl-compose)
1209 (defgroup vhdl-port nil
1210 "Customizations for port translation functions."
1211 :group 'vhdl
1212 :group 'vhdl-compose)
1214 (defcustom vhdl-include-port-comments nil
1215 "*Non-nil means include port comments when a port is pasted."
1216 :type 'boolean
1217 :group 'vhdl-port)
1219 (defcustom vhdl-include-direction-comments nil
1220 "*Non-nil means include port direction in instantiations as comments."
1221 :type 'boolean
1222 :group 'vhdl-port)
1224 (defcustom vhdl-include-type-comments nil
1225 "*Non-nil means include generic/port type in instantiations as comments."
1226 :type 'boolean
1227 :group 'vhdl-port)
1229 (defcustom vhdl-include-group-comments 'never
1230 "*Specifies whether to include group comments and spacings.
1231 The comments and empty lines between groups of ports are pasted:
1232 Never : never
1233 Declarations: in entity/component/constant/signal declarations only
1234 Always : also in generic/port maps"
1235 :type '(choice (const :tag "Never" never)
1236 (const :tag "Declarations" decl)
1237 (const :tag "Always" always))
1238 :group 'vhdl-port)
1240 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1241 (concat
1242 "*Specifies how actual port names are obtained from formal port names.
1243 In a component instantiation, an actual port name can be obtained by
1244 modifying the formal port name (e.g. attaching or stripping off a substring)."
1245 vhdl-name-doc-string)
1246 :type '(cons (regexp :tag "From regexp")
1247 (string :tag "To string "))
1248 :group 'vhdl-port)
1250 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1251 (concat
1252 "*Specifies how an instance name is obtained.
1253 The instance name can be obtained by modifying the name of the component to be
1254 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1255 by a unique number (starting with 1).
1256 If TO STRING is empty, the instance name is queried."
1257 vhdl-name-doc-string)
1258 :type '(cons (regexp :tag "From regexp")
1259 (string :tag "To string "))
1260 :group 'vhdl-port)
1263 (defgroup vhdl-testbench nil
1264 "Customizations for testbench generation."
1265 :group 'vhdl-port)
1267 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1268 (concat
1269 "*Specifies how the testbench entity name is obtained.
1270 The entity name of a testbench can be obtained by modifying the name of
1271 the component to be tested (e.g. attaching or stripping off a substring)."
1272 vhdl-name-doc-string)
1273 :type '(cons (regexp :tag "From regexp")
1274 (string :tag "To string "))
1275 :group 'vhdl-testbench)
1277 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1278 (concat
1279 "*Specifies how the testbench architecture name is obtained.
1280 The testbench architecture name can be obtained by modifying the name of
1281 the component to be tested (e.g. attaching or stripping off a substring).
1282 If TO STRING is empty, the architecture name is queried."
1283 vhdl-name-doc-string)
1284 :type '(cons (regexp :tag "From regexp")
1285 (string :tag "To string "))
1286 :group 'vhdl-testbench)
1288 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1289 (concat
1290 "*Specifies how the testbench configuration name is obtained.
1291 The configuration name of a testbench can be obtained by modifying the entity
1292 and/or architecture name (e.g. attaching or stripping off a substring). The
1293 string that is matched against the regexp is the concatenation of the entity
1294 and the architecture name separated by a space. This gives access to both
1295 names (see default setting as example)."
1296 vhdl-name-doc-string)
1297 :type '(cons (regexp :tag "From regexp")
1298 (string :tag "To string "))
1299 :group 'vhdl-testbench)
1301 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1302 (concat
1303 "*Specifies how a DUT instance name is obtained.
1304 The design-under-test instance name (i.e. the component instantiated in the
1305 testbench) can be obtained by modifying the component name (e.g. attaching
1306 or stripping off a substring)."
1307 vhdl-name-doc-string)
1308 :type '(cons (regexp :tag "From regexp")
1309 (string :tag "To string "))
1310 :group 'vhdl-testbench)
1312 (defcustom vhdl-testbench-include-header t
1313 "*Non-nil means include a header in automatically generated files."
1314 :type 'boolean
1315 :group 'vhdl-testbench)
1317 (defcustom vhdl-testbench-declarations "\
1318 -- clock
1319 signal Clk : std_logic := '1';
1321 "*String or file to be inserted in the testbench declarative part.
1322 If the string specifies an existing file name, the contents of the file is
1323 inserted, otherwise the string itself is inserted in the testbench
1324 architecture before the BEGIN keyword.
1325 Type `C-j' for newlines."
1326 :type 'string
1327 :group 'vhdl-testbench)
1329 (defcustom vhdl-testbench-statements "\
1330 -- clock generation
1331 Clk <= not Clk after 10 ns;
1333 -- waveform generation
1334 WaveGen_Proc: process
1335 begin
1336 -- insert signal assignments here
1338 wait until Clk = '1';
1339 end process WaveGen_Proc;
1341 "*String or file to be inserted in the testbench statement part.
1342 If the string specifies an existing file name, the contents of the file is
1343 inserted, otherwise the string itself is inserted in the testbench
1344 architecture before the END keyword.
1345 Type `C-j' for newlines."
1346 :type 'string
1347 :group 'vhdl-testbench)
1349 (defcustom vhdl-testbench-initialize-signals nil
1350 "*Non-nil means initialize signals with `0' when declared in testbench."
1351 :type 'boolean
1352 :group 'vhdl-testbench)
1354 (defcustom vhdl-testbench-include-library t
1355 "*Non-nil means a library/use clause for std_logic_1164 is included."
1356 :type 'boolean
1357 :group 'vhdl-testbench)
1359 (defcustom vhdl-testbench-include-configuration t
1360 "*Non-nil means a testbench configuration is attached at the end."
1361 :type 'boolean
1362 :group 'vhdl-testbench)
1364 (defcustom vhdl-testbench-create-files 'single
1365 "*Specifies whether new files should be created for the testbench.
1366 testbench entity and architecture are inserted:
1367 None : in current buffer
1368 Single file : in new single file
1369 Separate files: in two separate files
1370 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1371 and `vhdl-testbench-architecture-file-name'."
1372 :type '(choice (const :tag "None" none)
1373 (const :tag "Single file" single)
1374 (const :tag "Separate files" separate))
1375 :group 'vhdl-testbench)
1377 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1378 (concat
1379 "*Specifies how the testbench entity file name is obtained.
1380 The entity file name can be obtained by modifying the testbench entity name
1381 \(e.g. attaching or stripping off a substring). The file extension is
1382 automatically taken from the file name of the current buffer. Testbench
1383 files can be created in a different directory by prepending a relative or
1384 absolute path to the file name."
1385 vhdl-name-doc-string)
1386 :type '(cons (regexp :tag "From regexp")
1387 (string :tag "To string "))
1388 :group 'vhdl-testbench)
1390 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1391 (concat
1392 "*Specifies how the testbench architecture file name is obtained.
1393 The architecture file name can be obtained by modifying the testbench entity
1394 and/or architecture name (e.g. attaching or stripping off a substring). The
1395 string that is matched against the regexp is the concatenation of the entity
1396 and the architecture name separated by a space. This gives access to both
1397 names (see default setting as example). Testbench files can be created in
1398 a different directory by prepending a relative or absolute path to the file
1399 name."
1400 vhdl-name-doc-string)
1401 :type '(cons (regexp :tag "From regexp")
1402 (string :tag "To string "))
1403 :group 'vhdl-testbench)
1406 (defgroup vhdl-comment nil
1407 "Customizations for comments."
1408 :group 'vhdl)
1410 (defcustom vhdl-self-insert-comments t
1411 "*Non-nil means various templates automatically insert help comments."
1412 :type 'boolean
1413 :group 'vhdl-comment)
1415 (defcustom vhdl-prompt-for-comments t
1416 "*Non-nil means various templates prompt for user definable comments."
1417 :type 'boolean
1418 :group 'vhdl-comment)
1420 (defcustom vhdl-inline-comment-column 40
1421 "*Column to indent and align inline comments to.
1422 Overrides local option `comment-column'.
1424 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1425 \"Activate Options\"."
1426 :type 'integer
1427 :group 'vhdl-comment)
1429 (defcustom vhdl-end-comment-column 79
1430 "*End of comment column.
1431 Comments that exceed this column number are wrapped.
1433 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1434 \"Activate Options\"."
1435 :type 'integer
1436 :group 'vhdl-comment)
1438 (defvar end-comment-column)
1441 (defgroup vhdl-align nil
1442 "Customizations for alignment."
1443 :group 'vhdl)
1445 (defcustom vhdl-auto-align t
1446 "*Non-nil means align some templates automatically after generation."
1447 :type 'boolean
1448 :group 'vhdl-align)
1450 (defcustom vhdl-align-groups t
1451 "*Non-nil means align groups of code lines separately.
1452 A group of code lines is a region of consecutive lines between two lines that
1453 match the regexp in option `vhdl-align-group-separate'."
1454 :type 'boolean
1455 :group 'vhdl-align)
1457 (defcustom vhdl-align-group-separate "^\\s-*$"
1458 "*Regexp for matching a line that separates groups of lines for alignment.
1459 Examples:
1460 \"^\\s-*$\": matches an empty line
1461 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1462 :type 'regexp
1463 :group 'vhdl-align)
1465 (defcustom vhdl-align-same-indent t
1466 "*Non-nil means align blocks with same indent separately.
1467 When a region or the entire buffer is aligned, the code is divided into
1468 blocks of same indent which are aligned separately (except for argument/port
1469 lists). This gives nicer alignment in most cases.
1470 Option `vhdl-align-groups' still applies within these blocks."
1471 :type 'boolean
1472 :group 'vhdl-align)
1475 (defgroup vhdl-highlight nil
1476 "Customizations for highlighting."
1477 :group 'vhdl)
1479 (defcustom vhdl-highlight-keywords t
1480 "*Non-nil means highlight VHDL keywords and other standardized words.
1481 The following faces are used:
1482 `font-lock-keyword-face' : keywords
1483 `font-lock-type-face' : standardized types
1484 `vhdl-font-lock-attribute-face': standardized attributes
1485 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1486 `vhdl-font-lock-function-face' : standardized function and package names
1488 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1489 entry \"Fontify Buffer\")."
1490 :type 'boolean
1491 :set (lambda (variable value)
1492 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1493 :group 'vhdl-highlight)
1495 (defcustom vhdl-highlight-names t
1496 "*Non-nil means highlight declaration names and construct labels.
1497 The following faces are used:
1498 `font-lock-function-name-face' : names in declarations of units,
1499 subprograms, components, as well as labels of VHDL constructs
1500 `font-lock-type-face' : names in type/nature declarations
1501 `vhdl-font-lock-attribute-face': names in attribute declarations
1502 `font-lock-variable-name-face' : names in declarations of signals,
1503 variables, constants, subprogram parameters, generics, and ports
1505 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1506 entry \"Fontify Buffer\")."
1507 :type 'boolean
1508 :set (lambda (variable value)
1509 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1510 :group 'vhdl-highlight)
1512 (defcustom vhdl-highlight-special-words nil
1513 "*Non-nil means highlight words with special syntax.
1514 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1515 are highlighted accordingly.
1516 Can be used for visual support of naming conventions.
1518 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1519 entry \"Fontify Buffer\")."
1520 :type 'boolean
1521 :set (lambda (variable value)
1522 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1523 :group 'vhdl-highlight)
1525 (defcustom vhdl-highlight-forbidden-words nil
1526 "*Non-nil means highlight forbidden words.
1527 The reserved words specified in option `vhdl-forbidden-words' or having the
1528 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1529 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1530 use them.
1532 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1533 entry \"Fontify Buffer\")."
1534 :type 'boolean
1535 :set (lambda (variable value)
1536 (vhdl-custom-set variable value
1537 'vhdl-words-init 'vhdl-font-lock-init))
1538 :group 'vhdl-highlight)
1540 (defcustom vhdl-highlight-verilog-keywords nil
1541 "*Non-nil means highlight Verilog keywords as reserved words.
1542 Verilog keywords are highlighted in a warning color (face
1543 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1545 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1546 entry \"Fontify Buffer\")."
1547 :type 'boolean
1548 :set (lambda (variable value)
1549 (vhdl-custom-set variable value
1550 'vhdl-words-init 'vhdl-font-lock-init))
1551 :group 'vhdl-highlight)
1553 (defcustom vhdl-highlight-translate-off nil
1554 "*Non-nil means background-highlight code excluded from translation.
1555 That is, all code between \"-- pragma translate_off\" and
1556 \"-- pragma translate_on\" is highlighted using a different background color
1557 \(face `vhdl-font-lock-translate-off-face').
1558 Note: this might slow down on-the-fly fontification (and thus editing).
1560 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1561 entry \"Fontify Buffer\")."
1562 :type 'boolean
1563 :set (lambda (variable value)
1564 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1565 :group 'vhdl-highlight)
1567 (defcustom vhdl-highlight-case-sensitive nil
1568 "*Non-nil means consider case for highlighting.
1569 Possible trade-off:
1570 non-nil also upper-case VHDL words are highlighted, but case of words with
1571 special syntax is not considered
1572 nil only lower-case VHDL words are highlighted, but case of words with
1573 special syntax is considered
1574 Overrides local option `font-lock-keywords-case-fold-search'.
1576 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1577 entry \"Fontify Buffer\")."
1578 :type 'boolean
1579 :group 'vhdl-highlight)
1581 (defcustom vhdl-special-syntax-alist
1582 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1583 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1584 ("variable" "\\w+_v" "Grey50" "Grey80"))
1585 "*List of special syntax to be highlighted.
1586 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1587 syntax (as regular expression) are highlighted in the corresponding color.
1589 Name : string of words and spaces
1590 Regexp : regular expression describing word syntax
1591 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1592 Color (light): foreground color for light background
1593 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1594 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1595 Color (dark) : foreground color for dark background
1596 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1597 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1599 Can be used for visual support of naming conventions, such as highlighting
1600 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1601 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1602 common substrings or name suffices.
1603 For each entry, a new face is generated with the specified colors and name
1604 \"vhdl-font-lock-\" + name + \"-face\".
1606 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1607 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1608 :type '(repeat (list :tag "Face" :indent 2
1609 (string :tag "Name ")
1610 (regexp :tag "Regexp " "\\w+_")
1611 (string :tag "Color (light)")
1612 (string :tag "Color (dark) ")))
1613 :set (lambda (variable value)
1614 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1615 :group 'vhdl-highlight)
1617 (defcustom vhdl-forbidden-words '()
1618 "*List of forbidden words to be highlighted.
1619 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1620 words are highlighted in a warning color to indicate not to use them.
1622 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1623 entry \"Fontify Buffer\")."
1624 :type '(repeat (string :format "%v"))
1625 :set (lambda (variable value)
1626 (vhdl-custom-set variable value
1627 'vhdl-words-init 'vhdl-font-lock-init))
1628 :group 'vhdl-highlight)
1630 (defcustom vhdl-forbidden-syntax ""
1631 "*Syntax of forbidden words to be highlighted.
1632 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1633 syntax are highlighted in a warning color to indicate not to use them.
1634 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1635 highlights identifiers with 10 or more characters).
1637 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1638 entry \"Fontify Buffer\")."
1639 :type 'regexp
1640 :set (lambda (variable value)
1641 (vhdl-custom-set variable value
1642 'vhdl-words-init 'vhdl-font-lock-init))
1643 :group 'vhdl-highlight)
1645 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1646 "*List of compiler directive keywords recognized for highlighting.
1648 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1649 entry \"Fontify Buffer\")."
1650 :type '(repeat (string :format "%v"))
1651 :set (lambda (variable value)
1652 (vhdl-custom-set variable value
1653 'vhdl-words-init 'vhdl-font-lock-init))
1654 :group 'vhdl-highlight)
1657 (defgroup vhdl-speedbar nil
1658 "Customizations for speedbar."
1659 :group 'vhdl)
1661 (defcustom vhdl-speedbar-auto-open nil
1662 "*Non-nil means automatically open speedbar at startup.
1663 Alternatively, the speedbar can be opened from the VHDL menu."
1664 :type 'boolean
1665 :group 'vhdl-speedbar)
1667 (defcustom vhdl-speedbar-display-mode 'files
1668 "*Specifies the default displaying mode when opening speedbar.
1669 Alternatively, the displaying mode can be selected from the speedbar menu or
1670 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1671 :type '(choice (const :tag "Files" files)
1672 (const :tag "Directory hierarchy" directory)
1673 (const :tag "Project hierarchy" project))
1674 :group 'vhdl-speedbar)
1676 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1677 "*Limits scanning of large files and netlists.
1678 Design units: maximum file size to scan for design units
1679 Hierarchy (instances of subcomponents):
1680 File size: maximum file size to scan for instances (in bytes)
1681 Instances per arch: maximum number of instances to scan per architecture
1683 \"None\" always means that there is no limit.
1684 In case of files not or incompletely scanned, a warning message and the file
1685 names are printed out.
1686 Background: scanning for instances is considerably slower than scanning for
1687 design units, especially when there are many instances. These limits should
1688 prevent the scanning of large netlists."
1689 :type '(list (choice :tag "Design units"
1690 :format "%t : %[Value Menu%] %v"
1691 (const :tag "None" nil)
1692 (integer :tag "File size"))
1693 (list :tag "Hierarchy" :indent 2
1694 (choice :tag "File size"
1695 :format "%t : %[Value Menu%] %v"
1696 (const :tag "None" nil)
1697 (integer :tag "Size "))
1698 (choice :tag "Instances per arch"
1699 (const :tag "None" nil)
1700 (integer :tag "Number "))))
1701 :group 'vhdl-speedbar)
1703 (defcustom vhdl-speedbar-jump-to-unit t
1704 "*Non-nil means jump to the design unit code when opened in a buffer.
1705 The buffer cursor position is left unchanged otherwise."
1706 :type 'boolean
1707 :group 'vhdl-speedbar)
1709 (defcustom vhdl-speedbar-update-on-saving t
1710 "*Automatically update design hierarchy when buffer is saved."
1711 :type 'boolean
1712 :group 'vhdl-speedbar)
1714 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1715 "*Automatically save modified hierarchy caches when exiting Emacs.
1716 Hierarchy: design hierarchy information
1717 Display: displaying information (which design units to expand)"
1718 :type '(set (const :tag "Hierarchy" hierarchy)
1719 (const :tag "Display" display))
1720 :group 'vhdl-speedbar)
1722 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1723 "*Name of file for saving hierarchy cache.
1724 \"\\1\" is replaced by the project name if a project is specified,
1725 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1726 different users to have cache files in the same directory). Can also have
1727 an absolute path (i.e. all caches can be stored in one global directory)."
1728 :type 'string
1729 :group 'vhdl-speedbar)
1732 (defgroup vhdl-menu nil
1733 "Customizations for menues."
1734 :group 'vhdl)
1736 (defcustom vhdl-index-menu nil
1737 "*Non-nil means add an index menu for a source file when loading.
1738 Alternatively, the speedbar can be used. Note that the index menu scans a file
1739 when it is opened, while speedbar only scans the file upon request."
1740 :type 'boolean
1741 :group 'vhdl-menu)
1743 (defcustom vhdl-source-file-menu nil
1744 "*Non-nil means add a menu of all source files in current directory.
1745 Alternatively, the speedbar can be used."
1746 :type 'boolean
1747 :group 'vhdl-menu)
1749 (defcustom vhdl-hideshow-menu nil
1750 "*Non-nil means add hideshow menu and functionality at startup.
1751 Hideshow can also be enabled from the VHDL Mode menu.
1752 Hideshow allows hiding code of various VHDL constructs.
1754 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1755 \"Activate Options\"."
1756 :type 'boolean
1757 :group 'vhdl-menu)
1759 (defcustom vhdl-hide-all-init nil
1760 "*Non-nil means hide all design units initially after a file is loaded."
1761 :type 'boolean
1762 :group 'vhdl-menu)
1765 (defgroup vhdl-print nil
1766 "Customizations for printing."
1767 :group 'vhdl)
1769 (defcustom vhdl-print-two-column t
1770 "*Non-nil means print code in two columns and landscape format.
1771 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1772 prints VHDL files in a nice two-column landscape style.
1774 NOTE: Activate the new setting by restarting Emacs.
1775 Overrides `ps-print' settings locally."
1776 :type 'boolean
1777 :group 'vhdl-print)
1779 (defcustom vhdl-print-customize-faces t
1780 "*Non-nil means use an optimized set of faces for postscript printing.
1782 NOTE: Activate the new setting by restarting Emacs.
1783 Overrides `ps-print' settings locally."
1784 :type 'boolean
1785 :group 'vhdl-print)
1788 (defgroup vhdl-misc nil
1789 "Miscellaneous customizations."
1790 :group 'vhdl)
1792 (defcustom vhdl-intelligent-tab t
1793 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1794 That is, if preceeding character is part of a word then complete word,
1795 else if not at beginning of line then insert tab,
1796 else if last command was a `TAB' or `RET' then dedent one step,
1797 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1798 If nil, TAB always indents current line (i.e. `TAB' is bound to
1799 `indent-according-to-mode').
1801 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1802 \"Activate Options\"."
1803 :type 'boolean
1804 :group 'vhdl-misc)
1806 (defcustom vhdl-indent-syntax-based t
1807 "*Non-nil means indent lines of code based on their syntactic context.
1808 Otherwise, a line is indented like the previous nonblank line. This can be
1809 useful in large files where syntax-based indentation gets very slow."
1810 :type 'boolean
1811 :group 'vhdl-misc)
1813 (defcustom vhdl-word-completion-case-sensitive nil
1814 "*Non-nil means word completion using `TAB' is case sensitive.
1815 That is, `TAB' completes words that start with the same letters and case.
1816 Otherwise, case is ignored."
1817 :type 'boolean
1818 :group 'vhdl-misc)
1820 (defcustom vhdl-word-completion-in-minibuffer t
1821 "*Non-nil enables word completion in minibuffer (for template prompts).
1823 NOTE: Activate the new setting by restarting Emacs."
1824 :type 'boolean
1825 :group 'vhdl-misc)
1827 (defcustom vhdl-underscore-is-part-of-word nil
1828 "*Non-nil means consider the underscore character `_' as part of word.
1829 An identifier containing underscores is then treated as a single word in
1830 select and move operations. All parts of an identifier separated by underscore
1831 are treated as single words otherwise.
1833 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1834 \"Activate Options\"."
1835 :type 'boolean
1836 :set (lambda (variable value)
1837 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1838 :group 'vhdl-misc)
1841 (defgroup vhdl-related nil
1842 "Related general customizations."
1843 :group 'vhdl)
1845 ;; add related general customizations
1846 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1847 (if vhdl-xemacs
1848 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1849 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1850 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1851 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1852 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1853 (unless vhdl-xemacs
1854 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1855 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1856 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1857 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1859 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1860 ;; Internal variables
1862 (defvar vhdl-menu-max-size 20
1863 "*Specifies the maximum size of a menu before splitting it into submenues.")
1865 (defvar vhdl-progress-interval 1
1866 "*Interval used to update progress status during long operations.
1867 If a number, percentage complete gets updated after each interval of
1868 that many seconds. To inhibit all messages, set this option to nil.")
1870 (defvar vhdl-inhibit-startup-warnings-p nil
1871 "*If non-nil, inhibits start up compatibility warnings.")
1873 (defvar vhdl-strict-syntax-p nil
1874 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1875 If the syntactic symbol for a particular line does not match a symbol
1876 in the offsets alist, an error is generated, otherwise no error is
1877 reported and the syntactic symbol is ignored.")
1879 (defvar vhdl-echo-syntactic-information-p nil
1880 "*If non-nil, syntactic info is echoed when the line is indented.")
1882 (defconst vhdl-offsets-alist-default
1883 '((string . -1000)
1884 (cpp-macro . -1000)
1885 (block-open . 0)
1886 (block-close . 0)
1887 (statement . 0)
1888 (statement-cont . vhdl-lineup-statement-cont)
1889 (statement-block-intro . +)
1890 (statement-case-intro . +)
1891 (case-alternative . +)
1892 (comment . vhdl-lineup-comment)
1893 (arglist-intro . +)
1894 (arglist-cont . 0)
1895 (arglist-cont-nonempty . vhdl-lineup-arglist)
1896 (arglist-close . vhdl-lineup-arglist)
1897 (entity . 0)
1898 (configuration . 0)
1899 (package . 0)
1900 (architecture . 0)
1901 (package-body . 0)
1903 "Default settings for offsets of syntactic elements.
1904 Do not change this constant! See the variable `vhdl-offsets-alist' for
1905 more information.")
1907 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1908 "*Association list of syntactic element symbols and indentation offsets.
1909 As described below, each cons cell in this list has the form:
1911 (SYNTACTIC-SYMBOL . OFFSET)
1913 When a line is indented, `vhdl-mode' first determines the syntactic
1914 context of the line by generating a list of symbols called syntactic
1915 elements. This list can contain more than one syntactic element and
1916 the global variable `vhdl-syntactic-context' contains the context list
1917 for the line being indented. Each element in this list is actually a
1918 cons cell of the syntactic symbol and a buffer position. This buffer
1919 position is call the relative indent point for the line. Some
1920 syntactic symbols may not have a relative indent point associated with
1921 them.
1923 After the syntactic context list for a line is generated, `vhdl-mode'
1924 calculates the absolute indentation for the line by looking at each
1925 syntactic element in the list. First, it compares the syntactic
1926 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1927 finds a match, it adds the OFFSET to the column of the relative indent
1928 point. The sum of this calculation for each element in the syntactic
1929 list is the absolute offset for line being indented.
1931 If the syntactic element does not match any in the `vhdl-offsets-alist',
1932 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1933 the element is ignored.
1935 Actually, OFFSET can be an integer, a function, a variable, or one of
1936 the following symbols: `+', `-', `++', or `--'. These latter
1937 designate positive or negative multiples of `vhdl-basic-offset',
1938 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1939 called with a single argument containing the cons of the syntactic
1940 element symbol and the relative indent point. The function should
1941 return an integer offset.
1943 Here is the current list of valid syntactic element symbols:
1945 string -- inside multi-line string
1946 block-open -- statement block open
1947 block-close -- statement block close
1948 statement -- a VHDL statement
1949 statement-cont -- a continuation of a VHDL statement
1950 statement-block-intro -- the first line in a new statement block
1951 statement-case-intro -- the first line in a case alternative block
1952 case-alternative -- a case statement alternative clause
1953 comment -- a line containing only a comment
1954 arglist-intro -- the first line in an argument list
1955 arglist-cont -- subsequent argument list lines when no
1956 arguments follow on the same line as the
1957 the arglist opening paren
1958 arglist-cont-nonempty -- subsequent argument list lines when at
1959 least one argument follows on the same
1960 line as the arglist opening paren
1961 arglist-close -- the solo close paren of an argument list
1962 entity -- inside an entity declaration
1963 configuration -- inside a configuration declaration
1964 package -- inside a package declaration
1965 architecture -- inside an architecture body
1966 package-body -- inside a package body")
1968 (defvar vhdl-comment-only-line-offset 0
1969 "*Extra offset for line which contains only the start of a comment.
1970 Can contain an integer or a cons cell of the form:
1972 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1974 Where NON-ANCHORED-OFFSET is the amount of offset given to
1975 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1976 the amount of offset to give column-zero anchored comment-only lines.
1977 Just an integer as value is equivalent to (<val> . 0)")
1979 (defvar vhdl-special-indent-hook nil
1980 "*Hook for user defined special indentation adjustments.
1981 This hook gets called after a line is indented by the mode.")
1983 (defvar vhdl-style-alist
1984 '(("IEEE"
1985 (vhdl-basic-offset . 4)
1986 (vhdl-offsets-alist . ())))
1987 "Styles of Indentation.
1988 Elements of this alist are of the form:
1990 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1992 where STYLE-STRING is a short descriptive string used to select a
1993 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1994 value for that variable when using the selected style.
1996 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1997 case, the VALUE is a list containing elements of the form:
1999 (SYNTACTIC-SYMBOL . VALUE)
2001 as described in `vhdl-offsets-alist'. These are passed directly to
2002 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2003 your style, only those that are different from the default.")
2005 ;; dynamically append the default value of most variables
2006 (or (assoc "Default" vhdl-style-alist)
2007 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2008 vhdl-strict-syntax-p
2009 vhdl-echo-syntactic-information-p
2010 vhdl-basic-offset
2011 vhdl-offsets-alist
2012 vhdl-comment-only-line-offset))
2013 (default (cons "Default"
2014 (mapcar
2015 (function
2016 (lambda (var)
2017 (cons var (symbol-value var))))
2018 varlist))))
2019 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2021 (defvar vhdl-mode-hook nil
2022 "*Hook called by `vhdl-mode'.")
2025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2026 ;;; Required packages
2027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2029 ;; mandatory
2030 (require 'assoc)
2031 (require 'compile) ; XEmacs
2032 (require 'easymenu)
2033 (require 'hippie-exp)
2035 ;; optional (minimize warning messages during compile)
2036 (eval-when-compile
2037 (require 'font-lock)
2038 (require 'ps-print)
2039 (require 'speedbar))
2042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2043 ;;; Compatibility
2044 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2046 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2047 ;; XEmacs compatibility
2049 ;; active regions
2050 (defun vhdl-keep-region-active ()
2051 "Do whatever is necessary to keep the region active in XEmacs.
2052 Ignore byte-compiler warnings you might see."
2053 (and (boundp 'zmacs-region-stays)
2054 (setq zmacs-region-stays t)))
2056 ;; `wildcard-to-regexp' is included only in XEmacs 21
2057 (unless (fboundp 'wildcard-to-regexp)
2058 (defun wildcard-to-regexp (wildcard)
2059 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2060 (let* ((i (string-match "[*?]" wildcard))
2061 (result (substring wildcard 0 i))
2062 (len (length wildcard)))
2063 (when i
2064 (while (< i len)
2065 (let ((ch (aref wildcard i)))
2066 (setq result (concat result
2067 (cond ((eq ch ?*) "[^\000]*")
2068 ((eq ch ??) "[^\000]")
2069 (t (char-to-string ch)))))
2070 (setq i (1+ i)))))
2071 (concat "\\`" result "\\'"))))
2073 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2074 ;; `regexp-opt' accelerates fontification by 10-20%
2075 (unless (fboundp 'regexp-opt)
2076 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2077 (defun regexp-opt (strings &optional paren)
2078 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2079 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2081 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2082 (unless (fboundp 'match-string-no-properties)
2083 (defalias 'match-string-no-properties 'match-string))
2085 ;; `subst-char-in-string' undefined (XEmacs)
2086 (unless (fboundp 'subst-char-in-string)
2087 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2088 (let ((i (length string))
2089 (newstr (if inplace string (copy-sequence string))))
2090 (while (> i 0)
2091 (setq i (1- i))
2092 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2093 newstr)))
2095 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2096 (when (and vhdl-xemacs (string< itimer-version "1.09")
2097 (not noninteractive))
2098 (load "itimer")
2099 (when (string< itimer-version "1.09")
2100 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2101 (beep) (sit-for 5)))
2103 ;; `file-expand-wildcards' undefined (XEmacs)
2104 (unless (fboundp 'file-expand-wildcards)
2105 (defun file-expand-wildcards (pattern &optional full)
2106 "Taken from Emacs' `files.el'."
2107 (let* ((nondir (file-name-nondirectory pattern))
2108 (dirpart (file-name-directory pattern))
2109 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2110 (mapcar 'file-name-as-directory
2111 (file-expand-wildcards (directory-file-name dirpart)))
2112 (list dirpart)))
2113 contents)
2114 (while dirs
2115 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2116 (file-directory-p (directory-file-name (car dirs))))
2117 (let ((this-dir-contents
2118 (delq nil
2119 (mapcar #'(lambda (name)
2120 (unless (string-match "\\`\\.\\.?\\'"
2121 (file-name-nondirectory name))
2122 name))
2123 (directory-files (or (car dirs) ".") full
2124 (wildcard-to-regexp nondir))))))
2125 (setq contents
2126 (nconc
2127 (if (and (car dirs) (not full))
2128 (mapcar (function (lambda (name) (concat (car dirs) name)))
2129 this-dir-contents)
2130 this-dir-contents)
2131 contents))))
2132 (setq dirs (cdr dirs)))
2133 contents)))
2135 ;; `member-ignore-case' undefined (XEmacs)
2136 (unless (fboundp 'member-ignore-case)
2137 (defalias 'member-ignore-case 'member))
2139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2140 ;; Compatibility with older VHDL Mode versions
2142 (defvar vhdl-warnings nil
2143 "Warnings to tell the user during start up.")
2145 (defun vhdl-run-when-idle (secs repeat function)
2146 "Wait until idle, then run FUNCTION."
2147 (if (fboundp 'start-itimer)
2148 (start-itimer "vhdl-mode" function secs repeat t)
2149 ; (run-with-idle-timer secs repeat function)))
2150 ;; explicitely activate timer (necessary when Emacs is already idle)
2151 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2153 (defun vhdl-warning-when-idle (&rest args)
2154 "Wait until idle, then print out warning STRING and beep."
2155 (if noninteractive
2156 (vhdl-warning (apply 'format args) t)
2157 (unless vhdl-warnings
2158 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2159 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2161 (defun vhdl-warning (string &optional nobeep)
2162 "Print out warning STRING and beep."
2163 (message "WARNING: %s" string)
2164 (unless (or nobeep noninteractive) (beep)))
2166 (defun vhdl-print-warnings ()
2167 "Print out messages in variable `vhdl-warnings'."
2168 (let ((no-warnings (length vhdl-warnings)))
2169 (setq vhdl-warnings (nreverse vhdl-warnings))
2170 (while vhdl-warnings
2171 (message "WARNING: %s" (car vhdl-warnings))
2172 (setq vhdl-warnings (cdr vhdl-warnings)))
2173 (beep)
2174 (when (> no-warnings 1)
2175 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2177 ;; Backward compatibility checks and fixes
2178 ;; option `vhdl-compiler' changed format
2179 (unless (stringp vhdl-compiler)
2180 (setq vhdl-compiler "ModelSim")
2181 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2183 ;; option `vhdl-standard' changed format
2184 (unless (listp vhdl-standard)
2185 (setq vhdl-standard '(87 nil))
2186 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2188 ;; option `vhdl-model-alist' changed format
2189 (when (= (length (car vhdl-model-alist)) 3)
2190 (let ((old-alist vhdl-model-alist)
2191 new-alist)
2192 (while old-alist
2193 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2194 (setq old-alist (cdr old-alist)))
2195 (setq vhdl-model-alist (nreverse new-alist)))
2196 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2198 ;; option `vhdl-project-alist' changed format
2199 (when (= (length (car vhdl-project-alist)) 3)
2200 (let ((old-alist vhdl-project-alist)
2201 new-alist)
2202 (while old-alist
2203 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2204 (setq old-alist (cdr old-alist)))
2205 (setq vhdl-project-alist (nreverse new-alist)))
2206 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2208 ;; option `vhdl-project-alist' changed format (3.31.1)
2209 (when (= (length (car vhdl-project-alist)) 4)
2210 (let ((old-alist vhdl-project-alist)
2211 new-alist elem)
2212 (while old-alist
2213 (setq elem (car old-alist))
2214 (setq new-alist
2215 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2216 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2217 new-alist))
2218 (setq old-alist (cdr old-alist)))
2219 (setq vhdl-project-alist (nreverse new-alist)))
2220 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2222 ;; option `vhdl-project-alist' changed format (3.31.12)
2223 (when (= (length (car vhdl-project-alist)) 10)
2224 (let ((tmp-alist vhdl-project-alist))
2225 (while tmp-alist
2226 (setcdr (nthcdr 3 (car tmp-alist))
2227 (cons "" (nthcdr 4 (car tmp-alist))))
2228 (setq tmp-alist (cdr tmp-alist))))
2229 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2231 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2232 (when (= (length (car vhdl-compiler-alist)) 7)
2233 (let ((old-alist vhdl-compiler-alist)
2234 new-alist elem)
2235 (while old-alist
2236 (setq elem (car old-alist))
2237 (setq new-alist
2238 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2239 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2240 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2241 (nth 5 elem) (nth 6 elem) nil)
2242 new-alist))
2243 (setq old-alist (cdr old-alist)))
2244 (setq vhdl-compiler-alist (nreverse new-alist)))
2245 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2247 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2248 (when (= (length (car vhdl-compiler-alist)) 12)
2249 (let ((tmp-alist vhdl-compiler-alist))
2250 (while tmp-alist
2251 (setcdr (nthcdr 4 (car tmp-alist))
2252 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2253 (setq tmp-alist (cdr tmp-alist))))
2254 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2256 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2257 (when (= (length (car vhdl-compiler-alist)) 13)
2258 (let ((tmp-alist vhdl-compiler-alist))
2259 (while tmp-alist
2260 (setcdr (nthcdr 3 (car tmp-alist))
2261 (cons "" (nthcdr 4 (car tmp-alist))))
2262 (setq tmp-alist (cdr tmp-alist))))
2263 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2265 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2266 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2267 (let ((tmp-alist vhdl-compiler-alist))
2268 (while tmp-alist
2269 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2270 '(0 . nil))
2271 (setq tmp-alist (cdr tmp-alist))))
2272 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2274 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2275 (when (equal vhdl-project "")
2276 (setq vhdl-project nil)
2277 (customize-save-variable 'vhdl-project vhdl-project))
2279 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2280 (when (stringp vhdl-project-file-name)
2281 (setq vhdl-project-file-name (list vhdl-project-file-name))
2282 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2284 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2285 (if (not (boundp 'speedbar-indentation-width))
2286 (defvar speedbar-indentation-width 2)
2287 ;; set default to 2 if not already customized
2288 (unless (get 'speedbar-indentation-width 'saved-value)
2289 (setq speedbar-indentation-width 2)))
2292 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2293 ;;; Help functions / inline substitutions / macros
2294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2296 (defun vhdl-standard-p (standard)
2297 "Check if STANDARD is specified as used standard."
2298 (or (eq standard (car vhdl-standard))
2299 (memq standard (cadr vhdl-standard))))
2301 (defun vhdl-project-p (&optional warning)
2302 "Return non-nil if a project is displayed, i.e. directories or files are
2303 specified."
2304 (if (assoc vhdl-project vhdl-project-alist)
2305 vhdl-project
2306 (when (and vhdl-project warning)
2307 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2308 nil))
2310 (defun vhdl-resolve-env-variable (string)
2311 "Resolve environment variables in STRING."
2312 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2313 (setq string (concat (match-string 1 string)
2314 (getenv (match-string 2 string))
2315 (match-string 4 string))))
2316 string)
2318 (defun vhdl-default-directory ()
2319 "Return the default directory of the current project or the directory of the
2320 current buffer if no project is defined."
2321 (if (vhdl-project-p)
2322 (expand-file-name (vhdl-resolve-env-variable
2323 (nth 1 (aget vhdl-project-alist vhdl-project))))
2324 default-directory))
2326 (defmacro vhdl-prepare-search-1 (&rest body)
2327 "Enable case insensitive search and switch to syntax table that includes '_',
2328 then execute BODY, and finally restore the old environment. Used for
2329 consistent searching."
2330 `(let ((case-fold-search t) ; case insensitive search
2331 (current-syntax-table (syntax-table))
2332 result
2333 (restore-prog ; program to restore enviroment
2334 '(progn
2335 ;; restore syntax table
2336 (set-syntax-table current-syntax-table))))
2337 ;; use extended syntax table
2338 (set-syntax-table vhdl-mode-ext-syntax-table)
2339 ;; execute BODY safely
2340 (setq result
2341 (condition-case info
2342 (progn ,@body)
2343 (error (eval restore-prog) ; restore environment on error
2344 (error (cadr info))))) ; pass error up
2345 ;; restore environment
2346 (eval restore-prog)
2347 result))
2349 (defmacro vhdl-prepare-search-2 (&rest body)
2350 "Enable case insensitive search, switch to syntax table that includes '_',
2351 and remove `intangible' overlays, then execute BODY, and finally restore the
2352 old environment. Used for consistent searching."
2353 `(let ((case-fold-search t) ; case insensitive search
2354 (current-syntax-table (syntax-table))
2355 result overlay-all-list overlay-intangible-list overlay
2356 (restore-prog ; program to restore enviroment
2357 '(progn
2358 ;; restore syntax table
2359 (set-syntax-table current-syntax-table)
2360 ;; restore `intangible' overlays
2361 (when (fboundp 'overlay-lists)
2362 (while overlay-intangible-list
2363 (overlay-put (car overlay-intangible-list) 'intangible t)
2364 (setq overlay-intangible-list
2365 (cdr overlay-intangible-list)))))))
2366 ;; use extended syntax table
2367 (set-syntax-table vhdl-mode-ext-syntax-table)
2368 ;; remove `intangible' overlays
2369 (when (fboundp 'overlay-lists)
2370 (setq overlay-all-list (overlay-lists))
2371 (setq overlay-all-list
2372 (append (car overlay-all-list) (cdr overlay-all-list)))
2373 (while overlay-all-list
2374 (setq overlay (car overlay-all-list))
2375 (when (memq 'intangible (overlay-properties overlay))
2376 (setq overlay-intangible-list
2377 (cons overlay overlay-intangible-list))
2378 (overlay-put overlay 'intangible nil))
2379 (setq overlay-all-list (cdr overlay-all-list))))
2380 ;; execute BODY safely
2381 (setq result
2382 (condition-case info
2383 (progn ,@body)
2384 (error (eval restore-prog) ; restore environment on error
2385 (error (cadr info))))) ; pass error up
2386 ;; restore environment
2387 (eval restore-prog)
2388 result))
2390 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2391 "Visit file FILE-NAME and execute BODY."
2392 `(if (null ,file-name)
2393 (progn ,@body)
2394 (unless (file-directory-p ,file-name)
2395 (let ((source-buffer (current-buffer))
2396 (visiting-buffer (find-buffer-visiting ,file-name))
2397 file-opened)
2398 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2399 (condition-case ()
2400 (progn (set-buffer (create-file-buffer ,file-name))
2401 (setq file-opened t)
2402 (vhdl-insert-file-contents ,file-name)
2403 (modify-syntax-entry ?\- ". 12" (syntax-table))
2404 (modify-syntax-entry ?\n ">" (syntax-table))
2405 (modify-syntax-entry ?\^M ">" (syntax-table))
2406 (modify-syntax-entry ?_ "w" (syntax-table))
2408 (error
2409 (if ,issue-error
2410 (progn
2411 (when file-opened (kill-buffer (current-buffer)))
2412 (set-buffer source-buffer)
2413 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2414 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2415 nil))))
2416 (condition-case info
2417 (progn ,@body)
2418 (error
2419 (if ,issue-error
2420 (progn
2421 (when file-opened (kill-buffer (current-buffer)))
2422 (set-buffer source-buffer)
2423 (error (cadr info)))
2424 (vhdl-warning (cadr info))))))
2425 (when file-opened (kill-buffer (current-buffer)))
2426 (set-buffer source-buffer)))))
2428 (defun vhdl-insert-file-contents (filename)
2429 "Nicked from `insert-file-contents-literally', but allow coding system
2430 conversion."
2431 (let ((format-alist nil)
2432 (after-insert-file-functions nil)
2433 (jka-compr-compression-info-list nil))
2434 (insert-file-contents filename t)))
2436 (defun vhdl-sort-alist (alist)
2437 "Sort ALIST."
2438 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2440 (defun vhdl-get-subdirs (directory)
2441 "Recursively get subdirectories of DIRECTORY."
2442 (let ((dir-list (list (file-name-as-directory directory)))
2443 file-list)
2444 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2445 (while file-list
2446 (when (file-directory-p (car file-list))
2447 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2448 (setq file-list (cdr file-list)))
2449 dir-list))
2451 (defun vhdl-aput (alist-symbol key &optional value)
2452 "As `aput', but delete key-value pair if VALUE is nil."
2453 (if value
2454 (aput alist-symbol key value)
2455 (adelete alist-symbol key)))
2457 (defun vhdl-delete (elt list)
2458 "Delete by side effect the first occurrence of ELT as a member of LIST."
2459 (setq list (cons nil list))
2460 (let ((list1 list))
2461 (while (and (cdr list1) (not (equal elt (cadr list1))))
2462 (setq list1 (cdr list1)))
2463 (when list
2464 (setcdr list1 (cddr list1))))
2465 (cdr list))
2467 (defun vhdl-speedbar-refresh (&optional key)
2468 "Refresh directory or project with name KEY."
2469 (when (and (boundp 'speedbar-frame)
2470 (frame-live-p speedbar-frame))
2471 (let ((pos (point))
2472 (last-frame (selected-frame)))
2473 (if (null key)
2474 (speedbar-refresh)
2475 (select-frame speedbar-frame)
2476 (when (save-excursion
2477 (goto-char (point-min))
2478 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2479 (goto-char (match-end 1))
2480 (speedbar-do-function-pointer)
2481 (backward-char 2)
2482 (speedbar-do-function-pointer)
2483 (message "Refreshing speedbar...done"))
2484 (select-frame last-frame)))))
2486 (defun vhdl-show-messages ()
2487 "Get *Messages* buffer to show recent messages."
2488 (interactive)
2489 (display-buffer (if vhdl-xemacs " *Message-Log*" "*Messages*")))
2491 (defun vhdl-use-direct-instantiation ()
2492 "Return whether direct instantiation is used."
2493 (or (eq vhdl-use-direct-instantiation 'always)
2494 (and (eq vhdl-use-direct-instantiation 'standard)
2495 (not (vhdl-standard-p '87)))))
2497 (defun vhdl-max-marker (marker1 marker2)
2498 "Return larger marker."
2499 (if (> marker1 marker2) marker1 marker2))
2501 (defun vhdl-goto-marker (marker)
2502 "Goto marker in appropriate buffer."
2503 (when (markerp marker)
2504 (set-buffer (marker-buffer marker)))
2505 (goto-char marker))
2507 (defun vhdl-menu-split (list title)
2508 "Split menu LIST into several submenues, if number of
2509 elements > `vhdl-menu-max-size'."
2510 (if (> (length list) vhdl-menu-max-size)
2511 (let ((remain list)
2512 (result '())
2513 (sublist '())
2514 (menuno 1)
2515 (i 0))
2516 (while remain
2517 (setq sublist (cons (car remain) sublist))
2518 (setq remain (cdr remain))
2519 (setq i (+ i 1))
2520 (if (= i vhdl-menu-max-size)
2521 (progn
2522 (setq result (cons (cons (format "%s %s" title menuno)
2523 (nreverse sublist)) result))
2524 (setq i 0)
2525 (setq menuno (+ menuno 1))
2526 (setq sublist '()))))
2527 (and sublist
2528 (setq result (cons (cons (format "%s %s" title menuno)
2529 (nreverse sublist)) result)))
2530 (nreverse result))
2531 list))
2534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2535 ;;; Bindings
2536 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2539 ;; Key bindings
2541 (defvar vhdl-template-map nil
2542 "Keymap for VHDL templates.")
2544 (defun vhdl-template-map-init ()
2545 "Initialize `vhdl-template-map'."
2546 (setq vhdl-template-map (make-sparse-keymap))
2547 ;; key bindings for VHDL templates
2548 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2549 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2550 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2551 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2552 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2553 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2554 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2555 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2556 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2557 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2558 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2559 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2560 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2561 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2562 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2563 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2564 (define-key vhdl-template-map "el" 'vhdl-template-else)
2565 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2566 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2567 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2568 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2569 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2570 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2571 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2572 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2573 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2574 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2575 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2576 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2577 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2578 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2579 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2580 (define-key vhdl-template-map "li" 'vhdl-template-library)
2581 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2582 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2583 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2584 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2585 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2586 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2587 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2588 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2589 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2590 (define-key vhdl-template-map "po" 'vhdl-template-port)
2591 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2592 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2593 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2594 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2595 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2596 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2597 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2598 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2599 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2600 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2601 (define-key vhdl-template-map "us" 'vhdl-template-use)
2602 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2603 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2604 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2605 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2606 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2607 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2608 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2609 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2610 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2611 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2612 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2613 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2614 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2615 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2616 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2617 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2618 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2619 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2620 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2621 (when (vhdl-standard-p 'ams)
2622 (define-key vhdl-template-map "br" 'vhdl-template-break)
2623 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2624 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2625 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2626 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2627 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2628 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2629 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2630 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2631 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2632 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2634 (when (vhdl-standard-p 'math)
2635 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2636 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2639 ;; initialize template map for VHDL Mode
2640 (vhdl-template-map-init)
2642 (defun vhdl-function-name (prefix string &optional postfix)
2643 "Generate a Lisp function name.
2644 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2645 STRING are replaced by `-' and substrings are converted to lower case."
2646 (let ((name prefix))
2647 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2648 (setq name
2649 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2650 (setq string (substring string (match-beginning 2))))
2651 (when postfix (setq name (concat name "-" postfix)))
2652 (intern name)))
2654 (defvar vhdl-model-map nil
2655 "Keymap for VHDL models.")
2657 (defun vhdl-model-map-init ()
2658 "Initialize `vhdl-model-map'."
2659 (setq vhdl-model-map (make-sparse-keymap))
2660 ;; key bindings for VHDL models
2661 (let ((model-alist vhdl-model-alist) model)
2662 (while model-alist
2663 (setq model (car model-alist))
2664 (define-key vhdl-model-map (nth 2 model)
2665 (vhdl-function-name "vhdl-model" (nth 0 model)))
2666 (setq model-alist (cdr model-alist)))))
2668 ;; initialize user model map for VHDL Mode
2669 (vhdl-model-map-init)
2671 (defvar vhdl-mode-map nil
2672 "Keymap for VHDL Mode.")
2674 (defun vhdl-mode-map-init ()
2675 "Initialize `vhdl-mode-map'."
2676 (setq vhdl-mode-map (make-sparse-keymap))
2677 ;; template key bindings
2678 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2679 ;; model key bindings
2680 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2681 ;; standard key bindings
2682 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2683 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2684 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2685 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2686 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2687 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2688 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2689 (unless vhdl-xemacs ; would override `M-backspace' in XEmacs
2690 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2691 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2692 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2693 ;; backspace/delete key bindings
2694 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2695 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2696 (define-key vhdl-mode-map [delete] 'delete-char)
2697 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2698 ;; mode specific key bindings
2699 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2700 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2701 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2702 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2703 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2704 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2705 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2706 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2707 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2708 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2709 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2710 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2711 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2712 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2713 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2714 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2715 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2716 (if vhdl-xemacs ; `... C-g' not allowed in XEmacs
2717 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2718 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2719 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2720 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2721 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2722 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2723 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2724 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2725 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2726 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2727 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2728 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2729 (define-key vhdl-mode-map "\C-c\C-c\C-n" 'vhdl-compose-new-component)
2730 (define-key vhdl-mode-map "\C-c\C-c\C-p" 'vhdl-compose-place-component)
2731 (define-key vhdl-mode-map "\C-c\C-c\C-w" 'vhdl-compose-wire-components)
2732 (define-key vhdl-mode-map "\C-c\C-c\C-f" 'vhdl-compose-configuration)
2733 (define-key vhdl-mode-map "\C-c\C-c\C-k" 'vhdl-compose-components-package)
2734 (define-key vhdl-mode-map "\C-cc" 'vhdl-comment-uncomment-region)
2735 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2736 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2737 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2738 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2739 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2740 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2741 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2742 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2743 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2744 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2745 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2746 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2747 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2748 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2749 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2750 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2751 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2752 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2753 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2754 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2755 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2756 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2757 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2758 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2759 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2760 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2761 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2762 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2763 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2764 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2765 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2766 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2767 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2768 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2769 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2770 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2771 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2772 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2773 (define-key vhdl-mode-map "\C-cf" 'vhdl-fontify-buffer)
2774 (define-key vhdl-mode-map "\C-cs" 'vhdl-statistics-buffer)
2775 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2776 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2777 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2778 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2779 ;; insert commands bindings
2780 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2781 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2782 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2783 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2784 ;; electric key bindings
2785 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2786 (when vhdl-intelligent-tab
2787 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2788 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2789 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2790 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2791 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2792 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2793 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2794 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2795 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2796 (when (vhdl-standard-p 'ams)
2797 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2799 ;; initialize mode map for VHDL Mode
2800 (vhdl-mode-map-init)
2802 ;; define special minibuffer keymap for enabling word completion in minibuffer
2803 ;; (useful in template generator prompts)
2804 (defvar vhdl-minibuffer-local-map
2805 (let ((map (make-sparse-keymap)))
2806 (set-keymap-parent map minibuffer-local-map)
2807 (when vhdl-word-completion-in-minibuffer
2808 (define-key map "\t" 'vhdl-minibuffer-tab))
2809 map)
2810 "Keymap for minibuffer used in VHDL Mode.")
2812 ;; set up electric character functions to work with
2813 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2814 (mapcar
2815 (function
2816 (lambda (sym)
2817 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2818 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2819 '(vhdl-electric-space
2820 vhdl-electric-tab
2821 vhdl-electric-return
2822 vhdl-electric-dash
2823 vhdl-electric-open-bracket
2824 vhdl-electric-close-bracket
2825 vhdl-electric-quote
2826 vhdl-electric-semicolon
2827 vhdl-electric-comma
2828 vhdl-electric-period
2829 vhdl-electric-equal))
2831 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2832 ;; Syntax table
2834 (defvar vhdl-mode-syntax-table nil
2835 "Syntax table used in `vhdl-mode' buffers.")
2837 (defvar vhdl-mode-ext-syntax-table nil
2838 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2840 (defun vhdl-mode-syntax-table-init ()
2841 "Initialize `vhdl-mode-syntax-table'."
2842 (setq vhdl-mode-syntax-table (make-syntax-table))
2843 ;; define punctuation
2844 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2845 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2846 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2847 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2848 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2849 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2850 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2851 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2852 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2853 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2854 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2855 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2856 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2857 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2858 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2859 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2860 ;; define string
2861 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2862 ;; define underscore
2863 (when vhdl-underscore-is-part-of-word
2864 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2865 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2866 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2867 ;; and \n and \^M end a comment
2868 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2869 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2870 ;; define parentheses to match
2871 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2872 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2873 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2874 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2875 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2876 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2877 ;; extended syntax table including '_' (for simpler search regexps)
2878 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2879 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2881 ;; initialize syntax table for VHDL Mode
2882 (vhdl-mode-syntax-table-init)
2884 (defvar vhdl-syntactic-context nil
2885 "Buffer local variable containing syntactic analysis list.")
2886 (make-variable-buffer-local 'vhdl-syntactic-context)
2888 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2889 ;; Abbrev ook bindings
2891 (defvar vhdl-mode-abbrev-table nil
2892 "Abbrev table to use in `vhdl-mode' buffers.")
2894 (defun vhdl-mode-abbrev-table-init ()
2895 "Initialize `vhdl-mode-abbrev-table'."
2896 (define-abbrev-table 'vhdl-mode-abbrev-table
2897 (append
2898 (when (memq 'vhdl vhdl-electric-keywords)
2899 ;; VHDL'93 keywords
2901 ("--" "" vhdl-template-display-comment-hook 0)
2902 ("abs" "" vhdl-template-default-hook 0)
2903 ("access" "" vhdl-template-default-hook 0)
2904 ("after" "" vhdl-template-default-hook 0)
2905 ("alias" "" vhdl-template-alias-hook 0)
2906 ("all" "" vhdl-template-default-hook 0)
2907 ("and" "" vhdl-template-default-hook 0)
2908 ("arch" "" vhdl-template-architecture-hook 0)
2909 ("architecture" "" vhdl-template-architecture-hook 0)
2910 ("array" "" vhdl-template-default-hook 0)
2911 ("assert" "" vhdl-template-assert-hook 0)
2912 ("attr" "" vhdl-template-attribute-hook 0)
2913 ("attribute" "" vhdl-template-attribute-hook 0)
2914 ("begin" "" vhdl-template-default-indent-hook 0)
2915 ("block" "" vhdl-template-block-hook 0)
2916 ("body" "" vhdl-template-default-hook 0)
2917 ("buffer" "" vhdl-template-default-hook 0)
2918 ("bus" "" vhdl-template-default-hook 0)
2919 ("case" "" vhdl-template-case-hook 0)
2920 ("comp" "" vhdl-template-component-hook 0)
2921 ("component" "" vhdl-template-component-hook 0)
2922 ("cond" "" vhdl-template-conditional-signal-asst-hook 0)
2923 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0)
2924 ("conf" "" vhdl-template-configuration-hook 0)
2925 ("configuration" "" vhdl-template-configuration-hook 0)
2926 ("cons" "" vhdl-template-constant-hook 0)
2927 ("constant" "" vhdl-template-constant-hook 0)
2928 ("disconnect" "" vhdl-template-disconnect-hook 0)
2929 ("downto" "" vhdl-template-default-hook 0)
2930 ("else" "" vhdl-template-else-hook 0)
2931 ("elseif" "" vhdl-template-elsif-hook 0)
2932 ("elsif" "" vhdl-template-elsif-hook 0)
2933 ("end" "" vhdl-template-default-indent-hook 0)
2934 ("entity" "" vhdl-template-entity-hook 0)
2935 ("exit" "" vhdl-template-exit-hook 0)
2936 ("file" "" vhdl-template-file-hook 0)
2937 ("for" "" vhdl-template-for-hook 0)
2938 ("func" "" vhdl-template-function-hook 0)
2939 ("function" "" vhdl-template-function-hook 0)
2940 ("generic" "" vhdl-template-generic-hook 0)
2941 ("group" "" vhdl-template-group-hook 0)
2942 ("guarded" "" vhdl-template-default-hook 0)
2943 ("if" "" vhdl-template-if-hook 0)
2944 ("impure" "" vhdl-template-default-hook 0)
2945 ("in" "" vhdl-template-default-hook 0)
2946 ("inertial" "" vhdl-template-default-hook 0)
2947 ("inout" "" vhdl-template-default-hook 0)
2948 ("inst" "" vhdl-template-instance-hook 0)
2949 ("instance" "" vhdl-template-instance-hook 0)
2950 ("is" "" vhdl-template-default-hook 0)
2951 ("label" "" vhdl-template-default-hook 0)
2952 ("library" "" vhdl-template-library-hook 0)
2953 ("linkage" "" vhdl-template-default-hook 0)
2954 ("literal" "" vhdl-template-default-hook 0)
2955 ("loop" "" vhdl-template-bare-loop-hook 0)
2956 ("map" "" vhdl-template-map-hook 0)
2957 ("mod" "" vhdl-template-default-hook 0)
2958 ("nand" "" vhdl-template-default-hook 0)
2959 ("new" "" vhdl-template-default-hook 0)
2960 ("next" "" vhdl-template-next-hook 0)
2961 ("nor" "" vhdl-template-default-hook 0)
2962 ("not" "" vhdl-template-default-hook 0)
2963 ("null" "" vhdl-template-default-hook 0)
2964 ("of" "" vhdl-template-default-hook 0)
2965 ("on" "" vhdl-template-default-hook 0)
2966 ("open" "" vhdl-template-default-hook 0)
2967 ("or" "" vhdl-template-default-hook 0)
2968 ("others" "" vhdl-template-others-hook 0)
2969 ("out" "" vhdl-template-default-hook 0)
2970 ("pack" "" vhdl-template-package-hook 0)
2971 ("package" "" vhdl-template-package-hook 0)
2972 ("port" "" vhdl-template-port-hook 0)
2973 ("postponed" "" vhdl-template-default-hook 0)
2974 ("procedure" "" vhdl-template-procedure-hook 0)
2975 ("process" "" vhdl-template-process-hook 0)
2976 ("pure" "" vhdl-template-default-hook 0)
2977 ("range" "" vhdl-template-default-hook 0)
2978 ("record" "" vhdl-template-default-hook 0)
2979 ("register" "" vhdl-template-default-hook 0)
2980 ("reject" "" vhdl-template-default-hook 0)
2981 ("rem" "" vhdl-template-default-hook 0)
2982 ("report" "" vhdl-template-report-hook 0)
2983 ("return" "" vhdl-template-return-hook 0)
2984 ("rol" "" vhdl-template-default-hook 0)
2985 ("ror" "" vhdl-template-default-hook 0)
2986 ("select" "" vhdl-template-selected-signal-asst-hook 0)
2987 ("severity" "" vhdl-template-default-hook 0)
2988 ("shared" "" vhdl-template-default-hook 0)
2989 ("sig" "" vhdl-template-signal-hook 0)
2990 ("signal" "" vhdl-template-signal-hook 0)
2991 ("sla" "" vhdl-template-default-hook 0)
2992 ("sll" "" vhdl-template-default-hook 0)
2993 ("sra" "" vhdl-template-default-hook 0)
2994 ("srl" "" vhdl-template-default-hook 0)
2995 ("subtype" "" vhdl-template-subtype-hook 0)
2996 ("then" "" vhdl-template-default-hook 0)
2997 ("to" "" vhdl-template-default-hook 0)
2998 ("transport" "" vhdl-template-default-hook 0)
2999 ("type" "" vhdl-template-type-hook 0)
3000 ("unaffected" "" vhdl-template-default-hook 0)
3001 ("units" "" vhdl-template-default-hook 0)
3002 ("until" "" vhdl-template-default-hook 0)
3003 ("use" "" vhdl-template-use-hook 0)
3004 ("var" "" vhdl-template-variable-hook 0)
3005 ("variable" "" vhdl-template-variable-hook 0)
3006 ("wait" "" vhdl-template-wait-hook 0)
3007 ("when" "" vhdl-template-when-hook 0)
3008 ("while" "" vhdl-template-while-loop-hook 0)
3009 ("with" "" vhdl-template-with-hook 0)
3010 ("xnor" "" vhdl-template-default-hook 0)
3011 ("xor" "" vhdl-template-default-hook 0)
3013 ;; VHDL-AMS keywords
3014 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3016 ("across" "" vhdl-template-default-hook 0)
3017 ("break" "" vhdl-template-break-hook 0)
3018 ("limit" "" vhdl-template-limit-hook 0)
3019 ("nature" "" vhdl-template-nature-hook 0)
3020 ("noise" "" vhdl-template-default-hook 0)
3021 ("procedural" "" vhdl-template-procedural-hook 0)
3022 ("quantity" "" vhdl-template-quantity-hook 0)
3023 ("reference" "" vhdl-template-default-hook 0)
3024 ("spectrum" "" vhdl-template-default-hook 0)
3025 ("subnature" "" vhdl-template-subnature-hook 0)
3026 ("terminal" "" vhdl-template-terminal-hook 0)
3027 ("through" "" vhdl-template-default-hook 0)
3028 ("tolerance" "" vhdl-template-default-hook 0)
3030 ;; user model keywords
3031 (when (memq 'user vhdl-electric-keywords)
3032 (let ((alist vhdl-model-alist)
3033 abbrev-list keyword)
3034 (while alist
3035 (setq keyword (nth 3 (car alist)))
3036 (unless (equal keyword "")
3037 (setq abbrev-list
3038 (cons (list keyword ""
3039 (vhdl-function-name
3040 "vhdl-model" (nth 0 (car alist)) "hook") 0)
3041 abbrev-list)))
3042 (setq alist (cdr alist)))
3043 abbrev-list)))))
3045 ;; initialize abbrev table for VHDL Mode
3046 (vhdl-mode-abbrev-table-init)
3048 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3049 ;; Template completion lists
3051 (defvar vhdl-template-construct-alist nil
3052 "List of built-in construct templates.")
3054 (defun vhdl-template-construct-alist-init ()
3055 "Initialize `vhdl-template-construct-alist'."
3056 (setq
3057 vhdl-template-construct-alist
3058 (append
3060 ("alias declaration" vhdl-template-alias)
3061 ("architecture body" vhdl-template-architecture)
3062 ("assertion" vhdl-template-assert)
3063 ("attribute declaration" vhdl-template-attribute-decl)
3064 ("attribute specification" vhdl-template-attribute-spec)
3065 ("block configuration" vhdl-template-block-configuration)
3066 ("block statement" vhdl-template-block)
3067 ("case statement" vhdl-template-case-is)
3068 ("component configuration" vhdl-template-component-conf)
3069 ("component declaration" vhdl-template-component-decl)
3070 ("component instantiation statement" vhdl-template-component-inst)
3071 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3072 ("configuration declaration" vhdl-template-configuration-decl)
3073 ("configuration specification" vhdl-template-configuration-spec)
3074 ("constant declaration" vhdl-template-constant)
3075 ("disconnection specification" vhdl-template-disconnect)
3076 ("entity declaration" vhdl-template-entity)
3077 ("exit statement" vhdl-template-exit)
3078 ("file declaration" vhdl-template-file)
3079 ("generate statement" vhdl-template-generate)
3080 ("generic clause" vhdl-template-generic)
3081 ("group declaration" vhdl-template-group-decl)
3082 ("group template declaration" vhdl-template-group-template)
3083 ("if statement" vhdl-template-if-then)
3084 ("library clause" vhdl-template-library)
3085 ("loop statement" vhdl-template-loop)
3086 ("next statement" vhdl-template-next)
3087 ("package declaration" vhdl-template-package-decl)
3088 ("package body" vhdl-template-package-body)
3089 ("port clause" vhdl-template-port)
3090 ("process statement" vhdl-template-process)
3091 ("report statement" vhdl-template-report)
3092 ("return statement" vhdl-template-return)
3093 ("selected signal assignment" vhdl-template-selected-signal-asst)
3094 ("signal declaration" vhdl-template-signal)
3095 ("subprogram declaration" vhdl-template-subprogram-decl)
3096 ("subprogram body" vhdl-template-subprogram-body)
3097 ("subtype declaration" vhdl-template-subtype)
3098 ("type declaration" vhdl-template-type)
3099 ("use clause" vhdl-template-use)
3100 ("variable declaration" vhdl-template-variable)
3101 ("wait statement" vhdl-template-wait)
3103 (when (vhdl-standard-p 'ams)
3105 ("break statement" vhdl-template-break)
3106 ("nature declaration" vhdl-template-nature)
3107 ("quantity declaration" vhdl-template-quantity)
3108 ("simultaneous case statement" vhdl-template-case-use)
3109 ("simultaneous if statement" vhdl-template-if-use)
3110 ("simultaneous procedural statement" vhdl-template-procedural)
3111 ("step limit specification" vhdl-template-limit)
3112 ("subnature declaration" vhdl-template-subnature)
3113 ("terminal declaration" vhdl-template-terminal)
3114 )))))
3116 ;; initialize for VHDL Mode
3117 (vhdl-template-construct-alist-init)
3119 (defvar vhdl-template-package-alist nil
3120 "List of built-in package templates.")
3122 (defun vhdl-template-package-alist-init ()
3123 "Initialize `vhdl-template-package-alist'."
3124 (setq
3125 vhdl-template-package-alist
3126 (append
3128 ("numeric_bit" vhdl-template-package-numeric-bit)
3129 ("numeric_std" vhdl-template-package-numeric-std)
3130 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3131 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3132 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3133 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3134 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3135 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3136 ("textio" vhdl-template-package-textio)
3138 (when (vhdl-standard-p 'math)
3140 ("math_complex" vhdl-template-package-math-complex)
3141 ("math_real" vhdl-template-package-math-real)
3142 )))))
3144 ;; initialize for VHDL Mode
3145 (vhdl-template-package-alist-init)
3147 (defvar vhdl-template-directive-alist
3149 ("translate_on" vhdl-template-directive-translate-on)
3150 ("translate_off" vhdl-template-directive-translate-off)
3151 ("synthesis_on" vhdl-template-directive-synthesis-on)
3152 ("synthesis_off" vhdl-template-directive-synthesis-off)
3154 "List of built-in directive templates.")
3157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3158 ;;; Menues
3159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3162 ;; VHDL menu (using `easy-menu.el')
3164 (defun vhdl-customize ()
3165 "Call the customize function with `vhdl' as argument."
3166 (interactive)
3167 (customize-browse 'vhdl))
3169 (defun vhdl-create-mode-menu ()
3170 "Create VHDL Mode menu."
3171 `("VHDL"
3172 ,(append
3173 '("Project"
3174 ["None" (vhdl-set-project "")
3175 :style radio :selected (null vhdl-project)]
3176 "--")
3177 ;; add menu entries for defined projects
3178 (let ((project-alist vhdl-project-alist) menu-list name)
3179 (while project-alist
3180 (setq name (caar project-alist))
3181 (setq menu-list
3182 (cons `[,name (vhdl-set-project ,name)
3183 :style radio :selected (equal ,name vhdl-project)]
3184 menu-list))
3185 (setq project-alist (cdr project-alist)))
3186 (setq menu-list
3187 (if vhdl-project-sort
3188 (sort menu-list
3189 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3190 (nreverse menu-list)))
3191 (vhdl-menu-split menu-list "Project"))
3192 '("--" "--"
3193 ["Select Project..." vhdl-set-project t]
3194 ["Set As Default Project" vhdl-set-default-project t]
3195 "--"
3196 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3197 ["Import Project..." vhdl-import-project
3198 :keys "C-c C-p C-m" :active t]
3199 ["Export Project" vhdl-export-project vhdl-project]
3200 "--"
3201 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3202 "--"
3203 ("Compile"
3204 ["Compile Buffer" vhdl-compile t]
3205 ["Stop Compilation" kill-compilation t]
3206 "--"
3207 ["Make" vhdl-make t]
3208 ["Generate Makefile" vhdl-generate-makefile t]
3209 "--"
3210 ["Next Error" next-error t]
3211 ["Previous Error" previous-error t]
3212 ["First Error" first-error t]
3213 "--"
3214 ,(append
3215 '("Compiler")
3216 ;; add menu entries for defined compilers
3217 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3218 (while comp-alist
3219 (setq name (caar comp-alist))
3220 (setq menu-list
3221 (cons `[,name (setq vhdl-compiler ,name)
3222 :style radio :selected (equal ,name vhdl-compiler)]
3223 menu-list))
3224 (setq comp-alist (cdr comp-alist)))
3225 (setq menu-list (nreverse menu-list))
3226 (vhdl-menu-split menu-list "Compiler"))
3227 '("--" "--"
3228 ["Select Compiler..." vhdl-set-compiler t]
3229 "--"
3230 ["Customize Compiler..."
3231 (customize-option 'vhdl-compiler-alist) t])))
3232 "--"
3233 ,(append
3234 '("Template"
3235 ("VHDL Construct 1"
3236 ["Alias" vhdl-template-alias t]
3237 ["Architecture" vhdl-template-architecture t]
3238 ["Assert" vhdl-template-assert t]
3239 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3240 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3241 ["Block" vhdl-template-block t]
3242 ["Case" vhdl-template-case-is t]
3243 ["Component (Decl)" vhdl-template-component-decl t]
3244 ["(Component) Instance" vhdl-template-component-inst t]
3245 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3246 ["Configuration (Block)" vhdl-template-block-configuration t]
3247 ["Configuration (Comp)" vhdl-template-component-conf t]
3248 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3249 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3250 ["Constant" vhdl-template-constant t]
3251 ["Disconnect" vhdl-template-disconnect t]
3252 ["Else" vhdl-template-else t]
3253 ["Elsif" vhdl-template-elsif t]
3254 ["Entity" vhdl-template-entity t]
3255 ["Exit" vhdl-template-exit t]
3256 ["File" vhdl-template-file t]
3257 ["For (Generate)" vhdl-template-for-generate t]
3258 ["For (Loop)" vhdl-template-for-loop t]
3259 ["Function (Body)" vhdl-template-function-body t]
3260 ["Function (Decl)" vhdl-template-function-decl t]
3261 ["Generic" vhdl-template-generic t]
3262 ["Group (Decl)" vhdl-template-group-decl t]
3263 ["Group (Template)" vhdl-template-group-template t])
3264 ("VHDL Construct 2"
3265 ["If (Generate)" vhdl-template-if-generate t]
3266 ["If (Then)" vhdl-template-if-then t]
3267 ["Library" vhdl-template-library t]
3268 ["Loop" vhdl-template-bare-loop t]
3269 ["Map" vhdl-template-map t]
3270 ["Next" vhdl-template-next t]
3271 ["Others (Aggregate)" vhdl-template-others t]
3272 ["Package (Decl)" vhdl-template-package-decl t]
3273 ["Package (Body)" vhdl-template-package-body t]
3274 ["Port" vhdl-template-port t]
3275 ["Procedure (Body)" vhdl-template-procedure-body t]
3276 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3277 ["Process (Comb)" vhdl-template-process-comb t]
3278 ["Process (Seq)" vhdl-template-process-seq t]
3279 ["Report" vhdl-template-report t]
3280 ["Return" vhdl-template-return t]
3281 ["Select" vhdl-template-selected-signal-asst t]
3282 ["Signal" vhdl-template-signal t]
3283 ["Subtype" vhdl-template-subtype t]
3284 ["Type" vhdl-template-type t]
3285 ["Use" vhdl-template-use t]
3286 ["Variable" vhdl-template-variable t]
3287 ["Wait" vhdl-template-wait t]
3288 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3289 ["When" vhdl-template-when t]
3290 ["While (Loop)" vhdl-template-while-loop t]
3291 ["With" vhdl-template-with t]))
3292 (when (vhdl-standard-p 'ams)
3293 '(("VHDL-AMS Construct"
3294 ["Break" vhdl-template-break t]
3295 ["Case (Use)" vhdl-template-case-use t]
3296 ["If (Use)" vhdl-template-if-use t]
3297 ["Limit" vhdl-template-limit t]
3298 ["Nature" vhdl-template-nature t]
3299 ["Procedural" vhdl-template-procedural t]
3300 ["Quantity (Free)" vhdl-template-quantity-free t]
3301 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3302 ["Quantity (Source)" vhdl-template-quantity-source t]
3303 ["Subnature" vhdl-template-subnature t]
3304 ["Terminal" vhdl-template-terminal t])))
3305 '(["Insert Construct..." vhdl-template-insert-construct
3306 :keys "C-c C-i C-t"]
3307 "--")
3308 (list
3309 (append
3310 '("Package")
3311 (when (vhdl-standard-p 'math)
3312 '(["math_complex" vhdl-template-package-math-complex t]
3313 ["math_real" vhdl-template-package-math-real t]))
3314 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3315 ["numeric_std" vhdl-template-package-numeric-std t]
3316 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3317 ["textio" vhdl-template-package-textio t]
3318 "--"
3319 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3320 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3321 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3322 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3323 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3324 "--"
3325 ["Insert Package..." vhdl-template-insert-package
3326 :keys "C-c C-i C-p"])))
3327 '(("Directive"
3328 ["translate_on" vhdl-template-directive-translate-on t]
3329 ["translate_off" vhdl-template-directive-translate-off t]
3330 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3331 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3332 "--"
3333 ["Insert Directive..." vhdl-template-insert-directive
3334 :keys "C-c C-i C-d"])
3335 "--"
3336 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3337 ["Insert Footer" vhdl-template-footer t]
3338 ["Insert Date" vhdl-template-insert-date t]
3339 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3340 "--"
3341 ["Query Next Prompt" vhdl-template-search-prompt t]))
3342 ,(append
3343 '("Model")
3344 ;; add menu entries for defined models
3345 (let ((model-alist vhdl-model-alist) menu-list model)
3346 (while model-alist
3347 (setq model (car model-alist))
3348 (setq menu-list
3349 (cons
3350 (vector
3351 (nth 0 model)
3352 (vhdl-function-name "vhdl-model" (nth 0 model))
3353 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3354 menu-list))
3355 (setq model-alist (cdr model-alist)))
3356 (setq menu-list (nreverse menu-list))
3357 (vhdl-menu-split menu-list "Model"))
3358 '("--" "--"
3359 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3360 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3361 ("Port"
3362 ["Copy" vhdl-port-copy t]
3363 "--"
3364 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3365 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3366 ["Paste As Instance" vhdl-port-paste-instance
3367 :keys "C-c C-p C-i" :active vhdl-port-list]
3368 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3369 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3370 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3371 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3372 "--"
3373 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3374 "--"
3375 ["Flatten" vhdl-port-flatten
3376 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3377 ["Reverse Direction" vhdl-port-reverse-direction
3378 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3379 ("Compose"
3380 ["New Component" vhdl-compose-new-component t]
3381 ["Copy Component" vhdl-port-copy t]
3382 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3383 ["Wire Components" vhdl-compose-wire-components t]
3384 "--"
3385 ["Generate Configuration" vhdl-compose-configuration t]
3386 ["Generate Components Package" vhdl-compose-components-package t])
3387 ("Subprogram"
3388 ["Copy" vhdl-subprog-copy t]
3389 "--"
3390 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3391 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3392 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3393 "--"
3394 ["Flatten" vhdl-subprog-flatten
3395 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3396 "--"
3397 ("Comment"
3398 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3399 "--"
3400 ["Insert Inline Comment" vhdl-comment-append-inline t]
3401 ["Insert Horizontal Line" vhdl-comment-display-line t]
3402 ["Insert Display Comment" vhdl-comment-display t]
3403 "--"
3404 ["Fill Comment" fill-paragraph t]
3405 ["Fill Comment Region" fill-region (mark)]
3406 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3407 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3408 ("Line"
3409 ["Kill" vhdl-line-kill t]
3410 ["Copy" vhdl-line-copy t]
3411 ["Yank" vhdl-line-yank t]
3412 ["Expand" vhdl-line-expand t]
3413 "--"
3414 ["Transpose Next" vhdl-line-transpose-next t]
3415 ["Transpose Prev" vhdl-line-transpose-previous t]
3416 ["Open" vhdl-line-open t]
3417 ["Join" vhdl-delete-indentation t]
3418 "--"
3419 ["Goto" goto-line t]
3420 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3421 ("Move"
3422 ["Forward Statement" vhdl-end-of-statement t]
3423 ["Backward Statement" vhdl-beginning-of-statement t]
3424 ["Forward Expression" vhdl-forward-sexp t]
3425 ["Backward Expression" vhdl-backward-sexp t]
3426 ["Forward Same Indent" vhdl-forward-same-indent t]
3427 ["Backward Same Indent" vhdl-backward-same-indent t]
3428 ["Forward Function" vhdl-end-of-defun t]
3429 ["Backward Function" vhdl-beginning-of-defun t]
3430 ["Mark Function" vhdl-mark-defun t])
3431 "--"
3432 ("Indent"
3433 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3434 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3435 ["Region" vhdl-indent-region (mark)]
3436 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3437 ("Align"
3438 ["Group" vhdl-align-group t]
3439 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3440 ["List" vhdl-align-list t]
3441 ["Declarations" vhdl-align-declarations t]
3442 ["Region" vhdl-align-region (mark)]
3443 ["Buffer" vhdl-align-buffer t]
3444 "--"
3445 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3446 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3447 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3448 ("Fill"
3449 ["List" vhdl-fill-list t]
3450 ["Group" vhdl-fill-group t]
3451 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3452 ["Region" vhdl-fill-region (mark)])
3453 ("Beautify"
3454 ["Region" vhdl-beautify-region (mark)]
3455 ["Buffer" vhdl-beautify-buffer t])
3456 ("Fix"
3457 ["Generic/Port Clause" vhdl-fix-clause t]
3458 "--"
3459 ["Case Region" vhdl-fix-case-region (mark)]
3460 ["Case Buffer" vhdl-fix-case-buffer t]
3461 "--"
3462 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3463 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3464 "--"
3465 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3466 ("Update"
3467 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3468 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3469 "--"
3470 ["Fontify Buffer" vhdl-fontify-buffer t]
3471 ["Statistics Buffer" vhdl-statistics-buffer t]
3472 ["Show Messages" vhdl-show-messages t]
3473 ["Syntactic Info" vhdl-show-syntactic-information t]
3474 "--"
3475 ["Speedbar" vhdl-speedbar t]
3476 ["Hide/Show" vhdl-hs-minor-mode t]
3477 "--"
3478 ("Documentation"
3479 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3480 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3481 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3482 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3483 ["Version" vhdl-version t]
3484 ["Bug Report..." vhdl-submit-bug-report t]
3485 "--"
3486 ("Options"
3487 ("Mode"
3488 ["Electric Mode"
3489 (progn (customize-set-variable 'vhdl-electric-mode
3490 (not vhdl-electric-mode))
3491 (vhdl-mode-line-update))
3492 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3493 ["Stutter Mode"
3494 (progn (customize-set-variable 'vhdl-stutter-mode
3495 (not vhdl-stutter-mode))
3496 (vhdl-mode-line-update))
3497 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3498 ["Indent Tabs Mode"
3499 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3500 (not vhdl-indent-tabs-mode))
3501 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3502 :style toggle :selected vhdl-indent-tabs-mode]
3503 "--"
3504 ["Customize Group..." (customize-group 'vhdl-mode) t])
3505 ("Project"
3506 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3507 ,(append
3508 '("Selected Project at Startup"
3509 ["None" (progn (customize-set-variable 'vhdl-project nil)
3510 (vhdl-set-project ""))
3511 :style radio :selected (null vhdl-project)]
3512 "--")
3513 ;; add menu entries for defined projects
3514 (let ((project-alist vhdl-project-alist) menu-list name)
3515 (while project-alist
3516 (setq name (caar project-alist))
3517 (setq menu-list
3518 (cons `[,name (progn (customize-set-variable
3519 'vhdl-project ,name)
3520 (vhdl-set-project ,name))
3521 :style radio :selected (equal ,name vhdl-project)]
3522 menu-list))
3523 (setq project-alist (cdr project-alist)))
3524 (setq menu-list (nreverse menu-list))
3525 (vhdl-menu-split menu-list "Project")))
3526 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3527 ("Auto Load Setup File"
3528 ["At Startup"
3529 (customize-set-variable 'vhdl-project-auto-load
3530 (if (memq 'startup vhdl-project-auto-load)
3531 (delq 'startup vhdl-project-auto-load)
3532 (cons 'startup vhdl-project-auto-load)))
3533 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3534 ["Sort Projects"
3535 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3536 :style toggle :selected vhdl-project-sort]
3537 "--"
3538 ["Customize Group..." (customize-group 'vhdl-project) t])
3539 ("Compiler"
3540 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3541 ,(append
3542 '("Selected Compiler at Startup")
3543 ;; add menu entries for defined compilers
3544 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3545 (while comp-alist
3546 (setq name (caar comp-alist))
3547 (setq menu-list
3548 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3549 :style radio :selected (equal ,name vhdl-compiler)]
3550 menu-list))
3551 (setq comp-alist (cdr comp-alist)))
3552 (setq menu-list (nreverse menu-list))
3553 (vhdl-menu-split menu-list "Compler")))
3554 ["Use Local Error Regexp"
3555 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3556 (not vhdl-compile-use-local-error-regexp))
3557 :style toggle :selected vhdl-compile-use-local-error-regexp]
3558 ["Makefile Generation Hook..."
3559 (customize-option 'vhdl-makefile-generation-hook) t]
3560 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3561 "--"
3562 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3563 ("Style"
3564 ("VHDL Standard"
3565 ["VHDL'87"
3566 (progn (customize-set-variable 'vhdl-standard
3567 (list '87 (cadr vhdl-standard)))
3568 (vhdl-activate-customizations))
3569 :style radio :selected (eq '87 (car vhdl-standard))]
3570 ["VHDL'93"
3571 (progn (customize-set-variable 'vhdl-standard
3572 (list '93 (cadr vhdl-standard)))
3573 (vhdl-activate-customizations))
3574 :style radio :selected (eq '93 (car vhdl-standard))]
3575 "--"
3576 ["VHDL-AMS"
3577 (progn (customize-set-variable
3578 'vhdl-standard (list (car vhdl-standard)
3579 (if (memq 'ams (cadr vhdl-standard))
3580 (delq 'ams (cadr vhdl-standard))
3581 (cons 'ams (cadr vhdl-standard)))))
3582 (vhdl-activate-customizations))
3583 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3584 ["Math Packages"
3585 (progn (customize-set-variable
3586 'vhdl-standard (list (car vhdl-standard)
3587 (if (memq 'math (cadr vhdl-standard))
3588 (delq 'math (cadr vhdl-standard))
3589 (cons 'math (cadr vhdl-standard)))))
3590 (vhdl-activate-customizations))
3591 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3592 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3593 ["Upper Case Keywords"
3594 (customize-set-variable 'vhdl-upper-case-keywords
3595 (not vhdl-upper-case-keywords))
3596 :style toggle :selected vhdl-upper-case-keywords]
3597 ["Upper Case Types"
3598 (customize-set-variable 'vhdl-upper-case-types
3599 (not vhdl-upper-case-types))
3600 :style toggle :selected vhdl-upper-case-types]
3601 ["Upper Case Attributes"
3602 (customize-set-variable 'vhdl-upper-case-attributes
3603 (not vhdl-upper-case-attributes))
3604 :style toggle :selected vhdl-upper-case-attributes]
3605 ["Upper Case Enumeration Values"
3606 (customize-set-variable 'vhdl-upper-case-enum-values
3607 (not vhdl-upper-case-enum-values))
3608 :style toggle :selected vhdl-upper-case-enum-values]
3609 ["Upper Case Constants"
3610 (customize-set-variable 'vhdl-upper-case-constants
3611 (not vhdl-upper-case-constants))
3612 :style toggle :selected vhdl-upper-case-constants]
3613 ("Use Direct Instantiation"
3614 ["Never"
3615 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3616 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3617 ["Standard"
3618 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3619 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3620 ["Always"
3621 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3622 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3623 "--"
3624 ["Customize Group..." (customize-group 'vhdl-style) t])
3625 ("Naming"
3626 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3627 ["Architecture File Name..."
3628 (customize-option 'vhdl-architecture-file-name) t]
3629 ["Configuration File Name..."
3630 (customize-option 'vhdl-configuration-file-name) t]
3631 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3632 ("File Name Case"
3633 ["As Is"
3634 (customize-set-variable 'vhdl-file-name-case 'identity)
3635 :style radio :selected (eq 'identity vhdl-file-name-case)]
3636 ["Lower Case"
3637 (customize-set-variable 'vhdl-file-name-case 'downcase)
3638 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3639 ["Upper Case"
3640 (customize-set-variable 'vhdl-file-name-case 'upcase)
3641 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3642 ["Capitalize"
3643 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3644 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3645 "--"
3646 ["Customize Group..." (customize-group 'vhdl-naming) t])
3647 ("Template"
3648 ("Electric Keywords"
3649 ["VHDL Keywords"
3650 (customize-set-variable 'vhdl-electric-keywords
3651 (if (memq 'vhdl vhdl-electric-keywords)
3652 (delq 'vhdl vhdl-electric-keywords)
3653 (cons 'vhdl vhdl-electric-keywords)))
3654 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3655 ["User Model Keywords"
3656 (customize-set-variable 'vhdl-electric-keywords
3657 (if (memq 'user vhdl-electric-keywords)
3658 (delq 'user vhdl-electric-keywords)
3659 (cons 'user vhdl-electric-keywords)))
3660 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3661 ("Insert Optional Labels"
3662 ["None"
3663 (customize-set-variable 'vhdl-optional-labels 'none)
3664 :style radio :selected (eq 'none vhdl-optional-labels)]
3665 ["Processes Only"
3666 (customize-set-variable 'vhdl-optional-labels 'process)
3667 :style radio :selected (eq 'process vhdl-optional-labels)]
3668 ["All Constructs"
3669 (customize-set-variable 'vhdl-optional-labels 'all)
3670 :style radio :selected (eq 'all vhdl-optional-labels)])
3671 ("Insert Empty Lines"
3672 ["None"
3673 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3674 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3675 ["Design Units Only"
3676 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3677 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3678 ["All Constructs"
3679 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3680 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3681 ["Argument List Indent"
3682 (customize-set-variable 'vhdl-argument-list-indent
3683 (not vhdl-argument-list-indent))
3684 :style toggle :selected vhdl-argument-list-indent]
3685 ["Association List with Formals"
3686 (customize-set-variable 'vhdl-association-list-with-formals
3687 (not vhdl-association-list-with-formals))
3688 :style toggle :selected vhdl-association-list-with-formals]
3689 ["Conditions in Parenthesis"
3690 (customize-set-variable 'vhdl-conditions-in-parenthesis
3691 (not vhdl-conditions-in-parenthesis))
3692 :style toggle :selected vhdl-conditions-in-parenthesis]
3693 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3694 ["One String..." (customize-option 'vhdl-one-string) t]
3695 ("File Header"
3696 ["Header String..." (customize-option 'vhdl-file-header) t]
3697 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3698 ["Company Name..." (customize-option 'vhdl-company-name) t]
3699 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3700 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3701 ["Date Format..." (customize-option 'vhdl-date-format) t]
3702 ["Modify Date Prefix String..."
3703 (customize-option 'vhdl-modify-date-prefix-string) t]
3704 ["Modify Date on Saving"
3705 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3706 (not vhdl-modify-date-on-saving))
3707 (vhdl-activate-customizations))
3708 :style toggle :selected vhdl-modify-date-on-saving])
3709 ("Sequential Process"
3710 ("Kind of Reset"
3711 ["None"
3712 (customize-set-variable 'vhdl-reset-kind 'none)
3713 :style radio :selected (eq 'none vhdl-reset-kind)]
3714 ["Synchronous"
3715 (customize-set-variable 'vhdl-reset-kind 'sync)
3716 :style radio :selected (eq 'sync vhdl-reset-kind)]
3717 ["Asynchronous"
3718 (customize-set-variable 'vhdl-reset-kind 'async)
3719 :style radio :selected (eq 'async vhdl-reset-kind)])
3720 ["Reset is Active High"
3721 (customize-set-variable 'vhdl-reset-active-high
3722 (not vhdl-reset-active-high))
3723 :style toggle :selected vhdl-reset-active-high]
3724 ["Use Rising Clock Edge"
3725 (customize-set-variable 'vhdl-clock-rising-edge
3726 (not vhdl-clock-rising-edge))
3727 :style toggle :selected vhdl-clock-rising-edge]
3728 ("Clock Edge Condition"
3729 ["Standard"
3730 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3731 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3732 ["Function \"rising_edge\""
3733 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3734 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3735 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3736 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3737 "--"
3738 ["Customize Group..." (customize-group 'vhdl-template) t])
3739 ("Model"
3740 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3741 ("Port"
3742 ["Include Port Comments"
3743 (customize-set-variable 'vhdl-include-port-comments
3744 (not vhdl-include-port-comments))
3745 :style toggle :selected vhdl-include-port-comments]
3746 ["Include Direction Comments"
3747 (customize-set-variable 'vhdl-include-direction-comments
3748 (not vhdl-include-direction-comments))
3749 :style toggle :selected vhdl-include-direction-comments]
3750 ["Include Type Comments"
3751 (customize-set-variable 'vhdl-include-type-comments
3752 (not vhdl-include-type-comments))
3753 :style toggle :selected vhdl-include-type-comments]
3754 ("Include Group Comments"
3755 ["Never"
3756 (customize-set-variable 'vhdl-include-group-comments 'never)
3757 :style radio :selected (eq 'never vhdl-include-group-comments)]
3758 ["Declarations"
3759 (customize-set-variable 'vhdl-include-group-comments 'decl)
3760 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3761 ["Always"
3762 (customize-set-variable 'vhdl-include-group-comments 'always)
3763 :style radio :selected (eq 'always vhdl-include-group-comments)])
3764 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3765 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3766 ("Testbench"
3767 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3768 ["Architecture Name..."
3769 (customize-option 'vhdl-testbench-architecture-name) t]
3770 ["Configuration Name..."
3771 (customize-option 'vhdl-testbench-configuration-name) t]
3772 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3773 ["Include Header"
3774 (customize-set-variable 'vhdl-testbench-include-header
3775 (not vhdl-testbench-include-header))
3776 :style toggle :selected vhdl-testbench-include-header]
3777 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3778 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3779 ["Initialize Signals"
3780 (customize-set-variable 'vhdl-testbench-initialize-signals
3781 (not vhdl-testbench-initialize-signals))
3782 :style toggle :selected vhdl-testbench-initialize-signals]
3783 ["Include Library Clause"
3784 (customize-set-variable 'vhdl-testbench-include-library
3785 (not vhdl-testbench-include-library))
3786 :style toggle :selected vhdl-testbench-include-library]
3787 ["Include Configuration"
3788 (customize-set-variable 'vhdl-testbench-include-configuration
3789 (not vhdl-testbench-include-configuration))
3790 :style toggle :selected vhdl-testbench-include-configuration]
3791 ("Create Files"
3792 ["None"
3793 (customize-set-variable 'vhdl-testbench-create-files 'none)
3794 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3795 ["Single"
3796 (customize-set-variable 'vhdl-testbench-create-files 'single)
3797 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3798 ["Separate"
3799 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3800 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3801 ["Testbench Entity File Name..."
3802 (customize-option 'vhdl-testbench-entity-file-name) t]
3803 ["Testbench Architecture File Name..."
3804 (customize-option 'vhdl-testbench-architecture-file-name) t])
3805 "--"
3806 ["Customize Group..." (customize-group 'vhdl-port) t])
3807 ("Compose"
3808 ["Architecture Name..."
3809 (customize-option 'vhdl-compose-architecture-name) t]
3810 ["Configuration Name..."
3811 (customize-option 'vhdl-compose-configuration-name) t]
3812 ["Components Package Name..."
3813 (customize-option 'vhdl-components-package-name) t]
3814 ["Use Components Package"
3815 (customize-set-variable 'vhdl-use-components-package
3816 (not vhdl-use-components-package))
3817 :style toggle :selected vhdl-use-components-package]
3818 ["Include Header"
3819 (customize-set-variable 'vhdl-compose-include-header
3820 (not vhdl-compose-include-header))
3821 :style toggle :selected vhdl-compose-include-header]
3822 ("Create Entity/Architecture Files"
3823 ["None"
3824 (customize-set-variable 'vhdl-compose-create-files 'none)
3825 :style radio :selected (eq 'none vhdl-compose-create-files)]
3826 ["Single"
3827 (customize-set-variable 'vhdl-compose-create-files 'single)
3828 :style radio :selected (eq 'single vhdl-compose-create-files)]
3829 ["Separate"
3830 (customize-set-variable 'vhdl-compose-create-files 'separate)
3831 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3832 ["Create Configuration File"
3833 (customize-set-variable 'vhdl-compose-configuration-create-file
3834 (not vhdl-compose-configuration-create-file))
3835 :style toggle :selected vhdl-compose-configuration-create-file]
3836 ["Hierarchical Configuration"
3837 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3838 (not vhdl-compose-configuration-hierarchical))
3839 :style toggle :selected vhdl-compose-configuration-hierarchical]
3840 ["Use Subconfiguration"
3841 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3842 (not vhdl-compose-configuration-use-subconfiguration))
3843 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3844 "--"
3845 ["Customize Group..." (customize-group 'vhdl-compose) t])
3846 ("Comment"
3847 ["Self Insert Comments"
3848 (customize-set-variable 'vhdl-self-insert-comments
3849 (not vhdl-self-insert-comments))
3850 :style toggle :selected vhdl-self-insert-comments]
3851 ["Prompt for Comments"
3852 (customize-set-variable 'vhdl-prompt-for-comments
3853 (not vhdl-prompt-for-comments))
3854 :style toggle :selected vhdl-prompt-for-comments]
3855 ["Inline Comment Column..."
3856 (customize-option 'vhdl-inline-comment-column) t]
3857 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3858 "--"
3859 ["Customize Group..." (customize-group 'vhdl-comment) t])
3860 ("Align"
3861 ["Auto Align Templates"
3862 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3863 :style toggle :selected vhdl-auto-align]
3864 ["Align Line Groups"
3865 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3866 :style toggle :selected vhdl-align-groups]
3867 ["Group Separation String..."
3868 (customize-set-variable 'vhdl-align-group-separate) t]
3869 ["Align Lines with Same Indent"
3870 (customize-set-variable 'vhdl-align-same-indent
3871 (not vhdl-align-same-indent))
3872 :style toggle :selected vhdl-align-same-indent]
3873 "--"
3874 ["Customize Group..." (customize-group 'vhdl-align) t])
3875 ("Highlight"
3876 ["Highlighting On/Off..."
3877 (customize-option
3878 (if (fboundp 'global-font-lock-mode)
3879 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3880 ["Highlight Keywords"
3881 (progn (customize-set-variable 'vhdl-highlight-keywords
3882 (not vhdl-highlight-keywords))
3883 (vhdl-fontify-buffer))
3884 :style toggle :selected vhdl-highlight-keywords]
3885 ["Highlight Names"
3886 (progn (customize-set-variable 'vhdl-highlight-names
3887 (not vhdl-highlight-names))
3888 (vhdl-fontify-buffer))
3889 :style toggle :selected vhdl-highlight-names]
3890 ["Highlight Special Words"
3891 (progn (customize-set-variable 'vhdl-highlight-special-words
3892 (not vhdl-highlight-special-words))
3893 (vhdl-fontify-buffer))
3894 :style toggle :selected vhdl-highlight-special-words]
3895 ["Highlight Forbidden Words"
3896 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3897 (not vhdl-highlight-forbidden-words))
3898 (vhdl-fontify-buffer))
3899 :style toggle :selected vhdl-highlight-forbidden-words]
3900 ["Highlight Verilog Keywords"
3901 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3902 (not vhdl-highlight-verilog-keywords))
3903 (vhdl-fontify-buffer))
3904 :style toggle :selected vhdl-highlight-verilog-keywords]
3905 ["Highlight \"translate_off\""
3906 (progn (customize-set-variable 'vhdl-highlight-translate-off
3907 (not vhdl-highlight-translate-off))
3908 (vhdl-fontify-buffer))
3909 :style toggle :selected vhdl-highlight-translate-off]
3910 ["Case Sensitive Highlighting"
3911 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3912 (not vhdl-highlight-case-sensitive))
3913 (vhdl-fontify-buffer))
3914 :style toggle :selected vhdl-highlight-case-sensitive]
3915 ["Special Syntax Definition..."
3916 (customize-option 'vhdl-special-syntax-alist) t]
3917 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3918 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3919 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3920 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3921 "--"
3922 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3923 ("Speedbar"
3924 ["Auto Open at Startup"
3925 (customize-set-variable 'vhdl-speedbar-auto-open
3926 (not vhdl-speedbar-auto-open))
3927 :style toggle :selected vhdl-speedbar-auto-open]
3928 ("Default Displaying Mode"
3929 ["Files"
3930 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3931 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3932 ["Directory Hierarchy"
3933 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3934 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3935 ["Project Hierarchy"
3936 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3937 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3938 ["Indentation Offset..."
3939 (customize-option 'speedbar-indentation-width) t]
3940 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3941 ["Jump to Unit when Opening"
3942 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3943 (not vhdl-speedbar-jump-to-unit))
3944 :style toggle :selected vhdl-speedbar-jump-to-unit]
3945 ["Update Hierarchy on File Saving"
3946 (customize-set-variable 'vhdl-speedbar-update-on-saving
3947 (not vhdl-speedbar-update-on-saving))
3948 :style toggle :selected vhdl-speedbar-update-on-saving]
3949 ("Save in Cache File"
3950 ["Hierarchy Information"
3951 (customize-set-variable 'vhdl-speedbar-save-cache
3952 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3953 (delq 'hierarchy vhdl-speedbar-save-cache)
3954 (cons 'hierarchy vhdl-speedbar-save-cache)))
3955 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3956 ["Displaying Status"
3957 (customize-set-variable 'vhdl-speedbar-save-cache
3958 (if (memq 'display vhdl-speedbar-save-cache)
3959 (delq 'display vhdl-speedbar-save-cache)
3960 (cons 'display vhdl-speedbar-save-cache)))
3961 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3962 ["Cache File Name..."
3963 (customize-option 'vhdl-speedbar-cache-file-name) t]
3964 "--"
3965 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3966 ("Menu"
3967 ["Add Index Menu when Loading File"
3968 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3969 (vhdl-index-menu-init))
3970 :style toggle :selected vhdl-index-menu]
3971 ["Add Source File Menu when Loading File"
3972 (progn (customize-set-variable 'vhdl-source-file-menu
3973 (not vhdl-source-file-menu))
3974 (vhdl-add-source-files-menu))
3975 :style toggle :selected vhdl-source-file-menu]
3976 ["Add Hideshow Menu at Startup"
3977 (progn (customize-set-variable 'vhdl-hideshow-menu
3978 (not vhdl-hideshow-menu))
3979 (vhdl-activate-customizations))
3980 :style toggle :selected vhdl-hideshow-menu]
3981 ["Hide Everything Initially"
3982 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3983 :style toggle :selected vhdl-hide-all-init]
3984 "--"
3985 ["Customize Group..." (customize-group 'vhdl-menu) t])
3986 ("Print"
3987 ["In Two Column Format"
3988 (progn (customize-set-variable 'vhdl-print-two-column
3989 (not vhdl-print-two-column))
3990 (message "Activate new setting by saving options and restarting Emacs"))
3991 :style toggle :selected vhdl-print-two-column]
3992 ["Use Customized Faces"
3993 (progn (customize-set-variable 'vhdl-print-customize-faces
3994 (not vhdl-print-customize-faces))
3995 (message "Activate new setting by saving options and restarting Emacs"))
3996 :style toggle :selected vhdl-print-customize-faces]
3997 "--"
3998 ["Customize Group..." (customize-group 'vhdl-print) t])
3999 ("Miscellaneous"
4000 ["Use Intelligent Tab"
4001 (progn (customize-set-variable 'vhdl-intelligent-tab
4002 (not vhdl-intelligent-tab))
4003 (vhdl-activate-customizations))
4004 :style toggle :selected vhdl-intelligent-tab]
4005 ["Indent Syntax-Based"
4006 (customize-set-variable 'vhdl-indent-syntax-based
4007 (not vhdl-indent-syntax-based))
4008 :style toggle :selected vhdl-indent-syntax-based]
4009 ["Word Completion is Case Sensitive"
4010 (customize-set-variable 'vhdl-word-completion-case-sensitive
4011 (not vhdl-word-completion-case-sensitive))
4012 :style toggle :selected vhdl-word-completion-case-sensitive]
4013 ["Word Completion in Minibuffer"
4014 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4015 (not vhdl-word-completion-in-minibuffer))
4016 (message "Activate new setting by saving options and restarting Emacs"))
4017 :style toggle :selected vhdl-word-completion-in-minibuffer]
4018 ["Underscore is Part of Word"
4019 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4020 (not vhdl-underscore-is-part-of-word))
4021 (vhdl-activate-customizations))
4022 :style toggle :selected vhdl-underscore-is-part-of-word]
4023 "--"
4024 ["Customize Group..." (customize-group 'vhdl-misc) t])
4025 ["Related..." (customize-browse 'vhdl-related) t]
4026 "--"
4027 ["Save Options" customize-save-customized t]
4028 ["Activate Options" vhdl-activate-customizations t]
4029 ["Browse Options..." vhdl-customize t])))
4031 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4032 "VHDL Mode menu.")
4034 (defun vhdl-update-mode-menu ()
4035 "Update VHDL Mode menu."
4036 (interactive)
4037 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4038 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4039 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4040 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4041 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4043 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4044 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4046 (defconst vhdl-imenu-generic-expression
4048 ("Subprogram"
4049 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4051 ("Instance"
4052 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4054 ("Component"
4055 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4057 ("Procedural"
4058 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4060 ("Process"
4061 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4063 ("Block"
4064 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4066 ("Package"
4067 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4069 ("Configuration"
4070 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4072 ("Architecture"
4073 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4075 ("Entity"
4076 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4079 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4081 (defun vhdl-index-menu-init ()
4082 "Initialize index menu."
4083 (set (make-local-variable 'imenu-case-fold-search) t)
4084 (set (make-local-variable 'imenu-generic-expression)
4085 vhdl-imenu-generic-expression)
4086 (when (and vhdl-index-menu (fboundp 'imenu))
4087 (if (or (not (boundp 'font-lock-maximum-size))
4088 (> font-lock-maximum-size (buffer-size)))
4089 (imenu-add-to-menubar "Index")
4090 (message "Scanning buffer for index...buffer too big"))))
4092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4093 ;; Source file menu (using `easy-menu.el')
4095 (defvar vhdl-sources-menu nil)
4097 (defun vhdl-directory-files (directory &optional full match)
4098 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4099 message."
4100 (if (not (file-directory-p directory))
4101 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4102 (let ((dir (directory-files directory full match)))
4103 (setq dir (delete "." dir))
4104 (setq dir (delete ".." dir))
4105 dir)))
4107 (defun vhdl-get-source-files (&optional full directory)
4108 "Get list of VHDL source files in DIRECTORY or current directory."
4109 (let ((mode-alist auto-mode-alist)
4110 filename-regexp)
4111 ;; create regular expressions for matching file names
4112 (setq filename-regexp "\\`[^.].*\\(")
4113 (while mode-alist
4114 (when (eq (cdar mode-alist) 'vhdl-mode)
4115 (setq filename-regexp
4116 (concat filename-regexp (caar mode-alist) "\\|")))
4117 (setq mode-alist (cdr mode-alist)))
4118 (setq filename-regexp
4119 (concat (substring filename-regexp 0
4120 (string-match "\\\\|$" filename-regexp)) "\\)"))
4121 ;; find files
4122 (vhdl-directory-files
4123 (or directory default-directory) full filename-regexp)))
4125 (defun vhdl-add-source-files-menu ()
4126 "Scan directory for all VHDL source files and generate menu.
4127 The directory of the current source file is scanned."
4128 (interactive)
4129 (message "Scanning directory for source files ...")
4130 (let ((newmap (current-local-map))
4131 (file-list (vhdl-get-source-files))
4132 menu-list found)
4133 ;; Create list for menu
4134 (setq found nil)
4135 (while file-list
4136 (setq found t)
4137 (setq menu-list (cons (vector (car file-list)
4138 (list 'find-file (car file-list)) t)
4139 menu-list))
4140 (setq file-list (cdr file-list)))
4141 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4142 (when found (setq menu-list (cons "--" menu-list)))
4143 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4144 (setq menu-list (cons "Sources" menu-list))
4145 ;; Create menu
4146 (easy-menu-add menu-list)
4147 (easy-menu-define vhdl-sources-menu newmap
4148 "VHDL source files menu" menu-list))
4149 (message ""))
4152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4153 ;;; Mode definition
4154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4155 ;; performs all buffer local initializations
4157 ;;;###autoload
4158 (defun vhdl-mode ()
4159 "Major mode for editing VHDL code.
4161 Usage:
4162 ------
4164 TEMPLATE INSERTION (electrification):
4165 After typing a VHDL keyword and entering `SPC', you are prompted for
4166 arguments while a template is generated for that VHDL construct. Typing
4167 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4168 template generation. Optional arguments are indicated by square
4169 brackets and removed if the queried string is left empty. Prompts for
4170 mandatory arguments remain in the code if the queried string is left
4171 empty. They can be queried again by `C-c C-t C-q'. Enabled
4172 electrification is indicated by `/e' in the modeline.
4174 Typing `M-SPC' after a keyword inserts a space without calling the
4175 template generator. Automatic template generation (i.e.
4176 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4177 setting option `vhdl-electric-mode' (see OPTIONS).
4179 Template generators can be invoked from the VHDL menu, by key
4180 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4181 the keyword (i.e. first word of menu entry not in parenthesis) and
4182 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4183 conf, comp, cons, func, inst, pack, sig, var.
4185 Template styles can be customized in customization group
4186 `vhdl-template' \(see OPTIONS).
4189 HEADER INSERTION:
4190 A file header can be inserted by `C-c C-t C-h'. A file footer
4191 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4192 See customization group `vhdl-header'.
4195 STUTTERING:
4196 Double striking of some keys inserts cumbersome VHDL syntax elements.
4197 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4198 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4199 the modeline. The stuttering keys and their effects are:
4201 ;; --> \" : \" [ --> ( -- --> comment
4202 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4203 .. --> \" => \" ] --> ) --- --> horizontal line
4204 ,, --> \" <= \" ]] --> ] ---- --> display comment
4205 == --> \" == \" '' --> \\\"
4208 WORD COMPLETION:
4209 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4210 word in the buffer that starts alike, inserts it and adjusts case.
4211 Re-typing `TAB' toggles through alternative word completions. This also
4212 works in the minibuffer (i.e. in template generator prompts).
4214 Typing `TAB' after `(' looks for and inserts complete parenthesized
4215 expressions (e.g. for array index ranges). All keywords as well as
4216 standard types and subprograms of VHDL have predefined abbreviations
4217 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4218 beginning with \"std\").
4220 Typing `TAB' after a non-word character indents the line if at the
4221 beginning of a line (i.e. no preceding non-blank characters), and
4222 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4223 stop.
4226 COMMENTS:
4227 `--' puts a single comment.
4228 `---' draws a horizontal line for separating code segments.
4229 `----' inserts a display comment, i.e. two horizontal lines
4230 with a comment in between.
4231 `--CR' comments out code on that line. Re-hitting CR comments
4232 out following lines.
4233 `C-c c' comments out a region if not commented out,
4234 uncomments a region if already commented out.
4236 You are prompted for comments after object definitions (i.e. signals,
4237 variables, constants, ports) and after subprogram and process
4238 specifications if option `vhdl-prompt-for-comments' is non-nil.
4239 Comments are automatically inserted as additional labels (e.g. after
4240 begin statements) and as help comments if `vhdl-self-insert-comments' is
4241 non-nil.
4243 Inline comments (i.e. comments after a piece of code on the same line)
4244 are indented at least to `vhdl-inline-comment-column'. Comments go at
4245 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4246 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4247 in a comment automatically opens a new comment line. `M-q' re-fills
4248 multi-line comments.
4251 INDENTATION:
4252 `TAB' indents a line if at the beginning of the line. The amount of
4253 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4254 always indents the current line (is bound to `TAB' if option
4255 `vhdl-intelligent-tab' is nil).
4257 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4258 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4259 indented normally (nil) or relative to the opening parenthesis (non-nil)
4260 according to option `vhdl-argument-list-indent'.
4262 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4263 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4264 and vice versa.
4266 Syntax-based indentation can be very slow in large files. Option
4267 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4270 ALIGNMENT:
4271 The alignment functions align operators, keywords, and inline comments
4272 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4273 separated by blank lines, `C-c C-a C-i' a block of lines with same
4274 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4275 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4276 C-a C-d' all lines within the declarative part of a design unit. `C-c
4277 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4278 for a group of lines, and `C-c C-a M-c' for a region.
4280 If option `vhdl-align-groups' is non-nil, groups of code lines
4281 separated by special lines (see option `vhdl-align-group-separate') are
4282 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4283 blocks of lines with same indent are aligned separately. Some templates
4284 are automatically aligned after generation if option `vhdl-auto-align'
4285 is non-nil.
4287 Alignment tries to align inline comments at
4288 `vhdl-inline-comment-column' and tries inline comment not to exceed
4289 `vhdl-end-comment-column'.
4291 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4292 symbols are surrounded by one space, and multiple spaces are eliminated.
4295 CODE FILLING:
4296 Code filling allows to condense code (e.g. sensitivity lists or port
4297 maps) by removing comments and newlines and re-wrapping so that all
4298 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4299 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4300 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4301 `C-c C-f M-f' an entire region.
4304 CODE BEAUTIFICATION:
4305 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4306 buffer respectively. This inludes indentation, alignment, and case
4307 fixing. Code beautification can also be run non-interactively using the
4308 command:
4310 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4313 PORT TRANSLATION:
4314 Generic and port clauses from entity or component declarations can be
4315 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4316 as component instantiations and corresponding internal constants and
4317 signals, as a generic map with constants as actual generics, and as
4318 internal signal initializations (menu).
4320 To include formals in component instantiations, see option
4321 `vhdl-association-list-with-formals'. To include comments in pasting,
4322 see options `vhdl-include-...-comments'.
4324 A clause with several generic/port names on the same line can be
4325 flattened (`C-c C-p C-f') so that only one name per line exists. The
4326 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4327 outputs and vice versa, which can be useful in testbenches. (This
4328 reversion is done on the internal data structure and is only reflected
4329 in subsequent paste operations.)
4331 Names for actual ports, instances, testbenches, and
4332 design-under-test instances can be derived from existing names according
4333 to options `vhdl-...-name'. See customization group `vhdl-port'.
4336 SUBPROGRAM TRANSLATION:
4337 Similar functionality exists for copying/pasting the interface of
4338 subprograms (function/procedure). A subprogram interface can be copied
4339 and then pasted as a subprogram declaration, body or call (uses
4340 association list with formals).
4343 TESTBENCH GENERATION:
4344 A copied port can also be pasted as a testbench. The generated
4345 testbench includes an entity, an architecture, and an optional
4346 configuration. The architecture contains the component declaration and
4347 instantiation of the DUT as well as internal constant and signal
4348 declarations. Additional user-defined templates can be inserted. The
4349 names used for entity/architecture/configuration/DUT as well as the file
4350 structure to be generated can be customized. See customization group
4351 `vhdl-testbench'.
4354 KEY BINDINGS:
4355 Key bindings (`C-c ...') exist for most commands (see in menu).
4358 VHDL MENU:
4359 All commands can be found in the VHDL menu including their key bindings.
4362 FILE BROWSER:
4363 The speedbar allows browsing of directories and file contents. It can
4364 be accessed from the VHDL menu and is automatically opened if option
4365 `vhdl-speedbar-auto-open' is non-nil.
4367 In speedbar, open files and directories with `mouse-2' on the name and
4368 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4371 DESIGN HIERARCHY BROWSER:
4372 The speedbar can also be used for browsing the hierarchy of design units
4373 contained in the source files of the current directory or the specified
4374 projects (see option `vhdl-project-alist').
4376 The speedbar can be switched between file, directory hierarchy and
4377 project hierarchy browsing mode in the speedbar menu or by typing `f',
4378 `h' or `H' in speedbar.
4380 In speedbar, open design units with `mouse-2' on the name and browse
4381 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4382 from entities and components (in packages). Individual design units and
4383 complete designs can directly be compiled (\"Make\" menu entry).
4385 The hierarchy is automatically updated upon saving a modified source
4386 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4387 hierarchy is only updated for projects that have been opened once in the
4388 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4389 options in group `vhdl-speedbar').
4391 Simple design consistency checks are done during scanning, such as
4392 multiple declarations of the same unit or missing primary units that are
4393 required by secondary units.
4396 STRUCTURAL COMPOSITION:
4397 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4398 for a new component. Subcomponents (i.e. component declaration and
4399 instantiation) can be automatically placed from a previously read port
4400 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4401 all subcomponents can be automatically connected using internal signals
4402 and ports (`C-c C-c C-w') following these rules:
4403 - subcomponent actual ports with same name are considered to be
4404 connected by a signal (internal signal or port)
4405 - signals that are only inputs to subcomponents are considered as
4406 inputs to this component -> input port created
4407 - signals that are only outputs from subcomponents are considered as
4408 outputs from this component -> output port created
4409 - signals that are inputs to AND outputs from subcomponents are
4410 considered as internal connections -> internal signal created
4412 Purpose: With appropriate naming conventions it is possible to
4413 create higher design levels with only a few mouse clicks or key
4414 strokes. A new design level can be created by simply generating a new
4415 component, placing the required subcomponents from the hierarchy
4416 browser, and wiring everything automatically.
4418 Note: Automatic wiring only works reliably on templates of new
4419 components and component instantiations that were created by VHDL mode.
4421 Component declarations can be placed in a components package (option
4422 `vhdl-use-components-package') which can be automatically generated for
4423 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4424 component instantiation is also supported (option
4425 `vhdl-use-direct-instantiation').
4427 | Configuration declarations can automatically be generated either from
4428 | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4429 | the speedbar menu (for the architecture under the cursor). The
4430 | configurations can optionally be hierarchical (i.e. include all
4431 | component levels of a hierarchical design, option
4432 | `vhdl-compose-configuration-hierarchical') or include subconfigurations
4433 | (option `vhdl-compose-configuration-use-subconfiguration'). For
4434 | subcomponents in hierarchical configurations, the most-recently-analyzed
4435 | (mra) architecture is selected. If another architecture is desired, it
4436 | can be marked as most-recently-analyzed (speedbar menu) before
4437 | generating the configuration.
4439 | Note: Configurations of subcomponents (i.e. hierarchical configuration
4440 | declarations) are currently not considered when displaying
4441 | configurations in speedbar.
4443 See the options group `vhdl-compose' for all relevant user options.
4446 SOURCE FILE COMPILATION:
4447 The syntax of the current buffer can be analyzed by calling a VHDL
4448 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4449 option `vhdl-compiler'. The available compilers are listed in option
4450 `vhdl-compiler-alist' including all required compilation command,
4451 command options, compilation directory, and error message syntax
4452 information. New compilers can be added.
4454 All the source files of an entire design can be compiled by the `make'
4455 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4458 MAKEFILE GENERATION:
4459 Makefiles can be generated automatically by an internal generation
4460 routine (`C-c M-k'). The library unit dependency information is
4461 obtained from the hierarchy browser. Makefile generation can be
4462 customized for each compiler in option `vhdl-compiler-alist'.
4464 Makefile generation can also be run non-interactively using the
4465 command:
4467 emacs -batch -l ~/.emacs -l vhdl-mode
4468 [-compiler compilername] [-project projectname]
4469 -f vhdl-generate-makefile
4471 The Makefile's default target \"all\" compiles the entire design, the
4472 target \"clean\" removes it and the target \"library\" creates the
4473 library directory if not existent. The Makefile also includes a target
4474 for each primary library unit which allows selective compilation of this
4475 unit, its secondary units and its subhierarchy (example: compilation of
4476 a design specified by a configuration). User specific parts can be
4477 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4479 Limitations:
4480 - Only library units and dependencies within the current library are
4481 considered. Makefiles for designs that span multiple libraries are
4482 not (yet) supported.
4483 - Only one-level configurations are supported (also hierarchical),
4484 but configurations that go down several levels are not.
4485 - The \"others\" keyword in configurations is not supported.
4488 PROJECTS:
4489 Projects can be defined in option `vhdl-project-alist' and a current
4490 project be selected using option `vhdl-project' (permanently) or from
4491 the menu or speedbar (temporarily). For each project, title and
4492 description strings (for the file headers), source files/directories
4493 (for the hierarchy browser and Makefile generation), library name, and
4494 compiler-dependent options, exceptions and compilation directory can be
4495 specified. Compilation settings overwrite the settings of option
4496 `vhdl-compiler-alist'.
4498 Project setups can be exported (i.e. written to a file) and imported.
4499 Imported setups are not automatically saved in `vhdl-project-alist' but
4500 can be saved afterwards in its customization buffer. When starting
4501 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4502 vhdl-mode\") in a directory with an existing project setup file, it is
4503 automatically loaded and its project activated if option
4504 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4505 files can be specified in option `vhdl-project-file-name'. Multiple
4506 project setups can be automatically loaded from global directories.
4507 This is an alternative to specifying project setups with option
4508 `vhdl-project-alist'.
4511 SPECIAL MENUES:
4512 As an alternative to the speedbar, an index menu can be added (set
4513 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4514 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4515 file) for browsing the file contents (is not populated if buffer is
4516 larger than `font-lock-maximum-size'). Also, a source file menu can be
4517 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4518 current directory for VHDL source files.
4521 VHDL STANDARDS:
4522 The VHDL standards to be used are specified in option `vhdl-standard'.
4523 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4526 KEYWORD CASE:
4527 Lower and upper case for keywords and standardized types, attributes,
4528 and enumeration values is supported. If the option
4529 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4530 lower case and are converted into upper case automatically (not for
4531 types, attributes, and enumeration values). The case of keywords,
4532 types, attributes,and enumeration values can be fixed for an entire
4533 region (menu) or buffer (`C-c C-x C-c') according to the options
4534 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4537 HIGHLIGHTING (fontification):
4538 Keywords and standardized types, attributes, enumeration values, and
4539 function names (controlled by option `vhdl-highlight-keywords'), as well
4540 as comments, strings, and template prompts are highlighted using
4541 different colors. Unit, subprogram, signal, variable, constant,
4542 parameter and generic/port names in declarations as well as labels are
4543 highlighted if option `vhdl-highlight-names' is non-nil.
4545 Additional reserved words or words with a forbidden syntax (e.g. words
4546 that should be avoided) can be specified in option
4547 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4548 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4549 keywords are highlighted as forbidden words if option
4550 `vhdl-highlight-verilog-keywords' is non-nil.
4552 Words with special syntax can be highlighted by specifying their
4553 syntax and color in option `vhdl-special-syntax-alist' and by setting
4554 option `vhdl-highlight-special-words' to non-nil. This allows to
4555 establish some naming conventions (e.g. to distinguish different kinds
4556 of signals or other objects by using name suffices) and to support them
4557 visually.
4559 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4560 to support case-sensitive highlighting. However, keywords are then only
4561 highlighted if written in lower case.
4563 Code between \"translate_off\" and \"translate_on\" pragmas is
4564 highlighted using a different background color if option
4565 `vhdl-highlight-translate-off' is non-nil.
4567 For documentation and customization of the used colors see
4568 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4569 highlighting of matching parenthesis, see customization group
4570 `paren-showing'. Automatic buffer highlighting is turned on/off by
4571 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4574 USER MODELS:
4575 VHDL models (templates) can be specified by the user and made accessible
4576 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4577 electrification. See option `vhdl-model-alist'.
4580 HIDE/SHOW:
4581 The code of blocks, processes, subprograms, component declarations and
4582 instantiations, generic/port clauses, and configuration declarations can
4583 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4584 the code (see customization group `vhdl-menu'). XEmacs: limited
4585 functionality due to old `hideshow.el' package.
4588 CODE UPDATING:
4589 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4590 current process, `C-c C-u M-s' of all processes in the current buffer.
4591 Limitations:
4592 - Only declared local signals (ports, signals declared in
4593 architecture and blocks) are automatically inserted.
4594 - Global signals declared in packages are not automatically inserted.
4595 Insert them once manually (will be kept afterwards).
4596 - Out parameters of procedures are considered to be read.
4597 Use option `vhdl-entity-file-name' to specify the entity file name
4598 \(used to obtain the port names).
4601 CODE FIXING:
4602 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4603 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4606 PRINTING:
4607 Postscript printing with different faces (an optimized set of faces is
4608 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4609 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4610 postscript printing commands. Option `vhdl-print-two-column' defines
4611 appropriate default settings for nice landscape two-column printing.
4612 The paper format can be set by option `ps-paper-type'. Do not forget to
4613 switch `ps-print-color-p' to nil for printing on black-and-white
4614 printers.
4617 OPTIONS:
4618 User options allow customization of VHDL Mode. All options are
4619 accessible from the \"Options\" menu entry. Simple options (switches
4620 and choices) can directly be changed, while for complex options a
4621 customization buffer is opened. Changed options can be saved for future
4622 sessions using the \"Save Options\" menu entry.
4624 Options and their detailed descriptions can also be accessed by using
4625 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4626 customize-group' for groups). Some customizations only take effect
4627 after some action (read the NOTE in the option documentation).
4628 Customization can also be done globally (i.e. site-wide, read the
4629 INSTALL file).
4631 Not all options are described in this documentation, so go and see
4632 what other useful user options there are (`M-x vhdl-customize' or menu)!
4635 FILE EXTENSIONS:
4636 As default, files with extensions \".vhd\" and \".vhdl\" are
4637 automatically recognized as VHDL source files. To add an extension
4638 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4640 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4643 HINTS:
4644 - To start Emacs with open VHDL hierarchy browser without having to load
4645 a VHDL file first, use the command:
4647 emacs -l vhdl-mode -f speedbar-frame-mode
4649 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4651 - Some features only work on properly indented code.
4654 RELEASE NOTES:
4655 See also the release notes (menu) for added features in new releases.
4658 Maintenance:
4659 ------------
4661 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4662 Add a description of the problem and include a reproducible test case.
4664 Questions and enhancement requests can be sent to <reto@gnu.org>.
4666 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4667 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4668 releases. You are kindly invited to participate in beta testing. Subscribe
4669 to above mailing lists by sending an email to <reto@gnu.org>.
4671 VHDL Mode is officially distributed at
4672 http://opensource.ethz.ch/emacs/vhdl-mode.html
4673 where the latest version can be found.
4676 Known problems:
4677 ---------------
4679 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4680 - XEmacs: Incorrect start-up when automatically opening speedbar.
4681 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4684 The VHDL Mode Authors
4685 Reto Zimmermann and Rod Whitby
4687 Key bindings:
4688 -------------
4690 \\{vhdl-mode-map}"
4691 (interactive)
4692 (kill-all-local-variables)
4693 (setq major-mode 'vhdl-mode)
4694 (setq mode-name "VHDL")
4696 ;; set maps and tables
4697 (use-local-map vhdl-mode-map)
4698 (set-syntax-table vhdl-mode-syntax-table)
4699 (setq local-abbrev-table vhdl-mode-abbrev-table)
4701 ;; set local variables
4702 (set (make-local-variable 'paragraph-start)
4703 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4704 (set (make-local-variable 'paragraph-separate) paragraph-start)
4705 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4706 (set (make-local-variable 'require-final-newline)
4707 (if vhdl-emacs-22 mode-require-final-newline t))
4708 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4709 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4710 (set (make-local-variable 'comment-start) "--")
4711 (set (make-local-variable 'comment-end) "")
4712 (when vhdl-emacs-21
4713 (set (make-local-variable 'comment-padding) ""))
4714 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4715 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4716 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4717 (set (make-local-variable 'comment-multi-line) nil)
4718 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4719 (set (make-local-variable 'hippie-expand-verbose) nil)
4721 ;; setup the comment indent variable in a Emacs version portable way
4722 ;; ignore any byte compiler warnings you might get here
4723 (when (boundp 'comment-indent-function)
4724 (make-local-variable 'comment-indent-function)
4725 (setq comment-indent-function 'vhdl-comment-indent))
4727 ;; initialize font locking
4728 (set (make-local-variable 'font-lock-defaults)
4729 (list
4730 '(nil vhdl-font-lock-keywords) nil
4731 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4732 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4733 (unless vhdl-emacs-21
4734 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4735 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4736 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4737 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4738 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4739 ; (turn-on-font-lock)
4741 ;; variables for source file compilation
4742 (when vhdl-compile-use-local-error-regexp
4743 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4744 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4746 ;; add index menu
4747 (vhdl-index-menu-init)
4748 ;; add source file menu
4749 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4750 ;; add VHDL menu
4751 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4752 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4753 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4754 ;; initialize hideshow and add menu
4755 (vhdl-hideshow-init)
4756 (run-hooks 'menu-bar-update-hook)
4758 ;; miscellaneous
4759 (vhdl-ps-print-init)
4760 (vhdl-write-file-hooks-init)
4761 (vhdl-mode-line-update)
4762 (message "VHDL Mode %s.%s" vhdl-version
4763 (if noninteractive "" " See menu for documentation and release notes."))
4765 ;; run hooks
4766 (if vhdl-emacs-22
4767 (run-mode-hooks 'vhdl-mode-hook)
4768 (run-hooks 'vhdl-mode-hook)))
4770 (defun vhdl-activate-customizations ()
4771 "Activate all customizations on local variables."
4772 (interactive)
4773 (vhdl-mode-map-init)
4774 (use-local-map vhdl-mode-map)
4775 (set-syntax-table vhdl-mode-syntax-table)
4776 (setq comment-column vhdl-inline-comment-column)
4777 (setq end-comment-column vhdl-end-comment-column)
4778 (vhdl-write-file-hooks-init)
4779 (vhdl-update-mode-menu)
4780 (vhdl-hideshow-init)
4781 (run-hooks 'menu-bar-update-hook)
4782 (vhdl-mode-line-update))
4784 (defun vhdl-write-file-hooks-init ()
4785 "Add/remove hooks when buffer is saved."
4786 (if vhdl-modify-date-on-saving
4787 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4788 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4789 (make-local-variable 'after-save-hook)
4790 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4792 (defun vhdl-process-command-line-option (option)
4793 "Process command line options for VHDL Mode."
4794 (cond
4795 ;; set compiler
4796 ((equal option "-compiler")
4797 (vhdl-set-compiler (car command-line-args-left))
4798 (setq command-line-args-left (cdr command-line-args-left)))
4799 ;; set project
4800 ((equal option "-project")
4801 (vhdl-set-project (car command-line-args-left))
4802 (setq command-line-args-left (cdr command-line-args-left)))))
4804 ;; make Emacs process VHDL Mode options
4805 (setq command-switch-alist
4806 (append command-switch-alist
4807 '(("-compiler" . vhdl-process-command-line-option)
4808 ("-project" . vhdl-process-command-line-option))))
4811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4812 ;;; Keywords and standardized words
4813 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4815 (defconst vhdl-93-keywords
4817 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4818 "assert" "attribute"
4819 "begin" "block" "body" "buffer" "bus"
4820 "case" "component" "configuration" "constant"
4821 "disconnect" "downto"
4822 "else" "elsif" "end" "entity" "exit"
4823 "file" "for" "function"
4824 "generate" "generic" "group" "guarded"
4825 "if" "impure" "in" "inertial" "inout" "is"
4826 "label" "library" "linkage" "literal" "loop"
4827 "map" "mod"
4828 "nand" "new" "next" "nor" "not" "null"
4829 "of" "on" "open" "or" "others" "out"
4830 "package" "port" "postponed" "procedure" "process" "pure"
4831 "range" "record" "register" "reject" "rem" "report" "return"
4832 "rol" "ror"
4833 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4834 "then" "to" "transport" "type"
4835 "unaffected" "units" "until" "use"
4836 "variable"
4837 "wait" "when" "while" "with"
4838 "xnor" "xor"
4840 "List of VHDL'93 keywords.")
4842 (defconst vhdl-ams-keywords
4844 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4845 "reference" "spectrum" "subnature" "terminal" "through"
4846 "tolerance"
4848 "List of VHDL-AMS keywords.")
4850 (defconst vhdl-verilog-keywords
4852 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4853 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4854 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4855 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4856 "endprimitive" "endspecify" "endtable" "endtask" "event"
4857 "for" "force" "forever" "fork" "function"
4858 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4859 "macromodule" "makefile" "medium" "module"
4860 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4861 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4862 "pullup"
4863 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4864 "rtranif0" "rtranif1"
4865 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4866 "strong1" "supply" "supply0" "supply1"
4867 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4868 "triand" "trior" "trireg"
4869 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4871 "List of Verilog keywords as candidate for additional reserved words.")
4873 (defconst vhdl-93-types
4875 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4876 "real" "time" "natural" "positive" "string" "line" "text" "side"
4877 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4878 "std_logic" "std_logic_vector"
4879 "std_ulogic" "std_ulogic_vector"
4881 "List of VHDL'93 standardized types.")
4883 (defconst vhdl-ams-types
4885 "domain_type" "real_vector"
4886 ;; from `nature_pkg' package
4887 "voltage" "current" "electrical" "position" "velocity" "force"
4888 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4889 "pressure" "flowrate" "fluid"
4891 "List of VHDL-AMS standardized types.")
4893 (defconst vhdl-math-types
4895 "complex" "complex_polar"
4897 "List of Math Packages standardized types.")
4899 (defconst vhdl-93-attributes
4901 "base" "left" "right" "high" "low" "pos" "val" "succ"
4902 "pred" "leftof" "rightof" "range" "reverse_range"
4903 "length" "delayed" "stable" "quiet" "transaction"
4904 "event" "active" "last_event" "last_active" "last_value"
4905 "driving" "driving_value" "ascending" "value" "image"
4906 "simple_name" "instance_name" "path_name"
4907 "foreign"
4909 "List of VHDL'93 standardized attributes.")
4911 (defconst vhdl-ams-attributes
4913 "across" "through"
4914 "reference" "contribution" "tolerance"
4915 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4916 "ramp" "slew"
4918 "List of VHDL-AMS standardized attributes.")
4920 (defconst vhdl-93-enum-values
4922 "true" "false"
4923 "note" "warning" "error" "failure"
4924 "read_mode" "write_mode" "append_mode"
4925 "open_ok" "status_error" "name_error" "mode_error"
4926 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4927 "right" "left"
4929 "List of VHDL'93 standardized enumeration values.")
4931 (defconst vhdl-ams-enum-values
4933 "quiescent_domain" "time_domain" "frequency_domain"
4934 ;; from `nature_pkg' package
4935 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4937 "List of VHDL-AMS standardized enumeration values.")
4939 (defconst vhdl-math-constants
4941 "math_e" "math_1_over_e"
4942 "math_pi" "math_two_pi" "math_1_over_pi"
4943 "math_half_pi" "math_q_pi" "math_3_half_pi"
4944 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4945 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4946 "math_deg_to_rad" "math_rad_to_deg"
4947 "cbase_1" "cbase_j" "czero"
4949 "List of Math Packages standardized constants.")
4951 (defconst vhdl-93-functions
4953 "now" "resolved" "rising_edge" "falling_edge"
4954 "read" "readline" "write" "writeline" "endfile"
4955 "resize" "is_X" "std_match"
4956 "shift_left" "shift_right" "rotate_left" "rotate_right"
4957 "to_unsigned" "to_signed" "to_integer"
4958 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4959 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4960 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4961 "shl" "shr" "ext" "sxt"
4962 "deallocate"
4964 "List of VHDL'93 standardized functions.")
4966 (defconst vhdl-ams-functions
4968 "frequency"
4970 "List of VHDL-AMS standardized functions.")
4972 (defconst vhdl-math-functions
4974 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4975 "sqrt" "cbrt" "exp" "log"
4976 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4977 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4978 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4980 "List of Math Packages standardized functions.")
4982 (defconst vhdl-93-packages
4984 "std_logic_1164" "numeric_std" "numeric_bit"
4985 "standard" "textio"
4986 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4987 "std_logic_misc" "std_logic_textio"
4988 "ieee" "std" "work"
4990 "List of VHDL'93 standardized packages and libraries.")
4992 (defconst vhdl-ams-packages
4994 ;; from `nature_pkg' package
4995 "nature_pkg"
4997 "List of VHDL-AMS standardized packages and libraries.")
4999 (defconst vhdl-math-packages
5001 "math_real" "math_complex"
5003 "List of Math Packages standardized packages and libraries.")
5005 (defvar vhdl-keywords nil
5006 "List of VHDL keywords.")
5008 (defvar vhdl-types nil
5009 "List of VHDL standardized types.")
5011 (defvar vhdl-attributes nil
5012 "List of VHDL standardized attributes.")
5014 (defvar vhdl-enum-values nil
5015 "List of VHDL standardized enumeration values.")
5017 (defvar vhdl-constants nil
5018 "List of VHDL standardized constants.")
5020 (defvar vhdl-functions nil
5021 "List of VHDL standardized functions.")
5023 (defvar vhdl-packages nil
5024 "List of VHDL standardized packages and libraries.")
5026 (defvar vhdl-reserved-words nil
5027 "List of additional reserved words.")
5029 (defvar vhdl-keywords-regexp nil
5030 "Regexp for VHDL keywords.")
5032 (defvar vhdl-types-regexp nil
5033 "Regexp for VHDL standardized types.")
5035 (defvar vhdl-attributes-regexp nil
5036 "Regexp for VHDL standardized attributes.")
5038 (defvar vhdl-enum-values-regexp nil
5039 "Regexp for VHDL standardized enumeration values.")
5041 (defvar vhdl-functions-regexp nil
5042 "Regexp for VHDL standardized functions.")
5044 (defvar vhdl-packages-regexp nil
5045 "Regexp for VHDL standardized packages and libraries.")
5047 (defvar vhdl-reserved-words-regexp nil
5048 "Regexp for additional reserved words.")
5050 (defvar vhdl-directive-keywords-regexp nil
5051 "Regexp for compiler directive keywords.")
5053 (defun vhdl-words-init ()
5054 "Initialize reserved words."
5055 (setq vhdl-keywords
5056 (append vhdl-93-keywords
5057 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5058 (setq vhdl-types
5059 (append vhdl-93-types
5060 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5061 (when (vhdl-standard-p 'math) vhdl-math-types)))
5062 (setq vhdl-attributes
5063 (append vhdl-93-attributes
5064 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5065 (setq vhdl-enum-values
5066 (append vhdl-93-enum-values
5067 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5068 (setq vhdl-constants
5069 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5070 (setq vhdl-functions
5071 (append vhdl-93-functions
5072 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5073 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5074 (setq vhdl-packages
5075 (append vhdl-93-packages
5076 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5077 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5078 (setq vhdl-reserved-words
5079 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5080 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5081 '("")))
5082 (setq vhdl-keywords-regexp
5083 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5084 (setq vhdl-types-regexp
5085 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5086 (setq vhdl-attributes-regexp
5087 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5088 (setq vhdl-enum-values-regexp
5089 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5090 (setq vhdl-functions-regexp
5091 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5092 (setq vhdl-packages-regexp
5093 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5094 (setq vhdl-reserved-words-regexp
5095 (concat "\\<\\("
5096 (unless (equal vhdl-forbidden-syntax "")
5097 (concat vhdl-forbidden-syntax "\\|"))
5098 (regexp-opt vhdl-reserved-words)
5099 "\\)\\>"))
5100 (setq vhdl-directive-keywords-regexp
5101 (concat "\\<\\(" (mapconcat 'regexp-quote
5102 vhdl-directive-keywords "\\|") "\\)\\>"))
5103 (vhdl-abbrev-list-init))
5105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5106 ;; Words to expand
5108 (defvar vhdl-abbrev-list nil
5109 "Predefined abbreviations for VHDL.")
5111 (defun vhdl-abbrev-list-init ()
5112 (setq vhdl-abbrev-list
5113 (append
5114 (list vhdl-upper-case-keywords) vhdl-keywords
5115 (list vhdl-upper-case-types) vhdl-types
5116 (list vhdl-upper-case-attributes) vhdl-attributes
5117 (list vhdl-upper-case-enum-values) vhdl-enum-values
5118 (list vhdl-upper-case-constants) vhdl-constants
5119 (list nil) vhdl-functions
5120 (list nil) vhdl-packages)))
5122 ;; initialize reserved words for VHDL Mode
5123 (vhdl-words-init)
5126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5127 ;;; Indentation
5128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5131 ;; Syntax analysis
5133 ;; constant regular expressions for looking at various constructs
5135 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5136 "Regexp describing a VHDL symbol.
5137 We cannot use just `word' syntax class since `_' cannot be in word
5138 class. Putting underscore in word class breaks forward word movement
5139 behavior that users are familiar with.")
5141 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5142 "Regexp describing a case statement header key.")
5144 (defconst vhdl-label-key
5145 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5146 "Regexp describing a VHDL label.")
5148 ;; Macro definitions:
5150 (defmacro vhdl-point (position)
5151 "Return the value of point at certain commonly referenced POSITIONs.
5152 POSITION can be one of the following symbols:
5154 bol -- beginning of line
5155 eol -- end of line
5156 bod -- beginning of defun
5157 boi -- back to indentation
5158 eoi -- last whitespace on line
5159 ionl -- indentation of next line
5160 iopl -- indentation of previous line
5161 bonl -- beginning of next line
5162 bopl -- beginning of previous line
5164 This function does not modify point or mark."
5165 (or (and (eq 'quote (car-safe position))
5166 (null (cddr position)))
5167 (error "ERROR: Bad buffer position requested: %s" position))
5168 (setq position (nth 1 position))
5169 `(let ((here (point)))
5170 ,@(cond
5171 ((eq position 'bol) '((beginning-of-line)))
5172 ((eq position 'eol) '((end-of-line)))
5173 ((eq position 'bod) '((save-match-data
5174 (vhdl-beginning-of-defun))))
5175 ((eq position 'boi) '((back-to-indentation)))
5176 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5177 ((eq position 'bonl) '((forward-line 1)))
5178 ((eq position 'bopl) '((forward-line -1)))
5179 ((eq position 'iopl)
5180 '((forward-line -1)
5181 (back-to-indentation)))
5182 ((eq position 'ionl)
5183 '((forward-line 1)
5184 (back-to-indentation)))
5185 (t (error "ERROR: Unknown buffer position requested: %s" position))
5187 (prog1
5188 (point)
5189 (goto-char here))
5190 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5191 ;; doesn't hurt for v19
5192 ,@nil
5195 (defmacro vhdl-safe (&rest body)
5196 "Safely execute BODY, return nil if an error occurred."
5197 `(condition-case nil
5198 (progn ,@body)
5199 (error nil)))
5201 (defmacro vhdl-add-syntax (symbol &optional relpos)
5202 "A simple macro to append the syntax in SYMBOL to the syntax list.
5203 Try to increase performance by using this macro."
5204 `(setq vhdl-syntactic-context
5205 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5207 (defmacro vhdl-has-syntax (symbol)
5208 "A simple macro to return check the syntax list.
5209 Try to increase performance by using this macro."
5210 `(assoc ,symbol vhdl-syntactic-context))
5212 ;; Syntactic element offset manipulation:
5214 (defun vhdl-read-offset (langelem)
5215 "Read new offset value for LANGELEM from minibuffer.
5216 Return a valid value only."
5217 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5218 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5219 (prompt "Offset: ")
5220 offset input interned)
5221 (while (not offset)
5222 (setq input (read-string prompt oldoff)
5223 offset (cond ((string-equal "+" input) '+)
5224 ((string-equal "-" input) '-)
5225 ((string-equal "++" input) '++)
5226 ((string-equal "--" input) '--)
5227 ((string-match "^-?[0-9]+$" input)
5228 (string-to-number input))
5229 ((fboundp (setq interned (intern input)))
5230 interned)
5231 ((boundp interned) interned)
5232 ;; error, but don't signal one, keep trying
5233 ;; to read an input value
5234 (t (ding)
5235 (setq prompt errmsg)
5236 nil))))
5237 offset))
5239 (defun vhdl-set-offset (symbol offset &optional add-p)
5240 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5241 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5242 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5243 `vhdl-offsets-alist' if it doesn't already appear there."
5244 (interactive
5245 (let* ((langelem
5246 (intern (completing-read
5247 (concat "Syntactic symbol to change"
5248 (if current-prefix-arg " or add" "")
5249 ": ")
5250 (mapcar
5251 (function
5252 (lambda (langelem)
5253 (cons (format "%s" (car langelem)) nil)))
5254 vhdl-offsets-alist)
5255 nil (not current-prefix-arg)
5256 ;; initial contents tries to be the last element
5257 ;; on the syntactic analysis list for the current
5258 ;; line
5259 (let* ((syntax (vhdl-get-syntactic-context))
5260 (len (length syntax))
5261 (ic (format "%s" (car (nth (1- len) syntax)))))
5264 (offset (vhdl-read-offset langelem)))
5265 (list langelem offset current-prefix-arg)))
5266 ;; sanity check offset
5267 (or (eq offset '+)
5268 (eq offset '-)
5269 (eq offset '++)
5270 (eq offset '--)
5271 (integerp offset)
5272 (fboundp offset)
5273 (boundp offset)
5274 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5275 offset))
5276 (let ((entry (assq symbol vhdl-offsets-alist)))
5277 (if entry
5278 (setcdr entry offset)
5279 (if add-p
5280 (setq vhdl-offsets-alist
5281 (cons (cons symbol offset) vhdl-offsets-alist))
5282 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5283 (vhdl-keep-region-active))
5285 (defun vhdl-set-style (style &optional local)
5286 "Set `vhdl-mode' variables to use one of several different indentation styles.
5287 STYLE is a string representing the desired style and optional LOCAL is
5288 a flag which, if non-nil, means to make the style variables being
5289 changed buffer local, instead of the default, which is to set the
5290 global variables. Interactively, the flag comes from the prefix
5291 argument. The styles are chosen from the `vhdl-style-alist' variable."
5292 (interactive (list (completing-read "Use which VHDL indentation style? "
5293 vhdl-style-alist nil t)
5294 current-prefix-arg))
5295 (let ((vars (cdr (assoc style vhdl-style-alist))))
5296 (or vars
5297 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5298 ;; set all the variables
5299 (mapcar
5300 (function
5301 (lambda (varentry)
5302 (let ((var (car varentry))
5303 (val (cdr varentry)))
5304 (and local
5305 (make-local-variable var))
5306 ;; special case for vhdl-offsets-alist
5307 (if (not (eq var 'vhdl-offsets-alist))
5308 (set var val)
5309 ;; reset vhdl-offsets-alist to the default value first
5310 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5311 ;; now set the langelems that are different
5312 (mapcar
5313 (function
5314 (lambda (langentry)
5315 (let ((langelem (car langentry))
5316 (offset (cdr langentry)))
5317 (vhdl-set-offset langelem offset)
5319 val))
5321 vars))
5322 (vhdl-keep-region-active))
5324 (defun vhdl-get-offset (langelem)
5325 "Get offset from LANGELEM which is a cons cell of the form:
5326 \(SYMBOL . RELPOS). The symbol is matched against
5327 vhdl-offsets-alist and the offset found there is either returned,
5328 or added to the indentation at RELPOS. If RELPOS is nil, then
5329 the offset is simply returned."
5330 (let* ((symbol (car langelem))
5331 (relpos (cdr langelem))
5332 (match (assq symbol vhdl-offsets-alist))
5333 (offset (cdr-safe match)))
5334 ;; offset can be a number, a function, a variable, or one of the
5335 ;; symbols + or -
5336 (cond
5337 ((not match)
5338 (if vhdl-strict-syntax-p
5339 (error "ERROR: Don't know how to indent a %s" symbol)
5340 (setq offset 0
5341 relpos 0)))
5342 ((eq offset '+) (setq offset vhdl-basic-offset))
5343 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5344 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5345 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5346 ((and (not (numberp offset))
5347 (fboundp offset))
5348 (setq offset (funcall offset langelem)))
5349 ((not (numberp offset))
5350 (setq offset (eval offset)))
5352 (+ (if (and relpos
5353 (< relpos (vhdl-point 'bol)))
5354 (save-excursion
5355 (goto-char relpos)
5356 (current-column))
5358 offset)))
5360 ;; Syntactic support functions:
5362 (defun vhdl-in-comment-p ()
5363 "Check if point is in a comment."
5364 (eq (vhdl-in-literal) 'comment))
5366 (defun vhdl-in-string-p ()
5367 "Check if point is in a string."
5368 (eq (vhdl-in-literal) 'string))
5370 (defun vhdl-in-literal ()
5371 "Determine if point is in a VHDL literal."
5372 (save-excursion
5373 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5374 (cond
5375 ((nth 3 state) 'string)
5376 ((nth 4 state) 'comment)
5377 ((vhdl-beginning-of-macro) 'pound)
5378 (t nil)))))
5380 (defun vhdl-forward-comment (&optional direction)
5381 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5382 negative, skip forward otherwise."
5383 (interactive "p")
5384 (if (and direction (< direction 0))
5385 ;; skip backwards
5386 (progn
5387 (skip-chars-backward " \t\n")
5388 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5389 (goto-char (match-beginning 3))
5390 (skip-chars-backward " \t\n")))
5391 ;; skip forwards
5392 (skip-chars-forward " \t\n")
5393 (while (looking-at "--.*")
5394 (goto-char (match-end 0))
5395 (skip-chars-forward " \t\n"))))
5397 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5398 (unless (and vhdl-xemacs (string< "21.2" emacs-version))
5399 (defalias 'vhdl-forward-comment 'forward-comment))
5401 ;; This is the best we can do in Win-Emacs.
5402 (defun vhdl-win-il (&optional lim)
5403 "Determine if point is in a VHDL literal."
5404 (save-excursion
5405 (let* ((here (point))
5406 (state nil)
5407 (match nil)
5408 (lim (or lim (vhdl-point 'bod))))
5409 (goto-char lim )
5410 (while (< (point) here)
5411 (setq match
5412 (and (re-search-forward "--\\|[\"']"
5413 here 'move)
5414 (buffer-substring (match-beginning 0) (match-end 0))))
5415 (setq state
5416 (cond
5417 ;; no match
5418 ((null match) nil)
5419 ;; looking at the opening of a VHDL style comment
5420 ((string= "--" match)
5421 (if (<= here (progn (end-of-line) (point))) 'comment))
5422 ;; looking at the opening of a double quote string
5423 ((string= "\"" match)
5424 (if (not (save-restriction
5425 ;; this seems to be necessary since the
5426 ;; re-search-forward will not work without it
5427 (narrow-to-region (point) here)
5428 (re-search-forward
5429 ;; this regexp matches a double quote
5430 ;; which is preceded by an even number
5431 ;; of backslashes, including zero
5432 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5433 'string))
5434 ;; looking at the opening of a single quote string
5435 ((string= "'" match)
5436 (if (not (save-restriction
5437 ;; see comments from above
5438 (narrow-to-region (point) here)
5439 (re-search-forward
5440 ;; this matches a single quote which is
5441 ;; preceded by zero or two backslashes.
5442 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5443 here 'move)))
5444 'string))
5445 (t nil)))
5446 ) ; end-while
5447 state)))
5449 (and (string-match "Win-Emacs" emacs-version)
5450 (fset 'vhdl-in-literal 'vhdl-win-il))
5452 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5453 ;; defined as lexical whitespace or comments. Search no farther back
5454 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5455 ;; used for backward skipping, (point-max) is used for forward
5456 ;; skipping.
5458 (defun vhdl-forward-syntactic-ws (&optional lim)
5459 "Forward skip of syntactic whitespace."
5460 (let* ((here (point-max))
5461 (hugenum (point-max)))
5462 (while (/= here (point))
5463 (setq here (point))
5464 (vhdl-forward-comment hugenum)
5465 ;; skip preprocessor directives
5466 (when (and (eq (char-after) ?#)
5467 (= (vhdl-point 'boi) (point)))
5468 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5469 (= (forward-line 1) 0)))
5470 (end-of-line)))
5471 (if lim (goto-char (min (point) lim)))))
5474 ;; This is the best we can do in Win-Emacs.
5475 (defun vhdl-win-fsws (&optional lim)
5476 "Forward skip syntactic whitespace for Win-Emacs."
5477 (let ((lim (or lim (point-max)))
5478 stop)
5479 (while (not stop)
5480 (skip-chars-forward " \t\n\r\f" lim)
5481 (cond
5482 ;; vhdl comment
5483 ((looking-at "--") (end-of-line))
5484 ;; none of the above
5485 (t (setq stop t))))))
5487 (and (string-match "Win-Emacs" emacs-version)
5488 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5490 (defun vhdl-beginning-of-macro (&optional lim)
5491 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5492 (let ((here (point)))
5493 (beginning-of-line)
5494 (while (eq (char-before (1- (point))) ?\\)
5495 (forward-line -1))
5496 (back-to-indentation)
5497 (if (and (<= (point) here)
5498 (eq (char-after) ?#))
5500 (goto-char here)
5501 nil)))
5503 (defun vhdl-backward-syntactic-ws (&optional lim)
5504 "Backward skip over syntactic whitespace."
5505 (let* ((here (point-min))
5506 (hugenum (- (point-max))))
5507 (while (/= here (point))
5508 (setq here (point))
5509 (vhdl-forward-comment hugenum)
5510 (vhdl-beginning-of-macro))
5511 (if lim (goto-char (max (point) lim)))))
5513 ;; This is the best we can do in Win-Emacs.
5514 (defun vhdl-win-bsws (&optional lim)
5515 "Backward skip syntactic whitespace for Win-Emacs."
5516 (let ((lim (or lim (vhdl-point 'bod)))
5517 stop)
5518 (while (not stop)
5519 (skip-chars-backward " \t\n\r\f" lim)
5520 (cond
5521 ;; vhdl comment
5522 ((eq (vhdl-in-literal) 'comment)
5523 (skip-chars-backward "^-" lim)
5524 (skip-chars-backward "-" lim)
5525 (while (not (or (and (= (following-char) ?-)
5526 (= (char-after (1+ (point))) ?-))
5527 (<= (point) lim)))
5528 (skip-chars-backward "^-" lim)
5529 (skip-chars-backward "-" lim)))
5530 ;; none of the above
5531 (t (setq stop t))))))
5533 (and (string-match "Win-Emacs" emacs-version)
5534 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5536 ;; Functions to help finding the correct indentation column:
5538 (defun vhdl-first-word (point)
5539 "If the keyword at POINT is at boi, then return (current-column) at
5540 that point, else nil."
5541 (save-excursion
5542 (and (goto-char point)
5543 (eq (point) (vhdl-point 'boi))
5544 (current-column))))
5546 (defun vhdl-last-word (point)
5547 "If the keyword at POINT is at eoi, then return (current-column) at
5548 that point, else nil."
5549 (save-excursion
5550 (and (goto-char point)
5551 (save-excursion (or (eq (progn (forward-sexp) (point))
5552 (vhdl-point 'eoi))
5553 (looking-at "\\s-*\\(--\\)?")))
5554 (current-column))))
5556 ;; Core syntactic evaluation functions:
5558 (defconst vhdl-libunit-re
5559 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5561 (defun vhdl-libunit-p ()
5562 (and
5563 (save-excursion
5564 (forward-sexp)
5565 (skip-chars-forward " \t\n")
5566 (not (looking-at "is\\b[^_]")))
5567 (save-excursion
5568 (backward-sexp)
5569 (and (not (looking-at "use\\b[^_]"))
5570 (progn
5571 (forward-sexp)
5572 (vhdl-forward-syntactic-ws)
5573 (/= (following-char) ?:))))
5576 (defconst vhdl-defun-re
5577 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5579 (defun vhdl-defun-p ()
5580 (save-excursion
5581 (if (looking-at "block\\|process\\|procedural")
5582 ;; "block", "process", "procedural":
5583 (save-excursion
5584 (backward-sexp)
5585 (not (looking-at "end\\s-+\\w")))
5586 ;; "architecture", "configuration", "entity",
5587 ;; "package", "procedure", "function":
5588 t)))
5590 (defun vhdl-corresponding-defun ()
5591 "If the word at the current position corresponds to a \"defun\"
5592 keyword, then return a string that can be used to find the
5593 corresponding \"begin\" keyword, else return nil."
5594 (save-excursion
5595 (and (looking-at vhdl-defun-re)
5596 (vhdl-defun-p)
5597 (if (looking-at "block\\|process\\|procedural")
5598 ;; "block", "process". "procedural:
5599 (buffer-substring (match-beginning 0) (match-end 0))
5600 ;; "architecture", "configuration", "entity", "package",
5601 ;; "procedure", "function":
5602 "is"))))
5604 (defconst vhdl-begin-fwd-re
5605 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5606 "A regular expression for searching forward that matches all known
5607 \"begin\" keywords.")
5609 (defconst vhdl-begin-bwd-re
5610 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5611 "A regular expression for searching backward that matches all known
5612 \"begin\" keywords.")
5614 (defun vhdl-begin-p (&optional lim)
5615 "Return t if we are looking at a real \"begin\" keyword.
5616 Assumes that the caller will make sure that we are looking at
5617 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5618 the middle of an identifier that just happens to contain a \"begin\"
5619 keyword."
5620 (cond
5621 ;; "[architecture|case|configuration|entity|package|
5622 ;; procedure|function] ... is":
5623 ((and (looking-at "i")
5624 (save-excursion
5625 ;; Skip backward over first sexp (needed to skip over a
5626 ;; procedure interface list, and is harmless in other
5627 ;; situations). Note that we need "return" in the
5628 ;; following search list so that we don't run into
5629 ;; semicolons in the function interface list.
5630 (backward-sexp)
5631 (let (foundp)
5632 (while (and (not foundp)
5633 (re-search-backward
5634 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5635 lim 'move))
5636 (if (or (= (preceding-char) ?_)
5637 (vhdl-in-literal))
5638 (backward-char)
5639 (setq foundp t))))
5640 (and (/= (following-char) ?\;)
5641 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5643 ;; "begin", "then":
5644 ((looking-at "be\\|t")
5646 ;; "else":
5647 ((and (looking-at "e")
5648 ;; make sure that the "else" isn't inside a
5649 ;; conditional signal assignment.
5650 (save-excursion
5651 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5652 (or (eq (following-char) ?\;)
5653 (eq (point) lim))))
5655 ;; "block", "generate", "loop", "process", "procedural",
5656 ;; "units", "record":
5657 ((and (looking-at "bl\\|[glpur]")
5658 (save-excursion
5659 (backward-sexp)
5660 (not (looking-at "end\\s-+\\w"))))
5662 ;; "component":
5663 ((and (looking-at "c")
5664 (save-excursion
5665 (backward-sexp)
5666 (not (looking-at "end\\s-+\\w")))
5667 ;; look out for the dreaded entity class in an attribute
5668 (save-excursion
5669 (vhdl-backward-syntactic-ws lim)
5670 (/= (preceding-char) ?:)))
5672 ;; "for" (inside configuration declaration):
5673 ((and (looking-at "f")
5674 (save-excursion
5675 (backward-sexp)
5676 (not (looking-at "end\\s-+\\w")))
5677 (vhdl-has-syntax 'configuration))
5681 (defun vhdl-corresponding-mid (&optional lim)
5682 (cond
5683 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5684 "begin")
5685 ((looking-at "then")
5686 "<else>")
5688 "end")))
5690 (defun vhdl-corresponding-end (&optional lim)
5691 "If the word at the current position corresponds to a \"begin\"
5692 keyword, then return a vector containing enough information to find
5693 the corresponding \"end\" keyword, else return nil. The keyword to
5694 search forward for is aref 0. The column in which the keyword must
5695 appear is aref 1 or nil if any column is suitable.
5696 Assumes that the caller will make sure that we are not in the middle
5697 of an identifier that just happens to contain a \"begin\" keyword."
5698 (save-excursion
5699 (and (looking-at vhdl-begin-fwd-re)
5700 (/= (preceding-char) ?_)
5701 (not (vhdl-in-literal))
5702 (vhdl-begin-p lim)
5703 (cond
5704 ;; "is", "generate", "loop":
5705 ((looking-at "[igl]")
5706 (vector "end"
5707 (and (vhdl-last-word (point))
5708 (or (vhdl-first-word (point))
5709 (save-excursion
5710 (vhdl-beginning-of-statement-1 lim)
5711 (vhdl-backward-skip-label lim)
5712 (vhdl-first-word (point)))))))
5713 ;; "begin", "else", "for":
5714 ((looking-at "be\\|[ef]")
5715 (vector "end"
5716 (and (vhdl-last-word (point))
5717 (or (vhdl-first-word (point))
5718 (save-excursion
5719 (vhdl-beginning-of-statement-1 lim)
5720 (vhdl-backward-skip-label lim)
5721 (vhdl-first-word (point)))))))
5722 ;; "component", "units", "record":
5723 ((looking-at "[cur]")
5724 ;; The first end found will close the block
5725 (vector "end" nil))
5726 ;; "block", "process", "procedural":
5727 ((looking-at "bl\\|p")
5728 (vector "end"
5729 (or (vhdl-first-word (point))
5730 (save-excursion
5731 (vhdl-beginning-of-statement-1 lim)
5732 (vhdl-backward-skip-label lim)
5733 (vhdl-first-word (point))))))
5734 ;; "then":
5735 ((looking-at "t")
5736 (vector "elsif\\|else\\|end\\s-+if"
5737 (and (vhdl-last-word (point))
5738 (or (vhdl-first-word (point))
5739 (save-excursion
5740 (vhdl-beginning-of-statement-1 lim)
5741 (vhdl-backward-skip-label lim)
5742 (vhdl-first-word (point)))))))
5743 ))))
5745 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5747 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5749 (defun vhdl-end-p (&optional lim)
5750 "Return t if we are looking at a real \"end\" keyword.
5751 Assumes that the caller will make sure that we are looking at
5752 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5753 the middle of an identifier that just happens to contain an \"end\"
5754 keyword."
5755 (or (not (looking-at "else"))
5756 ;; make sure that the "else" isn't inside a conditional signal
5757 ;; assignment.
5758 (save-excursion
5759 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5760 (or (eq (following-char) ?\;)
5761 (eq (point) lim)
5762 (vhdl-in-literal)))))
5764 (defun vhdl-corresponding-begin (&optional lim)
5765 "If the word at the current position corresponds to an \"end\"
5766 keyword, then return a vector containing enough information to find
5767 the corresponding \"begin\" keyword, else return nil. The keyword to
5768 search backward for is aref 0. The column in which the keyword must
5769 appear is aref 1 or nil if any column is suitable. The supplementary
5770 keyword to search forward for is aref 2 or nil if this is not
5771 required. If aref 3 is t, then the \"begin\" keyword may be found in
5772 the middle of a statement.
5773 Assumes that the caller will make sure that we are not in the middle
5774 of an identifier that just happens to contain an \"end\" keyword."
5775 (save-excursion
5776 (let (pos)
5777 (if (and (looking-at vhdl-end-fwd-re)
5778 (not (vhdl-in-literal))
5779 (vhdl-end-p lim))
5780 (if (looking-at "el")
5781 ;; "else", "elsif":
5782 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5783 ;; "end ...":
5784 (setq pos (point))
5785 (forward-sexp)
5786 (skip-chars-forward " \t\n")
5787 (cond
5788 ;; "end if":
5789 ((looking-at "if\\b[^_]")
5790 (vector "else\\|elsif\\|if"
5791 (vhdl-first-word pos)
5792 "else\\|then" nil))
5793 ;; "end component":
5794 ((looking-at "component\\b[^_]")
5795 (vector (buffer-substring (match-beginning 1)
5796 (match-end 1))
5797 (vhdl-first-word pos)
5798 nil nil))
5799 ;; "end units", "end record":
5800 ((looking-at "\\(units\\|record\\)\\b[^_]")
5801 (vector (buffer-substring (match-beginning 1)
5802 (match-end 1))
5803 (vhdl-first-word pos)
5804 nil t))
5805 ;; "end block", "end process", "end procedural":
5806 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5807 (vector "begin" (vhdl-first-word pos) nil nil))
5808 ;; "end case":
5809 ((looking-at "case\\b[^_]")
5810 (vector "case" (vhdl-first-word pos) "is" nil))
5811 ;; "end generate":
5812 ((looking-at "generate\\b[^_]")
5813 (vector "generate\\|for\\|if"
5814 (vhdl-first-word pos)
5815 "generate" nil))
5816 ;; "end loop":
5817 ((looking-at "loop\\b[^_]")
5818 (vector "loop\\|while\\|for"
5819 (vhdl-first-word pos)
5820 "loop" nil))
5821 ;; "end for" (inside configuration declaration):
5822 ((looking-at "for\\b[^_]")
5823 (vector "for" (vhdl-first-word pos) nil nil))
5824 ;; "end [id]":
5826 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5827 (vhdl-first-word pos)
5828 ;; return an alist of (statement . keyword) mappings
5830 ;; "begin ... end [id]":
5831 ("begin" . nil)
5832 ;; "architecture ... is ... begin ... end [id]":
5833 ("architecture" . "is")
5834 ;; "configuration ... is ... end [id]":
5835 ("configuration" . "is")
5836 ;; "entity ... is ... end [id]":
5837 ("entity" . "is")
5838 ;; "package ... is ... end [id]":
5839 ("package" . "is")
5840 ;; "procedure ... is ... begin ... end [id]":
5841 ("procedure" . "is")
5842 ;; "function ... is ... begin ... end [id]":
5843 ("function" . "is")
5845 nil))
5846 ))) ; "end ..."
5849 (defconst vhdl-leader-re
5850 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5852 (defun vhdl-end-of-leader ()
5853 (save-excursion
5854 (cond ((looking-at "block\\|process\\|procedural")
5855 (if (save-excursion
5856 (forward-sexp)
5857 (skip-chars-forward " \t\n")
5858 (= (following-char) ?\())
5859 (forward-sexp 2)
5860 (forward-sexp))
5861 (when (looking-at "[ \t\n]*is")
5862 (goto-char (match-end 0)))
5863 (point))
5864 ((looking-at "component")
5865 (forward-sexp 2)
5866 (when (looking-at "[ \t\n]*is")
5867 (goto-char (match-end 0)))
5868 (point))
5869 ((looking-at "for")
5870 (forward-sexp 2)
5871 (skip-chars-forward " \t\n")
5872 (while (looking-at "[,:(]")
5873 (forward-sexp)
5874 (skip-chars-forward " \t\n"))
5875 (point))
5876 (t nil)
5879 (defconst vhdl-trailer-re
5880 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
5882 (defconst vhdl-statement-fwd-re
5883 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5884 "A regular expression for searching forward that matches all known
5885 \"statement\" keywords.")
5887 (defconst vhdl-statement-bwd-re
5888 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5889 "A regular expression for searching backward that matches all known
5890 \"statement\" keywords.")
5892 (defun vhdl-statement-p (&optional lim)
5893 "Return t if we are looking at a real \"statement\" keyword.
5894 Assumes that the caller will make sure that we are looking at
5895 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5896 in the middle of an identifier that just happens to contain a
5897 \"statement\" keyword."
5898 (cond
5899 ;; "for" ... "generate":
5900 ((and (looking-at "f")
5901 ;; Make sure it's the start of a parameter specification.
5902 (save-excursion
5903 (forward-sexp 2)
5904 (skip-chars-forward " \t\n")
5905 (looking-at "in\\b[^_]"))
5906 ;; Make sure it's not an "end for".
5907 (save-excursion
5908 (backward-sexp)
5909 (not (looking-at "end\\s-+\\w"))))
5911 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5912 ((and (looking-at "i")
5913 ;; Make sure it's not an "end if".
5914 (save-excursion
5915 (backward-sexp)
5916 (not (looking-at "end\\s-+\\w"))))
5918 ;; "while" ... "loop":
5919 ((looking-at "w")
5923 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5924 "Regexp describing a case statement alternative key.")
5926 (defun vhdl-case-alternative-p (&optional lim)
5927 "Return t if we are looking at a real case alternative.
5928 Assumes that the caller will make sure that we are looking at
5929 vhdl-case-alternative-re, and are not inside a literal, and that
5930 we are not in the middle of an identifier that just happens to
5931 contain a \"when\" keyword."
5932 (save-excursion
5933 (let (foundp)
5934 (while (and (not foundp)
5935 (re-search-backward ";\\|<=" lim 'move))
5936 (if (or (= (preceding-char) ?_)
5937 (vhdl-in-literal))
5938 (backward-char)
5939 (setq foundp t)))
5940 (or (eq (following-char) ?\;)
5941 (eq (point) lim)))
5944 ;; Core syntactic movement functions:
5946 (defconst vhdl-b-t-b-re
5947 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5949 (defun vhdl-backward-to-block (&optional lim)
5950 "Move backward to the previous \"begin\" or \"end\" keyword."
5951 (let (foundp)
5952 (while (and (not foundp)
5953 (re-search-backward vhdl-b-t-b-re lim 'move))
5954 (if (or (= (preceding-char) ?_)
5955 (vhdl-in-literal))
5956 (backward-char)
5957 (cond
5958 ;; "begin" keyword:
5959 ((and (looking-at vhdl-begin-fwd-re)
5960 (/= (preceding-char) ?_)
5961 (vhdl-begin-p lim))
5962 (setq foundp 'begin))
5963 ;; "end" keyword:
5964 ((and (looking-at vhdl-end-fwd-re)
5965 (/= (preceding-char) ?_)
5966 (vhdl-end-p lim))
5967 (setq foundp 'end))
5970 foundp
5973 (defun vhdl-forward-sexp (&optional count lim)
5974 "Move forward across one balanced expression (sexp).
5975 With COUNT, do it that many times."
5976 (interactive "p")
5977 (let ((count (or count 1))
5978 (case-fold-search t)
5979 end-vec target)
5980 (save-excursion
5981 (while (> count 0)
5982 ;; skip whitespace
5983 (skip-chars-forward " \t\n")
5984 ;; Check for an unbalanced "end" keyword
5985 (if (and (looking-at vhdl-end-fwd-re)
5986 (/= (preceding-char) ?_)
5987 (not (vhdl-in-literal))
5988 (vhdl-end-p lim)
5989 (not (looking-at "else")))
5990 (error
5991 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5992 ;; If the current keyword is a "begin" keyword, then find the
5993 ;; corresponding "end" keyword.
5994 (if (setq end-vec (vhdl-corresponding-end lim))
5995 (let (
5996 ;; end-re is the statement keyword to search for
5997 (end-re
5998 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5999 ;; column is either the statement keyword target column
6000 ;; or nil
6001 (column (aref end-vec 1))
6002 (eol (vhdl-point 'eol))
6003 foundp literal placeholder)
6004 ;; Look for the statement keyword.
6005 (while (and (not foundp)
6006 (re-search-forward end-re nil t)
6007 (setq placeholder (match-end 1))
6008 (goto-char (match-beginning 0)))
6009 ;; If we are in a literal, or not in the right target
6010 ;; column and not on the same line as the begin, then
6011 ;; try again.
6012 (if (or (and column
6013 (/= (current-indentation) column)
6014 (> (point) eol))
6015 (= (preceding-char) ?_)
6016 (setq literal (vhdl-in-literal)))
6017 (if (eq literal 'comment)
6018 (end-of-line)
6019 (forward-char))
6020 ;; An "else" keyword corresponds to both the opening brace
6021 ;; of the following sexp and the closing brace of the
6022 ;; previous sexp.
6023 (if (not (looking-at "else"))
6024 (goto-char placeholder))
6025 (setq foundp t))
6027 (if (not foundp)
6028 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6030 ;; If the current keyword is not a "begin" keyword, then just
6031 ;; perform the normal forward-sexp.
6032 (forward-sexp)
6034 (setq count (1- count))
6036 (setq target (point)))
6037 (goto-char target)
6038 nil))
6040 (defun vhdl-backward-sexp (&optional count lim)
6041 "Move backward across one balanced expression (sexp).
6042 With COUNT, do it that many times. LIM bounds any required backward
6043 searches."
6044 (interactive "p")
6045 (let ((count (or count 1))
6046 (case-fold-search t)
6047 begin-vec target)
6048 (save-excursion
6049 (while (> count 0)
6050 ;; Perform the normal backward-sexp, unless we are looking at
6051 ;; "else" - an "else" keyword corresponds to both the opening brace
6052 ;; of the following sexp and the closing brace of the previous sexp.
6053 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6054 (/= (preceding-char) ?_)
6055 (not (vhdl-in-literal)))
6057 (backward-sexp)
6058 (if (and (looking-at vhdl-begin-fwd-re)
6059 (/= (preceding-char) ?_)
6060 (not (vhdl-in-literal))
6061 (vhdl-begin-p lim))
6062 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6063 ;; If the current keyword is an "end" keyword, then find the
6064 ;; corresponding "begin" keyword.
6065 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6066 (/= (preceding-char) ?_))
6067 (let (
6068 ;; begin-re is the statement keyword to search for
6069 (begin-re
6070 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6071 ;; column is either the statement keyword target column
6072 ;; or nil
6073 (column (aref begin-vec 1))
6074 ;; internal-p controls where the statement keyword can
6075 ;; be found.
6076 (internal-p (aref begin-vec 3))
6077 (last-backward (point)) last-forward
6078 foundp literal keyword)
6079 ;; Look for the statement keyword.
6080 (while (and (not foundp)
6081 (re-search-backward begin-re lim t)
6082 (setq keyword
6083 (buffer-substring (match-beginning 1)
6084 (match-end 1))))
6085 ;; If we are in a literal or in the wrong column,
6086 ;; then try again.
6087 (if (or (and column
6088 (and (/= (current-indentation) column)
6089 ;; possibly accept current-column as
6090 ;; well as current-indentation.
6091 (or (not internal-p)
6092 (/= (current-column) column))))
6093 (= (preceding-char) ?_)
6094 (vhdl-in-literal))
6095 (backward-char)
6096 ;; If there is a supplementary keyword, then
6097 ;; search forward for it.
6098 (if (and (setq begin-re (aref begin-vec 2))
6099 (or (not (listp begin-re))
6100 ;; If begin-re is an alist, then find the
6101 ;; element corresponding to the actual
6102 ;; keyword that we found.
6103 (progn
6104 (setq begin-re
6105 (assoc keyword begin-re))
6106 (and begin-re
6107 (setq begin-re (cdr begin-re))))))
6108 (and
6109 (setq begin-re
6110 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6111 (save-excursion
6112 (setq last-forward (point))
6113 ;; Look for the supplementary keyword
6114 ;; (bounded by the backward search start
6115 ;; point).
6116 (while (and (not foundp)
6117 (re-search-forward begin-re
6118 last-backward t)
6119 (goto-char (match-beginning 1)))
6120 ;; If we are in a literal, then try again.
6121 (if (or (= (preceding-char) ?_)
6122 (setq literal
6123 (vhdl-in-literal)))
6124 (if (eq literal 'comment)
6125 (goto-char
6126 (min (vhdl-point 'eol) last-backward))
6127 (forward-char))
6128 ;; We have found the supplementary keyword.
6129 ;; Save the position of the keyword in foundp.
6130 (setq foundp (point)))
6132 foundp)
6133 ;; If the supplementary keyword was found, then
6134 ;; move point to the supplementary keyword.
6135 (goto-char foundp))
6136 ;; If there was no supplementary keyword, then
6137 ;; point is already at the statement keyword.
6138 (setq foundp t)))
6139 ) ; end of the search for the statement keyword
6140 (if (not foundp)
6141 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6143 (setq count (1- count))
6145 (setq target (point)))
6146 (goto-char target)
6147 nil))
6149 (defun vhdl-backward-up-list (&optional count limit)
6150 "Move backward out of one level of blocks.
6151 With argument, do this that many times."
6152 (interactive "p")
6153 (let ((count (or count 1))
6154 target)
6155 (save-excursion
6156 (while (> count 0)
6157 (if (looking-at vhdl-defun-re)
6158 (error "ERROR: Unbalanced blocks"))
6159 (vhdl-backward-to-block limit)
6160 (setq count (1- count)))
6161 (setq target (point)))
6162 (goto-char target)))
6164 (defun vhdl-end-of-defun (&optional count)
6165 "Move forward to the end of a VHDL defun."
6166 (interactive)
6167 (let ((case-fold-search t))
6168 (vhdl-beginning-of-defun)
6169 (if (not (looking-at "block\\|process\\|procedural"))
6170 (re-search-forward "\\bis\\b"))
6171 (vhdl-forward-sexp)))
6173 (defun vhdl-mark-defun ()
6174 "Put mark at end of this \"defun\", point at beginning."
6175 (interactive)
6176 (let ((case-fold-search t))
6177 (push-mark)
6178 (vhdl-beginning-of-defun)
6179 (push-mark)
6180 (if (not (looking-at "block\\|process\\|procedural"))
6181 (re-search-forward "\\bis\\b"))
6182 (vhdl-forward-sexp)
6183 (exchange-point-and-mark)))
6185 (defun vhdl-beginning-of-libunit ()
6186 "Move backward to the beginning of a VHDL library unit.
6187 Returns the location of the corresponding begin keyword, unless search
6188 stops due to beginning or end of buffer.
6189 Note that if point is between the \"libunit\" keyword and the
6190 corresponding \"begin\" keyword, then that libunit will not be
6191 recognized, and the search will continue backwards. If point is
6192 at the \"begin\" keyword, then the defun will be recognized. The
6193 returned point is at the first character of the \"libunit\" keyword."
6194 (let ((last-forward (point))
6195 (last-backward
6196 ;; Just in case we are actually sitting on the "begin"
6197 ;; keyword, allow for the keyword and an extra character,
6198 ;; as this will be used when looking forward for the
6199 ;; "begin" keyword.
6200 (save-excursion (forward-word 1) (1+ (point))))
6201 foundp literal placeholder)
6202 ;; Find the "libunit" keyword.
6203 (while (and (not foundp)
6204 (re-search-backward vhdl-libunit-re nil 'move))
6205 ;; If we are in a literal, or not at a real libunit, then try again.
6206 (if (or (= (preceding-char) ?_)
6207 (vhdl-in-literal)
6208 (not (vhdl-libunit-p)))
6209 (backward-char)
6210 ;; Find the corresponding "begin" keyword.
6211 (setq last-forward (point))
6212 (while (and (not foundp)
6213 (re-search-forward "\\bis\\b[^_]" last-backward t)
6214 (setq placeholder (match-beginning 0)))
6215 (if (or (= (preceding-char) ?_)
6216 (setq literal (vhdl-in-literal)))
6217 ;; It wasn't a real keyword, so keep searching.
6218 (if (eq literal 'comment)
6219 (goto-char
6220 (min (vhdl-point 'eol) last-backward))
6221 (forward-char))
6222 ;; We have found the begin keyword, loop will exit.
6223 (setq foundp placeholder)))
6224 ;; Go back to the libunit keyword
6225 (goto-char last-forward)))
6226 foundp))
6228 (defun vhdl-beginning-of-defun (&optional count)
6229 "Move backward to the beginning of a VHDL defun.
6230 With argument, do it that many times.
6231 Returns the location of the corresponding begin keyword, unless search
6232 stops due to beginning or end of buffer."
6233 ;; Note that if point is between the "defun" keyword and the
6234 ;; corresponding "begin" keyword, then that defun will not be
6235 ;; recognized, and the search will continue backwards. If point is
6236 ;; at the "begin" keyword, then the defun will be recognized. The
6237 ;; returned point is at the first character of the "defun" keyword.
6238 (interactive "p")
6239 (let ((count (or count 1))
6240 (case-fold-search t)
6241 (last-forward (point))
6242 foundp)
6243 (while (> count 0)
6244 (setq foundp nil)
6245 (goto-char last-forward)
6246 (let ((last-backward
6247 ;; Just in case we are actually sitting on the "begin"
6248 ;; keyword, allow for the keyword and an extra character,
6249 ;; as this will be used when looking forward for the
6250 ;; "begin" keyword.
6251 (save-excursion (forward-word 1) (1+ (point))))
6252 begin-string literal)
6253 (while (and (not foundp)
6254 (re-search-backward vhdl-defun-re nil 'move))
6255 ;; If we are in a literal, then try again.
6256 (if (or (= (preceding-char) ?_)
6257 (vhdl-in-literal))
6258 (backward-char)
6259 (if (setq begin-string (vhdl-corresponding-defun))
6260 ;; This is a real defun keyword.
6261 ;; Find the corresponding "begin" keyword.
6262 ;; Look for the begin keyword.
6263 (progn
6264 ;; Save the search start point.
6265 (setq last-forward (point))
6266 (while (and (not foundp)
6267 (search-forward begin-string last-backward t))
6268 (if (or (= (preceding-char) ?_)
6269 (save-match-data
6270 (setq literal (vhdl-in-literal))))
6271 ;; It wasn't a real keyword, so keep searching.
6272 (if (eq literal 'comment)
6273 (goto-char
6274 (min (vhdl-point 'eol) last-backward))
6275 (forward-char))
6276 ;; We have found the begin keyword, loop will exit.
6277 (setq foundp (match-beginning 0)))
6279 ;; Go back to the defun keyword
6280 (goto-char last-forward)) ; end search for begin keyword
6282 ) ; end of the search for the defun keyword
6284 (setq count (1- count))
6286 (vhdl-keep-region-active)
6287 foundp))
6289 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6290 "Go to the beginning of the innermost VHDL statement.
6291 With prefix arg, go back N - 1 statements. If already at the
6292 beginning of a statement then go to the beginning of the preceding
6293 one. If within a string or comment, or next to a comment (only
6294 whitespace between), move by sentences instead of statements.
6296 When called from a program, this function takes 3 optional args: the
6297 prefix arg, a buffer position limit which is the farthest back to
6298 search, and an argument indicating an interactive call."
6299 (interactive "p\np")
6300 (let ((count (or count 1))
6301 (case-fold-search t)
6302 (lim (or lim (point-min)))
6303 (here (point))
6304 state)
6305 (save-excursion
6306 (goto-char lim)
6307 (setq state (parse-partial-sexp (point) here nil nil)))
6308 (if (and interactive
6309 (or (nth 3 state)
6310 (nth 4 state)
6311 (looking-at (concat "[ \t]*" comment-start-skip))))
6312 (forward-sentence (- count))
6313 (while (> count 0)
6314 (vhdl-beginning-of-statement-1 lim)
6315 (setq count (1- count))))
6316 ;; its possible we've been left up-buf of lim
6317 (goto-char (max (point) lim))
6319 (vhdl-keep-region-active))
6321 (defconst vhdl-e-o-s-re
6322 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6324 (defun vhdl-end-of-statement ()
6325 "Very simple implementation."
6326 (interactive)
6327 (re-search-forward vhdl-e-o-s-re))
6329 (defconst vhdl-b-o-s-re
6330 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6331 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6333 (defun vhdl-beginning-of-statement-1 (&optional lim)
6334 "Move to the start of the current statement, or the previous
6335 statement if already at the beginning of one."
6336 (let ((lim (or lim (point-min)))
6337 (here (point))
6338 (pos (point))
6339 donep)
6340 ;; go backwards one balanced expression, but be careful of
6341 ;; unbalanced paren being reached
6342 (if (not (vhdl-safe (progn (backward-sexp) t)))
6343 (progn
6344 (backward-up-list 1)
6345 (forward-char)
6346 (vhdl-forward-syntactic-ws here)
6347 (setq donep t)))
6348 (while (and (not donep)
6349 (not (bobp))
6350 ;; look backwards for a statement boundary
6351 (re-search-backward vhdl-b-o-s-re lim 'move))
6352 (if (or (= (preceding-char) ?_)
6353 (vhdl-in-literal))
6354 (backward-char)
6355 (cond
6356 ;; If we are looking at an open paren, then stop after it
6357 ((eq (following-char) ?\()
6358 (forward-char)
6359 (vhdl-forward-syntactic-ws here)
6360 (setq donep t))
6361 ;; If we are looking at a close paren, then skip it
6362 ((eq (following-char) ?\))
6363 (forward-char)
6364 (setq pos (point))
6365 (backward-sexp)
6366 (if (< (point) lim)
6367 (progn (goto-char pos)
6368 (vhdl-forward-syntactic-ws here)
6369 (setq donep t))))
6370 ;; If we are looking at a semicolon, then stop
6371 ((eq (following-char) ?\;)
6372 (progn
6373 (forward-char)
6374 (vhdl-forward-syntactic-ws here)
6375 (setq donep t)))
6376 ;; If we are looking at a "begin", then stop
6377 ((and (looking-at vhdl-begin-fwd-re)
6378 (/= (preceding-char) ?_)
6379 (vhdl-begin-p nil))
6380 ;; If it's a leader "begin", then find the
6381 ;; right place
6382 (if (looking-at vhdl-leader-re)
6383 (save-excursion
6384 ;; set a default stop point at the begin
6385 (setq pos (point))
6386 ;; is the start point inside the leader area ?
6387 (goto-char (vhdl-end-of-leader))
6388 (vhdl-forward-syntactic-ws here)
6389 (if (< (point) here)
6390 ;; start point was not inside leader area
6391 ;; set stop point at word after leader
6392 (setq pos (point))))
6393 (forward-word 1)
6394 (vhdl-forward-syntactic-ws here)
6395 (setq pos (point)))
6396 (goto-char pos)
6397 (setq donep t))
6398 ;; If we are looking at a "statement", then stop
6399 ((and (looking-at vhdl-statement-fwd-re)
6400 (/= (preceding-char) ?_)
6401 (vhdl-statement-p nil))
6402 (setq donep t))
6403 ;; If we are looking at a case alternative key, then stop
6404 ((and (looking-at vhdl-case-alternative-re)
6405 (vhdl-case-alternative-p lim))
6406 (save-excursion
6407 ;; set a default stop point at the when
6408 (setq pos (point))
6409 ;; is the start point inside the case alternative key ?
6410 (looking-at vhdl-case-alternative-re)
6411 (goto-char (match-end 0))
6412 (vhdl-forward-syntactic-ws here)
6413 (if (< (point) here)
6414 ;; start point was not inside the case alternative key
6415 ;; set stop point at word after case alternative keyleader
6416 (setq pos (point))))
6417 (goto-char pos)
6418 (setq donep t))
6419 ;; Bogus find, continue
6421 (backward-char)))))
6424 ;; Defuns for calculating the current syntactic state:
6426 (defun vhdl-get-library-unit (bod placeholder)
6427 "If there is an enclosing library unit at BOD, with its \"begin\"
6428 keyword at PLACEHOLDER, then return the library unit type."
6429 (let ((here (vhdl-point 'bol)))
6430 (if (save-excursion
6431 (goto-char placeholder)
6432 (vhdl-safe (vhdl-forward-sexp 1 bod))
6433 (<= here (point)))
6434 (save-excursion
6435 (goto-char bod)
6436 (cond
6437 ((looking-at "e") 'entity)
6438 ((looking-at "a") 'architecture)
6439 ((looking-at "c") 'configuration)
6440 ((looking-at "p")
6441 (save-excursion
6442 (goto-char bod)
6443 (forward-sexp)
6444 (vhdl-forward-syntactic-ws here)
6445 (if (looking-at "body\\b[^_]")
6446 'package-body 'package))))))
6449 (defun vhdl-get-block-state (&optional lim)
6450 "Finds and records all the closest opens.
6451 LIM is the furthest back we need to search (it should be the
6452 previous libunit keyword)."
6453 (let ((here (point))
6454 (lim (or lim (point-min)))
6455 keyword sexp-start sexp-mid sexp-end
6456 preceding-sexp containing-sexp
6457 containing-begin containing-mid containing-paren)
6458 (save-excursion
6459 ;; Find the containing-paren, and use that as the limit
6460 (if (setq containing-paren
6461 (save-restriction
6462 (narrow-to-region lim (point))
6463 (vhdl-safe (scan-lists (point) -1 1))))
6464 (setq lim containing-paren))
6465 ;; Look backwards for "begin" and "end" keywords.
6466 (while (and (> (point) lim)
6467 (not containing-sexp))
6468 (setq keyword (vhdl-backward-to-block lim))
6469 (cond
6470 ((eq keyword 'begin)
6471 ;; Found a "begin" keyword
6472 (setq sexp-start (point))
6473 (setq sexp-mid (vhdl-corresponding-mid lim))
6474 (setq sexp-end (vhdl-safe
6475 (save-excursion
6476 (vhdl-forward-sexp 1 lim) (point))))
6477 (if (and sexp-end (<= sexp-end here))
6478 ;; we want to record this sexp, but we only want to
6479 ;; record the last-most of any of them before here
6480 (or preceding-sexp
6481 (setq preceding-sexp sexp-start))
6482 ;; we're contained in this sexp so put sexp-start on
6483 ;; front of list
6484 (setq containing-sexp sexp-start)
6485 (setq containing-mid sexp-mid)
6486 (setq containing-begin t)))
6487 ((eq keyword 'end)
6488 ;; Found an "end" keyword
6489 (forward-sexp)
6490 (setq sexp-end (point))
6491 (setq sexp-mid nil)
6492 (setq sexp-start
6493 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6494 (progn (backward-sexp) (point))))
6495 ;; we want to record this sexp, but we only want to
6496 ;; record the last-most of any of them before here
6497 (or preceding-sexp
6498 (setq preceding-sexp sexp-start)))
6500 ;; Check if the containing-paren should be the containing-sexp
6501 (if (and containing-paren
6502 (or (null containing-sexp)
6503 (< containing-sexp containing-paren)))
6504 (setq containing-sexp containing-paren
6505 preceding-sexp nil
6506 containing-begin nil
6507 containing-mid nil))
6508 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6512 (defconst vhdl-s-c-a-re
6513 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6515 (defun vhdl-skip-case-alternative (&optional lim)
6516 "Skip forward over case/when bodies, with optional maximal
6517 limit. If no next case alternative is found, nil is returned and
6518 point is not moved."
6519 (let ((lim (or lim (point-max)))
6520 (here (point))
6521 donep foundp)
6522 (while (and (< (point) lim)
6523 (not donep))
6524 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6525 (save-match-data
6526 (not (vhdl-in-literal)))
6527 (/= (match-beginning 0) here))
6528 (progn
6529 (goto-char (match-beginning 0))
6530 (cond
6531 ((and (looking-at "case")
6532 (re-search-forward "\\bis[^_]" lim t))
6533 (backward-sexp)
6534 (vhdl-forward-sexp))
6536 (setq donep t
6537 foundp t))))))
6538 (if (not foundp)
6539 (goto-char here))
6540 foundp))
6542 (defun vhdl-backward-skip-label (&optional lim)
6543 "Skip backward over a label, with optional maximal
6544 limit. If label is not found, nil is returned and point
6545 is not moved."
6546 (let ((lim (or lim (point-min)))
6547 placeholder)
6548 (if (save-excursion
6549 (vhdl-backward-syntactic-ws lim)
6550 (and (eq (preceding-char) ?:)
6551 (progn
6552 (backward-sexp)
6553 (setq placeholder (point))
6554 (looking-at vhdl-label-key))))
6555 (goto-char placeholder))
6558 (defun vhdl-forward-skip-label (&optional lim)
6559 "Skip forward over a label, with optional maximal
6560 limit. If label is not found, nil is returned and point
6561 is not moved."
6562 (let ((lim (or lim (point-max))))
6563 (if (looking-at vhdl-label-key)
6564 (progn
6565 (goto-char (match-end 0))
6566 (vhdl-forward-syntactic-ws lim)))
6569 (defun vhdl-get-syntactic-context ()
6570 "Guess the syntactic description of the current line of VHDL code."
6571 (save-excursion
6572 (save-restriction
6573 (beginning-of-line)
6574 (let* ((indent-point (point))
6575 (case-fold-search t)
6576 vec literal containing-sexp preceding-sexp
6577 containing-begin containing-mid containing-leader
6578 char-before-ip char-after-ip begin-after-ip end-after-ip
6579 placeholder lim library-unit
6582 ;; Reset the syntactic context
6583 (setq vhdl-syntactic-context nil)
6585 (save-excursion
6586 ;; Move to the start of the previous library unit, and
6587 ;; record the position of the "begin" keyword.
6588 (setq placeholder (vhdl-beginning-of-libunit))
6589 ;; The position of the "libunit" keyword gives us a gross
6590 ;; limit point.
6591 (setq lim (point))
6594 ;; If there is a previous library unit, and we are enclosed by
6595 ;; it, then set the syntax accordingly.
6596 (and placeholder
6597 (setq library-unit (vhdl-get-library-unit lim placeholder))
6598 (vhdl-add-syntax library-unit lim))
6600 ;; Find the surrounding state.
6601 (if (setq vec (vhdl-get-block-state lim))
6602 (progn
6603 (setq containing-sexp (aref vec 0))
6604 (setq preceding-sexp (aref vec 1))
6605 (setq containing-begin (aref vec 2))
6606 (setq containing-mid (aref vec 3))
6609 ;; set the limit on the farthest back we need to search
6610 (setq lim (if containing-sexp
6611 (save-excursion
6612 (goto-char containing-sexp)
6613 ;; set containing-leader if required
6614 (if (looking-at vhdl-leader-re)
6615 (setq containing-leader (vhdl-end-of-leader)))
6616 (vhdl-point 'bol))
6617 (point-min)))
6619 ;; cache char before and after indent point, and move point to
6620 ;; the most likely position to perform the majority of tests
6621 (goto-char indent-point)
6622 (skip-chars-forward " \t")
6623 (setq literal (vhdl-in-literal))
6624 (setq char-after-ip (following-char))
6625 (setq begin-after-ip (and
6626 (not literal)
6627 (looking-at vhdl-begin-fwd-re)
6628 (vhdl-begin-p)))
6629 (setq end-after-ip (and
6630 (not literal)
6631 (looking-at vhdl-end-fwd-re)
6632 (vhdl-end-p)))
6633 (vhdl-backward-syntactic-ws lim)
6634 (setq char-before-ip (preceding-char))
6635 (goto-char indent-point)
6636 (skip-chars-forward " \t")
6638 ;; now figure out syntactic qualities of the current line
6639 (cond
6640 ;; CASE 1: in a string or comment.
6641 ((memq literal '(string comment))
6642 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6643 ;; CASE 2: Line is at top level.
6644 ((null containing-sexp)
6645 ;; Find the point to which indentation will be relative
6646 (save-excursion
6647 (if (null preceding-sexp)
6648 ;; CASE 2X.1
6649 ;; no preceding-sexp -> use the preceding statement
6650 (vhdl-beginning-of-statement-1 lim)
6651 ;; CASE 2X.2
6652 ;; if there is a preceding-sexp then indent relative to it
6653 (goto-char preceding-sexp)
6654 ;; if not at boi, then the block-opening keyword is
6655 ;; probably following a label, so we need a different
6656 ;; relpos
6657 (if (/= (point) (vhdl-point 'boi))
6658 ;; CASE 2X.3
6659 (vhdl-beginning-of-statement-1 lim)))
6660 ;; v-b-o-s could have left us at point-min
6661 (and (bobp)
6662 ;; CASE 2X.4
6663 (vhdl-forward-syntactic-ws indent-point))
6664 (setq placeholder (point)))
6665 (cond
6666 ;; CASE 2A : we are looking at a block-open
6667 (begin-after-ip
6668 (vhdl-add-syntax 'block-open placeholder))
6669 ;; CASE 2B: we are looking at a block-close
6670 (end-after-ip
6671 (vhdl-add-syntax 'block-close placeholder))
6672 ;; CASE 2C: we are looking at a top-level statement
6673 ((progn
6674 (vhdl-backward-syntactic-ws lim)
6675 (or (bobp)
6676 (= (preceding-char) ?\;)))
6677 (vhdl-add-syntax 'statement placeholder))
6678 ;; CASE 2D: we are looking at a top-level statement-cont
6680 (vhdl-beginning-of-statement-1 lim)
6681 ;; v-b-o-s could have left us at point-min
6682 (and (bobp)
6683 ;; CASE 2D.1
6684 (vhdl-forward-syntactic-ws indent-point))
6685 (vhdl-add-syntax 'statement-cont (point)))
6686 )) ; end CASE 2
6687 ;; CASE 3: line is inside parentheses. Most likely we are
6688 ;; either in a subprogram argument (interface) list, or a
6689 ;; continued expression containing parentheses.
6690 ((null containing-begin)
6691 (vhdl-backward-syntactic-ws containing-sexp)
6692 (cond
6693 ;; CASE 3A: we are looking at the arglist closing paren
6694 ((eq char-after-ip ?\))
6695 (goto-char containing-sexp)
6696 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6697 ;; CASE 3B: we are looking at the first argument in an empty
6698 ;; argument list.
6699 ((eq char-before-ip ?\()
6700 (goto-char containing-sexp)
6701 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6702 ;; CASE 3C: we are looking at an arglist continuation line,
6703 ;; but the preceding argument is on the same line as the
6704 ;; opening paren. This case includes multi-line
6705 ;; expression paren groupings.
6706 ((and (save-excursion
6707 (goto-char (1+ containing-sexp))
6708 (skip-chars-forward " \t")
6709 (not (eolp))
6710 (not (looking-at "--")))
6711 (save-excursion
6712 (vhdl-beginning-of-statement-1 containing-sexp)
6713 (skip-chars-backward " \t(")
6714 (<= (point) containing-sexp)))
6715 (goto-char containing-sexp)
6716 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6717 ;; CASE 3D: we are looking at just a normal arglist
6718 ;; continuation line
6719 (t (vhdl-beginning-of-statement-1 containing-sexp)
6720 (vhdl-forward-syntactic-ws indent-point)
6721 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6723 ;; CASE 4: A block mid open
6724 ((and begin-after-ip
6725 (looking-at containing-mid))
6726 (goto-char containing-sexp)
6727 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6728 (if (looking-at vhdl-trailer-re)
6729 ;; CASE 4.1
6730 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6731 (vhdl-backward-skip-label (vhdl-point 'boi))
6732 (vhdl-add-syntax 'block-open (point)))
6733 ;; CASE 5: block close brace
6734 (end-after-ip
6735 (goto-char containing-sexp)
6736 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6737 (if (looking-at vhdl-trailer-re)
6738 ;; CASE 5.1
6739 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6740 (vhdl-backward-skip-label (vhdl-point 'boi))
6741 (vhdl-add-syntax 'block-close (point)))
6742 ;; CASE 6: A continued statement
6743 ((and (/= char-before-ip ?\;)
6744 ;; check it's not a trailer begin keyword, or a begin
6745 ;; keyword immediately following a label.
6746 (not (and begin-after-ip
6747 (or (looking-at vhdl-trailer-re)
6748 (save-excursion
6749 (vhdl-backward-skip-label containing-sexp)))))
6750 ;; check it's not a statement keyword
6751 (not (and (looking-at vhdl-statement-fwd-re)
6752 (vhdl-statement-p)))
6753 ;; see if the b-o-s is before the indent point
6754 (> indent-point
6755 (save-excursion
6756 (vhdl-beginning-of-statement-1 containing-sexp)
6757 ;; If we ended up after a leader, then this will
6758 ;; move us forward to the start of the first
6759 ;; statement. Note that a containing sexp here is
6760 ;; always a keyword, not a paren, so this will
6761 ;; have no effect if we hit the containing-sexp.
6762 (vhdl-forward-syntactic-ws indent-point)
6763 (setq placeholder (point))))
6764 ;; check it's not a block-intro
6765 (/= placeholder containing-sexp)
6766 ;; check it's not a case block-intro
6767 (save-excursion
6768 (goto-char placeholder)
6769 (or (not (looking-at vhdl-case-alternative-re))
6770 (> (match-end 0) indent-point))))
6771 ;; Make placeholder skip a label, but only if it puts us
6772 ;; before the indent point at the start of a line.
6773 (let ((new placeholder))
6774 (if (and (> indent-point
6775 (save-excursion
6776 (goto-char placeholder)
6777 (vhdl-forward-skip-label indent-point)
6778 (setq new (point))))
6779 (save-excursion
6780 (goto-char new)
6781 (eq new (progn (back-to-indentation) (point)))))
6782 (setq placeholder new)))
6783 (vhdl-add-syntax 'statement-cont placeholder)
6784 (if begin-after-ip
6785 (vhdl-add-syntax 'block-open)))
6786 ;; Statement. But what kind?
6787 ;; CASE 7: A case alternative key
6788 ((and (looking-at vhdl-case-alternative-re)
6789 (vhdl-case-alternative-p containing-sexp))
6790 ;; for a case alternative key, we set relpos to the first
6791 ;; non-whitespace char on the line containing the "case"
6792 ;; keyword.
6793 (goto-char containing-sexp)
6794 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6795 (if (looking-at vhdl-trailer-re)
6796 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6797 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6798 ;; CASE 8: statement catchall
6800 ;; we know its a statement, but we need to find out if it is
6801 ;; the first statement in a block
6802 (if containing-leader
6803 (goto-char containing-leader)
6804 (goto-char containing-sexp)
6805 ;; Note that a containing sexp here is always a keyword,
6806 ;; not a paren, so skip over the keyword.
6807 (forward-sexp))
6808 ;; move to the start of the first statement
6809 (vhdl-forward-syntactic-ws indent-point)
6810 (setq placeholder (point))
6811 ;; we want to ignore case alternatives keys when skipping forward
6812 (let (incase-p)
6813 (while (looking-at vhdl-case-alternative-re)
6814 (setq incase-p (point))
6815 ;; we also want to skip over the body of the
6816 ;; case/when statement if that doesn't put us at
6817 ;; after the indent-point
6818 (while (vhdl-skip-case-alternative indent-point))
6819 ;; set up the match end
6820 (looking-at vhdl-case-alternative-re)
6821 (goto-char (match-end 0))
6822 ;; move to the start of the first case alternative statement
6823 (vhdl-forward-syntactic-ws indent-point)
6824 (setq placeholder (point)))
6825 (cond
6826 ;; CASE 8A: we saw a case/when statement so we must be
6827 ;; in a switch statement. find out if we are at the
6828 ;; statement just after a case alternative key
6829 ((and incase-p
6830 (= (point) indent-point))
6831 ;; relpos is the "when" keyword
6832 (vhdl-add-syntax 'statement-case-intro incase-p))
6833 ;; CASE 8B: any old statement
6834 ((< (point) indent-point)
6835 ;; relpos is the first statement of the block
6836 (vhdl-add-syntax 'statement placeholder)
6837 (if begin-after-ip
6838 (vhdl-add-syntax 'block-open)))
6839 ;; CASE 8C: first statement in a block
6841 (goto-char containing-sexp)
6842 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6843 (if (looking-at vhdl-trailer-re)
6844 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6845 (vhdl-backward-skip-label (vhdl-point 'boi))
6846 (vhdl-add-syntax 'statement-block-intro (point))
6847 (if begin-after-ip
6848 (vhdl-add-syntax 'block-open)))
6852 ;; now we need to look at any modifiers
6853 (goto-char indent-point)
6854 (skip-chars-forward " \t")
6855 (if (looking-at "--")
6856 (vhdl-add-syntax 'comment))
6857 (if (eq literal 'pound)
6858 (vhdl-add-syntax 'cpp-macro))
6859 ;; return the syntax
6860 vhdl-syntactic-context))))
6862 ;; Standard indentation line-ups:
6864 (defun vhdl-lineup-arglist (langelem)
6865 "Lineup the current arglist line with the arglist appearing just
6866 after the containing paren which starts the arglist."
6867 (save-excursion
6868 (let* ((containing-sexp
6869 (save-excursion
6870 ;; arglist-cont-nonempty gives relpos ==
6871 ;; to boi of containing-sexp paren. This
6872 ;; is good when offset is +, but bad
6873 ;; when it is vhdl-lineup-arglist, so we
6874 ;; have to special case a kludge here.
6875 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6876 (progn
6877 (beginning-of-line)
6878 (backward-up-list 1)
6879 (skip-chars-forward " \t" (vhdl-point 'eol)))
6880 (goto-char (cdr langelem)))
6881 (point)))
6882 (cs-curcol (save-excursion
6883 (goto-char (cdr langelem))
6884 (current-column))))
6885 (if (save-excursion
6886 (beginning-of-line)
6887 (looking-at "[ \t]*)"))
6888 (progn (goto-char (match-end 0))
6889 (backward-sexp)
6890 (forward-char)
6891 (vhdl-forward-syntactic-ws)
6892 (- (current-column) cs-curcol))
6893 (goto-char containing-sexp)
6894 (or (eolp)
6895 (let ((eol (vhdl-point 'eol))
6896 (here (progn
6897 (forward-char)
6898 (skip-chars-forward " \t")
6899 (point))))
6900 (vhdl-forward-syntactic-ws)
6901 (if (< (point) eol)
6902 (goto-char here))))
6903 (- (current-column) cs-curcol)
6904 ))))
6906 (defun vhdl-lineup-arglist-intro (langelem)
6907 "Lineup an arglist-intro line to just after the open paren."
6908 (save-excursion
6909 (let ((cs-curcol (save-excursion
6910 (goto-char (cdr langelem))
6911 (current-column)))
6912 (ce-curcol (save-excursion
6913 (beginning-of-line)
6914 (backward-up-list 1)
6915 (skip-chars-forward " \t" (vhdl-point 'eol))
6916 (current-column))))
6917 (- ce-curcol cs-curcol -1))))
6919 (defun vhdl-lineup-comment (langelem)
6920 "Support old behavior for comment indentation. We look at
6921 vhdl-comment-only-line-offset to decide how to indent comment
6922 only-lines."
6923 (save-excursion
6924 (back-to-indentation)
6925 ;; at or to the right of comment-column
6926 (if (>= (current-column) comment-column)
6927 (vhdl-comment-indent)
6928 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6929 (if (not (bolp))
6930 (or (car-safe vhdl-comment-only-line-offset)
6931 vhdl-comment-only-line-offset)
6932 (or (cdr-safe vhdl-comment-only-line-offset)
6933 (car-safe vhdl-comment-only-line-offset)
6934 -1000 ;jam it against the left side
6935 )))))
6937 (defun vhdl-lineup-statement-cont (langelem)
6938 "Line up statement-cont after the assignment operator."
6939 (save-excursion
6940 (let* ((relpos (cdr langelem))
6941 (assignp (save-excursion
6942 (goto-char (vhdl-point 'boi))
6943 (and (re-search-forward "\\(<\\|:\\)="
6944 (vhdl-point 'eol) t)
6945 (- (point) (vhdl-point 'boi)))))
6946 (curcol (progn
6947 (goto-char relpos)
6948 (current-column)))
6949 foundp)
6950 (while (and (not foundp)
6951 (< (point) (vhdl-point 'eol)))
6952 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6953 (if (vhdl-in-literal)
6954 (forward-char)
6955 (if (= (preceding-char) ?\()
6956 ;; skip over any parenthesized expressions
6957 (goto-char (min (vhdl-point 'eol)
6958 (scan-lists (point) 1 1)))
6959 ;; found an assignment operator (not at eol)
6960 (setq foundp (not (looking-at "\\s-*$"))))))
6961 (if (not foundp)
6962 ;; there's no assignment operator on the line
6963 vhdl-basic-offset
6964 ;; calculate indentation column after assign and ws, unless
6965 ;; our line contains an assignment operator
6966 (if (not assignp)
6967 (progn
6968 (forward-char)
6969 (skip-chars-forward " \t")
6970 (setq assignp 0)))
6971 (- (current-column) assignp curcol))
6974 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6975 ;; Progress reporting
6977 (defvar vhdl-progress-info nil
6978 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6980 (defun vhdl-update-progress-info (string pos)
6981 "Update progress information."
6982 (when (and vhdl-progress-info (not noninteractive)
6983 (< vhdl-progress-interval
6984 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6985 (let ((delta (- (aref vhdl-progress-info 1)
6986 (aref vhdl-progress-info 0))))
6987 (if (= 0 delta)
6988 (message (concat string "... (100%s)") "%")
6989 (message (concat string "... (%2d%s)")
6990 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6991 delta) "%")))
6992 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6994 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6995 ;; Indentation commands
6997 (defun vhdl-electric-tab (&optional prefix-arg)
6998 "If preceeding character is part of a word or a paren then hippie-expand,
6999 else if right of non whitespace on line then insert tab,
7000 else if last command was a tab or return then dedent one step or if a comment
7001 toggle between normal indent and inline comment indent,
7002 else indent `correctly'."
7003 (interactive "*P")
7004 (vhdl-prepare-search-2
7005 (cond
7006 ;; expand word
7007 ((= (char-syntax (preceding-char)) ?w)
7008 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7009 (case-replace nil)
7010 (hippie-expand-only-buffers
7011 (or (and (boundp 'hippie-expand-only-buffers)
7012 hippie-expand-only-buffers)
7013 '(vhdl-mode))))
7014 (vhdl-expand-abbrev prefix-arg)))
7015 ;; expand parenthesis
7016 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7017 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7018 (case-replace nil))
7019 (vhdl-expand-paren prefix-arg)))
7020 ;; insert tab
7021 ((> (current-column) (current-indentation))
7022 (insert-tab))
7023 ;; toggle comment indent
7024 ((and (looking-at "--")
7025 (or (eq last-command 'vhdl-electric-tab)
7026 (eq last-command 'vhdl-electric-return)))
7027 (cond ((= (current-indentation) 0) ; no indent
7028 (indent-to 1)
7029 (indent-according-to-mode))
7030 ((< (current-indentation) comment-column) ; normal indent
7031 (indent-to comment-column)
7032 (indent-according-to-mode))
7033 (t ; inline comment indent
7034 (delete-region (line-beginning-position) (point)))))
7035 ;; dedent
7036 ((and (>= (current-indentation) vhdl-basic-offset)
7037 (or (eq last-command 'vhdl-electric-tab)
7038 (eq last-command 'vhdl-electric-return)))
7039 (backward-delete-char-untabify vhdl-basic-offset nil))
7040 ;; indent line
7041 (t (indent-according-to-mode)))
7042 (setq this-command 'vhdl-electric-tab)))
7044 (defun vhdl-electric-return ()
7045 "newline-and-indent or indent-new-comment-line if in comment and preceding
7046 character is a space."
7047 (interactive)
7048 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7049 (indent-new-comment-line)
7050 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7051 (vhdl-fix-case-word -1))
7052 (newline-and-indent)))
7054 (defun vhdl-indent-line ()
7055 "Indent the current line as VHDL code. Returns the amount of
7056 indentation change."
7057 (interactive)
7058 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7059 (pos (- (point-max) (point)))
7060 (indent
7061 (if syntax
7062 ;; indent syntax-based
7063 (if (and (eq (caar syntax) 'comment)
7064 (>= (vhdl-get-offset (car syntax)) comment-column))
7065 ;; special case: comments at or right of comment-column
7066 (vhdl-get-offset (car syntax))
7067 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7068 ;; indent like previous nonblank line
7069 (save-excursion (beginning-of-line)
7070 (re-search-backward "^[^\n]" nil t)
7071 (current-indentation))))
7072 (shift-amt (- indent (current-indentation))))
7073 (and vhdl-echo-syntactic-information-p
7074 (message "syntax: %s, indent= %d" syntax indent))
7075 (unless (zerop shift-amt)
7076 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7077 (beginning-of-line)
7078 (indent-to indent))
7079 (if (< (point) (vhdl-point 'boi))
7080 (back-to-indentation)
7081 ;; If initial point was within line's indentation, position after
7082 ;; the indentation. Else stay at same point in text.
7083 (when (> (- (point-max) pos) (point))
7084 (goto-char (- (point-max) pos))))
7085 (run-hooks 'vhdl-special-indent-hook)
7086 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7087 shift-amt))
7089 (defun vhdl-indent-region (beg end column)
7090 "Indent region as VHDL code.
7091 Adds progress reporting to `indent-region'."
7092 (interactive "r\nP")
7093 (when vhdl-progress-interval
7094 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7095 (count-lines (point-min) end) 0)))
7096 (indent-region beg end column)
7097 (when vhdl-progress-interval (message "Indenting...done"))
7098 (setq vhdl-progress-info nil))
7100 (defun vhdl-indent-buffer ()
7101 "Indent whole buffer as VHDL code.
7102 Calls `indent-region' for whole buffer and adds progress reporting."
7103 (interactive)
7104 (vhdl-indent-region (point-min) (point-max) nil))
7106 (defun vhdl-indent-group ()
7107 "Indent group of lines between empty lines."
7108 (interactive)
7109 (let ((beg (save-excursion
7110 (if (re-search-backward vhdl-align-group-separate nil t)
7111 (point-marker)
7112 (point-min-marker))))
7113 (end (save-excursion
7114 (if (re-search-forward vhdl-align-group-separate nil t)
7115 (point-marker)
7116 (point-max-marker)))))
7117 (vhdl-indent-region beg end nil)))
7119 (defun vhdl-indent-sexp (&optional endpos)
7120 "Indent each line of the list starting just after point.
7121 If optional arg ENDPOS is given, indent each line, stopping when
7122 ENDPOS is encountered."
7123 (interactive)
7124 (save-excursion
7125 (let ((beg (point))
7126 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7127 (indent-region beg end nil))))
7129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7130 ;; Miscellaneous commands
7132 (defun vhdl-show-syntactic-information ()
7133 "Show syntactic information for current line."
7134 (interactive)
7135 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7136 (vhdl-keep-region-active))
7138 ;; Verification and regression functions:
7140 (defun vhdl-regress-line (&optional arg)
7141 "Check syntactic information for current line."
7142 (interactive "P")
7143 (let ((expected (save-excursion
7144 (end-of-line)
7145 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7146 (forward-char 4)
7147 (read (current-buffer)))))
7148 (actual (vhdl-get-syntactic-context))
7149 (expurgated))
7150 ;; remove the library unit symbols
7151 (mapcar
7152 (function
7153 (lambda (elt)
7154 (if (memq (car elt) '(entity configuration package
7155 package-body architecture))
7157 (setq expurgated (append expurgated (list elt))))))
7158 actual)
7159 (if (and (not arg) expected (listp expected))
7160 (if (not (equal expected expurgated))
7161 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7162 (save-excursion
7163 (beginning-of-line)
7164 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7165 (end-of-line)
7166 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7167 (delete-region (point) (line-end-position)))
7168 (insert " -- ")
7169 (insert (format "%s" expurgated))))))
7170 (vhdl-keep-region-active))
7173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7174 ;;; Alignment, whitespace fixup, beautifying
7175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7177 (defconst vhdl-align-alist
7179 ;; after some keywords
7180 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7181 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7182 ;; before ':'
7183 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7184 ;; after direction specifications
7185 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7186 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7187 ;; before "==", ":=", "=>", and "<="
7188 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7189 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7190 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7191 ;; before some keywords
7192 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7193 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7194 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7195 ;; before "=>" since "when/else ... =>" can occur
7196 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7198 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7199 It is searched in order. If REGEXP is found anywhere in the first
7200 line of a region to be aligned, ALIGN-PATTERN will be used for that
7201 region. ALIGN-PATTERN must include the whitespace to be expanded or
7202 contracted. It may also provide regexps for the text surrounding the
7203 whitespace. SUBEXP specifies which sub-expression of
7204 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7207 ;; Align code
7209 (defvar vhdl-align-try-all-clauses t
7210 "If REGEXP is not found on the first line of the region that clause
7211 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7213 (defun vhdl-do-group (function &optional spacing)
7214 "Apply FUNCTION on group of lines between empty lines."
7215 (let
7216 ;; search for group beginning
7217 ((beg (save-excursion
7218 (if (re-search-backward vhdl-align-group-separate nil t)
7219 (progn (beginning-of-line 2) (back-to-indentation) (point))
7220 (point-min))))
7221 ;; search for group end
7222 (end (save-excursion
7223 (if (re-search-forward vhdl-align-group-separate nil t)
7224 (progn (beginning-of-line) (point))
7225 (point-max)))))
7226 ;; run FUNCTION
7227 (funcall function beg end spacing)))
7229 (defun vhdl-do-list (function &optional spacing)
7230 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7231 parentheses."
7232 (let (beg end)
7233 (save-excursion
7234 ;; search for beginning of balanced group of parentheses
7235 (setq beg (vhdl-re-search-backward "[()]" nil t))
7236 (while (looking-at ")")
7237 (forward-char) (backward-sexp)
7238 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7239 ;; search for end of balanced group of parentheses
7240 (when beg
7241 (forward-list)
7242 (setq end (point))
7243 (goto-char (1+ beg))
7244 (skip-chars-forward " \t\n")
7245 (setq beg (point))))
7246 ;; run FUNCTION
7247 (if beg
7248 (funcall function beg end spacing)
7249 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7251 (defun vhdl-do-same-indent (function &optional spacing)
7252 "Apply FUNCTION to block of lines with same indent."
7253 (let ((indent (current-indentation))
7254 beg end)
7255 ;; search for first line with same indent
7256 (save-excursion
7257 (while (and (not (bobp))
7258 (or (looking-at "^\\s-*\\(--.*\\)?$")
7259 (= (current-indentation) indent)))
7260 (unless (looking-at "^\\s-*$")
7261 (back-to-indentation) (setq beg (point)))
7262 (beginning-of-line -0)))
7263 ;; search for last line with same indent
7264 (save-excursion
7265 (while (and (not (eobp))
7266 (or (looking-at "^\\s-*\\(--.*\\)?$")
7267 (= (current-indentation) indent)))
7268 (if (looking-at "^\\s-*$")
7269 (beginning-of-line 2)
7270 (beginning-of-line 2)
7271 (setq end (point)))))
7272 ;; run FUNCTION
7273 (funcall function beg end spacing)))
7275 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7276 "Attempt to align a range of lines based on the content of the
7277 lines. The definition of `alignment-list' determines the matching
7278 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7279 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7280 indentation is done before aligning."
7281 (interactive "r\np")
7282 (setq alignment-list (or alignment-list vhdl-align-alist))
7283 (setq spacing (or spacing 1))
7284 (save-excursion
7285 (let (bol indent)
7286 (goto-char end)
7287 (setq end (point-marker))
7288 (goto-char begin)
7289 (setq bol (setq begin (progn (beginning-of-line) (point))))
7290 ; (untabify bol end)
7291 (when indent
7292 (indent-region bol end nil))))
7293 (let ((copy (copy-alist alignment-list)))
7294 (vhdl-prepare-search-2
7295 (while copy
7296 (save-excursion
7297 (goto-char begin)
7298 (let (element
7299 (eol (save-excursion (progn (end-of-line) (point)))))
7300 (setq element (nth 0 copy))
7301 (when (and (or (and (listp (car element))
7302 (memq major-mode (car element)))
7303 (eq major-mode (car element)))
7304 (or vhdl-align-try-all-clauses
7305 (re-search-forward (car (cdr element)) eol t)))
7306 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7307 (car (cdr (cdr (cdr element)))) spacing))
7308 (setq copy (cdr copy))))))))
7310 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7311 "Align a range of lines from BEGIN to END. The regular expression
7312 MATCH must match exactly one field: the whitespace to be
7313 contracted/expanded. The alignment column will equal the
7314 rightmost column of the widest whitespace block. SPACING is
7315 the amount of extra spaces to add to the calculated maximum required.
7316 SPACING defaults to 1 so that at least one space is inserted after
7317 the token in MATCH."
7318 (setq spacing (or spacing 1))
7319 (setq substr (or substr 1))
7320 (save-excursion
7321 (let (distance (max 0) (lines 0) bol eol width)
7322 ;; Determine the greatest whitespace distance to the alignment
7323 ;; character
7324 (goto-char begin)
7325 (setq eol (progn (end-of-line) (point))
7326 bol (setq begin (progn (beginning-of-line) (point))))
7327 (while (< bol end)
7328 (save-excursion
7329 (when (and (re-search-forward match eol t)
7330 (not (vhdl-in-literal)))
7331 (setq distance (- (match-beginning substr) bol))
7332 (when (> distance max)
7333 (setq max distance))))
7334 (forward-line)
7335 (setq bol (point)
7336 eol (save-excursion (end-of-line) (point)))
7337 (setq lines (1+ lines)))
7338 ;; Now insert enough maxs to push each assignment operator to
7339 ;; the same column. We need to use 'lines' as a counter, since
7340 ;; the location of the mark may change
7341 (goto-char (setq bol begin))
7342 (setq eol (save-excursion (end-of-line) (point)))
7343 (while (> lines 0)
7344 (when (and (re-search-forward match eol t)
7345 (not (vhdl-in-literal)))
7346 (setq width (- (match-end substr) (match-beginning substr)))
7347 (setq distance (- (match-beginning substr) bol))
7348 (goto-char (match-beginning substr))
7349 (delete-char width)
7350 (insert-char ? (+ (- max distance) spacing)))
7351 (beginning-of-line)
7352 (forward-line)
7353 (setq bol (point)
7354 eol (save-excursion (end-of-line) (point)))
7355 (setq lines (1- lines))))))
7357 (defun vhdl-align-region-groups (beg end &optional spacing
7358 no-message no-comments)
7359 "Align region, treat groups of lines separately."
7360 (interactive "r\nP")
7361 (save-excursion
7362 (let (orig pos)
7363 (goto-char beg)
7364 (beginning-of-line)
7365 (setq orig (point-marker))
7366 (setq beg (point))
7367 (goto-char end)
7368 (setq end (point-marker))
7369 (untabify beg end)
7370 (unless no-message
7371 (when vhdl-progress-interval
7372 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7373 (count-lines (point-min) end) 0))))
7374 (vhdl-fixup-whitespace-region beg end t)
7375 (goto-char beg)
7376 (if (not vhdl-align-groups)
7377 ;; align entire region
7378 (progn (vhdl-align-region-1 beg end spacing)
7379 (unless no-comments
7380 (vhdl-align-inline-comment-region-1 beg end)))
7381 ;; align groups
7382 (while (and (< beg end)
7383 (re-search-forward vhdl-align-group-separate end t))
7384 (setq pos (point-marker))
7385 (vhdl-align-region-1 beg pos spacing)
7386 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7387 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7388 (setq beg (1+ pos))
7389 (goto-char beg))
7390 ;; align last group
7391 (when (< beg end)
7392 (vhdl-align-region-1 beg end spacing)
7393 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7394 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7395 (when vhdl-indent-tabs-mode
7396 (tabify orig end))
7397 (unless no-message
7398 (when vhdl-progress-interval (message "Aligning...done"))
7399 (setq vhdl-progress-info nil)))))
7401 (defun vhdl-align-region (beg end &optional spacing)
7402 "Align region, treat blocks with same indent and argument lists separately."
7403 (interactive "r\nP")
7404 (if (not vhdl-align-same-indent)
7405 ;; align entire region
7406 (vhdl-align-region-groups beg end spacing)
7407 ;; align blocks with same indent and argument lists
7408 (save-excursion
7409 (let ((cur-beg beg)
7410 indent cur-end)
7411 (when vhdl-progress-interval
7412 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7413 (count-lines (point-min) end) 0)))
7414 (goto-char end)
7415 (setq end (point-marker))
7416 (goto-char cur-beg)
7417 (while (< (point) end)
7418 ;; is argument list opening?
7419 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7420 (point) (vhdl-point 'eol)))))
7421 ;; determine region for argument list
7422 (progn (goto-char cur-beg)
7423 (forward-sexp)
7424 (setq cur-end (point))
7425 (beginning-of-line 2))
7426 ;; determine region with same indent
7427 (setq indent (current-indentation))
7428 (setq cur-beg (point))
7429 (setq cur-end (vhdl-point 'bonl))
7430 (beginning-of-line 2)
7431 (while (and (< (point) end)
7432 (or (looking-at "^\\s-*\\(--.*\\)?$")
7433 (= (current-indentation) indent))
7434 (<= (save-excursion
7435 (nth 0 (parse-partial-sexp
7436 (point) (vhdl-point 'eol)))) 0))
7437 (unless (looking-at "^\\s-*$")
7438 (setq cur-end (vhdl-point 'bonl)))
7439 (beginning-of-line 2)))
7440 ;; align region
7441 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7442 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7443 (when vhdl-progress-interval (message "Aligning...done"))
7444 (setq vhdl-progress-info nil)))))
7446 (defun vhdl-align-group (&optional spacing)
7447 "Align group of lines between empty lines."
7448 (interactive)
7449 (vhdl-do-group 'vhdl-align-region spacing))
7451 (defun vhdl-align-list (&optional spacing)
7452 "Align the lines of a list surrounded by a balanced group of parentheses."
7453 (interactive)
7454 (vhdl-do-list 'vhdl-align-region-groups spacing))
7456 (defun vhdl-align-same-indent (&optional spacing)
7457 "Align block of lines with same indent."
7458 (interactive)
7459 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7461 (defun vhdl-align-declarations (&optional spacing)
7462 "Align the lines within the declarative part of a design unit."
7463 (interactive)
7464 (let (beg end)
7465 (vhdl-prepare-search-2
7466 (save-excursion
7467 ;; search for declarative part
7468 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7469 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7470 (setq beg (point))
7471 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7472 (setq end (point)))))
7473 (if beg
7474 (vhdl-align-region-groups beg end spacing)
7475 (error "ERROR: Not within the declarative part of a design unit"))))
7477 (defun vhdl-align-buffer ()
7478 "Align buffer."
7479 (interactive)
7480 (vhdl-align-region (point-min) (point-max)))
7482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7483 ;; Align inline comments
7485 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7486 "Align inline comments in region."
7487 (save-excursion
7488 (let ((start-max comment-column)
7489 (length-max 0)
7490 comment-list start-list tmp-list start length
7491 cur-start prev-start no-code)
7492 (setq spacing (or spacing 2))
7493 (vhdl-prepare-search-2
7494 (goto-char beg)
7495 ;; search for comment start positions and lengths
7496 (while (< (point) end)
7497 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7498 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7499 (not (save-excursion (goto-char (match-beginning 2))
7500 (vhdl-in-literal))))
7501 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7502 (setq length (- (match-end 2) (match-beginning 2)))
7503 (setq start-max (max start start-max))
7504 (setq length-max (max length length-max))
7505 (setq comment-list (cons (cons start length) comment-list)))
7506 (beginning-of-line 2))
7507 (setq comment-list
7508 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7509 ;; reduce start positions
7510 (setq start-list (list (caar comment-list)))
7511 (setq comment-list (cdr comment-list))
7512 (while comment-list
7513 (unless (or (= (caar comment-list) (car start-list))
7514 (<= (+ (car start-list) (cdar comment-list))
7515 end-comment-column))
7516 (setq start-list (cons (caar comment-list) start-list)))
7517 (setq comment-list (cdr comment-list)))
7518 ;; align lines as nicely as possible
7519 (goto-char beg)
7520 (while (< (point) end)
7521 (setq cur-start nil)
7522 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7523 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7524 (not (save-excursion
7525 (goto-char (match-beginning 3))
7526 (vhdl-in-literal))))
7527 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7528 (>= (- (match-end 2) (match-beginning 2))
7529 comment-column))))
7530 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7531 (setq length (- (match-end 3) (match-beginning 3)))
7532 (setq no-code (= (match-beginning 1) (match-end 1)))
7533 ;; insert minimum whitespace
7534 (goto-char (match-end 2))
7535 (delete-region (match-beginning 2) (match-end 2))
7536 (insert-char ?\ spacing)
7537 (setq tmp-list start-list)
7538 ;; insert additional whitespace to align
7539 (setq cur-start
7540 (cond
7541 ;; align comment-only line to inline comment of previous line
7542 ((and no-code prev-start
7543 (<= length (- end-comment-column prev-start)))
7544 prev-start)
7545 ;; align all comments at `start-max' if this is possible
7546 ((<= (+ start-max length-max) end-comment-column)
7547 start-max)
7548 ;; align at `comment-column' if possible
7549 ((and (<= start comment-column)
7550 (<= length (- end-comment-column comment-column)))
7551 comment-column)
7552 ;; align at left-most possible start position otherwise
7554 (while (and tmp-list (< (car tmp-list) start))
7555 (setq tmp-list (cdr tmp-list)))
7556 (car tmp-list))))
7557 (indent-to cur-start))
7558 (setq prev-start cur-start)
7559 (beginning-of-line 2))))))
7561 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7562 "Align inline comments within a region. Groups of code lines separated by
7563 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7564 (interactive "r\nP")
7565 (save-excursion
7566 (let (orig pos)
7567 (goto-char beg)
7568 (beginning-of-line)
7569 (setq orig (point-marker))
7570 (setq beg (point))
7571 (goto-char end)
7572 (setq end (point-marker))
7573 (untabify beg end)
7574 (unless no-message (message "Aligning inline comments..."))
7575 (goto-char beg)
7576 (if (not vhdl-align-groups)
7577 ;; align entire region
7578 (vhdl-align-inline-comment-region-1 beg end spacing)
7579 ;; align groups
7580 (while (and (< beg end)
7581 (re-search-forward vhdl-align-group-separate end t))
7582 (setq pos (point-marker))
7583 (vhdl-align-inline-comment-region-1 beg pos spacing)
7584 (setq beg (1+ pos))
7585 (goto-char beg))
7586 ;; align last group
7587 (when (< beg end)
7588 (vhdl-align-inline-comment-region-1 beg end spacing)))
7589 (when vhdl-indent-tabs-mode
7590 (tabify orig end))
7591 (unless no-message (message "Aligning inline comments...done")))))
7593 (defun vhdl-align-inline-comment-group (&optional spacing)
7594 "Align inline comments within a group of lines between empty lines."
7595 (interactive)
7596 (save-excursion
7597 (let ((start (point))
7598 beg end)
7599 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7600 (point-marker) (point-max)))
7601 (goto-char start)
7602 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7603 (point) (point-min)))
7604 (untabify beg end)
7605 (message "Aligning inline comments...")
7606 (vhdl-align-inline-comment-region-1 beg end)
7607 (when vhdl-indent-tabs-mode
7608 (tabify beg end))
7609 (message "Aligning inline comments...done"))))
7611 (defun vhdl-align-inline-comment-buffer ()
7612 "Align inline comments within buffer. Groups of code lines separated by
7613 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7614 (interactive)
7615 (vhdl-align-inline-comment-region (point-min) (point-max)))
7617 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7618 ;; Fixup whitespace
7620 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7621 "Fixup whitespace in region. Surround operator symbols by one space,
7622 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7623 end of line, do nothing in comments and strings."
7624 (interactive "r")
7625 (unless no-message (message "Fixing up whitespace..."))
7626 (save-excursion
7627 (goto-char end)
7628 (setq end (point-marker))
7629 ;; have no space before and one space after `,' and ';'
7630 (goto-char beg)
7631 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7632 (if (match-string 1)
7633 (goto-char (match-end 1))
7634 (replace-match "\\3 " nil nil nil 3)))
7635 ;; have no space after `('
7636 (goto-char beg)
7637 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
7638 (if (match-string 1)
7639 (goto-char (match-end 1))
7640 (replace-match "\\2")))
7641 ;; have no space before `)'
7642 (goto-char beg)
7643 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7644 (if (match-string 1)
7645 (goto-char (match-end 1))
7646 (replace-match "\\2")))
7647 ;; surround operator symbols by one space
7648 (goto-char beg)
7649 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7650 (if (match-string 1)
7651 (goto-char (match-end 1))
7652 (replace-match "\\3 \\4 \\5")
7653 (goto-char (match-end 2))))
7654 ;; eliminate multiple spaces and spaces at end of line
7655 (goto-char beg)
7656 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7657 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7658 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7659 (progn (replace-match "" nil nil) t))
7660 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7661 (progn (replace-match ";" nil nil) t))
7662 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7663 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7664 (progn (replace-match " " nil nil) t))
7665 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7666 (progn (replace-match " " nil nil) t))
7667 ; (re-search-forward "[^ \t-]+" end t))))
7668 (re-search-forward "[^ \t\"-]+" end t))))
7669 (unless no-message (message "Fixing up whitespace...done")))
7671 (defun vhdl-fixup-whitespace-buffer ()
7672 "Fixup whitespace in buffer. Surround operator symbols by one space,
7673 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7674 end of line, do nothing in comments."
7675 (interactive)
7676 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7679 ;; Beautify
7681 (defun vhdl-beautify-region (beg end)
7682 "Beautify region by applying indentation, whitespace fixup, alignment, and
7683 case fixing to a region. Calls functions `vhdl-indent-buffer',
7684 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7685 `vhdl-fix-case-buffer'."
7686 (interactive "r")
7687 (setq end (save-excursion (goto-char end) (point-marker)))
7688 (vhdl-indent-region beg end nil)
7689 (let ((vhdl-align-groups t))
7690 (vhdl-align-region beg end))
7691 (vhdl-fix-case-region beg end))
7693 (defun vhdl-beautify-buffer ()
7694 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7695 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7696 buffer."
7697 (interactive)
7698 (vhdl-beautify-region (point-min) (point-max))
7699 (when noninteractive (save-buffer)))
7701 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7702 ;; Code filling
7704 (defun vhdl-fill-region (beg end &optional arg)
7705 "Fill lines for a region of code."
7706 (interactive "r\np")
7707 (save-excursion
7708 (goto-char beg)
7709 (let ((margin (if arg (current-indentation) (current-column))))
7710 (goto-char end)
7711 (setq end (point-marker))
7712 ;; remove inline comments, newlines and whitespace
7713 (vhdl-comment-kill-region beg end)
7714 (vhdl-comment-kill-inline-region beg end)
7715 (subst-char-in-region beg (1- end) ?\n ?\ )
7716 (vhdl-fixup-whitespace-region beg end)
7717 ;; wrap and end-comment-column
7718 (goto-char beg)
7719 (while (re-search-forward "\\s-" end t)
7720 (when(> (current-column) vhdl-end-comment-column)
7721 (backward-char)
7722 (when (re-search-backward "\\s-" beg t)
7723 (replace-match "\n")
7724 (indent-to margin)))))))
7726 (defun vhdl-fill-group ()
7727 "Fill group of lines between empty lines."
7728 (interactive)
7729 (vhdl-do-group 'vhdl-fill-region))
7731 (defun vhdl-fill-list ()
7732 "Fill the lines of a list surrounded by a balanced group of parentheses."
7733 (interactive)
7734 (vhdl-do-list 'vhdl-fill-region))
7736 (defun vhdl-fill-same-indent ()
7737 "Fill the lines of block of lines with same indent."
7738 (interactive)
7739 (vhdl-do-same-indent 'vhdl-fill-region))
7742 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7743 ;;; Code updating/fixing
7744 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7747 ;; Sensitivity list update
7749 ;; Strategy:
7750 ;; - no sensitivity list is generated for processes with wait statements
7751 ;; - otherwise, do the following:
7752 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7753 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7754 ;; manually entered global signals)
7755 ;; 3. signals from 1. and 2. form the list of visible signals
7756 ;; 4. search for if/elsif conditions containing an event (sequential code)
7757 ;; 5. scan for strings that are within syntactical regions where signals are
7758 ;; read but not within sequential code, and that correspond to visible
7759 ;; signals
7760 ;; 6. replace sensitivity list by list of signals from 5.
7762 (defun vhdl-update-sensitivity-list-process ()
7763 "Update sensitivity list of current process."
7764 (interactive)
7765 (save-excursion
7766 (vhdl-prepare-search-2
7767 (end-of-line)
7768 ;; look whether in process
7769 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7770 (equal (upcase (match-string 2)) "PROCESS")
7771 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7772 (error "ERROR: Not within a process")
7773 (message "Updating sensitivity list...")
7774 (vhdl-update-sensitivity-list)
7775 (message "Updating sensitivity list...done")))))
7777 (defun vhdl-update-sensitivity-list-buffer ()
7778 "Update sensitivity list of all processes in current buffer."
7779 (interactive)
7780 (save-excursion
7781 (vhdl-prepare-search-2
7782 (goto-char (point-min))
7783 (message "Updating sensitivity lists...")
7784 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7785 (goto-char (match-beginning 0))
7786 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
7787 (message "Updating sensitivity lists...done"))))
7789 (defun vhdl-update-sensitivity-list ()
7790 "Update sensitivity list."
7791 (let ((proc-beg (point))
7792 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7793 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7794 seq-region-list)
7795 (cond
7796 ;; search for wait statement (no sensitivity list allowed)
7797 ((progn (goto-char proc-mid)
7798 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7799 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7800 ;; combinational process (update sensitivity list)
7802 (let
7803 ;; scan for visible signals
7804 ((visible-list (vhdl-get-visible-signals))
7805 ;; define syntactic regions where signals are read
7806 (scan-regions-list
7807 '(;; right-hand side of signal/variable assignment
7808 ;; (special case: "<=" is relational operator in a condition)
7809 ((re-search-forward "[<:]=" proc-end t)
7810 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7811 ;; if condition
7812 ((re-search-forward "^\\s-*if\\>" proc-end t)
7813 (re-search-forward "\\<then\\>" proc-end t))
7814 ;; elsif condition
7815 ((re-search-forward "\\<elsif\\>" proc-end t)
7816 (re-search-forward "\\<then\\>" proc-end t))
7817 ;; while loop condition
7818 ((re-search-forward "^\\s-*while\\>" proc-end t)
7819 (re-search-forward "\\<loop\\>" proc-end t))
7820 ;; exit/next condition
7821 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7822 (re-search-forward ";" proc-end t))
7823 ;; assert condition
7824 ((re-search-forward "\\<assert\\>" proc-end t)
7825 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7826 ;; case expression
7827 ((re-search-forward "^\\s-*case\\>" proc-end t)
7828 (re-search-forward "\\<is\\>" proc-end t))
7829 ;; parameter list of procedure call
7830 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7831 (1- (point)))
7832 (progn (backward-char) (forward-sexp)
7833 (while (looking-at "(") (forward-sexp)) (point)))))
7834 name read-list sens-list signal-list
7835 sens-beg sens-end beg end margin)
7836 ;; scan for signals in old sensitivity list
7837 (goto-char proc-beg)
7838 (re-search-forward "\\<process\\>" proc-mid t)
7839 (if (not (looking-at "[ \t\n]*("))
7840 (setq sens-beg (point))
7841 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7842 (goto-char (match-end 1))
7843 (forward-sexp)
7844 (setq sens-end (1- (point)))
7845 (goto-char sens-beg)
7846 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7847 (setq sens-list
7848 (cons (downcase (match-string 0)) sens-list))
7849 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7850 (setq signal-list (append visible-list sens-list))
7851 ;; search for sequential parts
7852 (goto-char proc-mid)
7853 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7854 (setq end (re-search-forward "\\<then\\>" proc-end t))
7855 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7856 (goto-char end)
7857 (backward-word 1)
7858 (vhdl-forward-sexp)
7859 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7860 (beginning-of-line)))
7861 ;; scan for signals read in process
7862 (while scan-regions-list
7863 (goto-char proc-mid)
7864 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7865 (setq end (eval (nth 1 (car scan-regions-list)))))
7866 (goto-char beg)
7867 (unless (or (vhdl-in-literal)
7868 (and seq-region-list
7869 (let ((tmp-list seq-region-list))
7870 (while (and tmp-list
7871 (< (point) (caar tmp-list)))
7872 (setq tmp-list (cdr tmp-list)))
7873 (and tmp-list (< (point) (cdar tmp-list))))))
7874 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
7875 (setq name (match-string 1))
7876 (when (and (not (match-string 4)) ; not when formal parameter
7877 (not (and (match-string 3) ; not event attribute
7878 (not (member (downcase (match-string 3))
7879 '("event" "last_event" "transaction")))))
7880 (member (downcase name) signal-list))
7881 (unless (member-ignore-case name read-list)
7882 (setq read-list (cons name read-list))))
7883 (goto-char (match-end 1)))))
7884 (setq scan-regions-list (cdr scan-regions-list)))
7885 ;; update sensitivity list
7886 (goto-char sens-beg)
7887 (if sens-end
7888 (delete-region sens-beg sens-end)
7889 (when read-list
7890 (insert " ()") (backward-char)))
7891 (setq read-list (sort read-list 'string<))
7892 (when read-list
7893 (setq margin (current-column))
7894 (insert (car read-list))
7895 (setq read-list (cdr read-list))
7896 (while read-list
7897 (insert ",")
7898 (if (<= (+ (current-column) (length (car read-list)) 2)
7899 end-comment-column)
7900 (insert " ")
7901 (insert "\n") (indent-to margin))
7902 (insert (car read-list))
7903 (setq read-list (cdr read-list)))))))))
7905 (defun vhdl-get-visible-signals ()
7906 "Get all signals visible in the current block."
7907 (let (beg end signal-list entity-name file-name)
7908 (vhdl-prepare-search-2
7909 ;; get entity name
7910 (save-excursion
7911 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
7912 (not (equal "END" (upcase (match-string 1))))
7913 (setq entity-name (match-string 2)))
7914 (error "ERROR: Not within an architecture")))
7915 ;; search for signals declared in entity port clause
7916 (save-excursion
7917 (goto-char (point-min))
7918 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7919 (setq file-name
7920 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7921 "." (file-name-extension (buffer-file-name)))))
7922 (vhdl-visit-file
7923 file-name t
7924 (vhdl-prepare-search-2
7925 (goto-char (point-min))
7926 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7927 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7928 (when (setq beg (re-search-forward
7929 "^\\s-*port[ \t\n]*("
7930 (save-excursion
7931 (re-search-forward "^end\\>" nil t)) t))
7932 (setq end (save-excursion
7933 (backward-char) (forward-sexp) (point)))
7934 (vhdl-forward-syntactic-ws)
7935 (while (< (point) end)
7936 (when (looking-at "signal[ \t\n]+")
7937 (goto-char (match-end 0)))
7938 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7939 (setq signal-list
7940 (cons (downcase (match-string 1)) signal-list))
7941 (goto-char (match-end 0))
7942 (vhdl-forward-syntactic-ws))
7943 (re-search-forward ";" end 1)
7944 (vhdl-forward-syntactic-ws)))))))
7945 ;; search for signals declared in architecture declarative part
7946 (save-excursion
7947 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7948 (not (equal "END" (upcase (match-string 1))))
7949 (setq end (re-search-forward "^begin\\>" nil t))))
7950 (error "ERROR: No architecture declarative part found")
7951 ;; scan for all declared signal and alias names
7952 (goto-char beg)
7953 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7954 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7955 (if (match-string 2)
7956 ;; scan signal name
7957 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7958 (setq signal-list
7959 (cons (downcase (match-string 1)) signal-list))
7960 (goto-char (match-end 0)))
7961 ;; scan alias name, check is alias of (declared) signal
7962 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7963 (member (downcase (match-string 2)) signal-list))
7964 (setq signal-list
7965 (cons (downcase (match-string 1)) signal-list))
7966 (goto-char (match-end 0))))
7967 (setq beg (point))))))
7968 ;; search for signals declared in surrounding block declarative parts
7969 (save-excursion
7970 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7971 (match-string 2))
7972 (goto-char (match-end 2))
7973 (vhdl-backward-sexp)
7974 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7975 beg)
7976 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7977 ;; scan for all declared signal names
7978 (goto-char beg)
7979 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7980 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7981 (if (match-string 2)
7982 ;; scan signal name
7983 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7984 (setq signal-list
7985 (cons (downcase (match-string 1)) signal-list))
7986 (goto-char (match-end 0)))
7987 ;; scan alias name, check is alias of (declared) signal
7988 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7989 (member (downcase (match-string 2)) signal-list))
7990 (setq signal-list
7991 (cons (downcase (match-string 1)) signal-list))
7992 (goto-char (match-end 0))))))
7993 (goto-char beg)))
7994 signal-list)))
7996 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7997 ;; Generic/port clause fixing
7999 (defun vhdl-fix-clause ()
8000 "Fix closing parenthesis within generic/port clause."
8001 (interactive)
8002 (save-excursion
8003 (vhdl-prepare-search-2
8004 (let ((pos (point))
8005 beg end)
8006 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
8007 (error "ERROR: Not within a generic/port clause")
8008 ;; search for end of clause
8009 (goto-char (match-end 0))
8010 (setq beg (1- (point)))
8011 (vhdl-forward-syntactic-ws)
8012 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
8013 (goto-char (1- (match-end 0)))
8014 (setq end (point-marker))
8015 (forward-char)
8016 (vhdl-forward-syntactic-ws))
8017 (goto-char end)
8018 (when (> pos (save-excursion (end-of-line) (point)))
8019 (error "ERROR: Not within a generic/port clause"))
8020 ;; delete closing parenthesis on separate line (not supported style)
8021 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8022 (vhdl-line-kill)
8023 (vhdl-backward-syntactic-ws)
8024 (setq end (point-marker))
8025 (insert ";"))
8026 ;; delete superfluous parentheses
8027 (while (progn (goto-char beg)
8028 (condition-case () (forward-sexp)
8029 (error (goto-char (point-max))))
8030 (< (point) end))
8031 (delete-backward-char 1))
8032 ;; add closing parenthesis
8033 (when (> (point) end)
8034 (goto-char end)
8035 (insert ")")))))))
8037 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8038 ;; Miscellaneous
8040 (defun vhdl-remove-trailing-spaces ()
8041 "Remove trailing spaces in the whole buffer."
8042 (interactive)
8043 (save-match-data
8044 (save-excursion
8045 (goto-char (point-min))
8046 (while (re-search-forward "[ \t]+$" (point-max) t)
8047 (unless (vhdl-in-literal)
8048 (replace-match "" nil nil))))))
8051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8052 ;;; Electrification
8053 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8055 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8056 "Syntax of prompt inserted by template generators.")
8058 (defvar vhdl-template-invoked-by-hook nil
8059 "Indicates whether a template has been invoked by a hook or by key or menu.
8060 Used for undoing after template abortion.")
8062 ;; correct different behavior of function `unread-command-events' in XEmacs
8063 (defun vhdl-character-to-event (arg))
8064 (defalias 'vhdl-character-to-event
8065 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8067 (defun vhdl-work-library ()
8068 "Return the working library name of the current project or \"work\" if no
8069 project is defined."
8070 (vhdl-resolve-env-variable
8071 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8073 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8074 ;; Enabling/disabling
8076 (defun vhdl-mode-line-update ()
8077 "Update the modeline string for VHDL major mode."
8078 (setq mode-name (concat "VHDL"
8079 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
8080 (and vhdl-electric-mode "e")
8081 (and vhdl-stutter-mode "s")))
8082 (force-mode-line-update t))
8084 (defun vhdl-electric-mode (arg)
8085 "Toggle VHDL electric mode.
8086 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8087 (interactive "P")
8088 (setq vhdl-electric-mode
8089 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
8090 ((> arg 0) t) (t nil)))
8091 (vhdl-mode-line-update))
8093 (defun vhdl-stutter-mode (arg)
8094 "Toggle VHDL stuttering mode.
8095 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8096 (interactive "P")
8097 (setq vhdl-stutter-mode
8098 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
8099 ((> arg 0) t) (t nil)))
8100 (vhdl-mode-line-update))
8102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8103 ;; Stuttering
8105 (defun vhdl-electric-dash (count)
8106 "-- starts a comment, --- draws a horizontal line,
8107 ---- starts a display comment."
8108 (interactive "p")
8109 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8110 (cond
8111 ((and abbrev-start-location (= abbrev-start-location (point)))
8112 (setq abbrev-start-location nil)
8113 (goto-char last-abbrev-location)
8114 (beginning-of-line nil)
8115 (vhdl-comment-display))
8116 ((/= (preceding-char) ?-) ; standard dash (minus)
8117 (self-insert-command count))
8118 (t (self-insert-command count)
8119 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8120 (let ((next-input (read-char)))
8121 (if (= next-input ?-) ; triple dash
8122 (progn
8123 (vhdl-comment-display-line)
8124 (message
8125 "Enter '-' for display comment, else continue coding")
8126 (let ((next-input (read-char)))
8127 (if (= next-input ?-) ; four dashes
8128 (vhdl-comment-display t)
8129 (setq unread-command-events ; pushback the char
8130 (list (vhdl-character-to-event next-input))))))
8131 (setq unread-command-events ; pushback the char
8132 (list (vhdl-character-to-event next-input)))
8133 (vhdl-comment-insert)))))
8134 (self-insert-command count)))
8136 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8137 (interactive "p")
8138 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8139 (if (= (preceding-char) ?\()
8140 (progn (delete-char -1) (insert-char ?\[ 1))
8141 (insert-char ?\( 1))
8142 (self-insert-command count)))
8144 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8145 (interactive "p")
8146 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8147 (progn
8148 (if (= (preceding-char) ?\))
8149 (progn (delete-char -1) (insert-char ?\] 1))
8150 (insert-char ?\) 1))
8151 (blink-matching-open))
8152 (self-insert-command count)))
8154 (defun vhdl-electric-quote (count) "'' --> \""
8155 (interactive "p")
8156 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8157 (if (= (preceding-char) last-input-char)
8158 (progn (delete-backward-char 1) (insert-char ?\" 1))
8159 (insert-char ?\' 1))
8160 (self-insert-command count)))
8162 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8163 (interactive "p")
8164 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8165 (cond ((= (preceding-char) last-input-char)
8166 (progn (delete-char -1)
8167 (unless (eq (preceding-char) ? ) (insert " "))
8168 (insert ": ")
8169 (setq this-command 'vhdl-electric-colon)))
8170 ((and
8171 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8172 (progn (delete-char -1) (insert "= ")))
8173 (t (insert-char ?\; 1)))
8174 (self-insert-command count)))
8176 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8177 (interactive "p")
8178 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8179 (cond ((= (preceding-char) last-input-char)
8180 (progn (delete-char -1)
8181 (unless (eq (preceding-char) ? ) (insert " "))
8182 (insert "<= ")))
8183 (t (insert-char ?\, 1)))
8184 (self-insert-command count)))
8186 (defun vhdl-electric-period (count) "'..' --> ' => '"
8187 (interactive "p")
8188 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8189 (cond ((= (preceding-char) last-input-char)
8190 (progn (delete-char -1)
8191 (unless (eq (preceding-char) ? ) (insert " "))
8192 (insert "=> ")))
8193 (t (insert-char ?\. 1)))
8194 (self-insert-command count)))
8196 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8197 (interactive "p")
8198 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8199 (cond ((= (preceding-char) last-input-char)
8200 (progn (delete-char -1)
8201 (unless (eq (preceding-char) ? ) (insert " "))
8202 (insert "== ")))
8203 (t (insert-char ?\= 1)))
8204 (self-insert-command count)))
8206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8207 ;; VHDL templates
8209 (defun vhdl-template-paired-parens ()
8210 "Insert a pair of round parentheses, placing point between them."
8211 (interactive)
8212 (insert "()")
8213 (backward-char))
8215 (defun vhdl-template-alias ()
8216 "Insert alias declaration."
8217 (interactive)
8218 (let ((start (point)))
8219 (vhdl-insert-keyword "ALIAS ")
8220 (when (vhdl-template-field "name" nil t start (point))
8221 (insert " : ")
8222 (unless (vhdl-template-field
8223 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8224 nil t)
8225 (delete-backward-char 3))
8226 (vhdl-insert-keyword " IS ")
8227 (vhdl-template-field "name" ";")
8228 (vhdl-comment-insert-inline))))
8230 (defun vhdl-template-architecture ()
8231 "Insert architecture."
8232 (interactive)
8233 (let ((margin (current-indentation))
8234 (start (point))
8235 arch-name)
8236 (vhdl-insert-keyword "ARCHITECTURE ")
8237 (when (setq arch-name
8238 (vhdl-template-field "name" nil t start (point)))
8239 (vhdl-insert-keyword " OF ")
8240 (if (save-excursion
8241 (vhdl-prepare-search-1
8242 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8243 (insert (match-string 1))
8244 (vhdl-template-field "entity name"))
8245 (vhdl-insert-keyword " IS\n")
8246 (vhdl-template-begin-end
8247 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8248 (memq vhdl-insert-empty-lines '(unit all))))))
8250 (defun vhdl-template-array (kind &optional secondary)
8251 "Insert array type definition."
8252 (interactive)
8253 (let ((start (point)))
8254 (vhdl-insert-keyword "ARRAY (")
8255 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8256 secondary)
8257 (vhdl-insert-keyword ") OF ")
8258 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8259 (vhdl-insert-keyword ";"))))
8261 (defun vhdl-template-assert ()
8262 "Insert an assertion statement."
8263 (interactive)
8264 (let ((start (point)))
8265 (vhdl-insert-keyword "ASSERT ")
8266 (when vhdl-conditions-in-parenthesis (insert "("))
8267 (when (vhdl-template-field "condition (negated)" nil t start (point))
8268 (when vhdl-conditions-in-parenthesis (insert ")"))
8269 (setq start (point))
8270 (vhdl-insert-keyword " REPORT ")
8271 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8272 (delete-region start (point)))
8273 (setq start (point))
8274 (vhdl-insert-keyword " SEVERITY ")
8275 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8276 (delete-region start (point)))
8277 (insert ";"))))
8279 (defun vhdl-template-attribute ()
8280 "Insert an attribute declaration or specification."
8281 (interactive)
8282 (if (eq (vhdl-decision-query
8283 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8284 (vhdl-template-attribute-spec)
8285 (vhdl-template-attribute-decl)))
8287 (defun vhdl-template-attribute-decl ()
8288 "Insert an attribute declaration."
8289 (interactive)
8290 (let ((start (point)))
8291 (vhdl-insert-keyword "ATTRIBUTE ")
8292 (when (vhdl-template-field "name" " : " t start (point))
8293 (vhdl-template-field "type" ";")
8294 (vhdl-comment-insert-inline))))
8296 (defun vhdl-template-attribute-spec ()
8297 "Insert an attribute specification."
8298 (interactive)
8299 (let ((start (point)))
8300 (vhdl-insert-keyword "ATTRIBUTE ")
8301 (when (vhdl-template-field "name" nil t start (point))
8302 (vhdl-insert-keyword " OF ")
8303 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8304 (vhdl-template-field "entity class")
8305 (vhdl-insert-keyword " IS ")
8306 (vhdl-template-field "expression" ";"))))
8308 (defun vhdl-template-block ()
8309 "Insert a block."
8310 (interactive)
8311 (let ((margin (current-indentation))
8312 (start (point))
8313 label)
8314 (vhdl-insert-keyword ": BLOCK ")
8315 (goto-char start)
8316 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8317 (forward-word 1)
8318 (forward-char 1)
8319 (insert "(")
8320 (if (vhdl-template-field "[guard expression]" nil t)
8321 (insert ")")
8322 (delete-char -2))
8323 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8324 (insert "\n")
8325 (vhdl-template-begin-end "BLOCK" label margin)
8326 (vhdl-comment-block))))
8328 (defun vhdl-template-block-configuration ()
8329 "Insert a block configuration statement."
8330 (interactive)
8331 (let ((margin (current-indentation))
8332 (start (point)))
8333 (vhdl-insert-keyword "FOR ")
8334 (when (vhdl-template-field "block name" nil t start (point))
8335 (vhdl-insert-keyword "\n\n")
8336 (indent-to margin)
8337 (vhdl-insert-keyword "END FOR;")
8338 (end-of-line 0)
8339 (indent-to (+ margin vhdl-basic-offset)))))
8341 (defun vhdl-template-break ()
8342 "Insert a break statement."
8343 (interactive)
8344 (let (position)
8345 (vhdl-insert-keyword "BREAK")
8346 (setq position (point))
8347 (insert " ")
8348 (while (or
8349 (progn (vhdl-insert-keyword "FOR ")
8350 (if (vhdl-template-field "[quantity name]" " USE " t)
8351 (progn (vhdl-template-field "quantity name" " => ") t)
8352 (delete-region (point)
8353 (progn (forward-word -1) (point)))
8354 nil))
8355 (vhdl-template-field "[quantity name]" " => " t))
8356 (vhdl-template-field "expression")
8357 (setq position (point))
8358 (insert ", "))
8359 (delete-region position (point))
8360 (unless (vhdl-sequential-statement-p)
8361 (vhdl-insert-keyword " ON ")
8362 (if (vhdl-template-field "[sensitivity list]" nil t)
8363 (setq position (point))
8364 (delete-region position (point))))
8365 (vhdl-insert-keyword " WHEN ")
8366 (when vhdl-conditions-in-parenthesis (insert "("))
8367 (if (vhdl-template-field "[condition]" nil t)
8368 (when vhdl-conditions-in-parenthesis (insert ")"))
8369 (delete-region position (point)))
8370 (insert ";")))
8372 (defun vhdl-template-case (&optional kind)
8373 "Insert a case statement."
8374 (interactive)
8375 (let ((margin (current-indentation))
8376 (start (point))
8377 label)
8378 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8379 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8380 (vhdl-insert-keyword "CASE ")
8381 (vhdl-insert-keyword ": CASE ")
8382 (goto-char start)
8383 (setq label (vhdl-template-field "[label]" nil t))
8384 (unless label (delete-char 2))
8385 (forward-word 1)
8386 (forward-char 1))
8387 (when (vhdl-template-field "expression" nil t start (point))
8388 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8389 (indent-to margin)
8390 (vhdl-insert-keyword "END CASE")
8391 (when label (insert " " label))
8392 (insert ";")
8393 (forward-line -1)
8394 (indent-to (+ margin vhdl-basic-offset))
8395 (vhdl-insert-keyword "WHEN ")
8396 (let ((position (point)))
8397 (insert " => ;\n")
8398 (indent-to (+ margin vhdl-basic-offset))
8399 (vhdl-insert-keyword "WHEN OTHERS => null;")
8400 (goto-char position)))))
8402 (defun vhdl-template-case-is ()
8403 "Insert a sequential case statement."
8404 (interactive)
8405 (vhdl-template-case 'is))
8407 (defun vhdl-template-case-use ()
8408 "Insert a simultaneous case statement."
8409 (interactive)
8410 (vhdl-template-case 'use))
8412 (defun vhdl-template-component ()
8413 "Insert a component declaration."
8414 (interactive)
8415 (vhdl-template-component-decl))
8417 (defun vhdl-template-component-conf ()
8418 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8419 since these are almost equivalent)."
8420 (interactive)
8421 (let ((margin (current-indentation))
8422 (result (vhdl-template-configuration-spec t)))
8423 (when result
8424 (insert "\n")
8425 (indent-to margin)
8426 (vhdl-insert-keyword "END FOR;")
8427 (when (eq result 'no-use)
8428 (end-of-line -0)))))
8430 (defun vhdl-template-component-decl ()
8431 "Insert a component declaration."
8432 (interactive)
8433 (let ((margin (current-indentation))
8434 (start (point))
8435 name end-column)
8436 (vhdl-insert-keyword "COMPONENT ")
8437 (when (setq name (vhdl-template-field "name" nil t start (point)))
8438 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8439 (insert "\n\n")
8440 (indent-to margin)
8441 (vhdl-insert-keyword "END COMPONENT")
8442 (unless (vhdl-standard-p '87) (insert " " name))
8443 (insert ";")
8444 (setq end-column (current-column))
8445 (end-of-line -0)
8446 (indent-to (+ margin vhdl-basic-offset))
8447 (vhdl-template-generic-list t t)
8448 (insert "\n")
8449 (indent-to (+ margin vhdl-basic-offset))
8450 (vhdl-template-port-list t)
8451 (beginning-of-line 2)
8452 (forward-char end-column))))
8454 (defun vhdl-template-component-inst ()
8455 "Insert a component instantiation statement."
8456 (interactive)
8457 (let ((margin (current-indentation))
8458 (start (point))
8459 unit position)
8460 (when (vhdl-template-field "instance label" nil t start (point))
8461 (insert ": ")
8462 (if (not (vhdl-use-direct-instantiation))
8463 (vhdl-template-field "component name")
8464 ;; direct instantiation
8465 (setq unit (vhdl-template-field
8466 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8467 (setq unit (upcase (or unit "")))
8468 (cond ((equal unit "ENTITY")
8469 (vhdl-template-field "library name" "." nil nil nil nil
8470 (vhdl-work-library))
8471 (vhdl-template-field "entity name" "(")
8472 (if (vhdl-template-field "[architecture name]" nil t)
8473 (insert ")")
8474 (delete-char -1)))
8475 ((equal unit "CONFIGURATION")
8476 (vhdl-template-field "library name" "." nil nil nil nil
8477 (vhdl-work-library))
8478 (vhdl-template-field "configuration name"))
8479 (t (vhdl-template-field "component name"))))
8480 (insert "\n")
8481 (indent-to (+ margin vhdl-basic-offset))
8482 (setq position (point))
8483 (vhdl-insert-keyword "GENERIC ")
8484 (when (vhdl-template-map position t t)
8485 (insert "\n")
8486 (indent-to (+ margin vhdl-basic-offset)))
8487 (setq position (point))
8488 (vhdl-insert-keyword "PORT ")
8489 (unless (vhdl-template-map position t t)
8490 (delete-region (line-beginning-position) (point))
8491 (delete-char -1))
8492 (insert ";"))))
8494 (defun vhdl-template-conditional-signal-asst ()
8495 "Insert a conditional signal assignment."
8496 (interactive)
8497 (when (vhdl-template-field "target signal")
8498 (insert " <= ")
8499 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8500 ; (insert " "))
8501 (let ((margin (current-column))
8502 (start (point))
8503 position)
8504 (vhdl-template-field "waveform")
8505 (setq position (point))
8506 (vhdl-insert-keyword " WHEN ")
8507 (when vhdl-conditions-in-parenthesis (insert "("))
8508 (while (and (vhdl-template-field "[condition]" nil t)
8509 (progn
8510 (when vhdl-conditions-in-parenthesis (insert ")"))
8511 (setq position (point))
8512 (vhdl-insert-keyword " ELSE")
8513 (insert "\n")
8514 (indent-to margin)
8515 (vhdl-template-field "[waveform]" nil t)))
8516 (setq position (point))
8517 (vhdl-insert-keyword " WHEN ")
8518 (when vhdl-conditions-in-parenthesis (insert "(")))
8519 (delete-region position (point))
8520 (insert ";")
8521 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8523 (defun vhdl-template-configuration ()
8524 "Insert a configuration specification if within an architecture,
8525 a block or component configuration if within a configuration declaration,
8526 a configuration declaration if not within a design unit."
8527 (interactive)
8528 (vhdl-prepare-search-1
8529 (cond
8530 ((and (save-excursion ; architecture body
8531 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8532 (equal "ARCHITECTURE" (upcase (match-string 1))))
8533 (vhdl-template-configuration-spec))
8534 ((and (save-excursion ; configuration declaration
8535 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8536 (equal "CONFIGURATION" (upcase (match-string 1))))
8537 (if (eq (vhdl-decision-query
8538 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8539 (vhdl-template-component-conf)
8540 (vhdl-template-block-configuration)))
8541 (t (vhdl-template-configuration-decl))))) ; otherwise
8543 (defun vhdl-template-configuration-spec (&optional optional-use)
8544 "Insert a configuration specification."
8545 (interactive)
8546 (let ((margin (current-indentation))
8547 (start (point))
8548 aspect position)
8549 (vhdl-insert-keyword "FOR ")
8550 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8551 t start (point))
8552 (vhdl-template-field "component name" "\n")
8553 (indent-to (+ margin vhdl-basic-offset))
8554 (setq start (point))
8555 (vhdl-insert-keyword "USE ")
8556 (if (and optional-use
8557 (not (setq aspect (vhdl-template-field
8558 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8559 (progn (delete-region start (point)) 'no-use)
8560 (unless optional-use
8561 (setq aspect (vhdl-template-field
8562 "ENTITY | CONFIGURATION | OPEN" " ")))
8563 (setq aspect (upcase (or aspect "")))
8564 (cond ((equal aspect "ENTITY")
8565 (vhdl-template-field "library name" "." nil nil nil nil
8566 (vhdl-work-library))
8567 (vhdl-template-field "entity name" "(")
8568 (if (vhdl-template-field "[architecture name]" nil t)
8569 (insert ")")
8570 (delete-char -1))
8571 (insert "\n")
8572 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8573 (setq position (point))
8574 (vhdl-insert-keyword "GENERIC ")
8575 (when (vhdl-template-map position t t)
8576 (insert "\n")
8577 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8578 (setq position (point))
8579 (vhdl-insert-keyword "PORT ")
8580 (unless (vhdl-template-map position t t)
8581 (delete-region (line-beginning-position) (point))
8582 (delete-char -1))
8583 (insert ";")
8585 ((equal aspect "CONFIGURATION")
8586 (vhdl-template-field "library name" "." nil nil nil nil
8587 (vhdl-work-library))
8588 (vhdl-template-field "configuration name" ";"))
8589 (t (delete-backward-char 1) (insert ";") t))))))
8592 (defun vhdl-template-configuration-decl ()
8593 "Insert a configuration declaration."
8594 (interactive)
8595 (let ((margin (current-indentation))
8596 (start (point))
8597 entity-exists string name position)
8598 (vhdl-insert-keyword "CONFIGURATION ")
8599 (when (setq name (vhdl-template-field "name" nil t start (point)))
8600 (vhdl-insert-keyword " OF ")
8601 (save-excursion
8602 (vhdl-prepare-search-1
8603 (setq entity-exists (vhdl-re-search-backward
8604 "\\<entity \\(\\w*\\) is\\>" nil t))
8605 (setq string (match-string 1))))
8606 (if (and entity-exists (not (equal string "")))
8607 (insert string)
8608 (vhdl-template-field "entity name"))
8609 (vhdl-insert-keyword " IS\n")
8610 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8611 (indent-to (+ margin vhdl-basic-offset))
8612 (setq position (point))
8613 (insert "\n")
8614 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8615 (indent-to margin)
8616 (vhdl-insert-keyword "END ")
8617 (unless (vhdl-standard-p '87)
8618 (vhdl-insert-keyword "CONFIGURATION "))
8619 (insert name ";")
8620 (goto-char position))))
8622 (defun vhdl-template-constant ()
8623 "Insert a constant declaration."
8624 (interactive)
8625 (let ((start (point))
8626 (in-arglist (vhdl-in-argument-list-p)))
8627 (vhdl-insert-keyword "CONSTANT ")
8628 (when (vhdl-template-field "name" nil t start (point))
8629 (insert " : ")
8630 (when in-arglist (vhdl-insert-keyword "IN "))
8631 (vhdl-template-field "type")
8632 (if in-arglist
8633 (progn (insert ";")
8634 (vhdl-comment-insert-inline))
8635 (let ((position (point)))
8636 (insert " := ")
8637 (unless (vhdl-template-field "[initialization]" nil t)
8638 (delete-region position (point)))
8639 (insert ";")
8640 (vhdl-comment-insert-inline))))))
8642 (defun vhdl-template-default ()
8643 "Insert nothing."
8644 (interactive)
8645 (insert " ")
8646 (unexpand-abbrev)
8647 (backward-word 1)
8648 (vhdl-case-word 1)
8649 (forward-char 1))
8651 (defun vhdl-template-default-indent ()
8652 "Insert nothing and indent."
8653 (interactive)
8654 (insert " ")
8655 (unexpand-abbrev)
8656 (backward-word 1)
8657 (vhdl-case-word 1)
8658 (forward-char 1)
8659 (indent-according-to-mode))
8661 (defun vhdl-template-disconnect ()
8662 "Insert a disconnect statement."
8663 (interactive)
8664 (let ((start (point)))
8665 (vhdl-insert-keyword "DISCONNECT ")
8666 (when (vhdl-template-field "signal names | OTHERS | ALL"
8667 " : " t start (point))
8668 (vhdl-template-field "type")
8669 (vhdl-insert-keyword " AFTER ")
8670 (vhdl-template-field "time expression" ";"))))
8672 (defun vhdl-template-else ()
8673 "Insert an else statement."
8674 (interactive)
8675 (let (margin)
8676 (vhdl-prepare-search-1
8677 (vhdl-insert-keyword "ELSE")
8678 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8679 (equal "WHEN" (upcase (match-string 1))))
8680 (insert " ")
8681 (indent-according-to-mode)
8682 (setq margin (current-indentation))
8683 (insert "\n")
8684 (indent-to (+ margin vhdl-basic-offset))))))
8686 (defun vhdl-template-elsif ()
8687 "Insert an elsif statement."
8688 (interactive)
8689 (let ((start (point))
8690 margin)
8691 (vhdl-insert-keyword "ELSIF ")
8692 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8693 (when vhdl-conditions-in-parenthesis (insert "("))
8694 (when (vhdl-template-field "condition" nil t start (point))
8695 (when vhdl-conditions-in-parenthesis (insert ")"))
8696 (indent-according-to-mode)
8697 (setq margin (current-indentation))
8698 (vhdl-insert-keyword
8699 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8700 (indent-to (+ margin vhdl-basic-offset))))))
8702 (defun vhdl-template-entity ()
8703 "Insert an entity."
8704 (interactive)
8705 (let ((margin (current-indentation))
8706 (start (point))
8707 name end-column)
8708 (vhdl-insert-keyword "ENTITY ")
8709 (when (setq name (vhdl-template-field "name" nil t start (point)))
8710 (vhdl-insert-keyword " IS\n\n")
8711 (indent-to margin)
8712 (vhdl-insert-keyword "END ")
8713 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8714 (insert name ";")
8715 (setq end-column (current-column))
8716 (end-of-line -0)
8717 (indent-to (+ margin vhdl-basic-offset))
8718 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8719 (indent-to (+ margin vhdl-basic-offset))
8720 (when (vhdl-template-generic-list t)
8721 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8722 (insert "\n")
8723 (indent-to (+ margin vhdl-basic-offset))
8724 (when (vhdl-template-port-list t)
8725 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8726 (beginning-of-line 2)
8727 (forward-char end-column))))
8729 (defun vhdl-template-exit ()
8730 "Insert an exit statement."
8731 (interactive)
8732 (let ((start (point)))
8733 (vhdl-insert-keyword "EXIT ")
8734 (if (vhdl-template-field "[loop label]" nil t start (point))
8735 (let ((position (point)))
8736 (vhdl-insert-keyword " WHEN ")
8737 (when vhdl-conditions-in-parenthesis (insert "("))
8738 (if (vhdl-template-field "[condition]" nil t)
8739 (when vhdl-conditions-in-parenthesis (insert ")"))
8740 (delete-region position (point))))
8741 (delete-char -1))
8742 (insert ";")))
8744 (defun vhdl-template-file ()
8745 "Insert a file declaration."
8746 (interactive)
8747 (let ((start (point)))
8748 (vhdl-insert-keyword "FILE ")
8749 (when (vhdl-template-field "name" nil t start (point))
8750 (insert " : ")
8751 (vhdl-template-field "type")
8752 (unless (vhdl-standard-p '87)
8753 (vhdl-insert-keyword " OPEN ")
8754 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8755 nil t)
8756 (delete-backward-char 6)))
8757 (vhdl-insert-keyword " IS ")
8758 (when (vhdl-standard-p '87)
8759 (vhdl-template-field "[IN | OUT]" " " t))
8760 (vhdl-template-field "filename-string" nil nil nil nil t)
8761 (insert ";")
8762 (vhdl-comment-insert-inline))))
8764 (defun vhdl-template-for ()
8765 "Insert a block or component configuration if within a configuration
8766 declaration, a configuration specification if within an architecture
8767 declarative part (and not within a subprogram), a for-loop if within a
8768 sequential statement part (subprogram or process), and a for-generate
8769 otherwise."
8770 (interactive)
8771 (vhdl-prepare-search-1
8772 (cond
8773 ((vhdl-sequential-statement-p) ; sequential statement
8774 (vhdl-template-for-loop))
8775 ((and (save-excursion ; configuration declaration
8776 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8777 (equal "CONFIGURATION" (upcase (match-string 1))))
8778 (if (eq (vhdl-decision-query
8779 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8780 (vhdl-template-component-conf)
8781 (vhdl-template-block-configuration)))
8782 ((and (save-excursion
8783 (re-search-backward ; architecture declarative part
8784 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8785 (equal "ARCHITECTURE" (upcase (match-string 1))))
8786 (vhdl-template-configuration-spec))
8787 (t (vhdl-template-for-generate))))) ; concurrent statement
8789 (defun vhdl-template-for-generate ()
8790 "Insert a for-generate."
8791 (interactive)
8792 (let ((margin (current-indentation))
8793 (start (point))
8794 label position)
8795 (vhdl-insert-keyword ": FOR ")
8796 (setq position (point-marker))
8797 (goto-char start)
8798 (when (setq label (vhdl-template-field "label" nil t start position))
8799 (goto-char position)
8800 (vhdl-template-field "loop variable")
8801 (vhdl-insert-keyword " IN ")
8802 (vhdl-template-field "range")
8803 (vhdl-template-generate-body margin label))))
8805 (defun vhdl-template-for-loop ()
8806 "Insert a for loop."
8807 (interactive)
8808 (let ((margin (current-indentation))
8809 (start (point))
8810 label index)
8811 (if (not (eq vhdl-optional-labels 'all))
8812 (vhdl-insert-keyword "FOR ")
8813 (vhdl-insert-keyword ": FOR ")
8814 (goto-char start)
8815 (setq label (vhdl-template-field "[label]" nil t))
8816 (unless label (delete-char 2))
8817 (forward-word 1)
8818 (forward-char 1))
8819 (when (setq index (vhdl-template-field "loop variable"
8820 nil t start (point)))
8821 (vhdl-insert-keyword " IN ")
8822 (vhdl-template-field "range")
8823 (vhdl-insert-keyword " LOOP\n\n")
8824 (indent-to margin)
8825 (vhdl-insert-keyword "END LOOP")
8826 (if label
8827 (insert " " label ";")
8828 (insert ";")
8829 (when vhdl-self-insert-comments (insert " -- " index)))
8830 (forward-line -1)
8831 (indent-to (+ margin vhdl-basic-offset)))))
8833 (defun vhdl-template-function (&optional kind)
8834 "Insert a function declaration or body."
8835 (interactive)
8836 (let ((margin (current-indentation))
8837 (start (point))
8838 name)
8839 (vhdl-insert-keyword "FUNCTION ")
8840 (when (setq name (vhdl-template-field "name" nil t start (point)))
8841 (vhdl-template-argument-list t)
8842 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8843 (end-of-line)
8844 (insert "\n")
8845 (indent-to (+ margin vhdl-basic-offset))
8846 (vhdl-insert-keyword "RETURN ")
8847 (vhdl-template-field "type")
8848 (if (if kind (eq kind 'body)
8849 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8850 (progn (vhdl-insert-keyword " IS\n")
8851 (vhdl-template-begin-end
8852 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8853 (vhdl-comment-block))
8854 (insert ";")))))
8856 (defun vhdl-template-function-decl ()
8857 "Insert a function declaration."
8858 (interactive)
8859 (vhdl-template-function 'decl))
8861 (defun vhdl-template-function-body ()
8862 "Insert a function declaration."
8863 (interactive)
8864 (vhdl-template-function 'body))
8866 (defun vhdl-template-generate ()
8867 "Insert a generation scheme."
8868 (interactive)
8869 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8870 (vhdl-template-if-generate)
8871 (vhdl-template-for-generate)))
8873 (defun vhdl-template-generic ()
8874 "Insert generic declaration, or generic map in instantiation statements."
8875 (interactive)
8876 (let ((start (point)))
8877 (vhdl-prepare-search-1
8878 (cond
8879 ((and (save-excursion ; entity declaration
8880 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8881 (equal "ENTITY" (upcase (match-string 1))))
8882 (vhdl-template-generic-list nil))
8883 ((or (save-excursion
8884 (or (beginning-of-line)
8885 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8886 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8887 (vhdl-insert-keyword "GENERIC ")
8888 (vhdl-template-map start))
8889 (t (vhdl-template-generic-list nil t))))))
8891 (defun vhdl-template-group ()
8892 "Insert group or group template declaration."
8893 (interactive)
8894 (let ((start (point)))
8895 (if (eq (vhdl-decision-query
8896 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8897 (vhdl-template-group-template)
8898 (vhdl-template-group-decl))))
8900 (defun vhdl-template-group-decl ()
8901 "Insert group declaration."
8902 (interactive)
8903 (let ((start (point)))
8904 (vhdl-insert-keyword "GROUP ")
8905 (when (vhdl-template-field "name" " : " t start (point))
8906 (vhdl-template-field "template name" " (")
8907 (vhdl-template-field "constituent list" ");")
8908 (vhdl-comment-insert-inline))))
8910 (defun vhdl-template-group-template ()
8911 "Insert group template declaration."
8912 (interactive)
8913 (let ((start (point)))
8914 (vhdl-insert-keyword "GROUP ")
8915 (when (vhdl-template-field "template name" nil t start (point))
8916 (vhdl-insert-keyword " IS (")
8917 (vhdl-template-field "entity class list" ");")
8918 (vhdl-comment-insert-inline))))
8920 (defun vhdl-template-if ()
8921 "Insert a sequential if statement or an if-generate statement."
8922 (interactive)
8923 (if (vhdl-sequential-statement-p)
8924 (vhdl-template-if-then)
8925 (if (and (vhdl-standard-p 'ams)
8926 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8927 (vhdl-template-if-use)
8928 (vhdl-template-if-generate))))
8930 (defun vhdl-template-if-generate ()
8931 "Insert an if-generate."
8932 (interactive)
8933 (let ((margin (current-indentation))
8934 (start (point))
8935 label position)
8936 (vhdl-insert-keyword ": IF ")
8937 (setq position (point-marker))
8938 (goto-char start)
8939 (when (setq label (vhdl-template-field "label" nil t start position))
8940 (goto-char position)
8941 (when vhdl-conditions-in-parenthesis (insert "("))
8942 (vhdl-template-field "condition")
8943 (when vhdl-conditions-in-parenthesis (insert ")"))
8944 (vhdl-template-generate-body margin label))))
8946 (defun vhdl-template-if-then-use (kind)
8947 "Insert a sequential if statement."
8948 (interactive)
8949 (let ((margin (current-indentation))
8950 (start (point))
8951 label)
8952 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8953 (vhdl-insert-keyword "IF ")
8954 (vhdl-insert-keyword ": IF ")
8955 (goto-char start)
8956 (setq label (vhdl-template-field "[label]" nil t))
8957 (unless label (delete-char 2))
8958 (forward-word 1)
8959 (forward-char 1))
8960 (when vhdl-conditions-in-parenthesis (insert "("))
8961 (when (vhdl-template-field "condition" nil t start (point))
8962 (when vhdl-conditions-in-parenthesis (insert ")"))
8963 (vhdl-insert-keyword
8964 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8965 (indent-to margin)
8966 (vhdl-insert-keyword "END IF")
8967 (when label (insert " " label))
8968 (insert ";")
8969 (forward-line -1)
8970 (indent-to (+ margin vhdl-basic-offset)))))
8972 (defun vhdl-template-if-then ()
8973 "Insert a sequential if statement."
8974 (interactive)
8975 (vhdl-template-if-then-use 'then))
8977 (defun vhdl-template-if-use ()
8978 "Insert a simultaneous if statement."
8979 (interactive)
8980 (vhdl-template-if-then-use 'use))
8982 (defun vhdl-template-instance ()
8983 "Insert a component instantiation statement."
8984 (interactive)
8985 (vhdl-template-component-inst))
8987 (defun vhdl-template-library ()
8988 "Insert a library specification."
8989 (interactive)
8990 (let ((margin (current-indentation))
8991 (start (point))
8992 name end-pos)
8993 (vhdl-insert-keyword "LIBRARY ")
8994 (when (setq name (vhdl-template-field "names" nil t start (point)))
8995 (insert ";")
8996 (unless (string-match "," name)
8997 (setq end-pos (point))
8998 (insert "\n")
8999 (indent-to margin)
9000 (vhdl-insert-keyword "USE ")
9001 (insert name)
9002 (vhdl-insert-keyword "..ALL;")
9003 (backward-char 5)
9004 (if (vhdl-template-field "package name")
9005 (forward-char 5)
9006 (delete-region end-pos (+ (point) 5)))))))
9008 (defun vhdl-template-limit ()
9009 "Insert a limit."
9010 (interactive)
9011 (let ((start (point)))
9012 (vhdl-insert-keyword "LIMIT ")
9013 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9014 t start (point))
9015 (vhdl-template-field "type")
9016 (vhdl-insert-keyword " WITH ")
9017 (vhdl-template-field "real expression" ";"))))
9019 (defun vhdl-template-loop ()
9020 "Insert a loop."
9021 (interactive)
9022 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9023 (cond ((eq char ?w)
9024 (vhdl-template-while-loop))
9025 ((eq char ?f)
9026 (vhdl-template-for-loop))
9027 (t (vhdl-template-bare-loop)))))
9029 (defun vhdl-template-bare-loop ()
9030 "Insert a loop."
9031 (interactive)
9032 (let ((margin (current-indentation))
9033 (start (point))
9034 label)
9035 (if (not (eq vhdl-optional-labels 'all))
9036 (vhdl-insert-keyword "LOOP ")
9037 (vhdl-insert-keyword ": LOOP ")
9038 (goto-char start)
9039 (setq label (vhdl-template-field "[label]" nil t))
9040 (unless label (delete-char 2))
9041 (forward-word 1)
9042 (delete-char 1))
9043 (insert "\n\n")
9044 (indent-to margin)
9045 (vhdl-insert-keyword "END LOOP")
9046 (insert (if label (concat " " label ";") ";"))
9047 (forward-line -1)
9048 (indent-to (+ margin vhdl-basic-offset))))
9050 (defun vhdl-template-map (&optional start optional secondary)
9051 "Insert a map specification with association list."
9052 (interactive)
9053 (let ((start (or start (point)))
9054 margin end-pos)
9055 (vhdl-insert-keyword "MAP (")
9056 (if (not vhdl-association-list-with-formals)
9057 (if (vhdl-template-field
9058 (concat (and optional "[") "association list" (and optional "]"))
9059 ")" (or (not secondary) optional)
9060 (and (not secondary) start) (point))
9062 (if (and optional secondary) (delete-region start (point)))
9063 nil)
9064 (if vhdl-argument-list-indent
9065 (setq margin (current-column))
9066 (setq margin (+ (current-indentation) vhdl-basic-offset))
9067 (insert "\n")
9068 (indent-to margin))
9069 (if (vhdl-template-field
9070 (concat (and optional "[") "formal" (and optional "]"))
9071 " => " (or (not secondary) optional)
9072 (and (not secondary) start) (point))
9073 (progn
9074 (vhdl-template-field "actual" ",")
9075 (setq end-pos (point))
9076 (insert "\n")
9077 (indent-to margin)
9078 (while (vhdl-template-field "[formal]" " => " t)
9079 (vhdl-template-field "actual" ",")
9080 (setq end-pos (point))
9081 (insert "\n")
9082 (indent-to margin))
9083 (delete-region end-pos (point))
9084 (delete-backward-char 1)
9085 (insert ")")
9086 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9088 (when (and optional secondary) (delete-region start (point)))
9089 nil))))
9091 (defun vhdl-template-modify (&optional noerror)
9092 "Actualize modification date."
9093 (interactive)
9094 (vhdl-prepare-search-2
9095 (save-excursion
9096 (goto-char (point-min))
9097 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9098 (progn (delete-region (point) (progn (end-of-line) (point)))
9099 (vhdl-template-insert-date))
9100 (unless noerror
9101 (error (concat "ERROR: Modification date prefix string \""
9102 vhdl-modify-date-prefix-string "\" not found")))))))
9104 (defun vhdl-template-modify-noerror ()
9105 "Call `vhdl-template-modify' with NOERROR non-nil."
9106 (vhdl-template-modify t))
9108 (defun vhdl-template-nature ()
9109 "Insert a nature declaration."
9110 (interactive)
9111 (let ((start (point))
9112 name mid-pos end-pos)
9113 (vhdl-insert-keyword "NATURE ")
9114 (when (setq name (vhdl-template-field "name" nil t start (point)))
9115 (vhdl-insert-keyword " IS ")
9116 (let ((definition
9117 (upcase
9118 (or (vhdl-template-field
9119 "across type | ARRAY | RECORD")
9120 ""))))
9121 (cond ((equal definition "")
9122 (insert ";"))
9123 ((equal definition "ARRAY")
9124 (delete-region (point) (progn (forward-word -1) (point)))
9125 (vhdl-template-array 'nature t))
9126 ((equal definition "RECORD")
9127 (setq mid-pos (point-marker))
9128 (delete-region (point) (progn (forward-word -1) (point)))
9129 (vhdl-template-record 'nature name t))
9131 (vhdl-insert-keyword " ACROSS ")
9132 (vhdl-template-field "through type")
9133 (vhdl-insert-keyword " THROUGH ")
9134 (vhdl-template-field "reference name")
9135 (vhdl-insert-keyword " REFERENCE;")))
9136 (when mid-pos
9137 (setq end-pos (point-marker))
9138 (goto-char mid-pos)
9139 (end-of-line))
9140 (vhdl-comment-insert-inline)
9141 (when end-pos (goto-char end-pos))))))
9143 (defun vhdl-template-next ()
9144 "Insert a next statement."
9145 (interactive)
9146 (let ((start (point)))
9147 (vhdl-insert-keyword "NEXT ")
9148 (if (vhdl-template-field "[loop label]" nil t start (point))
9149 (let ((position (point)))
9150 (vhdl-insert-keyword " WHEN ")
9151 (when vhdl-conditions-in-parenthesis (insert "("))
9152 (if (vhdl-template-field "[condition]" nil t)
9153 (when vhdl-conditions-in-parenthesis (insert ")"))
9154 (delete-region position (point))))
9155 (delete-char -1))
9156 (insert ";")))
9158 (defun vhdl-template-others ()
9159 "Insert an others aggregate."
9160 (interactive)
9161 (let ((start (point)))
9162 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9163 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9164 (vhdl-insert-keyword "OTHERS => '")
9165 (when (vhdl-template-field "value" nil t start (point))
9166 (insert "')")))
9167 (vhdl-insert-keyword "OTHERS "))))
9169 (defun vhdl-template-package (&optional kind)
9170 "Insert a package specification or body."
9171 (interactive)
9172 (let ((margin (current-indentation))
9173 (start (point))
9174 name body position)
9175 (vhdl-insert-keyword "PACKAGE ")
9176 (setq body (if kind (eq kind 'body)
9177 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9178 (when body
9179 (vhdl-insert-keyword "BODY ")
9180 (when (save-excursion
9181 (vhdl-prepare-search-1
9182 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9183 (insert (setq name (match-string 1)))))
9184 (when (or name
9185 (setq name (vhdl-template-field "name" nil t start (point))))
9186 (vhdl-insert-keyword " IS\n")
9187 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9188 (indent-to (+ margin vhdl-basic-offset))
9189 (setq position (point))
9190 (insert "\n")
9191 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9192 (indent-to margin)
9193 (vhdl-insert-keyword "END ")
9194 (unless (vhdl-standard-p '87)
9195 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9196 (insert (or name "") ";")
9197 (goto-char position))))
9199 (defun vhdl-template-package-decl ()
9200 "Insert a package specification."
9201 (interactive)
9202 (vhdl-template-package 'decl))
9204 (defun vhdl-template-package-body ()
9205 "Insert a package body."
9206 (interactive)
9207 (vhdl-template-package 'body))
9209 (defun vhdl-template-port ()
9210 "Insert a port declaration, or port map in instantiation statements."
9211 (interactive)
9212 (let ((start (point)))
9213 (vhdl-prepare-search-1
9214 (cond
9215 ((and (save-excursion ; entity declaration
9216 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9217 (equal "ENTITY" (upcase (match-string 1))))
9218 (vhdl-template-port-list nil))
9219 ((or (save-excursion
9220 (or (beginning-of-line)
9221 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9222 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9223 (vhdl-insert-keyword "PORT ")
9224 (vhdl-template-map start))
9225 (t (vhdl-template-port-list nil))))))
9227 (defun vhdl-template-procedural ()
9228 "Insert a procedural."
9229 (interactive)
9230 (let ((margin (current-indentation))
9231 (start (point))
9232 (case-fold-search t)
9233 label)
9234 (vhdl-insert-keyword "PROCEDURAL ")
9235 (when (memq vhdl-optional-labels '(process all))
9236 (goto-char start)
9237 (insert ": ")
9238 (goto-char start)
9239 (setq label (vhdl-template-field "[label]" nil t))
9240 (unless label (delete-char 2))
9241 (forward-word 1)
9242 (forward-char 1))
9243 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9244 (insert "\n")
9245 (vhdl-template-begin-end "PROCEDURAL" label margin)
9246 (vhdl-comment-block)))
9248 (defun vhdl-template-procedure (&optional kind)
9249 "Insert a procedure declaration or body."
9250 (interactive)
9251 (let ((margin (current-indentation))
9252 (start (point))
9253 name)
9254 (vhdl-insert-keyword "PROCEDURE ")
9255 (when (setq name (vhdl-template-field "name" nil t start (point)))
9256 (vhdl-template-argument-list)
9257 (if (if kind (eq kind 'body)
9258 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9259 (progn (vhdl-insert-keyword " IS")
9260 (when vhdl-auto-align
9261 (vhdl-align-region-groups start (point) 1))
9262 (end-of-line) (insert "\n")
9263 (vhdl-template-begin-end
9264 (unless (vhdl-standard-p '87) "PROCEDURE")
9265 name margin)
9266 (vhdl-comment-block))
9267 (insert ";")
9268 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9269 (end-of-line)))))
9271 (defun vhdl-template-procedure-decl ()
9272 "Insert a procedure declaration."
9273 (interactive)
9274 (vhdl-template-procedure 'decl))
9276 (defun vhdl-template-procedure-body ()
9277 "Insert a procedure body."
9278 (interactive)
9279 (vhdl-template-procedure 'body))
9281 (defun vhdl-template-process (&optional kind)
9282 "Insert a process."
9283 (interactive)
9284 (let ((margin (current-indentation))
9285 (start (point))
9286 label seq input-signals clock reset final-pos)
9287 (setq seq (if kind (eq kind 'seq)
9288 (eq (vhdl-decision-query
9289 "process" "(c)ombinational or (s)equential?" t) ?s)))
9290 (vhdl-insert-keyword "PROCESS ")
9291 (when (memq vhdl-optional-labels '(process all))
9292 (goto-char start)
9293 (insert ": ")
9294 (goto-char start)
9295 (setq label (vhdl-template-field "[label]" nil t))
9296 (unless label (delete-char 2))
9297 (forward-word 1)
9298 (forward-char 1))
9299 (insert "(")
9300 (if (not seq)
9301 (unless (setq input-signals
9302 (vhdl-template-field "[sensitivity list]" ")" t))
9303 (setq input-signals "")
9304 (delete-char -2))
9305 (setq clock (or (and (not (equal "" vhdl-clock-name))
9306 (progn (insert vhdl-clock-name) vhdl-clock-name))
9307 (vhdl-template-field "clock name") "<clock>"))
9308 (when (eq vhdl-reset-kind 'async)
9309 (insert ", ")
9310 (setq reset (or (and (not (equal "" vhdl-reset-name))
9311 (progn (insert vhdl-reset-name) vhdl-reset-name))
9312 (vhdl-template-field "reset name") "<reset>")))
9313 (insert ")"))
9314 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9315 (insert "\n")
9316 (vhdl-template-begin-end "PROCESS" label margin)
9317 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9318 (when vhdl-prompt-for-comments
9319 (setq final-pos (point-marker))
9320 (vhdl-prepare-search-2
9321 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9322 (vhdl-re-search-backward "\\<process\\>" nil t))
9323 (end-of-line -0)
9324 (if (bobp)
9325 (progn (insert "\n") (forward-line -1))
9326 (insert "\n"))
9327 (indent-to margin)
9328 (insert "-- purpose: ")
9329 (if (not (vhdl-template-field "[description]" nil t))
9330 (vhdl-line-kill-entire)
9331 (insert "\n")
9332 (indent-to margin)
9333 (insert "-- type : ")
9334 (insert (if seq "sequential" "combinational") "\n")
9335 (indent-to margin)
9336 (insert "-- inputs : ")
9337 (if (not seq)
9338 (insert input-signals)
9339 (insert clock ", ")
9340 (when reset (insert reset ", "))
9341 (unless (vhdl-template-field "[signal names]" nil t)
9342 (delete-char -2)))
9343 (insert "\n")
9344 (indent-to margin)
9345 (insert "-- outputs: ")
9346 (vhdl-template-field "[signal names]" nil t))))
9347 (goto-char final-pos))))
9349 (defun vhdl-template-process-comb ()
9350 "Insert a combinational process."
9351 (interactive)
9352 (vhdl-template-process 'comb))
9354 (defun vhdl-template-process-seq ()
9355 "Insert a sequential process."
9356 (interactive)
9357 (vhdl-template-process 'seq))
9359 (defun vhdl-template-quantity ()
9360 "Insert a quantity declaration."
9361 (interactive)
9362 (if (vhdl-in-argument-list-p)
9363 (let ((start (point)))
9364 (vhdl-insert-keyword "QUANTITY ")
9365 (when (vhdl-template-field "names" nil t start (point))
9366 (insert " : ")
9367 (vhdl-template-field "[IN | OUT]" " " t)
9368 (vhdl-template-field "type")
9369 (insert ";")
9370 (vhdl-comment-insert-inline)))
9371 (let ((char (vhdl-decision-query
9372 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9373 (cond ((eq char ?f) (vhdl-template-quantity-free))
9374 ((eq char ?b) (vhdl-template-quantity-branch))
9375 ((eq char ?s) (vhdl-template-quantity-source))
9376 (t (vhdl-template-undo (point) (point)))))))
9378 (defun vhdl-template-quantity-free ()
9379 "Insert a free quantity declaration."
9380 (interactive)
9381 (vhdl-insert-keyword "QUANTITY ")
9382 (vhdl-template-field "names")
9383 (insert " : ")
9384 (vhdl-template-field "type")
9385 (let ((position (point)))
9386 (insert " := ")
9387 (unless (vhdl-template-field "[initialization]" nil t)
9388 (delete-region position (point)))
9389 (insert ";")
9390 (vhdl-comment-insert-inline)))
9392 (defun vhdl-template-quantity-branch ()
9393 "Insert a branch quantity declaration."
9394 (interactive)
9395 (let (position)
9396 (vhdl-insert-keyword "QUANTITY ")
9397 (when (vhdl-template-field "[across names]" " " t)
9398 (vhdl-insert-keyword "ACROSS "))
9399 (when (vhdl-template-field "[through names]" " " t)
9400 (vhdl-insert-keyword "THROUGH "))
9401 (vhdl-template-field "plus terminal name")
9402 (setq position (point))
9403 (vhdl-insert-keyword " TO ")
9404 (unless (vhdl-template-field "[minus terminal name]" nil t)
9405 (delete-region position (point)))
9406 (insert ";")
9407 (vhdl-comment-insert-inline)))
9409 (defun vhdl-template-quantity-source ()
9410 "Insert a source quantity declaration."
9411 (interactive)
9412 (vhdl-insert-keyword "QUANTITY ")
9413 (vhdl-template-field "names")
9414 (insert " : ")
9415 (vhdl-template-field "type" " ")
9416 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9417 (progn (vhdl-insert-keyword "NOISE ")
9418 (vhdl-template-field "power expression"))
9419 (vhdl-insert-keyword "SPECTRUM ")
9420 (vhdl-template-field "magnitude expression" ", ")
9421 (vhdl-template-field "phase expression"))
9422 (insert ";")
9423 (vhdl-comment-insert-inline))
9425 (defun vhdl-template-record (kind &optional name secondary)
9426 "Insert a record type declaration."
9427 (interactive)
9428 (let ((margin (current-column))
9429 (start (point))
9430 (first t))
9431 (vhdl-insert-keyword "RECORD\n")
9432 (indent-to (+ margin vhdl-basic-offset))
9433 (when (or (vhdl-template-field "element names"
9434 nil (not secondary) start (point))
9435 secondary)
9436 (while (or first (vhdl-template-field "[element names]" nil t))
9437 (insert " : ")
9438 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9439 (vhdl-comment-insert-inline)
9440 (insert "\n")
9441 (indent-to (+ margin vhdl-basic-offset))
9442 (setq first nil))
9443 (delete-region (line-beginning-position) (point))
9444 (indent-to margin)
9445 (vhdl-insert-keyword "END RECORD")
9446 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9447 (insert ";")
9448 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9450 (defun vhdl-template-report ()
9451 "Insert a report statement."
9452 (interactive)
9453 (let ((start (point)))
9454 (vhdl-insert-keyword "REPORT ")
9455 (if (equal "\"\"" (vhdl-template-field
9456 "string expression" nil t start (point) t))
9457 (delete-backward-char 2)
9458 (setq start (point))
9459 (vhdl-insert-keyword " SEVERITY ")
9460 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9461 (delete-region start (point)))
9462 (insert ";"))))
9464 (defun vhdl-template-return ()
9465 "Insert a return statement."
9466 (interactive)
9467 (let ((start (point)))
9468 (vhdl-insert-keyword "RETURN ")
9469 (unless (vhdl-template-field "[expression]" nil t start (point))
9470 (delete-char -1))
9471 (insert ";")))
9473 (defun vhdl-template-selected-signal-asst ()
9474 "Insert a selected signal assignment."
9475 (interactive)
9476 (let ((margin (current-indentation))
9477 (start (point))
9478 (choices t))
9479 (let ((position (point)))
9480 (vhdl-insert-keyword " SELECT ")
9481 (goto-char position))
9482 (vhdl-insert-keyword "WITH ")
9483 (when (vhdl-template-field "selector expression"
9484 nil t start (+ (point) 7))
9485 (forward-word 1)
9486 (delete-char 1)
9487 (insert "\n")
9488 (indent-to (+ margin vhdl-basic-offset))
9489 (vhdl-template-field "target signal" " <= ")
9490 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9491 (insert "\n")
9492 (indent-to (+ margin vhdl-basic-offset))
9493 (vhdl-template-field "waveform")
9494 (vhdl-insert-keyword " WHEN ")
9495 (vhdl-template-field "choices" ",")
9496 (insert "\n")
9497 (indent-to (+ margin vhdl-basic-offset))
9498 (while (and choices (vhdl-template-field "[waveform]" nil t))
9499 (vhdl-insert-keyword " WHEN ")
9500 (if (setq choices (vhdl-template-field "[choices]" "," t))
9501 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9502 (vhdl-insert-keyword "OTHERS")))
9503 (when choices
9504 (fixup-whitespace)
9505 (delete-char -2))
9506 (insert ";")
9507 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9509 (defun vhdl-template-signal ()
9510 "Insert a signal declaration."
9511 (interactive)
9512 (let ((start (point))
9513 (in-arglist (vhdl-in-argument-list-p)))
9514 (vhdl-insert-keyword "SIGNAL ")
9515 (when (vhdl-template-field "names" nil t start (point))
9516 (insert " : ")
9517 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9518 (vhdl-template-field "type")
9519 (if in-arglist
9520 (progn (insert ";")
9521 (vhdl-comment-insert-inline))
9522 (let ((position (point)))
9523 (insert " := ")
9524 (unless (vhdl-template-field "[initialization]" nil t)
9525 (delete-region position (point)))
9526 (insert ";")
9527 (vhdl-comment-insert-inline))))))
9529 (defun vhdl-template-subnature ()
9530 "Insert a subnature declaration."
9531 (interactive)
9532 (let ((start (point))
9533 position)
9534 (vhdl-insert-keyword "SUBNATURE ")
9535 (when (vhdl-template-field "name" nil t start (point))
9536 (vhdl-insert-keyword " IS ")
9537 (vhdl-template-field "nature" " (")
9538 (if (vhdl-template-field "[index range]" nil t)
9539 (insert ")")
9540 (delete-char -2))
9541 (setq position (point))
9542 (vhdl-insert-keyword " TOLERANCE ")
9543 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9544 nil t nil nil t))
9545 (delete-region position (point))
9546 (vhdl-insert-keyword " ACROSS ")
9547 (vhdl-template-field "string expression" nil nil nil nil t)
9548 (vhdl-insert-keyword " THROUGH"))
9549 (insert ";")
9550 (vhdl-comment-insert-inline))))
9552 (defun vhdl-template-subprogram-body ()
9553 "Insert a subprogram body."
9554 (interactive)
9555 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9556 (vhdl-template-function-body)
9557 (vhdl-template-procedure-body)))
9559 (defun vhdl-template-subprogram-decl ()
9560 "Insert a subprogram declaration."
9561 (interactive)
9562 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9563 (vhdl-template-function-decl)
9564 (vhdl-template-procedure-decl)))
9566 (defun vhdl-template-subtype ()
9567 "Insert a subtype declaration."
9568 (interactive)
9569 (let ((start (point)))
9570 (vhdl-insert-keyword "SUBTYPE ")
9571 (when (vhdl-template-field "name" nil t start (point))
9572 (vhdl-insert-keyword " IS ")
9573 (vhdl-template-field "type" " ")
9574 (unless
9575 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9576 (delete-char -1))
9577 (insert ";")
9578 (vhdl-comment-insert-inline))))
9580 (defun vhdl-template-terminal ()
9581 "Insert a terminal declaration."
9582 (interactive)
9583 (let ((start (point)))
9584 (vhdl-insert-keyword "TERMINAL ")
9585 (when (vhdl-template-field "names" nil t start (point))
9586 (insert " : ")
9587 (vhdl-template-field "nature")
9588 (insert ";")
9589 (vhdl-comment-insert-inline))))
9591 (defun vhdl-template-type ()
9592 "Insert a type declaration."
9593 (interactive)
9594 (let ((start (point))
9595 name mid-pos end-pos)
9596 (vhdl-insert-keyword "TYPE ")
9597 (when (setq name (vhdl-template-field "name" nil t start (point)))
9598 (vhdl-insert-keyword " IS ")
9599 (let ((definition
9600 (upcase
9601 (or (vhdl-template-field
9602 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9603 ""))))
9604 (cond ((equal definition "")
9605 (delete-backward-char 4)
9606 (insert ";"))
9607 ((equal definition "ARRAY")
9608 (delete-region (point) (progn (forward-word -1) (point)))
9609 (vhdl-template-array 'type t))
9610 ((equal definition "RECORD")
9611 (setq mid-pos (point-marker))
9612 (delete-region (point) (progn (forward-word -1) (point)))
9613 (vhdl-template-record 'type name t))
9614 ((equal definition "ACCESS")
9615 (insert " ")
9616 (vhdl-template-field "type" ";"))
9617 ((equal definition "FILE")
9618 (vhdl-insert-keyword " OF ")
9619 (vhdl-template-field "type" ";"))
9620 (t (insert ";")))
9621 (when mid-pos
9622 (setq end-pos (point-marker))
9623 (goto-char mid-pos)
9624 (end-of-line))
9625 (vhdl-comment-insert-inline)
9626 (when end-pos (goto-char end-pos))))))
9628 (defun vhdl-template-use ()
9629 "Insert a use clause."
9630 (interactive)
9631 (let ((start (point)))
9632 (vhdl-prepare-search-1
9633 (vhdl-insert-keyword "USE ")
9634 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9635 (vhdl-insert-keyword "..ALL;")
9636 (backward-char 6)
9637 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9638 (forward-char 1)
9639 (vhdl-template-field "package name")
9640 (forward-char 5))))))
9642 (defun vhdl-template-variable ()
9643 "Insert a variable declaration."
9644 (interactive)
9645 (let ((start (point))
9646 (in-arglist (vhdl-in-argument-list-p)))
9647 (vhdl-prepare-search-2
9648 (if (or (save-excursion
9649 (and (vhdl-re-search-backward
9650 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9651 nil t)
9652 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9653 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9654 (vhdl-insert-keyword "VARIABLE ")
9655 (vhdl-insert-keyword "SHARED VARIABLE ")))
9656 (when (vhdl-template-field "names" nil t start (point))
9657 (insert " : ")
9658 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9659 (vhdl-template-field "type")
9660 (if in-arglist
9661 (progn (insert ";")
9662 (vhdl-comment-insert-inline))
9663 (let ((position (point)))
9664 (insert " := ")
9665 (unless (vhdl-template-field "[initialization]" nil t)
9666 (delete-region position (point)))
9667 (insert ";")
9668 (vhdl-comment-insert-inline))))))
9670 (defun vhdl-template-wait ()
9671 "Insert a wait statement."
9672 (interactive)
9673 (vhdl-insert-keyword "WAIT ")
9674 (unless (vhdl-template-field
9675 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9676 nil t)
9677 (delete-char -1))
9678 (insert ";"))
9680 (defun vhdl-template-when ()
9681 "Indent correctly if within a case statement."
9682 (interactive)
9683 (let ((position (point))
9684 margin)
9685 (vhdl-prepare-search-2
9686 (if (and (= (current-column) (current-indentation))
9687 (vhdl-re-search-forward "\\<end\\>" nil t)
9688 (looking-at "\\s-*\\<case\\>"))
9689 (progn
9690 (setq margin (current-indentation))
9691 (goto-char position)
9692 (delete-horizontal-space)
9693 (indent-to (+ margin vhdl-basic-offset)))
9694 (goto-char position)))
9695 (vhdl-insert-keyword "WHEN ")))
9697 (defun vhdl-template-while-loop ()
9698 "Insert a while loop."
9699 (interactive)
9700 (let* ((margin (current-indentation))
9701 (start (point))
9702 label)
9703 (if (not (eq vhdl-optional-labels 'all))
9704 (vhdl-insert-keyword "WHILE ")
9705 (vhdl-insert-keyword ": WHILE ")
9706 (goto-char start)
9707 (setq label (vhdl-template-field "[label]" nil t))
9708 (unless label (delete-char 2))
9709 (forward-word 1)
9710 (forward-char 1))
9711 (when vhdl-conditions-in-parenthesis (insert "("))
9712 (when (vhdl-template-field "condition" nil t start (point))
9713 (when vhdl-conditions-in-parenthesis (insert ")"))
9714 (vhdl-insert-keyword " LOOP\n\n")
9715 (indent-to margin)
9716 (vhdl-insert-keyword "END LOOP")
9717 (insert (if label (concat " " label ";") ";"))
9718 (forward-line -1)
9719 (indent-to (+ margin vhdl-basic-offset)))))
9721 (defun vhdl-template-with ()
9722 "Insert a with statement (i.e. selected signal assignment)."
9723 (interactive)
9724 (vhdl-prepare-search-1
9725 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9726 (equal ";" (match-string 1)))
9727 (vhdl-template-selected-signal-asst)
9728 (vhdl-insert-keyword "WITH "))))
9730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9731 ;; Special templates
9733 (defun vhdl-template-clocked-wait ()
9734 "Insert a wait statement for rising/falling clock edge."
9735 (interactive)
9736 (let ((start (point))
9737 clock)
9738 (vhdl-insert-keyword "WAIT UNTIL ")
9739 (when (setq clock
9740 (or (and (not (equal "" vhdl-clock-name))
9741 (progn (insert vhdl-clock-name) vhdl-clock-name))
9742 (vhdl-template-field "clock name" nil t start (point))))
9743 (insert "'event")
9744 (vhdl-insert-keyword " AND ")
9745 (insert clock)
9746 (insert
9747 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9748 (vhdl-comment-insert-inline
9749 (concat (if vhdl-clock-rising-edge "rising" "falling")
9750 " clock edge")))))
9752 (defun vhdl-template-seq-process (clock reset)
9753 "Insert a template for the body of a sequential process."
9754 (let ((margin (current-indentation))
9755 position)
9756 (vhdl-insert-keyword "IF ")
9757 (when (eq vhdl-reset-kind 'async)
9758 (insert reset " = "
9759 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9760 (vhdl-insert-keyword " THEN")
9761 (vhdl-comment-insert-inline
9762 (concat "asynchronous reset (active "
9763 (if vhdl-reset-active-high "high" "low") ")"))
9764 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9765 (setq position (point))
9766 (insert "\n") (indent-to margin)
9767 (vhdl-insert-keyword "ELSIF "))
9768 (if (eq vhdl-clock-edge-condition 'function)
9769 (insert (if vhdl-clock-rising-edge "rising" "falling")
9770 "_edge(" clock ")")
9771 (insert clock "'event")
9772 (vhdl-insert-keyword " AND ")
9773 (insert clock " = "
9774 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9775 (vhdl-insert-keyword " THEN")
9776 (vhdl-comment-insert-inline
9777 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9778 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9779 (when (eq vhdl-reset-kind 'sync)
9780 (vhdl-insert-keyword "IF ")
9781 (setq reset (or (and (not (equal "" vhdl-reset-name))
9782 (progn (insert vhdl-reset-name) vhdl-reset-name))
9783 (vhdl-template-field "reset name") "<reset>"))
9784 (insert " = "
9785 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9786 (vhdl-insert-keyword " THEN")
9787 (vhdl-comment-insert-inline
9788 (concat "synchronous reset (active "
9789 (if vhdl-reset-active-high "high" "low") ")"))
9790 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9791 (setq position (point))
9792 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9793 (vhdl-insert-keyword "ELSE")
9794 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9795 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9796 (vhdl-insert-keyword "END IF;"))
9797 (when (eq vhdl-reset-kind 'none)
9798 (setq position (point)))
9799 (insert "\n") (indent-to margin)
9800 (vhdl-insert-keyword "END IF;")
9801 (goto-char position)
9802 reset))
9804 (defun vhdl-template-standard-package (library package)
9805 "Insert specification of a standard package. Include a library
9806 specification, if not already there."
9807 (let ((margin (current-indentation)))
9808 (unless (equal library "std")
9809 (unless (or (save-excursion
9810 (vhdl-prepare-search-1
9811 (and (not (bobp))
9812 (re-search-backward
9813 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9814 library "\\|end\\)\\>") nil t)
9815 (match-string 2))))
9816 (equal (downcase library) "work"))
9817 (vhdl-insert-keyword "LIBRARY ")
9818 (insert library ";")
9819 (when package
9820 (insert "\n")
9821 (indent-to margin)))
9822 (when package
9823 (vhdl-insert-keyword "USE ")
9824 (insert library "." package)
9825 (vhdl-insert-keyword ".ALL;")))))
9827 (defun vhdl-template-package-math-complex ()
9828 "Insert specification of `math_complex' package."
9829 (interactive)
9830 (vhdl-template-standard-package "ieee" "math_complex"))
9832 (defun vhdl-template-package-math-real ()
9833 "Insert specification of `math_real' package."
9834 (interactive)
9835 (vhdl-template-standard-package "ieee" "math_real"))
9837 (defun vhdl-template-package-numeric-bit ()
9838 "Insert specification of `numeric_bit' package."
9839 (interactive)
9840 (vhdl-template-standard-package "ieee" "numeric_bit"))
9842 (defun vhdl-template-package-numeric-std ()
9843 "Insert specification of `numeric_std' package."
9844 (interactive)
9845 (vhdl-template-standard-package "ieee" "numeric_std"))
9847 (defun vhdl-template-package-std-logic-1164 ()
9848 "Insert specification of `std_logic_1164' package."
9849 (interactive)
9850 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9852 (defun vhdl-template-package-std-logic-arith ()
9853 "Insert specification of `std_logic_arith' package."
9854 (interactive)
9855 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9857 (defun vhdl-template-package-std-logic-misc ()
9858 "Insert specification of `std_logic_misc' package."
9859 (interactive)
9860 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9862 (defun vhdl-template-package-std-logic-signed ()
9863 "Insert specification of `std_logic_signed' package."
9864 (interactive)
9865 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9867 (defun vhdl-template-package-std-logic-textio ()
9868 "Insert specification of `std_logic_textio' package."
9869 (interactive)
9870 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9872 (defun vhdl-template-package-std-logic-unsigned ()
9873 "Insert specification of `std_logic_unsigned' package."
9874 (interactive)
9875 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9877 (defun vhdl-template-package-textio ()
9878 "Insert specification of `textio' package."
9879 (interactive)
9880 (vhdl-template-standard-package "std" "textio"))
9882 (defun vhdl-template-directive (directive)
9883 "Insert directive."
9884 (unless (= (current-indentation) (current-column))
9885 (delete-horizontal-space)
9886 (insert " "))
9887 (insert "-- pragma " directive))
9889 (defun vhdl-template-directive-translate-on ()
9890 "Insert directive 'translate_on'."
9891 (interactive)
9892 (vhdl-template-directive "translate_on"))
9894 (defun vhdl-template-directive-translate-off ()
9895 "Insert directive 'translate_off'."
9896 (interactive)
9897 (vhdl-template-directive "translate_off"))
9899 (defun vhdl-template-directive-synthesis-on ()
9900 "Insert directive 'synthesis_on'."
9901 (interactive)
9902 (vhdl-template-directive "synthesis_on"))
9904 (defun vhdl-template-directive-synthesis-off ()
9905 "Insert directive 'synthesis_off'."
9906 (interactive)
9907 (vhdl-template-directive "synthesis_off"))
9909 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9910 ;; Header and footer templates
9912 (defun vhdl-template-header (&optional file-title)
9913 "Insert a VHDL file header."
9914 (interactive)
9915 (unless (equal vhdl-file-header "")
9916 (let (pos)
9917 (save-excursion
9918 (goto-char (point-min))
9919 (vhdl-insert-string-or-file vhdl-file-header)
9920 (setq pos (point-marker)))
9921 (vhdl-template-replace-header-keywords
9922 (point-min-marker) pos file-title))))
9924 (defun vhdl-template-footer ()
9925 "Insert a VHDL file footer."
9926 (interactive)
9927 (unless (equal vhdl-file-footer "")
9928 (let (pos)
9929 (save-excursion
9930 (goto-char (point-max))
9931 (setq pos (point-marker))
9932 (vhdl-insert-string-or-file vhdl-file-footer)
9933 (unless (= (preceding-char) ?\n)
9934 (insert "\n")))
9935 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9937 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9938 is-model)
9939 "Replace keywords in header and footer."
9940 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9941 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9942 pos)
9943 (vhdl-prepare-search-2
9944 (save-excursion
9945 (goto-char beg)
9946 (while (search-forward "<projectdesc>" end t)
9947 (replace-match project-desc t t))
9948 (goto-char beg)
9949 (while (search-forward "<filename>" end t)
9950 (replace-match (buffer-name) t t))
9951 (goto-char beg)
9952 (while (search-forward "<copyright>" end t)
9953 (replace-match vhdl-copyright-string t t))
9954 (goto-char beg)
9955 (while (search-forward "<author>" end t)
9956 (replace-match "" t t)
9957 (insert (user-full-name))
9958 (when user-mail-address (insert " <" user-mail-address ">")))
9959 (goto-char beg)
9960 (while (search-forward "<login>" end t)
9961 (replace-match (user-login-name) t t))
9962 (goto-char beg)
9963 (while (search-forward "<project>" end t)
9964 (replace-match project-title t t))
9965 (goto-char beg)
9966 (while (search-forward "<company>" end t)
9967 (replace-match vhdl-company-name t t))
9968 (goto-char beg)
9969 (while (search-forward "<platform>" end t)
9970 (replace-match vhdl-platform-spec t t))
9971 (goto-char beg)
9972 (while (search-forward "<standard>" end t)
9973 (replace-match
9974 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9975 ((vhdl-standard-p '93) "'93"))
9976 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9977 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9978 (goto-char beg)
9979 ;; Replace <RCS> with $, so that RCS for the source is
9980 ;; not over-enthusiastic with replacements
9981 (while (search-forward "<RCS>" end t)
9982 (replace-match "$" nil t))
9983 (goto-char beg)
9984 (while (search-forward "<date>" end t)
9985 (replace-match "" t t)
9986 (vhdl-template-insert-date))
9987 (goto-char beg)
9988 (while (search-forward "<year>" end t)
9989 (replace-match (format-time-string "%Y" nil) t t))
9990 (goto-char beg)
9991 (when file-title
9992 (while (search-forward "<title string>" end t)
9993 (replace-match file-title t t))
9994 (goto-char beg))
9995 (let (string)
9996 (while
9997 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9998 (setq string (read-string (concat (match-string 1) ": ")))
9999 (replace-match string t t)))
10000 (goto-char beg)
10001 (when (and (not is-model) (search-forward "<cursor>" end t))
10002 (replace-match "" t t)
10003 (setq pos (point))))
10004 (when pos (goto-char pos))
10005 (unless is-model
10006 (when (or (not project-title) (equal project-title ""))
10007 (message "You can specify a project title in user option `vhdl-project-alist'"))
10008 (when (or (not project-desc) (equal project-desc ""))
10009 (message "You can specify a project description in user option `vhdl-project-alist'"))
10010 (when (equal vhdl-platform-spec "")
10011 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10012 (when (equal vhdl-company-name "")
10013 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10015 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10016 ;; Comment templates and functions
10018 (defun vhdl-comment-indent ()
10019 "Indent comments."
10020 (let* ((position (point))
10021 (col
10022 (progn
10023 (forward-line -1)
10024 (if (re-search-forward "--" position t)
10025 (- (current-column) 2) ; existing comment at bol stays there
10026 (goto-char position)
10027 (skip-chars-backward " \t")
10028 (max comment-column ; else indent to comment column
10029 (1+ (current-column))))))) ; except leave at least one space
10030 (goto-char position)
10031 col))
10033 (defun vhdl-comment-insert ()
10034 "Start a comment at the end of the line.
10035 If on line with code, indent at least `comment-column'.
10036 If starting after end-comment-column, start a new line."
10037 (interactive)
10038 (when (> (current-column) end-comment-column) (newline-and-indent))
10039 (if (or (looking-at "\\s-*$") ; end of line
10040 (and (not unread-command-events) ; called with key binding or menu
10041 (not (end-of-line))))
10042 (let (margin)
10043 (while (= (preceding-char) ?-) (delete-char -1))
10044 (setq margin (current-column))
10045 (delete-horizontal-space)
10046 (if (bolp)
10047 (progn (indent-to margin) (insert "--"))
10048 (insert " ")
10049 (indent-to comment-column)
10050 (insert "--"))
10051 (if (not unread-command-events) (insert " ")))
10052 ;; else code following current point implies commenting out code
10053 (let (next-input code)
10054 (while (= (preceding-char) ?-) (delete-char -2))
10055 (while (= (setq next-input (read-char)) 13) ; CR
10056 (insert "--") ; or have a space after it?
10057 (forward-char -2)
10058 (forward-line 1)
10059 (message "Enter CR if commenting out a line of code.")
10060 (setq code t))
10061 (unless code
10062 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10063 (setq unread-command-events
10064 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10066 (defun vhdl-comment-display (&optional line-exists)
10067 "Add 2 comment lines at the current indent, making a display comment."
10068 (interactive)
10069 (let ((margin (current-indentation)))
10070 (unless line-exists (vhdl-comment-display-line))
10071 (insert "\n") (indent-to margin)
10072 (insert "\n") (indent-to margin)
10073 (vhdl-comment-display-line)
10074 (end-of-line -0)
10075 (insert "-- ")))
10077 (defun vhdl-comment-display-line ()
10078 "Displays one line of dashes."
10079 (interactive)
10080 (while (= (preceding-char) ?-) (delete-char -2))
10081 (let* ((col (current-column))
10082 (len (- end-comment-column col)))
10083 (insert-char ?- len)))
10085 (defun vhdl-comment-append-inline ()
10086 "Append empty inline comment to current line."
10087 (interactive)
10088 (end-of-line)
10089 (delete-horizontal-space)
10090 (insert " ")
10091 (indent-to comment-column)
10092 (insert "-- "))
10094 (defun vhdl-comment-insert-inline (&optional string always-insert)
10095 "Insert inline comment."
10096 (when (or (and string (or vhdl-self-insert-comments always-insert))
10097 (and (not string) vhdl-prompt-for-comments))
10098 (let ((position (point)))
10099 (insert " ")
10100 (indent-to comment-column)
10101 (insert "-- ")
10102 (if (not (or (and string (progn (insert string) t))
10103 (vhdl-template-field "[comment]" nil t)))
10104 (delete-region position (point))
10105 (while (= (preceding-char) ? ) (delete-backward-char 1))
10106 ; (when (> (current-column) end-comment-column)
10107 ; (setq position (point-marker))
10108 ; (re-search-backward "-- ")
10109 ; (insert "\n")
10110 ; (indent-to comment-column)
10111 ; (goto-char position))
10112 ))))
10114 (defun vhdl-comment-block ()
10115 "Insert comment for code block."
10116 (when vhdl-prompt-for-comments
10117 (let ((final-pos (point-marker)))
10118 (vhdl-prepare-search-2
10119 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10120 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10121 (let (margin)
10122 (back-to-indentation)
10123 (setq margin (current-column))
10124 (end-of-line -0)
10125 (if (bobp)
10126 (progn (insert "\n") (forward-line -1))
10127 (insert "\n"))
10128 (indent-to margin)
10129 (insert "-- purpose: ")
10130 (unless (vhdl-template-field "[description]" nil t)
10131 (vhdl-line-kill-entire)))))
10132 (goto-char final-pos))))
10134 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10135 "Comment out region if not commented out, uncomment otherwise."
10136 (interactive "r\nP")
10137 (save-excursion
10138 (goto-char (1- end))
10139 (end-of-line)
10140 (setq end (point-marker))
10141 (goto-char beg)
10142 (beginning-of-line)
10143 (setq beg (point))
10144 (if (looking-at comment-start)
10145 (comment-region beg end '(4))
10146 (comment-region beg end))))
10148 (defun vhdl-comment-uncomment-line (&optional arg)
10149 "Comment out line if not commented out, uncomment otherwise."
10150 (interactive "p")
10151 (save-excursion
10152 (beginning-of-line)
10153 (let ((position (point)))
10154 (forward-line (or arg 1))
10155 (vhdl-comment-uncomment-region position (point)))))
10157 (defun vhdl-comment-kill-region (beg end)
10158 "Kill comments in region."
10159 (interactive "r")
10160 (save-excursion
10161 (goto-char end)
10162 (setq end (point-marker))
10163 (goto-char beg)
10164 (beginning-of-line)
10165 (while (< (point) end)
10166 (if (looking-at "^\\(\\s-*--.*\n\\)")
10167 (progn (delete-region (match-beginning 1) (match-end 1)))
10168 (beginning-of-line 2)))))
10170 (defun vhdl-comment-kill-inline-region (beg end)
10171 "Kill inline comments in region."
10172 (interactive "r")
10173 (save-excursion
10174 (goto-char end)
10175 (setq end (point-marker))
10176 (goto-char beg)
10177 (beginning-of-line)
10178 (while (< (point) end)
10179 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10180 (delete-region (match-beginning 1) (match-end 1)))
10181 (beginning-of-line 2))))
10183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10184 ;; Subtemplates
10186 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10187 "Insert a begin ... end pair with optional name after the end.
10188 Point is left between them."
10189 (let (position)
10190 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10191 (indent-to margin)
10192 (vhdl-insert-keyword "BEGIN")
10193 (when (and (or construct name) vhdl-self-insert-comments)
10194 (insert " --")
10195 (when construct (insert " ") (vhdl-insert-keyword construct))
10196 (when name (insert " " name)))
10197 (insert "\n")
10198 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10199 (indent-to (+ margin vhdl-basic-offset))
10200 (setq position (point))
10201 (insert "\n")
10202 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10203 (indent-to margin)
10204 (vhdl-insert-keyword "END")
10205 (when construct (insert " ") (vhdl-insert-keyword construct))
10206 (insert (if name (concat " " name) "") ";")
10207 (goto-char position)))
10209 (defun vhdl-template-argument-list (&optional is-function)
10210 "Read from user a procedure or function argument list."
10211 (insert " (")
10212 (let ((margin (current-column))
10213 (start (point))
10214 (end-pos (point))
10215 not-empty interface semicolon-pos)
10216 (unless vhdl-argument-list-indent
10217 (setq margin (+ (current-indentation) vhdl-basic-offset))
10218 (insert "\n")
10219 (indent-to margin))
10220 (setq interface (vhdl-template-field
10221 (concat "[CONSTANT | SIGNAL"
10222 (unless is-function " | VARIABLE") "]") " " t))
10223 (while (vhdl-template-field "[names]" nil t)
10224 (setq not-empty t)
10225 (insert " : ")
10226 (unless is-function
10227 (if (and interface (equal (upcase interface) "CONSTANT"))
10228 (vhdl-insert-keyword "IN ")
10229 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10230 (vhdl-template-field "type")
10231 (setq semicolon-pos (point))
10232 (insert ";")
10233 (vhdl-comment-insert-inline)
10234 (setq end-pos (point))
10235 (insert "\n")
10236 (indent-to margin)
10237 (setq interface (vhdl-template-field
10238 (concat "[CONSTANT | SIGNAL"
10239 (unless is-function " | VARIABLE") "]") " " t)))
10240 (delete-region end-pos (point))
10241 (when semicolon-pos (goto-char semicolon-pos))
10242 (if not-empty
10243 (progn (delete-char 1) (insert ")"))
10244 (delete-backward-char 2))))
10246 (defun vhdl-template-generic-list (optional &optional no-value)
10247 "Read from user a generic spec argument list."
10248 (let (margin
10249 (start (point)))
10250 (vhdl-insert-keyword "GENERIC (")
10251 (setq margin (current-column))
10252 (unless vhdl-argument-list-indent
10253 (let ((position (point)))
10254 (back-to-indentation)
10255 (setq margin (+ (current-column) vhdl-basic-offset))
10256 (goto-char position)
10257 (insert "\n")
10258 (indent-to margin)))
10259 (let ((vhdl-generics (vhdl-template-field
10260 (concat (and optional "[") "name"
10261 (and no-value "s") (and optional "]"))
10262 nil optional)))
10263 (if (not vhdl-generics)
10264 (if optional
10265 (progn (vhdl-line-kill-entire) (end-of-line -0)
10266 (unless vhdl-argument-list-indent
10267 (vhdl-line-kill-entire) (end-of-line -0)))
10268 (vhdl-template-undo start (point))
10269 nil )
10270 (insert " : ")
10271 (let (semicolon-pos end-pos)
10272 (while vhdl-generics
10273 (vhdl-template-field "type")
10274 (if no-value
10275 (progn (setq semicolon-pos (point))
10276 (insert ";"))
10277 (insert " := ")
10278 (unless (vhdl-template-field "[value]" nil t)
10279 (delete-char -4))
10280 (setq semicolon-pos (point))
10281 (insert ";"))
10282 (vhdl-comment-insert-inline)
10283 (setq end-pos (point))
10284 (insert "\n")
10285 (indent-to margin)
10286 (setq vhdl-generics (vhdl-template-field
10287 (concat "[name" (and no-value "s") "]")
10288 " : " t)))
10289 (delete-region end-pos (point))
10290 (goto-char semicolon-pos)
10291 (insert ")")
10292 (end-of-line)
10293 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10294 t)))))
10296 (defun vhdl-template-port-list (optional)
10297 "Read from user a port spec argument list."
10298 (let ((start (point))
10299 margin vhdl-ports object)
10300 (vhdl-insert-keyword "PORT (")
10301 (setq margin (current-column))
10302 (unless vhdl-argument-list-indent
10303 (let ((position (point)))
10304 (back-to-indentation)
10305 (setq margin (+ (current-column) vhdl-basic-offset))
10306 (goto-char position)
10307 (insert "\n")
10308 (indent-to margin)))
10309 (when (vhdl-standard-p 'ams)
10310 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10311 " " t)))
10312 (setq vhdl-ports (vhdl-template-field
10313 (concat (and optional "[") "names" (and optional "]"))
10314 nil optional))
10315 (if (not vhdl-ports)
10316 (if optional
10317 (progn (vhdl-line-kill-entire) (end-of-line -0)
10318 (unless vhdl-argument-list-indent
10319 (vhdl-line-kill-entire) (end-of-line -0)))
10320 (vhdl-template-undo start (point))
10321 nil)
10322 (insert " : ")
10323 (let (semicolon-pos end-pos)
10324 (while vhdl-ports
10325 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10326 (vhdl-template-field "IN | OUT | INOUT" " "))
10327 ((equal "QUANTITY" (upcase object))
10328 (vhdl-template-field "[IN | OUT]" " " t)))
10329 (vhdl-template-field
10330 (if (and object (equal "TERMINAL" (upcase object)))
10331 "nature" "type"))
10332 (setq semicolon-pos (point))
10333 (insert ";")
10334 (vhdl-comment-insert-inline)
10335 (setq end-pos (point))
10336 (insert "\n")
10337 (indent-to margin)
10338 (when (vhdl-standard-p 'ams)
10339 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10340 " " t)))
10341 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10342 (delete-region end-pos (point))
10343 (goto-char semicolon-pos)
10344 (insert ")")
10345 (end-of-line)
10346 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10347 t))))
10349 (defun vhdl-template-generate-body (margin label)
10350 "Insert body for generate template."
10351 (vhdl-insert-keyword " GENERATE")
10352 ; (if (not (vhdl-standard-p '87))
10353 ; (vhdl-template-begin-end "GENERATE" label margin)
10354 (insert "\n\n")
10355 (indent-to margin)
10356 (vhdl-insert-keyword "END GENERATE ")
10357 (insert label ";")
10358 (end-of-line 0)
10359 (indent-to (+ margin vhdl-basic-offset)))
10361 (defun vhdl-template-insert-date ()
10362 "Insert date in appropriate format."
10363 (interactive)
10364 (insert
10365 (cond
10366 ;; 'american, 'european, 'scientific kept for backward compatibility
10367 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10368 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10369 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10370 (t (format-time-string vhdl-date-format nil)))))
10372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10373 ;; Help functions
10375 (defun vhdl-electric-space (count)
10376 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10377 if in comment and past end-comment-column."
10378 (interactive "p")
10379 (cond ((vhdl-in-comment-p)
10380 (self-insert-command count)
10381 (cond ((>= (current-column) (+ 2 end-comment-column))
10382 (backward-char 1)
10383 (skip-chars-backward "^ \t\n")
10384 (indent-new-comment-line)
10385 (skip-chars-forward "^ \t\n")
10386 (forward-char 1))
10387 ((>= (current-column) end-comment-column)
10388 (indent-new-comment-line))
10389 (t nil)))
10390 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10391 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10392 (vhdl-prepare-search-1
10393 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10394 (self-insert-command count))
10395 (t (self-insert-command count))))
10397 (defun vhdl-template-field (prompt &optional follow-string optional
10398 begin end is-string default)
10399 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10400 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10401 an empty string is inserted, return nil and call `vhdl-template-undo' for
10402 the region between BEGIN and END. IS-STRING indicates whether a string
10403 with double-quotes is to be inserted. DEFAULT specifies a default string."
10404 (let ((position (point))
10405 string)
10406 (insert "<" prompt ">")
10407 (setq string
10408 (condition-case ()
10409 (read-from-minibuffer (concat prompt ": ")
10410 (or (and is-string '("\"\"" . 2)) default)
10411 vhdl-minibuffer-local-map)
10412 (quit (if (and optional begin end)
10413 (progn (beep) "")
10414 (keyboard-quit)))))
10415 (when (or (not (equal string "")) optional)
10416 (delete-region position (point)))
10417 (when (and (equal string "") optional begin end)
10418 (vhdl-template-undo begin end)
10419 (message "Template aborted"))
10420 (unless (equal string "")
10421 (insert string)
10422 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10423 vhdl-keywords-regexp)
10424 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10425 vhdl-types-regexp)
10426 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10427 (concat "'" vhdl-attributes-regexp))
10428 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10429 vhdl-enum-values-regexp))
10430 (when (or (not (equal string "")) (not optional))
10431 (insert (or follow-string "")))
10432 (if (equal string "") nil string)))
10434 (defun vhdl-decision-query (string prompt &optional optional)
10435 "Query a decision from the user."
10436 (let ((start (point)))
10437 (when string (vhdl-insert-keyword (concat string " ")))
10438 (message prompt)
10439 (let ((char (read-char)))
10440 (delete-region start (point))
10441 (if (and optional (eq char ?\r))
10442 (progn (insert " ")
10443 (unexpand-abbrev)
10444 (throw 'abort "ERROR: Template aborted"))
10445 char))))
10447 (defun vhdl-insert-keyword (keyword)
10448 "Insert KEYWORD and adjust case."
10449 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10451 (defun vhdl-case-keyword (keyword)
10452 "Adjust case of KEYWORD."
10453 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10455 (defun vhdl-case-word (num)
10456 "Adjust case of following NUM words."
10457 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10459 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10460 "If preceeding character is part of a word or a paren then hippie-expand,
10461 else insert tab (used for word completion in VHDL minibuffer)."
10462 (interactive "P")
10463 (cond
10464 ;; expand word
10465 ((= (char-syntax (preceding-char)) ?w)
10466 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10467 (case-replace nil)
10468 (hippie-expand-only-buffers
10469 (or (and (boundp 'hippie-expand-only-buffers)
10470 hippie-expand-only-buffers)
10471 '(vhdl-mode))))
10472 (vhdl-expand-abbrev prefix-arg)))
10473 ;; expand parenthesis
10474 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10475 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10476 (case-replace nil))
10477 (vhdl-expand-paren prefix-arg)))
10478 ;; insert tab
10479 (t (insert-tab))))
10481 (defun vhdl-template-search-prompt ()
10482 "Search for left out template prompts and query again."
10483 (interactive)
10484 (vhdl-prepare-search-2
10485 (when (or (re-search-forward
10486 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10487 (re-search-backward
10488 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10489 (let ((string (match-string 1)))
10490 (replace-match "")
10491 (vhdl-template-field string)))))
10493 (defun vhdl-template-undo (begin end)
10494 "Undo aborted template by deleting region and unexpanding the keyword."
10495 (cond (vhdl-template-invoked-by-hook
10496 (goto-char end)
10497 (insert " ")
10498 (delete-region begin end)
10499 (unexpand-abbrev))
10500 (t (delete-region begin end))))
10502 (defun vhdl-insert-string-or-file (string)
10503 "Insert STRING or file contents if STRING is an existing file name."
10504 (unless (equal string "")
10505 (let ((file-name
10506 (progn (string-match "^\\([^\n]+\\)" string)
10507 (vhdl-resolve-env-variable (match-string 1 string)))))
10508 (if (file-exists-p file-name)
10509 (forward-char (cadr (insert-file-contents file-name)))
10510 (insert string)))))
10512 (defun vhdl-beginning-of-block ()
10513 "Move cursor to the beginning of the enclosing block."
10514 (let (pos)
10515 (save-excursion
10516 (beginning-of-line)
10517 ;; search backward for block beginning or end
10518 (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))
10519 ;; not consider subprogram declarations
10520 (or (and (match-string 5)
10521 (save-match-data
10522 (save-excursion
10523 (goto-char (match-end 5))
10524 (forward-word 1)
10525 (vhdl-forward-syntactic-ws)
10526 (when (looking-at "(")
10527 (forward-sexp))
10528 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10529 (match-string 1)))
10530 ;; not consider configuration specifications
10531 (and (match-string 6)
10532 (save-match-data
10533 (save-excursion
10534 (vhdl-end-of-block)
10535 (beginning-of-line)
10536 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10537 (match-string 2))
10538 ;; skip subblock if block end found
10539 (vhdl-beginning-of-block)))
10540 (when pos (goto-char pos))))
10542 (defun vhdl-end-of-block ()
10543 "Move cursor to the end of the enclosing block."
10544 (let (pos)
10545 (save-excursion
10546 (end-of-line)
10547 ;; search forward for block beginning or end
10548 (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))
10549 ;; not consider subprogram declarations
10550 (or (and (match-string 5)
10551 (save-match-data
10552 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10553 (match-string 1)))
10554 ;; not consider configuration specifications
10555 (and (match-string 6)
10556 (save-match-data
10557 (save-excursion
10558 (vhdl-end-of-block)
10559 (beginning-of-line)
10560 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10561 (not (match-string 2)))
10562 ;; skip subblock if block beginning found
10563 (vhdl-end-of-block)))
10564 (when pos (goto-char pos))))
10566 (defun vhdl-sequential-statement-p ()
10567 "Check if point is within sequential statement part."
10568 (let ((start (point)))
10569 (save-excursion
10570 (vhdl-prepare-search-2
10571 ;; is sequential statement if ...
10572 (and (re-search-backward "^\\s-*begin\\>" nil t)
10573 ;; ... point is between "begin" and "end" of ...
10574 (progn (vhdl-end-of-block)
10575 (< start (point)))
10576 ;; ... a sequential block
10577 (progn (vhdl-beginning-of-block)
10578 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10580 (defun vhdl-in-argument-list-p ()
10581 "Check if within an argument list."
10582 (save-excursion
10583 (vhdl-prepare-search-2
10584 (or (string-match "arglist"
10585 (format "%s" (caar (vhdl-get-syntactic-context))))
10586 (progn (beginning-of-line)
10587 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10589 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10590 ;; Abbrev hooks
10592 (defun vhdl-hooked-abbrev (func)
10593 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10594 but not if inside a comment or quote."
10595 (if (or (vhdl-in-literal)
10596 (save-excursion
10597 (forward-word -1)
10598 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10599 (progn
10600 (insert " ")
10601 (unexpand-abbrev)
10602 (delete-char -1))
10603 (if (not vhdl-electric-mode)
10604 (progn
10605 (insert " ")
10606 (unexpand-abbrev)
10607 (backward-word 1)
10608 (vhdl-case-word 1)
10609 (delete-char 1))
10610 (let ((invoke-char last-command-char)
10611 (abbrev-mode -1)
10612 (vhdl-template-invoked-by-hook t))
10613 (let ((caught (catch 'abort
10614 (funcall func))))
10615 (when (stringp caught) (message "%s" caught)))
10616 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10617 ;; delete CR which is still in event queue
10618 (if (fboundp 'enqueue-eval-event)
10619 (enqueue-eval-event 'delete-char -1)
10620 (setq unread-command-events ; push back a delete char
10621 (list (vhdl-character-to-event ?\177))))))))
10623 (defun vhdl-template-alias-hook ()
10624 (vhdl-hooked-abbrev 'vhdl-template-alias))
10625 (defun vhdl-template-architecture-hook ()
10626 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10627 (defun vhdl-template-assert-hook ()
10628 (vhdl-hooked-abbrev 'vhdl-template-assert))
10629 (defun vhdl-template-attribute-hook ()
10630 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10631 (defun vhdl-template-block-hook ()
10632 (vhdl-hooked-abbrev 'vhdl-template-block))
10633 (defun vhdl-template-break-hook ()
10634 (vhdl-hooked-abbrev 'vhdl-template-break))
10635 (defun vhdl-template-case-hook ()
10636 (vhdl-hooked-abbrev 'vhdl-template-case))
10637 (defun vhdl-template-component-hook ()
10638 (vhdl-hooked-abbrev 'vhdl-template-component))
10639 (defun vhdl-template-instance-hook ()
10640 (vhdl-hooked-abbrev 'vhdl-template-instance))
10641 (defun vhdl-template-conditional-signal-asst-hook ()
10642 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10643 (defun vhdl-template-configuration-hook ()
10644 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10645 (defun vhdl-template-constant-hook ()
10646 (vhdl-hooked-abbrev 'vhdl-template-constant))
10647 (defun vhdl-template-disconnect-hook ()
10648 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10649 (defun vhdl-template-display-comment-hook ()
10650 (vhdl-hooked-abbrev 'vhdl-comment-display))
10651 (defun vhdl-template-else-hook ()
10652 (vhdl-hooked-abbrev 'vhdl-template-else))
10653 (defun vhdl-template-elsif-hook ()
10654 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10655 (defun vhdl-template-entity-hook ()
10656 (vhdl-hooked-abbrev 'vhdl-template-entity))
10657 (defun vhdl-template-exit-hook ()
10658 (vhdl-hooked-abbrev 'vhdl-template-exit))
10659 (defun vhdl-template-file-hook ()
10660 (vhdl-hooked-abbrev 'vhdl-template-file))
10661 (defun vhdl-template-for-hook ()
10662 (vhdl-hooked-abbrev 'vhdl-template-for))
10663 (defun vhdl-template-function-hook ()
10664 (vhdl-hooked-abbrev 'vhdl-template-function))
10665 (defun vhdl-template-generic-hook ()
10666 (vhdl-hooked-abbrev 'vhdl-template-generic))
10667 (defun vhdl-template-group-hook ()
10668 (vhdl-hooked-abbrev 'vhdl-template-group))
10669 (defun vhdl-template-library-hook ()
10670 (vhdl-hooked-abbrev 'vhdl-template-library))
10671 (defun vhdl-template-limit-hook ()
10672 (vhdl-hooked-abbrev 'vhdl-template-limit))
10673 (defun vhdl-template-if-hook ()
10674 (vhdl-hooked-abbrev 'vhdl-template-if))
10675 (defun vhdl-template-bare-loop-hook ()
10676 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10677 (defun vhdl-template-map-hook ()
10678 (vhdl-hooked-abbrev 'vhdl-template-map))
10679 (defun vhdl-template-nature-hook ()
10680 (vhdl-hooked-abbrev 'vhdl-template-nature))
10681 (defun vhdl-template-next-hook ()
10682 (vhdl-hooked-abbrev 'vhdl-template-next))
10683 (defun vhdl-template-others-hook ()
10684 (vhdl-hooked-abbrev 'vhdl-template-others))
10685 (defun vhdl-template-package-hook ()
10686 (vhdl-hooked-abbrev 'vhdl-template-package))
10687 (defun vhdl-template-port-hook ()
10688 (vhdl-hooked-abbrev 'vhdl-template-port))
10689 (defun vhdl-template-procedural-hook ()
10690 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10691 (defun vhdl-template-procedure-hook ()
10692 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10693 (defun vhdl-template-process-hook ()
10694 (vhdl-hooked-abbrev 'vhdl-template-process))
10695 (defun vhdl-template-quantity-hook ()
10696 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10697 (defun vhdl-template-report-hook ()
10698 (vhdl-hooked-abbrev 'vhdl-template-report))
10699 (defun vhdl-template-return-hook ()
10700 (vhdl-hooked-abbrev 'vhdl-template-return))
10701 (defun vhdl-template-selected-signal-asst-hook ()
10702 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10703 (defun vhdl-template-signal-hook ()
10704 (vhdl-hooked-abbrev 'vhdl-template-signal))
10705 (defun vhdl-template-subnature-hook ()
10706 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10707 (defun vhdl-template-subtype-hook ()
10708 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10709 (defun vhdl-template-terminal-hook ()
10710 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10711 (defun vhdl-template-type-hook ()
10712 (vhdl-hooked-abbrev 'vhdl-template-type))
10713 (defun vhdl-template-use-hook ()
10714 (vhdl-hooked-abbrev 'vhdl-template-use))
10715 (defun vhdl-template-variable-hook ()
10716 (vhdl-hooked-abbrev 'vhdl-template-variable))
10717 (defun vhdl-template-wait-hook ()
10718 (vhdl-hooked-abbrev 'vhdl-template-wait))
10719 (defun vhdl-template-when-hook ()
10720 (vhdl-hooked-abbrev 'vhdl-template-when))
10721 (defun vhdl-template-while-loop-hook ()
10722 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10723 (defun vhdl-template-with-hook ()
10724 (vhdl-hooked-abbrev 'vhdl-template-with))
10725 (defun vhdl-template-and-hook ()
10726 (vhdl-hooked-abbrev 'vhdl-template-and))
10727 (defun vhdl-template-or-hook ()
10728 (vhdl-hooked-abbrev 'vhdl-template-or))
10729 (defun vhdl-template-nand-hook ()
10730 (vhdl-hooked-abbrev 'vhdl-template-nand))
10731 (defun vhdl-template-nor-hook ()
10732 (vhdl-hooked-abbrev 'vhdl-template-nor))
10733 (defun vhdl-template-xor-hook ()
10734 (vhdl-hooked-abbrev 'vhdl-template-xor))
10735 (defun vhdl-template-xnor-hook ()
10736 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10737 (defun vhdl-template-not-hook ()
10738 (vhdl-hooked-abbrev 'vhdl-template-not))
10740 (defun vhdl-template-default-hook ()
10741 (vhdl-hooked-abbrev 'vhdl-template-default))
10742 (defun vhdl-template-default-indent-hook ()
10743 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10745 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10746 ;; Template insertion from completion list
10748 (defun vhdl-template-insert-construct (name)
10749 "Insert the built-in construct template with NAME."
10750 (interactive
10751 (list (let ((completion-ignore-case t))
10752 (completing-read "Construct name: "
10753 vhdl-template-construct-alist nil t))))
10754 (vhdl-template-insert-fun
10755 (cadr (assoc name vhdl-template-construct-alist))))
10757 (defun vhdl-template-insert-package (name)
10758 "Insert the built-in package template with NAME."
10759 (interactive
10760 (list (let ((completion-ignore-case t))
10761 (completing-read "Package name: "
10762 vhdl-template-package-alist nil t))))
10763 (vhdl-template-insert-fun
10764 (cadr (assoc name vhdl-template-package-alist))))
10766 (defun vhdl-template-insert-directive (name)
10767 "Insert the built-in directive template with NAME."
10768 (interactive
10769 (list (let ((completion-ignore-case t))
10770 (completing-read "Directive name: "
10771 vhdl-template-directive-alist nil t))))
10772 (vhdl-template-insert-fun
10773 (cadr (assoc name vhdl-template-directive-alist))))
10775 (defun vhdl-template-insert-fun (fun)
10776 "Call FUN to insert a built-in template."
10777 (let ((caught (catch 'abort (when fun (funcall fun)))))
10778 (when (stringp caught) (message "%s" caught))))
10781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10782 ;;; Models
10783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10785 (defun vhdl-model-insert (model-name)
10786 "Insert the user model with name MODEL-NAME."
10787 (interactive
10788 (let ((completion-ignore-case t))
10789 (list (completing-read "Model name: " vhdl-model-alist))))
10790 (indent-according-to-mode)
10791 (let ((start (point-marker))
10792 (margin (current-indentation))
10793 model position prompt string end)
10794 (vhdl-prepare-search-2
10795 (when (setq model (assoc model-name vhdl-model-alist))
10796 ;; insert model
10797 (beginning-of-line)
10798 (delete-horizontal-space)
10799 (goto-char start)
10800 (vhdl-insert-string-or-file (nth 1 model))
10801 (setq end (point-marker))
10802 ;; indent code
10803 (goto-char start)
10804 (beginning-of-line)
10805 (while (< (point) end)
10806 (unless (looking-at "^$")
10807 (insert-char ? margin))
10808 (beginning-of-line 2))
10809 (goto-char start)
10810 ;; insert clock
10811 (unless (equal "" vhdl-clock-name)
10812 (while (re-search-forward "<clock>" end t)
10813 (replace-match vhdl-clock-name)))
10814 (goto-char start)
10815 ;; insert reset
10816 (unless (equal "" vhdl-reset-name)
10817 (while (re-search-forward "<reset>" end t)
10818 (replace-match vhdl-reset-name)))
10819 ;; replace header prompts
10820 (vhdl-template-replace-header-keywords start end nil t)
10821 (goto-char start)
10822 ;; query other prompts
10823 (while (re-search-forward
10824 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10825 (unless (equal "cursor" (match-string 1))
10826 (setq position (match-beginning 1))
10827 (setq prompt (match-string 1))
10828 (replace-match "")
10829 (setq string (vhdl-template-field prompt nil t))
10830 ;; replace occurrences of same prompt
10831 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10832 (replace-match (or string "")))
10833 (goto-char position)))
10834 (goto-char start)
10835 ;; goto final position
10836 (if (re-search-forward "<cursor>" end t)
10837 (replace-match "")
10838 (goto-char end))))))
10840 (defun vhdl-model-defun ()
10841 "Define help and hook functions for user models."
10842 (let ((model-alist vhdl-model-alist)
10843 model-name model-keyword)
10844 (while model-alist
10845 ;; define functions for user models that can be invoked from menu and key
10846 ;; bindings and which themselves call `vhdl-model-insert' with the model
10847 ;; name as argument
10848 (setq model-name (nth 0 (car model-alist)))
10849 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10850 ,(concat "Insert model for \"" model-name "\".")
10851 (interactive)
10852 (vhdl-model-insert ,model-name)))
10853 ;; define hooks for user models that are invoked from keyword abbrevs
10854 (setq model-keyword (nth 3 (car model-alist)))
10855 (unless (equal model-keyword "")
10856 (eval `(defun
10857 ,(vhdl-function-name
10858 "vhdl-model" model-name "hook") ()
10859 (vhdl-hooked-abbrev
10860 ',(vhdl-function-name "vhdl-model" model-name)))))
10861 (setq model-alist (cdr model-alist)))))
10863 (vhdl-model-defun)
10866 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10867 ;;; Port translation
10868 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10870 (defvar vhdl-port-list nil
10871 "Variable to hold last port map parsed.")
10872 ;; structure: (parenthesised expression means list of such entries)
10873 ;; (ent-name
10874 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10875 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10876 ;; (lib-name pack-key))
10878 (defun vhdl-parse-string (string &optional optional)
10879 "Check that the text following point matches the regexp in STRING."
10880 (if (looking-at string)
10881 (goto-char (match-end 0))
10882 (unless optional
10883 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10884 (vhdl-current-line) string)))
10885 nil))
10887 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
10888 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10889 (vhdl-prepare-search-1
10890 (if (string-match (car regexp-cons) string)
10891 (if adjust-case
10892 (funcall vhdl-file-name-case
10893 (replace-match (cdr regexp-cons) t nil string))
10894 (replace-match (cdr regexp-cons) t nil string))
10895 string)))
10897 (defun vhdl-parse-group-comment ()
10898 "Parse comment and empty lines between groups of lines."
10899 (let ((start (point))
10900 string)
10901 (vhdl-forward-comment (point-max))
10902 (setq string (buffer-substring-no-properties start (point)))
10903 (vhdl-forward-syntactic-ws)
10904 ;; strip off leading blanks and first newline
10905 (while (string-match "^\\(\\s-+\\)" string)
10906 (setq string (concat (substring string 0 (match-beginning 1))
10907 (substring string (match-end 1)))))
10908 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10909 (substring string 1)
10910 string)))
10912 (defun vhdl-paste-group-comment (string indent)
10913 "Paste comment and empty lines from STRING between groups of lines
10914 with INDENT."
10915 (let ((pos (point-marker)))
10916 (when (> indent 0)
10917 (while (string-match "^\\(--\\)" string)
10918 (setq string (concat (substring string 0 (match-beginning 1))
10919 (make-string indent ? )
10920 (substring string (match-beginning 1))))))
10921 (beginning-of-line)
10922 (insert string)
10923 (goto-char pos)))
10925 (defvar vhdl-port-flattened nil
10926 "Indicates whether a port has been flattened.")
10928 (defun vhdl-port-flatten (&optional as-alist)
10929 "Flatten port list so that only one generic/port exists per line.
10930 This operation is performed on an internally stored port and is only
10931 reflected in a subsequent paste operation."
10932 (interactive)
10933 (if (not vhdl-port-list)
10934 (error "ERROR: No port has been read")
10935 (message "Flattening port for next paste...")
10936 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10937 (old-vhdl-port-list (cdr vhdl-port-list))
10938 old-port-list new-port-list old-port new-port names)
10939 ;; traverse port list and flatten entries
10940 (while (cdr old-vhdl-port-list)
10941 (setq old-port-list (car old-vhdl-port-list))
10942 (setq new-port-list nil)
10943 (while old-port-list
10944 (setq old-port (car old-port-list))
10945 (setq names (car old-port))
10946 (while names
10947 (setq new-port (cons (if as-alist (car names) (list (car names)))
10948 (cdr old-port)))
10949 (setq new-port-list (append new-port-list (list new-port)))
10950 (setq names (cdr names)))
10951 (setq old-port-list (cdr old-port-list)))
10952 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10953 (setq new-vhdl-port-list (append new-vhdl-port-list
10954 (list new-port-list))))
10955 (setq vhdl-port-list
10956 (append new-vhdl-port-list (list old-vhdl-port-list))
10957 vhdl-port-flattened t)
10958 (message "Flattening port for next paste...done"))))
10960 (defvar vhdl-port-reversed-direction nil
10961 "Indicates whether port directions are reversed.")
10963 (defun vhdl-port-reverse-direction ()
10964 "Reverse direction for all ports (useful in testbenches).
10965 This operation is performed on an internally stored port and is only
10966 reflected in a subsequent paste operation."
10967 (interactive)
10968 (if (not vhdl-port-list)
10969 (error "ERROR: No port has been read")
10970 (message "Reversing port directions for next paste...")
10971 (let ((port-list (nth 2 vhdl-port-list))
10972 port-dir-car port-dir)
10973 ;; traverse port list and reverse directions
10974 (while port-list
10975 (setq port-dir-car (cddr (car port-list))
10976 port-dir (car port-dir-car))
10977 (setcar port-dir-car
10978 (cond ((equal port-dir "in") "out")
10979 ((equal port-dir "out") "in")
10980 (t port-dir)))
10981 (setq port-list (cdr port-list)))
10982 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10983 (message "Reversing port directions for next paste...done"))))
10985 (defun vhdl-port-copy ()
10986 "Get generic and port information from an entity or component declaration."
10987 (interactive)
10988 (save-excursion
10989 (let (parse-error end-of-list
10990 decl-type name generic-list port-list context-clause
10991 object names direct type init comment group-comment)
10992 (vhdl-prepare-search-2
10993 (setq
10994 parse-error
10995 (catch 'parse
10996 ;; check if within entity or component declaration
10997 (end-of-line)
10998 (when (or (not (re-search-backward
10999 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11000 (equal "END" (upcase (match-string 1))))
11001 (throw 'parse "ERROR: Not within an entity or component declaration"))
11002 (setq decl-type (downcase (match-string-no-properties 1)))
11003 (forward-word 1)
11004 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11005 (setq name (match-string-no-properties 1))
11006 (message "Reading port of %s \"%s\"..." decl-type name)
11007 (vhdl-forward-syntactic-ws)
11008 ;; parse generic clause
11009 (when (vhdl-parse-string "generic[ \t\n]*(" t)
11010 ;; parse group comment and spacing
11011 (setq group-comment (vhdl-parse-group-comment))
11012 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11013 (while (not end-of-list)
11014 ;; parse names (accept extended identifiers)
11015 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11016 (setq names (list (match-string-no-properties 1)))
11017 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
11018 (setq names
11019 (append names (list (match-string-no-properties 1)))))
11020 ;; parse type
11021 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
11022 (setq type (match-string-no-properties 1))
11023 (setq comment nil)
11024 (while (looking-at "(")
11025 (setq type
11026 (concat type
11027 (buffer-substring-no-properties
11028 (point) (progn (forward-sexp) (point)))
11029 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11030 (match-string-no-properties 1)))))
11031 ;; special case: closing parenthesis is on separate line
11032 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11033 (setq comment (substring type (match-beginning 2)))
11034 (setq type (substring type 0 (match-beginning 1))))
11035 ;; strip of trailing group-comment
11036 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11037 (setq type (substring type 0 (match-end 1)))
11038 ;; parse initialization expression
11039 (setq init nil)
11040 (when (vhdl-parse-string ":=[ \t\n]*" t)
11041 (vhdl-parse-string "\\([^();\n]*\\)")
11042 (setq init (match-string-no-properties 1))
11043 (while (looking-at "(")
11044 (setq init
11045 (concat init
11046 (buffer-substring-no-properties
11047 (point) (progn (forward-sexp) (point)))
11048 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11049 (match-string-no-properties 1))))))
11050 ;; special case: closing parenthesis is on separate line
11051 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11052 (setq comment (substring init (match-beginning 2)))
11053 (setq init (substring init 0 (match-beginning 1)))
11054 (vhdl-forward-syntactic-ws))
11055 (skip-chars-forward " \t")
11056 ;; parse inline comment, special case: as above, no initial.
11057 (unless comment
11058 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11059 (match-string-no-properties 1))))
11060 (vhdl-forward-syntactic-ws)
11061 (setq end-of-list (vhdl-parse-string ")" t))
11062 (vhdl-parse-string "\\s-*;\\s-*")
11063 ;; parse inline comment
11064 (unless comment
11065 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11066 (match-string-no-properties 1))))
11067 ;; save everything in list
11068 (setq generic-list (append generic-list
11069 (list (list names type init
11070 comment group-comment))))
11071 ;; parse group comment and spacing
11072 (setq group-comment (vhdl-parse-group-comment))))
11073 ;; parse port clause
11074 (when (vhdl-parse-string "port[ \t\n]*(" t)
11075 ;; parse group comment and spacing
11076 (setq group-comment (vhdl-parse-group-comment))
11077 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
11078 (while (not end-of-list)
11079 ;; parse object
11080 (setq object
11081 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
11082 (match-string-no-properties 1)))
11083 ;; parse names (accept extended identifiers)
11084 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11085 (setq names (list (match-string-no-properties 1)))
11086 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11087 (setq names (append names (list (match-string-no-properties 1)))))
11088 ;; parse direction
11089 (vhdl-parse-string ":[ \t\n]*")
11090 (setq direct
11091 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
11092 (match-string-no-properties 1)))
11093 ;; parse type
11094 (vhdl-parse-string "\\([^();\n]+\\)")
11095 (setq type (match-string-no-properties 1))
11096 (setq comment nil)
11097 (while (looking-at "(")
11098 (setq type (concat type
11099 (buffer-substring-no-properties
11100 (point) (progn (forward-sexp) (point)))
11101 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11102 (match-string-no-properties 1)))))
11103 ;; special case: closing parenthesis is on separate line
11104 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11105 (setq comment (substring type (match-beginning 2)))
11106 (setq type (substring type 0 (match-beginning 1))))
11107 ;; strip of trailing group-comment
11108 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11109 (setq type (substring type 0 (match-end 1)))
11110 (vhdl-forward-syntactic-ws)
11111 (setq end-of-list (vhdl-parse-string ")" t))
11112 (vhdl-parse-string "\\s-*;\\s-*")
11113 ;; parse inline comment
11114 (unless comment
11115 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11116 (match-string-no-properties 1))))
11117 ;; save everything in list
11118 (setq port-list (append port-list
11119 (list (list names object direct type
11120 comment group-comment))))
11121 ;; parse group comment and spacing
11122 (setq group-comment (vhdl-parse-group-comment))))
11123 ; (vhdl-parse-string "end\\>")
11124 ;; parse context clause
11125 (setq context-clause (vhdl-scan-context-clause))
11126 ; ;; add surrounding package to context clause
11127 ; (when (and (equal decl-type "component")
11128 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11129 ; (setq context-clause
11130 ; (append context-clause
11131 ; (list (cons (vhdl-work-library)
11132 ; (match-string-no-properties 1))))))
11133 (message "Reading port of %s \"%s\"...done" decl-type name)
11134 nil)))
11135 ;; finish parsing
11136 (if parse-error
11137 (error parse-error)
11138 (setq vhdl-port-list (list name generic-list port-list context-clause)
11139 vhdl-port-reversed-direction nil
11140 vhdl-port-flattened nil)))))
11142 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11143 "Paste a context clause."
11144 (let ((margin (current-indentation))
11145 (clause-list (nth 3 vhdl-port-list))
11146 clause)
11147 (while clause-list
11148 (setq clause (car clause-list))
11149 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11150 (downcase exclude-pack-name)))
11151 (save-excursion
11152 (re-search-backward
11153 (concat "^\\s-*use\\s-+" (car clause)
11154 "\." (cdr clause) "\\>") nil t)))
11155 (vhdl-template-standard-package (car clause) (cdr clause))
11156 (insert "\n"))
11157 (setq clause-list (cdr clause-list)))))
11159 (defun vhdl-port-paste-generic (&optional no-init)
11160 "Paste a generic clause."
11161 (let ((margin (current-indentation))
11162 (generic-list (nth 1 vhdl-port-list))
11163 list-margin start names generic)
11164 ;; paste generic clause
11165 (when generic-list
11166 (setq start (point))
11167 (vhdl-insert-keyword "GENERIC (")
11168 (unless vhdl-argument-list-indent
11169 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11170 (setq list-margin (current-column))
11171 (while generic-list
11172 (setq generic (car generic-list))
11173 ;; paste group comment and spacing
11174 (when (memq vhdl-include-group-comments '(decl always))
11175 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11176 ;; paste names
11177 (setq names (nth 0 generic))
11178 (while names
11179 (insert (car names))
11180 (setq names (cdr names))
11181 (when names (insert ", ")))
11182 ;; paste type
11183 (insert " : " (nth 1 generic))
11184 ;; paste initialization
11185 (when (and (not no-init) (nth 2 generic))
11186 (insert " := " (nth 2 generic)))
11187 (unless (cdr generic-list) (insert ")"))
11188 (insert ";")
11189 ;; paste comment
11190 (when (and vhdl-include-port-comments (nth 3 generic))
11191 (vhdl-comment-insert-inline (nth 3 generic) t))
11192 (setq generic-list (cdr generic-list))
11193 (when generic-list (insert "\n") (indent-to list-margin)))
11194 ;; align generic clause
11195 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11197 (defun vhdl-port-paste-port ()
11198 "Paste a port clause."
11199 (let ((margin (current-indentation))
11200 (port-list (nth 2 vhdl-port-list))
11201 list-margin start names port)
11202 ;; paste port clause
11203 (when port-list
11204 (setq start (point))
11205 (vhdl-insert-keyword "PORT (")
11206 (unless vhdl-argument-list-indent
11207 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11208 (setq list-margin (current-column))
11209 (while port-list
11210 (setq port (car port-list))
11211 ;; paste group comment and spacing
11212 (when (memq vhdl-include-group-comments '(decl always))
11213 (vhdl-paste-group-comment (nth 5 port) list-margin))
11214 ;; paste object
11215 (when (nth 1 port) (insert (nth 1 port) " "))
11216 ;; paste names
11217 (setq names (nth 0 port))
11218 (while names
11219 (insert (car names))
11220 (setq names (cdr names))
11221 (when names (insert ", ")))
11222 ;; paste direction
11223 (insert " : ")
11224 (when (nth 2 port) (insert (nth 2 port) " "))
11225 ;; paste type
11226 (insert (nth 3 port))
11227 (unless (cdr port-list) (insert ")"))
11228 (insert ";")
11229 ;; paste comment
11230 (when (and vhdl-include-port-comments (nth 4 port))
11231 (vhdl-comment-insert-inline (nth 4 port) t))
11232 (setq port-list (cdr port-list))
11233 (when port-list (insert "\n") (indent-to list-margin)))
11234 ;; align port clause
11235 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11237 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11238 "Paste as an entity or component declaration."
11239 (unless no-indent (indent-according-to-mode))
11240 (let ((margin (current-indentation))
11241 (name (nth 0 vhdl-port-list)))
11242 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11243 (insert name)
11244 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11245 (vhdl-insert-keyword " IS"))
11246 ;; paste generic and port clause
11247 (when (nth 1 vhdl-port-list)
11248 (insert "\n")
11249 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11250 (insert "\n"))
11251 (indent-to (+ margin vhdl-basic-offset))
11252 (vhdl-port-paste-generic (eq kind 'component)))
11253 (when (nth 2 vhdl-port-list)
11254 (insert "\n")
11255 (when (and (memq vhdl-insert-empty-lines '(unit all))
11256 (eq kind 'entity))
11257 (insert "\n"))
11258 (indent-to (+ margin vhdl-basic-offset)))
11259 (vhdl-port-paste-port)
11260 (insert "\n")
11261 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11262 (insert "\n"))
11263 (indent-to margin)
11264 (vhdl-insert-keyword "END")
11265 (if (eq kind 'entity)
11266 (progn
11267 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11268 (insert " " name))
11269 (vhdl-insert-keyword " COMPONENT")
11270 (unless (vhdl-standard-p '87) (insert " " name)))
11271 (insert ";")))
11273 (defun vhdl-port-paste-entity (&optional no-indent)
11274 "Paste as an entity declaration."
11275 (interactive)
11276 (if (not vhdl-port-list)
11277 (error "ERROR: No port read")
11278 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11279 (vhdl-port-paste-declaration 'entity no-indent)
11280 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11282 (defun vhdl-port-paste-component (&optional no-indent)
11283 "Paste as a component declaration."
11284 (interactive)
11285 (if (not vhdl-port-list)
11286 (error "ERROR: No port read")
11287 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11288 (vhdl-port-paste-declaration 'component no-indent)
11289 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11291 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11292 "Paste as a generic map."
11293 (interactive)
11294 (unless secondary (indent-according-to-mode))
11295 (let ((margin (current-indentation))
11296 list-margin start generic
11297 (generic-list (nth 1 vhdl-port-list)))
11298 (when generic-list
11299 (setq start (point))
11300 (vhdl-insert-keyword "GENERIC MAP (")
11301 (if (not vhdl-association-list-with-formals)
11302 ;; paste list of actual generics
11303 (while generic-list
11304 (insert (if no-constants
11305 (car (nth 0 (car generic-list)))
11306 (or (nth 2 (car generic-list)) " ")))
11307 (setq generic-list (cdr generic-list))
11308 (insert (if generic-list ", " ")"))
11309 (when (and (not generic-list) secondary
11310 (null (nth 2 vhdl-port-list)))
11311 (insert ";")))
11312 (unless vhdl-argument-list-indent
11313 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11314 (setq list-margin (current-column))
11315 (while generic-list
11316 (setq generic (car generic-list))
11317 ;; paste group comment and spacing
11318 (when (eq vhdl-include-group-comments 'always)
11319 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11320 ;; paste formal and actual generic
11321 (insert (car (nth 0 generic)) " => "
11322 (if no-constants
11323 (car (nth 0 generic))
11324 (or (nth 2 generic) "")))
11325 (setq generic-list (cdr generic-list))
11326 (insert (if generic-list "," ")"))
11327 (when (and (not generic-list) secondary
11328 (null (nth 2 vhdl-port-list)))
11329 (insert ";"))
11330 ;; paste comment
11331 (when (or vhdl-include-type-comments
11332 (and vhdl-include-port-comments (nth 3 generic)))
11333 (vhdl-comment-insert-inline
11334 (concat
11335 (when vhdl-include-type-comments
11336 (concat "[" (nth 1 generic) "] "))
11337 (when vhdl-include-port-comments (nth 3 generic))) t))
11338 (when generic-list (insert "\n") (indent-to list-margin)))
11339 ;; align generic map
11340 (when vhdl-auto-align
11341 (vhdl-align-region-groups start (point) 1 t))))))
11343 (defun vhdl-port-paste-port-map ()
11344 "Paste as a port map."
11345 (let ((margin (current-indentation))
11346 list-margin start port
11347 (port-list (nth 2 vhdl-port-list)))
11348 (when port-list
11349 (setq start (point))
11350 (vhdl-insert-keyword "PORT MAP (")
11351 (if (not vhdl-association-list-with-formals)
11352 ;; paste list of actual ports
11353 (while port-list
11354 (insert (vhdl-replace-string vhdl-actual-port-name
11355 (car (nth 0 (car port-list)))))
11356 (setq port-list (cdr port-list))
11357 (insert (if port-list ", " ")")))
11358 (unless vhdl-argument-list-indent
11359 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11360 (setq list-margin (current-column))
11361 (while port-list
11362 (setq port (car port-list))
11363 ;; paste group comment and spacing
11364 (when (eq vhdl-include-group-comments 'always)
11365 (vhdl-paste-group-comment (nth 5 port) list-margin))
11366 ;; paste formal and actual port
11367 (insert (car (nth 0 port)) " => ")
11368 (insert (vhdl-replace-string vhdl-actual-port-name
11369 (car (nth 0 port))))
11370 (setq port-list (cdr port-list))
11371 (insert (if port-list "," ");"))
11372 ;; paste comment
11373 (when (or vhdl-include-direction-comments
11374 vhdl-include-type-comments
11375 (and vhdl-include-port-comments (nth 4 port)))
11376 (vhdl-comment-insert-inline
11377 (concat
11378 (cond ((and vhdl-include-direction-comments
11379 vhdl-include-type-comments)
11380 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11381 (nth 3 port) "] "))
11382 ((and vhdl-include-direction-comments (nth 2 port))
11383 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11384 (vhdl-include-direction-comments " ")
11385 (vhdl-include-type-comments
11386 (concat "[" (nth 3 port) "] ")))
11387 (when vhdl-include-port-comments (nth 4 port))) t))
11388 (when port-list (insert "\n") (indent-to list-margin)))
11389 ;; align port clause
11390 (when vhdl-auto-align
11391 (vhdl-align-region-groups start (point) 1))))))
11393 (defun vhdl-port-paste-instance (&optional name no-indent title)
11394 "Paste as an instantiation."
11395 (interactive)
11396 (if (not vhdl-port-list)
11397 (error "ERROR: No port read")
11398 (let ((orig-vhdl-port-list vhdl-port-list))
11399 ;; flatten local copy of port list (must be flat for port mapping)
11400 (vhdl-port-flatten)
11401 (unless no-indent (indent-according-to-mode))
11402 (let ((margin (current-indentation)))
11403 ;; paste instantiation
11404 (cond (name
11405 (insert name))
11406 ((equal (cdr vhdl-instance-name) "")
11407 (setq name (vhdl-template-field "instance name")))
11408 ((string-match "\%d" (cdr vhdl-instance-name))
11409 (let ((n 1))
11410 (while (save-excursion
11411 (setq name (format (vhdl-replace-string
11412 vhdl-instance-name
11413 (nth 0 vhdl-port-list)) n))
11414 (goto-char (point-min))
11415 (vhdl-re-search-forward name nil t))
11416 (setq n (1+ n)))
11417 (insert name)))
11418 (t (insert (vhdl-replace-string vhdl-instance-name
11419 (nth 0 vhdl-port-list)))))
11420 (message "Pasting port as instantiation \"%s\"..." name)
11421 (insert ": ")
11422 (when title
11423 (save-excursion
11424 (beginning-of-line)
11425 (indent-to vhdl-basic-offset)
11426 (insert "-- instance \"" name "\"\n")))
11427 (if (not (vhdl-use-direct-instantiation))
11428 (insert (nth 0 vhdl-port-list))
11429 (vhdl-insert-keyword "ENTITY ")
11430 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11431 (when (nth 1 vhdl-port-list)
11432 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11433 (vhdl-port-paste-generic-map t t))
11434 (when (nth 2 vhdl-port-list)
11435 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11436 (vhdl-port-paste-port-map))
11437 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11438 (insert ";"))
11439 (message "Pasting port as instantiation \"%s\"...done" name))
11440 (setq vhdl-port-list orig-vhdl-port-list))))
11442 (defun vhdl-port-paste-constants (&optional no-indent)
11443 "Paste generics as constants."
11444 (interactive)
11445 (if (not vhdl-port-list)
11446 (error "ERROR: No port read")
11447 (let ((orig-vhdl-port-list vhdl-port-list))
11448 (message "Pasting port as constants...")
11449 ;; flatten local copy of port list (must be flat for constant initial.)
11450 (vhdl-port-flatten)
11451 (unless no-indent (indent-according-to-mode))
11452 (let ((margin (current-indentation))
11453 start generic name
11454 (generic-list (nth 1 vhdl-port-list)))
11455 (when generic-list
11456 (setq start (point))
11457 (while generic-list
11458 (setq generic (car generic-list))
11459 ;; paste group comment and spacing
11460 (when (memq vhdl-include-group-comments '(decl always))
11461 (vhdl-paste-group-comment (nth 4 generic) margin))
11462 (vhdl-insert-keyword "CONSTANT ")
11463 ;; paste generic constants
11464 (setq name (nth 0 generic))
11465 (when name
11466 (insert (car name))
11467 ;; paste type
11468 (insert " : " (nth 1 generic))
11469 ;; paste initialization
11470 (when (nth 2 generic)
11471 (insert " := " (nth 2 generic)))
11472 (insert ";")
11473 ;; paste comment
11474 (when (and vhdl-include-port-comments (nth 3 generic))
11475 (vhdl-comment-insert-inline (nth 3 generic) t))
11476 (setq generic-list (cdr generic-list))
11477 (when generic-list (insert "\n") (indent-to margin))))
11478 ;; align signal list
11479 (when vhdl-auto-align
11480 (vhdl-align-region-groups start (point) 1))))
11481 (message "Pasting port as constants...done")
11482 (setq vhdl-port-list orig-vhdl-port-list))))
11484 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11485 "Paste ports as internal signals."
11486 (interactive)
11487 (if (not vhdl-port-list)
11488 (error "ERROR: No port read")
11489 (message "Pasting port as signals...")
11490 (unless no-indent (indent-according-to-mode))
11491 (let ((margin (current-indentation))
11492 start port names
11493 (port-list (nth 2 vhdl-port-list)))
11494 (when port-list
11495 (setq start (point))
11496 (while port-list
11497 (setq port (car port-list))
11498 ;; paste group comment and spacing
11499 (when (memq vhdl-include-group-comments '(decl always))
11500 (vhdl-paste-group-comment (nth 5 port) margin))
11501 ;; paste object
11502 (if (nth 1 port)
11503 (insert (nth 1 port) " ")
11504 (vhdl-insert-keyword "SIGNAL "))
11505 ;; paste actual port signals
11506 (setq names (nth 0 port))
11507 (while names
11508 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11509 (setq names (cdr names))
11510 (when names (insert ", ")))
11511 ;; paste type
11512 (insert " : " (nth 3 port))
11513 ;; paste initialization (inputs only)
11514 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11515 (insert " := " (if (string-match "(.+)" (nth 3 port))
11516 "(others => '0')" "'0'")))
11517 (insert ";")
11518 ;; paste comment
11519 (when (or vhdl-include-direction-comments
11520 (and vhdl-include-port-comments (nth 4 port)))
11521 (vhdl-comment-insert-inline
11522 (concat
11523 (cond ((and vhdl-include-direction-comments (nth 2 port))
11524 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11525 (vhdl-include-direction-comments " "))
11526 (when vhdl-include-port-comments (nth 4 port))) t))
11527 (setq port-list (cdr port-list))
11528 (when port-list (insert "\n") (indent-to margin)))
11529 ;; align signal list
11530 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11531 (message "Pasting port as signals...done")))
11533 (defun vhdl-port-paste-initializations (&optional no-indent)
11534 "Paste ports as signal initializations."
11535 (interactive)
11536 (if (not vhdl-port-list)
11537 (error "ERROR: No port read")
11538 (let ((orig-vhdl-port-list vhdl-port-list))
11539 (message "Pasting port as initializations...")
11540 ;; flatten local copy of port list (must be flat for signal initial.)
11541 (vhdl-port-flatten)
11542 (unless no-indent (indent-according-to-mode))
11543 (let ((margin (current-indentation))
11544 start port name
11545 (port-list (nth 2 vhdl-port-list)))
11546 (when port-list
11547 (setq start (point))
11548 (while port-list
11549 (setq port (car port-list))
11550 ;; paste actual port signal (inputs only)
11551 (when (equal "IN" (upcase (nth 2 port)))
11552 (setq name (car (nth 0 port)))
11553 (insert (vhdl-replace-string vhdl-actual-port-name name))
11554 ;; paste initialization
11555 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11556 "(others => '0')" "'0'") ";"))
11557 (setq port-list (cdr port-list))
11558 (when (and port-list
11559 (equal "IN" (upcase (nth 2 (car port-list)))))
11560 (insert "\n") (indent-to margin)))
11561 ;; align signal list
11562 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11563 (message "Pasting port as initializations...done")
11564 (setq vhdl-port-list orig-vhdl-port-list))))
11566 (defun vhdl-port-paste-testbench ()
11567 "Paste as a bare-bones testbench."
11568 (interactive)
11569 (if (not vhdl-port-list)
11570 (error "ERROR: No port read")
11571 (let ((case-fold-search t)
11572 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11573 (nth 0 vhdl-port-list)))
11574 (source-buffer (current-buffer))
11575 arch-name config-name ent-file-name arch-file-name
11576 ent-buffer arch-buffer position)
11577 ;; open entity file
11578 (unless (eq vhdl-testbench-create-files 'none)
11579 (setq ent-file-name
11580 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11581 ent-name t)
11582 "." (file-name-extension (buffer-file-name))))
11583 (if (file-exists-p ent-file-name)
11584 (if (y-or-n-p
11585 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11586 (progn (find-file ent-file-name)
11587 (erase-buffer)
11588 (set-buffer-modified-p nil))
11589 (if (eq vhdl-testbench-create-files 'separate)
11590 (setq ent-file-name nil)
11591 (error "ERROR: Pasting port as testbench...aborted")))
11592 (find-file ent-file-name)))
11593 (unless (and (eq vhdl-testbench-create-files 'separate)
11594 (null ent-file-name))
11595 ;; paste entity header
11596 (if vhdl-testbench-include-header
11597 (progn (vhdl-template-header
11598 (concat "Testbench for design \""
11599 (nth 0 vhdl-port-list) "\""))
11600 (goto-char (point-max)))
11601 (vhdl-comment-display-line) (insert "\n\n"))
11602 ;; paste std_logic_1164 package
11603 (when vhdl-testbench-include-library
11604 (vhdl-template-package-std-logic-1164)
11605 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11606 ;; paste entity declaration
11607 (vhdl-insert-keyword "ENTITY ")
11608 (insert ent-name)
11609 (vhdl-insert-keyword " IS")
11610 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11611 (insert "\n")
11612 (vhdl-insert-keyword "END ")
11613 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11614 (insert ent-name ";")
11615 (insert "\n\n")
11616 (vhdl-comment-display-line) (insert "\n"))
11617 ;; get architecture name
11618 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11619 (read-from-minibuffer "architecture name: "
11620 nil vhdl-minibuffer-local-map)
11621 (vhdl-replace-string vhdl-testbench-architecture-name
11622 (nth 0 vhdl-port-list))))
11623 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11624 ;; open architecture file
11625 (if (not (eq vhdl-testbench-create-files 'separate))
11626 (insert "\n")
11627 (setq ent-buffer (current-buffer))
11628 (setq arch-file-name
11629 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11630 (concat ent-name " " arch-name) t)
11631 "." (file-name-extension (buffer-file-name))))
11632 (when (and (file-exists-p arch-file-name)
11633 (not (y-or-n-p (concat "File \"" arch-file-name
11634 "\" exists; overwrite? "))))
11635 (error "ERROR: Pasting port as testbench...aborted"))
11636 (find-file arch-file-name)
11637 (erase-buffer)
11638 (set-buffer-modified-p nil)
11639 ;; paste architecture header
11640 (if vhdl-testbench-include-header
11641 (progn (vhdl-template-header
11642 (concat "Testbench architecture for design \""
11643 (nth 0 vhdl-port-list) "\""))
11644 (goto-char (point-max)))
11645 (vhdl-comment-display-line) (insert "\n\n")))
11646 ;; paste architecture body
11647 (vhdl-insert-keyword "ARCHITECTURE ")
11648 (insert arch-name)
11649 (vhdl-insert-keyword " OF ")
11650 (insert ent-name)
11651 (vhdl-insert-keyword " IS")
11652 (insert "\n\n") (indent-to vhdl-basic-offset)
11653 ;; paste component declaration
11654 (unless (vhdl-use-direct-instantiation)
11655 (vhdl-port-paste-component t)
11656 (insert "\n\n") (indent-to vhdl-basic-offset))
11657 ;; paste constants
11658 (when (nth 1 vhdl-port-list)
11659 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11660 (vhdl-port-paste-constants t)
11661 (insert "\n\n") (indent-to vhdl-basic-offset))
11662 ;; paste internal signals
11663 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11664 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11665 (insert "\n")
11666 ;; paste custom declarations
11667 (unless (equal "" vhdl-testbench-declarations)
11668 (insert "\n")
11669 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11670 (setq position (point))
11671 (insert "\n\n")
11672 (vhdl-comment-display-line) (insert "\n")
11673 (when vhdl-testbench-include-configuration
11674 (setq config-name (vhdl-replace-string
11675 vhdl-testbench-configuration-name
11676 (concat ent-name " " arch-name)))
11677 (insert "\n")
11678 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11679 (vhdl-insert-keyword " OF ") (insert ent-name)
11680 (vhdl-insert-keyword " IS\n")
11681 (indent-to vhdl-basic-offset)
11682 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11683 (indent-to vhdl-basic-offset)
11684 (vhdl-insert-keyword "END FOR;\n")
11685 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11686 (vhdl-comment-display-line) (insert "\n"))
11687 (goto-char position)
11688 (vhdl-template-begin-end
11689 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11690 ;; paste instantiation
11691 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11692 (vhdl-port-paste-instance
11693 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11694 (insert "\n")
11695 ;; paste custom statements
11696 (unless (equal "" vhdl-testbench-statements)
11697 (insert "\n")
11698 (vhdl-insert-string-or-file vhdl-testbench-statements))
11699 (insert "\n")
11700 (indent-to vhdl-basic-offset)
11701 (unless (eq vhdl-testbench-create-files 'none)
11702 (setq arch-buffer (current-buffer))
11703 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11704 (set-buffer arch-buffer) (save-buffer))
11705 (message "%s"
11706 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11707 ent-name arch-name)
11708 (and ent-file-name
11709 (format "\n File created: \"%s\"" ent-file-name))
11710 (and arch-file-name
11711 (format "\n File created: \"%s\"" arch-file-name)))))))
11714 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11715 ;;; Subprogram interface translation
11716 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11718 (defvar vhdl-subprog-list nil
11719 "Variable to hold last subprogram interface parsed.")
11720 ;; structure: (parenthesised expression means list of such entries)
11721 ;; (subprog-name kind
11722 ;; ((names) object direct type init comment group-comment)
11723 ;; return-type return-comment group-comment)
11725 (defvar vhdl-subprog-flattened nil
11726 "Indicates whether an subprogram interface has been flattened.")
11728 (defun vhdl-subprog-flatten ()
11729 "Flatten interface list so that only one parameter exists per line."
11730 (interactive)
11731 (if (not vhdl-subprog-list)
11732 (error "ERROR: No subprogram interface has been read")
11733 (message "Flattening subprogram interface...")
11734 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11735 new-subprog-list old-subprog new-subprog names)
11736 ;; traverse parameter list and flatten entries
11737 (while old-subprog-list
11738 (setq old-subprog (car old-subprog-list))
11739 (setq names (car old-subprog))
11740 (while names
11741 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11742 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11743 (setq names (cdr names)))
11744 (setq old-subprog-list (cdr old-subprog-list)))
11745 (setq vhdl-subprog-list
11746 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11747 new-subprog-list (nth 3 vhdl-subprog-list)
11748 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11749 vhdl-subprog-flattened t)
11750 (message "Flattening subprogram interface...done"))))
11752 (defun vhdl-subprog-copy ()
11753 "Get interface information from a subprogram specification."
11754 (interactive)
11755 (save-excursion
11756 (let (parse-error pos end-of-list
11757 name kind param-list object names direct type init
11758 comment group-comment
11759 return-type return-comment return-group-comment)
11760 (vhdl-prepare-search-2
11761 (setq
11762 parse-error
11763 (catch 'parse
11764 ;; check if within function declaration
11765 (setq pos (point))
11766 (end-of-line)
11767 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11768 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11769 (goto-char (match-end 0))
11770 (save-excursion (backward-char)
11771 (forward-sexp)
11772 (<= pos (point))))
11773 (throw 'parse "ERROR: Not within a subprogram specification"))
11774 (setq name (match-string-no-properties 5))
11775 (setq kind (if (match-string 2) 'procedure 'function))
11776 (setq end-of-list (not (match-string 7)))
11777 (message "Reading interface of subprogram \"%s\"..." name)
11778 ;; parse parameter list
11779 (setq group-comment (vhdl-parse-group-comment))
11780 (setq end-of-list (or end-of-list
11781 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11782 (while (not end-of-list)
11783 ;; parse object
11784 (setq object
11785 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11786 (match-string-no-properties 1)))
11787 ;; parse names (accept extended identifiers)
11788 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11789 (setq names (list (match-string-no-properties 1)))
11790 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11791 (setq names (append names (list (match-string-no-properties 1)))))
11792 ;; parse direction
11793 (vhdl-parse-string ":[ \t\n]*")
11794 (setq direct
11795 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11796 (match-string-no-properties 1)))
11797 ;; parse type
11798 (vhdl-parse-string "\\([^():;\n]+\\)")
11799 (setq type (match-string-no-properties 1))
11800 (setq comment nil)
11801 (while (looking-at "(")
11802 (setq type
11803 (concat type
11804 (buffer-substring-no-properties
11805 (point) (progn (forward-sexp) (point)))
11806 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11807 (match-string-no-properties 1)))))
11808 ;; special case: closing parenthesis is on separate line
11809 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11810 (setq comment (substring type (match-beginning 2)))
11811 (setq type (substring type 0 (match-beginning 1))))
11812 ;; strip off trailing group-comment
11813 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11814 (setq type (substring type 0 (match-end 1)))
11815 ;; parse initialization expression
11816 (setq init nil)
11817 (when (vhdl-parse-string ":=[ \t\n]*" t)
11818 (vhdl-parse-string "\\([^();\n]*\\)")
11819 (setq init (match-string-no-properties 1))
11820 (while (looking-at "(")
11821 (setq init
11822 (concat init
11823 (buffer-substring-no-properties
11824 (point) (progn (forward-sexp) (point)))
11825 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11826 (match-string-no-properties 1))))))
11827 ;; special case: closing parenthesis is on separate line
11828 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11829 (setq comment (substring init (match-beginning 2)))
11830 (setq init (substring init 0 (match-beginning 1)))
11831 (vhdl-forward-syntactic-ws))
11832 (skip-chars-forward " \t")
11833 ;; parse inline comment, special case: as above, no initial.
11834 (unless comment
11835 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11836 (match-string-no-properties 1))))
11837 (vhdl-forward-syntactic-ws)
11838 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11839 ;; parse inline comment
11840 (unless comment
11841 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11842 (match-string-no-properties 1))))
11843 (setq return-group-comment (vhdl-parse-group-comment))
11844 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11845 ;; parse return type
11846 (when (match-string 3)
11847 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11848 (setq return-type (match-string-no-properties 1))
11849 (when (and return-type
11850 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11851 (setq return-comment (substring return-type (match-beginning 2)))
11852 (setq return-type (substring return-type 0 (match-beginning 1))))
11853 ;; strip of trailing group-comment
11854 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11855 (setq return-type (substring return-type 0 (match-end 1)))
11856 ;; parse return comment
11857 (unless return-comment
11858 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11859 (match-string-no-properties 1)))))
11860 ;; parse inline comment
11861 (unless comment
11862 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11863 (match-string-no-properties 1))))
11864 ;; save everything in list
11865 (setq param-list (append param-list
11866 (list (list names object direct type init
11867 comment group-comment))))
11868 ;; parse group comment and spacing
11869 (setq group-comment (vhdl-parse-group-comment)))
11870 (message "Reading interface of subprogram \"%s\"...done" name)
11871 nil)))
11872 ;; finish parsing
11873 (if parse-error
11874 (error parse-error)
11875 (setq vhdl-subprog-list
11876 (list name kind param-list return-type return-comment
11877 return-group-comment)
11878 vhdl-subprog-flattened nil)))))
11880 (defun vhdl-subprog-paste-specification (kind)
11881 "Paste as a subprogram specification."
11882 (indent-according-to-mode)
11883 (let ((margin (current-column))
11884 (param-list (nth 2 vhdl-subprog-list))
11885 list-margin start names param)
11886 ;; paste keyword and name
11887 (vhdl-insert-keyword
11888 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11889 (insert (nth 0 vhdl-subprog-list))
11890 (if (not param-list)
11891 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11892 (setq start (point))
11893 ;; paste parameter list
11894 (insert " (")
11895 (unless vhdl-argument-list-indent
11896 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11897 (setq list-margin (current-column))
11898 (while param-list
11899 (setq param (car param-list))
11900 ;; paste group comment and spacing
11901 (when (memq vhdl-include-group-comments (list kind 'always))
11902 (vhdl-paste-group-comment (nth 6 param) list-margin))
11903 ;; paste object
11904 (when (nth 1 param) (insert (nth 1 param) " "))
11905 ;; paste names
11906 (setq names (nth 0 param))
11907 (while names
11908 (insert (car names))
11909 (setq names (cdr names))
11910 (when names (insert ", ")))
11911 ;; paste direction
11912 (insert " : ")
11913 (when (nth 2 param) (insert (nth 2 param) " "))
11914 ;; paste type
11915 (insert (nth 3 param))
11916 ;; paste initialization
11917 (when (nth 4 param) (insert " := " (nth 4 param)))
11918 ;; terminate line
11919 (if (cdr param-list)
11920 (insert ";")
11921 (insert ")")
11922 (when (null (nth 3 vhdl-subprog-list))
11923 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11924 ;; paste comment
11925 (when (and vhdl-include-port-comments (nth 5 param))
11926 (vhdl-comment-insert-inline (nth 5 param) t))
11927 (setq param-list (cdr param-list))
11928 (when param-list (insert "\n") (indent-to list-margin)))
11929 (when (nth 3 vhdl-subprog-list)
11930 (insert "\n") (indent-to list-margin)
11931 ;; paste group comment and spacing
11932 (when (memq vhdl-include-group-comments (list kind 'always))
11933 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11934 ;; paste return type
11935 (insert "return " (nth 3 vhdl-subprog-list))
11936 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11937 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11938 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11939 ;; align parameter list
11940 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11941 ;; paste body
11942 (when (eq kind 'body)
11943 (insert "\n")
11944 (vhdl-template-begin-end
11945 (unless (vhdl-standard-p '87)
11946 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11947 (nth 0 vhdl-subprog-list) margin))))
11949 (defun vhdl-subprog-paste-declaration ()
11950 "Paste as a subprogram declaration."
11951 (interactive)
11952 (if (not vhdl-subprog-list)
11953 (error "ERROR: No subprogram interface read")
11954 (message "Pasting interface as subprogram declaration \"%s\"..."
11955 (car vhdl-subprog-list))
11956 ;; paste specification
11957 (vhdl-subprog-paste-specification 'decl)
11958 (message "Pasting interface as subprogram declaration \"%s\"...done"
11959 (car vhdl-subprog-list))))
11961 (defun vhdl-subprog-paste-body ()
11962 "Paste as a subprogram body."
11963 (interactive)
11964 (if (not vhdl-subprog-list)
11965 (error "ERROR: No subprogram interface read")
11966 (message "Pasting interface as subprogram body \"%s\"..."
11967 (car vhdl-subprog-list))
11968 ;; paste specification and body
11969 (vhdl-subprog-paste-specification 'body)
11970 (message "Pasting interface as subprogram body \"%s\"...done"
11971 (car vhdl-subprog-list))))
11973 (defun vhdl-subprog-paste-call ()
11974 "Paste as a subprogram call."
11975 (interactive)
11976 (if (not vhdl-subprog-list)
11977 (error "ERROR: No subprogram interface read")
11978 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11979 param-list margin list-margin param start)
11980 ;; flatten local copy of interface list (must be flat for parameter mapping)
11981 (vhdl-subprog-flatten)
11982 (setq param-list (nth 2 vhdl-subprog-list))
11983 (indent-according-to-mode)
11984 (setq margin (current-indentation))
11985 (message "Pasting interface as subprogram call \"%s\"..."
11986 (car vhdl-subprog-list))
11987 ;; paste name
11988 (insert (nth 0 vhdl-subprog-list))
11989 (if (not param-list)
11990 (insert ";")
11991 (setq start (point))
11992 ;; paste parameter list
11993 (insert " (")
11994 (unless vhdl-argument-list-indent
11995 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11996 (setq list-margin (current-column))
11997 (while param-list
11998 (setq param (car param-list))
11999 ;; paste group comment and spacing
12000 (when (eq vhdl-include-group-comments 'always)
12001 (vhdl-paste-group-comment (nth 6 param) list-margin))
12002 ;; paste formal port
12003 (insert (car (nth 0 param)) " => ")
12004 (setq param-list (cdr param-list))
12005 (insert (if param-list "," ");"))
12006 ;; paste comment
12007 (when (and vhdl-include-port-comments (nth 5 param))
12008 (vhdl-comment-insert-inline (nth 5 param)))
12009 (when param-list (insert "\n") (indent-to list-margin)))
12010 ;; align parameter list
12011 (when vhdl-auto-align
12012 (vhdl-align-region-groups start (point) 1)))
12013 (message "Pasting interface as subprogram call \"%s\"...done"
12014 (car vhdl-subprog-list))
12015 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12019 ;;; Miscellaneous
12020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12022 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12023 ;; Hippie expand customization
12025 (defvar vhdl-expand-upper-case nil)
12027 (defun vhdl-try-expand-abbrev (old)
12028 "Try expanding abbreviations from `vhdl-abbrev-list'."
12029 (unless old
12030 (he-init-string (he-dabbrev-beg) (point))
12031 (setq he-expand-list
12032 (let ((abbrev-list vhdl-abbrev-list)
12033 (sel-abbrev-list '()))
12034 (while abbrev-list
12035 (when (or (not (stringp (car abbrev-list)))
12036 (string-match
12037 (concat "^" he-search-string) (car abbrev-list)))
12038 (setq sel-abbrev-list
12039 (cons (car abbrev-list) sel-abbrev-list)))
12040 (setq abbrev-list (cdr abbrev-list)))
12041 (nreverse sel-abbrev-list))))
12042 (while (and he-expand-list
12043 (or (not (stringp (car he-expand-list)))
12044 (he-string-member (car he-expand-list) he-tried-table t)))
12045 ; (equal (car he-expand-list) he-search-string)))
12046 (unless (stringp (car he-expand-list))
12047 (setq vhdl-expand-upper-case (car he-expand-list)))
12048 (setq he-expand-list (cdr he-expand-list)))
12049 (if (null he-expand-list)
12050 (progn (when old (he-reset-string))
12051 nil)
12052 (he-substitute-string
12053 (if vhdl-expand-upper-case
12054 (upcase (car he-expand-list))
12055 (car he-expand-list))
12057 (setq he-expand-list (cdr he-expand-list))
12060 (defun vhdl-he-list-beg ()
12061 "Also looks at the word before `(' in order to better match parenthesized
12062 expressions (e.g. for index ranges of types and signals)."
12063 (save-excursion
12064 (condition-case ()
12065 (progn (backward-up-list 1)
12066 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12067 (error ()))
12068 (point)))
12070 ;; override `he-list-beg' from `hippie-exp'
12071 (unless (and (boundp 'viper-mode) viper-mode)
12072 (defalias 'he-list-beg 'vhdl-he-list-beg))
12074 ;; function for expanding abbrevs and dabbrevs
12075 (defun vhdl-expand-abbrev (arg))
12076 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
12077 '(try-expand-dabbrev
12078 try-expand-dabbrev-all-buffers
12079 vhdl-try-expand-abbrev)))
12081 ;; function for expanding parenthesis
12082 (defun vhdl-expand-paren (arg))
12083 (fset 'vhdl-expand-paren (make-hippie-expand-function
12084 '(try-expand-list
12085 try-expand-list-all-buffers)))
12087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12088 ;; Case fixing
12090 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12091 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12092 depending on parameter UPPER-CASE."
12093 (let ((case-replace nil)
12094 (last-update 0))
12095 (vhdl-prepare-search-2
12096 (save-excursion
12097 (goto-char end)
12098 (setq end (point-marker))
12099 (goto-char beg)
12100 (while (re-search-forward word-regexp end t)
12101 (or (vhdl-in-literal)
12102 (if upper-case
12103 (upcase-word -1)
12104 (downcase-word -1)))
12105 (when (and count vhdl-progress-interval (not noninteractive)
12106 (< vhdl-progress-interval
12107 (- (nth 1 (current-time)) last-update)))
12108 (message "Fixing case... (%2d%s)"
12109 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12110 "%")
12111 (setq last-update (nth 1 (current-time)))))
12112 (goto-char end)))))
12114 (defun vhdl-fix-case-region (beg end &optional arg)
12115 "Convert all VHDL words in region to lower or upper case, depending on
12116 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12117 (interactive "r\nP")
12118 (vhdl-fix-case-region-1
12119 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12120 (vhdl-fix-case-region-1
12121 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12122 (vhdl-fix-case-region-1
12123 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12124 (vhdl-fix-case-region-1
12125 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12126 (when vhdl-progress-interval (message "Fixing case...done")))
12128 (defun vhdl-fix-case-buffer ()
12129 "Convert all VHDL words in buffer to lower or upper case, depending on
12130 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12131 (interactive)
12132 (vhdl-fix-case-region (point-min) (point-max)))
12134 (defun vhdl-fix-case-word (&optional arg)
12135 "Convert word after cursor to upper case if necessary."
12136 (interactive "p")
12137 (save-excursion
12138 (when arg (backward-word 1))
12139 (vhdl-prepare-search-1
12140 (when (and vhdl-upper-case-keywords
12141 (looking-at vhdl-keywords-regexp))
12142 (upcase-word 1))
12143 (when (and vhdl-upper-case-types
12144 (looking-at vhdl-types-regexp))
12145 (upcase-word 1))
12146 (when (and vhdl-upper-case-attributes
12147 (looking-at vhdl-attributes-regexp))
12148 (upcase-word 1))
12149 (when (and vhdl-upper-case-enum-values
12150 (looking-at vhdl-enum-values-regexp))
12151 (upcase-word 1)))))
12153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12154 ;; Line handling functions
12156 (defun vhdl-current-line ()
12157 "Return the line number of the line containing point."
12158 (save-restriction
12159 (widen)
12160 (save-excursion
12161 (beginning-of-line)
12162 (1+ (count-lines 1 (point))))))
12164 (defun vhdl-line-kill-entire (&optional arg)
12165 "Delete entire line."
12166 (interactive "p")
12167 (beginning-of-line)
12168 (kill-line (or arg 1)))
12170 (defun vhdl-line-kill (&optional arg)
12171 "Kill current line."
12172 (interactive "p")
12173 (vhdl-line-kill-entire arg))
12175 (defun vhdl-line-copy (&optional arg)
12176 "Copy current line."
12177 (interactive "p")
12178 (save-excursion
12179 (beginning-of-line)
12180 (let ((position (point)))
12181 (forward-line (or arg 1))
12182 (copy-region-as-kill position (point)))))
12184 (defun vhdl-line-yank ()
12185 "Yank entire line."
12186 (interactive)
12187 (beginning-of-line)
12188 (yank))
12190 (defun vhdl-line-expand (&optional prefix-arg)
12191 "Hippie-expand current line."
12192 (interactive "P")
12193 (let ((case-fold-search t) (case-replace nil)
12194 (hippie-expand-try-functions-list
12195 '(try-expand-line try-expand-line-all-buffers)))
12196 (hippie-expand prefix-arg)))
12198 (defun vhdl-line-transpose-next (&optional arg)
12199 "Interchange this line with next line."
12200 (interactive "p")
12201 (forward-line 1)
12202 (transpose-lines (or arg 1))
12203 (forward-line -1))
12205 (defun vhdl-line-transpose-previous (&optional arg)
12206 "Interchange this line with previous line."
12207 (interactive "p")
12208 (forward-line 1)
12209 (transpose-lines (- 0 (or arg 0)))
12210 (forward-line -1))
12212 (defun vhdl-line-open ()
12213 "Open a new line and indent."
12214 (interactive)
12215 (end-of-line -0)
12216 (newline-and-indent))
12218 (defun vhdl-delete-indentation ()
12219 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12220 it works within comments too."
12221 (interactive)
12222 (let ((fill-prefix "-- "))
12223 (delete-indentation)))
12225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12226 ;; Move functions
12228 (defun vhdl-forward-same-indent ()
12229 "Move forward to next line with same indent."
12230 (interactive)
12231 (let ((pos (point))
12232 (indent (current-indentation)))
12233 (beginning-of-line 2)
12234 (while (and (not (eobp))
12235 (or (looking-at "^\\s-*\\(--.*\\)?$")
12236 (> (current-indentation) indent)))
12237 (beginning-of-line 2))
12238 (if (= (current-indentation) indent)
12239 (back-to-indentation)
12240 (message "No following line with same indent found in this block")
12241 (goto-char pos)
12242 nil)))
12244 (defun vhdl-backward-same-indent ()
12245 "Move backward to previous line with same indent."
12246 (interactive)
12247 (let ((pos (point))
12248 (indent (current-indentation)))
12249 (beginning-of-line -0)
12250 (while (and (not (bobp))
12251 (or (looking-at "^\\s-*\\(--.*\\)?$")
12252 (> (current-indentation) indent)))
12253 (beginning-of-line -0))
12254 (if (= (current-indentation) indent)
12255 (back-to-indentation)
12256 (message "No preceding line with same indent found in this block")
12257 (goto-char pos)
12258 nil)))
12260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12261 ;; Statistics
12263 (defun vhdl-statistics-buffer ()
12264 "Get some file statistics."
12265 (interactive)
12266 (let ((no-stats 0)
12267 (no-code-lines 0)
12268 (no-lines (count-lines (point-min) (point-max))))
12269 (save-excursion
12270 ;; count statements
12271 (goto-char (point-min))
12272 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12273 (if (match-string 1)
12274 (goto-char (match-end 1))
12275 (setq no-stats (1+ no-stats))))
12276 ;; count code lines
12277 (goto-char (point-min))
12278 (while (not (eobp))
12279 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12280 (setq no-code-lines (1+ no-code-lines)))
12281 (beginning-of-line 2)))
12282 ;; print results
12283 (message "\n\
12284 File statistics: \"%s\"\n\
12285 ---------------------\n\
12286 # statements : %5d\n\
12287 # code lines : %5d\n\
12288 # total lines : %5d\n\ "
12289 (buffer-file-name) no-stats no-code-lines no-lines)
12290 (unless vhdl-emacs-21 (vhdl-show-messages))))
12292 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12293 ;; Help functions
12295 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12296 "Like `re-search-forward', but does not match within literals."
12297 (let (pos)
12298 (save-excursion
12299 (while (and (setq pos (re-search-forward regexp bound noerror count))
12300 (vhdl-in-literal))))
12301 (when pos (goto-char pos))
12302 pos))
12304 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12305 "Like `re-search-backward', but does not match within literals."
12306 (let (pos)
12307 (save-excursion
12308 (while (and (setq pos (re-search-backward regexp bound noerror count))
12309 (vhdl-in-literal))))
12310 (when pos (goto-char pos))
12311 pos))
12314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12315 ;;; Project
12316 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12318 (defun vhdl-set-project (name)
12319 "Set current project to NAME."
12320 (interactive
12321 (list (let ((completion-ignore-case t))
12322 (completing-read "Project name: " vhdl-project-alist nil t))))
12323 (cond ((equal name "")
12324 (setq vhdl-project nil)
12325 (message "Current VHDL project: None"))
12326 ((assoc name vhdl-project-alist)
12327 (setq vhdl-project name)
12328 (message "Current VHDL project: \"%s\"" name))
12330 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12331 (vhdl-speedbar-update-current-project))
12333 (defun vhdl-set-default-project ()
12334 "Set current project as default on startup."
12335 (interactive)
12336 (customize-set-variable 'vhdl-project vhdl-project)
12337 (customize-save-customized))
12339 (defun vhdl-toggle-project (name token indent)
12340 "Set current project to NAME or unset if NAME is current project."
12341 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12343 (defun vhdl-export-project (file-name)
12344 "Write project setup for current project."
12345 (interactive
12346 (let ((name (vhdl-resolve-env-variable
12347 (vhdl-replace-string
12348 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12349 (concat (subst-char-in-string
12350 ? ?_ (or (vhdl-project-p)
12351 (error "ERROR: No current project")))
12352 " " (user-login-name))))))
12353 (list (read-file-name
12354 "Write project file: "
12355 (when (file-name-absolute-p name) "") nil nil name))))
12356 (setq file-name (abbreviate-file-name file-name))
12357 (let ((orig-buffer (current-buffer)))
12358 (unless (file-exists-p (file-name-directory file-name))
12359 (make-directory (file-name-directory file-name) t))
12360 (if (not (file-writable-p file-name))
12361 (error "ERROR: File not writable: \"%s\"" file-name)
12362 (set-buffer (find-file-noselect file-name t t))
12363 (erase-buffer)
12364 (insert ";; -*- Emacs-Lisp -*-\n\n"
12365 ";;; " (file-name-nondirectory file-name)
12366 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12367 ";; Project : " vhdl-project "\n"
12368 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12369 (user-login-name) "\n\n\n"
12370 ";; project name\n"
12371 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12372 ";; project setup\n"
12373 "(aput 'vhdl-project-alist vhdl-project\n'")
12374 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12375 (insert ")\n")
12376 (save-buffer)
12377 (kill-buffer (current-buffer))
12378 (set-buffer orig-buffer))))
12380 (defun vhdl-import-project (file-name &optional auto not-make-current)
12381 "Read project setup and set current project."
12382 (interactive
12383 (let ((name (vhdl-resolve-env-variable
12384 (vhdl-replace-string
12385 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12386 (concat "" " " (user-login-name))))))
12387 (list (read-file-name
12388 "Read project file: " (when (file-name-absolute-p name) "") nil t
12389 (file-name-directory name)))))
12390 (when (file-exists-p file-name)
12391 (condition-case ()
12392 (let ((current-project vhdl-project))
12393 (load-file file-name)
12394 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12395 (adelete 'vhdl-project-alist vhdl-project)
12396 (error ""))
12397 (when not-make-current
12398 (setq vhdl-project current-project))
12399 (vhdl-update-mode-menu)
12400 (vhdl-speedbar-refresh)
12401 (unless not-make-current
12402 (message "Current VHDL project: \"%s\"%s"
12403 vhdl-project (if auto " (auto-loaded)" ""))))
12404 (error (vhdl-warning
12405 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12407 (defun vhdl-duplicate-project ()
12408 "Duplicate setup of current project."
12409 (interactive)
12410 (let ((new-name (read-from-minibuffer "New project name: "))
12411 (project-entry (aget vhdl-project-alist vhdl-project t)))
12412 (setq vhdl-project-alist
12413 (append vhdl-project-alist
12414 (list (cons new-name project-entry))))
12415 (vhdl-update-mode-menu)))
12417 (defun vhdl-auto-load-project ()
12418 "Automatically load project setup at startup."
12419 (let ((file-name-list vhdl-project-file-name)
12420 file-list list-length)
12421 (while file-name-list
12422 (setq file-list
12423 (append file-list
12424 (file-expand-wildcards
12425 (vhdl-resolve-env-variable
12426 (vhdl-replace-string
12427 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12428 (concat "\*" " " (user-login-name)))))))
12429 (setq list-length (or list-length (length file-list)))
12430 (setq file-name-list (cdr file-name-list)))
12431 (while file-list
12432 (vhdl-import-project (expand-file-name (car file-list)) t
12433 (not (> list-length 0)))
12434 (setq list-length (1- list-length))
12435 (setq file-list (cdr file-list)))))
12437 ;; automatically load project setup when idle after startup
12438 (when (memq 'startup vhdl-project-auto-load)
12439 (if noninteractive
12440 (vhdl-auto-load-project)
12441 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12445 ;;; Hideshow
12446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12447 ;; (using `hideshow.el')
12449 (defconst vhdl-hs-start-regexp
12450 (concat
12451 "\\(^\\)\\s-*\\("
12452 ;; generic/port clause
12453 "\\(generic\\|port\\)[ \t\n]*(\\|"
12454 ;; component
12455 "component\\>\\|"
12456 ;; component instantiation
12457 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12458 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12459 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12460 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12461 ;; subprogram
12462 "\\(function\\|procedure\\)\\>\\|"
12463 ;; process, block
12464 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12465 ;; configuration declaration
12466 "configuration\\>"
12467 "\\)")
12468 "Regexp to match start of construct to hide.")
12470 (defun vhdl-hs-forward-sexp-func (count)
12471 "Find end of construct to hide (for hideshow). Only searches forward."
12472 (let ((pos (point)))
12473 (vhdl-prepare-search-2
12474 (beginning-of-line)
12475 (cond
12476 ;; generic/port clause
12477 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12478 (goto-char (match-end 0))
12479 (backward-char)
12480 (forward-sexp))
12481 ;; component declaration
12482 ((looking-at "^\\s-*component\\>")
12483 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12484 ;; component instantiation
12485 ((looking-at
12486 (concat
12487 "^\\s-*\\w+\\s-*:[ \t\n]*"
12488 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12489 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12490 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12491 (goto-char (match-end 0))
12492 (backward-char)
12493 (forward-sexp)
12494 (setq pos (point))
12495 (vhdl-forward-syntactic-ws)
12496 (when (looking-at "port\\s-+map[ \t\n]*(")
12497 (goto-char (match-end 0))
12498 (backward-char)
12499 (forward-sexp)
12500 (setq pos (point)))
12501 (goto-char pos))
12502 ;; subprogram declaration/body
12503 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12504 (goto-char (match-end 0))
12505 (vhdl-forward-syntactic-ws)
12506 (when (looking-at "(")
12507 (forward-sexp))
12508 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12509 (vhdl-in-literal)))
12510 ;; subprogram body
12511 (when (match-string 2)
12512 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12513 (backward-word 1)
12514 (vhdl-forward-sexp)))
12515 ;; block (recursive)
12516 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12517 (goto-char (match-end 0))
12518 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12519 (match-beginning 2))
12520 (vhdl-hs-forward-sexp-func count)))
12521 ;; process
12522 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12523 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12524 ;; configuration declaration
12525 ((looking-at "^\\s-*configuration\\>")
12526 (forward-word 4)
12527 (vhdl-forward-sexp))
12528 (t (goto-char pos))))))
12530 (defun vhdl-hideshow-init ()
12531 "Initialize `hideshow'."
12532 (when vhdl-hideshow-menu
12533 (vhdl-hs-minor-mode 1)))
12535 (defun vhdl-hs-minor-mode (&optional arg)
12536 "Toggle hideshow minor mode and update menu bar."
12537 (interactive "P")
12538 (require 'hideshow)
12539 ;; check for hideshow version 5.x
12540 (if (not (boundp 'hs-block-start-mdata-select))
12541 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12542 ;; initialize hideshow
12543 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12544 (setq hs-special-modes-alist
12545 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12546 'vhdl-hs-forward-sexp-func nil)
12547 hs-special-modes-alist)))
12548 (make-local-variable 'hs-minor-mode-hook)
12549 (if vhdl-hide-all-init
12550 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12551 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12552 (hs-minor-mode arg)
12553 (vhdl-mode-line-update))) ; hack to update menu bar
12556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12557 ;;; Font locking
12558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12559 ;; (using `font-lock.el')
12561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12562 ;; Help functions
12564 (defun vhdl-within-translate-off ()
12565 "Return point if within translate-off region, else nil."
12566 (and (save-excursion
12567 (re-search-backward
12568 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12569 (equal "off" (match-string 1))
12570 (point)))
12572 (defun vhdl-start-translate-off (limit)
12573 "Return point before translate-off pragma if before LIMIT, else nil."
12574 (when (re-search-forward
12575 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12576 (match-beginning 0)))
12578 (defun vhdl-end-translate-off (limit)
12579 "Return point after translate-on pragma if before LIMIT, else nil."
12580 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12582 (defun vhdl-match-translate-off (limit)
12583 "Match a translate-off block, setting match-data and returning t, else nil."
12584 (when (< (point) limit)
12585 (let ((start (or (vhdl-within-translate-off)
12586 (vhdl-start-translate-off limit)))
12587 (case-fold-search t))
12588 (when start
12589 (let ((end (or (vhdl-end-translate-off limit) limit)))
12590 (set-match-data (list start end))
12591 (goto-char end))))))
12593 (defun vhdl-font-lock-match-item (limit)
12594 "Match, and move over, any declaration item after point. Adapted from
12595 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12596 (condition-case nil
12597 (save-restriction
12598 (narrow-to-region (point-min) limit)
12599 ;; match item
12600 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12601 (save-match-data
12602 (goto-char (match-end 1))
12603 ;; move to next item
12604 (if (looking-at "\\(\\s-*,\\)")
12605 (goto-char (match-end 1))
12606 (end-of-line) t))))
12607 (error t)))
12609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12610 ;; Syntax definitions
12612 (defconst vhdl-font-lock-syntactic-keywords
12613 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12614 "Mark single quotes as having string quote syntax in 'c' instances.")
12616 (defvar vhdl-font-lock-keywords nil
12617 "Regular expressions to highlight in VHDL Mode.")
12619 (defvar vhdl-font-lock-keywords-0
12620 ;; set in `vhdl-font-lock-init' because dependent on user options
12621 "For consideration as a value of `vhdl-font-lock-keywords'.
12622 This does highlighting of template prompts and directives (pragmas).")
12624 (defvar vhdl-font-lock-keywords-1 nil
12625 ;; set in `vhdl-font-lock-init' because dependent on user options
12626 "For consideration as a value of `vhdl-font-lock-keywords'.
12627 This does highlighting of keywords and standard identifiers.")
12629 (defconst vhdl-font-lock-keywords-2
12630 (list
12631 ;; highlight names of units, subprograms, and components when declared
12632 (list
12633 (concat
12634 "^\\s-*\\("
12635 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12636 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12637 "\\)\\s-+\\(\\w+\\)")
12638 5 'font-lock-function-name-face)
12640 ;; highlight entity names of architectures and configurations
12641 (list
12642 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12643 2 'font-lock-function-name-face)
12645 ;; highlight labels of common constructs
12646 (list
12647 (concat
12648 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12649 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12650 "postponed\\|process\\|"
12651 (when (vhdl-standard-p 'ams) "procedural\\|")
12652 "with\\|while"
12653 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
12654 1 'font-lock-function-name-face)
12656 ;; highlight label and component name of component instantiations
12657 (list
12658 (concat
12659 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12660 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12661 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12663 ;; highlight label and instantiated unit of component instantiations
12664 (list
12665 (concat
12666 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12667 "\\(component\\|configuration\\|entity\\)\\s-+"
12668 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12669 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12670 '(5 font-lock-function-name-face nil t)
12671 '(7 font-lock-function-name-face nil t))
12673 ;; highlight names and labels at end of constructs
12674 (list
12675 (concat
12676 "^\\s-*end\\s-+\\(\\("
12677 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12678 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12679 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12680 (when (vhdl-standard-p 'ams) "procedural\\|")
12681 "units"
12682 "\\)\\s-+\\)?\\(\\w*\\)")
12683 5 'font-lock-function-name-face)
12685 ;; highlight labels in exit and next statements
12686 (list
12687 (concat
12688 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12689 3 'font-lock-function-name-face)
12691 ;; highlight entity name in attribute specifications
12692 (list
12693 (concat
12694 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12695 1 'font-lock-function-name-face)
12697 ;; highlight labels in block and component specifications
12698 (list
12699 (concat
12700 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12701 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12702 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12704 ;; highlight names in library clauses
12705 (list "^\\s-*library\\>"
12706 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12708 ;; highlight names in use clauses
12709 (list
12710 (concat
12711 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12712 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12713 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12714 '(7 font-lock-function-name-face nil t))
12716 ;; highlight attribute name in attribute declarations/specifications
12717 (list
12718 (concat
12719 "^\\s-*attribute\\s-+\\(\\w+\\)")
12720 1 'vhdl-font-lock-attribute-face)
12722 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12723 (list
12724 (concat
12725 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12726 3 'font-lock-type-face)
12728 ;; highlight signal/variable/constant declaration names
12729 (list "\\(:[^=]\\)"
12730 '(vhdl-font-lock-match-item
12731 (progn (goto-char (match-beginning 1))
12732 (skip-syntax-backward " ")
12733 (skip-syntax-backward "w_")
12734 (skip-syntax-backward " ")
12735 (while (= (preceding-char) ?,)
12736 (backward-char 1)
12737 (skip-syntax-backward " ")
12738 (skip-syntax-backward "w_")
12739 (skip-syntax-backward " ")))
12740 ; (skip-chars-backward "^-(\n\";")
12741 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12743 ;; highlight formal parameters in component instantiations and subprogram
12744 ;; calls
12745 (list "\\(=>\\)"
12746 '(vhdl-font-lock-match-item
12747 (progn (goto-char (match-beginning 1))
12748 (skip-syntax-backward " ")
12749 (while (= (preceding-char) ?\)) (backward-sexp))
12750 (skip-syntax-backward "w_")
12751 (skip-syntax-backward " ")
12752 (when (memq (preceding-char) '(?n ?N ?|))
12753 (goto-char (point-max))))
12754 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12756 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12757 ;; variables
12758 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12759 '(vhdl-font-lock-match-item
12760 (progn (goto-char (match-end 1)) (match-beginning 2))
12761 nil (1 font-lock-variable-name-face)))
12763 "For consideration as a value of `vhdl-font-lock-keywords'.
12764 This does context sensitive highlighting of names and labels.")
12766 (defvar vhdl-font-lock-keywords-3 nil
12767 ;; set in `vhdl-font-lock-init' because dependent on user options
12768 "For consideration as a value of `vhdl-font-lock-keywords'.
12769 This does highlighting of words with special syntax.")
12771 (defvar vhdl-font-lock-keywords-4 nil
12772 ;; set in `vhdl-font-lock-init' because dependent on user options
12773 "For consideration as a value of `vhdl-font-lock-keywords'.
12774 This does highlighting of additional reserved words.")
12776 (defconst vhdl-font-lock-keywords-5
12777 ;; background highlight translate-off regions
12778 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12779 "For consideration as a value of `vhdl-font-lock-keywords'.
12780 This does background highlighting of translate-off regions.")
12782 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12783 ;; Font and color definitions
12785 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12786 "Face name to use for prompts.")
12788 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12789 "Face name to use for standardized attributes.")
12791 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12792 "Face name to use for standardized enumeration values.")
12794 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12795 "Face name to use for standardized functions and packages.")
12797 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12798 "Face name to use for directives.")
12800 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12801 "Face name to use for additional reserved words.")
12803 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12804 "Face name to use for translate-off regions.")
12806 ;; face names to use for words with special syntax.
12807 (let ((syntax-alist vhdl-special-syntax-alist)
12808 name)
12809 (while syntax-alist
12810 (setq name (vhdl-function-name
12811 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12812 (eval `(defvar ,name ',name
12813 ,(concat "Face name to use for "
12814 (nth 0 (car syntax-alist)) ".")))
12815 (setq syntax-alist (cdr syntax-alist))))
12817 (defgroup vhdl-highlight-faces nil
12818 "Faces for highlighting."
12819 :group 'vhdl-highlight)
12821 ;; add faces used from `font-lock'
12822 (custom-add-to-group
12823 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12824 (custom-add-to-group
12825 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12826 (custom-add-to-group
12827 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12828 (custom-add-to-group
12829 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12830 (custom-add-to-group
12831 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12832 (custom-add-to-group
12833 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12835 (defface vhdl-font-lock-prompt-face
12836 '((((min-colors 88) (class color) (background light))
12837 (:foreground "Red1" :bold t))
12838 (((class color) (background light)) (:foreground "Red" :bold t))
12839 (((class color) (background dark)) (:foreground "Pink" :bold t))
12840 (t (:inverse-video t)))
12841 "Font lock mode face used to highlight prompts."
12842 :group 'vhdl-highlight-faces)
12844 (defface vhdl-font-lock-attribute-face
12845 '((((class color) (background light)) (:foreground "Orchid"))
12846 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12847 (t (:italic t :bold t)))
12848 "Font lock mode face used to highlight standardized attributes."
12849 :group 'vhdl-highlight-faces)
12851 (defface vhdl-font-lock-enumvalue-face
12852 '((((class color) (background light)) (:foreground "SaddleBrown"))
12853 (((class color) (background dark)) (:foreground "BurlyWood"))
12854 (t (:italic t :bold t)))
12855 "Font lock mode face used to highlight standardized enumeration values."
12856 :group 'vhdl-highlight-faces)
12858 (defface vhdl-font-lock-function-face
12859 '((((class color) (background light)) (:foreground "Cyan4"))
12860 (((class color) (background dark)) (:foreground "Orchid1"))
12861 (t (:italic t :bold t)))
12862 "Font lock mode face used to highlight standardized functions and packages."
12863 :group 'vhdl-highlight-faces)
12865 (defface vhdl-font-lock-directive-face
12866 '((((class color) (background light)) (:foreground "CadetBlue"))
12867 (((class color) (background dark)) (:foreground "Aquamarine"))
12868 (t (:italic t :bold t)))
12869 "Font lock mode face used to highlight directives."
12870 :group 'vhdl-highlight-faces)
12872 (defface vhdl-font-lock-reserved-words-face
12873 '((((class color) (background light)) (:foreground "Orange" :bold t))
12874 (((min-colors 88) (class color) (background dark))
12875 (:foreground "Yellow1" :bold t))
12876 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12877 (t ()))
12878 "Font lock mode face used to highlight additional reserved words."
12879 :group 'vhdl-highlight-faces)
12881 (defface vhdl-font-lock-translate-off-face
12882 '((((class color) (background light)) (:background "LightGray"))
12883 (((class color) (background dark)) (:background "DimGray"))
12884 (t ()))
12885 "Font lock mode face used to background highlight translate-off regions."
12886 :group 'vhdl-highlight-faces)
12888 ;; font lock mode faces used to highlight words with special syntax.
12889 (let ((syntax-alist vhdl-special-syntax-alist))
12890 (while syntax-alist
12891 (eval `(defface ,(vhdl-function-name
12892 "vhdl-font-lock" (caar syntax-alist) "face")
12893 '((((class color) (background light))
12894 (:foreground ,(nth 2 (car syntax-alist))))
12895 (((class color) (background dark))
12896 (:foreground ,(nth 3 (car syntax-alist))))
12897 (t ()))
12898 ,(concat "Font lock mode face used to highlight "
12899 (nth 0 (car syntax-alist)) ".")
12900 :group 'vhdl-highlight-faces))
12901 (setq syntax-alist (cdr syntax-alist))))
12903 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12904 ;; Font lock initialization
12906 (defun vhdl-font-lock-init ()
12907 "Initialize fontification."
12908 ;; highlight template prompts and directives
12909 (setq vhdl-font-lock-keywords-0
12910 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12911 vhdl-template-prompt-syntax ">\\)")
12912 2 'vhdl-font-lock-prompt-face t)
12913 (list (concat "--\\s-*"
12914 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12915 2 'vhdl-font-lock-directive-face t)
12916 ;; highlight c-preprocessor directives
12917 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12918 '(1 font-lock-builtin-face)
12919 '(3 font-lock-variable-name-face nil t))))
12920 ;; highlight keywords and standardized types, attributes, enumeration
12921 ;; values, and subprograms
12922 (setq vhdl-font-lock-keywords-1
12923 (list
12924 (list (concat "'" vhdl-attributes-regexp)
12925 1 'vhdl-font-lock-attribute-face)
12926 (list vhdl-types-regexp 1 'font-lock-type-face)
12927 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12928 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12929 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12930 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12931 ;; highlight words with special syntax.
12932 (setq vhdl-font-lock-keywords-3
12933 (let ((syntax-alist vhdl-special-syntax-alist)
12934 keywords)
12935 (while syntax-alist
12936 (setq keywords
12937 (cons
12938 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12939 (vhdl-function-name
12940 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12941 keywords))
12942 (setq syntax-alist (cdr syntax-alist)))
12943 keywords))
12944 ;; highlight additional reserved words
12945 (setq vhdl-font-lock-keywords-4
12946 (list (list vhdl-reserved-words-regexp 1
12947 'vhdl-font-lock-reserved-words-face)))
12948 ;; highlight everything together
12949 (setq vhdl-font-lock-keywords
12950 (append
12951 vhdl-font-lock-keywords-0
12952 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12953 (when (or vhdl-highlight-forbidden-words
12954 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12955 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12956 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12957 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12959 ;; initialize fontification for VHDL Mode
12960 (vhdl-font-lock-init)
12962 (defun vhdl-fontify-buffer ()
12963 "Re-initialize fontification and fontify buffer."
12964 (interactive)
12965 (setq font-lock-defaults
12966 (list
12967 'vhdl-font-lock-keywords nil
12968 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12969 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12970 (when (fboundp 'font-lock-unset-defaults)
12971 (font-lock-unset-defaults)) ; not implemented in XEmacs
12972 (font-lock-set-defaults)
12973 (font-lock-mode nil)
12974 (font-lock-mode t))
12976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12977 ;; Initialization for postscript printing
12979 (defun vhdl-ps-print-settings ()
12980 "Initialize custom face and page settings for postscript printing."
12981 ;; define custom face settings
12982 (unless (or (not vhdl-print-customize-faces)
12983 ps-print-color-p)
12984 (set (make-local-variable 'ps-bold-faces)
12985 '(font-lock-keyword-face
12986 font-lock-type-face
12987 vhdl-font-lock-attribute-face
12988 vhdl-font-lock-enumvalue-face
12989 vhdl-font-lock-directive-face))
12990 (set (make-local-variable 'ps-italic-faces)
12991 '(font-lock-comment-face
12992 font-lock-function-name-face
12993 font-lock-type-face
12994 vhdl-font-lock-attribute-face
12995 vhdl-font-lock-enumvalue-face
12996 vhdl-font-lock-directive-face))
12997 (set (make-local-variable 'ps-underlined-faces)
12998 '(font-lock-string-face))
12999 (setq ps-always-build-face-reference t))
13000 ;; define page settings, so that a line containing 79 characters (default)
13001 ;; fits into one column
13002 (when vhdl-print-two-column
13003 (set (make-local-variable 'ps-landscape-mode) t)
13004 (set (make-local-variable 'ps-number-of-columns) 2)
13005 (set (make-local-variable 'ps-font-size) 7.0)
13006 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13007 (set (make-local-variable 'ps-header-font-size) 9.0)
13008 (set (make-local-variable 'ps-header-offset) 12.0)
13009 (when (eq ps-paper-type 'letter)
13010 (set (make-local-variable 'ps-inter-column) 40.0)
13011 (set (make-local-variable 'ps-left-margin) 40.0)
13012 (set (make-local-variable 'ps-right-margin) 40.0))))
13014 (defun vhdl-ps-print-init ()
13015 "Initialize postscript printing."
13016 (if vhdl-xemacs
13017 (when (boundp 'ps-print-color-p)
13018 (vhdl-ps-print-settings))
13019 (make-local-variable 'ps-print-hook)
13020 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13024 ;;; Hierarchy browser (using `speedbar.el')
13025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13026 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13027 ;; directory by using the speedbar.
13029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13030 ;; Variables
13032 (defvar vhdl-entity-alist nil
13033 "Cache with entities and corresponding architectures for each
13034 project/directory.")
13035 ;; structure: (parenthesised expression means list of such entries)
13036 ;; (cache-key
13037 ;; (ent-key ent-name ent-file ent-line
13038 ;; (arch-key arch-name arch-file arch-line
13039 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13040 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13041 ;; (lib-name pack-key))
13042 ;; mra-key (lib-name pack-key))
13044 (defvar vhdl-config-alist nil
13045 "Cache with configurations for each project/directory.")
13046 ;; structure: (parenthesised expression means list of such entries)
13047 ;; (cache-key
13048 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13049 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13050 ;; inst-conf-key inst-lib-key)
13051 ;; (lib-name pack-key)))
13053 (defvar vhdl-package-alist nil
13054 "Cache with packages for each project/directory.")
13055 ;; structure: (parenthesised expression means list of such entries)
13056 ;; (cache-key
13057 ;; (pack-key pack-name pack-file pack-line
13058 ;; (comp-key comp-name comp-file comp-line)
13059 ;; (func-key func-name func-file func-line)
13060 ;; (lib-name pack-key)
13061 ;; pack-body-file pack-body-line
13062 ;; (func-key func-name func-body-file func-body-line)
13063 ;; (lib-name pack-key)))
13065 (defvar vhdl-ent-inst-alist nil
13066 "Cache with instantiated entities for each project/directory.")
13067 ;; structure: (parenthesised expression means list of such entries)
13068 ;; (cache-key (inst-ent-key))
13070 (defvar vhdl-file-alist nil
13071 "Cache with design units in each file for each project/directory.")
13072 ;; structure: (parenthesised expression means list of such entries)
13073 ;; (cache-key
13074 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13075 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13077 (defvar vhdl-directory-alist nil
13078 "Cache with source directories for each project.")
13079 ;; structure: (parenthesised expression means list of such entries)
13080 ;; (cache-key (directory))
13082 (defvar vhdl-speedbar-shown-unit-alist nil
13083 "Alist of design units simultaneously open in the current speedbar for each
13084 directory and project.")
13086 (defvar vhdl-speedbar-shown-project-list nil
13087 "List of projects simultaneously open in the current speedbar.")
13089 (defvar vhdl-updated-project-list nil
13090 "List of projects and directories with updated files.")
13092 (defvar vhdl-modified-file-list nil
13093 "List of modified files to be rescanned for hierarchy updating.")
13095 (defvar vhdl-speedbar-hierarchy-depth 0
13096 "Depth of instantiation hierarchy to display.")
13098 (defvar vhdl-speedbar-show-projects nil
13099 "Non-nil means project hierarchy is displayed in speedbar, directory
13100 hierarchy otherwise.")
13102 (defun vhdl-get-end-of-unit ()
13103 "Return position of end of current unit."
13104 (let ((pos (point)))
13105 (save-excursion
13106 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13107 (save-excursion
13108 (goto-char (match-beginning 0))
13109 (vhdl-backward-syntactic-ws)
13110 (and (/= (preceding-char) ?\;) (not (bobp))))))
13111 (re-search-backward "^[ \t]*end\\>" pos 1)
13112 (point))))
13114 (defun vhdl-match-string-downcase (num &optional string)
13115 "Like `match-string-no-properties' with down-casing."
13116 (let ((match (match-string-no-properties num string)))
13117 (and match (downcase match))))
13120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13121 ;; Scan functions
13123 (defun vhdl-scan-context-clause ()
13124 "Scan the context clause that preceeds a design unit."
13125 (let (lib-alist)
13126 (save-excursion
13127 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13128 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13129 (equal "USE" (upcase (match-string 1))))
13130 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13131 (setq lib-alist (cons (cons (match-string-no-properties 1)
13132 (vhdl-match-string-downcase 2))
13133 lib-alist))))))
13134 lib-alist))
13136 (defun vhdl-scan-directory-contents (name &optional project update num-string
13137 non-final)
13138 "Scan contents of VHDL files in directory or file pattern NAME."
13139 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13140 ; (unless (file-directory-p (match-string 1 name))
13141 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13142 (let* ((dir-name (match-string 1 name))
13143 (file-pattern (match-string 2 name))
13144 (is-directory (= 0 (length file-pattern)))
13145 (file-list
13146 (if update
13147 (list name)
13148 (if is-directory
13149 (vhdl-get-source-files t dir-name)
13150 (vhdl-directory-files
13151 dir-name t (wildcard-to-regexp file-pattern)))))
13152 (key (or project dir-name))
13153 (file-exclude-regexp
13154 (or (nth 3 (aget vhdl-project-alist project)) ""))
13155 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13156 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13157 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13158 ent-alist conf-alist pack-alist ent-inst-list file-alist
13159 tmp-list tmp-entry no-files files-exist big-files)
13160 (when (or project update)
13161 (setq ent-alist (aget vhdl-entity-alist key t)
13162 conf-alist (aget vhdl-config-alist key t)
13163 pack-alist (aget vhdl-package-alist key t)
13164 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13165 file-alist (aget vhdl-file-alist key t)))
13166 (when (and (not is-directory) (null file-list))
13167 (message "No such file: \"%s\"" name))
13168 (setq files-exist file-list)
13169 (when file-list
13170 (setq no-files (length file-list))
13171 (message "Scanning %s %s\"%s\"..."
13172 (if is-directory "directory" "files") (or num-string "") name)
13173 ;; exclude files
13174 (unless (equal file-exclude-regexp "")
13175 (let ((case-fold-search nil)
13176 file-tmp-list)
13177 (while file-list
13178 (unless (string-match file-exclude-regexp (car file-list))
13179 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13180 (setq file-list (cdr file-list)))
13181 (setq file-list (nreverse file-tmp-list))))
13182 ;; do for all files
13183 (while file-list
13184 (unless noninteractive
13185 (message "Scanning %s %s\"%s\"... (%2d%s)"
13186 (if is-directory "directory" "files")
13187 (or num-string "") name
13188 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13189 (let ((file-name (abbreviate-file-name (car file-list)))
13190 ent-list arch-list arch-ent-list conf-list
13191 pack-list pack-body-list inst-list inst-ent-list)
13192 ;; scan file
13193 (vhdl-visit-file
13194 file-name nil
13195 (vhdl-prepare-search-2
13196 (save-excursion
13197 ;; scan for design units
13198 (if (and limit-design-file-size
13199 (< limit-design-file-size (buffer-size)))
13200 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13201 (setq big-files t))
13202 ;; scan for entities
13203 (goto-char (point-min))
13204 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13205 (let* ((ent-name (match-string-no-properties 1))
13206 (ent-key (downcase ent-name))
13207 (ent-entry (aget ent-alist ent-key t))
13208 (lib-alist (vhdl-scan-context-clause)))
13209 (if (nth 1 ent-entry)
13210 (vhdl-warning-when-idle
13211 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13212 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13213 file-name (vhdl-current-line))
13214 (setq ent-list (cons ent-key ent-list))
13215 (aput 'ent-alist ent-key
13216 (list ent-name file-name (vhdl-current-line)
13217 (nth 3 ent-entry) (nth 4 ent-entry)
13218 lib-alist)))))
13219 ;; scan for architectures
13220 (goto-char (point-min))
13221 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13222 (let* ((arch-name (match-string-no-properties 1))
13223 (arch-key (downcase arch-name))
13224 (ent-name (match-string-no-properties 2))
13225 (ent-key (downcase ent-name))
13226 (ent-entry (aget ent-alist ent-key t))
13227 (arch-alist (nth 3 ent-entry))
13228 (arch-entry (aget arch-alist arch-key t))
13229 (lib-arch-alist (vhdl-scan-context-clause)))
13230 (if arch-entry
13231 (vhdl-warning-when-idle
13232 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13233 arch-name ent-name (nth 1 arch-entry)
13234 (nth 2 arch-entry) file-name (vhdl-current-line))
13235 (setq arch-list (cons arch-key arch-list)
13236 arch-ent-list (cons ent-key arch-ent-list))
13237 (aput 'arch-alist arch-key
13238 (list arch-name file-name (vhdl-current-line) nil
13239 lib-arch-alist))
13240 (aput 'ent-alist ent-key
13241 (list (or (nth 0 ent-entry) ent-name)
13242 (nth 1 ent-entry) (nth 2 ent-entry)
13243 (vhdl-sort-alist arch-alist)
13244 arch-key (nth 5 ent-entry))))))
13245 ;; scan for configurations
13246 (goto-char (point-min))
13247 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13248 (let* ((conf-name (match-string-no-properties 1))
13249 (conf-key (downcase conf-name))
13250 (conf-entry (aget conf-alist conf-key t))
13251 (ent-name (match-string-no-properties 2))
13252 (ent-key (downcase ent-name))
13253 (lib-alist (vhdl-scan-context-clause))
13254 (conf-line (vhdl-current-line))
13255 (end-of-unit (vhdl-get-end-of-unit))
13256 arch-key comp-conf-list inst-key-list
13257 inst-comp-key inst-ent-key inst-arch-key
13258 inst-conf-key inst-lib-key)
13259 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13260 (setq arch-key (vhdl-match-string-downcase 1)))
13261 (if conf-entry
13262 (vhdl-warning-when-idle
13263 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13264 conf-name ent-name (nth 1 conf-entry)
13265 (nth 2 conf-entry) file-name conf-line)
13266 (setq conf-list (cons conf-key conf-list))
13267 ;; scan for subconfigurations and subentities
13268 (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)
13269 (setq inst-comp-key (vhdl-match-string-downcase 3)
13270 inst-key-list (split-string
13271 (vhdl-match-string-downcase 1)
13272 "[ \t\n]*,[ \t\n]*"))
13273 (vhdl-forward-syntactic-ws)
13274 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13275 (setq
13276 inst-lib-key (vhdl-match-string-downcase 3)
13277 inst-ent-key (and (match-string 2)
13278 (vhdl-match-string-downcase 4))
13279 inst-arch-key (and (match-string 2)
13280 (vhdl-match-string-downcase 6))
13281 inst-conf-key (and (not (match-string 2))
13282 (vhdl-match-string-downcase 4)))
13283 (while inst-key-list
13284 (setq comp-conf-list
13285 (cons (list (car inst-key-list)
13286 inst-comp-key inst-ent-key
13287 inst-arch-key inst-conf-key
13288 inst-lib-key)
13289 comp-conf-list))
13290 (setq inst-key-list (cdr inst-key-list)))))
13291 (aput 'conf-alist conf-key
13292 (list conf-name file-name conf-line ent-key
13293 arch-key comp-conf-list lib-alist)))))
13294 ;; scan for packages
13295 (goto-char (point-min))
13296 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13297 (let* ((pack-name (match-string-no-properties 2))
13298 (pack-key (downcase pack-name))
13299 (is-body (match-string-no-properties 1))
13300 (pack-entry (aget pack-alist pack-key t))
13301 (pack-line (vhdl-current-line))
13302 (end-of-unit (vhdl-get-end-of-unit))
13303 comp-name func-name comp-alist func-alist lib-alist)
13304 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13305 (vhdl-warning-when-idle
13306 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13307 (if is-body " body" "") pack-name
13308 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13309 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13310 file-name (vhdl-current-line))
13311 ;; scan for context clauses
13312 (setq lib-alist (vhdl-scan-context-clause))
13313 ;; scan for component and subprogram declarations/bodies
13314 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13315 (if (equal (upcase (match-string 1)) "COMPONENT")
13316 (setq comp-name (match-string-no-properties 2)
13317 comp-alist
13318 (cons (list (downcase comp-name) comp-name
13319 file-name (vhdl-current-line))
13320 comp-alist))
13321 (setq func-name (match-string-no-properties 2)
13322 func-alist
13323 (cons (list (downcase func-name) func-name
13324 file-name (vhdl-current-line))
13325 func-alist))))
13326 (setq func-alist (nreverse func-alist))
13327 (setq comp-alist (nreverse comp-alist))
13328 (if is-body
13329 (setq pack-body-list (cons pack-key pack-body-list))
13330 (setq pack-list (cons pack-key pack-list)))
13331 (aput
13332 'pack-alist pack-key
13333 (if is-body
13334 (list (or (nth 0 pack-entry) pack-name)
13335 (nth 1 pack-entry) (nth 2 pack-entry)
13336 (nth 3 pack-entry) (nth 4 pack-entry)
13337 (nth 5 pack-entry)
13338 file-name pack-line func-alist lib-alist)
13339 (list pack-name file-name pack-line
13340 comp-alist func-alist lib-alist
13341 (nth 6 pack-entry) (nth 7 pack-entry)
13342 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13343 ;; scan for hierarchy
13344 (if (and limit-hier-file-size
13345 (< limit-hier-file-size (buffer-size)))
13346 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13347 (setq big-files t))
13348 ;; scan for architectures
13349 (goto-char (point-min))
13350 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13351 (let* ((ent-name (match-string-no-properties 2))
13352 (ent-key (downcase ent-name))
13353 (arch-name (match-string-no-properties 1))
13354 (arch-key (downcase arch-name))
13355 (ent-entry (aget ent-alist ent-key t))
13356 (arch-alist (nth 3 ent-entry))
13357 (arch-entry (aget arch-alist arch-key t))
13358 (beg-of-unit (point))
13359 (end-of-unit (vhdl-get-end-of-unit))
13360 (inst-no 0)
13361 inst-alist inst-path)
13362 ;; scan for contained instantiations
13363 (while (and (re-search-forward
13364 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13365 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13366 "component[ \t\n]+\\(\\w+\\)\\|"
13367 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13368 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13369 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13370 (or (not limit-hier-inst-no)
13371 (<= (setq inst-no (1+ inst-no))
13372 limit-hier-inst-no)))
13373 (cond
13374 ;; block/generate beginning found
13375 ((match-string 14)
13376 (setq inst-path
13377 (cons (match-string-no-properties 1) inst-path)))
13378 ;; block/generate end found
13379 ((match-string 16)
13380 (setq inst-path (cdr inst-path)))
13381 ;; instantiation found
13383 (let* ((inst-name (match-string-no-properties 1))
13384 (inst-key (downcase inst-name))
13385 (inst-comp-name
13386 (or (match-string-no-properties 3)
13387 (match-string-no-properties 6)))
13388 (inst-ent-key
13389 (or (and (match-string 8)
13390 (vhdl-match-string-downcase 11))
13391 (and inst-comp-name
13392 (downcase inst-comp-name))))
13393 (inst-arch-key (vhdl-match-string-downcase 13))
13394 (inst-conf-key
13395 (and (not (match-string 8))
13396 (vhdl-match-string-downcase 11)))
13397 (inst-lib-key (vhdl-match-string-downcase 10)))
13398 (goto-char (match-end 1))
13399 (setq inst-list (cons inst-key inst-list)
13400 inst-ent-list
13401 (cons inst-ent-key inst-ent-list))
13402 (setq inst-alist
13403 (append
13404 inst-alist
13405 (list (list inst-key inst-name file-name
13406 (vhdl-current-line) inst-comp-name
13407 inst-ent-key inst-arch-key
13408 inst-conf-key inst-lib-key
13409 (reverse inst-path)))))))))
13410 ;; scan for contained configuration specifications
13411 (goto-char beg-of-unit)
13412 (while (re-search-forward
13413 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13414 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13415 (let* ((inst-comp-name (match-string-no-properties 3))
13416 (inst-ent-key
13417 (and (match-string 6)
13418 (vhdl-match-string-downcase 9)))
13419 (inst-arch-key (vhdl-match-string-downcase 11))
13420 (inst-conf-key
13421 (and (not (match-string 6))
13422 (vhdl-match-string-downcase 9)))
13423 (inst-lib-key (vhdl-match-string-downcase 8))
13424 (inst-key-list
13425 (split-string (vhdl-match-string-downcase 1)
13426 "[ \t\n]*,[ \t\n]*"))
13427 (tmp-inst-alist inst-alist)
13428 inst-entry)
13429 (while tmp-inst-alist
13430 (when (and (or (equal "all" (car inst-key-list))
13431 (member (nth 0 (car tmp-inst-alist))
13432 inst-key-list))
13433 (equal
13434 (downcase
13435 (or (nth 4 (car tmp-inst-alist)) ""))
13436 (downcase inst-comp-name)))
13437 (setq inst-entry (car tmp-inst-alist))
13438 (setq inst-ent-list
13439 (cons (or inst-ent-key (nth 5 inst-entry))
13440 (vhdl-delete
13441 (nth 5 inst-entry) inst-ent-list)))
13442 (setq inst-entry
13443 (list (nth 0 inst-entry) (nth 1 inst-entry)
13444 (nth 2 inst-entry) (nth 3 inst-entry)
13445 (nth 4 inst-entry)
13446 (or inst-ent-key (nth 5 inst-entry))
13447 (or inst-arch-key (nth 6 inst-entry))
13448 inst-conf-key inst-lib-key))
13449 (setcar tmp-inst-alist inst-entry))
13450 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13451 ;; save in cache
13452 (aput 'arch-alist arch-key
13453 (list (nth 0 arch-entry) (nth 1 arch-entry)
13454 (nth 2 arch-entry) inst-alist
13455 (nth 4 arch-entry)))
13456 (aput 'ent-alist ent-key
13457 (list (nth 0 ent-entry) (nth 1 ent-entry)
13458 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13459 (nth 4 ent-entry) (nth 5 ent-entry)))
13460 (when (and limit-hier-inst-no
13461 (> inst-no limit-hier-inst-no))
13462 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13463 (setq big-files t))
13464 (goto-char end-of-unit))))
13465 ;; remember design units for this file
13466 (aput 'file-alist file-name
13467 (list ent-list arch-list arch-ent-list conf-list
13468 pack-list pack-body-list inst-list inst-ent-list))
13469 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13470 (setq file-list (cdr file-list))))
13471 (when (or (and (not project) files-exist)
13472 (and project (not non-final)))
13473 ;; consistency checks:
13474 ;; check whether each architecture has a corresponding entity
13475 (setq tmp-list ent-alist)
13476 (while tmp-list
13477 (when (null (nth 2 (car tmp-list)))
13478 (setq tmp-entry (car (nth 4 (car tmp-list))))
13479 (vhdl-warning-when-idle
13480 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13481 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13482 (nth 3 tmp-entry)))
13483 (setq tmp-list (cdr tmp-list)))
13484 ;; check whether configuration has a corresponding entity/architecture
13485 (setq tmp-list conf-alist)
13486 (while tmp-list
13487 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13488 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13489 (setq tmp-entry (car tmp-list))
13490 (vhdl-warning-when-idle
13491 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13492 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13493 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13494 (setq tmp-entry (car tmp-list))
13495 (vhdl-warning-when-idle
13496 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13497 (nth 1 tmp-entry) (nth 4 tmp-entry)
13498 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13499 (setq tmp-list (cdr tmp-list)))
13500 ;; check whether each package body has a package declaration
13501 (setq tmp-list pack-alist)
13502 (while tmp-list
13503 (when (null (nth 2 (car tmp-list)))
13504 (setq tmp-entry (car tmp-list))
13505 (vhdl-warning-when-idle
13506 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13507 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13508 (setq tmp-list (cdr tmp-list)))
13509 ;; sort lists
13510 (setq ent-alist (vhdl-sort-alist ent-alist))
13511 (setq conf-alist (vhdl-sort-alist conf-alist))
13512 (setq pack-alist (vhdl-sort-alist pack-alist))
13513 ;; remember updated directory/project
13514 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13515 ;; clear directory alists
13516 (unless project
13517 (adelete 'vhdl-entity-alist key)
13518 (adelete 'vhdl-config-alist key)
13519 (adelete 'vhdl-package-alist key)
13520 (adelete 'vhdl-ent-inst-alist key)
13521 (adelete 'vhdl-file-alist key))
13522 ;; put directory contents into cache
13523 (aput 'vhdl-entity-alist key ent-alist)
13524 (aput 'vhdl-config-alist key conf-alist)
13525 (aput 'vhdl-package-alist key pack-alist)
13526 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13527 (aput 'vhdl-file-alist key file-alist)
13528 ;; final messages
13529 (message "Scanning %s %s\"%s\"...done"
13530 (if is-directory "directory" "files") (or num-string "") name)
13531 (unless project (message "Scanning directory...done"))
13532 (when big-files
13533 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13534 ;; save cache when scanned non-interactively
13535 (when (or (not project) (not non-final))
13536 (when (and noninteractive vhdl-speedbar-save-cache)
13537 (vhdl-save-cache key)))
13540 (defun vhdl-scan-project-contents (project)
13541 "Scan the contents of all VHDL files found in the directories and files
13542 of PROJECT."
13543 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13544 (default-dir (vhdl-resolve-env-variable
13545 (nth 1 (aget vhdl-project-alist project))))
13546 (file-exclude-regexp
13547 (or (nth 3 (aget vhdl-project-alist project)) ""))
13548 dir-list-tmp dir dir-name num-dir act-dir recursive)
13549 ;; clear project alists
13550 (adelete 'vhdl-entity-alist project)
13551 (adelete 'vhdl-config-alist project)
13552 (adelete 'vhdl-package-alist project)
13553 (adelete 'vhdl-ent-inst-alist project)
13554 (adelete 'vhdl-file-alist project)
13555 ;; expand directory names by default-directory
13556 (message "Collecting source files...")
13557 (while dir-list
13558 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13559 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13560 (setq recursive (match-string 1 dir)
13561 dir-name (match-string 3 dir))
13562 (setq dir-list-tmp
13563 (cons (concat recursive
13564 (if (file-name-absolute-p dir-name) "" default-dir)
13565 dir-name)
13566 dir-list-tmp))
13567 (setq dir-list (cdr dir-list)))
13568 ;; resolve path wildcards
13569 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13570 ;; expand directories
13571 (while dir-list-tmp
13572 (setq dir (car dir-list-tmp))
13573 ;; get subdirectories
13574 (if (string-match "-r \\(.*[/\\]\\)" dir)
13575 (setq dir-list (append dir-list (vhdl-get-subdirs
13576 (match-string 1 dir))))
13577 (setq dir-list (append dir-list (list dir))))
13578 (setq dir-list-tmp (cdr dir-list-tmp)))
13579 ;; exclude files
13580 (unless (equal file-exclude-regexp "")
13581 (let ((case-fold-search nil))
13582 (while dir-list
13583 (unless (string-match file-exclude-regexp (car dir-list))
13584 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13585 (setq dir-list (cdr dir-list)))
13586 (setq dir-list (nreverse dir-list-tmp))))
13587 (message "Collecting source files...done")
13588 ;; scan for design units for each directory in DIR-LIST
13589 (setq dir-list-tmp nil
13590 num-dir (length dir-list)
13591 act-dir 1)
13592 (while dir-list
13593 (setq dir-name (abbreviate-file-name
13594 (expand-file-name (car dir-list))))
13595 (vhdl-scan-directory-contents dir-name project nil
13596 (format "(%s/%s) " act-dir num-dir)
13597 (cdr dir-list))
13598 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13599 (setq dir-list (cdr dir-list)
13600 act-dir (1+ act-dir)))
13601 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13602 (message "Scanning project \"%s\"...done" project)))
13604 (defun vhdl-update-file-contents (file-name)
13605 "Update hierarchy information by contents of current buffer."
13606 (setq file-name (abbreviate-file-name file-name))
13607 (let* ((dir-name (file-name-directory file-name))
13608 (directory-alist vhdl-directory-alist)
13609 updated)
13610 (while directory-alist
13611 (when (member dir-name (nth 1 (car directory-alist)))
13612 (let* ((vhdl-project (nth 0 (car directory-alist)))
13613 (project (vhdl-project-p))
13614 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13615 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13616 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13617 (ent-inst-list (car (aget vhdl-ent-inst-alist
13618 (or project dir-name) t)))
13619 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13620 (file-entry (aget file-alist file-name t))
13621 (ent-list (nth 0 file-entry))
13622 (arch-list (nth 1 file-entry))
13623 (arch-ent-list (nth 2 file-entry))
13624 (conf-list (nth 3 file-entry))
13625 (pack-list (nth 4 file-entry))
13626 (pack-body-list (nth 5 file-entry))
13627 (inst-ent-list (nth 7 file-entry))
13628 (cache-key (or project dir-name))
13629 arch-alist key ent-key entry)
13630 ;; delete design units previously contained in this file:
13631 ;; entities
13632 (while ent-list
13633 (setq key (car ent-list)
13634 entry (aget ent-alist key t))
13635 (when (equal file-name (nth 1 entry))
13636 (if (nth 3 entry)
13637 (aput 'ent-alist key
13638 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13639 (adelete 'ent-alist key)))
13640 (setq ent-list (cdr ent-list)))
13641 ;; architectures
13642 (while arch-list
13643 (setq key (car arch-list)
13644 ent-key (car arch-ent-list)
13645 entry (aget ent-alist ent-key t)
13646 arch-alist (nth 3 entry))
13647 (when (equal file-name (nth 1 (aget arch-alist key t)))
13648 (adelete 'arch-alist key)
13649 (if (or (nth 1 entry) arch-alist)
13650 (aput 'ent-alist ent-key
13651 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13652 arch-alist (nth 4 entry) (nth 5 entry)))
13653 (adelete 'ent-alist ent-key)))
13654 (setq arch-list (cdr arch-list)
13655 arch-ent-list (cdr arch-ent-list)))
13656 ;; configurations
13657 (while conf-list
13658 (setq key (car conf-list))
13659 (when (equal file-name (nth 1 (aget conf-alist key t)))
13660 (adelete 'conf-alist key))
13661 (setq conf-list (cdr conf-list)))
13662 ;; package declarations
13663 (while pack-list
13664 (setq key (car pack-list)
13665 entry (aget pack-alist key t))
13666 (when (equal file-name (nth 1 entry))
13667 (if (nth 6 entry)
13668 (aput 'pack-alist key
13669 (list (nth 0 entry) nil nil nil nil nil
13670 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13671 (nth 9 entry)))
13672 (adelete 'pack-alist key)))
13673 (setq pack-list (cdr pack-list)))
13674 ;; package bodies
13675 (while pack-body-list
13676 (setq key (car pack-body-list)
13677 entry (aget pack-alist key t))
13678 (when (equal file-name (nth 6 entry))
13679 (if (nth 1 entry)
13680 (aput 'pack-alist key
13681 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13682 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13683 nil nil nil nil))
13684 (adelete 'pack-alist key)))
13685 (setq pack-body-list (cdr pack-body-list)))
13686 ;; instantiated entities
13687 (while inst-ent-list
13688 (setq ent-inst-list
13689 (vhdl-delete (car inst-ent-list) ent-inst-list))
13690 (setq inst-ent-list (cdr inst-ent-list)))
13691 ;; update caches
13692 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13693 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13694 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13695 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13696 ;; scan file
13697 (vhdl-scan-directory-contents file-name project t)
13698 (when (or (and vhdl-speedbar-show-projects project)
13699 (and (not vhdl-speedbar-show-projects) (not project)))
13700 (vhdl-speedbar-refresh project))
13701 (setq updated t)))
13702 (setq directory-alist (cdr directory-alist)))
13703 updated))
13705 (defun vhdl-update-hierarchy ()
13706 "Update directory and hierarchy information in speedbar."
13707 (let ((file-list (reverse vhdl-modified-file-list))
13708 updated)
13709 (when (and vhdl-speedbar-update-on-saving file-list)
13710 (while file-list
13711 (setq updated
13712 (or (vhdl-update-file-contents (car file-list))
13713 updated))
13714 (setq file-list (cdr file-list)))
13715 (setq vhdl-modified-file-list nil)
13716 (vhdl-speedbar-update-current-unit)
13717 (when updated (message "Updating hierarchy...done")))))
13719 ;; structure (parenthesised expression means list of such entries)
13720 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13721 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13722 ;; comp-lib-name level)
13723 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13724 conf-inst-alist level indent
13725 &optional include-top ent-hier)
13726 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13727 entity ENT-KEY."
13728 (let* ((ent-entry (aget ent-alist ent-key t))
13729 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13730 (cdar (last (nth 3 ent-entry)))))
13731 (inst-alist (nth 3 arch-entry))
13732 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13733 hier-list subcomp-list tmp-list inst-key inst-comp-name
13734 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13735 (when (= level 0) (message "Extract design hierarchy..."))
13736 (when include-top
13737 (setq level (1+ level)))
13738 (when (member ent-key ent-hier)
13739 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13740 ;; check configured architecture (already checked during scanning)
13741 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13742 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13743 ;; process all instances
13744 (while inst-alist
13745 (setq inst-entry (car inst-alist)
13746 inst-key (nth 0 inst-entry)
13747 inst-comp-name (nth 4 inst-entry)
13748 inst-conf-key (nth 7 inst-entry))
13749 ;; search entry in configuration's instantiations list
13750 (setq tmp-list conf-inst-alist)
13751 (while (and tmp-list
13752 (not (and (member (nth 0 (car tmp-list))
13753 (list "all" inst-key))
13754 (equal (nth 1 (car tmp-list))
13755 (downcase (or inst-comp-name ""))))))
13756 (setq tmp-list (cdr tmp-list)))
13757 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13758 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13759 (when (and inst-conf-key (not inst-conf-entry))
13760 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13761 ;; determine entity
13762 (setq inst-ent-key
13763 (or (nth 2 (car tmp-list)) ; from configuration
13764 (nth 3 inst-conf-entry) ; from subconfiguration
13765 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13766 ; from configuration spec.
13767 (nth 5 inst-entry))) ; from direct instantiation
13768 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13769 ;; determine architecture
13770 (setq inst-arch-key
13771 (or (nth 3 (car tmp-list)) ; from configuration
13772 (nth 4 inst-conf-entry) ; from subconfiguration
13773 (nth 6 inst-entry) ; from direct instantiation
13774 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13775 ; from configuration spec.
13776 (nth 4 inst-ent-entry) ; MRA
13777 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
13778 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13779 ;; set library
13780 (setq inst-lib-key
13781 (or (nth 5 (car tmp-list)) ; from configuration
13782 (nth 8 inst-entry))) ; from direct instantiation
13783 ;; gather information for this instance
13784 (setq comp-entry
13785 (list (nth 1 inst-entry)
13786 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13787 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13788 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13789 (or (nth 0 inst-arch-entry) inst-arch-key)
13790 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13791 (or (nth 0 inst-conf-entry) inst-conf-key)
13792 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13793 inst-lib-key level))
13794 ;; get subcomponent hierarchy
13795 (setq subcomp-list (vhdl-get-hierarchy
13796 ent-alist conf-alist
13797 inst-ent-key inst-arch-key inst-conf-key
13798 (nth 5 inst-conf-entry)
13799 (1+ level) indent nil (cons ent-key ent-hier)))
13800 ;; add to list
13801 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13802 (setq inst-alist (cdr inst-alist)))
13803 (when include-top
13804 (setq hier-list
13805 (cons (list nil nil (nth 0 ent-entry)
13806 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13807 (nth 0 arch-entry)
13808 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13809 nil nil
13810 nil (1- level))
13811 hier-list)))
13812 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13813 hier-list))
13815 (defun vhdl-get-instantiations (ent-key indent)
13816 "Get all instantiations of entity ENT-KEY."
13817 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13818 arch-alist inst-alist ent-inst-list
13819 ent-entry arch-entry inst-entry)
13820 (while ent-alist
13821 (setq ent-entry (car ent-alist))
13822 (setq arch-alist (nth 4 ent-entry))
13823 (while arch-alist
13824 (setq arch-entry (car arch-alist))
13825 (setq inst-alist (nth 4 arch-entry))
13826 (while inst-alist
13827 (setq inst-entry (car inst-alist))
13828 (when (equal ent-key (nth 5 inst-entry))
13829 (setq ent-inst-list
13830 (cons (list (nth 1 inst-entry)
13831 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13832 (nth 1 ent-entry)
13833 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13834 (nth 1 arch-entry)
13835 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13836 ent-inst-list)))
13837 (setq inst-alist (cdr inst-alist)))
13838 (setq arch-alist (cdr arch-alist)))
13839 (setq ent-alist (cdr ent-alist)))
13840 (nreverse ent-inst-list)))
13842 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13843 ;; Caching in file
13845 (defun vhdl-save-caches ()
13846 "Save all updated hierarchy caches to file."
13847 (interactive)
13848 (condition-case nil
13849 (when vhdl-speedbar-save-cache
13850 ;; update hierarchy
13851 (vhdl-update-hierarchy)
13852 (let ((project-list vhdl-updated-project-list))
13853 (message "Saving hierarchy caches...")
13854 ;; write updated project caches
13855 (while project-list
13856 (vhdl-save-cache (car project-list))
13857 (setq project-list (cdr project-list)))
13858 (message "Saving hierarchy caches...done")))
13859 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
13860 (sit-for 2)))))
13862 (defun vhdl-save-cache (key)
13863 "Save current hierarchy cache to file."
13864 (let* ((orig-buffer (current-buffer))
13865 (vhdl-project key)
13866 (project (vhdl-project-p))
13867 (default-directory key)
13868 (directory (abbreviate-file-name (vhdl-default-directory)))
13869 (file-name (vhdl-resolve-env-variable
13870 (vhdl-replace-string
13871 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13872 (concat
13873 (subst-char-in-string ? ?_ (or project "dir"))
13874 " " (user-login-name)))))
13875 (file-dir-name (expand-file-name file-name directory))
13876 (cache-key (or project directory))
13877 (key (if project "project" "directory")))
13878 (unless (file-exists-p (file-name-directory file-dir-name))
13879 (make-directory (file-name-directory file-dir-name) t))
13880 (if (not (file-writable-p file-dir-name))
13881 (progn (vhdl-warning (format "File not writable: \"%s\""
13882 (abbreviate-file-name file-dir-name)))
13883 (sit-for 2))
13884 (message "Saving cache: \"%s\"" file-dir-name)
13885 (set-buffer (find-file-noselect file-dir-name t t))
13886 (erase-buffer)
13887 (insert ";; -*- Emacs-Lisp -*-\n\n"
13888 ";;; " (file-name-nondirectory file-name)
13889 " - design hierarchy cache file for Emacs VHDL Mode "
13890 vhdl-version "\n")
13891 (insert "\n;; " (if project "Project " "Directory") " : ")
13892 (if project (insert project) (prin1 directory (current-buffer)))
13893 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13894 (user-login-name) "\n\n"
13895 "\n;; version number\n"
13896 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13897 "\n;; " (if project "project" "directory") " name"
13898 "\n(setq " key " ")
13899 (prin1 (or project directory) (current-buffer))
13900 (insert ")\n")
13901 (when (member 'hierarchy vhdl-speedbar-save-cache)
13902 (insert "\n;; entity and architecture cache\n"
13903 "(aput 'vhdl-entity-alist " key " '")
13904 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13905 (insert ")\n\n;; configuration cache\n"
13906 "(aput 'vhdl-config-alist " key " '")
13907 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13908 (insert ")\n\n;; package cache\n"
13909 "(aput 'vhdl-package-alist " key " '")
13910 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13911 (insert ")\n\n;; instantiated entities cache\n"
13912 "(aput 'vhdl-ent-inst-alist " key " '")
13913 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13914 (insert ")\n\n;; design units per file cache\n"
13915 "(aput 'vhdl-file-alist " key " '")
13916 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13917 (when project
13918 (insert ")\n\n;; source directories in project cache\n"
13919 "(aput 'vhdl-directory-alist " key " '")
13920 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13921 (insert ")\n"))
13922 (when (member 'display vhdl-speedbar-save-cache)
13923 (insert "\n;; shown design units cache\n"
13924 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13925 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13926 (current-buffer))
13927 (insert ")\n"))
13928 (setq vhdl-updated-project-list
13929 (delete cache-key vhdl-updated-project-list))
13930 (save-buffer)
13931 (kill-buffer (current-buffer))
13932 (set-buffer orig-buffer))))
13934 (defun vhdl-load-cache (key)
13935 "Load hierarchy cache information from file."
13936 (let* ((vhdl-project key)
13937 (default-directory key)
13938 (directory (vhdl-default-directory))
13939 (file-name (vhdl-resolve-env-variable
13940 (vhdl-replace-string
13941 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13942 (concat
13943 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13944 " " (user-login-name)))))
13945 (file-dir-name (expand-file-name file-name directory))
13946 vhdl-cache-version)
13947 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13948 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13949 (when (file-exists-p file-dir-name)
13950 (condition-case ()
13951 (progn (load-file file-dir-name)
13952 (string< (mapconcat
13953 (lambda (a) (format "%3d" (string-to-number a)))
13954 (split-string "3.33" "\\.") "")
13955 (mapconcat
13956 (lambda (a) (format "%3d" (string-to-number a)))
13957 (split-string vhdl-cache-version "\\.") "")))
13958 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13959 nil))))))
13961 (defun vhdl-require-hierarchy-info ()
13962 "Make sure that hierarchy information is available. Load cache or scan files
13963 if required."
13964 (if (vhdl-project-p)
13965 (unless (or (assoc vhdl-project vhdl-file-alist)
13966 (vhdl-load-cache vhdl-project))
13967 (vhdl-scan-project-contents vhdl-project))
13968 (let ((directory (abbreviate-file-name default-directory)))
13969 (unless (or (assoc directory vhdl-file-alist)
13970 (vhdl-load-cache directory))
13971 (vhdl-scan-directory-contents directory)))))
13973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13974 ;; Add hierarchy browser functionality to speedbar
13976 (defvar vhdl-speedbar-key-map nil
13977 "Keymap used when in the VHDL hierarchy browser mode.")
13979 (defvar vhdl-speedbar-menu-items nil
13980 "Additional menu-items to add to speedbar frame.")
13982 (defun vhdl-speedbar-initialize ()
13983 "Initialize speedbar."
13984 ;; general settings
13985 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13986 ;; VHDL file extensions (extracted from `auto-mode-alist')
13987 (let ((mode-alist auto-mode-alist))
13988 (while mode-alist
13989 (when (eq (cdar mode-alist) 'vhdl-mode)
13990 (speedbar-add-supported-extension (caar mode-alist)))
13991 (setq mode-alist (cdr mode-alist))))
13992 ;; hierarchy browser settings
13993 (when (boundp 'speedbar-mode-functions-list)
13994 ;; special functions
13995 (speedbar-add-mode-functions-list
13996 '("vhdl directory"
13997 (speedbar-item-info . vhdl-speedbar-item-info)
13998 (speedbar-line-directory . speedbar-files-line-path)))
13999 (speedbar-add-mode-functions-list
14000 '("vhdl project"
14001 (speedbar-item-info . vhdl-speedbar-item-info)
14002 (speedbar-line-directory . vhdl-speedbar-line-project)))
14003 ;; keymap
14004 (unless vhdl-speedbar-key-map
14005 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
14006 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14007 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14008 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
14009 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14010 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14011 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14012 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14013 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
14014 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14015 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
14016 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14017 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14018 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14019 (let ((key 0))
14020 (while (<= key 9)
14021 (define-key vhdl-speedbar-key-map (int-to-string key)
14022 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14023 (setq key (1+ key)))))
14024 (define-key speedbar-key-map "h"
14025 (lambda () (interactive)
14026 (speedbar-change-initial-expansion-list "vhdl directory")))
14027 (define-key speedbar-key-map "H"
14028 (lambda () (interactive)
14029 (speedbar-change-initial-expansion-list "vhdl project")))
14030 ;; menu
14031 (unless vhdl-speedbar-menu-items
14032 (setq
14033 vhdl-speedbar-menu-items
14034 `(["Edit" speedbar-edit-line t]
14035 ["Expand" speedbar-expand-line
14036 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14037 ["Contract" vhdl-speedbar-contract-level t]
14038 ["Expand All" vhdl-speedbar-expand-all t]
14039 ["Contract All" vhdl-speedbar-contract-all t]
14040 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14041 (while (<= key 9)
14042 (setq menu-list
14043 (cons `[,(if (= key 0) "All" (int-to-string key))
14044 (vhdl-speedbar-set-depth ,key)
14045 :style radio
14046 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14047 :keys ,(int-to-string key)]
14048 menu-list))
14049 (setq key (1+ key)))
14050 (nreverse menu-list))
14051 "--"
14052 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14053 (or (vhdl-speedbar-check-unit 'entity)
14054 (vhdl-speedbar-check-unit 'subprogram))]
14055 ["Place Component" vhdl-speedbar-place-component
14056 (vhdl-speedbar-check-unit 'entity)]
14057 ["Generate Configuration" vhdl-speedbar-configuration
14058 (vhdl-speedbar-check-unit 'architecture)]
14059 ["Select as MRA" vhdl-speedbar-select-mra
14060 (vhdl-speedbar-check-unit 'architecture)]
14061 ["Make" vhdl-speedbar-make-design
14062 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14063 ["Generate Makefile" vhdl-speedbar-generate-makefile
14064 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14065 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14066 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14067 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
14068 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14069 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14070 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
14071 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14072 ;; hook-ups
14073 (speedbar-add-expansion-list
14074 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14075 vhdl-speedbar-display-directory))
14076 (speedbar-add-expansion-list
14077 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14078 vhdl-speedbar-display-projects))
14079 (setq speedbar-stealthy-function-list
14080 (append
14081 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14082 ("vhdl project" vhdl-speedbar-update-current-project
14083 vhdl-speedbar-update-current-unit)
14084 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14085 ; (speedbar-extension-list-to-regex
14086 ; speedbar-ignored-path-expressions))))
14088 speedbar-stealthy-function-list))
14089 (when (eq vhdl-speedbar-display-mode 'directory)
14090 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14091 (when (eq vhdl-speedbar-display-mode 'project)
14092 (setq speedbar-initial-expansion-list-name "vhdl project"))
14093 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14095 (defun vhdl-speedbar (&optional arg)
14096 "Open/close speedbar."
14097 (interactive)
14098 (if (not (fboundp 'speedbar))
14099 (error "WARNING: Speedbar is not available or not installed")
14100 (condition-case ()
14101 (speedbar-frame-mode arg)
14102 (error (error "WARNING: An error occurred while opening speedbar")))))
14104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14105 ;; Display functions
14107 (defvar vhdl-speedbar-last-selected-project nil
14108 "Name of last selected project.")
14110 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14111 (defmacro speedbar-with-writable (&rest forms)
14112 "Allow the buffer to be writable and evaluate FORMS."
14113 (list 'let '((inhibit-read-only t))
14114 (cons 'progn forms)))
14115 (put 'speedbar-with-writable 'lisp-indent-function 0)
14117 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14118 "Display directory and hierarchy information in speedbar."
14119 (setq vhdl-speedbar-show-projects nil)
14120 (setq speedbar-ignored-directory-regexp
14121 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14122 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14123 (setq speedbar-last-selected-file nil)
14124 (speedbar-with-writable
14125 (condition-case nil
14126 (progn
14127 ;; insert directory path
14128 (speedbar-directory-buttons directory depth)
14129 ;; insert subdirectories
14130 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14131 ;; scan and insert hierarchy of current directory
14132 (vhdl-speedbar-insert-dir-hierarchy directory depth
14133 speedbar-power-click)
14134 ;; expand subdirectories
14135 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14136 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14138 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14139 "Display projects and hierarchy information in speedbar."
14140 (setq vhdl-speedbar-show-projects t)
14141 (setq speedbar-ignored-directory-regexp ".")
14142 (setq speedbar-last-selected-file nil)
14143 (setq vhdl-speedbar-last-selected-project nil)
14144 (speedbar-with-writable
14145 (condition-case nil
14146 ;; insert projects
14147 (vhdl-speedbar-insert-projects)
14148 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14149 (setq speedbar-full-text-cache nil)) ; prevent caching
14151 (defun vhdl-speedbar-insert-projects ()
14152 "Insert all projects in speedbar."
14153 (vhdl-speedbar-make-title-line "Projects:")
14154 (let ((project-alist (if vhdl-project-sort
14155 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14156 vhdl-project-alist))
14157 (vhdl-speedbar-update-current-unit nil))
14158 ;; insert projects
14159 (while project-alist
14160 (speedbar-make-tag-line
14161 'angle ?+ 'vhdl-speedbar-expand-project
14162 (caar project-alist) (caar project-alist)
14163 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14164 (setq project-alist (cdr project-alist)))
14165 (setq project-alist vhdl-project-alist)
14166 ;; expand projects
14167 (while project-alist
14168 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14169 (goto-char (point-min))
14170 (when (re-search-forward
14171 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14172 (goto-char (match-end 1))
14173 (speedbar-do-function-pointer)))
14174 (setq project-alist (cdr project-alist))))
14175 ; (vhdl-speedbar-update-current-project)
14176 ; (vhdl-speedbar-update-current-unit nil t)
14179 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14180 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14181 otherwise use cached data."
14182 (when (or rescan (and (not (assoc project vhdl-file-alist))
14183 (not (vhdl-load-cache project))))
14184 (vhdl-scan-project-contents project))
14185 ;; insert design hierarchy
14186 (vhdl-speedbar-insert-hierarchy
14187 (aget vhdl-entity-alist project t)
14188 (aget vhdl-config-alist project t)
14189 (aget vhdl-package-alist project t)
14190 (car (aget vhdl-ent-inst-alist project t)) indent)
14191 (insert (int-to-string indent) ":\n")
14192 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14193 (put-text-property (1- (point)) (point) 'invisible nil)
14194 ;; expand design units
14195 (vhdl-speedbar-expand-units project))
14197 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14198 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14199 otherwise use cached data."
14200 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14201 (not (vhdl-load-cache directory))))
14202 (vhdl-scan-directory-contents directory))
14203 ;; insert design hierarchy
14204 (vhdl-speedbar-insert-hierarchy
14205 (aget vhdl-entity-alist directory t)
14206 (aget vhdl-config-alist directory t)
14207 (aget vhdl-package-alist directory t)
14208 (car (aget vhdl-ent-inst-alist directory t)) depth)
14209 ;; expand design units
14210 (vhdl-speedbar-expand-units directory)
14211 (aput 'vhdl-directory-alist directory (list (list directory))))
14213 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14214 ent-inst-list depth)
14215 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14216 (if (not (or ent-alist conf-alist pack-alist))
14217 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14218 (let (ent-entry conf-entry pack-entry)
14219 ;; insert entities
14220 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14221 (while ent-alist
14222 (setq ent-entry (car ent-alist))
14223 (speedbar-make-tag-line
14224 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14225 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14226 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14227 'vhdl-speedbar-entity-face depth)
14228 (unless (nth 2 ent-entry)
14229 (end-of-line 0) (insert "!") (forward-char 1))
14230 (unless (member (nth 0 ent-entry) ent-inst-list)
14231 (end-of-line 0) (insert " (top)") (forward-char 1))
14232 (setq ent-alist (cdr ent-alist)))
14233 ;; insert configurations
14234 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14235 (while conf-alist
14236 (setq conf-entry (car conf-alist))
14237 (speedbar-make-tag-line
14238 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14239 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14240 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14241 'vhdl-speedbar-configuration-face depth)
14242 (setq conf-alist (cdr conf-alist)))
14243 ;; insert packages
14244 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14245 (while pack-alist
14246 (setq pack-entry (car pack-alist))
14247 (vhdl-speedbar-make-pack-line
14248 (nth 0 pack-entry) (nth 1 pack-entry)
14249 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14250 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14251 depth)
14252 (setq pack-alist (cdr pack-alist))))))
14254 (defun vhdl-speedbar-rescan-hierarchy ()
14255 "Rescan hierarchy for the directory or project under the cursor."
14256 (interactive)
14257 (let (key path)
14258 (cond
14259 ;; current project
14260 (vhdl-speedbar-show-projects
14261 (setq key (vhdl-speedbar-line-project))
14262 (vhdl-scan-project-contents key))
14263 ;; top-level directory
14264 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14265 (re-search-forward "[0-9]+:" nil t)
14266 (vhdl-scan-directory-contents
14267 (abbreviate-file-name (speedbar-line-directory))))
14268 ;; current directory
14269 (t (setq path (speedbar-line-directory))
14270 (string-match "^\\(.+[/\\]\\)" path)
14271 (vhdl-scan-directory-contents
14272 (abbreviate-file-name (match-string 1 path)))))
14273 (vhdl-speedbar-refresh key)))
14275 (defun vhdl-speedbar-expand-dirs (directory)
14276 "Expand subdirectories in DIRECTORY according to
14277 `speedbar-shown-directories'."
14278 ;; (nicked from `speedbar-default-directory-list')
14279 (let ((sf (cdr (reverse speedbar-shown-directories)))
14280 (vhdl-speedbar-update-current-unit nil))
14281 (setq speedbar-shown-directories
14282 (list (expand-file-name default-directory)))
14283 (while sf
14284 (when (speedbar-goto-this-file (car sf))
14285 (beginning-of-line)
14286 (when (looking-at "[0-9]+:\\s-*<")
14287 (goto-char (match-end 0))
14288 (speedbar-do-function-pointer)))
14289 (setq sf (cdr sf))))
14290 (vhdl-speedbar-update-current-unit nil t))
14292 (defun vhdl-speedbar-expand-units (key)
14293 "Expand design units in directory/project KEY according to
14294 `vhdl-speedbar-shown-unit-alist'."
14295 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14296 (vhdl-speedbar-update-current-unit nil)
14297 vhdl-updated-project-list)
14298 (adelete 'vhdl-speedbar-shown-unit-alist key)
14299 (vhdl-prepare-search-1
14300 (while unit-alist ; expand units
14301 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14302 (beginning-of-line)
14303 (let ((arch-alist (nth 1 (car unit-alist)))
14304 position)
14305 (when (looking-at "^[0-9]+:\\s-*\\[")
14306 (goto-char (match-end 0))
14307 (setq position (point))
14308 (speedbar-do-function-pointer)
14309 (select-frame speedbar-frame)
14310 (while arch-alist ; expand architectures
14311 (goto-char position)
14312 (when (re-search-forward
14313 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14314 (car arch-alist) "\\>\\)") nil t)
14315 (beginning-of-line)
14316 (when (looking-at "^[0-9]+:\\s-*{")
14317 (goto-char (match-end 0))
14318 (speedbar-do-function-pointer)
14319 (select-frame speedbar-frame)))
14320 (setq arch-alist (cdr arch-alist))))
14321 (setq unit-alist (cdr unit-alist))))))
14322 (vhdl-speedbar-update-current-unit nil t))
14324 (defun vhdl-speedbar-contract-level ()
14325 "Contract current level in current directory/project."
14326 (interactive)
14327 (when (or (save-excursion
14328 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14329 (and (save-excursion
14330 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14331 (re-search-backward
14332 (format "^[0-%d]:\\s-*[[{<]-"
14333 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14334 (goto-char (match-end 0))
14335 (speedbar-do-function-pointer)
14336 (speedbar-center-buffer-smartly)))
14338 (defun vhdl-speedbar-contract-all ()
14339 "Contract all expanded design units in current directory/project."
14340 (interactive)
14341 (if (and vhdl-speedbar-show-projects
14342 (save-excursion (beginning-of-line) (looking-at "^0:")))
14343 (progn (setq vhdl-speedbar-shown-project-list nil)
14344 (vhdl-speedbar-refresh))
14345 (let ((key (vhdl-speedbar-line-key)))
14346 (adelete 'vhdl-speedbar-shown-unit-alist key)
14347 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14348 (when (memq 'display vhdl-speedbar-save-cache)
14349 (add-to-list 'vhdl-updated-project-list key)))))
14351 (defun vhdl-speedbar-expand-all ()
14352 "Expand all design units in current directory/project."
14353 (interactive)
14354 (let* ((key (vhdl-speedbar-line-key))
14355 (ent-alist (aget vhdl-entity-alist key t))
14356 (conf-alist (aget vhdl-config-alist key t))
14357 (pack-alist (aget vhdl-package-alist key t))
14358 arch-alist unit-alist subunit-alist)
14359 (add-to-list 'vhdl-speedbar-shown-project-list key)
14360 (while ent-alist
14361 (setq arch-alist (nth 4 (car ent-alist)))
14362 (setq subunit-alist nil)
14363 (while arch-alist
14364 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14365 (setq arch-alist (cdr arch-alist)))
14366 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14367 (setq ent-alist (cdr ent-alist)))
14368 (while conf-alist
14369 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14370 (setq conf-alist (cdr conf-alist)))
14371 (while pack-alist
14372 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14373 (setq pack-alist (cdr pack-alist)))
14374 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14375 (vhdl-speedbar-refresh)
14376 (when (memq 'display vhdl-speedbar-save-cache)
14377 (add-to-list 'vhdl-updated-project-list key))))
14379 (defun vhdl-speedbar-expand-project (text token indent)
14380 "Expand/contract the project under the cursor."
14381 (cond
14382 ((string-match "+" text) ; expand project
14383 (speedbar-change-expand-button-char ?-)
14384 (unless (member token vhdl-speedbar-shown-project-list)
14385 (setq vhdl-speedbar-shown-project-list
14386 (cons token vhdl-speedbar-shown-project-list)))
14387 (speedbar-with-writable
14388 (save-excursion
14389 (end-of-line) (forward-char 1)
14390 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14391 speedbar-power-click))))
14392 ((string-match "-" text) ; contract project
14393 (speedbar-change-expand-button-char ?+)
14394 (setq vhdl-speedbar-shown-project-list
14395 (delete token vhdl-speedbar-shown-project-list))
14396 (speedbar-delete-subblock indent))
14397 (t (error "Nothing to display")))
14398 (when (equal (selected-frame) speedbar-frame)
14399 (speedbar-center-buffer-smartly)))
14401 (defun vhdl-speedbar-expand-entity (text token indent)
14402 "Expand/contract the entity under the cursor."
14403 (cond
14404 ((string-match "+" text) ; expand entity
14405 (let* ((key (vhdl-speedbar-line-key indent))
14406 (ent-alist (aget vhdl-entity-alist key t))
14407 (ent-entry (aget ent-alist token t))
14408 (arch-alist (nth 3 ent-entry))
14409 (inst-alist (vhdl-get-instantiations token indent))
14410 (subpack-alist (nth 5 ent-entry))
14411 (multiple-arch (> (length arch-alist) 1))
14412 arch-entry inst-entry)
14413 (if (not (or arch-alist inst-alist subpack-alist))
14414 (speedbar-change-expand-button-char ??)
14415 (speedbar-change-expand-button-char ?-)
14416 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14417 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14418 (aput 'unit-alist token nil)
14419 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14420 (speedbar-with-writable
14421 (save-excursion
14422 (end-of-line) (forward-char 1)
14423 ;; insert architectures
14424 (when arch-alist
14425 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14426 (while arch-alist
14427 (setq arch-entry (car arch-alist))
14428 (speedbar-make-tag-line
14429 'curly ?+ 'vhdl-speedbar-expand-architecture
14430 (cons token (nth 0 arch-entry))
14431 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14432 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14433 'vhdl-speedbar-architecture-face (1+ indent))
14434 (when (and multiple-arch
14435 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14436 (end-of-line 0) (insert " (mra)") (forward-char 1))
14437 (setq arch-alist (cdr arch-alist)))
14438 ;; insert instantiations
14439 (when inst-alist
14440 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14441 (while inst-alist
14442 (setq inst-entry (car inst-alist))
14443 (vhdl-speedbar-make-inst-line
14444 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14445 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14446 nil nil nil (1+ indent) 0 " in ")
14447 (setq inst-alist (cdr inst-alist)))
14448 ;; insert required packages
14449 (vhdl-speedbar-insert-subpackages
14450 subpack-alist (1+ indent) indent)))
14451 (when (memq 'display vhdl-speedbar-save-cache)
14452 (add-to-list 'vhdl-updated-project-list key))
14453 (vhdl-speedbar-update-current-unit t t))))
14454 ((string-match "-" text) ; contract entity
14455 (speedbar-change-expand-button-char ?+)
14456 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14457 (let* ((key (vhdl-speedbar-line-key indent))
14458 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14459 (adelete 'unit-alist token)
14460 (if unit-alist
14461 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14462 (adelete 'vhdl-speedbar-shown-unit-alist key))
14463 (speedbar-delete-subblock indent)
14464 (when (memq 'display vhdl-speedbar-save-cache)
14465 (add-to-list 'vhdl-updated-project-list key))))
14466 (t (error "Nothing to display")))
14467 (when (equal (selected-frame) speedbar-frame)
14468 (speedbar-center-buffer-smartly)))
14470 (defun vhdl-speedbar-expand-architecture (text token indent)
14471 "Expand/contract the architecture under the cursor."
14472 (cond
14473 ((string-match "+" text) ; expand architecture
14474 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14475 (ent-alist (aget vhdl-entity-alist key t))
14476 (conf-alist (aget vhdl-config-alist key t))
14477 (hier-alist (vhdl-get-hierarchy
14478 ent-alist conf-alist (car token) (cdr token) nil nil
14479 0 (1- indent)))
14480 (ent-entry (aget ent-alist (car token) t))
14481 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14482 (subpack-alist (nth 4 arch-entry))
14483 entry)
14484 (if (not (or hier-alist subpack-alist))
14485 (speedbar-change-expand-button-char ??)
14486 (speedbar-change-expand-button-char ?-)
14487 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14488 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14489 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14490 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14491 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14492 (speedbar-with-writable
14493 (save-excursion
14494 (end-of-line) (forward-char 1)
14495 ;; insert instance hierarchy
14496 (when hier-alist
14497 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14498 (1+ indent)))
14499 (while hier-alist
14500 (setq entry (car hier-alist))
14501 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14502 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14503 (vhdl-speedbar-make-inst-line
14504 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14505 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14506 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14507 (setq hier-alist (cdr hier-alist)))
14508 ;; insert required packages
14509 (vhdl-speedbar-insert-subpackages
14510 subpack-alist (1+ indent) (1- indent))))
14511 (when (memq 'display vhdl-speedbar-save-cache)
14512 (add-to-list 'vhdl-updated-project-list key))
14513 (vhdl-speedbar-update-current-unit t t))))
14514 ((string-match "-" text) ; contract architecture
14515 (speedbar-change-expand-button-char ?+)
14516 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14517 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14518 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14519 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14520 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14521 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14522 (speedbar-delete-subblock indent)
14523 (when (memq 'display vhdl-speedbar-save-cache)
14524 (add-to-list 'vhdl-updated-project-list key))))
14525 (t (error "Nothing to display")))
14526 (when (equal (selected-frame) speedbar-frame)
14527 (speedbar-center-buffer-smartly)))
14529 (defun vhdl-speedbar-expand-config (text token indent)
14530 "Expand/contract the configuration under the cursor."
14531 (cond
14532 ((string-match "+" text) ; expand configuration
14533 (let* ((key (vhdl-speedbar-line-key indent))
14534 (conf-alist (aget vhdl-config-alist key t))
14535 (conf-entry (aget conf-alist token))
14536 (ent-alist (aget vhdl-entity-alist key t))
14537 (hier-alist (vhdl-get-hierarchy
14538 ent-alist conf-alist (nth 3 conf-entry)
14539 (nth 4 conf-entry) token (nth 5 conf-entry)
14540 0 indent t))
14541 (subpack-alist (nth 6 conf-entry))
14542 entry)
14543 (if (not (or hier-alist subpack-alist))
14544 (speedbar-change-expand-button-char ??)
14545 (speedbar-change-expand-button-char ?-)
14546 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14547 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14548 (aput 'unit-alist token nil)
14549 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14550 (speedbar-with-writable
14551 (save-excursion
14552 (end-of-line) (forward-char 1)
14553 ;; insert instance hierarchy
14554 (when hier-alist
14555 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14556 (while hier-alist
14557 (setq entry (car hier-alist))
14558 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14559 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14560 (vhdl-speedbar-make-inst-line
14561 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14562 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14563 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14564 (setq hier-alist (cdr hier-alist)))
14565 ;; insert required packages
14566 (vhdl-speedbar-insert-subpackages
14567 subpack-alist (1+ indent) indent)))
14568 (when (memq 'display vhdl-speedbar-save-cache)
14569 (add-to-list 'vhdl-updated-project-list key))
14570 (vhdl-speedbar-update-current-unit t t))))
14571 ((string-match "-" text) ; contract configuration
14572 (speedbar-change-expand-button-char ?+)
14573 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14574 (let* ((key (vhdl-speedbar-line-key indent))
14575 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14576 (adelete 'unit-alist token)
14577 (if unit-alist
14578 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14579 (adelete 'vhdl-speedbar-shown-unit-alist key))
14580 (speedbar-delete-subblock indent)
14581 (when (memq 'display vhdl-speedbar-save-cache)
14582 (add-to-list 'vhdl-updated-project-list key))))
14583 (t (error "Nothing to display")))
14584 (when (equal (selected-frame) speedbar-frame)
14585 (speedbar-center-buffer-smartly)))
14587 (defun vhdl-speedbar-expand-package (text token indent)
14588 "Expand/contract the package under the cursor."
14589 (cond
14590 ((string-match "+" text) ; expand package
14591 (let* ((key (vhdl-speedbar-line-key indent))
14592 (pack-alist (aget vhdl-package-alist key t))
14593 (pack-entry (aget pack-alist token t))
14594 (comp-alist (nth 3 pack-entry))
14595 (func-alist (nth 4 pack-entry))
14596 (func-body-alist (nth 8 pack-entry))
14597 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14598 comp-entry func-entry func-body-entry)
14599 (if (not (or comp-alist func-alist subpack-alist))
14600 (speedbar-change-expand-button-char ??)
14601 (speedbar-change-expand-button-char ?-)
14602 ;; add package to `vhdl-speedbar-shown-unit-alist'
14603 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14604 (aput 'unit-alist token nil)
14605 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14606 (speedbar-with-writable
14607 (save-excursion
14608 (end-of-line) (forward-char 1)
14609 ;; insert components
14610 (when comp-alist
14611 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14612 (while comp-alist
14613 (setq comp-entry (car comp-alist))
14614 (speedbar-make-tag-line
14615 nil nil nil
14616 (cons token (nth 0 comp-entry))
14617 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14618 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14619 'vhdl-speedbar-entity-face (1+ indent))
14620 (setq comp-alist (cdr comp-alist)))
14621 ;; insert subprograms
14622 (when func-alist
14623 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14624 (while func-alist
14625 (setq func-entry (car func-alist)
14626 func-body-entry (aget func-body-alist (car func-entry) t))
14627 (when (nth 2 func-entry)
14628 (vhdl-speedbar-make-subprogram-line
14629 (nth 1 func-entry)
14630 (cons (nth 2 func-entry) (nth 3 func-entry))
14631 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14632 (1+ indent)))
14633 (setq func-alist (cdr func-alist)))
14634 ;; insert required packages
14635 (vhdl-speedbar-insert-subpackages
14636 subpack-alist (1+ indent) indent)))
14637 (when (memq 'display vhdl-speedbar-save-cache)
14638 (add-to-list 'vhdl-updated-project-list key))
14639 (vhdl-speedbar-update-current-unit t t))))
14640 ((string-match "-" text) ; contract package
14641 (speedbar-change-expand-button-char ?+)
14642 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14643 (let* ((key (vhdl-speedbar-line-key indent))
14644 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14645 (adelete 'unit-alist token)
14646 (if unit-alist
14647 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14648 (adelete 'vhdl-speedbar-shown-unit-alist key))
14649 (speedbar-delete-subblock indent)
14650 (when (memq 'display vhdl-speedbar-save-cache)
14651 (add-to-list 'vhdl-updated-project-list key))))
14652 (t (error "Nothing to display")))
14653 (when (equal (selected-frame) speedbar-frame)
14654 (speedbar-center-buffer-smartly)))
14656 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14657 "Insert required packages."
14658 (let* ((pack-alist (aget vhdl-package-alist
14659 (vhdl-speedbar-line-key dir-indent) t))
14660 pack-key lib-name pack-entry)
14661 (when subpack-alist
14662 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14663 (while subpack-alist
14664 (setq pack-key (cdar subpack-alist)
14665 lib-name (caar subpack-alist))
14666 (setq pack-entry (aget pack-alist pack-key t))
14667 (vhdl-speedbar-make-subpack-line
14668 (or (nth 0 pack-entry) pack-key) lib-name
14669 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14670 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
14671 (setq subpack-alist (cdr subpack-alist)))))
14673 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14674 ;; Display help functions
14676 (defvar vhdl-speedbar-update-current-unit t
14677 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14679 (defun vhdl-speedbar-update-current-project ()
14680 "Highlight project that is currently active."
14681 (when (and vhdl-speedbar-show-projects
14682 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14683 (and (boundp 'speedbar-frame)
14684 (frame-live-p speedbar-frame)))
14685 (let ((last-frame (selected-frame))
14686 (project-alist vhdl-project-alist)
14687 pos)
14688 (select-frame speedbar-frame)
14689 (speedbar-with-writable
14690 (save-excursion
14691 (while project-alist
14692 (goto-char (point-min))
14693 (when (re-search-forward
14694 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14695 (put-text-property (match-beginning 1) (match-end 1) 'face
14696 (if (equal (caar project-alist) vhdl-project)
14697 'speedbar-selected-face
14698 'speedbar-directory-face))
14699 (when (equal (caar project-alist) vhdl-project)
14700 (setq pos (1- (match-beginning 1)))))
14701 (setq project-alist (cdr project-alist))))
14702 (when pos (goto-char pos)))
14703 (select-frame last-frame)
14704 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14707 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14708 "Highlight all design units that are contained in the current file.
14709 NO-POSITION non-nil means do not re-position cursor."
14710 (let ((last-frame (selected-frame))
14711 (project-list vhdl-speedbar-shown-project-list)
14712 file-alist pos file-name)
14713 ;; get current file name
14714 (if (fboundp 'speedbar-select-attached-frame)
14715 (speedbar-select-attached-frame)
14716 (select-frame speedbar-attached-frame))
14717 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14718 (when (and vhdl-speedbar-update-current-unit
14719 (or always (not (equal file-name speedbar-last-selected-file))))
14720 (if vhdl-speedbar-show-projects
14721 (while project-list
14722 (setq file-alist (append file-alist (aget vhdl-file-alist
14723 (car project-list) t)))
14724 (setq project-list (cdr project-list)))
14725 (setq file-alist (aget vhdl-file-alist
14726 (abbreviate-file-name default-directory) t)))
14727 (select-frame speedbar-frame)
14728 (set-buffer speedbar-buffer)
14729 (speedbar-with-writable
14730 (vhdl-prepare-search-1
14731 (save-excursion
14732 ;; unhighlight last units
14733 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14734 (vhdl-speedbar-update-units
14735 "\\[.\\] " (nth 0 file-entry)
14736 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14737 (vhdl-speedbar-update-units
14738 "{.} " (nth 1 file-entry)
14739 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14740 (vhdl-speedbar-update-units
14741 "\\[.\\] " (nth 3 file-entry)
14742 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14743 (vhdl-speedbar-update-units
14744 "[]>] " (nth 4 file-entry)
14745 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14746 (vhdl-speedbar-update-units
14747 "\\[.\\].+(" '("body")
14748 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14749 (vhdl-speedbar-update-units
14750 "> " (nth 6 file-entry)
14751 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14752 ;; highlight current units
14753 (let* ((file-entry (aget file-alist file-name t)))
14754 (setq
14755 pos (vhdl-speedbar-update-units
14756 "\\[.\\] " (nth 0 file-entry)
14757 file-name 'vhdl-speedbar-entity-selected-face pos)
14758 pos (vhdl-speedbar-update-units
14759 "{.} " (nth 1 file-entry)
14760 file-name 'vhdl-speedbar-architecture-selected-face pos)
14761 pos (vhdl-speedbar-update-units
14762 "\\[.\\] " (nth 3 file-entry)
14763 file-name 'vhdl-speedbar-configuration-selected-face pos)
14764 pos (vhdl-speedbar-update-units
14765 "[]>] " (nth 4 file-entry)
14766 file-name 'vhdl-speedbar-package-selected-face pos)
14767 pos (vhdl-speedbar-update-units
14768 "\\[.\\].+(" '("body")
14769 file-name 'vhdl-speedbar-package-selected-face pos)
14770 pos (vhdl-speedbar-update-units
14771 "> " (nth 6 file-entry)
14772 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14773 ;; move speedbar so the first highlighted unit is visible
14774 (when (and pos (not no-position))
14775 (goto-char pos)
14776 (speedbar-center-buffer-smartly)
14777 (speedbar-position-cursor-on-line))
14778 (setq speedbar-last-selected-file file-name))
14779 (select-frame last-frame)
14782 (defun vhdl-speedbar-update-units (text unit-list file-name face
14783 &optional pos)
14784 "Help function to highlight design units."
14785 (while unit-list
14786 (goto-char (point-min))
14787 (while (re-search-forward
14788 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14789 (when (equal file-name (car (get-text-property
14790 (match-beginning 1) 'speedbar-token)))
14791 (setq pos (or pos (point-marker)))
14792 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14793 (setq unit-list (cdr unit-list)))
14794 pos)
14796 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14797 ent-name ent-file-marker
14798 arch-name arch-file-marker
14799 conf-name conf-file-marker
14800 lib-name depth offset delimiter)
14801 "Insert instantiation entry."
14802 (let ((start (point))
14803 visible-start)
14804 (insert (int-to-string depth) ":")
14805 (put-text-property start (point) 'invisible t)
14806 (setq visible-start (point))
14807 (insert-char ? (* depth speedbar-indentation-width))
14808 (while (> offset 0)
14809 (insert "|")
14810 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14811 (setq offset (1- offset)))
14812 (put-text-property visible-start (point) 'invisible nil)
14813 (setq start (point))
14814 (insert ">")
14815 (speedbar-make-button start (point) nil nil nil)
14816 (setq visible-start (point))
14817 (insert " ")
14818 (setq start (point))
14819 (if (not inst-name)
14820 (insert "(top)")
14821 (insert inst-name)
14822 (speedbar-make-button
14823 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14824 'vhdl-speedbar-find-file inst-file-marker))
14825 (insert delimiter)
14826 (when ent-name
14827 (setq start (point))
14828 (insert ent-name)
14829 (speedbar-make-button
14830 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14831 'vhdl-speedbar-find-file ent-file-marker)
14832 (when arch-name
14833 (insert " (")
14834 (setq start (point))
14835 (insert arch-name)
14836 (speedbar-make-button
14837 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14838 'vhdl-speedbar-find-file arch-file-marker)
14839 (insert ")"))
14840 (when conf-name
14841 (insert " (")
14842 (setq start (point))
14843 (insert conf-name)
14844 (speedbar-make-button
14845 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14846 'vhdl-speedbar-find-file conf-file-marker)
14847 (insert ")")))
14848 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14849 (setq start (point))
14850 (insert " (" lib-name ")")
14851 (put-text-property (+ 2 start) (1- (point)) 'face
14852 'vhdl-speedbar-library-face))
14853 (insert-char ?\n 1)
14854 (put-text-property visible-start (point) 'invisible nil)))
14856 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14857 body-file-marker depth)
14858 "Insert package entry."
14859 (let ((start (point))
14860 visible-start)
14861 (insert (int-to-string depth) ":")
14862 (put-text-property start (point) 'invisible t)
14863 (setq visible-start (point))
14864 (insert-char ? (* depth speedbar-indentation-width))
14865 (put-text-property visible-start (point) 'invisible nil)
14866 (setq start (point))
14867 (insert "[+]")
14868 (speedbar-make-button
14869 start (point) 'speedbar-button-face 'speedbar-highlight-face
14870 'vhdl-speedbar-expand-package pack-key)
14871 (setq visible-start (point))
14872 (insert-char ? 1 nil)
14873 (setq start (point))
14874 (insert pack-name)
14875 (speedbar-make-button
14876 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14877 'vhdl-speedbar-find-file pack-file-marker)
14878 (unless (car pack-file-marker)
14879 (insert "!"))
14880 (when (car body-file-marker)
14881 (insert " (")
14882 (setq start (point))
14883 (insert "body")
14884 (speedbar-make-button
14885 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14886 'vhdl-speedbar-find-file body-file-marker)
14887 (insert ")"))
14888 (insert-char ?\n 1)
14889 (put-text-property visible-start (point) 'invisible nil)))
14891 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14892 pack-body-file-marker depth)
14893 "Insert used package entry."
14894 (let ((start (point))
14895 visible-start)
14896 (insert (int-to-string depth) ":")
14897 (put-text-property start (point) 'invisible t)
14898 (setq visible-start (point))
14899 (insert-char ? (* depth speedbar-indentation-width))
14900 (put-text-property visible-start (point) 'invisible nil)
14901 (setq start (point))
14902 (insert ">")
14903 (speedbar-make-button start (point) nil nil nil)
14904 (setq visible-start (point))
14905 (insert " ")
14906 (setq start (point))
14907 (insert pack-name)
14908 (speedbar-make-button
14909 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14910 'vhdl-speedbar-find-file pack-file-marker)
14911 (when (car pack-body-file-marker)
14912 (insert " (")
14913 (setq start (point))
14914 (insert "body")
14915 (speedbar-make-button
14916 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14917 'vhdl-speedbar-find-file pack-body-file-marker)
14918 (insert ")"))
14919 (setq start (point))
14920 (insert " (" lib-name ")")
14921 (put-text-property (+ 2 start) (1- (point)) 'face
14922 'vhdl-speedbar-library-face)
14923 (insert-char ?\n 1)
14924 (put-text-property visible-start (point) 'invisible nil)))
14926 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14927 func-body-file-marker
14928 depth)
14929 "Insert subprogram entry."
14930 (let ((start (point))
14931 visible-start)
14932 (insert (int-to-string depth) ":")
14933 (put-text-property start (point) 'invisible t)
14934 (setq visible-start (point))
14935 (insert-char ? (* depth speedbar-indentation-width))
14936 (put-text-property visible-start (point) 'invisible nil)
14937 (setq start (point))
14938 (insert ">")
14939 (speedbar-make-button start (point) nil nil nil)
14940 (setq visible-start (point))
14941 (insert " ")
14942 (setq start (point))
14943 (insert func-name)
14944 (speedbar-make-button
14945 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14946 'vhdl-speedbar-find-file func-file-marker)
14947 (when (car func-body-file-marker)
14948 (insert " (")
14949 (setq start (point))
14950 (insert "body")
14951 (speedbar-make-button
14952 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14953 'vhdl-speedbar-find-file func-body-file-marker)
14954 (insert ")"))
14955 (insert-char ?\n 1)
14956 (put-text-property visible-start (point) 'invisible nil)))
14958 (defun vhdl-speedbar-make-title-line (text &optional depth)
14959 "Insert design unit title entry."
14960 (let ((start (point))
14961 visible-start)
14962 (when depth
14963 (insert (int-to-string depth) ":")
14964 (put-text-property start (point) 'invisible t))
14965 (setq visible-start (point))
14966 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14967 (setq start (point))
14968 (insert text)
14969 (speedbar-make-button start (point) nil nil nil nil)
14970 (insert-char ?\n 1)
14971 (put-text-property visible-start (point) 'invisible nil)))
14973 (defun vhdl-speedbar-insert-dirs (files level)
14974 "Insert subdirectories."
14975 (let ((dirs (car files)))
14976 (while dirs
14977 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14978 (car dirs) 'speedbar-dir-follow nil
14979 'speedbar-directory-face level)
14980 (setq dirs (cdr dirs)))))
14982 (defun vhdl-speedbar-dired (text token indent)
14983 "Speedbar click handler for directory expand button in hierarchy mode."
14984 (cond ((string-match "+" text) ; we have to expand this dir
14985 (setq speedbar-shown-directories
14986 (cons (expand-file-name
14987 (concat (speedbar-line-directory indent) token "/"))
14988 speedbar-shown-directories))
14989 (speedbar-change-expand-button-char ?-)
14990 (speedbar-reset-scanners)
14991 (speedbar-with-writable
14992 (save-excursion
14993 (end-of-line) (forward-char 1)
14994 (vhdl-speedbar-insert-dirs
14995 (speedbar-file-lists
14996 (concat (speedbar-line-directory indent) token "/"))
14997 (1+ indent))
14998 (speedbar-reset-scanners)
14999 (vhdl-speedbar-insert-dir-hierarchy
15000 (abbreviate-file-name
15001 (concat (speedbar-line-directory indent) token "/"))
15002 (1+ indent) speedbar-power-click)))
15003 (vhdl-speedbar-update-current-unit t t))
15004 ((string-match "-" text) ; we have to contract this node
15005 (speedbar-reset-scanners)
15006 (let ((oldl speedbar-shown-directories)
15007 (newl nil)
15008 (td (expand-file-name
15009 (concat (speedbar-line-directory indent) token))))
15010 (while oldl
15011 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15012 (setq newl (cons (car oldl) newl)))
15013 (setq oldl (cdr oldl)))
15014 (setq speedbar-shown-directories (nreverse newl)))
15015 (speedbar-change-expand-button-char ?+)
15016 (speedbar-delete-subblock indent))
15017 (t (error "Nothing to display")))
15018 (when (equal (selected-frame) speedbar-frame)
15019 (speedbar-center-buffer-smartly)))
15021 (defun vhdl-speedbar-item-info ()
15022 "Derive and display information about this line item."
15023 (save-excursion
15024 (beginning-of-line)
15025 ;; skip invisible number info
15026 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15027 (cond
15028 ;; project/directory entry
15029 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15030 (if vhdl-speedbar-show-projects
15031 (message "Project \"%s\"" (match-string-no-properties 1))
15032 (speedbar-files-item-info)))
15033 ;; design unit entry
15034 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15035 (goto-char (match-end 1))
15036 (let ((face (get-text-property (point) 'face)))
15037 (message
15038 "%s \"%s\" in \"%s\""
15039 ;; design unit kind
15040 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15041 (eq face 'vhdl-speedbar-entity-selected-face))
15042 (if (equal (match-string 2) ">") "Component" "Entity"))
15043 ((or (eq face 'vhdl-speedbar-architecture-face)
15044 (eq face 'vhdl-speedbar-architecture-selected-face))
15045 "Architecture")
15046 ((or (eq face 'vhdl-speedbar-configuration-face)
15047 (eq face 'vhdl-speedbar-configuration-selected-face))
15048 "Configuration")
15049 ((or (eq face 'vhdl-speedbar-package-face)
15050 (eq face 'vhdl-speedbar-package-selected-face))
15051 "Package")
15052 ((or (eq face 'vhdl-speedbar-instantiation-face)
15053 (eq face 'vhdl-speedbar-instantiation-selected-face))
15054 "Instantiation")
15055 ((eq face 'vhdl-speedbar-subprogram-face)
15056 "Subprogram")
15057 (t ""))
15058 ;; design unit name
15059 (buffer-substring-no-properties
15060 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15061 (match-end 1))
15062 ;; file name
15063 (file-relative-name
15064 (or (car (get-text-property (point) 'speedbar-token))
15065 "?")
15066 (vhdl-default-directory)))))
15067 (t (message "")))))
15069 (defun vhdl-speedbar-line-text ()
15070 "Calls `speedbar-line-text' and removes text properties."
15071 (let ((string (speedbar-line-text)))
15072 (set-text-properties 0 (length string) nil string)
15073 string))
15075 (defun vhdl-speedbar-higher-text ()
15076 "Get speedbar-line-text of higher level."
15077 (let (depth string)
15078 (save-excursion
15079 (beginning-of-line)
15080 (looking-at "^\\([0-9]+\\):")
15081 (setq depth (string-to-number (match-string 1)))
15082 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15083 (setq string (match-string 1))
15084 (set-text-properties 0 (length string) nil string)
15085 string))))
15087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15088 ;; Help functions
15090 (defun vhdl-speedbar-line-key (&optional indent)
15091 "Get currently displayed directory of project name."
15092 (if vhdl-speedbar-show-projects
15093 (vhdl-speedbar-line-project)
15094 (abbreviate-file-name
15095 (file-name-as-directory (speedbar-line-directory indent)))))
15097 (defun vhdl-speedbar-line-project (&optional indent)
15098 "Get currently displayed project name."
15099 (and vhdl-speedbar-show-projects
15100 (save-excursion
15101 (end-of-line)
15102 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15103 (match-string-no-properties 1))))
15105 (defun vhdl-add-modified-file ()
15106 "Add file to `vhdl-modified-file-list'."
15107 (when vhdl-file-alist
15108 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15109 nil)
15111 (defun vhdl-resolve-paths (path-list)
15112 "Resolve path wildcards in PATH-LIST."
15113 (let (path-list-1 path-list-2 path-beg path-end dir)
15114 ;; eliminate non-existent directories
15115 (while path-list
15116 (setq dir (car path-list))
15117 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15118 (if (file-directory-p (match-string 2 dir))
15119 (setq path-list-1 (cons dir path-list-1))
15120 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15121 (setq path-list (cdr path-list)))
15122 ;; resolve path wildcards
15123 (while path-list-1
15124 (setq dir (car path-list-1))
15125 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15126 (progn
15127 (setq path-beg (match-string 1 dir)
15128 path-end (match-string 5 dir))
15129 (setq path-list-1
15130 (append
15131 (mapcar
15132 (function
15133 (lambda (var) (concat path-beg var path-end)))
15134 (let ((all-list (vhdl-directory-files
15135 (match-string 2 dir) t
15136 (concat "\\<" (wildcard-to-regexp
15137 (match-string 4 dir)))))
15138 dir-list)
15139 (while all-list
15140 (when (file-directory-p (car all-list))
15141 (setq dir-list (cons (car all-list) dir-list)))
15142 (setq all-list (cdr all-list)))
15143 dir-list))
15144 (cdr path-list-1))))
15145 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15146 (when (file-directory-p (match-string 2 dir))
15147 (setq path-list-2 (cons dir path-list-2)))
15148 (setq path-list-1 (cdr path-list-1))))
15149 (nreverse path-list-2)))
15151 (defun vhdl-speedbar-goto-this-unit (directory unit)
15152 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15153 (let ((dest (point)))
15154 (if (and (if vhdl-speedbar-show-projects
15155 (progn (goto-char (point-min)) t)
15156 (speedbar-goto-this-file directory))
15157 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15158 (progn (speedbar-position-cursor-on-line)
15160 (goto-char dest)
15161 nil)))
15163 (defun vhdl-speedbar-find-file (text token indent)
15164 "When user clicks on TEXT, load file with name and position in TOKEN.
15165 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15166 is already shown in a buffer."
15167 (if (not (car token))
15168 (error "ERROR: File cannot be found")
15169 (let ((buffer (get-file-buffer (car token))))
15170 (speedbar-find-file-in-frame (car token))
15171 (when (or vhdl-speedbar-jump-to-unit buffer)
15172 (goto-line (cdr token))
15173 (recenter))
15174 (vhdl-speedbar-update-current-unit t t)
15175 (speedbar-set-timer speedbar-update-speed)
15176 (speedbar-maybee-jump-to-attached-frame))))
15178 (defun vhdl-speedbar-port-copy ()
15179 "Copy the port of the entity/component or subprogram under the cursor."
15180 (interactive)
15181 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15182 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15183 (error "ERROR: No entity/component or subprogram under cursor")
15184 (beginning-of-line)
15185 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15186 (condition-case info
15187 (let ((token (get-text-property
15188 (match-beginning 3) 'speedbar-token)))
15189 (vhdl-visit-file (car token) t
15190 (progn (goto-line (cdr token))
15191 (end-of-line)
15192 (if is-entity
15193 (vhdl-port-copy)
15194 (vhdl-subprog-copy)))))
15195 (error (error "ERROR: %s not scanned successfully\n (%s)"
15196 (if is-entity "Port" "Interface") (cadr info))))
15197 (error "ERROR: No entity/component or subprogram on current line")))))
15199 (defun vhdl-speedbar-place-component ()
15200 "Place the entity/component under the cursor as component."
15201 (interactive)
15202 (if (not (vhdl-speedbar-check-unit 'entity))
15203 (error "ERROR: No entity/component under cursor")
15204 (vhdl-speedbar-port-copy)
15205 (if (fboundp 'speedbar-select-attached-frame)
15206 (speedbar-select-attached-frame)
15207 (select-frame speedbar-attached-frame))
15208 (vhdl-compose-place-component)
15209 (select-frame speedbar-frame)))
15211 (defun vhdl-speedbar-configuration ()
15212 "Generate configuration for the architecture under the cursor."
15213 (interactive)
15214 (if (not (vhdl-speedbar-check-unit 'architecture))
15215 (error "ERROR: No architecture under cursor")
15216 (let ((arch-name (vhdl-speedbar-line-text))
15217 (ent-name (vhdl-speedbar-higher-text)))
15218 (if (fboundp 'speedbar-select-attached-frame)
15219 (speedbar-select-attached-frame)
15220 (select-frame speedbar-attached-frame))
15221 (vhdl-compose-configuration ent-name arch-name))))
15223 (defun vhdl-speedbar-select-mra ()
15224 "Select the architecture under the cursor as MRA."
15225 (interactive)
15226 (if (not (vhdl-speedbar-check-unit 'architecture))
15227 (error "ERROR: No architecture under cursor")
15228 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15229 (ent-key (downcase (vhdl-speedbar-higher-text)))
15230 (ent-alist (aget vhdl-entity-alist
15231 (or (vhdl-project-p) default-directory) t))
15232 (ent-entry (aget ent-alist ent-key t)))
15233 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15234 (speedbar-refresh))))
15236 (defun vhdl-speedbar-make-design ()
15237 "Make (compile) design unit or directory/project under the cursor."
15238 (interactive)
15239 (if (not (save-excursion (beginning-of-line)
15240 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15241 (error "ERROR: No primary design unit or directory/project under cursor")
15242 (let ((is-unit (match-string 2))
15243 (unit-name (vhdl-speedbar-line-text))
15244 (vhdl-project (vhdl-speedbar-line-project))
15245 (directory (file-name-as-directory
15246 (or (speedbar-line-file) (speedbar-line-directory)))))
15247 (if (fboundp 'speedbar-select-attached-frame)
15248 (speedbar-select-attached-frame)
15249 (select-frame speedbar-attached-frame))
15250 (let ((default-directory directory))
15251 (vhdl-make (and is-unit unit-name))))))
15253 (defun vhdl-speedbar-generate-makefile ()
15254 "Generate Makefile for directory/project under the cursor."
15255 (interactive)
15256 (let ((vhdl-project (vhdl-speedbar-line-project))
15257 (default-directory (file-name-as-directory
15258 (or (speedbar-line-file) (speedbar-line-directory)))))
15259 (vhdl-generate-makefile)))
15261 (defun vhdl-speedbar-check-unit (design-unit)
15262 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15263 expansion function)."
15264 (save-excursion
15265 (speedbar-position-cursor-on-line)
15266 (cond ((eq design-unit 'entity)
15267 (memq (get-text-property (match-end 0) 'face)
15268 '(vhdl-speedbar-entity-face
15269 vhdl-speedbar-entity-selected-face)))
15270 ((eq design-unit 'architecture)
15271 (memq (get-text-property (match-end 0) 'face)
15272 '(vhdl-speedbar-architecture-face
15273 vhdl-speedbar-architecture-selected-face)))
15274 ((eq design-unit 'subprogram)
15275 (eq (get-text-property (match-end 0) 'face)
15276 'vhdl-speedbar-subprogram-face))
15277 (t nil))))
15279 (defun vhdl-speedbar-set-depth (depth)
15280 "Set hierarchy display depth to DEPTH and refresh speedbar."
15281 (setq vhdl-speedbar-hierarchy-depth depth)
15282 (speedbar-refresh))
15284 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15285 ;; Fontification
15287 (defface vhdl-speedbar-entity-face
15288 '((((class color) (background light)) (:foreground "ForestGreen"))
15289 (((class color) (background dark)) (:foreground "PaleGreen")))
15290 "Face used for displaying entity names."
15291 :group 'speedbar-faces)
15293 (defface vhdl-speedbar-architecture-face
15294 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15295 (((class color) (background light)) (:foreground "Blue"))
15297 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15298 "Face used for displaying architecture names."
15299 :group 'speedbar-faces)
15301 (defface vhdl-speedbar-configuration-face
15302 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15303 (((class color) (background dark)) (:foreground "Salmon")))
15304 "Face used for displaying configuration names."
15305 :group 'speedbar-faces)
15307 (defface vhdl-speedbar-package-face
15308 '((((class color) (background light)) (:foreground "Grey50"))
15309 (((class color) (background dark)) (:foreground "Grey80")))
15310 "Face used for displaying package names."
15311 :group 'speedbar-faces)
15313 (defface vhdl-speedbar-library-face
15314 '((((class color) (background light)) (:foreground "Purple"))
15315 (((class color) (background dark)) (:foreground "Orchid1")))
15316 "Face used for displaying library names."
15317 :group 'speedbar-faces)
15319 (defface vhdl-speedbar-instantiation-face
15320 '((((class color) (background light)) (:foreground "Brown"))
15321 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15322 (((class color) (background dark)) (:foreground "Yellow")))
15323 "Face used for displaying instantiation names."
15324 :group 'speedbar-faces)
15326 (defface vhdl-speedbar-subprogram-face
15327 '((((class color) (background light)) (:foreground "Orchid4"))
15328 (((class color) (background dark)) (:foreground "BurlyWood2")))
15329 "Face used for displaying subprogram names."
15330 :group 'speedbar-faces)
15332 (defface vhdl-speedbar-entity-selected-face
15333 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15334 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15335 "Face used for displaying entity names."
15336 :group 'speedbar-faces)
15338 (defface vhdl-speedbar-architecture-selected-face
15339 '((((min-colors 88) (class color) (background light)) (:foreground
15340 "Blue1" :underline t))
15341 (((class color) (background light)) (:foreground "Blue" :underline t))
15342 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15343 "Face used for displaying architecture names."
15344 :group 'speedbar-faces)
15346 (defface vhdl-speedbar-configuration-selected-face
15347 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15348 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15349 "Face used for displaying configuration names."
15350 :group 'speedbar-faces)
15352 (defface vhdl-speedbar-package-selected-face
15353 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15354 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15355 "Face used for displaying package names."
15356 :group 'speedbar-faces)
15358 (defface vhdl-speedbar-instantiation-selected-face
15359 '((((class color) (background light)) (:foreground "Brown" :underline t))
15360 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15361 "Face used for displaying instantiation names."
15362 :group 'speedbar-faces)
15364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15365 ;; Initialization
15367 ;; add speedbar
15368 (when (fboundp 'speedbar)
15369 (condition-case ()
15370 (when (and vhdl-speedbar-auto-open
15371 (not (and (boundp 'speedbar-frame)
15372 (frame-live-p speedbar-frame))))
15373 (speedbar-frame-mode 1)
15374 (if (fboundp 'speedbar-select-attached-frame)
15375 (speedbar-select-attached-frame)
15376 (select-frame speedbar-attached-frame)))
15377 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15379 ;; initialize speedbar
15380 (if (not (boundp 'speedbar-frame))
15381 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15382 (vhdl-speedbar-initialize)
15383 (when speedbar-frame (vhdl-speedbar-refresh)))
15386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15387 ;;; Structural composition
15388 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15390 (defun vhdl-get-components-package-name ()
15391 "Return the name of the components package."
15392 (let ((project (vhdl-project-p)))
15393 (if project
15394 (vhdl-replace-string (car vhdl-components-package-name)
15395 (subst-char-in-string ? ?_ project))
15396 (cdr vhdl-components-package-name))))
15398 (defun vhdl-compose-new-component ()
15399 "Create entity and architecture for new component."
15400 (interactive)
15401 (let* ((case-fold-search t)
15402 (ent-name (read-from-minibuffer "entity name: "
15403 nil vhdl-minibuffer-local-map))
15404 (arch-name
15405 (if (equal (cdr vhdl-compose-architecture-name) "")
15406 (read-from-minibuffer "architecture name: "
15407 nil vhdl-minibuffer-local-map)
15408 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15409 ent-file-name arch-file-name ent-buffer arch-buffer project)
15410 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15411 ;; open entity file
15412 (unless (eq vhdl-compose-create-files 'none)
15413 (setq ent-file-name
15414 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15415 "." (file-name-extension (buffer-file-name))))
15416 (when (and (file-exists-p ent-file-name)
15417 (not (y-or-n-p (concat "File \"" ent-file-name
15418 "\" exists; overwrite? "))))
15419 (error "ERROR: Creating component...aborted"))
15420 (find-file ent-file-name)
15421 (erase-buffer)
15422 (set-buffer-modified-p nil))
15423 ;; insert header
15424 (if vhdl-compose-include-header
15425 (progn (vhdl-template-header)
15426 (goto-char (point-max)))
15427 (vhdl-comment-display-line) (insert "\n\n"))
15428 ;; insert library clause
15429 (vhdl-template-package-std-logic-1164)
15430 (when vhdl-use-components-package
15431 (insert "\n")
15432 (vhdl-template-standard-package (vhdl-work-library)
15433 (vhdl-get-components-package-name)))
15434 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15435 ;; insert entity declaration
15436 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15437 (vhdl-insert-keyword " IS\n")
15438 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15439 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15440 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15441 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15442 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15443 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15444 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15445 (vhdl-insert-keyword "END ")
15446 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15447 (insert ent-name ";\n\n")
15448 (vhdl-comment-display-line) (insert "\n")
15449 ;; open architecture file
15450 (if (not (eq vhdl-compose-create-files 'separate))
15451 (insert "\n")
15452 (setq ent-buffer (current-buffer))
15453 (setq arch-file-name
15454 (concat (vhdl-replace-string vhdl-architecture-file-name
15455 (concat ent-name " " arch-name) t)
15456 "." (file-name-extension (buffer-file-name))))
15457 (when (and (file-exists-p arch-file-name)
15458 (not (y-or-n-p (concat "File \"" arch-file-name
15459 "\" exists; overwrite? "))))
15460 (error "ERROR: Creating component...aborted"))
15461 (find-file arch-file-name)
15462 (erase-buffer)
15463 (set-buffer-modified-p nil)
15464 ;; insert header
15465 (if vhdl-compose-include-header
15466 (progn (vhdl-template-header)
15467 (goto-char (point-max)))
15468 (vhdl-comment-display-line) (insert "\n\n")))
15469 ;; insert architecture body
15470 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15471 (vhdl-insert-keyword " OF ") (insert ent-name)
15472 (vhdl-insert-keyword " IS\n\n")
15473 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15474 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15475 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15476 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15477 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15478 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15479 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15480 (vhdl-insert-keyword "BEGIN")
15481 (when vhdl-self-insert-comments
15482 (insert " -- ")
15483 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15484 (insert arch-name))
15485 (insert "\n\n")
15486 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15487 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15488 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15489 (vhdl-insert-keyword "END ")
15490 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15491 (insert arch-name ";\n\n")
15492 ;; insert footer and save
15493 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15494 (vhdl-template-footer)
15495 (vhdl-comment-display-line) (insert "\n"))
15496 (goto-char (point-min))
15497 (setq arch-buffer (current-buffer))
15498 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15499 (set-buffer arch-buffer) (save-buffer)
15500 (message "%s"
15501 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15502 (and ent-file-name
15503 (format "\n File created: \"%s\"" ent-file-name))
15504 (and arch-file-name
15505 (format "\n File created: \"%s\"" arch-file-name))))))
15507 (defun vhdl-compose-place-component ()
15508 "Place new component by pasting current port as component declaration and
15509 component instantiation."
15510 (interactive)
15511 (if (not vhdl-port-list)
15512 (error "ERROR: No port has been read")
15513 (save-excursion
15514 (vhdl-prepare-search-2
15515 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15516 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15517 (error "ERROR: No architecture found"))
15518 (let* ((ent-name (match-string 1))
15519 (ent-file-name
15520 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15521 "." (file-name-extension (buffer-file-name))))
15522 (orig-buffer (current-buffer)))
15523 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15524 ;; place component declaration
15525 (unless (or vhdl-use-components-package
15526 (vhdl-use-direct-instantiation)
15527 (save-excursion
15528 (re-search-forward
15529 (concat "^\\s-*component\\s-+"
15530 (car vhdl-port-list) "\\>") nil t)))
15531 (re-search-forward "^begin\\>" nil)
15532 (beginning-of-line)
15533 (skip-chars-backward " \t\n")
15534 (insert "\n\n") (indent-to vhdl-basic-offset)
15535 (vhdl-port-paste-component t))
15536 ;; place component instantiation
15537 (re-search-forward "^end\\>" nil)
15538 (beginning-of-line)
15539 (skip-chars-backward " \t\n")
15540 (insert "\n\n") (indent-to vhdl-basic-offset)
15541 (vhdl-port-paste-instance nil t t)
15542 ;; place use clause for used packages
15543 (when (nth 3 vhdl-port-list)
15544 ;; open entity file
15545 (when (file-exists-p ent-file-name)
15546 (find-file ent-file-name))
15547 (goto-char (point-min))
15548 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15549 (error "ERROR: Entity not found: \"%s\"" ent-name))
15550 (goto-char (match-beginning 0))
15551 (if (and (save-excursion
15552 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15553 (match-string 1))
15554 (progn (goto-char (match-end 0))
15555 (beginning-of-line 2))
15556 (insert "\n")
15557 (backward-char))
15558 (vhdl-port-paste-context-clause)
15559 (switch-to-buffer orig-buffer))
15560 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15562 (defun vhdl-compose-wire-components ()
15563 "Connect components."
15564 (interactive)
15565 (save-excursion
15566 (vhdl-prepare-search-2
15567 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15568 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15569 (error "ERROR: No architecture found"))
15570 (let* ((ent-name (match-string 1))
15571 (ent-file-name
15572 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15573 "." (file-name-extension (buffer-file-name))))
15574 (arch-decl-pos (point-marker))
15575 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15576 (arch-end-pos (re-search-forward "^end\\>" nil))
15577 (pack-name (vhdl-get-components-package-name))
15578 (pack-file-name
15579 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15580 "." (file-name-extension (buffer-file-name))))
15581 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15582 port-alist generic-alist inst-alist
15583 signal-name signal-entry signal-alist local-list written-list
15584 single-in-list multi-in-list single-out-list multi-out-list
15585 constant-name constant-entry constant-alist single-list multi-list
15586 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15587 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15588 signal-beg-pos signal-pos
15589 constant-temp-pos port-temp-pos signal-temp-pos)
15590 (message "Wiring components...")
15591 ;; process all instances
15592 (goto-char arch-stat-pos)
15593 (while (re-search-forward
15594 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15595 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15596 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15597 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15598 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15599 (setq inst-name (match-string-no-properties 1)
15600 comp-name (match-string-no-properties 4)
15601 comp-ent-name (match-string-no-properties 12)
15602 has-generic (or (match-string 7) (match-string 17)))
15603 ;; get port ...
15604 (if comp-name
15605 ;; ... from component declaration
15606 (vhdl-visit-file
15607 (when vhdl-use-components-package pack-file-name) t
15608 (save-excursion
15609 (goto-char (point-min))
15610 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15611 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15612 (vhdl-port-copy)))
15613 ;; ... from entity declaration (direct instantiation)
15614 (setq comp-ent-file-name
15615 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15616 "." (file-name-extension (buffer-file-name))))
15617 (vhdl-visit-file
15618 comp-ent-file-name t
15619 (save-excursion
15620 (goto-char (point-min))
15621 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15622 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15623 (vhdl-port-copy))))
15624 (vhdl-port-flatten t)
15625 (setq generic-alist (nth 1 vhdl-port-list)
15626 port-alist (nth 2 vhdl-port-list)
15627 vhdl-port-list nil)
15628 (setq constant-alist nil
15629 signal-alist nil)
15630 (when has-generic
15631 ;; process all constants in generic map
15632 (vhdl-forward-syntactic-ws)
15633 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15634 (setq constant-name (match-string-no-properties 3))
15635 (setq constant-entry
15636 (cons constant-name
15637 (if (match-string 1)
15638 (or (aget generic-alist (match-string 2) t)
15639 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15640 (cdar generic-alist))))
15641 (setq constant-alist (cons constant-entry constant-alist))
15642 (setq constant-name (downcase constant-name))
15643 (if (or (member constant-name single-list)
15644 (member constant-name multi-list))
15645 (progn (setq single-list (delete constant-name single-list))
15646 (add-to-list 'multi-list constant-name))
15647 (add-to-list 'single-list constant-name))
15648 (unless (match-string 1)
15649 (setq generic-alist (cdr generic-alist)))
15650 (vhdl-forward-syntactic-ws))
15651 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15652 ;; process all signals in port map
15653 (vhdl-forward-syntactic-ws)
15654 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15655 (setq signal-name (match-string-no-properties 3))
15656 (setq signal-entry (cons signal-name
15657 (if (match-string 1)
15658 (or (aget port-alist (match-string 2) t)
15659 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15660 (cdar port-alist))))
15661 (setq signal-alist (cons signal-entry signal-alist))
15662 (setq signal-name (downcase signal-name))
15663 (if (equal (upcase (nth 2 signal-entry)) "IN")
15664 ;; input signal
15665 (cond
15666 ((member signal-name local-list)
15667 nil)
15668 ((or (member signal-name single-out-list)
15669 (member signal-name multi-out-list))
15670 (setq single-out-list (delete signal-name single-out-list))
15671 (setq multi-out-list (delete signal-name multi-out-list))
15672 (add-to-list 'local-list signal-name))
15673 ((member signal-name single-in-list)
15674 (setq single-in-list (delete signal-name single-in-list))
15675 (add-to-list 'multi-in-list signal-name))
15676 ((not (member signal-name multi-in-list))
15677 (add-to-list 'single-in-list signal-name)))
15678 ;; output signal
15679 (cond
15680 ((member signal-name local-list)
15681 nil)
15682 ((or (member signal-name single-in-list)
15683 (member signal-name multi-in-list))
15684 (setq single-in-list (delete signal-name single-in-list))
15685 (setq multi-in-list (delete signal-name multi-in-list))
15686 (add-to-list 'local-list signal-name))
15687 ((member signal-name single-out-list)
15688 (setq single-out-list (delete signal-name single-out-list))
15689 (add-to-list 'multi-out-list signal-name))
15690 ((not (member signal-name multi-out-list))
15691 (add-to-list 'single-out-list signal-name))))
15692 (unless (match-string 1)
15693 (setq port-alist (cdr port-alist)))
15694 (vhdl-forward-syntactic-ws))
15695 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15696 (nreverse signal-alist)) inst-alist)))
15697 ;; prepare signal insertion
15698 (vhdl-goto-marker arch-decl-pos)
15699 (forward-line 1)
15700 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15701 (setq signal-pos (point-marker))
15702 (while (progn (vhdl-forward-syntactic-ws)
15703 (looking-at "signal\\>"))
15704 (beginning-of-line 2)
15705 (delete-region signal-pos (point)))
15706 (setq signal-beg-pos signal-pos)
15707 ;; open entity file
15708 (when (file-exists-p ent-file-name)
15709 (find-file ent-file-name))
15710 (goto-char (point-min))
15711 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15712 (error "ERROR: Entity not found: \"%s\"" ent-name))
15713 ;; prepare generic clause insertion
15714 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15715 (match-string 1))
15716 (goto-char (match-beginning 0))
15717 (indent-to vhdl-basic-offset)
15718 (insert "generic ();\n\n")
15719 (backward-char 4))
15720 (backward-char)
15721 (setq generic-pos (point-marker))
15722 (forward-sexp) (end-of-line)
15723 (delete-region generic-pos (point)) (delete-char 1)
15724 (insert "(\n")
15725 (when multi-list
15726 (insert "\n")
15727 (indent-to (* 2 vhdl-basic-offset))
15728 (insert "-- global generics\n"))
15729 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15730 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15731 ;; prepare port clause insertion
15732 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15733 (match-string 1))
15734 (goto-char (match-beginning 0))
15735 (indent-to vhdl-basic-offset)
15736 (insert "port ();\n\n")
15737 (backward-char 4))
15738 (backward-char)
15739 (setq port-in-pos (point-marker))
15740 (forward-sexp) (end-of-line)
15741 (delete-region port-in-pos (point)) (delete-char 1)
15742 (insert "(\n")
15743 (when (or multi-in-list multi-out-list)
15744 (insert "\n")
15745 (indent-to (* 2 vhdl-basic-offset))
15746 (insert "-- global ports\n"))
15747 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15748 port-out-pos (point-marker) port-inst-pos (point-marker)
15749 port-end-pos (point-marker))
15750 ;; insert generics, ports and signals
15751 (setq inst-alist (nreverse inst-alist))
15752 (while inst-alist
15753 (setq inst-name (nth 0 (car inst-alist))
15754 constant-alist (nth 1 (car inst-alist))
15755 signal-alist (nth 2 (car inst-alist))
15756 constant-temp-pos generic-inst-pos
15757 port-temp-pos port-inst-pos
15758 signal-temp-pos signal-pos)
15759 ;; generics
15760 (while constant-alist
15761 (setq constant-name (downcase (caar constant-alist))
15762 constant-entry (car constant-alist))
15763 (cond ((member constant-name written-list)
15764 nil)
15765 ((member constant-name multi-list)
15766 (vhdl-goto-marker generic-pos)
15767 (setq generic-end-pos
15768 (vhdl-max-marker
15769 generic-end-pos
15770 (vhdl-compose-insert-generic constant-entry)))
15771 (setq generic-pos (point-marker))
15772 (add-to-list 'written-list constant-name))
15774 (vhdl-goto-marker
15775 (vhdl-max-marker generic-inst-pos generic-pos))
15776 (setq generic-end-pos
15777 (vhdl-compose-insert-generic constant-entry))
15778 (setq generic-inst-pos (point-marker))
15779 (add-to-list 'written-list constant-name)))
15780 (setq constant-alist (cdr constant-alist)))
15781 (when (/= constant-temp-pos generic-inst-pos)
15782 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15783 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15784 (insert "-- generics for \"" inst-name "\"\n")
15785 (vhdl-goto-marker generic-inst-pos))
15786 ;; ports and signals
15787 (while signal-alist
15788 (setq signal-name (downcase (caar signal-alist))
15789 signal-entry (car signal-alist))
15790 (cond ((member signal-name written-list)
15791 nil)
15792 ((member signal-name multi-in-list)
15793 (vhdl-goto-marker port-in-pos)
15794 (setq port-end-pos
15795 (vhdl-max-marker
15796 port-end-pos (vhdl-compose-insert-port signal-entry)))
15797 (setq port-in-pos (point-marker))
15798 (add-to-list 'written-list signal-name))
15799 ((member signal-name multi-out-list)
15800 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15801 (setq port-end-pos
15802 (vhdl-max-marker
15803 port-end-pos (vhdl-compose-insert-port signal-entry)))
15804 (setq port-out-pos (point-marker))
15805 (add-to-list 'written-list signal-name))
15806 ((or (member signal-name single-in-list)
15807 (member signal-name single-out-list))
15808 (vhdl-goto-marker
15809 (vhdl-max-marker
15810 port-inst-pos
15811 (vhdl-max-marker port-out-pos port-in-pos)))
15812 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15813 (setq port-inst-pos (point-marker))
15814 (add-to-list 'written-list signal-name))
15815 ((equal (upcase (nth 2 signal-entry)) "OUT")
15816 (vhdl-goto-marker signal-pos)
15817 (vhdl-compose-insert-signal signal-entry)
15818 (setq signal-pos (point-marker))
15819 (add-to-list 'written-list signal-name)))
15820 (setq signal-alist (cdr signal-alist)))
15821 (when (/= port-temp-pos port-inst-pos)
15822 (vhdl-goto-marker
15823 (vhdl-max-marker port-temp-pos
15824 (vhdl-max-marker port-in-pos port-out-pos)))
15825 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15826 (insert "-- ports to \"" inst-name "\"\n")
15827 (vhdl-goto-marker port-inst-pos))
15828 (when (/= signal-temp-pos signal-pos)
15829 (vhdl-goto-marker signal-temp-pos)
15830 (insert "\n") (indent-to vhdl-basic-offset)
15831 (insert "-- outputs of \"" inst-name "\"\n")
15832 (vhdl-goto-marker signal-pos))
15833 (setq inst-alist (cdr inst-alist)))
15834 ;; finalize generic/port clause
15835 (vhdl-goto-marker generic-end-pos) (backward-char)
15836 (when (= generic-beg-pos generic-end-pos)
15837 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15838 (insert ";") (backward-char))
15839 (insert ")")
15840 (vhdl-goto-marker port-end-pos) (backward-char)
15841 (when (= port-beg-pos port-end-pos)
15842 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15843 (insert ";") (backward-char))
15844 (insert ")")
15845 ;; align everything
15846 (when vhdl-auto-align
15847 (vhdl-goto-marker generic-beg-pos)
15848 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15849 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15850 (vhdl-goto-marker signal-beg-pos)
15851 (vhdl-align-region-groups signal-beg-pos signal-pos))
15852 (switch-to-buffer (marker-buffer signal-beg-pos))
15853 (message "Wiring components...done")))))
15855 (defun vhdl-compose-insert-generic (entry)
15856 "Insert ENTRY as generic declaration."
15857 (let (pos)
15858 (indent-to (* 2 vhdl-basic-offset))
15859 (insert (nth 0 entry) " : " (nth 1 entry))
15860 (when (nth 2 entry)
15861 (insert " := " (nth 2 entry)))
15862 (insert ";")
15863 (setq pos (point-marker))
15864 (when (and vhdl-include-port-comments (nth 3 entry))
15865 (vhdl-comment-insert-inline (nth 3 entry) t))
15866 (insert "\n")
15867 pos))
15869 (defun vhdl-compose-insert-port (entry)
15870 "Insert ENTRY as port declaration."
15871 (let (pos)
15872 (indent-to (* 2 vhdl-basic-offset))
15873 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15874 (setq pos (point-marker))
15875 (when (and vhdl-include-port-comments (nth 4 entry))
15876 (vhdl-comment-insert-inline (nth 4 entry) t))
15877 (insert "\n")
15878 pos))
15880 (defun vhdl-compose-insert-signal (entry)
15881 "Insert ENTRY as signal declaration."
15882 (indent-to vhdl-basic-offset)
15883 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15884 (when (and vhdl-include-port-comments (nth 4 entry))
15885 (vhdl-comment-insert-inline (nth 4 entry) t))
15886 (insert "\n"))
15888 (defun vhdl-compose-components-package ()
15889 "Generate a package containing component declarations for all entities in the
15890 current project/directory."
15891 (interactive)
15892 (vhdl-require-hierarchy-info)
15893 (let* ((project (vhdl-project-p))
15894 (pack-name (vhdl-get-components-package-name))
15895 (pack-file-name
15896 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15897 "." (file-name-extension (buffer-file-name))))
15898 (ent-alist (aget vhdl-entity-alist
15899 (or project default-directory) t))
15900 (lazy-lock-minimum-size 0)
15901 clause-pos component-pos)
15902 (message "Generating components package \"%s\"..." pack-name)
15903 ;; open package file
15904 (when (and (file-exists-p pack-file-name)
15905 (not (y-or-n-p (concat "File \"" pack-file-name
15906 "\" exists; overwrite? "))))
15907 (error "ERROR: Generating components package...aborted"))
15908 (find-file pack-file-name)
15909 (erase-buffer)
15910 ;; insert header
15911 (if vhdl-compose-include-header
15912 (progn (vhdl-template-header
15913 (concat "Components package (generated by Emacs VHDL Mode "
15914 vhdl-version ")"))
15915 (goto-char (point-max)))
15916 (vhdl-comment-display-line) (insert "\n\n"))
15917 ;; insert std_logic_1164 package
15918 (vhdl-template-package-std-logic-1164)
15919 (insert "\n") (setq clause-pos (point-marker))
15920 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15921 ;; insert package declaration
15922 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15923 (vhdl-insert-keyword " IS\n\n")
15924 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15925 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15926 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15927 (indent-to vhdl-basic-offset)
15928 (setq component-pos (point-marker))
15929 (insert "\n\n") (vhdl-insert-keyword "END ")
15930 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15931 (insert pack-name ";\n\n")
15932 ;; insert footer
15933 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15934 (vhdl-template-footer)
15935 (vhdl-comment-display-line) (insert "\n"))
15936 ;; insert component declarations
15937 (while ent-alist
15938 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15939 (progn (goto-line (nth 3 (car ent-alist)))
15940 (end-of-line)
15941 (vhdl-port-copy)))
15942 (goto-char component-pos)
15943 (vhdl-port-paste-component t)
15944 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15945 (setq component-pos (point-marker))
15946 (goto-char clause-pos)
15947 (vhdl-port-paste-context-clause pack-name)
15948 (setq clause-pos (point-marker))
15949 (setq ent-alist (cdr ent-alist)))
15950 (goto-char (point-min))
15951 (save-buffer)
15952 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15953 pack-name pack-file-name)))
15955 (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15956 &optional insert-conf)
15957 "Generate block configuration for architecture."
15958 (let ((margin (current-indentation))
15959 (beg (save-excursion (beginning-of-line) (point)))
15960 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15961 ;; insert block configuration (for architecture)
15962 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15963 (setq margin (+ margin vhdl-basic-offset))
15964 ;; process all instances
15965 (while inst-alist
15966 (setq inst-entry (car inst-alist))
15967 ;; is component?
15968 (when (nth 4 inst-entry)
15969 (setq insert-conf t)
15970 (setq inst-path (nth 9 inst-entry))
15971 ;; skip common path with previous instance
15972 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15973 (setq inst-path (cdr inst-path)
15974 inst-prev-path (cdr inst-prev-path)))
15975 ;; insert block configuration end (for previous block/generate)
15976 (while inst-prev-path
15977 (setq margin (- margin vhdl-basic-offset))
15978 (indent-to margin)
15979 (vhdl-insert-keyword "END FOR;\n")
15980 (setq inst-prev-path (cdr inst-prev-path)))
15981 ;; insert block configuration beginning (for current block/generate)
15982 (indent-to margin)
15983 (while inst-path
15984 (setq margin (+ margin vhdl-basic-offset))
15985 (vhdl-insert-keyword "FOR ")
15986 (insert (car inst-path) "\n")
15987 (indent-to margin)
15988 (setq inst-path (cdr inst-path)))
15989 ;; insert component configuration beginning
15990 (vhdl-insert-keyword "FOR ")
15991 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15992 ;; find subconfiguration
15993 (setq conf-key (nth 7 inst-entry))
15994 (setq tmp-alist conf-alist)
15995 ;; use first configuration found for instance's entity
15996 (while (and tmp-alist (null conf-key))
15997 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15998 (setq conf-key (nth 0 (car tmp-alist))))
15999 (setq tmp-alist (cdr tmp-alist)))
16000 (setq conf-entry (aget conf-alist conf-key t))
16001 ;; insert binding indication ...
16002 ;; ... with subconfiguration (if exists)
16003 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16004 (progn
16005 (indent-to (+ margin vhdl-basic-offset))
16006 (vhdl-insert-keyword "USE CONFIGURATION ")
16007 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16008 (insert ";\n"))
16009 ;; ... with entity (if exists)
16010 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16011 (when ent-entry
16012 (indent-to (+ margin vhdl-basic-offset))
16013 (vhdl-insert-keyword "USE ENTITY ")
16014 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16015 ;; insert architecture name (if architecture exists)
16016 (when (nth 3 ent-entry)
16017 (setq arch-name
16018 ;; choose architecture name a) from configuration,
16019 ;; b) from mra, or c) from first architecture
16020 (or (nth 0 (aget (nth 3 ent-entry)
16021 (or (nth 6 inst-entry)
16022 (nth 4 ent-entry)) t))
16023 (nth 1 (car (nth 3 ent-entry)))))
16024 (insert "(" arch-name ")"))
16025 (insert ";\n")
16026 ;; insert block configuration (for architecture of subcomponent)
16027 (when (and vhdl-compose-configuration-hierarchical
16028 (nth 3 ent-entry))
16029 (indent-to (+ margin vhdl-basic-offset))
16030 (vhdl-compose-configuration-architecture
16031 (nth 0 ent-entry) arch-name
16032 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16033 ;; insert component configuration end
16034 (indent-to margin)
16035 (vhdl-insert-keyword "END FOR;\n")
16036 (setq inst-prev-path (nth 9 inst-entry)))
16037 (setq inst-alist (cdr inst-alist)))
16038 ;; insert block configuration end (for block/generate)
16039 (while inst-prev-path
16040 (setq margin (- margin vhdl-basic-offset))
16041 (indent-to margin)
16042 (vhdl-insert-keyword "END FOR;\n")
16043 (setq inst-prev-path (cdr inst-prev-path)))
16044 (indent-to (- margin vhdl-basic-offset))
16045 ;; insert block configuration end or remove beginning (for architecture)
16046 (if insert-conf
16047 (vhdl-insert-keyword "END FOR;\n")
16048 (delete-region beg (point)))))
16050 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16051 "Generate configuration declaration."
16052 (interactive)
16053 (vhdl-require-hierarchy-info)
16054 (let ((ent-alist (aget vhdl-entity-alist
16055 (or (vhdl-project-p) default-directory) t))
16056 (conf-alist (aget vhdl-config-alist
16057 (or (vhdl-project-p) default-directory) t))
16058 (from-speedbar ent-name)
16059 inst-alist conf-name conf-file-name pos)
16060 (vhdl-prepare-search-2
16061 ;; get entity and architecture name
16062 (unless ent-name
16063 (save-excursion
16064 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16065 (not (equal "END" (upcase (match-string 1))))
16066 (setq ent-name (match-string-no-properties 3))
16067 (setq arch-name (match-string-no-properties 2)))
16068 (error "ERROR: Not within an architecture"))))
16069 (setq conf-name (vhdl-replace-string
16070 vhdl-compose-configuration-name
16071 (concat ent-name " " arch-name)))
16072 (setq inst-alist
16073 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16074 (downcase arch-name) t))))
16075 (message "Generating configuration \"%s\"..." conf-name)
16076 (if vhdl-compose-configuration-create-file
16077 ;; open configuration file
16078 (progn
16079 (setq conf-file-name
16080 (concat (vhdl-replace-string vhdl-configuration-file-name
16081 conf-name t)
16082 "." (file-name-extension (buffer-file-name))))
16083 (when (and (file-exists-p conf-file-name)
16084 (not (y-or-n-p (concat "File \"" conf-file-name
16085 "\" exists; overwrite? "))))
16086 (error "ERROR: Creating configuration...aborted"))
16087 (find-file conf-file-name)
16088 (erase-buffer)
16089 (set-buffer-modified-p nil)
16090 ;; insert header
16091 (if vhdl-compose-include-header
16092 (progn (vhdl-template-header
16093 (concat "Configuration declaration for design \""
16094 ent-name "(" arch-name ")\""))
16095 (goto-char (point-max)))
16096 (vhdl-comment-display-line) (insert "\n\n")))
16097 ;; goto end of architecture
16098 (unless from-speedbar
16099 (re-search-forward "^end\\>" nil)
16100 (end-of-line) (insert "\n\n")
16101 (vhdl-comment-display-line) (insert "\n\n")))
16102 ;; insert library clause
16103 (setq pos (point))
16104 (vhdl-template-standard-package (vhdl-work-library) nil)
16105 (when (/= pos (point))
16106 (insert "\n\n"))
16107 ;; insert configuration
16108 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16109 (vhdl-insert-keyword " OF ") (insert ent-name)
16110 (vhdl-insert-keyword " IS\n")
16111 (indent-to vhdl-basic-offset)
16112 ;; insert block configuration (for architecture)
16113 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16114 (vhdl-insert-keyword "END ") (insert conf-name ";")
16115 (when conf-file-name
16116 ;; insert footer and save
16117 (insert "\n\n")
16118 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16119 (vhdl-template-footer)
16120 (vhdl-comment-display-line) (insert "\n"))
16121 (save-buffer))
16122 (message "%s"
16123 (concat (format "Generating configuration \"%s\"...done" conf-name)
16124 (and conf-file-name
16125 (format "\n File created: \"%s\"" conf-file-name))))))
16128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16129 ;;; Compilation / Makefile generation
16130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16131 ;; (using `compile.el')
16133 (defun vhdl-makefile-name ()
16134 "Return the Makefile name of the current project or the current compiler if
16135 no project is defined."
16136 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16137 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16138 (vhdl-replace-string
16139 (cons "\\(.*\\)\n\\(.*\\)"
16140 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16141 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16143 (defun vhdl-compile-directory ()
16144 "Return the directory where compilation/make should be run."
16145 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16146 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16147 (directory (vhdl-resolve-env-variable
16148 (if project
16149 (vhdl-replace-string
16150 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16151 (nth 6 compiler)))))
16152 (file-name-as-directory
16153 (if (file-name-absolute-p directory)
16154 directory
16155 (expand-file-name directory (vhdl-default-directory))))))
16157 (defun vhdl-uniquify (in-list)
16158 "Remove duplicate elements from IN-LIST."
16159 (let (out-list)
16160 (while in-list
16161 (add-to-list 'out-list (car in-list))
16162 (setq in-list (cdr in-list)))
16163 out-list))
16165 (defun vhdl-set-compiler (name)
16166 "Set current compiler to NAME."
16167 (interactive
16168 (list (let ((completion-ignore-case t))
16169 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16170 (if (assoc name vhdl-compiler-alist)
16171 (progn (setq vhdl-compiler name)
16172 (message "Current compiler: \"%s\"" vhdl-compiler))
16173 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16176 ;; Compilation
16178 (defun vhdl-compile-init ()
16179 "Initialize for compilation."
16180 (when (or (null compilation-error-regexp-alist)
16181 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16182 compilation-error-regexp-alist)))
16183 ;; `compilation-error-regexp-alist'
16184 (let ((commands-alist vhdl-compiler-alist)
16185 regexp-alist sublist)
16186 (while commands-alist
16187 (setq sublist (nth 11 (car commands-alist)))
16188 (unless (or (equal "" (car sublist))
16189 (assoc (car sublist) regexp-alist))
16190 (setq regexp-alist (cons (list (nth 0 sublist)
16191 (if (= 0 (nth 1 sublist))
16192 (if vhdl-xemacs 9 nil)
16193 (nth 1 sublist))
16194 (nth 2 sublist) (nth 3 sublist))
16195 regexp-alist)))
16196 (setq commands-alist (cdr commands-alist)))
16197 (setq compilation-error-regexp-alist
16198 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16199 ;; `compilation-file-regexp-alist'
16200 (let ((commands-alist vhdl-compiler-alist)
16201 regexp-alist sublist)
16202 ;; matches vhdl-mode file name output
16203 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16204 (while commands-alist
16205 (setq sublist (nth 12 (car commands-alist)))
16206 (unless (or (equal "" (car sublist))
16207 (assoc (car sublist) regexp-alist))
16208 (setq regexp-alist (cons sublist regexp-alist)))
16209 (setq commands-alist (cdr commands-alist)))
16210 (setq compilation-file-regexp-alist
16211 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16213 (defvar vhdl-compile-file-name nil
16214 "Name of file to be compiled.")
16216 (defun vhdl-compile-print-file-name ()
16217 "Function called within `compile' to print out file name for compilers that
16218 do not print any file names."
16219 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16221 (defun vhdl-get-compile-options (project compiler file-name
16222 &optional file-options-only)
16223 "Get compiler options. Returning nil means do not compile this file."
16224 (let* ((compiler-options (nth 1 compiler))
16225 (project-entry (aget (nth 4 project) vhdl-compiler))
16226 (project-options (nth 0 project-entry))
16227 (exception-list (and file-name (nth 2 project-entry)))
16228 (work-library (vhdl-work-library))
16229 (case-fold-search nil)
16230 file-options)
16231 (while (and exception-list
16232 (not (string-match (caar exception-list) file-name)))
16233 (setq exception-list (cdr exception-list)))
16234 (if (and exception-list (not (cdar exception-list)))
16236 (if (and file-options-only (not exception-list))
16237 'default
16238 (setq file-options (cdar exception-list))
16239 ;; insert library name in compiler-specific options
16240 (setq compiler-options
16241 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16242 work-library))
16243 ;; insert compiler-specific options in project-specific options
16244 (when project-options
16245 (setq project-options
16246 (vhdl-replace-string
16247 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16248 (concat work-library "\n" compiler-options))))
16249 ;; insert project-specific options in file-specific options
16250 (when file-options
16251 (setq file-options
16252 (vhdl-replace-string
16253 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16254 (concat work-library "\n" compiler-options "\n"
16255 project-options))))
16256 ;; return options
16257 (or file-options project-options compiler-options)))))
16259 (defun vhdl-get-make-options (project compiler)
16260 "Get make options."
16261 (let* ((compiler-options (nth 3 compiler))
16262 (project-entry (aget (nth 4 project) vhdl-compiler))
16263 (project-options (nth 1 project-entry))
16264 (makefile-name (vhdl-makefile-name)))
16265 ;; insert Makefile name in compiler-specific options
16266 (setq compiler-options
16267 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16268 makefile-name))
16269 ;; insert compiler-specific options in project-specific options
16270 (when project-options
16271 (setq project-options
16272 (vhdl-replace-string
16273 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16274 (concat makefile-name "\n" compiler-options))))
16275 ;; return options
16276 (or project-options compiler-options)))
16278 (defun vhdl-compile ()
16279 "Compile current buffer using the VHDL compiler specified in
16280 `vhdl-compiler'."
16281 (interactive)
16282 (vhdl-compile-init)
16283 (let* ((project (aget vhdl-project-alist vhdl-project))
16284 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16285 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16286 (command (nth 0 compiler))
16287 (file-name (buffer-file-name))
16288 (options (vhdl-get-compile-options project compiler file-name))
16289 (default-directory (vhdl-compile-directory))
16290 compilation-process-setup-function)
16291 (unless (file-directory-p default-directory)
16292 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16293 ;; put file name into quotes if it contains spaces
16294 (when (string-match " " file-name)
16295 (setq file-name (concat "\"" file-name "\"")))
16296 ;; print out file name if compiler does not
16297 (setq vhdl-compile-file-name (buffer-file-name))
16298 (when (and (= 0 (nth 1 (nth 10 compiler)))
16299 (= 0 (nth 1 (nth 11 compiler))))
16300 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16301 ;; run compilation
16302 (if options
16303 (when command
16304 (compile (concat command " " options " " file-name)))
16305 (vhdl-warning "Your project settings tell me not to compile this file"))))
16307 (defvar vhdl-make-target "all"
16308 "Default target for `vhdl-make' command.")
16310 (defun vhdl-make (&optional target)
16311 "Call make command for compilation of all updated source files (requires
16312 `Makefile'). Optional argument TARGET allows to compile the design
16313 specified by a target."
16314 (interactive)
16315 (setq vhdl-make-target
16316 (or target (read-from-minibuffer "Target: " vhdl-make-target
16317 vhdl-minibuffer-local-map)))
16318 (vhdl-compile-init)
16319 (let* ((project (aget vhdl-project-alist vhdl-project))
16320 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16321 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16322 (command (nth 2 compiler))
16323 (options (vhdl-get-make-options project compiler))
16324 (default-directory (vhdl-compile-directory)))
16325 (unless (file-directory-p default-directory)
16326 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16327 ;; run make
16328 (compile (concat (if (equal command "") "make" command)
16329 " " options " " vhdl-make-target))))
16331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16332 ;; Makefile generation
16334 (defun vhdl-generate-makefile ()
16335 "Generate `Makefile'."
16336 (interactive)
16337 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16338 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16339 (command (nth 4 compiler)))
16340 ;; generate makefile
16341 (if command
16342 (let ((default-directory (vhdl-compile-directory)))
16343 (compile (vhdl-replace-string
16344 (cons "\\(.*\\) \\(.*\\)" command)
16345 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16346 (vhdl-generate-makefile-1))))
16348 (defun vhdl-get-packages (lib-alist work-library)
16349 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16350 (let (pack-list)
16351 (while lib-alist
16352 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16353 (setq pack-list (cons (cdar lib-alist) pack-list)))
16354 (setq lib-alist (cdr lib-alist)))
16355 pack-list))
16357 (defun vhdl-generate-makefile-1 ()
16358 "Generate Makefile for current project or directory."
16359 ;; scan hierarchy if required
16360 (if (vhdl-project-p)
16361 (unless (or (assoc vhdl-project vhdl-file-alist)
16362 (vhdl-load-cache vhdl-project))
16363 (vhdl-scan-project-contents vhdl-project))
16364 (let ((directory (abbreviate-file-name default-directory)))
16365 (unless (or (assoc directory vhdl-file-alist)
16366 (vhdl-load-cache directory))
16367 (vhdl-scan-directory-contents directory))))
16368 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16369 (project (vhdl-project-p))
16370 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16371 (conf-alist (aget vhdl-config-alist (or project directory) t))
16372 (pack-alist (aget vhdl-package-alist (or project directory) t))
16373 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16374 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16375 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16376 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16377 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16378 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16379 (adjust-case (nth 5 regexp-list))
16380 (work-library (downcase (vhdl-work-library)))
16381 (compile-directory (expand-file-name (vhdl-compile-directory)
16382 default-directory))
16383 (makefile-name (vhdl-makefile-name))
16384 rule-alist arch-alist inst-alist
16385 target-list depend-list unit-list prim-list second-list subcomp-list
16386 lib-alist lib-body-alist pack-list all-pack-list
16387 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16388 conf-key conf-file-name pack-key pack-file-name
16389 ent-entry arch-entry conf-entry pack-entry inst-entry
16390 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16391 tmp-key tmp-list rule)
16392 ;; check prerequisites
16393 (unless (file-exists-p compile-directory)
16394 (make-directory compile-directory t))
16395 (unless regexp-list
16396 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16397 vhdl-compiler))
16398 (message "Generating makefile \"%s\"..." makefile-name)
16399 ;; rules for all entities
16400 (setq tmp-list ent-alist)
16401 (while ent-alist
16402 (setq ent-entry (car ent-alist)
16403 ent-key (nth 0 ent-entry))
16404 (when (nth 2 ent-entry)
16405 (setq ent-file-name (file-relative-name
16406 (nth 2 ent-entry) compile-directory)
16407 arch-alist (nth 4 ent-entry)
16408 lib-alist (nth 6 ent-entry)
16409 rule (aget rule-alist ent-file-name)
16410 target-list (nth 0 rule)
16411 depend-list (nth 1 rule)
16412 second-list nil
16413 subcomp-list nil)
16414 (setq tmp-key (vhdl-replace-string
16415 ent-regexp (funcall adjust-case ent-key)))
16416 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16417 ;; rule target for this entity
16418 (setq target-list (cons ent-key target-list))
16419 ;; rule dependencies for all used packages
16420 (setq pack-list (vhdl-get-packages lib-alist work-library))
16421 (setq depend-list (append depend-list pack-list))
16422 (setq all-pack-list pack-list)
16423 ;; add rule
16424 (aput 'rule-alist ent-file-name (list target-list depend-list))
16425 ;; rules for all corresponding architectures
16426 (while arch-alist
16427 (setq arch-entry (car arch-alist)
16428 arch-key (nth 0 arch-entry)
16429 ent-arch-key (concat ent-key "-" arch-key)
16430 arch-file-name (file-relative-name (nth 2 arch-entry)
16431 compile-directory)
16432 inst-alist (nth 4 arch-entry)
16433 lib-alist (nth 5 arch-entry)
16434 rule (aget rule-alist arch-file-name)
16435 target-list (nth 0 rule)
16436 depend-list (nth 1 rule))
16437 (setq tmp-key (vhdl-replace-string
16438 arch-regexp
16439 (funcall adjust-case (concat arch-key " " ent-key))))
16440 (setq unit-list
16441 (cons (cons ent-arch-key tmp-key) unit-list))
16442 (setq second-list (cons ent-arch-key second-list))
16443 ;; rule target for this architecture
16444 (setq target-list (cons ent-arch-key target-list))
16445 ;; rule dependency for corresponding entity
16446 (setq depend-list (cons ent-key depend-list))
16447 ;; rule dependencies for contained component instantiations
16448 (while inst-alist
16449 (setq inst-entry (car inst-alist))
16450 (when (or (null (nth 8 inst-entry))
16451 (equal (downcase (nth 8 inst-entry)) work-library))
16452 (setq inst-ent-key (or (nth 7 inst-entry)
16453 (nth 5 inst-entry)))
16454 (setq depend-list (cons inst-ent-key depend-list)
16455 subcomp-list (cons inst-ent-key subcomp-list)))
16456 (setq inst-alist (cdr inst-alist)))
16457 ;; rule dependencies for all used packages
16458 (setq pack-list (vhdl-get-packages lib-alist work-library))
16459 (setq depend-list (append depend-list pack-list))
16460 (setq all-pack-list (append all-pack-list pack-list))
16461 ;; add rule
16462 (aput 'rule-alist arch-file-name (list target-list depend-list))
16463 (setq arch-alist (cdr arch-alist)))
16464 (setq prim-list (cons (list ent-key second-list
16465 (append subcomp-list all-pack-list))
16466 prim-list)))
16467 (setq ent-alist (cdr ent-alist)))
16468 (setq ent-alist tmp-list)
16469 ;; rules for all configurations
16470 (setq tmp-list conf-alist)
16471 (while conf-alist
16472 (setq conf-entry (car conf-alist)
16473 conf-key (nth 0 conf-entry)
16474 conf-file-name (file-relative-name
16475 (nth 2 conf-entry) compile-directory)
16476 ent-key (nth 4 conf-entry)
16477 arch-key (nth 5 conf-entry)
16478 inst-alist (nth 6 conf-entry)
16479 lib-alist (nth 7 conf-entry)
16480 rule (aget rule-alist conf-file-name)
16481 target-list (nth 0 rule)
16482 depend-list (nth 1 rule)
16483 subcomp-list (list ent-key))
16484 (setq tmp-key (vhdl-replace-string
16485 conf-regexp (funcall adjust-case conf-key)))
16486 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16487 ;; rule target for this configuration
16488 (setq target-list (cons conf-key target-list))
16489 ;; rule dependency for corresponding entity and architecture
16490 (setq depend-list
16491 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16492 ;; rule dependencies for used packages
16493 (setq pack-list (vhdl-get-packages lib-alist work-library))
16494 (setq depend-list (append depend-list pack-list))
16495 ;; rule dependencies for contained component configurations
16496 (while inst-alist
16497 (setq inst-entry (car inst-alist))
16498 (setq inst-ent-key (nth 2 inst-entry)
16499 ; comp-arch-key (nth 2 inst-entry))
16500 inst-conf-key (nth 4 inst-entry))
16501 (when (equal (downcase (nth 5 inst-entry)) work-library)
16502 (when inst-ent-key
16503 (setq depend-list (cons inst-ent-key depend-list)
16504 subcomp-list (cons inst-ent-key subcomp-list)))
16505 ; (when comp-arch-key
16506 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16507 ; depend-list)))
16508 (when inst-conf-key
16509 (setq depend-list (cons inst-conf-key depend-list)
16510 subcomp-list (cons inst-conf-key subcomp-list))))
16511 (setq inst-alist (cdr inst-alist)))
16512 ;; add rule
16513 (aput 'rule-alist conf-file-name (list target-list depend-list))
16514 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16515 prim-list))
16516 (setq conf-alist (cdr conf-alist)))
16517 (setq conf-alist tmp-list)
16518 ;; rules for all packages
16519 (setq tmp-list pack-alist)
16520 (while pack-alist
16521 (setq pack-entry (car pack-alist)
16522 pack-key (nth 0 pack-entry)
16523 pack-body-key nil)
16524 (when (nth 2 pack-entry)
16525 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16526 compile-directory)
16527 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16528 rule (aget rule-alist pack-file-name)
16529 target-list (nth 0 rule) depend-list (nth 1 rule))
16530 (setq tmp-key (vhdl-replace-string
16531 pack-regexp (funcall adjust-case pack-key)))
16532 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16533 ;; rule target for this package
16534 (setq target-list (cons pack-key target-list))
16535 ;; rule dependencies for all used packages
16536 (setq pack-list (vhdl-get-packages lib-alist work-library))
16537 (setq depend-list (append depend-list pack-list))
16538 (setq all-pack-list pack-list)
16539 ;; add rule
16540 (aput 'rule-alist pack-file-name (list target-list depend-list))
16541 ;; rules for this package's body
16542 (when (nth 7 pack-entry)
16543 (setq pack-body-key (concat pack-key "-body")
16544 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16545 compile-directory)
16546 rule (aget rule-alist pack-body-file-name)
16547 target-list (nth 0 rule)
16548 depend-list (nth 1 rule))
16549 (setq tmp-key (vhdl-replace-string
16550 pack-body-regexp (funcall adjust-case pack-key)))
16551 (setq unit-list
16552 (cons (cons pack-body-key tmp-key) unit-list))
16553 ;; rule target for this package's body
16554 (setq target-list (cons pack-body-key target-list))
16555 ;; rule dependency for corresponding package declaration
16556 (setq depend-list (cons pack-key depend-list))
16557 ;; rule dependencies for all used packages
16558 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16559 (setq depend-list (append depend-list pack-list))
16560 (setq all-pack-list (append all-pack-list pack-list))
16561 ;; add rule
16562 (aput 'rule-alist pack-body-file-name
16563 (list target-list depend-list)))
16564 (setq prim-list
16565 (cons (list pack-key (when pack-body-key (list pack-body-key))
16566 all-pack-list)
16567 prim-list)))
16568 (setq pack-alist (cdr pack-alist)))
16569 (setq pack-alist tmp-list)
16570 ;; generate Makefile
16571 (let* ((project (aget vhdl-project-alist project))
16572 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16573 (compiler-id (nth 9 compiler))
16574 (library-directory
16575 (vhdl-resolve-env-variable
16576 (vhdl-replace-string
16577 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16578 compiler-id)))
16579 (makefile-path-name (expand-file-name
16580 makefile-name compile-directory))
16581 (orig-buffer (current-buffer))
16582 cell second-list subcomp-list options unit-key unit-name)
16583 ;; sort lists
16584 (setq unit-list (vhdl-sort-alist unit-list))
16585 (setq prim-list (vhdl-sort-alist prim-list))
16586 (setq tmp-list rule-alist)
16587 (while tmp-list ; pre-sort rule targets
16588 (setq cell (cdar tmp-list))
16589 (setcar cell (sort (car cell) 'string<))
16590 (setq tmp-list (cdr tmp-list)))
16591 (setq rule-alist ; sort by first rule target
16592 (sort rule-alist
16593 (function (lambda (a b)
16594 (string< (car (cadr a)) (car (cadr b)))))))
16595 ;; open and clear Makefile
16596 (set-buffer (find-file-noselect makefile-path-name t t))
16597 (erase-buffer)
16598 (insert "# -*- Makefile -*-\n"
16599 "### " (file-name-nondirectory makefile-name)
16600 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16601 "\n")
16602 (if project
16603 (insert "\n# Project : " (nth 0 project))
16604 (insert "\n# Directory : \"" directory "\""))
16605 (insert "\n# Platform : " vhdl-compiler
16606 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16607 (user-login-name) "\n")
16608 ;; insert compile and option variable settings
16609 (insert "\n\n# Define compilation command and options\n"
16610 "\nCOMPILE = " (nth 0 compiler)
16611 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16612 "\n")
16613 ;; insert library paths
16614 (setq library-directory
16615 (directory-file-name
16616 (if (file-name-absolute-p library-directory)
16617 library-directory
16618 (file-relative-name
16619 (expand-file-name library-directory directory)
16620 compile-directory))))
16621 (insert "\n\n# Define library paths\n"
16622 "\nLIBRARY-" work-library " = " library-directory "\n")
16623 ;; insert variable definitions for all library unit files
16624 (insert "\n\n# Define library unit files\n")
16625 (setq tmp-list unit-list)
16626 (while unit-list
16627 (insert "\nUNIT-" work-library "-" (caar unit-list)
16628 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16629 (setq unit-list (cdr unit-list)))
16630 ;; insert variable definition for list of all library unit files
16631 (insert "\n\n\n# Define list of all library unit files\n"
16632 "\nALL_UNITS =")
16633 (setq unit-list tmp-list)
16634 (while unit-list
16635 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16636 (setq unit-list (cdr unit-list)))
16637 (insert "\n")
16638 (setq unit-list tmp-list)
16639 ;; insert `make all' rule
16640 (insert "\n\n\n# Rule for compiling entire design\n"
16641 "\nall :"
16642 " \\\n\t\tlibrary"
16643 " \\\n\t\t$(ALL_UNITS)\n")
16644 ;; insert `make clean' rule
16645 (insert "\n\n# Rule for cleaning entire design\n"
16646 "\nclean : "
16647 "\n\t-rm -f $(ALL_UNITS)\n")
16648 ;; insert `make library' rule
16649 (insert "\n\n# Rule for creating library directory\n"
16650 "\nlibrary :"
16651 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16652 "\n$(LIBRARY-" work-library ") :"
16653 "\n\t"
16654 (vhdl-replace-string
16655 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16656 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16657 "\n")
16658 ;; insert rule for each library unit
16659 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16660 (while prim-list
16661 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16662 (setq subcomp-list
16663 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16664 (setq unit-key (caar prim-list)
16665 unit-name (or (nth 0 (aget ent-alist unit-key t))
16666 (nth 0 (aget conf-alist unit-key t))
16667 (nth 0 (aget pack-alist unit-key t))))
16668 (insert "\n" unit-key)
16669 (unless (equal unit-key unit-name)
16670 (insert " \\\n" unit-name))
16671 (insert " :"
16672 " \\\n\t\tlibrary"
16673 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16674 (while second-list
16675 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16676 (setq second-list (cdr second-list)))
16677 (while subcomp-list
16678 (when (and (assoc (car subcomp-list) unit-list)
16679 (not (equal unit-key (car subcomp-list))))
16680 (insert " \\\n\t\t" (car subcomp-list)))
16681 (setq subcomp-list (cdr subcomp-list)))
16682 (insert "\n")
16683 (setq prim-list (cdr prim-list)))
16684 ;; insert rule for each library unit file
16685 (insert "\n\n# Rules for compiling single library unit files\n")
16686 (while rule-alist
16687 (setq rule (car rule-alist))
16688 ;; get compiler options for this file
16689 (setq options
16690 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16691 ;; insert rule if file is supposed to be compiled
16692 (setq target-list (nth 1 rule)
16693 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16694 ;; insert targets
16695 (setq tmp-list target-list)
16696 (while target-list
16697 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16698 (if (cdr target-list) " \\" " :"))
16699 (setq target-list (cdr target-list)))
16700 (setq target-list tmp-list)
16701 ;; insert file name as first dependency
16702 (insert " \\\n\t\t" (nth 0 rule))
16703 ;; insert dependencies (except if also target or unit does not exist)
16704 (while depend-list
16705 (when (and (not (member (car depend-list) target-list))
16706 (assoc (car depend-list) unit-list))
16707 (insert " \\\n\t\t"
16708 "$(UNIT-" work-library "-" (car depend-list) ")"))
16709 (setq depend-list (cdr depend-list)))
16710 ;; insert compile command
16711 (if options
16712 (insert "\n\t$(COMPILE) "
16713 (if (eq options 'default) "$(OPTIONS)" options) " "
16714 (nth 0 rule) "\n")
16715 (setq tmp-list target-list)
16716 (while target-list
16717 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16718 (if (cdr target-list) " \\" "\n"))
16719 (setq target-list (cdr target-list)))
16720 (setq target-list tmp-list))
16721 (setq rule-alist (cdr rule-alist)))
16722 (insert "\n\n### " makefile-name " ends here\n")
16723 ;; run Makefile generation hook
16724 (run-hooks 'vhdl-makefile-generation-hook)
16725 (message "Generating makefile \"%s\"...done" makefile-name)
16726 ;; save and close file
16727 (if (file-writable-p makefile-path-name)
16728 (progn (save-buffer)
16729 (kill-buffer (current-buffer))
16730 (set-buffer orig-buffer)
16731 (add-to-history 'file-name-history makefile-path-name))
16732 (vhdl-warning-when-idle
16733 (format "File not writable: \"%s\""
16734 (abbreviate-file-name makefile-path-name)))
16735 (switch-to-buffer (current-buffer))))))
16738 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16739 ;;; Bug reports
16740 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16741 ;; (using `reporter.el')
16743 (defconst vhdl-mode-help-address
16744 "Reto Zimmermann <reto@gnu.org>"
16745 "Address for VHDL Mode bug reports.")
16747 (defun vhdl-submit-bug-report ()
16748 "Submit via mail a bug report on VHDL Mode."
16749 (interactive)
16750 ;; load in reporter
16751 (and
16752 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16753 (let ((reporter-prompt-for-summary-p t))
16754 (reporter-submit-bug-report
16755 vhdl-mode-help-address
16756 (concat "VHDL Mode " vhdl-version)
16757 (list
16758 ;; report all important user options
16759 'vhdl-offsets-alist
16760 'vhdl-comment-only-line-offset
16761 'tab-width
16762 'vhdl-electric-mode
16763 'vhdl-stutter-mode
16764 'vhdl-indent-tabs-mode
16765 'vhdl-project-alist
16766 'vhdl-project
16767 'vhdl-project-file-name
16768 'vhdl-project-auto-load
16769 'vhdl-project-sort
16770 'vhdl-compiler-alist
16771 'vhdl-compiler
16772 'vhdl-compile-use-local-error-regexp
16773 'vhdl-makefile-generation-hook
16774 'vhdl-default-library
16775 'vhdl-standard
16776 'vhdl-basic-offset
16777 'vhdl-upper-case-keywords
16778 'vhdl-upper-case-types
16779 'vhdl-upper-case-attributes
16780 'vhdl-upper-case-enum-values
16781 'vhdl-upper-case-constants
16782 'vhdl-use-direct-instantiation
16783 'vhdl-compose-configuration-name
16784 'vhdl-entity-file-name
16785 'vhdl-architecture-file-name
16786 'vhdl-configuration-file-name
16787 'vhdl-package-file-name
16788 'vhdl-file-name-case
16789 'vhdl-electric-keywords
16790 'vhdl-optional-labels
16791 'vhdl-insert-empty-lines
16792 'vhdl-argument-list-indent
16793 'vhdl-association-list-with-formals
16794 'vhdl-conditions-in-parenthesis
16795 'vhdl-zero-string
16796 'vhdl-one-string
16797 'vhdl-file-header
16798 'vhdl-file-footer
16799 'vhdl-company-name
16800 'vhdl-copyright-string
16801 'vhdl-platform-spec
16802 'vhdl-date-format
16803 'vhdl-modify-date-prefix-string
16804 'vhdl-modify-date-on-saving
16805 'vhdl-reset-kind
16806 'vhdl-reset-active-high
16807 'vhdl-clock-rising-edge
16808 'vhdl-clock-edge-condition
16809 'vhdl-clock-name
16810 'vhdl-reset-name
16811 'vhdl-model-alist
16812 'vhdl-include-port-comments
16813 'vhdl-include-direction-comments
16814 'vhdl-include-type-comments
16815 'vhdl-include-group-comments
16816 'vhdl-actual-port-name
16817 'vhdl-instance-name
16818 'vhdl-testbench-entity-name
16819 'vhdl-testbench-architecture-name
16820 'vhdl-testbench-configuration-name
16821 'vhdl-testbench-dut-name
16822 'vhdl-testbench-include-header
16823 'vhdl-testbench-declarations
16824 'vhdl-testbench-statements
16825 'vhdl-testbench-initialize-signals
16826 'vhdl-testbench-include-library
16827 'vhdl-testbench-include-configuration
16828 'vhdl-testbench-create-files
16829 'vhdl-testbench-entity-file-name
16830 'vhdl-testbench-architecture-file-name
16831 'vhdl-compose-create-files
16832 'vhdl-compose-configuration-create-file
16833 'vhdl-compose-configuration-hierarchical
16834 'vhdl-compose-configuration-use-subconfiguration
16835 'vhdl-compose-include-header
16836 'vhdl-compose-architecture-name
16837 'vhdl-components-package-name
16838 'vhdl-use-components-package
16839 'vhdl-self-insert-comments
16840 'vhdl-prompt-for-comments
16841 'vhdl-inline-comment-column
16842 'vhdl-end-comment-column
16843 'vhdl-auto-align
16844 'vhdl-align-groups
16845 'vhdl-align-group-separate
16846 'vhdl-align-same-indent
16847 'vhdl-highlight-keywords
16848 'vhdl-highlight-names
16849 'vhdl-highlight-special-words
16850 'vhdl-highlight-forbidden-words
16851 'vhdl-highlight-verilog-keywords
16852 'vhdl-highlight-translate-off
16853 'vhdl-highlight-case-sensitive
16854 'vhdl-special-syntax-alist
16855 'vhdl-forbidden-words
16856 'vhdl-forbidden-syntax
16857 'vhdl-directive-keywords
16858 'vhdl-speedbar-auto-open
16859 'vhdl-speedbar-display-mode
16860 'vhdl-speedbar-scan-limit
16861 'vhdl-speedbar-jump-to-unit
16862 'vhdl-speedbar-update-on-saving
16863 'vhdl-speedbar-save-cache
16864 'vhdl-speedbar-cache-file-name
16865 'vhdl-index-menu
16866 'vhdl-source-file-menu
16867 'vhdl-hideshow-menu
16868 'vhdl-hide-all-init
16869 'vhdl-print-two-column
16870 'vhdl-print-customize-faces
16871 'vhdl-intelligent-tab
16872 'vhdl-indent-syntax-based
16873 'vhdl-word-completion-case-sensitive
16874 'vhdl-word-completion-in-minibuffer
16875 'vhdl-underscore-is-part-of-word
16876 'vhdl-mode-hook)
16877 (function
16878 (lambda ()
16879 (insert
16880 (if vhdl-special-indent-hook
16881 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16882 "vhdl-special-indent-hook is set to '"
16883 (format "%s" vhdl-special-indent-hook)
16884 ".\nPerhaps this is your problem?\n"
16885 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16886 "\n"))))
16888 "Hi Reto,"))))
16891 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16892 ;;; Documentation
16893 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16895 (defconst vhdl-doc-release-notes nil
16897 Release Notes for VHDL Mode 3.33
16898 ================================
16900 - New Features
16901 - User Options
16904 New Features
16905 ------------
16907 CONFIGURATION DECLARATION GENERATION:
16908 - Automatic generation of a configuration declaration for a design.
16909 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
16912 User Options
16913 ------------
16915 `vhdl-configuration-file-name': (new)
16916 Specify how the configuration file name is obtained.
16917 `vhdl-compose-configuration-name': (new)
16918 Specify how the configuration name is optained.
16919 `vhdl-compose-configuration-create-file': (new)
16920 Specify whether a new file should be created for a configuration.
16921 `vhdl-compose-configuration-hierarchical': (new)
16922 Specify whether hierarchical configurations should be created.
16923 `vhdl-compose-configuration-use-subconfiguration': (new)
16924 Specify whether subconfigurations should be used inside configurations.
16928 (defconst vhdl-doc-keywords nil
16930 Reserved words in VHDL
16931 ----------------------
16933 VHDL'93 (IEEE Std 1076-1993):
16934 `vhdl-93-keywords' : keywords
16935 `vhdl-93-types' : standardized types
16936 `vhdl-93-attributes' : standardized attributes
16937 `vhdl-93-enum-values' : standardized enumeration values
16938 `vhdl-93-functions' : standardized functions
16939 `vhdl-93-packages' : standardized packages and libraries
16941 VHDL-AMS (IEEE Std 1076.1):
16942 `vhdl-ams-keywords' : keywords
16943 `vhdl-ams-types' : standardized types
16944 `vhdl-ams-attributes' : standardized attributes
16945 `vhdl-ams-enum-values' : standardized enumeration values
16946 `vhdl-ams-functions' : standardized functions
16948 Math Packages (IEEE Std 1076.2):
16949 `vhdl-math-types' : standardized types
16950 `vhdl-math-constants' : standardized constants
16951 `vhdl-math-functions' : standardized functions
16952 `vhdl-math-packages' : standardized packages
16954 Forbidden words:
16955 `vhdl-verilog-keywords' : Verilog reserved words
16957 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16960 (defconst vhdl-doc-coding-style nil
16962 For VHDL coding style and naming convention guidelines, see the following
16963 references:
16965 \[1] Ben Cohen.
16966 \"VHDL Coding Styles and Methodologies\".
16967 Kluwer Academic Publishers, 1999.
16968 http://members.aol.com/vhdlcohen/vhdl/
16970 \[2] Michael Keating and Pierre Bricaud.
16971 \"Reuse Methodology Manual, Second Edition\".
16972 Kluwer Academic Publishers, 1999.
16973 http://www.openmore.com/openmore/rmm2.html
16975 \[3] European Space Agency.
16976 \"VHDL Modelling Guidelines\".
16977 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16979 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16980 to visually support naming conventions.")
16983 (defun vhdl-version ()
16984 "Echo the current version of VHDL Mode in the minibuffer."
16985 (interactive)
16986 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16987 (vhdl-keep-region-active))
16989 (defun vhdl-doc-variable (variable)
16990 "Display VARIABLE's documentation in *Help* buffer."
16991 (interactive)
16992 (unless vhdl-xemacs
16993 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16994 (with-output-to-temp-buffer
16995 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16996 (princ (documentation-property variable 'variable-documentation))
16997 (with-current-buffer standard-output
16998 (help-mode))
16999 (print-help-return-message)))
17001 (defun vhdl-doc-mode ()
17002 "Display VHDL Mode documentation in *Help* buffer."
17003 (interactive)
17004 (unless vhdl-xemacs
17005 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
17006 (with-output-to-temp-buffer
17007 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17008 (princ mode-name)
17009 (princ " mode:\n")
17010 (princ (documentation 'vhdl-mode))
17011 (with-current-buffer standard-output
17012 (help-mode))
17013 (print-help-return-message)))
17016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17018 (provide 'vhdl-mode)
17020 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
17021 ;;; vhdl-mode.el ends here