Fix use of obsolete variables in vhdl-mode.el.
[emacs.git] / lisp / progmodes / vhdl-mode.el
blob0ca3439dd603e1b652bb3e6408cd0e0fcf3f1163
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2012 Free Software Foundation, Inc.
5 ;; Authors: Reto Zimmermann <reto@gnu.org>
6 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
7 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
8 ;; Keywords: languages vhdl
9 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
11 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
12 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
13 ;; filed in the Emacs bug reporting system against this file, a copy
14 ;; of the bug report be sent to the maintainer's email address.
16 (defconst vhdl-version "3.33.28"
17 "VHDL Mode version number.")
19 (defconst vhdl-time-stamp "2010-09-22"
20 "VHDL Mode time stamp for last update.")
22 ;; This file is part of GNU Emacs.
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;; Commentary:
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;; This package provides an Emacs major mode for editing VHDL code.
42 ;; It includes the following features:
44 ;; - Syntax highlighting
45 ;; - Indentation
46 ;; - Template insertion (electrification)
47 ;; - Insertion of file headers
48 ;; - Insertion of user-specified models
49 ;; - Port translation / testbench generation
50 ;; - Structural composition
51 ;; - Configuration generation
52 ;; - Sensitivity list updating
53 ;; - File browser
54 ;; - Design hierarchy browser
55 ;; - Source file compilation (syntax analysis)
56 ;; - Makefile generation
57 ;; - Code hiding
58 ;; - Word/keyword completion
59 ;; - Block commenting
60 ;; - Code fixing/alignment/beautification
61 ;; - PostScript printing
62 ;; - VHDL'87/'93 and VHDL-AMS supported
63 ;; - Comprehensive menu
64 ;; - Fully customizable
65 ;; - Works under GNU Emacs (recommended) and XEmacs
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; Documentation
70 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; Emacs Versions
75 ;; supported: GNU Emacs 20.X/21.X/22.X,23.X, XEmacs 20.X/21.X
76 ;; tested on: GNU Emacs 20.4/21.3/22.1,23.X, XEmacs 21.1 (marginally)
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79 ;; Installation
81 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X/23.X, XEmacs 20.X/21.X.
83 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
84 ;; or into an arbitrary directory that is added to the load path by the
85 ;; following line in your Emacs start-up file `.emacs':
87 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
89 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
90 ;; directory. Otherwise, byte-compile the source file:
91 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
92 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
94 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
95 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
96 ;; (not required in Emacs 20 and higher):
98 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
99 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
101 ;; More detailed installation instructions are included in the official
102 ;; VHDL Mode distribution.
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105 ;; Acknowledgments
107 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
108 ;; and Steve Grout.
110 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
111 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
113 ;; Many thanks to all the users who sent me bug reports and enhancement
114 ;; requests.
115 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
116 ;; enhancement suggestions and the fruitful discussions.
117 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
118 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
120 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
121 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
122 ;; giving me the opportunity to develop this code.
123 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
124 ;; of the Swiss Government.
126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128 ;;; Code:
130 ;; Emacs 21+ handling
131 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
132 "Non-nil if GNU Emacs 21, 22, ... is used.")
133 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
134 "Non-nil if GNU Emacs 22, ... is used.")
136 (defvar compilation-file-regexp-alist)
137 (defvar conf-alist)
138 (defvar conf-entry)
139 (defvar conf-key)
140 (defvar ent-alist)
141 (defvar itimer-version)
142 (defvar lazy-lock-defer-contextually)
143 (defvar lazy-lock-defer-on-scrolling)
144 (defvar lazy-lock-defer-on-the-fly)
145 (defvar speedbar-attached-frame)
148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149 ;;; Variables
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;; help function for user options
153 (defun vhdl-custom-set (variable value &rest functions)
154 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
155 (if (fboundp 'custom-set-default)
156 (custom-set-default variable value)
157 (set-default variable value))
158 (while functions
159 (when (fboundp (car functions)) (funcall (car functions)))
160 (setq functions (cdr functions))))
162 (defun vhdl-widget-directory-validate (widget)
163 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
164 '/' or is empty)."
165 (let ((val (widget-value widget)))
166 (unless (string-match "^\\(\\|.*/\\)$" val)
167 (widget-put widget :error "Invalid directory entry: must end with '/'")
168 widget)))
170 ;; help string for user options
171 (defconst vhdl-name-doc-string "
173 FROM REGEXP is a regular expression matching the original name:
174 \".*\" matches the entire string
175 \"\\(...\\)\" matches a substring
176 TO STRING specifies the string to be inserted as new name:
177 \"\\&\" means substitute entire matched text
178 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
179 Examples:
180 \".*\" \"\\&\" inserts original string
181 \".*\" \"\\&_i\" attaches \"_i\" to original string
182 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
183 \".*\" \"foo\" inserts constant string \"foo\"
184 \".*\" \"\" inserts empty string")
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ;; User variables (customization options)
189 (defgroup vhdl nil
190 "Customizations for VHDL Mode."
191 :prefix "vhdl-"
192 :group 'languages
193 ; :version "21.2" ; comment out for XEmacs
196 (defgroup vhdl-mode nil
197 "Customizations for modes."
198 :group 'vhdl)
200 (defcustom vhdl-indent-tabs-mode nil
201 "Non-nil means indentation can insert tabs.
202 Overrides local variable `indent-tabs-mode'."
203 :type 'boolean
204 :group 'vhdl-mode)
207 (defgroup vhdl-compile nil
208 "Customizations for compilation."
209 :group 'vhdl)
211 (defcustom vhdl-compiler-alist
213 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
214 nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
215 ("\\s-\\([0-9]+\\):" 0 1 0) ("Compiling file \\(.+\\)" 1)
216 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
217 "PACK/\\1.vif" "BODY/\\1.vif" upcase))
218 ;; Aldec
219 ;; COMP96 ERROR COMP96_0078: "Unknown identifier "Addr_Bits"." "<filename>" 40 30
220 ("Aldec" "vcom" "-93 -work \\1" "make" "-f \\1"
221 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
222 (".+?[ \t]+\\(?:ERROR\\)[^:]+:.+?\\(?:.+\"\\(.+?\\)\"[ \t]+\\([0-9]+\\)\\)" 1 2 0) ("" 0)
223 nil)
224 ;; Cadence Leapfrog: cv -file test.vhd
225 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
226 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
227 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
228 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
229 ("\\1/entity" "\\2/\\1" "\\1/configuration"
230 "\\1/package" "\\1/body" downcase))
231 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
232 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
233 ;; (PLL_400X_TOP) is not declared [10.3].
234 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
235 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
236 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
237 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
238 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
239 ;; ghdl vhdl: ghdl test.vhd
240 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
241 nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
242 ("ghdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
243 ("\\1/entity" "\\2/\\1" "\\1/configuration"
244 "\\1/package" "\\1/body" downcase))
245 ;; Ikos Voyager: analyze test.vhd
246 ;; analyze test.vhd
247 ;; E L4/C5: this library unit is inaccessible
248 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
249 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
250 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
251 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
252 nil)
253 ;; ModelSim, Model Technology: vcom test.vhd
254 ;; ERROR: test.vhd(14): Unknown identifier: positiv
255 ;; WARNING[2]: test.vhd(85): Possible infinite loop
256 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
257 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
258 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
259 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
260 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*:\\( *\[[0-9]+\]\\)? \\(.+\\)(\\([0-9]+\\)):" 3 4 0) ("" 0)
261 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
262 "\\1/_primary.dat" "\\1/body.dat" downcase))
263 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
264 ;; test.vhd:34: error message
265 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
266 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
267 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
268 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
269 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
270 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
271 ;; ERROR: test.vhd(24): near "dnd": expecting: END
272 ;; WARNING[4]: test.vhd(30): A space is required between ...
273 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
274 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
275 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
276 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
277 "\\1/_primary.dat" "\\1/body.dat" downcase))
278 ;; Savant: scram -publish-cc test.vhd
279 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
280 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
281 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
282 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
283 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
284 "\\1_config.vhdl" "\\1_package.vhdl"
285 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
286 ;; Simili: vhdlp -work test.vhd
287 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
288 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
289 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
290 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
291 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
292 "\\1/prim.var" "\\1/_body.var" downcase))
293 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
294 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
295 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
296 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
297 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
298 nil)
299 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
300 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
301 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
302 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
303 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
304 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
305 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
306 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
307 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
308 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
309 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
310 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
311 ;; Synplify:
312 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
313 ("Synplify" "n/a" "n/a" "make" "-f \\1"
314 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
315 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
316 nil)
317 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
318 ;; Compiling "test.vhd" line 1...
319 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
320 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
321 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
322 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
323 ("^ *Compiling \"\\(.+\\)\" " 1)
324 nil)
325 ;; VeriBest: vc vhdl test.vhd
326 ;; (no file name printed out!)
327 ;; 32: Z <= A and BitA ;
328 ;; ^^^^
329 ;; [Error] Name BITA is unknown
330 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
331 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
332 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
333 nil)
334 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
335 ;; Compiling "test.vhd" line 1...
336 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
337 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
338 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
339 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
340 ("^ *Compiling \"\\(.+\\)\" " 1)
341 nil)
342 ;; Xilinx XST:
343 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
344 ("Xilinx XST" "xflow" "" "make" "-f \\1"
345 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
346 ("^ERROR:HDLParsers:[0-9]+ - \"\\(.+\\)\" Line \\([0-9]+\\)\." 1 2 0) ("" 0)
347 nil)
349 "List of available VHDL compilers and their properties.
350 Each list entry specifies the following items for a compiler:
351 Compiler:
352 Compiler name : name used in option `vhdl-compiler' to choose compiler
353 Compile command : command used for source file compilation
354 Compile options : compile options (\"\\1\" inserts library name)
355 Make command : command used for compilation using a Makefile
356 Make options : make options (\"\\1\" inserts Makefile name)
357 Generate Makefile: use built-in function or command to generate a Makefile
358 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
359 Library command : command to create library directory \(\"\\1\" inserts
360 library directory, \"\\2\" inserts library name)
361 Compile directory: where compilation is run and the Makefile is placed
362 Library directory: directory of default library
363 Makefile name : name of Makefile (default is \"Makefile\")
364 ID string : compiler identification string (see `vhdl-project-alist')
365 Error message:
366 Regexp : regular expression to match error messages (*)
367 File subexp index: index of subexpression that matches the file name
368 Line subexp index: index of subexpression that matches the line number
369 Column subexp idx: index of subexpression that matches the column number
370 File message:
371 Regexp : regular expression to match a file name message
372 File subexp index: index of subexpression that matches the file name
373 Unit-to-file name mapping: mapping of library unit names to names of files
374 generated by the compiler (used for Makefile generation)
375 To string : string a name is mapped to (\"\\1\" inserts the unit name,
376 \"\\2\" inserts the entity name for architectures)
377 Case adjustment : adjust case of inserted unit names
379 \(*) The regular expression must match the error message starting from the
380 beginning of the line (but not necessarily to the end of the line).
382 Compile options allows insertion of the library name (see `vhdl-project-alist')
383 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
385 For Makefile generation, the built-in function can be used (requires
386 specification of the unit-to-file name mapping). Alternatively, an
387 external command can be specified. Work directory allows specification of
388 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
389 used for Makefile generation). To use another library name than \"work\",
390 customize `vhdl-project-alist'. The library command is inserted in Makefiles
391 to automatically create the library directory if not existent.
393 Compile options, compile directory, library directory, and Makefile name are
394 overwritten by the project settings if a project is defined (see
395 `vhdl-project-alist'). Directory paths are relative to the source file
396 directory.
398 Some compilers do not include the file name in the error message, but print
399 out a file name message in advance. In this case, set \"File Subexp Index\"
400 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
401 If no file name at all is printed out, set both \"File Message\" entries to 0
402 \(a default file name message will be printed out instead, does not work in
403 XEmacs).
405 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
406 assigning its name to option `vhdl-compiler'.
408 Please send any missing or erroneous compiler properties to the maintainer for
409 updating.
411 NOTE: Activate new error and file message regexps and reflect the new setting
412 in the choice list of option `vhdl-compiler' by restarting Emacs."
413 :type '(repeat
414 (list :tag "Compiler" :indent 2
415 (string :tag "Compiler name ")
416 (string :tag "Compile command ")
417 (string :tag "Compile options " "-work \\1")
418 (string :tag "Make command " "make")
419 (string :tag "Make options " "-f \\1")
420 (choice :tag "Generate Makefile "
421 (const :tag "Built-in function" nil)
422 (string :tag "Command" "vmake \\2 > \\1"))
423 (string :tag "Library command " "mkdir \\1")
424 (directory :tag "Compile directory "
425 :validate vhdl-widget-directory-validate "./")
426 (directory :tag "Library directory "
427 :validate vhdl-widget-directory-validate "work/")
428 (file :tag "Makefile name " "Makefile")
429 (string :tag "ID string ")
430 (list :tag "Error message" :indent 4
431 (regexp :tag "Regexp ")
432 (integer :tag "File subexp index")
433 (integer :tag "Line subexp index")
434 (integer :tag "Column subexp idx"))
435 (list :tag "File message" :indent 4
436 (regexp :tag "Regexp ")
437 (integer :tag "File subexp index"))
438 (choice :tag "Unit-to-file name mapping"
439 :format "%t: %[Value Menu%] %v\n"
440 (const :tag "Not defined" nil)
441 (list :tag "To string" :indent 4
442 (string :tag "Entity " "\\1.vhd")
443 (string :tag "Architecture " "\\2_\\1.vhd")
444 (string :tag "Configuration " "\\1.vhd")
445 (string :tag "Package " "\\1.vhd")
446 (string :tag "Package Body " "\\1_body.vhd")
447 (choice :tag "Case adjustment "
448 (const :tag "None" identity)
449 (const :tag "Upcase" upcase)
450 (const :tag "Downcase" downcase))))))
451 :set (lambda (variable value)
452 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
453 :group 'vhdl-compile)
455 (defcustom vhdl-compiler "GHDL"
456 "Specifies the VHDL compiler to be used for syntax analysis.
457 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
458 :type (let ((alist vhdl-compiler-alist) list)
459 (while alist
460 (setq list (cons (list 'const (caar alist)) list))
461 (setq alist (cdr alist)))
462 (append '(choice) (nreverse list)))
463 :group 'vhdl-compile)
465 (defcustom vhdl-compile-use-local-error-regexp t
466 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
467 In this case, only error message regexps for VHDL compilers are active if
468 compilation is started from a VHDL buffer. Otherwise, the error message
469 regexps are appended to the predefined global regexps, and all regexps are
470 active all the time. Note that by doing that, the predefined global regexps
471 might result in erroneous parsing of error messages for some VHDL compilers.
473 NOTE: Activate the new setting by restarting Emacs."
474 :type 'boolean
475 :group 'vhdl-compile)
477 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
478 "List of default target names in Makefiles.
479 Automatically generated Makefiles include three default targets to compile
480 the entire design, clean the entire design and to create the design library.
481 This option allows to change the names of these targets to avoid conflicts
482 with other user Makefiles."
483 :type '(list (string :tag "Compile entire design")
484 (string :tag "Clean entire design ")
485 (string :tag "Create design library"))
486 :group 'vhdl-compile)
488 (defcustom vhdl-makefile-generation-hook nil
489 "Functions to run at the end of Makefile generation.
490 Allows to insert user specific parts into a Makefile.
492 Example:
493 \(lambda nil
494 \(re-search-backward \"^# Rule for compiling entire design\")
495 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
496 :type 'hook
497 :group 'vhdl-compile)
499 (defcustom vhdl-default-library "work"
500 "Name of default library.
501 Is overwritten by project settings if a project is active."
502 :type 'string
503 :group 'vhdl-compile)
506 (defgroup vhdl-project nil
507 "Customizations for projects."
508 :group 'vhdl)
510 (defcustom vhdl-project-alist
511 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
512 "~/example1/" ("src/system/" "src/components/") ""
513 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
514 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
515 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
516 ("Example 2" "Individual source files, multiple compilers in different directories"
517 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
518 nil "\\1/" "work" "\\1/work/" "Makefile" "")
519 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
520 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
521 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
522 -------------------------------------------------------------------------------
523 -- This is a multi-line project description
524 -- that can be used as a project dependent part of the file header.
526 "List of projects and their properties.
527 Name : name used in option `vhdl-project' to choose project
528 Title : title of project (single-line string)
529 Default directory: default project directory (absolute path)
530 Sources : a) source files : path + \"/\" + file name
531 b) directory : path + \"/\"
532 c) directory tree: \"-r \" + path + \"/\"
533 Exclude regexp : matches file/directory names to be excluded as sources
534 Compile options : project-specific options for each compiler
535 Compiler name : name of compiler for which these options are valid
536 Compile options: project-specific compiler options
537 (\"\\1\" inserts library name, \"\\2\" default options)
538 Make options: project-specific make options
539 (\"\\1\" inserts Makefile name, \"\\2\" default options)
540 Exceptions : file-specific exceptions
541 File name regexp: matches file names for which exceptions are valid
542 - Options : file-specific compiler options string
543 (\"\\1\" inserts library name, \"\\2\" default options,
544 \"\\3\" project-specific options)
545 - Do not compile: do not compile this file (in Makefile)
546 Compile directory: where compilation is run and the Makefile is placed
547 \(\"\\1\" inserts compiler ID string)
548 Library name : name of library (default is \"work\")
549 Library directory: path to library (\"\\1\" inserts compiler ID string)
550 Makefile name : name of Makefile
551 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
552 Description : description of project (multi-line string)
554 Project title and description are used to insert into the file header (see
555 option `vhdl-file-header').
557 The default directory must have an absolute path (use `M-TAB' for completion).
558 All other paths can be absolute or relative to the default directory. All
559 paths must end with '/'.
561 The design units found in the sources (files and directories) are shown in the
562 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
563 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
564 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
565 specified, the default directory is taken as source directory. Otherwise,
566 the default directory is only taken as source directory if there is a sources
567 entry with the empty string or \"./\". Exclude regexp allows to filter out
568 specific file and directory names from the list of sources (e.g. CVS
569 directories).
571 Files are compiled in the compile directory. Makefiles are also placed into
572 the compile directory. Library directory specifies which directory the
573 compiler compiles into (used to generate the Makefile).
575 Since different compile/library directories and Makefiles may exist for
576 different compilers within one project, these paths and names allow the
577 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
578 Compile options, compile directory, library directory, and Makefile name
579 overwrite the settings of the current compiler.
581 File-specific compiler options (highest priority) overwrite project-specific
582 options which overwrite default options (lowest priority). Lower priority
583 options can be inserted in higher priority options. This allows to reuse
584 default options (e.g. \"-file\") in project- or file-specific options (e.g.
585 \"-93 -file\").
587 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
588 by restarting Emacs."
589 :type `(repeat
590 (list :tag "Project" :indent 2
591 (string :tag "Name ")
592 (string :tag "Title ")
593 (directory :tag "Default directory"
594 :validate vhdl-widget-directory-validate
595 ,(abbreviate-file-name default-directory))
596 (repeat :tag "Sources " :indent 4
597 (directory :format " %v" "./"))
598 (regexp :tag "Exclude regexp ")
599 (repeat
600 :tag "Compile options " :indent 4
601 (list :tag "Compiler" :indent 6
602 ,(let ((alist vhdl-compiler-alist) list)
603 (while alist
604 (setq list (cons (list 'const (caar alist)) list))
605 (setq alist (cdr alist)))
606 (append '(choice :tag "Compiler name")
607 (nreverse list)))
608 (string :tag "Compile options" "\\2")
609 (string :tag "Make options " "\\2")
610 (repeat
611 :tag "Exceptions " :indent 8
612 (cons :format "%v"
613 (regexp :tag "File name regexp ")
614 (choice :format "%[Value Menu%] %v"
615 (string :tag "Options" "\\3")
616 (const :tag "Do not compile" nil))))))
617 (directory :tag "Compile directory"
618 :validate vhdl-widget-directory-validate "./")
619 (string :tag "Library name " "work")
620 (directory :tag "Library directory"
621 :validate vhdl-widget-directory-validate "work/")
622 (file :tag "Makefile name " "Makefile")
623 (string :tag "Description: (type `C-j' for newline)"
624 :format "%t\n%v\n")))
625 :set (lambda (variable value)
626 (vhdl-custom-set variable value
627 'vhdl-update-mode-menu
628 'vhdl-speedbar-refresh))
629 :group 'vhdl-project)
631 (defcustom vhdl-project nil
632 "Specifies the default for the current project.
633 Select a project name from the ones defined in option `vhdl-project-alist'.
634 Is used to determine the project title and description to be inserted in file
635 headers and the source files/directories to be scanned in the hierarchy
636 browser. The current project can also be changed temporarily in the menu."
637 :type (let ((alist vhdl-project-alist) list)
638 (while alist
639 (setq list (cons (list 'const (caar alist)) list))
640 (setq alist (cdr alist)))
641 (append '(choice (const :tag "None" nil) (const :tag "--"))
642 (nreverse list)))
643 :group 'vhdl-project)
645 (defcustom vhdl-project-file-name '("\\1.prj")
646 "List of file names/paths for importing/exporting project setups.
647 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
648 replaced by the user name (allows to have user-specific project setups).
649 The first entry is used as file name to import/export individual project
650 setups. All entries are used to automatically import project setups at
651 startup (see option `vhdl-project-auto-load'). Projects loaded from the
652 first entry are automatically made current. Hint: specify local project
653 setups in first entry, global setups in following entries; loading a local
654 project setup will make it current, while loading the global setups
655 is done without changing the current project.
656 Names can also have an absolute path (i.e. project setups can be stored
657 in global directories)."
658 :type '(repeat (string :tag "File name" "\\1.prj"))
659 :group 'vhdl-project)
661 (defcustom vhdl-project-auto-load '(startup)
662 "Automatically load project setups from files.
663 All project setup files that match the file names specified in option
664 `vhdl-project-file-name' are automatically loaded. The project of the
665 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
666 entry is activated.
667 A project setup file can be obtained by exporting a project (see menu).
668 At startup: project setup file is loaded at Emacs startup"
669 :type '(set (const :tag "At startup" startup))
670 :group 'vhdl-project)
672 (defcustom vhdl-project-sort t
673 "Non-nil means projects are displayed in alphabetical order."
674 :type 'boolean
675 :group 'vhdl-project)
678 (defgroup vhdl-style nil
679 "Customizations for coding styles."
680 :group 'vhdl
681 :group 'vhdl-template
682 :group 'vhdl-port
683 :group 'vhdl-compose)
685 (defcustom vhdl-standard '(93 nil)
686 "VHDL standards used.
687 Basic standard:
688 VHDL'87 : IEEE Std 1076-1987
689 VHDL'93/02 : IEEE Std 1076-1993/2002
690 Additional standards:
691 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
692 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
694 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
695 \"Activate Options\"."
696 :type '(list (choice :tag "Basic standard"
697 (const :tag "VHDL'87" 87)
698 (const :tag "VHDL'93/02" 93))
699 (set :tag "Additional standards" :indent 2
700 (const :tag "VHDL-AMS" ams)
701 (const :tag "Math packages" math)))
702 :set (lambda (variable value)
703 (vhdl-custom-set variable value
704 'vhdl-template-map-init
705 'vhdl-mode-abbrev-table-init
706 'vhdl-template-construct-alist-init
707 'vhdl-template-package-alist-init
708 'vhdl-update-mode-menu
709 'vhdl-words-init 'vhdl-font-lock-init))
710 :group 'vhdl-style)
712 (defcustom vhdl-basic-offset 2
713 "Amount of basic offset used for indentation.
714 This value is used by + and - symbols in `vhdl-offsets-alist'."
715 :type 'integer
716 :group 'vhdl-style)
718 (defcustom vhdl-upper-case-keywords nil
719 "Non-nil means convert keywords to upper case.
720 This is done when typed or expanded or by the fix case functions."
721 :type 'boolean
722 :set (lambda (variable value)
723 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
724 :group 'vhdl-style)
726 (defcustom vhdl-upper-case-types nil
727 "Non-nil means convert standardized types to upper case.
728 This is done when expanded or by the fix case functions."
729 :type 'boolean
730 :set (lambda (variable value)
731 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
732 :group 'vhdl-style)
734 (defcustom vhdl-upper-case-attributes nil
735 "Non-nil means convert standardized attributes to upper case.
736 This is done when expanded or by the fix case functions."
737 :type 'boolean
738 :set (lambda (variable value)
739 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
740 :group 'vhdl-style)
742 (defcustom vhdl-upper-case-enum-values nil
743 "Non-nil means convert standardized enumeration values to upper case.
744 This is done when expanded or by the fix case functions."
745 :type 'boolean
746 :set (lambda (variable value)
747 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
748 :group 'vhdl-style)
750 (defcustom vhdl-upper-case-constants t
751 "Non-nil means convert standardized constants to upper case.
752 This is done when expanded."
753 :type 'boolean
754 :set (lambda (variable value)
755 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
756 :group 'vhdl-style)
758 (defcustom vhdl-use-direct-instantiation 'standard
759 "Non-nil means use VHDL'93 direct component instantiation.
760 Never : never
761 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
762 Always : always"
763 :type '(choice (const :tag "Never" never)
764 (const :tag "Standard" standard)
765 (const :tag "Always" always))
766 :group 'vhdl-style)
768 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
769 "Non-nil means include array indices / record fields in sensitivity list.
770 If a signal read in a process is a record field or pointed to by an array
771 index, the record field or array index is included with the record name in
772 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
773 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
774 :type 'boolean
775 :group 'vhdl-style)
777 (defgroup vhdl-naming nil
778 "Customizations for naming conventions."
779 :group 'vhdl)
781 (defcustom vhdl-entity-file-name '(".*" . "\\&")
782 (concat
783 "Specifies how the entity file name is obtained.
784 The entity file name can be obtained by modifying the entity name (e.g.
785 attaching or stripping off a substring). The file extension is automatically
786 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-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
794 (concat
795 "Specifies how the architecture file name is obtained.
796 The architecture file name can be obtained by modifying the entity
797 and/or architecture name (e.g. attaching or stripping off a substring). The
798 file extension is automatically taken from the file name of the current
799 buffer. The string that is matched against the regexp is the concatenation
800 of the entity and the architecture name separated by a space. This gives
801 access to both names (see default setting as example)."
802 vhdl-name-doc-string)
803 :type '(cons (regexp :tag "From regexp")
804 (string :tag "To string "))
805 :group 'vhdl-naming
806 :group 'vhdl-compose)
808 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
809 (concat
810 "Specifies how the configuration file name is obtained.
811 The configuration file name can be obtained by modifying the configuration
812 name (e.g. attaching or stripping off a substring). The file extension is
813 automatically taken from the file name of the current buffer."
814 vhdl-name-doc-string)
815 :type '(cons (regexp :tag "From regexp")
816 (string :tag "To string "))
817 :group 'vhdl-naming
818 :group 'vhdl-compose)
820 (defcustom vhdl-package-file-name '(".*" . "\\&")
821 (concat
822 "Specifies how the package file name is obtained.
823 The package file name can be obtained by modifying the package name (e.g.
824 attaching or stripping off a substring). The file extension is automatically
825 taken from the file name of the current buffer. Package files can be created
826 in a different directory by prepending a relative or absolute path to the
827 file name."
828 vhdl-name-doc-string)
829 :type '(cons (regexp :tag "From regexp")
830 (string :tag "To string "))
831 :group 'vhdl-naming
832 :group 'vhdl-compose)
834 (defcustom vhdl-file-name-case 'identity
835 "Specifies how to change case for obtaining file names.
836 When deriving a file name from a VHDL unit name, case can be changed as
837 follows:
838 As Is: case is not changed (taken as is)
839 Lower Case: whole name is changed to lower case
840 Upper Case: whole name is changed to upper case
841 Capitalize: first letter of each word in name is capitalized"
842 :type '(choice (const :tag "As Is" identity)
843 (const :tag "Lower Case" downcase)
844 (const :tag "Upper Case" upcase)
845 (const :tag "Capitalize" capitalize))
846 :group 'vhdl-naming
847 :group 'vhdl-compose)
850 (defgroup vhdl-template nil
851 "Customizations for electrification."
852 :group 'vhdl)
854 (defcustom vhdl-electric-keywords '(vhdl user)
855 "Type of keywords for which electrification is enabled.
856 VHDL keywords: invoke built-in templates
857 User keywords: invoke user models (see option `vhdl-model-alist')"
858 :type '(set (const :tag "VHDL keywords" vhdl)
859 (const :tag "User model keywords" user))
860 :set (lambda (variable value)
861 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
862 :group 'vhdl-template)
864 (defcustom vhdl-optional-labels 'process
865 "Constructs for which labels are to be queried.
866 Template generators prompt for optional labels for:
867 None : no constructs
868 Processes only: processes only (also procedurals in VHDL-AMS)
869 All constructs: all constructs with optional labels and keyword END"
870 :type '(choice (const :tag "None" none)
871 (const :tag "Processes only" process)
872 (const :tag "All constructs" all))
873 :group 'vhdl-template)
875 (defcustom vhdl-insert-empty-lines 'unit
876 "Specifies whether to insert empty lines in some templates.
877 This improves readability of code. Empty lines are inserted in:
878 None : no constructs
879 Design units only: entities, architectures, configurations, packages only
880 All constructs : also all constructs with BEGIN...END parts
882 Replaces option `vhdl-additional-empty-lines'."
883 :type '(choice (const :tag "None" none)
884 (const :tag "Design units only" unit)
885 (const :tag "All constructs" all))
886 :group 'vhdl-template
887 :group 'vhdl-port
888 :group 'vhdl-compose)
890 (defcustom vhdl-argument-list-indent nil
891 "Non-nil means indent argument lists relative to opening parenthesis.
892 That is, argument, association, and port lists start on the same line as the
893 opening parenthesis and subsequent lines are indented accordingly.
894 Otherwise, lists start on a new line and are indented as normal code."
895 :type 'boolean
896 :group 'vhdl-template
897 :group 'vhdl-port
898 :group 'vhdl-compose)
900 (defcustom vhdl-association-list-with-formals t
901 "Non-nil means write association lists with formal parameters.
902 Templates prompt for formal and actual parameters (ports/generics).
903 When pasting component instantiations, formals are included.
904 If nil, only a list of actual parameters is entered."
905 :type 'boolean
906 :group 'vhdl-template
907 :group 'vhdl-port
908 :group 'vhdl-compose)
910 (defcustom vhdl-conditions-in-parenthesis nil
911 "Non-nil means place parenthesis around condition expressions."
912 :type 'boolean
913 :group 'vhdl-template)
915 (defcustom vhdl-zero-string "'0'"
916 "String to use for a logic zero."
917 :type 'string
918 :group 'vhdl-template)
920 (defcustom vhdl-one-string "'1'"
921 "String to use for a logic one."
922 :type 'string
923 :group 'vhdl-template)
926 (defgroup vhdl-header nil
927 "Customizations for file header."
928 :group 'vhdl-template
929 :group 'vhdl-compose)
931 (defcustom vhdl-file-header "\
932 -------------------------------------------------------------------------------
933 -- Title : <title string>
934 -- Project : <project>
935 -------------------------------------------------------------------------------
936 -- File : <filename>
937 -- Author : <author>
938 -- Company : <company>
939 -- Created : <date>
940 -- Last update: <date>
941 -- Platform : <platform>
942 -- Standard : <standard>
943 <projectdesc>-------------------------------------------------------------------------------
944 -- Description: <cursor>
945 <copyright>-------------------------------------------------------------------------------
946 -- Revisions :
947 -- Date Version Author Description
948 -- <date> 1.0 <login>\tCreated
949 -------------------------------------------------------------------------------
952 "String or file to insert as file header.
953 If the string specifies an existing file name, the contents of the file is
954 inserted, otherwise the string itself is inserted as file header.
955 Type `C-j' for newlines.
956 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
957 if the header needs to be version controlled.
959 The following keywords for template generation are supported:
960 <filename> : replaced by the name of the buffer
961 <author> : replaced by the user name and email address
962 \(`user-full-name',`mail-host-address', `user-mail-address')
963 <authorfull> : replaced by the user full name (`user-full-name')
964 <login> : replaced by user login name (`user-login-name')
965 <company> : replaced by contents of option `vhdl-company-name'
966 <date> : replaced by the current date
967 <year> : replaced by the current year
968 <project> : replaced by title of current project (`vhdl-project')
969 <projectdesc> : replaced by description of current project (`vhdl-project')
970 <copyright> : replaced by copyright string (`vhdl-copyright-string')
971 <platform> : replaced by contents of option `vhdl-platform-spec'
972 <standard> : replaced by the VHDL language standard(s) used
973 <... string> : replaced by a queried string (\"...\" is the prompt word)
974 <title string>: replaced by file title in automatically generated files
975 <cursor> : final cursor position
977 The (multi-line) project description <projectdesc> can be used as a project
978 dependent part of the file header and can also contain the above keywords."
979 :type 'string
980 :group 'vhdl-header)
982 (defcustom vhdl-file-footer ""
983 "String or file to insert as file footer.
984 If the string specifies an existing file name, the contents of the file is
985 inserted, otherwise the string itself is inserted as file footer (i.e. at
986 the end of the file).
987 Type `C-j' for newlines.
988 The same keywords as in option `vhdl-file-header' can be used."
989 :type 'string
990 :group 'vhdl-header)
992 (defcustom vhdl-company-name ""
993 "Name of company to insert in file header.
994 See option `vhdl-file-header'."
995 :type 'string
996 :group 'vhdl-header)
998 (defcustom vhdl-copyright-string "\
999 -------------------------------------------------------------------------------
1000 -- Copyright (c) <year> <company>
1002 "Copyright string to insert in file header.
1003 Can be multi-line string (type `C-j' for newline) and contain other file
1004 header keywords (see option `vhdl-file-header')."
1005 :type 'string
1006 :group 'vhdl-header)
1008 (defcustom vhdl-platform-spec ""
1009 "Specification of VHDL platform to insert in file header.
1010 The platform specification should contain names and versions of the
1011 simulation and synthesis tools used.
1012 See option `vhdl-file-header'."
1013 :type 'string
1014 :group 'vhdl-header)
1016 (defcustom vhdl-date-format "%Y-%m-%d"
1017 "Specifies the date format to use in the header.
1018 This string is passed as argument to the command `format-time-string'.
1019 For more information on format strings, see the documentation for the
1020 `format-time-string' command (C-h f `format-time-string')."
1021 :type 'string
1022 :group 'vhdl-header)
1024 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1025 "Prefix string of modification date in VHDL file header.
1026 If actualization of the modification date is called (menu,
1027 `\\[vhdl-template-modify]'), this string is searched and the rest
1028 of the line replaced by the current date."
1029 :type 'string
1030 :group 'vhdl-header)
1032 (defcustom vhdl-modify-date-on-saving t
1033 "Non-nil means update the modification date when the buffer is saved.
1034 Calls function `\\[vhdl-template-modify]').
1036 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1037 \"Activate Options\"."
1038 :type 'boolean
1039 :group 'vhdl-header)
1042 (defgroup vhdl-sequential-process nil
1043 "Customizations for sequential processes."
1044 :group 'vhdl-template)
1046 (defcustom vhdl-reset-kind 'async
1047 "Specifies which kind of reset to use in sequential processes."
1048 :type '(choice (const :tag "None" none)
1049 (const :tag "Synchronous" sync)
1050 (const :tag "Asynchronous" async)
1051 (const :tag "Query" query))
1052 :group 'vhdl-sequential-process)
1054 (defcustom vhdl-reset-active-high nil
1055 "Non-nil means reset in sequential processes is active high.
1056 Otherwise, reset is active low."
1057 :type 'boolean
1058 :group 'vhdl-sequential-process)
1060 (defcustom vhdl-clock-rising-edge t
1061 "Non-nil means rising edge of clock triggers sequential processes.
1062 Otherwise, falling edge triggers."
1063 :type 'boolean
1064 :group 'vhdl-sequential-process)
1066 (defcustom vhdl-clock-edge-condition 'standard
1067 "Syntax of the clock edge condition.
1068 Standard: \"clk'event and clk = '1'\"
1069 Function: \"rising_edge(clk)\""
1070 :type '(choice (const :tag "Standard" standard)
1071 (const :tag "Function" function))
1072 :group 'vhdl-sequential-process)
1074 (defcustom vhdl-clock-name ""
1075 "Name of clock signal to use in templates."
1076 :type 'string
1077 :group 'vhdl-sequential-process)
1079 (defcustom vhdl-reset-name ""
1080 "Name of reset signal to use in templates."
1081 :type 'string
1082 :group 'vhdl-sequential-process)
1085 (defgroup vhdl-model nil
1086 "Customizations for user models."
1087 :group 'vhdl)
1089 (defcustom vhdl-model-alist
1090 '(("Example Model"
1091 "<label> : process (<clock>, <reset>)
1092 begin -- process <label>
1093 if <reset> = '0' then -- asynchronous reset (active low)
1094 <cursor>
1095 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1096 if <enable> = '1' then -- synchronous load
1098 end if;
1099 end if;
1100 end process <label>;"
1101 "e" ""))
1102 "List of user models.
1103 VHDL models (templates) can be specified by the user in this list. They can be
1104 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1105 electrification (i.e. overriding existing or creating new keywords, see
1106 option `vhdl-electric-keywords').
1107 Name : name of model (string of words and spaces)
1108 String : string or name of file to be inserted as model (newline: `C-j')
1109 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1110 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1111 Keyword : keyword to invoke model
1113 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1114 A prompt that appears several times is queried once and replaced throughout
1115 the model. Special prompts are:
1116 <clock> : name specified in `vhdl-clock-name' (if not empty)
1117 <reset> : name specified in `vhdl-reset-name' (if not empty)
1118 <cursor>: final cursor position
1119 File header prompts (see variable `vhdl-file-header') are automatically
1120 replaced, so that user models can also be used to insert different types of
1121 headers.
1123 If the string specifies an existing file name, the contents of the file is
1124 inserted, otherwise the string itself is inserted.
1125 The code within the models should be correctly indented.
1126 Type `C-j' for newlines.
1128 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1129 \"Activate Options\"."
1130 :type '(repeat (list :tag "Model" :indent 2
1131 (string :tag "Name ")
1132 (string :tag "String : (type `C-j' for newline)"
1133 :format "%t\n%v")
1134 (sexp :tag "Key binding" x)
1135 (string :tag "Keyword " :format "%t: %v\n")))
1136 :set (lambda (variable value)
1137 (vhdl-custom-set variable value
1138 'vhdl-model-map-init
1139 'vhdl-model-defun
1140 'vhdl-mode-abbrev-table-init
1141 'vhdl-update-mode-menu))
1142 :group 'vhdl-model)
1145 (defgroup vhdl-compose nil
1146 "Customizations for structural composition."
1147 :group 'vhdl)
1149 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1150 (concat
1151 "Specifies how the component architecture name is obtained.
1152 The component architecture name can be obtained by modifying the entity name
1153 \(e.g. attaching or stripping off a substring).
1154 If TO STRING is empty, the architecture name is queried."
1155 vhdl-name-doc-string)
1156 :type '(cons (regexp :tag "From regexp")
1157 (string :tag "To string "))
1158 :group 'vhdl-compose)
1160 (defcustom vhdl-compose-configuration-name
1161 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1162 (concat
1163 "Specifies how the configuration name is obtained.
1164 The configuration name can be obtained by modifying the entity and/or
1165 architecture name (e.g. attaching or stripping off a substring). The string
1166 that is matched against the regexp is the concatenation of the entity and the
1167 architecture name separated by a space. This gives access to both names (see
1168 default setting as example)."
1169 vhdl-name-doc-string)
1170 :type '(cons (regexp :tag "From regexp")
1171 (string :tag "To string "))
1172 :group 'vhdl-compose)
1174 (defcustom vhdl-components-package-name
1175 '((".*" . "\\&_components") . "components")
1176 (concat
1177 "Specifies how the name for the components package is obtained.
1178 The components package is a package containing all component declarations for
1179 the current design. Its name can be obtained by modifying the project name
1180 \(e.g. attaching or stripping off a substring). If no project is defined, the
1181 DIRECTORY entry is chosen."
1182 vhdl-name-doc-string)
1183 :type '(cons (cons :tag "Project" :indent 2
1184 (regexp :tag "From regexp")
1185 (string :tag "To string "))
1186 (string :tag "Directory:\n String "))
1187 :group 'vhdl-compose)
1189 (defcustom vhdl-use-components-package nil
1190 "Non-nil means use a separate components package for component declarations.
1191 Otherwise, component declarations are inserted and searched for in the
1192 architecture declarative parts."
1193 :type 'boolean
1194 :group 'vhdl-compose)
1196 (defcustom vhdl-compose-include-header t
1197 "Non-nil means include a header in automatically generated files."
1198 :type 'boolean
1199 :group 'vhdl-compose)
1201 (defcustom vhdl-compose-create-files 'single
1202 "Specifies whether new files should be created for the new component.
1203 The component's entity and architecture are inserted:
1204 None : in current buffer
1205 Single file : in new single file
1206 Separate files: in two separate files
1207 The file names are obtained from variables `vhdl-entity-file-name' and
1208 `vhdl-architecture-file-name'."
1209 :type '(choice (const :tag "None" none)
1210 (const :tag "Single file" single)
1211 (const :tag "Separate files" separate))
1212 :group 'vhdl-compose)
1214 (defcustom vhdl-compose-configuration-create-file nil
1215 "Specifies whether a new file should be created for the configuration.
1216 If non-nil, a new file is created for the configuration.
1217 The file name is obtained from variable `vhdl-configuration-file-name'."
1218 :type 'boolean
1219 :group 'vhdl-compose)
1221 (defcustom vhdl-compose-configuration-hierarchical t
1222 "Specifies whether hierarchical configurations should be created.
1223 If non-nil, automatically created configurations are hierarchical and include
1224 the whole hierarchy of subcomponents. Otherwise the configuration only
1225 includes one level of subcomponents."
1226 :type 'boolean
1227 :group 'vhdl-compose)
1229 (defcustom vhdl-compose-configuration-use-subconfiguration t
1230 "Specifies whether subconfigurations should be used inside configurations.
1231 If non-nil, automatically created configurations use configurations in binding
1232 indications for subcomponents, if such configurations exist. Otherwise,
1233 entities are used in binding indications for subcomponents."
1234 :type 'boolean
1235 :group 'vhdl-compose)
1238 (defgroup vhdl-port nil
1239 "Customizations for port translation functions."
1240 :group 'vhdl
1241 :group 'vhdl-compose)
1243 (defcustom vhdl-include-port-comments nil
1244 "Non-nil means include port comments when a port is pasted."
1245 :type 'boolean
1246 :group 'vhdl-port)
1248 (defcustom vhdl-include-direction-comments nil
1249 "Non-nil means include port direction in instantiations as comments."
1250 :type 'boolean
1251 :group 'vhdl-port)
1253 (defcustom vhdl-include-type-comments nil
1254 "Non-nil means include generic/port type in instantiations as comments."
1255 :type 'boolean
1256 :group 'vhdl-port)
1258 (defcustom vhdl-include-group-comments 'never
1259 "Specifies whether to include group comments and spacings.
1260 The comments and empty lines between groups of ports are pasted:
1261 Never : never
1262 Declarations: in entity/component/constant/signal declarations only
1263 Always : also in generic/port maps"
1264 :type '(choice (const :tag "Never" never)
1265 (const :tag "Declarations" decl)
1266 (const :tag "Always" always))
1267 :group 'vhdl-port)
1269 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1270 (concat
1271 "Specifies how actual port names are obtained from formal port names.
1272 In a component instantiation, an actual port name can be obtained by
1273 modifying the formal port name (e.g. attaching or stripping off a substring)."
1274 vhdl-name-doc-string)
1275 :type '(cons (regexp :tag "From regexp")
1276 (string :tag "To string "))
1277 :group 'vhdl-port)
1279 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1280 (concat
1281 "Specifies how an instance name is obtained.
1282 The instance name can be obtained by modifying the name of the component to be
1283 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1284 by a unique number (starting with 1).
1285 If TO STRING is empty, the instance name is queried."
1286 vhdl-name-doc-string)
1287 :type '(cons (regexp :tag "From regexp")
1288 (string :tag "To string "))
1289 :group 'vhdl-port)
1292 (defgroup vhdl-testbench nil
1293 "Customizations for testbench generation."
1294 :group 'vhdl-port)
1296 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1297 (concat
1298 "Specifies how the testbench entity name is obtained.
1299 The entity name of a testbench can be obtained by modifying the name of
1300 the component to be tested (e.g. attaching or stripping off a substring)."
1301 vhdl-name-doc-string)
1302 :type '(cons (regexp :tag "From regexp")
1303 (string :tag "To string "))
1304 :group 'vhdl-testbench)
1306 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1307 (concat
1308 "Specifies how the testbench architecture name is obtained.
1309 The testbench architecture name can be obtained by modifying the name of
1310 the component to be tested (e.g. attaching or stripping off a substring).
1311 If TO STRING is empty, the architecture name is queried."
1312 vhdl-name-doc-string)
1313 :type '(cons (regexp :tag "From regexp")
1314 (string :tag "To string "))
1315 :group 'vhdl-testbench)
1317 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1318 (concat
1319 "Specifies how the testbench configuration name is obtained.
1320 The configuration name of a testbench can be obtained by modifying the entity
1321 and/or architecture name (e.g. attaching or stripping off a substring). The
1322 string that is matched against the regexp is the concatenation of the entity
1323 and the architecture name separated by a space. This gives access to both
1324 names (see default setting as example)."
1325 vhdl-name-doc-string)
1326 :type '(cons (regexp :tag "From regexp")
1327 (string :tag "To string "))
1328 :group 'vhdl-testbench)
1330 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1331 (concat
1332 "Specifies how a DUT instance name is obtained.
1333 The design-under-test instance name (i.e. the component instantiated in the
1334 testbench) can be obtained by modifying the component name (e.g. attaching
1335 or stripping off a substring)."
1336 vhdl-name-doc-string)
1337 :type '(cons (regexp :tag "From regexp")
1338 (string :tag "To string "))
1339 :group 'vhdl-testbench)
1341 (defcustom vhdl-testbench-include-header t
1342 "Non-nil means include a header in automatically generated files."
1343 :type 'boolean
1344 :group 'vhdl-testbench)
1346 (defcustom vhdl-testbench-declarations "\
1347 -- clock
1348 signal Clk : std_logic := '1';
1350 "String or file to be inserted in the testbench declarative part.
1351 If the string specifies an existing file name, the contents of the file is
1352 inserted, otherwise the string itself is inserted in the testbench
1353 architecture before the BEGIN keyword.
1354 Type `C-j' for newlines."
1355 :type 'string
1356 :group 'vhdl-testbench)
1358 (defcustom vhdl-testbench-statements "\
1359 -- clock generation
1360 Clk <= not Clk after 10 ns;
1362 -- waveform generation
1363 WaveGen_Proc: process
1364 begin
1365 -- insert signal assignments here
1367 wait until Clk = '1';
1368 end process WaveGen_Proc;
1370 "String or file to be inserted in the testbench statement part.
1371 If the string specifies an existing file name, the contents of the file is
1372 inserted, otherwise the string itself is inserted in the testbench
1373 architecture before the END keyword.
1374 Type `C-j' for newlines."
1375 :type 'string
1376 :group 'vhdl-testbench)
1378 (defcustom vhdl-testbench-initialize-signals nil
1379 "Non-nil means initialize signals with `0' when declared in testbench."
1380 :type 'boolean
1381 :group 'vhdl-testbench)
1383 (defcustom vhdl-testbench-include-library t
1384 "Non-nil means a library/use clause for std_logic_1164 is included."
1385 :type 'boolean
1386 :group 'vhdl-testbench)
1388 (defcustom vhdl-testbench-include-configuration t
1389 "Non-nil means a testbench configuration is attached at the end."
1390 :type 'boolean
1391 :group 'vhdl-testbench)
1393 (defcustom vhdl-testbench-create-files 'single
1394 "Specifies whether new files should be created for the testbench.
1395 testbench entity and architecture are inserted:
1396 None : in current buffer
1397 Single file : in new single file
1398 Separate files: in two separate files
1399 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1400 and `vhdl-testbench-architecture-file-name'."
1401 :type '(choice (const :tag "None" none)
1402 (const :tag "Single file" single)
1403 (const :tag "Separate files" separate))
1404 :group 'vhdl-testbench)
1406 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1407 (concat
1408 "Specifies how the testbench entity file name is obtained.
1409 The entity file name can be obtained by modifying the testbench entity name
1410 \(e.g. attaching or stripping off a substring). The file extension is
1411 automatically taken from the file name of the current buffer. Testbench
1412 files can be created in a different directory by prepending a relative or
1413 absolute path to the file name."
1414 vhdl-name-doc-string)
1415 :type '(cons (regexp :tag "From regexp")
1416 (string :tag "To string "))
1417 :group 'vhdl-testbench)
1419 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1420 (concat
1421 "Specifies how the testbench architecture file name is obtained.
1422 The architecture file name can be obtained by modifying the testbench entity
1423 and/or architecture name (e.g. attaching or stripping off a substring). The
1424 string that is matched against the regexp is the concatenation of the entity
1425 and the architecture name separated by a space. This gives access to both
1426 names (see default setting as example). Testbench files can be created in
1427 a different directory by prepending a relative or absolute path to the file
1428 name."
1429 vhdl-name-doc-string)
1430 :type '(cons (regexp :tag "From regexp")
1431 (string :tag "To string "))
1432 :group 'vhdl-testbench)
1435 (defgroup vhdl-comment nil
1436 "Customizations for comments."
1437 :group 'vhdl)
1439 (defcustom vhdl-self-insert-comments t
1440 "Non-nil means various templates automatically insert help comments."
1441 :type 'boolean
1442 :group 'vhdl-comment)
1444 (defcustom vhdl-prompt-for-comments t
1445 "Non-nil means various templates prompt for user definable comments."
1446 :type 'boolean
1447 :group 'vhdl-comment)
1449 (defcustom vhdl-inline-comment-column 40
1450 "Column to indent and align inline comments to.
1451 Overrides local option `comment-column'.
1453 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1454 \"Activate Options\"."
1455 :type 'integer
1456 :group 'vhdl-comment)
1458 (defcustom vhdl-end-comment-column 79
1459 "End of comment column.
1460 Comments that exceed this column number are wrapped.
1462 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1463 \"Activate Options\"."
1464 :type 'integer
1465 :group 'vhdl-comment)
1467 (defvar end-comment-column)
1470 (defgroup vhdl-align nil
1471 "Customizations for alignment."
1472 :group 'vhdl)
1474 (defcustom vhdl-auto-align t
1475 "Non-nil means align some templates automatically after generation."
1476 :type 'boolean
1477 :group 'vhdl-align)
1479 (defcustom vhdl-align-groups t
1480 "Non-nil means align groups of code lines separately.
1481 A group of code lines is a region of consecutive lines between two lines that
1482 match the regexp in option `vhdl-align-group-separate'."
1483 :type 'boolean
1484 :group 'vhdl-align)
1486 (defcustom vhdl-align-group-separate "^\\s-*$"
1487 "Regexp for matching a line that separates groups of lines for alignment.
1488 Examples:
1489 \"^\\s-*$\": matches an empty line
1490 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1491 :type 'regexp
1492 :group 'vhdl-align)
1494 (defcustom vhdl-align-same-indent t
1495 "Non-nil means align blocks with same indent separately.
1496 When a region or the entire buffer is aligned, the code is divided into
1497 blocks of same indent which are aligned separately (except for argument/port
1498 lists). This gives nicer alignment in most cases.
1499 Option `vhdl-align-groups' still applies within these blocks."
1500 :type 'boolean
1501 :group 'vhdl-align)
1504 (defgroup vhdl-highlight nil
1505 "Customizations for highlighting."
1506 :group 'vhdl)
1508 (defcustom vhdl-highlight-keywords t
1509 "Non-nil means highlight VHDL keywords and other standardized words.
1510 The following faces are used:
1511 `font-lock-keyword-face' : keywords
1512 `font-lock-type-face' : standardized types
1513 `vhdl-font-lock-attribute-face': standardized attributes
1514 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1515 `vhdl-font-lock-function-face' : standardized function and package names
1517 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1518 entry \"Fontify Buffer\")."
1519 :type 'boolean
1520 :set (lambda (variable value)
1521 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1522 :group 'vhdl-highlight)
1524 (defcustom vhdl-highlight-names t
1525 "Non-nil means highlight declaration names and construct labels.
1526 The following faces are used:
1527 `font-lock-function-name-face' : names in declarations of units,
1528 subprograms, components, as well as labels of VHDL constructs
1529 `font-lock-type-face' : names in type/nature declarations
1530 `vhdl-font-lock-attribute-face': names in attribute declarations
1531 `font-lock-variable-name-face' : names in declarations of signals,
1532 variables, constants, subprogram parameters, generics, and ports
1534 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1535 entry \"Fontify Buffer\")."
1536 :type 'boolean
1537 :set (lambda (variable value)
1538 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1539 :group 'vhdl-highlight)
1541 (defcustom vhdl-highlight-special-words nil
1542 "Non-nil means highlight words with special syntax.
1543 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1544 are highlighted accordingly.
1545 Can be used for visual support of naming conventions.
1547 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1548 entry \"Fontify Buffer\")."
1549 :type 'boolean
1550 :set (lambda (variable value)
1551 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1552 :group 'vhdl-highlight)
1554 (defcustom vhdl-highlight-forbidden-words nil
1555 "Non-nil means highlight forbidden words.
1556 The reserved words specified in option `vhdl-forbidden-words' or having the
1557 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1558 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1559 use them.
1561 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1562 entry \"Fontify Buffer\")."
1563 :type 'boolean
1564 :set (lambda (variable value)
1565 (vhdl-custom-set variable value
1566 'vhdl-words-init 'vhdl-font-lock-init))
1567 :group 'vhdl-highlight)
1569 (defcustom vhdl-highlight-verilog-keywords nil
1570 "Non-nil means highlight Verilog keywords as reserved words.
1571 Verilog keywords are highlighted in a warning color (face
1572 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1574 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1575 entry \"Fontify Buffer\")."
1576 :type 'boolean
1577 :set (lambda (variable value)
1578 (vhdl-custom-set variable value
1579 'vhdl-words-init 'vhdl-font-lock-init))
1580 :group 'vhdl-highlight)
1582 (defcustom vhdl-highlight-translate-off nil
1583 "Non-nil means background-highlight code excluded from translation.
1584 That is, all code between \"-- pragma translate_off\" and
1585 \"-- pragma translate_on\" is highlighted using a different background color
1586 \(face `vhdl-font-lock-translate-off-face').
1587 Note: this might slow down on-the-fly fontification (and thus editing).
1589 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1590 entry \"Fontify Buffer\")."
1591 :type 'boolean
1592 :set (lambda (variable value)
1593 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1594 :group 'vhdl-highlight)
1596 (defcustom vhdl-highlight-case-sensitive nil
1597 "Non-nil means consider case for highlighting.
1598 Possible trade-off:
1599 non-nil also upper-case VHDL words are highlighted, but case of words with
1600 special syntax is not considered
1601 nil only lower-case VHDL words are highlighted, but case of words with
1602 special syntax is considered
1603 Overrides local option `font-lock-keywords-case-fold-search'.
1605 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1606 entry \"Fontify Buffer\")."
1607 :type 'boolean
1608 :group 'vhdl-highlight)
1610 (defcustom vhdl-special-syntax-alist
1611 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1612 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1613 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1614 "List of special syntax to be highlighted.
1615 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1616 syntax (as regular expression) are highlighted in the corresponding color.
1618 Name : string of words and spaces
1619 Regexp : regular expression describing word syntax
1620 (e.g. \"\\\\=\<\\\w+_c\\\\=\>\" matches word with suffix \"_c\")
1621 expression must start with \"\\\\=\<\" and end with \"\\\\=\>\"
1622 if only whole words should be matched (no substrings)
1623 Color (light): foreground color for light background
1624 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1625 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1626 Color (dark) : foreground color for dark background
1627 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1628 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1629 In comments : If non-nil, words are also highlighted inside comments
1631 Can be used for visual support of naming conventions, such as highlighting
1632 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1633 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1634 common substrings or name suffices.
1635 For each entry, a new face is generated with the specified colors and name
1636 \"vhdl-font-lock-\" + name + \"-face\".
1638 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1639 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1640 :type '(repeat (list :tag "Face" :indent 2
1641 (string :tag "Name ")
1642 (regexp :tag "Regexp " "\\w+_")
1643 (string :tag "Color (light)")
1644 (string :tag "Color (dark) ")
1645 (boolean :tag "In comments ")))
1646 :set (lambda (variable value)
1647 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1648 :group 'vhdl-highlight)
1650 (defcustom vhdl-forbidden-words '()
1651 "List of forbidden words to be highlighted.
1652 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1653 words are highlighted in a warning color to indicate not to use them.
1655 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1656 entry \"Fontify Buffer\")."
1657 :type '(repeat (string :format "%v"))
1658 :set (lambda (variable value)
1659 (vhdl-custom-set variable value
1660 'vhdl-words-init 'vhdl-font-lock-init))
1661 :group 'vhdl-highlight)
1663 (defcustom vhdl-forbidden-syntax ""
1664 "Syntax of forbidden words to be highlighted.
1665 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1666 syntax are highlighted in a warning color to indicate not to use them.
1667 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1668 highlights identifiers with 10 or more characters).
1670 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1671 entry \"Fontify Buffer\")."
1672 :type 'regexp
1673 :set (lambda (variable value)
1674 (vhdl-custom-set variable value
1675 'vhdl-words-init 'vhdl-font-lock-init))
1676 :group 'vhdl-highlight)
1678 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1679 "List of compiler directive keywords recognized for highlighting.
1681 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1682 entry \"Fontify Buffer\")."
1683 :type '(repeat (string :format "%v"))
1684 :set (lambda (variable value)
1685 (vhdl-custom-set variable value
1686 'vhdl-words-init 'vhdl-font-lock-init))
1687 :group 'vhdl-highlight)
1690 (defgroup vhdl-speedbar nil
1691 "Customizations for speedbar."
1692 :group 'vhdl)
1694 (defcustom vhdl-speedbar-auto-open nil
1695 "Non-nil means automatically open speedbar at startup.
1696 Alternatively, the speedbar can be opened from the VHDL menu."
1697 :type 'boolean
1698 :group 'vhdl-speedbar)
1700 (defcustom vhdl-speedbar-display-mode 'files
1701 "Specifies the default displaying mode when opening speedbar.
1702 Alternatively, the displaying mode can be selected from the speedbar menu or
1703 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1704 :type '(choice (const :tag "Files" files)
1705 (const :tag "Directory hierarchy" directory)
1706 (const :tag "Project hierarchy" project))
1707 :group 'vhdl-speedbar)
1709 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1710 "Limits scanning of large files and netlists.
1711 Design units: maximum file size to scan for design units
1712 Hierarchy (instances of subcomponents):
1713 File size: maximum file size to scan for instances (in bytes)
1714 Instances per arch: maximum number of instances to scan per architecture
1716 \"None\" always means that there is no limit.
1717 In case of files not or incompletely scanned, a warning message and the file
1718 names are printed out.
1719 Background: scanning for instances is considerably slower than scanning for
1720 design units, especially when there are many instances. These limits should
1721 prevent the scanning of large netlists."
1722 :type '(list (choice :tag "Design units"
1723 :format "%t : %[Value Menu%] %v"
1724 (const :tag "None" nil)
1725 (integer :tag "File size"))
1726 (list :tag "Hierarchy" :indent 2
1727 (choice :tag "File size"
1728 :format "%t : %[Value Menu%] %v"
1729 (const :tag "None" nil)
1730 (integer :tag "Size "))
1731 (choice :tag "Instances per arch"
1732 (const :tag "None" nil)
1733 (integer :tag "Number "))))
1734 :group 'vhdl-speedbar)
1736 (defcustom vhdl-speedbar-jump-to-unit t
1737 "Non-nil means jump to the design unit code when opened in a buffer.
1738 The buffer cursor position is left unchanged otherwise."
1739 :type 'boolean
1740 :group 'vhdl-speedbar)
1742 (defcustom vhdl-speedbar-update-on-saving t
1743 "Automatically update design hierarchy when buffer is saved."
1744 :type 'boolean
1745 :group 'vhdl-speedbar)
1747 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1748 "Automatically save modified hierarchy caches when exiting Emacs.
1749 Hierarchy: design hierarchy information
1750 Display: displaying information (which design units to expand)"
1751 :type '(set (const :tag "Hierarchy" hierarchy)
1752 (const :tag "Display" display))
1753 :group 'vhdl-speedbar)
1755 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1756 "Name of file for saving hierarchy cache.
1757 \"\\1\" is replaced by the project name if a project is specified,
1758 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1759 different users to have cache files in the same directory). Can also have
1760 an absolute path (i.e. all caches can be stored in one global directory)."
1761 :type 'string
1762 :group 'vhdl-speedbar)
1765 (defgroup vhdl-menu nil
1766 "Customizations for menus."
1767 :group 'vhdl)
1769 (defcustom vhdl-index-menu nil
1770 "Non-nil means add an index menu for a source file when loading.
1771 Alternatively, the speedbar can be used. Note that the index menu scans a file
1772 when it is opened, while speedbar only scans the file upon request."
1773 :type 'boolean
1774 :group 'vhdl-menu)
1776 (defcustom vhdl-source-file-menu nil
1777 "Non-nil means add a menu of all source files in current directory.
1778 Alternatively, the speedbar can be used."
1779 :type 'boolean
1780 :group 'vhdl-menu)
1782 (defcustom vhdl-hideshow-menu nil
1783 "Non-nil means add hideshow menu and functionality at startup.
1784 Hideshow can also be enabled from the VHDL Mode menu.
1785 Hideshow allows hiding code of various VHDL constructs.
1787 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1788 \"Activate Options\"."
1789 :type 'boolean
1790 :group 'vhdl-menu)
1792 (defcustom vhdl-hide-all-init nil
1793 "Non-nil means hide all design units initially after a file is loaded."
1794 :type 'boolean
1795 :group 'vhdl-menu)
1798 (defgroup vhdl-print nil
1799 "Customizations for printing."
1800 :group 'vhdl)
1802 (defcustom vhdl-print-two-column t
1803 "Non-nil means print code in two columns and landscape format.
1804 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1805 prints VHDL files in a nice two-column landscape style.
1807 NOTE: Activate the new setting by restarting Emacs.
1808 Overrides `ps-print' settings locally."
1809 :type 'boolean
1810 :group 'vhdl-print)
1812 (defcustom vhdl-print-customize-faces t
1813 "Non-nil means use an optimized set of faces for PostScript printing.
1815 NOTE: Activate the new setting by restarting Emacs.
1816 Overrides `ps-print' settings locally."
1817 :type 'boolean
1818 :group 'vhdl-print)
1821 (defgroup vhdl-misc nil
1822 "Miscellaneous customizations."
1823 :group 'vhdl)
1825 (defcustom vhdl-intelligent-tab t
1826 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1827 That is, if preceding character is part of a word then complete word,
1828 else if not at beginning of line then insert tab,
1829 else if last command was a `TAB' or `RET' then dedent one step,
1830 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1831 If nil, TAB always indents current line (i.e. `TAB' is bound to
1832 `indent-according-to-mode').
1834 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1835 \"Activate Options\"."
1836 :type 'boolean
1837 :group 'vhdl-misc)
1839 (defcustom vhdl-indent-syntax-based t
1840 "Non-nil means indent lines of code based on their syntactic context.
1841 Otherwise, a line is indented like the previous nonblank line. This can be
1842 useful in large files where syntax-based indentation gets very slow."
1843 :type 'boolean
1844 :group 'vhdl-misc)
1846 (defcustom vhdl-indent-comment-like-next-code-line t
1847 "*Non-nil means comment lines are indented like the following code line.
1848 Otherwise, comment lines are indented like the preceding code line.
1849 Indenting comment lines like the following code line gives nicer indentation
1850 when comments precede the code that they refer to."
1851 :type 'boolean
1852 :group 'vhdl-misc)
1854 (defcustom vhdl-word-completion-case-sensitive nil
1855 "Non-nil means word completion using `TAB' is case sensitive.
1856 That is, `TAB' completes words that start with the same letters and case.
1857 Otherwise, case is ignored."
1858 :type 'boolean
1859 :group 'vhdl-misc)
1861 (defcustom vhdl-word-completion-in-minibuffer t
1862 "Non-nil enables word completion in minibuffer (for template prompts).
1864 NOTE: Activate the new setting by restarting Emacs."
1865 :type 'boolean
1866 :group 'vhdl-misc)
1868 (defcustom vhdl-underscore-is-part-of-word nil
1869 "Non-nil means consider the underscore character `_' as part of word.
1870 An identifier containing underscores is then treated as a single word in
1871 select and move operations. All parts of an identifier separated by underscore
1872 are treated as single words otherwise.
1874 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1875 \"Activate Options\"."
1876 :type 'boolean
1877 :set (lambda (variable value)
1878 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1879 :group 'vhdl-misc)
1882 (defgroup vhdl-related nil
1883 "Related general customizations."
1884 :group 'vhdl)
1886 ;; add related general customizations
1887 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1888 (if (featurep 'xemacs)
1889 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1890 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1891 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1892 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1893 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1894 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1895 (unless (featurep 'xemacs)
1896 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1897 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1898 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1899 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1901 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1902 ;; Hidden user variables
1904 (defvar vhdl-compile-absolute-path nil
1905 "If non-nil, use absolute instead of relative path for compiled files.")
1907 (defvar vhdl-comment-display-line-char ?-
1908 "Character to use in comment display line.")
1910 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1911 ;; Internal variables
1913 (defvar vhdl-menu-max-size 20
1914 "Specifies the maximum size of a menu before splitting it into submenus.")
1916 (defvar vhdl-progress-interval 1
1917 "Interval used to update progress status during long operations.
1918 If a number, percentage complete gets updated after each interval of
1919 that many seconds. To inhibit all messages, set this option to nil.")
1921 (defvar vhdl-inhibit-startup-warnings-p nil
1922 "If non-nil, inhibits start up compatibility warnings.")
1924 (defvar vhdl-strict-syntax-p nil
1925 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1926 If the syntactic symbol for a particular line does not match a symbol
1927 in the offsets alist, an error is generated, otherwise no error is
1928 reported and the syntactic symbol is ignored.")
1930 (defvar vhdl-echo-syntactic-information-p nil
1931 "If non-nil, syntactic info is echoed when the line is indented.")
1933 (defconst vhdl-offsets-alist-default
1934 '((string . -1000)
1935 (cpp-macro . -1000)
1936 (block-open . 0)
1937 (block-close . 0)
1938 (statement . 0)
1939 (statement-cont . vhdl-lineup-statement-cont)
1940 (statement-block-intro . +)
1941 (statement-case-intro . +)
1942 (case-alternative . +)
1943 (comment . vhdl-lineup-comment)
1944 (arglist-intro . +)
1945 (arglist-cont . 0)
1946 (arglist-cont-nonempty . vhdl-lineup-arglist)
1947 (arglist-close . vhdl-lineup-arglist)
1948 (entity . 0)
1949 (configuration . 0)
1950 (package . 0)
1951 (architecture . 0)
1952 (package-body . 0)
1954 "Default settings for offsets of syntactic elements.
1955 Do not change this constant! See the variable `vhdl-offsets-alist' for
1956 more information.")
1958 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1959 "Association list of syntactic element symbols and indentation offsets.
1960 As described below, each cons cell in this list has the form:
1962 (SYNTACTIC-SYMBOL . OFFSET)
1964 When a line is indented, `vhdl-mode' first determines the syntactic
1965 context of the line by generating a list of symbols called syntactic
1966 elements. This list can contain more than one syntactic element and
1967 the global variable `vhdl-syntactic-context' contains the context list
1968 for the line being indented. Each element in this list is actually a
1969 cons cell of the syntactic symbol and a buffer position. This buffer
1970 position is call the relative indent point for the line. Some
1971 syntactic symbols may not have a relative indent point associated with
1972 them.
1974 After the syntactic context list for a line is generated, `vhdl-mode'
1975 calculates the absolute indentation for the line by looking at each
1976 syntactic element in the list. First, it compares the syntactic
1977 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1978 finds a match, it adds the OFFSET to the column of the relative indent
1979 point. The sum of this calculation for each element in the syntactic
1980 list is the absolute offset for line being indented.
1982 If the syntactic element does not match any in the `vhdl-offsets-alist',
1983 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1984 the element is ignored.
1986 Actually, OFFSET can be an integer, a function, a variable, or one of
1987 the following symbols: `+', `-', `++', or `--'. These latter
1988 designate positive or negative multiples of `vhdl-basic-offset',
1989 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1990 called with a single argument containing the cons of the syntactic
1991 element symbol and the relative indent point. The function should
1992 return an integer offset.
1994 Here is the current list of valid syntactic element symbols:
1996 string -- inside multi-line string
1997 block-open -- statement block open
1998 block-close -- statement block close
1999 statement -- a VHDL statement
2000 statement-cont -- a continuation of a VHDL statement
2001 statement-block-intro -- the first line in a new statement block
2002 statement-case-intro -- the first line in a case alternative block
2003 case-alternative -- a case statement alternative clause
2004 comment -- a line containing only a comment
2005 arglist-intro -- the first line in an argument list
2006 arglist-cont -- subsequent argument list lines when no
2007 arguments follow on the same line as
2008 the arglist opening paren
2009 arglist-cont-nonempty -- subsequent argument list lines when at
2010 least one argument follows on the same
2011 line as the arglist opening paren
2012 arglist-close -- the solo close paren of an argument list
2013 entity -- inside an entity declaration
2014 configuration -- inside a configuration declaration
2015 package -- inside a package declaration
2016 architecture -- inside an architecture body
2017 package-body -- inside a package body")
2019 (defvar vhdl-comment-only-line-offset 0
2020 "Extra offset for line which contains only the start of a comment.
2021 Can contain an integer or a cons cell of the form:
2023 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2025 Where NON-ANCHORED-OFFSET is the amount of offset given to
2026 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2027 the amount of offset to give column-zero anchored comment-only lines.
2028 Just an integer as value is equivalent to (<val> . 0)")
2030 (defvar vhdl-special-indent-hook nil
2031 "Hook for user defined special indentation adjustments.
2032 This hook gets called after a line is indented by the mode.")
2034 (defvar vhdl-style-alist
2035 '(("IEEE"
2036 (vhdl-basic-offset . 4)
2037 (vhdl-offsets-alist . ())))
2038 "Styles of Indentation.
2039 Elements of this alist are of the form:
2041 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2043 where STYLE-STRING is a short descriptive string used to select a
2044 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2045 value for that variable when using the selected style.
2047 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2048 case, the VALUE is a list containing elements of the form:
2050 (SYNTACTIC-SYMBOL . VALUE)
2052 as described in `vhdl-offsets-alist'. These are passed directly to
2053 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2054 your style, only those that are different from the default.")
2056 ;; dynamically append the default value of most variables
2057 (or (assoc "Default" vhdl-style-alist)
2058 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2059 vhdl-strict-syntax-p
2060 vhdl-echo-syntactic-information-p
2061 vhdl-basic-offset
2062 vhdl-offsets-alist
2063 vhdl-comment-only-line-offset))
2064 (default (cons "Default"
2065 (mapcar
2066 (function
2067 (lambda (var)
2068 (cons var (symbol-value var))))
2069 varlist))))
2070 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2072 (defvar vhdl-mode-hook nil
2073 "Hook called by `vhdl-mode'.")
2076 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2077 ;;; Required packages
2078 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2080 ;; mandatory
2081 (require 'assoc)
2082 (require 'compile) ; XEmacs
2083 (require 'easymenu)
2084 (require 'hippie-exp)
2086 ;; optional (minimize warning messages during compile)
2087 (eval-when-compile
2088 (require 'font-lock)
2089 (require 'ps-print)
2090 (require 'speedbar))
2093 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2094 ;;; Compatibility
2095 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2097 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2098 ;; XEmacs compatibility
2100 ;; active regions
2101 (defun vhdl-keep-region-active ()
2102 "Do whatever is necessary to keep the region active in XEmacs.
2103 Ignore byte-compiler warnings you might see."
2104 (and (featurep 'xemacs)
2105 (setq zmacs-region-stays t)))
2107 ;; `wildcard-to-regexp' is included only in XEmacs 21
2108 (unless (fboundp 'wildcard-to-regexp)
2109 (defun wildcard-to-regexp (wildcard)
2110 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2111 (let* ((i (string-match "[*?]" wildcard))
2112 (result (substring wildcard 0 i))
2113 (len (length wildcard)))
2114 (when i
2115 (while (< i len)
2116 (let ((ch (aref wildcard i)))
2117 (setq result (concat result
2118 (cond ((eq ch ?*) "[^\000]*")
2119 ((eq ch ??) "[^\000]")
2120 (t (char-to-string ch)))))
2121 (setq i (1+ i)))))
2122 (concat "\\`" result "\\'"))))
2124 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2125 ;; `regexp-opt' accelerates fontification by 10-20%
2126 (unless (fboundp 'regexp-opt)
2127 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2128 (defun regexp-opt (strings &optional paren)
2129 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2130 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2132 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2133 (unless (fboundp 'match-string-no-properties)
2134 (defalias 'match-string-no-properties 'match-string))
2136 ;; `subst-char-in-string' undefined (XEmacs)
2137 (unless (fboundp 'subst-char-in-string)
2138 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2139 (let ((i (length string))
2140 (newstr (if inplace string (copy-sequence string))))
2141 (while (> i 0)
2142 (setq i (1- i))
2143 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2144 newstr)))
2146 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2147 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2148 (not noninteractive))
2149 (load "itimer")
2150 (when (string< itimer-version "1.09")
2151 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2152 (beep) (sit-for 5)))
2154 ;; `file-expand-wildcards' undefined (XEmacs)
2155 (unless (fboundp 'file-expand-wildcards)
2156 (defun file-expand-wildcards (pattern &optional full)
2157 "Taken from Emacs's `files.el'."
2158 (let* ((nondir (file-name-nondirectory pattern))
2159 (dirpart (file-name-directory pattern))
2160 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2161 (mapcar 'file-name-as-directory
2162 (file-expand-wildcards (directory-file-name dirpart)))
2163 (list dirpart)))
2164 contents)
2165 (while dirs
2166 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2167 (file-directory-p (directory-file-name (car dirs))))
2168 (let ((this-dir-contents
2169 (delq nil
2170 (mapcar #'(lambda (name)
2171 (unless (string-match "\\`\\.\\.?\\'"
2172 (file-name-nondirectory name))
2173 name))
2174 (directory-files (or (car dirs) ".") full
2175 (wildcard-to-regexp nondir))))))
2176 (setq contents
2177 (nconc
2178 (if (and (car dirs) (not full))
2179 (mapcar (function (lambda (name) (concat (car dirs) name)))
2180 this-dir-contents)
2181 this-dir-contents)
2182 contents))))
2183 (setq dirs (cdr dirs)))
2184 contents)))
2186 ;; `member-ignore-case' undefined (XEmacs)
2187 (unless (fboundp 'member-ignore-case)
2188 (defalias 'member-ignore-case 'member))
2190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2191 ;; Compatibility with older VHDL Mode versions
2193 (defvar vhdl-warnings nil
2194 "Warnings to tell the user during start up.")
2196 (defun vhdl-run-when-idle (secs repeat function)
2197 "Wait until idle, then run FUNCTION."
2198 (if (fboundp 'start-itimer)
2199 (start-itimer "vhdl-mode" function secs repeat t)
2200 ; (run-with-idle-timer secs repeat function)))
2201 ;; explicitly activate timer (necessary when Emacs is already idle)
2202 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2204 (defun vhdl-warning-when-idle (&rest args)
2205 "Wait until idle, then print out warning STRING and beep."
2206 (if noninteractive
2207 (vhdl-warning (apply 'format args) t)
2208 (unless vhdl-warnings
2209 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2210 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2212 (defun vhdl-warning (string &optional nobeep)
2213 "Print out warning STRING and beep."
2214 (message "WARNING: %s" string)
2215 (unless (or nobeep noninteractive) (beep)))
2217 (defun vhdl-print-warnings ()
2218 "Print out messages in variable `vhdl-warnings'."
2219 (let ((no-warnings (length vhdl-warnings)))
2220 (setq vhdl-warnings (nreverse vhdl-warnings))
2221 (while vhdl-warnings
2222 (message "WARNING: %s" (car vhdl-warnings))
2223 (setq vhdl-warnings (cdr vhdl-warnings)))
2224 (beep)
2225 (when (> no-warnings 1)
2226 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2228 ;; Backward compatibility checks and fixes
2229 ;; option `vhdl-compiler' changed format
2230 (unless (stringp vhdl-compiler)
2231 (setq vhdl-compiler "ModelSim")
2232 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2234 ;; option `vhdl-standard' changed format
2235 (unless (listp vhdl-standard)
2236 (setq vhdl-standard '(87 nil))
2237 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2239 ;; option `vhdl-model-alist' changed format
2240 (when (= (length (car vhdl-model-alist)) 3)
2241 (let ((old-alist vhdl-model-alist)
2242 new-alist)
2243 (while old-alist
2244 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2245 (setq old-alist (cdr old-alist)))
2246 (setq vhdl-model-alist (nreverse new-alist)))
2247 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2249 ;; option `vhdl-project-alist' changed format
2250 (when (= (length (car vhdl-project-alist)) 3)
2251 (let ((old-alist vhdl-project-alist)
2252 new-alist)
2253 (while old-alist
2254 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2255 (setq old-alist (cdr old-alist)))
2256 (setq vhdl-project-alist (nreverse new-alist)))
2257 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2259 ;; option `vhdl-project-alist' changed format (3.31.1)
2260 (when (= (length (car vhdl-project-alist)) 4)
2261 (let ((old-alist vhdl-project-alist)
2262 new-alist elem)
2263 (while old-alist
2264 (setq elem (car old-alist))
2265 (setq new-alist
2266 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2267 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2268 new-alist))
2269 (setq old-alist (cdr old-alist)))
2270 (setq vhdl-project-alist (nreverse new-alist)))
2271 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2273 ;; option `vhdl-project-alist' changed format (3.31.12)
2274 (when (= (length (car vhdl-project-alist)) 10)
2275 (let ((tmp-alist vhdl-project-alist))
2276 (while tmp-alist
2277 (setcdr (nthcdr 3 (car tmp-alist))
2278 (cons "" (nthcdr 4 (car tmp-alist))))
2279 (setq tmp-alist (cdr tmp-alist))))
2280 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2282 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2283 (when (= (length (car vhdl-compiler-alist)) 7)
2284 (let ((old-alist vhdl-compiler-alist)
2285 new-alist elem)
2286 (while old-alist
2287 (setq elem (car old-alist))
2288 (setq new-alist
2289 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2290 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2291 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2292 (nth 5 elem) (nth 6 elem) nil)
2293 new-alist))
2294 (setq old-alist (cdr old-alist)))
2295 (setq vhdl-compiler-alist (nreverse new-alist)))
2296 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2298 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2299 (when (= (length (car vhdl-compiler-alist)) 12)
2300 (let ((tmp-alist vhdl-compiler-alist))
2301 (while tmp-alist
2302 (setcdr (nthcdr 4 (car tmp-alist))
2303 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2304 (setq tmp-alist (cdr tmp-alist))))
2305 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2307 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2308 (when (= (length (car vhdl-compiler-alist)) 13)
2309 (let ((tmp-alist vhdl-compiler-alist))
2310 (while tmp-alist
2311 (setcdr (nthcdr 3 (car tmp-alist))
2312 (cons "" (nthcdr 4 (car tmp-alist))))
2313 (setq tmp-alist (cdr tmp-alist))))
2314 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2316 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2317 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2318 (let ((tmp-alist vhdl-compiler-alist))
2319 (while tmp-alist
2320 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2321 '(0 . nil))
2322 (setq tmp-alist (cdr tmp-alist))))
2323 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2325 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2326 (when (equal vhdl-project "")
2327 (setq vhdl-project nil)
2328 (customize-save-variable 'vhdl-project vhdl-project))
2330 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2331 (when (stringp vhdl-project-file-name)
2332 (setq vhdl-project-file-name (list vhdl-project-file-name))
2333 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2335 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2336 (if (not (boundp 'speedbar-indentation-width))
2337 (defvar speedbar-indentation-width 2)
2338 ;; set default to 2 if not already customized
2339 (unless (get 'speedbar-indentation-width 'saved-value)
2340 (setq speedbar-indentation-width 2)))
2343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2344 ;;; Help functions / inline substitutions / macros
2345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2347 (defun vhdl-standard-p (standard)
2348 "Check if STANDARD is specified as used standard."
2349 (or (eq standard (car vhdl-standard))
2350 (memq standard (cadr vhdl-standard))))
2352 (defun vhdl-project-p (&optional warning)
2353 "Return non-nil if a project is displayed, i.e. directories or files are
2354 specified."
2355 (if (assoc vhdl-project vhdl-project-alist)
2356 vhdl-project
2357 (when (and vhdl-project warning)
2358 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2359 nil))
2361 (defun vhdl-resolve-env-variable (string)
2362 "Resolve environment variables in STRING."
2363 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2364 (setq string (concat (match-string 1 string)
2365 (getenv (match-string 2 string))
2366 (match-string 4 string))))
2367 string)
2369 (defun vhdl-default-directory ()
2370 "Return the default directory of the current project or the directory of the
2371 current buffer if no project is defined."
2372 (if (vhdl-project-p)
2373 (expand-file-name (vhdl-resolve-env-variable
2374 (nth 1 (aget vhdl-project-alist vhdl-project))))
2375 default-directory))
2377 (defmacro vhdl-prepare-search-1 (&rest body)
2378 "Enable case insensitive search and switch to syntax table that includes '_',
2379 then execute BODY, and finally restore the old environment. Used for
2380 consistent searching."
2381 `(let ((case-fold-search t)) ; case insensitive search
2382 ;; use extended syntax table
2383 (with-syntax-table vhdl-mode-ext-syntax-table
2384 ,@body)))
2386 (defmacro vhdl-prepare-search-2 (&rest body)
2387 "Enable case insensitive search, switch to syntax table that includes '_',
2388 and remove `intangible' overlays, then execute BODY, and finally restore the
2389 old environment. Used for consistent searching."
2390 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2391 `(let ((case-fold-search t) ; case insensitive search
2392 (current-syntax-table (syntax-table))
2393 overlay-all-list overlay-intangible-list overlay)
2394 ;; use extended syntax table
2395 (set-syntax-table vhdl-mode-ext-syntax-table)
2396 ;; remove `intangible' overlays
2397 (when (fboundp 'overlay-lists)
2398 (setq overlay-all-list (overlay-lists))
2399 (setq overlay-all-list
2400 (append (car overlay-all-list) (cdr overlay-all-list)))
2401 (while overlay-all-list
2402 (setq overlay (car overlay-all-list))
2403 (when (memq 'intangible (overlay-properties overlay))
2404 (setq overlay-intangible-list
2405 (cons overlay overlay-intangible-list))
2406 (overlay-put overlay 'intangible nil))
2407 (setq overlay-all-list (cdr overlay-all-list))))
2408 ;; execute BODY safely
2409 (unwind-protect
2410 (progn ,@body)
2411 ;; restore syntax table
2412 (set-syntax-table current-syntax-table)
2413 ;; restore `intangible' overlays
2414 (when (fboundp 'overlay-lists)
2415 (while overlay-intangible-list
2416 (overlay-put (car overlay-intangible-list) 'intangible t)
2417 (setq overlay-intangible-list
2418 (cdr overlay-intangible-list)))))))
2420 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2421 "Visit file FILE-NAME and execute BODY."
2422 `(if (null ,file-name)
2423 (progn ,@body)
2424 (unless (file-directory-p ,file-name)
2425 (let ((source-buffer (current-buffer))
2426 (visiting-buffer (find-buffer-visiting ,file-name))
2427 file-opened)
2428 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2429 (condition-case ()
2430 (progn (set-buffer (create-file-buffer ,file-name))
2431 (setq file-opened t)
2432 (vhdl-insert-file-contents ,file-name)
2433 (modify-syntax-entry ?\- ". 12" (syntax-table))
2434 (modify-syntax-entry ?\n ">" (syntax-table))
2435 (modify-syntax-entry ?\^M ">" (syntax-table))
2436 (modify-syntax-entry ?_ "w" (syntax-table))
2438 (error
2439 (if ,issue-error
2440 (progn
2441 (when file-opened (kill-buffer (current-buffer)))
2442 (set-buffer source-buffer)
2443 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2444 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2445 nil))))
2446 (condition-case info
2447 (progn ,@body)
2448 (error
2449 (if ,issue-error
2450 (progn
2451 (when file-opened (kill-buffer (current-buffer)))
2452 (set-buffer source-buffer)
2453 (error (cadr info)))
2454 (vhdl-warning (cadr info))))))
2455 (when file-opened (kill-buffer (current-buffer)))
2456 (set-buffer source-buffer)))))
2458 (defun vhdl-insert-file-contents (filename)
2459 "Nicked from `insert-file-contents-literally', but allow coding system
2460 conversion."
2461 (let ((format-alist nil)
2462 (after-insert-file-functions nil)
2463 (jka-compr-compression-info-list nil))
2464 (insert-file-contents filename t)))
2466 (defun vhdl-sort-alist (alist)
2467 "Sort ALIST."
2468 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2470 (defun vhdl-get-subdirs (directory)
2471 "Recursively get subdirectories of DIRECTORY."
2472 (let ((dir-list (list (file-name-as-directory directory)))
2473 file-list)
2474 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2475 (while file-list
2476 (when (file-directory-p (car file-list))
2477 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2478 (setq file-list (cdr file-list)))
2479 dir-list))
2481 (defun vhdl-aput (alist-symbol key &optional value)
2482 "As `aput', but delete key-value pair if VALUE is nil."
2483 (if value
2484 (aput alist-symbol key value)
2485 (adelete alist-symbol key)))
2487 (defun vhdl-delete (elt list)
2488 "Delete by side effect the first occurrence of ELT as a member of LIST."
2489 (setq list (cons nil list))
2490 (let ((list1 list))
2491 (while (and (cdr list1) (not (equal elt (cadr list1))))
2492 (setq list1 (cdr list1)))
2493 (when list
2494 (setcdr list1 (cddr list1))))
2495 (cdr list))
2497 (defun vhdl-speedbar-refresh (&optional key)
2498 "Refresh directory or project with name KEY."
2499 (when (and (boundp 'speedbar-frame)
2500 (frame-live-p speedbar-frame))
2501 (let ((pos (point))
2502 (last-frame (selected-frame)))
2503 (if (null key)
2504 (speedbar-refresh)
2505 (select-frame speedbar-frame)
2506 (when (save-excursion
2507 (goto-char (point-min))
2508 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2509 (goto-char (match-end 1))
2510 (speedbar-do-function-pointer)
2511 (backward-char 2)
2512 (speedbar-do-function-pointer)
2513 (message "Refreshing speedbar...done"))
2514 (select-frame last-frame)))))
2516 (defun vhdl-show-messages ()
2517 "Get *Messages* buffer to show recent messages."
2518 (interactive)
2519 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2521 (defun vhdl-use-direct-instantiation ()
2522 "Return whether direct instantiation is used."
2523 (or (eq vhdl-use-direct-instantiation 'always)
2524 (and (eq vhdl-use-direct-instantiation 'standard)
2525 (not (vhdl-standard-p '87)))))
2527 (defun vhdl-max-marker (marker1 marker2)
2528 "Return larger marker."
2529 (if (> marker1 marker2) marker1 marker2))
2531 (defun vhdl-goto-marker (marker)
2532 "Goto marker in appropriate buffer."
2533 (when (markerp marker)
2534 (set-buffer (marker-buffer marker)))
2535 (goto-char marker))
2537 (defun vhdl-menu-split (list title)
2538 "Split menu LIST into several submenus, if number of
2539 elements > `vhdl-menu-max-size'."
2540 (if (> (length list) vhdl-menu-max-size)
2541 (let ((remain list)
2542 (result '())
2543 (sublist '())
2544 (menuno 1)
2545 (i 0))
2546 (while remain
2547 (setq sublist (cons (car remain) sublist))
2548 (setq remain (cdr remain))
2549 (setq i (+ i 1))
2550 (if (= i vhdl-menu-max-size)
2551 (progn
2552 (setq result (cons (cons (format "%s %s" title menuno)
2553 (nreverse sublist)) result))
2554 (setq i 0)
2555 (setq menuno (+ menuno 1))
2556 (setq sublist '()))))
2557 (and sublist
2558 (setq result (cons (cons (format "%s %s" title menuno)
2559 (nreverse sublist)) result)))
2560 (nreverse result))
2561 list))
2564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2565 ;;; Bindings
2566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2569 ;; Key bindings
2571 (defvar vhdl-template-map nil
2572 "Keymap for VHDL templates.")
2574 (defun vhdl-template-map-init ()
2575 "Initialize `vhdl-template-map'."
2576 (setq vhdl-template-map (make-sparse-keymap))
2577 ;; key bindings for VHDL templates
2578 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2579 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2580 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2581 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2582 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2583 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2584 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2585 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2586 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2587 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2588 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2589 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2590 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2591 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2592 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2593 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2594 (define-key vhdl-template-map "el" 'vhdl-template-else)
2595 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2596 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2597 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2598 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2599 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2600 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2601 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2602 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2603 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2604 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2605 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2606 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2607 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2608 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2609 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2610 (define-key vhdl-template-map "li" 'vhdl-template-library)
2611 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2612 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2613 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2614 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2615 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2616 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2617 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2618 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2619 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2620 (define-key vhdl-template-map "po" 'vhdl-template-port)
2621 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2622 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2623 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2624 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2625 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2626 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2627 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2628 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2629 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2630 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2631 (define-key vhdl-template-map "us" 'vhdl-template-use)
2632 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2633 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2634 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2635 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2636 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2637 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2638 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2639 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2640 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2641 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2642 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2643 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2644 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2645 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2646 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2647 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2648 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2649 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2650 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2651 (when (vhdl-standard-p 'ams)
2652 (define-key vhdl-template-map "br" 'vhdl-template-break)
2653 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2654 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2655 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2656 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2657 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2658 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2659 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2660 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2661 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2662 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2664 (when (vhdl-standard-p 'math)
2665 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2666 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2669 ;; initialize template map for VHDL Mode
2670 (vhdl-template-map-init)
2672 (defun vhdl-function-name (prefix string &optional postfix)
2673 "Generate a Lisp function name.
2674 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2675 STRING are replaced by `-' and substrings are converted to lower case."
2676 (let ((name prefix))
2677 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2678 (setq name
2679 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2680 (setq string (substring string (match-beginning 2))))
2681 (when postfix (setq name (concat name "-" postfix)))
2682 (intern name)))
2684 (defvar vhdl-model-map nil
2685 "Keymap for VHDL models.")
2687 (defun vhdl-model-map-init ()
2688 "Initialize `vhdl-model-map'."
2689 (setq vhdl-model-map (make-sparse-keymap))
2690 ;; key bindings for VHDL models
2691 (let ((model-alist vhdl-model-alist) model)
2692 (while model-alist
2693 (setq model (car model-alist))
2694 (define-key vhdl-model-map (nth 2 model)
2695 (vhdl-function-name "vhdl-model" (nth 0 model)))
2696 (setq model-alist (cdr model-alist)))))
2698 ;; initialize user model map for VHDL Mode
2699 (vhdl-model-map-init)
2701 (defvar vhdl-mode-map nil
2702 "Keymap for VHDL Mode.")
2704 (defun vhdl-mode-map-init ()
2705 "Initialize `vhdl-mode-map'."
2706 (setq vhdl-mode-map (make-sparse-keymap))
2707 ;; template key bindings
2708 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2709 ;; model key bindings
2710 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2711 ;; standard key bindings
2712 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2713 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2714 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2715 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2716 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2717 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2718 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2719 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2720 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2721 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2722 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2723 ;; backspace/delete key bindings
2724 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2725 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2726 (define-key vhdl-mode-map [delete] 'delete-char)
2727 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2728 ;; mode specific key bindings
2729 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2730 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2731 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2732 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2733 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2734 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2735 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2736 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2737 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2738 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2739 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2740 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2741 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2742 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2743 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2744 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2745 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2746 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2747 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2748 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2749 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2750 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2751 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2752 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2753 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2754 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2755 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2756 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2757 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2758 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2759 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2760 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2761 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2762 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2763 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2764 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2765 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2766 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2767 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2768 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2769 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2770 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2771 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2772 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2773 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2774 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2775 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2776 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2777 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2778 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2779 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2780 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2781 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2782 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2783 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2784 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2785 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2786 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2787 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2788 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2789 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2790 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2791 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2792 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2793 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2794 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2795 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2796 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2797 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2798 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2799 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2800 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2801 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2802 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2803 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2804 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2805 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2806 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2807 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2808 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2809 ;; insert commands bindings
2810 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2811 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2812 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2813 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2814 ;; electric key bindings
2815 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2816 (when vhdl-intelligent-tab
2817 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2818 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2819 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2820 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2821 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2822 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2823 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2824 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2825 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2826 (when (vhdl-standard-p 'ams)
2827 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2829 ;; initialize mode map for VHDL Mode
2830 (vhdl-mode-map-init)
2832 ;; define special minibuffer keymap for enabling word completion in minibuffer
2833 ;; (useful in template generator prompts)
2834 (defvar vhdl-minibuffer-local-map
2835 (let ((map (make-sparse-keymap)))
2836 (set-keymap-parent map minibuffer-local-map)
2837 (when vhdl-word-completion-in-minibuffer
2838 (define-key map "\t" 'vhdl-minibuffer-tab))
2839 map)
2840 "Keymap for minibuffer used in VHDL Mode.")
2842 ;; set up electric character functions to work with
2843 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2844 (mapc
2845 (function
2846 (lambda (sym)
2847 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2848 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2849 '(vhdl-electric-space
2850 vhdl-electric-tab
2851 vhdl-electric-return
2852 vhdl-electric-dash
2853 vhdl-electric-open-bracket
2854 vhdl-electric-close-bracket
2855 vhdl-electric-quote
2856 vhdl-electric-semicolon
2857 vhdl-electric-comma
2858 vhdl-electric-period
2859 vhdl-electric-equal))
2861 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2862 ;; Syntax table
2864 (defvar vhdl-mode-syntax-table nil
2865 "Syntax table used in `vhdl-mode' buffers.")
2867 (defvar vhdl-mode-ext-syntax-table nil
2868 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2870 (defun vhdl-mode-syntax-table-init ()
2871 "Initialize `vhdl-mode-syntax-table'."
2872 (setq vhdl-mode-syntax-table (make-syntax-table))
2873 ;; define punctuation
2874 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2875 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2876 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2877 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2878 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2879 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2880 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2881 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2882 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2883 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2884 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2885 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2886 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2887 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2888 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2889 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2890 ;; define string
2891 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2892 ;; define underscore
2893 (when vhdl-underscore-is-part-of-word
2894 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2895 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2896 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2897 ;; and \n and \^M end a comment
2898 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2899 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2900 ;; define parentheses to match
2901 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2902 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2903 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2904 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2905 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2906 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2907 ;; extended syntax table including '_' (for simpler search regexps)
2908 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2909 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2911 ;; initialize syntax table for VHDL Mode
2912 (vhdl-mode-syntax-table-init)
2914 (defvar vhdl-syntactic-context nil
2915 "Buffer local variable containing syntactic analysis list.")
2916 (make-variable-buffer-local 'vhdl-syntactic-context)
2918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2919 ;; Abbrev ook bindings
2921 (defvar vhdl-mode-abbrev-table nil
2922 "Abbrev table to use in `vhdl-mode' buffers.")
2924 (defun vhdl-mode-abbrev-table-init ()
2925 "Initialize `vhdl-mode-abbrev-table'."
2926 (define-abbrev-table 'vhdl-mode-abbrev-table
2927 (append
2928 (when (memq 'vhdl vhdl-electric-keywords)
2929 ;; VHDL'93 keywords
2930 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2932 ("--" . vhdl-template-display-comment-hook)
2933 ("abs" . vhdl-template-default-hook)
2934 ("access" . vhdl-template-default-hook)
2935 ("after" . vhdl-template-default-hook)
2936 ("alias" . vhdl-template-alias-hook)
2937 ("all" . vhdl-template-default-hook)
2938 ("and" . vhdl-template-default-hook)
2939 ("arch" . vhdl-template-architecture-hook)
2940 ("architecture" . vhdl-template-architecture-hook)
2941 ("array" . vhdl-template-default-hook)
2942 ("assert" . vhdl-template-assert-hook)
2943 ("attr" . vhdl-template-attribute-hook)
2944 ("attribute" . vhdl-template-attribute-hook)
2945 ("begin" . vhdl-template-default-indent-hook)
2946 ("block" . vhdl-template-block-hook)
2947 ("body" . vhdl-template-default-hook)
2948 ("buffer" . vhdl-template-default-hook)
2949 ("bus" . vhdl-template-default-hook)
2950 ("case" . vhdl-template-case-hook)
2951 ("comp" . vhdl-template-component-hook)
2952 ("component" . vhdl-template-component-hook)
2953 ("cond" . vhdl-template-conditional-signal-asst-hook)
2954 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2955 ("conf" . vhdl-template-configuration-hook)
2956 ("configuration" . vhdl-template-configuration-hook)
2957 ("cons" . vhdl-template-constant-hook)
2958 ("constant" . vhdl-template-constant-hook)
2959 ("disconnect" . vhdl-template-disconnect-hook)
2960 ("downto" . vhdl-template-default-hook)
2961 ("else" . vhdl-template-else-hook)
2962 ("elseif" . vhdl-template-elsif-hook)
2963 ("elsif" . vhdl-template-elsif-hook)
2964 ("end" . vhdl-template-default-indent-hook)
2965 ("entity" . vhdl-template-entity-hook)
2966 ("exit" . vhdl-template-exit-hook)
2967 ("file" . vhdl-template-file-hook)
2968 ("for" . vhdl-template-for-hook)
2969 ("func" . vhdl-template-function-hook)
2970 ("function" . vhdl-template-function-hook)
2971 ("generic" . vhdl-template-generic-hook)
2972 ("group" . vhdl-template-group-hook)
2973 ("guarded" . vhdl-template-default-hook)
2974 ("if" . vhdl-template-if-hook)
2975 ("impure" . vhdl-template-default-hook)
2976 ("in" . vhdl-template-default-hook)
2977 ("inertial" . vhdl-template-default-hook)
2978 ("inout" . vhdl-template-default-hook)
2979 ("inst" . vhdl-template-instance-hook)
2980 ("instance" . vhdl-template-instance-hook)
2981 ("is" . vhdl-template-default-hook)
2982 ("label" . vhdl-template-default-hook)
2983 ("library" . vhdl-template-library-hook)
2984 ("linkage" . vhdl-template-default-hook)
2985 ("literal" . vhdl-template-default-hook)
2986 ("loop" . vhdl-template-bare-loop-hook)
2987 ("map" . vhdl-template-map-hook)
2988 ("mod" . vhdl-template-default-hook)
2989 ("nand" . vhdl-template-default-hook)
2990 ("new" . vhdl-template-default-hook)
2991 ("next" . vhdl-template-next-hook)
2992 ("nor" . vhdl-template-default-hook)
2993 ("not" . vhdl-template-default-hook)
2994 ("null" . vhdl-template-default-hook)
2995 ("of" . vhdl-template-default-hook)
2996 ("on" . vhdl-template-default-hook)
2997 ("open" . vhdl-template-default-hook)
2998 ("or" . vhdl-template-default-hook)
2999 ("others" . vhdl-template-others-hook)
3000 ("out" . vhdl-template-default-hook)
3001 ("pack" . vhdl-template-package-hook)
3002 ("package" . vhdl-template-package-hook)
3003 ("port" . vhdl-template-port-hook)
3004 ("postponed" . vhdl-template-default-hook)
3005 ("procedure" . vhdl-template-procedure-hook)
3006 ("process" . vhdl-template-process-hook)
3007 ("pure" . vhdl-template-default-hook)
3008 ("range" . vhdl-template-default-hook)
3009 ("record" . vhdl-template-default-hook)
3010 ("register" . vhdl-template-default-hook)
3011 ("reject" . vhdl-template-default-hook)
3012 ("rem" . vhdl-template-default-hook)
3013 ("report" . vhdl-template-report-hook)
3014 ("return" . vhdl-template-return-hook)
3015 ("rol" . vhdl-template-default-hook)
3016 ("ror" . vhdl-template-default-hook)
3017 ("select" . vhdl-template-selected-signal-asst-hook)
3018 ("severity" . vhdl-template-default-hook)
3019 ("shared" . vhdl-template-default-hook)
3020 ("sig" . vhdl-template-signal-hook)
3021 ("signal" . vhdl-template-signal-hook)
3022 ("sla" . vhdl-template-default-hook)
3023 ("sll" . vhdl-template-default-hook)
3024 ("sra" . vhdl-template-default-hook)
3025 ("srl" . vhdl-template-default-hook)
3026 ("subtype" . vhdl-template-subtype-hook)
3027 ("then" . vhdl-template-default-hook)
3028 ("to" . vhdl-template-default-hook)
3029 ("transport" . vhdl-template-default-hook)
3030 ("type" . vhdl-template-type-hook)
3031 ("unaffected" . vhdl-template-default-hook)
3032 ("units" . vhdl-template-default-hook)
3033 ("until" . vhdl-template-default-hook)
3034 ("use" . vhdl-template-use-hook)
3035 ("var" . vhdl-template-variable-hook)
3036 ("variable" . vhdl-template-variable-hook)
3037 ("wait" . vhdl-template-wait-hook)
3038 ("when" . vhdl-template-when-hook)
3039 ("while" . vhdl-template-while-loop-hook)
3040 ("with" . vhdl-template-with-hook)
3041 ("xnor" . vhdl-template-default-hook)
3042 ("xor" . vhdl-template-default-hook)
3044 ;; VHDL-AMS keywords
3045 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3046 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
3048 ("across" . vhdl-template-default-hook)
3049 ("break" . vhdl-template-break-hook)
3050 ("limit" . vhdl-template-limit-hook)
3051 ("nature" . vhdl-template-nature-hook)
3052 ("noise" . vhdl-template-default-hook)
3053 ("procedural" . vhdl-template-procedural-hook)
3054 ("quantity" . vhdl-template-quantity-hook)
3055 ("reference" . vhdl-template-default-hook)
3056 ("spectrum" . vhdl-template-default-hook)
3057 ("subnature" . vhdl-template-subnature-hook)
3058 ("terminal" . vhdl-template-terminal-hook)
3059 ("through" . vhdl-template-default-hook)
3060 ("tolerance" . vhdl-template-default-hook)
3062 ;; user model keywords
3063 (when (memq 'user vhdl-electric-keywords)
3064 (let (abbrev-list keyword)
3065 (dolist (elem vhdl-model-alist)
3066 (setq keyword (nth 3 elem))
3067 (unless (equal keyword "")
3068 (push (list keyword ""
3069 (vhdl-function-name
3070 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3071 abbrev-list)))
3072 abbrev-list)))))
3074 ;; initialize abbrev table for VHDL Mode
3075 (vhdl-mode-abbrev-table-init)
3077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3078 ;; Template completion lists
3080 (defvar vhdl-template-construct-alist nil
3081 "List of built-in construct templates.")
3083 (defun vhdl-template-construct-alist-init ()
3084 "Initialize `vhdl-template-construct-alist'."
3085 (setq
3086 vhdl-template-construct-alist
3087 (append
3089 ("alias declaration" vhdl-template-alias)
3090 ("architecture body" vhdl-template-architecture)
3091 ("assertion" vhdl-template-assert)
3092 ("attribute declaration" vhdl-template-attribute-decl)
3093 ("attribute specification" vhdl-template-attribute-spec)
3094 ("block configuration" vhdl-template-block-configuration)
3095 ("block statement" vhdl-template-block)
3096 ("case statement" vhdl-template-case-is)
3097 ("component configuration" vhdl-template-component-conf)
3098 ("component declaration" vhdl-template-component-decl)
3099 ("component instantiation statement" vhdl-template-component-inst)
3100 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3101 ("configuration declaration" vhdl-template-configuration-decl)
3102 ("configuration specification" vhdl-template-configuration-spec)
3103 ("constant declaration" vhdl-template-constant)
3104 ("disconnection specification" vhdl-template-disconnect)
3105 ("entity declaration" vhdl-template-entity)
3106 ("exit statement" vhdl-template-exit)
3107 ("file declaration" vhdl-template-file)
3108 ("generate statement" vhdl-template-generate)
3109 ("generic clause" vhdl-template-generic)
3110 ("group declaration" vhdl-template-group-decl)
3111 ("group template declaration" vhdl-template-group-template)
3112 ("if statement" vhdl-template-if-then)
3113 ("library clause" vhdl-template-library)
3114 ("loop statement" vhdl-template-loop)
3115 ("next statement" vhdl-template-next)
3116 ("package declaration" vhdl-template-package-decl)
3117 ("package body" vhdl-template-package-body)
3118 ("port clause" vhdl-template-port)
3119 ("process statement" vhdl-template-process)
3120 ("report statement" vhdl-template-report)
3121 ("return statement" vhdl-template-return)
3122 ("selected signal assignment" vhdl-template-selected-signal-asst)
3123 ("signal declaration" vhdl-template-signal)
3124 ("subprogram declaration" vhdl-template-subprogram-decl)
3125 ("subprogram body" vhdl-template-subprogram-body)
3126 ("subtype declaration" vhdl-template-subtype)
3127 ("type declaration" vhdl-template-type)
3128 ("use clause" vhdl-template-use)
3129 ("variable declaration" vhdl-template-variable)
3130 ("wait statement" vhdl-template-wait)
3132 (when (vhdl-standard-p 'ams)
3134 ("break statement" vhdl-template-break)
3135 ("nature declaration" vhdl-template-nature)
3136 ("quantity declaration" vhdl-template-quantity)
3137 ("simultaneous case statement" vhdl-template-case-use)
3138 ("simultaneous if statement" vhdl-template-if-use)
3139 ("simultaneous procedural statement" vhdl-template-procedural)
3140 ("step limit specification" vhdl-template-limit)
3141 ("subnature declaration" vhdl-template-subnature)
3142 ("terminal declaration" vhdl-template-terminal)
3143 )))))
3145 ;; initialize for VHDL Mode
3146 (vhdl-template-construct-alist-init)
3148 (defvar vhdl-template-package-alist nil
3149 "List of built-in package templates.")
3151 (defun vhdl-template-package-alist-init ()
3152 "Initialize `vhdl-template-package-alist'."
3153 (setq
3154 vhdl-template-package-alist
3155 (append
3157 ("numeric_bit" vhdl-template-package-numeric-bit)
3158 ("numeric_std" vhdl-template-package-numeric-std)
3159 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3160 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3161 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3162 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3163 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3164 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3165 ("textio" vhdl-template-package-textio)
3167 (when (vhdl-standard-p 'math)
3169 ("math_complex" vhdl-template-package-math-complex)
3170 ("math_real" vhdl-template-package-math-real)
3171 )))))
3173 ;; initialize for VHDL Mode
3174 (vhdl-template-package-alist-init)
3176 (defvar vhdl-template-directive-alist
3178 ("translate_on" vhdl-template-directive-translate-on)
3179 ("translate_off" vhdl-template-directive-translate-off)
3180 ("synthesis_on" vhdl-template-directive-synthesis-on)
3181 ("synthesis_off" vhdl-template-directive-synthesis-off)
3183 "List of built-in directive templates.")
3186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3187 ;;; Menus
3188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3191 ;; VHDL menu (using `easy-menu.el')
3193 (defun vhdl-customize ()
3194 "Call the customize function with `vhdl' as argument."
3195 (interactive)
3196 (customize-browse 'vhdl))
3198 (defun vhdl-create-mode-menu ()
3199 "Create VHDL Mode menu."
3200 `("VHDL"
3201 ,(append
3202 '("Project"
3203 ["None" (vhdl-set-project "")
3204 :style radio :selected (null vhdl-project)]
3205 "--")
3206 ;; add menu entries for defined projects
3207 (let ((project-alist vhdl-project-alist) menu-list name)
3208 (while project-alist
3209 (setq name (caar project-alist))
3210 (setq menu-list
3211 (cons `[,name (vhdl-set-project ,name)
3212 :style radio :selected (equal ,name vhdl-project)]
3213 menu-list))
3214 (setq project-alist (cdr project-alist)))
3215 (setq menu-list
3216 (if vhdl-project-sort
3217 (sort menu-list
3218 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3219 (nreverse menu-list)))
3220 (vhdl-menu-split menu-list "Project"))
3221 '("--" "--"
3222 ["Select Project..." vhdl-set-project t]
3223 ["Set As Default Project" vhdl-set-default-project t]
3224 "--"
3225 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3226 ["Import Project..." vhdl-import-project
3227 :keys "C-c C-p C-m" :active t]
3228 ["Export Project" vhdl-export-project vhdl-project]
3229 "--"
3230 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3231 "--"
3232 ("Compile"
3233 ["Compile Buffer" vhdl-compile t]
3234 ["Stop Compilation" kill-compilation t]
3235 "--"
3236 ["Make" vhdl-make t]
3237 ["Generate Makefile" vhdl-generate-makefile t]
3238 "--"
3239 ["Next Error" next-error t]
3240 ["Previous Error" previous-error t]
3241 ["First Error" first-error t]
3242 "--"
3243 ,(append
3244 '("Compiler")
3245 ;; add menu entries for defined compilers
3246 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3247 (while comp-alist
3248 (setq name (caar comp-alist))
3249 (setq menu-list
3250 (cons `[,name (setq vhdl-compiler ,name)
3251 :style radio :selected (equal ,name vhdl-compiler)]
3252 menu-list))
3253 (setq comp-alist (cdr comp-alist)))
3254 (setq menu-list (nreverse menu-list))
3255 (vhdl-menu-split menu-list "Compiler"))
3256 '("--" "--"
3257 ["Select Compiler..." vhdl-set-compiler t]
3258 "--"
3259 ["Customize Compiler..."
3260 (customize-option 'vhdl-compiler-alist) t])))
3261 "--"
3262 ,(append
3263 '("Template"
3264 ("VHDL Construct 1"
3265 ["Alias" vhdl-template-alias t]
3266 ["Architecture" vhdl-template-architecture t]
3267 ["Assert" vhdl-template-assert t]
3268 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3269 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3270 ["Block" vhdl-template-block t]
3271 ["Case" vhdl-template-case-is t]
3272 ["Component (Decl)" vhdl-template-component-decl t]
3273 ["(Component) Instance" vhdl-template-component-inst t]
3274 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3275 ["Configuration (Block)" vhdl-template-block-configuration t]
3276 ["Configuration (Comp)" vhdl-template-component-conf t]
3277 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3278 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3279 ["Constant" vhdl-template-constant t]
3280 ["Disconnect" vhdl-template-disconnect t]
3281 ["Else" vhdl-template-else t]
3282 ["Elsif" vhdl-template-elsif t]
3283 ["Entity" vhdl-template-entity t]
3284 ["Exit" vhdl-template-exit t]
3285 ["File" vhdl-template-file t]
3286 ["For (Generate)" vhdl-template-for-generate t]
3287 ["For (Loop)" vhdl-template-for-loop t]
3288 ["Function (Body)" vhdl-template-function-body t]
3289 ["Function (Decl)" vhdl-template-function-decl t]
3290 ["Generic" vhdl-template-generic t]
3291 ["Group (Decl)" vhdl-template-group-decl t]
3292 ["Group (Template)" vhdl-template-group-template t])
3293 ("VHDL Construct 2"
3294 ["If (Generate)" vhdl-template-if-generate t]
3295 ["If (Then)" vhdl-template-if-then t]
3296 ["Library" vhdl-template-library t]
3297 ["Loop" vhdl-template-bare-loop t]
3298 ["Map" vhdl-template-map t]
3299 ["Next" vhdl-template-next t]
3300 ["Others (Aggregate)" vhdl-template-others t]
3301 ["Package (Decl)" vhdl-template-package-decl t]
3302 ["Package (Body)" vhdl-template-package-body t]
3303 ["Port" vhdl-template-port t]
3304 ["Procedure (Body)" vhdl-template-procedure-body t]
3305 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3306 ["Process (Comb)" vhdl-template-process-comb t]
3307 ["Process (Seq)" vhdl-template-process-seq t]
3308 ["Report" vhdl-template-report t]
3309 ["Return" vhdl-template-return t]
3310 ["Select" vhdl-template-selected-signal-asst t]
3311 ["Signal" vhdl-template-signal t]
3312 ["Subtype" vhdl-template-subtype t]
3313 ["Type" vhdl-template-type t]
3314 ["Use" vhdl-template-use t]
3315 ["Variable" vhdl-template-variable t]
3316 ["Wait" vhdl-template-wait t]
3317 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3318 ["When" vhdl-template-when t]
3319 ["While (Loop)" vhdl-template-while-loop t]
3320 ["With" vhdl-template-with t]))
3321 (when (vhdl-standard-p 'ams)
3322 '(("VHDL-AMS Construct"
3323 ["Break" vhdl-template-break t]
3324 ["Case (Use)" vhdl-template-case-use t]
3325 ["If (Use)" vhdl-template-if-use t]
3326 ["Limit" vhdl-template-limit t]
3327 ["Nature" vhdl-template-nature t]
3328 ["Procedural" vhdl-template-procedural t]
3329 ["Quantity (Free)" vhdl-template-quantity-free t]
3330 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3331 ["Quantity (Source)" vhdl-template-quantity-source t]
3332 ["Subnature" vhdl-template-subnature t]
3333 ["Terminal" vhdl-template-terminal t])))
3334 '(["Insert Construct..." vhdl-template-insert-construct
3335 :keys "C-c C-i C-t"]
3336 "--")
3337 (list
3338 (append
3339 '("Package")
3340 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3341 ["numeric_std" vhdl-template-package-numeric-std t]
3342 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3343 ["textio" vhdl-template-package-textio t]
3344 "--"
3345 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3346 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3347 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3348 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3349 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3350 "--")
3351 (when (vhdl-standard-p 'ams)
3352 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3353 ["material_constants" vhdl-template-package-material-constants t]
3354 ["energy_systems" vhdl-template-package-energy-systems t]
3355 ["electrical_systems" vhdl-template-package-electrical-systems t]
3356 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3357 ["radiant_systems" vhdl-template-package-radiant-systems t]
3358 ["thermal_systems" vhdl-template-package-thermal-systems t]
3359 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3360 "--"))
3361 (when (vhdl-standard-p 'math)
3362 '(["math_complex" vhdl-template-package-math-complex t]
3363 ["math_real" vhdl-template-package-math-real t]
3364 "--"))
3365 '(["Insert Package..." vhdl-template-insert-package
3366 :keys "C-c C-i C-p"])))
3367 '(("Directive"
3368 ["translate_on" vhdl-template-directive-translate-on t]
3369 ["translate_off" vhdl-template-directive-translate-off t]
3370 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3371 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3372 "--"
3373 ["Insert Directive..." vhdl-template-insert-directive
3374 :keys "C-c C-i C-d"])
3375 "--"
3376 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3377 ["Insert Footer" vhdl-template-footer t]
3378 ["Insert Date" vhdl-template-insert-date t]
3379 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3380 "--"
3381 ["Query Next Prompt" vhdl-template-search-prompt t]))
3382 ,(append
3383 '("Model")
3384 ;; add menu entries for defined models
3385 (let ((model-alist vhdl-model-alist) menu-list model)
3386 (while model-alist
3387 (setq model (car model-alist))
3388 (setq menu-list
3389 (cons
3390 (vector
3391 (nth 0 model)
3392 (vhdl-function-name "vhdl-model" (nth 0 model))
3393 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3394 menu-list))
3395 (setq model-alist (cdr model-alist)))
3396 (setq menu-list (nreverse menu-list))
3397 (vhdl-menu-split menu-list "Model"))
3398 '("--" "--"
3399 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3400 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3401 ("Port"
3402 ["Copy" vhdl-port-copy t]
3403 "--"
3404 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3405 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3406 ["Paste As Instance" vhdl-port-paste-instance
3407 :keys "C-c C-p C-i" :active vhdl-port-list]
3408 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3409 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3410 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3411 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3412 "--"
3413 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3414 "--"
3415 ["Flatten" vhdl-port-flatten
3416 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3417 ["Reverse Direction" vhdl-port-reverse-direction
3418 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3419 ("Compose"
3420 ["New Component" vhdl-compose-new-component t]
3421 ["Copy Component" vhdl-port-copy t]
3422 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3423 ["Wire Components" vhdl-compose-wire-components t]
3424 "--"
3425 ["Generate Configuration" vhdl-compose-configuration t]
3426 ["Generate Components Package" vhdl-compose-components-package t])
3427 ("Subprogram"
3428 ["Copy" vhdl-subprog-copy t]
3429 "--"
3430 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3431 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3432 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3433 "--"
3434 ["Flatten" vhdl-subprog-flatten
3435 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3436 "--"
3437 ("Comment"
3438 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3439 "--"
3440 ["Insert Inline Comment" vhdl-comment-append-inline t]
3441 ["Insert Horizontal Line" vhdl-comment-display-line t]
3442 ["Insert Display Comment" vhdl-comment-display t]
3443 "--"
3444 ["Fill Comment" fill-paragraph t]
3445 ["Fill Comment Region" fill-region (mark)]
3446 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3447 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3448 ("Line"
3449 ["Kill" vhdl-line-kill t]
3450 ["Copy" vhdl-line-copy t]
3451 ["Yank" vhdl-line-yank t]
3452 ["Expand" vhdl-line-expand t]
3453 "--"
3454 ["Transpose Next" vhdl-line-transpose-next t]
3455 ["Transpose Prev" vhdl-line-transpose-previous t]
3456 ["Open" vhdl-line-open t]
3457 ["Join" vhdl-delete-indentation t]
3458 "--"
3459 ["Goto" goto-line t]
3460 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3461 ("Move"
3462 ["Forward Statement" vhdl-end-of-statement t]
3463 ["Backward Statement" vhdl-beginning-of-statement t]
3464 ["Forward Expression" vhdl-forward-sexp t]
3465 ["Backward Expression" vhdl-backward-sexp t]
3466 ["Forward Same Indent" vhdl-forward-same-indent t]
3467 ["Backward Same Indent" vhdl-backward-same-indent t]
3468 ["Forward Function" vhdl-end-of-defun t]
3469 ["Backward Function" vhdl-beginning-of-defun t]
3470 ["Mark Function" vhdl-mark-defun t])
3471 "--"
3472 ("Indent"
3473 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3474 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3475 ["Region" vhdl-indent-region (mark)]
3476 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3477 ("Align"
3478 ["Group" vhdl-align-group t]
3479 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3480 ["List" vhdl-align-list t]
3481 ["Declarations" vhdl-align-declarations t]
3482 ["Region" vhdl-align-region (mark)]
3483 ["Buffer" vhdl-align-buffer t]
3484 "--"
3485 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3486 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3487 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3488 ("Fill"
3489 ["List" vhdl-fill-list t]
3490 ["Group" vhdl-fill-group t]
3491 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3492 ["Region" vhdl-fill-region (mark)])
3493 ("Beautify"
3494 ["Region" vhdl-beautify-region (mark)]
3495 ["Buffer" vhdl-beautify-buffer t])
3496 ("Fix"
3497 ["Generic/Port Clause" vhdl-fix-clause t]
3498 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3499 "--"
3500 ["Case Region" vhdl-fix-case-region (mark)]
3501 ["Case Buffer" vhdl-fix-case-buffer t]
3502 "--"
3503 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3504 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3505 "--"
3506 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3507 ("Update"
3508 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3509 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3510 "--"
3511 ["Fontify Buffer" vhdl-fontify-buffer t]
3512 ["Statistics Buffer" vhdl-statistics-buffer t]
3513 ["Show Messages" vhdl-show-messages t]
3514 ["Syntactic Info" vhdl-show-syntactic-information t]
3515 "--"
3516 ["Speedbar" vhdl-speedbar t]
3517 ["Hide/Show" vhdl-hs-minor-mode t]
3518 "--"
3519 ("Documentation"
3520 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3521 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3522 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3523 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3524 ["Version" vhdl-version t]
3525 ["Bug Report..." vhdl-submit-bug-report t]
3526 "--"
3527 ("Options"
3528 ("Mode"
3529 ["Electric Mode"
3530 (progn (customize-set-variable 'vhdl-electric-mode
3531 (not vhdl-electric-mode))
3532 (vhdl-mode-line-update))
3533 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3534 ["Stutter Mode"
3535 (progn (customize-set-variable 'vhdl-stutter-mode
3536 (not vhdl-stutter-mode))
3537 (vhdl-mode-line-update))
3538 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3539 ["Indent Tabs Mode"
3540 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3541 (not vhdl-indent-tabs-mode))
3542 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3543 :style toggle :selected vhdl-indent-tabs-mode]
3544 "--"
3545 ["Customize Group..." (customize-group 'vhdl-mode) t])
3546 ("Project"
3547 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3548 ,(append
3549 '("Selected Project at Startup"
3550 ["None" (progn (customize-set-variable 'vhdl-project nil)
3551 (vhdl-set-project ""))
3552 :style radio :selected (null vhdl-project)]
3553 "--")
3554 ;; add menu entries for defined projects
3555 (let ((project-alist vhdl-project-alist) menu-list name)
3556 (while project-alist
3557 (setq name (caar project-alist))
3558 (setq menu-list
3559 (cons `[,name (progn (customize-set-variable
3560 'vhdl-project ,name)
3561 (vhdl-set-project ,name))
3562 :style radio :selected (equal ,name vhdl-project)]
3563 menu-list))
3564 (setq project-alist (cdr project-alist)))
3565 (setq menu-list (nreverse menu-list))
3566 (vhdl-menu-split menu-list "Project")))
3567 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3568 ("Auto Load Setup File"
3569 ["At Startup"
3570 (customize-set-variable 'vhdl-project-auto-load
3571 (if (memq 'startup vhdl-project-auto-load)
3572 (delq 'startup vhdl-project-auto-load)
3573 (cons 'startup vhdl-project-auto-load)))
3574 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3575 ["Sort Projects"
3576 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3577 :style toggle :selected vhdl-project-sort]
3578 "--"
3579 ["Customize Group..." (customize-group 'vhdl-project) t])
3580 ("Compiler"
3581 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3582 ,(append
3583 '("Selected Compiler at Startup")
3584 ;; add menu entries for defined compilers
3585 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3586 (while comp-alist
3587 (setq name (caar comp-alist))
3588 (setq menu-list
3589 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3590 :style radio :selected (equal ,name vhdl-compiler)]
3591 menu-list))
3592 (setq comp-alist (cdr comp-alist)))
3593 (setq menu-list (nreverse menu-list))
3594 (vhdl-menu-split menu-list "Compiler")))
3595 ["Use Local Error Regexp"
3596 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3597 (not vhdl-compile-use-local-error-regexp))
3598 :style toggle :selected vhdl-compile-use-local-error-regexp]
3599 ["Makefile Default Targets..."
3600 (customize-option 'vhdl-makefile-default-targets) t]
3601 ["Makefile Generation Hook..."
3602 (customize-option 'vhdl-makefile-generation-hook) t]
3603 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3604 "--"
3605 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3606 ("Style"
3607 ("VHDL Standard"
3608 ["VHDL'87"
3609 (progn (customize-set-variable 'vhdl-standard
3610 (list '87 (cadr vhdl-standard)))
3611 (vhdl-activate-customizations))
3612 :style radio :selected (eq '87 (car vhdl-standard))]
3613 ["VHDL'93/02"
3614 (progn (customize-set-variable 'vhdl-standard
3615 (list '93 (cadr vhdl-standard)))
3616 (vhdl-activate-customizations))
3617 :style radio :selected (eq '93 (car vhdl-standard))]
3618 "--"
3619 ["VHDL-AMS"
3620 (progn (customize-set-variable
3621 'vhdl-standard (list (car vhdl-standard)
3622 (if (memq 'ams (cadr vhdl-standard))
3623 (delq 'ams (cadr vhdl-standard))
3624 (cons 'ams (cadr vhdl-standard)))))
3625 (vhdl-activate-customizations))
3626 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3627 ["Math Packages"
3628 (progn (customize-set-variable
3629 'vhdl-standard (list (car vhdl-standard)
3630 (if (memq 'math (cadr vhdl-standard))
3631 (delq 'math (cadr vhdl-standard))
3632 (cons 'math (cadr vhdl-standard)))))
3633 (vhdl-activate-customizations))
3634 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3635 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3636 ["Upper Case Keywords"
3637 (customize-set-variable 'vhdl-upper-case-keywords
3638 (not vhdl-upper-case-keywords))
3639 :style toggle :selected vhdl-upper-case-keywords]
3640 ["Upper Case Types"
3641 (customize-set-variable 'vhdl-upper-case-types
3642 (not vhdl-upper-case-types))
3643 :style toggle :selected vhdl-upper-case-types]
3644 ["Upper Case Attributes"
3645 (customize-set-variable 'vhdl-upper-case-attributes
3646 (not vhdl-upper-case-attributes))
3647 :style toggle :selected vhdl-upper-case-attributes]
3648 ["Upper Case Enumeration Values"
3649 (customize-set-variable 'vhdl-upper-case-enum-values
3650 (not vhdl-upper-case-enum-values))
3651 :style toggle :selected vhdl-upper-case-enum-values]
3652 ["Upper Case Constants"
3653 (customize-set-variable 'vhdl-upper-case-constants
3654 (not vhdl-upper-case-constants))
3655 :style toggle :selected vhdl-upper-case-constants]
3656 ("Use Direct Instantiation"
3657 ["Never"
3658 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3659 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3660 ["Standard"
3661 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3662 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3663 ["Always"
3664 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3665 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3666 ["Include Array Index and Record Field in Sensitivity List"
3667 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3668 (not vhdl-array-index-record-field-in-sensitivity-list))
3669 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3670 "--"
3671 ["Customize Group..." (customize-group 'vhdl-style) t])
3672 ("Naming"
3673 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3674 ["Architecture File Name..."
3675 (customize-option 'vhdl-architecture-file-name) t]
3676 ["Configuration File Name..."
3677 (customize-option 'vhdl-configuration-file-name) t]
3678 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3679 ("File Name Case"
3680 ["As Is"
3681 (customize-set-variable 'vhdl-file-name-case 'identity)
3682 :style radio :selected (eq 'identity vhdl-file-name-case)]
3683 ["Lower Case"
3684 (customize-set-variable 'vhdl-file-name-case 'downcase)
3685 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3686 ["Upper Case"
3687 (customize-set-variable 'vhdl-file-name-case 'upcase)
3688 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3689 ["Capitalize"
3690 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3691 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3692 "--"
3693 ["Customize Group..." (customize-group 'vhdl-naming) t])
3694 ("Template"
3695 ("Electric Keywords"
3696 ["VHDL Keywords"
3697 (customize-set-variable 'vhdl-electric-keywords
3698 (if (memq 'vhdl vhdl-electric-keywords)
3699 (delq 'vhdl vhdl-electric-keywords)
3700 (cons 'vhdl vhdl-electric-keywords)))
3701 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3702 ["User Model Keywords"
3703 (customize-set-variable 'vhdl-electric-keywords
3704 (if (memq 'user vhdl-electric-keywords)
3705 (delq 'user vhdl-electric-keywords)
3706 (cons 'user vhdl-electric-keywords)))
3707 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3708 ("Insert Optional Labels"
3709 ["None"
3710 (customize-set-variable 'vhdl-optional-labels 'none)
3711 :style radio :selected (eq 'none vhdl-optional-labels)]
3712 ["Processes Only"
3713 (customize-set-variable 'vhdl-optional-labels 'process)
3714 :style radio :selected (eq 'process vhdl-optional-labels)]
3715 ["All Constructs"
3716 (customize-set-variable 'vhdl-optional-labels 'all)
3717 :style radio :selected (eq 'all vhdl-optional-labels)])
3718 ("Insert Empty Lines"
3719 ["None"
3720 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3721 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3722 ["Design Units Only"
3723 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3724 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3725 ["All Constructs"
3726 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3727 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3728 ["Argument List Indent"
3729 (customize-set-variable 'vhdl-argument-list-indent
3730 (not vhdl-argument-list-indent))
3731 :style toggle :selected vhdl-argument-list-indent]
3732 ["Association List with Formals"
3733 (customize-set-variable 'vhdl-association-list-with-formals
3734 (not vhdl-association-list-with-formals))
3735 :style toggle :selected vhdl-association-list-with-formals]
3736 ["Conditions in Parenthesis"
3737 (customize-set-variable 'vhdl-conditions-in-parenthesis
3738 (not vhdl-conditions-in-parenthesis))
3739 :style toggle :selected vhdl-conditions-in-parenthesis]
3740 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3741 ["One String..." (customize-option 'vhdl-one-string) t]
3742 ("File Header"
3743 ["Header String..." (customize-option 'vhdl-file-header) t]
3744 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3745 ["Company Name..." (customize-option 'vhdl-company-name) t]
3746 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3747 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3748 ["Date Format..." (customize-option 'vhdl-date-format) t]
3749 ["Modify Date Prefix String..."
3750 (customize-option 'vhdl-modify-date-prefix-string) t]
3751 ["Modify Date on Saving"
3752 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3753 (not vhdl-modify-date-on-saving))
3754 (vhdl-activate-customizations))
3755 :style toggle :selected vhdl-modify-date-on-saving])
3756 ("Sequential Process"
3757 ("Kind of Reset"
3758 ["None"
3759 (customize-set-variable 'vhdl-reset-kind 'none)
3760 :style radio :selected (eq 'none vhdl-reset-kind)]
3761 ["Synchronous"
3762 (customize-set-variable 'vhdl-reset-kind 'sync)
3763 :style radio :selected (eq 'sync vhdl-reset-kind)]
3764 ["Asynchronous"
3765 (customize-set-variable 'vhdl-reset-kind 'async)
3766 :style radio :selected (eq 'async vhdl-reset-kind)]
3767 ["Query"
3768 (customize-set-variable 'vhdl-reset-kind 'query)
3769 :style radio :selected (eq 'query vhdl-reset-kind)])
3770 ["Reset is Active High"
3771 (customize-set-variable 'vhdl-reset-active-high
3772 (not vhdl-reset-active-high))
3773 :style toggle :selected vhdl-reset-active-high]
3774 ["Use Rising Clock Edge"
3775 (customize-set-variable 'vhdl-clock-rising-edge
3776 (not vhdl-clock-rising-edge))
3777 :style toggle :selected vhdl-clock-rising-edge]
3778 ("Clock Edge Condition"
3779 ["Standard"
3780 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3781 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3782 ["Function \"rising_edge\""
3783 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3784 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3785 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3786 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3787 "--"
3788 ["Customize Group..." (customize-group 'vhdl-template) t])
3789 ("Model"
3790 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3791 ("Port"
3792 ["Include Port Comments"
3793 (customize-set-variable 'vhdl-include-port-comments
3794 (not vhdl-include-port-comments))
3795 :style toggle :selected vhdl-include-port-comments]
3796 ["Include Direction Comments"
3797 (customize-set-variable 'vhdl-include-direction-comments
3798 (not vhdl-include-direction-comments))
3799 :style toggle :selected vhdl-include-direction-comments]
3800 ["Include Type Comments"
3801 (customize-set-variable 'vhdl-include-type-comments
3802 (not vhdl-include-type-comments))
3803 :style toggle :selected vhdl-include-type-comments]
3804 ("Include Group Comments"
3805 ["Never"
3806 (customize-set-variable 'vhdl-include-group-comments 'never)
3807 :style radio :selected (eq 'never vhdl-include-group-comments)]
3808 ["Declarations"
3809 (customize-set-variable 'vhdl-include-group-comments 'decl)
3810 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3811 ["Always"
3812 (customize-set-variable 'vhdl-include-group-comments 'always)
3813 :style radio :selected (eq 'always vhdl-include-group-comments)])
3814 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3815 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3816 ("Testbench"
3817 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3818 ["Architecture Name..."
3819 (customize-option 'vhdl-testbench-architecture-name) t]
3820 ["Configuration Name..."
3821 (customize-option 'vhdl-testbench-configuration-name) t]
3822 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3823 ["Include Header"
3824 (customize-set-variable 'vhdl-testbench-include-header
3825 (not vhdl-testbench-include-header))
3826 :style toggle :selected vhdl-testbench-include-header]
3827 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3828 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3829 ["Initialize Signals"
3830 (customize-set-variable 'vhdl-testbench-initialize-signals
3831 (not vhdl-testbench-initialize-signals))
3832 :style toggle :selected vhdl-testbench-initialize-signals]
3833 ["Include Library Clause"
3834 (customize-set-variable 'vhdl-testbench-include-library
3835 (not vhdl-testbench-include-library))
3836 :style toggle :selected vhdl-testbench-include-library]
3837 ["Include Configuration"
3838 (customize-set-variable 'vhdl-testbench-include-configuration
3839 (not vhdl-testbench-include-configuration))
3840 :style toggle :selected vhdl-testbench-include-configuration]
3841 ("Create Files"
3842 ["None"
3843 (customize-set-variable 'vhdl-testbench-create-files 'none)
3844 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3845 ["Single"
3846 (customize-set-variable 'vhdl-testbench-create-files 'single)
3847 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3848 ["Separate"
3849 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3850 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3851 ["Testbench Entity File Name..."
3852 (customize-option 'vhdl-testbench-entity-file-name) t]
3853 ["Testbench Architecture File Name..."
3854 (customize-option 'vhdl-testbench-architecture-file-name) t])
3855 "--"
3856 ["Customize Group..." (customize-group 'vhdl-port) t])
3857 ("Compose"
3858 ["Architecture Name..."
3859 (customize-option 'vhdl-compose-architecture-name) t]
3860 ["Configuration Name..."
3861 (customize-option 'vhdl-compose-configuration-name) t]
3862 ["Components Package Name..."
3863 (customize-option 'vhdl-components-package-name) t]
3864 ["Use Components Package"
3865 (customize-set-variable 'vhdl-use-components-package
3866 (not vhdl-use-components-package))
3867 :style toggle :selected vhdl-use-components-package]
3868 ["Include Header"
3869 (customize-set-variable 'vhdl-compose-include-header
3870 (not vhdl-compose-include-header))
3871 :style toggle :selected vhdl-compose-include-header]
3872 ("Create Entity/Architecture Files"
3873 ["None"
3874 (customize-set-variable 'vhdl-compose-create-files 'none)
3875 :style radio :selected (eq 'none vhdl-compose-create-files)]
3876 ["Single"
3877 (customize-set-variable 'vhdl-compose-create-files 'single)
3878 :style radio :selected (eq 'single vhdl-compose-create-files)]
3879 ["Separate"
3880 (customize-set-variable 'vhdl-compose-create-files 'separate)
3881 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3882 ["Create Configuration File"
3883 (customize-set-variable 'vhdl-compose-configuration-create-file
3884 (not vhdl-compose-configuration-create-file))
3885 :style toggle :selected vhdl-compose-configuration-create-file]
3886 ["Hierarchical Configuration"
3887 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3888 (not vhdl-compose-configuration-hierarchical))
3889 :style toggle :selected vhdl-compose-configuration-hierarchical]
3890 ["Use Subconfiguration"
3891 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3892 (not vhdl-compose-configuration-use-subconfiguration))
3893 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3894 "--"
3895 ["Customize Group..." (customize-group 'vhdl-compose) t])
3896 ("Comment"
3897 ["Self Insert Comments"
3898 (customize-set-variable 'vhdl-self-insert-comments
3899 (not vhdl-self-insert-comments))
3900 :style toggle :selected vhdl-self-insert-comments]
3901 ["Prompt for Comments"
3902 (customize-set-variable 'vhdl-prompt-for-comments
3903 (not vhdl-prompt-for-comments))
3904 :style toggle :selected vhdl-prompt-for-comments]
3905 ["Inline Comment Column..."
3906 (customize-option 'vhdl-inline-comment-column) t]
3907 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3908 "--"
3909 ["Customize Group..." (customize-group 'vhdl-comment) t])
3910 ("Align"
3911 ["Auto Align Templates"
3912 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3913 :style toggle :selected vhdl-auto-align]
3914 ["Align Line Groups"
3915 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3916 :style toggle :selected vhdl-align-groups]
3917 ["Group Separation String..."
3918 (customize-set-variable 'vhdl-align-group-separate) t]
3919 ["Align Lines with Same Indent"
3920 (customize-set-variable 'vhdl-align-same-indent
3921 (not vhdl-align-same-indent))
3922 :style toggle :selected vhdl-align-same-indent]
3923 "--"
3924 ["Customize Group..." (customize-group 'vhdl-align) t])
3925 ("Highlight"
3926 ["Highlighting On/Off..."
3927 (customize-option
3928 (if (fboundp 'global-font-lock-mode)
3929 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3930 ["Highlight Keywords"
3931 (progn (customize-set-variable 'vhdl-highlight-keywords
3932 (not vhdl-highlight-keywords))
3933 (vhdl-fontify-buffer))
3934 :style toggle :selected vhdl-highlight-keywords]
3935 ["Highlight Names"
3936 (progn (customize-set-variable 'vhdl-highlight-names
3937 (not vhdl-highlight-names))
3938 (vhdl-fontify-buffer))
3939 :style toggle :selected vhdl-highlight-names]
3940 ["Highlight Special Words"
3941 (progn (customize-set-variable 'vhdl-highlight-special-words
3942 (not vhdl-highlight-special-words))
3943 (vhdl-fontify-buffer))
3944 :style toggle :selected vhdl-highlight-special-words]
3945 ["Highlight Forbidden Words"
3946 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3947 (not vhdl-highlight-forbidden-words))
3948 (vhdl-fontify-buffer))
3949 :style toggle :selected vhdl-highlight-forbidden-words]
3950 ["Highlight Verilog Keywords"
3951 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3952 (not vhdl-highlight-verilog-keywords))
3953 (vhdl-fontify-buffer))
3954 :style toggle :selected vhdl-highlight-verilog-keywords]
3955 ["Highlight \"translate_off\""
3956 (progn (customize-set-variable 'vhdl-highlight-translate-off
3957 (not vhdl-highlight-translate-off))
3958 (vhdl-fontify-buffer))
3959 :style toggle :selected vhdl-highlight-translate-off]
3960 ["Case Sensitive Highlighting"
3961 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3962 (not vhdl-highlight-case-sensitive))
3963 (vhdl-fontify-buffer))
3964 :style toggle :selected vhdl-highlight-case-sensitive]
3965 ["Special Syntax Definition..."
3966 (customize-option 'vhdl-special-syntax-alist) t]
3967 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3968 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3969 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3970 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3971 "--"
3972 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3973 ("Speedbar"
3974 ["Auto Open at Startup"
3975 (customize-set-variable 'vhdl-speedbar-auto-open
3976 (not vhdl-speedbar-auto-open))
3977 :style toggle :selected vhdl-speedbar-auto-open]
3978 ("Default Displaying Mode"
3979 ["Files"
3980 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3981 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3982 ["Directory Hierarchy"
3983 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3984 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3985 ["Project Hierarchy"
3986 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3987 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3988 ["Indentation Offset..."
3989 (customize-option 'speedbar-indentation-width) t]
3990 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3991 ["Jump to Unit when Opening"
3992 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3993 (not vhdl-speedbar-jump-to-unit))
3994 :style toggle :selected vhdl-speedbar-jump-to-unit]
3995 ["Update Hierarchy on File Saving"
3996 (customize-set-variable 'vhdl-speedbar-update-on-saving
3997 (not vhdl-speedbar-update-on-saving))
3998 :style toggle :selected vhdl-speedbar-update-on-saving]
3999 ("Save in Cache File"
4000 ["Hierarchy Information"
4001 (customize-set-variable 'vhdl-speedbar-save-cache
4002 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4003 (delq 'hierarchy vhdl-speedbar-save-cache)
4004 (cons 'hierarchy vhdl-speedbar-save-cache)))
4005 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4006 ["Displaying Status"
4007 (customize-set-variable 'vhdl-speedbar-save-cache
4008 (if (memq 'display vhdl-speedbar-save-cache)
4009 (delq 'display vhdl-speedbar-save-cache)
4010 (cons 'display vhdl-speedbar-save-cache)))
4011 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4012 ["Cache File Name..."
4013 (customize-option 'vhdl-speedbar-cache-file-name) t]
4014 "--"
4015 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4016 ("Menu"
4017 ["Add Index Menu when Loading File"
4018 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4019 (vhdl-index-menu-init))
4020 :style toggle :selected vhdl-index-menu]
4021 ["Add Source File Menu when Loading File"
4022 (progn (customize-set-variable 'vhdl-source-file-menu
4023 (not vhdl-source-file-menu))
4024 (vhdl-add-source-files-menu))
4025 :style toggle :selected vhdl-source-file-menu]
4026 ["Add Hideshow Menu at Startup"
4027 (progn (customize-set-variable 'vhdl-hideshow-menu
4028 (not vhdl-hideshow-menu))
4029 (vhdl-activate-customizations))
4030 :style toggle :selected vhdl-hideshow-menu]
4031 ["Hide Everything Initially"
4032 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4033 :style toggle :selected vhdl-hide-all-init]
4034 "--"
4035 ["Customize Group..." (customize-group 'vhdl-menu) t])
4036 ("Print"
4037 ["In Two Column Format"
4038 (progn (customize-set-variable 'vhdl-print-two-column
4039 (not vhdl-print-two-column))
4040 (message "Activate new setting by saving options and restarting Emacs"))
4041 :style toggle :selected vhdl-print-two-column]
4042 ["Use Customized Faces"
4043 (progn (customize-set-variable 'vhdl-print-customize-faces
4044 (not vhdl-print-customize-faces))
4045 (message "Activate new setting by saving options and restarting Emacs"))
4046 :style toggle :selected vhdl-print-customize-faces]
4047 "--"
4048 ["Customize Group..." (customize-group 'vhdl-print) t])
4049 ("Miscellaneous"
4050 ["Use Intelligent Tab"
4051 (progn (customize-set-variable 'vhdl-intelligent-tab
4052 (not vhdl-intelligent-tab))
4053 (vhdl-activate-customizations))
4054 :style toggle :selected vhdl-intelligent-tab]
4055 ["Indent Syntax-Based"
4056 (customize-set-variable 'vhdl-indent-syntax-based
4057 (not vhdl-indent-syntax-based))
4058 :style toggle :selected vhdl-indent-syntax-based]
4059 ["Indent Comments Like Next Code Line"
4060 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4061 (not vhdl-indent-comment-like-next-code-line))
4062 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4063 ["Word Completion is Case Sensitive"
4064 (customize-set-variable 'vhdl-word-completion-case-sensitive
4065 (not vhdl-word-completion-case-sensitive))
4066 :style toggle :selected vhdl-word-completion-case-sensitive]
4067 ["Word Completion in Minibuffer"
4068 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4069 (not vhdl-word-completion-in-minibuffer))
4070 (message "Activate new setting by saving options and restarting Emacs"))
4071 :style toggle :selected vhdl-word-completion-in-minibuffer]
4072 ["Underscore is Part of Word"
4073 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4074 (not vhdl-underscore-is-part-of-word))
4075 (vhdl-activate-customizations))
4076 :style toggle :selected vhdl-underscore-is-part-of-word]
4077 "--"
4078 ["Customize Group..." (customize-group 'vhdl-misc) t])
4079 ["Related..." (customize-browse 'vhdl-related) t]
4080 "--"
4081 ["Save Options" customize-save-customized t]
4082 ["Activate Options" vhdl-activate-customizations t]
4083 ["Browse Options..." vhdl-customize t])))
4085 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4086 "VHDL Mode menu.")
4088 (defun vhdl-update-mode-menu ()
4089 "Update VHDL Mode menu."
4090 (interactive)
4091 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4092 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4093 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4094 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4095 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4097 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4098 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4100 (defconst vhdl-imenu-generic-expression
4102 ("Subprogram"
4103 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4105 ("Instance"
4106 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4108 ("Component"
4109 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4111 ("Procedural"
4112 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4114 ("Process"
4115 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4117 ("Block"
4118 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4120 ("Package"
4121 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4123 ("Configuration"
4124 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4126 ("Architecture"
4127 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4129 ("Entity"
4130 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4133 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4135 (defun vhdl-index-menu-init ()
4136 "Initialize index menu."
4137 (set (make-local-variable 'imenu-case-fold-search) t)
4138 (set (make-local-variable 'imenu-generic-expression)
4139 vhdl-imenu-generic-expression)
4140 (when (and vhdl-index-menu (fboundp 'imenu))
4141 (imenu-add-to-menubar "Index")))
4143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4144 ;; Source file menu (using `easy-menu.el')
4146 (defvar vhdl-sources-menu nil)
4148 (defun vhdl-directory-files (directory &optional full match)
4149 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4150 message."
4151 (if (not (file-directory-p directory))
4152 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4153 (let ((dir (directory-files directory full match)))
4154 (setq dir (delete "." dir))
4155 (setq dir (delete ".." dir))
4156 dir)))
4158 (defun vhdl-get-source-files (&optional full directory)
4159 "Get list of VHDL source files in DIRECTORY or current directory."
4160 (let ((mode-alist auto-mode-alist)
4161 filename-regexp)
4162 ;; create regular expressions for matching file names
4163 (setq filename-regexp "\\`[^.].*\\(")
4164 (while mode-alist
4165 (when (eq (cdar mode-alist) 'vhdl-mode)
4166 (setq filename-regexp
4167 (concat filename-regexp (caar mode-alist) "\\|")))
4168 (setq mode-alist (cdr mode-alist)))
4169 (setq filename-regexp
4170 (concat (substring filename-regexp 0
4171 (string-match "\\\\|$" filename-regexp)) "\\)"))
4172 ;; find files
4173 (vhdl-directory-files
4174 (or directory default-directory) full filename-regexp)))
4176 (defun vhdl-add-source-files-menu ()
4177 "Scan directory for all VHDL source files and generate menu.
4178 The directory of the current source file is scanned."
4179 (interactive)
4180 (message "Scanning directory for source files ...")
4181 (let ((newmap (current-local-map))
4182 (file-list (vhdl-get-source-files))
4183 menu-list found)
4184 ;; Create list for menu
4185 (setq found nil)
4186 (while file-list
4187 (setq found t)
4188 (setq menu-list (cons (vector (car file-list)
4189 (list 'find-file (car file-list)) t)
4190 menu-list))
4191 (setq file-list (cdr file-list)))
4192 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4193 (when found (setq menu-list (cons "--" menu-list)))
4194 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4195 (setq menu-list (cons "Sources" menu-list))
4196 ;; Create menu
4197 (easy-menu-add menu-list)
4198 (easy-menu-define vhdl-sources-menu newmap
4199 "VHDL source files menu" menu-list))
4200 (message ""))
4203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4204 ;;; Mode definition
4205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4206 ;; performs all buffer local initializations
4208 ;;;###autoload
4209 (define-derived-mode vhdl-mode prog-mode
4210 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4211 (vhdl-electric-mode "e")
4212 (vhdl-stutter-mode "s"))
4213 "Major mode for editing VHDL code.
4215 Usage:
4216 ------
4218 TEMPLATE INSERTION (electrification):
4219 After typing a VHDL keyword and entering `SPC', you are prompted for
4220 arguments while a template is generated for that VHDL construct. Typing
4221 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4222 template generation. Optional arguments are indicated by square
4223 brackets and removed if the queried string is left empty. Prompts for
4224 mandatory arguments remain in the code if the queried string is left
4225 empty. They can be queried again by `C-c C-t C-q'. Enabled
4226 electrification is indicated by `/e' in the mode line.
4228 Typing `M-SPC' after a keyword inserts a space without calling the
4229 template generator. Automatic template generation (i.e.
4230 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4231 setting option `vhdl-electric-mode' (see OPTIONS).
4233 Template generators can be invoked from the VHDL menu, by key
4234 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4235 the keyword (i.e. first word of menu entry not in parenthesis) and
4236 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4237 conf, comp, cons, func, inst, pack, sig, var.
4239 Template styles can be customized in customization group
4240 `vhdl-template' \(see OPTIONS).
4243 HEADER INSERTION:
4244 A file header can be inserted by `C-c C-t C-h'. A file footer
4245 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4246 See customization group `vhdl-header'.
4249 STUTTERING:
4250 Double striking of some keys inserts cumbersome VHDL syntax elements.
4251 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4252 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4253 the mode line. The stuttering keys and their effects are:
4255 ;; --> \" : \" [ --> ( -- --> comment
4256 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4257 .. --> \" => \" ] --> ) --- --> horizontal line
4258 ,, --> \" <= \" ]] --> ] ---- --> display comment
4259 == --> \" == \" '' --> \\\"
4262 WORD COMPLETION:
4263 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4264 word in the buffer that starts alike, inserts it and adjusts case.
4265 Re-typing `TAB' toggles through alternative word completions. This also
4266 works in the minibuffer (i.e. in template generator prompts).
4268 Typing `TAB' after `(' looks for and inserts complete parenthesized
4269 expressions (e.g. for array index ranges). All keywords as well as
4270 standard types and subprograms of VHDL have predefined abbreviations
4271 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4272 beginning with \"std\").
4274 Typing `TAB' after a non-word character indents the line if at the
4275 beginning of a line (i.e. no preceding non-blank characters), and
4276 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4277 stop.
4280 COMMENTS:
4281 `--' puts a single comment.
4282 `---' draws a horizontal line for separating code segments.
4283 `----' inserts a display comment, i.e. two horizontal lines
4284 with a comment in between.
4285 `--CR' comments out code on that line. Re-hitting CR comments
4286 out following lines.
4287 `C-c C-c' comments out a region if not commented out,
4288 uncomments a region if already commented out. Option
4289 `comment-style' defines where the comment characters
4290 should be placed (beginning of line, indent, etc.).
4292 You are prompted for comments after object definitions (i.e. signals,
4293 variables, constants, ports) and after subprogram and process
4294 specifications if option `vhdl-prompt-for-comments' is non-nil.
4295 Comments are automatically inserted as additional labels (e.g. after
4296 begin statements) and as help comments if `vhdl-self-insert-comments' is
4297 non-nil.
4299 Inline comments (i.e. comments after a piece of code on the same line)
4300 are indented at least to `vhdl-inline-comment-column'. Comments go at
4301 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4302 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4303 in a comment automatically opens a new comment line. `M-q' re-fills
4304 multi-line comments.
4307 INDENTATION:
4308 `TAB' indents a line if at the beginning of the line. The amount of
4309 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4310 always indents the current line (is bound to `TAB' if option
4311 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4312 the entire region.
4314 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4315 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4316 indented normally (nil) or relative to the opening parenthesis (non-nil)
4317 according to option `vhdl-argument-list-indent'.
4319 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4320 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4321 and vice versa.
4323 Syntax-based indentation can be very slow in large files. Option
4324 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4326 Option `vhdl-indent-comment-like-next-code-line' controls whether
4327 comment lines are indented like the preceding or like the following code
4328 line.
4331 ALIGNMENT:
4332 The alignment functions align operators, keywords, and inline comments
4333 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4334 separated by blank lines, `C-c C-a C-i' a block of lines with same
4335 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4336 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4337 C-a C-d' all lines within the declarative part of a design unit. `C-c
4338 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4339 for a group of lines, and `C-c C-a M-c' for a region.
4341 If option `vhdl-align-groups' is non-nil, groups of code lines
4342 separated by special lines (see option `vhdl-align-group-separate') are
4343 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4344 blocks of lines with same indent are aligned separately. Some templates
4345 are automatically aligned after generation if option `vhdl-auto-align'
4346 is non-nil.
4348 Alignment tries to align inline comments at
4349 `vhdl-inline-comment-column' and tries inline comment not to exceed
4350 `vhdl-end-comment-column'.
4352 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4353 symbols are surrounded by one space, and multiple spaces are eliminated.
4356 CODE FILLING:
4357 Code filling allows to condense code (e.g. sensitivity lists or port
4358 maps) by removing comments and newlines and re-wrapping so that all
4359 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4360 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4361 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4362 `C-c C-f M-f' an entire region.
4365 CODE BEAUTIFICATION:
4366 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4367 buffer respectively. This includes indentation, alignment, and case
4368 fixing. Code beautification can also be run non-interactively using the
4369 command:
4371 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4374 PORT TRANSLATION:
4375 Generic and port clauses from entity or component declarations can be
4376 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4377 as component instantiations and corresponding internal constants and
4378 signals, as a generic map with constants as actual generics, and as
4379 internal signal initializations (menu).
4381 To include formals in component instantiations, see option
4382 `vhdl-association-list-with-formals'. To include comments in pasting,
4383 see options `vhdl-include-...-comments'.
4385 A clause with several generic/port names on the same line can be
4386 flattened (`C-c C-p C-f') so that only one name per line exists. The
4387 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4388 outputs and vice versa, which can be useful in testbenches. (This
4389 reversion is done on the internal data structure and is only reflected
4390 in subsequent paste operations.)
4392 Names for actual ports, instances, testbenches, and
4393 design-under-test instances can be derived from existing names according
4394 to options `vhdl-...-name'. See customization group `vhdl-port'.
4397 SUBPROGRAM TRANSLATION:
4398 Similar functionality exists for copying/pasting the interface of
4399 subprograms (function/procedure). A subprogram interface can be copied
4400 and then pasted as a subprogram declaration, body or call (uses
4401 association list with formals).
4404 TESTBENCH GENERATION:
4405 A copied port can also be pasted as a testbench. The generated
4406 testbench includes an entity, an architecture, and an optional
4407 configuration. The architecture contains the component declaration and
4408 instantiation of the DUT as well as internal constant and signal
4409 declarations. Additional user-defined templates can be inserted. The
4410 names used for entity/architecture/configuration/DUT as well as the file
4411 structure to be generated can be customized. See customization group
4412 `vhdl-testbench'.
4415 KEY BINDINGS:
4416 Key bindings (`C-c ...') exist for most commands (see in menu).
4419 VHDL MENU:
4420 All commands can be found in the VHDL menu including their key bindings.
4423 FILE BROWSER:
4424 The speedbar allows browsing of directories and file contents. It can
4425 be accessed from the VHDL menu and is automatically opened if option
4426 `vhdl-speedbar-auto-open' is non-nil.
4428 In speedbar, open files and directories with `mouse-2' on the name and
4429 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4432 DESIGN HIERARCHY BROWSER:
4433 The speedbar can also be used for browsing the hierarchy of design units
4434 contained in the source files of the current directory or the specified
4435 projects (see option `vhdl-project-alist').
4437 The speedbar can be switched between file, directory hierarchy and
4438 project hierarchy browsing mode in the speedbar menu or by typing `f',
4439 `h' or `H' in speedbar.
4441 In speedbar, open design units with `mouse-2' on the name and browse
4442 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4443 from entities and components (in packages). Individual design units and
4444 complete designs can directly be compiled (\"Make\" menu entry).
4446 The hierarchy is automatically updated upon saving a modified source
4447 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4448 hierarchy is only updated for projects that have been opened once in the
4449 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4450 options in group `vhdl-speedbar').
4452 Simple design consistency checks are done during scanning, such as
4453 multiple declarations of the same unit or missing primary units that are
4454 required by secondary units.
4457 STRUCTURAL COMPOSITION:
4458 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4459 for a new component. Subcomponents (i.e. component declaration and
4460 instantiation) can be automatically placed from a previously read port
4461 \(`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4462 all subcomponents can be automatically connected using internal signals
4463 and ports (`C-c C-m C-w') following these rules:
4464 - subcomponent actual ports with same name are considered to be
4465 connected by a signal (internal signal or port)
4466 - signals that are only inputs to subcomponents are considered as
4467 inputs to this component -> input port created
4468 - signals that are only outputs from subcomponents are considered as
4469 outputs from this component -> output port created
4470 - signals that are inputs to AND outputs from subcomponents are
4471 considered as internal connections -> internal signal created
4473 Purpose: With appropriate naming conventions it is possible to
4474 create higher design levels with only a few mouse clicks or key
4475 strokes. A new design level can be created by simply generating a new
4476 component, placing the required subcomponents from the hierarchy
4477 browser, and wiring everything automatically.
4479 Note: Automatic wiring only works reliably on templates of new
4480 components and component instantiations that were created by VHDL mode.
4482 Component declarations can be placed in a components package (option
4483 `vhdl-use-components-package') which can be automatically generated for
4484 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4485 component instantiation is also supported (option
4486 `vhdl-use-direct-instantiation').
4488 Configuration declarations can automatically be generated either from
4489 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4490 the speedbar menu (for the architecture under the cursor). The
4491 configurations can optionally be hierarchical (i.e. include all
4492 component levels of a hierarchical design, option
4493 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4494 (option `vhdl-compose-configuration-use-subconfiguration'). For
4495 subcomponents in hierarchical configurations, the most-recently-analyzed
4496 (mra) architecture is selected. If another architecture is desired, it
4497 can be marked as most-recently-analyzed (speedbar menu) before
4498 generating the configuration.
4500 Note: Configurations of subcomponents (i.e. hierarchical configuration
4501 declarations) are currently not considered when displaying
4502 configurations in speedbar.
4504 See the options group `vhdl-compose' for all relevant user options.
4507 SOURCE FILE COMPILATION:
4508 The syntax of the current buffer can be analyzed by calling a VHDL
4509 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4510 option `vhdl-compiler'. The available compilers are listed in option
4511 `vhdl-compiler-alist' including all required compilation command,
4512 command options, compilation directory, and error message syntax
4513 information. New compilers can be added.
4515 All the source files of an entire design can be compiled by the `make'
4516 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4519 MAKEFILE GENERATION:
4520 Makefiles can be generated automatically by an internal generation
4521 routine (`C-c M-k'). The library unit dependency information is
4522 obtained from the hierarchy browser. Makefile generation can be
4523 customized for each compiler in option `vhdl-compiler-alist'.
4525 Makefile generation can also be run non-interactively using the
4526 command:
4528 emacs -batch -l ~/.emacs -l vhdl-mode
4529 [-compiler compilername] [-project projectname]
4530 -f vhdl-generate-makefile
4532 The Makefile's default target \"all\" compiles the entire design, the
4533 target \"clean\" removes it and the target \"library\" creates the
4534 library directory if not existent. These target names can be customized
4535 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4536 target for each primary library unit which allows selective compilation
4537 of this unit, its secondary units and its subhierarchy (example:
4538 compilation of a design specified by a configuration). User specific
4539 parts can be inserted into a Makefile with option
4540 `vhdl-makefile-generation-hook'.
4542 Limitations:
4543 - Only library units and dependencies within the current library are
4544 considered. Makefiles for designs that span multiple libraries are
4545 not (yet) supported.
4546 - Only one-level configurations are supported (also hierarchical),
4547 but configurations that go down several levels are not.
4548 - The \"others\" keyword in configurations is not supported.
4551 PROJECTS:
4552 Projects can be defined in option `vhdl-project-alist' and a current
4553 project be selected using option `vhdl-project' (permanently) or from
4554 the menu or speedbar (temporarily). For each project, title and
4555 description strings (for the file headers), source files/directories
4556 (for the hierarchy browser and Makefile generation), library name, and
4557 compiler-dependent options, exceptions and compilation directory can be
4558 specified. Compilation settings overwrite the settings of option
4559 `vhdl-compiler-alist'.
4561 Project setups can be exported (i.e. written to a file) and imported.
4562 Imported setups are not automatically saved in `vhdl-project-alist' but
4563 can be saved afterwards in its customization buffer. When starting
4564 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4565 vhdl-mode\") in a directory with an existing project setup file, it is
4566 automatically loaded and its project activated if option
4567 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4568 files can be specified in option `vhdl-project-file-name'. Multiple
4569 project setups can be automatically loaded from global directories.
4570 This is an alternative to specifying project setups with option
4571 `vhdl-project-alist'.
4574 SPECIAL MENUES:
4575 As an alternative to the speedbar, an index menu can be added (set
4576 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4577 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4578 file) for browsing the file contents (is not populated if buffer is
4579 larger than `font-lock-maximum-size'). Also, a source file menu can be
4580 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4581 current directory for VHDL source files.
4584 VHDL STANDARDS:
4585 The VHDL standards to be used are specified in option `vhdl-standard'.
4586 Available standards are: VHDL'87/'93(02), VHDL-AMS, and Math Packages.
4589 KEYWORD CASE:
4590 Lower and upper case for keywords and standardized types, attributes,
4591 and enumeration values is supported. If the option
4592 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4593 lower case and are converted into upper case automatically (not for
4594 types, attributes, and enumeration values). The case of keywords,
4595 types, attributes,and enumeration values can be fixed for an entire
4596 region (menu) or buffer (`C-c C-x C-c') according to the options
4597 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4600 HIGHLIGHTING (fontification):
4601 Keywords and standardized types, attributes, enumeration values, and
4602 function names (controlled by option `vhdl-highlight-keywords'), as well
4603 as comments, strings, and template prompts are highlighted using
4604 different colors. Unit, subprogram, signal, variable, constant,
4605 parameter and generic/port names in declarations as well as labels are
4606 highlighted if option `vhdl-highlight-names' is non-nil.
4608 Additional reserved words or words with a forbidden syntax (e.g. words
4609 that should be avoided) can be specified in option
4610 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4611 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4612 keywords are highlighted as forbidden words if option
4613 `vhdl-highlight-verilog-keywords' is non-nil.
4615 Words with special syntax can be highlighted by specifying their
4616 syntax and color in option `vhdl-special-syntax-alist' and by setting
4617 option `vhdl-highlight-special-words' to non-nil. This allows to
4618 establish some naming conventions (e.g. to distinguish different kinds
4619 of signals or other objects by using name suffices) and to support them
4620 visually.
4622 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4623 to support case-sensitive highlighting. However, keywords are then only
4624 highlighted if written in lower case.
4626 Code between \"translate_off\" and \"translate_on\" pragmas is
4627 highlighted using a different background color if option
4628 `vhdl-highlight-translate-off' is non-nil.
4630 For documentation and customization of the used colors see
4631 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4632 highlighting of matching parenthesis, see customization group
4633 `paren-showing'. Automatic buffer highlighting is turned on/off by
4634 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4637 USER MODELS:
4638 VHDL models (templates) can be specified by the user and made accessible
4639 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4640 electrification. See option `vhdl-model-alist'.
4643 HIDE/SHOW:
4644 The code of blocks, processes, subprograms, component declarations and
4645 instantiations, generic/port clauses, and configuration declarations can
4646 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4647 the code (see customization group `vhdl-menu'). XEmacs: limited
4648 functionality due to old `hideshow.el' package.
4651 CODE UPDATING:
4652 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4653 current process, `C-c C-u M-s' of all processes in the current buffer.
4654 Limitations:
4655 - Only declared local signals (ports, signals declared in
4656 architecture and blocks) are automatically inserted.
4657 - Global signals declared in packages are not automatically inserted.
4658 Insert them once manually (will be kept afterwards).
4659 - Out parameters of procedures are considered to be read.
4660 Use option `vhdl-entity-file-name' to specify the entity file name
4661 \(used to obtain the port names).
4662 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4663 specify whether to include array indices and record fields in
4664 sensitivity lists.
4667 CODE FIXING:
4668 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4669 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4672 PRINTING:
4673 PostScript printing with different faces (an optimized set of faces is
4674 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4675 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4676 PostScript printing commands. Option `vhdl-print-two-column' defines
4677 appropriate default settings for nice landscape two-column printing.
4678 The paper format can be set by option `ps-paper-type'. Do not forget to
4679 switch `ps-print-color-p' to nil for printing on black-and-white
4680 printers.
4683 OPTIONS:
4684 User options allow customization of VHDL Mode. All options are
4685 accessible from the \"Options\" menu entry. Simple options (switches
4686 and choices) can directly be changed, while for complex options a
4687 customization buffer is opened. Changed options can be saved for future
4688 sessions using the \"Save Options\" menu entry.
4690 Options and their detailed descriptions can also be accessed by using
4691 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4692 customize-group' for groups). Some customizations only take effect
4693 after some action (read the NOTE in the option documentation).
4694 Customization can also be done globally (i.e. site-wide, read the
4695 INSTALL file).
4697 Not all options are described in this documentation, so go and see
4698 what other useful user options there are (`M-x vhdl-customize' or menu)!
4701 FILE EXTENSIONS:
4702 As default, files with extensions \".vhd\" and \".vhdl\" are
4703 automatically recognized as VHDL source files. To add an extension
4704 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4706 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4709 HINTS:
4710 - To start Emacs with open VHDL hierarchy browser without having to load
4711 a VHDL file first, use the command:
4713 emacs -l vhdl-mode -f speedbar-frame-mode
4715 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4717 - Some features only work on properly indented code.
4720 RELEASE NOTES:
4721 See also the release notes (menu) for added features in new releases.
4724 Maintenance:
4725 ------------
4727 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4728 Add a description of the problem and include a reproducible test case.
4730 Questions and enhancement requests can be sent to <reto@gnu.org>.
4732 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4733 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4734 releases. You are kindly invited to participate in beta testing. Subscribe
4735 to above mailing lists by sending an email to <reto@gnu.org>.
4737 VHDL Mode is officially distributed at
4738 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4739 where the latest version can be found.
4742 Known problems:
4743 ---------------
4745 - XEmacs: Incorrect start-up when automatically opening speedbar.
4746 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4747 - Indentation incorrect for new 'postponed' VHDL keyword.
4748 - Indentation incorrect for 'protected body' construct.
4751 The VHDL Mode Authors
4752 Reto Zimmermann and Rod Whitby
4754 Key bindings:
4755 -------------
4757 \\{vhdl-mode-map}"
4758 :abbrev-table vhdl-mode-abbrev-table
4760 ;; set local variables
4761 (set (make-local-variable 'paragraph-start)
4762 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4763 (set (make-local-variable 'paragraph-separate) paragraph-start)
4764 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4765 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4766 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4767 (set (make-local-variable 'comment-start) "--")
4768 (set (make-local-variable 'comment-end) "")
4769 (when vhdl-emacs-21
4770 (set (make-local-variable 'comment-padding) ""))
4771 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4772 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4773 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4774 (set (make-local-variable 'comment-multi-line) nil)
4775 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4776 (set (make-local-variable 'hippie-expand-verbose) nil)
4778 ;; setup the comment indent variable in a Emacs version portable way
4779 ;; ignore any byte compiler warnings you might get here
4780 (when (boundp 'comment-indent-function)
4781 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4783 ;; initialize font locking
4784 (set (make-local-variable 'font-lock-defaults)
4785 (list
4786 '(nil vhdl-font-lock-keywords) nil
4787 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4788 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4789 (set (make-local-variable 'syntax-propertize-function)
4790 (syntax-propertize-rules
4791 ;; Mark single quotes as having string quote syntax in
4792 ;; 'c' instances.
4793 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4794 (set (make-local-variable 'font-lock-syntactic-keywords)
4795 vhdl-font-lock-syntactic-keywords))
4796 (unless vhdl-emacs-21
4797 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4798 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4799 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4800 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4801 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4802 ; (turn-on-font-lock)
4804 ;; variables for source file compilation
4805 (when vhdl-compile-use-local-error-regexp
4806 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4807 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4809 ;; add index menu
4810 (vhdl-index-menu-init)
4811 ;; add source file menu
4812 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4813 ;; add VHDL menu
4814 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4815 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4816 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4817 ;; initialize hideshow and add menu
4818 (vhdl-hideshow-init)
4819 (run-hooks 'menu-bar-update-hook)
4821 ;; miscellaneous
4822 (vhdl-ps-print-init)
4823 (vhdl-write-file-hooks-init)
4824 (message "VHDL Mode %s.%s" vhdl-version
4825 (if noninteractive "" " See menu for documentation and release notes.")))
4827 (defun vhdl-activate-customizations ()
4828 "Activate all customizations on local variables."
4829 (interactive)
4830 (vhdl-mode-map-init)
4831 (use-local-map vhdl-mode-map)
4832 (set-syntax-table vhdl-mode-syntax-table)
4833 (setq comment-column vhdl-inline-comment-column)
4834 (setq end-comment-column vhdl-end-comment-column)
4835 (vhdl-write-file-hooks-init)
4836 (vhdl-update-mode-menu)
4837 (vhdl-hideshow-init)
4838 (run-hooks 'menu-bar-update-hook))
4840 (defun vhdl-write-file-hooks-init ()
4841 "Add/remove hooks when buffer is saved."
4842 (if vhdl-modify-date-on-saving
4843 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4844 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4845 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4846 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4848 (defun vhdl-process-command-line-option (option)
4849 "Process command line options for VHDL Mode."
4850 (cond
4851 ;; set compiler
4852 ((equal option "-compiler")
4853 (vhdl-set-compiler (car command-line-args-left))
4854 (setq command-line-args-left (cdr command-line-args-left)))
4855 ;; set project
4856 ((equal option "-project")
4857 (vhdl-set-project (car command-line-args-left))
4858 (setq command-line-args-left (cdr command-line-args-left)))))
4860 ;; make Emacs process VHDL Mode options
4861 (setq command-switch-alist
4862 (append command-switch-alist
4863 '(("-compiler" . vhdl-process-command-line-option)
4864 ("-project" . vhdl-process-command-line-option))))
4867 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4868 ;;; Keywords and standardized words
4869 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4871 (defconst vhdl-02-keywords
4873 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4874 "assert" "attribute"
4875 "begin" "block" "body" "buffer" "bus"
4876 "case" "component" "configuration" "constant"
4877 "disconnect" "downto"
4878 "else" "elsif" "end" "entity" "exit"
4879 "file" "for" "function"
4880 "generate" "generic" "group" "guarded"
4881 "if" "impure" "in" "inertial" "inout" "is"
4882 "label" "library" "linkage" "literal" "loop"
4883 "map" "mod"
4884 "nand" "new" "next" "nor" "not" "null"
4885 "of" "on" "open" "or" "others" "out"
4886 "package" "port" "postponed" "procedure" "process" "protected" "pure"
4887 "range" "record" "register" "reject" "rem" "report" "return"
4888 "rol" "ror"
4889 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4890 "then" "to" "transport" "type"
4891 "unaffected" "units" "until" "use"
4892 "variable"
4893 "wait" "when" "while" "with"
4894 "xnor" "xor"
4896 "List of VHDL'02 keywords.")
4898 (defconst vhdl-ams-keywords
4900 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4901 "reference" "spectrum" "subnature" "terminal" "through"
4902 "tolerance"
4904 "List of VHDL-AMS keywords.")
4906 (defconst vhdl-verilog-keywords
4908 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4909 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4910 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4911 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4912 "endprimitive" "endspecify" "endtable" "endtask" "event"
4913 "for" "force" "forever" "fork" "function"
4914 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4915 "macromodule" "makefile" "medium" "module"
4916 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4917 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4918 "pullup"
4919 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4920 "rtranif0" "rtranif1"
4921 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4922 "strong1" "supply" "supply0" "supply1"
4923 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4924 "triand" "trior" "trireg"
4925 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4927 "List of Verilog keywords as candidate for additional reserved words.")
4929 (defconst vhdl-02-types
4931 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4932 "real" "time" "natural" "positive" "string" "line" "text" "side"
4933 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4934 "std_logic" "std_logic_vector"
4935 "std_ulogic" "std_ulogic_vector"
4937 "List of VHDL'02 standardized types.")
4939 (defconst vhdl-ams-types
4940 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
4942 ;; package `standard'
4943 "domain_type" "real_vector"
4944 ;; package `energy_systems'
4945 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
4946 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
4947 "real_across_vector" "real_through_vector"
4948 ;; package `electrical_systems'
4949 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
4950 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
4951 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
4952 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
4953 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
4954 "magnetic_flux_vector" "charge_vector" "resistance_vector"
4955 "conductance_vector" "capacitance_vector" "electric_flux_vector"
4956 "electric_flux_density_vector" "electric_field_strength_vector"
4957 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
4958 "inductance_vector" "reluctance_vector" "ground"
4959 ;; package `mechanical_systems'
4960 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
4961 "damping" "momentum" "angle" "torque" "angular_velocity"
4962 "angular_acceleration" "moment_inertia" "angular_momentum"
4963 "angular_stiffness" "angular_damping" "translational"
4964 "translational_vector" "translational_velocity"
4965 "translational_velocity_vector" "rotational" "rotational_vector"
4966 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
4967 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
4968 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
4969 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
4970 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
4971 "angular_momentum_vector" "angular_stiffness_vector"
4972 "angular_damping_vector" "anchor" "translational_v_ref"
4973 "rotational_v_ref" "translational_v" "rotational_v"
4974 ;; package `radiant_systems'
4975 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
4976 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
4977 "illuminance_vector" "irradiance_vector"
4978 ;; package `thermal_systems'
4979 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
4980 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
4981 "heat_flow_vector" "thermal_capacitance_vector"
4982 "thermal_resistance_vector" "thermal_conductance_vector"
4983 ;; package `fluidic_systems'
4984 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
4985 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
4986 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
4987 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
4988 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
4989 "density_vector" "viscosity_vector" "fresistance_vector"
4990 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
4991 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
4992 "cfinertance_vector"
4994 "List of VHDL-AMS standardized types.")
4996 (defconst vhdl-math-types
4998 "complex" "complex_polar" "positive_real" "principal_value"
5000 "List of Math Packages standardized types.")
5002 (defconst vhdl-02-attributes
5004 "base" "left" "right" "high" "low" "pos" "val" "succ"
5005 "pred" "leftof" "rightof" "range" "reverse_range"
5006 "length" "delayed" "stable" "quiet" "transaction"
5007 "event" "active" "last_event" "last_active" "last_value"
5008 "driving" "driving_value" "ascending" "value" "image"
5009 "simple_name" "instance_name" "path_name"
5010 "foreign"
5012 "List of VHDL'02 standardized attributes.")
5014 (defconst vhdl-ams-attributes
5016 "across" "through"
5017 "reference" "contribution" "tolerance"
5018 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5019 "ramp" "slew"
5021 "List of VHDL-AMS standardized attributes.")
5023 (defconst vhdl-02-enum-values
5025 "true" "false"
5026 "note" "warning" "error" "failure"
5027 "read_mode" "write_mode" "append_mode"
5028 "open_ok" "status_error" "name_error" "mode_error"
5029 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5030 "right" "left"
5032 "List of VHDL'02 standardized enumeration values.")
5034 (defconst vhdl-ams-enum-values
5036 "quiescent_domain" "time_domain" "frequency_domain"
5037 ;; from `nature_pkg' package
5038 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5040 "List of VHDL-AMS standardized enumeration values.")
5042 (defconst vhdl-ams-constants
5043 ;; standard: IEEE Std 1076.1.1-2004
5045 ;; package `fundamental_constants'
5046 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5047 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5048 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5049 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5050 ;; package `material_constants'
5051 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5052 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5053 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5055 "List of VHDL-AMS standardized constants.")
5057 (defconst vhdl-math-constants
5058 ;; standard: IEEE Std 1076.2-1996
5060 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5061 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5062 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5063 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5064 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5065 "math_sqrt_pi"
5067 "List of Math Packages standardized constants.")
5069 (defconst vhdl-02-functions
5071 "now" "resolved" "rising_edge" "falling_edge"
5072 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5073 "endfile"
5074 "resize" "is_X" "std_match"
5075 "shift_left" "shift_right" "rotate_left" "rotate_right"
5076 "to_unsigned" "to_signed" "to_integer"
5077 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5078 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5079 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5080 "shl" "shr" "ext" "sxt"
5081 "deallocate"
5083 "List of VHDL'02 standardized functions.")
5085 (defconst vhdl-ams-functions
5087 ;; package `standard'
5088 "frequency"
5090 "List of VHDL-AMS standardized functions.")
5092 (defconst vhdl-math-functions
5093 ;; standard: IEEE Std 1076.2-1996
5095 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5096 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5097 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5098 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5099 "tan" "tanh" "trunc" "uniform"
5101 "List of Math Packages standardized functions.")
5103 (defconst vhdl-02-packages
5105 "std_logic_1164" "numeric_std" "numeric_bit"
5106 "standard" "textio"
5107 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5108 "std_logic_misc" "std_logic_textio"
5109 "ieee" "std" "work"
5111 "List of VHDL'02 standardized packages and libraries.")
5113 (defconst vhdl-ams-packages
5115 "fundamental_constants" "material_constants" "energy_systems"
5116 "electrical_systems" "mechanical_systems" "radiant_systems"
5117 "thermal_systems" "fluidic_systems"
5119 "List of VHDL-AMS standardized packages and libraries.")
5121 (defconst vhdl-math-packages
5123 "math_real" "math_complex"
5125 "List of Math Packages standardized packages and libraries.")
5127 (defvar vhdl-keywords nil
5128 "List of VHDL keywords.")
5130 (defvar vhdl-types nil
5131 "List of VHDL standardized types.")
5133 (defvar vhdl-attributes nil
5134 "List of VHDL standardized attributes.")
5136 (defvar vhdl-enum-values nil
5137 "List of VHDL standardized enumeration values.")
5139 (defvar vhdl-constants nil
5140 "List of VHDL standardized constants.")
5142 (defvar vhdl-functions nil
5143 "List of VHDL standardized functions.")
5145 (defvar vhdl-packages nil
5146 "List of VHDL standardized packages and libraries.")
5148 (defvar vhdl-reserved-words nil
5149 "List of additional reserved words.")
5151 (defvar vhdl-keywords-regexp nil
5152 "Regexp for VHDL keywords.")
5154 (defvar vhdl-types-regexp nil
5155 "Regexp for VHDL standardized types.")
5157 (defvar vhdl-attributes-regexp nil
5158 "Regexp for VHDL standardized attributes.")
5160 (defvar vhdl-enum-values-regexp nil
5161 "Regexp for VHDL standardized enumeration values.")
5163 (defvar vhdl-constants-regexp nil
5164 "Regexp for VHDL standardized constants.")
5166 (defvar vhdl-functions-regexp nil
5167 "Regexp for VHDL standardized functions.")
5169 (defvar vhdl-packages-regexp nil
5170 "Regexp for VHDL standardized packages and libraries.")
5172 (defvar vhdl-reserved-words-regexp nil
5173 "Regexp for additional reserved words.")
5175 (defvar vhdl-directive-keywords-regexp nil
5176 "Regexp for compiler directive keywords.")
5178 (defun vhdl-upcase-list (condition list)
5179 "Upcase all elements in LIST based on CONDITION."
5180 (when condition
5181 (let ((tmp-list list))
5182 (while tmp-list
5183 (setcar tmp-list (upcase (car tmp-list)))
5184 (setq tmp-list (cdr tmp-list)))))
5185 list)
5187 (defun vhdl-words-init ()
5188 "Initialize reserved words."
5189 (setq vhdl-keywords
5190 (vhdl-upcase-list
5191 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5192 (append vhdl-02-keywords
5193 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5194 (setq vhdl-types
5195 (vhdl-upcase-list
5196 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5197 (append vhdl-02-types
5198 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5199 (when (vhdl-standard-p 'math) vhdl-math-types))))
5200 (setq vhdl-attributes
5201 (vhdl-upcase-list
5202 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5203 (append vhdl-02-attributes
5204 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5205 (setq vhdl-enum-values
5206 (vhdl-upcase-list
5207 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5208 (append vhdl-02-enum-values
5209 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5210 (setq vhdl-constants
5211 (vhdl-upcase-list
5212 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5213 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5214 (when (vhdl-standard-p 'math) vhdl-math-constants)
5215 '(""))))
5216 (setq vhdl-functions
5217 (append vhdl-02-functions
5218 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5219 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5220 (setq vhdl-packages
5221 (append vhdl-02-packages
5222 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5223 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5224 (setq vhdl-reserved-words
5225 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5226 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5227 '("")))
5228 (setq vhdl-keywords-regexp
5229 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5230 (setq vhdl-types-regexp
5231 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5232 (setq vhdl-attributes-regexp
5233 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5234 (setq vhdl-enum-values-regexp
5235 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5236 (setq vhdl-constants-regexp
5237 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5238 (setq vhdl-functions-regexp
5239 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5240 (setq vhdl-packages-regexp
5241 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5242 (setq vhdl-reserved-words-regexp
5243 (concat "\\<\\("
5244 (unless (equal vhdl-forbidden-syntax "")
5245 (concat vhdl-forbidden-syntax "\\|"))
5246 (regexp-opt vhdl-reserved-words)
5247 "\\)\\>"))
5248 (setq vhdl-directive-keywords-regexp
5249 (concat "\\<\\(" (mapconcat 'regexp-quote
5250 vhdl-directive-keywords "\\|") "\\)\\>"))
5251 (vhdl-abbrev-list-init))
5253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5254 ;; Words to expand
5256 (defvar vhdl-abbrev-list nil
5257 "Predefined abbreviations for VHDL.")
5259 (defun vhdl-abbrev-list-init ()
5260 (setq vhdl-abbrev-list
5261 (append
5262 (list vhdl-upper-case-keywords) vhdl-keywords
5263 (list vhdl-upper-case-types) vhdl-types
5264 (list vhdl-upper-case-attributes) vhdl-attributes
5265 (list vhdl-upper-case-enum-values) vhdl-enum-values
5266 (list vhdl-upper-case-constants) vhdl-constants
5267 (list nil) vhdl-functions
5268 (list nil) vhdl-packages)))
5270 ;; initialize reserved words for VHDL Mode
5271 (vhdl-words-init)
5274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5275 ;;; Indentation
5276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5279 ;; Syntax analysis
5281 ;; constant regular expressions for looking at various constructs
5283 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5284 "Regexp describing a VHDL symbol.
5285 We cannot use just `word' syntax class since `_' cannot be in word
5286 class. Putting underscore in word class breaks forward word movement
5287 behavior that users are familiar with.")
5289 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5290 "Regexp describing a case statement header key.")
5292 (defconst vhdl-label-key
5293 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5294 "Regexp describing a VHDL label.")
5296 ;; Macro definitions:
5298 (defmacro vhdl-point (position)
5299 "Return the value of point at certain commonly referenced POSITIONs.
5300 POSITION can be one of the following symbols:
5302 bol -- beginning of line
5303 eol -- end of line
5304 bod -- beginning of defun
5305 boi -- back to indentation
5306 eoi -- last whitespace on line
5307 ionl -- indentation of next line
5308 iopl -- indentation of previous line
5309 bonl -- beginning of next line
5310 bopl -- beginning of previous line
5312 This function does not modify point or mark."
5313 (or (and (eq 'quote (car-safe position))
5314 (null (cddr position)))
5315 (error "ERROR: Bad buffer position requested: %s" position))
5316 (setq position (nth 1 position))
5317 `(let ((here (point)))
5318 ,@(cond
5319 ((eq position 'bol) '((beginning-of-line)))
5320 ((eq position 'eol) '((end-of-line)))
5321 ((eq position 'bod) '((save-match-data
5322 (vhdl-beginning-of-defun))))
5323 ((eq position 'boi) '((back-to-indentation)))
5324 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5325 ((eq position 'bonl) '((forward-line 1)))
5326 ((eq position 'bopl) '((forward-line -1)))
5327 ((eq position 'iopl)
5328 '((forward-line -1)
5329 (back-to-indentation)))
5330 ((eq position 'ionl)
5331 '((forward-line 1)
5332 (back-to-indentation)))
5333 (t (error "ERROR: Unknown buffer position requested: %s" position))
5335 (prog1
5336 (point)
5337 (goto-char here))
5338 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5339 ;; doesn't hurt for v19
5340 ,@nil
5343 (defmacro vhdl-safe (&rest body)
5344 "Safely execute BODY, return nil if an error occurred."
5345 `(condition-case nil
5346 (progn ,@body)
5347 (error nil)))
5349 (defmacro vhdl-add-syntax (symbol &optional relpos)
5350 "A simple macro to append the syntax in SYMBOL to the syntax list.
5351 Try to increase performance by using this macro."
5352 `(setq vhdl-syntactic-context
5353 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5355 (defmacro vhdl-has-syntax (symbol)
5356 "A simple macro to return check the syntax list.
5357 Try to increase performance by using this macro."
5358 `(assoc ,symbol vhdl-syntactic-context))
5360 ;; Syntactic element offset manipulation:
5362 (defun vhdl-read-offset (langelem)
5363 "Read new offset value for LANGELEM from minibuffer.
5364 Return a valid value only."
5365 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5366 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5367 (prompt "Offset: ")
5368 offset input interned)
5369 (while (not offset)
5370 (setq input (read-string prompt oldoff)
5371 offset (cond ((string-equal "+" input) '+)
5372 ((string-equal "-" input) '-)
5373 ((string-equal "++" input) '++)
5374 ((string-equal "--" input) '--)
5375 ((string-match "^-?[0-9]+$" input)
5376 (string-to-number input))
5377 ((fboundp (setq interned (intern input)))
5378 interned)
5379 ((boundp interned) interned)
5380 ;; error, but don't signal one, keep trying
5381 ;; to read an input value
5382 (t (ding)
5383 (setq prompt errmsg)
5384 nil))))
5385 offset))
5387 (defun vhdl-set-offset (symbol offset &optional add-p)
5388 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5389 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5390 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5391 `vhdl-offsets-alist' if it doesn't already appear there."
5392 (interactive
5393 (let* ((langelem
5394 (intern (completing-read
5395 (concat "Syntactic symbol to change"
5396 (if current-prefix-arg " or add" "")
5397 ": ")
5398 (mapcar
5399 (function
5400 (lambda (langelem)
5401 (cons (format "%s" (car langelem)) nil)))
5402 vhdl-offsets-alist)
5403 nil (not current-prefix-arg)
5404 ;; initial contents tries to be the last element
5405 ;; on the syntactic analysis list for the current
5406 ;; line
5407 (let* ((syntax (vhdl-get-syntactic-context))
5408 (len (length syntax))
5409 (ic (format "%s" (car (nth (1- len) syntax)))))
5412 (offset (vhdl-read-offset langelem)))
5413 (list langelem offset current-prefix-arg)))
5414 ;; sanity check offset
5415 (or (eq offset '+)
5416 (eq offset '-)
5417 (eq offset '++)
5418 (eq offset '--)
5419 (integerp offset)
5420 (fboundp offset)
5421 (boundp offset)
5422 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5423 offset))
5424 (let ((entry (assq symbol vhdl-offsets-alist)))
5425 (if entry
5426 (setcdr entry offset)
5427 (if add-p
5428 (setq vhdl-offsets-alist
5429 (cons (cons symbol offset) vhdl-offsets-alist))
5430 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5431 (vhdl-keep-region-active))
5433 (defun vhdl-set-style (style &optional local)
5434 "Set `vhdl-mode' variables to use one of several different indentation styles.
5435 STYLE is a string representing the desired style and optional LOCAL is
5436 a flag which, if non-nil, means to make the style variables being
5437 changed buffer local, instead of the default, which is to set the
5438 global variables. Interactively, the flag comes from the prefix
5439 argument. The styles are chosen from the `vhdl-style-alist' variable."
5440 (interactive (list (completing-read "Use which VHDL indentation style? "
5441 vhdl-style-alist nil t)
5442 current-prefix-arg))
5443 (let ((vars (cdr (assoc style vhdl-style-alist))))
5444 (or vars
5445 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5446 ;; set all the variables
5447 (mapc
5448 (function
5449 (lambda (varentry)
5450 (let ((var (car varentry))
5451 (val (cdr varentry)))
5452 ;; special case for vhdl-offsets-alist
5453 (if (not (eq var 'vhdl-offsets-alist))
5454 (set (if local (make-local-variable var) var) val)
5455 ;; reset vhdl-offsets-alist to the default value first
5456 (set (if local (make-local-variable var) var)
5457 (copy-alist vhdl-offsets-alist-default))
5458 ;; now set the langelems that are different
5459 (mapcar
5460 (function
5461 (lambda (langentry)
5462 (let ((langelem (car langentry))
5463 (offset (cdr langentry)))
5464 (vhdl-set-offset langelem offset)
5466 val))
5468 vars))
5469 (vhdl-keep-region-active))
5471 (defun vhdl-get-offset (langelem)
5472 "Get offset from LANGELEM which is a cons cell of the form:
5473 \(SYMBOL . RELPOS). The symbol is matched against
5474 vhdl-offsets-alist and the offset found there is either returned,
5475 or added to the indentation at RELPOS. If RELPOS is nil, then
5476 the offset is simply returned."
5477 (let* ((symbol (car langelem))
5478 (relpos (cdr langelem))
5479 (match (assq symbol vhdl-offsets-alist))
5480 (offset (cdr-safe match)))
5481 ;; offset can be a number, a function, a variable, or one of the
5482 ;; symbols + or -
5483 (cond
5484 ((not match)
5485 (if vhdl-strict-syntax-p
5486 (error "ERROR: Don't know how to indent a %s" symbol)
5487 (setq offset 0
5488 relpos 0)))
5489 ((eq offset '+) (setq offset vhdl-basic-offset))
5490 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5491 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5492 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5493 ((and (not (numberp offset))
5494 (fboundp offset))
5495 (setq offset (funcall offset langelem)))
5496 ((not (numberp offset))
5497 (setq offset (eval offset)))
5499 (+ (if (and relpos
5500 (< relpos (vhdl-point 'bol)))
5501 (save-excursion
5502 (goto-char relpos)
5503 (current-column))
5505 offset)))
5507 ;; Syntactic support functions:
5509 (defun vhdl-in-comment-p ()
5510 "Check if point is in a comment."
5511 (eq (vhdl-in-literal) 'comment))
5513 (defun vhdl-in-string-p ()
5514 "Check if point is in a string."
5515 (eq (vhdl-in-literal) 'string))
5517 (defun vhdl-in-quote-p ()
5518 "Check if point is in a quote ('x')."
5519 (or (and (> (point) (point-min))
5520 (< (1+ (point)) (point-max))
5521 (= (char-before (point)) ?\')
5522 (= (char-after (1+ (point))) ?\'))
5523 (and (> (1- (point)) (point-min))
5524 (< (point) (point-max))
5525 (= (char-before (1- (point))) ?\')
5526 (= (char-after (point)) ?\'))))
5528 (defun vhdl-in-literal ()
5529 "Determine if point is in a VHDL literal."
5530 (save-excursion
5531 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5532 (cond
5533 ((nth 3 state) 'string)
5534 ((nth 4 state) 'comment)
5535 ((vhdl-beginning-of-macro) 'pound)
5536 (t nil)))))
5538 (defun vhdl-in-extended-identifier-p ()
5539 "Determine if point is inside extended identifier (delimited by '\')."
5540 (save-match-data
5541 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5542 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5544 (defun vhdl-forward-comment (&optional direction)
5545 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5546 negative, skip forward otherwise."
5547 (interactive "p")
5548 (if (and direction (< direction 0))
5549 ;; skip backwards
5550 (progn
5551 (skip-chars-backward " \t\n\r\f")
5552 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5553 (goto-char (match-beginning 3))
5554 (skip-chars-backward " \t\n\r\f")))
5555 ;; skip forwards
5556 (skip-chars-forward " \t\n\r\f")
5557 (while (looking-at "--.*")
5558 (goto-char (match-end 0))
5559 (skip-chars-forward " \t\n\r\f"))))
5561 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5562 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5563 (defalias 'vhdl-forward-comment 'forward-comment))
5565 (defun vhdl-back-to-indentation ()
5566 "Move point to the first non-whitespace character on this line."
5567 (interactive)
5568 (beginning-of-line 1)
5569 (skip-syntax-forward " " (vhdl-point 'eol)))
5571 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5572 (when (featurep 'xemacs)
5573 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5575 ;; This is the best we can do in Win-Emacs.
5576 (defun vhdl-win-il (&optional lim)
5577 "Determine if point is in a VHDL literal."
5578 (save-excursion
5579 (let* ((here (point))
5580 (state nil)
5581 (match nil)
5582 (lim (or lim (vhdl-point 'bod))))
5583 (goto-char lim )
5584 (while (< (point) here)
5585 (setq match
5586 (and (re-search-forward "--\\|[\"']"
5587 here 'move)
5588 (buffer-substring (match-beginning 0) (match-end 0))))
5589 (setq state
5590 (cond
5591 ;; no match
5592 ((null match) nil)
5593 ;; looking at the opening of a VHDL style comment
5594 ((string= "--" match)
5595 (if (<= here (progn (end-of-line) (point))) 'comment))
5596 ;; looking at the opening of a double quote string
5597 ((string= "\"" match)
5598 (if (not (save-restriction
5599 ;; this seems to be necessary since the
5600 ;; re-search-forward will not work without it
5601 (narrow-to-region (point) here)
5602 (re-search-forward
5603 ;; this regexp matches a double quote
5604 ;; which is preceded by an even number
5605 ;; of backslashes, including zero
5606 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5607 'string))
5608 ;; looking at the opening of a single quote string
5609 ((string= "'" match)
5610 (if (not (save-restriction
5611 ;; see comments from above
5612 (narrow-to-region (point) here)
5613 (re-search-forward
5614 ;; this matches a single quote which is
5615 ;; preceded by zero or two backslashes.
5616 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5617 here 'move)))
5618 'string))
5619 (t nil)))
5620 ) ; end-while
5621 state)))
5623 (and (string-match "Win-Emacs" emacs-version)
5624 (fset 'vhdl-in-literal 'vhdl-win-il))
5626 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5627 ;; defined as lexical whitespace or comments. Search no farther back
5628 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5629 ;; used for backward skipping, (point-max) is used for forward
5630 ;; skipping.
5632 (defun vhdl-forward-syntactic-ws (&optional lim)
5633 "Forward skip of syntactic whitespace."
5634 (let* ((here (point-max))
5635 (hugenum (point-max)))
5636 (while (/= here (point))
5637 (setq here (point))
5638 (vhdl-forward-comment hugenum)
5639 ;; skip preprocessor directives
5640 (when (and (eq (char-after) ?#)
5641 (= (vhdl-point 'boi) (point)))
5642 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5643 (= (forward-line 1) 0)))
5644 (end-of-line)))
5645 (if lim (goto-char (min (point) lim)))))
5648 ;; This is the best we can do in Win-Emacs.
5649 (defun vhdl-win-fsws (&optional lim)
5650 "Forward skip syntactic whitespace for Win-Emacs."
5651 (let ((lim (or lim (point-max)))
5652 stop)
5653 (while (not stop)
5654 (skip-chars-forward " \t\n\r\f" lim)
5655 (cond
5656 ;; vhdl comment
5657 ((looking-at "--") (end-of-line))
5658 ;; none of the above
5659 (t (setq stop t))))))
5661 (and (string-match "Win-Emacs" emacs-version)
5662 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5664 (defun vhdl-beginning-of-macro (&optional lim)
5665 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5666 (let ((here (point)))
5667 (beginning-of-line)
5668 (while (eq (char-before (1- (point))) ?\\)
5669 (forward-line -1))
5670 (back-to-indentation)
5671 (if (and (<= (point) here)
5672 (eq (char-after) ?#))
5674 (goto-char here)
5675 nil)))
5677 (defun vhdl-backward-syntactic-ws (&optional lim)
5678 "Backward skip over syntactic whitespace."
5679 (let* ((here (point-min))
5680 (hugenum (- (point-max))))
5681 (while (/= here (point))
5682 (setq here (point))
5683 (vhdl-forward-comment hugenum)
5684 (vhdl-beginning-of-macro))
5685 (if lim (goto-char (max (point) lim)))))
5687 ;; This is the best we can do in Win-Emacs.
5688 (defun vhdl-win-bsws (&optional lim)
5689 "Backward skip syntactic whitespace for Win-Emacs."
5690 (let ((lim (or lim (vhdl-point 'bod)))
5691 stop)
5692 (while (not stop)
5693 (skip-chars-backward " \t\n\r\f" lim)
5694 (cond
5695 ;; vhdl comment
5696 ((eq (vhdl-in-literal) 'comment)
5697 (skip-chars-backward "^-" lim)
5698 (skip-chars-backward "-" lim)
5699 (while (not (or (and (= (following-char) ?-)
5700 (= (char-after (1+ (point))) ?-))
5701 (<= (point) lim)))
5702 (skip-chars-backward "^-" lim)
5703 (skip-chars-backward "-" lim)))
5704 ;; none of the above
5705 (t (setq stop t))))))
5707 (and (string-match "Win-Emacs" emacs-version)
5708 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5710 ;; Functions to help finding the correct indentation column:
5712 (defun vhdl-first-word (point)
5713 "If the keyword at POINT is at boi, then return (current-column) at
5714 that point, else nil."
5715 (save-excursion
5716 (and (goto-char point)
5717 (eq (point) (vhdl-point 'boi))
5718 (current-column))))
5720 (defun vhdl-last-word (point)
5721 "If the keyword at POINT is at eoi, then return (current-column) at
5722 that point, else nil."
5723 (save-excursion
5724 (and (goto-char point)
5725 (save-excursion (or (eq (progn (forward-sexp) (point))
5726 (vhdl-point 'eoi))
5727 (looking-at "\\s-*\\(--\\)?")))
5728 (current-column))))
5730 ;; Core syntactic evaluation functions:
5732 (defconst vhdl-libunit-re
5733 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5735 (defun vhdl-libunit-p ()
5736 (and
5737 (save-excursion
5738 (forward-sexp)
5739 (skip-chars-forward " \t\n\r\f")
5740 (not (looking-at "is\\b[^_]")))
5741 (save-excursion
5742 (backward-sexp)
5743 (and (not (looking-at "use\\b[^_]"))
5744 (progn
5745 (forward-sexp)
5746 (vhdl-forward-syntactic-ws)
5747 (/= (following-char) ?:))))
5750 (defconst vhdl-defun-re
5751 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5753 (defun vhdl-defun-p ()
5754 (save-excursion
5755 (if (looking-at "block\\|process\\|procedural")
5756 ;; "block", "process", "procedural":
5757 (save-excursion
5758 (backward-sexp)
5759 (not (looking-at "end\\s-+\\w")))
5760 ;; "architecture", "configuration", "entity",
5761 ;; "package", "procedure", "function":
5762 t)))
5764 (defun vhdl-corresponding-defun ()
5765 "If the word at the current position corresponds to a \"defun\"
5766 keyword, then return a string that can be used to find the
5767 corresponding \"begin\" keyword, else return nil."
5768 (save-excursion
5769 (and (looking-at vhdl-defun-re)
5770 (vhdl-defun-p)
5771 (if (looking-at "block\\|process\\|procedural")
5772 ;; "block", "process". "procedural:
5773 (buffer-substring (match-beginning 0) (match-end 0))
5774 ;; "architecture", "configuration", "entity", "package",
5775 ;; "procedure", "function":
5776 "is"))))
5778 (defconst vhdl-begin-fwd-re
5779 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5780 "A regular expression for searching forward that matches all known
5781 \"begin\" keywords.")
5783 (defconst vhdl-begin-bwd-re
5784 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5785 "A regular expression for searching backward that matches all known
5786 \"begin\" keywords.")
5788 (defun vhdl-begin-p (&optional lim)
5789 "Return t if we are looking at a real \"begin\" keyword.
5790 Assumes that the caller will make sure that we are looking at
5791 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5792 the middle of an identifier that just happens to contain a \"begin\"
5793 keyword."
5794 (cond
5795 ;; "[architecture|case|configuration|entity|package|
5796 ;; procedure|function] ... is":
5797 ((and (looking-at "i")
5798 (save-excursion
5799 ;; Skip backward over first sexp (needed to skip over a
5800 ;; procedure interface list, and is harmless in other
5801 ;; situations). Note that we need "return" in the
5802 ;; following search list so that we don't run into
5803 ;; semicolons in the function interface list.
5804 (backward-sexp)
5805 (let (foundp)
5806 (while (and (not foundp)
5807 (re-search-backward
5808 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5809 lim 'move))
5810 (if (or (= (preceding-char) ?_)
5811 (vhdl-in-literal))
5812 (backward-char)
5813 (setq foundp t))))
5814 (and (/= (following-char) ?\;)
5815 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5817 ;; "begin", "then", "use":
5818 ((looking-at "be\\|t\\|use")
5820 ;; "else":
5821 ((and (looking-at "e")
5822 ;; make sure that the "else" isn't inside a
5823 ;; conditional signal assignment.
5824 (save-excursion
5825 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5826 (or (eq (following-char) ?\;)
5827 (eq (point) lim))))
5829 ;; "block", "generate", "loop", "process", "procedural",
5830 ;; "units", "record", "protected body":
5831 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
5832 (save-excursion
5833 (backward-sexp)
5834 (not (looking-at "end\\s-+\\w"))))
5836 ;; "component":
5837 ((and (looking-at "c")
5838 (save-excursion
5839 (backward-sexp)
5840 (not (looking-at "end\\s-+\\w")))
5841 ;; look out for the dreaded entity class in an attribute
5842 (save-excursion
5843 (vhdl-backward-syntactic-ws lim)
5844 (/= (preceding-char) ?:)))
5846 ;; "for" (inside configuration declaration):
5847 ((and (looking-at "f")
5848 (save-excursion
5849 (backward-sexp)
5850 (not (looking-at "end\\s-+\\w")))
5851 (vhdl-has-syntax 'configuration))
5855 (defun vhdl-corresponding-mid (&optional lim)
5856 (cond
5857 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5858 "begin")
5859 ((looking-at "then\\|use")
5860 "<else>")
5862 "end")))
5864 (defun vhdl-corresponding-end (&optional lim)
5865 "If the word at the current position corresponds to a \"begin\"
5866 keyword, then return a vector containing enough information to find
5867 the corresponding \"end\" keyword, else return nil. The keyword to
5868 search forward for is aref 0. The column in which the keyword must
5869 appear is aref 1 or nil if any column is suitable.
5870 Assumes that the caller will make sure that we are not in the middle
5871 of an identifier that just happens to contain a \"begin\" keyword."
5872 (save-excursion
5873 (and (looking-at vhdl-begin-fwd-re)
5874 (or (not (looking-at "\\<use\\>"))
5875 (save-excursion (back-to-indentation)
5876 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
5877 (/= (preceding-char) ?_)
5878 (not (vhdl-in-literal))
5879 (vhdl-begin-p lim)
5880 (cond
5881 ;; "is", "generate", "loop":
5882 ((looking-at "[igl]")
5883 (vector "end"
5884 (and (vhdl-last-word (point))
5885 (or (vhdl-first-word (point))
5886 (save-excursion
5887 (vhdl-beginning-of-statement-1 lim)
5888 (vhdl-backward-skip-label lim)
5889 (vhdl-first-word (point)))))))
5890 ;; "begin", "else", "for":
5891 ((looking-at "be\\|[ef]")
5892 (vector "end"
5893 (and (vhdl-last-word (point))
5894 (or (vhdl-first-word (point))
5895 (save-excursion
5896 (vhdl-beginning-of-statement-1 lim)
5897 (vhdl-backward-skip-label lim)
5898 (vhdl-first-word (point)))))))
5899 ;; "component", "units", "record", "protected body":
5900 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
5901 ;; The first end found will close the block
5902 (vector "end" nil))
5903 ;; "block", "process", "procedural":
5904 ((looking-at "bl\\|p")
5905 (vector "end"
5906 (or (vhdl-first-word (point))
5907 (save-excursion
5908 (vhdl-beginning-of-statement-1 lim)
5909 (vhdl-backward-skip-label lim)
5910 (vhdl-first-word (point))))))
5911 ;; "then":
5912 ((looking-at "t\\|use")
5913 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
5914 (and (vhdl-last-word (point))
5915 (or (vhdl-first-word (point))
5916 (save-excursion
5917 (vhdl-beginning-of-statement-1 lim)
5918 (vhdl-backward-skip-label lim)
5919 (vhdl-first-word (point)))))))
5920 ))))
5922 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5924 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5926 (defun vhdl-end-p (&optional lim)
5927 "Return t if we are looking at a real \"end\" keyword.
5928 Assumes that the caller will make sure that we are looking at
5929 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5930 the middle of an identifier that just happens to contain an \"end\"
5931 keyword."
5932 (or (not (looking-at "else"))
5933 ;; make sure that the "else" isn't inside a conditional signal
5934 ;; assignment.
5935 (save-excursion
5936 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5937 (or (eq (following-char) ?\;)
5938 (eq (point) lim)
5939 (vhdl-in-literal)))))
5941 (defun vhdl-corresponding-begin (&optional lim)
5942 "If the word at the current position corresponds to an \"end\"
5943 keyword, then return a vector containing enough information to find
5944 the corresponding \"begin\" keyword, else return nil. The keyword to
5945 search backward for is aref 0. The column in which the keyword must
5946 appear is aref 1 or nil if any column is suitable. The supplementary
5947 keyword to search forward for is aref 2 or nil if this is not
5948 required. If aref 3 is t, then the \"begin\" keyword may be found in
5949 the middle of a statement.
5950 Assumes that the caller will make sure that we are not in the middle
5951 of an identifier that just happens to contain an \"end\" keyword."
5952 (save-excursion
5953 (let (pos)
5954 (if (and (looking-at vhdl-end-fwd-re)
5955 (not (vhdl-in-literal))
5956 (vhdl-end-p lim))
5957 (if (looking-at "el")
5958 ;; "else", "elsif":
5959 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
5960 ;; "end ...":
5961 (setq pos (point))
5962 (forward-sexp)
5963 (skip-chars-forward " \t\n\r\f")
5964 (cond
5965 ;; "end if":
5966 ((looking-at "if\\b[^_]")
5967 (vector "else\\|elsif\\|if"
5968 (vhdl-first-word pos)
5969 "else\\|then\\|use" nil))
5970 ;; "end component":
5971 ((looking-at "component\\b[^_]")
5972 (vector (buffer-substring (match-beginning 1)
5973 (match-end 1))
5974 (vhdl-first-word pos)
5975 nil nil))
5976 ;; "end units", "end record", "end protected":
5977 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
5978 (vector (buffer-substring (match-beginning 1)
5979 (match-end 1))
5980 (vhdl-first-word pos)
5981 nil t))
5982 ;; "end block", "end process", "end procedural":
5983 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5984 (vector "begin" (vhdl-first-word pos) nil nil))
5985 ;; "end case":
5986 ((looking-at "case\\b[^_]")
5987 (vector "case" (vhdl-first-word pos) "is" nil))
5988 ;; "end generate":
5989 ((looking-at "generate\\b[^_]")
5990 (vector "generate\\|for\\|if"
5991 (vhdl-first-word pos)
5992 "generate" nil))
5993 ;; "end loop":
5994 ((looking-at "loop\\b[^_]")
5995 (vector "loop\\|while\\|for"
5996 (vhdl-first-word pos)
5997 "loop" nil))
5998 ;; "end for" (inside configuration declaration):
5999 ((looking-at "for\\b[^_]")
6000 (vector "for" (vhdl-first-word pos) nil nil))
6001 ;; "end [id]":
6003 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
6004 (vhdl-first-word pos)
6005 ;; return an alist of (statement . keyword) mappings
6007 ;; "begin ... end [id]":
6008 ("begin" . nil)
6009 ;; "architecture ... is ... begin ... end [id]":
6010 ("architecture" . "is")
6011 ;; "configuration ... is ... end [id]":
6012 ("configuration" . "is")
6013 ;; "entity ... is ... end [id]":
6014 ("entity" . "is")
6015 ;; "package ... is ... end [id]":
6016 ("package" . "is")
6017 ;; "procedure ... is ... begin ... end [id]":
6018 ("procedure" . "is")
6019 ;; "function ... is ... begin ... end [id]":
6020 ("function" . "is")
6022 nil))
6023 ))) ; "end ..."
6026 (defconst vhdl-leader-re
6027 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6029 (defun vhdl-end-of-leader ()
6030 (save-excursion
6031 (cond ((looking-at "block\\|process\\|procedural")
6032 (if (save-excursion
6033 (forward-sexp)
6034 (skip-chars-forward " \t\n\r\f")
6035 (= (following-char) ?\())
6036 (forward-sexp 2)
6037 (forward-sexp))
6038 (when (looking-at "[ \t\n\r\f]*is")
6039 (goto-char (match-end 0)))
6040 (point))
6041 ((looking-at "component")
6042 (forward-sexp 2)
6043 (when (looking-at "[ \t\n\r\f]*is")
6044 (goto-char (match-end 0)))
6045 (point))
6046 ((looking-at "for")
6047 (forward-sexp 2)
6048 (skip-chars-forward " \t\n\r\f")
6049 (while (looking-at "[,:(]")
6050 (forward-sexp)
6051 (skip-chars-forward " \t\n\r\f"))
6052 (point))
6053 (t nil)
6056 (defconst vhdl-trailer-re
6057 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6059 (defconst vhdl-statement-fwd-re
6060 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6061 "A regular expression for searching forward that matches all known
6062 \"statement\" keywords.")
6064 (defconst vhdl-statement-bwd-re
6065 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6066 "A regular expression for searching backward that matches all known
6067 \"statement\" keywords.")
6069 (defun vhdl-statement-p (&optional lim)
6070 "Return t if we are looking at a real \"statement\" keyword.
6071 Assumes that the caller will make sure that we are looking at
6072 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6073 in the middle of an identifier that just happens to contain a
6074 \"statement\" keyword."
6075 (cond
6076 ;; "for" ... "generate":
6077 ((and (looking-at "f")
6078 ;; Make sure it's the start of a parameter specification.
6079 (save-excursion
6080 (forward-sexp 2)
6081 (skip-chars-forward " \t\n\r\f")
6082 (looking-at "in\\b[^_]"))
6083 ;; Make sure it's not an "end for".
6084 (save-excursion
6085 (backward-sexp)
6086 (not (looking-at "end\\s-+\\w"))))
6088 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6089 ((and (looking-at "i")
6090 ;; Make sure it's not an "end if".
6091 (save-excursion
6092 (backward-sexp)
6093 (not (looking-at "end\\s-+\\w"))))
6095 ;; "while" ... "loop":
6096 ((looking-at "w")
6100 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6101 "Regexp describing a case statement alternative key.")
6103 (defun vhdl-case-alternative-p (&optional lim)
6104 "Return t if we are looking at a real case alternative.
6105 Assumes that the caller will make sure that we are looking at
6106 vhdl-case-alternative-re, and are not inside a literal, and that
6107 we are not in the middle of an identifier that just happens to
6108 contain a \"when\" keyword."
6109 (save-excursion
6110 (let (foundp)
6111 (while (and (not foundp)
6112 (re-search-backward ";\\|<=" lim 'move))
6113 (if (or (= (preceding-char) ?_)
6114 (vhdl-in-literal))
6115 (backward-char)
6116 (setq foundp t)))
6117 (or (eq (following-char) ?\;)
6118 (eq (point) lim)))
6121 ;; Core syntactic movement functions:
6123 (defconst vhdl-b-t-b-re
6124 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6126 (defun vhdl-backward-to-block (&optional lim)
6127 "Move backward to the previous \"begin\" or \"end\" keyword."
6128 (let (foundp)
6129 (while (and (not foundp)
6130 (re-search-backward vhdl-b-t-b-re lim 'move))
6131 (if (or (= (preceding-char) ?_)
6132 (vhdl-in-literal))
6133 (backward-char)
6134 (cond
6135 ;; "begin" keyword:
6136 ((and (looking-at vhdl-begin-fwd-re)
6137 (or (not (looking-at "\\<use\\>"))
6138 (save-excursion (back-to-indentation)
6139 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6140 (/= (preceding-char) ?_)
6141 (vhdl-begin-p lim))
6142 (setq foundp 'begin))
6143 ;; "end" keyword:
6144 ((and (looking-at vhdl-end-fwd-re)
6145 (/= (preceding-char) ?_)
6146 (vhdl-end-p lim))
6147 (setq foundp 'end))
6150 foundp
6153 (defun vhdl-forward-sexp (&optional count lim)
6154 "Move forward across one balanced expression (sexp).
6155 With COUNT, do it that many times."
6156 (interactive "p")
6157 (let ((count (or count 1))
6158 (case-fold-search t)
6159 end-vec target)
6160 (save-excursion
6161 (while (> count 0)
6162 ;; skip whitespace
6163 (skip-chars-forward " \t\n\r\f")
6164 ;; Check for an unbalanced "end" keyword
6165 (if (and (looking-at vhdl-end-fwd-re)
6166 (/= (preceding-char) ?_)
6167 (not (vhdl-in-literal))
6168 (vhdl-end-p lim)
6169 (not (looking-at "else")))
6170 (error
6171 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6172 ;; If the current keyword is a "begin" keyword, then find the
6173 ;; corresponding "end" keyword.
6174 (if (setq end-vec (vhdl-corresponding-end lim))
6175 (let (
6176 ;; end-re is the statement keyword to search for
6177 (end-re
6178 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6179 ;; column is either the statement keyword target column
6180 ;; or nil
6181 (column (aref end-vec 1))
6182 (eol (vhdl-point 'eol))
6183 foundp literal placeholder)
6184 ;; Look for the statement keyword.
6185 (while (and (not foundp)
6186 (re-search-forward end-re nil t)
6187 (setq placeholder (match-end 1))
6188 (goto-char (match-beginning 0)))
6189 ;; If we are in a literal, or not in the right target
6190 ;; column and not on the same line as the begin, then
6191 ;; try again.
6192 (if (or (and column
6193 (/= (current-indentation) column)
6194 (> (point) eol))
6195 (= (preceding-char) ?_)
6196 (setq literal (vhdl-in-literal)))
6197 (if (eq literal 'comment)
6198 (end-of-line)
6199 (forward-char))
6200 ;; An "else" keyword corresponds to both the opening brace
6201 ;; of the following sexp and the closing brace of the
6202 ;; previous sexp.
6203 (if (not (looking-at "else"))
6204 (goto-char placeholder))
6205 (setq foundp t))
6207 (if (not foundp)
6208 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6210 ;; If the current keyword is not a "begin" keyword, then just
6211 ;; perform the normal forward-sexp.
6212 (forward-sexp)
6214 (setq count (1- count))
6216 (setq target (point)))
6217 (goto-char target)
6218 nil))
6220 (defun vhdl-backward-sexp (&optional count lim)
6221 "Move backward across one balanced expression (sexp).
6222 With COUNT, do it that many times. LIM bounds any required backward
6223 searches."
6224 (interactive "p")
6225 (let ((count (or count 1))
6226 (case-fold-search t)
6227 begin-vec target)
6228 (save-excursion
6229 (while (> count 0)
6230 ;; Perform the normal backward-sexp, unless we are looking at
6231 ;; "else" - an "else" keyword corresponds to both the opening brace
6232 ;; of the following sexp and the closing brace of the previous sexp.
6233 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6234 (/= (preceding-char) ?_)
6235 (not (vhdl-in-literal)))
6237 (backward-sexp)
6238 (if (and (looking-at vhdl-begin-fwd-re)
6239 (or (not (looking-at "\\<use\\>"))
6240 (save-excursion
6241 (back-to-indentation)
6242 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6243 (/= (preceding-char) ?_)
6244 (not (vhdl-in-literal))
6245 (vhdl-begin-p lim))
6246 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6247 ;; If the current keyword is an "end" keyword, then find the
6248 ;; corresponding "begin" keyword.
6249 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6250 (/= (preceding-char) ?_))
6251 (let (
6252 ;; begin-re is the statement keyword to search for
6253 (begin-re
6254 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6255 ;; column is either the statement keyword target column
6256 ;; or nil
6257 (column (aref begin-vec 1))
6258 ;; internal-p controls where the statement keyword can
6259 ;; be found.
6260 (internal-p (aref begin-vec 3))
6261 (last-backward (point)) last-forward
6262 foundp literal keyword)
6263 ;; Look for the statement keyword.
6264 (while (and (not foundp)
6265 (re-search-backward begin-re lim t)
6266 (setq keyword
6267 (buffer-substring (match-beginning 1)
6268 (match-end 1))))
6269 ;; If we are in a literal or in the wrong column,
6270 ;; then try again.
6271 (if (or (and column
6272 (and (/= (current-indentation) column)
6273 ;; possibly accept current-column as
6274 ;; well as current-indentation.
6275 (or (not internal-p)
6276 (/= (current-column) column))))
6277 (= (preceding-char) ?_)
6278 (vhdl-in-literal))
6279 (backward-char)
6280 ;; If there is a supplementary keyword, then
6281 ;; search forward for it.
6282 (if (and (setq begin-re (aref begin-vec 2))
6283 (or (not (listp begin-re))
6284 ;; If begin-re is an alist, then find the
6285 ;; element corresponding to the actual
6286 ;; keyword that we found.
6287 (progn
6288 (setq begin-re
6289 (assoc keyword begin-re))
6290 (and begin-re
6291 (setq begin-re (cdr begin-re))))))
6292 (and
6293 (setq begin-re
6294 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6295 (save-excursion
6296 (setq last-forward (point))
6297 ;; Look for the supplementary keyword
6298 ;; (bounded by the backward search start
6299 ;; point).
6300 (while (and (not foundp)
6301 (re-search-forward begin-re
6302 last-backward t)
6303 (goto-char (match-beginning 1)))
6304 ;; If we are in a literal, then try again.
6305 (if (or (= (preceding-char) ?_)
6306 (setq literal
6307 (vhdl-in-literal)))
6308 (if (eq literal 'comment)
6309 (goto-char
6310 (min (vhdl-point 'eol) last-backward))
6311 (forward-char))
6312 ;; We have found the supplementary keyword.
6313 ;; Save the position of the keyword in foundp.
6314 (setq foundp (point)))
6316 foundp)
6317 ;; If the supplementary keyword was found, then
6318 ;; move point to the supplementary keyword.
6319 (goto-char foundp))
6320 ;; If there was no supplementary keyword, then
6321 ;; point is already at the statement keyword.
6322 (setq foundp t)))
6323 ) ; end of the search for the statement keyword
6324 (if (not foundp)
6325 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6327 (setq count (1- count))
6329 (setq target (point)))
6330 (goto-char target)
6331 nil))
6333 (defun vhdl-backward-up-list (&optional count limit)
6334 "Move backward out of one level of blocks.
6335 With argument, do this that many times."
6336 (interactive "p")
6337 (let ((count (or count 1))
6338 target)
6339 (save-excursion
6340 (while (> count 0)
6341 (if (looking-at vhdl-defun-re)
6342 (error "ERROR: Unbalanced blocks"))
6343 (vhdl-backward-to-block limit)
6344 (setq count (1- count)))
6345 (setq target (point)))
6346 (goto-char target)))
6348 (defun vhdl-end-of-defun (&optional count)
6349 "Move forward to the end of a VHDL defun."
6350 (interactive)
6351 (let ((case-fold-search t))
6352 (vhdl-beginning-of-defun)
6353 (if (not (looking-at "block\\|process\\|procedural"))
6354 (re-search-forward "\\bis\\b"))
6355 (vhdl-forward-sexp)))
6357 (defun vhdl-mark-defun ()
6358 "Put mark at end of this \"defun\", point at beginning."
6359 (interactive)
6360 (let ((case-fold-search t))
6361 (push-mark)
6362 (vhdl-beginning-of-defun)
6363 (push-mark)
6364 (if (not (looking-at "block\\|process\\|procedural"))
6365 (re-search-forward "\\bis\\b"))
6366 (vhdl-forward-sexp)
6367 (exchange-point-and-mark)))
6369 (defun vhdl-beginning-of-libunit ()
6370 "Move backward to the beginning of a VHDL library unit.
6371 Returns the location of the corresponding begin keyword, unless search
6372 stops due to beginning or end of buffer.
6373 Note that if point is between the \"libunit\" keyword and the
6374 corresponding \"begin\" keyword, then that libunit will not be
6375 recognized, and the search will continue backwards. If point is
6376 at the \"begin\" keyword, then the defun will be recognized. The
6377 returned point is at the first character of the \"libunit\" keyword."
6378 (let ((last-forward (point))
6379 (last-backward
6380 ;; Just in case we are actually sitting on the "begin"
6381 ;; keyword, allow for the keyword and an extra character,
6382 ;; as this will be used when looking forward for the
6383 ;; "begin" keyword.
6384 (save-excursion (forward-word 1) (1+ (point))))
6385 foundp literal placeholder)
6386 ;; Find the "libunit" keyword.
6387 (while (and (not foundp)
6388 (re-search-backward vhdl-libunit-re nil 'move))
6389 ;; If we are in a literal, or not at a real libunit, then try again.
6390 (if (or (= (preceding-char) ?_)
6391 (vhdl-in-literal)
6392 (not (vhdl-libunit-p)))
6393 (backward-char)
6394 ;; Find the corresponding "begin" keyword.
6395 (setq last-forward (point))
6396 (while (and (not foundp)
6397 (re-search-forward "\\bis\\b[^_]" last-backward t)
6398 (setq placeholder (match-beginning 0)))
6399 (if (or (= (preceding-char) ?_)
6400 (setq literal (vhdl-in-literal)))
6401 ;; It wasn't a real keyword, so keep searching.
6402 (if (eq literal 'comment)
6403 (goto-char
6404 (min (vhdl-point 'eol) last-backward))
6405 (forward-char))
6406 ;; We have found the begin keyword, loop will exit.
6407 (setq foundp placeholder)))
6408 ;; Go back to the libunit keyword
6409 (goto-char last-forward)))
6410 foundp))
6412 (defun vhdl-beginning-of-defun (&optional count)
6413 "Move backward to the beginning of a VHDL defun.
6414 With argument, do it that many times.
6415 Returns the location of the corresponding begin keyword, unless search
6416 stops due to beginning or end of buffer."
6417 ;; Note that if point is between the "defun" keyword and the
6418 ;; corresponding "begin" keyword, then that defun will not be
6419 ;; recognized, and the search will continue backwards. If point is
6420 ;; at the "begin" keyword, then the defun will be recognized. The
6421 ;; returned point is at the first character of the "defun" keyword.
6422 (interactive "p")
6423 (let ((count (or count 1))
6424 (case-fold-search t)
6425 (last-forward (point))
6426 foundp)
6427 (while (> count 0)
6428 (setq foundp nil)
6429 (goto-char last-forward)
6430 (let ((last-backward
6431 ;; Just in case we are actually sitting on the "begin"
6432 ;; keyword, allow for the keyword and an extra character,
6433 ;; as this will be used when looking forward for the
6434 ;; "begin" keyword.
6435 (save-excursion (forward-word 1) (1+ (point))))
6436 begin-string literal)
6437 (while (and (not foundp)
6438 (re-search-backward vhdl-defun-re nil 'move))
6439 ;; If we are in a literal, then try again.
6440 (if (or (= (preceding-char) ?_)
6441 (vhdl-in-literal))
6442 (backward-char)
6443 (if (setq begin-string (vhdl-corresponding-defun))
6444 ;; This is a real defun keyword.
6445 ;; Find the corresponding "begin" keyword.
6446 ;; Look for the begin keyword.
6447 (progn
6448 ;; Save the search start point.
6449 (setq last-forward (point))
6450 (while (and (not foundp)
6451 (search-forward begin-string last-backward t))
6452 (if (or (= (preceding-char) ?_)
6453 (save-match-data
6454 (setq literal (vhdl-in-literal))))
6455 ;; It wasn't a real keyword, so keep searching.
6456 (if (eq literal 'comment)
6457 (goto-char
6458 (min (vhdl-point 'eol) last-backward))
6459 (forward-char))
6460 ;; We have found the begin keyword, loop will exit.
6461 (setq foundp (match-beginning 0)))
6463 ;; Go back to the defun keyword
6464 (goto-char last-forward)) ; end search for begin keyword
6466 ) ; end of the search for the defun keyword
6468 (setq count (1- count))
6470 (vhdl-keep-region-active)
6471 foundp))
6473 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6474 "Go to the beginning of the innermost VHDL statement.
6475 With prefix arg, go back N - 1 statements. If already at the
6476 beginning of a statement then go to the beginning of the preceding
6477 one. If within a string or comment, or next to a comment (only
6478 whitespace between), move by sentences instead of statements.
6480 When called from a program, this function takes 3 optional args: the
6481 prefix arg, a buffer position limit which is the farthest back to
6482 search, and an argument indicating an interactive call."
6483 (interactive "p\np")
6484 (let ((count (or count 1))
6485 (case-fold-search t)
6486 (lim (or lim (point-min)))
6487 (here (point))
6488 state)
6489 (save-excursion
6490 (goto-char lim)
6491 (setq state (parse-partial-sexp (point) here nil nil)))
6492 (if (and interactive
6493 (or (nth 3 state)
6494 (nth 4 state)
6495 (looking-at (concat "[ \t]*" comment-start-skip))))
6496 (forward-sentence (- count))
6497 (while (> count 0)
6498 (vhdl-beginning-of-statement-1 lim)
6499 (setq count (1- count))))
6500 ;; its possible we've been left up-buf of lim
6501 (goto-char (max (point) lim))
6503 (vhdl-keep-region-active))
6505 (defconst vhdl-e-o-s-re
6506 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6508 (defun vhdl-end-of-statement ()
6509 "Very simple implementation."
6510 (interactive)
6511 (re-search-forward vhdl-e-o-s-re))
6513 (defconst vhdl-b-o-s-re
6514 (concat ";[^_]\\|\([^_]\\|\)[^_]\\|\\bwhen\\b[^_]\\|"
6515 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6517 (defun vhdl-beginning-of-statement-1 (&optional lim)
6518 "Move to the start of the current statement, or the previous
6519 statement if already at the beginning of one."
6520 (let ((lim (or lim (point-min)))
6521 (here (point))
6522 (pos (point))
6523 donep)
6524 ;; go backwards one balanced expression, but be careful of
6525 ;; unbalanced paren being reached
6526 (if (not (vhdl-safe (progn (backward-sexp) t)))
6527 (progn
6528 (backward-up-list 1)
6529 (forward-char)
6530 (vhdl-forward-syntactic-ws here)
6531 (setq donep t)))
6532 (while (and (not donep)
6533 (not (bobp))
6534 ;; look backwards for a statement boundary
6535 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6536 (if (or (= (preceding-char) ?_)
6537 (vhdl-in-literal))
6538 (backward-char)
6539 (cond
6540 ;; If we are looking at an open paren, then stop after it
6541 ((eq (following-char) ?\()
6542 (forward-char)
6543 (vhdl-forward-syntactic-ws here)
6544 (setq donep t))
6545 ;; If we are looking at a close paren, then skip it
6546 ((eq (following-char) ?\))
6547 (forward-char)
6548 (setq pos (point))
6549 (backward-sexp)
6550 (if (< (point) lim)
6551 (progn (goto-char pos)
6552 (vhdl-forward-syntactic-ws here)
6553 (setq donep t))))
6554 ;; If we are looking at a semicolon, then stop
6555 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6556 (progn
6557 (forward-char)
6558 (vhdl-forward-syntactic-ws here)
6559 (setq donep t)))
6560 ;; If we are looking at a "begin", then stop
6561 ((and (looking-at vhdl-begin-fwd-re)
6562 (or (not (looking-at "\\<use\\>"))
6563 (save-excursion
6564 (back-to-indentation)
6565 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6566 (/= (preceding-char) ?_)
6567 (vhdl-begin-p nil))
6568 ;; If it's a leader "begin", then find the
6569 ;; right place
6570 (if (looking-at vhdl-leader-re)
6571 (save-excursion
6572 ;; set a default stop point at the begin
6573 (setq pos (point))
6574 ;; is the start point inside the leader area ?
6575 (goto-char (vhdl-end-of-leader))
6576 (vhdl-forward-syntactic-ws here)
6577 (if (< (point) here)
6578 ;; start point was not inside leader area
6579 ;; set stop point at word after leader
6580 (setq pos (point))))
6581 (forward-word 1)
6582 (vhdl-forward-syntactic-ws here)
6583 (setq pos (point)))
6584 (goto-char pos)
6585 (setq donep t))
6586 ;; If we are looking at a "statement", then stop
6587 ((and (looking-at vhdl-statement-fwd-re)
6588 (/= (preceding-char) ?_)
6589 (vhdl-statement-p nil))
6590 (setq donep t))
6591 ;; If we are looking at a case alternative key, then stop
6592 ((and (looking-at vhdl-case-alternative-re)
6593 (vhdl-case-alternative-p lim))
6594 (save-excursion
6595 ;; set a default stop point at the when
6596 (setq pos (point))
6597 ;; is the start point inside the case alternative key ?
6598 (looking-at vhdl-case-alternative-re)
6599 (goto-char (match-end 0))
6600 (vhdl-forward-syntactic-ws here)
6601 (if (< (point) here)
6602 ;; start point was not inside the case alternative key
6603 ;; set stop point at word after case alternative keyleader
6604 (setq pos (point))))
6605 (goto-char pos)
6606 (setq donep t))
6607 ;; Bogus find, continue
6609 (backward-char)))))
6612 ;; Defuns for calculating the current syntactic state:
6614 (defun vhdl-get-library-unit (bod placeholder)
6615 "If there is an enclosing library unit at BOD, with its \"begin\"
6616 keyword at PLACEHOLDER, then return the library unit type."
6617 (let ((here (vhdl-point 'bol)))
6618 (if (save-excursion
6619 (goto-char placeholder)
6620 (vhdl-safe (vhdl-forward-sexp 1 bod))
6621 (<= here (point)))
6622 (save-excursion
6623 (goto-char bod)
6624 (cond
6625 ((looking-at "e") 'entity)
6626 ((looking-at "a") 'architecture)
6627 ((looking-at "c") 'configuration)
6628 ((looking-at "p")
6629 (save-excursion
6630 (goto-char bod)
6631 (forward-sexp)
6632 (vhdl-forward-syntactic-ws here)
6633 (if (looking-at "body\\b[^_]")
6634 'package-body 'package))))))
6637 (defun vhdl-get-block-state (&optional lim)
6638 "Finds and records all the closest opens.
6639 LIM is the furthest back we need to search (it should be the
6640 previous libunit keyword)."
6641 (let ((here (point))
6642 (lim (or lim (point-min)))
6643 keyword sexp-start sexp-mid sexp-end
6644 preceding-sexp containing-sexp
6645 containing-begin containing-mid containing-paren)
6646 (save-excursion
6647 ;; Find the containing-paren, and use that as the limit
6648 (if (setq containing-paren
6649 (save-restriction
6650 (narrow-to-region lim (point))
6651 (vhdl-safe (scan-lists (point) -1 1))))
6652 (setq lim containing-paren))
6653 ;; Look backwards for "begin" and "end" keywords.
6654 (while (and (> (point) lim)
6655 (not containing-sexp))
6656 (setq keyword (vhdl-backward-to-block lim))
6657 (cond
6658 ((eq keyword 'begin)
6659 ;; Found a "begin" keyword
6660 (setq sexp-start (point))
6661 (setq sexp-mid (vhdl-corresponding-mid lim))
6662 (setq sexp-end (vhdl-safe
6663 (save-excursion
6664 (vhdl-forward-sexp 1 lim) (point))))
6665 (if (and sexp-end (<= sexp-end here))
6666 ;; we want to record this sexp, but we only want to
6667 ;; record the last-most of any of them before here
6668 (or preceding-sexp
6669 (setq preceding-sexp sexp-start))
6670 ;; we're contained in this sexp so put sexp-start on
6671 ;; front of list
6672 (setq containing-sexp sexp-start)
6673 (setq containing-mid sexp-mid)
6674 (setq containing-begin t)))
6675 ((eq keyword 'end)
6676 ;; Found an "end" keyword
6677 (forward-sexp)
6678 (setq sexp-end (point))
6679 (setq sexp-mid nil)
6680 (setq sexp-start
6681 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6682 (progn (backward-sexp) (point))))
6683 ;; we want to record this sexp, but we only want to
6684 ;; record the last-most of any of them before here
6685 (or preceding-sexp
6686 (setq preceding-sexp sexp-start)))
6688 ;; Check if the containing-paren should be the containing-sexp
6689 (if (and containing-paren
6690 (or (null containing-sexp)
6691 (< containing-sexp containing-paren)))
6692 (setq containing-sexp containing-paren
6693 preceding-sexp nil
6694 containing-begin nil
6695 containing-mid nil))
6696 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6700 (defconst vhdl-s-c-a-re
6701 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6703 (defun vhdl-skip-case-alternative (&optional lim)
6704 "Skip forward over case/when bodies, with optional maximal
6705 limit. If no next case alternative is found, nil is returned and
6706 point is not moved."
6707 (let ((lim (or lim (point-max)))
6708 (here (point))
6709 donep foundp)
6710 (while (and (< (point) lim)
6711 (not donep))
6712 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6713 (save-match-data
6714 (not (vhdl-in-literal)))
6715 (/= (match-beginning 0) here))
6716 (progn
6717 (goto-char (match-beginning 0))
6718 (cond
6719 ((and (looking-at "case")
6720 (re-search-forward "\\bis[^_]" lim t))
6721 (backward-sexp)
6722 (vhdl-forward-sexp))
6724 (setq donep t
6725 foundp t))))))
6726 (if (not foundp)
6727 (goto-char here))
6728 foundp))
6730 (defun vhdl-backward-skip-label (&optional lim)
6731 "Skip backward over a label, with optional maximal
6732 limit. If label is not found, nil is returned and point
6733 is not moved."
6734 (let ((lim (or lim (point-min)))
6735 placeholder)
6736 (if (save-excursion
6737 (vhdl-backward-syntactic-ws lim)
6738 (and (eq (preceding-char) ?:)
6739 (progn
6740 (backward-sexp)
6741 (setq placeholder (point))
6742 (looking-at vhdl-label-key))))
6743 (goto-char placeholder))
6746 (defun vhdl-forward-skip-label (&optional lim)
6747 "Skip forward over a label, with optional maximal
6748 limit. If label is not found, nil is returned and point
6749 is not moved."
6750 (let ((lim (or lim (point-max))))
6751 (if (looking-at vhdl-label-key)
6752 (progn
6753 (goto-char (match-end 0))
6754 (vhdl-forward-syntactic-ws lim)))
6757 (defun vhdl-get-syntactic-context ()
6758 "Guess the syntactic description of the current line of VHDL code."
6759 (save-excursion
6760 (save-restriction
6761 (beginning-of-line)
6762 (let* ((indent-point (point))
6763 (case-fold-search t)
6764 vec literal containing-sexp preceding-sexp
6765 containing-begin containing-mid containing-leader
6766 char-before-ip char-after-ip begin-after-ip end-after-ip
6767 placeholder lim library-unit
6770 ;; Reset the syntactic context
6771 (setq vhdl-syntactic-context nil)
6773 (save-excursion
6774 ;; Move to the start of the previous library unit, and
6775 ;; record the position of the "begin" keyword.
6776 (setq placeholder (vhdl-beginning-of-libunit))
6777 ;; The position of the "libunit" keyword gives us a gross
6778 ;; limit point.
6779 (setq lim (point))
6782 ;; If there is a previous library unit, and we are enclosed by
6783 ;; it, then set the syntax accordingly.
6784 (and placeholder
6785 (setq library-unit (vhdl-get-library-unit lim placeholder))
6786 (vhdl-add-syntax library-unit lim))
6788 ;; Find the surrounding state.
6789 (if (setq vec (vhdl-get-block-state lim))
6790 (progn
6791 (setq containing-sexp (aref vec 0))
6792 (setq preceding-sexp (aref vec 1))
6793 (setq containing-begin (aref vec 2))
6794 (setq containing-mid (aref vec 3))
6797 ;; set the limit on the farthest back we need to search
6798 (setq lim (if containing-sexp
6799 (save-excursion
6800 (goto-char containing-sexp)
6801 ;; set containing-leader if required
6802 (if (looking-at vhdl-leader-re)
6803 (setq containing-leader (vhdl-end-of-leader)))
6804 (vhdl-point 'bol))
6805 (point-min)))
6807 ;; cache char before and after indent point, and move point to
6808 ;; the most likely position to perform the majority of tests
6809 (goto-char indent-point)
6810 (skip-chars-forward " \t")
6811 (setq literal (vhdl-in-literal))
6812 (setq char-after-ip (following-char))
6813 (setq begin-after-ip (and
6814 (not literal)
6815 (looking-at vhdl-begin-fwd-re)
6816 (or (not (looking-at "\\<use\\>"))
6817 (save-excursion
6818 (back-to-indentation)
6819 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6820 (vhdl-begin-p)))
6821 (setq end-after-ip (and
6822 (not literal)
6823 (looking-at vhdl-end-fwd-re)
6824 (vhdl-end-p)))
6825 (vhdl-backward-syntactic-ws lim)
6826 (setq char-before-ip (preceding-char))
6827 (goto-char indent-point)
6828 (skip-chars-forward " \t")
6830 ;; now figure out syntactic qualities of the current line
6831 (cond
6832 ;; CASE 1: in a string or comment.
6833 ((memq literal '(string comment))
6834 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6835 ;; CASE 2: Line is at top level.
6836 ((null containing-sexp)
6837 ;; Find the point to which indentation will be relative
6838 (save-excursion
6839 (if (null preceding-sexp)
6840 ;; CASE 2X.1
6841 ;; no preceding-sexp -> use the preceding statement
6842 (vhdl-beginning-of-statement-1 lim)
6843 ;; CASE 2X.2
6844 ;; if there is a preceding-sexp then indent relative to it
6845 (goto-char preceding-sexp)
6846 ;; if not at boi, then the block-opening keyword is
6847 ;; probably following a label, so we need a different
6848 ;; relpos
6849 (if (/= (point) (vhdl-point 'boi))
6850 ;; CASE 2X.3
6851 (vhdl-beginning-of-statement-1 lim)))
6852 ;; v-b-o-s could have left us at point-min
6853 (and (bobp)
6854 ;; CASE 2X.4
6855 (vhdl-forward-syntactic-ws indent-point))
6856 (setq placeholder (point)))
6857 (cond
6858 ;; CASE 2A : we are looking at a block-open
6859 (begin-after-ip
6860 (vhdl-add-syntax 'block-open placeholder))
6861 ;; CASE 2B: we are looking at a block-close
6862 (end-after-ip
6863 (vhdl-add-syntax 'block-close placeholder))
6864 ;; CASE 2C: we are looking at a top-level statement
6865 ((progn
6866 (vhdl-backward-syntactic-ws lim)
6867 (or (bobp)
6868 (and (= (preceding-char) ?\;)
6869 (not (vhdl-in-quote-p)))))
6870 (vhdl-add-syntax 'statement placeholder))
6871 ;; CASE 2D: we are looking at a top-level statement-cont
6873 (vhdl-beginning-of-statement-1 lim)
6874 ;; v-b-o-s could have left us at point-min
6875 (and (bobp)
6876 ;; CASE 2D.1
6877 (vhdl-forward-syntactic-ws indent-point))
6878 (vhdl-add-syntax 'statement-cont (point)))
6879 )) ; end CASE 2
6880 ;; CASE 3: line is inside parentheses. Most likely we are
6881 ;; either in a subprogram argument (interface) list, or a
6882 ;; continued expression containing parentheses.
6883 ((null containing-begin)
6884 (vhdl-backward-syntactic-ws containing-sexp)
6885 (cond
6886 ;; CASE 3A: we are looking at the arglist closing paren
6887 ((eq char-after-ip ?\))
6888 (goto-char containing-sexp)
6889 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6890 ;; CASE 3B: we are looking at the first argument in an empty
6891 ;; argument list.
6892 ((eq char-before-ip ?\()
6893 (goto-char containing-sexp)
6894 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6895 ;; CASE 3C: we are looking at an arglist continuation line,
6896 ;; but the preceding argument is on the same line as the
6897 ;; opening paren. This case includes multi-line
6898 ;; expression paren groupings.
6899 ((and (save-excursion
6900 (goto-char (1+ containing-sexp))
6901 (skip-chars-forward " \t")
6902 (not (eolp))
6903 (not (looking-at "--")))
6904 (save-excursion
6905 (vhdl-beginning-of-statement-1 containing-sexp)
6906 (skip-chars-backward " \t(")
6907 (while (and (= (preceding-char) ?\;)
6908 (not (vhdl-in-quote-p)))
6909 (vhdl-beginning-of-statement-1 containing-sexp)
6910 (skip-chars-backward " \t("))
6911 (<= (point) containing-sexp)))
6912 (goto-char containing-sexp)
6913 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6914 ;; CASE 3D: we are looking at just a normal arglist
6915 ;; continuation line
6916 (t (vhdl-beginning-of-statement-1 containing-sexp)
6917 (vhdl-forward-syntactic-ws indent-point)
6918 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6920 ;; CASE 4: A block mid open
6921 ((and begin-after-ip
6922 (looking-at containing-mid))
6923 (goto-char containing-sexp)
6924 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6925 (if (looking-at vhdl-trailer-re)
6926 ;; CASE 4.1
6927 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6928 (vhdl-backward-skip-label (vhdl-point 'boi))
6929 (vhdl-add-syntax 'block-open (point)))
6930 ;; CASE 5: block close brace
6931 (end-after-ip
6932 (goto-char containing-sexp)
6933 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6934 (if (looking-at vhdl-trailer-re)
6935 ;; CASE 5.1
6936 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6937 (vhdl-backward-skip-label (vhdl-point 'boi))
6938 (vhdl-add-syntax 'block-close (point)))
6939 ;; CASE 6: A continued statement
6940 ((and (/= char-before-ip ?\;)
6941 ;; check it's not a trailer begin keyword, or a begin
6942 ;; keyword immediately following a label.
6943 (not (and begin-after-ip
6944 (or (looking-at vhdl-trailer-re)
6945 (save-excursion
6946 (vhdl-backward-skip-label containing-sexp)))))
6947 ;; check it's not a statement keyword
6948 (not (and (looking-at vhdl-statement-fwd-re)
6949 (vhdl-statement-p)))
6950 ;; see if the b-o-s is before the indent point
6951 (> indent-point
6952 (save-excursion
6953 (vhdl-beginning-of-statement-1 containing-sexp)
6954 ;; If we ended up after a leader, then this will
6955 ;; move us forward to the start of the first
6956 ;; statement. Note that a containing sexp here is
6957 ;; always a keyword, not a paren, so this will
6958 ;; have no effect if we hit the containing-sexp.
6959 (vhdl-forward-syntactic-ws indent-point)
6960 (setq placeholder (point))))
6961 ;; check it's not a block-intro
6962 (/= placeholder containing-sexp)
6963 ;; check it's not a case block-intro
6964 (save-excursion
6965 (goto-char placeholder)
6966 (or (not (looking-at vhdl-case-alternative-re))
6967 (> (match-end 0) indent-point))))
6968 ;; Make placeholder skip a label, but only if it puts us
6969 ;; before the indent point at the start of a line.
6970 (let ((new placeholder))
6971 (if (and (> indent-point
6972 (save-excursion
6973 (goto-char placeholder)
6974 (vhdl-forward-skip-label indent-point)
6975 (setq new (point))))
6976 (save-excursion
6977 (goto-char new)
6978 (eq new (progn (back-to-indentation) (point)))))
6979 (setq placeholder new)))
6980 (vhdl-add-syntax 'statement-cont placeholder)
6981 (if begin-after-ip
6982 (vhdl-add-syntax 'block-open)))
6983 ;; Statement. But what kind?
6984 ;; CASE 7: A case alternative key
6985 ((and (looking-at vhdl-case-alternative-re)
6986 (vhdl-case-alternative-p containing-sexp))
6987 ;; for a case alternative key, we set relpos to the first
6988 ;; non-whitespace char on the line containing the "case"
6989 ;; keyword.
6990 (goto-char containing-sexp)
6991 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6992 (if (looking-at vhdl-trailer-re)
6993 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6994 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6995 ;; CASE 8: statement catchall
6997 ;; we know its a statement, but we need to find out if it is
6998 ;; the first statement in a block
6999 (if containing-leader
7000 (goto-char containing-leader)
7001 (goto-char containing-sexp)
7002 ;; Note that a containing sexp here is always a keyword,
7003 ;; not a paren, so skip over the keyword.
7004 (forward-sexp))
7005 ;; move to the start of the first statement
7006 (vhdl-forward-syntactic-ws indent-point)
7007 (setq placeholder (point))
7008 ;; we want to ignore case alternatives keys when skipping forward
7009 (let (incase-p)
7010 (while (looking-at vhdl-case-alternative-re)
7011 (setq incase-p (point))
7012 ;; we also want to skip over the body of the
7013 ;; case/when statement if that doesn't put us at
7014 ;; after the indent-point
7015 (while (vhdl-skip-case-alternative indent-point))
7016 ;; set up the match end
7017 (looking-at vhdl-case-alternative-re)
7018 (goto-char (match-end 0))
7019 ;; move to the start of the first case alternative statement
7020 (vhdl-forward-syntactic-ws indent-point)
7021 (setq placeholder (point)))
7022 (cond
7023 ;; CASE 8A: we saw a case/when statement so we must be
7024 ;; in a switch statement. find out if we are at the
7025 ;; statement just after a case alternative key
7026 ((and incase-p
7027 (= (point) indent-point))
7028 ;; relpos is the "when" keyword
7029 (vhdl-add-syntax 'statement-case-intro incase-p))
7030 ;; CASE 8B: any old statement
7031 ((< (point) indent-point)
7032 ;; relpos is the first statement of the block
7033 (vhdl-add-syntax 'statement placeholder)
7034 (if begin-after-ip
7035 (vhdl-add-syntax 'block-open)))
7036 ;; CASE 8C: first statement in a block
7038 (goto-char containing-sexp)
7039 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7040 (if (looking-at vhdl-trailer-re)
7041 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7042 (vhdl-backward-skip-label (vhdl-point 'boi))
7043 (vhdl-add-syntax 'statement-block-intro (point))
7044 (if begin-after-ip
7045 (vhdl-add-syntax 'block-open)))
7049 ;; now we need to look at any modifiers
7050 (goto-char indent-point)
7051 (skip-chars-forward " \t")
7052 (if (looking-at "--")
7053 (vhdl-add-syntax 'comment))
7054 (if (eq literal 'pound)
7055 (vhdl-add-syntax 'cpp-macro))
7056 ;; return the syntax
7057 vhdl-syntactic-context))))
7059 ;; Standard indentation line-ups:
7061 (defun vhdl-lineup-arglist (langelem)
7062 "Lineup the current arglist line with the arglist appearing just
7063 after the containing paren which starts the arglist."
7064 (save-excursion
7065 (let* ((containing-sexp
7066 (save-excursion
7067 ;; arglist-cont-nonempty gives relpos ==
7068 ;; to boi of containing-sexp paren. This
7069 ;; is good when offset is +, but bad
7070 ;; when it is vhdl-lineup-arglist, so we
7071 ;; have to special case a kludge here.
7072 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7073 (progn
7074 (beginning-of-line)
7075 (backward-up-list 1)
7076 (skip-chars-forward " \t" (vhdl-point 'eol)))
7077 (goto-char (cdr langelem)))
7078 (point)))
7079 (cs-curcol (save-excursion
7080 (goto-char (cdr langelem))
7081 (current-column))))
7082 (if (save-excursion
7083 (beginning-of-line)
7084 (looking-at "[ \t]*)"))
7085 (progn (goto-char (match-end 0))
7086 (backward-sexp)
7087 (forward-char)
7088 (vhdl-forward-syntactic-ws)
7089 (- (current-column) cs-curcol))
7090 (goto-char containing-sexp)
7091 (or (eolp)
7092 (let ((eol (vhdl-point 'eol))
7093 (here (progn
7094 (forward-char)
7095 (skip-chars-forward " \t")
7096 (point))))
7097 (vhdl-forward-syntactic-ws)
7098 (if (< (point) eol)
7099 (goto-char here))))
7100 (- (current-column) cs-curcol)
7101 ))))
7103 (defun vhdl-lineup-arglist-intro (langelem)
7104 "Lineup an arglist-intro line to just after the open paren."
7105 (save-excursion
7106 (let ((cs-curcol (save-excursion
7107 (goto-char (cdr langelem))
7108 (current-column)))
7109 (ce-curcol (save-excursion
7110 (beginning-of-line)
7111 (backward-up-list 1)
7112 (skip-chars-forward " \t" (vhdl-point 'eol))
7113 (current-column))))
7114 (- ce-curcol cs-curcol -1))))
7116 (defun vhdl-lineup-comment (langelem)
7117 "Support old behavior for comment indentation. We look at
7118 vhdl-comment-only-line-offset to decide how to indent comment
7119 only-lines."
7120 (save-excursion
7121 (back-to-indentation)
7122 ;; at or to the right of comment-column
7123 (if (>= (current-column) comment-column)
7124 (vhdl-comment-indent)
7125 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7126 (if (not (bolp))
7127 (or (car-safe vhdl-comment-only-line-offset)
7128 vhdl-comment-only-line-offset)
7129 (or (cdr-safe vhdl-comment-only-line-offset)
7130 (car-safe vhdl-comment-only-line-offset)
7131 -1000 ;jam it against the left side
7132 )))))
7134 (defun vhdl-lineup-statement-cont (langelem)
7135 "Line up statement-cont after the assignment operator."
7136 (save-excursion
7137 (let* ((relpos (cdr langelem))
7138 (assignp (save-excursion
7139 (goto-char (vhdl-point 'boi))
7140 (and (re-search-forward "\\(<\\|:\\|=\\)="
7141 (vhdl-point 'eol) t)
7142 (- (point) (vhdl-point 'boi)))))
7143 (curcol (progn
7144 (goto-char relpos)
7145 (current-column)))
7146 foundp)
7147 (while (and (not foundp)
7148 (< (point) (vhdl-point 'eol)))
7149 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7150 (if (vhdl-in-literal)
7151 (forward-char)
7152 (if (= (preceding-char) ?\()
7153 ;; skip over any parenthesized expressions
7154 (goto-char (min (vhdl-point 'eol)
7155 (scan-lists (point) 1 1)))
7156 ;; found an assignment operator (not at eol)
7157 (setq foundp (not (looking-at "\\s-*$"))))))
7158 (if (not foundp)
7159 ;; there's no assignment operator on the line
7160 vhdl-basic-offset
7161 ;; calculate indentation column after assign and ws, unless
7162 ;; our line contains an assignment operator
7163 (if (not assignp)
7164 (progn
7165 (forward-char)
7166 (skip-chars-forward " \t")
7167 (setq assignp 0)))
7168 (- (current-column) assignp curcol))
7171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7172 ;; Progress reporting
7174 (defvar vhdl-progress-info nil
7175 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7177 (defun vhdl-update-progress-info (string pos)
7178 "Update progress information."
7179 (when (and vhdl-progress-info (not noninteractive)
7180 (< vhdl-progress-interval
7181 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7182 (let ((delta (- (aref vhdl-progress-info 1)
7183 (aref vhdl-progress-info 0))))
7184 (if (= 0 delta)
7185 (message (concat string "... (100%s)") "%")
7186 (message (concat string "... (%2d%s)")
7187 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
7188 delta) "%")))
7189 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7191 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7192 ;; Indentation commands
7194 (defun vhdl-electric-tab (&optional prefix-arg)
7195 "If preceding character is part of a word or a paren then hippie-expand,
7196 else if right of non whitespace on line then insert tab,
7197 else if last command was a tab or return then dedent one step or if a comment
7198 toggle between normal indent and inline comment indent,
7199 else indent `correctly'."
7200 (interactive "*P")
7201 (vhdl-prepare-search-2
7202 (cond
7203 ;; indent region if region is active
7204 ((and (not (featurep 'xemacs)) (use-region-p))
7205 (vhdl-indent-region (region-beginning) (region-end) nil))
7206 ;; expand word
7207 ((= (char-syntax (preceding-char)) ?w)
7208 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7209 (case-replace nil)
7210 (hippie-expand-only-buffers
7211 (or (and (boundp 'hippie-expand-only-buffers)
7212 hippie-expand-only-buffers)
7213 '(vhdl-mode))))
7214 (vhdl-expand-abbrev prefix-arg)))
7215 ;; expand parenthesis
7216 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7217 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7218 (case-replace nil))
7219 (vhdl-expand-paren prefix-arg)))
7220 ;; insert tab
7221 ((> (current-column) (current-indentation))
7222 (insert-tab))
7223 ;; toggle comment indent
7224 ((and (looking-at "--")
7225 (or (eq last-command 'vhdl-electric-tab)
7226 (eq last-command 'vhdl-electric-return)))
7227 (cond ((= (current-indentation) 0) ; no indent
7228 (indent-to 1)
7229 (indent-according-to-mode))
7230 ((< (current-indentation) comment-column) ; normal indent
7231 (indent-to comment-column)
7232 (indent-according-to-mode))
7233 (t ; inline comment indent
7234 (delete-region (line-beginning-position) (point)))))
7235 ;; dedent
7236 ((and (>= (current-indentation) vhdl-basic-offset)
7237 (or (eq last-command 'vhdl-electric-tab)
7238 (eq last-command 'vhdl-electric-return)))
7239 (backward-delete-char-untabify vhdl-basic-offset nil))
7240 ;; indent line
7241 (t (indent-according-to-mode)))
7242 (setq this-command 'vhdl-electric-tab)))
7244 (defun vhdl-electric-return ()
7245 "newline-and-indent or indent-new-comment-line if in comment and preceding
7246 character is a space."
7247 (interactive)
7248 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7249 (indent-new-comment-line)
7250 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7251 (not (vhdl-in-comment-p)))
7252 (vhdl-fix-case-word -1))
7253 (newline-and-indent)))
7255 (defun vhdl-indent-line ()
7256 "Indent the current line as VHDL code. Returns the amount of
7257 indentation change."
7258 (interactive)
7259 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7260 (pos (- (point-max) (point)))
7261 (is-comment nil)
7262 (indent
7263 (if syntax
7264 ;; indent syntax-based
7265 (if (and (eq (caar syntax) 'comment)
7266 (>= (vhdl-get-offset (car syntax)) comment-column))
7267 ;; special case: comments at or right of comment-column
7268 (vhdl-get-offset (car syntax))
7269 ;; align comments like following code line
7270 (when vhdl-indent-comment-like-next-code-line
7271 (save-excursion
7272 (while (eq (caar syntax) 'comment)
7273 (setq is-comment t)
7274 (beginning-of-line 2)
7275 (setq syntax (vhdl-get-syntactic-context)))))
7276 (when is-comment
7277 (setq syntax (cons (cons 'comment nil) syntax)))
7278 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7279 ;; indent like previous nonblank line
7280 (save-excursion (beginning-of-line)
7281 (re-search-backward "^[^\n]" nil t)
7282 (current-indentation))))
7283 (shift-amt (- indent (current-indentation))))
7284 (and vhdl-echo-syntactic-information-p
7285 (message "syntax: %s, indent= %d" syntax indent))
7286 (let ((has-formfeed
7287 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7288 (when (or (not (zerop shift-amt)) has-formfeed)
7289 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7290 (beginning-of-line)
7291 (when has-formfeed (insert "\f"))
7292 (indent-to indent)))
7293 (if (< (point) (vhdl-point 'boi))
7294 (back-to-indentation)
7295 ;; If initial point was within line's indentation, position after
7296 ;; the indentation. Else stay at same point in text.
7297 (when (> (- (point-max) pos) (point))
7298 (goto-char (- (point-max) pos))))
7299 (run-hooks 'vhdl-special-indent-hook)
7300 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7301 shift-amt))
7303 (defun vhdl-indent-region (beg end &optional column)
7304 "Indent region as VHDL code.
7305 Adds progress reporting to `indent-region'."
7306 (interactive "r\nP")
7307 (when vhdl-progress-interval
7308 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7309 (count-lines (point-min) end) 0)))
7310 (indent-region beg end column)
7311 (when vhdl-progress-interval (message "Indenting...done"))
7312 (setq vhdl-progress-info nil))
7314 (defun vhdl-indent-buffer ()
7315 "Indent whole buffer as VHDL code.
7316 Calls `indent-region' for whole buffer and adds progress reporting."
7317 (interactive)
7318 (vhdl-indent-region (point-min) (point-max)))
7320 (defun vhdl-indent-group ()
7321 "Indent group of lines between empty lines."
7322 (interactive)
7323 (let ((beg (save-excursion
7324 (if (re-search-backward vhdl-align-group-separate nil t)
7325 (point-marker)
7326 (point-min-marker))))
7327 (end (save-excursion
7328 (if (re-search-forward vhdl-align-group-separate nil t)
7329 (point-marker)
7330 (point-max-marker)))))
7331 (vhdl-indent-region beg end)))
7333 (defun vhdl-indent-sexp (&optional endpos)
7334 "Indent each line of the list starting just after point.
7335 If optional arg ENDPOS is given, indent each line, stopping when
7336 ENDPOS is encountered."
7337 (interactive)
7338 (save-excursion
7339 (let ((beg (point))
7340 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7341 (indent-region beg end nil))))
7343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7344 ;; Miscellaneous commands
7346 (defun vhdl-show-syntactic-information ()
7347 "Show syntactic information for current line."
7348 (interactive)
7349 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7350 (vhdl-keep-region-active))
7352 ;; Verification and regression functions:
7354 (defun vhdl-regress-line (&optional arg)
7355 "Check syntactic information for current line."
7356 (interactive "P")
7357 (let ((expected (save-excursion
7358 (end-of-line)
7359 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7360 (forward-char 4)
7361 (read (current-buffer)))))
7362 (actual (vhdl-get-syntactic-context))
7363 (expurgated))
7364 ;; remove the library unit symbols
7365 (mapc
7366 (function
7367 (lambda (elt)
7368 (if (memq (car elt) '(entity configuration package
7369 package-body architecture))
7371 (setq expurgated (append expurgated (list elt))))))
7372 actual)
7373 (if (and (not arg) expected (listp expected))
7374 (if (not (equal expected expurgated))
7375 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7376 (save-excursion
7377 (beginning-of-line)
7378 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7379 (end-of-line)
7380 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7381 (delete-region (point) (line-end-position)))
7382 (insert " -- ")
7383 (insert (format "%s" expurgated))))))
7384 (vhdl-keep-region-active))
7387 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7388 ;;; Alignment, whitespace fixup, beautifying
7389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7391 (defconst vhdl-align-alist
7393 ;; after some keywords
7394 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7395 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7396 ;; before ':'
7397 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7398 ;; after direction specifications
7399 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7400 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7401 ;; before "==", ":=", "=>", and "<="
7402 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7403 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7404 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7405 ;; before some keywords
7406 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7407 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7408 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7409 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7410 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7411 ;; before "=>" since "when/else ... =>" can occur
7412 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7414 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7415 It is searched in order. If REGEXP is found anywhere in the first
7416 line of a region to be aligned, ALIGN-PATTERN will be used for that
7417 region. ALIGN-PATTERN must include the whitespace to be expanded or
7418 contracted. It may also provide regexps for the text surrounding the
7419 whitespace. SUBEXP specifies which sub-expression of
7420 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7423 ;; Align code
7425 (defvar vhdl-align-try-all-clauses t
7426 "If REGEXP is not found on the first line of the region that clause
7427 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7429 (defun vhdl-do-group (function &optional spacing)
7430 "Apply FUNCTION on group of lines between empty lines."
7431 (let
7432 ;; search for group beginning
7433 ((beg (save-excursion
7434 (if (re-search-backward vhdl-align-group-separate nil t)
7435 (progn (beginning-of-line 2) (back-to-indentation) (point))
7436 (point-min))))
7437 ;; search for group end
7438 (end (save-excursion
7439 (if (re-search-forward vhdl-align-group-separate nil t)
7440 (progn (beginning-of-line) (point))
7441 (point-max)))))
7442 ;; run FUNCTION
7443 (funcall function beg end spacing)))
7445 (defun vhdl-do-list (function &optional spacing)
7446 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7447 parentheses."
7448 (let (beg end)
7449 (save-excursion
7450 ;; search for beginning of balanced group of parentheses
7451 (setq beg (vhdl-re-search-backward "[()]" nil t))
7452 (while (looking-at ")")
7453 (forward-char) (backward-sexp)
7454 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7455 ;; search for end of balanced group of parentheses
7456 (when beg
7457 (forward-list)
7458 (setq end (point))
7459 (goto-char (1+ beg))
7460 (skip-chars-forward " \t\n\r\f")
7461 (setq beg (point))))
7462 ;; run FUNCTION
7463 (if beg
7464 (funcall function beg end spacing)
7465 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7467 (defun vhdl-do-same-indent (function &optional spacing)
7468 "Apply FUNCTION to block of lines with same indent."
7469 (let ((indent (current-indentation))
7470 beg end)
7471 ;; search for first line with same indent
7472 (save-excursion
7473 (while (and (not (bobp))
7474 (or (looking-at "^\\s-*\\(--.*\\)?$")
7475 (= (current-indentation) indent)))
7476 (unless (looking-at "^\\s-*$")
7477 (back-to-indentation) (setq beg (point)))
7478 (beginning-of-line -0)))
7479 ;; search for last line with same indent
7480 (save-excursion
7481 (while (and (not (eobp))
7482 (or (looking-at "^\\s-*\\(--.*\\)?$")
7483 (= (current-indentation) indent)))
7484 (if (looking-at "^\\s-*$")
7485 (beginning-of-line 2)
7486 (beginning-of-line 2)
7487 (setq end (point)))))
7488 ;; run FUNCTION
7489 (funcall function beg end spacing)))
7491 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7492 "Attempt to align a range of lines based on the content of the
7493 lines. The definition of `alignment-list' determines the matching
7494 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7495 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7496 indentation is done before aligning."
7497 (interactive "r\np")
7498 (setq alignment-list (or alignment-list vhdl-align-alist))
7499 (setq spacing (or spacing 1))
7500 (save-excursion
7501 (let (bol indent)
7502 (goto-char end)
7503 (setq end (point-marker))
7504 (goto-char begin)
7505 (setq bol (setq begin (progn (beginning-of-line) (point))))
7506 ; (untabify bol end)
7507 (when indent
7508 (indent-region bol end nil))))
7509 (let ((copy (copy-alist alignment-list)))
7510 (vhdl-prepare-search-2
7511 (while copy
7512 (save-excursion
7513 (goto-char begin)
7514 (let (element
7515 (eol (point-at-eol)))
7516 (setq element (nth 0 copy))
7517 (when (and (or (and (listp (car element))
7518 (memq major-mode (car element)))
7519 (eq major-mode (car element)))
7520 (or vhdl-align-try-all-clauses
7521 (re-search-forward (car (cdr element)) eol t)))
7522 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7523 (car (cdr (cdr (cdr element)))) spacing))
7524 (setq copy (cdr copy))))))))
7526 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7527 "Align a range of lines from BEGIN to END. The regular expression
7528 MATCH must match exactly one field: the whitespace to be
7529 contracted/expanded. The alignment column will equal the
7530 rightmost column of the widest whitespace block. SPACING is
7531 the amount of extra spaces to add to the calculated maximum required.
7532 SPACING defaults to 1 so that at least one space is inserted after
7533 the token in MATCH."
7534 (setq spacing (or spacing 1))
7535 (setq substr (or substr 1))
7536 (save-excursion
7537 (let (distance (max 0) (lines 0) bol eol width)
7538 ;; Determine the greatest whitespace distance to the alignment
7539 ;; character
7540 (goto-char begin)
7541 (setq eol (point-at-eol)
7542 bol (setq begin (progn (beginning-of-line) (point))))
7543 (while (< bol end)
7544 (save-excursion
7545 (when (and (vhdl-re-search-forward match eol t)
7546 (save-excursion
7547 (goto-char (match-beginning 0))
7548 (forward-char)
7549 (and (not (vhdl-in-literal))
7550 (not (vhdl-in-quote-p))
7551 (not (vhdl-in-extended-identifier-p))))
7552 (not (looking-at "\\s-*$")))
7553 (setq distance (- (match-beginning substr) bol))
7554 (when (> distance max)
7555 (setq max distance))))
7556 (forward-line)
7557 (setq bol (point)
7558 eol (point-at-eol))
7559 (setq lines (1+ lines)))
7560 ;; Now insert enough maxs to push each assignment operator to
7561 ;; the same column. We need to use 'lines' as a counter, since
7562 ;; the location of the mark may change
7563 (goto-char (setq bol begin))
7564 (setq eol (point-at-eol))
7565 (while (> lines 0)
7566 (when (and (vhdl-re-search-forward match eol t)
7567 (save-excursion
7568 (goto-char (match-beginning 0))
7569 (forward-char)
7570 (and (not (vhdl-in-literal))
7571 (not (vhdl-in-quote-p))
7572 (not (vhdl-in-extended-identifier-p))))
7573 (not (looking-at "\\s-*$"))
7574 (> (match-beginning 0) ; not if at boi
7575 (save-excursion (back-to-indentation) (point))))
7576 (setq width (- (match-end substr) (match-beginning substr)))
7577 (setq distance (- (match-beginning substr) bol))
7578 (goto-char (match-beginning substr))
7579 (delete-char width)
7580 (insert-char ? (+ (- max distance) spacing)))
7581 (beginning-of-line)
7582 (forward-line)
7583 (setq bol (point)
7584 eol (point-at-eol))
7585 (setq lines (1- lines))))))
7587 (defun vhdl-align-region-groups (beg end &optional spacing
7588 no-message no-comments)
7589 "Align region, treat groups of lines separately."
7590 (interactive "r\nP")
7591 (save-excursion
7592 (let (orig pos)
7593 (goto-char beg)
7594 (beginning-of-line)
7595 (setq orig (point-marker))
7596 (setq beg (point))
7597 (goto-char end)
7598 (setq end (point-marker))
7599 (untabify beg end)
7600 (unless no-message
7601 (when vhdl-progress-interval
7602 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7603 (count-lines (point-min) end) 0))))
7604 (vhdl-fixup-whitespace-region beg end t)
7605 (goto-char beg)
7606 (if (not vhdl-align-groups)
7607 ;; align entire region
7608 (progn (vhdl-align-region-1 beg end spacing)
7609 (unless no-comments
7610 (vhdl-align-inline-comment-region-1 beg end)))
7611 ;; align groups
7612 (while (and (< beg end)
7613 (re-search-forward vhdl-align-group-separate end t))
7614 (setq pos (point-marker))
7615 (vhdl-align-region-1 beg pos spacing)
7616 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7617 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7618 (setq beg (1+ pos))
7619 (goto-char beg))
7620 ;; align last group
7621 (when (< beg end)
7622 (vhdl-align-region-1 beg end spacing)
7623 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7624 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7625 (when vhdl-indent-tabs-mode
7626 (tabify orig end))
7627 (unless no-message
7628 (when vhdl-progress-interval (message "Aligning...done"))
7629 (setq vhdl-progress-info nil)))))
7631 (defun vhdl-align-region (beg end &optional spacing)
7632 "Align region, treat blocks with same indent and argument lists separately."
7633 (interactive "r\nP")
7634 (if (not vhdl-align-same-indent)
7635 ;; align entire region
7636 (vhdl-align-region-groups beg end spacing)
7637 ;; align blocks with same indent and argument lists
7638 (save-excursion
7639 (let ((cur-beg beg)
7640 indent cur-end)
7641 (when vhdl-progress-interval
7642 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7643 (count-lines (point-min) end) 0)))
7644 (goto-char end)
7645 (setq end (point-marker))
7646 (goto-char cur-beg)
7647 (while (< (point) end)
7648 ;; is argument list opening?
7649 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7650 (point) (vhdl-point 'eol)))))
7651 ;; determine region for argument list
7652 (progn (goto-char cur-beg)
7653 (forward-sexp)
7654 (setq cur-end (point))
7655 (beginning-of-line 2))
7656 ;; determine region with same indent
7657 (setq indent (current-indentation))
7658 (setq cur-beg (point))
7659 (setq cur-end (vhdl-point 'bonl))
7660 (beginning-of-line 2)
7661 (while (and (< (point) end)
7662 (or (looking-at "^\\s-*\\(--.*\\)?$")
7663 (= (current-indentation) indent))
7664 (<= (save-excursion
7665 (nth 0 (parse-partial-sexp
7666 (point) (vhdl-point 'eol)))) 0))
7667 (unless (looking-at "^\\s-*$")
7668 (setq cur-end (vhdl-point 'bonl)))
7669 (beginning-of-line 2)))
7670 ;; align region
7671 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7672 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7673 (when vhdl-progress-interval (message "Aligning...done"))
7674 (setq vhdl-progress-info nil)))))
7676 (defun vhdl-align-group (&optional spacing)
7677 "Align group of lines between empty lines."
7678 (interactive)
7679 (vhdl-do-group 'vhdl-align-region spacing))
7681 (defun vhdl-align-list (&optional spacing)
7682 "Align the lines of a list surrounded by a balanced group of parentheses."
7683 (interactive)
7684 (vhdl-do-list 'vhdl-align-region-groups spacing))
7686 (defun vhdl-align-same-indent (&optional spacing)
7687 "Align block of lines with same indent."
7688 (interactive)
7689 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7691 (defun vhdl-align-declarations (&optional spacing)
7692 "Align the lines within the declarative part of a design unit."
7693 (interactive)
7694 (let (beg end)
7695 (vhdl-prepare-search-2
7696 (save-excursion
7697 ;; search for declarative part
7698 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7699 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7700 (setq beg (point))
7701 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7702 (setq end (point)))))
7703 (if beg
7704 (vhdl-align-region-groups beg end spacing)
7705 (error "ERROR: Not within the declarative part of a design unit"))))
7707 (defun vhdl-align-buffer ()
7708 "Align buffer."
7709 (interactive)
7710 (vhdl-align-region (point-min) (point-max)))
7712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7713 ;; Align inline comments
7715 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7716 "Align inline comments in region."
7717 (save-excursion
7718 (let ((start-max comment-column)
7719 (length-max 0)
7720 comment-list start-list tmp-list start length
7721 cur-start prev-start no-code)
7722 (setq spacing (or spacing 2))
7723 (vhdl-prepare-search-2
7724 (goto-char beg)
7725 ;; search for comment start positions and lengths
7726 (while (< (point) end)
7727 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7728 (looking-at "^\\(.*[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7729 (not (save-excursion (goto-char (match-beginning 2))
7730 (vhdl-in-literal))))
7731 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7732 (setq length (- (match-end 2) (match-beginning 2)))
7733 (setq start-max (max start start-max))
7734 (setq length-max (max length length-max))
7735 (setq comment-list (cons (cons start length) comment-list)))
7736 (beginning-of-line 2))
7737 (setq comment-list
7738 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7739 ;; reduce start positions
7740 (setq start-list (list (caar comment-list)))
7741 (setq comment-list (cdr comment-list))
7742 (while comment-list
7743 (unless (or (= (caar comment-list) (car start-list))
7744 (<= (+ (car start-list) (cdar comment-list))
7745 end-comment-column))
7746 (setq start-list (cons (caar comment-list) start-list)))
7747 (setq comment-list (cdr comment-list)))
7748 ;; align lines as nicely as possible
7749 (goto-char beg)
7750 (while (< (point) end)
7751 (setq cur-start nil)
7752 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7753 (or (and (looking-at "^\\(.*[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7754 (not (save-excursion
7755 (goto-char (match-beginning 3))
7756 (vhdl-in-literal))))
7757 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7758 (>= (- (match-end 2) (match-beginning 2))
7759 comment-column))))
7760 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7761 (setq length (- (match-end 3) (match-beginning 3)))
7762 (setq no-code (= (match-beginning 1) (match-end 1)))
7763 ;; insert minimum whitespace
7764 (goto-char (match-end 2))
7765 (delete-region (match-beginning 2) (match-end 2))
7766 (insert-char ?\ spacing)
7767 (setq tmp-list start-list)
7768 ;; insert additional whitespace to align
7769 (setq cur-start
7770 (cond
7771 ;; align comment-only line to inline comment of previous line
7772 ((and no-code prev-start
7773 (<= length (- end-comment-column prev-start)))
7774 prev-start)
7775 ;; align all comments at `start-max' if this is possible
7776 ((<= (+ start-max length-max) end-comment-column)
7777 start-max)
7778 ;; align at `comment-column' if possible
7779 ((and (<= start comment-column)
7780 (<= length (- end-comment-column comment-column)))
7781 comment-column)
7782 ;; align at left-most possible start position otherwise
7784 (while (and tmp-list (< (car tmp-list) start))
7785 (setq tmp-list (cdr tmp-list)))
7786 (car tmp-list))))
7787 (indent-to cur-start))
7788 (setq prev-start cur-start)
7789 (beginning-of-line 2))))))
7791 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7792 "Align inline comments within a region. Groups of code lines separated by
7793 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7794 (interactive "r\nP")
7795 (save-excursion
7796 (let (orig pos)
7797 (goto-char beg)
7798 (beginning-of-line)
7799 (setq orig (point-marker))
7800 (setq beg (point))
7801 (goto-char end)
7802 (setq end (point-marker))
7803 (untabify beg end)
7804 (unless no-message (message "Aligning inline comments..."))
7805 (goto-char beg)
7806 (if (not vhdl-align-groups)
7807 ;; align entire region
7808 (vhdl-align-inline-comment-region-1 beg end spacing)
7809 ;; align groups
7810 (while (and (< beg end)
7811 (re-search-forward vhdl-align-group-separate end t))
7812 (setq pos (point-marker))
7813 (vhdl-align-inline-comment-region-1 beg pos spacing)
7814 (setq beg (1+ pos))
7815 (goto-char beg))
7816 ;; align last group
7817 (when (< beg end)
7818 (vhdl-align-inline-comment-region-1 beg end spacing)))
7819 (when vhdl-indent-tabs-mode
7820 (tabify orig end))
7821 (unless no-message (message "Aligning inline comments...done")))))
7823 (defun vhdl-align-inline-comment-group (&optional spacing)
7824 "Align inline comments within a group of lines between empty lines."
7825 (interactive)
7826 (save-excursion
7827 (let ((start (point))
7828 beg end)
7829 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7830 (point-marker) (point-max)))
7831 (goto-char start)
7832 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7833 (point) (point-min)))
7834 (untabify beg end)
7835 (message "Aligning inline comments...")
7836 (vhdl-align-inline-comment-region-1 beg end)
7837 (when vhdl-indent-tabs-mode
7838 (tabify beg end))
7839 (message "Aligning inline comments...done"))))
7841 (defun vhdl-align-inline-comment-buffer ()
7842 "Align inline comments within buffer. Groups of code lines separated by
7843 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7844 (interactive)
7845 (vhdl-align-inline-comment-region (point-min) (point-max)))
7847 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7848 ;; Fixup whitespace
7850 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7851 "Fixup whitespace in region. Surround operator symbols by one space,
7852 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7853 end of line, do nothing in comments and strings."
7854 (interactive "r")
7855 (unless no-message (message "Fixing up whitespace..."))
7856 (save-excursion
7857 (goto-char end)
7858 (setq end (point-marker))
7859 ;; have no space before and one space after `,' and ';'
7860 (goto-char beg)
7861 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7862 (if (match-string 1)
7863 (goto-char (match-end 1))
7864 (replace-match "\\3 " nil nil nil 2)))
7865 ;; have no space after `('
7866 (goto-char beg)
7867 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
7868 (if (match-string 1)
7869 (goto-char (match-end 1))
7870 (replace-match "\\2")))
7871 ;; have no space before `)'
7872 (goto-char beg)
7873 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7874 (if (match-string 1)
7875 (goto-char (match-end 1))
7876 (replace-match "\\2")))
7877 ;; surround operator symbols by one space
7878 (goto-char beg)
7879 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>]\\|$\\)\\)" end t)
7880 (if (or (match-string 1)
7881 (<= (match-beginning 0) ; not if at boi
7882 (save-excursion (back-to-indentation) (point))))
7883 (goto-char (match-end 0))
7884 (replace-match "\\3 \\4 \\5")
7885 (goto-char (match-end 2))))
7886 ;; eliminate multiple spaces and spaces at end of line
7887 (goto-char beg)
7888 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7889 (and (looking-at "--.*") (re-search-forward "--.*" end t))
7890 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7891 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7892 (progn (replace-match "" nil nil) t))
7893 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7894 (progn (replace-match ";" nil nil) t))
7895 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7896 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7897 (progn (replace-match " " nil nil) t))
7898 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7899 (progn (replace-match " " nil nil) t))
7900 (and (looking-at "-") (re-search-forward "-" end t))
7901 ; (re-search-forward "[^ \t-]+" end t))))
7902 (re-search-forward "[^ \t\"-]+" end t))))
7903 (unless no-message (message "Fixing up whitespace...done")))
7905 (defun vhdl-fixup-whitespace-buffer ()
7906 "Fixup whitespace in buffer. Surround operator symbols by one space,
7907 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7908 end of line, do nothing in comments."
7909 (interactive)
7910 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7912 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7913 ;; Beautify
7915 (defun vhdl-beautify-region (beg end)
7916 "Beautify region by applying indentation, whitespace fixup, alignment, and
7917 case fixing to a region. Calls functions `vhdl-indent-buffer',
7918 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7919 `vhdl-fix-case-buffer'."
7920 (interactive "r")
7921 (setq end (save-excursion (goto-char end) (point-marker)))
7922 (vhdl-indent-region beg end)
7923 (let ((vhdl-align-groups t))
7924 (vhdl-align-region beg end))
7925 (vhdl-fix-case-region beg end))
7927 (defun vhdl-beautify-buffer ()
7928 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7929 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7930 buffer."
7931 (interactive)
7932 (vhdl-beautify-region (point-min) (point-max))
7933 (when noninteractive (save-buffer)))
7935 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7936 ;; Code filling
7938 (defun vhdl-fill-region (beg end &optional arg)
7939 "Fill lines for a region of code."
7940 (interactive "r\np")
7941 (save-excursion
7942 (goto-char beg)
7943 (let ((margin (if arg (current-indentation) (current-column))))
7944 (goto-char end)
7945 (setq end (point-marker))
7946 ;; remove inline comments, newlines and whitespace
7947 (vhdl-comment-kill-region beg end)
7948 (vhdl-comment-kill-inline-region beg end)
7949 (subst-char-in-region beg (1- end) ?\n ?\ )
7950 (vhdl-fixup-whitespace-region beg end)
7951 ;; wrap and end-comment-column
7952 (goto-char beg)
7953 (while (re-search-forward "\\s-" end t)
7954 (when(> (current-column) vhdl-end-comment-column)
7955 (backward-char)
7956 (when (re-search-backward "\\s-" beg t)
7957 (replace-match "\n")
7958 (indent-to margin)))))))
7960 (defun vhdl-fill-group ()
7961 "Fill group of lines between empty lines."
7962 (interactive)
7963 (vhdl-do-group 'vhdl-fill-region))
7965 (defun vhdl-fill-list ()
7966 "Fill the lines of a list surrounded by a balanced group of parentheses."
7967 (interactive)
7968 (vhdl-do-list 'vhdl-fill-region))
7970 (defun vhdl-fill-same-indent ()
7971 "Fill the lines of block of lines with same indent."
7972 (interactive)
7973 (vhdl-do-same-indent 'vhdl-fill-region))
7976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7977 ;;; Code updating/fixing
7978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7981 ;; Sensitivity list update
7983 ;; Strategy:
7984 ;; - no sensitivity list is generated for processes with wait statements
7985 ;; - otherwise, do the following:
7986 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7987 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7988 ;; manually entered global signals)
7989 ;; 3. signals from 1. and 2. form the list of visible signals
7990 ;; 4. search for if/elsif conditions containing an event (sequential code)
7991 ;; 5. scan for strings that are within syntactical regions where signals are
7992 ;; read but not within sequential code, and that correspond to visible
7993 ;; signals
7994 ;; 6. replace sensitivity list by list of signals from 5.
7996 (defun vhdl-update-sensitivity-list-process ()
7997 "Update sensitivity list of current process."
7998 (interactive)
7999 (save-excursion
8000 (vhdl-prepare-search-2
8001 (end-of-line)
8002 ;; look whether in process
8003 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8004 (equal (upcase (match-string 2)) "PROCESS")
8005 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8006 (error "ERROR: Not within a process")
8007 (message "Updating sensitivity list...")
8008 (vhdl-update-sensitivity-list)
8009 (message "Updating sensitivity list...done")))))
8011 (defun vhdl-update-sensitivity-list-buffer ()
8012 "Update sensitivity list of all processes in current buffer."
8013 (interactive)
8014 (save-excursion
8015 (vhdl-prepare-search-2
8016 (goto-char (point-min))
8017 (message "Updating sensitivity lists...")
8018 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8019 (goto-char (match-beginning 0))
8020 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8021 (message "Updating sensitivity lists...done"))))
8023 (defun vhdl-update-sensitivity-list ()
8024 "Update sensitivity list."
8025 (let ((proc-beg (point))
8026 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8027 (proc-mid (vhdl-re-search-backward
8028 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8029 seq-region-list)
8030 (cond
8031 ;; error if 'begin' keyword missing
8032 ((not (match-string 2))
8033 (error "ERROR: No 'begin' keyword found"))
8034 ;; search for wait statement (no sensitivity list allowed)
8035 ((progn (goto-char proc-mid)
8036 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8037 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8038 ;; combinational process (update sensitivity list)
8040 (let
8041 ;; scan for visible signals
8042 ((visible-list (vhdl-get-visible-signals))
8043 ;; define syntactic regions where signals are read
8044 (scan-regions-list
8045 '(;; right-hand side of signal/variable assignment
8046 ;; (special case: "<=" is relational operator in a condition)
8047 ((re-search-forward "[<:]=" proc-end t)
8048 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8049 ;; if condition
8050 ((re-search-forward "^\\s-*if\\>" proc-end t)
8051 (re-search-forward "\\<then\\>" proc-end t))
8052 ;; elsif condition
8053 ((re-search-forward "\\<elsif\\>" proc-end t)
8054 (re-search-forward "\\<then\\>" proc-end t))
8055 ;; while loop condition
8056 ((re-search-forward "^\\s-*while\\>" proc-end t)
8057 (re-search-forward "\\<loop\\>" proc-end t))
8058 ;; exit/next condition
8059 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8060 (re-search-forward ";" proc-end t))
8061 ;; assert condition
8062 ((re-search-forward "\\<assert\\>" proc-end t)
8063 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8064 ;; case expression
8065 ((re-search-forward "^\\s-*case\\>" proc-end t)
8066 (re-search-forward "\\<is\\>" proc-end t))
8067 ;; parameter list of procedure call, array index
8068 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8069 (1- (point)))
8070 (progn (backward-char) (forward-sexp)
8071 (while (looking-at "(") (forward-sexp)) (point)))))
8072 name field read-list sens-list signal-list
8073 sens-beg sens-end beg end margin)
8074 ;; scan for signals in old sensitivity list
8075 (goto-char proc-beg)
8076 (re-search-forward "\\<process\\>" proc-mid t)
8077 (if (not (looking-at "[ \t\n\r\f]*("))
8078 (setq sens-beg (point))
8079 (setq sens-beg (re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8080 (goto-char (match-end 1))
8081 (forward-sexp)
8082 (setq sens-end (1- (point)))
8083 (goto-char sens-beg)
8084 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
8085 (setq sens-list
8086 (cons (downcase (match-string 0)) sens-list))
8087 (re-search-forward "\\s-*,\\s-*" sens-end t))))
8088 (setq signal-list (append visible-list sens-list))
8089 ;; search for sequential parts
8090 (goto-char proc-mid)
8091 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8092 (setq end (re-search-forward "\\<then\\>" proc-end t))
8093 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8094 (goto-char end)
8095 (backward-word 1)
8096 (vhdl-forward-sexp)
8097 (setq seq-region-list (cons (cons end (point)) seq-region-list))
8098 (beginning-of-line)))
8099 ;; scan for signals read in process
8100 (while scan-regions-list
8101 (goto-char proc-mid)
8102 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8103 (setq end (eval (nth 1 (car scan-regions-list)))))
8104 (goto-char beg)
8105 (unless (or (vhdl-in-literal)
8106 (and seq-region-list
8107 (let ((tmp-list seq-region-list))
8108 (while (and tmp-list
8109 (< (point) (caar tmp-list)))
8110 (setq tmp-list (cdr tmp-list)))
8111 (and tmp-list (< (point) (cdar tmp-list))))))
8112 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8113 (setq name (match-string 1))
8114 (when vhdl-array-index-record-field-in-sensitivity-list
8115 (setq field (match-string 2)))
8116 (when (and (not (match-string 6)) ; not when formal parameter
8117 (not (and (match-string 5) ; not event attribute
8118 (not (member (downcase (match-string 5))
8119 '("event" "last_event" "transaction")))))
8120 (member (downcase name) signal-list))
8121 (unless (member-ignore-case (concat name field) read-list)
8122 (setq read-list (cons (concat name field) read-list))))
8123 (goto-char (match-end 1)))))
8124 (setq scan-regions-list (cdr scan-regions-list)))
8125 ;; update sensitivity list
8126 (goto-char sens-beg)
8127 (if sens-end
8128 (delete-region sens-beg sens-end)
8129 (when read-list
8130 (insert " ()") (backward-char)))
8131 (setq read-list (sort read-list 'string<))
8132 (when read-list
8133 (setq margin (current-column))
8134 (insert (car read-list))
8135 (setq read-list (cdr read-list))
8136 (while read-list
8137 (insert ",")
8138 (if (<= (+ (current-column) (length (car read-list)) 2)
8139 end-comment-column)
8140 (insert " ")
8141 (insert "\n") (indent-to margin))
8142 (insert (car read-list))
8143 (setq read-list (cdr read-list)))))))))
8145 (defun vhdl-get-visible-signals ()
8146 "Get all signals visible in the current block."
8147 (let (beg end signal-list entity-name file-name)
8148 (vhdl-prepare-search-2
8149 ;; get entity name
8150 (save-excursion
8151 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8152 (not (equal "END" (upcase (match-string 1))))
8153 (setq entity-name (match-string 2)))
8154 (error "ERROR: Not within an architecture")))
8155 ;; search for signals declared in entity port clause
8156 (save-excursion
8157 (goto-char (point-min))
8158 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8159 (setq file-name
8160 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8161 "." (file-name-extension (buffer-file-name)))))
8162 (vhdl-visit-file
8163 file-name t
8164 (vhdl-prepare-search-2
8165 (goto-char (point-min))
8166 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8167 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8168 (when (setq beg (vhdl-re-search-forward
8169 "\\<port[ \t\n\r\f]*("
8170 (save-excursion
8171 (re-search-forward "^end\\>" nil t)) t))
8172 (setq end (save-excursion
8173 (backward-char) (forward-sexp) (point)))
8174 (vhdl-forward-syntactic-ws)
8175 (while (< (point) end)
8176 (when (looking-at "signal[ \t\n\r\f]+")
8177 (goto-char (match-end 0)))
8178 (while (looking-at "\\(\\w+\\)[ \t\n\r\f,]+")
8179 (setq signal-list
8180 (cons (downcase (match-string 1)) signal-list))
8181 (goto-char (match-end 0))
8182 (vhdl-forward-syntactic-ws))
8183 (re-search-forward ";" end 1)
8184 (vhdl-forward-syntactic-ws)))))))
8185 ;; search for signals declared in architecture declarative part
8186 (save-excursion
8187 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8188 (not (equal "END" (upcase (match-string 1))))
8189 (setq end (re-search-forward "^begin\\>" nil t))))
8190 (error "ERROR: No architecture declarative part found")
8191 ;; scan for all declared signal and alias names
8192 (goto-char beg)
8193 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8194 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8195 (if (match-string 2)
8196 ;; scan signal name
8197 (while (looking-at "[ \t\n\r\f,]+\\(\\w+\\)")
8198 (setq signal-list
8199 (cons (downcase (match-string 1)) signal-list))
8200 (goto-char (match-end 0)))
8201 ;; scan alias name, check is alias of (declared) signal
8202 (when (and (looking-at "[ \t\n\r\f]+\\(\\w+\\)[^;]*\\<is[ \t\n\r\f]+\\(\\w+\\)")
8203 (member (downcase (match-string 2)) signal-list))
8204 (setq signal-list
8205 (cons (downcase (match-string 1)) signal-list))
8206 (goto-char (match-end 0))))
8207 (setq beg (point))))))
8208 ;; search for signals declared in surrounding block declarative parts
8209 (save-excursion
8210 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
8211 (match-string 2))
8212 (goto-char (match-end 2))
8213 (vhdl-backward-sexp)
8214 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
8215 beg)
8216 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8217 ;; scan for all declared signal names
8218 (goto-char beg)
8219 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8220 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8221 (if (match-string 2)
8222 ;; scan signal name
8223 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8224 (setq signal-list
8225 (cons (downcase (match-string 1)) signal-list))
8226 (goto-char (match-end 0)))
8227 ;; scan alias name, check is alias of (declared) signal
8228 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8229 (member (downcase (match-string 2)) signal-list))
8230 (setq signal-list
8231 (cons (downcase (match-string 1)) signal-list))
8232 (goto-char (match-end 0))))))
8233 (goto-char beg)))
8234 signal-list)))
8236 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8237 ;; Generic/port clause fixing
8239 (defun vhdl-fix-clause-buffer ()
8240 "Fix all generic/port clauses in current buffer."
8241 (interactive)
8242 (save-excursion
8243 (vhdl-prepare-search-2
8244 (goto-char (point-min))
8245 (message "Fixing generic/port clauses...")
8246 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8247 (goto-char (match-end 0))
8248 (condition-case nil (vhdl-fix-clause) (error "")))
8249 (message "Fixing generic/port clauses...done"))))
8251 (defun vhdl-fix-clause ()
8252 "Fix closing parenthesis within generic/port clause."
8253 (interactive)
8254 (save-excursion
8255 (vhdl-prepare-search-2
8256 (let ((pos (point))
8257 beg end)
8258 (end-of-line)
8259 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8260 (error "ERROR: Not within a generic/port clause")
8261 ;; search for end of clause
8262 (goto-char (match-end 0))
8263 (setq beg (1- (point)))
8264 (vhdl-forward-syntactic-ws)
8265 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8266 (goto-char (1- (match-end 0)))
8267 (setq end (point-marker))
8268 (forward-char)
8269 (vhdl-forward-syntactic-ws))
8270 (goto-char end)
8271 (when (> pos (point-at-eol))
8272 (error "ERROR: Not within a generic/port clause"))
8273 ;; delete closing parenthesis on separate line (not supported style)
8274 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8275 (vhdl-line-kill)
8276 (vhdl-backward-syntactic-ws)
8277 (setq end (point-marker))
8278 (insert ";"))
8279 ;; delete superfluous parentheses
8280 (while (progn (goto-char beg)
8281 (condition-case () (forward-sexp)
8282 (error (goto-char (point-max))))
8283 (< (point) end))
8284 (delete-char -1))
8285 ;; add closing parenthesis
8286 (when (> (point) end)
8287 (goto-char end)
8288 (insert ")")))))))
8290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8291 ;; Miscellaneous
8293 (defun vhdl-remove-trailing-spaces ()
8294 "Remove trailing spaces in the whole buffer."
8295 (interactive)
8296 (save-match-data
8297 (save-excursion
8298 (goto-char (point-min))
8299 (while (re-search-forward "[ \t]+$" (point-max) t)
8300 (unless (vhdl-in-literal)
8301 (replace-match "" nil nil))))))
8304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8305 ;;; Electrification
8306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8308 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8309 "Syntax of prompt inserted by template generators.")
8311 (defvar vhdl-template-invoked-by-hook nil
8312 "Indicates whether a template has been invoked by a hook or by key or menu.
8313 Used for undoing after template abortion.")
8315 ;; correct different behavior of function `unread-command-events' in XEmacs
8316 (defun vhdl-character-to-event (arg))
8317 (defalias 'vhdl-character-to-event
8318 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8320 (defun vhdl-work-library ()
8321 "Return the working library name of the current project or \"work\" if no
8322 project is defined."
8323 (vhdl-resolve-env-variable
8324 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8326 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8327 ;; Enabling/disabling
8329 (define-minor-mode vhdl-electric-mode
8330 "Toggle VHDL electric mode.
8331 With a prefix argument ARG, enable the mode if ARG is positive,
8332 and disable it otherwise. If called from Lisp, enable it if ARG
8333 is omitted or nil."
8334 :global t)
8336 (define-minor-mode vhdl-stutter-mode
8337 "Toggle VHDL stuttering mode.
8338 With a prefix argument ARG, enable the mode if ARG is positive,
8339 and disable it otherwise. If called from Lisp, enable it if ARG
8340 is omitted or nil."
8341 :global t)
8343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8344 ;; Stuttering
8346 (defun vhdl-electric-dash (count)
8347 "-- starts a comment, --- draws a horizontal line,
8348 ---- starts a display comment."
8349 (interactive "p")
8350 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8351 (cond
8352 ((and abbrev-start-location (= abbrev-start-location (point)))
8353 (setq abbrev-start-location nil)
8354 (goto-char last-abbrev-location)
8355 (beginning-of-line nil)
8356 (vhdl-comment-display))
8357 ((/= (preceding-char) ?-) ; standard dash (minus)
8358 (self-insert-command count))
8359 (t (self-insert-command count)
8360 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8361 (let ((next-input (read-char)))
8362 (if (= next-input ?-) ; triple dash
8363 (progn
8364 (vhdl-comment-display-line)
8365 (message
8366 "Enter '-' for display comment, else continue coding")
8367 (let ((next-input (read-char)))
8368 (if (= next-input ?-) ; four dashes
8369 (vhdl-comment-display t)
8370 (setq unread-command-events ; pushback the char
8371 (list (vhdl-character-to-event next-input))))))
8372 (setq unread-command-events ; pushback the char
8373 (list (vhdl-character-to-event next-input)))
8374 (vhdl-comment-insert)))))
8375 (self-insert-command count)))
8377 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8378 (interactive "p")
8379 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8380 (if (= (preceding-char) ?\()
8381 (progn (delete-char -1) (insert-char ?\[ 1))
8382 (insert-char ?\( 1))
8383 (self-insert-command count)))
8385 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8386 (interactive "p")
8387 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8388 (progn
8389 (if (= (preceding-char) ?\))
8390 (progn (delete-char -1) (insert-char ?\] 1))
8391 (insert-char ?\) 1))
8392 (blink-matching-open))
8393 (self-insert-command count)))
8395 (defun vhdl-electric-quote (count) "'' --> \""
8396 (interactive "p")
8397 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8398 (if (= (preceding-char) last-input-event)
8399 (progn (delete-char -1) (insert-char ?\" 1))
8400 (insert-char ?\' 1))
8401 (self-insert-command count)))
8403 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8404 (interactive "p")
8405 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8406 (cond ((= (preceding-char) last-input-event)
8407 (progn (delete-char -1)
8408 (unless (eq (preceding-char) ? ) (insert " "))
8409 (insert ": ")
8410 (setq this-command 'vhdl-electric-colon)))
8411 ((and
8412 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8413 (progn (delete-char -1) (insert "= ")))
8414 (t (insert-char ?\; 1)))
8415 (self-insert-command count)))
8417 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8418 (interactive "p")
8419 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8420 (cond ((= (preceding-char) last-input-event)
8421 (progn (delete-char -1)
8422 (unless (eq (preceding-char) ? ) (insert " "))
8423 (insert "<= ")))
8424 (t (insert-char ?\, 1)))
8425 (self-insert-command count)))
8427 (defun vhdl-electric-period (count) "'..' --> ' => '"
8428 (interactive "p")
8429 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8430 (cond ((= (preceding-char) last-input-event)
8431 (progn (delete-char -1)
8432 (unless (eq (preceding-char) ? ) (insert " "))
8433 (insert "=> ")))
8434 (t (insert-char ?\. 1)))
8435 (self-insert-command count)))
8437 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8438 (interactive "p")
8439 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8440 (cond ((= (preceding-char) last-input-event)
8441 (progn (delete-char -1)
8442 (unless (eq (preceding-char) ? ) (insert " "))
8443 (insert "== ")))
8444 (t (insert-char ?\= 1)))
8445 (self-insert-command count)))
8447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8448 ;; VHDL templates
8450 (defun vhdl-template-paired-parens ()
8451 "Insert a pair of round parentheses, placing point between them."
8452 (interactive)
8453 (insert "()")
8454 (backward-char))
8456 (defun vhdl-template-alias ()
8457 "Insert alias declaration."
8458 (interactive)
8459 (let ((start (point)))
8460 (vhdl-insert-keyword "ALIAS ")
8461 (when (vhdl-template-field "name" nil t start (point))
8462 (insert " : ")
8463 (unless (vhdl-template-field
8464 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8465 nil t)
8466 (delete-char -3))
8467 (vhdl-insert-keyword " IS ")
8468 (vhdl-template-field "name" ";")
8469 (vhdl-comment-insert-inline))))
8471 (defun vhdl-template-architecture ()
8472 "Insert architecture."
8473 (interactive)
8474 (let ((margin (current-indentation))
8475 (start (point))
8476 arch-name)
8477 (vhdl-insert-keyword "ARCHITECTURE ")
8478 (when (setq arch-name
8479 (vhdl-template-field "name" nil t start (point)))
8480 (vhdl-insert-keyword " OF ")
8481 (if (save-excursion
8482 (vhdl-prepare-search-1
8483 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8484 (insert (match-string 1))
8485 (vhdl-template-field "entity name"))
8486 (vhdl-insert-keyword " IS\n")
8487 (vhdl-template-begin-end
8488 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8489 (memq vhdl-insert-empty-lines '(unit all))))))
8491 (defun vhdl-template-array (kind &optional secondary)
8492 "Insert array type definition."
8493 (interactive)
8494 (let ((start (point)))
8495 (vhdl-insert-keyword "ARRAY (")
8496 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8497 secondary)
8498 (vhdl-insert-keyword ") OF ")
8499 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8500 (vhdl-insert-keyword ";"))))
8502 (defun vhdl-template-assert ()
8503 "Insert an assertion statement."
8504 (interactive)
8505 (let ((start (point)))
8506 (vhdl-insert-keyword "ASSERT ")
8507 (when vhdl-conditions-in-parenthesis (insert "("))
8508 (when (vhdl-template-field "condition (negated)" nil t start (point))
8509 (when vhdl-conditions-in-parenthesis (insert ")"))
8510 (setq start (point))
8511 (vhdl-insert-keyword " REPORT ")
8512 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8513 (delete-region start (point)))
8514 (setq start (point))
8515 (vhdl-insert-keyword " SEVERITY ")
8516 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8517 (delete-region start (point)))
8518 (insert ";"))))
8520 (defun vhdl-template-attribute ()
8521 "Insert an attribute declaration or specification."
8522 (interactive)
8523 (if (eq (vhdl-decision-query
8524 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8525 (vhdl-template-attribute-spec)
8526 (vhdl-template-attribute-decl)))
8528 (defun vhdl-template-attribute-decl ()
8529 "Insert an attribute declaration."
8530 (interactive)
8531 (let ((start (point)))
8532 (vhdl-insert-keyword "ATTRIBUTE ")
8533 (when (vhdl-template-field "name" " : " t start (point))
8534 (vhdl-template-field "type" ";")
8535 (vhdl-comment-insert-inline))))
8537 (defun vhdl-template-attribute-spec ()
8538 "Insert an attribute specification."
8539 (interactive)
8540 (let ((start (point)))
8541 (vhdl-insert-keyword "ATTRIBUTE ")
8542 (when (vhdl-template-field "name" nil t start (point))
8543 (vhdl-insert-keyword " OF ")
8544 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8545 (vhdl-template-field "entity class")
8546 (vhdl-insert-keyword " IS ")
8547 (vhdl-template-field "expression" ";"))))
8549 (defun vhdl-template-block ()
8550 "Insert a block."
8551 (interactive)
8552 (let ((margin (current-indentation))
8553 (start (point))
8554 label)
8555 (vhdl-insert-keyword ": BLOCK ")
8556 (goto-char start)
8557 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8558 (forward-word 1)
8559 (forward-char 1)
8560 (insert "(")
8561 (if (vhdl-template-field "[guard expression]" nil t)
8562 (insert ")")
8563 (delete-char -2))
8564 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8565 (insert "\n")
8566 (vhdl-template-begin-end "BLOCK" label margin)
8567 (vhdl-comment-block))))
8569 (defun vhdl-template-block-configuration ()
8570 "Insert a block configuration statement."
8571 (interactive)
8572 (let ((margin (current-indentation))
8573 (start (point)))
8574 (vhdl-insert-keyword "FOR ")
8575 (when (vhdl-template-field "block name" nil t start (point))
8576 (vhdl-insert-keyword "\n\n")
8577 (indent-to margin)
8578 (vhdl-insert-keyword "END FOR;")
8579 (end-of-line 0)
8580 (indent-to (+ margin vhdl-basic-offset)))))
8582 (defun vhdl-template-break ()
8583 "Insert a break statement."
8584 (interactive)
8585 (let (position)
8586 (vhdl-insert-keyword "BREAK")
8587 (setq position (point))
8588 (insert " ")
8589 (while (or
8590 (progn (vhdl-insert-keyword "FOR ")
8591 (if (vhdl-template-field "[quantity name]" " USE " t)
8592 (progn (vhdl-template-field "quantity name" " => ") t)
8593 (delete-region (point)
8594 (progn (forward-word -1) (point)))
8595 nil))
8596 (vhdl-template-field "[quantity name]" " => " t))
8597 (vhdl-template-field "expression")
8598 (setq position (point))
8599 (insert ", "))
8600 (delete-region position (point))
8601 (unless (vhdl-sequential-statement-p)
8602 (vhdl-insert-keyword " ON ")
8603 (if (vhdl-template-field "[sensitivity list]" nil t)
8604 (setq position (point))
8605 (delete-region position (point))))
8606 (vhdl-insert-keyword " WHEN ")
8607 (when vhdl-conditions-in-parenthesis (insert "("))
8608 (if (vhdl-template-field "[condition]" nil t)
8609 (when vhdl-conditions-in-parenthesis (insert ")"))
8610 (delete-region position (point)))
8611 (insert ";")))
8613 (defun vhdl-template-case (&optional kind)
8614 "Insert a case statement."
8615 (interactive)
8616 (let ((margin (current-indentation))
8617 (start (point))
8618 label)
8619 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
8620 (not (vhdl-standard-p 'ams))) 'is 'use)))
8621 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8622 (vhdl-insert-keyword "CASE ")
8623 (vhdl-insert-keyword ": CASE ")
8624 (goto-char start)
8625 (setq label (vhdl-template-field "[label]" nil t))
8626 (unless label (delete-char 2))
8627 (forward-word 1)
8628 (forward-char 1))
8629 (when (vhdl-template-field "expression" nil t start (point))
8630 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8631 (indent-to margin)
8632 (vhdl-insert-keyword "END CASE")
8633 (when label (insert " " label))
8634 (insert ";")
8635 (forward-line -1)
8636 (indent-to (+ margin vhdl-basic-offset))
8637 (vhdl-insert-keyword "WHEN ")
8638 (let ((position (point)))
8639 (insert " => ;\n")
8640 (indent-to (+ margin vhdl-basic-offset))
8641 (vhdl-insert-keyword "WHEN OTHERS => null;")
8642 (goto-char position)))))
8644 (defun vhdl-template-case-is ()
8645 "Insert a sequential case statement."
8646 (interactive)
8647 (vhdl-template-case 'is))
8649 (defun vhdl-template-case-use ()
8650 "Insert a simultaneous case statement."
8651 (interactive)
8652 (vhdl-template-case 'use))
8654 (defun vhdl-template-component ()
8655 "Insert a component declaration."
8656 (interactive)
8657 (vhdl-template-component-decl))
8659 (defun vhdl-template-component-conf ()
8660 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8661 since these are almost equivalent)."
8662 (interactive)
8663 (let ((margin (current-indentation))
8664 (result (vhdl-template-configuration-spec t)))
8665 (when result
8666 (insert "\n")
8667 (indent-to margin)
8668 (vhdl-insert-keyword "END FOR;")
8669 (when (eq result 'no-use)
8670 (end-of-line -0)))))
8672 (defun vhdl-template-component-decl ()
8673 "Insert a component declaration."
8674 (interactive)
8675 (let ((margin (current-indentation))
8676 (start (point))
8677 name end-column)
8678 (vhdl-insert-keyword "COMPONENT ")
8679 (when (setq name (vhdl-template-field "name" nil t start (point)))
8680 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8681 (insert "\n\n")
8682 (indent-to margin)
8683 (vhdl-insert-keyword "END COMPONENT")
8684 (unless (vhdl-standard-p '87) (insert " " name))
8685 (insert ";")
8686 (setq end-column (current-column))
8687 (end-of-line -0)
8688 (indent-to (+ margin vhdl-basic-offset))
8689 (vhdl-template-generic-list t t)
8690 (insert "\n")
8691 (indent-to (+ margin vhdl-basic-offset))
8692 (vhdl-template-port-list t)
8693 (beginning-of-line 2)
8694 (forward-char end-column))))
8696 (defun vhdl-template-component-inst ()
8697 "Insert a component instantiation statement."
8698 (interactive)
8699 (let ((margin (current-indentation))
8700 (start (point))
8701 unit position)
8702 (when (vhdl-template-field "instance label" nil t start (point))
8703 (insert ": ")
8704 (if (not (vhdl-use-direct-instantiation))
8705 (vhdl-template-field "component name")
8706 ;; direct instantiation
8707 (setq unit (vhdl-template-field
8708 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8709 (setq unit (upcase (or unit "")))
8710 (cond ((equal unit "ENTITY")
8711 (vhdl-template-field "library name" "." nil nil nil nil
8712 (vhdl-work-library))
8713 (vhdl-template-field "entity name" "(")
8714 (if (vhdl-template-field "[architecture name]" nil t)
8715 (insert ")")
8716 (delete-char -1)))
8717 ((equal unit "CONFIGURATION")
8718 (vhdl-template-field "library name" "." nil nil nil nil
8719 (vhdl-work-library))
8720 (vhdl-template-field "configuration name"))
8721 (t (vhdl-template-field "component name"))))
8722 (insert "\n")
8723 (indent-to (+ margin vhdl-basic-offset))
8724 (setq position (point))
8725 (vhdl-insert-keyword "GENERIC ")
8726 (when (vhdl-template-map position t t)
8727 (insert "\n")
8728 (indent-to (+ margin vhdl-basic-offset)))
8729 (setq position (point))
8730 (vhdl-insert-keyword "PORT ")
8731 (unless (vhdl-template-map position t t)
8732 (delete-region (line-beginning-position) (point))
8733 (delete-char -1))
8734 (insert ";"))))
8736 (defun vhdl-template-conditional-signal-asst ()
8737 "Insert a conditional signal assignment."
8738 (interactive)
8739 (when (vhdl-template-field "target signal")
8740 (insert " <= ")
8741 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8742 ; (insert " "))
8743 (let ((margin (current-column))
8744 (start (point))
8745 position)
8746 (vhdl-template-field "waveform")
8747 (setq position (point))
8748 (vhdl-insert-keyword " WHEN ")
8749 (when vhdl-conditions-in-parenthesis (insert "("))
8750 (while (and (vhdl-template-field "[condition]" nil t)
8751 (progn
8752 (when vhdl-conditions-in-parenthesis (insert ")"))
8753 (setq position (point))
8754 (vhdl-insert-keyword " ELSE")
8755 (insert "\n")
8756 (indent-to margin)
8757 (vhdl-template-field "[waveform]" nil t)))
8758 (setq position (point))
8759 (vhdl-insert-keyword " WHEN ")
8760 (when vhdl-conditions-in-parenthesis (insert "(")))
8761 (delete-region position (point))
8762 (insert ";")
8763 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8765 (defun vhdl-template-configuration ()
8766 "Insert a configuration specification if within an architecture,
8767 a block or component configuration if within a configuration declaration,
8768 a configuration declaration if not within a design unit."
8769 (interactive)
8770 (vhdl-prepare-search-1
8771 (cond
8772 ((and (save-excursion ; architecture body
8773 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8774 (equal "ARCHITECTURE" (upcase (match-string 1))))
8775 (vhdl-template-configuration-spec))
8776 ((and (save-excursion ; configuration declaration
8777 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8778 (equal "CONFIGURATION" (upcase (match-string 1))))
8779 (if (eq (vhdl-decision-query
8780 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8781 (vhdl-template-component-conf)
8782 (vhdl-template-block-configuration)))
8783 (t (vhdl-template-configuration-decl))))) ; otherwise
8785 (defun vhdl-template-configuration-spec (&optional optional-use)
8786 "Insert a configuration specification."
8787 (interactive)
8788 (let ((margin (current-indentation))
8789 (start (point))
8790 aspect position)
8791 (vhdl-insert-keyword "FOR ")
8792 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8793 t start (point))
8794 (vhdl-template-field "component name" "\n")
8795 (indent-to (+ margin vhdl-basic-offset))
8796 (setq start (point))
8797 (vhdl-insert-keyword "USE ")
8798 (if (and optional-use
8799 (not (setq aspect (vhdl-template-field
8800 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8801 (progn (delete-region start (point)) 'no-use)
8802 (unless optional-use
8803 (setq aspect (vhdl-template-field
8804 "ENTITY | CONFIGURATION | OPEN" " ")))
8805 (setq aspect (upcase (or aspect "")))
8806 (cond ((equal aspect "ENTITY")
8807 (vhdl-template-field "library name" "." nil nil nil nil
8808 (vhdl-work-library))
8809 (vhdl-template-field "entity name" "(")
8810 (if (vhdl-template-field "[architecture name]" nil t)
8811 (insert ")")
8812 (delete-char -1))
8813 (insert "\n")
8814 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8815 (setq position (point))
8816 (vhdl-insert-keyword "GENERIC ")
8817 (when (vhdl-template-map position t t)
8818 (insert "\n")
8819 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8820 (setq position (point))
8821 (vhdl-insert-keyword "PORT ")
8822 (unless (vhdl-template-map position t t)
8823 (delete-region (line-beginning-position) (point))
8824 (delete-char -1))
8825 (insert ";")
8827 ((equal aspect "CONFIGURATION")
8828 (vhdl-template-field "library name" "." nil nil nil nil
8829 (vhdl-work-library))
8830 (vhdl-template-field "configuration name" ";"))
8831 (t (delete-char -1) (insert ";") t))))))
8834 (defun vhdl-template-configuration-decl ()
8835 "Insert a configuration declaration."
8836 (interactive)
8837 (let ((margin (current-indentation))
8838 (start (point))
8839 entity-exists string name position)
8840 (vhdl-insert-keyword "CONFIGURATION ")
8841 (when (setq name (vhdl-template-field "name" nil t start (point)))
8842 (vhdl-insert-keyword " OF ")
8843 (save-excursion
8844 (vhdl-prepare-search-1
8845 (setq entity-exists (vhdl-re-search-backward
8846 "\\<entity \\(\\w*\\) is\\>" nil t))
8847 (setq string (match-string 1))))
8848 (if (and entity-exists (not (equal string "")))
8849 (insert string)
8850 (vhdl-template-field "entity name"))
8851 (vhdl-insert-keyword " IS\n")
8852 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8853 (indent-to (+ margin vhdl-basic-offset))
8854 (setq position (point))
8855 (insert "\n")
8856 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8857 (indent-to margin)
8858 (vhdl-insert-keyword "END ")
8859 (unless (vhdl-standard-p '87)
8860 (vhdl-insert-keyword "CONFIGURATION "))
8861 (insert name ";")
8862 (goto-char position))))
8864 (defun vhdl-template-constant ()
8865 "Insert a constant declaration."
8866 (interactive)
8867 (let ((start (point))
8868 (in-arglist (vhdl-in-argument-list-p)))
8869 (vhdl-insert-keyword "CONSTANT ")
8870 (when (vhdl-template-field "name" nil t start (point))
8871 (insert " : ")
8872 (when in-arglist (vhdl-insert-keyword "IN "))
8873 (vhdl-template-field "type")
8874 (if in-arglist
8875 (progn (insert ";")
8876 (vhdl-comment-insert-inline))
8877 (let ((position (point)))
8878 (insert " := ")
8879 (unless (vhdl-template-field "[initialization]" nil t)
8880 (delete-region position (point)))
8881 (insert ";")
8882 (vhdl-comment-insert-inline))))))
8884 (defun vhdl-template-default ()
8885 "Insert nothing."
8886 (interactive)
8887 (insert " ")
8888 (unexpand-abbrev)
8889 (backward-word 1)
8890 (vhdl-case-word 1)
8891 (forward-char 1))
8893 (defun vhdl-template-default-indent ()
8894 "Insert nothing and indent."
8895 (interactive)
8896 (insert " ")
8897 (unexpand-abbrev)
8898 (backward-word 1)
8899 (vhdl-case-word 1)
8900 (forward-char 1)
8901 (indent-according-to-mode))
8903 (defun vhdl-template-disconnect ()
8904 "Insert a disconnect statement."
8905 (interactive)
8906 (let ((start (point)))
8907 (vhdl-insert-keyword "DISCONNECT ")
8908 (when (vhdl-template-field "signal names | OTHERS | ALL"
8909 " : " t start (point))
8910 (vhdl-template-field "type")
8911 (vhdl-insert-keyword " AFTER ")
8912 (vhdl-template-field "time expression" ";"))))
8914 (defun vhdl-template-else ()
8915 "Insert an else statement."
8916 (interactive)
8917 (let (margin)
8918 (vhdl-prepare-search-1
8919 (vhdl-insert-keyword "ELSE")
8920 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8921 (equal "WHEN" (upcase (match-string 1))))
8922 (insert " ")
8923 (indent-according-to-mode)
8924 (setq margin (current-indentation))
8925 (insert "\n")
8926 (indent-to (+ margin vhdl-basic-offset))))))
8928 (defun vhdl-template-elsif ()
8929 "Insert an elsif statement."
8930 (interactive)
8931 (let ((start (point))
8932 margin)
8933 (vhdl-insert-keyword "ELSIF ")
8934 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8935 (when vhdl-conditions-in-parenthesis (insert "("))
8936 (when (vhdl-template-field "condition" nil t start (point))
8937 (when vhdl-conditions-in-parenthesis (insert ")"))
8938 (indent-according-to-mode)
8939 (setq margin (current-indentation))
8940 (vhdl-insert-keyword
8941 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8942 (indent-to (+ margin vhdl-basic-offset))))))
8944 (defun vhdl-template-entity ()
8945 "Insert an entity."
8946 (interactive)
8947 (let ((margin (current-indentation))
8948 (start (point))
8949 name end-column)
8950 (vhdl-insert-keyword "ENTITY ")
8951 (when (setq name (vhdl-template-field "name" nil t start (point)))
8952 (vhdl-insert-keyword " IS\n\n")
8953 (indent-to margin)
8954 (vhdl-insert-keyword "END ")
8955 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8956 (insert name ";")
8957 (setq end-column (current-column))
8958 (end-of-line -0)
8959 (indent-to (+ margin vhdl-basic-offset))
8960 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8961 (indent-to (+ margin vhdl-basic-offset))
8962 (when (vhdl-template-generic-list t)
8963 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8964 (insert "\n")
8965 (indent-to (+ margin vhdl-basic-offset))
8966 (when (vhdl-template-port-list t)
8967 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8968 (beginning-of-line 2)
8969 (forward-char end-column))))
8971 (defun vhdl-template-exit ()
8972 "Insert an exit statement."
8973 (interactive)
8974 (let ((start (point)))
8975 (vhdl-insert-keyword "EXIT ")
8976 (if (vhdl-template-field "[loop label]" nil t start (point))
8977 (let ((position (point)))
8978 (vhdl-insert-keyword " WHEN ")
8979 (when vhdl-conditions-in-parenthesis (insert "("))
8980 (if (vhdl-template-field "[condition]" nil t)
8981 (when vhdl-conditions-in-parenthesis (insert ")"))
8982 (delete-region position (point))))
8983 (delete-char -1))
8984 (insert ";")))
8986 (defun vhdl-template-file ()
8987 "Insert a file declaration."
8988 (interactive)
8989 (let ((start (point)))
8990 (vhdl-insert-keyword "FILE ")
8991 (when (vhdl-template-field "name" nil t start (point))
8992 (insert " : ")
8993 (vhdl-template-field "type")
8994 (unless (vhdl-standard-p '87)
8995 (vhdl-insert-keyword " OPEN ")
8996 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8997 nil t)
8998 (delete-char -6)))
8999 (vhdl-insert-keyword " IS ")
9000 (when (vhdl-standard-p '87)
9001 (vhdl-template-field "[IN | OUT]" " " t))
9002 (vhdl-template-field "filename-string" nil nil nil nil t)
9003 (insert ";")
9004 (vhdl-comment-insert-inline))))
9006 (defun vhdl-template-for ()
9007 "Insert a block or component configuration if within a configuration
9008 declaration, a configuration specification if within an architecture
9009 declarative part (and not within a subprogram), a for-loop if within a
9010 sequential statement part (subprogram or process), and a for-generate
9011 otherwise."
9012 (interactive)
9013 (vhdl-prepare-search-1
9014 (cond
9015 ((vhdl-sequential-statement-p) ; sequential statement
9016 (vhdl-template-for-loop))
9017 ((and (save-excursion ; configuration declaration
9018 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9019 (equal "CONFIGURATION" (upcase (match-string 1))))
9020 (if (eq (vhdl-decision-query
9021 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9022 (vhdl-template-component-conf)
9023 (vhdl-template-block-configuration)))
9024 ((and (save-excursion
9025 (re-search-backward ; architecture declarative part
9026 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9027 (equal "ARCHITECTURE" (upcase (match-string 1))))
9028 (vhdl-template-configuration-spec))
9029 (t (vhdl-template-for-generate))))) ; concurrent statement
9031 (defun vhdl-template-for-generate ()
9032 "Insert a for-generate."
9033 (interactive)
9034 (let ((margin (current-indentation))
9035 (start (point))
9036 label position)
9037 (vhdl-insert-keyword ": FOR ")
9038 (setq position (point-marker))
9039 (goto-char start)
9040 (when (setq label (vhdl-template-field "label" nil t start position))
9041 (goto-char position)
9042 (vhdl-template-field "loop variable")
9043 (vhdl-insert-keyword " IN ")
9044 (vhdl-template-field "range")
9045 (vhdl-template-generate-body margin label))))
9047 (defun vhdl-template-for-loop ()
9048 "Insert a for loop."
9049 (interactive)
9050 (let ((margin (current-indentation))
9051 (start (point))
9052 label index)
9053 (if (not (eq vhdl-optional-labels 'all))
9054 (vhdl-insert-keyword "FOR ")
9055 (vhdl-insert-keyword ": FOR ")
9056 (goto-char start)
9057 (setq label (vhdl-template-field "[label]" nil t))
9058 (unless label (delete-char 2))
9059 (forward-word 1)
9060 (forward-char 1))
9061 (when (setq index (vhdl-template-field "loop variable"
9062 nil t start (point)))
9063 (vhdl-insert-keyword " IN ")
9064 (vhdl-template-field "range")
9065 (vhdl-insert-keyword " LOOP\n\n")
9066 (indent-to margin)
9067 (vhdl-insert-keyword "END LOOP")
9068 (if label
9069 (insert " " label ";")
9070 (insert ";")
9071 (when vhdl-self-insert-comments (insert " -- " index)))
9072 (forward-line -1)
9073 (indent-to (+ margin vhdl-basic-offset)))))
9075 (defun vhdl-template-function (&optional kind)
9076 "Insert a function declaration or body."
9077 (interactive)
9078 (let ((margin (current-indentation))
9079 (start (point))
9080 name)
9081 (vhdl-insert-keyword "FUNCTION ")
9082 (when (setq name (vhdl-template-field "name" nil t start (point)))
9083 (vhdl-template-argument-list t)
9084 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9085 (end-of-line)
9086 (insert "\n")
9087 (indent-to (+ margin vhdl-basic-offset))
9088 (vhdl-insert-keyword "RETURN ")
9089 (vhdl-template-field "type")
9090 (if (if kind (eq kind 'body)
9091 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9092 (progn (vhdl-insert-keyword " IS\n")
9093 (vhdl-template-begin-end
9094 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9095 (vhdl-comment-block))
9096 (insert ";")))))
9098 (defun vhdl-template-function-decl ()
9099 "Insert a function declaration."
9100 (interactive)
9101 (vhdl-template-function 'decl))
9103 (defun vhdl-template-function-body ()
9104 "Insert a function declaration."
9105 (interactive)
9106 (vhdl-template-function 'body))
9108 (defun vhdl-template-generate ()
9109 "Insert a generation scheme."
9110 (interactive)
9111 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9112 (vhdl-template-if-generate)
9113 (vhdl-template-for-generate)))
9115 (defun vhdl-template-generic ()
9116 "Insert generic declaration, or generic map in instantiation statements."
9117 (interactive)
9118 (let ((start (point)))
9119 (vhdl-prepare-search-1
9120 (cond
9121 ((and (save-excursion ; entity declaration
9122 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9123 (equal "ENTITY" (upcase (match-string 1))))
9124 (vhdl-template-generic-list nil))
9125 ((or (save-excursion
9126 (or (beginning-of-line)
9127 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9128 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9129 (vhdl-insert-keyword "GENERIC ")
9130 (vhdl-template-map start))
9131 (t (vhdl-template-generic-list nil t))))))
9133 (defun vhdl-template-group ()
9134 "Insert group or group template declaration."
9135 (interactive)
9136 (let ((start (point)))
9137 (if (eq (vhdl-decision-query
9138 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9139 (vhdl-template-group-template)
9140 (vhdl-template-group-decl))))
9142 (defun vhdl-template-group-decl ()
9143 "Insert group declaration."
9144 (interactive)
9145 (let ((start (point)))
9146 (vhdl-insert-keyword "GROUP ")
9147 (when (vhdl-template-field "name" " : " t start (point))
9148 (vhdl-template-field "template name" " (")
9149 (vhdl-template-field "constituent list" ");")
9150 (vhdl-comment-insert-inline))))
9152 (defun vhdl-template-group-template ()
9153 "Insert group template declaration."
9154 (interactive)
9155 (let ((start (point)))
9156 (vhdl-insert-keyword "GROUP ")
9157 (when (vhdl-template-field "template name" nil t start (point))
9158 (vhdl-insert-keyword " IS (")
9159 (vhdl-template-field "entity class list" ");")
9160 (vhdl-comment-insert-inline))))
9162 (defun vhdl-template-if ()
9163 "Insert a sequential if statement or an if-generate statement."
9164 (interactive)
9165 (if (vhdl-sequential-statement-p)
9166 (vhdl-template-if-then)
9167 (if (and (vhdl-standard-p 'ams)
9168 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9169 (vhdl-template-if-use)
9170 (vhdl-template-if-generate))))
9172 (defun vhdl-template-if-generate ()
9173 "Insert an if-generate."
9174 (interactive)
9175 (let ((margin (current-indentation))
9176 (start (point))
9177 label position)
9178 (vhdl-insert-keyword ": IF ")
9179 (setq position (point-marker))
9180 (goto-char start)
9181 (when (setq label (vhdl-template-field "label" nil t start position))
9182 (goto-char position)
9183 (when vhdl-conditions-in-parenthesis (insert "("))
9184 (vhdl-template-field "condition")
9185 (when vhdl-conditions-in-parenthesis (insert ")"))
9186 (vhdl-template-generate-body margin label))))
9188 (defun vhdl-template-if-then-use (kind)
9189 "Insert a sequential if statement."
9190 (interactive)
9191 (let ((margin (current-indentation))
9192 (start (point))
9193 label)
9194 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9195 (vhdl-insert-keyword "IF ")
9196 (vhdl-insert-keyword ": IF ")
9197 (goto-char start)
9198 (setq label (vhdl-template-field "[label]" nil t))
9199 (unless label (delete-char 2))
9200 (forward-word 1)
9201 (forward-char 1))
9202 (when vhdl-conditions-in-parenthesis (insert "("))
9203 (when (vhdl-template-field "condition" nil t start (point))
9204 (when vhdl-conditions-in-parenthesis (insert ")"))
9205 (vhdl-insert-keyword
9206 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9207 (indent-to margin)
9208 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9209 (when label (insert " " label))
9210 (insert ";")
9211 (forward-line -1)
9212 (indent-to (+ margin vhdl-basic-offset)))))
9214 (defun vhdl-template-if-then ()
9215 "Insert a sequential if statement."
9216 (interactive)
9217 (vhdl-template-if-then-use 'then))
9219 (defun vhdl-template-if-use ()
9220 "Insert a simultaneous if statement."
9221 (interactive)
9222 (vhdl-template-if-then-use 'use))
9224 (defun vhdl-template-instance ()
9225 "Insert a component instantiation statement."
9226 (interactive)
9227 (vhdl-template-component-inst))
9229 (defun vhdl-template-library ()
9230 "Insert a library specification."
9231 (interactive)
9232 (let ((margin (current-indentation))
9233 (start (point))
9234 name end-pos)
9235 (vhdl-insert-keyword "LIBRARY ")
9236 (when (setq name (vhdl-template-field "names" nil t start (point)))
9237 (insert ";")
9238 (unless (string-match "," name)
9239 (setq end-pos (point))
9240 (insert "\n")
9241 (indent-to margin)
9242 (vhdl-insert-keyword "USE ")
9243 (insert name)
9244 (vhdl-insert-keyword "..ALL;")
9245 (backward-char 5)
9246 (if (vhdl-template-field "package name")
9247 (forward-char 5)
9248 (delete-region end-pos (+ (point) 5)))))))
9250 (defun vhdl-template-limit ()
9251 "Insert a limit."
9252 (interactive)
9253 (let ((start (point)))
9254 (vhdl-insert-keyword "LIMIT ")
9255 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9256 t start (point))
9257 (vhdl-template-field "type")
9258 (vhdl-insert-keyword " WITH ")
9259 (vhdl-template-field "real expression" ";"))))
9261 (defun vhdl-template-loop ()
9262 "Insert a loop."
9263 (interactive)
9264 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9265 (cond ((eq char ?w)
9266 (vhdl-template-while-loop))
9267 ((eq char ?f)
9268 (vhdl-template-for-loop))
9269 (t (vhdl-template-bare-loop)))))
9271 (defun vhdl-template-bare-loop ()
9272 "Insert a loop."
9273 (interactive)
9274 (let ((margin (current-indentation))
9275 (start (point))
9276 label)
9277 (if (not (eq vhdl-optional-labels 'all))
9278 (vhdl-insert-keyword "LOOP ")
9279 (vhdl-insert-keyword ": LOOP ")
9280 (goto-char start)
9281 (setq label (vhdl-template-field "[label]" nil t))
9282 (unless label (delete-char 2))
9283 (forward-word 1)
9284 (delete-char 1))
9285 (insert "\n\n")
9286 (indent-to margin)
9287 (vhdl-insert-keyword "END LOOP")
9288 (insert (if label (concat " " label ";") ";"))
9289 (forward-line -1)
9290 (indent-to (+ margin vhdl-basic-offset))))
9292 (defun vhdl-template-map (&optional start optional secondary)
9293 "Insert a map specification with association list."
9294 (interactive)
9295 (let ((start (or start (point)))
9296 margin end-pos)
9297 (vhdl-insert-keyword "MAP (")
9298 (if (not vhdl-association-list-with-formals)
9299 (if (vhdl-template-field
9300 (concat (and optional "[") "association list" (and optional "]"))
9301 ")" (or (not secondary) optional)
9302 (and (not secondary) start) (point))
9304 (if (and optional secondary) (delete-region start (point)))
9305 nil)
9306 (if vhdl-argument-list-indent
9307 (setq margin (current-column))
9308 (setq margin (+ (current-indentation) vhdl-basic-offset))
9309 (insert "\n")
9310 (indent-to margin))
9311 (if (vhdl-template-field
9312 (concat (and optional "[") "formal" (and optional "]"))
9313 " => " (or (not secondary) optional)
9314 (and (not secondary) start) (point))
9315 (progn
9316 (vhdl-template-field "actual" ",")
9317 (setq end-pos (point))
9318 (insert "\n")
9319 (indent-to margin)
9320 (while (vhdl-template-field "[formal]" " => " t)
9321 (vhdl-template-field "actual" ",")
9322 (setq end-pos (point))
9323 (insert "\n")
9324 (indent-to margin))
9325 (delete-region end-pos (point))
9326 (delete-char -1)
9327 (insert ")")
9328 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9330 (when (and optional secondary) (delete-region start (point)))
9331 nil))))
9333 (defun vhdl-template-modify (&optional noerror)
9334 "Actualize modification date."
9335 (interactive)
9336 (vhdl-prepare-search-2
9337 (save-excursion
9338 (goto-char (point-min))
9339 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9340 (progn (delete-region (point) (progn (end-of-line) (point)))
9341 (vhdl-template-insert-date))
9342 (unless noerror
9343 (error "ERROR: Modification date prefix string \"%s\" not found"
9344 vhdl-modify-date-prefix-string))))))
9347 (defun vhdl-template-modify-noerror ()
9348 "Call `vhdl-template-modify' with NOERROR non-nil."
9349 (vhdl-template-modify t))
9351 (defun vhdl-template-nature ()
9352 "Insert a nature declaration."
9353 (interactive)
9354 (let ((start (point))
9355 name mid-pos end-pos)
9356 (vhdl-insert-keyword "NATURE ")
9357 (when (setq name (vhdl-template-field "name" nil t start (point)))
9358 (vhdl-insert-keyword " IS ")
9359 (let ((definition
9360 (upcase
9361 (or (vhdl-template-field
9362 "across type | ARRAY | RECORD")
9363 ""))))
9364 (cond ((equal definition "")
9365 (insert ";"))
9366 ((equal definition "ARRAY")
9367 (delete-region (point) (progn (forward-word -1) (point)))
9368 (vhdl-template-array 'nature t))
9369 ((equal definition "RECORD")
9370 (setq mid-pos (point-marker))
9371 (delete-region (point) (progn (forward-word -1) (point)))
9372 (vhdl-template-record 'nature name t))
9374 (vhdl-insert-keyword " ACROSS ")
9375 (vhdl-template-field "through type")
9376 (vhdl-insert-keyword " THROUGH ")
9377 (vhdl-template-field "reference name")
9378 (vhdl-insert-keyword " REFERENCE;")))
9379 (when mid-pos
9380 (setq end-pos (point-marker))
9381 (goto-char mid-pos)
9382 (end-of-line))
9383 (vhdl-comment-insert-inline)
9384 (when end-pos (goto-char end-pos))))))
9386 (defun vhdl-template-next ()
9387 "Insert a next statement."
9388 (interactive)
9389 (let ((start (point)))
9390 (vhdl-insert-keyword "NEXT ")
9391 (if (vhdl-template-field "[loop label]" nil t start (point))
9392 (let ((position (point)))
9393 (vhdl-insert-keyword " WHEN ")
9394 (when vhdl-conditions-in-parenthesis (insert "("))
9395 (if (vhdl-template-field "[condition]" nil t)
9396 (when vhdl-conditions-in-parenthesis (insert ")"))
9397 (delete-region position (point))))
9398 (delete-char -1))
9399 (insert ";")))
9401 (defun vhdl-template-others ()
9402 "Insert an others aggregate."
9403 (interactive)
9404 (let ((start (point)))
9405 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9406 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9407 (vhdl-insert-keyword "OTHERS => '")
9408 (when (vhdl-template-field "value" nil t start (point))
9409 (insert "')")))
9410 (vhdl-insert-keyword "OTHERS "))))
9412 (defun vhdl-template-package (&optional kind)
9413 "Insert a package specification or body."
9414 (interactive)
9415 (let ((margin (current-indentation))
9416 (start (point))
9417 name body position)
9418 (vhdl-insert-keyword "PACKAGE ")
9419 (setq body (if kind (eq kind 'body)
9420 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9421 (when body
9422 (vhdl-insert-keyword "BODY ")
9423 (when (save-excursion
9424 (vhdl-prepare-search-1
9425 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9426 (insert (setq name (match-string 1)))))
9427 (when (or name
9428 (setq name (vhdl-template-field "name" nil t start (point))))
9429 (vhdl-insert-keyword " IS\n")
9430 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9431 (indent-to (+ margin vhdl-basic-offset))
9432 (setq position (point))
9433 (insert "\n")
9434 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9435 (indent-to margin)
9436 (vhdl-insert-keyword "END ")
9437 (unless (vhdl-standard-p '87)
9438 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9439 (insert (or name "") ";")
9440 (goto-char position))))
9442 (defun vhdl-template-package-decl ()
9443 "Insert a package specification."
9444 (interactive)
9445 (vhdl-template-package 'decl))
9447 (defun vhdl-template-package-body ()
9448 "Insert a package body."
9449 (interactive)
9450 (vhdl-template-package 'body))
9452 (defun vhdl-template-port ()
9453 "Insert a port declaration, or port map in instantiation statements."
9454 (interactive)
9455 (let ((start (point)))
9456 (vhdl-prepare-search-1
9457 (cond
9458 ((and (save-excursion ; entity declaration
9459 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9460 (equal "ENTITY" (upcase (match-string 1))))
9461 (vhdl-template-port-list nil))
9462 ((or (save-excursion
9463 (or (beginning-of-line)
9464 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9465 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9466 (vhdl-insert-keyword "PORT ")
9467 (vhdl-template-map start))
9468 (t (vhdl-template-port-list nil))))))
9470 (defun vhdl-template-procedural ()
9471 "Insert a procedural."
9472 (interactive)
9473 (let ((margin (current-indentation))
9474 (start (point))
9475 (case-fold-search t)
9476 label)
9477 (vhdl-insert-keyword "PROCEDURAL ")
9478 (when (memq vhdl-optional-labels '(process all))
9479 (goto-char start)
9480 (insert ": ")
9481 (goto-char start)
9482 (setq label (vhdl-template-field "[label]" nil t))
9483 (unless label (delete-char 2))
9484 (forward-word 1)
9485 (forward-char 1))
9486 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9487 (insert "\n")
9488 (vhdl-template-begin-end "PROCEDURAL" label margin)
9489 (vhdl-comment-block)))
9491 (defun vhdl-template-procedure (&optional kind)
9492 "Insert a procedure declaration or body."
9493 (interactive)
9494 (let ((margin (current-indentation))
9495 (start (point))
9496 name)
9497 (vhdl-insert-keyword "PROCEDURE ")
9498 (when (setq name (vhdl-template-field "name" nil t start (point)))
9499 (vhdl-template-argument-list)
9500 (if (if kind (eq kind 'body)
9501 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9502 (progn (vhdl-insert-keyword " IS")
9503 (when vhdl-auto-align
9504 (vhdl-align-region-groups start (point) 1))
9505 (end-of-line) (insert "\n")
9506 (vhdl-template-begin-end
9507 (unless (vhdl-standard-p '87) "PROCEDURE")
9508 name margin)
9509 (vhdl-comment-block))
9510 (insert ";")
9511 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9512 (end-of-line)))))
9514 (defun vhdl-template-procedure-decl ()
9515 "Insert a procedure declaration."
9516 (interactive)
9517 (vhdl-template-procedure 'decl))
9519 (defun vhdl-template-procedure-body ()
9520 "Insert a procedure body."
9521 (interactive)
9522 (vhdl-template-procedure 'body))
9524 (defun vhdl-template-process (&optional kind)
9525 "Insert a process."
9526 (interactive)
9527 (let ((margin (current-indentation))
9528 (start (point))
9529 (reset-kind vhdl-reset-kind)
9530 label seq input-signals clock reset final-pos)
9531 (setq seq (if kind (eq kind 'seq)
9532 (eq (vhdl-decision-query
9533 "process" "(c)ombinational or (s)equential?" t) ?s)))
9534 (vhdl-insert-keyword "PROCESS ")
9535 (when (memq vhdl-optional-labels '(process all))
9536 (goto-char start)
9537 (insert ": ")
9538 (goto-char start)
9539 (setq label (vhdl-template-field "[label]" nil t))
9540 (unless label (delete-char 2))
9541 (forward-word 1)
9542 (forward-char 1))
9543 (insert "(")
9544 (if (not seq)
9545 (unless (setq input-signals
9546 (vhdl-template-field "[sensitivity list]" ")" t))
9547 (setq input-signals "")
9548 (delete-char -2))
9549 (setq clock (or (and (not (equal "" vhdl-clock-name))
9550 (progn (insert vhdl-clock-name) vhdl-clock-name))
9551 (vhdl-template-field "clock name") "<clock>"))
9552 (when (eq reset-kind 'query)
9553 (setq reset-kind
9554 (if (eq (vhdl-decision-query
9555 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9556 'async
9557 'sync)))
9558 (when (eq reset-kind 'async)
9559 (insert ", ")
9560 (setq reset (or (and (not (equal "" vhdl-reset-name))
9561 (progn (insert vhdl-reset-name) vhdl-reset-name))
9562 (vhdl-template-field "reset name") "<reset>")))
9563 (insert ")"))
9564 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9565 (insert "\n")
9566 (vhdl-template-begin-end "PROCESS" label margin)
9567 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9568 (when vhdl-prompt-for-comments
9569 (setq final-pos (point-marker))
9570 (vhdl-prepare-search-2
9571 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9572 (vhdl-re-search-backward "\\<process\\>" nil t))
9573 (end-of-line -0)
9574 (if (bobp)
9575 (progn (insert "\n") (forward-line -1))
9576 (insert "\n"))
9577 (indent-to margin)
9578 (insert "-- purpose: ")
9579 (if (not (vhdl-template-field "[description]" nil t))
9580 (vhdl-line-kill-entire)
9581 (insert "\n")
9582 (indent-to margin)
9583 (insert "-- type : ")
9584 (insert (if seq "sequential" "combinational") "\n")
9585 (indent-to margin)
9586 (insert "-- inputs : ")
9587 (if (not seq)
9588 (insert input-signals)
9589 (insert clock ", ")
9590 (when reset (insert reset ", "))
9591 (unless (vhdl-template-field "[signal names]" nil t)
9592 (delete-char -2)))
9593 (insert "\n")
9594 (indent-to margin)
9595 (insert "-- outputs: ")
9596 (vhdl-template-field "[signal names]" nil t))))
9597 (goto-char final-pos))))
9599 (defun vhdl-template-process-comb ()
9600 "Insert a combinational process."
9601 (interactive)
9602 (vhdl-template-process 'comb))
9604 (defun vhdl-template-process-seq ()
9605 "Insert a sequential process."
9606 (interactive)
9607 (vhdl-template-process 'seq))
9609 (defun vhdl-template-quantity ()
9610 "Insert a quantity declaration."
9611 (interactive)
9612 (if (vhdl-in-argument-list-p)
9613 (let ((start (point)))
9614 (vhdl-insert-keyword "QUANTITY ")
9615 (when (vhdl-template-field "names" nil t start (point))
9616 (insert " : ")
9617 (vhdl-template-field "[IN | OUT]" " " t)
9618 (vhdl-template-field "type")
9619 (insert ";")
9620 (vhdl-comment-insert-inline)))
9621 (let ((char (vhdl-decision-query
9622 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9623 (cond ((eq char ?f) (vhdl-template-quantity-free))
9624 ((eq char ?b) (vhdl-template-quantity-branch))
9625 ((eq char ?s) (vhdl-template-quantity-source))
9626 (t (vhdl-template-undo (point) (point)))))))
9628 (defun vhdl-template-quantity-free ()
9629 "Insert a free quantity declaration."
9630 (interactive)
9631 (vhdl-insert-keyword "QUANTITY ")
9632 (vhdl-template-field "names")
9633 (insert " : ")
9634 (vhdl-template-field "type")
9635 (let ((position (point)))
9636 (insert " := ")
9637 (unless (vhdl-template-field "[initialization]" nil t)
9638 (delete-region position (point)))
9639 (insert ";")
9640 (vhdl-comment-insert-inline)))
9642 (defun vhdl-template-quantity-branch ()
9643 "Insert a branch quantity declaration."
9644 (interactive)
9645 (let (position)
9646 (vhdl-insert-keyword "QUANTITY ")
9647 (when (vhdl-template-field "[across names]" " " t)
9648 (vhdl-insert-keyword "ACROSS "))
9649 (when (vhdl-template-field "[through names]" " " t)
9650 (vhdl-insert-keyword "THROUGH "))
9651 (vhdl-template-field "plus terminal name")
9652 (setq position (point))
9653 (vhdl-insert-keyword " TO ")
9654 (unless (vhdl-template-field "[minus terminal name]" nil t)
9655 (delete-region position (point)))
9656 (insert ";")
9657 (vhdl-comment-insert-inline)))
9659 (defun vhdl-template-quantity-source ()
9660 "Insert a source quantity declaration."
9661 (interactive)
9662 (vhdl-insert-keyword "QUANTITY ")
9663 (vhdl-template-field "names")
9664 (insert " : ")
9665 (vhdl-template-field "type" " ")
9666 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9667 (progn (vhdl-insert-keyword "NOISE ")
9668 (vhdl-template-field "power expression"))
9669 (vhdl-insert-keyword "SPECTRUM ")
9670 (vhdl-template-field "magnitude expression" ", ")
9671 (vhdl-template-field "phase expression"))
9672 (insert ";")
9673 (vhdl-comment-insert-inline))
9675 (defun vhdl-template-record (kind &optional name secondary)
9676 "Insert a record type declaration."
9677 (interactive)
9678 (let ((margin (current-column))
9679 (start (point))
9680 (first t))
9681 (vhdl-insert-keyword "RECORD\n")
9682 (indent-to (+ margin vhdl-basic-offset))
9683 (when (or (vhdl-template-field "element names"
9684 nil (not secondary) start (point))
9685 secondary)
9686 (while (or first (vhdl-template-field "[element names]" nil t))
9687 (insert " : ")
9688 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9689 (vhdl-comment-insert-inline)
9690 (insert "\n")
9691 (indent-to (+ margin vhdl-basic-offset))
9692 (setq first nil))
9693 (delete-region (line-beginning-position) (point))
9694 (indent-to margin)
9695 (vhdl-insert-keyword "END RECORD")
9696 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9697 (insert ";")
9698 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9700 (defun vhdl-template-report ()
9701 "Insert a report statement."
9702 (interactive)
9703 (let ((start (point)))
9704 (vhdl-insert-keyword "REPORT ")
9705 (if (equal "\"\"" (vhdl-template-field
9706 "string expression" nil t start (point) t))
9707 (delete-char -2)
9708 (setq start (point))
9709 (vhdl-insert-keyword " SEVERITY ")
9710 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9711 (delete-region start (point)))
9712 (insert ";"))))
9714 (defun vhdl-template-return ()
9715 "Insert a return statement."
9716 (interactive)
9717 (let ((start (point)))
9718 (vhdl-insert-keyword "RETURN ")
9719 (unless (vhdl-template-field "[expression]" nil t start (point))
9720 (delete-char -1))
9721 (insert ";")))
9723 (defun vhdl-template-selected-signal-asst ()
9724 "Insert a selected signal assignment."
9725 (interactive)
9726 (let ((margin (current-indentation))
9727 (start (point))
9728 (choices t))
9729 (let ((position (point)))
9730 (vhdl-insert-keyword " SELECT ")
9731 (goto-char position))
9732 (vhdl-insert-keyword "WITH ")
9733 (when (vhdl-template-field "selector expression"
9734 nil t start (+ (point) 7))
9735 (forward-word 1)
9736 (delete-char 1)
9737 (insert "\n")
9738 (indent-to (+ margin vhdl-basic-offset))
9739 (vhdl-template-field "target signal" " <= ")
9740 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9741 (insert "\n")
9742 (indent-to (+ margin vhdl-basic-offset))
9743 (vhdl-template-field "waveform")
9744 (vhdl-insert-keyword " WHEN ")
9745 (vhdl-template-field "choices" ",")
9746 (insert "\n")
9747 (indent-to (+ margin vhdl-basic-offset))
9748 (while (and choices (vhdl-template-field "[waveform]" nil t))
9749 (vhdl-insert-keyword " WHEN ")
9750 (if (setq choices (vhdl-template-field "[choices]" "," t))
9751 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9752 (vhdl-insert-keyword "OTHERS")))
9753 (when choices
9754 (fixup-whitespace)
9755 (delete-char -2))
9756 (insert ";")
9757 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9759 (defun vhdl-template-signal ()
9760 "Insert a signal declaration."
9761 (interactive)
9762 (let ((start (point))
9763 (in-arglist (vhdl-in-argument-list-p)))
9764 (vhdl-insert-keyword "SIGNAL ")
9765 (when (vhdl-template-field "names" nil t start (point))
9766 (insert " : ")
9767 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9768 (vhdl-template-field "type")
9769 (if in-arglist
9770 (progn (insert ";")
9771 (vhdl-comment-insert-inline))
9772 (let ((position (point)))
9773 (insert " := ")
9774 (unless (vhdl-template-field "[initialization]" nil t)
9775 (delete-region position (point)))
9776 (insert ";")
9777 (vhdl-comment-insert-inline))))))
9779 (defun vhdl-template-subnature ()
9780 "Insert a subnature declaration."
9781 (interactive)
9782 (let ((start (point))
9783 position)
9784 (vhdl-insert-keyword "SUBNATURE ")
9785 (when (vhdl-template-field "name" nil t start (point))
9786 (vhdl-insert-keyword " IS ")
9787 (vhdl-template-field "nature" " (")
9788 (if (vhdl-template-field "[index range]" nil t)
9789 (insert ")")
9790 (delete-char -2))
9791 (setq position (point))
9792 (vhdl-insert-keyword " TOLERANCE ")
9793 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9794 nil t nil nil t))
9795 (delete-region position (point))
9796 (vhdl-insert-keyword " ACROSS ")
9797 (vhdl-template-field "string expression" nil nil nil nil t)
9798 (vhdl-insert-keyword " THROUGH"))
9799 (insert ";")
9800 (vhdl-comment-insert-inline))))
9802 (defun vhdl-template-subprogram-body ()
9803 "Insert a subprogram body."
9804 (interactive)
9805 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9806 (vhdl-template-function-body)
9807 (vhdl-template-procedure-body)))
9809 (defun vhdl-template-subprogram-decl ()
9810 "Insert a subprogram declaration."
9811 (interactive)
9812 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9813 (vhdl-template-function-decl)
9814 (vhdl-template-procedure-decl)))
9816 (defun vhdl-template-subtype ()
9817 "Insert a subtype declaration."
9818 (interactive)
9819 (let ((start (point)))
9820 (vhdl-insert-keyword "SUBTYPE ")
9821 (when (vhdl-template-field "name" nil t start (point))
9822 (vhdl-insert-keyword " IS ")
9823 (vhdl-template-field "type" " ")
9824 (unless
9825 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9826 (delete-char -1))
9827 (insert ";")
9828 (vhdl-comment-insert-inline))))
9830 (defun vhdl-template-terminal ()
9831 "Insert a terminal declaration."
9832 (interactive)
9833 (let ((start (point)))
9834 (vhdl-insert-keyword "TERMINAL ")
9835 (when (vhdl-template-field "names" nil t start (point))
9836 (insert " : ")
9837 (vhdl-template-field "nature")
9838 (insert ";")
9839 (vhdl-comment-insert-inline))))
9841 (defun vhdl-template-type ()
9842 "Insert a type declaration."
9843 (interactive)
9844 (let ((start (point))
9845 name mid-pos end-pos)
9846 (vhdl-insert-keyword "TYPE ")
9847 (when (setq name (vhdl-template-field "name" nil t start (point)))
9848 (vhdl-insert-keyword " IS ")
9849 (let ((definition
9850 (upcase
9851 (or (vhdl-template-field
9852 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9853 ""))))
9854 (cond ((equal definition "")
9855 (delete-char -4)
9856 (insert ";"))
9857 ((equal definition "ARRAY")
9858 (delete-region (point) (progn (forward-word -1) (point)))
9859 (vhdl-template-array 'type t))
9860 ((equal definition "RECORD")
9861 (setq mid-pos (point-marker))
9862 (delete-region (point) (progn (forward-word -1) (point)))
9863 (vhdl-template-record 'type name t))
9864 ((equal definition "ACCESS")
9865 (insert " ")
9866 (vhdl-template-field "type" ";"))
9867 ((equal definition "FILE")
9868 (vhdl-insert-keyword " OF ")
9869 (vhdl-template-field "type" ";"))
9870 (t (insert ";")))
9871 (when mid-pos
9872 (setq end-pos (point-marker))
9873 (goto-char mid-pos)
9874 (end-of-line))
9875 (vhdl-comment-insert-inline)
9876 (when end-pos (goto-char end-pos))))))
9878 (defun vhdl-template-use ()
9879 "Insert a use clause."
9880 (interactive)
9881 (let ((start (point)))
9882 (vhdl-prepare-search-1
9883 (vhdl-insert-keyword "USE ")
9884 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9885 (vhdl-insert-keyword "..ALL;")
9886 (backward-char 6)
9887 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9888 (forward-char 1)
9889 (vhdl-template-field "package name")
9890 (forward-char 5))))))
9892 (defun vhdl-template-variable ()
9893 "Insert a variable declaration."
9894 (interactive)
9895 (let ((start (point))
9896 (in-arglist (vhdl-in-argument-list-p)))
9897 (vhdl-prepare-search-2
9898 (if (or (save-excursion
9899 (progn (vhdl-beginning-of-block)
9900 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
9901 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9902 (vhdl-insert-keyword "VARIABLE ")
9903 (if (vhdl-standard-p '87)
9904 (error "ERROR: Not within sequential block")
9905 (vhdl-insert-keyword "SHARED VARIABLE "))))
9906 (when (vhdl-template-field "names" nil t start (point))
9907 (insert " : ")
9908 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9909 (vhdl-template-field "type")
9910 (if in-arglist
9911 (progn (insert ";")
9912 (vhdl-comment-insert-inline))
9913 (let ((position (point)))
9914 (insert " := ")
9915 (unless (vhdl-template-field "[initialization]" nil t)
9916 (delete-region position (point)))
9917 (insert ";")
9918 (vhdl-comment-insert-inline))))))
9920 (defun vhdl-template-wait ()
9921 "Insert a wait statement."
9922 (interactive)
9923 (vhdl-insert-keyword "WAIT ")
9924 (unless (vhdl-template-field
9925 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9926 nil t)
9927 (delete-char -1))
9928 (insert ";"))
9930 (defun vhdl-template-when ()
9931 "Indent correctly if within a case statement."
9932 (interactive)
9933 (let ((position (point))
9934 margin)
9935 (vhdl-prepare-search-2
9936 (if (and (= (current-column) (current-indentation))
9937 (vhdl-re-search-forward "\\<end\\>" nil t)
9938 (looking-at "\\s-*\\<case\\>"))
9939 (progn
9940 (setq margin (current-indentation))
9941 (goto-char position)
9942 (delete-horizontal-space)
9943 (indent-to (+ margin vhdl-basic-offset)))
9944 (goto-char position)))
9945 (vhdl-insert-keyword "WHEN ")))
9947 (defun vhdl-template-while-loop ()
9948 "Insert a while loop."
9949 (interactive)
9950 (let* ((margin (current-indentation))
9951 (start (point))
9952 label)
9953 (if (not (eq vhdl-optional-labels 'all))
9954 (vhdl-insert-keyword "WHILE ")
9955 (vhdl-insert-keyword ": WHILE ")
9956 (goto-char start)
9957 (setq label (vhdl-template-field "[label]" nil t))
9958 (unless label (delete-char 2))
9959 (forward-word 1)
9960 (forward-char 1))
9961 (when vhdl-conditions-in-parenthesis (insert "("))
9962 (when (vhdl-template-field "condition" nil t start (point))
9963 (when vhdl-conditions-in-parenthesis (insert ")"))
9964 (vhdl-insert-keyword " LOOP\n\n")
9965 (indent-to margin)
9966 (vhdl-insert-keyword "END LOOP")
9967 (insert (if label (concat " " label ";") ";"))
9968 (forward-line -1)
9969 (indent-to (+ margin vhdl-basic-offset)))))
9971 (defun vhdl-template-with ()
9972 "Insert a with statement (i.e. selected signal assignment)."
9973 (interactive)
9974 (vhdl-prepare-search-1
9975 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9976 (equal ";" (match-string 1)))
9977 (vhdl-template-selected-signal-asst)
9978 (vhdl-insert-keyword "WITH "))))
9980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9981 ;; Special templates
9983 (defun vhdl-template-clocked-wait ()
9984 "Insert a wait statement for rising/falling clock edge."
9985 (interactive)
9986 (let ((start (point))
9987 clock)
9988 (vhdl-insert-keyword "WAIT UNTIL ")
9989 (when (setq clock
9990 (or (and (not (equal "" vhdl-clock-name))
9991 (progn (insert vhdl-clock-name) vhdl-clock-name))
9992 (vhdl-template-field "clock name" nil t start (point))))
9993 (insert "'event")
9994 (vhdl-insert-keyword " AND ")
9995 (insert clock)
9996 (insert
9997 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9998 (vhdl-comment-insert-inline
9999 (concat (if vhdl-clock-rising-edge "rising" "falling")
10000 " clock edge")))))
10002 (defun vhdl-template-seq-process (clock reset reset-kind)
10003 "Insert a template for the body of a sequential process."
10004 (let ((margin (current-indentation))
10005 position)
10006 (vhdl-insert-keyword "IF ")
10007 (when vhdl-conditions-in-parenthesis (insert "("))
10008 (when (eq reset-kind 'async)
10009 (insert reset " = "
10010 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10011 (when vhdl-conditions-in-parenthesis (insert ")"))
10012 (vhdl-insert-keyword " THEN")
10013 (vhdl-comment-insert-inline
10014 (concat "asynchronous reset (active "
10015 (if vhdl-reset-active-high "high" "low") ")"))
10016 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10017 (setq position (point))
10018 (insert "\n") (indent-to margin)
10019 (vhdl-insert-keyword "ELSIF ")
10020 (when vhdl-conditions-in-parenthesis (insert "(")))
10021 (if (eq vhdl-clock-edge-condition 'function)
10022 (insert (if vhdl-clock-rising-edge "rising" "falling")
10023 "_edge(" clock ")")
10024 (insert clock "'event")
10025 (vhdl-insert-keyword " AND ")
10026 (insert clock " = "
10027 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10028 (when vhdl-conditions-in-parenthesis (insert ")"))
10029 (vhdl-insert-keyword " THEN")
10030 (vhdl-comment-insert-inline
10031 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10032 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10033 (when (eq reset-kind 'sync)
10034 (vhdl-insert-keyword "IF ")
10035 (when vhdl-conditions-in-parenthesis (insert "("))
10036 (setq reset (or (and (not (equal "" vhdl-reset-name))
10037 (progn (insert vhdl-reset-name) vhdl-reset-name))
10038 (vhdl-template-field "reset name") "<reset>"))
10039 (insert " = "
10040 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10041 (when vhdl-conditions-in-parenthesis (insert ")"))
10042 (vhdl-insert-keyword " THEN")
10043 (vhdl-comment-insert-inline
10044 (concat "synchronous reset (active "
10045 (if vhdl-reset-active-high "high" "low") ")"))
10046 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10047 (setq position (point))
10048 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10049 (vhdl-insert-keyword "ELSE")
10050 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10051 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10052 (vhdl-insert-keyword "END IF;"))
10053 (when (eq reset-kind 'none)
10054 (setq position (point)))
10055 (insert "\n") (indent-to margin)
10056 (vhdl-insert-keyword "END IF;")
10057 (goto-char position)
10058 reset))
10060 (defun vhdl-template-standard-package (library package)
10061 "Insert specification of a standard package. Include a library
10062 specification, if not already there."
10063 (let ((margin (current-indentation)))
10064 (unless (equal library "std")
10065 (unless (or (save-excursion
10066 (vhdl-prepare-search-1
10067 (and (not (bobp))
10068 (re-search-backward
10069 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10070 library "\\|end\\)\\>") nil t)
10071 (match-string 2))))
10072 (equal (downcase library) "work"))
10073 (vhdl-insert-keyword "LIBRARY ")
10074 (insert library ";")
10075 (when package
10076 (insert "\n")
10077 (indent-to margin))))
10078 (when package
10079 (vhdl-insert-keyword "USE ")
10080 (insert library "." package)
10081 (vhdl-insert-keyword ".ALL;"))))
10083 (defun vhdl-template-package-numeric-bit ()
10084 "Insert specification of `numeric_bit' package."
10085 (interactive)
10086 (vhdl-template-standard-package "ieee" "numeric_bit"))
10088 (defun vhdl-template-package-numeric-std ()
10089 "Insert specification of `numeric_std' package."
10090 (interactive)
10091 (vhdl-template-standard-package "ieee" "numeric_std"))
10093 (defun vhdl-template-package-std-logic-1164 ()
10094 "Insert specification of `std_logic_1164' package."
10095 (interactive)
10096 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10098 (defun vhdl-template-package-std-logic-arith ()
10099 "Insert specification of `std_logic_arith' package."
10100 (interactive)
10101 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10103 (defun vhdl-template-package-std-logic-misc ()
10104 "Insert specification of `std_logic_misc' package."
10105 (interactive)
10106 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10108 (defun vhdl-template-package-std-logic-signed ()
10109 "Insert specification of `std_logic_signed' package."
10110 (interactive)
10111 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10113 (defun vhdl-template-package-std-logic-textio ()
10114 "Insert specification of `std_logic_textio' package."
10115 (interactive)
10116 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10118 (defun vhdl-template-package-std-logic-unsigned ()
10119 "Insert specification of `std_logic_unsigned' package."
10120 (interactive)
10121 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10123 (defun vhdl-template-package-textio ()
10124 "Insert specification of `textio' package."
10125 (interactive)
10126 (vhdl-template-standard-package "std" "textio"))
10128 (defun vhdl-template-package-fundamental-constants ()
10129 "Insert specification of `fundamental_constants' package."
10130 (interactive)
10131 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10133 (defun vhdl-template-package-material-constants ()
10134 "Insert specification of `material_constants' package."
10135 (interactive)
10136 (vhdl-template-standard-package "ieee" "material_constants"))
10138 (defun vhdl-template-package-energy-systems ()
10139 "Insert specification of `energy_systems' package."
10140 (interactive)
10141 (vhdl-template-standard-package "ieee" "energy_systems"))
10143 (defun vhdl-template-package-electrical-systems ()
10144 "Insert specification of `electrical_systems' package."
10145 (interactive)
10146 (vhdl-template-standard-package "ieee" "electrical_systems"))
10148 (defun vhdl-template-package-mechanical-systems ()
10149 "Insert specification of `mechanical_systems' package."
10150 (interactive)
10151 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10153 (defun vhdl-template-package-radiant-systems ()
10154 "Insert specification of `radiant_systems' package."
10155 (interactive)
10156 (vhdl-template-standard-package "ieee" "radiant_systems"))
10158 (defun vhdl-template-package-thermal-systems ()
10159 "Insert specification of `thermal_systems' package."
10160 (interactive)
10161 (vhdl-template-standard-package "ieee" "thermal_systems"))
10163 (defun vhdl-template-package-fluidic-systems ()
10164 "Insert specification of `fluidic_systems' package."
10165 (interactive)
10166 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10168 (defun vhdl-template-package-math-complex ()
10169 "Insert specification of `math_complex' package."
10170 (interactive)
10171 (vhdl-template-standard-package "ieee" "math_complex"))
10173 (defun vhdl-template-package-math-real ()
10174 "Insert specification of `math_real' package."
10175 (interactive)
10176 (vhdl-template-standard-package "ieee" "math_real"))
10178 (defun vhdl-template-directive (directive)
10179 "Insert directive."
10180 (unless (= (current-indentation) (current-column))
10181 (delete-horizontal-space)
10182 (insert " "))
10183 (insert "-- pragma " directive))
10185 (defun vhdl-template-directive-translate-on ()
10186 "Insert directive 'translate_on'."
10187 (interactive)
10188 (vhdl-template-directive "translate_on"))
10190 (defun vhdl-template-directive-translate-off ()
10191 "Insert directive 'translate_off'."
10192 (interactive)
10193 (vhdl-template-directive "translate_off"))
10195 (defun vhdl-template-directive-synthesis-on ()
10196 "Insert directive 'synthesis_on'."
10197 (interactive)
10198 (vhdl-template-directive "synthesis_on"))
10200 (defun vhdl-template-directive-synthesis-off ()
10201 "Insert directive 'synthesis_off'."
10202 (interactive)
10203 (vhdl-template-directive "synthesis_off"))
10205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10206 ;; Header and footer templates
10208 (defun vhdl-template-header (&optional file-title)
10209 "Insert a VHDL file header."
10210 (interactive)
10211 (unless (equal vhdl-file-header "")
10212 (let (pos)
10213 (save-excursion
10214 (goto-char (point-min))
10215 (vhdl-insert-string-or-file vhdl-file-header)
10216 (setq pos (point-marker)))
10217 (vhdl-template-replace-header-keywords
10218 (point-min-marker) pos file-title))))
10220 (defun vhdl-template-footer ()
10221 "Insert a VHDL file footer."
10222 (interactive)
10223 (unless (equal vhdl-file-footer "")
10224 (let (pos)
10225 (save-excursion
10226 (goto-char (point-max))
10227 (setq pos (point-marker))
10228 (vhdl-insert-string-or-file vhdl-file-footer)
10229 (unless (= (preceding-char) ?\n)
10230 (insert "\n")))
10231 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10233 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10234 is-model)
10235 "Replace keywords in header and footer."
10236 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
10237 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
10238 pos)
10239 (vhdl-prepare-search-2
10240 (save-excursion
10241 (goto-char beg)
10242 (while (search-forward "<projectdesc>" end t)
10243 (replace-match project-desc t t))
10244 (goto-char beg)
10245 (while (search-forward "<filename>" end t)
10246 (replace-match (buffer-name) t t))
10247 (goto-char beg)
10248 (while (search-forward "<copyright>" end t)
10249 (replace-match vhdl-copyright-string t t))
10250 (goto-char beg)
10251 (while (search-forward "<author>" end t)
10252 (replace-match "" t t)
10253 (insert (user-full-name))
10254 (when user-mail-address (insert " <" user-mail-address ">")))
10255 (goto-char beg)
10256 (while (search-forward "<authorfull>" end t)
10257 (replace-match (user-full-name) t t))
10258 (goto-char beg)
10259 (while (search-forward "<login>" end t)
10260 (replace-match (user-login-name) t t))
10261 (goto-char beg)
10262 (while (search-forward "<project>" end t)
10263 (replace-match project-title t t))
10264 (goto-char beg)
10265 (while (search-forward "<company>" end t)
10266 (replace-match vhdl-company-name t t))
10267 (goto-char beg)
10268 (while (search-forward "<platform>" end t)
10269 (replace-match vhdl-platform-spec t t))
10270 (goto-char beg)
10271 (while (search-forward "<standard>" end t)
10272 (replace-match
10273 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10274 ((vhdl-standard-p '93) "'93/02"))
10275 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10276 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10277 (goto-char beg)
10278 ;; Replace <RCS> with $, so that RCS for the source is
10279 ;; not over-enthusiastic with replacements
10280 (while (search-forward "<RCS>" end t)
10281 (replace-match "$" nil t))
10282 (goto-char beg)
10283 (while (search-forward "<date>" end t)
10284 (replace-match "" t t)
10285 (vhdl-template-insert-date))
10286 (goto-char beg)
10287 (while (search-forward "<year>" end t)
10288 (replace-match (format-time-string "%Y" nil) t t))
10289 (goto-char beg)
10290 (when file-title
10291 (while (search-forward "<title string>" end t)
10292 (replace-match file-title t t))
10293 (goto-char beg))
10294 (let (string)
10295 (while
10296 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10297 (setq string (read-string (concat (match-string 1) ": ")))
10298 (replace-match string t t)))
10299 (goto-char beg)
10300 (when (and (not is-model) (search-forward "<cursor>" end t))
10301 (replace-match "" t t)
10302 (setq pos (point))))
10303 (when pos (goto-char pos))
10304 (unless is-model
10305 (when (or (not project-title) (equal project-title ""))
10306 (message "You can specify a project title in user option `vhdl-project-alist'"))
10307 (when (or (not project-desc) (equal project-desc ""))
10308 (message "You can specify a project description in user option `vhdl-project-alist'"))
10309 (when (equal vhdl-platform-spec "")
10310 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10311 (when (equal vhdl-company-name "")
10312 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10315 ;; Comment templates and functions
10317 (defun vhdl-comment-indent ()
10318 "Indent comments."
10319 (let* ((position (point))
10320 (col
10321 (progn
10322 (forward-line -1)
10323 (if (re-search-forward "--" position t)
10324 (- (current-column) 2) ; existing comment at bol stays there
10325 (goto-char position)
10326 (skip-chars-backward " \t")
10327 (max comment-column ; else indent to comment column
10328 (1+ (current-column))))))) ; except leave at least one space
10329 (goto-char position)
10330 col))
10332 (defun vhdl-comment-insert ()
10333 "Start a comment at the end of the line.
10334 If on line with code, indent at least `comment-column'.
10335 If starting after end-comment-column, start a new line."
10336 (interactive)
10337 (when (> (current-column) end-comment-column) (newline-and-indent))
10338 (if (or (looking-at "\\s-*$") ; end of line
10339 (and (not unread-command-events) ; called with key binding or menu
10340 (not (end-of-line))))
10341 (let (margin)
10342 (while (= (preceding-char) ?-) (delete-char -1))
10343 (setq margin (current-column))
10344 (delete-horizontal-space)
10345 (if (bolp)
10346 (progn (indent-to margin) (insert "--"))
10347 (insert " ")
10348 (indent-to comment-column)
10349 (insert "--"))
10350 (if (not unread-command-events) (insert " ")))
10351 ;; else code following current point implies commenting out code
10352 (let (next-input code)
10353 (while (= (preceding-char) ?-) (delete-char -2))
10354 (while (= (setq next-input (read-char)) 13) ; CR
10355 (insert "--") ; or have a space after it?
10356 (forward-char -2)
10357 (forward-line 1)
10358 (message "Enter CR if commenting out a line of code.")
10359 (setq code t))
10360 (unless code
10361 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10362 (setq unread-command-events
10363 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10365 (defun vhdl-comment-display (&optional line-exists)
10366 "Add 2 comment lines at the current indent, making a display comment."
10367 (interactive)
10368 (let ((margin (current-indentation)))
10369 (unless line-exists (vhdl-comment-display-line))
10370 (insert "\n") (indent-to margin)
10371 (insert "\n") (indent-to margin)
10372 (vhdl-comment-display-line)
10373 (end-of-line -0)
10374 (insert "-- ")))
10376 (defun vhdl-comment-display-line ()
10377 "Displays one line of dashes."
10378 (interactive)
10379 (while (= (preceding-char) ?-) (delete-char -2))
10380 (insert "--")
10381 (let* ((col (current-column))
10382 (len (- end-comment-column col)))
10383 (insert-char vhdl-comment-display-line-char len)))
10385 (defun vhdl-comment-append-inline ()
10386 "Append empty inline comment to current line."
10387 (interactive)
10388 (end-of-line)
10389 (delete-horizontal-space)
10390 (insert " ")
10391 (indent-to comment-column)
10392 (insert "-- "))
10394 (defun vhdl-comment-insert-inline (&optional string always-insert)
10395 "Insert inline comment."
10396 (when (or (and string (or vhdl-self-insert-comments always-insert))
10397 (and (not string) vhdl-prompt-for-comments))
10398 (let ((position (point)))
10399 (insert " ")
10400 (indent-to comment-column)
10401 (insert "-- ")
10402 (if (not (or (and string (progn (insert string) t))
10403 (vhdl-template-field "[comment]" nil t)))
10404 (delete-region position (point))
10405 (while (= (preceding-char) ?\ ) (delete-char -1))
10406 ;; (when (> (current-column) end-comment-column)
10407 ;; (setq position (point-marker))
10408 ;; (re-search-backward "-- ")
10409 ;; (insert "\n")
10410 ;; (indent-to comment-column)
10411 ;; (goto-char position))
10412 ))))
10414 (defun vhdl-comment-block ()
10415 "Insert comment for code block."
10416 (when vhdl-prompt-for-comments
10417 (let ((final-pos (point-marker)))
10418 (vhdl-prepare-search-2
10419 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10420 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10421 (let (margin)
10422 (back-to-indentation)
10423 (setq margin (current-column))
10424 (end-of-line -0)
10425 (if (bobp)
10426 (progn (insert "\n") (forward-line -1))
10427 (insert "\n"))
10428 (indent-to margin)
10429 (insert "-- purpose: ")
10430 (unless (vhdl-template-field "[description]" nil t)
10431 (vhdl-line-kill-entire)))))
10432 (goto-char final-pos))))
10434 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10435 "Comment out region if not commented out, uncomment otherwise."
10436 (interactive "r\nP")
10437 (save-excursion
10438 (goto-char (1- end))
10439 (end-of-line)
10440 (setq end (point-marker))
10441 (goto-char beg)
10442 (beginning-of-line)
10443 (setq beg (point))
10444 (if (looking-at (concat "\\s-*" comment-start))
10445 (comment-region beg end '(4))
10446 (comment-region beg end))))
10448 (defun vhdl-comment-uncomment-line (&optional arg)
10449 "Comment out line if not commented out, uncomment otherwise."
10450 (interactive "p")
10451 (save-excursion
10452 (beginning-of-line)
10453 (let ((position (point)))
10454 (forward-line (or arg 1))
10455 (vhdl-comment-uncomment-region position (point)))))
10457 (defun vhdl-comment-kill-region (beg end)
10458 "Kill comments in region."
10459 (interactive "r")
10460 (save-excursion
10461 (goto-char end)
10462 (setq end (point-marker))
10463 (goto-char beg)
10464 (beginning-of-line)
10465 (while (< (point) end)
10466 (if (looking-at "^\\(\\s-*--.*\n\\)")
10467 (progn (delete-region (match-beginning 1) (match-end 1)))
10468 (beginning-of-line 2)))))
10470 (defun vhdl-comment-kill-inline-region (beg end)
10471 "Kill inline comments in region."
10472 (interactive "r")
10473 (save-excursion
10474 (goto-char end)
10475 (setq end (point-marker))
10476 (goto-char beg)
10477 (beginning-of-line)
10478 (while (< (point) end)
10479 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10480 (delete-region (match-beginning 1) (match-end 1)))
10481 (beginning-of-line 2))))
10483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10484 ;; Subtemplates
10486 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10487 "Insert a begin ... end pair with optional name after the end.
10488 Point is left between them."
10489 (let (position)
10490 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10491 (indent-to margin)
10492 (vhdl-insert-keyword "BEGIN")
10493 (when (and (or construct name) vhdl-self-insert-comments)
10494 (insert " --")
10495 (when construct (insert " ") (vhdl-insert-keyword construct))
10496 (when name (insert " " name)))
10497 (insert "\n")
10498 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10499 (indent-to (+ margin vhdl-basic-offset))
10500 (setq position (point))
10501 (insert "\n")
10502 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10503 (indent-to margin)
10504 (vhdl-insert-keyword "END")
10505 (when construct (insert " ") (vhdl-insert-keyword construct))
10506 (insert (if name (concat " " name) "") ";")
10507 (goto-char position)))
10509 (defun vhdl-template-argument-list (&optional is-function)
10510 "Read from user a procedure or function argument list."
10511 (insert " (")
10512 (let ((margin (current-column))
10513 (start (point))
10514 (end-pos (point))
10515 not-empty interface semicolon-pos)
10516 (unless vhdl-argument-list-indent
10517 (setq margin (+ (current-indentation) vhdl-basic-offset))
10518 (insert "\n")
10519 (indent-to margin))
10520 (setq interface (vhdl-template-field
10521 (concat "[CONSTANT | SIGNAL"
10522 (unless is-function " | VARIABLE") "]") " " t))
10523 (while (vhdl-template-field "[names]" nil t)
10524 (setq not-empty t)
10525 (insert " : ")
10526 (unless is-function
10527 (if (and interface (equal (upcase interface) "CONSTANT"))
10528 (vhdl-insert-keyword "IN ")
10529 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10530 (vhdl-template-field "type")
10531 (setq semicolon-pos (point))
10532 (insert ";")
10533 (vhdl-comment-insert-inline)
10534 (setq end-pos (point))
10535 (insert "\n")
10536 (indent-to margin)
10537 (setq interface (vhdl-template-field
10538 (concat "[CONSTANT | SIGNAL"
10539 (unless is-function " | VARIABLE") "]") " " t)))
10540 (delete-region end-pos (point))
10541 (when semicolon-pos (goto-char semicolon-pos))
10542 (if not-empty
10543 (progn (delete-char 1) (insert ")"))
10544 (delete-char -2))))
10546 (defun vhdl-template-generic-list (optional &optional no-value)
10547 "Read from user a generic spec argument list."
10548 (let (margin
10549 (start (point)))
10550 (vhdl-insert-keyword "GENERIC (")
10551 (setq margin (current-column))
10552 (unless vhdl-argument-list-indent
10553 (let ((position (point)))
10554 (back-to-indentation)
10555 (setq margin (+ (current-column) vhdl-basic-offset))
10556 (goto-char position)
10557 (insert "\n")
10558 (indent-to margin)))
10559 (let ((vhdl-generics (vhdl-template-field
10560 (concat (and optional "[") "name"
10561 (and no-value "s") (and optional "]"))
10562 nil optional)))
10563 (if (not vhdl-generics)
10564 (if optional
10565 (progn (vhdl-line-kill-entire) (end-of-line -0)
10566 (unless vhdl-argument-list-indent
10567 (vhdl-line-kill-entire) (end-of-line -0)))
10568 (vhdl-template-undo start (point))
10569 nil )
10570 (insert " : ")
10571 (let (semicolon-pos end-pos)
10572 (while vhdl-generics
10573 (vhdl-template-field "type")
10574 (if no-value
10575 (progn (setq semicolon-pos (point))
10576 (insert ";"))
10577 (insert " := ")
10578 (unless (vhdl-template-field "[value]" nil t)
10579 (delete-char -4))
10580 (setq semicolon-pos (point))
10581 (insert ";"))
10582 (vhdl-comment-insert-inline)
10583 (setq end-pos (point))
10584 (insert "\n")
10585 (indent-to margin)
10586 (setq vhdl-generics (vhdl-template-field
10587 (concat "[name" (and no-value "s") "]")
10588 " : " t)))
10589 (delete-region end-pos (point))
10590 (goto-char semicolon-pos)
10591 (insert ")")
10592 (end-of-line)
10593 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10594 t)))))
10596 (defun vhdl-template-port-list (optional)
10597 "Read from user a port spec argument list."
10598 (let ((start (point))
10599 margin vhdl-ports object)
10600 (vhdl-insert-keyword "PORT (")
10601 (setq margin (current-column))
10602 (unless vhdl-argument-list-indent
10603 (let ((position (point)))
10604 (back-to-indentation)
10605 (setq margin (+ (current-column) vhdl-basic-offset))
10606 (goto-char position)
10607 (insert "\n")
10608 (indent-to margin)))
10609 (when (vhdl-standard-p 'ams)
10610 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10611 " " t)))
10612 (setq vhdl-ports (vhdl-template-field
10613 (concat (and optional "[") "names" (and optional "]"))
10614 nil optional))
10615 (if (not vhdl-ports)
10616 (if optional
10617 (progn (vhdl-line-kill-entire) (end-of-line -0)
10618 (unless vhdl-argument-list-indent
10619 (vhdl-line-kill-entire) (end-of-line -0)))
10620 (vhdl-template-undo start (point))
10621 nil)
10622 (insert " : ")
10623 (let (semicolon-pos end-pos)
10624 (while vhdl-ports
10625 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10626 (vhdl-template-field "IN | OUT | INOUT" " "))
10627 ((equal "QUANTITY" (upcase object))
10628 (vhdl-template-field "[IN | OUT]" " " t)))
10629 (vhdl-template-field
10630 (if (and object (equal "TERMINAL" (upcase object)))
10631 "nature" "type"))
10632 (setq semicolon-pos (point))
10633 (insert ";")
10634 (vhdl-comment-insert-inline)
10635 (setq end-pos (point))
10636 (insert "\n")
10637 (indent-to margin)
10638 (when (vhdl-standard-p 'ams)
10639 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10640 " " t)))
10641 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10642 (delete-region end-pos (point))
10643 (goto-char semicolon-pos)
10644 (insert ")")
10645 (end-of-line)
10646 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10647 t))))
10649 (defun vhdl-template-generate-body (margin label)
10650 "Insert body for generate template."
10651 (vhdl-insert-keyword " GENERATE")
10652 ; (if (not (vhdl-standard-p '87))
10653 ; (vhdl-template-begin-end "GENERATE" label margin)
10654 (insert "\n\n")
10655 (indent-to margin)
10656 (vhdl-insert-keyword "END GENERATE ")
10657 (insert label ";")
10658 (end-of-line 0)
10659 (indent-to (+ margin vhdl-basic-offset)))
10661 (defun vhdl-template-insert-date ()
10662 "Insert date in appropriate format."
10663 (interactive)
10664 (insert
10665 (cond
10666 ;; 'american, 'european, 'scientific kept for backward compatibility
10667 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10668 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10669 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10670 (t (format-time-string vhdl-date-format nil)))))
10672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10673 ;; Help functions
10675 (defun vhdl-electric-space (count)
10676 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10677 if in comment and past end-comment-column."
10678 (interactive "p")
10679 (cond ((vhdl-in-comment-p)
10680 (self-insert-command count)
10681 (cond ((>= (current-column) (+ 2 end-comment-column))
10682 (backward-char 1)
10683 (skip-chars-backward "^ \t\n\r\f")
10684 (indent-new-comment-line)
10685 (skip-chars-forward "^ \t\n\r\f")
10686 (forward-char 1))
10687 ((>= (current-column) end-comment-column)
10688 (indent-new-comment-line))
10689 (t nil)))
10690 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10691 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10692 (vhdl-prepare-search-1
10693 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10694 (self-insert-command count))
10695 (t (self-insert-command count))))
10697 (defun vhdl-template-field (prompt &optional follow-string optional
10698 begin end is-string default)
10699 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10700 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10701 an empty string is inserted, return nil and call `vhdl-template-undo' for
10702 the region between BEGIN and END. IS-STRING indicates whether a string
10703 with double-quotes is to be inserted. DEFAULT specifies a default string."
10704 (let ((position (point))
10705 string)
10706 (insert "<" prompt ">")
10707 (setq string
10708 (condition-case ()
10709 (read-from-minibuffer (concat prompt ": ")
10710 (or (and is-string '("\"\"" . 2)) default)
10711 vhdl-minibuffer-local-map)
10712 (quit (if (and optional begin end)
10713 (progn (beep) "")
10714 (keyboard-quit)))))
10715 (when (or (not (equal string "")) optional)
10716 (delete-region position (point)))
10717 (when (and (equal string "") optional begin end)
10718 (vhdl-template-undo begin end)
10719 (message "Template aborted"))
10720 (unless (equal string "")
10721 (insert string)
10722 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10723 vhdl-keywords-regexp)
10724 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10725 vhdl-types-regexp)
10726 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10727 (concat "'" vhdl-attributes-regexp))
10728 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10729 vhdl-enum-values-regexp)
10730 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
10731 vhdl-constants-regexp))
10732 (when (or (not (equal string "")) (not optional))
10733 (insert (or follow-string "")))
10734 (if (equal string "") nil string)))
10736 (defun vhdl-decision-query (string prompt &optional optional)
10737 "Query a decision from the user."
10738 (let ((start (point)))
10739 (when string (vhdl-insert-keyword (concat string " ")))
10740 (message "%s" (or prompt ""))
10741 (let ((char (read-char)))
10742 (delete-region start (point))
10743 (if (and optional (eq char ?\r))
10744 (progn (insert " ")
10745 (unexpand-abbrev)
10746 (throw 'abort "ERROR: Template aborted"))
10747 char))))
10749 (defun vhdl-insert-keyword (keyword)
10750 "Insert KEYWORD and adjust case."
10751 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10753 (defun vhdl-case-keyword (keyword)
10754 "Adjust case of KEYWORD."
10755 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10757 (defun vhdl-case-word (num)
10758 "Adjust case of following NUM words."
10759 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10761 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10762 "If preceding character is part of a word or a paren then hippie-expand,
10763 else insert tab (used for word completion in VHDL minibuffer)."
10764 (interactive "P")
10765 (cond
10766 ;; expand word
10767 ((= (char-syntax (preceding-char)) ?w)
10768 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10769 (case-replace nil)
10770 (hippie-expand-only-buffers
10771 (or (and (boundp 'hippie-expand-only-buffers)
10772 hippie-expand-only-buffers)
10773 '(vhdl-mode))))
10774 (vhdl-expand-abbrev prefix-arg)))
10775 ;; expand parenthesis
10776 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10777 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10778 (case-replace nil))
10779 (vhdl-expand-paren prefix-arg)))
10780 ;; insert tab
10781 (t (insert-tab))))
10783 (defun vhdl-template-search-prompt ()
10784 "Search for left out template prompts and query again."
10785 (interactive)
10786 (vhdl-prepare-search-2
10787 (when (or (re-search-forward
10788 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10789 (re-search-backward
10790 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10791 (let ((string (match-string 1)))
10792 (replace-match "")
10793 (vhdl-template-field string)))))
10795 (defun vhdl-template-undo (begin end)
10796 "Undo aborted template by deleting region and unexpanding the keyword."
10797 (cond (vhdl-template-invoked-by-hook
10798 (goto-char end)
10799 (insert " ")
10800 (delete-region begin end)
10801 (unexpand-abbrev))
10802 (t (delete-region begin end))))
10804 (defun vhdl-insert-string-or-file (string)
10805 "Insert STRING or file contents if STRING is an existing file name."
10806 (unless (equal string "")
10807 (let ((file-name
10808 (progn (string-match "^\\([^\n]+\\)" string)
10809 (vhdl-resolve-env-variable (match-string 1 string)))))
10810 (if (file-exists-p file-name)
10811 (forward-char (cadr (insert-file-contents file-name)))
10812 (insert string)))))
10814 (defun vhdl-beginning-of-block ()
10815 "Move cursor to the beginning of the enclosing block."
10816 (let (pos)
10817 (vhdl-prepare-search-2
10818 (save-excursion
10819 (beginning-of-line)
10820 ;; search backward for block beginning or end
10821 (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
10822 ;; not consider subprogram declarations
10823 (or (and (match-string 5)
10824 (save-match-data
10825 (save-excursion
10826 (goto-char (match-end 5))
10827 (forward-word 1)
10828 (vhdl-forward-syntactic-ws)
10829 (when (looking-at "(")
10830 (forward-sexp))
10831 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10832 (match-string 1)))
10833 ;; not consider configuration specifications
10834 (and (match-string 6)
10835 (save-match-data
10836 (save-excursion
10837 (vhdl-end-of-block)
10838 (beginning-of-line)
10839 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10840 (match-string 2))
10841 ;; skip subblock if block end found
10842 (vhdl-beginning-of-block))))
10843 (when pos (goto-char pos))))
10845 (defun vhdl-end-of-block ()
10846 "Move cursor to the end of the enclosing block."
10847 (let (pos)
10848 (vhdl-prepare-search-2
10849 (save-excursion
10850 (end-of-line)
10851 ;; search forward for block beginning or end
10852 (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
10853 ;; not consider subprogram declarations
10854 (or (and (match-string 5)
10855 (save-match-data
10856 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10857 (match-string 1)))
10858 ;; not consider configuration specifications
10859 (and (match-string 6)
10860 (save-match-data
10861 (save-excursion
10862 (vhdl-end-of-block)
10863 (beginning-of-line)
10864 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10865 (not (match-string 2)))
10866 ;; skip subblock if block beginning found
10867 (vhdl-end-of-block))))
10868 (when pos (goto-char pos))))
10870 (defun vhdl-sequential-statement-p ()
10871 "Check if point is within sequential statement part."
10872 (let ((start (point)))
10873 (save-excursion
10874 (vhdl-prepare-search-2
10875 ;; is sequential statement if ...
10876 (and (re-search-backward "^\\s-*begin\\>" nil t)
10877 ;; ... point is between "begin" and "end" of ...
10878 (progn (vhdl-end-of-block)
10879 (< start (point)))
10880 ;; ... a sequential block
10881 (progn (vhdl-beginning-of-block)
10882 (looking-at "^\\s-*\\(\\(\\w+[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(\\w+[ \t\n\r\f]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10884 (defun vhdl-in-argument-list-p ()
10885 "Check if within an argument list."
10886 (save-excursion
10887 (vhdl-prepare-search-2
10888 (or (string-match "arglist"
10889 (format "%s" (caar (vhdl-get-syntactic-context))))
10890 (progn (beginning-of-line)
10891 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10893 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10894 ;; Abbrev hooks
10896 (defun vhdl-hooked-abbrev (func)
10897 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10898 but not if inside a comment or quote."
10899 (if (or (vhdl-in-literal)
10900 (save-excursion
10901 (forward-word -1)
10902 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10903 (progn
10904 (insert " ")
10905 (unexpand-abbrev)
10906 (backward-word 1)
10907 (vhdl-case-word 1)
10908 (delete-char 1))
10909 (if (not vhdl-electric-mode)
10910 (progn
10911 (insert " ")
10912 (unexpand-abbrev)
10913 (backward-word 1)
10914 (vhdl-case-word 1)
10915 (delete-char 1))
10916 (let ((invoke-char last-command-event)
10917 (abbrev-mode -1)
10918 (vhdl-template-invoked-by-hook t))
10919 (let ((caught (catch 'abort
10920 (funcall func))))
10921 (when (stringp caught) (message "%s" caught)))
10922 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10923 ;; delete CR which is still in event queue
10924 (if (fboundp 'enqueue-eval-event)
10925 (enqueue-eval-event 'delete-char -1)
10926 (setq unread-command-events ; push back a delete char
10927 (list (vhdl-character-to-event ?\177))))))))
10929 (defun vhdl-template-alias-hook ()
10930 (vhdl-hooked-abbrev 'vhdl-template-alias))
10931 (defun vhdl-template-architecture-hook ()
10932 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10933 (defun vhdl-template-assert-hook ()
10934 (vhdl-hooked-abbrev 'vhdl-template-assert))
10935 (defun vhdl-template-attribute-hook ()
10936 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10937 (defun vhdl-template-block-hook ()
10938 (vhdl-hooked-abbrev 'vhdl-template-block))
10939 (defun vhdl-template-break-hook ()
10940 (vhdl-hooked-abbrev 'vhdl-template-break))
10941 (defun vhdl-template-case-hook ()
10942 (vhdl-hooked-abbrev 'vhdl-template-case))
10943 (defun vhdl-template-component-hook ()
10944 (vhdl-hooked-abbrev 'vhdl-template-component))
10945 (defun vhdl-template-instance-hook ()
10946 (vhdl-hooked-abbrev 'vhdl-template-instance))
10947 (defun vhdl-template-conditional-signal-asst-hook ()
10948 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10949 (defun vhdl-template-configuration-hook ()
10950 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10951 (defun vhdl-template-constant-hook ()
10952 (vhdl-hooked-abbrev 'vhdl-template-constant))
10953 (defun vhdl-template-disconnect-hook ()
10954 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10955 (defun vhdl-template-display-comment-hook ()
10956 (vhdl-hooked-abbrev 'vhdl-comment-display))
10957 (defun vhdl-template-else-hook ()
10958 (vhdl-hooked-abbrev 'vhdl-template-else))
10959 (defun vhdl-template-elsif-hook ()
10960 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10961 (defun vhdl-template-entity-hook ()
10962 (vhdl-hooked-abbrev 'vhdl-template-entity))
10963 (defun vhdl-template-exit-hook ()
10964 (vhdl-hooked-abbrev 'vhdl-template-exit))
10965 (defun vhdl-template-file-hook ()
10966 (vhdl-hooked-abbrev 'vhdl-template-file))
10967 (defun vhdl-template-for-hook ()
10968 (vhdl-hooked-abbrev 'vhdl-template-for))
10969 (defun vhdl-template-function-hook ()
10970 (vhdl-hooked-abbrev 'vhdl-template-function))
10971 (defun vhdl-template-generic-hook ()
10972 (vhdl-hooked-abbrev 'vhdl-template-generic))
10973 (defun vhdl-template-group-hook ()
10974 (vhdl-hooked-abbrev 'vhdl-template-group))
10975 (defun vhdl-template-library-hook ()
10976 (vhdl-hooked-abbrev 'vhdl-template-library))
10977 (defun vhdl-template-limit-hook ()
10978 (vhdl-hooked-abbrev 'vhdl-template-limit))
10979 (defun vhdl-template-if-hook ()
10980 (vhdl-hooked-abbrev 'vhdl-template-if))
10981 (defun vhdl-template-bare-loop-hook ()
10982 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10983 (defun vhdl-template-map-hook ()
10984 (vhdl-hooked-abbrev 'vhdl-template-map))
10985 (defun vhdl-template-nature-hook ()
10986 (vhdl-hooked-abbrev 'vhdl-template-nature))
10987 (defun vhdl-template-next-hook ()
10988 (vhdl-hooked-abbrev 'vhdl-template-next))
10989 (defun vhdl-template-others-hook ()
10990 (vhdl-hooked-abbrev 'vhdl-template-others))
10991 (defun vhdl-template-package-hook ()
10992 (vhdl-hooked-abbrev 'vhdl-template-package))
10993 (defun vhdl-template-port-hook ()
10994 (vhdl-hooked-abbrev 'vhdl-template-port))
10995 (defun vhdl-template-procedural-hook ()
10996 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10997 (defun vhdl-template-procedure-hook ()
10998 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10999 (defun vhdl-template-process-hook ()
11000 (vhdl-hooked-abbrev 'vhdl-template-process))
11001 (defun vhdl-template-quantity-hook ()
11002 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11003 (defun vhdl-template-report-hook ()
11004 (vhdl-hooked-abbrev 'vhdl-template-report))
11005 (defun vhdl-template-return-hook ()
11006 (vhdl-hooked-abbrev 'vhdl-template-return))
11007 (defun vhdl-template-selected-signal-asst-hook ()
11008 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11009 (defun vhdl-template-signal-hook ()
11010 (vhdl-hooked-abbrev 'vhdl-template-signal))
11011 (defun vhdl-template-subnature-hook ()
11012 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11013 (defun vhdl-template-subtype-hook ()
11014 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11015 (defun vhdl-template-terminal-hook ()
11016 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11017 (defun vhdl-template-type-hook ()
11018 (vhdl-hooked-abbrev 'vhdl-template-type))
11019 (defun vhdl-template-use-hook ()
11020 (vhdl-hooked-abbrev 'vhdl-template-use))
11021 (defun vhdl-template-variable-hook ()
11022 (vhdl-hooked-abbrev 'vhdl-template-variable))
11023 (defun vhdl-template-wait-hook ()
11024 (vhdl-hooked-abbrev 'vhdl-template-wait))
11025 (defun vhdl-template-when-hook ()
11026 (vhdl-hooked-abbrev 'vhdl-template-when))
11027 (defun vhdl-template-while-loop-hook ()
11028 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11029 (defun vhdl-template-with-hook ()
11030 (vhdl-hooked-abbrev 'vhdl-template-with))
11031 (defun vhdl-template-and-hook ()
11032 (vhdl-hooked-abbrev 'vhdl-template-and))
11033 (defun vhdl-template-or-hook ()
11034 (vhdl-hooked-abbrev 'vhdl-template-or))
11035 (defun vhdl-template-nand-hook ()
11036 (vhdl-hooked-abbrev 'vhdl-template-nand))
11037 (defun vhdl-template-nor-hook ()
11038 (vhdl-hooked-abbrev 'vhdl-template-nor))
11039 (defun vhdl-template-xor-hook ()
11040 (vhdl-hooked-abbrev 'vhdl-template-xor))
11041 (defun vhdl-template-xnor-hook ()
11042 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11043 (defun vhdl-template-not-hook ()
11044 (vhdl-hooked-abbrev 'vhdl-template-not))
11046 (defun vhdl-template-default-hook ()
11047 (vhdl-hooked-abbrev 'vhdl-template-default))
11048 (defun vhdl-template-default-indent-hook ()
11049 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11052 ;; Template insertion from completion list
11054 (defun vhdl-template-insert-construct (name)
11055 "Insert the built-in construct template with NAME."
11056 (interactive
11057 (list (let ((completion-ignore-case t))
11058 (completing-read "Construct name: "
11059 vhdl-template-construct-alist nil t))))
11060 (vhdl-template-insert-fun
11061 (cadr (assoc name vhdl-template-construct-alist))))
11063 (defun vhdl-template-insert-package (name)
11064 "Insert the built-in package template with NAME."
11065 (interactive
11066 (list (let ((completion-ignore-case t))
11067 (completing-read "Package name: "
11068 vhdl-template-package-alist nil t))))
11069 (vhdl-template-insert-fun
11070 (cadr (assoc name vhdl-template-package-alist))))
11072 (defun vhdl-template-insert-directive (name)
11073 "Insert the built-in directive template with NAME."
11074 (interactive
11075 (list (let ((completion-ignore-case t))
11076 (completing-read "Directive name: "
11077 vhdl-template-directive-alist nil t))))
11078 (vhdl-template-insert-fun
11079 (cadr (assoc name vhdl-template-directive-alist))))
11081 (defun vhdl-template-insert-fun (fun)
11082 "Call FUN to insert a built-in template."
11083 (let ((caught (catch 'abort (when fun (funcall fun)))))
11084 (when (stringp caught) (message "%s" caught))))
11087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11088 ;;; Models
11089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11091 (defun vhdl-model-insert (model-name)
11092 "Insert the user model with name MODEL-NAME."
11093 (interactive
11094 (let ((completion-ignore-case t))
11095 (list (completing-read "Model name: " vhdl-model-alist))))
11096 (indent-according-to-mode)
11097 (let ((start (point-marker))
11098 (margin (current-indentation))
11099 model position prompt string end)
11100 (vhdl-prepare-search-2
11101 (when (setq model (assoc model-name vhdl-model-alist))
11102 ;; insert model
11103 (beginning-of-line)
11104 (delete-horizontal-space)
11105 (goto-char start)
11106 (vhdl-insert-string-or-file (nth 1 model))
11107 (setq end (point-marker))
11108 ;; indent code
11109 (goto-char start)
11110 (beginning-of-line)
11111 (while (< (point) end)
11112 (unless (looking-at "^$")
11113 (insert-char ? margin))
11114 (beginning-of-line 2))
11115 (goto-char start)
11116 ;; insert clock
11117 (unless (equal "" vhdl-clock-name)
11118 (while (re-search-forward "<clock>" end t)
11119 (replace-match vhdl-clock-name)))
11120 (goto-char start)
11121 ;; insert reset
11122 (unless (equal "" vhdl-reset-name)
11123 (while (re-search-forward "<reset>" end t)
11124 (replace-match vhdl-reset-name)))
11125 ;; replace header prompts
11126 (vhdl-template-replace-header-keywords start end nil t)
11127 (goto-char start)
11128 ;; query other prompts
11129 (while (re-search-forward
11130 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11131 (unless (equal "cursor" (match-string 1))
11132 (setq position (match-beginning 1))
11133 (setq prompt (match-string 1))
11134 (replace-match "")
11135 (setq string (vhdl-template-field prompt nil t))
11136 ;; replace occurrences of same prompt
11137 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11138 (replace-match (or string "")))
11139 (goto-char position)))
11140 (goto-char start)
11141 ;; goto final position
11142 (if (re-search-forward "<cursor>" end t)
11143 (replace-match "")
11144 (goto-char end))))))
11146 (defun vhdl-model-defun ()
11147 "Define help and hook functions for user models."
11148 (let ((model-alist vhdl-model-alist)
11149 model-name model-keyword)
11150 (while model-alist
11151 ;; define functions for user models that can be invoked from menu and key
11152 ;; bindings and which themselves call `vhdl-model-insert' with the model
11153 ;; name as argument
11154 (setq model-name (nth 0 (car model-alist)))
11155 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11156 ,(concat "Insert model for \"" model-name "\".")
11157 (interactive)
11158 (vhdl-model-insert ,model-name)))
11159 ;; define hooks for user models that are invoked from keyword abbrevs
11160 (setq model-keyword (nth 3 (car model-alist)))
11161 (unless (equal model-keyword "")
11162 (eval `(defun
11163 ,(vhdl-function-name
11164 "vhdl-model" model-name "hook") ()
11165 (vhdl-hooked-abbrev
11166 ',(vhdl-function-name "vhdl-model" model-name)))))
11167 (setq model-alist (cdr model-alist)))))
11169 (vhdl-model-defun)
11172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11173 ;;; Port translation
11174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11176 (defvar vhdl-port-list nil
11177 "Variable to hold last port map parsed.")
11178 ;; structure: (parenthesized expression means list of such entries)
11179 ;; (ent-name
11180 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11181 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11182 ;; (lib-name pack-key))
11184 (defun vhdl-parse-string (string &optional optional)
11185 "Check that the text following point matches the regexp in STRING."
11186 (if (looking-at string)
11187 (progn (goto-char (match-end 0))
11188 (when (vhdl-in-literal)
11189 (end-of-line))
11190 (point))
11191 (unless optional
11192 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11193 (vhdl-current-line) string)))
11194 nil))
11196 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11197 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11198 (vhdl-prepare-search-1
11199 (if (string-match (car regexp-cons) string)
11200 (if adjust-case
11201 (funcall vhdl-file-name-case
11202 (replace-match (cdr regexp-cons) t nil string))
11203 (replace-match (cdr regexp-cons) t nil string))
11204 string)))
11206 (defun vhdl-parse-group-comment ()
11207 "Parse comment and empty lines between groups of lines."
11208 (let ((start (point))
11209 string)
11210 (vhdl-forward-comment (point-max))
11211 (setq string (buffer-substring-no-properties start (point)))
11212 (vhdl-forward-syntactic-ws)
11213 ;; strip off leading blanks and first newline
11214 (while (string-match "^\\(\\s-+\\)" string)
11215 (setq string (concat (substring string 0 (match-beginning 1))
11216 (substring string (match-end 1)))))
11217 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11218 (substring string 1)
11219 string)))
11221 (defun vhdl-paste-group-comment (string indent)
11222 "Paste comment and empty lines from STRING between groups of lines
11223 with INDENT."
11224 (let ((pos (point-marker)))
11225 (when (> indent 0)
11226 (while (string-match "^\\(--\\)" string)
11227 (setq string (concat (substring string 0 (match-beginning 1))
11228 (make-string indent ? )
11229 (substring string (match-beginning 1))))))
11230 (beginning-of-line)
11231 (insert string)
11232 (goto-char pos)))
11234 (defvar vhdl-port-flattened nil
11235 "Indicates whether a port has been flattened.")
11237 (defun vhdl-port-flatten (&optional as-alist)
11238 "Flatten port list so that only one generic/port exists per line.
11239 This operation is performed on an internally stored port and is only
11240 reflected in a subsequent paste operation."
11241 (interactive)
11242 (if (not vhdl-port-list)
11243 (error "ERROR: No port has been read")
11244 (message "Flattening port for next paste...")
11245 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11246 (old-vhdl-port-list (cdr vhdl-port-list))
11247 old-port-list new-port-list old-port new-port names)
11248 ;; traverse port list and flatten entries
11249 (while (cdr old-vhdl-port-list)
11250 (setq old-port-list (car old-vhdl-port-list))
11251 (setq new-port-list nil)
11252 (while old-port-list
11253 (setq old-port (car old-port-list))
11254 (setq names (car old-port))
11255 (while names
11256 (setq new-port (cons (if as-alist (car names) (list (car names)))
11257 (cdr old-port)))
11258 (setq new-port-list (append new-port-list (list new-port)))
11259 (setq names (cdr names)))
11260 (setq old-port-list (cdr old-port-list)))
11261 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11262 (setq new-vhdl-port-list (append new-vhdl-port-list
11263 (list new-port-list))))
11264 (setq vhdl-port-list
11265 (append new-vhdl-port-list (list old-vhdl-port-list))
11266 vhdl-port-flattened t)
11267 (message "Flattening port for next paste...done"))))
11269 (defvar vhdl-port-reversed-direction nil
11270 "Indicates whether port directions are reversed.")
11272 (defun vhdl-port-reverse-direction ()
11273 "Reverse direction for all ports (useful in testbenches).
11274 This operation is performed on an internally stored port and is only
11275 reflected in a subsequent paste operation."
11276 (interactive)
11277 (if (not vhdl-port-list)
11278 (error "ERROR: No port has been read")
11279 (message "Reversing port directions for next paste...")
11280 (let ((port-list (nth 2 vhdl-port-list))
11281 port-dir-car port-dir)
11282 ;; traverse port list and reverse directions
11283 (while port-list
11284 (setq port-dir-car (cddr (car port-list))
11285 port-dir (car port-dir-car))
11286 (setcar port-dir-car
11287 (cond ((equal port-dir "in") "out")
11288 ((equal port-dir "IN") "OUT")
11289 ((equal port-dir "out") "in")
11290 ((equal port-dir "OUT") "IN")
11291 (t port-dir)))
11292 (setq port-list (cdr port-list)))
11293 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11294 (message "Reversing port directions for next paste...done"))))
11296 (defun vhdl-port-copy ()
11297 "Get generic and port information from an entity or component declaration."
11298 (interactive)
11299 (save-excursion
11300 (let (parse-error end-of-list
11301 decl-type name generic-list port-list context-clause
11302 object names direct type init comment group-comment)
11303 (vhdl-prepare-search-2
11304 (setq
11305 parse-error
11306 (catch 'parse
11307 ;; check if within entity or component declaration
11308 (end-of-line)
11309 (when (or (not (re-search-backward
11310 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11311 (equal "END" (upcase (match-string 1))))
11312 (throw 'parse "ERROR: Not within an entity or component declaration"))
11313 (setq decl-type (downcase (match-string-no-properties 1)))
11314 (forward-word 1)
11315 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11316 (setq name (match-string-no-properties 1))
11317 (message "Reading port of %s \"%s\"..." decl-type name)
11318 (vhdl-forward-syntactic-ws)
11319 ;; parse generic clause
11320 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11321 ;; parse group comment and spacing
11322 (setq group-comment (vhdl-parse-group-comment))
11323 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11324 (while (not end-of-list)
11325 ;; parse names (accept extended identifiers)
11326 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11327 (setq names (list (match-string-no-properties 1)))
11328 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11329 (setq names
11330 (append names (list (match-string-no-properties 1)))))
11331 ;; parse type
11332 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11333 (setq type (match-string-no-properties 1))
11334 (when (vhdl-in-comment-p) ; if stuck in comment
11335 (setq type (concat type (and (vhdl-parse-string ".*")
11336 (match-string-no-properties 0)))))
11337 (setq comment nil)
11338 (while (looking-at "(")
11339 (setq type
11340 (concat type
11341 (buffer-substring-no-properties
11342 (point) (progn (forward-sexp) (point)))
11343 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11344 (match-string-no-properties 1)))))
11345 ;; special case: closing parenthesis is on separate line
11346 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11347 (setq comment (substring type (match-beginning 2)))
11348 (setq type (substring type 0 (match-beginning 1))))
11349 ;; strip of trailing group-comment
11350 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11351 (setq type (substring type 0 (match-end 1)))
11352 ;; parse initialization expression
11353 (setq init nil)
11354 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11355 (vhdl-parse-string "\\([^();\n]*\\)")
11356 (setq init (match-string-no-properties 1))
11357 (while (looking-at "(")
11358 (setq init
11359 (concat init
11360 (buffer-substring-no-properties
11361 (point) (progn (forward-sexp) (point)))
11362 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11363 (match-string-no-properties 1))))))
11364 ;; special case: closing parenthesis is on separate line
11365 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11366 (setq comment (substring init (match-beginning 2)))
11367 (setq init (substring init 0 (match-beginning 1)))
11368 (vhdl-forward-syntactic-ws))
11369 (skip-chars-forward " \t")
11370 ;; parse inline comment, special case: as above, no initial.
11371 (unless comment
11372 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11373 (match-string-no-properties 1))))
11374 (vhdl-forward-syntactic-ws)
11375 (setq end-of-list (vhdl-parse-string ")" t))
11376 (vhdl-parse-string "\\s-*;\\s-*")
11377 ;; parse inline comment
11378 (unless comment
11379 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11380 (match-string-no-properties 1))))
11381 ;; save everything in list
11382 (setq generic-list (append generic-list
11383 (list (list names type init
11384 comment group-comment))))
11385 ;; parse group comment and spacing
11386 (setq group-comment (vhdl-parse-group-comment))))
11387 ;; parse port clause
11388 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11389 ;; parse group comment and spacing
11390 (setq group-comment (vhdl-parse-group-comment))
11391 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11392 (while (not end-of-list)
11393 ;; parse object
11394 (setq object
11395 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11396 (match-string-no-properties 1)))
11397 ;; parse names (accept extended identifiers)
11398 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11399 (setq names (list (match-string-no-properties 1)))
11400 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11401 (setq names (append names (list (match-string-no-properties 1)))))
11402 ;; parse direction
11403 (vhdl-parse-string ":[ \t\n\r\f]*")
11404 (setq direct
11405 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11406 (match-string-no-properties 1)))
11407 ;; parse type
11408 (vhdl-parse-string "\\([^();\n]+\\)")
11409 (setq type (match-string-no-properties 1))
11410 (when (vhdl-in-comment-p) ; if stuck in comment
11411 (setq type (concat type (and (vhdl-parse-string ".*")
11412 (match-string-no-properties 0)))))
11413 (setq comment nil)
11414 (while (looking-at "(")
11415 (setq type (concat type
11416 (buffer-substring-no-properties
11417 (point) (progn (forward-sexp) (point)))
11418 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11419 (match-string-no-properties 1)))))
11420 ;; special case: closing parenthesis is on separate line
11421 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11422 (setq comment (substring type (match-beginning 2)))
11423 (setq type (substring type 0 (match-beginning 1))))
11424 ;; strip of trailing group-comment
11425 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11426 (setq type (substring type 0 (match-end 1)))
11427 (vhdl-forward-syntactic-ws)
11428 (setq end-of-list (vhdl-parse-string ")" t))
11429 (vhdl-parse-string "\\s-*;\\s-*")
11430 ;; parse inline comment
11431 (unless comment
11432 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11433 (match-string-no-properties 1))))
11434 ;; save everything in list
11435 (setq port-list (append port-list
11436 (list (list names object direct type
11437 comment group-comment))))
11438 ;; parse group comment and spacing
11439 (setq group-comment (vhdl-parse-group-comment))))
11440 ; (vhdl-parse-string "end\\>")
11441 ;; parse context clause
11442 (setq context-clause (vhdl-scan-context-clause))
11443 ; ;; add surrounding package to context clause
11444 ; (when (and (equal decl-type "component")
11445 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11446 ; (setq context-clause
11447 ; (append context-clause
11448 ; (list (cons (vhdl-work-library)
11449 ; (match-string-no-properties 1))))))
11450 (message "Reading port of %s \"%s\"...done" decl-type name)
11451 nil)))
11452 ;; finish parsing
11453 (if parse-error
11454 (error parse-error)
11455 (setq vhdl-port-list (list name generic-list port-list context-clause)
11456 vhdl-port-reversed-direction nil
11457 vhdl-port-flattened nil)))))
11459 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11460 "Paste a context clause."
11461 (let ((margin (current-indentation))
11462 (clause-list (nth 3 vhdl-port-list))
11463 clause)
11464 (while clause-list
11465 (setq clause (car clause-list))
11466 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11467 (downcase exclude-pack-name)))
11468 (save-excursion
11469 (re-search-backward
11470 (concat "^\\s-*use\\s-+" (car clause)
11471 "\." (cdr clause) "\\>") nil t)))
11472 (vhdl-template-standard-package (car clause) (cdr clause))
11473 (insert "\n"))
11474 (setq clause-list (cdr clause-list)))))
11476 (defun vhdl-port-paste-generic (&optional no-init)
11477 "Paste a generic clause."
11478 (let ((margin (current-indentation))
11479 (generic-list (nth 1 vhdl-port-list))
11480 list-margin start names generic)
11481 ;; paste generic clause
11482 (when generic-list
11483 (setq start (point))
11484 (vhdl-insert-keyword "GENERIC (")
11485 (unless vhdl-argument-list-indent
11486 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11487 (setq list-margin (current-column))
11488 (while generic-list
11489 (setq generic (car generic-list))
11490 ;; paste group comment and spacing
11491 (when (memq vhdl-include-group-comments '(decl always))
11492 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11493 ;; paste names
11494 (setq names (nth 0 generic))
11495 (while names
11496 (insert (car names))
11497 (setq names (cdr names))
11498 (when names (insert ", ")))
11499 ;; paste type
11500 (insert " : " (nth 1 generic))
11501 ;; paste initialization
11502 (when (and (not no-init) (nth 2 generic))
11503 (insert " := " (nth 2 generic)))
11504 (unless (cdr generic-list) (insert ")"))
11505 (insert ";")
11506 ;; paste comment
11507 (when (and vhdl-include-port-comments (nth 3 generic))
11508 (vhdl-comment-insert-inline (nth 3 generic) t))
11509 (setq generic-list (cdr generic-list))
11510 (when generic-list (insert "\n") (indent-to list-margin)))
11511 ;; align generic clause
11512 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11514 (defun vhdl-port-paste-port ()
11515 "Paste a port clause."
11516 (let ((margin (current-indentation))
11517 (port-list (nth 2 vhdl-port-list))
11518 list-margin start names port)
11519 ;; paste port clause
11520 (when port-list
11521 (setq start (point))
11522 (vhdl-insert-keyword "PORT (")
11523 (unless vhdl-argument-list-indent
11524 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11525 (setq list-margin (current-column))
11526 (while port-list
11527 (setq port (car port-list))
11528 ;; paste group comment and spacing
11529 (when (memq vhdl-include-group-comments '(decl always))
11530 (vhdl-paste-group-comment (nth 5 port) list-margin))
11531 ;; paste object
11532 (when (nth 1 port) (insert (nth 1 port) " "))
11533 ;; paste names
11534 (setq names (nth 0 port))
11535 (while names
11536 (insert (car names))
11537 (setq names (cdr names))
11538 (when names (insert ", ")))
11539 ;; paste direction
11540 (insert " : ")
11541 (when (nth 2 port) (insert (nth 2 port) " "))
11542 ;; paste type
11543 (insert (nth 3 port))
11544 (unless (cdr port-list) (insert ")"))
11545 (insert ";")
11546 ;; paste comment
11547 (when (and vhdl-include-port-comments (nth 4 port))
11548 (vhdl-comment-insert-inline (nth 4 port) t))
11549 (setq port-list (cdr port-list))
11550 (when port-list (insert "\n") (indent-to list-margin)))
11551 ;; align port clause
11552 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11554 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11555 "Paste as an entity or component declaration."
11556 (unless no-indent (indent-according-to-mode))
11557 (let ((margin (current-indentation))
11558 (name (nth 0 vhdl-port-list)))
11559 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11560 (insert name)
11561 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11562 (vhdl-insert-keyword " IS"))
11563 ;; paste generic and port clause
11564 (when (nth 1 vhdl-port-list)
11565 (insert "\n")
11566 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11567 (insert "\n"))
11568 (indent-to (+ margin vhdl-basic-offset))
11569 (vhdl-port-paste-generic (eq kind 'component)))
11570 (when (nth 2 vhdl-port-list)
11571 (insert "\n")
11572 (when (and (memq vhdl-insert-empty-lines '(unit all))
11573 (eq kind 'entity))
11574 (insert "\n"))
11575 (indent-to (+ margin vhdl-basic-offset)))
11576 (vhdl-port-paste-port)
11577 (insert "\n")
11578 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11579 (insert "\n"))
11580 (indent-to margin)
11581 (vhdl-insert-keyword "END")
11582 (if (eq kind 'entity)
11583 (progn
11584 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11585 (insert " " name))
11586 (vhdl-insert-keyword " COMPONENT")
11587 (unless (vhdl-standard-p '87) (insert " " name)))
11588 (insert ";")))
11590 (defun vhdl-port-paste-entity (&optional no-indent)
11591 "Paste as an entity declaration."
11592 (interactive)
11593 (if (not vhdl-port-list)
11594 (error "ERROR: No port read")
11595 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11596 (vhdl-port-paste-declaration 'entity no-indent)
11597 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11599 (defun vhdl-port-paste-component (&optional no-indent)
11600 "Paste as a component declaration."
11601 (interactive)
11602 (if (not vhdl-port-list)
11603 (error "ERROR: No port read")
11604 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11605 (vhdl-port-paste-declaration 'component no-indent)
11606 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11608 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11609 "Paste as a generic map."
11610 (interactive)
11611 (unless secondary (indent-according-to-mode))
11612 (let ((margin (current-indentation))
11613 list-margin start generic
11614 (generic-list (nth 1 vhdl-port-list)))
11615 (when generic-list
11616 (setq start (point))
11617 (vhdl-insert-keyword "GENERIC MAP (")
11618 (if (not vhdl-association-list-with-formals)
11619 ;; paste list of actual generics
11620 (while generic-list
11621 (insert (if no-constants
11622 (car (nth 0 (car generic-list)))
11623 (or (nth 2 (car generic-list)) " ")))
11624 (setq generic-list (cdr generic-list))
11625 (insert (if generic-list ", " ")"))
11626 (when (and (not generic-list) secondary
11627 (null (nth 2 vhdl-port-list)))
11628 (insert ";")))
11629 (unless vhdl-argument-list-indent
11630 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11631 (setq list-margin (current-column))
11632 (while generic-list
11633 (setq generic (car generic-list))
11634 ;; paste group comment and spacing
11635 (when (eq vhdl-include-group-comments 'always)
11636 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11637 ;; paste formal and actual generic
11638 (insert (car (nth 0 generic)) " => "
11639 (if no-constants
11640 (car (nth 0 generic))
11641 (or (nth 2 generic) "")))
11642 (setq generic-list (cdr generic-list))
11643 (insert (if generic-list "," ")"))
11644 (when (and (not generic-list) secondary
11645 (null (nth 2 vhdl-port-list)))
11646 (insert ";"))
11647 ;; paste comment
11648 (when (or vhdl-include-type-comments
11649 (and vhdl-include-port-comments (nth 3 generic)))
11650 (vhdl-comment-insert-inline
11651 (concat
11652 (when vhdl-include-type-comments
11653 (concat "[" (nth 1 generic) "] "))
11654 (when vhdl-include-port-comments (nth 3 generic))) t))
11655 (when generic-list (insert "\n") (indent-to list-margin)))
11656 ;; align generic map
11657 (when vhdl-auto-align
11658 (vhdl-align-region-groups start (point) 1 t))))))
11660 (defun vhdl-port-paste-port-map ()
11661 "Paste as a port map."
11662 (let ((margin (current-indentation))
11663 list-margin start port
11664 (port-list (nth 2 vhdl-port-list)))
11665 (when port-list
11666 (setq start (point))
11667 (vhdl-insert-keyword "PORT MAP (")
11668 (if (not vhdl-association-list-with-formals)
11669 ;; paste list of actual ports
11670 (while port-list
11671 (insert (vhdl-replace-string vhdl-actual-port-name
11672 (car (nth 0 (car port-list)))))
11673 (setq port-list (cdr port-list))
11674 (insert (if port-list ", " ")")))
11675 (unless vhdl-argument-list-indent
11676 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11677 (setq list-margin (current-column))
11678 (while port-list
11679 (setq port (car port-list))
11680 ;; paste group comment and spacing
11681 (when (eq vhdl-include-group-comments 'always)
11682 (vhdl-paste-group-comment (nth 5 port) list-margin))
11683 ;; paste formal and actual port
11684 (insert (car (nth 0 port)) " => ")
11685 (insert (vhdl-replace-string vhdl-actual-port-name
11686 (car (nth 0 port))))
11687 (setq port-list (cdr port-list))
11688 (insert (if port-list "," ");"))
11689 ;; paste comment
11690 (when (or (and vhdl-include-direction-comments (nth 2 port))
11691 vhdl-include-type-comments
11692 (and vhdl-include-port-comments (nth 4 port)))
11693 (vhdl-comment-insert-inline
11694 (concat
11695 (cond ((and vhdl-include-direction-comments
11696 vhdl-include-type-comments)
11697 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11698 (nth 3 port) "] "))
11699 ((and vhdl-include-direction-comments (nth 2 port))
11700 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11701 (vhdl-include-direction-comments " ")
11702 (vhdl-include-type-comments
11703 (concat "[" (nth 3 port) "] ")))
11704 (when vhdl-include-port-comments (nth 4 port))) t))
11705 (when port-list (insert "\n") (indent-to list-margin)))
11706 ;; align port clause
11707 (when vhdl-auto-align
11708 (vhdl-align-region-groups start (point) 1))))))
11710 (defun vhdl-port-paste-instance (&optional name no-indent title)
11711 "Paste as an instantiation."
11712 (interactive)
11713 (if (not vhdl-port-list)
11714 (error "ERROR: No port read")
11715 (let ((orig-vhdl-port-list vhdl-port-list))
11716 ;; flatten local copy of port list (must be flat for port mapping)
11717 (vhdl-port-flatten)
11718 (unless no-indent (indent-according-to-mode))
11719 (let ((margin (current-indentation)))
11720 ;; paste instantiation
11721 (cond (name
11722 (insert name))
11723 ((equal (cdr vhdl-instance-name) "")
11724 (setq name (vhdl-template-field "instance name")))
11725 ((string-match "\%d" (cdr vhdl-instance-name))
11726 (let ((n 1))
11727 (while (save-excursion
11728 (setq name (format (vhdl-replace-string
11729 vhdl-instance-name
11730 (nth 0 vhdl-port-list)) n))
11731 (goto-char (point-min))
11732 (vhdl-re-search-forward name nil t))
11733 (setq n (1+ n)))
11734 (insert name)))
11735 (t (insert (vhdl-replace-string vhdl-instance-name
11736 (nth 0 vhdl-port-list)))))
11737 (message "Pasting port as instantiation \"%s\"..." name)
11738 (insert ": ")
11739 (when title
11740 (save-excursion
11741 (beginning-of-line)
11742 (indent-to vhdl-basic-offset)
11743 (insert "-- instance \"" name "\"\n")))
11744 (if (not (vhdl-use-direct-instantiation))
11745 (insert (nth 0 vhdl-port-list))
11746 (vhdl-insert-keyword "ENTITY ")
11747 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11748 (when (nth 1 vhdl-port-list)
11749 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11750 (vhdl-port-paste-generic-map t t))
11751 (when (nth 2 vhdl-port-list)
11752 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11753 (vhdl-port-paste-port-map))
11754 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11755 (insert ";"))
11756 (message "Pasting port as instantiation \"%s\"...done" name))
11757 (setq vhdl-port-list orig-vhdl-port-list))))
11759 (defun vhdl-port-paste-constants (&optional no-indent)
11760 "Paste generics as constants."
11761 (interactive)
11762 (if (not vhdl-port-list)
11763 (error "ERROR: No port read")
11764 (let ((orig-vhdl-port-list vhdl-port-list))
11765 (message "Pasting port as constants...")
11766 ;; flatten local copy of port list (must be flat for constant initial.)
11767 (vhdl-port-flatten)
11768 (unless no-indent (indent-according-to-mode))
11769 (let ((margin (current-indentation))
11770 start generic name
11771 (generic-list (nth 1 vhdl-port-list)))
11772 (when generic-list
11773 (setq start (point))
11774 (while generic-list
11775 (setq generic (car generic-list))
11776 ;; paste group comment and spacing
11777 (when (memq vhdl-include-group-comments '(decl always))
11778 (vhdl-paste-group-comment (nth 4 generic) margin))
11779 (vhdl-insert-keyword "CONSTANT ")
11780 ;; paste generic constants
11781 (setq name (nth 0 generic))
11782 (when name
11783 (insert (car name))
11784 ;; paste type
11785 (insert " : " (nth 1 generic))
11786 ;; paste initialization
11787 (when (nth 2 generic)
11788 (insert " := " (nth 2 generic)))
11789 (insert ";")
11790 ;; paste comment
11791 (when (and vhdl-include-port-comments (nth 3 generic))
11792 (vhdl-comment-insert-inline (nth 3 generic) t))
11793 (setq generic-list (cdr generic-list))
11794 (when generic-list (insert "\n") (indent-to margin))))
11795 ;; align signal list
11796 (when vhdl-auto-align
11797 (vhdl-align-region-groups start (point) 1))))
11798 (message "Pasting port as constants...done")
11799 (setq vhdl-port-list orig-vhdl-port-list))))
11801 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11802 "Paste ports as internal signals."
11803 (interactive)
11804 (if (not vhdl-port-list)
11805 (error "ERROR: No port read")
11806 (message "Pasting port as signals...")
11807 (unless no-indent (indent-according-to-mode))
11808 (let ((margin (current-indentation))
11809 start port names
11810 (port-list (nth 2 vhdl-port-list)))
11811 (when port-list
11812 (setq start (point))
11813 (while port-list
11814 (setq port (car port-list))
11815 ;; paste group comment and spacing
11816 (when (memq vhdl-include-group-comments '(decl always))
11817 (vhdl-paste-group-comment (nth 5 port) margin))
11818 ;; paste object
11819 (if (nth 1 port)
11820 (insert (nth 1 port) " ")
11821 (vhdl-insert-keyword "SIGNAL "))
11822 ;; paste actual port signals
11823 (setq names (nth 0 port))
11824 (while names
11825 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11826 (setq names (cdr names))
11827 (when names (insert ", ")))
11828 ;; paste type
11829 (insert " : " (nth 3 port))
11830 ;; paste initialization (inputs only)
11831 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
11832 (insert " := "
11833 (cond ((string-match "integer" (nth 3 port)) "0")
11834 ((string-match "natural" (nth 3 port)) "0")
11835 ((string-match "positive" (nth 3 port)) "0")
11836 ((string-match "real" (nth 3 port)) "0.0")
11837 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
11838 (t "'0'"))))
11839 (insert ";")
11840 ;; paste comment
11841 (when (or (and vhdl-include-direction-comments (nth 2 port))
11842 (and vhdl-include-port-comments (nth 4 port)))
11843 (vhdl-comment-insert-inline
11844 (concat
11845 (cond ((and vhdl-include-direction-comments (nth 2 port))
11846 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11847 (vhdl-include-direction-comments " "))
11848 (when vhdl-include-port-comments (nth 4 port))) t))
11849 (setq port-list (cdr port-list))
11850 (when port-list (insert "\n") (indent-to margin)))
11851 ;; align signal list
11852 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11853 (message "Pasting port as signals...done")))
11855 (defun vhdl-port-paste-initializations (&optional no-indent)
11856 "Paste ports as signal initializations."
11857 (interactive)
11858 (if (not vhdl-port-list)
11859 (error "ERROR: No port read")
11860 (let ((orig-vhdl-port-list vhdl-port-list))
11861 (message "Pasting port as initializations...")
11862 ;; flatten local copy of port list (must be flat for signal initial.)
11863 (vhdl-port-flatten)
11864 (unless no-indent (indent-according-to-mode))
11865 (let ((margin (current-indentation))
11866 start port name
11867 (port-list (nth 2 vhdl-port-list)))
11868 (when port-list
11869 (setq start (point))
11870 (while port-list
11871 (setq port (car port-list))
11872 ;; paste actual port signal (inputs only)
11873 (when (equal "IN" (upcase (nth 2 port)))
11874 (setq name (car (nth 0 port)))
11875 (insert (vhdl-replace-string vhdl-actual-port-name name))
11876 ;; paste initialization
11877 (insert " <= "
11878 (cond ((string-match "integer" (nth 3 port)) "0")
11879 ((string-match "natural" (nth 3 port)) "0")
11880 ((string-match "positive" (nth 3 port)) "0")
11881 ((string-match "real" (nth 3 port)) "0.0")
11882 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
11883 (t "'0'"))
11884 ";"))
11885 (setq port-list (cdr port-list))
11886 (when (and port-list
11887 (equal "IN" (upcase (nth 2 (car port-list)))))
11888 (insert "\n") (indent-to margin)))
11889 ;; align signal list
11890 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11891 (message "Pasting port as initializations...done")
11892 (setq vhdl-port-list orig-vhdl-port-list))))
11894 (defun vhdl-port-paste-testbench ()
11895 "Paste as a bare-bones testbench."
11896 (interactive)
11897 (if (not vhdl-port-list)
11898 (error "ERROR: No port read")
11899 (let ((case-fold-search t)
11900 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11901 (nth 0 vhdl-port-list)))
11902 (source-buffer (current-buffer))
11903 arch-name config-name ent-file-name arch-file-name
11904 ent-buffer arch-buffer position)
11905 ;; open entity file
11906 (unless (eq vhdl-testbench-create-files 'none)
11907 (setq ent-file-name
11908 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11909 ent-name t)
11910 "." (file-name-extension (buffer-file-name))))
11911 (if (file-exists-p ent-file-name)
11912 (if (y-or-n-p
11913 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11914 (progn (find-file ent-file-name)
11915 (erase-buffer)
11916 (set-buffer-modified-p nil))
11917 (if (eq vhdl-testbench-create-files 'separate)
11918 (setq ent-file-name nil)
11919 (error "ERROR: Pasting port as testbench...aborted")))
11920 (find-file ent-file-name)))
11921 (unless (and (eq vhdl-testbench-create-files 'separate)
11922 (null ent-file-name))
11923 ;; paste entity header
11924 (if vhdl-testbench-include-header
11925 (progn (vhdl-template-header
11926 (concat "Testbench for design \""
11927 (nth 0 vhdl-port-list) "\""))
11928 (goto-char (point-max)))
11929 (vhdl-comment-display-line) (insert "\n\n"))
11930 ;; paste std_logic_1164 package
11931 (when vhdl-testbench-include-library
11932 (vhdl-template-package-std-logic-1164)
11933 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11934 ;; paste entity declaration
11935 (vhdl-insert-keyword "ENTITY ")
11936 (insert ent-name)
11937 (vhdl-insert-keyword " IS")
11938 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11939 (insert "\n")
11940 (vhdl-insert-keyword "END ")
11941 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11942 (insert ent-name ";")
11943 (insert "\n\n")
11944 (vhdl-comment-display-line) (insert "\n"))
11945 ;; get architecture name
11946 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11947 (read-from-minibuffer "architecture name: "
11948 nil vhdl-minibuffer-local-map)
11949 (vhdl-replace-string vhdl-testbench-architecture-name
11950 (nth 0 vhdl-port-list))))
11951 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11952 ;; open architecture file
11953 (if (not (eq vhdl-testbench-create-files 'separate))
11954 (insert "\n")
11955 (setq ent-buffer (current-buffer))
11956 (setq arch-file-name
11957 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11958 (concat ent-name " " arch-name) t)
11959 "." (file-name-extension (buffer-file-name))))
11960 (when (and (file-exists-p arch-file-name)
11961 (not (y-or-n-p (concat "File \"" arch-file-name
11962 "\" exists; overwrite? "))))
11963 (error "ERROR: Pasting port as testbench...aborted"))
11964 (find-file arch-file-name)
11965 (erase-buffer)
11966 (set-buffer-modified-p nil)
11967 ;; paste architecture header
11968 (if vhdl-testbench-include-header
11969 (progn (vhdl-template-header
11970 (concat "Testbench architecture for design \""
11971 (nth 0 vhdl-port-list) "\""))
11972 (goto-char (point-max)))
11973 (vhdl-comment-display-line) (insert "\n\n")))
11974 ;; paste architecture body
11975 (vhdl-insert-keyword "ARCHITECTURE ")
11976 (insert arch-name)
11977 (vhdl-insert-keyword " OF ")
11978 (insert ent-name)
11979 (vhdl-insert-keyword " IS")
11980 (insert "\n\n") (indent-to vhdl-basic-offset)
11981 ;; paste component declaration
11982 (unless (vhdl-use-direct-instantiation)
11983 (vhdl-port-paste-component t)
11984 (insert "\n\n") (indent-to vhdl-basic-offset))
11985 ;; paste constants
11986 (when (nth 1 vhdl-port-list)
11987 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11988 (vhdl-port-paste-constants t)
11989 (insert "\n\n") (indent-to vhdl-basic-offset))
11990 ;; paste internal signals
11991 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11992 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11993 (insert "\n")
11994 ;; paste custom declarations
11995 (unless (equal "" vhdl-testbench-declarations)
11996 (insert "\n")
11997 (setq position (point))
11998 (vhdl-insert-string-or-file vhdl-testbench-declarations)
11999 (vhdl-indent-region position (point)))
12000 (setq position (point))
12001 (insert "\n\n")
12002 (vhdl-comment-display-line) (insert "\n")
12003 (when vhdl-testbench-include-configuration
12004 (setq config-name (vhdl-replace-string
12005 vhdl-testbench-configuration-name
12006 (concat ent-name " " arch-name)))
12007 (insert "\n")
12008 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12009 (vhdl-insert-keyword " OF ") (insert ent-name)
12010 (vhdl-insert-keyword " IS\n")
12011 (indent-to vhdl-basic-offset)
12012 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12013 (indent-to vhdl-basic-offset)
12014 (vhdl-insert-keyword "END FOR;\n")
12015 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12016 (vhdl-comment-display-line) (insert "\n"))
12017 (goto-char position)
12018 (vhdl-template-begin-end
12019 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12020 ;; paste instantiation
12021 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12022 (vhdl-port-paste-instance
12023 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12024 (insert "\n")
12025 ;; paste custom statements
12026 (unless (equal "" vhdl-testbench-statements)
12027 (insert "\n")
12028 (setq position (point))
12029 (vhdl-insert-string-or-file vhdl-testbench-statements)
12030 (vhdl-indent-region position (point)))
12031 (insert "\n")
12032 (indent-to vhdl-basic-offset)
12033 (unless (eq vhdl-testbench-create-files 'none)
12034 (setq arch-buffer (current-buffer))
12035 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12036 (set-buffer arch-buffer) (save-buffer))
12037 (message "%s"
12038 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12039 ent-name arch-name)
12040 (and ent-file-name
12041 (format "\n File created: \"%s\"" ent-file-name))
12042 (and arch-file-name
12043 (format "\n File created: \"%s\"" arch-file-name)))))))
12046 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12047 ;;; Subprogram interface translation
12048 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12050 (defvar vhdl-subprog-list nil
12051 "Variable to hold last subprogram interface parsed.")
12052 ;; structure: (parenthesized expression means list of such entries)
12053 ;; (subprog-name kind
12054 ;; ((names) object direct type init comment group-comment)
12055 ;; return-type return-comment group-comment)
12057 (defvar vhdl-subprog-flattened nil
12058 "Indicates whether an subprogram interface has been flattened.")
12060 (defun vhdl-subprog-flatten ()
12061 "Flatten interface list so that only one parameter exists per line."
12062 (interactive)
12063 (if (not vhdl-subprog-list)
12064 (error "ERROR: No subprogram interface has been read")
12065 (message "Flattening subprogram interface...")
12066 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12067 new-subprog-list old-subprog new-subprog names)
12068 ;; traverse parameter list and flatten entries
12069 (while old-subprog-list
12070 (setq old-subprog (car old-subprog-list))
12071 (setq names (car old-subprog))
12072 (while names
12073 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12074 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12075 (setq names (cdr names)))
12076 (setq old-subprog-list (cdr old-subprog-list)))
12077 (setq vhdl-subprog-list
12078 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12079 new-subprog-list (nth 3 vhdl-subprog-list)
12080 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12081 vhdl-subprog-flattened t)
12082 (message "Flattening subprogram interface...done"))))
12084 (defun vhdl-subprog-copy ()
12085 "Get interface information from a subprogram specification."
12086 (interactive)
12087 (save-excursion
12088 (let (parse-error pos end-of-list
12089 name kind param-list object names direct type init
12090 comment group-comment
12091 return-type return-comment return-group-comment)
12092 (vhdl-prepare-search-2
12093 (setq
12094 parse-error
12095 (catch 'parse
12096 ;; check if within function declaration
12097 (setq pos (point))
12098 (end-of-line)
12099 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12100 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12101 (goto-char (match-end 0))
12102 (save-excursion (backward-char)
12103 (forward-sexp)
12104 (<= pos (point))))
12105 (throw 'parse "ERROR: Not within a subprogram specification"))
12106 (setq name (match-string-no-properties 5))
12107 (setq kind (if (match-string 2) 'procedure 'function))
12108 (setq end-of-list (not (match-string 7)))
12109 (message "Reading interface of subprogram \"%s\"..." name)
12110 ;; parse parameter list
12111 (setq group-comment (vhdl-parse-group-comment))
12112 (setq end-of-list (or end-of-list
12113 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12114 (while (not end-of-list)
12115 ;; parse object
12116 (setq object
12117 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12118 (match-string-no-properties 1)))
12119 ;; parse names (accept extended identifiers)
12120 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12121 (setq names (list (match-string-no-properties 1)))
12122 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12123 (setq names (append names (list (match-string-no-properties 1)))))
12124 ;; parse direction
12125 (vhdl-parse-string ":[ \t\n\r\f]*")
12126 (setq direct
12127 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12128 (match-string-no-properties 1)))
12129 ;; parse type
12130 (vhdl-parse-string "\\([^():;\n]+\\)")
12131 (setq type (match-string-no-properties 1))
12132 (setq comment nil)
12133 (while (looking-at "(")
12134 (setq type
12135 (concat type
12136 (buffer-substring-no-properties
12137 (point) (progn (forward-sexp) (point)))
12138 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12139 (match-string-no-properties 1)))))
12140 ;; special case: closing parenthesis is on separate line
12141 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12142 (setq comment (substring type (match-beginning 2)))
12143 (setq type (substring type 0 (match-beginning 1))))
12144 ;; strip off trailing group-comment
12145 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12146 (setq type (substring type 0 (match-end 1)))
12147 ;; parse initialization expression
12148 (setq init nil)
12149 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12150 (vhdl-parse-string "\\([^();\n]*\\)")
12151 (setq init (match-string-no-properties 1))
12152 (while (looking-at "(")
12153 (setq init
12154 (concat init
12155 (buffer-substring-no-properties
12156 (point) (progn (forward-sexp) (point)))
12157 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12158 (match-string-no-properties 1))))))
12159 ;; special case: closing parenthesis is on separate line
12160 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12161 (setq comment (substring init (match-beginning 2)))
12162 (setq init (substring init 0 (match-beginning 1)))
12163 (vhdl-forward-syntactic-ws))
12164 (skip-chars-forward " \t")
12165 ;; parse inline comment, special case: as above, no initial.
12166 (unless comment
12167 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12168 (match-string-no-properties 1))))
12169 (vhdl-forward-syntactic-ws)
12170 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12171 ;; parse inline comment
12172 (unless comment
12173 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12174 (match-string-no-properties 1))))
12175 (setq return-group-comment (vhdl-parse-group-comment))
12176 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12177 ;; parse return type
12178 (when (match-string 3)
12179 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12180 (setq return-type (match-string-no-properties 1))
12181 (when (and return-type
12182 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12183 (setq return-comment (substring return-type (match-beginning 2)))
12184 (setq return-type (substring return-type 0 (match-beginning 1))))
12185 ;; strip of trailing group-comment
12186 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12187 (setq return-type (substring return-type 0 (match-end 1)))
12188 ;; parse return comment
12189 (unless return-comment
12190 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12191 (match-string-no-properties 1)))))
12192 ;; parse inline comment
12193 (unless comment
12194 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12195 (match-string-no-properties 1))))
12196 ;; save everything in list
12197 (setq param-list (append param-list
12198 (list (list names object direct type init
12199 comment group-comment))))
12200 ;; parse group comment and spacing
12201 (setq group-comment (vhdl-parse-group-comment)))
12202 (message "Reading interface of subprogram \"%s\"...done" name)
12203 nil)))
12204 ;; finish parsing
12205 (if parse-error
12206 (error parse-error)
12207 (setq vhdl-subprog-list
12208 (list name kind param-list return-type return-comment
12209 return-group-comment)
12210 vhdl-subprog-flattened nil)))))
12212 (defun vhdl-subprog-paste-specification (kind)
12213 "Paste as a subprogram specification."
12214 (indent-according-to-mode)
12215 (let ((margin (current-column))
12216 (param-list (nth 2 vhdl-subprog-list))
12217 list-margin start names param)
12218 ;; paste keyword and name
12219 (vhdl-insert-keyword
12220 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12221 (insert (nth 0 vhdl-subprog-list))
12222 (if (not param-list)
12223 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12224 (setq start (point))
12225 ;; paste parameter list
12226 (insert " (")
12227 (unless vhdl-argument-list-indent
12228 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12229 (setq list-margin (current-column))
12230 (while param-list
12231 (setq param (car param-list))
12232 ;; paste group comment and spacing
12233 (when (memq vhdl-include-group-comments (list kind 'always))
12234 (vhdl-paste-group-comment (nth 6 param) list-margin))
12235 ;; paste object
12236 (when (nth 1 param) (insert (nth 1 param) " "))
12237 ;; paste names
12238 (setq names (nth 0 param))
12239 (while names
12240 (insert (car names))
12241 (setq names (cdr names))
12242 (when names (insert ", ")))
12243 ;; paste direction
12244 (insert " : ")
12245 (when (nth 2 param) (insert (nth 2 param) " "))
12246 ;; paste type
12247 (insert (nth 3 param))
12248 ;; paste initialization
12249 (when (nth 4 param) (insert " := " (nth 4 param)))
12250 ;; terminate line
12251 (if (cdr param-list)
12252 (insert ";")
12253 (insert ")")
12254 (when (null (nth 3 vhdl-subprog-list))
12255 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12256 ;; paste comment
12257 (when (and vhdl-include-port-comments (nth 5 param))
12258 (vhdl-comment-insert-inline (nth 5 param) t))
12259 (setq param-list (cdr param-list))
12260 (when param-list (insert "\n") (indent-to list-margin)))
12261 (when (nth 3 vhdl-subprog-list)
12262 (insert "\n") (indent-to list-margin)
12263 ;; paste group comment and spacing
12264 (when (memq vhdl-include-group-comments (list kind 'always))
12265 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12266 ;; paste return type
12267 (insert "return " (nth 3 vhdl-subprog-list))
12268 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12269 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12270 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12271 ;; align parameter list
12272 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12273 ;; paste body
12274 (when (eq kind 'body)
12275 (insert "\n")
12276 (vhdl-template-begin-end
12277 (unless (vhdl-standard-p '87)
12278 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12279 (nth 0 vhdl-subprog-list) margin))))
12281 (defun vhdl-subprog-paste-declaration ()
12282 "Paste as a subprogram declaration."
12283 (interactive)
12284 (if (not vhdl-subprog-list)
12285 (error "ERROR: No subprogram interface read")
12286 (message "Pasting interface as subprogram declaration \"%s\"..."
12287 (car vhdl-subprog-list))
12288 ;; paste specification
12289 (vhdl-subprog-paste-specification 'decl)
12290 (message "Pasting interface as subprogram declaration \"%s\"...done"
12291 (car vhdl-subprog-list))))
12293 (defun vhdl-subprog-paste-body ()
12294 "Paste as a subprogram body."
12295 (interactive)
12296 (if (not vhdl-subprog-list)
12297 (error "ERROR: No subprogram interface read")
12298 (message "Pasting interface as subprogram body \"%s\"..."
12299 (car vhdl-subprog-list))
12300 ;; paste specification and body
12301 (vhdl-subprog-paste-specification 'body)
12302 (message "Pasting interface as subprogram body \"%s\"...done"
12303 (car vhdl-subprog-list))))
12305 (defun vhdl-subprog-paste-call ()
12306 "Paste as a subprogram call."
12307 (interactive)
12308 (if (not vhdl-subprog-list)
12309 (error "ERROR: No subprogram interface read")
12310 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12311 param-list margin list-margin param start)
12312 ;; flatten local copy of interface list (must be flat for parameter mapping)
12313 (vhdl-subprog-flatten)
12314 (setq param-list (nth 2 vhdl-subprog-list))
12315 (indent-according-to-mode)
12316 (setq margin (current-indentation))
12317 (message "Pasting interface as subprogram call \"%s\"..."
12318 (car vhdl-subprog-list))
12319 ;; paste name
12320 (insert (nth 0 vhdl-subprog-list))
12321 (if (not param-list)
12322 (insert ";")
12323 (setq start (point))
12324 ;; paste parameter list
12325 (insert " (")
12326 (unless vhdl-argument-list-indent
12327 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12328 (setq list-margin (current-column))
12329 (while param-list
12330 (setq param (car param-list))
12331 ;; paste group comment and spacing
12332 (when (eq vhdl-include-group-comments 'always)
12333 (vhdl-paste-group-comment (nth 6 param) list-margin))
12334 ;; paste formal port
12335 (insert (car (nth 0 param)) " => ")
12336 (setq param-list (cdr param-list))
12337 (insert (if param-list "," ");"))
12338 ;; paste comment
12339 (when (and vhdl-include-port-comments (nth 5 param))
12340 (vhdl-comment-insert-inline (nth 5 param)))
12341 (when param-list (insert "\n") (indent-to list-margin)))
12342 ;; align parameter list
12343 (when vhdl-auto-align
12344 (vhdl-align-region-groups start (point) 1)))
12345 (message "Pasting interface as subprogram call \"%s\"...done"
12346 (car vhdl-subprog-list))
12347 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12350 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12351 ;;; Miscellaneous
12352 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12354 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12355 ;; Hippie expand customization
12357 (defvar vhdl-expand-upper-case nil)
12359 (defun vhdl-try-expand-abbrev (old)
12360 "Try expanding abbreviations from `vhdl-abbrev-list'."
12361 (unless old
12362 (he-init-string (he-dabbrev-beg) (point))
12363 (setq he-expand-list
12364 (let ((abbrev-list vhdl-abbrev-list)
12365 (sel-abbrev-list '()))
12366 (while abbrev-list
12367 (when (or (not (stringp (car abbrev-list)))
12368 (string-match
12369 (concat "^" he-search-string) (car abbrev-list)))
12370 (setq sel-abbrev-list
12371 (cons (car abbrev-list) sel-abbrev-list)))
12372 (setq abbrev-list (cdr abbrev-list)))
12373 (nreverse sel-abbrev-list))))
12374 (while (and he-expand-list
12375 (or (not (stringp (car he-expand-list)))
12376 (he-string-member (car he-expand-list) he-tried-table t)))
12377 ; (equal (car he-expand-list) he-search-string)))
12378 (unless (stringp (car he-expand-list))
12379 (setq vhdl-expand-upper-case (car he-expand-list)))
12380 (setq he-expand-list (cdr he-expand-list)))
12381 (if (null he-expand-list)
12382 (progn (when old (he-reset-string))
12383 nil)
12384 (he-substitute-string
12385 (if vhdl-expand-upper-case
12386 (upcase (car he-expand-list))
12387 (car he-expand-list))
12389 (setq he-expand-list (cdr he-expand-list))
12392 (defun vhdl-he-list-beg ()
12393 "Also looks at the word before `(' in order to better match parenthesized
12394 expressions (e.g. for index ranges of types and signals)."
12395 (save-excursion
12396 (condition-case ()
12397 (progn (backward-up-list 1)
12398 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12399 (error ()))
12400 (point)))
12402 ;; override `he-list-beg' from `hippie-exp'
12403 (unless (and (boundp 'viper-mode) viper-mode)
12404 (defalias 'he-list-beg 'vhdl-he-list-beg))
12406 ;; function for expanding abbrevs and dabbrevs
12407 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12408 '(try-expand-dabbrev
12409 try-expand-dabbrev-all-buffers
12410 vhdl-try-expand-abbrev)))
12412 ;; function for expanding parenthesis
12413 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12414 '(try-expand-list
12415 try-expand-list-all-buffers)))
12417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12418 ;; Case fixing
12420 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12421 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12422 depending on parameter UPPER-CASE."
12423 (let ((case-replace nil)
12424 (last-update 0))
12425 (vhdl-prepare-search-2
12426 (save-excursion
12427 (goto-char end)
12428 (setq end (point-marker))
12429 (goto-char beg)
12430 (while (re-search-forward word-regexp end t)
12431 (or (vhdl-in-literal)
12432 (if upper-case
12433 (upcase-word -1)
12434 (downcase-word -1)))
12435 (when (and count vhdl-progress-interval (not noninteractive)
12436 (< vhdl-progress-interval
12437 (- (nth 1 (current-time)) last-update)))
12438 (message "Fixing case... (%2d%s)"
12439 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
12440 "%")
12441 (setq last-update (nth 1 (current-time)))))
12442 (goto-char end)))))
12444 (defun vhdl-fix-case-region (beg end &optional arg)
12445 "Convert all VHDL words in region to lower or upper case, depending on
12446 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12447 (interactive "r\nP")
12448 (vhdl-fix-case-region-1
12449 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12450 (vhdl-fix-case-region-1
12451 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12452 (vhdl-fix-case-region-1
12453 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12454 (vhdl-fix-case-region-1
12455 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12456 (vhdl-fix-case-region-1
12457 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
12458 (when vhdl-progress-interval (message "Fixing case...done")))
12460 (defun vhdl-fix-case-buffer ()
12461 "Convert all VHDL words in buffer to lower or upper case, depending on
12462 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12463 (interactive)
12464 (vhdl-fix-case-region (point-min) (point-max)))
12466 (defun vhdl-fix-case-word (&optional arg)
12467 "Convert word after cursor to upper case if necessary."
12468 (interactive "p")
12469 (save-excursion
12470 (when arg (backward-word 1))
12471 (vhdl-prepare-search-1
12472 (when (and vhdl-upper-case-keywords
12473 (looking-at vhdl-keywords-regexp))
12474 (upcase-word 1))
12475 (when (and vhdl-upper-case-types
12476 (looking-at vhdl-types-regexp))
12477 (upcase-word 1))
12478 (when (and vhdl-upper-case-attributes
12479 (looking-at vhdl-attributes-regexp))
12480 (upcase-word 1))
12481 (when (and vhdl-upper-case-enum-values
12482 (looking-at vhdl-enum-values-regexp))
12483 (upcase-word 1))
12484 (when (and vhdl-upper-case-constants
12485 (looking-at vhdl-constants-regexp))
12486 (upcase-word 1)))))
12488 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12489 ;; Line handling functions
12491 (defun vhdl-current-line ()
12492 "Return the line number of the line containing point."
12493 (save-restriction
12494 (widen)
12495 (1+ (count-lines (point-min) (point-at-bol)))))
12497 (defun vhdl-line-kill-entire (&optional arg)
12498 "Delete entire line."
12499 (interactive "p")
12500 (beginning-of-line)
12501 (kill-line (or arg 1)))
12503 (defun vhdl-line-kill (&optional arg)
12504 "Kill current line."
12505 (interactive "p")
12506 (vhdl-line-kill-entire arg))
12508 (defun vhdl-line-copy (&optional arg)
12509 "Copy current line."
12510 (interactive "p")
12511 (save-excursion
12512 (let ((position (point-at-bol)))
12513 (forward-line (or arg 1))
12514 (copy-region-as-kill position (point)))))
12516 (defun vhdl-line-yank ()
12517 "Yank entire line."
12518 (interactive)
12519 (beginning-of-line)
12520 (yank))
12522 (defun vhdl-line-expand (&optional prefix-arg)
12523 "Hippie-expand current line."
12524 (interactive "P")
12525 (let ((case-fold-search t) (case-replace nil)
12526 (hippie-expand-try-functions-list
12527 '(try-expand-line try-expand-line-all-buffers)))
12528 (hippie-expand prefix-arg)))
12530 (defun vhdl-line-transpose-next (&optional arg)
12531 "Interchange this line with next line."
12532 (interactive "p")
12533 (forward-line 1)
12534 (transpose-lines (or arg 1))
12535 (forward-line -1))
12537 (defun vhdl-line-transpose-previous (&optional arg)
12538 "Interchange this line with previous line."
12539 (interactive "p")
12540 (forward-line 1)
12541 (transpose-lines (- 0 (or arg 0)))
12542 (forward-line -1))
12544 (defun vhdl-line-open ()
12545 "Open a new line and indent."
12546 (interactive)
12547 (end-of-line -0)
12548 (newline-and-indent))
12550 (defun vhdl-delete-indentation ()
12551 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12552 it works within comments too."
12553 (interactive)
12554 (let ((fill-prefix "-- "))
12555 (delete-indentation)))
12557 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12558 ;; Move functions
12560 (defun vhdl-forward-same-indent ()
12561 "Move forward to next line with same indent."
12562 (interactive)
12563 (let ((pos (point))
12564 (indent (current-indentation)))
12565 (beginning-of-line 2)
12566 (while (and (not (eobp))
12567 (or (looking-at "^\\s-*\\(--.*\\)?$")
12568 (> (current-indentation) indent)))
12569 (beginning-of-line 2))
12570 (if (= (current-indentation) indent)
12571 (back-to-indentation)
12572 (message "No following line with same indent found in this block")
12573 (goto-char pos)
12574 nil)))
12576 (defun vhdl-backward-same-indent ()
12577 "Move backward to previous line with same indent."
12578 (interactive)
12579 (let ((pos (point))
12580 (indent (current-indentation)))
12581 (beginning-of-line -0)
12582 (while (and (not (bobp))
12583 (or (looking-at "^\\s-*\\(--.*\\)?$")
12584 (> (current-indentation) indent)))
12585 (beginning-of-line -0))
12586 (if (= (current-indentation) indent)
12587 (back-to-indentation)
12588 (message "No preceding line with same indent found in this block")
12589 (goto-char pos)
12590 nil)))
12592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12593 ;; Statistics
12595 (defun vhdl-statistics-buffer ()
12596 "Get some file statistics."
12597 (interactive)
12598 (let ((no-stats 0)
12599 (no-code-lines 0)
12600 (no-empty-lines 0)
12601 (no-comm-lines 0)
12602 (no-comments 0)
12603 (no-lines (count-lines (point-min) (point-max))))
12604 (save-excursion
12605 ;; count statements
12606 (goto-char (point-min))
12607 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12608 (if (match-string 1)
12609 (goto-char (match-end 1))
12610 (setq no-stats (1+ no-stats))))
12611 ;; count code lines
12612 (goto-char (point-min))
12613 (while (not (eobp))
12614 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12615 (setq no-code-lines (1+ no-code-lines)))
12616 (beginning-of-line 2))
12617 ;; count empty lines
12618 (goto-char (point-min))
12619 (while (and (re-search-forward "^\\s-*$" nil t)
12620 (not (eq (point) (point-max))))
12621 (if (match-string 1)
12622 (goto-char (match-end 1))
12623 (setq no-empty-lines (1+ no-empty-lines))
12624 (unless (eq (point) (point-max))
12625 (forward-char))))
12626 ;; count comment-only lines
12627 (goto-char (point-min))
12628 (while (re-search-forward "^\\s-*--.*" nil t)
12629 (if (match-string 1)
12630 (goto-char (match-end 1))
12631 (setq no-comm-lines (1+ no-comm-lines))))
12632 ;; count comments
12633 (goto-char (point-min))
12634 (while (re-search-forward "--.*" nil t)
12635 (if (match-string 1)
12636 (goto-char (match-end 1))
12637 (setq no-comments (1+ no-comments)))))
12638 ;; print results
12639 (message "\n\
12640 File statistics: \"%s\"\n\
12641 ---------------------\n\
12642 # statements : %5d\n\
12643 # code lines : %5d\n\
12644 # empty lines : %5d\n\
12645 # comment lines : %5d\n\
12646 # comments : %5d\n\
12647 # total lines : %5d\n\ "
12648 (buffer-file-name) no-stats no-code-lines no-empty-lines
12649 no-comm-lines no-comments no-lines)
12650 (unless vhdl-emacs-21 (vhdl-show-messages))))
12652 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12653 ;; Help functions
12655 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12656 "Like `re-search-forward', but does not match within literals."
12657 (let (pos)
12658 (save-excursion
12659 (while (and (setq pos (re-search-forward regexp bound noerror count))
12660 (vhdl-in-literal))))
12661 (when pos (goto-char pos))
12662 pos))
12664 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12665 "Like `re-search-backward', but does not match within literals."
12666 (let (pos)
12667 (save-excursion
12668 (while (and (setq pos (re-search-backward regexp bound noerror count))
12669 (vhdl-in-literal))))
12670 (when pos (goto-char pos))
12671 pos))
12674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12675 ;;; Project
12676 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12678 (defun vhdl-set-project (name)
12679 "Set current project to NAME."
12680 (interactive
12681 (list (let ((completion-ignore-case t))
12682 (completing-read "Project name: " vhdl-project-alist nil t))))
12683 (cond ((equal name "")
12684 (setq vhdl-project nil)
12685 (message "Current VHDL project: None"))
12686 ((assoc name vhdl-project-alist)
12687 (setq vhdl-project name)
12688 (message "Current VHDL project: \"%s\"" name))
12690 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12691 (vhdl-speedbar-update-current-project))
12693 (defun vhdl-set-default-project ()
12694 "Set current project as default on startup."
12695 (interactive)
12696 (customize-set-variable 'vhdl-project vhdl-project)
12697 (customize-save-customized))
12699 (defun vhdl-toggle-project (name token indent)
12700 "Set current project to NAME or unset if NAME is current project."
12701 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12703 (defun vhdl-export-project (file-name)
12704 "Write project setup for current project."
12705 (interactive
12706 (let ((name (vhdl-resolve-env-variable
12707 (vhdl-replace-string
12708 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12709 (concat (subst-char-in-string
12710 ? ?_ (or (vhdl-project-p)
12711 (error "ERROR: No current project")))
12712 " " (user-login-name))))))
12713 (list (read-file-name
12714 "Write project file: "
12715 (when (file-name-absolute-p name) "") nil nil name))))
12716 (setq file-name (abbreviate-file-name file-name))
12717 (let ((orig-buffer (current-buffer)))
12718 (unless (file-exists-p (file-name-directory file-name))
12719 (make-directory (file-name-directory file-name) t))
12720 (if (not (file-writable-p file-name))
12721 (error "ERROR: File not writable: \"%s\"" file-name)
12722 (set-buffer (find-file-noselect file-name t t))
12723 (erase-buffer)
12724 (insert ";; -*- Emacs-Lisp -*-\n\n"
12725 ";;; " (file-name-nondirectory file-name)
12726 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12727 ";; Project : " vhdl-project "\n"
12728 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12729 (user-login-name) "\n\n\n"
12730 ";; project name\n"
12731 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12732 ";; project setup\n"
12733 "(aput 'vhdl-project-alist vhdl-project\n'")
12734 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12735 (insert ")\n")
12736 (save-buffer)
12737 (kill-buffer (current-buffer))
12738 (set-buffer orig-buffer))))
12740 (defun vhdl-import-project (file-name &optional auto not-make-current)
12741 "Read project setup and set current project."
12742 (interactive
12743 (let ((name (vhdl-resolve-env-variable
12744 (vhdl-replace-string
12745 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12746 (concat "" " " (user-login-name))))))
12747 (list (read-file-name
12748 "Read project file: " (when (file-name-absolute-p name) "") nil t
12749 (file-name-directory name)))))
12750 (when (file-exists-p file-name)
12751 (condition-case ()
12752 (let ((current-project vhdl-project))
12753 (load-file file-name)
12754 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12755 (adelete 'vhdl-project-alist vhdl-project)
12756 (error ""))
12757 (when not-make-current
12758 (setq vhdl-project current-project))
12759 (vhdl-update-mode-menu)
12760 (vhdl-speedbar-refresh)
12761 (unless not-make-current
12762 (message "Current VHDL project: \"%s\"%s"
12763 vhdl-project (if auto " (auto-loaded)" ""))))
12764 (error (vhdl-warning
12765 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12767 (defun vhdl-duplicate-project ()
12768 "Duplicate setup of current project."
12769 (interactive)
12770 (let ((new-name (read-from-minibuffer "New project name: "))
12771 (project-entry (aget vhdl-project-alist vhdl-project t)))
12772 (setq vhdl-project-alist
12773 (append vhdl-project-alist
12774 (list (cons new-name project-entry))))
12775 (vhdl-update-mode-menu)))
12777 (defun vhdl-auto-load-project ()
12778 "Automatically load project setup at startup."
12779 (let ((file-name-list vhdl-project-file-name)
12780 file-list list-length)
12781 (while file-name-list
12782 (setq file-list
12783 (append file-list
12784 (file-expand-wildcards
12785 (vhdl-resolve-env-variable
12786 (vhdl-replace-string
12787 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12788 (concat "\*" " " (user-login-name)))))))
12789 (setq list-length (or list-length (length file-list)))
12790 (setq file-name-list (cdr file-name-list)))
12791 (while file-list
12792 (vhdl-import-project (expand-file-name (car file-list)) t
12793 (not (> list-length 0)))
12794 (setq list-length (1- list-length))
12795 (setq file-list (cdr file-list)))))
12797 ;; automatically load project setup when idle after startup
12798 (when (memq 'startup vhdl-project-auto-load)
12799 (if noninteractive
12800 (vhdl-auto-load-project)
12801 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12804 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12805 ;;; Hideshow
12806 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12807 ;; (using `hideshow.el')
12809 (defconst vhdl-hs-start-regexp
12810 (concat
12811 "\\(^\\)\\s-*\\("
12812 ;; generic/port clause
12813 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
12814 ;; component
12815 "component\\>\\|"
12816 ;; component instantiation
12817 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
12818 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
12819 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
12820 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
12821 ;; subprogram
12822 "\\(function\\|procedure\\)\\>\\|"
12823 ;; process, block
12824 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
12825 ;; configuration declaration
12826 "configuration\\>"
12827 "\\)")
12828 "Regexp to match start of construct to hide.")
12830 (defun vhdl-hs-forward-sexp-func (count)
12831 "Find end of construct to hide (for hideshow). Only searches forward."
12832 (let ((pos (point)))
12833 (vhdl-prepare-search-2
12834 (beginning-of-line)
12835 (cond
12836 ;; generic/port clause
12837 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
12838 (goto-char (match-end 0))
12839 (backward-char)
12840 (forward-sexp))
12841 ;; component declaration
12842 ((looking-at "^\\s-*component\\>")
12843 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12844 ;; component instantiation
12845 ((looking-at
12846 (concat
12847 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
12848 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
12849 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
12850 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
12851 (goto-char (match-end 0))
12852 (backward-char)
12853 (forward-sexp)
12854 (setq pos (point))
12855 (vhdl-forward-syntactic-ws)
12856 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
12857 (goto-char (match-end 0))
12858 (backward-char)
12859 (forward-sexp)
12860 (setq pos (point)))
12861 (goto-char pos))
12862 ;; subprogram declaration/body
12863 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12864 (goto-char (match-end 0))
12865 (vhdl-forward-syntactic-ws)
12866 (when (looking-at "(")
12867 (forward-sexp))
12868 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12869 (vhdl-in-literal)))
12870 ;; subprogram body
12871 (when (match-string 2)
12872 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12873 (backward-word 1)
12874 (vhdl-forward-sexp)))
12875 ;; block (recursive)
12876 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12877 (goto-char (match-end 0))
12878 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12879 (match-beginning 2))
12880 (vhdl-hs-forward-sexp-func count)))
12881 ;; process
12882 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12883 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12884 ;; configuration declaration
12885 ((looking-at "^\\s-*configuration\\>")
12886 (forward-word 4)
12887 (vhdl-forward-sexp))
12888 (t (goto-char pos))))))
12890 (defun vhdl-hideshow-init ()
12891 "Initialize `hideshow'."
12892 (when vhdl-hideshow-menu
12893 (vhdl-hs-minor-mode 1)))
12895 (defun vhdl-hs-minor-mode (&optional arg)
12896 "Toggle hideshow minor mode and update menu bar."
12897 (interactive "P")
12898 (require 'hideshow)
12899 ;; check for hideshow version 5.x
12900 (if (not (boundp 'hs-block-start-mdata-select))
12901 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12902 ;; initialize hideshow
12903 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12904 (setq hs-special-modes-alist
12905 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12906 'vhdl-hs-forward-sexp-func nil)
12907 hs-special-modes-alist)))
12908 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
12909 (if vhdl-hide-all-init
12910 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
12911 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
12912 (hs-minor-mode arg)
12913 (force-mode-line-update))) ; hack to update menu bar
12916 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12917 ;;; Font locking
12918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12919 ;; (using `font-lock.el')
12921 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12922 ;; Help functions
12924 (defun vhdl-within-translate-off ()
12925 "Return point if within translate-off region, else nil."
12926 (and (save-excursion
12927 (re-search-backward
12928 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12929 (equal "off" (match-string 1))
12930 (point)))
12932 (defun vhdl-start-translate-off (limit)
12933 "Return point before translate-off pragma if before LIMIT, else nil."
12934 (when (re-search-forward
12935 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12936 (match-beginning 0)))
12938 (defun vhdl-end-translate-off (limit)
12939 "Return point after translate-on pragma if before LIMIT, else nil."
12940 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12942 (defun vhdl-match-translate-off (limit)
12943 "Match a translate-off block, setting match-data and returning t, else nil."
12944 (when (< (point) limit)
12945 (let ((start (or (vhdl-within-translate-off)
12946 (vhdl-start-translate-off limit)))
12947 (case-fold-search t))
12948 (when start
12949 (let ((end (or (vhdl-end-translate-off limit) limit)))
12950 (set-match-data (list start end))
12951 (goto-char end))))))
12953 (defun vhdl-font-lock-match-item (limit)
12954 "Match, and move over, any declaration item after point. Adapted from
12955 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12956 (condition-case nil
12957 (save-restriction
12958 (narrow-to-region (point-min) limit)
12959 ;; match item
12960 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12961 (save-match-data
12962 (goto-char (match-end 1))
12963 ;; move to next item
12964 (if (looking-at "\\(\\s-*,\\)")
12965 (goto-char (match-end 1))
12966 (end-of-line) t))))
12967 (error t)))
12969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12970 ;; Syntax definitions
12972 (defconst vhdl-font-lock-syntactic-keywords
12973 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12974 "Mark single quotes as having string quote syntax in 'c' instances.")
12976 (defvar vhdl-font-lock-keywords nil
12977 "Regular expressions to highlight in VHDL Mode.")
12979 (defvar vhdl-font-lock-keywords-0
12980 ;; set in `vhdl-font-lock-init' because dependent on user options
12981 "For consideration as a value of `vhdl-font-lock-keywords'.
12982 This does highlighting of template prompts and directives (pragmas).")
12984 (defvar vhdl-font-lock-keywords-1 nil
12985 ;; set in `vhdl-font-lock-init' because dependent on user options
12986 "For consideration as a value of `vhdl-font-lock-keywords'.
12987 This does highlighting of keywords and standard identifiers.")
12989 (defconst vhdl-font-lock-keywords-2
12990 (list
12991 ;; highlight names of units, subprograms, and components when declared
12992 (list
12993 (concat
12994 "^\\s-*\\("
12995 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12996 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12997 "\\)\\s-+\\(\\w+\\)")
12998 5 'font-lock-function-name-face)
13000 ;; highlight entity names of architectures and configurations
13001 (list
13002 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13003 2 'font-lock-function-name-face)
13005 ;; highlight labels of common constructs
13006 (list
13007 (concat
13008 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13009 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13010 "postponed\\|process\\|"
13011 (when (vhdl-standard-p 'ams) "procedural\\|")
13012 "with\\|while"
13013 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13014 1 'font-lock-function-name-face)
13016 ;; highlight label and component name of component instantiations
13017 (list
13018 (concat
13019 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13020 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13021 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13023 ;; highlight label and instantiated unit of component instantiations
13024 (list
13025 (concat
13026 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13027 "\\(component\\|configuration\\|entity\\)\\s-+"
13028 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13029 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13030 '(5 font-lock-function-name-face nil t)
13031 '(7 font-lock-function-name-face nil t))
13033 ;; highlight names and labels at end of constructs
13034 (list
13035 (concat
13036 "^\\s-*end\\s-+\\(\\("
13037 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
13038 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
13039 "procedure\\|\\(postponed\\s-+\\)?process\\|"
13040 (when (vhdl-standard-p 'ams) "procedural\\|")
13041 "units"
13042 "\\)\\s-+\\)?\\(\\w*\\)")
13043 5 'font-lock-function-name-face)
13045 ;; highlight labels in exit and next statements
13046 (list
13047 (concat
13048 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13049 3 'font-lock-function-name-face)
13051 ;; highlight entity name in attribute specifications
13052 (list
13053 (concat
13054 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13055 1 'font-lock-function-name-face)
13057 ;; highlight labels in block and component specifications
13058 (list
13059 (concat
13060 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13061 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13062 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13064 ;; highlight names in library clauses
13065 (list "^\\s-*library\\>"
13066 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13068 ;; highlight names in use clauses
13069 (list
13070 (concat
13071 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13072 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13073 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
13074 '(7 font-lock-function-name-face nil t))
13076 ;; highlight attribute name in attribute declarations/specifications
13077 (list
13078 (concat
13079 "^\\s-*attribute\\s-+\\(\\w+\\)")
13080 1 'vhdl-font-lock-attribute-face)
13082 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13083 (list
13084 (concat
13085 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13086 5 'font-lock-type-face)
13088 ;; highlight signal/variable/constant declaration names
13089 (list "\\(:[^=]\\)"
13090 '(vhdl-font-lock-match-item
13091 (progn (goto-char (match-beginning 1))
13092 (skip-syntax-backward " ")
13093 (skip-syntax-backward "w_")
13094 (skip-syntax-backward " ")
13095 (while (= (preceding-char) ?,)
13096 (backward-char 1)
13097 (skip-syntax-backward " ")
13098 (skip-syntax-backward "w_")
13099 (skip-syntax-backward " ")))
13100 ; (skip-chars-backward "^-(\n\";")
13101 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13103 ;; highlight formal parameters in component instantiations and subprogram
13104 ;; calls
13105 (list "\\(=>\\)"
13106 '(vhdl-font-lock-match-item
13107 (progn (goto-char (match-beginning 1))
13108 (skip-syntax-backward " ")
13109 (while (= (preceding-char) ?\)) (backward-sexp))
13110 (skip-syntax-backward "w_")
13111 (skip-syntax-backward " ")
13112 (when (memq (preceding-char) '(?n ?N ?|))
13113 (goto-char (point-max))))
13114 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13116 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13117 ;; variables
13118 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13119 '(vhdl-font-lock-match-item
13120 (progn (goto-char (match-end 1)) (match-beginning 2))
13121 nil (1 font-lock-variable-name-face)))
13123 "For consideration as a value of `vhdl-font-lock-keywords'.
13124 This does context sensitive highlighting of names and labels.")
13126 (defvar vhdl-font-lock-keywords-3 nil
13127 ;; set in `vhdl-font-lock-init' because dependent on user options
13128 "For consideration as a value of `vhdl-font-lock-keywords'.
13129 This does highlighting of words with special syntax.")
13131 (defvar vhdl-font-lock-keywords-4 nil
13132 ;; set in `vhdl-font-lock-init' because dependent on user options
13133 "For consideration as a value of `vhdl-font-lock-keywords'.
13134 This does highlighting of additional reserved words.")
13136 (defconst vhdl-font-lock-keywords-5
13137 ;; background highlight translate-off regions
13138 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13139 "For consideration as a value of `vhdl-font-lock-keywords'.
13140 This does background highlighting of translate-off regions.")
13142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13143 ;; Font and color definitions
13145 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13146 "Face name to use for prompts.")
13148 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13149 "Face name to use for standardized attributes.")
13151 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13152 "Face name to use for standardized enumeration values.")
13154 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13155 "Face name to use for standardized functions and packages.")
13157 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13158 "Face name to use for directives.")
13160 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13161 "Face name to use for additional reserved words.")
13163 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13164 "Face name to use for translate-off regions.")
13166 ;; face names to use for words with special syntax.
13167 (let ((syntax-alist vhdl-special-syntax-alist)
13168 name)
13169 (while syntax-alist
13170 (setq name (vhdl-function-name
13171 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13172 (eval `(defvar ,name ',name
13173 ,(concat "Face name to use for "
13174 (nth 0 (car syntax-alist)) ".")))
13175 (setq syntax-alist (cdr syntax-alist))))
13177 (defgroup vhdl-highlight-faces nil
13178 "Faces for highlighting."
13179 :group 'vhdl-highlight)
13181 ;; add faces used from `font-lock'
13182 (custom-add-to-group
13183 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13184 (custom-add-to-group
13185 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13186 (custom-add-to-group
13187 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13188 (custom-add-to-group
13189 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13190 (custom-add-to-group
13191 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13192 (custom-add-to-group
13193 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13195 (defface vhdl-font-lock-prompt-face
13196 '((((min-colors 88) (class color) (background light))
13197 (:foreground "Red1" :bold t))
13198 (((class color) (background light)) (:foreground "Red" :bold t))
13199 (((class color) (background dark)) (:foreground "Pink" :bold t))
13200 (t (:inverse-video t)))
13201 "Font lock mode face used to highlight prompts."
13202 :group 'vhdl-highlight-faces)
13204 (defface vhdl-font-lock-attribute-face
13205 '((((class color) (background light)) (:foreground "Orchid"))
13206 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13207 (t (:italic t :bold t)))
13208 "Font lock mode face used to highlight standardized attributes."
13209 :group 'vhdl-highlight-faces)
13211 (defface vhdl-font-lock-enumvalue-face
13212 '((((class color) (background light)) (:foreground "SaddleBrown"))
13213 (((class color) (background dark)) (:foreground "BurlyWood"))
13214 (t (:italic t :bold t)))
13215 "Font lock mode face used to highlight standardized enumeration values."
13216 :group 'vhdl-highlight-faces)
13218 (defface vhdl-font-lock-function-face
13219 '((((class color) (background light)) (:foreground "Cyan4"))
13220 (((class color) (background dark)) (:foreground "Orchid1"))
13221 (t (:italic t :bold t)))
13222 "Font lock mode face used to highlight standardized functions and packages."
13223 :group 'vhdl-highlight-faces)
13225 (defface vhdl-font-lock-directive-face
13226 '((((class color) (background light)) (:foreground "CadetBlue"))
13227 (((class color) (background dark)) (:foreground "Aquamarine"))
13228 (t (:italic t :bold t)))
13229 "Font lock mode face used to highlight directives."
13230 :group 'vhdl-highlight-faces)
13232 (defface vhdl-font-lock-reserved-words-face
13233 '((((class color) (background light)) (:foreground "Orange" :bold t))
13234 (((min-colors 88) (class color) (background dark))
13235 (:foreground "Yellow1" :bold t))
13236 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13237 (t ()))
13238 "Font lock mode face used to highlight additional reserved words."
13239 :group 'vhdl-highlight-faces)
13241 (defface vhdl-font-lock-translate-off-face
13242 '((((class color) (background light)) (:background "LightGray"))
13243 (((class color) (background dark)) (:background "DimGray"))
13244 (t ()))
13245 "Font lock mode face used to background highlight translate-off regions."
13246 :group 'vhdl-highlight-faces)
13248 ;; font lock mode faces used to highlight words with special syntax.
13249 (let ((syntax-alist vhdl-special-syntax-alist))
13250 (while syntax-alist
13251 (eval `(defface ,(vhdl-function-name
13252 "vhdl-font-lock" (caar syntax-alist) "face")
13253 '((((class color) (background light))
13254 (:foreground ,(nth 2 (car syntax-alist))))
13255 (((class color) (background dark))
13256 (:foreground ,(nth 3 (car syntax-alist))))
13257 (t ()))
13258 ,(concat "Font lock mode face used to highlight "
13259 (nth 0 (car syntax-alist)) ".")
13260 :group 'vhdl-highlight-faces))
13261 (setq syntax-alist (cdr syntax-alist))))
13263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13264 ;; Font lock initialization
13266 (defun vhdl-font-lock-init ()
13267 "Initialize fontification."
13268 ;; highlight template prompts and directives
13269 (setq vhdl-font-lock-keywords-0
13270 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13271 vhdl-template-prompt-syntax ">\\)")
13272 2 'vhdl-font-lock-prompt-face t)
13273 (list (concat "--\\s-*"
13274 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13275 2 'vhdl-font-lock-directive-face t)
13276 ;; highlight c-preprocessor directives
13277 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13278 '(1 font-lock-builtin-face)
13279 '(3 font-lock-variable-name-face nil t))))
13280 ;; highlight keywords and standardized types, attributes, enumeration
13281 ;; values, and subprograms
13282 (setq vhdl-font-lock-keywords-1
13283 (list
13284 (list (concat "'" vhdl-attributes-regexp)
13285 1 'vhdl-font-lock-attribute-face)
13286 (list vhdl-types-regexp 1 'font-lock-type-face)
13287 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13288 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13289 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13290 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13291 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13292 ;; highlight words with special syntax.
13293 (setq vhdl-font-lock-keywords-3
13294 (let ((syntax-alist vhdl-special-syntax-alist)
13295 keywords)
13296 (while syntax-alist
13297 (setq keywords
13298 (cons
13299 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13300 (vhdl-function-name
13301 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13302 (nth 4 (car syntax-alist)))
13303 keywords))
13304 (setq syntax-alist (cdr syntax-alist)))
13305 keywords))
13306 ;; highlight additional reserved words
13307 (setq vhdl-font-lock-keywords-4
13308 (list (list vhdl-reserved-words-regexp 1
13309 'vhdl-font-lock-reserved-words-face)))
13310 ;; highlight everything together
13311 (setq vhdl-font-lock-keywords
13312 (append
13313 vhdl-font-lock-keywords-0
13314 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13315 (when (or vhdl-highlight-forbidden-words
13316 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13317 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13318 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13319 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13321 ;; initialize fontification for VHDL Mode
13322 (vhdl-font-lock-init)
13324 (defun vhdl-fontify-buffer ()
13325 "Re-initialize fontification and fontify buffer."
13326 (interactive)
13327 (setq font-lock-defaults
13328 `(vhdl-font-lock-keywords
13329 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13330 beginning-of-line))
13331 (when (fboundp 'font-lock-unset-defaults)
13332 (font-lock-unset-defaults)) ; not implemented in XEmacs
13333 (font-lock-set-defaults)
13334 (font-lock-mode nil)
13335 (font-lock-mode t))
13337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13338 ;; Initialization for PostScript printing
13340 (defun vhdl-ps-print-settings ()
13341 "Initialize custom face and page settings for PostScript printing."
13342 ;; define custom face settings
13343 (unless (or (not vhdl-print-customize-faces)
13344 ps-print-color-p)
13345 (set (make-local-variable 'ps-bold-faces)
13346 '(font-lock-keyword-face
13347 font-lock-type-face
13348 vhdl-font-lock-attribute-face
13349 vhdl-font-lock-enumvalue-face
13350 vhdl-font-lock-directive-face))
13351 (set (make-local-variable 'ps-italic-faces)
13352 '(font-lock-comment-face
13353 font-lock-function-name-face
13354 font-lock-type-face
13355 vhdl-font-lock-attribute-face
13356 vhdl-font-lock-enumvalue-face
13357 vhdl-font-lock-directive-face))
13358 (set (make-local-variable 'ps-underlined-faces)
13359 '(font-lock-string-face))
13360 (setq ps-always-build-face-reference t))
13361 ;; define page settings, so that a line containing 79 characters (default)
13362 ;; fits into one column
13363 (when vhdl-print-two-column
13364 (set (make-local-variable 'ps-landscape-mode) t)
13365 (set (make-local-variable 'ps-number-of-columns) 2)
13366 (set (make-local-variable 'ps-font-size) 7.0)
13367 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13368 (set (make-local-variable 'ps-header-font-size) 9.0)
13369 (set (make-local-variable 'ps-header-offset) 12.0)
13370 (when (eq ps-paper-type 'letter)
13371 (set (make-local-variable 'ps-inter-column) 40.0)
13372 (set (make-local-variable 'ps-left-margin) 40.0)
13373 (set (make-local-variable 'ps-right-margin) 40.0))))
13375 (defun vhdl-ps-print-init ()
13376 "Initialize PostScript printing."
13377 (if (featurep 'xemacs)
13378 (when (boundp 'ps-print-color-p)
13379 (vhdl-ps-print-settings))
13380 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13381 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13385 ;;; Hierarchy browser (using `speedbar.el')
13386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13387 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13388 ;; directory by using the speedbar.
13390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13391 ;; Variables
13393 (defvar vhdl-entity-alist nil
13394 "Cache with entities and corresponding architectures for each
13395 project/directory.")
13396 ;; structure: (parenthesized expression means list of such entries)
13397 ;; (cache-key
13398 ;; (ent-key ent-name ent-file ent-line
13399 ;; (arch-key arch-name arch-file arch-line
13400 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13401 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13402 ;; (lib-name pack-key))
13403 ;; mra-key (lib-name pack-key))
13405 (defvar vhdl-config-alist nil
13406 "Cache with configurations for each project/directory.")
13407 ;; structure: (parenthesized expression means list of such entries)
13408 ;; (cache-key
13409 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13410 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13411 ;; inst-conf-key inst-lib-key)
13412 ;; (lib-name pack-key)))
13414 (defvar vhdl-package-alist nil
13415 "Cache with packages for each project/directory.")
13416 ;; structure: (parenthesized expression means list of such entries)
13417 ;; (cache-key
13418 ;; (pack-key pack-name pack-file pack-line
13419 ;; (comp-key comp-name comp-file comp-line)
13420 ;; (func-key func-name func-file func-line)
13421 ;; (lib-name pack-key)
13422 ;; pack-body-file pack-body-line
13423 ;; (func-key func-name func-body-file func-body-line)
13424 ;; (lib-name pack-key)))
13426 (defvar vhdl-ent-inst-alist nil
13427 "Cache with instantiated entities for each project/directory.")
13428 ;; structure: (parenthesized expression means list of such entries)
13429 ;; (cache-key (inst-ent-key))
13431 (defvar vhdl-file-alist nil
13432 "Cache with design units in each file for each project/directory.")
13433 ;; structure: (parenthesized expression means list of such entries)
13434 ;; (cache-key
13435 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13436 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13438 (defvar vhdl-directory-alist nil
13439 "Cache with source directories for each project.")
13440 ;; structure: (parenthesized expression means list of such entries)
13441 ;; (cache-key (directory))
13443 (defvar vhdl-speedbar-shown-unit-alist nil
13444 "Alist of design units simultaneously open in the current speedbar for each
13445 directory and project.")
13447 (defvar vhdl-speedbar-shown-project-list nil
13448 "List of projects simultaneously open in the current speedbar.")
13450 (defvar vhdl-updated-project-list nil
13451 "List of projects and directories with updated files.")
13453 (defvar vhdl-modified-file-list nil
13454 "List of modified files to be rescanned for hierarchy updating.")
13456 (defvar vhdl-speedbar-hierarchy-depth 0
13457 "Depth of instantiation hierarchy to display.")
13459 (defvar vhdl-speedbar-show-projects nil
13460 "Non-nil means project hierarchy is displayed in speedbar, directory
13461 hierarchy otherwise.")
13463 (defun vhdl-get-end-of-unit ()
13464 "Return position of end of current unit."
13465 (let ((pos (point)))
13466 (save-excursion
13467 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13468 (save-excursion
13469 (goto-char (match-beginning 0))
13470 (vhdl-backward-syntactic-ws)
13471 (and (/= (preceding-char) ?\;) (not (bobp))))))
13472 (re-search-backward "^[ \t]*end\\>" pos 1)
13473 (point))))
13475 (defun vhdl-match-string-downcase (num &optional string)
13476 "Like `match-string-no-properties' with down-casing."
13477 (let ((match (match-string-no-properties num string)))
13478 (and match (downcase match))))
13481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13482 ;; Scan functions
13484 (defun vhdl-scan-context-clause ()
13485 "Scan the context clause that precedes a design unit."
13486 (let (lib-alist)
13487 (save-excursion
13488 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13489 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13490 (equal "USE" (upcase (match-string 1))))
13491 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13492 (setq lib-alist (cons (cons (match-string-no-properties 1)
13493 (vhdl-match-string-downcase 2))
13494 lib-alist))))))
13495 lib-alist))
13497 (defun vhdl-scan-directory-contents (name &optional project update num-string
13498 non-final)
13499 "Scan contents of VHDL files in directory or file pattern NAME."
13500 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13501 ; (unless (file-directory-p (match-string 1 name))
13502 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13503 (let* ((dir-name (match-string 1 name))
13504 (file-pattern (match-string 2 name))
13505 (is-directory (= 0 (length file-pattern)))
13506 (file-list
13507 (if update
13508 (list name)
13509 (if is-directory
13510 (vhdl-get-source-files t dir-name)
13511 (vhdl-directory-files
13512 dir-name t (wildcard-to-regexp file-pattern)))))
13513 (key (or project dir-name))
13514 (file-exclude-regexp
13515 (or (nth 3 (aget vhdl-project-alist project)) ""))
13516 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13517 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13518 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13519 ent-alist conf-alist pack-alist ent-inst-list file-alist
13520 tmp-list tmp-entry no-files files-exist big-files)
13521 (when (or project update)
13522 (setq ent-alist (aget vhdl-entity-alist key t)
13523 conf-alist (aget vhdl-config-alist key t)
13524 pack-alist (aget vhdl-package-alist key t)
13525 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13526 file-alist (aget vhdl-file-alist key t)))
13527 (when (and (not is-directory) (null file-list))
13528 (message "No such file: \"%s\"" name))
13529 (setq files-exist file-list)
13530 (when file-list
13531 (setq no-files (length file-list))
13532 (message "Scanning %s %s\"%s\"..."
13533 (if is-directory "directory" "files") (or num-string "") name)
13534 ;; exclude files
13535 (unless (equal file-exclude-regexp "")
13536 (let ((case-fold-search nil)
13537 file-tmp-list)
13538 (while file-list
13539 (unless (string-match file-exclude-regexp (car file-list))
13540 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13541 (setq file-list (cdr file-list)))
13542 (setq file-list (nreverse file-tmp-list))))
13543 ;; do for all files
13544 (while file-list
13545 (unless noninteractive
13546 (message "Scanning %s %s\"%s\"... (%2d%s)"
13547 (if is-directory "directory" "files")
13548 (or num-string "") name
13549 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13550 (let ((file-name (abbreviate-file-name (car file-list)))
13551 ent-list arch-list arch-ent-list conf-list
13552 pack-list pack-body-list inst-list inst-ent-list)
13553 ;; scan file
13554 (vhdl-visit-file
13555 file-name nil
13556 (vhdl-prepare-search-2
13557 (save-excursion
13558 ;; scan for design units
13559 (if (and limit-design-file-size
13560 (< limit-design-file-size (buffer-size)))
13561 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13562 (setq big-files t))
13563 ;; scan for entities
13564 (goto-char (point-min))
13565 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13566 (let* ((ent-name (match-string-no-properties 1))
13567 (ent-key (downcase ent-name))
13568 (ent-entry (aget ent-alist ent-key t))
13569 (lib-alist (vhdl-scan-context-clause)))
13570 (if (nth 1 ent-entry)
13571 (vhdl-warning-when-idle
13572 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13573 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13574 file-name (vhdl-current-line))
13575 (setq ent-list (cons ent-key ent-list))
13576 (aput 'ent-alist ent-key
13577 (list ent-name file-name (vhdl-current-line)
13578 (nth 3 ent-entry) (nth 4 ent-entry)
13579 lib-alist)))))
13580 ;; scan for architectures
13581 (goto-char (point-min))
13582 (while (re-search-forward "^[ \t]*architecture[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13583 (let* ((arch-name (match-string-no-properties 1))
13584 (arch-key (downcase arch-name))
13585 (ent-name (match-string-no-properties 2))
13586 (ent-key (downcase ent-name))
13587 (ent-entry (aget ent-alist ent-key t))
13588 (arch-alist (nth 3 ent-entry))
13589 (arch-entry (aget arch-alist arch-key t))
13590 (lib-arch-alist (vhdl-scan-context-clause)))
13591 (if arch-entry
13592 (vhdl-warning-when-idle
13593 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13594 arch-name ent-name (nth 1 arch-entry)
13595 (nth 2 arch-entry) file-name (vhdl-current-line))
13596 (setq arch-list (cons arch-key arch-list)
13597 arch-ent-list (cons ent-key arch-ent-list))
13598 (aput 'arch-alist arch-key
13599 (list arch-name file-name (vhdl-current-line) nil
13600 lib-arch-alist))
13601 (aput 'ent-alist ent-key
13602 (list (or (nth 0 ent-entry) ent-name)
13603 (nth 1 ent-entry) (nth 2 ent-entry)
13604 (vhdl-sort-alist arch-alist)
13605 arch-key (nth 5 ent-entry))))))
13606 ;; scan for configurations
13607 (goto-char (point-min))
13608 (while (re-search-forward "^[ \t]*configuration[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13609 (let* ((conf-name (match-string-no-properties 1))
13610 (conf-key (downcase conf-name))
13611 (conf-entry (aget conf-alist conf-key t))
13612 (ent-name (match-string-no-properties 2))
13613 (ent-key (downcase ent-name))
13614 (lib-alist (vhdl-scan-context-clause))
13615 (conf-line (vhdl-current-line))
13616 (end-of-unit (vhdl-get-end-of-unit))
13617 arch-key comp-conf-list inst-key-list
13618 inst-comp-key inst-ent-key inst-arch-key
13619 inst-conf-key inst-lib-key)
13620 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13621 (setq arch-key (vhdl-match-string-downcase 1)))
13622 (if conf-entry
13623 (vhdl-warning-when-idle
13624 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13625 conf-name ent-name (nth 1 conf-entry)
13626 (nth 2 conf-entry) file-name conf-line)
13627 (setq conf-list (cons conf-key conf-list))
13628 ;; scan for subconfigurations and subentities
13629 (while (re-search-forward "^[ \t]*for[ \t\n\r\f]+\\(\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]+" end-of-unit t)
13630 (setq inst-comp-key (vhdl-match-string-downcase 3)
13631 inst-key-list (split-string
13632 (vhdl-match-string-downcase 1)
13633 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13634 (vhdl-forward-syntactic-ws)
13635 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13636 (setq
13637 inst-lib-key (vhdl-match-string-downcase 3)
13638 inst-ent-key (and (match-string 2)
13639 (vhdl-match-string-downcase 4))
13640 inst-arch-key (and (match-string 2)
13641 (vhdl-match-string-downcase 6))
13642 inst-conf-key (and (not (match-string 2))
13643 (vhdl-match-string-downcase 4)))
13644 (while inst-key-list
13645 (setq comp-conf-list
13646 (cons (list (car inst-key-list)
13647 inst-comp-key inst-ent-key
13648 inst-arch-key inst-conf-key
13649 inst-lib-key)
13650 comp-conf-list))
13651 (setq inst-key-list (cdr inst-key-list)))))
13652 (aput 'conf-alist conf-key
13653 (list conf-name file-name conf-line ent-key
13654 arch-key comp-conf-list lib-alist)))))
13655 ;; scan for packages
13656 (goto-char (point-min))
13657 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13658 (let* ((pack-name (match-string-no-properties 2))
13659 (pack-key (downcase pack-name))
13660 (is-body (match-string-no-properties 1))
13661 (pack-entry (aget pack-alist pack-key t))
13662 (pack-line (vhdl-current-line))
13663 (end-of-unit (vhdl-get-end-of-unit))
13664 comp-name func-name comp-alist func-alist lib-alist)
13665 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13666 (vhdl-warning-when-idle
13667 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13668 (if is-body " body" "") pack-name
13669 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13670 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13671 file-name (vhdl-current-line))
13672 ;; scan for context clauses
13673 (setq lib-alist (vhdl-scan-context-clause))
13674 ;; scan for component and subprogram declarations/bodies
13675 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13676 (if (equal (upcase (match-string 1)) "COMPONENT")
13677 (setq comp-name (match-string-no-properties 2)
13678 comp-alist
13679 (cons (list (downcase comp-name) comp-name
13680 file-name (vhdl-current-line))
13681 comp-alist))
13682 (setq func-name (match-string-no-properties 2)
13683 func-alist
13684 (cons (list (downcase func-name) func-name
13685 file-name (vhdl-current-line))
13686 func-alist))))
13687 (setq func-alist (nreverse func-alist))
13688 (setq comp-alist (nreverse comp-alist))
13689 (if is-body
13690 (setq pack-body-list (cons pack-key pack-body-list))
13691 (setq pack-list (cons pack-key pack-list)))
13692 (aput
13693 'pack-alist pack-key
13694 (if is-body
13695 (list (or (nth 0 pack-entry) pack-name)
13696 (nth 1 pack-entry) (nth 2 pack-entry)
13697 (nth 3 pack-entry) (nth 4 pack-entry)
13698 (nth 5 pack-entry)
13699 file-name pack-line func-alist lib-alist)
13700 (list pack-name file-name pack-line
13701 comp-alist func-alist lib-alist
13702 (nth 6 pack-entry) (nth 7 pack-entry)
13703 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13704 ;; scan for hierarchy
13705 (if (and limit-hier-file-size
13706 (< limit-hier-file-size (buffer-size)))
13707 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13708 (setq big-files t))
13709 ;; scan for architectures
13710 (goto-char (point-min))
13711 (while (re-search-forward "^[ \t]*architecture[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13712 (let* ((ent-name (match-string-no-properties 2))
13713 (ent-key (downcase ent-name))
13714 (arch-name (match-string-no-properties 1))
13715 (arch-key (downcase arch-name))
13716 (ent-entry (aget ent-alist ent-key t))
13717 (arch-alist (nth 3 ent-entry))
13718 (arch-entry (aget arch-alist arch-key t))
13719 (beg-of-unit (point))
13720 (end-of-unit (vhdl-get-end-of-unit))
13721 (inst-no 0)
13722 inst-alist inst-path)
13723 ;; scan for contained instantiations
13724 (while (and (re-search-forward
13725 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
13726 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
13727 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
13728 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
13729 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13730 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13731 (or (not limit-hier-inst-no)
13732 (<= (setq inst-no (1+ inst-no))
13733 limit-hier-inst-no)))
13734 (cond
13735 ;; block/generate beginning found
13736 ((match-string 14)
13737 (setq inst-path
13738 (cons (match-string-no-properties 1) inst-path)))
13739 ;; block/generate end found
13740 ((match-string 16)
13741 (setq inst-path (cdr inst-path)))
13742 ;; instantiation found
13744 (let* ((inst-name (match-string-no-properties 1))
13745 (inst-key (downcase inst-name))
13746 (inst-comp-name
13747 (or (match-string-no-properties 3)
13748 (match-string-no-properties 6)))
13749 (inst-ent-key
13750 (or (and (match-string 8)
13751 (vhdl-match-string-downcase 11))
13752 (and inst-comp-name
13753 (downcase inst-comp-name))))
13754 (inst-arch-key (vhdl-match-string-downcase 13))
13755 (inst-conf-key
13756 (and (not (match-string 8))
13757 (vhdl-match-string-downcase 11)))
13758 (inst-lib-key (vhdl-match-string-downcase 10)))
13759 (goto-char (match-end 1))
13760 (setq inst-list (cons inst-key inst-list)
13761 inst-ent-list
13762 (cons inst-ent-key inst-ent-list))
13763 (setq inst-alist
13764 (append
13765 inst-alist
13766 (list (list inst-key inst-name file-name
13767 (vhdl-current-line) inst-comp-name
13768 inst-ent-key inst-arch-key
13769 inst-conf-key inst-lib-key
13770 (reverse inst-path)))))))))
13771 ;; scan for contained configuration specifications
13772 (goto-char beg-of-unit)
13773 (while (re-search-forward
13774 (concat "^[ \t]*for[ \t\n\r\f]+\\(\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*"
13775 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
13776 (let* ((inst-comp-name (match-string-no-properties 3))
13777 (inst-ent-key
13778 (and (match-string 6)
13779 (vhdl-match-string-downcase 9)))
13780 (inst-arch-key (vhdl-match-string-downcase 11))
13781 (inst-conf-key
13782 (and (not (match-string 6))
13783 (vhdl-match-string-downcase 9)))
13784 (inst-lib-key (vhdl-match-string-downcase 8))
13785 (inst-key-list
13786 (split-string (vhdl-match-string-downcase 1)
13787 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13788 (tmp-inst-alist inst-alist)
13789 inst-entry)
13790 (while tmp-inst-alist
13791 (when (and (or (equal "all" (car inst-key-list))
13792 (member (nth 0 (car tmp-inst-alist))
13793 inst-key-list))
13794 (equal
13795 (downcase
13796 (or (nth 4 (car tmp-inst-alist)) ""))
13797 (downcase inst-comp-name)))
13798 (setq inst-entry (car tmp-inst-alist))
13799 (setq inst-ent-list
13800 (cons (or inst-ent-key (nth 5 inst-entry))
13801 (vhdl-delete
13802 (nth 5 inst-entry) inst-ent-list)))
13803 (setq inst-entry
13804 (list (nth 0 inst-entry) (nth 1 inst-entry)
13805 (nth 2 inst-entry) (nth 3 inst-entry)
13806 (nth 4 inst-entry)
13807 (or inst-ent-key (nth 5 inst-entry))
13808 (or inst-arch-key (nth 6 inst-entry))
13809 inst-conf-key inst-lib-key))
13810 (setcar tmp-inst-alist inst-entry))
13811 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13812 ;; save in cache
13813 (aput 'arch-alist arch-key
13814 (list (nth 0 arch-entry) (nth 1 arch-entry)
13815 (nth 2 arch-entry) inst-alist
13816 (nth 4 arch-entry)))
13817 (aput 'ent-alist ent-key
13818 (list (nth 0 ent-entry) (nth 1 ent-entry)
13819 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13820 (nth 4 ent-entry) (nth 5 ent-entry)))
13821 (when (and limit-hier-inst-no
13822 (> inst-no limit-hier-inst-no))
13823 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13824 (setq big-files t))
13825 (goto-char end-of-unit))))
13826 ;; remember design units for this file
13827 (aput 'file-alist file-name
13828 (list ent-list arch-list arch-ent-list conf-list
13829 pack-list pack-body-list inst-list inst-ent-list))
13830 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13831 (setq file-list (cdr file-list))))
13832 (when (or (and (not project) files-exist)
13833 (and project (not non-final)))
13834 ;; consistency checks:
13835 ;; check whether each architecture has a corresponding entity
13836 (setq tmp-list ent-alist)
13837 (while tmp-list
13838 (when (null (nth 2 (car tmp-list)))
13839 (setq tmp-entry (car (nth 4 (car tmp-list))))
13840 (vhdl-warning-when-idle
13841 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13842 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13843 (nth 3 tmp-entry)))
13844 (setq tmp-list (cdr tmp-list)))
13845 ;; check whether configuration has a corresponding entity/architecture
13846 (setq tmp-list conf-alist)
13847 (while tmp-list
13848 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13849 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13850 (setq tmp-entry (car tmp-list))
13851 (vhdl-warning-when-idle
13852 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13853 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13854 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13855 (setq tmp-entry (car tmp-list))
13856 (vhdl-warning-when-idle
13857 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13858 (nth 1 tmp-entry) (nth 4 tmp-entry)
13859 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13860 (setq tmp-list (cdr tmp-list)))
13861 ;; check whether each package body has a package declaration
13862 (setq tmp-list pack-alist)
13863 (while tmp-list
13864 (when (null (nth 2 (car tmp-list)))
13865 (setq tmp-entry (car tmp-list))
13866 (vhdl-warning-when-idle
13867 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13868 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13869 (setq tmp-list (cdr tmp-list)))
13870 ;; sort lists
13871 (setq ent-alist (vhdl-sort-alist ent-alist))
13872 (setq conf-alist (vhdl-sort-alist conf-alist))
13873 (setq pack-alist (vhdl-sort-alist pack-alist))
13874 ;; remember updated directory/project
13875 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13876 ;; clear directory alists
13877 (unless project
13878 (adelete 'vhdl-entity-alist key)
13879 (adelete 'vhdl-config-alist key)
13880 (adelete 'vhdl-package-alist key)
13881 (adelete 'vhdl-ent-inst-alist key)
13882 (adelete 'vhdl-file-alist key))
13883 ;; put directory contents into cache
13884 (aput 'vhdl-entity-alist key ent-alist)
13885 (aput 'vhdl-config-alist key conf-alist)
13886 (aput 'vhdl-package-alist key pack-alist)
13887 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13888 (aput 'vhdl-file-alist key file-alist)
13889 ;; final messages
13890 (message "Scanning %s %s\"%s\"...done"
13891 (if is-directory "directory" "files") (or num-string "") name)
13892 (unless project (message "Scanning directory...done"))
13893 (when big-files
13894 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13895 ;; save cache when scanned non-interactively
13896 (when (or (not project) (not non-final))
13897 (when (and noninteractive vhdl-speedbar-save-cache)
13898 (vhdl-save-cache key)))
13901 (defun vhdl-scan-project-contents (project)
13902 "Scan the contents of all VHDL files found in the directories and files
13903 of PROJECT."
13904 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13905 (default-dir (vhdl-resolve-env-variable
13906 (nth 1 (aget vhdl-project-alist project))))
13907 (file-exclude-regexp
13908 (or (nth 3 (aget vhdl-project-alist project)) ""))
13909 dir-list-tmp dir dir-name num-dir act-dir recursive)
13910 ;; clear project alists
13911 (adelete 'vhdl-entity-alist project)
13912 (adelete 'vhdl-config-alist project)
13913 (adelete 'vhdl-package-alist project)
13914 (adelete 'vhdl-ent-inst-alist project)
13915 (adelete 'vhdl-file-alist project)
13916 ;; expand directory names by default-directory
13917 (message "Collecting source files...")
13918 (while dir-list
13919 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13920 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13921 (setq recursive (match-string 1 dir)
13922 dir-name (match-string 3 dir))
13923 (setq dir-list-tmp
13924 (cons (concat recursive
13925 (if (file-name-absolute-p dir-name) "" default-dir)
13926 dir-name)
13927 dir-list-tmp))
13928 (setq dir-list (cdr dir-list)))
13929 ;; resolve path wildcards
13930 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13931 ;; expand directories
13932 (while dir-list-tmp
13933 (setq dir (car dir-list-tmp))
13934 ;; get subdirectories
13935 (if (string-match "-r \\(.*[/\\]\\)" dir)
13936 (setq dir-list (append dir-list (vhdl-get-subdirs
13937 (match-string 1 dir))))
13938 (setq dir-list (append dir-list (list dir))))
13939 (setq dir-list-tmp (cdr dir-list-tmp)))
13940 ;; exclude files
13941 (unless (equal file-exclude-regexp "")
13942 (let ((case-fold-search nil))
13943 (while dir-list
13944 (unless (string-match file-exclude-regexp (car dir-list))
13945 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13946 (setq dir-list (cdr dir-list)))
13947 (setq dir-list (nreverse dir-list-tmp))))
13948 (message "Collecting source files...done")
13949 ;; scan for design units for each directory in DIR-LIST
13950 (setq dir-list-tmp nil
13951 num-dir (length dir-list)
13952 act-dir 1)
13953 (while dir-list
13954 (setq dir-name (abbreviate-file-name
13955 (expand-file-name (car dir-list))))
13956 (vhdl-scan-directory-contents dir-name project nil
13957 (format "(%s/%s) " act-dir num-dir)
13958 (cdr dir-list))
13959 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13960 (setq dir-list (cdr dir-list)
13961 act-dir (1+ act-dir)))
13962 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13963 (message "Scanning project \"%s\"...done" project)))
13965 (defun vhdl-update-file-contents (file-name)
13966 "Update hierarchy information by contents of current buffer."
13967 (setq file-name (abbreviate-file-name file-name))
13968 (let* ((dir-name (file-name-directory file-name))
13969 (directory-alist vhdl-directory-alist)
13970 updated)
13971 (while directory-alist
13972 (when (member dir-name (nth 1 (car directory-alist)))
13973 (let* ((vhdl-project (nth 0 (car directory-alist)))
13974 (project (vhdl-project-p))
13975 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13976 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13977 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13978 (ent-inst-list (car (aget vhdl-ent-inst-alist
13979 (or project dir-name) t)))
13980 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13981 (file-entry (aget file-alist file-name t))
13982 (ent-list (nth 0 file-entry))
13983 (arch-list (nth 1 file-entry))
13984 (arch-ent-list (nth 2 file-entry))
13985 (conf-list (nth 3 file-entry))
13986 (pack-list (nth 4 file-entry))
13987 (pack-body-list (nth 5 file-entry))
13988 (inst-ent-list (nth 7 file-entry))
13989 (cache-key (or project dir-name))
13990 arch-alist key ent-key entry)
13991 ;; delete design units previously contained in this file:
13992 ;; entities
13993 (while ent-list
13994 (setq key (car ent-list)
13995 entry (aget ent-alist key t))
13996 (when (equal file-name (nth 1 entry))
13997 (if (nth 3 entry)
13998 (aput 'ent-alist key
13999 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14000 (adelete 'ent-alist key)))
14001 (setq ent-list (cdr ent-list)))
14002 ;; architectures
14003 (while arch-list
14004 (setq key (car arch-list)
14005 ent-key (car arch-ent-list)
14006 entry (aget ent-alist ent-key t)
14007 arch-alist (nth 3 entry))
14008 (when (equal file-name (nth 1 (aget arch-alist key t)))
14009 (adelete 'arch-alist key)
14010 (if (or (nth 1 entry) arch-alist)
14011 (aput 'ent-alist ent-key
14012 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14013 arch-alist (nth 4 entry) (nth 5 entry)))
14014 (adelete 'ent-alist ent-key)))
14015 (setq arch-list (cdr arch-list)
14016 arch-ent-list (cdr arch-ent-list)))
14017 ;; configurations
14018 (while conf-list
14019 (setq key (car conf-list))
14020 (when (equal file-name (nth 1 (aget conf-alist key t)))
14021 (adelete 'conf-alist key))
14022 (setq conf-list (cdr conf-list)))
14023 ;; package declarations
14024 (while pack-list
14025 (setq key (car pack-list)
14026 entry (aget pack-alist key t))
14027 (when (equal file-name (nth 1 entry))
14028 (if (nth 6 entry)
14029 (aput 'pack-alist key
14030 (list (nth 0 entry) nil nil nil nil nil
14031 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14032 (nth 9 entry)))
14033 (adelete 'pack-alist key)))
14034 (setq pack-list (cdr pack-list)))
14035 ;; package bodies
14036 (while pack-body-list
14037 (setq key (car pack-body-list)
14038 entry (aget pack-alist key t))
14039 (when (equal file-name (nth 6 entry))
14040 (if (nth 1 entry)
14041 (aput 'pack-alist key
14042 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14043 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14044 nil nil nil nil))
14045 (adelete 'pack-alist key)))
14046 (setq pack-body-list (cdr pack-body-list)))
14047 ;; instantiated entities
14048 (while inst-ent-list
14049 (setq ent-inst-list
14050 (vhdl-delete (car inst-ent-list) ent-inst-list))
14051 (setq inst-ent-list (cdr inst-ent-list)))
14052 ;; update caches
14053 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
14054 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
14055 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
14056 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14057 ;; scan file
14058 (vhdl-scan-directory-contents file-name project t)
14059 (when (or (and vhdl-speedbar-show-projects project)
14060 (and (not vhdl-speedbar-show-projects) (not project)))
14061 (vhdl-speedbar-refresh project))
14062 (setq updated t)))
14063 (setq directory-alist (cdr directory-alist)))
14064 updated))
14066 (defun vhdl-update-hierarchy ()
14067 "Update directory and hierarchy information in speedbar."
14068 (let ((file-list (reverse vhdl-modified-file-list))
14069 updated)
14070 (when (and vhdl-speedbar-update-on-saving file-list)
14071 (while file-list
14072 (setq updated
14073 (or (vhdl-update-file-contents (car file-list))
14074 updated))
14075 (setq file-list (cdr file-list)))
14076 (setq vhdl-modified-file-list nil)
14077 (vhdl-speedbar-update-current-unit)
14078 (when updated (message "Updating hierarchy...done")))))
14080 ;; structure (parenthesized expression means list of such entries)
14081 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14082 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14083 ;; comp-lib-name level)
14084 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14085 conf-inst-alist level indent
14086 &optional include-top ent-hier)
14087 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14088 entity ENT-KEY."
14089 (let* ((ent-entry (aget ent-alist ent-key t))
14090 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
14091 (cdar (last (nth 3 ent-entry)))))
14092 (inst-alist (nth 3 arch-entry))
14093 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14094 hier-list subcomp-list tmp-list inst-key inst-comp-name
14095 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14096 (when (= level 0) (message "Extract design hierarchy..."))
14097 (when include-top
14098 (setq level (1+ level)))
14099 (when (member ent-key ent-hier)
14100 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14101 ;; check configured architecture (already checked during scanning)
14102 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
14103 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
14104 ;; process all instances
14105 (while inst-alist
14106 (setq inst-entry (car inst-alist)
14107 inst-key (nth 0 inst-entry)
14108 inst-comp-name (nth 4 inst-entry)
14109 inst-conf-key (nth 7 inst-entry))
14110 ;; search entry in configuration's instantiations list
14111 (setq tmp-list conf-inst-alist)
14112 (while (and tmp-list
14113 (not (and (member (nth 0 (car tmp-list))
14114 (list "all" inst-key))
14115 (equal (nth 1 (car tmp-list))
14116 (downcase (or inst-comp-name ""))))))
14117 (setq tmp-list (cdr tmp-list)))
14118 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14119 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
14120 (when (and inst-conf-key (not inst-conf-entry))
14121 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14122 ;; determine entity
14123 (setq inst-ent-key
14124 (or (nth 2 (car tmp-list)) ; from configuration
14125 (nth 3 inst-conf-entry) ; from subconfiguration
14126 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
14127 ; from configuration spec.
14128 (nth 5 inst-entry))) ; from direct instantiation
14129 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
14130 ;; determine architecture
14131 (setq inst-arch-key
14132 (or (nth 3 (car tmp-list)) ; from configuration
14133 (nth 4 inst-conf-entry) ; from subconfiguration
14134 (nth 6 inst-entry) ; from direct instantiation
14135 (nth 4 (aget conf-alist (nth 7 inst-entry)))
14136 ; from configuration spec.
14137 (nth 4 inst-ent-entry) ; MRA
14138 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14139 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
14140 ;; set library
14141 (setq inst-lib-key
14142 (or (nth 5 (car tmp-list)) ; from configuration
14143 (nth 8 inst-entry))) ; from direct instantiation
14144 ;; gather information for this instance
14145 (setq comp-entry
14146 (list (nth 1 inst-entry)
14147 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14148 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14149 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14150 (or (nth 0 inst-arch-entry) inst-arch-key)
14151 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14152 (or (nth 0 inst-conf-entry) inst-conf-key)
14153 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14154 inst-lib-key level))
14155 ;; get subcomponent hierarchy
14156 (setq subcomp-list (vhdl-get-hierarchy
14157 ent-alist conf-alist
14158 inst-ent-key inst-arch-key inst-conf-key
14159 (nth 5 inst-conf-entry)
14160 (1+ level) indent nil (cons ent-key ent-hier)))
14161 ;; add to list
14162 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14163 (setq inst-alist (cdr inst-alist)))
14164 (when include-top
14165 (setq hier-list
14166 (cons (list nil nil (nth 0 ent-entry)
14167 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14168 (nth 0 arch-entry)
14169 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14170 nil nil
14171 nil (1- level))
14172 hier-list)))
14173 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14174 hier-list))
14176 (defun vhdl-get-instantiations (ent-key indent)
14177 "Get all instantiations of entity ENT-KEY."
14178 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
14179 arch-alist inst-alist ent-inst-list
14180 ent-entry arch-entry inst-entry)
14181 (while ent-alist
14182 (setq ent-entry (car ent-alist))
14183 (setq arch-alist (nth 4 ent-entry))
14184 (while arch-alist
14185 (setq arch-entry (car arch-alist))
14186 (setq inst-alist (nth 4 arch-entry))
14187 (while inst-alist
14188 (setq inst-entry (car inst-alist))
14189 (when (equal ent-key (nth 5 inst-entry))
14190 (setq ent-inst-list
14191 (cons (list (nth 1 inst-entry)
14192 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14193 (nth 1 ent-entry)
14194 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14195 (nth 1 arch-entry)
14196 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14197 ent-inst-list)))
14198 (setq inst-alist (cdr inst-alist)))
14199 (setq arch-alist (cdr arch-alist)))
14200 (setq ent-alist (cdr ent-alist)))
14201 (nreverse ent-inst-list)))
14203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14204 ;; Caching in file
14206 (defun vhdl-save-caches ()
14207 "Save all updated hierarchy caches to file."
14208 (interactive)
14209 (condition-case nil
14210 (when vhdl-speedbar-save-cache
14211 ;; update hierarchy
14212 (vhdl-update-hierarchy)
14213 (let ((project-list vhdl-updated-project-list))
14214 (message "Saving hierarchy caches...")
14215 ;; write updated project caches
14216 (while project-list
14217 (vhdl-save-cache (car project-list))
14218 (setq project-list (cdr project-list)))
14219 (message "Saving hierarchy caches...done")))
14220 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14221 (sit-for 2)))))
14223 (defun vhdl-save-cache (key)
14224 "Save current hierarchy cache to file."
14225 (let* ((orig-buffer (current-buffer))
14226 (vhdl-project key)
14227 (project (vhdl-project-p))
14228 (default-directory key)
14229 (directory (abbreviate-file-name (vhdl-default-directory)))
14230 (file-name (vhdl-resolve-env-variable
14231 (vhdl-replace-string
14232 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14233 (concat
14234 (subst-char-in-string ? ?_ (or project "dir"))
14235 " " (user-login-name)))))
14236 (file-dir-name (expand-file-name file-name directory))
14237 (cache-key (or project directory))
14238 (key (if project "project" "directory")))
14239 (unless (file-exists-p (file-name-directory file-dir-name))
14240 (make-directory (file-name-directory file-dir-name) t))
14241 (if (not (file-writable-p file-dir-name))
14242 (progn (vhdl-warning (format "File not writable: \"%s\""
14243 (abbreviate-file-name file-dir-name)))
14244 (sit-for 2))
14245 (message "Saving cache: \"%s\"" file-dir-name)
14246 (set-buffer (find-file-noselect file-dir-name t t))
14247 (erase-buffer)
14248 (insert ";; -*- Emacs-Lisp -*-\n\n"
14249 ";;; " (file-name-nondirectory file-name)
14250 " - design hierarchy cache file for Emacs VHDL Mode "
14251 vhdl-version "\n")
14252 (insert "\n;; " (if project "Project " "Directory") " : ")
14253 (if project (insert project) (prin1 directory (current-buffer)))
14254 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14255 (user-login-name) "\n\n"
14256 "\n;; version number\n"
14257 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14258 "\n;; " (if project "project" "directory") " name"
14259 "\n(setq " key " ")
14260 (prin1 (or project directory) (current-buffer))
14261 (insert ")\n")
14262 (when (member 'hierarchy vhdl-speedbar-save-cache)
14263 (insert "\n;; entity and architecture cache\n"
14264 "(aput 'vhdl-entity-alist " key " '")
14265 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
14266 (insert ")\n\n;; configuration cache\n"
14267 "(aput 'vhdl-config-alist " key " '")
14268 (print (aget vhdl-config-alist cache-key t) (current-buffer))
14269 (insert ")\n\n;; package cache\n"
14270 "(aput 'vhdl-package-alist " key " '")
14271 (print (aget vhdl-package-alist cache-key t) (current-buffer))
14272 (insert ")\n\n;; instantiated entities cache\n"
14273 "(aput 'vhdl-ent-inst-alist " key " '")
14274 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
14275 (insert ")\n\n;; design units per file cache\n"
14276 "(aput 'vhdl-file-alist " key " '")
14277 (print (aget vhdl-file-alist cache-key t) (current-buffer))
14278 (when project
14279 (insert ")\n\n;; source directories in project cache\n"
14280 "(aput 'vhdl-directory-alist " key " '")
14281 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
14282 (insert ")\n"))
14283 (when (member 'display vhdl-speedbar-save-cache)
14284 (insert "\n;; shown design units cache\n"
14285 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
14286 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
14287 (current-buffer))
14288 (insert ")\n"))
14289 (setq vhdl-updated-project-list
14290 (delete cache-key vhdl-updated-project-list))
14291 (save-buffer)
14292 (kill-buffer (current-buffer))
14293 (set-buffer orig-buffer))))
14295 (defun vhdl-load-cache (key)
14296 "Load hierarchy cache information from file."
14297 (let* ((vhdl-project key)
14298 (default-directory key)
14299 (directory (vhdl-default-directory))
14300 (file-name (vhdl-resolve-env-variable
14301 (vhdl-replace-string
14302 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14303 (concat
14304 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14305 " " (user-login-name)))))
14306 (file-dir-name (expand-file-name file-name directory))
14307 vhdl-cache-version)
14308 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14309 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14310 (when (file-exists-p file-dir-name)
14311 (condition-case ()
14312 (progn (load-file file-dir-name)
14313 (string< (mapconcat
14314 (lambda (a) (format "%3d" (string-to-number a)))
14315 (split-string "3.33" "\\.") "")
14316 (mapconcat
14317 (lambda (a) (format "%3d" (string-to-number a)))
14318 (split-string vhdl-cache-version "\\.") "")))
14319 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14320 nil))))))
14322 (defun vhdl-require-hierarchy-info ()
14323 "Make sure that hierarchy information is available. Load cache or scan files
14324 if required."
14325 (if (vhdl-project-p)
14326 (unless (or (assoc vhdl-project vhdl-file-alist)
14327 (vhdl-load-cache vhdl-project))
14328 (vhdl-scan-project-contents vhdl-project))
14329 (let ((directory (abbreviate-file-name default-directory)))
14330 (unless (or (assoc directory vhdl-file-alist)
14331 (vhdl-load-cache directory))
14332 (vhdl-scan-directory-contents directory)))))
14334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14335 ;; Add hierarchy browser functionality to speedbar
14337 (defvar vhdl-speedbar-key-map nil
14338 "Keymap used when in the VHDL hierarchy browser mode.")
14340 (defvar vhdl-speedbar-menu-items nil
14341 "Additional menu-items to add to speedbar frame.")
14343 (defun vhdl-speedbar-initialize ()
14344 "Initialize speedbar."
14345 ;; general settings
14346 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
14347 ;; VHDL file extensions (extracted from `auto-mode-alist')
14348 (let ((mode-alist auto-mode-alist))
14349 (while mode-alist
14350 (when (eq (cdar mode-alist) 'vhdl-mode)
14351 (speedbar-add-supported-extension (caar mode-alist)))
14352 (setq mode-alist (cdr mode-alist))))
14353 ;; hierarchy browser settings
14354 (when (boundp 'speedbar-mode-functions-list)
14355 ;; special functions
14356 (speedbar-add-mode-functions-list
14357 '("vhdl directory"
14358 (speedbar-item-info . vhdl-speedbar-item-info)
14359 (speedbar-line-directory . speedbar-files-line-path)))
14360 (speedbar-add-mode-functions-list
14361 '("vhdl project"
14362 (speedbar-item-info . vhdl-speedbar-item-info)
14363 (speedbar-line-directory . vhdl-speedbar-line-project)))
14364 ;; keymap
14365 (unless vhdl-speedbar-key-map
14366 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
14367 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14368 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14369 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
14370 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14371 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14372 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14373 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14374 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
14375 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14376 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
14377 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14378 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14379 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14380 (let ((key 0))
14381 (while (<= key 9)
14382 (define-key vhdl-speedbar-key-map (int-to-string key)
14383 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14384 (setq key (1+ key)))))
14385 (define-key speedbar-mode-map "h"
14386 (lambda () (interactive)
14387 (speedbar-change-initial-expansion-list "vhdl directory")))
14388 (define-key speedbar-mode-map "H"
14389 (lambda () (interactive)
14390 (speedbar-change-initial-expansion-list "vhdl project")))
14391 ;; menu
14392 (unless vhdl-speedbar-menu-items
14393 (setq
14394 vhdl-speedbar-menu-items
14395 `(["Edit" speedbar-edit-line t]
14396 ["Expand" speedbar-expand-line
14397 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14398 ["Contract" vhdl-speedbar-contract-level t]
14399 ["Expand All" vhdl-speedbar-expand-all t]
14400 ["Contract All" vhdl-speedbar-contract-all t]
14401 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14402 (while (<= key 9)
14403 (setq menu-list
14404 (cons `[,(if (= key 0) "All" (int-to-string key))
14405 (vhdl-speedbar-set-depth ,key)
14406 :style radio
14407 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14408 :keys ,(int-to-string key)]
14409 menu-list))
14410 (setq key (1+ key)))
14411 (nreverse menu-list))
14412 "--"
14413 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14414 (or (vhdl-speedbar-check-unit 'entity)
14415 (vhdl-speedbar-check-unit 'subprogram))]
14416 ["Place Component" vhdl-speedbar-place-component
14417 (vhdl-speedbar-check-unit 'entity)]
14418 ["Generate Configuration" vhdl-speedbar-configuration
14419 (vhdl-speedbar-check-unit 'architecture)]
14420 ["Select as MRA" vhdl-speedbar-select-mra
14421 (vhdl-speedbar-check-unit 'architecture)]
14422 ["Make" vhdl-speedbar-make-design
14423 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14424 ["Generate Makefile" vhdl-speedbar-generate-makefile
14425 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14426 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14427 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14428 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14429 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14430 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14431 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14432 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14433 ;; hook-ups
14434 (speedbar-add-expansion-list
14435 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14436 vhdl-speedbar-display-directory))
14437 (speedbar-add-expansion-list
14438 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14439 vhdl-speedbar-display-projects))
14440 (setq speedbar-stealthy-function-list
14441 (append
14442 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14443 ("vhdl project" vhdl-speedbar-update-current-project
14444 vhdl-speedbar-update-current-unit)
14445 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14446 ; (speedbar-extension-list-to-regex
14447 ; speedbar-ignored-path-expressions))))
14449 speedbar-stealthy-function-list))
14450 (when (eq vhdl-speedbar-display-mode 'directory)
14451 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14452 (when (eq vhdl-speedbar-display-mode 'project)
14453 (setq speedbar-initial-expansion-list-name "vhdl project"))
14454 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14456 (defun vhdl-speedbar (&optional arg)
14457 "Open/close speedbar."
14458 (interactive)
14459 (if (not (fboundp 'speedbar))
14460 (error "WARNING: Speedbar is not available or not installed")
14461 (condition-case ()
14462 (speedbar-frame-mode arg)
14463 (error (error "WARNING: An error occurred while opening speedbar")))))
14465 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14466 ;; Display functions
14468 (defvar vhdl-speedbar-last-selected-project nil
14469 "Name of last selected project.")
14471 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14472 (defmacro speedbar-with-writable (&rest forms)
14473 "Allow the buffer to be writable and evaluate FORMS."
14474 (list 'let '((inhibit-read-only t))
14475 (cons 'progn forms)))
14476 (put 'speedbar-with-writable 'lisp-indent-function 0)
14478 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14479 "Display directory and hierarchy information in speedbar."
14480 (setq vhdl-speedbar-show-projects nil)
14481 (setq speedbar-ignored-directory-regexp
14482 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14483 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14484 (setq speedbar-last-selected-file nil)
14485 (speedbar-with-writable
14486 (condition-case nil
14487 (progn
14488 ;; insert directory path
14489 (speedbar-directory-buttons directory depth)
14490 ;; insert subdirectories
14491 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14492 ;; scan and insert hierarchy of current directory
14493 (vhdl-speedbar-insert-dir-hierarchy directory depth
14494 speedbar-power-click)
14495 ;; expand subdirectories
14496 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14497 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14499 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14500 "Display projects and hierarchy information in speedbar."
14501 (setq vhdl-speedbar-show-projects t)
14502 (setq speedbar-ignored-directory-regexp ".")
14503 (setq speedbar-last-selected-file nil)
14504 (setq vhdl-speedbar-last-selected-project nil)
14505 (speedbar-with-writable
14506 (condition-case nil
14507 ;; insert projects
14508 (vhdl-speedbar-insert-projects)
14509 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14510 (setq speedbar-full-text-cache nil)) ; prevent caching
14512 (defun vhdl-speedbar-insert-projects ()
14513 "Insert all projects in speedbar."
14514 (vhdl-speedbar-make-title-line "Projects:")
14515 (let ((project-alist (if vhdl-project-sort
14516 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14517 vhdl-project-alist))
14518 (vhdl-speedbar-update-current-unit nil))
14519 ;; insert projects
14520 (while project-alist
14521 (speedbar-make-tag-line
14522 'angle ?+ 'vhdl-speedbar-expand-project
14523 (caar project-alist) (caar project-alist)
14524 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14525 (setq project-alist (cdr project-alist)))
14526 (setq project-alist vhdl-project-alist)
14527 ;; expand projects
14528 (while project-alist
14529 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14530 (goto-char (point-min))
14531 (when (re-search-forward
14532 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14533 (goto-char (match-end 1))
14534 (speedbar-do-function-pointer)))
14535 (setq project-alist (cdr project-alist))))
14536 ; (vhdl-speedbar-update-current-project)
14537 ; (vhdl-speedbar-update-current-unit nil t)
14540 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14541 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14542 otherwise use cached data."
14543 (when (or rescan (and (not (assoc project vhdl-file-alist))
14544 (not (vhdl-load-cache project))))
14545 (vhdl-scan-project-contents project))
14546 ;; insert design hierarchy
14547 (vhdl-speedbar-insert-hierarchy
14548 (aget vhdl-entity-alist project t)
14549 (aget vhdl-config-alist project t)
14550 (aget vhdl-package-alist project t)
14551 (car (aget vhdl-ent-inst-alist project t)) indent)
14552 (insert (int-to-string indent) ":\n")
14553 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14554 (put-text-property (1- (point)) (point) 'invisible nil)
14555 ;; expand design units
14556 (vhdl-speedbar-expand-units project))
14558 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14559 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14560 otherwise use cached data."
14561 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14562 (not (vhdl-load-cache directory))))
14563 (vhdl-scan-directory-contents directory))
14564 ;; insert design hierarchy
14565 (vhdl-speedbar-insert-hierarchy
14566 (aget vhdl-entity-alist directory t)
14567 (aget vhdl-config-alist directory t)
14568 (aget vhdl-package-alist directory t)
14569 (car (aget vhdl-ent-inst-alist directory t)) depth)
14570 ;; expand design units
14571 (vhdl-speedbar-expand-units directory)
14572 (aput 'vhdl-directory-alist directory (list (list directory))))
14574 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14575 ent-inst-list depth)
14576 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14577 (if (not (or ent-alist conf-alist pack-alist))
14578 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14579 (let (ent-entry conf-entry pack-entry)
14580 ;; insert entities
14581 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14582 (while ent-alist
14583 (setq ent-entry (car ent-alist))
14584 (speedbar-make-tag-line
14585 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14586 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14587 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14588 'vhdl-speedbar-entity-face depth)
14589 (unless (nth 2 ent-entry)
14590 (end-of-line 0) (insert "!") (forward-char 1))
14591 (unless (member (nth 0 ent-entry) ent-inst-list)
14592 (end-of-line 0) (insert " (top)") (forward-char 1))
14593 (setq ent-alist (cdr ent-alist)))
14594 ;; insert configurations
14595 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14596 (while conf-alist
14597 (setq conf-entry (car conf-alist))
14598 (speedbar-make-tag-line
14599 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14600 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14601 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14602 'vhdl-speedbar-configuration-face depth)
14603 (setq conf-alist (cdr conf-alist)))
14604 ;; insert packages
14605 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14606 (while pack-alist
14607 (setq pack-entry (car pack-alist))
14608 (vhdl-speedbar-make-pack-line
14609 (nth 0 pack-entry) (nth 1 pack-entry)
14610 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14611 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14612 depth)
14613 (setq pack-alist (cdr pack-alist))))))
14615 (defun vhdl-speedbar-rescan-hierarchy ()
14616 "Rescan hierarchy for the directory or project under the cursor."
14617 (interactive)
14618 (let (key path)
14619 (cond
14620 ;; current project
14621 (vhdl-speedbar-show-projects
14622 (setq key (vhdl-speedbar-line-project))
14623 (vhdl-scan-project-contents key))
14624 ;; top-level directory
14625 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14626 (re-search-forward "[0-9]+:" nil t)
14627 (vhdl-scan-directory-contents
14628 (abbreviate-file-name (speedbar-line-directory))))
14629 ;; current directory
14630 (t (setq path (speedbar-line-directory))
14631 (string-match "^\\(.+[/\\]\\)" path)
14632 (vhdl-scan-directory-contents
14633 (abbreviate-file-name (match-string 1 path)))))
14634 (vhdl-speedbar-refresh key)))
14636 (defun vhdl-speedbar-expand-dirs (directory)
14637 "Expand subdirectories in DIRECTORY according to
14638 `speedbar-shown-directories'."
14639 ;; (nicked from `speedbar-default-directory-list')
14640 (let ((sf (cdr (reverse speedbar-shown-directories)))
14641 (vhdl-speedbar-update-current-unit nil))
14642 (setq speedbar-shown-directories
14643 (list (expand-file-name default-directory)))
14644 (while sf
14645 (when (speedbar-goto-this-file (car sf))
14646 (beginning-of-line)
14647 (when (looking-at "[0-9]+:\\s-*<")
14648 (goto-char (match-end 0))
14649 (speedbar-do-function-pointer)))
14650 (setq sf (cdr sf))))
14651 (vhdl-speedbar-update-current-unit nil t))
14653 (defun vhdl-speedbar-expand-units (key)
14654 "Expand design units in directory/project KEY according to
14655 `vhdl-speedbar-shown-unit-alist'."
14656 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14657 (vhdl-speedbar-update-current-unit nil)
14658 vhdl-updated-project-list)
14659 (adelete 'vhdl-speedbar-shown-unit-alist key)
14660 (vhdl-prepare-search-1
14661 (while unit-alist ; expand units
14662 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14663 (beginning-of-line)
14664 (let ((arch-alist (nth 1 (car unit-alist)))
14665 position)
14666 (when (looking-at "^[0-9]+:\\s-*\\[")
14667 (goto-char (match-end 0))
14668 (setq position (point))
14669 (speedbar-do-function-pointer)
14670 (select-frame speedbar-frame)
14671 (while arch-alist ; expand architectures
14672 (goto-char position)
14673 (when (re-search-forward
14674 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14675 (car arch-alist) "\\>\\)") nil t)
14676 (beginning-of-line)
14677 (when (looking-at "^[0-9]+:\\s-*{")
14678 (goto-char (match-end 0))
14679 (speedbar-do-function-pointer)
14680 (select-frame speedbar-frame)))
14681 (setq arch-alist (cdr arch-alist))))
14682 (setq unit-alist (cdr unit-alist))))))
14683 (vhdl-speedbar-update-current-unit nil t))
14685 (defun vhdl-speedbar-contract-level ()
14686 "Contract current level in current directory/project."
14687 (interactive)
14688 (when (or (save-excursion
14689 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14690 (and (save-excursion
14691 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14692 (re-search-backward
14693 (format "^[0-%d]:\\s-*[[{<]-"
14694 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14695 (goto-char (match-end 0))
14696 (speedbar-do-function-pointer)
14697 (speedbar-center-buffer-smartly)))
14699 (defun vhdl-speedbar-contract-all ()
14700 "Contract all expanded design units in current directory/project."
14701 (interactive)
14702 (if (and vhdl-speedbar-show-projects
14703 (save-excursion (beginning-of-line) (looking-at "^0:")))
14704 (progn (setq vhdl-speedbar-shown-project-list nil)
14705 (vhdl-speedbar-refresh))
14706 (let ((key (vhdl-speedbar-line-key)))
14707 (adelete 'vhdl-speedbar-shown-unit-alist key)
14708 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14709 (when (memq 'display vhdl-speedbar-save-cache)
14710 (add-to-list 'vhdl-updated-project-list key)))))
14712 (defun vhdl-speedbar-expand-all ()
14713 "Expand all design units in current directory/project."
14714 (interactive)
14715 (let* ((key (vhdl-speedbar-line-key))
14716 (ent-alist (aget vhdl-entity-alist key t))
14717 (conf-alist (aget vhdl-config-alist key t))
14718 (pack-alist (aget vhdl-package-alist key t))
14719 arch-alist unit-alist subunit-alist)
14720 (add-to-list 'vhdl-speedbar-shown-project-list key)
14721 (while ent-alist
14722 (setq arch-alist (nth 4 (car ent-alist)))
14723 (setq subunit-alist nil)
14724 (while arch-alist
14725 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14726 (setq arch-alist (cdr arch-alist)))
14727 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14728 (setq ent-alist (cdr ent-alist)))
14729 (while conf-alist
14730 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14731 (setq conf-alist (cdr conf-alist)))
14732 (while pack-alist
14733 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14734 (setq pack-alist (cdr pack-alist)))
14735 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14736 (vhdl-speedbar-refresh)
14737 (when (memq 'display vhdl-speedbar-save-cache)
14738 (add-to-list 'vhdl-updated-project-list key))))
14740 (defun vhdl-speedbar-expand-project (text token indent)
14741 "Expand/contract the project under the cursor."
14742 (cond
14743 ((string-match "+" text) ; expand project
14744 (speedbar-change-expand-button-char ?-)
14745 (unless (member token vhdl-speedbar-shown-project-list)
14746 (setq vhdl-speedbar-shown-project-list
14747 (cons token vhdl-speedbar-shown-project-list)))
14748 (speedbar-with-writable
14749 (save-excursion
14750 (end-of-line) (forward-char 1)
14751 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14752 speedbar-power-click))))
14753 ((string-match "-" text) ; contract project
14754 (speedbar-change-expand-button-char ?+)
14755 (setq vhdl-speedbar-shown-project-list
14756 (delete token vhdl-speedbar-shown-project-list))
14757 (speedbar-delete-subblock indent))
14758 (t (error "Nothing to display")))
14759 (when (equal (selected-frame) speedbar-frame)
14760 (speedbar-center-buffer-smartly)))
14762 (defun vhdl-speedbar-expand-entity (text token indent)
14763 "Expand/contract the entity under the cursor."
14764 (cond
14765 ((string-match "+" text) ; expand entity
14766 (let* ((key (vhdl-speedbar-line-key indent))
14767 (ent-alist (aget vhdl-entity-alist key t))
14768 (ent-entry (aget ent-alist token t))
14769 (arch-alist (nth 3 ent-entry))
14770 (inst-alist (vhdl-get-instantiations token indent))
14771 (subpack-alist (nth 5 ent-entry))
14772 (multiple-arch (> (length arch-alist) 1))
14773 arch-entry inst-entry)
14774 (if (not (or arch-alist inst-alist subpack-alist))
14775 (speedbar-change-expand-button-char ??)
14776 (speedbar-change-expand-button-char ?-)
14777 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14778 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14779 (aput 'unit-alist token nil)
14780 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14781 (speedbar-with-writable
14782 (save-excursion
14783 (end-of-line) (forward-char 1)
14784 ;; insert architectures
14785 (when arch-alist
14786 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14787 (while arch-alist
14788 (setq arch-entry (car arch-alist))
14789 (speedbar-make-tag-line
14790 'curly ?+ 'vhdl-speedbar-expand-architecture
14791 (cons token (nth 0 arch-entry))
14792 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14793 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14794 'vhdl-speedbar-architecture-face (1+ indent))
14795 (when (and multiple-arch
14796 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14797 (end-of-line 0) (insert " (mra)") (forward-char 1))
14798 (setq arch-alist (cdr arch-alist)))
14799 ;; insert instantiations
14800 (when inst-alist
14801 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14802 (while inst-alist
14803 (setq inst-entry (car inst-alist))
14804 (vhdl-speedbar-make-inst-line
14805 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14806 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14807 nil nil nil (1+ indent) 0 " in ")
14808 (setq inst-alist (cdr inst-alist)))
14809 ;; insert required packages
14810 (vhdl-speedbar-insert-subpackages
14811 subpack-alist (1+ indent) indent)))
14812 (when (memq 'display vhdl-speedbar-save-cache)
14813 (add-to-list 'vhdl-updated-project-list key))
14814 (vhdl-speedbar-update-current-unit t t))))
14815 ((string-match "-" text) ; contract entity
14816 (speedbar-change-expand-button-char ?+)
14817 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14818 (let* ((key (vhdl-speedbar-line-key indent))
14819 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14820 (adelete 'unit-alist token)
14821 (if unit-alist
14822 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14823 (adelete 'vhdl-speedbar-shown-unit-alist key))
14824 (speedbar-delete-subblock indent)
14825 (when (memq 'display vhdl-speedbar-save-cache)
14826 (add-to-list 'vhdl-updated-project-list key))))
14827 (t (error "Nothing to display")))
14828 (when (equal (selected-frame) speedbar-frame)
14829 (speedbar-center-buffer-smartly)))
14831 (defun vhdl-speedbar-expand-architecture (text token indent)
14832 "Expand/contract the architecture under the cursor."
14833 (cond
14834 ((string-match "+" text) ; expand architecture
14835 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14836 (ent-alist (aget vhdl-entity-alist key t))
14837 (conf-alist (aget vhdl-config-alist key t))
14838 (hier-alist (vhdl-get-hierarchy
14839 ent-alist conf-alist (car token) (cdr token) nil nil
14840 0 (1- indent)))
14841 (ent-entry (aget ent-alist (car token) t))
14842 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14843 (subpack-alist (nth 4 arch-entry))
14844 entry)
14845 (if (not (or hier-alist subpack-alist))
14846 (speedbar-change-expand-button-char ??)
14847 (speedbar-change-expand-button-char ?-)
14848 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14849 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14850 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14851 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14852 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14853 (speedbar-with-writable
14854 (save-excursion
14855 (end-of-line) (forward-char 1)
14856 ;; insert instance hierarchy
14857 (when hier-alist
14858 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14859 (1+ indent)))
14860 (while hier-alist
14861 (setq entry (car hier-alist))
14862 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14863 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14864 (vhdl-speedbar-make-inst-line
14865 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14866 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14867 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14868 (setq hier-alist (cdr hier-alist)))
14869 ;; insert required packages
14870 (vhdl-speedbar-insert-subpackages
14871 subpack-alist (1+ indent) (1- indent))))
14872 (when (memq 'display vhdl-speedbar-save-cache)
14873 (add-to-list 'vhdl-updated-project-list key))
14874 (vhdl-speedbar-update-current-unit t t))))
14875 ((string-match "-" text) ; contract architecture
14876 (speedbar-change-expand-button-char ?+)
14877 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14878 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14879 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14880 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14881 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14882 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14883 (speedbar-delete-subblock indent)
14884 (when (memq 'display vhdl-speedbar-save-cache)
14885 (add-to-list 'vhdl-updated-project-list key))))
14886 (t (error "Nothing to display")))
14887 (when (equal (selected-frame) speedbar-frame)
14888 (speedbar-center-buffer-smartly)))
14890 (defun vhdl-speedbar-expand-config (text token indent)
14891 "Expand/contract the configuration under the cursor."
14892 (cond
14893 ((string-match "+" text) ; expand configuration
14894 (let* ((key (vhdl-speedbar-line-key indent))
14895 (conf-alist (aget vhdl-config-alist key t))
14896 (conf-entry (aget conf-alist token))
14897 (ent-alist (aget vhdl-entity-alist key t))
14898 (hier-alist (vhdl-get-hierarchy
14899 ent-alist conf-alist (nth 3 conf-entry)
14900 (nth 4 conf-entry) token (nth 5 conf-entry)
14901 0 indent t))
14902 (subpack-alist (nth 6 conf-entry))
14903 entry)
14904 (if (not (or hier-alist subpack-alist))
14905 (speedbar-change-expand-button-char ??)
14906 (speedbar-change-expand-button-char ?-)
14907 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14908 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14909 (aput 'unit-alist token nil)
14910 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14911 (speedbar-with-writable
14912 (save-excursion
14913 (end-of-line) (forward-char 1)
14914 ;; insert instance hierarchy
14915 (when hier-alist
14916 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14917 (while hier-alist
14918 (setq entry (car hier-alist))
14919 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14920 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14921 (vhdl-speedbar-make-inst-line
14922 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14923 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14924 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14925 (setq hier-alist (cdr hier-alist)))
14926 ;; insert required packages
14927 (vhdl-speedbar-insert-subpackages
14928 subpack-alist (1+ indent) indent)))
14929 (when (memq 'display vhdl-speedbar-save-cache)
14930 (add-to-list 'vhdl-updated-project-list key))
14931 (vhdl-speedbar-update-current-unit t t))))
14932 ((string-match "-" text) ; contract configuration
14933 (speedbar-change-expand-button-char ?+)
14934 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14935 (let* ((key (vhdl-speedbar-line-key indent))
14936 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14937 (adelete 'unit-alist token)
14938 (if unit-alist
14939 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14940 (adelete 'vhdl-speedbar-shown-unit-alist key))
14941 (speedbar-delete-subblock indent)
14942 (when (memq 'display vhdl-speedbar-save-cache)
14943 (add-to-list 'vhdl-updated-project-list key))))
14944 (t (error "Nothing to display")))
14945 (when (equal (selected-frame) speedbar-frame)
14946 (speedbar-center-buffer-smartly)))
14948 (defun vhdl-speedbar-expand-package (text token indent)
14949 "Expand/contract the package under the cursor."
14950 (cond
14951 ((string-match "+" text) ; expand package
14952 (let* ((key (vhdl-speedbar-line-key indent))
14953 (pack-alist (aget vhdl-package-alist key t))
14954 (pack-entry (aget pack-alist token t))
14955 (comp-alist (nth 3 pack-entry))
14956 (func-alist (nth 4 pack-entry))
14957 (func-body-alist (nth 8 pack-entry))
14958 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14959 comp-entry func-entry func-body-entry)
14960 (if (not (or comp-alist func-alist subpack-alist))
14961 (speedbar-change-expand-button-char ??)
14962 (speedbar-change-expand-button-char ?-)
14963 ;; add package to `vhdl-speedbar-shown-unit-alist'
14964 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14965 (aput 'unit-alist token nil)
14966 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14967 (speedbar-with-writable
14968 (save-excursion
14969 (end-of-line) (forward-char 1)
14970 ;; insert components
14971 (when comp-alist
14972 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14973 (while comp-alist
14974 (setq comp-entry (car comp-alist))
14975 (speedbar-make-tag-line
14976 nil nil nil
14977 (cons token (nth 0 comp-entry))
14978 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14979 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14980 'vhdl-speedbar-entity-face (1+ indent))
14981 (setq comp-alist (cdr comp-alist)))
14982 ;; insert subprograms
14983 (when func-alist
14984 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14985 (while func-alist
14986 (setq func-entry (car func-alist)
14987 func-body-entry (aget func-body-alist (car func-entry) t))
14988 (when (nth 2 func-entry)
14989 (vhdl-speedbar-make-subprogram-line
14990 (nth 1 func-entry)
14991 (cons (nth 2 func-entry) (nth 3 func-entry))
14992 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14993 (1+ indent)))
14994 (setq func-alist (cdr func-alist)))
14995 ;; insert required packages
14996 (vhdl-speedbar-insert-subpackages
14997 subpack-alist (1+ indent) indent)))
14998 (when (memq 'display vhdl-speedbar-save-cache)
14999 (add-to-list 'vhdl-updated-project-list key))
15000 (vhdl-speedbar-update-current-unit t t))))
15001 ((string-match "-" text) ; contract package
15002 (speedbar-change-expand-button-char ?+)
15003 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15004 (let* ((key (vhdl-speedbar-line-key indent))
15005 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
15006 (adelete 'unit-alist token)
15007 (if unit-alist
15008 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15009 (adelete 'vhdl-speedbar-shown-unit-alist key))
15010 (speedbar-delete-subblock indent)
15011 (when (memq 'display vhdl-speedbar-save-cache)
15012 (add-to-list 'vhdl-updated-project-list key))))
15013 (t (error "Nothing to display")))
15014 (when (equal (selected-frame) speedbar-frame)
15015 (speedbar-center-buffer-smartly)))
15017 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15018 "Insert required packages."
15019 (let* ((pack-alist (aget vhdl-package-alist
15020 (vhdl-speedbar-line-key dir-indent) t))
15021 pack-key lib-name pack-entry)
15022 (when subpack-alist
15023 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15024 (while subpack-alist
15025 (setq pack-key (cdar subpack-alist)
15026 lib-name (caar subpack-alist))
15027 (setq pack-entry (aget pack-alist pack-key t))
15028 (vhdl-speedbar-make-subpack-line
15029 (or (nth 0 pack-entry) pack-key) lib-name
15030 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15031 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15032 (setq subpack-alist (cdr subpack-alist)))))
15034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15035 ;; Display help functions
15037 (defvar vhdl-speedbar-update-current-unit t
15038 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15040 (defun vhdl-speedbar-update-current-project ()
15041 "Highlight project that is currently active."
15042 (when (and vhdl-speedbar-show-projects
15043 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15044 (and (boundp 'speedbar-frame)
15045 (frame-live-p speedbar-frame)))
15046 (let ((last-frame (selected-frame))
15047 (project-alist vhdl-project-alist)
15048 pos)
15049 (select-frame speedbar-frame)
15050 (speedbar-with-writable
15051 (save-excursion
15052 (while project-alist
15053 (goto-char (point-min))
15054 (when (re-search-forward
15055 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15056 (put-text-property (match-beginning 1) (match-end 1) 'face
15057 (if (equal (caar project-alist) vhdl-project)
15058 'speedbar-selected-face
15059 'speedbar-directory-face))
15060 (when (equal (caar project-alist) vhdl-project)
15061 (setq pos (1- (match-beginning 1)))))
15062 (setq project-alist (cdr project-alist))))
15063 (when pos (goto-char pos)))
15064 (select-frame last-frame)
15065 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15068 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15069 "Highlight all design units that are contained in the current file.
15070 NO-POSITION non-nil means do not re-position cursor."
15071 (let ((last-frame (selected-frame))
15072 (project-list vhdl-speedbar-shown-project-list)
15073 file-alist pos file-name)
15074 ;; get current file name
15075 (if (fboundp 'speedbar-select-attached-frame)
15076 (speedbar-select-attached-frame)
15077 (select-frame speedbar-attached-frame))
15078 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15079 (when (and vhdl-speedbar-update-current-unit
15080 (or always (not (equal file-name speedbar-last-selected-file))))
15081 (if vhdl-speedbar-show-projects
15082 (while project-list
15083 (setq file-alist (append file-alist (aget vhdl-file-alist
15084 (car project-list) t)))
15085 (setq project-list (cdr project-list)))
15086 (setq file-alist (aget vhdl-file-alist
15087 (abbreviate-file-name default-directory) t)))
15088 (select-frame speedbar-frame)
15089 (set-buffer speedbar-buffer)
15090 (speedbar-with-writable
15091 (vhdl-prepare-search-1
15092 (save-excursion
15093 ;; unhighlight last units
15094 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
15095 (vhdl-speedbar-update-units
15096 "\\[.\\] " (nth 0 file-entry)
15097 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15098 (vhdl-speedbar-update-units
15099 "{.} " (nth 1 file-entry)
15100 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15101 (vhdl-speedbar-update-units
15102 "\\[.\\] " (nth 3 file-entry)
15103 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15104 (vhdl-speedbar-update-units
15105 "[]>] " (nth 4 file-entry)
15106 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15107 (vhdl-speedbar-update-units
15108 "\\[.\\].+(" '("body")
15109 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15110 (vhdl-speedbar-update-units
15111 "> " (nth 6 file-entry)
15112 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15113 ;; highlight current units
15114 (let* ((file-entry (aget file-alist file-name t)))
15115 (setq
15116 pos (vhdl-speedbar-update-units
15117 "\\[.\\] " (nth 0 file-entry)
15118 file-name 'vhdl-speedbar-entity-selected-face pos)
15119 pos (vhdl-speedbar-update-units
15120 "{.} " (nth 1 file-entry)
15121 file-name 'vhdl-speedbar-architecture-selected-face pos)
15122 pos (vhdl-speedbar-update-units
15123 "\\[.\\] " (nth 3 file-entry)
15124 file-name 'vhdl-speedbar-configuration-selected-face pos)
15125 pos (vhdl-speedbar-update-units
15126 "[]>] " (nth 4 file-entry)
15127 file-name 'vhdl-speedbar-package-selected-face pos)
15128 pos (vhdl-speedbar-update-units
15129 "\\[.\\].+(" '("body")
15130 file-name 'vhdl-speedbar-package-selected-face pos)
15131 pos (vhdl-speedbar-update-units
15132 "> " (nth 6 file-entry)
15133 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15134 ;; move speedbar so the first highlighted unit is visible
15135 (when (and pos (not no-position))
15136 (goto-char pos)
15137 (speedbar-center-buffer-smartly)
15138 (speedbar-position-cursor-on-line))
15139 (setq speedbar-last-selected-file file-name))
15140 (select-frame last-frame)
15143 (defun vhdl-speedbar-update-units (text unit-list file-name face
15144 &optional pos)
15145 "Help function to highlight design units."
15146 (while unit-list
15147 (goto-char (point-min))
15148 (while (re-search-forward
15149 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15150 (when (equal file-name (car (get-text-property
15151 (match-beginning 1) 'speedbar-token)))
15152 (setq pos (or pos (point-marker)))
15153 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15154 (setq unit-list (cdr unit-list)))
15155 pos)
15157 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15158 ent-name ent-file-marker
15159 arch-name arch-file-marker
15160 conf-name conf-file-marker
15161 lib-name depth offset delimiter)
15162 "Insert instantiation entry."
15163 (let ((start (point))
15164 visible-start)
15165 (insert (int-to-string depth) ":")
15166 (put-text-property start (point) 'invisible t)
15167 (setq visible-start (point))
15168 (insert-char ? (* depth speedbar-indentation-width))
15169 (while (> offset 0)
15170 (insert "|")
15171 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15172 (setq offset (1- offset)))
15173 (put-text-property visible-start (point) 'invisible nil)
15174 (setq start (point))
15175 (insert ">")
15176 (speedbar-make-button start (point) nil nil nil)
15177 (setq visible-start (point))
15178 (insert " ")
15179 (setq start (point))
15180 (if (not inst-name)
15181 (insert "(top)")
15182 (insert inst-name)
15183 (speedbar-make-button
15184 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15185 'vhdl-speedbar-find-file inst-file-marker))
15186 (insert delimiter)
15187 (when ent-name
15188 (setq start (point))
15189 (insert ent-name)
15190 (speedbar-make-button
15191 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15192 'vhdl-speedbar-find-file ent-file-marker)
15193 (when arch-name
15194 (insert " (")
15195 (setq start (point))
15196 (insert arch-name)
15197 (speedbar-make-button
15198 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15199 'vhdl-speedbar-find-file arch-file-marker)
15200 (insert ")"))
15201 (when conf-name
15202 (insert " (")
15203 (setq start (point))
15204 (insert conf-name)
15205 (speedbar-make-button
15206 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15207 'vhdl-speedbar-find-file conf-file-marker)
15208 (insert ")")))
15209 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15210 (setq start (point))
15211 (insert " (" lib-name ")")
15212 (put-text-property (+ 2 start) (1- (point)) 'face
15213 'vhdl-speedbar-library-face))
15214 (insert-char ?\n 1)
15215 (put-text-property visible-start (point) 'invisible nil)))
15217 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15218 body-file-marker depth)
15219 "Insert package entry."
15220 (let ((start (point))
15221 visible-start)
15222 (insert (int-to-string depth) ":")
15223 (put-text-property start (point) 'invisible t)
15224 (setq visible-start (point))
15225 (insert-char ? (* depth speedbar-indentation-width))
15226 (put-text-property visible-start (point) 'invisible nil)
15227 (setq start (point))
15228 (insert "[+]")
15229 (speedbar-make-button
15230 start (point) 'speedbar-button-face 'speedbar-highlight-face
15231 'vhdl-speedbar-expand-package pack-key)
15232 (setq visible-start (point))
15233 (insert-char ? 1 nil)
15234 (setq start (point))
15235 (insert pack-name)
15236 (speedbar-make-button
15237 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15238 'vhdl-speedbar-find-file pack-file-marker)
15239 (unless (car pack-file-marker)
15240 (insert "!"))
15241 (when (car body-file-marker)
15242 (insert " (")
15243 (setq start (point))
15244 (insert "body")
15245 (speedbar-make-button
15246 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15247 'vhdl-speedbar-find-file body-file-marker)
15248 (insert ")"))
15249 (insert-char ?\n 1)
15250 (put-text-property visible-start (point) 'invisible nil)))
15252 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15253 pack-body-file-marker depth)
15254 "Insert used package entry."
15255 (let ((start (point))
15256 visible-start)
15257 (insert (int-to-string depth) ":")
15258 (put-text-property start (point) 'invisible t)
15259 (setq visible-start (point))
15260 (insert-char ? (* depth speedbar-indentation-width))
15261 (put-text-property visible-start (point) 'invisible nil)
15262 (setq start (point))
15263 (insert ">")
15264 (speedbar-make-button start (point) nil nil nil)
15265 (setq visible-start (point))
15266 (insert " ")
15267 (setq start (point))
15268 (insert pack-name)
15269 (speedbar-make-button
15270 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15271 'vhdl-speedbar-find-file pack-file-marker)
15272 (when (car pack-body-file-marker)
15273 (insert " (")
15274 (setq start (point))
15275 (insert "body")
15276 (speedbar-make-button
15277 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15278 'vhdl-speedbar-find-file pack-body-file-marker)
15279 (insert ")"))
15280 (setq start (point))
15281 (insert " (" lib-name ")")
15282 (put-text-property (+ 2 start) (1- (point)) 'face
15283 'vhdl-speedbar-library-face)
15284 (insert-char ?\n 1)
15285 (put-text-property visible-start (point) 'invisible nil)))
15287 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15288 func-body-file-marker
15289 depth)
15290 "Insert subprogram entry."
15291 (let ((start (point))
15292 visible-start)
15293 (insert (int-to-string depth) ":")
15294 (put-text-property start (point) 'invisible t)
15295 (setq visible-start (point))
15296 (insert-char ? (* depth speedbar-indentation-width))
15297 (put-text-property visible-start (point) 'invisible nil)
15298 (setq start (point))
15299 (insert ">")
15300 (speedbar-make-button start (point) nil nil nil)
15301 (setq visible-start (point))
15302 (insert " ")
15303 (setq start (point))
15304 (insert func-name)
15305 (speedbar-make-button
15306 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15307 'vhdl-speedbar-find-file func-file-marker)
15308 (when (car func-body-file-marker)
15309 (insert " (")
15310 (setq start (point))
15311 (insert "body")
15312 (speedbar-make-button
15313 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15314 'vhdl-speedbar-find-file func-body-file-marker)
15315 (insert ")"))
15316 (insert-char ?\n 1)
15317 (put-text-property visible-start (point) 'invisible nil)))
15319 (defun vhdl-speedbar-make-title-line (text &optional depth)
15320 "Insert design unit title entry."
15321 (let ((start (point))
15322 visible-start)
15323 (when depth
15324 (insert (int-to-string depth) ":")
15325 (put-text-property start (point) 'invisible t))
15326 (setq visible-start (point))
15327 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15328 (setq start (point))
15329 (insert text)
15330 (speedbar-make-button start (point) nil nil nil nil)
15331 (insert-char ?\n 1)
15332 (put-text-property visible-start (point) 'invisible nil)))
15334 (defun vhdl-speedbar-insert-dirs (files level)
15335 "Insert subdirectories."
15336 (let ((dirs (car files)))
15337 (while dirs
15338 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15339 (car dirs) 'speedbar-dir-follow nil
15340 'speedbar-directory-face level)
15341 (setq dirs (cdr dirs)))))
15343 (defun vhdl-speedbar-dired (text token indent)
15344 "Speedbar click handler for directory expand button in hierarchy mode."
15345 (cond ((string-match "+" text) ; we have to expand this dir
15346 (setq speedbar-shown-directories
15347 (cons (expand-file-name
15348 (concat (speedbar-line-directory indent) token "/"))
15349 speedbar-shown-directories))
15350 (speedbar-change-expand-button-char ?-)
15351 (speedbar-reset-scanners)
15352 (speedbar-with-writable
15353 (save-excursion
15354 (end-of-line) (forward-char 1)
15355 (vhdl-speedbar-insert-dirs
15356 (speedbar-file-lists
15357 (concat (speedbar-line-directory indent) token "/"))
15358 (1+ indent))
15359 (speedbar-reset-scanners)
15360 (vhdl-speedbar-insert-dir-hierarchy
15361 (abbreviate-file-name
15362 (concat (speedbar-line-directory indent) token "/"))
15363 (1+ indent) speedbar-power-click)))
15364 (vhdl-speedbar-update-current-unit t t))
15365 ((string-match "-" text) ; we have to contract this node
15366 (speedbar-reset-scanners)
15367 (let ((oldl speedbar-shown-directories)
15368 (newl nil)
15369 (td (expand-file-name
15370 (concat (speedbar-line-directory indent) token))))
15371 (while oldl
15372 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15373 (setq newl (cons (car oldl) newl)))
15374 (setq oldl (cdr oldl)))
15375 (setq speedbar-shown-directories (nreverse newl)))
15376 (speedbar-change-expand-button-char ?+)
15377 (speedbar-delete-subblock indent))
15378 (t (error "Nothing to display")))
15379 (when (equal (selected-frame) speedbar-frame)
15380 (speedbar-center-buffer-smartly)))
15382 (defun vhdl-speedbar-item-info ()
15383 "Derive and display information about this line item."
15384 (save-excursion
15385 (beginning-of-line)
15386 ;; skip invisible number info
15387 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15388 (cond
15389 ;; project/directory entry
15390 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15391 (if vhdl-speedbar-show-projects
15392 (message "Project \"%s\"" (match-string-no-properties 1))
15393 (speedbar-files-item-info)))
15394 ;; design unit entry
15395 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15396 (goto-char (match-end 1))
15397 (let ((face (get-text-property (point) 'face)))
15398 (message
15399 "%s \"%s\" in \"%s\""
15400 ;; design unit kind
15401 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15402 (eq face 'vhdl-speedbar-entity-selected-face))
15403 (if (equal (match-string 2) ">") "Component" "Entity"))
15404 ((or (eq face 'vhdl-speedbar-architecture-face)
15405 (eq face 'vhdl-speedbar-architecture-selected-face))
15406 "Architecture")
15407 ((or (eq face 'vhdl-speedbar-configuration-face)
15408 (eq face 'vhdl-speedbar-configuration-selected-face))
15409 "Configuration")
15410 ((or (eq face 'vhdl-speedbar-package-face)
15411 (eq face 'vhdl-speedbar-package-selected-face))
15412 "Package")
15413 ((or (eq face 'vhdl-speedbar-instantiation-face)
15414 (eq face 'vhdl-speedbar-instantiation-selected-face))
15415 "Instantiation")
15416 ((eq face 'vhdl-speedbar-subprogram-face)
15417 "Subprogram")
15418 (t ""))
15419 ;; design unit name
15420 (buffer-substring-no-properties
15421 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15422 (match-end 1))
15423 ;; file name
15424 (file-relative-name
15425 (or (car (get-text-property (point) 'speedbar-token))
15426 "?")
15427 (vhdl-default-directory)))))
15428 (t (message "")))))
15430 (defun vhdl-speedbar-line-text ()
15431 "Calls `speedbar-line-text' and removes text properties."
15432 (let ((string (speedbar-line-text)))
15433 (set-text-properties 0 (length string) nil string)
15434 string))
15436 (defun vhdl-speedbar-higher-text ()
15437 "Get speedbar-line-text of higher level."
15438 (let (depth string)
15439 (save-excursion
15440 (beginning-of-line)
15441 (looking-at "^\\([0-9]+\\):")
15442 (setq depth (string-to-number (match-string 1)))
15443 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15444 (setq string (match-string 1))
15445 (set-text-properties 0 (length string) nil string)
15446 string))))
15448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15449 ;; Help functions
15451 (defun vhdl-speedbar-line-key (&optional indent)
15452 "Get currently displayed directory of project name."
15453 (if vhdl-speedbar-show-projects
15454 (vhdl-speedbar-line-project)
15455 (abbreviate-file-name
15456 (file-name-as-directory (speedbar-line-directory indent)))))
15458 (defun vhdl-speedbar-line-project (&optional indent)
15459 "Get currently displayed project name."
15460 (and vhdl-speedbar-show-projects
15461 (save-excursion
15462 (end-of-line)
15463 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15464 (match-string-no-properties 1))))
15466 (defun vhdl-add-modified-file ()
15467 "Add file to `vhdl-modified-file-list'."
15468 (when vhdl-file-alist
15469 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15470 nil)
15472 (defun vhdl-resolve-paths (path-list)
15473 "Resolve path wildcards in PATH-LIST."
15474 (let (path-list-1 path-list-2 path-beg path-end dir)
15475 ;; eliminate non-existent directories
15476 (while path-list
15477 (setq dir (car path-list))
15478 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15479 (if (file-directory-p (match-string 2 dir))
15480 (setq path-list-1 (cons dir path-list-1))
15481 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15482 (setq path-list (cdr path-list)))
15483 ;; resolve path wildcards
15484 (while path-list-1
15485 (setq dir (car path-list-1))
15486 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15487 (progn
15488 (setq path-beg (match-string 1 dir)
15489 path-end (match-string 5 dir))
15490 (setq path-list-1
15491 (append
15492 (mapcar
15493 (function
15494 (lambda (var) (concat path-beg var path-end)))
15495 (let ((all-list (vhdl-directory-files
15496 (match-string 2 dir) t
15497 (concat "\\<" (wildcard-to-regexp
15498 (match-string 4 dir)))))
15499 dir-list)
15500 (while all-list
15501 (when (file-directory-p (car all-list))
15502 (setq dir-list (cons (car all-list) dir-list)))
15503 (setq all-list (cdr all-list)))
15504 dir-list))
15505 (cdr path-list-1))))
15506 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15507 (when (file-directory-p (match-string 2 dir))
15508 (setq path-list-2 (cons dir path-list-2)))
15509 (setq path-list-1 (cdr path-list-1))))
15510 (nreverse path-list-2)))
15512 (defun vhdl-speedbar-goto-this-unit (directory unit)
15513 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15514 (let ((dest (point)))
15515 (if (and (if vhdl-speedbar-show-projects
15516 (progn (goto-char (point-min)) t)
15517 (speedbar-goto-this-file directory))
15518 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15519 (progn (speedbar-position-cursor-on-line)
15521 (goto-char dest)
15522 nil)))
15524 (defun vhdl-speedbar-find-file (text token indent)
15525 "When user clicks on TEXT, load file with name and position in TOKEN.
15526 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15527 is already shown in a buffer."
15528 (if (not (car token))
15529 (error "ERROR: File cannot be found")
15530 (let ((buffer (get-file-buffer (car token))))
15531 (speedbar-find-file-in-frame (car token))
15532 (when (or vhdl-speedbar-jump-to-unit buffer)
15533 (goto-char (point-min))
15534 (forward-line (1- (cdr token)))
15535 (recenter))
15536 (vhdl-speedbar-update-current-unit t t)
15537 (speedbar-set-timer dframe-update-speed)
15538 (speedbar-maybee-jump-to-attached-frame))))
15540 (defun vhdl-speedbar-port-copy ()
15541 "Copy the port of the entity/component or subprogram under the cursor."
15542 (interactive)
15543 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15544 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15545 (error "ERROR: No entity/component or subprogram under cursor")
15546 (beginning-of-line)
15547 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15548 (condition-case info
15549 (let ((token (get-text-property
15550 (match-beginning 3) 'speedbar-token)))
15551 (vhdl-visit-file (car token) t
15552 (progn (goto-char (point-min))
15553 (forward-line (1- (cdr token)))
15554 (end-of-line)
15555 (if is-entity
15556 (vhdl-port-copy)
15557 (vhdl-subprog-copy)))))
15558 (error (error "ERROR: %s not scanned successfully\n (%s)"
15559 (if is-entity "Port" "Interface") (cadr info))))
15560 (error "ERROR: No entity/component or subprogram on current line")))))
15562 (defun vhdl-speedbar-place-component ()
15563 "Place the entity/component under the cursor as component."
15564 (interactive)
15565 (if (not (vhdl-speedbar-check-unit 'entity))
15566 (error "ERROR: No entity/component under cursor")
15567 (vhdl-speedbar-port-copy)
15568 (if (fboundp 'speedbar-select-attached-frame)
15569 (speedbar-select-attached-frame)
15570 (select-frame speedbar-attached-frame))
15571 (vhdl-compose-place-component)
15572 (select-frame speedbar-frame)))
15574 (defun vhdl-speedbar-configuration ()
15575 "Generate configuration for the architecture under the cursor."
15576 (interactive)
15577 (if (not (vhdl-speedbar-check-unit 'architecture))
15578 (error "ERROR: No architecture under cursor")
15579 (let ((arch-name (vhdl-speedbar-line-text))
15580 (ent-name (vhdl-speedbar-higher-text)))
15581 (if (fboundp 'speedbar-select-attached-frame)
15582 (speedbar-select-attached-frame)
15583 (select-frame speedbar-attached-frame))
15584 (vhdl-compose-configuration ent-name arch-name))))
15586 (defun vhdl-speedbar-select-mra ()
15587 "Select the architecture under the cursor as MRA."
15588 (interactive)
15589 (if (not (vhdl-speedbar-check-unit 'architecture))
15590 (error "ERROR: No architecture under cursor")
15591 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15592 (ent-key (downcase (vhdl-speedbar-higher-text)))
15593 (ent-alist (aget vhdl-entity-alist
15594 (or (vhdl-project-p) default-directory) t))
15595 (ent-entry (aget ent-alist ent-key t)))
15596 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15597 (speedbar-refresh))))
15599 (defun vhdl-speedbar-make-design ()
15600 "Make (compile) design unit or directory/project under the cursor."
15601 (interactive)
15602 (if (not (save-excursion (beginning-of-line)
15603 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15604 (error "ERROR: No primary design unit or directory/project under cursor")
15605 (let ((is-unit (match-string 2))
15606 (unit-name (vhdl-speedbar-line-text))
15607 (vhdl-project (vhdl-speedbar-line-project))
15608 (directory (file-name-as-directory
15609 (or (speedbar-line-file) (speedbar-line-directory)))))
15610 (if (fboundp 'speedbar-select-attached-frame)
15611 (speedbar-select-attached-frame)
15612 (select-frame speedbar-attached-frame))
15613 (let ((default-directory directory))
15614 (vhdl-make (and is-unit unit-name))))))
15616 (defun vhdl-speedbar-generate-makefile ()
15617 "Generate Makefile for directory/project under the cursor."
15618 (interactive)
15619 (let ((vhdl-project (vhdl-speedbar-line-project))
15620 (default-directory (file-name-as-directory
15621 (or (speedbar-line-file) (speedbar-line-directory)))))
15622 (vhdl-generate-makefile)))
15624 (defun vhdl-speedbar-check-unit (design-unit)
15625 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15626 expansion function)."
15627 (save-excursion
15628 (speedbar-position-cursor-on-line)
15629 (cond ((eq design-unit 'entity)
15630 (memq (get-text-property (match-end 0) 'face)
15631 '(vhdl-speedbar-entity-face
15632 vhdl-speedbar-entity-selected-face)))
15633 ((eq design-unit 'architecture)
15634 (memq (get-text-property (match-end 0) 'face)
15635 '(vhdl-speedbar-architecture-face
15636 vhdl-speedbar-architecture-selected-face)))
15637 ((eq design-unit 'subprogram)
15638 (eq (get-text-property (match-end 0) 'face)
15639 'vhdl-speedbar-subprogram-face))
15640 (t nil))))
15642 (defun vhdl-speedbar-set-depth (depth)
15643 "Set hierarchy display depth to DEPTH and refresh speedbar."
15644 (setq vhdl-speedbar-hierarchy-depth depth)
15645 (speedbar-refresh))
15647 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15648 ;; Fontification
15650 (defface vhdl-speedbar-entity-face
15651 '((((class color) (background light)) (:foreground "ForestGreen"))
15652 (((class color) (background dark)) (:foreground "PaleGreen")))
15653 "Face used for displaying entity names."
15654 :group 'speedbar-faces)
15656 (defface vhdl-speedbar-architecture-face
15657 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15658 (((class color) (background light)) (:foreground "Blue"))
15660 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15661 "Face used for displaying architecture names."
15662 :group 'speedbar-faces)
15664 (defface vhdl-speedbar-configuration-face
15665 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15666 (((class color) (background dark)) (:foreground "Salmon")))
15667 "Face used for displaying configuration names."
15668 :group 'speedbar-faces)
15670 (defface vhdl-speedbar-package-face
15671 '((((class color) (background light)) (:foreground "Grey50"))
15672 (((class color) (background dark)) (:foreground "Grey80")))
15673 "Face used for displaying package names."
15674 :group 'speedbar-faces)
15676 (defface vhdl-speedbar-library-face
15677 '((((class color) (background light)) (:foreground "Purple"))
15678 (((class color) (background dark)) (:foreground "Orchid1")))
15679 "Face used for displaying library names."
15680 :group 'speedbar-faces)
15682 (defface vhdl-speedbar-instantiation-face
15683 '((((class color) (background light)) (:foreground "Brown"))
15684 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15685 (((class color) (background dark)) (:foreground "Yellow")))
15686 "Face used for displaying instantiation names."
15687 :group 'speedbar-faces)
15689 (defface vhdl-speedbar-subprogram-face
15690 '((((class color) (background light)) (:foreground "Orchid4"))
15691 (((class color) (background dark)) (:foreground "BurlyWood2")))
15692 "Face used for displaying subprogram names."
15693 :group 'speedbar-faces)
15695 (defface vhdl-speedbar-entity-selected-face
15696 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15697 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15698 "Face used for displaying entity names."
15699 :group 'speedbar-faces)
15701 (defface vhdl-speedbar-architecture-selected-face
15702 '((((min-colors 88) (class color) (background light)) (:foreground
15703 "Blue1" :underline t))
15704 (((class color) (background light)) (:foreground "Blue" :underline t))
15705 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15706 "Face used for displaying architecture names."
15707 :group 'speedbar-faces)
15709 (defface vhdl-speedbar-configuration-selected-face
15710 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15711 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15712 "Face used for displaying configuration names."
15713 :group 'speedbar-faces)
15715 (defface vhdl-speedbar-package-selected-face
15716 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15717 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15718 "Face used for displaying package names."
15719 :group 'speedbar-faces)
15721 (defface vhdl-speedbar-instantiation-selected-face
15722 '((((class color) (background light)) (:foreground "Brown" :underline t))
15723 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15724 "Face used for displaying instantiation names."
15725 :group 'speedbar-faces)
15727 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15728 ;; Initialization
15730 ;; add speedbar
15731 (when (fboundp 'speedbar)
15732 (condition-case ()
15733 (when (and vhdl-speedbar-auto-open
15734 (not (and (boundp 'speedbar-frame)
15735 (frame-live-p speedbar-frame))))
15736 (speedbar-frame-mode 1)
15737 (if (fboundp 'speedbar-select-attached-frame)
15738 (speedbar-select-attached-frame)
15739 (select-frame speedbar-attached-frame)))
15740 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15742 ;; initialize speedbar
15743 (if (not (boundp 'speedbar-frame))
15744 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15745 (vhdl-speedbar-initialize)
15746 (when speedbar-frame (vhdl-speedbar-refresh)))
15749 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15750 ;;; Structural composition
15751 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15753 (defun vhdl-get-components-package-name ()
15754 "Return the name of the components package."
15755 (let ((project (vhdl-project-p)))
15756 (if project
15757 (vhdl-replace-string (car vhdl-components-package-name)
15758 (subst-char-in-string ? ?_ project))
15759 (cdr vhdl-components-package-name))))
15761 (defun vhdl-compose-new-component ()
15762 "Create entity and architecture for new component."
15763 (interactive)
15764 (let* ((case-fold-search t)
15765 (ent-name (read-from-minibuffer "entity name: "
15766 nil vhdl-minibuffer-local-map))
15767 (arch-name
15768 (if (equal (cdr vhdl-compose-architecture-name) "")
15769 (read-from-minibuffer "architecture name: "
15770 nil vhdl-minibuffer-local-map)
15771 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15772 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
15773 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15774 ;; open entity file
15775 (unless (eq vhdl-compose-create-files 'none)
15776 (setq ent-file-name
15777 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15778 "." (file-name-extension (buffer-file-name))))
15779 (when (and (file-exists-p ent-file-name)
15780 (not (y-or-n-p (concat "File \"" ent-file-name
15781 "\" exists; overwrite? "))))
15782 (error "ERROR: Creating component...aborted"))
15783 (find-file ent-file-name)
15784 (erase-buffer)
15785 (set-buffer-modified-p nil))
15786 ;; insert header
15787 (if vhdl-compose-include-header
15788 (progn (vhdl-template-header)
15789 (setq end-pos (point))
15790 (goto-char (point-max)))
15791 (vhdl-comment-display-line) (insert "\n\n"))
15792 ;; insert library clause
15793 (vhdl-template-package-std-logic-1164)
15794 (when vhdl-use-components-package
15795 (insert "\n")
15796 (vhdl-template-standard-package (vhdl-work-library)
15797 (vhdl-get-components-package-name)))
15798 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15799 ;; insert entity declaration
15800 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15801 (vhdl-insert-keyword " IS\n")
15802 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15803 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15804 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15805 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15806 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15807 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15808 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15809 (vhdl-insert-keyword "END ")
15810 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15811 (insert ent-name ";\n\n")
15812 (vhdl-comment-display-line) (insert "\n")
15813 ;; open architecture file
15814 (if (not (eq vhdl-compose-create-files 'separate))
15815 (insert "\n")
15816 (goto-char (or end-pos (point-min)))
15817 (setq ent-buffer (current-buffer))
15818 (setq arch-file-name
15819 (concat (vhdl-replace-string vhdl-architecture-file-name
15820 (concat ent-name " " arch-name) t)
15821 "." (file-name-extension (buffer-file-name))))
15822 (when (and (file-exists-p arch-file-name)
15823 (not (y-or-n-p (concat "File \"" arch-file-name
15824 "\" exists; overwrite? "))))
15825 (error "ERROR: Creating component...aborted"))
15826 (find-file arch-file-name)
15827 (erase-buffer)
15828 (set-buffer-modified-p nil)
15829 ;; insert header
15830 (if vhdl-compose-include-header
15831 (progn (vhdl-template-header)
15832 (goto-char (point-max)))
15833 (vhdl-comment-display-line) (insert "\n\n")))
15834 ;; insert architecture body
15835 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15836 (vhdl-insert-keyword " OF ") (insert ent-name)
15837 (vhdl-insert-keyword " IS\n\n")
15838 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15839 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15840 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15841 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15842 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15843 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15844 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15845 (vhdl-insert-keyword "BEGIN")
15846 (when vhdl-self-insert-comments
15847 (insert " -- ")
15848 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15849 (insert arch-name))
15850 (insert "\n\n")
15851 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15852 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15853 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15854 (vhdl-insert-keyword "END ")
15855 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15856 (insert arch-name ";\n\n")
15857 ;; insert footer and save
15858 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15859 (vhdl-template-footer)
15860 (vhdl-comment-display-line) (insert "\n"))
15861 (goto-char (or end-pos (point-min)))
15862 (setq arch-buffer (current-buffer))
15863 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15864 (set-buffer arch-buffer) (save-buffer)
15865 (message "%s"
15866 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15867 (and ent-file-name
15868 (format "\n File created: \"%s\"" ent-file-name))
15869 (and arch-file-name
15870 (format "\n File created: \"%s\"" arch-file-name))))))
15872 (defun vhdl-compose-place-component ()
15873 "Place new component by pasting current port as component declaration and
15874 component instantiation."
15875 (interactive)
15876 (if (not vhdl-port-list)
15877 (error "ERROR: No port has been read")
15878 (save-excursion
15879 (vhdl-prepare-search-2
15880 (unless (or (re-search-backward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
15881 (re-search-forward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t))
15882 (error "ERROR: No architecture found"))
15883 (let* ((ent-name (match-string 1))
15884 (ent-file-name
15885 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15886 "." (file-name-extension (buffer-file-name))))
15887 (orig-buffer (current-buffer)))
15888 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15889 ;; place component declaration
15890 (unless (or vhdl-use-components-package
15891 (vhdl-use-direct-instantiation)
15892 (save-excursion
15893 (re-search-forward
15894 (concat "^\\s-*component\\s-+"
15895 (car vhdl-port-list) "\\>") nil t)))
15896 (re-search-forward "^begin\\>" nil)
15897 (beginning-of-line)
15898 (skip-chars-backward " \t\n\r\f")
15899 (insert "\n\n") (indent-to vhdl-basic-offset)
15900 (vhdl-port-paste-component t))
15901 ;; place component instantiation
15902 (re-search-forward "^end\\>" nil)
15903 (beginning-of-line)
15904 (skip-chars-backward " \t\n\r\f")
15905 (insert "\n\n") (indent-to vhdl-basic-offset)
15906 (vhdl-port-paste-instance nil t t)
15907 ;; place use clause for used packages
15908 (when (nth 3 vhdl-port-list)
15909 ;; open entity file
15910 (when (file-exists-p ent-file-name)
15911 (find-file ent-file-name))
15912 (goto-char (point-min))
15913 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
15914 (error "ERROR: Entity not found: \"%s\"" ent-name))
15915 (goto-char (match-beginning 0))
15916 (if (and (save-excursion
15917 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15918 (match-string 1))
15919 (progn (goto-char (match-end 0))
15920 (beginning-of-line 2))
15921 (insert "\n")
15922 (backward-char))
15923 (vhdl-port-paste-context-clause)
15924 (switch-to-buffer orig-buffer))
15925 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15927 (defun vhdl-compose-wire-components ()
15928 "Connect components."
15929 (interactive)
15930 (save-excursion
15931 (vhdl-prepare-search-2
15932 (unless (or (re-search-backward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
15933 (re-search-forward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t))
15934 (error "ERROR: No architecture found"))
15935 (let* ((ent-name (match-string 1))
15936 (ent-file-name
15937 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15938 "." (file-name-extension (buffer-file-name))))
15939 (arch-decl-pos (point-marker))
15940 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15941 (arch-end-pos (re-search-forward "^end\\>" nil))
15942 (pack-name (vhdl-get-components-package-name))
15943 (pack-file-name
15944 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15945 "." (file-name-extension (buffer-file-name))))
15946 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15947 port-alist generic-alist inst-alist
15948 signal-name signal-entry signal-alist local-list written-list
15949 single-in-list multi-in-list single-out-list multi-out-list
15950 constant-name constant-entry constant-alist single-list multi-list
15951 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15952 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15953 signal-beg-pos signal-pos
15954 constant-temp-pos port-temp-pos signal-temp-pos)
15955 (message "Wiring components...")
15956 ;; process all instances
15957 (goto-char arch-stat-pos)
15958 (while (re-search-forward
15959 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
15960 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
15961 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
15962 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
15963 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\)[ \t\n\r\f]*(") arch-end-pos t)
15964 (setq inst-name (match-string-no-properties 1)
15965 comp-name (match-string-no-properties 4)
15966 comp-ent-name (match-string-no-properties 12)
15967 has-generic (or (match-string 7) (match-string 17)))
15968 ;; get port ...
15969 (if comp-name
15970 ;; ... from component declaration
15971 (vhdl-visit-file
15972 (when vhdl-use-components-package pack-file-name) t
15973 (save-excursion
15974 (goto-char (point-min))
15975 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
15976 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15977 (vhdl-port-copy)))
15978 ;; ... from entity declaration (direct instantiation)
15979 (setq comp-ent-file-name
15980 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15981 "." (file-name-extension (buffer-file-name))))
15982 (vhdl-visit-file
15983 comp-ent-file-name t
15984 (save-excursion
15985 (goto-char (point-min))
15986 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
15987 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15988 (vhdl-port-copy))))
15989 (vhdl-port-flatten t)
15990 (setq generic-alist (nth 1 vhdl-port-list)
15991 port-alist (nth 2 vhdl-port-list)
15992 vhdl-port-list nil)
15993 (setq constant-alist nil
15994 signal-alist nil)
15995 (when has-generic
15996 ;; process all constants in generic map
15997 (vhdl-forward-syntactic-ws)
15998 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
15999 (setq constant-name (match-string-no-properties 3))
16000 (setq constant-entry
16001 (cons constant-name
16002 (if (match-string 1)
16003 (or (aget generic-alist (match-string 2) t)
16004 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16005 (cdar generic-alist))))
16006 (setq constant-alist (cons constant-entry constant-alist))
16007 (setq constant-name (downcase constant-name))
16008 (if (or (member constant-name single-list)
16009 (member constant-name multi-list))
16010 (progn (setq single-list (delete constant-name single-list))
16011 (add-to-list 'multi-list constant-name))
16012 (add-to-list 'single-list constant-name))
16013 (unless (match-string 1)
16014 (setq generic-alist (cdr generic-alist)))
16015 (vhdl-forward-syntactic-ws))
16016 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16017 ;; process all signals in port map
16018 (vhdl-forward-syntactic-ws)
16019 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16020 (setq signal-name (match-string-no-properties 3))
16021 (setq signal-entry (cons signal-name
16022 (if (match-string 1)
16023 (or (aget port-alist (match-string 2) t)
16024 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16025 (cdar port-alist))))
16026 (setq signal-alist (cons signal-entry signal-alist))
16027 (setq signal-name (downcase signal-name))
16028 (if (equal (upcase (nth 2 signal-entry)) "IN")
16029 ;; input signal
16030 (cond
16031 ((member signal-name local-list)
16032 nil)
16033 ((or (member signal-name single-out-list)
16034 (member signal-name multi-out-list))
16035 (setq single-out-list (delete signal-name single-out-list))
16036 (setq multi-out-list (delete signal-name multi-out-list))
16037 (add-to-list 'local-list signal-name))
16038 ((member signal-name single-in-list)
16039 (setq single-in-list (delete signal-name single-in-list))
16040 (add-to-list 'multi-in-list signal-name))
16041 ((not (member signal-name multi-in-list))
16042 (add-to-list 'single-in-list signal-name)))
16043 ;; output signal
16044 (cond
16045 ((member signal-name local-list)
16046 nil)
16047 ((or (member signal-name single-in-list)
16048 (member signal-name multi-in-list))
16049 (setq single-in-list (delete signal-name single-in-list))
16050 (setq multi-in-list (delete signal-name multi-in-list))
16051 (add-to-list 'local-list signal-name))
16052 ((member signal-name single-out-list)
16053 (setq single-out-list (delete signal-name single-out-list))
16054 (add-to-list 'multi-out-list signal-name))
16055 ((not (member signal-name multi-out-list))
16056 (add-to-list 'single-out-list signal-name))))
16057 (unless (match-string 1)
16058 (setq port-alist (cdr port-alist)))
16059 (vhdl-forward-syntactic-ws))
16060 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
16061 (nreverse signal-alist)) inst-alist)))
16062 ;; prepare signal insertion
16063 (vhdl-goto-marker arch-decl-pos)
16064 (forward-line 1)
16065 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16066 (setq signal-pos (point-marker))
16067 (while (progn (vhdl-forward-syntactic-ws)
16068 (looking-at "signal\\>"))
16069 (beginning-of-line 2)
16070 (delete-region signal-pos (point)))
16071 (setq signal-beg-pos signal-pos)
16072 ;; open entity file
16073 (when (file-exists-p ent-file-name)
16074 (find-file ent-file-name))
16075 (goto-char (point-min))
16076 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16077 (error "ERROR: Entity not found: \"%s\"" ent-name))
16078 ;; prepare generic clause insertion
16079 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16080 (match-string 1))
16081 (goto-char (match-beginning 0))
16082 (indent-to vhdl-basic-offset)
16083 (insert "generic ();\n\n")
16084 (backward-char 4))
16085 (backward-char)
16086 (setq generic-pos (point-marker))
16087 (forward-sexp) (end-of-line)
16088 (delete-region generic-pos (point)) (delete-char 1)
16089 (insert "(\n")
16090 (when multi-list
16091 (insert "\n")
16092 (indent-to (* 2 vhdl-basic-offset))
16093 (insert "-- global generics\n"))
16094 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16095 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16096 ;; prepare port clause insertion
16097 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16098 (match-string 1))
16099 (goto-char (match-beginning 0))
16100 (indent-to vhdl-basic-offset)
16101 (insert "port ();\n\n")
16102 (backward-char 4))
16103 (backward-char)
16104 (setq port-in-pos (point-marker))
16105 (forward-sexp) (end-of-line)
16106 (delete-region port-in-pos (point)) (delete-char 1)
16107 (insert "(\n")
16108 (when (or multi-in-list multi-out-list)
16109 (insert "\n")
16110 (indent-to (* 2 vhdl-basic-offset))
16111 (insert "-- global ports\n"))
16112 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16113 port-out-pos (point-marker) port-inst-pos (point-marker)
16114 port-end-pos (point-marker))
16115 ;; insert generics, ports and signals
16116 (setq inst-alist (nreverse inst-alist))
16117 (while inst-alist
16118 (setq inst-name (nth 0 (car inst-alist))
16119 constant-alist (nth 1 (car inst-alist))
16120 signal-alist (nth 2 (car inst-alist))
16121 constant-temp-pos generic-inst-pos
16122 port-temp-pos port-inst-pos
16123 signal-temp-pos signal-pos)
16124 ;; generics
16125 (while constant-alist
16126 (setq constant-name (downcase (caar constant-alist))
16127 constant-entry (car constant-alist))
16128 (cond ((member constant-name written-list)
16129 nil)
16130 ((member constant-name multi-list)
16131 (vhdl-goto-marker generic-pos)
16132 (setq generic-end-pos
16133 (vhdl-max-marker
16134 generic-end-pos
16135 (vhdl-compose-insert-generic constant-entry)))
16136 (setq generic-pos (point-marker))
16137 (add-to-list 'written-list constant-name))
16139 (vhdl-goto-marker
16140 (vhdl-max-marker generic-inst-pos generic-pos))
16141 (setq generic-end-pos
16142 (vhdl-compose-insert-generic constant-entry))
16143 (setq generic-inst-pos (point-marker))
16144 (add-to-list 'written-list constant-name)))
16145 (setq constant-alist (cdr constant-alist)))
16146 (when (/= constant-temp-pos generic-inst-pos)
16147 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16148 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16149 (insert "-- generics for \"" inst-name "\"\n")
16150 (vhdl-goto-marker generic-inst-pos))
16151 ;; ports and signals
16152 (while signal-alist
16153 (setq signal-name (downcase (caar signal-alist))
16154 signal-entry (car signal-alist))
16155 (cond ((member signal-name written-list)
16156 nil)
16157 ((member signal-name multi-in-list)
16158 (vhdl-goto-marker port-in-pos)
16159 (setq port-end-pos
16160 (vhdl-max-marker
16161 port-end-pos (vhdl-compose-insert-port signal-entry)))
16162 (setq port-in-pos (point-marker))
16163 (add-to-list 'written-list signal-name))
16164 ((member signal-name multi-out-list)
16165 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16166 (setq port-end-pos
16167 (vhdl-max-marker
16168 port-end-pos (vhdl-compose-insert-port signal-entry)))
16169 (setq port-out-pos (point-marker))
16170 (add-to-list 'written-list signal-name))
16171 ((or (member signal-name single-in-list)
16172 (member signal-name single-out-list))
16173 (vhdl-goto-marker
16174 (vhdl-max-marker
16175 port-inst-pos
16176 (vhdl-max-marker port-out-pos port-in-pos)))
16177 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16178 (setq port-inst-pos (point-marker))
16179 (add-to-list 'written-list signal-name))
16180 ((equal (upcase (nth 2 signal-entry)) "OUT")
16181 (vhdl-goto-marker signal-pos)
16182 (vhdl-compose-insert-signal signal-entry)
16183 (setq signal-pos (point-marker))
16184 (add-to-list 'written-list signal-name)))
16185 (setq signal-alist (cdr signal-alist)))
16186 (when (/= port-temp-pos port-inst-pos)
16187 (vhdl-goto-marker
16188 (vhdl-max-marker port-temp-pos
16189 (vhdl-max-marker port-in-pos port-out-pos)))
16190 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16191 (insert "-- ports to \"" inst-name "\"\n")
16192 (vhdl-goto-marker port-inst-pos))
16193 (when (/= signal-temp-pos signal-pos)
16194 (vhdl-goto-marker signal-temp-pos)
16195 (insert "\n") (indent-to vhdl-basic-offset)
16196 (insert "-- outputs of \"" inst-name "\"\n")
16197 (vhdl-goto-marker signal-pos))
16198 (setq inst-alist (cdr inst-alist)))
16199 ;; finalize generic/port clause
16200 (vhdl-goto-marker generic-end-pos) (backward-char)
16201 (when (= generic-beg-pos generic-end-pos)
16202 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16203 (insert ";") (backward-char))
16204 (insert ")")
16205 (vhdl-goto-marker port-end-pos) (backward-char)
16206 (when (= port-beg-pos port-end-pos)
16207 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16208 (insert ";") (backward-char))
16209 (insert ")")
16210 ;; align everything
16211 (when vhdl-auto-align
16212 (vhdl-goto-marker generic-beg-pos)
16213 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16214 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16215 (vhdl-goto-marker signal-beg-pos)
16216 (vhdl-align-region-groups signal-beg-pos signal-pos))
16217 (switch-to-buffer (marker-buffer signal-beg-pos))
16218 (message "Wiring components...done")))))
16220 (defun vhdl-compose-insert-generic (entry)
16221 "Insert ENTRY as generic declaration."
16222 (let (pos)
16223 (indent-to (* 2 vhdl-basic-offset))
16224 (insert (nth 0 entry) " : " (nth 1 entry))
16225 (when (nth 2 entry)
16226 (insert " := " (nth 2 entry)))
16227 (insert ";")
16228 (setq pos (point-marker))
16229 (when (and vhdl-include-port-comments (nth 3 entry))
16230 (vhdl-comment-insert-inline (nth 3 entry) t))
16231 (insert "\n")
16232 pos))
16234 (defun vhdl-compose-insert-port (entry)
16235 "Insert ENTRY as port declaration."
16236 (let (pos)
16237 (indent-to (* 2 vhdl-basic-offset))
16238 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16239 (setq pos (point-marker))
16240 (when (and vhdl-include-port-comments (nth 4 entry))
16241 (vhdl-comment-insert-inline (nth 4 entry) t))
16242 (insert "\n")
16243 pos))
16245 (defun vhdl-compose-insert-signal (entry)
16246 "Insert ENTRY as signal declaration."
16247 (indent-to vhdl-basic-offset)
16248 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16249 (when (and vhdl-include-port-comments (nth 4 entry))
16250 (vhdl-comment-insert-inline (nth 4 entry) t))
16251 (insert "\n"))
16253 (defun vhdl-compose-components-package ()
16254 "Generate a package containing component declarations for all entities in the
16255 current project/directory."
16256 (interactive)
16257 (vhdl-require-hierarchy-info)
16258 (let* ((project (vhdl-project-p))
16259 (pack-name (vhdl-get-components-package-name))
16260 (pack-file-name
16261 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16262 "." (file-name-extension (buffer-file-name))))
16263 (ent-alist (aget vhdl-entity-alist
16264 (or project default-directory) t))
16265 (lazy-lock-minimum-size 0)
16266 clause-pos component-pos)
16267 (message "Generating components package \"%s\"..." pack-name)
16268 ;; open package file
16269 (when (and (file-exists-p pack-file-name)
16270 (not (y-or-n-p (concat "File \"" pack-file-name
16271 "\" exists; overwrite? "))))
16272 (error "ERROR: Generating components package...aborted"))
16273 (find-file pack-file-name)
16274 (erase-buffer)
16275 ;; insert header
16276 (if vhdl-compose-include-header
16277 (progn (vhdl-template-header
16278 (concat "Components package (generated by Emacs VHDL Mode "
16279 vhdl-version ")"))
16280 (goto-char (point-max)))
16281 (vhdl-comment-display-line) (insert "\n\n"))
16282 ;; insert std_logic_1164 package
16283 (vhdl-template-package-std-logic-1164)
16284 (insert "\n") (setq clause-pos (point-marker))
16285 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16286 ;; insert package declaration
16287 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16288 (vhdl-insert-keyword " IS\n\n")
16289 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16290 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16291 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16292 (indent-to vhdl-basic-offset)
16293 (setq component-pos (point-marker))
16294 (insert "\n\n") (vhdl-insert-keyword "END ")
16295 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16296 (insert pack-name ";\n\n")
16297 ;; insert footer
16298 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16299 (vhdl-template-footer)
16300 (vhdl-comment-display-line) (insert "\n"))
16301 ;; insert component declarations
16302 (while ent-alist
16303 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16304 (progn (goto-char (point-min))
16305 (forward-line (1- (nth 3 (car ent-alist))))
16306 (end-of-line)
16307 (vhdl-port-copy)))
16308 (goto-char component-pos)
16309 (vhdl-port-paste-component t)
16310 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16311 (setq component-pos (point-marker))
16312 (goto-char clause-pos)
16313 (vhdl-port-paste-context-clause pack-name)
16314 (setq clause-pos (point-marker))
16315 (setq ent-alist (cdr ent-alist)))
16316 (goto-char (point-min))
16317 (save-buffer)
16318 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16319 pack-name pack-file-name)))
16321 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16322 conf-alist inst-alist
16323 &optional insert-conf)
16324 "Generate block configuration for architecture."
16325 (let ((margin (current-indentation))
16326 (beg (point-at-bol))
16327 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16328 ;; insert block configuration (for architecture)
16329 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16330 (setq margin (+ margin vhdl-basic-offset))
16331 ;; process all instances
16332 (while inst-alist
16333 (setq inst-entry (car inst-alist))
16334 ;; is component?
16335 (when (nth 4 inst-entry)
16336 (setq insert-conf t)
16337 (setq inst-path (nth 9 inst-entry))
16338 ;; skip common path with previous instance
16339 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16340 (setq inst-path (cdr inst-path)
16341 inst-prev-path (cdr inst-prev-path)))
16342 ;; insert block configuration end (for previous block/generate)
16343 (while inst-prev-path
16344 (setq margin (- margin vhdl-basic-offset))
16345 (indent-to margin)
16346 (vhdl-insert-keyword "END FOR;\n")
16347 (setq inst-prev-path (cdr inst-prev-path)))
16348 ;; insert block configuration beginning (for current block/generate)
16349 (indent-to margin)
16350 (while inst-path
16351 (setq margin (+ margin vhdl-basic-offset))
16352 (vhdl-insert-keyword "FOR ")
16353 (insert (car inst-path) "\n")
16354 (indent-to margin)
16355 (setq inst-path (cdr inst-path)))
16356 ;; insert component configuration beginning
16357 (vhdl-insert-keyword "FOR ")
16358 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16359 ;; find subconfiguration
16360 (setq conf-key (nth 7 inst-entry))
16361 (setq tmp-alist conf-alist)
16362 ;; use first configuration found for instance's entity
16363 (while (and tmp-alist (null conf-key))
16364 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16365 (setq conf-key (nth 0 (car tmp-alist))))
16366 (setq tmp-alist (cdr tmp-alist)))
16367 (setq conf-entry (aget conf-alist conf-key t))
16368 ;; insert binding indication ...
16369 ;; ... with subconfiguration (if exists)
16370 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16371 (progn
16372 (indent-to (+ margin vhdl-basic-offset))
16373 (vhdl-insert-keyword "USE CONFIGURATION ")
16374 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16375 (insert ";\n"))
16376 ;; ... with entity (if exists)
16377 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16378 (when ent-entry
16379 (indent-to (+ margin vhdl-basic-offset))
16380 (vhdl-insert-keyword "USE ENTITY ")
16381 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16382 ;; insert architecture name (if architecture exists)
16383 (when (nth 3 ent-entry)
16384 (setq arch-name
16385 ;; choose architecture name a) from configuration,
16386 ;; b) from mra, or c) from first architecture
16387 (or (nth 0 (aget (nth 3 ent-entry)
16388 (or (nth 6 inst-entry)
16389 (nth 4 ent-entry)) t))
16390 (nth 1 (car (nth 3 ent-entry)))))
16391 (insert "(" arch-name ")"))
16392 (insert ";\n")
16393 ;; insert block configuration (for architecture of subcomponent)
16394 (when (and vhdl-compose-configuration-hierarchical
16395 (nth 3 ent-entry))
16396 (indent-to (+ margin vhdl-basic-offset))
16397 (vhdl-compose-configuration-architecture
16398 (nth 0 ent-entry) arch-name ent-alist conf-alist
16399 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16400 ;; insert component configuration end
16401 (indent-to margin)
16402 (vhdl-insert-keyword "END FOR;\n")
16403 (setq inst-prev-path (nth 9 inst-entry)))
16404 (setq inst-alist (cdr inst-alist)))
16405 ;; insert block configuration end (for block/generate)
16406 (while inst-prev-path
16407 (setq margin (- margin vhdl-basic-offset))
16408 (indent-to margin)
16409 (vhdl-insert-keyword "END FOR;\n")
16410 (setq inst-prev-path (cdr inst-prev-path)))
16411 (indent-to (- margin vhdl-basic-offset))
16412 ;; insert block configuration end or remove beginning (for architecture)
16413 (if insert-conf
16414 (vhdl-insert-keyword "END FOR;\n")
16415 (delete-region beg (point)))))
16417 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16418 "Generate configuration declaration."
16419 (interactive)
16420 (vhdl-require-hierarchy-info)
16421 (let ((ent-alist (aget vhdl-entity-alist
16422 (or (vhdl-project-p) default-directory) t))
16423 (conf-alist (aget vhdl-config-alist
16424 (or (vhdl-project-p) default-directory) t))
16425 (from-speedbar ent-name)
16426 inst-alist conf-name conf-file-name pos)
16427 (vhdl-prepare-search-2
16428 ;; get entity and architecture name
16429 (unless ent-name
16430 (save-excursion
16431 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16432 (not (equal "END" (upcase (match-string 1))))
16433 (setq ent-name (match-string-no-properties 3))
16434 (setq arch-name (match-string-no-properties 2)))
16435 (error "ERROR: Not within an architecture"))))
16436 (setq conf-name (vhdl-replace-string
16437 vhdl-compose-configuration-name
16438 (concat ent-name " " arch-name)))
16439 (setq inst-alist
16440 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16441 (downcase arch-name) t))))
16442 (message "Generating configuration \"%s\"..." conf-name)
16443 (if vhdl-compose-configuration-create-file
16444 ;; open configuration file
16445 (progn
16446 (setq conf-file-name
16447 (concat (vhdl-replace-string vhdl-configuration-file-name
16448 conf-name t)
16449 "." (file-name-extension (buffer-file-name))))
16450 (when (and (file-exists-p conf-file-name)
16451 (not (y-or-n-p (concat "File \"" conf-file-name
16452 "\" exists; overwrite? "))))
16453 (error "ERROR: Creating configuration...aborted"))
16454 (find-file conf-file-name)
16455 (erase-buffer)
16456 (set-buffer-modified-p nil)
16457 ;; insert header
16458 (if vhdl-compose-include-header
16459 (progn (vhdl-template-header
16460 (concat "Configuration declaration for design \""
16461 ent-name "(" arch-name ")\""))
16462 (goto-char (point-max)))
16463 (vhdl-comment-display-line) (insert "\n\n")))
16464 ;; goto end of architecture
16465 (unless from-speedbar
16466 (re-search-forward "^end\\>" nil)
16467 (end-of-line) (insert "\n\n")
16468 (vhdl-comment-display-line) (insert "\n\n")))
16469 ;; insert library clause
16470 (setq pos (point))
16471 (vhdl-template-standard-package (vhdl-work-library) nil)
16472 (when (/= pos (point))
16473 (insert "\n\n"))
16474 ;; insert configuration
16475 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16476 (vhdl-insert-keyword " OF ") (insert ent-name)
16477 (vhdl-insert-keyword " IS\n")
16478 (indent-to vhdl-basic-offset)
16479 ;; insert block configuration (for architecture)
16480 (vhdl-compose-configuration-architecture
16481 ent-name arch-name ent-alist conf-alist inst-alist t)
16482 (vhdl-insert-keyword "END ") (insert conf-name ";")
16483 (when conf-file-name
16484 ;; insert footer and save
16485 (insert "\n\n")
16486 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16487 (vhdl-template-footer)
16488 (vhdl-comment-display-line) (insert "\n"))
16489 (save-buffer))
16490 (message "%s"
16491 (concat (format "Generating configuration \"%s\"...done" conf-name)
16492 (and conf-file-name
16493 (format "\n File created: \"%s\"" conf-file-name))))))
16496 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16497 ;;; Compilation / Makefile generation
16498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16499 ;; (using `compile.el')
16501 (defvar vhdl-compile-post-command ""
16502 "String appended to compile command after file name.")
16504 (defun vhdl-makefile-name ()
16505 "Return the Makefile name of the current project or the current compiler if
16506 no project is defined."
16507 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16508 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16509 (vhdl-replace-string
16510 (cons "\\(.*\\)\n\\(.*\\)"
16511 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16512 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16514 (defun vhdl-compile-directory ()
16515 "Return the directory where compilation/make should be run."
16516 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16517 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16518 (directory (vhdl-resolve-env-variable
16519 (if project
16520 (vhdl-replace-string
16521 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16522 (nth 6 compiler)))))
16523 (file-name-as-directory
16524 (if (file-name-absolute-p directory)
16525 directory
16526 (expand-file-name directory (vhdl-default-directory))))))
16528 (defun vhdl-uniquify (in-list)
16529 "Remove duplicate elements from IN-LIST."
16530 (let (out-list)
16531 (while in-list
16532 (add-to-list 'out-list (car in-list))
16533 (setq in-list (cdr in-list)))
16534 out-list))
16536 (defun vhdl-set-compiler (name)
16537 "Set current compiler to NAME."
16538 (interactive
16539 (list (let ((completion-ignore-case t))
16540 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16541 (if (assoc name vhdl-compiler-alist)
16542 (progn (setq vhdl-compiler name)
16543 (message "Current compiler: \"%s\"" vhdl-compiler))
16544 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16546 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16547 ;; Compilation
16549 (defun vhdl-compile-init ()
16550 "Initialize for compilation."
16551 (when (or (null compilation-error-regexp-alist)
16552 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16553 compilation-error-regexp-alist)))
16554 ;; `compilation-error-regexp-alist'
16555 (let ((commands-alist vhdl-compiler-alist)
16556 regexp-alist sublist)
16557 (while commands-alist
16558 (setq sublist (nth 11 (car commands-alist)))
16559 (unless (or (equal "" (car sublist))
16560 (assoc (car sublist) regexp-alist))
16561 (setq regexp-alist (cons (list (nth 0 sublist)
16562 (if (= 0 (nth 1 sublist))
16563 (if (featurep 'xemacs) 9 nil)
16564 (nth 1 sublist))
16565 (nth 2 sublist) (nth 3 sublist))
16566 regexp-alist)))
16567 (setq commands-alist (cdr commands-alist)))
16568 (setq compilation-error-regexp-alist
16569 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16570 ;; `compilation-file-regexp-alist'
16571 (let ((commands-alist vhdl-compiler-alist)
16572 regexp-alist sublist)
16573 ;; matches vhdl-mode file name output
16574 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16575 (while commands-alist
16576 (setq sublist (nth 12 (car commands-alist)))
16577 (unless (or (equal "" (car sublist))
16578 (assoc (car sublist) regexp-alist))
16579 (setq regexp-alist (cons sublist regexp-alist)))
16580 (setq commands-alist (cdr commands-alist)))
16581 (setq compilation-file-regexp-alist
16582 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16584 (defvar vhdl-compile-file-name nil
16585 "Name of file to be compiled.")
16587 (defun vhdl-compile-print-file-name ()
16588 "Function called within `compile' to print out file name for compilers that
16589 do not print any file names."
16590 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16592 (defun vhdl-get-compile-options (project compiler file-name
16593 &optional file-options-only)
16594 "Get compiler options. Returning nil means do not compile this file."
16595 (let* ((compiler-options (nth 1 compiler))
16596 (project-entry (aget (nth 4 project) vhdl-compiler))
16597 (project-options (nth 0 project-entry))
16598 (exception-list (and file-name (nth 2 project-entry)))
16599 (work-library (vhdl-work-library))
16600 (case-fold-search nil)
16601 file-options)
16602 (while (and exception-list
16603 (not (string-match (caar exception-list) file-name)))
16604 (setq exception-list (cdr exception-list)))
16605 (if (and exception-list (not (cdar exception-list)))
16607 (if (and file-options-only (not exception-list))
16608 'default
16609 (setq file-options (cdar exception-list))
16610 ;; insert library name in compiler-specific options
16611 (setq compiler-options
16612 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16613 work-library))
16614 ;; insert compiler-specific options in project-specific options
16615 (when project-options
16616 (setq project-options
16617 (vhdl-replace-string
16618 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16619 (concat work-library "\n" compiler-options))))
16620 ;; insert project-specific options in file-specific options
16621 (when file-options
16622 (setq file-options
16623 (vhdl-replace-string
16624 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16625 (concat work-library "\n" compiler-options "\n"
16626 project-options))))
16627 ;; return options
16628 (or file-options project-options compiler-options)))))
16630 (defun vhdl-get-make-options (project compiler)
16631 "Get make options."
16632 (let* ((compiler-options (nth 3 compiler))
16633 (project-entry (aget (nth 4 project) vhdl-compiler))
16634 (project-options (nth 1 project-entry))
16635 (makefile-name (vhdl-makefile-name)))
16636 ;; insert Makefile name in compiler-specific options
16637 (setq compiler-options
16638 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16639 makefile-name))
16640 ;; insert compiler-specific options in project-specific options
16641 (when project-options
16642 (setq project-options
16643 (vhdl-replace-string
16644 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16645 (concat makefile-name "\n" compiler-options))))
16646 ;; return options
16647 (or project-options compiler-options)))
16649 (defun vhdl-compile ()
16650 "Compile current buffer using the VHDL compiler specified in
16651 `vhdl-compiler'."
16652 (interactive)
16653 (vhdl-compile-init)
16654 (let* ((project (aget vhdl-project-alist vhdl-project))
16655 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16656 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16657 (command (nth 0 compiler))
16658 (default-directory (vhdl-compile-directory))
16659 (file-name (if vhdl-compile-absolute-path
16660 (buffer-file-name)
16661 (file-relative-name (buffer-file-name))))
16662 (options (vhdl-get-compile-options project compiler file-name))
16663 compilation-process-setup-function)
16664 (unless (file-directory-p default-directory)
16665 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16666 ;; put file name into quotes if it contains spaces
16667 (when (string-match " " file-name)
16668 (setq file-name (concat "\"" file-name "\"")))
16669 ;; print out file name if compiler does not
16670 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
16671 (buffer-file-name)
16672 (file-relative-name (buffer-file-name))))
16673 (when (and (= 0 (nth 1 (nth 10 compiler)))
16674 (= 0 (nth 1 (nth 11 compiler))))
16675 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16676 ;; run compilation
16677 (if options
16678 (when command
16679 (compile (concat command " " options " " file-name
16680 (unless (equal vhdl-compile-post-command "")
16681 (concat " " vhdl-compile-post-command)))))
16682 (vhdl-warning "Your project settings tell me not to compile this file"))))
16684 (defvar vhdl-make-target "all"
16685 "Default target for `vhdl-make' command.")
16687 (defun vhdl-make (&optional target)
16688 "Call make command for compilation of all updated source files (requires
16689 `Makefile'). Optional argument TARGET allows to compile the design
16690 specified by a target."
16691 (interactive)
16692 (setq vhdl-make-target
16693 (or target (read-from-minibuffer "Target: " vhdl-make-target
16694 vhdl-minibuffer-local-map)))
16695 (vhdl-compile-init)
16696 (let* ((project (aget vhdl-project-alist vhdl-project))
16697 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16698 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16699 (command (nth 2 compiler))
16700 (options (vhdl-get-make-options project compiler))
16701 (default-directory (vhdl-compile-directory)))
16702 (unless (file-directory-p default-directory)
16703 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16704 ;; run make
16705 (compile (concat (if (equal command "") "make" command)
16706 " " options " " vhdl-make-target))))
16708 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16709 ;; Makefile generation
16711 (defun vhdl-generate-makefile ()
16712 "Generate `Makefile'."
16713 (interactive)
16714 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16715 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16716 (command (nth 4 compiler)))
16717 ;; generate makefile
16718 (if command
16719 (let ((default-directory (vhdl-compile-directory)))
16720 (compile (vhdl-replace-string
16721 (cons "\\(.*\\) \\(.*\\)" command)
16722 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16723 (vhdl-generate-makefile-1))))
16725 (defun vhdl-get-packages (lib-alist work-library)
16726 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16727 (let (pack-list)
16728 (while lib-alist
16729 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16730 (setq pack-list (cons (cdar lib-alist) pack-list)))
16731 (setq lib-alist (cdr lib-alist)))
16732 pack-list))
16734 (defun vhdl-generate-makefile-1 ()
16735 "Generate Makefile for current project or directory."
16736 ;; scan hierarchy if required
16737 (if (vhdl-project-p)
16738 (unless (or (assoc vhdl-project vhdl-file-alist)
16739 (vhdl-load-cache vhdl-project))
16740 (vhdl-scan-project-contents vhdl-project))
16741 (let ((directory (abbreviate-file-name default-directory)))
16742 (unless (or (assoc directory vhdl-file-alist)
16743 (vhdl-load-cache directory))
16744 (vhdl-scan-directory-contents directory))))
16745 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16746 (project (vhdl-project-p))
16747 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16748 (conf-alist (aget vhdl-config-alist (or project directory) t))
16749 (pack-alist (aget vhdl-package-alist (or project directory) t))
16750 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16751 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16752 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16753 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16754 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16755 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16756 (adjust-case (nth 5 regexp-list))
16757 (work-library (downcase (vhdl-work-library)))
16758 (compile-directory (expand-file-name (vhdl-compile-directory)
16759 default-directory))
16760 (makefile-name (vhdl-makefile-name))
16761 rule-alist arch-alist inst-alist
16762 target-list depend-list unit-list prim-list second-list subcomp-list
16763 lib-alist lib-body-alist pack-list all-pack-list
16764 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16765 conf-key conf-file-name pack-key pack-file-name
16766 ent-entry arch-entry conf-entry pack-entry inst-entry
16767 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16768 tmp-key tmp-list rule)
16769 ;; check prerequisites
16770 (unless (file-exists-p compile-directory)
16771 (make-directory compile-directory t))
16772 (unless regexp-list
16773 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16774 vhdl-compiler))
16775 (message "Generating makefile \"%s\"..." makefile-name)
16776 ;; rules for all entities
16777 (setq tmp-list ent-alist)
16778 (while ent-alist
16779 (setq ent-entry (car ent-alist)
16780 ent-key (nth 0 ent-entry))
16781 (when (nth 2 ent-entry)
16782 (setq ent-file-name (file-relative-name
16783 (nth 2 ent-entry) compile-directory)
16784 arch-alist (nth 4 ent-entry)
16785 lib-alist (nth 6 ent-entry)
16786 rule (aget rule-alist ent-file-name)
16787 target-list (nth 0 rule)
16788 depend-list (nth 1 rule)
16789 second-list nil
16790 subcomp-list nil)
16791 (setq tmp-key (vhdl-replace-string
16792 ent-regexp (funcall adjust-case ent-key)))
16793 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16794 ;; rule target for this entity
16795 (setq target-list (cons ent-key target-list))
16796 ;; rule dependencies for all used packages
16797 (setq pack-list (vhdl-get-packages lib-alist work-library))
16798 (setq depend-list (append depend-list pack-list))
16799 (setq all-pack-list pack-list)
16800 ;; add rule
16801 (aput 'rule-alist ent-file-name (list target-list depend-list))
16802 ;; rules for all corresponding architectures
16803 (while arch-alist
16804 (setq arch-entry (car arch-alist)
16805 arch-key (nth 0 arch-entry)
16806 ent-arch-key (concat ent-key "-" arch-key)
16807 arch-file-name (file-relative-name (nth 2 arch-entry)
16808 compile-directory)
16809 inst-alist (nth 4 arch-entry)
16810 lib-alist (nth 5 arch-entry)
16811 rule (aget rule-alist arch-file-name)
16812 target-list (nth 0 rule)
16813 depend-list (nth 1 rule))
16814 (setq tmp-key (vhdl-replace-string
16815 arch-regexp
16816 (funcall adjust-case (concat arch-key " " ent-key))))
16817 (setq unit-list
16818 (cons (cons ent-arch-key tmp-key) unit-list))
16819 (setq second-list (cons ent-arch-key second-list))
16820 ;; rule target for this architecture
16821 (setq target-list (cons ent-arch-key target-list))
16822 ;; rule dependency for corresponding entity
16823 (setq depend-list (cons ent-key depend-list))
16824 ;; rule dependencies for contained component instantiations
16825 (while inst-alist
16826 (setq inst-entry (car inst-alist))
16827 (when (or (null (nth 8 inst-entry))
16828 (equal (downcase (nth 8 inst-entry)) work-library))
16829 (setq inst-ent-key (or (nth 7 inst-entry)
16830 (nth 5 inst-entry)))
16831 (setq depend-list (cons inst-ent-key depend-list)
16832 subcomp-list (cons inst-ent-key subcomp-list)))
16833 (setq inst-alist (cdr inst-alist)))
16834 ;; rule dependencies for all used packages
16835 (setq pack-list (vhdl-get-packages lib-alist work-library))
16836 (setq depend-list (append depend-list pack-list))
16837 (setq all-pack-list (append all-pack-list pack-list))
16838 ;; add rule
16839 (aput 'rule-alist arch-file-name (list target-list depend-list))
16840 (setq arch-alist (cdr arch-alist)))
16841 (setq prim-list (cons (list ent-key second-list
16842 (append subcomp-list all-pack-list))
16843 prim-list)))
16844 (setq ent-alist (cdr ent-alist)))
16845 (setq ent-alist tmp-list)
16846 ;; rules for all configurations
16847 (setq tmp-list conf-alist)
16848 (while conf-alist
16849 (setq conf-entry (car conf-alist)
16850 conf-key (nth 0 conf-entry)
16851 conf-file-name (file-relative-name
16852 (nth 2 conf-entry) compile-directory)
16853 ent-key (nth 4 conf-entry)
16854 arch-key (nth 5 conf-entry)
16855 inst-alist (nth 6 conf-entry)
16856 lib-alist (nth 7 conf-entry)
16857 rule (aget rule-alist conf-file-name)
16858 target-list (nth 0 rule)
16859 depend-list (nth 1 rule)
16860 subcomp-list (list ent-key))
16861 (setq tmp-key (vhdl-replace-string
16862 conf-regexp (funcall adjust-case conf-key)))
16863 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16864 ;; rule target for this configuration
16865 (setq target-list (cons conf-key target-list))
16866 ;; rule dependency for corresponding entity and architecture
16867 (setq depend-list
16868 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16869 ;; rule dependencies for used packages
16870 (setq pack-list (vhdl-get-packages lib-alist work-library))
16871 (setq depend-list (append depend-list pack-list))
16872 ;; rule dependencies for contained component configurations
16873 (while inst-alist
16874 (setq inst-entry (car inst-alist))
16875 (setq inst-ent-key (nth 2 inst-entry)
16876 ; comp-arch-key (nth 2 inst-entry))
16877 inst-conf-key (nth 4 inst-entry))
16878 (when (equal (downcase (nth 5 inst-entry)) work-library)
16879 (when inst-ent-key
16880 (setq depend-list (cons inst-ent-key depend-list)
16881 subcomp-list (cons inst-ent-key subcomp-list)))
16882 ; (when comp-arch-key
16883 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16884 ; depend-list)))
16885 (when inst-conf-key
16886 (setq depend-list (cons inst-conf-key depend-list)
16887 subcomp-list (cons inst-conf-key subcomp-list))))
16888 (setq inst-alist (cdr inst-alist)))
16889 ;; add rule
16890 (aput 'rule-alist conf-file-name (list target-list depend-list))
16891 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16892 prim-list))
16893 (setq conf-alist (cdr conf-alist)))
16894 (setq conf-alist tmp-list)
16895 ;; rules for all packages
16896 (setq tmp-list pack-alist)
16897 (while pack-alist
16898 (setq pack-entry (car pack-alist)
16899 pack-key (nth 0 pack-entry)
16900 pack-body-key nil)
16901 (when (nth 2 pack-entry)
16902 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16903 compile-directory)
16904 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16905 rule (aget rule-alist pack-file-name)
16906 target-list (nth 0 rule) depend-list (nth 1 rule))
16907 (setq tmp-key (vhdl-replace-string
16908 pack-regexp (funcall adjust-case pack-key)))
16909 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16910 ;; rule target for this package
16911 (setq target-list (cons pack-key target-list))
16912 ;; rule dependencies for all used packages
16913 (setq pack-list (vhdl-get-packages lib-alist work-library))
16914 (setq depend-list (append depend-list pack-list))
16915 (setq all-pack-list pack-list)
16916 ;; add rule
16917 (aput 'rule-alist pack-file-name (list target-list depend-list))
16918 ;; rules for this package's body
16919 (when (nth 7 pack-entry)
16920 (setq pack-body-key (concat pack-key "-body")
16921 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16922 compile-directory)
16923 rule (aget rule-alist pack-body-file-name)
16924 target-list (nth 0 rule)
16925 depend-list (nth 1 rule))
16926 (setq tmp-key (vhdl-replace-string
16927 pack-body-regexp (funcall adjust-case pack-key)))
16928 (setq unit-list
16929 (cons (cons pack-body-key tmp-key) unit-list))
16930 ;; rule target for this package's body
16931 (setq target-list (cons pack-body-key target-list))
16932 ;; rule dependency for corresponding package declaration
16933 (setq depend-list (cons pack-key depend-list))
16934 ;; rule dependencies for all used packages
16935 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16936 (setq depend-list (append depend-list pack-list))
16937 (setq all-pack-list (append all-pack-list pack-list))
16938 ;; add rule
16939 (aput 'rule-alist pack-body-file-name
16940 (list target-list depend-list)))
16941 (setq prim-list
16942 (cons (list pack-key (when pack-body-key (list pack-body-key))
16943 all-pack-list)
16944 prim-list)))
16945 (setq pack-alist (cdr pack-alist)))
16946 (setq pack-alist tmp-list)
16947 ;; generate Makefile
16948 (let* ((project (aget vhdl-project-alist project))
16949 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16950 (compiler-id (nth 9 compiler))
16951 (library-directory
16952 (vhdl-resolve-env-variable
16953 (vhdl-replace-string
16954 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16955 compiler-id)))
16956 (makefile-path-name (expand-file-name
16957 makefile-name compile-directory))
16958 (orig-buffer (current-buffer))
16959 cell second-list subcomp-list options unit-key unit-name)
16960 ;; sort lists
16961 (setq unit-list (vhdl-sort-alist unit-list))
16962 (setq prim-list (vhdl-sort-alist prim-list))
16963 (setq tmp-list rule-alist)
16964 (while tmp-list ; pre-sort rule targets
16965 (setq cell (cdar tmp-list))
16966 (setcar cell (sort (car cell) 'string<))
16967 (setq tmp-list (cdr tmp-list)))
16968 (setq rule-alist ; sort by first rule target
16969 (sort rule-alist
16970 (function (lambda (a b)
16971 (string< (car (cadr a)) (car (cadr b)))))))
16972 ;; open and clear Makefile
16973 (set-buffer (find-file-noselect makefile-path-name t t))
16974 (erase-buffer)
16975 (insert "# -*- Makefile -*-\n"
16976 "### " (file-name-nondirectory makefile-name)
16977 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16978 "\n")
16979 (if project
16980 (insert "\n# Project : " (nth 0 project))
16981 (insert "\n# Directory : \"" directory "\""))
16982 (insert "\n# Platform : " vhdl-compiler
16983 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16984 (user-login-name) "\n")
16985 ;; insert compile and option variable settings
16986 (insert "\n\n# Define compilation command and options\n"
16987 "\nCOMPILE = " (nth 0 compiler)
16988 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16989 (if (equal vhdl-compile-post-command "") ""
16990 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
16991 "\n")
16992 ;; insert library paths
16993 (setq library-directory
16994 (directory-file-name
16995 (if (file-name-absolute-p library-directory)
16996 library-directory
16997 (file-relative-name
16998 (expand-file-name library-directory directory)
16999 compile-directory))))
17000 (insert "\n\n# Define library paths\n"
17001 "\nLIBRARY-" work-library " = " library-directory "\n")
17002 ;; insert variable definitions for all library unit files
17003 (insert "\n\n# Define library unit files\n")
17004 (setq tmp-list unit-list)
17005 (while unit-list
17006 (insert "\nUNIT-" work-library "-" (caar unit-list)
17007 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
17008 (setq unit-list (cdr unit-list)))
17009 ;; insert variable definition for list of all library unit files
17010 (insert "\n\n\n# Define list of all library unit files\n"
17011 "\nALL_UNITS =")
17012 (setq unit-list tmp-list)
17013 (while unit-list
17014 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17015 (setq unit-list (cdr unit-list)))
17016 (insert "\n")
17017 (setq unit-list tmp-list)
17018 ;; insert `make all' rule
17019 (insert "\n\n\n# Rule for compiling entire design\n"
17020 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17021 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17022 " \\\n\t\t$(ALL_UNITS)\n")
17023 ;; insert `make clean' rule
17024 (insert "\n\n# Rule for cleaning entire design\n"
17025 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17026 "\n\t-rm -f $(ALL_UNITS)\n")
17027 ;; insert `make library' rule
17028 (insert "\n\n# Rule for creating library directory\n"
17029 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17030 " \\\n\t\t$(LIBRARY-" work-library ")\n"
17031 "\n$(LIBRARY-" work-library ") :"
17032 "\n\t"
17033 (vhdl-replace-string
17034 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17035 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17036 "\n")
17037 ;; insert '.PHONY' declaration
17038 (insert "\n\n.PHONY : "
17039 (nth 0 vhdl-makefile-default-targets) " "
17040 (nth 1 vhdl-makefile-default-targets) " "
17041 (nth 2 vhdl-makefile-default-targets) "\n")
17042 ;; insert rule for each library unit
17043 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17044 (while prim-list
17045 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17046 (setq subcomp-list
17047 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17048 (setq unit-key (caar prim-list)
17049 unit-name (or (nth 0 (aget ent-alist unit-key t))
17050 (nth 0 (aget conf-alist unit-key t))
17051 (nth 0 (aget pack-alist unit-key t))))
17052 (insert "\n" unit-key)
17053 (unless (equal unit-key unit-name)
17054 (insert " \\\n" unit-name))
17055 (insert " :"
17056 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17057 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17058 (while second-list
17059 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17060 (setq second-list (cdr second-list)))
17061 (while subcomp-list
17062 (when (and (assoc (car subcomp-list) unit-list)
17063 (not (equal unit-key (car subcomp-list))))
17064 (insert " \\\n\t\t" (car subcomp-list)))
17065 (setq subcomp-list (cdr subcomp-list)))
17066 (insert "\n")
17067 (setq prim-list (cdr prim-list)))
17068 ;; insert rule for each library unit file
17069 (insert "\n\n# Rules for compiling single library unit files\n")
17070 (while rule-alist
17071 (setq rule (car rule-alist))
17072 ;; get compiler options for this file
17073 (setq options
17074 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17075 ;; insert rule if file is supposed to be compiled
17076 (setq target-list (nth 1 rule)
17077 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17078 ;; insert targets
17079 (setq tmp-list target-list)
17080 (while target-list
17081 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17082 (if (cdr target-list) " \\" " :"))
17083 (setq target-list (cdr target-list)))
17084 (setq target-list tmp-list)
17085 ;; insert file name as first dependency
17086 (insert " \\\n\t\t" (nth 0 rule))
17087 ;; insert dependencies (except if also target or unit does not exist)
17088 (while depend-list
17089 (when (and (not (member (car depend-list) target-list))
17090 (assoc (car depend-list) unit-list))
17091 (insert " \\\n\t\t"
17092 "$(UNIT-" work-library "-" (car depend-list) ")"))
17093 (setq depend-list (cdr depend-list)))
17094 ;; insert compile command
17095 (if options
17096 (insert "\n\t$(COMPILE) "
17097 (if (eq options 'default) "$(OPTIONS)" options) " "
17098 (nth 0 rule)
17099 (if (equal vhdl-compile-post-command "") ""
17100 " $(POST-COMPILE)") "\n")
17101 (setq tmp-list target-list)
17102 (while target-list
17103 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
17104 (if (cdr target-list) " \\" "\n"))
17105 (setq target-list (cdr target-list)))
17106 (setq target-list tmp-list))
17107 (setq rule-alist (cdr rule-alist)))
17108 (insert "\n\n### " makefile-name " ends here\n")
17109 ;; run Makefile generation hook
17110 (run-hooks 'vhdl-makefile-generation-hook)
17111 (message "Generating makefile \"%s\"...done" makefile-name)
17112 ;; save and close file
17113 (if (file-writable-p makefile-path-name)
17114 (progn (save-buffer)
17115 (kill-buffer (current-buffer))
17116 (set-buffer orig-buffer)
17117 (add-to-history 'file-name-history makefile-path-name))
17118 (vhdl-warning-when-idle
17119 (format "File not writable: \"%s\""
17120 (abbreviate-file-name makefile-path-name)))
17121 (switch-to-buffer (current-buffer))))))
17124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17125 ;;; Bug reports
17126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17127 ;; (using `reporter.el')
17129 (defconst vhdl-mode-help-address
17130 "Reto Zimmermann <reto@gnu.org>"
17131 "Address for VHDL Mode bug reports.")
17133 (defun vhdl-submit-bug-report ()
17134 "Submit via mail a bug report on VHDL Mode."
17135 (interactive)
17136 ;; load in reporter
17137 (and
17138 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17139 (let ((reporter-prompt-for-summary-p t))
17140 (reporter-submit-bug-report
17141 vhdl-mode-help-address
17142 (concat "VHDL Mode " vhdl-version)
17143 (list
17144 ;; report all important user options
17145 'vhdl-offsets-alist
17146 'vhdl-comment-only-line-offset
17147 'tab-width
17148 'vhdl-electric-mode
17149 'vhdl-stutter-mode
17150 'vhdl-indent-tabs-mode
17151 'vhdl-project-alist
17152 'vhdl-project
17153 'vhdl-project-file-name
17154 'vhdl-project-auto-load
17155 'vhdl-project-sort
17156 'vhdl-compiler-alist
17157 'vhdl-compiler
17158 'vhdl-compile-use-local-error-regexp
17159 'vhdl-makefile-default-targets
17160 'vhdl-makefile-generation-hook
17161 'vhdl-default-library
17162 'vhdl-standard
17163 'vhdl-basic-offset
17164 'vhdl-upper-case-keywords
17165 'vhdl-upper-case-types
17166 'vhdl-upper-case-attributes
17167 'vhdl-upper-case-enum-values
17168 'vhdl-upper-case-constants
17169 'vhdl-use-direct-instantiation
17170 'vhdl-array-index-record-field-in-sensitivity-list
17171 'vhdl-compose-configuration-name
17172 'vhdl-entity-file-name
17173 'vhdl-architecture-file-name
17174 'vhdl-configuration-file-name
17175 'vhdl-package-file-name
17176 'vhdl-file-name-case
17177 'vhdl-electric-keywords
17178 'vhdl-optional-labels
17179 'vhdl-insert-empty-lines
17180 'vhdl-argument-list-indent
17181 'vhdl-association-list-with-formals
17182 'vhdl-conditions-in-parenthesis
17183 'vhdl-zero-string
17184 'vhdl-one-string
17185 'vhdl-file-header
17186 'vhdl-file-footer
17187 'vhdl-company-name
17188 'vhdl-copyright-string
17189 'vhdl-platform-spec
17190 'vhdl-date-format
17191 'vhdl-modify-date-prefix-string
17192 'vhdl-modify-date-on-saving
17193 'vhdl-reset-kind
17194 'vhdl-reset-active-high
17195 'vhdl-clock-rising-edge
17196 'vhdl-clock-edge-condition
17197 'vhdl-clock-name
17198 'vhdl-reset-name
17199 'vhdl-model-alist
17200 'vhdl-include-port-comments
17201 'vhdl-include-direction-comments
17202 'vhdl-include-type-comments
17203 'vhdl-include-group-comments
17204 'vhdl-actual-port-name
17205 'vhdl-instance-name
17206 'vhdl-testbench-entity-name
17207 'vhdl-testbench-architecture-name
17208 'vhdl-testbench-configuration-name
17209 'vhdl-testbench-dut-name
17210 'vhdl-testbench-include-header
17211 'vhdl-testbench-declarations
17212 'vhdl-testbench-statements
17213 'vhdl-testbench-initialize-signals
17214 'vhdl-testbench-include-library
17215 'vhdl-testbench-include-configuration
17216 'vhdl-testbench-create-files
17217 'vhdl-testbench-entity-file-name
17218 'vhdl-testbench-architecture-file-name
17219 'vhdl-compose-create-files
17220 'vhdl-compose-configuration-create-file
17221 'vhdl-compose-configuration-hierarchical
17222 'vhdl-compose-configuration-use-subconfiguration
17223 'vhdl-compose-include-header
17224 'vhdl-compose-architecture-name
17225 'vhdl-components-package-name
17226 'vhdl-use-components-package
17227 'vhdl-self-insert-comments
17228 'vhdl-prompt-for-comments
17229 'vhdl-inline-comment-column
17230 'vhdl-end-comment-column
17231 'vhdl-auto-align
17232 'vhdl-align-groups
17233 'vhdl-align-group-separate
17234 'vhdl-align-same-indent
17235 'vhdl-highlight-keywords
17236 'vhdl-highlight-names
17237 'vhdl-highlight-special-words
17238 'vhdl-highlight-forbidden-words
17239 'vhdl-highlight-verilog-keywords
17240 'vhdl-highlight-translate-off
17241 'vhdl-highlight-case-sensitive
17242 'vhdl-special-syntax-alist
17243 'vhdl-forbidden-words
17244 'vhdl-forbidden-syntax
17245 'vhdl-directive-keywords
17246 'vhdl-speedbar-auto-open
17247 'vhdl-speedbar-display-mode
17248 'vhdl-speedbar-scan-limit
17249 'vhdl-speedbar-jump-to-unit
17250 'vhdl-speedbar-update-on-saving
17251 'vhdl-speedbar-save-cache
17252 'vhdl-speedbar-cache-file-name
17253 'vhdl-index-menu
17254 'vhdl-source-file-menu
17255 'vhdl-hideshow-menu
17256 'vhdl-hide-all-init
17257 'vhdl-print-two-column
17258 'vhdl-print-customize-faces
17259 'vhdl-intelligent-tab
17260 'vhdl-indent-syntax-based
17261 'vhdl-indent-comment-like-next-code-line
17262 'vhdl-word-completion-case-sensitive
17263 'vhdl-word-completion-in-minibuffer
17264 'vhdl-underscore-is-part-of-word
17265 'vhdl-mode-hook)
17266 (function
17267 (lambda ()
17268 (insert
17269 (if vhdl-special-indent-hook
17270 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17271 "vhdl-special-indent-hook is set to '"
17272 (format "%s" vhdl-special-indent-hook)
17273 ".\nPerhaps this is your problem?\n"
17274 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17275 "\n"))))
17277 "Hi Reto,"))))
17280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17281 ;;; Documentation
17282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17284 (defconst vhdl-doc-release-notes nil
17286 Release Notes for VHDL Mode 3.33
17287 ================================
17289 - New Features
17290 - User Options
17293 New Features
17294 ------------
17296 CONFIGURATION DECLARATION GENERATION:
17297 - Automatic generation of a configuration declaration for a design.
17298 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17301 Key Bindings
17302 ------------
17304 For Emacs compliance the following key bindings have been changed:
17306 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17307 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17308 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17309 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17312 User Options
17313 ------------
17315 `vhdl-configuration-file-name': (new)
17316 Specify how the configuration file name is obtained.
17317 `vhdl-compose-configuration-name': (new)
17318 Specify how the configuration name is obtained.
17319 `vhdl-compose-configuration-create-file': (new)
17320 Specify whether a new file should be created for a configuration.
17321 `vhdl-compose-configuration-hierarchical': (new)
17322 Specify whether hierarchical configurations should be created.
17323 `vhdl-compose-configuration-use-subconfiguration': (new)
17324 Specify whether subconfigurations should be used inside configurations.
17325 `vhdl-makefile-default-targets': (new)
17326 Customize names of Makefile default targets.
17327 `vhdl-indent-comment-like-next-code-line': (new)
17328 Specify whether comment lines are indented like following code line.
17329 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17330 Specify whether to include array indices / record fields in sensitivity list.
17334 (defconst vhdl-doc-keywords nil
17336 Reserved words in VHDL
17337 ----------------------
17339 VHDL'93/02 (IEEE Std 1076-1993/2002):
17340 `vhdl-02-keywords' : keywords
17341 `vhdl-02-types' : standardized types
17342 `vhdl-02-attributes' : standardized attributes
17343 `vhdl-02-enum-values' : standardized enumeration values
17344 `vhdl-02-functions' : standardized functions
17345 `vhdl-02-packages' : standardized packages and libraries
17347 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17348 `vhdl-ams-keywords' : keywords
17349 `vhdl-ams-types' : standardized types
17350 `vhdl-ams-attributes' : standardized attributes
17351 `vhdl-ams-enum-values' : standardized enumeration values
17352 `vhdl-ams-constants' : standardized constants
17353 `vhdl-ams-functions' : standardized functions
17355 Math Packages (IEEE Std 1076.2):
17356 `vhdl-math-types' : standardized types
17357 `vhdl-math-constants' : standardized constants
17358 `vhdl-math-functions' : standardized functions
17359 `vhdl-math-packages' : standardized packages
17361 Forbidden words:
17362 `vhdl-verilog-keywords' : Verilog reserved words
17364 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17367 (defconst vhdl-doc-coding-style nil
17369 For VHDL coding style and naming convention guidelines, see the following
17370 references:
17372 \[1] Ben Cohen.
17373 \"VHDL Coding Styles and Methodologies\".
17374 Kluwer Academic Publishers, 1999.
17375 http://members.aol.com/vhdlcohen/vhdl/
17377 \[2] Michael Keating and Pierre Bricaud.
17378 \"Reuse Methodology Manual, Second Edition\".
17379 Kluwer Academic Publishers, 1999.
17380 http://www.openmore.com/openmore/rmm2.html
17382 \[3] European Space Agency.
17383 \"VHDL Modelling Guidelines\".
17384 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17386 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17387 to visually support naming conventions.")
17390 (defun vhdl-version ()
17391 "Echo the current version of VHDL Mode in the minibuffer."
17392 (interactive)
17393 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17394 (vhdl-keep-region-active))
17396 (defun vhdl-doc-variable (variable)
17397 "Display VARIABLE's documentation in *Help* buffer."
17398 (interactive)
17399 (unless (featurep 'xemacs)
17400 (help-setup-xref (list #'vhdl-doc-variable variable)
17401 (called-interactively-p 'interactive)))
17402 (with-output-to-temp-buffer
17403 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17404 (princ (documentation-property variable 'variable-documentation))
17405 (with-current-buffer standard-output
17406 (help-mode))
17407 (help-print-return-message)))
17409 (defun vhdl-doc-mode ()
17410 "Display VHDL Mode documentation in *Help* buffer."
17411 (interactive)
17412 (unless (featurep 'xemacs)
17413 (help-setup-xref (list #'vhdl-doc-mode)
17414 (called-interactively-p 'interactive)))
17415 (with-output-to-temp-buffer
17416 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17417 (princ mode-name)
17418 (princ " mode:\n")
17419 (princ (documentation 'vhdl-mode))
17420 (with-current-buffer standard-output
17421 (help-mode))
17422 (help-print-return-message)))
17425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17427 (provide 'vhdl-mode)
17429 ;;; vhdl-mode.el ends here