Fix a cacheing bug, which led to inordinately slow c-beginning-of-defun.
[emacs.git] / lisp / progmodes / vhdl-mode.el
blob27ce9fb1b30822fab9dae29159d80160f86ec061
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2016 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.37.1"
17 "VHDL Mode version number.")
19 (defconst vhdl-time-stamp "2015-01-15"
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 ;; Emacs 21+ handling
130 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
131 "Non-nil if GNU Emacs 21, 22, ... is used.")
132 ;; Emacs 22+ handling
133 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
134 "Non-nil if GNU Emacs 22, ... is used.")
136 (defvar compilation-file-regexp-alist)
137 (defvar conf-alist)
138 (defvar conf-entry)
139 (defvar conf-key)
140 (defvar ent-alist)
141 (defvar itimer-version)
142 (defvar lazy-lock-defer-contextually)
143 (defvar lazy-lock-defer-on-scrolling)
144 (defvar lazy-lock-defer-on-the-fly)
145 (defvar speedbar-attached-frame)
148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149 ;;; Variables
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;; help function for user options
153 (defun vhdl-custom-set (variable value &rest functions)
154 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
155 (if (fboundp 'custom-set-default)
156 (custom-set-default variable value)
157 (set-default variable value))
158 (while functions
159 (when (fboundp (car functions)) (funcall (car functions)))
160 (setq functions (cdr functions))))
162 (defun vhdl-widget-directory-validate (widget)
163 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
164 '/' or is empty)."
165 (let ((val (widget-value widget)))
166 (unless (string-match "^\\(\\|.*/\\)$" val)
167 (widget-put widget :error "Invalid directory entry: must end with `/'")
168 widget)))
170 ;; help string for user options
171 (defconst vhdl-name-doc-string "
173 FROM REGEXP is a regular expression matching the original name:
174 \".*\" matches the entire string
175 \"\\(...\\)\" matches a substring
176 TO STRING specifies the string to be inserted as new name:
177 \"\\&\" means substitute entire matched text
178 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
179 Examples:
180 \".*\" \"\\&\" inserts original string
181 \".*\" \"\\&_i\" attaches \"_i\" to original string
182 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
183 \".*\" \"foo\" inserts constant string \"foo\"
184 \".*\" \"\" inserts empty string")
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ;; User variables (customization options)
189 (defgroup vhdl nil
190 "Customizations for VHDL Mode."
191 :prefix "vhdl-"
192 :group 'languages
193 ; :version "21.2" ; comment out for XEmacs
196 (defgroup vhdl-mode nil
197 "Customizations for modes."
198 :group 'vhdl)
200 (defcustom vhdl-indent-tabs-mode nil
201 "Non-nil means indentation can insert tabs.
202 Overrides local variable `indent-tabs-mode'."
203 :type 'boolean
204 :group 'vhdl-mode)
207 (defgroup vhdl-compile nil
208 "Customizations for compilation."
209 :group 'vhdl)
211 (defcustom vhdl-compiler-alist
213 ;; 60: docal <= false;
214 ;; ^^^^^
215 ;; [Error] Assignment error: variable is illegal target of signal assignment
216 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
217 nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
218 ("^\\s-+\\([0-9]+\\):\\s-+" nil 1 nil) ("^Compiling file \\(.+\\)" 1)
219 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
220 "PACK/\\1.vif" "BODY/\\1.vif" upcase))
221 ;; Aldec
222 ;; COMP96 ERROR COMP96_0018: "Identifier expected." "test.vhd" 66 3
223 ("Aldec" "vcom" "-work \\1" "make" "-f \\1"
224 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
225 ("^.* ERROR [^:]+: \".*\" \"\\([^ \t\n]+\\)\" \\([0-9]+\\) \\([0-9]+\\)" 1 2 3) ("" 0)
226 nil)
227 ;; Cadence Leapfrog: cv -file test.vhd
228 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
229 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
230 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
231 ("^duluth: \\*E,[0-9]+ (\\([^ \t\n]+\\),\\([0-9]+\\)):" 1 2 nil) ("" 0)
232 ("\\1/entity" "\\2/\\1" "\\1/configuration"
233 "\\1/package" "\\1/body" downcase))
234 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
235 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
236 ;; (PLL_400X_TOP) is not declared [10.3].
237 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
238 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
239 ("^ncvhdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
240 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
241 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
242 ;; ghdl vhdl
243 ;; ghdl -a bad_counter.vhdl
244 ;; bad_counter.vhdl:13:14: operator "=" is overloaded
245 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
246 nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
247 ("^ghdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
248 ("\\1/entity" "\\2/\\1" "\\1/configuration"
249 "\\1/package" "\\1/body" downcase))
250 ;; IBM Compiler
251 ;; 00 COACHDL* | [CCHDL-1]: File: adder.vhd, line.column: 120.6
252 ("IBM Compiler" "g2tvc" "-src" "precomp" "\\1"
253 nil "mkdir \\1" "./" "work/" "Makefile" "ibm"
254 ("^[0-9]+ COACHDL.*: File: \\([^ \t\n]+\\), *line.column: \\([0-9]+\\).\\([0-9]+\\)" 1 2 3) (" " 0)
255 nil)
256 ;; Ikos Voyager: analyze test.vhd
257 ;; analyze test.vhd
258 ;; E L4/C5: this library unit is inaccessible
259 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
260 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
261 ("^E L\\([0-9]+\\)/C\\([0-9]+\\):" nil 1 2)
262 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
263 nil)
264 ;; ModelSim, Model Technology: vcom test.vhd
265 ;; ERROR: test.vhd(14): Unknown identifier: positiv
266 ;; WARNING[2]: test.vhd(85): Possible infinite loop
267 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
268 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
269 ;; ** Error: counter_rtl.vhd(18): Nonresolved signal 'hallo' has multiple sources.
270 ;; Drivers:
271 ;; counter_rtl.vhd(27):Conditional signal assignment line__27
272 ;; counter_rtl.vhd(29):Conditional signal assignment line__29
273 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
274 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
275 ("\\(ERROR:\\|WARNING\\[[0-9]+\\]:\\|\\*\\* Error:\\|\\*\\* Warning: \\[[0-9]+\\]\\| +\\) \\([^ ]+\\)(\\([0-9]+\\)):" 2 3 nil)
276 ("" 0)
277 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
278 "\\1/_primary.dat" "\\1/body.dat" downcase))
279 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
280 ;; test.vhd:34: error message
281 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
282 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
283 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
284 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
285 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
286 ;; Quartus compiler
287 ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
288 ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
289 ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
290 ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
291 ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
292 ("Quartus" "make" "-work \\1" "make" "-f \\1"
293 nil "mkdir \\1" "./" "work/" "Makefile" "quartus"
294 ("^\\(Error\\|Warning\\): .* \\([^ \t\n]+\\)(\\([0-9]+\\))" 2 3 nil) ("" 0)
295 nil)
296 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
297 ;; ERROR: test.vhd(24): near "dnd": expecting: END
298 ;; WARNING[4]: test.vhd(30): A space is required between ...
299 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
300 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
301 ("^\\(ERROR\\|WARNING\\)[^:]*: \\([^ \t\n]+\\)(\\([0-9]+\\)):" 2 3 nil) ("" 0)
302 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
303 "\\1/_primary.dat" "\\1/body.dat" downcase))
304 ;; Savant: scram -publish-cc test.vhd
305 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
306 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
307 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
308 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
309 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
310 "\\1_config.vhdl" "\\1_package.vhdl"
311 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
312 ;; Simili: vhdlp -work test.vhd
313 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
314 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
315 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
316 ("^\\(Error\\|Warning\\): \\w+: \\([^ \t\n]+\\): (line \\([0-9]+\\)): " 2 3 nil) ("" 0)
317 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
318 "\\1/prim.var" "\\1/_body.var" downcase))
319 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
320 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
321 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
322 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
323 ("^ *ERROR\\[[0-9]+]::File \\([^ \t\n]+\\) Line \\([0-9]+\\):" 1 2 nil) ("" 0)
324 nil)
325 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
326 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
327 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
328 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
329 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
330 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
331 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
332 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
333 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
334 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
335 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
336 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
337 ;; Synplify:
338 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
339 ("Synplify" "n/a" "n/a" "make" "-f \\1"
340 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
341 ("^@[EWN]:\"\\([^ \t\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
342 nil)
343 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
344 ;; Compiling "test.vhd" line 1...
345 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
346 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
347 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
348 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
349 ("^ *Compiling \"\\(.+\\)\" " 1)
350 nil)
351 ;; VeriBest: vc vhdl test.vhd
352 ;; (no file name printed out!)
353 ;; 32: Z <= A and BitA ;
354 ;; ^^^^
355 ;; [Error] Name BITA is unknown
356 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
357 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
358 ("^ +\\([0-9]+\\): +[^ ]" nil 1 nil) ("" 0)
359 nil)
360 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
361 ;; Compiling "test.vhd" line 1...
362 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
363 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
364 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
365 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
366 ("^ *Compiling \"\\(.+\\)\" " 1)
367 nil)
368 ;; Xilinx XST:
369 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
370 ("Xilinx XST" "xflow" "" "make" "-f \\1"
371 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
372 ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \t\n]+\\)\" Line \\([0-9]+\\)\\." 1 2 nil) ("" 0)
373 nil)
375 "List of available VHDL compilers and their properties.
376 Each list entry specifies the following items for a compiler:
377 Compiler:
378 Compiler name : name used in option `vhdl-compiler' to choose compiler
379 Compile command : command used for source file compilation
380 Compile options : compile options (\"\\1\" inserts library name)
381 Make command : command used for compilation using a Makefile
382 Make options : make options (\"\\1\" inserts Makefile name)
383 Generate Makefile: use built-in function or command to generate a Makefile
384 (\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
385 Library command : command to create library directory (\"\\1\" inserts
386 library directory, \"\\2\" inserts library name)
387 Compile directory: where compilation is run and the Makefile is placed
388 Library directory: directory of default library
389 Makefile name : name of Makefile (default is \"Makefile\")
390 ID string : compiler identification string (see `vhdl-project-alist')
391 Error message:
392 Regexp : regular expression to match error messages (*)
393 File subexp index: index of subexpression that matches the file name
394 Line subexp index: index of subexpression that matches the line number
395 Column subexp idx: index of subexpression that matches the column number
396 File message:
397 Regexp : regular expression to match a file name message
398 File subexp index: index of subexpression that matches the file name
399 Unit-to-file name mapping: mapping of library unit names to names of files
400 generated by the compiler (used for Makefile generation)
401 To string : string a name is mapped to (\"\\1\" inserts the unit name,
402 \"\\2\" inserts the entity name for architectures,
403 \"\\3\" inserts the library name)
404 Case adjustment : adjust case of inserted unit names
406 \(*) The regular expression must match the error message starting from the
407 beginning of the line (but not necessarily to the end of the line).
409 Compile options allows insertion of the library name (see `vhdl-project-alist')
410 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
412 For Makefile generation, the built-in function can be used (requires
413 specification of the unit-to-file name mapping). Alternatively, an
414 external command can be specified. Work directory allows specification of
415 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
416 used for Makefile generation). To use another library name than \"work\",
417 customize `vhdl-project-alist'. The library command is inserted in Makefiles
418 to automatically create the library directory if not existent.
420 Compile options, compile directory, library directory, and Makefile name are
421 overwritten by the project settings if a project is defined (see
422 `vhdl-project-alist'). Directory paths are relative to the source file
423 directory.
425 Some compilers do not include the file name in the error message, but print
426 out a file name message in advance. In this case, set \"File Subexp Index\"
427 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
428 If no file name at all is printed out, set both \"File Message\" entries to 0
429 \(a default file name message will be printed out instead, does not work in
430 XEmacs).
432 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
433 assigning its name to option `vhdl-compiler'.
435 Please send any missing or erroneous compiler properties to the maintainer for
436 updating.
438 NOTE: Activate new error and file message regexps and reflect the new setting
439 in the choice list of option `vhdl-compiler' by restarting Emacs."
440 :type '(repeat
441 (list :tag "Compiler" :indent 2
442 (string :tag "Compiler name ")
443 (string :tag "Compile command ")
444 (string :tag "Compile options " "-work \\1")
445 (string :tag "Make command " "make")
446 (string :tag "Make options " "-f \\1")
447 (choice :tag "Generate Makefile "
448 (const :tag "Built-in function" nil)
449 (string :tag "Command" "vmake \\2 > \\1"))
450 (string :tag "Library command " "mkdir \\1")
451 (directory :tag "Compile directory "
452 :validate vhdl-widget-directory-validate "./")
453 (directory :tag "Library directory "
454 :validate vhdl-widget-directory-validate "work/")
455 (file :tag "Makefile name " "Makefile")
456 (string :tag "ID string ")
457 (list :tag "Error message" :indent 4
458 (regexp :tag "Regexp ")
459 (choice :tag "File subexp "
460 (integer :tag "Index")
461 (const :tag "No file name" nil))
462 (integer :tag "Line subexp index")
463 (choice :tag "Column subexp "
464 (integer :tag "Index")
465 (const :tag "No column number" nil)))
466 (list :tag "File message" :indent 4
467 (regexp :tag "Regexp ")
468 (integer :tag "File subexp index"))
469 (choice :tag "Unit-to-file name mapping"
470 :format "%t: %[Value Menu%] %v\n"
471 (const :tag "Not defined" nil)
472 (list :tag "To string" :indent 4
473 (string :tag "Entity " "\\1.vhd")
474 (string :tag "Architecture " "\\2_\\1.vhd")
475 (string :tag "Configuration " "\\1.vhd")
476 (string :tag "Package " "\\1.vhd")
477 (string :tag "Package Body " "\\1_body.vhd")
478 (choice :tag "Case adjustment "
479 (const :tag "None" identity)
480 (const :tag "Upcase" upcase)
481 (const :tag "Downcase" downcase))))))
482 :set (lambda (variable value)
483 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
484 :version "24.4"
485 :group 'vhdl-compile)
487 (defcustom vhdl-compiler "GHDL"
488 "Specifies the VHDL compiler to be used for syntax analysis.
489 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
490 :type (let ((alist vhdl-compiler-alist) list)
491 (while alist
492 (push (list 'const (caar alist)) list)
493 (setq alist (cdr alist)))
494 (append '(choice) (nreverse list)))
495 :group 'vhdl-compile)
497 (defcustom vhdl-compile-use-local-error-regexp nil
498 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
499 In this case, only error message regexps for VHDL compilers are active if
500 compilation is started from a VHDL buffer. Otherwise, the error message
501 regexps are appended to the predefined global regexps, and all regexps are
502 active all the time. Note that by doing that, the predefined global regexps
503 might result in erroneous parsing of error messages for some VHDL compilers.
505 NOTE: Activate the new setting by restarting Emacs."
506 :version "25.1" ; t -> nil
507 :type 'boolean
508 :group 'vhdl-compile)
510 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
511 "List of default target names in Makefiles.
512 Automatically generated Makefiles include three default targets to compile
513 the entire design, clean the entire design and to create the design library.
514 This option allows you to change the names of these targets to avoid conflicts
515 with other user Makefiles."
516 :type '(list (string :tag "Compile entire design")
517 (string :tag "Clean entire design ")
518 (string :tag "Create design library"))
519 :version "24.3"
520 :group 'vhdl-compile)
522 (defcustom vhdl-makefile-generation-hook nil
523 "Functions to run at the end of Makefile generation.
524 Allows you to insert user specific parts into a Makefile.
526 Example:
527 (lambda nil
528 (re-search-backward \"^# Rule for compiling entire design\")
529 (insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
530 :type 'hook
531 :group 'vhdl-compile)
533 (defcustom vhdl-default-library "work"
534 "Name of default library.
535 Is overwritten by project settings if a project is active."
536 :type 'string
537 :group 'vhdl-compile)
540 (defgroup vhdl-project nil
541 "Customizations for projects."
542 :group 'vhdl)
544 (defcustom vhdl-project-alist
545 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
546 "~/example1/" ("src/system/" "src/components/") ""
547 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
548 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
549 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
550 ("Example 2" "Individual source files, multiple compilers in different directories"
551 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
552 nil "\\1/" "work" "\\1/work/" "Makefile" "")
553 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
554 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
555 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
556 -------------------------------------------------------------------------------
557 -- This is a multi-line project description
558 -- that can be used as a project dependent part of the file header.
560 "List of projects and their properties.
561 Name : name used in option `vhdl-project' to choose project
562 Title : title of project (single-line string)
563 Default directory: default project directory (absolute path)
564 Sources : a) source files : path + \"/\" + file name
565 b) directory : path + \"/\"
566 c) directory tree: \"-r \" + path + \"/\"
567 Exclude regexp : matches file/directory names to be excluded as sources
568 Compile options : project-specific options for each compiler
569 Compiler name : name of compiler for which these options are valid
570 Compile options: project-specific compiler options
571 (\"\\1\" inserts library name, \"\\2\" default options)
572 Make options: project-specific make options
573 (\"\\1\" inserts Makefile name, \"\\2\" default options)
574 Exceptions : file-specific exceptions
575 File name regexp: matches file names for which exceptions are valid
576 - Options : file-specific compiler options string
577 (\"\\1\" inserts library name, \"\\2\" default options,
578 \"\\3\" project-specific options)
579 - Do not compile: do not compile this file (in Makefile)
580 Compile directory: where compilation is run and the Makefile is placed
581 (\"\\1\" inserts compiler ID string)
582 Library name : name of library (default is \"work\")
583 Library directory: path to library (\"\\1\" inserts compiler ID string)
584 Makefile name : name of Makefile
585 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
586 Description : description of project (multi-line string)
588 Project title and description are used to insert into the file header (see
589 option `vhdl-file-header').
591 The default directory must have an absolute path (use `M-TAB' for completion).
592 All other paths can be absolute or relative to the default directory. All
593 paths must end with `/'.
595 The design units found in the sources (files and directories) are shown in the
596 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
597 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
598 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
599 specified, the default directory is taken as source directory. Otherwise,
600 the default directory is only taken as source directory if there is a sources
601 entry with the empty string or \"./\". Exclude regexp allows you to filter
602 out specific file and directory names from the list of sources (e.g. CVS
603 directories).
605 Files are compiled in the compile directory. Makefiles are also placed into
606 the compile directory. Library directory specifies which directory the
607 compiler compiles into (used to generate the Makefile).
609 Since different compile/library directories and Makefiles may exist for
610 different compilers within one project, these paths and names allow the
611 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
612 Compile options, compile directory, library directory, and Makefile name
613 overwrite the settings of the current compiler.
615 File-specific compiler options (highest priority) overwrite project-specific
616 options which overwrite default options (lowest priority). Lower priority
617 options can be inserted in higher priority options. This allows you to reuse
618 default options (e.g. \"-file\") in project- or file-specific options (e.g.
619 \"-93 -file\").
621 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
622 by restarting Emacs."
623 :type `(repeat
624 (list :tag "Project" :indent 2
625 (string :tag "Name ")
626 (string :tag "Title ")
627 (directory :tag "Default directory"
628 :validate vhdl-widget-directory-validate
629 ,(abbreviate-file-name default-directory))
630 (repeat :tag "Sources " :indent 4
631 (directory :format " %v" "./"))
632 (regexp :tag "Exclude regexp ")
633 (repeat
634 :tag "Compile options " :indent 4
635 (list :tag "Compiler" :indent 6
636 ,(let ((alist vhdl-compiler-alist) list)
637 (while alist
638 (push (list 'const (caar alist)) list)
639 (setq alist (cdr alist)))
640 (append '(choice :tag "Compiler name")
641 (nreverse list)))
642 (string :tag "Compile options" "\\2")
643 (string :tag "Make options " "\\2")
644 (repeat
645 :tag "Exceptions " :indent 8
646 (cons :format "%v"
647 (regexp :tag "File name regexp ")
648 (choice :format "%[Value Menu%] %v"
649 (string :tag "Options" "\\3")
650 (const :tag "Do not compile" nil))))))
651 (directory :tag "Compile directory"
652 :validate vhdl-widget-directory-validate "./")
653 (string :tag "Library name " "work")
654 (directory :tag "Library directory"
655 :validate vhdl-widget-directory-validate "work/")
656 (file :tag "Makefile name " "Makefile")
657 (string :tag "Description: (type `C-j' for newline)"
658 :format "%t\n%v\n")))
659 :set (lambda (variable value)
660 (vhdl-custom-set variable value
661 'vhdl-update-mode-menu
662 'vhdl-speedbar-refresh))
663 :group 'vhdl-project)
665 (defcustom vhdl-project nil
666 "Specifies the default for the current project.
667 Select a project name from the ones defined in option `vhdl-project-alist'.
668 Is used to determine the project title and description to be inserted in file
669 headers and the source files/directories to be scanned in the hierarchy
670 browser. The current project can also be changed temporarily in the menu."
671 :type (let ((alist vhdl-project-alist) list)
672 (while alist
673 (push (list 'const (caar alist)) list)
674 (setq alist (cdr alist)))
675 (append '(choice (const :tag "None" nil) (const :tag "--"))
676 (nreverse list)))
677 :group 'vhdl-project)
679 (defcustom vhdl-project-file-name '("\\1.prj")
680 "List of file names/paths for importing/exporting project setups.
681 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
682 replaced by the user name (allows you to have user-specific project setups).
683 The first entry is used as file name to import/export individual project
684 setups. All entries are used to automatically import project setups at
685 startup (see option `vhdl-project-auto-load'). Projects loaded from the
686 first entry are automatically made current. Hint: specify local project
687 setups in first entry, global setups in following entries; loading a local
688 project setup will make it current, while loading the global setups
689 is done without changing the current project.
690 Names can also have an absolute path (i.e. project setups can be stored
691 in global directories)."
692 :type '(repeat (string :tag "File name" "\\1.prj"))
693 :group 'vhdl-project)
695 (defcustom vhdl-project-auto-load '(startup)
696 "Automatically load project setups from files.
697 All project setup files that match the file names specified in option
698 `vhdl-project-file-name' are automatically loaded. The project of the
699 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
700 entry is activated.
701 A project setup file can be obtained by exporting a project (see menu).
702 At startup: project setup file is loaded at Emacs startup"
703 :type '(set (const :tag "At startup" startup))
704 :group 'vhdl-project)
706 (defcustom vhdl-project-sort t
707 "Non-nil means projects are displayed in alphabetical order."
708 :type 'boolean
709 :group 'vhdl-project)
712 (defgroup vhdl-style nil
713 "Customizations for coding styles."
714 :group 'vhdl
715 :group 'vhdl-template
716 :group 'vhdl-port
717 :group 'vhdl-compose)
719 (defcustom vhdl-standard '(93 nil)
720 "VHDL standards used.
721 Basic standard:
722 VHDL'87 : IEEE Std 1076-1987
723 VHDL'93/02 : IEEE Std 1076-1993/2002
724 VHDL'08 : IEEE Std 1076-2008
725 Additional standards:
726 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
727 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
729 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
730 \"Activate Options\"."
731 :type '(list (choice :tag "Basic standard"
732 (const :tag "VHDL'87" 87)
733 (const :tag "VHDL'93/02" 93)
734 (const :tag "VHDL'08" 08))
735 (set :tag "Additional standards" :indent 2
736 (const :tag "VHDL-AMS" ams)
737 (const :tag "Math packages" math)))
738 :set (lambda (variable value)
739 (vhdl-custom-set variable value
740 'vhdl-template-map-init
741 'vhdl-mode-abbrev-table-init
742 'vhdl-template-construct-alist-init
743 'vhdl-template-package-alist-init
744 'vhdl-update-mode-menu
745 'vhdl-words-init 'vhdl-font-lock-init))
746 :group 'vhdl-style)
748 (defcustom vhdl-basic-offset 2
749 "Amount of basic offset used for indentation.
750 This value is used by + and - symbols in `vhdl-offsets-alist'."
751 :type 'integer
752 :group 'vhdl-style)
754 (defcustom vhdl-upper-case-keywords nil
755 "Non-nil means convert keywords to upper case.
756 This is done when typed or expanded or by the fix case functions."
757 :type 'boolean
758 :set (lambda (variable value)
759 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
760 :group 'vhdl-style)
762 (defcustom vhdl-upper-case-types nil
763 "Non-nil means convert standardized types to upper case.
764 This is done when 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-attributes nil
771 "Non-nil means convert standardized attributes 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-enum-values nil
779 "Non-nil means convert standardized enumeration values 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-constants t
787 "Non-nil means convert standardized constants to upper case.
788 This is done when expanded."
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-use-direct-instantiation 'standard
795 "Non-nil means use VHDL'93 direct component instantiation.
796 Never : never
797 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
798 Always : always"
799 :type '(choice (const :tag "Never" never)
800 (const :tag "Standard" standard)
801 (const :tag "Always" always))
802 :group 'vhdl-style)
804 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
805 "Non-nil means include array indices / record fields in sensitivity list.
806 If a signal read in a process is a record field or pointed to by an array
807 index, the record field or array index is included with the record name in
808 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
809 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
810 :type 'boolean
811 :version "24.3"
812 :group 'vhdl-style)
814 (defgroup vhdl-naming nil
815 "Customizations for naming conventions."
816 :group 'vhdl)
818 (defcustom vhdl-entity-file-name '(".*" . "\\&")
819 (concat
820 "Specifies how the entity file name is obtained.
821 The entity file name can be obtained by modifying the entity name (e.g.
822 attaching or stripping off a substring). The file extension is automatically
823 taken from the file name of the current buffer."
824 vhdl-name-doc-string)
825 :type '(cons (regexp :tag "From regexp")
826 (string :tag "To string "))
827 :group 'vhdl-naming
828 :group 'vhdl-compose)
830 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
831 (concat
832 "Specifies how the architecture file name is obtained.
833 The architecture file name can be obtained by modifying the entity
834 and/or architecture name (e.g. attaching or stripping off a substring). The
835 file extension is automatically taken from the file name of the current
836 buffer. The string that is matched against the regexp is the concatenation
837 of the entity and the architecture name separated by a space. This gives
838 access to both names (see default setting as example)."
839 vhdl-name-doc-string)
840 :type '(cons (regexp :tag "From regexp")
841 (string :tag "To string "))
842 :group 'vhdl-naming
843 :group 'vhdl-compose)
845 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
846 (concat
847 "Specifies how the configuration file name is obtained.
848 The configuration file name can be obtained by modifying the configuration
849 name (e.g. attaching or stripping off a substring). The file extension is
850 automatically taken from the file name of the current buffer."
851 vhdl-name-doc-string)
852 :type '(cons (regexp :tag "From regexp")
853 (string :tag "To string "))
854 :group 'vhdl-naming
855 :group 'vhdl-compose)
857 (defcustom vhdl-package-file-name '(".*" . "\\&")
858 (concat
859 "Specifies how the package file name is obtained.
860 The package file name can be obtained by modifying the package name (e.g.
861 attaching or stripping off a substring). The file extension is automatically
862 taken from the file name of the current buffer. Package files can be created
863 in a different directory by prepending a relative or absolute path to the
864 file name."
865 vhdl-name-doc-string)
866 :type '(cons (regexp :tag "From regexp")
867 (string :tag "To string "))
868 :group 'vhdl-naming
869 :group 'vhdl-compose)
871 (defcustom vhdl-file-name-case 'identity
872 "Specifies how to change case for obtaining file names.
873 When deriving a file name from a VHDL unit name, case can be changed as
874 follows:
875 As Is: case is not changed (taken as is)
876 Lower Case: whole name is changed to lower case
877 Upper Case: whole name is changed to upper case
878 Capitalize: first letter of each word in name is capitalized"
879 :type '(choice (const :tag "As Is" identity)
880 (const :tag "Lower Case" downcase)
881 (const :tag "Upper Case" upcase)
882 (const :tag "Capitalize" capitalize))
883 :group 'vhdl-naming
884 :group 'vhdl-compose)
887 (defgroup vhdl-template nil
888 "Customizations for electrification."
889 :group 'vhdl)
891 (defcustom vhdl-electric-keywords '(vhdl user)
892 "Type of keywords for which electrification is enabled.
893 VHDL keywords: invoke built-in templates
894 User keywords: invoke user models (see option `vhdl-model-alist')"
895 :type '(set (const :tag "VHDL keywords" vhdl)
896 (const :tag "User model keywords" user))
897 :set (lambda (variable value)
898 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
899 :group 'vhdl-template)
901 (defcustom vhdl-optional-labels 'process
902 "Constructs for which labels are to be queried.
903 Template generators prompt for optional labels for:
904 None : no constructs
905 Processes only: processes only (also procedurals in VHDL-AMS)
906 All constructs: all constructs with optional labels and keyword END"
907 :type '(choice (const :tag "None" none)
908 (const :tag "Processes only" process)
909 (const :tag "All constructs" all))
910 :group 'vhdl-template)
912 (defcustom vhdl-insert-empty-lines 'unit
913 "Specifies whether to insert empty lines in some templates.
914 This improves readability of code. Empty lines are inserted in:
915 None : no constructs
916 Design units only: entities, architectures, configurations, packages only
917 All constructs : also all constructs with BEGIN...END parts
919 Replaces option `vhdl-additional-empty-lines'."
920 :type '(choice (const :tag "None" none)
921 (const :tag "Design units only" unit)
922 (const :tag "All constructs" all))
923 :group 'vhdl-template
924 :group 'vhdl-port
925 :group 'vhdl-compose)
927 (defcustom vhdl-argument-list-indent nil
928 "Non-nil means indent argument lists relative to opening parenthesis.
929 That is, argument, association, and port lists start on the same line as the
930 opening parenthesis and subsequent lines are indented accordingly.
931 Otherwise, lists start on a new line and are indented as normal code."
932 :type 'boolean
933 :group 'vhdl-template
934 :group 'vhdl-port
935 :group 'vhdl-compose)
937 (defcustom vhdl-association-list-with-formals t
938 "Non-nil means write association lists with formal parameters.
939 Templates prompt for formal and actual parameters (ports/generics).
940 When pasting component instantiations, formals are included.
941 If nil, only a list of actual parameters is entered."
942 :type 'boolean
943 :group 'vhdl-template
944 :group 'vhdl-port
945 :group 'vhdl-compose)
947 (defcustom vhdl-conditions-in-parenthesis nil
948 "Non-nil means place parenthesis around condition expressions."
949 :type 'boolean
950 :group 'vhdl-template)
952 (defcustom vhdl-sensitivity-list-all t
953 "Non-nil means use `all' keyword in sensitivity list."
954 :version "25.1"
955 :type 'boolean
956 :group 'vhdl-template)
958 (defcustom vhdl-zero-string "'0'"
959 "String to use for a logic zero."
960 :type 'string
961 :group 'vhdl-template)
963 (defcustom vhdl-one-string "'1'"
964 "String to use for a logic one."
965 :type 'string
966 :group 'vhdl-template)
969 (defgroup vhdl-header nil
970 "Customizations for file header."
971 :group 'vhdl-template
972 :group 'vhdl-compose)
974 (defcustom vhdl-file-header "\
975 -------------------------------------------------------------------------------
976 -- Title : <title string>
977 -- Project : <project>
978 -------------------------------------------------------------------------------
979 -- File : <filename>
980 -- Author : <author>
981 -- Company : <company>
982 -- Created : <date>
983 -- Last update: <date>
984 -- Platform : <platform>
985 -- Standard : <standard>
986 <projectdesc>-------------------------------------------------------------------------------
987 -- Description: <cursor>
988 <copyright>-------------------------------------------------------------------------------
989 -- Revisions :
990 -- Date Version Author Description
991 -- <date> 1.0 <login>\tCreated
992 -------------------------------------------------------------------------------
995 "String or file to insert as file header.
996 If the string specifies an existing file name, the contents of the file is
997 inserted, otherwise the string itself is inserted as file header.
998 Type `C-j' for newlines.
999 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
1000 if the header needs to be version controlled.
1002 The following keywords for template generation are supported:
1003 <filename> : replaced by the name of the buffer
1004 <author> : replaced by the user name and email address
1005 (`user-full-name',`mail-host-address', `user-mail-address')
1006 <authorfull> : replaced by the user full name (`user-full-name')
1007 <login> : replaced by user login name (`user-login-name')
1008 <company> : replaced by contents of option `vhdl-company-name'
1009 <date> : replaced by the current date
1010 <year> : replaced by the current year
1011 <project> : replaced by title of current project (`vhdl-project')
1012 <projectdesc> : replaced by description of current project (`vhdl-project')
1013 <copyright> : replaced by copyright string (`vhdl-copyright-string')
1014 <platform> : replaced by contents of option `vhdl-platform-spec'
1015 <standard> : replaced by the VHDL language standard(s) used
1016 <... string> : replaced by a queried string (\"...\" is the prompt word)
1017 <title string>: replaced by file title in automatically generated files
1018 <cursor> : final cursor position
1020 The (multi-line) project description <projectdesc> can be used as a project
1021 dependent part of the file header and can also contain the above keywords."
1022 :type 'string
1023 :group 'vhdl-header)
1025 (defcustom vhdl-file-footer ""
1026 "String or file to insert as file footer.
1027 If the string specifies an existing file name, the contents of the file is
1028 inserted, otherwise the string itself is inserted as file footer (i.e. at
1029 the end of the file).
1030 Type `C-j' for newlines.
1031 The same keywords as in option `vhdl-file-header' can be used."
1032 :type 'string
1033 :group 'vhdl-header)
1035 (defcustom vhdl-company-name ""
1036 "Name of company to insert in file header.
1037 See option `vhdl-file-header'."
1038 :type 'string
1039 :group 'vhdl-header)
1041 (defcustom vhdl-copyright-string "\
1042 -------------------------------------------------------------------------------
1043 -- Copyright (c) <year> <company>
1045 "Copyright string to insert in file header.
1046 Can be multi-line string (type `C-j' for newline) and contain other file
1047 header keywords (see option `vhdl-file-header')."
1048 :type 'string
1049 :group 'vhdl-header)
1051 (defcustom vhdl-platform-spec ""
1052 "Specification of VHDL platform to insert in file header.
1053 The platform specification should contain names and versions of the
1054 simulation and synthesis tools used.
1055 See option `vhdl-file-header'."
1056 :type 'string
1057 :group 'vhdl-header)
1059 (defcustom vhdl-date-format "%Y-%m-%d"
1060 "Specifies the date format to use in the header.
1061 This string is passed as argument to the command `format-time-string'.
1062 For more information on format strings, see the documentation for the
1063 `format-time-string' command (C-h f `format-time-string')."
1064 :type 'string
1065 :group 'vhdl-header)
1067 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1068 "Prefix string of modification date in VHDL file header.
1069 If actualization of the modification date is called (menu,
1070 `\\[vhdl-template-modify]'), this string is searched and the rest
1071 of the line replaced by the current date."
1072 :type 'string
1073 :group 'vhdl-header)
1075 (defcustom vhdl-modify-date-on-saving t
1076 "Non-nil means update the modification date when the buffer is saved.
1077 Calls function `\\[vhdl-template-modify]').
1079 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1080 \"Activate Options\"."
1081 :type 'boolean
1082 :group 'vhdl-header)
1085 (defgroup vhdl-sequential-process nil
1086 "Customizations for sequential processes."
1087 :group 'vhdl-template)
1089 (defcustom vhdl-reset-kind 'async
1090 "Specifies which kind of reset to use in sequential processes."
1091 :type '(choice (const :tag "None" none)
1092 (const :tag "Synchronous" sync)
1093 (const :tag "Asynchronous" async)
1094 (const :tag "Query" query))
1095 :group 'vhdl-sequential-process)
1097 (defcustom vhdl-reset-active-high nil
1098 "Non-nil means reset in sequential processes is active high.
1099 Otherwise, reset is active low."
1100 :type 'boolean
1101 :group 'vhdl-sequential-process)
1103 (defcustom vhdl-clock-rising-edge t
1104 "Non-nil means rising edge of clock triggers sequential processes.
1105 Otherwise, falling edge triggers."
1106 :type 'boolean
1107 :group 'vhdl-sequential-process)
1109 (defcustom vhdl-clock-edge-condition 'standard
1110 "Syntax of the clock edge condition.
1111 Standard: \"clk\\='event and clk = \\='1\\='\"
1112 Function: \"rising_edge(clk)\""
1113 :type '(choice (const :tag "Standard" standard)
1114 (const :tag "Function" function))
1115 :group 'vhdl-sequential-process)
1117 (defcustom vhdl-clock-name ""
1118 "Name of clock signal to use in templates."
1119 :type 'string
1120 :group 'vhdl-sequential-process)
1122 (defcustom vhdl-reset-name ""
1123 "Name of reset signal to use in templates."
1124 :type 'string
1125 :group 'vhdl-sequential-process)
1128 (defgroup vhdl-model nil
1129 "Customizations for user models."
1130 :group 'vhdl)
1132 (defcustom vhdl-model-alist
1133 '(("Example Model"
1134 "<label> : process (<clock>, <reset>)
1135 begin -- process <label>
1136 if <reset> = '0' then -- asynchronous reset (active low)
1137 <cursor>
1138 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1139 if <enable> = '1' then -- synchronous load
1141 end if;
1142 end if;
1143 end process <label>;"
1144 "e" ""))
1145 "List of user models.
1146 VHDL models (templates) can be specified by the user in this list. They can be
1147 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1148 electrification (i.e. overriding existing or creating new keywords, see
1149 option `vhdl-electric-keywords').
1150 Name : name of model (string of words and spaces)
1151 String : string or name of file to be inserted as model (newline: `C-j')
1152 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1153 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1154 Keyword : keyword to invoke model
1156 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1157 A prompt that appears several times is queried once and replaced throughout
1158 the model. Special prompts are:
1159 <clock> : name specified in `vhdl-clock-name' (if not empty)
1160 <reset> : name specified in `vhdl-reset-name' (if not empty)
1161 <cursor>: final cursor position
1162 File header prompts (see variable `vhdl-file-header') are automatically
1163 replaced, so that user models can also be used to insert different types of
1164 headers.
1166 If the string specifies an existing file name, the contents of the file is
1167 inserted, otherwise the string itself is inserted.
1168 The code within the models should be correctly indented.
1169 Type `C-j' for newlines.
1171 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1172 \"Activate Options\"."
1173 :type '(repeat (list :tag "Model" :indent 2
1174 (string :tag "Name ")
1175 (string :tag "String : (type `C-j' for newline)"
1176 :format "%t\n%v")
1177 (sexp :tag "Key binding" x)
1178 (string :tag "Keyword " :format "%t: %v\n")))
1179 :set (lambda (variable value)
1180 (vhdl-custom-set variable value
1181 'vhdl-model-map-init
1182 'vhdl-model-defun
1183 'vhdl-mode-abbrev-table-init
1184 'vhdl-update-mode-menu))
1185 :group 'vhdl-model)
1188 (defgroup vhdl-compose nil
1189 "Customizations for structural composition."
1190 :group 'vhdl)
1192 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1193 (concat
1194 "Specifies how the component architecture name is obtained.
1195 The component architecture name can be obtained by modifying the entity name
1196 \(e.g. attaching or stripping off a substring).
1197 If TO STRING is empty, the architecture name is queried."
1198 vhdl-name-doc-string)
1199 :type '(cons (regexp :tag "From regexp")
1200 (string :tag "To string "))
1201 :group 'vhdl-compose)
1203 (defcustom vhdl-compose-configuration-name
1204 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1205 (concat
1206 "Specifies how the configuration name is obtained.
1207 The configuration name can be obtained by modifying the entity and/or
1208 architecture name (e.g. attaching or stripping off a substring). The string
1209 that is matched against the regexp is the concatenation of the entity and the
1210 architecture name separated by a space. This gives access to both names (see
1211 default setting as example)."
1212 vhdl-name-doc-string)
1213 :type '(cons (regexp :tag "From regexp")
1214 (string :tag "To string "))
1215 :group 'vhdl-compose)
1217 (defcustom vhdl-components-package-name
1218 '((".*" . "\\&_components") . "components")
1219 (concat
1220 "Specifies how the name for the components package is obtained.
1221 The components package is a package containing all component declarations for
1222 the current design. Its name can be obtained by modifying the project name
1223 \(e.g. attaching or stripping off a substring). If no project is defined, the
1224 DIRECTORY entry is chosen."
1225 vhdl-name-doc-string)
1226 :type '(cons (cons :tag "Project" :indent 2
1227 (regexp :tag "From regexp")
1228 (string :tag "To string "))
1229 (string :tag "Directory:\n String "))
1230 :group 'vhdl-compose)
1232 (defcustom vhdl-use-components-package nil
1233 "Non-nil means use a separate components package for component declarations.
1234 Otherwise, component declarations are inserted and searched for in the
1235 architecture declarative parts."
1236 :type 'boolean
1237 :group 'vhdl-compose)
1239 (defcustom vhdl-compose-include-header t
1240 "Non-nil means include a header in automatically generated files."
1241 :type 'boolean
1242 :group 'vhdl-compose)
1244 (defcustom vhdl-compose-create-files 'single
1245 "Specifies whether new files should be created for the new component.
1246 The component's entity and architecture are inserted:
1247 None : in current buffer
1248 Single file : in new single file
1249 Separate files: in two separate files
1250 The file names are obtained from variables `vhdl-entity-file-name' and
1251 `vhdl-architecture-file-name'."
1252 :type '(choice (const :tag "None" none)
1253 (const :tag "Single file" single)
1254 (const :tag "Separate files" separate))
1255 :group 'vhdl-compose)
1257 (defcustom vhdl-compose-configuration-create-file nil
1258 "Specifies whether a new file should be created for the configuration.
1259 If non-nil, a new file is created for the configuration.
1260 The file name is obtained from variable `vhdl-configuration-file-name'."
1261 :type 'boolean
1262 :group 'vhdl-compose)
1264 (defcustom vhdl-compose-configuration-hierarchical t
1265 "Specifies whether hierarchical configurations should be created.
1266 If non-nil, automatically created configurations are hierarchical and include
1267 the whole hierarchy of subcomponents. Otherwise the configuration only
1268 includes one level of subcomponents."
1269 :type 'boolean
1270 :group 'vhdl-compose)
1272 (defcustom vhdl-compose-configuration-use-subconfiguration t
1273 "Specifies whether subconfigurations should be used inside configurations.
1274 If non-nil, automatically created configurations use configurations in binding
1275 indications for subcomponents, if such configurations exist. Otherwise,
1276 entities are used in binding indications for subcomponents."
1277 :type 'boolean
1278 :group 'vhdl-compose)
1281 (defgroup vhdl-port nil
1282 "Customizations for port translation functions."
1283 :group 'vhdl
1284 :group 'vhdl-compose)
1286 (defcustom vhdl-include-port-comments nil
1287 "Non-nil means include port comments when a port is pasted."
1288 :type 'boolean
1289 :group 'vhdl-port)
1291 (defcustom vhdl-include-direction-comments nil
1292 "Non-nil means include port direction in instantiations as comments."
1293 :type 'boolean
1294 :group 'vhdl-port)
1296 (defcustom vhdl-include-type-comments nil
1297 "Non-nil means include generic/port type in instantiations as comments."
1298 :type 'boolean
1299 :group 'vhdl-port)
1301 (defcustom vhdl-include-group-comments 'never
1302 "Specifies whether to include group comments and spacings.
1303 The comments and empty lines between groups of ports are pasted:
1304 Never : never
1305 Declarations: in entity/component/constant/signal declarations only
1306 Always : also in generic/port maps"
1307 :type '(choice (const :tag "Never" never)
1308 (const :tag "Declarations" decl)
1309 (const :tag "Always" always))
1310 :group 'vhdl-port)
1312 (defcustom vhdl-actual-generic-name '(".*" . "\\&")
1313 (concat
1314 "Specifies how actual generic names are obtained from formal generic names.
1315 In a component instantiation, an actual generic name can be
1316 obtained by modifying the formal generic name (e.g. attaching or stripping
1317 off a substring)."
1318 vhdl-name-doc-string)
1319 :type '(cons (regexp :tag "From regexp")
1320 (string :tag "To string "))
1321 :group 'vhdl-port
1322 :version "24.4")
1324 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1325 (concat
1326 "Specifies how actual port names are obtained from formal port names.
1327 In a component instantiation, an actual port name can be obtained by
1328 modifying the formal port name (e.g. attaching or stripping off a substring)."
1329 vhdl-name-doc-string)
1330 :type '(cons (regexp :tag "From regexp")
1331 (string :tag "To string "))
1332 :group 'vhdl-port)
1334 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1335 (concat
1336 "Specifies how an instance name is obtained.
1337 The instance name can be obtained by modifying the name of the component to be
1338 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1339 by a unique number (starting with 1).
1340 If TO STRING is empty, the instance name is queried."
1341 vhdl-name-doc-string)
1342 :type '(cons (regexp :tag "From regexp")
1343 (string :tag "To string "))
1344 :group 'vhdl-port)
1347 (defgroup vhdl-testbench nil
1348 "Customizations for testbench generation."
1349 :group 'vhdl-port)
1351 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1352 (concat
1353 "Specifies how the testbench entity name is obtained.
1354 The entity name of a testbench can be obtained by modifying the name of
1355 the component to be tested (e.g. attaching or stripping off a substring)."
1356 vhdl-name-doc-string)
1357 :type '(cons (regexp :tag "From regexp")
1358 (string :tag "To string "))
1359 :group 'vhdl-testbench)
1361 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1362 (concat
1363 "Specifies how the testbench architecture name is obtained.
1364 The testbench architecture name can be obtained by modifying the name of
1365 the component to be tested (e.g. attaching or stripping off a substring).
1366 If TO STRING is empty, the architecture name is queried."
1367 vhdl-name-doc-string)
1368 :type '(cons (regexp :tag "From regexp")
1369 (string :tag "To string "))
1370 :group 'vhdl-testbench)
1372 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1373 (concat
1374 "Specifies how the testbench configuration name is obtained.
1375 The configuration name of a testbench can be obtained by modifying the entity
1376 and/or architecture name (e.g. attaching or stripping off a substring). The
1377 string that is matched against the regexp is the concatenation of the entity
1378 and the architecture name separated by a space. This gives access to both
1379 names (see default setting as example)."
1380 vhdl-name-doc-string)
1381 :type '(cons (regexp :tag "From regexp")
1382 (string :tag "To string "))
1383 :group 'vhdl-testbench)
1385 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1386 (concat
1387 "Specifies how a DUT instance name is obtained.
1388 The design-under-test instance name (i.e. the component instantiated in the
1389 testbench) can be obtained by modifying the component name (e.g. attaching
1390 or stripping off a substring)."
1391 vhdl-name-doc-string)
1392 :type '(cons (regexp :tag "From regexp")
1393 (string :tag "To string "))
1394 :group 'vhdl-testbench)
1396 (defcustom vhdl-testbench-include-header t
1397 "Non-nil means include a header in automatically generated files."
1398 :type 'boolean
1399 :group 'vhdl-testbench)
1401 (defcustom vhdl-testbench-declarations "\
1402 -- clock
1403 signal Clk : std_logic := '1';
1405 "String or file to be inserted in the testbench declarative part.
1406 If the string specifies an existing file name, the contents of the file is
1407 inserted, otherwise the string itself is inserted in the testbench
1408 architecture before the BEGIN keyword.
1409 Type `C-j' for newlines."
1410 :type 'string
1411 :group 'vhdl-testbench)
1413 (defcustom vhdl-testbench-statements "\
1414 -- clock generation
1415 Clk <= not Clk after 10 ns;
1417 -- waveform generation
1418 WaveGen_Proc: process
1419 begin
1420 -- insert signal assignments here
1422 wait until Clk = '1';
1423 end process WaveGen_Proc;
1425 "String or file to be inserted in the testbench statement part.
1426 If the string specifies an existing file name, the contents of the file is
1427 inserted, otherwise the string itself is inserted in the testbench
1428 architecture before the END keyword.
1429 Type `C-j' for newlines."
1430 :type 'string
1431 :group 'vhdl-testbench)
1433 (defcustom vhdl-testbench-initialize-signals nil
1434 "Non-nil means initialize signals with `0' when declared in testbench."
1435 :type 'boolean
1436 :group 'vhdl-testbench)
1438 (defcustom vhdl-testbench-include-library t
1439 "Non-nil means a library/use clause for std_logic_1164 is included."
1440 :type 'boolean
1441 :group 'vhdl-testbench)
1443 (defcustom vhdl-testbench-include-configuration t
1444 "Non-nil means a testbench configuration is attached at the end."
1445 :type 'boolean
1446 :group 'vhdl-testbench)
1448 (defcustom vhdl-testbench-create-files 'single
1449 "Specifies whether new files should be created for the testbench.
1450 testbench entity and architecture are inserted:
1451 None : in current buffer
1452 Single file : in new single file
1453 Separate files: in two separate files
1454 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1455 and `vhdl-testbench-architecture-file-name'."
1456 :type '(choice (const :tag "None" none)
1457 (const :tag "Single file" single)
1458 (const :tag "Separate files" separate))
1459 :group 'vhdl-testbench)
1461 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1462 (concat
1463 "Specifies how the testbench entity file name is obtained.
1464 The entity file name can be obtained by modifying the testbench entity name
1465 \(e.g. attaching or stripping off a substring). The file extension is
1466 automatically taken from the file name of the current buffer. Testbench
1467 files can be created in a different directory by prepending a relative or
1468 absolute path to the file name."
1469 vhdl-name-doc-string)
1470 :type '(cons (regexp :tag "From regexp")
1471 (string :tag "To string "))
1472 :group 'vhdl-testbench)
1474 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1475 (concat
1476 "Specifies how the testbench architecture file name is obtained.
1477 The architecture file name can be obtained by modifying the testbench entity
1478 and/or architecture name (e.g. attaching or stripping off a substring). The
1479 string that is matched against the regexp is the concatenation of the entity
1480 and the architecture name separated by a space. This gives access to both
1481 names (see default setting as example). Testbench files can be created in
1482 a different directory by prepending a relative or absolute path to the file
1483 name."
1484 vhdl-name-doc-string)
1485 :type '(cons (regexp :tag "From regexp")
1486 (string :tag "To string "))
1487 :group 'vhdl-testbench)
1490 (defgroup vhdl-comment nil
1491 "Customizations for comments."
1492 :group 'vhdl)
1494 (defcustom vhdl-self-insert-comments t
1495 "Non-nil means various templates automatically insert help comments."
1496 :type 'boolean
1497 :group 'vhdl-comment)
1499 (defcustom vhdl-prompt-for-comments t
1500 "Non-nil means various templates prompt for user definable comments."
1501 :type 'boolean
1502 :group 'vhdl-comment)
1504 (defcustom vhdl-inline-comment-column 40
1505 "Column to indent and align inline comments to.
1506 Overrides local option `comment-column'.
1508 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1509 \"Activate Options\"."
1510 :type 'integer
1511 :group 'vhdl-comment)
1513 (defcustom vhdl-end-comment-column 79
1514 "End of comment column.
1515 Comments that exceed this column number are wrapped.
1517 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1518 \"Activate Options\"."
1519 :type 'integer
1520 :group 'vhdl-comment)
1522 (defvar end-comment-column)
1525 (defgroup vhdl-beautify nil
1526 "Customizations for beautification."
1527 :group 'vhdl)
1529 (defcustom vhdl-auto-align t
1530 "Non-nil means align some templates automatically after generation."
1531 :type 'boolean
1532 :group 'vhdl-beautify)
1534 (defcustom vhdl-align-groups t
1535 "Non-nil means align groups of code lines separately.
1536 A group of code lines is a region of consecutive lines between two lines that
1537 match the regexp in option `vhdl-align-group-separate'."
1538 :type 'boolean
1539 :group 'vhdl-beautify)
1541 (defcustom vhdl-align-group-separate "^\\s-*$"
1542 "Regexp for matching a line that separates groups of lines for alignment.
1543 Examples:
1544 \"^\\s-*$\": matches an empty line
1545 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1546 :type 'regexp
1547 :group 'vhdl-beautify)
1549 (defcustom vhdl-align-same-indent t
1550 "Non-nil means align blocks with same indent separately.
1551 When a region or the entire buffer is aligned, the code is divided into
1552 blocks of same indent which are aligned separately (except for argument/port
1553 lists). This gives nicer alignment in most cases.
1554 Option `vhdl-align-groups' still applies within these blocks."
1555 :type 'boolean
1556 :group 'vhdl-beautify)
1558 (defcustom vhdl-beautify-options '(t t t t t)
1559 "List of options for beautifying code.
1560 Allows you to disable individual features of code beautification."
1561 :type '(list (boolean :tag "Whitespace cleanup ")
1562 (boolean :tag "Single statement per line")
1563 (boolean :tag "Indentation ")
1564 (boolean :tag "Alignment ")
1565 (boolean :tag "Case fixing "))
1566 :group 'vhdl-beautify
1567 :version "24.4")
1570 (defgroup vhdl-highlight nil
1571 "Customizations for highlighting."
1572 :group 'vhdl)
1574 (defcustom vhdl-highlight-keywords t
1575 "Non-nil means highlight VHDL keywords and other standardized words.
1576 The following faces are used:
1577 `font-lock-keyword-face' : keywords
1578 `font-lock-type-face' : standardized types
1579 `vhdl-font-lock-attribute-face': standardized attributes
1580 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1581 `vhdl-font-lock-function-face' : standardized function and package names
1583 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1584 entry \"Fontify Buffer\")."
1585 :type 'boolean
1586 :set (lambda (variable value)
1587 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1588 :group 'vhdl-highlight)
1590 (defcustom vhdl-highlight-names t
1591 "Non-nil means highlight declaration names and construct labels.
1592 The following faces are used:
1593 `font-lock-function-name-face' : names in declarations of units,
1594 subprograms, components, as well as labels of VHDL constructs
1595 `font-lock-type-face' : names in type/nature declarations
1596 `vhdl-font-lock-attribute-face': names in attribute declarations
1597 `font-lock-variable-name-face' : names in declarations of signals,
1598 variables, constants, subprogram parameters, generics, and ports
1600 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1601 entry \"Fontify Buffer\")."
1602 :type 'boolean
1603 :set (lambda (variable value)
1604 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1605 :group 'vhdl-highlight)
1607 (defcustom vhdl-highlight-special-words nil
1608 "Non-nil means highlight words with special syntax.
1609 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1610 are highlighted accordingly.
1611 Can be used for visual support of naming conventions.
1613 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1614 entry \"Fontify Buffer\")."
1615 :type 'boolean
1616 :set (lambda (variable value)
1617 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1618 :group 'vhdl-highlight)
1620 (defcustom vhdl-highlight-forbidden-words nil
1621 "Non-nil means highlight forbidden words.
1622 The reserved words specified in option `vhdl-forbidden-words' or having the
1623 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1624 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1625 use them.
1627 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1628 entry \"Fontify Buffer\")."
1629 :type 'boolean
1630 :set (lambda (variable value)
1631 (vhdl-custom-set variable value
1632 'vhdl-words-init 'vhdl-font-lock-init))
1633 :group 'vhdl-highlight)
1635 (defcustom vhdl-highlight-verilog-keywords nil
1636 "Non-nil means highlight Verilog keywords as reserved words.
1637 Verilog keywords are highlighted in a warning color (face
1638 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1640 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1641 entry \"Fontify Buffer\")."
1642 :type 'boolean
1643 :set (lambda (variable value)
1644 (vhdl-custom-set variable value
1645 'vhdl-words-init 'vhdl-font-lock-init))
1646 :group 'vhdl-highlight)
1648 (defcustom vhdl-highlight-translate-off nil
1649 "Non-nil means background-highlight code excluded from translation.
1650 That is, all code between \"-- pragma translate_off\" and
1651 \"-- pragma translate_on\" is highlighted using a different background color
1652 \(face `vhdl-font-lock-translate-off-face').
1653 Note: this might slow down on-the-fly fontification (and thus editing).
1655 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1656 entry \"Fontify Buffer\")."
1657 :type 'boolean
1658 :set (lambda (variable value)
1659 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1660 :group 'vhdl-highlight)
1662 (defcustom vhdl-highlight-case-sensitive nil
1663 "Non-nil means consider case for highlighting.
1664 Possible trade-off:
1665 non-nil also upper-case VHDL words are highlighted, but case of words with
1666 special syntax is not considered
1667 nil only lower-case VHDL words are highlighted, but case of words with
1668 special syntax is considered
1669 Overrides local option `font-lock-keywords-case-fold-search'.
1671 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1672 entry \"Fontify Buffer\")."
1673 :type 'boolean
1674 :group 'vhdl-highlight)
1676 (defcustom vhdl-special-syntax-alist
1677 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1678 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1679 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1680 "List of special syntax to be highlighted.
1681 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1682 syntax (as regular expression) are highlighted in the corresponding color.
1684 Name : string of words and spaces
1685 Regexp : regular expression describing word syntax
1686 (e.g., `\\=\\<\\w+_c\\>' matches word with suffix `_c')
1687 expression must start with `\\=\\<' and end with `\\>'
1688 if only whole words should be matched (no substrings)
1689 Color (light): foreground color for light background
1690 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1691 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1692 Color (dark) : foreground color for dark background
1693 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1694 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1695 In comments : If non-nil, words are also highlighted inside comments
1697 Can be used for visual support of naming conventions, such as highlighting
1698 different kinds of signals (e.g. `Clk50', `Rst_n') or objects (e.g.
1699 `Signal_s', `Variable_v', `Constant_c') by distinguishing them using
1700 common substrings or name suffices.
1701 For each entry, a new face is generated with the specified colors and name
1702 `vhdl-font-lock-' + name + `-face'.
1704 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1705 entry `Fontify Buffer'). All other changes require restarting Emacs."
1706 :type '(repeat (list :tag "Face" :indent 2
1707 (string :tag "Name ")
1708 (regexp :tag "Regexp " "\\w+_")
1709 (string :tag "Color (light)")
1710 (string :tag "Color (dark) ")
1711 (boolean :tag "In comments ")))
1712 :set (lambda (variable value)
1713 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1714 :group 'vhdl-highlight)
1716 (defcustom vhdl-forbidden-words '()
1717 "List of forbidden words to be highlighted.
1718 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1719 words are highlighted in a warning color to indicate not to use them.
1721 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1722 entry \"Fontify Buffer\")."
1723 :type '(repeat (string :format "%v"))
1724 :set (lambda (variable value)
1725 (vhdl-custom-set variable value
1726 'vhdl-words-init 'vhdl-font-lock-init))
1727 :group 'vhdl-highlight)
1729 (defcustom vhdl-forbidden-syntax ""
1730 "Syntax of forbidden words to be highlighted.
1731 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1732 syntax are highlighted in a warning color to indicate not to use them.
1733 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1734 highlights identifiers with 10 or more characters).
1736 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1737 entry \"Fontify Buffer\")."
1738 :type 'regexp
1739 :set (lambda (variable value)
1740 (vhdl-custom-set variable value
1741 'vhdl-words-init 'vhdl-font-lock-init))
1742 :group 'vhdl-highlight)
1744 (defcustom vhdl-directive-keywords '("psl" "pragma" "synopsys")
1745 "List of compiler directive keywords recognized for highlighting.
1747 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1748 entry \"Fontify Buffer\")."
1749 :type '(repeat (string :format "%v"))
1750 :set (lambda (variable value)
1751 (vhdl-custom-set variable value
1752 'vhdl-words-init 'vhdl-font-lock-init))
1753 :group 'vhdl-highlight)
1756 (defgroup vhdl-speedbar nil
1757 "Customizations for speedbar."
1758 :group 'vhdl)
1760 (defcustom vhdl-speedbar-auto-open nil
1761 "Non-nil means automatically open speedbar at startup.
1762 Alternatively, the speedbar can be opened from the VHDL menu."
1763 :type 'boolean
1764 :group 'vhdl-speedbar)
1766 (defcustom vhdl-speedbar-display-mode 'files
1767 "Specifies the default displaying mode when opening speedbar.
1768 Alternatively, the displaying mode can be selected from the speedbar menu or
1769 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1770 :type '(choice (const :tag "Files" files)
1771 (const :tag "Directory hierarchy" directory)
1772 (const :tag "Project hierarchy" project))
1773 :group 'vhdl-speedbar)
1775 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1776 "Limits scanning of large files and netlists.
1777 Design units: maximum file size to scan for design units
1778 Hierarchy (instances of subcomponents):
1779 File size: maximum file size to scan for instances (in bytes)
1780 Instances per arch: maximum number of instances to scan per architecture
1782 \"None\" always means that there is no limit.
1783 In case of files not or incompletely scanned, a warning message and the file
1784 names are printed out.
1785 Background: scanning for instances is considerably slower than scanning for
1786 design units, especially when there are many instances. These limits should
1787 prevent the scanning of large netlists."
1788 :type '(list (choice :tag "Design units"
1789 :format "%t : %[Value Menu%] %v"
1790 (const :tag "None" nil)
1791 (integer :tag "File size"))
1792 (list :tag "Hierarchy" :indent 2
1793 (choice :tag "File size"
1794 :format "%t : %[Value Menu%] %v"
1795 (const :tag "None" nil)
1796 (integer :tag "Size "))
1797 (choice :tag "Instances per arch"
1798 (const :tag "None" nil)
1799 (integer :tag "Number "))))
1800 :group 'vhdl-speedbar)
1802 (defcustom vhdl-speedbar-jump-to-unit t
1803 "Non-nil means jump to the design unit code when opened in a buffer.
1804 The buffer cursor position is left unchanged otherwise."
1805 :type 'boolean
1806 :group 'vhdl-speedbar)
1808 (defcustom vhdl-speedbar-update-on-saving t
1809 "Automatically update design hierarchy when buffer is saved."
1810 :type 'boolean
1811 :group 'vhdl-speedbar)
1813 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1814 "Automatically save modified hierarchy caches when exiting Emacs.
1815 Hierarchy: design hierarchy information
1816 Display: displaying information (which design units to expand)"
1817 :type '(set (const :tag "Hierarchy" hierarchy)
1818 (const :tag "Display" display))
1819 :group 'vhdl-speedbar)
1821 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1822 "Name of file for saving hierarchy cache.
1823 \"\\1\" is replaced by the project name if a project is specified,
1824 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1825 different users to have cache files in the same directory). Can also have
1826 an absolute path (i.e. all caches can be stored in one global directory)."
1827 :type 'string
1828 :group 'vhdl-speedbar)
1831 (defgroup vhdl-menu nil
1832 "Customizations for menus."
1833 :group 'vhdl)
1835 (defcustom vhdl-index-menu nil
1836 "Non-nil means add an index menu for a source file when loading.
1837 Alternatively, the speedbar can be used. Note that the index menu scans a file
1838 when it is opened, while speedbar only scans the file upon request."
1839 :type 'boolean
1840 :group 'vhdl-menu)
1842 (defcustom vhdl-source-file-menu nil
1843 "Non-nil means add a menu of all source files in current directory.
1844 Alternatively, the speedbar can be used."
1845 :type 'boolean
1846 :group 'vhdl-menu)
1848 (defcustom vhdl-hideshow-menu nil
1849 "Non-nil means add hideshow menu and functionality at startup.
1850 Hideshow can also be enabled from the VHDL Mode menu.
1851 Hideshow allows hiding code of various VHDL constructs.
1853 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1854 \"Activate Options\"."
1855 :type 'boolean
1856 :group 'vhdl-menu)
1858 (defcustom vhdl-hide-all-init nil
1859 "Non-nil means hide all design units initially after a file is loaded."
1860 :type 'boolean
1861 :group 'vhdl-menu)
1864 (defgroup vhdl-print nil
1865 "Customizations for printing."
1866 :group 'vhdl)
1868 (defcustom vhdl-print-two-column t
1869 "Non-nil means print code in two columns and landscape format.
1870 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1871 prints VHDL files in a nice two-column landscape style.
1873 NOTE: Activate the new setting by restarting Emacs.
1874 Overrides `ps-print' settings locally."
1875 :type 'boolean
1876 :group 'vhdl-print)
1878 (defcustom vhdl-print-customize-faces t
1879 "Non-nil means use an optimized set of faces for PostScript printing.
1881 NOTE: Activate the new setting by restarting Emacs.
1882 Overrides `ps-print' settings locally."
1883 :type 'boolean
1884 :group 'vhdl-print)
1887 (defgroup vhdl-misc nil
1888 "Miscellaneous customizations."
1889 :group 'vhdl)
1891 (defcustom vhdl-intelligent-tab t
1892 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1893 That is, if preceding character is part of a word then complete word,
1894 else if not at beginning of line then insert tab,
1895 else if last command was a `TAB' or `RET' then dedent one step,
1896 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1897 If nil, TAB always indents current line (i.e. `TAB' is bound to
1898 `indent-according-to-mode').
1900 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1901 \"Activate Options\"."
1902 :type 'boolean
1903 :group 'vhdl-misc)
1905 (defcustom vhdl-indent-syntax-based t
1906 "Non-nil means indent lines of code based on their syntactic context.
1907 Otherwise, a line is indented like the previous nonblank line. This can be
1908 useful in large files where syntax-based indentation gets very slow."
1909 :type 'boolean
1910 :group 'vhdl-misc)
1912 (defcustom vhdl-indent-comment-like-next-code-line t
1913 "Non-nil means comment lines are indented like the following code line.
1914 Otherwise, comment lines are indented like the preceding code line.
1915 Indenting comment lines like the following code line gives nicer indentation
1916 when comments precede the code that they refer to."
1917 :type 'boolean
1918 :version "24.3"
1919 :group 'vhdl-misc)
1921 (defcustom vhdl-word-completion-case-sensitive nil
1922 "Non-nil means word completion using `TAB' is case sensitive.
1923 That is, `TAB' completes words that start with the same letters and case.
1924 Otherwise, case is ignored."
1925 :type 'boolean
1926 :group 'vhdl-misc)
1928 (defcustom vhdl-word-completion-in-minibuffer t
1929 "Non-nil enables word completion in minibuffer (for template prompts).
1931 NOTE: Activate the new setting by restarting Emacs."
1932 :type 'boolean
1933 :group 'vhdl-misc)
1935 (defcustom vhdl-underscore-is-part-of-word nil
1936 "Non-nil means consider the underscore character `_' as part of word.
1937 An identifier containing underscores is then treated as a single word in
1938 select and move operations. All parts of an identifier separated by underscore
1939 are treated as single words otherwise."
1940 :type 'boolean
1941 :group 'vhdl-misc)
1942 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1943 'superword-mode "24.4")
1946 (defgroup vhdl-related nil
1947 "Related general customizations."
1948 :group 'vhdl)
1950 ;; add related general customizations
1951 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1952 (if (featurep 'xemacs)
1953 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1954 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1955 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1956 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1957 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1958 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1959 (unless (featurep 'xemacs)
1960 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1961 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1962 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1963 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1965 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1966 ;; Hidden user variables
1968 (defvar vhdl-compile-absolute-path nil
1969 "If non-nil, use absolute instead of relative path for compiled files.")
1971 (defvar vhdl-comment-display-line-char ?-
1972 "Character to use in comment display line.")
1974 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1975 ;; Internal variables
1977 (defvar vhdl-menu-max-size 20
1978 "Specifies the maximum size of a menu before splitting it into submenus.")
1980 (defvar vhdl-progress-interval 1
1981 "Interval used to update progress status during long operations.
1982 If a number, percentage complete gets updated after each interval of
1983 that many seconds. To inhibit all messages, set this option to nil.")
1985 (defvar vhdl-inhibit-startup-warnings-p nil
1986 "If non-nil, inhibits start up compatibility warnings.")
1988 (defvar vhdl-strict-syntax-p nil
1989 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1990 If the syntactic symbol for a particular line does not match a symbol
1991 in the offsets alist, an error is generated, otherwise no error is
1992 reported and the syntactic symbol is ignored.")
1994 (defvar vhdl-echo-syntactic-information-p nil
1995 "If non-nil, syntactic info is echoed when the line is indented.")
1997 (defconst vhdl-offsets-alist-default
1998 '((string . -1000)
1999 (cpp-macro . -1000)
2000 (block-open . 0)
2001 (block-close . 0)
2002 (statement . 0)
2003 (statement-cont . vhdl-lineup-statement-cont)
2004 (statement-block-intro . +)
2005 (statement-case-intro . +)
2006 (case-alternative . +)
2007 (comment . vhdl-lineup-comment)
2008 (arglist-intro . +)
2009 (arglist-cont . 0)
2010 (arglist-cont-nonempty . vhdl-lineup-arglist)
2011 (arglist-close . vhdl-lineup-arglist)
2012 (entity . 0)
2013 (configuration . 0)
2014 (package . 0)
2015 (architecture . 0)
2016 (package-body . 0)
2017 (context . 0)
2018 (directive . 0)
2020 "Default settings for offsets of syntactic elements.
2021 Do not change this constant! See the variable `vhdl-offsets-alist' for
2022 more information.")
2024 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
2025 "Association list of syntactic element symbols and indentation offsets.
2026 As described below, each cons cell in this list has the form:
2028 (SYNTACTIC-SYMBOL . OFFSET)
2030 When a line is indented, `vhdl-mode' first determines the syntactic
2031 context of the line by generating a list of symbols called syntactic
2032 elements. This list can contain more than one syntactic element and
2033 the global variable `vhdl-syntactic-context' contains the context list
2034 for the line being indented. Each element in this list is actually a
2035 cons cell of the syntactic symbol and a buffer position. This buffer
2036 position is call the relative indent point for the line. Some
2037 syntactic symbols may not have a relative indent point associated with
2038 them.
2040 After the syntactic context list for a line is generated, `vhdl-mode'
2041 calculates the absolute indentation for the line by looking at each
2042 syntactic element in the list. First, it compares the syntactic
2043 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2044 finds a match, it adds the OFFSET to the column of the relative indent
2045 point. The sum of this calculation for each element in the syntactic
2046 list is the absolute offset for line being indented.
2048 If the syntactic element does not match any in the `vhdl-offsets-alist',
2049 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2050 the element is ignored.
2052 Actually, OFFSET can be an integer, a function, a variable, or one of
2053 the following symbols: `+', `-', `++', or `--'. These latter
2054 designate positive or negative multiples of `vhdl-basic-offset',
2055 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2056 called with a single argument containing the cons of the syntactic
2057 element symbol and the relative indent point. The function should
2058 return an integer offset.
2060 Here is the current list of valid syntactic element symbols:
2062 string -- inside multi-line string
2063 block-open -- statement block open
2064 block-close -- statement block close
2065 statement -- a VHDL statement
2066 statement-cont -- a continuation of a VHDL statement
2067 statement-block-intro -- the first line in a new statement block
2068 statement-case-intro -- the first line in a case alternative block
2069 case-alternative -- a case statement alternative clause
2070 comment -- a line containing only a comment
2071 arglist-intro -- the first line in an argument list
2072 arglist-cont -- subsequent argument list lines when no
2073 arguments follow on the same line as
2074 the arglist opening paren
2075 arglist-cont-nonempty -- subsequent argument list lines when at
2076 least one argument follows on the same
2077 line as the arglist opening paren
2078 arglist-close -- the solo close paren of an argument list
2079 entity -- inside an entity declaration
2080 configuration -- inside a configuration declaration
2081 package -- inside a package declaration
2082 architecture -- inside an architecture body
2083 package-body -- inside a package body
2084 context -- inside a context declaration")
2086 (defvar vhdl-comment-only-line-offset 0
2087 "Extra offset for line which contains only the start of a comment.
2088 Can contain an integer or a cons cell of the form:
2090 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2092 Where NON-ANCHORED-OFFSET is the amount of offset given to
2093 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2094 the amount of offset to give column-zero anchored comment-only lines.
2095 Just an integer as value is equivalent to (<val> . 0)")
2097 (defvar vhdl-special-indent-hook nil
2098 "Hook for user defined special indentation adjustments.
2099 This hook gets called after a line is indented by the mode.")
2101 (defvar vhdl-style-alist
2102 '(("IEEE"
2103 (vhdl-basic-offset . 4)
2104 (vhdl-offsets-alist . ())))
2105 "Styles of Indentation.
2106 Elements of this alist are of the form:
2108 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2110 where STYLE-STRING is a short descriptive string used to select a
2111 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2112 value for that variable when using the selected style.
2114 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2115 case, the VALUE is a list containing elements of the form:
2117 (SYNTACTIC-SYMBOL . VALUE)
2119 as described in `vhdl-offsets-alist'. These are passed directly to
2120 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2121 your style, only those that are different from the default.")
2123 ;; dynamically append the default value of most variables
2124 (or (assoc "Default" vhdl-style-alist)
2125 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2126 vhdl-strict-syntax-p
2127 vhdl-echo-syntactic-information-p
2128 vhdl-basic-offset
2129 vhdl-offsets-alist
2130 vhdl-comment-only-line-offset))
2131 (default (cons "Default"
2132 (mapcar
2133 (function
2134 (lambda (var)
2135 (cons var (symbol-value var))))
2136 varlist))))
2137 (push default vhdl-style-alist)))
2139 (defvar vhdl-mode-hook nil
2140 "Hook called by `vhdl-mode'.")
2143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2144 ;;; Required packages
2145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2147 ;; mandatory
2148 (require 'compile) ; XEmacs
2149 (require 'easymenu)
2150 (require 'hippie-exp)
2152 ;; optional (minimize warning messages during compile)
2153 (unless (featurep 'xemacs)
2154 (eval-when-compile
2155 (require 'font-lock)
2156 (require 'ps-print)
2157 (require 'speedbar))) ; for speedbar-with-writable
2159 (defun vhdl-aput (alist-symbol key &optional value)
2160 "Insert a key-value pair into an alist.
2161 The alist is referenced by ALIST-SYMBOL. The key-value pair is made
2162 from KEY and VALUE. If the key-value pair referenced by KEY can be
2163 found in the alist, the value of KEY will be set to VALUE. If the
2164 key-value pair cannot be found in the alist, it will be inserted into
2165 the head of the alist."
2166 (let* ((alist (symbol-value alist-symbol))
2167 (elem (assoc key alist)))
2168 (if elem
2169 (setcdr elem value)
2170 (set alist-symbol (cons (cons key value) alist)))))
2172 (defun vhdl-adelete (alist-symbol key)
2173 "Delete a key-value pair from the alist.
2174 Alist is referenced by ALIST-SYMBOL and the key-value pair to remove
2175 is pair matching KEY."
2176 (let ((alist (symbol-value alist-symbol)) alist-cdr)
2177 (while (equal key (caar alist))
2178 (setq alist (cdr alist))
2179 (set alist-symbol alist))
2180 (while (setq alist-cdr (cdr alist))
2181 (if (equal key (caar alist-cdr))
2182 (setcdr alist (cdr alist-cdr))
2183 (setq alist alist-cdr)))))
2185 (defun vhdl-aget (alist key)
2186 "Return the value in ALIST that is associated with KEY. If KEY is
2187 not found, then nil is returned."
2188 (cdr (assoc key alist)))
2190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2191 ;;; Compatibility
2192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2195 ;; XEmacs compatibility
2197 ;; active regions
2198 (defun vhdl-keep-region-active ()
2199 "Do whatever is necessary to keep the region active in XEmacs.
2200 Ignore byte-compiler warnings you might see."
2201 (and (featurep 'xemacs)
2202 (setq zmacs-region-stays t)))
2204 ;; `wildcard-to-regexp' is included only in XEmacs 21
2205 (unless (fboundp 'wildcard-to-regexp)
2206 (defun wildcard-to-regexp (wildcard)
2207 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2208 (let* ((i (string-match "[*?]" wildcard))
2209 (result (substring wildcard 0 i))
2210 (len (length wildcard)))
2211 (when i
2212 (while (< i len)
2213 (let ((ch (aref wildcard i)))
2214 (setq result (concat result
2215 (cond ((eq ch ?*) "[^\000]*")
2216 ((eq ch ??) "[^\000]")
2217 (t (char-to-string ch)))))
2218 (setq i (1+ i)))))
2219 (concat "\\`" result "\\'"))))
2221 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2222 ;; `regexp-opt' accelerates fontification by 10-20%
2223 (unless (fboundp 'regexp-opt)
2224 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2225 (defun regexp-opt (strings &optional paren)
2226 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2227 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2229 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2230 (unless (fboundp 'match-string-no-properties)
2231 (defalias 'match-string-no-properties 'match-string))
2233 ;; `subst-char-in-string' undefined (XEmacs)
2234 (unless (fboundp 'subst-char-in-string)
2235 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2236 (let ((i (length string))
2237 (newstr (if inplace string (copy-sequence string))))
2238 (while (> i 0)
2239 (setq i (1- i))
2240 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2241 newstr)))
2243 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2244 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2245 (not noninteractive))
2246 (load "itimer")
2247 (when (string< itimer-version "1.09")
2248 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2249 (beep) (sit-for 5)))
2251 ;; `file-expand-wildcards' undefined (XEmacs)
2252 (unless (fboundp 'file-expand-wildcards)
2253 (defun file-expand-wildcards (pattern &optional full)
2254 "Taken from Emacs's `files.el'."
2255 (let* ((nondir (file-name-nondirectory pattern))
2256 (dirpart (file-name-directory pattern))
2257 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2258 (mapcar 'file-name-as-directory
2259 (file-expand-wildcards (directory-file-name dirpart)))
2260 (list dirpart)))
2261 contents)
2262 (while dirs
2263 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2264 (file-directory-p (directory-file-name (car dirs))))
2265 (let ((this-dir-contents
2266 (delq nil
2267 (mapcar #'(lambda (name)
2268 (unless (string-match "\\`\\.\\.?\\'"
2269 (file-name-nondirectory name))
2270 name))
2271 (directory-files (or (car dirs) ".") full
2272 (wildcard-to-regexp nondir))))))
2273 (setq contents
2274 (nconc
2275 (if (and (car dirs) (not full))
2276 (mapcar (function (lambda (name) (concat (car dirs) name)))
2277 this-dir-contents)
2278 this-dir-contents)
2279 contents))))
2280 (setq dirs (cdr dirs)))
2281 contents)))
2283 ;; `member-ignore-case' undefined (XEmacs)
2284 (unless (fboundp 'member-ignore-case)
2285 (defalias 'member-ignore-case 'member))
2287 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2288 ;; behavior in XEmacs
2289 (defvar vhdl-last-input-event)
2290 (if (featurep 'xemacs)
2291 (defvaralias 'vhdl-last-input-event 'last-input-char)
2292 (defvaralias 'vhdl-last-input-event 'last-input-event))
2294 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2295 ;;;(unless (fboundp 'help-print-return-message)
2296 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2298 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2299 ;; Compatibility with older VHDL Mode versions
2301 (defvar vhdl-warnings nil
2302 "Warnings to tell the user during start up.")
2304 (defun vhdl-run-when-idle (secs repeat function)
2305 "Wait until idle, then run FUNCTION."
2306 (if (fboundp 'start-itimer)
2307 (start-itimer "vhdl-mode" function secs repeat t)
2308 ;; explicitly activate timer (necessary when Emacs is already idle)
2309 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2311 (defun vhdl-warning-when-idle (&rest args)
2312 "Wait until idle, then print out warning STRING and beep."
2313 (let ((message (apply #'format-message args)))
2314 (if noninteractive
2315 (vhdl-warning message t)
2316 (unless vhdl-warnings
2317 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2318 (push message vhdl-warnings))))
2320 (defun vhdl-warning (string &optional nobeep)
2321 "Print out warning STRING and beep."
2322 (message "WARNING: %s" string)
2323 (unless (or nobeep noninteractive) (beep)))
2325 (defun vhdl-print-warnings ()
2326 "Print out messages in variable `vhdl-warnings'."
2327 (let ((no-warnings (length vhdl-warnings)))
2328 (setq vhdl-warnings (nreverse vhdl-warnings))
2329 (while vhdl-warnings
2330 (message "WARNING: %s" (car vhdl-warnings))
2331 (setq vhdl-warnings (cdr vhdl-warnings)))
2332 (beep)
2333 (when (> no-warnings 1)
2334 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2336 ;; Backward compatibility checks and fixes
2337 ;; option `vhdl-compiler' changed format
2338 (unless (stringp vhdl-compiler)
2339 (setq vhdl-compiler "ModelSim")
2340 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2342 ;; option `vhdl-standard' changed format
2343 (unless (listp vhdl-standard)
2344 (setq vhdl-standard '(87 nil))
2345 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2347 ;; option `vhdl-model-alist' changed format
2348 (when (= (length (car vhdl-model-alist)) 3)
2349 (let ((old-alist vhdl-model-alist)
2350 new-alist)
2351 (while old-alist
2352 (push (append (car old-alist) '("")) new-alist)
2353 (setq old-alist (cdr old-alist)))
2354 (setq vhdl-model-alist (nreverse new-alist)))
2355 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2357 ;; option `vhdl-project-alist' changed format
2358 (when (= (length (car vhdl-project-alist)) 3)
2359 (let ((old-alist vhdl-project-alist)
2360 new-alist)
2361 (while old-alist
2362 (push (append (car old-alist) '("")) new-alist)
2363 (setq old-alist (cdr old-alist)))
2364 (setq vhdl-project-alist (nreverse new-alist)))
2365 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2367 ;; option `vhdl-project-alist' changed format (3.31.1)
2368 (when (= (length (car vhdl-project-alist)) 4)
2369 (let ((old-alist vhdl-project-alist)
2370 new-alist elem)
2371 (while old-alist
2372 (setq elem (car old-alist))
2373 (setq new-alist
2374 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2375 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2376 new-alist))
2377 (setq old-alist (cdr old-alist)))
2378 (setq vhdl-project-alist (nreverse new-alist)))
2379 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2381 ;; option `vhdl-project-alist' changed format (3.31.12)
2382 (when (= (length (car vhdl-project-alist)) 10)
2383 (let ((tmp-alist vhdl-project-alist))
2384 (while tmp-alist
2385 (setcdr (nthcdr 3 (car tmp-alist))
2386 (cons "" (nthcdr 4 (car tmp-alist))))
2387 (setq tmp-alist (cdr tmp-alist))))
2388 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2390 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2391 (when (= (length (car vhdl-compiler-alist)) 7)
2392 (let ((old-alist vhdl-compiler-alist)
2393 new-alist elem)
2394 (while old-alist
2395 (setq elem (car old-alist))
2396 (setq new-alist
2397 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2398 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2399 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2400 (nth 5 elem) (nth 6 elem) nil)
2401 new-alist))
2402 (setq old-alist (cdr old-alist)))
2403 (setq vhdl-compiler-alist (nreverse new-alist)))
2404 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2406 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2407 (when (= (length (car vhdl-compiler-alist)) 12)
2408 (let ((tmp-alist vhdl-compiler-alist))
2409 (while tmp-alist
2410 (setcdr (nthcdr 4 (car tmp-alist))
2411 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2412 (setq tmp-alist (cdr tmp-alist))))
2413 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2415 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2416 (when (= (length (car vhdl-compiler-alist)) 13)
2417 (let ((tmp-alist vhdl-compiler-alist))
2418 (while tmp-alist
2419 (setcdr (nthcdr 3 (car tmp-alist))
2420 (cons "" (nthcdr 4 (car tmp-alist))))
2421 (setq tmp-alist (cdr tmp-alist))))
2422 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2424 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2425 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2426 (let ((tmp-alist vhdl-compiler-alist))
2427 (while tmp-alist
2428 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2429 '(0 . nil))
2430 (setq tmp-alist (cdr tmp-alist))))
2431 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2433 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2434 (when (equal vhdl-project "")
2435 (setq vhdl-project nil)
2436 (customize-save-variable 'vhdl-project vhdl-project))
2438 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2439 (when (stringp vhdl-project-file-name)
2440 (setq vhdl-project-file-name (list vhdl-project-file-name))
2441 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2443 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2444 (if (not (boundp 'speedbar-indentation-width))
2445 (defvar speedbar-indentation-width 2)
2446 ;; set default to 2 if not already customized
2447 (unless (get 'speedbar-indentation-width 'saved-value)
2448 (setq speedbar-indentation-width 2)))
2450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2451 ;;; Help functions / inline substitutions / macros
2452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2454 (defun vhdl-standard-p (standard)
2455 "Check if STANDARD is specified as used standard."
2456 (or (eq standard (car vhdl-standard))
2457 (memq standard (cadr vhdl-standard))))
2459 (defun vhdl-project-p (&optional warning)
2460 "Return non-nil if a project is displayed, i.e. directories or files are
2461 specified."
2462 (if (assoc vhdl-project vhdl-project-alist)
2463 vhdl-project
2464 (when (and vhdl-project warning)
2465 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2466 nil))
2468 (defun vhdl-resolve-env-variable (string)
2469 "Resolve environment variables in STRING."
2470 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2471 (setq string (concat (match-string 1 string)
2472 (getenv (match-string 2 string))
2473 (match-string 4 string))))
2474 string)
2476 (defun vhdl-default-directory ()
2477 "Return the default directory of the current project or the directory of the
2478 current buffer if no project is defined."
2479 (if (vhdl-project-p)
2480 (expand-file-name (vhdl-resolve-env-variable
2481 (nth 1 (vhdl-aget vhdl-project-alist vhdl-project))))
2482 default-directory))
2484 (defmacro vhdl-prepare-search-1 (&rest body)
2485 "Enable case insensitive search and switch to syntax table that includes `_',
2486 then execute BODY, and finally restore the old environment. Used for
2487 consistent searching."
2488 `(let ((case-fold-search t)) ; case insensitive search
2489 ;; use extended syntax table
2490 (with-syntax-table vhdl-mode-ext-syntax-table
2491 ,@body)))
2493 (defmacro vhdl-prepare-search-2 (&rest body)
2494 "Enable case insensitive search, switch to syntax table that includes `_',
2495 arrange to ignore `intangible' overlays, then execute BODY, and finally restore
2496 the old environment. Used for consistent searching."
2497 `(let ((case-fold-search t) ; case insensitive search
2498 (current-syntax-table (syntax-table))
2499 (inhibit-point-motion-hooks t))
2500 ;; use extended syntax table
2501 (set-syntax-table vhdl-mode-ext-syntax-table)
2502 ;; execute BODY safely
2503 (unwind-protect
2504 (progn ,@body)
2505 ;; restore syntax table
2506 (set-syntax-table current-syntax-table))))
2508 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2509 "Visit file FILE-NAME and execute BODY."
2510 `(if (null ,file-name)
2511 (progn ,@body)
2512 (unless (file-directory-p ,file-name)
2513 (let ((source-buffer (current-buffer))
2514 (visiting-buffer (find-buffer-visiting ,file-name))
2515 file-opened)
2516 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2517 (condition-case ()
2518 (progn (set-buffer (create-file-buffer ,file-name))
2519 (setq file-opened t)
2520 (vhdl-insert-file-contents ,file-name)
2521 ;; FIXME: This modifies a global syntax-table!
2522 (modify-syntax-entry ?\- ". 12" (syntax-table))
2523 (modify-syntax-entry ?\n ">" (syntax-table))
2524 (modify-syntax-entry ?\^M ">" (syntax-table))
2525 (modify-syntax-entry ?_ "w" (syntax-table))
2527 (error
2528 (if ,issue-error
2529 (progn
2530 (when file-opened (kill-buffer (current-buffer)))
2531 (set-buffer source-buffer)
2532 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2533 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2534 nil))))
2535 (condition-case info
2536 (progn ,@body)
2537 (error
2538 (if ,issue-error
2539 (progn
2540 (when file-opened (kill-buffer (current-buffer)))
2541 (set-buffer source-buffer)
2542 (error (cadr info)))
2543 (vhdl-warning (cadr info))))))
2544 (when file-opened (kill-buffer (current-buffer)))
2545 (set-buffer source-buffer)))))
2547 (defun vhdl-insert-file-contents (filename)
2548 "Nicked from `insert-file-contents-literally', but allow coding system
2549 conversion."
2550 (let ((format-alist nil)
2551 (after-insert-file-functions nil)
2552 (jka-compr-compression-info-list nil))
2553 (insert-file-contents filename t)))
2555 (defun vhdl-sort-alist (alist)
2556 "Sort ALIST."
2557 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2559 (defun vhdl-get-subdirs (directory)
2560 "Recursively get subdirectories of DIRECTORY."
2561 (let ((dir-list (list (file-name-as-directory directory)))
2562 file-list)
2563 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2564 (while file-list
2565 (when (file-directory-p (car file-list))
2566 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2567 (setq file-list (cdr file-list)))
2568 dir-list))
2570 (defun vhdl-aput-delete-if-nil (alist-symbol key &optional value)
2571 "As `aput', but delete key-value pair if VALUE is nil."
2572 (if value
2573 (vhdl-aput alist-symbol key value)
2574 (vhdl-adelete alist-symbol key)))
2576 (defun vhdl-delete (elt list)
2577 "Delete by side effect the first occurrence of ELT as a member of LIST."
2578 (push nil list)
2579 (let ((list1 list))
2580 (while (and (cdr list1) (not (equal elt (cadr list1))))
2581 (setq list1 (cdr list1)))
2582 (when list
2583 (setcdr list1 (cddr list1))))
2584 (cdr list))
2586 (declare-function speedbar-refresh "speedbar" (&optional arg))
2587 (declare-function speedbar-do-function-pointer "speedbar" ())
2589 (defun vhdl-speedbar-refresh (&optional key)
2590 "Refresh directory or project with name KEY."
2591 (when (and (boundp 'speedbar-frame)
2592 (frame-live-p speedbar-frame))
2593 (let ((pos (point))
2594 (last-frame (selected-frame)))
2595 (if (null key)
2596 (speedbar-refresh)
2597 (select-frame speedbar-frame)
2598 (when (save-excursion
2599 (goto-char (point-min))
2600 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2601 (goto-char (match-end 1))
2602 (speedbar-do-function-pointer)
2603 (backward-char 2)
2604 (speedbar-do-function-pointer)
2605 (message "Refreshing speedbar...done"))
2606 (select-frame last-frame)))))
2608 (defun vhdl-show-messages ()
2609 "Get *Messages* buffer to show recent messages."
2610 (interactive)
2611 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2613 (defun vhdl-use-direct-instantiation ()
2614 "Return whether direct instantiation is used."
2615 (or (eq vhdl-use-direct-instantiation 'always)
2616 (and (eq vhdl-use-direct-instantiation 'standard)
2617 (not (vhdl-standard-p '87)))))
2619 (defun vhdl-max-marker (marker1 marker2)
2620 "Return larger marker."
2621 (if (> marker1 marker2) marker1 marker2))
2623 (defun vhdl-goto-marker (marker)
2624 "Goto marker in appropriate buffer."
2625 (when (markerp marker)
2626 (set-buffer (marker-buffer marker)))
2627 (goto-char marker))
2629 (defun vhdl-menu-split (list title)
2630 "Split menu LIST into several submenus, if number of
2631 elements > `vhdl-menu-max-size'."
2632 (if (> (length list) vhdl-menu-max-size)
2633 (let ((remain list)
2634 (result '())
2635 (sublist '())
2636 (menuno 1)
2637 (i 0))
2638 (while remain
2639 (push (car remain) sublist)
2640 (setq remain (cdr remain))
2641 (setq i (+ i 1))
2642 (if (= i vhdl-menu-max-size)
2643 (progn
2644 (push (cons (format "%s %s" title menuno)
2645 (nreverse sublist)) result)
2646 (setq i 0)
2647 (setq menuno (+ menuno 1))
2648 (setq sublist '()))))
2649 (and sublist
2650 (push (cons (format "%s %s" title menuno)
2651 (nreverse sublist)) result))
2652 (nreverse result))
2653 list))
2656 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2657 ;;; Bindings
2658 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2661 ;; Key bindings
2663 (defvar vhdl-template-map nil
2664 "Keymap for VHDL templates.")
2666 (defun vhdl-template-map-init ()
2667 "Initialize `vhdl-template-map'."
2668 (setq vhdl-template-map (make-sparse-keymap))
2669 ;; key bindings for VHDL templates
2670 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2671 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2672 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2673 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2674 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2675 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2676 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2677 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2678 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2679 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2680 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2681 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2682 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2683 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2684 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2685 (define-key vhdl-template-map "ct" 'vhdl-template-context)
2686 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2687 (define-key vhdl-template-map "el" 'vhdl-template-else)
2688 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2689 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2690 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2691 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2692 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2693 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2694 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2695 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2696 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2697 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2698 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2699 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2700 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2701 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2702 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2703 (define-key vhdl-template-map "li" 'vhdl-template-library)
2704 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2705 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2706 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2707 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2708 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2709 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2710 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2711 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2712 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2713 (define-key vhdl-template-map "po" 'vhdl-template-port)
2714 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2715 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2716 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2717 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2718 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2719 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2720 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2721 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2722 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2723 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2724 (define-key vhdl-template-map "us" 'vhdl-template-use)
2725 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2726 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2727 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2728 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2729 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2730 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2731 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2732 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2733 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2734 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2735 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2736 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2737 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2738 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2739 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2740 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2741 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2742 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2743 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2744 (when (vhdl-standard-p 'ams)
2745 (define-key vhdl-template-map "br" 'vhdl-template-break)
2746 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2747 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2748 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2749 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2750 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2751 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2752 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2753 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2754 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2755 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2757 (when (vhdl-standard-p 'math)
2758 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2759 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2762 ;; initialize template map for VHDL Mode
2763 (vhdl-template-map-init)
2765 (defun vhdl-function-name (prefix string &optional postfix)
2766 "Generate a Lisp function name.
2767 PREFIX, STRING and optional POSTFIX are concatenated by `-' and spaces in
2768 STRING are replaced by `-' and substrings are converted to lower case."
2769 (let ((name prefix))
2770 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2771 (setq name
2772 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2773 (setq string (substring string (match-beginning 2))))
2774 (when postfix (setq name (concat name "-" postfix)))
2775 (intern name)))
2777 (defvar vhdl-model-map nil
2778 "Keymap for VHDL models.")
2780 (defun vhdl-model-map-init ()
2781 "Initialize `vhdl-model-map'."
2782 (setq vhdl-model-map (make-sparse-keymap))
2783 ;; key bindings for VHDL models
2784 (let ((model-alist vhdl-model-alist) model)
2785 (while model-alist
2786 (setq model (car model-alist))
2787 (define-key vhdl-model-map (nth 2 model)
2788 (vhdl-function-name "vhdl-model" (nth 0 model)))
2789 (setq model-alist (cdr model-alist)))))
2791 ;; initialize user model map for VHDL Mode
2792 (vhdl-model-map-init)
2794 (defvar vhdl-mode-map nil
2795 "Keymap for VHDL Mode.")
2797 (defun vhdl-mode-map-init ()
2798 "Initialize `vhdl-mode-map'."
2799 (setq vhdl-mode-map (make-sparse-keymap))
2800 ;; template key bindings
2801 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2802 ;; model key bindings
2803 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2804 ;; standard key bindings
2805 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2806 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2807 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2808 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2809 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2810 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2811 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2812 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2813 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2814 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2815 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2816 ;; mode specific key bindings
2817 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2818 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2819 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2820 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2821 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2822 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2823 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2824 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2825 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2826 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2827 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2828 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2829 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2830 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2831 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2832 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2833 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2834 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2835 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2836 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2837 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2838 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2839 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2840 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2841 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2842 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2843 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2844 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2845 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2846 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2847 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2848 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2849 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2850 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2851 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2852 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2853 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2854 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2855 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2856 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2857 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2858 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2859 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2860 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2861 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2862 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2863 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2864 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2865 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2866 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2867 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2868 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2869 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2870 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2871 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2872 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2873 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2874 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2875 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2876 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2877 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2878 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2879 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2880 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2881 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2882 (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
2883 (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
2884 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2885 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2886 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2887 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2888 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2889 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2890 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2891 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2892 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2893 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2894 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2895 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2896 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2897 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2898 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2899 ;; insert commands bindings
2900 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2901 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2902 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2903 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2904 ;; electric key bindings
2905 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2906 (when vhdl-intelligent-tab
2907 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2908 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2909 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2910 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2911 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2912 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2913 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2914 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2915 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2916 (when (vhdl-standard-p 'ams)
2917 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2919 ;; initialize mode map for VHDL Mode
2920 (vhdl-mode-map-init)
2922 ;; define special minibuffer keymap for enabling word completion in minibuffer
2923 ;; (useful in template generator prompts)
2924 (defvar vhdl-minibuffer-local-map
2925 (let ((map (make-sparse-keymap)))
2926 (set-keymap-parent map minibuffer-local-map)
2927 (when vhdl-word-completion-in-minibuffer
2928 (define-key map "\t" 'vhdl-minibuffer-tab))
2929 map)
2930 "Keymap for minibuffer used in VHDL Mode.")
2932 ;; set up electric character functions to work with
2933 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2934 (mapc
2935 (function
2936 (lambda (sym)
2937 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2938 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2939 '(vhdl-electric-space
2940 vhdl-electric-tab
2941 vhdl-electric-return
2942 vhdl-electric-dash
2943 vhdl-electric-open-bracket
2944 vhdl-electric-close-bracket
2945 vhdl-electric-quote
2946 vhdl-electric-semicolon
2947 vhdl-electric-comma
2948 vhdl-electric-period
2949 vhdl-electric-equal))
2951 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2952 ;; Syntax table
2954 (defvar vhdl-mode-syntax-table
2955 (let ((st (make-syntax-table)))
2956 ;; define punctuation
2957 (modify-syntax-entry ?\# "." st)
2958 (modify-syntax-entry ?\$ "." st)
2959 (modify-syntax-entry ?\% "." st)
2960 (modify-syntax-entry ?\& "." st)
2961 (modify-syntax-entry ?\' "." st)
2962 (modify-syntax-entry ?\* "." st)
2963 (modify-syntax-entry ?\+ "." st)
2964 (modify-syntax-entry ?\. "." st)
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 ;; define string
2974 (modify-syntax-entry ?\" "\"" st)
2975 ;; define underscore
2976 (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
2977 ;; single-line comments
2978 (modify-syntax-entry ?\- ". 12b" st)
2979 ;; multi-line comments
2980 (modify-syntax-entry ?\/ ". 14b" st)
2981 (modify-syntax-entry ?* ". 23" st)
2982 (modify-syntax-entry ?\n "> b" st)
2983 (modify-syntax-entry ?\^M "> b" st)
2984 ;; define parentheses to match
2985 (modify-syntax-entry ?\( "()" st)
2986 (modify-syntax-entry ?\) ")(" st)
2987 (modify-syntax-entry ?\[ "(]" st)
2988 (modify-syntax-entry ?\] ")[" st)
2989 (modify-syntax-entry ?\{ "(}" st)
2990 (modify-syntax-entry ?\} "){" st)
2992 "Syntax table used in `vhdl-mode' buffers.")
2994 (defvar vhdl-mode-ext-syntax-table
2995 ;; Extended syntax table including '_' (for simpler search regexps).
2996 (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
2997 (modify-syntax-entry ?_ "w" st)
2999 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
3001 (defvar vhdl-syntactic-context nil
3002 "Buffer local variable containing syntactic analysis list.")
3003 (make-variable-buffer-local 'vhdl-syntactic-context)
3005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3006 ;; Abbrev hook bindings
3008 (defvar vhdl-mode-abbrev-table nil
3009 "Abbrev table to use in `vhdl-mode' buffers.")
3011 (defun vhdl-mode-abbrev-table-init ()
3012 "Initialize `vhdl-mode-abbrev-table'."
3013 (define-abbrev-table 'vhdl-mode-abbrev-table
3014 (append
3015 (when (memq 'vhdl vhdl-electric-keywords)
3016 ;; VHDL'02 keywords
3017 (mapcar (if (featurep 'xemacs)
3018 (lambda (x) (list (car x) "" (cdr x) 0))
3019 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3021 ("--" . vhdl-template-display-comment-hook)
3022 ("abs" . vhdl-template-default-hook)
3023 ("access" . vhdl-template-default-hook)
3024 ("after" . vhdl-template-default-hook)
3025 ("alias" . vhdl-template-alias-hook)
3026 ("all" . vhdl-template-default-hook)
3027 ("and" . vhdl-template-default-hook)
3028 ("arch" . vhdl-template-architecture-hook)
3029 ("architecture" . vhdl-template-architecture-hook)
3030 ("array" . vhdl-template-default-hook)
3031 ("assert" . vhdl-template-assert-hook)
3032 ("attr" . vhdl-template-attribute-hook)
3033 ("attribute" . vhdl-template-attribute-hook)
3034 ("begin" . vhdl-template-default-indent-hook)
3035 ("block" . vhdl-template-block-hook)
3036 ("body" . vhdl-template-default-hook)
3037 ("buffer" . vhdl-template-default-hook)
3038 ("bus" . vhdl-template-default-hook)
3039 ("case" . vhdl-template-case-hook)
3040 ("comp" . vhdl-template-component-hook)
3041 ("component" . vhdl-template-component-hook)
3042 ("cond" . vhdl-template-conditional-signal-asst-hook)
3043 ("conditional" . vhdl-template-conditional-signal-asst-hook)
3044 ("conf" . vhdl-template-configuration-hook)
3045 ("configuration" . vhdl-template-configuration-hook)
3046 ("cons" . vhdl-template-constant-hook)
3047 ("constant" . vhdl-template-constant-hook)
3048 ("context" . vhdl-template-context-hook)
3049 ("disconnect" . vhdl-template-disconnect-hook)
3050 ("downto" . vhdl-template-default-hook)
3051 ("else" . vhdl-template-else-hook)
3052 ("elseif" . vhdl-template-elsif-hook)
3053 ("elsif" . vhdl-template-elsif-hook)
3054 ("end" . vhdl-template-default-indent-hook)
3055 ("entity" . vhdl-template-entity-hook)
3056 ("exit" . vhdl-template-exit-hook)
3057 ("file" . vhdl-template-file-hook)
3058 ("for" . vhdl-template-for-hook)
3059 ("func" . vhdl-template-function-hook)
3060 ("function" . vhdl-template-function-hook)
3061 ("generic" . vhdl-template-generic-hook)
3062 ("group" . vhdl-template-group-hook)
3063 ("guarded" . vhdl-template-default-hook)
3064 ("if" . vhdl-template-if-hook)
3065 ("impure" . vhdl-template-default-hook)
3066 ("in" . vhdl-template-default-hook)
3067 ("inertial" . vhdl-template-default-hook)
3068 ("inout" . vhdl-template-default-hook)
3069 ("inst" . vhdl-template-instance-hook)
3070 ("instance" . vhdl-template-instance-hook)
3071 ("is" . vhdl-template-default-hook)
3072 ("label" . vhdl-template-default-hook)
3073 ("library" . vhdl-template-library-hook)
3074 ("linkage" . vhdl-template-default-hook)
3075 ("literal" . vhdl-template-default-hook)
3076 ("loop" . vhdl-template-bare-loop-hook)
3077 ("map" . vhdl-template-map-hook)
3078 ("mod" . vhdl-template-default-hook)
3079 ("nand" . vhdl-template-default-hook)
3080 ("new" . vhdl-template-default-hook)
3081 ("next" . vhdl-template-next-hook)
3082 ("nor" . vhdl-template-default-hook)
3083 ("not" . vhdl-template-default-hook)
3084 ("null" . vhdl-template-default-hook)
3085 ("of" . vhdl-template-default-hook)
3086 ("on" . vhdl-template-default-hook)
3087 ("open" . vhdl-template-default-hook)
3088 ("or" . vhdl-template-default-hook)
3089 ("others" . vhdl-template-others-hook)
3090 ("out" . vhdl-template-default-hook)
3091 ("pack" . vhdl-template-package-hook)
3092 ("package" . vhdl-template-package-hook)
3093 ("port" . vhdl-template-port-hook)
3094 ("postponed" . vhdl-template-default-hook)
3095 ("procedure" . vhdl-template-procedure-hook)
3096 ("process" . vhdl-template-process-hook)
3097 ("pure" . vhdl-template-default-hook)
3098 ("range" . vhdl-template-default-hook)
3099 ("record" . vhdl-template-default-hook)
3100 ("register" . vhdl-template-default-hook)
3101 ("reject" . vhdl-template-default-hook)
3102 ("rem" . vhdl-template-default-hook)
3103 ("report" . vhdl-template-report-hook)
3104 ("return" . vhdl-template-return-hook)
3105 ("rol" . vhdl-template-default-hook)
3106 ("ror" . vhdl-template-default-hook)
3107 ("select" . vhdl-template-selected-signal-asst-hook)
3108 ("severity" . vhdl-template-default-hook)
3109 ("shared" . vhdl-template-default-hook)
3110 ("sig" . vhdl-template-signal-hook)
3111 ("signal" . vhdl-template-signal-hook)
3112 ("sla" . vhdl-template-default-hook)
3113 ("sll" . vhdl-template-default-hook)
3114 ("sra" . vhdl-template-default-hook)
3115 ("srl" . vhdl-template-default-hook)
3116 ("subtype" . vhdl-template-subtype-hook)
3117 ("then" . vhdl-template-default-hook)
3118 ("to" . vhdl-template-default-hook)
3119 ("transport" . vhdl-template-default-hook)
3120 ("type" . vhdl-template-type-hook)
3121 ("unaffected" . vhdl-template-default-hook)
3122 ("units" . vhdl-template-default-hook)
3123 ("until" . vhdl-template-default-hook)
3124 ("use" . vhdl-template-use-hook)
3125 ("var" . vhdl-template-variable-hook)
3126 ("variable" . vhdl-template-variable-hook)
3127 ("wait" . vhdl-template-wait-hook)
3128 ("when" . vhdl-template-when-hook)
3129 ("while" . vhdl-template-while-loop-hook)
3130 ("with" . vhdl-template-with-hook)
3131 ("xnor" . vhdl-template-default-hook)
3132 ("xor" . vhdl-template-default-hook)
3134 ;; VHDL-AMS keywords
3135 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3136 (mapcar (if (featurep 'xemacs)
3137 (lambda (x) (list (car x) "" (cdr x) 0))
3138 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3140 ("across" . vhdl-template-default-hook)
3141 ("break" . vhdl-template-break-hook)
3142 ("limit" . vhdl-template-limit-hook)
3143 ("nature" . vhdl-template-nature-hook)
3144 ("noise" . vhdl-template-default-hook)
3145 ("procedural" . vhdl-template-procedural-hook)
3146 ("quantity" . vhdl-template-quantity-hook)
3147 ("reference" . vhdl-template-default-hook)
3148 ("spectrum" . vhdl-template-default-hook)
3149 ("subnature" . vhdl-template-subnature-hook)
3150 ("terminal" . vhdl-template-terminal-hook)
3151 ("through" . vhdl-template-default-hook)
3152 ("tolerance" . vhdl-template-default-hook)
3154 ;; user model keywords
3155 (when (memq 'user vhdl-electric-keywords)
3156 (let (abbrev-list keyword)
3157 (dolist (elem vhdl-model-alist)
3158 (setq keyword (nth 3 elem))
3159 (unless (equal keyword "")
3160 (push (list keyword ""
3161 (vhdl-function-name
3162 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3163 abbrev-list)))
3164 abbrev-list)))))
3166 ;; initialize abbrev table for VHDL Mode
3167 (vhdl-mode-abbrev-table-init)
3169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3170 ;; Template completion lists
3172 (defvar vhdl-template-construct-alist nil
3173 "List of built-in construct templates.")
3175 (defun vhdl-template-construct-alist-init ()
3176 "Initialize `vhdl-template-construct-alist'."
3177 (setq
3178 vhdl-template-construct-alist
3179 (append
3181 ("alias declaration" vhdl-template-alias)
3182 ("architecture body" vhdl-template-architecture)
3183 ("assertion" vhdl-template-assert)
3184 ("attribute declaration" vhdl-template-attribute-decl)
3185 ("attribute specification" vhdl-template-attribute-spec)
3186 ("block configuration" vhdl-template-block-configuration)
3187 ("block statement" vhdl-template-block)
3188 ("case statement" vhdl-template-case-is)
3189 ("component configuration" vhdl-template-component-conf)
3190 ("component declaration" vhdl-template-component-decl)
3191 ("component instantiation statement" vhdl-template-component-inst)
3192 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3193 ("configuration declaration" vhdl-template-configuration-decl)
3194 ("configuration specification" vhdl-template-configuration-spec)
3195 ("constant declaration" vhdl-template-constant)
3196 ("context declaration" vhdl-template-context)
3197 ("disconnection specification" vhdl-template-disconnect)
3198 ("entity declaration" vhdl-template-entity)
3199 ("exit statement" vhdl-template-exit)
3200 ("file declaration" vhdl-template-file)
3201 ("generate statement" vhdl-template-generate)
3202 ("generic clause" vhdl-template-generic)
3203 ("group declaration" vhdl-template-group-decl)
3204 ("group template declaration" vhdl-template-group-template)
3205 ("if statement" vhdl-template-if-then)
3206 ("library clause" vhdl-template-library)
3207 ("loop statement" vhdl-template-loop)
3208 ("next statement" vhdl-template-next)
3209 ("package declaration" vhdl-template-package-decl)
3210 ("package body" vhdl-template-package-body)
3211 ("port clause" vhdl-template-port)
3212 ("process statement" vhdl-template-process)
3213 ("report statement" vhdl-template-report)
3214 ("return statement" vhdl-template-return)
3215 ("selected signal assignment" vhdl-template-selected-signal-asst)
3216 ("signal declaration" vhdl-template-signal)
3217 ("subprogram declaration" vhdl-template-subprogram-decl)
3218 ("subprogram body" vhdl-template-subprogram-body)
3219 ("subtype declaration" vhdl-template-subtype)
3220 ("type declaration" vhdl-template-type)
3221 ("use clause" vhdl-template-use)
3222 ("variable declaration" vhdl-template-variable)
3223 ("wait statement" vhdl-template-wait)
3225 (when (vhdl-standard-p 'ams)
3227 ("break statement" vhdl-template-break)
3228 ("nature declaration" vhdl-template-nature)
3229 ("quantity declaration" vhdl-template-quantity)
3230 ("simultaneous case statement" vhdl-template-case-use)
3231 ("simultaneous if statement" vhdl-template-if-use)
3232 ("simultaneous procedural statement" vhdl-template-procedural)
3233 ("step limit specification" vhdl-template-limit)
3234 ("subnature declaration" vhdl-template-subnature)
3235 ("terminal declaration" vhdl-template-terminal)
3236 )))))
3238 ;; initialize for VHDL Mode
3239 (vhdl-template-construct-alist-init)
3241 (defvar vhdl-template-package-alist nil
3242 "List of built-in package templates.")
3244 (defun vhdl-template-package-alist-init ()
3245 "Initialize `vhdl-template-package-alist'."
3246 (setq
3247 vhdl-template-package-alist
3248 (append
3250 ("numeric_bit" vhdl-template-package-numeric-bit)
3251 ("numeric_std" vhdl-template-package-numeric-std)
3252 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3253 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3254 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3255 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3256 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3257 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3258 ("textio" vhdl-template-package-textio)
3260 (when (vhdl-standard-p 'math)
3262 ("math_complex" vhdl-template-package-math-complex)
3263 ("math_real" vhdl-template-package-math-real)
3264 )))))
3266 ;; initialize for VHDL Mode
3267 (vhdl-template-package-alist-init)
3269 (defvar vhdl-template-directive-alist
3271 ("translate_on" vhdl-template-directive-translate-on)
3272 ("translate_off" vhdl-template-directive-translate-off)
3273 ("synthesis_on" vhdl-template-directive-synthesis-on)
3274 ("synthesis_off" vhdl-template-directive-synthesis-off)
3276 "List of built-in directive templates.")
3279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3280 ;;; Menus
3281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3284 ;; VHDL menu (using `easy-menu.el')
3286 (defun vhdl-customize ()
3287 "Call the customize function with `vhdl' as argument."
3288 (interactive)
3289 (customize-browse 'vhdl))
3291 (defun vhdl-create-mode-menu ()
3292 "Create VHDL Mode menu."
3293 `("VHDL"
3294 ,(append
3295 '("Project"
3296 ["None" (vhdl-set-project "")
3297 :style radio :selected (null vhdl-project)]
3298 "--")
3299 ;; add menu entries for defined projects
3300 (let ((project-alist vhdl-project-alist) menu-list name)
3301 (while project-alist
3302 (setq name (caar project-alist))
3303 (setq menu-list
3304 (cons `[,name (vhdl-set-project ,name)
3305 :style radio :selected (equal ,name vhdl-project)]
3306 menu-list))
3307 (setq project-alist (cdr project-alist)))
3308 (setq menu-list
3309 (if vhdl-project-sort
3310 (sort menu-list
3311 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3312 (nreverse menu-list)))
3313 (vhdl-menu-split menu-list "Project"))
3314 '("--" "--"
3315 ["Select Project..." vhdl-set-project t]
3316 ["Set As Default Project" vhdl-set-default-project t]
3317 "--"
3318 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3319 ["Import Project..." vhdl-import-project
3320 :keys "C-c C-p C-m" :active t]
3321 ["Export Project" vhdl-export-project vhdl-project]
3322 "--"
3323 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3324 "--"
3325 ("Compile"
3326 ["Compile Buffer" vhdl-compile t]
3327 ["Stop Compilation" kill-compilation t]
3328 "--"
3329 ["Make" vhdl-make t]
3330 ["Generate Makefile" vhdl-generate-makefile t]
3331 "--"
3332 ["Next Error" next-error t]
3333 ["Previous Error" previous-error t]
3334 ["First Error" first-error t]
3335 "--"
3336 ,(append
3337 '("Compiler")
3338 ;; add menu entries for defined compilers
3339 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3340 (while comp-alist
3341 (setq name (caar comp-alist))
3342 (setq menu-list
3343 (cons `[,name (setq vhdl-compiler ,name)
3344 :style radio :selected (equal ,name vhdl-compiler)]
3345 menu-list))
3346 (setq comp-alist (cdr comp-alist)))
3347 (setq menu-list (nreverse menu-list))
3348 (vhdl-menu-split menu-list "Compiler"))
3349 '("--" "--"
3350 ["Select Compiler..." vhdl-set-compiler t]
3351 "--"
3352 ["Customize Compiler..."
3353 (customize-option 'vhdl-compiler-alist) t])))
3354 "--"
3355 ,(append
3356 '("Template"
3357 ("VHDL Construct 1"
3358 ["Alias" vhdl-template-alias t]
3359 ["Architecture" vhdl-template-architecture t]
3360 ["Assert" vhdl-template-assert t]
3361 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3362 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3363 ["Block" vhdl-template-block t]
3364 ["Case" vhdl-template-case-is t]
3365 ["Component (Decl)" vhdl-template-component-decl t]
3366 ["(Component) Instance" vhdl-template-component-inst t]
3367 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3368 ["Configuration (Block)" vhdl-template-block-configuration t]
3369 ["Configuration (Comp)" vhdl-template-component-conf t]
3370 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3371 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3372 ["Constant" vhdl-template-constant t]
3373 ["Context" vhdl-template-context t]
3374 ["Disconnect" vhdl-template-disconnect t]
3375 ["Else" vhdl-template-else t]
3376 ["Elsif" vhdl-template-elsif t]
3377 ["Entity" vhdl-template-entity t]
3378 ["Exit" vhdl-template-exit t]
3379 ["File" vhdl-template-file t]
3380 ["For (Generate)" vhdl-template-for-generate t]
3381 ["For (Loop)" vhdl-template-for-loop t]
3382 ["Function (Body)" vhdl-template-function-body t]
3383 ["Function (Decl)" vhdl-template-function-decl t]
3384 ["Generic" vhdl-template-generic t]
3385 ["Group (Decl)" vhdl-template-group-decl t]
3386 ["Group (Template)" vhdl-template-group-template t])
3387 ("VHDL Construct 2"
3388 ["If (Generate)" vhdl-template-if-generate t]
3389 ["If (Then)" vhdl-template-if-then t]
3390 ["Library" vhdl-template-library t]
3391 ["Loop" vhdl-template-bare-loop t]
3392 ["Map" vhdl-template-map t]
3393 ["Next" vhdl-template-next t]
3394 ["Others (Aggregate)" vhdl-template-others t]
3395 ["Package (Decl)" vhdl-template-package-decl t]
3396 ["Package (Body)" vhdl-template-package-body t]
3397 ["Port" vhdl-template-port t]
3398 ["Procedure (Body)" vhdl-template-procedure-body t]
3399 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3400 ["Process (Comb)" vhdl-template-process-comb t]
3401 ["Process (Seq)" vhdl-template-process-seq t]
3402 ["Report" vhdl-template-report t]
3403 ["Return" vhdl-template-return t]
3404 ["Select" vhdl-template-selected-signal-asst t]
3405 ["Signal" vhdl-template-signal t]
3406 ["Subtype" vhdl-template-subtype t]
3407 ["Type" vhdl-template-type t]
3408 ["Use" vhdl-template-use t]
3409 ["Variable" vhdl-template-variable t]
3410 ["Wait" vhdl-template-wait t]
3411 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3412 ["When" vhdl-template-when t]
3413 ["While (Loop)" vhdl-template-while-loop t]
3414 ["With" vhdl-template-with t]))
3415 (when (vhdl-standard-p 'ams)
3416 '(("VHDL-AMS Construct"
3417 ["Break" vhdl-template-break t]
3418 ["Case (Use)" vhdl-template-case-use t]
3419 ["If (Use)" vhdl-template-if-use t]
3420 ["Limit" vhdl-template-limit t]
3421 ["Nature" vhdl-template-nature t]
3422 ["Procedural" vhdl-template-procedural t]
3423 ["Quantity (Free)" vhdl-template-quantity-free t]
3424 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3425 ["Quantity (Source)" vhdl-template-quantity-source t]
3426 ["Subnature" vhdl-template-subnature t]
3427 ["Terminal" vhdl-template-terminal t])))
3428 '(["Insert Construct..." vhdl-template-insert-construct
3429 :keys "C-c C-i C-t"]
3430 "--")
3431 (list
3432 (append
3433 '("Package")
3434 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3435 ["numeric_std" vhdl-template-package-numeric-std t]
3436 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3437 ["textio" vhdl-template-package-textio t]
3438 "--"
3439 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3440 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3441 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3442 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3443 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3444 "--")
3445 (when (vhdl-standard-p 'ams)
3446 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3447 ["material_constants" vhdl-template-package-material-constants t]
3448 ["energy_systems" vhdl-template-package-energy-systems t]
3449 ["electrical_systems" vhdl-template-package-electrical-systems t]
3450 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3451 ["radiant_systems" vhdl-template-package-radiant-systems t]
3452 ["thermal_systems" vhdl-template-package-thermal-systems t]
3453 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3454 "--"))
3455 (when (vhdl-standard-p 'math)
3456 '(["math_complex" vhdl-template-package-math-complex t]
3457 ["math_real" vhdl-template-package-math-real t]
3458 "--"))
3459 '(["Insert Package..." vhdl-template-insert-package
3460 :keys "C-c C-i C-p"])))
3461 '(("Directive"
3462 ["translate_on" vhdl-template-directive-translate-on t]
3463 ["translate_off" vhdl-template-directive-translate-off t]
3464 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3465 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3466 "--"
3467 ["Insert Directive..." vhdl-template-insert-directive
3468 :keys "C-c C-i C-d"])
3469 "--"
3470 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3471 ["Insert Footer" vhdl-template-footer t]
3472 ["Insert Date" vhdl-template-insert-date t]
3473 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3474 "--"
3475 ["Query Next Prompt" vhdl-template-search-prompt t]))
3476 ,(append
3477 '("Model")
3478 ;; add menu entries for defined models
3479 (let ((model-alist vhdl-model-alist) menu-list model)
3480 (while model-alist
3481 (setq model (car model-alist))
3482 (setq menu-list
3483 (cons
3484 (vector
3485 (nth 0 model)
3486 (vhdl-function-name "vhdl-model" (nth 0 model))
3487 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3488 menu-list))
3489 (setq model-alist (cdr model-alist)))
3490 (setq menu-list (nreverse menu-list))
3491 (vhdl-menu-split menu-list "Model"))
3492 '("--" "--"
3493 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3494 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3495 ("Port"
3496 ["Copy" vhdl-port-copy t]
3497 "--"
3498 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3499 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3500 ["Paste As Instance" vhdl-port-paste-instance
3501 :keys "C-c C-p C-i" :active vhdl-port-list]
3502 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3503 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3504 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3505 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3506 "--"
3507 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3508 "--"
3509 ["Flatten" vhdl-port-flatten
3510 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3511 ["Reverse Direction" vhdl-port-reverse-direction
3512 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3513 ("Compose"
3514 ["New Component" vhdl-compose-new-component t]
3515 ["Copy Component" vhdl-port-copy t]
3516 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3517 ["Wire Components" vhdl-compose-wire-components t]
3518 "--"
3519 ["Generate Configuration" vhdl-compose-configuration t]
3520 ["Generate Components Package" vhdl-compose-components-package t])
3521 ("Subprogram"
3522 ["Copy" vhdl-subprog-copy t]
3523 "--"
3524 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3525 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3526 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3527 "--"
3528 ["Flatten" vhdl-subprog-flatten
3529 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3530 "--"
3531 ("Comment"
3532 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3533 "--"
3534 ["Insert Inline Comment" vhdl-comment-append-inline t]
3535 ["Insert Horizontal Line" vhdl-comment-display-line t]
3536 ["Insert Display Comment" vhdl-comment-display t]
3537 "--"
3538 ["Fill Comment" fill-paragraph t]
3539 ["Fill Comment Region" fill-region (mark)]
3540 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3541 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3542 ("Line"
3543 ["Kill" vhdl-line-kill t]
3544 ["Copy" vhdl-line-copy t]
3545 ["Yank" vhdl-line-yank t]
3546 ["Expand" vhdl-line-expand t]
3547 "--"
3548 ["Transpose Next" vhdl-line-transpose-next t]
3549 ["Transpose Prev" vhdl-line-transpose-previous t]
3550 ["Open" vhdl-line-open t]
3551 ["Join" vhdl-delete-indentation t]
3552 "--"
3553 ["Goto" goto-line t]
3554 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3555 ("Move"
3556 ["Forward Statement" vhdl-end-of-statement t]
3557 ["Backward Statement" vhdl-beginning-of-statement t]
3558 ["Forward Expression" vhdl-forward-sexp t]
3559 ["Backward Expression" vhdl-backward-sexp t]
3560 ["Forward Same Indent" vhdl-forward-same-indent t]
3561 ["Backward Same Indent" vhdl-backward-same-indent t]
3562 ["Forward Function" vhdl-end-of-defun t]
3563 ["Backward Function" vhdl-beginning-of-defun t]
3564 ["Mark Function" vhdl-mark-defun t])
3565 "--"
3566 ("Indent"
3567 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3568 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3569 ["Region" vhdl-indent-region (mark)]
3570 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3571 ("Align"
3572 ["Group" vhdl-align-group t]
3573 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3574 ["List" vhdl-align-list t]
3575 ["Declarations" vhdl-align-declarations t]
3576 ["Region" vhdl-align-region (mark)]
3577 ["Buffer" vhdl-align-buffer t]
3578 "--"
3579 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3580 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3581 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3582 ("Fill"
3583 ["List" vhdl-fill-list t]
3584 ["Group" vhdl-fill-group t]
3585 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3586 ["Region" vhdl-fill-region (mark)])
3587 ("Beautify"
3588 ["Region" vhdl-beautify-region (mark)]
3589 ["Buffer" vhdl-beautify-buffer t])
3590 ("Fix"
3591 ["Generic/Port Clause" vhdl-fix-clause t]
3592 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3593 "--"
3594 ["Case Region" vhdl-fix-case-region (mark)]
3595 ["Case Buffer" vhdl-fix-case-buffer t]
3596 "--"
3597 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3598 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3599 "--"
3600 ["Statement Region" vhdl-fix-statement-region (mark)]
3601 ["Statement Buffer" vhdl-fix-statement-buffer t]
3602 "--"
3603 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3604 ("Update"
3605 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3606 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3607 "--"
3608 ["Fontify Buffer" vhdl-fontify-buffer t]
3609 ["Statistics Buffer" vhdl-statistics-buffer t]
3610 ["Show Messages" vhdl-show-messages t]
3611 ["Syntactic Info" vhdl-show-syntactic-information t]
3612 "--"
3613 ["Speedbar" vhdl-speedbar t]
3614 ["Hide/Show" vhdl-hs-minor-mode t]
3615 "--"
3616 ("Documentation"
3617 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3618 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3619 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3620 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3621 ["Version" vhdl-version t]
3622 ["Bug Report..." vhdl-submit-bug-report t]
3623 "--"
3624 ("Options"
3625 ("Mode"
3626 ["Electric Mode"
3627 (progn (customize-set-variable 'vhdl-electric-mode
3628 (not vhdl-electric-mode))
3629 (vhdl-mode-line-update))
3630 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3631 ["Stutter Mode"
3632 (progn (customize-set-variable 'vhdl-stutter-mode
3633 (not vhdl-stutter-mode))
3634 (vhdl-mode-line-update))
3635 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3636 ["Indent Tabs Mode"
3637 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3638 (not vhdl-indent-tabs-mode))
3639 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3640 :style toggle :selected vhdl-indent-tabs-mode]
3641 "--"
3642 ["Customize Group..." (customize-group 'vhdl-mode) t])
3643 ("Project"
3644 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3645 ,(append
3646 '("Selected Project at Startup"
3647 ["None" (progn (customize-set-variable 'vhdl-project nil)
3648 (vhdl-set-project ""))
3649 :style radio :selected (null vhdl-project)]
3650 "--")
3651 ;; add menu entries for defined projects
3652 (let ((project-alist vhdl-project-alist) menu-list name)
3653 (while project-alist
3654 (setq name (caar project-alist))
3655 (setq menu-list
3656 (cons `[,name (progn (customize-set-variable
3657 'vhdl-project ,name)
3658 (vhdl-set-project ,name))
3659 :style radio :selected (equal ,name vhdl-project)]
3660 menu-list))
3661 (setq project-alist (cdr project-alist)))
3662 (setq menu-list (nreverse menu-list))
3663 (vhdl-menu-split menu-list "Project")))
3664 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3665 ("Auto Load Setup File"
3666 ["At Startup"
3667 (customize-set-variable 'vhdl-project-auto-load
3668 (if (memq 'startup vhdl-project-auto-load)
3669 (delq 'startup vhdl-project-auto-load)
3670 (cons 'startup vhdl-project-auto-load)))
3671 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3672 ["Sort Projects"
3673 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3674 :style toggle :selected vhdl-project-sort]
3675 "--"
3676 ["Customize Group..." (customize-group 'vhdl-project) t])
3677 ("Compiler"
3678 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3679 ,(append
3680 '("Selected Compiler at Startup")
3681 ;; add menu entries for defined compilers
3682 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3683 (while comp-alist
3684 (setq name (caar comp-alist))
3685 (setq menu-list
3686 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3687 :style radio :selected (equal ,name vhdl-compiler)]
3688 menu-list))
3689 (setq comp-alist (cdr comp-alist)))
3690 (setq menu-list (nreverse menu-list))
3691 (vhdl-menu-split menu-list "Compiler")))
3692 ["Use Local Error Regexp"
3693 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3694 (not vhdl-compile-use-local-error-regexp))
3695 :style toggle :selected vhdl-compile-use-local-error-regexp]
3696 ["Makefile Default Targets..."
3697 (customize-option 'vhdl-makefile-default-targets) t]
3698 ["Makefile Generation Hook..."
3699 (customize-option 'vhdl-makefile-generation-hook) t]
3700 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3701 "--"
3702 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3703 ("Style"
3704 ("VHDL Standard"
3705 ["VHDL'87"
3706 (progn (customize-set-variable 'vhdl-standard
3707 (list '87 (cadr vhdl-standard)))
3708 (vhdl-activate-customizations))
3709 :style radio :selected (eq '87 (car vhdl-standard))]
3710 ["VHDL'93/02"
3711 (progn (customize-set-variable 'vhdl-standard
3712 (list '93 (cadr vhdl-standard)))
3713 (vhdl-activate-customizations))
3714 :style radio :selected (eq '93 (car vhdl-standard))]
3715 ["VHDL'08"
3716 (progn (customize-set-variable 'vhdl-standard
3717 (list '08 (cadr vhdl-standard)))
3718 (vhdl-activate-customizations))
3719 :style radio :selected (eq '08 (car vhdl-standard))]
3720 "--"
3721 ["VHDL-AMS"
3722 (progn (customize-set-variable
3723 'vhdl-standard (list (car vhdl-standard)
3724 (if (memq 'ams (cadr vhdl-standard))
3725 (delq 'ams (cadr vhdl-standard))
3726 (cons 'ams (cadr vhdl-standard)))))
3727 (vhdl-activate-customizations))
3728 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3729 ["Math Packages"
3730 (progn (customize-set-variable
3731 'vhdl-standard (list (car vhdl-standard)
3732 (if (memq 'math (cadr vhdl-standard))
3733 (delq 'math (cadr vhdl-standard))
3734 (cons 'math (cadr vhdl-standard)))))
3735 (vhdl-activate-customizations))
3736 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3737 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3738 ["Upper Case Keywords"
3739 (customize-set-variable 'vhdl-upper-case-keywords
3740 (not vhdl-upper-case-keywords))
3741 :style toggle :selected vhdl-upper-case-keywords]
3742 ["Upper Case Types"
3743 (customize-set-variable 'vhdl-upper-case-types
3744 (not vhdl-upper-case-types))
3745 :style toggle :selected vhdl-upper-case-types]
3746 ["Upper Case Attributes"
3747 (customize-set-variable 'vhdl-upper-case-attributes
3748 (not vhdl-upper-case-attributes))
3749 :style toggle :selected vhdl-upper-case-attributes]
3750 ["Upper Case Enumeration Values"
3751 (customize-set-variable 'vhdl-upper-case-enum-values
3752 (not vhdl-upper-case-enum-values))
3753 :style toggle :selected vhdl-upper-case-enum-values]
3754 ["Upper Case Constants"
3755 (customize-set-variable 'vhdl-upper-case-constants
3756 (not vhdl-upper-case-constants))
3757 :style toggle :selected vhdl-upper-case-constants]
3758 ("Use Direct Instantiation"
3759 ["Never"
3760 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3761 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3762 ["Standard"
3763 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3764 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3765 ["Always"
3766 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3767 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3768 ["Include Array Index and Record Field in Sensitivity List"
3769 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3770 (not vhdl-array-index-record-field-in-sensitivity-list))
3771 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3772 "--"
3773 ["Customize Group..." (customize-group 'vhdl-style) t])
3774 ("Naming"
3775 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3776 ["Architecture File Name..."
3777 (customize-option 'vhdl-architecture-file-name) t]
3778 ["Configuration File Name..."
3779 (customize-option 'vhdl-configuration-file-name) t]
3780 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3781 ("File Name Case"
3782 ["As Is"
3783 (customize-set-variable 'vhdl-file-name-case 'identity)
3784 :style radio :selected (eq 'identity vhdl-file-name-case)]
3785 ["Lower Case"
3786 (customize-set-variable 'vhdl-file-name-case 'downcase)
3787 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3788 ["Upper Case"
3789 (customize-set-variable 'vhdl-file-name-case 'upcase)
3790 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3791 ["Capitalize"
3792 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3793 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3794 "--"
3795 ["Customize Group..." (customize-group 'vhdl-naming) t])
3796 ("Template"
3797 ("Electric Keywords"
3798 ["VHDL Keywords"
3799 (customize-set-variable 'vhdl-electric-keywords
3800 (if (memq 'vhdl vhdl-electric-keywords)
3801 (delq 'vhdl vhdl-electric-keywords)
3802 (cons 'vhdl vhdl-electric-keywords)))
3803 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3804 ["User Model Keywords"
3805 (customize-set-variable 'vhdl-electric-keywords
3806 (if (memq 'user vhdl-electric-keywords)
3807 (delq 'user vhdl-electric-keywords)
3808 (cons 'user vhdl-electric-keywords)))
3809 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3810 ("Insert Optional Labels"
3811 ["None"
3812 (customize-set-variable 'vhdl-optional-labels 'none)
3813 :style radio :selected (eq 'none vhdl-optional-labels)]
3814 ["Processes Only"
3815 (customize-set-variable 'vhdl-optional-labels 'process)
3816 :style radio :selected (eq 'process vhdl-optional-labels)]
3817 ["All Constructs"
3818 (customize-set-variable 'vhdl-optional-labels 'all)
3819 :style radio :selected (eq 'all vhdl-optional-labels)])
3820 ("Insert Empty Lines"
3821 ["None"
3822 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3823 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3824 ["Design Units Only"
3825 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3826 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3827 ["All Constructs"
3828 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3829 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3830 ["Argument List Indent"
3831 (customize-set-variable 'vhdl-argument-list-indent
3832 (not vhdl-argument-list-indent))
3833 :style toggle :selected vhdl-argument-list-indent]
3834 ["Association List with Formals"
3835 (customize-set-variable 'vhdl-association-list-with-formals
3836 (not vhdl-association-list-with-formals))
3837 :style toggle :selected vhdl-association-list-with-formals]
3838 ["Conditions in Parenthesis"
3839 (customize-set-variable 'vhdl-conditions-in-parenthesis
3840 (not vhdl-conditions-in-parenthesis))
3841 :style toggle :selected vhdl-conditions-in-parenthesis]
3842 ["Sensitivity List uses 'all'"
3843 (customize-set-variable 'vhdl-sensitivity-list-all
3844 (not vhdl-sensitivity-list-all))
3845 :style toggle :selected vhdl-sensitivity-list-all]
3846 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3847 ["One String..." (customize-option 'vhdl-one-string) t]
3848 ("File Header"
3849 ["Header String..." (customize-option 'vhdl-file-header) t]
3850 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3851 ["Company Name..." (customize-option 'vhdl-company-name) t]
3852 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3853 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3854 ["Date Format..." (customize-option 'vhdl-date-format) t]
3855 ["Modify Date Prefix String..."
3856 (customize-option 'vhdl-modify-date-prefix-string) t]
3857 ["Modify Date on Saving"
3858 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3859 (not vhdl-modify-date-on-saving))
3860 (vhdl-activate-customizations))
3861 :style toggle :selected vhdl-modify-date-on-saving])
3862 ("Sequential Process"
3863 ("Kind of Reset"
3864 ["None"
3865 (customize-set-variable 'vhdl-reset-kind 'none)
3866 :style radio :selected (eq 'none vhdl-reset-kind)]
3867 ["Synchronous"
3868 (customize-set-variable 'vhdl-reset-kind 'sync)
3869 :style radio :selected (eq 'sync vhdl-reset-kind)]
3870 ["Asynchronous"
3871 (customize-set-variable 'vhdl-reset-kind 'async)
3872 :style radio :selected (eq 'async vhdl-reset-kind)]
3873 ["Query"
3874 (customize-set-variable 'vhdl-reset-kind 'query)
3875 :style radio :selected (eq 'query vhdl-reset-kind)])
3876 ["Reset is Active High"
3877 (customize-set-variable 'vhdl-reset-active-high
3878 (not vhdl-reset-active-high))
3879 :style toggle :selected vhdl-reset-active-high]
3880 ["Use Rising Clock Edge"
3881 (customize-set-variable 'vhdl-clock-rising-edge
3882 (not vhdl-clock-rising-edge))
3883 :style toggle :selected vhdl-clock-rising-edge]
3884 ("Clock Edge Condition"
3885 ["Standard"
3886 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3887 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3888 ["Function \"rising_edge\""
3889 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3890 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3891 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3892 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3893 "--"
3894 ["Customize Group..." (customize-group 'vhdl-template) t])
3895 ("Model"
3896 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3897 ("Port"
3898 ["Include Port Comments"
3899 (customize-set-variable 'vhdl-include-port-comments
3900 (not vhdl-include-port-comments))
3901 :style toggle :selected vhdl-include-port-comments]
3902 ["Include Direction Comments"
3903 (customize-set-variable 'vhdl-include-direction-comments
3904 (not vhdl-include-direction-comments))
3905 :style toggle :selected vhdl-include-direction-comments]
3906 ["Include Type Comments"
3907 (customize-set-variable 'vhdl-include-type-comments
3908 (not vhdl-include-type-comments))
3909 :style toggle :selected vhdl-include-type-comments]
3910 ("Include Group Comments"
3911 ["Never"
3912 (customize-set-variable 'vhdl-include-group-comments 'never)
3913 :style radio :selected (eq 'never vhdl-include-group-comments)]
3914 ["Declarations"
3915 (customize-set-variable 'vhdl-include-group-comments 'decl)
3916 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3917 ["Always"
3918 (customize-set-variable 'vhdl-include-group-comments 'always)
3919 :style radio :selected (eq 'always vhdl-include-group-comments)])
3920 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
3921 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3922 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3923 ("Testbench"
3924 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3925 ["Architecture Name..."
3926 (customize-option 'vhdl-testbench-architecture-name) t]
3927 ["Configuration Name..."
3928 (customize-option 'vhdl-testbench-configuration-name) t]
3929 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3930 ["Include Header"
3931 (customize-set-variable 'vhdl-testbench-include-header
3932 (not vhdl-testbench-include-header))
3933 :style toggle :selected vhdl-testbench-include-header]
3934 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3935 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3936 ["Initialize Signals"
3937 (customize-set-variable 'vhdl-testbench-initialize-signals
3938 (not vhdl-testbench-initialize-signals))
3939 :style toggle :selected vhdl-testbench-initialize-signals]
3940 ["Include Library Clause"
3941 (customize-set-variable 'vhdl-testbench-include-library
3942 (not vhdl-testbench-include-library))
3943 :style toggle :selected vhdl-testbench-include-library]
3944 ["Include Configuration"
3945 (customize-set-variable 'vhdl-testbench-include-configuration
3946 (not vhdl-testbench-include-configuration))
3947 :style toggle :selected vhdl-testbench-include-configuration]
3948 ("Create Files"
3949 ["None"
3950 (customize-set-variable 'vhdl-testbench-create-files 'none)
3951 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3952 ["Single"
3953 (customize-set-variable 'vhdl-testbench-create-files 'single)
3954 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3955 ["Separate"
3956 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3957 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3958 ["Testbench Entity File Name..."
3959 (customize-option 'vhdl-testbench-entity-file-name) t]
3960 ["Testbench Architecture File Name..."
3961 (customize-option 'vhdl-testbench-architecture-file-name) t])
3962 "--"
3963 ["Customize Group..." (customize-group 'vhdl-port) t])
3964 ("Compose"
3965 ["Architecture Name..."
3966 (customize-option 'vhdl-compose-architecture-name) t]
3967 ["Configuration Name..."
3968 (customize-option 'vhdl-compose-configuration-name) t]
3969 ["Components Package Name..."
3970 (customize-option 'vhdl-components-package-name) t]
3971 ["Use Components Package"
3972 (customize-set-variable 'vhdl-use-components-package
3973 (not vhdl-use-components-package))
3974 :style toggle :selected vhdl-use-components-package]
3975 ["Include Header"
3976 (customize-set-variable 'vhdl-compose-include-header
3977 (not vhdl-compose-include-header))
3978 :style toggle :selected vhdl-compose-include-header]
3979 ("Create Entity/Architecture Files"
3980 ["None"
3981 (customize-set-variable 'vhdl-compose-create-files 'none)
3982 :style radio :selected (eq 'none vhdl-compose-create-files)]
3983 ["Single"
3984 (customize-set-variable 'vhdl-compose-create-files 'single)
3985 :style radio :selected (eq 'single vhdl-compose-create-files)]
3986 ["Separate"
3987 (customize-set-variable 'vhdl-compose-create-files 'separate)
3988 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3989 ["Create Configuration File"
3990 (customize-set-variable 'vhdl-compose-configuration-create-file
3991 (not vhdl-compose-configuration-create-file))
3992 :style toggle :selected vhdl-compose-configuration-create-file]
3993 ["Hierarchical Configuration"
3994 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3995 (not vhdl-compose-configuration-hierarchical))
3996 :style toggle :selected vhdl-compose-configuration-hierarchical]
3997 ["Use Subconfiguration"
3998 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3999 (not vhdl-compose-configuration-use-subconfiguration))
4000 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
4001 "--"
4002 ["Customize Group..." (customize-group 'vhdl-compose) t])
4003 ("Comment"
4004 ["Self Insert Comments"
4005 (customize-set-variable 'vhdl-self-insert-comments
4006 (not vhdl-self-insert-comments))
4007 :style toggle :selected vhdl-self-insert-comments]
4008 ["Prompt for Comments"
4009 (customize-set-variable 'vhdl-prompt-for-comments
4010 (not vhdl-prompt-for-comments))
4011 :style toggle :selected vhdl-prompt-for-comments]
4012 ["Inline Comment Column..."
4013 (customize-option 'vhdl-inline-comment-column) t]
4014 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
4015 "--"
4016 ["Customize Group..." (customize-group 'vhdl-comment) t])
4017 ("Beautify"
4018 ["Auto Align Templates"
4019 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
4020 :style toggle :selected vhdl-auto-align]
4021 ["Align Line Groups"
4022 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
4023 :style toggle :selected vhdl-align-groups]
4024 ["Group Separation String..."
4025 (customize-option 'vhdl-align-group-separate) t]
4026 ["Align Lines with Same Indent"
4027 (customize-set-variable 'vhdl-align-same-indent
4028 (not vhdl-align-same-indent))
4029 :style toggle :selected vhdl-align-same-indent]
4030 ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
4031 "--"
4032 ["Customize Group..." (customize-group 'vhdl-beautify) t])
4033 ("Highlight"
4034 ["Highlighting On/Off..."
4035 (customize-option
4036 (if (fboundp 'global-font-lock-mode)
4037 'global-font-lock-mode 'font-lock-auto-fontify)) t]
4038 ["Highlight Keywords"
4039 (progn (customize-set-variable 'vhdl-highlight-keywords
4040 (not vhdl-highlight-keywords))
4041 (vhdl-fontify-buffer))
4042 :style toggle :selected vhdl-highlight-keywords]
4043 ["Highlight Names"
4044 (progn (customize-set-variable 'vhdl-highlight-names
4045 (not vhdl-highlight-names))
4046 (vhdl-fontify-buffer))
4047 :style toggle :selected vhdl-highlight-names]
4048 ["Highlight Special Words"
4049 (progn (customize-set-variable 'vhdl-highlight-special-words
4050 (not vhdl-highlight-special-words))
4051 (vhdl-fontify-buffer))
4052 :style toggle :selected vhdl-highlight-special-words]
4053 ["Highlight Forbidden Words"
4054 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4055 (not vhdl-highlight-forbidden-words))
4056 (vhdl-fontify-buffer))
4057 :style toggle :selected vhdl-highlight-forbidden-words]
4058 ["Highlight Verilog Keywords"
4059 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4060 (not vhdl-highlight-verilog-keywords))
4061 (vhdl-fontify-buffer))
4062 :style toggle :selected vhdl-highlight-verilog-keywords]
4063 ["Highlight \"translate_off\""
4064 (progn (customize-set-variable 'vhdl-highlight-translate-off
4065 (not vhdl-highlight-translate-off))
4066 (vhdl-fontify-buffer))
4067 :style toggle :selected vhdl-highlight-translate-off]
4068 ["Case Sensitive Highlighting"
4069 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4070 (not vhdl-highlight-case-sensitive))
4071 (vhdl-fontify-buffer))
4072 :style toggle :selected vhdl-highlight-case-sensitive]
4073 ["Special Syntax Definition..."
4074 (customize-option 'vhdl-special-syntax-alist) t]
4075 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
4076 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
4077 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
4078 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
4079 "--"
4080 ["Customize Group..." (customize-group 'vhdl-highlight) t])
4081 ("Speedbar"
4082 ["Auto Open at Startup"
4083 (customize-set-variable 'vhdl-speedbar-auto-open
4084 (not vhdl-speedbar-auto-open))
4085 :style toggle :selected vhdl-speedbar-auto-open]
4086 ("Default Displaying Mode"
4087 ["Files"
4088 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
4089 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
4090 ["Directory Hierarchy"
4091 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
4092 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
4093 ["Project Hierarchy"
4094 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
4095 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
4096 ["Indentation Offset..."
4097 (customize-option 'speedbar-indentation-width) t]
4098 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
4099 ["Jump to Unit when Opening"
4100 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4101 (not vhdl-speedbar-jump-to-unit))
4102 :style toggle :selected vhdl-speedbar-jump-to-unit]
4103 ["Update Hierarchy on File Saving"
4104 (customize-set-variable 'vhdl-speedbar-update-on-saving
4105 (not vhdl-speedbar-update-on-saving))
4106 :style toggle :selected vhdl-speedbar-update-on-saving]
4107 ("Save in Cache File"
4108 ["Hierarchy Information"
4109 (customize-set-variable 'vhdl-speedbar-save-cache
4110 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4111 (delq 'hierarchy vhdl-speedbar-save-cache)
4112 (cons 'hierarchy vhdl-speedbar-save-cache)))
4113 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4114 ["Displaying Status"
4115 (customize-set-variable 'vhdl-speedbar-save-cache
4116 (if (memq 'display vhdl-speedbar-save-cache)
4117 (delq 'display vhdl-speedbar-save-cache)
4118 (cons 'display vhdl-speedbar-save-cache)))
4119 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4120 ["Cache File Name..."
4121 (customize-option 'vhdl-speedbar-cache-file-name) t]
4122 "--"
4123 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4124 ("Menu"
4125 ["Add Index Menu when Loading File"
4126 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4127 (vhdl-index-menu-init))
4128 :style toggle :selected vhdl-index-menu]
4129 ["Add Source File Menu when Loading File"
4130 (progn (customize-set-variable 'vhdl-source-file-menu
4131 (not vhdl-source-file-menu))
4132 (vhdl-add-source-files-menu))
4133 :style toggle :selected vhdl-source-file-menu]
4134 ["Add Hideshow Menu at Startup"
4135 (progn (customize-set-variable 'vhdl-hideshow-menu
4136 (not vhdl-hideshow-menu))
4137 (vhdl-activate-customizations))
4138 :style toggle :selected vhdl-hideshow-menu]
4139 ["Hide Everything Initially"
4140 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4141 :style toggle :selected vhdl-hide-all-init]
4142 "--"
4143 ["Customize Group..." (customize-group 'vhdl-menu) t])
4144 ("Print"
4145 ["In Two Column Format"
4146 (progn (customize-set-variable 'vhdl-print-two-column
4147 (not vhdl-print-two-column))
4148 (message "Activate new setting by saving options and restarting Emacs"))
4149 :style toggle :selected vhdl-print-two-column]
4150 ["Use Customized Faces"
4151 (progn (customize-set-variable 'vhdl-print-customize-faces
4152 (not vhdl-print-customize-faces))
4153 (message "Activate new setting by saving options and restarting Emacs"))
4154 :style toggle :selected vhdl-print-customize-faces]
4155 "--"
4156 ["Customize Group..." (customize-group 'vhdl-print) t])
4157 ("Miscellaneous"
4158 ["Use Intelligent Tab"
4159 (progn (customize-set-variable 'vhdl-intelligent-tab
4160 (not vhdl-intelligent-tab))
4161 (vhdl-activate-customizations))
4162 :style toggle :selected vhdl-intelligent-tab]
4163 ["Indent Syntax-Based"
4164 (customize-set-variable 'vhdl-indent-syntax-based
4165 (not vhdl-indent-syntax-based))
4166 :style toggle :selected vhdl-indent-syntax-based]
4167 ["Indent Comments Like Next Code Line"
4168 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4169 (not vhdl-indent-comment-like-next-code-line))
4170 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4171 ["Word Completion is Case Sensitive"
4172 (customize-set-variable 'vhdl-word-completion-case-sensitive
4173 (not vhdl-word-completion-case-sensitive))
4174 :style toggle :selected vhdl-word-completion-case-sensitive]
4175 ["Word Completion in Minibuffer"
4176 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4177 (not vhdl-word-completion-in-minibuffer))
4178 (message "Activate new setting by saving options and restarting Emacs"))
4179 :style toggle :selected vhdl-word-completion-in-minibuffer]
4180 ["Underscore is Part of Word"
4181 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4182 (not vhdl-underscore-is-part-of-word))
4183 (vhdl-activate-customizations))
4184 :style toggle :selected vhdl-underscore-is-part-of-word]
4185 "--"
4186 ["Customize Group..." (customize-group 'vhdl-misc) t])
4187 ["Related..." (customize-browse 'vhdl-related) t]
4188 "--"
4189 ["Save Options" customize-save-customized t]
4190 ["Activate Options" vhdl-activate-customizations t]
4191 ["Browse Options..." vhdl-customize t])))
4193 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4194 "VHDL Mode menu.")
4196 (defun vhdl-update-mode-menu ()
4197 "Update VHDL Mode menu."
4198 (interactive)
4199 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4200 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4201 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4202 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4203 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4206 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4208 (defconst vhdl-imenu-generic-expression
4210 ("Subprogram"
4211 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4213 ("Instance"
4214 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4216 ("Component"
4217 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4219 ("Procedural"
4220 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4222 ("Process"
4223 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4225 ("Block"
4226 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4228 ("Package"
4229 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4231 ("Configuration"
4232 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4234 ("Architecture"
4235 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4237 ("Entity"
4238 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4240 ("Context"
4241 "^\\s-*\\(context\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4244 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4246 (defun vhdl-index-menu-init ()
4247 "Initialize index menu."
4248 (set (make-local-variable 'imenu-case-fold-search) t)
4249 (set (make-local-variable 'imenu-generic-expression)
4250 vhdl-imenu-generic-expression)
4251 (when (and vhdl-index-menu (fboundp 'imenu))
4252 (imenu-add-to-menubar "Index")))
4254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4255 ;; Source file menu (using `easy-menu.el')
4257 (defvar vhdl-sources-menu nil)
4259 (defun vhdl-directory-files (directory &optional full match)
4260 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4261 message."
4262 (if (not (file-directory-p directory))
4263 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4264 (let ((dir (directory-files directory full match)))
4265 (setq dir (delete "." dir))
4266 (setq dir (delete ".." dir))
4267 dir)))
4269 (defun vhdl-get-source-files (&optional full directory)
4270 "Get list of VHDL source files in DIRECTORY or current directory."
4271 (let ((mode-alist auto-mode-alist)
4272 filename-regexp)
4273 ;; create regular expressions for matching file names
4274 (setq filename-regexp "\\`[^.].*\\(")
4275 (while mode-alist
4276 (when (eq (cdar mode-alist) 'vhdl-mode)
4277 (setq filename-regexp
4278 (concat filename-regexp (caar mode-alist) "\\|")))
4279 (setq mode-alist (cdr mode-alist)))
4280 (setq filename-regexp
4281 (concat (substring filename-regexp 0
4282 (string-match "\\\\|$" filename-regexp)) "\\)"))
4283 ;; find files
4284 (vhdl-directory-files
4285 (or directory default-directory) full filename-regexp)))
4287 (defun vhdl-add-source-files-menu ()
4288 "Scan directory for all VHDL source files and generate menu.
4289 The directory of the current source file is scanned."
4290 (interactive)
4291 (message "Scanning directory for source files ...")
4292 (let ((newmap (current-local-map))
4293 (file-list (vhdl-get-source-files))
4294 menu-list found)
4295 ;; Create list for menu
4296 (setq found nil)
4297 (while file-list
4298 (setq found t)
4299 (push (vector (car file-list) (list 'find-file (car file-list)) t)
4300 menu-list)
4301 (setq file-list (cdr file-list)))
4302 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4303 (when found (push "--" menu-list))
4304 (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
4305 (push "Sources" menu-list)
4306 ;; Create menu
4307 (easy-menu-add menu-list)
4308 (easy-menu-define vhdl-sources-menu newmap
4309 "VHDL source files menu" menu-list))
4310 (message ""))
4313 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4314 ;;; Mode definition
4315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4316 ;; performs all buffer local initializations
4318 ;;;###autoload
4319 (define-derived-mode vhdl-mode prog-mode
4320 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4321 (vhdl-electric-mode "e")
4322 (vhdl-stutter-mode "s"))
4323 "Major mode for editing VHDL code.
4325 Usage:
4326 ------
4328 TEMPLATE INSERTION (electrification):
4329 After typing a VHDL keyword and entering `SPC', you are prompted for
4330 arguments while a template is generated for that VHDL construct. Typing
4331 `RET' or `C-g' at the first (mandatory) prompt aborts the current
4332 template generation. Optional arguments are indicated by square
4333 brackets and removed if the queried string is left empty. Prompts for
4334 mandatory arguments remain in the code if the queried string is left
4335 empty. They can be queried again by `C-c C-t C-q'. Enabled
4336 electrification is indicated by `/e' in the mode line.
4338 Typing `M-SPC' after a keyword inserts a space without calling the
4339 template generator. Automatic template generation (i.e.
4340 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4341 setting option `vhdl-electric-mode' (see OPTIONS).
4343 Template generators can be invoked from the VHDL menu, by key
4344 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4345 the keyword (i.e. first word of menu entry not in parenthesis) and
4346 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4347 conf, comp, cons, func, inst, pack, sig, var.
4349 Template styles can be customized in customization group
4350 `vhdl-template' (see OPTIONS).
4353 HEADER INSERTION:
4354 A file header can be inserted by `C-c C-t C-h'. A file footer
4355 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4356 See customization group `vhdl-header'.
4359 STUTTERING:
4360 Double striking of some keys inserts cumbersome VHDL syntax elements.
4361 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4362 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4363 the mode line. The stuttering keys and their effects are:
4365 ;; --> \" : \" [ --> ( -- --> comment
4366 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4367 .. --> \" => \" ] --> ) --- --> horizontal line
4368 ,, --> \" <= \" ]] --> ] ---- --> display comment
4369 == --> \" == \" \\='\\=' --> \\\"
4372 WORD COMPLETION:
4373 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4374 word in the buffer that starts alike, inserts it and adjusts case.
4375 Re-typing `TAB' toggles through alternative word completions. This also
4376 works in the minibuffer (i.e. in template generator prompts).
4378 Typing `TAB' after `(' looks for and inserts complete parenthesized
4379 expressions (e.g. for array index ranges). All keywords as well as
4380 standard types and subprograms of VHDL have predefined abbreviations
4381 (e.g., type \"std\" and `TAB' will toggle through all standard types
4382 beginning with \"std\").
4384 Typing `TAB' after a non-word character indents the line if at the
4385 beginning of a line (i.e. no preceding non-blank characters), and
4386 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4387 stop.
4390 COMMENTS:
4391 `--' puts a single comment.
4392 `---' draws a horizontal line for separating code segments.
4393 `----' inserts a display comment, i.e. two horizontal lines
4394 with a comment in between.
4395 `--CR' comments out code on that line. Re-hitting CR comments
4396 out following lines.
4397 `C-c C-c' comments out a region if not commented out,
4398 uncomments a region if already commented out. Option
4399 `comment-style' defines where the comment characters
4400 should be placed (beginning of line, indent, etc.).
4402 You are prompted for comments after object definitions (i.e. signals,
4403 variables, constants, ports) and after subprogram and process
4404 specifications if option `vhdl-prompt-for-comments' is non-nil.
4405 Comments are automatically inserted as additional labels (e.g. after
4406 begin statements) and as help comments if `vhdl-self-insert-comments' is
4407 non-nil.
4409 Inline comments (i.e. comments after a piece of code on the same line)
4410 are indented at least to `vhdl-inline-comment-column'. Comments go at
4411 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4412 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4413 in a comment automatically opens a new comment line. `M-q' re-fills
4414 multi-line comments.
4417 INDENTATION:
4418 `TAB' indents a line if at the beginning of the line. The amount of
4419 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4420 always indents the current line (is bound to `TAB' if option
4421 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4422 the entire region.
4424 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4425 (`M-C-\\') or the entire buffer (menu). Argument and port lists are
4426 indented normally (nil) or relative to the opening parenthesis (non-nil)
4427 according to option `vhdl-argument-list-indent'.
4429 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4430 tabs. `\\[tabify]' and `\\[untabify]' allow the conversion of spaces to
4431 tabs and vice versa.
4433 Syntax-based indentation can be very slow in large files. Option
4434 `vhdl-indent-syntax-based' allows you to use faster but simpler indentation.
4436 Option `vhdl-indent-comment-like-next-code-line' controls whether
4437 comment lines are indented like the preceding or like the following code
4438 line.
4441 ALIGNMENT:
4442 The alignment functions align operators, keywords, and inline comments
4443 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4444 separated by blank lines, `C-c C-a C-i' a block of lines with same
4445 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4446 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4447 C-a C-d' all lines within the declarative part of a design unit. `C-c
4448 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4449 for a group of lines, and `C-c C-a M-c' for a region.
4451 If option `vhdl-align-groups' is non-nil, groups of code lines
4452 separated by special lines (see option `vhdl-align-group-separate') are
4453 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4454 blocks of lines with same indent are aligned separately. Some templates
4455 are automatically aligned after generation if option `vhdl-auto-align'
4456 is non-nil.
4458 Alignment tries to align inline comments at
4459 `vhdl-inline-comment-column' and tries inline comment not to exceed
4460 `vhdl-end-comment-column'.
4462 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4463 symbols are surrounded by one space, and multiple spaces are eliminated.
4466 CODE FILLING:
4467 Code filling allows you to condense code (e.g. sensitivity lists or port
4468 maps) by removing comments and newlines and re-wrapping so that all
4469 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4470 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4471 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4472 `C-c C-f M-f' an entire region.
4475 CODE BEAUTIFICATION:
4476 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4477 buffer respectively. This includes indentation, alignment, and case
4478 fixing. Code beautification can also be run non-interactively using the
4479 command:
4481 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4484 PORT TRANSLATION:
4485 Generic and port clauses from entity or component declarations can be
4486 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4487 as component instantiations and corresponding internal constants and
4488 signals, as a generic map with constants as actual generics, and as
4489 internal signal initializations (menu).
4491 To include formals in component instantiations, see option
4492 `vhdl-association-list-with-formals'. To include comments in pasting,
4493 see options `vhdl-include-...-comments'.
4495 A clause with several generic/port names on the same line can be
4496 flattened (`C-c C-p C-f') so that only one name per line exists. The
4497 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4498 outputs and vice versa, which can be useful in testbenches. (This
4499 reversion is done on the internal data structure and is only reflected
4500 in subsequent paste operations.)
4502 Names for actual ports, instances, testbenches, and
4503 design-under-test instances can be derived from existing names according
4504 to options `vhdl-...-name'. See customization group `vhdl-port'.
4507 SUBPROGRAM TRANSLATION:
4508 Similar functionality exists for copying/pasting the interface of
4509 subprograms (function/procedure). A subprogram interface can be copied
4510 and then pasted as a subprogram declaration, body or call (uses
4511 association list with formals).
4514 TESTBENCH GENERATION:
4515 A copied port can also be pasted as a testbench. The generated
4516 testbench includes an entity, an architecture, and an optional
4517 configuration. The architecture contains the component declaration and
4518 instantiation of the DUT as well as internal constant and signal
4519 declarations. Additional user-defined templates can be inserted. The
4520 names used for entity/architecture/configuration/DUT as well as the file
4521 structure to be generated can be customized. See customization group
4522 `vhdl-testbench'.
4525 KEY BINDINGS:
4526 Key bindings (`C-c ...') exist for most commands (see in menu).
4529 VHDL MENU:
4530 All commands can be found in the VHDL menu including their key bindings.
4533 FILE BROWSER:
4534 The speedbar allows browsing of directories and file contents. It can
4535 be accessed from the VHDL menu and is automatically opened if option
4536 `vhdl-speedbar-auto-open' is non-nil.
4538 In speedbar, open files and directories with `mouse-2' on the name and
4539 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4542 DESIGN HIERARCHY BROWSER:
4543 The speedbar can also be used for browsing the hierarchy of design units
4544 contained in the source files of the current directory or the specified
4545 projects (see option `vhdl-project-alist').
4547 The speedbar can be switched between file, directory hierarchy and
4548 project hierarchy browsing mode in the speedbar menu or by typing `f',
4549 `h' or `H' in speedbar.
4551 In speedbar, open design units with `mouse-2' on the name and browse
4552 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4553 from entities and components (in packages). Individual design units and
4554 complete designs can directly be compiled (\"Make\" menu entry).
4556 The hierarchy is automatically updated upon saving a modified source
4557 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4558 hierarchy is only updated for projects that have been opened once in the
4559 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4560 options in group `vhdl-speedbar').
4562 Simple design consistency checks are done during scanning, such as
4563 multiple declarations of the same unit or missing primary units that are
4564 required by secondary units.
4567 STRUCTURAL COMPOSITION:
4568 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4569 for a new component. Subcomponents (i.e. component declaration and
4570 instantiation) can be automatically placed from a previously read port
4571 (`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4572 all subcomponents can be automatically connected using internal signals
4573 and ports (`C-c C-m C-w') following these rules:
4574 - subcomponent actual ports with same name are considered to be
4575 connected by a signal (internal signal or port)
4576 - signals that are only inputs to subcomponents are considered as
4577 inputs to this component -> input port created
4578 - signals that are only outputs from subcomponents are considered as
4579 outputs from this component -> output port created
4580 - signals that are inputs to AND outputs from subcomponents are
4581 considered as internal connections -> internal signal created
4583 Purpose: With appropriate naming conventions it is possible to
4584 create higher design levels with only a few mouse clicks or key
4585 strokes. A new design level can be created by simply generating a new
4586 component, placing the required subcomponents from the hierarchy
4587 browser, and wiring everything automatically.
4589 Note: Automatic wiring only works reliably on templates of new
4590 components and component instantiations that were created by VHDL mode.
4592 Component declarations can be placed in a components package (option
4593 `vhdl-use-components-package') which can be automatically generated for
4594 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4595 component instantiation is also supported (option
4596 `vhdl-use-direct-instantiation').
4598 Configuration declarations can automatically be generated either from
4599 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4600 the speedbar menu (for the architecture under the cursor). The
4601 configurations can optionally be hierarchical (i.e. include all
4602 component levels of a hierarchical design, option
4603 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4604 (option `vhdl-compose-configuration-use-subconfiguration'). For
4605 subcomponents in hierarchical configurations, the most-recently-analyzed
4606 (mra) architecture is selected. If another architecture is desired, it
4607 can be marked as most-recently-analyzed (speedbar menu) before
4608 generating the configuration.
4610 Note: Configurations of subcomponents (i.e. hierarchical configuration
4611 declarations) are currently not considered when displaying
4612 configurations in speedbar.
4614 See the options group `vhdl-compose' for all relevant user options.
4617 SOURCE FILE COMPILATION:
4618 The syntax of the current buffer can be analyzed by calling a VHDL
4619 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4620 option `vhdl-compiler'. The available compilers are listed in option
4621 `vhdl-compiler-alist' including all required compilation command,
4622 command options, compilation directory, and error message syntax
4623 information. New compilers can be added.
4625 All the source files of an entire design can be compiled by the `make'
4626 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4629 MAKEFILE GENERATION:
4630 Makefiles can be generated automatically by an internal generation
4631 routine (`C-c M-k'). The library unit dependency information is
4632 obtained from the hierarchy browser. Makefile generation can be
4633 customized for each compiler in option `vhdl-compiler-alist'.
4635 Makefile generation can also be run non-interactively using the
4636 command:
4638 emacs -batch -l ~/.emacs -l vhdl-mode
4639 [-compiler compilername] [-project projectname]
4640 -f vhdl-generate-makefile
4642 The Makefile's default target \"all\" compiles the entire design, the
4643 target \"clean\" removes it and the target \"library\" creates the
4644 library directory if not existent. These target names can be customized
4645 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4646 target for each primary library unit which allows selective compilation
4647 of this unit, its secondary units and its subhierarchy (example:
4648 compilation of a design specified by a configuration). User specific
4649 parts can be inserted into a Makefile with option
4650 `vhdl-makefile-generation-hook'.
4652 Limitations:
4653 - Only library units and dependencies within the current library are
4654 considered. Makefiles for designs that span multiple libraries are
4655 not (yet) supported.
4656 - Only one-level configurations are supported (also hierarchical),
4657 but configurations that go down several levels are not.
4658 - The \"others\" keyword in configurations is not supported.
4661 PROJECTS:
4662 Projects can be defined in option `vhdl-project-alist' and a current
4663 project be selected using option `vhdl-project' (permanently) or from
4664 the menu or speedbar (temporarily). For each project, title and
4665 description strings (for the file headers), source files/directories
4666 (for the hierarchy browser and Makefile generation), library name, and
4667 compiler-dependent options, exceptions and compilation directory can be
4668 specified. Compilation settings overwrite the settings of option
4669 `vhdl-compiler-alist'.
4671 Project setups can be exported (i.e. written to a file) and imported.
4672 Imported setups are not automatically saved in `vhdl-project-alist' but
4673 can be saved afterwards in its customization buffer. When starting
4674 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4675 vhdl-mode\") in a directory with an existing project setup file, it is
4676 automatically loaded and its project activated if option
4677 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4678 files can be specified in option `vhdl-project-file-name'. Multiple
4679 project setups can be automatically loaded from global directories.
4680 This is an alternative to specifying project setups with option
4681 `vhdl-project-alist'.
4684 SPECIAL MENUES:
4685 As an alternative to the speedbar, an index menu can be added (set
4686 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4687 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4688 file) for browsing the file contents (is not populated if buffer is
4689 larger than 256000). Also, a source file menu can be
4690 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4691 current directory for VHDL source files.
4694 VHDL STANDARDS:
4695 The VHDL standards to be used are specified in option `vhdl-standard'.
4696 Available standards are: VHDL'87/'93(02)/'08, VHDL-AMS, and Math Packages.
4699 KEYWORD CASE:
4700 Lower and upper case for keywords and standardized types, attributes,
4701 and enumeration values is supported. If the option
4702 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4703 lower case and are converted into upper case automatically (not for
4704 types, attributes, and enumeration values). The case of keywords,
4705 types, attributes,and enumeration values can be fixed for an entire
4706 region (menu) or buffer (`C-c C-x C-c') according to the options
4707 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4710 HIGHLIGHTING (fontification):
4711 Keywords and standardized types, attributes, enumeration values, and
4712 function names (controlled by option `vhdl-highlight-keywords'), as well
4713 as comments, strings, and template prompts are highlighted using
4714 different colors. Unit, subprogram, signal, variable, constant,
4715 parameter and generic/port names in declarations as well as labels are
4716 highlighted if option `vhdl-highlight-names' is non-nil.
4718 Additional reserved words or words with a forbidden syntax (e.g. words
4719 that should be avoided) can be specified in option
4720 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4721 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4722 keywords are highlighted as forbidden words if option
4723 `vhdl-highlight-verilog-keywords' is non-nil.
4725 Words with special syntax can be highlighted by specifying their
4726 syntax and color in option `vhdl-special-syntax-alist' and by setting
4727 option `vhdl-highlight-special-words' to non-nil. This allows you to
4728 establish some naming conventions (e.g. to distinguish different kinds
4729 of signals or other objects by using name suffices) and to support them
4730 visually.
4732 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4733 to support case-sensitive highlighting. However, keywords are then only
4734 highlighted if written in lower case.
4736 Code between \"translate_off\" and \"translate_on\" pragmas is
4737 highlighted using a different background color if option
4738 `vhdl-highlight-translate-off' is non-nil.
4740 For documentation and customization of the used colors see
4741 customization group `vhdl-highlight-faces' (`\\[customize-group]'). For
4742 highlighting of matching parenthesis, see customization group
4743 `paren-showing'. Automatic buffer highlighting is turned on/off by
4744 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4747 USER MODELS:
4748 VHDL models (templates) can be specified by the user and made accessible
4749 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4750 electrification. See option `vhdl-model-alist'.
4753 HIDE/SHOW:
4754 The code of blocks, processes, subprograms, component declarations and
4755 instantiations, generic/port clauses, and configuration declarations can
4756 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4757 the code (see customization group `vhdl-menu'). XEmacs: limited
4758 functionality due to old `hideshow.el' package.
4761 CODE UPDATING:
4762 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4763 current process, `C-c C-u M-s' of all processes in the current buffer.
4764 Limitations:
4765 - Only declared local signals (ports, signals declared in
4766 architecture and blocks) are automatically inserted.
4767 - Global signals declared in packages are not automatically inserted.
4768 Insert them once manually (will be kept afterwards).
4769 - Out parameters of procedures are considered to be read.
4770 Use option `vhdl-entity-file-name' to specify the entity file name
4771 (used to obtain the port names).
4772 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4773 specify whether to include array indices and record fields in
4774 sensitivity lists.
4777 CODE FIXING:
4778 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4779 (e.g., if the closing parenthesis is on the wrong line or is missing).
4782 PRINTING:
4783 PostScript printing with different faces (an optimized set of faces is
4784 used if `vhdl-print-customize-faces' is non-nil) or colors (if
4785 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4786 PostScript printing commands. Option `vhdl-print-two-column' defines
4787 appropriate default settings for nice landscape two-column printing.
4788 The paper format can be set by option `ps-paper-type'. Do not forget to
4789 switch `ps-print-color-p' to nil for printing on black-and-white
4790 printers.
4793 OPTIONS:
4794 User options allow customization of VHDL Mode. All options are
4795 accessible from the \"Options\" menu entry. Simple options (switches
4796 and choices) can directly be changed, while for complex options a
4797 customization buffer is opened. Changed options can be saved for future
4798 sessions using the \"Save Options\" menu entry.
4800 Options and their detailed descriptions can also be accessed by using
4801 the \"Customize\" menu entry or the command `\\[customize-option]'
4802 (`\\[customize-group]' for groups). Some customizations only take effect
4803 after some action (read the NOTE in the option documentation).
4804 Customization can also be done globally (i.e. site-wide, read the
4805 INSTALL file).
4807 Not all options are described in this documentation, so go and see
4808 what other useful user options there are (`\\[vhdl-customize]' or menu)!
4811 FILE EXTENSIONS:
4812 As default, files with extensions \".vhd\" and \".vhdl\" are
4813 automatically recognized as VHDL source files. To add an extension
4814 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4816 (push \\='(\"\\\\.xxx\\\\\\='\" . vhdl-mode) auto-mode-alist)
4819 HINTS:
4820 - To start Emacs with open VHDL hierarchy browser without having to load
4821 a VHDL file first, use the command:
4823 emacs -l vhdl-mode -f speedbar-frame-mode
4825 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4827 - Some features only work on properly indented code.
4830 RELEASE NOTES:
4831 See also the release notes (menu) for added features in new releases.
4834 Maintenance:
4835 ------------
4837 To submit a bug report, enter `\\[vhdl-submit-bug-report]' within VHDL Mode.
4838 Add a description of the problem and include a reproducible test case.
4840 Questions and enhancement requests can be sent to <reto@gnu.org>.
4842 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4843 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4844 releases. You are kindly invited to participate in beta testing. Subscribe
4845 to above mailing lists by sending an email to <reto@gnu.org>.
4847 VHDL Mode is officially distributed at
4848 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4849 where the latest version can be found.
4852 Known problems:
4853 ---------------
4855 - XEmacs: Incorrect start-up when automatically opening speedbar.
4856 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4857 - Indentation incorrect for new 'postponed' VHDL keyword.
4858 - Indentation incorrect for 'protected body' construct.
4861 The VHDL Mode Authors
4862 Reto Zimmermann and Rod Whitby
4864 Key bindings:
4865 -------------
4867 \\{vhdl-mode-map}"
4868 :abbrev-table vhdl-mode-abbrev-table
4870 ;; set local variables
4871 (set (make-local-variable 'paragraph-start)
4872 "\\s-*\\(--+\\s-*$\\|$\\)")
4873 (set (make-local-variable 'paragraph-separate) paragraph-start)
4874 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4875 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4876 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4877 (set (make-local-variable 'comment-start) "--")
4878 (set (make-local-variable 'comment-end) "")
4879 (when vhdl-emacs-21
4880 (set (make-local-variable 'comment-padding) ""))
4881 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4882 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4883 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4884 (set (make-local-variable 'comment-multi-line) nil)
4885 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4886 (set (make-local-variable 'hippie-expand-verbose) nil)
4888 ;; setup the comment indent variable in a Emacs version portable way
4889 ;; ignore any byte compiler warnings you might get here
4890 (when (boundp 'comment-indent-function)
4891 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4893 ;; initialize font locking
4894 (set (make-local-variable 'font-lock-defaults)
4895 (list
4896 '(nil vhdl-font-lock-keywords) nil
4897 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4898 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4899 (set (make-local-variable 'syntax-propertize-function)
4900 (syntax-propertize-rules
4901 ;; Mark single quotes as having string quote syntax in
4902 ;; 'c' instances.
4903 ("\\('\\).\\('\\)" (1 "\"'") (2 "\"'"))))
4904 (set (make-local-variable 'font-lock-syntactic-keywords)
4905 vhdl-font-lock-syntactic-keywords))
4906 (unless vhdl-emacs-21
4907 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4908 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4909 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4910 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4912 ;; variables for source file compilation
4913 (when vhdl-compile-use-local-error-regexp
4914 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4915 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4917 ;; add index menu
4918 (vhdl-index-menu-init)
4919 ;; add source file menu
4920 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4921 ;; add VHDL menu
4922 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4923 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4924 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4925 ;; initialize hideshow and add menu
4926 (vhdl-hideshow-init)
4927 (run-hooks 'menu-bar-update-hook)
4929 ;; miscellaneous
4930 (vhdl-ps-print-init)
4931 (vhdl-write-file-hooks-init)
4932 (message "VHDL Mode %s.%s" vhdl-version
4933 (if noninteractive "" " See menu for documentation and release notes.")))
4935 (defun vhdl-activate-customizations ()
4936 "Activate all customizations on local variables."
4937 (interactive)
4938 (vhdl-mode-map-init)
4939 (use-local-map vhdl-mode-map)
4940 (set-syntax-table vhdl-mode-syntax-table)
4941 (setq comment-column vhdl-inline-comment-column)
4942 (setq end-comment-column vhdl-end-comment-column)
4943 (vhdl-write-file-hooks-init)
4944 (vhdl-update-mode-menu)
4945 (vhdl-hideshow-init)
4946 (run-hooks 'menu-bar-update-hook))
4948 (defun vhdl-write-file-hooks-init ()
4949 "Add/remove hooks when buffer is saved."
4950 (if vhdl-modify-date-on-saving
4951 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4952 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4953 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4954 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4956 (defun vhdl-process-command-line-option (option)
4957 "Process command line options for VHDL Mode."
4958 (cond
4959 ;; set compiler
4960 ((equal option "-compiler")
4961 (vhdl-set-compiler (car command-line-args-left))
4962 (setq command-line-args-left (cdr command-line-args-left)))
4963 ;; set project
4964 ((equal option "-project")
4965 (vhdl-set-project (car command-line-args-left))
4966 (setq command-line-args-left (cdr command-line-args-left)))))
4968 ;; make Emacs process VHDL Mode options
4969 (setq command-switch-alist
4970 (append command-switch-alist
4971 '(("-compiler" . vhdl-process-command-line-option)
4972 ("-project" . vhdl-process-command-line-option))))
4975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4976 ;;; Keywords and standardized words
4977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4979 (defconst vhdl-02-keywords
4981 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4982 "assert" "attribute"
4983 "begin" "block" "body" "buffer" "bus"
4984 "case" "component" "configuration" "constant"
4985 "disconnect" "downto"
4986 "else" "elsif" "end" "entity" "exit"
4987 "file" "for" "function"
4988 "generate" "generic" "group" "guarded"
4989 "if" "impure" "in" "inertial" "inout" "is"
4990 "label" "library" "linkage" "literal" "loop"
4991 "map" "mod"
4992 "nand" "new" "next" "nor" "not" "null"
4993 "of" "on" "open" "or" "others" "out"
4994 "package" "port" "postponed" "procedure" "process" "protected" "pure"
4995 "range" "record" "register" "reject" "rem" "report" "return"
4996 "rol" "ror"
4997 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4998 "then" "to" "transport" "type"
4999 "unaffected" "units" "until" "use"
5000 "variable"
5001 "wait" "when" "while" "with"
5002 "xnor" "xor"
5004 "List of VHDL'02 keywords.")
5006 (defconst vhdl-08-keywords
5008 "context" "force" "property" "release" "sequence"
5010 "List of VHDL'08 keywords.")
5012 (defconst vhdl-ams-keywords
5014 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
5015 "reference" "spectrum" "subnature" "terminal" "through"
5016 "tolerance"
5018 "List of VHDL-AMS keywords.")
5020 (defconst vhdl-verilog-keywords
5022 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
5023 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
5024 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
5025 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
5026 "endprimitive" "endspecify" "endtable" "endtask" "event"
5027 "for" "force" "forever" "fork" "function"
5028 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
5029 "macromodule" "makefile" "medium" "module"
5030 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
5031 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
5032 "pullup"
5033 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
5034 "rtranif0" "rtranif1"
5035 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
5036 "strong1" "supply" "supply0" "supply1"
5037 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5038 "triand" "trior" "trireg"
5039 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
5041 "List of Verilog keywords as candidate for additional reserved words.")
5043 (defconst vhdl-02-types
5045 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
5046 "real" "time" "natural" "positive" "string" "line" "text" "side"
5047 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
5048 "std_logic" "std_logic_vector"
5049 "std_ulogic" "std_ulogic_vector"
5051 "List of VHDL'02 standardized types.")
5053 (defconst vhdl-08-types
5055 "boolean_vector" "integer_vector" "real_vector" "time_vector"
5057 "List of VHDL'08 standardized types.")
5059 (defconst vhdl-ams-types
5060 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5062 ;; package `standard'
5063 "domain_type" "real_vector"
5064 ;; package `energy_systems'
5065 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5066 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5067 "real_across_vector" "real_through_vector"
5068 ;; package `electrical_systems'
5069 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5070 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5071 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5072 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5073 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5074 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5075 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5076 "electric_flux_density_vector" "electric_field_strength_vector"
5077 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5078 "inductance_vector" "reluctance_vector" "ground"
5079 ;; package `mechanical_systems'
5080 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5081 "damping" "momentum" "angle" "torque" "angular_velocity"
5082 "angular_acceleration" "moment_inertia" "angular_momentum"
5083 "angular_stiffness" "angular_damping" "translational"
5084 "translational_vector" "translational_velocity"
5085 "translational_velocity_vector" "rotational" "rotational_vector"
5086 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5087 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5088 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5089 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5090 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5091 "angular_momentum_vector" "angular_stiffness_vector"
5092 "angular_damping_vector" "anchor" "translational_v_ref"
5093 "rotational_v_ref" "translational_v" "rotational_v"
5094 ;; package `radiant_systems'
5095 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5096 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5097 "illuminance_vector" "irradiance_vector"
5098 ;; package `thermal_systems'
5099 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5100 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5101 "heat_flow_vector" "thermal_capacitance_vector"
5102 "thermal_resistance_vector" "thermal_conductance_vector"
5103 ;; package `fluidic_systems'
5104 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5105 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5106 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5107 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5108 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5109 "density_vector" "viscosity_vector" "fresistance_vector"
5110 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5111 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5112 "cfinertance_vector"
5114 "List of VHDL-AMS standardized types.")
5116 (defconst vhdl-math-types
5118 "complex" "complex_polar" "positive_real" "principal_value"
5120 "List of Math Packages standardized types.")
5122 (defconst vhdl-02-attributes
5124 "base" "left" "right" "high" "low" "pos" "val" "succ"
5125 "pred" "leftof" "rightof" "range" "reverse_range"
5126 "length" "delayed" "stable" "quiet" "transaction"
5127 "event" "active" "last_event" "last_active" "last_value"
5128 "driving" "driving_value" "ascending" "value" "image"
5129 "simple_name" "instance_name" "path_name"
5130 "foreign"
5132 "List of VHDL'02 standardized attributes.")
5134 (defconst vhdl-08-attributes
5136 "instance_name" "path_name"
5138 "List of VHDL'08 standardized attributes.")
5140 (defconst vhdl-ams-attributes
5142 "across" "through"
5143 "reference" "contribution" "tolerance"
5144 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5145 "ramp" "slew"
5147 "List of VHDL-AMS standardized attributes.")
5149 (defconst vhdl-02-enum-values
5151 "true" "false"
5152 "note" "warning" "error" "failure"
5153 "read_mode" "write_mode" "append_mode"
5154 "open_ok" "status_error" "name_error" "mode_error"
5155 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5156 "right" "left"
5158 "List of VHDL'02 standardized enumeration values.")
5160 (defconst vhdl-ams-enum-values
5162 "quiescent_domain" "time_domain" "frequency_domain"
5163 ;; from `nature_pkg' package
5164 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5166 "List of VHDL-AMS standardized enumeration values.")
5168 (defconst vhdl-ams-constants
5169 ;; standard: IEEE Std 1076.1.1-2004
5171 ;; package `fundamental_constants'
5172 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5173 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5174 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5175 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5176 ;; package `material_constants'
5177 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5178 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5179 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5181 "List of VHDL-AMS standardized constants.")
5183 (defconst vhdl-math-constants
5184 ;; standard: IEEE Std 1076.2-1996
5186 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5187 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5188 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5189 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5190 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5191 "math_sqrt_pi"
5193 "List of Math Packages standardized constants.")
5195 (defconst vhdl-02-functions
5197 "now" "resolved" "rising_edge" "falling_edge"
5198 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5199 "endfile"
5200 "resize" "is_X" "std_match"
5201 "shift_left" "shift_right" "rotate_left" "rotate_right"
5202 "to_unsigned" "to_signed" "to_integer"
5203 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5204 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5205 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5206 "shl" "shr" "ext" "sxt"
5207 "deallocate"
5209 "List of VHDL'02 standardized functions.")
5211 (defconst vhdl-08-functions
5213 "finish" "flush" "justify" "maximum" "minimum"
5214 "resolution_limit" "rising_edge" "stop" "swrite"
5215 "tee" "to_binarystring" "to_bstring" "to_hexstring" "to_hstring"
5216 "to_octalstring" "to_ostring" "to_string"
5218 "List of VHDL'08 standardized functions.")
5220 (defconst vhdl-ams-functions
5222 ;; package `standard'
5223 "frequency"
5225 "List of VHDL-AMS standardized functions.")
5227 (defconst vhdl-math-functions
5228 ;; standard: IEEE Std 1076.2-1996
5230 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5231 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5232 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5233 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5234 "tan" "tanh" "trunc" "uniform"
5236 "List of Math Packages standardized functions.")
5238 (defconst vhdl-02-packages
5240 "std_logic_1164" "numeric_std" "numeric_bit"
5241 "standard" "textio"
5242 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5243 "std_logic_misc" "std_logic_textio"
5244 "ieee" "std" "work"
5246 "List of VHDL'02 standardized packages and libraries.")
5248 (defconst vhdl-08-packages
5250 "env" "numeric_std_signed" "numeric_std_unsigned"
5251 "ieee_bit_context" "ieee_std_context" ;; contexts
5253 "List of VHDL'08 standardized packages and libraries.")
5255 (defconst vhdl-ams-packages
5257 "fundamental_constants" "material_constants" "energy_systems"
5258 "electrical_systems" "mechanical_systems" "radiant_systems"
5259 "thermal_systems" "fluidic_systems"
5261 "List of VHDL-AMS standardized packages and libraries.")
5263 (defconst vhdl-math-packages
5265 "math_real" "math_complex"
5267 "List of Math Packages standardized packages and libraries.")
5269 (defconst vhdl-08-directives
5271 "author" "author_info" "begin" "begin_protected" "comment"
5272 "data_block" "data_keyname" "data_keyowner" "data_method"
5273 "decrypt_license" "digest_block" "digest_key_method" "digest_keyname"
5274 "digest_keyowner" "digest_method"
5275 "encoding" "encrypt_agent" "encrypt_agent_info" "end" "end_protected"
5276 "key_block" "key_keyname" "key_keyowner" "key_method"
5277 "runtime_license" "viewport"
5279 "List of VHDL'08 standardized tool directives.")
5281 (defvar vhdl-keywords nil
5282 "List of VHDL keywords.")
5284 (defvar vhdl-types nil
5285 "List of VHDL standardized types.")
5287 (defvar vhdl-attributes nil
5288 "List of VHDL standardized attributes.")
5290 (defvar vhdl-enum-values nil
5291 "List of VHDL standardized enumeration values.")
5293 (defvar vhdl-constants nil
5294 "List of VHDL standardized constants.")
5296 (defvar vhdl-functions nil
5297 "List of VHDL standardized functions.")
5299 (defvar vhdl-packages nil
5300 "List of VHDL standardized packages and libraries.")
5302 (defvar vhdl-directives nil
5303 "List of VHDL standardized packages and libraries.")
5305 (defvar vhdl-reserved-words nil
5306 "List of additional reserved words.")
5308 (defvar vhdl-keywords-regexp nil
5309 "Regexp for VHDL keywords.")
5311 (defvar vhdl-types-regexp nil
5312 "Regexp for VHDL standardized types.")
5314 (defvar vhdl-attributes-regexp nil
5315 "Regexp for VHDL standardized attributes.")
5317 (defvar vhdl-enum-values-regexp nil
5318 "Regexp for VHDL standardized enumeration values.")
5320 (defvar vhdl-constants-regexp nil
5321 "Regexp for VHDL standardized constants.")
5323 (defvar vhdl-functions-regexp nil
5324 "Regexp for VHDL standardized functions.")
5326 (defvar vhdl-packages-regexp nil
5327 "Regexp for VHDL standardized packages and libraries.")
5329 (defvar vhdl-reserved-words-regexp nil
5330 "Regexp for additional reserved words.")
5332 (defvar vhdl-directive-keywords-regexp nil
5333 "Regexp for compiler directive keywords.")
5335 (defun vhdl-upcase-list (condition list)
5336 "Upcase all elements in LIST based on CONDITION."
5337 (when condition
5338 (let ((tmp-list list))
5339 (while tmp-list
5340 (setcar tmp-list (upcase (car tmp-list)))
5341 (setq tmp-list (cdr tmp-list)))))
5342 list)
5344 (defun vhdl-words-init ()
5345 "Initialize reserved words."
5346 (setq vhdl-keywords
5347 (vhdl-upcase-list
5348 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5349 (append vhdl-02-keywords
5350 (when (vhdl-standard-p '08) vhdl-08-keywords)
5351 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5352 (setq vhdl-types
5353 (vhdl-upcase-list
5354 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5355 (append vhdl-02-types
5356 (when (vhdl-standard-p '08) vhdl-08-types)
5357 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5358 (when (vhdl-standard-p 'math) vhdl-math-types))))
5359 (setq vhdl-attributes
5360 (vhdl-upcase-list
5361 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5362 (append vhdl-02-attributes
5363 (when (vhdl-standard-p '08) vhdl-08-attributes)
5364 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5365 (setq vhdl-enum-values
5366 (vhdl-upcase-list
5367 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5368 (append vhdl-02-enum-values
5369 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5370 (setq vhdl-constants
5371 (vhdl-upcase-list
5372 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5373 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5374 (when (vhdl-standard-p 'math) vhdl-math-constants)
5375 '(""))))
5376 (setq vhdl-functions
5377 (append vhdl-02-functions
5378 (when (vhdl-standard-p '08) vhdl-08-functions)
5379 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5380 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5381 (setq vhdl-packages
5382 (append vhdl-02-packages
5383 (when (vhdl-standard-p '08) vhdl-08-packages)
5384 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5385 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5386 (setq vhdl-directives
5387 (append (when (vhdl-standard-p '08) vhdl-08-directives)))
5388 (setq vhdl-reserved-words
5389 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5390 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5391 '("")))
5392 (setq vhdl-keywords-regexp
5393 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5394 (setq vhdl-types-regexp
5395 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5396 (setq vhdl-attributes-regexp
5397 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5398 (setq vhdl-enum-values-regexp
5399 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5400 (setq vhdl-constants-regexp
5401 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5402 (setq vhdl-functions-regexp
5403 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5404 (setq vhdl-packages-regexp
5405 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5406 (setq vhdl-reserved-words-regexp
5407 (concat "\\<\\("
5408 (unless (equal vhdl-forbidden-syntax "")
5409 (concat vhdl-forbidden-syntax "\\|"))
5410 (regexp-opt vhdl-reserved-words)
5411 "\\)\\>"))
5412 (setq vhdl-directive-keywords-regexp
5413 (concat "\\<\\(" (mapconcat 'regexp-quote
5414 vhdl-directive-keywords "\\|") "\\)\\>"))
5415 (vhdl-abbrev-list-init))
5417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5418 ;; Words to expand
5420 (defvar vhdl-abbrev-list nil
5421 "Predefined abbreviations for VHDL.")
5423 (defun vhdl-abbrev-list-init ()
5424 (setq vhdl-abbrev-list
5425 (append
5426 (list vhdl-upper-case-keywords) vhdl-keywords
5427 (list vhdl-upper-case-types) vhdl-types
5428 (list vhdl-upper-case-attributes) vhdl-attributes
5429 (list vhdl-upper-case-enum-values) vhdl-enum-values
5430 (list vhdl-upper-case-constants) vhdl-constants
5431 (list nil) vhdl-functions
5432 (list nil) vhdl-packages
5433 (list nil) vhdl-directives)))
5435 ;; initialize reserved words for VHDL Mode
5436 (vhdl-words-init)
5439 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5440 ;;; Indentation
5441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5443 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5444 ;; Syntax analysis
5446 ;; constant regular expressions for looking at various constructs
5448 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5449 "Regexp describing a VHDL symbol.
5450 We cannot use just `word' syntax class since `_' cannot be in word
5451 class. Putting underscore in word class breaks forward word movement
5452 behavior that users are familiar with.")
5454 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5455 "Regexp describing a case statement header key.")
5457 (defconst vhdl-label-key
5458 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5459 "Regexp describing a VHDL label.")
5461 ;; Macro definitions:
5463 (defmacro vhdl-point (position)
5464 "Return the value of point at certain commonly referenced POSITIONs.
5465 POSITION can be one of the following symbols:
5467 bol -- beginning of line
5468 eol -- end of line
5469 bod -- beginning of defun
5470 boi -- back to indentation
5471 eoi -- last whitespace on line
5472 ionl -- indentation of next line
5473 iopl -- indentation of previous line
5474 bonl -- beginning of next line
5475 bopl -- beginning of previous line
5477 This function does not modify point or mark."
5478 (or (and (eq 'quote (car-safe position))
5479 (null (cddr position)))
5480 (error "ERROR: Bad buffer position requested: %s" position))
5481 (setq position (nth 1 position))
5482 `(let ((here (point)))
5483 ,@(cond
5484 ((eq position 'bol) '((beginning-of-line)))
5485 ((eq position 'eol) '((end-of-line)))
5486 ((eq position 'bod) '((save-match-data
5487 (vhdl-beginning-of-defun))))
5488 ((eq position 'boi) '((back-to-indentation)))
5489 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5490 ((eq position 'bonl) '((forward-line 1)))
5491 ((eq position 'bopl) '((forward-line -1)))
5492 ((eq position 'iopl)
5493 '((forward-line -1)
5494 (back-to-indentation)))
5495 ((eq position 'ionl)
5496 '((forward-line 1)
5497 (back-to-indentation)))
5498 (t (error "ERROR: Unknown buffer position requested: %s" position))
5500 (prog1
5501 (point)
5502 (goto-char here))
5503 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5504 ;; doesn't hurt for v19
5505 ,@nil
5508 (defmacro vhdl-safe (&rest body)
5509 "Safely execute BODY, return nil if an error occurred."
5510 `(condition-case nil
5511 (progn ,@body)
5512 (error nil)))
5514 (defmacro vhdl-add-syntax (symbol &optional relpos)
5515 "A simple macro to append the syntax in SYMBOL to the syntax list.
5516 Try to increase performance by using this macro."
5517 `(setq vhdl-syntactic-context
5518 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5520 (defmacro vhdl-has-syntax (symbol)
5521 "A simple macro to return check the syntax list.
5522 Try to increase performance by using this macro."
5523 `(assoc ,symbol vhdl-syntactic-context))
5525 ;; Syntactic element offset manipulation:
5527 (defun vhdl-read-offset (langelem)
5528 "Read new offset value for LANGELEM from minibuffer.
5529 Return a valid value only."
5530 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5531 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5532 (prompt "Offset: ")
5533 offset input interned)
5534 (while (not offset)
5535 (setq input (read-string prompt oldoff)
5536 offset (cond ((string-equal "+" input) '+)
5537 ((string-equal "-" input) '-)
5538 ((string-equal "++" input) '++)
5539 ((string-equal "--" input) '--)
5540 ((string-match "^-?[0-9]+$" input)
5541 (string-to-number input))
5542 ((fboundp (setq interned (intern input)))
5543 interned)
5544 ((boundp interned) interned)
5545 ;; error, but don't signal one, keep trying
5546 ;; to read an input value
5547 (t (ding)
5548 (setq prompt errmsg)
5549 nil))))
5550 offset))
5552 (defun vhdl-set-offset (symbol offset &optional add-p)
5553 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5554 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5555 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5556 `vhdl-offsets-alist' if it doesn't already appear there."
5557 (interactive
5558 (let* ((langelem
5559 (intern (completing-read
5560 (concat "Syntactic symbol to change"
5561 (if current-prefix-arg " or add" "")
5562 ": ")
5563 (mapcar
5564 (function
5565 (lambda (langelem)
5566 (cons (format "%s" (car langelem)) nil)))
5567 vhdl-offsets-alist)
5568 nil (not current-prefix-arg)
5569 ;; initial contents tries to be the last element
5570 ;; on the syntactic analysis list for the current
5571 ;; line
5572 (let* ((syntax (vhdl-get-syntactic-context))
5573 (len (length syntax))
5574 (ic (format "%s" (car (nth (1- len) syntax)))))
5577 (offset (vhdl-read-offset langelem)))
5578 (list langelem offset current-prefix-arg)))
5579 ;; sanity check offset
5580 (or (eq offset '+)
5581 (eq offset '-)
5582 (eq offset '++)
5583 (eq offset '--)
5584 (integerp offset)
5585 (fboundp offset)
5586 (boundp offset)
5587 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5588 offset))
5589 (let ((entry (assq symbol vhdl-offsets-alist)))
5590 (if entry
5591 (setcdr entry offset)
5592 (if add-p
5593 (setq vhdl-offsets-alist
5594 (cons (cons symbol offset) vhdl-offsets-alist))
5595 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5596 (vhdl-keep-region-active))
5598 (defun vhdl-set-style (style &optional local)
5599 "Set `vhdl-mode' variables to use one of several different indentation styles.
5600 STYLE is a string representing the desired style and optional LOCAL is
5601 a flag which, if non-nil, means to make the style variables being
5602 changed buffer local, instead of the default, which is to set the
5603 global variables. Interactively, the flag comes from the prefix
5604 argument. The styles are chosen from the `vhdl-style-alist' variable."
5605 (interactive (list (completing-read "Use which VHDL indentation style? "
5606 vhdl-style-alist nil t)
5607 current-prefix-arg))
5608 (let ((vars (cdr (assoc style vhdl-style-alist))))
5609 (or vars
5610 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5611 ;; set all the variables
5612 (mapc
5613 (function
5614 (lambda (varentry)
5615 (let ((var (car varentry))
5616 (val (cdr varentry)))
5617 ;; special case for vhdl-offsets-alist
5618 (if (not (eq var 'vhdl-offsets-alist))
5619 (set (if local (make-local-variable var) var) val)
5620 ;; reset vhdl-offsets-alist to the default value first
5621 (set (if local (make-local-variable var) var)
5622 (copy-alist vhdl-offsets-alist-default))
5623 ;; now set the langelems that are different
5624 (mapcar
5625 (function
5626 (lambda (langentry)
5627 (let ((langelem (car langentry))
5628 (offset (cdr langentry)))
5629 (vhdl-set-offset langelem offset)
5631 val))
5633 vars))
5634 (vhdl-keep-region-active))
5636 (defun vhdl-get-offset (langelem)
5637 "Get offset from LANGELEM which is a cons cell of the form:
5638 \(SYMBOL . RELPOS). The symbol is matched against
5639 vhdl-offsets-alist and the offset found there is either returned,
5640 or added to the indentation at RELPOS. If RELPOS is nil, then
5641 the offset is simply returned."
5642 (let* ((symbol (car langelem))
5643 (relpos (cdr langelem))
5644 (match (assq symbol vhdl-offsets-alist))
5645 (offset (cdr-safe match)))
5646 ;; offset can be a number, a function, a variable, or one of the
5647 ;; symbols + or -
5648 (cond
5649 ((not match)
5650 (if vhdl-strict-syntax-p
5651 (error "ERROR: Don't know how to indent a %s" symbol)
5652 (setq offset 0
5653 relpos 0)))
5654 ((eq offset '+) (setq offset vhdl-basic-offset))
5655 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5656 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5657 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5658 ((and (not (numberp offset))
5659 (fboundp offset))
5660 (setq offset (funcall offset langelem)))
5661 ((not (numberp offset))
5662 (setq offset (eval offset)))
5664 (+ (if (and relpos
5665 (< relpos (vhdl-point 'bol)))
5666 (save-excursion
5667 (goto-char relpos)
5668 (current-column))
5670 offset)))
5672 ;; Syntactic support functions:
5674 (defun vhdl-in-comment-p (&optional pos)
5675 "Check if point is in a comment (include multi-line comments)."
5676 (let ((parse (lambda (p)
5677 (let ((c (char-after p)))
5678 (or (and c (eq (char-syntax c) ?<))
5679 (nth 4 (parse-partial-sexp
5680 (save-excursion
5681 (beginning-of-defun)
5682 (point)) p)))))))
5683 (save-excursion
5684 (goto-char (or pos (point)))
5685 (or (funcall parse (point))
5686 ;; `parse-partial-sexp's notion of comments doesn't span lines
5687 (progn
5688 (back-to-indentation)
5689 (unless (eolp)
5690 (forward-char)
5691 (funcall parse (point))))))))
5693 (defun vhdl-in-string-p ()
5694 "Check if point is in a string."
5695 (eq (vhdl-in-literal) 'string))
5697 (defun vhdl-in-quote-p ()
5698 "Check if point is in a quote ('x')."
5699 (or (and (> (point) (point-min))
5700 (< (1+ (point)) (point-max))
5701 (= (char-before (point)) ?\')
5702 (= (char-after (1+ (point))) ?\'))
5703 (and (> (1- (point)) (point-min))
5704 (< (point) (point-max))
5705 (= (char-before (1- (point))) ?\')
5706 (= (char-after (point)) ?\'))))
5708 (defun vhdl-in-literal ()
5709 "Determine if point is in a VHDL literal."
5710 (save-excursion
5711 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5712 (cond
5713 ((nth 3 state) 'string)
5714 ((nth 4 state) 'comment)
5715 ((vhdl-beginning-of-macro) 'pound)
5716 ((vhdl-beginning-of-directive) 'directive)
5717 ;; for multi-line comments
5718 ((and (vhdl-standard-p '08) (vhdl-in-comment-p)) 'comment)
5719 (t nil)))))
5721 (defun vhdl-in-extended-identifier-p ()
5722 "Determine if point is inside extended identifier (delimited by `\\')."
5723 (save-match-data
5724 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5725 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5727 (defun vhdl-forward-comment (&optional direction)
5728 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5729 negative, skip forward otherwise."
5730 (interactive "p")
5731 (if (and direction (< direction 0))
5732 ;; skip backwards
5733 (progn
5734 (skip-chars-backward " \t\n\r\f")
5735 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5736 (goto-char (match-beginning 3))
5737 (skip-chars-backward " \t\n\r\f")))
5738 ;; skip forwards
5739 (skip-chars-forward " \t\n\r\f")
5740 (while (looking-at "--.*")
5741 (goto-char (match-end 0))
5742 (skip-chars-forward " \t\n\r\f"))))
5744 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5745 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5746 (defalias 'vhdl-forward-comment 'forward-comment))
5748 (defun vhdl-back-to-indentation ()
5749 "Move point to the first non-whitespace character on this line."
5750 (interactive)
5751 (beginning-of-line 1)
5752 (skip-syntax-forward " " (vhdl-point 'eol)))
5754 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5755 (when (featurep 'xemacs)
5756 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5758 ;; This is the best we can do in Win-Emacs.
5759 (defun vhdl-win-il (&optional lim)
5760 "Determine if point is in a VHDL literal."
5761 (save-excursion
5762 (let* ((here (point))
5763 (state nil)
5764 (match nil)
5765 (lim (or lim (vhdl-point 'bod))))
5766 (goto-char lim )
5767 (while (< (point) here)
5768 (setq match
5769 (and (re-search-forward "--\\|[\"']\\|`"
5770 here 'move)
5771 (buffer-substring (match-beginning 0) (match-end 0))))
5772 (setq state
5773 (cond
5774 ;; no match
5775 ((null match) nil)
5776 ;; looking at the opening of a VHDL style comment
5777 ((string= "--" match)
5778 (if (<= here (progn (end-of-line) (point))) 'comment))
5779 ;; looking at a directive
5780 ((string= "`" match)
5781 (if (<= here (progn (end-of-line) (point))) 'directive))
5782 ;; looking at the opening of a double quote string
5783 ((string= "\"" match)
5784 (if (not (save-restriction
5785 ;; this seems to be necessary since the
5786 ;; re-search-forward will not work without it
5787 (narrow-to-region (point) here)
5788 (re-search-forward
5789 ;; this regexp matches a double quote
5790 ;; which is preceded by an even number
5791 ;; of backslashes, including zero
5792 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5793 'string))
5794 ;; looking at the opening of a single quote string
5795 ((string= "'" match)
5796 (if (not (save-restriction
5797 ;; see comments from above
5798 (narrow-to-region (point) here)
5799 (re-search-forward
5800 ;; this matches a single quote which is
5801 ;; preceded by zero or two backslashes.
5802 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5803 here 'move)))
5804 'string))
5805 (t nil)))
5806 ) ; end-while
5807 state)))
5809 (and (string-match "Win-Emacs" emacs-version)
5810 (fset 'vhdl-in-literal 'vhdl-win-il))
5812 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5813 ;; defined as lexical whitespace or comments. Search no farther back
5814 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5815 ;; used for backward skipping, (point-max) is used for forward
5816 ;; skipping.
5818 (defun vhdl-forward-syntactic-ws (&optional lim)
5819 "Forward skip of syntactic whitespace."
5820 (let* ((here (point-max))
5821 (hugenum (point-max)))
5822 (while (/= here (point))
5823 (setq here (point))
5824 (vhdl-forward-comment hugenum)
5825 ;; skip preprocessor directives
5826 (when (and (or (eq (char-after) ?#) (eq (char-after) ?`))
5827 (= (vhdl-point 'boi) (point)))
5828 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5829 (= (forward-line 1) 0)))
5830 (end-of-line)))
5831 (if lim (goto-char (min (point) lim)))))
5834 ;; This is the best we can do in Win-Emacs.
5835 (defun vhdl-win-fsws (&optional lim)
5836 "Forward skip syntactic whitespace for Win-Emacs."
5837 (let ((lim (or lim (point-max)))
5838 stop)
5839 (while (not stop)
5840 (skip-chars-forward " \t\n\r\f" lim)
5841 (cond
5842 ;; vhdl comment
5843 ((looking-at "--") (end-of-line))
5844 ;; none of the above
5845 (t (setq stop t))))))
5847 (and (string-match "Win-Emacs" emacs-version)
5848 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5850 (defun vhdl-beginning-of-macro (&optional lim)
5851 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5852 (let ((here (point)))
5853 (beginning-of-line)
5854 (while (eq (char-before (1- (point))) ?\\)
5855 (forward-line -1))
5856 (back-to-indentation)
5857 (if (and (<= (point) here)
5858 (eq (char-after) ?#))
5860 (goto-char here)
5861 nil)))
5863 (defun vhdl-beginning-of-directive (&optional lim)
5864 "Go to the beginning of a directive (nicked from `cc-engine')."
5865 (let ((here (point)))
5866 (beginning-of-line)
5867 (while (eq (char-before (1- (point))) ?\\)
5868 (forward-line -1))
5869 (back-to-indentation)
5870 (if (and (<= (point) here)
5871 (eq (char-after) ?`))
5873 (goto-char here)
5874 nil)))
5876 (defun vhdl-backward-syntactic-ws (&optional lim)
5877 "Backward skip over syntactic whitespace."
5878 (let* ((here (point-min))
5879 (hugenum (- (point-max))))
5880 (while (/= here (point))
5881 (setq here (point))
5882 (vhdl-forward-comment hugenum)
5883 (vhdl-beginning-of-macro))
5884 (if lim (goto-char (max (point) lim)))))
5886 ;; This is the best we can do in Win-Emacs.
5887 (defun vhdl-win-bsws (&optional lim)
5888 "Backward skip syntactic whitespace for Win-Emacs."
5889 (let ((lim (or lim (vhdl-point 'bod)))
5890 stop)
5891 (while (not stop)
5892 (skip-chars-backward " \t\n\r\f" lim)
5893 (cond
5894 ;; vhdl comment
5895 ((eq (vhdl-in-literal) 'comment)
5896 (skip-chars-backward "^-" lim)
5897 (skip-chars-backward "-" lim)
5898 (while (not (or (and (= (following-char) ?-)
5899 (= (char-after (1+ (point))) ?-))
5900 (<= (point) lim)))
5901 (skip-chars-backward "^-" lim)
5902 (skip-chars-backward "-" lim)))
5903 ;; none of the above
5904 (t (setq stop t))))))
5906 (and (string-match "Win-Emacs" emacs-version)
5907 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5909 ;; Functions to help finding the correct indentation column:
5911 (defun vhdl-first-word (point)
5912 "If the keyword at POINT is at boi, then return (current-column) at
5913 that point, else nil."
5914 (save-excursion
5915 (and (goto-char point)
5916 (eq (point) (vhdl-point 'boi))
5917 (current-column))))
5919 (defun vhdl-last-word (point)
5920 "If the keyword at POINT is at eoi, then return (current-column) at
5921 that point, else nil."
5922 (save-excursion
5923 (and (goto-char point)
5924 (save-excursion (or (eq (progn (forward-sexp) (point))
5925 (vhdl-point 'eoi))
5926 (looking-at "\\s-*\\(--\\)?")))
5927 (current-column))))
5929 ;; Core syntactic evaluation functions:
5931 (defconst vhdl-libunit-re
5932 "\\b\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\b[^_]")
5934 (defun vhdl-libunit-p ()
5935 (and
5936 (save-excursion
5937 (forward-sexp)
5938 (skip-chars-forward " \t\n\r\f")
5939 (not (looking-at "is\\b[^_]")))
5940 (save-excursion
5941 (backward-sexp)
5942 (and (not (looking-at "use\\b[^_]"))
5943 (progn
5944 (forward-sexp)
5945 (vhdl-forward-syntactic-ws)
5946 (/= (following-char) ?:))))
5949 (defconst vhdl-defun-re
5950 "\\b\\(architecture\\|block\\|configuration\\|context\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5952 (defun vhdl-defun-p ()
5953 (save-excursion
5954 (if (looking-at "block\\|process\\|procedural")
5955 ;; "block", "process", "procedural":
5956 (save-excursion
5957 (backward-sexp)
5958 (not (looking-at "end\\s-+\\w")))
5959 ;; "architecture", "configuration", "context", "entity",
5960 ;; "package", "procedure", "function":
5961 t)))
5963 (defun vhdl-corresponding-defun ()
5964 "If the word at the current position corresponds to a \"defun\"
5965 keyword, then return a string that can be used to find the
5966 corresponding \"begin\" keyword, else return nil."
5967 (save-excursion
5968 (and (looking-at vhdl-defun-re)
5969 (vhdl-defun-p)
5970 (if (looking-at "block\\|process\\|procedural")
5971 ;; "block", "process". "procedural:
5972 (buffer-substring (match-beginning 0) (match-end 0))
5973 ;; "architecture", "configuration", "context", "entity", "package",
5974 ;; "procedure", "function":
5975 "is"))))
5977 (defconst vhdl-begin-fwd-re
5978 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5979 "A regular expression for searching forward that matches all known
5980 \"begin\" keywords.")
5982 (defconst vhdl-begin-bwd-re
5983 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5984 "A regular expression for searching backward that matches all known
5985 \"begin\" keywords.")
5987 (defun vhdl-begin-p (&optional lim)
5988 "Return t if we are looking at a real \"begin\" keyword.
5989 Assumes that the caller will make sure that we are looking at
5990 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5991 the middle of an identifier that just happens to contain a \"begin\"
5992 keyword."
5993 (cond
5994 ;; "[architecture|case|configuration|context|entity|package|
5995 ;; procedure|function] ... is":
5996 ((and (looking-at "i")
5997 (save-excursion
5998 ;; Skip backward over first sexp (needed to skip over a
5999 ;; procedure interface list, and is harmless in other
6000 ;; situations). Note that we need "return" in the
6001 ;; following search list so that we don't run into
6002 ;; semicolons in the function interface list.
6003 (backward-sexp)
6004 (let (foundp)
6005 (while (and (not foundp)
6006 (re-search-backward
6007 ";\\|\\b\\(architecture\\|case\\|configuration\\|context\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
6008 lim 'move))
6009 (if (or (= (preceding-char) ?_)
6010 (vhdl-in-literal))
6011 (backward-char)
6012 (setq foundp t))))
6013 (and (/= (following-char) ?\;)
6014 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
6016 ;; "begin", "then", "use":
6017 ((looking-at "be\\|t\\|use")
6019 ;; "else":
6020 ((and (looking-at "e")
6021 ;; make sure that the "else" isn't inside a
6022 ;; conditional signal assignment.
6023 (save-excursion
6024 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6025 (or (eq (following-char) ?\;)
6026 (eq (point) lim))))
6028 ;; "block", "generate", "loop", "process", "procedural",
6029 ;; "units", "record", "protected body":
6030 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
6031 (save-excursion
6032 (backward-sexp)
6033 (not (looking-at "end\\s-+\\w"))))
6035 ;; "component":
6036 ((and (looking-at "c")
6037 (save-excursion
6038 (backward-sexp)
6039 (not (looking-at "end\\s-+\\w")))
6040 ;; look out for the dreaded entity class in an attribute
6041 (save-excursion
6042 (vhdl-backward-syntactic-ws lim)
6043 (/= (preceding-char) ?:)))
6045 ;; "for" (inside configuration declaration):
6046 ((and (looking-at "f")
6047 (save-excursion
6048 (backward-sexp)
6049 (not (looking-at "end\\s-+\\w")))
6050 (vhdl-has-syntax 'configuration))
6054 (defun vhdl-corresponding-mid (&optional lim)
6055 (cond
6056 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
6057 "begin")
6058 ((looking-at "then\\|use")
6059 "<else>")
6061 "end")))
6063 (defun vhdl-corresponding-end (&optional lim)
6064 "If the word at the current position corresponds to a \"begin\"
6065 keyword, then return a vector containing enough information to find
6066 the corresponding \"end\" keyword, else return nil. The keyword to
6067 search forward for is aref 0. The column in which the keyword must
6068 appear is aref 1 or nil if any column is suitable.
6069 Assumes that the caller will make sure that we are not in the middle
6070 of an identifier that just happens to contain a \"begin\" keyword."
6071 (save-excursion
6072 (and (looking-at vhdl-begin-fwd-re)
6073 (or (not (looking-at "\\<use\\>"))
6074 (save-excursion (back-to-indentation)
6075 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6076 (/= (preceding-char) ?_)
6077 (not (vhdl-in-literal))
6078 (vhdl-begin-p lim)
6079 (cond
6080 ;; "is", "generate", "loop":
6081 ((looking-at "[igl]")
6082 (vector "end"
6083 (and (vhdl-last-word (point))
6084 (or (vhdl-first-word (point))
6085 (save-excursion
6086 (vhdl-beginning-of-statement-1 lim)
6087 (vhdl-backward-skip-label lim)
6088 (vhdl-first-word (point)))))))
6089 ;; "begin", "else", "for":
6090 ((looking-at "be\\|[ef]")
6091 (vector "end"
6092 (and (vhdl-last-word (point))
6093 (or (vhdl-first-word (point))
6094 (save-excursion
6095 (vhdl-beginning-of-statement-1 lim)
6096 (vhdl-backward-skip-label lim)
6097 (vhdl-first-word (point)))))))
6098 ;; "component", "units", "record", "protected body":
6099 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
6100 ;; The first end found will close the block
6101 (vector "end" nil))
6102 ;; "block", "process", "procedural":
6103 ((looking-at "bl\\|p")
6104 (vector "end"
6105 (or (vhdl-first-word (point))
6106 (save-excursion
6107 (vhdl-beginning-of-statement-1 lim)
6108 (vhdl-backward-skip-label lim)
6109 (vhdl-first-word (point))))))
6110 ;; "then":
6111 ((looking-at "t\\|use")
6112 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
6113 (and (vhdl-last-word (point))
6114 (or (vhdl-first-word (point))
6115 (save-excursion
6116 (vhdl-beginning-of-statement-1 lim)
6117 (vhdl-backward-skip-label lim)
6118 (vhdl-first-word (point)))))))
6119 ))))
6121 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
6123 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
6125 (defun vhdl-end-p (&optional lim)
6126 "Return t if we are looking at a real \"end\" keyword.
6127 Assumes that the caller will make sure that we are looking at
6128 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
6129 the middle of an identifier that just happens to contain an \"end\"
6130 keyword."
6131 (or (not (looking-at "else"))
6132 ;; make sure that the "else" isn't inside a conditional signal
6133 ;; assignment.
6134 (save-excursion
6135 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6136 (or (eq (following-char) ?\;)
6137 (eq (point) lim)
6138 (vhdl-in-literal)))))
6140 (defun vhdl-corresponding-begin (&optional lim)
6141 "If the word at the current position corresponds to an \"end\"
6142 keyword, then return a vector containing enough information to find
6143 the corresponding \"begin\" keyword, else return nil. The keyword to
6144 search backward for is aref 0. The column in which the keyword must
6145 appear is aref 1 or nil if any column is suitable. The supplementary
6146 keyword to search forward for is aref 2 or nil if this is not
6147 required. If aref 3 is t, then the \"begin\" keyword may be found in
6148 the middle of a statement.
6149 Assumes that the caller will make sure that we are not in the middle
6150 of an identifier that just happens to contain an \"end\" keyword."
6151 (save-excursion
6152 (let (pos)
6153 (if (and (looking-at vhdl-end-fwd-re)
6154 (not (vhdl-in-literal))
6155 (vhdl-end-p lim))
6156 (if (looking-at "el")
6157 ;; "else", "elsif":
6158 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
6159 ;; "end ...":
6160 (setq pos (point))
6161 (forward-sexp)
6162 (skip-chars-forward " \t\n\r\f")
6163 (cond
6164 ;; "end if":
6165 ((looking-at "if\\b[^_]")
6166 (vector "else\\|elsif\\|if"
6167 (vhdl-first-word pos)
6168 "else\\|then\\|use" nil))
6169 ;; "end component":
6170 ((looking-at "component\\b[^_]")
6171 (vector (buffer-substring (match-beginning 1)
6172 (match-end 1))
6173 (vhdl-first-word pos)
6174 nil nil))
6175 ;; "end units", "end record", "end protected":
6176 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6177 (vector (buffer-substring (match-beginning 1)
6178 (match-end 1))
6179 (vhdl-first-word pos)
6180 nil t))
6181 ;; "end block", "end process", "end procedural":
6182 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6183 (vector "begin" (vhdl-first-word pos) nil nil))
6184 ;; "end case":
6185 ((looking-at "case\\b[^_]")
6186 (vector "case" (vhdl-first-word pos) "is" nil))
6187 ;; "end generate":
6188 ((looking-at "generate\\b[^_]")
6189 (vector "generate\\|for\\|if"
6190 (vhdl-first-word pos)
6191 "generate" nil))
6192 ;; "end loop":
6193 ((looking-at "loop\\b[^_]")
6194 (vector "loop\\|while\\|for"
6195 (vhdl-first-word pos)
6196 "loop" nil))
6197 ;; "end for" (inside configuration declaration):
6198 ((looking-at "for\\b[^_]")
6199 (vector "for" (vhdl-first-word pos) nil nil))
6200 ;; "end [id]":
6202 (vector "begin\\|architecture\\|configuration\\|context\\|entity\\|package\\|procedure\\|function"
6203 (vhdl-first-word pos)
6204 ;; return an alist of (statement . keyword) mappings
6206 ;; "begin ... end [id]":
6207 ("begin" . nil)
6208 ;; "architecture ... is ... begin ... end [id]":
6209 ("architecture" . "is")
6210 ;; "configuration ... is ... end [id]":
6211 ("configuration" . "is")
6212 ;; "context ... is ... end [id]":
6213 ("context" . "is")
6214 ;; "entity ... is ... end [id]":
6215 ("entity" . "is")
6216 ;; "package ... is ... end [id]":
6217 ("package" . "is")
6218 ;; "procedure ... is ... begin ... end [id]":
6219 ("procedure" . "is")
6220 ;; "function ... is ... begin ... end [id]":
6221 ("function" . "is")
6223 nil))
6224 ))) ; "end ..."
6227 (defconst vhdl-leader-re
6228 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6230 (defun vhdl-end-of-leader ()
6231 (save-excursion
6232 (cond ((looking-at "block\\|process\\|procedural")
6233 (if (save-excursion
6234 (forward-sexp)
6235 (skip-chars-forward " \t\n\r\f")
6236 (= (following-char) ?\())
6237 (forward-sexp 2)
6238 (forward-sexp))
6239 (when (looking-at "[ \t\n\r\f]*is")
6240 (goto-char (match-end 0)))
6241 (point))
6242 ((looking-at "component")
6243 (forward-sexp 2)
6244 (when (looking-at "[ \t\n\r\f]*is")
6245 (goto-char (match-end 0)))
6246 (point))
6247 ((looking-at "for")
6248 (forward-sexp 2)
6249 (skip-chars-forward " \t\n\r\f")
6250 (while (looking-at "[,:(]")
6251 (forward-sexp)
6252 (skip-chars-forward " \t\n\r\f"))
6253 (point))
6254 (t nil)
6257 (defconst vhdl-trailer-re
6258 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6260 (defconst vhdl-statement-fwd-re
6261 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6262 "A regular expression for searching forward that matches all known
6263 \"statement\" keywords.")
6265 (defconst vhdl-statement-bwd-re
6266 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6267 "A regular expression for searching backward that matches all known
6268 \"statement\" keywords.")
6270 (defun vhdl-statement-p (&optional lim)
6271 "Return t if we are looking at a real \"statement\" keyword.
6272 Assumes that the caller will make sure that we are looking at
6273 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6274 in the middle of an identifier that just happens to contain a
6275 \"statement\" keyword."
6276 (cond
6277 ;; "for" ... "generate":
6278 ((and (looking-at "f")
6279 ;; Make sure it's the start of a parameter specification.
6280 (save-excursion
6281 (forward-sexp 2)
6282 (skip-chars-forward " \t\n\r\f")
6283 (looking-at "in\\b[^_]"))
6284 ;; Make sure it's not an "end for".
6285 (save-excursion
6286 (backward-sexp)
6287 (not (looking-at "end\\s-+\\w"))))
6289 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6290 ((and (looking-at "i")
6291 ;; Make sure it's not an "end if".
6292 (save-excursion
6293 (backward-sexp)
6294 (not (looking-at "end\\s-+\\w"))))
6296 ;; "while" ... "loop":
6297 ((looking-at "w")
6301 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6302 "Regexp describing a case statement alternative key.")
6304 (defun vhdl-case-alternative-p (&optional lim)
6305 "Return t if we are looking at a real case alternative.
6306 Assumes that the caller will make sure that we are looking at
6307 vhdl-case-alternative-re, and are not inside a literal, and that
6308 we are not in the middle of an identifier that just happens to
6309 contain a \"when\" keyword."
6310 (save-excursion
6311 (let (foundp)
6312 (while (and (not foundp)
6313 (re-search-backward ";\\|<=" lim 'move))
6314 (if (or (= (preceding-char) ?_)
6315 (vhdl-in-literal))
6316 (backward-char)
6317 (setq foundp t)))
6318 (or (eq (following-char) ?\;)
6319 (eq (point) lim)))
6322 ;; Core syntactic movement functions:
6324 (defconst vhdl-b-t-b-re
6325 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6327 (defun vhdl-backward-to-block (&optional lim)
6328 "Move backward to the previous \"begin\" or \"end\" keyword."
6329 (let (foundp)
6330 (while (and (not foundp)
6331 (re-search-backward vhdl-b-t-b-re lim 'move))
6332 (if (or (= (preceding-char) ?_)
6333 (vhdl-in-literal))
6334 (backward-char)
6335 (cond
6336 ;; "begin" keyword:
6337 ((and (looking-at vhdl-begin-fwd-re)
6338 (or (not (looking-at "\\<use\\>"))
6339 (save-excursion (back-to-indentation)
6340 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6341 (/= (preceding-char) ?_)
6342 (vhdl-begin-p lim))
6343 (setq foundp 'begin))
6344 ;; "end" keyword:
6345 ((and (looking-at vhdl-end-fwd-re)
6346 (/= (preceding-char) ?_)
6347 (vhdl-end-p lim))
6348 (setq foundp 'end))
6351 foundp
6354 (defun vhdl-forward-sexp (&optional count lim)
6355 "Move forward across one balanced expression (sexp).
6356 With COUNT, do it that many times."
6357 (interactive "p")
6358 (let ((count (or count 1))
6359 (case-fold-search t)
6360 end-vec target)
6361 (save-excursion
6362 (while (> count 0)
6363 ;; skip whitespace
6364 (skip-chars-forward " \t\n\r\f")
6365 ;; Check for an unbalanced "end" keyword
6366 (if (and (looking-at vhdl-end-fwd-re)
6367 (/= (preceding-char) ?_)
6368 (not (vhdl-in-literal))
6369 (vhdl-end-p lim)
6370 (not (looking-at "else")))
6371 (error
6372 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6373 ;; If the current keyword is a "begin" keyword, then find the
6374 ;; corresponding "end" keyword.
6375 (if (setq end-vec (vhdl-corresponding-end lim))
6376 (let (
6377 ;; end-re is the statement keyword to search for
6378 (end-re
6379 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6380 ;; column is either the statement keyword target column
6381 ;; or nil
6382 (column (aref end-vec 1))
6383 (eol (vhdl-point 'eol))
6384 foundp literal placeholder)
6385 ;; Look for the statement keyword.
6386 (while (and (not foundp)
6387 (re-search-forward end-re nil t)
6388 (setq placeholder (match-end 1))
6389 (goto-char (match-beginning 0)))
6390 ;; If we are in a literal, or not in the right target
6391 ;; column and not on the same line as the begin, then
6392 ;; try again.
6393 (if (or (and column
6394 (/= (current-indentation) column)
6395 (> (point) eol))
6396 (= (preceding-char) ?_)
6397 (setq literal (vhdl-in-literal)))
6398 (if (eq literal 'comment)
6399 (end-of-line)
6400 (forward-char))
6401 ;; An "else" keyword corresponds to both the opening brace
6402 ;; of the following sexp and the closing brace of the
6403 ;; previous sexp.
6404 (if (not (looking-at "else"))
6405 (goto-char placeholder))
6406 (setq foundp t))
6408 (if (not foundp)
6409 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6411 ;; If the current keyword is not a "begin" keyword, then just
6412 ;; perform the normal forward-sexp.
6413 (forward-sexp)
6415 (setq count (1- count))
6417 (setq target (point)))
6418 (goto-char target)
6419 nil))
6421 (defun vhdl-backward-sexp (&optional count lim)
6422 "Move backward across one balanced expression (sexp).
6423 With COUNT, do it that many times. LIM bounds any required backward
6424 searches."
6425 (interactive "p")
6426 (let ((count (or count 1))
6427 (case-fold-search t)
6428 begin-vec target)
6429 (save-excursion
6430 (while (> count 0)
6431 ;; Perform the normal backward-sexp, unless we are looking at
6432 ;; "else" - an "else" keyword corresponds to both the opening brace
6433 ;; of the following sexp and the closing brace of the previous sexp.
6434 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6435 (/= (preceding-char) ?_)
6436 (not (vhdl-in-literal)))
6438 (backward-sexp)
6439 (if (and (looking-at vhdl-begin-fwd-re)
6440 (or (not (looking-at "\\<use\\>"))
6441 (save-excursion
6442 (back-to-indentation)
6443 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6444 (/= (preceding-char) ?_)
6445 (not (vhdl-in-literal))
6446 (vhdl-begin-p lim))
6447 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6448 ;; If the current keyword is an "end" keyword, then find the
6449 ;; corresponding "begin" keyword.
6450 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6451 (/= (preceding-char) ?_))
6452 (let (
6453 ;; begin-re is the statement keyword to search for
6454 (begin-re
6455 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6456 ;; column is either the statement keyword target column
6457 ;; or nil
6458 (column (aref begin-vec 1))
6459 ;; internal-p controls where the statement keyword can
6460 ;; be found.
6461 (internal-p (aref begin-vec 3))
6462 (last-backward (point)) last-forward
6463 foundp literal keyword)
6464 ;; Look for the statement keyword.
6465 (while (and (not foundp)
6466 (re-search-backward begin-re lim t)
6467 (setq keyword
6468 (buffer-substring (match-beginning 1)
6469 (match-end 1))))
6470 ;; If we are in a literal or in the wrong column,
6471 ;; then try again.
6472 (if (or (and column
6473 (and (/= (current-indentation) column)
6474 ;; possibly accept current-column as
6475 ;; well as current-indentation.
6476 (or (not internal-p)
6477 (/= (current-column) column))))
6478 (= (preceding-char) ?_)
6479 (vhdl-in-literal))
6480 (backward-char)
6481 ;; If there is a supplementary keyword, then
6482 ;; search forward for it.
6483 (if (and (setq begin-re (aref begin-vec 2))
6484 (or (not (listp begin-re))
6485 ;; If begin-re is an alist, then find the
6486 ;; element corresponding to the actual
6487 ;; keyword that we found.
6488 (progn
6489 (setq begin-re
6490 (assoc keyword begin-re))
6491 (and begin-re
6492 (setq begin-re (cdr begin-re))))))
6493 (and
6494 (setq begin-re
6495 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6496 (save-excursion
6497 (setq last-forward (point))
6498 ;; Look for the supplementary keyword
6499 ;; (bounded by the backward search start
6500 ;; point).
6501 (while (and (not foundp)
6502 (re-search-forward begin-re
6503 last-backward t)
6504 (goto-char (match-beginning 1)))
6505 ;; If we are in a literal, then try again.
6506 (if (or (= (preceding-char) ?_)
6507 (setq literal
6508 (vhdl-in-literal)))
6509 (if (eq literal 'comment)
6510 (goto-char
6511 (min (vhdl-point 'eol) last-backward))
6512 (forward-char))
6513 ;; We have found the supplementary keyword.
6514 ;; Save the position of the keyword in foundp.
6515 (setq foundp (point)))
6517 foundp)
6518 ;; If the supplementary keyword was found, then
6519 ;; move point to the supplementary keyword.
6520 (goto-char foundp))
6521 ;; If there was no supplementary keyword, then
6522 ;; point is already at the statement keyword.
6523 (setq foundp t)))
6524 ) ; end of the search for the statement keyword
6525 (if (not foundp)
6526 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6528 (setq count (1- count))
6530 (setq target (point)))
6531 (goto-char target)
6532 nil))
6534 (defun vhdl-backward-up-list (&optional count limit)
6535 "Move backward out of one level of blocks.
6536 With argument, do this that many times."
6537 (interactive "p")
6538 (let ((count (or count 1))
6539 target)
6540 (save-excursion
6541 (while (> count 0)
6542 (if (looking-at vhdl-defun-re)
6543 (error "ERROR: Unbalanced blocks"))
6544 (vhdl-backward-to-block limit)
6545 (setq count (1- count)))
6546 (setq target (point)))
6547 (goto-char target)))
6549 (defun vhdl-end-of-defun (&optional count)
6550 "Move forward to the end of a VHDL defun."
6551 (interactive)
6552 (let ((case-fold-search t))
6553 (vhdl-beginning-of-defun)
6554 (if (not (looking-at "block\\|process\\|procedural"))
6555 (re-search-forward "\\bis\\b"))
6556 (vhdl-forward-sexp)))
6558 (defun vhdl-mark-defun ()
6559 "Put mark at end of this \"defun\", point at beginning."
6560 (interactive)
6561 (let ((case-fold-search t))
6562 (push-mark)
6563 (vhdl-beginning-of-defun)
6564 (push-mark)
6565 (if (not (looking-at "block\\|process\\|procedural"))
6566 (re-search-forward "\\bis\\b"))
6567 (vhdl-forward-sexp)
6568 (exchange-point-and-mark)))
6570 (defun vhdl-beginning-of-libunit ()
6571 "Move backward to the beginning of a VHDL library unit.
6572 Returns the location of the corresponding begin keyword, unless search
6573 stops due to beginning or end of buffer.
6574 Note that if point is between the \"libunit\" keyword and the
6575 corresponding \"begin\" keyword, then that libunit will not be
6576 recognized, and the search will continue backwards. If point is
6577 at the \"begin\" keyword, then the defun will be recognized. The
6578 returned point is at the first character of the \"libunit\" keyword."
6579 (let ((last-forward (point))
6580 (last-backward
6581 ;; Just in case we are actually sitting on the "begin"
6582 ;; keyword, allow for the keyword and an extra character,
6583 ;; as this will be used when looking forward for the
6584 ;; "begin" keyword.
6585 (save-excursion (forward-word-strictly 1) (1+ (point))))
6586 foundp literal placeholder)
6587 ;; Find the "libunit" keyword.
6588 (while (and (not foundp)
6589 (re-search-backward vhdl-libunit-re nil 'move))
6590 ;; If we are in a literal, or not at a real libunit, then try again.
6591 (if (or (= (preceding-char) ?_)
6592 (vhdl-in-literal)
6593 (not (vhdl-libunit-p)))
6594 (backward-char)
6595 ;; Find the corresponding "begin" keyword.
6596 (setq last-forward (point))
6597 (while (and (not foundp)
6598 (re-search-forward "\\bis\\b[^_]" last-backward t)
6599 (setq placeholder (match-beginning 0)))
6600 (if (or (= (preceding-char) ?_)
6601 (setq literal (vhdl-in-literal)))
6602 ;; It wasn't a real keyword, so keep searching.
6603 (if (eq literal 'comment)
6604 (goto-char
6605 (min (vhdl-point 'eol) last-backward))
6606 (forward-char))
6607 ;; We have found the begin keyword, loop will exit.
6608 (setq foundp placeholder)))
6609 ;; Go back to the libunit keyword
6610 (goto-char last-forward)))
6611 foundp))
6613 (defun vhdl-beginning-of-defun (&optional count)
6614 "Move backward to the beginning of a VHDL defun.
6615 With argument, do it that many times.
6616 Returns the location of the corresponding begin keyword, unless search
6617 stops due to beginning or end of buffer."
6618 ;; Note that if point is between the "defun" keyword and the
6619 ;; corresponding "begin" keyword, then that defun will not be
6620 ;; recognized, and the search will continue backwards. If point is
6621 ;; at the "begin" keyword, then the defun will be recognized. The
6622 ;; returned point is at the first character of the "defun" keyword.
6623 (interactive "p")
6624 (let ((count (or count 1))
6625 (case-fold-search t)
6626 (last-forward (point))
6627 foundp)
6628 (while (> count 0)
6629 (setq foundp nil)
6630 (goto-char last-forward)
6631 (let ((last-backward
6632 ;; Just in case we are actually sitting on the "begin"
6633 ;; keyword, allow for the keyword and an extra character,
6634 ;; as this will be used when looking forward for the
6635 ;; "begin" keyword.
6636 (save-excursion (forward-word-strictly 1) (1+ (point))))
6637 begin-string literal)
6638 (while (and (not foundp)
6639 (re-search-backward vhdl-defun-re nil 'move))
6640 ;; If we are in a literal, then try again.
6641 (if (or (= (preceding-char) ?_)
6642 (vhdl-in-literal))
6643 (backward-char)
6644 (if (setq begin-string (vhdl-corresponding-defun))
6645 ;; This is a real defun keyword.
6646 ;; Find the corresponding "begin" keyword.
6647 ;; Look for the begin keyword.
6648 (progn
6649 ;; Save the search start point.
6650 (setq last-forward (point))
6651 (while (and (not foundp)
6652 (search-forward begin-string last-backward t))
6653 (if (or (= (preceding-char) ?_)
6654 (save-match-data
6655 (setq literal (vhdl-in-literal))))
6656 ;; It wasn't a real keyword, so keep searching.
6657 (if (eq literal 'comment)
6658 (goto-char
6659 (min (vhdl-point 'eol) last-backward))
6660 (forward-char))
6661 ;; We have found the begin keyword, loop will exit.
6662 (setq foundp (match-beginning 0)))
6664 ;; Go back to the defun keyword
6665 (goto-char last-forward)) ; end search for begin keyword
6667 ) ; end of the search for the defun keyword
6669 (setq count (1- count))
6671 (vhdl-keep-region-active)
6672 foundp))
6674 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6675 "Go to the beginning of the innermost VHDL statement.
6676 With prefix arg, go back N - 1 statements. If already at the
6677 beginning of a statement then go to the beginning of the preceding
6678 one. If within a string or comment, or next to a comment (only
6679 whitespace between), move by sentences instead of statements.
6681 When called from a program, this function takes 3 optional args: the
6682 prefix arg, a buffer position limit which is the farthest back to
6683 search, and an argument indicating an interactive call."
6684 (interactive "p\np")
6685 (let ((count (or count 1))
6686 (case-fold-search t)
6687 (lim (or lim (point-min)))
6688 (here (point))
6689 state)
6690 (save-excursion
6691 (goto-char lim)
6692 (setq state (parse-partial-sexp (point) here nil nil)))
6693 (if (and interactive
6694 (or (nth 3 state)
6695 (nth 4 state)
6696 (looking-at (concat "[ \t]*" comment-start-skip))))
6697 (forward-sentence (- count))
6698 (while (> count 0)
6699 (vhdl-beginning-of-statement-1 lim)
6700 (setq count (1- count))))
6701 ;; its possible we've been left up-buf of lim
6702 (goto-char (max (point) lim))
6704 (vhdl-keep-region-active))
6706 (defconst vhdl-e-o-s-re
6707 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6709 (defun vhdl-end-of-statement ()
6710 "Very simple implementation."
6711 (interactive)
6712 (re-search-forward vhdl-e-o-s-re))
6714 (defconst vhdl-b-o-s-re
6715 (concat ";[^_]\\|([^_]\\|)[^_]\\|\\bwhen\\b[^_]\\|"
6716 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6718 (defun vhdl-beginning-of-statement-1 (&optional lim)
6719 "Move to the start of the current statement, or the previous
6720 statement if already at the beginning of one."
6721 (let ((lim (or lim (point-min)))
6722 (here (point))
6723 (pos (point))
6724 donep)
6725 ;; go backwards one balanced expression, but be careful of
6726 ;; unbalanced paren being reached
6727 (if (not (vhdl-safe (progn (backward-sexp) t)))
6728 (progn
6729 (backward-up-list 1)
6730 (forward-char)
6731 (vhdl-forward-syntactic-ws here)
6732 (setq donep t)))
6733 (while (and (not donep)
6734 (not (bobp))
6735 ;; look backwards for a statement boundary
6736 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6737 (if (or (= (preceding-char) ?_)
6738 (vhdl-in-literal))
6739 (backward-char)
6740 (cond
6741 ;; If we are looking at an open paren, then stop after it
6742 ((eq (following-char) ?\()
6743 (forward-char)
6744 (vhdl-forward-syntactic-ws here)
6745 (setq donep t))
6746 ;; If we are looking at a close paren, then skip it
6747 ((eq (following-char) ?\))
6748 (forward-char)
6749 (setq pos (point))
6750 (backward-sexp)
6751 (if (< (point) lim)
6752 (progn (goto-char pos)
6753 (vhdl-forward-syntactic-ws here)
6754 (setq donep t))))
6755 ;; If we are looking at a semicolon, then stop
6756 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6757 (progn
6758 (forward-char)
6759 (vhdl-forward-syntactic-ws here)
6760 (setq donep t)))
6761 ;; If we are looking at a "begin", then stop
6762 ((and (looking-at vhdl-begin-fwd-re)
6763 (or (not (looking-at "\\<use\\>"))
6764 (save-excursion
6765 (back-to-indentation)
6766 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6767 (/= (preceding-char) ?_)
6768 (vhdl-begin-p nil))
6769 ;; If it's a leader "begin", then find the
6770 ;; right place
6771 (if (looking-at vhdl-leader-re)
6772 (save-excursion
6773 ;; set a default stop point at the begin
6774 (setq pos (point))
6775 ;; is the start point inside the leader area ?
6776 (goto-char (vhdl-end-of-leader))
6777 (vhdl-forward-syntactic-ws here)
6778 (if (< (point) here)
6779 ;; start point was not inside leader area
6780 ;; set stop point at word after leader
6781 (setq pos (point))))
6782 (forward-word-strictly 1)
6783 (vhdl-forward-syntactic-ws here)
6784 (setq pos (point)))
6785 (goto-char pos)
6786 (setq donep t))
6787 ;; If we are looking at a "statement", then stop
6788 ((and (looking-at vhdl-statement-fwd-re)
6789 (/= (preceding-char) ?_)
6790 (vhdl-statement-p nil))
6791 (setq donep t))
6792 ;; If we are looking at a case alternative key, then stop
6793 ((and (looking-at vhdl-case-alternative-re)
6794 (vhdl-case-alternative-p lim))
6795 (save-excursion
6796 ;; set a default stop point at the when
6797 (setq pos (point))
6798 ;; is the start point inside the case alternative key ?
6799 (looking-at vhdl-case-alternative-re)
6800 (goto-char (match-end 0))
6801 (vhdl-forward-syntactic-ws here)
6802 (if (< (point) here)
6803 ;; start point was not inside the case alternative key
6804 ;; set stop point at word after case alternative keyleader
6805 (setq pos (point))))
6806 (goto-char pos)
6807 (setq donep t))
6808 ;; Bogus find, continue
6810 (backward-char)))))
6813 ;; Defuns for calculating the current syntactic state:
6815 (defun vhdl-get-library-unit (bod placeholder)
6816 "If there is an enclosing library unit at BOD, with its \"begin\"
6817 keyword at PLACEHOLDER, then return the library unit type."
6818 (let ((here (vhdl-point 'bol)))
6819 (if (save-excursion
6820 (goto-char placeholder)
6821 (vhdl-safe (vhdl-forward-sexp 1 bod))
6822 (<= here (point)))
6823 (save-excursion
6824 (goto-char bod)
6825 (cond
6826 ((looking-at "e") 'entity)
6827 ((looking-at "a") 'architecture)
6828 ((looking-at "conf") 'configuration)
6829 ((looking-at "cont") 'context)
6830 ((looking-at "p")
6831 (save-excursion
6832 (goto-char bod)
6833 (forward-sexp)
6834 (vhdl-forward-syntactic-ws here)
6835 (if (looking-at "body\\b[^_]")
6836 'package-body 'package))))))
6839 (defun vhdl-get-block-state (&optional lim)
6840 "Finds and records all the closest opens.
6841 LIM is the furthest back we need to search (it should be the
6842 previous libunit keyword)."
6843 (let ((here (point))
6844 (lim (or lim (point-min)))
6845 keyword sexp-start sexp-mid sexp-end
6846 preceding-sexp containing-sexp
6847 containing-begin containing-mid containing-paren)
6848 (save-excursion
6849 ;; Find the containing-paren, and use that as the limit
6850 (if (setq containing-paren
6851 (save-restriction
6852 (narrow-to-region lim (point))
6853 (vhdl-safe (scan-lists (point) -1 1))))
6854 (setq lim containing-paren))
6855 ;; Look backwards for "begin" and "end" keywords.
6856 (while (and (> (point) lim)
6857 (not containing-sexp))
6858 (setq keyword (vhdl-backward-to-block lim))
6859 (cond
6860 ((eq keyword 'begin)
6861 ;; Found a "begin" keyword
6862 (setq sexp-start (point))
6863 (setq sexp-mid (vhdl-corresponding-mid lim))
6864 (setq sexp-end (vhdl-safe
6865 (save-excursion
6866 (vhdl-forward-sexp 1 lim) (point))))
6867 (if (and sexp-end (<= sexp-end here))
6868 ;; we want to record this sexp, but we only want to
6869 ;; record the last-most of any of them before here
6870 (or preceding-sexp
6871 (setq preceding-sexp sexp-start))
6872 ;; we're contained in this sexp so put sexp-start on
6873 ;; front of list
6874 (setq containing-sexp sexp-start)
6875 (setq containing-mid sexp-mid)
6876 (setq containing-begin t)))
6877 ((eq keyword 'end)
6878 ;; Found an "end" keyword
6879 (forward-sexp)
6880 (setq sexp-end (point))
6881 (setq sexp-mid nil)
6882 (setq sexp-start
6883 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6884 (progn (backward-sexp) (point))))
6885 ;; we want to record this sexp, but we only want to
6886 ;; record the last-most of any of them before here
6887 (or preceding-sexp
6888 (setq preceding-sexp sexp-start)))
6890 ;; Check if the containing-paren should be the containing-sexp
6891 (if (and containing-paren
6892 (or (null containing-sexp)
6893 (< containing-sexp containing-paren)))
6894 (setq containing-sexp containing-paren
6895 preceding-sexp nil
6896 containing-begin nil
6897 containing-mid nil))
6898 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6902 (defconst vhdl-s-c-a-re
6903 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6905 (defun vhdl-skip-case-alternative (&optional lim)
6906 "Skip forward over case/when bodies, with optional maximal
6907 limit. If no next case alternative is found, nil is returned and
6908 point is not moved."
6909 (let ((lim (or lim (point-max)))
6910 (here (point))
6911 donep foundp)
6912 (while (and (< (point) lim)
6913 (not donep))
6914 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6915 (save-match-data
6916 (not (vhdl-in-literal)))
6917 (/= (match-beginning 0) here))
6918 (progn
6919 (goto-char (match-beginning 0))
6920 (cond
6921 ((and (looking-at "case")
6922 (re-search-forward "\\bis[^_]" lim t))
6923 (backward-sexp)
6924 (vhdl-forward-sexp))
6926 (setq donep t
6927 foundp t))))))
6928 (if (not foundp)
6929 (goto-char here))
6930 foundp))
6932 (defun vhdl-backward-skip-label (&optional lim)
6933 "Skip backward over a label, with optional maximal
6934 limit. If label is not found, nil is returned and point
6935 is not moved."
6936 (let ((lim (or lim (point-min)))
6937 placeholder)
6938 (if (save-excursion
6939 (vhdl-backward-syntactic-ws lim)
6940 (and (eq (preceding-char) ?:)
6941 (progn
6942 (backward-sexp)
6943 (setq placeholder (point))
6944 (looking-at vhdl-label-key))))
6945 (goto-char placeholder))
6948 (defun vhdl-forward-skip-label (&optional lim)
6949 "Skip forward over a label, with optional maximal
6950 limit. If label is not found, nil is returned and point
6951 is not moved."
6952 (let ((lim (or lim (point-max))))
6953 (if (looking-at vhdl-label-key)
6954 (progn
6955 (goto-char (match-end 0))
6956 (vhdl-forward-syntactic-ws lim)))
6959 (defun vhdl-get-syntactic-context ()
6960 "Guess the syntactic description of the current line of VHDL code."
6961 (save-excursion
6962 (save-restriction
6963 (beginning-of-line)
6964 (let* ((indent-point (point))
6965 (case-fold-search t)
6966 vec literal containing-sexp preceding-sexp
6967 containing-begin containing-mid containing-leader
6968 char-before-ip char-after-ip begin-after-ip end-after-ip
6969 placeholder lim library-unit
6972 ;; Reset the syntactic context
6973 (setq vhdl-syntactic-context nil)
6975 (save-excursion
6976 ;; Move to the start of the previous library unit, and
6977 ;; record the position of the "begin" keyword.
6978 (setq placeholder (vhdl-beginning-of-libunit))
6979 ;; The position of the "libunit" keyword gives us a gross
6980 ;; limit point.
6981 (setq lim (point))
6984 ;; If there is a previous library unit, and we are enclosed by
6985 ;; it, then set the syntax accordingly.
6986 (and placeholder
6987 (setq library-unit (vhdl-get-library-unit lim placeholder))
6988 (vhdl-add-syntax library-unit lim))
6990 ;; Find the surrounding state.
6991 (if (setq vec (vhdl-get-block-state lim))
6992 (progn
6993 (setq containing-sexp (aref vec 0))
6994 (setq preceding-sexp (aref vec 1))
6995 (setq containing-begin (aref vec 2))
6996 (setq containing-mid (aref vec 3))
6999 ;; set the limit on the farthest back we need to search
7000 (setq lim (if containing-sexp
7001 (save-excursion
7002 (goto-char containing-sexp)
7003 ;; set containing-leader if required
7004 (if (looking-at vhdl-leader-re)
7005 (setq containing-leader (vhdl-end-of-leader)))
7006 (vhdl-point 'bol))
7007 (point-min)))
7009 ;; cache char before and after indent point, and move point to
7010 ;; the most likely position to perform the majority of tests
7011 (goto-char indent-point)
7012 (skip-chars-forward " \t")
7013 (setq literal (vhdl-in-literal))
7014 (setq char-after-ip (following-char))
7015 (setq begin-after-ip (and
7016 (not literal)
7017 (looking-at vhdl-begin-fwd-re)
7018 (or (not (looking-at "\\<use\\>"))
7019 (save-excursion
7020 (back-to-indentation)
7021 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
7022 (vhdl-begin-p)))
7023 (setq end-after-ip (and
7024 (not literal)
7025 (looking-at vhdl-end-fwd-re)
7026 (vhdl-end-p)))
7027 (vhdl-backward-syntactic-ws lim)
7028 (setq char-before-ip (preceding-char))
7029 (goto-char indent-point)
7030 (skip-chars-forward " \t")
7032 ;; now figure out syntactic qualities of the current line
7033 (cond
7034 ;; CASE 1: in a string or comment.
7035 ((memq literal '(string comment))
7036 (vhdl-add-syntax literal (vhdl-point 'bopl)))
7037 ;; CASE 2: Line is at top level.
7038 ((null containing-sexp)
7039 ;; Find the point to which indentation will be relative
7040 (save-excursion
7041 (if (null preceding-sexp)
7042 ;; CASE 2X.1
7043 ;; no preceding-sexp -> use the preceding statement
7044 (vhdl-beginning-of-statement-1 lim)
7045 ;; CASE 2X.2
7046 ;; if there is a preceding-sexp then indent relative to it
7047 (goto-char preceding-sexp)
7048 ;; if not at boi, then the block-opening keyword is
7049 ;; probably following a label, so we need a different
7050 ;; relpos
7051 (if (/= (point) (vhdl-point 'boi))
7052 ;; CASE 2X.3
7053 (vhdl-beginning-of-statement-1 lim)))
7054 ;; v-b-o-s could have left us at point-min
7055 (and (bobp)
7056 ;; CASE 2X.4
7057 (vhdl-forward-syntactic-ws indent-point))
7058 (setq placeholder (point)))
7059 (cond
7060 ;; CASE 2A : we are looking at a block-open
7061 (begin-after-ip
7062 (vhdl-add-syntax 'block-open placeholder))
7063 ;; CASE 2B: we are looking at a block-close
7064 (end-after-ip
7065 (vhdl-add-syntax 'block-close placeholder))
7066 ;; CASE 2C: we are looking at a top-level statement
7067 ((progn
7068 (vhdl-backward-syntactic-ws lim)
7069 (or (bobp)
7070 (and (= (preceding-char) ?\;)
7071 (not (vhdl-in-quote-p)))))
7072 (vhdl-add-syntax 'statement placeholder))
7073 ;; CASE 2D: we are looking at a top-level statement-cont
7075 (vhdl-beginning-of-statement-1 lim)
7076 ;; v-b-o-s could have left us at point-min
7077 (and (bobp)
7078 ;; CASE 2D.1
7079 (vhdl-forward-syntactic-ws indent-point))
7080 (vhdl-add-syntax 'statement-cont (point)))
7081 )) ; end CASE 2
7082 ;; CASE 3: line is inside parentheses. Most likely we are
7083 ;; either in a subprogram argument (interface) list, or a
7084 ;; continued expression containing parentheses.
7085 ((null containing-begin)
7086 (vhdl-backward-syntactic-ws containing-sexp)
7087 (cond
7088 ;; CASE 3A: we are looking at the arglist closing paren
7089 ((eq char-after-ip ?\))
7090 (goto-char containing-sexp)
7091 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
7092 ;; CASE 3B: we are looking at the first argument in an empty
7093 ;; argument list.
7094 ((eq char-before-ip ?\()
7095 (goto-char containing-sexp)
7096 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
7097 ;; CASE 3C: we are looking at an arglist continuation line,
7098 ;; but the preceding argument is on the same line as the
7099 ;; opening paren. This case includes multi-line
7100 ;; expression paren groupings.
7101 ((and (save-excursion
7102 (goto-char (1+ containing-sexp))
7103 (skip-chars-forward " \t")
7104 (not (eolp))
7105 (not (looking-at "--\\|`")))
7106 (save-excursion
7107 (vhdl-beginning-of-statement-1 containing-sexp)
7108 (skip-chars-backward " \t(")
7109 (while (and (= (preceding-char) ?\;)
7110 (not (vhdl-in-quote-p)))
7111 (vhdl-beginning-of-statement-1 containing-sexp)
7112 (skip-chars-backward " \t("))
7113 (<= (point) containing-sexp)))
7114 (goto-char containing-sexp)
7115 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
7116 ;; CASE 3D: we are looking at just a normal arglist
7117 ;; continuation line
7118 (t (vhdl-beginning-of-statement-1 containing-sexp)
7119 (vhdl-forward-syntactic-ws indent-point)
7120 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
7122 ;; CASE 4: A block mid open
7123 ((and begin-after-ip
7124 (looking-at containing-mid))
7125 (goto-char containing-sexp)
7126 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7127 (if (looking-at vhdl-trailer-re)
7128 ;; CASE 4.1
7129 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7130 (vhdl-backward-skip-label (vhdl-point 'boi))
7131 (vhdl-add-syntax 'block-open (point)))
7132 ;; CASE 5: block close brace
7133 (end-after-ip
7134 (goto-char containing-sexp)
7135 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7136 (if (looking-at vhdl-trailer-re)
7137 ;; CASE 5.1
7138 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7139 (vhdl-backward-skip-label (vhdl-point 'boi))
7140 (vhdl-add-syntax 'block-close (point)))
7141 ;; CASE 6: A continued statement
7142 ((and (/= char-before-ip ?\;)
7143 ;; check it's not a trailer begin keyword, or a begin
7144 ;; keyword immediately following a label.
7145 (not (and begin-after-ip
7146 (or (looking-at vhdl-trailer-re)
7147 (save-excursion
7148 (vhdl-backward-skip-label containing-sexp)))))
7149 ;; check it's not a statement keyword
7150 (not (and (looking-at vhdl-statement-fwd-re)
7151 (vhdl-statement-p)))
7152 ;; see if the b-o-s is before the indent point
7153 (> indent-point
7154 (save-excursion
7155 (vhdl-beginning-of-statement-1 containing-sexp)
7156 ;; If we ended up after a leader, then this will
7157 ;; move us forward to the start of the first
7158 ;; statement. Note that a containing sexp here is
7159 ;; always a keyword, not a paren, so this will
7160 ;; have no effect if we hit the containing-sexp.
7161 (vhdl-forward-syntactic-ws indent-point)
7162 (setq placeholder (point))))
7163 ;; check it's not a block-intro
7164 (/= placeholder containing-sexp)
7165 ;; check it's not a case block-intro
7166 (save-excursion
7167 (goto-char placeholder)
7168 (or (not (looking-at vhdl-case-alternative-re))
7169 (> (match-end 0) indent-point))))
7170 ;; Make placeholder skip a label, but only if it puts us
7171 ;; before the indent point at the start of a line.
7172 (let ((new placeholder))
7173 (if (and (> indent-point
7174 (save-excursion
7175 (goto-char placeholder)
7176 (vhdl-forward-skip-label indent-point)
7177 (setq new (point))))
7178 (save-excursion
7179 (goto-char new)
7180 (eq new (progn (back-to-indentation) (point)))))
7181 (setq placeholder new)))
7182 (vhdl-add-syntax 'statement-cont placeholder)
7183 (if begin-after-ip
7184 (vhdl-add-syntax 'block-open)))
7185 ;; Statement. But what kind?
7186 ;; CASE 7: A case alternative key
7187 ((and (looking-at vhdl-case-alternative-re)
7188 (vhdl-case-alternative-p containing-sexp))
7189 ;; for a case alternative key, we set relpos to the first
7190 ;; non-whitespace char on the line containing the "case"
7191 ;; keyword.
7192 (goto-char containing-sexp)
7193 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7194 (if (looking-at vhdl-trailer-re)
7195 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7196 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
7197 ;; CASE 8: statement catchall
7199 ;; we know its a statement, but we need to find out if it is
7200 ;; the first statement in a block
7201 (if containing-leader
7202 (goto-char containing-leader)
7203 (goto-char containing-sexp)
7204 ;; Note that a containing sexp here is always a keyword,
7205 ;; not a paren, so skip over the keyword.
7206 (forward-sexp))
7207 ;; move to the start of the first statement
7208 (vhdl-forward-syntactic-ws indent-point)
7209 (setq placeholder (point))
7210 ;; we want to ignore case alternatives keys when skipping forward
7211 (let (incase-p)
7212 (while (looking-at vhdl-case-alternative-re)
7213 (setq incase-p (point))
7214 ;; we also want to skip over the body of the
7215 ;; case/when statement if that doesn't put us at
7216 ;; after the indent-point
7217 (while (vhdl-skip-case-alternative indent-point))
7218 ;; set up the match end
7219 (looking-at vhdl-case-alternative-re)
7220 (goto-char (match-end 0))
7221 ;; move to the start of the first case alternative statement
7222 (vhdl-forward-syntactic-ws indent-point)
7223 (setq placeholder (point)))
7224 (cond
7225 ;; CASE 8A: we saw a case/when statement so we must be
7226 ;; in a switch statement. find out if we are at the
7227 ;; statement just after a case alternative key
7228 ((and incase-p
7229 (= (point) indent-point))
7230 ;; relpos is the "when" keyword
7231 (vhdl-add-syntax 'statement-case-intro incase-p))
7232 ;; CASE 8B: any old statement
7233 ((< (point) indent-point)
7234 ;; relpos is the first statement of the block
7235 (vhdl-add-syntax 'statement placeholder)
7236 (if begin-after-ip
7237 (vhdl-add-syntax 'block-open)))
7238 ;; CASE 8C: first statement in a block
7240 (goto-char containing-sexp)
7241 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7242 (if (looking-at vhdl-trailer-re)
7243 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7244 (vhdl-backward-skip-label (vhdl-point 'boi))
7245 (vhdl-add-syntax 'statement-block-intro (point))
7246 (if begin-after-ip
7247 (vhdl-add-syntax 'block-open)))
7251 ;; now we need to look at any modifiers
7252 (goto-char indent-point)
7253 (skip-chars-forward " \t")
7254 (if (or (looking-at "--") (looking-at "/\\*"))
7255 (vhdl-add-syntax 'comment))
7256 (if (looking-at "`")
7257 (vhdl-add-syntax 'directive))
7258 (if (eq literal 'pound)
7259 (vhdl-add-syntax 'cpp-macro))
7260 ;; return the syntax
7261 vhdl-syntactic-context))))
7263 ;; Standard indentation line-ups:
7265 (defun vhdl-lineup-arglist (langelem)
7266 "Lineup the current arglist line with the arglist appearing just
7267 after the containing paren which starts the arglist."
7268 (save-excursion
7269 (let* ((containing-sexp
7270 (save-excursion
7271 ;; arglist-cont-nonempty gives relpos ==
7272 ;; to boi of containing-sexp paren. This
7273 ;; is good when offset is +, but bad
7274 ;; when it is vhdl-lineup-arglist, so we
7275 ;; have to special case a kludge here.
7276 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7277 (progn
7278 (beginning-of-line)
7279 (backward-up-list 1)
7280 (skip-chars-forward " \t" (vhdl-point 'eol)))
7281 (goto-char (cdr langelem)))
7282 (point)))
7283 (cs-curcol (save-excursion
7284 (goto-char (cdr langelem))
7285 (current-column))))
7286 (if (save-excursion
7287 (beginning-of-line)
7288 (looking-at "[ \t]*)"))
7289 (progn (goto-char (match-end 0))
7290 (backward-sexp)
7291 (forward-char)
7292 (vhdl-forward-syntactic-ws)
7293 (- (current-column) cs-curcol))
7294 (goto-char containing-sexp)
7295 (or (eolp)
7296 (let ((eol (vhdl-point 'eol))
7297 (here (progn
7298 (forward-char)
7299 (skip-chars-forward " \t")
7300 (point))))
7301 (vhdl-forward-syntactic-ws)
7302 (if (< (point) eol)
7303 (goto-char here))))
7304 (- (current-column) cs-curcol)
7305 ))))
7307 (defun vhdl-lineup-arglist-intro (langelem)
7308 "Lineup an arglist-intro line to just after the open paren."
7309 (save-excursion
7310 (let ((cs-curcol (save-excursion
7311 (goto-char (cdr langelem))
7312 (current-column)))
7313 (ce-curcol (save-excursion
7314 (beginning-of-line)
7315 (backward-up-list 1)
7316 (skip-chars-forward " \t" (vhdl-point 'eol))
7317 (current-column))))
7318 (- ce-curcol cs-curcol -1))))
7320 (defun vhdl-lineup-comment (langelem)
7321 "Support old behavior for comment indentation. We look at
7322 vhdl-comment-only-line-offset to decide how to indent comment
7323 only-lines."
7324 (save-excursion
7325 (back-to-indentation)
7326 ;; at or to the right of comment-column
7327 (if (>= (current-column) comment-column)
7328 (vhdl-comment-indent)
7329 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7330 (if (not (bolp))
7331 ;; inside multi-line comment
7332 (if (looking-at "\\*")
7334 ;; otherwise
7335 (or (car-safe vhdl-comment-only-line-offset)
7336 vhdl-comment-only-line-offset))
7337 (or (cdr-safe vhdl-comment-only-line-offset)
7338 (car-safe vhdl-comment-only-line-offset)
7339 -1000 ;jam it against the left side
7340 )))))
7342 (defun vhdl-lineup-statement-cont (langelem)
7343 "Line up statement-cont after the assignment operator."
7344 (save-excursion
7345 (let* ((relpos (cdr langelem))
7346 (assignp (save-excursion
7347 (goto-char (vhdl-point 'boi))
7348 (and (re-search-forward "\\(<\\|:\\|=\\)="
7349 (vhdl-point 'eol) t)
7350 (- (point) (vhdl-point 'boi)))))
7351 (curcol (progn
7352 (goto-char relpos)
7353 (current-column)))
7354 foundp)
7355 (while (and (not foundp)
7356 (< (point) (vhdl-point 'eol)))
7357 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7358 (if (vhdl-in-literal)
7359 (forward-char)
7360 (if (= (preceding-char) ?\()
7361 ;; skip over any parenthesized expressions
7362 (goto-char (min (vhdl-point 'eol)
7363 (scan-lists (point) 1 1)))
7364 ;; found an assignment operator (not at eol)
7365 (setq foundp (not (looking-at "\\s-*$"))))))
7366 (if (not foundp)
7367 ;; there's no assignment operator on the line
7368 vhdl-basic-offset
7369 ;; calculate indentation column after assign and ws, unless
7370 ;; our line contains an assignment operator
7371 (if (not assignp)
7372 (progn
7373 (forward-char)
7374 (skip-chars-forward " \t")
7375 (setq assignp 0)))
7376 (- (current-column) assignp curcol))
7379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7380 ;; Progress reporting
7382 (defvar vhdl-progress-info nil
7383 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7385 (defun vhdl-update-progress-info (string pos)
7386 "Update progress information."
7387 (when (and vhdl-progress-info (not noninteractive)
7388 (< vhdl-progress-interval
7389 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7390 (let ((delta (- (aref vhdl-progress-info 1)
7391 (aref vhdl-progress-info 0))))
7392 (message "%s... (%2d%%)" string
7393 (if (= 0 delta)
7395 (floor (* 100.0 (- pos (aref vhdl-progress-info 0)))
7396 delta))))
7397 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7400 ;; Indentation commands
7402 (defun vhdl-electric-tab (&optional prefix-arg)
7403 "If preceding character is part of a word or a paren then hippie-expand,
7404 else if right of non whitespace on line then insert tab,
7405 else if last command was a tab or return then dedent one step or if a comment
7406 toggle between normal indent and inline comment indent,
7407 else indent `correctly'."
7408 (interactive "*P")
7409 (vhdl-prepare-search-2
7410 (cond
7411 ;; indent region if region is active
7412 ((and (not (featurep 'xemacs)) (use-region-p))
7413 (vhdl-indent-region (region-beginning) (region-end) nil))
7414 ;; expand word
7415 ((= (char-syntax (preceding-char)) ?w)
7416 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7417 (case-replace nil)
7418 (hippie-expand-only-buffers
7419 (or (and (boundp 'hippie-expand-only-buffers)
7420 hippie-expand-only-buffers)
7421 '(vhdl-mode))))
7422 (vhdl-expand-abbrev prefix-arg)))
7423 ;; expand parenthesis
7424 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7425 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7426 (case-replace nil))
7427 (vhdl-expand-paren prefix-arg)))
7428 ;; insert tab
7429 ((> (current-column) (current-indentation))
7430 (insert-tab))
7431 ;; toggle comment indent
7432 ((and (looking-at "--")
7433 (or (eq last-command 'vhdl-electric-tab)
7434 (eq last-command 'vhdl-electric-return)))
7435 (cond ((= (current-indentation) 0) ; no indent
7436 (indent-to 1)
7437 (indent-according-to-mode))
7438 ((< (current-indentation) comment-column) ; normal indent
7439 (indent-to comment-column)
7440 (indent-according-to-mode))
7441 (t ; inline comment indent
7442 (delete-region (line-beginning-position) (point)))))
7443 ;; dedent
7444 ((and (>= (current-indentation) vhdl-basic-offset)
7445 (or (eq last-command 'vhdl-electric-tab)
7446 (eq last-command 'vhdl-electric-return)))
7447 (backward-delete-char-untabify vhdl-basic-offset nil))
7448 ;; indent line
7449 (t (indent-according-to-mode)))
7450 (setq this-command 'vhdl-electric-tab)))
7452 (defun vhdl-electric-return ()
7453 "newline-and-indent or indent-new-comment-line if in comment and preceding
7454 character is a space."
7455 (interactive)
7456 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7457 (indent-new-comment-line)
7458 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7459 (not (vhdl-in-comment-p)))
7460 (vhdl-fix-case-word -1))
7461 (newline-and-indent)))
7463 (defun vhdl-indent-line ()
7464 "Indent the current line as VHDL code. Returns the amount of
7465 indentation change."
7466 (interactive)
7467 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7468 (pos (- (point-max) (point)))
7469 (is-comment nil)
7470 (indent
7471 (if syntax
7472 ;; indent syntax-based
7473 (if (and (eq (caar syntax) 'comment)
7474 (>= (vhdl-get-offset (car syntax)) comment-column))
7475 ;; special case: comments at or right of comment-column
7476 (vhdl-get-offset (car syntax))
7477 ;; align comments like following code line
7478 (when vhdl-indent-comment-like-next-code-line
7479 (save-excursion
7480 (while (eq (caar syntax) 'comment)
7481 (setq is-comment t)
7482 (beginning-of-line 2)
7483 (setq syntax (vhdl-get-syntactic-context)))))
7484 (when is-comment
7485 (push (cons 'comment nil) syntax))
7486 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7487 ;; indent like previous nonblank line
7488 (save-excursion (beginning-of-line)
7489 (re-search-backward "^[^\n]" nil t)
7490 (current-indentation))))
7491 (shift-amt (- indent (current-indentation))))
7492 (and vhdl-echo-syntactic-information-p
7493 (message "syntax: %s, indent= %d" syntax indent))
7494 (let ((has-formfeed
7495 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7496 (when (or (not (zerop shift-amt)) has-formfeed)
7497 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7498 (beginning-of-line)
7499 (when has-formfeed (insert "\f"))
7500 (indent-to indent)))
7501 (if (< (point) (vhdl-point 'boi))
7502 (back-to-indentation)
7503 ;; If initial point was within line's indentation, position after
7504 ;; the indentation. Else stay at same point in text.
7505 (when (> (- (point-max) pos) (point))
7506 (goto-char (- (point-max) pos))))
7507 (run-hooks 'vhdl-special-indent-hook)
7508 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7509 shift-amt))
7511 (defun vhdl-indent-region (beg end &optional column)
7512 "Indent region as VHDL code.
7513 Adds progress reporting to `indent-region'."
7514 (interactive "r\nP")
7515 (when vhdl-progress-interval
7516 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7517 (count-lines (point-min) end) 0)))
7518 (indent-region beg end column)
7519 (when vhdl-progress-interval (message "Indenting...done"))
7520 (setq vhdl-progress-info nil))
7522 (defun vhdl-indent-buffer ()
7523 "Indent whole buffer as VHDL code.
7524 Calls `indent-region' for whole buffer and adds progress reporting."
7525 (interactive)
7526 (vhdl-indent-region (point-min) (point-max)))
7528 (defun vhdl-indent-group ()
7529 "Indent group of lines between empty lines."
7530 (interactive)
7531 (let ((beg (save-excursion
7532 (if (re-search-backward vhdl-align-group-separate nil t)
7533 (point-marker)
7534 (point-min-marker))))
7535 (end (save-excursion
7536 (if (re-search-forward vhdl-align-group-separate nil t)
7537 (point-marker)
7538 (point-max-marker)))))
7539 (vhdl-indent-region beg end)))
7541 (defun vhdl-indent-sexp (&optional endpos)
7542 "Indent each line of the list starting just after point.
7543 If optional arg ENDPOS is given, indent each line, stopping when
7544 ENDPOS is encountered."
7545 (interactive)
7546 (save-excursion
7547 (let ((beg (point))
7548 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7549 (indent-region beg end nil))))
7551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7552 ;; Miscellaneous commands
7554 (defun vhdl-show-syntactic-information ()
7555 "Show syntactic information for current line."
7556 (interactive)
7557 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7558 (vhdl-keep-region-active))
7560 ;; Verification and regression functions:
7562 (defun vhdl-regress-line (&optional arg)
7563 "Check syntactic information for current line."
7564 (interactive "P")
7565 (let ((expected (save-excursion
7566 (end-of-line)
7567 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7568 (forward-char 4)
7569 (read (current-buffer)))))
7570 (actual (vhdl-get-syntactic-context))
7571 (expurgated))
7572 ;; remove the library unit symbols
7573 (mapc
7574 (function
7575 (lambda (elt)
7576 (if (memq (car elt) '(entity configuration context package
7577 package-body architecture))
7579 (setq expurgated (append expurgated (list elt))))))
7580 actual)
7581 (if (and (not arg) expected (listp expected))
7582 (if (not (equal expected expurgated))
7583 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7584 (save-excursion
7585 (beginning-of-line)
7586 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7587 (end-of-line)
7588 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7589 (delete-region (point) (line-end-position)))
7590 (insert " -- ")
7591 (insert (format "%s" expurgated))))))
7592 (vhdl-keep-region-active))
7595 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7596 ;;; Alignment, beautifying
7597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7599 (defconst vhdl-align-alist
7601 ;; after some keywords
7602 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7603 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7604 ;; before ':'
7605 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7606 ;; after direction specifications
7607 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7608 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7609 ;; before "==", ":=", "=>", and "<="
7610 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7611 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7612 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7613 ;; before some keywords
7614 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7615 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7616 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7617 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7618 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7619 ;; before "=>" since "when/else ... =>" can occur
7620 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7622 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7623 It is searched in order. If REGEXP is found anywhere in the first
7624 line of a region to be aligned, ALIGN-PATTERN will be used for that
7625 region. ALIGN-PATTERN must include the whitespace to be expanded or
7626 contracted. It may also provide regexps for the text surrounding the
7627 whitespace. SUBEXP specifies which sub-expression of
7628 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7631 ;; Align code
7633 (defvar vhdl-align-try-all-clauses t
7634 "If REGEXP is not found on the first line of the region that clause
7635 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7637 (defun vhdl-do-group (function &optional spacing)
7638 "Apply FUNCTION on group of lines between empty lines."
7639 (let
7640 ;; search for group beginning
7641 ((beg (save-excursion
7642 (if (re-search-backward vhdl-align-group-separate nil t)
7643 (progn (beginning-of-line 2) (back-to-indentation) (point))
7644 (point-min))))
7645 ;; search for group end
7646 (end (save-excursion
7647 (if (re-search-forward vhdl-align-group-separate nil t)
7648 (progn (beginning-of-line) (point))
7649 (point-max)))))
7650 ;; run FUNCTION
7651 (funcall function beg end spacing)))
7653 (defun vhdl-do-list (function &optional spacing)
7654 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7655 parentheses."
7656 (let (beg end)
7657 (save-excursion
7658 ;; search for beginning of balanced group of parentheses
7659 (setq beg (vhdl-re-search-backward "[()]" nil t))
7660 (while (looking-at ")")
7661 (forward-char) (backward-sexp)
7662 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7663 ;; search for end of balanced group of parentheses
7664 (when beg
7665 (forward-list)
7666 (setq end (point))
7667 (goto-char (1+ beg))
7668 (skip-chars-forward " \t\n\r\f")
7669 (setq beg (point))))
7670 ;; run FUNCTION
7671 (if beg
7672 (funcall function beg end spacing)
7673 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7675 (defun vhdl-do-same-indent (function &optional spacing)
7676 "Apply FUNCTION to block of lines with same indent."
7677 (let ((indent (current-indentation))
7678 beg end)
7679 ;; search for first line with same indent
7680 (save-excursion
7681 (while (and (not (bobp))
7682 (or (looking-at "^\\s-*\\(--.*\\)?$")
7683 (= (current-indentation) indent)))
7684 (unless (looking-at "^\\s-*$")
7685 (back-to-indentation) (setq beg (point)))
7686 (beginning-of-line -0)))
7687 ;; search for last line with same indent
7688 (save-excursion
7689 (while (and (not (eobp))
7690 (or (looking-at "^\\s-*\\(--.*\\)?$")
7691 (= (current-indentation) indent)))
7692 (if (looking-at "^\\s-*$")
7693 (beginning-of-line 2)
7694 (beginning-of-line 2)
7695 (setq end (point)))))
7696 ;; run FUNCTION
7697 (funcall function beg end spacing)))
7699 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7700 "Attempt to align a range of lines based on the content of the
7701 lines. The definition of `alignment-list' determines the matching
7702 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7703 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7704 indentation is done before aligning."
7705 (interactive "r\np")
7706 (setq alignment-list (or alignment-list vhdl-align-alist))
7707 (setq spacing (or spacing 1))
7708 (save-excursion
7709 (let (bol indent)
7710 (goto-char end)
7711 (setq end (point-marker))
7712 (goto-char begin)
7713 (setq bol (setq begin (progn (beginning-of-line) (point))))
7714 (when indent
7715 (indent-region bol end nil))))
7716 (let ((copy (copy-alist alignment-list)))
7717 (vhdl-prepare-search-2
7718 (while copy
7719 (save-excursion
7720 (goto-char begin)
7721 (let (element
7722 (eol (point-at-eol)))
7723 (setq element (nth 0 copy))
7724 (when (and (or (and (listp (car element))
7725 (memq major-mode (car element)))
7726 (eq major-mode (car element)))
7727 (or vhdl-align-try-all-clauses
7728 (re-search-forward (car (cdr element)) eol t)))
7729 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7730 (car (cdr (cdr (cdr element)))) spacing))
7731 (setq copy (cdr copy))))))))
7733 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7734 "Align a range of lines from BEGIN to END. The regular expression
7735 MATCH must match exactly one field: the whitespace to be
7736 contracted/expanded. The alignment column will equal the
7737 rightmost column of the widest whitespace block. SPACING is
7738 the amount of extra spaces to add to the calculated maximum required.
7739 SPACING defaults to 1 so that at least one space is inserted after
7740 the token in MATCH."
7741 (setq spacing (or spacing 1))
7742 (setq substr (or substr 1))
7743 (save-excursion
7744 (let (distance (max 0) (lines 0) bol eol width)
7745 ;; Determine the greatest whitespace distance to the alignment
7746 ;; character
7747 (goto-char begin)
7748 (setq eol (point-at-eol)
7749 bol (setq begin (progn (beginning-of-line) (point))))
7750 (while (< bol end)
7751 (save-excursion
7752 (when (and (vhdl-re-search-forward match eol t)
7753 (save-excursion
7754 (goto-char (match-beginning 0))
7755 (forward-char)
7756 (and (not (vhdl-in-literal))
7757 (not (vhdl-in-quote-p))
7758 (not (vhdl-in-extended-identifier-p))))
7759 (not (looking-at "\\s-*$")))
7760 (setq distance (- (match-beginning substr) bol))
7761 (when (> distance max)
7762 (setq max distance))))
7763 (forward-line)
7764 (setq bol (point)
7765 eol (point-at-eol))
7766 (setq lines (1+ lines)))
7767 ;; Now insert enough maxs to push each assignment operator to
7768 ;; the same column. We need to use 'lines' as a counter, since
7769 ;; the location of the mark may change
7770 (goto-char (setq bol begin))
7771 (setq eol (point-at-eol))
7772 (while (> lines 0)
7773 (when (and (vhdl-re-search-forward match eol t)
7774 (save-excursion
7775 (goto-char (match-beginning 0))
7776 (forward-char)
7777 (and (not (vhdl-in-literal))
7778 (not (vhdl-in-quote-p))
7779 (not (vhdl-in-extended-identifier-p))))
7780 (not (looking-at "\\s-*$"))
7781 (> (match-beginning 0) ; not if at boi
7782 (save-excursion (back-to-indentation) (point))))
7783 (setq width (- (match-end substr) (match-beginning substr)))
7784 (setq distance (- (match-beginning substr) bol))
7785 (goto-char (match-beginning substr))
7786 (delete-char width)
7787 (insert-char ? (+ (- max distance) spacing)))
7788 (beginning-of-line)
7789 (forward-line)
7790 (setq bol (point)
7791 eol (point-at-eol))
7792 (setq lines (1- lines))))))
7794 (defun vhdl-align-region-groups (beg end &optional spacing
7795 no-message no-comments)
7796 "Align region, treat groups of lines separately."
7797 (interactive "r\nP")
7798 (save-excursion
7799 (let (orig pos)
7800 (goto-char beg)
7801 (beginning-of-line)
7802 (setq orig (point-marker))
7803 (setq beg (point))
7804 (goto-char end)
7805 (setq end (point-marker))
7806 (untabify beg end)
7807 (unless no-message
7808 (when vhdl-progress-interval
7809 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7810 (count-lines (point-min) end) 0))))
7811 (when (nth 0 vhdl-beautify-options)
7812 (vhdl-fixup-whitespace-region beg end t))
7813 (goto-char beg)
7814 (if (not vhdl-align-groups)
7815 ;; align entire region
7816 (progn (vhdl-align-region-1 beg end spacing)
7817 (unless no-comments
7818 (vhdl-align-inline-comment-region-1 beg end)))
7819 ;; align groups
7820 (while (and (< beg end)
7821 (re-search-forward vhdl-align-group-separate end t))
7822 (setq pos (point-marker))
7823 (vhdl-align-region-1 beg pos spacing)
7824 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7825 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7826 (setq beg (1+ pos))
7827 (goto-char beg))
7828 ;; align last group
7829 (when (< beg end)
7830 (vhdl-align-region-1 beg end spacing)
7831 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7832 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7833 (when vhdl-indent-tabs-mode
7834 (tabify orig end))
7835 (unless no-message
7836 (when vhdl-progress-interval (message "Aligning...done"))
7837 (setq vhdl-progress-info nil)))))
7839 (defun vhdl-align-region (beg end &optional spacing)
7840 "Align region, treat blocks with same indent and argument lists separately."
7841 (interactive "r\nP")
7842 (if (not vhdl-align-same-indent)
7843 ;; align entire region
7844 (vhdl-align-region-groups beg end spacing)
7845 ;; align blocks with same indent and argument lists
7846 (save-excursion
7847 (let ((cur-beg beg)
7848 indent cur-end)
7849 (when vhdl-progress-interval
7850 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7851 (count-lines (point-min) end) 0)))
7852 (goto-char end)
7853 (setq end (point-marker))
7854 (goto-char cur-beg)
7855 (while (< (point) end)
7856 ;; is argument list opening?
7857 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7858 (point) (vhdl-point 'eol)))))
7859 ;; determine region for argument list
7860 (progn (goto-char cur-beg)
7861 (forward-sexp)
7862 (setq cur-end (point))
7863 (beginning-of-line 2))
7864 ;; determine region with same indent
7865 (setq indent (current-indentation))
7866 (setq cur-beg (point))
7867 (setq cur-end (vhdl-point 'bonl))
7868 (beginning-of-line 2)
7869 (while (and (< (point) end)
7870 (or (looking-at "^\\s-*\\(--.*\\)?$")
7871 (= (current-indentation) indent))
7872 (<= (save-excursion
7873 (nth 0 (parse-partial-sexp
7874 (point) (vhdl-point 'eol)))) 0))
7875 (unless (looking-at "^\\s-*$")
7876 (setq cur-end (vhdl-point 'bonl)))
7877 (beginning-of-line 2)))
7878 ;; align region
7879 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7880 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7881 (when vhdl-progress-interval (message "Aligning...done"))
7882 (setq vhdl-progress-info nil)))))
7884 (defun vhdl-align-group (&optional spacing)
7885 "Align group of lines between empty lines."
7886 (interactive)
7887 (vhdl-do-group 'vhdl-align-region spacing))
7889 (defun vhdl-align-list (&optional spacing)
7890 "Align the lines of a list surrounded by a balanced group of parentheses."
7891 (interactive)
7892 (vhdl-do-list 'vhdl-align-region-groups spacing))
7894 (defun vhdl-align-same-indent (&optional spacing)
7895 "Align block of lines with same indent."
7896 (interactive)
7897 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7899 (defun vhdl-align-declarations (&optional spacing)
7900 "Align the lines within the declarative part of a design unit."
7901 (interactive)
7902 (let (beg end)
7903 (vhdl-prepare-search-2
7904 (save-excursion
7905 ;; search for declarative part
7906 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|context\\|end\\|entity\\|package\\)\\>" nil t)
7907 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7908 (setq beg (point))
7909 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7910 (setq end (point)))))
7911 (if beg
7912 (vhdl-align-region-groups beg end spacing)
7913 (error "ERROR: Not within the declarative part of a design unit"))))
7915 (defun vhdl-align-buffer ()
7916 "Align buffer."
7917 (interactive)
7918 (vhdl-align-region (point-min) (point-max)))
7920 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7921 ;; Align inline comments
7923 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7924 "Align inline comments in region."
7925 (save-excursion
7926 (let ((start-max comment-column)
7927 (length-max 0)
7928 comment-list start-list tmp-list start length
7929 cur-start prev-start no-code)
7930 (setq spacing (or spacing 2))
7931 (vhdl-prepare-search-2
7932 (goto-char beg)
7933 ;; search for comment start positions and lengths
7934 (while (< (point) end)
7935 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7936 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7937 (not (save-excursion (goto-char (match-beginning 2))
7938 (vhdl-in-literal))))
7939 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7940 (setq length (- (match-end 2) (match-beginning 2)))
7941 (setq start-max (max start start-max))
7942 (setq length-max (max length length-max))
7943 (push (cons start length) comment-list))
7944 (beginning-of-line 2))
7945 (setq comment-list
7946 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7947 ;; reduce start positions
7948 (setq start-list (list (caar comment-list)))
7949 (setq comment-list (cdr comment-list))
7950 (while comment-list
7951 (unless (or (= (caar comment-list) (car start-list))
7952 (<= (+ (car start-list) (cdar comment-list))
7953 end-comment-column))
7954 (push (caar comment-list) start-list))
7955 (setq comment-list (cdr comment-list)))
7956 ;; align lines as nicely as possible
7957 (goto-char beg)
7958 (while (< (point) end)
7959 (setq cur-start nil)
7960 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7961 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7962 (not (save-excursion
7963 (goto-char (match-beginning 3))
7964 (vhdl-in-literal))))
7965 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7966 (>= (- (match-end 2) (match-beginning 2))
7967 comment-column))))
7968 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7969 (setq length (- (match-end 3) (match-beginning 3)))
7970 (setq no-code (= (match-beginning 1) (match-end 1)))
7971 ;; insert minimum whitespace
7972 (goto-char (match-end 2))
7973 (delete-region (match-beginning 2) (match-end 2))
7974 (insert-char ?\ spacing)
7975 (setq tmp-list start-list)
7976 ;; insert additional whitespace to align
7977 (setq cur-start
7978 (cond
7979 ;; align comment-only line to inline comment of previous line
7980 ((and no-code prev-start
7981 (<= length (- end-comment-column prev-start)))
7982 prev-start)
7983 ;; align all comments at `start-max' if this is possible
7984 ((<= (+ start-max length-max) end-comment-column)
7985 start-max)
7986 ;; align at `comment-column' if possible
7987 ((and (<= start comment-column)
7988 (<= length (- end-comment-column comment-column)))
7989 comment-column)
7990 ;; align at left-most possible start position otherwise
7992 (while (and tmp-list (< (car tmp-list) start))
7993 (setq tmp-list (cdr tmp-list)))
7994 (car tmp-list))))
7995 (indent-to cur-start))
7996 (setq prev-start cur-start)
7997 (beginning-of-line 2))))))
7999 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
8000 "Align inline comments within a region. Groups of code lines separated by
8001 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8002 (interactive "r\nP")
8003 (save-excursion
8004 (let (orig pos)
8005 (goto-char beg)
8006 (beginning-of-line)
8007 (setq orig (point-marker))
8008 (setq beg (point))
8009 (goto-char end)
8010 (setq end (point-marker))
8011 (untabify beg end)
8012 (unless no-message (message "Aligning inline comments..."))
8013 (goto-char beg)
8014 (if (not vhdl-align-groups)
8015 ;; align entire region
8016 (vhdl-align-inline-comment-region-1 beg end spacing)
8017 ;; align groups
8018 (while (and (< beg end)
8019 (re-search-forward vhdl-align-group-separate end t))
8020 (setq pos (point-marker))
8021 (vhdl-align-inline-comment-region-1 beg pos spacing)
8022 (setq beg (1+ pos))
8023 (goto-char beg))
8024 ;; align last group
8025 (when (< beg end)
8026 (vhdl-align-inline-comment-region-1 beg end spacing)))
8027 (when vhdl-indent-tabs-mode
8028 (tabify orig end))
8029 (unless no-message (message "Aligning inline comments...done")))))
8031 (defun vhdl-align-inline-comment-group (&optional spacing)
8032 "Align inline comments within a group of lines between empty lines."
8033 (interactive)
8034 (save-excursion
8035 (let ((start (point))
8036 beg end)
8037 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
8038 (point-marker) (point-max)))
8039 (goto-char start)
8040 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
8041 (point) (point-min)))
8042 (untabify beg end)
8043 (message "Aligning inline comments...")
8044 (vhdl-align-inline-comment-region-1 beg end)
8045 (when vhdl-indent-tabs-mode
8046 (tabify beg end))
8047 (message "Aligning inline comments...done"))))
8049 (defun vhdl-align-inline-comment-buffer ()
8050 "Align inline comments within buffer. Groups of code lines separated by
8051 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8052 (interactive)
8053 (vhdl-align-inline-comment-region (point-min) (point-max)))
8055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8056 ;; Fixup whitespace
8058 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
8059 "Fixup whitespace in region. Surround operator symbols by one space,
8060 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8061 end of line, do nothing in comments and strings."
8062 (interactive "r")
8063 (unless no-message (message "Fixing up whitespace..."))
8064 (save-excursion
8065 (goto-char end)
8066 (setq end (point-marker))
8067 ;; have no space before and one space after `,' and ';'
8068 (goto-char beg)
8069 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
8070 (if (match-string 1)
8071 (goto-char (match-end 1))
8072 (replace-match "\\3 " nil nil nil 2)))
8073 ;; have no space after `('
8074 (goto-char beg)
8075 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
8076 (if (match-string 1)
8077 (goto-char (match-end 1))
8078 (replace-match "\\2")))
8079 ;; have no space before `)'
8080 (goto-char beg)
8081 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
8082 (if (match-string 1)
8083 (goto-char (match-end 1))
8084 (replace-match "\\2")))
8085 ;; surround operator symbols by one space
8086 (goto-char beg)
8087 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
8088 (if (or (match-string 1)
8089 (<= (match-beginning 0) ; not if at boi
8090 (save-excursion (back-to-indentation) (point))))
8091 (goto-char (match-end 0))
8092 (replace-match "\\3 \\4 \\5")
8093 (goto-char (match-end 2))))
8094 ;; eliminate multiple spaces and spaces at end of line
8095 (goto-char beg)
8096 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
8097 (and (looking-at "--.*") (re-search-forward "--.*" end t))
8098 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
8099 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
8100 (progn (replace-match "" nil nil) t))
8101 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
8102 (progn (replace-match ";" nil nil) t))
8103 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
8104 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
8105 (progn (replace-match " " nil nil) t))
8106 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
8107 (progn (replace-match " " nil nil) t))
8108 (and (looking-at "-") (re-search-forward "-" end t))
8109 (re-search-forward "[^ \t\"-]+" end t))))
8110 (unless no-message (message "Fixing up whitespace...done")))
8112 (defun vhdl-fixup-whitespace-buffer ()
8113 "Fixup whitespace in buffer. Surround operator symbols by one space,
8114 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8115 end of line, do nothing in comments."
8116 (interactive)
8117 (vhdl-fixup-whitespace-region (point-min) (point-max)))
8119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8120 ;; Case fixing
8122 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
8123 "Convert all words matching WORD-REGEXP in region to lower or upper case,
8124 depending on parameter UPPER-CASE."
8125 (let ((case-replace nil)
8126 (last-update 0))
8127 (vhdl-prepare-search-2
8128 (save-excursion
8129 (goto-char end)
8130 (setq end (point-marker))
8131 (goto-char beg)
8132 (while (re-search-forward word-regexp end t)
8133 (or (vhdl-in-literal)
8134 (if upper-case
8135 (upcase-word -1)
8136 (downcase-word -1)))
8137 (when (and count vhdl-progress-interval (not noninteractive)
8138 (< vhdl-progress-interval
8139 (- (nth 1 (current-time)) last-update)))
8140 (message "Fixing case... (%2d%s)"
8141 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
8142 "%")
8143 (setq last-update (nth 1 (current-time)))))
8144 (goto-char end)))))
8146 (defun vhdl-fix-case-region (beg end &optional arg)
8147 "Convert all VHDL words in region to lower or upper case, depending on
8148 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8149 (interactive "r\nP")
8150 (vhdl-fix-case-region-1
8151 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
8152 (vhdl-fix-case-region-1
8153 beg end vhdl-upper-case-types vhdl-types-regexp 1)
8154 (vhdl-fix-case-region-1
8155 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
8156 (vhdl-fix-case-region-1
8157 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
8158 (vhdl-fix-case-region-1
8159 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
8160 (when vhdl-progress-interval (message "Fixing case...done")))
8162 (defun vhdl-fix-case-buffer ()
8163 "Convert all VHDL words in buffer to lower or upper case, depending on
8164 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8165 (interactive)
8166 (vhdl-fix-case-region (point-min) (point-max)))
8168 (defun vhdl-fix-case-word (&optional arg)
8169 "Convert word after cursor to upper case if necessary."
8170 (interactive "p")
8171 (save-excursion
8172 (when arg (backward-word 1))
8173 (vhdl-prepare-search-1
8174 (when (and vhdl-upper-case-keywords
8175 (looking-at vhdl-keywords-regexp))
8176 (upcase-word 1))
8177 (when (and vhdl-upper-case-types
8178 (looking-at vhdl-types-regexp))
8179 (upcase-word 1))
8180 (when (and vhdl-upper-case-attributes
8181 (looking-at vhdl-attributes-regexp))
8182 (upcase-word 1))
8183 (when (and vhdl-upper-case-enum-values
8184 (looking-at vhdl-enum-values-regexp))
8185 (upcase-word 1))
8186 (when (and vhdl-upper-case-constants
8187 (looking-at vhdl-constants-regexp))
8188 (upcase-word 1)))))
8190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8191 ;; Fix statements
8192 ;; - force each statement to be on a separate line except when on same line
8193 ;; with 'end' keyword
8195 (defun vhdl-fix-statement-region (beg end &optional arg)
8196 "Force statements in region on separate line except when on same line
8197 with `end' keyword (necessary for correct indentation).
8198 Currently supported keywords: `begin', `if'."
8199 (interactive "r\nP")
8200 (vhdl-prepare-search-2
8201 (let (point)
8202 (save-excursion
8203 (goto-char end)
8204 (setq end (point-marker))
8205 (goto-char beg)
8206 ;; `begin' keyword
8207 (while (re-search-forward
8208 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
8209 (goto-char (match-end 0))
8210 (setq point (point-marker))
8211 (when (and (match-string 1)
8212 (or (not (match-string 2))
8213 (save-excursion (goto-char (match-end 2))
8214 (vhdl-in-literal)))
8215 (not (save-excursion (goto-char (match-beginning 1))
8216 (vhdl-in-literal))))
8217 (goto-char (match-beginning 1))
8218 (insert "\n")
8219 (indent-according-to-mode))
8220 (goto-char point))
8221 (goto-char beg)
8222 ;; `for', `if' keywords
8223 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
8224 (goto-char (match-end 1))
8225 (setq point (point-marker))
8226 ;; exception: in literal or preceded by `end', `wait' or label
8227 (when (and (not (save-excursion (goto-char (match-beginning 1))
8228 (vhdl-in-literal)))
8229 (save-excursion
8230 (beginning-of-line 1)
8231 (save-match-data
8232 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8233 (match-beginning 1) t)
8234 (not (string-match
8235 "\\(\\<end\\>\\|\\<wait .*\\|\\w+\\s-*:\\)\\s-*$"
8236 (match-string 1)))))))
8237 (goto-char (match-beginning 1))
8238 (insert "\n")
8239 (indent-according-to-mode))
8240 (goto-char point))))))
8242 (defun vhdl-fix-statement-buffer ()
8243 "Force statements in buffer on separate line except when on same line
8244 with `end' keyword (necessary for correct indentation)."
8245 (interactive)
8246 (vhdl-fix-statement-region (point-min) (point-max)))
8248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8249 ;; Trailing spaces
8251 (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
8252 "Remove trailing spaces in region."
8253 (interactive "r\nP")
8254 (save-excursion
8255 (goto-char end)
8256 (setq end (point-marker))
8257 (goto-char beg)
8258 (while (re-search-forward "[ \t]+$" end t)
8259 (unless (vhdl-in-literal)
8260 (replace-match "" nil nil)))))
8262 (defun vhdl-remove-trailing-spaces ()
8263 "Remove trailing spaces in buffer."
8264 (interactive)
8265 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8268 ;; Beautify
8270 (defun vhdl-beautify-region (beg end)
8271 "Beautify region by applying indentation, whitespace fixup, alignment, and
8272 case fixing to a region. Calls functions `vhdl-indent-buffer',
8273 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8274 `vhdl-fix-case-buffer'."
8275 (interactive "r")
8276 (setq end (save-excursion (goto-char end) (point-marker)))
8277 (save-excursion ; remove DOS EOL characters in UNIX file
8278 (goto-char beg)
8279 (while (search-forward "\r" nil t)
8280 (replace-match "" nil t)))
8281 (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
8282 (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
8283 (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
8284 (when (nth 3 vhdl-beautify-options)
8285 (let ((vhdl-align-groups t)) (vhdl-align-region beg end)))
8286 (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
8287 (when (nth 0 vhdl-beautify-options)
8288 (vhdl-remove-trailing-spaces-region beg end)
8289 (if vhdl-indent-tabs-mode (tabify beg end) (untabify beg end))))
8291 (defun vhdl-beautify-buffer ()
8292 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8293 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8294 buffer."
8295 (interactive)
8296 (vhdl-beautify-region (point-min) (point-max))
8297 (when noninteractive (save-buffer)))
8299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8300 ;; Code filling
8302 (defun vhdl-fill-region (beg end &optional arg)
8303 "Fill lines for a region of code."
8304 (interactive "r\np")
8305 (save-excursion
8306 (goto-char beg)
8307 (let ((margin (if arg (current-indentation) (current-column))))
8308 (goto-char end)
8309 (setq end (point-marker))
8310 ;; remove inline comments, newlines and whitespace
8311 (vhdl-comment-kill-region beg end)
8312 (vhdl-comment-kill-inline-region beg end)
8313 (subst-char-in-region beg (1- end) ?\n ?\ )
8314 (vhdl-fixup-whitespace-region beg end)
8315 ;; wrap and end-comment-column
8316 (goto-char beg)
8317 (while (re-search-forward "\\s-" end t)
8318 (when(> (current-column) vhdl-end-comment-column)
8319 (backward-char)
8320 (when (re-search-backward "\\s-" beg t)
8321 (replace-match "\n")
8322 (indent-to margin)))))))
8324 (defun vhdl-fill-group ()
8325 "Fill group of lines between empty lines."
8326 (interactive)
8327 (vhdl-do-group 'vhdl-fill-region))
8329 (defun vhdl-fill-list ()
8330 "Fill the lines of a list surrounded by a balanced group of parentheses."
8331 (interactive)
8332 (vhdl-do-list 'vhdl-fill-region))
8334 (defun vhdl-fill-same-indent ()
8335 "Fill the lines of block of lines with same indent."
8336 (interactive)
8337 (vhdl-do-same-indent 'vhdl-fill-region))
8340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8341 ;;; Code updating/fixing
8342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8345 ;; Sensitivity list update
8347 ;; Strategy:
8348 ;; - no sensitivity list is generated for processes with wait statements
8349 ;; - otherwise, do the following:
8350 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8351 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8352 ;; manually entered global signals)
8353 ;; 3. signals from 1. and 2. form the list of visible signals
8354 ;; 4. search for if/elsif conditions containing an event (sequential code)
8355 ;; 5. scan for strings that are within syntactical regions where signals are
8356 ;; read but not within sequential code, and that correspond to visible
8357 ;; signals
8358 ;; 6. replace sensitivity list by list of signals from 5.
8360 (defun vhdl-update-sensitivity-list-process ()
8361 "Update sensitivity list of current process."
8362 (interactive)
8363 (save-excursion
8364 (vhdl-prepare-search-2
8365 (end-of-line)
8366 ;; look whether in process
8367 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8368 (equal (upcase (match-string 2)) "PROCESS")
8369 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8370 (error "ERROR: Not within a process")
8371 (message "Updating sensitivity list...")
8372 (vhdl-update-sensitivity-list)
8373 (message "Updating sensitivity list...done")))))
8375 (defun vhdl-update-sensitivity-list-buffer ()
8376 "Update sensitivity list of all processes in current buffer."
8377 (interactive)
8378 (save-excursion
8379 (vhdl-prepare-search-2
8380 (goto-char (point-min))
8381 (message "Updating sensitivity lists...")
8382 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8383 (goto-char (match-beginning 0))
8384 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8385 (message "Updating sensitivity lists...done")))
8386 (when noninteractive (save-buffer)))
8388 (defun vhdl-update-sensitivity-list ()
8389 "Update sensitivity list."
8390 (let ((proc-beg (point))
8391 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8392 (proc-mid (vhdl-re-search-backward
8393 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8394 seq-region-list)
8395 (cond
8396 ;; error if 'begin' keyword missing
8397 ((not (match-string 2))
8398 (error "ERROR: No 'begin' keyword found"))
8399 ;; search for wait statement (no sensitivity list allowed)
8400 ((progn (goto-char proc-mid)
8401 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8402 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8403 ;; combinational process (update sensitivity list)
8405 (let
8406 ;; scan for visible signals
8407 ((visible-list (vhdl-get-visible-signals))
8408 ;; define syntactic regions where signals are read
8409 (scan-regions-list
8410 '(;; right-hand side of signal/variable assignment
8411 ;; (special case: "<=" is relational operator in a condition)
8412 ((vhdl-re-search-forward "[<:]=" proc-end t)
8413 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8414 ;; if condition
8415 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
8416 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8417 ;; elsif condition
8418 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
8419 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8420 ;; while loop condition
8421 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
8422 (vhdl-re-search-forward "\\<loop\\>" proc-end t))
8423 ;; exit/next condition
8424 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8425 (vhdl-re-search-forward ";" proc-end t))
8426 ;; assert condition
8427 ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
8428 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8429 ;; case expression
8430 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
8431 (vhdl-re-search-forward "\\<is\\>" proc-end t))
8432 ;; parameter list of procedure call, array index
8433 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8434 (1- (point)))
8435 (progn (backward-char) (forward-sexp)
8436 (while (looking-at "(") (forward-sexp)) (point)))))
8437 name field read-list sens-list signal-list tmp-list
8438 sens-beg sens-end beg end margin)
8439 ;; scan for signals in old sensitivity list
8440 (goto-char proc-beg)
8441 (vhdl-re-search-forward "\\<process\\>" proc-mid t)
8442 (if (not (looking-at "[ \t\n\r\f]*("))
8443 (setq sens-beg (point))
8444 (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8445 (goto-char (match-end 1))
8446 (forward-sexp)
8447 (setq sens-end (1- (point)))
8448 (goto-char sens-beg)
8449 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
8450 (setq sens-list
8451 (cons (downcase (match-string 0)) sens-list))
8452 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
8453 (setq signal-list (append visible-list sens-list))
8454 ;; search for sequential parts
8455 (goto-char proc-mid)
8456 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8457 (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
8458 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8459 (goto-char end)
8460 (backward-word-strictly 1)
8461 (vhdl-forward-sexp)
8462 (push (cons end (point)) seq-region-list)
8463 (beginning-of-line)))
8464 ;; scan for signals read in process
8465 (while scan-regions-list
8466 (goto-char proc-mid)
8467 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8468 (setq end (eval (nth 1 (car scan-regions-list)))))
8469 (goto-char beg)
8470 (unless (or (vhdl-in-literal)
8471 (and seq-region-list
8472 (let ((tmp-list seq-region-list))
8473 (while (and tmp-list
8474 (< (point) (caar tmp-list)))
8475 (setq tmp-list (cdr tmp-list)))
8476 (and tmp-list (< (point) (cdar tmp-list))))))
8477 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8478 (setq name (match-string 1))
8479 ;; get array index range
8480 (when vhdl-array-index-record-field-in-sensitivity-list
8481 (setq field (match-string 2))
8482 ;; not use if it includes a variable name
8483 (save-match-data
8484 (setq tmp-list visible-list)
8485 (while (and field tmp-list)
8486 (when (string-match
8487 (concat "\\<" (car tmp-list) "\\>") field)
8488 (setq field nil))
8489 (setq tmp-list (cdr tmp-list)))))
8490 (when (and (not (match-string 6)) ; not when formal parameter
8491 (not (and (match-string 5) ; not event attribute
8492 (not (member (downcase (match-string 5))
8493 '("event" "last_event" "transaction")))))
8494 (member (downcase name) signal-list))
8495 ;; not add if name or name+field already exists
8496 (unless
8497 (or (member-ignore-case name read-list)
8498 (member-ignore-case (concat name field) read-list))
8499 (push (concat name field) read-list))
8500 (setq tmp-list read-list)
8501 ;; remove existing name+field if name is added
8502 (save-match-data
8503 (while tmp-list
8504 (when (string-match (concat "^" name field "[(.]")
8505 (car tmp-list))
8506 (setq read-list (delete (car tmp-list) read-list)))
8507 (setq tmp-list (cdr tmp-list)))))
8508 (goto-char (match-end 1)))))
8509 (setq scan-regions-list (cdr scan-regions-list)))
8510 ;; update sensitivity list
8511 (goto-char sens-beg)
8512 (if sens-end
8513 (delete-region sens-beg sens-end)
8514 (when read-list
8515 (insert " ()") (backward-char)))
8516 (setq read-list (sort read-list 'string<))
8517 (when read-list
8518 (setq margin (current-column))
8519 (insert (car read-list))
8520 (setq read-list (cdr read-list))
8521 (while read-list
8522 (insert ",")
8523 (if (<= (+ (current-column) (length (car read-list)) 2)
8524 end-comment-column)
8525 (insert " ")
8526 (insert "\n") (indent-to margin))
8527 (insert (car read-list))
8528 (setq read-list (cdr read-list)))))))))
8530 (defun vhdl-get-visible-signals ()
8531 "Get all signals visible in the current block."
8532 (let (beg end signal-list entity-name file-name)
8533 (vhdl-prepare-search-2
8534 ;; get entity name
8535 (save-excursion
8536 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8537 (not (equal "END" (upcase (match-string 1))))
8538 (setq entity-name (match-string 2)))
8539 (error "ERROR: Not within an architecture")))
8540 ;; search for signals declared in entity port clause
8541 (save-excursion
8542 (goto-char (point-min))
8543 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8544 (setq file-name
8545 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8546 "." (file-name-extension (buffer-file-name)))))
8547 (vhdl-visit-file
8548 file-name t
8549 (vhdl-prepare-search-2
8550 (goto-char (point-min))
8551 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8552 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8553 (when (setq beg (vhdl-re-search-forward
8554 "\\<port[ \t\n\r\f]*("
8555 (save-excursion
8556 (re-search-forward "^end\\>" nil t)) t))
8557 (setq end (save-excursion
8558 (backward-char) (forward-sexp) (point)))
8559 (vhdl-forward-syntactic-ws)
8560 (while (< (point) end)
8561 (when (looking-at "signal[ \t\n\r\f]+")
8562 (goto-char (match-end 0)))
8563 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8564 (setq signal-list
8565 (cons (downcase (match-string 1)) signal-list))
8566 (goto-char (match-end 0))
8567 (vhdl-forward-syntactic-ws))
8568 (re-search-forward ";" end 1)
8569 (vhdl-forward-syntactic-ws)))))))
8570 ;; search for signals declared in architecture declarative part
8571 (save-excursion
8572 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8573 (not (equal "END" (upcase (match-string 1))))
8574 (setq end (re-search-forward "^begin\\>" nil t))))
8575 (error "ERROR: No architecture declarative part found")
8576 ;; scan for all declared signal and alias names
8577 (goto-char beg)
8578 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8579 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8580 (if (match-string 2)
8581 ;; scan signal name
8582 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8583 (setq signal-list
8584 (cons (downcase (match-string 1)) signal-list))
8585 (goto-char (match-end 0)))
8586 ;; scan alias name, check is alias of (declared) signal
8587 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8588 (member (downcase (match-string 2)) signal-list))
8589 (setq signal-list
8590 (cons (downcase (match-string 1)) signal-list))
8591 (goto-char (match-end 0))))
8592 (setq beg (point))))))
8593 ;; search for signals declared in surrounding block declarative parts
8594 (save-excursion
8595 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*\\(block\\|\\(for\\|if\\).*\\<generate\\>\\)\\|\\(end\\)\\s-+block\\)\\>" nil t))
8596 (match-string 4))
8597 (goto-char (match-end 4))
8598 (vhdl-backward-sexp)
8599 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*\\(block\\|generate\\)\\>" nil t))
8600 beg)
8601 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8602 ;; scan for all declared signal names
8603 (goto-char beg)
8604 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8605 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8606 (if (match-string 2)
8607 ;; scan signal name
8608 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8609 (setq signal-list
8610 (cons (downcase (match-string 1)) signal-list))
8611 (goto-char (match-end 0)))
8612 ;; scan alias name, check is alias of (declared) signal
8613 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8614 (member (downcase (match-string 2)) signal-list))
8615 (setq signal-list
8616 (cons (downcase (match-string 1)) signal-list))
8617 (goto-char (match-end 0))))))
8618 (goto-char beg)))
8619 signal-list)))
8621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8622 ;; Generic/port clause fixing
8624 (defun vhdl-fix-clause-buffer ()
8625 "Fix all generic/port clauses in current buffer."
8626 (interactive)
8627 (save-excursion
8628 (vhdl-prepare-search-2
8629 (goto-char (point-min))
8630 (message "Fixing generic/port clauses...")
8631 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8632 (goto-char (match-end 0))
8633 (condition-case nil (vhdl-fix-clause) (error "")))
8634 (message "Fixing generic/port clauses...done"))))
8636 (defun vhdl-fix-clause ()
8637 "Fix closing parenthesis within generic/port clause."
8638 (interactive)
8639 (save-excursion
8640 (vhdl-prepare-search-2
8641 (let ((pos (point))
8642 beg end)
8643 (end-of-line)
8644 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8645 (error "ERROR: Not within a generic/port clause")
8646 ;; search for end of clause
8647 (goto-char (match-end 0))
8648 (setq beg (1- (point)))
8649 (vhdl-forward-syntactic-ws)
8650 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8651 (goto-char (1- (match-end 0)))
8652 (setq end (point-marker))
8653 (forward-char)
8654 (vhdl-forward-syntactic-ws))
8655 (goto-char end)
8656 (when (> pos (point-at-eol))
8657 (error "ERROR: Not within a generic/port clause"))
8658 ;; delete closing parenthesis on separate line (not supported style)
8659 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8660 (vhdl-line-kill)
8661 (vhdl-backward-syntactic-ws)
8662 (setq end (point-marker))
8663 (insert ";"))
8664 ;; delete superfluous parentheses
8665 (while (progn (goto-char beg)
8666 (condition-case () (forward-sexp)
8667 (error (goto-char (point-max))))
8668 (< (point) end))
8669 (delete-char -1))
8670 ;; add closing parenthesis
8671 (when (> (point) end)
8672 (goto-char end)
8673 (insert ")")))))))
8676 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8677 ;;; Electrification
8678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8680 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8681 "Syntax of prompt inserted by template generators.")
8683 (defvar vhdl-template-invoked-by-hook nil
8684 "Indicates whether a template has been invoked by a hook or by key or menu.
8685 Used for undoing after template abortion.")
8687 ;; correct different behavior of function `unread-command-events' in XEmacs
8688 (defun vhdl-character-to-event (arg))
8689 (defalias 'vhdl-character-to-event
8690 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8692 (defun vhdl-work-library ()
8693 "Return the working library name of the current project or \"work\" if no
8694 project is defined."
8695 (vhdl-resolve-env-variable
8696 (or (nth 6 (vhdl-aget vhdl-project-alist vhdl-project))
8697 vhdl-default-library)))
8699 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8700 ;; Enabling/disabling
8702 (define-minor-mode vhdl-electric-mode
8703 "Toggle VHDL electric mode.
8704 With a prefix argument ARG, enable the mode if ARG is positive,
8705 and disable it otherwise. If called from Lisp, enable it if ARG
8706 is omitted or nil."
8707 :global t :group 'vhdl-mode)
8709 (define-minor-mode vhdl-stutter-mode
8710 "Toggle VHDL stuttering mode.
8711 With a prefix argument ARG, enable the mode if ARG is positive,
8712 and disable it otherwise. If called from Lisp, enable it if ARG
8713 is omitted or nil."
8714 :global t :group 'vhdl-mode)
8716 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8717 ;; Stuttering
8719 (defun vhdl-electric-dash (count)
8720 "-- starts a comment, --- draws a horizontal line,
8721 ---- starts a display comment."
8722 (interactive "p")
8723 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8724 (cond
8725 ((and abbrev-start-location (= abbrev-start-location (point)))
8726 (setq abbrev-start-location nil)
8727 (goto-char last-abbrev-location)
8728 (beginning-of-line nil)
8729 (vhdl-comment-display))
8730 ((/= (preceding-char) ?-) ; standard dash (minus)
8731 (self-insert-command count))
8732 (t (self-insert-command count)
8733 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8734 (let ((next-input (read-char)))
8735 (if (= next-input ?-) ; triple dash
8736 (progn
8737 (vhdl-comment-display-line)
8738 (message
8739 "Enter '-' for display comment, else continue coding")
8740 (let ((next-input (read-char)))
8741 (if (= next-input ?-) ; four dashes
8742 (vhdl-comment-display t)
8743 (push (vhdl-character-to-event next-input)
8744 ; pushback the char
8745 unread-command-events))))
8746 (push (vhdl-character-to-event next-input) ; pushback the char
8747 unread-command-events)
8748 (vhdl-comment-insert)))))
8749 (self-insert-command count)))
8751 (defun vhdl-electric-open-bracket (count) "`[' --> `(', `([' --> `['"
8752 (interactive "p")
8753 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8754 (if (= (preceding-char) ?\()
8755 (progn (delete-char -1) (insert-char ?\[ 1))
8756 (insert-char ?\( 1))
8757 (self-insert-command count)))
8759 (defun vhdl-electric-close-bracket (count) "`]' --> `)', `)]' --> `]'"
8760 (interactive "p")
8761 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8762 (progn
8763 (if (= (preceding-char) ?\))
8764 (progn (delete-char -1) (insert-char ?\] 1))
8765 (insert-char ?\) 1))
8766 (blink-matching-open))
8767 (self-insert-command count)))
8769 (defun vhdl-electric-quote (count) "\\='\\=' --> \""
8770 (interactive "p")
8771 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8772 (if (= (preceding-char) vhdl-last-input-event)
8773 (progn (delete-char -1) (insert-char ?\" 1))
8774 (insert-char ?\' 1))
8775 (self-insert-command count)))
8777 (defun vhdl-electric-semicolon (count) "`;;' --> ` : ', `: ;' --> ` := '"
8778 (interactive "p")
8779 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8780 (cond ((= (preceding-char) vhdl-last-input-event)
8781 (progn (delete-char -1)
8782 (unless (eq (preceding-char) ? ) (insert " "))
8783 (insert ": ")
8784 (setq this-command 'vhdl-electric-colon)))
8785 ((and
8786 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8787 (progn (delete-char -1) (insert "= ")))
8788 (t (insert-char ?\; 1)))
8789 (self-insert-command count)))
8791 (defun vhdl-electric-comma (count) "`,,' --> ` <= '"
8792 (interactive "p")
8793 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8794 (cond ((= (preceding-char) vhdl-last-input-event)
8795 (progn (delete-char -1)
8796 (unless (eq (preceding-char) ? ) (insert " "))
8797 (insert "<= ")))
8798 (t (insert-char ?\, 1)))
8799 (self-insert-command count)))
8801 (defun vhdl-electric-period (count) "`..' --> ` => '"
8802 (interactive "p")
8803 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8804 (cond ((= (preceding-char) vhdl-last-input-event)
8805 (progn (delete-char -1)
8806 (unless (eq (preceding-char) ? ) (insert " "))
8807 (insert "=> ")))
8808 (t (insert-char ?\. 1)))
8809 (self-insert-command count)))
8811 (defun vhdl-electric-equal (count) "`==' --> ` == '"
8812 (interactive "p")
8813 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8814 (cond ((= (preceding-char) vhdl-last-input-event)
8815 (progn (delete-char -1)
8816 (unless (eq (preceding-char) ? ) (insert " "))
8817 (insert "== ")))
8818 (t (insert-char ?\= 1)))
8819 (self-insert-command count)))
8821 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8822 ;; VHDL templates
8824 (defun vhdl-template-paired-parens ()
8825 "Insert a pair of round parentheses, placing point between them."
8826 (interactive)
8827 (insert "()")
8828 (backward-char))
8830 (defun vhdl-template-alias ()
8831 "Insert alias declaration."
8832 (interactive)
8833 (let ((start (point)))
8834 (vhdl-insert-keyword "ALIAS ")
8835 (when (vhdl-template-field "name" nil t start (point))
8836 (insert " : ")
8837 (unless (vhdl-template-field
8838 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8839 nil t)
8840 (delete-char -3))
8841 (vhdl-insert-keyword " IS ")
8842 (vhdl-template-field "name" ";")
8843 (vhdl-comment-insert-inline))))
8845 (defun vhdl-template-architecture ()
8846 "Insert architecture."
8847 (interactive)
8848 (let ((margin (current-indentation))
8849 (start (point))
8850 arch-name)
8851 (vhdl-insert-keyword "ARCHITECTURE ")
8852 (when (setq arch-name
8853 (vhdl-template-field "name" nil t start (point)))
8854 (vhdl-insert-keyword " OF ")
8855 (if (save-excursion
8856 (vhdl-prepare-search-1
8857 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8858 (insert (match-string 1))
8859 (vhdl-template-field "entity name"))
8860 (vhdl-insert-keyword " IS\n")
8861 (vhdl-template-begin-end
8862 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8863 (memq vhdl-insert-empty-lines '(unit all))))))
8865 (defun vhdl-template-array (kind &optional secondary)
8866 "Insert array type definition."
8867 (interactive)
8868 (let ((start (point)))
8869 (vhdl-insert-keyword "ARRAY (")
8870 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8871 secondary)
8872 (vhdl-insert-keyword ") OF ")
8873 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8874 (vhdl-insert-keyword ";"))))
8876 (defun vhdl-template-assert ()
8877 "Insert an assertion statement."
8878 (interactive)
8879 (let ((start (point)))
8880 (vhdl-insert-keyword "ASSERT ")
8881 (when vhdl-conditions-in-parenthesis (insert "("))
8882 (when (vhdl-template-field "condition (negated)" nil t start (point))
8883 (when vhdl-conditions-in-parenthesis (insert ")"))
8884 (setq start (point))
8885 (vhdl-insert-keyword " REPORT ")
8886 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8887 (delete-region start (point)))
8888 (setq start (point))
8889 (vhdl-insert-keyword " SEVERITY ")
8890 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8891 (delete-region start (point)))
8892 (insert ";"))))
8894 (defun vhdl-template-attribute ()
8895 "Insert an attribute declaration or specification."
8896 (interactive)
8897 (if (eq (vhdl-decision-query
8898 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8899 (vhdl-template-attribute-spec)
8900 (vhdl-template-attribute-decl)))
8902 (defun vhdl-template-attribute-decl ()
8903 "Insert an attribute declaration."
8904 (interactive)
8905 (let ((start (point)))
8906 (vhdl-insert-keyword "ATTRIBUTE ")
8907 (when (vhdl-template-field "name" " : " t start (point))
8908 (vhdl-template-field "type" ";")
8909 (vhdl-comment-insert-inline))))
8911 (defun vhdl-template-attribute-spec ()
8912 "Insert an attribute specification."
8913 (interactive)
8914 (let ((start (point)))
8915 (vhdl-insert-keyword "ATTRIBUTE ")
8916 (when (vhdl-template-field "name" nil t start (point))
8917 (vhdl-insert-keyword " OF ")
8918 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8919 (vhdl-template-field "entity class")
8920 (vhdl-insert-keyword " IS ")
8921 (vhdl-template-field "expression" ";"))))
8923 (defun vhdl-template-block ()
8924 "Insert a block."
8925 (interactive)
8926 (let ((margin (current-indentation))
8927 (start (point))
8928 label)
8929 (vhdl-insert-keyword ": BLOCK ")
8930 (goto-char start)
8931 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8932 (forward-word-strictly 1)
8933 (forward-char 1)
8934 (insert "(")
8935 (if (vhdl-template-field "[guard expression]" nil t)
8936 (insert ")")
8937 (delete-char -2))
8938 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8939 (insert "\n")
8940 (vhdl-template-begin-end "BLOCK" label margin)
8941 (vhdl-comment-block))))
8943 (defun vhdl-template-block-configuration ()
8944 "Insert a block configuration statement."
8945 (interactive)
8946 (let ((margin (current-indentation))
8947 (start (point)))
8948 (vhdl-insert-keyword "FOR ")
8949 (when (vhdl-template-field "block name" nil t start (point))
8950 (vhdl-insert-keyword "\n\n")
8951 (indent-to margin)
8952 (vhdl-insert-keyword "END FOR;")
8953 (end-of-line 0)
8954 (indent-to (+ margin vhdl-basic-offset)))))
8956 (defun vhdl-template-break ()
8957 "Insert a break statement."
8958 (interactive)
8959 (let (position)
8960 (vhdl-insert-keyword "BREAK")
8961 (setq position (point))
8962 (insert " ")
8963 (while (or
8964 (progn (vhdl-insert-keyword "FOR ")
8965 (if (vhdl-template-field "[quantity name]" " USE " t)
8966 (progn (vhdl-template-field "quantity name" " => ") t)
8967 (delete-region (point)
8968 (progn (forward-word-strictly -1) (point)))
8969 nil))
8970 (vhdl-template-field "[quantity name]" " => " t))
8971 (vhdl-template-field "expression")
8972 (setq position (point))
8973 (insert ", "))
8974 (delete-region position (point))
8975 (unless (vhdl-sequential-statement-p)
8976 (vhdl-insert-keyword " ON ")
8977 (if (vhdl-template-field "[sensitivity list]" nil t)
8978 (setq position (point))
8979 (delete-region position (point))))
8980 (vhdl-insert-keyword " WHEN ")
8981 (when vhdl-conditions-in-parenthesis (insert "("))
8982 (if (vhdl-template-field "[condition]" nil t)
8983 (when vhdl-conditions-in-parenthesis (insert ")"))
8984 (delete-region position (point)))
8985 (insert ";")))
8987 (defun vhdl-template-case (&optional kind)
8988 "Insert a case statement."
8989 (interactive)
8990 (let ((margin (current-indentation))
8991 (start (point))
8992 label)
8993 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
8994 (not (vhdl-standard-p 'ams))) 'is 'use)))
8995 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8996 (vhdl-insert-keyword "CASE ")
8997 (vhdl-insert-keyword ": CASE ")
8998 (goto-char start)
8999 (setq label (vhdl-template-field "[label]" nil t))
9000 (unless label (delete-char 2))
9001 (forward-word-strictly 1)
9002 (forward-char 1))
9003 (when (vhdl-template-field "expression" nil t start (point))
9004 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
9005 (indent-to margin)
9006 (vhdl-insert-keyword "END CASE")
9007 (when label (insert " " label))
9008 (insert ";")
9009 (forward-line -1)
9010 (indent-to (+ margin vhdl-basic-offset))
9011 (vhdl-insert-keyword "WHEN ")
9012 (let ((position (point)))
9013 (insert " => ;\n")
9014 (indent-to (+ margin vhdl-basic-offset))
9015 (vhdl-insert-keyword "WHEN OTHERS => null;")
9016 (goto-char position)))))
9018 (defun vhdl-template-case-is ()
9019 "Insert a sequential case statement."
9020 (interactive)
9021 (vhdl-template-case 'is))
9023 (defun vhdl-template-case-use ()
9024 "Insert a simultaneous case statement."
9025 (interactive)
9026 (vhdl-template-case 'use))
9028 (defun vhdl-template-component ()
9029 "Insert a component declaration."
9030 (interactive)
9031 (vhdl-template-component-decl))
9033 (defun vhdl-template-component-conf ()
9034 "Insert a component configuration (uses `vhdl-template-configuration-spec'
9035 since these are almost equivalent)."
9036 (interactive)
9037 (let ((margin (current-indentation))
9038 (result (vhdl-template-configuration-spec t)))
9039 (when result
9040 (insert "\n")
9041 (indent-to margin)
9042 (vhdl-insert-keyword "END FOR;")
9043 (when (eq result 'no-use)
9044 (end-of-line -0)))))
9046 (defun vhdl-template-component-decl ()
9047 "Insert a component declaration."
9048 (interactive)
9049 (let ((margin (current-indentation))
9050 (start (point))
9051 name end-column)
9052 (vhdl-insert-keyword "COMPONENT ")
9053 (when (setq name (vhdl-template-field "name" nil t start (point)))
9054 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9055 (insert "\n\n")
9056 (indent-to margin)
9057 (vhdl-insert-keyword "END COMPONENT")
9058 (unless (vhdl-standard-p '87) (insert " " name))
9059 (insert ";")
9060 (setq end-column (current-column))
9061 (end-of-line -0)
9062 (indent-to (+ margin vhdl-basic-offset))
9063 (vhdl-template-generic-list t t)
9064 (insert "\n")
9065 (indent-to (+ margin vhdl-basic-offset))
9066 (vhdl-template-port-list t)
9067 (beginning-of-line 2)
9068 (forward-char end-column))))
9070 (defun vhdl-template-component-inst ()
9071 "Insert a component instantiation statement."
9072 (interactive)
9073 (let ((margin (current-indentation))
9074 (start (point))
9075 unit position)
9076 (when (vhdl-template-field "instance label" nil t start (point))
9077 (insert ": ")
9078 (if (not (vhdl-use-direct-instantiation))
9079 (vhdl-template-field "component name")
9080 ;; direct instantiation
9081 (setq unit (vhdl-template-field
9082 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
9083 (setq unit (upcase (or unit "")))
9084 (cond ((equal unit "ENTITY")
9085 (let ((begin (point)))
9086 (vhdl-template-field "library name" "." t begin (point) nil
9087 (vhdl-work-library))
9088 (vhdl-template-field "entity name" "(")
9089 (if (vhdl-template-field "[architecture name]" nil t)
9090 (insert ")")
9091 (delete-char -1))))
9092 ((equal unit "CONFIGURATION")
9093 (vhdl-template-field "library name" "." nil nil nil nil
9094 (vhdl-work-library))
9095 (vhdl-template-field "configuration name"))
9096 (t (vhdl-template-field "component name"))))
9097 (insert "\n")
9098 (indent-to (+ margin vhdl-basic-offset))
9099 (setq position (point))
9100 (vhdl-insert-keyword "GENERIC ")
9101 (when (vhdl-template-map position t t)
9102 (insert "\n")
9103 (indent-to (+ margin vhdl-basic-offset)))
9104 (setq position (point))
9105 (vhdl-insert-keyword "PORT ")
9106 (unless (vhdl-template-map position t t)
9107 (delete-region (line-beginning-position) (point))
9108 (delete-char -1))
9109 (insert ";"))))
9111 (defun vhdl-template-conditional-signal-asst ()
9112 "Insert a conditional signal assignment."
9113 (interactive)
9114 (when (vhdl-template-field "target signal")
9115 (insert " <= ")
9116 (let ((margin (current-column))
9117 (start (point))
9118 position)
9119 (vhdl-template-field "waveform")
9120 (setq position (point))
9121 (vhdl-insert-keyword " WHEN ")
9122 (when vhdl-conditions-in-parenthesis (insert "("))
9123 (while (and (vhdl-template-field "[condition]" nil t)
9124 (progn
9125 (when vhdl-conditions-in-parenthesis (insert ")"))
9126 (setq position (point))
9127 (vhdl-insert-keyword " ELSE")
9128 (insert "\n")
9129 (indent-to margin)
9130 (vhdl-template-field "[waveform]" nil t)))
9131 (setq position (point))
9132 (vhdl-insert-keyword " WHEN ")
9133 (when vhdl-conditions-in-parenthesis (insert "(")))
9134 (delete-region position (point))
9135 (insert ";")
9136 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9138 (defun vhdl-template-configuration ()
9139 "Insert a configuration specification if within an architecture,
9140 a block or component configuration if within a configuration declaration,
9141 a configuration declaration if not within a design unit."
9142 (interactive)
9143 (vhdl-prepare-search-1
9144 (cond
9145 ((and (save-excursion ; architecture body
9146 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
9147 (equal "ARCHITECTURE" (upcase (match-string 1))))
9148 (vhdl-template-configuration-spec))
9149 ((and (save-excursion ; configuration declaration
9150 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9151 (equal "CONFIGURATION" (upcase (match-string 1))))
9152 (if (eq (vhdl-decision-query
9153 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
9154 (vhdl-template-component-conf)
9155 (vhdl-template-block-configuration)))
9156 (t (vhdl-template-configuration-decl))))) ; otherwise
9158 (defun vhdl-template-configuration-spec (&optional optional-use)
9159 "Insert a configuration specification."
9160 (interactive)
9161 (let ((margin (current-indentation))
9162 (start (point))
9163 aspect position)
9164 (vhdl-insert-keyword "FOR ")
9165 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9166 t start (point))
9167 (vhdl-template-field "component name" "\n")
9168 (indent-to (+ margin vhdl-basic-offset))
9169 (setq start (point))
9170 (vhdl-insert-keyword "USE ")
9171 (if (and optional-use
9172 (not (setq aspect (vhdl-template-field
9173 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
9174 (progn (delete-region start (point)) 'no-use)
9175 (unless optional-use
9176 (setq aspect (vhdl-template-field
9177 "ENTITY | CONFIGURATION | OPEN" " ")))
9178 (setq aspect (upcase (or aspect "")))
9179 (cond ((equal aspect "ENTITY")
9180 (vhdl-template-field "library name" "." nil nil nil nil
9181 (vhdl-work-library))
9182 (vhdl-template-field "entity name" "(")
9183 (if (vhdl-template-field "[architecture name]" nil t)
9184 (insert ")")
9185 (delete-char -1))
9186 (insert "\n")
9187 (indent-to (+ margin (* 2 vhdl-basic-offset)))
9188 (setq position (point))
9189 (vhdl-insert-keyword "GENERIC ")
9190 (when (vhdl-template-map position t t)
9191 (insert "\n")
9192 (indent-to (+ margin (* 2 vhdl-basic-offset))))
9193 (setq position (point))
9194 (vhdl-insert-keyword "PORT ")
9195 (unless (vhdl-template-map position t t)
9196 (delete-region (line-beginning-position) (point))
9197 (delete-char -1))
9198 (insert ";")
9200 ((equal aspect "CONFIGURATION")
9201 (vhdl-template-field "library name" "." nil nil nil nil
9202 (vhdl-work-library))
9203 (vhdl-template-field "configuration name" ";"))
9204 (t (delete-char -1) (insert ";") t))))))
9207 (defun vhdl-template-configuration-decl ()
9208 "Insert a configuration declaration."
9209 (interactive)
9210 (let ((margin (current-indentation))
9211 (start (point))
9212 entity-exists string name position)
9213 (vhdl-insert-keyword "CONFIGURATION ")
9214 (when (setq name (vhdl-template-field "name" nil t start (point)))
9215 (vhdl-insert-keyword " OF ")
9216 (save-excursion
9217 (vhdl-prepare-search-1
9218 (setq entity-exists (vhdl-re-search-backward
9219 "\\<entity \\(\\w*\\) is\\>" nil t))
9220 (setq string (match-string 1))))
9221 (if (and entity-exists (not (equal string "")))
9222 (insert string)
9223 (vhdl-template-field "entity name"))
9224 (vhdl-insert-keyword " IS\n")
9225 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9226 (indent-to (+ margin vhdl-basic-offset))
9227 (setq position (point))
9228 (insert "\n")
9229 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9230 (indent-to margin)
9231 (vhdl-insert-keyword "END ")
9232 (unless (vhdl-standard-p '87)
9233 (vhdl-insert-keyword "CONFIGURATION "))
9234 (insert name ";")
9235 (goto-char position))))
9237 (defun vhdl-template-constant ()
9238 "Insert a constant declaration."
9239 (interactive)
9240 (let ((start (point))
9241 (in-arglist (vhdl-in-argument-list-p)))
9242 (vhdl-insert-keyword "CONSTANT ")
9243 (when (vhdl-template-field "name" nil t start (point))
9244 (insert " : ")
9245 (when in-arglist (vhdl-insert-keyword "IN "))
9246 (vhdl-template-field "type")
9247 (if in-arglist
9248 (progn (insert ";")
9249 (vhdl-comment-insert-inline))
9250 (let ((position (point)))
9251 (insert " := ")
9252 (unless (vhdl-template-field "[initialization]" nil t)
9253 (delete-region position (point)))
9254 (insert ";")
9255 (vhdl-comment-insert-inline))))))
9257 (defun vhdl-template-context ()
9258 "Insert a context declaration."
9259 (interactive)
9260 (let ((margin (current-indentation))
9261 (start (point))
9262 entity-exists string name position)
9263 (vhdl-insert-keyword "CONTEXT ")
9264 (when (setq name (vhdl-template-field "name" nil t start (point)))
9265 (vhdl-insert-keyword " IS\n")
9266 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9267 (indent-to (+ margin vhdl-basic-offset))
9268 (setq position (point))
9269 (insert "\n")
9270 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9271 (indent-to margin)
9272 (vhdl-insert-keyword "END ")
9273 (unless (vhdl-standard-p '87)
9274 (vhdl-insert-keyword "CONTEXT "))
9275 (insert name ";")
9276 (goto-char position))))
9278 (defun vhdl-template-default ()
9279 "Insert nothing."
9280 (interactive)
9281 (insert " ")
9282 (unexpand-abbrev)
9283 (backward-word-strictly 1)
9284 (vhdl-case-word 1)
9285 (forward-char 1))
9287 (defun vhdl-template-default-indent ()
9288 "Insert nothing and indent."
9289 (interactive)
9290 (insert " ")
9291 (unexpand-abbrev)
9292 (backward-word-strictly 1)
9293 (vhdl-case-word 1)
9294 (forward-char 1)
9295 (indent-according-to-mode))
9297 (defun vhdl-template-disconnect ()
9298 "Insert a disconnect statement."
9299 (interactive)
9300 (let ((start (point)))
9301 (vhdl-insert-keyword "DISCONNECT ")
9302 (when (vhdl-template-field "signal names | OTHERS | ALL"
9303 " : " t start (point))
9304 (vhdl-template-field "type")
9305 (vhdl-insert-keyword " AFTER ")
9306 (vhdl-template-field "time expression" ";"))))
9308 (defun vhdl-template-else ()
9309 "Insert an else statement."
9310 (interactive)
9311 (let (margin)
9312 (vhdl-prepare-search-1
9313 (vhdl-insert-keyword "ELSE")
9314 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
9315 (equal "WHEN" (upcase (match-string 1))))
9316 (insert " ")
9317 (indent-according-to-mode)
9318 (setq margin (current-indentation))
9319 (insert "\n")
9320 (indent-to (+ margin vhdl-basic-offset))))))
9322 (defun vhdl-template-elsif ()
9323 "Insert an elsif statement."
9324 (interactive)
9325 (let ((start (point))
9326 margin)
9327 (vhdl-insert-keyword "ELSIF ")
9328 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
9329 (when vhdl-conditions-in-parenthesis (insert "("))
9330 (when (vhdl-template-field "condition" nil t start (point))
9331 (when vhdl-conditions-in-parenthesis (insert ")"))
9332 (indent-according-to-mode)
9333 (setq margin (current-indentation))
9334 (vhdl-insert-keyword
9335 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
9336 (indent-to (+ margin vhdl-basic-offset))))))
9338 (defun vhdl-template-entity ()
9339 "Insert an entity."
9340 (interactive)
9341 (let ((margin (current-indentation))
9342 (start (point))
9343 name end-column)
9344 (vhdl-insert-keyword "ENTITY ")
9345 (when (setq name (vhdl-template-field "name" nil t start (point)))
9346 (vhdl-insert-keyword " IS\n\n")
9347 (indent-to margin)
9348 (vhdl-insert-keyword "END ")
9349 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9350 (insert name ";")
9351 (setq end-column (current-column))
9352 (end-of-line -0)
9353 (indent-to (+ margin vhdl-basic-offset))
9354 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9355 (indent-to (+ margin vhdl-basic-offset))
9356 (when (vhdl-template-generic-list t)
9357 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9358 (insert "\n")
9359 (indent-to (+ margin vhdl-basic-offset))
9360 (when (vhdl-template-port-list t)
9361 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9362 (beginning-of-line 2)
9363 (forward-char end-column))))
9365 (defun vhdl-template-exit ()
9366 "Insert an exit statement."
9367 (interactive)
9368 (let ((start (point)))
9369 (vhdl-insert-keyword "EXIT ")
9370 (if (vhdl-template-field "[loop label]" nil t start (point))
9371 (let ((position (point)))
9372 (vhdl-insert-keyword " WHEN ")
9373 (when vhdl-conditions-in-parenthesis (insert "("))
9374 (if (vhdl-template-field "[condition]" nil t)
9375 (when vhdl-conditions-in-parenthesis (insert ")"))
9376 (delete-region position (point))))
9377 (delete-char -1))
9378 (insert ";")))
9380 (defun vhdl-template-file ()
9381 "Insert a file declaration."
9382 (interactive)
9383 (let ((start (point)))
9384 (vhdl-insert-keyword "FILE ")
9385 (when (vhdl-template-field "name" nil t start (point))
9386 (insert " : ")
9387 (vhdl-template-field "type")
9388 (unless (vhdl-standard-p '87)
9389 (vhdl-insert-keyword " OPEN ")
9390 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9391 nil t)
9392 (delete-char -6)))
9393 (vhdl-insert-keyword " IS ")
9394 (when (vhdl-standard-p '87)
9395 (vhdl-template-field "[IN | OUT]" " " t))
9396 (vhdl-template-field "filename-string" nil nil nil nil t)
9397 (insert ";")
9398 (vhdl-comment-insert-inline))))
9400 (defun vhdl-template-for ()
9401 "Insert a block or component configuration if within a configuration
9402 declaration, a configuration specification if within an architecture
9403 declarative part (and not within a subprogram), a for-loop if within a
9404 sequential statement part (subprogram or process), and a for-generate
9405 otherwise."
9406 (interactive)
9407 (vhdl-prepare-search-1
9408 (cond
9409 ((vhdl-sequential-statement-p) ; sequential statement
9410 (vhdl-template-for-loop))
9411 ((and (save-excursion ; configuration declaration
9412 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9413 (equal "CONFIGURATION" (upcase (match-string 1))))
9414 (if (eq (vhdl-decision-query
9415 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9416 (vhdl-template-component-conf)
9417 (vhdl-template-block-configuration)))
9418 ((and (save-excursion
9419 (re-search-backward ; architecture declarative part
9420 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9421 (equal "ARCHITECTURE" (upcase (match-string 1))))
9422 (vhdl-template-configuration-spec))
9423 (t (vhdl-template-for-generate))))) ; concurrent statement
9425 (defun vhdl-template-for-generate ()
9426 "Insert a for-generate."
9427 (interactive)
9428 (let ((margin (current-indentation))
9429 (start (point))
9430 label position)
9431 (vhdl-insert-keyword ": FOR ")
9432 (setq position (point-marker))
9433 (goto-char start)
9434 (when (setq label (vhdl-template-field "label" nil t start position))
9435 (goto-char position)
9436 (vhdl-template-field "loop variable")
9437 (vhdl-insert-keyword " IN ")
9438 (vhdl-template-field "range")
9439 (vhdl-template-generate-body margin label))))
9441 (defun vhdl-template-for-loop ()
9442 "Insert a for loop."
9443 (interactive)
9444 (let ((margin (current-indentation))
9445 (start (point))
9446 label index)
9447 (if (not (eq vhdl-optional-labels 'all))
9448 (vhdl-insert-keyword "FOR ")
9449 (vhdl-insert-keyword ": FOR ")
9450 (goto-char start)
9451 (setq label (vhdl-template-field "[label]" nil t))
9452 (unless label (delete-char 2))
9453 (forward-word-strictly 1)
9454 (forward-char 1))
9455 (when (setq index (vhdl-template-field "loop variable"
9456 nil t start (point)))
9457 (vhdl-insert-keyword " IN ")
9458 (vhdl-template-field "range")
9459 (vhdl-insert-keyword " LOOP\n\n")
9460 (indent-to margin)
9461 (vhdl-insert-keyword "END LOOP")
9462 (if label
9463 (insert " " label ";")
9464 (insert ";")
9465 (when vhdl-self-insert-comments (insert " -- " index)))
9466 (forward-line -1)
9467 (indent-to (+ margin vhdl-basic-offset)))))
9469 (defun vhdl-template-function (&optional kind)
9470 "Insert a function declaration or body."
9471 (interactive)
9472 (let ((margin (current-indentation))
9473 (start (point))
9474 name)
9475 (vhdl-insert-keyword "FUNCTION ")
9476 (when (setq name (vhdl-template-field "name" nil t start (point)))
9477 (vhdl-template-argument-list t)
9478 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9479 (end-of-line)
9480 (insert "\n")
9481 (indent-to (+ margin vhdl-basic-offset))
9482 (vhdl-insert-keyword "RETURN ")
9483 (vhdl-template-field "type")
9484 (if (if kind (eq kind 'body)
9485 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9486 (progn (vhdl-insert-keyword " IS\n")
9487 (vhdl-template-begin-end
9488 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9489 (vhdl-comment-block))
9490 (insert ";")))))
9492 (defun vhdl-template-function-decl ()
9493 "Insert a function declaration."
9494 (interactive)
9495 (vhdl-template-function 'decl))
9497 (defun vhdl-template-function-body ()
9498 "Insert a function declaration."
9499 (interactive)
9500 (vhdl-template-function 'body))
9502 (defun vhdl-template-generate ()
9503 "Insert a generation scheme."
9504 (interactive)
9505 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9506 (vhdl-template-if-generate)
9507 (vhdl-template-for-generate)))
9509 (defun vhdl-template-generic ()
9510 "Insert generic declaration, or generic map in instantiation statements."
9511 (interactive)
9512 (let ((start (point)))
9513 (vhdl-prepare-search-1
9514 (cond
9515 ((and (save-excursion ; entity declaration
9516 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9517 (equal "ENTITY" (upcase (match-string 1))))
9518 (vhdl-template-generic-list nil))
9519 ((or (save-excursion
9520 (or (beginning-of-line)
9521 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9522 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9523 (vhdl-insert-keyword "GENERIC ")
9524 (vhdl-template-map start))
9525 (t (vhdl-template-generic-list nil t))))))
9527 (defun vhdl-template-group ()
9528 "Insert group or group template declaration."
9529 (interactive)
9530 (let ((start (point)))
9531 (if (eq (vhdl-decision-query
9532 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9533 (vhdl-template-group-template)
9534 (vhdl-template-group-decl))))
9536 (defun vhdl-template-group-decl ()
9537 "Insert group declaration."
9538 (interactive)
9539 (let ((start (point)))
9540 (vhdl-insert-keyword "GROUP ")
9541 (when (vhdl-template-field "name" " : " t start (point))
9542 (vhdl-template-field "template name" " (")
9543 (vhdl-template-field "constituent list" ");")
9544 (vhdl-comment-insert-inline))))
9546 (defun vhdl-template-group-template ()
9547 "Insert group template declaration."
9548 (interactive)
9549 (let ((start (point)))
9550 (vhdl-insert-keyword "GROUP ")
9551 (when (vhdl-template-field "template name" nil t start (point))
9552 (vhdl-insert-keyword " IS (")
9553 (vhdl-template-field "entity class list" ");")
9554 (vhdl-comment-insert-inline))))
9556 (defun vhdl-template-if ()
9557 "Insert a sequential if statement or an if-generate statement."
9558 (interactive)
9559 (if (vhdl-sequential-statement-p)
9560 (vhdl-template-if-then)
9561 (if (and (vhdl-standard-p 'ams)
9562 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9563 (vhdl-template-if-use)
9564 (vhdl-template-if-generate))))
9566 (defun vhdl-template-if-generate ()
9567 "Insert an if-generate."
9568 (interactive)
9569 (let ((margin (current-indentation))
9570 (start (point))
9571 label position)
9572 (vhdl-insert-keyword ": IF ")
9573 (setq position (point-marker))
9574 (goto-char start)
9575 (when (setq label (vhdl-template-field "label" nil t start position))
9576 (goto-char position)
9577 (when vhdl-conditions-in-parenthesis (insert "("))
9578 (vhdl-template-field "condition")
9579 (when vhdl-conditions-in-parenthesis (insert ")"))
9580 (vhdl-template-generate-body margin label))))
9582 (defun vhdl-template-if-then-use (kind)
9583 "Insert a sequential if statement."
9584 (interactive)
9585 (let ((margin (current-indentation))
9586 (start (point))
9587 label)
9588 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9589 (vhdl-insert-keyword "IF ")
9590 (vhdl-insert-keyword ": IF ")
9591 (goto-char start)
9592 (setq label (vhdl-template-field "[label]" nil t))
9593 (unless label (delete-char 2))
9594 (forward-word-strictly 1)
9595 (forward-char 1))
9596 (when vhdl-conditions-in-parenthesis (insert "("))
9597 (when (vhdl-template-field "condition" nil t start (point))
9598 (when vhdl-conditions-in-parenthesis (insert ")"))
9599 (vhdl-insert-keyword
9600 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9601 (indent-to margin)
9602 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9603 (when label (insert " " label))
9604 (insert ";")
9605 (forward-line -1)
9606 (indent-to (+ margin vhdl-basic-offset)))))
9608 (defun vhdl-template-if-then ()
9609 "Insert a sequential if statement."
9610 (interactive)
9611 (vhdl-template-if-then-use 'then))
9613 (defun vhdl-template-if-use ()
9614 "Insert a simultaneous if statement."
9615 (interactive)
9616 (vhdl-template-if-then-use 'use))
9618 (defun vhdl-template-instance ()
9619 "Insert a component instantiation statement."
9620 (interactive)
9621 (vhdl-template-component-inst))
9623 (defun vhdl-template-library ()
9624 "Insert a library specification."
9625 (interactive)
9626 (let ((margin (current-indentation))
9627 (start (point))
9628 name end-pos)
9629 (vhdl-insert-keyword "LIBRARY ")
9630 (when (setq name (vhdl-template-field "names" nil t start (point)))
9631 (insert ";")
9632 (unless (string-match "," name)
9633 (setq end-pos (point))
9634 (insert "\n")
9635 (indent-to margin)
9636 (vhdl-insert-keyword "USE ")
9637 (insert name)
9638 (vhdl-insert-keyword "..ALL;")
9639 (backward-char 5)
9640 (if (vhdl-template-field "package name")
9641 (forward-char 5)
9642 (delete-region end-pos (+ (point) 5)))))))
9644 (defun vhdl-template-limit ()
9645 "Insert a limit."
9646 (interactive)
9647 (let ((start (point)))
9648 (vhdl-insert-keyword "LIMIT ")
9649 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9650 t start (point))
9651 (vhdl-template-field "type")
9652 (vhdl-insert-keyword " WITH ")
9653 (vhdl-template-field "real expression" ";"))))
9655 (defun vhdl-template-loop ()
9656 "Insert a loop."
9657 (interactive)
9658 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9659 (cond ((eq char ?w)
9660 (vhdl-template-while-loop))
9661 ((eq char ?f)
9662 (vhdl-template-for-loop))
9663 (t (vhdl-template-bare-loop)))))
9665 (defun vhdl-template-bare-loop ()
9666 "Insert a loop."
9667 (interactive)
9668 (let ((margin (current-indentation))
9669 (start (point))
9670 label)
9671 (if (not (eq vhdl-optional-labels 'all))
9672 (vhdl-insert-keyword "LOOP ")
9673 (vhdl-insert-keyword ": LOOP ")
9674 (goto-char start)
9675 (setq label (vhdl-template-field "[label]" nil t))
9676 (unless label (delete-char 2))
9677 (forward-word-strictly 1)
9678 (delete-char 1))
9679 (insert "\n\n")
9680 (indent-to margin)
9681 (vhdl-insert-keyword "END LOOP")
9682 (insert (if label (concat " " label ";") ";"))
9683 (forward-line -1)
9684 (indent-to (+ margin vhdl-basic-offset))))
9686 (defun vhdl-template-map (&optional start optional secondary)
9687 "Insert a map specification with association list."
9688 (interactive)
9689 (let ((start (or start (point)))
9690 margin end-pos)
9691 (vhdl-insert-keyword "MAP (")
9692 (if (not vhdl-association-list-with-formals)
9693 (if (vhdl-template-field
9694 (concat (and optional "[") "association list" (and optional "]"))
9695 ")" (or (not secondary) optional)
9696 (and (not secondary) start) (point))
9698 (if (and optional secondary) (delete-region start (point)))
9699 nil)
9700 (if vhdl-argument-list-indent
9701 (setq margin (current-column))
9702 (setq margin (+ (current-indentation) vhdl-basic-offset))
9703 (insert "\n")
9704 (indent-to margin))
9705 (if (vhdl-template-field
9706 (concat (and optional "[") "formal" (and optional "]"))
9707 " => " (or (not secondary) optional)
9708 (and (not secondary) start) (point))
9709 (progn
9710 (vhdl-template-field "actual" ",")
9711 (setq end-pos (point))
9712 (insert "\n")
9713 (indent-to margin)
9714 (while (vhdl-template-field "[formal]" " => " t)
9715 (vhdl-template-field "actual" ",")
9716 (setq end-pos (point))
9717 (insert "\n")
9718 (indent-to margin))
9719 (delete-region end-pos (point))
9720 (delete-char -1)
9721 (insert ")")
9722 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9724 (when (and optional secondary) (delete-region start (point)))
9725 nil))))
9727 (defun vhdl-template-modify (&optional noerror)
9728 "Actualize modification date."
9729 (interactive)
9730 (vhdl-prepare-search-2
9731 (save-excursion
9732 (goto-char (point-min))
9733 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9734 (progn (delete-region (point) (progn (end-of-line) (point)))
9735 (vhdl-template-insert-date))
9736 (unless noerror
9737 (error "ERROR: Modification date prefix string \"%s\" not found"
9738 vhdl-modify-date-prefix-string))))))
9741 (defun vhdl-template-modify-noerror ()
9742 "Call `vhdl-template-modify' with NOERROR non-nil."
9743 (vhdl-template-modify t))
9745 (defun vhdl-template-nature ()
9746 "Insert a nature declaration."
9747 (interactive)
9748 (let ((start (point))
9749 name mid-pos end-pos)
9750 (vhdl-insert-keyword "NATURE ")
9751 (when (setq name (vhdl-template-field "name" nil t start (point)))
9752 (vhdl-insert-keyword " IS ")
9753 (let ((definition
9754 (upcase
9755 (or (vhdl-template-field
9756 "across type | ARRAY | RECORD")
9757 ""))))
9758 (cond ((equal definition "")
9759 (insert ";"))
9760 ((equal definition "ARRAY")
9761 (delete-region (point) (progn (forward-word-strictly -1)
9762 (point)))
9763 (vhdl-template-array 'nature t))
9764 ((equal definition "RECORD")
9765 (setq mid-pos (point-marker))
9766 (delete-region (point) (progn (forward-word-strictly -1)
9767 (point)))
9768 (vhdl-template-record 'nature name t))
9770 (vhdl-insert-keyword " ACROSS ")
9771 (vhdl-template-field "through type")
9772 (vhdl-insert-keyword " THROUGH ")
9773 (vhdl-template-field "reference name")
9774 (vhdl-insert-keyword " REFERENCE;")))
9775 (when mid-pos
9776 (setq end-pos (point-marker))
9777 (goto-char mid-pos)
9778 (end-of-line))
9779 (vhdl-comment-insert-inline)
9780 (when end-pos (goto-char end-pos))))))
9782 (defun vhdl-template-next ()
9783 "Insert a next statement."
9784 (interactive)
9785 (let ((start (point)))
9786 (vhdl-insert-keyword "NEXT ")
9787 (if (vhdl-template-field "[loop label]" nil t start (point))
9788 (let ((position (point)))
9789 (vhdl-insert-keyword " WHEN ")
9790 (when vhdl-conditions-in-parenthesis (insert "("))
9791 (if (vhdl-template-field "[condition]" nil t)
9792 (when vhdl-conditions-in-parenthesis (insert ")"))
9793 (delete-region position (point))))
9794 (delete-char -1))
9795 (insert ";")))
9797 (defun vhdl-template-others ()
9798 "Insert an others aggregate."
9799 (interactive)
9800 (let ((start (point)))
9801 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9802 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9803 (vhdl-insert-keyword "OTHERS => '")
9804 (when (vhdl-template-field "value" nil t start (point))
9805 (insert "')")))
9806 (vhdl-insert-keyword "OTHERS "))))
9808 (defun vhdl-template-package (&optional kind)
9809 "Insert a package specification or body."
9810 (interactive)
9811 (let ((margin (current-indentation))
9812 (start (point))
9813 name body position)
9814 (vhdl-insert-keyword "PACKAGE ")
9815 (setq body (if kind (eq kind 'body)
9816 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9817 (when body
9818 (vhdl-insert-keyword "BODY ")
9819 (when (save-excursion
9820 (vhdl-prepare-search-1
9821 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9822 (insert (setq name (match-string 1)))))
9823 (when (or name
9824 (setq name (vhdl-template-field "name" nil t start (point))))
9825 (vhdl-insert-keyword " IS\n")
9826 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9827 (indent-to (+ margin vhdl-basic-offset))
9828 (setq position (point))
9829 (insert "\n")
9830 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9831 (indent-to margin)
9832 (vhdl-insert-keyword "END ")
9833 (unless (vhdl-standard-p '87)
9834 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9835 (insert (or name "") ";")
9836 (goto-char position))))
9838 (defun vhdl-template-package-decl ()
9839 "Insert a package specification."
9840 (interactive)
9841 (vhdl-template-package 'decl))
9843 (defun vhdl-template-package-body ()
9844 "Insert a package body."
9845 (interactive)
9846 (vhdl-template-package 'body))
9848 (defun vhdl-template-port ()
9849 "Insert a port declaration, or port map in instantiation statements."
9850 (interactive)
9851 (let ((start (point)))
9852 (vhdl-prepare-search-1
9853 (cond
9854 ((and (save-excursion ; entity declaration
9855 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9856 (equal "ENTITY" (upcase (match-string 1))))
9857 (vhdl-template-port-list nil))
9858 ((or (save-excursion
9859 (or (beginning-of-line)
9860 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9861 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9862 (vhdl-insert-keyword "PORT ")
9863 (vhdl-template-map start))
9864 (t (vhdl-template-port-list nil))))))
9866 (defun vhdl-template-procedural ()
9867 "Insert a procedural."
9868 (interactive)
9869 (let ((margin (current-indentation))
9870 (start (point))
9871 (case-fold-search t)
9872 label)
9873 (vhdl-insert-keyword "PROCEDURAL ")
9874 (when (memq vhdl-optional-labels '(process all))
9875 (goto-char start)
9876 (insert ": ")
9877 (goto-char start)
9878 (setq label (vhdl-template-field "[label]" nil t))
9879 (unless label (delete-char 2))
9880 (forward-word-strictly 1)
9881 (forward-char 1))
9882 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9883 (insert "\n")
9884 (vhdl-template-begin-end "PROCEDURAL" label margin)
9885 (vhdl-comment-block)))
9887 (defun vhdl-template-procedure (&optional kind)
9888 "Insert a procedure declaration or body."
9889 (interactive)
9890 (let ((margin (current-indentation))
9891 (start (point))
9892 name)
9893 (vhdl-insert-keyword "PROCEDURE ")
9894 (when (setq name (vhdl-template-field "name" nil t start (point)))
9895 (vhdl-template-argument-list)
9896 (if (if kind (eq kind 'body)
9897 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9898 (progn (vhdl-insert-keyword " IS")
9899 (when vhdl-auto-align
9900 (vhdl-align-region-groups start (point) 1))
9901 (end-of-line) (insert "\n")
9902 (vhdl-template-begin-end
9903 (unless (vhdl-standard-p '87) "PROCEDURE")
9904 name margin)
9905 (vhdl-comment-block))
9906 (insert ";")
9907 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9908 (end-of-line)))))
9910 (defun vhdl-template-procedure-decl ()
9911 "Insert a procedure declaration."
9912 (interactive)
9913 (vhdl-template-procedure 'decl))
9915 (defun vhdl-template-procedure-body ()
9916 "Insert a procedure body."
9917 (interactive)
9918 (vhdl-template-procedure 'body))
9920 (defun vhdl-template-process (&optional kind)
9921 "Insert a process."
9922 (interactive)
9923 (let ((margin (current-indentation))
9924 (start (point))
9925 (reset-kind vhdl-reset-kind)
9926 label seq input-signals clock reset final-pos)
9927 (setq seq (if kind (eq kind 'seq)
9928 (eq (vhdl-decision-query
9929 "process" "(c)ombinational or (s)equential?" t) ?s)))
9930 (vhdl-insert-keyword "PROCESS ")
9931 (when (memq vhdl-optional-labels '(process all))
9932 (goto-char start)
9933 (insert ": ")
9934 (goto-char start)
9935 (setq label (vhdl-template-field "[label]" nil t))
9936 (unless label (delete-char 2))
9937 (forward-word-strictly 1)
9938 (forward-char 1))
9939 (insert "(")
9940 (if (not seq)
9941 (unless (or (and (vhdl-standard-p '08) vhdl-sensitivity-list-all
9942 (progn (insert "all)") (setq input-signals "all")))
9943 (setq input-signals
9944 (vhdl-template-field "[sensitivity list]" ")" t)))
9945 (setq input-signals "")
9946 (delete-char -2))
9947 (setq clock (or (and (not (equal "" vhdl-clock-name))
9948 (progn (insert vhdl-clock-name) vhdl-clock-name))
9949 (vhdl-template-field "clock name") "<clock>"))
9950 (when (eq reset-kind 'query)
9951 (setq reset-kind
9952 (if (eq (vhdl-decision-query
9953 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9954 'async
9955 'sync)))
9956 (when (eq reset-kind 'async)
9957 (insert ", ")
9958 (setq reset (or (and (not (equal "" vhdl-reset-name))
9959 (progn (insert vhdl-reset-name) vhdl-reset-name))
9960 (vhdl-template-field "reset name") "<reset>")))
9961 (insert ")"))
9962 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9963 (insert "\n")
9964 (vhdl-template-begin-end "PROCESS" label margin)
9965 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9966 (when vhdl-prompt-for-comments
9967 (setq final-pos (point-marker))
9968 (vhdl-prepare-search-2
9969 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9970 (vhdl-re-search-backward "\\<process\\>" nil t))
9971 (end-of-line -0)
9972 (if (bobp)
9973 (progn (insert "\n") (forward-line -1))
9974 (insert "\n"))
9975 (indent-to margin)
9976 (insert "-- purpose: ")
9977 (if (not (vhdl-template-field "[description]" nil t))
9978 (vhdl-line-kill-entire)
9979 (insert "\n")
9980 (indent-to margin)
9981 (insert "-- type : ")
9982 (insert (if seq "sequential" "combinational") "\n")
9983 (indent-to margin)
9984 (insert "-- inputs : ")
9985 (if (not seq)
9986 (insert input-signals)
9987 (insert clock ", ")
9988 (when reset (insert reset ", "))
9989 (unless (vhdl-template-field "[signal names]" nil t)
9990 (delete-char -2)))
9991 (insert "\n")
9992 (indent-to margin)
9993 (insert "-- outputs: ")
9994 (vhdl-template-field "[signal names]" nil t))))
9995 (goto-char final-pos))))
9997 (defun vhdl-template-process-comb ()
9998 "Insert a combinational process."
9999 (interactive)
10000 (vhdl-template-process 'comb))
10002 (defun vhdl-template-process-seq ()
10003 "Insert a sequential process."
10004 (interactive)
10005 (vhdl-template-process 'seq))
10007 (defun vhdl-template-quantity ()
10008 "Insert a quantity declaration."
10009 (interactive)
10010 (if (vhdl-in-argument-list-p)
10011 (let ((start (point)))
10012 (vhdl-insert-keyword "QUANTITY ")
10013 (when (vhdl-template-field "names" nil t start (point))
10014 (insert " : ")
10015 (vhdl-template-field "[IN | OUT]" " " t)
10016 (vhdl-template-field "type")
10017 (insert ";")
10018 (vhdl-comment-insert-inline)))
10019 (let ((char (vhdl-decision-query
10020 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
10021 (cond ((eq char ?f) (vhdl-template-quantity-free))
10022 ((eq char ?b) (vhdl-template-quantity-branch))
10023 ((eq char ?s) (vhdl-template-quantity-source))
10024 (t (vhdl-template-undo (point) (point)))))))
10026 (defun vhdl-template-quantity-free ()
10027 "Insert a free quantity declaration."
10028 (interactive)
10029 (vhdl-insert-keyword "QUANTITY ")
10030 (vhdl-template-field "names")
10031 (insert " : ")
10032 (vhdl-template-field "type")
10033 (let ((position (point)))
10034 (insert " := ")
10035 (unless (vhdl-template-field "[initialization]" nil t)
10036 (delete-region position (point)))
10037 (insert ";")
10038 (vhdl-comment-insert-inline)))
10040 (defun vhdl-template-quantity-branch ()
10041 "Insert a branch quantity declaration."
10042 (interactive)
10043 (let (position)
10044 (vhdl-insert-keyword "QUANTITY ")
10045 (when (vhdl-template-field "[across names]" " " t)
10046 (vhdl-insert-keyword "ACROSS "))
10047 (when (vhdl-template-field "[through names]" " " t)
10048 (vhdl-insert-keyword "THROUGH "))
10049 (vhdl-template-field "plus terminal name")
10050 (setq position (point))
10051 (vhdl-insert-keyword " TO ")
10052 (unless (vhdl-template-field "[minus terminal name]" nil t)
10053 (delete-region position (point)))
10054 (insert ";")
10055 (vhdl-comment-insert-inline)))
10057 (defun vhdl-template-quantity-source ()
10058 "Insert a source quantity declaration."
10059 (interactive)
10060 (vhdl-insert-keyword "QUANTITY ")
10061 (vhdl-template-field "names")
10062 (insert " : ")
10063 (vhdl-template-field "type" " ")
10064 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
10065 (progn (vhdl-insert-keyword "NOISE ")
10066 (vhdl-template-field "power expression"))
10067 (vhdl-insert-keyword "SPECTRUM ")
10068 (vhdl-template-field "magnitude expression" ", ")
10069 (vhdl-template-field "phase expression"))
10070 (insert ";")
10071 (vhdl-comment-insert-inline))
10073 (defun vhdl-template-record (kind &optional name secondary)
10074 "Insert a record type declaration."
10075 (interactive)
10076 (let ((margin (current-indentation))
10077 (start (point))
10078 (first t))
10079 (vhdl-insert-keyword "RECORD\n")
10080 (indent-to (+ margin vhdl-basic-offset))
10081 (when (or (vhdl-template-field "element names"
10082 nil (not secondary) start (point))
10083 secondary)
10084 (while (or first (vhdl-template-field "[element names]" nil t))
10085 (insert " : ")
10086 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
10087 (vhdl-comment-insert-inline)
10088 (insert "\n")
10089 (indent-to (+ margin vhdl-basic-offset))
10090 (setq first nil))
10091 (delete-region (line-beginning-position) (point))
10092 (indent-to margin)
10093 (vhdl-insert-keyword "END RECORD")
10094 (unless (vhdl-standard-p '87) (and name (insert " " name)))
10095 (insert ";")
10096 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10098 (defun vhdl-template-report ()
10099 "Insert a report statement."
10100 (interactive)
10101 (let ((start (point)))
10102 (vhdl-insert-keyword "REPORT ")
10103 (if (equal "\"\"" (vhdl-template-field
10104 "string expression" nil t start (point) t))
10105 (delete-char -2)
10106 (setq start (point))
10107 (vhdl-insert-keyword " SEVERITY ")
10108 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
10109 (delete-region start (point)))
10110 (insert ";"))))
10112 (defun vhdl-template-return ()
10113 "Insert a return statement."
10114 (interactive)
10115 (let ((start (point)))
10116 (vhdl-insert-keyword "RETURN ")
10117 (unless (vhdl-template-field "[expression]" nil t start (point))
10118 (delete-char -1))
10119 (insert ";")))
10121 (defun vhdl-template-selected-signal-asst ()
10122 "Insert a selected signal assignment."
10123 (interactive)
10124 (let ((margin (current-indentation))
10125 (start (point))
10126 (choices t))
10127 (let ((position (point)))
10128 (vhdl-insert-keyword " SELECT ")
10129 (goto-char position))
10130 (vhdl-insert-keyword "WITH ")
10131 (when (vhdl-template-field "selector expression"
10132 nil t start (+ (point) 7))
10133 (forward-word-strictly 1)
10134 (delete-char 1)
10135 (insert "\n")
10136 (indent-to (+ margin vhdl-basic-offset))
10137 (vhdl-template-field "target signal" " <= ")
10138 (insert "\n")
10139 (indent-to (+ margin vhdl-basic-offset))
10140 (vhdl-template-field "waveform")
10141 (vhdl-insert-keyword " WHEN ")
10142 (vhdl-template-field "choices" ",")
10143 (insert "\n")
10144 (indent-to (+ margin vhdl-basic-offset))
10145 (while (and choices (vhdl-template-field "[waveform]" nil t))
10146 (vhdl-insert-keyword " WHEN ")
10147 (if (setq choices (vhdl-template-field "[choices]" "," t))
10148 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10149 (vhdl-insert-keyword "OTHERS")))
10150 (when choices
10151 (fixup-whitespace)
10152 (delete-char -2))
10153 (insert ";")
10154 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10156 (defun vhdl-template-signal ()
10157 "Insert a signal declaration."
10158 (interactive)
10159 (let ((start (point))
10160 (in-arglist (vhdl-in-argument-list-p)))
10161 (vhdl-insert-keyword "SIGNAL ")
10162 (when (vhdl-template-field "names" nil t start (point))
10163 (insert " : ")
10164 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10165 (vhdl-template-field "type")
10166 (if in-arglist
10167 (progn (insert ";")
10168 (vhdl-comment-insert-inline))
10169 (let ((position (point)))
10170 (insert " := ")
10171 (unless (vhdl-template-field "[initialization]" nil t)
10172 (delete-region position (point)))
10173 (insert ";")
10174 (vhdl-comment-insert-inline))))))
10176 (defun vhdl-template-subnature ()
10177 "Insert a subnature declaration."
10178 (interactive)
10179 (let ((start (point))
10180 position)
10181 (vhdl-insert-keyword "SUBNATURE ")
10182 (when (vhdl-template-field "name" nil t start (point))
10183 (vhdl-insert-keyword " IS ")
10184 (vhdl-template-field "nature" " (")
10185 (if (vhdl-template-field "[index range]" nil t)
10186 (insert ")")
10187 (delete-char -2))
10188 (setq position (point))
10189 (vhdl-insert-keyword " TOLERANCE ")
10190 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10191 nil t nil nil t))
10192 (delete-region position (point))
10193 (vhdl-insert-keyword " ACROSS ")
10194 (vhdl-template-field "string expression" nil nil nil nil t)
10195 (vhdl-insert-keyword " THROUGH"))
10196 (insert ";")
10197 (vhdl-comment-insert-inline))))
10199 (defun vhdl-template-subprogram-body ()
10200 "Insert a subprogram body."
10201 (interactive)
10202 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10203 (vhdl-template-function-body)
10204 (vhdl-template-procedure-body)))
10206 (defun vhdl-template-subprogram-decl ()
10207 "Insert a subprogram declaration."
10208 (interactive)
10209 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10210 (vhdl-template-function-decl)
10211 (vhdl-template-procedure-decl)))
10213 (defun vhdl-template-subtype ()
10214 "Insert a subtype declaration."
10215 (interactive)
10216 (let ((start (point)))
10217 (vhdl-insert-keyword "SUBTYPE ")
10218 (when (vhdl-template-field "name" nil t start (point))
10219 (vhdl-insert-keyword " IS ")
10220 (vhdl-template-field "type" " ")
10221 (unless
10222 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
10223 (delete-char -1))
10224 (insert ";")
10225 (vhdl-comment-insert-inline))))
10227 (defun vhdl-template-terminal ()
10228 "Insert a terminal declaration."
10229 (interactive)
10230 (let ((start (point)))
10231 (vhdl-insert-keyword "TERMINAL ")
10232 (when (vhdl-template-field "names" nil t start (point))
10233 (insert " : ")
10234 (vhdl-template-field "nature")
10235 (insert ";")
10236 (vhdl-comment-insert-inline))))
10238 (defun vhdl-template-type ()
10239 "Insert a type declaration."
10240 (interactive)
10241 (let ((start (point))
10242 name mid-pos end-pos)
10243 (vhdl-insert-keyword "TYPE ")
10244 (when (setq name (vhdl-template-field "name" nil t start (point)))
10245 (vhdl-insert-keyword " IS ")
10246 (let ((definition
10247 (upcase
10248 (or (vhdl-template-field
10249 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
10250 ""))))
10251 (cond ((equal definition "")
10252 (delete-char -4)
10253 (insert ";"))
10254 ((equal definition "ARRAY")
10255 (delete-region (point) (progn (forward-word-strictly -1)
10256 (point)))
10257 (vhdl-template-array 'type t))
10258 ((equal definition "RECORD")
10259 (setq mid-pos (point-marker))
10260 (delete-region (point) (progn (forward-word-strictly -1)
10261 (point)))
10262 (vhdl-template-record 'type name t))
10263 ((equal definition "ACCESS")
10264 (insert " ")
10265 (vhdl-template-field "type" ";"))
10266 ((equal definition "FILE")
10267 (vhdl-insert-keyword " OF ")
10268 (vhdl-template-field "type" ";"))
10269 ((equal definition "ENUM")
10270 (kill-word -1)
10271 (insert "(")
10272 (setq end-pos (point-marker))
10273 (insert ");"))
10274 (t (insert ";")))
10275 (when mid-pos
10276 (setq end-pos (point-marker))
10277 (goto-char mid-pos)
10278 (end-of-line))
10279 (vhdl-comment-insert-inline)
10280 (when end-pos (goto-char end-pos))))))
10282 (defun vhdl-template-use ()
10283 "Insert a use clause."
10284 (interactive)
10285 (let ((start (point)))
10286 (vhdl-prepare-search-1
10287 (vhdl-insert-keyword "USE ")
10288 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10289 (vhdl-insert-keyword "..ALL;")
10290 (backward-char 6)
10291 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
10292 (forward-char 1)
10293 (vhdl-template-field "package name")
10294 (forward-char 5))))))
10296 (defun vhdl-template-variable ()
10297 "Insert a variable declaration."
10298 (interactive)
10299 (let ((start (point))
10300 (in-arglist (vhdl-in-argument-list-p)))
10301 (vhdl-prepare-search-2
10302 (if (or (save-excursion
10303 (progn (vhdl-beginning-of-block)
10304 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10305 (save-excursion (backward-word-strictly 1)
10306 (looking-at "\\<shared\\>")))
10307 (vhdl-insert-keyword "VARIABLE ")
10308 (if (vhdl-standard-p '87)
10309 (error "ERROR: Not within sequential block")
10310 (vhdl-insert-keyword "SHARED VARIABLE "))))
10311 (when (vhdl-template-field "names" nil t start (point))
10312 (insert " : ")
10313 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10314 (vhdl-template-field "type")
10315 (if in-arglist
10316 (progn (insert ";")
10317 (vhdl-comment-insert-inline))
10318 (let ((position (point)))
10319 (insert " := ")
10320 (unless (vhdl-template-field "[initialization]" nil t)
10321 (delete-region position (point)))
10322 (insert ";")
10323 (vhdl-comment-insert-inline))))))
10325 (defun vhdl-template-wait ()
10326 "Insert a wait statement."
10327 (interactive)
10328 (vhdl-insert-keyword "WAIT ")
10329 (unless (vhdl-template-field
10330 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10331 nil t)
10332 (delete-char -1))
10333 (insert ";"))
10335 (defun vhdl-template-when ()
10336 "Indent correctly if within a case statement."
10337 (interactive)
10338 (let ((position (point))
10339 margin)
10340 (vhdl-prepare-search-2
10341 (if (and (= (current-column) (current-indentation))
10342 (vhdl-re-search-forward "\\<end\\>" nil t)
10343 (looking-at "\\s-*\\<case\\>"))
10344 (progn
10345 (setq margin (current-indentation))
10346 (goto-char position)
10347 (delete-horizontal-space)
10348 (indent-to (+ margin vhdl-basic-offset)))
10349 (goto-char position)))
10350 (vhdl-insert-keyword "WHEN ")))
10352 (defun vhdl-template-while-loop ()
10353 "Insert a while loop."
10354 (interactive)
10355 (let* ((margin (current-indentation))
10356 (start (point))
10357 label)
10358 (if (not (eq vhdl-optional-labels 'all))
10359 (vhdl-insert-keyword "WHILE ")
10360 (vhdl-insert-keyword ": WHILE ")
10361 (goto-char start)
10362 (setq label (vhdl-template-field "[label]" nil t))
10363 (unless label (delete-char 2))
10364 (forward-word-strictly 1)
10365 (forward-char 1))
10366 (when vhdl-conditions-in-parenthesis (insert "("))
10367 (when (vhdl-template-field "condition" nil t start (point))
10368 (when vhdl-conditions-in-parenthesis (insert ")"))
10369 (vhdl-insert-keyword " LOOP\n\n")
10370 (indent-to margin)
10371 (vhdl-insert-keyword "END LOOP")
10372 (insert (if label (concat " " label ";") ";"))
10373 (forward-line -1)
10374 (indent-to (+ margin vhdl-basic-offset)))))
10376 (defun vhdl-template-with ()
10377 "Insert a with statement (i.e. selected signal assignment)."
10378 (interactive)
10379 (vhdl-prepare-search-1
10380 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10381 (equal ";" (match-string 1)))
10382 (vhdl-template-selected-signal-asst)
10383 (vhdl-insert-keyword "WITH "))))
10385 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10386 ;; Special templates
10388 (defun vhdl-template-clocked-wait ()
10389 "Insert a wait statement for rising/falling clock edge."
10390 (interactive)
10391 (let ((start (point))
10392 clock)
10393 (vhdl-insert-keyword "WAIT UNTIL ")
10394 (when (setq clock
10395 (or (and (not (equal "" vhdl-clock-name))
10396 (progn (insert vhdl-clock-name) vhdl-clock-name))
10397 (vhdl-template-field "clock name" nil t start (point))))
10398 (insert "'event")
10399 (vhdl-insert-keyword " AND ")
10400 (insert clock)
10401 (insert
10402 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10403 (vhdl-comment-insert-inline
10404 (concat (if vhdl-clock-rising-edge "rising" "falling")
10405 " clock edge")))))
10407 (defun vhdl-template-seq-process (clock reset reset-kind)
10408 "Insert a template for the body of a sequential process."
10409 (let ((margin (current-indentation))
10410 position)
10411 (vhdl-insert-keyword "IF ")
10412 (when vhdl-conditions-in-parenthesis (insert "("))
10413 (when (eq reset-kind 'async)
10414 (insert reset " = "
10415 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10416 (when vhdl-conditions-in-parenthesis (insert ")"))
10417 (vhdl-insert-keyword " THEN")
10418 (vhdl-comment-insert-inline
10419 (concat "asynchronous reset (active "
10420 (if vhdl-reset-active-high "high" "low") ")"))
10421 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10422 (setq position (point))
10423 (insert "\n") (indent-to margin)
10424 (vhdl-insert-keyword "ELSIF ")
10425 (when vhdl-conditions-in-parenthesis (insert "(")))
10426 (if (eq vhdl-clock-edge-condition 'function)
10427 (insert (if vhdl-clock-rising-edge "rising" "falling")
10428 "_edge(" clock ")")
10429 (insert clock "'event")
10430 (vhdl-insert-keyword " AND ")
10431 (insert clock " = "
10432 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10433 (when vhdl-conditions-in-parenthesis (insert ")"))
10434 (vhdl-insert-keyword " THEN")
10435 (vhdl-comment-insert-inline
10436 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10437 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10438 (when (eq reset-kind 'sync)
10439 (vhdl-insert-keyword "IF ")
10440 (when vhdl-conditions-in-parenthesis (insert "("))
10441 (setq reset (or (and (not (equal "" vhdl-reset-name))
10442 (progn (insert vhdl-reset-name) vhdl-reset-name))
10443 (vhdl-template-field "reset name") "<reset>"))
10444 (insert " = "
10445 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10446 (when vhdl-conditions-in-parenthesis (insert ")"))
10447 (vhdl-insert-keyword " THEN")
10448 (vhdl-comment-insert-inline
10449 (concat "synchronous reset (active "
10450 (if vhdl-reset-active-high "high" "low") ")"))
10451 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10452 (setq position (point))
10453 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10454 (vhdl-insert-keyword "ELSE")
10455 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10456 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10457 (vhdl-insert-keyword "END IF;"))
10458 (when (eq reset-kind 'none)
10459 (setq position (point)))
10460 (insert "\n") (indent-to margin)
10461 (vhdl-insert-keyword "END IF;")
10462 (goto-char position)
10463 reset))
10465 (defun vhdl-template-standard-package (library package)
10466 "Insert specification of a standard package. Include a library
10467 specification, if not already there."
10468 (let ((margin (current-indentation)))
10469 (unless (equal library "std")
10470 (unless (or (save-excursion
10471 (vhdl-prepare-search-1
10472 (and (not (bobp))
10473 (re-search-backward
10474 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10475 library "\\|end\\)\\>") nil t)
10476 (match-string 2))))
10477 (equal (downcase library) "work"))
10478 (vhdl-insert-keyword "LIBRARY ")
10479 (insert library ";")
10480 (when package
10481 (insert "\n")
10482 (indent-to margin))))
10483 (when package
10484 (vhdl-insert-keyword "USE ")
10485 (insert library "." package)
10486 (vhdl-insert-keyword ".ALL;"))))
10488 (defun vhdl-template-package-numeric-bit ()
10489 "Insert specification of `numeric_bit' package."
10490 (interactive)
10491 (vhdl-template-standard-package "ieee" "numeric_bit"))
10493 (defun vhdl-template-package-numeric-std ()
10494 "Insert specification of `numeric_std' package."
10495 (interactive)
10496 (vhdl-template-standard-package "ieee" "numeric_std"))
10498 (defun vhdl-template-package-std-logic-1164 ()
10499 "Insert specification of `std_logic_1164' package."
10500 (interactive)
10501 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10503 (defun vhdl-template-package-std-logic-arith ()
10504 "Insert specification of `std_logic_arith' package."
10505 (interactive)
10506 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10508 (defun vhdl-template-package-std-logic-misc ()
10509 "Insert specification of `std_logic_misc' package."
10510 (interactive)
10511 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10513 (defun vhdl-template-package-std-logic-signed ()
10514 "Insert specification of `std_logic_signed' package."
10515 (interactive)
10516 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10518 (defun vhdl-template-package-std-logic-textio ()
10519 "Insert specification of `std_logic_textio' package."
10520 (interactive)
10521 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10523 (defun vhdl-template-package-std-logic-unsigned ()
10524 "Insert specification of `std_logic_unsigned' package."
10525 (interactive)
10526 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10528 (defun vhdl-template-package-textio ()
10529 "Insert specification of `textio' package."
10530 (interactive)
10531 (vhdl-template-standard-package "std" "textio"))
10533 (defun vhdl-template-package-fundamental-constants ()
10534 "Insert specification of `fundamental_constants' package."
10535 (interactive)
10536 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10538 (defun vhdl-template-package-material-constants ()
10539 "Insert specification of `material_constants' package."
10540 (interactive)
10541 (vhdl-template-standard-package "ieee" "material_constants"))
10543 (defun vhdl-template-package-energy-systems ()
10544 "Insert specification of `energy_systems' package."
10545 (interactive)
10546 (vhdl-template-standard-package "ieee" "energy_systems"))
10548 (defun vhdl-template-package-electrical-systems ()
10549 "Insert specification of `electrical_systems' package."
10550 (interactive)
10551 (vhdl-template-standard-package "ieee" "electrical_systems"))
10553 (defun vhdl-template-package-mechanical-systems ()
10554 "Insert specification of `mechanical_systems' package."
10555 (interactive)
10556 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10558 (defun vhdl-template-package-radiant-systems ()
10559 "Insert specification of `radiant_systems' package."
10560 (interactive)
10561 (vhdl-template-standard-package "ieee" "radiant_systems"))
10563 (defun vhdl-template-package-thermal-systems ()
10564 "Insert specification of `thermal_systems' package."
10565 (interactive)
10566 (vhdl-template-standard-package "ieee" "thermal_systems"))
10568 (defun vhdl-template-package-fluidic-systems ()
10569 "Insert specification of `fluidic_systems' package."
10570 (interactive)
10571 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10573 (defun vhdl-template-package-math-complex ()
10574 "Insert specification of `math_complex' package."
10575 (interactive)
10576 (vhdl-template-standard-package "ieee" "math_complex"))
10578 (defun vhdl-template-package-math-real ()
10579 "Insert specification of `math_real' package."
10580 (interactive)
10581 (vhdl-template-standard-package "ieee" "math_real"))
10583 (defun vhdl-template-directive (directive)
10584 "Insert directive."
10585 (unless (= (current-indentation) (current-column))
10586 (delete-horizontal-space)
10587 (insert " "))
10588 (insert "-- pragma " directive))
10590 (defun vhdl-template-directive-translate-on ()
10591 "Insert directive `translate_on'."
10592 (interactive)
10593 (vhdl-template-directive "translate_on"))
10595 (defun vhdl-template-directive-translate-off ()
10596 "Insert directive `translate_off'."
10597 (interactive)
10598 (vhdl-template-directive "translate_off"))
10600 (defun vhdl-template-directive-synthesis-on ()
10601 "Insert directive `synthesis_on'."
10602 (interactive)
10603 (vhdl-template-directive "synthesis_on"))
10605 (defun vhdl-template-directive-synthesis-off ()
10606 "Insert directive `synthesis_off'."
10607 (interactive)
10608 (vhdl-template-directive "synthesis_off"))
10610 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10611 ;; Header and footer templates
10613 (defun vhdl-template-header (&optional file-title)
10614 "Insert a VHDL file header."
10615 (interactive)
10616 (unless (equal vhdl-file-header "")
10617 (let (pos)
10618 (save-excursion
10619 (goto-char (point-min))
10620 (vhdl-insert-string-or-file vhdl-file-header)
10621 (setq pos (point-marker)))
10622 (vhdl-template-replace-header-keywords
10623 (point-min-marker) pos file-title))))
10625 (defun vhdl-template-footer ()
10626 "Insert a VHDL file footer."
10627 (interactive)
10628 (unless (equal vhdl-file-footer "")
10629 (let (pos)
10630 (save-excursion
10631 (goto-char (point-max))
10632 (setq pos (point-marker))
10633 (vhdl-insert-string-or-file vhdl-file-footer)
10634 (unless (= (preceding-char) ?\n)
10635 (insert "\n")))
10636 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10638 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10639 is-model)
10640 "Replace keywords in header and footer."
10641 (let ((project-title (or (nth 0 (vhdl-aget vhdl-project-alist vhdl-project))
10642 ""))
10643 (project-desc (or (nth 9 (vhdl-aget vhdl-project-alist vhdl-project))
10644 ""))
10645 pos)
10646 (vhdl-prepare-search-2
10647 (save-excursion
10648 (goto-char beg)
10649 (while (search-forward "<projectdesc>" end t)
10650 (replace-match project-desc t t))
10651 (goto-char beg)
10652 (while (search-forward "<filename>" end t)
10653 (replace-match (buffer-name) t t))
10654 (goto-char beg)
10655 (while (search-forward "<copyright>" end t)
10656 (replace-match vhdl-copyright-string t t))
10657 (goto-char beg)
10658 (while (search-forward "<author>" end t)
10659 (replace-match "" t t)
10660 (insert (user-full-name))
10661 (when user-mail-address (insert " <" user-mail-address ">")))
10662 (goto-char beg)
10663 (while (search-forward "<authorfull>" end t)
10664 (replace-match (user-full-name) t t))
10665 (goto-char beg)
10666 (while (search-forward "<login>" end t)
10667 (replace-match (user-login-name) t t))
10668 (goto-char beg)
10669 (while (search-forward "<project>" end t)
10670 (replace-match project-title t t))
10671 (goto-char beg)
10672 (while (search-forward "<company>" end t)
10673 (replace-match vhdl-company-name t t))
10674 (goto-char beg)
10675 (while (search-forward "<platform>" end t)
10676 (replace-match vhdl-platform-spec t t))
10677 (goto-char beg)
10678 (while (search-forward "<standard>" end t)
10679 (replace-match
10680 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10681 ((vhdl-standard-p '93) "'93/02")
10682 ((vhdl-standard-p '08) "'08"))
10683 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10684 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10685 (goto-char beg)
10686 ;; Replace <RCS> with $, so that RCS for the source is
10687 ;; not over-enthusiastic with replacements
10688 (while (search-forward "<RCS>" end t)
10689 (replace-match "$" nil t))
10690 (goto-char beg)
10691 (while (search-forward "<date>" end t)
10692 (replace-match "" t t)
10693 (vhdl-template-insert-date))
10694 (goto-char beg)
10695 (while (search-forward "<year>" end t)
10696 (replace-match (format-time-string "%Y" nil) t t))
10697 (goto-char beg)
10698 (when file-title
10699 (while (search-forward "<title string>" end t)
10700 (replace-match file-title t t))
10701 (goto-char beg))
10702 (let (string)
10703 (while (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10704 (save-match-data
10705 (setq string (read-string (concat (match-string 1) ": "))))
10706 (replace-match string t t)))
10707 (goto-char beg)
10708 (when (and (not is-model) (search-forward "<cursor>" end t))
10709 (replace-match "" t t)
10710 (setq pos (point))))
10711 (when pos (goto-char pos))
10712 (unless is-model
10713 (when (or (not project-title) (equal project-title ""))
10714 (message "You can specify a project title in user option `vhdl-project-alist'"))
10715 (when (or (not project-desc) (equal project-desc ""))
10716 (message "You can specify a project description in user option `vhdl-project-alist'"))
10717 (when (equal vhdl-platform-spec "")
10718 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10719 (when (equal vhdl-company-name "")
10720 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10722 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10723 ;; Comment templates and functions
10725 (defun vhdl-comment-indent ()
10726 "Indent comments."
10727 (let* ((position (point))
10728 (col
10729 (progn
10730 (forward-line -1)
10731 (if (re-search-forward "--" position t)
10732 (- (current-column) 2) ; existing comment at bol stays there
10733 (goto-char position)
10734 (skip-chars-backward " \t")
10735 (max comment-column ; else indent to comment column
10736 (1+ (current-column))))))) ; except leave at least one space
10737 (goto-char position)
10738 col))
10740 (defun vhdl-comment-insert ()
10741 "Start a comment at the end of the line.
10742 If on line with code, indent at least `comment-column'.
10743 If starting after end-comment-column, start a new line."
10744 (interactive)
10745 (when (> (current-column) end-comment-column) (newline-and-indent))
10746 (if (or (looking-at "\\s-*$") ; end of line
10747 (and (not unread-command-events) ; called with key binding or menu
10748 (not (end-of-line))))
10749 (let (margin)
10750 (while (= (preceding-char) ?-) (delete-char -1))
10751 (setq margin (current-column))
10752 (delete-horizontal-space)
10753 (if (bolp)
10754 (progn (indent-to margin) (insert "--"))
10755 (insert " ")
10756 (indent-to comment-column)
10757 (insert "--"))
10758 (if (not unread-command-events) (insert " ")))
10759 ;; else code following current point implies commenting out code
10760 (let (next-input code)
10761 (while (= (preceding-char) ?-) (delete-char -2))
10762 (while (= (setq next-input (read-char)) 13) ; CR
10763 (insert "--") ; or have a space after it?
10764 (forward-char -2)
10765 (forward-line 1)
10766 (message "Enter CR if commenting out a line of code.")
10767 (setq code t))
10768 (unless code
10769 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10770 (push (vhdl-character-to-event next-input) ; pushback the char
10771 unread-command-events))))
10773 (defun vhdl-comment-display (&optional line-exists)
10774 "Add 2 comment lines at the current indent, making a display comment."
10775 (interactive)
10776 (let ((margin (current-indentation)))
10777 (unless line-exists (vhdl-comment-display-line))
10778 (insert "\n") (indent-to margin)
10779 (insert "\n") (indent-to margin)
10780 (vhdl-comment-display-line)
10781 (end-of-line -0)
10782 (insert "-- ")))
10784 (defun vhdl-comment-display-line ()
10785 "Displays one line of dashes."
10786 (interactive)
10787 (while (= (preceding-char) ?-) (delete-char -2))
10788 (insert "--")
10789 (let* ((col (current-column))
10790 (len (- end-comment-column col)))
10791 (insert-char vhdl-comment-display-line-char len)))
10793 (defun vhdl-comment-append-inline ()
10794 "Append empty inline comment to current line."
10795 (interactive)
10796 (end-of-line)
10797 (delete-horizontal-space)
10798 (insert " ")
10799 (indent-to comment-column)
10800 (insert "-- "))
10802 (defun vhdl-comment-insert-inline (&optional string always-insert)
10803 "Insert inline comment."
10804 (when (or (and string (or vhdl-self-insert-comments always-insert))
10805 (and (not string) vhdl-prompt-for-comments))
10806 (let ((position (point)))
10807 (insert " ")
10808 (indent-to comment-column)
10809 (insert "-- ")
10810 (if (not (or (and string (progn (insert string) t))
10811 (vhdl-template-field "[comment]" nil t)))
10812 (delete-region position (point))
10813 (while (= (preceding-char) ?\ ) (delete-char -1))))))
10815 (defun vhdl-comment-block ()
10816 "Insert comment for code block."
10817 (when vhdl-prompt-for-comments
10818 (let ((final-pos (point-marker)))
10819 (vhdl-prepare-search-2
10820 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10821 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10822 (let (margin)
10823 (back-to-indentation)
10824 (setq margin (current-column))
10825 (end-of-line -0)
10826 (if (bobp)
10827 (progn (insert "\n") (forward-line -1))
10828 (insert "\n"))
10829 (indent-to margin)
10830 (insert "-- purpose: ")
10831 (unless (vhdl-template-field "[description]" nil t)
10832 (vhdl-line-kill-entire)))))
10833 (goto-char final-pos))))
10835 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10836 "Comment out region if not commented out, uncomment otherwise."
10837 (interactive "r\nP")
10838 (save-excursion
10839 (goto-char (1- end))
10840 (end-of-line)
10841 (setq end (point-marker))
10842 (goto-char beg)
10843 (beginning-of-line)
10844 (setq beg (point))
10845 (if (looking-at (concat "\\s-*" comment-start))
10846 (comment-region beg end '(4))
10847 (comment-region beg end))))
10849 (defun vhdl-comment-uncomment-line (&optional arg)
10850 "Comment out line if not commented out, uncomment otherwise."
10851 (interactive "p")
10852 (save-excursion
10853 (beginning-of-line)
10854 (let ((position (point)))
10855 (forward-line (or arg 1))
10856 (vhdl-comment-uncomment-region position (point)))))
10858 (defun vhdl-comment-kill-region (beg end)
10859 "Kill comments in region."
10860 (interactive "r")
10861 (save-excursion
10862 (goto-char end)
10863 (setq end (point-marker))
10864 (goto-char beg)
10865 (beginning-of-line)
10866 (while (< (point) end)
10867 (if (looking-at "^\\(\\s-*--.*\n\\)")
10868 (progn (delete-region (match-beginning 1) (match-end 1)))
10869 (beginning-of-line 2)))))
10871 (defun vhdl-comment-kill-inline-region (beg end)
10872 "Kill inline comments in region."
10873 (interactive "r")
10874 (save-excursion
10875 (goto-char end)
10876 (setq end (point-marker))
10877 (goto-char beg)
10878 (beginning-of-line)
10879 (while (< (point) end)
10880 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10881 (delete-region (match-beginning 1) (match-end 1)))
10882 (beginning-of-line 2))))
10884 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10885 ;; Subtemplates
10887 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10888 "Insert a begin ... end pair with optional name after the end.
10889 Point is left between them."
10890 (let (position)
10891 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10892 (indent-to margin)
10893 (vhdl-insert-keyword "BEGIN")
10894 (when (and (or construct name) vhdl-self-insert-comments)
10895 (insert " --")
10896 (when construct (insert " ") (vhdl-insert-keyword construct))
10897 (when name (insert " " name)))
10898 (insert "\n")
10899 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10900 (indent-to (+ margin vhdl-basic-offset))
10901 (setq position (point))
10902 (insert "\n")
10903 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10904 (indent-to margin)
10905 (vhdl-insert-keyword "END")
10906 (when construct (insert " ") (vhdl-insert-keyword construct))
10907 (insert (if name (concat " " name) "") ";")
10908 (goto-char position)))
10910 (defun vhdl-template-argument-list (&optional is-function)
10911 "Read from user a procedure or function argument list."
10912 (insert " (")
10913 (let ((margin (current-column))
10914 (start (point))
10915 (end-pos (point))
10916 not-empty interface semicolon-pos)
10917 (unless vhdl-argument-list-indent
10918 (setq margin (+ (current-indentation) vhdl-basic-offset))
10919 (insert "\n")
10920 (indent-to margin))
10921 (setq interface (vhdl-template-field
10922 (concat "[CONSTANT | SIGNAL"
10923 (unless is-function " | VARIABLE") "]") " " t))
10924 (while (vhdl-template-field "[names]" nil t)
10925 (setq not-empty t)
10926 (insert " : ")
10927 (unless is-function
10928 (if (and interface (equal (upcase interface) "CONSTANT"))
10929 (vhdl-insert-keyword "IN ")
10930 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10931 (vhdl-template-field "type")
10932 (setq semicolon-pos (point))
10933 (insert ";")
10934 (vhdl-comment-insert-inline)
10935 (setq end-pos (point))
10936 (insert "\n")
10937 (indent-to margin)
10938 (setq interface (vhdl-template-field
10939 (concat "[CONSTANT | SIGNAL"
10940 (unless is-function " | VARIABLE") "]") " " t)))
10941 (delete-region end-pos (point))
10942 (when semicolon-pos (goto-char semicolon-pos))
10943 (if not-empty
10944 (progn (delete-char 1) (insert ")"))
10945 (delete-char -2))))
10947 (defun vhdl-template-generic-list (optional &optional no-value)
10948 "Read from user a generic spec argument list."
10949 (let (margin
10950 (start (point)))
10951 (vhdl-insert-keyword "GENERIC (")
10952 (setq margin (current-column))
10953 (unless vhdl-argument-list-indent
10954 (let ((position (point)))
10955 (back-to-indentation)
10956 (setq margin (+ (current-column) vhdl-basic-offset))
10957 (goto-char position)
10958 (insert "\n")
10959 (indent-to margin)))
10960 (let ((vhdl-generics (vhdl-template-field
10961 (concat (and optional "[") "name"
10962 (and no-value "s") (and optional "]"))
10963 nil optional)))
10964 (if (not vhdl-generics)
10965 (if optional
10966 (progn (vhdl-line-kill-entire) (end-of-line -0)
10967 (unless vhdl-argument-list-indent
10968 (vhdl-line-kill-entire) (end-of-line -0)))
10969 (vhdl-template-undo start (point))
10970 nil )
10971 (insert " : ")
10972 (let (semicolon-pos end-pos)
10973 (while vhdl-generics
10974 (vhdl-template-field "type")
10975 (if no-value
10976 (progn (setq semicolon-pos (point))
10977 (insert ";"))
10978 (insert " := ")
10979 (unless (vhdl-template-field "[value]" nil t)
10980 (delete-char -4))
10981 (setq semicolon-pos (point))
10982 (insert ";"))
10983 (vhdl-comment-insert-inline)
10984 (setq end-pos (point))
10985 (insert "\n")
10986 (indent-to margin)
10987 (setq vhdl-generics (vhdl-template-field
10988 (concat "[name" (and no-value "s") "]")
10989 " : " t)))
10990 (delete-region end-pos (point))
10991 (goto-char semicolon-pos)
10992 (insert ")")
10993 (end-of-line)
10994 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10995 t)))))
10997 (defun vhdl-template-port-list (optional)
10998 "Read from user a port spec argument list."
10999 (let ((start (point))
11000 margin vhdl-ports object)
11001 (vhdl-insert-keyword "PORT (")
11002 (setq margin (current-column))
11003 (unless vhdl-argument-list-indent
11004 (let ((position (point)))
11005 (back-to-indentation)
11006 (setq margin (+ (current-column) vhdl-basic-offset))
11007 (goto-char position)
11008 (insert "\n")
11009 (indent-to margin)))
11010 (when (vhdl-standard-p 'ams)
11011 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11012 " " t)))
11013 (setq vhdl-ports (vhdl-template-field
11014 (concat (and optional "[") "names" (and optional "]"))
11015 nil optional))
11016 (if (not vhdl-ports)
11017 (if optional
11018 (progn (vhdl-line-kill-entire) (end-of-line -0)
11019 (unless vhdl-argument-list-indent
11020 (vhdl-line-kill-entire) (end-of-line -0)))
11021 (vhdl-template-undo start (point))
11022 nil)
11023 (insert " : ")
11024 (let (semicolon-pos end-pos)
11025 (while vhdl-ports
11026 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
11027 (vhdl-template-field "IN | OUT | INOUT" " "))
11028 ((equal "QUANTITY" (upcase object))
11029 (vhdl-template-field "[IN | OUT]" " " t)))
11030 (vhdl-template-field
11031 (if (and object (equal "TERMINAL" (upcase object)))
11032 "nature" "type"))
11033 (setq semicolon-pos (point))
11034 (insert ";")
11035 (vhdl-comment-insert-inline)
11036 (setq end-pos (point))
11037 (insert "\n")
11038 (indent-to margin)
11039 (when (vhdl-standard-p 'ams)
11040 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11041 " " t)))
11042 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
11043 (delete-region end-pos (point))
11044 (goto-char semicolon-pos)
11045 (insert ")")
11046 (end-of-line)
11047 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
11048 t))))
11050 (defun vhdl-template-generate-body (margin label)
11051 "Insert body for generate template."
11052 (vhdl-insert-keyword " GENERATE")
11053 (insert "\n\n")
11054 (indent-to margin)
11055 (vhdl-insert-keyword "END GENERATE ")
11056 (insert label ";")
11057 (end-of-line 0)
11058 (indent-to (+ margin vhdl-basic-offset)))
11060 (defun vhdl-template-insert-date ()
11061 "Insert date in appropriate format."
11062 (interactive)
11063 (insert
11064 (cond
11065 ;; 'american, 'european, 'scientific kept for backward compatibility
11066 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
11067 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
11068 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
11069 (t (format-time-string vhdl-date-format nil)))))
11071 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11072 ;; Help functions
11074 (defun vhdl-electric-space (count)
11075 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
11076 if in comment and past end-comment-column."
11077 (interactive "p")
11078 (cond ((vhdl-in-comment-p)
11079 (self-insert-command count)
11080 (cond ((>= (current-column) (+ 2 end-comment-column))
11081 (backward-char 1)
11082 (skip-chars-backward "^ \t\n\r\f")
11083 (indent-new-comment-line)
11084 (skip-chars-forward "^ \t\n\r\f")
11085 (forward-char 1))
11086 ((>= (current-column) end-comment-column)
11087 (indent-new-comment-line))
11088 (t nil)))
11089 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
11090 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
11091 (vhdl-prepare-search-1
11092 (or (expand-abbrev) (vhdl-fix-case-word -1)))
11093 (self-insert-command count))
11094 (t (self-insert-command count))))
11096 (defun vhdl-template-field (prompt &optional follow-string optional
11097 begin end is-string default)
11098 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
11099 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
11100 an empty string is inserted, return nil and call `vhdl-template-undo' for
11101 the region between BEGIN and END. IS-STRING indicates whether a string
11102 with double-quotes is to be inserted. DEFAULT specifies a default string."
11103 (let ((position (point))
11104 string)
11105 (insert "<" prompt ">")
11106 (setq string
11107 (condition-case ()
11108 (read-from-minibuffer (concat prompt ": ")
11109 (or (and is-string '("\"\"" . 2)) default)
11110 vhdl-minibuffer-local-map)
11111 (quit (if (and optional begin end)
11112 (progn (beep) "")
11113 (keyboard-quit)))))
11114 (when (or (not (equal string "")) optional)
11115 (delete-region position (point)))
11116 (when (and (equal string "") optional begin end)
11117 (vhdl-template-undo begin end)
11118 (message "Template aborted"))
11119 (unless (equal string "")
11120 (insert string)
11121 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
11122 vhdl-keywords-regexp)
11123 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
11124 vhdl-types-regexp)
11125 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
11126 (concat "'" vhdl-attributes-regexp))
11127 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
11128 vhdl-enum-values-regexp)
11129 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
11130 vhdl-constants-regexp))
11131 (when (or (not (equal string "")) (not optional))
11132 (insert (or follow-string "")))
11133 (if (equal string "") nil string)))
11135 (defun vhdl-decision-query (string prompt &optional optional)
11136 "Query a decision from the user."
11137 (let ((start (point)))
11138 (when string (vhdl-insert-keyword (concat string " ")))
11139 (message "%s" (or prompt ""))
11140 (let ((char (read-char)))
11141 (delete-region start (point))
11142 (if (and optional (eq char ?\r))
11143 (progn (insert " ")
11144 (unexpand-abbrev)
11145 (throw 'abort "ERROR: Template aborted"))
11146 char))))
11148 (defun vhdl-insert-keyword (keyword)
11149 "Insert KEYWORD and adjust case."
11150 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
11152 (defun vhdl-case-keyword (keyword)
11153 "Adjust case of KEYWORD."
11154 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
11156 (defun vhdl-case-word (num)
11157 "Adjust case of following NUM words."
11158 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
11160 (defun vhdl-minibuffer-tab (&optional prefix-arg)
11161 "If preceding character is part of a word or a paren then hippie-expand,
11162 else insert tab (used for word completion in VHDL minibuffer)."
11163 (interactive "P")
11164 (cond
11165 ;; expand word
11166 ((= (char-syntax (preceding-char)) ?w)
11167 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11168 (case-replace nil)
11169 (hippie-expand-only-buffers
11170 (or (and (boundp 'hippie-expand-only-buffers)
11171 hippie-expand-only-buffers)
11172 '(vhdl-mode))))
11173 (vhdl-expand-abbrev prefix-arg)))
11174 ;; expand parenthesis
11175 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
11176 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11177 (case-replace nil))
11178 (vhdl-expand-paren prefix-arg)))
11179 ;; insert tab
11180 (t (insert-tab))))
11182 (defun vhdl-template-search-prompt ()
11183 "Search for left out template prompts and query again."
11184 (interactive)
11185 (vhdl-prepare-search-2
11186 (when (or (re-search-forward
11187 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
11188 (re-search-backward
11189 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
11190 (let ((string (match-string 1)))
11191 (replace-match "")
11192 (vhdl-template-field string)))))
11194 (defun vhdl-template-undo (begin end)
11195 "Undo aborted template by deleting region and unexpanding the keyword."
11196 (cond (vhdl-template-invoked-by-hook
11197 (goto-char end)
11198 (insert " ")
11199 (delete-region begin end)
11200 (unexpand-abbrev))
11201 (t (delete-region begin end))))
11203 (defun vhdl-insert-string-or-file (string)
11204 "Insert STRING or file contents if STRING is an existing file name."
11205 (unless (equal string "")
11206 (let ((file-name
11207 (progn (string-match "^\\([^\n]+\\)" string)
11208 (vhdl-resolve-env-variable (match-string 1 string)))))
11209 (if (file-exists-p file-name)
11210 (forward-char (cadr (insert-file-contents file-name)))
11211 (insert string)))))
11213 (defun vhdl-beginning-of-block ()
11214 "Move cursor to the beginning of the enclosing block."
11215 (let (pos)
11216 (vhdl-prepare-search-2
11217 (save-excursion
11218 (beginning-of-line)
11219 ;; search backward for block beginning or end
11220 (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))
11221 ;; not consider subprogram declarations
11222 (or (and (match-string 5)
11223 (save-match-data
11224 (save-excursion
11225 (goto-char (match-end 5))
11226 (forward-word-strictly 1)
11227 (vhdl-forward-syntactic-ws)
11228 (when (looking-at "(")
11229 (forward-sexp))
11230 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11231 (match-string 1)))
11232 ;; not consider configuration specifications
11233 (and (match-string 6)
11234 (save-match-data
11235 (save-excursion
11236 (vhdl-end-of-block)
11237 (beginning-of-line)
11238 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11239 (match-string 2))
11240 ;; skip subblock if block end found
11241 (vhdl-beginning-of-block))))
11242 (when pos (goto-char pos))))
11244 (defun vhdl-end-of-block ()
11245 "Move cursor to the end of the enclosing block."
11246 (let (pos)
11247 (vhdl-prepare-search-2
11248 (save-excursion
11249 (end-of-line)
11250 ;; search forward for block beginning or end
11251 (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))
11252 ;; not consider subprogram declarations
11253 (or (and (match-string 5)
11254 (save-match-data
11255 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11256 (match-string 1)))
11257 ;; not consider configuration specifications
11258 (and (match-string 6)
11259 (save-match-data
11260 (save-excursion
11261 (vhdl-end-of-block)
11262 (beginning-of-line)
11263 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11264 (not (match-string 2)))
11265 ;; skip subblock if block beginning found
11266 (vhdl-end-of-block))))
11267 (when pos (goto-char pos))))
11269 (defun vhdl-sequential-statement-p ()
11270 "Check if point is within sequential statement part."
11271 (let ((start (point)))
11272 (save-excursion
11273 (vhdl-prepare-search-2
11274 ;; is sequential statement if ...
11275 (and (re-search-backward "^\\s-*begin\\>" nil t)
11276 ;; ... point is between "begin" and "end" of ...
11277 (progn (vhdl-end-of-block)
11278 (< start (point)))
11279 ;; ... a sequential block
11280 (progn (vhdl-beginning-of-block)
11281 (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\\)\\)\\>")))))))
11283 (defun vhdl-in-argument-list-p ()
11284 "Check if within an argument list."
11285 (save-excursion
11286 (vhdl-prepare-search-2
11287 (or (string-match "arglist"
11288 (format "%s" (caar (vhdl-get-syntactic-context))))
11289 (progn (beginning-of-line)
11290 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11292 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11293 ;; Abbrev hooks
11295 (defun vhdl-hooked-abbrev (func)
11296 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11297 but not if inside a comment or quote."
11298 (if (or (vhdl-in-literal)
11299 (save-excursion
11300 (forward-word-strictly -1)
11301 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11302 (progn
11303 (insert " ")
11304 (unexpand-abbrev)
11305 (backward-word-strictly 1)
11306 (vhdl-case-word 1)
11307 (delete-char 1))
11308 (if (not vhdl-electric-mode)
11309 (progn
11310 (insert " ")
11311 (unexpand-abbrev)
11312 (backward-word-strictly 1)
11313 (vhdl-case-word 1)
11314 (delete-char 1))
11315 (let ((invoke-char vhdl-last-input-event)
11316 (abbrev-mode -1)
11317 (vhdl-template-invoked-by-hook t))
11318 (let ((caught (catch 'abort
11319 (funcall func))))
11320 (when (stringp caught) (message "%s" caught)))
11321 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
11322 ;; delete CR which is still in event queue
11323 (if (fboundp 'enqueue-eval-event)
11324 (enqueue-eval-event 'delete-char -1)
11325 (push (vhdl-character-to-event ?\177) ; push back a delete char
11326 unread-command-events))))))
11328 (defun vhdl-template-alias-hook ()
11329 (vhdl-hooked-abbrev 'vhdl-template-alias))
11330 (defun vhdl-template-architecture-hook ()
11331 (vhdl-hooked-abbrev 'vhdl-template-architecture))
11332 (defun vhdl-template-assert-hook ()
11333 (vhdl-hooked-abbrev 'vhdl-template-assert))
11334 (defun vhdl-template-attribute-hook ()
11335 (vhdl-hooked-abbrev 'vhdl-template-attribute))
11336 (defun vhdl-template-block-hook ()
11337 (vhdl-hooked-abbrev 'vhdl-template-block))
11338 (defun vhdl-template-break-hook ()
11339 (vhdl-hooked-abbrev 'vhdl-template-break))
11340 (defun vhdl-template-case-hook ()
11341 (vhdl-hooked-abbrev 'vhdl-template-case))
11342 (defun vhdl-template-component-hook ()
11343 (vhdl-hooked-abbrev 'vhdl-template-component))
11344 (defun vhdl-template-instance-hook ()
11345 (vhdl-hooked-abbrev 'vhdl-template-instance))
11346 (defun vhdl-template-conditional-signal-asst-hook ()
11347 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
11348 (defun vhdl-template-configuration-hook ()
11349 (vhdl-hooked-abbrev 'vhdl-template-configuration))
11350 (defun vhdl-template-constant-hook ()
11351 (vhdl-hooked-abbrev 'vhdl-template-constant))
11352 (defun vhdl-template-context-hook ()
11353 (vhdl-hooked-abbrev 'vhdl-template-context))
11354 (defun vhdl-template-disconnect-hook ()
11355 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
11356 (defun vhdl-template-display-comment-hook ()
11357 (vhdl-hooked-abbrev 'vhdl-comment-display))
11358 (defun vhdl-template-else-hook ()
11359 (vhdl-hooked-abbrev 'vhdl-template-else))
11360 (defun vhdl-template-elsif-hook ()
11361 (vhdl-hooked-abbrev 'vhdl-template-elsif))
11362 (defun vhdl-template-entity-hook ()
11363 (vhdl-hooked-abbrev 'vhdl-template-entity))
11364 (defun vhdl-template-exit-hook ()
11365 (vhdl-hooked-abbrev 'vhdl-template-exit))
11366 (defun vhdl-template-file-hook ()
11367 (vhdl-hooked-abbrev 'vhdl-template-file))
11368 (defun vhdl-template-for-hook ()
11369 (vhdl-hooked-abbrev 'vhdl-template-for))
11370 (defun vhdl-template-function-hook ()
11371 (vhdl-hooked-abbrev 'vhdl-template-function))
11372 (defun vhdl-template-generic-hook ()
11373 (vhdl-hooked-abbrev 'vhdl-template-generic))
11374 (defun vhdl-template-group-hook ()
11375 (vhdl-hooked-abbrev 'vhdl-template-group))
11376 (defun vhdl-template-library-hook ()
11377 (vhdl-hooked-abbrev 'vhdl-template-library))
11378 (defun vhdl-template-limit-hook ()
11379 (vhdl-hooked-abbrev 'vhdl-template-limit))
11380 (defun vhdl-template-if-hook ()
11381 (vhdl-hooked-abbrev 'vhdl-template-if))
11382 (defun vhdl-template-bare-loop-hook ()
11383 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
11384 (defun vhdl-template-map-hook ()
11385 (vhdl-hooked-abbrev 'vhdl-template-map))
11386 (defun vhdl-template-nature-hook ()
11387 (vhdl-hooked-abbrev 'vhdl-template-nature))
11388 (defun vhdl-template-next-hook ()
11389 (vhdl-hooked-abbrev 'vhdl-template-next))
11390 (defun vhdl-template-others-hook ()
11391 (vhdl-hooked-abbrev 'vhdl-template-others))
11392 (defun vhdl-template-package-hook ()
11393 (vhdl-hooked-abbrev 'vhdl-template-package))
11394 (defun vhdl-template-port-hook ()
11395 (vhdl-hooked-abbrev 'vhdl-template-port))
11396 (defun vhdl-template-procedural-hook ()
11397 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11398 (defun vhdl-template-procedure-hook ()
11399 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11400 (defun vhdl-template-process-hook ()
11401 (vhdl-hooked-abbrev 'vhdl-template-process))
11402 (defun vhdl-template-quantity-hook ()
11403 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11404 (defun vhdl-template-report-hook ()
11405 (vhdl-hooked-abbrev 'vhdl-template-report))
11406 (defun vhdl-template-return-hook ()
11407 (vhdl-hooked-abbrev 'vhdl-template-return))
11408 (defun vhdl-template-selected-signal-asst-hook ()
11409 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11410 (defun vhdl-template-signal-hook ()
11411 (vhdl-hooked-abbrev 'vhdl-template-signal))
11412 (defun vhdl-template-subnature-hook ()
11413 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11414 (defun vhdl-template-subtype-hook ()
11415 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11416 (defun vhdl-template-terminal-hook ()
11417 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11418 (defun vhdl-template-type-hook ()
11419 (vhdl-hooked-abbrev 'vhdl-template-type))
11420 (defun vhdl-template-use-hook ()
11421 (vhdl-hooked-abbrev 'vhdl-template-use))
11422 (defun vhdl-template-variable-hook ()
11423 (vhdl-hooked-abbrev 'vhdl-template-variable))
11424 (defun vhdl-template-wait-hook ()
11425 (vhdl-hooked-abbrev 'vhdl-template-wait))
11426 (defun vhdl-template-when-hook ()
11427 (vhdl-hooked-abbrev 'vhdl-template-when))
11428 (defun vhdl-template-while-loop-hook ()
11429 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11430 (defun vhdl-template-with-hook ()
11431 (vhdl-hooked-abbrev 'vhdl-template-with))
11432 (defun vhdl-template-and-hook ()
11433 (vhdl-hooked-abbrev 'vhdl-template-and))
11434 (defun vhdl-template-or-hook ()
11435 (vhdl-hooked-abbrev 'vhdl-template-or))
11436 (defun vhdl-template-nand-hook ()
11437 (vhdl-hooked-abbrev 'vhdl-template-nand))
11438 (defun vhdl-template-nor-hook ()
11439 (vhdl-hooked-abbrev 'vhdl-template-nor))
11440 (defun vhdl-template-xor-hook ()
11441 (vhdl-hooked-abbrev 'vhdl-template-xor))
11442 (defun vhdl-template-xnor-hook ()
11443 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11444 (defun vhdl-template-not-hook ()
11445 (vhdl-hooked-abbrev 'vhdl-template-not))
11447 (defun vhdl-template-default-hook ()
11448 (vhdl-hooked-abbrev 'vhdl-template-default))
11449 (defun vhdl-template-default-indent-hook ()
11450 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11453 ;; Template insertion from completion list
11455 (defun vhdl-template-insert-construct (name)
11456 "Insert the built-in construct template with NAME."
11457 (interactive
11458 (list (let ((completion-ignore-case t))
11459 (completing-read "Construct name: "
11460 vhdl-template-construct-alist nil t))))
11461 (vhdl-template-insert-fun
11462 (cadr (assoc name vhdl-template-construct-alist))))
11464 (defun vhdl-template-insert-package (name)
11465 "Insert the built-in package template with NAME."
11466 (interactive
11467 (list (let ((completion-ignore-case t))
11468 (completing-read "Package name: "
11469 vhdl-template-package-alist nil t))))
11470 (vhdl-template-insert-fun
11471 (cadr (assoc name vhdl-template-package-alist))))
11473 (defun vhdl-template-insert-directive (name)
11474 "Insert the built-in directive template with NAME."
11475 (interactive
11476 (list (let ((completion-ignore-case t))
11477 (completing-read "Directive name: "
11478 vhdl-template-directive-alist nil t))))
11479 (vhdl-template-insert-fun
11480 (cadr (assoc name vhdl-template-directive-alist))))
11482 (defun vhdl-template-insert-fun (fun)
11483 "Call FUN to insert a built-in template."
11484 (let ((caught (catch 'abort (when fun (funcall fun)))))
11485 (when (stringp caught) (message "%s" caught))))
11488 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11489 ;;; Models
11490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11492 (defun vhdl-model-insert (model-name)
11493 "Insert the user model with name MODEL-NAME."
11494 (interactive
11495 (let ((completion-ignore-case t))
11496 (list (completing-read "Model name: " vhdl-model-alist))))
11497 (indent-according-to-mode)
11498 (let ((start (point-marker))
11499 (margin (current-indentation))
11500 model position prompt string end)
11501 (vhdl-prepare-search-2
11502 (when (setq model (assoc model-name vhdl-model-alist))
11503 ;; insert model
11504 (beginning-of-line)
11505 (delete-horizontal-space)
11506 (goto-char start)
11507 (vhdl-insert-string-or-file (nth 1 model))
11508 (setq end (point-marker))
11509 ;; indent code
11510 (goto-char start)
11511 (beginning-of-line)
11512 (while (< (point) end)
11513 (unless (looking-at "^$")
11514 (insert-char ? margin))
11515 (beginning-of-line 2))
11516 (goto-char start)
11517 ;; insert clock
11518 (unless (equal "" vhdl-clock-name)
11519 (while (re-search-forward "<clock>" end t)
11520 (replace-match vhdl-clock-name)))
11521 (goto-char start)
11522 ;; insert reset
11523 (unless (equal "" vhdl-reset-name)
11524 (while (re-search-forward "<reset>" end t)
11525 (replace-match vhdl-reset-name)))
11526 ;; replace header prompts
11527 (vhdl-template-replace-header-keywords start end nil t)
11528 (goto-char start)
11529 ;; query other prompts
11530 (while (re-search-forward
11531 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11532 (unless (equal "cursor" (match-string 1))
11533 (setq position (match-beginning 1))
11534 (setq prompt (match-string 1))
11535 (replace-match "")
11536 (setq string (vhdl-template-field prompt nil t))
11537 ;; replace occurrences of same prompt
11538 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11539 (replace-match (or string "")))
11540 (goto-char position)))
11541 (goto-char start)
11542 ;; goto final position
11543 (if (re-search-forward "<cursor>" end t)
11544 (replace-match "")
11545 (goto-char end))))))
11547 (defun vhdl-model-defun ()
11548 "Define help and hook functions for user models."
11549 (let ((model-alist vhdl-model-alist)
11550 model-name model-keyword)
11551 (while model-alist
11552 ;; define functions for user models that can be invoked from menu and key
11553 ;; bindings and which themselves call `vhdl-model-insert' with the model
11554 ;; name as argument
11555 (setq model-name (nth 0 (car model-alist)))
11556 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11557 ,(concat "Insert model for \"" model-name "\".")
11558 (interactive)
11559 (vhdl-model-insert ,model-name)))
11560 ;; define hooks for user models that are invoked from keyword abbrevs
11561 (setq model-keyword (nth 3 (car model-alist)))
11562 (unless (equal model-keyword "")
11563 (eval `(defun
11564 ,(vhdl-function-name
11565 "vhdl-model" model-name "hook") ()
11566 (vhdl-hooked-abbrev
11567 ',(vhdl-function-name "vhdl-model" model-name)))))
11568 (setq model-alist (cdr model-alist)))))
11570 (vhdl-model-defun)
11573 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11574 ;;; Port translation
11575 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11577 (defvar vhdl-port-list nil
11578 "Variable to hold last port map parsed.")
11579 ;; structure: (parenthesized expression means list of such entries)
11580 ;; (ent-name
11581 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11582 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11583 ;; (lib-name pack-key))
11585 (defun vhdl-parse-string (string &optional optional)
11586 "Check that the text following point matches the regexp in STRING."
11587 (if (looking-at string)
11588 (progn (goto-char (match-end 0))
11589 (when (vhdl-in-literal)
11590 (end-of-line))
11591 (point))
11592 (unless optional
11593 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11594 (vhdl-current-line) string)))
11595 nil))
11597 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11598 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11599 (vhdl-prepare-search-1
11600 (if (string-match (car regexp-cons) string)
11601 (if adjust-case
11602 (funcall vhdl-file-name-case
11603 (replace-match (cdr regexp-cons) t nil string))
11604 (replace-match (cdr regexp-cons) t nil string))
11605 string)))
11607 (defun vhdl-parse-group-comment ()
11608 "Parse comment and empty lines between groups of lines."
11609 (let ((start (point))
11610 string)
11611 (vhdl-forward-comment (point-max))
11612 (setq string (buffer-substring-no-properties start (point)))
11613 (vhdl-forward-syntactic-ws)
11614 ;; strip off leading blanks and first newline
11615 (while (string-match "^\\(\\s-+\\)" string)
11616 (setq string (concat (substring string 0 (match-beginning 1))
11617 (substring string (match-end 1)))))
11618 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11619 (substring string 1)
11620 string)))
11622 (defun vhdl-paste-group-comment (string indent)
11623 "Paste comment and empty lines from STRING between groups of lines
11624 with INDENT."
11625 (let ((pos (point-marker)))
11626 (when (> indent 0)
11627 (while (string-match "^\\(--\\)" string)
11628 (setq string (concat (substring string 0 (match-beginning 1))
11629 (make-string indent ? )
11630 (substring string (match-beginning 1))))))
11631 (beginning-of-line)
11632 (insert string)
11633 (goto-char pos)))
11635 (defvar vhdl-port-flattened nil
11636 "Indicates whether a port has been flattened.")
11638 (defun vhdl-port-flatten (&optional as-alist)
11639 "Flatten port list so that only one generic/port exists per line.
11640 This operation is performed on an internally stored port and is only
11641 reflected in a subsequent paste operation."
11642 (interactive)
11643 (if (not vhdl-port-list)
11644 (error "ERROR: No port has been read")
11645 (message "Flattening port for next paste...")
11646 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11647 (old-vhdl-port-list (cdr vhdl-port-list))
11648 old-port-list new-port-list old-port new-port names)
11649 ;; traverse port list and flatten entries
11650 (while (cdr old-vhdl-port-list)
11651 (setq old-port-list (car old-vhdl-port-list))
11652 (setq new-port-list nil)
11653 (while old-port-list
11654 (setq old-port (car old-port-list))
11655 (setq names (car old-port))
11656 (while names
11657 (setq new-port (cons (if as-alist (car names) (list (car names)))
11658 (cdr old-port)))
11659 (setq new-port-list (append new-port-list (list new-port)))
11660 (setq names (cdr names)))
11661 (setq old-port-list (cdr old-port-list)))
11662 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11663 (setq new-vhdl-port-list (append new-vhdl-port-list
11664 (list new-port-list))))
11665 (setq vhdl-port-list
11666 (append new-vhdl-port-list (list old-vhdl-port-list))
11667 vhdl-port-flattened t)
11668 (message "Flattening port for next paste...done"))))
11670 (defvar vhdl-port-reversed-direction nil
11671 "Indicates whether port directions are reversed.")
11673 (defun vhdl-port-reverse-direction ()
11674 "Reverse direction for all ports (useful in testbenches).
11675 This operation is performed on an internally stored port and is only
11676 reflected in a subsequent paste operation."
11677 (interactive)
11678 (if (not vhdl-port-list)
11679 (error "ERROR: No port has been read")
11680 (message "Reversing port directions for next paste...")
11681 (let ((port-list (nth 2 vhdl-port-list))
11682 port-dir-car port-dir)
11683 ;; traverse port list and reverse directions
11684 (while port-list
11685 (setq port-dir-car (cddr (car port-list))
11686 port-dir (car port-dir-car))
11687 (setcar port-dir-car
11688 (cond ((equal port-dir "in") "out")
11689 ((equal port-dir "IN") "OUT")
11690 ((equal port-dir "out") "in")
11691 ((equal port-dir "OUT") "IN")
11692 (t port-dir)))
11693 (setq port-list (cdr port-list)))
11694 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11695 (message "Reversing port directions for next paste...done"))))
11697 (defun vhdl-port-copy ()
11698 "Get generic and port information from an entity or component declaration."
11699 (interactive)
11700 (save-excursion
11701 (let (parse-error end-of-list
11702 decl-type name generic-list port-list context-clause
11703 object names direct type init comment group-comment)
11704 (vhdl-prepare-search-2
11705 (setq
11706 parse-error
11707 (catch 'parse
11708 ;; check if within entity or component declaration
11709 (end-of-line)
11710 (when (or (not (re-search-backward
11711 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11712 (equal "END" (upcase (match-string 1))))
11713 (throw 'parse "ERROR: Not within an entity or component declaration"))
11714 (setq decl-type (downcase (match-string-no-properties 1)))
11715 (forward-word-strictly 1)
11716 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11717 (setq name (match-string-no-properties 1))
11718 (message "Reading port of %s \"%s\"..." decl-type name)
11719 (vhdl-forward-syntactic-ws)
11720 ;; parse generic clause
11721 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11722 ;; parse group comment and spacing
11723 (setq group-comment (vhdl-parse-group-comment))
11724 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11725 (while (not end-of-list)
11726 ;; parse names (accept extended identifiers)
11727 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11728 (setq names (list (match-string-no-properties 1)))
11729 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11730 (setq names
11731 (append names (list (match-string-no-properties 1)))))
11732 ;; parse type
11733 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11734 (setq type (match-string-no-properties 1))
11735 (when (vhdl-in-comment-p) ; if stuck in comment
11736 (setq type (concat type (and (vhdl-parse-string ".*")
11737 (match-string-no-properties 0)))))
11738 (setq comment nil)
11739 (while (looking-at "(")
11740 (setq type
11741 (concat type
11742 (buffer-substring-no-properties
11743 (point) (progn (forward-sexp) (point)))
11744 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11745 (match-string-no-properties 1)))))
11746 ;; special case: closing parenthesis is on separate line
11747 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11748 (setq comment (substring type (match-beginning 2)))
11749 (setq type (substring type 0 (match-beginning 1))))
11750 ;; strip of trailing group-comment
11751 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11752 (setq type (substring type 0 (match-end 1)))
11753 ;; parse initialization expression
11754 (setq init nil)
11755 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11756 (vhdl-parse-string "\\([^();\n]*\\)")
11757 (setq init (match-string-no-properties 1))
11758 (while (looking-at "(")
11759 (setq init
11760 (concat init
11761 (buffer-substring-no-properties
11762 (point) (progn (forward-sexp) (point)))
11763 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11764 (match-string-no-properties 1))))))
11765 ;; special case: closing parenthesis is on separate line
11766 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11767 (setq comment (substring init (match-beginning 2)))
11768 (setq init (substring init 0 (match-beginning 1)))
11769 (vhdl-forward-syntactic-ws))
11770 (skip-chars-forward " \t")
11771 ;; parse inline comment, special case: as above, no initial.
11772 (unless comment
11773 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11774 (match-string-no-properties 1))))
11775 (vhdl-forward-syntactic-ws)
11776 (setq end-of-list (vhdl-parse-string ")" t))
11777 (vhdl-parse-string "\\s-*;\\s-*")
11778 ;; parse inline comment
11779 (unless comment
11780 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11781 (match-string-no-properties 1))))
11782 ;; save everything in list
11783 (setq generic-list (append generic-list
11784 (list (list names type init
11785 comment group-comment))))
11786 ;; parse group comment and spacing
11787 (setq group-comment (vhdl-parse-group-comment))))
11788 ;; parse port clause
11789 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11790 ;; parse group comment and spacing
11791 (setq group-comment (vhdl-parse-group-comment))
11792 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11793 (while (not end-of-list)
11794 ;; parse object
11795 (setq object
11796 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11797 (match-string-no-properties 1)))
11798 ;; parse names (accept extended identifiers)
11799 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11800 (setq names (list (match-string-no-properties 1)))
11801 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11802 (setq names (append names (list (match-string-no-properties 1)))))
11803 ;; parse direction
11804 (vhdl-parse-string ":[ \t\n\r\f]*")
11805 (setq direct
11806 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11807 (match-string-no-properties 1)))
11808 ;; parse type
11809 (vhdl-parse-string "\\([^();\n]+\\)")
11810 (setq type (match-string-no-properties 1))
11811 (when (vhdl-in-comment-p) ; if stuck in comment
11812 (setq type (concat type (and (vhdl-parse-string ".*")
11813 (match-string-no-properties 0)))))
11814 (setq comment nil)
11815 (while (looking-at "(")
11816 (setq type (concat type
11817 (buffer-substring-no-properties
11818 (point) (progn (forward-sexp) (point)))
11819 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11820 (match-string-no-properties 1)))))
11821 ;; special case: closing parenthesis is on separate line
11822 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11823 (setq comment (substring type (match-beginning 2)))
11824 (setq type (substring type 0 (match-beginning 1))))
11825 ;; strip of trailing group-comment
11826 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11827 (setq type (substring type 0 (match-end 1)))
11828 (vhdl-forward-syntactic-ws)
11829 (setq end-of-list (vhdl-parse-string ")" t))
11830 (vhdl-parse-string "\\s-*;\\s-*")
11831 ;; parse inline comment
11832 (unless comment
11833 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11834 (match-string-no-properties 1))))
11835 ;; save everything in list
11836 (setq port-list (append port-list
11837 (list (list names object direct type
11838 comment group-comment))))
11839 ;; parse group comment and spacing
11840 (setq group-comment (vhdl-parse-group-comment))))
11841 ;; parse context clause
11842 (setq context-clause (vhdl-scan-context-clause))
11843 ; ;; add surrounding package to context clause
11844 ; (when (and (equal decl-type "component")
11845 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11846 ; (setq context-clause
11847 ; (append context-clause
11848 ; (list (cons (vhdl-work-library)
11849 ; (match-string-no-properties 1))))))
11850 (message "Reading port of %s \"%s\"...done" decl-type name)
11851 nil)))
11852 ;; finish parsing
11853 (if parse-error
11854 (error parse-error)
11855 (setq vhdl-port-list (list name generic-list port-list context-clause)
11856 vhdl-port-reversed-direction nil
11857 vhdl-port-flattened nil)))))
11859 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11860 "Paste a context clause."
11861 (let ((margin (current-indentation))
11862 (clause-list (nth 3 vhdl-port-list))
11863 clause)
11864 (while clause-list
11865 (setq clause (car clause-list))
11866 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11867 (downcase exclude-pack-name)))
11868 (save-excursion
11869 (re-search-backward
11870 (concat "^\\s-*use\\s-+" (car clause)
11871 "." (cdr clause) "\\>") nil t)))
11872 (vhdl-template-standard-package (car clause) (cdr clause))
11873 (insert "\n"))
11874 (setq clause-list (cdr clause-list)))))
11876 (defun vhdl-port-paste-generic (&optional no-init)
11877 "Paste a generic clause."
11878 (let ((margin (current-indentation))
11879 (generic-list (nth 1 vhdl-port-list))
11880 list-margin start names generic)
11881 ;; paste generic clause
11882 (when generic-list
11883 (setq start (point))
11884 (vhdl-insert-keyword "GENERIC (")
11885 (unless vhdl-argument-list-indent
11886 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11887 (setq list-margin (current-column))
11888 (while generic-list
11889 (setq generic (car generic-list))
11890 ;; paste group comment and spacing
11891 (when (memq vhdl-include-group-comments '(decl always))
11892 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11893 ;; paste names
11894 (setq names (nth 0 generic))
11895 (while names
11896 (insert (car names))
11897 (setq names (cdr names))
11898 (when names (insert ", ")))
11899 ;; paste type
11900 (insert " : " (nth 1 generic))
11901 ;; paste initialization
11902 (when (and (not no-init) (nth 2 generic))
11903 (insert " := " (nth 2 generic)))
11904 (unless (cdr generic-list) (insert ")"))
11905 (insert ";")
11906 ;; paste comment
11907 (when (and vhdl-include-port-comments (nth 3 generic))
11908 (vhdl-comment-insert-inline (nth 3 generic) t))
11909 (setq generic-list (cdr generic-list))
11910 (when generic-list (insert "\n") (indent-to list-margin)))
11911 ;; align generic clause
11912 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11914 (defun vhdl-port-paste-port ()
11915 "Paste a port clause."
11916 (let ((margin (current-indentation))
11917 (port-list (nth 2 vhdl-port-list))
11918 list-margin start names port)
11919 ;; paste port clause
11920 (when port-list
11921 (setq start (point))
11922 (vhdl-insert-keyword "PORT (")
11923 (unless vhdl-argument-list-indent
11924 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11925 (setq list-margin (current-column))
11926 (while port-list
11927 (setq port (car port-list))
11928 ;; paste group comment and spacing
11929 (when (memq vhdl-include-group-comments '(decl always))
11930 (vhdl-paste-group-comment (nth 5 port) list-margin))
11931 ;; paste object
11932 (when (nth 1 port) (insert (nth 1 port) " "))
11933 ;; paste names
11934 (setq names (nth 0 port))
11935 (while names
11936 (insert (car names))
11937 (setq names (cdr names))
11938 (when names (insert ", ")))
11939 ;; paste direction
11940 (insert " : ")
11941 (when (nth 2 port) (insert (nth 2 port) " "))
11942 ;; paste type
11943 (insert (nth 3 port))
11944 (unless (cdr port-list) (insert ")"))
11945 (insert ";")
11946 ;; paste comment
11947 (when (and vhdl-include-port-comments (nth 4 port))
11948 (vhdl-comment-insert-inline (nth 4 port) t))
11949 (setq port-list (cdr port-list))
11950 (when port-list (insert "\n") (indent-to list-margin)))
11951 ;; align port clause
11952 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11954 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11955 "Paste as an entity or component declaration."
11956 (unless no-indent (indent-according-to-mode))
11957 (let ((margin (current-indentation))
11958 (name (nth 0 vhdl-port-list)))
11959 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11960 (insert name)
11961 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11962 (vhdl-insert-keyword " IS"))
11963 ;; paste generic and port clause
11964 (when (nth 1 vhdl-port-list)
11965 (insert "\n")
11966 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11967 (insert "\n"))
11968 (indent-to (+ margin vhdl-basic-offset))
11969 (vhdl-port-paste-generic (eq kind 'component)))
11970 (when (nth 2 vhdl-port-list)
11971 (insert "\n")
11972 (when (and (memq vhdl-insert-empty-lines '(unit all))
11973 (eq kind 'entity))
11974 (insert "\n"))
11975 (indent-to (+ margin vhdl-basic-offset)))
11976 (vhdl-port-paste-port)
11977 (insert "\n")
11978 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11979 (insert "\n"))
11980 (indent-to margin)
11981 (vhdl-insert-keyword "END")
11982 (if (eq kind 'entity)
11983 (progn
11984 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11985 (insert " " name))
11986 (vhdl-insert-keyword " COMPONENT")
11987 (unless (vhdl-standard-p '87) (insert " " name)))
11988 (insert ";")))
11990 (defun vhdl-port-paste-entity (&optional no-indent)
11991 "Paste as an entity declaration."
11992 (interactive)
11993 (if (not vhdl-port-list)
11994 (error "ERROR: No port read")
11995 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11996 (vhdl-port-paste-declaration 'entity no-indent)
11997 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11999 (defun vhdl-port-paste-component (&optional no-indent)
12000 "Paste as a component declaration."
12001 (interactive)
12002 (if (not vhdl-port-list)
12003 (error "ERROR: No port read")
12004 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
12005 (vhdl-port-paste-declaration 'component no-indent)
12006 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
12008 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
12009 "Paste as a generic map."
12010 (interactive)
12011 (unless secondary (indent-according-to-mode))
12012 (let ((margin (current-indentation))
12013 list-margin start generic
12014 (generic-list (nth 1 vhdl-port-list)))
12015 (when generic-list
12016 (setq start (point))
12017 (vhdl-insert-keyword "GENERIC MAP (")
12018 (if (not vhdl-association-list-with-formals)
12019 ;; paste list of actual generics
12020 (while generic-list
12021 (insert (if no-constants
12022 (car (nth 0 (car generic-list)))
12023 (or (nth 2 (car generic-list)) " ")))
12024 (setq generic-list (cdr generic-list))
12025 (insert (if generic-list ", " ")"))
12026 (when (and (not generic-list) secondary
12027 (null (nth 2 vhdl-port-list)))
12028 (insert ";")))
12029 (unless vhdl-argument-list-indent
12030 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12031 (setq list-margin (current-column))
12032 (while generic-list
12033 (setq generic (car generic-list))
12034 ;; paste group comment and spacing
12035 (when (eq vhdl-include-group-comments 'always)
12036 (vhdl-paste-group-comment (nth 4 generic) list-margin))
12037 ;; paste formal and actual generic
12038 (insert (car (nth 0 generic)) " => "
12039 (if no-constants
12040 (vhdl-replace-string vhdl-actual-generic-name
12041 (car (nth 0 generic)))
12042 (or (nth 2 generic) "")))
12043 (setq generic-list (cdr generic-list))
12044 (insert (if generic-list "," ")"))
12045 (when (and (not generic-list) secondary
12046 (null (nth 2 vhdl-port-list)))
12047 (insert ";"))
12048 ;; paste comment
12049 (when (or vhdl-include-type-comments
12050 (and vhdl-include-port-comments (nth 3 generic)))
12051 (vhdl-comment-insert-inline
12052 (concat
12053 (when vhdl-include-type-comments
12054 (concat "[" (nth 1 generic) "] "))
12055 (when vhdl-include-port-comments (nth 3 generic))) t))
12056 (when generic-list (insert "\n") (indent-to list-margin)))
12057 ;; align generic map
12058 (when vhdl-auto-align
12059 (vhdl-align-region-groups start (point) 1 t))))))
12061 (defun vhdl-port-paste-port-map ()
12062 "Paste as a port map."
12063 (let ((margin (current-indentation))
12064 list-margin start port
12065 (port-list (nth 2 vhdl-port-list)))
12066 (when port-list
12067 (setq start (point))
12068 (vhdl-insert-keyword "PORT MAP (")
12069 (if (not vhdl-association-list-with-formals)
12070 ;; paste list of actual ports
12071 (while port-list
12072 (insert (vhdl-replace-string vhdl-actual-port-name
12073 (car (nth 0 (car port-list)))))
12074 (setq port-list (cdr port-list))
12075 (insert (if port-list ", " ")")))
12076 (unless vhdl-argument-list-indent
12077 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12078 (setq list-margin (current-column))
12079 (while port-list
12080 (setq port (car port-list))
12081 ;; paste group comment and spacing
12082 (when (eq vhdl-include-group-comments 'always)
12083 (vhdl-paste-group-comment (nth 5 port) list-margin))
12084 ;; paste formal and actual port
12085 (insert (car (nth 0 port)) " => ")
12086 (insert (vhdl-replace-string vhdl-actual-port-name
12087 (car (nth 0 port))))
12088 (setq port-list (cdr port-list))
12089 (insert (if port-list "," ");"))
12090 ;; paste comment
12091 (when (or (and vhdl-include-direction-comments (nth 2 port))
12092 vhdl-include-type-comments
12093 (and vhdl-include-port-comments (nth 4 port)))
12094 (vhdl-comment-insert-inline
12095 (concat
12096 (cond ((and vhdl-include-direction-comments
12097 vhdl-include-type-comments)
12098 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
12099 (nth 3 port) "] "))
12100 ((and vhdl-include-direction-comments (nth 2 port))
12101 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12102 (vhdl-include-direction-comments " ")
12103 (vhdl-include-type-comments
12104 (concat "[" (nth 3 port) "] ")))
12105 (when vhdl-include-port-comments (nth 4 port))) t))
12106 (when port-list (insert "\n") (indent-to list-margin)))
12107 ;; align port clause
12108 (when vhdl-auto-align
12109 (vhdl-align-region-groups start (point) 1))))))
12111 (defun vhdl-port-paste-instance (&optional name no-indent title)
12112 "Paste as an instantiation."
12113 (interactive)
12114 (if (not vhdl-port-list)
12115 (error "ERROR: No port read")
12116 (let ((orig-vhdl-port-list vhdl-port-list))
12117 ;; flatten local copy of port list (must be flat for port mapping)
12118 (vhdl-port-flatten)
12119 (unless no-indent (indent-according-to-mode))
12120 (let ((margin (current-indentation)))
12121 ;; paste instantiation
12122 (cond (name
12123 (insert name))
12124 ((equal (cdr vhdl-instance-name) "")
12125 (setq name (vhdl-template-field "instance name")))
12126 ((string-match "%d" (cdr vhdl-instance-name))
12127 (let ((n 1))
12128 (while (save-excursion
12129 (setq name (format (vhdl-replace-string
12130 vhdl-instance-name
12131 (nth 0 vhdl-port-list)) n))
12132 (goto-char (point-min))
12133 (vhdl-re-search-forward name nil t))
12134 (setq n (1+ n)))
12135 (insert name)))
12136 (t (insert (vhdl-replace-string vhdl-instance-name
12137 (nth 0 vhdl-port-list)))))
12138 (message "Pasting port as instantiation \"%s\"..." name)
12139 (insert ": ")
12140 (when title
12141 (save-excursion
12142 (beginning-of-line)
12143 (indent-to vhdl-basic-offset)
12144 (insert "-- instance \"" name "\"\n")))
12145 (if (not (vhdl-use-direct-instantiation))
12146 (insert (nth 0 vhdl-port-list))
12147 (vhdl-insert-keyword "ENTITY ")
12148 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
12149 (when (nth 1 vhdl-port-list)
12150 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12151 (vhdl-port-paste-generic-map t t))
12152 (when (nth 2 vhdl-port-list)
12153 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12154 (vhdl-port-paste-port-map))
12155 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
12156 (insert ";"))
12157 (message "Pasting port as instantiation \"%s\"...done" name))
12158 (setq vhdl-port-list orig-vhdl-port-list))))
12160 (defun vhdl-port-paste-constants (&optional no-indent)
12161 "Paste generics as constants."
12162 (interactive)
12163 (if (not vhdl-port-list)
12164 (error "ERROR: No port read")
12165 (let ((orig-vhdl-port-list vhdl-port-list))
12166 (message "Pasting port as constants...")
12167 ;; flatten local copy of port list (must be flat for constant initial.)
12168 (vhdl-port-flatten)
12169 (unless no-indent (indent-according-to-mode))
12170 (let ((margin (current-indentation))
12171 start generic name
12172 (generic-list (nth 1 vhdl-port-list)))
12173 (when generic-list
12174 (setq start (point))
12175 (while generic-list
12176 (setq generic (car generic-list))
12177 ;; paste group comment and spacing
12178 (when (memq vhdl-include-group-comments '(decl always))
12179 (vhdl-paste-group-comment (nth 4 generic) margin))
12180 (vhdl-insert-keyword "CONSTANT ")
12181 ;; paste generic constants
12182 (setq name (nth 0 generic))
12183 (when name
12184 (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
12185 ;; paste type
12186 (insert " : " (nth 1 generic))
12187 ;; paste initialization
12188 (when (nth 2 generic)
12189 (insert " := " (nth 2 generic)))
12190 (insert ";")
12191 ;; paste comment
12192 (when (and vhdl-include-port-comments (nth 3 generic))
12193 (vhdl-comment-insert-inline (nth 3 generic) t))
12194 (setq generic-list (cdr generic-list))
12195 (when generic-list (insert "\n") (indent-to margin))))
12196 ;; align signal list
12197 (when vhdl-auto-align
12198 (vhdl-align-region-groups start (point) 1))))
12199 (message "Pasting port as constants...done")
12200 (setq vhdl-port-list orig-vhdl-port-list))))
12202 (defun vhdl-port-paste-signals (&optional initialize no-indent)
12203 "Paste ports as internal signals."
12204 (interactive)
12205 (if (not vhdl-port-list)
12206 (error "ERROR: No port read")
12207 (message "Pasting port as signals...")
12208 (unless no-indent (indent-according-to-mode))
12209 (let ((margin (current-indentation))
12210 start port names type generic-list port-name constant-name pos
12211 (port-list (nth 2 vhdl-port-list)))
12212 (when port-list
12213 (setq start (point))
12214 (while port-list
12215 (setq port (car port-list))
12216 ;; paste group comment and spacing
12217 (when (memq vhdl-include-group-comments '(decl always))
12218 (vhdl-paste-group-comment (nth 5 port) margin))
12219 ;; paste object
12220 (if (nth 1 port)
12221 (insert (nth 1 port) " ")
12222 (vhdl-insert-keyword "SIGNAL "))
12223 ;; paste actual port signals
12224 (setq names (nth 0 port))
12225 (while names
12226 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
12227 (setq names (cdr names))
12228 (when names (insert ", ")))
12229 ;; paste type
12230 (setq type (nth 3 port))
12231 (setq generic-list (nth 1 vhdl-port-list))
12232 (vhdl-prepare-search-1
12233 (setq pos 0)
12234 ;; replace formal by actual generics
12235 (while generic-list
12236 (setq port-name (car (nth 0 (car generic-list))))
12237 (while (string-match (concat "\\<" port-name "\\>") type pos)
12238 (setq constant-name
12239 (save-match-data (vhdl-replace-string
12240 vhdl-actual-generic-name port-name)))
12241 (setq type (replace-match constant-name t nil type))
12242 (setq pos (match-end 0)))
12243 (setq generic-list (cdr generic-list))))
12244 (insert " : " type)
12245 ;; paste initialization (inputs only)
12246 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
12247 (insert " := "
12248 (cond ((string-match "integer" (nth 3 port)) "0")
12249 ((string-match "natural" (nth 3 port)) "0")
12250 ((string-match "positive" (nth 3 port)) "0")
12251 ((string-match "real" (nth 3 port)) "0.0")
12252 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12253 (t "'0'"))))
12254 (insert ";")
12255 ;; paste comment
12256 (when (or (and vhdl-include-direction-comments (nth 2 port))
12257 (and vhdl-include-port-comments (nth 4 port)))
12258 (vhdl-comment-insert-inline
12259 (concat
12260 (cond ((and vhdl-include-direction-comments (nth 2 port))
12261 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12262 (vhdl-include-direction-comments " "))
12263 (when vhdl-include-port-comments (nth 4 port))) t))
12264 (setq port-list (cdr port-list))
12265 (when port-list (insert "\n") (indent-to margin)))
12266 ;; align signal list
12267 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12268 (message "Pasting port as signals...done")))
12270 (defun vhdl-port-paste-initializations (&optional no-indent)
12271 "Paste ports as signal initializations."
12272 (interactive)
12273 (if (not vhdl-port-list)
12274 (error "ERROR: No port read")
12275 (let ((orig-vhdl-port-list vhdl-port-list))
12276 (message "Pasting port as initializations...")
12277 ;; flatten local copy of port list (must be flat for signal initial.)
12278 (vhdl-port-flatten)
12279 (unless no-indent (indent-according-to-mode))
12280 (let ((margin (current-indentation))
12281 start port name
12282 (port-list (nth 2 vhdl-port-list)))
12283 (when port-list
12284 (setq start (point))
12285 (while port-list
12286 (setq port (car port-list))
12287 ;; paste actual port signal (inputs only)
12288 (when (equal "IN" (upcase (nth 2 port)))
12289 (setq name (car (nth 0 port)))
12290 (insert (vhdl-replace-string vhdl-actual-port-name name))
12291 ;; paste initialization
12292 (insert " <= "
12293 (cond ((string-match "integer" (nth 3 port)) "0")
12294 ((string-match "natural" (nth 3 port)) "0")
12295 ((string-match "positive" (nth 3 port)) "0")
12296 ((string-match "real" (nth 3 port)) "0.0")
12297 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12298 (t "'0'"))
12299 ";"))
12300 (setq port-list (cdr port-list))
12301 (when (and port-list
12302 (equal "IN" (upcase (nth 2 (car port-list)))))
12303 (insert "\n") (indent-to margin)))
12304 ;; align signal list
12305 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12306 (message "Pasting port as initializations...done")
12307 (setq vhdl-port-list orig-vhdl-port-list))))
12309 (defun vhdl-port-paste-testbench ()
12310 "Paste as a bare-bones testbench."
12311 (interactive)
12312 (if (not vhdl-port-list)
12313 (error "ERROR: No port read")
12314 (let ((case-fold-search t)
12315 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12316 (nth 0 vhdl-port-list)))
12317 (source-buffer (current-buffer))
12318 arch-name config-name ent-file-name arch-file-name
12319 ent-buffer arch-buffer position)
12320 ;; open entity file
12321 (unless (eq vhdl-testbench-create-files 'none)
12322 (setq ent-file-name
12323 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12324 ent-name t)
12325 "." (file-name-extension (buffer-file-name))))
12326 (if (file-exists-p ent-file-name)
12327 (if (y-or-n-p
12328 (concat "File \"" ent-file-name "\" exists; overwrite? "))
12329 (progn (find-file ent-file-name)
12330 (erase-buffer)
12331 (set-buffer-modified-p nil))
12332 (if (eq vhdl-testbench-create-files 'separate)
12333 (setq ent-file-name nil)
12334 (error "ERROR: Pasting port as testbench...aborted")))
12335 (find-file ent-file-name)))
12336 (unless (and (eq vhdl-testbench-create-files 'separate)
12337 (null ent-file-name))
12338 ;; paste entity header
12339 (if vhdl-testbench-include-header
12340 (progn (vhdl-template-header
12341 (concat "Testbench for design \""
12342 (nth 0 vhdl-port-list) "\""))
12343 (goto-char (point-max)))
12344 (vhdl-comment-display-line) (insert "\n\n"))
12345 ;; paste std_logic_1164 package
12346 (when vhdl-testbench-include-library
12347 (vhdl-template-package-std-logic-1164)
12348 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12349 ;; paste entity declaration
12350 (vhdl-insert-keyword "ENTITY ")
12351 (insert ent-name)
12352 (vhdl-insert-keyword " IS")
12353 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
12354 (insert "\n")
12355 (vhdl-insert-keyword "END ")
12356 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12357 (insert ent-name ";")
12358 (insert "\n\n")
12359 (vhdl-comment-display-line) (insert "\n"))
12360 ;; get architecture name
12361 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
12362 (read-from-minibuffer "architecture name: "
12363 nil vhdl-minibuffer-local-map)
12364 (vhdl-replace-string vhdl-testbench-architecture-name
12365 (nth 0 vhdl-port-list))))
12366 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
12367 ;; open architecture file
12368 (if (not (eq vhdl-testbench-create-files 'separate))
12369 (insert "\n")
12370 (setq ent-buffer (current-buffer))
12371 (setq arch-file-name
12372 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12373 (concat ent-name " " arch-name) t)
12374 "." (file-name-extension (buffer-file-name))))
12375 (when (and (file-exists-p arch-file-name)
12376 (not (y-or-n-p (concat "File \"" arch-file-name
12377 "\" exists; overwrite? "))))
12378 (error "ERROR: Pasting port as testbench...aborted"))
12379 (find-file arch-file-name)
12380 (erase-buffer)
12381 (set-buffer-modified-p nil)
12382 ;; paste architecture header
12383 (if vhdl-testbench-include-header
12384 (progn (vhdl-template-header
12385 (concat "Testbench architecture for design \""
12386 (nth 0 vhdl-port-list) "\""))
12387 (goto-char (point-max)))
12388 (vhdl-comment-display-line) (insert "\n\n")))
12389 ;; paste architecture body
12390 (vhdl-insert-keyword "ARCHITECTURE ")
12391 (insert arch-name)
12392 (vhdl-insert-keyword " OF ")
12393 (insert ent-name)
12394 (vhdl-insert-keyword " IS")
12395 (insert "\n\n") (indent-to vhdl-basic-offset)
12396 ;; paste component declaration
12397 (unless (vhdl-use-direct-instantiation)
12398 (vhdl-port-paste-component t)
12399 (insert "\n\n") (indent-to vhdl-basic-offset))
12400 ;; paste constants
12401 (when (nth 1 vhdl-port-list)
12402 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
12403 (vhdl-port-paste-constants t)
12404 (insert "\n\n") (indent-to vhdl-basic-offset))
12405 ;; paste internal signals
12406 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
12407 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
12408 (insert "\n")
12409 ;; paste custom declarations
12410 (unless (equal "" vhdl-testbench-declarations)
12411 (insert "\n")
12412 (setq position (point))
12413 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12414 (vhdl-indent-region position (point)))
12415 (setq position (point))
12416 (insert "\n\n")
12417 (vhdl-comment-display-line) (insert "\n")
12418 (when vhdl-testbench-include-configuration
12419 (setq config-name (vhdl-replace-string
12420 vhdl-testbench-configuration-name
12421 (concat ent-name " " arch-name)))
12422 (insert "\n")
12423 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12424 (vhdl-insert-keyword " OF ") (insert ent-name)
12425 (vhdl-insert-keyword " IS\n")
12426 (indent-to vhdl-basic-offset)
12427 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12428 (indent-to vhdl-basic-offset)
12429 (vhdl-insert-keyword "END FOR;\n")
12430 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12431 (vhdl-comment-display-line) (insert "\n"))
12432 (goto-char position)
12433 (vhdl-template-begin-end
12434 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12435 ;; paste instantiation
12436 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12437 (vhdl-port-paste-instance
12438 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12439 (insert "\n")
12440 ;; paste custom statements
12441 (unless (equal "" vhdl-testbench-statements)
12442 (insert "\n")
12443 (setq position (point))
12444 (vhdl-insert-string-or-file vhdl-testbench-statements)
12445 (vhdl-indent-region position (point)))
12446 (insert "\n")
12447 (indent-to vhdl-basic-offset)
12448 (unless (eq vhdl-testbench-create-files 'none)
12449 (setq arch-buffer (current-buffer))
12450 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12451 (set-buffer arch-buffer) (save-buffer))
12452 (message "%s"
12453 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12454 ent-name arch-name)
12455 (and ent-file-name
12456 (format "\n File created: \"%s\"" ent-file-name))
12457 (and arch-file-name
12458 (format "\n File created: \"%s\"" arch-file-name)))))))
12461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12462 ;;; Subprogram interface translation
12463 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12465 (defvar vhdl-subprog-list nil
12466 "Variable to hold last subprogram interface parsed.")
12467 ;; structure: (parenthesized expression means list of such entries)
12468 ;; (subprog-name kind
12469 ;; ((names) object direct type init comment group-comment)
12470 ;; return-type return-comment group-comment)
12472 (defvar vhdl-subprog-flattened nil
12473 "Indicates whether an subprogram interface has been flattened.")
12475 (defun vhdl-subprog-flatten ()
12476 "Flatten interface list so that only one parameter exists per line."
12477 (interactive)
12478 (if (not vhdl-subprog-list)
12479 (error "ERROR: No subprogram interface has been read")
12480 (message "Flattening subprogram interface...")
12481 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12482 new-subprog-list old-subprog new-subprog names)
12483 ;; traverse parameter list and flatten entries
12484 (while old-subprog-list
12485 (setq old-subprog (car old-subprog-list))
12486 (setq names (car old-subprog))
12487 (while names
12488 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12489 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12490 (setq names (cdr names)))
12491 (setq old-subprog-list (cdr old-subprog-list)))
12492 (setq vhdl-subprog-list
12493 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12494 new-subprog-list (nth 3 vhdl-subprog-list)
12495 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12496 vhdl-subprog-flattened t)
12497 (message "Flattening subprogram interface...done"))))
12499 (defun vhdl-subprog-copy ()
12500 "Get interface information from a subprogram specification."
12501 (interactive)
12502 (save-excursion
12503 (let (parse-error pos end-of-list
12504 name kind param-list object names direct type init
12505 comment group-comment
12506 return-type return-comment return-group-comment)
12507 (vhdl-prepare-search-2
12508 (setq
12509 parse-error
12510 (catch 'parse
12511 ;; check if within function declaration
12512 (setq pos (point))
12513 (end-of-line)
12514 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12515 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12516 (goto-char (match-end 0))
12517 (save-excursion (backward-char)
12518 (forward-sexp)
12519 (<= pos (point))))
12520 (throw 'parse "ERROR: Not within a subprogram specification"))
12521 (setq name (match-string-no-properties 5))
12522 (setq kind (if (match-string 2) 'procedure 'function))
12523 (setq end-of-list (not (match-string 7)))
12524 (message "Reading interface of subprogram \"%s\"..." name)
12525 ;; parse parameter list
12526 (setq group-comment (vhdl-parse-group-comment))
12527 (setq end-of-list (or end-of-list
12528 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12529 (while (not end-of-list)
12530 ;; parse object
12531 (setq object
12532 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12533 (match-string-no-properties 1)))
12534 ;; parse names (accept extended identifiers)
12535 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12536 (setq names (list (match-string-no-properties 1)))
12537 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12538 (setq names (append names (list (match-string-no-properties 1)))))
12539 ;; parse direction
12540 (vhdl-parse-string ":[ \t\n\r\f]*")
12541 (setq direct
12542 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12543 (match-string-no-properties 1)))
12544 ;; parse type
12545 (vhdl-parse-string "\\([^():;\n]+\\)")
12546 (setq type (match-string-no-properties 1))
12547 (setq comment nil)
12548 (while (looking-at "(")
12549 (setq type
12550 (concat type
12551 (buffer-substring-no-properties
12552 (point) (progn (forward-sexp) (point)))
12553 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12554 (match-string-no-properties 1)))))
12555 ;; special case: closing parenthesis is on separate line
12556 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12557 (setq comment (substring type (match-beginning 2)))
12558 (setq type (substring type 0 (match-beginning 1))))
12559 ;; strip off trailing group-comment
12560 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12561 (setq type (substring type 0 (match-end 1)))
12562 ;; parse initialization expression
12563 (setq init nil)
12564 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12565 (vhdl-parse-string "\\([^();\n]*\\)")
12566 (setq init (match-string-no-properties 1))
12567 (while (looking-at "(")
12568 (setq init
12569 (concat init
12570 (buffer-substring-no-properties
12571 (point) (progn (forward-sexp) (point)))
12572 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12573 (match-string-no-properties 1))))))
12574 ;; special case: closing parenthesis is on separate line
12575 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12576 (setq comment (substring init (match-beginning 2)))
12577 (setq init (substring init 0 (match-beginning 1)))
12578 (vhdl-forward-syntactic-ws))
12579 (skip-chars-forward " \t")
12580 ;; parse inline comment, special case: as above, no initial.
12581 (unless comment
12582 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12583 (match-string-no-properties 1))))
12584 (vhdl-forward-syntactic-ws)
12585 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12586 ;; parse inline comment
12587 (unless comment
12588 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12589 (match-string-no-properties 1))))
12590 (setq return-group-comment (vhdl-parse-group-comment))
12591 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12592 ;; parse return type
12593 (when (match-string 3)
12594 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12595 (setq return-type (match-string-no-properties 1))
12596 (when (and return-type
12597 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12598 (setq return-comment (substring return-type (match-beginning 2)))
12599 (setq return-type (substring return-type 0 (match-beginning 1))))
12600 ;; strip of trailing group-comment
12601 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12602 (setq return-type (substring return-type 0 (match-end 1)))
12603 ;; parse return comment
12604 (unless return-comment
12605 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12606 (match-string-no-properties 1)))))
12607 ;; parse inline comment
12608 (unless comment
12609 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12610 (match-string-no-properties 1))))
12611 ;; save everything in list
12612 (setq param-list (append param-list
12613 (list (list names object direct type init
12614 comment group-comment))))
12615 ;; parse group comment and spacing
12616 (setq group-comment (vhdl-parse-group-comment)))
12617 (message "Reading interface of subprogram \"%s\"...done" name)
12618 nil)))
12619 ;; finish parsing
12620 (if parse-error
12621 (error parse-error)
12622 (setq vhdl-subprog-list
12623 (list name kind param-list return-type return-comment
12624 return-group-comment)
12625 vhdl-subprog-flattened nil)))))
12627 (defun vhdl-subprog-paste-specification (kind)
12628 "Paste as a subprogram specification."
12629 (indent-according-to-mode)
12630 (let ((margin (current-column))
12631 (param-list (nth 2 vhdl-subprog-list))
12632 list-margin start names param)
12633 ;; paste keyword and name
12634 (vhdl-insert-keyword
12635 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12636 (insert (nth 0 vhdl-subprog-list))
12637 (if (not param-list)
12638 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12639 (setq start (point))
12640 ;; paste parameter list
12641 (insert " (")
12642 (unless vhdl-argument-list-indent
12643 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12644 (setq list-margin (current-column))
12645 (while param-list
12646 (setq param (car param-list))
12647 ;; paste group comment and spacing
12648 (when (memq vhdl-include-group-comments (list kind 'always))
12649 (vhdl-paste-group-comment (nth 6 param) list-margin))
12650 ;; paste object
12651 (when (nth 1 param) (insert (nth 1 param) " "))
12652 ;; paste names
12653 (setq names (nth 0 param))
12654 (while names
12655 (insert (car names))
12656 (setq names (cdr names))
12657 (when names (insert ", ")))
12658 ;; paste direction
12659 (insert " : ")
12660 (when (nth 2 param) (insert (nth 2 param) " "))
12661 ;; paste type
12662 (insert (nth 3 param))
12663 ;; paste initialization
12664 (when (nth 4 param) (insert " := " (nth 4 param)))
12665 ;; terminate line
12666 (if (cdr param-list)
12667 (insert ";")
12668 (insert ")")
12669 (when (null (nth 3 vhdl-subprog-list))
12670 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12671 ;; paste comment
12672 (when (and vhdl-include-port-comments (nth 5 param))
12673 (vhdl-comment-insert-inline (nth 5 param) t))
12674 (setq param-list (cdr param-list))
12675 (when param-list (insert "\n") (indent-to list-margin)))
12676 (when (nth 3 vhdl-subprog-list)
12677 (insert "\n") (indent-to list-margin)
12678 ;; paste group comment and spacing
12679 (when (memq vhdl-include-group-comments (list kind 'always))
12680 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12681 ;; paste return type
12682 (insert "return " (nth 3 vhdl-subprog-list))
12683 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12684 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12685 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12686 ;; align parameter list
12687 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12688 ;; paste body
12689 (when (eq kind 'body)
12690 (insert "\n")
12691 (vhdl-template-begin-end
12692 (unless (vhdl-standard-p '87)
12693 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12694 (nth 0 vhdl-subprog-list) margin))))
12696 (defun vhdl-subprog-paste-declaration ()
12697 "Paste as a subprogram declaration."
12698 (interactive)
12699 (if (not vhdl-subprog-list)
12700 (error "ERROR: No subprogram interface read")
12701 (message "Pasting interface as subprogram declaration \"%s\"..."
12702 (car vhdl-subprog-list))
12703 ;; paste specification
12704 (vhdl-subprog-paste-specification 'decl)
12705 (message "Pasting interface as subprogram declaration \"%s\"...done"
12706 (car vhdl-subprog-list))))
12708 (defun vhdl-subprog-paste-body ()
12709 "Paste as a subprogram body."
12710 (interactive)
12711 (if (not vhdl-subprog-list)
12712 (error "ERROR: No subprogram interface read")
12713 (message "Pasting interface as subprogram body \"%s\"..."
12714 (car vhdl-subprog-list))
12715 ;; paste specification and body
12716 (vhdl-subprog-paste-specification 'body)
12717 (message "Pasting interface as subprogram body \"%s\"...done"
12718 (car vhdl-subprog-list))))
12720 (defun vhdl-subprog-paste-call ()
12721 "Paste as a subprogram call."
12722 (interactive)
12723 (if (not vhdl-subprog-list)
12724 (error "ERROR: No subprogram interface read")
12725 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12726 param-list margin list-margin param start)
12727 ;; flatten local copy of interface list (must be flat for parameter mapping)
12728 (vhdl-subprog-flatten)
12729 (setq param-list (nth 2 vhdl-subprog-list))
12730 (indent-according-to-mode)
12731 (setq margin (current-indentation))
12732 (message "Pasting interface as subprogram call \"%s\"..."
12733 (car vhdl-subprog-list))
12734 ;; paste name
12735 (insert (nth 0 vhdl-subprog-list))
12736 (if (not param-list)
12737 (insert ";")
12738 (setq start (point))
12739 ;; paste parameter list
12740 (insert " (")
12741 (unless vhdl-argument-list-indent
12742 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12743 (setq list-margin (current-column))
12744 (while param-list
12745 (setq param (car param-list))
12746 ;; paste group comment and spacing
12747 (when (eq vhdl-include-group-comments 'always)
12748 (vhdl-paste-group-comment (nth 6 param) list-margin))
12749 ;; paste formal port
12750 (insert (car (nth 0 param)) " => ")
12751 (setq param-list (cdr param-list))
12752 (insert (if param-list "," ");"))
12753 ;; paste comment
12754 (when (and vhdl-include-port-comments (nth 5 param))
12755 (vhdl-comment-insert-inline (nth 5 param)))
12756 (when param-list (insert "\n") (indent-to list-margin)))
12757 ;; align parameter list
12758 (when vhdl-auto-align
12759 (vhdl-align-region-groups start (point) 1)))
12760 (message "Pasting interface as subprogram call \"%s\"...done"
12761 (car vhdl-subprog-list))
12762 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12765 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12766 ;;; Miscellaneous
12767 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12769 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12770 ;; Hippie expand customization
12772 (defvar vhdl-expand-upper-case nil)
12774 (defun vhdl-try-expand-abbrev (old)
12775 "Try expanding abbreviations from `vhdl-abbrev-list'."
12776 (unless old
12777 (he-init-string (he-dabbrev-beg) (point))
12778 (setq he-expand-list
12779 (let ((abbrev-list vhdl-abbrev-list)
12780 (sel-abbrev-list '()))
12781 (while abbrev-list
12782 (when (or (not (stringp (car abbrev-list)))
12783 (string-match
12784 (concat "^" he-search-string) (car abbrev-list)))
12785 (setq sel-abbrev-list
12786 (cons (car abbrev-list) sel-abbrev-list)))
12787 (setq abbrev-list (cdr abbrev-list)))
12788 (nreverse sel-abbrev-list))))
12789 (while (and he-expand-list
12790 (or (not (stringp (car he-expand-list)))
12791 (he-string-member (car he-expand-list) he-tried-table t)))
12792 (unless (stringp (car he-expand-list))
12793 (setq vhdl-expand-upper-case (car he-expand-list)))
12794 (setq he-expand-list (cdr he-expand-list)))
12795 (if (null he-expand-list)
12796 (progn (when old (he-reset-string))
12797 nil)
12798 (he-substitute-string
12799 (if vhdl-expand-upper-case
12800 (upcase (car he-expand-list))
12801 (car he-expand-list))
12803 (setq he-expand-list (cdr he-expand-list))
12806 (defun vhdl-he-list-beg ()
12807 "Also looks at the word before `(' in order to better match parenthesized
12808 expressions (e.g. for index ranges of types and signals)."
12809 (save-excursion
12810 (condition-case ()
12811 (progn (backward-up-list 1)
12812 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12813 (error ()))
12814 (point)))
12816 ;; override `he-list-beg' from `hippie-exp'
12817 (unless (and (boundp 'viper-mode) viper-mode)
12818 (defalias 'he-list-beg 'vhdl-he-list-beg))
12820 ;; function for expanding abbrevs and dabbrevs
12821 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12822 '(try-expand-dabbrev
12823 try-expand-dabbrev-all-buffers
12824 vhdl-try-expand-abbrev)))
12826 ;; function for expanding parenthesis
12827 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12828 '(try-expand-list
12829 try-expand-list-all-buffers)))
12831 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12832 ;; Line handling functions
12834 (defun vhdl-current-line ()
12835 "Return the line number of the line containing point."
12836 (save-restriction
12837 (widen)
12838 (1+ (count-lines (point-min) (point-at-bol)))))
12840 (defun vhdl-line-kill-entire (&optional arg)
12841 "Delete entire line."
12842 (interactive "p")
12843 (beginning-of-line)
12844 (kill-line (or arg 1)))
12846 (defun vhdl-line-kill (&optional arg)
12847 "Kill current line."
12848 (interactive "p")
12849 (vhdl-line-kill-entire arg))
12851 (defun vhdl-line-copy (&optional arg)
12852 "Copy current line."
12853 (interactive "p")
12854 (save-excursion
12855 (let ((position (point-at-bol)))
12856 (forward-line (or arg 1))
12857 (copy-region-as-kill position (point)))))
12859 (defun vhdl-line-yank ()
12860 "Yank entire line."
12861 (interactive)
12862 (beginning-of-line)
12863 (yank))
12865 (defun vhdl-line-expand (&optional prefix-arg)
12866 "Hippie-expand current line."
12867 (interactive "P")
12868 (require 'hippie-exp)
12869 (let ((case-fold-search t) (case-replace nil)
12870 (hippie-expand-try-functions-list
12871 '(try-expand-line try-expand-line-all-buffers)))
12872 (hippie-expand prefix-arg)))
12874 (defun vhdl-line-transpose-next (&optional arg)
12875 "Interchange this line with next line."
12876 (interactive "p")
12877 (forward-line 1)
12878 (transpose-lines (or arg 1))
12879 (forward-line -1))
12881 (defun vhdl-line-transpose-previous (&optional arg)
12882 "Interchange this line with previous line."
12883 (interactive "p")
12884 (forward-line 1)
12885 (transpose-lines (- 0 (or arg 0)))
12886 (forward-line -1))
12888 (defun vhdl-line-open ()
12889 "Open a new line and indent."
12890 (interactive)
12891 (end-of-line -0)
12892 (newline-and-indent))
12894 (defun vhdl-delete-indentation ()
12895 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12896 it works within comments too."
12897 (interactive)
12898 (let ((fill-prefix "-- "))
12899 (delete-indentation)))
12901 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12902 ;; Move functions
12904 (defun vhdl-forward-same-indent ()
12905 "Move forward to next line with same indent."
12906 (interactive)
12907 (let ((pos (point))
12908 (indent (current-indentation)))
12909 (beginning-of-line 2)
12910 (while (and (not (eobp))
12911 (or (looking-at "^\\s-*\\(--.*\\)?$")
12912 (> (current-indentation) indent)))
12913 (beginning-of-line 2))
12914 (if (= (current-indentation) indent)
12915 (back-to-indentation)
12916 (message "No following line with same indent found in this block")
12917 (goto-char pos)
12918 nil)))
12920 (defun vhdl-backward-same-indent ()
12921 "Move backward to previous line with same indent."
12922 (interactive)
12923 (let ((pos (point))
12924 (indent (current-indentation)))
12925 (beginning-of-line -0)
12926 (while (and (not (bobp))
12927 (or (looking-at "^\\s-*\\(--.*\\)?$")
12928 (> (current-indentation) indent)))
12929 (beginning-of-line -0))
12930 (if (= (current-indentation) indent)
12931 (back-to-indentation)
12932 (message "No preceding line with same indent found in this block")
12933 (goto-char pos)
12934 nil)))
12936 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12937 ;; Statistics
12939 (defun vhdl-statistics-buffer ()
12940 "Get some file statistics."
12941 (interactive)
12942 (let ((no-stats 0)
12943 (no-code-lines 0)
12944 (no-empty-lines 0)
12945 (no-comm-lines 0)
12946 (no-comments 0)
12947 (no-lines (count-lines (point-min) (point-max))))
12948 (save-excursion
12949 ;; count statements
12950 (goto-char (point-min))
12951 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12952 (if (match-string 1)
12953 (goto-char (match-end 1))
12954 (setq no-stats (1+ no-stats))))
12955 ;; count code lines
12956 (goto-char (point-min))
12957 (while (not (eobp))
12958 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12959 (setq no-code-lines (1+ no-code-lines)))
12960 (beginning-of-line 2))
12961 ;; count empty lines
12962 (goto-char (point-min))
12963 (while (and (re-search-forward "^\\s-*$" nil t)
12964 (not (eq (point) (point-max))))
12965 (if (match-string 1)
12966 (goto-char (match-end 1))
12967 (setq no-empty-lines (1+ no-empty-lines))
12968 (unless (eq (point) (point-max))
12969 (forward-char))))
12970 ;; count comment-only lines
12971 (goto-char (point-min))
12972 (while (re-search-forward "^\\s-*--.*" nil t)
12973 (if (match-string 1)
12974 (goto-char (match-end 1))
12975 (setq no-comm-lines (1+ no-comm-lines))))
12976 ;; count comments
12977 (goto-char (point-min))
12978 (while (re-search-forward "--.*" nil t)
12979 (if (match-string 1)
12980 (goto-char (match-end 1))
12981 (setq no-comments (1+ no-comments)))))
12982 ;; print results
12983 (message "\n\
12984 File statistics: \"%s\"\n\
12985 -----------------------\n\
12986 # statements : %5d\n\
12987 # code lines : %5d\n\
12988 # empty lines : %5d\n\
12989 # comment lines : %5d\n\
12990 # comments : %5d\n\
12991 # total lines : %5d\n"
12992 (buffer-file-name) no-stats no-code-lines no-empty-lines
12993 no-comm-lines no-comments no-lines)
12994 (unless vhdl-emacs-21 (vhdl-show-messages))))
12996 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12997 ;; Help functions
12999 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
13000 "Like `re-search-forward', but does not match within literals."
13001 (let (pos)
13002 (save-excursion
13003 (while (and (setq pos (re-search-forward regexp bound noerror count))
13004 (vhdl-in-literal))))
13005 (when pos (goto-char pos))
13006 pos))
13008 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
13009 "Like `re-search-backward', but does not match within literals."
13010 (let (pos)
13011 (save-excursion
13012 (while (and (setq pos (re-search-backward regexp bound noerror count))
13013 (vhdl-in-literal))))
13014 (when pos (goto-char pos))
13015 pos))
13018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13019 ;;; Project
13020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13022 (defun vhdl-set-project (name)
13023 "Set current project to NAME."
13024 (interactive
13025 (list (let ((completion-ignore-case t))
13026 (completing-read "Project name: " vhdl-project-alist nil t))))
13027 (cond ((equal name "")
13028 (setq vhdl-project nil)
13029 (message "Current VHDL project: None"))
13030 ((assoc name vhdl-project-alist)
13031 (setq vhdl-project name)
13032 (message "Current VHDL project: \"%s\"" name))
13034 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
13035 (vhdl-speedbar-update-current-project))
13037 (defun vhdl-set-default-project ()
13038 "Set current project as default on startup."
13039 (interactive)
13040 (customize-set-variable 'vhdl-project vhdl-project)
13041 (customize-save-customized))
13043 (defun vhdl-toggle-project (name token indent)
13044 "Set current project to NAME or unset if NAME is current project."
13045 (vhdl-set-project (if (equal name vhdl-project) "" name)))
13047 (defun vhdl-export-project (file-name)
13048 "Write project setup for current project."
13049 (interactive
13050 (let ((name (vhdl-resolve-env-variable
13051 (vhdl-replace-string
13052 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13053 (concat (subst-char-in-string
13054 ? ?_ (or (vhdl-project-p)
13055 (error "ERROR: No current project")))
13056 " " (user-login-name))))))
13057 (list (read-file-name
13058 "Write project file: "
13059 (when (file-name-absolute-p name) "") nil nil name))))
13060 (setq file-name (abbreviate-file-name file-name))
13061 (let ((orig-buffer (current-buffer)))
13062 (unless (file-exists-p (file-name-directory file-name))
13063 (make-directory (file-name-directory file-name) t))
13064 (if (not (file-writable-p file-name))
13065 (error "ERROR: File not writable: \"%s\"" file-name)
13066 (set-buffer (find-file-noselect file-name t t))
13067 (erase-buffer)
13068 (insert ";; -*- Emacs-Lisp -*-\n\n"
13069 ";;; " (file-name-nondirectory file-name)
13070 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
13071 ";; Project : " vhdl-project "\n"
13072 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
13073 (user-login-name) "\n\n\n"
13074 ";; project name\n"
13075 "(setq vhdl-project \"" vhdl-project "\")\n\n"
13076 ";; project setup\n"
13077 "(vhdl-aput 'vhdl-project-alist vhdl-project\n'")
13078 (pp (vhdl-aget vhdl-project-alist vhdl-project) (current-buffer))
13079 (insert ")\n")
13080 (save-buffer)
13081 (kill-buffer (current-buffer))
13082 (set-buffer orig-buffer))))
13084 (defun vhdl-import-project (file-name &optional auto not-make-current)
13085 "Read project setup and set current project."
13086 (interactive
13087 (let ((name (vhdl-resolve-env-variable
13088 (vhdl-replace-string
13089 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13090 (concat "" " " (user-login-name))))))
13091 (list (read-file-name
13092 "Read project file: " (when (file-name-absolute-p name) "") nil t
13093 (file-name-directory name)))))
13094 (when (file-exists-p file-name)
13095 (condition-case ()
13096 (let ((current-project vhdl-project))
13097 (load-file file-name)
13098 (when (/= (length (vhdl-aget vhdl-project-alist vhdl-project)) 10)
13099 (vhdl-adelete 'vhdl-project-alist vhdl-project)
13100 (error ""))
13101 (if not-make-current
13102 (setq vhdl-project current-project)
13103 (setq vhdl-compiler
13104 (caar (nth 4 (vhdl-aget vhdl-project-alist vhdl-project)))))
13105 (vhdl-update-mode-menu)
13106 (vhdl-speedbar-refresh)
13107 (unless not-make-current
13108 (message "Current VHDL project: \"%s\"; compiler: \"%s\"%s"
13109 vhdl-project vhdl-compiler (if auto " (auto-loaded)" ""))))
13110 (error (vhdl-warning
13111 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
13113 (defun vhdl-duplicate-project ()
13114 "Duplicate setup of current project."
13115 (interactive)
13116 (let ((new-name (read-from-minibuffer "New project name: "))
13117 (project-entry (vhdl-aget vhdl-project-alist vhdl-project)))
13118 (setq vhdl-project-alist
13119 (append vhdl-project-alist
13120 (list (cons new-name project-entry))))
13121 (vhdl-update-mode-menu)))
13123 (defun vhdl-auto-load-project ()
13124 "Automatically load project setup at startup."
13125 (let ((file-name-list vhdl-project-file-name)
13126 file-list list-length)
13127 (while file-name-list
13128 (setq file-list
13129 (append file-list
13130 (file-expand-wildcards
13131 (vhdl-resolve-env-variable
13132 (vhdl-replace-string
13133 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
13134 (concat "* " (user-login-name)))))))
13135 (setq list-length (or list-length (length file-list)))
13136 (setq file-name-list (cdr file-name-list)))
13137 (while file-list
13138 (vhdl-import-project (expand-file-name (car file-list)) t
13139 (not (> list-length 0)))
13140 (setq list-length (1- list-length))
13141 (setq file-list (cdr file-list)))))
13143 ;; automatically load project setup when idle after startup
13144 (when (memq 'startup vhdl-project-auto-load)
13145 (if noninteractive
13146 (vhdl-auto-load-project)
13147 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
13150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13151 ;;; Hideshow
13152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13153 ;; (using `hideshow.el')
13155 (defconst vhdl-hs-start-regexp
13156 (concat
13157 "\\(^\\)\\s-*\\("
13158 ;; generic/port clause
13159 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
13160 ;; component
13161 "component\\>\\|"
13162 ;; component instantiation
13163 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
13164 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13165 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
13166 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
13167 ;; subprogram
13168 "\\(function\\|procedure\\)\\>\\|"
13169 ;; process, block
13170 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13171 ;; configuration declaration
13172 "configuration\\>"
13173 "\\)")
13174 "Regexp to match start of construct to hide.")
13176 (defun vhdl-hs-forward-sexp-func (count)
13177 "Find end of construct to hide (for hideshow). Only searches forward."
13178 (let ((pos (point)))
13179 (vhdl-prepare-search-2
13180 (beginning-of-line)
13181 (cond
13182 ;; generic/port clause
13183 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13184 (goto-char (match-end 0))
13185 (backward-char)
13186 (forward-sexp))
13187 ;; component declaration
13188 ((looking-at "^\\s-*component\\>")
13189 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
13190 ;; component instantiation
13191 ((looking-at
13192 (concat
13193 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13194 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13195 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13196 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13197 (goto-char (match-end 0))
13198 (backward-char)
13199 (forward-sexp)
13200 (setq pos (point))
13201 (vhdl-forward-syntactic-ws)
13202 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13203 (goto-char (match-end 0))
13204 (backward-char)
13205 (forward-sexp)
13206 (setq pos (point)))
13207 (goto-char pos))
13208 ;; subprogram declaration/body
13209 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13210 (goto-char (match-end 0))
13211 (vhdl-forward-syntactic-ws)
13212 (when (looking-at "(")
13213 (forward-sexp))
13214 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
13215 (vhdl-in-literal)))
13216 ;; subprogram body
13217 (when (match-string 2)
13218 (re-search-forward "^\\s-*\\<begin\\>" nil t)
13219 (backward-word-strictly 1)
13220 (vhdl-forward-sexp)))
13221 ;; block (recursive)
13222 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13223 (goto-char (match-end 0))
13224 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
13225 (match-beginning 2))
13226 (vhdl-hs-forward-sexp-func count)))
13227 ;; process
13228 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13229 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
13230 ;; configuration declaration
13231 ((looking-at "^\\s-*configuration\\>")
13232 (forward-word-strictly 4)
13233 (vhdl-forward-sexp))
13234 (t (goto-char pos))))))
13236 (defun vhdl-hideshow-init ()
13237 "Initialize `hideshow'."
13238 (when vhdl-hideshow-menu
13239 (vhdl-hs-minor-mode 1)))
13241 (defun vhdl-hs-minor-mode (&optional arg)
13242 "Toggle hideshow minor mode and update menu bar."
13243 (interactive "P")
13244 (require 'hideshow)
13245 ;; check for hideshow version 5.x
13246 (if (not (boundp 'hs-block-start-mdata-select))
13247 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13248 ;; initialize hideshow
13249 (unless (assoc 'vhdl-mode hs-special-modes-alist)
13250 (setq hs-special-modes-alist
13251 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
13252 'vhdl-hs-forward-sexp-func nil)
13253 hs-special-modes-alist)))
13254 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
13255 (if vhdl-hide-all-init
13256 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
13257 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
13258 (hs-minor-mode arg)
13259 (force-mode-line-update))) ; hack to update menu bar
13262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13263 ;;; Font locking
13264 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13265 ;; (using `font-lock.el')
13267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13268 ;; Help functions
13270 (defun vhdl-within-translate-off ()
13271 "Return point if within translate-off region, else nil."
13272 (and (save-excursion
13273 (re-search-backward
13274 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
13275 (equal "off" (match-string 1))
13276 (point)))
13278 (defun vhdl-start-translate-off (limit)
13279 "Return point before translate-off pragma if before LIMIT, else nil."
13280 (when (re-search-forward
13281 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
13282 (match-beginning 0)))
13284 (defun vhdl-end-translate-off (limit)
13285 "Return point after translate-on pragma if before LIMIT, else nil."
13286 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
13288 (defun vhdl-match-translate-off (limit)
13289 "Match a translate-off block, setting match-data and returning t, else nil."
13290 (when (< (point) limit)
13291 (let ((start (or (vhdl-within-translate-off)
13292 (vhdl-start-translate-off limit)))
13293 (case-fold-search t))
13294 (when start
13295 (let ((end (or (vhdl-end-translate-off limit) limit)))
13296 (set-match-data (list start end))
13297 (goto-char end))))))
13299 (defun vhdl-font-lock-match-item (limit)
13300 "Match, and move over, any declaration item after point. Adapted from
13301 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13302 (condition-case nil
13303 (save-restriction
13304 (narrow-to-region (point-min) limit)
13305 ;; match item
13306 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13307 (save-match-data
13308 (goto-char (match-end 1))
13309 ;; move to next item
13310 (if (looking-at "\\(\\s-*,\\)")
13311 (goto-char (match-end 1))
13312 (end-of-line) t))))
13313 (error t)))
13315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13316 ;; Syntax definitions
13318 (defconst vhdl-font-lock-syntactic-keywords
13319 '(("\\('\\).\\('\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
13320 "Mark single quotes as having string quote syntax in `c' instances.")
13322 (defvar vhdl-font-lock-keywords nil
13323 "Regular expressions to highlight in VHDL Mode.")
13325 (defvar vhdl-font-lock-keywords-0
13326 ;; set in `vhdl-font-lock-init' because dependent on user options
13327 "For consideration as a value of `vhdl-font-lock-keywords'.
13328 This does highlighting of template prompts and directives (pragmas).")
13330 (defvar vhdl-font-lock-keywords-1 nil
13331 ;; set in `vhdl-font-lock-init' because dependent on user options
13332 "For consideration as a value of `vhdl-font-lock-keywords'.
13333 This does highlighting of keywords and standard identifiers.")
13335 (defconst vhdl-font-lock-keywords-2
13336 (list
13337 ;; highlight names of units, subprograms, and components when declared
13338 (list
13339 (concat
13340 "^\\s-*\\("
13341 "architecture\\|configuration\\|context\\|entity\\|package"
13342 "\\(\\s-+body\\)?\\|"
13343 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13344 "\\)\\s-+\\(\\w+\\)")
13345 5 'font-lock-function-name-face)
13347 ;; highlight entity names of architectures and configurations
13348 (list
13349 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13350 2 'font-lock-function-name-face)
13352 ;; highlight labels of common constructs
13353 (list
13354 (concat
13355 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13356 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13357 "postponed\\|process\\|"
13358 (when (vhdl-standard-p 'ams) "procedural\\|")
13359 "with\\|while"
13360 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13361 1 'font-lock-function-name-face)
13363 ;; highlight label and component name of component instantiations
13364 (list
13365 (concat
13366 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13367 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13368 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13370 ;; highlight label and instantiated unit of component instantiations
13371 (list
13372 (concat
13373 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13374 "\\(component\\|configuration\\|entity\\)\\s-+"
13375 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13376 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13377 '(5 font-lock-function-name-face nil t)
13378 '(7 font-lock-function-name-face nil t))
13380 ;; highlight names and labels at end of constructs
13381 (list
13382 (concat
13383 "^\\s-*end\\s-+\\(\\("
13384 "architecture\\|block\\|case\\|component\\|configuration\\|context\\|"
13385 "entity\\|for\\|function\\|generate\\|if\\|loop\\|package"
13386 "\\(\\s-+body\\)?\\|procedure\\|\\(postponed\\s-+\\)?process\\|"
13387 (when (vhdl-standard-p 'ams) "procedural\\|")
13388 "units"
13389 "\\)\\s-+\\)?\\(\\w*\\)")
13390 5 'font-lock-function-name-face)
13392 ;; highlight labels in exit and next statements
13393 (list
13394 (concat
13395 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13396 3 'font-lock-function-name-face)
13398 ;; highlight entity name in attribute specifications
13399 (list
13400 (concat
13401 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13402 1 'font-lock-function-name-face)
13404 ;; highlight labels in block and component specifications
13405 (list
13406 (concat
13407 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13408 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13409 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13411 ;; highlight names in library clauses
13412 (list "^\\s-*library\\>"
13413 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13415 ;; highlight names in use clauses
13416 (list
13417 (concat
13418 "\\<\\(context\\|use\\)\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13419 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13420 '(4 font-lock-function-name-face) '(6 font-lock-function-name-face nil t)
13421 '(8 font-lock-function-name-face nil t))
13423 ;; highlight attribute name in attribute declarations/specifications
13424 (list
13425 (concat
13426 "^\\s-*attribute\\s-+\\(\\w+\\)")
13427 1 'vhdl-font-lock-attribute-face)
13429 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13430 (list
13431 (concat
13432 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13433 5 'font-lock-type-face)
13435 ;; highlight signal/variable/constant declaration names
13436 (list "\\(:[^=]\\)"
13437 '(vhdl-font-lock-match-item
13438 (progn (goto-char (match-beginning 1))
13439 (skip-syntax-backward " ")
13440 (skip-syntax-backward "w_")
13441 (skip-syntax-backward " ")
13442 (while (= (preceding-char) ?,)
13443 (backward-char 1)
13444 (skip-syntax-backward " ")
13445 (skip-syntax-backward "w_")
13446 (skip-syntax-backward " ")))
13447 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13449 ;; highlight formal parameters in component instantiations and subprogram
13450 ;; calls
13451 (list "\\(=>\\)"
13452 '(vhdl-font-lock-match-item
13453 (progn (goto-char (match-beginning 1))
13454 (skip-syntax-backward " ")
13455 (while (= (preceding-char) ?\)) (backward-sexp))
13456 (skip-syntax-backward "w_")
13457 (skip-syntax-backward " ")
13458 (when (memq (preceding-char) '(?n ?N ?|))
13459 (goto-char (point-max))))
13460 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13462 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13463 ;; variables
13464 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13465 '(vhdl-font-lock-match-item
13466 (progn (goto-char (match-end 1)) (match-beginning 2))
13467 nil (1 font-lock-variable-name-face)))
13469 ;; highlight tool directives
13470 (list
13471 (concat
13472 "^\\s-*\\(`\\w+\\)")
13473 1 'font-lock-preprocessor-face)
13475 "For consideration as a value of `vhdl-font-lock-keywords'.
13476 This does context sensitive highlighting of names and labels.")
13478 (defvar vhdl-font-lock-keywords-3 nil
13479 ;; set in `vhdl-font-lock-init' because dependent on user options
13480 "For consideration as a value of `vhdl-font-lock-keywords'.
13481 This does highlighting of words with special syntax.")
13483 (defvar vhdl-font-lock-keywords-4 nil
13484 ;; set in `vhdl-font-lock-init' because dependent on user options
13485 "For consideration as a value of `vhdl-font-lock-keywords'.
13486 This does highlighting of additional reserved words.")
13488 (defconst vhdl-font-lock-keywords-5
13489 ;; background highlight translate-off regions
13490 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13491 "For consideration as a value of `vhdl-font-lock-keywords'.
13492 This does background highlighting of translate-off regions.")
13494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13495 ;; Font and color definitions
13497 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13498 "Face name to use for prompts.")
13500 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13501 "Face name to use for standardized attributes.")
13503 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13504 "Face name to use for standardized enumeration values.")
13506 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13507 "Face name to use for standardized functions and packages.")
13509 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13510 "Face name to use for directives.")
13512 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13513 "Face name to use for additional reserved words.")
13515 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13516 "Face name to use for translate-off regions.")
13518 ;; face names to use for words with special syntax.
13519 (let ((syntax-alist vhdl-special-syntax-alist)
13520 name)
13521 (while syntax-alist
13522 (setq name (vhdl-function-name
13523 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13524 (eval `(defvar ,name ',name
13525 ,(concat "Face name to use for "
13526 (nth 0 (car syntax-alist)) ".")))
13527 (setq syntax-alist (cdr syntax-alist))))
13529 (defgroup vhdl-highlight-faces nil
13530 "Faces for highlighting."
13531 :group 'vhdl-highlight)
13533 ;; add faces used from `font-lock'
13534 (custom-add-to-group
13535 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13536 (custom-add-to-group
13537 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13538 (custom-add-to-group
13539 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13540 (custom-add-to-group
13541 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13542 (custom-add-to-group
13543 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13544 (custom-add-to-group
13545 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13547 (defface vhdl-font-lock-prompt-face
13548 '((((min-colors 88) (class color) (background light))
13549 (:foreground "Red1" :bold t))
13550 (((class color) (background light)) (:foreground "Red" :bold t))
13551 (((class color) (background dark)) (:foreground "Pink" :bold t))
13552 (t (:inverse-video t)))
13553 "Font lock mode face used to highlight prompts."
13554 :group 'vhdl-highlight-faces)
13556 (defface vhdl-font-lock-attribute-face
13557 '((((class color) (background light)) (:foreground "Orchid"))
13558 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13559 (t (:italic t :bold t)))
13560 "Font lock mode face used to highlight standardized attributes."
13561 :group 'vhdl-highlight-faces)
13563 (defface vhdl-font-lock-enumvalue-face
13564 '((((class color) (background light)) (:foreground "SaddleBrown"))
13565 (((class color) (background dark)) (:foreground "BurlyWood"))
13566 (t (:italic t :bold t)))
13567 "Font lock mode face used to highlight standardized enumeration values."
13568 :group 'vhdl-highlight-faces)
13570 (defface vhdl-font-lock-function-face
13571 '((((class color) (background light)) (:foreground "Cyan4"))
13572 (((class color) (background dark)) (:foreground "Orchid1"))
13573 (t (:italic t :bold t)))
13574 "Font lock mode face used to highlight standardized functions and packages."
13575 :group 'vhdl-highlight-faces)
13577 (defface vhdl-font-lock-directive-face
13578 '((((class color) (background light)) (:foreground "CadetBlue"))
13579 (((class color) (background dark)) (:foreground "Aquamarine"))
13580 (t (:italic t :bold t)))
13581 "Font lock mode face used to highlight directives."
13582 :group 'vhdl-highlight-faces)
13584 (defface vhdl-font-lock-reserved-words-face
13585 '((((class color) (background light)) (:foreground "Orange" :bold t))
13586 (((min-colors 88) (class color) (background dark))
13587 (:foreground "Yellow1" :bold t))
13588 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13589 (t ()))
13590 "Font lock mode face used to highlight additional reserved words."
13591 :group 'vhdl-highlight-faces)
13593 (defface vhdl-font-lock-translate-off-face
13594 '((((class color) (background light)) (:background "LightGray"))
13595 (((class color) (background dark)) (:background "DimGray"))
13596 (t ()))
13597 "Font lock mode face used to background highlight translate-off regions."
13598 :group 'vhdl-highlight-faces)
13600 ;; font lock mode faces used to highlight words with special syntax.
13601 (let ((syntax-alist vhdl-special-syntax-alist))
13602 (while syntax-alist
13603 (eval `(defface ,(vhdl-function-name
13604 "vhdl-font-lock" (caar syntax-alist) "face")
13605 '((((class color) (background light))
13606 (:foreground ,(nth 2 (car syntax-alist))))
13607 (((class color) (background dark))
13608 (:foreground ,(nth 3 (car syntax-alist))))
13609 (t ()))
13610 ,(concat "Font lock mode face used to highlight "
13611 (nth 0 (car syntax-alist)) ".")
13612 :group 'vhdl-highlight-faces))
13613 (setq syntax-alist (cdr syntax-alist))))
13615 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13616 ;; Font lock initialization
13618 (defun vhdl-font-lock-init ()
13619 "Initialize fontification."
13620 ;; highlight template prompts and directives
13621 (setq vhdl-font-lock-keywords-0
13622 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13623 vhdl-template-prompt-syntax ">\\)")
13624 2 'vhdl-font-lock-prompt-face t)
13625 (list (concat "--\\s-*"
13626 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13627 2 'vhdl-font-lock-directive-face t)
13628 ;; highlight c-preprocessor directives
13629 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13630 '(1 font-lock-builtin-face)
13631 '(3 font-lock-variable-name-face nil t))))
13632 ;; highlight keywords and standardized types, attributes, enumeration
13633 ;; values, and subprograms
13634 (setq vhdl-font-lock-keywords-1
13635 (list
13636 (list (concat "'" vhdl-attributes-regexp)
13637 1 'vhdl-font-lock-attribute-face)
13638 (list vhdl-types-regexp 1 'font-lock-type-face)
13639 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13640 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13641 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13642 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13643 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13644 ;; highlight words with special syntax.
13645 (setq vhdl-font-lock-keywords-3
13646 (let ((syntax-alist vhdl-special-syntax-alist)
13647 keywords)
13648 (while syntax-alist
13649 (setq keywords
13650 (cons
13651 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13652 (vhdl-function-name
13653 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13654 (nth 4 (car syntax-alist)))
13655 keywords))
13656 (setq syntax-alist (cdr syntax-alist)))
13657 keywords))
13658 ;; highlight additional reserved words
13659 (setq vhdl-font-lock-keywords-4
13660 (list (list vhdl-reserved-words-regexp 1
13661 'vhdl-font-lock-reserved-words-face)))
13662 ;; highlight everything together
13663 (setq vhdl-font-lock-keywords
13664 (append
13665 vhdl-font-lock-keywords-0
13666 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13667 (when (or vhdl-highlight-forbidden-words
13668 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13669 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13670 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13671 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13673 ;; initialize fontification for VHDL Mode
13674 (vhdl-font-lock-init)
13676 (defun vhdl-fontify-buffer ()
13677 "Re-initialize fontification and fontify buffer."
13678 (interactive)
13679 (setq font-lock-defaults
13680 `(vhdl-font-lock-keywords
13681 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13682 beginning-of-line))
13683 (when (fboundp 'font-lock-unset-defaults)
13684 (font-lock-unset-defaults)) ; not implemented in XEmacs
13685 (font-lock-set-defaults)
13686 (font-lock-mode nil)
13687 (font-lock-mode t))
13689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13690 ;; Initialization for PostScript printing
13692 (defun vhdl-ps-print-settings ()
13693 "Initialize custom face and page settings for PostScript printing."
13694 ;; define custom face settings
13695 (unless (or (not vhdl-print-customize-faces)
13696 ps-print-color-p)
13697 (set (make-local-variable 'ps-bold-faces)
13698 '(font-lock-keyword-face
13699 font-lock-type-face
13700 vhdl-font-lock-attribute-face
13701 vhdl-font-lock-enumvalue-face
13702 vhdl-font-lock-directive-face))
13703 (set (make-local-variable 'ps-italic-faces)
13704 '(font-lock-comment-face
13705 font-lock-function-name-face
13706 font-lock-type-face
13707 vhdl-font-lock-attribute-face
13708 vhdl-font-lock-enumvalue-face
13709 vhdl-font-lock-directive-face))
13710 (set (make-local-variable 'ps-underlined-faces)
13711 '(font-lock-string-face))
13712 (setq ps-always-build-face-reference t))
13713 ;; define page settings, so that a line containing 79 characters (default)
13714 ;; fits into one column
13715 (when vhdl-print-two-column
13716 (set (make-local-variable 'ps-landscape-mode) t)
13717 (set (make-local-variable 'ps-number-of-columns) 2)
13718 (set (make-local-variable 'ps-font-size) 7.0)
13719 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13720 (set (make-local-variable 'ps-header-font-size) 9.0)
13721 (set (make-local-variable 'ps-header-offset) 12.0)
13722 (when (eq ps-paper-type 'letter)
13723 (set (make-local-variable 'ps-inter-column) 40.0)
13724 (set (make-local-variable 'ps-left-margin) 40.0)
13725 (set (make-local-variable 'ps-right-margin) 40.0))))
13727 (defun vhdl-ps-print-init ()
13728 "Initialize PostScript printing."
13729 (if (featurep 'xemacs)
13730 (when (boundp 'ps-print-color-p)
13731 (vhdl-ps-print-settings))
13732 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13733 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13736 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13737 ;;; Hierarchy browser (using `speedbar.el')
13738 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13739 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13740 ;; directory by using the speedbar.
13742 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13743 ;; Variables
13745 (defvar vhdl-entity-alist nil
13746 "Cache with entities and corresponding architectures for each
13747 project/directory.")
13748 ;; structure: (parenthesized expression means list of such entries)
13749 ;; (cache-key
13750 ;; (ent-key ent-name ent-file ent-line
13751 ;; (arch-key arch-name arch-file arch-line
13752 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13753 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13754 ;; (lib-name pack-key))
13755 ;; mra-key (lib-name pack-key))
13757 (defvar vhdl-config-alist nil
13758 "Cache with configurations for each project/directory.")
13759 ;; structure: (parenthesized expression means list of such entries)
13760 ;; (cache-key
13761 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13762 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13763 ;; inst-conf-key inst-lib-key)
13764 ;; (lib-name pack-key)))
13766 (defvar vhdl-package-alist nil
13767 "Cache with packages for each project/directory.")
13768 ;; structure: (parenthesized expression means list of such entries)
13769 ;; (cache-key
13770 ;; (pack-key pack-name pack-file pack-line
13771 ;; (comp-key comp-name comp-file comp-line)
13772 ;; (func-key func-name func-file func-line)
13773 ;; (lib-name pack-key)
13774 ;; pack-body-file pack-body-line
13775 ;; (func-key func-name func-body-file func-body-line)
13776 ;; (lib-name pack-key)))
13778 (defvar vhdl-ent-inst-alist nil
13779 "Cache with instantiated entities for each project/directory.")
13780 ;; structure: (parenthesized expression means list of such entries)
13781 ;; (cache-key (inst-ent-key))
13783 (defvar vhdl-file-alist nil
13784 "Cache with design units in each file for each project/directory.")
13785 ;; structure: (parenthesized expression means list of such entries)
13786 ;; (cache-key
13787 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13788 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13790 (defvar vhdl-directory-alist nil
13791 "Cache with source directories for each project.")
13792 ;; structure: (parenthesized expression means list of such entries)
13793 ;; (cache-key (directory))
13795 (defvar vhdl-speedbar-shown-unit-alist nil
13796 "Alist of design units simultaneously open in the current speedbar for each
13797 directory and project.")
13799 (defvar vhdl-speedbar-shown-project-list nil
13800 "List of projects simultaneously open in the current speedbar.")
13802 (defvar vhdl-updated-project-list nil
13803 "List of projects and directories with updated files.")
13805 (defvar vhdl-modified-file-list nil
13806 "List of modified files to be rescanned for hierarchy updating.")
13808 (defvar vhdl-speedbar-hierarchy-depth 0
13809 "Depth of instantiation hierarchy to display.")
13811 (defvar vhdl-speedbar-show-projects nil
13812 "Non-nil means project hierarchy is displayed in speedbar, directory
13813 hierarchy otherwise.")
13815 (defun vhdl-get-end-of-unit ()
13816 "Return position of end of current unit."
13817 (let ((pos (point)))
13818 (save-excursion
13819 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil 1)
13820 (save-excursion
13821 (goto-char (match-beginning 0))
13822 (vhdl-backward-syntactic-ws)
13823 (and (/= (preceding-char) ?\;) (not (bobp))))))
13824 (re-search-backward "^[ \t]*end\\>" pos 1)
13825 (point))))
13827 (defun vhdl-match-string-downcase (num &optional string)
13828 "Like `match-string-no-properties' with down-casing."
13829 (let ((match (match-string-no-properties num string)))
13830 (and match (downcase match))))
13833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13834 ;; Scan functions
13836 (defun vhdl-scan-context-clause ()
13837 "Scan the context clause that precedes a design unit."
13838 (let (lib-alist)
13839 (save-excursion
13840 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil t)
13841 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13842 (equal "USE" (upcase (match-string 1))))
13843 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13844 (push (cons (match-string-no-properties 1)
13845 (vhdl-match-string-downcase 2))
13846 lib-alist)))))
13847 lib-alist))
13849 (defun vhdl-scan-directory-contents (name &optional project update num-string
13850 non-final)
13851 "Scan contents of VHDL files in directory or file pattern NAME."
13852 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13853 (let* ((dir-name (match-string 1 name))
13854 (file-pattern (match-string 2 name))
13855 (is-directory (= 0 (length file-pattern)))
13856 (file-list
13857 (if update
13858 (list name)
13859 (if is-directory
13860 (vhdl-get-source-files t dir-name)
13861 (vhdl-directory-files
13862 dir-name t (wildcard-to-regexp file-pattern)))))
13863 (key (or project dir-name))
13864 (file-exclude-regexp
13865 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
13866 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13867 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13868 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13869 ent-alist conf-alist pack-alist ent-inst-list file-alist
13870 tmp-list tmp-entry no-files files-exist big-files)
13871 (when (or project update)
13872 (setq ent-alist (vhdl-aget vhdl-entity-alist key)
13873 conf-alist (vhdl-aget vhdl-config-alist key)
13874 pack-alist (vhdl-aget vhdl-package-alist key)
13875 ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist key))
13876 file-alist (vhdl-aget vhdl-file-alist key)))
13877 (when (and (not is-directory) (null file-list))
13878 (message "No such file: \"%s\"" name))
13879 (setq files-exist file-list)
13880 (when file-list
13881 (setq no-files (length file-list))
13882 (message "Scanning %s %s\"%s\"..."
13883 (if is-directory "directory" "files") (or num-string "") name)
13884 ;; exclude files
13885 (unless (equal file-exclude-regexp "")
13886 (let ((case-fold-search nil)
13887 file-tmp-list)
13888 (while file-list
13889 (unless (string-match file-exclude-regexp (car file-list))
13890 (push (car file-list) file-tmp-list))
13891 (setq file-list (cdr file-list)))
13892 (setq file-list (nreverse file-tmp-list))))
13893 ;; do for all files
13894 (while file-list
13895 (unless noninteractive
13896 (message "Scanning %s %s\"%s\"... (%2d%%)"
13897 (if is-directory "directory" "files")
13898 (or num-string "") name
13899 (floor (* 100.0 (- no-files (length file-list))) no-files)))
13900 (let ((file-name (abbreviate-file-name (car file-list)))
13901 ent-list arch-list arch-ent-list conf-list
13902 pack-list pack-body-list inst-list inst-ent-list)
13903 ;; scan file
13904 (vhdl-visit-file
13905 file-name nil
13906 (vhdl-prepare-search-2
13907 (save-excursion
13908 ;; scan for design units
13909 (if (and limit-design-file-size
13910 (< limit-design-file-size (buffer-size)))
13911 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13912 (setq big-files t))
13913 ;; scan for entities
13914 (goto-char (point-min))
13915 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13916 (let* ((ent-name (match-string-no-properties 1))
13917 (ent-key (downcase ent-name))
13918 (ent-entry (vhdl-aget ent-alist ent-key))
13919 (lib-alist (vhdl-scan-context-clause)))
13920 (if (nth 1 ent-entry)
13921 (vhdl-warning-when-idle
13922 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13923 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13924 file-name (vhdl-current-line))
13925 (push ent-key ent-list)
13926 (vhdl-aput 'ent-alist ent-key
13927 (list ent-name file-name (vhdl-current-line)
13928 (nth 3 ent-entry) (nth 4 ent-entry)
13929 lib-alist)))))
13930 ;; scan for architectures
13931 (goto-char (point-min))
13932 (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)
13933 (let* ((arch-name (match-string-no-properties 1))
13934 (arch-key (downcase arch-name))
13935 (ent-name (match-string-no-properties 2))
13936 (ent-key (downcase ent-name))
13937 (ent-entry (vhdl-aget ent-alist ent-key))
13938 (arch-alist (nth 3 ent-entry))
13939 (arch-entry (vhdl-aget arch-alist arch-key))
13940 (lib-arch-alist (vhdl-scan-context-clause)))
13941 (if arch-entry
13942 (vhdl-warning-when-idle
13943 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13944 arch-name ent-name (nth 1 arch-entry)
13945 (nth 2 arch-entry) file-name (vhdl-current-line))
13946 (setq arch-list (cons arch-key arch-list)
13947 arch-ent-list (cons ent-key arch-ent-list))
13948 (vhdl-aput 'arch-alist arch-key
13949 (list arch-name file-name (vhdl-current-line)
13950 nil lib-arch-alist))
13951 (vhdl-aput 'ent-alist ent-key
13952 (list (or (nth 0 ent-entry) ent-name)
13953 (nth 1 ent-entry) (nth 2 ent-entry)
13954 (vhdl-sort-alist arch-alist)
13955 arch-key (nth 5 ent-entry))))))
13956 ;; scan for configurations
13957 (goto-char (point-min))
13958 (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)
13959 (let* ((conf-name (match-string-no-properties 1))
13960 (conf-key (downcase conf-name))
13961 (conf-entry (vhdl-aget conf-alist conf-key))
13962 (ent-name (match-string-no-properties 2))
13963 (ent-key (downcase ent-name))
13964 (lib-alist (vhdl-scan-context-clause))
13965 (conf-line (vhdl-current-line))
13966 (end-of-unit (vhdl-get-end-of-unit))
13967 arch-key comp-conf-list inst-key-list
13968 inst-comp-key inst-ent-key inst-arch-key
13969 inst-conf-key inst-lib-key)
13970 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13971 (setq arch-key (vhdl-match-string-downcase 1)))
13972 (if conf-entry
13973 (vhdl-warning-when-idle
13974 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13975 conf-name ent-name (nth 1 conf-entry)
13976 (nth 2 conf-entry) file-name conf-line)
13977 (push conf-key conf-list)
13978 ;; scan for subconfigurations and subentities
13979 (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)
13980 (setq inst-comp-key (vhdl-match-string-downcase 3)
13981 inst-key-list (split-string
13982 (vhdl-match-string-downcase 1)
13983 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13984 (vhdl-forward-syntactic-ws)
13985 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13986 (setq
13987 inst-lib-key (vhdl-match-string-downcase 3)
13988 inst-ent-key (and (match-string 2)
13989 (vhdl-match-string-downcase 4))
13990 inst-arch-key (and (match-string 2)
13991 (vhdl-match-string-downcase 6))
13992 inst-conf-key (and (not (match-string 2))
13993 (vhdl-match-string-downcase 4)))
13994 (while inst-key-list
13995 (setq comp-conf-list
13996 (cons (list (car inst-key-list)
13997 inst-comp-key inst-ent-key
13998 inst-arch-key inst-conf-key
13999 inst-lib-key)
14000 comp-conf-list))
14001 (setq inst-key-list (cdr inst-key-list)))))
14002 (vhdl-aput 'conf-alist conf-key
14003 (list conf-name file-name conf-line ent-key
14004 arch-key comp-conf-list lib-alist)))))
14005 ;; scan for packages
14006 (goto-char (point-min))
14007 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
14008 (let* ((pack-name (match-string-no-properties 2))
14009 (pack-key (downcase pack-name))
14010 (is-body (match-string-no-properties 1))
14011 (pack-entry (vhdl-aget pack-alist pack-key))
14012 (pack-line (vhdl-current-line))
14013 (end-of-unit (vhdl-get-end-of-unit))
14014 comp-name func-name comp-alist func-alist lib-alist)
14015 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14016 (vhdl-warning-when-idle
14017 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
14018 (if is-body " body" "") pack-name
14019 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14020 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
14021 file-name (vhdl-current-line))
14022 ;; scan for context clauses
14023 (setq lib-alist (vhdl-scan-context-clause))
14024 ;; scan for component and subprogram declarations/bodies
14025 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
14026 (if (equal (upcase (match-string 1)) "COMPONENT")
14027 (setq comp-name (match-string-no-properties 2)
14028 comp-alist
14029 (cons (list (downcase comp-name) comp-name
14030 file-name (vhdl-current-line))
14031 comp-alist))
14032 (setq func-name (match-string-no-properties 2)
14033 func-alist
14034 (cons (list (downcase func-name) func-name
14035 file-name (vhdl-current-line))
14036 func-alist))))
14037 (setq func-alist (nreverse func-alist))
14038 (setq comp-alist (nreverse comp-alist))
14039 (if is-body
14040 (push pack-key pack-body-list)
14041 (push pack-key pack-list))
14042 (vhdl-aput
14043 'pack-alist pack-key
14044 (if is-body
14045 (list (or (nth 0 pack-entry) pack-name)
14046 (nth 1 pack-entry) (nth 2 pack-entry)
14047 (nth 3 pack-entry) (nth 4 pack-entry)
14048 (nth 5 pack-entry)
14049 file-name pack-line func-alist lib-alist)
14050 (list pack-name file-name pack-line
14051 comp-alist func-alist lib-alist
14052 (nth 6 pack-entry) (nth 7 pack-entry)
14053 (nth 8 pack-entry) (nth 9 pack-entry))))))))
14054 ;; scan for hierarchy
14055 (if (and limit-hier-file-size
14056 (< limit-hier-file-size (buffer-size)))
14057 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
14058 (setq big-files t))
14059 ;; scan for architectures
14060 (goto-char (point-min))
14061 (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)
14062 (let* ((ent-name (match-string-no-properties 2))
14063 (ent-key (downcase ent-name))
14064 (arch-name (match-string-no-properties 1))
14065 (arch-key (downcase arch-name))
14066 (ent-entry (vhdl-aget ent-alist ent-key))
14067 (arch-alist (nth 3 ent-entry))
14068 (arch-entry (vhdl-aget arch-alist arch-key))
14069 (beg-of-unit (point))
14070 (end-of-unit (vhdl-get-end-of-unit))
14071 (inst-no 0)
14072 inst-alist inst-path)
14073 ;; scan for contained instantiations
14074 (while (and (re-search-forward
14075 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
14076 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
14077 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
14078 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
14079 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
14080 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
14081 (or (not limit-hier-inst-no)
14082 (<= (if (or (match-string 14)
14083 (match-string 16))
14084 inst-no
14085 (setq inst-no (1+ inst-no)))
14086 limit-hier-inst-no)))
14087 (cond
14088 ;; block/generate beginning found
14089 ((match-string 14)
14090 (setq inst-path
14091 (cons (match-string-no-properties 1) inst-path)))
14092 ;; block/generate end found
14093 ((match-string 16)
14094 (setq inst-path (cdr inst-path)))
14095 ;; instantiation found
14097 (let* ((inst-name (match-string-no-properties 1))
14098 (inst-key (downcase inst-name))
14099 (inst-comp-name
14100 (or (match-string-no-properties 3)
14101 (match-string-no-properties 6)))
14102 (inst-ent-key
14103 (or (and (match-string 8)
14104 (vhdl-match-string-downcase 11))
14105 (and inst-comp-name
14106 (downcase inst-comp-name))))
14107 (inst-arch-key (vhdl-match-string-downcase 13))
14108 (inst-conf-key
14109 (and (not (match-string 8))
14110 (vhdl-match-string-downcase 11)))
14111 (inst-lib-key (vhdl-match-string-downcase 10)))
14112 (goto-char (match-end 1))
14113 (setq inst-list (cons inst-key inst-list)
14114 inst-ent-list
14115 (cons inst-ent-key inst-ent-list))
14116 (setq inst-alist
14117 (append
14118 inst-alist
14119 (list (list inst-key inst-name file-name
14120 (vhdl-current-line) inst-comp-name
14121 inst-ent-key inst-arch-key
14122 inst-conf-key inst-lib-key
14123 (reverse inst-path)))))))))
14124 ;; scan for contained configuration specifications
14125 (goto-char beg-of-unit)
14126 (while (re-search-forward
14127 (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]*\\)*"
14128 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
14129 (let* ((inst-comp-name (match-string-no-properties 3))
14130 (inst-ent-key
14131 (and (match-string 6)
14132 (vhdl-match-string-downcase 9)))
14133 (inst-arch-key (vhdl-match-string-downcase 11))
14134 (inst-conf-key
14135 (and (not (match-string 6))
14136 (vhdl-match-string-downcase 9)))
14137 (inst-lib-key (vhdl-match-string-downcase 8))
14138 (inst-key-list
14139 (split-string (vhdl-match-string-downcase 1)
14140 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
14141 (tmp-inst-alist inst-alist)
14142 inst-entry)
14143 (while tmp-inst-alist
14144 (when (and (or (equal "all" (car inst-key-list))
14145 (member (nth 0 (car tmp-inst-alist))
14146 inst-key-list))
14147 (equal
14148 (downcase
14149 (or (nth 4 (car tmp-inst-alist)) ""))
14150 (downcase inst-comp-name)))
14151 (setq inst-entry (car tmp-inst-alist))
14152 (setq inst-ent-list
14153 (cons (or inst-ent-key (nth 5 inst-entry))
14154 (vhdl-delete
14155 (nth 5 inst-entry) inst-ent-list)))
14156 (setq inst-entry
14157 (list (nth 0 inst-entry) (nth 1 inst-entry)
14158 (nth 2 inst-entry) (nth 3 inst-entry)
14159 (nth 4 inst-entry)
14160 (or inst-ent-key (nth 5 inst-entry))
14161 (or inst-arch-key (nth 6 inst-entry))
14162 inst-conf-key inst-lib-key))
14163 (setcar tmp-inst-alist inst-entry))
14164 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
14165 ;; save in cache
14166 (vhdl-aput 'arch-alist arch-key
14167 (list (nth 0 arch-entry) (nth 1 arch-entry)
14168 (nth 2 arch-entry) inst-alist
14169 (nth 4 arch-entry)))
14170 (vhdl-aput 'ent-alist ent-key
14171 (list (nth 0 ent-entry) (nth 1 ent-entry)
14172 (nth 2 ent-entry)
14173 (vhdl-sort-alist arch-alist)
14174 (nth 4 ent-entry) (nth 5 ent-entry)))
14175 (when (and limit-hier-inst-no
14176 (> inst-no limit-hier-inst-no))
14177 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
14178 (setq big-files t))
14179 (goto-char end-of-unit))))
14180 ;; remember design units for this file
14181 (vhdl-aput 'file-alist file-name
14182 (list ent-list arch-list arch-ent-list conf-list
14183 pack-list pack-body-list
14184 inst-list inst-ent-list))
14185 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
14186 (setq file-list (cdr file-list))))
14187 (when (or (and (not project) files-exist)
14188 (and project (not non-final)))
14189 ;; consistency checks:
14190 ;; check whether each architecture has a corresponding entity
14191 (setq tmp-list ent-alist)
14192 (while tmp-list
14193 (when (null (nth 2 (car tmp-list)))
14194 (setq tmp-entry (car (nth 4 (car tmp-list))))
14195 (vhdl-warning-when-idle
14196 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14197 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
14198 (nth 3 tmp-entry)))
14199 (setq tmp-list (cdr tmp-list)))
14200 ;; check whether configuration has a corresponding entity/architecture
14201 (setq tmp-list conf-alist)
14202 (while tmp-list
14203 (if (setq tmp-entry (vhdl-aget ent-alist (nth 4 (car tmp-list))))
14204 (unless (vhdl-aget (nth 3 tmp-entry) (nth 5 (car tmp-list)))
14205 (setq tmp-entry (car tmp-list))
14206 (vhdl-warning-when-idle
14207 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14208 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
14209 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14210 (setq tmp-entry (car tmp-list))
14211 (vhdl-warning-when-idle
14212 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14213 (nth 1 tmp-entry) (nth 4 tmp-entry)
14214 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14215 (setq tmp-list (cdr tmp-list)))
14216 ;; check whether each package body has a package declaration
14217 (setq tmp-list pack-alist)
14218 (while tmp-list
14219 (when (null (nth 2 (car tmp-list)))
14220 (setq tmp-entry (car tmp-list))
14221 (vhdl-warning-when-idle
14222 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14223 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
14224 (setq tmp-list (cdr tmp-list)))
14225 ;; sort lists
14226 (setq ent-alist (vhdl-sort-alist ent-alist))
14227 (setq conf-alist (vhdl-sort-alist conf-alist))
14228 (setq pack-alist (vhdl-sort-alist pack-alist))
14229 ;; remember updated directory/project
14230 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
14231 ;; clear directory alists
14232 (unless project
14233 (vhdl-adelete 'vhdl-entity-alist key)
14234 (vhdl-adelete 'vhdl-config-alist key)
14235 (vhdl-adelete 'vhdl-package-alist key)
14236 (vhdl-adelete 'vhdl-ent-inst-alist key)
14237 (vhdl-adelete 'vhdl-file-alist key))
14238 ;; put directory contents into cache
14239 (vhdl-aput 'vhdl-entity-alist key ent-alist)
14240 (vhdl-aput 'vhdl-config-alist key conf-alist)
14241 (vhdl-aput 'vhdl-package-alist key pack-alist)
14242 (vhdl-aput 'vhdl-ent-inst-alist key (list ent-inst-list))
14243 (vhdl-aput 'vhdl-file-alist key file-alist)
14244 ;; final messages
14245 (message "Scanning %s %s\"%s\"...done"
14246 (if is-directory "directory" "files") (or num-string "") name)
14247 (unless project (message "Scanning directory...done"))
14248 (when big-files
14249 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14250 ;; save cache when scanned non-interactively
14251 (when (or (not project) (not non-final))
14252 (when (and noninteractive vhdl-speedbar-save-cache)
14253 (vhdl-save-cache key)))
14256 (defun vhdl-scan-project-contents (project)
14257 "Scan the contents of all VHDL files found in the directories and files
14258 of PROJECT."
14259 (let ((dir-list (or (nth 2 (vhdl-aget vhdl-project-alist project)) '("")))
14260 (default-dir (vhdl-resolve-env-variable
14261 (nth 1 (vhdl-aget vhdl-project-alist project))))
14262 (file-exclude-regexp
14263 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
14264 dir-list-tmp dir dir-name num-dir act-dir recursive)
14265 ;; clear project alists
14266 (vhdl-adelete 'vhdl-entity-alist project)
14267 (vhdl-adelete 'vhdl-config-alist project)
14268 (vhdl-adelete 'vhdl-package-alist project)
14269 (vhdl-adelete 'vhdl-ent-inst-alist project)
14270 (vhdl-adelete 'vhdl-file-alist project)
14271 ;; expand directory names by default-directory
14272 (message "Collecting source files...")
14273 (while dir-list
14274 (setq dir (vhdl-resolve-env-variable (car dir-list)))
14275 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
14276 (setq recursive (match-string 1 dir)
14277 dir-name (match-string 3 dir))
14278 (setq dir-list-tmp
14279 (cons (concat recursive
14280 (if (file-name-absolute-p dir-name) "" default-dir)
14281 dir-name)
14282 dir-list-tmp))
14283 (setq dir-list (cdr dir-list)))
14284 ;; resolve path wildcards
14285 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
14286 ;; expand directories
14287 (while dir-list-tmp
14288 (setq dir (car dir-list-tmp))
14289 ;; get subdirectories
14290 (if (string-match "-r \\(.*[/\\]\\)" dir)
14291 (setq dir-list (append dir-list (vhdl-get-subdirs
14292 (match-string 1 dir))))
14293 (setq dir-list (append dir-list (list dir))))
14294 (setq dir-list-tmp (cdr dir-list-tmp)))
14295 ;; exclude files
14296 (unless (equal file-exclude-regexp "")
14297 (let ((case-fold-search nil))
14298 (while dir-list
14299 (unless (string-match file-exclude-regexp (car dir-list))
14300 (push (car dir-list) dir-list-tmp))
14301 (setq dir-list (cdr dir-list)))
14302 (setq dir-list (nreverse dir-list-tmp))))
14303 (message "Collecting source files...done")
14304 ;; scan for design units for each directory in DIR-LIST
14305 (setq dir-list-tmp nil
14306 num-dir (length dir-list)
14307 act-dir 1)
14308 (while dir-list
14309 (setq dir-name (abbreviate-file-name
14310 (expand-file-name (car dir-list))))
14311 (vhdl-scan-directory-contents dir-name project nil
14312 (format "(%s/%s) " act-dir num-dir)
14313 (cdr dir-list))
14314 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
14315 (setq dir-list (cdr dir-list)
14316 act-dir (1+ act-dir)))
14317 (vhdl-aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
14318 (message "Scanning project \"%s\"...done" project)))
14320 (defun vhdl-update-file-contents (file-name)
14321 "Update hierarchy information by contents of current buffer."
14322 (setq file-name (abbreviate-file-name file-name))
14323 (let* ((dir-name (file-name-directory file-name))
14324 (directory-alist vhdl-directory-alist)
14325 updated)
14326 (while directory-alist
14327 (when (member dir-name (nth 1 (car directory-alist)))
14328 (let* ((vhdl-project (nth 0 (car directory-alist)))
14329 (project (vhdl-project-p))
14330 (ent-alist (vhdl-aget vhdl-entity-alist
14331 (or project dir-name)))
14332 (conf-alist (vhdl-aget vhdl-config-alist
14333 (or project dir-name)))
14334 (pack-alist (vhdl-aget vhdl-package-alist
14335 (or project dir-name)))
14336 (ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist
14337 (or project dir-name))))
14338 (file-alist (vhdl-aget vhdl-file-alist (or project dir-name)))
14339 (file-entry (vhdl-aget file-alist file-name))
14340 (ent-list (nth 0 file-entry))
14341 (arch-list (nth 1 file-entry))
14342 (arch-ent-list (nth 2 file-entry))
14343 (conf-list (nth 3 file-entry))
14344 (pack-list (nth 4 file-entry))
14345 (pack-body-list (nth 5 file-entry))
14346 (inst-ent-list (nth 7 file-entry))
14347 (cache-key (or project dir-name))
14348 arch-alist key ent-key entry)
14349 ;; delete design units previously contained in this file:
14350 ;; entities
14351 (while ent-list
14352 (setq key (car ent-list)
14353 entry (vhdl-aget ent-alist key))
14354 (when (equal file-name (nth 1 entry))
14355 (if (nth 3 entry)
14356 (vhdl-aput 'ent-alist key
14357 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14358 (vhdl-adelete 'ent-alist key)))
14359 (setq ent-list (cdr ent-list)))
14360 ;; architectures
14361 (while arch-list
14362 (setq key (car arch-list)
14363 ent-key (car arch-ent-list)
14364 entry (vhdl-aget ent-alist ent-key)
14365 arch-alist (nth 3 entry))
14366 (when (equal file-name (nth 1 (vhdl-aget arch-alist key)))
14367 (vhdl-adelete 'arch-alist key)
14368 (if (or (nth 1 entry) arch-alist)
14369 (vhdl-aput 'ent-alist ent-key
14370 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14371 arch-alist (nth 4 entry) (nth 5 entry)))
14372 (vhdl-adelete 'ent-alist ent-key)))
14373 (setq arch-list (cdr arch-list)
14374 arch-ent-list (cdr arch-ent-list)))
14375 ;; configurations
14376 (while conf-list
14377 (setq key (car conf-list))
14378 (when (equal file-name (nth 1 (vhdl-aget conf-alist key)))
14379 (vhdl-adelete 'conf-alist key))
14380 (setq conf-list (cdr conf-list)))
14381 ;; package declarations
14382 (while pack-list
14383 (setq key (car pack-list)
14384 entry (vhdl-aget pack-alist key))
14385 (when (equal file-name (nth 1 entry))
14386 (if (nth 6 entry)
14387 (vhdl-aput 'pack-alist key
14388 (list (nth 0 entry) nil nil nil nil nil
14389 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14390 (nth 9 entry)))
14391 (vhdl-adelete 'pack-alist key)))
14392 (setq pack-list (cdr pack-list)))
14393 ;; package bodies
14394 (while pack-body-list
14395 (setq key (car pack-body-list)
14396 entry (vhdl-aget pack-alist key))
14397 (when (equal file-name (nth 6 entry))
14398 (if (nth 1 entry)
14399 (vhdl-aput 'pack-alist key
14400 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14401 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14402 nil nil nil nil))
14403 (vhdl-adelete 'pack-alist key)))
14404 (setq pack-body-list (cdr pack-body-list)))
14405 ;; instantiated entities
14406 (while inst-ent-list
14407 (setq ent-inst-list
14408 (vhdl-delete (car inst-ent-list) ent-inst-list))
14409 (setq inst-ent-list (cdr inst-ent-list)))
14410 ;; update caches
14411 (vhdl-aput-delete-if-nil 'vhdl-entity-alist cache-key ent-alist)
14412 (vhdl-aput-delete-if-nil 'vhdl-config-alist cache-key conf-alist)
14413 (vhdl-aput-delete-if-nil 'vhdl-package-alist cache-key pack-alist)
14414 (vhdl-aput-delete-if-nil 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14415 ;; scan file
14416 (vhdl-scan-directory-contents file-name project t)
14417 (when (or (and vhdl-speedbar-show-projects project)
14418 (and (not vhdl-speedbar-show-projects) (not project)))
14419 (vhdl-speedbar-refresh project))
14420 (setq updated t)))
14421 (setq directory-alist (cdr directory-alist)))
14422 updated))
14424 (defun vhdl-update-hierarchy ()
14425 "Update directory and hierarchy information in speedbar."
14426 (let ((file-list (reverse vhdl-modified-file-list))
14427 updated)
14428 (when (and vhdl-speedbar-update-on-saving file-list)
14429 (while file-list
14430 (setq updated
14431 (or (vhdl-update-file-contents (car file-list))
14432 updated))
14433 (setq file-list (cdr file-list)))
14434 (setq vhdl-modified-file-list nil)
14435 (vhdl-speedbar-update-current-unit)
14436 (when updated (message "Updating hierarchy...done")))))
14438 ;; structure (parenthesized expression means list of such entries)
14439 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14440 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14441 ;; comp-lib-name level)
14442 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14443 conf-inst-alist level indent
14444 &optional include-top ent-hier)
14445 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14446 entity ENT-KEY."
14447 (let* ((ent-entry (vhdl-aget ent-alist ent-key))
14448 (arch-entry (if arch-key (vhdl-aget (nth 3 ent-entry) arch-key)
14449 (cdar (last (nth 3 ent-entry)))))
14450 (inst-alist (nth 3 arch-entry))
14451 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14452 hier-list subcomp-list tmp-list inst-key inst-comp-name
14453 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14454 (when (= level 0) (message "Extract design hierarchy..."))
14455 (when include-top
14456 (setq level (1+ level)))
14457 (when (member ent-key ent-hier)
14458 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14459 ;; process all instances
14460 (while inst-alist
14461 (setq inst-entry (car inst-alist)
14462 inst-key (nth 0 inst-entry)
14463 inst-comp-name (nth 4 inst-entry)
14464 inst-conf-key (nth 7 inst-entry))
14465 ;; search entry in configuration's instantiations list
14466 (setq tmp-list conf-inst-alist)
14467 (while (and tmp-list
14468 (not (and (member (nth 0 (car tmp-list))
14469 (list "all" inst-key))
14470 (equal (nth 1 (car tmp-list))
14471 (downcase (or inst-comp-name ""))))))
14472 (setq tmp-list (cdr tmp-list)))
14473 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14474 (setq inst-conf-entry (vhdl-aget conf-alist inst-conf-key))
14475 (when (and inst-conf-key (not inst-conf-entry))
14476 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14477 ;; determine entity
14478 (setq inst-ent-key
14479 (or (nth 2 (car tmp-list)) ; from configuration
14480 (nth 3 inst-conf-entry) ; from subconfiguration
14481 (nth 3 (vhdl-aget conf-alist (nth 7 inst-entry)))
14482 ; from configuration spec.
14483 (nth 5 inst-entry))) ; from direct instantiation
14484 (setq inst-ent-entry (vhdl-aget ent-alist inst-ent-key))
14485 ;; determine architecture
14486 (setq inst-arch-key
14487 (or (nth 3 (car tmp-list)) ; from configuration
14488 (nth 4 inst-conf-entry) ; from subconfiguration
14489 (nth 6 inst-entry) ; from direct instantiation
14490 (nth 4 (vhdl-aget conf-alist (nth 7 inst-entry)))
14491 ; from configuration spec.
14492 (nth 4 inst-ent-entry) ; MRA
14493 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14494 (setq inst-arch-entry (vhdl-aget (nth 3 inst-ent-entry) inst-arch-key))
14495 ;; set library
14496 (setq inst-lib-key
14497 (or (nth 5 (car tmp-list)) ; from configuration
14498 (nth 8 inst-entry))) ; from direct instantiation
14499 ;; gather information for this instance
14500 (setq comp-entry
14501 (list (nth 1 inst-entry)
14502 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14503 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14504 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14505 (or (nth 0 inst-arch-entry) inst-arch-key)
14506 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14507 (or (nth 0 inst-conf-entry) inst-conf-key)
14508 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14509 inst-lib-key level))
14510 ;; get subcomponent hierarchy
14511 (setq subcomp-list (vhdl-get-hierarchy
14512 ent-alist conf-alist
14513 inst-ent-key inst-arch-key inst-conf-key
14514 (nth 5 inst-conf-entry)
14515 (1+ level) indent nil (cons ent-key ent-hier)))
14516 ;; add to list
14517 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14518 (setq inst-alist (cdr inst-alist)))
14519 (when include-top
14520 (setq hier-list
14521 (cons (list nil nil (nth 0 ent-entry)
14522 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14523 (nth 0 arch-entry)
14524 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14525 nil nil
14526 nil (1- level))
14527 hier-list)))
14528 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14529 hier-list))
14531 (defun vhdl-get-instantiations (ent-key indent)
14532 "Get all instantiations of entity ENT-KEY."
14533 (let ((ent-alist (vhdl-aget vhdl-entity-alist
14534 (vhdl-speedbar-line-key indent)))
14535 arch-alist inst-alist ent-inst-list
14536 ent-entry arch-entry inst-entry)
14537 (while ent-alist
14538 (setq ent-entry (car ent-alist))
14539 (setq arch-alist (nth 4 ent-entry))
14540 (while arch-alist
14541 (setq arch-entry (car arch-alist))
14542 (setq inst-alist (nth 4 arch-entry))
14543 (while inst-alist
14544 (setq inst-entry (car inst-alist))
14545 (when (equal ent-key (nth 5 inst-entry))
14546 (setq ent-inst-list
14547 (cons (list (nth 1 inst-entry)
14548 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14549 (nth 1 ent-entry)
14550 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14551 (nth 1 arch-entry)
14552 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14553 ent-inst-list)))
14554 (setq inst-alist (cdr inst-alist)))
14555 (setq arch-alist (cdr arch-alist)))
14556 (setq ent-alist (cdr ent-alist)))
14557 (nreverse ent-inst-list)))
14559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14560 ;; Caching in file
14562 (defun vhdl-save-caches ()
14563 "Save all updated hierarchy caches to file."
14564 (interactive)
14565 (condition-case nil
14566 (when vhdl-speedbar-save-cache
14567 ;; update hierarchy
14568 (vhdl-update-hierarchy)
14569 (let ((project-list vhdl-updated-project-list))
14570 (message "Saving hierarchy caches...")
14571 ;; write updated project caches
14572 (while project-list
14573 (vhdl-save-cache (car project-list))
14574 (setq project-list (cdr project-list)))
14575 (message "Saving hierarchy caches...done")))
14576 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14577 (sit-for 2)))))
14579 (defun vhdl-save-cache (key)
14580 "Save current hierarchy cache to file."
14581 (let* ((orig-buffer (current-buffer))
14582 (vhdl-project key)
14583 (project (vhdl-project-p))
14584 (default-directory key)
14585 (directory (abbreviate-file-name (vhdl-default-directory)))
14586 (file-name (vhdl-resolve-env-variable
14587 (vhdl-replace-string
14588 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14589 (concat
14590 (subst-char-in-string ? ?_ (or project "dir"))
14591 " " (user-login-name)))))
14592 (file-dir-name (expand-file-name file-name directory))
14593 (cache-key (or project directory))
14594 (key (if project "project" "directory")))
14595 (unless (file-exists-p (file-name-directory file-dir-name))
14596 (make-directory (file-name-directory file-dir-name) t))
14597 (if (not (file-writable-p file-dir-name))
14598 (progn (vhdl-warning (format "File not writable: \"%s\""
14599 (abbreviate-file-name file-dir-name)))
14600 (sit-for 2))
14601 (message "Saving cache: \"%s\"" file-dir-name)
14602 (set-buffer (find-file-noselect file-dir-name t t))
14603 (erase-buffer)
14604 (insert ";; -*- Emacs-Lisp -*-\n\n"
14605 ";;; " (file-name-nondirectory file-name)
14606 " - design hierarchy cache file for Emacs VHDL Mode "
14607 vhdl-version "\n")
14608 (insert "\n;; " (if project "Project " "Directory") " : ")
14609 (if project (insert project) (prin1 directory (current-buffer)))
14610 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14611 (user-login-name) "\n\n"
14612 "\n;; version number\n"
14613 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14614 "\n;; " (if project "project" "directory") " name"
14615 "\n(setq " key " ")
14616 (prin1 (or project directory) (current-buffer))
14617 (insert ")\n")
14618 (when (member 'hierarchy vhdl-speedbar-save-cache)
14619 (insert "\n;; entity and architecture cache\n"
14620 "(vhdl-aput 'vhdl-entity-alist " key " '")
14621 (print (vhdl-aget vhdl-entity-alist cache-key) (current-buffer))
14622 (insert ")\n\n;; configuration cache\n"
14623 "(vhdl-aput 'vhdl-config-alist " key " '")
14624 (print (vhdl-aget vhdl-config-alist cache-key) (current-buffer))
14625 (insert ")\n\n;; package cache\n"
14626 "(vhdl-aput 'vhdl-package-alist " key " '")
14627 (print (vhdl-aget vhdl-package-alist cache-key) (current-buffer))
14628 (insert ")\n\n;; instantiated entities cache\n"
14629 "(vhdl-aput 'vhdl-ent-inst-alist " key " '")
14630 (print (vhdl-aget vhdl-ent-inst-alist cache-key) (current-buffer))
14631 (insert ")\n\n;; design units per file cache\n"
14632 "(vhdl-aput 'vhdl-file-alist " key " '")
14633 (print (vhdl-aget vhdl-file-alist cache-key) (current-buffer))
14634 (when project
14635 (insert ")\n\n;; source directories in project cache\n"
14636 "(vhdl-aput 'vhdl-directory-alist " key " '")
14637 (print (vhdl-aget vhdl-directory-alist cache-key) (current-buffer)))
14638 (insert ")\n"))
14639 (when (member 'display vhdl-speedbar-save-cache)
14640 (insert "\n;; shown design units cache\n"
14641 "(vhdl-aput 'vhdl-speedbar-shown-unit-alist " key " '")
14642 (print (vhdl-aget vhdl-speedbar-shown-unit-alist cache-key)
14643 (current-buffer))
14644 (insert ")\n"))
14645 (setq vhdl-updated-project-list
14646 (delete cache-key vhdl-updated-project-list))
14647 (save-buffer)
14648 (kill-buffer (current-buffer))
14649 (set-buffer orig-buffer))))
14651 (defun vhdl-load-cache (key)
14652 "Load hierarchy cache information from file."
14653 (let* ((vhdl-project key)
14654 (default-directory key)
14655 (directory (vhdl-default-directory))
14656 (file-name (vhdl-resolve-env-variable
14657 (vhdl-replace-string
14658 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14659 (concat
14660 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14661 " " (user-login-name)))))
14662 (file-dir-name (expand-file-name file-name directory))
14663 vhdl-cache-version)
14664 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14665 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14666 (when (file-exists-p file-dir-name)
14667 (condition-case ()
14668 (progn (load-file file-dir-name)
14669 (string< (mapconcat
14670 (lambda (a) (format "%3d" (string-to-number a)))
14671 (split-string "3.33" "\\.") "")
14672 (mapconcat
14673 (lambda (a) (format "%3d" (string-to-number a)))
14674 (split-string vhdl-cache-version "\\.") "")))
14675 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14676 nil))))))
14678 (defun vhdl-require-hierarchy-info ()
14679 "Make sure that hierarchy information is available. Load cache or scan files
14680 if required."
14681 (if (vhdl-project-p)
14682 (unless (or (assoc vhdl-project vhdl-file-alist)
14683 (vhdl-load-cache vhdl-project))
14684 (vhdl-scan-project-contents vhdl-project))
14685 (let ((directory (abbreviate-file-name default-directory)))
14686 (unless (or (assoc directory vhdl-file-alist)
14687 (vhdl-load-cache directory))
14688 (vhdl-scan-directory-contents directory)))))
14690 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14691 ;; Add hierarchy browser functionality to speedbar
14693 (defvar vhdl-speedbar-mode-map nil
14694 "Keymap used when in the VHDL hierarchy browser mode.")
14696 (defvar vhdl-speedbar-menu-items nil
14697 "Additional menu-items to add to speedbar frame.")
14699 (declare-function speedbar-add-supported-extension "speedbar" (extension))
14700 (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
14701 (declare-function speedbar-make-specialized-keymap "speedbar" ())
14702 (declare-function speedbar-change-initial-expansion-list "speedbar"
14703 (new-default))
14704 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
14706 (defun vhdl-speedbar-initialize ()
14707 "Initialize speedbar."
14708 ;; general settings
14709 ;; VHDL file extensions (extracted from `auto-mode-alist')
14710 (let ((mode-alist auto-mode-alist))
14711 (while mode-alist
14712 (when (eq (cdar mode-alist) 'vhdl-mode)
14713 (speedbar-add-supported-extension (caar mode-alist)))
14714 (setq mode-alist (cdr mode-alist))))
14715 ;; hierarchy browser settings
14716 (when (boundp 'speedbar-mode-functions-list)
14717 ;; special functions
14718 (speedbar-add-mode-functions-list
14719 '("vhdl directory"
14720 (speedbar-item-info . vhdl-speedbar-item-info)
14721 (speedbar-line-directory . speedbar-files-line-path)))
14722 (speedbar-add-mode-functions-list
14723 '("vhdl project"
14724 (speedbar-item-info . vhdl-speedbar-item-info)
14725 (speedbar-line-directory . vhdl-speedbar-line-project)))
14726 ;; keymap
14727 (unless vhdl-speedbar-mode-map
14728 (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
14729 (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
14730 (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
14731 (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
14732 (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
14733 (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
14734 (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
14735 (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
14736 (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
14737 (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
14738 (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
14739 (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
14740 (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
14741 (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
14742 (let ((key 0))
14743 (while (<= key 9)
14744 (define-key vhdl-speedbar-mode-map (int-to-string key)
14745 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14746 (setq key (1+ key)))))
14747 (define-key speedbar-mode-map "h"
14748 (lambda () (interactive)
14749 (speedbar-change-initial-expansion-list "vhdl directory")))
14750 (define-key speedbar-mode-map "H"
14751 (lambda () (interactive)
14752 (speedbar-change-initial-expansion-list "vhdl project")))
14753 ;; menu
14754 (unless vhdl-speedbar-menu-items
14755 (setq
14756 vhdl-speedbar-menu-items
14757 `(["Edit" speedbar-edit-line t]
14758 ["Expand" speedbar-expand-line
14759 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14760 ["Contract" vhdl-speedbar-contract-level t]
14761 ["Expand All" vhdl-speedbar-expand-all t]
14762 ["Contract All" vhdl-speedbar-contract-all t]
14763 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14764 (while (<= key 9)
14765 (setq menu-list
14766 (cons `[,(if (= key 0) "All" (int-to-string key))
14767 (vhdl-speedbar-set-depth ,key)
14768 :style radio
14769 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14770 :keys ,(int-to-string key)]
14771 menu-list))
14772 (setq key (1+ key)))
14773 (nreverse menu-list))
14774 "--"
14775 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14776 (or (vhdl-speedbar-check-unit 'entity)
14777 (vhdl-speedbar-check-unit 'subprogram))]
14778 ["Place Component" vhdl-speedbar-place-component
14779 (vhdl-speedbar-check-unit 'entity)]
14780 ["Generate Configuration" vhdl-speedbar-configuration
14781 (vhdl-speedbar-check-unit 'architecture)]
14782 ["Select as MRA" vhdl-speedbar-select-mra
14783 (vhdl-speedbar-check-unit 'architecture)]
14784 ["Make" vhdl-speedbar-make-design
14785 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14786 ["Generate Makefile" vhdl-speedbar-generate-makefile
14787 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14788 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14789 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14790 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14791 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14792 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14793 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14794 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14795 ;; hook-ups
14796 (speedbar-add-expansion-list
14797 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14798 vhdl-speedbar-display-directory))
14799 (speedbar-add-expansion-list
14800 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14801 vhdl-speedbar-display-projects))
14802 (setq speedbar-stealthy-function-list
14803 (append
14804 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14805 ("vhdl project" vhdl-speedbar-update-current-project
14806 vhdl-speedbar-update-current-unit))
14807 speedbar-stealthy-function-list))
14808 (when (eq vhdl-speedbar-display-mode 'directory)
14809 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14810 (when (eq vhdl-speedbar-display-mode 'project)
14811 (setq speedbar-initial-expansion-list-name "vhdl project"))
14812 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14814 (defun vhdl-speedbar (&optional arg)
14815 "Open/close speedbar."
14816 (interactive)
14817 (if (not (fboundp 'speedbar))
14818 (error "WARNING: Speedbar is not available or not installed")
14819 (condition-case ()
14820 (speedbar-frame-mode arg)
14821 (error (error "WARNING: An error occurred while opening speedbar")))))
14823 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14824 ;; Display functions
14826 (defvar vhdl-speedbar-last-selected-project nil
14827 "Name of last selected project.")
14829 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14830 ;;; (defmacro speedbar-with-writable (&rest forms)
14831 ;;; "Allow the buffer to be writable and evaluate FORMS."
14832 ;;; (list 'let '((inhibit-read-only t))
14833 ;;; (cons 'progn forms)))
14834 ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
14836 (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
14837 (declare-function speedbar-directory-buttons "speedbar" (directory _index))
14838 (declare-function speedbar-file-lists "speedbar" (directory))
14840 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14841 "Display directory and hierarchy information in speedbar."
14842 (setq vhdl-speedbar-show-projects nil)
14843 (setq speedbar-ignored-directory-regexp
14844 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14845 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14846 (setq speedbar-last-selected-file nil)
14847 (speedbar-with-writable
14848 (condition-case nil
14849 (progn
14850 ;; insert directory path
14851 (speedbar-directory-buttons directory depth)
14852 ;; insert subdirectories
14853 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14854 ;; scan and insert hierarchy of current directory
14855 (vhdl-speedbar-insert-dir-hierarchy directory depth
14856 speedbar-power-click)
14857 ;; expand subdirectories
14858 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14859 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14861 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14862 "Display projects and hierarchy information in speedbar."
14863 (setq vhdl-speedbar-show-projects t)
14864 (setq speedbar-ignored-directory-regexp ".")
14865 (setq speedbar-last-selected-file nil)
14866 (setq vhdl-speedbar-last-selected-project nil)
14867 (speedbar-with-writable
14868 (condition-case nil
14869 ;; insert projects
14870 (vhdl-speedbar-insert-projects)
14871 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14872 (setq speedbar-full-text-cache nil)) ; prevent caching
14874 (declare-function speedbar-make-tag-line "speedbar"
14875 (type char func data tag tfunc tdata tface depth))
14877 (defun vhdl-speedbar-insert-projects ()
14878 "Insert all projects in speedbar."
14879 (vhdl-speedbar-make-title-line "Projects:")
14880 (let ((project-alist (if vhdl-project-sort
14881 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14882 vhdl-project-alist))
14883 (vhdl-speedbar-update-current-unit nil))
14884 ;; insert projects
14885 (while project-alist
14886 (speedbar-make-tag-line
14887 'angle ?+ 'vhdl-speedbar-expand-project
14888 (caar project-alist) (caar project-alist)
14889 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14890 (setq project-alist (cdr project-alist)))
14891 (setq project-alist vhdl-project-alist)
14892 ;; expand projects
14893 (while project-alist
14894 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14895 (goto-char (point-min))
14896 (when (re-search-forward
14897 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14898 (goto-char (match-end 1))
14899 (speedbar-do-function-pointer)))
14900 (setq project-alist (cdr project-alist)))))
14902 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14903 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14904 otherwise use cached data."
14905 (when (or rescan (and (not (assoc project vhdl-file-alist))
14906 (not (vhdl-load-cache project))))
14907 (vhdl-scan-project-contents project))
14908 ;; insert design hierarchy
14909 (vhdl-speedbar-insert-hierarchy
14910 (vhdl-aget vhdl-entity-alist project)
14911 (vhdl-aget vhdl-config-alist project)
14912 (vhdl-aget vhdl-package-alist project)
14913 (car (vhdl-aget vhdl-ent-inst-alist project)) indent)
14914 (insert (int-to-string indent) ":\n")
14915 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14916 (put-text-property (1- (point)) (point) 'invisible nil)
14917 ;; expand design units
14918 (vhdl-speedbar-expand-units project))
14920 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14921 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14922 otherwise use cached data."
14923 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14924 (not (vhdl-load-cache directory))))
14925 (vhdl-scan-directory-contents directory))
14926 ;; insert design hierarchy
14927 (vhdl-speedbar-insert-hierarchy
14928 (vhdl-aget vhdl-entity-alist directory)
14929 (vhdl-aget vhdl-config-alist directory)
14930 (vhdl-aget vhdl-package-alist directory)
14931 (car (vhdl-aget vhdl-ent-inst-alist directory)) depth)
14932 ;; expand design units
14933 (vhdl-speedbar-expand-units directory)
14934 (vhdl-aput 'vhdl-directory-alist directory (list (list directory))))
14936 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14937 ent-inst-list depth)
14938 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14939 (if (not (or ent-alist conf-alist pack-alist))
14940 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14941 (let (ent-entry conf-entry pack-entry)
14942 ;; insert entities
14943 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14944 (while ent-alist
14945 (setq ent-entry (car ent-alist))
14946 (speedbar-make-tag-line
14947 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14948 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14949 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14950 'vhdl-speedbar-entity-face depth)
14951 (unless (nth 2 ent-entry)
14952 (end-of-line 0) (insert "!") (forward-char 1))
14953 (unless (member (nth 0 ent-entry) ent-inst-list)
14954 (end-of-line 0) (insert " (top)") (forward-char 1))
14955 (setq ent-alist (cdr ent-alist)))
14956 ;; insert configurations
14957 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14958 (while conf-alist
14959 (setq conf-entry (car conf-alist))
14960 (speedbar-make-tag-line
14961 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14962 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14963 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14964 'vhdl-speedbar-configuration-face depth)
14965 (setq conf-alist (cdr conf-alist)))
14966 ;; insert packages
14967 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14968 (while pack-alist
14969 (setq pack-entry (car pack-alist))
14970 (vhdl-speedbar-make-pack-line
14971 (nth 0 pack-entry) (nth 1 pack-entry)
14972 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14973 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14974 depth)
14975 (setq pack-alist (cdr pack-alist))))))
14977 (declare-function speedbar-line-directory "speedbar" (&optional depth))
14979 (defun vhdl-speedbar-rescan-hierarchy ()
14980 "Rescan hierarchy for the directory or project under the cursor."
14981 (interactive)
14982 (let (key path)
14983 (cond
14984 ;; current project
14985 (vhdl-speedbar-show-projects
14986 (setq key (vhdl-speedbar-line-project))
14987 (vhdl-scan-project-contents key))
14988 ;; top-level directory
14989 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14990 (re-search-forward "[0-9]+:" nil t)
14991 (vhdl-scan-directory-contents
14992 (abbreviate-file-name (speedbar-line-directory))))
14993 ;; current directory
14994 (t (setq path (speedbar-line-directory))
14995 (string-match "^\\(.+[/\\]\\)" path)
14996 (vhdl-scan-directory-contents
14997 (abbreviate-file-name (match-string 1 path)))))
14998 (vhdl-speedbar-refresh key)))
15000 (declare-function speedbar-goto-this-file "speedbar" (file))
15002 (defun vhdl-speedbar-expand-dirs (directory)
15003 "Expand subdirectories in DIRECTORY according to
15004 `speedbar-shown-directories'."
15005 ;; (nicked from `speedbar-default-directory-list')
15006 (let ((sf (cdr (reverse speedbar-shown-directories)))
15007 (vhdl-speedbar-update-current-unit nil))
15008 (setq speedbar-shown-directories
15009 (list (expand-file-name default-directory)))
15010 (while sf
15011 (when (speedbar-goto-this-file (car sf))
15012 (beginning-of-line)
15013 (when (looking-at "[0-9]+:\\s-*<")
15014 (goto-char (match-end 0))
15015 (speedbar-do-function-pointer)))
15016 (setq sf (cdr sf))))
15017 (vhdl-speedbar-update-current-unit nil t))
15019 (defun vhdl-speedbar-expand-units (key)
15020 "Expand design units in directory/project KEY according to
15021 `vhdl-speedbar-shown-unit-alist'."
15022 (let ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15023 (vhdl-speedbar-update-current-unit nil)
15024 vhdl-updated-project-list)
15025 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15026 (vhdl-prepare-search-1
15027 (while unit-alist ; expand units
15028 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
15029 (beginning-of-line)
15030 (let ((arch-alist (nth 1 (car unit-alist)))
15031 position)
15032 (when (looking-at "^[0-9]+:\\s-*\\[")
15033 (goto-char (match-end 0))
15034 (setq position (point))
15035 (speedbar-do-function-pointer)
15036 (select-frame speedbar-frame)
15037 (while arch-alist ; expand architectures
15038 (goto-char position)
15039 (when (re-search-forward
15040 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
15041 (car arch-alist) "\\>\\)") nil t)
15042 (beginning-of-line)
15043 (when (looking-at "^[0-9]+:\\s-*{")
15044 (goto-char (match-end 0))
15045 (speedbar-do-function-pointer)
15046 (select-frame speedbar-frame)))
15047 (setq arch-alist (cdr arch-alist))))
15048 (setq unit-alist (cdr unit-alist))))))
15049 (vhdl-speedbar-update-current-unit nil t))
15051 (declare-function speedbar-center-buffer-smartly "speedbar" ())
15053 (defun vhdl-speedbar-contract-level ()
15054 "Contract current level in current directory/project."
15055 (interactive)
15056 (when (or (save-excursion
15057 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
15058 (and (save-excursion
15059 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
15060 (re-search-backward
15061 (format "^[0-%d]:\\s-*[[{<]-"
15062 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
15063 (goto-char (match-end 0))
15064 (speedbar-do-function-pointer)
15065 (speedbar-center-buffer-smartly)))
15067 (defun vhdl-speedbar-contract-all ()
15068 "Contract all expanded design units in current directory/project."
15069 (interactive)
15070 (if (and vhdl-speedbar-show-projects
15071 (save-excursion (beginning-of-line) (looking-at "^0:")))
15072 (progn (setq vhdl-speedbar-shown-project-list nil)
15073 (vhdl-speedbar-refresh))
15074 (let ((key (vhdl-speedbar-line-key)))
15075 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15076 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
15077 (when (memq 'display vhdl-speedbar-save-cache)
15078 (add-to-list 'vhdl-updated-project-list key)))))
15080 (defun vhdl-speedbar-expand-all ()
15081 "Expand all design units in current directory/project."
15082 (interactive)
15083 (let* ((key (vhdl-speedbar-line-key))
15084 (ent-alist (vhdl-aget vhdl-entity-alist key))
15085 (conf-alist (vhdl-aget vhdl-config-alist key))
15086 (pack-alist (vhdl-aget vhdl-package-alist key))
15087 arch-alist unit-alist subunit-alist)
15088 (add-to-list 'vhdl-speedbar-shown-project-list key)
15089 (while ent-alist
15090 (setq arch-alist (nth 4 (car ent-alist)))
15091 (setq subunit-alist nil)
15092 (while arch-alist
15093 (push (caar arch-alist) subunit-alist)
15094 (setq arch-alist (cdr arch-alist)))
15095 (push (list (caar ent-alist) subunit-alist) unit-alist)
15096 (setq ent-alist (cdr ent-alist)))
15097 (while conf-alist
15098 (push (list (caar conf-alist)) unit-alist)
15099 (setq conf-alist (cdr conf-alist)))
15100 (while pack-alist
15101 (push (list (caar pack-alist)) unit-alist)
15102 (setq pack-alist (cdr pack-alist)))
15103 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15104 (vhdl-speedbar-refresh)
15105 (when (memq 'display vhdl-speedbar-save-cache)
15106 (add-to-list 'vhdl-updated-project-list key))))
15108 (declare-function speedbar-change-expand-button-char "speedbar" (char))
15109 (declare-function speedbar-delete-subblock "speedbar" (indent))
15111 (defun vhdl-speedbar-expand-project (text token indent)
15112 "Expand/contract the project under the cursor."
15113 (cond
15114 ((string-match "+" text) ; expand project
15115 (speedbar-change-expand-button-char ?-)
15116 (unless (member token vhdl-speedbar-shown-project-list)
15117 (setq vhdl-speedbar-shown-project-list
15118 (cons token vhdl-speedbar-shown-project-list)))
15119 (speedbar-with-writable
15120 (save-excursion
15121 (end-of-line) (forward-char 1)
15122 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
15123 speedbar-power-click))))
15124 ((string-match "-" text) ; contract project
15125 (speedbar-change-expand-button-char ?+)
15126 (setq vhdl-speedbar-shown-project-list
15127 (delete token vhdl-speedbar-shown-project-list))
15128 (speedbar-delete-subblock indent))
15129 (t (error "Nothing to display")))
15130 (when (equal (selected-frame) speedbar-frame)
15131 (speedbar-center-buffer-smartly)))
15133 (defun vhdl-speedbar-expand-entity (text token indent)
15134 "Expand/contract the entity under the cursor."
15135 (cond
15136 ((string-match "+" text) ; expand entity
15137 (let* ((key (vhdl-speedbar-line-key indent))
15138 (ent-alist (vhdl-aget vhdl-entity-alist key))
15139 (ent-entry (vhdl-aget ent-alist token))
15140 (arch-alist (nth 3 ent-entry))
15141 (inst-alist (vhdl-get-instantiations token indent))
15142 (subpack-alist (nth 5 ent-entry))
15143 (multiple-arch (> (length arch-alist) 1))
15144 arch-entry inst-entry)
15145 (if (not (or arch-alist inst-alist subpack-alist))
15146 (speedbar-change-expand-button-char ??)
15147 (speedbar-change-expand-button-char ?-)
15148 ;; add entity to `vhdl-speedbar-shown-unit-alist'
15149 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15150 (vhdl-aput 'unit-alist token nil)
15151 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15152 (speedbar-with-writable
15153 (save-excursion
15154 (end-of-line) (forward-char 1)
15155 ;; insert architectures
15156 (when arch-alist
15157 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
15158 (while arch-alist
15159 (setq arch-entry (car arch-alist))
15160 (speedbar-make-tag-line
15161 'curly ?+ 'vhdl-speedbar-expand-architecture
15162 (cons token (nth 0 arch-entry))
15163 (nth 1 arch-entry) 'vhdl-speedbar-find-file
15164 (cons (nth 2 arch-entry) (nth 3 arch-entry))
15165 'vhdl-speedbar-architecture-face (1+ indent))
15166 (when (and multiple-arch
15167 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
15168 (end-of-line 0) (insert " (mra)") (forward-char 1))
15169 (setq arch-alist (cdr arch-alist)))
15170 ;; insert instantiations
15171 (when inst-alist
15172 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
15173 (while inst-alist
15174 (setq inst-entry (car inst-alist))
15175 (vhdl-speedbar-make-inst-line
15176 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
15177 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
15178 nil nil nil (1+ indent) 0 " in ")
15179 (setq inst-alist (cdr inst-alist)))
15180 ;; insert required packages
15181 (vhdl-speedbar-insert-subpackages
15182 subpack-alist (1+ indent) indent)))
15183 (when (memq 'display vhdl-speedbar-save-cache)
15184 (add-to-list 'vhdl-updated-project-list key))
15185 (vhdl-speedbar-update-current-unit t t))))
15186 ((string-match "-" text) ; contract entity
15187 (speedbar-change-expand-button-char ?+)
15188 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
15189 (let* ((key (vhdl-speedbar-line-key indent))
15190 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15191 (vhdl-adelete 'unit-alist token)
15192 (if unit-alist
15193 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15194 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15195 (speedbar-delete-subblock indent)
15196 (when (memq 'display vhdl-speedbar-save-cache)
15197 (add-to-list 'vhdl-updated-project-list key))))
15198 (t (error "Nothing to display")))
15199 (when (equal (selected-frame) speedbar-frame)
15200 (speedbar-center-buffer-smartly)))
15202 (defun vhdl-speedbar-expand-architecture (text token indent)
15203 "Expand/contract the architecture under the cursor."
15204 (cond
15205 ((string-match "+" text) ; expand architecture
15206 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15207 (ent-alist (vhdl-aget vhdl-entity-alist key))
15208 (conf-alist (vhdl-aget vhdl-config-alist key))
15209 (hier-alist (vhdl-get-hierarchy
15210 ent-alist conf-alist (car token) (cdr token) nil nil
15211 0 (1- indent)))
15212 (ent-entry (vhdl-aget ent-alist (car token)))
15213 (arch-entry (vhdl-aget (nth 3 ent-entry) (cdr token)))
15214 (subpack-alist (nth 4 arch-entry))
15215 entry)
15216 (if (not (or hier-alist subpack-alist))
15217 (speedbar-change-expand-button-char ??)
15218 (speedbar-change-expand-button-char ?-)
15219 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15220 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15221 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15222 (vhdl-aput 'unit-alist (car token)
15223 (list (cons (cdr token) arch-alist)))
15224 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15225 (speedbar-with-writable
15226 (save-excursion
15227 (end-of-line) (forward-char 1)
15228 ;; insert instance hierarchy
15229 (when hier-alist
15230 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15231 (1+ indent)))
15232 (while hier-alist
15233 (setq entry (car hier-alist))
15234 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15235 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15236 (vhdl-speedbar-make-inst-line
15237 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15238 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15239 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
15240 (setq hier-alist (cdr hier-alist)))
15241 ;; insert required packages
15242 (vhdl-speedbar-insert-subpackages
15243 subpack-alist (1+ indent) (1- indent))))
15244 (when (memq 'display vhdl-speedbar-save-cache)
15245 (add-to-list 'vhdl-updated-project-list key))
15246 (vhdl-speedbar-update-current-unit t t))))
15247 ((string-match "-" text) ; contract architecture
15248 (speedbar-change-expand-button-char ?+)
15249 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15250 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15251 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15252 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15253 (vhdl-aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
15254 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15255 (speedbar-delete-subblock indent)
15256 (when (memq 'display vhdl-speedbar-save-cache)
15257 (add-to-list 'vhdl-updated-project-list key))))
15258 (t (error "Nothing to display")))
15259 (when (equal (selected-frame) speedbar-frame)
15260 (speedbar-center-buffer-smartly)))
15262 (defun vhdl-speedbar-expand-config (text token indent)
15263 "Expand/contract the configuration under the cursor."
15264 (cond
15265 ((string-match "+" text) ; expand configuration
15266 (let* ((key (vhdl-speedbar-line-key indent))
15267 (conf-alist (vhdl-aget vhdl-config-alist key))
15268 (conf-entry (vhdl-aget conf-alist token))
15269 (ent-alist (vhdl-aget vhdl-entity-alist key))
15270 (hier-alist (vhdl-get-hierarchy
15271 ent-alist conf-alist (nth 3 conf-entry)
15272 (nth 4 conf-entry) token (nth 5 conf-entry)
15273 0 indent t))
15274 (subpack-alist (nth 6 conf-entry))
15275 entry)
15276 (if (not (or hier-alist subpack-alist))
15277 (speedbar-change-expand-button-char ??)
15278 (speedbar-change-expand-button-char ?-)
15279 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15280 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15281 (vhdl-aput 'unit-alist token nil)
15282 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15283 (speedbar-with-writable
15284 (save-excursion
15285 (end-of-line) (forward-char 1)
15286 ;; insert instance hierarchy
15287 (when hier-alist
15288 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
15289 (while hier-alist
15290 (setq entry (car hier-alist))
15291 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15292 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15293 (vhdl-speedbar-make-inst-line
15294 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15295 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15296 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
15297 (setq hier-alist (cdr hier-alist)))
15298 ;; insert required packages
15299 (vhdl-speedbar-insert-subpackages
15300 subpack-alist (1+ indent) indent)))
15301 (when (memq 'display vhdl-speedbar-save-cache)
15302 (add-to-list 'vhdl-updated-project-list key))
15303 (vhdl-speedbar-update-current-unit t t))))
15304 ((string-match "-" text) ; contract configuration
15305 (speedbar-change-expand-button-char ?+)
15306 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15307 (let* ((key (vhdl-speedbar-line-key indent))
15308 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15309 (vhdl-adelete 'unit-alist token)
15310 (if unit-alist
15311 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15312 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15313 (speedbar-delete-subblock indent)
15314 (when (memq 'display vhdl-speedbar-save-cache)
15315 (add-to-list 'vhdl-updated-project-list key))))
15316 (t (error "Nothing to display")))
15317 (when (equal (selected-frame) speedbar-frame)
15318 (speedbar-center-buffer-smartly)))
15320 (defun vhdl-speedbar-expand-package (text token indent)
15321 "Expand/contract the package under the cursor."
15322 (cond
15323 ((string-match "+" text) ; expand package
15324 (let* ((key (vhdl-speedbar-line-key indent))
15325 (pack-alist (vhdl-aget vhdl-package-alist key))
15326 (pack-entry (vhdl-aget pack-alist token))
15327 (comp-alist (nth 3 pack-entry))
15328 (func-alist (nth 4 pack-entry))
15329 (func-body-alist (nth 8 pack-entry))
15330 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
15331 comp-entry func-entry func-body-entry)
15332 (if (not (or comp-alist func-alist subpack-alist))
15333 (speedbar-change-expand-button-char ??)
15334 (speedbar-change-expand-button-char ?-)
15335 ;; add package to `vhdl-speedbar-shown-unit-alist'
15336 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15337 (vhdl-aput 'unit-alist token nil)
15338 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15339 (speedbar-with-writable
15340 (save-excursion
15341 (end-of-line) (forward-char 1)
15342 ;; insert components
15343 (when comp-alist
15344 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
15345 (while comp-alist
15346 (setq comp-entry (car comp-alist))
15347 (speedbar-make-tag-line
15348 nil nil nil
15349 (cons token (nth 0 comp-entry))
15350 (nth 1 comp-entry) 'vhdl-speedbar-find-file
15351 (cons (nth 2 comp-entry) (nth 3 comp-entry))
15352 'vhdl-speedbar-entity-face (1+ indent))
15353 (setq comp-alist (cdr comp-alist)))
15354 ;; insert subprograms
15355 (when func-alist
15356 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
15357 (while func-alist
15358 (setq func-entry (car func-alist)
15359 func-body-entry (vhdl-aget func-body-alist
15360 (car func-entry)))
15361 (when (nth 2 func-entry)
15362 (vhdl-speedbar-make-subprogram-line
15363 (nth 1 func-entry)
15364 (cons (nth 2 func-entry) (nth 3 func-entry))
15365 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
15366 (1+ indent)))
15367 (setq func-alist (cdr func-alist)))
15368 ;; insert required packages
15369 (vhdl-speedbar-insert-subpackages
15370 subpack-alist (1+ indent) indent)))
15371 (when (memq 'display vhdl-speedbar-save-cache)
15372 (add-to-list 'vhdl-updated-project-list key))
15373 (vhdl-speedbar-update-current-unit t t))))
15374 ((string-match "-" text) ; contract package
15375 (speedbar-change-expand-button-char ?+)
15376 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15377 (let* ((key (vhdl-speedbar-line-key indent))
15378 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15379 (vhdl-adelete 'unit-alist token)
15380 (if unit-alist
15381 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15382 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15383 (speedbar-delete-subblock indent)
15384 (when (memq 'display vhdl-speedbar-save-cache)
15385 (add-to-list 'vhdl-updated-project-list key))))
15386 (t (error "Nothing to display")))
15387 (when (equal (selected-frame) speedbar-frame)
15388 (speedbar-center-buffer-smartly)))
15390 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15391 "Insert required packages."
15392 (let* ((pack-alist (vhdl-aget vhdl-package-alist
15393 (vhdl-speedbar-line-key dir-indent)))
15394 pack-key lib-name pack-entry)
15395 (when subpack-alist
15396 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15397 (while subpack-alist
15398 (setq pack-key (cdar subpack-alist)
15399 lib-name (caar subpack-alist))
15400 (setq pack-entry (vhdl-aget pack-alist pack-key))
15401 (vhdl-speedbar-make-subpack-line
15402 (or (nth 0 pack-entry) pack-key) lib-name
15403 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15404 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15405 (setq subpack-alist (cdr subpack-alist)))))
15407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15408 ;; Display help functions
15410 (defvar vhdl-speedbar-update-current-unit t
15411 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15413 (defun vhdl-speedbar-update-current-project ()
15414 "Highlight project that is currently active."
15415 (when (and vhdl-speedbar-show-projects
15416 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15417 (and (boundp 'speedbar-frame)
15418 (frame-live-p speedbar-frame)))
15419 (let ((last-frame (selected-frame))
15420 (project-alist vhdl-project-alist)
15421 pos)
15422 (select-frame speedbar-frame)
15423 (speedbar-with-writable
15424 (save-excursion
15425 (while project-alist
15426 (goto-char (point-min))
15427 (when (re-search-forward
15428 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15429 (put-text-property (match-beginning 1) (match-end 1) 'face
15430 (if (equal (caar project-alist) vhdl-project)
15431 'speedbar-selected-face
15432 'speedbar-directory-face))
15433 (when (equal (caar project-alist) vhdl-project)
15434 (setq pos (1- (match-beginning 1)))))
15435 (setq project-alist (cdr project-alist))))
15436 (when pos (goto-char pos)))
15437 (select-frame last-frame)
15438 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15441 (declare-function speedbar-position-cursor-on-line "speedbar" ())
15443 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15444 "Highlight all design units that are contained in the current file.
15445 NO-POSITION non-nil means do not re-position cursor."
15446 (let ((last-frame (selected-frame))
15447 (project-list vhdl-speedbar-shown-project-list)
15448 file-alist pos file-name)
15449 ;; get current file name
15450 (if (fboundp 'speedbar-select-attached-frame)
15451 (speedbar-select-attached-frame)
15452 (select-frame speedbar-attached-frame))
15453 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15454 (when (and vhdl-speedbar-update-current-unit
15455 (or always (not (equal file-name speedbar-last-selected-file))))
15456 (if vhdl-speedbar-show-projects
15457 (while project-list
15458 (setq file-alist (append file-alist
15459 (vhdl-aget vhdl-file-alist
15460 (car project-list))))
15461 (setq project-list (cdr project-list)))
15462 (setq file-alist
15463 (vhdl-aget vhdl-file-alist
15464 (abbreviate-file-name default-directory))))
15465 (select-frame speedbar-frame)
15466 (set-buffer speedbar-buffer)
15467 (speedbar-with-writable
15468 (vhdl-prepare-search-1
15469 (save-excursion
15470 ;; unhighlight last units
15471 (let* ((file-entry (vhdl-aget file-alist
15472 speedbar-last-selected-file)))
15473 (vhdl-speedbar-update-units
15474 "\\[.] " (nth 0 file-entry)
15475 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15476 (vhdl-speedbar-update-units
15477 "{.} " (nth 1 file-entry)
15478 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15479 (vhdl-speedbar-update-units
15480 "\\[.] " (nth 3 file-entry)
15481 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15482 (vhdl-speedbar-update-units
15483 "[]>] " (nth 4 file-entry)
15484 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15485 (vhdl-speedbar-update-units
15486 "\\[.].+(" '("body")
15487 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15488 (vhdl-speedbar-update-units
15489 "> " (nth 6 file-entry)
15490 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15491 ;; highlight current units
15492 (let* ((file-entry (vhdl-aget file-alist file-name)))
15493 (setq
15494 pos (vhdl-speedbar-update-units
15495 "\\[.] " (nth 0 file-entry)
15496 file-name 'vhdl-speedbar-entity-selected-face pos)
15497 pos (vhdl-speedbar-update-units
15498 "{.} " (nth 1 file-entry)
15499 file-name 'vhdl-speedbar-architecture-selected-face pos)
15500 pos (vhdl-speedbar-update-units
15501 "\\[.] " (nth 3 file-entry)
15502 file-name 'vhdl-speedbar-configuration-selected-face pos)
15503 pos (vhdl-speedbar-update-units
15504 "[]>] " (nth 4 file-entry)
15505 file-name 'vhdl-speedbar-package-selected-face pos)
15506 pos (vhdl-speedbar-update-units
15507 "\\[.].+(" '("body")
15508 file-name 'vhdl-speedbar-package-selected-face pos)
15509 pos (vhdl-speedbar-update-units
15510 "> " (nth 6 file-entry)
15511 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15512 ;; move speedbar so the first highlighted unit is visible
15513 (when (and pos (not no-position))
15514 (goto-char pos)
15515 (speedbar-center-buffer-smartly)
15516 (speedbar-position-cursor-on-line))
15517 (setq speedbar-last-selected-file file-name))
15518 (select-frame last-frame)
15521 (defun vhdl-speedbar-update-units (text unit-list file-name face
15522 &optional pos)
15523 "Help function to highlight design units."
15524 (while unit-list
15525 (goto-char (point-min))
15526 (while (re-search-forward
15527 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15528 (when (equal file-name (car (get-text-property
15529 (match-beginning 1) 'speedbar-token)))
15530 (setq pos (or pos (point-marker)))
15531 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15532 (setq unit-list (cdr unit-list)))
15533 pos)
15535 (declare-function speedbar-make-button "speedbar"
15536 (start end face mouse function &optional token))
15538 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15539 ent-name ent-file-marker
15540 arch-name arch-file-marker
15541 conf-name conf-file-marker
15542 lib-name depth offset delimiter)
15543 "Insert instantiation entry."
15544 (let ((start (point))
15545 visible-start)
15546 (insert (int-to-string depth) ":")
15547 (put-text-property start (point) 'invisible t)
15548 (setq visible-start (point))
15549 (insert-char ? (* depth speedbar-indentation-width))
15550 (while (> offset 0)
15551 (insert "|")
15552 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15553 (setq offset (1- offset)))
15554 (put-text-property visible-start (point) 'invisible nil)
15555 (setq start (point))
15556 (insert ">")
15557 (speedbar-make-button start (point) nil nil nil)
15558 (setq visible-start (point))
15559 (insert " ")
15560 (setq start (point))
15561 (if (not inst-name)
15562 (insert "(top)")
15563 (insert inst-name)
15564 (speedbar-make-button
15565 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15566 'vhdl-speedbar-find-file inst-file-marker))
15567 (insert delimiter)
15568 (when ent-name
15569 (setq start (point))
15570 (insert ent-name)
15571 (speedbar-make-button
15572 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15573 'vhdl-speedbar-find-file ent-file-marker)
15574 (when arch-name
15575 (insert " (")
15576 (setq start (point))
15577 (insert arch-name)
15578 (speedbar-make-button
15579 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15580 'vhdl-speedbar-find-file arch-file-marker)
15581 (insert ")"))
15582 (when conf-name
15583 (insert " (")
15584 (setq start (point))
15585 (insert conf-name)
15586 (speedbar-make-button
15587 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15588 'vhdl-speedbar-find-file conf-file-marker)
15589 (insert ")")))
15590 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15591 (setq start (point))
15592 (insert " (" lib-name ")")
15593 (put-text-property (+ 2 start) (1- (point)) 'face
15594 'vhdl-speedbar-library-face))
15595 (insert-char ?\n 1)
15596 (put-text-property visible-start (point) 'invisible nil)))
15598 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15599 body-file-marker depth)
15600 "Insert package entry."
15601 (let ((start (point))
15602 visible-start)
15603 (insert (int-to-string depth) ":")
15604 (put-text-property start (point) 'invisible t)
15605 (setq visible-start (point))
15606 (insert-char ? (* depth speedbar-indentation-width))
15607 (put-text-property visible-start (point) 'invisible nil)
15608 (setq start (point))
15609 (insert "[+]")
15610 (speedbar-make-button
15611 start (point) 'speedbar-button-face 'speedbar-highlight-face
15612 'vhdl-speedbar-expand-package pack-key)
15613 (setq visible-start (point))
15614 (insert-char ? 1 nil)
15615 (setq start (point))
15616 (insert pack-name)
15617 (speedbar-make-button
15618 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15619 'vhdl-speedbar-find-file pack-file-marker)
15620 (unless (car pack-file-marker)
15621 (insert "!"))
15622 (when (car body-file-marker)
15623 (insert " (")
15624 (setq start (point))
15625 (insert "body")
15626 (speedbar-make-button
15627 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15628 'vhdl-speedbar-find-file body-file-marker)
15629 (insert ")"))
15630 (insert-char ?\n 1)
15631 (put-text-property visible-start (point) 'invisible nil)))
15633 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15634 pack-body-file-marker depth)
15635 "Insert used package entry."
15636 (let ((start (point))
15637 visible-start)
15638 (insert (int-to-string depth) ":")
15639 (put-text-property start (point) 'invisible t)
15640 (setq visible-start (point))
15641 (insert-char ? (* depth speedbar-indentation-width))
15642 (put-text-property visible-start (point) 'invisible nil)
15643 (setq start (point))
15644 (insert ">")
15645 (speedbar-make-button start (point) nil nil nil)
15646 (setq visible-start (point))
15647 (insert " ")
15648 (setq start (point))
15649 (insert pack-name)
15650 (speedbar-make-button
15651 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15652 'vhdl-speedbar-find-file pack-file-marker)
15653 (when (car pack-body-file-marker)
15654 (insert " (")
15655 (setq start (point))
15656 (insert "body")
15657 (speedbar-make-button
15658 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15659 'vhdl-speedbar-find-file pack-body-file-marker)
15660 (insert ")"))
15661 (setq start (point))
15662 (insert " (" lib-name ")")
15663 (put-text-property (+ 2 start) (1- (point)) 'face
15664 'vhdl-speedbar-library-face)
15665 (insert-char ?\n 1)
15666 (put-text-property visible-start (point) 'invisible nil)))
15668 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15669 func-body-file-marker
15670 depth)
15671 "Insert subprogram entry."
15672 (let ((start (point))
15673 visible-start)
15674 (insert (int-to-string depth) ":")
15675 (put-text-property start (point) 'invisible t)
15676 (setq visible-start (point))
15677 (insert-char ? (* depth speedbar-indentation-width))
15678 (put-text-property visible-start (point) 'invisible nil)
15679 (setq start (point))
15680 (insert ">")
15681 (speedbar-make-button start (point) nil nil nil)
15682 (setq visible-start (point))
15683 (insert " ")
15684 (setq start (point))
15685 (insert func-name)
15686 (speedbar-make-button
15687 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15688 'vhdl-speedbar-find-file func-file-marker)
15689 (when (car func-body-file-marker)
15690 (insert " (")
15691 (setq start (point))
15692 (insert "body")
15693 (speedbar-make-button
15694 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15695 'vhdl-speedbar-find-file func-body-file-marker)
15696 (insert ")"))
15697 (insert-char ?\n 1)
15698 (put-text-property visible-start (point) 'invisible nil)))
15700 (defun vhdl-speedbar-make-title-line (text &optional depth)
15701 "Insert design unit title entry."
15702 (let ((start (point))
15703 visible-start)
15704 (when depth
15705 (insert (int-to-string depth) ":")
15706 (put-text-property start (point) 'invisible t))
15707 (setq visible-start (point))
15708 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15709 (setq start (point))
15710 (insert text)
15711 (speedbar-make-button start (point) nil nil nil nil)
15712 (insert-char ?\n 1)
15713 (put-text-property visible-start (point) 'invisible nil)))
15715 (defun vhdl-speedbar-insert-dirs (files level)
15716 "Insert subdirectories."
15717 (let ((dirs (car files)))
15718 (while dirs
15719 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15720 (car dirs) 'speedbar-dir-follow nil
15721 'speedbar-directory-face level)
15722 (setq dirs (cdr dirs)))))
15724 (declare-function speedbar-reset-scanners "speedbar" ())
15726 (defun vhdl-speedbar-dired (text token indent)
15727 "Speedbar click handler for directory expand button in hierarchy mode."
15728 (cond ((string-match "+" text) ; we have to expand this dir
15729 (setq speedbar-shown-directories
15730 (cons (expand-file-name
15731 (concat (speedbar-line-directory indent) token "/"))
15732 speedbar-shown-directories))
15733 (speedbar-change-expand-button-char ?-)
15734 (speedbar-reset-scanners)
15735 (speedbar-with-writable
15736 (save-excursion
15737 (end-of-line) (forward-char 1)
15738 (vhdl-speedbar-insert-dirs
15739 (speedbar-file-lists
15740 (concat (speedbar-line-directory indent) token "/"))
15741 (1+ indent))
15742 (speedbar-reset-scanners)
15743 (vhdl-speedbar-insert-dir-hierarchy
15744 (abbreviate-file-name
15745 (concat (speedbar-line-directory indent) token "/"))
15746 (1+ indent) speedbar-power-click)))
15747 (vhdl-speedbar-update-current-unit t t))
15748 ((string-match "-" text) ; we have to contract this node
15749 (speedbar-reset-scanners)
15750 (let ((oldl speedbar-shown-directories)
15751 (newl nil)
15752 (td (expand-file-name
15753 (concat (speedbar-line-directory indent) token))))
15754 (while oldl
15755 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15756 (push (car oldl) newl))
15757 (setq oldl (cdr oldl)))
15758 (setq speedbar-shown-directories (nreverse newl)))
15759 (speedbar-change-expand-button-char ?+)
15760 (speedbar-delete-subblock indent))
15761 (t (error "Nothing to display")))
15762 (when (equal (selected-frame) speedbar-frame)
15763 (speedbar-center-buffer-smartly)))
15765 (declare-function speedbar-files-item-info "speedbar" ())
15767 (defun vhdl-speedbar-item-info ()
15768 "Derive and display information about this line item."
15769 (save-excursion
15770 (beginning-of-line)
15771 ;; skip invisible number info
15772 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15773 (cond
15774 ;; project/directory entry
15775 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15776 (if vhdl-speedbar-show-projects
15777 (message "Project \"%s\"" (match-string-no-properties 1))
15778 (speedbar-files-item-info)))
15779 ;; design unit entry
15780 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15781 (goto-char (match-end 1))
15782 (let ((face (get-text-property (point) 'face)))
15783 (message
15784 "%s \"%s\" in \"%s\""
15785 ;; design unit kind
15786 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15787 (eq face 'vhdl-speedbar-entity-selected-face))
15788 (if (equal (match-string 2) ">") "Component" "Entity"))
15789 ((or (eq face 'vhdl-speedbar-architecture-face)
15790 (eq face 'vhdl-speedbar-architecture-selected-face))
15791 "Architecture")
15792 ((or (eq face 'vhdl-speedbar-configuration-face)
15793 (eq face 'vhdl-speedbar-configuration-selected-face))
15794 "Configuration")
15795 ((or (eq face 'vhdl-speedbar-package-face)
15796 (eq face 'vhdl-speedbar-package-selected-face))
15797 "Package")
15798 ((or (eq face 'vhdl-speedbar-instantiation-face)
15799 (eq face 'vhdl-speedbar-instantiation-selected-face))
15800 "Instantiation")
15801 ((eq face 'vhdl-speedbar-subprogram-face)
15802 "Subprogram")
15803 (t ""))
15804 ;; design unit name
15805 (buffer-substring-no-properties
15806 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15807 (match-end 1))
15808 ;; file name
15809 (file-relative-name
15810 (or (car (get-text-property (point) 'speedbar-token))
15811 "?")
15812 (vhdl-default-directory)))))
15813 (t (message "")))))
15815 (declare-function speedbar-line-text "speedbar" (&optional p))
15817 (defun vhdl-speedbar-line-text ()
15818 "Calls `speedbar-line-text' and removes text properties."
15819 (let ((string (speedbar-line-text)))
15820 (set-text-properties 0 (length string) nil string)
15821 string))
15823 (defun vhdl-speedbar-higher-text ()
15824 "Get speedbar-line-text of higher level."
15825 (let (depth string)
15826 (save-excursion
15827 (beginning-of-line)
15828 (looking-at "^\\([0-9]+\\):")
15829 (setq depth (string-to-number (match-string 1)))
15830 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15831 (setq string (match-string 1))
15832 (set-text-properties 0 (length string) nil string)
15833 string))))
15835 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15836 ;; Help functions
15838 (defun vhdl-speedbar-line-key (&optional indent)
15839 "Get currently displayed directory of project name."
15840 (if vhdl-speedbar-show-projects
15841 (vhdl-speedbar-line-project)
15842 (abbreviate-file-name
15843 (file-name-as-directory (speedbar-line-directory indent)))))
15845 (defun vhdl-speedbar-line-project (&optional indent)
15846 "Get currently displayed project name."
15847 (and vhdl-speedbar-show-projects
15848 (save-excursion
15849 (end-of-line)
15850 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15851 (match-string-no-properties 1))))
15853 (defun vhdl-add-modified-file ()
15854 "Add file to `vhdl-modified-file-list'."
15855 (when vhdl-file-alist
15856 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15857 nil)
15859 (defun vhdl-resolve-paths (path-list)
15860 "Resolve path wildcards in PATH-LIST."
15861 (let (path-list-1 path-list-2 path-beg path-end dir)
15862 ;; eliminate non-existent directories
15863 (while path-list
15864 (setq dir (car path-list))
15865 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15866 (if (file-directory-p (match-string 2 dir))
15867 (push dir path-list-1)
15868 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15869 (setq path-list (cdr path-list)))
15870 ;; resolve path wildcards
15871 (while path-list-1
15872 (setq dir (car path-list-1))
15873 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15874 (progn
15875 (setq path-beg (match-string 1 dir)
15876 path-end (match-string 5 dir))
15877 (setq path-list-1
15878 (append
15879 (mapcar
15880 (function
15881 (lambda (var) (concat path-beg var path-end)))
15882 (let ((all-list (vhdl-directory-files
15883 (match-string 2 dir) t
15884 (concat "\\<" (wildcard-to-regexp
15885 (match-string 4 dir)))))
15886 dir-list)
15887 (while all-list
15888 (when (file-directory-p (car all-list))
15889 (push (car all-list) dir-list))
15890 (setq all-list (cdr all-list)))
15891 dir-list))
15892 (cdr path-list-1))))
15893 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15894 (when (file-directory-p (match-string 2 dir))
15895 (push dir path-list-2))
15896 (setq path-list-1 (cdr path-list-1))))
15897 (nreverse path-list-2)))
15899 (defun vhdl-speedbar-goto-this-unit (directory unit)
15900 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15901 (let ((dest (point)))
15902 (if (and (if vhdl-speedbar-show-projects
15903 (progn (goto-char (point-min)) t)
15904 (speedbar-goto-this-file directory))
15905 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15906 (progn (speedbar-position-cursor-on-line)
15908 (goto-char dest)
15909 nil)))
15911 (declare-function speedbar-find-file-in-frame "speedbar" (file))
15912 (declare-function speedbar-set-timer "speedbar" (timeout))
15913 ;; speedbar loads dframe at runtime.
15914 (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
15916 (defun vhdl-speedbar-find-file (text token indent)
15917 "When user clicks on TEXT, load file with name and position in TOKEN.
15918 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15919 is already shown in a buffer."
15920 (if (not (car token))
15921 (error "ERROR: File cannot be found")
15922 (let ((buffer (get-file-buffer (car token))))
15923 (speedbar-find-file-in-frame (car token))
15924 (when (or vhdl-speedbar-jump-to-unit buffer)
15925 (goto-char (point-min))
15926 (forward-line (1- (cdr token)))
15927 (recenter))
15928 (vhdl-speedbar-update-current-unit t t)
15929 (speedbar-set-timer dframe-update-speed)
15930 (dframe-maybee-jump-to-attached-frame))))
15932 (defun vhdl-speedbar-port-copy ()
15933 "Copy the port of the entity/component or subprogram under the cursor."
15934 (interactive)
15935 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15936 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15937 (error "ERROR: No entity/component or subprogram under cursor")
15938 (beginning-of-line)
15939 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15940 (condition-case info
15941 (let ((token (get-text-property
15942 (match-beginning 3) 'speedbar-token)))
15943 (vhdl-visit-file (car token) t
15944 (progn (goto-char (point-min))
15945 (forward-line (1- (cdr token)))
15946 (end-of-line)
15947 (if is-entity
15948 (vhdl-port-copy)
15949 (vhdl-subprog-copy)))))
15950 (error (error "ERROR: %s not scanned successfully\n (%s)"
15951 (if is-entity "Port" "Interface") (cadr info))))
15952 (error "ERROR: No entity/component or subprogram on current line")))))
15954 (defun vhdl-speedbar-place-component ()
15955 "Place the entity/component under the cursor as component."
15956 (interactive)
15957 (if (not (vhdl-speedbar-check-unit 'entity))
15958 (error "ERROR: No entity/component under cursor")
15959 (vhdl-speedbar-port-copy)
15960 (if (fboundp 'speedbar-select-attached-frame)
15961 (speedbar-select-attached-frame)
15962 (select-frame speedbar-attached-frame))
15963 (vhdl-compose-place-component)
15964 (select-frame speedbar-frame)))
15966 (defun vhdl-speedbar-configuration ()
15967 "Generate configuration for the architecture under the cursor."
15968 (interactive)
15969 (if (not (vhdl-speedbar-check-unit 'architecture))
15970 (error "ERROR: No architecture under cursor")
15971 (let ((arch-name (vhdl-speedbar-line-text))
15972 (ent-name (vhdl-speedbar-higher-text)))
15973 (if (fboundp 'speedbar-select-attached-frame)
15974 (speedbar-select-attached-frame)
15975 (select-frame speedbar-attached-frame))
15976 (vhdl-compose-configuration ent-name arch-name))))
15978 (defun vhdl-speedbar-select-mra ()
15979 "Select the architecture under the cursor as MRA."
15980 (interactive)
15981 (if (not (vhdl-speedbar-check-unit 'architecture))
15982 (error "ERROR: No architecture under cursor")
15983 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15984 (ent-key (downcase (vhdl-speedbar-higher-text)))
15985 (ent-alist (vhdl-aget
15986 vhdl-entity-alist
15987 (or (vhdl-project-p)
15988 (abbreviate-file-name default-directory))))
15989 (ent-entry (vhdl-aget ent-alist ent-key)))
15990 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15991 (speedbar-refresh))))
15993 (declare-function speedbar-line-file "speedbar" (&optional p))
15995 (defun vhdl-speedbar-make-design ()
15996 "Make (compile) design unit or directory/project under the cursor."
15997 (interactive)
15998 (if (not (save-excursion (beginning-of-line)
15999 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
16000 (error "ERROR: No primary design unit or directory/project under cursor")
16001 (let ((is-unit (match-string 2))
16002 (unit-name (vhdl-speedbar-line-text))
16003 (vhdl-project (vhdl-speedbar-line-project))
16004 (directory (file-name-as-directory
16005 (or (speedbar-line-file) (speedbar-line-directory)))))
16006 (if (fboundp 'speedbar-select-attached-frame)
16007 (speedbar-select-attached-frame)
16008 (select-frame speedbar-attached-frame))
16009 (let ((default-directory directory))
16010 (vhdl-make (and is-unit unit-name))))))
16012 (defun vhdl-speedbar-generate-makefile ()
16013 "Generate Makefile for directory/project under the cursor."
16014 (interactive)
16015 (let ((vhdl-project (vhdl-speedbar-line-project))
16016 (default-directory (file-name-as-directory
16017 (or (speedbar-line-file) (speedbar-line-directory)))))
16018 (vhdl-generate-makefile)))
16020 (defun vhdl-speedbar-check-unit (design-unit)
16021 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
16022 expansion function)."
16023 (save-excursion
16024 (speedbar-position-cursor-on-line)
16025 (cond ((eq design-unit 'entity)
16026 (memq (get-text-property (match-end 0) 'face)
16027 '(vhdl-speedbar-entity-face
16028 vhdl-speedbar-entity-selected-face)))
16029 ((eq design-unit 'architecture)
16030 (memq (get-text-property (match-end 0) 'face)
16031 '(vhdl-speedbar-architecture-face
16032 vhdl-speedbar-architecture-selected-face)))
16033 ((eq design-unit 'subprogram)
16034 (eq (get-text-property (match-end 0) 'face)
16035 'vhdl-speedbar-subprogram-face))
16036 (t nil))))
16038 (defun vhdl-speedbar-set-depth (depth)
16039 "Set hierarchy display depth to DEPTH and refresh speedbar."
16040 (setq vhdl-speedbar-hierarchy-depth depth)
16041 (speedbar-refresh))
16043 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16044 ;; Fontification
16046 (defface vhdl-speedbar-entity-face
16047 '((((class color) (background light)) (:foreground "ForestGreen"))
16048 (((class color) (background dark)) (:foreground "PaleGreen")))
16049 "Face used for displaying entity names."
16050 :group 'speedbar-faces)
16052 (defface vhdl-speedbar-architecture-face
16053 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
16054 (((class color) (background light)) (:foreground "Blue"))
16056 (((class color) (background dark)) (:foreground "LightSkyBlue")))
16057 "Face used for displaying architecture names."
16058 :group 'speedbar-faces)
16060 (defface vhdl-speedbar-configuration-face
16061 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
16062 (((class color) (background dark)) (:foreground "Salmon")))
16063 "Face used for displaying configuration names."
16064 :group 'speedbar-faces)
16066 (defface vhdl-speedbar-package-face
16067 '((((class color) (background light)) (:foreground "Grey50"))
16068 (((class color) (background dark)) (:foreground "Grey80")))
16069 "Face used for displaying package names."
16070 :group 'speedbar-faces)
16072 (defface vhdl-speedbar-library-face
16073 '((((class color) (background light)) (:foreground "Purple"))
16074 (((class color) (background dark)) (:foreground "Orchid1")))
16075 "Face used for displaying library names."
16076 :group 'speedbar-faces)
16078 (defface vhdl-speedbar-instantiation-face
16079 '((((class color) (background light)) (:foreground "Brown"))
16080 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
16081 (((class color) (background dark)) (:foreground "Yellow")))
16082 "Face used for displaying instantiation names."
16083 :group 'speedbar-faces)
16085 (defface vhdl-speedbar-subprogram-face
16086 '((((class color) (background light)) (:foreground "Orchid4"))
16087 (((class color) (background dark)) (:foreground "BurlyWood2")))
16088 "Face used for displaying subprogram names."
16089 :group 'speedbar-faces)
16091 (defface vhdl-speedbar-entity-selected-face
16092 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
16093 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
16094 "Face used for displaying entity names."
16095 :group 'speedbar-faces)
16097 (defface vhdl-speedbar-architecture-selected-face
16098 '((((min-colors 88) (class color) (background light)) (:foreground
16099 "Blue1" :underline t))
16100 (((class color) (background light)) (:foreground "Blue" :underline t))
16101 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
16102 "Face used for displaying architecture names."
16103 :group 'speedbar-faces)
16105 (defface vhdl-speedbar-configuration-selected-face
16106 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
16107 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
16108 "Face used for displaying configuration names."
16109 :group 'speedbar-faces)
16111 (defface vhdl-speedbar-package-selected-face
16112 '((((class color) (background light)) (:foreground "Grey50" :underline t))
16113 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
16114 "Face used for displaying package names."
16115 :group 'speedbar-faces)
16117 (defface vhdl-speedbar-instantiation-selected-face
16118 '((((class color) (background light)) (:foreground "Brown" :underline t))
16119 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
16120 "Face used for displaying instantiation names."
16121 :group 'speedbar-faces)
16123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16124 ;; Initialization
16126 ;; add speedbar
16127 (when (fboundp 'speedbar)
16128 (let ((current-frame (selected-frame)))
16129 (condition-case ()
16130 (when (and vhdl-speedbar-auto-open
16131 (not (and (boundp 'speedbar-frame)
16132 (frame-live-p speedbar-frame))))
16133 (speedbar-frame-mode 1))
16134 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar")))
16135 (select-frame current-frame)))
16137 ;; initialize speedbar
16138 (if (not (boundp 'speedbar-frame))
16139 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
16140 (vhdl-speedbar-initialize)
16141 (when speedbar-frame (vhdl-speedbar-refresh)))
16144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16145 ;;; Structural composition
16146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16148 (defun vhdl-get-components-package-name ()
16149 "Return the name of the components package."
16150 (let ((project (vhdl-project-p)))
16151 (if project
16152 (vhdl-replace-string (car vhdl-components-package-name)
16153 (subst-char-in-string ? ?_ project))
16154 (cdr vhdl-components-package-name))))
16156 (defun vhdl-compose-new-component ()
16157 "Create entity and architecture for new component."
16158 (interactive)
16159 (let* ((case-fold-search t)
16160 (ent-name (read-from-minibuffer "entity name: "
16161 nil vhdl-minibuffer-local-map))
16162 (arch-name
16163 (if (equal (cdr vhdl-compose-architecture-name) "")
16164 (read-from-minibuffer "architecture name: "
16165 nil vhdl-minibuffer-local-map)
16166 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
16167 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
16168 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
16169 ;; open entity file
16170 (unless (eq vhdl-compose-create-files 'none)
16171 (setq ent-file-name
16172 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16173 "." (file-name-extension (buffer-file-name))))
16174 (when (and (file-exists-p ent-file-name)
16175 (not (y-or-n-p (concat "File \"" ent-file-name
16176 "\" exists; overwrite? "))))
16177 (error "ERROR: Creating component...aborted"))
16178 (find-file ent-file-name)
16179 (erase-buffer)
16180 (set-buffer-modified-p nil))
16181 ;; insert header
16182 (if vhdl-compose-include-header
16183 (progn (vhdl-template-header)
16184 (setq end-pos (point))
16185 (goto-char (point-max)))
16186 (vhdl-comment-display-line) (insert "\n\n"))
16187 ;; insert library clause
16188 (vhdl-template-package-std-logic-1164)
16189 (when vhdl-use-components-package
16190 (insert "\n")
16191 (vhdl-template-standard-package (vhdl-work-library)
16192 (vhdl-get-components-package-name)))
16193 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
16194 ;; insert entity declaration
16195 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
16196 (vhdl-insert-keyword " IS\n")
16197 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16198 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
16199 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16200 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16201 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
16202 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16203 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16204 (vhdl-insert-keyword "END ")
16205 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
16206 (insert ent-name ";\n\n")
16207 (vhdl-comment-display-line) (insert "\n")
16208 ;; open architecture file
16209 (if (not (eq vhdl-compose-create-files 'separate))
16210 (insert "\n")
16211 (goto-char (or end-pos (point-min)))
16212 (setq ent-buffer (current-buffer))
16213 (setq arch-file-name
16214 (concat (vhdl-replace-string vhdl-architecture-file-name
16215 (concat ent-name " " arch-name) t)
16216 "." (file-name-extension (buffer-file-name))))
16217 (when (and (file-exists-p arch-file-name)
16218 (not (y-or-n-p (concat "File \"" arch-file-name
16219 "\" exists; overwrite? "))))
16220 (error "ERROR: Creating component...aborted"))
16221 (find-file arch-file-name)
16222 (erase-buffer)
16223 (set-buffer-modified-p nil)
16224 ;; insert header
16225 (if vhdl-compose-include-header
16226 (progn (vhdl-template-header)
16227 (goto-char (point-max)))
16228 (vhdl-comment-display-line) (insert "\n\n")))
16229 ;; insert architecture body
16230 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
16231 (vhdl-insert-keyword " OF ") (insert ent-name)
16232 (vhdl-insert-keyword " IS\n\n")
16233 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16234 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
16235 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16236 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
16237 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16238 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16239 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
16240 (vhdl-insert-keyword "BEGIN")
16241 (when vhdl-self-insert-comments
16242 (insert " -- ")
16243 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16244 (insert arch-name))
16245 (insert "\n\n")
16246 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16247 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
16248 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16249 (vhdl-insert-keyword "END ")
16250 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16251 (insert arch-name ";\n\n")
16252 ;; insert footer and save
16253 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16254 (vhdl-template-footer)
16255 (vhdl-comment-display-line) (insert "\n"))
16256 (goto-char (or end-pos (point-min)))
16257 (setq arch-buffer (current-buffer))
16258 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
16259 (set-buffer arch-buffer) (save-buffer)
16260 (message "%s"
16261 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
16262 (and ent-file-name
16263 (format "\n File created: \"%s\"" ent-file-name))
16264 (and arch-file-name
16265 (format "\n File created: \"%s\"" arch-file-name))))))
16267 (defun vhdl-compose-place-component ()
16268 "Place new component by pasting current port as component declaration and
16269 component instantiation."
16270 (interactive)
16271 (if (not vhdl-port-list)
16272 (error "ERROR: No port has been read")
16273 (save-excursion
16274 (vhdl-prepare-search-2
16275 (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)
16276 (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))
16277 (error "ERROR: No architecture found"))
16278 (let* ((ent-name (match-string 1))
16279 (ent-file-name
16280 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16281 "." (file-name-extension (buffer-file-name))))
16282 (orig-buffer (current-buffer)))
16283 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
16284 ;; place component declaration
16285 (unless (or vhdl-use-components-package
16286 (vhdl-use-direct-instantiation)
16287 (save-excursion
16288 (re-search-forward
16289 (concat "^\\s-*component\\s-+"
16290 (car vhdl-port-list) "\\>") nil t)))
16291 (re-search-forward "^begin\\>" nil)
16292 (beginning-of-line)
16293 (skip-chars-backward " \t\n\r\f")
16294 (insert "\n\n") (indent-to vhdl-basic-offset)
16295 (vhdl-port-paste-component t))
16296 ;; place component instantiation
16297 (re-search-forward "^end\\>" nil)
16298 (beginning-of-line)
16299 (skip-chars-backward " \t\n\r\f")
16300 (insert "\n\n") (indent-to vhdl-basic-offset)
16301 (vhdl-port-paste-instance nil t t)
16302 ;; place use clause for used packages
16303 (when (nth 3 vhdl-port-list)
16304 ;; open entity file
16305 (when (file-exists-p ent-file-name)
16306 (find-file ent-file-name))
16307 (goto-char (point-min))
16308 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16309 (error "ERROR: Entity not found: \"%s\"" ent-name))
16310 (goto-char (match-beginning 0))
16311 (if (and (save-excursion
16312 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
16313 (match-string 1))
16314 (progn (goto-char (match-end 0))
16315 (beginning-of-line 2))
16316 (insert "\n")
16317 (backward-char))
16318 (vhdl-port-paste-context-clause)
16319 (switch-to-buffer orig-buffer))
16320 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
16322 (defun vhdl-compose-wire-components ()
16323 "Connect components."
16324 (interactive)
16325 (save-excursion
16326 (vhdl-prepare-search-2
16327 (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)
16328 (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))
16329 (error "ERROR: No architecture found"))
16330 (let* ((ent-name (match-string 1))
16331 (ent-file-name
16332 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16333 "." (file-name-extension (buffer-file-name))))
16334 (arch-decl-pos (point-marker))
16335 (arch-stat-pos (re-search-forward "^begin\\>" nil))
16336 (arch-end-pos (re-search-forward "^end\\>" nil))
16337 (pack-name (vhdl-get-components-package-name))
16338 (pack-file-name
16339 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16340 "." (file-name-extension (buffer-file-name))))
16341 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16342 port-alist generic-alist inst-alist
16343 signal-name signal-entry signal-alist local-list written-list
16344 single-in-list multi-in-list single-out-list multi-out-list
16345 constant-name constant-entry constant-alist single-list multi-list
16346 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16347 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16348 signal-beg-pos signal-pos
16349 constant-temp-pos port-temp-pos signal-temp-pos)
16350 (message "Wiring components...")
16351 ;; process all instances
16352 (goto-char arch-stat-pos)
16353 (while (re-search-forward
16354 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16355 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16356 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16357 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16358 "[ \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)
16359 (setq inst-name (match-string-no-properties 1)
16360 comp-name (match-string-no-properties 4)
16361 comp-ent-name (match-string-no-properties 12)
16362 has-generic (or (match-string 7) (match-string 17)))
16363 ;; get port ...
16364 (if comp-name
16365 ;; ... from component declaration
16366 (vhdl-visit-file
16367 (when vhdl-use-components-package pack-file-name) t
16368 (save-excursion
16369 (goto-char (point-min))
16370 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
16371 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
16372 (vhdl-port-copy)))
16373 ;; ... from entity declaration (direct instantiation)
16374 (setq comp-ent-file-name
16375 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
16376 "." (file-name-extension (buffer-file-name))))
16377 (vhdl-visit-file
16378 comp-ent-file-name t
16379 (save-excursion
16380 (goto-char (point-min))
16381 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
16382 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
16383 (vhdl-port-copy))))
16384 (vhdl-port-flatten t)
16385 (setq generic-alist (nth 1 vhdl-port-list)
16386 port-alist (nth 2 vhdl-port-list)
16387 vhdl-port-list nil)
16388 (setq constant-alist nil
16389 signal-alist nil)
16390 (when has-generic
16391 ;; process all constants in generic map
16392 (vhdl-forward-syntactic-ws)
16393 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16394 (setq constant-name (match-string-no-properties 3))
16395 (setq constant-entry
16396 (cons constant-name
16397 (if (match-string 1)
16398 (or (vhdl-aget generic-alist (match-string 2))
16399 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16400 (cdar generic-alist))))
16401 (push constant-entry constant-alist)
16402 (setq constant-name (downcase constant-name))
16403 (if (or (member constant-name single-list)
16404 (member constant-name multi-list))
16405 (progn (setq single-list (delete constant-name single-list))
16406 (add-to-list 'multi-list constant-name))
16407 (add-to-list 'single-list constant-name))
16408 (unless (match-string 1)
16409 (setq generic-alist (cdr generic-alist)))
16410 (vhdl-forward-syntactic-ws))
16411 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16412 ;; process all signals in port map
16413 (vhdl-forward-syntactic-ws)
16414 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16415 (setq signal-name (match-string-no-properties 3))
16416 (setq signal-entry
16417 (cons signal-name
16418 (if (match-string 1)
16419 (or (vhdl-aget port-alist (match-string 2))
16420 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16421 (cdar port-alist))))
16422 (push signal-entry signal-alist)
16423 (setq signal-name (downcase signal-name))
16424 (if (equal (upcase (nth 2 signal-entry)) "IN")
16425 ;; input signal
16426 (cond
16427 ((member signal-name local-list)
16428 nil)
16429 ((or (member signal-name single-out-list)
16430 (member signal-name multi-out-list))
16431 (setq single-out-list (delete signal-name single-out-list))
16432 (setq multi-out-list (delete signal-name multi-out-list))
16433 (add-to-list 'local-list signal-name))
16434 ((member signal-name single-in-list)
16435 (setq single-in-list (delete signal-name single-in-list))
16436 (add-to-list 'multi-in-list signal-name))
16437 ((not (member signal-name multi-in-list))
16438 (add-to-list 'single-in-list signal-name)))
16439 ;; output signal
16440 (cond
16441 ((member signal-name local-list)
16442 nil)
16443 ((or (member signal-name single-in-list)
16444 (member signal-name multi-in-list))
16445 (setq single-in-list (delete signal-name single-in-list))
16446 (setq multi-in-list (delete signal-name multi-in-list))
16447 (add-to-list 'local-list signal-name))
16448 ((member signal-name single-out-list)
16449 (setq single-out-list (delete signal-name single-out-list))
16450 (add-to-list 'multi-out-list signal-name))
16451 ((not (member signal-name multi-out-list))
16452 (add-to-list 'single-out-list signal-name))))
16453 (unless (match-string 1)
16454 (setq port-alist (cdr port-alist)))
16455 (vhdl-forward-syntactic-ws))
16456 (push (list inst-name (nreverse constant-alist)
16457 (nreverse signal-alist)) inst-alist))
16458 ;; prepare signal insertion
16459 (vhdl-goto-marker arch-decl-pos)
16460 (forward-line 1)
16461 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16462 (setq signal-pos (point-marker))
16463 (while (progn (vhdl-forward-syntactic-ws)
16464 (looking-at "signal\\>"))
16465 (beginning-of-line 2)
16466 (delete-region signal-pos (point)))
16467 (setq signal-beg-pos signal-pos)
16468 ;; open entity file
16469 (when (file-exists-p ent-file-name)
16470 (find-file ent-file-name))
16471 (goto-char (point-min))
16472 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16473 (error "ERROR: Entity not found: \"%s\"" ent-name))
16474 ;; prepare generic clause insertion
16475 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16476 (match-string 1))
16477 (goto-char (match-beginning 0))
16478 (indent-to vhdl-basic-offset)
16479 (insert "generic ();\n\n")
16480 (backward-char 4))
16481 (backward-char)
16482 (setq generic-pos (point-marker))
16483 (forward-sexp) (end-of-line)
16484 (delete-region generic-pos (point)) (delete-char 1)
16485 (insert "(\n")
16486 (when multi-list
16487 (insert "\n")
16488 (indent-to (* 2 vhdl-basic-offset))
16489 (insert "-- global generics\n"))
16490 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16491 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16492 ;; prepare port clause insertion
16493 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16494 (match-string 1))
16495 (goto-char (match-beginning 0))
16496 (indent-to vhdl-basic-offset)
16497 (insert "port ();\n\n")
16498 (backward-char 4))
16499 (backward-char)
16500 (setq port-in-pos (point-marker))
16501 (forward-sexp) (end-of-line)
16502 (delete-region port-in-pos (point)) (delete-char 1)
16503 (insert "(\n")
16504 (when (or multi-in-list multi-out-list)
16505 (insert "\n")
16506 (indent-to (* 2 vhdl-basic-offset))
16507 (insert "-- global ports\n"))
16508 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16509 port-out-pos (point-marker) port-inst-pos (point-marker)
16510 port-end-pos (point-marker))
16511 ;; insert generics, ports and signals
16512 (setq inst-alist (nreverse inst-alist))
16513 (while inst-alist
16514 (setq inst-name (nth 0 (car inst-alist))
16515 constant-alist (nth 1 (car inst-alist))
16516 signal-alist (nth 2 (car inst-alist))
16517 constant-temp-pos generic-inst-pos
16518 port-temp-pos port-inst-pos
16519 signal-temp-pos signal-pos)
16520 ;; generics
16521 (while constant-alist
16522 (setq constant-name (downcase (caar constant-alist))
16523 constant-entry (car constant-alist))
16524 (unless (string-match "^[0-9]+" constant-name)
16525 (cond ((member constant-name written-list)
16526 nil)
16527 ((member constant-name multi-list)
16528 (vhdl-goto-marker generic-pos)
16529 (setq generic-end-pos
16530 (vhdl-max-marker
16531 generic-end-pos
16532 (vhdl-compose-insert-generic constant-entry)))
16533 (setq generic-pos (point-marker))
16534 (add-to-list 'written-list constant-name))
16536 (vhdl-goto-marker
16537 (vhdl-max-marker generic-inst-pos generic-pos))
16538 (setq generic-end-pos
16539 (vhdl-compose-insert-generic constant-entry))
16540 (setq generic-inst-pos (point-marker))
16541 (add-to-list 'written-list constant-name))))
16542 (setq constant-alist (cdr constant-alist)))
16543 (when (/= constant-temp-pos generic-inst-pos)
16544 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16545 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16546 (insert "-- generics for \"" inst-name "\"\n")
16547 (vhdl-goto-marker generic-inst-pos))
16548 ;; ports and signals
16549 (while signal-alist
16550 (setq signal-name (downcase (caar signal-alist))
16551 signal-entry (car signal-alist))
16552 (cond ((member signal-name written-list)
16553 nil)
16554 ((member signal-name multi-in-list)
16555 (vhdl-goto-marker port-in-pos)
16556 (setq port-end-pos
16557 (vhdl-max-marker
16558 port-end-pos (vhdl-compose-insert-port signal-entry)))
16559 (setq port-in-pos (point-marker))
16560 (add-to-list 'written-list signal-name))
16561 ((member signal-name multi-out-list)
16562 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16563 (setq port-end-pos
16564 (vhdl-max-marker
16565 port-end-pos (vhdl-compose-insert-port signal-entry)))
16566 (setq port-out-pos (point-marker))
16567 (add-to-list 'written-list signal-name))
16568 ((or (member signal-name single-in-list)
16569 (member signal-name single-out-list))
16570 (vhdl-goto-marker
16571 (vhdl-max-marker
16572 port-inst-pos
16573 (vhdl-max-marker port-out-pos port-in-pos)))
16574 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16575 (setq port-inst-pos (point-marker))
16576 (add-to-list 'written-list signal-name))
16577 ((equal (upcase (nth 2 signal-entry)) "OUT")
16578 (vhdl-goto-marker signal-pos)
16579 (vhdl-compose-insert-signal signal-entry)
16580 (setq signal-pos (point-marker))
16581 (add-to-list 'written-list signal-name)))
16582 (setq signal-alist (cdr signal-alist)))
16583 (when (/= port-temp-pos port-inst-pos)
16584 (vhdl-goto-marker
16585 (vhdl-max-marker port-temp-pos
16586 (vhdl-max-marker port-in-pos port-out-pos)))
16587 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16588 (insert "-- ports to \"" inst-name "\"\n")
16589 (vhdl-goto-marker port-inst-pos))
16590 (when (/= signal-temp-pos signal-pos)
16591 (vhdl-goto-marker signal-temp-pos)
16592 (insert "\n") (indent-to vhdl-basic-offset)
16593 (insert "-- outputs of \"" inst-name "\"\n")
16594 (vhdl-goto-marker signal-pos))
16595 (setq inst-alist (cdr inst-alist)))
16596 ;; finalize generic/port clause
16597 (vhdl-goto-marker generic-end-pos) (backward-char)
16598 (when (= generic-beg-pos generic-end-pos)
16599 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16600 (insert ";") (backward-char))
16601 (insert ")")
16602 (vhdl-goto-marker port-end-pos) (backward-char)
16603 (when (= port-beg-pos port-end-pos)
16604 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16605 (insert ";") (backward-char))
16606 (insert ")")
16607 ;; align everything
16608 (when vhdl-auto-align
16609 (vhdl-goto-marker generic-beg-pos)
16610 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16611 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16612 (vhdl-goto-marker signal-beg-pos)
16613 (vhdl-align-region-groups signal-beg-pos signal-pos))
16614 (switch-to-buffer (marker-buffer signal-beg-pos))
16615 (message "Wiring components...done")))))
16617 (defun vhdl-compose-insert-generic (entry)
16618 "Insert ENTRY as generic declaration."
16619 (let (pos)
16620 (indent-to (* 2 vhdl-basic-offset))
16621 (insert (nth 0 entry) " : " (nth 1 entry))
16622 (when (nth 2 entry)
16623 (insert " := " (nth 2 entry)))
16624 (insert ";")
16625 (setq pos (point-marker))
16626 (when (and vhdl-include-port-comments (nth 3 entry))
16627 (vhdl-comment-insert-inline (nth 3 entry) t))
16628 (insert "\n")
16629 pos))
16631 (defun vhdl-compose-insert-port (entry)
16632 "Insert ENTRY as port declaration."
16633 (let (pos)
16634 (indent-to (* 2 vhdl-basic-offset))
16635 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16636 (setq pos (point-marker))
16637 (when (and vhdl-include-port-comments (nth 4 entry))
16638 (vhdl-comment-insert-inline (nth 4 entry) t))
16639 (insert "\n")
16640 pos))
16642 (defun vhdl-compose-insert-signal (entry)
16643 "Insert ENTRY as signal declaration."
16644 (indent-to vhdl-basic-offset)
16645 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16646 (when (and vhdl-include-port-comments (nth 4 entry))
16647 (vhdl-comment-insert-inline (nth 4 entry) t))
16648 (insert "\n"))
16650 (defun vhdl-compose-components-package ()
16651 "Generate a package containing component declarations for all entities in the
16652 current project/directory."
16653 (interactive)
16654 (vhdl-require-hierarchy-info)
16655 (let* ((project (vhdl-project-p))
16656 (pack-name (vhdl-get-components-package-name))
16657 (pack-file-name
16658 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16659 "." (file-name-extension (buffer-file-name))))
16660 (ent-alist (vhdl-aget vhdl-entity-alist
16661 (or project
16662 (abbreviate-file-name default-directory))))
16663 (lazy-lock-minimum-size 0)
16664 clause-pos component-pos)
16665 (message "Generating components package \"%s\"..." pack-name)
16666 ;; open package file
16667 (when (and (file-exists-p pack-file-name)
16668 (not (y-or-n-p (concat "File \"" pack-file-name
16669 "\" exists; overwrite? "))))
16670 (error "ERROR: Generating components package...aborted"))
16671 (find-file pack-file-name)
16672 (erase-buffer)
16673 ;; insert header
16674 (if vhdl-compose-include-header
16675 (progn (vhdl-template-header
16676 (concat "Components package (generated by Emacs VHDL Mode "
16677 vhdl-version ")"))
16678 (goto-char (point-max)))
16679 (vhdl-comment-display-line) (insert "\n\n"))
16680 ;; insert std_logic_1164 package
16681 (vhdl-template-package-std-logic-1164)
16682 (insert "\n") (setq clause-pos (point-marker))
16683 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16684 ;; insert package declaration
16685 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16686 (vhdl-insert-keyword " IS\n\n")
16687 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16688 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16689 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16690 (indent-to vhdl-basic-offset)
16691 (setq component-pos (point-marker))
16692 (insert "\n\n") (vhdl-insert-keyword "END ")
16693 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16694 (insert pack-name ";\n\n")
16695 ;; insert footer
16696 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16697 (vhdl-template-footer)
16698 (vhdl-comment-display-line) (insert "\n"))
16699 ;; insert component declarations
16700 (while ent-alist
16701 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16702 (progn (goto-char (point-min))
16703 (forward-line (1- (nth 3 (car ent-alist))))
16704 (end-of-line)
16705 (vhdl-port-copy)))
16706 (goto-char component-pos)
16707 (vhdl-port-paste-component t)
16708 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16709 (setq component-pos (point-marker))
16710 (goto-char clause-pos)
16711 (vhdl-port-paste-context-clause pack-name)
16712 (setq clause-pos (point-marker))
16713 (setq ent-alist (cdr ent-alist)))
16714 (goto-char (point-min))
16715 (save-buffer)
16716 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16717 pack-name pack-file-name)))
16719 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16720 conf-alist inst-alist
16721 &optional insert-conf)
16722 "Generate block configuration for architecture."
16723 (let ((margin (current-indentation))
16724 (beg (point-at-bol))
16725 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16726 ;; insert block configuration (for architecture)
16727 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16728 (setq margin (+ margin vhdl-basic-offset))
16729 ;; process all instances
16730 (while inst-alist
16731 (setq inst-entry (car inst-alist))
16732 ;; is component?
16733 (when (nth 4 inst-entry)
16734 (setq insert-conf t)
16735 (setq inst-path (nth 9 inst-entry))
16736 ;; skip common path with previous instance
16737 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16738 (setq inst-path (cdr inst-path)
16739 inst-prev-path (cdr inst-prev-path)))
16740 ;; insert block configuration end (for previous block/generate)
16741 (while inst-prev-path
16742 (setq margin (- margin vhdl-basic-offset))
16743 (indent-to margin)
16744 (vhdl-insert-keyword "END FOR;\n")
16745 (setq inst-prev-path (cdr inst-prev-path)))
16746 ;; insert block configuration beginning (for current block/generate)
16747 (indent-to margin)
16748 (while inst-path
16749 (setq margin (+ margin vhdl-basic-offset))
16750 (vhdl-insert-keyword "FOR ")
16751 (insert (car inst-path) "\n")
16752 (indent-to margin)
16753 (setq inst-path (cdr inst-path)))
16754 ;; insert component configuration beginning
16755 (vhdl-insert-keyword "FOR ")
16756 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16757 ;; find subconfiguration
16758 (setq conf-key (nth 7 inst-entry))
16759 (setq tmp-alist conf-alist)
16760 ;; use first configuration found for instance's entity
16761 (while (and tmp-alist (null conf-key))
16762 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16763 (setq conf-key (nth 0 (car tmp-alist))))
16764 (setq tmp-alist (cdr tmp-alist)))
16765 (setq conf-entry (vhdl-aget conf-alist conf-key))
16766 ;; insert binding indication ...
16767 ;; ... with subconfiguration (if exists)
16768 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16769 (progn
16770 (indent-to (+ margin vhdl-basic-offset))
16771 (vhdl-insert-keyword "USE CONFIGURATION ")
16772 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16773 (insert ";\n"))
16774 ;; ... with entity (if exists)
16775 (setq ent-entry (vhdl-aget ent-alist (nth 5 inst-entry)))
16776 (when ent-entry
16777 (indent-to (+ margin vhdl-basic-offset))
16778 (vhdl-insert-keyword "USE ENTITY ")
16779 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16780 ;; insert architecture name (if architecture exists)
16781 (when (nth 3 ent-entry)
16782 (setq arch-name
16783 ;; choose architecture name a) from configuration,
16784 ;; b) from mra, or c) from first architecture
16785 (or (nth 0 (vhdl-aget (nth 3 ent-entry)
16786 (or (nth 6 inst-entry)
16787 (nth 4 ent-entry))))
16788 (nth 1 (car (nth 3 ent-entry)))))
16789 (insert "(" arch-name ")"))
16790 (insert ";\n")
16791 ;; insert block configuration (for architecture of subcomponent)
16792 (when (and vhdl-compose-configuration-hierarchical
16793 (nth 3 ent-entry))
16794 (indent-to (+ margin vhdl-basic-offset))
16795 (vhdl-compose-configuration-architecture
16796 (nth 0 ent-entry) arch-name ent-alist conf-alist
16797 (nth 3 (vhdl-aget (nth 3 ent-entry) (downcase arch-name)))))))
16798 ;; insert component configuration end
16799 (indent-to margin)
16800 (vhdl-insert-keyword "END FOR;\n")
16801 (setq inst-prev-path (nth 9 inst-entry)))
16802 (setq inst-alist (cdr inst-alist)))
16803 ;; insert block configuration end (for block/generate)
16804 (while inst-prev-path
16805 (setq margin (- margin vhdl-basic-offset))
16806 (indent-to margin)
16807 (vhdl-insert-keyword "END FOR;\n")
16808 (setq inst-prev-path (cdr inst-prev-path)))
16809 (indent-to (- margin vhdl-basic-offset))
16810 ;; insert block configuration end or remove beginning (for architecture)
16811 (if insert-conf
16812 (vhdl-insert-keyword "END FOR;\n")
16813 (delete-region beg (point)))))
16815 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16816 "Generate configuration declaration."
16817 (interactive)
16818 (vhdl-require-hierarchy-info)
16819 (let ((ent-alist (vhdl-aget vhdl-entity-alist
16820 (or (vhdl-project-p)
16821 (abbreviate-file-name default-directory))))
16822 (conf-alist (vhdl-aget vhdl-config-alist
16823 (or (vhdl-project-p)
16824 (abbreviate-file-name default-directory))))
16825 (from-speedbar ent-name)
16826 inst-alist conf-name conf-file-name pos)
16827 (vhdl-prepare-search-2
16828 ;; get entity and architecture name
16829 (unless ent-name
16830 (save-excursion
16831 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16832 (not (equal "END" (upcase (match-string 1))))
16833 (setq ent-name (match-string-no-properties 3))
16834 (setq arch-name (match-string-no-properties 2)))
16835 (error "ERROR: Not within an architecture"))))
16836 (setq conf-name (vhdl-replace-string
16837 vhdl-compose-configuration-name
16838 (concat ent-name " " arch-name)))
16839 (setq inst-alist
16840 (nth 3 (vhdl-aget (nth 3 (vhdl-aget ent-alist (downcase ent-name)))
16841 (downcase arch-name)))))
16842 (message "Generating configuration \"%s\"..." conf-name)
16843 (if vhdl-compose-configuration-create-file
16844 ;; open configuration file
16845 (progn
16846 (setq conf-file-name
16847 (concat (vhdl-replace-string vhdl-configuration-file-name
16848 conf-name t)
16849 "." (file-name-extension (buffer-file-name))))
16850 (when (and (file-exists-p conf-file-name)
16851 (not (y-or-n-p (concat "File \"" conf-file-name
16852 "\" exists; overwrite? "))))
16853 (error "ERROR: Creating configuration...aborted"))
16854 (find-file conf-file-name)
16855 (erase-buffer)
16856 (set-buffer-modified-p nil)
16857 ;; insert header
16858 (if vhdl-compose-include-header
16859 (progn (vhdl-template-header
16860 (concat "Configuration declaration for design \""
16861 ent-name "(" arch-name ")\""))
16862 (goto-char (point-max)))
16863 (vhdl-comment-display-line) (insert "\n\n")))
16864 ;; goto end of architecture
16865 (unless from-speedbar
16866 (re-search-forward "^end\\>" nil)
16867 (end-of-line) (insert "\n\n")
16868 (vhdl-comment-display-line) (insert "\n\n")))
16869 ;; insert library clause
16870 (setq pos (point))
16871 (vhdl-template-standard-package (vhdl-work-library) nil)
16872 (when (/= pos (point))
16873 (insert "\n\n"))
16874 ;; insert configuration
16875 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16876 (vhdl-insert-keyword " OF ") (insert ent-name)
16877 (vhdl-insert-keyword " IS\n")
16878 (indent-to vhdl-basic-offset)
16879 ;; insert block configuration (for architecture)
16880 (vhdl-compose-configuration-architecture
16881 ent-name arch-name ent-alist conf-alist inst-alist t)
16882 (vhdl-insert-keyword "END ") (insert conf-name ";")
16883 (when conf-file-name
16884 ;; insert footer and save
16885 (insert "\n\n")
16886 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16887 (vhdl-template-footer)
16888 (vhdl-comment-display-line) (insert "\n"))
16889 (save-buffer))
16890 (message "%s"
16891 (concat (format "Generating configuration \"%s\"...done" conf-name)
16892 (and conf-file-name
16893 (format "\n File created: \"%s\"" conf-file-name))))))
16896 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16897 ;;; Compilation / Makefile generation
16898 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16899 ;; (using `compile.el')
16901 (defvar vhdl-compile-post-command ""
16902 "String appended to compile command after file name.")
16904 (defun vhdl-makefile-name ()
16905 "Return the Makefile name of the current project or the current compiler if
16906 no project is defined."
16907 (let ((project-alist (vhdl-aget vhdl-project-alist vhdl-project))
16908 (compiler-alist (vhdl-aget vhdl-compiler-alist vhdl-compiler)))
16909 (vhdl-replace-string
16910 (cons "\\(.*\\)\n\\(.*\\)"
16911 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16912 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16914 (defun vhdl-compile-directory ()
16915 "Return the directory where compilation/make should be run."
16916 (let* ((project (vhdl-aget vhdl-project-alist (vhdl-project-p t)))
16917 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
16918 (directory (vhdl-resolve-env-variable
16919 (if project
16920 (vhdl-replace-string
16921 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16922 (nth 6 compiler)))))
16923 (file-name-as-directory
16924 (if (file-name-absolute-p directory)
16925 directory
16926 (expand-file-name directory (vhdl-default-directory))))))
16928 (defun vhdl-uniquify (in-list)
16929 "Remove duplicate elements from IN-LIST."
16930 (let (out-list)
16931 (while in-list
16932 (add-to-list 'out-list (car in-list))
16933 (setq in-list (cdr in-list)))
16934 out-list))
16936 (defun vhdl-set-compiler (name)
16937 "Set current compiler to NAME."
16938 (interactive
16939 (list (let ((completion-ignore-case t))
16940 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16941 (if (assoc name vhdl-compiler-alist)
16942 (progn (setq vhdl-compiler name)
16943 (message "Current compiler: \"%s\"" vhdl-compiler))
16944 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16947 ;; Compilation
16949 (defun vhdl-compile-init ()
16950 "Initialize for compilation."
16951 (when (and (not vhdl-emacs-22)
16952 (or (null compilation-error-regexp-alist)
16953 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16954 compilation-error-regexp-alist))))
16955 ;; `compilation-error-regexp-alist'
16956 (let ((commands-alist vhdl-compiler-alist)
16957 regexp-alist sublist)
16958 (while commands-alist
16959 (setq sublist (nth 11 (car commands-alist)))
16960 (unless (or (equal "" (car sublist))
16961 (assoc (car sublist) regexp-alist))
16962 (push (list (nth 0 sublist)
16963 (if (and (featurep 'xemacs) (not (nth 1 sublist)))
16965 (nth 1 sublist))
16966 (nth 2 sublist) (nth 3 sublist))
16967 regexp-alist))
16968 (setq commands-alist (cdr commands-alist)))
16969 (setq compilation-error-regexp-alist
16970 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16971 ;; `compilation-file-regexp-alist'
16972 (let ((commands-alist vhdl-compiler-alist)
16973 regexp-alist sublist)
16974 ;; matches vhdl-mode file name output
16975 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16976 (while commands-alist
16977 (setq sublist (nth 12 (car commands-alist)))
16978 (unless (or (equal "" (car sublist))
16979 (assoc (car sublist) regexp-alist))
16980 (push sublist regexp-alist))
16981 (setq commands-alist (cdr commands-alist)))
16982 (setq compilation-file-regexp-alist
16983 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16985 (defvar vhdl-compile-file-name nil
16986 "Name of file to be compiled.")
16988 (defun vhdl-compile-print-file-name ()
16989 "Function called within `compile' to print out file name for compilers that
16990 do not print any file names."
16991 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16993 (defun vhdl-get-compile-options (project compiler file-name
16994 &optional file-options-only)
16995 "Get compiler options. Returning nil means do not compile this file."
16996 (let* ((compiler-options (nth 1 compiler))
16997 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
16998 (project-options (nth 0 project-entry))
16999 (exception-list (and file-name (nth 2 project-entry)))
17000 (work-library (vhdl-work-library))
17001 (case-fold-search nil)
17002 file-options)
17003 (while (and exception-list
17004 (not (string-match (caar exception-list) file-name)))
17005 (setq exception-list (cdr exception-list)))
17006 (if (and exception-list (not (cdar exception-list)))
17008 (if (and file-options-only (not exception-list))
17009 'default
17010 (setq file-options (cdar exception-list))
17011 ;; insert library name in compiler-specific options
17012 (setq compiler-options
17013 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
17014 work-library))
17015 ;; insert compiler-specific options in project-specific options
17016 (when project-options
17017 (setq project-options
17018 (vhdl-replace-string
17019 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17020 (concat work-library "\n" compiler-options))))
17021 ;; insert project-specific options in file-specific options
17022 (when file-options
17023 (setq file-options
17024 (vhdl-replace-string
17025 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
17026 (concat work-library "\n" compiler-options "\n"
17027 project-options))))
17028 ;; return options
17029 (or file-options project-options compiler-options)))))
17031 (defun vhdl-get-make-options (project compiler)
17032 "Get make options."
17033 (let* ((compiler-options (nth 3 compiler))
17034 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17035 (project-options (nth 1 project-entry))
17036 (makefile-name (vhdl-makefile-name)))
17037 ;; insert Makefile name in compiler-specific options
17038 (setq compiler-options
17039 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
17040 makefile-name))
17041 ;; insert compiler-specific options in project-specific options
17042 (when project-options
17043 (setq project-options
17044 (vhdl-replace-string
17045 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17046 (concat makefile-name "\n" compiler-options))))
17047 ;; return options
17048 (or project-options compiler-options)))
17050 (defun vhdl-compile ()
17051 "Compile current buffer using the VHDL compiler specified in
17052 `vhdl-compiler'."
17053 (interactive)
17054 (vhdl-compile-init)
17055 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17056 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17057 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17058 (command (nth 0 compiler))
17059 (default-directory (vhdl-compile-directory))
17060 (file-name (if vhdl-compile-absolute-path
17061 (buffer-file-name)
17062 (file-relative-name (buffer-file-name))))
17063 (options (vhdl-get-compile-options project compiler file-name))
17064 compilation-process-setup-function)
17065 (unless (file-directory-p default-directory)
17066 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17067 ;; put file name into quotes if it contains spaces
17068 (when (string-match " " file-name)
17069 (setq file-name (concat "\"" file-name "\"")))
17070 ;; print out file name if compiler does not
17071 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
17072 (buffer-file-name)
17073 (file-relative-name (buffer-file-name))))
17074 (when (and (= 0 (nth 1 (nth 10 compiler)))
17075 (= 0 (nth 1 (nth 11 compiler))))
17076 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
17077 ;; run compilation
17078 (if options
17079 (when command
17080 (compile (concat command " " options " " file-name
17081 (unless (equal vhdl-compile-post-command "")
17082 (concat " " vhdl-compile-post-command)))))
17083 (vhdl-warning "Your project settings tell me not to compile this file"))))
17085 (defvar vhdl-make-target "all"
17086 "Default target for `vhdl-make' command.")
17088 (defun vhdl-make (&optional target)
17089 "Call make command for compilation of all updated source files (requires
17090 `Makefile'). Optional argument TARGET allows you to compile the design
17091 specified by a target."
17092 (interactive)
17093 (setq vhdl-make-target
17094 (or target (read-from-minibuffer "Target: " vhdl-make-target
17095 vhdl-minibuffer-local-map)))
17096 (vhdl-compile-init)
17097 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17098 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17099 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17100 (command (nth 2 compiler))
17101 (options (vhdl-get-make-options project compiler))
17102 (default-directory (vhdl-compile-directory)))
17103 (unless (file-directory-p default-directory)
17104 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17105 ;; run make
17106 (compile (concat (if (equal command "") "make" command)
17107 " " options " " vhdl-make-target))))
17109 ;; Emacs 22+ setup
17110 (defvar vhdl-error-regexp-emacs-alist
17111 ;; Get regexps from `vhdl-compiler-alist'
17112 (let ((compiler-alist vhdl-compiler-alist)
17113 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
17114 (while compiler-alist
17115 ;; only add regexps for currently selected compiler
17116 (when (or (not vhdl-compile-use-local-error-regexp)
17117 (equal vhdl-compiler (nth 0 (car compiler-alist))))
17118 ;; add error message regexps
17119 (setq error-regexp-alist
17120 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
17121 (nth 11 (car compiler-alist)))
17122 error-regexp-alist))
17123 ;; add filename regexps
17124 (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
17125 (setq error-regexp-alist
17126 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
17127 (nth 12 (car compiler-alist)))
17128 error-regexp-alist))))
17129 (setq compiler-alist (cdr compiler-alist)))
17130 error-regexp-alist)
17131 "List of regexps for VHDL compilers. For Emacs 22+.")
17133 ;; Add error regexps using compilation-mode-hook.
17134 (defun vhdl-error-regexp-add-emacs ()
17135 "Set up Emacs compile for VHDL."
17136 (interactive)
17137 (when (and (boundp 'compilation-error-regexp-alist-alist)
17138 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
17139 ;; remove all other compilers
17140 (when vhdl-compile-use-local-error-regexp
17141 (setq compilation-error-regexp-alist nil))
17142 ;; add VHDL compilers
17143 (mapcar
17144 (lambda (item)
17145 (push (car item) compilation-error-regexp-alist)
17146 (push item compilation-error-regexp-alist-alist))
17147 vhdl-error-regexp-emacs-alist)))
17149 (when vhdl-emacs-22
17150 (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
17152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17153 ;; Makefile generation
17155 (defun vhdl-generate-makefile ()
17156 "Generate `Makefile'."
17157 (interactive)
17158 (let* ((compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17159 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17160 (command (nth 4 compiler)))
17161 ;; generate makefile
17162 (if command
17163 (let ((default-directory (vhdl-compile-directory)))
17164 (compile (vhdl-replace-string
17165 (cons "\\(.*\\) \\(.*\\)" command)
17166 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
17167 (vhdl-generate-makefile-1))))
17169 (defun vhdl-get-packages (lib-alist work-library)
17170 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
17171 (let (pack-list)
17172 (while lib-alist
17173 (when (equal (downcase (caar lib-alist)) (downcase work-library))
17174 (push (cdar lib-alist) pack-list))
17175 (setq lib-alist (cdr lib-alist)))
17176 pack-list))
17178 (defun vhdl-generate-makefile-1 ()
17179 "Generate Makefile for current project or directory."
17180 ;; scan hierarchy if required
17181 (if (vhdl-project-p)
17182 (unless (or (assoc vhdl-project vhdl-file-alist)
17183 (vhdl-load-cache vhdl-project))
17184 (vhdl-scan-project-contents vhdl-project))
17185 (let ((directory (abbreviate-file-name default-directory)))
17186 (unless (or (assoc directory vhdl-file-alist)
17187 (vhdl-load-cache directory))
17188 (vhdl-scan-directory-contents directory))))
17189 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
17190 (project (vhdl-project-p))
17191 (ent-alist (vhdl-aget vhdl-entity-alist (or project directory)))
17192 (conf-alist (vhdl-aget vhdl-config-alist (or project directory)))
17193 (pack-alist (vhdl-aget vhdl-package-alist (or project directory)))
17194 (regexp-list (or (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17195 '("\\1.vhd" "\\2_\\1.vhd" "\\1.vhd"
17196 "\\1.vhd" "\\1_body.vhd" identity)))
17197 (mapping-exist
17198 (if (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler)) t nil))
17199 (ent-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 0 regexp-list)))
17200 (arch-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
17201 (conf-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 2 regexp-list)))
17202 (pack-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 3 regexp-list)))
17203 (pack-body-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 4 regexp-list)))
17204 (adjust-case (nth 5 regexp-list))
17205 (work-library (downcase (vhdl-work-library)))
17206 (compile-directory (expand-file-name (vhdl-compile-directory)
17207 default-directory))
17208 (makefile-name (vhdl-makefile-name))
17209 rule-alist arch-alist inst-alist
17210 target-list depend-list unit-list prim-list second-list subcomp-list
17211 lib-alist lib-body-alist pack-list all-pack-list
17212 ent-key ent-file-name arch-key arch-file-name ent-arch-key
17213 conf-key conf-file-name pack-key pack-file-name
17214 ent-entry arch-entry conf-entry pack-entry inst-entry
17215 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
17216 tmp-key tmp-list rule)
17217 ;; check prerequisites
17218 (unless (file-exists-p compile-directory)
17219 (make-directory compile-directory t))
17220 (unless mapping-exist
17221 (vhdl-warning
17222 (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\""
17223 vhdl-compiler vhdl-compiler) t))
17224 (message "Generating makefile \"%s\"..." makefile-name)
17225 ;; rules for all entities
17226 (setq tmp-list ent-alist)
17227 (while ent-alist
17228 (setq ent-entry (car ent-alist)
17229 ent-key (nth 0 ent-entry))
17230 (when (nth 2 ent-entry)
17231 (setq ent-file-name (if vhdl-compile-absolute-path
17232 (nth 2 ent-entry)
17233 (file-relative-name (nth 2 ent-entry)
17234 compile-directory))
17235 arch-alist (nth 4 ent-entry)
17236 lib-alist (nth 6 ent-entry)
17237 rule (vhdl-aget rule-alist ent-file-name)
17238 target-list (nth 0 rule)
17239 depend-list (nth 1 rule)
17240 second-list nil
17241 subcomp-list nil)
17242 (setq tmp-key (vhdl-replace-string
17243 ent-regexp
17244 (funcall adjust-case
17245 (concat ent-key " " work-library))))
17246 (push (cons ent-key tmp-key) unit-list)
17247 ;; rule target for this entity
17248 (push ent-key target-list)
17249 ;; rule dependencies for all used packages
17250 (setq pack-list (vhdl-get-packages lib-alist work-library))
17251 (setq depend-list (append depend-list pack-list))
17252 (setq all-pack-list pack-list)
17253 ;; add rule
17254 (vhdl-aput 'rule-alist ent-file-name (list target-list depend-list))
17255 ;; rules for all corresponding architectures
17256 (while arch-alist
17257 (setq arch-entry (car arch-alist)
17258 arch-key (nth 0 arch-entry)
17259 ent-arch-key (concat ent-key "-" arch-key)
17260 arch-file-name (if vhdl-compile-absolute-path
17261 (nth 2 arch-entry)
17262 (file-relative-name (nth 2 arch-entry)
17263 compile-directory))
17264 inst-alist (nth 4 arch-entry)
17265 lib-alist (nth 5 arch-entry)
17266 rule (vhdl-aget rule-alist arch-file-name)
17267 target-list (nth 0 rule)
17268 depend-list (nth 1 rule))
17269 (setq tmp-key (vhdl-replace-string
17270 arch-regexp
17271 (funcall adjust-case
17272 (concat arch-key " " ent-key " "
17273 work-library))))
17274 (setq unit-list
17275 (cons (cons ent-arch-key tmp-key) unit-list))
17276 (push ent-arch-key second-list)
17277 ;; rule target for this architecture
17278 (push ent-arch-key target-list)
17279 ;; rule dependency for corresponding entity
17280 (push ent-key depend-list)
17281 ;; rule dependencies for contained component instantiations
17282 (while inst-alist
17283 (setq inst-entry (car inst-alist))
17284 (when (or (null (nth 8 inst-entry))
17285 (equal (downcase (nth 8 inst-entry)) work-library))
17286 (setq inst-ent-key (or (nth 7 inst-entry)
17287 (nth 5 inst-entry)))
17288 (setq depend-list (cons inst-ent-key depend-list)
17289 subcomp-list (cons inst-ent-key subcomp-list)))
17290 (setq inst-alist (cdr inst-alist)))
17291 ;; rule dependencies for all used packages
17292 (setq pack-list (vhdl-get-packages lib-alist work-library))
17293 (setq depend-list (append depend-list pack-list))
17294 (setq all-pack-list (append all-pack-list pack-list))
17295 ;; add rule
17296 (vhdl-aput 'rule-alist arch-file-name (list target-list depend-list))
17297 (setq arch-alist (cdr arch-alist)))
17298 (push (list ent-key second-list (append subcomp-list all-pack-list))
17299 prim-list))
17300 (setq ent-alist (cdr ent-alist)))
17301 (setq ent-alist tmp-list)
17302 ;; rules for all configurations
17303 (setq tmp-list conf-alist)
17304 (while conf-alist
17305 (setq conf-entry (car conf-alist)
17306 conf-key (nth 0 conf-entry)
17307 conf-file-name (if vhdl-compile-absolute-path
17308 (nth 2 conf-entry)
17309 (file-relative-name (nth 2 conf-entry)
17310 compile-directory))
17311 ent-key (nth 4 conf-entry)
17312 arch-key (nth 5 conf-entry)
17313 inst-alist (nth 6 conf-entry)
17314 lib-alist (nth 7 conf-entry)
17315 rule (vhdl-aget rule-alist conf-file-name)
17316 target-list (nth 0 rule)
17317 depend-list (nth 1 rule)
17318 subcomp-list (list ent-key))
17319 (setq tmp-key (vhdl-replace-string
17320 conf-regexp
17321 (funcall adjust-case
17322 (concat conf-key " " work-library))))
17323 (push (cons conf-key tmp-key) unit-list)
17324 ;; rule target for this configuration
17325 (push conf-key target-list)
17326 ;; rule dependency for corresponding entity and architecture
17327 (setq depend-list
17328 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
17329 ;; rule dependencies for used packages
17330 (setq pack-list (vhdl-get-packages lib-alist work-library))
17331 (setq depend-list (append depend-list pack-list))
17332 ;; rule dependencies for contained component configurations
17333 (while inst-alist
17334 (setq inst-entry (car inst-alist))
17335 (setq inst-ent-key (nth 2 inst-entry)
17336 inst-conf-key (nth 4 inst-entry))
17337 (when (equal (downcase (nth 5 inst-entry)) work-library)
17338 (when inst-ent-key
17339 (setq depend-list (cons inst-ent-key depend-list)
17340 subcomp-list (cons inst-ent-key subcomp-list)))
17341 (when inst-conf-key
17342 (setq depend-list (cons inst-conf-key depend-list)
17343 subcomp-list (cons inst-conf-key subcomp-list))))
17344 (setq inst-alist (cdr inst-alist)))
17345 ;; add rule
17346 (vhdl-aput 'rule-alist conf-file-name (list target-list depend-list))
17347 (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
17348 (setq conf-alist (cdr conf-alist)))
17349 (setq conf-alist tmp-list)
17350 ;; rules for all packages
17351 (setq tmp-list pack-alist)
17352 (while pack-alist
17353 (setq pack-entry (car pack-alist)
17354 pack-key (nth 0 pack-entry)
17355 pack-body-key nil)
17356 (when (nth 2 pack-entry)
17357 (setq pack-file-name (if vhdl-compile-absolute-path
17358 (nth 2 pack-entry)
17359 (file-relative-name (nth 2 pack-entry)
17360 compile-directory))
17361 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
17362 rule (vhdl-aget rule-alist pack-file-name)
17363 target-list (nth 0 rule) depend-list (nth 1 rule))
17364 (setq tmp-key (vhdl-replace-string
17365 pack-regexp
17366 (funcall adjust-case
17367 (concat pack-key " " work-library))))
17368 (push (cons pack-key tmp-key) unit-list)
17369 ;; rule target for this package
17370 (push pack-key target-list)
17371 ;; rule dependencies for all used packages
17372 (setq pack-list (vhdl-get-packages lib-alist work-library))
17373 (setq depend-list (append depend-list pack-list))
17374 (setq all-pack-list pack-list)
17375 ;; add rule
17376 (vhdl-aput 'rule-alist pack-file-name (list target-list depend-list))
17377 ;; rules for this package's body
17378 (when (nth 7 pack-entry)
17379 (setq pack-body-key (concat pack-key "-body")
17380 pack-body-file-name (if vhdl-compile-absolute-path
17381 (nth 7 pack-entry)
17382 (file-relative-name (nth 7 pack-entry)
17383 compile-directory))
17384 rule (vhdl-aget rule-alist pack-body-file-name)
17385 target-list (nth 0 rule)
17386 depend-list (nth 1 rule))
17387 (setq tmp-key (vhdl-replace-string
17388 pack-body-regexp
17389 (funcall adjust-case
17390 (concat pack-key " " work-library))))
17391 (setq unit-list
17392 (cons (cons pack-body-key tmp-key) unit-list))
17393 ;; rule target for this package's body
17394 (push pack-body-key target-list)
17395 ;; rule dependency for corresponding package declaration
17396 (push pack-key depend-list)
17397 ;; rule dependencies for all used packages
17398 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
17399 (setq depend-list (append depend-list pack-list))
17400 (setq all-pack-list (append all-pack-list pack-list))
17401 ;; add rule
17402 (vhdl-aput 'rule-alist pack-body-file-name
17403 (list target-list depend-list)))
17404 (setq prim-list
17405 (cons (list pack-key (when pack-body-key (list pack-body-key))
17406 all-pack-list)
17407 prim-list)))
17408 (setq pack-alist (cdr pack-alist)))
17409 (setq pack-alist tmp-list)
17410 ;; generate Makefile
17411 (let* ((project (vhdl-aget vhdl-project-alist project))
17412 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17413 (compiler-id (nth 9 compiler))
17414 (library-directory
17415 (vhdl-resolve-env-variable
17416 (vhdl-replace-string
17417 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
17418 compiler-id)))
17419 (makefile-path-name (expand-file-name
17420 makefile-name compile-directory))
17421 (orig-buffer (current-buffer))
17422 cell second-list subcomp-list options unit-key unit-name)
17423 ;; sort lists
17424 (setq unit-list (vhdl-sort-alist unit-list))
17425 (setq prim-list (vhdl-sort-alist prim-list))
17426 (setq tmp-list rule-alist)
17427 (while tmp-list ; pre-sort rule targets
17428 (setq cell (cdar tmp-list))
17429 (setcar cell (sort (car cell) 'string<))
17430 (setq tmp-list (cdr tmp-list)))
17431 (setq rule-alist ; sort by first rule target
17432 (sort rule-alist
17433 (function (lambda (a b)
17434 (string< (car (cadr a)) (car (cadr b)))))))
17435 ;; open and clear Makefile
17436 (set-buffer (find-file-noselect makefile-path-name t t))
17437 (erase-buffer)
17438 (insert "# -*- Makefile -*-\n"
17439 "### " (file-name-nondirectory makefile-name)
17440 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17441 "\n")
17442 (if project
17443 (insert "\n# Project : " (nth 0 project))
17444 (insert "\n# Directory : \"" directory "\""))
17445 (insert "\n# Platform : " vhdl-compiler
17446 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17447 (user-login-name) "\n")
17448 ;; insert compile and option variable settings
17449 (insert "\n\n# Define compilation command and options\n"
17450 "\nCOMPILE = " (nth 0 compiler)
17451 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
17452 (if (equal vhdl-compile-post-command "") ""
17453 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
17454 "\n")
17455 ;; insert library paths
17456 (setq library-directory
17457 (directory-file-name
17458 (if (file-name-absolute-p library-directory)
17459 library-directory
17460 (file-relative-name
17461 (expand-file-name library-directory directory)
17462 compile-directory))))
17463 (insert "\n\n# Define library paths\n"
17464 "\nLIBRARY-" work-library " = " library-directory "\n")
17465 (unless mapping-exist
17466 (insert "LIBRARY-" work-library "-make = " "$(LIBRARY-" work-library
17467 ")/make" "\n"))
17468 ;; insert variable definitions for all library unit files
17469 (insert "\n\n# Define library unit files\n")
17470 (setq tmp-list unit-list)
17471 (while unit-list
17472 (insert "\nUNIT-" work-library "-" (caar unit-list)
17473 " = \\\n\t$(LIBRARY-" work-library
17474 (if mapping-exist "" "-make") ")/" (cdar unit-list))
17475 (setq unit-list (cdr unit-list)))
17476 ;; insert variable definition for list of all library unit files
17477 (insert "\n\n\n# Define list of all library unit files\n"
17478 "\nALL_UNITS =")
17479 (setq unit-list tmp-list)
17480 (while unit-list
17481 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17482 (setq unit-list (cdr unit-list)))
17483 (insert "\n")
17484 (setq unit-list tmp-list)
17485 ;; insert `make all' rule
17486 (insert "\n\n\n# Rule for compiling entire design\n"
17487 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17488 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17489 " \\\n\t\t$(ALL_UNITS)\n")
17490 ;; insert `make clean' rule
17491 (insert "\n\n# Rule for cleaning entire design\n"
17492 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17493 "\n\t-rm -f $(ALL_UNITS)\n")
17494 ;; insert `make library' rule
17495 (insert "\n\n# Rule for creating library directory\n"
17496 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17497 " \\\n\t\t$(LIBRARY-" work-library ")"
17498 (if mapping-exist ""
17499 (concat " \\\n\t\t$(LIBRARY-" work-library "-make)\n"))
17500 "\n"
17501 "\n$(LIBRARY-" work-library ") :"
17502 "\n\t"
17503 (vhdl-replace-string
17504 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17505 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17506 "\n")
17507 (unless mapping-exist
17508 (insert "\n$(LIBRARY-" work-library "-make) :"
17509 "\n\t"
17510 "mkdir -p $(LIBRARY-" work-library "-make)\n"))
17511 ;; insert '.PHONY' declaration
17512 (insert "\n\n.PHONY : "
17513 (nth 0 vhdl-makefile-default-targets) " "
17514 (nth 1 vhdl-makefile-default-targets) " "
17515 (nth 2 vhdl-makefile-default-targets) "\n")
17516 ;; insert rule for each library unit
17517 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17518 (while prim-list
17519 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17520 (setq subcomp-list
17521 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17522 (setq unit-key (caar prim-list)
17523 unit-name (or (nth 0 (vhdl-aget ent-alist unit-key))
17524 (nth 0 (vhdl-aget conf-alist unit-key))
17525 (nth 0 (vhdl-aget pack-alist unit-key))))
17526 (insert "\n" unit-key)
17527 (unless (equal unit-key unit-name)
17528 (insert " \\\n" unit-name))
17529 (insert " :"
17530 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
17531 (while subcomp-list
17532 (when (and (assoc (car subcomp-list) unit-list)
17533 (not (equal unit-key (car subcomp-list))))
17534 (insert " \\\n\t\t" (car subcomp-list)))
17535 (setq subcomp-list (cdr subcomp-list)))
17536 (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17537 (while second-list
17538 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17539 (setq second-list (cdr second-list)))
17540 (insert "\n")
17541 (setq prim-list (cdr prim-list)))
17542 ;; insert rule for each library unit file
17543 (insert "\n\n# Rules for compiling single library unit files\n")
17544 (while rule-alist
17545 (setq rule (car rule-alist))
17546 ;; get compiler options for this file
17547 (setq options
17548 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17549 ;; insert rule if file is supposed to be compiled
17550 (setq target-list (nth 1 rule)
17551 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17552 ;; insert targets
17553 (setq tmp-list target-list)
17554 (while target-list
17555 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17556 (if (cdr target-list) " \\" " :"))
17557 (setq target-list (cdr target-list)))
17558 (setq target-list tmp-list)
17559 ;; insert file name as first dependency
17560 (insert " \\\n\t\t" (nth 0 rule))
17561 ;; insert dependencies (except if also target or unit does not exist)
17562 (while depend-list
17563 (when (and (not (member (car depend-list) target-list))
17564 (assoc (car depend-list) unit-list))
17565 (insert " \\\n\t\t"
17566 "$(UNIT-" work-library "-" (car depend-list) ")"))
17567 (setq depend-list (cdr depend-list)))
17568 ;; insert compile command
17569 (if options
17570 (insert "\n\t$(COMPILE) "
17571 (if (eq options 'default) "$(OPTIONS)" options) " "
17572 (nth 0 rule)
17573 (if (equal vhdl-compile-post-command "") ""
17574 " $(POST-COMPILE)") "\n")
17575 (insert "\n"))
17576 (unless (and options mapping-exist)
17577 (setq tmp-list target-list)
17578 (while target-list
17579 (insert "\t@touch $(UNIT-" work-library "-" (car target-list) ")\n")
17580 (setq target-list (cdr target-list)))
17581 (setq target-list tmp-list))
17582 (setq rule-alist (cdr rule-alist)))
17584 (insert "\n\n### " makefile-name " ends here\n")
17585 ;; run Makefile generation hook
17586 (run-hooks 'vhdl-makefile-generation-hook)
17587 (message "Generating makefile \"%s\"...done" makefile-name)
17588 ;; save and close file
17589 (if (file-writable-p makefile-path-name)
17590 (progn (save-buffer)
17591 (kill-buffer (current-buffer))
17592 (set-buffer orig-buffer)
17593 (when (fboundp 'add-to-history)
17594 (add-to-history 'file-name-history makefile-path-name)))
17595 (vhdl-warning-when-idle
17596 (format "File not writable: \"%s\""
17597 (abbreviate-file-name makefile-path-name)))
17598 (switch-to-buffer (current-buffer))))))
17601 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17602 ;;; Bug reports
17603 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17604 ;; (using `reporter.el')
17606 (defconst vhdl-mode-help-address
17607 "Reto Zimmermann <reto@gnu.org>"
17608 "Address for VHDL Mode bug reports.")
17610 (defun vhdl-submit-bug-report ()
17611 "Submit via mail a bug report on VHDL Mode."
17612 (interactive)
17613 ;; load in reporter
17614 (and
17615 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17616 (let ((reporter-prompt-for-summary-p t))
17617 (reporter-submit-bug-report
17618 vhdl-mode-help-address
17619 (concat "VHDL Mode " vhdl-version)
17620 (list
17621 ;; report all important user options
17622 'vhdl-offsets-alist
17623 'vhdl-comment-only-line-offset
17624 'tab-width
17625 'vhdl-electric-mode
17626 'vhdl-stutter-mode
17627 'vhdl-indent-tabs-mode
17628 'vhdl-project-alist
17629 'vhdl-project
17630 'vhdl-project-file-name
17631 'vhdl-project-auto-load
17632 'vhdl-project-sort
17633 'vhdl-compiler-alist
17634 'vhdl-compiler
17635 'vhdl-compile-use-local-error-regexp
17636 'vhdl-makefile-default-targets
17637 'vhdl-makefile-generation-hook
17638 'vhdl-default-library
17639 'vhdl-standard
17640 'vhdl-basic-offset
17641 'vhdl-upper-case-keywords
17642 'vhdl-upper-case-types
17643 'vhdl-upper-case-attributes
17644 'vhdl-upper-case-enum-values
17645 'vhdl-upper-case-constants
17646 'vhdl-use-direct-instantiation
17647 'vhdl-array-index-record-field-in-sensitivity-list
17648 'vhdl-compose-configuration-name
17649 'vhdl-entity-file-name
17650 'vhdl-architecture-file-name
17651 'vhdl-configuration-file-name
17652 'vhdl-package-file-name
17653 'vhdl-file-name-case
17654 'vhdl-electric-keywords
17655 'vhdl-optional-labels
17656 'vhdl-insert-empty-lines
17657 'vhdl-argument-list-indent
17658 'vhdl-association-list-with-formals
17659 'vhdl-conditions-in-parenthesis
17660 'vhdl-sensitivity-list-all
17661 'vhdl-zero-string
17662 'vhdl-one-string
17663 'vhdl-file-header
17664 'vhdl-file-footer
17665 'vhdl-company-name
17666 'vhdl-copyright-string
17667 'vhdl-platform-spec
17668 'vhdl-date-format
17669 'vhdl-modify-date-prefix-string
17670 'vhdl-modify-date-on-saving
17671 'vhdl-reset-kind
17672 'vhdl-reset-active-high
17673 'vhdl-clock-rising-edge
17674 'vhdl-clock-edge-condition
17675 'vhdl-clock-name
17676 'vhdl-reset-name
17677 'vhdl-model-alist
17678 'vhdl-include-port-comments
17679 'vhdl-include-direction-comments
17680 'vhdl-include-type-comments
17681 'vhdl-include-group-comments
17682 'vhdl-actual-generic-name
17683 'vhdl-actual-port-name
17684 'vhdl-instance-name
17685 'vhdl-testbench-entity-name
17686 'vhdl-testbench-architecture-name
17687 'vhdl-testbench-configuration-name
17688 'vhdl-testbench-dut-name
17689 'vhdl-testbench-include-header
17690 'vhdl-testbench-declarations
17691 'vhdl-testbench-statements
17692 'vhdl-testbench-initialize-signals
17693 'vhdl-testbench-include-library
17694 'vhdl-testbench-include-configuration
17695 'vhdl-testbench-create-files
17696 'vhdl-testbench-entity-file-name
17697 'vhdl-testbench-architecture-file-name
17698 'vhdl-compose-create-files
17699 'vhdl-compose-configuration-create-file
17700 'vhdl-compose-configuration-hierarchical
17701 'vhdl-compose-configuration-use-subconfiguration
17702 'vhdl-compose-include-header
17703 'vhdl-compose-architecture-name
17704 'vhdl-components-package-name
17705 'vhdl-use-components-package
17706 'vhdl-self-insert-comments
17707 'vhdl-prompt-for-comments
17708 'vhdl-inline-comment-column
17709 'vhdl-end-comment-column
17710 'vhdl-auto-align
17711 'vhdl-align-groups
17712 'vhdl-align-group-separate
17713 'vhdl-align-same-indent
17714 'vhdl-highlight-keywords
17715 'vhdl-highlight-names
17716 'vhdl-highlight-special-words
17717 'vhdl-highlight-forbidden-words
17718 'vhdl-highlight-verilog-keywords
17719 'vhdl-highlight-translate-off
17720 'vhdl-highlight-case-sensitive
17721 'vhdl-special-syntax-alist
17722 'vhdl-forbidden-words
17723 'vhdl-forbidden-syntax
17724 'vhdl-directive-keywords
17725 'vhdl-speedbar-auto-open
17726 'vhdl-speedbar-display-mode
17727 'vhdl-speedbar-scan-limit
17728 'vhdl-speedbar-jump-to-unit
17729 'vhdl-speedbar-update-on-saving
17730 'vhdl-speedbar-save-cache
17731 'vhdl-speedbar-cache-file-name
17732 'vhdl-index-menu
17733 'vhdl-source-file-menu
17734 'vhdl-hideshow-menu
17735 'vhdl-hide-all-init
17736 'vhdl-print-two-column
17737 'vhdl-print-customize-faces
17738 'vhdl-intelligent-tab
17739 'vhdl-indent-syntax-based
17740 'vhdl-indent-comment-like-next-code-line
17741 'vhdl-word-completion-case-sensitive
17742 'vhdl-word-completion-in-minibuffer
17743 'vhdl-underscore-is-part-of-word
17744 'vhdl-mode-hook)
17745 (function
17746 (lambda ()
17747 (insert
17748 (if vhdl-special-indent-hook
17749 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17750 "vhdl-special-indent-hook is set to '"
17751 (format "%s" vhdl-special-indent-hook)
17752 ".\nPerhaps this is your problem?\n"
17753 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17754 "\n"))))
17756 "Hi Reto,"))))
17759 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17760 ;;; Documentation
17761 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17763 (defconst vhdl-doc-release-notes nil
17765 Release Notes for VHDL Mode 3.37
17766 ================================
17768 - Added support for VHDL'08:
17769 - New keywords, types, functions, attributes, operators, packages
17770 - Context declaration
17771 - Block comments
17772 - Directives
17773 - `all' keyword in sensitivity list
17776 Release Notes for VHDL Mode 3.34
17777 ================================
17779 - Added support for GNU Emacs 22/23/24:
17780 - Compilation error parsing fixed for new `compile.el' package.
17782 - Port translation: Derive actual generic name from formal generic name.
17784 - New user options:
17785 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17788 Release Notes for VHDL Mode 3.33
17789 ================================
17791 New Features
17792 ------------
17794 CONFIGURATION DECLARATION GENERATION:
17795 - Automatic generation of a configuration declaration for a design.
17796 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17799 Key Bindings
17800 ------------
17802 For Emacs compliance the following key bindings have been changed:
17804 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17805 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17806 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17807 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17810 User Options
17811 ------------
17813 `vhdl-configuration-file-name': (new)
17814 Specify how the configuration file name is obtained.
17815 `vhdl-compose-configuration-name': (new)
17816 Specify how the configuration name is obtained.
17817 `vhdl-compose-configuration-create-file': (new)
17818 Specify whether a new file should be created for a configuration.
17819 `vhdl-compose-configuration-hierarchical': (new)
17820 Specify whether hierarchical configurations should be created.
17821 `vhdl-compose-configuration-use-subconfiguration': (new)
17822 Specify whether subconfigurations should be used inside configurations.
17823 `vhdl-makefile-default-targets': (new)
17824 Customize names of Makefile default targets.
17825 `vhdl-indent-comment-like-next-code-line': (new)
17826 Specify whether comment lines are indented like following code line.
17827 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17828 Specify whether to include array indices / record fields in sensitivity list.
17832 (defconst vhdl-doc-keywords nil
17834 Reserved words in VHDL
17835 ----------------------
17837 VHDL'08 (IEEE Std 1076-2008):
17838 `vhdl-08-keywords' : keywords
17839 `vhdl-08-types' : standardized types
17840 `vhdl-08-attributes' : standardized attributes
17841 `vhdl-08-functions' : standardized functions
17842 `vhdl-08-packages' : standardized packages and libraries
17844 VHDL'93/02 (IEEE Std 1076-1993/2002):
17845 `vhdl-02-keywords' : keywords
17846 `vhdl-02-types' : standardized types
17847 `vhdl-02-attributes' : standardized attributes
17848 `vhdl-02-enum-values' : standardized enumeration values
17849 `vhdl-02-functions' : standardized functions
17850 `vhdl-02-packages' : standardized packages and libraries
17852 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17853 `vhdl-ams-keywords' : keywords
17854 `vhdl-ams-types' : standardized types
17855 `vhdl-ams-attributes' : standardized attributes
17856 `vhdl-ams-enum-values' : standardized enumeration values
17857 `vhdl-ams-constants' : standardized constants
17858 `vhdl-ams-functions' : standardized functions
17860 Math Packages (IEEE Std 1076.2):
17861 `vhdl-math-types' : standardized types
17862 `vhdl-math-constants' : standardized constants
17863 `vhdl-math-functions' : standardized functions
17864 `vhdl-math-packages' : standardized packages
17866 Forbidden words:
17867 `vhdl-verilog-keywords' : Verilog reserved words
17869 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17872 (defconst vhdl-doc-coding-style nil
17874 For VHDL coding style and naming convention guidelines, see the following
17875 references:
17877 [1] Ben Cohen.
17878 \"VHDL Coding Styles and Methodologies\".
17879 Kluwer Academic Publishers, 1999.
17880 http://members.aol.com/vhdlcohen/vhdl/
17882 [2] Michael Keating and Pierre Bricaud.
17883 \"Reuse Methodology Manual, Second Edition\".
17884 Kluwer Academic Publishers, 1999.
17885 http://www.openmore.com/openmore/rmm2.html
17887 [3] European Space Agency.
17888 \"VHDL Modelling Guidelines\".
17889 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17891 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17892 to visually support naming conventions.")
17895 (defun vhdl-version ()
17896 "Echo the current version of VHDL Mode in the minibuffer."
17897 (interactive)
17898 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17899 (vhdl-keep-region-active))
17901 (defun vhdl-doc-variable (variable)
17902 "Display VARIABLE's documentation in *Help* buffer."
17903 (interactive)
17904 (unless (featurep 'xemacs)
17905 (help-setup-xref (list #'vhdl-doc-variable variable)
17906 (called-interactively-p 'interactive)))
17907 (with-output-to-temp-buffer
17908 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17909 (princ (documentation-property variable 'variable-documentation))
17910 (with-current-buffer standard-output
17911 (help-mode))
17912 (help-print-return-message)))
17914 (defun vhdl-doc-mode ()
17915 "Display VHDL Mode documentation in *Help* buffer."
17916 (interactive)
17917 (unless (featurep 'xemacs)
17918 (help-setup-xref (list #'vhdl-doc-mode)
17919 (called-interactively-p 'interactive)))
17920 (with-output-to-temp-buffer
17921 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17922 (princ mode-name)
17923 (princ " mode:\n")
17924 (princ (documentation 'vhdl-mode))
17925 (with-current-buffer standard-output
17926 (help-mode))
17927 (help-print-return-message)))
17930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17932 (provide 'vhdl-mode)
17934 ;;; vhdl-mode.el ends here