* lisp/progmodes/vhdl-mode.el: Avoid add-to-list on local vars
[emacs.git] / lisp / progmodes / vhdl-mode.el
blob6c76d7e4ad2a3be75bb5454ab8c825904dd4c114
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2017 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.38.1"
17 "VHDL Mode version number.")
19 (defconst vhdl-time-stamp "2015-03-12"
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/'02/'08 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 24.1
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 ;; Installation
80 ;; Prerequisites: GNU Emacs 20/21/22/23/24, XEmacs 20/21.
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 (eval-when-compile (require 'cl))
130 (eval-and-compile
131 ;; Before Emacs-24.4, `pushnew' expands to runtime calls to `cl-adjoin'
132 ;; even for relatively simple cases such as used here. We only test <25
133 ;; because it's easier and sufficient.
134 (when (or (featurep 'xemacs) (< emacs-major-version 25))
135 (require 'cl)))
137 ;; Emacs 21+ handling
138 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
139 "Non-nil if GNU Emacs 21, 22, ... is used.")
140 ;; Emacs 22+ handling
141 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
142 "Non-nil if GNU Emacs 22, ... is used.")
144 (defvar compilation-file-regexp-alist)
145 (defvar conf-alist)
146 (defvar conf-entry)
147 (defvar conf-key)
148 (defvar ent-alist)
149 (defvar itimer-version)
150 (defvar lazy-lock-defer-contextually)
151 (defvar lazy-lock-defer-on-scrolling)
152 (defvar lazy-lock-defer-on-the-fly)
153 (defvar speedbar-attached-frame)
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
157 ;;; Variables
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
160 ;; help function for user options
161 (defun vhdl-custom-set (variable value &rest functions)
162 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
163 (if (fboundp 'custom-set-default)
164 (custom-set-default variable value)
165 (set-default variable value))
166 (while functions
167 (when (fboundp (car functions)) (funcall (car functions)))
168 (setq functions (cdr functions))))
170 (defun vhdl-widget-directory-validate (widget)
171 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
172 '/' or is empty)."
173 (let ((val (widget-value widget)))
174 (unless (string-match "^\\(\\|.*/\\)$" val)
175 (widget-put widget :error "Invalid directory entry: must end with `/'")
176 widget)))
178 ;; help string for user options
179 (defconst vhdl-name-doc-string "
181 FROM REGEXP is a regular expression matching the original name:
182 \".*\" matches the entire string
183 \"\\(...\\)\" matches a substring
184 TO STRING specifies the string to be inserted as new name:
185 \"\\&\" means substitute entire matched text
186 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
187 Examples:
188 \".*\" \"\\&\" inserts original string
189 \".*\" \"\\&_i\" attaches \"_i\" to original string
190 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
191 \".*\" \"foo\" inserts constant string \"foo\"
192 \".*\" \"\" inserts empty string")
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 ;; User variables (customization options)
197 (defgroup vhdl nil
198 "Customizations for VHDL Mode."
199 :prefix "vhdl-"
200 :group 'languages
201 ; :version "21.2" ; comment out for XEmacs
204 (defgroup vhdl-mode nil
205 "Customizations for modes."
206 :group 'vhdl)
208 (defcustom vhdl-indent-tabs-mode nil
209 "Non-nil means indentation can insert tabs.
210 Overrides local variable `indent-tabs-mode'."
211 :type 'boolean
212 :group 'vhdl-mode)
215 (defgroup vhdl-compile nil
216 "Customizations for compilation."
217 :group 'vhdl)
219 (defcustom vhdl-compiler-alist
221 ;; 60: docal <= false;
222 ;; ^^^^^
223 ;; [Error] Assignment error: variable is illegal target of signal assignment
224 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
225 nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
226 ("^\\s-+\\([0-9]+\\):\\s-+" nil 1 nil) ("^Compiling file \\(.+\\)" 1)
227 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
228 "PACK/\\1.vif" "BODY/\\1.vif" upcase))
229 ;; Aldec
230 ;; COMP96 ERROR COMP96_0018: "Identifier expected." "test.vhd" 66 3
231 ("Aldec" "vcom" "-work \\1" "make" "-f \\1"
232 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
233 ("^.* ERROR [^:]+: \".*\" \"\\([^ \t\n]+\\)\" \\([0-9]+\\) \\([0-9]+\\)" 1 2 3) ("" 0)
234 nil)
235 ;; Cadence Leapfrog: cv -file test.vhd
236 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
237 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
238 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
239 ("^duluth: \\*E,[0-9]+ (\\([^ \t\n]+\\),\\([0-9]+\\)):" 1 2 nil) ("" 0)
240 ("\\1/entity" "\\2/\\1" "\\1/configuration"
241 "\\1/package" "\\1/body" downcase))
242 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
243 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
244 ;; (PLL_400X_TOP) is not declared [10.3].
245 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
246 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
247 ("^ncvhdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
248 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
249 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
250 ;; ghdl vhdl
251 ;; ghdl -a bad_counter.vhdl
252 ;; bad_counter.vhdl:13:14: operator "=" is overloaded
253 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
254 nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
255 ("^ghdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
256 ("\\1/entity" "\\2/\\1" "\\1/configuration"
257 "\\1/package" "\\1/body" downcase))
258 ;; IBM Compiler
259 ;; 00 COACHDL* | [CCHDL-1]: File: adder.vhd, line.column: 120.6
260 ("IBM Compiler" "g2tvc" "-src" "precomp" "\\1"
261 nil "mkdir \\1" "./" "work/" "Makefile" "ibm"
262 ("^[0-9]+ COACHDL.*: File: \\([^ \t\n]+\\), *line.column: \\([0-9]+\\).\\([0-9]+\\)" 1 2 3) (" " 0)
263 nil)
264 ;; Ikos Voyager: analyze test.vhd
265 ;; analyze test.vhd
266 ;; E L4/C5: this library unit is inaccessible
267 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
268 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
269 ("^E L\\([0-9]+\\)/C\\([0-9]+\\):" nil 1 2)
270 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
271 nil)
272 ;; ModelSim, Model Technology: vcom test.vhd
273 ;; ERROR: test.vhd(14): Unknown identifier: positiv
274 ;; WARNING[2]: test.vhd(85): Possible infinite loop
275 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
276 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
277 ;; ** Error: counter_rtl.vhd(18): Nonresolved signal 'hallo' has multiple sources.
278 ;; Drivers:
279 ;; counter_rtl.vhd(27):Conditional signal assignment line__27
280 ;; counter_rtl.vhd(29):Conditional signal assignment line__29
281 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
282 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
283 ("\\(ERROR:\\|WARNING\\[[0-9]+\\]:\\|\\*\\* Error:\\|\\*\\* Warning: \\[[0-9]+\\]\\| +\\) \\([^ ]+\\)(\\([0-9]+\\)):" 2 3 nil)
284 ("" 0)
285 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
286 "\\1/_primary.dat" "\\1/body.dat" downcase))
287 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
288 ;; test.vhd:34: error message
289 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
290 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
291 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
292 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
293 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
294 ;; Quartus compiler
295 ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
296 ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
297 ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
298 ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
299 ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
300 ("Quartus" "make" "-work \\1" "make" "-f \\1"
301 nil "mkdir \\1" "./" "work/" "Makefile" "quartus"
302 ("^\\(Error\\|Warning\\): .* \\([^ \t\n]+\\)(\\([0-9]+\\))" 2 3 nil) ("" 0)
303 nil)
304 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
305 ;; ERROR: test.vhd(24): near "dnd": expecting: END
306 ;; WARNING[4]: test.vhd(30): A space is required between ...
307 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
308 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
309 ("^\\(ERROR\\|WARNING\\)[^:]*: \\([^ \t\n]+\\)(\\([0-9]+\\)):" 2 3 nil) ("" 0)
310 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
311 "\\1/_primary.dat" "\\1/body.dat" downcase))
312 ;; Savant: scram -publish-cc test.vhd
313 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
314 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
315 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
316 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
317 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
318 "\\1_config.vhdl" "\\1_package.vhdl"
319 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
320 ;; Simili: vhdlp -work test.vhd
321 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
322 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
323 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
324 ("^\\(Error\\|Warning\\): \\w+: \\([^ \t\n]+\\): (line \\([0-9]+\\)): " 2 3 nil) ("" 0)
325 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
326 "\\1/prim.var" "\\1/_body.var" downcase))
327 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
328 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
329 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
330 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
331 ("^ *ERROR\\[[0-9]+]::File \\([^ \t\n]+\\) Line \\([0-9]+\\):" 1 2 nil) ("" 0)
332 nil)
333 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
334 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
335 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
336 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
337 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
338 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
339 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
340 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
341 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
342 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
343 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
344 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
345 ;; Synplify:
346 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
347 ("Synplify" "n/a" "n/a" "make" "-f \\1"
348 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
349 ("^@[EWN]:\"\\([^ \t\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
350 nil)
351 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
352 ;; Compiling "test.vhd" line 1...
353 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
354 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
355 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
356 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
357 ("^ *Compiling \"\\(.+\\)\" " 1)
358 nil)
359 ;; VeriBest: vc vhdl test.vhd
360 ;; (no file name printed out!)
361 ;; 32: Z <= A and BitA ;
362 ;; ^^^^
363 ;; [Error] Name BITA is unknown
364 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
365 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
366 ("^ +\\([0-9]+\\): +[^ ]" nil 1 nil) ("" 0)
367 nil)
368 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
369 ;; Compiling "test.vhd" line 1...
370 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
371 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
372 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
373 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
374 ("^ *Compiling \"\\(.+\\)\" " 1)
375 nil)
376 ;; Xilinx XST:
377 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
378 ("Xilinx XST" "xflow" "" "make" "-f \\1"
379 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
380 ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \t\n]+\\)\" Line \\([0-9]+\\)\\." 1 2 nil) ("" 0)
381 nil)
383 "List of available VHDL compilers and their properties.
384 Each list entry specifies the following items for a compiler:
385 Compiler:
386 Compiler name : name used in option `vhdl-compiler' to choose compiler
387 Compile command : command used for source file compilation
388 Compile options : compile options (\"\\1\" inserts library name)
389 Make command : command used for compilation using a Makefile
390 Make options : make options (\"\\1\" inserts Makefile name)
391 Generate Makefile: use built-in function or command to generate a Makefile
392 (\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
393 Library command : command to create library directory (\"\\1\" inserts
394 library directory, \"\\2\" inserts library name)
395 Compile directory: where compilation is run and the Makefile is placed
396 Library directory: directory of default library
397 Makefile name : name of Makefile (default is \"Makefile\")
398 ID string : compiler identification string (see `vhdl-project-alist')
399 Error message:
400 Regexp : regular expression to match error messages (*)
401 File subexp index: index of subexpression that matches the file name
402 Line subexp index: index of subexpression that matches the line number
403 Column subexp idx: index of subexpression that matches the column number
404 File message:
405 Regexp : regular expression to match a file name message
406 File subexp index: index of subexpression that matches the file name
407 Unit-to-file name mapping: mapping of library unit names to names of files
408 generated by the compiler (used for Makefile generation)
409 To string : string a name is mapped to (\"\\1\" inserts the unit name,
410 \"\\2\" inserts the entity name for architectures,
411 \"\\3\" inserts the library name)
412 Case adjustment : adjust case of inserted unit names
414 \(*) The regular expression must match the error message starting from the
415 beginning of the line (but not necessarily to the end of the line).
417 Compile options allows insertion of the library name (see `vhdl-project-alist')
418 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
420 For Makefile generation, the built-in function can be used (requires
421 specification of the unit-to-file name mapping). Alternatively, an
422 external command can be specified. Work directory allows specification of
423 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
424 used for Makefile generation). To use another library name than \"work\",
425 customize `vhdl-project-alist'. The library command is inserted in Makefiles
426 to automatically create the library directory if not existent.
428 Compile options, compile directory, library directory, and Makefile name are
429 overwritten by the project settings if a project is defined (see
430 `vhdl-project-alist'). Directory paths are relative to the source file
431 directory.
433 Some compilers do not include the file name in the error message, but print
434 out a file name message in advance. In this case, set \"File Subexp Index\"
435 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
436 If no file name at all is printed out, set both \"File Message\" entries to 0
437 \(a default file name message will be printed out instead, does not work in
438 XEmacs).
440 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
441 assigning its name to option `vhdl-compiler'.
443 Please send any missing or erroneous compiler properties to the maintainer for
444 updating.
446 NOTE: Activate new error and file message regexps and reflect the new setting
447 in the choice list of option `vhdl-compiler' by restarting Emacs."
448 :type '(repeat
449 (list :tag "Compiler" :indent 2
450 (string :tag "Compiler name ")
451 (string :tag "Compile command ")
452 (string :tag "Compile options " "-work \\1")
453 (string :tag "Make command " "make")
454 (string :tag "Make options " "-f \\1")
455 (choice :tag "Generate Makefile "
456 (const :tag "Built-in function" nil)
457 (string :tag "Command" "vmake \\2 > \\1"))
458 (string :tag "Library command " "mkdir \\1")
459 (directory :tag "Compile directory "
460 :validate vhdl-widget-directory-validate "./")
461 (directory :tag "Library directory "
462 :validate vhdl-widget-directory-validate "work/")
463 (file :tag "Makefile name " "Makefile")
464 (string :tag "ID string ")
465 (list :tag "Error message" :indent 4
466 (regexp :tag "Regexp ")
467 (choice :tag "File subexp "
468 (integer :tag "Index")
469 (const :tag "No file name" nil))
470 (integer :tag "Line subexp index")
471 (choice :tag "Column subexp "
472 (integer :tag "Index")
473 (const :tag "No column number" nil)))
474 (list :tag "File message" :indent 4
475 (regexp :tag "Regexp ")
476 (integer :tag "File subexp index"))
477 (choice :tag "Unit-to-file name mapping"
478 :format "%t: %[Value Menu%] %v\n"
479 (const :tag "Not defined" nil)
480 (list :tag "To string" :indent 4
481 (string :tag "Entity " "\\1.vhd")
482 (string :tag "Architecture " "\\2_\\1.vhd")
483 (string :tag "Configuration " "\\1.vhd")
484 (string :tag "Package " "\\1.vhd")
485 (string :tag "Package Body " "\\1_body.vhd")
486 (choice :tag "Case adjustment "
487 (const :tag "None" identity)
488 (const :tag "Upcase" upcase)
489 (const :tag "Downcase" downcase))))))
490 :set (lambda (variable value)
491 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
492 :version "24.4"
493 :group 'vhdl-compile)
495 (defcustom vhdl-compiler "GHDL"
496 "Specifies the VHDL compiler to be used for syntax analysis.
497 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
498 :type (let ((alist vhdl-compiler-alist) list)
499 (while alist
500 (push (list 'const (caar alist)) list)
501 (setq alist (cdr alist)))
502 (append '(choice) (nreverse list)))
503 :group 'vhdl-compile)
505 (defcustom vhdl-compile-use-local-error-regexp nil
506 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
507 In this case, only error message regexps for VHDL compilers are active if
508 compilation is started from a VHDL buffer. Otherwise, the error message
509 regexps are appended to the predefined global regexps, and all regexps are
510 active all the time. Note that by doing that, the predefined global regexps
511 might result in erroneous parsing of error messages for some VHDL compilers.
513 NOTE: Activate the new setting by restarting Emacs."
514 :version "25.1" ; t -> nil
515 :type 'boolean
516 :group 'vhdl-compile)
518 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
519 "List of default target names in Makefiles.
520 Automatically generated Makefiles include three default targets to compile
521 the entire design, clean the entire design and to create the design library.
522 This option allows you to change the names of these targets to avoid conflicts
523 with other user Makefiles."
524 :type '(list (string :tag "Compile entire design")
525 (string :tag "Clean entire design ")
526 (string :tag "Create design library"))
527 :version "24.3"
528 :group 'vhdl-compile)
530 (defcustom vhdl-makefile-generation-hook nil
531 "Functions to run at the end of Makefile generation.
532 Allows you to insert user specific parts into a Makefile.
534 Example:
535 (lambda nil
536 (re-search-backward \"^# Rule for compiling entire design\")
537 (insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
538 :type 'hook
539 :group 'vhdl-compile)
541 (defcustom vhdl-default-library "work"
542 "Name of default library.
543 Is overwritten by project settings if a project is active."
544 :type 'string
545 :group 'vhdl-compile)
548 (defgroup vhdl-project nil
549 "Customizations for projects."
550 :group 'vhdl)
552 (defcustom vhdl-project-alist
553 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
554 "~/example1/" ("src/system/" "src/components/") ""
555 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
556 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
557 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
558 ("Example 2" "Individual source files, multiple compilers in different directories"
559 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
560 nil "\\1/" "work" "\\1/work/" "Makefile" "")
561 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
562 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
563 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
564 -------------------------------------------------------------------------------
565 -- This is a multi-line project description
566 -- that can be used as a project dependent part of the file header.
568 "List of projects and their properties.
569 Name : name used in option `vhdl-project' to choose project
570 Title : title of project (single-line string)
571 Default directory: default project directory (absolute path)
572 Sources : a) source files : path + \"/\" + file name
573 b) directory : path + \"/\"
574 c) directory tree: \"-r \" + path + \"/\"
575 Exclude regexp : matches file/directory names to be excluded as sources
576 Compile options : project-specific options for each compiler
577 Compiler name : name of compiler for which these options are valid
578 Compile options: project-specific compiler options
579 (\"\\1\" inserts library name, \"\\2\" default options)
580 Make options: project-specific make options
581 (\"\\1\" inserts Makefile name, \"\\2\" default options)
582 Exceptions : file-specific exceptions
583 File name regexp: matches file names for which exceptions are valid
584 - Options : file-specific compiler options string
585 (\"\\1\" inserts library name, \"\\2\" default options,
586 \"\\3\" project-specific options)
587 - Do not compile: do not compile this file (in Makefile)
588 Compile directory: where compilation is run and the Makefile is placed
589 (\"\\1\" inserts compiler ID string)
590 Library name : name of library (default is \"work\")
591 Library directory: path to library (\"\\1\" inserts compiler ID string)
592 Makefile name : name of Makefile
593 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
594 Description : description of project (multi-line string)
596 Project title and description are used to insert into the file header (see
597 option `vhdl-file-header').
599 The default directory must have an absolute path (use `M-TAB' for completion).
600 All other paths can be absolute or relative to the default directory. All
601 paths must end with `/'.
603 The design units found in the sources (files and directories) are shown in the
604 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
605 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
606 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
607 specified, the default directory is taken as source directory. Otherwise,
608 the default directory is only taken as source directory if there is a sources
609 entry with the empty string or \"./\". Exclude regexp allows you to filter
610 out specific file and directory names from the list of sources (e.g. CVS
611 directories).
613 Files are compiled in the compile directory. Makefiles are also placed into
614 the compile directory. Library directory specifies which directory the
615 compiler compiles into (used to generate the Makefile).
617 Since different compile/library directories and Makefiles may exist for
618 different compilers within one project, these paths and names allow the
619 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
620 Compile options, compile directory, library directory, and Makefile name
621 overwrite the settings of the current compiler.
623 File-specific compiler options (highest priority) overwrite project-specific
624 options which overwrite default options (lowest priority). Lower priority
625 options can be inserted in higher priority options. This allows you to reuse
626 default options (e.g. \"-file\") in project- or file-specific options (e.g.
627 \"-93 -file\").
629 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
630 by restarting Emacs."
631 :type `(repeat
632 (list :tag "Project" :indent 2
633 (string :tag "Name ")
634 (string :tag "Title ")
635 (directory :tag "Default directory"
636 :validate vhdl-widget-directory-validate
637 ,(abbreviate-file-name default-directory))
638 (repeat :tag "Sources " :indent 4
639 (directory :format " %v" "./"))
640 (regexp :tag "Exclude regexp ")
641 (repeat
642 :tag "Compile options " :indent 4
643 (list :tag "Compiler" :indent 6
644 ,(let ((alist vhdl-compiler-alist) list)
645 (while alist
646 (push (list 'const (caar alist)) list)
647 (setq alist (cdr alist)))
648 (append '(choice :tag "Compiler name")
649 (nreverse list)))
650 (string :tag "Compile options" "\\2")
651 (string :tag "Make options " "\\2")
652 (repeat
653 :tag "Exceptions " :indent 8
654 (cons :format "%v"
655 (regexp :tag "File name regexp ")
656 (choice :format "%[Value Menu%] %v"
657 (string :tag "Options" "\\3")
658 (const :tag "Do not compile" nil))))))
659 (directory :tag "Compile directory"
660 :validate vhdl-widget-directory-validate "./")
661 (string :tag "Library name " "work")
662 (directory :tag "Library directory"
663 :validate vhdl-widget-directory-validate "work/")
664 (file :tag "Makefile name " "Makefile")
665 (string :tag "Description: (type `C-j' for newline)"
666 :format "%t\n%v\n")))
667 :set (lambda (variable value)
668 (vhdl-custom-set variable value
669 'vhdl-update-mode-menu
670 'vhdl-speedbar-refresh))
671 :group 'vhdl-project)
673 (defcustom vhdl-project nil
674 "Specifies the default for the current project.
675 Select a project name from the ones defined in option `vhdl-project-alist'.
676 Is used to determine the project title and description to be inserted in file
677 headers and the source files/directories to be scanned in the hierarchy
678 browser. The current project can also be changed temporarily in the menu."
679 :type (let ((alist vhdl-project-alist) list)
680 (while alist
681 (push (list 'const (caar alist)) list)
682 (setq alist (cdr alist)))
683 (append '(choice (const :tag "None" nil) (const :tag "--"))
684 (nreverse list)))
685 :group 'vhdl-project)
687 (defcustom vhdl-project-file-name '("\\1.prj")
688 "List of file names/paths for importing/exporting project setups.
689 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
690 replaced by the user name (allows you to have user-specific project setups).
691 The first entry is used as file name to import/export individual project
692 setups. All entries are used to automatically import project setups at
693 startup (see option `vhdl-project-auto-load'). Projects loaded from the
694 first entry are automatically made current. Hint: specify local project
695 setups in first entry, global setups in following entries; loading a local
696 project setup will make it current, while loading the global setups
697 is done without changing the current project.
698 Names can also have an absolute path (i.e. project setups can be stored
699 in global directories)."
700 :type '(repeat (string :tag "File name" "\\1.prj"))
701 :group 'vhdl-project)
703 (defcustom vhdl-project-auto-load '(startup)
704 "Automatically load project setups from files.
705 All project setup files that match the file names specified in option
706 `vhdl-project-file-name' are automatically loaded. The project of the
707 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
708 entry is activated.
709 A project setup file can be obtained by exporting a project (see menu).
710 At startup: project setup file is loaded at Emacs startup"
711 :type '(set (const :tag "At startup" startup))
712 :group 'vhdl-project)
714 (defcustom vhdl-project-sort t
715 "Non-nil means projects are displayed in alphabetical order."
716 :type 'boolean
717 :group 'vhdl-project)
720 (defgroup vhdl-style nil
721 "Customizations for coding styles."
722 :group 'vhdl
723 :group 'vhdl-template
724 :group 'vhdl-port
725 :group 'vhdl-compose)
727 (defcustom vhdl-standard '(93 nil)
728 "VHDL standards used.
729 Basic standard:
730 VHDL'87 : IEEE Std 1076-1987
731 VHDL'93/02 : IEEE Std 1076-1993/2002
732 VHDL'08 : IEEE Std 1076-2008
733 Additional standards:
734 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
735 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
737 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
738 \"Activate Options\"."
739 :type '(list (choice :tag "Basic standard"
740 (const :tag "VHDL'87" 87)
741 (const :tag "VHDL'93/02" 93)
742 (const :tag "VHDL'08" 08))
743 (set :tag "Additional standards" :indent 2
744 (const :tag "VHDL-AMS" ams)
745 (const :tag "Math packages" math)))
746 :set (lambda (variable value)
747 (vhdl-custom-set variable value
748 'vhdl-template-map-init
749 'vhdl-mode-abbrev-table-init
750 'vhdl-template-construct-alist-init
751 'vhdl-template-package-alist-init
752 'vhdl-update-mode-menu
753 'vhdl-words-init 'vhdl-font-lock-init))
754 :group 'vhdl-style)
756 (defcustom vhdl-basic-offset 2
757 "Amount of basic offset used for indentation.
758 This value is used by + and - symbols in `vhdl-offsets-alist'."
759 :type 'integer
760 :group 'vhdl-style)
762 (defcustom vhdl-upper-case-keywords nil
763 "Non-nil means convert keywords to upper case.
764 This is done when typed or expanded or by the fix case functions."
765 :type 'boolean
766 :set (lambda (variable value)
767 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
768 :group 'vhdl-style)
770 (defcustom vhdl-upper-case-types nil
771 "Non-nil means convert standardized types to upper case.
772 This is done when expanded or by the fix case functions."
773 :type 'boolean
774 :set (lambda (variable value)
775 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
776 :group 'vhdl-style)
778 (defcustom vhdl-upper-case-attributes nil
779 "Non-nil means convert standardized attributes to upper case.
780 This is done when expanded or by the fix case functions."
781 :type 'boolean
782 :set (lambda (variable value)
783 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
784 :group 'vhdl-style)
786 (defcustom vhdl-upper-case-enum-values nil
787 "Non-nil means convert standardized enumeration values to upper case.
788 This is done when expanded or by the fix case functions."
789 :type 'boolean
790 :set (lambda (variable value)
791 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
792 :group 'vhdl-style)
794 (defcustom vhdl-upper-case-constants t
795 "Non-nil means convert standardized constants to upper case.
796 This is done when expanded."
797 :type 'boolean
798 :set (lambda (variable value)
799 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
800 :group 'vhdl-style)
802 (defcustom vhdl-use-direct-instantiation 'standard
803 "Non-nil means use VHDL'93 direct component instantiation.
804 Never : never
805 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
806 Always : always"
807 :type '(choice (const :tag "Never" never)
808 (const :tag "Standard" standard)
809 (const :tag "Always" always))
810 :group 'vhdl-style)
812 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
813 "Non-nil means include array indices / record fields in sensitivity list.
814 If a signal read in a process is a record field or pointed to by an array
815 index, the record field or array index is included with the record name in
816 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
817 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
818 :type 'boolean
819 :version "24.3"
820 :group 'vhdl-style)
822 (defgroup vhdl-naming nil
823 "Customizations for naming conventions."
824 :group 'vhdl)
826 (defcustom vhdl-entity-file-name '(".*" . "\\&")
827 (concat
828 "Specifies how the entity file name is obtained.
829 The entity file name can be obtained by modifying the entity name (e.g.
830 attaching or stripping off a substring). The file extension is automatically
831 taken from the file name of the current buffer."
832 vhdl-name-doc-string)
833 :type '(cons (regexp :tag "From regexp")
834 (string :tag "To string "))
835 :group 'vhdl-naming
836 :group 'vhdl-compose)
838 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
839 (concat
840 "Specifies how the architecture file name is obtained.
841 The architecture file name can be obtained by modifying the entity
842 and/or architecture name (e.g. attaching or stripping off a substring). The
843 file extension is automatically taken from the file name of the current
844 buffer. The string that is matched against the regexp is the concatenation
845 of the entity and the architecture name separated by a space. This gives
846 access to both names (see default setting as example)."
847 vhdl-name-doc-string)
848 :type '(cons (regexp :tag "From regexp")
849 (string :tag "To string "))
850 :group 'vhdl-naming
851 :group 'vhdl-compose)
853 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
854 (concat
855 "Specifies how the configuration file name is obtained.
856 The configuration file name can be obtained by modifying the configuration
857 name (e.g. attaching or stripping off a substring). The file extension is
858 automatically taken from the file name of the current buffer."
859 vhdl-name-doc-string)
860 :type '(cons (regexp :tag "From regexp")
861 (string :tag "To string "))
862 :group 'vhdl-naming
863 :group 'vhdl-compose)
865 (defcustom vhdl-package-file-name '(".*" . "\\&")
866 (concat
867 "Specifies how the package file name is obtained.
868 The package file name can be obtained by modifying the package name (e.g.
869 attaching or stripping off a substring). The file extension is automatically
870 taken from the file name of the current buffer. Package files can be created
871 in a different directory by prepending a relative or absolute path to the
872 file name."
873 vhdl-name-doc-string)
874 :type '(cons (regexp :tag "From regexp")
875 (string :tag "To string "))
876 :group 'vhdl-naming
877 :group 'vhdl-compose)
879 (defcustom vhdl-file-name-case 'identity
880 "Specifies how to change case for obtaining file names.
881 When deriving a file name from a VHDL unit name, case can be changed as
882 follows:
883 As Is: case is not changed (taken as is)
884 Lower Case: whole name is changed to lower case
885 Upper Case: whole name is changed to upper case
886 Capitalize: first letter of each word in name is capitalized"
887 :type '(choice (const :tag "As Is" identity)
888 (const :tag "Lower Case" downcase)
889 (const :tag "Upper Case" upcase)
890 (const :tag "Capitalize" capitalize))
891 :group 'vhdl-naming
892 :group 'vhdl-compose)
895 (defgroup vhdl-template nil
896 "Customizations for electrification."
897 :group 'vhdl)
899 (defcustom vhdl-electric-keywords '(vhdl user)
900 "Type of keywords for which electrification is enabled.
901 VHDL keywords: invoke built-in templates
902 User keywords: invoke user models (see option `vhdl-model-alist')"
903 :type '(set (const :tag "VHDL keywords" vhdl)
904 (const :tag "User model keywords" user))
905 :set (lambda (variable value)
906 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
907 :group 'vhdl-template)
909 (defcustom vhdl-optional-labels 'process
910 "Constructs for which labels are to be queried.
911 Template generators prompt for optional labels for:
912 None : no constructs
913 Processes only: processes only (also procedurals in VHDL-AMS)
914 All constructs: all constructs with optional labels and keyword END"
915 :type '(choice (const :tag "None" none)
916 (const :tag "Processes only" process)
917 (const :tag "All constructs" all))
918 :group 'vhdl-template)
920 (defcustom vhdl-insert-empty-lines 'unit
921 "Specifies whether to insert empty lines in some templates.
922 This improves readability of code. Empty lines are inserted in:
923 None : no constructs
924 Design units only: entities, architectures, configurations, packages only
925 All constructs : also all constructs with BEGIN...END parts
927 Replaces option `vhdl-additional-empty-lines'."
928 :type '(choice (const :tag "None" none)
929 (const :tag "Design units only" unit)
930 (const :tag "All constructs" all))
931 :group 'vhdl-template
932 :group 'vhdl-port
933 :group 'vhdl-compose)
935 (defcustom vhdl-argument-list-indent nil
936 "Non-nil means indent argument lists relative to opening parenthesis.
937 That is, argument, association, and port lists start on the same line as the
938 opening parenthesis and subsequent lines are indented accordingly.
939 Otherwise, lists start on a new line and are indented as normal code."
940 :type 'boolean
941 :group 'vhdl-template
942 :group 'vhdl-port
943 :group 'vhdl-compose)
945 (defcustom vhdl-association-list-with-formals t
946 "Non-nil means write association lists with formal parameters.
947 Templates prompt for formal and actual parameters (ports/generics).
948 When pasting component instantiations, formals are included.
949 If nil, only a list of actual parameters is entered."
950 :type 'boolean
951 :group 'vhdl-template
952 :group 'vhdl-port
953 :group 'vhdl-compose)
955 (defcustom vhdl-conditions-in-parenthesis nil
956 "Non-nil means place parenthesis around condition expressions."
957 :type 'boolean
958 :group 'vhdl-template)
960 (defcustom vhdl-sensitivity-list-all t
961 "Non-nil means use `all' keyword in sensitivity list."
962 :version "25.1"
963 :type 'boolean
964 :group 'vhdl-template)
966 (defcustom vhdl-zero-string "'0'"
967 "String to use for a logic zero."
968 :type 'string
969 :group 'vhdl-template)
971 (defcustom vhdl-one-string "'1'"
972 "String to use for a logic one."
973 :type 'string
974 :group 'vhdl-template)
977 (defgroup vhdl-header nil
978 "Customizations for file header."
979 :group 'vhdl-template
980 :group 'vhdl-compose)
982 (defcustom vhdl-file-header "\
983 -------------------------------------------------------------------------------
984 -- Title : <title string>
985 -- Project : <project>
986 -------------------------------------------------------------------------------
987 -- File : <filename>
988 -- Author : <author>
989 -- Company : <company>
990 -- Created : <date>
991 -- Last update: <date>
992 -- Platform : <platform>
993 -- Standard : <standard>
994 <projectdesc>-------------------------------------------------------------------------------
995 -- Description: <cursor>
996 <copyright>-------------------------------------------------------------------------------
997 -- Revisions :
998 -- Date Version Author Description
999 -- <date> 1.0 <login>\tCreated
1000 -------------------------------------------------------------------------------
1003 "String or file to insert as file header.
1004 If the string specifies an existing file name, the contents of the file is
1005 inserted, otherwise the string itself is inserted as file header.
1006 Type `C-j' for newlines.
1007 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
1008 if the header needs to be version controlled.
1010 The following keywords for template generation are supported:
1011 <filename> : replaced by the name of the buffer
1012 <author> : replaced by the user name and email address
1013 (`user-full-name',`mail-host-address', `user-mail-address')
1014 <authorfull> : replaced by the user full name (`user-full-name')
1015 <login> : replaced by user login name (`user-login-name')
1016 <company> : replaced by contents of option `vhdl-company-name'
1017 <date> : replaced by the current date
1018 <year> : replaced by the current year
1019 <project> : replaced by title of current project (`vhdl-project')
1020 <projectdesc> : replaced by description of current project (`vhdl-project')
1021 <copyright> : replaced by copyright string (`vhdl-copyright-string')
1022 <platform> : replaced by contents of option `vhdl-platform-spec'
1023 <standard> : replaced by the VHDL language standard(s) used
1024 <... string> : replaced by a queried string (\"...\" is the prompt word)
1025 <title string>: replaced by file title in automatically generated files
1026 <cursor> : final cursor position
1028 The (multi-line) project description <projectdesc> can be used as a project
1029 dependent part of the file header and can also contain the above keywords."
1030 :type 'string
1031 :group 'vhdl-header)
1033 (defcustom vhdl-file-footer ""
1034 "String or file to insert as file footer.
1035 If the string specifies an existing file name, the contents of the file is
1036 inserted, otherwise the string itself is inserted as file footer (i.e. at
1037 the end of the file).
1038 Type `C-j' for newlines.
1039 The same keywords as in option `vhdl-file-header' can be used."
1040 :type 'string
1041 :group 'vhdl-header)
1043 (defcustom vhdl-company-name ""
1044 "Name of company to insert in file header.
1045 See option `vhdl-file-header'."
1046 :type 'string
1047 :group 'vhdl-header)
1049 (defcustom vhdl-copyright-string "\
1050 -------------------------------------------------------------------------------
1051 -- Copyright (c) <year> <company>
1053 "Copyright string to insert in file header.
1054 Can be multi-line string (type `C-j' for newline) and contain other file
1055 header keywords (see option `vhdl-file-header')."
1056 :type 'string
1057 :group 'vhdl-header)
1059 (defcustom vhdl-platform-spec ""
1060 "Specification of VHDL platform to insert in file header.
1061 The platform specification should contain names and versions of the
1062 simulation and synthesis tools used.
1063 See option `vhdl-file-header'."
1064 :type 'string
1065 :group 'vhdl-header)
1067 (defcustom vhdl-date-format "%Y-%m-%d"
1068 "Specifies the date format to use in the header.
1069 This string is passed as argument to the command `format-time-string'.
1070 For more information on format strings, see the documentation for the
1071 `format-time-string' command (C-h f `format-time-string')."
1072 :type 'string
1073 :group 'vhdl-header)
1075 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1076 "Prefix string of modification date in VHDL file header.
1077 If actualization of the modification date is called (menu,
1078 `\\[vhdl-template-modify]'), this string is searched and the rest
1079 of the line replaced by the current date."
1080 :type 'string
1081 :group 'vhdl-header)
1083 (defcustom vhdl-modify-date-on-saving t
1084 "Non-nil means update the modification date when the buffer is saved.
1085 Calls function `\\[vhdl-template-modify]').
1087 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1088 \"Activate Options\"."
1089 :type 'boolean
1090 :group 'vhdl-header)
1093 (defgroup vhdl-sequential-process nil
1094 "Customizations for sequential processes."
1095 :group 'vhdl-template)
1097 (defcustom vhdl-reset-kind 'async
1098 "Specifies which kind of reset to use in sequential processes."
1099 :type '(choice (const :tag "None" none)
1100 (const :tag "Synchronous" sync)
1101 (const :tag "Asynchronous" async)
1102 (const :tag "Query" query))
1103 :group 'vhdl-sequential-process)
1105 (defcustom vhdl-reset-active-high nil
1106 "Non-nil means reset in sequential processes is active high.
1107 Otherwise, reset is active low."
1108 :type 'boolean
1109 :group 'vhdl-sequential-process)
1111 (defcustom vhdl-clock-rising-edge t
1112 "Non-nil means rising edge of clock triggers sequential processes.
1113 Otherwise, falling edge triggers."
1114 :type 'boolean
1115 :group 'vhdl-sequential-process)
1117 (defcustom vhdl-clock-edge-condition 'standard
1118 "Syntax of the clock edge condition.
1119 Standard: \"clk\\='event and clk = \\='1\\='\"
1120 Function: \"rising_edge(clk)\""
1121 :type '(choice (const :tag "Standard" standard)
1122 (const :tag "Function" function))
1123 :group 'vhdl-sequential-process)
1125 (defcustom vhdl-clock-name ""
1126 "Name of clock signal to use in templates."
1127 :type 'string
1128 :group 'vhdl-sequential-process)
1130 (defcustom vhdl-reset-name ""
1131 "Name of reset signal to use in templates."
1132 :type 'string
1133 :group 'vhdl-sequential-process)
1136 (defgroup vhdl-model nil
1137 "Customizations for user models."
1138 :group 'vhdl)
1140 (defcustom vhdl-model-alist
1141 '(("Example Model"
1142 "<label> : process (<clock>, <reset>)
1143 begin -- process <label>
1144 if <reset> = '0' then -- asynchronous reset (active low)
1145 <cursor>
1146 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1147 if <enable> = '1' then -- synchronous load
1149 end if;
1150 end if;
1151 end process <label>;"
1152 "e" ""))
1153 "List of user models.
1154 VHDL models (templates) can be specified by the user in this list. They can be
1155 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1156 electrification (i.e. overriding existing or creating new keywords, see
1157 option `vhdl-electric-keywords').
1158 Name : name of model (string of words and spaces)
1159 String : string or name of file to be inserted as model (newline: `C-j')
1160 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1161 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1162 Keyword : keyword to invoke model
1164 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1165 A prompt that appears several times is queried once and replaced throughout
1166 the model. Special prompts are:
1167 <clock> : name specified in `vhdl-clock-name' (if not empty)
1168 <reset> : name specified in `vhdl-reset-name' (if not empty)
1169 <cursor>: final cursor position
1170 File header prompts (see variable `vhdl-file-header') are automatically
1171 replaced, so that user models can also be used to insert different types of
1172 headers.
1174 If the string specifies an existing file name, the contents of the file is
1175 inserted, otherwise the string itself is inserted.
1176 The code within the models should be correctly indented.
1177 Type `C-j' for newlines.
1179 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1180 \"Activate Options\"."
1181 :type '(repeat (list :tag "Model" :indent 2
1182 (string :tag "Name ")
1183 (string :tag "String : (type `C-j' for newline)"
1184 :format "%t\n%v")
1185 (sexp :tag "Key binding" x)
1186 (string :tag "Keyword " :format "%t: %v\n")))
1187 :set (lambda (variable value)
1188 (vhdl-custom-set variable value
1189 'vhdl-model-map-init
1190 'vhdl-model-defun
1191 'vhdl-mode-abbrev-table-init
1192 'vhdl-update-mode-menu))
1193 :group 'vhdl-model)
1196 (defgroup vhdl-compose nil
1197 "Customizations for structural composition."
1198 :group 'vhdl)
1200 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1201 (concat
1202 "Specifies how the component architecture name is obtained.
1203 The component architecture name can be obtained by modifying the entity name
1204 \(e.g. attaching or stripping off a substring).
1205 If TO STRING is empty, the architecture name is queried."
1206 vhdl-name-doc-string)
1207 :type '(cons (regexp :tag "From regexp")
1208 (string :tag "To string "))
1209 :group 'vhdl-compose)
1211 (defcustom vhdl-compose-configuration-name
1212 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1213 (concat
1214 "Specifies how the configuration name is obtained.
1215 The configuration name can be obtained by modifying the entity and/or
1216 architecture name (e.g. attaching or stripping off a substring). The string
1217 that is matched against the regexp is the concatenation of the entity and the
1218 architecture name separated by a space. This gives access to both names (see
1219 default setting as example)."
1220 vhdl-name-doc-string)
1221 :type '(cons (regexp :tag "From regexp")
1222 (string :tag "To string "))
1223 :group 'vhdl-compose)
1225 (defcustom vhdl-components-package-name
1226 '((".*" . "\\&_components") . "components")
1227 (concat
1228 "Specifies how the name for the components package is obtained.
1229 The components package is a package containing all component declarations for
1230 the current design. Its name can be obtained by modifying the project name
1231 \(e.g. attaching or stripping off a substring). If no project is defined, the
1232 DIRECTORY entry is chosen."
1233 vhdl-name-doc-string)
1234 :type '(cons (cons :tag "Project" :indent 2
1235 (regexp :tag "From regexp")
1236 (string :tag "To string "))
1237 (string :tag "Directory:\n String "))
1238 :group 'vhdl-compose)
1240 (defcustom vhdl-use-components-package nil
1241 "Non-nil means use a separate components package for component declarations.
1242 Otherwise, component declarations are inserted and searched for in the
1243 architecture declarative parts."
1244 :type 'boolean
1245 :group 'vhdl-compose)
1247 (defcustom vhdl-compose-include-header t
1248 "Non-nil means include a header in automatically generated files."
1249 :type 'boolean
1250 :group 'vhdl-compose)
1252 (defcustom vhdl-compose-create-files 'single
1253 "Specifies whether new files should be created for the new component.
1254 The component's entity and architecture are inserted:
1255 None : in current buffer
1256 Single file : in new single file
1257 Separate files: in two separate files
1258 The file names are obtained from variables `vhdl-entity-file-name' and
1259 `vhdl-architecture-file-name'."
1260 :type '(choice (const :tag "None" none)
1261 (const :tag "Single file" single)
1262 (const :tag "Separate files" separate))
1263 :group 'vhdl-compose)
1265 (defcustom vhdl-compose-configuration-create-file nil
1266 "Specifies whether a new file should be created for the configuration.
1267 If non-nil, a new file is created for the configuration.
1268 The file name is obtained from variable `vhdl-configuration-file-name'."
1269 :type 'boolean
1270 :group 'vhdl-compose)
1272 (defcustom vhdl-compose-configuration-hierarchical t
1273 "Specifies whether hierarchical configurations should be created.
1274 If non-nil, automatically created configurations are hierarchical and include
1275 the whole hierarchy of subcomponents. Otherwise the configuration only
1276 includes one level of subcomponents."
1277 :type 'boolean
1278 :group 'vhdl-compose)
1280 (defcustom vhdl-compose-configuration-use-subconfiguration t
1281 "Specifies whether subconfigurations should be used inside configurations.
1282 If non-nil, automatically created configurations use configurations in binding
1283 indications for subcomponents, if such configurations exist. Otherwise,
1284 entities are used in binding indications for subcomponents."
1285 :type 'boolean
1286 :group 'vhdl-compose)
1289 (defgroup vhdl-port nil
1290 "Customizations for port translation functions."
1291 :group 'vhdl
1292 :group 'vhdl-compose)
1294 (defcustom vhdl-include-port-comments nil
1295 "Non-nil means include port comments when a port is pasted."
1296 :type 'boolean
1297 :group 'vhdl-port)
1299 (defcustom vhdl-include-direction-comments nil
1300 "Non-nil means include port direction in instantiations as comments."
1301 :type 'boolean
1302 :group 'vhdl-port)
1304 (defcustom vhdl-include-type-comments nil
1305 "Non-nil means include generic/port type in instantiations as comments."
1306 :type 'boolean
1307 :group 'vhdl-port)
1309 (defcustom vhdl-include-group-comments 'never
1310 "Specifies whether to include group comments and spacings.
1311 The comments and empty lines between groups of ports are pasted:
1312 Never : never
1313 Declarations: in entity/component/constant/signal declarations only
1314 Always : also in generic/port maps"
1315 :type '(choice (const :tag "Never" never)
1316 (const :tag "Declarations" decl)
1317 (const :tag "Always" always))
1318 :group 'vhdl-port)
1320 (defcustom vhdl-actual-generic-name '(".*" . "\\&")
1321 (concat
1322 "Specifies how actual generic names are obtained from formal generic names.
1323 In a component instantiation, an actual generic name can be
1324 obtained by modifying the formal generic name (e.g. attaching or stripping
1325 off a substring)."
1326 vhdl-name-doc-string)
1327 :type '(cons (regexp :tag "From regexp")
1328 (string :tag "To string "))
1329 :group 'vhdl-port
1330 :version "24.4")
1332 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1333 (concat
1334 "Specifies how actual port names are obtained from formal port names.
1335 In a component instantiation, an actual port name can be obtained by
1336 modifying the formal port name (e.g. attaching or stripping off a substring)."
1337 vhdl-name-doc-string)
1338 :type '(cons (regexp :tag "From regexp")
1339 (string :tag "To string "))
1340 :group 'vhdl-port)
1342 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1343 (concat
1344 "Specifies how an instance name is obtained.
1345 The instance name can be obtained by modifying the name of the component to be
1346 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1347 by a unique number (starting with 1).
1348 If TO STRING is empty, the instance name is queried."
1349 vhdl-name-doc-string)
1350 :type '(cons (regexp :tag "From regexp")
1351 (string :tag "To string "))
1352 :group 'vhdl-port)
1355 (defgroup vhdl-testbench nil
1356 "Customizations for testbench generation."
1357 :group 'vhdl-port)
1359 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1360 (concat
1361 "Specifies how the testbench entity name is obtained.
1362 The entity name of a testbench can be obtained by modifying the name of
1363 the component to be tested (e.g. attaching or stripping off a substring)."
1364 vhdl-name-doc-string)
1365 :type '(cons (regexp :tag "From regexp")
1366 (string :tag "To string "))
1367 :group 'vhdl-testbench)
1369 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1370 (concat
1371 "Specifies how the testbench architecture name is obtained.
1372 The testbench architecture name can be obtained by modifying the name of
1373 the component to be tested (e.g. attaching or stripping off a substring).
1374 If TO STRING is empty, the architecture name is queried."
1375 vhdl-name-doc-string)
1376 :type '(cons (regexp :tag "From regexp")
1377 (string :tag "To string "))
1378 :group 'vhdl-testbench)
1380 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1381 (concat
1382 "Specifies how the testbench configuration name is obtained.
1383 The configuration name of a testbench can be obtained by modifying the entity
1384 and/or architecture name (e.g. attaching or stripping off a substring). The
1385 string that is matched against the regexp is the concatenation of the entity
1386 and the architecture name separated by a space. This gives access to both
1387 names (see default setting as example)."
1388 vhdl-name-doc-string)
1389 :type '(cons (regexp :tag "From regexp")
1390 (string :tag "To string "))
1391 :group 'vhdl-testbench)
1393 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1394 (concat
1395 "Specifies how a DUT instance name is obtained.
1396 The design-under-test instance name (i.e. the component instantiated in the
1397 testbench) can be obtained by modifying the component name (e.g. attaching
1398 or stripping off a substring)."
1399 vhdl-name-doc-string)
1400 :type '(cons (regexp :tag "From regexp")
1401 (string :tag "To string "))
1402 :group 'vhdl-testbench)
1404 (defcustom vhdl-testbench-include-header t
1405 "Non-nil means include a header in automatically generated files."
1406 :type 'boolean
1407 :group 'vhdl-testbench)
1409 (defcustom vhdl-testbench-declarations "\
1410 -- clock
1411 signal Clk : std_logic := '1';
1413 "String or file to be inserted in the testbench declarative part.
1414 If the string specifies an existing file name, the contents of the file is
1415 inserted, otherwise the string itself is inserted in the testbench
1416 architecture before the BEGIN keyword.
1417 Type `C-j' for newlines."
1418 :type 'string
1419 :group 'vhdl-testbench)
1421 (defcustom vhdl-testbench-statements "\
1422 -- clock generation
1423 Clk <= not Clk after 10 ns;
1425 -- waveform generation
1426 WaveGen_Proc: process
1427 begin
1428 -- insert signal assignments here
1430 wait until Clk = '1';
1431 end process WaveGen_Proc;
1433 "String or file to be inserted in the testbench statement part.
1434 If the string specifies an existing file name, the contents of the file is
1435 inserted, otherwise the string itself is inserted in the testbench
1436 architecture before the END keyword.
1437 Type `C-j' for newlines."
1438 :type 'string
1439 :group 'vhdl-testbench)
1441 (defcustom vhdl-testbench-initialize-signals nil
1442 "Non-nil means initialize signals with `0' when declared in testbench."
1443 :type 'boolean
1444 :group 'vhdl-testbench)
1446 (defcustom vhdl-testbench-include-library t
1447 "Non-nil means a library/use clause for std_logic_1164 is included."
1448 :type 'boolean
1449 :group 'vhdl-testbench)
1451 (defcustom vhdl-testbench-include-configuration t
1452 "Non-nil means a testbench configuration is attached at the end."
1453 :type 'boolean
1454 :group 'vhdl-testbench)
1456 (defcustom vhdl-testbench-create-files 'single
1457 "Specifies whether new files should be created for the testbench.
1458 testbench entity and architecture are inserted:
1459 None : in current buffer
1460 Single file : in new single file
1461 Separate files: in two separate files
1462 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1463 and `vhdl-testbench-architecture-file-name'."
1464 :type '(choice (const :tag "None" none)
1465 (const :tag "Single file" single)
1466 (const :tag "Separate files" separate))
1467 :group 'vhdl-testbench)
1469 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1470 (concat
1471 "Specifies how the testbench entity file name is obtained.
1472 The entity file name can be obtained by modifying the testbench entity name
1473 \(e.g. attaching or stripping off a substring). The file extension is
1474 automatically taken from the file name of the current buffer. Testbench
1475 files can be created in a different directory by prepending a relative or
1476 absolute path to the file name."
1477 vhdl-name-doc-string)
1478 :type '(cons (regexp :tag "From regexp")
1479 (string :tag "To string "))
1480 :group 'vhdl-testbench)
1482 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1483 (concat
1484 "Specifies how the testbench architecture file name is obtained.
1485 The architecture file name can be obtained by modifying the testbench entity
1486 and/or architecture name (e.g. attaching or stripping off a substring). The
1487 string that is matched against the regexp is the concatenation of the entity
1488 and the architecture name separated by a space. This gives access to both
1489 names (see default setting as example). Testbench files can be created in
1490 a different directory by prepending a relative or absolute path to the file
1491 name."
1492 vhdl-name-doc-string)
1493 :type '(cons (regexp :tag "From regexp")
1494 (string :tag "To string "))
1495 :group 'vhdl-testbench)
1498 (defgroup vhdl-comment nil
1499 "Customizations for comments."
1500 :group 'vhdl)
1502 (defcustom vhdl-self-insert-comments t
1503 "Non-nil means various templates automatically insert help comments."
1504 :type 'boolean
1505 :group 'vhdl-comment)
1507 (defcustom vhdl-prompt-for-comments t
1508 "Non-nil means various templates prompt for user definable comments."
1509 :type 'boolean
1510 :group 'vhdl-comment)
1512 (defcustom vhdl-inline-comment-column 40
1513 "Column to indent and align inline comments to.
1514 Overrides local option `comment-column'.
1516 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1517 \"Activate Options\"."
1518 :type 'integer
1519 :group 'vhdl-comment)
1521 (defcustom vhdl-end-comment-column 79
1522 "End of comment column.
1523 Comments that exceed this column number are wrapped.
1525 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1526 \"Activate Options\"."
1527 :type 'integer
1528 :group 'vhdl-comment)
1530 (defvar end-comment-column)
1533 (defgroup vhdl-beautify nil
1534 "Customizations for beautification."
1535 :group 'vhdl)
1537 (defcustom vhdl-auto-align t
1538 "Non-nil means align some templates automatically after generation."
1539 :type 'boolean
1540 :group 'vhdl-beautify)
1542 (defcustom vhdl-align-groups t
1543 "Non-nil means align groups of code lines separately.
1544 A group of code lines is a region of consecutive lines between two lines that
1545 match the regexp in option `vhdl-align-group-separate'."
1546 :type 'boolean
1547 :group 'vhdl-beautify)
1549 (defcustom vhdl-align-group-separate "^\\s-*$"
1550 "Regexp for matching a line that separates groups of lines for alignment.
1551 Examples:
1552 \"^\\s-*$\": matches an empty line
1553 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1554 :type 'regexp
1555 :group 'vhdl-beautify)
1557 (defcustom vhdl-align-same-indent t
1558 "Non-nil means align blocks with same indent separately.
1559 When a region or the entire buffer is aligned, the code is divided into
1560 blocks of same indent which are aligned separately (except for argument/port
1561 lists). This gives nicer alignment in most cases.
1562 Option `vhdl-align-groups' still applies within these blocks."
1563 :type 'boolean
1564 :group 'vhdl-beautify)
1566 (defcustom vhdl-beautify-options '(t t t t t)
1567 "List of options for beautifying code.
1568 Allows you to disable individual features of code beautification."
1569 :type '(list (boolean :tag "Whitespace cleanup ")
1570 (boolean :tag "Single statement per line")
1571 (boolean :tag "Indentation ")
1572 (boolean :tag "Alignment ")
1573 (boolean :tag "Case fixing "))
1574 :group 'vhdl-beautify
1575 :version "24.4")
1578 (defgroup vhdl-highlight nil
1579 "Customizations for highlighting."
1580 :group 'vhdl)
1582 (defcustom vhdl-highlight-keywords t
1583 "Non-nil means highlight VHDL keywords and other standardized words.
1584 The following faces are used:
1585 `font-lock-keyword-face' : keywords
1586 `font-lock-type-face' : standardized types
1587 `vhdl-font-lock-attribute-face': standardized attributes
1588 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1589 `vhdl-font-lock-function-face' : standardized function and package names
1591 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1592 entry \"Fontify Buffer\")."
1593 :type 'boolean
1594 :set (lambda (variable value)
1595 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1596 :group 'vhdl-highlight)
1598 (defcustom vhdl-highlight-names t
1599 "Non-nil means highlight declaration names and construct labels.
1600 The following faces are used:
1601 `font-lock-function-name-face' : names in declarations of units,
1602 subprograms, components, as well as labels of VHDL constructs
1603 `font-lock-type-face' : names in type/nature declarations
1604 `vhdl-font-lock-attribute-face': names in attribute declarations
1605 `font-lock-variable-name-face' : names in declarations of signals,
1606 variables, constants, subprogram parameters, generics, and ports
1608 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1609 entry \"Fontify Buffer\")."
1610 :type 'boolean
1611 :set (lambda (variable value)
1612 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1613 :group 'vhdl-highlight)
1615 (defcustom vhdl-highlight-special-words nil
1616 "Non-nil means highlight words with special syntax.
1617 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1618 are highlighted accordingly.
1619 Can be used for visual support of naming conventions.
1621 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1622 entry \"Fontify Buffer\")."
1623 :type 'boolean
1624 :set (lambda (variable value)
1625 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1626 :group 'vhdl-highlight)
1628 (defcustom vhdl-highlight-forbidden-words nil
1629 "Non-nil means highlight forbidden words.
1630 The reserved words specified in option `vhdl-forbidden-words' or having the
1631 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1632 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1633 use them.
1635 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1636 entry \"Fontify Buffer\")."
1637 :type 'boolean
1638 :set (lambda (variable value)
1639 (vhdl-custom-set variable value
1640 'vhdl-words-init 'vhdl-font-lock-init))
1641 :group 'vhdl-highlight)
1643 (defcustom vhdl-highlight-verilog-keywords nil
1644 "Non-nil means highlight Verilog keywords as reserved words.
1645 Verilog keywords are highlighted in a warning color (face
1646 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1648 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1649 entry \"Fontify Buffer\")."
1650 :type 'boolean
1651 :set (lambda (variable value)
1652 (vhdl-custom-set variable value
1653 'vhdl-words-init 'vhdl-font-lock-init))
1654 :group 'vhdl-highlight)
1656 (defcustom vhdl-highlight-translate-off nil
1657 "Non-nil means background-highlight code excluded from translation.
1658 That is, all code between \"-- pragma translate_off\" and
1659 \"-- pragma translate_on\" is highlighted using a different background color
1660 \(face `vhdl-font-lock-translate-off-face').
1661 Note: this might slow down on-the-fly fontification (and thus editing).
1663 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1664 entry \"Fontify Buffer\")."
1665 :type 'boolean
1666 :set (lambda (variable value)
1667 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1668 :group 'vhdl-highlight)
1670 (defcustom vhdl-highlight-case-sensitive nil
1671 "Non-nil means consider case for highlighting.
1672 Possible trade-off:
1673 non-nil also upper-case VHDL words are highlighted, but case of words with
1674 special syntax is not considered
1675 nil only lower-case VHDL words are highlighted, but case of words with
1676 special syntax is considered
1677 Overrides local option `font-lock-keywords-case-fold-search'.
1679 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1680 entry \"Fontify Buffer\")."
1681 :type 'boolean
1682 :group 'vhdl-highlight)
1684 (defcustom vhdl-special-syntax-alist
1685 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1686 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1687 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1688 "List of special syntax to be highlighted.
1689 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1690 syntax (as regular expression) are highlighted in the corresponding color.
1692 Name : string of words and spaces
1693 Regexp : regular expression describing word syntax
1694 (e.g., `\\=\\<\\w+_c\\>' matches word with suffix `_c')
1695 expression must start with `\\=\\<' and end with `\\>'
1696 if only whole words should be matched (no substrings)
1697 Color (light): foreground color for light background
1698 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1699 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1700 Color (dark) : foreground color for dark background
1701 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1702 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1703 In comments : If non-nil, words are also highlighted inside comments
1705 Can be used for visual support of naming conventions, such as highlighting
1706 different kinds of signals (e.g. `Clk50', `Rst_n') or objects (e.g.
1707 `Signal_s', `Variable_v', `Constant_c') by distinguishing them using
1708 common substrings or name suffices.
1709 For each entry, a new face is generated with the specified colors and name
1710 `vhdl-font-lock-' + name + `-face'.
1712 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1713 entry `Fontify Buffer'). All other changes require restarting Emacs."
1714 :type '(repeat (list :tag "Face" :indent 2
1715 (string :tag "Name ")
1716 (regexp :tag "Regexp " "\\w+_")
1717 (string :tag "Color (light)")
1718 (string :tag "Color (dark) ")
1719 (boolean :tag "In comments ")))
1720 :set (lambda (variable value)
1721 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1722 :group 'vhdl-highlight)
1724 (defcustom vhdl-forbidden-words '()
1725 "List of forbidden words to be highlighted.
1726 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1727 words are highlighted in a warning color to indicate not to use them.
1729 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1730 entry \"Fontify Buffer\")."
1731 :type '(repeat (string :format "%v"))
1732 :set (lambda (variable value)
1733 (vhdl-custom-set variable value
1734 'vhdl-words-init 'vhdl-font-lock-init))
1735 :group 'vhdl-highlight)
1737 (defcustom vhdl-forbidden-syntax ""
1738 "Syntax of forbidden words to be highlighted.
1739 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1740 syntax are highlighted in a warning color to indicate not to use them.
1741 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1742 highlights identifiers with 10 or more characters).
1744 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1745 entry \"Fontify Buffer\")."
1746 :type 'regexp
1747 :set (lambda (variable value)
1748 (vhdl-custom-set variable value
1749 'vhdl-words-init 'vhdl-font-lock-init))
1750 :group 'vhdl-highlight)
1752 (defcustom vhdl-directive-keywords '("psl" "pragma" "synopsys")
1753 "List of compiler directive keywords recognized for highlighting.
1755 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1756 entry \"Fontify Buffer\")."
1757 :type '(repeat (string :format "%v"))
1758 :set (lambda (variable value)
1759 (vhdl-custom-set variable value
1760 'vhdl-words-init 'vhdl-font-lock-init))
1761 :group 'vhdl-highlight)
1764 (defgroup vhdl-speedbar nil
1765 "Customizations for speedbar."
1766 :group 'vhdl)
1768 (defcustom vhdl-speedbar-auto-open nil
1769 "Non-nil means automatically open speedbar at startup.
1770 Alternatively, the speedbar can be opened from the VHDL menu."
1771 :type 'boolean
1772 :group 'vhdl-speedbar)
1774 (defcustom vhdl-speedbar-display-mode 'files
1775 "Specifies the default displaying mode when opening speedbar.
1776 Alternatively, the displaying mode can be selected from the speedbar menu or
1777 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1778 :type '(choice (const :tag "Files" files)
1779 (const :tag "Directory hierarchy" directory)
1780 (const :tag "Project hierarchy" project))
1781 :group 'vhdl-speedbar)
1783 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1784 "Limits scanning of large files and netlists.
1785 Design units: maximum file size to scan for design units
1786 Hierarchy (instances of subcomponents):
1787 File size: maximum file size to scan for instances (in bytes)
1788 Instances per arch: maximum number of instances to scan per architecture
1790 \"None\" always means that there is no limit.
1791 In case of files not or incompletely scanned, a warning message and the file
1792 names are printed out.
1793 Background: scanning for instances is considerably slower than scanning for
1794 design units, especially when there are many instances. These limits should
1795 prevent the scanning of large netlists."
1796 :type '(list (choice :tag "Design units"
1797 :format "%t : %[Value Menu%] %v"
1798 (const :tag "None" nil)
1799 (integer :tag "File size"))
1800 (list :tag "Hierarchy" :indent 2
1801 (choice :tag "File size"
1802 :format "%t : %[Value Menu%] %v"
1803 (const :tag "None" nil)
1804 (integer :tag "Size "))
1805 (choice :tag "Instances per arch"
1806 (const :tag "None" nil)
1807 (integer :tag "Number "))))
1808 :group 'vhdl-speedbar)
1810 (defcustom vhdl-speedbar-jump-to-unit t
1811 "Non-nil means jump to the design unit code when opened in a buffer.
1812 The buffer cursor position is left unchanged otherwise."
1813 :type 'boolean
1814 :group 'vhdl-speedbar)
1816 (defcustom vhdl-speedbar-update-on-saving t
1817 "Automatically update design hierarchy when buffer is saved."
1818 :type 'boolean
1819 :group 'vhdl-speedbar)
1821 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1822 "Automatically save modified hierarchy caches when exiting Emacs.
1823 Hierarchy: design hierarchy information
1824 Display: displaying information (which design units to expand)"
1825 :type '(set (const :tag "Hierarchy" hierarchy)
1826 (const :tag "Display" display))
1827 :group 'vhdl-speedbar)
1829 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1830 "Name of file for saving hierarchy cache.
1831 \"\\1\" is replaced by the project name if a project is specified,
1832 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1833 different users to have cache files in the same directory). Can also have
1834 an absolute path (i.e. all caches can be stored in one global directory)."
1835 :type 'string
1836 :group 'vhdl-speedbar)
1839 (defgroup vhdl-menu nil
1840 "Customizations for menus."
1841 :group 'vhdl)
1843 (defcustom vhdl-index-menu nil
1844 "Non-nil means add an index menu for a source file when loading.
1845 Alternatively, the speedbar can be used. Note that the index menu scans a file
1846 when it is opened, while speedbar only scans the file upon request."
1847 :type 'boolean
1848 :group 'vhdl-menu)
1850 (defcustom vhdl-source-file-menu nil
1851 "Non-nil means add a menu of all source files in current directory.
1852 Alternatively, the speedbar can be used."
1853 :type 'boolean
1854 :group 'vhdl-menu)
1856 (defcustom vhdl-hideshow-menu nil
1857 "Non-nil means add hideshow menu and functionality at startup.
1858 Hideshow can also be enabled from the VHDL Mode menu.
1859 Hideshow allows hiding code of various VHDL constructs.
1861 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1862 \"Activate Options\"."
1863 :type 'boolean
1864 :group 'vhdl-menu)
1866 (defcustom vhdl-hide-all-init nil
1867 "Non-nil means hide all design units initially after a file is loaded."
1868 :type 'boolean
1869 :group 'vhdl-menu)
1872 (defgroup vhdl-print nil
1873 "Customizations for printing."
1874 :group 'vhdl)
1876 (defcustom vhdl-print-two-column t
1877 "Non-nil means print code in two columns and landscape format.
1878 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1879 prints VHDL files in a nice two-column landscape style.
1881 NOTE: Activate the new setting by restarting Emacs.
1882 Overrides `ps-print' settings locally."
1883 :type 'boolean
1884 :group 'vhdl-print)
1886 (defcustom vhdl-print-customize-faces t
1887 "Non-nil means use an optimized set of faces for PostScript printing.
1889 NOTE: Activate the new setting by restarting Emacs.
1890 Overrides `ps-print' settings locally."
1891 :type 'boolean
1892 :group 'vhdl-print)
1895 (defgroup vhdl-misc nil
1896 "Miscellaneous customizations."
1897 :group 'vhdl)
1899 (defcustom vhdl-intelligent-tab t
1900 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1901 That is, if preceding character is part of a word then complete word,
1902 else if not at beginning of line then insert tab,
1903 else if last command was a `TAB' or `RET' then dedent one step,
1904 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1905 If nil, TAB always indents current line (i.e. `TAB' is bound to
1906 `indent-according-to-mode').
1908 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1909 \"Activate Options\"."
1910 :type 'boolean
1911 :group 'vhdl-misc)
1913 (defcustom vhdl-indent-syntax-based t
1914 "Non-nil means indent lines of code based on their syntactic context.
1915 Otherwise, a line is indented like the previous nonblank line. This can be
1916 useful in large files where syntax-based indentation gets very slow."
1917 :type 'boolean
1918 :group 'vhdl-misc)
1920 (defcustom vhdl-indent-comment-like-next-code-line t
1921 "Non-nil means comment lines are indented like the following code line.
1922 Otherwise, comment lines are indented like the preceding code line.
1923 Indenting comment lines like the following code line gives nicer indentation
1924 when comments precede the code that they refer to."
1925 :type 'boolean
1926 :version "24.3"
1927 :group 'vhdl-misc)
1929 (defcustom vhdl-word-completion-case-sensitive nil
1930 "Non-nil means word completion using `TAB' is case sensitive.
1931 That is, `TAB' completes words that start with the same letters and case.
1932 Otherwise, case is ignored."
1933 :type 'boolean
1934 :group 'vhdl-misc)
1936 (defcustom vhdl-word-completion-in-minibuffer t
1937 "Non-nil enables word completion in minibuffer (for template prompts).
1939 NOTE: Activate the new setting by restarting Emacs."
1940 :type 'boolean
1941 :group 'vhdl-misc)
1943 (defcustom vhdl-underscore-is-part-of-word nil
1944 "Non-nil means consider the underscore character `_' as part of word.
1945 An identifier containing underscores is then treated as a single word in
1946 select and move operations. All parts of an identifier separated by underscore
1947 are treated as single words otherwise."
1948 :type 'boolean
1949 :group 'vhdl-misc)
1950 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1951 'superword-mode "24.4")
1954 (defgroup vhdl-related nil
1955 "Related general customizations."
1956 :group 'vhdl)
1958 ;; add related general customizations
1959 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1960 (if (featurep 'xemacs)
1961 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1962 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1963 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1964 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1965 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1966 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1967 (unless (featurep 'xemacs)
1968 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1969 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1970 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1971 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1974 ;; Hidden user variables
1976 (defvar vhdl-compile-absolute-path nil
1977 "If non-nil, use absolute instead of relative path for compiled files.")
1979 (defvar vhdl-comment-display-line-char ?-
1980 "Character to use in comment display line.")
1982 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1983 ;; Internal variables
1985 (defvar vhdl-menu-max-size 20
1986 "Specifies the maximum size of a menu before splitting it into submenus.")
1988 (defvar vhdl-progress-interval 1
1989 "Interval used to update progress status during long operations.
1990 If a number, percentage complete gets updated after each interval of
1991 that many seconds. To inhibit all messages, set this option to nil.")
1993 (defvar vhdl-inhibit-startup-warnings-p nil
1994 "If non-nil, inhibits start up compatibility warnings.")
1996 (defvar vhdl-strict-syntax-p nil
1997 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1998 If the syntactic symbol for a particular line does not match a symbol
1999 in the offsets alist, an error is generated, otherwise no error is
2000 reported and the syntactic symbol is ignored.")
2002 (defvar vhdl-echo-syntactic-information-p nil
2003 "If non-nil, syntactic info is echoed when the line is indented.")
2005 (defconst vhdl-offsets-alist-default
2006 '((string . -1000)
2007 (cpp-macro . -1000)
2008 (block-open . 0)
2009 (block-close . 0)
2010 (statement . 0)
2011 (statement-cont . vhdl-lineup-statement-cont)
2012 (statement-block-intro . +)
2013 (statement-case-intro . +)
2014 (case-alternative . +)
2015 (comment . vhdl-lineup-comment)
2016 (arglist-intro . +)
2017 (arglist-cont . 0)
2018 (arglist-cont-nonempty . vhdl-lineup-arglist)
2019 (arglist-close . vhdl-lineup-arglist)
2020 (entity . 0)
2021 (configuration . 0)
2022 (package . 0)
2023 (architecture . 0)
2024 (package-body . 0)
2025 (context . 0)
2026 (directive . 0)
2028 "Default settings for offsets of syntactic elements.
2029 Do not change this constant! See the variable `vhdl-offsets-alist' for
2030 more information.")
2032 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
2033 "Association list of syntactic element symbols and indentation offsets.
2034 As described below, each cons cell in this list has the form:
2036 (SYNTACTIC-SYMBOL . OFFSET)
2038 When a line is indented, `vhdl-mode' first determines the syntactic
2039 context of the line by generating a list of symbols called syntactic
2040 elements. This list can contain more than one syntactic element and
2041 the global variable `vhdl-syntactic-context' contains the context list
2042 for the line being indented. Each element in this list is actually a
2043 cons cell of the syntactic symbol and a buffer position. This buffer
2044 position is call the relative indent point for the line. Some
2045 syntactic symbols may not have a relative indent point associated with
2046 them.
2048 After the syntactic context list for a line is generated, `vhdl-mode'
2049 calculates the absolute indentation for the line by looking at each
2050 syntactic element in the list. First, it compares the syntactic
2051 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2052 finds a match, it adds the OFFSET to the column of the relative indent
2053 point. The sum of this calculation for each element in the syntactic
2054 list is the absolute offset for line being indented.
2056 If the syntactic element does not match any in the `vhdl-offsets-alist',
2057 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2058 the element is ignored.
2060 Actually, OFFSET can be an integer, a function, a variable, or one of
2061 the following symbols: `+', `-', `++', or `--'. These latter
2062 designate positive or negative multiples of `vhdl-basic-offset',
2063 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2064 called with a single argument containing the cons of the syntactic
2065 element symbol and the relative indent point. The function should
2066 return an integer offset.
2068 Here is the current list of valid syntactic element symbols:
2070 string -- inside multi-line string
2071 block-open -- statement block open
2072 block-close -- statement block close
2073 statement -- a VHDL statement
2074 statement-cont -- a continuation of a VHDL statement
2075 statement-block-intro -- the first line in a new statement block
2076 statement-case-intro -- the first line in a case alternative block
2077 case-alternative -- a case statement alternative clause
2078 comment -- a line containing only a comment
2079 arglist-intro -- the first line in an argument list
2080 arglist-cont -- subsequent argument list lines when no
2081 arguments follow on the same line as
2082 the arglist opening paren
2083 arglist-cont-nonempty -- subsequent argument list lines when at
2084 least one argument follows on the same
2085 line as the arglist opening paren
2086 arglist-close -- the solo close paren of an argument list
2087 entity -- inside an entity declaration
2088 configuration -- inside a configuration declaration
2089 package -- inside a package declaration
2090 architecture -- inside an architecture body
2091 package-body -- inside a package body
2092 context -- inside a context declaration")
2094 (defvar vhdl-comment-only-line-offset 0
2095 "Extra offset for line which contains only the start of a comment.
2096 Can contain an integer or a cons cell of the form:
2098 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2100 Where NON-ANCHORED-OFFSET is the amount of offset given to
2101 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2102 the amount of offset to give column-zero anchored comment-only lines.
2103 Just an integer as value is equivalent to (<val> . 0)")
2105 (defvar vhdl-special-indent-hook nil
2106 "Hook for user defined special indentation adjustments.
2107 This hook gets called after a line is indented by the mode.")
2109 (defvar vhdl-style-alist
2110 '(("IEEE"
2111 (vhdl-basic-offset . 4)
2112 (vhdl-offsets-alist . ())))
2113 "Styles of Indentation.
2114 Elements of this alist are of the form:
2116 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2118 where STYLE-STRING is a short descriptive string used to select a
2119 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2120 value for that variable when using the selected style.
2122 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2123 case, the VALUE is a list containing elements of the form:
2125 (SYNTACTIC-SYMBOL . VALUE)
2127 as described in `vhdl-offsets-alist'. These are passed directly to
2128 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2129 your style, only those that are different from the default.")
2131 ;; dynamically append the default value of most variables
2132 (or (assoc "Default" vhdl-style-alist)
2133 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2134 vhdl-strict-syntax-p
2135 vhdl-echo-syntactic-information-p
2136 vhdl-basic-offset
2137 vhdl-offsets-alist
2138 vhdl-comment-only-line-offset))
2139 (default (cons "Default"
2140 (mapcar
2141 (function
2142 (lambda (var)
2143 (cons var (symbol-value var))))
2144 varlist))))
2145 (push default vhdl-style-alist)))
2147 (defvar vhdl-mode-hook nil
2148 "Hook called by `vhdl-mode'.")
2151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2152 ;;; Required packages
2153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2155 ;; mandatory
2156 (require 'compile) ; XEmacs
2157 (require 'easymenu)
2158 (require 'hippie-exp)
2160 ;; optional (minimize warning messages during compile)
2161 (unless (featurep 'xemacs)
2162 (eval-when-compile
2163 (require 'font-lock)
2164 (require 'ps-print)
2165 (require 'speedbar))) ; for speedbar-with-writable
2167 (defun vhdl-aput (alist-symbol key &optional value)
2168 "Insert a key-value pair into an alist.
2169 The alist is referenced by ALIST-SYMBOL. The key-value pair is made
2170 from KEY and VALUE. If the key-value pair referenced by KEY can be
2171 found in the alist, the value of KEY will be set to VALUE. If the
2172 key-value pair cannot be found in the alist, it will be inserted into
2173 the head of the alist."
2174 (let* ((alist (symbol-value alist-symbol))
2175 (elem (assoc key alist)))
2176 (if elem
2177 (setcdr elem value)
2178 (set alist-symbol (cons (cons key value) alist)))))
2180 (defun vhdl-adelete (alist-symbol key)
2181 "Delete a key-value pair from the alist.
2182 Alist is referenced by ALIST-SYMBOL and the key-value pair to remove
2183 is pair matching KEY."
2184 (let ((alist (symbol-value alist-symbol)) alist-cdr)
2185 (while (equal key (caar alist))
2186 (setq alist (cdr alist))
2187 (set alist-symbol alist))
2188 (while (setq alist-cdr (cdr alist))
2189 (if (equal key (caar alist-cdr))
2190 (setcdr alist (cdr alist-cdr))
2191 (setq alist alist-cdr)))))
2193 (defun vhdl-aget (alist key)
2194 "Return the value in ALIST that is associated with KEY. If KEY is
2195 not found, then nil is returned."
2196 (cdr (assoc key alist)))
2198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2199 ;;; Compatibility
2200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2202 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2203 ;; XEmacs compatibility
2205 ;; active regions
2206 (defun vhdl-keep-region-active ()
2207 "Do whatever is necessary to keep the region active in XEmacs.
2208 Ignore byte-compiler warnings you might see."
2209 (and (featurep 'xemacs)
2210 (setq zmacs-region-stays t)))
2212 ;; `wildcard-to-regexp' is included only in XEmacs 21
2213 (unless (fboundp 'wildcard-to-regexp)
2214 (defun wildcard-to-regexp (wildcard)
2215 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2216 (let* ((i (string-match "[*?]" wildcard))
2217 (result (substring wildcard 0 i))
2218 (len (length wildcard)))
2219 (when i
2220 (while (< i len)
2221 (let ((ch (aref wildcard i)))
2222 (setq result (concat result
2223 (cond ((eq ch ?*) "[^\000]*")
2224 ((eq ch ??) "[^\000]")
2225 (t (char-to-string ch)))))
2226 (setq i (1+ i)))))
2227 (concat "\\`" result "\\'"))))
2229 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2230 ;; `regexp-opt' accelerates fontification by 10-20%
2231 (unless (fboundp 'regexp-opt)
2232 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2233 (defun regexp-opt (strings &optional paren)
2234 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2235 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2237 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2238 (unless (fboundp 'match-string-no-properties)
2239 (defalias 'match-string-no-properties 'match-string))
2241 ;; `subst-char-in-string' undefined (XEmacs)
2242 (unless (fboundp 'subst-char-in-string)
2243 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2244 (let ((i (length string))
2245 (newstr (if inplace string (copy-sequence string))))
2246 (while (> i 0)
2247 (setq i (1- i))
2248 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2249 newstr)))
2251 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2252 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2253 (not noninteractive))
2254 (load "itimer")
2255 (when (string< itimer-version "1.09")
2256 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2257 (beep) (sit-for 5)))
2259 ;; `file-expand-wildcards' undefined (XEmacs)
2260 (unless (fboundp 'file-expand-wildcards)
2261 (defun file-expand-wildcards (pattern &optional full)
2262 "Taken from Emacs's `files.el'."
2263 (let* ((nondir (file-name-nondirectory pattern))
2264 (dirpart (file-name-directory pattern))
2265 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2266 (mapcar 'file-name-as-directory
2267 (file-expand-wildcards (directory-file-name dirpart)))
2268 (list dirpart)))
2269 contents)
2270 (while dirs
2271 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2272 (file-directory-p (directory-file-name (car dirs))))
2273 (let ((this-dir-contents
2274 (delq nil
2275 (mapcar #'(lambda (name)
2276 (unless (string-match "\\`\\.\\.?\\'"
2277 (file-name-nondirectory name))
2278 name))
2279 (directory-files (or (car dirs) ".") full
2280 (wildcard-to-regexp nondir))))))
2281 (setq contents
2282 (nconc
2283 (if (and (car dirs) (not full))
2284 (mapcar (function (lambda (name) (concat (car dirs) name)))
2285 this-dir-contents)
2286 this-dir-contents)
2287 contents))))
2288 (setq dirs (cdr dirs)))
2289 contents)))
2291 ;; `member-ignore-case' undefined (XEmacs)
2292 (unless (fboundp 'member-ignore-case)
2293 (defalias 'member-ignore-case 'member))
2295 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2296 ;; behavior in XEmacs
2297 (defvar vhdl-last-input-event)
2298 (if (featurep 'xemacs)
2299 (defvaralias 'vhdl-last-input-event 'last-input-char)
2300 (defvaralias 'vhdl-last-input-event 'last-input-event))
2302 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2303 ;;;(unless (fboundp 'help-print-return-message)
2304 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2307 ;; Compatibility with older VHDL Mode versions
2309 (defvar vhdl-warnings nil
2310 "Warnings to tell the user during start up.")
2312 (defun vhdl-run-when-idle (secs repeat function)
2313 "Wait until idle, then run FUNCTION."
2314 (if (fboundp 'start-itimer)
2315 (start-itimer "vhdl-mode" function secs repeat t)
2316 ;; explicitly activate timer (necessary when Emacs is already idle)
2317 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2319 (defun vhdl-warning-when-idle (&rest args)
2320 "Wait until idle, then print out warning STRING and beep."
2321 (let ((message (apply #'format-message args)))
2322 (if noninteractive
2323 (vhdl-warning message t)
2324 (unless vhdl-warnings
2325 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2326 (push message vhdl-warnings))))
2328 (defun vhdl-warning (string &optional nobeep)
2329 "Print out warning STRING and beep."
2330 (message "WARNING: %s" string)
2331 (unless (or nobeep noninteractive) (beep)))
2333 (defun vhdl-print-warnings ()
2334 "Print out messages in variable `vhdl-warnings'."
2335 (let ((no-warnings (length vhdl-warnings)))
2336 (setq vhdl-warnings (nreverse vhdl-warnings))
2337 (while vhdl-warnings
2338 (message "WARNING: %s" (car vhdl-warnings))
2339 (setq vhdl-warnings (cdr vhdl-warnings)))
2340 (beep)
2341 (when (> no-warnings 1)
2342 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2344 ;; Backward compatibility checks and fixes
2345 ;; option `vhdl-compiler' changed format
2346 (unless (stringp vhdl-compiler)
2347 (setq vhdl-compiler "ModelSim")
2348 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2350 ;; option `vhdl-standard' changed format
2351 (unless (listp vhdl-standard)
2352 (setq vhdl-standard '(87 nil))
2353 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2355 ;; option `vhdl-model-alist' changed format
2356 (when (= (length (car vhdl-model-alist)) 3)
2357 (let ((old-alist vhdl-model-alist)
2358 new-alist)
2359 (while old-alist
2360 (push (append (car old-alist) '("")) new-alist)
2361 (setq old-alist (cdr old-alist)))
2362 (setq vhdl-model-alist (nreverse new-alist)))
2363 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2365 ;; option `vhdl-project-alist' changed format
2366 (when (= (length (car vhdl-project-alist)) 3)
2367 (let ((old-alist vhdl-project-alist)
2368 new-alist)
2369 (while old-alist
2370 (push (append (car old-alist) '("")) new-alist)
2371 (setq old-alist (cdr old-alist)))
2372 (setq vhdl-project-alist (nreverse new-alist)))
2373 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2375 ;; option `vhdl-project-alist' changed format (3.31.1)
2376 (when (= (length (car vhdl-project-alist)) 4)
2377 (let ((old-alist vhdl-project-alist)
2378 new-alist elem)
2379 (while old-alist
2380 (setq elem (car old-alist))
2381 (setq new-alist
2382 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2383 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2384 new-alist))
2385 (setq old-alist (cdr old-alist)))
2386 (setq vhdl-project-alist (nreverse new-alist)))
2387 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2389 ;; option `vhdl-project-alist' changed format (3.31.12)
2390 (when (= (length (car vhdl-project-alist)) 10)
2391 (let ((tmp-alist vhdl-project-alist))
2392 (while tmp-alist
2393 (setcdr (nthcdr 3 (car tmp-alist))
2394 (cons "" (nthcdr 4 (car tmp-alist))))
2395 (setq tmp-alist (cdr tmp-alist))))
2396 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2398 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2399 (when (= (length (car vhdl-compiler-alist)) 7)
2400 (let ((old-alist vhdl-compiler-alist)
2401 new-alist elem)
2402 (while old-alist
2403 (setq elem (car old-alist))
2404 (setq new-alist
2405 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2406 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2407 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2408 (nth 5 elem) (nth 6 elem) nil)
2409 new-alist))
2410 (setq old-alist (cdr old-alist)))
2411 (setq vhdl-compiler-alist (nreverse new-alist)))
2412 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2414 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2415 (when (= (length (car vhdl-compiler-alist)) 12)
2416 (let ((tmp-alist vhdl-compiler-alist))
2417 (while tmp-alist
2418 (setcdr (nthcdr 4 (car tmp-alist))
2419 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2420 (setq tmp-alist (cdr tmp-alist))))
2421 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2423 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2424 (when (= (length (car vhdl-compiler-alist)) 13)
2425 (let ((tmp-alist vhdl-compiler-alist))
2426 (while tmp-alist
2427 (setcdr (nthcdr 3 (car tmp-alist))
2428 (cons "" (nthcdr 4 (car tmp-alist))))
2429 (setq tmp-alist (cdr tmp-alist))))
2430 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2432 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2433 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2434 (let ((tmp-alist vhdl-compiler-alist))
2435 (while tmp-alist
2436 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2437 '(0 . nil))
2438 (setq tmp-alist (cdr tmp-alist))))
2439 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2441 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2442 (when (equal vhdl-project "")
2443 (setq vhdl-project nil)
2444 (customize-save-variable 'vhdl-project vhdl-project))
2446 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2447 (when (stringp vhdl-project-file-name)
2448 (setq vhdl-project-file-name (list vhdl-project-file-name))
2449 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2451 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2452 (if (not (boundp 'speedbar-indentation-width))
2453 (defvar speedbar-indentation-width 2)
2454 ;; set default to 2 if not already customized
2455 (unless (get 'speedbar-indentation-width 'saved-value)
2456 (setq speedbar-indentation-width 2)))
2458 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2459 ;;; Help functions / inline substitutions / macros
2460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2462 (defun vhdl-standard-p (standard)
2463 "Check if STANDARD is specified as used standard."
2464 (or (eq standard (car vhdl-standard))
2465 (memq standard (cadr vhdl-standard))))
2467 (defun vhdl-project-p (&optional warning)
2468 "Return non-nil if a project is displayed, i.e. directories or files are
2469 specified."
2470 (if (assoc vhdl-project vhdl-project-alist)
2471 vhdl-project
2472 (when (and vhdl-project warning)
2473 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2474 nil))
2476 (defun vhdl-resolve-env-variable (string)
2477 "Resolve environment variables in STRING."
2478 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2479 (setq string (concat (match-string 1 string)
2480 (getenv (match-string 2 string))
2481 (match-string 4 string))))
2482 string)
2484 (defun vhdl-default-directory ()
2485 "Return the default directory of the current project or the directory of the
2486 current buffer if no project is defined."
2487 (if (vhdl-project-p)
2488 (expand-file-name (vhdl-resolve-env-variable
2489 (nth 1 (vhdl-aget vhdl-project-alist vhdl-project))))
2490 default-directory))
2492 (defmacro vhdl-prepare-search-1 (&rest body)
2493 "Enable case insensitive search and switch to syntax table that includes `_',
2494 then execute BODY, and finally restore the old environment. Used for
2495 consistent searching."
2496 `(let ((case-fold-search t)) ; case insensitive search
2497 ;; use extended syntax table
2498 (with-syntax-table vhdl-mode-ext-syntax-table
2499 ,@body)))
2501 (defmacro vhdl-prepare-search-2 (&rest body)
2502 "Enable case insensitive search, switch to syntax table that includes `_',
2503 arrange to ignore `intangible' overlays, then execute BODY, and finally restore
2504 the old environment. Used for consistent searching."
2505 `(let ((case-fold-search t) ; case insensitive search
2506 (current-syntax-table (syntax-table))
2507 (inhibit-point-motion-hooks t))
2508 ;; use extended syntax table
2509 (set-syntax-table vhdl-mode-ext-syntax-table)
2510 ;; execute BODY safely
2511 (unwind-protect
2512 (progn ,@body)
2513 ;; restore syntax table
2514 (set-syntax-table current-syntax-table))))
2516 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2517 "Visit file FILE-NAME and execute BODY."
2518 `(if (null ,file-name)
2519 (progn ,@body)
2520 (unless (file-directory-p ,file-name)
2521 (let ((source-buffer (current-buffer))
2522 (visiting-buffer (find-buffer-visiting ,file-name))
2523 file-opened)
2524 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2525 (condition-case ()
2526 (progn (set-buffer (create-file-buffer ,file-name))
2527 (setq file-opened t)
2528 (vhdl-insert-file-contents ,file-name)
2529 ;; FIXME: This modifies a global syntax-table!
2530 (modify-syntax-entry ?\- ". 12" (syntax-table))
2531 (modify-syntax-entry ?\n ">" (syntax-table))
2532 (modify-syntax-entry ?\^M ">" (syntax-table))
2533 (modify-syntax-entry ?_ "w" (syntax-table))
2535 (error
2536 (if ,issue-error
2537 (progn
2538 (when file-opened (kill-buffer (current-buffer)))
2539 (set-buffer source-buffer)
2540 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2541 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2542 nil))))
2543 (condition-case info
2544 (progn ,@body)
2545 (error
2546 (if ,issue-error
2547 (progn
2548 (when file-opened (kill-buffer (current-buffer)))
2549 (set-buffer source-buffer)
2550 (error (cadr info)))
2551 (vhdl-warning (cadr info))))))
2552 (when file-opened (kill-buffer (current-buffer)))
2553 (set-buffer source-buffer)))))
2555 (defun vhdl-insert-file-contents (filename)
2556 "Nicked from `insert-file-contents-literally', but allow coding system
2557 conversion."
2558 (let ((format-alist nil)
2559 (after-insert-file-functions nil)
2560 (jka-compr-compression-info-list nil))
2561 (insert-file-contents filename t)))
2563 (defun vhdl-sort-alist (alist)
2564 "Sort ALIST."
2565 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2567 (defun vhdl-get-subdirs (directory)
2568 "Recursively get subdirectories of DIRECTORY."
2569 (let ((dir-list (list (file-name-as-directory directory)))
2570 file-list)
2571 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2572 (while file-list
2573 (when (file-directory-p (car file-list))
2574 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2575 (setq file-list (cdr file-list)))
2576 dir-list))
2578 (defun vhdl-aput-delete-if-nil (alist-symbol key &optional value)
2579 "As `aput', but delete key-value pair if VALUE is nil."
2580 (if value
2581 (vhdl-aput alist-symbol key value)
2582 (vhdl-adelete alist-symbol key)))
2584 (defun vhdl-delete (elt list)
2585 "Delete by side effect the first occurrence of ELT as a member of LIST."
2586 (push nil list)
2587 (let ((list1 list))
2588 (while (and (cdr list1) (not (equal elt (cadr list1))))
2589 (setq list1 (cdr list1)))
2590 (when list
2591 (setcdr list1 (cddr list1))))
2592 (cdr list))
2594 (declare-function speedbar-refresh "speedbar" (&optional arg))
2595 (declare-function speedbar-do-function-pointer "speedbar" ())
2597 (defun vhdl-speedbar-refresh (&optional key)
2598 "Refresh directory or project with name KEY."
2599 (when (and (boundp 'speedbar-frame)
2600 (frame-live-p speedbar-frame))
2601 (let ((pos (point))
2602 (last-frame (selected-frame)))
2603 (if (null key)
2604 (speedbar-refresh)
2605 (select-frame speedbar-frame)
2606 (when (save-excursion
2607 (goto-char (point-min))
2608 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2609 (goto-char (match-end 1))
2610 (speedbar-do-function-pointer)
2611 (backward-char 2)
2612 (speedbar-do-function-pointer)
2613 (message "Refreshing speedbar...done"))
2614 (select-frame last-frame)))))
2616 (defun vhdl-show-messages ()
2617 "Get *Messages* buffer to show recent messages."
2618 (interactive)
2619 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2621 (defun vhdl-use-direct-instantiation ()
2622 "Return whether direct instantiation is used."
2623 (or (eq vhdl-use-direct-instantiation 'always)
2624 (and (eq vhdl-use-direct-instantiation 'standard)
2625 (not (vhdl-standard-p '87)))))
2627 (defun vhdl-max-marker (marker1 marker2)
2628 "Return larger marker."
2629 (if (> marker1 marker2) marker1 marker2))
2631 (defun vhdl-goto-marker (marker)
2632 "Goto marker in appropriate buffer."
2633 (when (markerp marker)
2634 (set-buffer (marker-buffer marker)))
2635 (goto-char marker))
2637 (defun vhdl-menu-split (list title)
2638 "Split menu LIST into several submenus, if number of
2639 elements > `vhdl-menu-max-size'."
2640 (if (> (length list) vhdl-menu-max-size)
2641 (let ((remain list)
2642 (result '())
2643 (sublist '())
2644 (menuno 1)
2645 (i 0))
2646 (while remain
2647 (push (car remain) sublist)
2648 (setq remain (cdr remain))
2649 (setq i (+ i 1))
2650 (if (= i vhdl-menu-max-size)
2651 (progn
2652 (push (cons (format "%s %s" title menuno)
2653 (nreverse sublist)) result)
2654 (setq i 0)
2655 (setq menuno (+ menuno 1))
2656 (setq sublist '()))))
2657 (and sublist
2658 (push (cons (format "%s %s" title menuno)
2659 (nreverse sublist)) result))
2660 (nreverse result))
2661 list))
2664 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2665 ;;; Bindings
2666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2669 ;; Key bindings
2671 (defvar vhdl-template-map nil
2672 "Keymap for VHDL templates.")
2674 (defun vhdl-template-map-init ()
2675 "Initialize `vhdl-template-map'."
2676 (setq vhdl-template-map (make-sparse-keymap))
2677 ;; key bindings for VHDL templates
2678 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2679 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2680 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2681 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2682 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2683 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2684 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2685 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2686 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2687 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2688 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2689 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2690 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2691 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2692 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2693 (define-key vhdl-template-map "ct" 'vhdl-template-context)
2694 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2695 (define-key vhdl-template-map "el" 'vhdl-template-else)
2696 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2697 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2698 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2699 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2700 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2701 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2702 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2703 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2704 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2705 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2706 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2707 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2708 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2709 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2710 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2711 (define-key vhdl-template-map "li" 'vhdl-template-library)
2712 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2713 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2714 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2715 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2716 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2717 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2718 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2719 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2720 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2721 (define-key vhdl-template-map "po" 'vhdl-template-port)
2722 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2723 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2724 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2725 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2726 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2727 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2728 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2729 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2730 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2731 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2732 (define-key vhdl-template-map "us" 'vhdl-template-use)
2733 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2734 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2735 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2736 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2737 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2738 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2739 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2740 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2741 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2742 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2743 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2744 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2745 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2746 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2747 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2748 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2749 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2750 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2751 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2752 (when (vhdl-standard-p 'ams)
2753 (define-key vhdl-template-map "br" 'vhdl-template-break)
2754 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2755 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2756 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2757 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2758 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2759 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2760 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2761 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2762 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2763 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2765 (when (vhdl-standard-p 'math)
2766 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2767 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2770 ;; initialize template map for VHDL Mode
2771 (vhdl-template-map-init)
2773 (defun vhdl-function-name (prefix string &optional postfix)
2774 "Generate a Lisp function name.
2775 PREFIX, STRING and optional POSTFIX are concatenated by `-' and spaces in
2776 STRING are replaced by `-' and substrings are converted to lower case."
2777 (let ((name prefix))
2778 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2779 (setq name
2780 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2781 (setq string (substring string (match-beginning 2))))
2782 (when postfix (setq name (concat name "-" postfix)))
2783 (intern name)))
2785 (defvar vhdl-model-map nil
2786 "Keymap for VHDL models.")
2788 (defun vhdl-model-map-init ()
2789 "Initialize `vhdl-model-map'."
2790 (setq vhdl-model-map (make-sparse-keymap))
2791 ;; key bindings for VHDL models
2792 (let ((model-alist vhdl-model-alist) model)
2793 (while model-alist
2794 (setq model (car model-alist))
2795 (define-key vhdl-model-map (nth 2 model)
2796 (vhdl-function-name "vhdl-model" (nth 0 model)))
2797 (setq model-alist (cdr model-alist)))))
2799 ;; initialize user model map for VHDL Mode
2800 (vhdl-model-map-init)
2802 (defvar vhdl-mode-map nil
2803 "Keymap for VHDL Mode.")
2805 (defun vhdl-mode-map-init ()
2806 "Initialize `vhdl-mode-map'."
2807 (setq vhdl-mode-map (make-sparse-keymap))
2808 ;; template key bindings
2809 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2810 ;; model key bindings
2811 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2812 ;; standard key bindings
2813 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2814 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2815 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2816 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2817 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2818 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2819 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2820 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2821 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2822 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2823 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2824 ;; mode specific key bindings
2825 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2826 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2827 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2828 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2829 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2830 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2831 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2832 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2833 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2834 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2835 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2836 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2837 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2838 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2839 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2840 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2841 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2842 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2843 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2844 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2845 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2846 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2847 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2848 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2849 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2850 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2851 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2852 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2853 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2854 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2855 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2856 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2857 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2858 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2859 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2860 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2861 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2862 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2863 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2864 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2865 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2866 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2867 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2868 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2869 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2870 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2871 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2872 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2873 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2874 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2875 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2876 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2877 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2878 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2879 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2880 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2881 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2882 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2883 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2884 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2885 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2886 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2887 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2888 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2889 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2890 (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
2891 (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
2892 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2893 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2894 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2895 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2896 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2897 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2898 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2899 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2900 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2901 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2902 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2903 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2904 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2905 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2906 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2907 ;; insert commands bindings
2908 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2909 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2910 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2911 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2912 ;; electric key bindings
2913 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2914 (when vhdl-intelligent-tab
2915 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2916 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2917 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2918 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2919 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2920 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2921 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2922 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2923 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2924 (when (vhdl-standard-p 'ams)
2925 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2927 ;; initialize mode map for VHDL Mode
2928 (vhdl-mode-map-init)
2930 ;; define special minibuffer keymap for enabling word completion in minibuffer
2931 ;; (useful in template generator prompts)
2932 (defvar vhdl-minibuffer-local-map
2933 (let ((map (make-sparse-keymap)))
2934 (set-keymap-parent map minibuffer-local-map)
2935 (when vhdl-word-completion-in-minibuffer
2936 (define-key map "\t" 'vhdl-minibuffer-tab))
2937 map)
2938 "Keymap for minibuffer used in VHDL Mode.")
2940 ;; set up electric character functions to work with
2941 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2942 (mapc
2943 (function
2944 (lambda (sym)
2945 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2946 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2947 '(vhdl-electric-space
2948 vhdl-electric-tab
2949 vhdl-electric-return
2950 vhdl-electric-dash
2951 vhdl-electric-open-bracket
2952 vhdl-electric-close-bracket
2953 vhdl-electric-quote
2954 vhdl-electric-semicolon
2955 vhdl-electric-comma
2956 vhdl-electric-period
2957 vhdl-electric-equal))
2959 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2960 ;; Syntax table
2962 (defvar vhdl-mode-syntax-table
2963 (let ((st (make-syntax-table)))
2964 ;; define punctuation
2965 (modify-syntax-entry ?\# "." st)
2966 (modify-syntax-entry ?\$ "." st)
2967 (modify-syntax-entry ?\% "." st)
2968 (modify-syntax-entry ?\& "." st)
2969 (modify-syntax-entry ?\' "." st)
2970 (modify-syntax-entry ?\* "." st)
2971 (modify-syntax-entry ?\+ "." st)
2972 (modify-syntax-entry ?\. "." st)
2973 ;;; (modify-syntax-entry ?\/ "." st)
2974 (modify-syntax-entry ?\: "." st)
2975 (modify-syntax-entry ?\; "." st)
2976 (modify-syntax-entry ?\< "." st)
2977 (modify-syntax-entry ?\= "." st)
2978 (modify-syntax-entry ?\> "." st)
2979 (modify-syntax-entry ?\\ "." st)
2980 (modify-syntax-entry ?\| "." st)
2981 ;; define string
2982 (modify-syntax-entry ?\" "\"" st)
2983 ;; define underscore
2984 (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
2985 ;; single-line comments
2986 (modify-syntax-entry ?\- ". 12b" st)
2987 ;; multi-line comments
2988 (modify-syntax-entry ?\/ ". 14b" st)
2989 (modify-syntax-entry ?* ". 23" st)
2990 (modify-syntax-entry ?\n "> b" st)
2991 (modify-syntax-entry ?\^M "> b" st)
2992 ;; define parentheses to match
2993 (modify-syntax-entry ?\( "()" st)
2994 (modify-syntax-entry ?\) ")(" st)
2995 (modify-syntax-entry ?\[ "(]" st)
2996 (modify-syntax-entry ?\] ")[" st)
2997 (modify-syntax-entry ?\{ "(}" st)
2998 (modify-syntax-entry ?\} "){" st)
3000 "Syntax table used in `vhdl-mode' buffers.")
3002 (defvar vhdl-mode-ext-syntax-table
3003 ;; Extended syntax table including '_' (for simpler search regexps).
3004 (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
3005 (modify-syntax-entry ?_ "w" st)
3007 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
3009 (defvar vhdl-syntactic-context nil
3010 "Buffer local variable containing syntactic analysis list.")
3011 (make-variable-buffer-local 'vhdl-syntactic-context)
3013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3014 ;; Abbrev hook bindings
3016 (defvar vhdl-mode-abbrev-table nil
3017 "Abbrev table to use in `vhdl-mode' buffers.")
3019 (defun vhdl-mode-abbrev-table-init ()
3020 "Initialize `vhdl-mode-abbrev-table'."
3021 (define-abbrev-table 'vhdl-mode-abbrev-table
3022 (append
3023 (when (memq 'vhdl vhdl-electric-keywords)
3024 ;; VHDL'02 keywords
3025 (mapcar (if (featurep 'xemacs)
3026 (lambda (x) (list (car x) "" (cdr x) 0))
3027 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3029 ("--" . vhdl-template-display-comment-hook)
3030 ("abs" . vhdl-template-default-hook)
3031 ("access" . vhdl-template-default-hook)
3032 ("after" . vhdl-template-default-hook)
3033 ("alias" . vhdl-template-alias-hook)
3034 ("all" . vhdl-template-default-hook)
3035 ("and" . vhdl-template-default-hook)
3036 ("arch" . vhdl-template-architecture-hook)
3037 ("architecture" . vhdl-template-architecture-hook)
3038 ("array" . vhdl-template-default-hook)
3039 ("assert" . vhdl-template-assert-hook)
3040 ("attr" . vhdl-template-attribute-hook)
3041 ("attribute" . vhdl-template-attribute-hook)
3042 ("begin" . vhdl-template-default-indent-hook)
3043 ("block" . vhdl-template-block-hook)
3044 ("body" . vhdl-template-default-hook)
3045 ("buffer" . vhdl-template-default-hook)
3046 ("bus" . vhdl-template-default-hook)
3047 ("case" . vhdl-template-case-hook)
3048 ("comp" . vhdl-template-component-hook)
3049 ("component" . vhdl-template-component-hook)
3050 ("cond" . vhdl-template-conditional-signal-asst-hook)
3051 ("conditional" . vhdl-template-conditional-signal-asst-hook)
3052 ("conf" . vhdl-template-configuration-hook)
3053 ("configuration" . vhdl-template-configuration-hook)
3054 ("cons" . vhdl-template-constant-hook)
3055 ("constant" . vhdl-template-constant-hook)
3056 ("context" . vhdl-template-context-hook)
3057 ("disconnect" . vhdl-template-disconnect-hook)
3058 ("downto" . vhdl-template-default-hook)
3059 ("else" . vhdl-template-else-hook)
3060 ("elseif" . vhdl-template-elsif-hook)
3061 ("elsif" . vhdl-template-elsif-hook)
3062 ("end" . vhdl-template-default-indent-hook)
3063 ("entity" . vhdl-template-entity-hook)
3064 ("exit" . vhdl-template-exit-hook)
3065 ("file" . vhdl-template-file-hook)
3066 ("for" . vhdl-template-for-hook)
3067 ("func" . vhdl-template-function-hook)
3068 ("function" . vhdl-template-function-hook)
3069 ("generic" . vhdl-template-generic-hook)
3070 ("group" . vhdl-template-group-hook)
3071 ("guarded" . vhdl-template-default-hook)
3072 ("if" . vhdl-template-if-hook)
3073 ("impure" . vhdl-template-default-hook)
3074 ("in" . vhdl-template-default-hook)
3075 ("inertial" . vhdl-template-default-hook)
3076 ("inout" . vhdl-template-default-hook)
3077 ("inst" . vhdl-template-instance-hook)
3078 ("instance" . vhdl-template-instance-hook)
3079 ("is" . vhdl-template-default-hook)
3080 ("label" . vhdl-template-default-hook)
3081 ("library" . vhdl-template-library-hook)
3082 ("linkage" . vhdl-template-default-hook)
3083 ("literal" . vhdl-template-default-hook)
3084 ("loop" . vhdl-template-bare-loop-hook)
3085 ("map" . vhdl-template-map-hook)
3086 ("mod" . vhdl-template-default-hook)
3087 ("nand" . vhdl-template-default-hook)
3088 ("new" . vhdl-template-default-hook)
3089 ("next" . vhdl-template-next-hook)
3090 ("nor" . vhdl-template-default-hook)
3091 ("not" . vhdl-template-default-hook)
3092 ("null" . vhdl-template-default-hook)
3093 ("of" . vhdl-template-default-hook)
3094 ("on" . vhdl-template-default-hook)
3095 ("open" . vhdl-template-default-hook)
3096 ("or" . vhdl-template-default-hook)
3097 ("others" . vhdl-template-others-hook)
3098 ("out" . vhdl-template-default-hook)
3099 ("pack" . vhdl-template-package-hook)
3100 ("package" . vhdl-template-package-hook)
3101 ("port" . vhdl-template-port-hook)
3102 ("postponed" . vhdl-template-default-hook)
3103 ("procedure" . vhdl-template-procedure-hook)
3104 ("process" . vhdl-template-process-hook)
3105 ("pure" . vhdl-template-default-hook)
3106 ("range" . vhdl-template-default-hook)
3107 ("record" . vhdl-template-default-hook)
3108 ("register" . vhdl-template-default-hook)
3109 ("reject" . vhdl-template-default-hook)
3110 ("rem" . vhdl-template-default-hook)
3111 ("report" . vhdl-template-report-hook)
3112 ("return" . vhdl-template-return-hook)
3113 ("rol" . vhdl-template-default-hook)
3114 ("ror" . vhdl-template-default-hook)
3115 ("select" . vhdl-template-selected-signal-asst-hook)
3116 ("severity" . vhdl-template-default-hook)
3117 ("shared" . vhdl-template-default-hook)
3118 ("sig" . vhdl-template-signal-hook)
3119 ("signal" . vhdl-template-signal-hook)
3120 ("sla" . vhdl-template-default-hook)
3121 ("sll" . vhdl-template-default-hook)
3122 ("sra" . vhdl-template-default-hook)
3123 ("srl" . vhdl-template-default-hook)
3124 ("subtype" . vhdl-template-subtype-hook)
3125 ("then" . vhdl-template-default-hook)
3126 ("to" . vhdl-template-default-hook)
3127 ("transport" . vhdl-template-default-hook)
3128 ("type" . vhdl-template-type-hook)
3129 ("unaffected" . vhdl-template-default-hook)
3130 ("units" . vhdl-template-default-hook)
3131 ("until" . vhdl-template-default-hook)
3132 ("use" . vhdl-template-use-hook)
3133 ("var" . vhdl-template-variable-hook)
3134 ("variable" . vhdl-template-variable-hook)
3135 ("wait" . vhdl-template-wait-hook)
3136 ("when" . vhdl-template-when-hook)
3137 ("while" . vhdl-template-while-loop-hook)
3138 ("with" . vhdl-template-with-hook)
3139 ("xnor" . vhdl-template-default-hook)
3140 ("xor" . vhdl-template-default-hook)
3142 ;; VHDL-AMS keywords
3143 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3144 (mapcar (if (featurep 'xemacs)
3145 (lambda (x) (list (car x) "" (cdr x) 0))
3146 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3148 ("across" . vhdl-template-default-hook)
3149 ("break" . vhdl-template-break-hook)
3150 ("limit" . vhdl-template-limit-hook)
3151 ("nature" . vhdl-template-nature-hook)
3152 ("noise" . vhdl-template-default-hook)
3153 ("procedural" . vhdl-template-procedural-hook)
3154 ("quantity" . vhdl-template-quantity-hook)
3155 ("reference" . vhdl-template-default-hook)
3156 ("spectrum" . vhdl-template-default-hook)
3157 ("subnature" . vhdl-template-subnature-hook)
3158 ("terminal" . vhdl-template-terminal-hook)
3159 ("through" . vhdl-template-default-hook)
3160 ("tolerance" . vhdl-template-default-hook)
3162 ;; user model keywords
3163 (when (memq 'user vhdl-electric-keywords)
3164 (let (abbrev-list keyword)
3165 (dolist (elem vhdl-model-alist)
3166 (setq keyword (nth 3 elem))
3167 (unless (equal keyword "")
3168 (push (list keyword ""
3169 (vhdl-function-name
3170 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3171 abbrev-list)))
3172 abbrev-list)))))
3174 ;; initialize abbrev table for VHDL Mode
3175 (vhdl-mode-abbrev-table-init)
3177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3178 ;; Template completion lists
3180 (defvar vhdl-template-construct-alist nil
3181 "List of built-in construct templates.")
3183 (defun vhdl-template-construct-alist-init ()
3184 "Initialize `vhdl-template-construct-alist'."
3185 (setq
3186 vhdl-template-construct-alist
3187 (append
3189 ("alias declaration" vhdl-template-alias)
3190 ("architecture body" vhdl-template-architecture)
3191 ("assertion" vhdl-template-assert)
3192 ("attribute declaration" vhdl-template-attribute-decl)
3193 ("attribute specification" vhdl-template-attribute-spec)
3194 ("block configuration" vhdl-template-block-configuration)
3195 ("block statement" vhdl-template-block)
3196 ("case statement" vhdl-template-case-is)
3197 ("component configuration" vhdl-template-component-conf)
3198 ("component declaration" vhdl-template-component-decl)
3199 ("component instantiation statement" vhdl-template-component-inst)
3200 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3201 ("configuration declaration" vhdl-template-configuration-decl)
3202 ("configuration specification" vhdl-template-configuration-spec)
3203 ("constant declaration" vhdl-template-constant)
3204 ("context declaration" vhdl-template-context)
3205 ("disconnection specification" vhdl-template-disconnect)
3206 ("entity declaration" vhdl-template-entity)
3207 ("exit statement" vhdl-template-exit)
3208 ("file declaration" vhdl-template-file)
3209 ("generate statement" vhdl-template-generate)
3210 ("generic clause" vhdl-template-generic)
3211 ("group declaration" vhdl-template-group-decl)
3212 ("group template declaration" vhdl-template-group-template)
3213 ("if statement" vhdl-template-if-then)
3214 ("library clause" vhdl-template-library)
3215 ("loop statement" vhdl-template-loop)
3216 ("next statement" vhdl-template-next)
3217 ("package declaration" vhdl-template-package-decl)
3218 ("package body" vhdl-template-package-body)
3219 ("port clause" vhdl-template-port)
3220 ("process statement" vhdl-template-process)
3221 ("report statement" vhdl-template-report)
3222 ("return statement" vhdl-template-return)
3223 ("selected signal assignment" vhdl-template-selected-signal-asst)
3224 ("signal declaration" vhdl-template-signal)
3225 ("subprogram declaration" vhdl-template-subprogram-decl)
3226 ("subprogram body" vhdl-template-subprogram-body)
3227 ("subtype declaration" vhdl-template-subtype)
3228 ("type declaration" vhdl-template-type)
3229 ("use clause" vhdl-template-use)
3230 ("variable declaration" vhdl-template-variable)
3231 ("wait statement" vhdl-template-wait)
3233 (when (vhdl-standard-p 'ams)
3235 ("break statement" vhdl-template-break)
3236 ("nature declaration" vhdl-template-nature)
3237 ("quantity declaration" vhdl-template-quantity)
3238 ("simultaneous case statement" vhdl-template-case-use)
3239 ("simultaneous if statement" vhdl-template-if-use)
3240 ("simultaneous procedural statement" vhdl-template-procedural)
3241 ("step limit specification" vhdl-template-limit)
3242 ("subnature declaration" vhdl-template-subnature)
3243 ("terminal declaration" vhdl-template-terminal)
3244 )))))
3246 ;; initialize for VHDL Mode
3247 (vhdl-template-construct-alist-init)
3249 (defvar vhdl-template-package-alist nil
3250 "List of built-in package templates.")
3252 (defun vhdl-template-package-alist-init ()
3253 "Initialize `vhdl-template-package-alist'."
3254 (setq
3255 vhdl-template-package-alist
3256 (append
3258 ("numeric_bit" vhdl-template-package-numeric-bit)
3259 ("numeric_std" vhdl-template-package-numeric-std)
3260 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3261 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3262 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3263 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3264 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3265 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3266 ("textio" vhdl-template-package-textio)
3268 (when (vhdl-standard-p 'math)
3270 ("math_complex" vhdl-template-package-math-complex)
3271 ("math_real" vhdl-template-package-math-real)
3272 )))))
3274 ;; initialize for VHDL Mode
3275 (vhdl-template-package-alist-init)
3277 (defvar vhdl-template-directive-alist
3279 ("translate_on" vhdl-template-directive-translate-on)
3280 ("translate_off" vhdl-template-directive-translate-off)
3281 ("synthesis_on" vhdl-template-directive-synthesis-on)
3282 ("synthesis_off" vhdl-template-directive-synthesis-off)
3284 "List of built-in directive templates.")
3287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3288 ;;; Menus
3289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3292 ;; VHDL menu (using `easy-menu.el')
3294 (defun vhdl-customize ()
3295 "Call the customize function with `vhdl' as argument."
3296 (interactive)
3297 (customize-browse 'vhdl))
3299 (defun vhdl-create-mode-menu ()
3300 "Create VHDL Mode menu."
3301 `("VHDL"
3302 ,(append
3303 '("Project"
3304 ["None" (vhdl-set-project "")
3305 :style radio :selected (null vhdl-project)]
3306 "--")
3307 ;; add menu entries for defined projects
3308 (let ((project-alist vhdl-project-alist) menu-list name)
3309 (while project-alist
3310 (setq name (caar project-alist))
3311 (setq menu-list
3312 (cons `[,name (vhdl-set-project ,name)
3313 :style radio :selected (equal ,name vhdl-project)]
3314 menu-list))
3315 (setq project-alist (cdr project-alist)))
3316 (setq menu-list
3317 (if vhdl-project-sort
3318 (sort menu-list
3319 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3320 (nreverse menu-list)))
3321 (vhdl-menu-split menu-list "Project"))
3322 '("--" "--"
3323 ["Select Project..." vhdl-set-project t]
3324 ["Set As Default Project" vhdl-set-default-project t]
3325 "--"
3326 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3327 ["Import Project..." vhdl-import-project
3328 :keys "C-c C-p C-m" :active t]
3329 ["Export Project" vhdl-export-project vhdl-project]
3330 "--"
3331 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3332 "--"
3333 ("Compile"
3334 ["Compile Buffer" vhdl-compile t]
3335 ["Stop Compilation" kill-compilation t]
3336 "--"
3337 ["Make" vhdl-make t]
3338 ["Generate Makefile" vhdl-generate-makefile t]
3339 "--"
3340 ["Next Error" next-error t]
3341 ["Previous Error" previous-error t]
3342 ["First Error" first-error t]
3343 "--"
3344 ,(append
3345 '("Compiler")
3346 ;; add menu entries for defined compilers
3347 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3348 (while comp-alist
3349 (setq name (caar comp-alist))
3350 (setq menu-list
3351 (cons `[,name (setq vhdl-compiler ,name)
3352 :style radio :selected (equal ,name vhdl-compiler)]
3353 menu-list))
3354 (setq comp-alist (cdr comp-alist)))
3355 (setq menu-list (nreverse menu-list))
3356 (vhdl-menu-split menu-list "Compiler"))
3357 '("--" "--"
3358 ["Select Compiler..." vhdl-set-compiler t]
3359 "--"
3360 ["Customize Compiler..."
3361 (customize-option 'vhdl-compiler-alist) t])))
3362 "--"
3363 ,(append
3364 '("Template"
3365 ("VHDL Construct 1"
3366 ["Alias" vhdl-template-alias t]
3367 ["Architecture" vhdl-template-architecture t]
3368 ["Assert" vhdl-template-assert t]
3369 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3370 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3371 ["Block" vhdl-template-block t]
3372 ["Case" vhdl-template-case-is t]
3373 ["Component (Decl)" vhdl-template-component-decl t]
3374 ["(Component) Instance" vhdl-template-component-inst t]
3375 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3376 ["Configuration (Block)" vhdl-template-block-configuration t]
3377 ["Configuration (Comp)" vhdl-template-component-conf t]
3378 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3379 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3380 ["Constant" vhdl-template-constant t]
3381 ["Context" vhdl-template-context t]
3382 ["Disconnect" vhdl-template-disconnect t]
3383 ["Else" vhdl-template-else t]
3384 ["Elsif" vhdl-template-elsif t]
3385 ["Entity" vhdl-template-entity t]
3386 ["Exit" vhdl-template-exit t]
3387 ["File" vhdl-template-file t]
3388 ["For (Generate)" vhdl-template-for-generate t]
3389 ["For (Loop)" vhdl-template-for-loop t]
3390 ["Function (Body)" vhdl-template-function-body t]
3391 ["Function (Decl)" vhdl-template-function-decl t]
3392 ["Generic" vhdl-template-generic t]
3393 ["Group (Decl)" vhdl-template-group-decl t]
3394 ["Group (Template)" vhdl-template-group-template t])
3395 ("VHDL Construct 2"
3396 ["If (Generate)" vhdl-template-if-generate t]
3397 ["If (Then)" vhdl-template-if-then t]
3398 ["Library" vhdl-template-library t]
3399 ["Loop" vhdl-template-bare-loop t]
3400 ["Map" vhdl-template-map t]
3401 ["Next" vhdl-template-next t]
3402 ["Others (Aggregate)" vhdl-template-others t]
3403 ["Package (Decl)" vhdl-template-package-decl t]
3404 ["Package (Body)" vhdl-template-package-body t]
3405 ["Port" vhdl-template-port t]
3406 ["Procedure (Body)" vhdl-template-procedure-body t]
3407 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3408 ["Process (Comb)" vhdl-template-process-comb t]
3409 ["Process (Seq)" vhdl-template-process-seq t]
3410 ["Report" vhdl-template-report t]
3411 ["Return" vhdl-template-return t]
3412 ["Select" vhdl-template-selected-signal-asst t]
3413 ["Signal" vhdl-template-signal t]
3414 ["Subtype" vhdl-template-subtype t]
3415 ["Type" vhdl-template-type t]
3416 ["Use" vhdl-template-use t]
3417 ["Variable" vhdl-template-variable t]
3418 ["Wait" vhdl-template-wait t]
3419 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3420 ["When" vhdl-template-when t]
3421 ["While (Loop)" vhdl-template-while-loop t]
3422 ["With" vhdl-template-with t]))
3423 (when (vhdl-standard-p 'ams)
3424 '(("VHDL-AMS Construct"
3425 ["Break" vhdl-template-break t]
3426 ["Case (Use)" vhdl-template-case-use t]
3427 ["If (Use)" vhdl-template-if-use t]
3428 ["Limit" vhdl-template-limit t]
3429 ["Nature" vhdl-template-nature t]
3430 ["Procedural" vhdl-template-procedural t]
3431 ["Quantity (Free)" vhdl-template-quantity-free t]
3432 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3433 ["Quantity (Source)" vhdl-template-quantity-source t]
3434 ["Subnature" vhdl-template-subnature t]
3435 ["Terminal" vhdl-template-terminal t])))
3436 '(["Insert Construct..." vhdl-template-insert-construct
3437 :keys "C-c C-i C-t"]
3438 "--")
3439 (list
3440 (append
3441 '("Package")
3442 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3443 ["numeric_std" vhdl-template-package-numeric-std t]
3444 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3445 ["textio" vhdl-template-package-textio t]
3446 "--"
3447 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3448 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3449 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3450 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3451 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3452 "--")
3453 (when (vhdl-standard-p 'ams)
3454 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3455 ["material_constants" vhdl-template-package-material-constants t]
3456 ["energy_systems" vhdl-template-package-energy-systems t]
3457 ["electrical_systems" vhdl-template-package-electrical-systems t]
3458 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3459 ["radiant_systems" vhdl-template-package-radiant-systems t]
3460 ["thermal_systems" vhdl-template-package-thermal-systems t]
3461 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3462 "--"))
3463 (when (vhdl-standard-p 'math)
3464 '(["math_complex" vhdl-template-package-math-complex t]
3465 ["math_real" vhdl-template-package-math-real t]
3466 "--"))
3467 '(["Insert Package..." vhdl-template-insert-package
3468 :keys "C-c C-i C-p"])))
3469 '(("Directive"
3470 ["translate_on" vhdl-template-directive-translate-on t]
3471 ["translate_off" vhdl-template-directive-translate-off t]
3472 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3473 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3474 "--"
3475 ["Insert Directive..." vhdl-template-insert-directive
3476 :keys "C-c C-i C-d"])
3477 "--"
3478 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3479 ["Insert Footer" vhdl-template-footer t]
3480 ["Insert Date" vhdl-template-insert-date t]
3481 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3482 "--"
3483 ["Query Next Prompt" vhdl-template-search-prompt t]))
3484 ,(append
3485 '("Model")
3486 ;; add menu entries for defined models
3487 (let ((model-alist vhdl-model-alist) menu-list model)
3488 (while model-alist
3489 (setq model (car model-alist))
3490 (setq menu-list
3491 (cons
3492 (vector
3493 (nth 0 model)
3494 (vhdl-function-name "vhdl-model" (nth 0 model))
3495 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3496 menu-list))
3497 (setq model-alist (cdr model-alist)))
3498 (setq menu-list (nreverse menu-list))
3499 (vhdl-menu-split menu-list "Model"))
3500 '("--" "--"
3501 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3502 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3503 ("Port"
3504 ["Copy" vhdl-port-copy t]
3505 "--"
3506 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3507 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3508 ["Paste As Instance" vhdl-port-paste-instance
3509 :keys "C-c C-p C-i" :active vhdl-port-list]
3510 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3511 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3512 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3513 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3514 "--"
3515 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3516 "--"
3517 ["Flatten" vhdl-port-flatten
3518 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3519 ["Reverse Direction" vhdl-port-reverse-direction
3520 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3521 ("Compose"
3522 ["New Component" vhdl-compose-new-component t]
3523 ["Copy Component" vhdl-port-copy t]
3524 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3525 ["Wire Components" vhdl-compose-wire-components t]
3526 "--"
3527 ["Generate Configuration" vhdl-compose-configuration t]
3528 ["Generate Components Package" vhdl-compose-components-package t])
3529 ("Subprogram"
3530 ["Copy" vhdl-subprog-copy t]
3531 "--"
3532 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3533 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3534 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3535 "--"
3536 ["Flatten" vhdl-subprog-flatten
3537 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3538 "--"
3539 ("Comment"
3540 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3541 "--"
3542 ["Insert Inline Comment" vhdl-comment-append-inline t]
3543 ["Insert Horizontal Line" vhdl-comment-display-line t]
3544 ["Insert Display Comment" vhdl-comment-display t]
3545 "--"
3546 ["Fill Comment" fill-paragraph t]
3547 ["Fill Comment Region" fill-region (mark)]
3548 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3549 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3550 ("Line"
3551 ["Kill" vhdl-line-kill t]
3552 ["Copy" vhdl-line-copy t]
3553 ["Yank" vhdl-line-yank t]
3554 ["Expand" vhdl-line-expand t]
3555 "--"
3556 ["Transpose Next" vhdl-line-transpose-next t]
3557 ["Transpose Prev" vhdl-line-transpose-previous t]
3558 ["Open" vhdl-line-open t]
3559 ["Join" vhdl-delete-indentation t]
3560 "--"
3561 ["Goto" goto-line t]
3562 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3563 ("Move"
3564 ["Forward Statement" vhdl-end-of-statement t]
3565 ["Backward Statement" vhdl-beginning-of-statement t]
3566 ["Forward Expression" vhdl-forward-sexp t]
3567 ["Backward Expression" vhdl-backward-sexp t]
3568 ["Forward Same Indent" vhdl-forward-same-indent t]
3569 ["Backward Same Indent" vhdl-backward-same-indent t]
3570 ["Forward Function" vhdl-end-of-defun t]
3571 ["Backward Function" vhdl-beginning-of-defun t]
3572 ["Mark Function" vhdl-mark-defun t])
3573 "--"
3574 ("Indent"
3575 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3576 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3577 ["Region" vhdl-indent-region (mark)]
3578 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3579 ("Align"
3580 ["Group" vhdl-align-group t]
3581 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3582 ["List" vhdl-align-list t]
3583 ["Declarations" vhdl-align-declarations t]
3584 ["Region" vhdl-align-region (mark)]
3585 ["Buffer" vhdl-align-buffer t]
3586 "--"
3587 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3588 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3589 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3590 ("Fill"
3591 ["List" vhdl-fill-list t]
3592 ["Group" vhdl-fill-group t]
3593 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3594 ["Region" vhdl-fill-region (mark)])
3595 ("Beautify"
3596 ["Region" vhdl-beautify-region (mark)]
3597 ["Buffer" vhdl-beautify-buffer t])
3598 ("Fix"
3599 ["Generic/Port Clause" vhdl-fix-clause t]
3600 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3601 "--"
3602 ["Case Region" vhdl-fix-case-region (mark)]
3603 ["Case Buffer" vhdl-fix-case-buffer t]
3604 "--"
3605 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3606 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3607 "--"
3608 ["Statement Region" vhdl-fix-statement-region (mark)]
3609 ["Statement Buffer" vhdl-fix-statement-buffer t]
3610 "--"
3611 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3612 ("Update"
3613 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3614 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3615 "--"
3616 ["Fontify Buffer" vhdl-fontify-buffer t]
3617 ["Statistics Buffer" vhdl-statistics-buffer t]
3618 ["Show Messages" vhdl-show-messages t]
3619 ["Syntactic Info" vhdl-show-syntactic-information t]
3620 "--"
3621 ["Speedbar" vhdl-speedbar t]
3622 ["Hide/Show" vhdl-hs-minor-mode t]
3623 "--"
3624 ("Documentation"
3625 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3626 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3627 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3628 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3629 ["Version" vhdl-version t]
3630 ["Bug Report..." vhdl-submit-bug-report t]
3631 "--"
3632 ("Options"
3633 ("Mode"
3634 ["Electric Mode"
3635 (progn (customize-set-variable 'vhdl-electric-mode
3636 (not vhdl-electric-mode))
3637 (vhdl-mode-line-update))
3638 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3639 ["Stutter Mode"
3640 (progn (customize-set-variable 'vhdl-stutter-mode
3641 (not vhdl-stutter-mode))
3642 (vhdl-mode-line-update))
3643 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3644 ["Indent Tabs Mode"
3645 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3646 (not vhdl-indent-tabs-mode))
3647 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3648 :style toggle :selected vhdl-indent-tabs-mode]
3649 "--"
3650 ["Customize Group..." (customize-group 'vhdl-mode) t])
3651 ("Project"
3652 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3653 ,(append
3654 '("Selected Project at Startup"
3655 ["None" (progn (customize-set-variable 'vhdl-project nil)
3656 (vhdl-set-project ""))
3657 :style radio :selected (null vhdl-project)]
3658 "--")
3659 ;; add menu entries for defined projects
3660 (let ((project-alist vhdl-project-alist) menu-list name)
3661 (while project-alist
3662 (setq name (caar project-alist))
3663 (setq menu-list
3664 (cons `[,name (progn (customize-set-variable
3665 'vhdl-project ,name)
3666 (vhdl-set-project ,name))
3667 :style radio :selected (equal ,name vhdl-project)]
3668 menu-list))
3669 (setq project-alist (cdr project-alist)))
3670 (setq menu-list (nreverse menu-list))
3671 (vhdl-menu-split menu-list "Project")))
3672 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3673 ("Auto Load Setup File"
3674 ["At Startup"
3675 (customize-set-variable 'vhdl-project-auto-load
3676 (if (memq 'startup vhdl-project-auto-load)
3677 (delq 'startup vhdl-project-auto-load)
3678 (cons 'startup vhdl-project-auto-load)))
3679 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3680 ["Sort Projects"
3681 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3682 :style toggle :selected vhdl-project-sort]
3683 "--"
3684 ["Customize Group..." (customize-group 'vhdl-project) t])
3685 ("Compiler"
3686 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3687 ,(append
3688 '("Selected Compiler at Startup")
3689 ;; add menu entries for defined compilers
3690 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3691 (while comp-alist
3692 (setq name (caar comp-alist))
3693 (setq menu-list
3694 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3695 :style radio :selected (equal ,name vhdl-compiler)]
3696 menu-list))
3697 (setq comp-alist (cdr comp-alist)))
3698 (setq menu-list (nreverse menu-list))
3699 (vhdl-menu-split menu-list "Compiler")))
3700 ["Use Local Error Regexp"
3701 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3702 (not vhdl-compile-use-local-error-regexp))
3703 :style toggle :selected vhdl-compile-use-local-error-regexp]
3704 ["Makefile Default Targets..."
3705 (customize-option 'vhdl-makefile-default-targets) t]
3706 ["Makefile Generation Hook..."
3707 (customize-option 'vhdl-makefile-generation-hook) t]
3708 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3709 "--"
3710 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3711 ("Style"
3712 ("VHDL Standard"
3713 ["VHDL'87"
3714 (progn (customize-set-variable 'vhdl-standard
3715 (list '87 (cadr vhdl-standard)))
3716 (vhdl-activate-customizations))
3717 :style radio :selected (eq '87 (car vhdl-standard))]
3718 ["VHDL'93/02"
3719 (progn (customize-set-variable 'vhdl-standard
3720 (list '93 (cadr vhdl-standard)))
3721 (vhdl-activate-customizations))
3722 :style radio :selected (eq '93 (car vhdl-standard))]
3723 ["VHDL'08"
3724 (progn (customize-set-variable 'vhdl-standard
3725 (list '08 (cadr vhdl-standard)))
3726 (vhdl-activate-customizations))
3727 :style radio :selected (eq '08 (car vhdl-standard))]
3728 "--"
3729 ["VHDL-AMS"
3730 (progn (customize-set-variable
3731 'vhdl-standard (list (car vhdl-standard)
3732 (if (memq 'ams (cadr vhdl-standard))
3733 (delq 'ams (cadr vhdl-standard))
3734 (cons 'ams (cadr vhdl-standard)))))
3735 (vhdl-activate-customizations))
3736 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3737 ["Math Packages"
3738 (progn (customize-set-variable
3739 'vhdl-standard (list (car vhdl-standard)
3740 (if (memq 'math (cadr vhdl-standard))
3741 (delq 'math (cadr vhdl-standard))
3742 (cons 'math (cadr vhdl-standard)))))
3743 (vhdl-activate-customizations))
3744 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3745 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3746 ["Upper Case Keywords"
3747 (customize-set-variable 'vhdl-upper-case-keywords
3748 (not vhdl-upper-case-keywords))
3749 :style toggle :selected vhdl-upper-case-keywords]
3750 ["Upper Case Types"
3751 (customize-set-variable 'vhdl-upper-case-types
3752 (not vhdl-upper-case-types))
3753 :style toggle :selected vhdl-upper-case-types]
3754 ["Upper Case Attributes"
3755 (customize-set-variable 'vhdl-upper-case-attributes
3756 (not vhdl-upper-case-attributes))
3757 :style toggle :selected vhdl-upper-case-attributes]
3758 ["Upper Case Enumeration Values"
3759 (customize-set-variable 'vhdl-upper-case-enum-values
3760 (not vhdl-upper-case-enum-values))
3761 :style toggle :selected vhdl-upper-case-enum-values]
3762 ["Upper Case Constants"
3763 (customize-set-variable 'vhdl-upper-case-constants
3764 (not vhdl-upper-case-constants))
3765 :style toggle :selected vhdl-upper-case-constants]
3766 ("Use Direct Instantiation"
3767 ["Never"
3768 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3769 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3770 ["Standard"
3771 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3772 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3773 ["Always"
3774 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3775 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3776 ["Include Array Index and Record Field in Sensitivity List"
3777 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3778 (not vhdl-array-index-record-field-in-sensitivity-list))
3779 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3780 "--"
3781 ["Customize Group..." (customize-group 'vhdl-style) t])
3782 ("Naming"
3783 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3784 ["Architecture File Name..."
3785 (customize-option 'vhdl-architecture-file-name) t]
3786 ["Configuration File Name..."
3787 (customize-option 'vhdl-configuration-file-name) t]
3788 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3789 ("File Name Case"
3790 ["As Is"
3791 (customize-set-variable 'vhdl-file-name-case 'identity)
3792 :style radio :selected (eq 'identity vhdl-file-name-case)]
3793 ["Lower Case"
3794 (customize-set-variable 'vhdl-file-name-case 'downcase)
3795 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3796 ["Upper Case"
3797 (customize-set-variable 'vhdl-file-name-case 'upcase)
3798 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3799 ["Capitalize"
3800 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3801 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3802 "--"
3803 ["Customize Group..." (customize-group 'vhdl-naming) t])
3804 ("Template"
3805 ("Electric Keywords"
3806 ["VHDL Keywords"
3807 (customize-set-variable 'vhdl-electric-keywords
3808 (if (memq 'vhdl vhdl-electric-keywords)
3809 (delq 'vhdl vhdl-electric-keywords)
3810 (cons 'vhdl vhdl-electric-keywords)))
3811 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3812 ["User Model Keywords"
3813 (customize-set-variable 'vhdl-electric-keywords
3814 (if (memq 'user vhdl-electric-keywords)
3815 (delq 'user vhdl-electric-keywords)
3816 (cons 'user vhdl-electric-keywords)))
3817 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3818 ("Insert Optional Labels"
3819 ["None"
3820 (customize-set-variable 'vhdl-optional-labels 'none)
3821 :style radio :selected (eq 'none vhdl-optional-labels)]
3822 ["Processes Only"
3823 (customize-set-variable 'vhdl-optional-labels 'process)
3824 :style radio :selected (eq 'process vhdl-optional-labels)]
3825 ["All Constructs"
3826 (customize-set-variable 'vhdl-optional-labels 'all)
3827 :style radio :selected (eq 'all vhdl-optional-labels)])
3828 ("Insert Empty Lines"
3829 ["None"
3830 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3831 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3832 ["Design Units Only"
3833 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3834 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3835 ["All Constructs"
3836 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3837 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3838 ["Argument List Indent"
3839 (customize-set-variable 'vhdl-argument-list-indent
3840 (not vhdl-argument-list-indent))
3841 :style toggle :selected vhdl-argument-list-indent]
3842 ["Association List with Formals"
3843 (customize-set-variable 'vhdl-association-list-with-formals
3844 (not vhdl-association-list-with-formals))
3845 :style toggle :selected vhdl-association-list-with-formals]
3846 ["Conditions in Parenthesis"
3847 (customize-set-variable 'vhdl-conditions-in-parenthesis
3848 (not vhdl-conditions-in-parenthesis))
3849 :style toggle :selected vhdl-conditions-in-parenthesis]
3850 ["Sensitivity List uses 'all'"
3851 (customize-set-variable 'vhdl-sensitivity-list-all
3852 (not vhdl-sensitivity-list-all))
3853 :style toggle :selected vhdl-sensitivity-list-all]
3854 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3855 ["One String..." (customize-option 'vhdl-one-string) t]
3856 ("File Header"
3857 ["Header String..." (customize-option 'vhdl-file-header) t]
3858 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3859 ["Company Name..." (customize-option 'vhdl-company-name) t]
3860 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3861 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3862 ["Date Format..." (customize-option 'vhdl-date-format) t]
3863 ["Modify Date Prefix String..."
3864 (customize-option 'vhdl-modify-date-prefix-string) t]
3865 ["Modify Date on Saving"
3866 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3867 (not vhdl-modify-date-on-saving))
3868 (vhdl-activate-customizations))
3869 :style toggle :selected vhdl-modify-date-on-saving])
3870 ("Sequential Process"
3871 ("Kind of Reset"
3872 ["None"
3873 (customize-set-variable 'vhdl-reset-kind 'none)
3874 :style radio :selected (eq 'none vhdl-reset-kind)]
3875 ["Synchronous"
3876 (customize-set-variable 'vhdl-reset-kind 'sync)
3877 :style radio :selected (eq 'sync vhdl-reset-kind)]
3878 ["Asynchronous"
3879 (customize-set-variable 'vhdl-reset-kind 'async)
3880 :style radio :selected (eq 'async vhdl-reset-kind)]
3881 ["Query"
3882 (customize-set-variable 'vhdl-reset-kind 'query)
3883 :style radio :selected (eq 'query vhdl-reset-kind)])
3884 ["Reset is Active High"
3885 (customize-set-variable 'vhdl-reset-active-high
3886 (not vhdl-reset-active-high))
3887 :style toggle :selected vhdl-reset-active-high]
3888 ["Use Rising Clock Edge"
3889 (customize-set-variable 'vhdl-clock-rising-edge
3890 (not vhdl-clock-rising-edge))
3891 :style toggle :selected vhdl-clock-rising-edge]
3892 ("Clock Edge Condition"
3893 ["Standard"
3894 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3895 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3896 ["Function \"rising_edge\""
3897 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3898 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3899 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3900 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3901 "--"
3902 ["Customize Group..." (customize-group 'vhdl-template) t])
3903 ("Model"
3904 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3905 ("Port"
3906 ["Include Port Comments"
3907 (customize-set-variable 'vhdl-include-port-comments
3908 (not vhdl-include-port-comments))
3909 :style toggle :selected vhdl-include-port-comments]
3910 ["Include Direction Comments"
3911 (customize-set-variable 'vhdl-include-direction-comments
3912 (not vhdl-include-direction-comments))
3913 :style toggle :selected vhdl-include-direction-comments]
3914 ["Include Type Comments"
3915 (customize-set-variable 'vhdl-include-type-comments
3916 (not vhdl-include-type-comments))
3917 :style toggle :selected vhdl-include-type-comments]
3918 ("Include Group Comments"
3919 ["Never"
3920 (customize-set-variable 'vhdl-include-group-comments 'never)
3921 :style radio :selected (eq 'never vhdl-include-group-comments)]
3922 ["Declarations"
3923 (customize-set-variable 'vhdl-include-group-comments 'decl)
3924 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3925 ["Always"
3926 (customize-set-variable 'vhdl-include-group-comments 'always)
3927 :style radio :selected (eq 'always vhdl-include-group-comments)])
3928 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
3929 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3930 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3931 ("Testbench"
3932 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3933 ["Architecture Name..."
3934 (customize-option 'vhdl-testbench-architecture-name) t]
3935 ["Configuration Name..."
3936 (customize-option 'vhdl-testbench-configuration-name) t]
3937 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3938 ["Include Header"
3939 (customize-set-variable 'vhdl-testbench-include-header
3940 (not vhdl-testbench-include-header))
3941 :style toggle :selected vhdl-testbench-include-header]
3942 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3943 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3944 ["Initialize Signals"
3945 (customize-set-variable 'vhdl-testbench-initialize-signals
3946 (not vhdl-testbench-initialize-signals))
3947 :style toggle :selected vhdl-testbench-initialize-signals]
3948 ["Include Library Clause"
3949 (customize-set-variable 'vhdl-testbench-include-library
3950 (not vhdl-testbench-include-library))
3951 :style toggle :selected vhdl-testbench-include-library]
3952 ["Include Configuration"
3953 (customize-set-variable 'vhdl-testbench-include-configuration
3954 (not vhdl-testbench-include-configuration))
3955 :style toggle :selected vhdl-testbench-include-configuration]
3956 ("Create Files"
3957 ["None"
3958 (customize-set-variable 'vhdl-testbench-create-files 'none)
3959 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3960 ["Single"
3961 (customize-set-variable 'vhdl-testbench-create-files 'single)
3962 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3963 ["Separate"
3964 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3965 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3966 ["Testbench Entity File Name..."
3967 (customize-option 'vhdl-testbench-entity-file-name) t]
3968 ["Testbench Architecture File Name..."
3969 (customize-option 'vhdl-testbench-architecture-file-name) t])
3970 "--"
3971 ["Customize Group..." (customize-group 'vhdl-port) t])
3972 ("Compose"
3973 ["Architecture Name..."
3974 (customize-option 'vhdl-compose-architecture-name) t]
3975 ["Configuration Name..."
3976 (customize-option 'vhdl-compose-configuration-name) t]
3977 ["Components Package Name..."
3978 (customize-option 'vhdl-components-package-name) t]
3979 ["Use Components Package"
3980 (customize-set-variable 'vhdl-use-components-package
3981 (not vhdl-use-components-package))
3982 :style toggle :selected vhdl-use-components-package]
3983 ["Include Header"
3984 (customize-set-variable 'vhdl-compose-include-header
3985 (not vhdl-compose-include-header))
3986 :style toggle :selected vhdl-compose-include-header]
3987 ("Create Entity/Architecture Files"
3988 ["None"
3989 (customize-set-variable 'vhdl-compose-create-files 'none)
3990 :style radio :selected (eq 'none vhdl-compose-create-files)]
3991 ["Single"
3992 (customize-set-variable 'vhdl-compose-create-files 'single)
3993 :style radio :selected (eq 'single vhdl-compose-create-files)]
3994 ["Separate"
3995 (customize-set-variable 'vhdl-compose-create-files 'separate)
3996 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3997 ["Create Configuration File"
3998 (customize-set-variable 'vhdl-compose-configuration-create-file
3999 (not vhdl-compose-configuration-create-file))
4000 :style toggle :selected vhdl-compose-configuration-create-file]
4001 ["Hierarchical Configuration"
4002 (customize-set-variable 'vhdl-compose-configuration-hierarchical
4003 (not vhdl-compose-configuration-hierarchical))
4004 :style toggle :selected vhdl-compose-configuration-hierarchical]
4005 ["Use Subconfiguration"
4006 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
4007 (not vhdl-compose-configuration-use-subconfiguration))
4008 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
4009 "--"
4010 ["Customize Group..." (customize-group 'vhdl-compose) t])
4011 ("Comment"
4012 ["Self Insert Comments"
4013 (customize-set-variable 'vhdl-self-insert-comments
4014 (not vhdl-self-insert-comments))
4015 :style toggle :selected vhdl-self-insert-comments]
4016 ["Prompt for Comments"
4017 (customize-set-variable 'vhdl-prompt-for-comments
4018 (not vhdl-prompt-for-comments))
4019 :style toggle :selected vhdl-prompt-for-comments]
4020 ["Inline Comment Column..."
4021 (customize-option 'vhdl-inline-comment-column) t]
4022 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
4023 "--"
4024 ["Customize Group..." (customize-group 'vhdl-comment) t])
4025 ("Beautify"
4026 ["Auto Align Templates"
4027 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
4028 :style toggle :selected vhdl-auto-align]
4029 ["Align Line Groups"
4030 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
4031 :style toggle :selected vhdl-align-groups]
4032 ["Group Separation String..."
4033 (customize-option 'vhdl-align-group-separate) t]
4034 ["Align Lines with Same Indent"
4035 (customize-set-variable 'vhdl-align-same-indent
4036 (not vhdl-align-same-indent))
4037 :style toggle :selected vhdl-align-same-indent]
4038 ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
4039 "--"
4040 ["Customize Group..." (customize-group 'vhdl-beautify) t])
4041 ("Highlight"
4042 ["Highlighting On/Off..."
4043 (customize-option
4044 (if (fboundp 'global-font-lock-mode)
4045 'global-font-lock-mode 'font-lock-auto-fontify)) t]
4046 ["Highlight Keywords"
4047 (progn (customize-set-variable 'vhdl-highlight-keywords
4048 (not vhdl-highlight-keywords))
4049 (vhdl-fontify-buffer))
4050 :style toggle :selected vhdl-highlight-keywords]
4051 ["Highlight Names"
4052 (progn (customize-set-variable 'vhdl-highlight-names
4053 (not vhdl-highlight-names))
4054 (vhdl-fontify-buffer))
4055 :style toggle :selected vhdl-highlight-names]
4056 ["Highlight Special Words"
4057 (progn (customize-set-variable 'vhdl-highlight-special-words
4058 (not vhdl-highlight-special-words))
4059 (vhdl-fontify-buffer))
4060 :style toggle :selected vhdl-highlight-special-words]
4061 ["Highlight Forbidden Words"
4062 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4063 (not vhdl-highlight-forbidden-words))
4064 (vhdl-fontify-buffer))
4065 :style toggle :selected vhdl-highlight-forbidden-words]
4066 ["Highlight Verilog Keywords"
4067 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4068 (not vhdl-highlight-verilog-keywords))
4069 (vhdl-fontify-buffer))
4070 :style toggle :selected vhdl-highlight-verilog-keywords]
4071 ["Highlight \"translate_off\""
4072 (progn (customize-set-variable 'vhdl-highlight-translate-off
4073 (not vhdl-highlight-translate-off))
4074 (vhdl-fontify-buffer))
4075 :style toggle :selected vhdl-highlight-translate-off]
4076 ["Case Sensitive Highlighting"
4077 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4078 (not vhdl-highlight-case-sensitive))
4079 (vhdl-fontify-buffer))
4080 :style toggle :selected vhdl-highlight-case-sensitive]
4081 ["Special Syntax Definition..."
4082 (customize-option 'vhdl-special-syntax-alist) t]
4083 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
4084 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
4085 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
4086 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
4087 "--"
4088 ["Customize Group..." (customize-group 'vhdl-highlight) t])
4089 ("Speedbar"
4090 ["Auto Open at Startup"
4091 (customize-set-variable 'vhdl-speedbar-auto-open
4092 (not vhdl-speedbar-auto-open))
4093 :style toggle :selected vhdl-speedbar-auto-open]
4094 ("Default Displaying Mode"
4095 ["Files"
4096 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
4097 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
4098 ["Directory Hierarchy"
4099 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
4100 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
4101 ["Project Hierarchy"
4102 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
4103 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
4104 ["Indentation Offset..."
4105 (customize-option 'speedbar-indentation-width) t]
4106 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
4107 ["Jump to Unit when Opening"
4108 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4109 (not vhdl-speedbar-jump-to-unit))
4110 :style toggle :selected vhdl-speedbar-jump-to-unit]
4111 ["Update Hierarchy on File Saving"
4112 (customize-set-variable 'vhdl-speedbar-update-on-saving
4113 (not vhdl-speedbar-update-on-saving))
4114 :style toggle :selected vhdl-speedbar-update-on-saving]
4115 ("Save in Cache File"
4116 ["Hierarchy Information"
4117 (customize-set-variable 'vhdl-speedbar-save-cache
4118 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4119 (delq 'hierarchy vhdl-speedbar-save-cache)
4120 (cons 'hierarchy vhdl-speedbar-save-cache)))
4121 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4122 ["Displaying Status"
4123 (customize-set-variable 'vhdl-speedbar-save-cache
4124 (if (memq 'display vhdl-speedbar-save-cache)
4125 (delq 'display vhdl-speedbar-save-cache)
4126 (cons 'display vhdl-speedbar-save-cache)))
4127 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4128 ["Cache File Name..."
4129 (customize-option 'vhdl-speedbar-cache-file-name) t]
4130 "--"
4131 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4132 ("Menu"
4133 ["Add Index Menu when Loading File"
4134 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4135 (vhdl-index-menu-init))
4136 :style toggle :selected vhdl-index-menu]
4137 ["Add Source File Menu when Loading File"
4138 (progn (customize-set-variable 'vhdl-source-file-menu
4139 (not vhdl-source-file-menu))
4140 (vhdl-add-source-files-menu))
4141 :style toggle :selected vhdl-source-file-menu]
4142 ["Add Hideshow Menu at Startup"
4143 (progn (customize-set-variable 'vhdl-hideshow-menu
4144 (not vhdl-hideshow-menu))
4145 (vhdl-activate-customizations))
4146 :style toggle :selected vhdl-hideshow-menu]
4147 ["Hide Everything Initially"
4148 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4149 :style toggle :selected vhdl-hide-all-init]
4150 "--"
4151 ["Customize Group..." (customize-group 'vhdl-menu) t])
4152 ("Print"
4153 ["In Two Column Format"
4154 (progn (customize-set-variable 'vhdl-print-two-column
4155 (not vhdl-print-two-column))
4156 (message "Activate new setting by saving options and restarting Emacs"))
4157 :style toggle :selected vhdl-print-two-column]
4158 ["Use Customized Faces"
4159 (progn (customize-set-variable 'vhdl-print-customize-faces
4160 (not vhdl-print-customize-faces))
4161 (message "Activate new setting by saving options and restarting Emacs"))
4162 :style toggle :selected vhdl-print-customize-faces]
4163 "--"
4164 ["Customize Group..." (customize-group 'vhdl-print) t])
4165 ("Miscellaneous"
4166 ["Use Intelligent Tab"
4167 (progn (customize-set-variable 'vhdl-intelligent-tab
4168 (not vhdl-intelligent-tab))
4169 (vhdl-activate-customizations))
4170 :style toggle :selected vhdl-intelligent-tab]
4171 ["Indent Syntax-Based"
4172 (customize-set-variable 'vhdl-indent-syntax-based
4173 (not vhdl-indent-syntax-based))
4174 :style toggle :selected vhdl-indent-syntax-based]
4175 ["Indent Comments Like Next Code Line"
4176 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4177 (not vhdl-indent-comment-like-next-code-line))
4178 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4179 ["Word Completion is Case Sensitive"
4180 (customize-set-variable 'vhdl-word-completion-case-sensitive
4181 (not vhdl-word-completion-case-sensitive))
4182 :style toggle :selected vhdl-word-completion-case-sensitive]
4183 ["Word Completion in Minibuffer"
4184 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4185 (not vhdl-word-completion-in-minibuffer))
4186 (message "Activate new setting by saving options and restarting Emacs"))
4187 :style toggle :selected vhdl-word-completion-in-minibuffer]
4188 ["Underscore is Part of Word"
4189 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4190 (not vhdl-underscore-is-part-of-word))
4191 (vhdl-activate-customizations))
4192 :style toggle :selected vhdl-underscore-is-part-of-word]
4193 "--"
4194 ["Customize Group..." (customize-group 'vhdl-misc) t])
4195 ["Related..." (customize-browse 'vhdl-related) t]
4196 "--"
4197 ["Save Options" customize-save-customized t]
4198 ["Activate Options" vhdl-activate-customizations t]
4199 ["Browse Options..." vhdl-customize t])))
4201 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4202 "VHDL Mode menu.")
4204 (defun vhdl-update-mode-menu ()
4205 "Update VHDL Mode menu."
4206 (interactive)
4207 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4208 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4209 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4210 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4211 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4213 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4214 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4216 (defconst vhdl-imenu-generic-expression
4218 ("Subprogram"
4219 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4221 ("Instance"
4222 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4224 ("Component"
4225 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4227 ("Procedural"
4228 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4230 ("Process"
4231 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4233 ("Block"
4234 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4236 ("Package"
4237 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4239 ("Configuration"
4240 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4242 ("Architecture"
4243 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4245 ("Entity"
4246 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4248 ("Context"
4249 "^\\s-*\\(context\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4252 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4254 (defun vhdl-index-menu-init ()
4255 "Initialize index menu."
4256 (set (make-local-variable 'imenu-case-fold-search) t)
4257 (set (make-local-variable 'imenu-generic-expression)
4258 vhdl-imenu-generic-expression)
4259 (when (and vhdl-index-menu (fboundp 'imenu))
4260 (imenu-add-to-menubar "Index")))
4262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4263 ;; Source file menu (using `easy-menu.el')
4265 (defvar vhdl-sources-menu nil)
4267 (defun vhdl-directory-files (directory &optional full match)
4268 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4269 message."
4270 (if (not (file-directory-p directory))
4271 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4272 (let ((dir (directory-files directory full match)))
4273 (setq dir (delete "." dir))
4274 (setq dir (delete ".." dir))
4275 dir)))
4277 (defun vhdl-get-source-files (&optional full directory)
4278 "Get list of VHDL source files in DIRECTORY or current directory."
4279 (let ((mode-alist auto-mode-alist)
4280 filename-regexp)
4281 ;; create regular expressions for matching file names
4282 (setq filename-regexp "\\`[^.].*\\(")
4283 (while mode-alist
4284 (when (eq (cdar mode-alist) 'vhdl-mode)
4285 (setq filename-regexp
4286 (concat filename-regexp (caar mode-alist) "\\|")))
4287 (setq mode-alist (cdr mode-alist)))
4288 (setq filename-regexp
4289 (concat (substring filename-regexp 0
4290 (string-match "\\\\|$" filename-regexp)) "\\)"))
4291 ;; find files
4292 (vhdl-directory-files
4293 (or directory default-directory) full filename-regexp)))
4295 (defun vhdl-add-source-files-menu ()
4296 "Scan directory for all VHDL source files and generate menu.
4297 The directory of the current source file is scanned."
4298 (interactive)
4299 (message "Scanning directory for source files ...")
4300 (let ((newmap (current-local-map))
4301 (file-list (vhdl-get-source-files))
4302 menu-list found)
4303 ;; Create list for menu
4304 (setq found nil)
4305 (while file-list
4306 (setq found t)
4307 (push (vector (car file-list) (list 'find-file (car file-list)) t)
4308 menu-list)
4309 (setq file-list (cdr file-list)))
4310 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4311 (when found (push "--" menu-list))
4312 (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
4313 (push "Sources" menu-list)
4314 ;; Create menu
4315 (easy-menu-add menu-list)
4316 (easy-menu-define vhdl-sources-menu newmap
4317 "VHDL source files menu" menu-list))
4318 (message ""))
4321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4322 ;;; Mode definition
4323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4324 ;; performs all buffer local initializations
4326 ;;;###autoload
4327 (define-derived-mode vhdl-mode prog-mode
4328 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4329 (vhdl-electric-mode "e")
4330 (vhdl-stutter-mode "s"))
4331 "Major mode for editing VHDL code.
4333 Usage:
4334 ------
4336 TEMPLATE INSERTION (electrification):
4337 After typing a VHDL keyword and entering `SPC', you are prompted for
4338 arguments while a template is generated for that VHDL construct. Typing
4339 `RET' or `C-g' at the first (mandatory) prompt aborts the current
4340 template generation. Optional arguments are indicated by square
4341 brackets and removed if the queried string is left empty. Prompts for
4342 mandatory arguments remain in the code if the queried string is left
4343 empty. They can be queried again by `C-c C-t C-q'. Enabled
4344 electrification is indicated by `/e' in the mode line.
4346 Typing `M-SPC' after a keyword inserts a space without calling the
4347 template generator. Automatic template generation (i.e.
4348 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4349 setting option `vhdl-electric-mode' (see OPTIONS).
4351 Template generators can be invoked from the VHDL menu, by key
4352 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4353 the keyword (i.e. first word of menu entry not in parenthesis) and
4354 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4355 conf, comp, cons, func, inst, pack, sig, var.
4357 Template styles can be customized in customization group
4358 `vhdl-template' (see OPTIONS).
4361 HEADER INSERTION:
4362 A file header can be inserted by `C-c C-t C-h'. A file footer
4363 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4364 See customization group `vhdl-header'.
4367 STUTTERING:
4368 Double striking of some keys inserts cumbersome VHDL syntax elements.
4369 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4370 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4371 the mode line. The stuttering keys and their effects are:
4373 ;; --> \" : \" [ --> ( -- --> comment
4374 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4375 .. --> \" => \" ] --> ) --- --> horizontal line
4376 ,, --> \" <= \" ]] --> ] ---- --> display comment
4377 == --> \" == \" \\='\\=' --> \\\"
4380 WORD COMPLETION:
4381 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4382 word in the buffer that starts alike, inserts it and adjusts case.
4383 Re-typing `TAB' toggles through alternative word completions. This also
4384 works in the minibuffer (i.e. in template generator prompts).
4386 Typing `TAB' after `(' looks for and inserts complete parenthesized
4387 expressions (e.g. for array index ranges). All keywords as well as
4388 standard types and subprograms of VHDL have predefined abbreviations
4389 (e.g., type \"std\" and `TAB' will toggle through all standard types
4390 beginning with \"std\").
4392 Typing `TAB' after a non-word character indents the line if at the
4393 beginning of a line (i.e. no preceding non-blank characters), and
4394 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4395 stop.
4398 COMMENTS:
4399 `--' puts a single comment.
4400 `---' draws a horizontal line for separating code segments.
4401 `----' inserts a display comment, i.e. two horizontal lines
4402 with a comment in between.
4403 `--CR' comments out code on that line. Re-hitting CR comments
4404 out following lines.
4405 `C-c C-c' comments out a region if not commented out,
4406 uncomments a region if already commented out. Option
4407 `comment-style' defines where the comment characters
4408 should be placed (beginning of line, indent, etc.).
4410 You are prompted for comments after object definitions (i.e. signals,
4411 variables, constants, ports) and after subprogram and process
4412 specifications if option `vhdl-prompt-for-comments' is non-nil.
4413 Comments are automatically inserted as additional labels (e.g. after
4414 begin statements) and as help comments if `vhdl-self-insert-comments' is
4415 non-nil.
4417 Inline comments (i.e. comments after a piece of code on the same line)
4418 are indented at least to `vhdl-inline-comment-column'. Comments go at
4419 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4420 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4421 in a comment automatically opens a new comment line. `M-q' re-fills
4422 multi-line comments.
4425 INDENTATION:
4426 `TAB' indents a line if at the beginning of the line. The amount of
4427 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4428 always indents the current line (is bound to `TAB' if option
4429 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4430 the entire region.
4432 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4433 (`M-C-\\') or the entire buffer (menu). Argument and port lists are
4434 indented normally (nil) or relative to the opening parenthesis (non-nil)
4435 according to option `vhdl-argument-list-indent'.
4437 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4438 tabs. `\\[tabify]' and `\\[untabify]' allow the conversion of spaces to
4439 tabs and vice versa.
4441 Syntax-based indentation can be very slow in large files. Option
4442 `vhdl-indent-syntax-based' allows you to use faster but simpler indentation.
4444 Option `vhdl-indent-comment-like-next-code-line' controls whether
4445 comment lines are indented like the preceding or like the following code
4446 line.
4449 ALIGNMENT:
4450 The alignment functions align operators, keywords, and inline comments
4451 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4452 separated by blank lines, `C-c C-a C-i' a block of lines with same
4453 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4454 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4455 C-a C-d' all lines within the declarative part of a design unit. `C-c
4456 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4457 for a group of lines, and `C-c C-a M-c' for a region.
4459 If option `vhdl-align-groups' is non-nil, groups of code lines
4460 separated by special lines (see option `vhdl-align-group-separate') are
4461 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4462 blocks of lines with same indent are aligned separately. Some templates
4463 are automatically aligned after generation if option `vhdl-auto-align'
4464 is non-nil.
4466 Alignment tries to align inline comments at
4467 `vhdl-inline-comment-column' and tries inline comment not to exceed
4468 `vhdl-end-comment-column'.
4470 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4471 symbols are surrounded by one space, and multiple spaces are eliminated.
4474 CODE FILLING:
4475 Code filling allows you to condense code (e.g. sensitivity lists or port
4476 maps) by removing comments and newlines and re-wrapping so that all
4477 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4478 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4479 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4480 `C-c C-f M-f' an entire region.
4483 CODE BEAUTIFICATION:
4484 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4485 buffer respectively. This includes indentation, alignment, and case
4486 fixing. Code beautification can also be run non-interactively using the
4487 command:
4489 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4492 PORT TRANSLATION:
4493 Generic and port clauses from entity or component declarations can be
4494 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4495 as component instantiations and corresponding internal constants and
4496 signals, as a generic map with constants as actual generics, and as
4497 internal signal initializations (menu).
4499 To include formals in component instantiations, see option
4500 `vhdl-association-list-with-formals'. To include comments in pasting,
4501 see options `vhdl-include-...-comments'.
4503 A clause with several generic/port names on the same line can be
4504 flattened (`C-c C-p C-f') so that only one name per line exists. The
4505 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4506 outputs and vice versa, which can be useful in testbenches. (This
4507 reversion is done on the internal data structure and is only reflected
4508 in subsequent paste operations.)
4510 Names for actual ports, instances, testbenches, and
4511 design-under-test instances can be derived from existing names according
4512 to options `vhdl-...-name'. See customization group `vhdl-port'.
4515 SUBPROGRAM TRANSLATION:
4516 Similar functionality exists for copying/pasting the interface of
4517 subprograms (function/procedure). A subprogram interface can be copied
4518 and then pasted as a subprogram declaration, body or call (uses
4519 association list with formals).
4522 TESTBENCH GENERATION:
4523 A copied port can also be pasted as a testbench. The generated
4524 testbench includes an entity, an architecture, and an optional
4525 configuration. The architecture contains the component declaration and
4526 instantiation of the DUT as well as internal constant and signal
4527 declarations. Additional user-defined templates can be inserted. The
4528 names used for entity/architecture/configuration/DUT as well as the file
4529 structure to be generated can be customized. See customization group
4530 `vhdl-testbench'.
4533 KEY BINDINGS:
4534 Key bindings (`C-c ...') exist for most commands (see in menu).
4537 VHDL MENU:
4538 All commands can be found in the VHDL menu including their key bindings.
4541 FILE BROWSER:
4542 The speedbar allows browsing of directories and file contents. It can
4543 be accessed from the VHDL menu and is automatically opened if option
4544 `vhdl-speedbar-auto-open' is non-nil.
4546 In speedbar, open files and directories with `mouse-2' on the name and
4547 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4550 DESIGN HIERARCHY BROWSER:
4551 The speedbar can also be used for browsing the hierarchy of design units
4552 contained in the source files of the current directory or the specified
4553 projects (see option `vhdl-project-alist').
4555 The speedbar can be switched between file, directory hierarchy and
4556 project hierarchy browsing mode in the speedbar menu or by typing `f',
4557 `h' or `H' in speedbar.
4559 In speedbar, open design units with `mouse-2' on the name and browse
4560 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4561 from entities and components (in packages). Individual design units and
4562 complete designs can directly be compiled (\"Make\" menu entry).
4564 The hierarchy is automatically updated upon saving a modified source
4565 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4566 hierarchy is only updated for projects that have been opened once in the
4567 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4568 options in group `vhdl-speedbar').
4570 Simple design consistency checks are done during scanning, such as
4571 multiple declarations of the same unit or missing primary units that are
4572 required by secondary units.
4575 STRUCTURAL COMPOSITION:
4576 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4577 for a new component. Subcomponents (i.e. component declaration and
4578 instantiation) can be automatically placed from a previously read port
4579 (`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4580 all subcomponents can be automatically connected using internal signals
4581 and ports (`C-c C-m C-w') following these rules:
4582 - subcomponent actual ports with same name are considered to be
4583 connected by a signal (internal signal or port)
4584 - signals that are only inputs to subcomponents are considered as
4585 inputs to this component -> input port created
4586 - signals that are only outputs from subcomponents are considered as
4587 outputs from this component -> output port created
4588 - signals that are inputs to AND outputs from subcomponents are
4589 considered as internal connections -> internal signal created
4591 Purpose: With appropriate naming conventions it is possible to
4592 create higher design levels with only a few mouse clicks or key
4593 strokes. A new design level can be created by simply generating a new
4594 component, placing the required subcomponents from the hierarchy
4595 browser, and wiring everything automatically.
4597 Note: Automatic wiring only works reliably on templates of new
4598 components and component instantiations that were created by VHDL mode.
4600 Component declarations can be placed in a components package (option
4601 `vhdl-use-components-package') which can be automatically generated for
4602 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4603 component instantiation is also supported (option
4604 `vhdl-use-direct-instantiation').
4606 Configuration declarations can automatically be generated either from
4607 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4608 the speedbar menu (for the architecture under the cursor). The
4609 configurations can optionally be hierarchical (i.e. include all
4610 component levels of a hierarchical design, option
4611 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4612 (option `vhdl-compose-configuration-use-subconfiguration'). For
4613 subcomponents in hierarchical configurations, the most-recently-analyzed
4614 (mra) architecture is selected. If another architecture is desired, it
4615 can be marked as most-recently-analyzed (speedbar menu) before
4616 generating the configuration.
4618 Note: Configurations of subcomponents (i.e. hierarchical configuration
4619 declarations) are currently not considered when displaying
4620 configurations in speedbar.
4622 See the options group `vhdl-compose' for all relevant user options.
4625 SOURCE FILE COMPILATION:
4626 The syntax of the current buffer can be analyzed by calling a VHDL
4627 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4628 option `vhdl-compiler'. The available compilers are listed in option
4629 `vhdl-compiler-alist' including all required compilation command,
4630 command options, compilation directory, and error message syntax
4631 information. New compilers can be added.
4633 All the source files of an entire design can be compiled by the `make'
4634 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4637 MAKEFILE GENERATION:
4638 Makefiles can be generated automatically by an internal generation
4639 routine (`C-c M-k'). The library unit dependency information is
4640 obtained from the hierarchy browser. Makefile generation can be
4641 customized for each compiler in option `vhdl-compiler-alist'.
4643 Makefile generation can also be run non-interactively using the
4644 command:
4646 emacs -batch -l ~/.emacs -l vhdl-mode
4647 [-compiler compilername] [-project projectname]
4648 -f vhdl-generate-makefile
4650 The Makefile's default target \"all\" compiles the entire design, the
4651 target \"clean\" removes it and the target \"library\" creates the
4652 library directory if not existent. These target names can be customized
4653 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4654 target for each primary library unit which allows selective compilation
4655 of this unit, its secondary units and its subhierarchy (example:
4656 compilation of a design specified by a configuration). User specific
4657 parts can be inserted into a Makefile with option
4658 `vhdl-makefile-generation-hook'.
4660 Limitations:
4661 - Only library units and dependencies within the current library are
4662 considered. Makefiles for designs that span multiple libraries are
4663 not (yet) supported.
4664 - Only one-level configurations are supported (also hierarchical),
4665 but configurations that go down several levels are not.
4666 - The \"others\" keyword in configurations is not supported.
4669 PROJECTS:
4670 Projects can be defined in option `vhdl-project-alist' and a current
4671 project be selected using option `vhdl-project' (permanently) or from
4672 the menu or speedbar (temporarily). For each project, title and
4673 description strings (for the file headers), source files/directories
4674 (for the hierarchy browser and Makefile generation), library name, and
4675 compiler-dependent options, exceptions and compilation directory can be
4676 specified. Compilation settings overwrite the settings of option
4677 `vhdl-compiler-alist'.
4679 Project setups can be exported (i.e. written to a file) and imported.
4680 Imported setups are not automatically saved in `vhdl-project-alist' but
4681 can be saved afterwards in its customization buffer. When starting
4682 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4683 vhdl-mode\") in a directory with an existing project setup file, it is
4684 automatically loaded and its project activated if option
4685 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4686 files can be specified in option `vhdl-project-file-name'. Multiple
4687 project setups can be automatically loaded from global directories.
4688 This is an alternative to specifying project setups with option
4689 `vhdl-project-alist'.
4692 SPECIAL MENUES:
4693 As an alternative to the speedbar, an index menu can be added (set
4694 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4695 (e.g. add \"(global-set-key [S-down-mouse-3] \\='imenu)\" to your start-up
4696 file) for browsing the file contents (is not populated if buffer is
4697 larger than 256000). Also, a source file menu can be
4698 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4699 current directory for VHDL source files.
4702 VHDL STANDARDS:
4703 The VHDL standards to be used are specified in option `vhdl-standard'.
4704 Available standards are: VHDL'87/'93(02)/'08, VHDL-AMS, and Math Packages.
4707 KEYWORD CASE:
4708 Lower and upper case for keywords and standardized types, attributes,
4709 and enumeration values is supported. If the option
4710 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4711 lower case and are converted into upper case automatically (not for
4712 types, attributes, and enumeration values). The case of keywords,
4713 types, attributes,and enumeration values can be fixed for an entire
4714 region (menu) or buffer (`C-c C-x C-c') according to the options
4715 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4718 HIGHLIGHTING (fontification):
4719 Keywords and standardized types, attributes, enumeration values, and
4720 function names (controlled by option `vhdl-highlight-keywords'), as well
4721 as comments, strings, and template prompts are highlighted using
4722 different colors. Unit, subprogram, signal, variable, constant,
4723 parameter and generic/port names in declarations as well as labels are
4724 highlighted if option `vhdl-highlight-names' is non-nil.
4726 Additional reserved words or words with a forbidden syntax (e.g. words
4727 that should be avoided) can be specified in option
4728 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4729 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4730 keywords are highlighted as forbidden words if option
4731 `vhdl-highlight-verilog-keywords' is non-nil.
4733 Words with special syntax can be highlighted by specifying their
4734 syntax and color in option `vhdl-special-syntax-alist' and by setting
4735 option `vhdl-highlight-special-words' to non-nil. This allows you to
4736 establish some naming conventions (e.g. to distinguish different kinds
4737 of signals or other objects by using name suffices) and to support them
4738 visually.
4740 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4741 to support case-sensitive highlighting. However, keywords are then only
4742 highlighted if written in lower case.
4744 Code between \"translate_off\" and \"translate_on\" pragmas is
4745 highlighted using a different background color if option
4746 `vhdl-highlight-translate-off' is non-nil.
4748 For documentation and customization of the used colors see
4749 customization group `vhdl-highlight-faces' (`\\[customize-group]'). For
4750 highlighting of matching parenthesis, see customization group
4751 `paren-showing'. Automatic buffer highlighting is turned on/off by
4752 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4755 USER MODELS:
4756 VHDL models (templates) can be specified by the user and made accessible
4757 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4758 electrification. See option `vhdl-model-alist'.
4761 HIDE/SHOW:
4762 The code of blocks, processes, subprograms, component declarations and
4763 instantiations, generic/port clauses, and configuration declarations can
4764 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4765 the code (see customization group `vhdl-menu'). XEmacs: limited
4766 functionality due to old `hideshow.el' package.
4769 CODE UPDATING:
4770 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4771 current process, `C-c C-u M-s' of all processes in the current buffer.
4772 Limitations:
4773 - Only declared local signals (ports, signals declared in
4774 architecture and blocks) are automatically inserted.
4775 - Global signals declared in packages are not automatically inserted.
4776 Insert them once manually (will be kept afterwards).
4777 - Out parameters of procedures are considered to be read.
4778 Use option `vhdl-entity-file-name' to specify the entity file name
4779 (used to obtain the port names).
4780 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4781 specify whether to include array indices and record fields in
4782 sensitivity lists.
4785 CODE FIXING:
4786 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4787 (e.g., if the closing parenthesis is on the wrong line or is missing).
4790 PRINTING:
4791 PostScript printing with different faces (an optimized set of faces is
4792 used if `vhdl-print-customize-faces' is non-nil) or colors (if
4793 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4794 PostScript printing commands. Option `vhdl-print-two-column' defines
4795 appropriate default settings for nice landscape two-column printing.
4796 The paper format can be set by option `ps-paper-type'. Do not forget to
4797 switch `ps-print-color-p' to nil for printing on black-and-white
4798 printers.
4801 OPTIONS:
4802 User options allow customization of VHDL Mode. All options are
4803 accessible from the \"Options\" menu entry. Simple options (switches
4804 and choices) can directly be changed, while for complex options a
4805 customization buffer is opened. Changed options can be saved for future
4806 sessions using the \"Save Options\" menu entry.
4808 Options and their detailed descriptions can also be accessed by using
4809 the \"Customize\" menu entry or the command `\\[customize-option]'
4810 (`\\[customize-group]' for groups). Some customizations only take effect
4811 after some action (read the NOTE in the option documentation).
4812 Customization can also be done globally (i.e. site-wide, read the
4813 INSTALL file).
4815 Not all options are described in this documentation, so go and see
4816 what other useful user options there are (`\\[vhdl-customize]' or menu)!
4819 FILE EXTENSIONS:
4820 As default, files with extensions \".vhd\" and \".vhdl\" are
4821 automatically recognized as VHDL source files. To add an extension
4822 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4824 (push \\='(\"\\\\.xxx\\\\\\='\" . vhdl-mode) auto-mode-alist)
4827 HINTS:
4828 - To start Emacs with open VHDL hierarchy browser without having to load
4829 a VHDL file first, use the command:
4831 emacs -l vhdl-mode -f speedbar-frame-mode
4833 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4835 - Some features only work on properly indented code.
4838 RELEASE NOTES:
4839 See also the release notes (menu) for added features in new releases.
4842 Maintenance:
4843 ------------
4845 To submit a bug report, enter `\\[vhdl-submit-bug-report]' within VHDL Mode.
4846 Add a description of the problem and include a reproducible test case.
4848 Questions and enhancement requests can be sent to <reto@gnu.org>.
4850 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4851 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4852 releases. You are kindly invited to participate in beta testing. Subscribe
4853 to above mailing lists by sending an email to <reto@gnu.org>.
4855 VHDL Mode is officially distributed at
4856 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4857 where the latest version can be found.
4860 Known problems:
4861 ---------------
4863 - XEmacs: Incorrect start-up when automatically opening speedbar.
4864 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4865 - Indentation incorrect for new 'postponed' VHDL keyword.
4866 - Indentation incorrect for 'protected body' construct.
4869 The VHDL Mode Authors
4870 Reto Zimmermann and Rod Whitby
4872 Key bindings:
4873 -------------
4875 \\{vhdl-mode-map}"
4876 :abbrev-table vhdl-mode-abbrev-table
4878 ;; set local variables
4879 (set (make-local-variable 'paragraph-start)
4880 "\\s-*\\(--+\\s-*$\\|$\\)")
4881 (set (make-local-variable 'paragraph-separate) paragraph-start)
4882 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4883 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4884 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4885 (set (make-local-variable 'comment-start) "--")
4886 (set (make-local-variable 'comment-end) "")
4887 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4888 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4889 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4890 (set (make-local-variable 'comment-multi-line) nil)
4891 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4892 (set (make-local-variable 'hippie-expand-verbose) nil)
4894 ;; setup the comment indent variable in a Emacs version portable way
4895 ;; ignore any byte compiler warnings you might get here
4896 (when (boundp 'comment-indent-function)
4897 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4899 ;; initialize font locking
4900 (set (make-local-variable 'font-lock-defaults)
4901 (list
4902 '(nil vhdl-font-lock-keywords) nil
4903 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4904 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4905 (set (make-local-variable 'syntax-propertize-function)
4906 (syntax-propertize-rules
4907 ;; Mark single quotes as having string quote syntax in
4908 ;; 'c' instances.
4909 ("\\('\\).\\('\\)" (1 "\"'") (2 "\"'"))))
4910 (set (make-local-variable 'font-lock-syntactic-keywords)
4911 vhdl-font-lock-syntactic-keywords))
4912 (unless vhdl-emacs-21
4913 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4914 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4915 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4916 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4918 ;; variables for source file compilation
4919 (when vhdl-compile-use-local-error-regexp
4920 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4921 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4923 ;; add index menu
4924 (vhdl-index-menu-init)
4925 ;; add source file menu
4926 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4927 ;; add VHDL menu
4928 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4929 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4930 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4931 ;; initialize hideshow and add menu
4932 (vhdl-hideshow-init)
4933 (run-hooks 'menu-bar-update-hook)
4935 ;; miscellaneous
4936 (vhdl-ps-print-init)
4937 (vhdl-write-file-hooks-init)
4938 (message "VHDL Mode %s.%s" vhdl-version
4939 (if noninteractive "" " See menu for documentation and release notes.")))
4941 (defun vhdl-activate-customizations ()
4942 "Activate all customizations on local variables."
4943 (interactive)
4944 (vhdl-mode-map-init)
4945 (use-local-map vhdl-mode-map)
4946 (set-syntax-table vhdl-mode-syntax-table)
4947 (setq comment-column vhdl-inline-comment-column)
4948 (setq end-comment-column vhdl-end-comment-column)
4949 (vhdl-write-file-hooks-init)
4950 (vhdl-update-mode-menu)
4951 (vhdl-hideshow-init)
4952 (run-hooks 'menu-bar-update-hook))
4954 (defun vhdl-write-file-hooks-init ()
4955 "Add/remove hooks when buffer is saved."
4956 (if vhdl-modify-date-on-saving
4957 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4958 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4959 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4960 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4962 (defun vhdl-process-command-line-option (option)
4963 "Process command line options for VHDL Mode."
4964 (cond
4965 ;; set compiler
4966 ((equal option "-compiler")
4967 (vhdl-set-compiler (car command-line-args-left))
4968 (setq command-line-args-left (cdr command-line-args-left)))
4969 ;; set project
4970 ((equal option "-project")
4971 (vhdl-set-project (car command-line-args-left))
4972 (setq command-line-args-left (cdr command-line-args-left)))))
4974 ;; make Emacs process VHDL Mode options
4975 (setq command-switch-alist
4976 (append command-switch-alist
4977 '(("-compiler" . vhdl-process-command-line-option)
4978 ("-project" . vhdl-process-command-line-option))))
4981 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4982 ;;; Keywords and standardized words
4983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4985 (defconst vhdl-02-keywords
4987 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4988 "assert" "attribute"
4989 "begin" "block" "body" "buffer" "bus"
4990 "case" "component" "configuration" "constant"
4991 "disconnect" "downto"
4992 "else" "elsif" "end" "entity" "exit"
4993 "file" "for" "function"
4994 "generate" "generic" "group" "guarded"
4995 "if" "impure" "in" "inertial" "inout" "is"
4996 "label" "library" "linkage" "literal" "loop"
4997 "map" "mod"
4998 "nand" "new" "next" "nor" "not" "null"
4999 "of" "on" "open" "or" "others" "out"
5000 "package" "port" "postponed" "procedure" "process" "protected" "pure"
5001 "range" "record" "register" "reject" "rem" "report" "return"
5002 "rol" "ror"
5003 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
5004 "then" "to" "transport" "type"
5005 "unaffected" "units" "until" "use"
5006 "variable"
5007 "wait" "when" "while" "with"
5008 "xnor" "xor"
5010 "List of VHDL'02 keywords.")
5012 (defconst vhdl-08-keywords
5014 "context" "force" "property" "release" "sequence"
5016 "List of VHDL'08 keywords.")
5018 (defconst vhdl-ams-keywords
5020 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
5021 "reference" "spectrum" "subnature" "terminal" "through"
5022 "tolerance"
5024 "List of VHDL-AMS keywords.")
5026 (defconst vhdl-verilog-keywords
5028 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
5029 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
5030 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
5031 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
5032 "endprimitive" "endspecify" "endtable" "endtask" "event"
5033 "for" "force" "forever" "fork" "function"
5034 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
5035 "macromodule" "makefile" "medium" "module"
5036 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
5037 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
5038 "pullup"
5039 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
5040 "rtranif0" "rtranif1"
5041 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
5042 "strong1" "supply" "supply0" "supply1"
5043 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5044 "triand" "trior" "trireg"
5045 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
5047 "List of Verilog keywords as candidate for additional reserved words.")
5049 (defconst vhdl-02-types
5051 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
5052 "real" "time" "natural" "positive" "string" "line" "text" "side"
5053 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
5054 "std_logic" "std_logic_vector"
5055 "std_ulogic" "std_ulogic_vector"
5057 "List of VHDL'02 standardized types.")
5059 (defconst vhdl-08-types
5061 "boolean_vector" "integer_vector" "real_vector" "time_vector"
5063 "List of VHDL'08 standardized types.")
5065 (defconst vhdl-ams-types
5066 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5068 ;; package `standard'
5069 "domain_type" "real_vector"
5070 ;; package `energy_systems'
5071 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5072 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5073 "real_across_vector" "real_through_vector"
5074 ;; package `electrical_systems'
5075 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5076 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5077 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5078 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5079 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5080 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5081 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5082 "electric_flux_density_vector" "electric_field_strength_vector"
5083 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5084 "inductance_vector" "reluctance_vector" "ground"
5085 ;; package `mechanical_systems'
5086 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5087 "damping" "momentum" "angle" "torque" "angular_velocity"
5088 "angular_acceleration" "moment_inertia" "angular_momentum"
5089 "angular_stiffness" "angular_damping" "translational"
5090 "translational_vector" "translational_velocity"
5091 "translational_velocity_vector" "rotational" "rotational_vector"
5092 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5093 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5094 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5095 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5096 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5097 "angular_momentum_vector" "angular_stiffness_vector"
5098 "angular_damping_vector" "anchor" "translational_v_ref"
5099 "rotational_v_ref" "translational_v" "rotational_v"
5100 ;; package `radiant_systems'
5101 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5102 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5103 "illuminance_vector" "irradiance_vector"
5104 ;; package `thermal_systems'
5105 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5106 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5107 "heat_flow_vector" "thermal_capacitance_vector"
5108 "thermal_resistance_vector" "thermal_conductance_vector"
5109 ;; package `fluidic_systems'
5110 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5111 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5112 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5113 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5114 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5115 "density_vector" "viscosity_vector" "fresistance_vector"
5116 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5117 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5118 "cfinertance_vector"
5120 "List of VHDL-AMS standardized types.")
5122 (defconst vhdl-math-types
5124 "complex" "complex_polar" "positive_real" "principal_value"
5126 "List of Math Packages standardized types.")
5128 (defconst vhdl-02-attributes
5130 "base" "left" "right" "high" "low" "pos" "val" "succ"
5131 "pred" "leftof" "rightof" "range" "reverse_range"
5132 "length" "delayed" "stable" "quiet" "transaction"
5133 "event" "active" "last_event" "last_active" "last_value"
5134 "driving" "driving_value" "ascending" "value" "image"
5135 "simple_name" "instance_name" "path_name"
5136 "foreign"
5138 "List of VHDL'02 standardized attributes.")
5140 (defconst vhdl-08-attributes
5142 "instance_name" "path_name"
5144 "List of VHDL'08 standardized attributes.")
5146 (defconst vhdl-ams-attributes
5148 "across" "through"
5149 "reference" "contribution" "tolerance"
5150 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5151 "ramp" "slew"
5153 "List of VHDL-AMS standardized attributes.")
5155 (defconst vhdl-02-enum-values
5157 "true" "false"
5158 "note" "warning" "error" "failure"
5159 "read_mode" "write_mode" "append_mode"
5160 "open_ok" "status_error" "name_error" "mode_error"
5161 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5162 "right" "left"
5164 "List of VHDL'02 standardized enumeration values.")
5166 (defconst vhdl-ams-enum-values
5168 "quiescent_domain" "time_domain" "frequency_domain"
5169 ;; from `nature_pkg' package
5170 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5172 "List of VHDL-AMS standardized enumeration values.")
5174 (defconst vhdl-ams-constants
5175 ;; standard: IEEE Std 1076.1.1-2004
5177 ;; package `fundamental_constants'
5178 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5179 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5180 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5181 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5182 ;; package `material_constants'
5183 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5184 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5185 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5187 "List of VHDL-AMS standardized constants.")
5189 (defconst vhdl-math-constants
5190 ;; standard: IEEE Std 1076.2-1996
5192 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5193 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5194 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5195 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5196 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5197 "math_sqrt_pi"
5199 "List of Math Packages standardized constants.")
5201 (defconst vhdl-02-functions
5203 "now" "resolved" "rising_edge" "falling_edge"
5204 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5205 "endfile"
5206 "resize" "is_X" "std_match"
5207 "shift_left" "shift_right" "rotate_left" "rotate_right"
5208 "to_unsigned" "to_signed" "to_integer"
5209 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5210 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5211 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5212 "shl" "shr" "ext" "sxt"
5213 "deallocate"
5215 "List of VHDL'02 standardized functions.")
5217 (defconst vhdl-08-functions
5219 "finish" "flush" "justify" "maximum" "minimum"
5220 "resolution_limit" "rising_edge" "stop" "swrite"
5221 "tee" "to_binarystring" "to_bstring" "to_hexstring" "to_hstring"
5222 "to_octalstring" "to_ostring" "to_string"
5224 "List of VHDL'08 standardized functions.")
5226 (defconst vhdl-ams-functions
5228 ;; package `standard'
5229 "frequency"
5231 "List of VHDL-AMS standardized functions.")
5233 (defconst vhdl-math-functions
5234 ;; standard: IEEE Std 1076.2-1996
5236 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5237 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5238 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5239 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5240 "tan" "tanh" "trunc" "uniform"
5242 "List of Math Packages standardized functions.")
5244 (defconst vhdl-02-packages
5246 "std_logic_1164" "numeric_std" "numeric_bit"
5247 "standard" "textio"
5248 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5249 "std_logic_misc" "std_logic_textio"
5250 "ieee" "std" "work"
5252 "List of VHDL'02 standardized packages and libraries.")
5254 (defconst vhdl-08-packages
5256 "env" "numeric_std_signed" "numeric_std_unsigned"
5257 "ieee_bit_context" "ieee_std_context" ;; contexts
5259 "List of VHDL'08 standardized packages and libraries.")
5261 (defconst vhdl-ams-packages
5263 "fundamental_constants" "material_constants" "energy_systems"
5264 "electrical_systems" "mechanical_systems" "radiant_systems"
5265 "thermal_systems" "fluidic_systems"
5267 "List of VHDL-AMS standardized packages and libraries.")
5269 (defconst vhdl-math-packages
5271 "math_real" "math_complex"
5273 "List of Math Packages standardized packages and libraries.")
5275 (defconst vhdl-08-directives
5277 "author" "author_info" "begin" "begin_protected" "comment"
5278 "data_block" "data_keyname" "data_keyowner" "data_method"
5279 "decrypt_license" "digest_block" "digest_key_method" "digest_keyname"
5280 "digest_keyowner" "digest_method"
5281 "encoding" "encrypt_agent" "encrypt_agent_info" "end" "end_protected"
5282 "key_block" "key_keyname" "key_keyowner" "key_method"
5283 "runtime_license" "viewport"
5285 "List of VHDL'08 standardized tool directives.")
5287 (defvar vhdl-keywords nil
5288 "List of VHDL keywords.")
5290 (defvar vhdl-types nil
5291 "List of VHDL standardized types.")
5293 (defvar vhdl-attributes nil
5294 "List of VHDL standardized attributes.")
5296 (defvar vhdl-enum-values nil
5297 "List of VHDL standardized enumeration values.")
5299 (defvar vhdl-constants nil
5300 "List of VHDL standardized constants.")
5302 (defvar vhdl-functions nil
5303 "List of VHDL standardized functions.")
5305 (defvar vhdl-packages nil
5306 "List of VHDL standardized packages and libraries.")
5308 (defvar vhdl-directives nil
5309 "List of VHDL standardized packages and libraries.")
5311 (defvar vhdl-reserved-words nil
5312 "List of additional reserved words.")
5314 (defvar vhdl-keywords-regexp nil
5315 "Regexp for VHDL keywords.")
5317 (defvar vhdl-types-regexp nil
5318 "Regexp for VHDL standardized types.")
5320 (defvar vhdl-attributes-regexp nil
5321 "Regexp for VHDL standardized attributes.")
5323 (defvar vhdl-enum-values-regexp nil
5324 "Regexp for VHDL standardized enumeration values.")
5326 (defvar vhdl-constants-regexp nil
5327 "Regexp for VHDL standardized constants.")
5329 (defvar vhdl-functions-regexp nil
5330 "Regexp for VHDL standardized functions.")
5332 (defvar vhdl-packages-regexp nil
5333 "Regexp for VHDL standardized packages and libraries.")
5335 (defvar vhdl-reserved-words-regexp nil
5336 "Regexp for additional reserved words.")
5338 (defvar vhdl-directive-keywords-regexp nil
5339 "Regexp for compiler directive keywords.")
5341 (defun vhdl-upcase-list (condition list)
5342 "Upcase all elements in LIST based on CONDITION."
5343 (when condition
5344 (let ((tmp-list list))
5345 (while tmp-list
5346 (setcar tmp-list (upcase (car tmp-list)))
5347 (setq tmp-list (cdr tmp-list)))))
5348 list)
5350 (defun vhdl-words-init ()
5351 "Initialize reserved words."
5352 (setq vhdl-keywords
5353 (vhdl-upcase-list
5354 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5355 (append vhdl-02-keywords
5356 (when (vhdl-standard-p '08) vhdl-08-keywords)
5357 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5358 (setq vhdl-types
5359 (vhdl-upcase-list
5360 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5361 (append vhdl-02-types
5362 (when (vhdl-standard-p '08) vhdl-08-types)
5363 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5364 (when (vhdl-standard-p 'math) vhdl-math-types))))
5365 (setq vhdl-attributes
5366 (vhdl-upcase-list
5367 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5368 (append vhdl-02-attributes
5369 (when (vhdl-standard-p '08) vhdl-08-attributes)
5370 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5371 (setq vhdl-enum-values
5372 (vhdl-upcase-list
5373 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5374 (append vhdl-02-enum-values
5375 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5376 (setq vhdl-constants
5377 (vhdl-upcase-list
5378 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5379 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5380 (when (vhdl-standard-p 'math) vhdl-math-constants)
5381 '(""))))
5382 (setq vhdl-functions
5383 (append vhdl-02-functions
5384 (when (vhdl-standard-p '08) vhdl-08-functions)
5385 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5386 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5387 (setq vhdl-packages
5388 (append vhdl-02-packages
5389 (when (vhdl-standard-p '08) vhdl-08-packages)
5390 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5391 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5392 (setq vhdl-directives
5393 (append (when (vhdl-standard-p '08) vhdl-08-directives)))
5394 (setq vhdl-reserved-words
5395 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5396 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5397 '("")))
5398 (setq vhdl-keywords-regexp
5399 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5400 (setq vhdl-types-regexp
5401 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5402 (setq vhdl-attributes-regexp
5403 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5404 (setq vhdl-enum-values-regexp
5405 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5406 (setq vhdl-constants-regexp
5407 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5408 (setq vhdl-functions-regexp
5409 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5410 (setq vhdl-packages-regexp
5411 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5412 (setq vhdl-reserved-words-regexp
5413 (concat "\\<\\("
5414 (unless (equal vhdl-forbidden-syntax "")
5415 (concat vhdl-forbidden-syntax "\\|"))
5416 (regexp-opt vhdl-reserved-words)
5417 "\\)\\>"))
5418 (setq vhdl-directive-keywords-regexp
5419 (concat "\\<\\(" (mapconcat 'regexp-quote
5420 vhdl-directive-keywords "\\|") "\\)\\>"))
5421 (vhdl-abbrev-list-init))
5423 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5424 ;; Words to expand
5426 (defvar vhdl-abbrev-list nil
5427 "Predefined abbreviations for VHDL.")
5429 (defun vhdl-abbrev-list-init ()
5430 (setq vhdl-abbrev-list
5431 (append
5432 (list vhdl-upper-case-keywords) vhdl-keywords
5433 (list vhdl-upper-case-types) vhdl-types
5434 (list vhdl-upper-case-attributes) vhdl-attributes
5435 (list vhdl-upper-case-enum-values) vhdl-enum-values
5436 (list vhdl-upper-case-constants) vhdl-constants
5437 (list nil) vhdl-functions
5438 (list nil) vhdl-packages
5439 (list nil) vhdl-directives)))
5441 ;; initialize reserved words for VHDL Mode
5442 (vhdl-words-init)
5445 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5446 ;;; Indentation
5447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5450 ;; Syntax analysis
5452 ;; constant regular expressions for looking at various constructs
5454 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5455 "Regexp describing a VHDL symbol.
5456 We cannot use just `word' syntax class since `_' cannot be in word
5457 class. Putting underscore in word class breaks forward word movement
5458 behavior that users are familiar with.")
5460 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5461 "Regexp describing a case statement header key.")
5463 (defconst vhdl-label-key
5464 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5465 "Regexp describing a VHDL label.")
5467 ;; Macro definitions:
5469 (defmacro vhdl-point (position)
5470 "Return the value of point at certain commonly referenced POSITIONs.
5471 POSITION can be one of the following symbols:
5473 bol -- beginning of line
5474 eol -- end of line
5475 bod -- beginning of defun
5476 boi -- back to indentation
5477 eoi -- last whitespace on line
5478 ionl -- indentation of next line
5479 iopl -- indentation of previous line
5480 bonl -- beginning of next line
5481 bopl -- beginning of previous line
5483 This function does not modify point or mark."
5484 (or (and (eq 'quote (car-safe position))
5485 (null (cddr position)))
5486 (error "ERROR: Bad buffer position requested: %s" position))
5487 (setq position (nth 1 position))
5488 `(let ((here (point)))
5489 ,@(cond
5490 ((eq position 'bol) '((beginning-of-line)))
5491 ((eq position 'eol) '((end-of-line)))
5492 ((eq position 'bod) '((save-match-data
5493 (vhdl-beginning-of-defun))))
5494 ((eq position 'boi) '((back-to-indentation)))
5495 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5496 ((eq position 'bonl) '((forward-line 1)))
5497 ((eq position 'bopl) '((forward-line -1)))
5498 ((eq position 'iopl)
5499 '((forward-line -1)
5500 (back-to-indentation)))
5501 ((eq position 'ionl)
5502 '((forward-line 1)
5503 (back-to-indentation)))
5504 (t (error "ERROR: Unknown buffer position requested: %s" position))
5506 (prog1
5507 (point)
5508 (goto-char here))
5509 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5510 ;; doesn't hurt for v19
5511 ,@nil
5514 (defmacro vhdl-safe (&rest body)
5515 "Safely execute BODY, return nil if an error occurred."
5516 `(condition-case nil
5517 (progn ,@body)
5518 (error nil)))
5520 (defmacro vhdl-add-syntax (symbol &optional relpos)
5521 "A simple macro to append the syntax in SYMBOL to the syntax list.
5522 Try to increase performance by using this macro."
5523 `(setq vhdl-syntactic-context
5524 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5526 (defmacro vhdl-has-syntax (symbol)
5527 "A simple macro to return check the syntax list.
5528 Try to increase performance by using this macro."
5529 `(assoc ,symbol vhdl-syntactic-context))
5531 ;; Syntactic element offset manipulation:
5533 (defun vhdl-read-offset (langelem)
5534 "Read new offset value for LANGELEM from minibuffer.
5535 Return a valid value only."
5536 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5537 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5538 (prompt "Offset: ")
5539 offset input interned)
5540 (while (not offset)
5541 (setq input (read-string prompt oldoff)
5542 offset (cond ((string-equal "+" input) '+)
5543 ((string-equal "-" input) '-)
5544 ((string-equal "++" input) '++)
5545 ((string-equal "--" input) '--)
5546 ((string-match "^-?[0-9]+$" input)
5547 (string-to-number input))
5548 ((fboundp (setq interned (intern input)))
5549 interned)
5550 ((boundp interned) interned)
5551 ;; error, but don't signal one, keep trying
5552 ;; to read an input value
5553 (t (ding)
5554 (setq prompt errmsg)
5555 nil))))
5556 offset))
5558 (defun vhdl-set-offset (symbol offset &optional add-p)
5559 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5560 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5561 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5562 `vhdl-offsets-alist' if it doesn't already appear there."
5563 (interactive
5564 (let* ((langelem
5565 (intern (completing-read
5566 (concat "Syntactic symbol to change"
5567 (if current-prefix-arg " or add" "")
5568 ": ")
5569 (mapcar
5570 (function
5571 (lambda (langelem)
5572 (cons (format "%s" (car langelem)) nil)))
5573 vhdl-offsets-alist)
5574 nil (not current-prefix-arg)
5575 ;; initial contents tries to be the last element
5576 ;; on the syntactic analysis list for the current
5577 ;; line
5578 (let* ((syntax (vhdl-get-syntactic-context))
5579 (len (length syntax))
5580 (ic (format "%s" (car (nth (1- len) syntax)))))
5583 (offset (vhdl-read-offset langelem)))
5584 (list langelem offset current-prefix-arg)))
5585 ;; sanity check offset
5586 (or (eq offset '+)
5587 (eq offset '-)
5588 (eq offset '++)
5589 (eq offset '--)
5590 (integerp offset)
5591 (fboundp offset)
5592 (boundp offset)
5593 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5594 offset))
5595 (let ((entry (assq symbol vhdl-offsets-alist)))
5596 (if entry
5597 (setcdr entry offset)
5598 (if add-p
5599 (setq vhdl-offsets-alist
5600 (cons (cons symbol offset) vhdl-offsets-alist))
5601 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5602 (vhdl-keep-region-active))
5604 (defun vhdl-set-style (style &optional local)
5605 "Set `vhdl-mode' variables to use one of several different indentation styles.
5606 STYLE is a string representing the desired style and optional LOCAL is
5607 a flag which, if non-nil, means to make the style variables being
5608 changed buffer local, instead of the default, which is to set the
5609 global variables. Interactively, the flag comes from the prefix
5610 argument. The styles are chosen from the `vhdl-style-alist' variable."
5611 (interactive (list (completing-read "Use which VHDL indentation style? "
5612 vhdl-style-alist nil t)
5613 current-prefix-arg))
5614 (let ((vars (cdr (assoc style vhdl-style-alist))))
5615 (or vars
5616 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5617 ;; set all the variables
5618 (mapc
5619 (function
5620 (lambda (varentry)
5621 (let ((var (car varentry))
5622 (val (cdr varentry)))
5623 ;; special case for vhdl-offsets-alist
5624 (if (not (eq var 'vhdl-offsets-alist))
5625 (set (if local (make-local-variable var) var) val)
5626 ;; reset vhdl-offsets-alist to the default value first
5627 (set (if local (make-local-variable var) var)
5628 (copy-alist vhdl-offsets-alist-default))
5629 ;; now set the langelems that are different
5630 (mapcar
5631 (function
5632 (lambda (langentry)
5633 (let ((langelem (car langentry))
5634 (offset (cdr langentry)))
5635 (vhdl-set-offset langelem offset)
5637 val))
5639 vars))
5640 (vhdl-keep-region-active))
5642 (defun vhdl-get-offset (langelem)
5643 "Get offset from LANGELEM which is a cons cell of the form:
5644 \(SYMBOL . RELPOS). The symbol is matched against
5645 vhdl-offsets-alist and the offset found there is either returned,
5646 or added to the indentation at RELPOS. If RELPOS is nil, then
5647 the offset is simply returned."
5648 (let* ((symbol (car langelem))
5649 (relpos (cdr langelem))
5650 (match (assq symbol vhdl-offsets-alist))
5651 (offset (cdr-safe match)))
5652 ;; offset can be a number, a function, a variable, or one of the
5653 ;; symbols + or -
5654 (cond
5655 ((not match)
5656 (if vhdl-strict-syntax-p
5657 (error "ERROR: Don't know how to indent a %s" symbol)
5658 (setq offset 0
5659 relpos 0)))
5660 ((eq offset '+) (setq offset vhdl-basic-offset))
5661 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5662 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5663 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5664 ((and (not (numberp offset))
5665 (fboundp offset))
5666 (setq offset (funcall offset langelem)))
5667 ((not (numberp offset))
5668 (setq offset (eval offset)))
5670 (+ (if (and relpos
5671 (< relpos (vhdl-point 'bol)))
5672 (save-excursion
5673 (goto-char relpos)
5674 (current-column))
5676 offset)))
5678 ;; Syntactic support functions:
5680 (defun vhdl-in-comment-p (&optional pos)
5681 "Check if point is in a comment (include multi-line comments)."
5682 (let ((parse (lambda (p)
5683 (let ((c (char-after p)))
5684 (or (and c (eq (char-syntax c) ?<))
5685 (nth 4 (parse-partial-sexp
5686 (save-excursion
5687 (beginning-of-defun)
5688 (point)) p)))))))
5689 (save-excursion
5690 (goto-char (or pos (point)))
5691 (or (funcall parse (point))
5692 ;; `parse-partial-sexp's notion of comments doesn't span lines
5693 (progn
5694 (back-to-indentation)
5695 (unless (eolp)
5696 (forward-char)
5697 (funcall parse (point))))))))
5699 (defun vhdl-in-string-p ()
5700 "Check if point is in a string."
5701 (eq (vhdl-in-literal) 'string))
5703 (defun vhdl-in-quote-p ()
5704 "Check if point is in a quote ('x')."
5705 (or (and (> (point) (point-min))
5706 (< (1+ (point)) (point-max))
5707 (= (char-before (point)) ?\')
5708 (= (char-after (1+ (point))) ?\'))
5709 (and (> (1- (point)) (point-min))
5710 (< (point) (point-max))
5711 (= (char-before (1- (point))) ?\')
5712 (= (char-after (point)) ?\'))))
5714 (defun vhdl-in-literal ()
5715 "Determine if point is in a VHDL literal."
5716 (save-excursion
5717 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5718 (cond
5719 ((nth 3 state) 'string)
5720 ((nth 4 state) 'comment)
5721 ((vhdl-beginning-of-macro) 'pound)
5722 ((vhdl-beginning-of-directive) 'directive)
5723 ;; for multi-line comments
5724 ((and (vhdl-standard-p '08) (vhdl-in-comment-p)) 'comment)
5725 (t nil)))))
5727 (defun vhdl-in-extended-identifier-p ()
5728 "Determine if point is inside extended identifier (delimited by `\\')."
5729 (save-match-data
5730 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5731 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5733 (defun vhdl-forward-comment (&optional direction)
5734 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5735 negative, skip forward otherwise."
5736 (interactive "p")
5737 (if (and direction (< direction 0))
5738 ;; skip backwards
5739 (progn
5740 (skip-chars-backward " \t\n\r\f")
5741 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5742 (goto-char (match-beginning 3))
5743 (skip-chars-backward " \t\n\r\f")))
5744 ;; skip forwards
5745 (skip-chars-forward " \t\n\r\f")
5746 (while (looking-at "--.*")
5747 (goto-char (match-end 0))
5748 (skip-chars-forward " \t\n\r\f"))))
5750 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5751 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5752 (defalias 'vhdl-forward-comment 'forward-comment))
5754 (defun vhdl-back-to-indentation ()
5755 "Move point to the first non-whitespace character on this line."
5756 (interactive)
5757 (beginning-of-line 1)
5758 (skip-syntax-forward " " (vhdl-point 'eol)))
5760 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5761 (when (featurep 'xemacs)
5762 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5764 ;; This is the best we can do in Win-Emacs.
5765 (defun vhdl-win-il (&optional lim)
5766 "Determine if point is in a VHDL literal."
5767 (save-excursion
5768 (let* ((here (point))
5769 (state nil)
5770 (match nil)
5771 (lim (or lim (vhdl-point 'bod))))
5772 (goto-char lim )
5773 (while (< (point) here)
5774 (setq match
5775 (and (re-search-forward "--\\|[\"']\\|`"
5776 here 'move)
5777 (buffer-substring (match-beginning 0) (match-end 0))))
5778 (setq state
5779 (cond
5780 ;; no match
5781 ((null match) nil)
5782 ;; looking at the opening of a VHDL style comment
5783 ((string= "--" match)
5784 (if (<= here (progn (end-of-line) (point))) 'comment))
5785 ;; looking at a directive
5786 ((string= "`" match)
5787 (if (<= here (progn (end-of-line) (point))) 'directive))
5788 ;; looking at the opening of a double quote string
5789 ((string= "\"" match)
5790 (if (not (save-restriction
5791 ;; this seems to be necessary since the
5792 ;; re-search-forward will not work without it
5793 (narrow-to-region (point) here)
5794 (re-search-forward
5795 ;; this regexp matches a double quote
5796 ;; which is preceded by an even number
5797 ;; of backslashes, including zero
5798 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5799 'string))
5800 ;; looking at the opening of a single quote string
5801 ((string= "'" match)
5802 (if (not (save-restriction
5803 ;; see comments from above
5804 (narrow-to-region (point) here)
5805 (re-search-forward
5806 ;; this matches a single quote which is
5807 ;; preceded by zero or two backslashes.
5808 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5809 here 'move)))
5810 'string))
5811 (t nil)))
5812 ) ; end-while
5813 state)))
5815 (and (string-match "Win-Emacs" emacs-version)
5816 (fset 'vhdl-in-literal 'vhdl-win-il))
5818 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5819 ;; defined as lexical whitespace or comments. Search no farther back
5820 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5821 ;; used for backward skipping, (point-max) is used for forward
5822 ;; skipping.
5824 (defun vhdl-forward-syntactic-ws (&optional lim)
5825 "Forward skip of syntactic whitespace."
5826 (let* ((here (point-max))
5827 (hugenum (point-max)))
5828 (while (/= here (point))
5829 (setq here (point))
5830 (vhdl-forward-comment hugenum)
5831 ;; skip preprocessor directives
5832 (when (and (or (eq (char-after) ?#) (eq (char-after) ?`))
5833 (= (vhdl-point 'boi) (point)))
5834 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5835 (= (forward-line 1) 0)))
5836 (end-of-line)))
5837 (if lim (goto-char (min (point) lim)))))
5840 ;; This is the best we can do in Win-Emacs.
5841 (defun vhdl-win-fsws (&optional lim)
5842 "Forward skip syntactic whitespace for Win-Emacs."
5843 (let ((lim (or lim (point-max)))
5844 stop)
5845 (while (not stop)
5846 (skip-chars-forward " \t\n\r\f" lim)
5847 (cond
5848 ;; vhdl comment
5849 ((looking-at "--") (end-of-line))
5850 ;; none of the above
5851 (t (setq stop t))))))
5853 (and (string-match "Win-Emacs" emacs-version)
5854 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5856 (defun vhdl-beginning-of-macro (&optional lim)
5857 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5858 (let ((here (point)))
5859 (beginning-of-line)
5860 (while (eq (char-before (1- (point))) ?\\)
5861 (forward-line -1))
5862 (back-to-indentation)
5863 (if (and (<= (point) here)
5864 (eq (char-after) ?#))
5866 (goto-char here)
5867 nil)))
5869 (defun vhdl-beginning-of-directive (&optional lim)
5870 "Go to the beginning of a directive (nicked from `cc-engine')."
5871 (let ((here (point)))
5872 (beginning-of-line)
5873 (while (eq (char-before (1- (point))) ?\\)
5874 (forward-line -1))
5875 (back-to-indentation)
5876 (if (and (<= (point) here)
5877 (eq (char-after) ?`))
5879 (goto-char here)
5880 nil)))
5882 (defun vhdl-backward-syntactic-ws (&optional lim)
5883 "Backward skip over syntactic whitespace."
5884 (let* ((here (point-min))
5885 (hugenum (- (point-max))))
5886 (while (/= here (point))
5887 (setq here (point))
5888 (vhdl-forward-comment hugenum)
5889 (vhdl-beginning-of-macro))
5890 (if lim (goto-char (max (point) lim)))))
5892 ;; This is the best we can do in Win-Emacs.
5893 (defun vhdl-win-bsws (&optional lim)
5894 "Backward skip syntactic whitespace for Win-Emacs."
5895 (let ((lim (or lim (vhdl-point 'bod)))
5896 stop)
5897 (while (not stop)
5898 (skip-chars-backward " \t\n\r\f" lim)
5899 (cond
5900 ;; vhdl comment
5901 ((eq (vhdl-in-literal) 'comment)
5902 (skip-chars-backward "^-" lim)
5903 (skip-chars-backward "-" lim)
5904 (while (not (or (and (= (following-char) ?-)
5905 (= (char-after (1+ (point))) ?-))
5906 (<= (point) lim)))
5907 (skip-chars-backward "^-" lim)
5908 (skip-chars-backward "-" lim)))
5909 ;; none of the above
5910 (t (setq stop t))))))
5912 (and (string-match "Win-Emacs" emacs-version)
5913 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5915 ;; Functions to help finding the correct indentation column:
5917 (defun vhdl-first-word (point)
5918 "If the keyword at POINT is at boi, then return (current-column) at
5919 that point, else nil."
5920 (save-excursion
5921 (and (goto-char point)
5922 (eq (point) (vhdl-point 'boi))
5923 (current-column))))
5925 (defun vhdl-last-word (point)
5926 "If the keyword at POINT is at eoi, then return (current-column) at
5927 that point, else nil."
5928 (save-excursion
5929 (and (goto-char point)
5930 (save-excursion (or (eq (progn (forward-sexp) (point))
5931 (vhdl-point 'eoi))
5932 (looking-at "\\s-*\\(--\\)?")))
5933 (current-column))))
5935 ;; Core syntactic evaluation functions:
5937 (defconst vhdl-libunit-re
5938 "\\b\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\b[^_]")
5940 (defun vhdl-libunit-p ()
5941 (and
5942 (save-excursion
5943 (forward-sexp)
5944 (skip-chars-forward " \t\n\r\f")
5945 (not (looking-at "is\\b[^_]")))
5946 (save-excursion
5947 (backward-sexp)
5948 (and (not (looking-at "use\\b[^_]"))
5949 (progn
5950 (forward-sexp)
5951 (vhdl-forward-syntactic-ws)
5952 (/= (following-char) ?:))))
5955 (defconst vhdl-defun-re
5956 "\\b\\(architecture\\|block\\|configuration\\|context\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5958 (defun vhdl-defun-p ()
5959 (save-excursion
5960 (if (looking-at "block\\|process\\|procedural")
5961 ;; "block", "process", "procedural":
5962 (save-excursion
5963 (backward-sexp)
5964 (not (looking-at "end\\s-+\\w")))
5965 ;; "architecture", "configuration", "context", "entity",
5966 ;; "package", "procedure", "function":
5967 t)))
5969 (defun vhdl-corresponding-defun ()
5970 "If the word at the current position corresponds to a \"defun\"
5971 keyword, then return a string that can be used to find the
5972 corresponding \"begin\" keyword, else return nil."
5973 (save-excursion
5974 (and (looking-at vhdl-defun-re)
5975 (vhdl-defun-p)
5976 (if (looking-at "block\\|process\\|procedural")
5977 ;; "block", "process". "procedural:
5978 (buffer-substring (match-beginning 0) (match-end 0))
5979 ;; "architecture", "configuration", "context", "entity", "package",
5980 ;; "procedure", "function":
5981 "is"))))
5983 (defconst vhdl-begin-fwd-re
5984 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5985 "A regular expression for searching forward that matches all known
5986 \"begin\" keywords.")
5988 (defconst vhdl-begin-bwd-re
5989 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5990 "A regular expression for searching backward that matches all known
5991 \"begin\" keywords.")
5993 (defun vhdl-begin-p (&optional lim)
5994 "Return t if we are looking at a real \"begin\" keyword.
5995 Assumes that the caller will make sure that we are looking at
5996 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5997 the middle of an identifier that just happens to contain a \"begin\"
5998 keyword."
5999 (cond
6000 ;; "[architecture|case|configuration|context|entity|package|
6001 ;; procedure|function] ... is":
6002 ((and (looking-at "i")
6003 (save-excursion
6004 ;; Skip backward over first sexp (needed to skip over a
6005 ;; procedure interface list, and is harmless in other
6006 ;; situations). Note that we need "return" in the
6007 ;; following search list so that we don't run into
6008 ;; semicolons in the function interface list.
6009 (backward-sexp)
6010 (skip-chars-forward "(")
6011 (let (foundp)
6012 (while (and (not foundp)
6013 (re-search-backward
6014 ";\\|\\b\\(architecture\\|case\\|configuration\\|context\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
6015 lim 'move))
6016 (if (or (= (preceding-char) ?_)
6017 (vhdl-in-literal))
6018 (backward-char)
6019 (setq foundp t))))
6020 (and (/= (following-char) ?\;)
6021 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
6023 ;; "begin", "then", "use":
6024 ((looking-at "be\\|t\\|use")
6026 ;; "else":
6027 ((and (looking-at "e")
6028 ;; make sure that the "else" isn't inside a
6029 ;; conditional signal assignment.
6030 (save-excursion
6031 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6032 (or (eq (following-char) ?\;)
6033 (eq (point) lim))))
6035 ;; "block", "generate", "loop", "process", "procedural",
6036 ;; "units", "record", "protected body":
6037 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
6038 (save-excursion
6039 (backward-sexp)
6040 (not (looking-at "end\\s-+\\w"))))
6042 ;; "component":
6043 ((and (looking-at "c")
6044 (save-excursion
6045 (backward-sexp)
6046 (not (looking-at "end\\s-+\\w")))
6047 ;; look out for the dreaded entity class in an attribute
6048 (save-excursion
6049 (vhdl-backward-syntactic-ws lim)
6050 (/= (preceding-char) ?:)))
6052 ;; "for" (inside configuration declaration):
6053 ((and (looking-at "f")
6054 (save-excursion
6055 (backward-sexp)
6056 (not (looking-at "end\\s-+\\w")))
6057 (vhdl-has-syntax 'configuration))
6061 (defun vhdl-corresponding-mid (&optional lim)
6062 (cond
6063 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
6064 "begin")
6065 ((looking-at "then\\|use")
6066 "<else>")
6068 "end")))
6070 (defun vhdl-corresponding-end (&optional lim)
6071 "If the word at the current position corresponds to a \"begin\"
6072 keyword, then return a vector containing enough information to find
6073 the corresponding \"end\" keyword, else return nil. The keyword to
6074 search forward for is aref 0. The column in which the keyword must
6075 appear is aref 1 or nil if any column is suitable.
6076 Assumes that the caller will make sure that we are not in the middle
6077 of an identifier that just happens to contain a \"begin\" keyword."
6078 (save-excursion
6079 (and (looking-at vhdl-begin-fwd-re)
6080 (or (not (looking-at "\\<use\\>"))
6081 (save-excursion (back-to-indentation)
6082 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6083 (/= (preceding-char) ?_)
6084 (not (vhdl-in-literal))
6085 (vhdl-begin-p lim)
6086 (cond
6087 ;; "is", "generate", "loop":
6088 ((looking-at "[igl]")
6089 (vector "end"
6090 (and (vhdl-last-word (point))
6091 (or (vhdl-first-word (point))
6092 (save-excursion
6093 (vhdl-beginning-of-statement-1 lim)
6094 (vhdl-backward-skip-label lim)
6095 (vhdl-first-word (point)))))))
6096 ;; "begin", "else", "for":
6097 ((looking-at "be\\|[ef]")
6098 (vector "end"
6099 (and (vhdl-last-word (point))
6100 (or (vhdl-first-word (point))
6101 (save-excursion
6102 (vhdl-beginning-of-statement-1 lim)
6103 (vhdl-backward-skip-label lim)
6104 (vhdl-first-word (point)))))))
6105 ;; "component", "units", "record", "protected body":
6106 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
6107 ;; The first end found will close the block
6108 (vector "end" nil))
6109 ;; "block", "process", "procedural":
6110 ((looking-at "bl\\|p")
6111 (vector "end"
6112 (or (vhdl-first-word (point))
6113 (save-excursion
6114 (vhdl-beginning-of-statement-1 lim)
6115 (vhdl-backward-skip-label lim)
6116 (vhdl-first-word (point))))))
6117 ;; "then":
6118 ((looking-at "t\\|use")
6119 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
6120 (and (vhdl-last-word (point))
6121 (or (vhdl-first-word (point))
6122 (save-excursion
6123 (vhdl-beginning-of-statement-1 lim)
6124 (vhdl-backward-skip-label lim)
6125 (vhdl-first-word (point)))))))
6126 ))))
6128 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
6130 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
6132 (defun vhdl-end-p (&optional lim)
6133 "Return t if we are looking at a real \"end\" keyword.
6134 Assumes that the caller will make sure that we are looking at
6135 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
6136 the middle of an identifier that just happens to contain an \"end\"
6137 keyword."
6138 (or (not (looking-at "else"))
6139 ;; make sure that the "else" isn't inside a conditional signal
6140 ;; assignment.
6141 (save-excursion
6142 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6143 (or (eq (following-char) ?\;)
6144 (eq (point) lim)
6145 (vhdl-in-literal)))))
6147 (defun vhdl-corresponding-begin (&optional lim)
6148 "If the word at the current position corresponds to an \"end\"
6149 keyword, then return a vector containing enough information to find
6150 the corresponding \"begin\" keyword, else return nil. The keyword to
6151 search backward for is aref 0. The column in which the keyword must
6152 appear is aref 1 or nil if any column is suitable. The supplementary
6153 keyword to search forward for is aref 2 or nil if this is not
6154 required. If aref 3 is t, then the \"begin\" keyword may be found in
6155 the middle of a statement.
6156 Assumes that the caller will make sure that we are not in the middle
6157 of an identifier that just happens to contain an \"end\" keyword."
6158 (save-excursion
6159 (let (pos)
6160 (if (and (looking-at vhdl-end-fwd-re)
6161 (not (vhdl-in-literal))
6162 (vhdl-end-p lim))
6163 (if (looking-at "el")
6164 ;; "else", "elsif":
6165 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
6166 ;; "end ...":
6167 (setq pos (point))
6168 (forward-sexp)
6169 (skip-chars-forward " \t\n\r\f")
6170 (cond
6171 ;; "end if":
6172 ((looking-at "if\\b[^_]")
6173 (vector "else\\|elsif\\|if"
6174 (vhdl-first-word pos)
6175 "else\\|then\\|use" nil))
6176 ;; "end component":
6177 ((looking-at "component\\b[^_]")
6178 (vector (buffer-substring (match-beginning 1)
6179 (match-end 1))
6180 (vhdl-first-word pos)
6181 nil nil))
6182 ;; "end units", "end record", "end protected":
6183 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6184 (vector (buffer-substring (match-beginning 1)
6185 (match-end 1))
6186 (vhdl-first-word pos)
6187 nil t))
6188 ;; "end block", "end process", "end procedural":
6189 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6190 (vector "begin" (vhdl-first-word pos) nil nil))
6191 ;; "end case":
6192 ((looking-at "case\\b[^_]")
6193 (vector "case" (vhdl-first-word pos) "is" nil))
6194 ;; "end generate":
6195 ((looking-at "generate\\b[^_]")
6196 (vector "generate\\|for\\|if"
6197 (vhdl-first-word pos)
6198 "generate" nil))
6199 ;; "end loop":
6200 ((looking-at "loop\\b[^_]")
6201 (vector "loop\\|while\\|for"
6202 (vhdl-first-word pos)
6203 "loop" nil))
6204 ;; "end for" (inside configuration declaration):
6205 ((looking-at "for\\b[^_]")
6206 (vector "for" (vhdl-first-word pos) nil nil))
6207 ;; "end [id]":
6209 (vector "begin\\|architecture\\|configuration\\|context\\|entity\\|package\\|procedure\\|function"
6210 (vhdl-first-word pos)
6211 ;; return an alist of (statement . keyword) mappings
6213 ;; "begin ... end [id]":
6214 ("begin" . nil)
6215 ;; "architecture ... is ... begin ... end [id]":
6216 ("architecture" . "is")
6217 ;; "configuration ... is ... end [id]":
6218 ("configuration" . "is")
6219 ;; "context ... is ... end [id]":
6220 ("context" . "is")
6221 ;; "entity ... is ... end [id]":
6222 ("entity" . "is")
6223 ;; "package ... is ... end [id]":
6224 ("package" . "is")
6225 ;; "procedure ... is ... begin ... end [id]":
6226 ("procedure" . "is")
6227 ;; "function ... is ... begin ... end [id]":
6228 ("function" . "is")
6230 nil))
6231 ))) ; "end ..."
6234 (defconst vhdl-leader-re
6235 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6237 (defun vhdl-end-of-leader ()
6238 (save-excursion
6239 (cond ((looking-at "block\\|process\\|procedural")
6240 (if (save-excursion
6241 (forward-sexp)
6242 (skip-chars-forward " \t\n\r\f")
6243 (= (following-char) ?\())
6244 (forward-sexp 2)
6245 (forward-sexp))
6246 (when (looking-at "[ \t\n\r\f]*is")
6247 (goto-char (match-end 0)))
6248 (point))
6249 ((looking-at "component")
6250 (forward-sexp 2)
6251 (when (looking-at "[ \t\n\r\f]*is")
6252 (goto-char (match-end 0)))
6253 (point))
6254 ((looking-at "for")
6255 (forward-sexp 2)
6256 (skip-chars-forward " \t\n\r\f")
6257 (while (looking-at "[,:(]")
6258 (forward-sexp)
6259 (skip-chars-forward " \t\n\r\f"))
6260 (point))
6261 (t nil)
6264 (defconst vhdl-trailer-re
6265 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6267 (defconst vhdl-statement-fwd-re
6268 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6269 "A regular expression for searching forward that matches all known
6270 \"statement\" keywords.")
6272 (defconst vhdl-statement-bwd-re
6273 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6274 "A regular expression for searching backward that matches all known
6275 \"statement\" keywords.")
6277 (defun vhdl-statement-p (&optional lim)
6278 "Return t if we are looking at a real \"statement\" keyword.
6279 Assumes that the caller will make sure that we are looking at
6280 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6281 in the middle of an identifier that just happens to contain a
6282 \"statement\" keyword."
6283 (cond
6284 ;; "for" ... "generate":
6285 ((and (looking-at "f")
6286 ;; Make sure it's the start of a parameter specification.
6287 (save-excursion
6288 (forward-sexp 2)
6289 (skip-chars-forward " \t\n\r\f")
6290 (looking-at "in\\b[^_]"))
6291 ;; Make sure it's not an "end for".
6292 (save-excursion
6293 (backward-sexp)
6294 (not (looking-at "end\\s-+\\w"))))
6296 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6297 ((and (looking-at "i")
6298 ;; Make sure it's not an "end if".
6299 (save-excursion
6300 (backward-sexp)
6301 (not (looking-at "end\\s-+\\w"))))
6303 ;; "while" ... "loop":
6304 ((looking-at "w")
6308 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6309 "Regexp describing a case statement alternative key.")
6311 (defun vhdl-case-alternative-p (&optional lim)
6312 "Return t if we are looking at a real case alternative.
6313 Assumes that the caller will make sure that we are looking at
6314 vhdl-case-alternative-re, and are not inside a literal, and that
6315 we are not in the middle of an identifier that just happens to
6316 contain a \"when\" keyword."
6317 (save-excursion
6318 (let (foundp)
6319 (while (and (not foundp)
6320 (re-search-backward ";\\|<=" lim 'move))
6321 (if (or (= (preceding-char) ?_)
6322 (vhdl-in-literal))
6323 (backward-char)
6324 (setq foundp t)))
6325 (or (eq (following-char) ?\;)
6326 (eq (point) lim)))
6329 ;; Core syntactic movement functions:
6331 (defconst vhdl-b-t-b-re
6332 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6334 (defun vhdl-backward-to-block (&optional lim)
6335 "Move backward to the previous \"begin\" or \"end\" keyword."
6336 (let (foundp)
6337 (while (and (not foundp)
6338 (re-search-backward vhdl-b-t-b-re lim 'move))
6339 (if (or (= (preceding-char) ?_)
6340 (vhdl-in-literal))
6341 (backward-char)
6342 (cond
6343 ;; "begin" keyword:
6344 ((and (looking-at vhdl-begin-fwd-re)
6345 (or (not (looking-at "\\<use\\>"))
6346 (save-excursion (back-to-indentation)
6347 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6348 (/= (preceding-char) ?_)
6349 (vhdl-begin-p lim))
6350 (setq foundp 'begin))
6351 ;; "end" keyword:
6352 ((and (looking-at vhdl-end-fwd-re)
6353 (/= (preceding-char) ?_)
6354 (vhdl-end-p lim))
6355 (setq foundp 'end))
6358 foundp
6361 (defun vhdl-forward-sexp (&optional count lim)
6362 "Move forward across one balanced expression (sexp).
6363 With COUNT, do it that many times."
6364 (interactive "p")
6365 (let ((count (or count 1))
6366 (case-fold-search t)
6367 end-vec target)
6368 (save-excursion
6369 (while (> count 0)
6370 ;; skip whitespace
6371 (skip-chars-forward " \t\n\r\f")
6372 ;; Check for an unbalanced "end" keyword
6373 (if (and (looking-at vhdl-end-fwd-re)
6374 (/= (preceding-char) ?_)
6375 (not (vhdl-in-literal))
6376 (vhdl-end-p lim)
6377 (not (looking-at "else")))
6378 (error
6379 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6380 ;; If the current keyword is a "begin" keyword, then find the
6381 ;; corresponding "end" keyword.
6382 (if (setq end-vec (vhdl-corresponding-end lim))
6383 (let (
6384 ;; end-re is the statement keyword to search for
6385 (end-re
6386 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6387 ;; column is either the statement keyword target column
6388 ;; or nil
6389 (column (aref end-vec 1))
6390 (eol (vhdl-point 'eol))
6391 foundp literal placeholder)
6392 ;; Look for the statement keyword.
6393 (while (and (not foundp)
6394 (re-search-forward end-re nil t)
6395 (setq placeholder (match-end 1))
6396 (goto-char (match-beginning 0)))
6397 ;; If we are in a literal, or not in the right target
6398 ;; column and not on the same line as the begin, then
6399 ;; try again.
6400 (if (or (and column
6401 (/= (current-indentation) column)
6402 (> (point) eol))
6403 (= (preceding-char) ?_)
6404 (setq literal (vhdl-in-literal)))
6405 (if (eq literal 'comment)
6406 (end-of-line)
6407 (forward-char))
6408 ;; An "else" keyword corresponds to both the opening brace
6409 ;; of the following sexp and the closing brace of the
6410 ;; previous sexp.
6411 (if (not (looking-at "else"))
6412 (goto-char placeholder))
6413 (setq foundp t))
6415 (if (not foundp)
6416 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6418 ;; If the current keyword is not a "begin" keyword, then just
6419 ;; perform the normal forward-sexp.
6420 (forward-sexp)
6422 (setq count (1- count))
6424 (setq target (point)))
6425 (goto-char target)
6426 nil))
6428 (defun vhdl-backward-sexp (&optional count lim)
6429 "Move backward across one balanced expression (sexp).
6430 With COUNT, do it that many times. LIM bounds any required backward
6431 searches."
6432 (interactive "p")
6433 (let ((count (or count 1))
6434 (case-fold-search t)
6435 begin-vec target)
6436 (save-excursion
6437 (while (> count 0)
6438 ;; Perform the normal backward-sexp, unless we are looking at
6439 ;; "else" - an "else" keyword corresponds to both the opening brace
6440 ;; of the following sexp and the closing brace of the previous sexp.
6441 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6442 (/= (preceding-char) ?_)
6443 (not (vhdl-in-literal)))
6445 (backward-sexp)
6446 (if (and (looking-at vhdl-begin-fwd-re)
6447 (or (not (looking-at "\\<use\\>"))
6448 (save-excursion
6449 (back-to-indentation)
6450 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6451 (/= (preceding-char) ?_)
6452 (not (vhdl-in-literal))
6453 (vhdl-begin-p lim))
6454 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6455 ;; If the current keyword is an "end" keyword, then find the
6456 ;; corresponding "begin" keyword.
6457 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6458 (/= (preceding-char) ?_))
6459 (let (
6460 ;; begin-re is the statement keyword to search for
6461 (begin-re
6462 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6463 ;; column is either the statement keyword target column
6464 ;; or nil
6465 (column (aref begin-vec 1))
6466 ;; internal-p controls where the statement keyword can
6467 ;; be found.
6468 (internal-p (aref begin-vec 3))
6469 (last-backward (point)) last-forward
6470 foundp literal keyword)
6471 ;; Look for the statement keyword.
6472 (while (and (not foundp)
6473 (re-search-backward begin-re lim t)
6474 (setq keyword
6475 (buffer-substring (match-beginning 1)
6476 (match-end 1))))
6477 ;; If we are in a literal or in the wrong column,
6478 ;; then try again.
6479 (if (or (and column
6480 (and (/= (current-indentation) column)
6481 ;; possibly accept current-column as
6482 ;; well as current-indentation.
6483 (or (not internal-p)
6484 (/= (current-column) column))))
6485 (= (preceding-char) ?_)
6486 (vhdl-in-literal))
6487 (backward-char)
6488 ;; If there is a supplementary keyword, then
6489 ;; search forward for it.
6490 (if (and (setq begin-re (aref begin-vec 2))
6491 (or (not (listp begin-re))
6492 ;; If begin-re is an alist, then find the
6493 ;; element corresponding to the actual
6494 ;; keyword that we found.
6495 (progn
6496 (setq begin-re
6497 (assoc keyword begin-re))
6498 (and begin-re
6499 (setq begin-re (cdr begin-re))))))
6500 (and
6501 (setq begin-re
6502 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6503 (save-excursion
6504 (setq last-forward (point))
6505 ;; Look for the supplementary keyword
6506 ;; (bounded by the backward search start
6507 ;; point).
6508 (while (and (not foundp)
6509 (re-search-forward begin-re
6510 last-backward t)
6511 (goto-char (match-beginning 1)))
6512 ;; If we are in a literal, then try again.
6513 (if (or (= (preceding-char) ?_)
6514 (setq literal
6515 (vhdl-in-literal)))
6516 (if (eq literal 'comment)
6517 (goto-char
6518 (min (vhdl-point 'eol) last-backward))
6519 (forward-char))
6520 ;; We have found the supplementary keyword.
6521 ;; Save the position of the keyword in foundp.
6522 (setq foundp (point)))
6524 foundp)
6525 ;; If the supplementary keyword was found, then
6526 ;; move point to the supplementary keyword.
6527 (goto-char foundp))
6528 ;; If there was no supplementary keyword, then
6529 ;; point is already at the statement keyword.
6530 (setq foundp t)))
6531 ) ; end of the search for the statement keyword
6532 (if (not foundp)
6533 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6535 (setq count (1- count))
6537 (setq target (point)))
6538 (goto-char target)
6539 nil))
6541 (defun vhdl-backward-up-list (&optional count limit)
6542 "Move backward out of one level of blocks.
6543 With argument, do this that many times."
6544 (interactive "p")
6545 (let ((count (or count 1))
6546 target)
6547 (save-excursion
6548 (while (> count 0)
6549 (if (looking-at vhdl-defun-re)
6550 (error "ERROR: Unbalanced blocks"))
6551 (vhdl-backward-to-block limit)
6552 (setq count (1- count)))
6553 (setq target (point)))
6554 (goto-char target)))
6556 (defun vhdl-end-of-defun (&optional count)
6557 "Move forward to the end of a VHDL defun."
6558 (interactive)
6559 (let ((case-fold-search t))
6560 (vhdl-beginning-of-defun)
6561 (if (not (looking-at "block\\|process\\|procedural"))
6562 (re-search-forward "\\bis\\b"))
6563 (vhdl-forward-sexp)))
6565 (defun vhdl-mark-defun ()
6566 "Put mark at end of this \"defun\", point at beginning."
6567 (interactive)
6568 (let ((case-fold-search t))
6569 (push-mark)
6570 (vhdl-beginning-of-defun)
6571 (push-mark)
6572 (if (not (looking-at "block\\|process\\|procedural"))
6573 (re-search-forward "\\bis\\b"))
6574 (vhdl-forward-sexp)
6575 (exchange-point-and-mark)))
6577 (defun vhdl-beginning-of-libunit ()
6578 "Move backward to the beginning of a VHDL library unit.
6579 Returns the location of the corresponding begin keyword, unless search
6580 stops due to beginning or end of buffer.
6581 Note that if point is between the \"libunit\" keyword and the
6582 corresponding \"begin\" keyword, then that libunit will not be
6583 recognized, and the search will continue backwards. If point is
6584 at the \"begin\" keyword, then the defun will be recognized. The
6585 returned point is at the first character of the \"libunit\" keyword."
6586 (let ((last-forward (point))
6587 (last-backward
6588 ;; Just in case we are actually sitting on the "begin"
6589 ;; keyword, allow for the keyword and an extra character,
6590 ;; as this will be used when looking forward for the
6591 ;; "begin" keyword.
6592 (save-excursion (forward-word-strictly 1) (1+ (point))))
6593 foundp literal placeholder)
6594 ;; Find the "libunit" keyword.
6595 (while (and (not foundp)
6596 (re-search-backward vhdl-libunit-re nil 'move))
6597 ;; If we are in a literal, or not at a real libunit, then try again.
6598 (if (or (= (preceding-char) ?_)
6599 (vhdl-in-literal)
6600 (not (vhdl-libunit-p)))
6601 (backward-char)
6602 ;; Find the corresponding "begin" keyword.
6603 (setq last-forward (point))
6604 (while (and (not foundp)
6605 (re-search-forward "\\bis\\b[^_]" last-backward t)
6606 (setq placeholder (match-beginning 0)))
6607 (if (or (= (preceding-char) ?_)
6608 (setq literal (vhdl-in-literal)))
6609 ;; It wasn't a real keyword, so keep searching.
6610 (if (eq literal 'comment)
6611 (goto-char
6612 (min (vhdl-point 'eol) last-backward))
6613 (forward-char))
6614 ;; We have found the begin keyword, loop will exit.
6615 (setq foundp placeholder)))
6616 ;; Go back to the libunit keyword
6617 (goto-char last-forward)))
6618 foundp))
6620 (defun vhdl-beginning-of-defun (&optional count)
6621 "Move backward to the beginning of a VHDL defun.
6622 With argument, do it that many times.
6623 Returns the location of the corresponding begin keyword, unless search
6624 stops due to beginning or end of buffer."
6625 ;; Note that if point is between the "defun" keyword and the
6626 ;; corresponding "begin" keyword, then that defun will not be
6627 ;; recognized, and the search will continue backwards. If point is
6628 ;; at the "begin" keyword, then the defun will be recognized. The
6629 ;; returned point is at the first character of the "defun" keyword.
6630 (interactive "p")
6631 (let ((count (or count 1))
6632 (case-fold-search t)
6633 (last-forward (point))
6634 foundp)
6635 (while (> count 0)
6636 (setq foundp nil)
6637 (goto-char last-forward)
6638 (let ((last-backward
6639 ;; Just in case we are actually sitting on the "begin"
6640 ;; keyword, allow for the keyword and an extra character,
6641 ;; as this will be used when looking forward for the
6642 ;; "begin" keyword.
6643 (save-excursion (forward-word-strictly 1) (1+ (point))))
6644 begin-string literal)
6645 (while (and (not foundp)
6646 (re-search-backward vhdl-defun-re nil 'move))
6647 ;; If we are in a literal, then try again.
6648 (if (or (= (preceding-char) ?_)
6649 (vhdl-in-literal))
6650 (backward-char)
6651 (if (setq begin-string (vhdl-corresponding-defun))
6652 ;; This is a real defun keyword.
6653 ;; Find the corresponding "begin" keyword.
6654 ;; Look for the begin keyword.
6655 (progn
6656 ;; Save the search start point.
6657 (setq last-forward (point))
6658 (while (and (not foundp)
6659 (search-forward begin-string last-backward t))
6660 (if (or (= (preceding-char) ?_)
6661 (save-match-data
6662 (setq literal (vhdl-in-literal))))
6663 ;; It wasn't a real keyword, so keep searching.
6664 (if (eq literal 'comment)
6665 (goto-char
6666 (min (vhdl-point 'eol) last-backward))
6667 (forward-char))
6668 ;; We have found the begin keyword, loop will exit.
6669 (setq foundp (match-beginning 0)))
6671 ;; Go back to the defun keyword
6672 (goto-char last-forward)) ; end search for begin keyword
6674 ) ; end of the search for the defun keyword
6676 (setq count (1- count))
6678 (vhdl-keep-region-active)
6679 foundp))
6681 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6682 "Go to the beginning of the innermost VHDL statement.
6683 With prefix arg, go back N - 1 statements. If already at the
6684 beginning of a statement then go to the beginning of the preceding
6685 one. If within a string or comment, or next to a comment (only
6686 whitespace between), move by sentences instead of statements.
6688 When called from a program, this function takes 3 optional args: the
6689 prefix arg, a buffer position limit which is the farthest back to
6690 search, and an argument indicating an interactive call."
6691 (interactive "p\np")
6692 (let ((count (or count 1))
6693 (case-fold-search t)
6694 (lim (or lim (point-min)))
6695 (here (point))
6696 state)
6697 (save-excursion
6698 (goto-char lim)
6699 (setq state (parse-partial-sexp (point) here nil nil)))
6700 (if (and interactive
6701 (or (nth 3 state)
6702 (nth 4 state)
6703 (looking-at (concat "[ \t]*" comment-start-skip))))
6704 (forward-sentence (- count))
6705 (while (> count 0)
6706 (vhdl-beginning-of-statement-1 lim)
6707 (setq count (1- count))))
6708 ;; its possible we've been left up-buf of lim
6709 (goto-char (max (point) lim))
6711 (vhdl-keep-region-active))
6713 (defconst vhdl-e-o-s-re
6714 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6716 (defun vhdl-end-of-statement ()
6717 "Very simple implementation."
6718 (interactive)
6719 (re-search-forward vhdl-e-o-s-re))
6721 (defconst vhdl-b-o-s-re
6722 (concat ";[^_]\\|([^_]\\|)[^_]\\|\\bwhen\\b[^_]\\|"
6723 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6725 (defun vhdl-beginning-of-statement-1 (&optional lim)
6726 "Move to the start of the current statement, or the previous
6727 statement if already at the beginning of one."
6728 (let ((lim (or lim (point-min)))
6729 (here (point))
6730 (pos (point))
6731 donep)
6732 ;; go backwards one balanced expression, but be careful of
6733 ;; unbalanced paren being reached
6734 (if (not (vhdl-safe (progn (backward-sexp) t)))
6735 (progn
6736 (backward-up-list 1)
6737 (forward-char)
6738 (vhdl-forward-syntactic-ws here)
6739 (setq donep t)))
6740 (while (and (not donep)
6741 (not (bobp))
6742 ;; look backwards for a statement boundary
6743 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6744 (if (or (= (preceding-char) ?_)
6745 (vhdl-in-literal))
6746 (backward-char)
6747 (cond
6748 ;; If we are looking at an open paren, then stop after it
6749 ((eq (following-char) ?\()
6750 (forward-char)
6751 (vhdl-forward-syntactic-ws here)
6752 (setq donep t))
6753 ;; If we are looking at a close paren, then skip it
6754 ((eq (following-char) ?\))
6755 (forward-char)
6756 (setq pos (point))
6757 (backward-sexp)
6758 (if (< (point) lim)
6759 (progn (goto-char pos)
6760 (vhdl-forward-syntactic-ws here)
6761 (setq donep t))))
6762 ;; If we are looking at a semicolon, then stop
6763 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6764 (progn
6765 (forward-char)
6766 (vhdl-forward-syntactic-ws here)
6767 (setq donep t)))
6768 ;; If we are looking at a "begin", then stop
6769 ((and (looking-at vhdl-begin-fwd-re)
6770 (or (not (looking-at "\\<use\\>"))
6771 (save-excursion
6772 (back-to-indentation)
6773 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6774 (/= (preceding-char) ?_)
6775 (vhdl-begin-p nil))
6776 ;; If it's a leader "begin", then find the
6777 ;; right place
6778 (if (looking-at vhdl-leader-re)
6779 (save-excursion
6780 ;; set a default stop point at the begin
6781 (setq pos (point))
6782 ;; is the start point inside the leader area ?
6783 (goto-char (vhdl-end-of-leader))
6784 (vhdl-forward-syntactic-ws here)
6785 (if (< (point) here)
6786 ;; start point was not inside leader area
6787 ;; set stop point at word after leader
6788 (setq pos (point))))
6789 (unless (looking-at "\\<else\\s-+generate\\>")
6790 (forward-word-strictly 1))
6791 (vhdl-forward-syntactic-ws here)
6792 (setq pos (point)))
6793 (goto-char pos)
6794 (setq donep t))
6795 ;; If we are looking at a "statement", then stop
6796 ((and (looking-at vhdl-statement-fwd-re)
6797 (/= (preceding-char) ?_)
6798 (vhdl-statement-p nil))
6799 (setq donep t))
6800 ;; If we are looking at a case alternative key, then stop
6801 ((and (looking-at vhdl-case-alternative-re)
6802 (vhdl-case-alternative-p lim))
6803 (save-excursion
6804 ;; set a default stop point at the when
6805 (setq pos (point))
6806 ;; is the start point inside the case alternative key ?
6807 (looking-at vhdl-case-alternative-re)
6808 (goto-char (match-end 0))
6809 (vhdl-forward-syntactic-ws here)
6810 (if (< (point) here)
6811 ;; start point was not inside the case alternative key
6812 ;; set stop point at word after case alternative keyleader
6813 (setq pos (point))))
6814 (goto-char pos)
6815 (setq donep t))
6816 ;; Bogus find, continue
6818 (backward-char)))))
6821 ;; Defuns for calculating the current syntactic state:
6823 (defun vhdl-get-library-unit (bod placeholder)
6824 "If there is an enclosing library unit at BOD, with its \"begin\"
6825 keyword at PLACEHOLDER, then return the library unit type."
6826 (let ((here (vhdl-point 'bol)))
6827 (if (save-excursion
6828 (goto-char placeholder)
6829 (vhdl-safe (vhdl-forward-sexp 1 bod))
6830 (<= here (point)))
6831 (save-excursion
6832 (goto-char bod)
6833 (cond
6834 ((looking-at "e") 'entity)
6835 ((looking-at "a") 'architecture)
6836 ((looking-at "conf") 'configuration)
6837 ((looking-at "cont") 'context)
6838 ((looking-at "p")
6839 (save-excursion
6840 (goto-char bod)
6841 (forward-sexp)
6842 (vhdl-forward-syntactic-ws here)
6843 (if (looking-at "body\\b[^_]")
6844 'package-body 'package))))))
6847 (defun vhdl-get-block-state (&optional lim)
6848 "Finds and records all the closest opens.
6849 LIM is the furthest back we need to search (it should be the
6850 previous libunit keyword)."
6851 (let ((here (point))
6852 (lim (or lim (point-min)))
6853 keyword sexp-start sexp-mid sexp-end
6854 preceding-sexp containing-sexp
6855 containing-begin containing-mid containing-paren)
6856 (save-excursion
6857 ;; Find the containing-paren, and use that as the limit
6858 (if (setq containing-paren
6859 (save-restriction
6860 (narrow-to-region lim (point))
6861 (vhdl-safe (scan-lists (point) -1 1))))
6862 (setq lim containing-paren))
6863 ;; Look backwards for "begin" and "end" keywords.
6864 (while (and (> (point) lim)
6865 (not containing-sexp))
6866 (setq keyword (vhdl-backward-to-block lim))
6867 (cond
6868 ((eq keyword 'begin)
6869 ;; Found a "begin" keyword
6870 (setq sexp-start (point))
6871 (setq sexp-mid (vhdl-corresponding-mid lim))
6872 (setq sexp-end (vhdl-safe
6873 (save-excursion
6874 (vhdl-forward-sexp 1 lim) (point))))
6875 (if (and sexp-end (<= sexp-end here))
6876 ;; we want to record this sexp, but we only want to
6877 ;; record the last-most of any of them before here
6878 (or preceding-sexp
6879 (setq preceding-sexp sexp-start))
6880 ;; we're contained in this sexp so put sexp-start on
6881 ;; front of list
6882 (setq containing-sexp sexp-start)
6883 (setq containing-mid sexp-mid)
6884 (setq containing-begin t)))
6885 ((eq keyword 'end)
6886 ;; Found an "end" keyword
6887 (forward-sexp)
6888 (setq sexp-end (point))
6889 (setq sexp-mid nil)
6890 (setq sexp-start
6891 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6892 (progn (backward-sexp) (point))))
6893 ;; we want to record this sexp, but we only want to
6894 ;; record the last-most of any of them before here
6895 (or preceding-sexp
6896 (setq preceding-sexp sexp-start)))
6898 ;; Check if the containing-paren should be the containing-sexp
6899 (if (and containing-paren
6900 (or (null containing-sexp)
6901 (< containing-sexp containing-paren)))
6902 (setq containing-sexp containing-paren
6903 preceding-sexp nil
6904 containing-begin nil
6905 containing-mid nil))
6906 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6910 (defconst vhdl-s-c-a-re
6911 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6913 (defun vhdl-skip-case-alternative (&optional lim)
6914 "Skip forward over case/when bodies, with optional maximal
6915 limit. If no next case alternative is found, nil is returned and
6916 point is not moved."
6917 (let ((lim (or lim (point-max)))
6918 (here (point))
6919 donep foundp)
6920 (while (and (< (point) lim)
6921 (not donep))
6922 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6923 (save-match-data
6924 (not (vhdl-in-literal)))
6925 (/= (match-beginning 0) here))
6926 (progn
6927 (goto-char (match-beginning 0))
6928 (cond
6929 ((and (looking-at "case")
6930 (re-search-forward "\\bis[^_]" lim t))
6931 (backward-sexp)
6932 (vhdl-forward-sexp))
6934 (setq donep t
6935 foundp t))))))
6936 (if (not foundp)
6937 (goto-char here))
6938 foundp))
6940 (defun vhdl-backward-skip-label (&optional lim)
6941 "Skip backward over a label, with optional maximal
6942 limit. If label is not found, nil is returned and point
6943 is not moved."
6944 (let ((lim (or lim (point-min)))
6945 placeholder)
6946 (if (save-excursion
6947 (vhdl-backward-syntactic-ws lim)
6948 (and (eq (preceding-char) ?:)
6949 (progn
6950 (backward-sexp)
6951 (setq placeholder (point))
6952 (looking-at vhdl-label-key))))
6953 (goto-char placeholder))
6956 (defun vhdl-forward-skip-label (&optional lim)
6957 "Skip forward over a label, with optional maximal
6958 limit. If label is not found, nil is returned and point
6959 is not moved."
6960 (let ((lim (or lim (point-max))))
6961 (if (looking-at vhdl-label-key)
6962 (progn
6963 (goto-char (match-end 0))
6964 (vhdl-forward-syntactic-ws lim)))
6967 (defun vhdl-get-syntactic-context ()
6968 "Guess the syntactic description of the current line of VHDL code."
6969 (save-excursion
6970 (save-restriction
6971 (beginning-of-line)
6972 (let* ((indent-point (point))
6973 (case-fold-search t)
6974 vec literal containing-sexp preceding-sexp
6975 containing-begin containing-mid containing-leader
6976 char-before-ip char-after-ip begin-after-ip end-after-ip
6977 placeholder lim library-unit
6980 ;; Reset the syntactic context
6981 (setq vhdl-syntactic-context nil)
6983 (save-excursion
6984 ;; Move to the start of the previous library unit, and
6985 ;; record the position of the "begin" keyword.
6986 (setq placeholder (vhdl-beginning-of-libunit))
6987 ;; The position of the "libunit" keyword gives us a gross
6988 ;; limit point.
6989 (setq lim (point))
6992 ;; If there is a previous library unit, and we are enclosed by
6993 ;; it, then set the syntax accordingly.
6994 (and placeholder
6995 (setq library-unit (vhdl-get-library-unit lim placeholder))
6996 (vhdl-add-syntax library-unit lim))
6998 ;; Find the surrounding state.
6999 (if (setq vec (vhdl-get-block-state lim))
7000 (progn
7001 (setq containing-sexp (aref vec 0))
7002 (setq preceding-sexp (aref vec 1))
7003 (setq containing-begin (aref vec 2))
7004 (setq containing-mid (aref vec 3))
7007 ;; set the limit on the farthest back we need to search
7008 (setq lim (if containing-sexp
7009 (save-excursion
7010 (goto-char containing-sexp)
7011 ;; set containing-leader if required
7012 (if (looking-at vhdl-leader-re)
7013 (setq containing-leader (vhdl-end-of-leader)))
7014 (vhdl-point 'bol))
7015 (point-min)))
7017 ;; cache char before and after indent point, and move point to
7018 ;; the most likely position to perform the majority of tests
7019 (goto-char indent-point)
7020 (skip-chars-forward " \t")
7021 (setq literal (vhdl-in-literal))
7022 (setq char-after-ip (following-char))
7023 (setq begin-after-ip (and
7024 (not literal)
7025 (looking-at vhdl-begin-fwd-re)
7026 (or (not (looking-at "\\<use\\>"))
7027 (save-excursion
7028 (back-to-indentation)
7029 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
7030 (vhdl-begin-p)))
7031 (setq end-after-ip (and
7032 (not literal)
7033 (looking-at vhdl-end-fwd-re)
7034 (vhdl-end-p)))
7035 (vhdl-backward-syntactic-ws lim)
7036 (setq char-before-ip (preceding-char))
7037 (goto-char indent-point)
7038 (skip-chars-forward " \t")
7040 ;; now figure out syntactic qualities of the current line
7041 (cond
7042 ;; CASE 1: in a string or comment.
7043 ((memq literal '(string comment))
7044 (vhdl-add-syntax literal (vhdl-point 'bopl)))
7045 ;; CASE 2: Line is at top level.
7046 ((null containing-sexp)
7047 ;; Find the point to which indentation will be relative
7048 (save-excursion
7049 (if (null preceding-sexp)
7050 ;; CASE 2X.1
7051 ;; no preceding-sexp -> use the preceding statement
7052 (vhdl-beginning-of-statement-1 lim)
7053 ;; CASE 2X.2
7054 ;; if there is a preceding-sexp then indent relative to it
7055 (goto-char preceding-sexp)
7056 ;; if not at boi, then the block-opening keyword is
7057 ;; probably following a label, so we need a different
7058 ;; relpos
7059 (if (/= (point) (vhdl-point 'boi))
7060 ;; CASE 2X.3
7061 (vhdl-beginning-of-statement-1 lim)))
7062 ;; v-b-o-s could have left us at point-min
7063 (and (bobp)
7064 ;; CASE 2X.4
7065 (vhdl-forward-syntactic-ws indent-point))
7066 (setq placeholder (point)))
7067 (cond
7068 ;; CASE 2A : we are looking at a block-open
7069 (begin-after-ip
7070 (vhdl-add-syntax 'block-open placeholder))
7071 ;; CASE 2B: we are looking at a block-close
7072 (end-after-ip
7073 (vhdl-add-syntax 'block-close placeholder))
7074 ;; CASE 2C: we are looking at a top-level statement
7075 ((progn
7076 (vhdl-backward-syntactic-ws lim)
7077 (or (bobp)
7078 (and (= (preceding-char) ?\;)
7079 (not (vhdl-in-quote-p)))))
7080 (vhdl-add-syntax 'statement placeholder))
7081 ;; CASE 2D: we are looking at a top-level statement-cont
7083 (vhdl-beginning-of-statement-1 lim)
7084 ;; v-b-o-s could have left us at point-min
7085 (and (bobp)
7086 ;; CASE 2D.1
7087 (vhdl-forward-syntactic-ws indent-point))
7088 (vhdl-add-syntax 'statement-cont (point)))
7089 )) ; end CASE 2
7090 ;; CASE 3: line is inside parentheses. Most likely we are
7091 ;; either in a subprogram argument (interface) list, or a
7092 ;; continued expression containing parentheses.
7093 ((null containing-begin)
7094 (vhdl-backward-syntactic-ws containing-sexp)
7095 (cond
7096 ;; CASE 3A: we are looking at the arglist closing paren
7097 ((eq char-after-ip ?\))
7098 (goto-char containing-sexp)
7099 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
7100 ;; CASE 3B: we are looking at the first argument in an empty
7101 ;; argument list.
7102 ((eq char-before-ip ?\()
7103 (goto-char containing-sexp)
7104 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
7105 ;; CASE 3C: we are looking at an arglist continuation line,
7106 ;; but the preceding argument is on the same line as the
7107 ;; opening paren. This case includes multi-line
7108 ;; expression paren groupings.
7109 ((and (save-excursion
7110 (goto-char (1+ containing-sexp))
7111 (skip-chars-forward " \t")
7112 (not (eolp))
7113 (not (looking-at "--\\|`")))
7114 (save-excursion
7115 (vhdl-beginning-of-statement-1 containing-sexp)
7116 (skip-chars-backward " \t(")
7117 (while (and (= (preceding-char) ?\;)
7118 (not (vhdl-in-quote-p)))
7119 (vhdl-beginning-of-statement-1 containing-sexp)
7120 (skip-chars-backward " \t("))
7121 (<= (point) containing-sexp)))
7122 (goto-char containing-sexp)
7123 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
7124 ;; CASE 3D: we are looking at just a normal arglist
7125 ;; continuation line
7126 (t (vhdl-beginning-of-statement-1 containing-sexp)
7127 (vhdl-forward-syntactic-ws indent-point)
7128 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
7130 ;; CASE 4: A block mid open
7131 ((and begin-after-ip
7132 (looking-at containing-mid))
7133 (goto-char containing-sexp)
7134 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7135 (if (looking-at vhdl-trailer-re)
7136 ;; CASE 4.1
7137 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7138 (vhdl-backward-skip-label (vhdl-point 'boi))
7139 (vhdl-add-syntax 'block-open (point)))
7140 ;; CASE 5: block close brace
7141 (end-after-ip
7142 (goto-char containing-sexp)
7143 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7144 (if (looking-at vhdl-trailer-re)
7145 ;; CASE 5.1
7146 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7147 (vhdl-backward-skip-label (vhdl-point 'boi))
7148 (vhdl-add-syntax 'block-close (point)))
7149 ;; CASE 6: A continued statement
7150 ((and (/= char-before-ip ?\;)
7151 ;; check it's not a trailer begin keyword, or a begin
7152 ;; keyword immediately following a label.
7153 (not (and begin-after-ip
7154 (or (looking-at vhdl-trailer-re)
7155 (save-excursion
7156 (vhdl-backward-skip-label containing-sexp)))))
7157 ;; check it's not a statement keyword
7158 (not (and (looking-at vhdl-statement-fwd-re)
7159 (vhdl-statement-p)))
7160 ;; see if the b-o-s is before the indent point
7161 (> indent-point
7162 (save-excursion
7163 (vhdl-beginning-of-statement-1 containing-sexp)
7164 ;; If we ended up after a leader, then this will
7165 ;; move us forward to the start of the first
7166 ;; statement. Note that a containing sexp here is
7167 ;; always a keyword, not a paren, so this will
7168 ;; have no effect if we hit the containing-sexp.
7169 (vhdl-forward-syntactic-ws indent-point)
7170 (setq placeholder (point))))
7171 ;; check it's not a block-intro
7172 (/= placeholder containing-sexp)
7173 ;; check it's not a case block-intro
7174 (save-excursion
7175 (goto-char placeholder)
7176 (or (not (looking-at vhdl-case-alternative-re))
7177 (> (match-end 0) indent-point))))
7178 ;; Make placeholder skip a label, but only if it puts us
7179 ;; before the indent point at the start of a line.
7180 (let ((new placeholder))
7181 (if (and (> indent-point
7182 (save-excursion
7183 (goto-char placeholder)
7184 (vhdl-forward-skip-label indent-point)
7185 (setq new (point))))
7186 (save-excursion
7187 (goto-char new)
7188 (eq new (progn (back-to-indentation) (point)))))
7189 (setq placeholder new)))
7190 (vhdl-add-syntax 'statement-cont placeholder)
7191 (if begin-after-ip
7192 (vhdl-add-syntax 'block-open)))
7193 ;; Statement. But what kind?
7194 ;; CASE 7: A case alternative key
7195 ((and (looking-at vhdl-case-alternative-re)
7196 (vhdl-case-alternative-p containing-sexp))
7197 ;; for a case alternative key, we set relpos to the first
7198 ;; non-whitespace char on the line containing the "case"
7199 ;; keyword.
7200 (goto-char containing-sexp)
7201 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7202 (if (looking-at vhdl-trailer-re)
7203 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7204 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
7205 ;; CASE 8: statement catchall
7207 ;; we know its a statement, but we need to find out if it is
7208 ;; the first statement in a block
7209 (if containing-leader
7210 (goto-char containing-leader)
7211 (goto-char containing-sexp)
7212 ;; Note that a containing sexp here is always a keyword,
7213 ;; not a paren, so skip over the keyword.
7214 (forward-sexp))
7215 ;; move to the start of the first statement
7216 (vhdl-forward-syntactic-ws indent-point)
7217 (setq placeholder (point))
7218 ;; we want to ignore case alternatives keys when skipping forward
7219 (let (incase-p)
7220 (while (looking-at vhdl-case-alternative-re)
7221 (setq incase-p (point))
7222 ;; we also want to skip over the body of the
7223 ;; case/when statement if that doesn't put us at
7224 ;; after the indent-point
7225 (while (vhdl-skip-case-alternative indent-point))
7226 ;; set up the match end
7227 (looking-at vhdl-case-alternative-re)
7228 (goto-char (match-end 0))
7229 ;; move to the start of the first case alternative statement
7230 (vhdl-forward-syntactic-ws indent-point)
7231 (setq placeholder (point)))
7232 (cond
7233 ;; CASE 8A: we saw a case/when statement so we must be
7234 ;; in a switch statement. find out if we are at the
7235 ;; statement just after a case alternative key
7236 ((and incase-p
7237 (= (point) indent-point))
7238 ;; relpos is the "when" keyword
7239 (vhdl-add-syntax 'statement-case-intro incase-p))
7240 ;; CASE 8B: any old statement
7241 ((< (point) indent-point)
7242 ;; relpos is the first statement of the block
7243 (vhdl-add-syntax 'statement placeholder)
7244 (if begin-after-ip
7245 (vhdl-add-syntax 'block-open)))
7246 ;; CASE 8C: first statement in a block
7248 (goto-char containing-sexp)
7249 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7250 (if (looking-at vhdl-trailer-re)
7251 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7252 (vhdl-backward-skip-label (vhdl-point 'boi))
7253 (vhdl-add-syntax 'statement-block-intro (point))
7254 (if begin-after-ip
7255 (vhdl-add-syntax 'block-open)))
7259 ;; now we need to look at any modifiers
7260 (goto-char indent-point)
7261 (skip-chars-forward " \t")
7262 (if (or (looking-at "--") (looking-at "/\\*"))
7263 (vhdl-add-syntax 'comment))
7264 (if (looking-at "`")
7265 (vhdl-add-syntax 'directive))
7266 (if (eq literal 'pound)
7267 (vhdl-add-syntax 'cpp-macro))
7268 ;; return the syntax
7269 vhdl-syntactic-context))))
7271 ;; Standard indentation line-ups:
7273 (defun vhdl-lineup-arglist (langelem)
7274 "Lineup the current arglist line with the arglist appearing just
7275 after the containing paren which starts the arglist."
7276 (save-excursion
7277 (let* ((containing-sexp
7278 (save-excursion
7279 ;; arglist-cont-nonempty gives relpos ==
7280 ;; to boi of containing-sexp paren. This
7281 ;; is good when offset is +, but bad
7282 ;; when it is vhdl-lineup-arglist, so we
7283 ;; have to special case a kludge here.
7284 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7285 (progn
7286 (beginning-of-line)
7287 (backward-up-list 1)
7288 (skip-chars-forward " \t" (vhdl-point 'eol)))
7289 (goto-char (cdr langelem)))
7290 (point)))
7291 (cs-curcol (save-excursion
7292 (goto-char (cdr langelem))
7293 (current-column))))
7294 (if (save-excursion
7295 (beginning-of-line)
7296 (looking-at "[ \t]*)"))
7297 (progn (goto-char (match-end 0))
7298 (backward-sexp)
7299 (forward-char)
7300 (vhdl-forward-syntactic-ws)
7301 (- (current-column) cs-curcol))
7302 (goto-char containing-sexp)
7303 (or (eolp)
7304 (let ((eol (vhdl-point 'eol))
7305 (here (progn
7306 (forward-char)
7307 (skip-chars-forward " \t")
7308 (point))))
7309 (vhdl-forward-syntactic-ws)
7310 (if (< (point) eol)
7311 (goto-char here))))
7312 (- (current-column) cs-curcol)
7313 ))))
7315 (defun vhdl-lineup-arglist-intro (langelem)
7316 "Lineup an arglist-intro line to just after the open paren."
7317 (save-excursion
7318 (let ((cs-curcol (save-excursion
7319 (goto-char (cdr langelem))
7320 (current-column)))
7321 (ce-curcol (save-excursion
7322 (beginning-of-line)
7323 (backward-up-list 1)
7324 (skip-chars-forward " \t" (vhdl-point 'eol))
7325 (current-column))))
7326 (- ce-curcol cs-curcol -1))))
7328 (defun vhdl-lineup-comment (langelem)
7329 "Support old behavior for comment indentation. We look at
7330 vhdl-comment-only-line-offset to decide how to indent comment
7331 only-lines."
7332 (save-excursion
7333 (back-to-indentation)
7334 ;; at or to the right of comment-column
7335 (if (>= (current-column) comment-column)
7336 (vhdl-comment-indent)
7337 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7338 (if (not (bolp))
7339 ;; inside multi-line comment
7340 (if (looking-at "\\*")
7342 ;; otherwise
7343 (or (car-safe vhdl-comment-only-line-offset)
7344 vhdl-comment-only-line-offset))
7345 (or (cdr-safe vhdl-comment-only-line-offset)
7346 (car-safe vhdl-comment-only-line-offset)
7347 -1000 ;jam it against the left side
7348 )))))
7350 (defun vhdl-lineup-statement-cont (langelem)
7351 "Line up statement-cont after the assignment operator."
7352 (save-excursion
7353 (let* ((relpos (cdr langelem))
7354 (assignp (save-excursion
7355 (goto-char (vhdl-point 'boi))
7356 (and (re-search-forward "\\(<\\|:\\|=\\)="
7357 (vhdl-point 'eol) t)
7358 (- (point) (vhdl-point 'boi)))))
7359 (curcol (progn
7360 (goto-char relpos)
7361 (current-column)))
7362 foundp)
7363 (while (and (not foundp)
7364 (< (point) (vhdl-point 'eol)))
7365 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7366 (if (vhdl-in-literal)
7367 (forward-char)
7368 (if (= (preceding-char) ?\()
7369 ;; skip over any parenthesized expressions
7370 (goto-char (min (vhdl-point 'eol)
7371 (scan-lists (point) 1 1)))
7372 ;; found an assignment operator (not at eol)
7373 (setq foundp (not (looking-at "\\s-*$"))))))
7374 (if (not foundp)
7375 ;; there's no assignment operator on the line
7376 vhdl-basic-offset
7377 ;; calculate indentation column after assign and ws, unless
7378 ;; our line contains an assignment operator
7379 (if (not assignp)
7380 (progn
7381 (forward-char)
7382 (skip-chars-forward " \t")
7383 (setq assignp 0)))
7384 (- (current-column) assignp curcol))
7387 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7388 ;; Progress reporting
7390 (defvar vhdl-progress-info nil
7391 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7393 (defun vhdl-update-progress-info (string pos)
7394 "Update progress information."
7395 (when (and vhdl-progress-info (not noninteractive)
7396 (< vhdl-progress-interval
7397 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7398 (let ((delta (- (aref vhdl-progress-info 1)
7399 (aref vhdl-progress-info 0))))
7400 (message "%s... (%2d%%)" string
7401 (if (= 0 delta)
7403 (floor (* 100.0 (- pos (aref vhdl-progress-info 0)))
7404 delta))))
7405 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7408 ;; Indentation commands
7410 (defun vhdl-electric-tab (&optional prefix-arg)
7411 "If preceding character is part of a word or a paren then hippie-expand,
7412 else if right of non whitespace on line then insert tab,
7413 else if last command was a tab or return then dedent one step or if a comment
7414 toggle between normal indent and inline comment indent,
7415 else indent `correctly'."
7416 (interactive "*P")
7417 (vhdl-prepare-search-2
7418 (cond
7419 ;; indent region if region is active
7420 ((and (not (featurep 'xemacs)) (use-region-p))
7421 (vhdl-indent-region (region-beginning) (region-end) nil))
7422 ;; expand word
7423 ((= (char-syntax (preceding-char)) ?w)
7424 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7425 (case-replace nil)
7426 (hippie-expand-only-buffers
7427 (or (and (boundp 'hippie-expand-only-buffers)
7428 hippie-expand-only-buffers)
7429 '(vhdl-mode))))
7430 (vhdl-expand-abbrev prefix-arg)))
7431 ;; expand parenthesis
7432 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7433 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7434 (case-replace nil))
7435 (vhdl-expand-paren prefix-arg)))
7436 ;; insert tab
7437 ((> (current-column) (current-indentation))
7438 (insert-tab))
7439 ;; toggle comment indent
7440 ((and (looking-at "--")
7441 (or (eq last-command 'vhdl-electric-tab)
7442 (eq last-command 'vhdl-electric-return)))
7443 (cond ((= (current-indentation) 0) ; no indent
7444 (indent-to 1)
7445 (indent-according-to-mode))
7446 ((< (current-indentation) comment-column) ; normal indent
7447 (indent-to comment-column)
7448 (indent-according-to-mode))
7449 (t ; inline comment indent
7450 (delete-region (line-beginning-position) (point)))))
7451 ;; dedent
7452 ((and (>= (current-indentation) vhdl-basic-offset)
7453 (or (eq last-command 'vhdl-electric-tab)
7454 (eq last-command 'vhdl-electric-return)))
7455 (backward-delete-char-untabify vhdl-basic-offset nil))
7456 ;; indent line
7457 (t (indent-according-to-mode)))
7458 (setq this-command 'vhdl-electric-tab)))
7460 (defun vhdl-electric-return ()
7461 "newline-and-indent or indent-new-comment-line if in comment and preceding
7462 character is a space."
7463 (interactive)
7464 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7465 (indent-new-comment-line)
7466 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7467 (not (vhdl-in-comment-p)))
7468 (vhdl-fix-case-word -1))
7469 (newline-and-indent)))
7471 (defun vhdl-indent-line ()
7472 "Indent the current line as VHDL code. Returns the amount of
7473 indentation change."
7474 (interactive)
7475 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7476 (pos (- (point-max) (point)))
7477 (is-comment nil)
7478 (indent
7479 (if syntax
7480 ;; indent syntax-based
7481 (if (and (eq (caar syntax) 'comment)
7482 (>= (vhdl-get-offset (car syntax)) comment-column))
7483 ;; special case: comments at or right of comment-column
7484 (vhdl-get-offset (car syntax))
7485 ;; align comments like following code line
7486 (when vhdl-indent-comment-like-next-code-line
7487 (save-excursion
7488 (while (eq (caar syntax) 'comment)
7489 (setq is-comment t)
7490 (beginning-of-line 2)
7491 (setq syntax (vhdl-get-syntactic-context)))))
7492 (when is-comment
7493 (push (cons 'comment nil) syntax))
7494 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7495 ;; indent like previous nonblank line
7496 (save-excursion (beginning-of-line)
7497 (re-search-backward "^[^\n]" nil t)
7498 (current-indentation))))
7499 (shift-amt (- indent (current-indentation))))
7500 (and vhdl-echo-syntactic-information-p
7501 (message "syntax: %s, indent= %d" syntax indent))
7502 (let ((has-formfeed
7503 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7504 (when (or (not (zerop shift-amt)) has-formfeed)
7505 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7506 (beginning-of-line)
7507 (when has-formfeed (insert "\f"))
7508 (indent-to indent)))
7509 (if (< (point) (vhdl-point 'boi))
7510 (back-to-indentation)
7511 ;; If initial point was within line's indentation, position after
7512 ;; the indentation. Else stay at same point in text.
7513 (when (> (- (point-max) pos) (point))
7514 (goto-char (- (point-max) pos))))
7515 (run-hooks 'vhdl-special-indent-hook)
7516 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7517 shift-amt))
7519 (defun vhdl-indent-region (beg end &optional column)
7520 "Indent region as VHDL code.
7521 Adds progress reporting to `indent-region'."
7522 (interactive "r\nP")
7523 (when vhdl-progress-interval
7524 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7525 (count-lines (point-min) end) 0)))
7526 (indent-region beg end column)
7527 (when vhdl-progress-interval (message "Indenting...done"))
7528 (setq vhdl-progress-info nil))
7530 (defun vhdl-indent-buffer ()
7531 "Indent whole buffer as VHDL code.
7532 Calls `indent-region' for whole buffer and adds progress reporting."
7533 (interactive)
7534 (vhdl-indent-region (point-min) (point-max)))
7536 (defun vhdl-indent-group ()
7537 "Indent group of lines between empty lines."
7538 (interactive)
7539 (let ((beg (save-excursion
7540 (if (re-search-backward vhdl-align-group-separate nil t)
7541 (point-marker)
7542 (point-min-marker))))
7543 (end (save-excursion
7544 (if (re-search-forward vhdl-align-group-separate nil t)
7545 (point-marker)
7546 (point-max-marker)))))
7547 (vhdl-indent-region beg end)))
7549 (defun vhdl-indent-sexp (&optional endpos)
7550 "Indent each line of the list starting just after point.
7551 If optional arg ENDPOS is given, indent each line, stopping when
7552 ENDPOS is encountered."
7553 (interactive)
7554 (save-excursion
7555 (let ((beg (point))
7556 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7557 (indent-region beg end nil))))
7559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7560 ;; Miscellaneous commands
7562 (defun vhdl-show-syntactic-information ()
7563 "Show syntactic information for current line."
7564 (interactive)
7565 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7566 (vhdl-keep-region-active))
7568 ;; Verification and regression functions:
7570 (defun vhdl-regress-line (&optional arg)
7571 "Check syntactic information for current line."
7572 (interactive "P")
7573 (let ((expected (save-excursion
7574 (end-of-line)
7575 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7576 (forward-char 4)
7577 (read (current-buffer)))))
7578 (actual (vhdl-get-syntactic-context))
7579 (expurgated))
7580 ;; remove the library unit symbols
7581 (mapc
7582 (function
7583 (lambda (elt)
7584 (if (memq (car elt) '(entity configuration context package
7585 package-body architecture))
7587 (setq expurgated (append expurgated (list elt))))))
7588 actual)
7589 (if (and (not arg) expected (listp expected))
7590 (if (not (equal expected expurgated))
7591 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7592 (save-excursion
7593 (beginning-of-line)
7594 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7595 (end-of-line)
7596 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7597 (delete-region (point) (line-end-position)))
7598 (insert " -- ")
7599 (insert (format "%s" expurgated))))))
7600 (vhdl-keep-region-active))
7603 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7604 ;;; Alignment, beautifying
7605 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7607 (defconst vhdl-align-alist
7609 ;; after some keywords
7610 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7611 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7612 ;; before ':'
7613 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7614 ;; after direction specifications
7615 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7616 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7617 ;; before "==", ":=", "=>", and "<="
7618 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7619 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7620 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7621 ;; before some keywords
7622 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7623 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7624 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7625 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7626 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7627 ;; before "=>" since "when/else ... =>" can occur
7628 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7630 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7631 It is searched in order. If REGEXP is found anywhere in the first
7632 line of a region to be aligned, ALIGN-PATTERN will be used for that
7633 region. ALIGN-PATTERN must include the whitespace to be expanded or
7634 contracted. It may also provide regexps for the text surrounding the
7635 whitespace. SUBEXP specifies which sub-expression of
7636 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7638 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7639 ;; Align code
7641 (defvar vhdl-align-try-all-clauses t
7642 "If REGEXP is not found on the first line of the region that clause
7643 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7645 (defun vhdl-do-group (function &optional spacing)
7646 "Apply FUNCTION on group of lines between empty lines."
7647 (let
7648 ;; search for group beginning
7649 ((beg (save-excursion
7650 (if (re-search-backward vhdl-align-group-separate nil t)
7651 (progn (beginning-of-line 2) (back-to-indentation) (point))
7652 (point-min))))
7653 ;; search for group end
7654 (end (save-excursion
7655 (if (re-search-forward vhdl-align-group-separate nil t)
7656 (progn (beginning-of-line) (point))
7657 (point-max)))))
7658 ;; run FUNCTION
7659 (funcall function beg end spacing)))
7661 (defun vhdl-do-list (function &optional spacing)
7662 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7663 parentheses."
7664 (let (beg end)
7665 (save-excursion
7666 ;; search for beginning of balanced group of parentheses
7667 (setq beg (vhdl-re-search-backward "[()]" nil t))
7668 (while (looking-at ")")
7669 (forward-char) (backward-sexp)
7670 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7671 ;; search for end of balanced group of parentheses
7672 (when beg
7673 (forward-list)
7674 (setq end (point))
7675 (goto-char (1+ beg))
7676 (skip-chars-forward " \t\n\r\f")
7677 (setq beg (point))))
7678 ;; run FUNCTION
7679 (if beg
7680 (funcall function beg end spacing)
7681 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7683 (defun vhdl-do-same-indent (function &optional spacing)
7684 "Apply FUNCTION to block of lines with same indent."
7685 (let ((indent (current-indentation))
7686 beg end)
7687 ;; search for first line with same indent
7688 (save-excursion
7689 (while (and (not (bobp))
7690 (or (looking-at "^\\s-*\\(--.*\\)?$")
7691 (= (current-indentation) indent)))
7692 (unless (looking-at "^\\s-*$")
7693 (back-to-indentation) (setq beg (point)))
7694 (beginning-of-line -0)))
7695 ;; search for last line with same indent
7696 (save-excursion
7697 (while (and (not (eobp))
7698 (or (looking-at "^\\s-*\\(--.*\\)?$")
7699 (= (current-indentation) indent)))
7700 (if (looking-at "^\\s-*$")
7701 (beginning-of-line 2)
7702 (beginning-of-line 2)
7703 (setq end (point)))))
7704 ;; run FUNCTION
7705 (funcall function beg end spacing)))
7707 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7708 "Attempt to align a range of lines based on the content of the
7709 lines. The definition of `alignment-list' determines the matching
7710 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7711 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7712 indentation is done before aligning."
7713 (interactive "r\np")
7714 (setq alignment-list (or alignment-list vhdl-align-alist))
7715 (setq spacing (or spacing 1))
7716 (save-excursion
7717 (let (bol indent)
7718 (goto-char end)
7719 (setq end (point-marker))
7720 (goto-char begin)
7721 (setq bol (setq begin (progn (beginning-of-line) (point))))
7722 (when indent
7723 (indent-region bol end nil))))
7724 (let ((copy (copy-alist alignment-list)))
7725 (vhdl-prepare-search-2
7726 (while copy
7727 (save-excursion
7728 (goto-char begin)
7729 (let (element
7730 (eol (point-at-eol)))
7731 (setq element (nth 0 copy))
7732 (when (and (or (and (listp (car element))
7733 (memq major-mode (car element)))
7734 (eq major-mode (car element)))
7735 (or vhdl-align-try-all-clauses
7736 (re-search-forward (car (cdr element)) eol t)))
7737 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7738 (car (cdr (cdr (cdr element)))) spacing))
7739 (setq copy (cdr copy))))))))
7741 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7742 "Align a range of lines from BEGIN to END. The regular expression
7743 MATCH must match exactly one field: the whitespace to be
7744 contracted/expanded. The alignment column will equal the
7745 rightmost column of the widest whitespace block. SPACING is
7746 the amount of extra spaces to add to the calculated maximum required.
7747 SPACING defaults to 1 so that at least one space is inserted after
7748 the token in MATCH."
7749 (setq spacing (or spacing 1))
7750 (setq substr (or substr 1))
7751 (save-excursion
7752 (let (distance (max 0) (lines 0) bol eol width)
7753 ;; Determine the greatest whitespace distance to the alignment
7754 ;; character
7755 (goto-char begin)
7756 (setq eol (point-at-eol)
7757 bol (setq begin (progn (beginning-of-line) (point))))
7758 (while (< bol end)
7759 (save-excursion
7760 (when (and (vhdl-re-search-forward match eol t)
7761 (save-excursion
7762 (goto-char (match-beginning 0))
7763 (forward-char)
7764 (and (not (vhdl-in-literal))
7765 (not (vhdl-in-quote-p))
7766 (not (vhdl-in-extended-identifier-p))))
7767 (not (looking-at "\\s-*$")))
7768 (setq distance (- (match-beginning substr) bol))
7769 (when (> distance max)
7770 (setq max distance))))
7771 (forward-line)
7772 (setq bol (point)
7773 eol (point-at-eol))
7774 (setq lines (1+ lines)))
7775 ;; Now insert enough maxs to push each assignment operator to
7776 ;; the same column. We need to use 'lines' as a counter, since
7777 ;; the location of the mark may change
7778 (goto-char (setq bol begin))
7779 (setq eol (point-at-eol))
7780 (while (> lines 0)
7781 (when (and (vhdl-re-search-forward match eol t)
7782 (save-excursion
7783 (goto-char (match-beginning 0))
7784 (forward-char)
7785 (and (not (vhdl-in-literal))
7786 (not (vhdl-in-quote-p))
7787 (not (vhdl-in-extended-identifier-p))))
7788 (not (looking-at "\\s-*$"))
7789 (> (match-beginning 0) ; not if at boi
7790 (save-excursion (back-to-indentation) (point))))
7791 (setq width (- (match-end substr) (match-beginning substr)))
7792 (setq distance (- (match-beginning substr) bol))
7793 (goto-char (match-beginning substr))
7794 (delete-char width)
7795 (insert-char ? (+ (- max distance) spacing)))
7796 (beginning-of-line)
7797 (forward-line)
7798 (setq bol (point)
7799 eol (point-at-eol))
7800 (setq lines (1- lines))))))
7802 (defun vhdl-align-region-groups (beg end &optional spacing
7803 no-message no-comments)
7804 "Align region, treat groups of lines separately."
7805 (interactive "r\nP")
7806 (save-excursion
7807 (let (orig pos)
7808 (goto-char beg)
7809 (beginning-of-line)
7810 (setq orig (point-marker))
7811 (setq beg (point))
7812 (goto-char end)
7813 (setq end (point-marker))
7814 (untabify beg end)
7815 (unless no-message
7816 (when vhdl-progress-interval
7817 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7818 (count-lines (point-min) end) 0))))
7819 (when (nth 0 vhdl-beautify-options)
7820 (vhdl-fixup-whitespace-region beg end t))
7821 (goto-char beg)
7822 (if (not vhdl-align-groups)
7823 ;; align entire region
7824 (progn (vhdl-align-region-1 beg end spacing)
7825 (unless no-comments
7826 (vhdl-align-inline-comment-region-1 beg end)))
7827 ;; align groups
7828 (while (and (< beg end)
7829 (re-search-forward vhdl-align-group-separate end t))
7830 (setq pos (point-marker))
7831 (vhdl-align-region-1 beg pos spacing)
7832 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7833 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7834 (setq beg (1+ pos))
7835 (goto-char beg))
7836 ;; align last group
7837 (when (< beg end)
7838 (vhdl-align-region-1 beg end spacing)
7839 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7840 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7841 (when vhdl-indent-tabs-mode
7842 (tabify orig end))
7843 (unless no-message
7844 (when vhdl-progress-interval (message "Aligning...done"))
7845 (setq vhdl-progress-info nil)))))
7847 (defun vhdl-align-region (beg end &optional spacing)
7848 "Align region, treat blocks with same indent and argument lists separately."
7849 (interactive "r\nP")
7850 (if (not vhdl-align-same-indent)
7851 ;; align entire region
7852 (vhdl-align-region-groups beg end spacing)
7853 ;; align blocks with same indent and argument lists
7854 (save-excursion
7855 (let ((cur-beg beg)
7856 indent cur-end)
7857 (when vhdl-progress-interval
7858 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7859 (count-lines (point-min) end) 0)))
7860 (goto-char end)
7861 (setq end (point-marker))
7862 (goto-char cur-beg)
7863 (while (< (point) end)
7864 ;; is argument list opening?
7865 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7866 (point) (vhdl-point 'eol)))))
7867 ;; determine region for argument list
7868 (progn (goto-char cur-beg)
7869 (forward-sexp)
7870 (setq cur-end (point))
7871 (beginning-of-line 2))
7872 ;; determine region with same indent
7873 (setq indent (current-indentation))
7874 (setq cur-beg (point))
7875 (setq cur-end (vhdl-point 'bonl))
7876 (beginning-of-line 2)
7877 (while (and (< (point) end)
7878 (or (looking-at "^\\s-*\\(--.*\\)?$")
7879 (= (current-indentation) indent))
7880 (<= (save-excursion
7881 (nth 0 (parse-partial-sexp
7882 (point) (vhdl-point 'eol)))) 0))
7883 (unless (looking-at "^\\s-*$")
7884 (setq cur-end (vhdl-point 'bonl)))
7885 (beginning-of-line 2)))
7886 ;; align region
7887 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7888 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7889 (when vhdl-progress-interval (message "Aligning...done"))
7890 (setq vhdl-progress-info nil)))))
7892 (defun vhdl-align-group (&optional spacing)
7893 "Align group of lines between empty lines."
7894 (interactive)
7895 (vhdl-do-group 'vhdl-align-region spacing))
7897 (defun vhdl-align-list (&optional spacing)
7898 "Align the lines of a list surrounded by a balanced group of parentheses."
7899 (interactive)
7900 (vhdl-do-list 'vhdl-align-region-groups spacing))
7902 (defun vhdl-align-same-indent (&optional spacing)
7903 "Align block of lines with same indent."
7904 (interactive)
7905 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7907 (defun vhdl-align-declarations (&optional spacing)
7908 "Align the lines within the declarative part of a design unit."
7909 (interactive)
7910 (let (beg end)
7911 (vhdl-prepare-search-2
7912 (save-excursion
7913 ;; search for declarative part
7914 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|context\\|end\\|entity\\|package\\)\\>" nil t)
7915 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7916 (setq beg (point))
7917 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7918 (setq end (point)))))
7919 (if beg
7920 (vhdl-align-region-groups beg end spacing)
7921 (error "ERROR: Not within the declarative part of a design unit"))))
7923 (defun vhdl-align-buffer ()
7924 "Align buffer."
7925 (interactive)
7926 (vhdl-align-region (point-min) (point-max)))
7928 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7929 ;; Align inline comments
7931 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7932 "Align inline comments in region."
7933 (save-excursion
7934 (let ((start-max comment-column)
7935 (length-max 0)
7936 comment-list start-list tmp-list start length
7937 cur-start prev-start no-code)
7938 (setq spacing (or spacing 2))
7939 (vhdl-prepare-search-2
7940 (goto-char beg)
7941 ;; search for comment start positions and lengths
7942 (while (< (point) end)
7943 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7944 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7945 (not (save-excursion (goto-char (match-beginning 2))
7946 (vhdl-in-literal))))
7947 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7948 (setq length (- (match-end 2) (match-beginning 2)))
7949 (setq start-max (max start start-max))
7950 (setq length-max (max length length-max))
7951 (push (cons start length) comment-list))
7952 (beginning-of-line 2))
7953 (setq comment-list
7954 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7955 ;; reduce start positions
7956 (setq start-list (list (caar comment-list)))
7957 (setq comment-list (cdr comment-list))
7958 (while comment-list
7959 (unless (or (= (caar comment-list) (car start-list))
7960 (<= (+ (car start-list) (cdar comment-list))
7961 end-comment-column))
7962 (push (caar comment-list) start-list))
7963 (setq comment-list (cdr comment-list)))
7964 ;; align lines as nicely as possible
7965 (goto-char beg)
7966 (while (< (point) end)
7967 (setq cur-start nil)
7968 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7969 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7970 (not (save-excursion
7971 (goto-char (match-beginning 3))
7972 (vhdl-in-literal))))
7973 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7974 (>= (- (match-end 2) (match-beginning 2))
7975 comment-column))))
7976 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7977 (setq length (- (match-end 3) (match-beginning 3)))
7978 (setq no-code (= (match-beginning 1) (match-end 1)))
7979 ;; insert minimum whitespace
7980 (goto-char (match-end 2))
7981 (delete-region (match-beginning 2) (match-end 2))
7982 (insert-char ?\ spacing)
7983 (setq tmp-list start-list)
7984 ;; insert additional whitespace to align
7985 (setq cur-start
7986 (cond
7987 ;; align comment-only line to inline comment of previous line
7988 ((and no-code prev-start
7989 (<= length (- end-comment-column prev-start)))
7990 prev-start)
7991 ;; align all comments at `start-max' if this is possible
7992 ((<= (+ start-max length-max) end-comment-column)
7993 start-max)
7994 ;; align at `comment-column' if possible
7995 ((and (<= start comment-column)
7996 (<= length (- end-comment-column comment-column)))
7997 comment-column)
7998 ;; align at left-most possible start position otherwise
8000 (while (and tmp-list (< (car tmp-list) start))
8001 (setq tmp-list (cdr tmp-list)))
8002 (car tmp-list))))
8003 (indent-to cur-start))
8004 (setq prev-start cur-start)
8005 (beginning-of-line 2))))))
8007 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
8008 "Align inline comments within a region. Groups of code lines separated by
8009 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8010 (interactive "r\nP")
8011 (save-excursion
8012 (let (orig pos)
8013 (goto-char beg)
8014 (beginning-of-line)
8015 (setq orig (point-marker))
8016 (setq beg (point))
8017 (goto-char end)
8018 (setq end (point-marker))
8019 (untabify beg end)
8020 (unless no-message (message "Aligning inline comments..."))
8021 (goto-char beg)
8022 (if (not vhdl-align-groups)
8023 ;; align entire region
8024 (vhdl-align-inline-comment-region-1 beg end spacing)
8025 ;; align groups
8026 (while (and (< beg end)
8027 (re-search-forward vhdl-align-group-separate end t))
8028 (setq pos (point-marker))
8029 (vhdl-align-inline-comment-region-1 beg pos spacing)
8030 (setq beg (1+ pos))
8031 (goto-char beg))
8032 ;; align last group
8033 (when (< beg end)
8034 (vhdl-align-inline-comment-region-1 beg end spacing)))
8035 (when vhdl-indent-tabs-mode
8036 (tabify orig end))
8037 (unless no-message (message "Aligning inline comments...done")))))
8039 (defun vhdl-align-inline-comment-group (&optional spacing)
8040 "Align inline comments within a group of lines between empty lines."
8041 (interactive)
8042 (save-excursion
8043 (let ((start (point))
8044 beg end)
8045 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
8046 (point-marker) (point-max)))
8047 (goto-char start)
8048 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
8049 (point) (point-min)))
8050 (untabify beg end)
8051 (message "Aligning inline comments...")
8052 (vhdl-align-inline-comment-region-1 beg end)
8053 (when vhdl-indent-tabs-mode
8054 (tabify beg end))
8055 (message "Aligning inline comments...done"))))
8057 (defun vhdl-align-inline-comment-buffer ()
8058 "Align inline comments within buffer. Groups of code lines separated by
8059 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8060 (interactive)
8061 (vhdl-align-inline-comment-region (point-min) (point-max)))
8063 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8064 ;; Fixup whitespace
8066 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
8067 "Fixup whitespace in region. Surround operator symbols by one space,
8068 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8069 end of line, do nothing in comments and strings."
8070 (interactive "r")
8071 (unless no-message (message "Fixing up whitespace..."))
8072 (save-excursion
8073 (goto-char end)
8074 (setq end (point-marker))
8075 ;; have no space before and one space after `,' and ';'
8076 (goto-char beg)
8077 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
8078 (if (match-string 1)
8079 (goto-char (match-end 1))
8080 (replace-match "\\3 " nil nil nil 2)))
8081 ;; have no space after `('
8082 (goto-char beg)
8083 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
8084 (if (match-string 1)
8085 (goto-char (match-end 1))
8086 (replace-match "\\2")))
8087 ;; have no space before `)'
8088 (goto-char beg)
8089 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
8090 (if (match-string 1)
8091 (goto-char (match-end 1))
8092 (replace-match "\\2")))
8093 ;; surround operator symbols by one space
8094 (goto-char beg)
8095 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
8096 (if (or (match-string 1)
8097 (<= (match-beginning 0) ; not if at boi
8098 (save-excursion (back-to-indentation) (point))))
8099 (goto-char (match-end 0))
8100 (replace-match "\\3 \\4 \\5")
8101 (goto-char (match-end 2))))
8102 ;; eliminate multiple spaces and spaces at end of line
8103 (goto-char beg)
8104 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
8105 (and (looking-at "--.*") (re-search-forward "--.*" end t))
8106 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
8107 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
8108 (progn (replace-match "" nil nil) t))
8109 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
8110 (progn (replace-match ";" nil nil) t))
8111 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
8112 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
8113 (progn (replace-match " " nil nil) t))
8114 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
8115 (progn (replace-match " " nil nil) t))
8116 (and (looking-at "-") (re-search-forward "-" end t))
8117 (re-search-forward "[^ \t\"-]+" end t))))
8118 (unless no-message (message "Fixing up whitespace...done")))
8120 (defun vhdl-fixup-whitespace-buffer ()
8121 "Fixup whitespace in buffer. Surround operator symbols by one space,
8122 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8123 end of line, do nothing in comments."
8124 (interactive)
8125 (vhdl-fixup-whitespace-region (point-min) (point-max)))
8127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8128 ;; Case fixing
8130 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
8131 "Convert all words matching WORD-REGEXP in region to lower or upper case,
8132 depending on parameter UPPER-CASE."
8133 (let ((case-replace nil)
8134 (last-update 0))
8135 (vhdl-prepare-search-2
8136 (save-excursion
8137 (goto-char end)
8138 (setq end (point-marker))
8139 (goto-char beg)
8140 (while (re-search-forward word-regexp end t)
8141 (or (vhdl-in-literal)
8142 (if upper-case
8143 (upcase-word -1)
8144 (downcase-word -1)))
8145 (when (and count vhdl-progress-interval (not noninteractive)
8146 (< vhdl-progress-interval
8147 (- (nth 1 (current-time)) last-update)))
8148 (message "Fixing case... (%2d%s)"
8149 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
8150 "%")
8151 (setq last-update (nth 1 (current-time)))))
8152 (goto-char end)))))
8154 (defun vhdl-fix-case-region (beg end &optional arg)
8155 "Convert all VHDL words in region to lower or upper case, depending on
8156 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8157 (interactive "r\nP")
8158 (vhdl-fix-case-region-1
8159 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
8160 (vhdl-fix-case-region-1
8161 beg end vhdl-upper-case-types vhdl-types-regexp 1)
8162 (vhdl-fix-case-region-1
8163 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
8164 (vhdl-fix-case-region-1
8165 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
8166 (vhdl-fix-case-region-1
8167 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
8168 (when vhdl-progress-interval (message "Fixing case...done")))
8170 (defun vhdl-fix-case-buffer ()
8171 "Convert all VHDL words in buffer to lower or upper case, depending on
8172 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8173 (interactive)
8174 (vhdl-fix-case-region (point-min) (point-max)))
8176 (defun vhdl-fix-case-word (&optional arg)
8177 "Convert word after cursor to upper case if necessary."
8178 (interactive "p")
8179 (save-excursion
8180 (when arg (backward-word 1))
8181 (vhdl-prepare-search-1
8182 (when (and vhdl-upper-case-keywords
8183 (looking-at vhdl-keywords-regexp))
8184 (upcase-word 1))
8185 (when (and vhdl-upper-case-types
8186 (looking-at vhdl-types-regexp))
8187 (upcase-word 1))
8188 (when (and vhdl-upper-case-attributes
8189 (looking-at vhdl-attributes-regexp))
8190 (upcase-word 1))
8191 (when (and vhdl-upper-case-enum-values
8192 (looking-at vhdl-enum-values-regexp))
8193 (upcase-word 1))
8194 (when (and vhdl-upper-case-constants
8195 (looking-at vhdl-constants-regexp))
8196 (upcase-word 1)))))
8198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8199 ;; Fix statements
8200 ;; - force each statement to be on a separate line except when on same line
8201 ;; with 'end' keyword
8203 (defun vhdl-fix-statement-region (beg end &optional arg)
8204 "Force statements in region on separate line except when on same line
8205 with `end' keyword (necessary for correct indentation).
8206 Currently supported keywords: `begin', `if'."
8207 (interactive "r\nP")
8208 (vhdl-prepare-search-2
8209 (let (point)
8210 (save-excursion
8211 (goto-char end)
8212 (setq end (point-marker))
8213 (goto-char beg)
8214 ;; `begin' keyword
8215 (while (re-search-forward
8216 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
8217 (goto-char (match-end 0))
8218 (setq point (point-marker))
8219 (when (and (match-string 1)
8220 (or (not (match-string 2))
8221 (save-excursion (goto-char (match-end 2))
8222 (vhdl-in-literal)))
8223 (not (save-excursion (goto-char (match-beginning 1))
8224 (vhdl-in-literal))))
8225 (goto-char (match-beginning 1))
8226 (insert "\n")
8227 (indent-according-to-mode))
8228 (goto-char point))
8229 (goto-char beg)
8230 ;; `for', `if' keywords
8231 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
8232 (goto-char (match-end 1))
8233 (setq point (point-marker))
8234 ;; exception: in literal or preceded by `end', `wait' or label
8235 (when (and (not (save-excursion (goto-char (match-beginning 1))
8236 (vhdl-in-literal)))
8237 (save-excursion
8238 (beginning-of-line 1)
8239 (save-match-data
8240 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8241 (match-beginning 1) t)
8242 (not (string-match
8243 "\\(\\<end\\>\\|\\<wait .*\\|\\w+\\s-*:\\)\\s-*$"
8244 (match-string 1)))))))
8245 (goto-char (match-beginning 1))
8246 (insert "\n")
8247 (indent-according-to-mode))
8248 (goto-char point))))))
8250 (defun vhdl-fix-statement-buffer ()
8251 "Force statements in buffer on separate line except when on same line
8252 with `end' keyword (necessary for correct indentation)."
8253 (interactive)
8254 (vhdl-fix-statement-region (point-min) (point-max)))
8256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8257 ;; Trailing spaces
8259 (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
8260 "Remove trailing spaces in region."
8261 (interactive "r\nP")
8262 (save-excursion
8263 (goto-char end)
8264 (setq end (point-marker))
8265 (goto-char beg)
8266 (while (re-search-forward "[ \t]+$" end t)
8267 (unless (vhdl-in-literal)
8268 (replace-match "" nil nil)))))
8270 (defun vhdl-remove-trailing-spaces ()
8271 "Remove trailing spaces in buffer."
8272 (interactive)
8273 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8276 ;; Beautify
8278 (defun vhdl-beautify-region (beg end)
8279 "Beautify region by applying indentation, whitespace fixup, alignment, and
8280 case fixing to a region. Calls functions `vhdl-indent-buffer',
8281 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8282 `vhdl-fix-case-buffer'."
8283 (interactive "r")
8284 (setq end (save-excursion (goto-char end) (point-marker)))
8285 (save-excursion ; remove DOS EOL characters in UNIX file
8286 (goto-char beg)
8287 (while (search-forward "\r" nil t)
8288 (replace-match "" nil t)))
8289 (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
8290 (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
8291 (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
8292 (when (nth 3 vhdl-beautify-options)
8293 (let ((vhdl-align-groups t)) (vhdl-align-region beg end)))
8294 (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
8295 (when (nth 0 vhdl-beautify-options)
8296 (vhdl-remove-trailing-spaces-region beg end)
8297 (if vhdl-indent-tabs-mode (tabify beg end) (untabify beg end))))
8299 (defun vhdl-beautify-buffer ()
8300 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8301 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8302 buffer."
8303 (interactive)
8304 (vhdl-beautify-region (point-min) (point-max))
8305 (when noninteractive (save-buffer)))
8307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8308 ;; Code filling
8310 (defun vhdl-fill-region (beg end &optional arg)
8311 "Fill lines for a region of code."
8312 (interactive "r\np")
8313 (save-excursion
8314 (goto-char beg)
8315 (let ((margin (if arg (current-indentation) (current-column))))
8316 (goto-char end)
8317 (setq end (point-marker))
8318 ;; remove inline comments, newlines and whitespace
8319 (vhdl-comment-kill-region beg end)
8320 (vhdl-comment-kill-inline-region beg end)
8321 (subst-char-in-region beg (1- end) ?\n ?\ )
8322 (vhdl-fixup-whitespace-region beg end)
8323 ;; wrap and end-comment-column
8324 (goto-char beg)
8325 (while (re-search-forward "\\s-" end t)
8326 (when(> (current-column) vhdl-end-comment-column)
8327 (backward-char)
8328 (when (re-search-backward "\\s-" beg t)
8329 (replace-match "\n")
8330 (indent-to margin)))))))
8332 (defun vhdl-fill-group ()
8333 "Fill group of lines between empty lines."
8334 (interactive)
8335 (vhdl-do-group 'vhdl-fill-region))
8337 (defun vhdl-fill-list ()
8338 "Fill the lines of a list surrounded by a balanced group of parentheses."
8339 (interactive)
8340 (vhdl-do-list 'vhdl-fill-region))
8342 (defun vhdl-fill-same-indent ()
8343 "Fill the lines of block of lines with same indent."
8344 (interactive)
8345 (vhdl-do-same-indent 'vhdl-fill-region))
8348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8349 ;;; Code updating/fixing
8350 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8352 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8353 ;; Sensitivity list update
8355 ;; Strategy:
8356 ;; - no sensitivity list is generated for processes with wait statements
8357 ;; - otherwise, do the following:
8358 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8359 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8360 ;; manually entered global signals)
8361 ;; 3. signals from 1. and 2. form the list of visible signals
8362 ;; 4. search for if/elsif conditions containing an event (sequential code)
8363 ;; 5. scan for strings that are within syntactical regions where signals are
8364 ;; read but not within sequential code, and that correspond to visible
8365 ;; signals
8366 ;; 6. replace sensitivity list by list of signals from 5.
8368 (defun vhdl-update-sensitivity-list-process ()
8369 "Update sensitivity list of current process."
8370 (interactive)
8371 (save-excursion
8372 (vhdl-prepare-search-2
8373 (end-of-line)
8374 ;; look whether in process
8375 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8376 (equal (upcase (match-string 2)) "PROCESS")
8377 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8378 (error "ERROR: Not within a process")
8379 (message "Updating sensitivity list...")
8380 (vhdl-update-sensitivity-list)
8381 (message "Updating sensitivity list...done")))))
8383 (defun vhdl-update-sensitivity-list-buffer ()
8384 "Update sensitivity list of all processes in current buffer."
8385 (interactive)
8386 (save-excursion
8387 (vhdl-prepare-search-2
8388 (goto-char (point-min))
8389 (message "Updating sensitivity lists...")
8390 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8391 (goto-char (match-beginning 0))
8392 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8393 (message "Updating sensitivity lists...done")))
8394 (when noninteractive (save-buffer)))
8396 (defun vhdl-update-sensitivity-list ()
8397 "Update sensitivity list."
8398 (let ((proc-beg (point))
8399 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8400 (proc-mid (vhdl-re-search-backward
8401 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8402 seq-region-list)
8403 (cond
8404 ;; error if 'begin' keyword missing
8405 ((not (match-string 2))
8406 (error "ERROR: No 'begin' keyword found"))
8407 ;; search for wait statement (no sensitivity list allowed)
8408 ((progn (goto-char proc-mid)
8409 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8410 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8411 ;; combinational process (update sensitivity list)
8413 (let
8414 ;; scan for visible signals
8415 ((visible-list (vhdl-get-visible-signals))
8416 ;; define syntactic regions where signals are read
8417 (scan-regions-list
8418 '(;; right-hand side of signal/variable assignment
8419 ;; (special case: "<=" is relational operator in a condition)
8420 ((vhdl-re-search-forward "[<:]=" proc-end t)
8421 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8422 ;; if condition
8423 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
8424 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8425 ;; elsif condition
8426 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
8427 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8428 ;; while loop condition
8429 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
8430 (vhdl-re-search-forward "\\<loop\\>" proc-end t))
8431 ;; exit/next condition
8432 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8433 (vhdl-re-search-forward ";" proc-end t))
8434 ;; assert condition
8435 ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
8436 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8437 ;; case expression
8438 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
8439 (vhdl-re-search-forward "\\<is\\>" proc-end t))
8440 ;; parameter list of procedure call, array index
8441 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8442 (1- (point)))
8443 (progn (backward-char) (forward-sexp)
8444 (while (looking-at "(") (forward-sexp)) (point)))))
8445 name field read-list sens-list signal-list tmp-list
8446 sens-beg sens-end beg end margin)
8447 ;; scan for signals in old sensitivity list
8448 (goto-char proc-beg)
8449 (vhdl-re-search-forward "\\<process\\>" proc-mid t)
8450 (if (not (looking-at "[ \t\n\r\f]*("))
8451 (setq sens-beg (point))
8452 (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8453 (goto-char (match-end 1))
8454 (forward-sexp)
8455 (setq sens-end (1- (point)))
8456 (goto-char sens-beg)
8457 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
8458 (setq sens-list
8459 (cons (downcase (match-string 0)) sens-list))
8460 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
8461 (setq signal-list (append visible-list sens-list))
8462 ;; search for sequential parts
8463 (goto-char proc-mid)
8464 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8465 (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
8466 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8467 (goto-char end)
8468 (backward-word-strictly 1)
8469 (vhdl-forward-sexp)
8470 (push (cons end (point)) seq-region-list)
8471 (beginning-of-line)))
8472 ;; scan for signals read in process
8473 (while scan-regions-list
8474 (goto-char proc-mid)
8475 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8476 (setq end (eval (nth 1 (car scan-regions-list)))))
8477 (goto-char beg)
8478 (unless (or (vhdl-in-literal)
8479 (and seq-region-list
8480 (let ((tmp-list seq-region-list))
8481 (while (and tmp-list
8482 (< (point) (caar tmp-list)))
8483 (setq tmp-list (cdr tmp-list)))
8484 (and tmp-list (< (point) (cdar tmp-list))))))
8485 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8486 (setq name (match-string 1))
8487 ;; get array index range
8488 (when vhdl-array-index-record-field-in-sensitivity-list
8489 (setq field (match-string 2))
8490 ;; not use if it includes a variable name
8491 (save-match-data
8492 (setq tmp-list visible-list)
8493 (while (and field tmp-list)
8494 (when (string-match
8495 (concat "\\<" (car tmp-list) "\\>") field)
8496 (setq field nil))
8497 (setq tmp-list (cdr tmp-list)))))
8498 (when (and (not (match-string 6)) ; not when formal parameter
8499 (not (and (match-string 5) ; not event attribute
8500 (not (member (downcase (match-string 5))
8501 '("event" "last_event" "transaction")))))
8502 (member (downcase name) signal-list))
8503 ;; not add if name or name+field already exists
8504 (unless
8505 (or (member-ignore-case name read-list)
8506 (member-ignore-case (concat name field) read-list))
8507 (push (concat name field) read-list))
8508 (setq tmp-list read-list)
8509 ;; remove existing name+field if name is added
8510 (save-match-data
8511 (while tmp-list
8512 (when (string-match (concat "^" name field "[(.]")
8513 (car tmp-list))
8514 (setq read-list (delete (car tmp-list) read-list)))
8515 (setq tmp-list (cdr tmp-list)))))
8516 (goto-char (match-end 1)))))
8517 (setq scan-regions-list (cdr scan-regions-list)))
8518 ;; update sensitivity list
8519 (goto-char sens-beg)
8520 (if sens-end
8521 (delete-region sens-beg sens-end)
8522 (when read-list
8523 (insert " ()") (backward-char)))
8524 (setq read-list (sort read-list 'string<))
8525 (when read-list
8526 (setq margin (current-column))
8527 (insert (car read-list))
8528 (setq read-list (cdr read-list))
8529 (while read-list
8530 (insert ",")
8531 (if (<= (+ (current-column) (length (car read-list)) 2)
8532 end-comment-column)
8533 (insert " ")
8534 (insert "\n") (indent-to margin))
8535 (insert (car read-list))
8536 (setq read-list (cdr read-list)))))))))
8538 (defun vhdl-get-visible-signals ()
8539 "Get all signals visible in the current block."
8540 (let (beg end signal-list entity-name file-name)
8541 (vhdl-prepare-search-2
8542 ;; get entity name
8543 (save-excursion
8544 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8545 (not (equal "END" (upcase (match-string 1))))
8546 (setq entity-name (match-string 2)))
8547 (error "ERROR: Not within an architecture")))
8548 ;; search for signals declared in entity port clause
8549 (save-excursion
8550 (goto-char (point-min))
8551 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8552 (setq file-name
8553 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8554 "." (file-name-extension (buffer-file-name)))))
8555 (vhdl-visit-file
8556 file-name t
8557 (vhdl-prepare-search-2
8558 (goto-char (point-min))
8559 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8560 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8561 (when (setq beg (vhdl-re-search-forward
8562 "\\<port[ \t\n\r\f]*("
8563 (save-excursion
8564 (re-search-forward "^end\\>" nil t)) t))
8565 (setq end (save-excursion
8566 (backward-char) (forward-sexp) (point)))
8567 (vhdl-forward-syntactic-ws)
8568 (while (< (point) end)
8569 (when (looking-at "signal[ \t\n\r\f]+")
8570 (goto-char (match-end 0)))
8571 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8572 (setq signal-list
8573 (cons (downcase (match-string 1)) signal-list))
8574 (goto-char (match-end 0))
8575 (vhdl-forward-syntactic-ws))
8576 (re-search-forward ";" end 1)
8577 (vhdl-forward-syntactic-ws)))))))
8578 ;; search for signals declared in architecture declarative part
8579 (save-excursion
8580 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8581 (not (equal "END" (upcase (match-string 1))))
8582 (setq end (re-search-forward "^begin\\>" nil t))))
8583 (error "ERROR: No architecture declarative part found")
8584 ;; scan for all declared signal and alias names
8585 (goto-char beg)
8586 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8587 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8588 (if (match-string 2)
8589 ;; scan signal name
8590 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8591 (setq signal-list
8592 (cons (downcase (match-string 1)) signal-list))
8593 (goto-char (match-end 0)))
8594 ;; scan alias name, check is alias of (declared) signal
8595 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8596 (member (downcase (match-string 2)) signal-list))
8597 (setq signal-list
8598 (cons (downcase (match-string 1)) signal-list))
8599 (goto-char (match-end 0))))
8600 (setq beg (point))))))
8601 ;; search for signals declared in surrounding block declarative parts
8602 (save-excursion
8603 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*\\(block\\|\\(for\\|if\\).*\\<generate\\>\\)\\|\\(end\\)\\s-+block\\)\\>" nil t))
8604 (match-string 4))
8605 (goto-char (match-end 4))
8606 (vhdl-backward-sexp)
8607 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*\\(block\\|generate\\)\\>" nil t))
8608 beg)
8609 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8610 ;; scan for all declared signal names
8611 (goto-char beg)
8612 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8613 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8614 (if (match-string 2)
8615 ;; scan signal name
8616 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8617 (setq signal-list
8618 (cons (downcase (match-string 1)) signal-list))
8619 (goto-char (match-end 0)))
8620 ;; scan alias name, check is alias of (declared) signal
8621 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8622 (member (downcase (match-string 2)) signal-list))
8623 (setq signal-list
8624 (cons (downcase (match-string 1)) signal-list))
8625 (goto-char (match-end 0))))))
8626 (goto-char beg)))
8627 signal-list)))
8629 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8630 ;; Generic/port clause fixing
8632 (defun vhdl-fix-clause-buffer ()
8633 "Fix all generic/port clauses in current buffer."
8634 (interactive)
8635 (save-excursion
8636 (vhdl-prepare-search-2
8637 (goto-char (point-min))
8638 (message "Fixing generic/port clauses...")
8639 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8640 (goto-char (match-end 0))
8641 (condition-case nil (vhdl-fix-clause) (error "")))
8642 (message "Fixing generic/port clauses...done"))))
8644 (defun vhdl-fix-clause ()
8645 "Fix closing parenthesis within generic/port clause."
8646 (interactive)
8647 (save-excursion
8648 (vhdl-prepare-search-2
8649 (let ((pos (point))
8650 beg end)
8651 (end-of-line)
8652 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8653 (error "ERROR: Not within a generic/port clause")
8654 ;; search for end of clause
8655 (goto-char (match-end 0))
8656 (setq beg (1- (point)))
8657 (vhdl-forward-syntactic-ws)
8658 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8659 (goto-char (1- (match-end 0)))
8660 (setq end (point-marker))
8661 (forward-char)
8662 (vhdl-forward-syntactic-ws))
8663 (goto-char end)
8664 (when (> pos (point-at-eol))
8665 (error "ERROR: Not within a generic/port clause"))
8666 ;; delete closing parenthesis on separate line (not supported style)
8667 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8668 (vhdl-line-kill)
8669 (vhdl-backward-syntactic-ws)
8670 (setq end (point-marker))
8671 (insert ";"))
8672 ;; delete superfluous parentheses
8673 (while (progn (goto-char beg)
8674 (condition-case () (forward-sexp)
8675 (error (goto-char (point-max))))
8676 (< (point) end))
8677 (delete-char -1))
8678 ;; add closing parenthesis
8679 (when (> (point) end)
8680 (goto-char end)
8681 (insert ")")))))))
8684 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8685 ;;; Electrification
8686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8688 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8689 "Syntax of prompt inserted by template generators.")
8691 (defvar vhdl-template-invoked-by-hook nil
8692 "Indicates whether a template has been invoked by a hook or by key or menu.
8693 Used for undoing after template abortion.")
8695 ;; correct different behavior of function `unread-command-events' in XEmacs
8696 (defun vhdl-character-to-event (arg))
8697 (defalias 'vhdl-character-to-event
8698 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8700 (defun vhdl-work-library ()
8701 "Return the working library name of the current project or \"work\" if no
8702 project is defined."
8703 (vhdl-resolve-env-variable
8704 (or (nth 6 (vhdl-aget vhdl-project-alist vhdl-project))
8705 vhdl-default-library)))
8707 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8708 ;; Enabling/disabling
8710 (define-minor-mode vhdl-electric-mode
8711 "Toggle VHDL electric mode.
8712 With a prefix argument ARG, enable the mode if ARG is positive,
8713 and disable it otherwise. If called from Lisp, enable it if ARG
8714 is omitted or nil."
8715 :global t :group 'vhdl-mode)
8717 (define-minor-mode vhdl-stutter-mode
8718 "Toggle VHDL stuttering mode.
8719 With a prefix argument ARG, enable the mode if ARG is positive,
8720 and disable it otherwise. If called from Lisp, enable it if ARG
8721 is omitted or nil."
8722 :global t :group 'vhdl-mode)
8724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8725 ;; Stuttering
8727 (defun vhdl-electric-dash (count)
8728 "-- starts a comment, --- draws a horizontal line,
8729 ---- starts a display comment."
8730 (interactive "p")
8731 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8732 (cond
8733 ((and abbrev-start-location (= abbrev-start-location (point)))
8734 (setq abbrev-start-location nil)
8735 (goto-char last-abbrev-location)
8736 (beginning-of-line nil)
8737 (vhdl-comment-display))
8738 ((/= (preceding-char) ?-) ; standard dash (minus)
8739 (self-insert-command count))
8740 (t (self-insert-command count)
8741 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8742 (let ((next-input (read-char)))
8743 (if (= next-input ?-) ; triple dash
8744 (progn
8745 (vhdl-comment-display-line)
8746 (message
8747 "Enter '-' for display comment, else continue coding")
8748 (let ((next-input (read-char)))
8749 (if (= next-input ?-) ; four dashes
8750 (vhdl-comment-display t)
8751 (push (vhdl-character-to-event next-input)
8752 ; pushback the char
8753 unread-command-events))))
8754 (push (vhdl-character-to-event next-input) ; pushback the char
8755 unread-command-events)
8756 (vhdl-comment-insert)))))
8757 (self-insert-command count)))
8759 (defun vhdl-electric-open-bracket (count) "`[' --> `(', `([' --> `['"
8760 (interactive "p")
8761 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8762 (if (= (preceding-char) ?\()
8763 (progn (delete-char -1) (insert-char ?\[ 1))
8764 (insert-char ?\( 1))
8765 (self-insert-command count)))
8767 (defun vhdl-electric-close-bracket (count) "`]' --> `)', `)]' --> `]'"
8768 (interactive "p")
8769 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8770 (progn
8771 (if (= (preceding-char) ?\))
8772 (progn (delete-char -1) (insert-char ?\] 1))
8773 (insert-char ?\) 1))
8774 (blink-matching-open))
8775 (self-insert-command count)))
8777 (defun vhdl-electric-quote (count) "\\='\\=' --> \""
8778 (interactive "p")
8779 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8780 (if (= (preceding-char) vhdl-last-input-event)
8781 (progn (delete-char -1) (insert-char ?\" 1))
8782 (insert-char ?\' 1))
8783 (self-insert-command count)))
8785 (defun vhdl-electric-semicolon (count) "`;;' --> ` : ', `: ;' --> ` := '"
8786 (interactive "p")
8787 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8788 (cond ((= (preceding-char) vhdl-last-input-event)
8789 (progn (delete-char -1)
8790 (unless (eq (preceding-char) ? ) (insert " "))
8791 (insert ": ")
8792 (setq this-command 'vhdl-electric-colon)))
8793 ((and
8794 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8795 (progn (delete-char -1) (insert "= ")))
8796 (t (insert-char ?\; 1)))
8797 (self-insert-command count)))
8799 (defun vhdl-electric-comma (count) "`,,' --> ` <= '"
8800 (interactive "p")
8801 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8802 (cond ((= (preceding-char) vhdl-last-input-event)
8803 (progn (delete-char -1)
8804 (unless (eq (preceding-char) ? ) (insert " "))
8805 (insert "<= ")))
8806 (t (insert-char ?\, 1)))
8807 (self-insert-command count)))
8809 (defun vhdl-electric-period (count) "`..' --> ` => '"
8810 (interactive "p")
8811 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8812 (cond ((= (preceding-char) vhdl-last-input-event)
8813 (progn (delete-char -1)
8814 (unless (eq (preceding-char) ? ) (insert " "))
8815 (insert "=> ")))
8816 (t (insert-char ?\. 1)))
8817 (self-insert-command count)))
8819 (defun vhdl-electric-equal (count) "`==' --> ` == '"
8820 (interactive "p")
8821 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8822 (cond ((= (preceding-char) vhdl-last-input-event)
8823 (progn (delete-char -1)
8824 (unless (eq (preceding-char) ? ) (insert " "))
8825 (insert "== ")))
8826 (t (insert-char ?\= 1)))
8827 (self-insert-command count)))
8829 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8830 ;; VHDL templates
8832 (defun vhdl-template-paired-parens ()
8833 "Insert a pair of round parentheses, placing point between them."
8834 (interactive)
8835 (insert "()")
8836 (backward-char))
8838 (defun vhdl-template-alias ()
8839 "Insert alias declaration."
8840 (interactive)
8841 (let ((start (point)))
8842 (vhdl-insert-keyword "ALIAS ")
8843 (when (vhdl-template-field "name" nil t start (point))
8844 (insert " : ")
8845 (unless (vhdl-template-field
8846 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8847 nil t)
8848 (delete-char -3))
8849 (vhdl-insert-keyword " IS ")
8850 (vhdl-template-field "name" ";")
8851 (vhdl-comment-insert-inline))))
8853 (defun vhdl-template-architecture ()
8854 "Insert architecture."
8855 (interactive)
8856 (let ((margin (current-indentation))
8857 (start (point))
8858 arch-name)
8859 (vhdl-insert-keyword "ARCHITECTURE ")
8860 (when (setq arch-name
8861 (vhdl-template-field "name" nil t start (point)))
8862 (vhdl-insert-keyword " OF ")
8863 (if (save-excursion
8864 (vhdl-prepare-search-1
8865 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8866 (insert (match-string 1))
8867 (vhdl-template-field "entity name"))
8868 (vhdl-insert-keyword " IS\n")
8869 (vhdl-template-begin-end
8870 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8871 (memq vhdl-insert-empty-lines '(unit all))))))
8873 (defun vhdl-template-array (kind &optional secondary)
8874 "Insert array type definition."
8875 (interactive)
8876 (let ((start (point)))
8877 (vhdl-insert-keyword "ARRAY (")
8878 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8879 secondary)
8880 (vhdl-insert-keyword ") OF ")
8881 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8882 (vhdl-insert-keyword ";"))))
8884 (defun vhdl-template-assert ()
8885 "Insert an assertion statement."
8886 (interactive)
8887 (let ((start (point)))
8888 (vhdl-insert-keyword "ASSERT ")
8889 (when vhdl-conditions-in-parenthesis (insert "("))
8890 (when (vhdl-template-field "condition (negated)" nil t start (point))
8891 (when vhdl-conditions-in-parenthesis (insert ")"))
8892 (setq start (point))
8893 (vhdl-insert-keyword " REPORT ")
8894 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8895 (delete-region start (point)))
8896 (setq start (point))
8897 (vhdl-insert-keyword " SEVERITY ")
8898 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8899 (delete-region start (point)))
8900 (insert ";"))))
8902 (defun vhdl-template-attribute ()
8903 "Insert an attribute declaration or specification."
8904 (interactive)
8905 (if (eq (vhdl-decision-query
8906 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8907 (vhdl-template-attribute-spec)
8908 (vhdl-template-attribute-decl)))
8910 (defun vhdl-template-attribute-decl ()
8911 "Insert an attribute declaration."
8912 (interactive)
8913 (let ((start (point)))
8914 (vhdl-insert-keyword "ATTRIBUTE ")
8915 (when (vhdl-template-field "name" " : " t start (point))
8916 (vhdl-template-field "type" ";")
8917 (vhdl-comment-insert-inline))))
8919 (defun vhdl-template-attribute-spec ()
8920 "Insert an attribute specification."
8921 (interactive)
8922 (let ((start (point)))
8923 (vhdl-insert-keyword "ATTRIBUTE ")
8924 (when (vhdl-template-field "name" nil t start (point))
8925 (vhdl-insert-keyword " OF ")
8926 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8927 (vhdl-template-field "entity class")
8928 (vhdl-insert-keyword " IS ")
8929 (vhdl-template-field "expression" ";"))))
8931 (defun vhdl-template-block ()
8932 "Insert a block."
8933 (interactive)
8934 (let ((margin (current-indentation))
8935 (start (point))
8936 label)
8937 (vhdl-insert-keyword ": BLOCK ")
8938 (goto-char start)
8939 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8940 (forward-word-strictly 1)
8941 (forward-char 1)
8942 (insert "(")
8943 (if (vhdl-template-field "[guard expression]" nil t)
8944 (insert ")")
8945 (delete-char -2))
8946 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8947 (insert "\n")
8948 (vhdl-template-begin-end "BLOCK" label margin)
8949 (vhdl-comment-block))))
8951 (defun vhdl-template-block-configuration ()
8952 "Insert a block configuration statement."
8953 (interactive)
8954 (let ((margin (current-indentation))
8955 (start (point)))
8956 (vhdl-insert-keyword "FOR ")
8957 (when (vhdl-template-field "block name" nil t start (point))
8958 (vhdl-insert-keyword "\n\n")
8959 (indent-to margin)
8960 (vhdl-insert-keyword "END FOR;")
8961 (end-of-line 0)
8962 (indent-to (+ margin vhdl-basic-offset)))))
8964 (defun vhdl-template-break ()
8965 "Insert a break statement."
8966 (interactive)
8967 (let (position)
8968 (vhdl-insert-keyword "BREAK")
8969 (setq position (point))
8970 (insert " ")
8971 (while (or
8972 (progn (vhdl-insert-keyword "FOR ")
8973 (if (vhdl-template-field "[quantity name]" " USE " t)
8974 (progn (vhdl-template-field "quantity name" " => ") t)
8975 (delete-region (point)
8976 (progn (forward-word-strictly -1) (point)))
8977 nil))
8978 (vhdl-template-field "[quantity name]" " => " t))
8979 (vhdl-template-field "expression")
8980 (setq position (point))
8981 (insert ", "))
8982 (delete-region position (point))
8983 (unless (vhdl-sequential-statement-p)
8984 (vhdl-insert-keyword " ON ")
8985 (if (vhdl-template-field "[sensitivity list]" nil t)
8986 (setq position (point))
8987 (delete-region position (point))))
8988 (vhdl-insert-keyword " WHEN ")
8989 (when vhdl-conditions-in-parenthesis (insert "("))
8990 (if (vhdl-template-field "[condition]" nil t)
8991 (when vhdl-conditions-in-parenthesis (insert ")"))
8992 (delete-region position (point)))
8993 (insert ";")))
8995 (defun vhdl-template-case (&optional kind)
8996 "Insert a case statement."
8997 (interactive)
8998 (let ((margin (current-indentation))
8999 (start (point))
9000 label)
9001 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
9002 (not (vhdl-standard-p 'ams))) 'is 'use)))
9003 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9004 (vhdl-insert-keyword "CASE ")
9005 (vhdl-insert-keyword ": CASE ")
9006 (goto-char start)
9007 (setq label (vhdl-template-field "[label]" nil t))
9008 (unless label (delete-char 2))
9009 (forward-word-strictly 1)
9010 (forward-char 1))
9011 (when (vhdl-template-field "expression" nil t start (point))
9012 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
9013 (indent-to margin)
9014 (vhdl-insert-keyword "END CASE")
9015 (when label (insert " " label))
9016 (insert ";")
9017 (forward-line -1)
9018 (indent-to (+ margin vhdl-basic-offset))
9019 (vhdl-insert-keyword "WHEN ")
9020 (let ((position (point)))
9021 (insert " => ;\n")
9022 (indent-to (+ margin vhdl-basic-offset))
9023 (vhdl-insert-keyword "WHEN OTHERS => null;")
9024 (goto-char position)))))
9026 (defun vhdl-template-case-is ()
9027 "Insert a sequential case statement."
9028 (interactive)
9029 (vhdl-template-case 'is))
9031 (defun vhdl-template-case-use ()
9032 "Insert a simultaneous case statement."
9033 (interactive)
9034 (vhdl-template-case 'use))
9036 (defun vhdl-template-component ()
9037 "Insert a component declaration."
9038 (interactive)
9039 (vhdl-template-component-decl))
9041 (defun vhdl-template-component-conf ()
9042 "Insert a component configuration (uses `vhdl-template-configuration-spec'
9043 since these are almost equivalent)."
9044 (interactive)
9045 (let ((margin (current-indentation))
9046 (result (vhdl-template-configuration-spec t)))
9047 (when result
9048 (insert "\n")
9049 (indent-to margin)
9050 (vhdl-insert-keyword "END FOR;")
9051 (when (eq result 'no-use)
9052 (end-of-line -0)))))
9054 (defun vhdl-template-component-decl ()
9055 "Insert a component declaration."
9056 (interactive)
9057 (let ((margin (current-indentation))
9058 (start (point))
9059 name end-column)
9060 (vhdl-insert-keyword "COMPONENT ")
9061 (when (setq name (vhdl-template-field "name" nil t start (point)))
9062 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9063 (insert "\n\n")
9064 (indent-to margin)
9065 (vhdl-insert-keyword "END COMPONENT")
9066 (unless (vhdl-standard-p '87) (insert " " name))
9067 (insert ";")
9068 (setq end-column (current-column))
9069 (end-of-line -0)
9070 (indent-to (+ margin vhdl-basic-offset))
9071 (vhdl-template-generic-list t t)
9072 (insert "\n")
9073 (indent-to (+ margin vhdl-basic-offset))
9074 (vhdl-template-port-list t)
9075 (beginning-of-line 2)
9076 (forward-char end-column))))
9078 (defun vhdl-template-component-inst ()
9079 "Insert a component instantiation statement."
9080 (interactive)
9081 (let ((margin (current-indentation))
9082 (start (point))
9083 unit position)
9084 (when (vhdl-template-field "instance label" nil t start (point))
9085 (insert ": ")
9086 (if (not (vhdl-use-direct-instantiation))
9087 (vhdl-template-field "component name")
9088 ;; direct instantiation
9089 (setq unit (vhdl-template-field
9090 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
9091 (setq unit (upcase (or unit "")))
9092 (cond ((equal unit "ENTITY")
9093 (let ((begin (point)))
9094 (vhdl-template-field "library name" "." t begin (point) nil
9095 (vhdl-work-library))
9096 (vhdl-template-field "entity name" "(")
9097 (if (vhdl-template-field "[architecture name]" nil t)
9098 (insert ")")
9099 (delete-char -1))))
9100 ((equal unit "CONFIGURATION")
9101 (vhdl-template-field "library name" "." nil nil nil nil
9102 (vhdl-work-library))
9103 (vhdl-template-field "configuration name"))
9104 (t (vhdl-template-field "component name"))))
9105 (insert "\n")
9106 (indent-to (+ margin vhdl-basic-offset))
9107 (setq position (point))
9108 (vhdl-insert-keyword "GENERIC ")
9109 (when (vhdl-template-map position t t)
9110 (insert "\n")
9111 (indent-to (+ margin vhdl-basic-offset)))
9112 (setq position (point))
9113 (vhdl-insert-keyword "PORT ")
9114 (unless (vhdl-template-map position t t)
9115 (delete-region (line-beginning-position) (point))
9116 (delete-char -1))
9117 (insert ";"))))
9119 (defun vhdl-template-conditional-signal-asst ()
9120 "Insert a conditional signal assignment."
9121 (interactive)
9122 (when (vhdl-template-field "target signal")
9123 (insert " <= ")
9124 (let ((margin (current-column))
9125 (start (point))
9126 position)
9127 (vhdl-template-field "waveform")
9128 (setq position (point))
9129 (vhdl-insert-keyword " WHEN ")
9130 (when vhdl-conditions-in-parenthesis (insert "("))
9131 (while (and (vhdl-template-field "[condition]" nil t)
9132 (progn
9133 (when vhdl-conditions-in-parenthesis (insert ")"))
9134 (setq position (point))
9135 (vhdl-insert-keyword " ELSE")
9136 (insert "\n")
9137 (indent-to margin)
9138 (vhdl-template-field "[waveform]" nil t)))
9139 (setq position (point))
9140 (vhdl-insert-keyword " WHEN ")
9141 (when vhdl-conditions-in-parenthesis (insert "(")))
9142 (delete-region position (point))
9143 (insert ";")
9144 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9146 (defun vhdl-template-configuration ()
9147 "Insert a configuration specification if within an architecture,
9148 a block or component configuration if within a configuration declaration,
9149 a configuration declaration if not within a design unit."
9150 (interactive)
9151 (vhdl-prepare-search-1
9152 (cond
9153 ((and (save-excursion ; architecture body
9154 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
9155 (equal "ARCHITECTURE" (upcase (match-string 1))))
9156 (vhdl-template-configuration-spec))
9157 ((and (save-excursion ; configuration declaration
9158 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9159 (equal "CONFIGURATION" (upcase (match-string 1))))
9160 (if (eq (vhdl-decision-query
9161 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
9162 (vhdl-template-component-conf)
9163 (vhdl-template-block-configuration)))
9164 (t (vhdl-template-configuration-decl))))) ; otherwise
9166 (defun vhdl-template-configuration-spec (&optional optional-use)
9167 "Insert a configuration specification."
9168 (interactive)
9169 (let ((margin (current-indentation))
9170 (start (point))
9171 aspect position)
9172 (vhdl-insert-keyword "FOR ")
9173 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9174 t start (point))
9175 (vhdl-template-field "component name" "\n")
9176 (indent-to (+ margin vhdl-basic-offset))
9177 (setq start (point))
9178 (vhdl-insert-keyword "USE ")
9179 (if (and optional-use
9180 (not (setq aspect (vhdl-template-field
9181 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
9182 (progn (delete-region start (point)) 'no-use)
9183 (unless optional-use
9184 (setq aspect (vhdl-template-field
9185 "ENTITY | CONFIGURATION | OPEN" " ")))
9186 (setq aspect (upcase (or aspect "")))
9187 (cond ((equal aspect "ENTITY")
9188 (vhdl-template-field "library name" "." nil nil nil nil
9189 (vhdl-work-library))
9190 (vhdl-template-field "entity name" "(")
9191 (if (vhdl-template-field "[architecture name]" nil t)
9192 (insert ")")
9193 (delete-char -1))
9194 (insert "\n")
9195 (indent-to (+ margin (* 2 vhdl-basic-offset)))
9196 (setq position (point))
9197 (vhdl-insert-keyword "GENERIC ")
9198 (when (vhdl-template-map position t t)
9199 (insert "\n")
9200 (indent-to (+ margin (* 2 vhdl-basic-offset))))
9201 (setq position (point))
9202 (vhdl-insert-keyword "PORT ")
9203 (unless (vhdl-template-map position t t)
9204 (delete-region (line-beginning-position) (point))
9205 (delete-char -1))
9206 (insert ";")
9208 ((equal aspect "CONFIGURATION")
9209 (vhdl-template-field "library name" "." nil nil nil nil
9210 (vhdl-work-library))
9211 (vhdl-template-field "configuration name" ";"))
9212 (t (delete-char -1) (insert ";") t))))))
9215 (defun vhdl-template-configuration-decl ()
9216 "Insert a configuration declaration."
9217 (interactive)
9218 (let ((margin (current-indentation))
9219 (start (point))
9220 entity-exists string name position)
9221 (vhdl-insert-keyword "CONFIGURATION ")
9222 (when (setq name (vhdl-template-field "name" nil t start (point)))
9223 (vhdl-insert-keyword " OF ")
9224 (save-excursion
9225 (vhdl-prepare-search-1
9226 (setq entity-exists (vhdl-re-search-backward
9227 "\\<entity \\(\\w*\\) is\\>" nil t))
9228 (setq string (match-string 1))))
9229 (if (and entity-exists (not (equal string "")))
9230 (insert string)
9231 (vhdl-template-field "entity name"))
9232 (vhdl-insert-keyword " IS\n")
9233 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9234 (indent-to (+ margin vhdl-basic-offset))
9235 (setq position (point))
9236 (insert "\n")
9237 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9238 (indent-to margin)
9239 (vhdl-insert-keyword "END ")
9240 (unless (vhdl-standard-p '87)
9241 (vhdl-insert-keyword "CONFIGURATION "))
9242 (insert name ";")
9243 (goto-char position))))
9245 (defun vhdl-template-constant ()
9246 "Insert a constant declaration."
9247 (interactive)
9248 (let ((start (point))
9249 (in-arglist (vhdl-in-argument-list-p)))
9250 (vhdl-insert-keyword "CONSTANT ")
9251 (when (vhdl-template-field "name" nil t start (point))
9252 (insert " : ")
9253 (when in-arglist (vhdl-insert-keyword "IN "))
9254 (vhdl-template-field "type")
9255 (if in-arglist
9256 (progn (insert ";")
9257 (vhdl-comment-insert-inline))
9258 (let ((position (point)))
9259 (insert " := ")
9260 (unless (vhdl-template-field "[initialization]" nil t)
9261 (delete-region position (point)))
9262 (insert ";")
9263 (vhdl-comment-insert-inline))))))
9265 (defun vhdl-template-context ()
9266 "Insert a context declaration."
9267 (interactive)
9268 (let ((margin (current-indentation))
9269 (start (point))
9270 entity-exists string name position)
9271 (vhdl-insert-keyword "CONTEXT ")
9272 (when (setq name (vhdl-template-field "name" nil t start (point)))
9273 (vhdl-insert-keyword " IS\n")
9274 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9275 (indent-to (+ margin vhdl-basic-offset))
9276 (setq position (point))
9277 (insert "\n")
9278 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9279 (indent-to margin)
9280 (vhdl-insert-keyword "END ")
9281 (unless (vhdl-standard-p '87)
9282 (vhdl-insert-keyword "CONTEXT "))
9283 (insert name ";")
9284 (goto-char position))))
9286 (defun vhdl-template-default ()
9287 "Insert nothing."
9288 (interactive)
9289 (insert " ")
9290 (unexpand-abbrev)
9291 (backward-word-strictly 1)
9292 (vhdl-case-word 1)
9293 (forward-char 1))
9295 (defun vhdl-template-default-indent ()
9296 "Insert nothing and indent."
9297 (interactive)
9298 (insert " ")
9299 (unexpand-abbrev)
9300 (backward-word-strictly 1)
9301 (vhdl-case-word 1)
9302 (forward-char 1)
9303 (indent-according-to-mode))
9305 (defun vhdl-template-disconnect ()
9306 "Insert a disconnect statement."
9307 (interactive)
9308 (let ((start (point)))
9309 (vhdl-insert-keyword "DISCONNECT ")
9310 (when (vhdl-template-field "signal names | OTHERS | ALL"
9311 " : " t start (point))
9312 (vhdl-template-field "type")
9313 (vhdl-insert-keyword " AFTER ")
9314 (vhdl-template-field "time expression" ";"))))
9316 (defun vhdl-template-else ()
9317 "Insert an else statement."
9318 (interactive)
9319 (let (margin)
9320 (vhdl-prepare-search-1
9321 (vhdl-insert-keyword "ELSE")
9322 (if (and (save-excursion (vhdl-re-search-backward "\\(\\(\\<when\\>\\)\\|;\\)" nil t))
9323 (match-string 2))
9324 (insert " ")
9325 (unless (vhdl-sequential-statement-p)
9326 (vhdl-insert-keyword " GENERATE"))
9327 (indent-according-to-mode)
9328 (setq margin (current-indentation))
9329 (insert "\n")
9330 (indent-to (+ margin vhdl-basic-offset))))))
9332 (defun vhdl-template-elsif ()
9333 "Insert an elsif statement."
9334 (interactive)
9335 (let ((start (point))
9336 margin)
9337 (vhdl-insert-keyword "ELSIF ")
9338 (when vhdl-conditions-in-parenthesis (insert "("))
9339 (when (vhdl-template-field "condition" nil t start (point))
9340 (when vhdl-conditions-in-parenthesis (insert ")"))
9341 (indent-according-to-mode)
9342 (setq margin (current-indentation))
9343 (vhdl-insert-keyword
9344 (concat " " (cond ((vhdl-sequential-statement-p) "THEN")
9345 ((vhdl-standard-p 'ams) "USE")
9346 (t "GENERATE")) "\n"))
9347 (indent-to (+ margin vhdl-basic-offset)))))
9349 (defun vhdl-template-entity ()
9350 "Insert an entity."
9351 (interactive)
9352 (let ((margin (current-indentation))
9353 (start (point))
9354 name end-column)
9355 (vhdl-insert-keyword "ENTITY ")
9356 (when (setq name (vhdl-template-field "name" nil t start (point)))
9357 (vhdl-insert-keyword " IS\n\n")
9358 (indent-to margin)
9359 (vhdl-insert-keyword "END ")
9360 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9361 (insert name ";")
9362 (setq end-column (current-column))
9363 (end-of-line -0)
9364 (indent-to (+ margin vhdl-basic-offset))
9365 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9366 (indent-to (+ margin vhdl-basic-offset))
9367 (when (vhdl-template-generic-list t)
9368 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9369 (insert "\n")
9370 (indent-to (+ margin vhdl-basic-offset))
9371 (when (vhdl-template-port-list t)
9372 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9373 (beginning-of-line 2)
9374 (forward-char end-column))))
9376 (defun vhdl-template-exit ()
9377 "Insert an exit statement."
9378 (interactive)
9379 (let ((start (point)))
9380 (vhdl-insert-keyword "EXIT ")
9381 (if (vhdl-template-field "[loop label]" nil t start (point))
9382 (let ((position (point)))
9383 (vhdl-insert-keyword " WHEN ")
9384 (when vhdl-conditions-in-parenthesis (insert "("))
9385 (if (vhdl-template-field "[condition]" nil t)
9386 (when vhdl-conditions-in-parenthesis (insert ")"))
9387 (delete-region position (point))))
9388 (delete-char -1))
9389 (insert ";")))
9391 (defun vhdl-template-file ()
9392 "Insert a file declaration."
9393 (interactive)
9394 (let ((start (point)))
9395 (vhdl-insert-keyword "FILE ")
9396 (when (vhdl-template-field "name" nil t start (point))
9397 (insert " : ")
9398 (vhdl-template-field "type")
9399 (unless (vhdl-standard-p '87)
9400 (vhdl-insert-keyword " OPEN ")
9401 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9402 nil t)
9403 (delete-char -6)))
9404 (vhdl-insert-keyword " IS ")
9405 (when (vhdl-standard-p '87)
9406 (vhdl-template-field "[IN | OUT]" " " t))
9407 (vhdl-template-field "filename-string" nil nil nil nil t)
9408 (insert ";")
9409 (vhdl-comment-insert-inline))))
9411 (defun vhdl-template-for ()
9412 "Insert a block or component configuration if within a configuration
9413 declaration, a configuration specification if within an architecture
9414 declarative part (and not within a subprogram), a for-loop if within a
9415 sequential statement part (subprogram or process), and a for-generate
9416 otherwise."
9417 (interactive)
9418 (vhdl-prepare-search-1
9419 (cond
9420 ((vhdl-sequential-statement-p) ; sequential statement
9421 (vhdl-template-for-loop))
9422 ((and (save-excursion ; configuration declaration
9423 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9424 (equal "CONFIGURATION" (upcase (match-string 1))))
9425 (if (eq (vhdl-decision-query
9426 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9427 (vhdl-template-component-conf)
9428 (vhdl-template-block-configuration)))
9429 ((and (save-excursion
9430 (re-search-backward ; architecture declarative part
9431 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9432 (equal "ARCHITECTURE" (upcase (match-string 1))))
9433 (vhdl-template-configuration-spec))
9434 (t (vhdl-template-for-generate))))) ; concurrent statement
9436 (defun vhdl-template-for-generate ()
9437 "Insert a for-generate."
9438 (interactive)
9439 (let ((margin (current-indentation))
9440 (start (point))
9441 label position)
9442 (vhdl-insert-keyword ": FOR ")
9443 (setq position (point-marker))
9444 (goto-char start)
9445 (when (setq label (vhdl-template-field "label" nil t start position))
9446 (goto-char position)
9447 (vhdl-template-field "loop variable")
9448 (vhdl-insert-keyword " IN ")
9449 (vhdl-template-field "range")
9450 (vhdl-template-generate-body margin label))))
9452 (defun vhdl-template-for-loop ()
9453 "Insert a for loop."
9454 (interactive)
9455 (let ((margin (current-indentation))
9456 (start (point))
9457 label index)
9458 (if (not (eq vhdl-optional-labels 'all))
9459 (vhdl-insert-keyword "FOR ")
9460 (vhdl-insert-keyword ": FOR ")
9461 (goto-char start)
9462 (setq label (vhdl-template-field "[label]" nil t))
9463 (unless label (delete-char 2))
9464 (forward-word-strictly 1)
9465 (forward-char 1))
9466 (when (setq index (vhdl-template-field "loop variable"
9467 nil t start (point)))
9468 (vhdl-insert-keyword " IN ")
9469 (vhdl-template-field "range")
9470 (vhdl-insert-keyword " LOOP\n\n")
9471 (indent-to margin)
9472 (vhdl-insert-keyword "END LOOP")
9473 (if label
9474 (insert " " label ";")
9475 (insert ";")
9476 (when vhdl-self-insert-comments (insert " -- " index)))
9477 (forward-line -1)
9478 (indent-to (+ margin vhdl-basic-offset)))))
9480 (defun vhdl-template-function (&optional kind)
9481 "Insert a function declaration or body."
9482 (interactive)
9483 (let ((margin (current-indentation))
9484 (start (point))
9485 name)
9486 (vhdl-insert-keyword "FUNCTION ")
9487 (when (setq name (vhdl-template-field "name" nil t start (point)))
9488 (vhdl-template-argument-list t)
9489 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9490 (end-of-line)
9491 (insert "\n")
9492 (indent-to (+ margin vhdl-basic-offset))
9493 (vhdl-insert-keyword "RETURN ")
9494 (vhdl-template-field "type")
9495 (if (if kind (eq kind 'body)
9496 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9497 (progn (vhdl-insert-keyword " IS\n")
9498 (vhdl-template-begin-end
9499 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9500 (vhdl-comment-block))
9501 (insert ";")))))
9503 (defun vhdl-template-function-decl ()
9504 "Insert a function declaration."
9505 (interactive)
9506 (vhdl-template-function 'decl))
9508 (defun vhdl-template-function-body ()
9509 "Insert a function declaration."
9510 (interactive)
9511 (vhdl-template-function 'body))
9513 (defun vhdl-template-generate ()
9514 "Insert a generation scheme."
9515 (interactive)
9516 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9517 (vhdl-template-if-generate)
9518 (vhdl-template-for-generate)))
9520 (defun vhdl-template-generic ()
9521 "Insert generic declaration, or generic map in instantiation statements."
9522 (interactive)
9523 (let ((start (point)))
9524 (vhdl-prepare-search-1
9525 (cond
9526 ((and (save-excursion ; entity declaration
9527 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9528 (equal "ENTITY" (upcase (match-string 1))))
9529 (vhdl-template-generic-list nil))
9530 ((or (save-excursion
9531 (or (beginning-of-line)
9532 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9533 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9534 (vhdl-insert-keyword "GENERIC ")
9535 (vhdl-template-map start))
9536 (t (vhdl-template-generic-list nil t))))))
9538 (defun vhdl-template-group ()
9539 "Insert group or group template declaration."
9540 (interactive)
9541 (let ((start (point)))
9542 (if (eq (vhdl-decision-query
9543 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9544 (vhdl-template-group-template)
9545 (vhdl-template-group-decl))))
9547 (defun vhdl-template-group-decl ()
9548 "Insert group declaration."
9549 (interactive)
9550 (let ((start (point)))
9551 (vhdl-insert-keyword "GROUP ")
9552 (when (vhdl-template-field "name" " : " t start (point))
9553 (vhdl-template-field "template name" " (")
9554 (vhdl-template-field "constituent list" ");")
9555 (vhdl-comment-insert-inline))))
9557 (defun vhdl-template-group-template ()
9558 "Insert group template declaration."
9559 (interactive)
9560 (let ((start (point)))
9561 (vhdl-insert-keyword "GROUP ")
9562 (when (vhdl-template-field "template name" nil t start (point))
9563 (vhdl-insert-keyword " IS (")
9564 (vhdl-template-field "entity class list" ");")
9565 (vhdl-comment-insert-inline))))
9567 (defun vhdl-template-if ()
9568 "Insert a sequential if statement or an if-generate statement."
9569 (interactive)
9570 (if (vhdl-sequential-statement-p)
9571 (vhdl-template-if-then)
9572 (if (and (vhdl-standard-p 'ams)
9573 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9574 (vhdl-template-if-use)
9575 (vhdl-template-if-generate))))
9577 (defun vhdl-template-if-generate ()
9578 "Insert an if-generate."
9579 (interactive)
9580 (let ((margin (current-indentation))
9581 (start (point))
9582 label position)
9583 (vhdl-insert-keyword ": IF ")
9584 (setq position (point-marker))
9585 (goto-char start)
9586 (when (setq label (vhdl-template-field "label" nil t start position))
9587 (goto-char position)
9588 (when vhdl-conditions-in-parenthesis (insert "("))
9589 (vhdl-template-field "condition")
9590 (when vhdl-conditions-in-parenthesis (insert ")"))
9591 (vhdl-template-generate-body margin label))))
9593 (defun vhdl-template-if-then-use (kind)
9594 "Insert a sequential if statement."
9595 (interactive)
9596 (let ((margin (current-indentation))
9597 (start (point))
9598 label)
9599 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9600 (vhdl-insert-keyword "IF ")
9601 (vhdl-insert-keyword ": IF ")
9602 (goto-char start)
9603 (setq label (vhdl-template-field "[label]" nil t))
9604 (unless label (delete-char 2))
9605 (forward-word-strictly 1)
9606 (forward-char 1))
9607 (when vhdl-conditions-in-parenthesis (insert "("))
9608 (when (vhdl-template-field "condition" nil t start (point))
9609 (when vhdl-conditions-in-parenthesis (insert ")"))
9610 (vhdl-insert-keyword
9611 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9612 (indent-to margin)
9613 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9614 (when label (insert " " label))
9615 (insert ";")
9616 (forward-line -1)
9617 (indent-to (+ margin vhdl-basic-offset)))))
9619 (defun vhdl-template-if-then ()
9620 "Insert a sequential if statement."
9621 (interactive)
9622 (vhdl-template-if-then-use 'then))
9624 (defun vhdl-template-if-use ()
9625 "Insert a simultaneous if statement."
9626 (interactive)
9627 (vhdl-template-if-then-use 'use))
9629 (defun vhdl-template-instance ()
9630 "Insert a component instantiation statement."
9631 (interactive)
9632 (vhdl-template-component-inst))
9634 (defun vhdl-template-library ()
9635 "Insert a library specification."
9636 (interactive)
9637 (let ((margin (current-indentation))
9638 (start (point))
9639 name end-pos)
9640 (vhdl-insert-keyword "LIBRARY ")
9641 (when (setq name (vhdl-template-field "names" nil t start (point)))
9642 (insert ";")
9643 (unless (string-match "," name)
9644 (setq end-pos (point))
9645 (insert "\n")
9646 (indent-to margin)
9647 (vhdl-insert-keyword "USE ")
9648 (insert name)
9649 (vhdl-insert-keyword "..ALL;")
9650 (backward-char 5)
9651 (if (vhdl-template-field "package name")
9652 (forward-char 5)
9653 (delete-region end-pos (+ (point) 5)))))))
9655 (defun vhdl-template-limit ()
9656 "Insert a limit."
9657 (interactive)
9658 (let ((start (point)))
9659 (vhdl-insert-keyword "LIMIT ")
9660 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9661 t start (point))
9662 (vhdl-template-field "type")
9663 (vhdl-insert-keyword " WITH ")
9664 (vhdl-template-field "real expression" ";"))))
9666 (defun vhdl-template-loop ()
9667 "Insert a loop."
9668 (interactive)
9669 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9670 (cond ((eq char ?w)
9671 (vhdl-template-while-loop))
9672 ((eq char ?f)
9673 (vhdl-template-for-loop))
9674 (t (vhdl-template-bare-loop)))))
9676 (defun vhdl-template-bare-loop ()
9677 "Insert a loop."
9678 (interactive)
9679 (let ((margin (current-indentation))
9680 (start (point))
9681 label)
9682 (if (not (eq vhdl-optional-labels 'all))
9683 (vhdl-insert-keyword "LOOP ")
9684 (vhdl-insert-keyword ": LOOP ")
9685 (goto-char start)
9686 (setq label (vhdl-template-field "[label]" nil t))
9687 (unless label (delete-char 2))
9688 (forward-word-strictly 1)
9689 (delete-char 1))
9690 (insert "\n\n")
9691 (indent-to margin)
9692 (vhdl-insert-keyword "END LOOP")
9693 (insert (if label (concat " " label ";") ";"))
9694 (forward-line -1)
9695 (indent-to (+ margin vhdl-basic-offset))))
9697 (defun vhdl-template-map (&optional start optional secondary)
9698 "Insert a map specification with association list."
9699 (interactive)
9700 (let ((start (or start (point)))
9701 margin end-pos)
9702 (vhdl-insert-keyword "MAP (")
9703 (if (not vhdl-association-list-with-formals)
9704 (if (vhdl-template-field
9705 (concat (and optional "[") "association list" (and optional "]"))
9706 ")" (or (not secondary) optional)
9707 (and (not secondary) start) (point))
9709 (if (and optional secondary) (delete-region start (point)))
9710 nil)
9711 (if vhdl-argument-list-indent
9712 (setq margin (current-column))
9713 (setq margin (+ (current-indentation) vhdl-basic-offset))
9714 (insert "\n")
9715 (indent-to margin))
9716 (if (vhdl-template-field
9717 (concat (and optional "[") "formal" (and optional "]"))
9718 " => " (or (not secondary) optional)
9719 (and (not secondary) start) (point))
9720 (progn
9721 (vhdl-template-field "actual" ",")
9722 (setq end-pos (point))
9723 (insert "\n")
9724 (indent-to margin)
9725 (while (vhdl-template-field "[formal]" " => " t)
9726 (vhdl-template-field "actual" ",")
9727 (setq end-pos (point))
9728 (insert "\n")
9729 (indent-to margin))
9730 (delete-region end-pos (point))
9731 (delete-char -1)
9732 (insert ")")
9733 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9735 (when (and optional secondary) (delete-region start (point)))
9736 nil))))
9738 (defun vhdl-template-modify (&optional noerror)
9739 "Actualize modification date."
9740 (interactive)
9741 (vhdl-prepare-search-2
9742 (save-excursion
9743 (goto-char (point-min))
9744 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9745 (progn (delete-region (point) (progn (end-of-line) (point)))
9746 (vhdl-template-insert-date))
9747 (unless noerror
9748 (error "ERROR: Modification date prefix string \"%s\" not found"
9749 vhdl-modify-date-prefix-string))))))
9752 (defun vhdl-template-modify-noerror ()
9753 "Call `vhdl-template-modify' with NOERROR non-nil."
9754 (vhdl-template-modify t))
9756 (defun vhdl-template-nature ()
9757 "Insert a nature declaration."
9758 (interactive)
9759 (let ((start (point))
9760 name mid-pos end-pos)
9761 (vhdl-insert-keyword "NATURE ")
9762 (when (setq name (vhdl-template-field "name" nil t start (point)))
9763 (vhdl-insert-keyword " IS ")
9764 (let ((definition
9765 (upcase
9766 (or (vhdl-template-field
9767 "across type | ARRAY | RECORD")
9768 ""))))
9769 (cond ((equal definition "")
9770 (insert ";"))
9771 ((equal definition "ARRAY")
9772 (delete-region (point) (progn (forward-word-strictly -1)
9773 (point)))
9774 (vhdl-template-array 'nature t))
9775 ((equal definition "RECORD")
9776 (setq mid-pos (point-marker))
9777 (delete-region (point) (progn (forward-word-strictly -1)
9778 (point)))
9779 (vhdl-template-record 'nature name t))
9781 (vhdl-insert-keyword " ACROSS ")
9782 (vhdl-template-field "through type")
9783 (vhdl-insert-keyword " THROUGH ")
9784 (vhdl-template-field "reference name")
9785 (vhdl-insert-keyword " REFERENCE;")))
9786 (when mid-pos
9787 (setq end-pos (point-marker))
9788 (goto-char mid-pos)
9789 (end-of-line))
9790 (vhdl-comment-insert-inline)
9791 (when end-pos (goto-char end-pos))))))
9793 (defun vhdl-template-next ()
9794 "Insert a next statement."
9795 (interactive)
9796 (let ((start (point)))
9797 (vhdl-insert-keyword "NEXT ")
9798 (if (vhdl-template-field "[loop label]" nil t start (point))
9799 (let ((position (point)))
9800 (vhdl-insert-keyword " WHEN ")
9801 (when vhdl-conditions-in-parenthesis (insert "("))
9802 (if (vhdl-template-field "[condition]" nil t)
9803 (when vhdl-conditions-in-parenthesis (insert ")"))
9804 (delete-region position (point))))
9805 (delete-char -1))
9806 (insert ";")))
9808 (defun vhdl-template-others ()
9809 "Insert an others aggregate."
9810 (interactive)
9811 (let ((start (point)))
9812 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9813 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9814 (vhdl-insert-keyword "OTHERS => '")
9815 (when (vhdl-template-field "value" nil t start (point))
9816 (insert "')")))
9817 (vhdl-insert-keyword "OTHERS "))))
9819 (defun vhdl-template-package (&optional kind)
9820 "Insert a package specification or body."
9821 (interactive)
9822 (let ((margin (current-indentation))
9823 (start (point))
9824 name body position)
9825 (vhdl-insert-keyword "PACKAGE ")
9826 (setq body (if kind (eq kind 'body)
9827 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9828 (when body
9829 (vhdl-insert-keyword "BODY ")
9830 (when (save-excursion
9831 (vhdl-prepare-search-1
9832 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9833 (insert (setq name (match-string 1)))))
9834 (when (or name
9835 (setq name (vhdl-template-field "name" nil t start (point))))
9836 (vhdl-insert-keyword " IS\n")
9837 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9838 (indent-to (+ margin vhdl-basic-offset))
9839 (setq position (point))
9840 (insert "\n")
9841 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9842 (indent-to margin)
9843 (vhdl-insert-keyword "END ")
9844 (unless (vhdl-standard-p '87)
9845 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9846 (insert (or name "") ";")
9847 (goto-char position))))
9849 (defun vhdl-template-package-decl ()
9850 "Insert a package specification."
9851 (interactive)
9852 (vhdl-template-package 'decl))
9854 (defun vhdl-template-package-body ()
9855 "Insert a package body."
9856 (interactive)
9857 (vhdl-template-package 'body))
9859 (defun vhdl-template-port ()
9860 "Insert a port declaration, or port map in instantiation statements."
9861 (interactive)
9862 (let ((start (point)))
9863 (vhdl-prepare-search-1
9864 (cond
9865 ((and (save-excursion ; entity declaration
9866 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9867 (equal "ENTITY" (upcase (match-string 1))))
9868 (vhdl-template-port-list nil))
9869 ((or (save-excursion
9870 (or (beginning-of-line)
9871 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9872 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9873 (vhdl-insert-keyword "PORT ")
9874 (vhdl-template-map start))
9875 (t (vhdl-template-port-list nil))))))
9877 (defun vhdl-template-procedural ()
9878 "Insert a procedural."
9879 (interactive)
9880 (let ((margin (current-indentation))
9881 (start (point))
9882 (case-fold-search t)
9883 label)
9884 (vhdl-insert-keyword "PROCEDURAL ")
9885 (when (memq vhdl-optional-labels '(process all))
9886 (goto-char start)
9887 (insert ": ")
9888 (goto-char start)
9889 (setq label (vhdl-template-field "[label]" nil t))
9890 (unless label (delete-char 2))
9891 (forward-word-strictly 1)
9892 (forward-char 1))
9893 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9894 (insert "\n")
9895 (vhdl-template-begin-end "PROCEDURAL" label margin)
9896 (vhdl-comment-block)))
9898 (defun vhdl-template-procedure (&optional kind)
9899 "Insert a procedure declaration or body."
9900 (interactive)
9901 (let ((margin (current-indentation))
9902 (start (point))
9903 name)
9904 (vhdl-insert-keyword "PROCEDURE ")
9905 (when (setq name (vhdl-template-field "name" nil t start (point)))
9906 (vhdl-template-argument-list)
9907 (if (if kind (eq kind 'body)
9908 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9909 (progn (vhdl-insert-keyword " IS")
9910 (when vhdl-auto-align
9911 (vhdl-align-region-groups start (point) 1))
9912 (end-of-line) (insert "\n")
9913 (vhdl-template-begin-end
9914 (unless (vhdl-standard-p '87) "PROCEDURE")
9915 name margin)
9916 (vhdl-comment-block))
9917 (insert ";")
9918 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9919 (end-of-line)))))
9921 (defun vhdl-template-procedure-decl ()
9922 "Insert a procedure declaration."
9923 (interactive)
9924 (vhdl-template-procedure 'decl))
9926 (defun vhdl-template-procedure-body ()
9927 "Insert a procedure body."
9928 (interactive)
9929 (vhdl-template-procedure 'body))
9931 (defun vhdl-template-process (&optional kind)
9932 "Insert a process."
9933 (interactive)
9934 (let ((margin (current-indentation))
9935 (start (point))
9936 (reset-kind vhdl-reset-kind)
9937 label seq input-signals clock reset final-pos)
9938 (setq seq (if kind (eq kind 'seq)
9939 (eq (vhdl-decision-query
9940 "process" "(c)ombinational or (s)equential?" t) ?s)))
9941 (vhdl-insert-keyword "PROCESS ")
9942 (when (memq vhdl-optional-labels '(process all))
9943 (goto-char start)
9944 (insert ": ")
9945 (goto-char start)
9946 (setq label (vhdl-template-field "[label]" nil t))
9947 (unless label (delete-char 2))
9948 (forward-word-strictly 1)
9949 (forward-char 1))
9950 (insert "(")
9951 (if (not seq)
9952 (unless (or (and (vhdl-standard-p '08) vhdl-sensitivity-list-all
9953 (progn (insert "all)") (setq input-signals "all")))
9954 (setq input-signals
9955 (vhdl-template-field "[sensitivity list]" ")" t)))
9956 (setq input-signals "")
9957 (delete-char -2))
9958 (setq clock (or (and (not (equal "" vhdl-clock-name))
9959 (progn (insert vhdl-clock-name) vhdl-clock-name))
9960 (vhdl-template-field "clock name") "<clock>"))
9961 (when (eq reset-kind 'query)
9962 (setq reset-kind
9963 (if (eq (vhdl-decision-query
9964 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9965 'async
9966 'sync)))
9967 (when (eq reset-kind 'async)
9968 (insert ", ")
9969 (setq reset (or (and (not (equal "" vhdl-reset-name))
9970 (progn (insert vhdl-reset-name) vhdl-reset-name))
9971 (vhdl-template-field "reset name") "<reset>")))
9972 (insert ")"))
9973 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9974 (insert "\n")
9975 (vhdl-template-begin-end "PROCESS" label margin)
9976 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9977 (when vhdl-prompt-for-comments
9978 (setq final-pos (point-marker))
9979 (vhdl-prepare-search-2
9980 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9981 (vhdl-re-search-backward "\\<process\\>" nil t))
9982 (end-of-line -0)
9983 (if (bobp)
9984 (progn (insert "\n") (forward-line -1))
9985 (insert "\n"))
9986 (indent-to margin)
9987 (insert "-- purpose: ")
9988 (if (not (vhdl-template-field "[description]" nil t))
9989 (vhdl-line-kill-entire)
9990 (insert "\n")
9991 (indent-to margin)
9992 (insert "-- type : ")
9993 (insert (if seq "sequential" "combinational") "\n")
9994 (indent-to margin)
9995 (insert "-- inputs : ")
9996 (if (not seq)
9997 (insert input-signals)
9998 (insert clock ", ")
9999 (when reset (insert reset ", "))
10000 (unless (vhdl-template-field "[signal names]" nil t)
10001 (delete-char -2)))
10002 (insert "\n")
10003 (indent-to margin)
10004 (insert "-- outputs: ")
10005 (vhdl-template-field "[signal names]" nil t))))
10006 (goto-char final-pos))))
10008 (defun vhdl-template-process-comb ()
10009 "Insert a combinational process."
10010 (interactive)
10011 (vhdl-template-process 'comb))
10013 (defun vhdl-template-process-seq ()
10014 "Insert a sequential process."
10015 (interactive)
10016 (vhdl-template-process 'seq))
10018 (defun vhdl-template-quantity ()
10019 "Insert a quantity declaration."
10020 (interactive)
10021 (if (vhdl-in-argument-list-p)
10022 (let ((start (point)))
10023 (vhdl-insert-keyword "QUANTITY ")
10024 (when (vhdl-template-field "names" nil t start (point))
10025 (insert " : ")
10026 (vhdl-template-field "[IN | OUT]" " " t)
10027 (vhdl-template-field "type")
10028 (insert ";")
10029 (vhdl-comment-insert-inline)))
10030 (let ((char (vhdl-decision-query
10031 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
10032 (cond ((eq char ?f) (vhdl-template-quantity-free))
10033 ((eq char ?b) (vhdl-template-quantity-branch))
10034 ((eq char ?s) (vhdl-template-quantity-source))
10035 (t (vhdl-template-undo (point) (point)))))))
10037 (defun vhdl-template-quantity-free ()
10038 "Insert a free quantity declaration."
10039 (interactive)
10040 (vhdl-insert-keyword "QUANTITY ")
10041 (vhdl-template-field "names")
10042 (insert " : ")
10043 (vhdl-template-field "type")
10044 (let ((position (point)))
10045 (insert " := ")
10046 (unless (vhdl-template-field "[initialization]" nil t)
10047 (delete-region position (point)))
10048 (insert ";")
10049 (vhdl-comment-insert-inline)))
10051 (defun vhdl-template-quantity-branch ()
10052 "Insert a branch quantity declaration."
10053 (interactive)
10054 (let (position)
10055 (vhdl-insert-keyword "QUANTITY ")
10056 (when (vhdl-template-field "[across names]" " " t)
10057 (vhdl-insert-keyword "ACROSS "))
10058 (when (vhdl-template-field "[through names]" " " t)
10059 (vhdl-insert-keyword "THROUGH "))
10060 (vhdl-template-field "plus terminal name")
10061 (setq position (point))
10062 (vhdl-insert-keyword " TO ")
10063 (unless (vhdl-template-field "[minus terminal name]" nil t)
10064 (delete-region position (point)))
10065 (insert ";")
10066 (vhdl-comment-insert-inline)))
10068 (defun vhdl-template-quantity-source ()
10069 "Insert a source quantity declaration."
10070 (interactive)
10071 (vhdl-insert-keyword "QUANTITY ")
10072 (vhdl-template-field "names")
10073 (insert " : ")
10074 (vhdl-template-field "type" " ")
10075 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
10076 (progn (vhdl-insert-keyword "NOISE ")
10077 (vhdl-template-field "power expression"))
10078 (vhdl-insert-keyword "SPECTRUM ")
10079 (vhdl-template-field "magnitude expression" ", ")
10080 (vhdl-template-field "phase expression"))
10081 (insert ";")
10082 (vhdl-comment-insert-inline))
10084 (defun vhdl-template-record (kind &optional name secondary)
10085 "Insert a record type declaration."
10086 (interactive)
10087 (let ((margin (current-indentation))
10088 (start (point))
10089 (first t))
10090 (vhdl-insert-keyword "RECORD\n")
10091 (indent-to (+ margin vhdl-basic-offset))
10092 (when (or (vhdl-template-field "element names"
10093 nil (not secondary) start (point))
10094 secondary)
10095 (while (or first (vhdl-template-field "[element names]" nil t))
10096 (insert " : ")
10097 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
10098 (vhdl-comment-insert-inline)
10099 (insert "\n")
10100 (indent-to (+ margin vhdl-basic-offset))
10101 (setq first nil))
10102 (delete-region (line-beginning-position) (point))
10103 (indent-to margin)
10104 (vhdl-insert-keyword "END RECORD")
10105 (unless (vhdl-standard-p '87) (and name (insert " " name)))
10106 (insert ";")
10107 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10109 (defun vhdl-template-report ()
10110 "Insert a report statement."
10111 (interactive)
10112 (let ((start (point)))
10113 (vhdl-insert-keyword "REPORT ")
10114 (if (equal "\"\"" (vhdl-template-field
10115 "string expression" nil t start (point) t))
10116 (delete-char -2)
10117 (setq start (point))
10118 (vhdl-insert-keyword " SEVERITY ")
10119 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
10120 (delete-region start (point)))
10121 (insert ";"))))
10123 (defun vhdl-template-return ()
10124 "Insert a return statement."
10125 (interactive)
10126 (let ((start (point)))
10127 (vhdl-insert-keyword "RETURN ")
10128 (unless (vhdl-template-field "[expression]" nil t start (point))
10129 (delete-char -1))
10130 (insert ";")))
10132 (defun vhdl-template-selected-signal-asst ()
10133 "Insert a selected signal assignment."
10134 (interactive)
10135 (let ((margin (current-indentation))
10136 (start (point))
10137 (choices t))
10138 (let ((position (point)))
10139 (vhdl-insert-keyword " SELECT ")
10140 (goto-char position))
10141 (vhdl-insert-keyword "WITH ")
10142 (when (vhdl-template-field "selector expression"
10143 nil t start (+ (point) 7))
10144 (forward-word-strictly 1)
10145 (delete-char 1)
10146 (insert "\n")
10147 (indent-to (+ margin vhdl-basic-offset))
10148 (vhdl-template-field "target signal" " <= ")
10149 (insert "\n")
10150 (indent-to (+ margin vhdl-basic-offset))
10151 (vhdl-template-field "waveform")
10152 (vhdl-insert-keyword " WHEN ")
10153 (vhdl-template-field "choices" ",")
10154 (insert "\n")
10155 (indent-to (+ margin vhdl-basic-offset))
10156 (while (and choices (vhdl-template-field "[waveform]" nil t))
10157 (vhdl-insert-keyword " WHEN ")
10158 (if (setq choices (vhdl-template-field "[choices]" "," t))
10159 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10160 (vhdl-insert-keyword "OTHERS")))
10161 (when choices
10162 (fixup-whitespace)
10163 (delete-char -2))
10164 (insert ";")
10165 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10167 (defun vhdl-template-signal ()
10168 "Insert a signal declaration."
10169 (interactive)
10170 (let ((start (point))
10171 (in-arglist (vhdl-in-argument-list-p)))
10172 (vhdl-insert-keyword "SIGNAL ")
10173 (when (vhdl-template-field "names" nil t start (point))
10174 (insert " : ")
10175 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10176 (vhdl-template-field "type")
10177 (if in-arglist
10178 (progn (insert ";")
10179 (vhdl-comment-insert-inline))
10180 (let ((position (point)))
10181 (insert " := ")
10182 (unless (vhdl-template-field "[initialization]" nil t)
10183 (delete-region position (point)))
10184 (insert ";")
10185 (vhdl-comment-insert-inline))))))
10187 (defun vhdl-template-subnature ()
10188 "Insert a subnature declaration."
10189 (interactive)
10190 (let ((start (point))
10191 position)
10192 (vhdl-insert-keyword "SUBNATURE ")
10193 (when (vhdl-template-field "name" nil t start (point))
10194 (vhdl-insert-keyword " IS ")
10195 (vhdl-template-field "nature" " (")
10196 (if (vhdl-template-field "[index range]" nil t)
10197 (insert ")")
10198 (delete-char -2))
10199 (setq position (point))
10200 (vhdl-insert-keyword " TOLERANCE ")
10201 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10202 nil t nil nil t))
10203 (delete-region position (point))
10204 (vhdl-insert-keyword " ACROSS ")
10205 (vhdl-template-field "string expression" nil nil nil nil t)
10206 (vhdl-insert-keyword " THROUGH"))
10207 (insert ";")
10208 (vhdl-comment-insert-inline))))
10210 (defun vhdl-template-subprogram-body ()
10211 "Insert a subprogram body."
10212 (interactive)
10213 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10214 (vhdl-template-function-body)
10215 (vhdl-template-procedure-body)))
10217 (defun vhdl-template-subprogram-decl ()
10218 "Insert a subprogram declaration."
10219 (interactive)
10220 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10221 (vhdl-template-function-decl)
10222 (vhdl-template-procedure-decl)))
10224 (defun vhdl-template-subtype ()
10225 "Insert a subtype declaration."
10226 (interactive)
10227 (let ((start (point)))
10228 (vhdl-insert-keyword "SUBTYPE ")
10229 (when (vhdl-template-field "name" nil t start (point))
10230 (vhdl-insert-keyword " IS ")
10231 (vhdl-template-field "type" " ")
10232 (unless
10233 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
10234 (delete-char -1))
10235 (insert ";")
10236 (vhdl-comment-insert-inline))))
10238 (defun vhdl-template-terminal ()
10239 "Insert a terminal declaration."
10240 (interactive)
10241 (let ((start (point)))
10242 (vhdl-insert-keyword "TERMINAL ")
10243 (when (vhdl-template-field "names" nil t start (point))
10244 (insert " : ")
10245 (vhdl-template-field "nature")
10246 (insert ";")
10247 (vhdl-comment-insert-inline))))
10249 (defun vhdl-template-type ()
10250 "Insert a type declaration."
10251 (interactive)
10252 (let ((start (point))
10253 name mid-pos end-pos)
10254 (vhdl-insert-keyword "TYPE ")
10255 (when (setq name (vhdl-template-field "name" nil t start (point)))
10256 (vhdl-insert-keyword " IS ")
10257 (let ((definition
10258 (upcase
10259 (or (vhdl-template-field
10260 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
10261 ""))))
10262 (cond ((equal definition "")
10263 (delete-char -4)
10264 (insert ";"))
10265 ((equal definition "ARRAY")
10266 (delete-region (point) (progn (forward-word-strictly -1)
10267 (point)))
10268 (vhdl-template-array 'type t))
10269 ((equal definition "RECORD")
10270 (setq mid-pos (point-marker))
10271 (delete-region (point) (progn (forward-word-strictly -1)
10272 (point)))
10273 (vhdl-template-record 'type name t))
10274 ((equal definition "ACCESS")
10275 (insert " ")
10276 (vhdl-template-field "type" ";"))
10277 ((equal definition "FILE")
10278 (vhdl-insert-keyword " OF ")
10279 (vhdl-template-field "type" ";"))
10280 ((equal definition "ENUM")
10281 (kill-word -1)
10282 (insert "(")
10283 (setq end-pos (point-marker))
10284 (insert ");"))
10285 (t (insert ";")))
10286 (when mid-pos
10287 (setq end-pos (point-marker))
10288 (goto-char mid-pos)
10289 (end-of-line))
10290 (vhdl-comment-insert-inline)
10291 (when end-pos (goto-char end-pos))))))
10293 (defun vhdl-template-use ()
10294 "Insert a use clause."
10295 (interactive)
10296 (let ((start (point)))
10297 (vhdl-prepare-search-1
10298 (vhdl-insert-keyword "USE ")
10299 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10300 (vhdl-insert-keyword "..ALL;")
10301 (backward-char 6)
10302 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
10303 (forward-char 1)
10304 (vhdl-template-field "package name")
10305 (forward-char 5))))))
10307 (defun vhdl-template-variable ()
10308 "Insert a variable declaration."
10309 (interactive)
10310 (let ((start (point))
10311 (in-arglist (vhdl-in-argument-list-p)))
10312 (vhdl-prepare-search-2
10313 (if (or (save-excursion
10314 (progn (vhdl-beginning-of-block)
10315 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10316 (save-excursion (backward-word-strictly 1)
10317 (looking-at "\\<shared\\>")))
10318 (vhdl-insert-keyword "VARIABLE ")
10319 (if (vhdl-standard-p '87)
10320 (error "ERROR: Not within sequential block")
10321 (vhdl-insert-keyword "SHARED VARIABLE "))))
10322 (when (vhdl-template-field "names" nil t start (point))
10323 (insert " : ")
10324 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10325 (vhdl-template-field "type")
10326 (if in-arglist
10327 (progn (insert ";")
10328 (vhdl-comment-insert-inline))
10329 (let ((position (point)))
10330 (insert " := ")
10331 (unless (vhdl-template-field "[initialization]" nil t)
10332 (delete-region position (point)))
10333 (insert ";")
10334 (vhdl-comment-insert-inline))))))
10336 (defun vhdl-template-wait ()
10337 "Insert a wait statement."
10338 (interactive)
10339 (vhdl-insert-keyword "WAIT ")
10340 (unless (vhdl-template-field
10341 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10342 nil t)
10343 (delete-char -1))
10344 (insert ";"))
10346 (defun vhdl-template-when ()
10347 "Indent correctly if within a case statement."
10348 (interactive)
10349 (let ((position (point))
10350 margin)
10351 (vhdl-prepare-search-2
10352 (if (and (= (current-column) (current-indentation))
10353 (vhdl-re-search-forward "\\<end\\>" nil t)
10354 (looking-at "\\s-*\\<case\\>"))
10355 (progn
10356 (setq margin (current-indentation))
10357 (goto-char position)
10358 (delete-horizontal-space)
10359 (indent-to (+ margin vhdl-basic-offset)))
10360 (goto-char position)))
10361 (vhdl-insert-keyword "WHEN ")))
10363 (defun vhdl-template-while-loop ()
10364 "Insert a while loop."
10365 (interactive)
10366 (let* ((margin (current-indentation))
10367 (start (point))
10368 label)
10369 (if (not (eq vhdl-optional-labels 'all))
10370 (vhdl-insert-keyword "WHILE ")
10371 (vhdl-insert-keyword ": WHILE ")
10372 (goto-char start)
10373 (setq label (vhdl-template-field "[label]" nil t))
10374 (unless label (delete-char 2))
10375 (forward-word-strictly 1)
10376 (forward-char 1))
10377 (when vhdl-conditions-in-parenthesis (insert "("))
10378 (when (vhdl-template-field "condition" nil t start (point))
10379 (when vhdl-conditions-in-parenthesis (insert ")"))
10380 (vhdl-insert-keyword " LOOP\n\n")
10381 (indent-to margin)
10382 (vhdl-insert-keyword "END LOOP")
10383 (insert (if label (concat " " label ";") ";"))
10384 (forward-line -1)
10385 (indent-to (+ margin vhdl-basic-offset)))))
10387 (defun vhdl-template-with ()
10388 "Insert a with statement (i.e. selected signal assignment)."
10389 (interactive)
10390 (vhdl-prepare-search-1
10391 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10392 (equal ";" (match-string 1)))
10393 (vhdl-template-selected-signal-asst)
10394 (vhdl-insert-keyword "WITH "))))
10396 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10397 ;; Special templates
10399 (defun vhdl-template-clocked-wait ()
10400 "Insert a wait statement for rising/falling clock edge."
10401 (interactive)
10402 (let ((start (point))
10403 clock)
10404 (vhdl-insert-keyword "WAIT UNTIL ")
10405 (when (setq clock
10406 (or (and (not (equal "" vhdl-clock-name))
10407 (progn (insert vhdl-clock-name) vhdl-clock-name))
10408 (vhdl-template-field "clock name" nil t start (point))))
10409 (insert "'event")
10410 (vhdl-insert-keyword " AND ")
10411 (insert clock)
10412 (insert
10413 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10414 (vhdl-comment-insert-inline
10415 (concat (if vhdl-clock-rising-edge "rising" "falling")
10416 " clock edge")))))
10418 (defun vhdl-template-seq-process (clock reset reset-kind)
10419 "Insert a template for the body of a sequential process."
10420 (let ((margin (current-indentation))
10421 position)
10422 (vhdl-insert-keyword "IF ")
10423 (when vhdl-conditions-in-parenthesis (insert "("))
10424 (when (eq reset-kind 'async)
10425 (insert reset " = "
10426 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10427 (when vhdl-conditions-in-parenthesis (insert ")"))
10428 (vhdl-insert-keyword " THEN")
10429 (vhdl-comment-insert-inline
10430 (concat "asynchronous reset (active "
10431 (if vhdl-reset-active-high "high" "low") ")"))
10432 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10433 (setq position (point))
10434 (insert "\n") (indent-to margin)
10435 (vhdl-insert-keyword "ELSIF ")
10436 (when vhdl-conditions-in-parenthesis (insert "(")))
10437 (if (eq vhdl-clock-edge-condition 'function)
10438 (insert (if vhdl-clock-rising-edge "rising" "falling")
10439 "_edge(" clock ")")
10440 (insert clock "'event")
10441 (vhdl-insert-keyword " AND ")
10442 (insert clock " = "
10443 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10444 (when vhdl-conditions-in-parenthesis (insert ")"))
10445 (vhdl-insert-keyword " THEN")
10446 (vhdl-comment-insert-inline
10447 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10448 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10449 (when (eq reset-kind 'sync)
10450 (vhdl-insert-keyword "IF ")
10451 (when vhdl-conditions-in-parenthesis (insert "("))
10452 (setq reset (or (and (not (equal "" vhdl-reset-name))
10453 (progn (insert vhdl-reset-name) vhdl-reset-name))
10454 (vhdl-template-field "reset name") "<reset>"))
10455 (insert " = "
10456 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10457 (when vhdl-conditions-in-parenthesis (insert ")"))
10458 (vhdl-insert-keyword " THEN")
10459 (vhdl-comment-insert-inline
10460 (concat "synchronous reset (active "
10461 (if vhdl-reset-active-high "high" "low") ")"))
10462 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10463 (setq position (point))
10464 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10465 (vhdl-insert-keyword "ELSE")
10466 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10467 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10468 (vhdl-insert-keyword "END IF;"))
10469 (when (eq reset-kind 'none)
10470 (setq position (point)))
10471 (insert "\n") (indent-to margin)
10472 (vhdl-insert-keyword "END IF;")
10473 (goto-char position)
10474 reset))
10476 (defun vhdl-template-standard-package (library package)
10477 "Insert specification of a standard package. Include a library
10478 specification, if not already there."
10479 (let ((margin (current-indentation)))
10480 (unless (equal library "std")
10481 (unless (or (save-excursion
10482 (vhdl-prepare-search-1
10483 (and (not (bobp))
10484 (re-search-backward
10485 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10486 library "\\|end\\)\\>") nil t)
10487 (match-string 2))))
10488 (equal (downcase library) "work"))
10489 (vhdl-insert-keyword "LIBRARY ")
10490 (insert library ";")
10491 (when package
10492 (insert "\n")
10493 (indent-to margin))))
10494 (when package
10495 (vhdl-insert-keyword "USE ")
10496 (insert library "." package)
10497 (vhdl-insert-keyword ".ALL;"))))
10499 (defun vhdl-template-package-numeric-bit ()
10500 "Insert specification of `numeric_bit' package."
10501 (interactive)
10502 (vhdl-template-standard-package "ieee" "numeric_bit"))
10504 (defun vhdl-template-package-numeric-std ()
10505 "Insert specification of `numeric_std' package."
10506 (interactive)
10507 (vhdl-template-standard-package "ieee" "numeric_std"))
10509 (defun vhdl-template-package-std-logic-1164 ()
10510 "Insert specification of `std_logic_1164' package."
10511 (interactive)
10512 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10514 (defun vhdl-template-package-std-logic-arith ()
10515 "Insert specification of `std_logic_arith' package."
10516 (interactive)
10517 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10519 (defun vhdl-template-package-std-logic-misc ()
10520 "Insert specification of `std_logic_misc' package."
10521 (interactive)
10522 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10524 (defun vhdl-template-package-std-logic-signed ()
10525 "Insert specification of `std_logic_signed' package."
10526 (interactive)
10527 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10529 (defun vhdl-template-package-std-logic-textio ()
10530 "Insert specification of `std_logic_textio' package."
10531 (interactive)
10532 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10534 (defun vhdl-template-package-std-logic-unsigned ()
10535 "Insert specification of `std_logic_unsigned' package."
10536 (interactive)
10537 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10539 (defun vhdl-template-package-textio ()
10540 "Insert specification of `textio' package."
10541 (interactive)
10542 (vhdl-template-standard-package "std" "textio"))
10544 (defun vhdl-template-package-fundamental-constants ()
10545 "Insert specification of `fundamental_constants' package."
10546 (interactive)
10547 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10549 (defun vhdl-template-package-material-constants ()
10550 "Insert specification of `material_constants' package."
10551 (interactive)
10552 (vhdl-template-standard-package "ieee" "material_constants"))
10554 (defun vhdl-template-package-energy-systems ()
10555 "Insert specification of `energy_systems' package."
10556 (interactive)
10557 (vhdl-template-standard-package "ieee" "energy_systems"))
10559 (defun vhdl-template-package-electrical-systems ()
10560 "Insert specification of `electrical_systems' package."
10561 (interactive)
10562 (vhdl-template-standard-package "ieee" "electrical_systems"))
10564 (defun vhdl-template-package-mechanical-systems ()
10565 "Insert specification of `mechanical_systems' package."
10566 (interactive)
10567 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10569 (defun vhdl-template-package-radiant-systems ()
10570 "Insert specification of `radiant_systems' package."
10571 (interactive)
10572 (vhdl-template-standard-package "ieee" "radiant_systems"))
10574 (defun vhdl-template-package-thermal-systems ()
10575 "Insert specification of `thermal_systems' package."
10576 (interactive)
10577 (vhdl-template-standard-package "ieee" "thermal_systems"))
10579 (defun vhdl-template-package-fluidic-systems ()
10580 "Insert specification of `fluidic_systems' package."
10581 (interactive)
10582 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10584 (defun vhdl-template-package-math-complex ()
10585 "Insert specification of `math_complex' package."
10586 (interactive)
10587 (vhdl-template-standard-package "ieee" "math_complex"))
10589 (defun vhdl-template-package-math-real ()
10590 "Insert specification of `math_real' package."
10591 (interactive)
10592 (vhdl-template-standard-package "ieee" "math_real"))
10594 (defun vhdl-template-directive (directive)
10595 "Insert directive."
10596 (unless (= (current-indentation) (current-column))
10597 (delete-horizontal-space)
10598 (insert " "))
10599 (insert "-- pragma " directive))
10601 (defun vhdl-template-directive-translate-on ()
10602 "Insert directive `translate_on'."
10603 (interactive)
10604 (vhdl-template-directive "translate_on"))
10606 (defun vhdl-template-directive-translate-off ()
10607 "Insert directive `translate_off'."
10608 (interactive)
10609 (vhdl-template-directive "translate_off"))
10611 (defun vhdl-template-directive-synthesis-on ()
10612 "Insert directive `synthesis_on'."
10613 (interactive)
10614 (vhdl-template-directive "synthesis_on"))
10616 (defun vhdl-template-directive-synthesis-off ()
10617 "Insert directive `synthesis_off'."
10618 (interactive)
10619 (vhdl-template-directive "synthesis_off"))
10621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10622 ;; Header and footer templates
10624 (defun vhdl-template-header (&optional file-title)
10625 "Insert a VHDL file header."
10626 (interactive)
10627 (unless (equal vhdl-file-header "")
10628 (let (pos)
10629 (save-excursion
10630 (goto-char (point-min))
10631 (vhdl-insert-string-or-file vhdl-file-header)
10632 (setq pos (point-marker)))
10633 (vhdl-template-replace-header-keywords
10634 (point-min-marker) pos file-title))))
10636 (defun vhdl-template-footer ()
10637 "Insert a VHDL file footer."
10638 (interactive)
10639 (unless (equal vhdl-file-footer "")
10640 (let (pos)
10641 (save-excursion
10642 (goto-char (point-max))
10643 (setq pos (point-marker))
10644 (vhdl-insert-string-or-file vhdl-file-footer)
10645 (unless (= (preceding-char) ?\n)
10646 (insert "\n")))
10647 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10649 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10650 is-model)
10651 "Replace keywords in header and footer."
10652 (let ((project-title (or (nth 0 (vhdl-aget vhdl-project-alist vhdl-project))
10653 ""))
10654 (project-desc (or (nth 9 (vhdl-aget vhdl-project-alist vhdl-project))
10655 ""))
10656 pos)
10657 (vhdl-prepare-search-2
10658 (save-excursion
10659 (goto-char beg)
10660 (while (search-forward "<projectdesc>" end t)
10661 (replace-match project-desc t t))
10662 (goto-char beg)
10663 (while (search-forward "<filename>" end t)
10664 (replace-match (buffer-name) t t))
10665 (goto-char beg)
10666 (while (search-forward "<copyright>" end t)
10667 (replace-match vhdl-copyright-string t t))
10668 (goto-char beg)
10669 (while (search-forward "<author>" end t)
10670 (replace-match "" t t)
10671 (insert (user-full-name))
10672 (when user-mail-address (insert " <" user-mail-address ">")))
10673 (goto-char beg)
10674 (while (search-forward "<authorfull>" end t)
10675 (replace-match (user-full-name) t t))
10676 (goto-char beg)
10677 (while (search-forward "<login>" end t)
10678 (replace-match (user-login-name) t t))
10679 (goto-char beg)
10680 (while (search-forward "<project>" end t)
10681 (replace-match project-title t t))
10682 (goto-char beg)
10683 (while (search-forward "<company>" end t)
10684 (replace-match vhdl-company-name t t))
10685 (goto-char beg)
10686 (while (search-forward "<platform>" end t)
10687 (replace-match vhdl-platform-spec t t))
10688 (goto-char beg)
10689 (while (search-forward "<standard>" end t)
10690 (replace-match
10691 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10692 ((vhdl-standard-p '93) "'93/02")
10693 ((vhdl-standard-p '08) "'08"))
10694 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10695 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10696 (goto-char beg)
10697 ;; Replace <RCS> with $, so that RCS for the source is
10698 ;; not over-enthusiastic with replacements
10699 (while (search-forward "<RCS>" end t)
10700 (replace-match "$" nil t))
10701 (goto-char beg)
10702 (while (search-forward "<date>" end t)
10703 (replace-match "" t t)
10704 (vhdl-template-insert-date))
10705 (goto-char beg)
10706 (while (search-forward "<year>" end t)
10707 (replace-match (format-time-string "%Y" nil) t t))
10708 (goto-char beg)
10709 (when file-title
10710 (while (search-forward "<title string>" end t)
10711 (replace-match file-title t t))
10712 (goto-char beg))
10713 (let (string)
10714 (while (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10715 (save-match-data
10716 (setq string (read-string (concat (match-string 1) ": "))))
10717 (replace-match string t t)))
10718 (goto-char beg)
10719 (when (and (not is-model) (search-forward "<cursor>" end t))
10720 (replace-match "" t t)
10721 (setq pos (point))))
10722 (when pos (goto-char pos))
10723 (unless is-model
10724 (when (or (not project-title) (equal project-title ""))
10725 (message "You can specify a project title in user option `vhdl-project-alist'"))
10726 (when (or (not project-desc) (equal project-desc ""))
10727 (message "You can specify a project description in user option `vhdl-project-alist'"))
10728 (when (equal vhdl-platform-spec "")
10729 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10730 (when (equal vhdl-company-name "")
10731 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10733 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10734 ;; Comment templates and functions
10736 (defun vhdl-comment-indent ()
10737 "Indent comments."
10738 (let* ((position (point))
10739 (col
10740 (progn
10741 (forward-line -1)
10742 (if (re-search-forward "--" position t)
10743 (- (current-column) 2) ; existing comment at bol stays there
10744 (goto-char position)
10745 (skip-chars-backward " \t")
10746 (max comment-column ; else indent to comment column
10747 (1+ (current-column))))))) ; except leave at least one space
10748 (goto-char position)
10749 col))
10751 (defun vhdl-comment-insert ()
10752 "Start a comment at the end of the line.
10753 If on line with code, indent at least `comment-column'.
10754 If starting after end-comment-column, start a new line."
10755 (interactive)
10756 (when (> (current-column) end-comment-column) (newline-and-indent))
10757 (if (or (looking-at "\\s-*$") ; end of line
10758 (and (not unread-command-events) ; called with key binding or menu
10759 (not (end-of-line))))
10760 (let (margin)
10761 (while (= (preceding-char) ?-) (delete-char -1))
10762 (setq margin (current-column))
10763 (delete-horizontal-space)
10764 (if (bolp)
10765 (progn (indent-to margin) (insert "--"))
10766 (insert " ")
10767 (indent-to comment-column)
10768 (insert "--"))
10769 (if (not unread-command-events) (insert " ")))
10770 ;; else code following current point implies commenting out code
10771 (let (next-input code)
10772 (while (= (preceding-char) ?-) (delete-char -2))
10773 (while (= (setq next-input (read-char)) 13) ; CR
10774 (insert "--") ; or have a space after it?
10775 (forward-char -2)
10776 (forward-line 1)
10777 (message "Enter CR if commenting out a line of code.")
10778 (setq code t))
10779 (unless code
10780 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10781 (push (vhdl-character-to-event next-input) ; pushback the char
10782 unread-command-events))))
10784 (defun vhdl-comment-display (&optional line-exists)
10785 "Add 2 comment lines at the current indent, making a display comment."
10786 (interactive)
10787 (let ((margin (current-indentation)))
10788 (unless line-exists (vhdl-comment-display-line))
10789 (insert "\n") (indent-to margin)
10790 (insert "\n") (indent-to margin)
10791 (vhdl-comment-display-line)
10792 (end-of-line -0)
10793 (insert "-- ")))
10795 (defun vhdl-comment-display-line ()
10796 "Displays one line of dashes."
10797 (interactive)
10798 (while (= (preceding-char) ?-) (delete-char -2))
10799 (insert "--")
10800 (let* ((col (current-column))
10801 (len (- end-comment-column col)))
10802 (insert-char vhdl-comment-display-line-char len)))
10804 (defun vhdl-comment-append-inline ()
10805 "Append empty inline comment to current line."
10806 (interactive)
10807 (end-of-line)
10808 (delete-horizontal-space)
10809 (insert " ")
10810 (indent-to comment-column)
10811 (insert "-- "))
10813 (defun vhdl-comment-insert-inline (&optional string always-insert)
10814 "Insert inline comment."
10815 (when (or (and string (or vhdl-self-insert-comments always-insert))
10816 (and (not string) vhdl-prompt-for-comments))
10817 (let ((position (point)))
10818 (insert " ")
10819 (indent-to comment-column)
10820 (insert "-- ")
10821 (if (not (or (and string (progn (insert string) t))
10822 (vhdl-template-field "[comment]" nil t)))
10823 (delete-region position (point))
10824 (while (= (preceding-char) ?\ ) (delete-char -1))))))
10826 (defun vhdl-comment-block ()
10827 "Insert comment for code block."
10828 (when vhdl-prompt-for-comments
10829 (let ((final-pos (point-marker)))
10830 (vhdl-prepare-search-2
10831 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10832 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10833 (let (margin)
10834 (back-to-indentation)
10835 (setq margin (current-column))
10836 (end-of-line -0)
10837 (if (bobp)
10838 (progn (insert "\n") (forward-line -1))
10839 (insert "\n"))
10840 (indent-to margin)
10841 (insert "-- purpose: ")
10842 (unless (vhdl-template-field "[description]" nil t)
10843 (vhdl-line-kill-entire)))))
10844 (goto-char final-pos))))
10846 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10847 "Comment out region if not commented out, uncomment otherwise."
10848 (interactive "r\nP")
10849 (save-excursion
10850 (goto-char (1- end))
10851 (end-of-line)
10852 (setq end (point-marker))
10853 (goto-char beg)
10854 (beginning-of-line)
10855 (setq beg (point))
10856 (if (looking-at (concat "\\s-*" comment-start))
10857 (comment-region beg end '(4))
10858 (comment-region beg end))))
10860 (defun vhdl-comment-uncomment-line (&optional arg)
10861 "Comment out line if not commented out, uncomment otherwise."
10862 (interactive "p")
10863 (save-excursion
10864 (beginning-of-line)
10865 (let ((position (point)))
10866 (forward-line (or arg 1))
10867 (vhdl-comment-uncomment-region position (point)))))
10869 (defun vhdl-comment-kill-region (beg end)
10870 "Kill comments in region."
10871 (interactive "r")
10872 (save-excursion
10873 (goto-char end)
10874 (setq end (point-marker))
10875 (goto-char beg)
10876 (beginning-of-line)
10877 (while (< (point) end)
10878 (if (looking-at "^\\(\\s-*--.*\n\\)")
10879 (progn (delete-region (match-beginning 1) (match-end 1)))
10880 (beginning-of-line 2)))))
10882 (defun vhdl-comment-kill-inline-region (beg end)
10883 "Kill inline comments in region."
10884 (interactive "r")
10885 (save-excursion
10886 (goto-char end)
10887 (setq end (point-marker))
10888 (goto-char beg)
10889 (beginning-of-line)
10890 (while (< (point) end)
10891 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10892 (delete-region (match-beginning 1) (match-end 1)))
10893 (beginning-of-line 2))))
10895 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10896 ;; Subtemplates
10898 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10899 "Insert a begin ... end pair with optional name after the end.
10900 Point is left between them."
10901 (let (position)
10902 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10903 (indent-to margin)
10904 (vhdl-insert-keyword "BEGIN")
10905 (when (and (or construct name) vhdl-self-insert-comments)
10906 (insert " --")
10907 (when construct (insert " ") (vhdl-insert-keyword construct))
10908 (when name (insert " " name)))
10909 (insert "\n")
10910 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10911 (indent-to (+ margin vhdl-basic-offset))
10912 (setq position (point))
10913 (insert "\n")
10914 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10915 (indent-to margin)
10916 (vhdl-insert-keyword "END")
10917 (when construct (insert " ") (vhdl-insert-keyword construct))
10918 (insert (if name (concat " " name) "") ";")
10919 (goto-char position)))
10921 (defun vhdl-template-argument-list (&optional is-function)
10922 "Read from user a procedure or function argument list."
10923 (insert " (")
10924 (let ((margin (current-column))
10925 (start (point))
10926 (end-pos (point))
10927 not-empty interface semicolon-pos)
10928 (unless vhdl-argument-list-indent
10929 (setq margin (+ (current-indentation) vhdl-basic-offset))
10930 (insert "\n")
10931 (indent-to margin))
10932 (setq interface (vhdl-template-field
10933 (concat "[CONSTANT | SIGNAL"
10934 (unless is-function " | VARIABLE") "]") " " t))
10935 (while (vhdl-template-field "[names]" nil t)
10936 (setq not-empty t)
10937 (insert " : ")
10938 (unless is-function
10939 (if (and interface (equal (upcase interface) "CONSTANT"))
10940 (vhdl-insert-keyword "IN ")
10941 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10942 (vhdl-template-field "type")
10943 (setq semicolon-pos (point))
10944 (insert ";")
10945 (vhdl-comment-insert-inline)
10946 (setq end-pos (point))
10947 (insert "\n")
10948 (indent-to margin)
10949 (setq interface (vhdl-template-field
10950 (concat "[CONSTANT | SIGNAL"
10951 (unless is-function " | VARIABLE") "]") " " t)))
10952 (delete-region end-pos (point))
10953 (when semicolon-pos (goto-char semicolon-pos))
10954 (if not-empty
10955 (progn (delete-char 1) (insert ")"))
10956 (delete-char -2))))
10958 (defun vhdl-template-generic-list (optional &optional no-value)
10959 "Read from user a generic spec argument list."
10960 (let (margin
10961 (start (point)))
10962 (vhdl-insert-keyword "GENERIC (")
10963 (setq margin (current-column))
10964 (unless vhdl-argument-list-indent
10965 (let ((position (point)))
10966 (back-to-indentation)
10967 (setq margin (+ (current-column) vhdl-basic-offset))
10968 (goto-char position)
10969 (insert "\n")
10970 (indent-to margin)))
10971 (let ((vhdl-generics (vhdl-template-field
10972 (concat (and optional "[") "name"
10973 (and no-value "s") (and optional "]"))
10974 nil optional)))
10975 (if (not vhdl-generics)
10976 (if optional
10977 (progn (vhdl-line-kill-entire) (end-of-line -0)
10978 (unless vhdl-argument-list-indent
10979 (vhdl-line-kill-entire) (end-of-line -0)))
10980 (vhdl-template-undo start (point))
10981 nil )
10982 (insert " : ")
10983 (let (semicolon-pos end-pos)
10984 (while vhdl-generics
10985 (vhdl-template-field "type")
10986 (if no-value
10987 (progn (setq semicolon-pos (point))
10988 (insert ";"))
10989 (insert " := ")
10990 (unless (vhdl-template-field "[value]" nil t)
10991 (delete-char -4))
10992 (setq semicolon-pos (point))
10993 (insert ";"))
10994 (vhdl-comment-insert-inline)
10995 (setq end-pos (point))
10996 (insert "\n")
10997 (indent-to margin)
10998 (setq vhdl-generics (vhdl-template-field
10999 (concat "[name" (and no-value "s") "]")
11000 " : " t)))
11001 (delete-region end-pos (point))
11002 (goto-char semicolon-pos)
11003 (insert ")")
11004 (end-of-line)
11005 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
11006 t)))))
11008 (defun vhdl-template-port-list (optional)
11009 "Read from user a port spec argument list."
11010 (let ((start (point))
11011 margin vhdl-ports object)
11012 (vhdl-insert-keyword "PORT (")
11013 (setq margin (current-column))
11014 (unless vhdl-argument-list-indent
11015 (let ((position (point)))
11016 (back-to-indentation)
11017 (setq margin (+ (current-column) vhdl-basic-offset))
11018 (goto-char position)
11019 (insert "\n")
11020 (indent-to margin)))
11021 (when (vhdl-standard-p 'ams)
11022 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11023 " " t)))
11024 (setq vhdl-ports (vhdl-template-field
11025 (concat (and optional "[") "names" (and optional "]"))
11026 nil optional))
11027 (if (not vhdl-ports)
11028 (if optional
11029 (progn (vhdl-line-kill-entire) (end-of-line -0)
11030 (unless vhdl-argument-list-indent
11031 (vhdl-line-kill-entire) (end-of-line -0)))
11032 (vhdl-template-undo start (point))
11033 nil)
11034 (insert " : ")
11035 (let (semicolon-pos end-pos)
11036 (while vhdl-ports
11037 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
11038 (vhdl-template-field "IN | OUT | INOUT" " "))
11039 ((equal "QUANTITY" (upcase object))
11040 (vhdl-template-field "[IN | OUT]" " " t)))
11041 (vhdl-template-field
11042 (if (and object (equal "TERMINAL" (upcase object)))
11043 "nature" "type"))
11044 (setq semicolon-pos (point))
11045 (insert ";")
11046 (vhdl-comment-insert-inline)
11047 (setq end-pos (point))
11048 (insert "\n")
11049 (indent-to margin)
11050 (when (vhdl-standard-p 'ams)
11051 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11052 " " t)))
11053 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
11054 (delete-region end-pos (point))
11055 (goto-char semicolon-pos)
11056 (insert ")")
11057 (end-of-line)
11058 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
11059 t))))
11061 (defun vhdl-template-generate-body (margin label)
11062 "Insert body for generate template."
11063 (vhdl-insert-keyword " GENERATE")
11064 (insert "\n\n")
11065 (indent-to margin)
11066 (vhdl-insert-keyword "END GENERATE ")
11067 (insert label ";")
11068 (end-of-line 0)
11069 (indent-to (+ margin vhdl-basic-offset)))
11071 (defun vhdl-template-insert-date ()
11072 "Insert date in appropriate format."
11073 (interactive)
11074 (insert
11075 (cond
11076 ;; 'american, 'european, 'scientific kept for backward compatibility
11077 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
11078 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
11079 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
11080 (t (format-time-string vhdl-date-format nil)))))
11082 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11083 ;; Help functions
11085 (defun vhdl-electric-space (count)
11086 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
11087 if in comment and past end-comment-column."
11088 (interactive "p")
11089 (cond ((vhdl-in-comment-p)
11090 (self-insert-command count)
11091 (cond ((>= (current-column) (+ 2 end-comment-column))
11092 (backward-char 1)
11093 (skip-chars-backward "^ \t\n\r\f")
11094 (indent-new-comment-line)
11095 (skip-chars-forward "^ \t\n\r\f")
11096 (forward-char 1))
11097 ((>= (current-column) end-comment-column)
11098 (indent-new-comment-line))
11099 (t nil)))
11100 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
11101 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
11102 (vhdl-prepare-search-1
11103 (or (expand-abbrev) (vhdl-fix-case-word -1)))
11104 (self-insert-command count))
11105 (t (self-insert-command count))))
11107 (defun vhdl-template-field (prompt &optional follow-string optional
11108 begin end is-string default)
11109 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
11110 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
11111 an empty string is inserted, return nil and call `vhdl-template-undo' for
11112 the region between BEGIN and END. IS-STRING indicates whether a string
11113 with double-quotes is to be inserted. DEFAULT specifies a default string."
11114 (let ((position (point))
11115 string)
11116 (insert "<" prompt ">")
11117 (setq string
11118 (condition-case ()
11119 (read-from-minibuffer (concat prompt ": ")
11120 (or (and is-string '("\"\"" . 2)) default)
11121 vhdl-minibuffer-local-map)
11122 (quit (if (and optional begin end)
11123 (progn (beep) "")
11124 (keyboard-quit)))))
11125 (when (or (not (equal string "")) optional)
11126 (delete-region position (point)))
11127 (when (and (equal string "") optional begin end)
11128 (vhdl-template-undo begin end)
11129 (message "Template aborted"))
11130 (unless (equal string "")
11131 (insert string)
11132 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
11133 vhdl-keywords-regexp)
11134 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
11135 vhdl-types-regexp)
11136 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
11137 (concat "'" vhdl-attributes-regexp))
11138 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
11139 vhdl-enum-values-regexp)
11140 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
11141 vhdl-constants-regexp))
11142 (when (or (not (equal string "")) (not optional))
11143 (insert (or follow-string "")))
11144 (if (equal string "") nil string)))
11146 (defun vhdl-decision-query (string prompt &optional optional)
11147 "Query a decision from the user."
11148 (let ((start (point)))
11149 (when string (vhdl-insert-keyword (concat string " ")))
11150 (message "%s" (or prompt ""))
11151 (let ((char (read-char)))
11152 (delete-region start (point))
11153 (if (and optional (eq char ?\r))
11154 (progn (insert " ")
11155 (unexpand-abbrev)
11156 (throw 'abort "ERROR: Template aborted"))
11157 char))))
11159 (defun vhdl-insert-keyword (keyword)
11160 "Insert KEYWORD and adjust case."
11161 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
11163 (defun vhdl-case-keyword (keyword)
11164 "Adjust case of KEYWORD."
11165 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
11167 (defun vhdl-case-word (num)
11168 "Adjust case of following NUM words."
11169 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
11171 (defun vhdl-minibuffer-tab (&optional prefix-arg)
11172 "If preceding character is part of a word or a paren then hippie-expand,
11173 else insert tab (used for word completion in VHDL minibuffer)."
11174 (interactive "P")
11175 (cond
11176 ;; expand word
11177 ((= (char-syntax (preceding-char)) ?w)
11178 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11179 (case-replace nil)
11180 (hippie-expand-only-buffers
11181 (or (and (boundp 'hippie-expand-only-buffers)
11182 hippie-expand-only-buffers)
11183 '(vhdl-mode))))
11184 (vhdl-expand-abbrev prefix-arg)))
11185 ;; expand parenthesis
11186 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
11187 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11188 (case-replace nil))
11189 (vhdl-expand-paren prefix-arg)))
11190 ;; insert tab
11191 (t (insert-tab))))
11193 (defun vhdl-template-search-prompt ()
11194 "Search for left out template prompts and query again."
11195 (interactive)
11196 (vhdl-prepare-search-2
11197 (when (or (re-search-forward
11198 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
11199 (re-search-backward
11200 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
11201 (let ((string (match-string 1)))
11202 (replace-match "")
11203 (vhdl-template-field string)))))
11205 (defun vhdl-template-undo (begin end)
11206 "Undo aborted template by deleting region and unexpanding the keyword."
11207 (cond (vhdl-template-invoked-by-hook
11208 (goto-char end)
11209 (insert " ")
11210 (delete-region begin end)
11211 (unexpand-abbrev))
11212 (t (delete-region begin end))))
11214 (defun vhdl-insert-string-or-file (string)
11215 "Insert STRING or file contents if STRING is an existing file name."
11216 (unless (equal string "")
11217 (let ((file-name
11218 (progn (string-match "^\\([^\n]+\\)" string)
11219 (vhdl-resolve-env-variable (match-string 1 string)))))
11220 (if (file-exists-p file-name)
11221 (forward-char (cadr (insert-file-contents file-name)))
11222 (insert string)))))
11224 (defun vhdl-beginning-of-block ()
11225 "Move cursor to the beginning of the enclosing block."
11226 (let (pos)
11227 (vhdl-prepare-search-2
11228 (save-excursion
11229 (beginning-of-line)
11230 ;; search backward for block beginning or end
11231 (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|context\\|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))
11232 ;; not consider subprogram declarations
11233 (or (and (match-string 5)
11234 (save-match-data
11235 (save-excursion
11236 (goto-char (match-end 5))
11237 (forward-word-strictly 1)
11238 (vhdl-forward-syntactic-ws)
11239 (when (looking-at "(")
11240 (forward-sexp))
11241 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11242 (match-string 1)))
11243 ;; not consider configuration specifications
11244 (and (match-string 6)
11245 (save-match-data
11246 (save-excursion
11247 (vhdl-end-of-block)
11248 (beginning-of-line)
11249 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11250 (match-string 2))
11251 ;; skip subblock if block end found
11252 (vhdl-beginning-of-block))))
11253 (when pos (goto-char pos))))
11255 (defun vhdl-end-of-block ()
11256 "Move cursor to the end of the enclosing block."
11257 (let (pos)
11258 (vhdl-prepare-search-2
11259 (save-excursion
11260 (end-of-line)
11261 ;; search forward for block beginning or end
11262 (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|context\\|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))
11263 ;; not consider subprogram declarations
11264 (or (and (match-string 5)
11265 (save-match-data
11266 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11267 (match-string 1)))
11268 ;; not consider configuration specifications
11269 (and (match-string 6)
11270 (save-match-data
11271 (save-excursion
11272 (vhdl-end-of-block)
11273 (beginning-of-line)
11274 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11275 (not (match-string 2)))
11276 ;; skip subblock if block beginning found
11277 (vhdl-end-of-block))))
11278 (when pos (goto-char pos))))
11280 (defun vhdl-sequential-statement-p ()
11281 "Check if point is within sequential statement part."
11282 (let ((start (point)))
11283 (save-excursion
11284 (vhdl-prepare-search-2
11285 ;; is sequential statement if ...
11286 (and (re-search-backward "^\\s-*begin\\>" nil t)
11287 ;; ... point is between "begin" and "end" of ...
11288 (progn (vhdl-end-of-block)
11289 (< start (point)))
11290 ;; ... a sequential block
11291 (progn (vhdl-beginning-of-block)
11292 (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\\)\\)\\>")))))))
11294 (defun vhdl-in-argument-list-p ()
11295 "Check if within an argument list."
11296 (save-excursion
11297 (vhdl-prepare-search-2
11298 (or (string-match "arglist"
11299 (format "%s" (caar (vhdl-get-syntactic-context))))
11300 (progn (beginning-of-line)
11301 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11303 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11304 ;; Abbrev hooks
11306 (defun vhdl-hooked-abbrev (func)
11307 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11308 but not if inside a comment or quote."
11309 (if (or (vhdl-in-literal)
11310 (save-excursion
11311 (forward-word-strictly -1)
11312 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11313 (progn
11314 (insert " ")
11315 (unexpand-abbrev)
11316 (backward-word-strictly 1)
11317 (vhdl-case-word 1)
11318 (delete-char 1))
11319 (if (not vhdl-electric-mode)
11320 (progn
11321 (insert " ")
11322 (unexpand-abbrev)
11323 (backward-word-strictly 1)
11324 (vhdl-case-word 1)
11325 (delete-char 1))
11326 (let ((invoke-char vhdl-last-input-event)
11327 (abbrev-mode -1)
11328 (vhdl-template-invoked-by-hook t))
11329 (let ((caught (catch 'abort
11330 (funcall func))))
11331 (when (stringp caught) (message "%s" caught)))
11332 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
11333 ;; delete CR which is still in event queue
11334 (if (fboundp 'enqueue-eval-event)
11335 (enqueue-eval-event 'delete-char -1)
11336 (push (vhdl-character-to-event ?\177) ; push back a delete char
11337 unread-command-events))))))
11339 (defun vhdl-template-alias-hook ()
11340 (vhdl-hooked-abbrev 'vhdl-template-alias))
11341 (defun vhdl-template-architecture-hook ()
11342 (vhdl-hooked-abbrev 'vhdl-template-architecture))
11343 (defun vhdl-template-assert-hook ()
11344 (vhdl-hooked-abbrev 'vhdl-template-assert))
11345 (defun vhdl-template-attribute-hook ()
11346 (vhdl-hooked-abbrev 'vhdl-template-attribute))
11347 (defun vhdl-template-block-hook ()
11348 (vhdl-hooked-abbrev 'vhdl-template-block))
11349 (defun vhdl-template-break-hook ()
11350 (vhdl-hooked-abbrev 'vhdl-template-break))
11351 (defun vhdl-template-case-hook ()
11352 (vhdl-hooked-abbrev 'vhdl-template-case))
11353 (defun vhdl-template-component-hook ()
11354 (vhdl-hooked-abbrev 'vhdl-template-component))
11355 (defun vhdl-template-instance-hook ()
11356 (vhdl-hooked-abbrev 'vhdl-template-instance))
11357 (defun vhdl-template-conditional-signal-asst-hook ()
11358 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
11359 (defun vhdl-template-configuration-hook ()
11360 (vhdl-hooked-abbrev 'vhdl-template-configuration))
11361 (defun vhdl-template-constant-hook ()
11362 (vhdl-hooked-abbrev 'vhdl-template-constant))
11363 (defun vhdl-template-context-hook ()
11364 (vhdl-hooked-abbrev 'vhdl-template-context))
11365 (defun vhdl-template-disconnect-hook ()
11366 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
11367 (defun vhdl-template-display-comment-hook ()
11368 (vhdl-hooked-abbrev 'vhdl-comment-display))
11369 (defun vhdl-template-else-hook ()
11370 (vhdl-hooked-abbrev 'vhdl-template-else))
11371 (defun vhdl-template-elsif-hook ()
11372 (vhdl-hooked-abbrev 'vhdl-template-elsif))
11373 (defun vhdl-template-entity-hook ()
11374 (vhdl-hooked-abbrev 'vhdl-template-entity))
11375 (defun vhdl-template-exit-hook ()
11376 (vhdl-hooked-abbrev 'vhdl-template-exit))
11377 (defun vhdl-template-file-hook ()
11378 (vhdl-hooked-abbrev 'vhdl-template-file))
11379 (defun vhdl-template-for-hook ()
11380 (vhdl-hooked-abbrev 'vhdl-template-for))
11381 (defun vhdl-template-function-hook ()
11382 (vhdl-hooked-abbrev 'vhdl-template-function))
11383 (defun vhdl-template-generic-hook ()
11384 (vhdl-hooked-abbrev 'vhdl-template-generic))
11385 (defun vhdl-template-group-hook ()
11386 (vhdl-hooked-abbrev 'vhdl-template-group))
11387 (defun vhdl-template-library-hook ()
11388 (vhdl-hooked-abbrev 'vhdl-template-library))
11389 (defun vhdl-template-limit-hook ()
11390 (vhdl-hooked-abbrev 'vhdl-template-limit))
11391 (defun vhdl-template-if-hook ()
11392 (vhdl-hooked-abbrev 'vhdl-template-if))
11393 (defun vhdl-template-bare-loop-hook ()
11394 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
11395 (defun vhdl-template-map-hook ()
11396 (vhdl-hooked-abbrev 'vhdl-template-map))
11397 (defun vhdl-template-nature-hook ()
11398 (vhdl-hooked-abbrev 'vhdl-template-nature))
11399 (defun vhdl-template-next-hook ()
11400 (vhdl-hooked-abbrev 'vhdl-template-next))
11401 (defun vhdl-template-others-hook ()
11402 (vhdl-hooked-abbrev 'vhdl-template-others))
11403 (defun vhdl-template-package-hook ()
11404 (vhdl-hooked-abbrev 'vhdl-template-package))
11405 (defun vhdl-template-port-hook ()
11406 (vhdl-hooked-abbrev 'vhdl-template-port))
11407 (defun vhdl-template-procedural-hook ()
11408 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11409 (defun vhdl-template-procedure-hook ()
11410 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11411 (defun vhdl-template-process-hook ()
11412 (vhdl-hooked-abbrev 'vhdl-template-process))
11413 (defun vhdl-template-quantity-hook ()
11414 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11415 (defun vhdl-template-report-hook ()
11416 (vhdl-hooked-abbrev 'vhdl-template-report))
11417 (defun vhdl-template-return-hook ()
11418 (vhdl-hooked-abbrev 'vhdl-template-return))
11419 (defun vhdl-template-selected-signal-asst-hook ()
11420 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11421 (defun vhdl-template-signal-hook ()
11422 (vhdl-hooked-abbrev 'vhdl-template-signal))
11423 (defun vhdl-template-subnature-hook ()
11424 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11425 (defun vhdl-template-subtype-hook ()
11426 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11427 (defun vhdl-template-terminal-hook ()
11428 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11429 (defun vhdl-template-type-hook ()
11430 (vhdl-hooked-abbrev 'vhdl-template-type))
11431 (defun vhdl-template-use-hook ()
11432 (vhdl-hooked-abbrev 'vhdl-template-use))
11433 (defun vhdl-template-variable-hook ()
11434 (vhdl-hooked-abbrev 'vhdl-template-variable))
11435 (defun vhdl-template-wait-hook ()
11436 (vhdl-hooked-abbrev 'vhdl-template-wait))
11437 (defun vhdl-template-when-hook ()
11438 (vhdl-hooked-abbrev 'vhdl-template-when))
11439 (defun vhdl-template-while-loop-hook ()
11440 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11441 (defun vhdl-template-with-hook ()
11442 (vhdl-hooked-abbrev 'vhdl-template-with))
11443 (defun vhdl-template-and-hook ()
11444 (vhdl-hooked-abbrev 'vhdl-template-and))
11445 (defun vhdl-template-or-hook ()
11446 (vhdl-hooked-abbrev 'vhdl-template-or))
11447 (defun vhdl-template-nand-hook ()
11448 (vhdl-hooked-abbrev 'vhdl-template-nand))
11449 (defun vhdl-template-nor-hook ()
11450 (vhdl-hooked-abbrev 'vhdl-template-nor))
11451 (defun vhdl-template-xor-hook ()
11452 (vhdl-hooked-abbrev 'vhdl-template-xor))
11453 (defun vhdl-template-xnor-hook ()
11454 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11455 (defun vhdl-template-not-hook ()
11456 (vhdl-hooked-abbrev 'vhdl-template-not))
11458 (defun vhdl-template-default-hook ()
11459 (vhdl-hooked-abbrev 'vhdl-template-default))
11460 (defun vhdl-template-default-indent-hook ()
11461 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11463 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11464 ;; Template insertion from completion list
11466 (defun vhdl-template-insert-construct (name)
11467 "Insert the built-in construct template with NAME."
11468 (interactive
11469 (list (let ((completion-ignore-case t))
11470 (completing-read "Construct name: "
11471 vhdl-template-construct-alist nil t))))
11472 (vhdl-template-insert-fun
11473 (cadr (assoc name vhdl-template-construct-alist))))
11475 (defun vhdl-template-insert-package (name)
11476 "Insert the built-in package template with NAME."
11477 (interactive
11478 (list (let ((completion-ignore-case t))
11479 (completing-read "Package name: "
11480 vhdl-template-package-alist nil t))))
11481 (vhdl-template-insert-fun
11482 (cadr (assoc name vhdl-template-package-alist))))
11484 (defun vhdl-template-insert-directive (name)
11485 "Insert the built-in directive template with NAME."
11486 (interactive
11487 (list (let ((completion-ignore-case t))
11488 (completing-read "Directive name: "
11489 vhdl-template-directive-alist nil t))))
11490 (vhdl-template-insert-fun
11491 (cadr (assoc name vhdl-template-directive-alist))))
11493 (defun vhdl-template-insert-fun (fun)
11494 "Call FUN to insert a built-in template."
11495 (let ((caught (catch 'abort (when fun (funcall fun)))))
11496 (when (stringp caught) (message "%s" caught))))
11499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11500 ;;; Models
11501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11503 (defun vhdl-model-insert (model-name)
11504 "Insert the user model with name MODEL-NAME."
11505 (interactive
11506 (let ((completion-ignore-case t))
11507 (list (completing-read "Model name: " vhdl-model-alist))))
11508 (indent-according-to-mode)
11509 (let ((start (point-marker))
11510 (margin (current-indentation))
11511 model position prompt string end)
11512 (vhdl-prepare-search-2
11513 (when (setq model (assoc model-name vhdl-model-alist))
11514 ;; insert model
11515 (beginning-of-line)
11516 (delete-horizontal-space)
11517 (goto-char start)
11518 (vhdl-insert-string-or-file (nth 1 model))
11519 (setq end (point-marker))
11520 ;; indent code
11521 (goto-char start)
11522 (beginning-of-line)
11523 (while (< (point) end)
11524 (unless (looking-at "^$")
11525 (insert-char ? margin))
11526 (beginning-of-line 2))
11527 (goto-char start)
11528 ;; insert clock
11529 (unless (equal "" vhdl-clock-name)
11530 (while (re-search-forward "<clock>" end t)
11531 (replace-match vhdl-clock-name)))
11532 (goto-char start)
11533 ;; insert reset
11534 (unless (equal "" vhdl-reset-name)
11535 (while (re-search-forward "<reset>" end t)
11536 (replace-match vhdl-reset-name)))
11537 ;; replace header prompts
11538 (vhdl-template-replace-header-keywords start end nil t)
11539 (goto-char start)
11540 ;; query other prompts
11541 (while (re-search-forward
11542 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11543 (unless (equal "cursor" (match-string 1))
11544 (setq position (match-beginning 1))
11545 (setq prompt (match-string 1))
11546 (replace-match "")
11547 (setq string (vhdl-template-field prompt nil t))
11548 ;; replace occurrences of same prompt
11549 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11550 (replace-match (or string "")))
11551 (goto-char position)))
11552 (goto-char start)
11553 ;; goto final position
11554 (if (re-search-forward "<cursor>" end t)
11555 (replace-match "")
11556 (goto-char end))))))
11558 (defun vhdl-model-defun ()
11559 "Define help and hook functions for user models."
11560 (let ((model-alist vhdl-model-alist)
11561 model-name model-keyword)
11562 (while model-alist
11563 ;; define functions for user models that can be invoked from menu and key
11564 ;; bindings and which themselves call `vhdl-model-insert' with the model
11565 ;; name as argument
11566 (setq model-name (nth 0 (car model-alist)))
11567 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11568 ,(concat "Insert model for \"" model-name "\".")
11569 (interactive)
11570 (vhdl-model-insert ,model-name)))
11571 ;; define hooks for user models that are invoked from keyword abbrevs
11572 (setq model-keyword (nth 3 (car model-alist)))
11573 (unless (equal model-keyword "")
11574 (eval `(defun
11575 ,(vhdl-function-name
11576 "vhdl-model" model-name "hook") ()
11577 (vhdl-hooked-abbrev
11578 ',(vhdl-function-name "vhdl-model" model-name)))))
11579 (setq model-alist (cdr model-alist)))))
11581 (vhdl-model-defun)
11584 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11585 ;;; Port translation
11586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11588 (defvar vhdl-port-list nil
11589 "Variable to hold last port map parsed.")
11590 ;; structure: (parenthesized expression means list of such entries)
11591 ;; (ent-name
11592 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11593 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11594 ;; (lib-name pack-key))
11596 (defun vhdl-parse-string (string &optional optional)
11597 "Check that the text following point matches the regexp in STRING."
11598 (if (looking-at string)
11599 (progn (goto-char (match-end 0))
11600 (when (vhdl-in-literal)
11601 (end-of-line))
11602 (point))
11603 (unless optional
11604 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11605 (vhdl-current-line) string)))
11606 nil))
11608 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11609 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11610 (vhdl-prepare-search-1
11611 (if (string-match (car regexp-cons) string)
11612 (if adjust-case
11613 (funcall vhdl-file-name-case
11614 (replace-match (cdr regexp-cons) t nil string))
11615 (replace-match (cdr regexp-cons) t nil string))
11616 string)))
11618 (defun vhdl-parse-group-comment ()
11619 "Parse comment and empty lines between groups of lines."
11620 (let ((start (point))
11621 string)
11622 (vhdl-forward-comment (point-max))
11623 (setq string (buffer-substring-no-properties start (point)))
11624 (vhdl-forward-syntactic-ws)
11625 ;; strip off leading blanks and first newline
11626 (while (string-match "^\\(\\s-+\\)" string)
11627 (setq string (concat (substring string 0 (match-beginning 1))
11628 (substring string (match-end 1)))))
11629 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11630 (substring string 1)
11631 string)))
11633 (defun vhdl-paste-group-comment (string indent)
11634 "Paste comment and empty lines from STRING between groups of lines
11635 with INDENT."
11636 (let ((pos (point-marker)))
11637 (when (> indent 0)
11638 (while (string-match "^\\(--\\)" string)
11639 (setq string (concat (substring string 0 (match-beginning 1))
11640 (make-string indent ? )
11641 (substring string (match-beginning 1))))))
11642 (beginning-of-line)
11643 (insert string)
11644 (goto-char pos)))
11646 (defvar vhdl-port-flattened nil
11647 "Indicates whether a port has been flattened.")
11649 (defun vhdl-port-flatten (&optional as-alist)
11650 "Flatten port list so that only one generic/port exists per line.
11651 This operation is performed on an internally stored port and is only
11652 reflected in a subsequent paste operation."
11653 (interactive)
11654 (if (not vhdl-port-list)
11655 (error "ERROR: No port has been read")
11656 (message "Flattening port for next paste...")
11657 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11658 (old-vhdl-port-list (cdr vhdl-port-list))
11659 old-port-list new-port-list old-port new-port names)
11660 ;; traverse port list and flatten entries
11661 (while (cdr old-vhdl-port-list)
11662 (setq old-port-list (car old-vhdl-port-list))
11663 (setq new-port-list nil)
11664 (while old-port-list
11665 (setq old-port (car old-port-list))
11666 (setq names (car old-port))
11667 (while names
11668 (setq new-port (cons (if as-alist (car names) (list (car names)))
11669 (cdr old-port)))
11670 (setq new-port-list (append new-port-list (list new-port)))
11671 (setq names (cdr names)))
11672 (setq old-port-list (cdr old-port-list)))
11673 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11674 (setq new-vhdl-port-list (append new-vhdl-port-list
11675 (list new-port-list))))
11676 (setq vhdl-port-list
11677 (append new-vhdl-port-list (list old-vhdl-port-list))
11678 vhdl-port-flattened t)
11679 (message "Flattening port for next paste...done"))))
11681 (defvar vhdl-port-reversed-direction nil
11682 "Indicates whether port directions are reversed.")
11684 (defun vhdl-port-reverse-direction ()
11685 "Reverse direction for all ports (useful in testbenches).
11686 This operation is performed on an internally stored port and is only
11687 reflected in a subsequent paste operation."
11688 (interactive)
11689 (if (not vhdl-port-list)
11690 (error "ERROR: No port has been read")
11691 (message "Reversing port directions for next paste...")
11692 (let ((port-list (nth 2 vhdl-port-list))
11693 port-dir-car port-dir)
11694 ;; traverse port list and reverse directions
11695 (while port-list
11696 (setq port-dir-car (cddr (car port-list))
11697 port-dir (car port-dir-car))
11698 (setcar port-dir-car
11699 (cond ((equal port-dir "in") "out")
11700 ((equal port-dir "IN") "OUT")
11701 ((equal port-dir "out") "in")
11702 ((equal port-dir "OUT") "IN")
11703 (t port-dir)))
11704 (setq port-list (cdr port-list)))
11705 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11706 (message "Reversing port directions for next paste...done"))))
11708 (defun vhdl-port-copy ()
11709 "Get generic and port information from an entity or component declaration."
11710 (interactive)
11711 (save-excursion
11712 (let (parse-error end-of-list
11713 decl-type name generic-list port-list context-clause
11714 object names direct type init comment group-comment)
11715 (vhdl-prepare-search-2
11716 (setq
11717 parse-error
11718 (catch 'parse
11719 ;; check if within entity or component declaration
11720 (end-of-line)
11721 (when (or (not (re-search-backward
11722 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11723 (equal "END" (upcase (match-string 1))))
11724 (throw 'parse "ERROR: Not within an entity or component declaration"))
11725 (setq decl-type (downcase (match-string-no-properties 1)))
11726 (forward-word-strictly 1)
11727 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11728 (setq name (match-string-no-properties 1))
11729 (message "Reading port of %s \"%s\"..." decl-type name)
11730 (vhdl-forward-syntactic-ws)
11731 ;; parse generic clause
11732 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11733 ;; parse group comment and spacing
11734 (setq group-comment (vhdl-parse-group-comment))
11735 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11736 (while (not end-of-list)
11737 ;; parse names (accept extended identifiers)
11738 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11739 (setq names (list (match-string-no-properties 1)))
11740 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11741 (setq names
11742 (append names (list (match-string-no-properties 1)))))
11743 ;; parse type
11744 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11745 (setq type (match-string-no-properties 1))
11746 (when (vhdl-in-comment-p) ; if stuck in comment
11747 (setq type (concat type (and (vhdl-parse-string ".*")
11748 (match-string-no-properties 0)))))
11749 (setq comment nil)
11750 (while (looking-at "(")
11751 (setq type
11752 (concat type
11753 (buffer-substring-no-properties
11754 (point) (progn (forward-sexp) (point)))
11755 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11756 (match-string-no-properties 1)))))
11757 ;; special case: closing parenthesis is on separate line
11758 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11759 (setq comment (substring type (match-beginning 2)))
11760 (setq type (substring type 0 (match-beginning 1))))
11761 ;; strip of trailing group-comment
11762 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11763 (setq type (substring type 0 (match-end 1)))
11764 ;; parse initialization expression
11765 (setq init nil)
11766 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11767 (vhdl-parse-string "\\([^();\n]*\\)")
11768 (setq init (match-string-no-properties 1))
11769 (while (looking-at "(")
11770 (setq init
11771 (concat init
11772 (buffer-substring-no-properties
11773 (point) (progn (forward-sexp) (point)))
11774 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11775 (match-string-no-properties 1))))))
11776 ;; special case: closing parenthesis is on separate line
11777 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11778 (setq comment (substring init (match-beginning 2)))
11779 (setq init (substring init 0 (match-beginning 1)))
11780 (vhdl-forward-syntactic-ws))
11781 (skip-chars-forward " \t")
11782 ;; parse inline comment, special case: as above, no initial.
11783 (unless comment
11784 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11785 (match-string-no-properties 1))))
11786 (vhdl-forward-syntactic-ws)
11787 (setq end-of-list (vhdl-parse-string ")" t))
11788 (vhdl-parse-string "\\s-*;\\s-*")
11789 ;; parse inline comment
11790 (unless comment
11791 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11792 (match-string-no-properties 1))))
11793 ;; save everything in list
11794 (setq generic-list (append generic-list
11795 (list (list names type init
11796 comment group-comment))))
11797 ;; parse group comment and spacing
11798 (setq group-comment (vhdl-parse-group-comment))))
11799 ;; parse port clause
11800 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11801 ;; parse group comment and spacing
11802 (setq group-comment (vhdl-parse-group-comment))
11803 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11804 (while (not end-of-list)
11805 ;; parse object
11806 (setq object
11807 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11808 (match-string-no-properties 1)))
11809 ;; parse names (accept extended identifiers)
11810 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11811 (setq names (list (match-string-no-properties 1)))
11812 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11813 (setq names (append names (list (match-string-no-properties 1)))))
11814 ;; parse direction
11815 (vhdl-parse-string ":[ \t\n\r\f]*")
11816 (setq direct
11817 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11818 (match-string-no-properties 1)))
11819 ;; parse type
11820 (vhdl-parse-string "\\([^();\n]+\\)")
11821 (setq type (match-string-no-properties 1))
11822 (when (vhdl-in-comment-p) ; if stuck in comment
11823 (setq type (concat type (and (vhdl-parse-string ".*")
11824 (match-string-no-properties 0)))))
11825 (setq comment nil)
11826 (while (looking-at "(")
11827 (setq type (concat type
11828 (buffer-substring-no-properties
11829 (point) (progn (forward-sexp) (point)))
11830 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11831 (match-string-no-properties 1)))))
11832 ;; special case: closing parenthesis is on separate line
11833 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11834 (setq comment (substring type (match-beginning 2)))
11835 (setq type (substring type 0 (match-beginning 1))))
11836 ;; strip of trailing group-comment
11837 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11838 (setq type (substring type 0 (match-end 1)))
11839 (vhdl-forward-syntactic-ws)
11840 (setq end-of-list (vhdl-parse-string ")" t))
11841 (vhdl-parse-string "\\s-*;\\s-*")
11842 ;; parse inline comment
11843 (unless comment
11844 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11845 (match-string-no-properties 1))))
11846 ;; save everything in list
11847 (setq port-list (append port-list
11848 (list (list names object direct type
11849 comment group-comment))))
11850 ;; parse group comment and spacing
11851 (setq group-comment (vhdl-parse-group-comment))))
11852 ;; parse context clause
11853 (setq context-clause (vhdl-scan-context-clause))
11854 ; ;; add surrounding package to context clause
11855 ; (when (and (equal decl-type "component")
11856 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11857 ; (setq context-clause
11858 ; (append context-clause
11859 ; (list (cons (vhdl-work-library)
11860 ; (match-string-no-properties 1))))))
11861 (message "Reading port of %s \"%s\"...done" decl-type name)
11862 nil)))
11863 ;; finish parsing
11864 (if parse-error
11865 (error parse-error)
11866 (setq vhdl-port-list (list name generic-list port-list context-clause)
11867 vhdl-port-reversed-direction nil
11868 vhdl-port-flattened nil)))))
11870 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11871 "Paste a context clause."
11872 (let ((margin (current-indentation))
11873 (clause-list (nth 3 vhdl-port-list))
11874 clause)
11875 (while clause-list
11876 (setq clause (car clause-list))
11877 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11878 (downcase exclude-pack-name)))
11879 (save-excursion
11880 (re-search-backward
11881 (concat "^\\s-*use\\s-+" (car clause)
11882 "." (cdr clause) "\\>") nil t)))
11883 (vhdl-template-standard-package (car clause) (cdr clause))
11884 (insert "\n"))
11885 (setq clause-list (cdr clause-list)))))
11887 (defun vhdl-port-paste-generic (&optional no-init)
11888 "Paste a generic clause."
11889 (let ((margin (current-indentation))
11890 (generic-list (nth 1 vhdl-port-list))
11891 list-margin start names generic)
11892 ;; paste generic clause
11893 (when generic-list
11894 (setq start (point))
11895 (vhdl-insert-keyword "GENERIC (")
11896 (unless vhdl-argument-list-indent
11897 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11898 (setq list-margin (current-column))
11899 (while generic-list
11900 (setq generic (car generic-list))
11901 ;; paste group comment and spacing
11902 (when (memq vhdl-include-group-comments '(decl always))
11903 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11904 ;; paste names
11905 (setq names (nth 0 generic))
11906 (while names
11907 (insert (car names))
11908 (setq names (cdr names))
11909 (when names (insert ", ")))
11910 ;; paste type
11911 (insert " : " (nth 1 generic))
11912 ;; paste initialization
11913 (when (and (not no-init) (nth 2 generic))
11914 (insert " := " (nth 2 generic)))
11915 (unless (cdr generic-list) (insert ")"))
11916 (insert ";")
11917 ;; paste comment
11918 (when (and vhdl-include-port-comments (nth 3 generic))
11919 (vhdl-comment-insert-inline (nth 3 generic) t))
11920 (setq generic-list (cdr generic-list))
11921 (when generic-list (insert "\n") (indent-to list-margin)))
11922 ;; align generic clause
11923 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11925 (defun vhdl-port-paste-port ()
11926 "Paste a port clause."
11927 (let ((margin (current-indentation))
11928 (port-list (nth 2 vhdl-port-list))
11929 list-margin start names port)
11930 ;; paste port clause
11931 (when port-list
11932 (setq start (point))
11933 (vhdl-insert-keyword "PORT (")
11934 (unless vhdl-argument-list-indent
11935 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11936 (setq list-margin (current-column))
11937 (while port-list
11938 (setq port (car port-list))
11939 ;; paste group comment and spacing
11940 (when (memq vhdl-include-group-comments '(decl always))
11941 (vhdl-paste-group-comment (nth 5 port) list-margin))
11942 ;; paste object
11943 (when (nth 1 port) (insert (nth 1 port) " "))
11944 ;; paste names
11945 (setq names (nth 0 port))
11946 (while names
11947 (insert (car names))
11948 (setq names (cdr names))
11949 (when names (insert ", ")))
11950 ;; paste direction
11951 (insert " : ")
11952 (when (nth 2 port) (insert (nth 2 port) " "))
11953 ;; paste type
11954 (insert (nth 3 port))
11955 (unless (cdr port-list) (insert ")"))
11956 (insert ";")
11957 ;; paste comment
11958 (when (and vhdl-include-port-comments (nth 4 port))
11959 (vhdl-comment-insert-inline (nth 4 port) t))
11960 (setq port-list (cdr port-list))
11961 (when port-list (insert "\n") (indent-to list-margin)))
11962 ;; align port clause
11963 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11965 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11966 "Paste as an entity or component declaration."
11967 (unless no-indent (indent-according-to-mode))
11968 (let ((margin (current-indentation))
11969 (name (nth 0 vhdl-port-list)))
11970 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11971 (insert name)
11972 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11973 (vhdl-insert-keyword " IS"))
11974 ;; paste generic and port clause
11975 (when (nth 1 vhdl-port-list)
11976 (insert "\n")
11977 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11978 (insert "\n"))
11979 (indent-to (+ margin vhdl-basic-offset))
11980 (vhdl-port-paste-generic (eq kind 'component)))
11981 (when (nth 2 vhdl-port-list)
11982 (insert "\n")
11983 (when (and (memq vhdl-insert-empty-lines '(unit all))
11984 (eq kind 'entity))
11985 (insert "\n"))
11986 (indent-to (+ margin vhdl-basic-offset)))
11987 (vhdl-port-paste-port)
11988 (insert "\n")
11989 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11990 (insert "\n"))
11991 (indent-to margin)
11992 (vhdl-insert-keyword "END")
11993 (if (eq kind 'entity)
11994 (progn
11995 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11996 (insert " " name))
11997 (vhdl-insert-keyword " COMPONENT")
11998 (unless (vhdl-standard-p '87) (insert " " name)))
11999 (insert ";")))
12001 (defun vhdl-port-paste-entity (&optional no-indent)
12002 "Paste as an entity declaration."
12003 (interactive)
12004 (if (not vhdl-port-list)
12005 (error "ERROR: No port read")
12006 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
12007 (vhdl-port-paste-declaration 'entity no-indent)
12008 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
12010 (defun vhdl-port-paste-component (&optional no-indent)
12011 "Paste as a component declaration."
12012 (interactive)
12013 (if (not vhdl-port-list)
12014 (error "ERROR: No port read")
12015 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
12016 (vhdl-port-paste-declaration 'component no-indent)
12017 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
12019 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
12020 "Paste as a generic map."
12021 (interactive)
12022 (unless secondary (indent-according-to-mode))
12023 (let ((margin (current-indentation))
12024 list-margin start generic
12025 (generic-list (nth 1 vhdl-port-list)))
12026 (when generic-list
12027 (setq start (point))
12028 (vhdl-insert-keyword "GENERIC MAP (")
12029 (if (not vhdl-association-list-with-formals)
12030 ;; paste list of actual generics
12031 (while generic-list
12032 (insert (if no-constants
12033 (car (nth 0 (car generic-list)))
12034 (or (nth 2 (car generic-list)) " ")))
12035 (setq generic-list (cdr generic-list))
12036 (insert (if generic-list ", " ")"))
12037 (when (and (not generic-list) secondary
12038 (null (nth 2 vhdl-port-list)))
12039 (insert ";")))
12040 (unless vhdl-argument-list-indent
12041 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12042 (setq list-margin (current-column))
12043 (while generic-list
12044 (setq generic (car generic-list))
12045 ;; paste group comment and spacing
12046 (when (eq vhdl-include-group-comments 'always)
12047 (vhdl-paste-group-comment (nth 4 generic) list-margin))
12048 ;; paste formal and actual generic
12049 (insert (car (nth 0 generic)) " => "
12050 (if no-constants
12051 (vhdl-replace-string vhdl-actual-generic-name
12052 (car (nth 0 generic)))
12053 (or (nth 2 generic) "")))
12054 (setq generic-list (cdr generic-list))
12055 (insert (if generic-list "," ")"))
12056 (when (and (not generic-list) secondary
12057 (null (nth 2 vhdl-port-list)))
12058 (insert ";"))
12059 ;; paste comment
12060 (when (or vhdl-include-type-comments
12061 (and vhdl-include-port-comments (nth 3 generic)))
12062 (vhdl-comment-insert-inline
12063 (concat
12064 (when vhdl-include-type-comments
12065 (concat "[" (nth 1 generic) "] "))
12066 (when vhdl-include-port-comments (nth 3 generic))) t))
12067 (when generic-list (insert "\n") (indent-to list-margin)))
12068 ;; align generic map
12069 (when vhdl-auto-align
12070 (vhdl-align-region-groups start (point) 1 t))))))
12072 (defun vhdl-port-paste-port-map ()
12073 "Paste as a port map."
12074 (let ((margin (current-indentation))
12075 list-margin start port
12076 (port-list (nth 2 vhdl-port-list)))
12077 (when port-list
12078 (setq start (point))
12079 (vhdl-insert-keyword "PORT MAP (")
12080 (if (not vhdl-association-list-with-formals)
12081 ;; paste list of actual ports
12082 (while port-list
12083 (insert (vhdl-replace-string vhdl-actual-port-name
12084 (car (nth 0 (car port-list)))))
12085 (setq port-list (cdr port-list))
12086 (insert (if port-list ", " ")")))
12087 (unless vhdl-argument-list-indent
12088 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12089 (setq list-margin (current-column))
12090 (while port-list
12091 (setq port (car port-list))
12092 ;; paste group comment and spacing
12093 (when (eq vhdl-include-group-comments 'always)
12094 (vhdl-paste-group-comment (nth 5 port) list-margin))
12095 ;; paste formal and actual port
12096 (insert (car (nth 0 port)) " => ")
12097 (insert (vhdl-replace-string vhdl-actual-port-name
12098 (car (nth 0 port))))
12099 (setq port-list (cdr port-list))
12100 (insert (if port-list "," ");"))
12101 ;; paste comment
12102 (when (or (and vhdl-include-direction-comments (nth 2 port))
12103 vhdl-include-type-comments
12104 (and vhdl-include-port-comments (nth 4 port)))
12105 (vhdl-comment-insert-inline
12106 (concat
12107 (cond ((and vhdl-include-direction-comments
12108 vhdl-include-type-comments)
12109 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
12110 (nth 3 port) "] "))
12111 ((and vhdl-include-direction-comments (nth 2 port))
12112 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12113 (vhdl-include-direction-comments " ")
12114 (vhdl-include-type-comments
12115 (concat "[" (nth 3 port) "] ")))
12116 (when vhdl-include-port-comments (nth 4 port))) t))
12117 (when port-list (insert "\n") (indent-to list-margin)))
12118 ;; align port clause
12119 (when vhdl-auto-align
12120 (vhdl-align-region-groups start (point) 1))))))
12122 (defun vhdl-port-paste-instance (&optional name no-indent title)
12123 "Paste as an instantiation."
12124 (interactive)
12125 (if (not vhdl-port-list)
12126 (error "ERROR: No port read")
12127 (let ((orig-vhdl-port-list vhdl-port-list))
12128 ;; flatten local copy of port list (must be flat for port mapping)
12129 (vhdl-port-flatten)
12130 (unless no-indent (indent-according-to-mode))
12131 (let ((margin (current-indentation)))
12132 ;; paste instantiation
12133 (cond (name
12134 (insert name))
12135 ((equal (cdr vhdl-instance-name) "")
12136 (setq name (vhdl-template-field "instance name")))
12137 ((string-match "%d" (cdr vhdl-instance-name))
12138 (let ((n 1))
12139 (while (save-excursion
12140 (setq name (format (vhdl-replace-string
12141 vhdl-instance-name
12142 (nth 0 vhdl-port-list)) n))
12143 (goto-char (point-min))
12144 (vhdl-re-search-forward name nil t))
12145 (setq n (1+ n)))
12146 (insert name)))
12147 (t (insert (vhdl-replace-string vhdl-instance-name
12148 (nth 0 vhdl-port-list)))))
12149 (message "Pasting port as instantiation \"%s\"..." name)
12150 (insert ": ")
12151 (when title
12152 (save-excursion
12153 (beginning-of-line)
12154 (indent-to vhdl-basic-offset)
12155 (insert "-- instance \"" name "\"\n")))
12156 (if (not (vhdl-use-direct-instantiation))
12157 (insert (nth 0 vhdl-port-list))
12158 (vhdl-insert-keyword "ENTITY ")
12159 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
12160 (when (nth 1 vhdl-port-list)
12161 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12162 (vhdl-port-paste-generic-map t t))
12163 (when (nth 2 vhdl-port-list)
12164 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12165 (vhdl-port-paste-port-map))
12166 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
12167 (insert ";"))
12168 (message "Pasting port as instantiation \"%s\"...done" name))
12169 (setq vhdl-port-list orig-vhdl-port-list))))
12171 (defun vhdl-port-paste-constants (&optional no-indent)
12172 "Paste generics as constants."
12173 (interactive)
12174 (if (not vhdl-port-list)
12175 (error "ERROR: No port read")
12176 (let ((orig-vhdl-port-list vhdl-port-list))
12177 (message "Pasting port as constants...")
12178 ;; flatten local copy of port list (must be flat for constant initial.)
12179 (vhdl-port-flatten)
12180 (unless no-indent (indent-according-to-mode))
12181 (let ((margin (current-indentation))
12182 start generic name
12183 (generic-list (nth 1 vhdl-port-list)))
12184 (when generic-list
12185 (setq start (point))
12186 (while generic-list
12187 (setq generic (car generic-list))
12188 ;; paste group comment and spacing
12189 (when (memq vhdl-include-group-comments '(decl always))
12190 (vhdl-paste-group-comment (nth 4 generic) margin))
12191 (vhdl-insert-keyword "CONSTANT ")
12192 ;; paste generic constants
12193 (setq name (nth 0 generic))
12194 (when name
12195 (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
12196 ;; paste type
12197 (insert " : " (nth 1 generic))
12198 ;; paste initialization
12199 (when (nth 2 generic)
12200 (insert " := " (nth 2 generic)))
12201 (insert ";")
12202 ;; paste comment
12203 (when (and vhdl-include-port-comments (nth 3 generic))
12204 (vhdl-comment-insert-inline (nth 3 generic) t))
12205 (setq generic-list (cdr generic-list))
12206 (when generic-list (insert "\n") (indent-to margin))))
12207 ;; align signal list
12208 (when vhdl-auto-align
12209 (vhdl-align-region-groups start (point) 1))))
12210 (message "Pasting port as constants...done")
12211 (setq vhdl-port-list orig-vhdl-port-list))))
12213 (defun vhdl-port-paste-signals (&optional initialize no-indent)
12214 "Paste ports as internal signals."
12215 (interactive)
12216 (if (not vhdl-port-list)
12217 (error "ERROR: No port read")
12218 (message "Pasting port as signals...")
12219 (unless no-indent (indent-according-to-mode))
12220 (let ((margin (current-indentation))
12221 start port names type generic-list port-name constant-name pos
12222 (port-list (nth 2 vhdl-port-list)))
12223 (when port-list
12224 (setq start (point))
12225 (while port-list
12226 (setq port (car port-list))
12227 ;; paste group comment and spacing
12228 (when (memq vhdl-include-group-comments '(decl always))
12229 (vhdl-paste-group-comment (nth 5 port) margin))
12230 ;; paste object
12231 (if (nth 1 port)
12232 (insert (nth 1 port) " ")
12233 (vhdl-insert-keyword "SIGNAL "))
12234 ;; paste actual port signals
12235 (setq names (nth 0 port))
12236 (while names
12237 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
12238 (setq names (cdr names))
12239 (when names (insert ", ")))
12240 ;; paste type
12241 (setq type (nth 3 port))
12242 (setq generic-list (nth 1 vhdl-port-list))
12243 (vhdl-prepare-search-1
12244 (setq pos 0)
12245 ;; replace formal by actual generics
12246 (while generic-list
12247 (setq port-name (car (nth 0 (car generic-list))))
12248 (while (string-match (concat "\\<" port-name "\\>") type pos)
12249 (setq constant-name
12250 (save-match-data (vhdl-replace-string
12251 vhdl-actual-generic-name port-name)))
12252 (setq type (replace-match constant-name t nil type))
12253 (setq pos (match-end 0)))
12254 (setq generic-list (cdr generic-list))))
12255 (insert " : " type)
12256 ;; paste initialization (inputs only)
12257 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
12258 (insert " := "
12259 (cond ((string-match "integer" (nth 3 port)) "0")
12260 ((string-match "natural" (nth 3 port)) "0")
12261 ((string-match "positive" (nth 3 port)) "0")
12262 ((string-match "real" (nth 3 port)) "0.0")
12263 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12264 (t "'0'"))))
12265 (insert ";")
12266 ;; paste comment
12267 (when (or (and vhdl-include-direction-comments (nth 2 port))
12268 (and vhdl-include-port-comments (nth 4 port)))
12269 (vhdl-comment-insert-inline
12270 (concat
12271 (cond ((and vhdl-include-direction-comments (nth 2 port))
12272 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12273 (vhdl-include-direction-comments " "))
12274 (when vhdl-include-port-comments (nth 4 port))) t))
12275 (setq port-list (cdr port-list))
12276 (when port-list (insert "\n") (indent-to margin)))
12277 ;; align signal list
12278 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12279 (message "Pasting port as signals...done")))
12281 (defun vhdl-port-paste-initializations (&optional no-indent)
12282 "Paste ports as signal initializations."
12283 (interactive)
12284 (if (not vhdl-port-list)
12285 (error "ERROR: No port read")
12286 (let ((orig-vhdl-port-list vhdl-port-list))
12287 (message "Pasting port as initializations...")
12288 ;; flatten local copy of port list (must be flat for signal initial.)
12289 (vhdl-port-flatten)
12290 (unless no-indent (indent-according-to-mode))
12291 (let ((margin (current-indentation))
12292 start port name
12293 (port-list (nth 2 vhdl-port-list)))
12294 (when port-list
12295 (setq start (point))
12296 (while port-list
12297 (setq port (car port-list))
12298 ;; paste actual port signal (inputs only)
12299 (when (equal "IN" (upcase (nth 2 port)))
12300 (setq name (car (nth 0 port)))
12301 (insert (vhdl-replace-string vhdl-actual-port-name name))
12302 ;; paste initialization
12303 (insert " <= "
12304 (cond ((string-match "integer" (nth 3 port)) "0")
12305 ((string-match "natural" (nth 3 port)) "0")
12306 ((string-match "positive" (nth 3 port)) "0")
12307 ((string-match "real" (nth 3 port)) "0.0")
12308 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12309 (t "'0'"))
12310 ";"))
12311 (setq port-list (cdr port-list))
12312 (when (and port-list
12313 (equal "IN" (upcase (nth 2 (car port-list)))))
12314 (insert "\n") (indent-to margin)))
12315 ;; align signal list
12316 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12317 (message "Pasting port as initializations...done")
12318 (setq vhdl-port-list orig-vhdl-port-list))))
12320 (defun vhdl-port-paste-testbench ()
12321 "Paste as a bare-bones testbench."
12322 (interactive)
12323 (if (not vhdl-port-list)
12324 (error "ERROR: No port read")
12325 (let ((case-fold-search t)
12326 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12327 (nth 0 vhdl-port-list)))
12328 (source-buffer (current-buffer))
12329 arch-name config-name ent-file-name arch-file-name
12330 ent-buffer arch-buffer position)
12331 ;; open entity file
12332 (unless (eq vhdl-testbench-create-files 'none)
12333 (setq ent-file-name
12334 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12335 ent-name t)
12336 "." (file-name-extension (buffer-file-name))))
12337 (if (file-exists-p ent-file-name)
12338 (if (y-or-n-p
12339 (concat "File \"" ent-file-name "\" exists; overwrite? "))
12340 (progn (find-file ent-file-name)
12341 (erase-buffer)
12342 (set-buffer-modified-p nil))
12343 (if (eq vhdl-testbench-create-files 'separate)
12344 (setq ent-file-name nil)
12345 (error "ERROR: Pasting port as testbench...aborted")))
12346 (find-file ent-file-name)))
12347 (unless (and (eq vhdl-testbench-create-files 'separate)
12348 (null ent-file-name))
12349 ;; paste entity header
12350 (if vhdl-testbench-include-header
12351 (progn (vhdl-template-header
12352 (concat "Testbench for design \""
12353 (nth 0 vhdl-port-list) "\""))
12354 (goto-char (point-max)))
12355 (vhdl-comment-display-line) (insert "\n\n"))
12356 ;; paste std_logic_1164 package
12357 (when vhdl-testbench-include-library
12358 (vhdl-template-package-std-logic-1164)
12359 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12360 ;; paste entity declaration
12361 (vhdl-insert-keyword "ENTITY ")
12362 (insert ent-name)
12363 (vhdl-insert-keyword " IS")
12364 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
12365 (insert "\n")
12366 (vhdl-insert-keyword "END ")
12367 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12368 (insert ent-name ";")
12369 (insert "\n\n")
12370 (vhdl-comment-display-line) (insert "\n"))
12371 ;; get architecture name
12372 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
12373 (read-from-minibuffer "architecture name: "
12374 nil vhdl-minibuffer-local-map)
12375 (vhdl-replace-string vhdl-testbench-architecture-name
12376 (nth 0 vhdl-port-list))))
12377 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
12378 ;; open architecture file
12379 (if (not (eq vhdl-testbench-create-files 'separate))
12380 (insert "\n")
12381 (setq ent-buffer (current-buffer))
12382 (setq arch-file-name
12383 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12384 (concat ent-name " " arch-name) t)
12385 "." (file-name-extension (buffer-file-name))))
12386 (when (and (file-exists-p arch-file-name)
12387 (not (y-or-n-p (concat "File \"" arch-file-name
12388 "\" exists; overwrite? "))))
12389 (error "ERROR: Pasting port as testbench...aborted"))
12390 (find-file arch-file-name)
12391 (erase-buffer)
12392 (set-buffer-modified-p nil)
12393 ;; paste architecture header
12394 (if vhdl-testbench-include-header
12395 (progn (vhdl-template-header
12396 (concat "Testbench architecture for design \""
12397 (nth 0 vhdl-port-list) "\""))
12398 (goto-char (point-max)))
12399 (vhdl-comment-display-line) (insert "\n\n")))
12400 ;; paste architecture body
12401 (vhdl-insert-keyword "ARCHITECTURE ")
12402 (insert arch-name)
12403 (vhdl-insert-keyword " OF ")
12404 (insert ent-name)
12405 (vhdl-insert-keyword " IS")
12406 (insert "\n\n") (indent-to vhdl-basic-offset)
12407 ;; paste component declaration
12408 (unless (vhdl-use-direct-instantiation)
12409 (vhdl-port-paste-component t)
12410 (insert "\n\n") (indent-to vhdl-basic-offset))
12411 ;; paste constants
12412 (when (nth 1 vhdl-port-list)
12413 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
12414 (vhdl-port-paste-constants t)
12415 (insert "\n\n") (indent-to vhdl-basic-offset))
12416 ;; paste internal signals
12417 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
12418 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
12419 (insert "\n")
12420 ;; paste custom declarations
12421 (unless (equal "" vhdl-testbench-declarations)
12422 (insert "\n")
12423 (setq position (point))
12424 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12425 (vhdl-indent-region position (point)))
12426 (setq position (point))
12427 (insert "\n\n")
12428 (vhdl-comment-display-line) (insert "\n")
12429 (when vhdl-testbench-include-configuration
12430 (setq config-name (vhdl-replace-string
12431 vhdl-testbench-configuration-name
12432 (concat ent-name " " arch-name)))
12433 (insert "\n")
12434 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12435 (vhdl-insert-keyword " OF ") (insert ent-name)
12436 (vhdl-insert-keyword " IS\n")
12437 (indent-to vhdl-basic-offset)
12438 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12439 (indent-to vhdl-basic-offset)
12440 (vhdl-insert-keyword "END FOR;\n")
12441 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12442 (vhdl-comment-display-line) (insert "\n"))
12443 (goto-char position)
12444 (vhdl-template-begin-end
12445 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12446 ;; paste instantiation
12447 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12448 (vhdl-port-paste-instance
12449 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12450 (insert "\n")
12451 ;; paste custom statements
12452 (unless (equal "" vhdl-testbench-statements)
12453 (insert "\n")
12454 (setq position (point))
12455 (vhdl-insert-string-or-file vhdl-testbench-statements)
12456 (vhdl-indent-region position (point)))
12457 (insert "\n")
12458 (indent-to vhdl-basic-offset)
12459 (unless (eq vhdl-testbench-create-files 'none)
12460 (setq arch-buffer (current-buffer))
12461 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12462 (set-buffer arch-buffer) (save-buffer))
12463 (message "%s"
12464 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12465 ent-name arch-name)
12466 (and ent-file-name
12467 (format "\n File created: \"%s\"" ent-file-name))
12468 (and arch-file-name
12469 (format "\n File created: \"%s\"" arch-file-name)))))))
12472 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12473 ;;; Subprogram interface translation
12474 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12476 (defvar vhdl-subprog-list nil
12477 "Variable to hold last subprogram interface parsed.")
12478 ;; structure: (parenthesized expression means list of such entries)
12479 ;; (subprog-name kind
12480 ;; ((names) object direct type init comment group-comment)
12481 ;; return-type return-comment group-comment)
12483 (defvar vhdl-subprog-flattened nil
12484 "Indicates whether an subprogram interface has been flattened.")
12486 (defun vhdl-subprog-flatten ()
12487 "Flatten interface list so that only one parameter exists per line."
12488 (interactive)
12489 (if (not vhdl-subprog-list)
12490 (error "ERROR: No subprogram interface has been read")
12491 (message "Flattening subprogram interface...")
12492 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12493 new-subprog-list old-subprog new-subprog names)
12494 ;; traverse parameter list and flatten entries
12495 (while old-subprog-list
12496 (setq old-subprog (car old-subprog-list))
12497 (setq names (car old-subprog))
12498 (while names
12499 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12500 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12501 (setq names (cdr names)))
12502 (setq old-subprog-list (cdr old-subprog-list)))
12503 (setq vhdl-subprog-list
12504 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12505 new-subprog-list (nth 3 vhdl-subprog-list)
12506 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12507 vhdl-subprog-flattened t)
12508 (message "Flattening subprogram interface...done"))))
12510 (defun vhdl-subprog-copy ()
12511 "Get interface information from a subprogram specification."
12512 (interactive)
12513 (save-excursion
12514 (let (parse-error pos end-of-list
12515 name kind param-list object names direct type init
12516 comment group-comment
12517 return-type return-comment return-group-comment)
12518 (vhdl-prepare-search-2
12519 (setq
12520 parse-error
12521 (catch 'parse
12522 ;; check if within function declaration
12523 (setq pos (point))
12524 (end-of-line)
12525 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12526 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12527 (goto-char (match-end 0))
12528 (save-excursion (backward-char)
12529 (forward-sexp)
12530 (<= pos (point))))
12531 (throw 'parse "ERROR: Not within a subprogram specification"))
12532 (setq name (match-string-no-properties 5))
12533 (setq kind (if (match-string 2) 'procedure 'function))
12534 (setq end-of-list (not (match-string 7)))
12535 (message "Reading interface of subprogram \"%s\"..." name)
12536 ;; parse parameter list
12537 (setq group-comment (vhdl-parse-group-comment))
12538 (setq end-of-list (or end-of-list
12539 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12540 (while (not end-of-list)
12541 ;; parse object
12542 (setq object
12543 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12544 (match-string-no-properties 1)))
12545 ;; parse names (accept extended identifiers)
12546 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12547 (setq names (list (match-string-no-properties 1)))
12548 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12549 (setq names (append names (list (match-string-no-properties 1)))))
12550 ;; parse direction
12551 (vhdl-parse-string ":[ \t\n\r\f]*")
12552 (setq direct
12553 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12554 (match-string-no-properties 1)))
12555 ;; parse type
12556 (vhdl-parse-string "\\([^():;\n]+\\)")
12557 (setq type (match-string-no-properties 1))
12558 (setq comment nil)
12559 (while (looking-at "(")
12560 (setq type
12561 (concat type
12562 (buffer-substring-no-properties
12563 (point) (progn (forward-sexp) (point)))
12564 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12565 (match-string-no-properties 1)))))
12566 ;; special case: closing parenthesis is on separate line
12567 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12568 (setq comment (substring type (match-beginning 2)))
12569 (setq type (substring type 0 (match-beginning 1))))
12570 ;; strip off trailing group-comment
12571 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12572 (setq type (substring type 0 (match-end 1)))
12573 ;; parse initialization expression
12574 (setq init nil)
12575 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12576 (vhdl-parse-string "\\([^();\n]*\\)")
12577 (setq init (match-string-no-properties 1))
12578 (while (looking-at "(")
12579 (setq init
12580 (concat init
12581 (buffer-substring-no-properties
12582 (point) (progn (forward-sexp) (point)))
12583 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12584 (match-string-no-properties 1))))))
12585 ;; special case: closing parenthesis is on separate line
12586 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12587 (setq comment (substring init (match-beginning 2)))
12588 (setq init (substring init 0 (match-beginning 1)))
12589 (vhdl-forward-syntactic-ws))
12590 (skip-chars-forward " \t")
12591 ;; parse inline comment, special case: as above, no initial.
12592 (unless comment
12593 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12594 (match-string-no-properties 1))))
12595 (vhdl-forward-syntactic-ws)
12596 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12597 ;; parse inline comment
12598 (unless comment
12599 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12600 (match-string-no-properties 1))))
12601 (setq return-group-comment (vhdl-parse-group-comment))
12602 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12603 ;; parse return type
12604 (when (match-string 3)
12605 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12606 (setq return-type (match-string-no-properties 1))
12607 (when (and return-type
12608 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12609 (setq return-comment (substring return-type (match-beginning 2)))
12610 (setq return-type (substring return-type 0 (match-beginning 1))))
12611 ;; strip of trailing group-comment
12612 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12613 (setq return-type (substring return-type 0 (match-end 1)))
12614 ;; parse return comment
12615 (unless return-comment
12616 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12617 (match-string-no-properties 1)))))
12618 ;; parse inline comment
12619 (unless comment
12620 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12621 (match-string-no-properties 1))))
12622 ;; save everything in list
12623 (setq param-list (append param-list
12624 (list (list names object direct type init
12625 comment group-comment))))
12626 ;; parse group comment and spacing
12627 (setq group-comment (vhdl-parse-group-comment)))
12628 (message "Reading interface of subprogram \"%s\"...done" name)
12629 nil)))
12630 ;; finish parsing
12631 (if parse-error
12632 (error parse-error)
12633 (setq vhdl-subprog-list
12634 (list name kind param-list return-type return-comment
12635 return-group-comment)
12636 vhdl-subprog-flattened nil)))))
12638 (defun vhdl-subprog-paste-specification (kind)
12639 "Paste as a subprogram specification."
12640 (indent-according-to-mode)
12641 (let ((margin (current-column))
12642 (param-list (nth 2 vhdl-subprog-list))
12643 list-margin start names param)
12644 ;; paste keyword and name
12645 (vhdl-insert-keyword
12646 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12647 (insert (nth 0 vhdl-subprog-list))
12648 (if (not param-list)
12649 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12650 (setq start (point))
12651 ;; paste parameter list
12652 (insert " (")
12653 (unless vhdl-argument-list-indent
12654 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12655 (setq list-margin (current-column))
12656 (while param-list
12657 (setq param (car param-list))
12658 ;; paste group comment and spacing
12659 (when (memq vhdl-include-group-comments (list kind 'always))
12660 (vhdl-paste-group-comment (nth 6 param) list-margin))
12661 ;; paste object
12662 (when (nth 1 param) (insert (nth 1 param) " "))
12663 ;; paste names
12664 (setq names (nth 0 param))
12665 (while names
12666 (insert (car names))
12667 (setq names (cdr names))
12668 (when names (insert ", ")))
12669 ;; paste direction
12670 (insert " : ")
12671 (when (nth 2 param) (insert (nth 2 param) " "))
12672 ;; paste type
12673 (insert (nth 3 param))
12674 ;; paste initialization
12675 (when (nth 4 param) (insert " := " (nth 4 param)))
12676 ;; terminate line
12677 (if (cdr param-list)
12678 (insert ";")
12679 (insert ")")
12680 (when (null (nth 3 vhdl-subprog-list))
12681 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12682 ;; paste comment
12683 (when (and vhdl-include-port-comments (nth 5 param))
12684 (vhdl-comment-insert-inline (nth 5 param) t))
12685 (setq param-list (cdr param-list))
12686 (when param-list (insert "\n") (indent-to list-margin)))
12687 (when (nth 3 vhdl-subprog-list)
12688 (insert "\n") (indent-to list-margin)
12689 ;; paste group comment and spacing
12690 (when (memq vhdl-include-group-comments (list kind 'always))
12691 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12692 ;; paste return type
12693 (insert "return " (nth 3 vhdl-subprog-list))
12694 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12695 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12696 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12697 ;; align parameter list
12698 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12699 ;; paste body
12700 (when (eq kind 'body)
12701 (insert "\n")
12702 (vhdl-template-begin-end
12703 (unless (vhdl-standard-p '87)
12704 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12705 (nth 0 vhdl-subprog-list) margin))))
12707 (defun vhdl-subprog-paste-declaration ()
12708 "Paste as a subprogram declaration."
12709 (interactive)
12710 (if (not vhdl-subprog-list)
12711 (error "ERROR: No subprogram interface read")
12712 (message "Pasting interface as subprogram declaration \"%s\"..."
12713 (car vhdl-subprog-list))
12714 ;; paste specification
12715 (vhdl-subprog-paste-specification 'decl)
12716 (message "Pasting interface as subprogram declaration \"%s\"...done"
12717 (car vhdl-subprog-list))))
12719 (defun vhdl-subprog-paste-body ()
12720 "Paste as a subprogram body."
12721 (interactive)
12722 (if (not vhdl-subprog-list)
12723 (error "ERROR: No subprogram interface read")
12724 (message "Pasting interface as subprogram body \"%s\"..."
12725 (car vhdl-subprog-list))
12726 ;; paste specification and body
12727 (vhdl-subprog-paste-specification 'body)
12728 (message "Pasting interface as subprogram body \"%s\"...done"
12729 (car vhdl-subprog-list))))
12731 (defun vhdl-subprog-paste-call ()
12732 "Paste as a subprogram call."
12733 (interactive)
12734 (if (not vhdl-subprog-list)
12735 (error "ERROR: No subprogram interface read")
12736 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12737 param-list margin list-margin param start)
12738 ;; flatten local copy of interface list (must be flat for parameter mapping)
12739 (vhdl-subprog-flatten)
12740 (setq param-list (nth 2 vhdl-subprog-list))
12741 (indent-according-to-mode)
12742 (setq margin (current-indentation))
12743 (message "Pasting interface as subprogram call \"%s\"..."
12744 (car vhdl-subprog-list))
12745 ;; paste name
12746 (insert (nth 0 vhdl-subprog-list))
12747 (if (not param-list)
12748 (insert ";")
12749 (setq start (point))
12750 ;; paste parameter list
12751 (insert " (")
12752 (unless vhdl-argument-list-indent
12753 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12754 (setq list-margin (current-column))
12755 (while param-list
12756 (setq param (car param-list))
12757 ;; paste group comment and spacing
12758 (when (eq vhdl-include-group-comments 'always)
12759 (vhdl-paste-group-comment (nth 6 param) list-margin))
12760 ;; paste formal port
12761 (insert (car (nth 0 param)) " => ")
12762 (setq param-list (cdr param-list))
12763 (insert (if param-list "," ");"))
12764 ;; paste comment
12765 (when (and vhdl-include-port-comments (nth 5 param))
12766 (vhdl-comment-insert-inline (nth 5 param)))
12767 (when param-list (insert "\n") (indent-to list-margin)))
12768 ;; align parameter list
12769 (when vhdl-auto-align
12770 (vhdl-align-region-groups start (point) 1)))
12771 (message "Pasting interface as subprogram call \"%s\"...done"
12772 (car vhdl-subprog-list))
12773 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12777 ;;; Miscellaneous
12778 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12780 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12781 ;; Hippie expand customization
12783 (defvar vhdl-expand-upper-case nil)
12785 (defun vhdl-try-expand-abbrev (old)
12786 "Try expanding abbreviations from `vhdl-abbrev-list'."
12787 (unless old
12788 (he-init-string (he-dabbrev-beg) (point))
12789 (setq he-expand-list
12790 (let ((abbrev-list vhdl-abbrev-list)
12791 (sel-abbrev-list '()))
12792 (while abbrev-list
12793 (when (or (not (stringp (car abbrev-list)))
12794 (string-match
12795 (concat "^" he-search-string) (car abbrev-list)))
12796 (setq sel-abbrev-list
12797 (cons (car abbrev-list) sel-abbrev-list)))
12798 (setq abbrev-list (cdr abbrev-list)))
12799 (nreverse sel-abbrev-list))))
12800 (while (and he-expand-list
12801 (or (not (stringp (car he-expand-list)))
12802 (he-string-member (car he-expand-list) he-tried-table t)))
12803 (unless (stringp (car he-expand-list))
12804 (setq vhdl-expand-upper-case (car he-expand-list)))
12805 (setq he-expand-list (cdr he-expand-list)))
12806 (if (null he-expand-list)
12807 (progn (when old (he-reset-string))
12808 nil)
12809 (he-substitute-string
12810 (if vhdl-expand-upper-case
12811 (upcase (car he-expand-list))
12812 (car he-expand-list))
12814 (setq he-expand-list (cdr he-expand-list))
12817 (defun vhdl-he-list-beg ()
12818 "Also looks at the word before `(' in order to better match parenthesized
12819 expressions (e.g. for index ranges of types and signals)."
12820 (save-excursion
12821 (condition-case ()
12822 (progn (backward-up-list 1)
12823 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12824 (error ()))
12825 (point)))
12827 ;; override `he-list-beg' from `hippie-exp'
12828 (unless (and (boundp 'viper-mode) viper-mode)
12829 (defalias 'he-list-beg 'vhdl-he-list-beg))
12831 ;; function for expanding abbrevs and dabbrevs
12832 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12833 '(try-expand-dabbrev
12834 try-expand-dabbrev-all-buffers
12835 vhdl-try-expand-abbrev)))
12837 ;; function for expanding parenthesis
12838 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12839 '(try-expand-list
12840 try-expand-list-all-buffers)))
12842 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12843 ;; Line handling functions
12845 (defun vhdl-current-line ()
12846 "Return the line number of the line containing point."
12847 (save-restriction
12848 (widen)
12849 (1+ (count-lines (point-min) (point-at-bol)))))
12851 (defun vhdl-line-kill-entire (&optional arg)
12852 "Delete entire line."
12853 (interactive "p")
12854 (beginning-of-line)
12855 (kill-line (or arg 1)))
12857 (defun vhdl-line-kill (&optional arg)
12858 "Kill current line."
12859 (interactive "p")
12860 (vhdl-line-kill-entire arg))
12862 (defun vhdl-line-copy (&optional arg)
12863 "Copy current line."
12864 (interactive "p")
12865 (save-excursion
12866 (let ((position (point-at-bol)))
12867 (forward-line (or arg 1))
12868 (copy-region-as-kill position (point)))))
12870 (defun vhdl-line-yank ()
12871 "Yank entire line."
12872 (interactive)
12873 (beginning-of-line)
12874 (yank))
12876 (defun vhdl-line-expand (&optional prefix-arg)
12877 "Hippie-expand current line."
12878 (interactive "P")
12879 (require 'hippie-exp)
12880 (let ((case-fold-search t) (case-replace nil)
12881 (hippie-expand-try-functions-list
12882 '(try-expand-line try-expand-line-all-buffers)))
12883 (hippie-expand prefix-arg)))
12885 (defun vhdl-line-transpose-next (&optional arg)
12886 "Interchange this line with next line."
12887 (interactive "p")
12888 (forward-line 1)
12889 (transpose-lines (or arg 1))
12890 (forward-line -1))
12892 (defun vhdl-line-transpose-previous (&optional arg)
12893 "Interchange this line with previous line."
12894 (interactive "p")
12895 (forward-line 1)
12896 (transpose-lines (- 0 (or arg 0)))
12897 (forward-line -1))
12899 (defun vhdl-line-open ()
12900 "Open a new line and indent."
12901 (interactive)
12902 (end-of-line -0)
12903 (newline-and-indent))
12905 (defun vhdl-delete-indentation ()
12906 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12907 it works within comments too."
12908 (interactive)
12909 (let ((fill-prefix "-- "))
12910 (delete-indentation)))
12912 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12913 ;; Move functions
12915 (defun vhdl-forward-same-indent ()
12916 "Move forward to next line with same indent."
12917 (interactive)
12918 (let ((pos (point))
12919 (indent (current-indentation)))
12920 (beginning-of-line 2)
12921 (while (and (not (eobp))
12922 (or (looking-at "^\\s-*\\(--.*\\)?$")
12923 (> (current-indentation) indent)))
12924 (beginning-of-line 2))
12925 (if (= (current-indentation) indent)
12926 (back-to-indentation)
12927 (message "No following line with same indent found in this block")
12928 (goto-char pos)
12929 nil)))
12931 (defun vhdl-backward-same-indent ()
12932 "Move backward to previous line with same indent."
12933 (interactive)
12934 (let ((pos (point))
12935 (indent (current-indentation)))
12936 (beginning-of-line -0)
12937 (while (and (not (bobp))
12938 (or (looking-at "^\\s-*\\(--.*\\)?$")
12939 (> (current-indentation) indent)))
12940 (beginning-of-line -0))
12941 (if (= (current-indentation) indent)
12942 (back-to-indentation)
12943 (message "No preceding line with same indent found in this block")
12944 (goto-char pos)
12945 nil)))
12947 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12948 ;; Statistics
12950 (defun vhdl-statistics-buffer ()
12951 "Get some file statistics."
12952 (interactive)
12953 (let ((no-stats 0)
12954 (no-code-lines 0)
12955 (no-empty-lines 0)
12956 (no-comm-lines 0)
12957 (no-comments 0)
12958 (no-lines (count-lines (point-min) (point-max))))
12959 (save-excursion
12960 ;; count statements
12961 (goto-char (point-min))
12962 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12963 (if (match-string 1)
12964 (goto-char (match-end 1))
12965 (setq no-stats (1+ no-stats))))
12966 ;; count code lines
12967 (goto-char (point-min))
12968 (while (not (eobp))
12969 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12970 (setq no-code-lines (1+ no-code-lines)))
12971 (beginning-of-line 2))
12972 ;; count empty lines
12973 (goto-char (point-min))
12974 (while (and (re-search-forward "^\\s-*$" nil t)
12975 (not (eq (point) (point-max))))
12976 (if (match-string 1)
12977 (goto-char (match-end 1))
12978 (setq no-empty-lines (1+ no-empty-lines))
12979 (unless (eq (point) (point-max))
12980 (forward-char))))
12981 ;; count comment-only lines
12982 (goto-char (point-min))
12983 (while (re-search-forward "^\\s-*--.*" nil t)
12984 (if (match-string 1)
12985 (goto-char (match-end 1))
12986 (setq no-comm-lines (1+ no-comm-lines))))
12987 ;; count comments
12988 (goto-char (point-min))
12989 (while (re-search-forward "--.*" nil t)
12990 (if (match-string 1)
12991 (goto-char (match-end 1))
12992 (setq no-comments (1+ no-comments)))))
12993 ;; print results
12994 (message "\n\
12995 File statistics: \"%s\"\n\
12996 -----------------------\n\
12997 # statements : %5d\n\
12998 # code lines : %5d\n\
12999 # empty lines : %5d\n\
13000 # comment lines : %5d\n\
13001 # comments : %5d\n\
13002 # total lines : %5d\n"
13003 (buffer-file-name) no-stats no-code-lines no-empty-lines
13004 no-comm-lines no-comments no-lines)
13005 (unless vhdl-emacs-21 (vhdl-show-messages))))
13007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13008 ;; Help functions
13010 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
13011 "Like `re-search-forward', but does not match within literals."
13012 (let (pos)
13013 (save-excursion
13014 (while (and (setq pos (re-search-forward regexp bound noerror count))
13015 (save-match-data (vhdl-in-literal)))))
13016 (when pos (goto-char pos))
13017 pos))
13019 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
13020 "Like `re-search-backward', but does not match within literals."
13021 (let (pos)
13022 (save-excursion
13023 (while (and (setq pos (re-search-backward regexp bound noerror count))
13024 (save-match-data (vhdl-in-literal)))))
13025 (when pos (goto-char pos))
13026 pos))
13029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13030 ;;; Project
13031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13033 (defun vhdl-set-project (name)
13034 "Set current project to NAME."
13035 (interactive
13036 (list (let ((completion-ignore-case t))
13037 (completing-read "Project name: " vhdl-project-alist nil t))))
13038 (cond ((equal name "")
13039 (setq vhdl-project nil)
13040 (message "Current VHDL project: None"))
13041 ((assoc name vhdl-project-alist)
13042 (setq vhdl-project name)
13043 (message "Current VHDL project: \"%s\"" name))
13045 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
13046 (vhdl-speedbar-update-current-project))
13048 (defun vhdl-set-default-project ()
13049 "Set current project as default on startup."
13050 (interactive)
13051 (customize-set-variable 'vhdl-project vhdl-project)
13052 (customize-save-customized))
13054 (defun vhdl-toggle-project (name token indent)
13055 "Set current project to NAME or unset if NAME is current project."
13056 (vhdl-set-project (if (equal name vhdl-project) "" name)))
13058 (defun vhdl-export-project (file-name)
13059 "Write project setup for current project."
13060 (interactive
13061 (let ((name (vhdl-resolve-env-variable
13062 (vhdl-replace-string
13063 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13064 (concat (subst-char-in-string
13065 ? ?_ (or (vhdl-project-p)
13066 (error "ERROR: No current project")))
13067 " " (user-login-name))))))
13068 (list (read-file-name
13069 "Write project file: "
13070 (when (file-name-absolute-p name) "") nil nil name))))
13071 (setq file-name (abbreviate-file-name file-name))
13072 (let ((orig-buffer (current-buffer)))
13073 (unless (file-exists-p (file-name-directory file-name))
13074 (make-directory (file-name-directory file-name) t))
13075 (if (not (file-writable-p file-name))
13076 (error "ERROR: File not writable: \"%s\"" file-name)
13077 (set-buffer (find-file-noselect file-name t t))
13078 (erase-buffer)
13079 (insert ";; -*- Emacs-Lisp -*-\n\n"
13080 ";;; " (file-name-nondirectory file-name)
13081 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
13082 ";; Project : " vhdl-project "\n"
13083 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
13084 (user-login-name) "\n\n\n"
13085 ";; project name\n"
13086 "(setq vhdl-project \"" vhdl-project "\")\n\n"
13087 ";; project setup\n"
13088 "(vhdl-aput 'vhdl-project-alist vhdl-project\n'")
13089 (pp (vhdl-aget vhdl-project-alist vhdl-project) (current-buffer))
13090 (insert ")\n")
13091 (save-buffer)
13092 (kill-buffer (current-buffer))
13093 (set-buffer orig-buffer))))
13095 (defun vhdl-import-project (file-name &optional auto not-make-current)
13096 "Read project setup and set current project."
13097 (interactive
13098 (let ((name (vhdl-resolve-env-variable
13099 (vhdl-replace-string
13100 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13101 (concat "" " " (user-login-name))))))
13102 (list (read-file-name
13103 "Read project file: " (when (file-name-absolute-p name) "") nil t
13104 (file-name-directory name)))))
13105 (when (file-exists-p file-name)
13106 (condition-case ()
13107 (let ((current-project vhdl-project))
13108 (load-file file-name)
13109 (when (/= (length (vhdl-aget vhdl-project-alist vhdl-project)) 10)
13110 (vhdl-adelete 'vhdl-project-alist vhdl-project)
13111 (error ""))
13112 (if not-make-current
13113 (setq vhdl-project current-project)
13114 (setq vhdl-compiler
13115 (caar (nth 4 (vhdl-aget vhdl-project-alist vhdl-project)))))
13116 (vhdl-update-mode-menu)
13117 (vhdl-speedbar-refresh)
13118 (unless not-make-current
13119 (message "Current VHDL project: \"%s\"; compiler: \"%s\"%s"
13120 vhdl-project vhdl-compiler (if auto " (auto-loaded)" ""))))
13121 (error (vhdl-warning
13122 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
13124 (defun vhdl-duplicate-project ()
13125 "Duplicate setup of current project."
13126 (interactive)
13127 (let ((new-name (read-from-minibuffer "New project name: "))
13128 (project-entry (vhdl-aget vhdl-project-alist vhdl-project)))
13129 (setq vhdl-project-alist
13130 (append vhdl-project-alist
13131 (list (cons new-name project-entry))))
13132 (vhdl-update-mode-menu)))
13134 (defun vhdl-auto-load-project ()
13135 "Automatically load project setup at startup."
13136 (let ((file-name-list vhdl-project-file-name)
13137 file-list list-length)
13138 (while file-name-list
13139 (setq file-list
13140 (append file-list
13141 (file-expand-wildcards
13142 (vhdl-resolve-env-variable
13143 (vhdl-replace-string
13144 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
13145 (concat "* " (user-login-name)))))))
13146 (setq list-length (or list-length (length file-list)))
13147 (setq file-name-list (cdr file-name-list)))
13148 (while file-list
13149 (vhdl-import-project (expand-file-name (car file-list)) t
13150 (not (> list-length 0)))
13151 (setq list-length (1- list-length))
13152 (setq file-list (cdr file-list)))))
13154 ;; automatically load project setup when idle after startup
13155 (when (memq 'startup vhdl-project-auto-load)
13156 (if noninteractive
13157 (vhdl-auto-load-project)
13158 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
13161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13162 ;;; Hideshow
13163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13164 ;; (using `hideshow.el')
13166 (defconst vhdl-hs-start-regexp
13167 (concat
13168 "\\(^\\)\\s-*\\("
13169 ;; generic/port clause
13170 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
13171 ;; component
13172 "component\\>\\|"
13173 ;; component instantiation
13174 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
13175 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13176 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
13177 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
13178 ;; subprogram
13179 "\\(function\\|procedure\\)\\>\\|"
13180 ;; process, block
13181 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13182 ;; configuration declaration
13183 "configuration\\>"
13184 "\\)")
13185 "Regexp to match start of construct to hide.")
13187 (defun vhdl-hs-forward-sexp-func (count)
13188 "Find end of construct to hide (for hideshow). Only searches forward."
13189 (let ((pos (point)))
13190 (vhdl-prepare-search-2
13191 (beginning-of-line)
13192 (cond
13193 ;; generic/port clause
13194 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13195 (goto-char (match-end 0))
13196 (backward-char)
13197 (forward-sexp))
13198 ;; component declaration
13199 ((looking-at "^\\s-*component\\>")
13200 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
13201 ;; component instantiation
13202 ((looking-at
13203 (concat
13204 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13205 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13206 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13207 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13208 (goto-char (match-end 0))
13209 (backward-char)
13210 (forward-sexp)
13211 (setq pos (point))
13212 (vhdl-forward-syntactic-ws)
13213 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13214 (goto-char (match-end 0))
13215 (backward-char)
13216 (forward-sexp)
13217 (setq pos (point)))
13218 (goto-char pos))
13219 ;; subprogram declaration/body
13220 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13221 (goto-char (match-end 0))
13222 (vhdl-forward-syntactic-ws)
13223 (when (looking-at "(")
13224 (forward-sexp))
13225 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
13226 (vhdl-in-literal)))
13227 ;; subprogram body
13228 (when (match-string 2)
13229 (re-search-forward "^\\s-*\\<begin\\>" nil t)
13230 (backward-word-strictly 1)
13231 (vhdl-forward-sexp)))
13232 ;; block (recursive)
13233 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13234 (goto-char (match-end 0))
13235 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
13236 (match-beginning 2))
13237 (vhdl-hs-forward-sexp-func count)))
13238 ;; process
13239 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13240 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
13241 ;; configuration declaration
13242 ((looking-at "^\\s-*configuration\\>")
13243 (forward-word-strictly 4)
13244 (vhdl-forward-sexp))
13245 (t (goto-char pos))))))
13247 (defun vhdl-hideshow-init ()
13248 "Initialize `hideshow'."
13249 (when vhdl-hideshow-menu
13250 (vhdl-hs-minor-mode 1)))
13252 (defun vhdl-hs-minor-mode (&optional arg)
13253 "Toggle hideshow minor mode and update menu bar."
13254 (interactive "P")
13255 (require 'hideshow)
13256 ;; check for hideshow version 5.x
13257 (if (not (boundp 'hs-block-start-mdata-select))
13258 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13259 ;; initialize hideshow
13260 (unless (assoc 'vhdl-mode hs-special-modes-alist)
13261 (setq hs-special-modes-alist
13262 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
13263 'vhdl-hs-forward-sexp-func nil)
13264 hs-special-modes-alist)))
13265 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
13266 (if vhdl-hide-all-init
13267 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
13268 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
13269 (hs-minor-mode arg)
13270 (force-mode-line-update))) ; hack to update menu bar
13273 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13274 ;;; Font locking
13275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13276 ;; (using `font-lock.el')
13278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13279 ;; Help functions
13281 (defun vhdl-within-translate-off ()
13282 "Return point if within translate-off region, else nil."
13283 (and (save-excursion
13284 (re-search-backward
13285 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
13286 (equal "off" (match-string 1))
13287 (point)))
13289 (defun vhdl-start-translate-off (limit)
13290 "Return point before translate-off pragma if before LIMIT, else nil."
13291 (when (re-search-forward
13292 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
13293 (match-beginning 0)))
13295 (defun vhdl-end-translate-off (limit)
13296 "Return point after translate-on pragma if before LIMIT, else nil."
13297 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
13299 (defun vhdl-match-translate-off (limit)
13300 "Match a translate-off block, setting match-data and returning t, else nil."
13301 (when (< (point) limit)
13302 (let ((start (or (vhdl-within-translate-off)
13303 (vhdl-start-translate-off limit)))
13304 (case-fold-search t))
13305 (when start
13306 (let ((end (or (vhdl-end-translate-off limit) limit)))
13307 (set-match-data (list start end))
13308 (goto-char end))))))
13310 (defun vhdl-font-lock-match-item (limit)
13311 "Match, and move over, any declaration item after point. Adapted from
13312 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13313 (condition-case nil
13314 (save-restriction
13315 (narrow-to-region (point-min) limit)
13316 ;; match item
13317 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13318 (save-match-data
13319 (goto-char (match-end 1))
13320 ;; move to next item
13321 (if (looking-at "\\(\\s-*,\\)")
13322 (goto-char (match-end 1))
13323 (end-of-line) t))))
13324 (error t)))
13326 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13327 ;; Syntax definitions
13329 (defconst vhdl-font-lock-syntactic-keywords
13330 '(("\\('\\).\\('\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
13331 "Mark single quotes as having string quote syntax in `c' instances.")
13333 (defvar vhdl-font-lock-keywords nil
13334 "Regular expressions to highlight in VHDL Mode.")
13336 (defvar vhdl-font-lock-keywords-0
13337 ;; set in `vhdl-font-lock-init' because dependent on user options
13338 "For consideration as a value of `vhdl-font-lock-keywords'.
13339 This does highlighting of template prompts and directives (pragmas).")
13341 (defvar vhdl-font-lock-keywords-1 nil
13342 ;; set in `vhdl-font-lock-init' because dependent on user options
13343 "For consideration as a value of `vhdl-font-lock-keywords'.
13344 This does highlighting of keywords and standard identifiers.")
13346 (defconst vhdl-font-lock-keywords-2
13347 (list
13348 ;; highlight names of units, subprograms, and components when declared
13349 (list
13350 (concat
13351 "^\\s-*\\("
13352 "architecture\\|configuration\\|context\\|entity\\|package"
13353 "\\(\\s-+body\\)?\\|"
13354 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13355 "\\)\\s-+\\(\\w+\\)")
13356 5 'font-lock-function-name-face)
13358 ;; highlight entity names of architectures and configurations
13359 (list
13360 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13361 2 'font-lock-function-name-face)
13363 ;; highlight labels of common constructs
13364 (list
13365 (concat
13366 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13367 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13368 "postponed\\|process\\|"
13369 (when (vhdl-standard-p 'ams) "procedural\\|")
13370 "with\\|while"
13371 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13372 1 'font-lock-function-name-face)
13374 ;; highlight label and component name of component instantiations
13375 (list
13376 (concat
13377 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13378 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13379 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13381 ;; highlight label and instantiated unit of component instantiations
13382 (list
13383 (concat
13384 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13385 "\\(component\\|configuration\\|entity\\)\\s-+"
13386 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13387 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13388 '(5 font-lock-function-name-face nil t)
13389 '(7 font-lock-function-name-face nil t))
13391 ;; highlight names and labels at end of constructs
13392 (list
13393 (concat
13394 "^\\s-*end\\s-+\\(\\("
13395 "architecture\\|block\\|case\\|component\\|configuration\\|context\\|"
13396 "entity\\|for\\|function\\|generate\\|if\\|loop\\|package"
13397 "\\(\\s-+body\\)?\\|procedure\\|\\(postponed\\s-+\\)?process\\|"
13398 (when (vhdl-standard-p 'ams) "procedural\\|")
13399 "units"
13400 "\\)\\s-+\\)?\\(\\w*\\)")
13401 5 'font-lock-function-name-face)
13403 ;; highlight labels in exit and next statements
13404 (list
13405 (concat
13406 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13407 3 'font-lock-function-name-face)
13409 ;; highlight entity name in attribute specifications
13410 (list
13411 (concat
13412 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13413 1 'font-lock-function-name-face)
13415 ;; highlight labels in block and component specifications
13416 (list
13417 (concat
13418 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13419 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13420 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13422 ;; highlight names in library clauses
13423 (list "^\\s-*library\\>"
13424 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13426 ;; highlight names in use clauses
13427 (list
13428 (concat
13429 "\\<\\(context\\|use\\)\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13430 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13431 '(4 font-lock-function-name-face) '(6 font-lock-function-name-face nil t)
13432 '(8 font-lock-function-name-face nil t))
13434 ;; highlight attribute name in attribute declarations/specifications
13435 (list
13436 (concat
13437 "^\\s-*attribute\\s-+\\(\\w+\\)")
13438 1 'vhdl-font-lock-attribute-face)
13440 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13441 (list
13442 (concat
13443 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13444 5 'font-lock-type-face)
13446 ;; highlight signal/variable/constant declaration names
13447 (list "\\(:[^=]\\)"
13448 '(vhdl-font-lock-match-item
13449 (progn (goto-char (match-beginning 1))
13450 (skip-syntax-backward " ")
13451 (skip-syntax-backward "w_")
13452 (skip-syntax-backward " ")
13453 (while (= (preceding-char) ?,)
13454 (backward-char 1)
13455 (skip-syntax-backward " ")
13456 (skip-syntax-backward "w_")
13457 (skip-syntax-backward " ")))
13458 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13460 ;; highlight formal parameters in component instantiations and subprogram
13461 ;; calls
13462 (list "\\(=>\\)"
13463 '(vhdl-font-lock-match-item
13464 (progn (goto-char (match-beginning 1))
13465 (skip-syntax-backward " ")
13466 (while (= (preceding-char) ?\)) (backward-sexp))
13467 (skip-syntax-backward "w_")
13468 (skip-syntax-backward " ")
13469 (when (memq (preceding-char) '(?n ?N ?|))
13470 (goto-char (point-max))))
13471 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13473 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13474 ;; variables
13475 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13476 '(vhdl-font-lock-match-item
13477 (progn (goto-char (match-end 1)) (match-beginning 2))
13478 nil (1 font-lock-variable-name-face)))
13480 ;; highlight tool directives
13481 (list
13482 (concat
13483 "^\\s-*\\(`\\w+\\)")
13484 1 'font-lock-preprocessor-face)
13486 "For consideration as a value of `vhdl-font-lock-keywords'.
13487 This does context sensitive highlighting of names and labels.")
13489 (defvar vhdl-font-lock-keywords-3 nil
13490 ;; set in `vhdl-font-lock-init' because dependent on user options
13491 "For consideration as a value of `vhdl-font-lock-keywords'.
13492 This does highlighting of words with special syntax.")
13494 (defvar vhdl-font-lock-keywords-4 nil
13495 ;; set in `vhdl-font-lock-init' because dependent on user options
13496 "For consideration as a value of `vhdl-font-lock-keywords'.
13497 This does highlighting of additional reserved words.")
13499 (defconst vhdl-font-lock-keywords-5
13500 ;; background highlight translate-off regions
13501 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13502 "For consideration as a value of `vhdl-font-lock-keywords'.
13503 This does background highlighting of translate-off regions.")
13505 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13506 ;; Font and color definitions
13508 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13509 "Face name to use for prompts.")
13511 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13512 "Face name to use for standardized attributes.")
13514 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13515 "Face name to use for standardized enumeration values.")
13517 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13518 "Face name to use for standardized functions and packages.")
13520 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13521 "Face name to use for directives.")
13523 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13524 "Face name to use for additional reserved words.")
13526 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13527 "Face name to use for translate-off regions.")
13529 ;; face names to use for words with special syntax.
13530 (let ((syntax-alist vhdl-special-syntax-alist)
13531 name)
13532 (while syntax-alist
13533 (setq name (vhdl-function-name
13534 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13535 (eval `(defvar ,name ',name
13536 ,(concat "Face name to use for "
13537 (nth 0 (car syntax-alist)) ".")))
13538 (setq syntax-alist (cdr syntax-alist))))
13540 (defgroup vhdl-highlight-faces nil
13541 "Faces for highlighting."
13542 :group 'vhdl-highlight)
13544 ;; add faces used from `font-lock'
13545 (custom-add-to-group
13546 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13547 (custom-add-to-group
13548 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13549 (custom-add-to-group
13550 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13551 (custom-add-to-group
13552 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13553 (custom-add-to-group
13554 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13555 (custom-add-to-group
13556 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13558 (defface vhdl-font-lock-prompt-face
13559 '((((min-colors 88) (class color) (background light))
13560 (:foreground "Red1" :bold t))
13561 (((class color) (background light)) (:foreground "Red" :bold t))
13562 (((class color) (background dark)) (:foreground "Pink" :bold t))
13563 (t (:inverse-video t)))
13564 "Font lock mode face used to highlight prompts."
13565 :group 'vhdl-highlight-faces)
13567 (defface vhdl-font-lock-attribute-face
13568 '((((class color) (background light)) (:foreground "Orchid"))
13569 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13570 (t (:italic t :bold t)))
13571 "Font lock mode face used to highlight standardized attributes."
13572 :group 'vhdl-highlight-faces)
13574 (defface vhdl-font-lock-enumvalue-face
13575 '((((class color) (background light)) (:foreground "SaddleBrown"))
13576 (((class color) (background dark)) (:foreground "BurlyWood"))
13577 (t (:italic t :bold t)))
13578 "Font lock mode face used to highlight standardized enumeration values."
13579 :group 'vhdl-highlight-faces)
13581 (defface vhdl-font-lock-function-face
13582 '((((class color) (background light)) (:foreground "Cyan4"))
13583 (((class color) (background dark)) (:foreground "Orchid1"))
13584 (t (:italic t :bold t)))
13585 "Font lock mode face used to highlight standardized functions and packages."
13586 :group 'vhdl-highlight-faces)
13588 (defface vhdl-font-lock-directive-face
13589 '((((class color) (background light)) (:foreground "CadetBlue"))
13590 (((class color) (background dark)) (:foreground "Aquamarine"))
13591 (t (:italic t :bold t)))
13592 "Font lock mode face used to highlight directives."
13593 :group 'vhdl-highlight-faces)
13595 (defface vhdl-font-lock-reserved-words-face
13596 '((((class color) (background light)) (:foreground "Orange" :bold t))
13597 (((min-colors 88) (class color) (background dark))
13598 (:foreground "Yellow1" :bold t))
13599 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13600 (t ()))
13601 "Font lock mode face used to highlight additional reserved words."
13602 :group 'vhdl-highlight-faces)
13604 (defface vhdl-font-lock-translate-off-face
13605 '((((class color) (background light)) (:background "LightGray"))
13606 (((class color) (background dark)) (:background "DimGray"))
13607 (t ()))
13608 "Font lock mode face used to background highlight translate-off regions."
13609 :group 'vhdl-highlight-faces)
13611 ;; font lock mode faces used to highlight words with special syntax.
13612 (let ((syntax-alist vhdl-special-syntax-alist))
13613 (while syntax-alist
13614 (eval `(defface ,(vhdl-function-name
13615 "vhdl-font-lock" (caar syntax-alist) "face")
13616 '((((class color) (background light))
13617 (:foreground ,(nth 2 (car syntax-alist))))
13618 (((class color) (background dark))
13619 (:foreground ,(nth 3 (car syntax-alist))))
13620 (t ()))
13621 ,(concat "Font lock mode face used to highlight "
13622 (nth 0 (car syntax-alist)) ".")
13623 :group 'vhdl-highlight-faces))
13624 (setq syntax-alist (cdr syntax-alist))))
13626 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13627 ;; Font lock initialization
13629 (defun vhdl-font-lock-init ()
13630 "Initialize fontification."
13631 ;; highlight template prompts and directives
13632 (setq vhdl-font-lock-keywords-0
13633 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13634 vhdl-template-prompt-syntax ">\\)")
13635 2 'vhdl-font-lock-prompt-face t)
13636 (list (concat "--\\s-*"
13637 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13638 2 'vhdl-font-lock-directive-face t)
13639 ;; highlight c-preprocessor directives
13640 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13641 '(1 font-lock-builtin-face)
13642 '(3 font-lock-variable-name-face nil t))))
13643 ;; highlight keywords and standardized types, attributes, enumeration
13644 ;; values, and subprograms
13645 (setq vhdl-font-lock-keywords-1
13646 (list
13647 (list (concat "'" vhdl-attributes-regexp)
13648 1 'vhdl-font-lock-attribute-face)
13649 (list vhdl-types-regexp 1 'font-lock-type-face)
13650 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13651 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13652 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13653 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13654 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13655 ;; highlight words with special syntax.
13656 (setq vhdl-font-lock-keywords-3
13657 (let ((syntax-alist vhdl-special-syntax-alist)
13658 keywords)
13659 (while syntax-alist
13660 (setq keywords
13661 (cons
13662 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13663 (vhdl-function-name
13664 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13665 (nth 4 (car syntax-alist)))
13666 keywords))
13667 (setq syntax-alist (cdr syntax-alist)))
13668 keywords))
13669 ;; highlight additional reserved words
13670 (setq vhdl-font-lock-keywords-4
13671 (list (list vhdl-reserved-words-regexp 1
13672 'vhdl-font-lock-reserved-words-face)))
13673 ;; highlight everything together
13674 (setq vhdl-font-lock-keywords
13675 (append
13676 vhdl-font-lock-keywords-0
13677 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13678 (when (or vhdl-highlight-forbidden-words
13679 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13680 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13681 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13682 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13684 ;; initialize fontification for VHDL Mode
13685 (vhdl-font-lock-init)
13687 (defun vhdl-fontify-buffer ()
13688 "Re-initialize fontification and fontify buffer."
13689 (interactive)
13690 (setq font-lock-defaults
13691 `(vhdl-font-lock-keywords
13692 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13693 beginning-of-line))
13694 (when (fboundp 'font-lock-unset-defaults)
13695 (font-lock-unset-defaults)) ; not implemented in XEmacs
13696 (font-lock-set-defaults)
13697 (font-lock-mode nil)
13698 (font-lock-mode t))
13700 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13701 ;; Initialization for PostScript printing
13703 (defun vhdl-ps-print-settings ()
13704 "Initialize custom face and page settings for PostScript printing."
13705 ;; define custom face settings
13706 (unless (or (not vhdl-print-customize-faces)
13707 ps-print-color-p)
13708 (set (make-local-variable 'ps-bold-faces)
13709 '(font-lock-keyword-face
13710 font-lock-type-face
13711 vhdl-font-lock-attribute-face
13712 vhdl-font-lock-enumvalue-face
13713 vhdl-font-lock-directive-face))
13714 (set (make-local-variable 'ps-italic-faces)
13715 '(font-lock-comment-face
13716 font-lock-function-name-face
13717 font-lock-type-face
13718 vhdl-font-lock-attribute-face
13719 vhdl-font-lock-enumvalue-face
13720 vhdl-font-lock-directive-face))
13721 (set (make-local-variable 'ps-underlined-faces)
13722 '(font-lock-string-face))
13723 (setq ps-always-build-face-reference t))
13724 ;; define page settings, so that a line containing 79 characters (default)
13725 ;; fits into one column
13726 (when vhdl-print-two-column
13727 (set (make-local-variable 'ps-landscape-mode) t)
13728 (set (make-local-variable 'ps-number-of-columns) 2)
13729 (set (make-local-variable 'ps-font-size) 7.0)
13730 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13731 (set (make-local-variable 'ps-header-font-size) 9.0)
13732 (set (make-local-variable 'ps-header-offset) 12.0)
13733 (when (eq ps-paper-type 'letter)
13734 (set (make-local-variable 'ps-inter-column) 40.0)
13735 (set (make-local-variable 'ps-left-margin) 40.0)
13736 (set (make-local-variable 'ps-right-margin) 40.0))))
13738 (defun vhdl-ps-print-init ()
13739 "Initialize PostScript printing."
13740 (if (featurep 'xemacs)
13741 (when (boundp 'ps-print-color-p)
13742 (vhdl-ps-print-settings))
13743 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13744 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13748 ;;; Hierarchy browser (using `speedbar.el')
13749 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13750 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13751 ;; directory by using the speedbar.
13753 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13754 ;; Variables
13756 (defvar vhdl-entity-alist nil
13757 "Cache with entities and corresponding architectures for each
13758 project/directory.")
13759 ;; structure: (parenthesized expression means list of such entries)
13760 ;; (cache-key
13761 ;; (ent-key ent-name ent-file ent-line
13762 ;; (arch-key arch-name arch-file arch-line
13763 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13764 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13765 ;; (lib-name pack-key))
13766 ;; mra-key (lib-name pack-key))
13768 (defvar vhdl-config-alist nil
13769 "Cache with configurations for each project/directory.")
13770 ;; structure: (parenthesized expression means list of such entries)
13771 ;; (cache-key
13772 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13773 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13774 ;; inst-conf-key inst-lib-key)
13775 ;; (lib-name pack-key)))
13777 (defvar vhdl-package-alist nil
13778 "Cache with packages for each project/directory.")
13779 ;; structure: (parenthesized expression means list of such entries)
13780 ;; (cache-key
13781 ;; (pack-key pack-name pack-file pack-line
13782 ;; (comp-key comp-name comp-file comp-line)
13783 ;; (func-key func-name func-file func-line)
13784 ;; (lib-name pack-key)
13785 ;; pack-body-file pack-body-line
13786 ;; (func-key func-name func-body-file func-body-line)
13787 ;; (lib-name pack-key)))
13789 (defvar vhdl-ent-inst-alist nil
13790 "Cache with instantiated entities for each project/directory.")
13791 ;; structure: (parenthesized expression means list of such entries)
13792 ;; (cache-key (inst-ent-key))
13794 (defvar vhdl-file-alist nil
13795 "Cache with design units in each file for each project/directory.")
13796 ;; structure: (parenthesized expression means list of such entries)
13797 ;; (cache-key
13798 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13799 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13801 (defvar vhdl-directory-alist nil
13802 "Cache with source directories for each project.")
13803 ;; structure: (parenthesized expression means list of such entries)
13804 ;; (cache-key (directory))
13806 (defvar vhdl-speedbar-shown-unit-alist nil
13807 "Alist of design units simultaneously open in the current speedbar for each
13808 directory and project.")
13810 (defvar vhdl-speedbar-shown-project-list nil
13811 "List of projects simultaneously open in the current speedbar.")
13813 (defvar vhdl-updated-project-list nil
13814 "List of projects and directories with updated files.")
13816 (defvar vhdl-modified-file-list nil
13817 "List of modified files to be rescanned for hierarchy updating.")
13819 (defvar vhdl-speedbar-hierarchy-depth 0
13820 "Depth of instantiation hierarchy to display.")
13822 (defvar vhdl-speedbar-show-projects nil
13823 "Non-nil means project hierarchy is displayed in speedbar, directory
13824 hierarchy otherwise.")
13826 (defun vhdl-get-end-of-unit ()
13827 "Return position of end of current unit."
13828 (let ((pos (point)))
13829 (save-excursion
13830 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil 1)
13831 (save-excursion
13832 (goto-char (match-beginning 0))
13833 (vhdl-backward-syntactic-ws)
13834 (and (/= (preceding-char) ?\;) (not (bobp))))))
13835 (re-search-backward "^[ \t]*end\\>" pos 1)
13836 (point))))
13838 (defun vhdl-match-string-downcase (num &optional string)
13839 "Like `match-string-no-properties' with down-casing."
13840 (let ((match (match-string-no-properties num string)))
13841 (and match (downcase match))))
13844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13845 ;; Scan functions
13847 (defun vhdl-scan-context-clause ()
13848 "Scan the context clause that precedes a design unit."
13849 (let (lib-alist)
13850 (save-excursion
13851 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil t)
13852 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13853 (equal "USE" (upcase (match-string 1))))
13854 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13855 (push (cons (match-string-no-properties 1)
13856 (vhdl-match-string-downcase 2))
13857 lib-alist)))))
13858 lib-alist))
13860 (defun vhdl-scan-directory-contents (name &optional project update num-string
13861 non-final)
13862 "Scan contents of VHDL files in directory or file pattern NAME."
13863 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13864 (let* ((dir-name (match-string 1 name))
13865 (file-pattern (match-string 2 name))
13866 (is-directory (= 0 (length file-pattern)))
13867 (file-list
13868 (if update
13869 (list name)
13870 (if is-directory
13871 (vhdl-get-source-files t dir-name)
13872 (vhdl-directory-files
13873 dir-name t (wildcard-to-regexp file-pattern)))))
13874 (key (or project dir-name))
13875 (file-exclude-regexp
13876 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
13877 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13878 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13879 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13880 ent-alist conf-alist pack-alist ent-inst-list file-alist
13881 tmp-list tmp-entry no-files files-exist big-files)
13882 (when (or project update)
13883 (setq ent-alist (vhdl-aget vhdl-entity-alist key)
13884 conf-alist (vhdl-aget vhdl-config-alist key)
13885 pack-alist (vhdl-aget vhdl-package-alist key)
13886 ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist key))
13887 file-alist (vhdl-aget vhdl-file-alist key)))
13888 (when (and (not is-directory) (null file-list))
13889 (message "No such file: \"%s\"" name))
13890 (setq files-exist file-list)
13891 (when file-list
13892 (setq no-files (length file-list))
13893 (message "Scanning %s %s\"%s\"..."
13894 (if is-directory "directory" "files") (or num-string "") name)
13895 ;; exclude files
13896 (unless (equal file-exclude-regexp "")
13897 (let ((case-fold-search nil)
13898 file-tmp-list)
13899 (while file-list
13900 (unless (string-match file-exclude-regexp (car file-list))
13901 (push (car file-list) file-tmp-list))
13902 (setq file-list (cdr file-list)))
13903 (setq file-list (nreverse file-tmp-list))))
13904 ;; do for all files
13905 (while file-list
13906 (unless noninteractive
13907 (message "Scanning %s %s\"%s\"... (%2d%%)"
13908 (if is-directory "directory" "files")
13909 (or num-string "") name
13910 (floor (* 100.0 (- no-files (length file-list))) no-files)))
13911 (let ((file-name (abbreviate-file-name (car file-list)))
13912 ent-list arch-list arch-ent-list conf-list
13913 pack-list pack-body-list inst-list inst-ent-list)
13914 ;; scan file
13915 (vhdl-visit-file
13916 file-name nil
13917 (vhdl-prepare-search-2
13918 (save-excursion
13919 ;; scan for design units
13920 (if (and limit-design-file-size
13921 (< limit-design-file-size (buffer-size)))
13922 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13923 (setq big-files t))
13924 ;; scan for entities
13925 (goto-char (point-min))
13926 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13927 (let* ((ent-name (match-string-no-properties 1))
13928 (ent-key (downcase ent-name))
13929 (ent-entry (vhdl-aget ent-alist ent-key))
13930 (lib-alist (vhdl-scan-context-clause)))
13931 (if (nth 1 ent-entry)
13932 (vhdl-warning-when-idle
13933 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13934 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13935 file-name (vhdl-current-line))
13936 (push ent-key ent-list)
13937 (vhdl-aput 'ent-alist ent-key
13938 (list ent-name file-name (vhdl-current-line)
13939 (nth 3 ent-entry) (nth 4 ent-entry)
13940 lib-alist)))))
13941 ;; scan for architectures
13942 (goto-char (point-min))
13943 (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)
13944 (let* ((arch-name (match-string-no-properties 1))
13945 (arch-key (downcase arch-name))
13946 (ent-name (match-string-no-properties 2))
13947 (ent-key (downcase ent-name))
13948 (ent-entry (vhdl-aget ent-alist ent-key))
13949 (arch-alist (nth 3 ent-entry))
13950 (arch-entry (vhdl-aget arch-alist arch-key))
13951 (lib-arch-alist (vhdl-scan-context-clause)))
13952 (if arch-entry
13953 (vhdl-warning-when-idle
13954 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13955 arch-name ent-name (nth 1 arch-entry)
13956 (nth 2 arch-entry) file-name (vhdl-current-line))
13957 (setq arch-list (cons arch-key arch-list)
13958 arch-ent-list (cons ent-key arch-ent-list))
13959 (vhdl-aput 'arch-alist arch-key
13960 (list arch-name file-name (vhdl-current-line)
13961 nil lib-arch-alist))
13962 (vhdl-aput 'ent-alist ent-key
13963 (list (or (nth 0 ent-entry) ent-name)
13964 (nth 1 ent-entry) (nth 2 ent-entry)
13965 (vhdl-sort-alist arch-alist)
13966 arch-key (nth 5 ent-entry))))))
13967 ;; scan for configurations
13968 (goto-char (point-min))
13969 (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)
13970 (let* ((conf-name (match-string-no-properties 1))
13971 (conf-key (downcase conf-name))
13972 (conf-entry (vhdl-aget conf-alist conf-key))
13973 (ent-name (match-string-no-properties 2))
13974 (ent-key (downcase ent-name))
13975 (lib-alist (vhdl-scan-context-clause))
13976 (conf-line (vhdl-current-line))
13977 (end-of-unit (vhdl-get-end-of-unit))
13978 arch-key comp-conf-list inst-key-list
13979 inst-comp-key inst-ent-key inst-arch-key
13980 inst-conf-key inst-lib-key)
13981 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13982 (setq arch-key (vhdl-match-string-downcase 1)))
13983 (if conf-entry
13984 (vhdl-warning-when-idle
13985 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13986 conf-name ent-name (nth 1 conf-entry)
13987 (nth 2 conf-entry) file-name conf-line)
13988 (push conf-key conf-list)
13989 ;; scan for subconfigurations and subentities
13990 (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)
13991 (setq inst-comp-key (vhdl-match-string-downcase 3)
13992 inst-key-list (split-string
13993 (vhdl-match-string-downcase 1)
13994 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13995 (vhdl-forward-syntactic-ws)
13996 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13997 (setq
13998 inst-lib-key (vhdl-match-string-downcase 3)
13999 inst-ent-key (and (match-string 2)
14000 (vhdl-match-string-downcase 4))
14001 inst-arch-key (and (match-string 2)
14002 (vhdl-match-string-downcase 6))
14003 inst-conf-key (and (not (match-string 2))
14004 (vhdl-match-string-downcase 4)))
14005 (while inst-key-list
14006 (setq comp-conf-list
14007 (cons (list (car inst-key-list)
14008 inst-comp-key inst-ent-key
14009 inst-arch-key inst-conf-key
14010 inst-lib-key)
14011 comp-conf-list))
14012 (setq inst-key-list (cdr inst-key-list)))))
14013 (vhdl-aput 'conf-alist conf-key
14014 (list conf-name file-name conf-line ent-key
14015 arch-key comp-conf-list lib-alist)))))
14016 ;; scan for packages
14017 (goto-char (point-min))
14018 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
14019 (let* ((pack-name (match-string-no-properties 2))
14020 (pack-key (downcase pack-name))
14021 (is-body (match-string-no-properties 1))
14022 (pack-entry (vhdl-aget pack-alist pack-key))
14023 (pack-line (vhdl-current-line))
14024 (end-of-unit (vhdl-get-end-of-unit))
14025 comp-name func-name comp-alist func-alist lib-alist)
14026 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14027 (vhdl-warning-when-idle
14028 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
14029 (if is-body " body" "") pack-name
14030 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14031 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
14032 file-name (vhdl-current-line))
14033 ;; scan for context clauses
14034 (setq lib-alist (vhdl-scan-context-clause))
14035 ;; scan for component and subprogram declarations/bodies
14036 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
14037 (if (equal (upcase (match-string 1)) "COMPONENT")
14038 (setq comp-name (match-string-no-properties 2)
14039 comp-alist
14040 (cons (list (downcase comp-name) comp-name
14041 file-name (vhdl-current-line))
14042 comp-alist))
14043 (setq func-name (match-string-no-properties 2)
14044 func-alist
14045 (cons (list (downcase func-name) func-name
14046 file-name (vhdl-current-line))
14047 func-alist))))
14048 (setq func-alist (nreverse func-alist))
14049 (setq comp-alist (nreverse comp-alist))
14050 (if is-body
14051 (push pack-key pack-body-list)
14052 (push pack-key pack-list))
14053 (vhdl-aput
14054 'pack-alist pack-key
14055 (if is-body
14056 (list (or (nth 0 pack-entry) pack-name)
14057 (nth 1 pack-entry) (nth 2 pack-entry)
14058 (nth 3 pack-entry) (nth 4 pack-entry)
14059 (nth 5 pack-entry)
14060 file-name pack-line func-alist lib-alist)
14061 (list pack-name file-name pack-line
14062 comp-alist func-alist lib-alist
14063 (nth 6 pack-entry) (nth 7 pack-entry)
14064 (nth 8 pack-entry) (nth 9 pack-entry))))))))
14065 ;; scan for hierarchy
14066 (if (and limit-hier-file-size
14067 (< limit-hier-file-size (buffer-size)))
14068 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
14069 (setq big-files t))
14070 ;; scan for architectures
14071 (goto-char (point-min))
14072 (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)
14073 (let* ((ent-name (match-string-no-properties 2))
14074 (ent-key (downcase ent-name))
14075 (arch-name (match-string-no-properties 1))
14076 (arch-key (downcase arch-name))
14077 (ent-entry (vhdl-aget ent-alist ent-key))
14078 (arch-alist (nth 3 ent-entry))
14079 (arch-entry (vhdl-aget arch-alist arch-key))
14080 (beg-of-unit (point))
14081 (end-of-unit (vhdl-get-end-of-unit))
14082 (inst-no 0)
14083 inst-alist inst-path)
14084 ;; scan for contained instantiations
14085 (while (and (re-search-forward
14086 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
14087 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
14088 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
14089 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
14090 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
14091 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
14092 (or (not limit-hier-inst-no)
14093 (<= (if (or (match-string 14)
14094 (match-string 16))
14095 inst-no
14096 (setq inst-no (1+ inst-no)))
14097 limit-hier-inst-no)))
14098 (cond
14099 ;; block/generate beginning found
14100 ((match-string 14)
14101 (setq inst-path
14102 (cons (match-string-no-properties 1) inst-path)))
14103 ;; block/generate end found
14104 ((match-string 16)
14105 (setq inst-path (cdr inst-path)))
14106 ;; instantiation found
14108 (let* ((inst-name (match-string-no-properties 1))
14109 (inst-key (downcase inst-name))
14110 (inst-comp-name
14111 (or (match-string-no-properties 3)
14112 (match-string-no-properties 6)))
14113 (inst-ent-key
14114 (or (and (match-string 8)
14115 (vhdl-match-string-downcase 11))
14116 (and inst-comp-name
14117 (downcase inst-comp-name))))
14118 (inst-arch-key (vhdl-match-string-downcase 13))
14119 (inst-conf-key
14120 (and (not (match-string 8))
14121 (vhdl-match-string-downcase 11)))
14122 (inst-lib-key (vhdl-match-string-downcase 10)))
14123 (goto-char (match-end 1))
14124 (setq inst-list (cons inst-key inst-list)
14125 inst-ent-list
14126 (cons inst-ent-key inst-ent-list))
14127 (setq inst-alist
14128 (append
14129 inst-alist
14130 (list (list inst-key inst-name file-name
14131 (vhdl-current-line) inst-comp-name
14132 inst-ent-key inst-arch-key
14133 inst-conf-key inst-lib-key
14134 (reverse inst-path)))))))))
14135 ;; scan for contained configuration specifications
14136 (goto-char beg-of-unit)
14137 (while (re-search-forward
14138 (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]*\\)*"
14139 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
14140 (let* ((inst-comp-name (match-string-no-properties 3))
14141 (inst-ent-key
14142 (and (match-string 6)
14143 (vhdl-match-string-downcase 9)))
14144 (inst-arch-key (vhdl-match-string-downcase 11))
14145 (inst-conf-key
14146 (and (not (match-string 6))
14147 (vhdl-match-string-downcase 9)))
14148 (inst-lib-key (vhdl-match-string-downcase 8))
14149 (inst-key-list
14150 (split-string (vhdl-match-string-downcase 1)
14151 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
14152 (tmp-inst-alist inst-alist)
14153 inst-entry)
14154 (while tmp-inst-alist
14155 (when (and (or (equal "all" (car inst-key-list))
14156 (member (nth 0 (car tmp-inst-alist))
14157 inst-key-list))
14158 (equal
14159 (downcase
14160 (or (nth 4 (car tmp-inst-alist)) ""))
14161 (downcase inst-comp-name)))
14162 (setq inst-entry (car tmp-inst-alist))
14163 (setq inst-ent-list
14164 (cons (or inst-ent-key (nth 5 inst-entry))
14165 (vhdl-delete
14166 (nth 5 inst-entry) inst-ent-list)))
14167 (setq inst-entry
14168 (list (nth 0 inst-entry) (nth 1 inst-entry)
14169 (nth 2 inst-entry) (nth 3 inst-entry)
14170 (nth 4 inst-entry)
14171 (or inst-ent-key (nth 5 inst-entry))
14172 (or inst-arch-key (nth 6 inst-entry))
14173 inst-conf-key inst-lib-key))
14174 (setcar tmp-inst-alist inst-entry))
14175 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
14176 ;; save in cache
14177 (vhdl-aput 'arch-alist arch-key
14178 (list (nth 0 arch-entry) (nth 1 arch-entry)
14179 (nth 2 arch-entry) inst-alist
14180 (nth 4 arch-entry)))
14181 (vhdl-aput 'ent-alist ent-key
14182 (list (nth 0 ent-entry) (nth 1 ent-entry)
14183 (nth 2 ent-entry)
14184 (vhdl-sort-alist arch-alist)
14185 (nth 4 ent-entry) (nth 5 ent-entry)))
14186 (when (and limit-hier-inst-no
14187 (> inst-no limit-hier-inst-no))
14188 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
14189 (setq big-files t))
14190 (goto-char end-of-unit))))
14191 ;; remember design units for this file
14192 (vhdl-aput 'file-alist file-name
14193 (list ent-list arch-list arch-ent-list conf-list
14194 pack-list pack-body-list
14195 inst-list inst-ent-list))
14196 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
14197 (setq file-list (cdr file-list))))
14198 (when (or (and (not project) files-exist)
14199 (and project (not non-final)))
14200 ;; consistency checks:
14201 ;; check whether each architecture has a corresponding entity
14202 (setq tmp-list ent-alist)
14203 (while tmp-list
14204 (when (null (nth 2 (car tmp-list)))
14205 (setq tmp-entry (car (nth 4 (car tmp-list))))
14206 (vhdl-warning-when-idle
14207 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14208 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
14209 (nth 3 tmp-entry)))
14210 (setq tmp-list (cdr tmp-list)))
14211 ;; check whether configuration has a corresponding entity/architecture
14212 (setq tmp-list conf-alist)
14213 (while tmp-list
14214 (if (setq tmp-entry (vhdl-aget ent-alist (nth 4 (car tmp-list))))
14215 (unless (vhdl-aget (nth 3 tmp-entry) (nth 5 (car tmp-list)))
14216 (setq tmp-entry (car tmp-list))
14217 (vhdl-warning-when-idle
14218 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14219 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
14220 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14221 (setq tmp-entry (car tmp-list))
14222 (vhdl-warning-when-idle
14223 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14224 (nth 1 tmp-entry) (nth 4 tmp-entry)
14225 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14226 (setq tmp-list (cdr tmp-list)))
14227 ;; check whether each package body has a package declaration
14228 (setq tmp-list pack-alist)
14229 (while tmp-list
14230 (when (null (nth 2 (car tmp-list)))
14231 (setq tmp-entry (car tmp-list))
14232 (vhdl-warning-when-idle
14233 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14234 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
14235 (setq tmp-list (cdr tmp-list)))
14236 ;; sort lists
14237 (setq ent-alist (vhdl-sort-alist ent-alist))
14238 (setq conf-alist (vhdl-sort-alist conf-alist))
14239 (setq pack-alist (vhdl-sort-alist pack-alist))
14240 ;; remember updated directory/project
14241 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
14242 ;; clear directory alists
14243 (unless project
14244 (vhdl-adelete 'vhdl-entity-alist key)
14245 (vhdl-adelete 'vhdl-config-alist key)
14246 (vhdl-adelete 'vhdl-package-alist key)
14247 (vhdl-adelete 'vhdl-ent-inst-alist key)
14248 (vhdl-adelete 'vhdl-file-alist key))
14249 ;; put directory contents into cache
14250 (vhdl-aput 'vhdl-entity-alist key ent-alist)
14251 (vhdl-aput 'vhdl-config-alist key conf-alist)
14252 (vhdl-aput 'vhdl-package-alist key pack-alist)
14253 (vhdl-aput 'vhdl-ent-inst-alist key (list ent-inst-list))
14254 (vhdl-aput 'vhdl-file-alist key file-alist)
14255 ;; final messages
14256 (message "Scanning %s %s\"%s\"...done"
14257 (if is-directory "directory" "files") (or num-string "") name)
14258 (unless project (message "Scanning directory...done"))
14259 (when big-files
14260 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14261 ;; save cache when scanned non-interactively
14262 (when (or (not project) (not non-final))
14263 (when (and noninteractive vhdl-speedbar-save-cache)
14264 (vhdl-save-cache key)))
14267 (defun vhdl-scan-project-contents (project)
14268 "Scan the contents of all VHDL files found in the directories and files
14269 of PROJECT."
14270 (let ((dir-list (or (nth 2 (vhdl-aget vhdl-project-alist project)) '("")))
14271 (default-dir (vhdl-resolve-env-variable
14272 (nth 1 (vhdl-aget vhdl-project-alist project))))
14273 (file-exclude-regexp
14274 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
14275 dir-list-tmp dir dir-name num-dir act-dir recursive)
14276 ;; clear project alists
14277 (vhdl-adelete 'vhdl-entity-alist project)
14278 (vhdl-adelete 'vhdl-config-alist project)
14279 (vhdl-adelete 'vhdl-package-alist project)
14280 (vhdl-adelete 'vhdl-ent-inst-alist project)
14281 (vhdl-adelete 'vhdl-file-alist project)
14282 ;; expand directory names by default-directory
14283 (message "Collecting source files...")
14284 (while dir-list
14285 (setq dir (vhdl-resolve-env-variable (car dir-list)))
14286 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
14287 (setq recursive (match-string 1 dir)
14288 dir-name (match-string 3 dir))
14289 (setq dir-list-tmp
14290 (cons (concat recursive
14291 (if (file-name-absolute-p dir-name) "" default-dir)
14292 dir-name)
14293 dir-list-tmp))
14294 (setq dir-list (cdr dir-list)))
14295 ;; resolve path wildcards
14296 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
14297 ;; expand directories
14298 (while dir-list-tmp
14299 (setq dir (car dir-list-tmp))
14300 ;; get subdirectories
14301 (if (string-match "-r \\(.*[/\\]\\)" dir)
14302 (setq dir-list (append dir-list (vhdl-get-subdirs
14303 (match-string 1 dir))))
14304 (setq dir-list (append dir-list (list dir))))
14305 (setq dir-list-tmp (cdr dir-list-tmp)))
14306 ;; exclude files
14307 (unless (equal file-exclude-regexp "")
14308 (let ((case-fold-search nil))
14309 (while dir-list
14310 (unless (string-match file-exclude-regexp (car dir-list))
14311 (push (car dir-list) dir-list-tmp))
14312 (setq dir-list (cdr dir-list)))
14313 (setq dir-list (nreverse dir-list-tmp))))
14314 (message "Collecting source files...done")
14315 ;; scan for design units for each directory in DIR-LIST
14316 (setq dir-list-tmp nil
14317 num-dir (length dir-list)
14318 act-dir 1)
14319 (while dir-list
14320 (setq dir-name (abbreviate-file-name
14321 (expand-file-name (car dir-list))))
14322 (vhdl-scan-directory-contents dir-name project nil
14323 (format "(%s/%s) " act-dir num-dir)
14324 (cdr dir-list))
14325 (pushnew (file-name-directory dir-name) dir-list-tmp :test #'equal)
14326 (setq dir-list (cdr dir-list)
14327 act-dir (1+ act-dir)))
14328 (vhdl-aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
14329 (message "Scanning project \"%s\"...done" project)))
14331 (defun vhdl-update-file-contents (file-name)
14332 "Update hierarchy information by contents of current buffer."
14333 (setq file-name (abbreviate-file-name file-name))
14334 (let* ((dir-name (file-name-directory file-name))
14335 (directory-alist vhdl-directory-alist)
14336 updated)
14337 (while directory-alist
14338 (when (member dir-name (nth 1 (car directory-alist)))
14339 (let* ((vhdl-project (nth 0 (car directory-alist)))
14340 (project (vhdl-project-p))
14341 (ent-alist (vhdl-aget vhdl-entity-alist
14342 (or project dir-name)))
14343 (conf-alist (vhdl-aget vhdl-config-alist
14344 (or project dir-name)))
14345 (pack-alist (vhdl-aget vhdl-package-alist
14346 (or project dir-name)))
14347 (ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist
14348 (or project dir-name))))
14349 (file-alist (vhdl-aget vhdl-file-alist (or project dir-name)))
14350 (file-entry (vhdl-aget file-alist file-name))
14351 (ent-list (nth 0 file-entry))
14352 (arch-list (nth 1 file-entry))
14353 (arch-ent-list (nth 2 file-entry))
14354 (conf-list (nth 3 file-entry))
14355 (pack-list (nth 4 file-entry))
14356 (pack-body-list (nth 5 file-entry))
14357 (inst-ent-list (nth 7 file-entry))
14358 (cache-key (or project dir-name))
14359 arch-alist key ent-key entry)
14360 ;; delete design units previously contained in this file:
14361 ;; entities
14362 (while ent-list
14363 (setq key (car ent-list)
14364 entry (vhdl-aget ent-alist key))
14365 (when (equal file-name (nth 1 entry))
14366 (if (nth 3 entry)
14367 (vhdl-aput 'ent-alist key
14368 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14369 (vhdl-adelete 'ent-alist key)))
14370 (setq ent-list (cdr ent-list)))
14371 ;; architectures
14372 (while arch-list
14373 (setq key (car arch-list)
14374 ent-key (car arch-ent-list)
14375 entry (vhdl-aget ent-alist ent-key)
14376 arch-alist (nth 3 entry))
14377 (when (equal file-name (nth 1 (vhdl-aget arch-alist key)))
14378 (vhdl-adelete 'arch-alist key)
14379 (if (or (nth 1 entry) arch-alist)
14380 (vhdl-aput 'ent-alist ent-key
14381 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14382 arch-alist (nth 4 entry) (nth 5 entry)))
14383 (vhdl-adelete 'ent-alist ent-key)))
14384 (setq arch-list (cdr arch-list)
14385 arch-ent-list (cdr arch-ent-list)))
14386 ;; configurations
14387 (while conf-list
14388 (setq key (car conf-list))
14389 (when (equal file-name (nth 1 (vhdl-aget conf-alist key)))
14390 (vhdl-adelete 'conf-alist key))
14391 (setq conf-list (cdr conf-list)))
14392 ;; package declarations
14393 (while pack-list
14394 (setq key (car pack-list)
14395 entry (vhdl-aget pack-alist key))
14396 (when (equal file-name (nth 1 entry))
14397 (if (nth 6 entry)
14398 (vhdl-aput 'pack-alist key
14399 (list (nth 0 entry) nil nil nil nil nil
14400 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14401 (nth 9 entry)))
14402 (vhdl-adelete 'pack-alist key)))
14403 (setq pack-list (cdr pack-list)))
14404 ;; package bodies
14405 (while pack-body-list
14406 (setq key (car pack-body-list)
14407 entry (vhdl-aget pack-alist key))
14408 (when (equal file-name (nth 6 entry))
14409 (if (nth 1 entry)
14410 (vhdl-aput 'pack-alist key
14411 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14412 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14413 nil nil nil nil))
14414 (vhdl-adelete 'pack-alist key)))
14415 (setq pack-body-list (cdr pack-body-list)))
14416 ;; instantiated entities
14417 (while inst-ent-list
14418 (setq ent-inst-list
14419 (vhdl-delete (car inst-ent-list) ent-inst-list))
14420 (setq inst-ent-list (cdr inst-ent-list)))
14421 ;; update caches
14422 (vhdl-aput-delete-if-nil 'vhdl-entity-alist cache-key ent-alist)
14423 (vhdl-aput-delete-if-nil 'vhdl-config-alist cache-key conf-alist)
14424 (vhdl-aput-delete-if-nil 'vhdl-package-alist cache-key pack-alist)
14425 (vhdl-aput-delete-if-nil 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14426 ;; scan file
14427 (vhdl-scan-directory-contents file-name project t)
14428 (when (or (and vhdl-speedbar-show-projects project)
14429 (and (not vhdl-speedbar-show-projects) (not project)))
14430 (vhdl-speedbar-refresh project))
14431 (setq updated t)))
14432 (setq directory-alist (cdr directory-alist)))
14433 updated))
14435 (defun vhdl-update-hierarchy ()
14436 "Update directory and hierarchy information in speedbar."
14437 (let ((file-list (reverse vhdl-modified-file-list))
14438 updated)
14439 (when (and vhdl-speedbar-update-on-saving file-list)
14440 (while file-list
14441 (setq updated
14442 (or (vhdl-update-file-contents (car file-list))
14443 updated))
14444 (setq file-list (cdr file-list)))
14445 (setq vhdl-modified-file-list nil)
14446 (vhdl-speedbar-update-current-unit)
14447 (when updated (message "Updating hierarchy...done")))))
14449 ;; structure (parenthesized expression means list of such entries)
14450 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14451 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14452 ;; comp-lib-name level)
14453 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14454 conf-inst-alist level indent
14455 &optional include-top ent-hier)
14456 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14457 entity ENT-KEY."
14458 (let* ((ent-entry (vhdl-aget ent-alist ent-key))
14459 (arch-entry (if arch-key (vhdl-aget (nth 3 ent-entry) arch-key)
14460 (cdar (last (nth 3 ent-entry)))))
14461 (inst-alist (nth 3 arch-entry))
14462 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14463 hier-list subcomp-list tmp-list inst-key inst-comp-name
14464 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14465 (when (= level 0) (message "Extract design hierarchy..."))
14466 (when include-top
14467 (setq level (1+ level)))
14468 (when (member ent-key ent-hier)
14469 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14470 ;; process all instances
14471 (while inst-alist
14472 (setq inst-entry (car inst-alist)
14473 inst-key (nth 0 inst-entry)
14474 inst-comp-name (nth 4 inst-entry)
14475 inst-conf-key (nth 7 inst-entry))
14476 ;; search entry in configuration's instantiations list
14477 (setq tmp-list conf-inst-alist)
14478 (while (and tmp-list
14479 (not (and (member (nth 0 (car tmp-list))
14480 (list "all" inst-key))
14481 (equal (nth 1 (car tmp-list))
14482 (downcase (or inst-comp-name ""))))))
14483 (setq tmp-list (cdr tmp-list)))
14484 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14485 (setq inst-conf-entry (vhdl-aget conf-alist inst-conf-key))
14486 (when (and inst-conf-key (not inst-conf-entry))
14487 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14488 ;; determine entity
14489 (setq inst-ent-key
14490 (or (nth 2 (car tmp-list)) ; from configuration
14491 (nth 3 inst-conf-entry) ; from subconfiguration
14492 (nth 3 (vhdl-aget conf-alist (nth 7 inst-entry)))
14493 ; from configuration spec.
14494 (nth 5 inst-entry))) ; from direct instantiation
14495 (setq inst-ent-entry (vhdl-aget ent-alist inst-ent-key))
14496 ;; determine architecture
14497 (setq inst-arch-key
14498 (or (nth 3 (car tmp-list)) ; from configuration
14499 (nth 4 inst-conf-entry) ; from subconfiguration
14500 (nth 6 inst-entry) ; from direct instantiation
14501 (nth 4 (vhdl-aget conf-alist (nth 7 inst-entry)))
14502 ; from configuration spec.
14503 (nth 4 inst-ent-entry) ; MRA
14504 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14505 (setq inst-arch-entry (vhdl-aget (nth 3 inst-ent-entry) inst-arch-key))
14506 ;; set library
14507 (setq inst-lib-key
14508 (or (nth 5 (car tmp-list)) ; from configuration
14509 (nth 8 inst-entry))) ; from direct instantiation
14510 ;; gather information for this instance
14511 (setq comp-entry
14512 (list (nth 1 inst-entry)
14513 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14514 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14515 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14516 (or (nth 0 inst-arch-entry) inst-arch-key)
14517 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14518 (or (nth 0 inst-conf-entry) inst-conf-key)
14519 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14520 inst-lib-key level))
14521 ;; get subcomponent hierarchy
14522 (setq subcomp-list (vhdl-get-hierarchy
14523 ent-alist conf-alist
14524 inst-ent-key inst-arch-key inst-conf-key
14525 (nth 5 inst-conf-entry)
14526 (1+ level) indent nil (cons ent-key ent-hier)))
14527 ;; add to list
14528 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14529 (setq inst-alist (cdr inst-alist)))
14530 (when include-top
14531 (setq hier-list
14532 (cons (list nil nil (nth 0 ent-entry)
14533 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14534 (nth 0 arch-entry)
14535 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14536 nil nil
14537 nil (1- level))
14538 hier-list)))
14539 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14540 hier-list))
14542 (defun vhdl-get-instantiations (ent-key indent)
14543 "Get all instantiations of entity ENT-KEY."
14544 (let ((ent-alist (vhdl-aget vhdl-entity-alist
14545 (vhdl-speedbar-line-key indent)))
14546 arch-alist inst-alist ent-inst-list
14547 ent-entry arch-entry inst-entry)
14548 (while ent-alist
14549 (setq ent-entry (car ent-alist))
14550 (setq arch-alist (nth 4 ent-entry))
14551 (while arch-alist
14552 (setq arch-entry (car arch-alist))
14553 (setq inst-alist (nth 4 arch-entry))
14554 (while inst-alist
14555 (setq inst-entry (car inst-alist))
14556 (when (equal ent-key (nth 5 inst-entry))
14557 (setq ent-inst-list
14558 (cons (list (nth 1 inst-entry)
14559 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14560 (nth 1 ent-entry)
14561 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14562 (nth 1 arch-entry)
14563 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14564 ent-inst-list)))
14565 (setq inst-alist (cdr inst-alist)))
14566 (setq arch-alist (cdr arch-alist)))
14567 (setq ent-alist (cdr ent-alist)))
14568 (nreverse ent-inst-list)))
14570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14571 ;; Caching in file
14573 (defun vhdl-save-caches ()
14574 "Save all updated hierarchy caches to file."
14575 (interactive)
14576 (condition-case nil
14577 (when vhdl-speedbar-save-cache
14578 ;; update hierarchy
14579 (vhdl-update-hierarchy)
14580 (let ((project-list vhdl-updated-project-list))
14581 (message "Saving hierarchy caches...")
14582 ;; write updated project caches
14583 (while project-list
14584 (vhdl-save-cache (car project-list))
14585 (setq project-list (cdr project-list)))
14586 (message "Saving hierarchy caches...done")))
14587 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14588 (sit-for 2)))))
14590 (defun vhdl-save-cache (key)
14591 "Save current hierarchy cache to file."
14592 (let* ((orig-buffer (current-buffer))
14593 (vhdl-project key)
14594 (project (vhdl-project-p))
14595 (default-directory key)
14596 (directory (abbreviate-file-name (vhdl-default-directory)))
14597 (file-name (vhdl-resolve-env-variable
14598 (vhdl-replace-string
14599 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14600 (concat
14601 (subst-char-in-string ? ?_ (or project "dir"))
14602 " " (user-login-name)))))
14603 (file-dir-name (expand-file-name file-name directory))
14604 (cache-key (or project directory))
14605 (key (if project "project" "directory")))
14606 (unless (file-exists-p (file-name-directory file-dir-name))
14607 (make-directory (file-name-directory file-dir-name) t))
14608 (if (not (file-writable-p file-dir-name))
14609 (progn (vhdl-warning (format "File not writable: \"%s\""
14610 (abbreviate-file-name file-dir-name)))
14611 (sit-for 2))
14612 (message "Saving cache: \"%s\"" file-dir-name)
14613 (set-buffer (find-file-noselect file-dir-name t t))
14614 (erase-buffer)
14615 (insert ";; -*- Emacs-Lisp -*-\n\n"
14616 ";;; " (file-name-nondirectory file-name)
14617 " - design hierarchy cache file for Emacs VHDL Mode "
14618 vhdl-version "\n")
14619 (insert "\n;; " (if project "Project " "Directory") " : ")
14620 (if project (insert project) (prin1 directory (current-buffer)))
14621 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14622 (user-login-name) "\n\n"
14623 "\n;; version number\n"
14624 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14625 "\n;; " (if project "project" "directory") " name"
14626 "\n(setq " key " ")
14627 (prin1 (or project directory) (current-buffer))
14628 (insert ")\n")
14629 (when (member 'hierarchy vhdl-speedbar-save-cache)
14630 (insert "\n;; entity and architecture cache\n"
14631 "(vhdl-aput 'vhdl-entity-alist " key " '")
14632 (print (vhdl-aget vhdl-entity-alist cache-key) (current-buffer))
14633 (insert ")\n\n;; configuration cache\n"
14634 "(vhdl-aput 'vhdl-config-alist " key " '")
14635 (print (vhdl-aget vhdl-config-alist cache-key) (current-buffer))
14636 (insert ")\n\n;; package cache\n"
14637 "(vhdl-aput 'vhdl-package-alist " key " '")
14638 (print (vhdl-aget vhdl-package-alist cache-key) (current-buffer))
14639 (insert ")\n\n;; instantiated entities cache\n"
14640 "(vhdl-aput 'vhdl-ent-inst-alist " key " '")
14641 (print (vhdl-aget vhdl-ent-inst-alist cache-key) (current-buffer))
14642 (insert ")\n\n;; design units per file cache\n"
14643 "(vhdl-aput 'vhdl-file-alist " key " '")
14644 (print (vhdl-aget vhdl-file-alist cache-key) (current-buffer))
14645 (when project
14646 (insert ")\n\n;; source directories in project cache\n"
14647 "(vhdl-aput 'vhdl-directory-alist " key " '")
14648 (print (vhdl-aget vhdl-directory-alist cache-key) (current-buffer)))
14649 (insert ")\n"))
14650 (when (member 'display vhdl-speedbar-save-cache)
14651 (insert "\n;; shown design units cache\n"
14652 "(vhdl-aput 'vhdl-speedbar-shown-unit-alist " key " '")
14653 (print (vhdl-aget vhdl-speedbar-shown-unit-alist cache-key)
14654 (current-buffer))
14655 (insert ")\n"))
14656 (setq vhdl-updated-project-list
14657 (delete cache-key vhdl-updated-project-list))
14658 (save-buffer)
14659 (kill-buffer (current-buffer))
14660 (set-buffer orig-buffer))))
14662 (defun vhdl-load-cache (key)
14663 "Load hierarchy cache information from file."
14664 (let* ((vhdl-project key)
14665 (default-directory key)
14666 (directory (vhdl-default-directory))
14667 (file-name (vhdl-resolve-env-variable
14668 (vhdl-replace-string
14669 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14670 (concat
14671 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14672 " " (user-login-name)))))
14673 (file-dir-name (expand-file-name file-name directory))
14674 vhdl-cache-version)
14675 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14676 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14677 (when (file-exists-p file-dir-name)
14678 (condition-case ()
14679 (progn (load-file file-dir-name)
14680 (string< (mapconcat
14681 (lambda (a) (format "%3d" (string-to-number a)))
14682 (split-string "3.33" "\\.") "")
14683 (mapconcat
14684 (lambda (a) (format "%3d" (string-to-number a)))
14685 (split-string vhdl-cache-version "\\.") "")))
14686 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14687 nil))))))
14689 (defun vhdl-require-hierarchy-info ()
14690 "Make sure that hierarchy information is available. Load cache or scan files
14691 if required."
14692 (if (vhdl-project-p)
14693 (unless (or (assoc vhdl-project vhdl-file-alist)
14694 (vhdl-load-cache vhdl-project))
14695 (vhdl-scan-project-contents vhdl-project))
14696 (let ((directory (abbreviate-file-name default-directory)))
14697 (unless (or (assoc directory vhdl-file-alist)
14698 (vhdl-load-cache directory))
14699 (vhdl-scan-directory-contents directory)))))
14701 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14702 ;; Add hierarchy browser functionality to speedbar
14704 (defvar vhdl-speedbar-mode-map nil
14705 "Keymap used when in the VHDL hierarchy browser mode.")
14707 (defvar vhdl-speedbar-menu-items nil
14708 "Additional menu-items to add to speedbar frame.")
14710 (declare-function speedbar-add-supported-extension "speedbar" (extension))
14711 (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
14712 (declare-function speedbar-make-specialized-keymap "speedbar" ())
14713 (declare-function speedbar-change-initial-expansion-list "speedbar"
14714 (new-default))
14715 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
14717 (defun vhdl-speedbar-initialize ()
14718 "Initialize speedbar."
14719 ;; general settings
14720 ;; VHDL file extensions (extracted from `auto-mode-alist')
14721 (let ((mode-alist auto-mode-alist))
14722 (while mode-alist
14723 (when (eq (cdar mode-alist) 'vhdl-mode)
14724 (speedbar-add-supported-extension (caar mode-alist)))
14725 (setq mode-alist (cdr mode-alist))))
14726 ;; hierarchy browser settings
14727 (when (boundp 'speedbar-mode-functions-list)
14728 ;; special functions
14729 (speedbar-add-mode-functions-list
14730 '("vhdl directory"
14731 (speedbar-item-info . vhdl-speedbar-item-info)
14732 (speedbar-line-directory . speedbar-files-line-path)))
14733 (speedbar-add-mode-functions-list
14734 '("vhdl project"
14735 (speedbar-item-info . vhdl-speedbar-item-info)
14736 (speedbar-line-directory . vhdl-speedbar-line-project)))
14737 ;; keymap
14738 (unless vhdl-speedbar-mode-map
14739 (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
14740 (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
14741 (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
14742 (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
14743 (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
14744 (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
14745 (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
14746 (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
14747 (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
14748 (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
14749 (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
14750 (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
14751 (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
14752 (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
14753 (let ((key 0))
14754 (while (<= key 9)
14755 (define-key vhdl-speedbar-mode-map (int-to-string key)
14756 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14757 (setq key (1+ key)))))
14758 (define-key speedbar-mode-map "h"
14759 (lambda () (interactive)
14760 (speedbar-change-initial-expansion-list "vhdl directory")))
14761 (define-key speedbar-mode-map "H"
14762 (lambda () (interactive)
14763 (speedbar-change-initial-expansion-list "vhdl project")))
14764 ;; menu
14765 (unless vhdl-speedbar-menu-items
14766 (setq
14767 vhdl-speedbar-menu-items
14768 `(["Edit" speedbar-edit-line t]
14769 ["Expand" speedbar-expand-line
14770 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14771 ["Contract" vhdl-speedbar-contract-level t]
14772 ["Expand All" vhdl-speedbar-expand-all t]
14773 ["Contract All" vhdl-speedbar-contract-all t]
14774 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14775 (while (<= key 9)
14776 (setq menu-list
14777 (cons `[,(if (= key 0) "All" (int-to-string key))
14778 (vhdl-speedbar-set-depth ,key)
14779 :style radio
14780 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14781 :keys ,(int-to-string key)]
14782 menu-list))
14783 (setq key (1+ key)))
14784 (nreverse menu-list))
14785 "--"
14786 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14787 (or (vhdl-speedbar-check-unit 'entity)
14788 (vhdl-speedbar-check-unit 'subprogram))]
14789 ["Place Component" vhdl-speedbar-place-component
14790 (vhdl-speedbar-check-unit 'entity)]
14791 ["Generate Configuration" vhdl-speedbar-configuration
14792 (vhdl-speedbar-check-unit 'architecture)]
14793 ["Select as MRA" vhdl-speedbar-select-mra
14794 (vhdl-speedbar-check-unit 'architecture)]
14795 ["Make" vhdl-speedbar-make-design
14796 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14797 ["Generate Makefile" vhdl-speedbar-generate-makefile
14798 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14799 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14800 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14801 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14802 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14803 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14804 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14805 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14806 ;; hook-ups
14807 (speedbar-add-expansion-list
14808 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14809 vhdl-speedbar-display-directory))
14810 (speedbar-add-expansion-list
14811 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14812 vhdl-speedbar-display-projects))
14813 (setq speedbar-stealthy-function-list
14814 (append
14815 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14816 ("vhdl project" vhdl-speedbar-update-current-project
14817 vhdl-speedbar-update-current-unit))
14818 speedbar-stealthy-function-list))
14819 (when (eq vhdl-speedbar-display-mode 'directory)
14820 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14821 (when (eq vhdl-speedbar-display-mode 'project)
14822 (setq speedbar-initial-expansion-list-name "vhdl project"))
14823 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14825 (defun vhdl-speedbar (&optional arg)
14826 "Open/close speedbar."
14827 (interactive)
14828 (if (not (fboundp 'speedbar))
14829 (error "WARNING: Speedbar is not available or not installed")
14830 (condition-case ()
14831 (speedbar-frame-mode arg)
14832 (error (error "WARNING: An error occurred while opening speedbar")))))
14834 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14835 ;; Display functions
14837 (defvar vhdl-speedbar-last-selected-project nil
14838 "Name of last selected project.")
14840 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14841 ;;; (defmacro speedbar-with-writable (&rest forms)
14842 ;;; "Allow the buffer to be writable and evaluate FORMS."
14843 ;;; (list 'let '((inhibit-read-only t))
14844 ;;; (cons 'progn forms)))
14845 ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
14847 (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
14848 (declare-function speedbar-directory-buttons "speedbar" (directory _index))
14849 (declare-function speedbar-file-lists "speedbar" (directory))
14851 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14852 "Display directory and hierarchy information in speedbar."
14853 (setq vhdl-speedbar-show-projects nil)
14854 (setq speedbar-ignored-directory-regexp
14855 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14856 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14857 (setq speedbar-last-selected-file nil)
14858 (speedbar-with-writable
14859 (condition-case nil
14860 (progn
14861 ;; insert directory path
14862 (speedbar-directory-buttons directory depth)
14863 ;; insert subdirectories
14864 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14865 ;; scan and insert hierarchy of current directory
14866 (vhdl-speedbar-insert-dir-hierarchy directory depth
14867 speedbar-power-click)
14868 ;; expand subdirectories
14869 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14870 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14872 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14873 "Display projects and hierarchy information in speedbar."
14874 (setq vhdl-speedbar-show-projects t)
14875 (setq speedbar-ignored-directory-regexp ".")
14876 (setq speedbar-last-selected-file nil)
14877 (setq vhdl-speedbar-last-selected-project nil)
14878 (speedbar-with-writable
14879 (condition-case nil
14880 ;; insert projects
14881 (vhdl-speedbar-insert-projects)
14882 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14883 (setq speedbar-full-text-cache nil)) ; prevent caching
14885 (declare-function speedbar-make-tag-line "speedbar"
14886 (type char func data tag tfunc tdata tface depth))
14888 (defun vhdl-speedbar-insert-projects ()
14889 "Insert all projects in speedbar."
14890 (vhdl-speedbar-make-title-line "Projects:")
14891 (let ((project-alist (if vhdl-project-sort
14892 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14893 vhdl-project-alist))
14894 (vhdl-speedbar-update-current-unit nil))
14895 ;; insert projects
14896 (while project-alist
14897 (speedbar-make-tag-line
14898 'angle ?+ 'vhdl-speedbar-expand-project
14899 (caar project-alist) (caar project-alist)
14900 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14901 (setq project-alist (cdr project-alist)))
14902 (setq project-alist vhdl-project-alist)
14903 ;; expand projects
14904 (while project-alist
14905 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14906 (goto-char (point-min))
14907 (when (re-search-forward
14908 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14909 (goto-char (match-end 1))
14910 (speedbar-do-function-pointer)))
14911 (setq project-alist (cdr project-alist)))))
14913 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14914 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14915 otherwise use cached data."
14916 (when (or rescan (and (not (assoc project vhdl-file-alist))
14917 (not (vhdl-load-cache project))))
14918 (vhdl-scan-project-contents project))
14919 ;; insert design hierarchy
14920 (vhdl-speedbar-insert-hierarchy
14921 (vhdl-aget vhdl-entity-alist project)
14922 (vhdl-aget vhdl-config-alist project)
14923 (vhdl-aget vhdl-package-alist project)
14924 (car (vhdl-aget vhdl-ent-inst-alist project)) indent)
14925 (insert (int-to-string indent) ":\n")
14926 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14927 (put-text-property (1- (point)) (point) 'invisible nil)
14928 ;; expand design units
14929 (vhdl-speedbar-expand-units project))
14931 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14932 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14933 otherwise use cached data."
14934 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14935 (not (vhdl-load-cache directory))))
14936 (vhdl-scan-directory-contents directory))
14937 ;; insert design hierarchy
14938 (vhdl-speedbar-insert-hierarchy
14939 (vhdl-aget vhdl-entity-alist directory)
14940 (vhdl-aget vhdl-config-alist directory)
14941 (vhdl-aget vhdl-package-alist directory)
14942 (car (vhdl-aget vhdl-ent-inst-alist directory)) depth)
14943 ;; expand design units
14944 (vhdl-speedbar-expand-units directory)
14945 (vhdl-aput 'vhdl-directory-alist directory (list (list directory))))
14947 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14948 ent-inst-list depth)
14949 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14950 (if (not (or ent-alist conf-alist pack-alist))
14951 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14952 (let (ent-entry conf-entry pack-entry)
14953 ;; insert entities
14954 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14955 (while ent-alist
14956 (setq ent-entry (car ent-alist))
14957 (speedbar-make-tag-line
14958 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14959 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14960 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14961 'vhdl-speedbar-entity-face depth)
14962 (unless (nth 2 ent-entry)
14963 (end-of-line 0) (insert "!") (forward-char 1))
14964 (unless (member (nth 0 ent-entry) ent-inst-list)
14965 (end-of-line 0) (insert " (top)") (forward-char 1))
14966 (setq ent-alist (cdr ent-alist)))
14967 ;; insert configurations
14968 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14969 (while conf-alist
14970 (setq conf-entry (car conf-alist))
14971 (speedbar-make-tag-line
14972 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14973 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14974 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14975 'vhdl-speedbar-configuration-face depth)
14976 (setq conf-alist (cdr conf-alist)))
14977 ;; insert packages
14978 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14979 (while pack-alist
14980 (setq pack-entry (car pack-alist))
14981 (vhdl-speedbar-make-pack-line
14982 (nth 0 pack-entry) (nth 1 pack-entry)
14983 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14984 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14985 depth)
14986 (setq pack-alist (cdr pack-alist))))))
14988 (declare-function speedbar-line-directory "speedbar" (&optional depth))
14990 (defun vhdl-speedbar-rescan-hierarchy ()
14991 "Rescan hierarchy for the directory or project under the cursor."
14992 (interactive)
14993 (let (key path)
14994 (cond
14995 ;; current project
14996 (vhdl-speedbar-show-projects
14997 (setq key (vhdl-speedbar-line-project))
14998 (vhdl-scan-project-contents key))
14999 ;; top-level directory
15000 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
15001 (re-search-forward "[0-9]+:" nil t)
15002 (vhdl-scan-directory-contents
15003 (abbreviate-file-name (speedbar-line-directory))))
15004 ;; current directory
15005 (t (setq path (speedbar-line-directory))
15006 (string-match "^\\(.+[/\\]\\)" path)
15007 (vhdl-scan-directory-contents
15008 (abbreviate-file-name (match-string 1 path)))))
15009 (vhdl-speedbar-refresh key)))
15011 (declare-function speedbar-goto-this-file "speedbar" (file))
15013 (defun vhdl-speedbar-expand-dirs (directory)
15014 "Expand subdirectories in DIRECTORY according to
15015 `speedbar-shown-directories'."
15016 ;; (nicked from `speedbar-default-directory-list')
15017 (let ((sf (cdr (reverse speedbar-shown-directories)))
15018 (vhdl-speedbar-update-current-unit nil))
15019 (setq speedbar-shown-directories
15020 (list (expand-file-name default-directory)))
15021 (while sf
15022 (when (speedbar-goto-this-file (car sf))
15023 (beginning-of-line)
15024 (when (looking-at "[0-9]+:\\s-*<")
15025 (goto-char (match-end 0))
15026 (speedbar-do-function-pointer)))
15027 (setq sf (cdr sf))))
15028 (vhdl-speedbar-update-current-unit nil t))
15030 (defun vhdl-speedbar-expand-units (key)
15031 "Expand design units in directory/project KEY according to
15032 `vhdl-speedbar-shown-unit-alist'."
15033 (let ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15034 (vhdl-speedbar-update-current-unit nil)
15035 vhdl-updated-project-list)
15036 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15037 (vhdl-prepare-search-1
15038 (while unit-alist ; expand units
15039 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
15040 (beginning-of-line)
15041 (let ((arch-alist (nth 1 (car unit-alist)))
15042 position)
15043 (when (looking-at "^[0-9]+:\\s-*\\[")
15044 (goto-char (match-end 0))
15045 (setq position (point))
15046 (speedbar-do-function-pointer)
15047 (select-frame speedbar-frame)
15048 (while arch-alist ; expand architectures
15049 (goto-char position)
15050 (when (re-search-forward
15051 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
15052 (car arch-alist) "\\>\\)") nil t)
15053 (beginning-of-line)
15054 (when (looking-at "^[0-9]+:\\s-*{")
15055 (goto-char (match-end 0))
15056 (speedbar-do-function-pointer)
15057 (select-frame speedbar-frame)))
15058 (setq arch-alist (cdr arch-alist))))
15059 (setq unit-alist (cdr unit-alist))))))
15060 (vhdl-speedbar-update-current-unit nil t))
15062 (declare-function speedbar-center-buffer-smartly "speedbar" ())
15064 (defun vhdl-speedbar-contract-level ()
15065 "Contract current level in current directory/project."
15066 (interactive)
15067 (when (or (save-excursion
15068 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
15069 (and (save-excursion
15070 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
15071 (re-search-backward
15072 (format "^[0-%d]:\\s-*[[{<]-"
15073 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
15074 (goto-char (match-end 0))
15075 (speedbar-do-function-pointer)
15076 (speedbar-center-buffer-smartly)))
15078 (defun vhdl-speedbar-contract-all ()
15079 "Contract all expanded design units in current directory/project."
15080 (interactive)
15081 (if (and vhdl-speedbar-show-projects
15082 (save-excursion (beginning-of-line) (looking-at "^0:")))
15083 (progn (setq vhdl-speedbar-shown-project-list nil)
15084 (vhdl-speedbar-refresh))
15085 (let ((key (vhdl-speedbar-line-key)))
15086 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15087 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
15088 (when (memq 'display vhdl-speedbar-save-cache)
15089 (add-to-list 'vhdl-updated-project-list key)))))
15091 (defun vhdl-speedbar-expand-all ()
15092 "Expand all design units in current directory/project."
15093 (interactive)
15094 (let* ((key (vhdl-speedbar-line-key))
15095 (ent-alist (vhdl-aget vhdl-entity-alist key))
15096 (conf-alist (vhdl-aget vhdl-config-alist key))
15097 (pack-alist (vhdl-aget vhdl-package-alist key))
15098 arch-alist unit-alist subunit-alist)
15099 (add-to-list 'vhdl-speedbar-shown-project-list key)
15100 (while ent-alist
15101 (setq arch-alist (nth 4 (car ent-alist)))
15102 (setq subunit-alist nil)
15103 (while arch-alist
15104 (push (caar arch-alist) subunit-alist)
15105 (setq arch-alist (cdr arch-alist)))
15106 (push (list (caar ent-alist) subunit-alist) unit-alist)
15107 (setq ent-alist (cdr ent-alist)))
15108 (while conf-alist
15109 (push (list (caar conf-alist)) unit-alist)
15110 (setq conf-alist (cdr conf-alist)))
15111 (while pack-alist
15112 (push (list (caar pack-alist)) unit-alist)
15113 (setq pack-alist (cdr pack-alist)))
15114 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15115 (vhdl-speedbar-refresh)
15116 (when (memq 'display vhdl-speedbar-save-cache)
15117 (add-to-list 'vhdl-updated-project-list key))))
15119 (declare-function speedbar-change-expand-button-char "speedbar" (char))
15120 (declare-function speedbar-delete-subblock "speedbar" (indent))
15122 (defun vhdl-speedbar-expand-project (text token indent)
15123 "Expand/contract the project under the cursor."
15124 (cond
15125 ((string-match "+" text) ; expand project
15126 (speedbar-change-expand-button-char ?-)
15127 (unless (member token vhdl-speedbar-shown-project-list)
15128 (setq vhdl-speedbar-shown-project-list
15129 (cons token vhdl-speedbar-shown-project-list)))
15130 (speedbar-with-writable
15131 (save-excursion
15132 (end-of-line) (forward-char 1)
15133 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
15134 speedbar-power-click))))
15135 ((string-match "-" text) ; contract project
15136 (speedbar-change-expand-button-char ?+)
15137 (setq vhdl-speedbar-shown-project-list
15138 (delete token vhdl-speedbar-shown-project-list))
15139 (speedbar-delete-subblock indent))
15140 (t (error "Nothing to display")))
15141 (when (equal (selected-frame) speedbar-frame)
15142 (speedbar-center-buffer-smartly)))
15144 (defun vhdl-speedbar-expand-entity (text token indent)
15145 "Expand/contract the entity under the cursor."
15146 (cond
15147 ((string-match "+" text) ; expand entity
15148 (let* ((key (vhdl-speedbar-line-key indent))
15149 (ent-alist (vhdl-aget vhdl-entity-alist key))
15150 (ent-entry (vhdl-aget ent-alist token))
15151 (arch-alist (nth 3 ent-entry))
15152 (inst-alist (vhdl-get-instantiations token indent))
15153 (subpack-alist (nth 5 ent-entry))
15154 (multiple-arch (> (length arch-alist) 1))
15155 arch-entry inst-entry)
15156 (if (not (or arch-alist inst-alist subpack-alist))
15157 (speedbar-change-expand-button-char ??)
15158 (speedbar-change-expand-button-char ?-)
15159 ;; add entity to `vhdl-speedbar-shown-unit-alist'
15160 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15161 (vhdl-aput 'unit-alist token nil)
15162 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15163 (speedbar-with-writable
15164 (save-excursion
15165 (end-of-line) (forward-char 1)
15166 ;; insert architectures
15167 (when arch-alist
15168 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
15169 (while arch-alist
15170 (setq arch-entry (car arch-alist))
15171 (speedbar-make-tag-line
15172 'curly ?+ 'vhdl-speedbar-expand-architecture
15173 (cons token (nth 0 arch-entry))
15174 (nth 1 arch-entry) 'vhdl-speedbar-find-file
15175 (cons (nth 2 arch-entry) (nth 3 arch-entry))
15176 'vhdl-speedbar-architecture-face (1+ indent))
15177 (when (and multiple-arch
15178 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
15179 (end-of-line 0) (insert " (mra)") (forward-char 1))
15180 (setq arch-alist (cdr arch-alist)))
15181 ;; insert instantiations
15182 (when inst-alist
15183 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
15184 (while inst-alist
15185 (setq inst-entry (car inst-alist))
15186 (vhdl-speedbar-make-inst-line
15187 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
15188 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
15189 nil nil nil (1+ indent) 0 " in ")
15190 (setq inst-alist (cdr inst-alist)))
15191 ;; insert required packages
15192 (vhdl-speedbar-insert-subpackages
15193 subpack-alist (1+ indent) indent)))
15194 (when (memq 'display vhdl-speedbar-save-cache)
15195 (add-to-list 'vhdl-updated-project-list key))
15196 (vhdl-speedbar-update-current-unit t t))))
15197 ((string-match "-" text) ; contract entity
15198 (speedbar-change-expand-button-char ?+)
15199 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
15200 (let* ((key (vhdl-speedbar-line-key indent))
15201 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15202 (vhdl-adelete 'unit-alist token)
15203 (if unit-alist
15204 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15205 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15206 (speedbar-delete-subblock indent)
15207 (when (memq 'display vhdl-speedbar-save-cache)
15208 (add-to-list 'vhdl-updated-project-list key))))
15209 (t (error "Nothing to display")))
15210 (when (equal (selected-frame) speedbar-frame)
15211 (speedbar-center-buffer-smartly)))
15213 (defun vhdl-speedbar-expand-architecture (text token indent)
15214 "Expand/contract the architecture under the cursor."
15215 (cond
15216 ((string-match "+" text) ; expand architecture
15217 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15218 (ent-alist (vhdl-aget vhdl-entity-alist key))
15219 (conf-alist (vhdl-aget vhdl-config-alist key))
15220 (hier-alist (vhdl-get-hierarchy
15221 ent-alist conf-alist (car token) (cdr token) nil nil
15222 0 (1- indent)))
15223 (ent-entry (vhdl-aget ent-alist (car token)))
15224 (arch-entry (vhdl-aget (nth 3 ent-entry) (cdr token)))
15225 (subpack-alist (nth 4 arch-entry))
15226 entry)
15227 (if (not (or hier-alist subpack-alist))
15228 (speedbar-change-expand-button-char ??)
15229 (speedbar-change-expand-button-char ?-)
15230 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15231 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15232 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15233 (vhdl-aput 'unit-alist (car token)
15234 (list (cons (cdr token) arch-alist)))
15235 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15236 (speedbar-with-writable
15237 (save-excursion
15238 (end-of-line) (forward-char 1)
15239 ;; insert instance hierarchy
15240 (when hier-alist
15241 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15242 (1+ indent)))
15243 (while hier-alist
15244 (setq entry (car hier-alist))
15245 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15246 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15247 (vhdl-speedbar-make-inst-line
15248 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15249 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15250 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
15251 (setq hier-alist (cdr hier-alist)))
15252 ;; insert required packages
15253 (vhdl-speedbar-insert-subpackages
15254 subpack-alist (1+ indent) (1- indent))))
15255 (when (memq 'display vhdl-speedbar-save-cache)
15256 (add-to-list 'vhdl-updated-project-list key))
15257 (vhdl-speedbar-update-current-unit t t))))
15258 ((string-match "-" text) ; contract architecture
15259 (speedbar-change-expand-button-char ?+)
15260 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15261 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15262 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15263 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15264 (vhdl-aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
15265 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15266 (speedbar-delete-subblock indent)
15267 (when (memq 'display vhdl-speedbar-save-cache)
15268 (add-to-list 'vhdl-updated-project-list key))))
15269 (t (error "Nothing to display")))
15270 (when (equal (selected-frame) speedbar-frame)
15271 (speedbar-center-buffer-smartly)))
15273 (defun vhdl-speedbar-expand-config (text token indent)
15274 "Expand/contract the configuration under the cursor."
15275 (cond
15276 ((string-match "+" text) ; expand configuration
15277 (let* ((key (vhdl-speedbar-line-key indent))
15278 (conf-alist (vhdl-aget vhdl-config-alist key))
15279 (conf-entry (vhdl-aget conf-alist token))
15280 (ent-alist (vhdl-aget vhdl-entity-alist key))
15281 (hier-alist (vhdl-get-hierarchy
15282 ent-alist conf-alist (nth 3 conf-entry)
15283 (nth 4 conf-entry) token (nth 5 conf-entry)
15284 0 indent t))
15285 (subpack-alist (nth 6 conf-entry))
15286 entry)
15287 (if (not (or hier-alist subpack-alist))
15288 (speedbar-change-expand-button-char ??)
15289 (speedbar-change-expand-button-char ?-)
15290 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15291 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15292 (vhdl-aput 'unit-alist token nil)
15293 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15294 (speedbar-with-writable
15295 (save-excursion
15296 (end-of-line) (forward-char 1)
15297 ;; insert instance hierarchy
15298 (when hier-alist
15299 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
15300 (while hier-alist
15301 (setq entry (car hier-alist))
15302 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15303 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15304 (vhdl-speedbar-make-inst-line
15305 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15306 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15307 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
15308 (setq hier-alist (cdr hier-alist)))
15309 ;; insert required packages
15310 (vhdl-speedbar-insert-subpackages
15311 subpack-alist (1+ indent) indent)))
15312 (when (memq 'display vhdl-speedbar-save-cache)
15313 (add-to-list 'vhdl-updated-project-list key))
15314 (vhdl-speedbar-update-current-unit t t))))
15315 ((string-match "-" text) ; contract configuration
15316 (speedbar-change-expand-button-char ?+)
15317 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15318 (let* ((key (vhdl-speedbar-line-key indent))
15319 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15320 (vhdl-adelete 'unit-alist token)
15321 (if unit-alist
15322 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15323 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15324 (speedbar-delete-subblock indent)
15325 (when (memq 'display vhdl-speedbar-save-cache)
15326 (add-to-list 'vhdl-updated-project-list key))))
15327 (t (error "Nothing to display")))
15328 (when (equal (selected-frame) speedbar-frame)
15329 (speedbar-center-buffer-smartly)))
15331 (defun vhdl-speedbar-expand-package (text token indent)
15332 "Expand/contract the package under the cursor."
15333 (cond
15334 ((string-match "+" text) ; expand package
15335 (let* ((key (vhdl-speedbar-line-key indent))
15336 (pack-alist (vhdl-aget vhdl-package-alist key))
15337 (pack-entry (vhdl-aget pack-alist token))
15338 (comp-alist (nth 3 pack-entry))
15339 (func-alist (nth 4 pack-entry))
15340 (func-body-alist (nth 8 pack-entry))
15341 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
15342 comp-entry func-entry func-body-entry)
15343 (if (not (or comp-alist func-alist subpack-alist))
15344 (speedbar-change-expand-button-char ??)
15345 (speedbar-change-expand-button-char ?-)
15346 ;; add package to `vhdl-speedbar-shown-unit-alist'
15347 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15348 (vhdl-aput 'unit-alist token nil)
15349 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15350 (speedbar-with-writable
15351 (save-excursion
15352 (end-of-line) (forward-char 1)
15353 ;; insert components
15354 (when comp-alist
15355 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
15356 (while comp-alist
15357 (setq comp-entry (car comp-alist))
15358 (speedbar-make-tag-line
15359 nil nil nil
15360 (cons token (nth 0 comp-entry))
15361 (nth 1 comp-entry) 'vhdl-speedbar-find-file
15362 (cons (nth 2 comp-entry) (nth 3 comp-entry))
15363 'vhdl-speedbar-entity-face (1+ indent))
15364 (setq comp-alist (cdr comp-alist)))
15365 ;; insert subprograms
15366 (when func-alist
15367 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
15368 (while func-alist
15369 (setq func-entry (car func-alist)
15370 func-body-entry (vhdl-aget func-body-alist
15371 (car func-entry)))
15372 (when (nth 2 func-entry)
15373 (vhdl-speedbar-make-subprogram-line
15374 (nth 1 func-entry)
15375 (cons (nth 2 func-entry) (nth 3 func-entry))
15376 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
15377 (1+ indent)))
15378 (setq func-alist (cdr func-alist)))
15379 ;; insert required packages
15380 (vhdl-speedbar-insert-subpackages
15381 subpack-alist (1+ indent) indent)))
15382 (when (memq 'display vhdl-speedbar-save-cache)
15383 (add-to-list 'vhdl-updated-project-list key))
15384 (vhdl-speedbar-update-current-unit t t))))
15385 ((string-match "-" text) ; contract package
15386 (speedbar-change-expand-button-char ?+)
15387 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15388 (let* ((key (vhdl-speedbar-line-key indent))
15389 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15390 (vhdl-adelete 'unit-alist token)
15391 (if unit-alist
15392 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15393 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15394 (speedbar-delete-subblock indent)
15395 (when (memq 'display vhdl-speedbar-save-cache)
15396 (add-to-list 'vhdl-updated-project-list key))))
15397 (t (error "Nothing to display")))
15398 (when (equal (selected-frame) speedbar-frame)
15399 (speedbar-center-buffer-smartly)))
15401 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15402 "Insert required packages."
15403 (let* ((pack-alist (vhdl-aget vhdl-package-alist
15404 (vhdl-speedbar-line-key dir-indent)))
15405 pack-key lib-name pack-entry)
15406 (when subpack-alist
15407 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15408 (while subpack-alist
15409 (setq pack-key (cdar subpack-alist)
15410 lib-name (caar subpack-alist))
15411 (setq pack-entry (vhdl-aget pack-alist pack-key))
15412 (vhdl-speedbar-make-subpack-line
15413 (or (nth 0 pack-entry) pack-key) lib-name
15414 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15415 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15416 (setq subpack-alist (cdr subpack-alist)))))
15418 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15419 ;; Display help functions
15421 (defvar vhdl-speedbar-update-current-unit t
15422 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15424 (defun vhdl-speedbar-update-current-project ()
15425 "Highlight project that is currently active."
15426 (when (and vhdl-speedbar-show-projects
15427 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15428 (and (boundp 'speedbar-frame)
15429 (frame-live-p speedbar-frame)))
15430 (let ((last-frame (selected-frame))
15431 (project-alist vhdl-project-alist)
15432 pos)
15433 (select-frame speedbar-frame)
15434 (speedbar-with-writable
15435 (save-excursion
15436 (while project-alist
15437 (goto-char (point-min))
15438 (when (re-search-forward
15439 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15440 (put-text-property (match-beginning 1) (match-end 1) 'face
15441 (if (equal (caar project-alist) vhdl-project)
15442 'speedbar-selected-face
15443 'speedbar-directory-face))
15444 (when (equal (caar project-alist) vhdl-project)
15445 (setq pos (1- (match-beginning 1)))))
15446 (setq project-alist (cdr project-alist))))
15447 (when pos (goto-char pos)))
15448 (select-frame last-frame)
15449 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15452 (declare-function speedbar-position-cursor-on-line "speedbar" ())
15454 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15455 "Highlight all design units that are contained in the current file.
15456 NO-POSITION non-nil means do not re-position cursor."
15457 (let ((last-frame (selected-frame))
15458 (project-list vhdl-speedbar-shown-project-list)
15459 file-alist pos file-name)
15460 ;; get current file name
15461 (if (fboundp 'speedbar-select-attached-frame)
15462 (speedbar-select-attached-frame)
15463 (select-frame speedbar-attached-frame))
15464 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15465 (when (and vhdl-speedbar-update-current-unit
15466 (or always (not (equal file-name speedbar-last-selected-file))))
15467 (if vhdl-speedbar-show-projects
15468 (while project-list
15469 (setq file-alist (append file-alist
15470 (vhdl-aget vhdl-file-alist
15471 (car project-list))))
15472 (setq project-list (cdr project-list)))
15473 (setq file-alist
15474 (vhdl-aget vhdl-file-alist
15475 (abbreviate-file-name default-directory))))
15476 (select-frame speedbar-frame)
15477 (set-buffer speedbar-buffer)
15478 (speedbar-with-writable
15479 (vhdl-prepare-search-1
15480 (save-excursion
15481 ;; unhighlight last units
15482 (let* ((file-entry (vhdl-aget file-alist
15483 speedbar-last-selected-file)))
15484 (vhdl-speedbar-update-units
15485 "\\[.] " (nth 0 file-entry)
15486 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15487 (vhdl-speedbar-update-units
15488 "{.} " (nth 1 file-entry)
15489 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15490 (vhdl-speedbar-update-units
15491 "\\[.] " (nth 3 file-entry)
15492 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15493 (vhdl-speedbar-update-units
15494 "[]>] " (nth 4 file-entry)
15495 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15496 (vhdl-speedbar-update-units
15497 "\\[.].+(" '("body")
15498 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15499 (vhdl-speedbar-update-units
15500 "> " (nth 6 file-entry)
15501 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15502 ;; highlight current units
15503 (let* ((file-entry (vhdl-aget file-alist file-name)))
15504 (setq
15505 pos (vhdl-speedbar-update-units
15506 "\\[.] " (nth 0 file-entry)
15507 file-name 'vhdl-speedbar-entity-selected-face pos)
15508 pos (vhdl-speedbar-update-units
15509 "{.} " (nth 1 file-entry)
15510 file-name 'vhdl-speedbar-architecture-selected-face pos)
15511 pos (vhdl-speedbar-update-units
15512 "\\[.] " (nth 3 file-entry)
15513 file-name 'vhdl-speedbar-configuration-selected-face pos)
15514 pos (vhdl-speedbar-update-units
15515 "[]>] " (nth 4 file-entry)
15516 file-name 'vhdl-speedbar-package-selected-face pos)
15517 pos (vhdl-speedbar-update-units
15518 "\\[.].+(" '("body")
15519 file-name 'vhdl-speedbar-package-selected-face pos)
15520 pos (vhdl-speedbar-update-units
15521 "> " (nth 6 file-entry)
15522 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15523 ;; move speedbar so the first highlighted unit is visible
15524 (when (and pos (not no-position))
15525 (goto-char pos)
15526 (speedbar-center-buffer-smartly)
15527 (speedbar-position-cursor-on-line))
15528 (setq speedbar-last-selected-file file-name))
15529 (select-frame last-frame)
15532 (defun vhdl-speedbar-update-units (text unit-list file-name face
15533 &optional pos)
15534 "Help function to highlight design units."
15535 (while unit-list
15536 (goto-char (point-min))
15537 (while (re-search-forward
15538 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15539 (when (equal file-name (car (get-text-property
15540 (match-beginning 1) 'speedbar-token)))
15541 (setq pos (or pos (point-marker)))
15542 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15543 (setq unit-list (cdr unit-list)))
15544 pos)
15546 (declare-function speedbar-make-button "speedbar"
15547 (start end face mouse function &optional token))
15549 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15550 ent-name ent-file-marker
15551 arch-name arch-file-marker
15552 conf-name conf-file-marker
15553 lib-name depth offset delimiter)
15554 "Insert instantiation entry."
15555 (let ((start (point))
15556 visible-start)
15557 (insert (int-to-string depth) ":")
15558 (put-text-property start (point) 'invisible t)
15559 (setq visible-start (point))
15560 (insert-char ? (* depth speedbar-indentation-width))
15561 (while (> offset 0)
15562 (insert "|")
15563 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15564 (setq offset (1- offset)))
15565 (put-text-property visible-start (point) 'invisible nil)
15566 (setq start (point))
15567 (insert ">")
15568 (speedbar-make-button start (point) nil nil nil)
15569 (setq visible-start (point))
15570 (insert " ")
15571 (setq start (point))
15572 (if (not inst-name)
15573 (insert "(top)")
15574 (insert inst-name)
15575 (speedbar-make-button
15576 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15577 'vhdl-speedbar-find-file inst-file-marker))
15578 (insert delimiter)
15579 (when ent-name
15580 (setq start (point))
15581 (insert ent-name)
15582 (speedbar-make-button
15583 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15584 'vhdl-speedbar-find-file ent-file-marker)
15585 (when arch-name
15586 (insert " (")
15587 (setq start (point))
15588 (insert arch-name)
15589 (speedbar-make-button
15590 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15591 'vhdl-speedbar-find-file arch-file-marker)
15592 (insert ")"))
15593 (when conf-name
15594 (insert " (")
15595 (setq start (point))
15596 (insert conf-name)
15597 (speedbar-make-button
15598 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15599 'vhdl-speedbar-find-file conf-file-marker)
15600 (insert ")")))
15601 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15602 (setq start (point))
15603 (insert " (" lib-name ")")
15604 (put-text-property (+ 2 start) (1- (point)) 'face
15605 'vhdl-speedbar-library-face))
15606 (insert-char ?\n 1)
15607 (put-text-property visible-start (point) 'invisible nil)))
15609 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15610 body-file-marker depth)
15611 "Insert package entry."
15612 (let ((start (point))
15613 visible-start)
15614 (insert (int-to-string depth) ":")
15615 (put-text-property start (point) 'invisible t)
15616 (setq visible-start (point))
15617 (insert-char ? (* depth speedbar-indentation-width))
15618 (put-text-property visible-start (point) 'invisible nil)
15619 (setq start (point))
15620 (insert "[+]")
15621 (speedbar-make-button
15622 start (point) 'speedbar-button-face 'speedbar-highlight-face
15623 'vhdl-speedbar-expand-package pack-key)
15624 (setq visible-start (point))
15625 (insert-char ? 1 nil)
15626 (setq start (point))
15627 (insert pack-name)
15628 (speedbar-make-button
15629 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15630 'vhdl-speedbar-find-file pack-file-marker)
15631 (unless (car pack-file-marker)
15632 (insert "!"))
15633 (when (car body-file-marker)
15634 (insert " (")
15635 (setq start (point))
15636 (insert "body")
15637 (speedbar-make-button
15638 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15639 'vhdl-speedbar-find-file body-file-marker)
15640 (insert ")"))
15641 (insert-char ?\n 1)
15642 (put-text-property visible-start (point) 'invisible nil)))
15644 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15645 pack-body-file-marker depth)
15646 "Insert used package entry."
15647 (let ((start (point))
15648 visible-start)
15649 (insert (int-to-string depth) ":")
15650 (put-text-property start (point) 'invisible t)
15651 (setq visible-start (point))
15652 (insert-char ? (* depth speedbar-indentation-width))
15653 (put-text-property visible-start (point) 'invisible nil)
15654 (setq start (point))
15655 (insert ">")
15656 (speedbar-make-button start (point) nil nil nil)
15657 (setq visible-start (point))
15658 (insert " ")
15659 (setq start (point))
15660 (insert pack-name)
15661 (speedbar-make-button
15662 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15663 'vhdl-speedbar-find-file pack-file-marker)
15664 (when (car pack-body-file-marker)
15665 (insert " (")
15666 (setq start (point))
15667 (insert "body")
15668 (speedbar-make-button
15669 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15670 'vhdl-speedbar-find-file pack-body-file-marker)
15671 (insert ")"))
15672 (setq start (point))
15673 (insert " (" lib-name ")")
15674 (put-text-property (+ 2 start) (1- (point)) 'face
15675 'vhdl-speedbar-library-face)
15676 (insert-char ?\n 1)
15677 (put-text-property visible-start (point) 'invisible nil)))
15679 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15680 func-body-file-marker
15681 depth)
15682 "Insert subprogram entry."
15683 (let ((start (point))
15684 visible-start)
15685 (insert (int-to-string depth) ":")
15686 (put-text-property start (point) 'invisible t)
15687 (setq visible-start (point))
15688 (insert-char ? (* depth speedbar-indentation-width))
15689 (put-text-property visible-start (point) 'invisible nil)
15690 (setq start (point))
15691 (insert ">")
15692 (speedbar-make-button start (point) nil nil nil)
15693 (setq visible-start (point))
15694 (insert " ")
15695 (setq start (point))
15696 (insert func-name)
15697 (speedbar-make-button
15698 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15699 'vhdl-speedbar-find-file func-file-marker)
15700 (when (car func-body-file-marker)
15701 (insert " (")
15702 (setq start (point))
15703 (insert "body")
15704 (speedbar-make-button
15705 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15706 'vhdl-speedbar-find-file func-body-file-marker)
15707 (insert ")"))
15708 (insert-char ?\n 1)
15709 (put-text-property visible-start (point) 'invisible nil)))
15711 (defun vhdl-speedbar-make-title-line (text &optional depth)
15712 "Insert design unit title entry."
15713 (let ((start (point))
15714 visible-start)
15715 (when depth
15716 (insert (int-to-string depth) ":")
15717 (put-text-property start (point) 'invisible t))
15718 (setq visible-start (point))
15719 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15720 (setq start (point))
15721 (insert text)
15722 (speedbar-make-button start (point) nil nil nil nil)
15723 (insert-char ?\n 1)
15724 (put-text-property visible-start (point) 'invisible nil)))
15726 (defun vhdl-speedbar-insert-dirs (files level)
15727 "Insert subdirectories."
15728 (let ((dirs (car files)))
15729 (while dirs
15730 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15731 (car dirs) 'speedbar-dir-follow nil
15732 'speedbar-directory-face level)
15733 (setq dirs (cdr dirs)))))
15735 (declare-function speedbar-reset-scanners "speedbar" ())
15737 (defun vhdl-speedbar-dired (text token indent)
15738 "Speedbar click handler for directory expand button in hierarchy mode."
15739 (cond ((string-match "+" text) ; we have to expand this dir
15740 (setq speedbar-shown-directories
15741 (cons (expand-file-name
15742 (concat (speedbar-line-directory indent) token "/"))
15743 speedbar-shown-directories))
15744 (speedbar-change-expand-button-char ?-)
15745 (speedbar-reset-scanners)
15746 (speedbar-with-writable
15747 (save-excursion
15748 (end-of-line) (forward-char 1)
15749 (vhdl-speedbar-insert-dirs
15750 (speedbar-file-lists
15751 (concat (speedbar-line-directory indent) token "/"))
15752 (1+ indent))
15753 (speedbar-reset-scanners)
15754 (vhdl-speedbar-insert-dir-hierarchy
15755 (abbreviate-file-name
15756 (concat (speedbar-line-directory indent) token "/"))
15757 (1+ indent) speedbar-power-click)))
15758 (vhdl-speedbar-update-current-unit t t))
15759 ((string-match "-" text) ; we have to contract this node
15760 (speedbar-reset-scanners)
15761 (let ((oldl speedbar-shown-directories)
15762 (newl nil)
15763 (td (expand-file-name
15764 (concat (speedbar-line-directory indent) token))))
15765 (while oldl
15766 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15767 (push (car oldl) newl))
15768 (setq oldl (cdr oldl)))
15769 (setq speedbar-shown-directories (nreverse newl)))
15770 (speedbar-change-expand-button-char ?+)
15771 (speedbar-delete-subblock indent))
15772 (t (error "Nothing to display")))
15773 (when (equal (selected-frame) speedbar-frame)
15774 (speedbar-center-buffer-smartly)))
15776 (declare-function speedbar-files-item-info "speedbar" ())
15778 (defun vhdl-speedbar-item-info ()
15779 "Derive and display information about this line item."
15780 (save-excursion
15781 (beginning-of-line)
15782 ;; skip invisible number info
15783 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15784 (cond
15785 ;; project/directory entry
15786 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15787 (if vhdl-speedbar-show-projects
15788 (message "Project \"%s\"" (match-string-no-properties 1))
15789 (speedbar-files-item-info)))
15790 ;; design unit entry
15791 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15792 (goto-char (match-end 1))
15793 (let ((face (get-text-property (point) 'face)))
15794 (message
15795 "%s \"%s\" in \"%s\""
15796 ;; design unit kind
15797 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15798 (eq face 'vhdl-speedbar-entity-selected-face))
15799 (if (equal (match-string 2) ">") "Component" "Entity"))
15800 ((or (eq face 'vhdl-speedbar-architecture-face)
15801 (eq face 'vhdl-speedbar-architecture-selected-face))
15802 "Architecture")
15803 ((or (eq face 'vhdl-speedbar-configuration-face)
15804 (eq face 'vhdl-speedbar-configuration-selected-face))
15805 "Configuration")
15806 ((or (eq face 'vhdl-speedbar-package-face)
15807 (eq face 'vhdl-speedbar-package-selected-face))
15808 "Package")
15809 ((or (eq face 'vhdl-speedbar-instantiation-face)
15810 (eq face 'vhdl-speedbar-instantiation-selected-face))
15811 "Instantiation")
15812 ((eq face 'vhdl-speedbar-subprogram-face)
15813 "Subprogram")
15814 (t ""))
15815 ;; design unit name
15816 (buffer-substring-no-properties
15817 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15818 (match-end 1))
15819 ;; file name
15820 (file-relative-name
15821 (or (car (get-text-property (point) 'speedbar-token))
15822 "?")
15823 (vhdl-default-directory)))))
15824 (t (message "")))))
15826 (declare-function speedbar-line-text "speedbar" (&optional p))
15828 (defun vhdl-speedbar-line-text ()
15829 "Calls `speedbar-line-text' and removes text properties."
15830 (let ((string (speedbar-line-text)))
15831 (set-text-properties 0 (length string) nil string)
15832 string))
15834 (defun vhdl-speedbar-higher-text ()
15835 "Get speedbar-line-text of higher level."
15836 (let (depth string)
15837 (save-excursion
15838 (beginning-of-line)
15839 (looking-at "^\\([0-9]+\\):")
15840 (setq depth (string-to-number (match-string 1)))
15841 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15842 (setq string (match-string 1))
15843 (set-text-properties 0 (length string) nil string)
15844 string))))
15846 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15847 ;; Help functions
15849 (defun vhdl-speedbar-line-key (&optional indent)
15850 "Get currently displayed directory of project name."
15851 (if vhdl-speedbar-show-projects
15852 (vhdl-speedbar-line-project)
15853 (abbreviate-file-name
15854 (file-name-as-directory (speedbar-line-directory indent)))))
15856 (defun vhdl-speedbar-line-project (&optional indent)
15857 "Get currently displayed project name."
15858 (and vhdl-speedbar-show-projects
15859 (save-excursion
15860 (end-of-line)
15861 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15862 (match-string-no-properties 1))))
15864 (defun vhdl-add-modified-file ()
15865 "Add file to `vhdl-modified-file-list'."
15866 (when vhdl-file-alist
15867 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15868 nil)
15870 (defun vhdl-resolve-paths (path-list)
15871 "Resolve path wildcards in PATH-LIST."
15872 (let (path-list-1 path-list-2 path-beg path-end dir)
15873 ;; eliminate non-existent directories
15874 (while path-list
15875 (setq dir (car path-list))
15876 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15877 (if (file-directory-p (match-string 2 dir))
15878 (push dir path-list-1)
15879 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15880 (setq path-list (cdr path-list)))
15881 ;; resolve path wildcards
15882 (while path-list-1
15883 (setq dir (car path-list-1))
15884 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15885 (progn
15886 (setq path-beg (match-string 1 dir)
15887 path-end (match-string 5 dir))
15888 (setq path-list-1
15889 (append
15890 (mapcar
15891 (function
15892 (lambda (var) (concat path-beg var path-end)))
15893 (let ((all-list (vhdl-directory-files
15894 (match-string 2 dir) t
15895 (concat "\\<" (wildcard-to-regexp
15896 (match-string 4 dir)))))
15897 dir-list)
15898 (while all-list
15899 (when (file-directory-p (car all-list))
15900 (push (car all-list) dir-list))
15901 (setq all-list (cdr all-list)))
15902 dir-list))
15903 (cdr path-list-1))))
15904 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15905 (when (file-directory-p (match-string 2 dir))
15906 (push dir path-list-2))
15907 (setq path-list-1 (cdr path-list-1))))
15908 (nreverse path-list-2)))
15910 (defun vhdl-speedbar-goto-this-unit (directory unit)
15911 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15912 (let ((dest (point)))
15913 (if (and (if vhdl-speedbar-show-projects
15914 (progn (goto-char (point-min)) t)
15915 (speedbar-goto-this-file directory))
15916 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15917 (progn (speedbar-position-cursor-on-line)
15919 (goto-char dest)
15920 nil)))
15922 (declare-function speedbar-find-file-in-frame "speedbar" (file))
15923 (declare-function speedbar-set-timer "speedbar" (timeout))
15924 ;; speedbar loads dframe at runtime.
15925 (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
15927 (defun vhdl-speedbar-find-file (text token indent)
15928 "When user clicks on TEXT, load file with name and position in TOKEN.
15929 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15930 is already shown in a buffer."
15931 (if (not (car token))
15932 (error "ERROR: File cannot be found")
15933 (let ((buffer (get-file-buffer (car token))))
15934 (speedbar-find-file-in-frame (car token))
15935 (when (or vhdl-speedbar-jump-to-unit buffer)
15936 (goto-char (point-min))
15937 (forward-line (1- (cdr token)))
15938 (recenter))
15939 (vhdl-speedbar-update-current-unit t t)
15940 (speedbar-set-timer dframe-update-speed)
15941 (dframe-maybee-jump-to-attached-frame))))
15943 (defun vhdl-speedbar-port-copy ()
15944 "Copy the port of the entity/component or subprogram under the cursor."
15945 (interactive)
15946 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15947 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15948 (error "ERROR: No entity/component or subprogram under cursor")
15949 (beginning-of-line)
15950 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15951 (condition-case info
15952 (let ((token (get-text-property
15953 (match-beginning 3) 'speedbar-token)))
15954 (vhdl-visit-file (car token) t
15955 (progn (goto-char (point-min))
15956 (forward-line (1- (cdr token)))
15957 (end-of-line)
15958 (if is-entity
15959 (vhdl-port-copy)
15960 (vhdl-subprog-copy)))))
15961 (error (error "ERROR: %s not scanned successfully\n (%s)"
15962 (if is-entity "Port" "Interface") (cadr info))))
15963 (error "ERROR: No entity/component or subprogram on current line")))))
15965 (defun vhdl-speedbar-place-component ()
15966 "Place the entity/component under the cursor as component."
15967 (interactive)
15968 (if (not (vhdl-speedbar-check-unit 'entity))
15969 (error "ERROR: No entity/component under cursor")
15970 (vhdl-speedbar-port-copy)
15971 (if (fboundp 'speedbar-select-attached-frame)
15972 (speedbar-select-attached-frame)
15973 (select-frame speedbar-attached-frame))
15974 (vhdl-compose-place-component)
15975 (select-frame speedbar-frame)))
15977 (defun vhdl-speedbar-configuration ()
15978 "Generate configuration for the architecture under the cursor."
15979 (interactive)
15980 (if (not (vhdl-speedbar-check-unit 'architecture))
15981 (error "ERROR: No architecture under cursor")
15982 (let ((arch-name (vhdl-speedbar-line-text))
15983 (ent-name (vhdl-speedbar-higher-text)))
15984 (if (fboundp 'speedbar-select-attached-frame)
15985 (speedbar-select-attached-frame)
15986 (select-frame speedbar-attached-frame))
15987 (vhdl-compose-configuration ent-name arch-name))))
15989 (defun vhdl-speedbar-select-mra ()
15990 "Select the architecture under the cursor as MRA."
15991 (interactive)
15992 (if (not (vhdl-speedbar-check-unit 'architecture))
15993 (error "ERROR: No architecture under cursor")
15994 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15995 (ent-key (downcase (vhdl-speedbar-higher-text)))
15996 (ent-alist (vhdl-aget
15997 vhdl-entity-alist
15998 (or (vhdl-project-p)
15999 (abbreviate-file-name default-directory))))
16000 (ent-entry (vhdl-aget ent-alist ent-key)))
16001 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
16002 (speedbar-refresh))))
16004 (declare-function speedbar-line-file "speedbar" (&optional p))
16006 (defun vhdl-speedbar-make-design ()
16007 "Make (compile) design unit or directory/project under the cursor."
16008 (interactive)
16009 (if (not (save-excursion (beginning-of-line)
16010 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
16011 (error "ERROR: No primary design unit or directory/project under cursor")
16012 (let ((is-unit (match-string 2))
16013 (unit-name (vhdl-speedbar-line-text))
16014 (vhdl-project (vhdl-speedbar-line-project))
16015 (directory (file-name-as-directory
16016 (or (speedbar-line-file) (speedbar-line-directory)))))
16017 (if (fboundp 'speedbar-select-attached-frame)
16018 (speedbar-select-attached-frame)
16019 (select-frame speedbar-attached-frame))
16020 (let ((default-directory directory))
16021 (vhdl-make (and is-unit unit-name))))))
16023 (defun vhdl-speedbar-generate-makefile ()
16024 "Generate Makefile for directory/project under the cursor."
16025 (interactive)
16026 (let ((vhdl-project (vhdl-speedbar-line-project))
16027 (default-directory (file-name-as-directory
16028 (or (speedbar-line-file) (speedbar-line-directory)))))
16029 (vhdl-generate-makefile)))
16031 (defun vhdl-speedbar-check-unit (design-unit)
16032 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
16033 expansion function)."
16034 (save-excursion
16035 (speedbar-position-cursor-on-line)
16036 (cond ((eq design-unit 'entity)
16037 (memq (get-text-property (match-end 0) 'face)
16038 '(vhdl-speedbar-entity-face
16039 vhdl-speedbar-entity-selected-face)))
16040 ((eq design-unit 'architecture)
16041 (memq (get-text-property (match-end 0) 'face)
16042 '(vhdl-speedbar-architecture-face
16043 vhdl-speedbar-architecture-selected-face)))
16044 ((eq design-unit 'subprogram)
16045 (eq (get-text-property (match-end 0) 'face)
16046 'vhdl-speedbar-subprogram-face))
16047 (t nil))))
16049 (defun vhdl-speedbar-set-depth (depth)
16050 "Set hierarchy display depth to DEPTH and refresh speedbar."
16051 (setq vhdl-speedbar-hierarchy-depth depth)
16052 (speedbar-refresh))
16054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16055 ;; Fontification
16057 (defface vhdl-speedbar-entity-face
16058 '((((class color) (background light)) (:foreground "ForestGreen"))
16059 (((class color) (background dark)) (:foreground "PaleGreen")))
16060 "Face used for displaying entity names."
16061 :group 'speedbar-faces)
16063 (defface vhdl-speedbar-architecture-face
16064 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
16065 (((class color) (background light)) (:foreground "Blue"))
16067 (((class color) (background dark)) (:foreground "LightSkyBlue")))
16068 "Face used for displaying architecture names."
16069 :group 'speedbar-faces)
16071 (defface vhdl-speedbar-configuration-face
16072 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
16073 (((class color) (background dark)) (:foreground "Salmon")))
16074 "Face used for displaying configuration names."
16075 :group 'speedbar-faces)
16077 (defface vhdl-speedbar-package-face
16078 '((((class color) (background light)) (:foreground "Grey50"))
16079 (((class color) (background dark)) (:foreground "Grey80")))
16080 "Face used for displaying package names."
16081 :group 'speedbar-faces)
16083 (defface vhdl-speedbar-library-face
16084 '((((class color) (background light)) (:foreground "Purple"))
16085 (((class color) (background dark)) (:foreground "Orchid1")))
16086 "Face used for displaying library names."
16087 :group 'speedbar-faces)
16089 (defface vhdl-speedbar-instantiation-face
16090 '((((class color) (background light)) (:foreground "Brown"))
16091 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
16092 (((class color) (background dark)) (:foreground "Yellow")))
16093 "Face used for displaying instantiation names."
16094 :group 'speedbar-faces)
16096 (defface vhdl-speedbar-subprogram-face
16097 '((((class color) (background light)) (:foreground "Orchid4"))
16098 (((class color) (background dark)) (:foreground "BurlyWood2")))
16099 "Face used for displaying subprogram names."
16100 :group 'speedbar-faces)
16102 (defface vhdl-speedbar-entity-selected-face
16103 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
16104 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
16105 "Face used for displaying entity names."
16106 :group 'speedbar-faces)
16108 (defface vhdl-speedbar-architecture-selected-face
16109 '((((min-colors 88) (class color) (background light)) (:foreground
16110 "Blue1" :underline t))
16111 (((class color) (background light)) (:foreground "Blue" :underline t))
16112 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
16113 "Face used for displaying architecture names."
16114 :group 'speedbar-faces)
16116 (defface vhdl-speedbar-configuration-selected-face
16117 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
16118 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
16119 "Face used for displaying configuration names."
16120 :group 'speedbar-faces)
16122 (defface vhdl-speedbar-package-selected-face
16123 '((((class color) (background light)) (:foreground "Grey50" :underline t))
16124 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
16125 "Face used for displaying package names."
16126 :group 'speedbar-faces)
16128 (defface vhdl-speedbar-instantiation-selected-face
16129 '((((class color) (background light)) (:foreground "Brown" :underline t))
16130 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
16131 "Face used for displaying instantiation names."
16132 :group 'speedbar-faces)
16134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16135 ;; Initialization
16137 ;; add speedbar
16138 (when (fboundp 'speedbar)
16139 (let ((current-frame (selected-frame)))
16140 (condition-case ()
16141 (when (and vhdl-speedbar-auto-open
16142 (not (and (boundp 'speedbar-frame)
16143 (frame-live-p speedbar-frame))))
16144 (speedbar-frame-mode 1))
16145 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar")))
16146 (select-frame current-frame)))
16148 ;; initialize speedbar
16149 (if (not (boundp 'speedbar-frame))
16150 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
16151 (vhdl-speedbar-initialize)
16152 (when speedbar-frame (vhdl-speedbar-refresh)))
16155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16156 ;;; Structural composition
16157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16159 (defun vhdl-get-components-package-name ()
16160 "Return the name of the components package."
16161 (let ((project (vhdl-project-p)))
16162 (if project
16163 (vhdl-replace-string (car vhdl-components-package-name)
16164 (subst-char-in-string ? ?_ project))
16165 (cdr vhdl-components-package-name))))
16167 (defun vhdl-compose-new-component ()
16168 "Create entity and architecture for new component."
16169 (interactive)
16170 (let* ((case-fold-search t)
16171 (ent-name (read-from-minibuffer "entity name: "
16172 nil vhdl-minibuffer-local-map))
16173 (arch-name
16174 (if (equal (cdr vhdl-compose-architecture-name) "")
16175 (read-from-minibuffer "architecture name: "
16176 nil vhdl-minibuffer-local-map)
16177 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
16178 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
16179 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
16180 ;; open entity file
16181 (unless (eq vhdl-compose-create-files 'none)
16182 (setq ent-file-name
16183 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16184 "." (file-name-extension (buffer-file-name))))
16185 (when (and (file-exists-p ent-file-name)
16186 (not (y-or-n-p (concat "File \"" ent-file-name
16187 "\" exists; overwrite? "))))
16188 (error "ERROR: Creating component...aborted"))
16189 (find-file ent-file-name)
16190 (erase-buffer)
16191 (set-buffer-modified-p nil))
16192 ;; insert header
16193 (if vhdl-compose-include-header
16194 (progn (vhdl-template-header)
16195 (setq end-pos (point))
16196 (goto-char (point-max)))
16197 (vhdl-comment-display-line) (insert "\n\n"))
16198 ;; insert library clause
16199 (vhdl-template-package-std-logic-1164)
16200 (when vhdl-use-components-package
16201 (insert "\n")
16202 (vhdl-template-standard-package (vhdl-work-library)
16203 (vhdl-get-components-package-name)))
16204 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
16205 ;; insert entity declaration
16206 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
16207 (vhdl-insert-keyword " IS\n")
16208 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16209 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
16210 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16211 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16212 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
16213 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16214 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16215 (vhdl-insert-keyword "END ")
16216 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
16217 (insert ent-name ";\n\n")
16218 (vhdl-comment-display-line) (insert "\n")
16219 ;; open architecture file
16220 (if (not (eq vhdl-compose-create-files 'separate))
16221 (insert "\n")
16222 (goto-char (or end-pos (point-min)))
16223 (setq ent-buffer (current-buffer))
16224 (setq arch-file-name
16225 (concat (vhdl-replace-string vhdl-architecture-file-name
16226 (concat ent-name " " arch-name) t)
16227 "." (file-name-extension (buffer-file-name))))
16228 (when (and (file-exists-p arch-file-name)
16229 (not (y-or-n-p (concat "File \"" arch-file-name
16230 "\" exists; overwrite? "))))
16231 (error "ERROR: Creating component...aborted"))
16232 (find-file arch-file-name)
16233 (erase-buffer)
16234 (set-buffer-modified-p nil)
16235 ;; insert header
16236 (if vhdl-compose-include-header
16237 (progn (vhdl-template-header)
16238 (goto-char (point-max)))
16239 (vhdl-comment-display-line) (insert "\n\n")))
16240 ;; insert architecture body
16241 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
16242 (vhdl-insert-keyword " OF ") (insert ent-name)
16243 (vhdl-insert-keyword " IS\n\n")
16244 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16245 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
16246 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16247 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
16248 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16249 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16250 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
16251 (vhdl-insert-keyword "BEGIN")
16252 (when vhdl-self-insert-comments
16253 (insert " -- ")
16254 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16255 (insert arch-name))
16256 (insert "\n\n")
16257 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16258 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
16259 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16260 (vhdl-insert-keyword "END ")
16261 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16262 (insert arch-name ";\n\n")
16263 ;; insert footer and save
16264 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16265 (vhdl-template-footer)
16266 (vhdl-comment-display-line) (insert "\n"))
16267 (goto-char (or end-pos (point-min)))
16268 (setq arch-buffer (current-buffer))
16269 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
16270 (set-buffer arch-buffer) (save-buffer)
16271 (message "%s"
16272 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
16273 (and ent-file-name
16274 (format "\n File created: \"%s\"" ent-file-name))
16275 (and arch-file-name
16276 (format "\n File created: \"%s\"" arch-file-name))))))
16278 (defun vhdl-compose-place-component ()
16279 "Place new component by pasting current port as component declaration and
16280 component instantiation."
16281 (interactive)
16282 (if (not vhdl-port-list)
16283 (error "ERROR: No port has been read")
16284 (save-excursion
16285 (vhdl-prepare-search-2
16286 (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)
16287 (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))
16288 (error "ERROR: No architecture found"))
16289 (let* ((ent-name (match-string 1))
16290 (ent-file-name
16291 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16292 "." (file-name-extension (buffer-file-name))))
16293 (orig-buffer (current-buffer)))
16294 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
16295 ;; place component declaration
16296 (unless (or vhdl-use-components-package
16297 (vhdl-use-direct-instantiation)
16298 (save-excursion
16299 (re-search-forward
16300 (concat "^\\s-*component\\s-+"
16301 (car vhdl-port-list) "\\>") nil t)))
16302 (re-search-forward "^begin\\>" nil)
16303 (beginning-of-line)
16304 (skip-chars-backward " \t\n\r\f")
16305 (insert "\n\n") (indent-to vhdl-basic-offset)
16306 (vhdl-port-paste-component t))
16307 ;; place component instantiation
16308 (re-search-forward "^end\\>" nil)
16309 (beginning-of-line)
16310 (skip-chars-backward " \t\n\r\f")
16311 (insert "\n\n") (indent-to vhdl-basic-offset)
16312 (vhdl-port-paste-instance nil t t)
16313 ;; place use clause for used packages
16314 (when (nth 3 vhdl-port-list)
16315 ;; open entity file
16316 (when (file-exists-p ent-file-name)
16317 (find-file ent-file-name))
16318 (goto-char (point-min))
16319 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16320 (error "ERROR: Entity not found: \"%s\"" ent-name))
16321 (goto-char (match-beginning 0))
16322 (if (and (save-excursion
16323 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
16324 (match-string 1))
16325 (progn (goto-char (match-end 0))
16326 (beginning-of-line 2))
16327 (insert "\n")
16328 (backward-char))
16329 (vhdl-port-paste-context-clause)
16330 (switch-to-buffer orig-buffer))
16331 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
16333 (defun vhdl-compose-wire-components ()
16334 "Connect components."
16335 (interactive)
16336 (save-excursion
16337 (vhdl-prepare-search-2
16338 (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)
16339 (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))
16340 (error "ERROR: No architecture found"))
16341 (let* ((ent-name (match-string 1))
16342 (ent-file-name
16343 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16344 "." (file-name-extension (buffer-file-name))))
16345 (arch-decl-pos (point-marker))
16346 (arch-stat-pos (re-search-forward "^begin\\>" nil))
16347 (arch-end-pos (re-search-forward "^end\\>" nil))
16348 (pack-name (vhdl-get-components-package-name))
16349 (pack-file-name
16350 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16351 "." (file-name-extension (buffer-file-name))))
16352 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16353 port-alist generic-alist inst-alist
16354 signal-name signal-entry signal-alist local-list written-list
16355 single-in-list multi-in-list single-out-list multi-out-list
16356 constant-name constant-entry constant-alist single-list multi-list
16357 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16358 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16359 signal-beg-pos signal-pos
16360 constant-temp-pos port-temp-pos signal-temp-pos)
16361 (message "Wiring components...")
16362 ;; process all instances
16363 (goto-char arch-stat-pos)
16364 (while (re-search-forward
16365 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16366 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16367 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16368 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16369 "[ \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)
16370 (setq inst-name (match-string-no-properties 1)
16371 comp-name (match-string-no-properties 4)
16372 comp-ent-name (match-string-no-properties 12)
16373 has-generic (or (match-string 7) (match-string 17)))
16374 ;; get port ...
16375 (if comp-name
16376 ;; ... from component declaration
16377 (vhdl-visit-file
16378 (when vhdl-use-components-package pack-file-name) t
16379 (save-excursion
16380 (goto-char (point-min))
16381 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
16382 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
16383 (vhdl-port-copy)))
16384 ;; ... from entity declaration (direct instantiation)
16385 (setq comp-ent-file-name
16386 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
16387 "." (file-name-extension (buffer-file-name))))
16388 (vhdl-visit-file
16389 comp-ent-file-name t
16390 (save-excursion
16391 (goto-char (point-min))
16392 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
16393 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
16394 (vhdl-port-copy))))
16395 (vhdl-port-flatten t)
16396 (setq generic-alist (nth 1 vhdl-port-list)
16397 port-alist (nth 2 vhdl-port-list)
16398 vhdl-port-list nil)
16399 (setq constant-alist nil
16400 signal-alist nil)
16401 (when has-generic
16402 ;; process all constants in generic map
16403 (vhdl-forward-syntactic-ws)
16404 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16405 (setq constant-name (match-string-no-properties 3))
16406 (setq constant-entry
16407 (cons constant-name
16408 (if (match-string 1)
16409 (or (vhdl-aget generic-alist (match-string 2))
16410 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16411 (cdar generic-alist))))
16412 (push constant-entry constant-alist)
16413 (setq constant-name (downcase constant-name))
16414 (if (or (member constant-name single-list)
16415 (member constant-name multi-list))
16416 (progn (setq single-list (delete constant-name single-list))
16417 (pushnew constant-name multi-list :test #'equal))
16418 (pushnew constant-name single-list :test #'equal))
16419 (unless (match-string 1)
16420 (setq generic-alist (cdr generic-alist)))
16421 (vhdl-forward-syntactic-ws))
16422 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16423 ;; process all signals in port map
16424 (vhdl-forward-syntactic-ws)
16425 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16426 (setq signal-name (match-string-no-properties 3))
16427 (setq signal-entry
16428 (cons signal-name
16429 (if (match-string 1)
16430 (or (vhdl-aget port-alist (match-string 2))
16431 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16432 (cdar port-alist))))
16433 (push signal-entry signal-alist)
16434 (setq signal-name (downcase signal-name))
16435 (if (equal (upcase (nth 2 signal-entry)) "IN")
16436 ;; input signal
16437 (cond
16438 ((member signal-name local-list)
16439 nil)
16440 ((or (member signal-name single-out-list)
16441 (member signal-name multi-out-list))
16442 (setq single-out-list (delete signal-name single-out-list))
16443 (setq multi-out-list (delete signal-name multi-out-list))
16444 (pushnew signal-name local-list :test #'equal))
16445 ((member signal-name single-in-list)
16446 (setq single-in-list (delete signal-name single-in-list))
16447 (pushnew signal-name multi-in-list :test #'equal))
16448 ((not (member signal-name multi-in-list))
16449 (pushnew signal-name single-in-list :test #'equal)))
16450 ;; output signal
16451 (cond
16452 ((member signal-name local-list)
16453 nil)
16454 ((or (member signal-name single-in-list)
16455 (member signal-name multi-in-list))
16456 (setq single-in-list (delete signal-name single-in-list))
16457 (setq multi-in-list (delete signal-name multi-in-list))
16458 (pushnew signal-name local-list :test #'equal))
16459 ((member signal-name single-out-list)
16460 (setq single-out-list (delete signal-name single-out-list))
16461 (pushnew signal-name multi-out-list :test #'equal))
16462 ((not (member signal-name multi-out-list))
16463 (pushnew signal-name single-out-list :test #'equal))))
16464 (unless (match-string 1)
16465 (setq port-alist (cdr port-alist)))
16466 (vhdl-forward-syntactic-ws))
16467 (push (list inst-name (nreverse constant-alist)
16468 (nreverse signal-alist))
16469 inst-alist))
16470 ;; prepare signal insertion
16471 (vhdl-goto-marker arch-decl-pos)
16472 (forward-line 1)
16473 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16474 (setq signal-pos (point-marker))
16475 (while (progn (vhdl-forward-syntactic-ws)
16476 (looking-at "signal\\>"))
16477 (beginning-of-line 2)
16478 (delete-region signal-pos (point)))
16479 (setq signal-beg-pos signal-pos)
16480 ;; open entity file
16481 (when (file-exists-p ent-file-name)
16482 (find-file ent-file-name))
16483 (goto-char (point-min))
16484 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16485 (error "ERROR: Entity not found: \"%s\"" ent-name))
16486 ;; prepare generic clause insertion
16487 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16488 (match-string 1))
16489 (goto-char (match-beginning 0))
16490 (indent-to vhdl-basic-offset)
16491 (insert "generic ();\n\n")
16492 (backward-char 4))
16493 (backward-char)
16494 (setq generic-pos (point-marker))
16495 (forward-sexp) (end-of-line)
16496 (delete-region generic-pos (point)) (delete-char 1)
16497 (insert "(\n")
16498 (when multi-list
16499 (insert "\n")
16500 (indent-to (* 2 vhdl-basic-offset))
16501 (insert "-- global generics\n"))
16502 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16503 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16504 ;; prepare port clause insertion
16505 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16506 (match-string 1))
16507 (goto-char (match-beginning 0))
16508 (indent-to vhdl-basic-offset)
16509 (insert "port ();\n\n")
16510 (backward-char 4))
16511 (backward-char)
16512 (setq port-in-pos (point-marker))
16513 (forward-sexp) (end-of-line)
16514 (delete-region port-in-pos (point)) (delete-char 1)
16515 (insert "(\n")
16516 (when (or multi-in-list multi-out-list)
16517 (insert "\n")
16518 (indent-to (* 2 vhdl-basic-offset))
16519 (insert "-- global ports\n"))
16520 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16521 port-out-pos (point-marker) port-inst-pos (point-marker)
16522 port-end-pos (point-marker))
16523 ;; insert generics, ports and signals
16524 (setq inst-alist (nreverse inst-alist))
16525 (while inst-alist
16526 (setq inst-name (nth 0 (car inst-alist))
16527 constant-alist (nth 1 (car inst-alist))
16528 signal-alist (nth 2 (car inst-alist))
16529 constant-temp-pos generic-inst-pos
16530 port-temp-pos port-inst-pos
16531 signal-temp-pos signal-pos)
16532 ;; generics
16533 (while constant-alist
16534 (setq constant-name (downcase (caar constant-alist))
16535 constant-entry (car constant-alist))
16536 (unless (string-match "^[0-9]+" constant-name)
16537 (cond ((member constant-name written-list)
16538 nil)
16539 ((member constant-name multi-list)
16540 (vhdl-goto-marker generic-pos)
16541 (setq generic-end-pos
16542 (vhdl-max-marker
16543 generic-end-pos
16544 (vhdl-compose-insert-generic constant-entry)))
16545 (setq generic-pos (point-marker))
16546 (pushnew constant-name written-list :test #'equal))
16548 (vhdl-goto-marker
16549 (vhdl-max-marker generic-inst-pos generic-pos))
16550 (setq generic-end-pos
16551 (vhdl-compose-insert-generic constant-entry))
16552 (setq generic-inst-pos (point-marker))
16553 (pushnew constant-name written-list :test #'equal))))
16554 (setq constant-alist (cdr constant-alist)))
16555 (when (/= constant-temp-pos generic-inst-pos)
16556 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16557 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16558 (insert "-- generics for \"" inst-name "\"\n")
16559 (vhdl-goto-marker generic-inst-pos))
16560 ;; ports and signals
16561 (while signal-alist
16562 (setq signal-name (downcase (caar signal-alist))
16563 signal-entry (car signal-alist))
16564 (cond ((member signal-name written-list)
16565 nil)
16566 ((member signal-name multi-in-list)
16567 (vhdl-goto-marker port-in-pos)
16568 (setq port-end-pos
16569 (vhdl-max-marker
16570 port-end-pos (vhdl-compose-insert-port signal-entry)))
16571 (setq port-in-pos (point-marker))
16572 (pushnew signal-name written-list :test #'equal))
16573 ((member signal-name multi-out-list)
16574 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16575 (setq port-end-pos
16576 (vhdl-max-marker
16577 port-end-pos (vhdl-compose-insert-port signal-entry)))
16578 (setq port-out-pos (point-marker))
16579 (pushnew signal-name written-list :test #'equal))
16580 ((or (member signal-name single-in-list)
16581 (member signal-name single-out-list))
16582 (vhdl-goto-marker
16583 (vhdl-max-marker
16584 port-inst-pos
16585 (vhdl-max-marker port-out-pos port-in-pos)))
16586 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16587 (setq port-inst-pos (point-marker))
16588 (pushnew signal-name written-list :test #'equal))
16589 ((equal (upcase (nth 2 signal-entry)) "OUT")
16590 (vhdl-goto-marker signal-pos)
16591 (vhdl-compose-insert-signal signal-entry)
16592 (setq signal-pos (point-marker))
16593 (pushnew signal-name written-list :test #'equal)))
16594 (setq signal-alist (cdr signal-alist)))
16595 (when (/= port-temp-pos port-inst-pos)
16596 (vhdl-goto-marker
16597 (vhdl-max-marker port-temp-pos
16598 (vhdl-max-marker port-in-pos port-out-pos)))
16599 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16600 (insert "-- ports to \"" inst-name "\"\n")
16601 (vhdl-goto-marker port-inst-pos))
16602 (when (/= signal-temp-pos signal-pos)
16603 (vhdl-goto-marker signal-temp-pos)
16604 (insert "\n") (indent-to vhdl-basic-offset)
16605 (insert "-- outputs of \"" inst-name "\"\n")
16606 (vhdl-goto-marker signal-pos))
16607 (setq inst-alist (cdr inst-alist)))
16608 ;; finalize generic/port clause
16609 (vhdl-goto-marker generic-end-pos) (backward-char)
16610 (when (= generic-beg-pos generic-end-pos)
16611 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16612 (insert ";") (backward-char))
16613 (insert ")")
16614 (vhdl-goto-marker port-end-pos) (backward-char)
16615 (when (= port-beg-pos port-end-pos)
16616 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16617 (insert ";") (backward-char))
16618 (insert ")")
16619 ;; align everything
16620 (when vhdl-auto-align
16621 (vhdl-goto-marker generic-beg-pos)
16622 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16623 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16624 (vhdl-goto-marker signal-beg-pos)
16625 (vhdl-align-region-groups signal-beg-pos signal-pos))
16626 (switch-to-buffer (marker-buffer signal-beg-pos))
16627 (message "Wiring components...done")))))
16629 (defun vhdl-compose-insert-generic (entry)
16630 "Insert ENTRY as generic declaration."
16631 (let (pos)
16632 (indent-to (* 2 vhdl-basic-offset))
16633 (insert (nth 0 entry) " : " (nth 1 entry))
16634 (when (nth 2 entry)
16635 (insert " := " (nth 2 entry)))
16636 (insert ";")
16637 (setq pos (point-marker))
16638 (when (and vhdl-include-port-comments (nth 3 entry))
16639 (vhdl-comment-insert-inline (nth 3 entry) t))
16640 (insert "\n")
16641 pos))
16643 (defun vhdl-compose-insert-port (entry)
16644 "Insert ENTRY as port declaration."
16645 (let (pos)
16646 (indent-to (* 2 vhdl-basic-offset))
16647 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16648 (setq pos (point-marker))
16649 (when (and vhdl-include-port-comments (nth 4 entry))
16650 (vhdl-comment-insert-inline (nth 4 entry) t))
16651 (insert "\n")
16652 pos))
16654 (defun vhdl-compose-insert-signal (entry)
16655 "Insert ENTRY as signal declaration."
16656 (indent-to vhdl-basic-offset)
16657 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16658 (when (and vhdl-include-port-comments (nth 4 entry))
16659 (vhdl-comment-insert-inline (nth 4 entry) t))
16660 (insert "\n"))
16662 (defun vhdl-compose-components-package ()
16663 "Generate a package containing component declarations for all entities in the
16664 current project/directory."
16665 (interactive)
16666 (vhdl-require-hierarchy-info)
16667 (let* ((project (vhdl-project-p))
16668 (pack-name (vhdl-get-components-package-name))
16669 (pack-file-name
16670 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16671 "." (file-name-extension (buffer-file-name))))
16672 (ent-alist (vhdl-aget vhdl-entity-alist
16673 (or project
16674 (abbreviate-file-name default-directory))))
16675 (lazy-lock-minimum-size 0)
16676 clause-pos component-pos)
16677 (message "Generating components package \"%s\"..." pack-name)
16678 ;; open package file
16679 (when (and (file-exists-p pack-file-name)
16680 (not (y-or-n-p (concat "File \"" pack-file-name
16681 "\" exists; overwrite? "))))
16682 (error "ERROR: Generating components package...aborted"))
16683 (find-file pack-file-name)
16684 (erase-buffer)
16685 ;; insert header
16686 (if vhdl-compose-include-header
16687 (progn (vhdl-template-header
16688 (concat "Components package (generated by Emacs VHDL Mode "
16689 vhdl-version ")"))
16690 (goto-char (point-max)))
16691 (vhdl-comment-display-line) (insert "\n\n"))
16692 ;; insert std_logic_1164 package
16693 (vhdl-template-package-std-logic-1164)
16694 (insert "\n") (setq clause-pos (point-marker))
16695 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16696 ;; insert package declaration
16697 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16698 (vhdl-insert-keyword " IS\n\n")
16699 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16700 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16701 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16702 (indent-to vhdl-basic-offset)
16703 (setq component-pos (point-marker))
16704 (insert "\n\n") (vhdl-insert-keyword "END ")
16705 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16706 (insert pack-name ";\n\n")
16707 ;; insert footer
16708 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16709 (vhdl-template-footer)
16710 (vhdl-comment-display-line) (insert "\n"))
16711 ;; insert component declarations
16712 (while ent-alist
16713 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16714 (progn (goto-char (point-min))
16715 (forward-line (1- (nth 3 (car ent-alist))))
16716 (end-of-line)
16717 (vhdl-port-copy)))
16718 (goto-char component-pos)
16719 (vhdl-port-paste-component t)
16720 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16721 (setq component-pos (point-marker))
16722 (goto-char clause-pos)
16723 (vhdl-port-paste-context-clause pack-name)
16724 (setq clause-pos (point-marker))
16725 (setq ent-alist (cdr ent-alist)))
16726 (goto-char (point-min))
16727 (save-buffer)
16728 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16729 pack-name pack-file-name)))
16731 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16732 conf-alist inst-alist
16733 &optional insert-conf)
16734 "Generate block configuration for architecture."
16735 (let ((margin (current-indentation))
16736 (beg (point-at-bol))
16737 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16738 ;; insert block configuration (for architecture)
16739 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16740 (setq margin (+ margin vhdl-basic-offset))
16741 ;; process all instances
16742 (while inst-alist
16743 (setq inst-entry (car inst-alist))
16744 ;; is component?
16745 (when (nth 4 inst-entry)
16746 (setq insert-conf t)
16747 (setq inst-path (nth 9 inst-entry))
16748 ;; skip common path with previous instance
16749 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16750 (setq inst-path (cdr inst-path)
16751 inst-prev-path (cdr inst-prev-path)))
16752 ;; insert block configuration end (for previous block/generate)
16753 (while inst-prev-path
16754 (setq margin (- margin vhdl-basic-offset))
16755 (indent-to margin)
16756 (vhdl-insert-keyword "END FOR;\n")
16757 (setq inst-prev-path (cdr inst-prev-path)))
16758 ;; insert block configuration beginning (for current block/generate)
16759 (indent-to margin)
16760 (while inst-path
16761 (setq margin (+ margin vhdl-basic-offset))
16762 (vhdl-insert-keyword "FOR ")
16763 (insert (car inst-path) "\n")
16764 (indent-to margin)
16765 (setq inst-path (cdr inst-path)))
16766 ;; insert component configuration beginning
16767 (vhdl-insert-keyword "FOR ")
16768 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16769 ;; find subconfiguration
16770 (setq conf-key (nth 7 inst-entry))
16771 (setq tmp-alist conf-alist)
16772 ;; use first configuration found for instance's entity
16773 (while (and tmp-alist (null conf-key))
16774 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16775 (setq conf-key (nth 0 (car tmp-alist))))
16776 (setq tmp-alist (cdr tmp-alist)))
16777 (setq conf-entry (vhdl-aget conf-alist conf-key))
16778 ;; insert binding indication ...
16779 ;; ... with subconfiguration (if exists)
16780 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16781 (progn
16782 (indent-to (+ margin vhdl-basic-offset))
16783 (vhdl-insert-keyword "USE CONFIGURATION ")
16784 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16785 (insert ";\n"))
16786 ;; ... with entity (if exists)
16787 (setq ent-entry (vhdl-aget ent-alist (nth 5 inst-entry)))
16788 (when ent-entry
16789 (indent-to (+ margin vhdl-basic-offset))
16790 (vhdl-insert-keyword "USE ENTITY ")
16791 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16792 ;; insert architecture name (if architecture exists)
16793 (when (nth 3 ent-entry)
16794 (setq arch-name
16795 ;; choose architecture name a) from configuration,
16796 ;; b) from mra, or c) from first architecture
16797 (or (nth 0 (vhdl-aget (nth 3 ent-entry)
16798 (or (nth 6 inst-entry)
16799 (nth 4 ent-entry))))
16800 (nth 1 (car (nth 3 ent-entry)))))
16801 (insert "(" arch-name ")"))
16802 (insert ";\n")
16803 ;; insert block configuration (for architecture of subcomponent)
16804 (when (and vhdl-compose-configuration-hierarchical
16805 (nth 3 ent-entry))
16806 (indent-to (+ margin vhdl-basic-offset))
16807 (vhdl-compose-configuration-architecture
16808 (nth 0 ent-entry) arch-name ent-alist conf-alist
16809 (nth 3 (vhdl-aget (nth 3 ent-entry) (downcase arch-name)))))))
16810 ;; insert component configuration end
16811 (indent-to margin)
16812 (vhdl-insert-keyword "END FOR;\n")
16813 (setq inst-prev-path (nth 9 inst-entry)))
16814 (setq inst-alist (cdr inst-alist)))
16815 ;; insert block configuration end (for block/generate)
16816 (while inst-prev-path
16817 (setq margin (- margin vhdl-basic-offset))
16818 (indent-to margin)
16819 (vhdl-insert-keyword "END FOR;\n")
16820 (setq inst-prev-path (cdr inst-prev-path)))
16821 (indent-to (- margin vhdl-basic-offset))
16822 ;; insert block configuration end or remove beginning (for architecture)
16823 (if insert-conf
16824 (vhdl-insert-keyword "END FOR;\n")
16825 (delete-region beg (point)))))
16827 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16828 "Generate configuration declaration."
16829 (interactive)
16830 (vhdl-require-hierarchy-info)
16831 (let ((ent-alist (vhdl-aget vhdl-entity-alist
16832 (or (vhdl-project-p)
16833 (abbreviate-file-name default-directory))))
16834 (conf-alist (vhdl-aget vhdl-config-alist
16835 (or (vhdl-project-p)
16836 (abbreviate-file-name default-directory))))
16837 (from-speedbar ent-name)
16838 inst-alist conf-name conf-file-name pos)
16839 (vhdl-prepare-search-2
16840 ;; get entity and architecture name
16841 (unless ent-name
16842 (save-excursion
16843 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16844 (not (equal "END" (upcase (match-string 1))))
16845 (setq ent-name (match-string-no-properties 3))
16846 (setq arch-name (match-string-no-properties 2)))
16847 (error "ERROR: Not within an architecture"))))
16848 (setq conf-name (vhdl-replace-string
16849 vhdl-compose-configuration-name
16850 (concat ent-name " " arch-name)))
16851 (setq inst-alist
16852 (nth 3 (vhdl-aget (nth 3 (vhdl-aget ent-alist (downcase ent-name)))
16853 (downcase arch-name)))))
16854 (message "Generating configuration \"%s\"..." conf-name)
16855 (if vhdl-compose-configuration-create-file
16856 ;; open configuration file
16857 (progn
16858 (setq conf-file-name
16859 (concat (vhdl-replace-string vhdl-configuration-file-name
16860 conf-name t)
16861 "." (file-name-extension (buffer-file-name))))
16862 (when (and (file-exists-p conf-file-name)
16863 (not (y-or-n-p (concat "File \"" conf-file-name
16864 "\" exists; overwrite? "))))
16865 (error "ERROR: Creating configuration...aborted"))
16866 (find-file conf-file-name)
16867 (erase-buffer)
16868 (set-buffer-modified-p nil)
16869 ;; insert header
16870 (if vhdl-compose-include-header
16871 (progn (vhdl-template-header
16872 (concat "Configuration declaration for design \""
16873 ent-name "(" arch-name ")\""))
16874 (goto-char (point-max)))
16875 (vhdl-comment-display-line) (insert "\n\n")))
16876 ;; goto end of architecture
16877 (unless from-speedbar
16878 (re-search-forward "^end\\>" nil)
16879 (end-of-line) (insert "\n\n")
16880 (vhdl-comment-display-line) (insert "\n\n")))
16881 ;; insert library clause
16882 (setq pos (point))
16883 (vhdl-template-standard-package (vhdl-work-library) nil)
16884 (when (/= pos (point))
16885 (insert "\n\n"))
16886 ;; insert configuration
16887 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16888 (vhdl-insert-keyword " OF ") (insert ent-name)
16889 (vhdl-insert-keyword " IS\n")
16890 (indent-to vhdl-basic-offset)
16891 ;; insert block configuration (for architecture)
16892 (vhdl-compose-configuration-architecture
16893 ent-name arch-name ent-alist conf-alist inst-alist t)
16894 (vhdl-insert-keyword "END ") (insert conf-name ";")
16895 (when conf-file-name
16896 ;; insert footer and save
16897 (insert "\n\n")
16898 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16899 (vhdl-template-footer)
16900 (vhdl-comment-display-line) (insert "\n"))
16901 (save-buffer))
16902 (message "%s"
16903 (concat (format "Generating configuration \"%s\"...done" conf-name)
16904 (and conf-file-name
16905 (format "\n File created: \"%s\"" conf-file-name))))))
16908 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16909 ;;; Compilation / Makefile generation
16910 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16911 ;; (using `compile.el')
16913 (defvar vhdl-compile-post-command ""
16914 "String appended to compile command after file name.")
16916 (defun vhdl-makefile-name ()
16917 "Return the Makefile name of the current project or the current compiler if
16918 no project is defined."
16919 (let ((project-alist (vhdl-aget vhdl-project-alist vhdl-project))
16920 (compiler-alist (vhdl-aget vhdl-compiler-alist vhdl-compiler)))
16921 (vhdl-replace-string
16922 (cons "\\(.*\\)\n\\(.*\\)"
16923 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16924 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16926 (defun vhdl-compile-directory ()
16927 "Return the directory where compilation/make should be run."
16928 (let* ((project (vhdl-aget vhdl-project-alist (vhdl-project-p t)))
16929 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
16930 (directory (vhdl-resolve-env-variable
16931 (if project
16932 (vhdl-replace-string
16933 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16934 (nth 6 compiler)))))
16935 (file-name-as-directory
16936 (if (file-name-absolute-p directory)
16937 directory
16938 (expand-file-name directory (vhdl-default-directory))))))
16940 (defun vhdl-uniquify (in-list)
16941 "Remove duplicate elements from IN-LIST."
16942 (let (out-list)
16943 (while in-list
16944 (pushnew (car in-list) out-list :test #'equal)
16945 (setq in-list (cdr in-list)))
16946 out-list))
16948 (defun vhdl-set-compiler (name)
16949 "Set current compiler to NAME."
16950 (interactive
16951 (list (let ((completion-ignore-case t))
16952 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16953 (if (assoc name vhdl-compiler-alist)
16954 (progn (setq vhdl-compiler name)
16955 (message "Current compiler: \"%s\"" vhdl-compiler))
16956 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16958 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16959 ;; Compilation
16961 (defun vhdl-compile-init ()
16962 "Initialize for compilation."
16963 (when (and (not vhdl-emacs-22)
16964 (or (null compilation-error-regexp-alist)
16965 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16966 compilation-error-regexp-alist))))
16967 ;; `compilation-error-regexp-alist'
16968 (let ((commands-alist vhdl-compiler-alist)
16969 regexp-alist sublist)
16970 (while commands-alist
16971 (setq sublist (nth 11 (car commands-alist)))
16972 (unless (or (equal "" (car sublist))
16973 (assoc (car sublist) regexp-alist))
16974 (push (list (nth 0 sublist)
16975 (if (and (featurep 'xemacs) (not (nth 1 sublist)))
16977 (nth 1 sublist))
16978 (nth 2 sublist) (nth 3 sublist))
16979 regexp-alist))
16980 (setq commands-alist (cdr commands-alist)))
16981 (setq compilation-error-regexp-alist
16982 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16983 ;; `compilation-file-regexp-alist'
16984 (let ((commands-alist vhdl-compiler-alist)
16985 regexp-alist sublist)
16986 ;; matches vhdl-mode file name output
16987 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16988 (while commands-alist
16989 (setq sublist (nth 12 (car commands-alist)))
16990 (unless (or (equal "" (car sublist))
16991 (assoc (car sublist) regexp-alist))
16992 (push sublist regexp-alist))
16993 (setq commands-alist (cdr commands-alist)))
16994 (setq compilation-file-regexp-alist
16995 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16997 (defvar vhdl-compile-file-name nil
16998 "Name of file to be compiled.")
17000 (defun vhdl-compile-print-file-name ()
17001 "Function called within `compile' to print out file name for compilers that
17002 do not print any file names."
17003 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
17005 (defun vhdl-get-compile-options (project compiler file-name
17006 &optional file-options-only)
17007 "Get compiler options. Returning nil means do not compile this file."
17008 (let* ((compiler-options (nth 1 compiler))
17009 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17010 (project-options (nth 0 project-entry))
17011 (exception-list (and file-name (nth 2 project-entry)))
17012 (work-library (vhdl-work-library))
17013 (case-fold-search nil)
17014 file-options)
17015 (while (and exception-list
17016 (not (string-match (caar exception-list) file-name)))
17017 (setq exception-list (cdr exception-list)))
17018 (if (and exception-list (not (cdar exception-list)))
17020 (if (and file-options-only (not exception-list))
17021 'default
17022 (setq file-options (cdar exception-list))
17023 ;; insert library name in compiler-specific options
17024 (setq compiler-options
17025 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
17026 work-library))
17027 ;; insert compiler-specific options in project-specific options
17028 (when project-options
17029 (setq project-options
17030 (vhdl-replace-string
17031 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17032 (concat work-library "\n" compiler-options))))
17033 ;; insert project-specific options in file-specific options
17034 (when file-options
17035 (setq file-options
17036 (vhdl-replace-string
17037 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
17038 (concat work-library "\n" compiler-options "\n"
17039 project-options))))
17040 ;; return options
17041 (or file-options project-options compiler-options)))))
17043 (defun vhdl-get-make-options (project compiler)
17044 "Get make options."
17045 (let* ((compiler-options (nth 3 compiler))
17046 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17047 (project-options (nth 1 project-entry))
17048 (makefile-name (vhdl-makefile-name)))
17049 ;; insert Makefile name in compiler-specific options
17050 (setq compiler-options
17051 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
17052 makefile-name))
17053 ;; insert compiler-specific options in project-specific options
17054 (when project-options
17055 (setq project-options
17056 (vhdl-replace-string
17057 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17058 (concat makefile-name "\n" compiler-options))))
17059 ;; return options
17060 (or project-options compiler-options)))
17062 (defun vhdl-compile ()
17063 "Compile current buffer using the VHDL compiler specified in
17064 `vhdl-compiler'."
17065 (interactive)
17066 (vhdl-compile-init)
17067 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17068 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17069 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17070 (command (nth 0 compiler))
17071 (default-directory (vhdl-compile-directory))
17072 (file-name (if vhdl-compile-absolute-path
17073 (buffer-file-name)
17074 (file-relative-name (buffer-file-name))))
17075 (options (vhdl-get-compile-options project compiler file-name))
17076 compilation-process-setup-function)
17077 (unless (file-directory-p default-directory)
17078 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17079 ;; put file name into quotes if it contains spaces
17080 (when (string-match " " file-name)
17081 (setq file-name (concat "\"" file-name "\"")))
17082 ;; print out file name if compiler does not
17083 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
17084 (buffer-file-name)
17085 (file-relative-name (buffer-file-name))))
17086 (when (and (= 0 (nth 1 (nth 10 compiler)))
17087 (= 0 (nth 1 (nth 11 compiler))))
17088 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
17089 ;; run compilation
17090 (if options
17091 (when command
17092 (compile (concat command " " options " " file-name
17093 (unless (equal vhdl-compile-post-command "")
17094 (concat " " vhdl-compile-post-command)))))
17095 (vhdl-warning "Your project settings tell me not to compile this file"))))
17097 (defvar vhdl-make-target "all"
17098 "Default target for `vhdl-make' command.")
17100 (defun vhdl-make (&optional target)
17101 "Call make command for compilation of all updated source files (requires
17102 `Makefile'). Optional argument TARGET allows you to compile the design
17103 specified by a target."
17104 (interactive)
17105 (setq vhdl-make-target
17106 (or target (read-from-minibuffer "Target: " vhdl-make-target
17107 vhdl-minibuffer-local-map)))
17108 (vhdl-compile-init)
17109 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17110 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17111 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17112 (command (nth 2 compiler))
17113 (options (vhdl-get-make-options project compiler))
17114 (default-directory (vhdl-compile-directory)))
17115 (unless (file-directory-p default-directory)
17116 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17117 ;; run make
17118 (compile (concat (if (equal command "") "make" command)
17119 " " options " " vhdl-make-target))))
17121 ;; Emacs 22+ setup
17122 (defvar vhdl-error-regexp-emacs-alist
17123 ;; Get regexps from `vhdl-compiler-alist'
17124 (let ((compiler-alist vhdl-compiler-alist)
17125 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
17126 (while compiler-alist
17127 ;; only add regexps for currently selected compiler
17128 (when (or (not vhdl-compile-use-local-error-regexp)
17129 (equal vhdl-compiler (nth 0 (car compiler-alist))))
17130 ;; add error message regexps
17131 (setq error-regexp-alist
17132 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
17133 (nth 11 (car compiler-alist)))
17134 error-regexp-alist))
17135 ;; add filename regexps
17136 (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
17137 (setq error-regexp-alist
17138 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
17139 (nth 12 (car compiler-alist)))
17140 error-regexp-alist))))
17141 (setq compiler-alist (cdr compiler-alist)))
17142 error-regexp-alist)
17143 "List of regexps for VHDL compilers. For Emacs 22+.")
17145 ;; Add error regexps using compilation-mode-hook.
17146 (defun vhdl-error-regexp-add-emacs ()
17147 "Set up Emacs compile for VHDL."
17148 (interactive)
17149 (when (and (boundp 'compilation-error-regexp-alist-alist)
17150 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
17151 ;; remove all other compilers
17152 (when vhdl-compile-use-local-error-regexp
17153 (setq compilation-error-regexp-alist nil))
17154 ;; add VHDL compilers
17155 (mapcar
17156 (lambda (item)
17157 (push (car item) compilation-error-regexp-alist)
17158 (push item compilation-error-regexp-alist-alist))
17159 vhdl-error-regexp-emacs-alist)))
17161 (when vhdl-emacs-22
17162 (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
17164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17165 ;; Makefile generation
17167 (defun vhdl-generate-makefile ()
17168 "Generate `Makefile'."
17169 (interactive)
17170 (let* ((compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17171 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17172 (command (nth 4 compiler)))
17173 ;; generate makefile
17174 (if command
17175 (let ((default-directory (vhdl-compile-directory)))
17176 (compile (vhdl-replace-string
17177 (cons "\\(.*\\) \\(.*\\)" command)
17178 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
17179 (vhdl-generate-makefile-1))))
17181 (defun vhdl-get-packages (lib-alist work-library)
17182 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
17183 (let (pack-list)
17184 (while lib-alist
17185 (when (equal (downcase (caar lib-alist)) (downcase work-library))
17186 (push (cdar lib-alist) pack-list))
17187 (setq lib-alist (cdr lib-alist)))
17188 pack-list))
17190 (defun vhdl-generate-makefile-1 ()
17191 "Generate Makefile for current project or directory."
17192 ;; scan hierarchy if required
17193 (if (vhdl-project-p)
17194 (unless (or (assoc vhdl-project vhdl-file-alist)
17195 (vhdl-load-cache vhdl-project))
17196 (vhdl-scan-project-contents vhdl-project))
17197 (let ((directory (abbreviate-file-name default-directory)))
17198 (unless (or (assoc directory vhdl-file-alist)
17199 (vhdl-load-cache directory))
17200 (vhdl-scan-directory-contents directory))))
17201 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
17202 (project (vhdl-project-p))
17203 (ent-alist (vhdl-aget vhdl-entity-alist (or project directory)))
17204 (conf-alist (vhdl-aget vhdl-config-alist (or project directory)))
17205 (pack-alist (vhdl-aget vhdl-package-alist (or project directory)))
17206 (regexp-list (or (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17207 '("\\1.vhd" "\\2_\\1.vhd" "\\1.vhd"
17208 "\\1.vhd" "\\1_body.vhd" identity)))
17209 (mapping-exist
17210 (if (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler)) t nil))
17211 (ent-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 0 regexp-list)))
17212 (arch-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
17213 (conf-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 2 regexp-list)))
17214 (pack-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 3 regexp-list)))
17215 (pack-body-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 4 regexp-list)))
17216 (adjust-case (nth 5 regexp-list))
17217 (work-library (downcase (vhdl-work-library)))
17218 (compile-directory (expand-file-name (vhdl-compile-directory)
17219 default-directory))
17220 (makefile-name (vhdl-makefile-name))
17221 rule-alist arch-alist inst-alist
17222 target-list depend-list unit-list prim-list second-list subcomp-list
17223 lib-alist lib-body-alist pack-list all-pack-list
17224 ent-key ent-file-name arch-key arch-file-name ent-arch-key
17225 conf-key conf-file-name pack-key pack-file-name
17226 ent-entry arch-entry conf-entry pack-entry inst-entry
17227 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
17228 tmp-key tmp-list rule)
17229 ;; check prerequisites
17230 (unless (file-exists-p compile-directory)
17231 (make-directory compile-directory t))
17232 (unless mapping-exist
17233 (vhdl-warning
17234 (format "No unit-to-file name mapping found for compiler \"%s\".\n Directory of dummy files is created instead (to be used as dependencies).\n Please contact the VHDL Mode maintainer for full support of \"%s\""
17235 vhdl-compiler vhdl-compiler) t))
17236 (message "Generating makefile \"%s\"..." makefile-name)
17237 ;; rules for all entities
17238 (setq tmp-list ent-alist)
17239 (while ent-alist
17240 (setq ent-entry (car ent-alist)
17241 ent-key (nth 0 ent-entry))
17242 (when (nth 2 ent-entry)
17243 (setq ent-file-name (if vhdl-compile-absolute-path
17244 (nth 2 ent-entry)
17245 (file-relative-name (nth 2 ent-entry)
17246 compile-directory))
17247 arch-alist (nth 4 ent-entry)
17248 lib-alist (nth 6 ent-entry)
17249 rule (vhdl-aget rule-alist ent-file-name)
17250 target-list (nth 0 rule)
17251 depend-list (nth 1 rule)
17252 second-list nil
17253 subcomp-list nil)
17254 (setq tmp-key (vhdl-replace-string
17255 ent-regexp
17256 (funcall adjust-case
17257 (concat ent-key " " work-library))))
17258 (push (cons ent-key tmp-key) unit-list)
17259 ;; rule target for this entity
17260 (push ent-key target-list)
17261 ;; rule dependencies for all used packages
17262 (setq pack-list (vhdl-get-packages lib-alist work-library))
17263 (setq depend-list (append depend-list pack-list))
17264 (setq all-pack-list pack-list)
17265 ;; add rule
17266 (vhdl-aput 'rule-alist ent-file-name (list target-list depend-list))
17267 ;; rules for all corresponding architectures
17268 (while arch-alist
17269 (setq arch-entry (car arch-alist)
17270 arch-key (nth 0 arch-entry)
17271 ent-arch-key (concat ent-key "-" arch-key)
17272 arch-file-name (if vhdl-compile-absolute-path
17273 (nth 2 arch-entry)
17274 (file-relative-name (nth 2 arch-entry)
17275 compile-directory))
17276 inst-alist (nth 4 arch-entry)
17277 lib-alist (nth 5 arch-entry)
17278 rule (vhdl-aget rule-alist arch-file-name)
17279 target-list (nth 0 rule)
17280 depend-list (nth 1 rule))
17281 (setq tmp-key (vhdl-replace-string
17282 arch-regexp
17283 (funcall adjust-case
17284 (concat arch-key " " ent-key " "
17285 work-library))))
17286 (setq unit-list
17287 (cons (cons ent-arch-key tmp-key) unit-list))
17288 (push ent-arch-key second-list)
17289 ;; rule target for this architecture
17290 (push ent-arch-key target-list)
17291 ;; rule dependency for corresponding entity
17292 (push ent-key depend-list)
17293 ;; rule dependencies for contained component instantiations
17294 (while inst-alist
17295 (setq inst-entry (car inst-alist))
17296 (when (or (null (nth 8 inst-entry))
17297 (equal (downcase (nth 8 inst-entry)) work-library))
17298 (setq inst-ent-key (or (nth 7 inst-entry)
17299 (nth 5 inst-entry)))
17300 (setq depend-list (cons inst-ent-key depend-list)
17301 subcomp-list (cons inst-ent-key subcomp-list)))
17302 (setq inst-alist (cdr inst-alist)))
17303 ;; rule dependencies for all used packages
17304 (setq pack-list (vhdl-get-packages lib-alist work-library))
17305 (setq depend-list (append depend-list pack-list))
17306 (setq all-pack-list (append all-pack-list pack-list))
17307 ;; add rule
17308 (vhdl-aput 'rule-alist arch-file-name (list target-list depend-list))
17309 (setq arch-alist (cdr arch-alist)))
17310 (push (list ent-key second-list (append subcomp-list all-pack-list))
17311 prim-list))
17312 (setq ent-alist (cdr ent-alist)))
17313 (setq ent-alist tmp-list)
17314 ;; rules for all configurations
17315 (setq tmp-list conf-alist)
17316 (while conf-alist
17317 (setq conf-entry (car conf-alist)
17318 conf-key (nth 0 conf-entry)
17319 conf-file-name (if vhdl-compile-absolute-path
17320 (nth 2 conf-entry)
17321 (file-relative-name (nth 2 conf-entry)
17322 compile-directory))
17323 ent-key (nth 4 conf-entry)
17324 arch-key (nth 5 conf-entry)
17325 inst-alist (nth 6 conf-entry)
17326 lib-alist (nth 7 conf-entry)
17327 rule (vhdl-aget rule-alist conf-file-name)
17328 target-list (nth 0 rule)
17329 depend-list (nth 1 rule)
17330 subcomp-list (list ent-key))
17331 (setq tmp-key (vhdl-replace-string
17332 conf-regexp
17333 (funcall adjust-case
17334 (concat conf-key " " work-library))))
17335 (push (cons conf-key tmp-key) unit-list)
17336 ;; rule target for this configuration
17337 (push conf-key target-list)
17338 ;; rule dependency for corresponding entity and architecture
17339 (setq depend-list
17340 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
17341 ;; rule dependencies for used packages
17342 (setq pack-list (vhdl-get-packages lib-alist work-library))
17343 (setq depend-list (append depend-list pack-list))
17344 ;; rule dependencies for contained component configurations
17345 (while inst-alist
17346 (setq inst-entry (car inst-alist))
17347 (setq inst-ent-key (nth 2 inst-entry)
17348 inst-conf-key (nth 4 inst-entry))
17349 (when (equal (downcase (nth 5 inst-entry)) work-library)
17350 (when inst-ent-key
17351 (setq depend-list (cons inst-ent-key depend-list)
17352 subcomp-list (cons inst-ent-key subcomp-list)))
17353 (when inst-conf-key
17354 (setq depend-list (cons inst-conf-key depend-list)
17355 subcomp-list (cons inst-conf-key subcomp-list))))
17356 (setq inst-alist (cdr inst-alist)))
17357 ;; add rule
17358 (vhdl-aput 'rule-alist conf-file-name (list target-list depend-list))
17359 (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
17360 (setq conf-alist (cdr conf-alist)))
17361 (setq conf-alist tmp-list)
17362 ;; rules for all packages
17363 (setq tmp-list pack-alist)
17364 (while pack-alist
17365 (setq pack-entry (car pack-alist)
17366 pack-key (nth 0 pack-entry)
17367 pack-body-key nil)
17368 (when (nth 2 pack-entry)
17369 (setq pack-file-name (if vhdl-compile-absolute-path
17370 (nth 2 pack-entry)
17371 (file-relative-name (nth 2 pack-entry)
17372 compile-directory))
17373 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
17374 rule (vhdl-aget rule-alist pack-file-name)
17375 target-list (nth 0 rule) depend-list (nth 1 rule))
17376 (setq tmp-key (vhdl-replace-string
17377 pack-regexp
17378 (funcall adjust-case
17379 (concat pack-key " " work-library))))
17380 (push (cons pack-key tmp-key) unit-list)
17381 ;; rule target for this package
17382 (push pack-key target-list)
17383 ;; rule dependencies for all used packages
17384 (setq pack-list (vhdl-get-packages lib-alist work-library))
17385 (setq depend-list (append depend-list pack-list))
17386 (setq all-pack-list pack-list)
17387 ;; add rule
17388 (vhdl-aput 'rule-alist pack-file-name (list target-list depend-list))
17389 ;; rules for this package's body
17390 (when (nth 7 pack-entry)
17391 (setq pack-body-key (concat pack-key "-body")
17392 pack-body-file-name (if vhdl-compile-absolute-path
17393 (nth 7 pack-entry)
17394 (file-relative-name (nth 7 pack-entry)
17395 compile-directory))
17396 rule (vhdl-aget rule-alist pack-body-file-name)
17397 target-list (nth 0 rule)
17398 depend-list (nth 1 rule))
17399 (setq tmp-key (vhdl-replace-string
17400 pack-body-regexp
17401 (funcall adjust-case
17402 (concat pack-key " " work-library))))
17403 (setq unit-list
17404 (cons (cons pack-body-key tmp-key) unit-list))
17405 ;; rule target for this package's body
17406 (push pack-body-key target-list)
17407 ;; rule dependency for corresponding package declaration
17408 (push pack-key depend-list)
17409 ;; rule dependencies for all used packages
17410 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
17411 (setq depend-list (append depend-list pack-list))
17412 (setq all-pack-list (append all-pack-list pack-list))
17413 ;; add rule
17414 (vhdl-aput 'rule-alist pack-body-file-name
17415 (list target-list depend-list)))
17416 (setq prim-list
17417 (cons (list pack-key (when pack-body-key (list pack-body-key))
17418 all-pack-list)
17419 prim-list)))
17420 (setq pack-alist (cdr pack-alist)))
17421 (setq pack-alist tmp-list)
17422 ;; generate Makefile
17423 (let* ((project (vhdl-aget vhdl-project-alist project))
17424 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17425 (compiler-id (nth 9 compiler))
17426 (library-directory
17427 (vhdl-resolve-env-variable
17428 (vhdl-replace-string
17429 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
17430 compiler-id)))
17431 (makefile-path-name (expand-file-name
17432 makefile-name compile-directory))
17433 (orig-buffer (current-buffer))
17434 cell second-list subcomp-list options unit-key unit-name)
17435 ;; sort lists
17436 (setq unit-list (vhdl-sort-alist unit-list))
17437 (setq prim-list (vhdl-sort-alist prim-list))
17438 (setq tmp-list rule-alist)
17439 (while tmp-list ; pre-sort rule targets
17440 (setq cell (cdar tmp-list))
17441 (setcar cell (sort (car cell) 'string<))
17442 (setq tmp-list (cdr tmp-list)))
17443 (setq rule-alist ; sort by first rule target
17444 (sort rule-alist
17445 (function (lambda (a b)
17446 (string< (car (cadr a)) (car (cadr b)))))))
17447 ;; open and clear Makefile
17448 (set-buffer (find-file-noselect makefile-path-name t t))
17449 (erase-buffer)
17450 (insert "# -*- Makefile -*-\n"
17451 "### " (file-name-nondirectory makefile-name)
17452 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17453 "\n")
17454 (if project
17455 (insert "\n# Project : " (nth 0 project))
17456 (insert "\n# Directory : \"" directory "\""))
17457 (insert "\n# Platform : " vhdl-compiler
17458 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17459 (user-login-name) "\n")
17460 ;; insert compile and option variable settings
17461 (insert "\n\n# Define compilation command and options\n"
17462 "\nCOMPILE = " (nth 0 compiler)
17463 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
17464 (if (equal vhdl-compile-post-command "") ""
17465 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
17466 "\n")
17467 ;; insert library paths
17468 (setq library-directory
17469 (directory-file-name
17470 (if (file-name-absolute-p library-directory)
17471 library-directory
17472 (file-relative-name
17473 (expand-file-name library-directory directory)
17474 compile-directory))))
17475 (insert "\n\n# Define library paths\n"
17476 "\nLIBRARY-" work-library " = " library-directory "\n")
17477 (unless mapping-exist
17478 (insert "LIBRARY-" work-library "-make = " "$(LIBRARY-" work-library
17479 ")/make" "\n"))
17480 ;; insert variable definitions for all library unit files
17481 (insert "\n\n# Define library unit files\n")
17482 (setq tmp-list unit-list)
17483 (while unit-list
17484 (insert "\nUNIT-" work-library "-" (caar unit-list)
17485 " = \\\n\t$(LIBRARY-" work-library
17486 (if mapping-exist "" "-make") ")/" (cdar unit-list))
17487 (setq unit-list (cdr unit-list)))
17488 ;; insert variable definition for list of all library unit files
17489 (insert "\n\n\n# Define list of all library unit files\n"
17490 "\nALL_UNITS =")
17491 (setq unit-list tmp-list)
17492 (while unit-list
17493 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17494 (setq unit-list (cdr unit-list)))
17495 (insert "\n")
17496 (setq unit-list tmp-list)
17497 ;; insert `make all' rule
17498 (insert "\n\n\n# Rule for compiling entire design\n"
17499 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17500 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17501 " \\\n\t\t$(ALL_UNITS)\n")
17502 ;; insert `make clean' rule
17503 (insert "\n\n# Rule for cleaning entire design\n"
17504 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17505 "\n\t-rm -f $(ALL_UNITS)\n")
17506 ;; insert `make library' rule
17507 (insert "\n\n# Rule for creating library directory\n"
17508 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17509 " \\\n\t\t$(LIBRARY-" work-library ")"
17510 (if mapping-exist ""
17511 (concat " \\\n\t\t$(LIBRARY-" work-library "-make)\n"))
17512 "\n"
17513 "\n$(LIBRARY-" work-library ") :"
17514 "\n\t"
17515 (vhdl-replace-string
17516 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17517 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17518 "\n")
17519 (unless mapping-exist
17520 (insert "\n$(LIBRARY-" work-library "-make) :"
17521 "\n\t"
17522 "mkdir -p $(LIBRARY-" work-library "-make)\n"))
17523 ;; insert '.PHONY' declaration
17524 (insert "\n\n.PHONY : "
17525 (nth 0 vhdl-makefile-default-targets) " "
17526 (nth 1 vhdl-makefile-default-targets) " "
17527 (nth 2 vhdl-makefile-default-targets) "\n")
17528 ;; insert rule for each library unit
17529 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17530 (while prim-list
17531 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17532 (setq subcomp-list
17533 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17534 (setq unit-key (caar prim-list)
17535 unit-name (or (nth 0 (vhdl-aget ent-alist unit-key))
17536 (nth 0 (vhdl-aget conf-alist unit-key))
17537 (nth 0 (vhdl-aget pack-alist unit-key))))
17538 (insert "\n" unit-key)
17539 (unless (equal unit-key unit-name)
17540 (insert " \\\n" unit-name))
17541 (insert " :"
17542 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
17543 (while subcomp-list
17544 (when (and (assoc (car subcomp-list) unit-list)
17545 (not (equal unit-key (car subcomp-list))))
17546 (insert " \\\n\t\t" (car subcomp-list)))
17547 (setq subcomp-list (cdr subcomp-list)))
17548 (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17549 (while second-list
17550 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17551 (setq second-list (cdr second-list)))
17552 (insert "\n")
17553 (setq prim-list (cdr prim-list)))
17554 ;; insert rule for each library unit file
17555 (insert "\n\n# Rules for compiling single library unit files\n")
17556 (while rule-alist
17557 (setq rule (car rule-alist))
17558 ;; get compiler options for this file
17559 (setq options
17560 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17561 ;; insert rule if file is supposed to be compiled
17562 (setq target-list (nth 1 rule)
17563 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17564 ;; insert targets
17565 (setq tmp-list target-list)
17566 (while target-list
17567 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17568 (if (cdr target-list) " \\" " :"))
17569 (setq target-list (cdr target-list)))
17570 (setq target-list tmp-list)
17571 ;; insert file name as first dependency
17572 (insert " \\\n\t\t" (nth 0 rule))
17573 ;; insert dependencies (except if also target or unit does not exist)
17574 (while depend-list
17575 (when (and (not (member (car depend-list) target-list))
17576 (assoc (car depend-list) unit-list))
17577 (insert " \\\n\t\t"
17578 "$(UNIT-" work-library "-" (car depend-list) ")"))
17579 (setq depend-list (cdr depend-list)))
17580 ;; insert compile command
17581 (if options
17582 (insert "\n\t$(COMPILE) "
17583 (if (eq options 'default) "$(OPTIONS)" options) " "
17584 (nth 0 rule)
17585 (if (equal vhdl-compile-post-command "") ""
17586 " $(POST-COMPILE)") "\n")
17587 (insert "\n"))
17588 (unless (and options mapping-exist)
17589 (setq tmp-list target-list)
17590 (while target-list
17591 (insert "\t@touch $(UNIT-" work-library "-" (car target-list) ")\n")
17592 (setq target-list (cdr target-list)))
17593 (setq target-list tmp-list))
17594 (setq rule-alist (cdr rule-alist)))
17596 (insert "\n\n### " makefile-name " ends here\n")
17597 ;; run Makefile generation hook
17598 (run-hooks 'vhdl-makefile-generation-hook)
17599 (message "Generating makefile \"%s\"...done" makefile-name)
17600 ;; save and close file
17601 (if (file-writable-p makefile-path-name)
17602 (progn (save-buffer)
17603 (kill-buffer (current-buffer))
17604 (set-buffer orig-buffer)
17605 (when (fboundp 'add-to-history)
17606 (add-to-history 'file-name-history makefile-path-name)))
17607 (vhdl-warning-when-idle
17608 (format "File not writable: \"%s\""
17609 (abbreviate-file-name makefile-path-name)))
17610 (switch-to-buffer (current-buffer))))))
17613 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17614 ;;; Bug reports
17615 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17616 ;; (using `reporter.el')
17618 (defconst vhdl-mode-help-address
17619 "Reto Zimmermann <reto@gnu.org>"
17620 "Address for VHDL Mode bug reports.")
17622 (defun vhdl-submit-bug-report ()
17623 "Submit via mail a bug report on VHDL Mode."
17624 (interactive)
17625 ;; load in reporter
17626 (and
17627 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17628 (let ((reporter-prompt-for-summary-p t))
17629 (reporter-submit-bug-report
17630 vhdl-mode-help-address
17631 (concat "VHDL Mode " vhdl-version)
17632 (list
17633 ;; report all important user options
17634 'vhdl-offsets-alist
17635 'vhdl-comment-only-line-offset
17636 'tab-width
17637 'vhdl-electric-mode
17638 'vhdl-stutter-mode
17639 'vhdl-indent-tabs-mode
17640 'vhdl-project-alist
17641 'vhdl-project
17642 'vhdl-project-file-name
17643 'vhdl-project-auto-load
17644 'vhdl-project-sort
17645 'vhdl-compiler-alist
17646 'vhdl-compiler
17647 'vhdl-compile-use-local-error-regexp
17648 'vhdl-makefile-default-targets
17649 'vhdl-makefile-generation-hook
17650 'vhdl-default-library
17651 'vhdl-standard
17652 'vhdl-basic-offset
17653 'vhdl-upper-case-keywords
17654 'vhdl-upper-case-types
17655 'vhdl-upper-case-attributes
17656 'vhdl-upper-case-enum-values
17657 'vhdl-upper-case-constants
17658 'vhdl-use-direct-instantiation
17659 'vhdl-array-index-record-field-in-sensitivity-list
17660 'vhdl-compose-configuration-name
17661 'vhdl-entity-file-name
17662 'vhdl-architecture-file-name
17663 'vhdl-configuration-file-name
17664 'vhdl-package-file-name
17665 'vhdl-file-name-case
17666 'vhdl-electric-keywords
17667 'vhdl-optional-labels
17668 'vhdl-insert-empty-lines
17669 'vhdl-argument-list-indent
17670 'vhdl-association-list-with-formals
17671 'vhdl-conditions-in-parenthesis
17672 'vhdl-sensitivity-list-all
17673 'vhdl-zero-string
17674 'vhdl-one-string
17675 'vhdl-file-header
17676 'vhdl-file-footer
17677 'vhdl-company-name
17678 'vhdl-copyright-string
17679 'vhdl-platform-spec
17680 'vhdl-date-format
17681 'vhdl-modify-date-prefix-string
17682 'vhdl-modify-date-on-saving
17683 'vhdl-reset-kind
17684 'vhdl-reset-active-high
17685 'vhdl-clock-rising-edge
17686 'vhdl-clock-edge-condition
17687 'vhdl-clock-name
17688 'vhdl-reset-name
17689 'vhdl-model-alist
17690 'vhdl-include-port-comments
17691 'vhdl-include-direction-comments
17692 'vhdl-include-type-comments
17693 'vhdl-include-group-comments
17694 'vhdl-actual-generic-name
17695 'vhdl-actual-port-name
17696 'vhdl-instance-name
17697 'vhdl-testbench-entity-name
17698 'vhdl-testbench-architecture-name
17699 'vhdl-testbench-configuration-name
17700 'vhdl-testbench-dut-name
17701 'vhdl-testbench-include-header
17702 'vhdl-testbench-declarations
17703 'vhdl-testbench-statements
17704 'vhdl-testbench-initialize-signals
17705 'vhdl-testbench-include-library
17706 'vhdl-testbench-include-configuration
17707 'vhdl-testbench-create-files
17708 'vhdl-testbench-entity-file-name
17709 'vhdl-testbench-architecture-file-name
17710 'vhdl-compose-create-files
17711 'vhdl-compose-configuration-create-file
17712 'vhdl-compose-configuration-hierarchical
17713 'vhdl-compose-configuration-use-subconfiguration
17714 'vhdl-compose-include-header
17715 'vhdl-compose-architecture-name
17716 'vhdl-components-package-name
17717 'vhdl-use-components-package
17718 'vhdl-self-insert-comments
17719 'vhdl-prompt-for-comments
17720 'vhdl-inline-comment-column
17721 'vhdl-end-comment-column
17722 'vhdl-auto-align
17723 'vhdl-align-groups
17724 'vhdl-align-group-separate
17725 'vhdl-align-same-indent
17726 'vhdl-highlight-keywords
17727 'vhdl-highlight-names
17728 'vhdl-highlight-special-words
17729 'vhdl-highlight-forbidden-words
17730 'vhdl-highlight-verilog-keywords
17731 'vhdl-highlight-translate-off
17732 'vhdl-highlight-case-sensitive
17733 'vhdl-special-syntax-alist
17734 'vhdl-forbidden-words
17735 'vhdl-forbidden-syntax
17736 'vhdl-directive-keywords
17737 'vhdl-speedbar-auto-open
17738 'vhdl-speedbar-display-mode
17739 'vhdl-speedbar-scan-limit
17740 'vhdl-speedbar-jump-to-unit
17741 'vhdl-speedbar-update-on-saving
17742 'vhdl-speedbar-save-cache
17743 'vhdl-speedbar-cache-file-name
17744 'vhdl-index-menu
17745 'vhdl-source-file-menu
17746 'vhdl-hideshow-menu
17747 'vhdl-hide-all-init
17748 'vhdl-print-two-column
17749 'vhdl-print-customize-faces
17750 'vhdl-intelligent-tab
17751 'vhdl-indent-syntax-based
17752 'vhdl-indent-comment-like-next-code-line
17753 'vhdl-word-completion-case-sensitive
17754 'vhdl-word-completion-in-minibuffer
17755 'vhdl-underscore-is-part-of-word
17756 'vhdl-mode-hook)
17757 (function
17758 (lambda ()
17759 (insert
17760 (if vhdl-special-indent-hook
17761 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17762 "vhdl-special-indent-hook is set to '"
17763 (format "%s" vhdl-special-indent-hook)
17764 ".\nPerhaps this is your problem?\n"
17765 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17766 "\n"))))
17768 "Hi Reto,"))))
17771 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17772 ;;; Documentation
17773 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17775 (defconst vhdl-doc-release-notes nil
17777 Release Notes for VHDL Mode 3.37
17778 ================================
17780 - Added support for VHDL'08:
17781 - New keywords, types, functions, attributes, operators, packages
17782 - Context declaration
17783 - Block comments
17784 - Directives
17785 - `all' keyword in sensitivity list
17788 Release Notes for VHDL Mode 3.34
17789 ================================
17791 - Added support for GNU Emacs 22/23/24:
17792 - Compilation error parsing fixed for new `compile.el' package.
17794 - Port translation: Derive actual generic name from formal generic name.
17796 - New user options:
17797 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17800 Release Notes for VHDL Mode 3.33
17801 ================================
17803 New Features
17804 ------------
17806 CONFIGURATION DECLARATION GENERATION:
17807 - Automatic generation of a configuration declaration for a design.
17808 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17811 Key Bindings
17812 ------------
17814 For Emacs compliance the following key bindings have been changed:
17816 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17817 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17818 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17819 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17822 User Options
17823 ------------
17825 `vhdl-configuration-file-name': (new)
17826 Specify how the configuration file name is obtained.
17827 `vhdl-compose-configuration-name': (new)
17828 Specify how the configuration name is obtained.
17829 `vhdl-compose-configuration-create-file': (new)
17830 Specify whether a new file should be created for a configuration.
17831 `vhdl-compose-configuration-hierarchical': (new)
17832 Specify whether hierarchical configurations should be created.
17833 `vhdl-compose-configuration-use-subconfiguration': (new)
17834 Specify whether subconfigurations should be used inside configurations.
17835 `vhdl-makefile-default-targets': (new)
17836 Customize names of Makefile default targets.
17837 `vhdl-indent-comment-like-next-code-line': (new)
17838 Specify whether comment lines are indented like following code line.
17839 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17840 Specify whether to include array indices / record fields in sensitivity list.
17844 (defconst vhdl-doc-keywords nil
17846 Reserved words in VHDL
17847 ----------------------
17849 VHDL'08 (IEEE Std 1076-2008):
17850 `vhdl-08-keywords' : keywords
17851 `vhdl-08-types' : standardized types
17852 `vhdl-08-attributes' : standardized attributes
17853 `vhdl-08-functions' : standardized functions
17854 `vhdl-08-packages' : standardized packages and libraries
17856 VHDL'93/02 (IEEE Std 1076-1993/2002):
17857 `vhdl-02-keywords' : keywords
17858 `vhdl-02-types' : standardized types
17859 `vhdl-02-attributes' : standardized attributes
17860 `vhdl-02-enum-values' : standardized enumeration values
17861 `vhdl-02-functions' : standardized functions
17862 `vhdl-02-packages' : standardized packages and libraries
17864 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17865 `vhdl-ams-keywords' : keywords
17866 `vhdl-ams-types' : standardized types
17867 `vhdl-ams-attributes' : standardized attributes
17868 `vhdl-ams-enum-values' : standardized enumeration values
17869 `vhdl-ams-constants' : standardized constants
17870 `vhdl-ams-functions' : standardized functions
17872 Math Packages (IEEE Std 1076.2):
17873 `vhdl-math-types' : standardized types
17874 `vhdl-math-constants' : standardized constants
17875 `vhdl-math-functions' : standardized functions
17876 `vhdl-math-packages' : standardized packages
17878 Forbidden words:
17879 `vhdl-verilog-keywords' : Verilog reserved words
17881 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17884 (defconst vhdl-doc-coding-style nil
17886 For VHDL coding style and naming convention guidelines, see the following
17887 references:
17889 [1] Ben Cohen.
17890 \"VHDL Coding Styles and Methodologies\".
17891 Kluwer Academic Publishers, 1999.
17892 http://members.aol.com/vhdlcohen/vhdl/
17894 [2] Michael Keating and Pierre Bricaud.
17895 \"Reuse Methodology Manual, Second Edition\".
17896 Kluwer Academic Publishers, 1999.
17897 http://www.openmore.com/openmore/rmm2.html
17899 [3] European Space Agency.
17900 \"VHDL Modelling Guidelines\".
17901 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17903 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17904 to visually support naming conventions.")
17907 (defun vhdl-version ()
17908 "Echo the current version of VHDL Mode in the minibuffer."
17909 (interactive)
17910 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17911 (vhdl-keep-region-active))
17913 (defun vhdl-doc-variable (variable)
17914 "Display VARIABLE's documentation in *Help* buffer."
17915 (interactive)
17916 (unless (featurep 'xemacs)
17917 (help-setup-xref (list #'vhdl-doc-variable variable)
17918 (called-interactively-p 'interactive)))
17919 (with-output-to-temp-buffer
17920 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17921 (princ (documentation-property variable 'variable-documentation))
17922 (with-current-buffer standard-output
17923 (help-mode))
17924 (help-print-return-message)))
17926 (defun vhdl-doc-mode ()
17927 "Display VHDL Mode documentation in *Help* buffer."
17928 (interactive)
17929 (unless (featurep 'xemacs)
17930 (help-setup-xref (list #'vhdl-doc-mode)
17931 (called-interactively-p 'interactive)))
17932 (with-output-to-temp-buffer
17933 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17934 (princ mode-name)
17935 (princ " mode:\n")
17936 (princ (documentation 'vhdl-mode))
17937 (with-current-buffer standard-output
17938 (help-mode))
17939 (help-print-return-message)))
17942 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17944 (provide 'vhdl-mode)
17946 ;;; vhdl-mode.el ends here