Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / progmodes / vhdl-mode.el
blobb422cf6c989c4061c665c440e8bf689ebda418f3
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2014 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.34.2"
17 "VHDL Mode version number.")
19 (defconst vhdl-time-stamp "2012-11-21"
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 ;; this updated version was only tested on: GNU Emacs 20.4
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 ;; Installation
80 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X/23.X, XEmacs 20.X/21.X.
82 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
83 ;; or into an arbitrary directory that is added to the load path by the
84 ;; following line in your Emacs start-up file `.emacs':
86 ;; (push (expand-file-name "<directory-name>") load-path)
88 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
89 ;; directory. Otherwise, byte-compile the source file:
90 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
91 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
93 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
94 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
95 ;; (not required in Emacs 20 and higher):
97 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
98 ;; (push '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist)
100 ;; More detailed installation instructions are included in the official
101 ;; VHDL Mode distribution.
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104 ;; Acknowledgments
106 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
107 ;; and Steve Grout.
109 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
110 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
112 ;; Many thanks to all the users who sent me bug reports and enhancement
113 ;; requests.
114 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
115 ;; enhancement suggestions and the fruitful discussions.
116 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
117 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
119 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
120 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
121 ;; giving me the opportunity to develop this code.
122 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
123 ;; of the Swiss Government.
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127 ;;; Code:
129 ;; Emacs 21+ handling
130 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
131 "Non-nil if GNU Emacs 21, 22, ... is used.")
132 ;; Emacs 22+ handling
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 ;; 60: docal <= false;
214 ;; ^^^^^
215 ;; [Error] Assignment error: variable is illegal target of signal assignment
216 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
217 nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
218 ("^\\s-+\\([0-9]+\\):\\s-+" nil 1 nil) ("Compiling file \\(.+\\)" 1)
219 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
220 "PACK/\\1.vif" "BODY/\\1.vif" upcase))
221 ;; Aldec
222 ;; COMP96 ERROR COMP96_0018: "Identifier expected." "test.vhd" 66 3
223 ("Aldec" "vcom" "-work \\1" "make" "-f \\1"
224 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
225 (".* ERROR [^:]+: \".*\" \"\\([^ \\t\\n]+\\)\" \\([0-9]+\\) \\([0-9]+\\)" 1 2 3) ("" 0)
226 nil)
227 ;; Cadence Leapfrog: cv -file test.vhd
228 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
229 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
230 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
231 ("duluth: \\*E,[0-9]+ (\\([^ \\t\\n]+\\),\\([0-9]+\\)):" 1 2 nil) ("" 0)
232 ("\\1/entity" "\\2/\\1" "\\1/configuration"
233 "\\1/package" "\\1/body" downcase))
234 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
235 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
236 ;; (PLL_400X_TOP) is not declared [10.3].
237 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
238 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
239 ("ncvhdl_p: \\*E,\\w+ (\\([^ \\t\\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
240 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
241 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
242 ;; ghdl vhdl: ghdl test.vhd
243 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
244 nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
245 ("ghdl_p: \\*E,\\w+ (\\([^ \\t\\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
246 ("\\1/entity" "\\2/\\1" "\\1/configuration"
247 "\\1/package" "\\1/body" downcase))
248 ;; IBM Compiler
249 ;; 00 COACHDL* | [CCHDL-1]: File: adder.vhd, line.column: 120.6
250 ("IBM Compiler" "g2tvc" "-src" "precomp" "\\1"
251 nil "mkdir \\1" "./" "work/" "Makefile" "ibm"
252 ("[0-9]+ COACHDL.*: File: \\([^ \\t\\n]+\\), line.column: \\([0-9]+\\).\\([0-9]+\\)" 1 2 3) (" " 0)
253 nil)
254 ;; Ikos Voyager: analyze test.vhd
255 ;; analyze test.vhd
256 ;; E L4/C5: this library unit is inaccessible
257 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
258 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
259 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" nil 1 2)
260 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
261 nil)
262 ;; ModelSim, Model Technology: vcom test.vhd
263 ;; ERROR: test.vhd(14): Unknown identifier: positiv
264 ;; WARNING[2]: test.vhd(85): Possible infinite loop
265 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
266 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
267 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
268 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
269 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*:\\( *\[[0-9]+\]\\)? \\([^ \\t\\n]+\\)(\\([0-9]+\\)):" 3 4 nil) ("" 0)
270 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
271 "\\1/_primary.dat" "\\1/body.dat" downcase))
272 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
273 ;; test.vhd:34: error message
274 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
275 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
276 ("\\([^ \\t\\n]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
277 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
278 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
279 ;; Quartus compiler
280 ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
281 ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
282 ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
283 ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
284 ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
285 ("Quartus" "make" "-work \\1" "make" "-f \\1"
286 nil "mkdir \\1" "./" "work/" "Makefile" "quartus"
287 ("\\(Error\\|Warning\\): .* \\([^ \\t\\n]+\\)(\\([0-9]+\\))" 2 3 nil) ("" 0)
288 nil)
289 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
290 ;; ERROR: test.vhd(24): near "dnd": expecting: END
291 ;; WARNING[4]: test.vhd(30): A space is required between ...
292 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
293 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
294 ("\\(ERROR\\|WARNING\\)[^:]*: \\([^ \\t\\n]+\\)(\\([0-9]+\\)):" 2 3 nil) ("" 0)
295 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
296 "\\1/_primary.dat" "\\1/body.dat" downcase))
297 ;; Savant: scram -publish-cc test.vhd
298 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
299 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
300 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
301 ("\\([^ \\t\\n]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
302 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
303 "\\1_config.vhdl" "\\1_package.vhdl"
304 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
305 ;; Simili: vhdlp -work test.vhd
306 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
307 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
308 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
309 ("\\(Error\\|Warning\\): \\w+: \\([^ \\t\\n]+\\): (line \\([0-9]+\\)): " 2 3 nil) ("" 0)
310 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
311 "\\1/prim.var" "\\1/_body.var" downcase))
312 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
313 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
314 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
315 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
316 ("^ *ERROR\[[0-9]+\]::File \\([^ \\t\\n]+\\) Line \\([0-9]+\\):" 1 2 nil) ("" 0)
317 nil)
318 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
319 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
320 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
321 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
322 ("\\*\\*Error: vhdlan,[0-9]+ \\([^ \\t\\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
323 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
324 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
325 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
326 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
327 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
328 ("\\*\\*Error: vhdlan,[0-9]+ \\([^ \\t\\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
329 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
330 ;; Synplify:
331 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
332 ("Synplify" "n/a" "n/a" "make" "-f \\1"
333 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
334 ("@[EWN]:\"\\([^ \\t\\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
335 nil)
336 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
337 ;; Compiling "test.vhd" line 1...
338 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
339 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
340 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
341 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
342 ("^ *Compiling \"\\(.+\\)\" " 1)
343 nil)
344 ;; VeriBest: vc vhdl test.vhd
345 ;; (no file name printed out!)
346 ;; 32: Z <= A and BitA ;
347 ;; ^^^^
348 ;; [Error] Name BITA is unknown
349 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
350 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
351 ("^ +\\([0-9]+\\): +[^ ]" nil 1 nil) ("" 0)
352 nil)
353 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
354 ;; Compiling "test.vhd" line 1...
355 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
356 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
357 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
358 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
359 ("^ *Compiling \"\\(.+\\)\" " 1)
360 nil)
361 ;; Xilinx XST:
362 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
363 ("Xilinx XST" "xflow" "" "make" "-f \\1"
364 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
365 ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \\t\\n]+\\)\" Line \\([0-9]+\\)\." 1 2 nil) ("" 0)
366 nil)
368 "List of available VHDL compilers and their properties.
369 Each list entry specifies the following items for a compiler:
370 Compiler:
371 Compiler name : name used in option `vhdl-compiler' to choose compiler
372 Compile command : command used for source file compilation
373 Compile options : compile options (\"\\1\" inserts library name)
374 Make command : command used for compilation using a Makefile
375 Make options : make options (\"\\1\" inserts Makefile name)
376 Generate Makefile: use built-in function or command to generate a Makefile
377 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
378 Library command : command to create library directory \(\"\\1\" inserts
379 library directory, \"\\2\" inserts library name)
380 Compile directory: where compilation is run and the Makefile is placed
381 Library directory: directory of default library
382 Makefile name : name of Makefile (default is \"Makefile\")
383 ID string : compiler identification string (see `vhdl-project-alist')
384 Error message:
385 Regexp : regular expression to match error messages (*)
386 File subexp index: index of subexpression that matches the file name
387 Line subexp index: index of subexpression that matches the line number
388 Column subexp idx: index of subexpression that matches the column number
389 File message:
390 Regexp : regular expression to match a file name message
391 File subexp index: index of subexpression that matches the file name
392 Unit-to-file name mapping: mapping of library unit names to names of files
393 generated by the compiler (used for Makefile generation)
394 To string : string a name is mapped to (\"\\1\" inserts the unit name,
395 \"\\2\" inserts the entity name for architectures)
396 Case adjustment : adjust case of inserted unit names
398 \(*) The regular expression must match the error message starting from the
399 beginning of the line (but not necessarily to the end of the line).
401 Compile options allows insertion of the library name (see `vhdl-project-alist')
402 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
404 For Makefile generation, the built-in function can be used (requires
405 specification of the unit-to-file name mapping). Alternatively, an
406 external command can be specified. Work directory allows specification of
407 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
408 used for Makefile generation). To use another library name than \"work\",
409 customize `vhdl-project-alist'. The library command is inserted in Makefiles
410 to automatically create the library directory if not existent.
412 Compile options, compile directory, library directory, and Makefile name are
413 overwritten by the project settings if a project is defined (see
414 `vhdl-project-alist'). Directory paths are relative to the source file
415 directory.
417 Some compilers do not include the file name in the error message, but print
418 out a file name message in advance. In this case, set \"File Subexp Index\"
419 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
420 If no file name at all is printed out, set both \"File Message\" entries to 0
421 \(a default file name message will be printed out instead, does not work in
422 XEmacs).
424 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
425 assigning its name to option `vhdl-compiler'.
427 Please send any missing or erroneous compiler properties to the maintainer for
428 updating.
430 NOTE: Activate new error and file message regexps and reflect the new setting
431 in the choice list of option `vhdl-compiler' by restarting Emacs."
432 :type '(repeat
433 (list :tag "Compiler" :indent 2
434 (string :tag "Compiler name ")
435 (string :tag "Compile command ")
436 (string :tag "Compile options " "-work \\1")
437 (string :tag "Make command " "make")
438 (string :tag "Make options " "-f \\1")
439 (choice :tag "Generate Makefile "
440 (const :tag "Built-in function" nil)
441 (string :tag "Command" "vmake \\2 > \\1"))
442 (string :tag "Library command " "mkdir \\1")
443 (directory :tag "Compile directory "
444 :validate vhdl-widget-directory-validate "./")
445 (directory :tag "Library directory "
446 :validate vhdl-widget-directory-validate "work/")
447 (file :tag "Makefile name " "Makefile")
448 (string :tag "ID string ")
449 (list :tag "Error message" :indent 4
450 (regexp :tag "Regexp ")
451 (choice :tag "File subexp "
452 (integer :tag "Index")
453 (const :tag "No file name" nil))
454 (integer :tag "Line subexp index")
455 (choice :tag "Column subexp "
456 (integer :tag "Index")
457 (const :tag "No column number" nil)))
458 (list :tag "File message" :indent 4
459 (regexp :tag "Regexp ")
460 (integer :tag "File subexp index"))
461 (choice :tag "Unit-to-file name mapping"
462 :format "%t: %[Value Menu%] %v\n"
463 (const :tag "Not defined" nil)
464 (list :tag "To string" :indent 4
465 (string :tag "Entity " "\\1.vhd")
466 (string :tag "Architecture " "\\2_\\1.vhd")
467 (string :tag "Configuration " "\\1.vhd")
468 (string :tag "Package " "\\1.vhd")
469 (string :tag "Package Body " "\\1_body.vhd")
470 (choice :tag "Case adjustment "
471 (const :tag "None" identity)
472 (const :tag "Upcase" upcase)
473 (const :tag "Downcase" downcase))))))
474 :set (lambda (variable value)
475 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
476 :version "24.4"
477 :group 'vhdl-compile)
479 (defcustom vhdl-compiler "GHDL"
480 "Specifies the VHDL compiler to be used for syntax analysis.
481 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
482 :type (let ((alist vhdl-compiler-alist) list)
483 (while alist
484 (push (list 'const (caar alist)) list)
485 (setq alist (cdr alist)))
486 (append '(choice) (nreverse list)))
487 :group 'vhdl-compile)
489 (defcustom vhdl-compile-use-local-error-regexp t
490 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
491 In this case, only error message regexps for VHDL compilers are active if
492 compilation is started from a VHDL buffer. Otherwise, the error message
493 regexps are appended to the predefined global regexps, and all regexps are
494 active all the time. Note that by doing that, the predefined global regexps
495 might result in erroneous parsing of error messages for some VHDL compilers.
497 NOTE: Activate the new setting by restarting Emacs."
498 :type 'boolean
499 :group 'vhdl-compile)
501 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
502 "List of default target names in Makefiles.
503 Automatically generated Makefiles include three default targets to compile
504 the entire design, clean the entire design and to create the design library.
505 This option allows to change the names of these targets to avoid conflicts
506 with other user Makefiles."
507 :type '(list (string :tag "Compile entire design")
508 (string :tag "Clean entire design ")
509 (string :tag "Create design library"))
510 :version "24.3"
511 :group 'vhdl-compile)
513 (defcustom vhdl-makefile-generation-hook nil
514 "Functions to run at the end of Makefile generation.
515 Allows to insert user specific parts into a Makefile.
517 Example:
518 \(lambda nil
519 \(re-search-backward \"^# Rule for compiling entire design\")
520 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
521 :type 'hook
522 :group 'vhdl-compile)
524 (defcustom vhdl-default-library "work"
525 "Name of default library.
526 Is overwritten by project settings if a project is active."
527 :type 'string
528 :group 'vhdl-compile)
531 (defgroup vhdl-project nil
532 "Customizations for projects."
533 :group 'vhdl)
535 (defcustom vhdl-project-alist
536 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
537 "~/example1/" ("src/system/" "src/components/") ""
538 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
539 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
540 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
541 ("Example 2" "Individual source files, multiple compilers in different directories"
542 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
543 nil "\\1/" "work" "\\1/work/" "Makefile" "")
544 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
545 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
546 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
547 -------------------------------------------------------------------------------
548 -- This is a multi-line project description
549 -- that can be used as a project dependent part of the file header.
551 "List of projects and their properties.
552 Name : name used in option `vhdl-project' to choose project
553 Title : title of project (single-line string)
554 Default directory: default project directory (absolute path)
555 Sources : a) source files : path + \"/\" + file name
556 b) directory : path + \"/\"
557 c) directory tree: \"-r \" + path + \"/\"
558 Exclude regexp : matches file/directory names to be excluded as sources
559 Compile options : project-specific options for each compiler
560 Compiler name : name of compiler for which these options are valid
561 Compile options: project-specific compiler options
562 (\"\\1\" inserts library name, \"\\2\" default options)
563 Make options: project-specific make options
564 (\"\\1\" inserts Makefile name, \"\\2\" default options)
565 Exceptions : file-specific exceptions
566 File name regexp: matches file names for which exceptions are valid
567 - Options : file-specific compiler options string
568 (\"\\1\" inserts library name, \"\\2\" default options,
569 \"\\3\" project-specific options)
570 - Do not compile: do not compile this file (in Makefile)
571 Compile directory: where compilation is run and the Makefile is placed
572 \(\"\\1\" inserts compiler ID string)
573 Library name : name of library (default is \"work\")
574 Library directory: path to library (\"\\1\" inserts compiler ID string)
575 Makefile name : name of Makefile
576 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
577 Description : description of project (multi-line string)
579 Project title and description are used to insert into the file header (see
580 option `vhdl-file-header').
582 The default directory must have an absolute path (use `M-TAB' for completion).
583 All other paths can be absolute or relative to the default directory. All
584 paths must end with '/'.
586 The design units found in the sources (files and directories) are shown in the
587 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
588 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
589 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
590 specified, the default directory is taken as source directory. Otherwise,
591 the default directory is only taken as source directory if there is a sources
592 entry with the empty string or \"./\". Exclude regexp allows to filter out
593 specific file and directory names from the list of sources (e.g. CVS
594 directories).
596 Files are compiled in the compile directory. Makefiles are also placed into
597 the compile directory. Library directory specifies which directory the
598 compiler compiles into (used to generate the Makefile).
600 Since different compile/library directories and Makefiles may exist for
601 different compilers within one project, these paths and names allow the
602 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
603 Compile options, compile directory, library directory, and Makefile name
604 overwrite the settings of the current compiler.
606 File-specific compiler options (highest priority) overwrite project-specific
607 options which overwrite default options (lowest priority). Lower priority
608 options can be inserted in higher priority options. This allows to reuse
609 default options (e.g. \"-file\") in project- or file-specific options (e.g.
610 \"-93 -file\").
612 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
613 by restarting Emacs."
614 :type `(repeat
615 (list :tag "Project" :indent 2
616 (string :tag "Name ")
617 (string :tag "Title ")
618 (directory :tag "Default directory"
619 :validate vhdl-widget-directory-validate
620 ,(abbreviate-file-name default-directory))
621 (repeat :tag "Sources " :indent 4
622 (directory :format " %v" "./"))
623 (regexp :tag "Exclude regexp ")
624 (repeat
625 :tag "Compile options " :indent 4
626 (list :tag "Compiler" :indent 6
627 ,(let ((alist vhdl-compiler-alist) list)
628 (while alist
629 (push (list 'const (caar alist)) list)
630 (setq alist (cdr alist)))
631 (append '(choice :tag "Compiler name")
632 (nreverse list)))
633 (string :tag "Compile options" "\\2")
634 (string :tag "Make options " "\\2")
635 (repeat
636 :tag "Exceptions " :indent 8
637 (cons :format "%v"
638 (regexp :tag "File name regexp ")
639 (choice :format "%[Value Menu%] %v"
640 (string :tag "Options" "\\3")
641 (const :tag "Do not compile" nil))))))
642 (directory :tag "Compile directory"
643 :validate vhdl-widget-directory-validate "./")
644 (string :tag "Library name " "work")
645 (directory :tag "Library directory"
646 :validate vhdl-widget-directory-validate "work/")
647 (file :tag "Makefile name " "Makefile")
648 (string :tag "Description: (type `C-j' for newline)"
649 :format "%t\n%v\n")))
650 :set (lambda (variable value)
651 (vhdl-custom-set variable value
652 'vhdl-update-mode-menu
653 'vhdl-speedbar-refresh))
654 :group 'vhdl-project)
656 (defcustom vhdl-project nil
657 "Specifies the default for the current project.
658 Select a project name from the ones defined in option `vhdl-project-alist'.
659 Is used to determine the project title and description to be inserted in file
660 headers and the source files/directories to be scanned in the hierarchy
661 browser. The current project can also be changed temporarily in the menu."
662 :type (let ((alist vhdl-project-alist) list)
663 (while alist
664 (push (list 'const (caar alist)) list)
665 (setq alist (cdr alist)))
666 (append '(choice (const :tag "None" nil) (const :tag "--"))
667 (nreverse list)))
668 :group 'vhdl-project)
670 (defcustom vhdl-project-file-name '("\\1.prj")
671 "List of file names/paths for importing/exporting project setups.
672 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
673 replaced by the user name (allows to have user-specific project setups).
674 The first entry is used as file name to import/export individual project
675 setups. All entries are used to automatically import project setups at
676 startup (see option `vhdl-project-auto-load'). Projects loaded from the
677 first entry are automatically made current. Hint: specify local project
678 setups in first entry, global setups in following entries; loading a local
679 project setup will make it current, while loading the global setups
680 is done without changing the current project.
681 Names can also have an absolute path (i.e. project setups can be stored
682 in global directories)."
683 :type '(repeat (string :tag "File name" "\\1.prj"))
684 :group 'vhdl-project)
686 (defcustom vhdl-project-auto-load '(startup)
687 "Automatically load project setups from files.
688 All project setup files that match the file names specified in option
689 `vhdl-project-file-name' are automatically loaded. The project of the
690 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
691 entry is activated.
692 A project setup file can be obtained by exporting a project (see menu).
693 At startup: project setup file is loaded at Emacs startup"
694 :type '(set (const :tag "At startup" startup))
695 :group 'vhdl-project)
697 (defcustom vhdl-project-sort t
698 "Non-nil means projects are displayed in alphabetical order."
699 :type 'boolean
700 :group 'vhdl-project)
703 (defgroup vhdl-style nil
704 "Customizations for coding styles."
705 :group 'vhdl
706 :group 'vhdl-template
707 :group 'vhdl-port
708 :group 'vhdl-compose)
710 (defcustom vhdl-standard '(93 nil)
711 "VHDL standards used.
712 Basic standard:
713 VHDL'87 : IEEE Std 1076-1987
714 VHDL'93/02 : IEEE Std 1076-1993/2002
715 Additional standards:
716 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
717 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
719 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
720 \"Activate Options\"."
721 :type '(list (choice :tag "Basic standard"
722 (const :tag "VHDL'87" 87)
723 (const :tag "VHDL'93/02" 93))
724 (set :tag "Additional standards" :indent 2
725 (const :tag "VHDL-AMS" ams)
726 (const :tag "Math packages" math)))
727 :set (lambda (variable value)
728 (vhdl-custom-set variable value
729 'vhdl-template-map-init
730 'vhdl-mode-abbrev-table-init
731 'vhdl-template-construct-alist-init
732 'vhdl-template-package-alist-init
733 'vhdl-update-mode-menu
734 'vhdl-words-init 'vhdl-font-lock-init))
735 :group 'vhdl-style)
737 (defcustom vhdl-basic-offset 2
738 "Amount of basic offset used for indentation.
739 This value is used by + and - symbols in `vhdl-offsets-alist'."
740 :type 'integer
741 :group 'vhdl-style)
743 (defcustom vhdl-upper-case-keywords nil
744 "Non-nil means convert keywords to upper case.
745 This is done when typed or expanded or by the fix case functions."
746 :type 'boolean
747 :set (lambda (variable value)
748 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
749 :group 'vhdl-style)
751 (defcustom vhdl-upper-case-types nil
752 "Non-nil means convert standardized types to upper case.
753 This is done when expanded or by the fix case functions."
754 :type 'boolean
755 :set (lambda (variable value)
756 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
757 :group 'vhdl-style)
759 (defcustom vhdl-upper-case-attributes nil
760 "Non-nil means convert standardized attributes to upper case.
761 This is done when expanded or by the fix case functions."
762 :type 'boolean
763 :set (lambda (variable value)
764 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
765 :group 'vhdl-style)
767 (defcustom vhdl-upper-case-enum-values nil
768 "Non-nil means convert standardized enumeration values to upper case.
769 This is done when expanded or by the fix case functions."
770 :type 'boolean
771 :set (lambda (variable value)
772 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
773 :group 'vhdl-style)
775 (defcustom vhdl-upper-case-constants t
776 "Non-nil means convert standardized constants to upper case.
777 This is done when expanded."
778 :type 'boolean
779 :set (lambda (variable value)
780 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
781 :group 'vhdl-style)
783 (defcustom vhdl-use-direct-instantiation 'standard
784 "Non-nil means use VHDL'93 direct component instantiation.
785 Never : never
786 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
787 Always : always"
788 :type '(choice (const :tag "Never" never)
789 (const :tag "Standard" standard)
790 (const :tag "Always" always))
791 :group 'vhdl-style)
793 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
794 "Non-nil means include array indices / record fields in sensitivity list.
795 If a signal read in a process is a record field or pointed to by an array
796 index, the record field or array index is included with the record name in
797 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
798 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
799 :type 'boolean
800 :version "24.3"
801 :group 'vhdl-style)
803 (defgroup vhdl-naming nil
804 "Customizations for naming conventions."
805 :group 'vhdl)
807 (defcustom vhdl-entity-file-name '(".*" . "\\&")
808 (concat
809 "Specifies how the entity file name is obtained.
810 The entity file name can be obtained by modifying the entity name (e.g.
811 attaching or stripping off a substring). The file extension is automatically
812 taken from the file name of the current buffer."
813 vhdl-name-doc-string)
814 :type '(cons (regexp :tag "From regexp")
815 (string :tag "To string "))
816 :group 'vhdl-naming
817 :group 'vhdl-compose)
819 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
820 (concat
821 "Specifies how the architecture file name is obtained.
822 The architecture file name can be obtained by modifying the entity
823 and/or architecture name (e.g. attaching or stripping off a substring). The
824 file extension is automatically taken from the file name of the current
825 buffer. The string that is matched against the regexp is the concatenation
826 of the entity and the architecture name separated by a space. This gives
827 access to both names (see default setting as example)."
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-configuration-file-name '(".*" . "\\&")
835 (concat
836 "Specifies how the configuration file name is obtained.
837 The configuration file name can be obtained by modifying the configuration
838 name (e.g. attaching or stripping off a substring). The file extension is
839 automatically taken from the file name of the current buffer."
840 vhdl-name-doc-string)
841 :type '(cons (regexp :tag "From regexp")
842 (string :tag "To string "))
843 :group 'vhdl-naming
844 :group 'vhdl-compose)
846 (defcustom vhdl-package-file-name '(".*" . "\\&")
847 (concat
848 "Specifies how the package file name is obtained.
849 The package file name can be obtained by modifying the package name (e.g.
850 attaching or stripping off a substring). The file extension is automatically
851 taken from the file name of the current buffer. Package files can be created
852 in a different directory by prepending a relative or absolute path to the
853 file name."
854 vhdl-name-doc-string)
855 :type '(cons (regexp :tag "From regexp")
856 (string :tag "To string "))
857 :group 'vhdl-naming
858 :group 'vhdl-compose)
860 (defcustom vhdl-file-name-case 'identity
861 "Specifies how to change case for obtaining file names.
862 When deriving a file name from a VHDL unit name, case can be changed as
863 follows:
864 As Is: case is not changed (taken as is)
865 Lower Case: whole name is changed to lower case
866 Upper Case: whole name is changed to upper case
867 Capitalize: first letter of each word in name is capitalized"
868 :type '(choice (const :tag "As Is" identity)
869 (const :tag "Lower Case" downcase)
870 (const :tag "Upper Case" upcase)
871 (const :tag "Capitalize" capitalize))
872 :group 'vhdl-naming
873 :group 'vhdl-compose)
876 (defgroup vhdl-template nil
877 "Customizations for electrification."
878 :group 'vhdl)
880 (defcustom vhdl-electric-keywords '(vhdl user)
881 "Type of keywords for which electrification is enabled.
882 VHDL keywords: invoke built-in templates
883 User keywords: invoke user models (see option `vhdl-model-alist')"
884 :type '(set (const :tag "VHDL keywords" vhdl)
885 (const :tag "User model keywords" user))
886 :set (lambda (variable value)
887 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
888 :group 'vhdl-template)
890 (defcustom vhdl-optional-labels 'process
891 "Constructs for which labels are to be queried.
892 Template generators prompt for optional labels for:
893 None : no constructs
894 Processes only: processes only (also procedurals in VHDL-AMS)
895 All constructs: all constructs with optional labels and keyword END"
896 :type '(choice (const :tag "None" none)
897 (const :tag "Processes only" process)
898 (const :tag "All constructs" all))
899 :group 'vhdl-template)
901 (defcustom vhdl-insert-empty-lines 'unit
902 "Specifies whether to insert empty lines in some templates.
903 This improves readability of code. Empty lines are inserted in:
904 None : no constructs
905 Design units only: entities, architectures, configurations, packages only
906 All constructs : also all constructs with BEGIN...END parts
908 Replaces option `vhdl-additional-empty-lines'."
909 :type '(choice (const :tag "None" none)
910 (const :tag "Design units only" unit)
911 (const :tag "All constructs" all))
912 :group 'vhdl-template
913 :group 'vhdl-port
914 :group 'vhdl-compose)
916 (defcustom vhdl-argument-list-indent nil
917 "Non-nil means indent argument lists relative to opening parenthesis.
918 That is, argument, association, and port lists start on the same line as the
919 opening parenthesis and subsequent lines are indented accordingly.
920 Otherwise, lists start on a new line and are indented as normal code."
921 :type 'boolean
922 :group 'vhdl-template
923 :group 'vhdl-port
924 :group 'vhdl-compose)
926 (defcustom vhdl-association-list-with-formals t
927 "Non-nil means write association lists with formal parameters.
928 Templates prompt for formal and actual parameters (ports/generics).
929 When pasting component instantiations, formals are included.
930 If nil, only a list of actual parameters is entered."
931 :type 'boolean
932 :group 'vhdl-template
933 :group 'vhdl-port
934 :group 'vhdl-compose)
936 (defcustom vhdl-conditions-in-parenthesis nil
937 "Non-nil means place parenthesis around condition expressions."
938 :type 'boolean
939 :group 'vhdl-template)
941 (defcustom vhdl-zero-string "'0'"
942 "String to use for a logic zero."
943 :type 'string
944 :group 'vhdl-template)
946 (defcustom vhdl-one-string "'1'"
947 "String to use for a logic one."
948 :type 'string
949 :group 'vhdl-template)
952 (defgroup vhdl-header nil
953 "Customizations for file header."
954 :group 'vhdl-template
955 :group 'vhdl-compose)
957 (defcustom vhdl-file-header "\
958 -------------------------------------------------------------------------------
959 -- Title : <title string>
960 -- Project : <project>
961 -------------------------------------------------------------------------------
962 -- File : <filename>
963 -- Author : <author>
964 -- Company : <company>
965 -- Created : <date>
966 -- Last update: <date>
967 -- Platform : <platform>
968 -- Standard : <standard>
969 <projectdesc>-------------------------------------------------------------------------------
970 -- Description: <cursor>
971 <copyright>-------------------------------------------------------------------------------
972 -- Revisions :
973 -- Date Version Author Description
974 -- <date> 1.0 <login>\tCreated
975 -------------------------------------------------------------------------------
978 "String or file to insert as file header.
979 If the string specifies an existing file name, the contents of the file is
980 inserted, otherwise the string itself is inserted as file header.
981 Type `C-j' for newlines.
982 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
983 if the header needs to be version controlled.
985 The following keywords for template generation are supported:
986 <filename> : replaced by the name of the buffer
987 <author> : replaced by the user name and email address
988 \(`user-full-name',`mail-host-address', `user-mail-address')
989 <authorfull> : replaced by the user full name (`user-full-name')
990 <login> : replaced by user login name (`user-login-name')
991 <company> : replaced by contents of option `vhdl-company-name'
992 <date> : replaced by the current date
993 <year> : replaced by the current year
994 <project> : replaced by title of current project (`vhdl-project')
995 <projectdesc> : replaced by description of current project (`vhdl-project')
996 <copyright> : replaced by copyright string (`vhdl-copyright-string')
997 <platform> : replaced by contents of option `vhdl-platform-spec'
998 <standard> : replaced by the VHDL language standard(s) used
999 <... string> : replaced by a queried string (\"...\" is the prompt word)
1000 <title string>: replaced by file title in automatically generated files
1001 <cursor> : final cursor position
1003 The (multi-line) project description <projectdesc> can be used as a project
1004 dependent part of the file header and can also contain the above keywords."
1005 :type 'string
1006 :group 'vhdl-header)
1008 (defcustom vhdl-file-footer ""
1009 "String or file to insert as file footer.
1010 If the string specifies an existing file name, the contents of the file is
1011 inserted, otherwise the string itself is inserted as file footer (i.e. at
1012 the end of the file).
1013 Type `C-j' for newlines.
1014 The same keywords as in option `vhdl-file-header' can be used."
1015 :type 'string
1016 :group 'vhdl-header)
1018 (defcustom vhdl-company-name ""
1019 "Name of company to insert in file header.
1020 See option `vhdl-file-header'."
1021 :type 'string
1022 :group 'vhdl-header)
1024 (defcustom vhdl-copyright-string "\
1025 -------------------------------------------------------------------------------
1026 -- Copyright (c) <year> <company>
1028 "Copyright string to insert in file header.
1029 Can be multi-line string (type `C-j' for newline) and contain other file
1030 header keywords (see option `vhdl-file-header')."
1031 :type 'string
1032 :group 'vhdl-header)
1034 (defcustom vhdl-platform-spec ""
1035 "Specification of VHDL platform to insert in file header.
1036 The platform specification should contain names and versions of the
1037 simulation and synthesis tools used.
1038 See option `vhdl-file-header'."
1039 :type 'string
1040 :group 'vhdl-header)
1042 (defcustom vhdl-date-format "%Y-%m-%d"
1043 "Specifies the date format to use in the header.
1044 This string is passed as argument to the command `format-time-string'.
1045 For more information on format strings, see the documentation for the
1046 `format-time-string' command (C-h f `format-time-string')."
1047 :type 'string
1048 :group 'vhdl-header)
1050 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1051 "Prefix string of modification date in VHDL file header.
1052 If actualization of the modification date is called (menu,
1053 `\\[vhdl-template-modify]'), this string is searched and the rest
1054 of the line replaced by the current date."
1055 :type 'string
1056 :group 'vhdl-header)
1058 (defcustom vhdl-modify-date-on-saving t
1059 "Non-nil means update the modification date when the buffer is saved.
1060 Calls function `\\[vhdl-template-modify]').
1062 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1063 \"Activate Options\"."
1064 :type 'boolean
1065 :group 'vhdl-header)
1068 (defgroup vhdl-sequential-process nil
1069 "Customizations for sequential processes."
1070 :group 'vhdl-template)
1072 (defcustom vhdl-reset-kind 'async
1073 "Specifies which kind of reset to use in sequential processes."
1074 :type '(choice (const :tag "None" none)
1075 (const :tag "Synchronous" sync)
1076 (const :tag "Asynchronous" async)
1077 (const :tag "Query" query))
1078 :group 'vhdl-sequential-process)
1080 (defcustom vhdl-reset-active-high nil
1081 "Non-nil means reset in sequential processes is active high.
1082 Otherwise, reset is active low."
1083 :type 'boolean
1084 :group 'vhdl-sequential-process)
1086 (defcustom vhdl-clock-rising-edge t
1087 "Non-nil means rising edge of clock triggers sequential processes.
1088 Otherwise, falling edge triggers."
1089 :type 'boolean
1090 :group 'vhdl-sequential-process)
1092 (defcustom vhdl-clock-edge-condition 'standard
1093 "Syntax of the clock edge condition.
1094 Standard: \"clk'event and clk = '1'\"
1095 Function: \"rising_edge(clk)\""
1096 :type '(choice (const :tag "Standard" standard)
1097 (const :tag "Function" function))
1098 :group 'vhdl-sequential-process)
1100 (defcustom vhdl-clock-name ""
1101 "Name of clock signal to use in templates."
1102 :type 'string
1103 :group 'vhdl-sequential-process)
1105 (defcustom vhdl-reset-name ""
1106 "Name of reset signal to use in templates."
1107 :type 'string
1108 :group 'vhdl-sequential-process)
1111 (defgroup vhdl-model nil
1112 "Customizations for user models."
1113 :group 'vhdl)
1115 (defcustom vhdl-model-alist
1116 '(("Example Model"
1117 "<label> : process (<clock>, <reset>)
1118 begin -- process <label>
1119 if <reset> = '0' then -- asynchronous reset (active low)
1120 <cursor>
1121 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1122 if <enable> = '1' then -- synchronous load
1124 end if;
1125 end if;
1126 end process <label>;"
1127 "e" ""))
1128 "List of user models.
1129 VHDL models (templates) can be specified by the user in this list. They can be
1130 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1131 electrification (i.e. overriding existing or creating new keywords, see
1132 option `vhdl-electric-keywords').
1133 Name : name of model (string of words and spaces)
1134 String : string or name of file to be inserted as model (newline: `C-j')
1135 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1136 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1137 Keyword : keyword to invoke model
1139 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1140 A prompt that appears several times is queried once and replaced throughout
1141 the model. Special prompts are:
1142 <clock> : name specified in `vhdl-clock-name' (if not empty)
1143 <reset> : name specified in `vhdl-reset-name' (if not empty)
1144 <cursor>: final cursor position
1145 File header prompts (see variable `vhdl-file-header') are automatically
1146 replaced, so that user models can also be used to insert different types of
1147 headers.
1149 If the string specifies an existing file name, the contents of the file is
1150 inserted, otherwise the string itself is inserted.
1151 The code within the models should be correctly indented.
1152 Type `C-j' for newlines.
1154 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1155 \"Activate Options\"."
1156 :type '(repeat (list :tag "Model" :indent 2
1157 (string :tag "Name ")
1158 (string :tag "String : (type `C-j' for newline)"
1159 :format "%t\n%v")
1160 (sexp :tag "Key binding" x)
1161 (string :tag "Keyword " :format "%t: %v\n")))
1162 :set (lambda (variable value)
1163 (vhdl-custom-set variable value
1164 'vhdl-model-map-init
1165 'vhdl-model-defun
1166 'vhdl-mode-abbrev-table-init
1167 'vhdl-update-mode-menu))
1168 :group 'vhdl-model)
1171 (defgroup vhdl-compose nil
1172 "Customizations for structural composition."
1173 :group 'vhdl)
1175 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1176 (concat
1177 "Specifies how the component architecture name is obtained.
1178 The component architecture name can be obtained by modifying the entity name
1179 \(e.g. attaching or stripping off a substring).
1180 If TO STRING is empty, the architecture name is queried."
1181 vhdl-name-doc-string)
1182 :type '(cons (regexp :tag "From regexp")
1183 (string :tag "To string "))
1184 :group 'vhdl-compose)
1186 (defcustom vhdl-compose-configuration-name
1187 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1188 (concat
1189 "Specifies how the configuration name is obtained.
1190 The configuration name can be obtained by modifying the entity and/or
1191 architecture name (e.g. attaching or stripping off a substring). The string
1192 that is matched against the regexp is the concatenation of the entity and the
1193 architecture name separated by a space. This gives access to both names (see
1194 default setting as example)."
1195 vhdl-name-doc-string)
1196 :type '(cons (regexp :tag "From regexp")
1197 (string :tag "To string "))
1198 :group 'vhdl-compose)
1200 (defcustom vhdl-components-package-name
1201 '((".*" . "\\&_components") . "components")
1202 (concat
1203 "Specifies how the name for the components package is obtained.
1204 The components package is a package containing all component declarations for
1205 the current design. Its name can be obtained by modifying the project name
1206 \(e.g. attaching or stripping off a substring). If no project is defined, the
1207 DIRECTORY entry is chosen."
1208 vhdl-name-doc-string)
1209 :type '(cons (cons :tag "Project" :indent 2
1210 (regexp :tag "From regexp")
1211 (string :tag "To string "))
1212 (string :tag "Directory:\n String "))
1213 :group 'vhdl-compose)
1215 (defcustom vhdl-use-components-package nil
1216 "Non-nil means use a separate components package for component declarations.
1217 Otherwise, component declarations are inserted and searched for in the
1218 architecture declarative parts."
1219 :type 'boolean
1220 :group 'vhdl-compose)
1222 (defcustom vhdl-compose-include-header t
1223 "Non-nil means include a header in automatically generated files."
1224 :type 'boolean
1225 :group 'vhdl-compose)
1227 (defcustom vhdl-compose-create-files 'single
1228 "Specifies whether new files should be created for the new component.
1229 The component's entity and architecture are inserted:
1230 None : in current buffer
1231 Single file : in new single file
1232 Separate files: in two separate files
1233 The file names are obtained from variables `vhdl-entity-file-name' and
1234 `vhdl-architecture-file-name'."
1235 :type '(choice (const :tag "None" none)
1236 (const :tag "Single file" single)
1237 (const :tag "Separate files" separate))
1238 :group 'vhdl-compose)
1240 (defcustom vhdl-compose-configuration-create-file nil
1241 "Specifies whether a new file should be created for the configuration.
1242 If non-nil, a new file is created for the configuration.
1243 The file name is obtained from variable `vhdl-configuration-file-name'."
1244 :type 'boolean
1245 :group 'vhdl-compose)
1247 (defcustom vhdl-compose-configuration-hierarchical t
1248 "Specifies whether hierarchical configurations should be created.
1249 If non-nil, automatically created configurations are hierarchical and include
1250 the whole hierarchy of subcomponents. Otherwise the configuration only
1251 includes one level of subcomponents."
1252 :type 'boolean
1253 :group 'vhdl-compose)
1255 (defcustom vhdl-compose-configuration-use-subconfiguration t
1256 "Specifies whether subconfigurations should be used inside configurations.
1257 If non-nil, automatically created configurations use configurations in binding
1258 indications for subcomponents, if such configurations exist. Otherwise,
1259 entities are used in binding indications for subcomponents."
1260 :type 'boolean
1261 :group 'vhdl-compose)
1264 (defgroup vhdl-port nil
1265 "Customizations for port translation functions."
1266 :group 'vhdl
1267 :group 'vhdl-compose)
1269 (defcustom vhdl-include-port-comments nil
1270 "Non-nil means include port comments when a port is pasted."
1271 :type 'boolean
1272 :group 'vhdl-port)
1274 (defcustom vhdl-include-direction-comments nil
1275 "Non-nil means include port direction in instantiations as comments."
1276 :type 'boolean
1277 :group 'vhdl-port)
1279 (defcustom vhdl-include-type-comments nil
1280 "Non-nil means include generic/port type in instantiations as comments."
1281 :type 'boolean
1282 :group 'vhdl-port)
1284 (defcustom vhdl-include-group-comments 'never
1285 "Specifies whether to include group comments and spacings.
1286 The comments and empty lines between groups of ports are pasted:
1287 Never : never
1288 Declarations: in entity/component/constant/signal declarations only
1289 Always : also in generic/port maps"
1290 :type '(choice (const :tag "Never" never)
1291 (const :tag "Declarations" decl)
1292 (const :tag "Always" always))
1293 :group 'vhdl-port)
1295 (defcustom vhdl-actual-generic-name '(".*" . "\\&")
1296 (concat
1297 "Specifies how actual generic names are obtained from formal generic names.
1298 In a component instantiation, an actual generic name can be
1299 obtained by modifying the formal generic name (e.g. attaching or stripping
1300 off a substring)."
1301 vhdl-name-doc-string)
1302 :type '(cons (regexp :tag "From regexp")
1303 (string :tag "To string "))
1304 :group 'vhdl-port
1305 :version "24.4")
1307 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1308 (concat
1309 "Specifies how actual port names are obtained from formal port names.
1310 In a component instantiation, an actual port name can be obtained by
1311 modifying the formal port name (e.g. attaching or stripping off a substring)."
1312 vhdl-name-doc-string)
1313 :type '(cons (regexp :tag "From regexp")
1314 (string :tag "To string "))
1315 :group 'vhdl-port)
1317 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1318 (concat
1319 "Specifies how an instance name is obtained.
1320 The instance name can be obtained by modifying the name of the component to be
1321 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1322 by a unique number (starting with 1).
1323 If TO STRING is empty, the instance name is queried."
1324 vhdl-name-doc-string)
1325 :type '(cons (regexp :tag "From regexp")
1326 (string :tag "To string "))
1327 :group 'vhdl-port)
1330 (defgroup vhdl-testbench nil
1331 "Customizations for testbench generation."
1332 :group 'vhdl-port)
1334 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1335 (concat
1336 "Specifies how the testbench entity name is obtained.
1337 The entity name of a testbench can be obtained by modifying the name of
1338 the component to be tested (e.g. attaching or stripping off a substring)."
1339 vhdl-name-doc-string)
1340 :type '(cons (regexp :tag "From regexp")
1341 (string :tag "To string "))
1342 :group 'vhdl-testbench)
1344 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1345 (concat
1346 "Specifies how the testbench architecture name is obtained.
1347 The testbench architecture name can be obtained by modifying the name of
1348 the component to be tested (e.g. attaching or stripping off a substring).
1349 If TO STRING is empty, the architecture name is queried."
1350 vhdl-name-doc-string)
1351 :type '(cons (regexp :tag "From regexp")
1352 (string :tag "To string "))
1353 :group 'vhdl-testbench)
1355 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1356 (concat
1357 "Specifies how the testbench configuration name is obtained.
1358 The configuration name of a testbench can be obtained by modifying the entity
1359 and/or architecture name (e.g. attaching or stripping off a substring). The
1360 string that is matched against the regexp is the concatenation of the entity
1361 and the architecture name separated by a space. This gives access to both
1362 names (see default setting as example)."
1363 vhdl-name-doc-string)
1364 :type '(cons (regexp :tag "From regexp")
1365 (string :tag "To string "))
1366 :group 'vhdl-testbench)
1368 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1369 (concat
1370 "Specifies how a DUT instance name is obtained.
1371 The design-under-test instance name (i.e. the component instantiated in the
1372 testbench) can be obtained by modifying the component name (e.g. attaching
1373 or stripping off a substring)."
1374 vhdl-name-doc-string)
1375 :type '(cons (regexp :tag "From regexp")
1376 (string :tag "To string "))
1377 :group 'vhdl-testbench)
1379 (defcustom vhdl-testbench-include-header t
1380 "Non-nil means include a header in automatically generated files."
1381 :type 'boolean
1382 :group 'vhdl-testbench)
1384 (defcustom vhdl-testbench-declarations "\
1385 -- clock
1386 signal Clk : std_logic := '1';
1388 "String or file to be inserted in the testbench declarative part.
1389 If the string specifies an existing file name, the contents of the file is
1390 inserted, otherwise the string itself is inserted in the testbench
1391 architecture before the BEGIN keyword.
1392 Type `C-j' for newlines."
1393 :type 'string
1394 :group 'vhdl-testbench)
1396 (defcustom vhdl-testbench-statements "\
1397 -- clock generation
1398 Clk <= not Clk after 10 ns;
1400 -- waveform generation
1401 WaveGen_Proc: process
1402 begin
1403 -- insert signal assignments here
1405 wait until Clk = '1';
1406 end process WaveGen_Proc;
1408 "String or file to be inserted in the testbench statement part.
1409 If the string specifies an existing file name, the contents of the file is
1410 inserted, otherwise the string itself is inserted in the testbench
1411 architecture before the END keyword.
1412 Type `C-j' for newlines."
1413 :type 'string
1414 :group 'vhdl-testbench)
1416 (defcustom vhdl-testbench-initialize-signals nil
1417 "Non-nil means initialize signals with `0' when declared in testbench."
1418 :type 'boolean
1419 :group 'vhdl-testbench)
1421 (defcustom vhdl-testbench-include-library t
1422 "Non-nil means a library/use clause for std_logic_1164 is included."
1423 :type 'boolean
1424 :group 'vhdl-testbench)
1426 (defcustom vhdl-testbench-include-configuration t
1427 "Non-nil means a testbench configuration is attached at the end."
1428 :type 'boolean
1429 :group 'vhdl-testbench)
1431 (defcustom vhdl-testbench-create-files 'single
1432 "Specifies whether new files should be created for the testbench.
1433 testbench entity and architecture are inserted:
1434 None : in current buffer
1435 Single file : in new single file
1436 Separate files: in two separate files
1437 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1438 and `vhdl-testbench-architecture-file-name'."
1439 :type '(choice (const :tag "None" none)
1440 (const :tag "Single file" single)
1441 (const :tag "Separate files" separate))
1442 :group 'vhdl-testbench)
1444 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1445 (concat
1446 "Specifies how the testbench entity file name is obtained.
1447 The entity file name can be obtained by modifying the testbench entity name
1448 \(e.g. attaching or stripping off a substring). The file extension is
1449 automatically taken from the file name of the current buffer. Testbench
1450 files can be created in a different directory by prepending a relative or
1451 absolute path to the file name."
1452 vhdl-name-doc-string)
1453 :type '(cons (regexp :tag "From regexp")
1454 (string :tag "To string "))
1455 :group 'vhdl-testbench)
1457 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1458 (concat
1459 "Specifies how the testbench architecture file name is obtained.
1460 The architecture file name can be obtained by modifying the testbench entity
1461 and/or architecture name (e.g. attaching or stripping off a substring). The
1462 string that is matched against the regexp is the concatenation of the entity
1463 and the architecture name separated by a space. This gives access to both
1464 names (see default setting as example). Testbench files can be created in
1465 a different directory by prepending a relative or absolute path to the file
1466 name."
1467 vhdl-name-doc-string)
1468 :type '(cons (regexp :tag "From regexp")
1469 (string :tag "To string "))
1470 :group 'vhdl-testbench)
1473 (defgroup vhdl-comment nil
1474 "Customizations for comments."
1475 :group 'vhdl)
1477 (defcustom vhdl-self-insert-comments t
1478 "Non-nil means various templates automatically insert help comments."
1479 :type 'boolean
1480 :group 'vhdl-comment)
1482 (defcustom vhdl-prompt-for-comments t
1483 "Non-nil means various templates prompt for user definable comments."
1484 :type 'boolean
1485 :group 'vhdl-comment)
1487 (defcustom vhdl-inline-comment-column 40
1488 "Column to indent and align inline comments to.
1489 Overrides local option `comment-column'.
1491 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1492 \"Activate Options\"."
1493 :type 'integer
1494 :group 'vhdl-comment)
1496 (defcustom vhdl-end-comment-column 79
1497 "End of comment column.
1498 Comments that exceed this column number are wrapped.
1500 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1501 \"Activate Options\"."
1502 :type 'integer
1503 :group 'vhdl-comment)
1505 (defvar end-comment-column)
1508 (defgroup vhdl-beautify nil
1509 "Customizations for beautification."
1510 :group 'vhdl)
1512 (defcustom vhdl-auto-align t
1513 "Non-nil means align some templates automatically after generation."
1514 :type 'boolean
1515 :group 'vhdl-beautify)
1517 (defcustom vhdl-align-groups t
1518 "Non-nil means align groups of code lines separately.
1519 A group of code lines is a region of consecutive lines between two lines that
1520 match the regexp in option `vhdl-align-group-separate'."
1521 :type 'boolean
1522 :group 'vhdl-beautify)
1524 (defcustom vhdl-align-group-separate "^\\s-*$"
1525 "Regexp for matching a line that separates groups of lines for alignment.
1526 Examples:
1527 \"^\\s-*$\": matches an empty line
1528 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1529 :type 'regexp
1530 :group 'vhdl-beautify)
1532 (defcustom vhdl-align-same-indent t
1533 "Non-nil means align blocks with same indent separately.
1534 When a region or the entire buffer is aligned, the code is divided into
1535 blocks of same indent which are aligned separately (except for argument/port
1536 lists). This gives nicer alignment in most cases.
1537 Option `vhdl-align-groups' still applies within these blocks."
1538 :type 'boolean
1539 :group 'vhdl-beautify)
1541 (defcustom vhdl-beautify-options '(t t t t t)
1542 "List of options for beautifying code. Allows to disable individual
1543 features of code beautification."
1544 :type '(list (boolean :tag "Whitespace cleanup ")
1545 (boolean :tag "Single statement per line")
1546 (boolean :tag "Indentation ")
1547 (boolean :tag "Alignment ")
1548 (boolean :tag "Case fixing "))
1549 :group 'vhdl-beautify
1550 :version "24.4")
1553 (defgroup vhdl-highlight nil
1554 "Customizations for highlighting."
1555 :group 'vhdl)
1557 (defcustom vhdl-highlight-keywords t
1558 "Non-nil means highlight VHDL keywords and other standardized words.
1559 The following faces are used:
1560 `font-lock-keyword-face' : keywords
1561 `font-lock-type-face' : standardized types
1562 `vhdl-font-lock-attribute-face': standardized attributes
1563 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1564 `vhdl-font-lock-function-face' : standardized function and package names
1566 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1567 entry \"Fontify Buffer\")."
1568 :type 'boolean
1569 :set (lambda (variable value)
1570 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1571 :group 'vhdl-highlight)
1573 (defcustom vhdl-highlight-names t
1574 "Non-nil means highlight declaration names and construct labels.
1575 The following faces are used:
1576 `font-lock-function-name-face' : names in declarations of units,
1577 subprograms, components, as well as labels of VHDL constructs
1578 `font-lock-type-face' : names in type/nature declarations
1579 `vhdl-font-lock-attribute-face': names in attribute declarations
1580 `font-lock-variable-name-face' : names in declarations of signals,
1581 variables, constants, subprogram parameters, generics, and ports
1583 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1584 entry \"Fontify Buffer\")."
1585 :type 'boolean
1586 :set (lambda (variable value)
1587 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1588 :group 'vhdl-highlight)
1590 (defcustom vhdl-highlight-special-words nil
1591 "Non-nil means highlight words with special syntax.
1592 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1593 are highlighted accordingly.
1594 Can be used for visual support of naming conventions.
1596 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1597 entry \"Fontify Buffer\")."
1598 :type 'boolean
1599 :set (lambda (variable value)
1600 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1601 :group 'vhdl-highlight)
1603 (defcustom vhdl-highlight-forbidden-words nil
1604 "Non-nil means highlight forbidden words.
1605 The reserved words specified in option `vhdl-forbidden-words' or having the
1606 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1607 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1608 use them.
1610 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1611 entry \"Fontify Buffer\")."
1612 :type 'boolean
1613 :set (lambda (variable value)
1614 (vhdl-custom-set variable value
1615 'vhdl-words-init 'vhdl-font-lock-init))
1616 :group 'vhdl-highlight)
1618 (defcustom vhdl-highlight-verilog-keywords nil
1619 "Non-nil means highlight Verilog keywords as reserved words.
1620 Verilog keywords are highlighted in a warning color (face
1621 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1623 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1624 entry \"Fontify Buffer\")."
1625 :type 'boolean
1626 :set (lambda (variable value)
1627 (vhdl-custom-set variable value
1628 'vhdl-words-init 'vhdl-font-lock-init))
1629 :group 'vhdl-highlight)
1631 (defcustom vhdl-highlight-translate-off nil
1632 "Non-nil means background-highlight code excluded from translation.
1633 That is, all code between \"-- pragma translate_off\" and
1634 \"-- pragma translate_on\" is highlighted using a different background color
1635 \(face `vhdl-font-lock-translate-off-face').
1636 Note: this might slow down on-the-fly fontification (and thus editing).
1638 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1639 entry \"Fontify Buffer\")."
1640 :type 'boolean
1641 :set (lambda (variable value)
1642 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1643 :group 'vhdl-highlight)
1645 (defcustom vhdl-highlight-case-sensitive nil
1646 "Non-nil means consider case for highlighting.
1647 Possible trade-off:
1648 non-nil also upper-case VHDL words are highlighted, but case of words with
1649 special syntax is not considered
1650 nil only lower-case VHDL words are highlighted, but case of words with
1651 special syntax is considered
1652 Overrides local option `font-lock-keywords-case-fold-search'.
1654 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1655 entry \"Fontify Buffer\")."
1656 :type 'boolean
1657 :group 'vhdl-highlight)
1659 (defcustom vhdl-special-syntax-alist
1660 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1661 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1662 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1663 "List of special syntax to be highlighted.
1664 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1665 syntax (as regular expression) are highlighted in the corresponding color.
1667 Name : string of words and spaces
1668 Regexp : regular expression describing word syntax
1669 (e.g. \"\\\\=\<\\\w+_c\\\\=\>\" matches word with suffix \"_c\")
1670 expression must start with \"\\\\=\<\" and end with \"\\\\=\>\"
1671 if only whole words should be matched (no substrings)
1672 Color (light): foreground color for light background
1673 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1674 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1675 Color (dark) : foreground color for dark background
1676 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1677 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1678 In comments : If non-nil, words are also highlighted inside comments
1680 Can be used for visual support of naming conventions, such as highlighting
1681 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1682 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1683 common substrings or name suffices.
1684 For each entry, a new face is generated with the specified colors and name
1685 \"vhdl-font-lock-\" + name + \"-face\".
1687 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1688 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1689 :type '(repeat (list :tag "Face" :indent 2
1690 (string :tag "Name ")
1691 (regexp :tag "Regexp " "\\w+_")
1692 (string :tag "Color (light)")
1693 (string :tag "Color (dark) ")
1694 (boolean :tag "In comments ")))
1695 :set (lambda (variable value)
1696 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1697 :group 'vhdl-highlight)
1699 (defcustom vhdl-forbidden-words '()
1700 "List of forbidden words to be highlighted.
1701 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1702 words are highlighted in a warning color to indicate not to use them.
1704 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1705 entry \"Fontify Buffer\")."
1706 :type '(repeat (string :format "%v"))
1707 :set (lambda (variable value)
1708 (vhdl-custom-set variable value
1709 'vhdl-words-init 'vhdl-font-lock-init))
1710 :group 'vhdl-highlight)
1712 (defcustom vhdl-forbidden-syntax ""
1713 "Syntax of forbidden words to be highlighted.
1714 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1715 syntax are highlighted in a warning color to indicate not to use them.
1716 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1717 highlights identifiers with 10 or more characters).
1719 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1720 entry \"Fontify Buffer\")."
1721 :type 'regexp
1722 :set (lambda (variable value)
1723 (vhdl-custom-set variable value
1724 'vhdl-words-init 'vhdl-font-lock-init))
1725 :group 'vhdl-highlight)
1727 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1728 "List of compiler directive keywords recognized for highlighting.
1730 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1731 entry \"Fontify Buffer\")."
1732 :type '(repeat (string :format "%v"))
1733 :set (lambda (variable value)
1734 (vhdl-custom-set variable value
1735 'vhdl-words-init 'vhdl-font-lock-init))
1736 :group 'vhdl-highlight)
1739 (defgroup vhdl-speedbar nil
1740 "Customizations for speedbar."
1741 :group 'vhdl)
1743 (defcustom vhdl-speedbar-auto-open nil
1744 "Non-nil means automatically open speedbar at startup.
1745 Alternatively, the speedbar can be opened from the VHDL menu."
1746 :type 'boolean
1747 :group 'vhdl-speedbar)
1749 (defcustom vhdl-speedbar-display-mode 'files
1750 "Specifies the default displaying mode when opening speedbar.
1751 Alternatively, the displaying mode can be selected from the speedbar menu or
1752 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1753 :type '(choice (const :tag "Files" files)
1754 (const :tag "Directory hierarchy" directory)
1755 (const :tag "Project hierarchy" project))
1756 :group 'vhdl-speedbar)
1758 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1759 "Limits scanning of large files and netlists.
1760 Design units: maximum file size to scan for design units
1761 Hierarchy (instances of subcomponents):
1762 File size: maximum file size to scan for instances (in bytes)
1763 Instances per arch: maximum number of instances to scan per architecture
1765 \"None\" always means that there is no limit.
1766 In case of files not or incompletely scanned, a warning message and the file
1767 names are printed out.
1768 Background: scanning for instances is considerably slower than scanning for
1769 design units, especially when there are many instances. These limits should
1770 prevent the scanning of large netlists."
1771 :type '(list (choice :tag "Design units"
1772 :format "%t : %[Value Menu%] %v"
1773 (const :tag "None" nil)
1774 (integer :tag "File size"))
1775 (list :tag "Hierarchy" :indent 2
1776 (choice :tag "File size"
1777 :format "%t : %[Value Menu%] %v"
1778 (const :tag "None" nil)
1779 (integer :tag "Size "))
1780 (choice :tag "Instances per arch"
1781 (const :tag "None" nil)
1782 (integer :tag "Number "))))
1783 :group 'vhdl-speedbar)
1785 (defcustom vhdl-speedbar-jump-to-unit t
1786 "Non-nil means jump to the design unit code when opened in a buffer.
1787 The buffer cursor position is left unchanged otherwise."
1788 :type 'boolean
1789 :group 'vhdl-speedbar)
1791 (defcustom vhdl-speedbar-update-on-saving t
1792 "Automatically update design hierarchy when buffer is saved."
1793 :type 'boolean
1794 :group 'vhdl-speedbar)
1796 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1797 "Automatically save modified hierarchy caches when exiting Emacs.
1798 Hierarchy: design hierarchy information
1799 Display: displaying information (which design units to expand)"
1800 :type '(set (const :tag "Hierarchy" hierarchy)
1801 (const :tag "Display" display))
1802 :group 'vhdl-speedbar)
1804 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1805 "Name of file for saving hierarchy cache.
1806 \"\\1\" is replaced by the project name if a project is specified,
1807 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1808 different users to have cache files in the same directory). Can also have
1809 an absolute path (i.e. all caches can be stored in one global directory)."
1810 :type 'string
1811 :group 'vhdl-speedbar)
1814 (defgroup vhdl-menu nil
1815 "Customizations for menus."
1816 :group 'vhdl)
1818 (defcustom vhdl-index-menu nil
1819 "Non-nil means add an index menu for a source file when loading.
1820 Alternatively, the speedbar can be used. Note that the index menu scans a file
1821 when it is opened, while speedbar only scans the file upon request."
1822 :type 'boolean
1823 :group 'vhdl-menu)
1825 (defcustom vhdl-source-file-menu nil
1826 "Non-nil means add a menu of all source files in current directory.
1827 Alternatively, the speedbar can be used."
1828 :type 'boolean
1829 :group 'vhdl-menu)
1831 (defcustom vhdl-hideshow-menu nil
1832 "Non-nil means add hideshow menu and functionality at startup.
1833 Hideshow can also be enabled from the VHDL Mode menu.
1834 Hideshow allows hiding code of various VHDL constructs.
1836 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1837 \"Activate Options\"."
1838 :type 'boolean
1839 :group 'vhdl-menu)
1841 (defcustom vhdl-hide-all-init nil
1842 "Non-nil means hide all design units initially after a file is loaded."
1843 :type 'boolean
1844 :group 'vhdl-menu)
1847 (defgroup vhdl-print nil
1848 "Customizations for printing."
1849 :group 'vhdl)
1851 (defcustom vhdl-print-two-column t
1852 "Non-nil means print code in two columns and landscape format.
1853 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1854 prints VHDL files in a nice two-column landscape style.
1856 NOTE: Activate the new setting by restarting Emacs.
1857 Overrides `ps-print' settings locally."
1858 :type 'boolean
1859 :group 'vhdl-print)
1861 (defcustom vhdl-print-customize-faces t
1862 "Non-nil means use an optimized set of faces for PostScript printing.
1864 NOTE: Activate the new setting by restarting Emacs.
1865 Overrides `ps-print' settings locally."
1866 :type 'boolean
1867 :group 'vhdl-print)
1870 (defgroup vhdl-misc nil
1871 "Miscellaneous customizations."
1872 :group 'vhdl)
1874 (defcustom vhdl-intelligent-tab t
1875 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1876 That is, if preceding character is part of a word then complete word,
1877 else if not at beginning of line then insert tab,
1878 else if last command was a `TAB' or `RET' then dedent one step,
1879 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1880 If nil, TAB always indents current line (i.e. `TAB' is bound to
1881 `indent-according-to-mode').
1883 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1884 \"Activate Options\"."
1885 :type 'boolean
1886 :group 'vhdl-misc)
1888 (defcustom vhdl-indent-syntax-based t
1889 "Non-nil means indent lines of code based on their syntactic context.
1890 Otherwise, a line is indented like the previous nonblank line. This can be
1891 useful in large files where syntax-based indentation gets very slow."
1892 :type 'boolean
1893 :group 'vhdl-misc)
1895 (defcustom vhdl-indent-comment-like-next-code-line t
1896 "Non-nil means comment lines are indented like the following code line.
1897 Otherwise, comment lines are indented like the preceding code line.
1898 Indenting comment lines like the following code line gives nicer indentation
1899 when comments precede the code that they refer to."
1900 :type 'boolean
1901 :version "24.3"
1902 :group 'vhdl-misc)
1904 (defcustom vhdl-word-completion-case-sensitive nil
1905 "Non-nil means word completion using `TAB' is case sensitive.
1906 That is, `TAB' completes words that start with the same letters and case.
1907 Otherwise, case is ignored."
1908 :type 'boolean
1909 :group 'vhdl-misc)
1911 (defcustom vhdl-word-completion-in-minibuffer t
1912 "Non-nil enables word completion in minibuffer (for template prompts).
1914 NOTE: Activate the new setting by restarting Emacs."
1915 :type 'boolean
1916 :group 'vhdl-misc)
1918 (defcustom vhdl-underscore-is-part-of-word nil
1919 "Non-nil means consider the underscore character `_' as part of word.
1920 An identifier containing underscores is then treated as a single word in
1921 select and move operations. All parts of an identifier separated by underscore
1922 are treated as single words otherwise."
1923 :type 'boolean
1924 :group 'vhdl-misc)
1925 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1926 'superword-mode "24.4")
1929 (defgroup vhdl-related nil
1930 "Related general customizations."
1931 :group 'vhdl)
1933 ;; add related general customizations
1934 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1935 (if (featurep 'xemacs)
1936 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1937 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1938 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1939 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1940 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1941 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1942 (unless (featurep 'xemacs)
1943 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1944 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1945 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1946 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1948 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1949 ;; Hidden user variables
1951 (defvar vhdl-compile-absolute-path nil
1952 "If non-nil, use absolute instead of relative path for compiled files.")
1954 (defvar vhdl-comment-display-line-char ?-
1955 "Character to use in comment display line.")
1957 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1958 ;; Internal variables
1960 (defvar vhdl-menu-max-size 20
1961 "Specifies the maximum size of a menu before splitting it into submenus.")
1963 (defvar vhdl-progress-interval 1
1964 "Interval used to update progress status during long operations.
1965 If a number, percentage complete gets updated after each interval of
1966 that many seconds. To inhibit all messages, set this option to nil.")
1968 (defvar vhdl-inhibit-startup-warnings-p nil
1969 "If non-nil, inhibits start up compatibility warnings.")
1971 (defvar vhdl-strict-syntax-p nil
1972 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1973 If the syntactic symbol for a particular line does not match a symbol
1974 in the offsets alist, an error is generated, otherwise no error is
1975 reported and the syntactic symbol is ignored.")
1977 (defvar vhdl-echo-syntactic-information-p nil
1978 "If non-nil, syntactic info is echoed when the line is indented.")
1980 (defconst vhdl-offsets-alist-default
1981 '((string . -1000)
1982 (cpp-macro . -1000)
1983 (block-open . 0)
1984 (block-close . 0)
1985 (statement . 0)
1986 (statement-cont . vhdl-lineup-statement-cont)
1987 (statement-block-intro . +)
1988 (statement-case-intro . +)
1989 (case-alternative . +)
1990 (comment . vhdl-lineup-comment)
1991 (arglist-intro . +)
1992 (arglist-cont . 0)
1993 (arglist-cont-nonempty . vhdl-lineup-arglist)
1994 (arglist-close . vhdl-lineup-arglist)
1995 (entity . 0)
1996 (configuration . 0)
1997 (package . 0)
1998 (architecture . 0)
1999 (package-body . 0)
2001 "Default settings for offsets of syntactic elements.
2002 Do not change this constant! See the variable `vhdl-offsets-alist' for
2003 more information.")
2005 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
2006 "Association list of syntactic element symbols and indentation offsets.
2007 As described below, each cons cell in this list has the form:
2009 (SYNTACTIC-SYMBOL . OFFSET)
2011 When a line is indented, `vhdl-mode' first determines the syntactic
2012 context of the line by generating a list of symbols called syntactic
2013 elements. This list can contain more than one syntactic element and
2014 the global variable `vhdl-syntactic-context' contains the context list
2015 for the line being indented. Each element in this list is actually a
2016 cons cell of the syntactic symbol and a buffer position. This buffer
2017 position is call the relative indent point for the line. Some
2018 syntactic symbols may not have a relative indent point associated with
2019 them.
2021 After the syntactic context list for a line is generated, `vhdl-mode'
2022 calculates the absolute indentation for the line by looking at each
2023 syntactic element in the list. First, it compares the syntactic
2024 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2025 finds a match, it adds the OFFSET to the column of the relative indent
2026 point. The sum of this calculation for each element in the syntactic
2027 list is the absolute offset for line being indented.
2029 If the syntactic element does not match any in the `vhdl-offsets-alist',
2030 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2031 the element is ignored.
2033 Actually, OFFSET can be an integer, a function, a variable, or one of
2034 the following symbols: `+', `-', `++', or `--'. These latter
2035 designate positive or negative multiples of `vhdl-basic-offset',
2036 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2037 called with a single argument containing the cons of the syntactic
2038 element symbol and the relative indent point. The function should
2039 return an integer offset.
2041 Here is the current list of valid syntactic element symbols:
2043 string -- inside multi-line string
2044 block-open -- statement block open
2045 block-close -- statement block close
2046 statement -- a VHDL statement
2047 statement-cont -- a continuation of a VHDL statement
2048 statement-block-intro -- the first line in a new statement block
2049 statement-case-intro -- the first line in a case alternative block
2050 case-alternative -- a case statement alternative clause
2051 comment -- a line containing only a comment
2052 arglist-intro -- the first line in an argument list
2053 arglist-cont -- subsequent argument list lines when no
2054 arguments follow on the same line as
2055 the arglist opening paren
2056 arglist-cont-nonempty -- subsequent argument list lines when at
2057 least one argument follows on the same
2058 line as the arglist opening paren
2059 arglist-close -- the solo close paren of an argument list
2060 entity -- inside an entity declaration
2061 configuration -- inside a configuration declaration
2062 package -- inside a package declaration
2063 architecture -- inside an architecture body
2064 package-body -- inside a package body")
2066 (defvar vhdl-comment-only-line-offset 0
2067 "Extra offset for line which contains only the start of a comment.
2068 Can contain an integer or a cons cell of the form:
2070 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2072 Where NON-ANCHORED-OFFSET is the amount of offset given to
2073 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2074 the amount of offset to give column-zero anchored comment-only lines.
2075 Just an integer as value is equivalent to (<val> . 0)")
2077 (defvar vhdl-special-indent-hook nil
2078 "Hook for user defined special indentation adjustments.
2079 This hook gets called after a line is indented by the mode.")
2081 (defvar vhdl-style-alist
2082 '(("IEEE"
2083 (vhdl-basic-offset . 4)
2084 (vhdl-offsets-alist . ())))
2085 "Styles of Indentation.
2086 Elements of this alist are of the form:
2088 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2090 where STYLE-STRING is a short descriptive string used to select a
2091 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2092 value for that variable when using the selected style.
2094 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2095 case, the VALUE is a list containing elements of the form:
2097 (SYNTACTIC-SYMBOL . VALUE)
2099 as described in `vhdl-offsets-alist'. These are passed directly to
2100 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2101 your style, only those that are different from the default.")
2103 ;; dynamically append the default value of most variables
2104 (or (assoc "Default" vhdl-style-alist)
2105 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2106 vhdl-strict-syntax-p
2107 vhdl-echo-syntactic-information-p
2108 vhdl-basic-offset
2109 vhdl-offsets-alist
2110 vhdl-comment-only-line-offset))
2111 (default (cons "Default"
2112 (mapcar
2113 (function
2114 (lambda (var)
2115 (cons var (symbol-value var))))
2116 varlist))))
2117 (push default vhdl-style-alist)))
2119 (defvar vhdl-mode-hook nil
2120 "Hook called by `vhdl-mode'.")
2123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2124 ;;; Required packages
2125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2127 ;; mandatory
2128 (require 'assoc)
2129 (require 'compile) ; XEmacs
2130 (require 'easymenu)
2131 (require 'hippie-exp)
2133 ;; optional (minimize warning messages during compile)
2134 (unless (featurep 'xemacs)
2135 (eval-when-compile
2136 (require 'font-lock)
2137 (require 'ps-print)
2138 (require 'speedbar))) ; for speedbar-with-writable
2141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2142 ;;; Compatibility
2143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2146 ;; XEmacs compatibility
2148 ;; active regions
2149 (defun vhdl-keep-region-active ()
2150 "Do whatever is necessary to keep the region active in XEmacs.
2151 Ignore byte-compiler warnings you might see."
2152 (and (featurep 'xemacs)
2153 (setq zmacs-region-stays t)))
2155 ;; `wildcard-to-regexp' is included only in XEmacs 21
2156 (unless (fboundp 'wildcard-to-regexp)
2157 (defun wildcard-to-regexp (wildcard)
2158 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2159 (let* ((i (string-match "[*?]" wildcard))
2160 (result (substring wildcard 0 i))
2161 (len (length wildcard)))
2162 (when i
2163 (while (< i len)
2164 (let ((ch (aref wildcard i)))
2165 (setq result (concat result
2166 (cond ((eq ch ?*) "[^\000]*")
2167 ((eq ch ??) "[^\000]")
2168 (t (char-to-string ch)))))
2169 (setq i (1+ i)))))
2170 (concat "\\`" result "\\'"))))
2172 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2173 ;; `regexp-opt' accelerates fontification by 10-20%
2174 (unless (fboundp 'regexp-opt)
2175 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2176 (defun regexp-opt (strings &optional paren)
2177 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2178 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2180 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2181 (unless (fboundp 'match-string-no-properties)
2182 (defalias 'match-string-no-properties 'match-string))
2184 ;; `subst-char-in-string' undefined (XEmacs)
2185 (unless (fboundp 'subst-char-in-string)
2186 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2187 (let ((i (length string))
2188 (newstr (if inplace string (copy-sequence string))))
2189 (while (> i 0)
2190 (setq i (1- i))
2191 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2192 newstr)))
2194 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2195 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2196 (not noninteractive))
2197 (load "itimer")
2198 (when (string< itimer-version "1.09")
2199 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2200 (beep) (sit-for 5)))
2202 ;; `file-expand-wildcards' undefined (XEmacs)
2203 (unless (fboundp 'file-expand-wildcards)
2204 (defun file-expand-wildcards (pattern &optional full)
2205 "Taken from Emacs's `files.el'."
2206 (let* ((nondir (file-name-nondirectory pattern))
2207 (dirpart (file-name-directory pattern))
2208 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2209 (mapcar 'file-name-as-directory
2210 (file-expand-wildcards (directory-file-name dirpart)))
2211 (list dirpart)))
2212 contents)
2213 (while dirs
2214 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2215 (file-directory-p (directory-file-name (car dirs))))
2216 (let ((this-dir-contents
2217 (delq nil
2218 (mapcar #'(lambda (name)
2219 (unless (string-match "\\`\\.\\.?\\'"
2220 (file-name-nondirectory name))
2221 name))
2222 (directory-files (or (car dirs) ".") full
2223 (wildcard-to-regexp nondir))))))
2224 (setq contents
2225 (nconc
2226 (if (and (car dirs) (not full))
2227 (mapcar (function (lambda (name) (concat (car dirs) name)))
2228 this-dir-contents)
2229 this-dir-contents)
2230 contents))))
2231 (setq dirs (cdr dirs)))
2232 contents)))
2234 ;; `member-ignore-case' undefined (XEmacs)
2235 (unless (fboundp 'member-ignore-case)
2236 (defalias 'member-ignore-case 'member))
2238 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2239 ;; behavior in XEmacs
2240 (defvar vhdl-last-input-event)
2241 (if (featurep 'xemacs)
2242 (defvaralias 'vhdl-last-input-event 'last-input-char)
2243 (defvaralias 'vhdl-last-input-event 'last-input-event))
2245 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2246 ;;;(unless (fboundp 'help-print-return-message)
2247 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2250 ;; Compatibility with older VHDL Mode versions
2252 (defvar vhdl-warnings nil
2253 "Warnings to tell the user during start up.")
2255 (defun vhdl-run-when-idle (secs repeat function)
2256 "Wait until idle, then run FUNCTION."
2257 (if (fboundp 'start-itimer)
2258 (start-itimer "vhdl-mode" function secs repeat t)
2259 ; (run-with-idle-timer secs repeat function)))
2260 ;; explicitly activate timer (necessary when Emacs is already idle)
2261 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2263 (defun vhdl-warning-when-idle (&rest args)
2264 "Wait until idle, then print out warning STRING and beep."
2265 (if noninteractive
2266 (vhdl-warning (apply 'format args) t)
2267 (unless vhdl-warnings
2268 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2269 (push (apply 'format args) vhdl-warnings)))
2271 (defun vhdl-warning (string &optional nobeep)
2272 "Print out warning STRING and beep."
2273 (message "WARNING: %s" string)
2274 (unless (or nobeep noninteractive) (beep)))
2276 (defun vhdl-print-warnings ()
2277 "Print out messages in variable `vhdl-warnings'."
2278 (let ((no-warnings (length vhdl-warnings)))
2279 (setq vhdl-warnings (nreverse vhdl-warnings))
2280 (while vhdl-warnings
2281 (message "WARNING: %s" (car vhdl-warnings))
2282 (setq vhdl-warnings (cdr vhdl-warnings)))
2283 (beep)
2284 (when (> no-warnings 1)
2285 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2287 ;; Backward compatibility checks and fixes
2288 ;; option `vhdl-compiler' changed format
2289 (unless (stringp vhdl-compiler)
2290 (setq vhdl-compiler "ModelSim")
2291 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2293 ;; option `vhdl-standard' changed format
2294 (unless (listp vhdl-standard)
2295 (setq vhdl-standard '(87 nil))
2296 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2298 ;; option `vhdl-model-alist' changed format
2299 (when (= (length (car vhdl-model-alist)) 3)
2300 (let ((old-alist vhdl-model-alist)
2301 new-alist)
2302 (while old-alist
2303 (push (append (car old-alist) '("")) new-alist)
2304 (setq old-alist (cdr old-alist)))
2305 (setq vhdl-model-alist (nreverse new-alist)))
2306 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2308 ;; option `vhdl-project-alist' changed format
2309 (when (= (length (car vhdl-project-alist)) 3)
2310 (let ((old-alist vhdl-project-alist)
2311 new-alist)
2312 (while old-alist
2313 (push (append (car old-alist) '("")) new-alist)
2314 (setq old-alist (cdr old-alist)))
2315 (setq vhdl-project-alist (nreverse new-alist)))
2316 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2318 ;; option `vhdl-project-alist' changed format (3.31.1)
2319 (when (= (length (car vhdl-project-alist)) 4)
2320 (let ((old-alist vhdl-project-alist)
2321 new-alist elem)
2322 (while old-alist
2323 (setq elem (car old-alist))
2324 (setq new-alist
2325 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2326 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2327 new-alist))
2328 (setq old-alist (cdr old-alist)))
2329 (setq vhdl-project-alist (nreverse new-alist)))
2330 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2332 ;; option `vhdl-project-alist' changed format (3.31.12)
2333 (when (= (length (car vhdl-project-alist)) 10)
2334 (let ((tmp-alist vhdl-project-alist))
2335 (while tmp-alist
2336 (setcdr (nthcdr 3 (car tmp-alist))
2337 (cons "" (nthcdr 4 (car tmp-alist))))
2338 (setq tmp-alist (cdr tmp-alist))))
2339 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2341 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2342 (when (= (length (car vhdl-compiler-alist)) 7)
2343 (let ((old-alist vhdl-compiler-alist)
2344 new-alist elem)
2345 (while old-alist
2346 (setq elem (car old-alist))
2347 (setq new-alist
2348 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2349 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2350 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2351 (nth 5 elem) (nth 6 elem) nil)
2352 new-alist))
2353 (setq old-alist (cdr old-alist)))
2354 (setq vhdl-compiler-alist (nreverse new-alist)))
2355 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2357 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2358 (when (= (length (car vhdl-compiler-alist)) 12)
2359 (let ((tmp-alist vhdl-compiler-alist))
2360 (while tmp-alist
2361 (setcdr (nthcdr 4 (car tmp-alist))
2362 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2363 (setq tmp-alist (cdr tmp-alist))))
2364 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2366 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2367 (when (= (length (car vhdl-compiler-alist)) 13)
2368 (let ((tmp-alist vhdl-compiler-alist))
2369 (while tmp-alist
2370 (setcdr (nthcdr 3 (car tmp-alist))
2371 (cons "" (nthcdr 4 (car tmp-alist))))
2372 (setq tmp-alist (cdr tmp-alist))))
2373 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2375 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2376 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2377 (let ((tmp-alist vhdl-compiler-alist))
2378 (while tmp-alist
2379 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2380 '(0 . nil))
2381 (setq tmp-alist (cdr tmp-alist))))
2382 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2384 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2385 (when (equal vhdl-project "")
2386 (setq vhdl-project nil)
2387 (customize-save-variable 'vhdl-project vhdl-project))
2389 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2390 (when (stringp vhdl-project-file-name)
2391 (setq vhdl-project-file-name (list vhdl-project-file-name))
2392 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2394 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2395 (if (not (boundp 'speedbar-indentation-width))
2396 (defvar speedbar-indentation-width 2)
2397 ;; set default to 2 if not already customized
2398 (unless (get 'speedbar-indentation-width 'saved-value)
2399 (setq speedbar-indentation-width 2)))
2401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2402 ;;; Help functions / inline substitutions / macros
2403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2405 (defun vhdl-standard-p (standard)
2406 "Check if STANDARD is specified as used standard."
2407 (or (eq standard (car vhdl-standard))
2408 (memq standard (cadr vhdl-standard))))
2410 (defun vhdl-project-p (&optional warning)
2411 "Return non-nil if a project is displayed, i.e. directories or files are
2412 specified."
2413 (if (assoc vhdl-project vhdl-project-alist)
2414 vhdl-project
2415 (when (and vhdl-project warning)
2416 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2417 nil))
2419 (defun vhdl-resolve-env-variable (string)
2420 "Resolve environment variables in STRING."
2421 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2422 (setq string (concat (match-string 1 string)
2423 (getenv (match-string 2 string))
2424 (match-string 4 string))))
2425 string)
2427 (defun vhdl-default-directory ()
2428 "Return the default directory of the current project or the directory of the
2429 current buffer if no project is defined."
2430 (if (vhdl-project-p)
2431 (expand-file-name (vhdl-resolve-env-variable
2432 (nth 1 (aget vhdl-project-alist vhdl-project))))
2433 default-directory))
2435 (defmacro vhdl-prepare-search-1 (&rest body)
2436 "Enable case insensitive search and switch to syntax table that includes '_',
2437 then execute BODY, and finally restore the old environment. Used for
2438 consistent searching."
2439 `(let ((case-fold-search t)) ; case insensitive search
2440 ;; use extended syntax table
2441 (with-syntax-table vhdl-mode-ext-syntax-table
2442 ,@body)))
2444 (defmacro vhdl-prepare-search-2 (&rest body)
2445 "Enable case insensitive search, switch to syntax table that includes '_',
2446 and remove `intangible' overlays, then execute BODY, and finally restore the
2447 old environment. Used for consistent searching."
2448 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2449 `(let ((case-fold-search t) ; case insensitive search
2450 (current-syntax-table (syntax-table))
2451 overlay-all-list overlay-intangible-list overlay)
2452 ;; use extended syntax table
2453 (set-syntax-table vhdl-mode-ext-syntax-table)
2454 ;; remove `intangible' overlays
2455 (when (fboundp 'overlay-lists)
2456 (setq overlay-all-list (overlay-lists))
2457 (setq overlay-all-list
2458 (append (car overlay-all-list) (cdr overlay-all-list)))
2459 (while overlay-all-list
2460 (setq overlay (car overlay-all-list))
2461 (when (memq 'intangible (overlay-properties overlay))
2462 (setq overlay-intangible-list
2463 (cons overlay overlay-intangible-list))
2464 (overlay-put overlay 'intangible nil))
2465 (setq overlay-all-list (cdr overlay-all-list))))
2466 ;; execute BODY safely
2467 (unwind-protect
2468 (progn ,@body)
2469 ;; restore syntax table
2470 (set-syntax-table current-syntax-table)
2471 ;; restore `intangible' overlays
2472 (when (fboundp 'overlay-lists)
2473 (while overlay-intangible-list
2474 (overlay-put (car overlay-intangible-list) 'intangible t)
2475 (setq overlay-intangible-list
2476 (cdr overlay-intangible-list)))))))
2478 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2479 "Visit file FILE-NAME and execute BODY."
2480 `(if (null ,file-name)
2481 (progn ,@body)
2482 (unless (file-directory-p ,file-name)
2483 (let ((source-buffer (current-buffer))
2484 (visiting-buffer (find-buffer-visiting ,file-name))
2485 file-opened)
2486 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2487 (condition-case ()
2488 (progn (set-buffer (create-file-buffer ,file-name))
2489 (setq file-opened t)
2490 (vhdl-insert-file-contents ,file-name)
2491 ;; FIXME: This modifies a global syntax-table!
2492 (modify-syntax-entry ?\- ". 12" (syntax-table))
2493 (modify-syntax-entry ?\n ">" (syntax-table))
2494 (modify-syntax-entry ?\^M ">" (syntax-table))
2495 (modify-syntax-entry ?_ "w" (syntax-table))
2497 (error
2498 (if ,issue-error
2499 (progn
2500 (when file-opened (kill-buffer (current-buffer)))
2501 (set-buffer source-buffer)
2502 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2503 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2504 nil))))
2505 (condition-case info
2506 (progn ,@body)
2507 (error
2508 (if ,issue-error
2509 (progn
2510 (when file-opened (kill-buffer (current-buffer)))
2511 (set-buffer source-buffer)
2512 (error (cadr info)))
2513 (vhdl-warning (cadr info))))))
2514 (when file-opened (kill-buffer (current-buffer)))
2515 (set-buffer source-buffer)))))
2517 (defun vhdl-insert-file-contents (filename)
2518 "Nicked from `insert-file-contents-literally', but allow coding system
2519 conversion."
2520 (let ((format-alist nil)
2521 (after-insert-file-functions nil)
2522 (jka-compr-compression-info-list nil))
2523 (insert-file-contents filename t)))
2525 (defun vhdl-sort-alist (alist)
2526 "Sort ALIST."
2527 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2529 (defun vhdl-get-subdirs (directory)
2530 "Recursively get subdirectories of DIRECTORY."
2531 (let ((dir-list (list (file-name-as-directory directory)))
2532 file-list)
2533 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2534 (while file-list
2535 (when (file-directory-p (car file-list))
2536 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2537 (setq file-list (cdr file-list)))
2538 dir-list))
2540 (defun vhdl-aput (alist-symbol key &optional value)
2541 "As `aput', but delete key-value pair if VALUE is nil."
2542 (if value
2543 (aput alist-symbol key value)
2544 (adelete alist-symbol key)))
2546 (defun vhdl-delete (elt list)
2547 "Delete by side effect the first occurrence of ELT as a member of LIST."
2548 (push nil list)
2549 (let ((list1 list))
2550 (while (and (cdr list1) (not (equal elt (cadr list1))))
2551 (setq list1 (cdr list1)))
2552 (when list
2553 (setcdr list1 (cddr list1))))
2554 (cdr list))
2556 (declare-function speedbar-refresh "speedbar" (&optional arg))
2557 (declare-function speedbar-do-function-pointer "speedbar" ())
2559 (defun vhdl-speedbar-refresh (&optional key)
2560 "Refresh directory or project with name KEY."
2561 (when (and (boundp 'speedbar-frame)
2562 (frame-live-p speedbar-frame))
2563 (let ((pos (point))
2564 (last-frame (selected-frame)))
2565 (if (null key)
2566 (speedbar-refresh)
2567 (select-frame speedbar-frame)
2568 (when (save-excursion
2569 (goto-char (point-min))
2570 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2571 (goto-char (match-end 1))
2572 (speedbar-do-function-pointer)
2573 (backward-char 2)
2574 (speedbar-do-function-pointer)
2575 (message "Refreshing speedbar...done"))
2576 (select-frame last-frame)))))
2578 (defun vhdl-show-messages ()
2579 "Get *Messages* buffer to show recent messages."
2580 (interactive)
2581 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2583 (defun vhdl-use-direct-instantiation ()
2584 "Return whether direct instantiation is used."
2585 (or (eq vhdl-use-direct-instantiation 'always)
2586 (and (eq vhdl-use-direct-instantiation 'standard)
2587 (not (vhdl-standard-p '87)))))
2589 (defun vhdl-max-marker (marker1 marker2)
2590 "Return larger marker."
2591 (if (> marker1 marker2) marker1 marker2))
2593 (defun vhdl-goto-marker (marker)
2594 "Goto marker in appropriate buffer."
2595 (when (markerp marker)
2596 (set-buffer (marker-buffer marker)))
2597 (goto-char marker))
2599 (defun vhdl-goto-line (line)
2600 "Use this instead of calling user level function `goto-line'."
2601 (goto-char (point-min))
2602 (forward-line (1- line)))
2604 (defun vhdl-menu-split (list title)
2605 "Split menu LIST into several submenus, if number of
2606 elements > `vhdl-menu-max-size'."
2607 (if (> (length list) vhdl-menu-max-size)
2608 (let ((remain list)
2609 (result '())
2610 (sublist '())
2611 (menuno 1)
2612 (i 0))
2613 (while remain
2614 (push (car remain) sublist)
2615 (setq remain (cdr remain))
2616 (setq i (+ i 1))
2617 (if (= i vhdl-menu-max-size)
2618 (progn
2619 (push (cons (format "%s %s" title menuno)
2620 (nreverse sublist)) result)
2621 (setq i 0)
2622 (setq menuno (+ menuno 1))
2623 (setq sublist '()))))
2624 (and sublist
2625 (push (cons (format "%s %s" title menuno)
2626 (nreverse sublist)) result))
2627 (nreverse result))
2628 list))
2631 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2632 ;;; Bindings
2633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2635 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2636 ;; Key bindings
2638 (defvar vhdl-template-map nil
2639 "Keymap for VHDL templates.")
2641 (defun vhdl-template-map-init ()
2642 "Initialize `vhdl-template-map'."
2643 (setq vhdl-template-map (make-sparse-keymap))
2644 ;; key bindings for VHDL templates
2645 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2646 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2647 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2648 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2649 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2650 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2651 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2652 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2653 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2654 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2655 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2656 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2657 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2658 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2659 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2660 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2661 (define-key vhdl-template-map "el" 'vhdl-template-else)
2662 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2663 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2664 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2665 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2666 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2667 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2668 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2669 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2670 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2671 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2672 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2673 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2674 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2675 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2676 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2677 (define-key vhdl-template-map "li" 'vhdl-template-library)
2678 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2679 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2680 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2681 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2682 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2683 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2684 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2685 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2686 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2687 (define-key vhdl-template-map "po" 'vhdl-template-port)
2688 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2689 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2690 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2691 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2692 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2693 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2694 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2695 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2696 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2697 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2698 (define-key vhdl-template-map "us" 'vhdl-template-use)
2699 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2700 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2701 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2702 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2703 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2704 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2705 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2706 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2707 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2708 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2709 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2710 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2711 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2712 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2713 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2714 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2715 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2716 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2717 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2718 (when (vhdl-standard-p 'ams)
2719 (define-key vhdl-template-map "br" 'vhdl-template-break)
2720 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2721 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2722 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2723 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2724 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2725 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2726 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2727 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2728 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2729 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2731 (when (vhdl-standard-p 'math)
2732 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2733 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2736 ;; initialize template map for VHDL Mode
2737 (vhdl-template-map-init)
2739 (defun vhdl-function-name (prefix string &optional postfix)
2740 "Generate a Lisp function name.
2741 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2742 STRING are replaced by `-' and substrings are converted to lower case."
2743 (let ((name prefix))
2744 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2745 (setq name
2746 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2747 (setq string (substring string (match-beginning 2))))
2748 (when postfix (setq name (concat name "-" postfix)))
2749 (intern name)))
2751 (defvar vhdl-model-map nil
2752 "Keymap for VHDL models.")
2754 (defun vhdl-model-map-init ()
2755 "Initialize `vhdl-model-map'."
2756 (setq vhdl-model-map (make-sparse-keymap))
2757 ;; key bindings for VHDL models
2758 (let ((model-alist vhdl-model-alist) model)
2759 (while model-alist
2760 (setq model (car model-alist))
2761 (define-key vhdl-model-map (nth 2 model)
2762 (vhdl-function-name "vhdl-model" (nth 0 model)))
2763 (setq model-alist (cdr model-alist)))))
2765 ;; initialize user model map for VHDL Mode
2766 (vhdl-model-map-init)
2768 (defvar vhdl-mode-map nil
2769 "Keymap for VHDL Mode.")
2771 (defun vhdl-mode-map-init ()
2772 "Initialize `vhdl-mode-map'."
2773 (setq vhdl-mode-map (make-sparse-keymap))
2774 ;; template key bindings
2775 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2776 ;; model key bindings
2777 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2778 ;; standard key bindings
2779 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2780 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2781 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2782 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2783 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2784 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2785 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2786 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2787 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2788 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2789 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2790 ;; mode specific key bindings
2791 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2792 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2793 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2794 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2795 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2796 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2797 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2798 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2799 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2800 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2801 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2802 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2803 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2804 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2805 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2806 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2807 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2808 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2809 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2810 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2811 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2812 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2813 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2814 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2815 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2816 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2817 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2818 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2819 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2820 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2821 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2822 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2823 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2824 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2825 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2826 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2827 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2828 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2829 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2830 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2831 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2832 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2833 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2834 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2835 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2836 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2837 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2838 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2839 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2840 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2841 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2842 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2843 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2844 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2845 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2846 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2847 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2848 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2849 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2850 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2851 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2852 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2853 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2854 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2855 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2856 (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
2857 (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
2858 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2859 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2860 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2861 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2862 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2863 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2864 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2865 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2866 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2867 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2868 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2869 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2870 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2871 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2872 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2873 ;; insert commands bindings
2874 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2875 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2876 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2877 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2878 ;; electric key bindings
2879 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2880 (when vhdl-intelligent-tab
2881 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2882 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2883 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2884 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2885 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2886 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2887 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2888 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2889 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2890 (when (vhdl-standard-p 'ams)
2891 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2893 ;; initialize mode map for VHDL Mode
2894 (vhdl-mode-map-init)
2896 ;; define special minibuffer keymap for enabling word completion in minibuffer
2897 ;; (useful in template generator prompts)
2898 (defvar vhdl-minibuffer-local-map
2899 (let ((map (make-sparse-keymap)))
2900 (set-keymap-parent map minibuffer-local-map)
2901 (when vhdl-word-completion-in-minibuffer
2902 (define-key map "\t" 'vhdl-minibuffer-tab))
2903 map)
2904 "Keymap for minibuffer used in VHDL Mode.")
2906 ;; set up electric character functions to work with
2907 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2908 (mapc
2909 (function
2910 (lambda (sym)
2911 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2912 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2913 '(vhdl-electric-space
2914 vhdl-electric-tab
2915 vhdl-electric-return
2916 vhdl-electric-dash
2917 vhdl-electric-open-bracket
2918 vhdl-electric-close-bracket
2919 vhdl-electric-quote
2920 vhdl-electric-semicolon
2921 vhdl-electric-comma
2922 vhdl-electric-period
2923 vhdl-electric-equal))
2925 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2926 ;; Syntax table
2928 (defvar vhdl-mode-syntax-table
2929 (let ((st (make-syntax-table)))
2930 ;; define punctuation
2931 (modify-syntax-entry ?\# "." st)
2932 (modify-syntax-entry ?\$ "." st)
2933 (modify-syntax-entry ?\% "." st)
2934 (modify-syntax-entry ?\& "." st)
2935 (modify-syntax-entry ?\' "." st)
2936 (modify-syntax-entry ?\* "." st)
2937 (modify-syntax-entry ?\+ "." st)
2938 (modify-syntax-entry ?\. "." st)
2939 (modify-syntax-entry ?\/ "." st)
2940 (modify-syntax-entry ?\: "." st)
2941 (modify-syntax-entry ?\; "." st)
2942 (modify-syntax-entry ?\< "." st)
2943 (modify-syntax-entry ?\= "." st)
2944 (modify-syntax-entry ?\> "." st)
2945 (modify-syntax-entry ?\\ "." st)
2946 (modify-syntax-entry ?\| "." st)
2947 ;; define string
2948 (modify-syntax-entry ?\" "\"" st)
2949 ;; define underscore
2950 (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
2951 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2952 (modify-syntax-entry ?\- ". 12" st)
2953 ;; and \n and \^M end a comment
2954 (modify-syntax-entry ?\n ">" st)
2955 (modify-syntax-entry ?\^M ">" st)
2956 ;; define parentheses to match
2957 (modify-syntax-entry ?\( "()" st)
2958 (modify-syntax-entry ?\) ")(" st)
2959 (modify-syntax-entry ?\[ "(]" st)
2960 (modify-syntax-entry ?\] ")[" st)
2961 (modify-syntax-entry ?\{ "(}" st)
2962 (modify-syntax-entry ?\} "){" st)
2964 "Syntax table used in `vhdl-mode' buffers.")
2966 (defvar vhdl-mode-ext-syntax-table
2967 ;; Extended syntax table including '_' (for simpler search regexps).
2968 (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
2969 (modify-syntax-entry ?_ "w" st)
2971 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2973 (defvar vhdl-syntactic-context nil
2974 "Buffer local variable containing syntactic analysis list.")
2975 (make-variable-buffer-local 'vhdl-syntactic-context)
2977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2978 ;; Abbrev ook bindings
2980 (defvar vhdl-mode-abbrev-table nil
2981 "Abbrev table to use in `vhdl-mode' buffers.")
2983 (defun vhdl-mode-abbrev-table-init ()
2984 "Initialize `vhdl-mode-abbrev-table'."
2985 (define-abbrev-table 'vhdl-mode-abbrev-table
2986 (append
2987 (when (memq 'vhdl vhdl-electric-keywords)
2988 ;; VHDL'93 keywords
2989 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2991 ("--" . vhdl-template-display-comment-hook)
2992 ("abs" . vhdl-template-default-hook)
2993 ("access" . vhdl-template-default-hook)
2994 ("after" . vhdl-template-default-hook)
2995 ("alias" . vhdl-template-alias-hook)
2996 ("all" . vhdl-template-default-hook)
2997 ("and" . vhdl-template-default-hook)
2998 ("arch" . vhdl-template-architecture-hook)
2999 ("architecture" . vhdl-template-architecture-hook)
3000 ("array" . vhdl-template-default-hook)
3001 ("assert" . vhdl-template-assert-hook)
3002 ("attr" . vhdl-template-attribute-hook)
3003 ("attribute" . vhdl-template-attribute-hook)
3004 ("begin" . vhdl-template-default-indent-hook)
3005 ("block" . vhdl-template-block-hook)
3006 ("body" . vhdl-template-default-hook)
3007 ("buffer" . vhdl-template-default-hook)
3008 ("bus" . vhdl-template-default-hook)
3009 ("case" . vhdl-template-case-hook)
3010 ("comp" . vhdl-template-component-hook)
3011 ("component" . vhdl-template-component-hook)
3012 ("cond" . vhdl-template-conditional-signal-asst-hook)
3013 ("conditional" . vhdl-template-conditional-signal-asst-hook)
3014 ("conf" . vhdl-template-configuration-hook)
3015 ("configuration" . vhdl-template-configuration-hook)
3016 ("cons" . vhdl-template-constant-hook)
3017 ("constant" . vhdl-template-constant-hook)
3018 ("disconnect" . vhdl-template-disconnect-hook)
3019 ("downto" . vhdl-template-default-hook)
3020 ("else" . vhdl-template-else-hook)
3021 ("elseif" . vhdl-template-elsif-hook)
3022 ("elsif" . vhdl-template-elsif-hook)
3023 ("end" . vhdl-template-default-indent-hook)
3024 ("entity" . vhdl-template-entity-hook)
3025 ("exit" . vhdl-template-exit-hook)
3026 ("file" . vhdl-template-file-hook)
3027 ("for" . vhdl-template-for-hook)
3028 ("func" . vhdl-template-function-hook)
3029 ("function" . vhdl-template-function-hook)
3030 ("generic" . vhdl-template-generic-hook)
3031 ("group" . vhdl-template-group-hook)
3032 ("guarded" . vhdl-template-default-hook)
3033 ("if" . vhdl-template-if-hook)
3034 ("impure" . vhdl-template-default-hook)
3035 ("in" . vhdl-template-default-hook)
3036 ("inertial" . vhdl-template-default-hook)
3037 ("inout" . vhdl-template-default-hook)
3038 ("inst" . vhdl-template-instance-hook)
3039 ("instance" . vhdl-template-instance-hook)
3040 ("is" . vhdl-template-default-hook)
3041 ("label" . vhdl-template-default-hook)
3042 ("library" . vhdl-template-library-hook)
3043 ("linkage" . vhdl-template-default-hook)
3044 ("literal" . vhdl-template-default-hook)
3045 ("loop" . vhdl-template-bare-loop-hook)
3046 ("map" . vhdl-template-map-hook)
3047 ("mod" . vhdl-template-default-hook)
3048 ("nand" . vhdl-template-default-hook)
3049 ("new" . vhdl-template-default-hook)
3050 ("next" . vhdl-template-next-hook)
3051 ("nor" . vhdl-template-default-hook)
3052 ("not" . vhdl-template-default-hook)
3053 ("null" . vhdl-template-default-hook)
3054 ("of" . vhdl-template-default-hook)
3055 ("on" . vhdl-template-default-hook)
3056 ("open" . vhdl-template-default-hook)
3057 ("or" . vhdl-template-default-hook)
3058 ("others" . vhdl-template-others-hook)
3059 ("out" . vhdl-template-default-hook)
3060 ("pack" . vhdl-template-package-hook)
3061 ("package" . vhdl-template-package-hook)
3062 ("port" . vhdl-template-port-hook)
3063 ("postponed" . vhdl-template-default-hook)
3064 ("procedure" . vhdl-template-procedure-hook)
3065 ("process" . vhdl-template-process-hook)
3066 ("pure" . vhdl-template-default-hook)
3067 ("range" . vhdl-template-default-hook)
3068 ("record" . vhdl-template-default-hook)
3069 ("register" . vhdl-template-default-hook)
3070 ("reject" . vhdl-template-default-hook)
3071 ("rem" . vhdl-template-default-hook)
3072 ("report" . vhdl-template-report-hook)
3073 ("return" . vhdl-template-return-hook)
3074 ("rol" . vhdl-template-default-hook)
3075 ("ror" . vhdl-template-default-hook)
3076 ("select" . vhdl-template-selected-signal-asst-hook)
3077 ("severity" . vhdl-template-default-hook)
3078 ("shared" . vhdl-template-default-hook)
3079 ("sig" . vhdl-template-signal-hook)
3080 ("signal" . vhdl-template-signal-hook)
3081 ("sla" . vhdl-template-default-hook)
3082 ("sll" . vhdl-template-default-hook)
3083 ("sra" . vhdl-template-default-hook)
3084 ("srl" . vhdl-template-default-hook)
3085 ("subtype" . vhdl-template-subtype-hook)
3086 ("then" . vhdl-template-default-hook)
3087 ("to" . vhdl-template-default-hook)
3088 ("transport" . vhdl-template-default-hook)
3089 ("type" . vhdl-template-type-hook)
3090 ("unaffected" . vhdl-template-default-hook)
3091 ("units" . vhdl-template-default-hook)
3092 ("until" . vhdl-template-default-hook)
3093 ("use" . vhdl-template-use-hook)
3094 ("var" . vhdl-template-variable-hook)
3095 ("variable" . vhdl-template-variable-hook)
3096 ("wait" . vhdl-template-wait-hook)
3097 ("when" . vhdl-template-when-hook)
3098 ("while" . vhdl-template-while-loop-hook)
3099 ("with" . vhdl-template-with-hook)
3100 ("xnor" . vhdl-template-default-hook)
3101 ("xor" . vhdl-template-default-hook)
3103 ;; VHDL-AMS keywords
3104 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3105 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
3107 ("across" . vhdl-template-default-hook)
3108 ("break" . vhdl-template-break-hook)
3109 ("limit" . vhdl-template-limit-hook)
3110 ("nature" . vhdl-template-nature-hook)
3111 ("noise" . vhdl-template-default-hook)
3112 ("procedural" . vhdl-template-procedural-hook)
3113 ("quantity" . vhdl-template-quantity-hook)
3114 ("reference" . vhdl-template-default-hook)
3115 ("spectrum" . vhdl-template-default-hook)
3116 ("subnature" . vhdl-template-subnature-hook)
3117 ("terminal" . vhdl-template-terminal-hook)
3118 ("through" . vhdl-template-default-hook)
3119 ("tolerance" . vhdl-template-default-hook)
3121 ;; user model keywords
3122 (when (memq 'user vhdl-electric-keywords)
3123 (let (abbrev-list keyword)
3124 (dolist (elem vhdl-model-alist)
3125 (setq keyword (nth 3 elem))
3126 (unless (equal keyword "")
3127 (push (list keyword ""
3128 (vhdl-function-name
3129 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3130 abbrev-list)))
3131 abbrev-list)))))
3133 ;; initialize abbrev table for VHDL Mode
3134 (vhdl-mode-abbrev-table-init)
3136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3137 ;; Template completion lists
3139 (defvar vhdl-template-construct-alist nil
3140 "List of built-in construct templates.")
3142 (defun vhdl-template-construct-alist-init ()
3143 "Initialize `vhdl-template-construct-alist'."
3144 (setq
3145 vhdl-template-construct-alist
3146 (append
3148 ("alias declaration" vhdl-template-alias)
3149 ("architecture body" vhdl-template-architecture)
3150 ("assertion" vhdl-template-assert)
3151 ("attribute declaration" vhdl-template-attribute-decl)
3152 ("attribute specification" vhdl-template-attribute-spec)
3153 ("block configuration" vhdl-template-block-configuration)
3154 ("block statement" vhdl-template-block)
3155 ("case statement" vhdl-template-case-is)
3156 ("component configuration" vhdl-template-component-conf)
3157 ("component declaration" vhdl-template-component-decl)
3158 ("component instantiation statement" vhdl-template-component-inst)
3159 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3160 ("configuration declaration" vhdl-template-configuration-decl)
3161 ("configuration specification" vhdl-template-configuration-spec)
3162 ("constant declaration" vhdl-template-constant)
3163 ("disconnection specification" vhdl-template-disconnect)
3164 ("entity declaration" vhdl-template-entity)
3165 ("exit statement" vhdl-template-exit)
3166 ("file declaration" vhdl-template-file)
3167 ("generate statement" vhdl-template-generate)
3168 ("generic clause" vhdl-template-generic)
3169 ("group declaration" vhdl-template-group-decl)
3170 ("group template declaration" vhdl-template-group-template)
3171 ("if statement" vhdl-template-if-then)
3172 ("library clause" vhdl-template-library)
3173 ("loop statement" vhdl-template-loop)
3174 ("next statement" vhdl-template-next)
3175 ("package declaration" vhdl-template-package-decl)
3176 ("package body" vhdl-template-package-body)
3177 ("port clause" vhdl-template-port)
3178 ("process statement" vhdl-template-process)
3179 ("report statement" vhdl-template-report)
3180 ("return statement" vhdl-template-return)
3181 ("selected signal assignment" vhdl-template-selected-signal-asst)
3182 ("signal declaration" vhdl-template-signal)
3183 ("subprogram declaration" vhdl-template-subprogram-decl)
3184 ("subprogram body" vhdl-template-subprogram-body)
3185 ("subtype declaration" vhdl-template-subtype)
3186 ("type declaration" vhdl-template-type)
3187 ("use clause" vhdl-template-use)
3188 ("variable declaration" vhdl-template-variable)
3189 ("wait statement" vhdl-template-wait)
3191 (when (vhdl-standard-p 'ams)
3193 ("break statement" vhdl-template-break)
3194 ("nature declaration" vhdl-template-nature)
3195 ("quantity declaration" vhdl-template-quantity)
3196 ("simultaneous case statement" vhdl-template-case-use)
3197 ("simultaneous if statement" vhdl-template-if-use)
3198 ("simultaneous procedural statement" vhdl-template-procedural)
3199 ("step limit specification" vhdl-template-limit)
3200 ("subnature declaration" vhdl-template-subnature)
3201 ("terminal declaration" vhdl-template-terminal)
3202 )))))
3204 ;; initialize for VHDL Mode
3205 (vhdl-template-construct-alist-init)
3207 (defvar vhdl-template-package-alist nil
3208 "List of built-in package templates.")
3210 (defun vhdl-template-package-alist-init ()
3211 "Initialize `vhdl-template-package-alist'."
3212 (setq
3213 vhdl-template-package-alist
3214 (append
3216 ("numeric_bit" vhdl-template-package-numeric-bit)
3217 ("numeric_std" vhdl-template-package-numeric-std)
3218 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3219 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3220 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3221 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3222 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3223 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3224 ("textio" vhdl-template-package-textio)
3226 (when (vhdl-standard-p 'math)
3228 ("math_complex" vhdl-template-package-math-complex)
3229 ("math_real" vhdl-template-package-math-real)
3230 )))))
3232 ;; initialize for VHDL Mode
3233 (vhdl-template-package-alist-init)
3235 (defvar vhdl-template-directive-alist
3237 ("translate_on" vhdl-template-directive-translate-on)
3238 ("translate_off" vhdl-template-directive-translate-off)
3239 ("synthesis_on" vhdl-template-directive-synthesis-on)
3240 ("synthesis_off" vhdl-template-directive-synthesis-off)
3242 "List of built-in directive templates.")
3245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3246 ;;; Menus
3247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3250 ;; VHDL menu (using `easy-menu.el')
3252 (defun vhdl-customize ()
3253 "Call the customize function with `vhdl' as argument."
3254 (interactive)
3255 (customize-browse 'vhdl))
3257 (defun vhdl-create-mode-menu ()
3258 "Create VHDL Mode menu."
3259 `("VHDL"
3260 ,(append
3261 '("Project"
3262 ["None" (vhdl-set-project "")
3263 :style radio :selected (null vhdl-project)]
3264 "--")
3265 ;; add menu entries for defined projects
3266 (let ((project-alist vhdl-project-alist) menu-list name)
3267 (while project-alist
3268 (setq name (caar project-alist))
3269 (setq menu-list
3270 (cons `[,name (vhdl-set-project ,name)
3271 :style radio :selected (equal ,name vhdl-project)]
3272 menu-list))
3273 (setq project-alist (cdr project-alist)))
3274 (setq menu-list
3275 (if vhdl-project-sort
3276 (sort menu-list
3277 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3278 (nreverse menu-list)))
3279 (vhdl-menu-split menu-list "Project"))
3280 '("--" "--"
3281 ["Select Project..." vhdl-set-project t]
3282 ["Set As Default Project" vhdl-set-default-project t]
3283 "--"
3284 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3285 ["Import Project..." vhdl-import-project
3286 :keys "C-c C-p C-m" :active t]
3287 ["Export Project" vhdl-export-project vhdl-project]
3288 "--"
3289 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3290 "--"
3291 ("Compile"
3292 ["Compile Buffer" vhdl-compile t]
3293 ["Stop Compilation" kill-compilation t]
3294 "--"
3295 ["Make" vhdl-make t]
3296 ["Generate Makefile" vhdl-generate-makefile t]
3297 "--"
3298 ["Next Error" next-error t]
3299 ["Previous Error" previous-error t]
3300 ["First Error" first-error t]
3301 "--"
3302 ,(append
3303 '("Compiler")
3304 ;; add menu entries for defined compilers
3305 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3306 (while comp-alist
3307 (setq name (caar comp-alist))
3308 (setq menu-list
3309 (cons `[,name (setq vhdl-compiler ,name)
3310 :style radio :selected (equal ,name vhdl-compiler)]
3311 menu-list))
3312 (setq comp-alist (cdr comp-alist)))
3313 (setq menu-list (nreverse menu-list))
3314 (vhdl-menu-split menu-list "Compiler"))
3315 '("--" "--"
3316 ["Select Compiler..." vhdl-set-compiler t]
3317 "--"
3318 ["Customize Compiler..."
3319 (customize-option 'vhdl-compiler-alist) t])))
3320 "--"
3321 ,(append
3322 '("Template"
3323 ("VHDL Construct 1"
3324 ["Alias" vhdl-template-alias t]
3325 ["Architecture" vhdl-template-architecture t]
3326 ["Assert" vhdl-template-assert t]
3327 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3328 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3329 ["Block" vhdl-template-block t]
3330 ["Case" vhdl-template-case-is t]
3331 ["Component (Decl)" vhdl-template-component-decl t]
3332 ["(Component) Instance" vhdl-template-component-inst t]
3333 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3334 ["Configuration (Block)" vhdl-template-block-configuration t]
3335 ["Configuration (Comp)" vhdl-template-component-conf t]
3336 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3337 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3338 ["Constant" vhdl-template-constant t]
3339 ["Disconnect" vhdl-template-disconnect t]
3340 ["Else" vhdl-template-else t]
3341 ["Elsif" vhdl-template-elsif t]
3342 ["Entity" vhdl-template-entity t]
3343 ["Exit" vhdl-template-exit t]
3344 ["File" vhdl-template-file t]
3345 ["For (Generate)" vhdl-template-for-generate t]
3346 ["For (Loop)" vhdl-template-for-loop t]
3347 ["Function (Body)" vhdl-template-function-body t]
3348 ["Function (Decl)" vhdl-template-function-decl t]
3349 ["Generic" vhdl-template-generic t]
3350 ["Group (Decl)" vhdl-template-group-decl t]
3351 ["Group (Template)" vhdl-template-group-template t])
3352 ("VHDL Construct 2"
3353 ["If (Generate)" vhdl-template-if-generate t]
3354 ["If (Then)" vhdl-template-if-then t]
3355 ["Library" vhdl-template-library t]
3356 ["Loop" vhdl-template-bare-loop t]
3357 ["Map" vhdl-template-map t]
3358 ["Next" vhdl-template-next t]
3359 ["Others (Aggregate)" vhdl-template-others t]
3360 ["Package (Decl)" vhdl-template-package-decl t]
3361 ["Package (Body)" vhdl-template-package-body t]
3362 ["Port" vhdl-template-port t]
3363 ["Procedure (Body)" vhdl-template-procedure-body t]
3364 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3365 ["Process (Comb)" vhdl-template-process-comb t]
3366 ["Process (Seq)" vhdl-template-process-seq t]
3367 ["Report" vhdl-template-report t]
3368 ["Return" vhdl-template-return t]
3369 ["Select" vhdl-template-selected-signal-asst t]
3370 ["Signal" vhdl-template-signal t]
3371 ["Subtype" vhdl-template-subtype t]
3372 ["Type" vhdl-template-type t]
3373 ["Use" vhdl-template-use t]
3374 ["Variable" vhdl-template-variable t]
3375 ["Wait" vhdl-template-wait t]
3376 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3377 ["When" vhdl-template-when t]
3378 ["While (Loop)" vhdl-template-while-loop t]
3379 ["With" vhdl-template-with t]))
3380 (when (vhdl-standard-p 'ams)
3381 '(("VHDL-AMS Construct"
3382 ["Break" vhdl-template-break t]
3383 ["Case (Use)" vhdl-template-case-use t]
3384 ["If (Use)" vhdl-template-if-use t]
3385 ["Limit" vhdl-template-limit t]
3386 ["Nature" vhdl-template-nature t]
3387 ["Procedural" vhdl-template-procedural t]
3388 ["Quantity (Free)" vhdl-template-quantity-free t]
3389 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3390 ["Quantity (Source)" vhdl-template-quantity-source t]
3391 ["Subnature" vhdl-template-subnature t]
3392 ["Terminal" vhdl-template-terminal t])))
3393 '(["Insert Construct..." vhdl-template-insert-construct
3394 :keys "C-c C-i C-t"]
3395 "--")
3396 (list
3397 (append
3398 '("Package")
3399 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3400 ["numeric_std" vhdl-template-package-numeric-std t]
3401 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3402 ["textio" vhdl-template-package-textio t]
3403 "--"
3404 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3405 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3406 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3407 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3408 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3409 "--")
3410 (when (vhdl-standard-p 'ams)
3411 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3412 ["material_constants" vhdl-template-package-material-constants t]
3413 ["energy_systems" vhdl-template-package-energy-systems t]
3414 ["electrical_systems" vhdl-template-package-electrical-systems t]
3415 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3416 ["radiant_systems" vhdl-template-package-radiant-systems t]
3417 ["thermal_systems" vhdl-template-package-thermal-systems t]
3418 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3419 "--"))
3420 (when (vhdl-standard-p 'math)
3421 '(["math_complex" vhdl-template-package-math-complex t]
3422 ["math_real" vhdl-template-package-math-real t]
3423 "--"))
3424 '(["Insert Package..." vhdl-template-insert-package
3425 :keys "C-c C-i C-p"])))
3426 '(("Directive"
3427 ["translate_on" vhdl-template-directive-translate-on t]
3428 ["translate_off" vhdl-template-directive-translate-off t]
3429 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3430 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3431 "--"
3432 ["Insert Directive..." vhdl-template-insert-directive
3433 :keys "C-c C-i C-d"])
3434 "--"
3435 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3436 ["Insert Footer" vhdl-template-footer t]
3437 ["Insert Date" vhdl-template-insert-date t]
3438 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3439 "--"
3440 ["Query Next Prompt" vhdl-template-search-prompt t]))
3441 ,(append
3442 '("Model")
3443 ;; add menu entries for defined models
3444 (let ((model-alist vhdl-model-alist) menu-list model)
3445 (while model-alist
3446 (setq model (car model-alist))
3447 (setq menu-list
3448 (cons
3449 (vector
3450 (nth 0 model)
3451 (vhdl-function-name "vhdl-model" (nth 0 model))
3452 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3453 menu-list))
3454 (setq model-alist (cdr model-alist)))
3455 (setq menu-list (nreverse menu-list))
3456 (vhdl-menu-split menu-list "Model"))
3457 '("--" "--"
3458 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3459 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3460 ("Port"
3461 ["Copy" vhdl-port-copy t]
3462 "--"
3463 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3464 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3465 ["Paste As Instance" vhdl-port-paste-instance
3466 :keys "C-c C-p C-i" :active vhdl-port-list]
3467 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3468 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3469 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3470 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3471 "--"
3472 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3473 "--"
3474 ["Flatten" vhdl-port-flatten
3475 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3476 ["Reverse Direction" vhdl-port-reverse-direction
3477 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3478 ("Compose"
3479 ["New Component" vhdl-compose-new-component t]
3480 ["Copy Component" vhdl-port-copy t]
3481 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3482 ["Wire Components" vhdl-compose-wire-components t]
3483 "--"
3484 ["Generate Configuration" vhdl-compose-configuration t]
3485 ["Generate Components Package" vhdl-compose-components-package t])
3486 ("Subprogram"
3487 ["Copy" vhdl-subprog-copy t]
3488 "--"
3489 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3490 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3491 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3492 "--"
3493 ["Flatten" vhdl-subprog-flatten
3494 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3495 "--"
3496 ("Comment"
3497 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3498 "--"
3499 ["Insert Inline Comment" vhdl-comment-append-inline t]
3500 ["Insert Horizontal Line" vhdl-comment-display-line t]
3501 ["Insert Display Comment" vhdl-comment-display t]
3502 "--"
3503 ["Fill Comment" fill-paragraph t]
3504 ["Fill Comment Region" fill-region (mark)]
3505 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3506 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3507 ("Line"
3508 ["Kill" vhdl-line-kill t]
3509 ["Copy" vhdl-line-copy t]
3510 ["Yank" vhdl-line-yank t]
3511 ["Expand" vhdl-line-expand t]
3512 "--"
3513 ["Transpose Next" vhdl-line-transpose-next t]
3514 ["Transpose Prev" vhdl-line-transpose-previous t]
3515 ["Open" vhdl-line-open t]
3516 ["Join" vhdl-delete-indentation t]
3517 "--"
3518 ["Goto" goto-line t]
3519 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3520 ("Move"
3521 ["Forward Statement" vhdl-end-of-statement t]
3522 ["Backward Statement" vhdl-beginning-of-statement t]
3523 ["Forward Expression" vhdl-forward-sexp t]
3524 ["Backward Expression" vhdl-backward-sexp t]
3525 ["Forward Same Indent" vhdl-forward-same-indent t]
3526 ["Backward Same Indent" vhdl-backward-same-indent t]
3527 ["Forward Function" vhdl-end-of-defun t]
3528 ["Backward Function" vhdl-beginning-of-defun t]
3529 ["Mark Function" vhdl-mark-defun t])
3530 "--"
3531 ("Indent"
3532 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3533 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3534 ["Region" vhdl-indent-region (mark)]
3535 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3536 ("Align"
3537 ["Group" vhdl-align-group t]
3538 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3539 ["List" vhdl-align-list t]
3540 ["Declarations" vhdl-align-declarations t]
3541 ["Region" vhdl-align-region (mark)]
3542 ["Buffer" vhdl-align-buffer t]
3543 "--"
3544 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3545 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3546 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3547 ("Fill"
3548 ["List" vhdl-fill-list t]
3549 ["Group" vhdl-fill-group t]
3550 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3551 ["Region" vhdl-fill-region (mark)])
3552 ("Beautify"
3553 ["Region" vhdl-beautify-region (mark)]
3554 ["Buffer" vhdl-beautify-buffer t])
3555 ("Fix"
3556 ["Generic/Port Clause" vhdl-fix-clause t]
3557 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3558 "--"
3559 ["Case Region" vhdl-fix-case-region (mark)]
3560 ["Case Buffer" vhdl-fix-case-buffer t]
3561 "--"
3562 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3563 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3564 "--"
3565 ["Statement Region" vhdl-fix-statement-region (mark)]
3566 ["Statement Buffer" vhdl-fix-statement-buffer t]
3567 "--"
3568 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3569 ("Update"
3570 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3571 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3572 "--"
3573 ["Fontify Buffer" vhdl-fontify-buffer t]
3574 ["Statistics Buffer" vhdl-statistics-buffer t]
3575 ["Show Messages" vhdl-show-messages t]
3576 ["Syntactic Info" vhdl-show-syntactic-information t]
3577 "--"
3578 ["Speedbar" vhdl-speedbar t]
3579 ["Hide/Show" vhdl-hs-minor-mode t]
3580 "--"
3581 ("Documentation"
3582 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3583 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3584 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3585 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3586 ["Version" vhdl-version t]
3587 ["Bug Report..." vhdl-submit-bug-report t]
3588 "--"
3589 ("Options"
3590 ("Mode"
3591 ["Electric Mode"
3592 (progn (customize-set-variable 'vhdl-electric-mode
3593 (not vhdl-electric-mode))
3594 (vhdl-mode-line-update))
3595 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3596 ["Stutter Mode"
3597 (progn (customize-set-variable 'vhdl-stutter-mode
3598 (not vhdl-stutter-mode))
3599 (vhdl-mode-line-update))
3600 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3601 ["Indent Tabs Mode"
3602 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3603 (not vhdl-indent-tabs-mode))
3604 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3605 :style toggle :selected vhdl-indent-tabs-mode]
3606 "--"
3607 ["Customize Group..." (customize-group 'vhdl-mode) t])
3608 ("Project"
3609 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3610 ,(append
3611 '("Selected Project at Startup"
3612 ["None" (progn (customize-set-variable 'vhdl-project nil)
3613 (vhdl-set-project ""))
3614 :style radio :selected (null vhdl-project)]
3615 "--")
3616 ;; add menu entries for defined projects
3617 (let ((project-alist vhdl-project-alist) menu-list name)
3618 (while project-alist
3619 (setq name (caar project-alist))
3620 (setq menu-list
3621 (cons `[,name (progn (customize-set-variable
3622 'vhdl-project ,name)
3623 (vhdl-set-project ,name))
3624 :style radio :selected (equal ,name vhdl-project)]
3625 menu-list))
3626 (setq project-alist (cdr project-alist)))
3627 (setq menu-list (nreverse menu-list))
3628 (vhdl-menu-split menu-list "Project")))
3629 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3630 ("Auto Load Setup File"
3631 ["At Startup"
3632 (customize-set-variable 'vhdl-project-auto-load
3633 (if (memq 'startup vhdl-project-auto-load)
3634 (delq 'startup vhdl-project-auto-load)
3635 (cons 'startup vhdl-project-auto-load)))
3636 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3637 ["Sort Projects"
3638 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3639 :style toggle :selected vhdl-project-sort]
3640 "--"
3641 ["Customize Group..." (customize-group 'vhdl-project) t])
3642 ("Compiler"
3643 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3644 ,(append
3645 '("Selected Compiler at Startup")
3646 ;; add menu entries for defined compilers
3647 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3648 (while comp-alist
3649 (setq name (caar comp-alist))
3650 (setq menu-list
3651 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3652 :style radio :selected (equal ,name vhdl-compiler)]
3653 menu-list))
3654 (setq comp-alist (cdr comp-alist)))
3655 (setq menu-list (nreverse menu-list))
3656 (vhdl-menu-split menu-list "Compiler")))
3657 ["Use Local Error Regexp"
3658 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3659 (not vhdl-compile-use-local-error-regexp))
3660 :style toggle :selected vhdl-compile-use-local-error-regexp]
3661 ["Makefile Default Targets..."
3662 (customize-option 'vhdl-makefile-default-targets) t]
3663 ["Makefile Generation Hook..."
3664 (customize-option 'vhdl-makefile-generation-hook) t]
3665 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3666 "--"
3667 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3668 ("Style"
3669 ("VHDL Standard"
3670 ["VHDL'87"
3671 (progn (customize-set-variable 'vhdl-standard
3672 (list '87 (cadr vhdl-standard)))
3673 (vhdl-activate-customizations))
3674 :style radio :selected (eq '87 (car vhdl-standard))]
3675 ["VHDL'93/02"
3676 (progn (customize-set-variable 'vhdl-standard
3677 (list '93 (cadr vhdl-standard)))
3678 (vhdl-activate-customizations))
3679 :style radio :selected (eq '93 (car vhdl-standard))]
3680 "--"
3681 ["VHDL-AMS"
3682 (progn (customize-set-variable
3683 'vhdl-standard (list (car vhdl-standard)
3684 (if (memq 'ams (cadr vhdl-standard))
3685 (delq 'ams (cadr vhdl-standard))
3686 (cons 'ams (cadr vhdl-standard)))))
3687 (vhdl-activate-customizations))
3688 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3689 ["Math Packages"
3690 (progn (customize-set-variable
3691 'vhdl-standard (list (car vhdl-standard)
3692 (if (memq 'math (cadr vhdl-standard))
3693 (delq 'math (cadr vhdl-standard))
3694 (cons 'math (cadr vhdl-standard)))))
3695 (vhdl-activate-customizations))
3696 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3697 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3698 ["Upper Case Keywords"
3699 (customize-set-variable 'vhdl-upper-case-keywords
3700 (not vhdl-upper-case-keywords))
3701 :style toggle :selected vhdl-upper-case-keywords]
3702 ["Upper Case Types"
3703 (customize-set-variable 'vhdl-upper-case-types
3704 (not vhdl-upper-case-types))
3705 :style toggle :selected vhdl-upper-case-types]
3706 ["Upper Case Attributes"
3707 (customize-set-variable 'vhdl-upper-case-attributes
3708 (not vhdl-upper-case-attributes))
3709 :style toggle :selected vhdl-upper-case-attributes]
3710 ["Upper Case Enumeration Values"
3711 (customize-set-variable 'vhdl-upper-case-enum-values
3712 (not vhdl-upper-case-enum-values))
3713 :style toggle :selected vhdl-upper-case-enum-values]
3714 ["Upper Case Constants"
3715 (customize-set-variable 'vhdl-upper-case-constants
3716 (not vhdl-upper-case-constants))
3717 :style toggle :selected vhdl-upper-case-constants]
3718 ("Use Direct Instantiation"
3719 ["Never"
3720 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3721 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3722 ["Standard"
3723 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3724 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3725 ["Always"
3726 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3727 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3728 ["Include Array Index and Record Field in Sensitivity List"
3729 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3730 (not vhdl-array-index-record-field-in-sensitivity-list))
3731 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3732 "--"
3733 ["Customize Group..." (customize-group 'vhdl-style) t])
3734 ("Naming"
3735 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3736 ["Architecture File Name..."
3737 (customize-option 'vhdl-architecture-file-name) t]
3738 ["Configuration File Name..."
3739 (customize-option 'vhdl-configuration-file-name) t]
3740 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3741 ("File Name Case"
3742 ["As Is"
3743 (customize-set-variable 'vhdl-file-name-case 'identity)
3744 :style radio :selected (eq 'identity vhdl-file-name-case)]
3745 ["Lower Case"
3746 (customize-set-variable 'vhdl-file-name-case 'downcase)
3747 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3748 ["Upper Case"
3749 (customize-set-variable 'vhdl-file-name-case 'upcase)
3750 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3751 ["Capitalize"
3752 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3753 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3754 "--"
3755 ["Customize Group..." (customize-group 'vhdl-naming) t])
3756 ("Template"
3757 ("Electric Keywords"
3758 ["VHDL Keywords"
3759 (customize-set-variable 'vhdl-electric-keywords
3760 (if (memq 'vhdl vhdl-electric-keywords)
3761 (delq 'vhdl vhdl-electric-keywords)
3762 (cons 'vhdl vhdl-electric-keywords)))
3763 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3764 ["User Model Keywords"
3765 (customize-set-variable 'vhdl-electric-keywords
3766 (if (memq 'user vhdl-electric-keywords)
3767 (delq 'user vhdl-electric-keywords)
3768 (cons 'user vhdl-electric-keywords)))
3769 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3770 ("Insert Optional Labels"
3771 ["None"
3772 (customize-set-variable 'vhdl-optional-labels 'none)
3773 :style radio :selected (eq 'none vhdl-optional-labels)]
3774 ["Processes Only"
3775 (customize-set-variable 'vhdl-optional-labels 'process)
3776 :style radio :selected (eq 'process vhdl-optional-labels)]
3777 ["All Constructs"
3778 (customize-set-variable 'vhdl-optional-labels 'all)
3779 :style radio :selected (eq 'all vhdl-optional-labels)])
3780 ("Insert Empty Lines"
3781 ["None"
3782 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3783 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3784 ["Design Units Only"
3785 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3786 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3787 ["All Constructs"
3788 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3789 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3790 ["Argument List Indent"
3791 (customize-set-variable 'vhdl-argument-list-indent
3792 (not vhdl-argument-list-indent))
3793 :style toggle :selected vhdl-argument-list-indent]
3794 ["Association List with Formals"
3795 (customize-set-variable 'vhdl-association-list-with-formals
3796 (not vhdl-association-list-with-formals))
3797 :style toggle :selected vhdl-association-list-with-formals]
3798 ["Conditions in Parenthesis"
3799 (customize-set-variable 'vhdl-conditions-in-parenthesis
3800 (not vhdl-conditions-in-parenthesis))
3801 :style toggle :selected vhdl-conditions-in-parenthesis]
3802 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3803 ["One String..." (customize-option 'vhdl-one-string) t]
3804 ("File Header"
3805 ["Header String..." (customize-option 'vhdl-file-header) t]
3806 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3807 ["Company Name..." (customize-option 'vhdl-company-name) t]
3808 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3809 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3810 ["Date Format..." (customize-option 'vhdl-date-format) t]
3811 ["Modify Date Prefix String..."
3812 (customize-option 'vhdl-modify-date-prefix-string) t]
3813 ["Modify Date on Saving"
3814 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3815 (not vhdl-modify-date-on-saving))
3816 (vhdl-activate-customizations))
3817 :style toggle :selected vhdl-modify-date-on-saving])
3818 ("Sequential Process"
3819 ("Kind of Reset"
3820 ["None"
3821 (customize-set-variable 'vhdl-reset-kind 'none)
3822 :style radio :selected (eq 'none vhdl-reset-kind)]
3823 ["Synchronous"
3824 (customize-set-variable 'vhdl-reset-kind 'sync)
3825 :style radio :selected (eq 'sync vhdl-reset-kind)]
3826 ["Asynchronous"
3827 (customize-set-variable 'vhdl-reset-kind 'async)
3828 :style radio :selected (eq 'async vhdl-reset-kind)]
3829 ["Query"
3830 (customize-set-variable 'vhdl-reset-kind 'query)
3831 :style radio :selected (eq 'query vhdl-reset-kind)])
3832 ["Reset is Active High"
3833 (customize-set-variable 'vhdl-reset-active-high
3834 (not vhdl-reset-active-high))
3835 :style toggle :selected vhdl-reset-active-high]
3836 ["Use Rising Clock Edge"
3837 (customize-set-variable 'vhdl-clock-rising-edge
3838 (not vhdl-clock-rising-edge))
3839 :style toggle :selected vhdl-clock-rising-edge]
3840 ("Clock Edge Condition"
3841 ["Standard"
3842 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3843 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3844 ["Function \"rising_edge\""
3845 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3846 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3847 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3848 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3849 "--"
3850 ["Customize Group..." (customize-group 'vhdl-template) t])
3851 ("Model"
3852 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3853 ("Port"
3854 ["Include Port Comments"
3855 (customize-set-variable 'vhdl-include-port-comments
3856 (not vhdl-include-port-comments))
3857 :style toggle :selected vhdl-include-port-comments]
3858 ["Include Direction Comments"
3859 (customize-set-variable 'vhdl-include-direction-comments
3860 (not vhdl-include-direction-comments))
3861 :style toggle :selected vhdl-include-direction-comments]
3862 ["Include Type Comments"
3863 (customize-set-variable 'vhdl-include-type-comments
3864 (not vhdl-include-type-comments))
3865 :style toggle :selected vhdl-include-type-comments]
3866 ("Include Group Comments"
3867 ["Never"
3868 (customize-set-variable 'vhdl-include-group-comments 'never)
3869 :style radio :selected (eq 'never vhdl-include-group-comments)]
3870 ["Declarations"
3871 (customize-set-variable 'vhdl-include-group-comments 'decl)
3872 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3873 ["Always"
3874 (customize-set-variable 'vhdl-include-group-comments 'always)
3875 :style radio :selected (eq 'always vhdl-include-group-comments)])
3876 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
3877 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3878 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3879 ("Testbench"
3880 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3881 ["Architecture Name..."
3882 (customize-option 'vhdl-testbench-architecture-name) t]
3883 ["Configuration Name..."
3884 (customize-option 'vhdl-testbench-configuration-name) t]
3885 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3886 ["Include Header"
3887 (customize-set-variable 'vhdl-testbench-include-header
3888 (not vhdl-testbench-include-header))
3889 :style toggle :selected vhdl-testbench-include-header]
3890 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3891 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3892 ["Initialize Signals"
3893 (customize-set-variable 'vhdl-testbench-initialize-signals
3894 (not vhdl-testbench-initialize-signals))
3895 :style toggle :selected vhdl-testbench-initialize-signals]
3896 ["Include Library Clause"
3897 (customize-set-variable 'vhdl-testbench-include-library
3898 (not vhdl-testbench-include-library))
3899 :style toggle :selected vhdl-testbench-include-library]
3900 ["Include Configuration"
3901 (customize-set-variable 'vhdl-testbench-include-configuration
3902 (not vhdl-testbench-include-configuration))
3903 :style toggle :selected vhdl-testbench-include-configuration]
3904 ("Create Files"
3905 ["None"
3906 (customize-set-variable 'vhdl-testbench-create-files 'none)
3907 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3908 ["Single"
3909 (customize-set-variable 'vhdl-testbench-create-files 'single)
3910 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3911 ["Separate"
3912 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3913 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3914 ["Testbench Entity File Name..."
3915 (customize-option 'vhdl-testbench-entity-file-name) t]
3916 ["Testbench Architecture File Name..."
3917 (customize-option 'vhdl-testbench-architecture-file-name) t])
3918 "--"
3919 ["Customize Group..." (customize-group 'vhdl-port) t])
3920 ("Compose"
3921 ["Architecture Name..."
3922 (customize-option 'vhdl-compose-architecture-name) t]
3923 ["Configuration Name..."
3924 (customize-option 'vhdl-compose-configuration-name) t]
3925 ["Components Package Name..."
3926 (customize-option 'vhdl-components-package-name) t]
3927 ["Use Components Package"
3928 (customize-set-variable 'vhdl-use-components-package
3929 (not vhdl-use-components-package))
3930 :style toggle :selected vhdl-use-components-package]
3931 ["Include Header"
3932 (customize-set-variable 'vhdl-compose-include-header
3933 (not vhdl-compose-include-header))
3934 :style toggle :selected vhdl-compose-include-header]
3935 ("Create Entity/Architecture Files"
3936 ["None"
3937 (customize-set-variable 'vhdl-compose-create-files 'none)
3938 :style radio :selected (eq 'none vhdl-compose-create-files)]
3939 ["Single"
3940 (customize-set-variable 'vhdl-compose-create-files 'single)
3941 :style radio :selected (eq 'single vhdl-compose-create-files)]
3942 ["Separate"
3943 (customize-set-variable 'vhdl-compose-create-files 'separate)
3944 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3945 ["Create Configuration File"
3946 (customize-set-variable 'vhdl-compose-configuration-create-file
3947 (not vhdl-compose-configuration-create-file))
3948 :style toggle :selected vhdl-compose-configuration-create-file]
3949 ["Hierarchical Configuration"
3950 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3951 (not vhdl-compose-configuration-hierarchical))
3952 :style toggle :selected vhdl-compose-configuration-hierarchical]
3953 ["Use Subconfiguration"
3954 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3955 (not vhdl-compose-configuration-use-subconfiguration))
3956 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3957 "--"
3958 ["Customize Group..." (customize-group 'vhdl-compose) t])
3959 ("Comment"
3960 ["Self Insert Comments"
3961 (customize-set-variable 'vhdl-self-insert-comments
3962 (not vhdl-self-insert-comments))
3963 :style toggle :selected vhdl-self-insert-comments]
3964 ["Prompt for Comments"
3965 (customize-set-variable 'vhdl-prompt-for-comments
3966 (not vhdl-prompt-for-comments))
3967 :style toggle :selected vhdl-prompt-for-comments]
3968 ["Inline Comment Column..."
3969 (customize-option 'vhdl-inline-comment-column) t]
3970 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3971 "--"
3972 ["Customize Group..." (customize-group 'vhdl-comment) t])
3973 ("Beautify"
3974 ["Auto Align Templates"
3975 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3976 :style toggle :selected vhdl-auto-align]
3977 ["Align Line Groups"
3978 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3979 :style toggle :selected vhdl-align-groups]
3980 ["Group Separation String..."
3981 (customize-option 'vhdl-align-group-separate) t]
3982 ["Align Lines with Same Indent"
3983 (customize-set-variable 'vhdl-align-same-indent
3984 (not vhdl-align-same-indent))
3985 :style toggle :selected vhdl-align-same-indent]
3986 ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
3987 "--"
3988 ["Customize Group..." (customize-group 'vhdl-beautify) t])
3989 ("Highlight"
3990 ["Highlighting On/Off..."
3991 (customize-option
3992 (if (fboundp 'global-font-lock-mode)
3993 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3994 ["Highlight Keywords"
3995 (progn (customize-set-variable 'vhdl-highlight-keywords
3996 (not vhdl-highlight-keywords))
3997 (vhdl-fontify-buffer))
3998 :style toggle :selected vhdl-highlight-keywords]
3999 ["Highlight Names"
4000 (progn (customize-set-variable 'vhdl-highlight-names
4001 (not vhdl-highlight-names))
4002 (vhdl-fontify-buffer))
4003 :style toggle :selected vhdl-highlight-names]
4004 ["Highlight Special Words"
4005 (progn (customize-set-variable 'vhdl-highlight-special-words
4006 (not vhdl-highlight-special-words))
4007 (vhdl-fontify-buffer))
4008 :style toggle :selected vhdl-highlight-special-words]
4009 ["Highlight Forbidden Words"
4010 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4011 (not vhdl-highlight-forbidden-words))
4012 (vhdl-fontify-buffer))
4013 :style toggle :selected vhdl-highlight-forbidden-words]
4014 ["Highlight Verilog Keywords"
4015 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4016 (not vhdl-highlight-verilog-keywords))
4017 (vhdl-fontify-buffer))
4018 :style toggle :selected vhdl-highlight-verilog-keywords]
4019 ["Highlight \"translate_off\""
4020 (progn (customize-set-variable 'vhdl-highlight-translate-off
4021 (not vhdl-highlight-translate-off))
4022 (vhdl-fontify-buffer))
4023 :style toggle :selected vhdl-highlight-translate-off]
4024 ["Case Sensitive Highlighting"
4025 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4026 (not vhdl-highlight-case-sensitive))
4027 (vhdl-fontify-buffer))
4028 :style toggle :selected vhdl-highlight-case-sensitive]
4029 ["Special Syntax Definition..."
4030 (customize-option 'vhdl-special-syntax-alist) t]
4031 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
4032 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
4033 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
4034 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
4035 "--"
4036 ["Customize Group..." (customize-group 'vhdl-highlight) t])
4037 ("Speedbar"
4038 ["Auto Open at Startup"
4039 (customize-set-variable 'vhdl-speedbar-auto-open
4040 (not vhdl-speedbar-auto-open))
4041 :style toggle :selected vhdl-speedbar-auto-open]
4042 ("Default Displaying Mode"
4043 ["Files"
4044 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
4045 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
4046 ["Directory Hierarchy"
4047 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
4048 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
4049 ["Project Hierarchy"
4050 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
4051 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
4052 ["Indentation Offset..."
4053 (customize-option 'speedbar-indentation-width) t]
4054 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
4055 ["Jump to Unit when Opening"
4056 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4057 (not vhdl-speedbar-jump-to-unit))
4058 :style toggle :selected vhdl-speedbar-jump-to-unit]
4059 ["Update Hierarchy on File Saving"
4060 (customize-set-variable 'vhdl-speedbar-update-on-saving
4061 (not vhdl-speedbar-update-on-saving))
4062 :style toggle :selected vhdl-speedbar-update-on-saving]
4063 ("Save in Cache File"
4064 ["Hierarchy Information"
4065 (customize-set-variable 'vhdl-speedbar-save-cache
4066 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4067 (delq 'hierarchy vhdl-speedbar-save-cache)
4068 (cons 'hierarchy vhdl-speedbar-save-cache)))
4069 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4070 ["Displaying Status"
4071 (customize-set-variable 'vhdl-speedbar-save-cache
4072 (if (memq 'display vhdl-speedbar-save-cache)
4073 (delq 'display vhdl-speedbar-save-cache)
4074 (cons 'display vhdl-speedbar-save-cache)))
4075 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4076 ["Cache File Name..."
4077 (customize-option 'vhdl-speedbar-cache-file-name) t]
4078 "--"
4079 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4080 ("Menu"
4081 ["Add Index Menu when Loading File"
4082 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4083 (vhdl-index-menu-init))
4084 :style toggle :selected vhdl-index-menu]
4085 ["Add Source File Menu when Loading File"
4086 (progn (customize-set-variable 'vhdl-source-file-menu
4087 (not vhdl-source-file-menu))
4088 (vhdl-add-source-files-menu))
4089 :style toggle :selected vhdl-source-file-menu]
4090 ["Add Hideshow Menu at Startup"
4091 (progn (customize-set-variable 'vhdl-hideshow-menu
4092 (not vhdl-hideshow-menu))
4093 (vhdl-activate-customizations))
4094 :style toggle :selected vhdl-hideshow-menu]
4095 ["Hide Everything Initially"
4096 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4097 :style toggle :selected vhdl-hide-all-init]
4098 "--"
4099 ["Customize Group..." (customize-group 'vhdl-menu) t])
4100 ("Print"
4101 ["In Two Column Format"
4102 (progn (customize-set-variable 'vhdl-print-two-column
4103 (not vhdl-print-two-column))
4104 (message "Activate new setting by saving options and restarting Emacs"))
4105 :style toggle :selected vhdl-print-two-column]
4106 ["Use Customized Faces"
4107 (progn (customize-set-variable 'vhdl-print-customize-faces
4108 (not vhdl-print-customize-faces))
4109 (message "Activate new setting by saving options and restarting Emacs"))
4110 :style toggle :selected vhdl-print-customize-faces]
4111 "--"
4112 ["Customize Group..." (customize-group 'vhdl-print) t])
4113 ("Miscellaneous"
4114 ["Use Intelligent Tab"
4115 (progn (customize-set-variable 'vhdl-intelligent-tab
4116 (not vhdl-intelligent-tab))
4117 (vhdl-activate-customizations))
4118 :style toggle :selected vhdl-intelligent-tab]
4119 ["Indent Syntax-Based"
4120 (customize-set-variable 'vhdl-indent-syntax-based
4121 (not vhdl-indent-syntax-based))
4122 :style toggle :selected vhdl-indent-syntax-based]
4123 ["Indent Comments Like Next Code Line"
4124 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4125 (not vhdl-indent-comment-like-next-code-line))
4126 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4127 ["Word Completion is Case Sensitive"
4128 (customize-set-variable 'vhdl-word-completion-case-sensitive
4129 (not vhdl-word-completion-case-sensitive))
4130 :style toggle :selected vhdl-word-completion-case-sensitive]
4131 ["Word Completion in Minibuffer"
4132 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4133 (not vhdl-word-completion-in-minibuffer))
4134 (message "Activate new setting by saving options and restarting Emacs"))
4135 :style toggle :selected vhdl-word-completion-in-minibuffer]
4136 ["Underscore is Part of Word"
4137 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4138 (not vhdl-underscore-is-part-of-word))
4139 (vhdl-activate-customizations))
4140 :style toggle :selected vhdl-underscore-is-part-of-word]
4141 "--"
4142 ["Customize Group..." (customize-group 'vhdl-misc) t])
4143 ["Related..." (customize-browse 'vhdl-related) t]
4144 "--"
4145 ["Save Options" customize-save-customized t]
4146 ["Activate Options" vhdl-activate-customizations t]
4147 ["Browse Options..." vhdl-customize t])))
4149 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4150 "VHDL Mode menu.")
4152 (defun vhdl-update-mode-menu ()
4153 "Update VHDL Mode menu."
4154 (interactive)
4155 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4156 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4157 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4158 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4159 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4162 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4164 (defconst vhdl-imenu-generic-expression
4166 ("Subprogram"
4167 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4169 ("Instance"
4170 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4172 ("Component"
4173 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4175 ("Procedural"
4176 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4178 ("Process"
4179 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4181 ("Block"
4182 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4184 ("Package"
4185 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4187 ("Configuration"
4188 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4190 ("Architecture"
4191 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4193 ("Entity"
4194 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4197 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4199 (defun vhdl-index-menu-init ()
4200 "Initialize index menu."
4201 (set (make-local-variable 'imenu-case-fold-search) t)
4202 (set (make-local-variable 'imenu-generic-expression)
4203 vhdl-imenu-generic-expression)
4204 (when (and vhdl-index-menu (fboundp 'imenu))
4205 (imenu-add-to-menubar "Index")))
4207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4208 ;; Source file menu (using `easy-menu.el')
4210 (defvar vhdl-sources-menu nil)
4212 (defun vhdl-directory-files (directory &optional full match)
4213 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4214 message."
4215 (if (not (file-directory-p directory))
4216 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4217 (let ((dir (directory-files directory full match)))
4218 (setq dir (delete "." dir))
4219 (setq dir (delete ".." dir))
4220 dir)))
4222 (defun vhdl-get-source-files (&optional full directory)
4223 "Get list of VHDL source files in DIRECTORY or current directory."
4224 (let ((mode-alist auto-mode-alist)
4225 filename-regexp)
4226 ;; create regular expressions for matching file names
4227 (setq filename-regexp "\\`[^.].*\\(")
4228 (while mode-alist
4229 (when (eq (cdar mode-alist) 'vhdl-mode)
4230 (setq filename-regexp
4231 (concat filename-regexp (caar mode-alist) "\\|")))
4232 (setq mode-alist (cdr mode-alist)))
4233 (setq filename-regexp
4234 (concat (substring filename-regexp 0
4235 (string-match "\\\\|$" filename-regexp)) "\\)"))
4236 ;; find files
4237 (vhdl-directory-files
4238 (or directory default-directory) full filename-regexp)))
4240 (defun vhdl-add-source-files-menu ()
4241 "Scan directory for all VHDL source files and generate menu.
4242 The directory of the current source file is scanned."
4243 (interactive)
4244 (message "Scanning directory for source files ...")
4245 (let ((newmap (current-local-map))
4246 (file-list (vhdl-get-source-files))
4247 menu-list found)
4248 ;; Create list for menu
4249 (setq found nil)
4250 (while file-list
4251 (setq found t)
4252 (push (vector (car file-list) (list 'find-file (car file-list)) t)
4253 menu-list)
4254 (setq file-list (cdr file-list)))
4255 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4256 (when found (push "--" menu-list))
4257 (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
4258 (push "Sources" menu-list)
4259 ;; Create menu
4260 (easy-menu-add menu-list)
4261 (easy-menu-define vhdl-sources-menu newmap
4262 "VHDL source files menu" menu-list))
4263 (message ""))
4266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4267 ;;; Mode definition
4268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4269 ;; performs all buffer local initializations
4271 ;;;###autoload
4272 (define-derived-mode vhdl-mode prog-mode
4273 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4274 (vhdl-electric-mode "e")
4275 (vhdl-stutter-mode "s"))
4276 "Major mode for editing VHDL code.
4278 Usage:
4279 ------
4281 TEMPLATE INSERTION (electrification):
4282 After typing a VHDL keyword and entering `SPC', you are prompted for
4283 arguments while a template is generated for that VHDL construct. Typing
4284 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4285 template generation. Optional arguments are indicated by square
4286 brackets and removed if the queried string is left empty. Prompts for
4287 mandatory arguments remain in the code if the queried string is left
4288 empty. They can be queried again by `C-c C-t C-q'. Enabled
4289 electrification is indicated by `/e' in the mode line.
4291 Typing `M-SPC' after a keyword inserts a space without calling the
4292 template generator. Automatic template generation (i.e.
4293 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4294 setting option `vhdl-electric-mode' (see OPTIONS).
4296 Template generators can be invoked from the VHDL menu, by key
4297 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4298 the keyword (i.e. first word of menu entry not in parenthesis) and
4299 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4300 conf, comp, cons, func, inst, pack, sig, var.
4302 Template styles can be customized in customization group
4303 `vhdl-template' \(see OPTIONS).
4306 HEADER INSERTION:
4307 A file header can be inserted by `C-c C-t C-h'. A file footer
4308 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4309 See customization group `vhdl-header'.
4312 STUTTERING:
4313 Double striking of some keys inserts cumbersome VHDL syntax elements.
4314 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4315 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4316 the mode line. The stuttering keys and their effects are:
4318 ;; --> \" : \" [ --> ( -- --> comment
4319 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4320 .. --> \" => \" ] --> ) --- --> horizontal line
4321 ,, --> \" <= \" ]] --> ] ---- --> display comment
4322 == --> \" == \" '' --> \\\"
4325 WORD COMPLETION:
4326 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4327 word in the buffer that starts alike, inserts it and adjusts case.
4328 Re-typing `TAB' toggles through alternative word completions. This also
4329 works in the minibuffer (i.e. in template generator prompts).
4331 Typing `TAB' after `(' looks for and inserts complete parenthesized
4332 expressions (e.g. for array index ranges). All keywords as well as
4333 standard types and subprograms of VHDL have predefined abbreviations
4334 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4335 beginning with \"std\").
4337 Typing `TAB' after a non-word character indents the line if at the
4338 beginning of a line (i.e. no preceding non-blank characters), and
4339 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4340 stop.
4343 COMMENTS:
4344 `--' puts a single comment.
4345 `---' draws a horizontal line for separating code segments.
4346 `----' inserts a display comment, i.e. two horizontal lines
4347 with a comment in between.
4348 `--CR' comments out code on that line. Re-hitting CR comments
4349 out following lines.
4350 `C-c C-c' comments out a region if not commented out,
4351 uncomments a region if already commented out. Option
4352 `comment-style' defines where the comment characters
4353 should be placed (beginning of line, indent, etc.).
4355 You are prompted for comments after object definitions (i.e. signals,
4356 variables, constants, ports) and after subprogram and process
4357 specifications if option `vhdl-prompt-for-comments' is non-nil.
4358 Comments are automatically inserted as additional labels (e.g. after
4359 begin statements) and as help comments if `vhdl-self-insert-comments' is
4360 non-nil.
4362 Inline comments (i.e. comments after a piece of code on the same line)
4363 are indented at least to `vhdl-inline-comment-column'. Comments go at
4364 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4365 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4366 in a comment automatically opens a new comment line. `M-q' re-fills
4367 multi-line comments.
4370 INDENTATION:
4371 `TAB' indents a line if at the beginning of the line. The amount of
4372 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4373 always indents the current line (is bound to `TAB' if option
4374 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4375 the entire region.
4377 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4378 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4379 indented normally (nil) or relative to the opening parenthesis (non-nil)
4380 according to option `vhdl-argument-list-indent'.
4382 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4383 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4384 and vice versa.
4386 Syntax-based indentation can be very slow in large files. Option
4387 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4389 Option `vhdl-indent-comment-like-next-code-line' controls whether
4390 comment lines are indented like the preceding or like the following code
4391 line.
4394 ALIGNMENT:
4395 The alignment functions align operators, keywords, and inline comments
4396 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4397 separated by blank lines, `C-c C-a C-i' a block of lines with same
4398 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4399 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4400 C-a C-d' all lines within the declarative part of a design unit. `C-c
4401 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4402 for a group of lines, and `C-c C-a M-c' for a region.
4404 If option `vhdl-align-groups' is non-nil, groups of code lines
4405 separated by special lines (see option `vhdl-align-group-separate') are
4406 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4407 blocks of lines with same indent are aligned separately. Some templates
4408 are automatically aligned after generation if option `vhdl-auto-align'
4409 is non-nil.
4411 Alignment tries to align inline comments at
4412 `vhdl-inline-comment-column' and tries inline comment not to exceed
4413 `vhdl-end-comment-column'.
4415 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4416 symbols are surrounded by one space, and multiple spaces are eliminated.
4419 CODE FILLING:
4420 Code filling allows to condense code (e.g. sensitivity lists or port
4421 maps) by removing comments and newlines and re-wrapping so that all
4422 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4423 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4424 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4425 `C-c C-f M-f' an entire region.
4428 CODE BEAUTIFICATION:
4429 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4430 buffer respectively. This includes indentation, alignment, and case
4431 fixing. Code beautification can also be run non-interactively using the
4432 command:
4434 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4437 PORT TRANSLATION:
4438 Generic and port clauses from entity or component declarations can be
4439 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4440 as component instantiations and corresponding internal constants and
4441 signals, as a generic map with constants as actual generics, and as
4442 internal signal initializations (menu).
4444 To include formals in component instantiations, see option
4445 `vhdl-association-list-with-formals'. To include comments in pasting,
4446 see options `vhdl-include-...-comments'.
4448 A clause with several generic/port names on the same line can be
4449 flattened (`C-c C-p C-f') so that only one name per line exists. The
4450 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4451 outputs and vice versa, which can be useful in testbenches. (This
4452 reversion is done on the internal data structure and is only reflected
4453 in subsequent paste operations.)
4455 Names for actual ports, instances, testbenches, and
4456 design-under-test instances can be derived from existing names according
4457 to options `vhdl-...-name'. See customization group `vhdl-port'.
4460 SUBPROGRAM TRANSLATION:
4461 Similar functionality exists for copying/pasting the interface of
4462 subprograms (function/procedure). A subprogram interface can be copied
4463 and then pasted as a subprogram declaration, body or call (uses
4464 association list with formals).
4467 TESTBENCH GENERATION:
4468 A copied port can also be pasted as a testbench. The generated
4469 testbench includes an entity, an architecture, and an optional
4470 configuration. The architecture contains the component declaration and
4471 instantiation of the DUT as well as internal constant and signal
4472 declarations. Additional user-defined templates can be inserted. The
4473 names used for entity/architecture/configuration/DUT as well as the file
4474 structure to be generated can be customized. See customization group
4475 `vhdl-testbench'.
4478 KEY BINDINGS:
4479 Key bindings (`C-c ...') exist for most commands (see in menu).
4482 VHDL MENU:
4483 All commands can be found in the VHDL menu including their key bindings.
4486 FILE BROWSER:
4487 The speedbar allows browsing of directories and file contents. It can
4488 be accessed from the VHDL menu and is automatically opened if option
4489 `vhdl-speedbar-auto-open' is non-nil.
4491 In speedbar, open files and directories with `mouse-2' on the name and
4492 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4495 DESIGN HIERARCHY BROWSER:
4496 The speedbar can also be used for browsing the hierarchy of design units
4497 contained in the source files of the current directory or the specified
4498 projects (see option `vhdl-project-alist').
4500 The speedbar can be switched between file, directory hierarchy and
4501 project hierarchy browsing mode in the speedbar menu or by typing `f',
4502 `h' or `H' in speedbar.
4504 In speedbar, open design units with `mouse-2' on the name and browse
4505 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4506 from entities and components (in packages). Individual design units and
4507 complete designs can directly be compiled (\"Make\" menu entry).
4509 The hierarchy is automatically updated upon saving a modified source
4510 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4511 hierarchy is only updated for projects that have been opened once in the
4512 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4513 options in group `vhdl-speedbar').
4515 Simple design consistency checks are done during scanning, such as
4516 multiple declarations of the same unit or missing primary units that are
4517 required by secondary units.
4520 STRUCTURAL COMPOSITION:
4521 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4522 for a new component. Subcomponents (i.e. component declaration and
4523 instantiation) can be automatically placed from a previously read port
4524 \(`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4525 all subcomponents can be automatically connected using internal signals
4526 and ports (`C-c C-m C-w') following these rules:
4527 - subcomponent actual ports with same name are considered to be
4528 connected by a signal (internal signal or port)
4529 - signals that are only inputs to subcomponents are considered as
4530 inputs to this component -> input port created
4531 - signals that are only outputs from subcomponents are considered as
4532 outputs from this component -> output port created
4533 - signals that are inputs to AND outputs from subcomponents are
4534 considered as internal connections -> internal signal created
4536 Purpose: With appropriate naming conventions it is possible to
4537 create higher design levels with only a few mouse clicks or key
4538 strokes. A new design level can be created by simply generating a new
4539 component, placing the required subcomponents from the hierarchy
4540 browser, and wiring everything automatically.
4542 Note: Automatic wiring only works reliably on templates of new
4543 components and component instantiations that were created by VHDL mode.
4545 Component declarations can be placed in a components package (option
4546 `vhdl-use-components-package') which can be automatically generated for
4547 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4548 component instantiation is also supported (option
4549 `vhdl-use-direct-instantiation').
4551 Configuration declarations can automatically be generated either from
4552 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4553 the speedbar menu (for the architecture under the cursor). The
4554 configurations can optionally be hierarchical (i.e. include all
4555 component levels of a hierarchical design, option
4556 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4557 (option `vhdl-compose-configuration-use-subconfiguration'). For
4558 subcomponents in hierarchical configurations, the most-recently-analyzed
4559 (mra) architecture is selected. If another architecture is desired, it
4560 can be marked as most-recently-analyzed (speedbar menu) before
4561 generating the configuration.
4563 Note: Configurations of subcomponents (i.e. hierarchical configuration
4564 declarations) are currently not considered when displaying
4565 configurations in speedbar.
4567 See the options group `vhdl-compose' for all relevant user options.
4570 SOURCE FILE COMPILATION:
4571 The syntax of the current buffer can be analyzed by calling a VHDL
4572 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4573 option `vhdl-compiler'. The available compilers are listed in option
4574 `vhdl-compiler-alist' including all required compilation command,
4575 command options, compilation directory, and error message syntax
4576 information. New compilers can be added.
4578 All the source files of an entire design can be compiled by the `make'
4579 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4582 MAKEFILE GENERATION:
4583 Makefiles can be generated automatically by an internal generation
4584 routine (`C-c M-k'). The library unit dependency information is
4585 obtained from the hierarchy browser. Makefile generation can be
4586 customized for each compiler in option `vhdl-compiler-alist'.
4588 Makefile generation can also be run non-interactively using the
4589 command:
4591 emacs -batch -l ~/.emacs -l vhdl-mode
4592 [-compiler compilername] [-project projectname]
4593 -f vhdl-generate-makefile
4595 The Makefile's default target \"all\" compiles the entire design, the
4596 target \"clean\" removes it and the target \"library\" creates the
4597 library directory if not existent. These target names can be customized
4598 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4599 target for each primary library unit which allows selective compilation
4600 of this unit, its secondary units and its subhierarchy (example:
4601 compilation of a design specified by a configuration). User specific
4602 parts can be inserted into a Makefile with option
4603 `vhdl-makefile-generation-hook'.
4605 Limitations:
4606 - Only library units and dependencies within the current library are
4607 considered. Makefiles for designs that span multiple libraries are
4608 not (yet) supported.
4609 - Only one-level configurations are supported (also hierarchical),
4610 but configurations that go down several levels are not.
4611 - The \"others\" keyword in configurations is not supported.
4614 PROJECTS:
4615 Projects can be defined in option `vhdl-project-alist' and a current
4616 project be selected using option `vhdl-project' (permanently) or from
4617 the menu or speedbar (temporarily). For each project, title and
4618 description strings (for the file headers), source files/directories
4619 (for the hierarchy browser and Makefile generation), library name, and
4620 compiler-dependent options, exceptions and compilation directory can be
4621 specified. Compilation settings overwrite the settings of option
4622 `vhdl-compiler-alist'.
4624 Project setups can be exported (i.e. written to a file) and imported.
4625 Imported setups are not automatically saved in `vhdl-project-alist' but
4626 can be saved afterwards in its customization buffer. When starting
4627 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4628 vhdl-mode\") in a directory with an existing project setup file, it is
4629 automatically loaded and its project activated if option
4630 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4631 files can be specified in option `vhdl-project-file-name'. Multiple
4632 project setups can be automatically loaded from global directories.
4633 This is an alternative to specifying project setups with option
4634 `vhdl-project-alist'.
4637 SPECIAL MENUES:
4638 As an alternative to the speedbar, an index menu can be added (set
4639 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4640 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4641 file) for browsing the file contents (is not populated if buffer is
4642 larger than 256000). Also, a source file menu can be
4643 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4644 current directory for VHDL source files.
4647 VHDL STANDARDS:
4648 The VHDL standards to be used are specified in option `vhdl-standard'.
4649 Available standards are: VHDL'87/'93(02), VHDL-AMS, and Math Packages.
4652 KEYWORD CASE:
4653 Lower and upper case for keywords and standardized types, attributes,
4654 and enumeration values is supported. If the option
4655 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4656 lower case and are converted into upper case automatically (not for
4657 types, attributes, and enumeration values). The case of keywords,
4658 types, attributes,and enumeration values can be fixed for an entire
4659 region (menu) or buffer (`C-c C-x C-c') according to the options
4660 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4663 HIGHLIGHTING (fontification):
4664 Keywords and standardized types, attributes, enumeration values, and
4665 function names (controlled by option `vhdl-highlight-keywords'), as well
4666 as comments, strings, and template prompts are highlighted using
4667 different colors. Unit, subprogram, signal, variable, constant,
4668 parameter and generic/port names in declarations as well as labels are
4669 highlighted if option `vhdl-highlight-names' is non-nil.
4671 Additional reserved words or words with a forbidden syntax (e.g. words
4672 that should be avoided) can be specified in option
4673 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4674 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4675 keywords are highlighted as forbidden words if option
4676 `vhdl-highlight-verilog-keywords' is non-nil.
4678 Words with special syntax can be highlighted by specifying their
4679 syntax and color in option `vhdl-special-syntax-alist' and by setting
4680 option `vhdl-highlight-special-words' to non-nil. This allows to
4681 establish some naming conventions (e.g. to distinguish different kinds
4682 of signals or other objects by using name suffices) and to support them
4683 visually.
4685 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4686 to support case-sensitive highlighting. However, keywords are then only
4687 highlighted if written in lower case.
4689 Code between \"translate_off\" and \"translate_on\" pragmas is
4690 highlighted using a different background color if option
4691 `vhdl-highlight-translate-off' is non-nil.
4693 For documentation and customization of the used colors see
4694 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4695 highlighting of matching parenthesis, see customization group
4696 `paren-showing'. Automatic buffer highlighting is turned on/off by
4697 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4700 USER MODELS:
4701 VHDL models (templates) can be specified by the user and made accessible
4702 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4703 electrification. See option `vhdl-model-alist'.
4706 HIDE/SHOW:
4707 The code of blocks, processes, subprograms, component declarations and
4708 instantiations, generic/port clauses, and configuration declarations can
4709 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4710 the code (see customization group `vhdl-menu'). XEmacs: limited
4711 functionality due to old `hideshow.el' package.
4714 CODE UPDATING:
4715 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4716 current process, `C-c C-u M-s' of all processes in the current buffer.
4717 Limitations:
4718 - Only declared local signals (ports, signals declared in
4719 architecture and blocks) are automatically inserted.
4720 - Global signals declared in packages are not automatically inserted.
4721 Insert them once manually (will be kept afterwards).
4722 - Out parameters of procedures are considered to be read.
4723 Use option `vhdl-entity-file-name' to specify the entity file name
4724 \(used to obtain the port names).
4725 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4726 specify whether to include array indices and record fields in
4727 sensitivity lists.
4730 CODE FIXING:
4731 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4732 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4735 PRINTING:
4736 PostScript printing with different faces (an optimized set of faces is
4737 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4738 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4739 PostScript printing commands. Option `vhdl-print-two-column' defines
4740 appropriate default settings for nice landscape two-column printing.
4741 The paper format can be set by option `ps-paper-type'. Do not forget to
4742 switch `ps-print-color-p' to nil for printing on black-and-white
4743 printers.
4746 OPTIONS:
4747 User options allow customization of VHDL Mode. All options are
4748 accessible from the \"Options\" menu entry. Simple options (switches
4749 and choices) can directly be changed, while for complex options a
4750 customization buffer is opened. Changed options can be saved for future
4751 sessions using the \"Save Options\" menu entry.
4753 Options and their detailed descriptions can also be accessed by using
4754 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4755 customize-group' for groups). Some customizations only take effect
4756 after some action (read the NOTE in the option documentation).
4757 Customization can also be done globally (i.e. site-wide, read the
4758 INSTALL file).
4760 Not all options are described in this documentation, so go and see
4761 what other useful user options there are (`M-x vhdl-customize' or menu)!
4764 FILE EXTENSIONS:
4765 As default, files with extensions \".vhd\" and \".vhdl\" are
4766 automatically recognized as VHDL source files. To add an extension
4767 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4769 \(push '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist)
4772 HINTS:
4773 - To start Emacs with open VHDL hierarchy browser without having to load
4774 a VHDL file first, use the command:
4776 emacs -l vhdl-mode -f speedbar-frame-mode
4778 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4780 - Some features only work on properly indented code.
4783 RELEASE NOTES:
4784 See also the release notes (menu) for added features in new releases.
4787 Maintenance:
4788 ------------
4790 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4791 Add a description of the problem and include a reproducible test case.
4793 Questions and enhancement requests can be sent to <reto@gnu.org>.
4795 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4796 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4797 releases. You are kindly invited to participate in beta testing. Subscribe
4798 to above mailing lists by sending an email to <reto@gnu.org>.
4800 VHDL Mode is officially distributed at
4801 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4802 where the latest version can be found.
4805 Known problems:
4806 ---------------
4808 - XEmacs: Incorrect start-up when automatically opening speedbar.
4809 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4810 - Indentation incorrect for new 'postponed' VHDL keyword.
4811 - Indentation incorrect for 'protected body' construct.
4814 The VHDL Mode Authors
4815 Reto Zimmermann and Rod Whitby
4817 Key bindings:
4818 -------------
4820 \\{vhdl-mode-map}"
4821 :abbrev-table vhdl-mode-abbrev-table
4823 ;; set local variables
4824 (set (make-local-variable 'paragraph-start)
4825 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4826 (set (make-local-variable 'paragraph-separate) paragraph-start)
4827 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4828 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4829 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4830 (set (make-local-variable 'comment-start) "--")
4831 (set (make-local-variable 'comment-end) "")
4832 (when vhdl-emacs-21
4833 (set (make-local-variable 'comment-padding) ""))
4834 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4835 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4836 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4837 (set (make-local-variable 'comment-multi-line) nil)
4838 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4839 (set (make-local-variable 'hippie-expand-verbose) nil)
4841 ;; setup the comment indent variable in a Emacs version portable way
4842 ;; ignore any byte compiler warnings you might get here
4843 (when (boundp 'comment-indent-function)
4844 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4846 ;; initialize font locking
4847 (set (make-local-variable 'font-lock-defaults)
4848 (list
4849 '(nil vhdl-font-lock-keywords) nil
4850 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4851 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4852 (set (make-local-variable 'syntax-propertize-function)
4853 (syntax-propertize-rules
4854 ;; Mark single quotes as having string quote syntax in
4855 ;; 'c' instances.
4856 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4857 (set (make-local-variable 'font-lock-syntactic-keywords)
4858 vhdl-font-lock-syntactic-keywords))
4859 (unless vhdl-emacs-21
4860 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4861 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4862 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4863 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4864 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4865 ; (turn-on-font-lock)
4867 ;; variables for source file compilation
4868 (when vhdl-compile-use-local-error-regexp
4869 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4870 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4872 ;; add index menu
4873 (vhdl-index-menu-init)
4874 ;; add source file menu
4875 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4876 ;; add VHDL menu
4877 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4878 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4879 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4880 ;; initialize hideshow and add menu
4881 (vhdl-hideshow-init)
4882 (run-hooks 'menu-bar-update-hook)
4884 ;; miscellaneous
4885 (vhdl-ps-print-init)
4886 (vhdl-write-file-hooks-init)
4887 (message "VHDL Mode %s.%s" vhdl-version
4888 (if noninteractive "" " See menu for documentation and release notes.")))
4890 (defun vhdl-activate-customizations ()
4891 "Activate all customizations on local variables."
4892 (interactive)
4893 (vhdl-mode-map-init)
4894 (use-local-map vhdl-mode-map)
4895 (set-syntax-table vhdl-mode-syntax-table)
4896 (setq comment-column vhdl-inline-comment-column)
4897 (setq end-comment-column vhdl-end-comment-column)
4898 (vhdl-write-file-hooks-init)
4899 (vhdl-update-mode-menu)
4900 (vhdl-hideshow-init)
4901 (run-hooks 'menu-bar-update-hook))
4903 (defun vhdl-write-file-hooks-init ()
4904 "Add/remove hooks when buffer is saved."
4905 (if vhdl-modify-date-on-saving
4906 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4907 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4908 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4909 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4911 (defun vhdl-process-command-line-option (option)
4912 "Process command line options for VHDL Mode."
4913 (cond
4914 ;; set compiler
4915 ((equal option "-compiler")
4916 (vhdl-set-compiler (car command-line-args-left))
4917 (setq command-line-args-left (cdr command-line-args-left)))
4918 ;; set project
4919 ((equal option "-project")
4920 (vhdl-set-project (car command-line-args-left))
4921 (setq command-line-args-left (cdr command-line-args-left)))))
4923 ;; make Emacs process VHDL Mode options
4924 (setq command-switch-alist
4925 (append command-switch-alist
4926 '(("-compiler" . vhdl-process-command-line-option)
4927 ("-project" . vhdl-process-command-line-option))))
4930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4931 ;;; Keywords and standardized words
4932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4934 (defconst vhdl-02-keywords
4936 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4937 "assert" "attribute"
4938 "begin" "block" "body" "buffer" "bus"
4939 "case" "component" "configuration" "constant"
4940 "disconnect" "downto"
4941 "else" "elsif" "end" "entity" "exit"
4942 "file" "for" "function"
4943 "generate" "generic" "group" "guarded"
4944 "if" "impure" "in" "inertial" "inout" "is"
4945 "label" "library" "linkage" "literal" "loop"
4946 "map" "mod"
4947 "nand" "new" "next" "nor" "not" "null"
4948 "of" "on" "open" "or" "others" "out"
4949 "package" "port" "postponed" "procedure" "process" "protected" "pure"
4950 "range" "record" "register" "reject" "rem" "report" "return"
4951 "rol" "ror"
4952 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4953 "then" "to" "transport" "type"
4954 "unaffected" "units" "until" "use"
4955 "variable"
4956 "wait" "when" "while" "with"
4957 "xnor" "xor"
4959 "List of VHDL'02 keywords.")
4961 (defconst vhdl-ams-keywords
4963 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4964 "reference" "spectrum" "subnature" "terminal" "through"
4965 "tolerance"
4967 "List of VHDL-AMS keywords.")
4969 (defconst vhdl-verilog-keywords
4971 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4972 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4973 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4974 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4975 "endprimitive" "endspecify" "endtable" "endtask" "event"
4976 "for" "force" "forever" "fork" "function"
4977 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4978 "macromodule" "makefile" "medium" "module"
4979 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4980 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4981 "pullup"
4982 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4983 "rtranif0" "rtranif1"
4984 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4985 "strong1" "supply" "supply0" "supply1"
4986 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4987 "triand" "trior" "trireg"
4988 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4990 "List of Verilog keywords as candidate for additional reserved words.")
4992 (defconst vhdl-02-types
4994 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4995 "real" "time" "natural" "positive" "string" "line" "text" "side"
4996 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4997 "std_logic" "std_logic_vector"
4998 "std_ulogic" "std_ulogic_vector"
5000 "List of VHDL'02 standardized types.")
5002 (defconst vhdl-ams-types
5003 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5005 ;; package `standard'
5006 "domain_type" "real_vector"
5007 ;; package `energy_systems'
5008 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5009 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5010 "real_across_vector" "real_through_vector"
5011 ;; package `electrical_systems'
5012 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5013 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5014 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5015 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5016 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5017 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5018 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5019 "electric_flux_density_vector" "electric_field_strength_vector"
5020 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5021 "inductance_vector" "reluctance_vector" "ground"
5022 ;; package `mechanical_systems'
5023 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5024 "damping" "momentum" "angle" "torque" "angular_velocity"
5025 "angular_acceleration" "moment_inertia" "angular_momentum"
5026 "angular_stiffness" "angular_damping" "translational"
5027 "translational_vector" "translational_velocity"
5028 "translational_velocity_vector" "rotational" "rotational_vector"
5029 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5030 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5031 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5032 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5033 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5034 "angular_momentum_vector" "angular_stiffness_vector"
5035 "angular_damping_vector" "anchor" "translational_v_ref"
5036 "rotational_v_ref" "translational_v" "rotational_v"
5037 ;; package `radiant_systems'
5038 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5039 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5040 "illuminance_vector" "irradiance_vector"
5041 ;; package `thermal_systems'
5042 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5043 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5044 "heat_flow_vector" "thermal_capacitance_vector"
5045 "thermal_resistance_vector" "thermal_conductance_vector"
5046 ;; package `fluidic_systems'
5047 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5048 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5049 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5050 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5051 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5052 "density_vector" "viscosity_vector" "fresistance_vector"
5053 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5054 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5055 "cfinertance_vector"
5057 "List of VHDL-AMS standardized types.")
5059 (defconst vhdl-math-types
5061 "complex" "complex_polar" "positive_real" "principal_value"
5063 "List of Math Packages standardized types.")
5065 (defconst vhdl-02-attributes
5067 "base" "left" "right" "high" "low" "pos" "val" "succ"
5068 "pred" "leftof" "rightof" "range" "reverse_range"
5069 "length" "delayed" "stable" "quiet" "transaction"
5070 "event" "active" "last_event" "last_active" "last_value"
5071 "driving" "driving_value" "ascending" "value" "image"
5072 "simple_name" "instance_name" "path_name"
5073 "foreign"
5075 "List of VHDL'02 standardized attributes.")
5077 (defconst vhdl-ams-attributes
5079 "across" "through"
5080 "reference" "contribution" "tolerance"
5081 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5082 "ramp" "slew"
5084 "List of VHDL-AMS standardized attributes.")
5086 (defconst vhdl-02-enum-values
5088 "true" "false"
5089 "note" "warning" "error" "failure"
5090 "read_mode" "write_mode" "append_mode"
5091 "open_ok" "status_error" "name_error" "mode_error"
5092 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5093 "right" "left"
5095 "List of VHDL'02 standardized enumeration values.")
5097 (defconst vhdl-ams-enum-values
5099 "quiescent_domain" "time_domain" "frequency_domain"
5100 ;; from `nature_pkg' package
5101 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5103 "List of VHDL-AMS standardized enumeration values.")
5105 (defconst vhdl-ams-constants
5106 ;; standard: IEEE Std 1076.1.1-2004
5108 ;; package `fundamental_constants'
5109 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5110 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5111 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5112 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5113 ;; package `material_constants'
5114 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5115 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5116 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5118 "List of VHDL-AMS standardized constants.")
5120 (defconst vhdl-math-constants
5121 ;; standard: IEEE Std 1076.2-1996
5123 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5124 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5125 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5126 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5127 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5128 "math_sqrt_pi"
5130 "List of Math Packages standardized constants.")
5132 (defconst vhdl-02-functions
5134 "now" "resolved" "rising_edge" "falling_edge"
5135 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5136 "endfile"
5137 "resize" "is_X" "std_match"
5138 "shift_left" "shift_right" "rotate_left" "rotate_right"
5139 "to_unsigned" "to_signed" "to_integer"
5140 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5141 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5142 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5143 "shl" "shr" "ext" "sxt"
5144 "deallocate"
5146 "List of VHDL'02 standardized functions.")
5148 (defconst vhdl-ams-functions
5150 ;; package `standard'
5151 "frequency"
5153 "List of VHDL-AMS standardized functions.")
5155 (defconst vhdl-math-functions
5156 ;; standard: IEEE Std 1076.2-1996
5158 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5159 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5160 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5161 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5162 "tan" "tanh" "trunc" "uniform"
5164 "List of Math Packages standardized functions.")
5166 (defconst vhdl-02-packages
5168 "std_logic_1164" "numeric_std" "numeric_bit"
5169 "standard" "textio"
5170 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5171 "std_logic_misc" "std_logic_textio"
5172 "ieee" "std" "work"
5174 "List of VHDL'02 standardized packages and libraries.")
5176 (defconst vhdl-ams-packages
5178 "fundamental_constants" "material_constants" "energy_systems"
5179 "electrical_systems" "mechanical_systems" "radiant_systems"
5180 "thermal_systems" "fluidic_systems"
5182 "List of VHDL-AMS standardized packages and libraries.")
5184 (defconst vhdl-math-packages
5186 "math_real" "math_complex"
5188 "List of Math Packages standardized packages and libraries.")
5190 (defvar vhdl-keywords nil
5191 "List of VHDL keywords.")
5193 (defvar vhdl-types nil
5194 "List of VHDL standardized types.")
5196 (defvar vhdl-attributes nil
5197 "List of VHDL standardized attributes.")
5199 (defvar vhdl-enum-values nil
5200 "List of VHDL standardized enumeration values.")
5202 (defvar vhdl-constants nil
5203 "List of VHDL standardized constants.")
5205 (defvar vhdl-functions nil
5206 "List of VHDL standardized functions.")
5208 (defvar vhdl-packages nil
5209 "List of VHDL standardized packages and libraries.")
5211 (defvar vhdl-reserved-words nil
5212 "List of additional reserved words.")
5214 (defvar vhdl-keywords-regexp nil
5215 "Regexp for VHDL keywords.")
5217 (defvar vhdl-types-regexp nil
5218 "Regexp for VHDL standardized types.")
5220 (defvar vhdl-attributes-regexp nil
5221 "Regexp for VHDL standardized attributes.")
5223 (defvar vhdl-enum-values-regexp nil
5224 "Regexp for VHDL standardized enumeration values.")
5226 (defvar vhdl-constants-regexp nil
5227 "Regexp for VHDL standardized constants.")
5229 (defvar vhdl-functions-regexp nil
5230 "Regexp for VHDL standardized functions.")
5232 (defvar vhdl-packages-regexp nil
5233 "Regexp for VHDL standardized packages and libraries.")
5235 (defvar vhdl-reserved-words-regexp nil
5236 "Regexp for additional reserved words.")
5238 (defvar vhdl-directive-keywords-regexp nil
5239 "Regexp for compiler directive keywords.")
5241 (defun vhdl-upcase-list (condition list)
5242 "Upcase all elements in LIST based on CONDITION."
5243 (when condition
5244 (let ((tmp-list list))
5245 (while tmp-list
5246 (setcar tmp-list (upcase (car tmp-list)))
5247 (setq tmp-list (cdr tmp-list)))))
5248 list)
5250 (defun vhdl-words-init ()
5251 "Initialize reserved words."
5252 (setq vhdl-keywords
5253 (vhdl-upcase-list
5254 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5255 (append vhdl-02-keywords
5256 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5257 (setq vhdl-types
5258 (vhdl-upcase-list
5259 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5260 (append vhdl-02-types
5261 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5262 (when (vhdl-standard-p 'math) vhdl-math-types))))
5263 (setq vhdl-attributes
5264 (vhdl-upcase-list
5265 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5266 (append vhdl-02-attributes
5267 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5268 (setq vhdl-enum-values
5269 (vhdl-upcase-list
5270 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5271 (append vhdl-02-enum-values
5272 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5273 (setq vhdl-constants
5274 (vhdl-upcase-list
5275 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5276 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5277 (when (vhdl-standard-p 'math) vhdl-math-constants)
5278 '(""))))
5279 (setq vhdl-functions
5280 (append vhdl-02-functions
5281 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5282 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5283 (setq vhdl-packages
5284 (append vhdl-02-packages
5285 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5286 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5287 (setq vhdl-reserved-words
5288 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5289 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5290 '("")))
5291 (setq vhdl-keywords-regexp
5292 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5293 (setq vhdl-types-regexp
5294 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5295 (setq vhdl-attributes-regexp
5296 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5297 (setq vhdl-enum-values-regexp
5298 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5299 (setq vhdl-constants-regexp
5300 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5301 (setq vhdl-functions-regexp
5302 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5303 (setq vhdl-packages-regexp
5304 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5305 (setq vhdl-reserved-words-regexp
5306 (concat "\\<\\("
5307 (unless (equal vhdl-forbidden-syntax "")
5308 (concat vhdl-forbidden-syntax "\\|"))
5309 (regexp-opt vhdl-reserved-words)
5310 "\\)\\>"))
5311 (setq vhdl-directive-keywords-regexp
5312 (concat "\\<\\(" (mapconcat 'regexp-quote
5313 vhdl-directive-keywords "\\|") "\\)\\>"))
5314 (vhdl-abbrev-list-init))
5316 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5317 ;; Words to expand
5319 (defvar vhdl-abbrev-list nil
5320 "Predefined abbreviations for VHDL.")
5322 (defun vhdl-abbrev-list-init ()
5323 (setq vhdl-abbrev-list
5324 (append
5325 (list vhdl-upper-case-keywords) vhdl-keywords
5326 (list vhdl-upper-case-types) vhdl-types
5327 (list vhdl-upper-case-attributes) vhdl-attributes
5328 (list vhdl-upper-case-enum-values) vhdl-enum-values
5329 (list vhdl-upper-case-constants) vhdl-constants
5330 (list nil) vhdl-functions
5331 (list nil) vhdl-packages)))
5333 ;; initialize reserved words for VHDL Mode
5334 (vhdl-words-init)
5337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5338 ;;; Indentation
5339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5342 ;; Syntax analysis
5344 ;; constant regular expressions for looking at various constructs
5346 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5347 "Regexp describing a VHDL symbol.
5348 We cannot use just `word' syntax class since `_' cannot be in word
5349 class. Putting underscore in word class breaks forward word movement
5350 behavior that users are familiar with.")
5352 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5353 "Regexp describing a case statement header key.")
5355 (defconst vhdl-label-key
5356 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5357 "Regexp describing a VHDL label.")
5359 ;; Macro definitions:
5361 (defmacro vhdl-point (position)
5362 "Return the value of point at certain commonly referenced POSITIONs.
5363 POSITION can be one of the following symbols:
5365 bol -- beginning of line
5366 eol -- end of line
5367 bod -- beginning of defun
5368 boi -- back to indentation
5369 eoi -- last whitespace on line
5370 ionl -- indentation of next line
5371 iopl -- indentation of previous line
5372 bonl -- beginning of next line
5373 bopl -- beginning of previous line
5375 This function does not modify point or mark."
5376 (or (and (eq 'quote (car-safe position))
5377 (null (cddr position)))
5378 (error "ERROR: Bad buffer position requested: %s" position))
5379 (setq position (nth 1 position))
5380 `(let ((here (point)))
5381 ,@(cond
5382 ((eq position 'bol) '((beginning-of-line)))
5383 ((eq position 'eol) '((end-of-line)))
5384 ((eq position 'bod) '((save-match-data
5385 (vhdl-beginning-of-defun))))
5386 ((eq position 'boi) '((back-to-indentation)))
5387 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5388 ((eq position 'bonl) '((forward-line 1)))
5389 ((eq position 'bopl) '((forward-line -1)))
5390 ((eq position 'iopl)
5391 '((forward-line -1)
5392 (back-to-indentation)))
5393 ((eq position 'ionl)
5394 '((forward-line 1)
5395 (back-to-indentation)))
5396 (t (error "ERROR: Unknown buffer position requested: %s" position))
5398 (prog1
5399 (point)
5400 (goto-char here))
5401 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5402 ;; doesn't hurt for v19
5403 ,@nil
5406 (defmacro vhdl-safe (&rest body)
5407 "Safely execute BODY, return nil if an error occurred."
5408 `(condition-case nil
5409 (progn ,@body)
5410 (error nil)))
5412 (defmacro vhdl-add-syntax (symbol &optional relpos)
5413 "A simple macro to append the syntax in SYMBOL to the syntax list.
5414 Try to increase performance by using this macro."
5415 `(setq vhdl-syntactic-context
5416 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5418 (defmacro vhdl-has-syntax (symbol)
5419 "A simple macro to return check the syntax list.
5420 Try to increase performance by using this macro."
5421 `(assoc ,symbol vhdl-syntactic-context))
5423 ;; Syntactic element offset manipulation:
5425 (defun vhdl-read-offset (langelem)
5426 "Read new offset value for LANGELEM from minibuffer.
5427 Return a valid value only."
5428 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5429 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5430 (prompt "Offset: ")
5431 offset input interned)
5432 (while (not offset)
5433 (setq input (read-string prompt oldoff)
5434 offset (cond ((string-equal "+" input) '+)
5435 ((string-equal "-" input) '-)
5436 ((string-equal "++" input) '++)
5437 ((string-equal "--" input) '--)
5438 ((string-match "^-?[0-9]+$" input)
5439 (string-to-number input))
5440 ((fboundp (setq interned (intern input)))
5441 interned)
5442 ((boundp interned) interned)
5443 ;; error, but don't signal one, keep trying
5444 ;; to read an input value
5445 (t (ding)
5446 (setq prompt errmsg)
5447 nil))))
5448 offset))
5450 (defun vhdl-set-offset (symbol offset &optional add-p)
5451 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5452 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5453 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5454 `vhdl-offsets-alist' if it doesn't already appear there."
5455 (interactive
5456 (let* ((langelem
5457 (intern (completing-read
5458 (concat "Syntactic symbol to change"
5459 (if current-prefix-arg " or add" "")
5460 ": ")
5461 (mapcar
5462 (function
5463 (lambda (langelem)
5464 (cons (format "%s" (car langelem)) nil)))
5465 vhdl-offsets-alist)
5466 nil (not current-prefix-arg)
5467 ;; initial contents tries to be the last element
5468 ;; on the syntactic analysis list for the current
5469 ;; line
5470 (let* ((syntax (vhdl-get-syntactic-context))
5471 (len (length syntax))
5472 (ic (format "%s" (car (nth (1- len) syntax)))))
5475 (offset (vhdl-read-offset langelem)))
5476 (list langelem offset current-prefix-arg)))
5477 ;; sanity check offset
5478 (or (eq offset '+)
5479 (eq offset '-)
5480 (eq offset '++)
5481 (eq offset '--)
5482 (integerp offset)
5483 (fboundp offset)
5484 (boundp offset)
5485 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5486 offset))
5487 (let ((entry (assq symbol vhdl-offsets-alist)))
5488 (if entry
5489 (setcdr entry offset)
5490 (if add-p
5491 (setq vhdl-offsets-alist
5492 (cons (cons symbol offset) vhdl-offsets-alist))
5493 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5494 (vhdl-keep-region-active))
5496 (defun vhdl-set-style (style &optional local)
5497 "Set `vhdl-mode' variables to use one of several different indentation styles.
5498 STYLE is a string representing the desired style and optional LOCAL is
5499 a flag which, if non-nil, means to make the style variables being
5500 changed buffer local, instead of the default, which is to set the
5501 global variables. Interactively, the flag comes from the prefix
5502 argument. The styles are chosen from the `vhdl-style-alist' variable."
5503 (interactive (list (completing-read "Use which VHDL indentation style? "
5504 vhdl-style-alist nil t)
5505 current-prefix-arg))
5506 (let ((vars (cdr (assoc style vhdl-style-alist))))
5507 (or vars
5508 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5509 ;; set all the variables
5510 (mapc
5511 (function
5512 (lambda (varentry)
5513 (let ((var (car varentry))
5514 (val (cdr varentry)))
5515 ;; special case for vhdl-offsets-alist
5516 (if (not (eq var 'vhdl-offsets-alist))
5517 (set (if local (make-local-variable var) var) val)
5518 ;; reset vhdl-offsets-alist to the default value first
5519 (set (if local (make-local-variable var) var)
5520 (copy-alist vhdl-offsets-alist-default))
5521 ;; now set the langelems that are different
5522 (mapcar
5523 (function
5524 (lambda (langentry)
5525 (let ((langelem (car langentry))
5526 (offset (cdr langentry)))
5527 (vhdl-set-offset langelem offset)
5529 val))
5531 vars))
5532 (vhdl-keep-region-active))
5534 (defun vhdl-get-offset (langelem)
5535 "Get offset from LANGELEM which is a cons cell of the form:
5536 \(SYMBOL . RELPOS). The symbol is matched against
5537 vhdl-offsets-alist and the offset found there is either returned,
5538 or added to the indentation at RELPOS. If RELPOS is nil, then
5539 the offset is simply returned."
5540 (let* ((symbol (car langelem))
5541 (relpos (cdr langelem))
5542 (match (assq symbol vhdl-offsets-alist))
5543 (offset (cdr-safe match)))
5544 ;; offset can be a number, a function, a variable, or one of the
5545 ;; symbols + or -
5546 (cond
5547 ((not match)
5548 (if vhdl-strict-syntax-p
5549 (error "ERROR: Don't know how to indent a %s" symbol)
5550 (setq offset 0
5551 relpos 0)))
5552 ((eq offset '+) (setq offset vhdl-basic-offset))
5553 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5554 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5555 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5556 ((and (not (numberp offset))
5557 (fboundp offset))
5558 (setq offset (funcall offset langelem)))
5559 ((not (numberp offset))
5560 (setq offset (eval offset)))
5562 (+ (if (and relpos
5563 (< relpos (vhdl-point 'bol)))
5564 (save-excursion
5565 (goto-char relpos)
5566 (current-column))
5568 offset)))
5570 ;; Syntactic support functions:
5572 (defun vhdl-in-comment-p ()
5573 "Check if point is in a comment."
5574 (eq (vhdl-in-literal) 'comment))
5576 (defun vhdl-in-string-p ()
5577 "Check if point is in a string."
5578 (eq (vhdl-in-literal) 'string))
5580 (defun vhdl-in-quote-p ()
5581 "Check if point is in a quote ('x')."
5582 (or (and (> (point) (point-min))
5583 (< (1+ (point)) (point-max))
5584 (= (char-before (point)) ?\')
5585 (= (char-after (1+ (point))) ?\'))
5586 (and (> (1- (point)) (point-min))
5587 (< (point) (point-max))
5588 (= (char-before (1- (point))) ?\')
5589 (= (char-after (point)) ?\'))))
5591 (defun vhdl-in-literal ()
5592 "Determine if point is in a VHDL literal."
5593 (save-excursion
5594 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5595 (cond
5596 ((nth 3 state) 'string)
5597 ((nth 4 state) 'comment)
5598 ((vhdl-beginning-of-macro) 'pound)
5599 (t nil)))))
5601 (defun vhdl-in-extended-identifier-p ()
5602 "Determine if point is inside extended identifier (delimited by '\')."
5603 (save-match-data
5604 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5605 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5607 (defun vhdl-forward-comment (&optional direction)
5608 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5609 negative, skip forward otherwise."
5610 (interactive "p")
5611 (if (and direction (< direction 0))
5612 ;; skip backwards
5613 (progn
5614 (skip-chars-backward " \t\n\r\f")
5615 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5616 (goto-char (match-beginning 3))
5617 (skip-chars-backward " \t\n\r\f")))
5618 ;; skip forwards
5619 (skip-chars-forward " \t\n\r\f")
5620 (while (looking-at "--.*")
5621 (goto-char (match-end 0))
5622 (skip-chars-forward " \t\n\r\f"))))
5624 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5625 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5626 (defalias 'vhdl-forward-comment 'forward-comment))
5628 (defun vhdl-back-to-indentation ()
5629 "Move point to the first non-whitespace character on this line."
5630 (interactive)
5631 (beginning-of-line 1)
5632 (skip-syntax-forward " " (vhdl-point 'eol)))
5634 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5635 (when (featurep 'xemacs)
5636 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5638 ;; This is the best we can do in Win-Emacs.
5639 (defun vhdl-win-il (&optional lim)
5640 "Determine if point is in a VHDL literal."
5641 (save-excursion
5642 (let* ((here (point))
5643 (state nil)
5644 (match nil)
5645 (lim (or lim (vhdl-point 'bod))))
5646 (goto-char lim )
5647 (while (< (point) here)
5648 (setq match
5649 (and (re-search-forward "--\\|[\"']"
5650 here 'move)
5651 (buffer-substring (match-beginning 0) (match-end 0))))
5652 (setq state
5653 (cond
5654 ;; no match
5655 ((null match) nil)
5656 ;; looking at the opening of a VHDL style comment
5657 ((string= "--" match)
5658 (if (<= here (progn (end-of-line) (point))) 'comment))
5659 ;; looking at the opening of a double quote string
5660 ((string= "\"" match)
5661 (if (not (save-restriction
5662 ;; this seems to be necessary since the
5663 ;; re-search-forward will not work without it
5664 (narrow-to-region (point) here)
5665 (re-search-forward
5666 ;; this regexp matches a double quote
5667 ;; which is preceded by an even number
5668 ;; of backslashes, including zero
5669 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5670 'string))
5671 ;; looking at the opening of a single quote string
5672 ((string= "'" match)
5673 (if (not (save-restriction
5674 ;; see comments from above
5675 (narrow-to-region (point) here)
5676 (re-search-forward
5677 ;; this matches a single quote which is
5678 ;; preceded by zero or two backslashes.
5679 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5680 here 'move)))
5681 'string))
5682 (t nil)))
5683 ) ; end-while
5684 state)))
5686 (and (string-match "Win-Emacs" emacs-version)
5687 (fset 'vhdl-in-literal 'vhdl-win-il))
5689 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5690 ;; defined as lexical whitespace or comments. Search no farther back
5691 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5692 ;; used for backward skipping, (point-max) is used for forward
5693 ;; skipping.
5695 (defun vhdl-forward-syntactic-ws (&optional lim)
5696 "Forward skip of syntactic whitespace."
5697 (let* ((here (point-max))
5698 (hugenum (point-max)))
5699 (while (/= here (point))
5700 (setq here (point))
5701 (vhdl-forward-comment hugenum)
5702 ;; skip preprocessor directives
5703 (when (and (eq (char-after) ?#)
5704 (= (vhdl-point 'boi) (point)))
5705 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5706 (= (forward-line 1) 0)))
5707 (end-of-line)))
5708 (if lim (goto-char (min (point) lim)))))
5711 ;; This is the best we can do in Win-Emacs.
5712 (defun vhdl-win-fsws (&optional lim)
5713 "Forward skip syntactic whitespace for Win-Emacs."
5714 (let ((lim (or lim (point-max)))
5715 stop)
5716 (while (not stop)
5717 (skip-chars-forward " \t\n\r\f" lim)
5718 (cond
5719 ;; vhdl comment
5720 ((looking-at "--") (end-of-line))
5721 ;; none of the above
5722 (t (setq stop t))))))
5724 (and (string-match "Win-Emacs" emacs-version)
5725 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5727 (defun vhdl-beginning-of-macro (&optional lim)
5728 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5729 (let ((here (point)))
5730 (beginning-of-line)
5731 (while (eq (char-before (1- (point))) ?\\)
5732 (forward-line -1))
5733 (back-to-indentation)
5734 (if (and (<= (point) here)
5735 (eq (char-after) ?#))
5737 (goto-char here)
5738 nil)))
5740 (defun vhdl-backward-syntactic-ws (&optional lim)
5741 "Backward skip over syntactic whitespace."
5742 (let* ((here (point-min))
5743 (hugenum (- (point-max))))
5744 (while (/= here (point))
5745 (setq here (point))
5746 (vhdl-forward-comment hugenum)
5747 (vhdl-beginning-of-macro))
5748 (if lim (goto-char (max (point) lim)))))
5750 ;; This is the best we can do in Win-Emacs.
5751 (defun vhdl-win-bsws (&optional lim)
5752 "Backward skip syntactic whitespace for Win-Emacs."
5753 (let ((lim (or lim (vhdl-point 'bod)))
5754 stop)
5755 (while (not stop)
5756 (skip-chars-backward " \t\n\r\f" lim)
5757 (cond
5758 ;; vhdl comment
5759 ((eq (vhdl-in-literal) 'comment)
5760 (skip-chars-backward "^-" lim)
5761 (skip-chars-backward "-" lim)
5762 (while (not (or (and (= (following-char) ?-)
5763 (= (char-after (1+ (point))) ?-))
5764 (<= (point) lim)))
5765 (skip-chars-backward "^-" lim)
5766 (skip-chars-backward "-" lim)))
5767 ;; none of the above
5768 (t (setq stop t))))))
5770 (and (string-match "Win-Emacs" emacs-version)
5771 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5773 ;; Functions to help finding the correct indentation column:
5775 (defun vhdl-first-word (point)
5776 "If the keyword at POINT is at boi, then return (current-column) at
5777 that point, else nil."
5778 (save-excursion
5779 (and (goto-char point)
5780 (eq (point) (vhdl-point 'boi))
5781 (current-column))))
5783 (defun vhdl-last-word (point)
5784 "If the keyword at POINT is at eoi, then return (current-column) at
5785 that point, else nil."
5786 (save-excursion
5787 (and (goto-char point)
5788 (save-excursion (or (eq (progn (forward-sexp) (point))
5789 (vhdl-point 'eoi))
5790 (looking-at "\\s-*\\(--\\)?")))
5791 (current-column))))
5793 ;; Core syntactic evaluation functions:
5795 (defconst vhdl-libunit-re
5796 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5798 (defun vhdl-libunit-p ()
5799 (and
5800 (save-excursion
5801 (forward-sexp)
5802 (skip-chars-forward " \t\n\r\f")
5803 (not (looking-at "is\\b[^_]")))
5804 (save-excursion
5805 (backward-sexp)
5806 (and (not (looking-at "use\\b[^_]"))
5807 (progn
5808 (forward-sexp)
5809 (vhdl-forward-syntactic-ws)
5810 (/= (following-char) ?:))))
5813 (defconst vhdl-defun-re
5814 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5816 (defun vhdl-defun-p ()
5817 (save-excursion
5818 (if (looking-at "block\\|process\\|procedural")
5819 ;; "block", "process", "procedural":
5820 (save-excursion
5821 (backward-sexp)
5822 (not (looking-at "end\\s-+\\w")))
5823 ;; "architecture", "configuration", "entity",
5824 ;; "package", "procedure", "function":
5825 t)))
5827 (defun vhdl-corresponding-defun ()
5828 "If the word at the current position corresponds to a \"defun\"
5829 keyword, then return a string that can be used to find the
5830 corresponding \"begin\" keyword, else return nil."
5831 (save-excursion
5832 (and (looking-at vhdl-defun-re)
5833 (vhdl-defun-p)
5834 (if (looking-at "block\\|process\\|procedural")
5835 ;; "block", "process". "procedural:
5836 (buffer-substring (match-beginning 0) (match-end 0))
5837 ;; "architecture", "configuration", "entity", "package",
5838 ;; "procedure", "function":
5839 "is"))))
5841 (defconst vhdl-begin-fwd-re
5842 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5843 "A regular expression for searching forward that matches all known
5844 \"begin\" keywords.")
5846 (defconst vhdl-begin-bwd-re
5847 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5848 "A regular expression for searching backward that matches all known
5849 \"begin\" keywords.")
5851 (defun vhdl-begin-p (&optional lim)
5852 "Return t if we are looking at a real \"begin\" keyword.
5853 Assumes that the caller will make sure that we are looking at
5854 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5855 the middle of an identifier that just happens to contain a \"begin\"
5856 keyword."
5857 (cond
5858 ;; "[architecture|case|configuration|entity|package|
5859 ;; procedure|function] ... is":
5860 ((and (looking-at "i")
5861 (save-excursion
5862 ;; Skip backward over first sexp (needed to skip over a
5863 ;; procedure interface list, and is harmless in other
5864 ;; situations). Note that we need "return" in the
5865 ;; following search list so that we don't run into
5866 ;; semicolons in the function interface list.
5867 (backward-sexp)
5868 (let (foundp)
5869 (while (and (not foundp)
5870 (re-search-backward
5871 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5872 lim 'move))
5873 (if (or (= (preceding-char) ?_)
5874 (vhdl-in-literal))
5875 (backward-char)
5876 (setq foundp t))))
5877 (and (/= (following-char) ?\;)
5878 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5880 ;; "begin", "then", "use":
5881 ((looking-at "be\\|t\\|use")
5883 ;; "else":
5884 ((and (looking-at "e")
5885 ;; make sure that the "else" isn't inside a
5886 ;; conditional signal assignment.
5887 (save-excursion
5888 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5889 (or (eq (following-char) ?\;)
5890 (eq (point) lim))))
5892 ;; "block", "generate", "loop", "process", "procedural",
5893 ;; "units", "record", "protected body":
5894 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
5895 (save-excursion
5896 (backward-sexp)
5897 (not (looking-at "end\\s-+\\w"))))
5899 ;; "component":
5900 ((and (looking-at "c")
5901 (save-excursion
5902 (backward-sexp)
5903 (not (looking-at "end\\s-+\\w")))
5904 ;; look out for the dreaded entity class in an attribute
5905 (save-excursion
5906 (vhdl-backward-syntactic-ws lim)
5907 (/= (preceding-char) ?:)))
5909 ;; "for" (inside configuration declaration):
5910 ((and (looking-at "f")
5911 (save-excursion
5912 (backward-sexp)
5913 (not (looking-at "end\\s-+\\w")))
5914 (vhdl-has-syntax 'configuration))
5918 (defun vhdl-corresponding-mid (&optional lim)
5919 (cond
5920 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5921 "begin")
5922 ((looking-at "then\\|use")
5923 "<else>")
5925 "end")))
5927 (defun vhdl-corresponding-end (&optional lim)
5928 "If the word at the current position corresponds to a \"begin\"
5929 keyword, then return a vector containing enough information to find
5930 the corresponding \"end\" keyword, else return nil. The keyword to
5931 search forward for is aref 0. The column in which the keyword must
5932 appear is aref 1 or nil if any column is suitable.
5933 Assumes that the caller will make sure that we are not in the middle
5934 of an identifier that just happens to contain a \"begin\" keyword."
5935 (save-excursion
5936 (and (looking-at vhdl-begin-fwd-re)
5937 (or (not (looking-at "\\<use\\>"))
5938 (save-excursion (back-to-indentation)
5939 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
5940 (/= (preceding-char) ?_)
5941 (not (vhdl-in-literal))
5942 (vhdl-begin-p lim)
5943 (cond
5944 ;; "is", "generate", "loop":
5945 ((looking-at "[igl]")
5946 (vector "end"
5947 (and (vhdl-last-word (point))
5948 (or (vhdl-first-word (point))
5949 (save-excursion
5950 (vhdl-beginning-of-statement-1 lim)
5951 (vhdl-backward-skip-label lim)
5952 (vhdl-first-word (point)))))))
5953 ;; "begin", "else", "for":
5954 ((looking-at "be\\|[ef]")
5955 (vector "end"
5956 (and (vhdl-last-word (point))
5957 (or (vhdl-first-word (point))
5958 (save-excursion
5959 (vhdl-beginning-of-statement-1 lim)
5960 (vhdl-backward-skip-label lim)
5961 (vhdl-first-word (point)))))))
5962 ;; "component", "units", "record", "protected body":
5963 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
5964 ;; The first end found will close the block
5965 (vector "end" nil))
5966 ;; "block", "process", "procedural":
5967 ((looking-at "bl\\|p")
5968 (vector "end"
5969 (or (vhdl-first-word (point))
5970 (save-excursion
5971 (vhdl-beginning-of-statement-1 lim)
5972 (vhdl-backward-skip-label lim)
5973 (vhdl-first-word (point))))))
5974 ;; "then":
5975 ((looking-at "t\\|use")
5976 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
5977 (and (vhdl-last-word (point))
5978 (or (vhdl-first-word (point))
5979 (save-excursion
5980 (vhdl-beginning-of-statement-1 lim)
5981 (vhdl-backward-skip-label lim)
5982 (vhdl-first-word (point)))))))
5983 ))))
5985 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5987 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5989 (defun vhdl-end-p (&optional lim)
5990 "Return t if we are looking at a real \"end\" keyword.
5991 Assumes that the caller will make sure that we are looking at
5992 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5993 the middle of an identifier that just happens to contain an \"end\"
5994 keyword."
5995 (or (not (looking-at "else"))
5996 ;; make sure that the "else" isn't inside a conditional signal
5997 ;; assignment.
5998 (save-excursion
5999 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6000 (or (eq (following-char) ?\;)
6001 (eq (point) lim)
6002 (vhdl-in-literal)))))
6004 (defun vhdl-corresponding-begin (&optional lim)
6005 "If the word at the current position corresponds to an \"end\"
6006 keyword, then return a vector containing enough information to find
6007 the corresponding \"begin\" keyword, else return nil. The keyword to
6008 search backward for is aref 0. The column in which the keyword must
6009 appear is aref 1 or nil if any column is suitable. The supplementary
6010 keyword to search forward for is aref 2 or nil if this is not
6011 required. If aref 3 is t, then the \"begin\" keyword may be found in
6012 the middle of a statement.
6013 Assumes that the caller will make sure that we are not in the middle
6014 of an identifier that just happens to contain an \"end\" keyword."
6015 (save-excursion
6016 (let (pos)
6017 (if (and (looking-at vhdl-end-fwd-re)
6018 (not (vhdl-in-literal))
6019 (vhdl-end-p lim))
6020 (if (looking-at "el")
6021 ;; "else", "elsif":
6022 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
6023 ;; "end ...":
6024 (setq pos (point))
6025 (forward-sexp)
6026 (skip-chars-forward " \t\n\r\f")
6027 (cond
6028 ;; "end if":
6029 ((looking-at "if\\b[^_]")
6030 (vector "else\\|elsif\\|if"
6031 (vhdl-first-word pos)
6032 "else\\|then\\|use" nil))
6033 ;; "end component":
6034 ((looking-at "component\\b[^_]")
6035 (vector (buffer-substring (match-beginning 1)
6036 (match-end 1))
6037 (vhdl-first-word pos)
6038 nil nil))
6039 ;; "end units", "end record", "end protected":
6040 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6041 (vector (buffer-substring (match-beginning 1)
6042 (match-end 1))
6043 (vhdl-first-word pos)
6044 nil t))
6045 ;; "end block", "end process", "end procedural":
6046 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6047 (vector "begin" (vhdl-first-word pos) nil nil))
6048 ;; "end case":
6049 ((looking-at "case\\b[^_]")
6050 (vector "case" (vhdl-first-word pos) "is" nil))
6051 ;; "end generate":
6052 ((looking-at "generate\\b[^_]")
6053 (vector "generate\\|for\\|if"
6054 (vhdl-first-word pos)
6055 "generate" nil))
6056 ;; "end loop":
6057 ((looking-at "loop\\b[^_]")
6058 (vector "loop\\|while\\|for"
6059 (vhdl-first-word pos)
6060 "loop" nil))
6061 ;; "end for" (inside configuration declaration):
6062 ((looking-at "for\\b[^_]")
6063 (vector "for" (vhdl-first-word pos) nil nil))
6064 ;; "end [id]":
6066 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
6067 (vhdl-first-word pos)
6068 ;; return an alist of (statement . keyword) mappings
6070 ;; "begin ... end [id]":
6071 ("begin" . nil)
6072 ;; "architecture ... is ... begin ... end [id]":
6073 ("architecture" . "is")
6074 ;; "configuration ... is ... end [id]":
6075 ("configuration" . "is")
6076 ;; "entity ... is ... end [id]":
6077 ("entity" . "is")
6078 ;; "package ... is ... end [id]":
6079 ("package" . "is")
6080 ;; "procedure ... is ... begin ... end [id]":
6081 ("procedure" . "is")
6082 ;; "function ... is ... begin ... end [id]":
6083 ("function" . "is")
6085 nil))
6086 ))) ; "end ..."
6089 (defconst vhdl-leader-re
6090 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6092 (defun vhdl-end-of-leader ()
6093 (save-excursion
6094 (cond ((looking-at "block\\|process\\|procedural")
6095 (if (save-excursion
6096 (forward-sexp)
6097 (skip-chars-forward " \t\n\r\f")
6098 (= (following-char) ?\())
6099 (forward-sexp 2)
6100 (forward-sexp))
6101 (when (looking-at "[ \t\n\r\f]*is")
6102 (goto-char (match-end 0)))
6103 (point))
6104 ((looking-at "component")
6105 (forward-sexp 2)
6106 (when (looking-at "[ \t\n\r\f]*is")
6107 (goto-char (match-end 0)))
6108 (point))
6109 ((looking-at "for")
6110 (forward-sexp 2)
6111 (skip-chars-forward " \t\n\r\f")
6112 (while (looking-at "[,:(]")
6113 (forward-sexp)
6114 (skip-chars-forward " \t\n\r\f"))
6115 (point))
6116 (t nil)
6119 (defconst vhdl-trailer-re
6120 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6122 (defconst vhdl-statement-fwd-re
6123 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6124 "A regular expression for searching forward that matches all known
6125 \"statement\" keywords.")
6127 (defconst vhdl-statement-bwd-re
6128 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6129 "A regular expression for searching backward that matches all known
6130 \"statement\" keywords.")
6132 (defun vhdl-statement-p (&optional lim)
6133 "Return t if we are looking at a real \"statement\" keyword.
6134 Assumes that the caller will make sure that we are looking at
6135 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6136 in the middle of an identifier that just happens to contain a
6137 \"statement\" keyword."
6138 (cond
6139 ;; "for" ... "generate":
6140 ((and (looking-at "f")
6141 ;; Make sure it's the start of a parameter specification.
6142 (save-excursion
6143 (forward-sexp 2)
6144 (skip-chars-forward " \t\n\r\f")
6145 (looking-at "in\\b[^_]"))
6146 ;; Make sure it's not an "end for".
6147 (save-excursion
6148 (backward-sexp)
6149 (not (looking-at "end\\s-+\\w"))))
6151 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6152 ((and (looking-at "i")
6153 ;; Make sure it's not an "end if".
6154 (save-excursion
6155 (backward-sexp)
6156 (not (looking-at "end\\s-+\\w"))))
6158 ;; "while" ... "loop":
6159 ((looking-at "w")
6163 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6164 "Regexp describing a case statement alternative key.")
6166 (defun vhdl-case-alternative-p (&optional lim)
6167 "Return t if we are looking at a real case alternative.
6168 Assumes that the caller will make sure that we are looking at
6169 vhdl-case-alternative-re, and are not inside a literal, and that
6170 we are not in the middle of an identifier that just happens to
6171 contain a \"when\" keyword."
6172 (save-excursion
6173 (let (foundp)
6174 (while (and (not foundp)
6175 (re-search-backward ";\\|<=" lim 'move))
6176 (if (or (= (preceding-char) ?_)
6177 (vhdl-in-literal))
6178 (backward-char)
6179 (setq foundp t)))
6180 (or (eq (following-char) ?\;)
6181 (eq (point) lim)))
6184 ;; Core syntactic movement functions:
6186 (defconst vhdl-b-t-b-re
6187 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6189 (defun vhdl-backward-to-block (&optional lim)
6190 "Move backward to the previous \"begin\" or \"end\" keyword."
6191 (let (foundp)
6192 (while (and (not foundp)
6193 (re-search-backward vhdl-b-t-b-re lim 'move))
6194 (if (or (= (preceding-char) ?_)
6195 (vhdl-in-literal))
6196 (backward-char)
6197 (cond
6198 ;; "begin" keyword:
6199 ((and (looking-at vhdl-begin-fwd-re)
6200 (or (not (looking-at "\\<use\\>"))
6201 (save-excursion (back-to-indentation)
6202 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6203 (/= (preceding-char) ?_)
6204 (vhdl-begin-p lim))
6205 (setq foundp 'begin))
6206 ;; "end" keyword:
6207 ((and (looking-at vhdl-end-fwd-re)
6208 (/= (preceding-char) ?_)
6209 (vhdl-end-p lim))
6210 (setq foundp 'end))
6213 foundp
6216 (defun vhdl-forward-sexp (&optional count lim)
6217 "Move forward across one balanced expression (sexp).
6218 With COUNT, do it that many times."
6219 (interactive "p")
6220 (let ((count (or count 1))
6221 (case-fold-search t)
6222 end-vec target)
6223 (save-excursion
6224 (while (> count 0)
6225 ;; skip whitespace
6226 (skip-chars-forward " \t\n\r\f")
6227 ;; Check for an unbalanced "end" keyword
6228 (if (and (looking-at vhdl-end-fwd-re)
6229 (/= (preceding-char) ?_)
6230 (not (vhdl-in-literal))
6231 (vhdl-end-p lim)
6232 (not (looking-at "else")))
6233 (error
6234 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6235 ;; If the current keyword is a "begin" keyword, then find the
6236 ;; corresponding "end" keyword.
6237 (if (setq end-vec (vhdl-corresponding-end lim))
6238 (let (
6239 ;; end-re is the statement keyword to search for
6240 (end-re
6241 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6242 ;; column is either the statement keyword target column
6243 ;; or nil
6244 (column (aref end-vec 1))
6245 (eol (vhdl-point 'eol))
6246 foundp literal placeholder)
6247 ;; Look for the statement keyword.
6248 (while (and (not foundp)
6249 (re-search-forward end-re nil t)
6250 (setq placeholder (match-end 1))
6251 (goto-char (match-beginning 0)))
6252 ;; If we are in a literal, or not in the right target
6253 ;; column and not on the same line as the begin, then
6254 ;; try again.
6255 (if (or (and column
6256 (/= (current-indentation) column)
6257 (> (point) eol))
6258 (= (preceding-char) ?_)
6259 (setq literal (vhdl-in-literal)))
6260 (if (eq literal 'comment)
6261 (end-of-line)
6262 (forward-char))
6263 ;; An "else" keyword corresponds to both the opening brace
6264 ;; of the following sexp and the closing brace of the
6265 ;; previous sexp.
6266 (if (not (looking-at "else"))
6267 (goto-char placeholder))
6268 (setq foundp t))
6270 (if (not foundp)
6271 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6273 ;; If the current keyword is not a "begin" keyword, then just
6274 ;; perform the normal forward-sexp.
6275 (forward-sexp)
6277 (setq count (1- count))
6279 (setq target (point)))
6280 (goto-char target)
6281 nil))
6283 (defun vhdl-backward-sexp (&optional count lim)
6284 "Move backward across one balanced expression (sexp).
6285 With COUNT, do it that many times. LIM bounds any required backward
6286 searches."
6287 (interactive "p")
6288 (let ((count (or count 1))
6289 (case-fold-search t)
6290 begin-vec target)
6291 (save-excursion
6292 (while (> count 0)
6293 ;; Perform the normal backward-sexp, unless we are looking at
6294 ;; "else" - an "else" keyword corresponds to both the opening brace
6295 ;; of the following sexp and the closing brace of the previous sexp.
6296 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6297 (/= (preceding-char) ?_)
6298 (not (vhdl-in-literal)))
6300 (backward-sexp)
6301 (if (and (looking-at vhdl-begin-fwd-re)
6302 (or (not (looking-at "\\<use\\>"))
6303 (save-excursion
6304 (back-to-indentation)
6305 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6306 (/= (preceding-char) ?_)
6307 (not (vhdl-in-literal))
6308 (vhdl-begin-p lim))
6309 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6310 ;; If the current keyword is an "end" keyword, then find the
6311 ;; corresponding "begin" keyword.
6312 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6313 (/= (preceding-char) ?_))
6314 (let (
6315 ;; begin-re is the statement keyword to search for
6316 (begin-re
6317 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6318 ;; column is either the statement keyword target column
6319 ;; or nil
6320 (column (aref begin-vec 1))
6321 ;; internal-p controls where the statement keyword can
6322 ;; be found.
6323 (internal-p (aref begin-vec 3))
6324 (last-backward (point)) last-forward
6325 foundp literal keyword)
6326 ;; Look for the statement keyword.
6327 (while (and (not foundp)
6328 (re-search-backward begin-re lim t)
6329 (setq keyword
6330 (buffer-substring (match-beginning 1)
6331 (match-end 1))))
6332 ;; If we are in a literal or in the wrong column,
6333 ;; then try again.
6334 (if (or (and column
6335 (and (/= (current-indentation) column)
6336 ;; possibly accept current-column as
6337 ;; well as current-indentation.
6338 (or (not internal-p)
6339 (/= (current-column) column))))
6340 (= (preceding-char) ?_)
6341 (vhdl-in-literal))
6342 (backward-char)
6343 ;; If there is a supplementary keyword, then
6344 ;; search forward for it.
6345 (if (and (setq begin-re (aref begin-vec 2))
6346 (or (not (listp begin-re))
6347 ;; If begin-re is an alist, then find the
6348 ;; element corresponding to the actual
6349 ;; keyword that we found.
6350 (progn
6351 (setq begin-re
6352 (assoc keyword begin-re))
6353 (and begin-re
6354 (setq begin-re (cdr begin-re))))))
6355 (and
6356 (setq begin-re
6357 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6358 (save-excursion
6359 (setq last-forward (point))
6360 ;; Look for the supplementary keyword
6361 ;; (bounded by the backward search start
6362 ;; point).
6363 (while (and (not foundp)
6364 (re-search-forward begin-re
6365 last-backward t)
6366 (goto-char (match-beginning 1)))
6367 ;; If we are in a literal, then try again.
6368 (if (or (= (preceding-char) ?_)
6369 (setq literal
6370 (vhdl-in-literal)))
6371 (if (eq literal 'comment)
6372 (goto-char
6373 (min (vhdl-point 'eol) last-backward))
6374 (forward-char))
6375 ;; We have found the supplementary keyword.
6376 ;; Save the position of the keyword in foundp.
6377 (setq foundp (point)))
6379 foundp)
6380 ;; If the supplementary keyword was found, then
6381 ;; move point to the supplementary keyword.
6382 (goto-char foundp))
6383 ;; If there was no supplementary keyword, then
6384 ;; point is already at the statement keyword.
6385 (setq foundp t)))
6386 ) ; end of the search for the statement keyword
6387 (if (not foundp)
6388 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6390 (setq count (1- count))
6392 (setq target (point)))
6393 (goto-char target)
6394 nil))
6396 (defun vhdl-backward-up-list (&optional count limit)
6397 "Move backward out of one level of blocks.
6398 With argument, do this that many times."
6399 (interactive "p")
6400 (let ((count (or count 1))
6401 target)
6402 (save-excursion
6403 (while (> count 0)
6404 (if (looking-at vhdl-defun-re)
6405 (error "ERROR: Unbalanced blocks"))
6406 (vhdl-backward-to-block limit)
6407 (setq count (1- count)))
6408 (setq target (point)))
6409 (goto-char target)))
6411 (defun vhdl-end-of-defun (&optional count)
6412 "Move forward to the end of a VHDL defun."
6413 (interactive)
6414 (let ((case-fold-search t))
6415 (vhdl-beginning-of-defun)
6416 (if (not (looking-at "block\\|process\\|procedural"))
6417 (re-search-forward "\\bis\\b"))
6418 (vhdl-forward-sexp)))
6420 (defun vhdl-mark-defun ()
6421 "Put mark at end of this \"defun\", point at beginning."
6422 (interactive)
6423 (let ((case-fold-search t))
6424 (push-mark)
6425 (vhdl-beginning-of-defun)
6426 (push-mark)
6427 (if (not (looking-at "block\\|process\\|procedural"))
6428 (re-search-forward "\\bis\\b"))
6429 (vhdl-forward-sexp)
6430 (exchange-point-and-mark)))
6432 (defun vhdl-beginning-of-libunit ()
6433 "Move backward to the beginning of a VHDL library unit.
6434 Returns the location of the corresponding begin keyword, unless search
6435 stops due to beginning or end of buffer.
6436 Note that if point is between the \"libunit\" keyword and the
6437 corresponding \"begin\" keyword, then that libunit will not be
6438 recognized, and the search will continue backwards. If point is
6439 at the \"begin\" keyword, then the defun will be recognized. The
6440 returned point is at the first character of the \"libunit\" keyword."
6441 (let ((last-forward (point))
6442 (last-backward
6443 ;; Just in case we are actually sitting on the "begin"
6444 ;; keyword, allow for the keyword and an extra character,
6445 ;; as this will be used when looking forward for the
6446 ;; "begin" keyword.
6447 (save-excursion (forward-word 1) (1+ (point))))
6448 foundp literal placeholder)
6449 ;; Find the "libunit" keyword.
6450 (while (and (not foundp)
6451 (re-search-backward vhdl-libunit-re nil 'move))
6452 ;; If we are in a literal, or not at a real libunit, then try again.
6453 (if (or (= (preceding-char) ?_)
6454 (vhdl-in-literal)
6455 (not (vhdl-libunit-p)))
6456 (backward-char)
6457 ;; Find the corresponding "begin" keyword.
6458 (setq last-forward (point))
6459 (while (and (not foundp)
6460 (re-search-forward "\\bis\\b[^_]" last-backward t)
6461 (setq placeholder (match-beginning 0)))
6462 (if (or (= (preceding-char) ?_)
6463 (setq literal (vhdl-in-literal)))
6464 ;; It wasn't a real keyword, so keep searching.
6465 (if (eq literal 'comment)
6466 (goto-char
6467 (min (vhdl-point 'eol) last-backward))
6468 (forward-char))
6469 ;; We have found the begin keyword, loop will exit.
6470 (setq foundp placeholder)))
6471 ;; Go back to the libunit keyword
6472 (goto-char last-forward)))
6473 foundp))
6475 (defun vhdl-beginning-of-defun (&optional count)
6476 "Move backward to the beginning of a VHDL defun.
6477 With argument, do it that many times.
6478 Returns the location of the corresponding begin keyword, unless search
6479 stops due to beginning or end of buffer."
6480 ;; Note that if point is between the "defun" keyword and the
6481 ;; corresponding "begin" keyword, then that defun will not be
6482 ;; recognized, and the search will continue backwards. If point is
6483 ;; at the "begin" keyword, then the defun will be recognized. The
6484 ;; returned point is at the first character of the "defun" keyword.
6485 (interactive "p")
6486 (let ((count (or count 1))
6487 (case-fold-search t)
6488 (last-forward (point))
6489 foundp)
6490 (while (> count 0)
6491 (setq foundp nil)
6492 (goto-char last-forward)
6493 (let ((last-backward
6494 ;; Just in case we are actually sitting on the "begin"
6495 ;; keyword, allow for the keyword and an extra character,
6496 ;; as this will be used when looking forward for the
6497 ;; "begin" keyword.
6498 (save-excursion (forward-word 1) (1+ (point))))
6499 begin-string literal)
6500 (while (and (not foundp)
6501 (re-search-backward vhdl-defun-re nil 'move))
6502 ;; If we are in a literal, then try again.
6503 (if (or (= (preceding-char) ?_)
6504 (vhdl-in-literal))
6505 (backward-char)
6506 (if (setq begin-string (vhdl-corresponding-defun))
6507 ;; This is a real defun keyword.
6508 ;; Find the corresponding "begin" keyword.
6509 ;; Look for the begin keyword.
6510 (progn
6511 ;; Save the search start point.
6512 (setq last-forward (point))
6513 (while (and (not foundp)
6514 (search-forward begin-string last-backward t))
6515 (if (or (= (preceding-char) ?_)
6516 (save-match-data
6517 (setq literal (vhdl-in-literal))))
6518 ;; It wasn't a real keyword, so keep searching.
6519 (if (eq literal 'comment)
6520 (goto-char
6521 (min (vhdl-point 'eol) last-backward))
6522 (forward-char))
6523 ;; We have found the begin keyword, loop will exit.
6524 (setq foundp (match-beginning 0)))
6526 ;; Go back to the defun keyword
6527 (goto-char last-forward)) ; end search for begin keyword
6529 ) ; end of the search for the defun keyword
6531 (setq count (1- count))
6533 (vhdl-keep-region-active)
6534 foundp))
6536 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6537 "Go to the beginning of the innermost VHDL statement.
6538 With prefix arg, go back N - 1 statements. If already at the
6539 beginning of a statement then go to the beginning of the preceding
6540 one. If within a string or comment, or next to a comment (only
6541 whitespace between), move by sentences instead of statements.
6543 When called from a program, this function takes 3 optional args: the
6544 prefix arg, a buffer position limit which is the farthest back to
6545 search, and an argument indicating an interactive call."
6546 (interactive "p\np")
6547 (let ((count (or count 1))
6548 (case-fold-search t)
6549 (lim (or lim (point-min)))
6550 (here (point))
6551 state)
6552 (save-excursion
6553 (goto-char lim)
6554 (setq state (parse-partial-sexp (point) here nil nil)))
6555 (if (and interactive
6556 (or (nth 3 state)
6557 (nth 4 state)
6558 (looking-at (concat "[ \t]*" comment-start-skip))))
6559 (forward-sentence (- count))
6560 (while (> count 0)
6561 (vhdl-beginning-of-statement-1 lim)
6562 (setq count (1- count))))
6563 ;; its possible we've been left up-buf of lim
6564 (goto-char (max (point) lim))
6566 (vhdl-keep-region-active))
6568 (defconst vhdl-e-o-s-re
6569 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6571 (defun vhdl-end-of-statement ()
6572 "Very simple implementation."
6573 (interactive)
6574 (re-search-forward vhdl-e-o-s-re))
6576 (defconst vhdl-b-o-s-re
6577 (concat ";[^_]\\|\([^_]\\|\)[^_]\\|\\bwhen\\b[^_]\\|"
6578 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6580 (defun vhdl-beginning-of-statement-1 (&optional lim)
6581 "Move to the start of the current statement, or the previous
6582 statement if already at the beginning of one."
6583 (let ((lim (or lim (point-min)))
6584 (here (point))
6585 (pos (point))
6586 donep)
6587 ;; go backwards one balanced expression, but be careful of
6588 ;; unbalanced paren being reached
6589 (if (not (vhdl-safe (progn (backward-sexp) t)))
6590 (progn
6591 (backward-up-list 1)
6592 (forward-char)
6593 (vhdl-forward-syntactic-ws here)
6594 (setq donep t)))
6595 (while (and (not donep)
6596 (not (bobp))
6597 ;; look backwards for a statement boundary
6598 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6599 (if (or (= (preceding-char) ?_)
6600 (vhdl-in-literal))
6601 (backward-char)
6602 (cond
6603 ;; If we are looking at an open paren, then stop after it
6604 ((eq (following-char) ?\()
6605 (forward-char)
6606 (vhdl-forward-syntactic-ws here)
6607 (setq donep t))
6608 ;; If we are looking at a close paren, then skip it
6609 ((eq (following-char) ?\))
6610 (forward-char)
6611 (setq pos (point))
6612 (backward-sexp)
6613 (if (< (point) lim)
6614 (progn (goto-char pos)
6615 (vhdl-forward-syntactic-ws here)
6616 (setq donep t))))
6617 ;; If we are looking at a semicolon, then stop
6618 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6619 (progn
6620 (forward-char)
6621 (vhdl-forward-syntactic-ws here)
6622 (setq donep t)))
6623 ;; If we are looking at a "begin", then stop
6624 ((and (looking-at vhdl-begin-fwd-re)
6625 (or (not (looking-at "\\<use\\>"))
6626 (save-excursion
6627 (back-to-indentation)
6628 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6629 (/= (preceding-char) ?_)
6630 (vhdl-begin-p nil))
6631 ;; If it's a leader "begin", then find the
6632 ;; right place
6633 (if (looking-at vhdl-leader-re)
6634 (save-excursion
6635 ;; set a default stop point at the begin
6636 (setq pos (point))
6637 ;; is the start point inside the leader area ?
6638 (goto-char (vhdl-end-of-leader))
6639 (vhdl-forward-syntactic-ws here)
6640 (if (< (point) here)
6641 ;; start point was not inside leader area
6642 ;; set stop point at word after leader
6643 (setq pos (point))))
6644 (forward-word 1)
6645 (vhdl-forward-syntactic-ws here)
6646 (setq pos (point)))
6647 (goto-char pos)
6648 (setq donep t))
6649 ;; If we are looking at a "statement", then stop
6650 ((and (looking-at vhdl-statement-fwd-re)
6651 (/= (preceding-char) ?_)
6652 (vhdl-statement-p nil))
6653 (setq donep t))
6654 ;; If we are looking at a case alternative key, then stop
6655 ((and (looking-at vhdl-case-alternative-re)
6656 (vhdl-case-alternative-p lim))
6657 (save-excursion
6658 ;; set a default stop point at the when
6659 (setq pos (point))
6660 ;; is the start point inside the case alternative key ?
6661 (looking-at vhdl-case-alternative-re)
6662 (goto-char (match-end 0))
6663 (vhdl-forward-syntactic-ws here)
6664 (if (< (point) here)
6665 ;; start point was not inside the case alternative key
6666 ;; set stop point at word after case alternative keyleader
6667 (setq pos (point))))
6668 (goto-char pos)
6669 (setq donep t))
6670 ;; Bogus find, continue
6672 (backward-char)))))
6675 ;; Defuns for calculating the current syntactic state:
6677 (defun vhdl-get-library-unit (bod placeholder)
6678 "If there is an enclosing library unit at BOD, with its \"begin\"
6679 keyword at PLACEHOLDER, then return the library unit type."
6680 (let ((here (vhdl-point 'bol)))
6681 (if (save-excursion
6682 (goto-char placeholder)
6683 (vhdl-safe (vhdl-forward-sexp 1 bod))
6684 (<= here (point)))
6685 (save-excursion
6686 (goto-char bod)
6687 (cond
6688 ((looking-at "e") 'entity)
6689 ((looking-at "a") 'architecture)
6690 ((looking-at "c") 'configuration)
6691 ((looking-at "p")
6692 (save-excursion
6693 (goto-char bod)
6694 (forward-sexp)
6695 (vhdl-forward-syntactic-ws here)
6696 (if (looking-at "body\\b[^_]")
6697 'package-body 'package))))))
6700 (defun vhdl-get-block-state (&optional lim)
6701 "Finds and records all the closest opens.
6702 LIM is the furthest back we need to search (it should be the
6703 previous libunit keyword)."
6704 (let ((here (point))
6705 (lim (or lim (point-min)))
6706 keyword sexp-start sexp-mid sexp-end
6707 preceding-sexp containing-sexp
6708 containing-begin containing-mid containing-paren)
6709 (save-excursion
6710 ;; Find the containing-paren, and use that as the limit
6711 (if (setq containing-paren
6712 (save-restriction
6713 (narrow-to-region lim (point))
6714 (vhdl-safe (scan-lists (point) -1 1))))
6715 (setq lim containing-paren))
6716 ;; Look backwards for "begin" and "end" keywords.
6717 (while (and (> (point) lim)
6718 (not containing-sexp))
6719 (setq keyword (vhdl-backward-to-block lim))
6720 (cond
6721 ((eq keyword 'begin)
6722 ;; Found a "begin" keyword
6723 (setq sexp-start (point))
6724 (setq sexp-mid (vhdl-corresponding-mid lim))
6725 (setq sexp-end (vhdl-safe
6726 (save-excursion
6727 (vhdl-forward-sexp 1 lim) (point))))
6728 (if (and sexp-end (<= sexp-end here))
6729 ;; we want to record this sexp, but we only want to
6730 ;; record the last-most of any of them before here
6731 (or preceding-sexp
6732 (setq preceding-sexp sexp-start))
6733 ;; we're contained in this sexp so put sexp-start on
6734 ;; front of list
6735 (setq containing-sexp sexp-start)
6736 (setq containing-mid sexp-mid)
6737 (setq containing-begin t)))
6738 ((eq keyword 'end)
6739 ;; Found an "end" keyword
6740 (forward-sexp)
6741 (setq sexp-end (point))
6742 (setq sexp-mid nil)
6743 (setq sexp-start
6744 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6745 (progn (backward-sexp) (point))))
6746 ;; we want to record this sexp, but we only want to
6747 ;; record the last-most of any of them before here
6748 (or preceding-sexp
6749 (setq preceding-sexp sexp-start)))
6751 ;; Check if the containing-paren should be the containing-sexp
6752 (if (and containing-paren
6753 (or (null containing-sexp)
6754 (< containing-sexp containing-paren)))
6755 (setq containing-sexp containing-paren
6756 preceding-sexp nil
6757 containing-begin nil
6758 containing-mid nil))
6759 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6763 (defconst vhdl-s-c-a-re
6764 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6766 (defun vhdl-skip-case-alternative (&optional lim)
6767 "Skip forward over case/when bodies, with optional maximal
6768 limit. If no next case alternative is found, nil is returned and
6769 point is not moved."
6770 (let ((lim (or lim (point-max)))
6771 (here (point))
6772 donep foundp)
6773 (while (and (< (point) lim)
6774 (not donep))
6775 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6776 (save-match-data
6777 (not (vhdl-in-literal)))
6778 (/= (match-beginning 0) here))
6779 (progn
6780 (goto-char (match-beginning 0))
6781 (cond
6782 ((and (looking-at "case")
6783 (re-search-forward "\\bis[^_]" lim t))
6784 (backward-sexp)
6785 (vhdl-forward-sexp))
6787 (setq donep t
6788 foundp t))))))
6789 (if (not foundp)
6790 (goto-char here))
6791 foundp))
6793 (defun vhdl-backward-skip-label (&optional lim)
6794 "Skip backward over a label, with optional maximal
6795 limit. If label is not found, nil is returned and point
6796 is not moved."
6797 (let ((lim (or lim (point-min)))
6798 placeholder)
6799 (if (save-excursion
6800 (vhdl-backward-syntactic-ws lim)
6801 (and (eq (preceding-char) ?:)
6802 (progn
6803 (backward-sexp)
6804 (setq placeholder (point))
6805 (looking-at vhdl-label-key))))
6806 (goto-char placeholder))
6809 (defun vhdl-forward-skip-label (&optional lim)
6810 "Skip forward over a label, with optional maximal
6811 limit. If label is not found, nil is returned and point
6812 is not moved."
6813 (let ((lim (or lim (point-max))))
6814 (if (looking-at vhdl-label-key)
6815 (progn
6816 (goto-char (match-end 0))
6817 (vhdl-forward-syntactic-ws lim)))
6820 (defun vhdl-get-syntactic-context ()
6821 "Guess the syntactic description of the current line of VHDL code."
6822 (save-excursion
6823 (save-restriction
6824 (beginning-of-line)
6825 (let* ((indent-point (point))
6826 (case-fold-search t)
6827 vec literal containing-sexp preceding-sexp
6828 containing-begin containing-mid containing-leader
6829 char-before-ip char-after-ip begin-after-ip end-after-ip
6830 placeholder lim library-unit
6833 ;; Reset the syntactic context
6834 (setq vhdl-syntactic-context nil)
6836 (save-excursion
6837 ;; Move to the start of the previous library unit, and
6838 ;; record the position of the "begin" keyword.
6839 (setq placeholder (vhdl-beginning-of-libunit))
6840 ;; The position of the "libunit" keyword gives us a gross
6841 ;; limit point.
6842 (setq lim (point))
6845 ;; If there is a previous library unit, and we are enclosed by
6846 ;; it, then set the syntax accordingly.
6847 (and placeholder
6848 (setq library-unit (vhdl-get-library-unit lim placeholder))
6849 (vhdl-add-syntax library-unit lim))
6851 ;; Find the surrounding state.
6852 (if (setq vec (vhdl-get-block-state lim))
6853 (progn
6854 (setq containing-sexp (aref vec 0))
6855 (setq preceding-sexp (aref vec 1))
6856 (setq containing-begin (aref vec 2))
6857 (setq containing-mid (aref vec 3))
6860 ;; set the limit on the farthest back we need to search
6861 (setq lim (if containing-sexp
6862 (save-excursion
6863 (goto-char containing-sexp)
6864 ;; set containing-leader if required
6865 (if (looking-at vhdl-leader-re)
6866 (setq containing-leader (vhdl-end-of-leader)))
6867 (vhdl-point 'bol))
6868 (point-min)))
6870 ;; cache char before and after indent point, and move point to
6871 ;; the most likely position to perform the majority of tests
6872 (goto-char indent-point)
6873 (skip-chars-forward " \t")
6874 (setq literal (vhdl-in-literal))
6875 (setq char-after-ip (following-char))
6876 (setq begin-after-ip (and
6877 (not literal)
6878 (looking-at vhdl-begin-fwd-re)
6879 (or (not (looking-at "\\<use\\>"))
6880 (save-excursion
6881 (back-to-indentation)
6882 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6883 (vhdl-begin-p)))
6884 (setq end-after-ip (and
6885 (not literal)
6886 (looking-at vhdl-end-fwd-re)
6887 (vhdl-end-p)))
6888 (vhdl-backward-syntactic-ws lim)
6889 (setq char-before-ip (preceding-char))
6890 (goto-char indent-point)
6891 (skip-chars-forward " \t")
6893 ;; now figure out syntactic qualities of the current line
6894 (cond
6895 ;; CASE 1: in a string or comment.
6896 ((memq literal '(string comment))
6897 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6898 ;; CASE 2: Line is at top level.
6899 ((null containing-sexp)
6900 ;; Find the point to which indentation will be relative
6901 (save-excursion
6902 (if (null preceding-sexp)
6903 ;; CASE 2X.1
6904 ;; no preceding-sexp -> use the preceding statement
6905 (vhdl-beginning-of-statement-1 lim)
6906 ;; CASE 2X.2
6907 ;; if there is a preceding-sexp then indent relative to it
6908 (goto-char preceding-sexp)
6909 ;; if not at boi, then the block-opening keyword is
6910 ;; probably following a label, so we need a different
6911 ;; relpos
6912 (if (/= (point) (vhdl-point 'boi))
6913 ;; CASE 2X.3
6914 (vhdl-beginning-of-statement-1 lim)))
6915 ;; v-b-o-s could have left us at point-min
6916 (and (bobp)
6917 ;; CASE 2X.4
6918 (vhdl-forward-syntactic-ws indent-point))
6919 (setq placeholder (point)))
6920 (cond
6921 ;; CASE 2A : we are looking at a block-open
6922 (begin-after-ip
6923 (vhdl-add-syntax 'block-open placeholder))
6924 ;; CASE 2B: we are looking at a block-close
6925 (end-after-ip
6926 (vhdl-add-syntax 'block-close placeholder))
6927 ;; CASE 2C: we are looking at a top-level statement
6928 ((progn
6929 (vhdl-backward-syntactic-ws lim)
6930 (or (bobp)
6931 (and (= (preceding-char) ?\;)
6932 (not (vhdl-in-quote-p)))))
6933 (vhdl-add-syntax 'statement placeholder))
6934 ;; CASE 2D: we are looking at a top-level statement-cont
6936 (vhdl-beginning-of-statement-1 lim)
6937 ;; v-b-o-s could have left us at point-min
6938 (and (bobp)
6939 ;; CASE 2D.1
6940 (vhdl-forward-syntactic-ws indent-point))
6941 (vhdl-add-syntax 'statement-cont (point)))
6942 )) ; end CASE 2
6943 ;; CASE 3: line is inside parentheses. Most likely we are
6944 ;; either in a subprogram argument (interface) list, or a
6945 ;; continued expression containing parentheses.
6946 ((null containing-begin)
6947 (vhdl-backward-syntactic-ws containing-sexp)
6948 (cond
6949 ;; CASE 3A: we are looking at the arglist closing paren
6950 ((eq char-after-ip ?\))
6951 (goto-char containing-sexp)
6952 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6953 ;; CASE 3B: we are looking at the first argument in an empty
6954 ;; argument list.
6955 ((eq char-before-ip ?\()
6956 (goto-char containing-sexp)
6957 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6958 ;; CASE 3C: we are looking at an arglist continuation line,
6959 ;; but the preceding argument is on the same line as the
6960 ;; opening paren. This case includes multi-line
6961 ;; expression paren groupings.
6962 ((and (save-excursion
6963 (goto-char (1+ containing-sexp))
6964 (skip-chars-forward " \t")
6965 (not (eolp))
6966 (not (looking-at "--")))
6967 (save-excursion
6968 (vhdl-beginning-of-statement-1 containing-sexp)
6969 (skip-chars-backward " \t(")
6970 (while (and (= (preceding-char) ?\;)
6971 (not (vhdl-in-quote-p)))
6972 (vhdl-beginning-of-statement-1 containing-sexp)
6973 (skip-chars-backward " \t("))
6974 (<= (point) containing-sexp)))
6975 (goto-char containing-sexp)
6976 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6977 ;; CASE 3D: we are looking at just a normal arglist
6978 ;; continuation line
6979 (t (vhdl-beginning-of-statement-1 containing-sexp)
6980 (vhdl-forward-syntactic-ws indent-point)
6981 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6983 ;; CASE 4: A block mid open
6984 ((and begin-after-ip
6985 (looking-at containing-mid))
6986 (goto-char containing-sexp)
6987 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6988 (if (looking-at vhdl-trailer-re)
6989 ;; CASE 4.1
6990 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6991 (vhdl-backward-skip-label (vhdl-point 'boi))
6992 (vhdl-add-syntax 'block-open (point)))
6993 ;; CASE 5: block close brace
6994 (end-after-ip
6995 (goto-char containing-sexp)
6996 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6997 (if (looking-at vhdl-trailer-re)
6998 ;; CASE 5.1
6999 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7000 (vhdl-backward-skip-label (vhdl-point 'boi))
7001 (vhdl-add-syntax 'block-close (point)))
7002 ;; CASE 6: A continued statement
7003 ((and (/= char-before-ip ?\;)
7004 ;; check it's not a trailer begin keyword, or a begin
7005 ;; keyword immediately following a label.
7006 (not (and begin-after-ip
7007 (or (looking-at vhdl-trailer-re)
7008 (save-excursion
7009 (vhdl-backward-skip-label containing-sexp)))))
7010 ;; check it's not a statement keyword
7011 (not (and (looking-at vhdl-statement-fwd-re)
7012 (vhdl-statement-p)))
7013 ;; see if the b-o-s is before the indent point
7014 (> indent-point
7015 (save-excursion
7016 (vhdl-beginning-of-statement-1 containing-sexp)
7017 ;; If we ended up after a leader, then this will
7018 ;; move us forward to the start of the first
7019 ;; statement. Note that a containing sexp here is
7020 ;; always a keyword, not a paren, so this will
7021 ;; have no effect if we hit the containing-sexp.
7022 (vhdl-forward-syntactic-ws indent-point)
7023 (setq placeholder (point))))
7024 ;; check it's not a block-intro
7025 (/= placeholder containing-sexp)
7026 ;; check it's not a case block-intro
7027 (save-excursion
7028 (goto-char placeholder)
7029 (or (not (looking-at vhdl-case-alternative-re))
7030 (> (match-end 0) indent-point))))
7031 ;; Make placeholder skip a label, but only if it puts us
7032 ;; before the indent point at the start of a line.
7033 (let ((new placeholder))
7034 (if (and (> indent-point
7035 (save-excursion
7036 (goto-char placeholder)
7037 (vhdl-forward-skip-label indent-point)
7038 (setq new (point))))
7039 (save-excursion
7040 (goto-char new)
7041 (eq new (progn (back-to-indentation) (point)))))
7042 (setq placeholder new)))
7043 (vhdl-add-syntax 'statement-cont placeholder)
7044 (if begin-after-ip
7045 (vhdl-add-syntax 'block-open)))
7046 ;; Statement. But what kind?
7047 ;; CASE 7: A case alternative key
7048 ((and (looking-at vhdl-case-alternative-re)
7049 (vhdl-case-alternative-p containing-sexp))
7050 ;; for a case alternative key, we set relpos to the first
7051 ;; non-whitespace char on the line containing the "case"
7052 ;; keyword.
7053 (goto-char containing-sexp)
7054 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7055 (if (looking-at vhdl-trailer-re)
7056 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7057 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
7058 ;; CASE 8: statement catchall
7060 ;; we know its a statement, but we need to find out if it is
7061 ;; the first statement in a block
7062 (if containing-leader
7063 (goto-char containing-leader)
7064 (goto-char containing-sexp)
7065 ;; Note that a containing sexp here is always a keyword,
7066 ;; not a paren, so skip over the keyword.
7067 (forward-sexp))
7068 ;; move to the start of the first statement
7069 (vhdl-forward-syntactic-ws indent-point)
7070 (setq placeholder (point))
7071 ;; we want to ignore case alternatives keys when skipping forward
7072 (let (incase-p)
7073 (while (looking-at vhdl-case-alternative-re)
7074 (setq incase-p (point))
7075 ;; we also want to skip over the body of the
7076 ;; case/when statement if that doesn't put us at
7077 ;; after the indent-point
7078 (while (vhdl-skip-case-alternative indent-point))
7079 ;; set up the match end
7080 (looking-at vhdl-case-alternative-re)
7081 (goto-char (match-end 0))
7082 ;; move to the start of the first case alternative statement
7083 (vhdl-forward-syntactic-ws indent-point)
7084 (setq placeholder (point)))
7085 (cond
7086 ;; CASE 8A: we saw a case/when statement so we must be
7087 ;; in a switch statement. find out if we are at the
7088 ;; statement just after a case alternative key
7089 ((and incase-p
7090 (= (point) indent-point))
7091 ;; relpos is the "when" keyword
7092 (vhdl-add-syntax 'statement-case-intro incase-p))
7093 ;; CASE 8B: any old statement
7094 ((< (point) indent-point)
7095 ;; relpos is the first statement of the block
7096 (vhdl-add-syntax 'statement placeholder)
7097 (if begin-after-ip
7098 (vhdl-add-syntax 'block-open)))
7099 ;; CASE 8C: first statement in a block
7101 (goto-char containing-sexp)
7102 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7103 (if (looking-at vhdl-trailer-re)
7104 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7105 (vhdl-backward-skip-label (vhdl-point 'boi))
7106 (vhdl-add-syntax 'statement-block-intro (point))
7107 (if begin-after-ip
7108 (vhdl-add-syntax 'block-open)))
7112 ;; now we need to look at any modifiers
7113 (goto-char indent-point)
7114 (skip-chars-forward " \t")
7115 (if (looking-at "--")
7116 (vhdl-add-syntax 'comment))
7117 (if (eq literal 'pound)
7118 (vhdl-add-syntax 'cpp-macro))
7119 ;; return the syntax
7120 vhdl-syntactic-context))))
7122 ;; Standard indentation line-ups:
7124 (defun vhdl-lineup-arglist (langelem)
7125 "Lineup the current arglist line with the arglist appearing just
7126 after the containing paren which starts the arglist."
7127 (save-excursion
7128 (let* ((containing-sexp
7129 (save-excursion
7130 ;; arglist-cont-nonempty gives relpos ==
7131 ;; to boi of containing-sexp paren. This
7132 ;; is good when offset is +, but bad
7133 ;; when it is vhdl-lineup-arglist, so we
7134 ;; have to special case a kludge here.
7135 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7136 (progn
7137 (beginning-of-line)
7138 (backward-up-list 1)
7139 (skip-chars-forward " \t" (vhdl-point 'eol)))
7140 (goto-char (cdr langelem)))
7141 (point)))
7142 (cs-curcol (save-excursion
7143 (goto-char (cdr langelem))
7144 (current-column))))
7145 (if (save-excursion
7146 (beginning-of-line)
7147 (looking-at "[ \t]*)"))
7148 (progn (goto-char (match-end 0))
7149 (backward-sexp)
7150 (forward-char)
7151 (vhdl-forward-syntactic-ws)
7152 (- (current-column) cs-curcol))
7153 (goto-char containing-sexp)
7154 (or (eolp)
7155 (let ((eol (vhdl-point 'eol))
7156 (here (progn
7157 (forward-char)
7158 (skip-chars-forward " \t")
7159 (point))))
7160 (vhdl-forward-syntactic-ws)
7161 (if (< (point) eol)
7162 (goto-char here))))
7163 (- (current-column) cs-curcol)
7164 ))))
7166 (defun vhdl-lineup-arglist-intro (langelem)
7167 "Lineup an arglist-intro line to just after the open paren."
7168 (save-excursion
7169 (let ((cs-curcol (save-excursion
7170 (goto-char (cdr langelem))
7171 (current-column)))
7172 (ce-curcol (save-excursion
7173 (beginning-of-line)
7174 (backward-up-list 1)
7175 (skip-chars-forward " \t" (vhdl-point 'eol))
7176 (current-column))))
7177 (- ce-curcol cs-curcol -1))))
7179 (defun vhdl-lineup-comment (langelem)
7180 "Support old behavior for comment indentation. We look at
7181 vhdl-comment-only-line-offset to decide how to indent comment
7182 only-lines."
7183 (save-excursion
7184 (back-to-indentation)
7185 ;; at or to the right of comment-column
7186 (if (>= (current-column) comment-column)
7187 (vhdl-comment-indent)
7188 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7189 (if (not (bolp))
7190 (or (car-safe vhdl-comment-only-line-offset)
7191 vhdl-comment-only-line-offset)
7192 (or (cdr-safe vhdl-comment-only-line-offset)
7193 (car-safe vhdl-comment-only-line-offset)
7194 -1000 ;jam it against the left side
7195 )))))
7197 (defun vhdl-lineup-statement-cont (langelem)
7198 "Line up statement-cont after the assignment operator."
7199 (save-excursion
7200 (let* ((relpos (cdr langelem))
7201 (assignp (save-excursion
7202 (goto-char (vhdl-point 'boi))
7203 (and (re-search-forward "\\(<\\|:\\|=\\)="
7204 (vhdl-point 'eol) t)
7205 (- (point) (vhdl-point 'boi)))))
7206 (curcol (progn
7207 (goto-char relpos)
7208 (current-column)))
7209 foundp)
7210 (while (and (not foundp)
7211 (< (point) (vhdl-point 'eol)))
7212 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7213 (if (vhdl-in-literal)
7214 (forward-char)
7215 (if (= (preceding-char) ?\()
7216 ;; skip over any parenthesized expressions
7217 (goto-char (min (vhdl-point 'eol)
7218 (scan-lists (point) 1 1)))
7219 ;; found an assignment operator (not at eol)
7220 (setq foundp (not (looking-at "\\s-*$"))))))
7221 (if (not foundp)
7222 ;; there's no assignment operator on the line
7223 vhdl-basic-offset
7224 ;; calculate indentation column after assign and ws, unless
7225 ;; our line contains an assignment operator
7226 (if (not assignp)
7227 (progn
7228 (forward-char)
7229 (skip-chars-forward " \t")
7230 (setq assignp 0)))
7231 (- (current-column) assignp curcol))
7234 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7235 ;; Progress reporting
7237 (defvar vhdl-progress-info nil
7238 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7240 (defun vhdl-update-progress-info (string pos)
7241 "Update progress information."
7242 (when (and vhdl-progress-info (not noninteractive)
7243 (< vhdl-progress-interval
7244 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7245 (let ((delta (- (aref vhdl-progress-info 1)
7246 (aref vhdl-progress-info 0))))
7247 (if (= 0 delta)
7248 (message (concat string "... (100%s)") "%")
7249 (message (concat string "... (%2d%s)")
7250 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
7251 delta) "%")))
7252 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7255 ;; Indentation commands
7257 (defun vhdl-electric-tab (&optional prefix-arg)
7258 "If preceding character is part of a word or a paren then hippie-expand,
7259 else if right of non whitespace on line then insert tab,
7260 else if last command was a tab or return then dedent one step or if a comment
7261 toggle between normal indent and inline comment indent,
7262 else indent `correctly'."
7263 (interactive "*P")
7264 (vhdl-prepare-search-2
7265 (cond
7266 ;; indent region if region is active
7267 ((and (not (featurep 'xemacs)) (use-region-p))
7268 (vhdl-indent-region (region-beginning) (region-end) nil))
7269 ;; expand word
7270 ((= (char-syntax (preceding-char)) ?w)
7271 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7272 (case-replace nil)
7273 (hippie-expand-only-buffers
7274 (or (and (boundp 'hippie-expand-only-buffers)
7275 hippie-expand-only-buffers)
7276 '(vhdl-mode))))
7277 (vhdl-expand-abbrev prefix-arg)))
7278 ;; expand parenthesis
7279 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7280 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7281 (case-replace nil))
7282 (vhdl-expand-paren prefix-arg)))
7283 ;; insert tab
7284 ((> (current-column) (current-indentation))
7285 (insert-tab))
7286 ;; toggle comment indent
7287 ((and (looking-at "--")
7288 (or (eq last-command 'vhdl-electric-tab)
7289 (eq last-command 'vhdl-electric-return)))
7290 (cond ((= (current-indentation) 0) ; no indent
7291 (indent-to 1)
7292 (indent-according-to-mode))
7293 ((< (current-indentation) comment-column) ; normal indent
7294 (indent-to comment-column)
7295 (indent-according-to-mode))
7296 (t ; inline comment indent
7297 (delete-region (line-beginning-position) (point)))))
7298 ;; dedent
7299 ((and (>= (current-indentation) vhdl-basic-offset)
7300 (or (eq last-command 'vhdl-electric-tab)
7301 (eq last-command 'vhdl-electric-return)))
7302 (backward-delete-char-untabify vhdl-basic-offset nil))
7303 ;; indent line
7304 (t (indent-according-to-mode)))
7305 (setq this-command 'vhdl-electric-tab)))
7307 (defun vhdl-electric-return ()
7308 "newline-and-indent or indent-new-comment-line if in comment and preceding
7309 character is a space."
7310 (interactive)
7311 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7312 (indent-new-comment-line)
7313 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7314 (not (vhdl-in-comment-p)))
7315 (vhdl-fix-case-word -1))
7316 (newline-and-indent)))
7318 (defun vhdl-indent-line ()
7319 "Indent the current line as VHDL code. Returns the amount of
7320 indentation change."
7321 (interactive)
7322 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7323 (pos (- (point-max) (point)))
7324 (is-comment nil)
7325 (indent
7326 (if syntax
7327 ;; indent syntax-based
7328 (if (and (eq (caar syntax) 'comment)
7329 (>= (vhdl-get-offset (car syntax)) comment-column))
7330 ;; special case: comments at or right of comment-column
7331 (vhdl-get-offset (car syntax))
7332 ;; align comments like following code line
7333 (when vhdl-indent-comment-like-next-code-line
7334 (save-excursion
7335 (while (eq (caar syntax) 'comment)
7336 (setq is-comment t)
7337 (beginning-of-line 2)
7338 (setq syntax (vhdl-get-syntactic-context)))))
7339 (when is-comment
7340 (push (cons 'comment nil) syntax))
7341 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7342 ;; indent like previous nonblank line
7343 (save-excursion (beginning-of-line)
7344 (re-search-backward "^[^\n]" nil t)
7345 (current-indentation))))
7346 (shift-amt (- indent (current-indentation))))
7347 (and vhdl-echo-syntactic-information-p
7348 (message "syntax: %s, indent= %d" syntax indent))
7349 (let ((has-formfeed
7350 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7351 (when (or (not (zerop shift-amt)) has-formfeed)
7352 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7353 (beginning-of-line)
7354 (when has-formfeed (insert "\f"))
7355 (indent-to indent)))
7356 (if (< (point) (vhdl-point 'boi))
7357 (back-to-indentation)
7358 ;; If initial point was within line's indentation, position after
7359 ;; the indentation. Else stay at same point in text.
7360 (when (> (- (point-max) pos) (point))
7361 (goto-char (- (point-max) pos))))
7362 (run-hooks 'vhdl-special-indent-hook)
7363 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7364 shift-amt))
7366 (defun vhdl-indent-region (beg end &optional column)
7367 "Indent region as VHDL code.
7368 Adds progress reporting to `indent-region'."
7369 (interactive "r\nP")
7370 (when vhdl-progress-interval
7371 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7372 (count-lines (point-min) end) 0)))
7373 (indent-region beg end column)
7374 (when vhdl-progress-interval (message "Indenting...done"))
7375 (setq vhdl-progress-info nil))
7377 (defun vhdl-indent-buffer ()
7378 "Indent whole buffer as VHDL code.
7379 Calls `indent-region' for whole buffer and adds progress reporting."
7380 (interactive)
7381 (vhdl-indent-region (point-min) (point-max)))
7383 (defun vhdl-indent-group ()
7384 "Indent group of lines between empty lines."
7385 (interactive)
7386 (let ((beg (save-excursion
7387 (if (re-search-backward vhdl-align-group-separate nil t)
7388 (point-marker)
7389 (point-min-marker))))
7390 (end (save-excursion
7391 (if (re-search-forward vhdl-align-group-separate nil t)
7392 (point-marker)
7393 (point-max-marker)))))
7394 (vhdl-indent-region beg end)))
7396 (defun vhdl-indent-sexp (&optional endpos)
7397 "Indent each line of the list starting just after point.
7398 If optional arg ENDPOS is given, indent each line, stopping when
7399 ENDPOS is encountered."
7400 (interactive)
7401 (save-excursion
7402 (let ((beg (point))
7403 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7404 (indent-region beg end nil))))
7406 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7407 ;; Miscellaneous commands
7409 (defun vhdl-show-syntactic-information ()
7410 "Show syntactic information for current line."
7411 (interactive)
7412 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7413 (vhdl-keep-region-active))
7415 ;; Verification and regression functions:
7417 (defun vhdl-regress-line (&optional arg)
7418 "Check syntactic information for current line."
7419 (interactive "P")
7420 (let ((expected (save-excursion
7421 (end-of-line)
7422 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7423 (forward-char 4)
7424 (read (current-buffer)))))
7425 (actual (vhdl-get-syntactic-context))
7426 (expurgated))
7427 ;; remove the library unit symbols
7428 (mapc
7429 (function
7430 (lambda (elt)
7431 (if (memq (car elt) '(entity configuration package
7432 package-body architecture))
7434 (setq expurgated (append expurgated (list elt))))))
7435 actual)
7436 (if (and (not arg) expected (listp expected))
7437 (if (not (equal expected expurgated))
7438 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7439 (save-excursion
7440 (beginning-of-line)
7441 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7442 (end-of-line)
7443 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7444 (delete-region (point) (line-end-position)))
7445 (insert " -- ")
7446 (insert (format "%s" expurgated))))))
7447 (vhdl-keep-region-active))
7450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7451 ;;; Alignment, beautifying
7452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7454 (defconst vhdl-align-alist
7456 ;; after some keywords
7457 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7458 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7459 ;; before ':'
7460 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7461 ;; after direction specifications
7462 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7463 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7464 ;; before "==", ":=", "=>", and "<="
7465 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7466 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7467 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7468 ;; before some keywords
7469 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7470 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7471 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7472 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7473 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7474 ;; before "=>" since "when/else ... =>" can occur
7475 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7477 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7478 It is searched in order. If REGEXP is found anywhere in the first
7479 line of a region to be aligned, ALIGN-PATTERN will be used for that
7480 region. ALIGN-PATTERN must include the whitespace to be expanded or
7481 contracted. It may also provide regexps for the text surrounding the
7482 whitespace. SUBEXP specifies which sub-expression of
7483 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7485 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7486 ;; Align code
7488 (defvar vhdl-align-try-all-clauses t
7489 "If REGEXP is not found on the first line of the region that clause
7490 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7492 (defun vhdl-do-group (function &optional spacing)
7493 "Apply FUNCTION on group of lines between empty lines."
7494 (let
7495 ;; search for group beginning
7496 ((beg (save-excursion
7497 (if (re-search-backward vhdl-align-group-separate nil t)
7498 (progn (beginning-of-line 2) (back-to-indentation) (point))
7499 (point-min))))
7500 ;; search for group end
7501 (end (save-excursion
7502 (if (re-search-forward vhdl-align-group-separate nil t)
7503 (progn (beginning-of-line) (point))
7504 (point-max)))))
7505 ;; run FUNCTION
7506 (funcall function beg end spacing)))
7508 (defun vhdl-do-list (function &optional spacing)
7509 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7510 parentheses."
7511 (let (beg end)
7512 (save-excursion
7513 ;; search for beginning of balanced group of parentheses
7514 (setq beg (vhdl-re-search-backward "[()]" nil t))
7515 (while (looking-at ")")
7516 (forward-char) (backward-sexp)
7517 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7518 ;; search for end of balanced group of parentheses
7519 (when beg
7520 (forward-list)
7521 (setq end (point))
7522 (goto-char (1+ beg))
7523 (skip-chars-forward " \t\n\r\f")
7524 (setq beg (point))))
7525 ;; run FUNCTION
7526 (if beg
7527 (funcall function beg end spacing)
7528 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7530 (defun vhdl-do-same-indent (function &optional spacing)
7531 "Apply FUNCTION to block of lines with same indent."
7532 (let ((indent (current-indentation))
7533 beg end)
7534 ;; search for first line with same indent
7535 (save-excursion
7536 (while (and (not (bobp))
7537 (or (looking-at "^\\s-*\\(--.*\\)?$")
7538 (= (current-indentation) indent)))
7539 (unless (looking-at "^\\s-*$")
7540 (back-to-indentation) (setq beg (point)))
7541 (beginning-of-line -0)))
7542 ;; search for last line with same indent
7543 (save-excursion
7544 (while (and (not (eobp))
7545 (or (looking-at "^\\s-*\\(--.*\\)?$")
7546 (= (current-indentation) indent)))
7547 (if (looking-at "^\\s-*$")
7548 (beginning-of-line 2)
7549 (beginning-of-line 2)
7550 (setq end (point)))))
7551 ;; run FUNCTION
7552 (funcall function beg end spacing)))
7554 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7555 "Attempt to align a range of lines based on the content of the
7556 lines. The definition of `alignment-list' determines the matching
7557 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7558 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7559 indentation is done before aligning."
7560 (interactive "r\np")
7561 (setq alignment-list (or alignment-list vhdl-align-alist))
7562 (setq spacing (or spacing 1))
7563 (save-excursion
7564 (let (bol indent)
7565 (goto-char end)
7566 (setq end (point-marker))
7567 (goto-char begin)
7568 (setq bol (setq begin (progn (beginning-of-line) (point))))
7569 ; (untabify bol end)
7570 (when indent
7571 (indent-region bol end nil))))
7572 (let ((copy (copy-alist alignment-list)))
7573 (vhdl-prepare-search-2
7574 (while copy
7575 (save-excursion
7576 (goto-char begin)
7577 (let (element
7578 (eol (point-at-eol)))
7579 (setq element (nth 0 copy))
7580 (when (and (or (and (listp (car element))
7581 (memq major-mode (car element)))
7582 (eq major-mode (car element)))
7583 (or vhdl-align-try-all-clauses
7584 (re-search-forward (car (cdr element)) eol t)))
7585 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7586 (car (cdr (cdr (cdr element)))) spacing))
7587 (setq copy (cdr copy))))))))
7589 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7590 "Align a range of lines from BEGIN to END. The regular expression
7591 MATCH must match exactly one field: the whitespace to be
7592 contracted/expanded. The alignment column will equal the
7593 rightmost column of the widest whitespace block. SPACING is
7594 the amount of extra spaces to add to the calculated maximum required.
7595 SPACING defaults to 1 so that at least one space is inserted after
7596 the token in MATCH."
7597 (setq spacing (or spacing 1))
7598 (setq substr (or substr 1))
7599 (save-excursion
7600 (let (distance (max 0) (lines 0) bol eol width)
7601 ;; Determine the greatest whitespace distance to the alignment
7602 ;; character
7603 (goto-char begin)
7604 (setq eol (point-at-eol)
7605 bol (setq begin (progn (beginning-of-line) (point))))
7606 (while (< bol end)
7607 (save-excursion
7608 (when (and (vhdl-re-search-forward match eol t)
7609 (save-excursion
7610 (goto-char (match-beginning 0))
7611 (forward-char)
7612 (and (not (vhdl-in-literal))
7613 (not (vhdl-in-quote-p))
7614 (not (vhdl-in-extended-identifier-p))))
7615 (not (looking-at "\\s-*$")))
7616 (setq distance (- (match-beginning substr) bol))
7617 (when (> distance max)
7618 (setq max distance))))
7619 (forward-line)
7620 (setq bol (point)
7621 eol (point-at-eol))
7622 (setq lines (1+ lines)))
7623 ;; Now insert enough maxs to push each assignment operator to
7624 ;; the same column. We need to use 'lines' as a counter, since
7625 ;; the location of the mark may change
7626 (goto-char (setq bol begin))
7627 (setq eol (point-at-eol))
7628 (while (> lines 0)
7629 (when (and (vhdl-re-search-forward match eol t)
7630 (save-excursion
7631 (goto-char (match-beginning 0))
7632 (forward-char)
7633 (and (not (vhdl-in-literal))
7634 (not (vhdl-in-quote-p))
7635 (not (vhdl-in-extended-identifier-p))))
7636 (not (looking-at "\\s-*$"))
7637 (> (match-beginning 0) ; not if at boi
7638 (save-excursion (back-to-indentation) (point))))
7639 (setq width (- (match-end substr) (match-beginning substr)))
7640 (setq distance (- (match-beginning substr) bol))
7641 (goto-char (match-beginning substr))
7642 (delete-char width)
7643 (insert-char ? (+ (- max distance) spacing)))
7644 (beginning-of-line)
7645 (forward-line)
7646 (setq bol (point)
7647 eol (point-at-eol))
7648 (setq lines (1- lines))))))
7650 (defun vhdl-align-region-groups (beg end &optional spacing
7651 no-message no-comments)
7652 "Align region, treat groups of lines separately."
7653 (interactive "r\nP")
7654 (save-excursion
7655 (let (orig pos)
7656 (goto-char beg)
7657 (beginning-of-line)
7658 (setq orig (point-marker))
7659 (setq beg (point))
7660 (goto-char end)
7661 (setq end (point-marker))
7662 (untabify beg end)
7663 (unless no-message
7664 (when vhdl-progress-interval
7665 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7666 (count-lines (point-min) end) 0))))
7667 (when (nth 0 vhdl-beautify-options)
7668 (vhdl-fixup-whitespace-region beg end t))
7669 (goto-char beg)
7670 (if (not vhdl-align-groups)
7671 ;; align entire region
7672 (progn (vhdl-align-region-1 beg end spacing)
7673 (unless no-comments
7674 (vhdl-align-inline-comment-region-1 beg end)))
7675 ;; align groups
7676 (while (and (< beg end)
7677 (re-search-forward vhdl-align-group-separate end t))
7678 (setq pos (point-marker))
7679 (vhdl-align-region-1 beg pos spacing)
7680 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7681 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7682 (setq beg (1+ pos))
7683 (goto-char beg))
7684 ;; align last group
7685 (when (< beg end)
7686 (vhdl-align-region-1 beg end spacing)
7687 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7688 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7689 (when vhdl-indent-tabs-mode
7690 (tabify orig end))
7691 (unless no-message
7692 (when vhdl-progress-interval (message "Aligning...done"))
7693 (setq vhdl-progress-info nil)))))
7695 (defun vhdl-align-region (beg end &optional spacing)
7696 "Align region, treat blocks with same indent and argument lists separately."
7697 (interactive "r\nP")
7698 (if (not vhdl-align-same-indent)
7699 ;; align entire region
7700 (vhdl-align-region-groups beg end spacing)
7701 ;; align blocks with same indent and argument lists
7702 (save-excursion
7703 (let ((cur-beg beg)
7704 indent cur-end)
7705 (when vhdl-progress-interval
7706 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7707 (count-lines (point-min) end) 0)))
7708 (goto-char end)
7709 (setq end (point-marker))
7710 (goto-char cur-beg)
7711 (while (< (point) end)
7712 ;; is argument list opening?
7713 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7714 (point) (vhdl-point 'eol)))))
7715 ;; determine region for argument list
7716 (progn (goto-char cur-beg)
7717 (forward-sexp)
7718 (setq cur-end (point))
7719 (beginning-of-line 2))
7720 ;; determine region with same indent
7721 (setq indent (current-indentation))
7722 (setq cur-beg (point))
7723 (setq cur-end (vhdl-point 'bonl))
7724 (beginning-of-line 2)
7725 (while (and (< (point) end)
7726 (or (looking-at "^\\s-*\\(--.*\\)?$")
7727 (= (current-indentation) indent))
7728 (<= (save-excursion
7729 (nth 0 (parse-partial-sexp
7730 (point) (vhdl-point 'eol)))) 0))
7731 (unless (looking-at "^\\s-*$")
7732 (setq cur-end (vhdl-point 'bonl)))
7733 (beginning-of-line 2)))
7734 ;; align region
7735 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7736 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7737 (when vhdl-progress-interval (message "Aligning...done"))
7738 (setq vhdl-progress-info nil)))))
7740 (defun vhdl-align-group (&optional spacing)
7741 "Align group of lines between empty lines."
7742 (interactive)
7743 (vhdl-do-group 'vhdl-align-region spacing))
7745 (defun vhdl-align-list (&optional spacing)
7746 "Align the lines of a list surrounded by a balanced group of parentheses."
7747 (interactive)
7748 (vhdl-do-list 'vhdl-align-region-groups spacing))
7750 (defun vhdl-align-same-indent (&optional spacing)
7751 "Align block of lines with same indent."
7752 (interactive)
7753 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7755 (defun vhdl-align-declarations (&optional spacing)
7756 "Align the lines within the declarative part of a design unit."
7757 (interactive)
7758 (let (beg end)
7759 (vhdl-prepare-search-2
7760 (save-excursion
7761 ;; search for declarative part
7762 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7763 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7764 (setq beg (point))
7765 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7766 (setq end (point)))))
7767 (if beg
7768 (vhdl-align-region-groups beg end spacing)
7769 (error "ERROR: Not within the declarative part of a design unit"))))
7771 (defun vhdl-align-buffer ()
7772 "Align buffer."
7773 (interactive)
7774 (vhdl-align-region (point-min) (point-max)))
7776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7777 ;; Align inline comments
7779 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7780 "Align inline comments in region."
7781 (save-excursion
7782 (let ((start-max comment-column)
7783 (length-max 0)
7784 comment-list start-list tmp-list start length
7785 cur-start prev-start no-code)
7786 (setq spacing (or spacing 2))
7787 (vhdl-prepare-search-2
7788 (goto-char beg)
7789 ;; search for comment start positions and lengths
7790 (while (< (point) end)
7791 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7792 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7793 (not (save-excursion (goto-char (match-beginning 2))
7794 (vhdl-in-literal))))
7795 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7796 (setq length (- (match-end 2) (match-beginning 2)))
7797 (setq start-max (max start start-max))
7798 (setq length-max (max length length-max))
7799 (push (cons start length) comment-list))
7800 (beginning-of-line 2))
7801 (setq comment-list
7802 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7803 ;; reduce start positions
7804 (setq start-list (list (caar comment-list)))
7805 (setq comment-list (cdr comment-list))
7806 (while comment-list
7807 (unless (or (= (caar comment-list) (car start-list))
7808 (<= (+ (car start-list) (cdar comment-list))
7809 end-comment-column))
7810 (push (caar comment-list) start-list))
7811 (setq comment-list (cdr comment-list)))
7812 ;; align lines as nicely as possible
7813 (goto-char beg)
7814 (while (< (point) end)
7815 (setq cur-start nil)
7816 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7817 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7818 (not (save-excursion
7819 (goto-char (match-beginning 3))
7820 (vhdl-in-literal))))
7821 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7822 (>= (- (match-end 2) (match-beginning 2))
7823 comment-column))))
7824 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7825 (setq length (- (match-end 3) (match-beginning 3)))
7826 (setq no-code (= (match-beginning 1) (match-end 1)))
7827 ;; insert minimum whitespace
7828 (goto-char (match-end 2))
7829 (delete-region (match-beginning 2) (match-end 2))
7830 (insert-char ?\ spacing)
7831 (setq tmp-list start-list)
7832 ;; insert additional whitespace to align
7833 (setq cur-start
7834 (cond
7835 ;; align comment-only line to inline comment of previous line
7836 ((and no-code prev-start
7837 (<= length (- end-comment-column prev-start)))
7838 prev-start)
7839 ;; align all comments at `start-max' if this is possible
7840 ((<= (+ start-max length-max) end-comment-column)
7841 start-max)
7842 ;; align at `comment-column' if possible
7843 ((and (<= start comment-column)
7844 (<= length (- end-comment-column comment-column)))
7845 comment-column)
7846 ;; align at left-most possible start position otherwise
7848 (while (and tmp-list (< (car tmp-list) start))
7849 (setq tmp-list (cdr tmp-list)))
7850 (car tmp-list))))
7851 (indent-to cur-start))
7852 (setq prev-start cur-start)
7853 (beginning-of-line 2))))))
7855 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7856 "Align inline comments within a region. Groups of code lines separated by
7857 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7858 (interactive "r\nP")
7859 (save-excursion
7860 (let (orig pos)
7861 (goto-char beg)
7862 (beginning-of-line)
7863 (setq orig (point-marker))
7864 (setq beg (point))
7865 (goto-char end)
7866 (setq end (point-marker))
7867 (untabify beg end)
7868 (unless no-message (message "Aligning inline comments..."))
7869 (goto-char beg)
7870 (if (not vhdl-align-groups)
7871 ;; align entire region
7872 (vhdl-align-inline-comment-region-1 beg end spacing)
7873 ;; align groups
7874 (while (and (< beg end)
7875 (re-search-forward vhdl-align-group-separate end t))
7876 (setq pos (point-marker))
7877 (vhdl-align-inline-comment-region-1 beg pos spacing)
7878 (setq beg (1+ pos))
7879 (goto-char beg))
7880 ;; align last group
7881 (when (< beg end)
7882 (vhdl-align-inline-comment-region-1 beg end spacing)))
7883 (when vhdl-indent-tabs-mode
7884 (tabify orig end))
7885 (unless no-message (message "Aligning inline comments...done")))))
7887 (defun vhdl-align-inline-comment-group (&optional spacing)
7888 "Align inline comments within a group of lines between empty lines."
7889 (interactive)
7890 (save-excursion
7891 (let ((start (point))
7892 beg end)
7893 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7894 (point-marker) (point-max)))
7895 (goto-char start)
7896 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7897 (point) (point-min)))
7898 (untabify beg end)
7899 (message "Aligning inline comments...")
7900 (vhdl-align-inline-comment-region-1 beg end)
7901 (when vhdl-indent-tabs-mode
7902 (tabify beg end))
7903 (message "Aligning inline comments...done"))))
7905 (defun vhdl-align-inline-comment-buffer ()
7906 "Align inline comments within buffer. Groups of code lines separated by
7907 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7908 (interactive)
7909 (vhdl-align-inline-comment-region (point-min) (point-max)))
7911 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7912 ;; Fixup whitespace
7914 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7915 "Fixup whitespace in region. Surround operator symbols by one space,
7916 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7917 end of line, do nothing in comments and strings."
7918 (interactive "r")
7919 (unless no-message (message "Fixing up whitespace..."))
7920 (save-excursion
7921 (goto-char end)
7922 (setq end (point-marker))
7923 ;; have no space before and one space after `,' and ';'
7924 (goto-char beg)
7925 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7926 (if (match-string 1)
7927 (goto-char (match-end 1))
7928 (replace-match "\\3 " nil nil nil 2)))
7929 ;; have no space after `('
7930 (goto-char beg)
7931 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
7932 (if (match-string 1)
7933 (goto-char (match-end 1))
7934 (replace-match "\\2")))
7935 ;; have no space before `)'
7936 (goto-char beg)
7937 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7938 (if (match-string 1)
7939 (goto-char (match-end 1))
7940 (replace-match "\\2")))
7941 ;; surround operator symbols by one space
7942 (goto-char beg)
7943 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
7944 (if (or (match-string 1)
7945 (<= (match-beginning 0) ; not if at boi
7946 (save-excursion (back-to-indentation) (point))))
7947 (goto-char (match-end 0))
7948 (replace-match "\\3 \\4 \\5")
7949 (goto-char (match-end 2))))
7950 ;; eliminate multiple spaces and spaces at end of line
7951 (goto-char beg)
7952 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7953 (and (looking-at "--.*") (re-search-forward "--.*" end t))
7954 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7955 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7956 (progn (replace-match "" nil nil) t))
7957 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7958 (progn (replace-match ";" nil nil) t))
7959 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7960 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7961 (progn (replace-match " " nil nil) t))
7962 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7963 (progn (replace-match " " nil nil) t))
7964 (and (looking-at "-") (re-search-forward "-" end t))
7965 ; (re-search-forward "[^ \t-]+" end t))))
7966 (re-search-forward "[^ \t\"-]+" end t))))
7967 (unless no-message (message "Fixing up whitespace...done")))
7969 (defun vhdl-fixup-whitespace-buffer ()
7970 "Fixup whitespace in buffer. Surround operator symbols by one space,
7971 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7972 end of line, do nothing in comments."
7973 (interactive)
7974 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7977 ;; Case fixing
7979 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
7980 "Convert all words matching WORD-REGEXP in region to lower or upper case,
7981 depending on parameter UPPER-CASE."
7982 (let ((case-replace nil)
7983 (last-update 0))
7984 (vhdl-prepare-search-2
7985 (save-excursion
7986 (goto-char end)
7987 (setq end (point-marker))
7988 (goto-char beg)
7989 (while (re-search-forward word-regexp end t)
7990 (or (vhdl-in-literal)
7991 (if upper-case
7992 (upcase-word -1)
7993 (downcase-word -1)))
7994 (when (and count vhdl-progress-interval (not noninteractive)
7995 (< vhdl-progress-interval
7996 (- (nth 1 (current-time)) last-update)))
7997 (message "Fixing case... (%2d%s)"
7998 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
7999 "%")
8000 (setq last-update (nth 1 (current-time)))))
8001 (goto-char end)))))
8003 (defun vhdl-fix-case-region (beg end &optional arg)
8004 "Convert all VHDL words in region to lower or upper case, depending on
8005 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8006 (interactive "r\nP")
8007 (vhdl-fix-case-region-1
8008 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
8009 (vhdl-fix-case-region-1
8010 beg end vhdl-upper-case-types vhdl-types-regexp 1)
8011 (vhdl-fix-case-region-1
8012 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
8013 (vhdl-fix-case-region-1
8014 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
8015 (vhdl-fix-case-region-1
8016 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
8017 (when vhdl-progress-interval (message "Fixing case...done")))
8019 (defun vhdl-fix-case-buffer ()
8020 "Convert all VHDL words in buffer to lower or upper case, depending on
8021 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8022 (interactive)
8023 (vhdl-fix-case-region (point-min) (point-max)))
8025 (defun vhdl-fix-case-word (&optional arg)
8026 "Convert word after cursor to upper case if necessary."
8027 (interactive "p")
8028 (save-excursion
8029 (when arg (backward-word 1))
8030 (vhdl-prepare-search-1
8031 (when (and vhdl-upper-case-keywords
8032 (looking-at vhdl-keywords-regexp))
8033 (upcase-word 1))
8034 (when (and vhdl-upper-case-types
8035 (looking-at vhdl-types-regexp))
8036 (upcase-word 1))
8037 (when (and vhdl-upper-case-attributes
8038 (looking-at vhdl-attributes-regexp))
8039 (upcase-word 1))
8040 (when (and vhdl-upper-case-enum-values
8041 (looking-at vhdl-enum-values-regexp))
8042 (upcase-word 1))
8043 (when (and vhdl-upper-case-constants
8044 (looking-at vhdl-constants-regexp))
8045 (upcase-word 1)))))
8047 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8048 ;; Fix statements
8049 ;; - force each statement to be on a separate line except when on same line
8050 ;; with 'end' keyword
8052 (defun vhdl-fix-statement-region (beg end &optional arg)
8053 "Force statements in region on separate line except when on same line
8054 with 'end' keyword (necessary for correct indentation).
8055 Currently supported keywords: 'begin', 'if'."
8056 (interactive "r\nP")
8057 (vhdl-prepare-search-2
8058 (let (point)
8059 (save-excursion
8060 (goto-char end)
8061 (setq end (point-marker))
8062 (goto-char beg)
8063 ;; `begin' keyword
8064 (while (re-search-forward
8065 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
8066 (goto-char (match-end 0))
8067 (setq point (point-marker))
8068 (when (and (match-string 1)
8069 (or (not (match-string 2))
8070 (save-excursion (goto-char (match-end 2))
8071 (vhdl-in-literal)))
8072 (not (save-excursion (goto-char (match-beginning 1))
8073 (vhdl-in-literal))))
8074 (goto-char (match-beginning 1))
8075 (insert "\n")
8076 (indent-according-to-mode))
8077 (goto-char point))
8078 (goto-char beg)
8079 ;; `for', `if' keywords
8080 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
8081 (goto-char (match-end 1))
8082 (setq point (point-marker))
8083 ;; exception: in literal or preceded by `end' or label
8084 (when (and (not (save-excursion (goto-char (match-beginning 1))
8085 (vhdl-in-literal)))
8086 (save-excursion
8087 (beginning-of-line 1)
8088 (save-match-data
8089 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8090 (match-beginning 1) t)
8091 (not (string-match
8092 "\\(\\<end\\>\\|\\<wait\\>\\|\\w+\\s-*:\\)\\s-*$"
8093 (match-string 1)))))))
8094 (goto-char (match-beginning 1))
8095 (insert "\n")
8096 (indent-according-to-mode))
8097 (goto-char point))))))
8099 (defun vhdl-fix-statement-buffer ()
8100 "Force statements in buffer on separate line except when on same line
8101 with 'end' keyword (necessary for correct indentation)."
8102 (interactive)
8103 (vhdl-fix-statement-region (point-min) (point-max)))
8105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8106 ;; Trailing spaces
8108 (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
8109 "Remove trailing spaces in region."
8110 (interactive "r\nP")
8111 (save-excursion
8112 (goto-char end)
8113 (setq end (point-marker))
8114 (goto-char beg)
8115 (while (re-search-forward "[ \t]+$" end t)
8116 (unless (vhdl-in-literal)
8117 (replace-match "" nil nil)))))
8119 (defun vhdl-remove-trailing-spaces ()
8120 "Remove trailing spaces in buffer."
8121 (interactive)
8122 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8125 ;; Beautify
8127 (defun vhdl-beautify-region (beg end)
8128 "Beautify region by applying indentation, whitespace fixup, alignment, and
8129 case fixing to a region. Calls functions `vhdl-indent-buffer',
8130 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8131 `vhdl-fix-case-buffer'."
8132 (interactive "r")
8133 (setq end (save-excursion (goto-char end) (point-marker)))
8134 (save-excursion ; remove DOS EOL characters in UNIX file
8135 (goto-char beg)
8136 (while (search-forward " " nil t)
8137 (replace-match "" nil t)))
8138 (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
8139 (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
8140 (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
8141 (let ((vhdl-align-groups t))
8142 (when (nth 3 vhdl-beautify-options) (vhdl-align-region beg end)))
8143 (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
8144 (when (nth 0 vhdl-beautify-options) (vhdl-remove-trailing-spaces-region beg end)))
8146 (defun vhdl-beautify-buffer ()
8147 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8148 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8149 buffer."
8150 (interactive)
8151 (vhdl-beautify-region (point-min) (point-max))
8152 (when noninteractive (save-buffer)))
8154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8155 ;; Code filling
8157 (defun vhdl-fill-region (beg end &optional arg)
8158 "Fill lines for a region of code."
8159 (interactive "r\np")
8160 (save-excursion
8161 (goto-char beg)
8162 (let ((margin (if arg (current-indentation) (current-column))))
8163 (goto-char end)
8164 (setq end (point-marker))
8165 ;; remove inline comments, newlines and whitespace
8166 (vhdl-comment-kill-region beg end)
8167 (vhdl-comment-kill-inline-region beg end)
8168 (subst-char-in-region beg (1- end) ?\n ?\ )
8169 (vhdl-fixup-whitespace-region beg end)
8170 ;; wrap and end-comment-column
8171 (goto-char beg)
8172 (while (re-search-forward "\\s-" end t)
8173 (when(> (current-column) vhdl-end-comment-column)
8174 (backward-char)
8175 (when (re-search-backward "\\s-" beg t)
8176 (replace-match "\n")
8177 (indent-to margin)))))))
8179 (defun vhdl-fill-group ()
8180 "Fill group of lines between empty lines."
8181 (interactive)
8182 (vhdl-do-group 'vhdl-fill-region))
8184 (defun vhdl-fill-list ()
8185 "Fill the lines of a list surrounded by a balanced group of parentheses."
8186 (interactive)
8187 (vhdl-do-list 'vhdl-fill-region))
8189 (defun vhdl-fill-same-indent ()
8190 "Fill the lines of block of lines with same indent."
8191 (interactive)
8192 (vhdl-do-same-indent 'vhdl-fill-region))
8195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8196 ;;; Code updating/fixing
8197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8199 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8200 ;; Sensitivity list update
8202 ;; Strategy:
8203 ;; - no sensitivity list is generated for processes with wait statements
8204 ;; - otherwise, do the following:
8205 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8206 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8207 ;; manually entered global signals)
8208 ;; 3. signals from 1. and 2. form the list of visible signals
8209 ;; 4. search for if/elsif conditions containing an event (sequential code)
8210 ;; 5. scan for strings that are within syntactical regions where signals are
8211 ;; read but not within sequential code, and that correspond to visible
8212 ;; signals
8213 ;; 6. replace sensitivity list by list of signals from 5.
8215 (defun vhdl-update-sensitivity-list-process ()
8216 "Update sensitivity list of current process."
8217 (interactive)
8218 (save-excursion
8219 (vhdl-prepare-search-2
8220 (end-of-line)
8221 ;; look whether in process
8222 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8223 (equal (upcase (match-string 2)) "PROCESS")
8224 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8225 (error "ERROR: Not within a process")
8226 (message "Updating sensitivity list...")
8227 (vhdl-update-sensitivity-list)
8228 (message "Updating sensitivity list...done")))))
8230 (defun vhdl-update-sensitivity-list-buffer ()
8231 "Update sensitivity list of all processes in current buffer."
8232 (interactive)
8233 (save-excursion
8234 (vhdl-prepare-search-2
8235 (goto-char (point-min))
8236 (message "Updating sensitivity lists...")
8237 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8238 (goto-char (match-beginning 0))
8239 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8240 (message "Updating sensitivity lists...done")))
8241 (when noninteractive (save-buffer)))
8243 (defun vhdl-update-sensitivity-list ()
8244 "Update sensitivity list."
8245 (let ((proc-beg (point))
8246 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8247 (proc-mid (vhdl-re-search-backward
8248 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8249 seq-region-list)
8250 (cond
8251 ;; error if 'begin' keyword missing
8252 ((not (match-string 2))
8253 (error "ERROR: No 'begin' keyword found"))
8254 ;; search for wait statement (no sensitivity list allowed)
8255 ((progn (goto-char proc-mid)
8256 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8257 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8258 ;; combinational process (update sensitivity list)
8260 (let
8261 ;; scan for visible signals
8262 ((visible-list (vhdl-get-visible-signals))
8263 ;; define syntactic regions where signals are read
8264 (scan-regions-list
8265 '(;; right-hand side of signal/variable assignment
8266 ;; (special case: "<=" is relational operator in a condition)
8267 ((vhdl-re-search-forward "[<:]=" proc-end t)
8268 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8269 ;; if condition
8270 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
8271 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8272 ;; elsif condition
8273 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
8274 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8275 ;; while loop condition
8276 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
8277 (vhdl-re-search-forward "\\<loop\\>" proc-end t))
8278 ;; exit/next condition
8279 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8280 (vhdl-re-search-forward ";" proc-end t))
8281 ;; assert condition
8282 ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
8283 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8284 ;; case expression
8285 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
8286 (vhdl-re-search-forward "\\<is\\>" proc-end t))
8287 ;; parameter list of procedure call, array index
8288 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8289 (1- (point)))
8290 (progn (backward-char) (forward-sexp)
8291 (while (looking-at "(") (forward-sexp)) (point)))))
8292 name field read-list sens-list signal-list tmp-list
8293 sens-beg sens-end beg end margin)
8294 ;; scan for signals in old sensitivity list
8295 (goto-char proc-beg)
8296 (vhdl-re-search-forward "\\<process\\>" proc-mid t)
8297 (if (not (looking-at "[ \t\n\r\f]*("))
8298 (setq sens-beg (point))
8299 (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8300 (goto-char (match-end 1))
8301 (forward-sexp)
8302 (setq sens-end (1- (point)))
8303 (goto-char sens-beg)
8304 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
8305 (setq sens-list
8306 (cons (downcase (match-string 0)) sens-list))
8307 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
8308 (setq signal-list (append visible-list sens-list))
8309 ;; search for sequential parts
8310 (goto-char proc-mid)
8311 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8312 (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
8313 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8314 (goto-char end)
8315 (backward-word 1)
8316 (vhdl-forward-sexp)
8317 (push (cons end (point)) seq-region-list)
8318 (beginning-of-line)))
8319 ;; scan for signals read in process
8320 (while scan-regions-list
8321 (goto-char proc-mid)
8322 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8323 (setq end (eval (nth 1 (car scan-regions-list)))))
8324 (goto-char beg)
8325 (unless (or (vhdl-in-literal)
8326 (and seq-region-list
8327 (let ((tmp-list seq-region-list))
8328 (while (and tmp-list
8329 (< (point) (caar tmp-list)))
8330 (setq tmp-list (cdr tmp-list)))
8331 (and tmp-list (< (point) (cdar tmp-list))))))
8332 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8333 (setq name (match-string 1))
8334 ;; get array index range
8335 (when vhdl-array-index-record-field-in-sensitivity-list
8336 (setq field (match-string 2))
8337 ;; not use if it includes a variable name
8338 (save-match-data
8339 (setq tmp-list visible-list)
8340 (while (and field tmp-list)
8341 (when (string-match
8342 (concat "\\<" (car tmp-list) "\\>") field)
8343 (setq field nil))
8344 (setq tmp-list (cdr tmp-list)))))
8345 (when (and (not (match-string 6)) ; not when formal parameter
8346 (not (and (match-string 5) ; not event attribute
8347 (not (member (downcase (match-string 5))
8348 '("event" "last_event" "transaction")))))
8349 (member (downcase name) signal-list))
8350 ;; not add if name or name+field already exists
8351 (unless
8352 (or (member-ignore-case name read-list)
8353 (member-ignore-case (concat name field) read-list))
8354 (push (concat name field) read-list))
8355 (setq tmp-list read-list)
8356 ;; remove existing name+field if name is added
8357 (save-match-data
8358 (while tmp-list
8359 (when (string-match (concat "^" name field "[(.]")
8360 (car tmp-list))
8361 (setq read-list (delete (car tmp-list) read-list)))
8362 (setq tmp-list (cdr tmp-list)))))
8363 (goto-char (match-end 1)))))
8364 (setq scan-regions-list (cdr scan-regions-list)))
8365 ;; update sensitivity list
8366 (goto-char sens-beg)
8367 (if sens-end
8368 (delete-region sens-beg sens-end)
8369 (when read-list
8370 (insert " ()") (backward-char)))
8371 (setq read-list (sort read-list 'string<))
8372 (when read-list
8373 (setq margin (current-column))
8374 (insert (car read-list))
8375 (setq read-list (cdr read-list))
8376 (while read-list
8377 (insert ",")
8378 (if (<= (+ (current-column) (length (car read-list)) 2)
8379 end-comment-column)
8380 (insert " ")
8381 (insert "\n") (indent-to margin))
8382 (insert (car read-list))
8383 (setq read-list (cdr read-list)))))))))
8385 (defun vhdl-get-visible-signals ()
8386 "Get all signals visible in the current block."
8387 (let (beg end signal-list entity-name file-name)
8388 (vhdl-prepare-search-2
8389 ;; get entity name
8390 (save-excursion
8391 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8392 (not (equal "END" (upcase (match-string 1))))
8393 (setq entity-name (match-string 2)))
8394 (error "ERROR: Not within an architecture")))
8395 ;; search for signals declared in entity port clause
8396 (save-excursion
8397 (goto-char (point-min))
8398 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8399 (setq file-name
8400 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8401 "." (file-name-extension (buffer-file-name)))))
8402 (vhdl-visit-file
8403 file-name t
8404 (vhdl-prepare-search-2
8405 (goto-char (point-min))
8406 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8407 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8408 (when (setq beg (vhdl-re-search-forward
8409 "\\<port[ \t\n\r\f]*("
8410 (save-excursion
8411 (re-search-forward "^end\\>" nil t)) t))
8412 (setq end (save-excursion
8413 (backward-char) (forward-sexp) (point)))
8414 (vhdl-forward-syntactic-ws)
8415 (while (< (point) end)
8416 (when (looking-at "signal[ \t\n\r\f]+")
8417 (goto-char (match-end 0)))
8418 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8419 (setq signal-list
8420 (cons (downcase (match-string 1)) signal-list))
8421 (goto-char (match-end 0))
8422 (vhdl-forward-syntactic-ws))
8423 (re-search-forward ";" end 1)
8424 (vhdl-forward-syntactic-ws)))))))
8425 ;; search for signals declared in architecture declarative part
8426 (save-excursion
8427 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8428 (not (equal "END" (upcase (match-string 1))))
8429 (setq end (re-search-forward "^begin\\>" nil t))))
8430 (error "ERROR: No architecture declarative part found")
8431 ;; scan for all declared signal and alias names
8432 (goto-char beg)
8433 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8434 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8435 (if (match-string 2)
8436 ;; scan signal name
8437 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8438 (setq signal-list
8439 (cons (downcase (match-string 1)) signal-list))
8440 (goto-char (match-end 0)))
8441 ;; scan alias name, check is alias of (declared) signal
8442 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8443 (member (downcase (match-string 2)) signal-list))
8444 (setq signal-list
8445 (cons (downcase (match-string 1)) signal-list))
8446 (goto-char (match-end 0))))
8447 (setq beg (point))))))
8448 ;; search for signals declared in surrounding block declarative parts
8449 (save-excursion
8450 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
8451 (match-string 2))
8452 (goto-char (match-end 2))
8453 (vhdl-backward-sexp)
8454 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
8455 beg)
8456 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8457 ;; scan for all declared signal names
8458 (goto-char beg)
8459 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8460 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8461 (if (match-string 2)
8462 ;; scan signal name
8463 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8464 (setq signal-list
8465 (cons (downcase (match-string 1)) signal-list))
8466 (goto-char (match-end 0)))
8467 ;; scan alias name, check is alias of (declared) signal
8468 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8469 (member (downcase (match-string 2)) signal-list))
8470 (setq signal-list
8471 (cons (downcase (match-string 1)) signal-list))
8472 (goto-char (match-end 0))))))
8473 (goto-char beg)))
8474 signal-list)))
8476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8477 ;; Generic/port clause fixing
8479 (defun vhdl-fix-clause-buffer ()
8480 "Fix all generic/port clauses in current buffer."
8481 (interactive)
8482 (save-excursion
8483 (vhdl-prepare-search-2
8484 (goto-char (point-min))
8485 (message "Fixing generic/port clauses...")
8486 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8487 (goto-char (match-end 0))
8488 (condition-case nil (vhdl-fix-clause) (error "")))
8489 (message "Fixing generic/port clauses...done"))))
8491 (defun vhdl-fix-clause ()
8492 "Fix closing parenthesis within generic/port clause."
8493 (interactive)
8494 (save-excursion
8495 (vhdl-prepare-search-2
8496 (let ((pos (point))
8497 beg end)
8498 (end-of-line)
8499 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8500 (error "ERROR: Not within a generic/port clause")
8501 ;; search for end of clause
8502 (goto-char (match-end 0))
8503 (setq beg (1- (point)))
8504 (vhdl-forward-syntactic-ws)
8505 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8506 (goto-char (1- (match-end 0)))
8507 (setq end (point-marker))
8508 (forward-char)
8509 (vhdl-forward-syntactic-ws))
8510 (goto-char end)
8511 (when (> pos (point-at-eol))
8512 (error "ERROR: Not within a generic/port clause"))
8513 ;; delete closing parenthesis on separate line (not supported style)
8514 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8515 (vhdl-line-kill)
8516 (vhdl-backward-syntactic-ws)
8517 (setq end (point-marker))
8518 (insert ";"))
8519 ;; delete superfluous parentheses
8520 (while (progn (goto-char beg)
8521 (condition-case () (forward-sexp)
8522 (error (goto-char (point-max))))
8523 (< (point) end))
8524 (delete-char -1))
8525 ;; add closing parenthesis
8526 (when (> (point) end)
8527 (goto-char end)
8528 (insert ")")))))))
8531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8532 ;;; Electrification
8533 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8535 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8536 "Syntax of prompt inserted by template generators.")
8538 (defvar vhdl-template-invoked-by-hook nil
8539 "Indicates whether a template has been invoked by a hook or by key or menu.
8540 Used for undoing after template abortion.")
8542 ;; correct different behavior of function `unread-command-events' in XEmacs
8543 (defun vhdl-character-to-event (arg))
8544 (defalias 'vhdl-character-to-event
8545 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8547 (defun vhdl-work-library ()
8548 "Return the working library name of the current project or \"work\" if no
8549 project is defined."
8550 (vhdl-resolve-env-variable
8551 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8553 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8554 ;; Enabling/disabling
8556 (define-minor-mode vhdl-electric-mode
8557 "Toggle VHDL electric mode.
8558 With a prefix argument ARG, enable the mode if ARG is positive,
8559 and disable it otherwise. If called from Lisp, enable it if ARG
8560 is omitted or nil."
8561 :global t :group 'vhdl-mode)
8563 (define-minor-mode vhdl-stutter-mode
8564 "Toggle VHDL stuttering mode.
8565 With a prefix argument ARG, enable the mode if ARG is positive,
8566 and disable it otherwise. If called from Lisp, enable it if ARG
8567 is omitted or nil."
8568 :global t :group 'vhdl-mode)
8570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8571 ;; Stuttering
8573 (defun vhdl-electric-dash (count)
8574 "-- starts a comment, --- draws a horizontal line,
8575 ---- starts a display comment."
8576 (interactive "p")
8577 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8578 (cond
8579 ((and abbrev-start-location (= abbrev-start-location (point)))
8580 (setq abbrev-start-location nil)
8581 (goto-char last-abbrev-location)
8582 (beginning-of-line nil)
8583 (vhdl-comment-display))
8584 ((/= (preceding-char) ?-) ; standard dash (minus)
8585 (self-insert-command count))
8586 (t (self-insert-command count)
8587 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8588 (let ((next-input (read-char)))
8589 (if (= next-input ?-) ; triple dash
8590 (progn
8591 (vhdl-comment-display-line)
8592 (message
8593 "Enter '-' for display comment, else continue coding")
8594 (let ((next-input (read-char)))
8595 (if (= next-input ?-) ; four dashes
8596 (vhdl-comment-display t)
8597 (setq unread-command-events ; pushback the char
8598 (list (vhdl-character-to-event next-input))))))
8599 (setq unread-command-events ; pushback the char
8600 (list (vhdl-character-to-event next-input)))
8601 (vhdl-comment-insert)))))
8602 (self-insert-command count)))
8604 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8605 (interactive "p")
8606 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8607 (if (= (preceding-char) ?\()
8608 (progn (delete-char -1) (insert-char ?\[ 1))
8609 (insert-char ?\( 1))
8610 (self-insert-command count)))
8612 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8613 (interactive "p")
8614 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8615 (progn
8616 (if (= (preceding-char) ?\))
8617 (progn (delete-char -1) (insert-char ?\] 1))
8618 (insert-char ?\) 1))
8619 (blink-matching-open))
8620 (self-insert-command count)))
8622 (defun vhdl-electric-quote (count) "'' --> \""
8623 (interactive "p")
8624 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8625 (if (= (preceding-char) vhdl-last-input-event)
8626 (progn (delete-char -1) (insert-char ?\" 1))
8627 (insert-char ?\' 1))
8628 (self-insert-command count)))
8630 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8631 (interactive "p")
8632 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8633 (cond ((= (preceding-char) vhdl-last-input-event)
8634 (progn (delete-char -1)
8635 (unless (eq (preceding-char) ? ) (insert " "))
8636 (insert ": ")
8637 (setq this-command 'vhdl-electric-colon)))
8638 ((and
8639 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8640 (progn (delete-char -1) (insert "= ")))
8641 (t (insert-char ?\; 1)))
8642 (self-insert-command count)))
8644 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8645 (interactive "p")
8646 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8647 (cond ((= (preceding-char) vhdl-last-input-event)
8648 (progn (delete-char -1)
8649 (unless (eq (preceding-char) ? ) (insert " "))
8650 (insert "<= ")))
8651 (t (insert-char ?\, 1)))
8652 (self-insert-command count)))
8654 (defun vhdl-electric-period (count) "'..' --> ' => '"
8655 (interactive "p")
8656 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8657 (cond ((= (preceding-char) vhdl-last-input-event)
8658 (progn (delete-char -1)
8659 (unless (eq (preceding-char) ? ) (insert " "))
8660 (insert "=> ")))
8661 (t (insert-char ?\. 1)))
8662 (self-insert-command count)))
8664 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8665 (interactive "p")
8666 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8667 (cond ((= (preceding-char) vhdl-last-input-event)
8668 (progn (delete-char -1)
8669 (unless (eq (preceding-char) ? ) (insert " "))
8670 (insert "== ")))
8671 (t (insert-char ?\= 1)))
8672 (self-insert-command count)))
8674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8675 ;; VHDL templates
8677 (defun vhdl-template-paired-parens ()
8678 "Insert a pair of round parentheses, placing point between them."
8679 (interactive)
8680 (insert "()")
8681 (backward-char))
8683 (defun vhdl-template-alias ()
8684 "Insert alias declaration."
8685 (interactive)
8686 (let ((start (point)))
8687 (vhdl-insert-keyword "ALIAS ")
8688 (when (vhdl-template-field "name" nil t start (point))
8689 (insert " : ")
8690 (unless (vhdl-template-field
8691 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8692 nil t)
8693 (delete-char -3))
8694 (vhdl-insert-keyword " IS ")
8695 (vhdl-template-field "name" ";")
8696 (vhdl-comment-insert-inline))))
8698 (defun vhdl-template-architecture ()
8699 "Insert architecture."
8700 (interactive)
8701 (let ((margin (current-indentation))
8702 (start (point))
8703 arch-name)
8704 (vhdl-insert-keyword "ARCHITECTURE ")
8705 (when (setq arch-name
8706 (vhdl-template-field "name" nil t start (point)))
8707 (vhdl-insert-keyword " OF ")
8708 (if (save-excursion
8709 (vhdl-prepare-search-1
8710 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8711 (insert (match-string 1))
8712 (vhdl-template-field "entity name"))
8713 (vhdl-insert-keyword " IS\n")
8714 (vhdl-template-begin-end
8715 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8716 (memq vhdl-insert-empty-lines '(unit all))))))
8718 (defun vhdl-template-array (kind &optional secondary)
8719 "Insert array type definition."
8720 (interactive)
8721 (let ((start (point)))
8722 (vhdl-insert-keyword "ARRAY (")
8723 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8724 secondary)
8725 (vhdl-insert-keyword ") OF ")
8726 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8727 (vhdl-insert-keyword ";"))))
8729 (defun vhdl-template-assert ()
8730 "Insert an assertion statement."
8731 (interactive)
8732 (let ((start (point)))
8733 (vhdl-insert-keyword "ASSERT ")
8734 (when vhdl-conditions-in-parenthesis (insert "("))
8735 (when (vhdl-template-field "condition (negated)" nil t start (point))
8736 (when vhdl-conditions-in-parenthesis (insert ")"))
8737 (setq start (point))
8738 (vhdl-insert-keyword " REPORT ")
8739 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8740 (delete-region start (point)))
8741 (setq start (point))
8742 (vhdl-insert-keyword " SEVERITY ")
8743 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8744 (delete-region start (point)))
8745 (insert ";"))))
8747 (defun vhdl-template-attribute ()
8748 "Insert an attribute declaration or specification."
8749 (interactive)
8750 (if (eq (vhdl-decision-query
8751 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8752 (vhdl-template-attribute-spec)
8753 (vhdl-template-attribute-decl)))
8755 (defun vhdl-template-attribute-decl ()
8756 "Insert an attribute declaration."
8757 (interactive)
8758 (let ((start (point)))
8759 (vhdl-insert-keyword "ATTRIBUTE ")
8760 (when (vhdl-template-field "name" " : " t start (point))
8761 (vhdl-template-field "type" ";")
8762 (vhdl-comment-insert-inline))))
8764 (defun vhdl-template-attribute-spec ()
8765 "Insert an attribute specification."
8766 (interactive)
8767 (let ((start (point)))
8768 (vhdl-insert-keyword "ATTRIBUTE ")
8769 (when (vhdl-template-field "name" nil t start (point))
8770 (vhdl-insert-keyword " OF ")
8771 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8772 (vhdl-template-field "entity class")
8773 (vhdl-insert-keyword " IS ")
8774 (vhdl-template-field "expression" ";"))))
8776 (defun vhdl-template-block ()
8777 "Insert a block."
8778 (interactive)
8779 (let ((margin (current-indentation))
8780 (start (point))
8781 label)
8782 (vhdl-insert-keyword ": BLOCK ")
8783 (goto-char start)
8784 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8785 (forward-word 1)
8786 (forward-char 1)
8787 (insert "(")
8788 (if (vhdl-template-field "[guard expression]" nil t)
8789 (insert ")")
8790 (delete-char -2))
8791 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8792 (insert "\n")
8793 (vhdl-template-begin-end "BLOCK" label margin)
8794 (vhdl-comment-block))))
8796 (defun vhdl-template-block-configuration ()
8797 "Insert a block configuration statement."
8798 (interactive)
8799 (let ((margin (current-indentation))
8800 (start (point)))
8801 (vhdl-insert-keyword "FOR ")
8802 (when (vhdl-template-field "block name" nil t start (point))
8803 (vhdl-insert-keyword "\n\n")
8804 (indent-to margin)
8805 (vhdl-insert-keyword "END FOR;")
8806 (end-of-line 0)
8807 (indent-to (+ margin vhdl-basic-offset)))))
8809 (defun vhdl-template-break ()
8810 "Insert a break statement."
8811 (interactive)
8812 (let (position)
8813 (vhdl-insert-keyword "BREAK")
8814 (setq position (point))
8815 (insert " ")
8816 (while (or
8817 (progn (vhdl-insert-keyword "FOR ")
8818 (if (vhdl-template-field "[quantity name]" " USE " t)
8819 (progn (vhdl-template-field "quantity name" " => ") t)
8820 (delete-region (point)
8821 (progn (forward-word -1) (point)))
8822 nil))
8823 (vhdl-template-field "[quantity name]" " => " t))
8824 (vhdl-template-field "expression")
8825 (setq position (point))
8826 (insert ", "))
8827 (delete-region position (point))
8828 (unless (vhdl-sequential-statement-p)
8829 (vhdl-insert-keyword " ON ")
8830 (if (vhdl-template-field "[sensitivity list]" nil t)
8831 (setq position (point))
8832 (delete-region position (point))))
8833 (vhdl-insert-keyword " WHEN ")
8834 (when vhdl-conditions-in-parenthesis (insert "("))
8835 (if (vhdl-template-field "[condition]" nil t)
8836 (when vhdl-conditions-in-parenthesis (insert ")"))
8837 (delete-region position (point)))
8838 (insert ";")))
8840 (defun vhdl-template-case (&optional kind)
8841 "Insert a case statement."
8842 (interactive)
8843 (let ((margin (current-indentation))
8844 (start (point))
8845 label)
8846 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
8847 (not (vhdl-standard-p 'ams))) 'is 'use)))
8848 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8849 (vhdl-insert-keyword "CASE ")
8850 (vhdl-insert-keyword ": CASE ")
8851 (goto-char start)
8852 (setq label (vhdl-template-field "[label]" nil t))
8853 (unless label (delete-char 2))
8854 (forward-word 1)
8855 (forward-char 1))
8856 (when (vhdl-template-field "expression" nil t start (point))
8857 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8858 (indent-to margin)
8859 (vhdl-insert-keyword "END CASE")
8860 (when label (insert " " label))
8861 (insert ";")
8862 (forward-line -1)
8863 (indent-to (+ margin vhdl-basic-offset))
8864 (vhdl-insert-keyword "WHEN ")
8865 (let ((position (point)))
8866 (insert " => ;\n")
8867 (indent-to (+ margin vhdl-basic-offset))
8868 (vhdl-insert-keyword "WHEN OTHERS => null;")
8869 (goto-char position)))))
8871 (defun vhdl-template-case-is ()
8872 "Insert a sequential case statement."
8873 (interactive)
8874 (vhdl-template-case 'is))
8876 (defun vhdl-template-case-use ()
8877 "Insert a simultaneous case statement."
8878 (interactive)
8879 (vhdl-template-case 'use))
8881 (defun vhdl-template-component ()
8882 "Insert a component declaration."
8883 (interactive)
8884 (vhdl-template-component-decl))
8886 (defun vhdl-template-component-conf ()
8887 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8888 since these are almost equivalent)."
8889 (interactive)
8890 (let ((margin (current-indentation))
8891 (result (vhdl-template-configuration-spec t)))
8892 (when result
8893 (insert "\n")
8894 (indent-to margin)
8895 (vhdl-insert-keyword "END FOR;")
8896 (when (eq result 'no-use)
8897 (end-of-line -0)))))
8899 (defun vhdl-template-component-decl ()
8900 "Insert a component declaration."
8901 (interactive)
8902 (let ((margin (current-indentation))
8903 (start (point))
8904 name end-column)
8905 (vhdl-insert-keyword "COMPONENT ")
8906 (when (setq name (vhdl-template-field "name" nil t start (point)))
8907 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8908 (insert "\n\n")
8909 (indent-to margin)
8910 (vhdl-insert-keyword "END COMPONENT")
8911 (unless (vhdl-standard-p '87) (insert " " name))
8912 (insert ";")
8913 (setq end-column (current-column))
8914 (end-of-line -0)
8915 (indent-to (+ margin vhdl-basic-offset))
8916 (vhdl-template-generic-list t t)
8917 (insert "\n")
8918 (indent-to (+ margin vhdl-basic-offset))
8919 (vhdl-template-port-list t)
8920 (beginning-of-line 2)
8921 (forward-char end-column))))
8923 (defun vhdl-template-component-inst ()
8924 "Insert a component instantiation statement."
8925 (interactive)
8926 (let ((margin (current-indentation))
8927 (start (point))
8928 unit position)
8929 (when (vhdl-template-field "instance label" nil t start (point))
8930 (insert ": ")
8931 (if (not (vhdl-use-direct-instantiation))
8932 (vhdl-template-field "component name")
8933 ;; direct instantiation
8934 (setq unit (vhdl-template-field
8935 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8936 (setq unit (upcase (or unit "")))
8937 (cond ((equal unit "ENTITY")
8938 (let ((begin (point)))
8939 (vhdl-template-field "library name" "." t begin (point) nil
8940 (vhdl-work-library))
8941 (vhdl-template-field "entity name" "(")
8942 (if (vhdl-template-field "[architecture name]" nil t)
8943 (insert ")")
8944 (delete-char -1))))
8945 ((equal unit "CONFIGURATION")
8946 (vhdl-template-field "library name" "." nil nil nil nil
8947 (vhdl-work-library))
8948 (vhdl-template-field "configuration name"))
8949 (t (vhdl-template-field "component name"))))
8950 (insert "\n")
8951 (indent-to (+ margin vhdl-basic-offset))
8952 (setq position (point))
8953 (vhdl-insert-keyword "GENERIC ")
8954 (when (vhdl-template-map position t t)
8955 (insert "\n")
8956 (indent-to (+ margin vhdl-basic-offset)))
8957 (setq position (point))
8958 (vhdl-insert-keyword "PORT ")
8959 (unless (vhdl-template-map position t t)
8960 (delete-region (line-beginning-position) (point))
8961 (delete-char -1))
8962 (insert ";"))))
8964 (defun vhdl-template-conditional-signal-asst ()
8965 "Insert a conditional signal assignment."
8966 (interactive)
8967 (when (vhdl-template-field "target signal")
8968 (insert " <= ")
8969 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8970 ; (insert " "))
8971 (let ((margin (current-column))
8972 (start (point))
8973 position)
8974 (vhdl-template-field "waveform")
8975 (setq position (point))
8976 (vhdl-insert-keyword " WHEN ")
8977 (when vhdl-conditions-in-parenthesis (insert "("))
8978 (while (and (vhdl-template-field "[condition]" nil t)
8979 (progn
8980 (when vhdl-conditions-in-parenthesis (insert ")"))
8981 (setq position (point))
8982 (vhdl-insert-keyword " ELSE")
8983 (insert "\n")
8984 (indent-to margin)
8985 (vhdl-template-field "[waveform]" nil t)))
8986 (setq position (point))
8987 (vhdl-insert-keyword " WHEN ")
8988 (when vhdl-conditions-in-parenthesis (insert "(")))
8989 (delete-region position (point))
8990 (insert ";")
8991 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8993 (defun vhdl-template-configuration ()
8994 "Insert a configuration specification if within an architecture,
8995 a block or component configuration if within a configuration declaration,
8996 a configuration declaration if not within a design unit."
8997 (interactive)
8998 (vhdl-prepare-search-1
8999 (cond
9000 ((and (save-excursion ; architecture body
9001 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
9002 (equal "ARCHITECTURE" (upcase (match-string 1))))
9003 (vhdl-template-configuration-spec))
9004 ((and (save-excursion ; configuration declaration
9005 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9006 (equal "CONFIGURATION" (upcase (match-string 1))))
9007 (if (eq (vhdl-decision-query
9008 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
9009 (vhdl-template-component-conf)
9010 (vhdl-template-block-configuration)))
9011 (t (vhdl-template-configuration-decl))))) ; otherwise
9013 (defun vhdl-template-configuration-spec (&optional optional-use)
9014 "Insert a configuration specification."
9015 (interactive)
9016 (let ((margin (current-indentation))
9017 (start (point))
9018 aspect position)
9019 (vhdl-insert-keyword "FOR ")
9020 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9021 t start (point))
9022 (vhdl-template-field "component name" "\n")
9023 (indent-to (+ margin vhdl-basic-offset))
9024 (setq start (point))
9025 (vhdl-insert-keyword "USE ")
9026 (if (and optional-use
9027 (not (setq aspect (vhdl-template-field
9028 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
9029 (progn (delete-region start (point)) 'no-use)
9030 (unless optional-use
9031 (setq aspect (vhdl-template-field
9032 "ENTITY | CONFIGURATION | OPEN" " ")))
9033 (setq aspect (upcase (or aspect "")))
9034 (cond ((equal aspect "ENTITY")
9035 (vhdl-template-field "library name" "." nil nil nil nil
9036 (vhdl-work-library))
9037 (vhdl-template-field "entity name" "(")
9038 (if (vhdl-template-field "[architecture name]" nil t)
9039 (insert ")")
9040 (delete-char -1))
9041 (insert "\n")
9042 (indent-to (+ margin (* 2 vhdl-basic-offset)))
9043 (setq position (point))
9044 (vhdl-insert-keyword "GENERIC ")
9045 (when (vhdl-template-map position t t)
9046 (insert "\n")
9047 (indent-to (+ margin (* 2 vhdl-basic-offset))))
9048 (setq position (point))
9049 (vhdl-insert-keyword "PORT ")
9050 (unless (vhdl-template-map position t t)
9051 (delete-region (line-beginning-position) (point))
9052 (delete-char -1))
9053 (insert ";")
9055 ((equal aspect "CONFIGURATION")
9056 (vhdl-template-field "library name" "." nil nil nil nil
9057 (vhdl-work-library))
9058 (vhdl-template-field "configuration name" ";"))
9059 (t (delete-char -1) (insert ";") t))))))
9062 (defun vhdl-template-configuration-decl ()
9063 "Insert a configuration declaration."
9064 (interactive)
9065 (let ((margin (current-indentation))
9066 (start (point))
9067 entity-exists string name position)
9068 (vhdl-insert-keyword "CONFIGURATION ")
9069 (when (setq name (vhdl-template-field "name" nil t start (point)))
9070 (vhdl-insert-keyword " OF ")
9071 (save-excursion
9072 (vhdl-prepare-search-1
9073 (setq entity-exists (vhdl-re-search-backward
9074 "\\<entity \\(\\w*\\) is\\>" nil t))
9075 (setq string (match-string 1))))
9076 (if (and entity-exists (not (equal string "")))
9077 (insert string)
9078 (vhdl-template-field "entity name"))
9079 (vhdl-insert-keyword " IS\n")
9080 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9081 (indent-to (+ margin vhdl-basic-offset))
9082 (setq position (point))
9083 (insert "\n")
9084 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9085 (indent-to margin)
9086 (vhdl-insert-keyword "END ")
9087 (unless (vhdl-standard-p '87)
9088 (vhdl-insert-keyword "CONFIGURATION "))
9089 (insert name ";")
9090 (goto-char position))))
9092 (defun vhdl-template-constant ()
9093 "Insert a constant declaration."
9094 (interactive)
9095 (let ((start (point))
9096 (in-arglist (vhdl-in-argument-list-p)))
9097 (vhdl-insert-keyword "CONSTANT ")
9098 (when (vhdl-template-field "name" nil t start (point))
9099 (insert " : ")
9100 (when in-arglist (vhdl-insert-keyword "IN "))
9101 (vhdl-template-field "type")
9102 (if in-arglist
9103 (progn (insert ";")
9104 (vhdl-comment-insert-inline))
9105 (let ((position (point)))
9106 (insert " := ")
9107 (unless (vhdl-template-field "[initialization]" nil t)
9108 (delete-region position (point)))
9109 (insert ";")
9110 (vhdl-comment-insert-inline))))))
9112 (defun vhdl-template-default ()
9113 "Insert nothing."
9114 (interactive)
9115 (insert " ")
9116 (unexpand-abbrev)
9117 (backward-word 1)
9118 (vhdl-case-word 1)
9119 (forward-char 1))
9121 (defun vhdl-template-default-indent ()
9122 "Insert nothing and indent."
9123 (interactive)
9124 (insert " ")
9125 (unexpand-abbrev)
9126 (backward-word 1)
9127 (vhdl-case-word 1)
9128 (forward-char 1)
9129 (indent-according-to-mode))
9131 (defun vhdl-template-disconnect ()
9132 "Insert a disconnect statement."
9133 (interactive)
9134 (let ((start (point)))
9135 (vhdl-insert-keyword "DISCONNECT ")
9136 (when (vhdl-template-field "signal names | OTHERS | ALL"
9137 " : " t start (point))
9138 (vhdl-template-field "type")
9139 (vhdl-insert-keyword " AFTER ")
9140 (vhdl-template-field "time expression" ";"))))
9142 (defun vhdl-template-else ()
9143 "Insert an else statement."
9144 (interactive)
9145 (let (margin)
9146 (vhdl-prepare-search-1
9147 (vhdl-insert-keyword "ELSE")
9148 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
9149 (equal "WHEN" (upcase (match-string 1))))
9150 (insert " ")
9151 (indent-according-to-mode)
9152 (setq margin (current-indentation))
9153 (insert "\n")
9154 (indent-to (+ margin vhdl-basic-offset))))))
9156 (defun vhdl-template-elsif ()
9157 "Insert an elsif statement."
9158 (interactive)
9159 (let ((start (point))
9160 margin)
9161 (vhdl-insert-keyword "ELSIF ")
9162 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
9163 (when vhdl-conditions-in-parenthesis (insert "("))
9164 (when (vhdl-template-field "condition" nil t start (point))
9165 (when vhdl-conditions-in-parenthesis (insert ")"))
9166 (indent-according-to-mode)
9167 (setq margin (current-indentation))
9168 (vhdl-insert-keyword
9169 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
9170 (indent-to (+ margin vhdl-basic-offset))))))
9172 (defun vhdl-template-entity ()
9173 "Insert an entity."
9174 (interactive)
9175 (let ((margin (current-indentation))
9176 (start (point))
9177 name end-column)
9178 (vhdl-insert-keyword "ENTITY ")
9179 (when (setq name (vhdl-template-field "name" nil t start (point)))
9180 (vhdl-insert-keyword " IS\n\n")
9181 (indent-to margin)
9182 (vhdl-insert-keyword "END ")
9183 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9184 (insert name ";")
9185 (setq end-column (current-column))
9186 (end-of-line -0)
9187 (indent-to (+ margin vhdl-basic-offset))
9188 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9189 (indent-to (+ margin vhdl-basic-offset))
9190 (when (vhdl-template-generic-list t)
9191 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9192 (insert "\n")
9193 (indent-to (+ margin vhdl-basic-offset))
9194 (when (vhdl-template-port-list t)
9195 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9196 (beginning-of-line 2)
9197 (forward-char end-column))))
9199 (defun vhdl-template-exit ()
9200 "Insert an exit statement."
9201 (interactive)
9202 (let ((start (point)))
9203 (vhdl-insert-keyword "EXIT ")
9204 (if (vhdl-template-field "[loop label]" nil t start (point))
9205 (let ((position (point)))
9206 (vhdl-insert-keyword " WHEN ")
9207 (when vhdl-conditions-in-parenthesis (insert "("))
9208 (if (vhdl-template-field "[condition]" nil t)
9209 (when vhdl-conditions-in-parenthesis (insert ")"))
9210 (delete-region position (point))))
9211 (delete-char -1))
9212 (insert ";")))
9214 (defun vhdl-template-file ()
9215 "Insert a file declaration."
9216 (interactive)
9217 (let ((start (point)))
9218 (vhdl-insert-keyword "FILE ")
9219 (when (vhdl-template-field "name" nil t start (point))
9220 (insert " : ")
9221 (vhdl-template-field "type")
9222 (unless (vhdl-standard-p '87)
9223 (vhdl-insert-keyword " OPEN ")
9224 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9225 nil t)
9226 (delete-char -6)))
9227 (vhdl-insert-keyword " IS ")
9228 (when (vhdl-standard-p '87)
9229 (vhdl-template-field "[IN | OUT]" " " t))
9230 (vhdl-template-field "filename-string" nil nil nil nil t)
9231 (insert ";")
9232 (vhdl-comment-insert-inline))))
9234 (defun vhdl-template-for ()
9235 "Insert a block or component configuration if within a configuration
9236 declaration, a configuration specification if within an architecture
9237 declarative part (and not within a subprogram), a for-loop if within a
9238 sequential statement part (subprogram or process), and a for-generate
9239 otherwise."
9240 (interactive)
9241 (vhdl-prepare-search-1
9242 (cond
9243 ((vhdl-sequential-statement-p) ; sequential statement
9244 (vhdl-template-for-loop))
9245 ((and (save-excursion ; configuration declaration
9246 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9247 (equal "CONFIGURATION" (upcase (match-string 1))))
9248 (if (eq (vhdl-decision-query
9249 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9250 (vhdl-template-component-conf)
9251 (vhdl-template-block-configuration)))
9252 ((and (save-excursion
9253 (re-search-backward ; architecture declarative part
9254 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9255 (equal "ARCHITECTURE" (upcase (match-string 1))))
9256 (vhdl-template-configuration-spec))
9257 (t (vhdl-template-for-generate))))) ; concurrent statement
9259 (defun vhdl-template-for-generate ()
9260 "Insert a for-generate."
9261 (interactive)
9262 (let ((margin (current-indentation))
9263 (start (point))
9264 label position)
9265 (vhdl-insert-keyword ": FOR ")
9266 (setq position (point-marker))
9267 (goto-char start)
9268 (when (setq label (vhdl-template-field "label" nil t start position))
9269 (goto-char position)
9270 (vhdl-template-field "loop variable")
9271 (vhdl-insert-keyword " IN ")
9272 (vhdl-template-field "range")
9273 (vhdl-template-generate-body margin label))))
9275 (defun vhdl-template-for-loop ()
9276 "Insert a for loop."
9277 (interactive)
9278 (let ((margin (current-indentation))
9279 (start (point))
9280 label index)
9281 (if (not (eq vhdl-optional-labels 'all))
9282 (vhdl-insert-keyword "FOR ")
9283 (vhdl-insert-keyword ": FOR ")
9284 (goto-char start)
9285 (setq label (vhdl-template-field "[label]" nil t))
9286 (unless label (delete-char 2))
9287 (forward-word 1)
9288 (forward-char 1))
9289 (when (setq index (vhdl-template-field "loop variable"
9290 nil t start (point)))
9291 (vhdl-insert-keyword " IN ")
9292 (vhdl-template-field "range")
9293 (vhdl-insert-keyword " LOOP\n\n")
9294 (indent-to margin)
9295 (vhdl-insert-keyword "END LOOP")
9296 (if label
9297 (insert " " label ";")
9298 (insert ";")
9299 (when vhdl-self-insert-comments (insert " -- " index)))
9300 (forward-line -1)
9301 (indent-to (+ margin vhdl-basic-offset)))))
9303 (defun vhdl-template-function (&optional kind)
9304 "Insert a function declaration or body."
9305 (interactive)
9306 (let ((margin (current-indentation))
9307 (start (point))
9308 name)
9309 (vhdl-insert-keyword "FUNCTION ")
9310 (when (setq name (vhdl-template-field "name" nil t start (point)))
9311 (vhdl-template-argument-list t)
9312 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9313 (end-of-line)
9314 (insert "\n")
9315 (indent-to (+ margin vhdl-basic-offset))
9316 (vhdl-insert-keyword "RETURN ")
9317 (vhdl-template-field "type")
9318 (if (if kind (eq kind 'body)
9319 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9320 (progn (vhdl-insert-keyword " IS\n")
9321 (vhdl-template-begin-end
9322 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9323 (vhdl-comment-block))
9324 (insert ";")))))
9326 (defun vhdl-template-function-decl ()
9327 "Insert a function declaration."
9328 (interactive)
9329 (vhdl-template-function 'decl))
9331 (defun vhdl-template-function-body ()
9332 "Insert a function declaration."
9333 (interactive)
9334 (vhdl-template-function 'body))
9336 (defun vhdl-template-generate ()
9337 "Insert a generation scheme."
9338 (interactive)
9339 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9340 (vhdl-template-if-generate)
9341 (vhdl-template-for-generate)))
9343 (defun vhdl-template-generic ()
9344 "Insert generic declaration, or generic map in instantiation statements."
9345 (interactive)
9346 (let ((start (point)))
9347 (vhdl-prepare-search-1
9348 (cond
9349 ((and (save-excursion ; entity declaration
9350 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9351 (equal "ENTITY" (upcase (match-string 1))))
9352 (vhdl-template-generic-list nil))
9353 ((or (save-excursion
9354 (or (beginning-of-line)
9355 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9356 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9357 (vhdl-insert-keyword "GENERIC ")
9358 (vhdl-template-map start))
9359 (t (vhdl-template-generic-list nil t))))))
9361 (defun vhdl-template-group ()
9362 "Insert group or group template declaration."
9363 (interactive)
9364 (let ((start (point)))
9365 (if (eq (vhdl-decision-query
9366 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9367 (vhdl-template-group-template)
9368 (vhdl-template-group-decl))))
9370 (defun vhdl-template-group-decl ()
9371 "Insert group declaration."
9372 (interactive)
9373 (let ((start (point)))
9374 (vhdl-insert-keyword "GROUP ")
9375 (when (vhdl-template-field "name" " : " t start (point))
9376 (vhdl-template-field "template name" " (")
9377 (vhdl-template-field "constituent list" ");")
9378 (vhdl-comment-insert-inline))))
9380 (defun vhdl-template-group-template ()
9381 "Insert group template declaration."
9382 (interactive)
9383 (let ((start (point)))
9384 (vhdl-insert-keyword "GROUP ")
9385 (when (vhdl-template-field "template name" nil t start (point))
9386 (vhdl-insert-keyword " IS (")
9387 (vhdl-template-field "entity class list" ");")
9388 (vhdl-comment-insert-inline))))
9390 (defun vhdl-template-if ()
9391 "Insert a sequential if statement or an if-generate statement."
9392 (interactive)
9393 (if (vhdl-sequential-statement-p)
9394 (vhdl-template-if-then)
9395 (if (and (vhdl-standard-p 'ams)
9396 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9397 (vhdl-template-if-use)
9398 (vhdl-template-if-generate))))
9400 (defun vhdl-template-if-generate ()
9401 "Insert an if-generate."
9402 (interactive)
9403 (let ((margin (current-indentation))
9404 (start (point))
9405 label position)
9406 (vhdl-insert-keyword ": IF ")
9407 (setq position (point-marker))
9408 (goto-char start)
9409 (when (setq label (vhdl-template-field "label" nil t start position))
9410 (goto-char position)
9411 (when vhdl-conditions-in-parenthesis (insert "("))
9412 (vhdl-template-field "condition")
9413 (when vhdl-conditions-in-parenthesis (insert ")"))
9414 (vhdl-template-generate-body margin label))))
9416 (defun vhdl-template-if-then-use (kind)
9417 "Insert a sequential if statement."
9418 (interactive)
9419 (let ((margin (current-indentation))
9420 (start (point))
9421 label)
9422 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9423 (vhdl-insert-keyword "IF ")
9424 (vhdl-insert-keyword ": IF ")
9425 (goto-char start)
9426 (setq label (vhdl-template-field "[label]" nil t))
9427 (unless label (delete-char 2))
9428 (forward-word 1)
9429 (forward-char 1))
9430 (when vhdl-conditions-in-parenthesis (insert "("))
9431 (when (vhdl-template-field "condition" nil t start (point))
9432 (when vhdl-conditions-in-parenthesis (insert ")"))
9433 (vhdl-insert-keyword
9434 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9435 (indent-to margin)
9436 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9437 (when label (insert " " label))
9438 (insert ";")
9439 (forward-line -1)
9440 (indent-to (+ margin vhdl-basic-offset)))))
9442 (defun vhdl-template-if-then ()
9443 "Insert a sequential if statement."
9444 (interactive)
9445 (vhdl-template-if-then-use 'then))
9447 (defun vhdl-template-if-use ()
9448 "Insert a simultaneous if statement."
9449 (interactive)
9450 (vhdl-template-if-then-use 'use))
9452 (defun vhdl-template-instance ()
9453 "Insert a component instantiation statement."
9454 (interactive)
9455 (vhdl-template-component-inst))
9457 (defun vhdl-template-library ()
9458 "Insert a library specification."
9459 (interactive)
9460 (let ((margin (current-indentation))
9461 (start (point))
9462 name end-pos)
9463 (vhdl-insert-keyword "LIBRARY ")
9464 (when (setq name (vhdl-template-field "names" nil t start (point)))
9465 (insert ";")
9466 (unless (string-match "," name)
9467 (setq end-pos (point))
9468 (insert "\n")
9469 (indent-to margin)
9470 (vhdl-insert-keyword "USE ")
9471 (insert name)
9472 (vhdl-insert-keyword "..ALL;")
9473 (backward-char 5)
9474 (if (vhdl-template-field "package name")
9475 (forward-char 5)
9476 (delete-region end-pos (+ (point) 5)))))))
9478 (defun vhdl-template-limit ()
9479 "Insert a limit."
9480 (interactive)
9481 (let ((start (point)))
9482 (vhdl-insert-keyword "LIMIT ")
9483 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9484 t start (point))
9485 (vhdl-template-field "type")
9486 (vhdl-insert-keyword " WITH ")
9487 (vhdl-template-field "real expression" ";"))))
9489 (defun vhdl-template-loop ()
9490 "Insert a loop."
9491 (interactive)
9492 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9493 (cond ((eq char ?w)
9494 (vhdl-template-while-loop))
9495 ((eq char ?f)
9496 (vhdl-template-for-loop))
9497 (t (vhdl-template-bare-loop)))))
9499 (defun vhdl-template-bare-loop ()
9500 "Insert a loop."
9501 (interactive)
9502 (let ((margin (current-indentation))
9503 (start (point))
9504 label)
9505 (if (not (eq vhdl-optional-labels 'all))
9506 (vhdl-insert-keyword "LOOP ")
9507 (vhdl-insert-keyword ": LOOP ")
9508 (goto-char start)
9509 (setq label (vhdl-template-field "[label]" nil t))
9510 (unless label (delete-char 2))
9511 (forward-word 1)
9512 (delete-char 1))
9513 (insert "\n\n")
9514 (indent-to margin)
9515 (vhdl-insert-keyword "END LOOP")
9516 (insert (if label (concat " " label ";") ";"))
9517 (forward-line -1)
9518 (indent-to (+ margin vhdl-basic-offset))))
9520 (defun vhdl-template-map (&optional start optional secondary)
9521 "Insert a map specification with association list."
9522 (interactive)
9523 (let ((start (or start (point)))
9524 margin end-pos)
9525 (vhdl-insert-keyword "MAP (")
9526 (if (not vhdl-association-list-with-formals)
9527 (if (vhdl-template-field
9528 (concat (and optional "[") "association list" (and optional "]"))
9529 ")" (or (not secondary) optional)
9530 (and (not secondary) start) (point))
9532 (if (and optional secondary) (delete-region start (point)))
9533 nil)
9534 (if vhdl-argument-list-indent
9535 (setq margin (current-column))
9536 (setq margin (+ (current-indentation) vhdl-basic-offset))
9537 (insert "\n")
9538 (indent-to margin))
9539 (if (vhdl-template-field
9540 (concat (and optional "[") "formal" (and optional "]"))
9541 " => " (or (not secondary) optional)
9542 (and (not secondary) start) (point))
9543 (progn
9544 (vhdl-template-field "actual" ",")
9545 (setq end-pos (point))
9546 (insert "\n")
9547 (indent-to margin)
9548 (while (vhdl-template-field "[formal]" " => " t)
9549 (vhdl-template-field "actual" ",")
9550 (setq end-pos (point))
9551 (insert "\n")
9552 (indent-to margin))
9553 (delete-region end-pos (point))
9554 (delete-char -1)
9555 (insert ")")
9556 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9558 (when (and optional secondary) (delete-region start (point)))
9559 nil))))
9561 (defun vhdl-template-modify (&optional noerror)
9562 "Actualize modification date."
9563 (interactive)
9564 (vhdl-prepare-search-2
9565 (save-excursion
9566 (goto-char (point-min))
9567 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9568 (progn (delete-region (point) (progn (end-of-line) (point)))
9569 (vhdl-template-insert-date))
9570 (unless noerror
9571 (error "ERROR: Modification date prefix string \"%s\" not found"
9572 vhdl-modify-date-prefix-string))))))
9575 (defun vhdl-template-modify-noerror ()
9576 "Call `vhdl-template-modify' with NOERROR non-nil."
9577 (vhdl-template-modify t))
9579 (defun vhdl-template-nature ()
9580 "Insert a nature declaration."
9581 (interactive)
9582 (let ((start (point))
9583 name mid-pos end-pos)
9584 (vhdl-insert-keyword "NATURE ")
9585 (when (setq name (vhdl-template-field "name" nil t start (point)))
9586 (vhdl-insert-keyword " IS ")
9587 (let ((definition
9588 (upcase
9589 (or (vhdl-template-field
9590 "across type | ARRAY | RECORD")
9591 ""))))
9592 (cond ((equal definition "")
9593 (insert ";"))
9594 ((equal definition "ARRAY")
9595 (delete-region (point) (progn (forward-word -1) (point)))
9596 (vhdl-template-array 'nature t))
9597 ((equal definition "RECORD")
9598 (setq mid-pos (point-marker))
9599 (delete-region (point) (progn (forward-word -1) (point)))
9600 (vhdl-template-record 'nature name t))
9602 (vhdl-insert-keyword " ACROSS ")
9603 (vhdl-template-field "through type")
9604 (vhdl-insert-keyword " THROUGH ")
9605 (vhdl-template-field "reference name")
9606 (vhdl-insert-keyword " REFERENCE;")))
9607 (when mid-pos
9608 (setq end-pos (point-marker))
9609 (goto-char mid-pos)
9610 (end-of-line))
9611 (vhdl-comment-insert-inline)
9612 (when end-pos (goto-char end-pos))))))
9614 (defun vhdl-template-next ()
9615 "Insert a next statement."
9616 (interactive)
9617 (let ((start (point)))
9618 (vhdl-insert-keyword "NEXT ")
9619 (if (vhdl-template-field "[loop label]" nil t start (point))
9620 (let ((position (point)))
9621 (vhdl-insert-keyword " WHEN ")
9622 (when vhdl-conditions-in-parenthesis (insert "("))
9623 (if (vhdl-template-field "[condition]" nil t)
9624 (when vhdl-conditions-in-parenthesis (insert ")"))
9625 (delete-region position (point))))
9626 (delete-char -1))
9627 (insert ";")))
9629 (defun vhdl-template-others ()
9630 "Insert an others aggregate."
9631 (interactive)
9632 (let ((start (point)))
9633 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9634 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9635 (vhdl-insert-keyword "OTHERS => '")
9636 (when (vhdl-template-field "value" nil t start (point))
9637 (insert "')")))
9638 (vhdl-insert-keyword "OTHERS "))))
9640 (defun vhdl-template-package (&optional kind)
9641 "Insert a package specification or body."
9642 (interactive)
9643 (let ((margin (current-indentation))
9644 (start (point))
9645 name body position)
9646 (vhdl-insert-keyword "PACKAGE ")
9647 (setq body (if kind (eq kind 'body)
9648 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9649 (when body
9650 (vhdl-insert-keyword "BODY ")
9651 (when (save-excursion
9652 (vhdl-prepare-search-1
9653 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9654 (insert (setq name (match-string 1)))))
9655 (when (or name
9656 (setq name (vhdl-template-field "name" nil t start (point))))
9657 (vhdl-insert-keyword " IS\n")
9658 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9659 (indent-to (+ margin vhdl-basic-offset))
9660 (setq position (point))
9661 (insert "\n")
9662 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9663 (indent-to margin)
9664 (vhdl-insert-keyword "END ")
9665 (unless (vhdl-standard-p '87)
9666 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9667 (insert (or name "") ";")
9668 (goto-char position))))
9670 (defun vhdl-template-package-decl ()
9671 "Insert a package specification."
9672 (interactive)
9673 (vhdl-template-package 'decl))
9675 (defun vhdl-template-package-body ()
9676 "Insert a package body."
9677 (interactive)
9678 (vhdl-template-package 'body))
9680 (defun vhdl-template-port ()
9681 "Insert a port declaration, or port map in instantiation statements."
9682 (interactive)
9683 (let ((start (point)))
9684 (vhdl-prepare-search-1
9685 (cond
9686 ((and (save-excursion ; entity declaration
9687 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9688 (equal "ENTITY" (upcase (match-string 1))))
9689 (vhdl-template-port-list nil))
9690 ((or (save-excursion
9691 (or (beginning-of-line)
9692 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9693 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9694 (vhdl-insert-keyword "PORT ")
9695 (vhdl-template-map start))
9696 (t (vhdl-template-port-list nil))))))
9698 (defun vhdl-template-procedural ()
9699 "Insert a procedural."
9700 (interactive)
9701 (let ((margin (current-indentation))
9702 (start (point))
9703 (case-fold-search t)
9704 label)
9705 (vhdl-insert-keyword "PROCEDURAL ")
9706 (when (memq vhdl-optional-labels '(process all))
9707 (goto-char start)
9708 (insert ": ")
9709 (goto-char start)
9710 (setq label (vhdl-template-field "[label]" nil t))
9711 (unless label (delete-char 2))
9712 (forward-word 1)
9713 (forward-char 1))
9714 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9715 (insert "\n")
9716 (vhdl-template-begin-end "PROCEDURAL" label margin)
9717 (vhdl-comment-block)))
9719 (defun vhdl-template-procedure (&optional kind)
9720 "Insert a procedure declaration or body."
9721 (interactive)
9722 (let ((margin (current-indentation))
9723 (start (point))
9724 name)
9725 (vhdl-insert-keyword "PROCEDURE ")
9726 (when (setq name (vhdl-template-field "name" nil t start (point)))
9727 (vhdl-template-argument-list)
9728 (if (if kind (eq kind 'body)
9729 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9730 (progn (vhdl-insert-keyword " IS")
9731 (when vhdl-auto-align
9732 (vhdl-align-region-groups start (point) 1))
9733 (end-of-line) (insert "\n")
9734 (vhdl-template-begin-end
9735 (unless (vhdl-standard-p '87) "PROCEDURE")
9736 name margin)
9737 (vhdl-comment-block))
9738 (insert ";")
9739 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9740 (end-of-line)))))
9742 (defun vhdl-template-procedure-decl ()
9743 "Insert a procedure declaration."
9744 (interactive)
9745 (vhdl-template-procedure 'decl))
9747 (defun vhdl-template-procedure-body ()
9748 "Insert a procedure body."
9749 (interactive)
9750 (vhdl-template-procedure 'body))
9752 (defun vhdl-template-process (&optional kind)
9753 "Insert a process."
9754 (interactive)
9755 (let ((margin (current-indentation))
9756 (start (point))
9757 (reset-kind vhdl-reset-kind)
9758 label seq input-signals clock reset final-pos)
9759 (setq seq (if kind (eq kind 'seq)
9760 (eq (vhdl-decision-query
9761 "process" "(c)ombinational or (s)equential?" t) ?s)))
9762 (vhdl-insert-keyword "PROCESS ")
9763 (when (memq vhdl-optional-labels '(process all))
9764 (goto-char start)
9765 (insert ": ")
9766 (goto-char start)
9767 (setq label (vhdl-template-field "[label]" nil t))
9768 (unless label (delete-char 2))
9769 (forward-word 1)
9770 (forward-char 1))
9771 (insert "(")
9772 (if (not seq)
9773 (unless (setq input-signals
9774 (vhdl-template-field "[sensitivity list]" ")" t))
9775 (setq input-signals "")
9776 (delete-char -2))
9777 (setq clock (or (and (not (equal "" vhdl-clock-name))
9778 (progn (insert vhdl-clock-name) vhdl-clock-name))
9779 (vhdl-template-field "clock name") "<clock>"))
9780 (when (eq reset-kind 'query)
9781 (setq reset-kind
9782 (if (eq (vhdl-decision-query
9783 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9784 'async
9785 'sync)))
9786 (when (eq reset-kind 'async)
9787 (insert ", ")
9788 (setq reset (or (and (not (equal "" vhdl-reset-name))
9789 (progn (insert vhdl-reset-name) vhdl-reset-name))
9790 (vhdl-template-field "reset name") "<reset>")))
9791 (insert ")"))
9792 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9793 (insert "\n")
9794 (vhdl-template-begin-end "PROCESS" label margin)
9795 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9796 (when vhdl-prompt-for-comments
9797 (setq final-pos (point-marker))
9798 (vhdl-prepare-search-2
9799 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9800 (vhdl-re-search-backward "\\<process\\>" nil t))
9801 (end-of-line -0)
9802 (if (bobp)
9803 (progn (insert "\n") (forward-line -1))
9804 (insert "\n"))
9805 (indent-to margin)
9806 (insert "-- purpose: ")
9807 (if (not (vhdl-template-field "[description]" nil t))
9808 (vhdl-line-kill-entire)
9809 (insert "\n")
9810 (indent-to margin)
9811 (insert "-- type : ")
9812 (insert (if seq "sequential" "combinational") "\n")
9813 (indent-to margin)
9814 (insert "-- inputs : ")
9815 (if (not seq)
9816 (insert input-signals)
9817 (insert clock ", ")
9818 (when reset (insert reset ", "))
9819 (unless (vhdl-template-field "[signal names]" nil t)
9820 (delete-char -2)))
9821 (insert "\n")
9822 (indent-to margin)
9823 (insert "-- outputs: ")
9824 (vhdl-template-field "[signal names]" nil t))))
9825 (goto-char final-pos))))
9827 (defun vhdl-template-process-comb ()
9828 "Insert a combinational process."
9829 (interactive)
9830 (vhdl-template-process 'comb))
9832 (defun vhdl-template-process-seq ()
9833 "Insert a sequential process."
9834 (interactive)
9835 (vhdl-template-process 'seq))
9837 (defun vhdl-template-quantity ()
9838 "Insert a quantity declaration."
9839 (interactive)
9840 (if (vhdl-in-argument-list-p)
9841 (let ((start (point)))
9842 (vhdl-insert-keyword "QUANTITY ")
9843 (when (vhdl-template-field "names" nil t start (point))
9844 (insert " : ")
9845 (vhdl-template-field "[IN | OUT]" " " t)
9846 (vhdl-template-field "type")
9847 (insert ";")
9848 (vhdl-comment-insert-inline)))
9849 (let ((char (vhdl-decision-query
9850 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9851 (cond ((eq char ?f) (vhdl-template-quantity-free))
9852 ((eq char ?b) (vhdl-template-quantity-branch))
9853 ((eq char ?s) (vhdl-template-quantity-source))
9854 (t (vhdl-template-undo (point) (point)))))))
9856 (defun vhdl-template-quantity-free ()
9857 "Insert a free quantity declaration."
9858 (interactive)
9859 (vhdl-insert-keyword "QUANTITY ")
9860 (vhdl-template-field "names")
9861 (insert " : ")
9862 (vhdl-template-field "type")
9863 (let ((position (point)))
9864 (insert " := ")
9865 (unless (vhdl-template-field "[initialization]" nil t)
9866 (delete-region position (point)))
9867 (insert ";")
9868 (vhdl-comment-insert-inline)))
9870 (defun vhdl-template-quantity-branch ()
9871 "Insert a branch quantity declaration."
9872 (interactive)
9873 (let (position)
9874 (vhdl-insert-keyword "QUANTITY ")
9875 (when (vhdl-template-field "[across names]" " " t)
9876 (vhdl-insert-keyword "ACROSS "))
9877 (when (vhdl-template-field "[through names]" " " t)
9878 (vhdl-insert-keyword "THROUGH "))
9879 (vhdl-template-field "plus terminal name")
9880 (setq position (point))
9881 (vhdl-insert-keyword " TO ")
9882 (unless (vhdl-template-field "[minus terminal name]" nil t)
9883 (delete-region position (point)))
9884 (insert ";")
9885 (vhdl-comment-insert-inline)))
9887 (defun vhdl-template-quantity-source ()
9888 "Insert a source quantity declaration."
9889 (interactive)
9890 (vhdl-insert-keyword "QUANTITY ")
9891 (vhdl-template-field "names")
9892 (insert " : ")
9893 (vhdl-template-field "type" " ")
9894 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9895 (progn (vhdl-insert-keyword "NOISE ")
9896 (vhdl-template-field "power expression"))
9897 (vhdl-insert-keyword "SPECTRUM ")
9898 (vhdl-template-field "magnitude expression" ", ")
9899 (vhdl-template-field "phase expression"))
9900 (insert ";")
9901 (vhdl-comment-insert-inline))
9903 (defun vhdl-template-record (kind &optional name secondary)
9904 "Insert a record type declaration."
9905 (interactive)
9906 (let ((margin (current-column))
9907 (start (point))
9908 (first t))
9909 (vhdl-insert-keyword "RECORD\n")
9910 (indent-to (+ margin vhdl-basic-offset))
9911 (when (or (vhdl-template-field "element names"
9912 nil (not secondary) start (point))
9913 secondary)
9914 (while (or first (vhdl-template-field "[element names]" nil t))
9915 (insert " : ")
9916 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9917 (vhdl-comment-insert-inline)
9918 (insert "\n")
9919 (indent-to (+ margin vhdl-basic-offset))
9920 (setq first nil))
9921 (delete-region (line-beginning-position) (point))
9922 (indent-to margin)
9923 (vhdl-insert-keyword "END RECORD")
9924 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9925 (insert ";")
9926 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9928 (defun vhdl-template-report ()
9929 "Insert a report statement."
9930 (interactive)
9931 (let ((start (point)))
9932 (vhdl-insert-keyword "REPORT ")
9933 (if (equal "\"\"" (vhdl-template-field
9934 "string expression" nil t start (point) t))
9935 (delete-char -2)
9936 (setq start (point))
9937 (vhdl-insert-keyword " SEVERITY ")
9938 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9939 (delete-region start (point)))
9940 (insert ";"))))
9942 (defun vhdl-template-return ()
9943 "Insert a return statement."
9944 (interactive)
9945 (let ((start (point)))
9946 (vhdl-insert-keyword "RETURN ")
9947 (unless (vhdl-template-field "[expression]" nil t start (point))
9948 (delete-char -1))
9949 (insert ";")))
9951 (defun vhdl-template-selected-signal-asst ()
9952 "Insert a selected signal assignment."
9953 (interactive)
9954 (let ((margin (current-indentation))
9955 (start (point))
9956 (choices t))
9957 (let ((position (point)))
9958 (vhdl-insert-keyword " SELECT ")
9959 (goto-char position))
9960 (vhdl-insert-keyword "WITH ")
9961 (when (vhdl-template-field "selector expression"
9962 nil t start (+ (point) 7))
9963 (forward-word 1)
9964 (delete-char 1)
9965 (insert "\n")
9966 (indent-to (+ margin vhdl-basic-offset))
9967 (vhdl-template-field "target signal" " <= ")
9968 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9969 (insert "\n")
9970 (indent-to (+ margin vhdl-basic-offset))
9971 (vhdl-template-field "waveform")
9972 (vhdl-insert-keyword " WHEN ")
9973 (vhdl-template-field "choices" ",")
9974 (insert "\n")
9975 (indent-to (+ margin vhdl-basic-offset))
9976 (while (and choices (vhdl-template-field "[waveform]" nil t))
9977 (vhdl-insert-keyword " WHEN ")
9978 (if (setq choices (vhdl-template-field "[choices]" "," t))
9979 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9980 (vhdl-insert-keyword "OTHERS")))
9981 (when choices
9982 (fixup-whitespace)
9983 (delete-char -2))
9984 (insert ";")
9985 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9987 (defun vhdl-template-signal ()
9988 "Insert a signal declaration."
9989 (interactive)
9990 (let ((start (point))
9991 (in-arglist (vhdl-in-argument-list-p)))
9992 (vhdl-insert-keyword "SIGNAL ")
9993 (when (vhdl-template-field "names" nil t start (point))
9994 (insert " : ")
9995 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9996 (vhdl-template-field "type")
9997 (if in-arglist
9998 (progn (insert ";")
9999 (vhdl-comment-insert-inline))
10000 (let ((position (point)))
10001 (insert " := ")
10002 (unless (vhdl-template-field "[initialization]" nil t)
10003 (delete-region position (point)))
10004 (insert ";")
10005 (vhdl-comment-insert-inline))))))
10007 (defun vhdl-template-subnature ()
10008 "Insert a subnature declaration."
10009 (interactive)
10010 (let ((start (point))
10011 position)
10012 (vhdl-insert-keyword "SUBNATURE ")
10013 (when (vhdl-template-field "name" nil t start (point))
10014 (vhdl-insert-keyword " IS ")
10015 (vhdl-template-field "nature" " (")
10016 (if (vhdl-template-field "[index range]" nil t)
10017 (insert ")")
10018 (delete-char -2))
10019 (setq position (point))
10020 (vhdl-insert-keyword " TOLERANCE ")
10021 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10022 nil t nil nil t))
10023 (delete-region position (point))
10024 (vhdl-insert-keyword " ACROSS ")
10025 (vhdl-template-field "string expression" nil nil nil nil t)
10026 (vhdl-insert-keyword " THROUGH"))
10027 (insert ";")
10028 (vhdl-comment-insert-inline))))
10030 (defun vhdl-template-subprogram-body ()
10031 "Insert a subprogram body."
10032 (interactive)
10033 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10034 (vhdl-template-function-body)
10035 (vhdl-template-procedure-body)))
10037 (defun vhdl-template-subprogram-decl ()
10038 "Insert a subprogram declaration."
10039 (interactive)
10040 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10041 (vhdl-template-function-decl)
10042 (vhdl-template-procedure-decl)))
10044 (defun vhdl-template-subtype ()
10045 "Insert a subtype declaration."
10046 (interactive)
10047 (let ((start (point)))
10048 (vhdl-insert-keyword "SUBTYPE ")
10049 (when (vhdl-template-field "name" nil t start (point))
10050 (vhdl-insert-keyword " IS ")
10051 (vhdl-template-field "type" " ")
10052 (unless
10053 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
10054 (delete-char -1))
10055 (insert ";")
10056 (vhdl-comment-insert-inline))))
10058 (defun vhdl-template-terminal ()
10059 "Insert a terminal declaration."
10060 (interactive)
10061 (let ((start (point)))
10062 (vhdl-insert-keyword "TERMINAL ")
10063 (when (vhdl-template-field "names" nil t start (point))
10064 (insert " : ")
10065 (vhdl-template-field "nature")
10066 (insert ";")
10067 (vhdl-comment-insert-inline))))
10069 (defun vhdl-template-type ()
10070 "Insert a type declaration."
10071 (interactive)
10072 (let ((start (point))
10073 name mid-pos end-pos)
10074 (vhdl-insert-keyword "TYPE ")
10075 (when (setq name (vhdl-template-field "name" nil t start (point)))
10076 (vhdl-insert-keyword " IS ")
10077 (let ((definition
10078 (upcase
10079 (or (vhdl-template-field
10080 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
10081 ""))))
10082 (cond ((equal definition "")
10083 (delete-char -4)
10084 (insert ";"))
10085 ((equal definition "ARRAY")
10086 (delete-region (point) (progn (forward-word -1) (point)))
10087 (vhdl-template-array 'type t))
10088 ((equal definition "RECORD")
10089 (setq mid-pos (point-marker))
10090 (delete-region (point) (progn (forward-word -1) (point)))
10091 (vhdl-template-record 'type name t))
10092 ((equal definition "ACCESS")
10093 (insert " ")
10094 (vhdl-template-field "type" ";"))
10095 ((equal definition "FILE")
10096 (vhdl-insert-keyword " OF ")
10097 (vhdl-template-field "type" ";"))
10098 ((equal definition "ENUM")
10099 (kill-word -1)
10100 (insert "(")
10101 (setq end-pos (point-marker))
10102 (insert ");"))
10103 (t (insert ";")))
10104 (when mid-pos
10105 (setq end-pos (point-marker))
10106 (goto-char mid-pos)
10107 (end-of-line))
10108 (vhdl-comment-insert-inline)
10109 (when end-pos (goto-char end-pos))))))
10111 (defun vhdl-template-use ()
10112 "Insert a use clause."
10113 (interactive)
10114 (let ((start (point)))
10115 (vhdl-prepare-search-1
10116 (vhdl-insert-keyword "USE ")
10117 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10118 (vhdl-insert-keyword "..ALL;")
10119 (backward-char 6)
10120 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
10121 (forward-char 1)
10122 (vhdl-template-field "package name")
10123 (forward-char 5))))))
10125 (defun vhdl-template-variable ()
10126 "Insert a variable declaration."
10127 (interactive)
10128 (let ((start (point))
10129 (in-arglist (vhdl-in-argument-list-p)))
10130 (vhdl-prepare-search-2
10131 (if (or (save-excursion
10132 (progn (vhdl-beginning-of-block)
10133 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10134 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
10135 (vhdl-insert-keyword "VARIABLE ")
10136 (if (vhdl-standard-p '87)
10137 (error "ERROR: Not within sequential block")
10138 (vhdl-insert-keyword "SHARED VARIABLE "))))
10139 (when (vhdl-template-field "names" nil t start (point))
10140 (insert " : ")
10141 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10142 (vhdl-template-field "type")
10143 (if in-arglist
10144 (progn (insert ";")
10145 (vhdl-comment-insert-inline))
10146 (let ((position (point)))
10147 (insert " := ")
10148 (unless (vhdl-template-field "[initialization]" nil t)
10149 (delete-region position (point)))
10150 (insert ";")
10151 (vhdl-comment-insert-inline))))))
10153 (defun vhdl-template-wait ()
10154 "Insert a wait statement."
10155 (interactive)
10156 (vhdl-insert-keyword "WAIT ")
10157 (unless (vhdl-template-field
10158 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10159 nil t)
10160 (delete-char -1))
10161 (insert ";"))
10163 (defun vhdl-template-when ()
10164 "Indent correctly if within a case statement."
10165 (interactive)
10166 (let ((position (point))
10167 margin)
10168 (vhdl-prepare-search-2
10169 (if (and (= (current-column) (current-indentation))
10170 (vhdl-re-search-forward "\\<end\\>" nil t)
10171 (looking-at "\\s-*\\<case\\>"))
10172 (progn
10173 (setq margin (current-indentation))
10174 (goto-char position)
10175 (delete-horizontal-space)
10176 (indent-to (+ margin vhdl-basic-offset)))
10177 (goto-char position)))
10178 (vhdl-insert-keyword "WHEN ")))
10180 (defun vhdl-template-while-loop ()
10181 "Insert a while loop."
10182 (interactive)
10183 (let* ((margin (current-indentation))
10184 (start (point))
10185 label)
10186 (if (not (eq vhdl-optional-labels 'all))
10187 (vhdl-insert-keyword "WHILE ")
10188 (vhdl-insert-keyword ": WHILE ")
10189 (goto-char start)
10190 (setq label (vhdl-template-field "[label]" nil t))
10191 (unless label (delete-char 2))
10192 (forward-word 1)
10193 (forward-char 1))
10194 (when vhdl-conditions-in-parenthesis (insert "("))
10195 (when (vhdl-template-field "condition" nil t start (point))
10196 (when vhdl-conditions-in-parenthesis (insert ")"))
10197 (vhdl-insert-keyword " LOOP\n\n")
10198 (indent-to margin)
10199 (vhdl-insert-keyword "END LOOP")
10200 (insert (if label (concat " " label ";") ";"))
10201 (forward-line -1)
10202 (indent-to (+ margin vhdl-basic-offset)))))
10204 (defun vhdl-template-with ()
10205 "Insert a with statement (i.e. selected signal assignment)."
10206 (interactive)
10207 (vhdl-prepare-search-1
10208 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10209 (equal ";" (match-string 1)))
10210 (vhdl-template-selected-signal-asst)
10211 (vhdl-insert-keyword "WITH "))))
10213 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10214 ;; Special templates
10216 (defun vhdl-template-clocked-wait ()
10217 "Insert a wait statement for rising/falling clock edge."
10218 (interactive)
10219 (let ((start (point))
10220 clock)
10221 (vhdl-insert-keyword "WAIT UNTIL ")
10222 (when (setq clock
10223 (or (and (not (equal "" vhdl-clock-name))
10224 (progn (insert vhdl-clock-name) vhdl-clock-name))
10225 (vhdl-template-field "clock name" nil t start (point))))
10226 (insert "'event")
10227 (vhdl-insert-keyword " AND ")
10228 (insert clock)
10229 (insert
10230 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10231 (vhdl-comment-insert-inline
10232 (concat (if vhdl-clock-rising-edge "rising" "falling")
10233 " clock edge")))))
10235 (defun vhdl-template-seq-process (clock reset reset-kind)
10236 "Insert a template for the body of a sequential process."
10237 (let ((margin (current-indentation))
10238 position)
10239 (vhdl-insert-keyword "IF ")
10240 (when vhdl-conditions-in-parenthesis (insert "("))
10241 (when (eq reset-kind 'async)
10242 (insert reset " = "
10243 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10244 (when vhdl-conditions-in-parenthesis (insert ")"))
10245 (vhdl-insert-keyword " THEN")
10246 (vhdl-comment-insert-inline
10247 (concat "asynchronous reset (active "
10248 (if vhdl-reset-active-high "high" "low") ")"))
10249 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10250 (setq position (point))
10251 (insert "\n") (indent-to margin)
10252 (vhdl-insert-keyword "ELSIF ")
10253 (when vhdl-conditions-in-parenthesis (insert "(")))
10254 (if (eq vhdl-clock-edge-condition 'function)
10255 (insert (if vhdl-clock-rising-edge "rising" "falling")
10256 "_edge(" clock ")")
10257 (insert clock "'event")
10258 (vhdl-insert-keyword " AND ")
10259 (insert clock " = "
10260 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10261 (when vhdl-conditions-in-parenthesis (insert ")"))
10262 (vhdl-insert-keyword " THEN")
10263 (vhdl-comment-insert-inline
10264 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10265 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10266 (when (eq reset-kind 'sync)
10267 (vhdl-insert-keyword "IF ")
10268 (when vhdl-conditions-in-parenthesis (insert "("))
10269 (setq reset (or (and (not (equal "" vhdl-reset-name))
10270 (progn (insert vhdl-reset-name) vhdl-reset-name))
10271 (vhdl-template-field "reset name") "<reset>"))
10272 (insert " = "
10273 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10274 (when vhdl-conditions-in-parenthesis (insert ")"))
10275 (vhdl-insert-keyword " THEN")
10276 (vhdl-comment-insert-inline
10277 (concat "synchronous reset (active "
10278 (if vhdl-reset-active-high "high" "low") ")"))
10279 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10280 (setq position (point))
10281 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10282 (vhdl-insert-keyword "ELSE")
10283 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10284 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10285 (vhdl-insert-keyword "END IF;"))
10286 (when (eq reset-kind 'none)
10287 (setq position (point)))
10288 (insert "\n") (indent-to margin)
10289 (vhdl-insert-keyword "END IF;")
10290 (goto-char position)
10291 reset))
10293 (defun vhdl-template-standard-package (library package)
10294 "Insert specification of a standard package. Include a library
10295 specification, if not already there."
10296 (let ((margin (current-indentation)))
10297 (unless (equal library "std")
10298 (unless (or (save-excursion
10299 (vhdl-prepare-search-1
10300 (and (not (bobp))
10301 (re-search-backward
10302 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10303 library "\\|end\\)\\>") nil t)
10304 (match-string 2))))
10305 (equal (downcase library) "work"))
10306 (vhdl-insert-keyword "LIBRARY ")
10307 (insert library ";")
10308 (when package
10309 (insert "\n")
10310 (indent-to margin))))
10311 (when package
10312 (vhdl-insert-keyword "USE ")
10313 (insert library "." package)
10314 (vhdl-insert-keyword ".ALL;"))))
10316 (defun vhdl-template-package-numeric-bit ()
10317 "Insert specification of `numeric_bit' package."
10318 (interactive)
10319 (vhdl-template-standard-package "ieee" "numeric_bit"))
10321 (defun vhdl-template-package-numeric-std ()
10322 "Insert specification of `numeric_std' package."
10323 (interactive)
10324 (vhdl-template-standard-package "ieee" "numeric_std"))
10326 (defun vhdl-template-package-std-logic-1164 ()
10327 "Insert specification of `std_logic_1164' package."
10328 (interactive)
10329 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10331 (defun vhdl-template-package-std-logic-arith ()
10332 "Insert specification of `std_logic_arith' package."
10333 (interactive)
10334 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10336 (defun vhdl-template-package-std-logic-misc ()
10337 "Insert specification of `std_logic_misc' package."
10338 (interactive)
10339 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10341 (defun vhdl-template-package-std-logic-signed ()
10342 "Insert specification of `std_logic_signed' package."
10343 (interactive)
10344 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10346 (defun vhdl-template-package-std-logic-textio ()
10347 "Insert specification of `std_logic_textio' package."
10348 (interactive)
10349 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10351 (defun vhdl-template-package-std-logic-unsigned ()
10352 "Insert specification of `std_logic_unsigned' package."
10353 (interactive)
10354 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10356 (defun vhdl-template-package-textio ()
10357 "Insert specification of `textio' package."
10358 (interactive)
10359 (vhdl-template-standard-package "std" "textio"))
10361 (defun vhdl-template-package-fundamental-constants ()
10362 "Insert specification of `fundamental_constants' package."
10363 (interactive)
10364 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10366 (defun vhdl-template-package-material-constants ()
10367 "Insert specification of `material_constants' package."
10368 (interactive)
10369 (vhdl-template-standard-package "ieee" "material_constants"))
10371 (defun vhdl-template-package-energy-systems ()
10372 "Insert specification of `energy_systems' package."
10373 (interactive)
10374 (vhdl-template-standard-package "ieee" "energy_systems"))
10376 (defun vhdl-template-package-electrical-systems ()
10377 "Insert specification of `electrical_systems' package."
10378 (interactive)
10379 (vhdl-template-standard-package "ieee" "electrical_systems"))
10381 (defun vhdl-template-package-mechanical-systems ()
10382 "Insert specification of `mechanical_systems' package."
10383 (interactive)
10384 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10386 (defun vhdl-template-package-radiant-systems ()
10387 "Insert specification of `radiant_systems' package."
10388 (interactive)
10389 (vhdl-template-standard-package "ieee" "radiant_systems"))
10391 (defun vhdl-template-package-thermal-systems ()
10392 "Insert specification of `thermal_systems' package."
10393 (interactive)
10394 (vhdl-template-standard-package "ieee" "thermal_systems"))
10396 (defun vhdl-template-package-fluidic-systems ()
10397 "Insert specification of `fluidic_systems' package."
10398 (interactive)
10399 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10401 (defun vhdl-template-package-math-complex ()
10402 "Insert specification of `math_complex' package."
10403 (interactive)
10404 (vhdl-template-standard-package "ieee" "math_complex"))
10406 (defun vhdl-template-package-math-real ()
10407 "Insert specification of `math_real' package."
10408 (interactive)
10409 (vhdl-template-standard-package "ieee" "math_real"))
10411 (defun vhdl-template-directive (directive)
10412 "Insert directive."
10413 (unless (= (current-indentation) (current-column))
10414 (delete-horizontal-space)
10415 (insert " "))
10416 (insert "-- pragma " directive))
10418 (defun vhdl-template-directive-translate-on ()
10419 "Insert directive 'translate_on'."
10420 (interactive)
10421 (vhdl-template-directive "translate_on"))
10423 (defun vhdl-template-directive-translate-off ()
10424 "Insert directive 'translate_off'."
10425 (interactive)
10426 (vhdl-template-directive "translate_off"))
10428 (defun vhdl-template-directive-synthesis-on ()
10429 "Insert directive 'synthesis_on'."
10430 (interactive)
10431 (vhdl-template-directive "synthesis_on"))
10433 (defun vhdl-template-directive-synthesis-off ()
10434 "Insert directive 'synthesis_off'."
10435 (interactive)
10436 (vhdl-template-directive "synthesis_off"))
10438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10439 ;; Header and footer templates
10441 (defun vhdl-template-header (&optional file-title)
10442 "Insert a VHDL file header."
10443 (interactive)
10444 (unless (equal vhdl-file-header "")
10445 (let (pos)
10446 (save-excursion
10447 (goto-char (point-min))
10448 (vhdl-insert-string-or-file vhdl-file-header)
10449 (setq pos (point-marker)))
10450 (vhdl-template-replace-header-keywords
10451 (point-min-marker) pos file-title))))
10453 (defun vhdl-template-footer ()
10454 "Insert a VHDL file footer."
10455 (interactive)
10456 (unless (equal vhdl-file-footer "")
10457 (let (pos)
10458 (save-excursion
10459 (goto-char (point-max))
10460 (setq pos (point-marker))
10461 (vhdl-insert-string-or-file vhdl-file-footer)
10462 (unless (= (preceding-char) ?\n)
10463 (insert "\n")))
10464 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10466 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10467 is-model)
10468 "Replace keywords in header and footer."
10469 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
10470 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
10471 pos)
10472 (vhdl-prepare-search-2
10473 (save-excursion
10474 (goto-char beg)
10475 (while (search-forward "<projectdesc>" end t)
10476 (replace-match project-desc t t))
10477 (goto-char beg)
10478 (while (search-forward "<filename>" end t)
10479 (replace-match (buffer-name) t t))
10480 (goto-char beg)
10481 (while (search-forward "<copyright>" end t)
10482 (replace-match vhdl-copyright-string t t))
10483 (goto-char beg)
10484 (while (search-forward "<author>" end t)
10485 (replace-match "" t t)
10486 (insert (user-full-name))
10487 (when user-mail-address (insert " <" user-mail-address ">")))
10488 (goto-char beg)
10489 (while (search-forward "<authorfull>" end t)
10490 (replace-match (user-full-name) t t))
10491 (goto-char beg)
10492 (while (search-forward "<login>" end t)
10493 (replace-match (user-login-name) t t))
10494 (goto-char beg)
10495 (while (search-forward "<project>" end t)
10496 (replace-match project-title t t))
10497 (goto-char beg)
10498 (while (search-forward "<company>" end t)
10499 (replace-match vhdl-company-name t t))
10500 (goto-char beg)
10501 (while (search-forward "<platform>" end t)
10502 (replace-match vhdl-platform-spec t t))
10503 (goto-char beg)
10504 (while (search-forward "<standard>" end t)
10505 (replace-match
10506 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10507 ((vhdl-standard-p '93) "'93/02"))
10508 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10509 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10510 (goto-char beg)
10511 ;; Replace <RCS> with $, so that RCS for the source is
10512 ;; not over-enthusiastic with replacements
10513 (while (search-forward "<RCS>" end t)
10514 (replace-match "$" nil t))
10515 (goto-char beg)
10516 (while (search-forward "<date>" end t)
10517 (replace-match "" t t)
10518 (vhdl-template-insert-date))
10519 (goto-char beg)
10520 (while (search-forward "<year>" end t)
10521 (replace-match (format-time-string "%Y" nil) t t))
10522 (goto-char beg)
10523 (when file-title
10524 (while (search-forward "<title string>" end t)
10525 (replace-match file-title t t))
10526 (goto-char beg))
10527 (let (string)
10528 (while
10529 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10530 (setq string (read-string (concat (match-string 1) ": ")))
10531 (replace-match string t t)))
10532 (goto-char beg)
10533 (when (and (not is-model) (search-forward "<cursor>" end t))
10534 (replace-match "" t t)
10535 (setq pos (point))))
10536 (when pos (goto-char pos))
10537 (unless is-model
10538 (when (or (not project-title) (equal project-title ""))
10539 (message "You can specify a project title in user option `vhdl-project-alist'"))
10540 (when (or (not project-desc) (equal project-desc ""))
10541 (message "You can specify a project description in user option `vhdl-project-alist'"))
10542 (when (equal vhdl-platform-spec "")
10543 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10544 (when (equal vhdl-company-name "")
10545 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10547 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10548 ;; Comment templates and functions
10550 (defun vhdl-comment-indent ()
10551 "Indent comments."
10552 (let* ((position (point))
10553 (col
10554 (progn
10555 (forward-line -1)
10556 (if (re-search-forward "--" position t)
10557 (- (current-column) 2) ; existing comment at bol stays there
10558 (goto-char position)
10559 (skip-chars-backward " \t")
10560 (max comment-column ; else indent to comment column
10561 (1+ (current-column))))))) ; except leave at least one space
10562 (goto-char position)
10563 col))
10565 (defun vhdl-comment-insert ()
10566 "Start a comment at the end of the line.
10567 If on line with code, indent at least `comment-column'.
10568 If starting after end-comment-column, start a new line."
10569 (interactive)
10570 (when (> (current-column) end-comment-column) (newline-and-indent))
10571 (if (or (looking-at "\\s-*$") ; end of line
10572 (and (not unread-command-events) ; called with key binding or menu
10573 (not (end-of-line))))
10574 (let (margin)
10575 (while (= (preceding-char) ?-) (delete-char -1))
10576 (setq margin (current-column))
10577 (delete-horizontal-space)
10578 (if (bolp)
10579 (progn (indent-to margin) (insert "--"))
10580 (insert " ")
10581 (indent-to comment-column)
10582 (insert "--"))
10583 (if (not unread-command-events) (insert " ")))
10584 ;; else code following current point implies commenting out code
10585 (let (next-input code)
10586 (while (= (preceding-char) ?-) (delete-char -2))
10587 (while (= (setq next-input (read-char)) 13) ; CR
10588 (insert "--") ; or have a space after it?
10589 (forward-char -2)
10590 (forward-line 1)
10591 (message "Enter CR if commenting out a line of code.")
10592 (setq code t))
10593 (unless code
10594 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10595 (setq unread-command-events
10596 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10598 (defun vhdl-comment-display (&optional line-exists)
10599 "Add 2 comment lines at the current indent, making a display comment."
10600 (interactive)
10601 (let ((margin (current-indentation)))
10602 (unless line-exists (vhdl-comment-display-line))
10603 (insert "\n") (indent-to margin)
10604 (insert "\n") (indent-to margin)
10605 (vhdl-comment-display-line)
10606 (end-of-line -0)
10607 (insert "-- ")))
10609 (defun vhdl-comment-display-line ()
10610 "Displays one line of dashes."
10611 (interactive)
10612 (while (= (preceding-char) ?-) (delete-char -2))
10613 (insert "--")
10614 (let* ((col (current-column))
10615 (len (- end-comment-column col)))
10616 (insert-char vhdl-comment-display-line-char len)))
10618 (defun vhdl-comment-append-inline ()
10619 "Append empty inline comment to current line."
10620 (interactive)
10621 (end-of-line)
10622 (delete-horizontal-space)
10623 (insert " ")
10624 (indent-to comment-column)
10625 (insert "-- "))
10627 (defun vhdl-comment-insert-inline (&optional string always-insert)
10628 "Insert inline comment."
10629 (when (or (and string (or vhdl-self-insert-comments always-insert))
10630 (and (not string) vhdl-prompt-for-comments))
10631 (let ((position (point)))
10632 (insert " ")
10633 (indent-to comment-column)
10634 (insert "-- ")
10635 (if (not (or (and string (progn (insert string) t))
10636 (vhdl-template-field "[comment]" nil t)))
10637 (delete-region position (point))
10638 (while (= (preceding-char) ?\ ) (delete-char -1))
10639 ;; (when (> (current-column) end-comment-column)
10640 ;; (setq position (point-marker))
10641 ;; (re-search-backward "-- ")
10642 ;; (insert "\n")
10643 ;; (indent-to comment-column)
10644 ;; (goto-char position))
10645 ))))
10647 (defun vhdl-comment-block ()
10648 "Insert comment for code block."
10649 (when vhdl-prompt-for-comments
10650 (let ((final-pos (point-marker)))
10651 (vhdl-prepare-search-2
10652 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10653 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10654 (let (margin)
10655 (back-to-indentation)
10656 (setq margin (current-column))
10657 (end-of-line -0)
10658 (if (bobp)
10659 (progn (insert "\n") (forward-line -1))
10660 (insert "\n"))
10661 (indent-to margin)
10662 (insert "-- purpose: ")
10663 (unless (vhdl-template-field "[description]" nil t)
10664 (vhdl-line-kill-entire)))))
10665 (goto-char final-pos))))
10667 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10668 "Comment out region if not commented out, uncomment otherwise."
10669 (interactive "r\nP")
10670 (save-excursion
10671 (goto-char (1- end))
10672 (end-of-line)
10673 (setq end (point-marker))
10674 (goto-char beg)
10675 (beginning-of-line)
10676 (setq beg (point))
10677 (if (looking-at (concat "\\s-*" comment-start))
10678 (comment-region beg end '(4))
10679 (comment-region beg end))))
10681 (defun vhdl-comment-uncomment-line (&optional arg)
10682 "Comment out line if not commented out, uncomment otherwise."
10683 (interactive "p")
10684 (save-excursion
10685 (beginning-of-line)
10686 (let ((position (point)))
10687 (forward-line (or arg 1))
10688 (vhdl-comment-uncomment-region position (point)))))
10690 (defun vhdl-comment-kill-region (beg end)
10691 "Kill comments in region."
10692 (interactive "r")
10693 (save-excursion
10694 (goto-char end)
10695 (setq end (point-marker))
10696 (goto-char beg)
10697 (beginning-of-line)
10698 (while (< (point) end)
10699 (if (looking-at "^\\(\\s-*--.*\n\\)")
10700 (progn (delete-region (match-beginning 1) (match-end 1)))
10701 (beginning-of-line 2)))))
10703 (defun vhdl-comment-kill-inline-region (beg end)
10704 "Kill inline comments in region."
10705 (interactive "r")
10706 (save-excursion
10707 (goto-char end)
10708 (setq end (point-marker))
10709 (goto-char beg)
10710 (beginning-of-line)
10711 (while (< (point) end)
10712 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10713 (delete-region (match-beginning 1) (match-end 1)))
10714 (beginning-of-line 2))))
10716 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10717 ;; Subtemplates
10719 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10720 "Insert a begin ... end pair with optional name after the end.
10721 Point is left between them."
10722 (let (position)
10723 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10724 (indent-to margin)
10725 (vhdl-insert-keyword "BEGIN")
10726 (when (and (or construct name) vhdl-self-insert-comments)
10727 (insert " --")
10728 (when construct (insert " ") (vhdl-insert-keyword construct))
10729 (when name (insert " " name)))
10730 (insert "\n")
10731 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10732 (indent-to (+ margin vhdl-basic-offset))
10733 (setq position (point))
10734 (insert "\n")
10735 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10736 (indent-to margin)
10737 (vhdl-insert-keyword "END")
10738 (when construct (insert " ") (vhdl-insert-keyword construct))
10739 (insert (if name (concat " " name) "") ";")
10740 (goto-char position)))
10742 (defun vhdl-template-argument-list (&optional is-function)
10743 "Read from user a procedure or function argument list."
10744 (insert " (")
10745 (let ((margin (current-column))
10746 (start (point))
10747 (end-pos (point))
10748 not-empty interface semicolon-pos)
10749 (unless vhdl-argument-list-indent
10750 (setq margin (+ (current-indentation) vhdl-basic-offset))
10751 (insert "\n")
10752 (indent-to margin))
10753 (setq interface (vhdl-template-field
10754 (concat "[CONSTANT | SIGNAL"
10755 (unless is-function " | VARIABLE") "]") " " t))
10756 (while (vhdl-template-field "[names]" nil t)
10757 (setq not-empty t)
10758 (insert " : ")
10759 (unless is-function
10760 (if (and interface (equal (upcase interface) "CONSTANT"))
10761 (vhdl-insert-keyword "IN ")
10762 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10763 (vhdl-template-field "type")
10764 (setq semicolon-pos (point))
10765 (insert ";")
10766 (vhdl-comment-insert-inline)
10767 (setq end-pos (point))
10768 (insert "\n")
10769 (indent-to margin)
10770 (setq interface (vhdl-template-field
10771 (concat "[CONSTANT | SIGNAL"
10772 (unless is-function " | VARIABLE") "]") " " t)))
10773 (delete-region end-pos (point))
10774 (when semicolon-pos (goto-char semicolon-pos))
10775 (if not-empty
10776 (progn (delete-char 1) (insert ")"))
10777 (delete-char -2))))
10779 (defun vhdl-template-generic-list (optional &optional no-value)
10780 "Read from user a generic spec argument list."
10781 (let (margin
10782 (start (point)))
10783 (vhdl-insert-keyword "GENERIC (")
10784 (setq margin (current-column))
10785 (unless vhdl-argument-list-indent
10786 (let ((position (point)))
10787 (back-to-indentation)
10788 (setq margin (+ (current-column) vhdl-basic-offset))
10789 (goto-char position)
10790 (insert "\n")
10791 (indent-to margin)))
10792 (let ((vhdl-generics (vhdl-template-field
10793 (concat (and optional "[") "name"
10794 (and no-value "s") (and optional "]"))
10795 nil optional)))
10796 (if (not vhdl-generics)
10797 (if optional
10798 (progn (vhdl-line-kill-entire) (end-of-line -0)
10799 (unless vhdl-argument-list-indent
10800 (vhdl-line-kill-entire) (end-of-line -0)))
10801 (vhdl-template-undo start (point))
10802 nil )
10803 (insert " : ")
10804 (let (semicolon-pos end-pos)
10805 (while vhdl-generics
10806 (vhdl-template-field "type")
10807 (if no-value
10808 (progn (setq semicolon-pos (point))
10809 (insert ";"))
10810 (insert " := ")
10811 (unless (vhdl-template-field "[value]" nil t)
10812 (delete-char -4))
10813 (setq semicolon-pos (point))
10814 (insert ";"))
10815 (vhdl-comment-insert-inline)
10816 (setq end-pos (point))
10817 (insert "\n")
10818 (indent-to margin)
10819 (setq vhdl-generics (vhdl-template-field
10820 (concat "[name" (and no-value "s") "]")
10821 " : " t)))
10822 (delete-region end-pos (point))
10823 (goto-char semicolon-pos)
10824 (insert ")")
10825 (end-of-line)
10826 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10827 t)))))
10829 (defun vhdl-template-port-list (optional)
10830 "Read from user a port spec argument list."
10831 (let ((start (point))
10832 margin vhdl-ports object)
10833 (vhdl-insert-keyword "PORT (")
10834 (setq margin (current-column))
10835 (unless vhdl-argument-list-indent
10836 (let ((position (point)))
10837 (back-to-indentation)
10838 (setq margin (+ (current-column) vhdl-basic-offset))
10839 (goto-char position)
10840 (insert "\n")
10841 (indent-to margin)))
10842 (when (vhdl-standard-p 'ams)
10843 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10844 " " t)))
10845 (setq vhdl-ports (vhdl-template-field
10846 (concat (and optional "[") "names" (and optional "]"))
10847 nil optional))
10848 (if (not vhdl-ports)
10849 (if optional
10850 (progn (vhdl-line-kill-entire) (end-of-line -0)
10851 (unless vhdl-argument-list-indent
10852 (vhdl-line-kill-entire) (end-of-line -0)))
10853 (vhdl-template-undo start (point))
10854 nil)
10855 (insert " : ")
10856 (let (semicolon-pos end-pos)
10857 (while vhdl-ports
10858 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10859 (vhdl-template-field "IN | OUT | INOUT" " "))
10860 ((equal "QUANTITY" (upcase object))
10861 (vhdl-template-field "[IN | OUT]" " " t)))
10862 (vhdl-template-field
10863 (if (and object (equal "TERMINAL" (upcase object)))
10864 "nature" "type"))
10865 (setq semicolon-pos (point))
10866 (insert ";")
10867 (vhdl-comment-insert-inline)
10868 (setq end-pos (point))
10869 (insert "\n")
10870 (indent-to margin)
10871 (when (vhdl-standard-p 'ams)
10872 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10873 " " t)))
10874 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10875 (delete-region end-pos (point))
10876 (goto-char semicolon-pos)
10877 (insert ")")
10878 (end-of-line)
10879 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10880 t))))
10882 (defun vhdl-template-generate-body (margin label)
10883 "Insert body for generate template."
10884 (vhdl-insert-keyword " GENERATE")
10885 ; (if (not (vhdl-standard-p '87))
10886 ; (vhdl-template-begin-end "GENERATE" label margin)
10887 (insert "\n\n")
10888 (indent-to margin)
10889 (vhdl-insert-keyword "END GENERATE ")
10890 (insert label ";")
10891 (end-of-line 0)
10892 (indent-to (+ margin vhdl-basic-offset)))
10894 (defun vhdl-template-insert-date ()
10895 "Insert date in appropriate format."
10896 (interactive)
10897 (insert
10898 (cond
10899 ;; 'american, 'european, 'scientific kept for backward compatibility
10900 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10901 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10902 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10903 (t (format-time-string vhdl-date-format nil)))))
10905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10906 ;; Help functions
10908 (defun vhdl-electric-space (count)
10909 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10910 if in comment and past end-comment-column."
10911 (interactive "p")
10912 (cond ((vhdl-in-comment-p)
10913 (self-insert-command count)
10914 (cond ((>= (current-column) (+ 2 end-comment-column))
10915 (backward-char 1)
10916 (skip-chars-backward "^ \t\n\r\f")
10917 (indent-new-comment-line)
10918 (skip-chars-forward "^ \t\n\r\f")
10919 (forward-char 1))
10920 ((>= (current-column) end-comment-column)
10921 (indent-new-comment-line))
10922 (t nil)))
10923 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10924 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10925 (vhdl-prepare-search-1
10926 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10927 (self-insert-command count))
10928 (t (self-insert-command count))))
10930 (defun vhdl-template-field (prompt &optional follow-string optional
10931 begin end is-string default)
10932 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10933 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10934 an empty string is inserted, return nil and call `vhdl-template-undo' for
10935 the region between BEGIN and END. IS-STRING indicates whether a string
10936 with double-quotes is to be inserted. DEFAULT specifies a default string."
10937 (let ((position (point))
10938 string)
10939 (insert "<" prompt ">")
10940 (setq string
10941 (condition-case ()
10942 (read-from-minibuffer (concat prompt ": ")
10943 (or (and is-string '("\"\"" . 2)) default)
10944 vhdl-minibuffer-local-map)
10945 (quit (if (and optional begin end)
10946 (progn (beep) "")
10947 (keyboard-quit)))))
10948 (when (or (not (equal string "")) optional)
10949 (delete-region position (point)))
10950 (when (and (equal string "") optional begin end)
10951 (vhdl-template-undo begin end)
10952 (message "Template aborted"))
10953 (unless (equal string "")
10954 (insert string)
10955 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10956 vhdl-keywords-regexp)
10957 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10958 vhdl-types-regexp)
10959 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10960 (concat "'" vhdl-attributes-regexp))
10961 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10962 vhdl-enum-values-regexp)
10963 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
10964 vhdl-constants-regexp))
10965 (when (or (not (equal string "")) (not optional))
10966 (insert (or follow-string "")))
10967 (if (equal string "") nil string)))
10969 (defun vhdl-decision-query (string prompt &optional optional)
10970 "Query a decision from the user."
10971 (let ((start (point)))
10972 (when string (vhdl-insert-keyword (concat string " ")))
10973 (message "%s" (or prompt ""))
10974 (let ((char (read-char)))
10975 (delete-region start (point))
10976 (if (and optional (eq char ?\r))
10977 (progn (insert " ")
10978 (unexpand-abbrev)
10979 (throw 'abort "ERROR: Template aborted"))
10980 char))))
10982 (defun vhdl-insert-keyword (keyword)
10983 "Insert KEYWORD and adjust case."
10984 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10986 (defun vhdl-case-keyword (keyword)
10987 "Adjust case of KEYWORD."
10988 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10990 (defun vhdl-case-word (num)
10991 "Adjust case of following NUM words."
10992 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10994 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10995 "If preceding character is part of a word or a paren then hippie-expand,
10996 else insert tab (used for word completion in VHDL minibuffer)."
10997 (interactive "P")
10998 (cond
10999 ;; expand word
11000 ((= (char-syntax (preceding-char)) ?w)
11001 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11002 (case-replace nil)
11003 (hippie-expand-only-buffers
11004 (or (and (boundp 'hippie-expand-only-buffers)
11005 hippie-expand-only-buffers)
11006 '(vhdl-mode))))
11007 (vhdl-expand-abbrev prefix-arg)))
11008 ;; expand parenthesis
11009 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
11010 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11011 (case-replace nil))
11012 (vhdl-expand-paren prefix-arg)))
11013 ;; insert tab
11014 (t (insert-tab))))
11016 (defun vhdl-template-search-prompt ()
11017 "Search for left out template prompts and query again."
11018 (interactive)
11019 (vhdl-prepare-search-2
11020 (when (or (re-search-forward
11021 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
11022 (re-search-backward
11023 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
11024 (let ((string (match-string 1)))
11025 (replace-match "")
11026 (vhdl-template-field string)))))
11028 (defun vhdl-template-undo (begin end)
11029 "Undo aborted template by deleting region and unexpanding the keyword."
11030 (cond (vhdl-template-invoked-by-hook
11031 (goto-char end)
11032 (insert " ")
11033 (delete-region begin end)
11034 (unexpand-abbrev))
11035 (t (delete-region begin end))))
11037 (defun vhdl-insert-string-or-file (string)
11038 "Insert STRING or file contents if STRING is an existing file name."
11039 (unless (equal string "")
11040 (let ((file-name
11041 (progn (string-match "^\\([^\n]+\\)" string)
11042 (vhdl-resolve-env-variable (match-string 1 string)))))
11043 (if (file-exists-p file-name)
11044 (forward-char (cadr (insert-file-contents file-name)))
11045 (insert string)))))
11047 (defun vhdl-beginning-of-block ()
11048 "Move cursor to the beginning of the enclosing block."
11049 (let (pos)
11050 (vhdl-prepare-search-2
11051 (save-excursion
11052 (beginning-of-line)
11053 ;; search backward for block beginning or end
11054 (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))
11055 ;; not consider subprogram declarations
11056 (or (and (match-string 5)
11057 (save-match-data
11058 (save-excursion
11059 (goto-char (match-end 5))
11060 (forward-word 1)
11061 (vhdl-forward-syntactic-ws)
11062 (when (looking-at "(")
11063 (forward-sexp))
11064 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11065 (match-string 1)))
11066 ;; not consider configuration specifications
11067 (and (match-string 6)
11068 (save-match-data
11069 (save-excursion
11070 (vhdl-end-of-block)
11071 (beginning-of-line)
11072 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11073 (match-string 2))
11074 ;; skip subblock if block end found
11075 (vhdl-beginning-of-block))))
11076 (when pos (goto-char pos))))
11078 (defun vhdl-end-of-block ()
11079 "Move cursor to the end of the enclosing block."
11080 (let (pos)
11081 (vhdl-prepare-search-2
11082 (save-excursion
11083 (end-of-line)
11084 ;; search forward for block beginning or end
11085 (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))
11086 ;; not consider subprogram declarations
11087 (or (and (match-string 5)
11088 (save-match-data
11089 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11090 (match-string 1)))
11091 ;; not consider configuration specifications
11092 (and (match-string 6)
11093 (save-match-data
11094 (save-excursion
11095 (vhdl-end-of-block)
11096 (beginning-of-line)
11097 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11098 (not (match-string 2)))
11099 ;; skip subblock if block beginning found
11100 (vhdl-end-of-block))))
11101 (when pos (goto-char pos))))
11103 (defun vhdl-sequential-statement-p ()
11104 "Check if point is within sequential statement part."
11105 (let ((start (point)))
11106 (save-excursion
11107 (vhdl-prepare-search-2
11108 ;; is sequential statement if ...
11109 (and (re-search-backward "^\\s-*begin\\>" nil t)
11110 ;; ... point is between "begin" and "end" of ...
11111 (progn (vhdl-end-of-block)
11112 (< start (point)))
11113 ;; ... a sequential block
11114 (progn (vhdl-beginning-of-block)
11115 (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\\)\\)\\>")))))))
11117 (defun vhdl-in-argument-list-p ()
11118 "Check if within an argument list."
11119 (save-excursion
11120 (vhdl-prepare-search-2
11121 (or (string-match "arglist"
11122 (format "%s" (caar (vhdl-get-syntactic-context))))
11123 (progn (beginning-of-line)
11124 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11127 ;; Abbrev hooks
11129 (defun vhdl-hooked-abbrev (func)
11130 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11131 but not if inside a comment or quote."
11132 (if (or (vhdl-in-literal)
11133 (save-excursion
11134 (forward-word -1)
11135 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11136 (progn
11137 (insert " ")
11138 (unexpand-abbrev)
11139 (backward-word 1)
11140 (vhdl-case-word 1)
11141 (delete-char 1))
11142 (if (not vhdl-electric-mode)
11143 (progn
11144 (insert " ")
11145 (unexpand-abbrev)
11146 (backward-word 1)
11147 (vhdl-case-word 1)
11148 (delete-char 1))
11149 (let ((invoke-char vhdl-last-input-event)
11150 (abbrev-mode -1)
11151 (vhdl-template-invoked-by-hook t))
11152 (let ((caught (catch 'abort
11153 (funcall func))))
11154 (when (stringp caught) (message "%s" caught)))
11155 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
11156 ;; delete CR which is still in event queue
11157 (if (fboundp 'enqueue-eval-event)
11158 (enqueue-eval-event 'delete-char -1)
11159 (setq unread-command-events ; push back a delete char
11160 (list (vhdl-character-to-event ?\177))))))))
11162 (defun vhdl-template-alias-hook ()
11163 (vhdl-hooked-abbrev 'vhdl-template-alias))
11164 (defun vhdl-template-architecture-hook ()
11165 (vhdl-hooked-abbrev 'vhdl-template-architecture))
11166 (defun vhdl-template-assert-hook ()
11167 (vhdl-hooked-abbrev 'vhdl-template-assert))
11168 (defun vhdl-template-attribute-hook ()
11169 (vhdl-hooked-abbrev 'vhdl-template-attribute))
11170 (defun vhdl-template-block-hook ()
11171 (vhdl-hooked-abbrev 'vhdl-template-block))
11172 (defun vhdl-template-break-hook ()
11173 (vhdl-hooked-abbrev 'vhdl-template-break))
11174 (defun vhdl-template-case-hook ()
11175 (vhdl-hooked-abbrev 'vhdl-template-case))
11176 (defun vhdl-template-component-hook ()
11177 (vhdl-hooked-abbrev 'vhdl-template-component))
11178 (defun vhdl-template-instance-hook ()
11179 (vhdl-hooked-abbrev 'vhdl-template-instance))
11180 (defun vhdl-template-conditional-signal-asst-hook ()
11181 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
11182 (defun vhdl-template-configuration-hook ()
11183 (vhdl-hooked-abbrev 'vhdl-template-configuration))
11184 (defun vhdl-template-constant-hook ()
11185 (vhdl-hooked-abbrev 'vhdl-template-constant))
11186 (defun vhdl-template-disconnect-hook ()
11187 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
11188 (defun vhdl-template-display-comment-hook ()
11189 (vhdl-hooked-abbrev 'vhdl-comment-display))
11190 (defun vhdl-template-else-hook ()
11191 (vhdl-hooked-abbrev 'vhdl-template-else))
11192 (defun vhdl-template-elsif-hook ()
11193 (vhdl-hooked-abbrev 'vhdl-template-elsif))
11194 (defun vhdl-template-entity-hook ()
11195 (vhdl-hooked-abbrev 'vhdl-template-entity))
11196 (defun vhdl-template-exit-hook ()
11197 (vhdl-hooked-abbrev 'vhdl-template-exit))
11198 (defun vhdl-template-file-hook ()
11199 (vhdl-hooked-abbrev 'vhdl-template-file))
11200 (defun vhdl-template-for-hook ()
11201 (vhdl-hooked-abbrev 'vhdl-template-for))
11202 (defun vhdl-template-function-hook ()
11203 (vhdl-hooked-abbrev 'vhdl-template-function))
11204 (defun vhdl-template-generic-hook ()
11205 (vhdl-hooked-abbrev 'vhdl-template-generic))
11206 (defun vhdl-template-group-hook ()
11207 (vhdl-hooked-abbrev 'vhdl-template-group))
11208 (defun vhdl-template-library-hook ()
11209 (vhdl-hooked-abbrev 'vhdl-template-library))
11210 (defun vhdl-template-limit-hook ()
11211 (vhdl-hooked-abbrev 'vhdl-template-limit))
11212 (defun vhdl-template-if-hook ()
11213 (vhdl-hooked-abbrev 'vhdl-template-if))
11214 (defun vhdl-template-bare-loop-hook ()
11215 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
11216 (defun vhdl-template-map-hook ()
11217 (vhdl-hooked-abbrev 'vhdl-template-map))
11218 (defun vhdl-template-nature-hook ()
11219 (vhdl-hooked-abbrev 'vhdl-template-nature))
11220 (defun vhdl-template-next-hook ()
11221 (vhdl-hooked-abbrev 'vhdl-template-next))
11222 (defun vhdl-template-others-hook ()
11223 (vhdl-hooked-abbrev 'vhdl-template-others))
11224 (defun vhdl-template-package-hook ()
11225 (vhdl-hooked-abbrev 'vhdl-template-package))
11226 (defun vhdl-template-port-hook ()
11227 (vhdl-hooked-abbrev 'vhdl-template-port))
11228 (defun vhdl-template-procedural-hook ()
11229 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11230 (defun vhdl-template-procedure-hook ()
11231 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11232 (defun vhdl-template-process-hook ()
11233 (vhdl-hooked-abbrev 'vhdl-template-process))
11234 (defun vhdl-template-quantity-hook ()
11235 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11236 (defun vhdl-template-report-hook ()
11237 (vhdl-hooked-abbrev 'vhdl-template-report))
11238 (defun vhdl-template-return-hook ()
11239 (vhdl-hooked-abbrev 'vhdl-template-return))
11240 (defun vhdl-template-selected-signal-asst-hook ()
11241 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11242 (defun vhdl-template-signal-hook ()
11243 (vhdl-hooked-abbrev 'vhdl-template-signal))
11244 (defun vhdl-template-subnature-hook ()
11245 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11246 (defun vhdl-template-subtype-hook ()
11247 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11248 (defun vhdl-template-terminal-hook ()
11249 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11250 (defun vhdl-template-type-hook ()
11251 (vhdl-hooked-abbrev 'vhdl-template-type))
11252 (defun vhdl-template-use-hook ()
11253 (vhdl-hooked-abbrev 'vhdl-template-use))
11254 (defun vhdl-template-variable-hook ()
11255 (vhdl-hooked-abbrev 'vhdl-template-variable))
11256 (defun vhdl-template-wait-hook ()
11257 (vhdl-hooked-abbrev 'vhdl-template-wait))
11258 (defun vhdl-template-when-hook ()
11259 (vhdl-hooked-abbrev 'vhdl-template-when))
11260 (defun vhdl-template-while-loop-hook ()
11261 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11262 (defun vhdl-template-with-hook ()
11263 (vhdl-hooked-abbrev 'vhdl-template-with))
11264 (defun vhdl-template-and-hook ()
11265 (vhdl-hooked-abbrev 'vhdl-template-and))
11266 (defun vhdl-template-or-hook ()
11267 (vhdl-hooked-abbrev 'vhdl-template-or))
11268 (defun vhdl-template-nand-hook ()
11269 (vhdl-hooked-abbrev 'vhdl-template-nand))
11270 (defun vhdl-template-nor-hook ()
11271 (vhdl-hooked-abbrev 'vhdl-template-nor))
11272 (defun vhdl-template-xor-hook ()
11273 (vhdl-hooked-abbrev 'vhdl-template-xor))
11274 (defun vhdl-template-xnor-hook ()
11275 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11276 (defun vhdl-template-not-hook ()
11277 (vhdl-hooked-abbrev 'vhdl-template-not))
11279 (defun vhdl-template-default-hook ()
11280 (vhdl-hooked-abbrev 'vhdl-template-default))
11281 (defun vhdl-template-default-indent-hook ()
11282 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11284 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11285 ;; Template insertion from completion list
11287 (defun vhdl-template-insert-construct (name)
11288 "Insert the built-in construct template with NAME."
11289 (interactive
11290 (list (let ((completion-ignore-case t))
11291 (completing-read "Construct name: "
11292 vhdl-template-construct-alist nil t))))
11293 (vhdl-template-insert-fun
11294 (cadr (assoc name vhdl-template-construct-alist))))
11296 (defun vhdl-template-insert-package (name)
11297 "Insert the built-in package template with NAME."
11298 (interactive
11299 (list (let ((completion-ignore-case t))
11300 (completing-read "Package name: "
11301 vhdl-template-package-alist nil t))))
11302 (vhdl-template-insert-fun
11303 (cadr (assoc name vhdl-template-package-alist))))
11305 (defun vhdl-template-insert-directive (name)
11306 "Insert the built-in directive template with NAME."
11307 (interactive
11308 (list (let ((completion-ignore-case t))
11309 (completing-read "Directive name: "
11310 vhdl-template-directive-alist nil t))))
11311 (vhdl-template-insert-fun
11312 (cadr (assoc name vhdl-template-directive-alist))))
11314 (defun vhdl-template-insert-fun (fun)
11315 "Call FUN to insert a built-in template."
11316 (let ((caught (catch 'abort (when fun (funcall fun)))))
11317 (when (stringp caught) (message "%s" caught))))
11320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11321 ;;; Models
11322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11324 (defun vhdl-model-insert (model-name)
11325 "Insert the user model with name MODEL-NAME."
11326 (interactive
11327 (let ((completion-ignore-case t))
11328 (list (completing-read "Model name: " vhdl-model-alist))))
11329 (indent-according-to-mode)
11330 (let ((start (point-marker))
11331 (margin (current-indentation))
11332 model position prompt string end)
11333 (vhdl-prepare-search-2
11334 (when (setq model (assoc model-name vhdl-model-alist))
11335 ;; insert model
11336 (beginning-of-line)
11337 (delete-horizontal-space)
11338 (goto-char start)
11339 (vhdl-insert-string-or-file (nth 1 model))
11340 (setq end (point-marker))
11341 ;; indent code
11342 (goto-char start)
11343 (beginning-of-line)
11344 (while (< (point) end)
11345 (unless (looking-at "^$")
11346 (insert-char ? margin))
11347 (beginning-of-line 2))
11348 (goto-char start)
11349 ;; insert clock
11350 (unless (equal "" vhdl-clock-name)
11351 (while (re-search-forward "<clock>" end t)
11352 (replace-match vhdl-clock-name)))
11353 (goto-char start)
11354 ;; insert reset
11355 (unless (equal "" vhdl-reset-name)
11356 (while (re-search-forward "<reset>" end t)
11357 (replace-match vhdl-reset-name)))
11358 ;; replace header prompts
11359 (vhdl-template-replace-header-keywords start end nil t)
11360 (goto-char start)
11361 ;; query other prompts
11362 (while (re-search-forward
11363 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11364 (unless (equal "cursor" (match-string 1))
11365 (setq position (match-beginning 1))
11366 (setq prompt (match-string 1))
11367 (replace-match "")
11368 (setq string (vhdl-template-field prompt nil t))
11369 ;; replace occurrences of same prompt
11370 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11371 (replace-match (or string "")))
11372 (goto-char position)))
11373 (goto-char start)
11374 ;; goto final position
11375 (if (re-search-forward "<cursor>" end t)
11376 (replace-match "")
11377 (goto-char end))))))
11379 (defun vhdl-model-defun ()
11380 "Define help and hook functions for user models."
11381 (let ((model-alist vhdl-model-alist)
11382 model-name model-keyword)
11383 (while model-alist
11384 ;; define functions for user models that can be invoked from menu and key
11385 ;; bindings and which themselves call `vhdl-model-insert' with the model
11386 ;; name as argument
11387 (setq model-name (nth 0 (car model-alist)))
11388 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11389 ,(concat "Insert model for \"" model-name "\".")
11390 (interactive)
11391 (vhdl-model-insert ,model-name)))
11392 ;; define hooks for user models that are invoked from keyword abbrevs
11393 (setq model-keyword (nth 3 (car model-alist)))
11394 (unless (equal model-keyword "")
11395 (eval `(defun
11396 ,(vhdl-function-name
11397 "vhdl-model" model-name "hook") ()
11398 (vhdl-hooked-abbrev
11399 ',(vhdl-function-name "vhdl-model" model-name)))))
11400 (setq model-alist (cdr model-alist)))))
11402 (vhdl-model-defun)
11405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11406 ;;; Port translation
11407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11409 (defvar vhdl-port-list nil
11410 "Variable to hold last port map parsed.")
11411 ;; structure: (parenthesized expression means list of such entries)
11412 ;; (ent-name
11413 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11414 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11415 ;; (lib-name pack-key))
11417 (defun vhdl-parse-string (string &optional optional)
11418 "Check that the text following point matches the regexp in STRING."
11419 (if (looking-at string)
11420 (progn (goto-char (match-end 0))
11421 (when (vhdl-in-literal)
11422 (end-of-line))
11423 (point))
11424 (unless optional
11425 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11426 (vhdl-current-line) string)))
11427 nil))
11429 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11430 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11431 (vhdl-prepare-search-1
11432 (if (string-match (car regexp-cons) string)
11433 (if adjust-case
11434 (funcall vhdl-file-name-case
11435 (replace-match (cdr regexp-cons) t nil string))
11436 (replace-match (cdr regexp-cons) t nil string))
11437 string)))
11439 (defun vhdl-parse-group-comment ()
11440 "Parse comment and empty lines between groups of lines."
11441 (let ((start (point))
11442 string)
11443 (vhdl-forward-comment (point-max))
11444 (setq string (buffer-substring-no-properties start (point)))
11445 (vhdl-forward-syntactic-ws)
11446 ;; strip off leading blanks and first newline
11447 (while (string-match "^\\(\\s-+\\)" string)
11448 (setq string (concat (substring string 0 (match-beginning 1))
11449 (substring string (match-end 1)))))
11450 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11451 (substring string 1)
11452 string)))
11454 (defun vhdl-paste-group-comment (string indent)
11455 "Paste comment and empty lines from STRING between groups of lines
11456 with INDENT."
11457 (let ((pos (point-marker)))
11458 (when (> indent 0)
11459 (while (string-match "^\\(--\\)" string)
11460 (setq string (concat (substring string 0 (match-beginning 1))
11461 (make-string indent ? )
11462 (substring string (match-beginning 1))))))
11463 (beginning-of-line)
11464 (insert string)
11465 (goto-char pos)))
11467 (defvar vhdl-port-flattened nil
11468 "Indicates whether a port has been flattened.")
11470 (defun vhdl-port-flatten (&optional as-alist)
11471 "Flatten port list so that only one generic/port exists per line.
11472 This operation is performed on an internally stored port and is only
11473 reflected in a subsequent paste operation."
11474 (interactive)
11475 (if (not vhdl-port-list)
11476 (error "ERROR: No port has been read")
11477 (message "Flattening port for next paste...")
11478 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11479 (old-vhdl-port-list (cdr vhdl-port-list))
11480 old-port-list new-port-list old-port new-port names)
11481 ;; traverse port list and flatten entries
11482 (while (cdr old-vhdl-port-list)
11483 (setq old-port-list (car old-vhdl-port-list))
11484 (setq new-port-list nil)
11485 (while old-port-list
11486 (setq old-port (car old-port-list))
11487 (setq names (car old-port))
11488 (while names
11489 (setq new-port (cons (if as-alist (car names) (list (car names)))
11490 (cdr old-port)))
11491 (setq new-port-list (append new-port-list (list new-port)))
11492 (setq names (cdr names)))
11493 (setq old-port-list (cdr old-port-list)))
11494 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11495 (setq new-vhdl-port-list (append new-vhdl-port-list
11496 (list new-port-list))))
11497 (setq vhdl-port-list
11498 (append new-vhdl-port-list (list old-vhdl-port-list))
11499 vhdl-port-flattened t)
11500 (message "Flattening port for next paste...done"))))
11502 (defvar vhdl-port-reversed-direction nil
11503 "Indicates whether port directions are reversed.")
11505 (defun vhdl-port-reverse-direction ()
11506 "Reverse direction for all ports (useful in testbenches).
11507 This operation is performed on an internally stored port and is only
11508 reflected in a subsequent paste operation."
11509 (interactive)
11510 (if (not vhdl-port-list)
11511 (error "ERROR: No port has been read")
11512 (message "Reversing port directions for next paste...")
11513 (let ((port-list (nth 2 vhdl-port-list))
11514 port-dir-car port-dir)
11515 ;; traverse port list and reverse directions
11516 (while port-list
11517 (setq port-dir-car (cddr (car port-list))
11518 port-dir (car port-dir-car))
11519 (setcar port-dir-car
11520 (cond ((equal port-dir "in") "out")
11521 ((equal port-dir "IN") "OUT")
11522 ((equal port-dir "out") "in")
11523 ((equal port-dir "OUT") "IN")
11524 (t port-dir)))
11525 (setq port-list (cdr port-list)))
11526 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11527 (message "Reversing port directions for next paste...done"))))
11529 (defun vhdl-port-copy ()
11530 "Get generic and port information from an entity or component declaration."
11531 (interactive)
11532 (save-excursion
11533 (let (parse-error end-of-list
11534 decl-type name generic-list port-list context-clause
11535 object names direct type init comment group-comment)
11536 (vhdl-prepare-search-2
11537 (setq
11538 parse-error
11539 (catch 'parse
11540 ;; check if within entity or component declaration
11541 (end-of-line)
11542 (when (or (not (re-search-backward
11543 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11544 (equal "END" (upcase (match-string 1))))
11545 (throw 'parse "ERROR: Not within an entity or component declaration"))
11546 (setq decl-type (downcase (match-string-no-properties 1)))
11547 (forward-word 1)
11548 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11549 (setq name (match-string-no-properties 1))
11550 (message "Reading port of %s \"%s\"..." decl-type name)
11551 (vhdl-forward-syntactic-ws)
11552 ;; parse generic clause
11553 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11554 ;; parse group comment and spacing
11555 (setq group-comment (vhdl-parse-group-comment))
11556 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11557 (while (not end-of-list)
11558 ;; parse names (accept extended identifiers)
11559 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11560 (setq names (list (match-string-no-properties 1)))
11561 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11562 (setq names
11563 (append names (list (match-string-no-properties 1)))))
11564 ;; parse type
11565 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11566 (setq type (match-string-no-properties 1))
11567 (when (vhdl-in-comment-p) ; if stuck in comment
11568 (setq type (concat type (and (vhdl-parse-string ".*")
11569 (match-string-no-properties 0)))))
11570 (setq comment nil)
11571 (while (looking-at "(")
11572 (setq type
11573 (concat type
11574 (buffer-substring-no-properties
11575 (point) (progn (forward-sexp) (point)))
11576 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11577 (match-string-no-properties 1)))))
11578 ;; special case: closing parenthesis is on separate line
11579 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11580 (setq comment (substring type (match-beginning 2)))
11581 (setq type (substring type 0 (match-beginning 1))))
11582 ;; strip of trailing group-comment
11583 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11584 (setq type (substring type 0 (match-end 1)))
11585 ;; parse initialization expression
11586 (setq init nil)
11587 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11588 (vhdl-parse-string "\\([^();\n]*\\)")
11589 (setq init (match-string-no-properties 1))
11590 (while (looking-at "(")
11591 (setq init
11592 (concat init
11593 (buffer-substring-no-properties
11594 (point) (progn (forward-sexp) (point)))
11595 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11596 (match-string-no-properties 1))))))
11597 ;; special case: closing parenthesis is on separate line
11598 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11599 (setq comment (substring init (match-beginning 2)))
11600 (setq init (substring init 0 (match-beginning 1)))
11601 (vhdl-forward-syntactic-ws))
11602 (skip-chars-forward " \t")
11603 ;; parse inline comment, special case: as above, no initial.
11604 (unless comment
11605 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11606 (match-string-no-properties 1))))
11607 (vhdl-forward-syntactic-ws)
11608 (setq end-of-list (vhdl-parse-string ")" t))
11609 (vhdl-parse-string "\\s-*;\\s-*")
11610 ;; parse inline comment
11611 (unless comment
11612 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11613 (match-string-no-properties 1))))
11614 ;; save everything in list
11615 (setq generic-list (append generic-list
11616 (list (list names type init
11617 comment group-comment))))
11618 ;; parse group comment and spacing
11619 (setq group-comment (vhdl-parse-group-comment))))
11620 ;; parse port clause
11621 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11622 ;; parse group comment and spacing
11623 (setq group-comment (vhdl-parse-group-comment))
11624 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11625 (while (not end-of-list)
11626 ;; parse object
11627 (setq object
11628 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11629 (match-string-no-properties 1)))
11630 ;; parse names (accept extended identifiers)
11631 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11632 (setq names (list (match-string-no-properties 1)))
11633 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11634 (setq names (append names (list (match-string-no-properties 1)))))
11635 ;; parse direction
11636 (vhdl-parse-string ":[ \t\n\r\f]*")
11637 (setq direct
11638 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11639 (match-string-no-properties 1)))
11640 ;; parse type
11641 (vhdl-parse-string "\\([^();\n]+\\)")
11642 (setq type (match-string-no-properties 1))
11643 (when (vhdl-in-comment-p) ; if stuck in comment
11644 (setq type (concat type (and (vhdl-parse-string ".*")
11645 (match-string-no-properties 0)))))
11646 (setq comment nil)
11647 (while (looking-at "(")
11648 (setq type (concat type
11649 (buffer-substring-no-properties
11650 (point) (progn (forward-sexp) (point)))
11651 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11652 (match-string-no-properties 1)))))
11653 ;; special case: closing parenthesis is on separate line
11654 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11655 (setq comment (substring type (match-beginning 2)))
11656 (setq type (substring type 0 (match-beginning 1))))
11657 ;; strip of trailing group-comment
11658 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11659 (setq type (substring type 0 (match-end 1)))
11660 (vhdl-forward-syntactic-ws)
11661 (setq end-of-list (vhdl-parse-string ")" t))
11662 (vhdl-parse-string "\\s-*;\\s-*")
11663 ;; parse inline comment
11664 (unless comment
11665 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11666 (match-string-no-properties 1))))
11667 ;; save everything in list
11668 (setq port-list (append port-list
11669 (list (list names object direct type
11670 comment group-comment))))
11671 ;; parse group comment and spacing
11672 (setq group-comment (vhdl-parse-group-comment))))
11673 ; (vhdl-parse-string "end\\>")
11674 ;; parse context clause
11675 (setq context-clause (vhdl-scan-context-clause))
11676 ; ;; add surrounding package to context clause
11677 ; (when (and (equal decl-type "component")
11678 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11679 ; (setq context-clause
11680 ; (append context-clause
11681 ; (list (cons (vhdl-work-library)
11682 ; (match-string-no-properties 1))))))
11683 (message "Reading port of %s \"%s\"...done" decl-type name)
11684 nil)))
11685 ;; finish parsing
11686 (if parse-error
11687 (error parse-error)
11688 (setq vhdl-port-list (list name generic-list port-list context-clause)
11689 vhdl-port-reversed-direction nil
11690 vhdl-port-flattened nil)))))
11692 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11693 "Paste a context clause."
11694 (let ((margin (current-indentation))
11695 (clause-list (nth 3 vhdl-port-list))
11696 clause)
11697 (while clause-list
11698 (setq clause (car clause-list))
11699 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11700 (downcase exclude-pack-name)))
11701 (save-excursion
11702 (re-search-backward
11703 (concat "^\\s-*use\\s-+" (car clause)
11704 "\." (cdr clause) "\\>") nil t)))
11705 (vhdl-template-standard-package (car clause) (cdr clause))
11706 (insert "\n"))
11707 (setq clause-list (cdr clause-list)))))
11709 (defun vhdl-port-paste-generic (&optional no-init)
11710 "Paste a generic clause."
11711 (let ((margin (current-indentation))
11712 (generic-list (nth 1 vhdl-port-list))
11713 list-margin start names generic)
11714 ;; paste generic clause
11715 (when generic-list
11716 (setq start (point))
11717 (vhdl-insert-keyword "GENERIC (")
11718 (unless vhdl-argument-list-indent
11719 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11720 (setq list-margin (current-column))
11721 (while generic-list
11722 (setq generic (car generic-list))
11723 ;; paste group comment and spacing
11724 (when (memq vhdl-include-group-comments '(decl always))
11725 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11726 ;; paste names
11727 (setq names (nth 0 generic))
11728 (while names
11729 (insert (car names))
11730 (setq names (cdr names))
11731 (when names (insert ", ")))
11732 ;; paste type
11733 (insert " : " (nth 1 generic))
11734 ;; paste initialization
11735 (when (and (not no-init) (nth 2 generic))
11736 (insert " := " (nth 2 generic)))
11737 (unless (cdr generic-list) (insert ")"))
11738 (insert ";")
11739 ;; paste comment
11740 (when (and vhdl-include-port-comments (nth 3 generic))
11741 (vhdl-comment-insert-inline (nth 3 generic) t))
11742 (setq generic-list (cdr generic-list))
11743 (when generic-list (insert "\n") (indent-to list-margin)))
11744 ;; align generic clause
11745 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11747 (defun vhdl-port-paste-port ()
11748 "Paste a port clause."
11749 (let ((margin (current-indentation))
11750 (port-list (nth 2 vhdl-port-list))
11751 list-margin start names port)
11752 ;; paste port clause
11753 (when port-list
11754 (setq start (point))
11755 (vhdl-insert-keyword "PORT (")
11756 (unless vhdl-argument-list-indent
11757 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11758 (setq list-margin (current-column))
11759 (while port-list
11760 (setq port (car port-list))
11761 ;; paste group comment and spacing
11762 (when (memq vhdl-include-group-comments '(decl always))
11763 (vhdl-paste-group-comment (nth 5 port) list-margin))
11764 ;; paste object
11765 (when (nth 1 port) (insert (nth 1 port) " "))
11766 ;; paste names
11767 (setq names (nth 0 port))
11768 (while names
11769 (insert (car names))
11770 (setq names (cdr names))
11771 (when names (insert ", ")))
11772 ;; paste direction
11773 (insert " : ")
11774 (when (nth 2 port) (insert (nth 2 port) " "))
11775 ;; paste type
11776 (insert (nth 3 port))
11777 (unless (cdr port-list) (insert ")"))
11778 (insert ";")
11779 ;; paste comment
11780 (when (and vhdl-include-port-comments (nth 4 port))
11781 (vhdl-comment-insert-inline (nth 4 port) t))
11782 (setq port-list (cdr port-list))
11783 (when port-list (insert "\n") (indent-to list-margin)))
11784 ;; align port clause
11785 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11787 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11788 "Paste as an entity or component declaration."
11789 (unless no-indent (indent-according-to-mode))
11790 (let ((margin (current-indentation))
11791 (name (nth 0 vhdl-port-list)))
11792 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11793 (insert name)
11794 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11795 (vhdl-insert-keyword " IS"))
11796 ;; paste generic and port clause
11797 (when (nth 1 vhdl-port-list)
11798 (insert "\n")
11799 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11800 (insert "\n"))
11801 (indent-to (+ margin vhdl-basic-offset))
11802 (vhdl-port-paste-generic (eq kind 'component)))
11803 (when (nth 2 vhdl-port-list)
11804 (insert "\n")
11805 (when (and (memq vhdl-insert-empty-lines '(unit all))
11806 (eq kind 'entity))
11807 (insert "\n"))
11808 (indent-to (+ margin vhdl-basic-offset)))
11809 (vhdl-port-paste-port)
11810 (insert "\n")
11811 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11812 (insert "\n"))
11813 (indent-to margin)
11814 (vhdl-insert-keyword "END")
11815 (if (eq kind 'entity)
11816 (progn
11817 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11818 (insert " " name))
11819 (vhdl-insert-keyword " COMPONENT")
11820 (unless (vhdl-standard-p '87) (insert " " name)))
11821 (insert ";")))
11823 (defun vhdl-port-paste-entity (&optional no-indent)
11824 "Paste as an entity declaration."
11825 (interactive)
11826 (if (not vhdl-port-list)
11827 (error "ERROR: No port read")
11828 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11829 (vhdl-port-paste-declaration 'entity no-indent)
11830 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11832 (defun vhdl-port-paste-component (&optional no-indent)
11833 "Paste as a component declaration."
11834 (interactive)
11835 (if (not vhdl-port-list)
11836 (error "ERROR: No port read")
11837 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11838 (vhdl-port-paste-declaration 'component no-indent)
11839 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11841 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11842 "Paste as a generic map."
11843 (interactive)
11844 (unless secondary (indent-according-to-mode))
11845 (let ((margin (current-indentation))
11846 list-margin start generic
11847 (generic-list (nth 1 vhdl-port-list)))
11848 (when generic-list
11849 (setq start (point))
11850 (vhdl-insert-keyword "GENERIC MAP (")
11851 (if (not vhdl-association-list-with-formals)
11852 ;; paste list of actual generics
11853 (while generic-list
11854 (insert (if no-constants
11855 (car (nth 0 (car generic-list)))
11856 (or (nth 2 (car generic-list)) " ")))
11857 (setq generic-list (cdr generic-list))
11858 (insert (if generic-list ", " ")"))
11859 (when (and (not generic-list) secondary
11860 (null (nth 2 vhdl-port-list)))
11861 (insert ";")))
11862 (unless vhdl-argument-list-indent
11863 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11864 (setq list-margin (current-column))
11865 (while generic-list
11866 (setq generic (car generic-list))
11867 ;; paste group comment and spacing
11868 (when (eq vhdl-include-group-comments 'always)
11869 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11870 ;; paste formal and actual generic
11871 (insert (car (nth 0 generic)) " => "
11872 (if no-constants
11873 (vhdl-replace-string vhdl-actual-generic-name
11874 (car (nth 0 generic)))
11875 (or (nth 2 generic) "")))
11876 (setq generic-list (cdr generic-list))
11877 (insert (if generic-list "," ")"))
11878 (when (and (not generic-list) secondary
11879 (null (nth 2 vhdl-port-list)))
11880 (insert ";"))
11881 ;; paste comment
11882 (when (or vhdl-include-type-comments
11883 (and vhdl-include-port-comments (nth 3 generic)))
11884 (vhdl-comment-insert-inline
11885 (concat
11886 (when vhdl-include-type-comments
11887 (concat "[" (nth 1 generic) "] "))
11888 (when vhdl-include-port-comments (nth 3 generic))) t))
11889 (when generic-list (insert "\n") (indent-to list-margin)))
11890 ;; align generic map
11891 (when vhdl-auto-align
11892 (vhdl-align-region-groups start (point) 1 t))))))
11894 (defun vhdl-port-paste-port-map ()
11895 "Paste as a port map."
11896 (let ((margin (current-indentation))
11897 list-margin start port
11898 (port-list (nth 2 vhdl-port-list)))
11899 (when port-list
11900 (setq start (point))
11901 (vhdl-insert-keyword "PORT MAP (")
11902 (if (not vhdl-association-list-with-formals)
11903 ;; paste list of actual ports
11904 (while port-list
11905 (insert (vhdl-replace-string vhdl-actual-port-name
11906 (car (nth 0 (car port-list)))))
11907 (setq port-list (cdr port-list))
11908 (insert (if port-list ", " ")")))
11909 (unless vhdl-argument-list-indent
11910 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11911 (setq list-margin (current-column))
11912 (while port-list
11913 (setq port (car port-list))
11914 ;; paste group comment and spacing
11915 (when (eq vhdl-include-group-comments 'always)
11916 (vhdl-paste-group-comment (nth 5 port) list-margin))
11917 ;; paste formal and actual port
11918 (insert (car (nth 0 port)) " => ")
11919 (insert (vhdl-replace-string vhdl-actual-port-name
11920 (car (nth 0 port))))
11921 (setq port-list (cdr port-list))
11922 (insert (if port-list "," ");"))
11923 ;; paste comment
11924 (when (or (and vhdl-include-direction-comments (nth 2 port))
11925 vhdl-include-type-comments
11926 (and vhdl-include-port-comments (nth 4 port)))
11927 (vhdl-comment-insert-inline
11928 (concat
11929 (cond ((and vhdl-include-direction-comments
11930 vhdl-include-type-comments)
11931 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11932 (nth 3 port) "] "))
11933 ((and vhdl-include-direction-comments (nth 2 port))
11934 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11935 (vhdl-include-direction-comments " ")
11936 (vhdl-include-type-comments
11937 (concat "[" (nth 3 port) "] ")))
11938 (when vhdl-include-port-comments (nth 4 port))) t))
11939 (when port-list (insert "\n") (indent-to list-margin)))
11940 ;; align port clause
11941 (when vhdl-auto-align
11942 (vhdl-align-region-groups start (point) 1))))))
11944 (defun vhdl-port-paste-instance (&optional name no-indent title)
11945 "Paste as an instantiation."
11946 (interactive)
11947 (if (not vhdl-port-list)
11948 (error "ERROR: No port read")
11949 (let ((orig-vhdl-port-list vhdl-port-list))
11950 ;; flatten local copy of port list (must be flat for port mapping)
11951 (vhdl-port-flatten)
11952 (unless no-indent (indent-according-to-mode))
11953 (let ((margin (current-indentation)))
11954 ;; paste instantiation
11955 (cond (name
11956 (insert name))
11957 ((equal (cdr vhdl-instance-name) "")
11958 (setq name (vhdl-template-field "instance name")))
11959 ((string-match "\%d" (cdr vhdl-instance-name))
11960 (let ((n 1))
11961 (while (save-excursion
11962 (setq name (format (vhdl-replace-string
11963 vhdl-instance-name
11964 (nth 0 vhdl-port-list)) n))
11965 (goto-char (point-min))
11966 (vhdl-re-search-forward name nil t))
11967 (setq n (1+ n)))
11968 (insert name)))
11969 (t (insert (vhdl-replace-string vhdl-instance-name
11970 (nth 0 vhdl-port-list)))))
11971 (message "Pasting port as instantiation \"%s\"..." name)
11972 (insert ": ")
11973 (when title
11974 (save-excursion
11975 (beginning-of-line)
11976 (indent-to vhdl-basic-offset)
11977 (insert "-- instance \"" name "\"\n")))
11978 (if (not (vhdl-use-direct-instantiation))
11979 (insert (nth 0 vhdl-port-list))
11980 (vhdl-insert-keyword "ENTITY ")
11981 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11982 (when (nth 1 vhdl-port-list)
11983 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11984 (vhdl-port-paste-generic-map t t))
11985 (when (nth 2 vhdl-port-list)
11986 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11987 (vhdl-port-paste-port-map))
11988 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11989 (insert ";"))
11990 (message "Pasting port as instantiation \"%s\"...done" name))
11991 (setq vhdl-port-list orig-vhdl-port-list))))
11993 (defun vhdl-port-paste-constants (&optional no-indent)
11994 "Paste generics as constants."
11995 (interactive)
11996 (if (not vhdl-port-list)
11997 (error "ERROR: No port read")
11998 (let ((orig-vhdl-port-list vhdl-port-list))
11999 (message "Pasting port as constants...")
12000 ;; flatten local copy of port list (must be flat for constant initial.)
12001 (vhdl-port-flatten)
12002 (unless no-indent (indent-according-to-mode))
12003 (let ((margin (current-indentation))
12004 start generic name
12005 (generic-list (nth 1 vhdl-port-list)))
12006 (when generic-list
12007 (setq start (point))
12008 (while generic-list
12009 (setq generic (car generic-list))
12010 ;; paste group comment and spacing
12011 (when (memq vhdl-include-group-comments '(decl always))
12012 (vhdl-paste-group-comment (nth 4 generic) margin))
12013 (vhdl-insert-keyword "CONSTANT ")
12014 ;; paste generic constants
12015 (setq name (nth 0 generic))
12016 (when name
12017 (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
12018 ;; paste type
12019 (insert " : " (nth 1 generic))
12020 ;; paste initialization
12021 (when (nth 2 generic)
12022 (insert " := " (nth 2 generic)))
12023 (insert ";")
12024 ;; paste comment
12025 (when (and vhdl-include-port-comments (nth 3 generic))
12026 (vhdl-comment-insert-inline (nth 3 generic) t))
12027 (setq generic-list (cdr generic-list))
12028 (when generic-list (insert "\n") (indent-to margin))))
12029 ;; align signal list
12030 (when vhdl-auto-align
12031 (vhdl-align-region-groups start (point) 1))))
12032 (message "Pasting port as constants...done")
12033 (setq vhdl-port-list orig-vhdl-port-list))))
12035 (defun vhdl-port-paste-signals (&optional initialize no-indent)
12036 "Paste ports as internal signals."
12037 (interactive)
12038 (if (not vhdl-port-list)
12039 (error "ERROR: No port read")
12040 (message "Pasting port as signals...")
12041 (unless no-indent (indent-according-to-mode))
12042 (let ((margin (current-indentation))
12043 start port names type generic-list port-name constant-name pos
12044 (port-list (nth 2 vhdl-port-list)))
12045 (when port-list
12046 (setq start (point))
12047 (while port-list
12048 (setq port (car port-list))
12049 ;; paste group comment and spacing
12050 (when (memq vhdl-include-group-comments '(decl always))
12051 (vhdl-paste-group-comment (nth 5 port) margin))
12052 ;; paste object
12053 (if (nth 1 port)
12054 (insert (nth 1 port) " ")
12055 (vhdl-insert-keyword "SIGNAL "))
12056 ;; paste actual port signals
12057 (setq names (nth 0 port))
12058 (while names
12059 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
12060 (setq names (cdr names))
12061 (when names (insert ", ")))
12062 ;; paste type
12063 (setq type (nth 3 port))
12064 (setq generic-list (nth 1 vhdl-port-list))
12065 (vhdl-prepare-search-1
12066 (setq pos 0)
12067 ;; replace formal by actual generics
12068 (while generic-list
12069 (setq port-name (car (nth 0 (car generic-list))))
12070 (while (string-match (concat "\\<" port-name "\\>") type pos)
12071 (setq constant-name
12072 (save-match-data (vhdl-replace-string
12073 vhdl-actual-generic-name port-name)))
12074 (setq type (replace-match constant-name t nil type))
12075 (setq pos (match-end 0)))
12076 (setq generic-list (cdr generic-list))))
12077 (insert " : " type)
12078 ;; paste initialization (inputs only)
12079 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
12080 (insert " := "
12081 (cond ((string-match "integer" (nth 3 port)) "0")
12082 ((string-match "natural" (nth 3 port)) "0")
12083 ((string-match "positive" (nth 3 port)) "0")
12084 ((string-match "real" (nth 3 port)) "0.0")
12085 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12086 (t "'0'"))))
12087 (insert ";")
12088 ;; paste comment
12089 (when (or (and vhdl-include-direction-comments (nth 2 port))
12090 (and vhdl-include-port-comments (nth 4 port)))
12091 (vhdl-comment-insert-inline
12092 (concat
12093 (cond ((and vhdl-include-direction-comments (nth 2 port))
12094 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12095 (vhdl-include-direction-comments " "))
12096 (when vhdl-include-port-comments (nth 4 port))) t))
12097 (setq port-list (cdr port-list))
12098 (when port-list (insert "\n") (indent-to margin)))
12099 ;; align signal list
12100 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12101 (message "Pasting port as signals...done")))
12103 (defun vhdl-port-paste-initializations (&optional no-indent)
12104 "Paste ports as signal initializations."
12105 (interactive)
12106 (if (not vhdl-port-list)
12107 (error "ERROR: No port read")
12108 (let ((orig-vhdl-port-list vhdl-port-list))
12109 (message "Pasting port as initializations...")
12110 ;; flatten local copy of port list (must be flat for signal initial.)
12111 (vhdl-port-flatten)
12112 (unless no-indent (indent-according-to-mode))
12113 (let ((margin (current-indentation))
12114 start port name
12115 (port-list (nth 2 vhdl-port-list)))
12116 (when port-list
12117 (setq start (point))
12118 (while port-list
12119 (setq port (car port-list))
12120 ;; paste actual port signal (inputs only)
12121 (when (equal "IN" (upcase (nth 2 port)))
12122 (setq name (car (nth 0 port)))
12123 (insert (vhdl-replace-string vhdl-actual-port-name name))
12124 ;; paste initialization
12125 (insert " <= "
12126 (cond ((string-match "integer" (nth 3 port)) "0")
12127 ((string-match "natural" (nth 3 port)) "0")
12128 ((string-match "positive" (nth 3 port)) "0")
12129 ((string-match "real" (nth 3 port)) "0.0")
12130 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12131 (t "'0'"))
12132 ";"))
12133 (setq port-list (cdr port-list))
12134 (when (and port-list
12135 (equal "IN" (upcase (nth 2 (car port-list)))))
12136 (insert "\n") (indent-to margin)))
12137 ;; align signal list
12138 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12139 (message "Pasting port as initializations...done")
12140 (setq vhdl-port-list orig-vhdl-port-list))))
12142 (defun vhdl-port-paste-testbench ()
12143 "Paste as a bare-bones testbench."
12144 (interactive)
12145 (if (not vhdl-port-list)
12146 (error "ERROR: No port read")
12147 (let ((case-fold-search t)
12148 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12149 (nth 0 vhdl-port-list)))
12150 (source-buffer (current-buffer))
12151 arch-name config-name ent-file-name arch-file-name
12152 ent-buffer arch-buffer position)
12153 ;; open entity file
12154 (unless (eq vhdl-testbench-create-files 'none)
12155 (setq ent-file-name
12156 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12157 ent-name t)
12158 "." (file-name-extension (buffer-file-name))))
12159 (if (file-exists-p ent-file-name)
12160 (if (y-or-n-p
12161 (concat "File \"" ent-file-name "\" exists; overwrite? "))
12162 (progn (find-file ent-file-name)
12163 (erase-buffer)
12164 (set-buffer-modified-p nil))
12165 (if (eq vhdl-testbench-create-files 'separate)
12166 (setq ent-file-name nil)
12167 (error "ERROR: Pasting port as testbench...aborted")))
12168 (find-file ent-file-name)))
12169 (unless (and (eq vhdl-testbench-create-files 'separate)
12170 (null ent-file-name))
12171 ;; paste entity header
12172 (if vhdl-testbench-include-header
12173 (progn (vhdl-template-header
12174 (concat "Testbench for design \""
12175 (nth 0 vhdl-port-list) "\""))
12176 (goto-char (point-max)))
12177 (vhdl-comment-display-line) (insert "\n\n"))
12178 ;; paste std_logic_1164 package
12179 (when vhdl-testbench-include-library
12180 (vhdl-template-package-std-logic-1164)
12181 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12182 ;; paste entity declaration
12183 (vhdl-insert-keyword "ENTITY ")
12184 (insert ent-name)
12185 (vhdl-insert-keyword " IS")
12186 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
12187 (insert "\n")
12188 (vhdl-insert-keyword "END ")
12189 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12190 (insert ent-name ";")
12191 (insert "\n\n")
12192 (vhdl-comment-display-line) (insert "\n"))
12193 ;; get architecture name
12194 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
12195 (read-from-minibuffer "architecture name: "
12196 nil vhdl-minibuffer-local-map)
12197 (vhdl-replace-string vhdl-testbench-architecture-name
12198 (nth 0 vhdl-port-list))))
12199 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
12200 ;; open architecture file
12201 (if (not (eq vhdl-testbench-create-files 'separate))
12202 (insert "\n")
12203 (setq ent-buffer (current-buffer))
12204 (setq arch-file-name
12205 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12206 (concat ent-name " " arch-name) t)
12207 "." (file-name-extension (buffer-file-name))))
12208 (when (and (file-exists-p arch-file-name)
12209 (not (y-or-n-p (concat "File \"" arch-file-name
12210 "\" exists; overwrite? "))))
12211 (error "ERROR: Pasting port as testbench...aborted"))
12212 (find-file arch-file-name)
12213 (erase-buffer)
12214 (set-buffer-modified-p nil)
12215 ;; paste architecture header
12216 (if vhdl-testbench-include-header
12217 (progn (vhdl-template-header
12218 (concat "Testbench architecture for design \""
12219 (nth 0 vhdl-port-list) "\""))
12220 (goto-char (point-max)))
12221 (vhdl-comment-display-line) (insert "\n\n")))
12222 ;; paste architecture body
12223 (vhdl-insert-keyword "ARCHITECTURE ")
12224 (insert arch-name)
12225 (vhdl-insert-keyword " OF ")
12226 (insert ent-name)
12227 (vhdl-insert-keyword " IS")
12228 (insert "\n\n") (indent-to vhdl-basic-offset)
12229 ;; paste component declaration
12230 (unless (vhdl-use-direct-instantiation)
12231 (vhdl-port-paste-component t)
12232 (insert "\n\n") (indent-to vhdl-basic-offset))
12233 ;; paste constants
12234 (when (nth 1 vhdl-port-list)
12235 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
12236 (vhdl-port-paste-constants t)
12237 (insert "\n\n") (indent-to vhdl-basic-offset))
12238 ;; paste internal signals
12239 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
12240 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
12241 (insert "\n")
12242 ;; paste custom declarations
12243 (unless (equal "" vhdl-testbench-declarations)
12244 (insert "\n")
12245 (setq position (point))
12246 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12247 (vhdl-indent-region position (point)))
12248 (setq position (point))
12249 (insert "\n\n")
12250 (vhdl-comment-display-line) (insert "\n")
12251 (when vhdl-testbench-include-configuration
12252 (setq config-name (vhdl-replace-string
12253 vhdl-testbench-configuration-name
12254 (concat ent-name " " arch-name)))
12255 (insert "\n")
12256 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12257 (vhdl-insert-keyword " OF ") (insert ent-name)
12258 (vhdl-insert-keyword " IS\n")
12259 (indent-to vhdl-basic-offset)
12260 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12261 (indent-to vhdl-basic-offset)
12262 (vhdl-insert-keyword "END FOR;\n")
12263 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12264 (vhdl-comment-display-line) (insert "\n"))
12265 (goto-char position)
12266 (vhdl-template-begin-end
12267 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12268 ;; paste instantiation
12269 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12270 (vhdl-port-paste-instance
12271 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12272 (insert "\n")
12273 ;; paste custom statements
12274 (unless (equal "" vhdl-testbench-statements)
12275 (insert "\n")
12276 (setq position (point))
12277 (vhdl-insert-string-or-file vhdl-testbench-statements)
12278 (vhdl-indent-region position (point)))
12279 (insert "\n")
12280 (indent-to vhdl-basic-offset)
12281 (unless (eq vhdl-testbench-create-files 'none)
12282 (setq arch-buffer (current-buffer))
12283 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12284 (set-buffer arch-buffer) (save-buffer))
12285 (message "%s"
12286 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12287 ent-name arch-name)
12288 (and ent-file-name
12289 (format "\n File created: \"%s\"" ent-file-name))
12290 (and arch-file-name
12291 (format "\n File created: \"%s\"" arch-file-name)))))))
12294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12295 ;;; Subprogram interface translation
12296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12298 (defvar vhdl-subprog-list nil
12299 "Variable to hold last subprogram interface parsed.")
12300 ;; structure: (parenthesized expression means list of such entries)
12301 ;; (subprog-name kind
12302 ;; ((names) object direct type init comment group-comment)
12303 ;; return-type return-comment group-comment)
12305 (defvar vhdl-subprog-flattened nil
12306 "Indicates whether an subprogram interface has been flattened.")
12308 (defun vhdl-subprog-flatten ()
12309 "Flatten interface list so that only one parameter exists per line."
12310 (interactive)
12311 (if (not vhdl-subprog-list)
12312 (error "ERROR: No subprogram interface has been read")
12313 (message "Flattening subprogram interface...")
12314 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12315 new-subprog-list old-subprog new-subprog names)
12316 ;; traverse parameter list and flatten entries
12317 (while old-subprog-list
12318 (setq old-subprog (car old-subprog-list))
12319 (setq names (car old-subprog))
12320 (while names
12321 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12322 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12323 (setq names (cdr names)))
12324 (setq old-subprog-list (cdr old-subprog-list)))
12325 (setq vhdl-subprog-list
12326 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12327 new-subprog-list (nth 3 vhdl-subprog-list)
12328 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12329 vhdl-subprog-flattened t)
12330 (message "Flattening subprogram interface...done"))))
12332 (defun vhdl-subprog-copy ()
12333 "Get interface information from a subprogram specification."
12334 (interactive)
12335 (save-excursion
12336 (let (parse-error pos end-of-list
12337 name kind param-list object names direct type init
12338 comment group-comment
12339 return-type return-comment return-group-comment)
12340 (vhdl-prepare-search-2
12341 (setq
12342 parse-error
12343 (catch 'parse
12344 ;; check if within function declaration
12345 (setq pos (point))
12346 (end-of-line)
12347 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12348 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12349 (goto-char (match-end 0))
12350 (save-excursion (backward-char)
12351 (forward-sexp)
12352 (<= pos (point))))
12353 (throw 'parse "ERROR: Not within a subprogram specification"))
12354 (setq name (match-string-no-properties 5))
12355 (setq kind (if (match-string 2) 'procedure 'function))
12356 (setq end-of-list (not (match-string 7)))
12357 (message "Reading interface of subprogram \"%s\"..." name)
12358 ;; parse parameter list
12359 (setq group-comment (vhdl-parse-group-comment))
12360 (setq end-of-list (or end-of-list
12361 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12362 (while (not end-of-list)
12363 ;; parse object
12364 (setq object
12365 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12366 (match-string-no-properties 1)))
12367 ;; parse names (accept extended identifiers)
12368 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12369 (setq names (list (match-string-no-properties 1)))
12370 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12371 (setq names (append names (list (match-string-no-properties 1)))))
12372 ;; parse direction
12373 (vhdl-parse-string ":[ \t\n\r\f]*")
12374 (setq direct
12375 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12376 (match-string-no-properties 1)))
12377 ;; parse type
12378 (vhdl-parse-string "\\([^():;\n]+\\)")
12379 (setq type (match-string-no-properties 1))
12380 (setq comment nil)
12381 (while (looking-at "(")
12382 (setq type
12383 (concat type
12384 (buffer-substring-no-properties
12385 (point) (progn (forward-sexp) (point)))
12386 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12387 (match-string-no-properties 1)))))
12388 ;; special case: closing parenthesis is on separate line
12389 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12390 (setq comment (substring type (match-beginning 2)))
12391 (setq type (substring type 0 (match-beginning 1))))
12392 ;; strip off trailing group-comment
12393 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12394 (setq type (substring type 0 (match-end 1)))
12395 ;; parse initialization expression
12396 (setq init nil)
12397 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12398 (vhdl-parse-string "\\([^();\n]*\\)")
12399 (setq init (match-string-no-properties 1))
12400 (while (looking-at "(")
12401 (setq init
12402 (concat init
12403 (buffer-substring-no-properties
12404 (point) (progn (forward-sexp) (point)))
12405 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12406 (match-string-no-properties 1))))))
12407 ;; special case: closing parenthesis is on separate line
12408 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12409 (setq comment (substring init (match-beginning 2)))
12410 (setq init (substring init 0 (match-beginning 1)))
12411 (vhdl-forward-syntactic-ws))
12412 (skip-chars-forward " \t")
12413 ;; parse inline comment, special case: as above, no initial.
12414 (unless comment
12415 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12416 (match-string-no-properties 1))))
12417 (vhdl-forward-syntactic-ws)
12418 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12419 ;; parse inline comment
12420 (unless comment
12421 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12422 (match-string-no-properties 1))))
12423 (setq return-group-comment (vhdl-parse-group-comment))
12424 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12425 ;; parse return type
12426 (when (match-string 3)
12427 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12428 (setq return-type (match-string-no-properties 1))
12429 (when (and return-type
12430 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12431 (setq return-comment (substring return-type (match-beginning 2)))
12432 (setq return-type (substring return-type 0 (match-beginning 1))))
12433 ;; strip of trailing group-comment
12434 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12435 (setq return-type (substring return-type 0 (match-end 1)))
12436 ;; parse return comment
12437 (unless return-comment
12438 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12439 (match-string-no-properties 1)))))
12440 ;; parse inline comment
12441 (unless comment
12442 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12443 (match-string-no-properties 1))))
12444 ;; save everything in list
12445 (setq param-list (append param-list
12446 (list (list names object direct type init
12447 comment group-comment))))
12448 ;; parse group comment and spacing
12449 (setq group-comment (vhdl-parse-group-comment)))
12450 (message "Reading interface of subprogram \"%s\"...done" name)
12451 nil)))
12452 ;; finish parsing
12453 (if parse-error
12454 (error parse-error)
12455 (setq vhdl-subprog-list
12456 (list name kind param-list return-type return-comment
12457 return-group-comment)
12458 vhdl-subprog-flattened nil)))))
12460 (defun vhdl-subprog-paste-specification (kind)
12461 "Paste as a subprogram specification."
12462 (indent-according-to-mode)
12463 (let ((margin (current-column))
12464 (param-list (nth 2 vhdl-subprog-list))
12465 list-margin start names param)
12466 ;; paste keyword and name
12467 (vhdl-insert-keyword
12468 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12469 (insert (nth 0 vhdl-subprog-list))
12470 (if (not param-list)
12471 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12472 (setq start (point))
12473 ;; paste parameter list
12474 (insert " (")
12475 (unless vhdl-argument-list-indent
12476 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12477 (setq list-margin (current-column))
12478 (while param-list
12479 (setq param (car param-list))
12480 ;; paste group comment and spacing
12481 (when (memq vhdl-include-group-comments (list kind 'always))
12482 (vhdl-paste-group-comment (nth 6 param) list-margin))
12483 ;; paste object
12484 (when (nth 1 param) (insert (nth 1 param) " "))
12485 ;; paste names
12486 (setq names (nth 0 param))
12487 (while names
12488 (insert (car names))
12489 (setq names (cdr names))
12490 (when names (insert ", ")))
12491 ;; paste direction
12492 (insert " : ")
12493 (when (nth 2 param) (insert (nth 2 param) " "))
12494 ;; paste type
12495 (insert (nth 3 param))
12496 ;; paste initialization
12497 (when (nth 4 param) (insert " := " (nth 4 param)))
12498 ;; terminate line
12499 (if (cdr param-list)
12500 (insert ";")
12501 (insert ")")
12502 (when (null (nth 3 vhdl-subprog-list))
12503 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12504 ;; paste comment
12505 (when (and vhdl-include-port-comments (nth 5 param))
12506 (vhdl-comment-insert-inline (nth 5 param) t))
12507 (setq param-list (cdr param-list))
12508 (when param-list (insert "\n") (indent-to list-margin)))
12509 (when (nth 3 vhdl-subprog-list)
12510 (insert "\n") (indent-to list-margin)
12511 ;; paste group comment and spacing
12512 (when (memq vhdl-include-group-comments (list kind 'always))
12513 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12514 ;; paste return type
12515 (insert "return " (nth 3 vhdl-subprog-list))
12516 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12517 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12518 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12519 ;; align parameter list
12520 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12521 ;; paste body
12522 (when (eq kind 'body)
12523 (insert "\n")
12524 (vhdl-template-begin-end
12525 (unless (vhdl-standard-p '87)
12526 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12527 (nth 0 vhdl-subprog-list) margin))))
12529 (defun vhdl-subprog-paste-declaration ()
12530 "Paste as a subprogram declaration."
12531 (interactive)
12532 (if (not vhdl-subprog-list)
12533 (error "ERROR: No subprogram interface read")
12534 (message "Pasting interface as subprogram declaration \"%s\"..."
12535 (car vhdl-subprog-list))
12536 ;; paste specification
12537 (vhdl-subprog-paste-specification 'decl)
12538 (message "Pasting interface as subprogram declaration \"%s\"...done"
12539 (car vhdl-subprog-list))))
12541 (defun vhdl-subprog-paste-body ()
12542 "Paste as a subprogram body."
12543 (interactive)
12544 (if (not vhdl-subprog-list)
12545 (error "ERROR: No subprogram interface read")
12546 (message "Pasting interface as subprogram body \"%s\"..."
12547 (car vhdl-subprog-list))
12548 ;; paste specification and body
12549 (vhdl-subprog-paste-specification 'body)
12550 (message "Pasting interface as subprogram body \"%s\"...done"
12551 (car vhdl-subprog-list))))
12553 (defun vhdl-subprog-paste-call ()
12554 "Paste as a subprogram call."
12555 (interactive)
12556 (if (not vhdl-subprog-list)
12557 (error "ERROR: No subprogram interface read")
12558 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12559 param-list margin list-margin param start)
12560 ;; flatten local copy of interface list (must be flat for parameter mapping)
12561 (vhdl-subprog-flatten)
12562 (setq param-list (nth 2 vhdl-subprog-list))
12563 (indent-according-to-mode)
12564 (setq margin (current-indentation))
12565 (message "Pasting interface as subprogram call \"%s\"..."
12566 (car vhdl-subprog-list))
12567 ;; paste name
12568 (insert (nth 0 vhdl-subprog-list))
12569 (if (not param-list)
12570 (insert ";")
12571 (setq start (point))
12572 ;; paste parameter list
12573 (insert " (")
12574 (unless vhdl-argument-list-indent
12575 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12576 (setq list-margin (current-column))
12577 (while param-list
12578 (setq param (car param-list))
12579 ;; paste group comment and spacing
12580 (when (eq vhdl-include-group-comments 'always)
12581 (vhdl-paste-group-comment (nth 6 param) list-margin))
12582 ;; paste formal port
12583 (insert (car (nth 0 param)) " => ")
12584 (setq param-list (cdr param-list))
12585 (insert (if param-list "," ");"))
12586 ;; paste comment
12587 (when (and vhdl-include-port-comments (nth 5 param))
12588 (vhdl-comment-insert-inline (nth 5 param)))
12589 (when param-list (insert "\n") (indent-to list-margin)))
12590 ;; align parameter list
12591 (when vhdl-auto-align
12592 (vhdl-align-region-groups start (point) 1)))
12593 (message "Pasting interface as subprogram call \"%s\"...done"
12594 (car vhdl-subprog-list))
12595 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12598 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12599 ;;; Miscellaneous
12600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12603 ;; Hippie expand customization
12605 (defvar vhdl-expand-upper-case nil)
12607 (defun vhdl-try-expand-abbrev (old)
12608 "Try expanding abbreviations from `vhdl-abbrev-list'."
12609 (unless old
12610 (he-init-string (he-dabbrev-beg) (point))
12611 (setq he-expand-list
12612 (let ((abbrev-list vhdl-abbrev-list)
12613 (sel-abbrev-list '()))
12614 (while abbrev-list
12615 (when (or (not (stringp (car abbrev-list)))
12616 (string-match
12617 (concat "^" he-search-string) (car abbrev-list)))
12618 (setq sel-abbrev-list
12619 (cons (car abbrev-list) sel-abbrev-list)))
12620 (setq abbrev-list (cdr abbrev-list)))
12621 (nreverse sel-abbrev-list))))
12622 (while (and he-expand-list
12623 (or (not (stringp (car he-expand-list)))
12624 (he-string-member (car he-expand-list) he-tried-table t)))
12625 ; (equal (car he-expand-list) he-search-string)))
12626 (unless (stringp (car he-expand-list))
12627 (setq vhdl-expand-upper-case (car he-expand-list)))
12628 (setq he-expand-list (cdr he-expand-list)))
12629 (if (null he-expand-list)
12630 (progn (when old (he-reset-string))
12631 nil)
12632 (he-substitute-string
12633 (if vhdl-expand-upper-case
12634 (upcase (car he-expand-list))
12635 (car he-expand-list))
12637 (setq he-expand-list (cdr he-expand-list))
12640 (defun vhdl-he-list-beg ()
12641 "Also looks at the word before `(' in order to better match parenthesized
12642 expressions (e.g. for index ranges of types and signals)."
12643 (save-excursion
12644 (condition-case ()
12645 (progn (backward-up-list 1)
12646 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12647 (error ()))
12648 (point)))
12650 ;; override `he-list-beg' from `hippie-exp'
12651 (unless (and (boundp 'viper-mode) viper-mode)
12652 (defalias 'he-list-beg 'vhdl-he-list-beg))
12654 ;; function for expanding abbrevs and dabbrevs
12655 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12656 '(try-expand-dabbrev
12657 try-expand-dabbrev-all-buffers
12658 vhdl-try-expand-abbrev)))
12660 ;; function for expanding parenthesis
12661 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12662 '(try-expand-list
12663 try-expand-list-all-buffers)))
12665 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12666 ;; Line handling functions
12668 (defun vhdl-current-line ()
12669 "Return the line number of the line containing point."
12670 (save-restriction
12671 (widen)
12672 (1+ (count-lines (point-min) (point-at-bol)))))
12674 (defun vhdl-line-kill-entire (&optional arg)
12675 "Delete entire line."
12676 (interactive "p")
12677 (beginning-of-line)
12678 (kill-line (or arg 1)))
12680 (defun vhdl-line-kill (&optional arg)
12681 "Kill current line."
12682 (interactive "p")
12683 (vhdl-line-kill-entire arg))
12685 (defun vhdl-line-copy (&optional arg)
12686 "Copy current line."
12687 (interactive "p")
12688 (save-excursion
12689 (let ((position (point-at-bol)))
12690 (forward-line (or arg 1))
12691 (copy-region-as-kill position (point)))))
12693 (defun vhdl-line-yank ()
12694 "Yank entire line."
12695 (interactive)
12696 (beginning-of-line)
12697 (yank))
12699 (defun vhdl-line-expand (&optional prefix-arg)
12700 "Hippie-expand current line."
12701 (interactive "P")
12702 (require 'hippie-exp)
12703 (let ((case-fold-search t) (case-replace nil)
12704 (hippie-expand-try-functions-list
12705 '(try-expand-line try-expand-line-all-buffers)))
12706 (hippie-expand prefix-arg)))
12708 (defun vhdl-line-transpose-next (&optional arg)
12709 "Interchange this line with next line."
12710 (interactive "p")
12711 (forward-line 1)
12712 (transpose-lines (or arg 1))
12713 (forward-line -1))
12715 (defun vhdl-line-transpose-previous (&optional arg)
12716 "Interchange this line with previous line."
12717 (interactive "p")
12718 (forward-line 1)
12719 (transpose-lines (- 0 (or arg 0)))
12720 (forward-line -1))
12722 (defun vhdl-line-open ()
12723 "Open a new line and indent."
12724 (interactive)
12725 (end-of-line -0)
12726 (newline-and-indent))
12728 (defun vhdl-delete-indentation ()
12729 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12730 it works within comments too."
12731 (interactive)
12732 (let ((fill-prefix "-- "))
12733 (delete-indentation)))
12735 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12736 ;; Move functions
12738 (defun vhdl-forward-same-indent ()
12739 "Move forward to next line with same indent."
12740 (interactive)
12741 (let ((pos (point))
12742 (indent (current-indentation)))
12743 (beginning-of-line 2)
12744 (while (and (not (eobp))
12745 (or (looking-at "^\\s-*\\(--.*\\)?$")
12746 (> (current-indentation) indent)))
12747 (beginning-of-line 2))
12748 (if (= (current-indentation) indent)
12749 (back-to-indentation)
12750 (message "No following line with same indent found in this block")
12751 (goto-char pos)
12752 nil)))
12754 (defun vhdl-backward-same-indent ()
12755 "Move backward to previous line with same indent."
12756 (interactive)
12757 (let ((pos (point))
12758 (indent (current-indentation)))
12759 (beginning-of-line -0)
12760 (while (and (not (bobp))
12761 (or (looking-at "^\\s-*\\(--.*\\)?$")
12762 (> (current-indentation) indent)))
12763 (beginning-of-line -0))
12764 (if (= (current-indentation) indent)
12765 (back-to-indentation)
12766 (message "No preceding line with same indent found in this block")
12767 (goto-char pos)
12768 nil)))
12770 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12771 ;; Statistics
12773 (defun vhdl-statistics-buffer ()
12774 "Get some file statistics."
12775 (interactive)
12776 (let ((no-stats 0)
12777 (no-code-lines 0)
12778 (no-empty-lines 0)
12779 (no-comm-lines 0)
12780 (no-comments 0)
12781 (no-lines (count-lines (point-min) (point-max))))
12782 (save-excursion
12783 ;; count statements
12784 (goto-char (point-min))
12785 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12786 (if (match-string 1)
12787 (goto-char (match-end 1))
12788 (setq no-stats (1+ no-stats))))
12789 ;; count code lines
12790 (goto-char (point-min))
12791 (while (not (eobp))
12792 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12793 (setq no-code-lines (1+ no-code-lines)))
12794 (beginning-of-line 2))
12795 ;; count empty lines
12796 (goto-char (point-min))
12797 (while (and (re-search-forward "^\\s-*$" nil t)
12798 (not (eq (point) (point-max))))
12799 (if (match-string 1)
12800 (goto-char (match-end 1))
12801 (setq no-empty-lines (1+ no-empty-lines))
12802 (unless (eq (point) (point-max))
12803 (forward-char))))
12804 ;; count comment-only lines
12805 (goto-char (point-min))
12806 (while (re-search-forward "^\\s-*--.*" nil t)
12807 (if (match-string 1)
12808 (goto-char (match-end 1))
12809 (setq no-comm-lines (1+ no-comm-lines))))
12810 ;; count comments
12811 (goto-char (point-min))
12812 (while (re-search-forward "--.*" nil t)
12813 (if (match-string 1)
12814 (goto-char (match-end 1))
12815 (setq no-comments (1+ no-comments)))))
12816 ;; print results
12817 (message "\n\
12818 File statistics: \"%s\"\n\
12819 -----------------------\n\
12820 # statements : %5d\n\
12821 # code lines : %5d\n\
12822 # empty lines : %5d\n\
12823 # comment lines : %5d\n\
12824 # comments : %5d\n\
12825 # total lines : %5d\n\ "
12826 (buffer-file-name) no-stats no-code-lines no-empty-lines
12827 no-comm-lines no-comments no-lines)
12828 (unless vhdl-emacs-21 (vhdl-show-messages))))
12830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12831 ;; Help functions
12833 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12834 "Like `re-search-forward', but does not match within literals."
12835 (let (pos)
12836 (save-excursion
12837 (while (and (setq pos (re-search-forward regexp bound noerror count))
12838 (vhdl-in-literal))))
12839 (when pos (goto-char pos))
12840 pos))
12842 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12843 "Like `re-search-backward', but does not match within literals."
12844 (let (pos)
12845 (save-excursion
12846 (while (and (setq pos (re-search-backward regexp bound noerror count))
12847 (vhdl-in-literal))))
12848 (when pos (goto-char pos))
12849 pos))
12852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12853 ;;; Project
12854 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12856 (defun vhdl-set-project (name)
12857 "Set current project to NAME."
12858 (interactive
12859 (list (let ((completion-ignore-case t))
12860 (completing-read "Project name: " vhdl-project-alist nil t))))
12861 (cond ((equal name "")
12862 (setq vhdl-project nil)
12863 (message "Current VHDL project: None"))
12864 ((assoc name vhdl-project-alist)
12865 (setq vhdl-project name)
12866 (message "Current VHDL project: \"%s\"" name))
12868 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12869 (vhdl-speedbar-update-current-project))
12871 (defun vhdl-set-default-project ()
12872 "Set current project as default on startup."
12873 (interactive)
12874 (customize-set-variable 'vhdl-project vhdl-project)
12875 (customize-save-customized))
12877 (defun vhdl-toggle-project (name token indent)
12878 "Set current project to NAME or unset if NAME is current project."
12879 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12881 (defun vhdl-export-project (file-name)
12882 "Write project setup for current project."
12883 (interactive
12884 (let ((name (vhdl-resolve-env-variable
12885 (vhdl-replace-string
12886 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12887 (concat (subst-char-in-string
12888 ? ?_ (or (vhdl-project-p)
12889 (error "ERROR: No current project")))
12890 " " (user-login-name))))))
12891 (list (read-file-name
12892 "Write project file: "
12893 (when (file-name-absolute-p name) "") nil nil name))))
12894 (setq file-name (abbreviate-file-name file-name))
12895 (let ((orig-buffer (current-buffer)))
12896 (unless (file-exists-p (file-name-directory file-name))
12897 (make-directory (file-name-directory file-name) t))
12898 (if (not (file-writable-p file-name))
12899 (error "ERROR: File not writable: \"%s\"" file-name)
12900 (set-buffer (find-file-noselect file-name t t))
12901 (erase-buffer)
12902 (insert ";; -*- Emacs-Lisp -*-\n\n"
12903 ";;; " (file-name-nondirectory file-name)
12904 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12905 ";; Project : " vhdl-project "\n"
12906 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12907 (user-login-name) "\n\n\n"
12908 ";; project name\n"
12909 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12910 ";; project setup\n"
12911 "(aput 'vhdl-project-alist vhdl-project\n'")
12912 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12913 (insert ")\n")
12914 (save-buffer)
12915 (kill-buffer (current-buffer))
12916 (set-buffer orig-buffer))))
12918 (defun vhdl-import-project (file-name &optional auto not-make-current)
12919 "Read project setup and set current project."
12920 (interactive
12921 (let ((name (vhdl-resolve-env-variable
12922 (vhdl-replace-string
12923 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12924 (concat "" " " (user-login-name))))))
12925 (list (read-file-name
12926 "Read project file: " (when (file-name-absolute-p name) "") nil t
12927 (file-name-directory name)))))
12928 (when (file-exists-p file-name)
12929 (condition-case ()
12930 (let ((current-project vhdl-project))
12931 (load-file file-name)
12932 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12933 (adelete 'vhdl-project-alist vhdl-project)
12934 (error ""))
12935 (when not-make-current
12936 (setq vhdl-project current-project))
12937 (vhdl-update-mode-menu)
12938 (vhdl-speedbar-refresh)
12939 (unless not-make-current
12940 (message "Current VHDL project: \"%s\"%s"
12941 vhdl-project (if auto " (auto-loaded)" ""))))
12942 (error (vhdl-warning
12943 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12945 (defun vhdl-duplicate-project ()
12946 "Duplicate setup of current project."
12947 (interactive)
12948 (let ((new-name (read-from-minibuffer "New project name: "))
12949 (project-entry (aget vhdl-project-alist vhdl-project t)))
12950 (setq vhdl-project-alist
12951 (append vhdl-project-alist
12952 (list (cons new-name project-entry))))
12953 (vhdl-update-mode-menu)))
12955 (defun vhdl-auto-load-project ()
12956 "Automatically load project setup at startup."
12957 (let ((file-name-list vhdl-project-file-name)
12958 file-list list-length)
12959 (while file-name-list
12960 (setq file-list
12961 (append file-list
12962 (file-expand-wildcards
12963 (vhdl-resolve-env-variable
12964 (vhdl-replace-string
12965 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12966 (concat "\*" " " (user-login-name)))))))
12967 (setq list-length (or list-length (length file-list)))
12968 (setq file-name-list (cdr file-name-list)))
12969 (while file-list
12970 (vhdl-import-project (expand-file-name (car file-list)) t
12971 (not (> list-length 0)))
12972 (setq list-length (1- list-length))
12973 (setq file-list (cdr file-list)))))
12975 ;; automatically load project setup when idle after startup
12976 (when (memq 'startup vhdl-project-auto-load)
12977 (if noninteractive
12978 (vhdl-auto-load-project)
12979 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12982 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12983 ;;; Hideshow
12984 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12985 ;; (using `hideshow.el')
12987 (defconst vhdl-hs-start-regexp
12988 (concat
12989 "\\(^\\)\\s-*\\("
12990 ;; generic/port clause
12991 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
12992 ;; component
12993 "component\\>\\|"
12994 ;; component instantiation
12995 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
12996 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
12997 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
12998 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
12999 ;; subprogram
13000 "\\(function\\|procedure\\)\\>\\|"
13001 ;; process, block
13002 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13003 ;; configuration declaration
13004 "configuration\\>"
13005 "\\)")
13006 "Regexp to match start of construct to hide.")
13008 (defun vhdl-hs-forward-sexp-func (count)
13009 "Find end of construct to hide (for hideshow). Only searches forward."
13010 (let ((pos (point)))
13011 (vhdl-prepare-search-2
13012 (beginning-of-line)
13013 (cond
13014 ;; generic/port clause
13015 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13016 (goto-char (match-end 0))
13017 (backward-char)
13018 (forward-sexp))
13019 ;; component declaration
13020 ((looking-at "^\\s-*component\\>")
13021 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
13022 ;; component instantiation
13023 ((looking-at
13024 (concat
13025 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13026 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13027 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13028 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13029 (goto-char (match-end 0))
13030 (backward-char)
13031 (forward-sexp)
13032 (setq pos (point))
13033 (vhdl-forward-syntactic-ws)
13034 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13035 (goto-char (match-end 0))
13036 (backward-char)
13037 (forward-sexp)
13038 (setq pos (point)))
13039 (goto-char pos))
13040 ;; subprogram declaration/body
13041 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13042 (goto-char (match-end 0))
13043 (vhdl-forward-syntactic-ws)
13044 (when (looking-at "(")
13045 (forward-sexp))
13046 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
13047 (vhdl-in-literal)))
13048 ;; subprogram body
13049 (when (match-string 2)
13050 (re-search-forward "^\\s-*\\<begin\\>" nil t)
13051 (backward-word 1)
13052 (vhdl-forward-sexp)))
13053 ;; block (recursive)
13054 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13055 (goto-char (match-end 0))
13056 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
13057 (match-beginning 2))
13058 (vhdl-hs-forward-sexp-func count)))
13059 ;; process
13060 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13061 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
13062 ;; configuration declaration
13063 ((looking-at "^\\s-*configuration\\>")
13064 (forward-word 4)
13065 (vhdl-forward-sexp))
13066 (t (goto-char pos))))))
13068 (defun vhdl-hideshow-init ()
13069 "Initialize `hideshow'."
13070 (when vhdl-hideshow-menu
13071 (vhdl-hs-minor-mode 1)))
13073 (defun vhdl-hs-minor-mode (&optional arg)
13074 "Toggle hideshow minor mode and update menu bar."
13075 (interactive "P")
13076 (require 'hideshow)
13077 ;; check for hideshow version 5.x
13078 (if (not (boundp 'hs-block-start-mdata-select))
13079 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13080 ;; initialize hideshow
13081 (unless (assoc 'vhdl-mode hs-special-modes-alist)
13082 (setq hs-special-modes-alist
13083 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
13084 'vhdl-hs-forward-sexp-func nil)
13085 hs-special-modes-alist)))
13086 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
13087 (if vhdl-hide-all-init
13088 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
13089 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
13090 (hs-minor-mode arg)
13091 (force-mode-line-update))) ; hack to update menu bar
13094 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13095 ;;; Font locking
13096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13097 ;; (using `font-lock.el')
13099 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13100 ;; Help functions
13102 (defun vhdl-within-translate-off ()
13103 "Return point if within translate-off region, else nil."
13104 (and (save-excursion
13105 (re-search-backward
13106 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
13107 (equal "off" (match-string 1))
13108 (point)))
13110 (defun vhdl-start-translate-off (limit)
13111 "Return point before translate-off pragma if before LIMIT, else nil."
13112 (when (re-search-forward
13113 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
13114 (match-beginning 0)))
13116 (defun vhdl-end-translate-off (limit)
13117 "Return point after translate-on pragma if before LIMIT, else nil."
13118 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
13120 (defun vhdl-match-translate-off (limit)
13121 "Match a translate-off block, setting match-data and returning t, else nil."
13122 (when (< (point) limit)
13123 (let ((start (or (vhdl-within-translate-off)
13124 (vhdl-start-translate-off limit)))
13125 (case-fold-search t))
13126 (when start
13127 (let ((end (or (vhdl-end-translate-off limit) limit)))
13128 (set-match-data (list start end))
13129 (goto-char end))))))
13131 (defun vhdl-font-lock-match-item (limit)
13132 "Match, and move over, any declaration item after point. Adapted from
13133 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13134 (condition-case nil
13135 (save-restriction
13136 (narrow-to-region (point-min) limit)
13137 ;; match item
13138 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13139 (save-match-data
13140 (goto-char (match-end 1))
13141 ;; move to next item
13142 (if (looking-at "\\(\\s-*,\\)")
13143 (goto-char (match-end 1))
13144 (end-of-line) t))))
13145 (error t)))
13147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13148 ;; Syntax definitions
13150 (defconst vhdl-font-lock-syntactic-keywords
13151 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
13152 "Mark single quotes as having string quote syntax in 'c' instances.")
13154 (defvar vhdl-font-lock-keywords nil
13155 "Regular expressions to highlight in VHDL Mode.")
13157 (defvar vhdl-font-lock-keywords-0
13158 ;; set in `vhdl-font-lock-init' because dependent on user options
13159 "For consideration as a value of `vhdl-font-lock-keywords'.
13160 This does highlighting of template prompts and directives (pragmas).")
13162 (defvar vhdl-font-lock-keywords-1 nil
13163 ;; set in `vhdl-font-lock-init' because dependent on user options
13164 "For consideration as a value of `vhdl-font-lock-keywords'.
13165 This does highlighting of keywords and standard identifiers.")
13167 (defconst vhdl-font-lock-keywords-2
13168 (list
13169 ;; highlight names of units, subprograms, and components when declared
13170 (list
13171 (concat
13172 "^\\s-*\\("
13173 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
13174 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13175 "\\)\\s-+\\(\\w+\\)")
13176 5 'font-lock-function-name-face)
13178 ;; highlight entity names of architectures and configurations
13179 (list
13180 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13181 2 'font-lock-function-name-face)
13183 ;; highlight labels of common constructs
13184 (list
13185 (concat
13186 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13187 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13188 "postponed\\|process\\|"
13189 (when (vhdl-standard-p 'ams) "procedural\\|")
13190 "with\\|while"
13191 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13192 1 'font-lock-function-name-face)
13194 ;; highlight label and component name of component instantiations
13195 (list
13196 (concat
13197 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13198 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13199 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13201 ;; highlight label and instantiated unit of component instantiations
13202 (list
13203 (concat
13204 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13205 "\\(component\\|configuration\\|entity\\)\\s-+"
13206 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13207 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13208 '(5 font-lock-function-name-face nil t)
13209 '(7 font-lock-function-name-face nil t))
13211 ;; highlight names and labels at end of constructs
13212 (list
13213 (concat
13214 "^\\s-*end\\s-+\\(\\("
13215 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
13216 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
13217 "procedure\\|\\(postponed\\s-+\\)?process\\|"
13218 (when (vhdl-standard-p 'ams) "procedural\\|")
13219 "units"
13220 "\\)\\s-+\\)?\\(\\w*\\)")
13221 5 'font-lock-function-name-face)
13223 ;; highlight labels in exit and next statements
13224 (list
13225 (concat
13226 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13227 3 'font-lock-function-name-face)
13229 ;; highlight entity name in attribute specifications
13230 (list
13231 (concat
13232 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13233 1 'font-lock-function-name-face)
13235 ;; highlight labels in block and component specifications
13236 (list
13237 (concat
13238 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13239 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13240 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13242 ;; highlight names in library clauses
13243 (list "^\\s-*library\\>"
13244 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13246 ;; highlight names in use clauses
13247 (list
13248 (concat
13249 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13250 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13251 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
13252 '(7 font-lock-function-name-face nil t))
13254 ;; highlight attribute name in attribute declarations/specifications
13255 (list
13256 (concat
13257 "^\\s-*attribute\\s-+\\(\\w+\\)")
13258 1 'vhdl-font-lock-attribute-face)
13260 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13261 (list
13262 (concat
13263 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13264 5 'font-lock-type-face)
13266 ;; highlight signal/variable/constant declaration names
13267 (list "\\(:[^=]\\)"
13268 '(vhdl-font-lock-match-item
13269 (progn (goto-char (match-beginning 1))
13270 (skip-syntax-backward " ")
13271 (skip-syntax-backward "w_")
13272 (skip-syntax-backward " ")
13273 (while (= (preceding-char) ?,)
13274 (backward-char 1)
13275 (skip-syntax-backward " ")
13276 (skip-syntax-backward "w_")
13277 (skip-syntax-backward " ")))
13278 ; (skip-chars-backward "^-(\n\";")
13279 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13281 ;; highlight formal parameters in component instantiations and subprogram
13282 ;; calls
13283 (list "\\(=>\\)"
13284 '(vhdl-font-lock-match-item
13285 (progn (goto-char (match-beginning 1))
13286 (skip-syntax-backward " ")
13287 (while (= (preceding-char) ?\)) (backward-sexp))
13288 (skip-syntax-backward "w_")
13289 (skip-syntax-backward " ")
13290 (when (memq (preceding-char) '(?n ?N ?|))
13291 (goto-char (point-max))))
13292 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13294 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13295 ;; variables
13296 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13297 '(vhdl-font-lock-match-item
13298 (progn (goto-char (match-end 1)) (match-beginning 2))
13299 nil (1 font-lock-variable-name-face)))
13301 "For consideration as a value of `vhdl-font-lock-keywords'.
13302 This does context sensitive highlighting of names and labels.")
13304 (defvar vhdl-font-lock-keywords-3 nil
13305 ;; set in `vhdl-font-lock-init' because dependent on user options
13306 "For consideration as a value of `vhdl-font-lock-keywords'.
13307 This does highlighting of words with special syntax.")
13309 (defvar vhdl-font-lock-keywords-4 nil
13310 ;; set in `vhdl-font-lock-init' because dependent on user options
13311 "For consideration as a value of `vhdl-font-lock-keywords'.
13312 This does highlighting of additional reserved words.")
13314 (defconst vhdl-font-lock-keywords-5
13315 ;; background highlight translate-off regions
13316 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13317 "For consideration as a value of `vhdl-font-lock-keywords'.
13318 This does background highlighting of translate-off regions.")
13320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13321 ;; Font and color definitions
13323 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13324 "Face name to use for prompts.")
13326 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13327 "Face name to use for standardized attributes.")
13329 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13330 "Face name to use for standardized enumeration values.")
13332 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13333 "Face name to use for standardized functions and packages.")
13335 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13336 "Face name to use for directives.")
13338 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13339 "Face name to use for additional reserved words.")
13341 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13342 "Face name to use for translate-off regions.")
13344 ;; face names to use for words with special syntax.
13345 (let ((syntax-alist vhdl-special-syntax-alist)
13346 name)
13347 (while syntax-alist
13348 (setq name (vhdl-function-name
13349 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13350 (eval `(defvar ,name ',name
13351 ,(concat "Face name to use for "
13352 (nth 0 (car syntax-alist)) ".")))
13353 (setq syntax-alist (cdr syntax-alist))))
13355 (defgroup vhdl-highlight-faces nil
13356 "Faces for highlighting."
13357 :group 'vhdl-highlight)
13359 ;; add faces used from `font-lock'
13360 (custom-add-to-group
13361 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13362 (custom-add-to-group
13363 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13364 (custom-add-to-group
13365 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13366 (custom-add-to-group
13367 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13368 (custom-add-to-group
13369 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13370 (custom-add-to-group
13371 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13373 (defface vhdl-font-lock-prompt-face
13374 '((((min-colors 88) (class color) (background light))
13375 (:foreground "Red1" :bold t))
13376 (((class color) (background light)) (:foreground "Red" :bold t))
13377 (((class color) (background dark)) (:foreground "Pink" :bold t))
13378 (t (:inverse-video t)))
13379 "Font lock mode face used to highlight prompts."
13380 :group 'vhdl-highlight-faces)
13382 (defface vhdl-font-lock-attribute-face
13383 '((((class color) (background light)) (:foreground "Orchid"))
13384 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13385 (t (:italic t :bold t)))
13386 "Font lock mode face used to highlight standardized attributes."
13387 :group 'vhdl-highlight-faces)
13389 (defface vhdl-font-lock-enumvalue-face
13390 '((((class color) (background light)) (:foreground "SaddleBrown"))
13391 (((class color) (background dark)) (:foreground "BurlyWood"))
13392 (t (:italic t :bold t)))
13393 "Font lock mode face used to highlight standardized enumeration values."
13394 :group 'vhdl-highlight-faces)
13396 (defface vhdl-font-lock-function-face
13397 '((((class color) (background light)) (:foreground "Cyan4"))
13398 (((class color) (background dark)) (:foreground "Orchid1"))
13399 (t (:italic t :bold t)))
13400 "Font lock mode face used to highlight standardized functions and packages."
13401 :group 'vhdl-highlight-faces)
13403 (defface vhdl-font-lock-directive-face
13404 '((((class color) (background light)) (:foreground "CadetBlue"))
13405 (((class color) (background dark)) (:foreground "Aquamarine"))
13406 (t (:italic t :bold t)))
13407 "Font lock mode face used to highlight directives."
13408 :group 'vhdl-highlight-faces)
13410 (defface vhdl-font-lock-reserved-words-face
13411 '((((class color) (background light)) (:foreground "Orange" :bold t))
13412 (((min-colors 88) (class color) (background dark))
13413 (:foreground "Yellow1" :bold t))
13414 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13415 (t ()))
13416 "Font lock mode face used to highlight additional reserved words."
13417 :group 'vhdl-highlight-faces)
13419 (defface vhdl-font-lock-translate-off-face
13420 '((((class color) (background light)) (:background "LightGray"))
13421 (((class color) (background dark)) (:background "DimGray"))
13422 (t ()))
13423 "Font lock mode face used to background highlight translate-off regions."
13424 :group 'vhdl-highlight-faces)
13426 ;; font lock mode faces used to highlight words with special syntax.
13427 (let ((syntax-alist vhdl-special-syntax-alist))
13428 (while syntax-alist
13429 (eval `(defface ,(vhdl-function-name
13430 "vhdl-font-lock" (caar syntax-alist) "face")
13431 '((((class color) (background light))
13432 (:foreground ,(nth 2 (car syntax-alist))))
13433 (((class color) (background dark))
13434 (:foreground ,(nth 3 (car syntax-alist))))
13435 (t ()))
13436 ,(concat "Font lock mode face used to highlight "
13437 (nth 0 (car syntax-alist)) ".")
13438 :group 'vhdl-highlight-faces))
13439 (setq syntax-alist (cdr syntax-alist))))
13441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13442 ;; Font lock initialization
13444 (defun vhdl-font-lock-init ()
13445 "Initialize fontification."
13446 ;; highlight template prompts and directives
13447 (setq vhdl-font-lock-keywords-0
13448 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13449 vhdl-template-prompt-syntax ">\\)")
13450 2 'vhdl-font-lock-prompt-face t)
13451 (list (concat "--\\s-*"
13452 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13453 2 'vhdl-font-lock-directive-face t)
13454 ;; highlight c-preprocessor directives
13455 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13456 '(1 font-lock-builtin-face)
13457 '(3 font-lock-variable-name-face nil t))))
13458 ;; highlight keywords and standardized types, attributes, enumeration
13459 ;; values, and subprograms
13460 (setq vhdl-font-lock-keywords-1
13461 (list
13462 (list (concat "'" vhdl-attributes-regexp)
13463 1 'vhdl-font-lock-attribute-face)
13464 (list vhdl-types-regexp 1 'font-lock-type-face)
13465 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13466 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13467 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13468 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13469 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13470 ;; highlight words with special syntax.
13471 (setq vhdl-font-lock-keywords-3
13472 (let ((syntax-alist vhdl-special-syntax-alist)
13473 keywords)
13474 (while syntax-alist
13475 (setq keywords
13476 (cons
13477 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13478 (vhdl-function-name
13479 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13480 (nth 4 (car syntax-alist)))
13481 keywords))
13482 (setq syntax-alist (cdr syntax-alist)))
13483 keywords))
13484 ;; highlight additional reserved words
13485 (setq vhdl-font-lock-keywords-4
13486 (list (list vhdl-reserved-words-regexp 1
13487 'vhdl-font-lock-reserved-words-face)))
13488 ;; highlight everything together
13489 (setq vhdl-font-lock-keywords
13490 (append
13491 vhdl-font-lock-keywords-0
13492 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13493 (when (or vhdl-highlight-forbidden-words
13494 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13495 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13496 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13497 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13499 ;; initialize fontification for VHDL Mode
13500 (vhdl-font-lock-init)
13502 (defun vhdl-fontify-buffer ()
13503 "Re-initialize fontification and fontify buffer."
13504 (interactive)
13505 (setq font-lock-defaults
13506 `(vhdl-font-lock-keywords
13507 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13508 beginning-of-line))
13509 (when (fboundp 'font-lock-unset-defaults)
13510 (font-lock-unset-defaults)) ; not implemented in XEmacs
13511 (font-lock-set-defaults)
13512 (font-lock-mode nil)
13513 (font-lock-mode t))
13515 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13516 ;; Initialization for PostScript printing
13518 (defun vhdl-ps-print-settings ()
13519 "Initialize custom face and page settings for PostScript printing."
13520 ;; define custom face settings
13521 (unless (or (not vhdl-print-customize-faces)
13522 ps-print-color-p)
13523 (set (make-local-variable 'ps-bold-faces)
13524 '(font-lock-keyword-face
13525 font-lock-type-face
13526 vhdl-font-lock-attribute-face
13527 vhdl-font-lock-enumvalue-face
13528 vhdl-font-lock-directive-face))
13529 (set (make-local-variable 'ps-italic-faces)
13530 '(font-lock-comment-face
13531 font-lock-function-name-face
13532 font-lock-type-face
13533 vhdl-font-lock-attribute-face
13534 vhdl-font-lock-enumvalue-face
13535 vhdl-font-lock-directive-face))
13536 (set (make-local-variable 'ps-underlined-faces)
13537 '(font-lock-string-face))
13538 (setq ps-always-build-face-reference t))
13539 ;; define page settings, so that a line containing 79 characters (default)
13540 ;; fits into one column
13541 (when vhdl-print-two-column
13542 (set (make-local-variable 'ps-landscape-mode) t)
13543 (set (make-local-variable 'ps-number-of-columns) 2)
13544 (set (make-local-variable 'ps-font-size) 7.0)
13545 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13546 (set (make-local-variable 'ps-header-font-size) 9.0)
13547 (set (make-local-variable 'ps-header-offset) 12.0)
13548 (when (eq ps-paper-type 'letter)
13549 (set (make-local-variable 'ps-inter-column) 40.0)
13550 (set (make-local-variable 'ps-left-margin) 40.0)
13551 (set (make-local-variable 'ps-right-margin) 40.0))))
13553 (defun vhdl-ps-print-init ()
13554 "Initialize PostScript printing."
13555 (if (featurep 'xemacs)
13556 (when (boundp 'ps-print-color-p)
13557 (vhdl-ps-print-settings))
13558 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13559 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13562 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13563 ;;; Hierarchy browser (using `speedbar.el')
13564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13565 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13566 ;; directory by using the speedbar.
13568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13569 ;; Variables
13571 (defvar vhdl-entity-alist nil
13572 "Cache with entities and corresponding architectures for each
13573 project/directory.")
13574 ;; structure: (parenthesized expression means list of such entries)
13575 ;; (cache-key
13576 ;; (ent-key ent-name ent-file ent-line
13577 ;; (arch-key arch-name arch-file arch-line
13578 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13579 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13580 ;; (lib-name pack-key))
13581 ;; mra-key (lib-name pack-key))
13583 (defvar vhdl-config-alist nil
13584 "Cache with configurations for each project/directory.")
13585 ;; structure: (parenthesized expression means list of such entries)
13586 ;; (cache-key
13587 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13588 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13589 ;; inst-conf-key inst-lib-key)
13590 ;; (lib-name pack-key)))
13592 (defvar vhdl-package-alist nil
13593 "Cache with packages for each project/directory.")
13594 ;; structure: (parenthesized expression means list of such entries)
13595 ;; (cache-key
13596 ;; (pack-key pack-name pack-file pack-line
13597 ;; (comp-key comp-name comp-file comp-line)
13598 ;; (func-key func-name func-file func-line)
13599 ;; (lib-name pack-key)
13600 ;; pack-body-file pack-body-line
13601 ;; (func-key func-name func-body-file func-body-line)
13602 ;; (lib-name pack-key)))
13604 (defvar vhdl-ent-inst-alist nil
13605 "Cache with instantiated entities for each project/directory.")
13606 ;; structure: (parenthesized expression means list of such entries)
13607 ;; (cache-key (inst-ent-key))
13609 (defvar vhdl-file-alist nil
13610 "Cache with design units in each file for each project/directory.")
13611 ;; structure: (parenthesized expression means list of such entries)
13612 ;; (cache-key
13613 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13614 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13616 (defvar vhdl-directory-alist nil
13617 "Cache with source directories for each project.")
13618 ;; structure: (parenthesized expression means list of such entries)
13619 ;; (cache-key (directory))
13621 (defvar vhdl-speedbar-shown-unit-alist nil
13622 "Alist of design units simultaneously open in the current speedbar for each
13623 directory and project.")
13625 (defvar vhdl-speedbar-shown-project-list nil
13626 "List of projects simultaneously open in the current speedbar.")
13628 (defvar vhdl-updated-project-list nil
13629 "List of projects and directories with updated files.")
13631 (defvar vhdl-modified-file-list nil
13632 "List of modified files to be rescanned for hierarchy updating.")
13634 (defvar vhdl-speedbar-hierarchy-depth 0
13635 "Depth of instantiation hierarchy to display.")
13637 (defvar vhdl-speedbar-show-projects nil
13638 "Non-nil means project hierarchy is displayed in speedbar, directory
13639 hierarchy otherwise.")
13641 (defun vhdl-get-end-of-unit ()
13642 "Return position of end of current unit."
13643 (let ((pos (point)))
13644 (save-excursion
13645 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13646 (save-excursion
13647 (goto-char (match-beginning 0))
13648 (vhdl-backward-syntactic-ws)
13649 (and (/= (preceding-char) ?\;) (not (bobp))))))
13650 (re-search-backward "^[ \t]*end\\>" pos 1)
13651 (point))))
13653 (defun vhdl-match-string-downcase (num &optional string)
13654 "Like `match-string-no-properties' with down-casing."
13655 (let ((match (match-string-no-properties num string)))
13656 (and match (downcase match))))
13659 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13660 ;; Scan functions
13662 (defun vhdl-scan-context-clause ()
13663 "Scan the context clause that precedes a design unit."
13664 (let (lib-alist)
13665 (save-excursion
13666 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13667 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13668 (equal "USE" (upcase (match-string 1))))
13669 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13670 (push (cons (match-string-no-properties 1)
13671 (vhdl-match-string-downcase 2))
13672 lib-alist)))))
13673 lib-alist))
13675 (defun vhdl-scan-directory-contents (name &optional project update num-string
13676 non-final)
13677 "Scan contents of VHDL files in directory or file pattern NAME."
13678 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13679 ; (unless (file-directory-p (match-string 1 name))
13680 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13681 (let* ((dir-name (match-string 1 name))
13682 (file-pattern (match-string 2 name))
13683 (is-directory (= 0 (length file-pattern)))
13684 (file-list
13685 (if update
13686 (list name)
13687 (if is-directory
13688 (vhdl-get-source-files t dir-name)
13689 (vhdl-directory-files
13690 dir-name t (wildcard-to-regexp file-pattern)))))
13691 (key (or project dir-name))
13692 (file-exclude-regexp
13693 (or (nth 3 (aget vhdl-project-alist project)) ""))
13694 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13695 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13696 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13697 ent-alist conf-alist pack-alist ent-inst-list file-alist
13698 tmp-list tmp-entry no-files files-exist big-files)
13699 (when (or project update)
13700 (setq ent-alist (aget vhdl-entity-alist key t)
13701 conf-alist (aget vhdl-config-alist key t)
13702 pack-alist (aget vhdl-package-alist key t)
13703 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13704 file-alist (aget vhdl-file-alist key t)))
13705 (when (and (not is-directory) (null file-list))
13706 (message "No such file: \"%s\"" name))
13707 (setq files-exist file-list)
13708 (when file-list
13709 (setq no-files (length file-list))
13710 (message "Scanning %s %s\"%s\"..."
13711 (if is-directory "directory" "files") (or num-string "") name)
13712 ;; exclude files
13713 (unless (equal file-exclude-regexp "")
13714 (let ((case-fold-search nil)
13715 file-tmp-list)
13716 (while file-list
13717 (unless (string-match file-exclude-regexp (car file-list))
13718 (push (car file-list) file-tmp-list))
13719 (setq file-list (cdr file-list)))
13720 (setq file-list (nreverse file-tmp-list))))
13721 ;; do for all files
13722 (while file-list
13723 (unless noninteractive
13724 (message "Scanning %s %s\"%s\"... (%2d%s)"
13725 (if is-directory "directory" "files")
13726 (or num-string "") name
13727 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13728 (let ((file-name (abbreviate-file-name (car file-list)))
13729 ent-list arch-list arch-ent-list conf-list
13730 pack-list pack-body-list inst-list inst-ent-list)
13731 ;; scan file
13732 (vhdl-visit-file
13733 file-name nil
13734 (vhdl-prepare-search-2
13735 (save-excursion
13736 ;; scan for design units
13737 (if (and limit-design-file-size
13738 (< limit-design-file-size (buffer-size)))
13739 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13740 (setq big-files t))
13741 ;; scan for entities
13742 (goto-char (point-min))
13743 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13744 (let* ((ent-name (match-string-no-properties 1))
13745 (ent-key (downcase ent-name))
13746 (ent-entry (aget ent-alist ent-key t))
13747 (lib-alist (vhdl-scan-context-clause)))
13748 (if (nth 1 ent-entry)
13749 (vhdl-warning-when-idle
13750 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13751 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13752 file-name (vhdl-current-line))
13753 (push ent-key ent-list)
13754 (aput 'ent-alist ent-key
13755 (list ent-name file-name (vhdl-current-line)
13756 (nth 3 ent-entry) (nth 4 ent-entry)
13757 lib-alist)))))
13758 ;; scan for architectures
13759 (goto-char (point-min))
13760 (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)
13761 (let* ((arch-name (match-string-no-properties 1))
13762 (arch-key (downcase arch-name))
13763 (ent-name (match-string-no-properties 2))
13764 (ent-key (downcase ent-name))
13765 (ent-entry (aget ent-alist ent-key t))
13766 (arch-alist (nth 3 ent-entry))
13767 (arch-entry (aget arch-alist arch-key t))
13768 (lib-arch-alist (vhdl-scan-context-clause)))
13769 (if arch-entry
13770 (vhdl-warning-when-idle
13771 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13772 arch-name ent-name (nth 1 arch-entry)
13773 (nth 2 arch-entry) file-name (vhdl-current-line))
13774 (setq arch-list (cons arch-key arch-list)
13775 arch-ent-list (cons ent-key arch-ent-list))
13776 (aput 'arch-alist arch-key
13777 (list arch-name file-name (vhdl-current-line) nil
13778 lib-arch-alist))
13779 (aput 'ent-alist ent-key
13780 (list (or (nth 0 ent-entry) ent-name)
13781 (nth 1 ent-entry) (nth 2 ent-entry)
13782 (vhdl-sort-alist arch-alist)
13783 arch-key (nth 5 ent-entry))))))
13784 ;; scan for configurations
13785 (goto-char (point-min))
13786 (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)
13787 (let* ((conf-name (match-string-no-properties 1))
13788 (conf-key (downcase conf-name))
13789 (conf-entry (aget conf-alist conf-key t))
13790 (ent-name (match-string-no-properties 2))
13791 (ent-key (downcase ent-name))
13792 (lib-alist (vhdl-scan-context-clause))
13793 (conf-line (vhdl-current-line))
13794 (end-of-unit (vhdl-get-end-of-unit))
13795 arch-key comp-conf-list inst-key-list
13796 inst-comp-key inst-ent-key inst-arch-key
13797 inst-conf-key inst-lib-key)
13798 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13799 (setq arch-key (vhdl-match-string-downcase 1)))
13800 (if conf-entry
13801 (vhdl-warning-when-idle
13802 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13803 conf-name ent-name (nth 1 conf-entry)
13804 (nth 2 conf-entry) file-name conf-line)
13805 (push conf-key conf-list)
13806 ;; scan for subconfigurations and subentities
13807 (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)
13808 (setq inst-comp-key (vhdl-match-string-downcase 3)
13809 inst-key-list (split-string
13810 (vhdl-match-string-downcase 1)
13811 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13812 (vhdl-forward-syntactic-ws)
13813 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13814 (setq
13815 inst-lib-key (vhdl-match-string-downcase 3)
13816 inst-ent-key (and (match-string 2)
13817 (vhdl-match-string-downcase 4))
13818 inst-arch-key (and (match-string 2)
13819 (vhdl-match-string-downcase 6))
13820 inst-conf-key (and (not (match-string 2))
13821 (vhdl-match-string-downcase 4)))
13822 (while inst-key-list
13823 (setq comp-conf-list
13824 (cons (list (car inst-key-list)
13825 inst-comp-key inst-ent-key
13826 inst-arch-key inst-conf-key
13827 inst-lib-key)
13828 comp-conf-list))
13829 (setq inst-key-list (cdr inst-key-list)))))
13830 (aput 'conf-alist conf-key
13831 (list conf-name file-name conf-line ent-key
13832 arch-key comp-conf-list lib-alist)))))
13833 ;; scan for packages
13834 (goto-char (point-min))
13835 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13836 (let* ((pack-name (match-string-no-properties 2))
13837 (pack-key (downcase pack-name))
13838 (is-body (match-string-no-properties 1))
13839 (pack-entry (aget pack-alist pack-key t))
13840 (pack-line (vhdl-current-line))
13841 (end-of-unit (vhdl-get-end-of-unit))
13842 comp-name func-name comp-alist func-alist lib-alist)
13843 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13844 (vhdl-warning-when-idle
13845 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13846 (if is-body " body" "") pack-name
13847 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13848 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13849 file-name (vhdl-current-line))
13850 ;; scan for context clauses
13851 (setq lib-alist (vhdl-scan-context-clause))
13852 ;; scan for component and subprogram declarations/bodies
13853 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13854 (if (equal (upcase (match-string 1)) "COMPONENT")
13855 (setq comp-name (match-string-no-properties 2)
13856 comp-alist
13857 (cons (list (downcase comp-name) comp-name
13858 file-name (vhdl-current-line))
13859 comp-alist))
13860 (setq func-name (match-string-no-properties 2)
13861 func-alist
13862 (cons (list (downcase func-name) func-name
13863 file-name (vhdl-current-line))
13864 func-alist))))
13865 (setq func-alist (nreverse func-alist))
13866 (setq comp-alist (nreverse comp-alist))
13867 (if is-body
13868 (push pack-key pack-body-list)
13869 (push pack-key pack-list))
13870 (aput
13871 'pack-alist pack-key
13872 (if is-body
13873 (list (or (nth 0 pack-entry) pack-name)
13874 (nth 1 pack-entry) (nth 2 pack-entry)
13875 (nth 3 pack-entry) (nth 4 pack-entry)
13876 (nth 5 pack-entry)
13877 file-name pack-line func-alist lib-alist)
13878 (list pack-name file-name pack-line
13879 comp-alist func-alist lib-alist
13880 (nth 6 pack-entry) (nth 7 pack-entry)
13881 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13882 ;; scan for hierarchy
13883 (if (and limit-hier-file-size
13884 (< limit-hier-file-size (buffer-size)))
13885 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13886 (setq big-files t))
13887 ;; scan for architectures
13888 (goto-char (point-min))
13889 (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)
13890 (let* ((ent-name (match-string-no-properties 2))
13891 (ent-key (downcase ent-name))
13892 (arch-name (match-string-no-properties 1))
13893 (arch-key (downcase arch-name))
13894 (ent-entry (aget ent-alist ent-key t))
13895 (arch-alist (nth 3 ent-entry))
13896 (arch-entry (aget arch-alist arch-key t))
13897 (beg-of-unit (point))
13898 (end-of-unit (vhdl-get-end-of-unit))
13899 (inst-no 0)
13900 inst-alist inst-path)
13901 ;; scan for contained instantiations
13902 (while (and (re-search-forward
13903 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
13904 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
13905 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
13906 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
13907 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13908 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13909 (or (not limit-hier-inst-no)
13910 (<= (setq inst-no (1+ inst-no))
13911 limit-hier-inst-no)))
13912 (cond
13913 ;; block/generate beginning found
13914 ((match-string 14)
13915 (setq inst-path
13916 (cons (match-string-no-properties 1) inst-path)))
13917 ;; block/generate end found
13918 ((match-string 16)
13919 (setq inst-path (cdr inst-path)))
13920 ;; instantiation found
13922 (let* ((inst-name (match-string-no-properties 1))
13923 (inst-key (downcase inst-name))
13924 (inst-comp-name
13925 (or (match-string-no-properties 3)
13926 (match-string-no-properties 6)))
13927 (inst-ent-key
13928 (or (and (match-string 8)
13929 (vhdl-match-string-downcase 11))
13930 (and inst-comp-name
13931 (downcase inst-comp-name))))
13932 (inst-arch-key (vhdl-match-string-downcase 13))
13933 (inst-conf-key
13934 (and (not (match-string 8))
13935 (vhdl-match-string-downcase 11)))
13936 (inst-lib-key (vhdl-match-string-downcase 10)))
13937 (goto-char (match-end 1))
13938 (setq inst-list (cons inst-key inst-list)
13939 inst-ent-list
13940 (cons inst-ent-key inst-ent-list))
13941 (setq inst-alist
13942 (append
13943 inst-alist
13944 (list (list inst-key inst-name file-name
13945 (vhdl-current-line) inst-comp-name
13946 inst-ent-key inst-arch-key
13947 inst-conf-key inst-lib-key
13948 (reverse inst-path)))))))))
13949 ;; scan for contained configuration specifications
13950 (goto-char beg-of-unit)
13951 (while (re-search-forward
13952 (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]*\\)*"
13953 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
13954 (let* ((inst-comp-name (match-string-no-properties 3))
13955 (inst-ent-key
13956 (and (match-string 6)
13957 (vhdl-match-string-downcase 9)))
13958 (inst-arch-key (vhdl-match-string-downcase 11))
13959 (inst-conf-key
13960 (and (not (match-string 6))
13961 (vhdl-match-string-downcase 9)))
13962 (inst-lib-key (vhdl-match-string-downcase 8))
13963 (inst-key-list
13964 (split-string (vhdl-match-string-downcase 1)
13965 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13966 (tmp-inst-alist inst-alist)
13967 inst-entry)
13968 (while tmp-inst-alist
13969 (when (and (or (equal "all" (car inst-key-list))
13970 (member (nth 0 (car tmp-inst-alist))
13971 inst-key-list))
13972 (equal
13973 (downcase
13974 (or (nth 4 (car tmp-inst-alist)) ""))
13975 (downcase inst-comp-name)))
13976 (setq inst-entry (car tmp-inst-alist))
13977 (setq inst-ent-list
13978 (cons (or inst-ent-key (nth 5 inst-entry))
13979 (vhdl-delete
13980 (nth 5 inst-entry) inst-ent-list)))
13981 (setq inst-entry
13982 (list (nth 0 inst-entry) (nth 1 inst-entry)
13983 (nth 2 inst-entry) (nth 3 inst-entry)
13984 (nth 4 inst-entry)
13985 (or inst-ent-key (nth 5 inst-entry))
13986 (or inst-arch-key (nth 6 inst-entry))
13987 inst-conf-key inst-lib-key))
13988 (setcar tmp-inst-alist inst-entry))
13989 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13990 ;; save in cache
13991 (aput 'arch-alist arch-key
13992 (list (nth 0 arch-entry) (nth 1 arch-entry)
13993 (nth 2 arch-entry) inst-alist
13994 (nth 4 arch-entry)))
13995 (aput 'ent-alist ent-key
13996 (list (nth 0 ent-entry) (nth 1 ent-entry)
13997 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13998 (nth 4 ent-entry) (nth 5 ent-entry)))
13999 (when (and limit-hier-inst-no
14000 (> inst-no limit-hier-inst-no))
14001 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
14002 (setq big-files t))
14003 (goto-char end-of-unit))))
14004 ;; remember design units for this file
14005 (aput 'file-alist file-name
14006 (list ent-list arch-list arch-ent-list conf-list
14007 pack-list pack-body-list inst-list inst-ent-list))
14008 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
14009 (setq file-list (cdr file-list))))
14010 (when (or (and (not project) files-exist)
14011 (and project (not non-final)))
14012 ;; consistency checks:
14013 ;; check whether each architecture has a corresponding entity
14014 (setq tmp-list ent-alist)
14015 (while tmp-list
14016 (when (null (nth 2 (car tmp-list)))
14017 (setq tmp-entry (car (nth 4 (car tmp-list))))
14018 (vhdl-warning-when-idle
14019 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14020 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
14021 (nth 3 tmp-entry)))
14022 (setq tmp-list (cdr tmp-list)))
14023 ;; check whether configuration has a corresponding entity/architecture
14024 (setq tmp-list conf-alist)
14025 (while tmp-list
14026 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
14027 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
14028 (setq tmp-entry (car tmp-list))
14029 (vhdl-warning-when-idle
14030 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14031 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
14032 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14033 (setq tmp-entry (car tmp-list))
14034 (vhdl-warning-when-idle
14035 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14036 (nth 1 tmp-entry) (nth 4 tmp-entry)
14037 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14038 (setq tmp-list (cdr tmp-list)))
14039 ;; check whether each package body has a package declaration
14040 (setq tmp-list pack-alist)
14041 (while tmp-list
14042 (when (null (nth 2 (car tmp-list)))
14043 (setq tmp-entry (car tmp-list))
14044 (vhdl-warning-when-idle
14045 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14046 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
14047 (setq tmp-list (cdr tmp-list)))
14048 ;; sort lists
14049 (setq ent-alist (vhdl-sort-alist ent-alist))
14050 (setq conf-alist (vhdl-sort-alist conf-alist))
14051 (setq pack-alist (vhdl-sort-alist pack-alist))
14052 ;; remember updated directory/project
14053 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
14054 ;; clear directory alists
14055 (unless project
14056 (adelete 'vhdl-entity-alist key)
14057 (adelete 'vhdl-config-alist key)
14058 (adelete 'vhdl-package-alist key)
14059 (adelete 'vhdl-ent-inst-alist key)
14060 (adelete 'vhdl-file-alist key))
14061 ;; put directory contents into cache
14062 (aput 'vhdl-entity-alist key ent-alist)
14063 (aput 'vhdl-config-alist key conf-alist)
14064 (aput 'vhdl-package-alist key pack-alist)
14065 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
14066 (aput 'vhdl-file-alist key file-alist)
14067 ;; final messages
14068 (message "Scanning %s %s\"%s\"...done"
14069 (if is-directory "directory" "files") (or num-string "") name)
14070 (unless project (message "Scanning directory...done"))
14071 (when big-files
14072 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14073 ;; save cache when scanned non-interactively
14074 (when (or (not project) (not non-final))
14075 (when (and noninteractive vhdl-speedbar-save-cache)
14076 (vhdl-save-cache key)))
14079 (defun vhdl-scan-project-contents (project)
14080 "Scan the contents of all VHDL files found in the directories and files
14081 of PROJECT."
14082 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
14083 (default-dir (vhdl-resolve-env-variable
14084 (nth 1 (aget vhdl-project-alist project))))
14085 (file-exclude-regexp
14086 (or (nth 3 (aget vhdl-project-alist project)) ""))
14087 dir-list-tmp dir dir-name num-dir act-dir recursive)
14088 ;; clear project alists
14089 (adelete 'vhdl-entity-alist project)
14090 (adelete 'vhdl-config-alist project)
14091 (adelete 'vhdl-package-alist project)
14092 (adelete 'vhdl-ent-inst-alist project)
14093 (adelete 'vhdl-file-alist project)
14094 ;; expand directory names by default-directory
14095 (message "Collecting source files...")
14096 (while dir-list
14097 (setq dir (vhdl-resolve-env-variable (car dir-list)))
14098 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
14099 (setq recursive (match-string 1 dir)
14100 dir-name (match-string 3 dir))
14101 (setq dir-list-tmp
14102 (cons (concat recursive
14103 (if (file-name-absolute-p dir-name) "" default-dir)
14104 dir-name)
14105 dir-list-tmp))
14106 (setq dir-list (cdr dir-list)))
14107 ;; resolve path wildcards
14108 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
14109 ;; expand directories
14110 (while dir-list-tmp
14111 (setq dir (car dir-list-tmp))
14112 ;; get subdirectories
14113 (if (string-match "-r \\(.*[/\\]\\)" dir)
14114 (setq dir-list (append dir-list (vhdl-get-subdirs
14115 (match-string 1 dir))))
14116 (setq dir-list (append dir-list (list dir))))
14117 (setq dir-list-tmp (cdr dir-list-tmp)))
14118 ;; exclude files
14119 (unless (equal file-exclude-regexp "")
14120 (let ((case-fold-search nil))
14121 (while dir-list
14122 (unless (string-match file-exclude-regexp (car dir-list))
14123 (push (car dir-list) dir-list-tmp))
14124 (setq dir-list (cdr dir-list)))
14125 (setq dir-list (nreverse dir-list-tmp))))
14126 (message "Collecting source files...done")
14127 ;; scan for design units for each directory in DIR-LIST
14128 (setq dir-list-tmp nil
14129 num-dir (length dir-list)
14130 act-dir 1)
14131 (while dir-list
14132 (setq dir-name (abbreviate-file-name
14133 (expand-file-name (car dir-list))))
14134 (vhdl-scan-directory-contents dir-name project nil
14135 (format "(%s/%s) " act-dir num-dir)
14136 (cdr dir-list))
14137 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
14138 (setq dir-list (cdr dir-list)
14139 act-dir (1+ act-dir)))
14140 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
14141 (message "Scanning project \"%s\"...done" project)))
14143 (defun vhdl-update-file-contents (file-name)
14144 "Update hierarchy information by contents of current buffer."
14145 (setq file-name (abbreviate-file-name file-name))
14146 (let* ((dir-name (file-name-directory file-name))
14147 (directory-alist vhdl-directory-alist)
14148 updated)
14149 (while directory-alist
14150 (when (member dir-name (nth 1 (car directory-alist)))
14151 (let* ((vhdl-project (nth 0 (car directory-alist)))
14152 (project (vhdl-project-p))
14153 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
14154 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
14155 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
14156 (ent-inst-list (car (aget vhdl-ent-inst-alist
14157 (or project dir-name) t)))
14158 (file-alist (aget vhdl-file-alist (or project dir-name) t))
14159 (file-entry (aget file-alist file-name t))
14160 (ent-list (nth 0 file-entry))
14161 (arch-list (nth 1 file-entry))
14162 (arch-ent-list (nth 2 file-entry))
14163 (conf-list (nth 3 file-entry))
14164 (pack-list (nth 4 file-entry))
14165 (pack-body-list (nth 5 file-entry))
14166 (inst-ent-list (nth 7 file-entry))
14167 (cache-key (or project dir-name))
14168 arch-alist key ent-key entry)
14169 ;; delete design units previously contained in this file:
14170 ;; entities
14171 (while ent-list
14172 (setq key (car ent-list)
14173 entry (aget ent-alist key t))
14174 (when (equal file-name (nth 1 entry))
14175 (if (nth 3 entry)
14176 (aput 'ent-alist key
14177 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14178 (adelete 'ent-alist key)))
14179 (setq ent-list (cdr ent-list)))
14180 ;; architectures
14181 (while arch-list
14182 (setq key (car arch-list)
14183 ent-key (car arch-ent-list)
14184 entry (aget ent-alist ent-key t)
14185 arch-alist (nth 3 entry))
14186 (when (equal file-name (nth 1 (aget arch-alist key t)))
14187 (adelete 'arch-alist key)
14188 (if (or (nth 1 entry) arch-alist)
14189 (aput 'ent-alist ent-key
14190 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14191 arch-alist (nth 4 entry) (nth 5 entry)))
14192 (adelete 'ent-alist ent-key)))
14193 (setq arch-list (cdr arch-list)
14194 arch-ent-list (cdr arch-ent-list)))
14195 ;; configurations
14196 (while conf-list
14197 (setq key (car conf-list))
14198 (when (equal file-name (nth 1 (aget conf-alist key t)))
14199 (adelete 'conf-alist key))
14200 (setq conf-list (cdr conf-list)))
14201 ;; package declarations
14202 (while pack-list
14203 (setq key (car pack-list)
14204 entry (aget pack-alist key t))
14205 (when (equal file-name (nth 1 entry))
14206 (if (nth 6 entry)
14207 (aput 'pack-alist key
14208 (list (nth 0 entry) nil nil nil nil nil
14209 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14210 (nth 9 entry)))
14211 (adelete 'pack-alist key)))
14212 (setq pack-list (cdr pack-list)))
14213 ;; package bodies
14214 (while pack-body-list
14215 (setq key (car pack-body-list)
14216 entry (aget pack-alist key t))
14217 (when (equal file-name (nth 6 entry))
14218 (if (nth 1 entry)
14219 (aput 'pack-alist key
14220 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14221 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14222 nil nil nil nil))
14223 (adelete 'pack-alist key)))
14224 (setq pack-body-list (cdr pack-body-list)))
14225 ;; instantiated entities
14226 (while inst-ent-list
14227 (setq ent-inst-list
14228 (vhdl-delete (car inst-ent-list) ent-inst-list))
14229 (setq inst-ent-list (cdr inst-ent-list)))
14230 ;; update caches
14231 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
14232 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
14233 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
14234 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14235 ;; scan file
14236 (vhdl-scan-directory-contents file-name project t)
14237 (when (or (and vhdl-speedbar-show-projects project)
14238 (and (not vhdl-speedbar-show-projects) (not project)))
14239 (vhdl-speedbar-refresh project))
14240 (setq updated t)))
14241 (setq directory-alist (cdr directory-alist)))
14242 updated))
14244 (defun vhdl-update-hierarchy ()
14245 "Update directory and hierarchy information in speedbar."
14246 (let ((file-list (reverse vhdl-modified-file-list))
14247 updated)
14248 (when (and vhdl-speedbar-update-on-saving file-list)
14249 (while file-list
14250 (setq updated
14251 (or (vhdl-update-file-contents (car file-list))
14252 updated))
14253 (setq file-list (cdr file-list)))
14254 (setq vhdl-modified-file-list nil)
14255 (vhdl-speedbar-update-current-unit)
14256 (when updated (message "Updating hierarchy...done")))))
14258 ;; structure (parenthesized expression means list of such entries)
14259 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14260 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14261 ;; comp-lib-name level)
14262 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14263 conf-inst-alist level indent
14264 &optional include-top ent-hier)
14265 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14266 entity ENT-KEY."
14267 (let* ((ent-entry (aget ent-alist ent-key t))
14268 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
14269 (cdar (last (nth 3 ent-entry)))))
14270 (inst-alist (nth 3 arch-entry))
14271 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14272 hier-list subcomp-list tmp-list inst-key inst-comp-name
14273 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14274 (when (= level 0) (message "Extract design hierarchy..."))
14275 (when include-top
14276 (setq level (1+ level)))
14277 (when (member ent-key ent-hier)
14278 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14279 ;; check configured architecture (already checked during scanning)
14280 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
14281 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
14282 ;; process all instances
14283 (while inst-alist
14284 (setq inst-entry (car inst-alist)
14285 inst-key (nth 0 inst-entry)
14286 inst-comp-name (nth 4 inst-entry)
14287 inst-conf-key (nth 7 inst-entry))
14288 ;; search entry in configuration's instantiations list
14289 (setq tmp-list conf-inst-alist)
14290 (while (and tmp-list
14291 (not (and (member (nth 0 (car tmp-list))
14292 (list "all" inst-key))
14293 (equal (nth 1 (car tmp-list))
14294 (downcase (or inst-comp-name ""))))))
14295 (setq tmp-list (cdr tmp-list)))
14296 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14297 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
14298 (when (and inst-conf-key (not inst-conf-entry))
14299 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14300 ;; determine entity
14301 (setq inst-ent-key
14302 (or (nth 2 (car tmp-list)) ; from configuration
14303 (nth 3 inst-conf-entry) ; from subconfiguration
14304 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
14305 ; from configuration spec.
14306 (nth 5 inst-entry))) ; from direct instantiation
14307 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
14308 ;; determine architecture
14309 (setq inst-arch-key
14310 (or (nth 3 (car tmp-list)) ; from configuration
14311 (nth 4 inst-conf-entry) ; from subconfiguration
14312 (nth 6 inst-entry) ; from direct instantiation
14313 (nth 4 (aget conf-alist (nth 7 inst-entry)))
14314 ; from configuration spec.
14315 (nth 4 inst-ent-entry) ; MRA
14316 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14317 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
14318 ;; set library
14319 (setq inst-lib-key
14320 (or (nth 5 (car tmp-list)) ; from configuration
14321 (nth 8 inst-entry))) ; from direct instantiation
14322 ;; gather information for this instance
14323 (setq comp-entry
14324 (list (nth 1 inst-entry)
14325 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14326 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14327 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14328 (or (nth 0 inst-arch-entry) inst-arch-key)
14329 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14330 (or (nth 0 inst-conf-entry) inst-conf-key)
14331 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14332 inst-lib-key level))
14333 ;; get subcomponent hierarchy
14334 (setq subcomp-list (vhdl-get-hierarchy
14335 ent-alist conf-alist
14336 inst-ent-key inst-arch-key inst-conf-key
14337 (nth 5 inst-conf-entry)
14338 (1+ level) indent nil (cons ent-key ent-hier)))
14339 ;; add to list
14340 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14341 (setq inst-alist (cdr inst-alist)))
14342 (when include-top
14343 (setq hier-list
14344 (cons (list nil nil (nth 0 ent-entry)
14345 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14346 (nth 0 arch-entry)
14347 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14348 nil nil
14349 nil (1- level))
14350 hier-list)))
14351 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14352 hier-list))
14354 (defun vhdl-get-instantiations (ent-key indent)
14355 "Get all instantiations of entity ENT-KEY."
14356 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
14357 arch-alist inst-alist ent-inst-list
14358 ent-entry arch-entry inst-entry)
14359 (while ent-alist
14360 (setq ent-entry (car ent-alist))
14361 (setq arch-alist (nth 4 ent-entry))
14362 (while arch-alist
14363 (setq arch-entry (car arch-alist))
14364 (setq inst-alist (nth 4 arch-entry))
14365 (while inst-alist
14366 (setq inst-entry (car inst-alist))
14367 (when (equal ent-key (nth 5 inst-entry))
14368 (setq ent-inst-list
14369 (cons (list (nth 1 inst-entry)
14370 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14371 (nth 1 ent-entry)
14372 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14373 (nth 1 arch-entry)
14374 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14375 ent-inst-list)))
14376 (setq inst-alist (cdr inst-alist)))
14377 (setq arch-alist (cdr arch-alist)))
14378 (setq ent-alist (cdr ent-alist)))
14379 (nreverse ent-inst-list)))
14381 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14382 ;; Caching in file
14384 (defun vhdl-save-caches ()
14385 "Save all updated hierarchy caches to file."
14386 (interactive)
14387 (condition-case nil
14388 (when vhdl-speedbar-save-cache
14389 ;; update hierarchy
14390 (vhdl-update-hierarchy)
14391 (let ((project-list vhdl-updated-project-list))
14392 (message "Saving hierarchy caches...")
14393 ;; write updated project caches
14394 (while project-list
14395 (vhdl-save-cache (car project-list))
14396 (setq project-list (cdr project-list)))
14397 (message "Saving hierarchy caches...done")))
14398 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14399 (sit-for 2)))))
14401 (defun vhdl-save-cache (key)
14402 "Save current hierarchy cache to file."
14403 (let* ((orig-buffer (current-buffer))
14404 (vhdl-project key)
14405 (project (vhdl-project-p))
14406 (default-directory key)
14407 (directory (abbreviate-file-name (vhdl-default-directory)))
14408 (file-name (vhdl-resolve-env-variable
14409 (vhdl-replace-string
14410 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14411 (concat
14412 (subst-char-in-string ? ?_ (or project "dir"))
14413 " " (user-login-name)))))
14414 (file-dir-name (expand-file-name file-name directory))
14415 (cache-key (or project directory))
14416 (key (if project "project" "directory")))
14417 (unless (file-exists-p (file-name-directory file-dir-name))
14418 (make-directory (file-name-directory file-dir-name) t))
14419 (if (not (file-writable-p file-dir-name))
14420 (progn (vhdl-warning (format "File not writable: \"%s\""
14421 (abbreviate-file-name file-dir-name)))
14422 (sit-for 2))
14423 (message "Saving cache: \"%s\"" file-dir-name)
14424 (set-buffer (find-file-noselect file-dir-name t t))
14425 (erase-buffer)
14426 (insert ";; -*- Emacs-Lisp -*-\n\n"
14427 ";;; " (file-name-nondirectory file-name)
14428 " - design hierarchy cache file for Emacs VHDL Mode "
14429 vhdl-version "\n")
14430 (insert "\n;; " (if project "Project " "Directory") " : ")
14431 (if project (insert project) (prin1 directory (current-buffer)))
14432 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14433 (user-login-name) "\n\n"
14434 "\n;; version number\n"
14435 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14436 "\n;; " (if project "project" "directory") " name"
14437 "\n(setq " key " ")
14438 (prin1 (or project directory) (current-buffer))
14439 (insert ")\n")
14440 (when (member 'hierarchy vhdl-speedbar-save-cache)
14441 (insert "\n;; entity and architecture cache\n"
14442 "(aput 'vhdl-entity-alist " key " '")
14443 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
14444 (insert ")\n\n;; configuration cache\n"
14445 "(aput 'vhdl-config-alist " key " '")
14446 (print (aget vhdl-config-alist cache-key t) (current-buffer))
14447 (insert ")\n\n;; package cache\n"
14448 "(aput 'vhdl-package-alist " key " '")
14449 (print (aget vhdl-package-alist cache-key t) (current-buffer))
14450 (insert ")\n\n;; instantiated entities cache\n"
14451 "(aput 'vhdl-ent-inst-alist " key " '")
14452 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
14453 (insert ")\n\n;; design units per file cache\n"
14454 "(aput 'vhdl-file-alist " key " '")
14455 (print (aget vhdl-file-alist cache-key t) (current-buffer))
14456 (when project
14457 (insert ")\n\n;; source directories in project cache\n"
14458 "(aput 'vhdl-directory-alist " key " '")
14459 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
14460 (insert ")\n"))
14461 (when (member 'display vhdl-speedbar-save-cache)
14462 (insert "\n;; shown design units cache\n"
14463 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
14464 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
14465 (current-buffer))
14466 (insert ")\n"))
14467 (setq vhdl-updated-project-list
14468 (delete cache-key vhdl-updated-project-list))
14469 (save-buffer)
14470 (kill-buffer (current-buffer))
14471 (set-buffer orig-buffer))))
14473 (defun vhdl-load-cache (key)
14474 "Load hierarchy cache information from file."
14475 (let* ((vhdl-project key)
14476 (default-directory key)
14477 (directory (vhdl-default-directory))
14478 (file-name (vhdl-resolve-env-variable
14479 (vhdl-replace-string
14480 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14481 (concat
14482 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14483 " " (user-login-name)))))
14484 (file-dir-name (expand-file-name file-name directory))
14485 vhdl-cache-version)
14486 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14487 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14488 (when (file-exists-p file-dir-name)
14489 (condition-case ()
14490 (progn (load-file file-dir-name)
14491 (string< (mapconcat
14492 (lambda (a) (format "%3d" (string-to-number a)))
14493 (split-string "3.33" "\\.") "")
14494 (mapconcat
14495 (lambda (a) (format "%3d" (string-to-number a)))
14496 (split-string vhdl-cache-version "\\.") "")))
14497 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14498 nil))))))
14500 (defun vhdl-require-hierarchy-info ()
14501 "Make sure that hierarchy information is available. Load cache or scan files
14502 if required."
14503 (if (vhdl-project-p)
14504 (unless (or (assoc vhdl-project vhdl-file-alist)
14505 (vhdl-load-cache vhdl-project))
14506 (vhdl-scan-project-contents vhdl-project))
14507 (let ((directory (abbreviate-file-name default-directory)))
14508 (unless (or (assoc directory vhdl-file-alist)
14509 (vhdl-load-cache directory))
14510 (vhdl-scan-directory-contents directory)))))
14512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14513 ;; Add hierarchy browser functionality to speedbar
14515 (defvar vhdl-speedbar-mode-map nil
14516 "Keymap used when in the VHDL hierarchy browser mode.")
14518 (defvar vhdl-speedbar-menu-items nil
14519 "Additional menu-items to add to speedbar frame.")
14521 (declare-function speedbar-add-supported-extension "speedbar" (extension))
14522 (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
14523 (declare-function speedbar-make-specialized-keymap "speedbar" ())
14524 (declare-function speedbar-change-initial-expansion-list "speedbar"
14525 (new-default))
14526 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
14528 (defun vhdl-speedbar-initialize ()
14529 "Initialize speedbar."
14530 ;; general settings
14531 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
14532 ;; VHDL file extensions (extracted from `auto-mode-alist')
14533 (let ((mode-alist auto-mode-alist))
14534 (while mode-alist
14535 (when (eq (cdar mode-alist) 'vhdl-mode)
14536 (speedbar-add-supported-extension (caar mode-alist)))
14537 (setq mode-alist (cdr mode-alist))))
14538 ;; hierarchy browser settings
14539 (when (boundp 'speedbar-mode-functions-list)
14540 ;; special functions
14541 (speedbar-add-mode-functions-list
14542 '("vhdl directory"
14543 (speedbar-item-info . vhdl-speedbar-item-info)
14544 (speedbar-line-directory . speedbar-files-line-path)))
14545 (speedbar-add-mode-functions-list
14546 '("vhdl project"
14547 (speedbar-item-info . vhdl-speedbar-item-info)
14548 (speedbar-line-directory . vhdl-speedbar-line-project)))
14549 ;; keymap
14550 (unless vhdl-speedbar-mode-map
14551 (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
14552 (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
14553 (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
14554 (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
14555 (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
14556 (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
14557 (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
14558 (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
14559 (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
14560 (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
14561 (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
14562 (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
14563 (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
14564 (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
14565 (let ((key 0))
14566 (while (<= key 9)
14567 (define-key vhdl-speedbar-mode-map (int-to-string key)
14568 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14569 (setq key (1+ key)))))
14570 (define-key speedbar-mode-map "h"
14571 (lambda () (interactive)
14572 (speedbar-change-initial-expansion-list "vhdl directory")))
14573 (define-key speedbar-mode-map "H"
14574 (lambda () (interactive)
14575 (speedbar-change-initial-expansion-list "vhdl project")))
14576 ;; menu
14577 (unless vhdl-speedbar-menu-items
14578 (setq
14579 vhdl-speedbar-menu-items
14580 `(["Edit" speedbar-edit-line t]
14581 ["Expand" speedbar-expand-line
14582 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14583 ["Contract" vhdl-speedbar-contract-level t]
14584 ["Expand All" vhdl-speedbar-expand-all t]
14585 ["Contract All" vhdl-speedbar-contract-all t]
14586 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14587 (while (<= key 9)
14588 (setq menu-list
14589 (cons `[,(if (= key 0) "All" (int-to-string key))
14590 (vhdl-speedbar-set-depth ,key)
14591 :style radio
14592 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14593 :keys ,(int-to-string key)]
14594 menu-list))
14595 (setq key (1+ key)))
14596 (nreverse menu-list))
14597 "--"
14598 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14599 (or (vhdl-speedbar-check-unit 'entity)
14600 (vhdl-speedbar-check-unit 'subprogram))]
14601 ["Place Component" vhdl-speedbar-place-component
14602 (vhdl-speedbar-check-unit 'entity)]
14603 ["Generate Configuration" vhdl-speedbar-configuration
14604 (vhdl-speedbar-check-unit 'architecture)]
14605 ["Select as MRA" vhdl-speedbar-select-mra
14606 (vhdl-speedbar-check-unit 'architecture)]
14607 ["Make" vhdl-speedbar-make-design
14608 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14609 ["Generate Makefile" vhdl-speedbar-generate-makefile
14610 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14611 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14612 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14613 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14614 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14615 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14616 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14617 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14618 ;; hook-ups
14619 (speedbar-add-expansion-list
14620 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14621 vhdl-speedbar-display-directory))
14622 (speedbar-add-expansion-list
14623 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14624 vhdl-speedbar-display-projects))
14625 (setq speedbar-stealthy-function-list
14626 (append
14627 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14628 ("vhdl project" vhdl-speedbar-update-current-project
14629 vhdl-speedbar-update-current-unit)
14630 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14631 ; (speedbar-extension-list-to-regex
14632 ; speedbar-ignored-path-expressions))))
14634 speedbar-stealthy-function-list))
14635 (when (eq vhdl-speedbar-display-mode 'directory)
14636 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14637 (when (eq vhdl-speedbar-display-mode 'project)
14638 (setq speedbar-initial-expansion-list-name "vhdl project"))
14639 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14641 (defun vhdl-speedbar (&optional arg)
14642 "Open/close speedbar."
14643 (interactive)
14644 (if (not (fboundp 'speedbar))
14645 (error "WARNING: Speedbar is not available or not installed")
14646 (condition-case ()
14647 (speedbar-frame-mode arg)
14648 (error (error "WARNING: An error occurred while opening speedbar")))))
14650 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14651 ;; Display functions
14653 (defvar vhdl-speedbar-last-selected-project nil
14654 "Name of last selected project.")
14656 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14657 ;;; (defmacro speedbar-with-writable (&rest forms)
14658 ;;; "Allow the buffer to be writable and evaluate FORMS."
14659 ;;; (list 'let '((inhibit-read-only t))
14660 ;;; (cons 'progn forms)))
14661 ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
14663 (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
14664 (declare-function speedbar-directory-buttons "speedbar" (directory _index))
14665 (declare-function speedbar-file-lists "speedbar" (directory))
14667 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14668 "Display directory and hierarchy information in speedbar."
14669 (setq vhdl-speedbar-show-projects nil)
14670 (setq speedbar-ignored-directory-regexp
14671 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14672 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14673 (setq speedbar-last-selected-file nil)
14674 (speedbar-with-writable
14675 (condition-case nil
14676 (progn
14677 ;; insert directory path
14678 (speedbar-directory-buttons directory depth)
14679 ;; insert subdirectories
14680 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14681 ;; scan and insert hierarchy of current directory
14682 (vhdl-speedbar-insert-dir-hierarchy directory depth
14683 speedbar-power-click)
14684 ;; expand subdirectories
14685 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14686 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14688 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14689 "Display projects and hierarchy information in speedbar."
14690 (setq vhdl-speedbar-show-projects t)
14691 (setq speedbar-ignored-directory-regexp ".")
14692 (setq speedbar-last-selected-file nil)
14693 (setq vhdl-speedbar-last-selected-project nil)
14694 (speedbar-with-writable
14695 (condition-case nil
14696 ;; insert projects
14697 (vhdl-speedbar-insert-projects)
14698 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14699 (setq speedbar-full-text-cache nil)) ; prevent caching
14701 (declare-function speedbar-make-tag-line "speedbar"
14702 (type char func data tag tfunc tdata tface depth))
14704 (defun vhdl-speedbar-insert-projects ()
14705 "Insert all projects in speedbar."
14706 (vhdl-speedbar-make-title-line "Projects:")
14707 (let ((project-alist (if vhdl-project-sort
14708 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14709 vhdl-project-alist))
14710 (vhdl-speedbar-update-current-unit nil))
14711 ;; insert projects
14712 (while project-alist
14713 (speedbar-make-tag-line
14714 'angle ?+ 'vhdl-speedbar-expand-project
14715 (caar project-alist) (caar project-alist)
14716 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14717 (setq project-alist (cdr project-alist)))
14718 (setq project-alist vhdl-project-alist)
14719 ;; expand projects
14720 (while project-alist
14721 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14722 (goto-char (point-min))
14723 (when (re-search-forward
14724 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14725 (goto-char (match-end 1))
14726 (speedbar-do-function-pointer)))
14727 (setq project-alist (cdr project-alist))))
14728 ; (vhdl-speedbar-update-current-project)
14729 ; (vhdl-speedbar-update-current-unit nil t)
14732 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14733 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14734 otherwise use cached data."
14735 (when (or rescan (and (not (assoc project vhdl-file-alist))
14736 (not (vhdl-load-cache project))))
14737 (vhdl-scan-project-contents project))
14738 ;; insert design hierarchy
14739 (vhdl-speedbar-insert-hierarchy
14740 (aget vhdl-entity-alist project t)
14741 (aget vhdl-config-alist project t)
14742 (aget vhdl-package-alist project t)
14743 (car (aget vhdl-ent-inst-alist project t)) indent)
14744 (insert (int-to-string indent) ":\n")
14745 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14746 (put-text-property (1- (point)) (point) 'invisible nil)
14747 ;; expand design units
14748 (vhdl-speedbar-expand-units project))
14750 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14751 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14752 otherwise use cached data."
14753 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14754 (not (vhdl-load-cache directory))))
14755 (vhdl-scan-directory-contents directory))
14756 ;; insert design hierarchy
14757 (vhdl-speedbar-insert-hierarchy
14758 (aget vhdl-entity-alist directory t)
14759 (aget vhdl-config-alist directory t)
14760 (aget vhdl-package-alist directory t)
14761 (car (aget vhdl-ent-inst-alist directory t)) depth)
14762 ;; expand design units
14763 (vhdl-speedbar-expand-units directory)
14764 (aput 'vhdl-directory-alist directory (list (list directory))))
14766 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14767 ent-inst-list depth)
14768 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14769 (if (not (or ent-alist conf-alist pack-alist))
14770 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14771 (let (ent-entry conf-entry pack-entry)
14772 ;; insert entities
14773 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14774 (while ent-alist
14775 (setq ent-entry (car ent-alist))
14776 (speedbar-make-tag-line
14777 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14778 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14779 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14780 'vhdl-speedbar-entity-face depth)
14781 (unless (nth 2 ent-entry)
14782 (end-of-line 0) (insert "!") (forward-char 1))
14783 (unless (member (nth 0 ent-entry) ent-inst-list)
14784 (end-of-line 0) (insert " (top)") (forward-char 1))
14785 (setq ent-alist (cdr ent-alist)))
14786 ;; insert configurations
14787 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14788 (while conf-alist
14789 (setq conf-entry (car conf-alist))
14790 (speedbar-make-tag-line
14791 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14792 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14793 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14794 'vhdl-speedbar-configuration-face depth)
14795 (setq conf-alist (cdr conf-alist)))
14796 ;; insert packages
14797 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14798 (while pack-alist
14799 (setq pack-entry (car pack-alist))
14800 (vhdl-speedbar-make-pack-line
14801 (nth 0 pack-entry) (nth 1 pack-entry)
14802 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14803 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14804 depth)
14805 (setq pack-alist (cdr pack-alist))))))
14807 (declare-function speedbar-line-directory "speedbar" (&optional depth))
14809 (defun vhdl-speedbar-rescan-hierarchy ()
14810 "Rescan hierarchy for the directory or project under the cursor."
14811 (interactive)
14812 (let (key path)
14813 (cond
14814 ;; current project
14815 (vhdl-speedbar-show-projects
14816 (setq key (vhdl-speedbar-line-project))
14817 (vhdl-scan-project-contents key))
14818 ;; top-level directory
14819 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14820 (re-search-forward "[0-9]+:" nil t)
14821 (vhdl-scan-directory-contents
14822 (abbreviate-file-name (speedbar-line-directory))))
14823 ;; current directory
14824 (t (setq path (speedbar-line-directory))
14825 (string-match "^\\(.+[/\\]\\)" path)
14826 (vhdl-scan-directory-contents
14827 (abbreviate-file-name (match-string 1 path)))))
14828 (vhdl-speedbar-refresh key)))
14830 (declare-function speedbar-goto-this-file "speedbar" (file))
14832 (defun vhdl-speedbar-expand-dirs (directory)
14833 "Expand subdirectories in DIRECTORY according to
14834 `speedbar-shown-directories'."
14835 ;; (nicked from `speedbar-default-directory-list')
14836 (let ((sf (cdr (reverse speedbar-shown-directories)))
14837 (vhdl-speedbar-update-current-unit nil))
14838 (setq speedbar-shown-directories
14839 (list (expand-file-name default-directory)))
14840 (while sf
14841 (when (speedbar-goto-this-file (car sf))
14842 (beginning-of-line)
14843 (when (looking-at "[0-9]+:\\s-*<")
14844 (goto-char (match-end 0))
14845 (speedbar-do-function-pointer)))
14846 (setq sf (cdr sf))))
14847 (vhdl-speedbar-update-current-unit nil t))
14849 (defun vhdl-speedbar-expand-units (key)
14850 "Expand design units in directory/project KEY according to
14851 `vhdl-speedbar-shown-unit-alist'."
14852 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14853 (vhdl-speedbar-update-current-unit nil)
14854 vhdl-updated-project-list)
14855 (adelete 'vhdl-speedbar-shown-unit-alist key)
14856 (vhdl-prepare-search-1
14857 (while unit-alist ; expand units
14858 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14859 (beginning-of-line)
14860 (let ((arch-alist (nth 1 (car unit-alist)))
14861 position)
14862 (when (looking-at "^[0-9]+:\\s-*\\[")
14863 (goto-char (match-end 0))
14864 (setq position (point))
14865 (speedbar-do-function-pointer)
14866 (select-frame speedbar-frame)
14867 (while arch-alist ; expand architectures
14868 (goto-char position)
14869 (when (re-search-forward
14870 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14871 (car arch-alist) "\\>\\)") nil t)
14872 (beginning-of-line)
14873 (when (looking-at "^[0-9]+:\\s-*{")
14874 (goto-char (match-end 0))
14875 (speedbar-do-function-pointer)
14876 (select-frame speedbar-frame)))
14877 (setq arch-alist (cdr arch-alist))))
14878 (setq unit-alist (cdr unit-alist))))))
14879 (vhdl-speedbar-update-current-unit nil t))
14881 (declare-function speedbar-center-buffer-smartly "speedbar" ())
14883 (defun vhdl-speedbar-contract-level ()
14884 "Contract current level in current directory/project."
14885 (interactive)
14886 (when (or (save-excursion
14887 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14888 (and (save-excursion
14889 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14890 (re-search-backward
14891 (format "^[0-%d]:\\s-*[[{<]-"
14892 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14893 (goto-char (match-end 0))
14894 (speedbar-do-function-pointer)
14895 (speedbar-center-buffer-smartly)))
14897 (defun vhdl-speedbar-contract-all ()
14898 "Contract all expanded design units in current directory/project."
14899 (interactive)
14900 (if (and vhdl-speedbar-show-projects
14901 (save-excursion (beginning-of-line) (looking-at "^0:")))
14902 (progn (setq vhdl-speedbar-shown-project-list nil)
14903 (vhdl-speedbar-refresh))
14904 (let ((key (vhdl-speedbar-line-key)))
14905 (adelete 'vhdl-speedbar-shown-unit-alist key)
14906 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14907 (when (memq 'display vhdl-speedbar-save-cache)
14908 (add-to-list 'vhdl-updated-project-list key)))))
14910 (defun vhdl-speedbar-expand-all ()
14911 "Expand all design units in current directory/project."
14912 (interactive)
14913 (let* ((key (vhdl-speedbar-line-key))
14914 (ent-alist (aget vhdl-entity-alist key t))
14915 (conf-alist (aget vhdl-config-alist key t))
14916 (pack-alist (aget vhdl-package-alist key t))
14917 arch-alist unit-alist subunit-alist)
14918 (add-to-list 'vhdl-speedbar-shown-project-list key)
14919 (while ent-alist
14920 (setq arch-alist (nth 4 (car ent-alist)))
14921 (setq subunit-alist nil)
14922 (while arch-alist
14923 (push (caar arch-alist) subunit-alist)
14924 (setq arch-alist (cdr arch-alist)))
14925 (push (list (caar ent-alist) subunit-alist) unit-alist)
14926 (setq ent-alist (cdr ent-alist)))
14927 (while conf-alist
14928 (push (list (caar conf-alist)) unit-alist)
14929 (setq conf-alist (cdr conf-alist)))
14930 (while pack-alist
14931 (push (list (caar pack-alist)) unit-alist)
14932 (setq pack-alist (cdr pack-alist)))
14933 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14934 (vhdl-speedbar-refresh)
14935 (when (memq 'display vhdl-speedbar-save-cache)
14936 (add-to-list 'vhdl-updated-project-list key))))
14938 (declare-function speedbar-change-expand-button-char "speedbar" (char))
14939 (declare-function speedbar-delete-subblock "speedbar" (indent))
14941 (defun vhdl-speedbar-expand-project (text token indent)
14942 "Expand/contract the project under the cursor."
14943 (cond
14944 ((string-match "+" text) ; expand project
14945 (speedbar-change-expand-button-char ?-)
14946 (unless (member token vhdl-speedbar-shown-project-list)
14947 (setq vhdl-speedbar-shown-project-list
14948 (cons token vhdl-speedbar-shown-project-list)))
14949 (speedbar-with-writable
14950 (save-excursion
14951 (end-of-line) (forward-char 1)
14952 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14953 speedbar-power-click))))
14954 ((string-match "-" text) ; contract project
14955 (speedbar-change-expand-button-char ?+)
14956 (setq vhdl-speedbar-shown-project-list
14957 (delete token vhdl-speedbar-shown-project-list))
14958 (speedbar-delete-subblock indent))
14959 (t (error "Nothing to display")))
14960 (when (equal (selected-frame) speedbar-frame)
14961 (speedbar-center-buffer-smartly)))
14963 (defun vhdl-speedbar-expand-entity (text token indent)
14964 "Expand/contract the entity under the cursor."
14965 (cond
14966 ((string-match "+" text) ; expand entity
14967 (let* ((key (vhdl-speedbar-line-key indent))
14968 (ent-alist (aget vhdl-entity-alist key t))
14969 (ent-entry (aget ent-alist token t))
14970 (arch-alist (nth 3 ent-entry))
14971 (inst-alist (vhdl-get-instantiations token indent))
14972 (subpack-alist (nth 5 ent-entry))
14973 (multiple-arch (> (length arch-alist) 1))
14974 arch-entry inst-entry)
14975 (if (not (or arch-alist inst-alist subpack-alist))
14976 (speedbar-change-expand-button-char ??)
14977 (speedbar-change-expand-button-char ?-)
14978 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14979 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14980 (aput 'unit-alist token nil)
14981 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14982 (speedbar-with-writable
14983 (save-excursion
14984 (end-of-line) (forward-char 1)
14985 ;; insert architectures
14986 (when arch-alist
14987 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14988 (while arch-alist
14989 (setq arch-entry (car arch-alist))
14990 (speedbar-make-tag-line
14991 'curly ?+ 'vhdl-speedbar-expand-architecture
14992 (cons token (nth 0 arch-entry))
14993 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14994 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14995 'vhdl-speedbar-architecture-face (1+ indent))
14996 (when (and multiple-arch
14997 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14998 (end-of-line 0) (insert " (mra)") (forward-char 1))
14999 (setq arch-alist (cdr arch-alist)))
15000 ;; insert instantiations
15001 (when inst-alist
15002 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
15003 (while inst-alist
15004 (setq inst-entry (car inst-alist))
15005 (vhdl-speedbar-make-inst-line
15006 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
15007 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
15008 nil nil nil (1+ indent) 0 " in ")
15009 (setq inst-alist (cdr inst-alist)))
15010 ;; insert required packages
15011 (vhdl-speedbar-insert-subpackages
15012 subpack-alist (1+ indent) indent)))
15013 (when (memq 'display vhdl-speedbar-save-cache)
15014 (add-to-list 'vhdl-updated-project-list key))
15015 (vhdl-speedbar-update-current-unit t t))))
15016 ((string-match "-" text) ; contract entity
15017 (speedbar-change-expand-button-char ?+)
15018 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
15019 (let* ((key (vhdl-speedbar-line-key indent))
15020 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
15021 (adelete 'unit-alist token)
15022 (if unit-alist
15023 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15024 (adelete 'vhdl-speedbar-shown-unit-alist key))
15025 (speedbar-delete-subblock indent)
15026 (when (memq 'display vhdl-speedbar-save-cache)
15027 (add-to-list 'vhdl-updated-project-list key))))
15028 (t (error "Nothing to display")))
15029 (when (equal (selected-frame) speedbar-frame)
15030 (speedbar-center-buffer-smartly)))
15032 (defun vhdl-speedbar-expand-architecture (text token indent)
15033 "Expand/contract the architecture under the cursor."
15034 (cond
15035 ((string-match "+" text) ; expand architecture
15036 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15037 (ent-alist (aget vhdl-entity-alist key t))
15038 (conf-alist (aget vhdl-config-alist key t))
15039 (hier-alist (vhdl-get-hierarchy
15040 ent-alist conf-alist (car token) (cdr token) nil nil
15041 0 (1- indent)))
15042 (ent-entry (aget ent-alist (car token) t))
15043 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
15044 (subpack-alist (nth 4 arch-entry))
15045 entry)
15046 (if (not (or hier-alist subpack-alist))
15047 (speedbar-change-expand-button-char ??)
15048 (speedbar-change-expand-button-char ?-)
15049 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15050 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
15051 (arch-alist (nth 0 (aget unit-alist (car token) t))))
15052 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
15053 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15054 (speedbar-with-writable
15055 (save-excursion
15056 (end-of-line) (forward-char 1)
15057 ;; insert instance hierarchy
15058 (when hier-alist
15059 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15060 (1+ indent)))
15061 (while hier-alist
15062 (setq entry (car hier-alist))
15063 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15064 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15065 (vhdl-speedbar-make-inst-line
15066 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15067 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15068 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
15069 (setq hier-alist (cdr hier-alist)))
15070 ;; insert required packages
15071 (vhdl-speedbar-insert-subpackages
15072 subpack-alist (1+ indent) (1- indent))))
15073 (when (memq 'display vhdl-speedbar-save-cache)
15074 (add-to-list 'vhdl-updated-project-list key))
15075 (vhdl-speedbar-update-current-unit t t))))
15076 ((string-match "-" text) ; contract architecture
15077 (speedbar-change-expand-button-char ?+)
15078 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15079 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15080 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
15081 (arch-alist (nth 0 (aget unit-alist (car token) t))))
15082 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
15083 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15084 (speedbar-delete-subblock indent)
15085 (when (memq 'display vhdl-speedbar-save-cache)
15086 (add-to-list 'vhdl-updated-project-list key))))
15087 (t (error "Nothing to display")))
15088 (when (equal (selected-frame) speedbar-frame)
15089 (speedbar-center-buffer-smartly)))
15091 (defun vhdl-speedbar-expand-config (text token indent)
15092 "Expand/contract the configuration under the cursor."
15093 (cond
15094 ((string-match "+" text) ; expand configuration
15095 (let* ((key (vhdl-speedbar-line-key indent))
15096 (conf-alist (aget vhdl-config-alist key t))
15097 (conf-entry (aget conf-alist token))
15098 (ent-alist (aget vhdl-entity-alist key t))
15099 (hier-alist (vhdl-get-hierarchy
15100 ent-alist conf-alist (nth 3 conf-entry)
15101 (nth 4 conf-entry) token (nth 5 conf-entry)
15102 0 indent t))
15103 (subpack-alist (nth 6 conf-entry))
15104 entry)
15105 (if (not (or hier-alist subpack-alist))
15106 (speedbar-change-expand-button-char ??)
15107 (speedbar-change-expand-button-char ?-)
15108 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15109 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
15110 (aput 'unit-alist token nil)
15111 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15112 (speedbar-with-writable
15113 (save-excursion
15114 (end-of-line) (forward-char 1)
15115 ;; insert instance hierarchy
15116 (when hier-alist
15117 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
15118 (while hier-alist
15119 (setq entry (car hier-alist))
15120 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15121 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15122 (vhdl-speedbar-make-inst-line
15123 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15124 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15125 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
15126 (setq hier-alist (cdr hier-alist)))
15127 ;; insert required packages
15128 (vhdl-speedbar-insert-subpackages
15129 subpack-alist (1+ indent) indent)))
15130 (when (memq 'display vhdl-speedbar-save-cache)
15131 (add-to-list 'vhdl-updated-project-list key))
15132 (vhdl-speedbar-update-current-unit t t))))
15133 ((string-match "-" text) ; contract configuration
15134 (speedbar-change-expand-button-char ?+)
15135 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15136 (let* ((key (vhdl-speedbar-line-key indent))
15137 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
15138 (adelete 'unit-alist token)
15139 (if unit-alist
15140 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15141 (adelete 'vhdl-speedbar-shown-unit-alist key))
15142 (speedbar-delete-subblock indent)
15143 (when (memq 'display vhdl-speedbar-save-cache)
15144 (add-to-list 'vhdl-updated-project-list key))))
15145 (t (error "Nothing to display")))
15146 (when (equal (selected-frame) speedbar-frame)
15147 (speedbar-center-buffer-smartly)))
15149 (defun vhdl-speedbar-expand-package (text token indent)
15150 "Expand/contract the package under the cursor."
15151 (cond
15152 ((string-match "+" text) ; expand package
15153 (let* ((key (vhdl-speedbar-line-key indent))
15154 (pack-alist (aget vhdl-package-alist key t))
15155 (pack-entry (aget pack-alist token t))
15156 (comp-alist (nth 3 pack-entry))
15157 (func-alist (nth 4 pack-entry))
15158 (func-body-alist (nth 8 pack-entry))
15159 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
15160 comp-entry func-entry func-body-entry)
15161 (if (not (or comp-alist func-alist subpack-alist))
15162 (speedbar-change-expand-button-char ??)
15163 (speedbar-change-expand-button-char ?-)
15164 ;; add package to `vhdl-speedbar-shown-unit-alist'
15165 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
15166 (aput 'unit-alist token nil)
15167 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15168 (speedbar-with-writable
15169 (save-excursion
15170 (end-of-line) (forward-char 1)
15171 ;; insert components
15172 (when comp-alist
15173 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
15174 (while comp-alist
15175 (setq comp-entry (car comp-alist))
15176 (speedbar-make-tag-line
15177 nil nil nil
15178 (cons token (nth 0 comp-entry))
15179 (nth 1 comp-entry) 'vhdl-speedbar-find-file
15180 (cons (nth 2 comp-entry) (nth 3 comp-entry))
15181 'vhdl-speedbar-entity-face (1+ indent))
15182 (setq comp-alist (cdr comp-alist)))
15183 ;; insert subprograms
15184 (when func-alist
15185 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
15186 (while func-alist
15187 (setq func-entry (car func-alist)
15188 func-body-entry (aget func-body-alist (car func-entry) t))
15189 (when (nth 2 func-entry)
15190 (vhdl-speedbar-make-subprogram-line
15191 (nth 1 func-entry)
15192 (cons (nth 2 func-entry) (nth 3 func-entry))
15193 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
15194 (1+ indent)))
15195 (setq func-alist (cdr func-alist)))
15196 ;; insert required packages
15197 (vhdl-speedbar-insert-subpackages
15198 subpack-alist (1+ indent) indent)))
15199 (when (memq 'display vhdl-speedbar-save-cache)
15200 (add-to-list 'vhdl-updated-project-list key))
15201 (vhdl-speedbar-update-current-unit t t))))
15202 ((string-match "-" text) ; contract package
15203 (speedbar-change-expand-button-char ?+)
15204 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15205 (let* ((key (vhdl-speedbar-line-key indent))
15206 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
15207 (adelete 'unit-alist token)
15208 (if unit-alist
15209 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15210 (adelete 'vhdl-speedbar-shown-unit-alist key))
15211 (speedbar-delete-subblock indent)
15212 (when (memq 'display vhdl-speedbar-save-cache)
15213 (add-to-list 'vhdl-updated-project-list key))))
15214 (t (error "Nothing to display")))
15215 (when (equal (selected-frame) speedbar-frame)
15216 (speedbar-center-buffer-smartly)))
15218 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15219 "Insert required packages."
15220 (let* ((pack-alist (aget vhdl-package-alist
15221 (vhdl-speedbar-line-key dir-indent) t))
15222 pack-key lib-name pack-entry)
15223 (when subpack-alist
15224 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15225 (while subpack-alist
15226 (setq pack-key (cdar subpack-alist)
15227 lib-name (caar subpack-alist))
15228 (setq pack-entry (aget pack-alist pack-key t))
15229 (vhdl-speedbar-make-subpack-line
15230 (or (nth 0 pack-entry) pack-key) lib-name
15231 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15232 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15233 (setq subpack-alist (cdr subpack-alist)))))
15235 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15236 ;; Display help functions
15238 (defvar vhdl-speedbar-update-current-unit t
15239 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15241 (defun vhdl-speedbar-update-current-project ()
15242 "Highlight project that is currently active."
15243 (when (and vhdl-speedbar-show-projects
15244 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15245 (and (boundp 'speedbar-frame)
15246 (frame-live-p speedbar-frame)))
15247 (let ((last-frame (selected-frame))
15248 (project-alist vhdl-project-alist)
15249 pos)
15250 (select-frame speedbar-frame)
15251 (speedbar-with-writable
15252 (save-excursion
15253 (while project-alist
15254 (goto-char (point-min))
15255 (when (re-search-forward
15256 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15257 (put-text-property (match-beginning 1) (match-end 1) 'face
15258 (if (equal (caar project-alist) vhdl-project)
15259 'speedbar-selected-face
15260 'speedbar-directory-face))
15261 (when (equal (caar project-alist) vhdl-project)
15262 (setq pos (1- (match-beginning 1)))))
15263 (setq project-alist (cdr project-alist))))
15264 (when pos (goto-char pos)))
15265 (select-frame last-frame)
15266 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15269 (declare-function speedbar-position-cursor-on-line "speedbar" ())
15271 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15272 "Highlight all design units that are contained in the current file.
15273 NO-POSITION non-nil means do not re-position cursor."
15274 (let ((last-frame (selected-frame))
15275 (project-list vhdl-speedbar-shown-project-list)
15276 file-alist pos file-name)
15277 ;; get current file name
15278 (if (fboundp 'speedbar-select-attached-frame)
15279 (speedbar-select-attached-frame)
15280 (select-frame speedbar-attached-frame))
15281 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15282 (when (and vhdl-speedbar-update-current-unit
15283 (or always (not (equal file-name speedbar-last-selected-file))))
15284 (if vhdl-speedbar-show-projects
15285 (while project-list
15286 (setq file-alist (append file-alist (aget vhdl-file-alist
15287 (car project-list) t)))
15288 (setq project-list (cdr project-list)))
15289 (setq file-alist (aget vhdl-file-alist
15290 (abbreviate-file-name default-directory) t)))
15291 (select-frame speedbar-frame)
15292 (set-buffer speedbar-buffer)
15293 (speedbar-with-writable
15294 (vhdl-prepare-search-1
15295 (save-excursion
15296 ;; unhighlight last units
15297 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
15298 (vhdl-speedbar-update-units
15299 "\\[.\\] " (nth 0 file-entry)
15300 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15301 (vhdl-speedbar-update-units
15302 "{.} " (nth 1 file-entry)
15303 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15304 (vhdl-speedbar-update-units
15305 "\\[.\\] " (nth 3 file-entry)
15306 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15307 (vhdl-speedbar-update-units
15308 "[]>] " (nth 4 file-entry)
15309 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15310 (vhdl-speedbar-update-units
15311 "\\[.\\].+(" '("body")
15312 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15313 (vhdl-speedbar-update-units
15314 "> " (nth 6 file-entry)
15315 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15316 ;; highlight current units
15317 (let* ((file-entry (aget file-alist file-name t)))
15318 (setq
15319 pos (vhdl-speedbar-update-units
15320 "\\[.\\] " (nth 0 file-entry)
15321 file-name 'vhdl-speedbar-entity-selected-face pos)
15322 pos (vhdl-speedbar-update-units
15323 "{.} " (nth 1 file-entry)
15324 file-name 'vhdl-speedbar-architecture-selected-face pos)
15325 pos (vhdl-speedbar-update-units
15326 "\\[.\\] " (nth 3 file-entry)
15327 file-name 'vhdl-speedbar-configuration-selected-face pos)
15328 pos (vhdl-speedbar-update-units
15329 "[]>] " (nth 4 file-entry)
15330 file-name 'vhdl-speedbar-package-selected-face pos)
15331 pos (vhdl-speedbar-update-units
15332 "\\[.\\].+(" '("body")
15333 file-name 'vhdl-speedbar-package-selected-face pos)
15334 pos (vhdl-speedbar-update-units
15335 "> " (nth 6 file-entry)
15336 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15337 ;; move speedbar so the first highlighted unit is visible
15338 (when (and pos (not no-position))
15339 (goto-char pos)
15340 (speedbar-center-buffer-smartly)
15341 (speedbar-position-cursor-on-line))
15342 (setq speedbar-last-selected-file file-name))
15343 (select-frame last-frame)
15346 (defun vhdl-speedbar-update-units (text unit-list file-name face
15347 &optional pos)
15348 "Help function to highlight design units."
15349 (while unit-list
15350 (goto-char (point-min))
15351 (while (re-search-forward
15352 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15353 (when (equal file-name (car (get-text-property
15354 (match-beginning 1) 'speedbar-token)))
15355 (setq pos (or pos (point-marker)))
15356 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15357 (setq unit-list (cdr unit-list)))
15358 pos)
15360 (declare-function speedbar-make-button "speedbar"
15361 (start end face mouse function &optional token))
15363 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15364 ent-name ent-file-marker
15365 arch-name arch-file-marker
15366 conf-name conf-file-marker
15367 lib-name depth offset delimiter)
15368 "Insert instantiation entry."
15369 (let ((start (point))
15370 visible-start)
15371 (insert (int-to-string depth) ":")
15372 (put-text-property start (point) 'invisible t)
15373 (setq visible-start (point))
15374 (insert-char ? (* depth speedbar-indentation-width))
15375 (while (> offset 0)
15376 (insert "|")
15377 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15378 (setq offset (1- offset)))
15379 (put-text-property visible-start (point) 'invisible nil)
15380 (setq start (point))
15381 (insert ">")
15382 (speedbar-make-button start (point) nil nil nil)
15383 (setq visible-start (point))
15384 (insert " ")
15385 (setq start (point))
15386 (if (not inst-name)
15387 (insert "(top)")
15388 (insert inst-name)
15389 (speedbar-make-button
15390 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15391 'vhdl-speedbar-find-file inst-file-marker))
15392 (insert delimiter)
15393 (when ent-name
15394 (setq start (point))
15395 (insert ent-name)
15396 (speedbar-make-button
15397 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15398 'vhdl-speedbar-find-file ent-file-marker)
15399 (when arch-name
15400 (insert " (")
15401 (setq start (point))
15402 (insert arch-name)
15403 (speedbar-make-button
15404 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15405 'vhdl-speedbar-find-file arch-file-marker)
15406 (insert ")"))
15407 (when conf-name
15408 (insert " (")
15409 (setq start (point))
15410 (insert conf-name)
15411 (speedbar-make-button
15412 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15413 'vhdl-speedbar-find-file conf-file-marker)
15414 (insert ")")))
15415 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15416 (setq start (point))
15417 (insert " (" lib-name ")")
15418 (put-text-property (+ 2 start) (1- (point)) 'face
15419 'vhdl-speedbar-library-face))
15420 (insert-char ?\n 1)
15421 (put-text-property visible-start (point) 'invisible nil)))
15423 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15424 body-file-marker depth)
15425 "Insert package entry."
15426 (let ((start (point))
15427 visible-start)
15428 (insert (int-to-string depth) ":")
15429 (put-text-property start (point) 'invisible t)
15430 (setq visible-start (point))
15431 (insert-char ? (* depth speedbar-indentation-width))
15432 (put-text-property visible-start (point) 'invisible nil)
15433 (setq start (point))
15434 (insert "[+]")
15435 (speedbar-make-button
15436 start (point) 'speedbar-button-face 'speedbar-highlight-face
15437 'vhdl-speedbar-expand-package pack-key)
15438 (setq visible-start (point))
15439 (insert-char ? 1 nil)
15440 (setq start (point))
15441 (insert pack-name)
15442 (speedbar-make-button
15443 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15444 'vhdl-speedbar-find-file pack-file-marker)
15445 (unless (car pack-file-marker)
15446 (insert "!"))
15447 (when (car body-file-marker)
15448 (insert " (")
15449 (setq start (point))
15450 (insert "body")
15451 (speedbar-make-button
15452 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15453 'vhdl-speedbar-find-file body-file-marker)
15454 (insert ")"))
15455 (insert-char ?\n 1)
15456 (put-text-property visible-start (point) 'invisible nil)))
15458 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15459 pack-body-file-marker depth)
15460 "Insert used package entry."
15461 (let ((start (point))
15462 visible-start)
15463 (insert (int-to-string depth) ":")
15464 (put-text-property start (point) 'invisible t)
15465 (setq visible-start (point))
15466 (insert-char ? (* depth speedbar-indentation-width))
15467 (put-text-property visible-start (point) 'invisible nil)
15468 (setq start (point))
15469 (insert ">")
15470 (speedbar-make-button start (point) nil nil nil)
15471 (setq visible-start (point))
15472 (insert " ")
15473 (setq start (point))
15474 (insert pack-name)
15475 (speedbar-make-button
15476 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15477 'vhdl-speedbar-find-file pack-file-marker)
15478 (when (car pack-body-file-marker)
15479 (insert " (")
15480 (setq start (point))
15481 (insert "body")
15482 (speedbar-make-button
15483 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15484 'vhdl-speedbar-find-file pack-body-file-marker)
15485 (insert ")"))
15486 (setq start (point))
15487 (insert " (" lib-name ")")
15488 (put-text-property (+ 2 start) (1- (point)) 'face
15489 'vhdl-speedbar-library-face)
15490 (insert-char ?\n 1)
15491 (put-text-property visible-start (point) 'invisible nil)))
15493 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15494 func-body-file-marker
15495 depth)
15496 "Insert subprogram entry."
15497 (let ((start (point))
15498 visible-start)
15499 (insert (int-to-string depth) ":")
15500 (put-text-property start (point) 'invisible t)
15501 (setq visible-start (point))
15502 (insert-char ? (* depth speedbar-indentation-width))
15503 (put-text-property visible-start (point) 'invisible nil)
15504 (setq start (point))
15505 (insert ">")
15506 (speedbar-make-button start (point) nil nil nil)
15507 (setq visible-start (point))
15508 (insert " ")
15509 (setq start (point))
15510 (insert func-name)
15511 (speedbar-make-button
15512 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15513 'vhdl-speedbar-find-file func-file-marker)
15514 (when (car func-body-file-marker)
15515 (insert " (")
15516 (setq start (point))
15517 (insert "body")
15518 (speedbar-make-button
15519 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15520 'vhdl-speedbar-find-file func-body-file-marker)
15521 (insert ")"))
15522 (insert-char ?\n 1)
15523 (put-text-property visible-start (point) 'invisible nil)))
15525 (defun vhdl-speedbar-make-title-line (text &optional depth)
15526 "Insert design unit title entry."
15527 (let ((start (point))
15528 visible-start)
15529 (when depth
15530 (insert (int-to-string depth) ":")
15531 (put-text-property start (point) 'invisible t))
15532 (setq visible-start (point))
15533 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15534 (setq start (point))
15535 (insert text)
15536 (speedbar-make-button start (point) nil nil nil nil)
15537 (insert-char ?\n 1)
15538 (put-text-property visible-start (point) 'invisible nil)))
15540 (defun vhdl-speedbar-insert-dirs (files level)
15541 "Insert subdirectories."
15542 (let ((dirs (car files)))
15543 (while dirs
15544 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15545 (car dirs) 'speedbar-dir-follow nil
15546 'speedbar-directory-face level)
15547 (setq dirs (cdr dirs)))))
15549 (declare-function speedbar-reset-scanners "speedbar" ())
15551 (defun vhdl-speedbar-dired (text token indent)
15552 "Speedbar click handler for directory expand button in hierarchy mode."
15553 (cond ((string-match "+" text) ; we have to expand this dir
15554 (setq speedbar-shown-directories
15555 (cons (expand-file-name
15556 (concat (speedbar-line-directory indent) token "/"))
15557 speedbar-shown-directories))
15558 (speedbar-change-expand-button-char ?-)
15559 (speedbar-reset-scanners)
15560 (speedbar-with-writable
15561 (save-excursion
15562 (end-of-line) (forward-char 1)
15563 (vhdl-speedbar-insert-dirs
15564 (speedbar-file-lists
15565 (concat (speedbar-line-directory indent) token "/"))
15566 (1+ indent))
15567 (speedbar-reset-scanners)
15568 (vhdl-speedbar-insert-dir-hierarchy
15569 (abbreviate-file-name
15570 (concat (speedbar-line-directory indent) token "/"))
15571 (1+ indent) speedbar-power-click)))
15572 (vhdl-speedbar-update-current-unit t t))
15573 ((string-match "-" text) ; we have to contract this node
15574 (speedbar-reset-scanners)
15575 (let ((oldl speedbar-shown-directories)
15576 (newl nil)
15577 (td (expand-file-name
15578 (concat (speedbar-line-directory indent) token))))
15579 (while oldl
15580 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15581 (push (car oldl) newl))
15582 (setq oldl (cdr oldl)))
15583 (setq speedbar-shown-directories (nreverse newl)))
15584 (speedbar-change-expand-button-char ?+)
15585 (speedbar-delete-subblock indent))
15586 (t (error "Nothing to display")))
15587 (when (equal (selected-frame) speedbar-frame)
15588 (speedbar-center-buffer-smartly)))
15590 (declare-function speedbar-files-item-info "speedbar" ())
15592 (defun vhdl-speedbar-item-info ()
15593 "Derive and display information about this line item."
15594 (save-excursion
15595 (beginning-of-line)
15596 ;; skip invisible number info
15597 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15598 (cond
15599 ;; project/directory entry
15600 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15601 (if vhdl-speedbar-show-projects
15602 (message "Project \"%s\"" (match-string-no-properties 1))
15603 (speedbar-files-item-info)))
15604 ;; design unit entry
15605 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15606 (goto-char (match-end 1))
15607 (let ((face (get-text-property (point) 'face)))
15608 (message
15609 "%s \"%s\" in \"%s\""
15610 ;; design unit kind
15611 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15612 (eq face 'vhdl-speedbar-entity-selected-face))
15613 (if (equal (match-string 2) ">") "Component" "Entity"))
15614 ((or (eq face 'vhdl-speedbar-architecture-face)
15615 (eq face 'vhdl-speedbar-architecture-selected-face))
15616 "Architecture")
15617 ((or (eq face 'vhdl-speedbar-configuration-face)
15618 (eq face 'vhdl-speedbar-configuration-selected-face))
15619 "Configuration")
15620 ((or (eq face 'vhdl-speedbar-package-face)
15621 (eq face 'vhdl-speedbar-package-selected-face))
15622 "Package")
15623 ((or (eq face 'vhdl-speedbar-instantiation-face)
15624 (eq face 'vhdl-speedbar-instantiation-selected-face))
15625 "Instantiation")
15626 ((eq face 'vhdl-speedbar-subprogram-face)
15627 "Subprogram")
15628 (t ""))
15629 ;; design unit name
15630 (buffer-substring-no-properties
15631 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15632 (match-end 1))
15633 ;; file name
15634 (file-relative-name
15635 (or (car (get-text-property (point) 'speedbar-token))
15636 "?")
15637 (vhdl-default-directory)))))
15638 (t (message "")))))
15640 (declare-function speedbar-line-text "speedbar" (&optional p))
15642 (defun vhdl-speedbar-line-text ()
15643 "Calls `speedbar-line-text' and removes text properties."
15644 (let ((string (speedbar-line-text)))
15645 (set-text-properties 0 (length string) nil string)
15646 string))
15648 (defun vhdl-speedbar-higher-text ()
15649 "Get speedbar-line-text of higher level."
15650 (let (depth string)
15651 (save-excursion
15652 (beginning-of-line)
15653 (looking-at "^\\([0-9]+\\):")
15654 (setq depth (string-to-number (match-string 1)))
15655 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15656 (setq string (match-string 1))
15657 (set-text-properties 0 (length string) nil string)
15658 string))))
15660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15661 ;; Help functions
15663 (defun vhdl-speedbar-line-key (&optional indent)
15664 "Get currently displayed directory of project name."
15665 (if vhdl-speedbar-show-projects
15666 (vhdl-speedbar-line-project)
15667 (abbreviate-file-name
15668 (file-name-as-directory (speedbar-line-directory indent)))))
15670 (defun vhdl-speedbar-line-project (&optional indent)
15671 "Get currently displayed project name."
15672 (and vhdl-speedbar-show-projects
15673 (save-excursion
15674 (end-of-line)
15675 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15676 (match-string-no-properties 1))))
15678 (defun vhdl-add-modified-file ()
15679 "Add file to `vhdl-modified-file-list'."
15680 (when vhdl-file-alist
15681 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15682 nil)
15684 (defun vhdl-resolve-paths (path-list)
15685 "Resolve path wildcards in PATH-LIST."
15686 (let (path-list-1 path-list-2 path-beg path-end dir)
15687 ;; eliminate non-existent directories
15688 (while path-list
15689 (setq dir (car path-list))
15690 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15691 (if (file-directory-p (match-string 2 dir))
15692 (push dir path-list-1)
15693 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15694 (setq path-list (cdr path-list)))
15695 ;; resolve path wildcards
15696 (while path-list-1
15697 (setq dir (car path-list-1))
15698 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15699 (progn
15700 (setq path-beg (match-string 1 dir)
15701 path-end (match-string 5 dir))
15702 (setq path-list-1
15703 (append
15704 (mapcar
15705 (function
15706 (lambda (var) (concat path-beg var path-end)))
15707 (let ((all-list (vhdl-directory-files
15708 (match-string 2 dir) t
15709 (concat "\\<" (wildcard-to-regexp
15710 (match-string 4 dir)))))
15711 dir-list)
15712 (while all-list
15713 (when (file-directory-p (car all-list))
15714 (push (car all-list) dir-list))
15715 (setq all-list (cdr all-list)))
15716 dir-list))
15717 (cdr path-list-1))))
15718 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15719 (when (file-directory-p (match-string 2 dir))
15720 (push dir path-list-2))
15721 (setq path-list-1 (cdr path-list-1))))
15722 (nreverse path-list-2)))
15724 (defun vhdl-speedbar-goto-this-unit (directory unit)
15725 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15726 (let ((dest (point)))
15727 (if (and (if vhdl-speedbar-show-projects
15728 (progn (goto-char (point-min)) t)
15729 (speedbar-goto-this-file directory))
15730 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15731 (progn (speedbar-position-cursor-on-line)
15733 (goto-char dest)
15734 nil)))
15736 (declare-function speedbar-find-file-in-frame "speedbar" (file))
15737 (declare-function speedbar-set-timer "speedbar" (timeout))
15738 ;; speedbar loads dframe at runtime.
15739 (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
15741 (defun vhdl-speedbar-find-file (text token indent)
15742 "When user clicks on TEXT, load file with name and position in TOKEN.
15743 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15744 is already shown in a buffer."
15745 (if (not (car token))
15746 (error "ERROR: File cannot be found")
15747 (let ((buffer (get-file-buffer (car token))))
15748 (speedbar-find-file-in-frame (car token))
15749 (when (or vhdl-speedbar-jump-to-unit buffer)
15750 (vhdl-goto-line (cdr token))
15751 (recenter))
15752 (vhdl-speedbar-update-current-unit t t)
15753 (speedbar-set-timer dframe-update-speed)
15754 (dframe-maybee-jump-to-attached-frame))))
15756 (defun vhdl-speedbar-port-copy ()
15757 "Copy the port of the entity/component or subprogram under the cursor."
15758 (interactive)
15759 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15760 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15761 (error "ERROR: No entity/component or subprogram under cursor")
15762 (beginning-of-line)
15763 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15764 (condition-case info
15765 (let ((token (get-text-property
15766 (match-beginning 3) 'speedbar-token)))
15767 (vhdl-visit-file (car token) t
15768 (progn (vhdl-goto-line (cdr token))
15769 (end-of-line)
15770 (if is-entity
15771 (vhdl-port-copy)
15772 (vhdl-subprog-copy)))))
15773 (error (error "ERROR: %s not scanned successfully\n (%s)"
15774 (if is-entity "Port" "Interface") (cadr info))))
15775 (error "ERROR: No entity/component or subprogram on current line")))))
15777 (defun vhdl-speedbar-place-component ()
15778 "Place the entity/component under the cursor as component."
15779 (interactive)
15780 (if (not (vhdl-speedbar-check-unit 'entity))
15781 (error "ERROR: No entity/component under cursor")
15782 (vhdl-speedbar-port-copy)
15783 (if (fboundp 'speedbar-select-attached-frame)
15784 (speedbar-select-attached-frame)
15785 (select-frame speedbar-attached-frame))
15786 (vhdl-compose-place-component)
15787 (select-frame speedbar-frame)))
15789 (defun vhdl-speedbar-configuration ()
15790 "Generate configuration for the architecture under the cursor."
15791 (interactive)
15792 (if (not (vhdl-speedbar-check-unit 'architecture))
15793 (error "ERROR: No architecture under cursor")
15794 (let ((arch-name (vhdl-speedbar-line-text))
15795 (ent-name (vhdl-speedbar-higher-text)))
15796 (if (fboundp 'speedbar-select-attached-frame)
15797 (speedbar-select-attached-frame)
15798 (select-frame speedbar-attached-frame))
15799 (vhdl-compose-configuration ent-name arch-name))))
15801 (defun vhdl-speedbar-select-mra ()
15802 "Select the architecture under the cursor as MRA."
15803 (interactive)
15804 (if (not (vhdl-speedbar-check-unit 'architecture))
15805 (error "ERROR: No architecture under cursor")
15806 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15807 (ent-key (downcase (vhdl-speedbar-higher-text)))
15808 (ent-alist (aget vhdl-entity-alist
15809 (or (vhdl-project-p) default-directory) t))
15810 (ent-entry (aget ent-alist ent-key t)))
15811 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15812 (speedbar-refresh))))
15814 (declare-function speedbar-line-file "speedbar" (&optional p))
15816 (defun vhdl-speedbar-make-design ()
15817 "Make (compile) design unit or directory/project under the cursor."
15818 (interactive)
15819 (if (not (save-excursion (beginning-of-line)
15820 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15821 (error "ERROR: No primary design unit or directory/project under cursor")
15822 (let ((is-unit (match-string 2))
15823 (unit-name (vhdl-speedbar-line-text))
15824 (vhdl-project (vhdl-speedbar-line-project))
15825 (directory (file-name-as-directory
15826 (or (speedbar-line-file) (speedbar-line-directory)))))
15827 (if (fboundp 'speedbar-select-attached-frame)
15828 (speedbar-select-attached-frame)
15829 (select-frame speedbar-attached-frame))
15830 (let ((default-directory directory))
15831 (vhdl-make (and is-unit unit-name))))))
15833 (defun vhdl-speedbar-generate-makefile ()
15834 "Generate Makefile for directory/project under the cursor."
15835 (interactive)
15836 (let ((vhdl-project (vhdl-speedbar-line-project))
15837 (default-directory (file-name-as-directory
15838 (or (speedbar-line-file) (speedbar-line-directory)))))
15839 (vhdl-generate-makefile)))
15841 (defun vhdl-speedbar-check-unit (design-unit)
15842 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15843 expansion function)."
15844 (save-excursion
15845 (speedbar-position-cursor-on-line)
15846 (cond ((eq design-unit 'entity)
15847 (memq (get-text-property (match-end 0) 'face)
15848 '(vhdl-speedbar-entity-face
15849 vhdl-speedbar-entity-selected-face)))
15850 ((eq design-unit 'architecture)
15851 (memq (get-text-property (match-end 0) 'face)
15852 '(vhdl-speedbar-architecture-face
15853 vhdl-speedbar-architecture-selected-face)))
15854 ((eq design-unit 'subprogram)
15855 (eq (get-text-property (match-end 0) 'face)
15856 'vhdl-speedbar-subprogram-face))
15857 (t nil))))
15859 (defun vhdl-speedbar-set-depth (depth)
15860 "Set hierarchy display depth to DEPTH and refresh speedbar."
15861 (setq vhdl-speedbar-hierarchy-depth depth)
15862 (speedbar-refresh))
15864 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15865 ;; Fontification
15867 (defface vhdl-speedbar-entity-face
15868 '((((class color) (background light)) (:foreground "ForestGreen"))
15869 (((class color) (background dark)) (:foreground "PaleGreen")))
15870 "Face used for displaying entity names."
15871 :group 'speedbar-faces)
15873 (defface vhdl-speedbar-architecture-face
15874 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15875 (((class color) (background light)) (:foreground "Blue"))
15877 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15878 "Face used for displaying architecture names."
15879 :group 'speedbar-faces)
15881 (defface vhdl-speedbar-configuration-face
15882 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15883 (((class color) (background dark)) (:foreground "Salmon")))
15884 "Face used for displaying configuration names."
15885 :group 'speedbar-faces)
15887 (defface vhdl-speedbar-package-face
15888 '((((class color) (background light)) (:foreground "Grey50"))
15889 (((class color) (background dark)) (:foreground "Grey80")))
15890 "Face used for displaying package names."
15891 :group 'speedbar-faces)
15893 (defface vhdl-speedbar-library-face
15894 '((((class color) (background light)) (:foreground "Purple"))
15895 (((class color) (background dark)) (:foreground "Orchid1")))
15896 "Face used for displaying library names."
15897 :group 'speedbar-faces)
15899 (defface vhdl-speedbar-instantiation-face
15900 '((((class color) (background light)) (:foreground "Brown"))
15901 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15902 (((class color) (background dark)) (:foreground "Yellow")))
15903 "Face used for displaying instantiation names."
15904 :group 'speedbar-faces)
15906 (defface vhdl-speedbar-subprogram-face
15907 '((((class color) (background light)) (:foreground "Orchid4"))
15908 (((class color) (background dark)) (:foreground "BurlyWood2")))
15909 "Face used for displaying subprogram names."
15910 :group 'speedbar-faces)
15912 (defface vhdl-speedbar-entity-selected-face
15913 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15914 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15915 "Face used for displaying entity names."
15916 :group 'speedbar-faces)
15918 (defface vhdl-speedbar-architecture-selected-face
15919 '((((min-colors 88) (class color) (background light)) (:foreground
15920 "Blue1" :underline t))
15921 (((class color) (background light)) (:foreground "Blue" :underline t))
15922 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15923 "Face used for displaying architecture names."
15924 :group 'speedbar-faces)
15926 (defface vhdl-speedbar-configuration-selected-face
15927 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15928 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15929 "Face used for displaying configuration names."
15930 :group 'speedbar-faces)
15932 (defface vhdl-speedbar-package-selected-face
15933 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15934 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15935 "Face used for displaying package names."
15936 :group 'speedbar-faces)
15938 (defface vhdl-speedbar-instantiation-selected-face
15939 '((((class color) (background light)) (:foreground "Brown" :underline t))
15940 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15941 "Face used for displaying instantiation names."
15942 :group 'speedbar-faces)
15944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15945 ;; Initialization
15947 ;; add speedbar
15948 (when (fboundp 'speedbar)
15949 (condition-case ()
15950 (when (and vhdl-speedbar-auto-open
15951 (not (and (boundp 'speedbar-frame)
15952 (frame-live-p speedbar-frame))))
15953 (speedbar-frame-mode 1)
15954 (if (fboundp 'speedbar-select-attached-frame)
15955 (speedbar-select-attached-frame)
15956 (select-frame speedbar-attached-frame)))
15957 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15959 ;; initialize speedbar
15960 (if (not (boundp 'speedbar-frame))
15961 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15962 (vhdl-speedbar-initialize)
15963 (when speedbar-frame (vhdl-speedbar-refresh)))
15966 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15967 ;;; Structural composition
15968 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15970 (defun vhdl-get-components-package-name ()
15971 "Return the name of the components package."
15972 (let ((project (vhdl-project-p)))
15973 (if project
15974 (vhdl-replace-string (car vhdl-components-package-name)
15975 (subst-char-in-string ? ?_ project))
15976 (cdr vhdl-components-package-name))))
15978 (defun vhdl-compose-new-component ()
15979 "Create entity and architecture for new component."
15980 (interactive)
15981 (let* ((case-fold-search t)
15982 (ent-name (read-from-minibuffer "entity name: "
15983 nil vhdl-minibuffer-local-map))
15984 (arch-name
15985 (if (equal (cdr vhdl-compose-architecture-name) "")
15986 (read-from-minibuffer "architecture name: "
15987 nil vhdl-minibuffer-local-map)
15988 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15989 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
15990 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15991 ;; open entity file
15992 (unless (eq vhdl-compose-create-files 'none)
15993 (setq ent-file-name
15994 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15995 "." (file-name-extension (buffer-file-name))))
15996 (when (and (file-exists-p ent-file-name)
15997 (not (y-or-n-p (concat "File \"" ent-file-name
15998 "\" exists; overwrite? "))))
15999 (error "ERROR: Creating component...aborted"))
16000 (find-file ent-file-name)
16001 (erase-buffer)
16002 (set-buffer-modified-p nil))
16003 ;; insert header
16004 (if vhdl-compose-include-header
16005 (progn (vhdl-template-header)
16006 (setq end-pos (point))
16007 (goto-char (point-max)))
16008 (vhdl-comment-display-line) (insert "\n\n"))
16009 ;; insert library clause
16010 (vhdl-template-package-std-logic-1164)
16011 (when vhdl-use-components-package
16012 (insert "\n")
16013 (vhdl-template-standard-package (vhdl-work-library)
16014 (vhdl-get-components-package-name)))
16015 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
16016 ;; insert entity declaration
16017 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
16018 (vhdl-insert-keyword " IS\n")
16019 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16020 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
16021 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16022 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16023 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
16024 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16025 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16026 (vhdl-insert-keyword "END ")
16027 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
16028 (insert ent-name ";\n\n")
16029 (vhdl-comment-display-line) (insert "\n")
16030 ;; open architecture file
16031 (if (not (eq vhdl-compose-create-files 'separate))
16032 (insert "\n")
16033 (goto-char (or end-pos (point-min)))
16034 (setq ent-buffer (current-buffer))
16035 (setq arch-file-name
16036 (concat (vhdl-replace-string vhdl-architecture-file-name
16037 (concat ent-name " " arch-name) t)
16038 "." (file-name-extension (buffer-file-name))))
16039 (when (and (file-exists-p arch-file-name)
16040 (not (y-or-n-p (concat "File \"" arch-file-name
16041 "\" exists; overwrite? "))))
16042 (error "ERROR: Creating component...aborted"))
16043 (find-file arch-file-name)
16044 (erase-buffer)
16045 (set-buffer-modified-p nil)
16046 ;; insert header
16047 (if vhdl-compose-include-header
16048 (progn (vhdl-template-header)
16049 (goto-char (point-max)))
16050 (vhdl-comment-display-line) (insert "\n\n")))
16051 ;; insert architecture body
16052 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
16053 (vhdl-insert-keyword " OF ") (insert ent-name)
16054 (vhdl-insert-keyword " IS\n\n")
16055 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16056 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
16057 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16058 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
16059 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16060 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16061 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
16062 (vhdl-insert-keyword "BEGIN")
16063 (when vhdl-self-insert-comments
16064 (insert " -- ")
16065 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16066 (insert arch-name))
16067 (insert "\n\n")
16068 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16069 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
16070 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16071 (vhdl-insert-keyword "END ")
16072 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16073 (insert arch-name ";\n\n")
16074 ;; insert footer and save
16075 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16076 (vhdl-template-footer)
16077 (vhdl-comment-display-line) (insert "\n"))
16078 (goto-char (or end-pos (point-min)))
16079 (setq arch-buffer (current-buffer))
16080 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
16081 (set-buffer arch-buffer) (save-buffer)
16082 (message "%s"
16083 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
16084 (and ent-file-name
16085 (format "\n File created: \"%s\"" ent-file-name))
16086 (and arch-file-name
16087 (format "\n File created: \"%s\"" arch-file-name))))))
16089 (defun vhdl-compose-place-component ()
16090 "Place new component by pasting current port as component declaration and
16091 component instantiation."
16092 (interactive)
16093 (if (not vhdl-port-list)
16094 (error "ERROR: No port has been read")
16095 (save-excursion
16096 (vhdl-prepare-search-2
16097 (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)
16098 (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))
16099 (error "ERROR: No architecture found"))
16100 (let* ((ent-name (match-string 1))
16101 (ent-file-name
16102 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16103 "." (file-name-extension (buffer-file-name))))
16104 (orig-buffer (current-buffer)))
16105 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
16106 ;; place component declaration
16107 (unless (or vhdl-use-components-package
16108 (vhdl-use-direct-instantiation)
16109 (save-excursion
16110 (re-search-forward
16111 (concat "^\\s-*component\\s-+"
16112 (car vhdl-port-list) "\\>") nil t)))
16113 (re-search-forward "^begin\\>" nil)
16114 (beginning-of-line)
16115 (skip-chars-backward " \t\n\r\f")
16116 (insert "\n\n") (indent-to vhdl-basic-offset)
16117 (vhdl-port-paste-component t))
16118 ;; place component instantiation
16119 (re-search-forward "^end\\>" nil)
16120 (beginning-of-line)
16121 (skip-chars-backward " \t\n\r\f")
16122 (insert "\n\n") (indent-to vhdl-basic-offset)
16123 (vhdl-port-paste-instance nil t t)
16124 ;; place use clause for used packages
16125 (when (nth 3 vhdl-port-list)
16126 ;; open entity file
16127 (when (file-exists-p ent-file-name)
16128 (find-file ent-file-name))
16129 (goto-char (point-min))
16130 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16131 (error "ERROR: Entity not found: \"%s\"" ent-name))
16132 (goto-char (match-beginning 0))
16133 (if (and (save-excursion
16134 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
16135 (match-string 1))
16136 (progn (goto-char (match-end 0))
16137 (beginning-of-line 2))
16138 (insert "\n")
16139 (backward-char))
16140 (vhdl-port-paste-context-clause)
16141 (switch-to-buffer orig-buffer))
16142 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
16144 (defun vhdl-compose-wire-components ()
16145 "Connect components."
16146 (interactive)
16147 (save-excursion
16148 (vhdl-prepare-search-2
16149 (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)
16150 (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))
16151 (error "ERROR: No architecture found"))
16152 (let* ((ent-name (match-string 1))
16153 (ent-file-name
16154 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16155 "." (file-name-extension (buffer-file-name))))
16156 (arch-decl-pos (point-marker))
16157 (arch-stat-pos (re-search-forward "^begin\\>" nil))
16158 (arch-end-pos (re-search-forward "^end\\>" nil))
16159 (pack-name (vhdl-get-components-package-name))
16160 (pack-file-name
16161 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16162 "." (file-name-extension (buffer-file-name))))
16163 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16164 port-alist generic-alist inst-alist
16165 signal-name signal-entry signal-alist local-list written-list
16166 single-in-list multi-in-list single-out-list multi-out-list
16167 constant-name constant-entry constant-alist single-list multi-list
16168 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16169 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16170 signal-beg-pos signal-pos
16171 constant-temp-pos port-temp-pos signal-temp-pos)
16172 (message "Wiring components...")
16173 ;; process all instances
16174 (goto-char arch-stat-pos)
16175 (while (re-search-forward
16176 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16177 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16178 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16179 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16180 "[ \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)
16181 (setq inst-name (match-string-no-properties 1)
16182 comp-name (match-string-no-properties 4)
16183 comp-ent-name (match-string-no-properties 12)
16184 has-generic (or (match-string 7) (match-string 17)))
16185 ;; get port ...
16186 (if comp-name
16187 ;; ... from component declaration
16188 (vhdl-visit-file
16189 (when vhdl-use-components-package pack-file-name) t
16190 (save-excursion
16191 (goto-char (point-min))
16192 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
16193 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
16194 (vhdl-port-copy)))
16195 ;; ... from entity declaration (direct instantiation)
16196 (setq comp-ent-file-name
16197 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
16198 "." (file-name-extension (buffer-file-name))))
16199 (vhdl-visit-file
16200 comp-ent-file-name t
16201 (save-excursion
16202 (goto-char (point-min))
16203 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
16204 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
16205 (vhdl-port-copy))))
16206 (vhdl-port-flatten t)
16207 (setq generic-alist (nth 1 vhdl-port-list)
16208 port-alist (nth 2 vhdl-port-list)
16209 vhdl-port-list nil)
16210 (setq constant-alist nil
16211 signal-alist nil)
16212 (when has-generic
16213 ;; process all constants in generic map
16214 (vhdl-forward-syntactic-ws)
16215 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16216 (setq constant-name (match-string-no-properties 3))
16217 (setq constant-entry
16218 (cons constant-name
16219 (if (match-string 1)
16220 (or (aget generic-alist (match-string 2) t)
16221 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16222 (cdar generic-alist))))
16223 (push constant-entry constant-alist)
16224 (setq constant-name (downcase constant-name))
16225 (if (or (member constant-name single-list)
16226 (member constant-name multi-list))
16227 (progn (setq single-list (delete constant-name single-list))
16228 (add-to-list 'multi-list constant-name))
16229 (add-to-list 'single-list constant-name))
16230 (unless (match-string 1)
16231 (setq generic-alist (cdr generic-alist)))
16232 (vhdl-forward-syntactic-ws))
16233 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16234 ;; process all signals in port map
16235 (vhdl-forward-syntactic-ws)
16236 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16237 (setq signal-name (match-string-no-properties 3))
16238 (setq signal-entry (cons signal-name
16239 (if (match-string 1)
16240 (or (aget port-alist (match-string 2) t)
16241 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16242 (cdar port-alist))))
16243 (push signal-entry signal-alist)
16244 (setq signal-name (downcase signal-name))
16245 (if (equal (upcase (nth 2 signal-entry)) "IN")
16246 ;; input signal
16247 (cond
16248 ((member signal-name local-list)
16249 nil)
16250 ((or (member signal-name single-out-list)
16251 (member signal-name multi-out-list))
16252 (setq single-out-list (delete signal-name single-out-list))
16253 (setq multi-out-list (delete signal-name multi-out-list))
16254 (add-to-list 'local-list signal-name))
16255 ((member signal-name single-in-list)
16256 (setq single-in-list (delete signal-name single-in-list))
16257 (add-to-list 'multi-in-list signal-name))
16258 ((not (member signal-name multi-in-list))
16259 (add-to-list 'single-in-list signal-name)))
16260 ;; output signal
16261 (cond
16262 ((member signal-name local-list)
16263 nil)
16264 ((or (member signal-name single-in-list)
16265 (member signal-name multi-in-list))
16266 (setq single-in-list (delete signal-name single-in-list))
16267 (setq multi-in-list (delete signal-name multi-in-list))
16268 (add-to-list 'local-list signal-name))
16269 ((member signal-name single-out-list)
16270 (setq single-out-list (delete signal-name single-out-list))
16271 (add-to-list 'multi-out-list signal-name))
16272 ((not (member signal-name multi-out-list))
16273 (add-to-list 'single-out-list signal-name))))
16274 (unless (match-string 1)
16275 (setq port-alist (cdr port-alist)))
16276 (vhdl-forward-syntactic-ws))
16277 (push (list inst-name (nreverse constant-alist)
16278 (nreverse signal-alist)) inst-alist))
16279 ;; prepare signal insertion
16280 (vhdl-goto-marker arch-decl-pos)
16281 (forward-line 1)
16282 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16283 (setq signal-pos (point-marker))
16284 (while (progn (vhdl-forward-syntactic-ws)
16285 (looking-at "signal\\>"))
16286 (beginning-of-line 2)
16287 (delete-region signal-pos (point)))
16288 (setq signal-beg-pos signal-pos)
16289 ;; open entity file
16290 (when (file-exists-p ent-file-name)
16291 (find-file ent-file-name))
16292 (goto-char (point-min))
16293 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16294 (error "ERROR: Entity not found: \"%s\"" ent-name))
16295 ;; prepare generic clause insertion
16296 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16297 (match-string 1))
16298 (goto-char (match-beginning 0))
16299 (indent-to vhdl-basic-offset)
16300 (insert "generic ();\n\n")
16301 (backward-char 4))
16302 (backward-char)
16303 (setq generic-pos (point-marker))
16304 (forward-sexp) (end-of-line)
16305 (delete-region generic-pos (point)) (delete-char 1)
16306 (insert "(\n")
16307 (when multi-list
16308 (insert "\n")
16309 (indent-to (* 2 vhdl-basic-offset))
16310 (insert "-- global generics\n"))
16311 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16312 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16313 ;; prepare port clause insertion
16314 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16315 (match-string 1))
16316 (goto-char (match-beginning 0))
16317 (indent-to vhdl-basic-offset)
16318 (insert "port ();\n\n")
16319 (backward-char 4))
16320 (backward-char)
16321 (setq port-in-pos (point-marker))
16322 (forward-sexp) (end-of-line)
16323 (delete-region port-in-pos (point)) (delete-char 1)
16324 (insert "(\n")
16325 (when (or multi-in-list multi-out-list)
16326 (insert "\n")
16327 (indent-to (* 2 vhdl-basic-offset))
16328 (insert "-- global ports\n"))
16329 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16330 port-out-pos (point-marker) port-inst-pos (point-marker)
16331 port-end-pos (point-marker))
16332 ;; insert generics, ports and signals
16333 (setq inst-alist (nreverse inst-alist))
16334 (while inst-alist
16335 (setq inst-name (nth 0 (car inst-alist))
16336 constant-alist (nth 1 (car inst-alist))
16337 signal-alist (nth 2 (car inst-alist))
16338 constant-temp-pos generic-inst-pos
16339 port-temp-pos port-inst-pos
16340 signal-temp-pos signal-pos)
16341 ;; generics
16342 (while constant-alist
16343 (setq constant-name (downcase (caar constant-alist))
16344 constant-entry (car constant-alist))
16345 (unless (string-match "^[0-9]+" constant-name)
16346 (cond ((member constant-name written-list)
16347 nil)
16348 ((member constant-name multi-list)
16349 (vhdl-goto-marker generic-pos)
16350 (setq generic-end-pos
16351 (vhdl-max-marker
16352 generic-end-pos
16353 (vhdl-compose-insert-generic constant-entry)))
16354 (setq generic-pos (point-marker))
16355 (add-to-list 'written-list constant-name))
16357 (vhdl-goto-marker
16358 (vhdl-max-marker generic-inst-pos generic-pos))
16359 (setq generic-end-pos
16360 (vhdl-compose-insert-generic constant-entry))
16361 (setq generic-inst-pos (point-marker))
16362 (add-to-list 'written-list constant-name))))
16363 (setq constant-alist (cdr constant-alist)))
16364 (when (/= constant-temp-pos generic-inst-pos)
16365 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16366 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16367 (insert "-- generics for \"" inst-name "\"\n")
16368 (vhdl-goto-marker generic-inst-pos))
16369 ;; ports and signals
16370 (while signal-alist
16371 (setq signal-name (downcase (caar signal-alist))
16372 signal-entry (car signal-alist))
16373 (cond ((member signal-name written-list)
16374 nil)
16375 ((member signal-name multi-in-list)
16376 (vhdl-goto-marker port-in-pos)
16377 (setq port-end-pos
16378 (vhdl-max-marker
16379 port-end-pos (vhdl-compose-insert-port signal-entry)))
16380 (setq port-in-pos (point-marker))
16381 (add-to-list 'written-list signal-name))
16382 ((member signal-name multi-out-list)
16383 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16384 (setq port-end-pos
16385 (vhdl-max-marker
16386 port-end-pos (vhdl-compose-insert-port signal-entry)))
16387 (setq port-out-pos (point-marker))
16388 (add-to-list 'written-list signal-name))
16389 ((or (member signal-name single-in-list)
16390 (member signal-name single-out-list))
16391 (vhdl-goto-marker
16392 (vhdl-max-marker
16393 port-inst-pos
16394 (vhdl-max-marker port-out-pos port-in-pos)))
16395 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16396 (setq port-inst-pos (point-marker))
16397 (add-to-list 'written-list signal-name))
16398 ((equal (upcase (nth 2 signal-entry)) "OUT")
16399 (vhdl-goto-marker signal-pos)
16400 (vhdl-compose-insert-signal signal-entry)
16401 (setq signal-pos (point-marker))
16402 (add-to-list 'written-list signal-name)))
16403 (setq signal-alist (cdr signal-alist)))
16404 (when (/= port-temp-pos port-inst-pos)
16405 (vhdl-goto-marker
16406 (vhdl-max-marker port-temp-pos
16407 (vhdl-max-marker port-in-pos port-out-pos)))
16408 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16409 (insert "-- ports to \"" inst-name "\"\n")
16410 (vhdl-goto-marker port-inst-pos))
16411 (when (/= signal-temp-pos signal-pos)
16412 (vhdl-goto-marker signal-temp-pos)
16413 (insert "\n") (indent-to vhdl-basic-offset)
16414 (insert "-- outputs of \"" inst-name "\"\n")
16415 (vhdl-goto-marker signal-pos))
16416 (setq inst-alist (cdr inst-alist)))
16417 ;; finalize generic/port clause
16418 (vhdl-goto-marker generic-end-pos) (backward-char)
16419 (when (= generic-beg-pos generic-end-pos)
16420 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16421 (insert ";") (backward-char))
16422 (insert ")")
16423 (vhdl-goto-marker port-end-pos) (backward-char)
16424 (when (= port-beg-pos port-end-pos)
16425 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16426 (insert ";") (backward-char))
16427 (insert ")")
16428 ;; align everything
16429 (when vhdl-auto-align
16430 (vhdl-goto-marker generic-beg-pos)
16431 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16432 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16433 (vhdl-goto-marker signal-beg-pos)
16434 (vhdl-align-region-groups signal-beg-pos signal-pos))
16435 (switch-to-buffer (marker-buffer signal-beg-pos))
16436 (message "Wiring components...done")))))
16438 (defun vhdl-compose-insert-generic (entry)
16439 "Insert ENTRY as generic declaration."
16440 (let (pos)
16441 (indent-to (* 2 vhdl-basic-offset))
16442 (insert (nth 0 entry) " : " (nth 1 entry))
16443 (when (nth 2 entry)
16444 (insert " := " (nth 2 entry)))
16445 (insert ";")
16446 (setq pos (point-marker))
16447 (when (and vhdl-include-port-comments (nth 3 entry))
16448 (vhdl-comment-insert-inline (nth 3 entry) t))
16449 (insert "\n")
16450 pos))
16452 (defun vhdl-compose-insert-port (entry)
16453 "Insert ENTRY as port declaration."
16454 (let (pos)
16455 (indent-to (* 2 vhdl-basic-offset))
16456 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16457 (setq pos (point-marker))
16458 (when (and vhdl-include-port-comments (nth 4 entry))
16459 (vhdl-comment-insert-inline (nth 4 entry) t))
16460 (insert "\n")
16461 pos))
16463 (defun vhdl-compose-insert-signal (entry)
16464 "Insert ENTRY as signal declaration."
16465 (indent-to vhdl-basic-offset)
16466 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16467 (when (and vhdl-include-port-comments (nth 4 entry))
16468 (vhdl-comment-insert-inline (nth 4 entry) t))
16469 (insert "\n"))
16471 (defun vhdl-compose-components-package ()
16472 "Generate a package containing component declarations for all entities in the
16473 current project/directory."
16474 (interactive)
16475 (vhdl-require-hierarchy-info)
16476 (let* ((project (vhdl-project-p))
16477 (pack-name (vhdl-get-components-package-name))
16478 (pack-file-name
16479 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16480 "." (file-name-extension (buffer-file-name))))
16481 (ent-alist (aget vhdl-entity-alist
16482 (or project default-directory) t))
16483 (lazy-lock-minimum-size 0)
16484 clause-pos component-pos)
16485 (message "Generating components package \"%s\"..." pack-name)
16486 ;; open package file
16487 (when (and (file-exists-p pack-file-name)
16488 (not (y-or-n-p (concat "File \"" pack-file-name
16489 "\" exists; overwrite? "))))
16490 (error "ERROR: Generating components package...aborted"))
16491 (find-file pack-file-name)
16492 (erase-buffer)
16493 ;; insert header
16494 (if vhdl-compose-include-header
16495 (progn (vhdl-template-header
16496 (concat "Components package (generated by Emacs VHDL Mode "
16497 vhdl-version ")"))
16498 (goto-char (point-max)))
16499 (vhdl-comment-display-line) (insert "\n\n"))
16500 ;; insert std_logic_1164 package
16501 (vhdl-template-package-std-logic-1164)
16502 (insert "\n") (setq clause-pos (point-marker))
16503 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16504 ;; insert package declaration
16505 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16506 (vhdl-insert-keyword " IS\n\n")
16507 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16508 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16509 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16510 (indent-to vhdl-basic-offset)
16511 (setq component-pos (point-marker))
16512 (insert "\n\n") (vhdl-insert-keyword "END ")
16513 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16514 (insert pack-name ";\n\n")
16515 ;; insert footer
16516 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16517 (vhdl-template-footer)
16518 (vhdl-comment-display-line) (insert "\n"))
16519 ;; insert component declarations
16520 (while ent-alist
16521 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16522 (progn (vhdl-goto-line (nth 3 (car ent-alist)))
16523 (end-of-line)
16524 (vhdl-port-copy)))
16525 (goto-char component-pos)
16526 (vhdl-port-paste-component t)
16527 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16528 (setq component-pos (point-marker))
16529 (goto-char clause-pos)
16530 (vhdl-port-paste-context-clause pack-name)
16531 (setq clause-pos (point-marker))
16532 (setq ent-alist (cdr ent-alist)))
16533 (goto-char (point-min))
16534 (save-buffer)
16535 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16536 pack-name pack-file-name)))
16538 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16539 conf-alist inst-alist
16540 &optional insert-conf)
16541 "Generate block configuration for architecture."
16542 (let ((margin (current-indentation))
16543 (beg (point-at-bol))
16544 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16545 ;; insert block configuration (for architecture)
16546 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16547 (setq margin (+ margin vhdl-basic-offset))
16548 ;; process all instances
16549 (while inst-alist
16550 (setq inst-entry (car inst-alist))
16551 ;; is component?
16552 (when (nth 4 inst-entry)
16553 (setq insert-conf t)
16554 (setq inst-path (nth 9 inst-entry))
16555 ;; skip common path with previous instance
16556 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16557 (setq inst-path (cdr inst-path)
16558 inst-prev-path (cdr inst-prev-path)))
16559 ;; insert block configuration end (for previous block/generate)
16560 (while inst-prev-path
16561 (setq margin (- margin vhdl-basic-offset))
16562 (indent-to margin)
16563 (vhdl-insert-keyword "END FOR;\n")
16564 (setq inst-prev-path (cdr inst-prev-path)))
16565 ;; insert block configuration beginning (for current block/generate)
16566 (indent-to margin)
16567 (while inst-path
16568 (setq margin (+ margin vhdl-basic-offset))
16569 (vhdl-insert-keyword "FOR ")
16570 (insert (car inst-path) "\n")
16571 (indent-to margin)
16572 (setq inst-path (cdr inst-path)))
16573 ;; insert component configuration beginning
16574 (vhdl-insert-keyword "FOR ")
16575 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16576 ;; find subconfiguration
16577 (setq conf-key (nth 7 inst-entry))
16578 (setq tmp-alist conf-alist)
16579 ;; use first configuration found for instance's entity
16580 (while (and tmp-alist (null conf-key))
16581 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16582 (setq conf-key (nth 0 (car tmp-alist))))
16583 (setq tmp-alist (cdr tmp-alist)))
16584 (setq conf-entry (aget conf-alist conf-key t))
16585 ;; insert binding indication ...
16586 ;; ... with subconfiguration (if exists)
16587 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16588 (progn
16589 (indent-to (+ margin vhdl-basic-offset))
16590 (vhdl-insert-keyword "USE CONFIGURATION ")
16591 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16592 (insert ";\n"))
16593 ;; ... with entity (if exists)
16594 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16595 (when ent-entry
16596 (indent-to (+ margin vhdl-basic-offset))
16597 (vhdl-insert-keyword "USE ENTITY ")
16598 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16599 ;; insert architecture name (if architecture exists)
16600 (when (nth 3 ent-entry)
16601 (setq arch-name
16602 ;; choose architecture name a) from configuration,
16603 ;; b) from mra, or c) from first architecture
16604 (or (nth 0 (aget (nth 3 ent-entry)
16605 (or (nth 6 inst-entry)
16606 (nth 4 ent-entry)) t))
16607 (nth 1 (car (nth 3 ent-entry)))))
16608 (insert "(" arch-name ")"))
16609 (insert ";\n")
16610 ;; insert block configuration (for architecture of subcomponent)
16611 (when (and vhdl-compose-configuration-hierarchical
16612 (nth 3 ent-entry))
16613 (indent-to (+ margin vhdl-basic-offset))
16614 (vhdl-compose-configuration-architecture
16615 (nth 0 ent-entry) arch-name ent-alist conf-alist
16616 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16617 ;; insert component configuration end
16618 (indent-to margin)
16619 (vhdl-insert-keyword "END FOR;\n")
16620 (setq inst-prev-path (nth 9 inst-entry)))
16621 (setq inst-alist (cdr inst-alist)))
16622 ;; insert block configuration end (for block/generate)
16623 (while inst-prev-path
16624 (setq margin (- margin vhdl-basic-offset))
16625 (indent-to margin)
16626 (vhdl-insert-keyword "END FOR;\n")
16627 (setq inst-prev-path (cdr inst-prev-path)))
16628 (indent-to (- margin vhdl-basic-offset))
16629 ;; insert block configuration end or remove beginning (for architecture)
16630 (if insert-conf
16631 (vhdl-insert-keyword "END FOR;\n")
16632 (delete-region beg (point)))))
16634 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16635 "Generate configuration declaration."
16636 (interactive)
16637 (vhdl-require-hierarchy-info)
16638 (let ((ent-alist (aget vhdl-entity-alist
16639 (or (vhdl-project-p) default-directory) t))
16640 (conf-alist (aget vhdl-config-alist
16641 (or (vhdl-project-p) default-directory) t))
16642 (from-speedbar ent-name)
16643 inst-alist conf-name conf-file-name pos)
16644 (vhdl-prepare-search-2
16645 ;; get entity and architecture name
16646 (unless ent-name
16647 (save-excursion
16648 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16649 (not (equal "END" (upcase (match-string 1))))
16650 (setq ent-name (match-string-no-properties 3))
16651 (setq arch-name (match-string-no-properties 2)))
16652 (error "ERROR: Not within an architecture"))))
16653 (setq conf-name (vhdl-replace-string
16654 vhdl-compose-configuration-name
16655 (concat ent-name " " arch-name)))
16656 (setq inst-alist
16657 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16658 (downcase arch-name) t))))
16659 (message "Generating configuration \"%s\"..." conf-name)
16660 (if vhdl-compose-configuration-create-file
16661 ;; open configuration file
16662 (progn
16663 (setq conf-file-name
16664 (concat (vhdl-replace-string vhdl-configuration-file-name
16665 conf-name t)
16666 "." (file-name-extension (buffer-file-name))))
16667 (when (and (file-exists-p conf-file-name)
16668 (not (y-or-n-p (concat "File \"" conf-file-name
16669 "\" exists; overwrite? "))))
16670 (error "ERROR: Creating configuration...aborted"))
16671 (find-file conf-file-name)
16672 (erase-buffer)
16673 (set-buffer-modified-p nil)
16674 ;; insert header
16675 (if vhdl-compose-include-header
16676 (progn (vhdl-template-header
16677 (concat "Configuration declaration for design \""
16678 ent-name "(" arch-name ")\""))
16679 (goto-char (point-max)))
16680 (vhdl-comment-display-line) (insert "\n\n")))
16681 ;; goto end of architecture
16682 (unless from-speedbar
16683 (re-search-forward "^end\\>" nil)
16684 (end-of-line) (insert "\n\n")
16685 (vhdl-comment-display-line) (insert "\n\n")))
16686 ;; insert library clause
16687 (setq pos (point))
16688 (vhdl-template-standard-package (vhdl-work-library) nil)
16689 (when (/= pos (point))
16690 (insert "\n\n"))
16691 ;; insert configuration
16692 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16693 (vhdl-insert-keyword " OF ") (insert ent-name)
16694 (vhdl-insert-keyword " IS\n")
16695 (indent-to vhdl-basic-offset)
16696 ;; insert block configuration (for architecture)
16697 (vhdl-compose-configuration-architecture
16698 ent-name arch-name ent-alist conf-alist inst-alist t)
16699 (vhdl-insert-keyword "END ") (insert conf-name ";")
16700 (when conf-file-name
16701 ;; insert footer and save
16702 (insert "\n\n")
16703 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16704 (vhdl-template-footer)
16705 (vhdl-comment-display-line) (insert "\n"))
16706 (save-buffer))
16707 (message "%s"
16708 (concat (format "Generating configuration \"%s\"...done" conf-name)
16709 (and conf-file-name
16710 (format "\n File created: \"%s\"" conf-file-name))))))
16713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16714 ;;; Compilation / Makefile generation
16715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16716 ;; (using `compile.el')
16718 (defvar vhdl-compile-post-command ""
16719 "String appended to compile command after file name.")
16721 (defun vhdl-makefile-name ()
16722 "Return the Makefile name of the current project or the current compiler if
16723 no project is defined."
16724 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16725 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16726 (vhdl-replace-string
16727 (cons "\\(.*\\)\n\\(.*\\)"
16728 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16729 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16731 (defun vhdl-compile-directory ()
16732 "Return the directory where compilation/make should be run."
16733 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16734 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16735 (directory (vhdl-resolve-env-variable
16736 (if project
16737 (vhdl-replace-string
16738 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16739 (nth 6 compiler)))))
16740 (file-name-as-directory
16741 (if (file-name-absolute-p directory)
16742 directory
16743 (expand-file-name directory (vhdl-default-directory))))))
16745 (defun vhdl-uniquify (in-list)
16746 "Remove duplicate elements from IN-LIST."
16747 (let (out-list)
16748 (while in-list
16749 (add-to-list 'out-list (car in-list))
16750 (setq in-list (cdr in-list)))
16751 out-list))
16753 (defun vhdl-set-compiler (name)
16754 "Set current compiler to NAME."
16755 (interactive
16756 (list (let ((completion-ignore-case t))
16757 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16758 (if (assoc name vhdl-compiler-alist)
16759 (progn (setq vhdl-compiler name)
16760 (message "Current compiler: \"%s\"" vhdl-compiler))
16761 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16763 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16764 ;; Compilation
16766 (defun vhdl-compile-init ()
16767 "Initialize for compilation."
16768 (when (or (null compilation-error-regexp-alist)
16769 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16770 compilation-error-regexp-alist)))
16771 ;; `compilation-error-regexp-alist'
16772 (let ((commands-alist vhdl-compiler-alist)
16773 regexp-alist sublist)
16774 (while commands-alist
16775 (setq sublist (nth 11 (car commands-alist)))
16776 (unless (or (equal "" (car sublist))
16777 (assoc (car sublist) regexp-alist))
16778 (push (list (nth 0 sublist)
16779 (if (and (featurep 'xemacs) (not (nth 1 sublist)))
16781 (nth 1 sublist))
16782 (nth 2 sublist) (nth 3 sublist))
16783 regexp-alist))
16784 (setq commands-alist (cdr commands-alist)))
16785 (setq compilation-error-regexp-alist
16786 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16787 ;; `compilation-file-regexp-alist'
16788 (let ((commands-alist vhdl-compiler-alist)
16789 regexp-alist sublist)
16790 ;; matches vhdl-mode file name output
16791 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16792 (while commands-alist
16793 (setq sublist (nth 12 (car commands-alist)))
16794 (unless (or (equal "" (car sublist))
16795 (assoc (car sublist) regexp-alist))
16796 (push sublist regexp-alist))
16797 (setq commands-alist (cdr commands-alist)))
16798 (setq compilation-file-regexp-alist
16799 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16801 (defvar vhdl-compile-file-name nil
16802 "Name of file to be compiled.")
16804 (defun vhdl-compile-print-file-name ()
16805 "Function called within `compile' to print out file name for compilers that
16806 do not print any file names."
16807 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16809 (defun vhdl-get-compile-options (project compiler file-name
16810 &optional file-options-only)
16811 "Get compiler options. Returning nil means do not compile this file."
16812 (let* ((compiler-options (nth 1 compiler))
16813 (project-entry (aget (nth 4 project) vhdl-compiler))
16814 (project-options (nth 0 project-entry))
16815 (exception-list (and file-name (nth 2 project-entry)))
16816 (work-library (vhdl-work-library))
16817 (case-fold-search nil)
16818 file-options)
16819 (while (and exception-list
16820 (not (string-match (caar exception-list) file-name)))
16821 (setq exception-list (cdr exception-list)))
16822 (if (and exception-list (not (cdar exception-list)))
16824 (if (and file-options-only (not exception-list))
16825 'default
16826 (setq file-options (cdar exception-list))
16827 ;; insert library name in compiler-specific options
16828 (setq compiler-options
16829 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16830 work-library))
16831 ;; insert compiler-specific options in project-specific options
16832 (when project-options
16833 (setq project-options
16834 (vhdl-replace-string
16835 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16836 (concat work-library "\n" compiler-options))))
16837 ;; insert project-specific options in file-specific options
16838 (when file-options
16839 (setq file-options
16840 (vhdl-replace-string
16841 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16842 (concat work-library "\n" compiler-options "\n"
16843 project-options))))
16844 ;; return options
16845 (or file-options project-options compiler-options)))))
16847 (defun vhdl-get-make-options (project compiler)
16848 "Get make options."
16849 (let* ((compiler-options (nth 3 compiler))
16850 (project-entry (aget (nth 4 project) vhdl-compiler))
16851 (project-options (nth 1 project-entry))
16852 (makefile-name (vhdl-makefile-name)))
16853 ;; insert Makefile name in compiler-specific options
16854 (setq compiler-options
16855 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16856 makefile-name))
16857 ;; insert compiler-specific options in project-specific options
16858 (when project-options
16859 (setq project-options
16860 (vhdl-replace-string
16861 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16862 (concat makefile-name "\n" compiler-options))))
16863 ;; return options
16864 (or project-options compiler-options)))
16866 (defun vhdl-compile ()
16867 "Compile current buffer using the VHDL compiler specified in
16868 `vhdl-compiler'."
16869 (interactive)
16870 (vhdl-compile-init)
16871 (let* ((project (aget vhdl-project-alist vhdl-project))
16872 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16873 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16874 (command (nth 0 compiler))
16875 (default-directory (vhdl-compile-directory))
16876 (file-name (if vhdl-compile-absolute-path
16877 (buffer-file-name)
16878 (file-relative-name (buffer-file-name))))
16879 (options (vhdl-get-compile-options project compiler file-name))
16880 compilation-process-setup-function)
16881 (unless (file-directory-p default-directory)
16882 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16883 ;; put file name into quotes if it contains spaces
16884 (when (string-match " " file-name)
16885 (setq file-name (concat "\"" file-name "\"")))
16886 ;; print out file name if compiler does not
16887 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
16888 (buffer-file-name)
16889 (file-relative-name (buffer-file-name))))
16890 (when (and (= 0 (nth 1 (nth 10 compiler)))
16891 (= 0 (nth 1 (nth 11 compiler))))
16892 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16893 ;; run compilation
16894 (if options
16895 (when command
16896 (compile (concat command " " options " " file-name
16897 (unless (equal vhdl-compile-post-command "")
16898 (concat " " vhdl-compile-post-command)))))
16899 (vhdl-warning "Your project settings tell me not to compile this file"))))
16901 (defvar vhdl-make-target "all"
16902 "Default target for `vhdl-make' command.")
16904 (defun vhdl-make (&optional target)
16905 "Call make command for compilation of all updated source files (requires
16906 `Makefile'). Optional argument TARGET allows to compile the design
16907 specified by a target."
16908 (interactive)
16909 (setq vhdl-make-target
16910 (or target (read-from-minibuffer "Target: " vhdl-make-target
16911 vhdl-minibuffer-local-map)))
16912 (vhdl-compile-init)
16913 (let* ((project (aget vhdl-project-alist vhdl-project))
16914 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16915 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16916 (command (nth 2 compiler))
16917 (options (vhdl-get-make-options project compiler))
16918 (default-directory (vhdl-compile-directory)))
16919 (unless (file-directory-p default-directory)
16920 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16921 ;; run make
16922 (compile (concat (if (equal command "") "make" command)
16923 " " options " " vhdl-make-target))))
16925 ;; Emacs 22+ setup
16926 (defvar vhdl-error-regexp-emacs-alist
16927 ;; Get regexps from `vhdl-compiler-alist'
16928 (let ((compiler-alist vhdl-compiler-alist)
16929 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
16930 (while compiler-alist
16931 ;; add error message regexps
16932 (setq error-regexp-alist
16933 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
16934 (nth 11 (car compiler-alist)))
16935 error-regexp-alist))
16936 ;; add filename regexps
16937 (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
16938 (setq error-regexp-alist
16939 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
16940 (nth 12 (car compiler-alist)))
16941 error-regexp-alist)))
16942 (setq compiler-alist (cdr compiler-alist)))
16943 error-regexp-alist)
16944 "List of regexps for VHDL compilers. For Emacs 22+.")
16946 ;; Add error regexps using compilation-mode-hook.
16947 (defun vhdl-error-regexp-add-emacs ()
16948 "Set up Emacs compile for VHDL."
16949 (interactive)
16950 (when (and (boundp 'compilation-error-regexp-alist-alist)
16951 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
16952 (mapcar
16953 (lambda (item)
16954 (push (car item) compilation-error-regexp-alist)
16955 (push item compilation-error-regexp-alist-alist))
16956 vhdl-error-regexp-emacs-alist)))
16958 (when vhdl-emacs-22
16959 (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
16961 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16962 ;; Makefile generation
16964 (defun vhdl-generate-makefile ()
16965 "Generate `Makefile'."
16966 (interactive)
16967 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16968 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16969 (command (nth 4 compiler)))
16970 ;; generate makefile
16971 (if command
16972 (let ((default-directory (vhdl-compile-directory)))
16973 (compile (vhdl-replace-string
16974 (cons "\\(.*\\) \\(.*\\)" command)
16975 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16976 (vhdl-generate-makefile-1))))
16978 (defun vhdl-get-packages (lib-alist work-library)
16979 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16980 (let (pack-list)
16981 (while lib-alist
16982 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16983 (push (cdar lib-alist) pack-list))
16984 (setq lib-alist (cdr lib-alist)))
16985 pack-list))
16987 (defun vhdl-generate-makefile-1 ()
16988 "Generate Makefile for current project or directory."
16989 ;; scan hierarchy if required
16990 (if (vhdl-project-p)
16991 (unless (or (assoc vhdl-project vhdl-file-alist)
16992 (vhdl-load-cache vhdl-project))
16993 (vhdl-scan-project-contents vhdl-project))
16994 (let ((directory (abbreviate-file-name default-directory)))
16995 (unless (or (assoc directory vhdl-file-alist)
16996 (vhdl-load-cache directory))
16997 (vhdl-scan-directory-contents directory))))
16998 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16999 (project (vhdl-project-p))
17000 (ent-alist (aget vhdl-entity-alist (or project directory) t))
17001 (conf-alist (aget vhdl-config-alist (or project directory) t))
17002 (pack-alist (aget vhdl-package-alist (or project directory) t))
17003 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
17004 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
17005 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
17006 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
17007 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
17008 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
17009 (adjust-case (nth 5 regexp-list))
17010 (work-library (downcase (vhdl-work-library)))
17011 (compile-directory (expand-file-name (vhdl-compile-directory)
17012 default-directory))
17013 (makefile-name (vhdl-makefile-name))
17014 rule-alist arch-alist inst-alist
17015 target-list depend-list unit-list prim-list second-list subcomp-list
17016 lib-alist lib-body-alist pack-list all-pack-list
17017 ent-key ent-file-name arch-key arch-file-name ent-arch-key
17018 conf-key conf-file-name pack-key pack-file-name
17019 ent-entry arch-entry conf-entry pack-entry inst-entry
17020 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
17021 tmp-key tmp-list rule)
17022 ;; check prerequisites
17023 (unless (file-exists-p compile-directory)
17024 (make-directory compile-directory t))
17025 (unless regexp-list
17026 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
17027 vhdl-compiler))
17028 (message "Generating makefile \"%s\"..." makefile-name)
17029 ;; rules for all entities
17030 (setq tmp-list ent-alist)
17031 (while ent-alist
17032 (setq ent-entry (car ent-alist)
17033 ent-key (nth 0 ent-entry))
17034 (when (nth 2 ent-entry)
17035 (setq ent-file-name (if vhdl-compile-absolute-path
17036 (nth 2 ent-entry)
17037 (file-relative-name (nth 2 ent-entry)
17038 compile-directory))
17039 arch-alist (nth 4 ent-entry)
17040 lib-alist (nth 6 ent-entry)
17041 rule (aget rule-alist ent-file-name)
17042 target-list (nth 0 rule)
17043 depend-list (nth 1 rule)
17044 second-list nil
17045 subcomp-list nil)
17046 (setq tmp-key (vhdl-replace-string
17047 ent-regexp (funcall adjust-case ent-key)))
17048 (push (cons ent-key tmp-key) unit-list)
17049 ;; rule target for this entity
17050 (push ent-key target-list)
17051 ;; rule dependencies for all used packages
17052 (setq pack-list (vhdl-get-packages lib-alist work-library))
17053 (setq depend-list (append depend-list pack-list))
17054 (setq all-pack-list pack-list)
17055 ;; add rule
17056 (aput 'rule-alist ent-file-name (list target-list depend-list))
17057 ;; rules for all corresponding architectures
17058 (while arch-alist
17059 (setq arch-entry (car arch-alist)
17060 arch-key (nth 0 arch-entry)
17061 ent-arch-key (concat ent-key "-" arch-key)
17062 arch-file-name (if vhdl-compile-absolute-path
17063 (nth 2 arch-entry)
17064 (file-relative-name (nth 2 arch-entry)
17065 compile-directory))
17066 inst-alist (nth 4 arch-entry)
17067 lib-alist (nth 5 arch-entry)
17068 rule (aget rule-alist arch-file-name)
17069 target-list (nth 0 rule)
17070 depend-list (nth 1 rule))
17071 (setq tmp-key (vhdl-replace-string
17072 arch-regexp
17073 (funcall adjust-case (concat arch-key " " ent-key))))
17074 (setq unit-list
17075 (cons (cons ent-arch-key tmp-key) unit-list))
17076 (push ent-arch-key second-list)
17077 ;; rule target for this architecture
17078 (push ent-arch-key target-list)
17079 ;; rule dependency for corresponding entity
17080 (push ent-key depend-list)
17081 ;; rule dependencies for contained component instantiations
17082 (while inst-alist
17083 (setq inst-entry (car inst-alist))
17084 (when (or (null (nth 8 inst-entry))
17085 (equal (downcase (nth 8 inst-entry)) work-library))
17086 (setq inst-ent-key (or (nth 7 inst-entry)
17087 (nth 5 inst-entry)))
17088 (setq depend-list (cons inst-ent-key depend-list)
17089 subcomp-list (cons inst-ent-key subcomp-list)))
17090 (setq inst-alist (cdr inst-alist)))
17091 ;; rule dependencies for all used packages
17092 (setq pack-list (vhdl-get-packages lib-alist work-library))
17093 (setq depend-list (append depend-list pack-list))
17094 (setq all-pack-list (append all-pack-list pack-list))
17095 ;; add rule
17096 (aput 'rule-alist arch-file-name (list target-list depend-list))
17097 (setq arch-alist (cdr arch-alist)))
17098 (push (list ent-key second-list (append subcomp-list all-pack-list))
17099 prim-list))
17100 (setq ent-alist (cdr ent-alist)))
17101 (setq ent-alist tmp-list)
17102 ;; rules for all configurations
17103 (setq tmp-list conf-alist)
17104 (while conf-alist
17105 (setq conf-entry (car conf-alist)
17106 conf-key (nth 0 conf-entry)
17107 conf-file-name (if vhdl-compile-absolute-path
17108 (nth 2 conf-entry)
17109 (file-relative-name (nth 2 conf-entry)
17110 compile-directory))
17111 ent-key (nth 4 conf-entry)
17112 arch-key (nth 5 conf-entry)
17113 inst-alist (nth 6 conf-entry)
17114 lib-alist (nth 7 conf-entry)
17115 rule (aget rule-alist conf-file-name)
17116 target-list (nth 0 rule)
17117 depend-list (nth 1 rule)
17118 subcomp-list (list ent-key))
17119 (setq tmp-key (vhdl-replace-string
17120 conf-regexp (funcall adjust-case conf-key)))
17121 (push (cons conf-key tmp-key) unit-list)
17122 ;; rule target for this configuration
17123 (push conf-key target-list)
17124 ;; rule dependency for corresponding entity and architecture
17125 (setq depend-list
17126 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
17127 ;; rule dependencies for used packages
17128 (setq pack-list (vhdl-get-packages lib-alist work-library))
17129 (setq depend-list (append depend-list pack-list))
17130 ;; rule dependencies for contained component configurations
17131 (while inst-alist
17132 (setq inst-entry (car inst-alist))
17133 (setq inst-ent-key (nth 2 inst-entry)
17134 ; comp-arch-key (nth 2 inst-entry))
17135 inst-conf-key (nth 4 inst-entry))
17136 (when (equal (downcase (nth 5 inst-entry)) work-library)
17137 (when inst-ent-key
17138 (setq depend-list (cons inst-ent-key depend-list)
17139 subcomp-list (cons inst-ent-key subcomp-list)))
17140 ; (when comp-arch-key
17141 ; (push (concat comp-ent-key "-" comp-arch-key) depend-list))
17142 (when inst-conf-key
17143 (setq depend-list (cons inst-conf-key depend-list)
17144 subcomp-list (cons inst-conf-key subcomp-list))))
17145 (setq inst-alist (cdr inst-alist)))
17146 ;; add rule
17147 (aput 'rule-alist conf-file-name (list target-list depend-list))
17148 (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
17149 (setq conf-alist (cdr conf-alist)))
17150 (setq conf-alist tmp-list)
17151 ;; rules for all packages
17152 (setq tmp-list pack-alist)
17153 (while pack-alist
17154 (setq pack-entry (car pack-alist)
17155 pack-key (nth 0 pack-entry)
17156 pack-body-key nil)
17157 (when (nth 2 pack-entry)
17158 (setq pack-file-name (if vhdl-compile-absolute-path
17159 (nth 2 pack-entry)
17160 (file-relative-name (nth 2 pack-entry)
17161 compile-directory))
17162 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
17163 rule (aget rule-alist pack-file-name)
17164 target-list (nth 0 rule) depend-list (nth 1 rule))
17165 (setq tmp-key (vhdl-replace-string
17166 pack-regexp (funcall adjust-case pack-key)))
17167 (push (cons pack-key tmp-key) unit-list)
17168 ;; rule target for this package
17169 (push pack-key target-list)
17170 ;; rule dependencies for all used packages
17171 (setq pack-list (vhdl-get-packages lib-alist work-library))
17172 (setq depend-list (append depend-list pack-list))
17173 (setq all-pack-list pack-list)
17174 ;; add rule
17175 (aput 'rule-alist pack-file-name (list target-list depend-list))
17176 ;; rules for this package's body
17177 (when (nth 7 pack-entry)
17178 (setq pack-body-key (concat pack-key "-body")
17179 pack-body-file-name (if vhdl-compile-absolute-path
17180 (nth 7 pack-entry)
17181 (file-relative-name (nth 7 pack-entry)
17182 compile-directory))
17183 rule (aget rule-alist pack-body-file-name)
17184 target-list (nth 0 rule)
17185 depend-list (nth 1 rule))
17186 (setq tmp-key (vhdl-replace-string
17187 pack-body-regexp (funcall adjust-case pack-key)))
17188 (setq unit-list
17189 (cons (cons pack-body-key tmp-key) unit-list))
17190 ;; rule target for this package's body
17191 (push pack-body-key target-list)
17192 ;; rule dependency for corresponding package declaration
17193 (push pack-key depend-list)
17194 ;; rule dependencies for all used packages
17195 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
17196 (setq depend-list (append depend-list pack-list))
17197 (setq all-pack-list (append all-pack-list pack-list))
17198 ;; add rule
17199 (aput 'rule-alist pack-body-file-name
17200 (list target-list depend-list)))
17201 (setq prim-list
17202 (cons (list pack-key (when pack-body-key (list pack-body-key))
17203 all-pack-list)
17204 prim-list)))
17205 (setq pack-alist (cdr pack-alist)))
17206 (setq pack-alist tmp-list)
17207 ;; generate Makefile
17208 (let* ((project (aget vhdl-project-alist project))
17209 (compiler (aget vhdl-compiler-alist vhdl-compiler))
17210 (compiler-id (nth 9 compiler))
17211 (library-directory
17212 (vhdl-resolve-env-variable
17213 (vhdl-replace-string
17214 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
17215 compiler-id)))
17216 (makefile-path-name (expand-file-name
17217 makefile-name compile-directory))
17218 (orig-buffer (current-buffer))
17219 cell second-list subcomp-list options unit-key unit-name)
17220 ;; sort lists
17221 (setq unit-list (vhdl-sort-alist unit-list))
17222 (setq prim-list (vhdl-sort-alist prim-list))
17223 (setq tmp-list rule-alist)
17224 (while tmp-list ; pre-sort rule targets
17225 (setq cell (cdar tmp-list))
17226 (setcar cell (sort (car cell) 'string<))
17227 (setq tmp-list (cdr tmp-list)))
17228 (setq rule-alist ; sort by first rule target
17229 (sort rule-alist
17230 (function (lambda (a b)
17231 (string< (car (cadr a)) (car (cadr b)))))))
17232 ;; open and clear Makefile
17233 (set-buffer (find-file-noselect makefile-path-name t t))
17234 (erase-buffer)
17235 (insert "# -*- Makefile -*-\n"
17236 "### " (file-name-nondirectory makefile-name)
17237 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17238 "\n")
17239 (if project
17240 (insert "\n# Project : " (nth 0 project))
17241 (insert "\n# Directory : \"" directory "\""))
17242 (insert "\n# Platform : " vhdl-compiler
17243 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17244 (user-login-name) "\n")
17245 ;; insert compile and option variable settings
17246 (insert "\n\n# Define compilation command and options\n"
17247 "\nCOMPILE = " (nth 0 compiler)
17248 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
17249 (if (equal vhdl-compile-post-command "") ""
17250 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
17251 "\n")
17252 ;; insert library paths
17253 (setq library-directory
17254 (directory-file-name
17255 (if (file-name-absolute-p library-directory)
17256 library-directory
17257 (file-relative-name
17258 (expand-file-name library-directory directory)
17259 compile-directory))))
17260 (insert "\n\n# Define library paths\n"
17261 "\nLIBRARY-" work-library " = " library-directory "\n")
17262 ;; insert variable definitions for all library unit files
17263 (insert "\n\n# Define library unit files\n")
17264 (setq tmp-list unit-list)
17265 (while unit-list
17266 (insert "\nUNIT-" work-library "-" (caar unit-list)
17267 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
17268 (setq unit-list (cdr unit-list)))
17269 ;; insert variable definition for list of all library unit files
17270 (insert "\n\n\n# Define list of all library unit files\n"
17271 "\nALL_UNITS =")
17272 (setq unit-list tmp-list)
17273 (while unit-list
17274 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17275 (setq unit-list (cdr unit-list)))
17276 (insert "\n")
17277 (setq unit-list tmp-list)
17278 ;; insert `make all' rule
17279 (insert "\n\n\n# Rule for compiling entire design\n"
17280 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17281 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17282 " \\\n\t\t$(ALL_UNITS)\n")
17283 ;; insert `make clean' rule
17284 (insert "\n\n# Rule for cleaning entire design\n"
17285 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17286 "\n\t-rm -f $(ALL_UNITS)\n")
17287 ;; insert `make library' rule
17288 (insert "\n\n# Rule for creating library directory\n"
17289 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17290 " \\\n\t\t$(LIBRARY-" work-library ")\n"
17291 "\n$(LIBRARY-" work-library ") :"
17292 "\n\t"
17293 (vhdl-replace-string
17294 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17295 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17296 "\n")
17297 ;; insert '.PHONY' declaration
17298 (insert "\n\n.PHONY : "
17299 (nth 0 vhdl-makefile-default-targets) " "
17300 (nth 1 vhdl-makefile-default-targets) " "
17301 (nth 2 vhdl-makefile-default-targets) "\n")
17302 ;; insert rule for each library unit
17303 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17304 (while prim-list
17305 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17306 (setq subcomp-list
17307 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17308 (setq unit-key (caar prim-list)
17309 unit-name (or (nth 0 (aget ent-alist unit-key t))
17310 (nth 0 (aget conf-alist unit-key t))
17311 (nth 0 (aget pack-alist unit-key t))))
17312 (insert "\n" unit-key)
17313 (unless (equal unit-key unit-name)
17314 (insert " \\\n" unit-name))
17315 (insert " :"
17316 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
17317 (while subcomp-list
17318 (when (and (assoc (car subcomp-list) unit-list)
17319 (not (equal unit-key (car subcomp-list))))
17320 (insert " \\\n\t\t" (car subcomp-list)))
17321 (setq subcomp-list (cdr subcomp-list)))
17322 (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17323 (while second-list
17324 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17325 (setq second-list (cdr second-list)))
17326 (insert "\n")
17327 (setq prim-list (cdr prim-list)))
17328 ;; insert rule for each library unit file
17329 (insert "\n\n# Rules for compiling single library unit files\n")
17330 (while rule-alist
17331 (setq rule (car rule-alist))
17332 ;; get compiler options for this file
17333 (setq options
17334 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17335 ;; insert rule if file is supposed to be compiled
17336 (setq target-list (nth 1 rule)
17337 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17338 ;; insert targets
17339 (setq tmp-list target-list)
17340 (while target-list
17341 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17342 (if (cdr target-list) " \\" " :"))
17343 (setq target-list (cdr target-list)))
17344 (setq target-list tmp-list)
17345 ;; insert file name as first dependency
17346 (insert " \\\n\t\t" (nth 0 rule))
17347 ;; insert dependencies (except if also target or unit does not exist)
17348 (while depend-list
17349 (when (and (not (member (car depend-list) target-list))
17350 (assoc (car depend-list) unit-list))
17351 (insert " \\\n\t\t"
17352 "$(UNIT-" work-library "-" (car depend-list) ")"))
17353 (setq depend-list (cdr depend-list)))
17354 ;; insert compile command
17355 (if options
17356 (insert "\n\t$(COMPILE) "
17357 (if (eq options 'default) "$(OPTIONS)" options) " "
17358 (nth 0 rule)
17359 (if (equal vhdl-compile-post-command "") ""
17360 " $(POST-COMPILE)") "\n")
17361 (setq tmp-list target-list)
17362 (while target-list
17363 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
17364 (if (cdr target-list) " \\" "\n"))
17365 (setq target-list (cdr target-list)))
17366 (setq target-list tmp-list))
17367 (setq rule-alist (cdr rule-alist)))
17368 (insert "\n\n### " makefile-name " ends here\n")
17369 ;; run Makefile generation hook
17370 (run-hooks 'vhdl-makefile-generation-hook)
17371 (message "Generating makefile \"%s\"...done" makefile-name)
17372 ;; save and close file
17373 (if (file-writable-p makefile-path-name)
17374 (progn (save-buffer)
17375 (kill-buffer (current-buffer))
17376 (set-buffer orig-buffer)
17377 (add-to-history 'file-name-history makefile-path-name))
17378 (vhdl-warning-when-idle
17379 (format "File not writable: \"%s\""
17380 (abbreviate-file-name makefile-path-name)))
17381 (switch-to-buffer (current-buffer))))))
17384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17385 ;;; Bug reports
17386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17387 ;; (using `reporter.el')
17389 (defconst vhdl-mode-help-address
17390 "Reto Zimmermann <reto@gnu.org>"
17391 "Address for VHDL Mode bug reports.")
17393 (defun vhdl-submit-bug-report ()
17394 "Submit via mail a bug report on VHDL Mode."
17395 (interactive)
17396 ;; load in reporter
17397 (and
17398 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17399 (let ((reporter-prompt-for-summary-p t))
17400 (reporter-submit-bug-report
17401 vhdl-mode-help-address
17402 (concat "VHDL Mode " vhdl-version)
17403 (list
17404 ;; report all important user options
17405 'vhdl-offsets-alist
17406 'vhdl-comment-only-line-offset
17407 'tab-width
17408 'vhdl-electric-mode
17409 'vhdl-stutter-mode
17410 'vhdl-indent-tabs-mode
17411 'vhdl-project-alist
17412 'vhdl-project
17413 'vhdl-project-file-name
17414 'vhdl-project-auto-load
17415 'vhdl-project-sort
17416 'vhdl-compiler-alist
17417 'vhdl-compiler
17418 'vhdl-compile-use-local-error-regexp
17419 'vhdl-makefile-default-targets
17420 'vhdl-makefile-generation-hook
17421 'vhdl-default-library
17422 'vhdl-standard
17423 'vhdl-basic-offset
17424 'vhdl-upper-case-keywords
17425 'vhdl-upper-case-types
17426 'vhdl-upper-case-attributes
17427 'vhdl-upper-case-enum-values
17428 'vhdl-upper-case-constants
17429 'vhdl-use-direct-instantiation
17430 'vhdl-array-index-record-field-in-sensitivity-list
17431 'vhdl-compose-configuration-name
17432 'vhdl-entity-file-name
17433 'vhdl-architecture-file-name
17434 'vhdl-configuration-file-name
17435 'vhdl-package-file-name
17436 'vhdl-file-name-case
17437 'vhdl-electric-keywords
17438 'vhdl-optional-labels
17439 'vhdl-insert-empty-lines
17440 'vhdl-argument-list-indent
17441 'vhdl-association-list-with-formals
17442 'vhdl-conditions-in-parenthesis
17443 'vhdl-zero-string
17444 'vhdl-one-string
17445 'vhdl-file-header
17446 'vhdl-file-footer
17447 'vhdl-company-name
17448 'vhdl-copyright-string
17449 'vhdl-platform-spec
17450 'vhdl-date-format
17451 'vhdl-modify-date-prefix-string
17452 'vhdl-modify-date-on-saving
17453 'vhdl-reset-kind
17454 'vhdl-reset-active-high
17455 'vhdl-clock-rising-edge
17456 'vhdl-clock-edge-condition
17457 'vhdl-clock-name
17458 'vhdl-reset-name
17459 'vhdl-model-alist
17460 'vhdl-include-port-comments
17461 'vhdl-include-direction-comments
17462 'vhdl-include-type-comments
17463 'vhdl-include-group-comments
17464 'vhdl-actual-generic-name
17465 'vhdl-actual-port-name
17466 'vhdl-instance-name
17467 'vhdl-testbench-entity-name
17468 'vhdl-testbench-architecture-name
17469 'vhdl-testbench-configuration-name
17470 'vhdl-testbench-dut-name
17471 'vhdl-testbench-include-header
17472 'vhdl-testbench-declarations
17473 'vhdl-testbench-statements
17474 'vhdl-testbench-initialize-signals
17475 'vhdl-testbench-include-library
17476 'vhdl-testbench-include-configuration
17477 'vhdl-testbench-create-files
17478 'vhdl-testbench-entity-file-name
17479 'vhdl-testbench-architecture-file-name
17480 'vhdl-compose-create-files
17481 'vhdl-compose-configuration-create-file
17482 'vhdl-compose-configuration-hierarchical
17483 'vhdl-compose-configuration-use-subconfiguration
17484 'vhdl-compose-include-header
17485 'vhdl-compose-architecture-name
17486 'vhdl-components-package-name
17487 'vhdl-use-components-package
17488 'vhdl-self-insert-comments
17489 'vhdl-prompt-for-comments
17490 'vhdl-inline-comment-column
17491 'vhdl-end-comment-column
17492 'vhdl-auto-align
17493 'vhdl-align-groups
17494 'vhdl-align-group-separate
17495 'vhdl-align-same-indent
17496 'vhdl-highlight-keywords
17497 'vhdl-highlight-names
17498 'vhdl-highlight-special-words
17499 'vhdl-highlight-forbidden-words
17500 'vhdl-highlight-verilog-keywords
17501 'vhdl-highlight-translate-off
17502 'vhdl-highlight-case-sensitive
17503 'vhdl-special-syntax-alist
17504 'vhdl-forbidden-words
17505 'vhdl-forbidden-syntax
17506 'vhdl-directive-keywords
17507 'vhdl-speedbar-auto-open
17508 'vhdl-speedbar-display-mode
17509 'vhdl-speedbar-scan-limit
17510 'vhdl-speedbar-jump-to-unit
17511 'vhdl-speedbar-update-on-saving
17512 'vhdl-speedbar-save-cache
17513 'vhdl-speedbar-cache-file-name
17514 'vhdl-index-menu
17515 'vhdl-source-file-menu
17516 'vhdl-hideshow-menu
17517 'vhdl-hide-all-init
17518 'vhdl-print-two-column
17519 'vhdl-print-customize-faces
17520 'vhdl-intelligent-tab
17521 'vhdl-indent-syntax-based
17522 'vhdl-indent-comment-like-next-code-line
17523 'vhdl-word-completion-case-sensitive
17524 'vhdl-word-completion-in-minibuffer
17525 'vhdl-underscore-is-part-of-word
17526 'vhdl-mode-hook)
17527 (function
17528 (lambda ()
17529 (insert
17530 (if vhdl-special-indent-hook
17531 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17532 "vhdl-special-indent-hook is set to '"
17533 (format "%s" vhdl-special-indent-hook)
17534 ".\nPerhaps this is your problem?\n"
17535 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17536 "\n"))))
17538 "Hi Reto,"))))
17541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17542 ;;; Documentation
17543 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17545 (defconst vhdl-doc-release-notes nil
17547 Release Notes for VHDL Mode 3.34
17548 ================================
17550 - Added support for GNU Emacs 22/23/24:
17551 - Compilation error parsing fixed for new `compile.el' package.
17553 - Port translation: Derive actual generic name from formal generic name.
17555 - New user options:
17556 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17559 Release Notes for VHDL Mode 3.33
17560 ================================
17562 New Features
17563 ------------
17565 CONFIGURATION DECLARATION GENERATION:
17566 - Automatic generation of a configuration declaration for a design.
17567 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17570 Key Bindings
17571 ------------
17573 For Emacs compliance the following key bindings have been changed:
17575 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17576 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17577 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17578 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17581 User Options
17582 ------------
17584 `vhdl-configuration-file-name': (new)
17585 Specify how the configuration file name is obtained.
17586 `vhdl-compose-configuration-name': (new)
17587 Specify how the configuration name is obtained.
17588 `vhdl-compose-configuration-create-file': (new)
17589 Specify whether a new file should be created for a configuration.
17590 `vhdl-compose-configuration-hierarchical': (new)
17591 Specify whether hierarchical configurations should be created.
17592 `vhdl-compose-configuration-use-subconfiguration': (new)
17593 Specify whether subconfigurations should be used inside configurations.
17594 `vhdl-makefile-default-targets': (new)
17595 Customize names of Makefile default targets.
17596 `vhdl-indent-comment-like-next-code-line': (new)
17597 Specify whether comment lines are indented like following code line.
17598 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17599 Specify whether to include array indices / record fields in sensitivity list.
17603 (defconst vhdl-doc-keywords nil
17605 Reserved words in VHDL
17606 ----------------------
17608 VHDL'93/02 (IEEE Std 1076-1993/2002):
17609 `vhdl-02-keywords' : keywords
17610 `vhdl-02-types' : standardized types
17611 `vhdl-02-attributes' : standardized attributes
17612 `vhdl-02-enum-values' : standardized enumeration values
17613 `vhdl-02-functions' : standardized functions
17614 `vhdl-02-packages' : standardized packages and libraries
17616 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17617 `vhdl-ams-keywords' : keywords
17618 `vhdl-ams-types' : standardized types
17619 `vhdl-ams-attributes' : standardized attributes
17620 `vhdl-ams-enum-values' : standardized enumeration values
17621 `vhdl-ams-constants' : standardized constants
17622 `vhdl-ams-functions' : standardized functions
17624 Math Packages (IEEE Std 1076.2):
17625 `vhdl-math-types' : standardized types
17626 `vhdl-math-constants' : standardized constants
17627 `vhdl-math-functions' : standardized functions
17628 `vhdl-math-packages' : standardized packages
17630 Forbidden words:
17631 `vhdl-verilog-keywords' : Verilog reserved words
17633 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17636 (defconst vhdl-doc-coding-style nil
17638 For VHDL coding style and naming convention guidelines, see the following
17639 references:
17641 \[1] Ben Cohen.
17642 \"VHDL Coding Styles and Methodologies\".
17643 Kluwer Academic Publishers, 1999.
17644 http://members.aol.com/vhdlcohen/vhdl/
17646 \[2] Michael Keating and Pierre Bricaud.
17647 \"Reuse Methodology Manual, Second Edition\".
17648 Kluwer Academic Publishers, 1999.
17649 http://www.openmore.com/openmore/rmm2.html
17651 \[3] European Space Agency.
17652 \"VHDL Modelling Guidelines\".
17653 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17655 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17656 to visually support naming conventions.")
17659 (defun vhdl-version ()
17660 "Echo the current version of VHDL Mode in the minibuffer."
17661 (interactive)
17662 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17663 (vhdl-keep-region-active))
17665 (defun vhdl-doc-variable (variable)
17666 "Display VARIABLE's documentation in *Help* buffer."
17667 (interactive)
17668 (unless (featurep 'xemacs)
17669 (help-setup-xref (list #'vhdl-doc-variable variable)
17670 (called-interactively-p 'interactive)))
17671 (with-output-to-temp-buffer
17672 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17673 (princ (documentation-property variable 'variable-documentation))
17674 (with-current-buffer standard-output
17675 (help-mode))
17676 (help-print-return-message)))
17678 (defun vhdl-doc-mode ()
17679 "Display VHDL Mode documentation in *Help* buffer."
17680 (interactive)
17681 (unless (featurep 'xemacs)
17682 (help-setup-xref (list #'vhdl-doc-mode)
17683 (called-interactively-p 'interactive)))
17684 (with-output-to-temp-buffer
17685 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17686 (princ mode-name)
17687 (princ " mode:\n")
17688 (princ (documentation 'vhdl-mode))
17689 (with-current-buffer standard-output
17690 (help-mode))
17691 (help-print-return-message)))
17694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17696 (provide 'vhdl-mode)
17698 ;;; vhdl-mode.el ends here