Use quit-window to hide buffers temporarily displayed by xref
[emacs.git] / lisp / progmodes / vhdl-mode.el
blob875de3b865c1be99424fb4b780a9bc94a701cb38
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2015 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.36.1"
17 "VHDL Mode version number.")
19 (defconst vhdl-time-stamp "2014-11-27"
20 "VHDL Mode time stamp for last update.")
22 ;; This file is part of GNU Emacs.
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;; Commentary:
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;; This package provides an Emacs major mode for editing VHDL code.
42 ;; It includes the following features:
44 ;; - Syntax highlighting
45 ;; - Indentation
46 ;; - Template insertion (electrification)
47 ;; - Insertion of file headers
48 ;; - Insertion of user-specified models
49 ;; - Port translation / testbench generation
50 ;; - Structural composition
51 ;; - Configuration generation
52 ;; - Sensitivity list updating
53 ;; - File browser
54 ;; - Design hierarchy browser
55 ;; - Source file compilation (syntax analysis)
56 ;; - Makefile generation
57 ;; - Code hiding
58 ;; - Word/keyword completion
59 ;; - Block commenting
60 ;; - Code fixing/alignment/beautification
61 ;; - PostScript printing
62 ;; - VHDL'87/'93 and VHDL-AMS supported
63 ;; - Comprehensive menu
64 ;; - Fully customizable
65 ;; - Works under GNU Emacs (recommended) and XEmacs
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; Documentation
70 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; Emacs Versions
75 ;; this updated version was only tested on: GNU Emacs 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 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
270 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
271 ("^\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*:\\( *\[[0-9]+\]\\)? \\([^ \t\n]+\\)(\\([0-9]+\\)):" 3 4 nil) ("" 0)
272 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
273 "\\1/_primary.dat" "\\1/body.dat" downcase))
274 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
275 ;; test.vhd:34: error message
276 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
277 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
278 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
279 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
280 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
281 ;; Quartus compiler
282 ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
283 ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
284 ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
285 ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
286 ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
287 ("Quartus" "make" "-work \\1" "make" "-f \\1"
288 nil "mkdir \\1" "./" "work/" "Makefile" "quartus"
289 ("^\\(Error\\|Warning\\): .* \\([^ \t\n]+\\)(\\([0-9]+\\))" 2 3 nil) ("" 0)
290 nil)
291 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
292 ;; ERROR: test.vhd(24): near "dnd": expecting: END
293 ;; WARNING[4]: test.vhd(30): A space is required between ...
294 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
295 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
296 ("^\\(ERROR\\|WARNING\\)[^:]*: \\([^ \t\n]+\\)(\\([0-9]+\\)):" 2 3 nil) ("" 0)
297 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
298 "\\1/_primary.dat" "\\1/body.dat" downcase))
299 ;; Savant: scram -publish-cc test.vhd
300 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
301 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
302 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
303 ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
304 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
305 "\\1_config.vhdl" "\\1_package.vhdl"
306 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
307 ;; Simili: vhdlp -work test.vhd
308 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
309 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
310 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
311 ("^\\(Error\\|Warning\\): \\w+: \\([^ \t\n]+\\): (line \\([0-9]+\\)): " 2 3 nil) ("" 0)
312 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
313 "\\1/prim.var" "\\1/_body.var" downcase))
314 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
315 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
316 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
317 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
318 ("^ *ERROR\[[0-9]+\]::File \\([^ \t\n]+\\) Line \\([0-9]+\\):" 1 2 nil) ("" 0)
319 nil)
320 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
321 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
322 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
323 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
324 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
325 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
326 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
327 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
328 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
329 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
330 ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
331 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
332 ;; Synplify:
333 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
334 ("Synplify" "n/a" "n/a" "make" "-f \\1"
335 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
336 ("^@[EWN]:\"\\([^ \t\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
337 nil)
338 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
339 ;; Compiling "test.vhd" line 1...
340 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
341 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
342 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
343 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
344 ("^ *Compiling \"\\(.+\\)\" " 1)
345 nil)
346 ;; VeriBest: vc vhdl test.vhd
347 ;; (no file name printed out!)
348 ;; 32: Z <= A and BitA ;
349 ;; ^^^^
350 ;; [Error] Name BITA is unknown
351 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
352 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
353 ("^ +\\([0-9]+\\): +[^ ]" nil 1 nil) ("" 0)
354 nil)
355 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
356 ;; Compiling "test.vhd" line 1...
357 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
358 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
359 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
360 ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
361 ("^ *Compiling \"\\(.+\\)\" " 1)
362 nil)
363 ;; Xilinx XST:
364 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
365 ("Xilinx XST" "xflow" "" "make" "-f \\1"
366 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
367 ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \t\n]+\\)\" Line \\([0-9]+\\)\." 1 2 nil) ("" 0)
368 nil)
370 "List of available VHDL compilers and their properties.
371 Each list entry specifies the following items for a compiler:
372 Compiler:
373 Compiler name : name used in option `vhdl-compiler' to choose compiler
374 Compile command : command used for source file compilation
375 Compile options : compile options (\"\\1\" inserts library name)
376 Make command : command used for compilation using a Makefile
377 Make options : make options (\"\\1\" inserts Makefile name)
378 Generate Makefile: use built-in function or command to generate a Makefile
379 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
380 Library command : command to create library directory \(\"\\1\" inserts
381 library directory, \"\\2\" inserts library name)
382 Compile directory: where compilation is run and the Makefile is placed
383 Library directory: directory of default library
384 Makefile name : name of Makefile (default is \"Makefile\")
385 ID string : compiler identification string (see `vhdl-project-alist')
386 Error message:
387 Regexp : regular expression to match error messages (*)
388 File subexp index: index of subexpression that matches the file name
389 Line subexp index: index of subexpression that matches the line number
390 Column subexp idx: index of subexpression that matches the column number
391 File message:
392 Regexp : regular expression to match a file name message
393 File subexp index: index of subexpression that matches the file name
394 Unit-to-file name mapping: mapping of library unit names to names of files
395 generated by the compiler (used for Makefile generation)
396 To string : string a name is mapped to (\"\\1\" inserts the unit name,
397 \"\\2\" inserts the entity name for architectures,
398 \"\\3\" inserts the library name)
399 Case adjustment : adjust case of inserted unit names
401 \(*) The regular expression must match the error message starting from the
402 beginning of the line (but not necessarily to the end of the line).
404 Compile options allows insertion of the library name (see `vhdl-project-alist')
405 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
407 For Makefile generation, the built-in function can be used (requires
408 specification of the unit-to-file name mapping). Alternatively, an
409 external command can be specified. Work directory allows specification of
410 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
411 used for Makefile generation). To use another library name than \"work\",
412 customize `vhdl-project-alist'. The library command is inserted in Makefiles
413 to automatically create the library directory if not existent.
415 Compile options, compile directory, library directory, and Makefile name are
416 overwritten by the project settings if a project is defined (see
417 `vhdl-project-alist'). Directory paths are relative to the source file
418 directory.
420 Some compilers do not include the file name in the error message, but print
421 out a file name message in advance. In this case, set \"File Subexp Index\"
422 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
423 If no file name at all is printed out, set both \"File Message\" entries to 0
424 \(a default file name message will be printed out instead, does not work in
425 XEmacs).
427 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
428 assigning its name to option `vhdl-compiler'.
430 Please send any missing or erroneous compiler properties to the maintainer for
431 updating.
433 NOTE: Activate new error and file message regexps and reflect the new setting
434 in the choice list of option `vhdl-compiler' by restarting Emacs."
435 :type '(repeat
436 (list :tag "Compiler" :indent 2
437 (string :tag "Compiler name ")
438 (string :tag "Compile command ")
439 (string :tag "Compile options " "-work \\1")
440 (string :tag "Make command " "make")
441 (string :tag "Make options " "-f \\1")
442 (choice :tag "Generate Makefile "
443 (const :tag "Built-in function" nil)
444 (string :tag "Command" "vmake \\2 > \\1"))
445 (string :tag "Library command " "mkdir \\1")
446 (directory :tag "Compile directory "
447 :validate vhdl-widget-directory-validate "./")
448 (directory :tag "Library directory "
449 :validate vhdl-widget-directory-validate "work/")
450 (file :tag "Makefile name " "Makefile")
451 (string :tag "ID string ")
452 (list :tag "Error message" :indent 4
453 (regexp :tag "Regexp ")
454 (choice :tag "File subexp "
455 (integer :tag "Index")
456 (const :tag "No file name" nil))
457 (integer :tag "Line subexp index")
458 (choice :tag "Column subexp "
459 (integer :tag "Index")
460 (const :tag "No column number" nil)))
461 (list :tag "File message" :indent 4
462 (regexp :tag "Regexp ")
463 (integer :tag "File subexp index"))
464 (choice :tag "Unit-to-file name mapping"
465 :format "%t: %[Value Menu%] %v\n"
466 (const :tag "Not defined" nil)
467 (list :tag "To string" :indent 4
468 (string :tag "Entity " "\\1.vhd")
469 (string :tag "Architecture " "\\2_\\1.vhd")
470 (string :tag "Configuration " "\\1.vhd")
471 (string :tag "Package " "\\1.vhd")
472 (string :tag "Package Body " "\\1_body.vhd")
473 (choice :tag "Case adjustment "
474 (const :tag "None" identity)
475 (const :tag "Upcase" upcase)
476 (const :tag "Downcase" downcase))))))
477 :set (lambda (variable value)
478 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
479 :version "24.4"
480 :group 'vhdl-compile)
482 (defcustom vhdl-compiler "GHDL"
483 "Specifies the VHDL compiler to be used for syntax analysis.
484 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
485 :type (let ((alist vhdl-compiler-alist) list)
486 (while alist
487 (push (list 'const (caar alist)) list)
488 (setq alist (cdr alist)))
489 (append '(choice) (nreverse list)))
490 :group 'vhdl-compile)
492 (defcustom vhdl-compile-use-local-error-regexp nil
493 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
494 In this case, only error message regexps for VHDL compilers are active if
495 compilation is started from a VHDL buffer. Otherwise, the error message
496 regexps are appended to the predefined global regexps, and all regexps are
497 active all the time. Note that by doing that, the predefined global regexps
498 might result in erroneous parsing of error messages for some VHDL compilers.
500 NOTE: Activate the new setting by restarting Emacs."
501 :version "25.1" ; t -> nil
502 :type 'boolean
503 :group 'vhdl-compile)
505 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
506 "List of default target names in Makefiles.
507 Automatically generated Makefiles include three default targets to compile
508 the entire design, clean the entire design and to create the design library.
509 This option allows you to change the names of these targets to avoid conflicts
510 with other user Makefiles."
511 :type '(list (string :tag "Compile entire design")
512 (string :tag "Clean entire design ")
513 (string :tag "Create design library"))
514 :version "24.3"
515 :group 'vhdl-compile)
517 (defcustom vhdl-makefile-generation-hook nil
518 "Functions to run at the end of Makefile generation.
519 Allows you to insert user specific parts into a Makefile.
521 Example:
522 \(lambda nil
523 \(re-search-backward \"^# Rule for compiling entire design\")
524 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
525 :type 'hook
526 :group 'vhdl-compile)
528 (defcustom vhdl-default-library "work"
529 "Name of default library.
530 Is overwritten by project settings if a project is active."
531 :type 'string
532 :group 'vhdl-compile)
535 (defgroup vhdl-project nil
536 "Customizations for projects."
537 :group 'vhdl)
539 (defcustom vhdl-project-alist
540 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
541 "~/example1/" ("src/system/" "src/components/") ""
542 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
543 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
544 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
545 ("Example 2" "Individual source files, multiple compilers in different directories"
546 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
547 nil "\\1/" "work" "\\1/work/" "Makefile" "")
548 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
549 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
550 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
551 -------------------------------------------------------------------------------
552 -- This is a multi-line project description
553 -- that can be used as a project dependent part of the file header.
555 "List of projects and their properties.
556 Name : name used in option `vhdl-project' to choose project
557 Title : title of project (single-line string)
558 Default directory: default project directory (absolute path)
559 Sources : a) source files : path + \"/\" + file name
560 b) directory : path + \"/\"
561 c) directory tree: \"-r \" + path + \"/\"
562 Exclude regexp : matches file/directory names to be excluded as sources
563 Compile options : project-specific options for each compiler
564 Compiler name : name of compiler for which these options are valid
565 Compile options: project-specific compiler options
566 (\"\\1\" inserts library name, \"\\2\" default options)
567 Make options: project-specific make options
568 (\"\\1\" inserts Makefile name, \"\\2\" default options)
569 Exceptions : file-specific exceptions
570 File name regexp: matches file names for which exceptions are valid
571 - Options : file-specific compiler options string
572 (\"\\1\" inserts library name, \"\\2\" default options,
573 \"\\3\" project-specific options)
574 - Do not compile: do not compile this file (in Makefile)
575 Compile directory: where compilation is run and the Makefile is placed
576 \(\"\\1\" inserts compiler ID string)
577 Library name : name of library (default is \"work\")
578 Library directory: path to library (\"\\1\" inserts compiler ID string)
579 Makefile name : name of Makefile
580 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
581 Description : description of project (multi-line string)
583 Project title and description are used to insert into the file header (see
584 option `vhdl-file-header').
586 The default directory must have an absolute path (use `M-TAB' for completion).
587 All other paths can be absolute or relative to the default directory. All
588 paths must end with '/'.
590 The design units found in the sources (files and directories) are shown in the
591 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
592 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
593 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
594 specified, the default directory is taken as source directory. Otherwise,
595 the default directory is only taken as source directory if there is a sources
596 entry with the empty string or \"./\". Exclude regexp allows you to filter
597 out specific file and directory names from the list of sources (e.g. CVS
598 directories).
600 Files are compiled in the compile directory. Makefiles are also placed into
601 the compile directory. Library directory specifies which directory the
602 compiler compiles into (used to generate the Makefile).
604 Since different compile/library directories and Makefiles may exist for
605 different compilers within one project, these paths and names allow the
606 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
607 Compile options, compile directory, library directory, and Makefile name
608 overwrite the settings of the current compiler.
610 File-specific compiler options (highest priority) overwrite project-specific
611 options which overwrite default options (lowest priority). Lower priority
612 options can be inserted in higher priority options. This allows you to reuse
613 default options (e.g. \"-file\") in project- or file-specific options (e.g.
614 \"-93 -file\").
616 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
617 by restarting Emacs."
618 :type `(repeat
619 (list :tag "Project" :indent 2
620 (string :tag "Name ")
621 (string :tag "Title ")
622 (directory :tag "Default directory"
623 :validate vhdl-widget-directory-validate
624 ,(abbreviate-file-name default-directory))
625 (repeat :tag "Sources " :indent 4
626 (directory :format " %v" "./"))
627 (regexp :tag "Exclude regexp ")
628 (repeat
629 :tag "Compile options " :indent 4
630 (list :tag "Compiler" :indent 6
631 ,(let ((alist vhdl-compiler-alist) list)
632 (while alist
633 (push (list 'const (caar alist)) list)
634 (setq alist (cdr alist)))
635 (append '(choice :tag "Compiler name")
636 (nreverse list)))
637 (string :tag "Compile options" "\\2")
638 (string :tag "Make options " "\\2")
639 (repeat
640 :tag "Exceptions " :indent 8
641 (cons :format "%v"
642 (regexp :tag "File name regexp ")
643 (choice :format "%[Value Menu%] %v"
644 (string :tag "Options" "\\3")
645 (const :tag "Do not compile" nil))))))
646 (directory :tag "Compile directory"
647 :validate vhdl-widget-directory-validate "./")
648 (string :tag "Library name " "work")
649 (directory :tag "Library directory"
650 :validate vhdl-widget-directory-validate "work/")
651 (file :tag "Makefile name " "Makefile")
652 (string :tag "Description: (type `C-j' for newline)"
653 :format "%t\n%v\n")))
654 :set (lambda (variable value)
655 (vhdl-custom-set variable value
656 'vhdl-update-mode-menu
657 'vhdl-speedbar-refresh))
658 :group 'vhdl-project)
660 (defcustom vhdl-project nil
661 "Specifies the default for the current project.
662 Select a project name from the ones defined in option `vhdl-project-alist'.
663 Is used to determine the project title and description to be inserted in file
664 headers and the source files/directories to be scanned in the hierarchy
665 browser. The current project can also be changed temporarily in the menu."
666 :type (let ((alist vhdl-project-alist) list)
667 (while alist
668 (push (list 'const (caar alist)) list)
669 (setq alist (cdr alist)))
670 (append '(choice (const :tag "None" nil) (const :tag "--"))
671 (nreverse list)))
672 :group 'vhdl-project)
674 (defcustom vhdl-project-file-name '("\\1.prj")
675 "List of file names/paths for importing/exporting project setups.
676 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
677 replaced by the user name (allows you to have user-specific project setups).
678 The first entry is used as file name to import/export individual project
679 setups. All entries are used to automatically import project setups at
680 startup (see option `vhdl-project-auto-load'). Projects loaded from the
681 first entry are automatically made current. Hint: specify local project
682 setups in first entry, global setups in following entries; loading a local
683 project setup will make it current, while loading the global setups
684 is done without changing the current project.
685 Names can also have an absolute path (i.e. project setups can be stored
686 in global directories)."
687 :type '(repeat (string :tag "File name" "\\1.prj"))
688 :group 'vhdl-project)
690 (defcustom vhdl-project-auto-load '(startup)
691 "Automatically load project setups from files.
692 All project setup files that match the file names specified in option
693 `vhdl-project-file-name' are automatically loaded. The project of the
694 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
695 entry is activated.
696 A project setup file can be obtained by exporting a project (see menu).
697 At startup: project setup file is loaded at Emacs startup"
698 :type '(set (const :tag "At startup" startup))
699 :group 'vhdl-project)
701 (defcustom vhdl-project-sort t
702 "Non-nil means projects are displayed in alphabetical order."
703 :type 'boolean
704 :group 'vhdl-project)
707 (defgroup vhdl-style nil
708 "Customizations for coding styles."
709 :group 'vhdl
710 :group 'vhdl-template
711 :group 'vhdl-port
712 :group 'vhdl-compose)
714 (defcustom vhdl-standard '(93 nil)
715 "VHDL standards used.
716 Basic standard:
717 VHDL'87 : IEEE Std 1076-1987
718 VHDL'93/02 : IEEE Std 1076-1993/2002
719 Additional standards:
720 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
721 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
723 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
724 \"Activate Options\"."
725 :type '(list (choice :tag "Basic standard"
726 (const :tag "VHDL'87" 87)
727 (const :tag "VHDL'93/02" 93))
728 (set :tag "Additional standards" :indent 2
729 (const :tag "VHDL-AMS" ams)
730 (const :tag "Math packages" math)))
731 :set (lambda (variable value)
732 (vhdl-custom-set variable value
733 'vhdl-template-map-init
734 'vhdl-mode-abbrev-table-init
735 'vhdl-template-construct-alist-init
736 'vhdl-template-package-alist-init
737 'vhdl-update-mode-menu
738 'vhdl-words-init 'vhdl-font-lock-init))
739 :group 'vhdl-style)
741 (defcustom vhdl-basic-offset 2
742 "Amount of basic offset used for indentation.
743 This value is used by + and - symbols in `vhdl-offsets-alist'."
744 :type 'integer
745 :group 'vhdl-style)
747 (defcustom vhdl-upper-case-keywords nil
748 "Non-nil means convert keywords to upper case.
749 This is done when typed or expanded or by the fix case functions."
750 :type 'boolean
751 :set (lambda (variable value)
752 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
753 :group 'vhdl-style)
755 (defcustom vhdl-upper-case-types nil
756 "Non-nil means convert standardized types to upper case.
757 This is done when expanded or by the fix case functions."
758 :type 'boolean
759 :set (lambda (variable value)
760 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
761 :group 'vhdl-style)
763 (defcustom vhdl-upper-case-attributes nil
764 "Non-nil means convert standardized attributes to upper case.
765 This is done when expanded or by the fix case functions."
766 :type 'boolean
767 :set (lambda (variable value)
768 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
769 :group 'vhdl-style)
771 (defcustom vhdl-upper-case-enum-values nil
772 "Non-nil means convert standardized enumeration values to upper case.
773 This is done when expanded or by the fix case functions."
774 :type 'boolean
775 :set (lambda (variable value)
776 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
777 :group 'vhdl-style)
779 (defcustom vhdl-upper-case-constants t
780 "Non-nil means convert standardized constants to upper case.
781 This is done when expanded."
782 :type 'boolean
783 :set (lambda (variable value)
784 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
785 :group 'vhdl-style)
787 (defcustom vhdl-use-direct-instantiation 'standard
788 "Non-nil means use VHDL'93 direct component instantiation.
789 Never : never
790 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
791 Always : always"
792 :type '(choice (const :tag "Never" never)
793 (const :tag "Standard" standard)
794 (const :tag "Always" always))
795 :group 'vhdl-style)
797 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
798 "Non-nil means include array indices / record fields in sensitivity list.
799 If a signal read in a process is a record field or pointed to by an array
800 index, the record field or array index is included with the record name in
801 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
802 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
803 :type 'boolean
804 :version "24.3"
805 :group 'vhdl-style)
807 (defgroup vhdl-naming nil
808 "Customizations for naming conventions."
809 :group 'vhdl)
811 (defcustom vhdl-entity-file-name '(".*" . "\\&")
812 (concat
813 "Specifies how the entity file name is obtained.
814 The entity file name can be obtained by modifying the entity name (e.g.
815 attaching or stripping off a substring). The file extension is automatically
816 taken from the file name of the current buffer."
817 vhdl-name-doc-string)
818 :type '(cons (regexp :tag "From regexp")
819 (string :tag "To string "))
820 :group 'vhdl-naming
821 :group 'vhdl-compose)
823 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
824 (concat
825 "Specifies how the architecture file name is obtained.
826 The architecture file name can be obtained by modifying the entity
827 and/or architecture name (e.g. attaching or stripping off a substring). The
828 file extension is automatically taken from the file name of the current
829 buffer. The string that is matched against the regexp is the concatenation
830 of the entity and the architecture name separated by a space. This gives
831 access to both names (see default setting as example)."
832 vhdl-name-doc-string)
833 :type '(cons (regexp :tag "From regexp")
834 (string :tag "To string "))
835 :group 'vhdl-naming
836 :group 'vhdl-compose)
838 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
839 (concat
840 "Specifies how the configuration file name is obtained.
841 The configuration file name can be obtained by modifying the configuration
842 name (e.g. attaching or stripping off a substring). The file extension is
843 automatically taken from the file name of the current buffer."
844 vhdl-name-doc-string)
845 :type '(cons (regexp :tag "From regexp")
846 (string :tag "To string "))
847 :group 'vhdl-naming
848 :group 'vhdl-compose)
850 (defcustom vhdl-package-file-name '(".*" . "\\&")
851 (concat
852 "Specifies how the package file name is obtained.
853 The package file name can be obtained by modifying the package name (e.g.
854 attaching or stripping off a substring). The file extension is automatically
855 taken from the file name of the current buffer. Package files can be created
856 in a different directory by prepending a relative or absolute path to the
857 file name."
858 vhdl-name-doc-string)
859 :type '(cons (regexp :tag "From regexp")
860 (string :tag "To string "))
861 :group 'vhdl-naming
862 :group 'vhdl-compose)
864 (defcustom vhdl-file-name-case 'identity
865 "Specifies how to change case for obtaining file names.
866 When deriving a file name from a VHDL unit name, case can be changed as
867 follows:
868 As Is: case is not changed (taken as is)
869 Lower Case: whole name is changed to lower case
870 Upper Case: whole name is changed to upper case
871 Capitalize: first letter of each word in name is capitalized"
872 :type '(choice (const :tag "As Is" identity)
873 (const :tag "Lower Case" downcase)
874 (const :tag "Upper Case" upcase)
875 (const :tag "Capitalize" capitalize))
876 :group 'vhdl-naming
877 :group 'vhdl-compose)
880 (defgroup vhdl-template nil
881 "Customizations for electrification."
882 :group 'vhdl)
884 (defcustom vhdl-electric-keywords '(vhdl user)
885 "Type of keywords for which electrification is enabled.
886 VHDL keywords: invoke built-in templates
887 User keywords: invoke user models (see option `vhdl-model-alist')"
888 :type '(set (const :tag "VHDL keywords" vhdl)
889 (const :tag "User model keywords" user))
890 :set (lambda (variable value)
891 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
892 :group 'vhdl-template)
894 (defcustom vhdl-optional-labels 'process
895 "Constructs for which labels are to be queried.
896 Template generators prompt for optional labels for:
897 None : no constructs
898 Processes only: processes only (also procedurals in VHDL-AMS)
899 All constructs: all constructs with optional labels and keyword END"
900 :type '(choice (const :tag "None" none)
901 (const :tag "Processes only" process)
902 (const :tag "All constructs" all))
903 :group 'vhdl-template)
905 (defcustom vhdl-insert-empty-lines 'unit
906 "Specifies whether to insert empty lines in some templates.
907 This improves readability of code. Empty lines are inserted in:
908 None : no constructs
909 Design units only: entities, architectures, configurations, packages only
910 All constructs : also all constructs with BEGIN...END parts
912 Replaces option `vhdl-additional-empty-lines'."
913 :type '(choice (const :tag "None" none)
914 (const :tag "Design units only" unit)
915 (const :tag "All constructs" all))
916 :group 'vhdl-template
917 :group 'vhdl-port
918 :group 'vhdl-compose)
920 (defcustom vhdl-argument-list-indent nil
921 "Non-nil means indent argument lists relative to opening parenthesis.
922 That is, argument, association, and port lists start on the same line as the
923 opening parenthesis and subsequent lines are indented accordingly.
924 Otherwise, lists start on a new line and are indented as normal code."
925 :type 'boolean
926 :group 'vhdl-template
927 :group 'vhdl-port
928 :group 'vhdl-compose)
930 (defcustom vhdl-association-list-with-formals t
931 "Non-nil means write association lists with formal parameters.
932 Templates prompt for formal and actual parameters (ports/generics).
933 When pasting component instantiations, formals are included.
934 If nil, only a list of actual parameters is entered."
935 :type 'boolean
936 :group 'vhdl-template
937 :group 'vhdl-port
938 :group 'vhdl-compose)
940 (defcustom vhdl-conditions-in-parenthesis nil
941 "Non-nil means place parenthesis around condition expressions."
942 :type 'boolean
943 :group 'vhdl-template)
945 (defcustom vhdl-zero-string "'0'"
946 "String to use for a logic zero."
947 :type 'string
948 :group 'vhdl-template)
950 (defcustom vhdl-one-string "'1'"
951 "String to use for a logic one."
952 :type 'string
953 :group 'vhdl-template)
956 (defgroup vhdl-header nil
957 "Customizations for file header."
958 :group 'vhdl-template
959 :group 'vhdl-compose)
961 (defcustom vhdl-file-header "\
962 -------------------------------------------------------------------------------
963 -- Title : <title string>
964 -- Project : <project>
965 -------------------------------------------------------------------------------
966 -- File : <filename>
967 -- Author : <author>
968 -- Company : <company>
969 -- Created : <date>
970 -- Last update: <date>
971 -- Platform : <platform>
972 -- Standard : <standard>
973 <projectdesc>-------------------------------------------------------------------------------
974 -- Description: <cursor>
975 <copyright>-------------------------------------------------------------------------------
976 -- Revisions :
977 -- Date Version Author Description
978 -- <date> 1.0 <login>\tCreated
979 -------------------------------------------------------------------------------
982 "String or file to insert as file header.
983 If the string specifies an existing file name, the contents of the file is
984 inserted, otherwise the string itself is inserted as file header.
985 Type `C-j' for newlines.
986 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
987 if the header needs to be version controlled.
989 The following keywords for template generation are supported:
990 <filename> : replaced by the name of the buffer
991 <author> : replaced by the user name and email address
992 \(`user-full-name',`mail-host-address', `user-mail-address')
993 <authorfull> : replaced by the user full name (`user-full-name')
994 <login> : replaced by user login name (`user-login-name')
995 <company> : replaced by contents of option `vhdl-company-name'
996 <date> : replaced by the current date
997 <year> : replaced by the current year
998 <project> : replaced by title of current project (`vhdl-project')
999 <projectdesc> : replaced by description of current project (`vhdl-project')
1000 <copyright> : replaced by copyright string (`vhdl-copyright-string')
1001 <platform> : replaced by contents of option `vhdl-platform-spec'
1002 <standard> : replaced by the VHDL language standard(s) used
1003 <... string> : replaced by a queried string (\"...\" is the prompt word)
1004 <title string>: replaced by file title in automatically generated files
1005 <cursor> : final cursor position
1007 The (multi-line) project description <projectdesc> can be used as a project
1008 dependent part of the file header and can also contain the above keywords."
1009 :type 'string
1010 :group 'vhdl-header)
1012 (defcustom vhdl-file-footer ""
1013 "String or file to insert as file footer.
1014 If the string specifies an existing file name, the contents of the file is
1015 inserted, otherwise the string itself is inserted as file footer (i.e. at
1016 the end of the file).
1017 Type `C-j' for newlines.
1018 The same keywords as in option `vhdl-file-header' can be used."
1019 :type 'string
1020 :group 'vhdl-header)
1022 (defcustom vhdl-company-name ""
1023 "Name of company to insert in file header.
1024 See option `vhdl-file-header'."
1025 :type 'string
1026 :group 'vhdl-header)
1028 (defcustom vhdl-copyright-string "\
1029 -------------------------------------------------------------------------------
1030 -- Copyright (c) <year> <company>
1032 "Copyright string to insert in file header.
1033 Can be multi-line string (type `C-j' for newline) and contain other file
1034 header keywords (see option `vhdl-file-header')."
1035 :type 'string
1036 :group 'vhdl-header)
1038 (defcustom vhdl-platform-spec ""
1039 "Specification of VHDL platform to insert in file header.
1040 The platform specification should contain names and versions of the
1041 simulation and synthesis tools used.
1042 See option `vhdl-file-header'."
1043 :type 'string
1044 :group 'vhdl-header)
1046 (defcustom vhdl-date-format "%Y-%m-%d"
1047 "Specifies the date format to use in the header.
1048 This string is passed as argument to the command `format-time-string'.
1049 For more information on format strings, see the documentation for the
1050 `format-time-string' command (C-h f `format-time-string')."
1051 :type 'string
1052 :group 'vhdl-header)
1054 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1055 "Prefix string of modification date in VHDL file header.
1056 If actualization of the modification date is called (menu,
1057 `\\[vhdl-template-modify]'), this string is searched and the rest
1058 of the line replaced by the current date."
1059 :type 'string
1060 :group 'vhdl-header)
1062 (defcustom vhdl-modify-date-on-saving t
1063 "Non-nil means update the modification date when the buffer is saved.
1064 Calls function `\\[vhdl-template-modify]').
1066 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1067 \"Activate Options\"."
1068 :type 'boolean
1069 :group 'vhdl-header)
1072 (defgroup vhdl-sequential-process nil
1073 "Customizations for sequential processes."
1074 :group 'vhdl-template)
1076 (defcustom vhdl-reset-kind 'async
1077 "Specifies which kind of reset to use in sequential processes."
1078 :type '(choice (const :tag "None" none)
1079 (const :tag "Synchronous" sync)
1080 (const :tag "Asynchronous" async)
1081 (const :tag "Query" query))
1082 :group 'vhdl-sequential-process)
1084 (defcustom vhdl-reset-active-high nil
1085 "Non-nil means reset in sequential processes is active high.
1086 Otherwise, reset is active low."
1087 :type 'boolean
1088 :group 'vhdl-sequential-process)
1090 (defcustom vhdl-clock-rising-edge t
1091 "Non-nil means rising edge of clock triggers sequential processes.
1092 Otherwise, falling edge triggers."
1093 :type 'boolean
1094 :group 'vhdl-sequential-process)
1096 (defcustom vhdl-clock-edge-condition 'standard
1097 "Syntax of the clock edge condition.
1098 Standard: \"clk'event and clk = '1'\"
1099 Function: \"rising_edge(clk)\""
1100 :type '(choice (const :tag "Standard" standard)
1101 (const :tag "Function" function))
1102 :group 'vhdl-sequential-process)
1104 (defcustom vhdl-clock-name ""
1105 "Name of clock signal to use in templates."
1106 :type 'string
1107 :group 'vhdl-sequential-process)
1109 (defcustom vhdl-reset-name ""
1110 "Name of reset signal to use in templates."
1111 :type 'string
1112 :group 'vhdl-sequential-process)
1115 (defgroup vhdl-model nil
1116 "Customizations for user models."
1117 :group 'vhdl)
1119 (defcustom vhdl-model-alist
1120 '(("Example Model"
1121 "<label> : process (<clock>, <reset>)
1122 begin -- process <label>
1123 if <reset> = '0' then -- asynchronous reset (active low)
1124 <cursor>
1125 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1126 if <enable> = '1' then -- synchronous load
1128 end if;
1129 end if;
1130 end process <label>;"
1131 "e" ""))
1132 "List of user models.
1133 VHDL models (templates) can be specified by the user in this list. They can be
1134 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1135 electrification (i.e. overriding existing or creating new keywords, see
1136 option `vhdl-electric-keywords').
1137 Name : name of model (string of words and spaces)
1138 String : string or name of file to be inserted as model (newline: `C-j')
1139 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1140 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1141 Keyword : keyword to invoke model
1143 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1144 A prompt that appears several times is queried once and replaced throughout
1145 the model. Special prompts are:
1146 <clock> : name specified in `vhdl-clock-name' (if not empty)
1147 <reset> : name specified in `vhdl-reset-name' (if not empty)
1148 <cursor>: final cursor position
1149 File header prompts (see variable `vhdl-file-header') are automatically
1150 replaced, so that user models can also be used to insert different types of
1151 headers.
1153 If the string specifies an existing file name, the contents of the file is
1154 inserted, otherwise the string itself is inserted.
1155 The code within the models should be correctly indented.
1156 Type `C-j' for newlines.
1158 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1159 \"Activate Options\"."
1160 :type '(repeat (list :tag "Model" :indent 2
1161 (string :tag "Name ")
1162 (string :tag "String : (type `C-j' for newline)"
1163 :format "%t\n%v")
1164 (sexp :tag "Key binding" x)
1165 (string :tag "Keyword " :format "%t: %v\n")))
1166 :set (lambda (variable value)
1167 (vhdl-custom-set variable value
1168 'vhdl-model-map-init
1169 'vhdl-model-defun
1170 'vhdl-mode-abbrev-table-init
1171 'vhdl-update-mode-menu))
1172 :group 'vhdl-model)
1175 (defgroup vhdl-compose nil
1176 "Customizations for structural composition."
1177 :group 'vhdl)
1179 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1180 (concat
1181 "Specifies how the component architecture name is obtained.
1182 The component architecture name can be obtained by modifying the entity name
1183 \(e.g. attaching or stripping off a substring).
1184 If TO STRING is empty, the architecture name is queried."
1185 vhdl-name-doc-string)
1186 :type '(cons (regexp :tag "From regexp")
1187 (string :tag "To string "))
1188 :group 'vhdl-compose)
1190 (defcustom vhdl-compose-configuration-name
1191 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1192 (concat
1193 "Specifies how the configuration name is obtained.
1194 The configuration name can be obtained by modifying the entity and/or
1195 architecture name (e.g. attaching or stripping off a substring). The string
1196 that is matched against the regexp is the concatenation of the entity and the
1197 architecture name separated by a space. This gives access to both names (see
1198 default setting as example)."
1199 vhdl-name-doc-string)
1200 :type '(cons (regexp :tag "From regexp")
1201 (string :tag "To string "))
1202 :group 'vhdl-compose)
1204 (defcustom vhdl-components-package-name
1205 '((".*" . "\\&_components") . "components")
1206 (concat
1207 "Specifies how the name for the components package is obtained.
1208 The components package is a package containing all component declarations for
1209 the current design. Its name can be obtained by modifying the project name
1210 \(e.g. attaching or stripping off a substring). If no project is defined, the
1211 DIRECTORY entry is chosen."
1212 vhdl-name-doc-string)
1213 :type '(cons (cons :tag "Project" :indent 2
1214 (regexp :tag "From regexp")
1215 (string :tag "To string "))
1216 (string :tag "Directory:\n String "))
1217 :group 'vhdl-compose)
1219 (defcustom vhdl-use-components-package nil
1220 "Non-nil means use a separate components package for component declarations.
1221 Otherwise, component declarations are inserted and searched for in the
1222 architecture declarative parts."
1223 :type 'boolean
1224 :group 'vhdl-compose)
1226 (defcustom vhdl-compose-include-header t
1227 "Non-nil means include a header in automatically generated files."
1228 :type 'boolean
1229 :group 'vhdl-compose)
1231 (defcustom vhdl-compose-create-files 'single
1232 "Specifies whether new files should be created for the new component.
1233 The component's entity and architecture are inserted:
1234 None : in current buffer
1235 Single file : in new single file
1236 Separate files: in two separate files
1237 The file names are obtained from variables `vhdl-entity-file-name' and
1238 `vhdl-architecture-file-name'."
1239 :type '(choice (const :tag "None" none)
1240 (const :tag "Single file" single)
1241 (const :tag "Separate files" separate))
1242 :group 'vhdl-compose)
1244 (defcustom vhdl-compose-configuration-create-file nil
1245 "Specifies whether a new file should be created for the configuration.
1246 If non-nil, a new file is created for the configuration.
1247 The file name is obtained from variable `vhdl-configuration-file-name'."
1248 :type 'boolean
1249 :group 'vhdl-compose)
1251 (defcustom vhdl-compose-configuration-hierarchical t
1252 "Specifies whether hierarchical configurations should be created.
1253 If non-nil, automatically created configurations are hierarchical and include
1254 the whole hierarchy of subcomponents. Otherwise the configuration only
1255 includes one level of subcomponents."
1256 :type 'boolean
1257 :group 'vhdl-compose)
1259 (defcustom vhdl-compose-configuration-use-subconfiguration t
1260 "Specifies whether subconfigurations should be used inside configurations.
1261 If non-nil, automatically created configurations use configurations in binding
1262 indications for subcomponents, if such configurations exist. Otherwise,
1263 entities are used in binding indications for subcomponents."
1264 :type 'boolean
1265 :group 'vhdl-compose)
1268 (defgroup vhdl-port nil
1269 "Customizations for port translation functions."
1270 :group 'vhdl
1271 :group 'vhdl-compose)
1273 (defcustom vhdl-include-port-comments nil
1274 "Non-nil means include port comments when a port is pasted."
1275 :type 'boolean
1276 :group 'vhdl-port)
1278 (defcustom vhdl-include-direction-comments nil
1279 "Non-nil means include port direction in instantiations as comments."
1280 :type 'boolean
1281 :group 'vhdl-port)
1283 (defcustom vhdl-include-type-comments nil
1284 "Non-nil means include generic/port type in instantiations as comments."
1285 :type 'boolean
1286 :group 'vhdl-port)
1288 (defcustom vhdl-include-group-comments 'never
1289 "Specifies whether to include group comments and spacings.
1290 The comments and empty lines between groups of ports are pasted:
1291 Never : never
1292 Declarations: in entity/component/constant/signal declarations only
1293 Always : also in generic/port maps"
1294 :type '(choice (const :tag "Never" never)
1295 (const :tag "Declarations" decl)
1296 (const :tag "Always" always))
1297 :group 'vhdl-port)
1299 (defcustom vhdl-actual-generic-name '(".*" . "\\&")
1300 (concat
1301 "Specifies how actual generic names are obtained from formal generic names.
1302 In a component instantiation, an actual generic name can be
1303 obtained by modifying the formal generic name (e.g. attaching or stripping
1304 off a substring)."
1305 vhdl-name-doc-string)
1306 :type '(cons (regexp :tag "From regexp")
1307 (string :tag "To string "))
1308 :group 'vhdl-port
1309 :version "24.4")
1311 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1312 (concat
1313 "Specifies how actual port names are obtained from formal port names.
1314 In a component instantiation, an actual port name can be obtained by
1315 modifying the formal port name (e.g. attaching or stripping off a substring)."
1316 vhdl-name-doc-string)
1317 :type '(cons (regexp :tag "From regexp")
1318 (string :tag "To string "))
1319 :group 'vhdl-port)
1321 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1322 (concat
1323 "Specifies how an instance name is obtained.
1324 The instance name can be obtained by modifying the name of the component to be
1325 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1326 by a unique number (starting with 1).
1327 If TO STRING is empty, the instance name is queried."
1328 vhdl-name-doc-string)
1329 :type '(cons (regexp :tag "From regexp")
1330 (string :tag "To string "))
1331 :group 'vhdl-port)
1334 (defgroup vhdl-testbench nil
1335 "Customizations for testbench generation."
1336 :group 'vhdl-port)
1338 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1339 (concat
1340 "Specifies how the testbench entity name is obtained.
1341 The entity name of a testbench can be obtained by modifying the name of
1342 the component to be tested (e.g. attaching or stripping off a substring)."
1343 vhdl-name-doc-string)
1344 :type '(cons (regexp :tag "From regexp")
1345 (string :tag "To string "))
1346 :group 'vhdl-testbench)
1348 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1349 (concat
1350 "Specifies how the testbench architecture name is obtained.
1351 The testbench architecture name can be obtained by modifying the name of
1352 the component to be tested (e.g. attaching or stripping off a substring).
1353 If TO STRING is empty, the architecture name is queried."
1354 vhdl-name-doc-string)
1355 :type '(cons (regexp :tag "From regexp")
1356 (string :tag "To string "))
1357 :group 'vhdl-testbench)
1359 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1360 (concat
1361 "Specifies how the testbench configuration name is obtained.
1362 The configuration name of a testbench can be obtained by modifying the entity
1363 and/or architecture name (e.g. attaching or stripping off a substring). The
1364 string that is matched against the regexp is the concatenation of the entity
1365 and the architecture name separated by a space. This gives access to both
1366 names (see default setting as example)."
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-dut-name '(".*" . "DUT")
1373 (concat
1374 "Specifies how a DUT instance name is obtained.
1375 The design-under-test instance name (i.e. the component instantiated in the
1376 testbench) can be obtained by modifying the component name (e.g. attaching
1377 or stripping off a substring)."
1378 vhdl-name-doc-string)
1379 :type '(cons (regexp :tag "From regexp")
1380 (string :tag "To string "))
1381 :group 'vhdl-testbench)
1383 (defcustom vhdl-testbench-include-header t
1384 "Non-nil means include a header in automatically generated files."
1385 :type 'boolean
1386 :group 'vhdl-testbench)
1388 (defcustom vhdl-testbench-declarations "\
1389 -- clock
1390 signal Clk : std_logic := '1';
1392 "String or file to be inserted in the testbench declarative part.
1393 If the string specifies an existing file name, the contents of the file is
1394 inserted, otherwise the string itself is inserted in the testbench
1395 architecture before the BEGIN keyword.
1396 Type `C-j' for newlines."
1397 :type 'string
1398 :group 'vhdl-testbench)
1400 (defcustom vhdl-testbench-statements "\
1401 -- clock generation
1402 Clk <= not Clk after 10 ns;
1404 -- waveform generation
1405 WaveGen_Proc: process
1406 begin
1407 -- insert signal assignments here
1409 wait until Clk = '1';
1410 end process WaveGen_Proc;
1412 "String or file to be inserted in the testbench statement part.
1413 If the string specifies an existing file name, the contents of the file is
1414 inserted, otherwise the string itself is inserted in the testbench
1415 architecture before the END keyword.
1416 Type `C-j' for newlines."
1417 :type 'string
1418 :group 'vhdl-testbench)
1420 (defcustom vhdl-testbench-initialize-signals nil
1421 "Non-nil means initialize signals with `0' when declared in testbench."
1422 :type 'boolean
1423 :group 'vhdl-testbench)
1425 (defcustom vhdl-testbench-include-library t
1426 "Non-nil means a library/use clause for std_logic_1164 is included."
1427 :type 'boolean
1428 :group 'vhdl-testbench)
1430 (defcustom vhdl-testbench-include-configuration t
1431 "Non-nil means a testbench configuration is attached at the end."
1432 :type 'boolean
1433 :group 'vhdl-testbench)
1435 (defcustom vhdl-testbench-create-files 'single
1436 "Specifies whether new files should be created for the testbench.
1437 testbench entity and architecture are inserted:
1438 None : in current buffer
1439 Single file : in new single file
1440 Separate files: in two separate files
1441 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1442 and `vhdl-testbench-architecture-file-name'."
1443 :type '(choice (const :tag "None" none)
1444 (const :tag "Single file" single)
1445 (const :tag "Separate files" separate))
1446 :group 'vhdl-testbench)
1448 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1449 (concat
1450 "Specifies how the testbench entity file name is obtained.
1451 The entity file name can be obtained by modifying the testbench entity name
1452 \(e.g. attaching or stripping off a substring). The file extension is
1453 automatically taken from the file name of the current buffer. Testbench
1454 files can be created in a different directory by prepending a relative or
1455 absolute path to the file name."
1456 vhdl-name-doc-string)
1457 :type '(cons (regexp :tag "From regexp")
1458 (string :tag "To string "))
1459 :group 'vhdl-testbench)
1461 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1462 (concat
1463 "Specifies how the testbench architecture file name is obtained.
1464 The architecture file name can be obtained by modifying the testbench entity
1465 and/or architecture name (e.g. attaching or stripping off a substring). The
1466 string that is matched against the regexp is the concatenation of the entity
1467 and the architecture name separated by a space. This gives access to both
1468 names (see default setting as example). Testbench files can be created in
1469 a different directory by prepending a relative or absolute path to the file
1470 name."
1471 vhdl-name-doc-string)
1472 :type '(cons (regexp :tag "From regexp")
1473 (string :tag "To string "))
1474 :group 'vhdl-testbench)
1477 (defgroup vhdl-comment nil
1478 "Customizations for comments."
1479 :group 'vhdl)
1481 (defcustom vhdl-self-insert-comments t
1482 "Non-nil means various templates automatically insert help comments."
1483 :type 'boolean
1484 :group 'vhdl-comment)
1486 (defcustom vhdl-prompt-for-comments t
1487 "Non-nil means various templates prompt for user definable comments."
1488 :type 'boolean
1489 :group 'vhdl-comment)
1491 (defcustom vhdl-inline-comment-column 40
1492 "Column to indent and align inline comments to.
1493 Overrides local option `comment-column'.
1495 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1496 \"Activate Options\"."
1497 :type 'integer
1498 :group 'vhdl-comment)
1500 (defcustom vhdl-end-comment-column 79
1501 "End of comment column.
1502 Comments that exceed this column number are wrapped.
1504 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1505 \"Activate Options\"."
1506 :type 'integer
1507 :group 'vhdl-comment)
1509 (defvar end-comment-column)
1512 (defgroup vhdl-beautify nil
1513 "Customizations for beautification."
1514 :group 'vhdl)
1516 (defcustom vhdl-auto-align t
1517 "Non-nil means align some templates automatically after generation."
1518 :type 'boolean
1519 :group 'vhdl-beautify)
1521 (defcustom vhdl-align-groups t
1522 "Non-nil means align groups of code lines separately.
1523 A group of code lines is a region of consecutive lines between two lines that
1524 match the regexp in option `vhdl-align-group-separate'."
1525 :type 'boolean
1526 :group 'vhdl-beautify)
1528 (defcustom vhdl-align-group-separate "^\\s-*$"
1529 "Regexp for matching a line that separates groups of lines for alignment.
1530 Examples:
1531 \"^\\s-*$\": matches an empty line
1532 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1533 :type 'regexp
1534 :group 'vhdl-beautify)
1536 (defcustom vhdl-align-same-indent t
1537 "Non-nil means align blocks with same indent separately.
1538 When a region or the entire buffer is aligned, the code is divided into
1539 blocks of same indent which are aligned separately (except for argument/port
1540 lists). This gives nicer alignment in most cases.
1541 Option `vhdl-align-groups' still applies within these blocks."
1542 :type 'boolean
1543 :group 'vhdl-beautify)
1545 (defcustom vhdl-beautify-options '(t t t t t)
1546 "List of options for beautifying code.
1547 Allows you to disable individual features of code beautification."
1548 :type '(list (boolean :tag "Whitespace cleanup ")
1549 (boolean :tag "Single statement per line")
1550 (boolean :tag "Indentation ")
1551 (boolean :tag "Alignment ")
1552 (boolean :tag "Case fixing "))
1553 :group 'vhdl-beautify
1554 :version "24.4")
1557 (defgroup vhdl-highlight nil
1558 "Customizations for highlighting."
1559 :group 'vhdl)
1561 (defcustom vhdl-highlight-keywords t
1562 "Non-nil means highlight VHDL keywords and other standardized words.
1563 The following faces are used:
1564 `font-lock-keyword-face' : keywords
1565 `font-lock-type-face' : standardized types
1566 `vhdl-font-lock-attribute-face': standardized attributes
1567 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1568 `vhdl-font-lock-function-face' : standardized function and package names
1570 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1571 entry \"Fontify Buffer\")."
1572 :type 'boolean
1573 :set (lambda (variable value)
1574 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1575 :group 'vhdl-highlight)
1577 (defcustom vhdl-highlight-names t
1578 "Non-nil means highlight declaration names and construct labels.
1579 The following faces are used:
1580 `font-lock-function-name-face' : names in declarations of units,
1581 subprograms, components, as well as labels of VHDL constructs
1582 `font-lock-type-face' : names in type/nature declarations
1583 `vhdl-font-lock-attribute-face': names in attribute declarations
1584 `font-lock-variable-name-face' : names in declarations of signals,
1585 variables, constants, subprogram parameters, generics, and ports
1587 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1588 entry \"Fontify Buffer\")."
1589 :type 'boolean
1590 :set (lambda (variable value)
1591 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1592 :group 'vhdl-highlight)
1594 (defcustom vhdl-highlight-special-words nil
1595 "Non-nil means highlight words with special syntax.
1596 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1597 are highlighted accordingly.
1598 Can be used for visual support of naming conventions.
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-forbidden-words nil
1608 "Non-nil means highlight forbidden words.
1609 The reserved words specified in option `vhdl-forbidden-words' or having the
1610 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1611 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1612 use them.
1614 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1615 entry \"Fontify Buffer\")."
1616 :type 'boolean
1617 :set (lambda (variable value)
1618 (vhdl-custom-set variable value
1619 'vhdl-words-init 'vhdl-font-lock-init))
1620 :group 'vhdl-highlight)
1622 (defcustom vhdl-highlight-verilog-keywords nil
1623 "Non-nil means highlight Verilog keywords as reserved words.
1624 Verilog keywords are highlighted in a warning color (face
1625 `vhdl-font-lock-reserved-words-face') to indicate not to 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-translate-off nil
1636 "Non-nil means background-highlight code excluded from translation.
1637 That is, all code between \"-- pragma translate_off\" and
1638 \"-- pragma translate_on\" is highlighted using a different background color
1639 \(face `vhdl-font-lock-translate-off-face').
1640 Note: this might slow down on-the-fly fontification (and thus editing).
1642 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1643 entry \"Fontify Buffer\")."
1644 :type 'boolean
1645 :set (lambda (variable value)
1646 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1647 :group 'vhdl-highlight)
1649 (defcustom vhdl-highlight-case-sensitive nil
1650 "Non-nil means consider case for highlighting.
1651 Possible trade-off:
1652 non-nil also upper-case VHDL words are highlighted, but case of words with
1653 special syntax is not considered
1654 nil only lower-case VHDL words are highlighted, but case of words with
1655 special syntax is considered
1656 Overrides local option `font-lock-keywords-case-fold-search'.
1658 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1659 entry \"Fontify Buffer\")."
1660 :type 'boolean
1661 :group 'vhdl-highlight)
1663 (defcustom vhdl-special-syntax-alist
1664 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1665 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1666 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1667 "List of special syntax to be highlighted.
1668 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1669 syntax (as regular expression) are highlighted in the corresponding color.
1671 Name : string of words and spaces
1672 Regexp : regular expression describing word syntax
1673 (e.g. \"\\\\=\<\\\w+_c\\\\=\>\" matches word with suffix \"_c\")
1674 expression must start with \"\\\\=\<\" and end with \"\\\\=\>\"
1675 if only whole words should be matched (no substrings)
1676 Color (light): foreground color for light background
1677 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1678 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1679 Color (dark) : foreground color for dark background
1680 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1681 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1682 In comments : If non-nil, words are also highlighted inside comments
1684 Can be used for visual support of naming conventions, such as highlighting
1685 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1686 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1687 common substrings or name suffices.
1688 For each entry, a new face is generated with the specified colors and name
1689 \"vhdl-font-lock-\" + name + \"-face\".
1691 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1692 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1693 :type '(repeat (list :tag "Face" :indent 2
1694 (string :tag "Name ")
1695 (regexp :tag "Regexp " "\\w+_")
1696 (string :tag "Color (light)")
1697 (string :tag "Color (dark) ")
1698 (boolean :tag "In comments ")))
1699 :set (lambda (variable value)
1700 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1701 :group 'vhdl-highlight)
1703 (defcustom vhdl-forbidden-words '()
1704 "List of forbidden words to be highlighted.
1705 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1706 words are highlighted in a warning color to indicate not to use them.
1708 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1709 entry \"Fontify Buffer\")."
1710 :type '(repeat (string :format "%v"))
1711 :set (lambda (variable value)
1712 (vhdl-custom-set variable value
1713 'vhdl-words-init 'vhdl-font-lock-init))
1714 :group 'vhdl-highlight)
1716 (defcustom vhdl-forbidden-syntax ""
1717 "Syntax of forbidden words to be highlighted.
1718 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1719 syntax are highlighted in a warning color to indicate not to use them.
1720 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1721 highlights identifiers with 10 or more characters).
1723 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1724 entry \"Fontify Buffer\")."
1725 :type 'regexp
1726 :set (lambda (variable value)
1727 (vhdl-custom-set variable value
1728 'vhdl-words-init 'vhdl-font-lock-init))
1729 :group 'vhdl-highlight)
1731 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1732 "List of compiler directive keywords recognized for highlighting.
1734 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1735 entry \"Fontify Buffer\")."
1736 :type '(repeat (string :format "%v"))
1737 :set (lambda (variable value)
1738 (vhdl-custom-set variable value
1739 'vhdl-words-init 'vhdl-font-lock-init))
1740 :group 'vhdl-highlight)
1743 (defgroup vhdl-speedbar nil
1744 "Customizations for speedbar."
1745 :group 'vhdl)
1747 (defcustom vhdl-speedbar-auto-open nil
1748 "Non-nil means automatically open speedbar at startup.
1749 Alternatively, the speedbar can be opened from the VHDL menu."
1750 :type 'boolean
1751 :group 'vhdl-speedbar)
1753 (defcustom vhdl-speedbar-display-mode 'files
1754 "Specifies the default displaying mode when opening speedbar.
1755 Alternatively, the displaying mode can be selected from the speedbar menu or
1756 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1757 :type '(choice (const :tag "Files" files)
1758 (const :tag "Directory hierarchy" directory)
1759 (const :tag "Project hierarchy" project))
1760 :group 'vhdl-speedbar)
1762 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1763 "Limits scanning of large files and netlists.
1764 Design units: maximum file size to scan for design units
1765 Hierarchy (instances of subcomponents):
1766 File size: maximum file size to scan for instances (in bytes)
1767 Instances per arch: maximum number of instances to scan per architecture
1769 \"None\" always means that there is no limit.
1770 In case of files not or incompletely scanned, a warning message and the file
1771 names are printed out.
1772 Background: scanning for instances is considerably slower than scanning for
1773 design units, especially when there are many instances. These limits should
1774 prevent the scanning of large netlists."
1775 :type '(list (choice :tag "Design units"
1776 :format "%t : %[Value Menu%] %v"
1777 (const :tag "None" nil)
1778 (integer :tag "File size"))
1779 (list :tag "Hierarchy" :indent 2
1780 (choice :tag "File size"
1781 :format "%t : %[Value Menu%] %v"
1782 (const :tag "None" nil)
1783 (integer :tag "Size "))
1784 (choice :tag "Instances per arch"
1785 (const :tag "None" nil)
1786 (integer :tag "Number "))))
1787 :group 'vhdl-speedbar)
1789 (defcustom vhdl-speedbar-jump-to-unit t
1790 "Non-nil means jump to the design unit code when opened in a buffer.
1791 The buffer cursor position is left unchanged otherwise."
1792 :type 'boolean
1793 :group 'vhdl-speedbar)
1795 (defcustom vhdl-speedbar-update-on-saving t
1796 "Automatically update design hierarchy when buffer is saved."
1797 :type 'boolean
1798 :group 'vhdl-speedbar)
1800 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1801 "Automatically save modified hierarchy caches when exiting Emacs.
1802 Hierarchy: design hierarchy information
1803 Display: displaying information (which design units to expand)"
1804 :type '(set (const :tag "Hierarchy" hierarchy)
1805 (const :tag "Display" display))
1806 :group 'vhdl-speedbar)
1808 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1809 "Name of file for saving hierarchy cache.
1810 \"\\1\" is replaced by the project name if a project is specified,
1811 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1812 different users to have cache files in the same directory). Can also have
1813 an absolute path (i.e. all caches can be stored in one global directory)."
1814 :type 'string
1815 :group 'vhdl-speedbar)
1818 (defgroup vhdl-menu nil
1819 "Customizations for menus."
1820 :group 'vhdl)
1822 (defcustom vhdl-index-menu nil
1823 "Non-nil means add an index menu for a source file when loading.
1824 Alternatively, the speedbar can be used. Note that the index menu scans a file
1825 when it is opened, while speedbar only scans the file upon request."
1826 :type 'boolean
1827 :group 'vhdl-menu)
1829 (defcustom vhdl-source-file-menu nil
1830 "Non-nil means add a menu of all source files in current directory.
1831 Alternatively, the speedbar can be used."
1832 :type 'boolean
1833 :group 'vhdl-menu)
1835 (defcustom vhdl-hideshow-menu nil
1836 "Non-nil means add hideshow menu and functionality at startup.
1837 Hideshow can also be enabled from the VHDL Mode menu.
1838 Hideshow allows hiding code of various VHDL constructs.
1840 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1841 \"Activate Options\"."
1842 :type 'boolean
1843 :group 'vhdl-menu)
1845 (defcustom vhdl-hide-all-init nil
1846 "Non-nil means hide all design units initially after a file is loaded."
1847 :type 'boolean
1848 :group 'vhdl-menu)
1851 (defgroup vhdl-print nil
1852 "Customizations for printing."
1853 :group 'vhdl)
1855 (defcustom vhdl-print-two-column t
1856 "Non-nil means print code in two columns and landscape format.
1857 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1858 prints VHDL files in a nice two-column landscape style.
1860 NOTE: Activate the new setting by restarting Emacs.
1861 Overrides `ps-print' settings locally."
1862 :type 'boolean
1863 :group 'vhdl-print)
1865 (defcustom vhdl-print-customize-faces t
1866 "Non-nil means use an optimized set of faces for PostScript printing.
1868 NOTE: Activate the new setting by restarting Emacs.
1869 Overrides `ps-print' settings locally."
1870 :type 'boolean
1871 :group 'vhdl-print)
1874 (defgroup vhdl-misc nil
1875 "Miscellaneous customizations."
1876 :group 'vhdl)
1878 (defcustom vhdl-intelligent-tab t
1879 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1880 That is, if preceding character is part of a word then complete word,
1881 else if not at beginning of line then insert tab,
1882 else if last command was a `TAB' or `RET' then dedent one step,
1883 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1884 If nil, TAB always indents current line (i.e. `TAB' is bound to
1885 `indent-according-to-mode').
1887 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1888 \"Activate Options\"."
1889 :type 'boolean
1890 :group 'vhdl-misc)
1892 (defcustom vhdl-indent-syntax-based t
1893 "Non-nil means indent lines of code based on their syntactic context.
1894 Otherwise, a line is indented like the previous nonblank line. This can be
1895 useful in large files where syntax-based indentation gets very slow."
1896 :type 'boolean
1897 :group 'vhdl-misc)
1899 (defcustom vhdl-indent-comment-like-next-code-line t
1900 "Non-nil means comment lines are indented like the following code line.
1901 Otherwise, comment lines are indented like the preceding code line.
1902 Indenting comment lines like the following code line gives nicer indentation
1903 when comments precede the code that they refer to."
1904 :type 'boolean
1905 :version "24.3"
1906 :group 'vhdl-misc)
1908 (defcustom vhdl-word-completion-case-sensitive nil
1909 "Non-nil means word completion using `TAB' is case sensitive.
1910 That is, `TAB' completes words that start with the same letters and case.
1911 Otherwise, case is ignored."
1912 :type 'boolean
1913 :group 'vhdl-misc)
1915 (defcustom vhdl-word-completion-in-minibuffer t
1916 "Non-nil enables word completion in minibuffer (for template prompts).
1918 NOTE: Activate the new setting by restarting Emacs."
1919 :type 'boolean
1920 :group 'vhdl-misc)
1922 (defcustom vhdl-underscore-is-part-of-word nil
1923 "Non-nil means consider the underscore character `_' as part of word.
1924 An identifier containing underscores is then treated as a single word in
1925 select and move operations. All parts of an identifier separated by underscore
1926 are treated as single words otherwise."
1927 :type 'boolean
1928 :group 'vhdl-misc)
1929 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1930 'superword-mode "24.4")
1933 (defgroup vhdl-related nil
1934 "Related general customizations."
1935 :group 'vhdl)
1937 ;; add related general customizations
1938 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1939 (if (featurep 'xemacs)
1940 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1941 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1942 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1943 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1944 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1945 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1946 (unless (featurep 'xemacs)
1947 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1948 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1949 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1950 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1952 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1953 ;; Hidden user variables
1955 (defvar vhdl-compile-absolute-path nil
1956 "If non-nil, use absolute instead of relative path for compiled files.")
1958 (defvar vhdl-comment-display-line-char ?-
1959 "Character to use in comment display line.")
1961 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1962 ;; Internal variables
1964 (defvar vhdl-menu-max-size 20
1965 "Specifies the maximum size of a menu before splitting it into submenus.")
1967 (defvar vhdl-progress-interval 1
1968 "Interval used to update progress status during long operations.
1969 If a number, percentage complete gets updated after each interval of
1970 that many seconds. To inhibit all messages, set this option to nil.")
1972 (defvar vhdl-inhibit-startup-warnings-p nil
1973 "If non-nil, inhibits start up compatibility warnings.")
1975 (defvar vhdl-strict-syntax-p nil
1976 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1977 If the syntactic symbol for a particular line does not match a symbol
1978 in the offsets alist, an error is generated, otherwise no error is
1979 reported and the syntactic symbol is ignored.")
1981 (defvar vhdl-echo-syntactic-information-p nil
1982 "If non-nil, syntactic info is echoed when the line is indented.")
1984 (defconst vhdl-offsets-alist-default
1985 '((string . -1000)
1986 (cpp-macro . -1000)
1987 (block-open . 0)
1988 (block-close . 0)
1989 (statement . 0)
1990 (statement-cont . vhdl-lineup-statement-cont)
1991 (statement-block-intro . +)
1992 (statement-case-intro . +)
1993 (case-alternative . +)
1994 (comment . vhdl-lineup-comment)
1995 (arglist-intro . +)
1996 (arglist-cont . 0)
1997 (arglist-cont-nonempty . vhdl-lineup-arglist)
1998 (arglist-close . vhdl-lineup-arglist)
1999 (entity . 0)
2000 (configuration . 0)
2001 (package . 0)
2002 (architecture . 0)
2003 (package-body . 0)
2005 "Default settings for offsets of syntactic elements.
2006 Do not change this constant! See the variable `vhdl-offsets-alist' for
2007 more information.")
2009 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
2010 "Association list of syntactic element symbols and indentation offsets.
2011 As described below, each cons cell in this list has the form:
2013 (SYNTACTIC-SYMBOL . OFFSET)
2015 When a line is indented, `vhdl-mode' first determines the syntactic
2016 context of the line by generating a list of symbols called syntactic
2017 elements. This list can contain more than one syntactic element and
2018 the global variable `vhdl-syntactic-context' contains the context list
2019 for the line being indented. Each element in this list is actually a
2020 cons cell of the syntactic symbol and a buffer position. This buffer
2021 position is call the relative indent point for the line. Some
2022 syntactic symbols may not have a relative indent point associated with
2023 them.
2025 After the syntactic context list for a line is generated, `vhdl-mode'
2026 calculates the absolute indentation for the line by looking at each
2027 syntactic element in the list. First, it compares the syntactic
2028 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2029 finds a match, it adds the OFFSET to the column of the relative indent
2030 point. The sum of this calculation for each element in the syntactic
2031 list is the absolute offset for line being indented.
2033 If the syntactic element does not match any in the `vhdl-offsets-alist',
2034 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2035 the element is ignored.
2037 Actually, OFFSET can be an integer, a function, a variable, or one of
2038 the following symbols: `+', `-', `++', or `--'. These latter
2039 designate positive or negative multiples of `vhdl-basic-offset',
2040 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2041 called with a single argument containing the cons of the syntactic
2042 element symbol and the relative indent point. The function should
2043 return an integer offset.
2045 Here is the current list of valid syntactic element symbols:
2047 string -- inside multi-line string
2048 block-open -- statement block open
2049 block-close -- statement block close
2050 statement -- a VHDL statement
2051 statement-cont -- a continuation of a VHDL statement
2052 statement-block-intro -- the first line in a new statement block
2053 statement-case-intro -- the first line in a case alternative block
2054 case-alternative -- a case statement alternative clause
2055 comment -- a line containing only a comment
2056 arglist-intro -- the first line in an argument list
2057 arglist-cont -- subsequent argument list lines when no
2058 arguments follow on the same line as
2059 the arglist opening paren
2060 arglist-cont-nonempty -- subsequent argument list lines when at
2061 least one argument follows on the same
2062 line as the arglist opening paren
2063 arglist-close -- the solo close paren of an argument list
2064 entity -- inside an entity declaration
2065 configuration -- inside a configuration declaration
2066 package -- inside a package declaration
2067 architecture -- inside an architecture body
2068 package-body -- inside a package body")
2070 (defvar vhdl-comment-only-line-offset 0
2071 "Extra offset for line which contains only the start of a comment.
2072 Can contain an integer or a cons cell of the form:
2074 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2076 Where NON-ANCHORED-OFFSET is the amount of offset given to
2077 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2078 the amount of offset to give column-zero anchored comment-only lines.
2079 Just an integer as value is equivalent to (<val> . 0)")
2081 (defvar vhdl-special-indent-hook nil
2082 "Hook for user defined special indentation adjustments.
2083 This hook gets called after a line is indented by the mode.")
2085 (defvar vhdl-style-alist
2086 '(("IEEE"
2087 (vhdl-basic-offset . 4)
2088 (vhdl-offsets-alist . ())))
2089 "Styles of Indentation.
2090 Elements of this alist are of the form:
2092 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2094 where STYLE-STRING is a short descriptive string used to select a
2095 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2096 value for that variable when using the selected style.
2098 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2099 case, the VALUE is a list containing elements of the form:
2101 (SYNTACTIC-SYMBOL . VALUE)
2103 as described in `vhdl-offsets-alist'. These are passed directly to
2104 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2105 your style, only those that are different from the default.")
2107 ;; dynamically append the default value of most variables
2108 (or (assoc "Default" vhdl-style-alist)
2109 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2110 vhdl-strict-syntax-p
2111 vhdl-echo-syntactic-information-p
2112 vhdl-basic-offset
2113 vhdl-offsets-alist
2114 vhdl-comment-only-line-offset))
2115 (default (cons "Default"
2116 (mapcar
2117 (function
2118 (lambda (var)
2119 (cons var (symbol-value var))))
2120 varlist))))
2121 (push default vhdl-style-alist)))
2123 (defvar vhdl-mode-hook nil
2124 "Hook called by `vhdl-mode'.")
2127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2128 ;;; Required packages
2129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2131 ;; mandatory
2132 (require 'compile) ; XEmacs
2133 (require 'easymenu)
2134 (require 'hippie-exp)
2136 ;; optional (minimize warning messages during compile)
2137 (unless (featurep 'xemacs)
2138 (eval-when-compile
2139 (require 'font-lock)
2140 (require 'ps-print)
2141 (require 'speedbar))) ; for speedbar-with-writable
2143 (defun vhdl-aput (alist-symbol key &optional value)
2144 "Insert a key-value pair into an alist.
2145 The alist is referenced by ALIST-SYMBOL. The key-value pair is made
2146 from KEY and VALUE. If the key-value pair referenced by KEY can be
2147 found in the alist, the value of KEY will be set to VALUE. If the
2148 key-value pair cannot be found in the alist, it will be inserted into
2149 the head of the alist."
2150 (let* ((alist (symbol-value alist-symbol))
2151 (elem (assoc key alist)))
2152 (if elem
2153 (setcdr elem value)
2154 (set alist-symbol (cons (cons key value) alist)))))
2156 (defun vhdl-adelete (alist-symbol key)
2157 "Delete a key-value pair from the alist.
2158 Alist is referenced by ALIST-SYMBOL and the key-value pair to remove
2159 is pair matching KEY."
2160 (let ((alist (symbol-value alist-symbol)) alist-cdr)
2161 (while (equal key (caar alist))
2162 (setq alist (cdr alist))
2163 (set alist-symbol alist))
2164 (while (setq alist-cdr (cdr alist))
2165 (if (equal key (caar alist-cdr))
2166 (setcdr alist (cdr alist-cdr))
2167 (setq alist alist-cdr)))))
2169 (defun vhdl-aget (alist key)
2170 "Return the value in ALIST that is associated with KEY. If KEY is
2171 not found, then nil is returned."
2172 (cdr (assoc key alist)))
2174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2175 ;;; Compatibility
2176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2179 ;; XEmacs compatibility
2181 ;; active regions
2182 (defun vhdl-keep-region-active ()
2183 "Do whatever is necessary to keep the region active in XEmacs.
2184 Ignore byte-compiler warnings you might see."
2185 (and (featurep 'xemacs)
2186 (setq zmacs-region-stays t)))
2188 ;; `wildcard-to-regexp' is included only in XEmacs 21
2189 (unless (fboundp 'wildcard-to-regexp)
2190 (defun wildcard-to-regexp (wildcard)
2191 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2192 (let* ((i (string-match "[*?]" wildcard))
2193 (result (substring wildcard 0 i))
2194 (len (length wildcard)))
2195 (when i
2196 (while (< i len)
2197 (let ((ch (aref wildcard i)))
2198 (setq result (concat result
2199 (cond ((eq ch ?*) "[^\000]*")
2200 ((eq ch ??) "[^\000]")
2201 (t (char-to-string ch)))))
2202 (setq i (1+ i)))))
2203 (concat "\\`" result "\\'"))))
2205 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2206 ;; `regexp-opt' accelerates fontification by 10-20%
2207 (unless (fboundp 'regexp-opt)
2208 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2209 (defun regexp-opt (strings &optional paren)
2210 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2211 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2213 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2214 (unless (fboundp 'match-string-no-properties)
2215 (defalias 'match-string-no-properties 'match-string))
2217 ;; `subst-char-in-string' undefined (XEmacs)
2218 (unless (fboundp 'subst-char-in-string)
2219 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2220 (let ((i (length string))
2221 (newstr (if inplace string (copy-sequence string))))
2222 (while (> i 0)
2223 (setq i (1- i))
2224 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2225 newstr)))
2227 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2228 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2229 (not noninteractive))
2230 (load "itimer")
2231 (when (string< itimer-version "1.09")
2232 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2233 (beep) (sit-for 5)))
2235 ;; `file-expand-wildcards' undefined (XEmacs)
2236 (unless (fboundp 'file-expand-wildcards)
2237 (defun file-expand-wildcards (pattern &optional full)
2238 "Taken from Emacs's `files.el'."
2239 (let* ((nondir (file-name-nondirectory pattern))
2240 (dirpart (file-name-directory pattern))
2241 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2242 (mapcar 'file-name-as-directory
2243 (file-expand-wildcards (directory-file-name dirpart)))
2244 (list dirpart)))
2245 contents)
2246 (while dirs
2247 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2248 (file-directory-p (directory-file-name (car dirs))))
2249 (let ((this-dir-contents
2250 (delq nil
2251 (mapcar #'(lambda (name)
2252 (unless (string-match "\\`\\.\\.?\\'"
2253 (file-name-nondirectory name))
2254 name))
2255 (directory-files (or (car dirs) ".") full
2256 (wildcard-to-regexp nondir))))))
2257 (setq contents
2258 (nconc
2259 (if (and (car dirs) (not full))
2260 (mapcar (function (lambda (name) (concat (car dirs) name)))
2261 this-dir-contents)
2262 this-dir-contents)
2263 contents))))
2264 (setq dirs (cdr dirs)))
2265 contents)))
2267 ;; `member-ignore-case' undefined (XEmacs)
2268 (unless (fboundp 'member-ignore-case)
2269 (defalias 'member-ignore-case 'member))
2271 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2272 ;; behavior in XEmacs
2273 (defvar vhdl-last-input-event)
2274 (if (featurep 'xemacs)
2275 (defvaralias 'vhdl-last-input-event 'last-input-char)
2276 (defvaralias 'vhdl-last-input-event 'last-input-event))
2278 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2279 ;;;(unless (fboundp 'help-print-return-message)
2280 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2283 ;; Compatibility with older VHDL Mode versions
2285 (defvar vhdl-warnings nil
2286 "Warnings to tell the user during start up.")
2288 (defun vhdl-run-when-idle (secs repeat function)
2289 "Wait until idle, then run FUNCTION."
2290 (if (fboundp 'start-itimer)
2291 (start-itimer "vhdl-mode" function secs repeat t)
2292 ;; explicitly activate timer (necessary when Emacs is already idle)
2293 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2295 (defun vhdl-warning-when-idle (&rest args)
2296 "Wait until idle, then print out warning STRING and beep."
2297 (if noninteractive
2298 (vhdl-warning (apply 'format args) t)
2299 (unless vhdl-warnings
2300 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2301 (push (apply 'format args) vhdl-warnings)))
2303 (defun vhdl-warning (string &optional nobeep)
2304 "Print out warning STRING and beep."
2305 (message "WARNING: %s" string)
2306 (unless (or nobeep noninteractive) (beep)))
2308 (defun vhdl-print-warnings ()
2309 "Print out messages in variable `vhdl-warnings'."
2310 (let ((no-warnings (length vhdl-warnings)))
2311 (setq vhdl-warnings (nreverse vhdl-warnings))
2312 (while vhdl-warnings
2313 (message "WARNING: %s" (car vhdl-warnings))
2314 (setq vhdl-warnings (cdr vhdl-warnings)))
2315 (beep)
2316 (when (> no-warnings 1)
2317 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2319 ;; Backward compatibility checks and fixes
2320 ;; option `vhdl-compiler' changed format
2321 (unless (stringp vhdl-compiler)
2322 (setq vhdl-compiler "ModelSim")
2323 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2325 ;; option `vhdl-standard' changed format
2326 (unless (listp vhdl-standard)
2327 (setq vhdl-standard '(87 nil))
2328 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2330 ;; option `vhdl-model-alist' changed format
2331 (when (= (length (car vhdl-model-alist)) 3)
2332 (let ((old-alist vhdl-model-alist)
2333 new-alist)
2334 (while old-alist
2335 (push (append (car old-alist) '("")) new-alist)
2336 (setq old-alist (cdr old-alist)))
2337 (setq vhdl-model-alist (nreverse new-alist)))
2338 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2340 ;; option `vhdl-project-alist' changed format
2341 (when (= (length (car vhdl-project-alist)) 3)
2342 (let ((old-alist vhdl-project-alist)
2343 new-alist)
2344 (while old-alist
2345 (push (append (car old-alist) '("")) new-alist)
2346 (setq old-alist (cdr old-alist)))
2347 (setq vhdl-project-alist (nreverse new-alist)))
2348 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2350 ;; option `vhdl-project-alist' changed format (3.31.1)
2351 (when (= (length (car vhdl-project-alist)) 4)
2352 (let ((old-alist vhdl-project-alist)
2353 new-alist elem)
2354 (while old-alist
2355 (setq elem (car old-alist))
2356 (setq new-alist
2357 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2358 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2359 new-alist))
2360 (setq old-alist (cdr old-alist)))
2361 (setq vhdl-project-alist (nreverse new-alist)))
2362 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2364 ;; option `vhdl-project-alist' changed format (3.31.12)
2365 (when (= (length (car vhdl-project-alist)) 10)
2366 (let ((tmp-alist vhdl-project-alist))
2367 (while tmp-alist
2368 (setcdr (nthcdr 3 (car tmp-alist))
2369 (cons "" (nthcdr 4 (car tmp-alist))))
2370 (setq tmp-alist (cdr tmp-alist))))
2371 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2373 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2374 (when (= (length (car vhdl-compiler-alist)) 7)
2375 (let ((old-alist vhdl-compiler-alist)
2376 new-alist elem)
2377 (while old-alist
2378 (setq elem (car old-alist))
2379 (setq new-alist
2380 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2381 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2382 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2383 (nth 5 elem) (nth 6 elem) nil)
2384 new-alist))
2385 (setq old-alist (cdr old-alist)))
2386 (setq vhdl-compiler-alist (nreverse new-alist)))
2387 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2389 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2390 (when (= (length (car vhdl-compiler-alist)) 12)
2391 (let ((tmp-alist vhdl-compiler-alist))
2392 (while tmp-alist
2393 (setcdr (nthcdr 4 (car tmp-alist))
2394 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2395 (setq tmp-alist (cdr tmp-alist))))
2396 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2398 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2399 (when (= (length (car vhdl-compiler-alist)) 13)
2400 (let ((tmp-alist vhdl-compiler-alist))
2401 (while tmp-alist
2402 (setcdr (nthcdr 3 (car tmp-alist))
2403 (cons "" (nthcdr 4 (car tmp-alist))))
2404 (setq tmp-alist (cdr tmp-alist))))
2405 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2407 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2408 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2409 (let ((tmp-alist vhdl-compiler-alist))
2410 (while tmp-alist
2411 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2412 '(0 . nil))
2413 (setq tmp-alist (cdr tmp-alist))))
2414 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2416 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2417 (when (equal vhdl-project "")
2418 (setq vhdl-project nil)
2419 (customize-save-variable 'vhdl-project vhdl-project))
2421 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2422 (when (stringp vhdl-project-file-name)
2423 (setq vhdl-project-file-name (list vhdl-project-file-name))
2424 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2426 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2427 (if (not (boundp 'speedbar-indentation-width))
2428 (defvar speedbar-indentation-width 2)
2429 ;; set default to 2 if not already customized
2430 (unless (get 'speedbar-indentation-width 'saved-value)
2431 (setq speedbar-indentation-width 2)))
2433 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2434 ;;; Help functions / inline substitutions / macros
2435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2437 (defun vhdl-standard-p (standard)
2438 "Check if STANDARD is specified as used standard."
2439 (or (eq standard (car vhdl-standard))
2440 (memq standard (cadr vhdl-standard))))
2442 (defun vhdl-project-p (&optional warning)
2443 "Return non-nil if a project is displayed, i.e. directories or files are
2444 specified."
2445 (if (assoc vhdl-project vhdl-project-alist)
2446 vhdl-project
2447 (when (and vhdl-project warning)
2448 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2449 nil))
2451 (defun vhdl-resolve-env-variable (string)
2452 "Resolve environment variables in STRING."
2453 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2454 (setq string (concat (match-string 1 string)
2455 (getenv (match-string 2 string))
2456 (match-string 4 string))))
2457 string)
2459 (defun vhdl-default-directory ()
2460 "Return the default directory of the current project or the directory of the
2461 current buffer if no project is defined."
2462 (if (vhdl-project-p)
2463 (expand-file-name (vhdl-resolve-env-variable
2464 (nth 1 (vhdl-aget vhdl-project-alist vhdl-project))))
2465 default-directory))
2467 (defmacro vhdl-prepare-search-1 (&rest body)
2468 "Enable case insensitive search and switch to syntax table that includes '_',
2469 then execute BODY, and finally restore the old environment. Used for
2470 consistent searching."
2471 `(let ((case-fold-search t)) ; case insensitive search
2472 ;; use extended syntax table
2473 (with-syntax-table vhdl-mode-ext-syntax-table
2474 ,@body)))
2476 (defmacro vhdl-prepare-search-2 (&rest body)
2477 "Enable case insensitive search, switch to syntax table that includes '_',
2478 and remove `intangible' overlays, then execute BODY, and finally restore the
2479 old environment. Used for consistent searching."
2480 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2481 `(let ((case-fold-search t) ; case insensitive search
2482 (current-syntax-table (syntax-table))
2483 overlay-all-list overlay-intangible-list overlay)
2484 ;; use extended syntax table
2485 (set-syntax-table vhdl-mode-ext-syntax-table)
2486 ;; remove `intangible' overlays
2487 (when (fboundp 'overlay-lists)
2488 (setq overlay-all-list (overlay-lists))
2489 (setq overlay-all-list
2490 (append (car overlay-all-list) (cdr overlay-all-list)))
2491 (while overlay-all-list
2492 (setq overlay (car overlay-all-list))
2493 (when (memq 'intangible (overlay-properties overlay))
2494 (setq overlay-intangible-list
2495 (cons overlay overlay-intangible-list))
2496 (overlay-put overlay 'intangible nil))
2497 (setq overlay-all-list (cdr overlay-all-list))))
2498 ;; execute BODY safely
2499 (unwind-protect
2500 (progn ,@body)
2501 ;; restore syntax table
2502 (set-syntax-table current-syntax-table)
2503 ;; restore `intangible' overlays
2504 (when (fboundp 'overlay-lists)
2505 (while overlay-intangible-list
2506 (overlay-put (car overlay-intangible-list) 'intangible t)
2507 (setq overlay-intangible-list
2508 (cdr overlay-intangible-list)))))))
2510 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2511 "Visit file FILE-NAME and execute BODY."
2512 `(if (null ,file-name)
2513 (progn ,@body)
2514 (unless (file-directory-p ,file-name)
2515 (let ((source-buffer (current-buffer))
2516 (visiting-buffer (find-buffer-visiting ,file-name))
2517 file-opened)
2518 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2519 (condition-case ()
2520 (progn (set-buffer (create-file-buffer ,file-name))
2521 (setq file-opened t)
2522 (vhdl-insert-file-contents ,file-name)
2523 ;; FIXME: This modifies a global syntax-table!
2524 (modify-syntax-entry ?\- ". 12" (syntax-table))
2525 (modify-syntax-entry ?\n ">" (syntax-table))
2526 (modify-syntax-entry ?\^M ">" (syntax-table))
2527 (modify-syntax-entry ?_ "w" (syntax-table))
2529 (error
2530 (if ,issue-error
2531 (progn
2532 (when file-opened (kill-buffer (current-buffer)))
2533 (set-buffer source-buffer)
2534 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2535 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2536 nil))))
2537 (condition-case info
2538 (progn ,@body)
2539 (error
2540 (if ,issue-error
2541 (progn
2542 (when file-opened (kill-buffer (current-buffer)))
2543 (set-buffer source-buffer)
2544 (error (cadr info)))
2545 (vhdl-warning (cadr info))))))
2546 (when file-opened (kill-buffer (current-buffer)))
2547 (set-buffer source-buffer)))))
2549 (defun vhdl-insert-file-contents (filename)
2550 "Nicked from `insert-file-contents-literally', but allow coding system
2551 conversion."
2552 (let ((format-alist nil)
2553 (after-insert-file-functions nil)
2554 (jka-compr-compression-info-list nil))
2555 (insert-file-contents filename t)))
2557 (defun vhdl-sort-alist (alist)
2558 "Sort ALIST."
2559 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2561 (defun vhdl-get-subdirs (directory)
2562 "Recursively get subdirectories of DIRECTORY."
2563 (let ((dir-list (list (file-name-as-directory directory)))
2564 file-list)
2565 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2566 (while file-list
2567 (when (file-directory-p (car file-list))
2568 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2569 (setq file-list (cdr file-list)))
2570 dir-list))
2572 (defun vhdl-aput-delete-if-nil (alist-symbol key &optional value)
2573 "As `aput', but delete key-value pair if VALUE is nil."
2574 (if value
2575 (vhdl-aput alist-symbol key value)
2576 (vhdl-adelete alist-symbol key)))
2578 (defun vhdl-delete (elt list)
2579 "Delete by side effect the first occurrence of ELT as a member of LIST."
2580 (push nil list)
2581 (let ((list1 list))
2582 (while (and (cdr list1) (not (equal elt (cadr list1))))
2583 (setq list1 (cdr list1)))
2584 (when list
2585 (setcdr list1 (cddr list1))))
2586 (cdr list))
2588 (declare-function speedbar-refresh "speedbar" (&optional arg))
2589 (declare-function speedbar-do-function-pointer "speedbar" ())
2591 (defun vhdl-speedbar-refresh (&optional key)
2592 "Refresh directory or project with name KEY."
2593 (when (and (boundp 'speedbar-frame)
2594 (frame-live-p speedbar-frame))
2595 (let ((pos (point))
2596 (last-frame (selected-frame)))
2597 (if (null key)
2598 (speedbar-refresh)
2599 (select-frame speedbar-frame)
2600 (when (save-excursion
2601 (goto-char (point-min))
2602 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2603 (goto-char (match-end 1))
2604 (speedbar-do-function-pointer)
2605 (backward-char 2)
2606 (speedbar-do-function-pointer)
2607 (message "Refreshing speedbar...done"))
2608 (select-frame last-frame)))))
2610 (defun vhdl-show-messages ()
2611 "Get *Messages* buffer to show recent messages."
2612 (interactive)
2613 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2615 (defun vhdl-use-direct-instantiation ()
2616 "Return whether direct instantiation is used."
2617 (or (eq vhdl-use-direct-instantiation 'always)
2618 (and (eq vhdl-use-direct-instantiation 'standard)
2619 (not (vhdl-standard-p '87)))))
2621 (defun vhdl-max-marker (marker1 marker2)
2622 "Return larger marker."
2623 (if (> marker1 marker2) marker1 marker2))
2625 (defun vhdl-goto-marker (marker)
2626 "Goto marker in appropriate buffer."
2627 (when (markerp marker)
2628 (set-buffer (marker-buffer marker)))
2629 (goto-char marker))
2631 (defun vhdl-menu-split (list title)
2632 "Split menu LIST into several submenus, if number of
2633 elements > `vhdl-menu-max-size'."
2634 (if (> (length list) vhdl-menu-max-size)
2635 (let ((remain list)
2636 (result '())
2637 (sublist '())
2638 (menuno 1)
2639 (i 0))
2640 (while remain
2641 (push (car remain) sublist)
2642 (setq remain (cdr remain))
2643 (setq i (+ i 1))
2644 (if (= i vhdl-menu-max-size)
2645 (progn
2646 (push (cons (format "%s %s" title menuno)
2647 (nreverse sublist)) result)
2648 (setq i 0)
2649 (setq menuno (+ menuno 1))
2650 (setq sublist '()))))
2651 (and sublist
2652 (push (cons (format "%s %s" title menuno)
2653 (nreverse sublist)) result))
2654 (nreverse result))
2655 list))
2658 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2659 ;;; Bindings
2660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2662 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2663 ;; Key bindings
2665 (defvar vhdl-template-map nil
2666 "Keymap for VHDL templates.")
2668 (defun vhdl-template-map-init ()
2669 "Initialize `vhdl-template-map'."
2670 (setq vhdl-template-map (make-sparse-keymap))
2671 ;; key bindings for VHDL templates
2672 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2673 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2674 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2675 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2676 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2677 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2678 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2679 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2680 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2681 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2682 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2683 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2684 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2685 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2686 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2687 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2688 (define-key vhdl-template-map "el" 'vhdl-template-else)
2689 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2690 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2691 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2692 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2693 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2694 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2695 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2696 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2697 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2698 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2699 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2700 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2701 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2702 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2703 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2704 (define-key vhdl-template-map "li" 'vhdl-template-library)
2705 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2706 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2707 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2708 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2709 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2710 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2711 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2712 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2713 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2714 (define-key vhdl-template-map "po" 'vhdl-template-port)
2715 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2716 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2717 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2718 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2719 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2720 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2721 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2722 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2723 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2724 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2725 (define-key vhdl-template-map "us" 'vhdl-template-use)
2726 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2727 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2728 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2729 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2730 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2731 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2732 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2733 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2734 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2735 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2736 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2737 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2738 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2739 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2740 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2741 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2742 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2743 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2744 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2745 (when (vhdl-standard-p 'ams)
2746 (define-key vhdl-template-map "br" 'vhdl-template-break)
2747 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2748 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2749 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2750 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2751 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2752 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2753 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2754 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2755 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2756 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2758 (when (vhdl-standard-p 'math)
2759 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2760 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2763 ;; initialize template map for VHDL Mode
2764 (vhdl-template-map-init)
2766 (defun vhdl-function-name (prefix string &optional postfix)
2767 "Generate a Lisp function name.
2768 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2769 STRING are replaced by `-' and substrings are converted to lower case."
2770 (let ((name prefix))
2771 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2772 (setq name
2773 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2774 (setq string (substring string (match-beginning 2))))
2775 (when postfix (setq name (concat name "-" postfix)))
2776 (intern name)))
2778 (defvar vhdl-model-map nil
2779 "Keymap for VHDL models.")
2781 (defun vhdl-model-map-init ()
2782 "Initialize `vhdl-model-map'."
2783 (setq vhdl-model-map (make-sparse-keymap))
2784 ;; key bindings for VHDL models
2785 (let ((model-alist vhdl-model-alist) model)
2786 (while model-alist
2787 (setq model (car model-alist))
2788 (define-key vhdl-model-map (nth 2 model)
2789 (vhdl-function-name "vhdl-model" (nth 0 model)))
2790 (setq model-alist (cdr model-alist)))))
2792 ;; initialize user model map for VHDL Mode
2793 (vhdl-model-map-init)
2795 (defvar vhdl-mode-map nil
2796 "Keymap for VHDL Mode.")
2798 (defun vhdl-mode-map-init ()
2799 "Initialize `vhdl-mode-map'."
2800 (setq vhdl-mode-map (make-sparse-keymap))
2801 ;; template key bindings
2802 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2803 ;; model key bindings
2804 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2805 ;; standard key bindings
2806 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2807 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2808 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2809 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2810 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2811 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2812 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2813 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2814 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2815 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2816 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2817 ;; mode specific key bindings
2818 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2819 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2820 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2821 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2822 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2823 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2824 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2825 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2826 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2827 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2828 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2829 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2830 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2831 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2832 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2833 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2834 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2835 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2836 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2837 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2838 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2839 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2840 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2841 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2842 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2843 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2844 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2845 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2846 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2847 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2848 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2849 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2850 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2851 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2852 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2853 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2854 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2855 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2856 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2857 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2858 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2859 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2860 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2861 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2862 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2863 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2864 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2865 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2866 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2867 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2868 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2869 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2870 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2871 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2872 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2873 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2874 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2875 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2876 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2877 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2878 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2879 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2880 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2881 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2882 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2883 (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
2884 (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
2885 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2886 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2887 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2888 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2889 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2890 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2891 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2892 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2893 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2894 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2895 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2896 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2897 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2898 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2899 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2900 ;; insert commands bindings
2901 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2902 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2903 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2904 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2905 ;; electric key bindings
2906 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2907 (when vhdl-intelligent-tab
2908 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2909 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2910 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2911 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2912 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2913 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2914 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2915 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2916 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2917 (when (vhdl-standard-p 'ams)
2918 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2920 ;; initialize mode map for VHDL Mode
2921 (vhdl-mode-map-init)
2923 ;; define special minibuffer keymap for enabling word completion in minibuffer
2924 ;; (useful in template generator prompts)
2925 (defvar vhdl-minibuffer-local-map
2926 (let ((map (make-sparse-keymap)))
2927 (set-keymap-parent map minibuffer-local-map)
2928 (when vhdl-word-completion-in-minibuffer
2929 (define-key map "\t" 'vhdl-minibuffer-tab))
2930 map)
2931 "Keymap for minibuffer used in VHDL Mode.")
2933 ;; set up electric character functions to work with
2934 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2935 (mapc
2936 (function
2937 (lambda (sym)
2938 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2939 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2940 '(vhdl-electric-space
2941 vhdl-electric-tab
2942 vhdl-electric-return
2943 vhdl-electric-dash
2944 vhdl-electric-open-bracket
2945 vhdl-electric-close-bracket
2946 vhdl-electric-quote
2947 vhdl-electric-semicolon
2948 vhdl-electric-comma
2949 vhdl-electric-period
2950 vhdl-electric-equal))
2952 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2953 ;; Syntax table
2955 (defvar vhdl-mode-syntax-table
2956 (let ((st (make-syntax-table)))
2957 ;; define punctuation
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 (modify-syntax-entry ?\| "." st)
2974 ;; define string
2975 (modify-syntax-entry ?\" "\"" st)
2976 ;; define underscore
2977 (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
2978 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2979 (modify-syntax-entry ?\- ". 12" st)
2980 ;; and \n and \^M end a comment
2981 (modify-syntax-entry ?\n ">" st)
2982 (modify-syntax-entry ?\^M ">" st)
2983 ;; define parentheses to match
2984 (modify-syntax-entry ?\( "()" st)
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)
2991 "Syntax table used in `vhdl-mode' buffers.")
2993 (defvar vhdl-mode-ext-syntax-table
2994 ;; Extended syntax table including '_' (for simpler search regexps).
2995 (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
2996 (modify-syntax-entry ?_ "w" st)
2998 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
3000 (defvar vhdl-syntactic-context nil
3001 "Buffer local variable containing syntactic analysis list.")
3002 (make-variable-buffer-local 'vhdl-syntactic-context)
3004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3005 ;; Abbrev hook bindings
3007 (defvar vhdl-mode-abbrev-table nil
3008 "Abbrev table to use in `vhdl-mode' buffers.")
3010 (defun vhdl-mode-abbrev-table-init ()
3011 "Initialize `vhdl-mode-abbrev-table'."
3012 (define-abbrev-table 'vhdl-mode-abbrev-table
3013 (append
3014 (when (memq 'vhdl vhdl-electric-keywords)
3015 ;; VHDL'02 keywords
3016 (mapcar (if (featurep 'xemacs)
3017 (lambda (x) (list (car x) "" (cdr x) 0))
3018 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3020 ("--" . vhdl-template-display-comment-hook)
3021 ("abs" . vhdl-template-default-hook)
3022 ("access" . vhdl-template-default-hook)
3023 ("after" . vhdl-template-default-hook)
3024 ("alias" . vhdl-template-alias-hook)
3025 ("all" . vhdl-template-default-hook)
3026 ("and" . vhdl-template-default-hook)
3027 ("arch" . vhdl-template-architecture-hook)
3028 ("architecture" . vhdl-template-architecture-hook)
3029 ("array" . vhdl-template-default-hook)
3030 ("assert" . vhdl-template-assert-hook)
3031 ("attr" . vhdl-template-attribute-hook)
3032 ("attribute" . vhdl-template-attribute-hook)
3033 ("begin" . vhdl-template-default-indent-hook)
3034 ("block" . vhdl-template-block-hook)
3035 ("body" . vhdl-template-default-hook)
3036 ("buffer" . vhdl-template-default-hook)
3037 ("bus" . vhdl-template-default-hook)
3038 ("case" . vhdl-template-case-hook)
3039 ("comp" . vhdl-template-component-hook)
3040 ("component" . vhdl-template-component-hook)
3041 ("cond" . vhdl-template-conditional-signal-asst-hook)
3042 ("conditional" . vhdl-template-conditional-signal-asst-hook)
3043 ("conf" . vhdl-template-configuration-hook)
3044 ("configuration" . vhdl-template-configuration-hook)
3045 ("cons" . vhdl-template-constant-hook)
3046 ("constant" . vhdl-template-constant-hook)
3047 ("disconnect" . vhdl-template-disconnect-hook)
3048 ("downto" . vhdl-template-default-hook)
3049 ("else" . vhdl-template-else-hook)
3050 ("elseif" . vhdl-template-elsif-hook)
3051 ("elsif" . vhdl-template-elsif-hook)
3052 ("end" . vhdl-template-default-indent-hook)
3053 ("entity" . vhdl-template-entity-hook)
3054 ("exit" . vhdl-template-exit-hook)
3055 ("file" . vhdl-template-file-hook)
3056 ("for" . vhdl-template-for-hook)
3057 ("func" . vhdl-template-function-hook)
3058 ("function" . vhdl-template-function-hook)
3059 ("generic" . vhdl-template-generic-hook)
3060 ("group" . vhdl-template-group-hook)
3061 ("guarded" . vhdl-template-default-hook)
3062 ("if" . vhdl-template-if-hook)
3063 ("impure" . vhdl-template-default-hook)
3064 ("in" . vhdl-template-default-hook)
3065 ("inertial" . vhdl-template-default-hook)
3066 ("inout" . vhdl-template-default-hook)
3067 ("inst" . vhdl-template-instance-hook)
3068 ("instance" . vhdl-template-instance-hook)
3069 ("is" . vhdl-template-default-hook)
3070 ("label" . vhdl-template-default-hook)
3071 ("library" . vhdl-template-library-hook)
3072 ("linkage" . vhdl-template-default-hook)
3073 ("literal" . vhdl-template-default-hook)
3074 ("loop" . vhdl-template-bare-loop-hook)
3075 ("map" . vhdl-template-map-hook)
3076 ("mod" . vhdl-template-default-hook)
3077 ("nand" . vhdl-template-default-hook)
3078 ("new" . vhdl-template-default-hook)
3079 ("next" . vhdl-template-next-hook)
3080 ("nor" . vhdl-template-default-hook)
3081 ("not" . vhdl-template-default-hook)
3082 ("null" . vhdl-template-default-hook)
3083 ("of" . vhdl-template-default-hook)
3084 ("on" . vhdl-template-default-hook)
3085 ("open" . vhdl-template-default-hook)
3086 ("or" . vhdl-template-default-hook)
3087 ("others" . vhdl-template-others-hook)
3088 ("out" . vhdl-template-default-hook)
3089 ("pack" . vhdl-template-package-hook)
3090 ("package" . vhdl-template-package-hook)
3091 ("port" . vhdl-template-port-hook)
3092 ("postponed" . vhdl-template-default-hook)
3093 ("procedure" . vhdl-template-procedure-hook)
3094 ("process" . vhdl-template-process-hook)
3095 ("pure" . vhdl-template-default-hook)
3096 ("range" . vhdl-template-default-hook)
3097 ("record" . vhdl-template-default-hook)
3098 ("register" . vhdl-template-default-hook)
3099 ("reject" . vhdl-template-default-hook)
3100 ("rem" . vhdl-template-default-hook)
3101 ("report" . vhdl-template-report-hook)
3102 ("return" . vhdl-template-return-hook)
3103 ("rol" . vhdl-template-default-hook)
3104 ("ror" . vhdl-template-default-hook)
3105 ("select" . vhdl-template-selected-signal-asst-hook)
3106 ("severity" . vhdl-template-default-hook)
3107 ("shared" . vhdl-template-default-hook)
3108 ("sig" . vhdl-template-signal-hook)
3109 ("signal" . vhdl-template-signal-hook)
3110 ("sla" . vhdl-template-default-hook)
3111 ("sll" . vhdl-template-default-hook)
3112 ("sra" . vhdl-template-default-hook)
3113 ("srl" . vhdl-template-default-hook)
3114 ("subtype" . vhdl-template-subtype-hook)
3115 ("then" . vhdl-template-default-hook)
3116 ("to" . vhdl-template-default-hook)
3117 ("transport" . vhdl-template-default-hook)
3118 ("type" . vhdl-template-type-hook)
3119 ("unaffected" . vhdl-template-default-hook)
3120 ("units" . vhdl-template-default-hook)
3121 ("until" . vhdl-template-default-hook)
3122 ("use" . vhdl-template-use-hook)
3123 ("var" . vhdl-template-variable-hook)
3124 ("variable" . vhdl-template-variable-hook)
3125 ("wait" . vhdl-template-wait-hook)
3126 ("when" . vhdl-template-when-hook)
3127 ("while" . vhdl-template-while-loop-hook)
3128 ("with" . vhdl-template-with-hook)
3129 ("xnor" . vhdl-template-default-hook)
3130 ("xor" . vhdl-template-default-hook)
3132 ;; VHDL-AMS keywords
3133 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3134 (mapcar (if (featurep 'xemacs)
3135 (lambda (x) (list (car x) "" (cdr x) 0))
3136 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3138 ("across" . vhdl-template-default-hook)
3139 ("break" . vhdl-template-break-hook)
3140 ("limit" . vhdl-template-limit-hook)
3141 ("nature" . vhdl-template-nature-hook)
3142 ("noise" . vhdl-template-default-hook)
3143 ("procedural" . vhdl-template-procedural-hook)
3144 ("quantity" . vhdl-template-quantity-hook)
3145 ("reference" . vhdl-template-default-hook)
3146 ("spectrum" . vhdl-template-default-hook)
3147 ("subnature" . vhdl-template-subnature-hook)
3148 ("terminal" . vhdl-template-terminal-hook)
3149 ("through" . vhdl-template-default-hook)
3150 ("tolerance" . vhdl-template-default-hook)
3152 ;; user model keywords
3153 (when (memq 'user vhdl-electric-keywords)
3154 (let (abbrev-list keyword)
3155 (dolist (elem vhdl-model-alist)
3156 (setq keyword (nth 3 elem))
3157 (unless (equal keyword "")
3158 (push (list keyword ""
3159 (vhdl-function-name
3160 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3161 abbrev-list)))
3162 abbrev-list)))))
3164 ;; initialize abbrev table for VHDL Mode
3165 (vhdl-mode-abbrev-table-init)
3167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3168 ;; Template completion lists
3170 (defvar vhdl-template-construct-alist nil
3171 "List of built-in construct templates.")
3173 (defun vhdl-template-construct-alist-init ()
3174 "Initialize `vhdl-template-construct-alist'."
3175 (setq
3176 vhdl-template-construct-alist
3177 (append
3179 ("alias declaration" vhdl-template-alias)
3180 ("architecture body" vhdl-template-architecture)
3181 ("assertion" vhdl-template-assert)
3182 ("attribute declaration" vhdl-template-attribute-decl)
3183 ("attribute specification" vhdl-template-attribute-spec)
3184 ("block configuration" vhdl-template-block-configuration)
3185 ("block statement" vhdl-template-block)
3186 ("case statement" vhdl-template-case-is)
3187 ("component configuration" vhdl-template-component-conf)
3188 ("component declaration" vhdl-template-component-decl)
3189 ("component instantiation statement" vhdl-template-component-inst)
3190 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3191 ("configuration declaration" vhdl-template-configuration-decl)
3192 ("configuration specification" vhdl-template-configuration-spec)
3193 ("constant declaration" vhdl-template-constant)
3194 ("disconnection specification" vhdl-template-disconnect)
3195 ("entity declaration" vhdl-template-entity)
3196 ("exit statement" vhdl-template-exit)
3197 ("file declaration" vhdl-template-file)
3198 ("generate statement" vhdl-template-generate)
3199 ("generic clause" vhdl-template-generic)
3200 ("group declaration" vhdl-template-group-decl)
3201 ("group template declaration" vhdl-template-group-template)
3202 ("if statement" vhdl-template-if-then)
3203 ("library clause" vhdl-template-library)
3204 ("loop statement" vhdl-template-loop)
3205 ("next statement" vhdl-template-next)
3206 ("package declaration" vhdl-template-package-decl)
3207 ("package body" vhdl-template-package-body)
3208 ("port clause" vhdl-template-port)
3209 ("process statement" vhdl-template-process)
3210 ("report statement" vhdl-template-report)
3211 ("return statement" vhdl-template-return)
3212 ("selected signal assignment" vhdl-template-selected-signal-asst)
3213 ("signal declaration" vhdl-template-signal)
3214 ("subprogram declaration" vhdl-template-subprogram-decl)
3215 ("subprogram body" vhdl-template-subprogram-body)
3216 ("subtype declaration" vhdl-template-subtype)
3217 ("type declaration" vhdl-template-type)
3218 ("use clause" vhdl-template-use)
3219 ("variable declaration" vhdl-template-variable)
3220 ("wait statement" vhdl-template-wait)
3222 (when (vhdl-standard-p 'ams)
3224 ("break statement" vhdl-template-break)
3225 ("nature declaration" vhdl-template-nature)
3226 ("quantity declaration" vhdl-template-quantity)
3227 ("simultaneous case statement" vhdl-template-case-use)
3228 ("simultaneous if statement" vhdl-template-if-use)
3229 ("simultaneous procedural statement" vhdl-template-procedural)
3230 ("step limit specification" vhdl-template-limit)
3231 ("subnature declaration" vhdl-template-subnature)
3232 ("terminal declaration" vhdl-template-terminal)
3233 )))))
3235 ;; initialize for VHDL Mode
3236 (vhdl-template-construct-alist-init)
3238 (defvar vhdl-template-package-alist nil
3239 "List of built-in package templates.")
3241 (defun vhdl-template-package-alist-init ()
3242 "Initialize `vhdl-template-package-alist'."
3243 (setq
3244 vhdl-template-package-alist
3245 (append
3247 ("numeric_bit" vhdl-template-package-numeric-bit)
3248 ("numeric_std" vhdl-template-package-numeric-std)
3249 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3250 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3251 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3252 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3253 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3254 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3255 ("textio" vhdl-template-package-textio)
3257 (when (vhdl-standard-p 'math)
3259 ("math_complex" vhdl-template-package-math-complex)
3260 ("math_real" vhdl-template-package-math-real)
3261 )))))
3263 ;; initialize for VHDL Mode
3264 (vhdl-template-package-alist-init)
3266 (defvar vhdl-template-directive-alist
3268 ("translate_on" vhdl-template-directive-translate-on)
3269 ("translate_off" vhdl-template-directive-translate-off)
3270 ("synthesis_on" vhdl-template-directive-synthesis-on)
3271 ("synthesis_off" vhdl-template-directive-synthesis-off)
3273 "List of built-in directive templates.")
3276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3277 ;;; Menus
3278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3281 ;; VHDL menu (using `easy-menu.el')
3283 (defun vhdl-customize ()
3284 "Call the customize function with `vhdl' as argument."
3285 (interactive)
3286 (customize-browse 'vhdl))
3288 (defun vhdl-create-mode-menu ()
3289 "Create VHDL Mode menu."
3290 `("VHDL"
3291 ,(append
3292 '("Project"
3293 ["None" (vhdl-set-project "")
3294 :style radio :selected (null vhdl-project)]
3295 "--")
3296 ;; add menu entries for defined projects
3297 (let ((project-alist vhdl-project-alist) menu-list name)
3298 (while project-alist
3299 (setq name (caar project-alist))
3300 (setq menu-list
3301 (cons `[,name (vhdl-set-project ,name)
3302 :style radio :selected (equal ,name vhdl-project)]
3303 menu-list))
3304 (setq project-alist (cdr project-alist)))
3305 (setq menu-list
3306 (if vhdl-project-sort
3307 (sort menu-list
3308 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3309 (nreverse menu-list)))
3310 (vhdl-menu-split menu-list "Project"))
3311 '("--" "--"
3312 ["Select Project..." vhdl-set-project t]
3313 ["Set As Default Project" vhdl-set-default-project t]
3314 "--"
3315 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3316 ["Import Project..." vhdl-import-project
3317 :keys "C-c C-p C-m" :active t]
3318 ["Export Project" vhdl-export-project vhdl-project]
3319 "--"
3320 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3321 "--"
3322 ("Compile"
3323 ["Compile Buffer" vhdl-compile t]
3324 ["Stop Compilation" kill-compilation t]
3325 "--"
3326 ["Make" vhdl-make t]
3327 ["Generate Makefile" vhdl-generate-makefile t]
3328 "--"
3329 ["Next Error" next-error t]
3330 ["Previous Error" previous-error t]
3331 ["First Error" first-error t]
3332 "--"
3333 ,(append
3334 '("Compiler")
3335 ;; add menu entries for defined compilers
3336 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3337 (while comp-alist
3338 (setq name (caar comp-alist))
3339 (setq menu-list
3340 (cons `[,name (setq vhdl-compiler ,name)
3341 :style radio :selected (equal ,name vhdl-compiler)]
3342 menu-list))
3343 (setq comp-alist (cdr comp-alist)))
3344 (setq menu-list (nreverse menu-list))
3345 (vhdl-menu-split menu-list "Compiler"))
3346 '("--" "--"
3347 ["Select Compiler..." vhdl-set-compiler t]
3348 "--"
3349 ["Customize Compiler..."
3350 (customize-option 'vhdl-compiler-alist) t])))
3351 "--"
3352 ,(append
3353 '("Template"
3354 ("VHDL Construct 1"
3355 ["Alias" vhdl-template-alias t]
3356 ["Architecture" vhdl-template-architecture t]
3357 ["Assert" vhdl-template-assert t]
3358 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3359 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3360 ["Block" vhdl-template-block t]
3361 ["Case" vhdl-template-case-is t]
3362 ["Component (Decl)" vhdl-template-component-decl t]
3363 ["(Component) Instance" vhdl-template-component-inst t]
3364 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3365 ["Configuration (Block)" vhdl-template-block-configuration t]
3366 ["Configuration (Comp)" vhdl-template-component-conf t]
3367 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3368 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3369 ["Constant" vhdl-template-constant t]
3370 ["Disconnect" vhdl-template-disconnect t]
3371 ["Else" vhdl-template-else t]
3372 ["Elsif" vhdl-template-elsif t]
3373 ["Entity" vhdl-template-entity t]
3374 ["Exit" vhdl-template-exit t]
3375 ["File" vhdl-template-file t]
3376 ["For (Generate)" vhdl-template-for-generate t]
3377 ["For (Loop)" vhdl-template-for-loop t]
3378 ["Function (Body)" vhdl-template-function-body t]
3379 ["Function (Decl)" vhdl-template-function-decl t]
3380 ["Generic" vhdl-template-generic t]
3381 ["Group (Decl)" vhdl-template-group-decl t]
3382 ["Group (Template)" vhdl-template-group-template t])
3383 ("VHDL Construct 2"
3384 ["If (Generate)" vhdl-template-if-generate t]
3385 ["If (Then)" vhdl-template-if-then t]
3386 ["Library" vhdl-template-library t]
3387 ["Loop" vhdl-template-bare-loop t]
3388 ["Map" vhdl-template-map t]
3389 ["Next" vhdl-template-next t]
3390 ["Others (Aggregate)" vhdl-template-others t]
3391 ["Package (Decl)" vhdl-template-package-decl t]
3392 ["Package (Body)" vhdl-template-package-body t]
3393 ["Port" vhdl-template-port t]
3394 ["Procedure (Body)" vhdl-template-procedure-body t]
3395 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3396 ["Process (Comb)" vhdl-template-process-comb t]
3397 ["Process (Seq)" vhdl-template-process-seq t]
3398 ["Report" vhdl-template-report t]
3399 ["Return" vhdl-template-return t]
3400 ["Select" vhdl-template-selected-signal-asst t]
3401 ["Signal" vhdl-template-signal t]
3402 ["Subtype" vhdl-template-subtype t]
3403 ["Type" vhdl-template-type t]
3404 ["Use" vhdl-template-use t]
3405 ["Variable" vhdl-template-variable t]
3406 ["Wait" vhdl-template-wait t]
3407 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3408 ["When" vhdl-template-when t]
3409 ["While (Loop)" vhdl-template-while-loop t]
3410 ["With" vhdl-template-with t]))
3411 (when (vhdl-standard-p 'ams)
3412 '(("VHDL-AMS Construct"
3413 ["Break" vhdl-template-break t]
3414 ["Case (Use)" vhdl-template-case-use t]
3415 ["If (Use)" vhdl-template-if-use t]
3416 ["Limit" vhdl-template-limit t]
3417 ["Nature" vhdl-template-nature t]
3418 ["Procedural" vhdl-template-procedural t]
3419 ["Quantity (Free)" vhdl-template-quantity-free t]
3420 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3421 ["Quantity (Source)" vhdl-template-quantity-source t]
3422 ["Subnature" vhdl-template-subnature t]
3423 ["Terminal" vhdl-template-terminal t])))
3424 '(["Insert Construct..." vhdl-template-insert-construct
3425 :keys "C-c C-i C-t"]
3426 "--")
3427 (list
3428 (append
3429 '("Package")
3430 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3431 ["numeric_std" vhdl-template-package-numeric-std t]
3432 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3433 ["textio" vhdl-template-package-textio t]
3434 "--"
3435 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3436 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3437 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3438 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3439 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3440 "--")
3441 (when (vhdl-standard-p 'ams)
3442 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3443 ["material_constants" vhdl-template-package-material-constants t]
3444 ["energy_systems" vhdl-template-package-energy-systems t]
3445 ["electrical_systems" vhdl-template-package-electrical-systems t]
3446 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3447 ["radiant_systems" vhdl-template-package-radiant-systems t]
3448 ["thermal_systems" vhdl-template-package-thermal-systems t]
3449 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3450 "--"))
3451 (when (vhdl-standard-p 'math)
3452 '(["math_complex" vhdl-template-package-math-complex t]
3453 ["math_real" vhdl-template-package-math-real t]
3454 "--"))
3455 '(["Insert Package..." vhdl-template-insert-package
3456 :keys "C-c C-i C-p"])))
3457 '(("Directive"
3458 ["translate_on" vhdl-template-directive-translate-on t]
3459 ["translate_off" vhdl-template-directive-translate-off t]
3460 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3461 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3462 "--"
3463 ["Insert Directive..." vhdl-template-insert-directive
3464 :keys "C-c C-i C-d"])
3465 "--"
3466 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3467 ["Insert Footer" vhdl-template-footer t]
3468 ["Insert Date" vhdl-template-insert-date t]
3469 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3470 "--"
3471 ["Query Next Prompt" vhdl-template-search-prompt t]))
3472 ,(append
3473 '("Model")
3474 ;; add menu entries for defined models
3475 (let ((model-alist vhdl-model-alist) menu-list model)
3476 (while model-alist
3477 (setq model (car model-alist))
3478 (setq menu-list
3479 (cons
3480 (vector
3481 (nth 0 model)
3482 (vhdl-function-name "vhdl-model" (nth 0 model))
3483 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3484 menu-list))
3485 (setq model-alist (cdr model-alist)))
3486 (setq menu-list (nreverse menu-list))
3487 (vhdl-menu-split menu-list "Model"))
3488 '("--" "--"
3489 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3490 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3491 ("Port"
3492 ["Copy" vhdl-port-copy t]
3493 "--"
3494 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3495 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3496 ["Paste As Instance" vhdl-port-paste-instance
3497 :keys "C-c C-p C-i" :active vhdl-port-list]
3498 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3499 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3500 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3501 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3502 "--"
3503 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3504 "--"
3505 ["Flatten" vhdl-port-flatten
3506 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3507 ["Reverse Direction" vhdl-port-reverse-direction
3508 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3509 ("Compose"
3510 ["New Component" vhdl-compose-new-component t]
3511 ["Copy Component" vhdl-port-copy t]
3512 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3513 ["Wire Components" vhdl-compose-wire-components t]
3514 "--"
3515 ["Generate Configuration" vhdl-compose-configuration t]
3516 ["Generate Components Package" vhdl-compose-components-package t])
3517 ("Subprogram"
3518 ["Copy" vhdl-subprog-copy t]
3519 "--"
3520 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3521 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3522 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3523 "--"
3524 ["Flatten" vhdl-subprog-flatten
3525 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3526 "--"
3527 ("Comment"
3528 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3529 "--"
3530 ["Insert Inline Comment" vhdl-comment-append-inline t]
3531 ["Insert Horizontal Line" vhdl-comment-display-line t]
3532 ["Insert Display Comment" vhdl-comment-display t]
3533 "--"
3534 ["Fill Comment" fill-paragraph t]
3535 ["Fill Comment Region" fill-region (mark)]
3536 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3537 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3538 ("Line"
3539 ["Kill" vhdl-line-kill t]
3540 ["Copy" vhdl-line-copy t]
3541 ["Yank" vhdl-line-yank t]
3542 ["Expand" vhdl-line-expand t]
3543 "--"
3544 ["Transpose Next" vhdl-line-transpose-next t]
3545 ["Transpose Prev" vhdl-line-transpose-previous t]
3546 ["Open" vhdl-line-open t]
3547 ["Join" vhdl-delete-indentation t]
3548 "--"
3549 ["Goto" goto-line t]
3550 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3551 ("Move"
3552 ["Forward Statement" vhdl-end-of-statement t]
3553 ["Backward Statement" vhdl-beginning-of-statement t]
3554 ["Forward Expression" vhdl-forward-sexp t]
3555 ["Backward Expression" vhdl-backward-sexp t]
3556 ["Forward Same Indent" vhdl-forward-same-indent t]
3557 ["Backward Same Indent" vhdl-backward-same-indent t]
3558 ["Forward Function" vhdl-end-of-defun t]
3559 ["Backward Function" vhdl-beginning-of-defun t]
3560 ["Mark Function" vhdl-mark-defun t])
3561 "--"
3562 ("Indent"
3563 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3564 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3565 ["Region" vhdl-indent-region (mark)]
3566 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3567 ("Align"
3568 ["Group" vhdl-align-group t]
3569 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3570 ["List" vhdl-align-list t]
3571 ["Declarations" vhdl-align-declarations t]
3572 ["Region" vhdl-align-region (mark)]
3573 ["Buffer" vhdl-align-buffer t]
3574 "--"
3575 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3576 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3577 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3578 ("Fill"
3579 ["List" vhdl-fill-list t]
3580 ["Group" vhdl-fill-group t]
3581 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3582 ["Region" vhdl-fill-region (mark)])
3583 ("Beautify"
3584 ["Region" vhdl-beautify-region (mark)]
3585 ["Buffer" vhdl-beautify-buffer t])
3586 ("Fix"
3587 ["Generic/Port Clause" vhdl-fix-clause t]
3588 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3589 "--"
3590 ["Case Region" vhdl-fix-case-region (mark)]
3591 ["Case Buffer" vhdl-fix-case-buffer t]
3592 "--"
3593 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3594 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3595 "--"
3596 ["Statement Region" vhdl-fix-statement-region (mark)]
3597 ["Statement Buffer" vhdl-fix-statement-buffer t]
3598 "--"
3599 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3600 ("Update"
3601 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3602 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3603 "--"
3604 ["Fontify Buffer" vhdl-fontify-buffer t]
3605 ["Statistics Buffer" vhdl-statistics-buffer t]
3606 ["Show Messages" vhdl-show-messages t]
3607 ["Syntactic Info" vhdl-show-syntactic-information t]
3608 "--"
3609 ["Speedbar" vhdl-speedbar t]
3610 ["Hide/Show" vhdl-hs-minor-mode t]
3611 "--"
3612 ("Documentation"
3613 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3614 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3615 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3616 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3617 ["Version" vhdl-version t]
3618 ["Bug Report..." vhdl-submit-bug-report t]
3619 "--"
3620 ("Options"
3621 ("Mode"
3622 ["Electric Mode"
3623 (progn (customize-set-variable 'vhdl-electric-mode
3624 (not vhdl-electric-mode))
3625 (vhdl-mode-line-update))
3626 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3627 ["Stutter Mode"
3628 (progn (customize-set-variable 'vhdl-stutter-mode
3629 (not vhdl-stutter-mode))
3630 (vhdl-mode-line-update))
3631 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3632 ["Indent Tabs Mode"
3633 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3634 (not vhdl-indent-tabs-mode))
3635 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3636 :style toggle :selected vhdl-indent-tabs-mode]
3637 "--"
3638 ["Customize Group..." (customize-group 'vhdl-mode) t])
3639 ("Project"
3640 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3641 ,(append
3642 '("Selected Project at Startup"
3643 ["None" (progn (customize-set-variable 'vhdl-project nil)
3644 (vhdl-set-project ""))
3645 :style radio :selected (null vhdl-project)]
3646 "--")
3647 ;; add menu entries for defined projects
3648 (let ((project-alist vhdl-project-alist) menu-list name)
3649 (while project-alist
3650 (setq name (caar project-alist))
3651 (setq menu-list
3652 (cons `[,name (progn (customize-set-variable
3653 'vhdl-project ,name)
3654 (vhdl-set-project ,name))
3655 :style radio :selected (equal ,name vhdl-project)]
3656 menu-list))
3657 (setq project-alist (cdr project-alist)))
3658 (setq menu-list (nreverse menu-list))
3659 (vhdl-menu-split menu-list "Project")))
3660 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3661 ("Auto Load Setup File"
3662 ["At Startup"
3663 (customize-set-variable 'vhdl-project-auto-load
3664 (if (memq 'startup vhdl-project-auto-load)
3665 (delq 'startup vhdl-project-auto-load)
3666 (cons 'startup vhdl-project-auto-load)))
3667 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3668 ["Sort Projects"
3669 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3670 :style toggle :selected vhdl-project-sort]
3671 "--"
3672 ["Customize Group..." (customize-group 'vhdl-project) t])
3673 ("Compiler"
3674 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3675 ,(append
3676 '("Selected Compiler at Startup")
3677 ;; add menu entries for defined compilers
3678 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3679 (while comp-alist
3680 (setq name (caar comp-alist))
3681 (setq menu-list
3682 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3683 :style radio :selected (equal ,name vhdl-compiler)]
3684 menu-list))
3685 (setq comp-alist (cdr comp-alist)))
3686 (setq menu-list (nreverse menu-list))
3687 (vhdl-menu-split menu-list "Compiler")))
3688 ["Use Local Error Regexp"
3689 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3690 (not vhdl-compile-use-local-error-regexp))
3691 :style toggle :selected vhdl-compile-use-local-error-regexp]
3692 ["Makefile Default Targets..."
3693 (customize-option 'vhdl-makefile-default-targets) t]
3694 ["Makefile Generation Hook..."
3695 (customize-option 'vhdl-makefile-generation-hook) t]
3696 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3697 "--"
3698 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3699 ("Style"
3700 ("VHDL Standard"
3701 ["VHDL'87"
3702 (progn (customize-set-variable 'vhdl-standard
3703 (list '87 (cadr vhdl-standard)))
3704 (vhdl-activate-customizations))
3705 :style radio :selected (eq '87 (car vhdl-standard))]
3706 ["VHDL'93/02"
3707 (progn (customize-set-variable 'vhdl-standard
3708 (list '93 (cadr vhdl-standard)))
3709 (vhdl-activate-customizations))
3710 :style radio :selected (eq '93 (car vhdl-standard))]
3711 "--"
3712 ["VHDL-AMS"
3713 (progn (customize-set-variable
3714 'vhdl-standard (list (car vhdl-standard)
3715 (if (memq 'ams (cadr vhdl-standard))
3716 (delq 'ams (cadr vhdl-standard))
3717 (cons 'ams (cadr vhdl-standard)))))
3718 (vhdl-activate-customizations))
3719 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3720 ["Math Packages"
3721 (progn (customize-set-variable
3722 'vhdl-standard (list (car vhdl-standard)
3723 (if (memq 'math (cadr vhdl-standard))
3724 (delq 'math (cadr vhdl-standard))
3725 (cons 'math (cadr vhdl-standard)))))
3726 (vhdl-activate-customizations))
3727 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3728 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3729 ["Upper Case Keywords"
3730 (customize-set-variable 'vhdl-upper-case-keywords
3731 (not vhdl-upper-case-keywords))
3732 :style toggle :selected vhdl-upper-case-keywords]
3733 ["Upper Case Types"
3734 (customize-set-variable 'vhdl-upper-case-types
3735 (not vhdl-upper-case-types))
3736 :style toggle :selected vhdl-upper-case-types]
3737 ["Upper Case Attributes"
3738 (customize-set-variable 'vhdl-upper-case-attributes
3739 (not vhdl-upper-case-attributes))
3740 :style toggle :selected vhdl-upper-case-attributes]
3741 ["Upper Case Enumeration Values"
3742 (customize-set-variable 'vhdl-upper-case-enum-values
3743 (not vhdl-upper-case-enum-values))
3744 :style toggle :selected vhdl-upper-case-enum-values]
3745 ["Upper Case Constants"
3746 (customize-set-variable 'vhdl-upper-case-constants
3747 (not vhdl-upper-case-constants))
3748 :style toggle :selected vhdl-upper-case-constants]
3749 ("Use Direct Instantiation"
3750 ["Never"
3751 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3752 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3753 ["Standard"
3754 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3755 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3756 ["Always"
3757 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3758 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3759 ["Include Array Index and Record Field in Sensitivity List"
3760 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3761 (not vhdl-array-index-record-field-in-sensitivity-list))
3762 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3763 "--"
3764 ["Customize Group..." (customize-group 'vhdl-style) t])
3765 ("Naming"
3766 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3767 ["Architecture File Name..."
3768 (customize-option 'vhdl-architecture-file-name) t]
3769 ["Configuration File Name..."
3770 (customize-option 'vhdl-configuration-file-name) t]
3771 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3772 ("File Name Case"
3773 ["As Is"
3774 (customize-set-variable 'vhdl-file-name-case 'identity)
3775 :style radio :selected (eq 'identity vhdl-file-name-case)]
3776 ["Lower Case"
3777 (customize-set-variable 'vhdl-file-name-case 'downcase)
3778 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3779 ["Upper Case"
3780 (customize-set-variable 'vhdl-file-name-case 'upcase)
3781 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3782 ["Capitalize"
3783 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3784 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3785 "--"
3786 ["Customize Group..." (customize-group 'vhdl-naming) t])
3787 ("Template"
3788 ("Electric Keywords"
3789 ["VHDL Keywords"
3790 (customize-set-variable 'vhdl-electric-keywords
3791 (if (memq 'vhdl vhdl-electric-keywords)
3792 (delq 'vhdl vhdl-electric-keywords)
3793 (cons 'vhdl vhdl-electric-keywords)))
3794 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3795 ["User Model Keywords"
3796 (customize-set-variable 'vhdl-electric-keywords
3797 (if (memq 'user vhdl-electric-keywords)
3798 (delq 'user vhdl-electric-keywords)
3799 (cons 'user vhdl-electric-keywords)))
3800 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3801 ("Insert Optional Labels"
3802 ["None"
3803 (customize-set-variable 'vhdl-optional-labels 'none)
3804 :style radio :selected (eq 'none vhdl-optional-labels)]
3805 ["Processes Only"
3806 (customize-set-variable 'vhdl-optional-labels 'process)
3807 :style radio :selected (eq 'process vhdl-optional-labels)]
3808 ["All Constructs"
3809 (customize-set-variable 'vhdl-optional-labels 'all)
3810 :style radio :selected (eq 'all vhdl-optional-labels)])
3811 ("Insert Empty Lines"
3812 ["None"
3813 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3814 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3815 ["Design Units Only"
3816 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3817 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3818 ["All Constructs"
3819 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3820 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3821 ["Argument List Indent"
3822 (customize-set-variable 'vhdl-argument-list-indent
3823 (not vhdl-argument-list-indent))
3824 :style toggle :selected vhdl-argument-list-indent]
3825 ["Association List with Formals"
3826 (customize-set-variable 'vhdl-association-list-with-formals
3827 (not vhdl-association-list-with-formals))
3828 :style toggle :selected vhdl-association-list-with-formals]
3829 ["Conditions in Parenthesis"
3830 (customize-set-variable 'vhdl-conditions-in-parenthesis
3831 (not vhdl-conditions-in-parenthesis))
3832 :style toggle :selected vhdl-conditions-in-parenthesis]
3833 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3834 ["One String..." (customize-option 'vhdl-one-string) t]
3835 ("File Header"
3836 ["Header String..." (customize-option 'vhdl-file-header) t]
3837 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3838 ["Company Name..." (customize-option 'vhdl-company-name) t]
3839 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3840 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3841 ["Date Format..." (customize-option 'vhdl-date-format) t]
3842 ["Modify Date Prefix String..."
3843 (customize-option 'vhdl-modify-date-prefix-string) t]
3844 ["Modify Date on Saving"
3845 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3846 (not vhdl-modify-date-on-saving))
3847 (vhdl-activate-customizations))
3848 :style toggle :selected vhdl-modify-date-on-saving])
3849 ("Sequential Process"
3850 ("Kind of Reset"
3851 ["None"
3852 (customize-set-variable 'vhdl-reset-kind 'none)
3853 :style radio :selected (eq 'none vhdl-reset-kind)]
3854 ["Synchronous"
3855 (customize-set-variable 'vhdl-reset-kind 'sync)
3856 :style radio :selected (eq 'sync vhdl-reset-kind)]
3857 ["Asynchronous"
3858 (customize-set-variable 'vhdl-reset-kind 'async)
3859 :style radio :selected (eq 'async vhdl-reset-kind)]
3860 ["Query"
3861 (customize-set-variable 'vhdl-reset-kind 'query)
3862 :style radio :selected (eq 'query vhdl-reset-kind)])
3863 ["Reset is Active High"
3864 (customize-set-variable 'vhdl-reset-active-high
3865 (not vhdl-reset-active-high))
3866 :style toggle :selected vhdl-reset-active-high]
3867 ["Use Rising Clock Edge"
3868 (customize-set-variable 'vhdl-clock-rising-edge
3869 (not vhdl-clock-rising-edge))
3870 :style toggle :selected vhdl-clock-rising-edge]
3871 ("Clock Edge Condition"
3872 ["Standard"
3873 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3874 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3875 ["Function \"rising_edge\""
3876 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3877 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3878 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3879 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3880 "--"
3881 ["Customize Group..." (customize-group 'vhdl-template) t])
3882 ("Model"
3883 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3884 ("Port"
3885 ["Include Port Comments"
3886 (customize-set-variable 'vhdl-include-port-comments
3887 (not vhdl-include-port-comments))
3888 :style toggle :selected vhdl-include-port-comments]
3889 ["Include Direction Comments"
3890 (customize-set-variable 'vhdl-include-direction-comments
3891 (not vhdl-include-direction-comments))
3892 :style toggle :selected vhdl-include-direction-comments]
3893 ["Include Type Comments"
3894 (customize-set-variable 'vhdl-include-type-comments
3895 (not vhdl-include-type-comments))
3896 :style toggle :selected vhdl-include-type-comments]
3897 ("Include Group Comments"
3898 ["Never"
3899 (customize-set-variable 'vhdl-include-group-comments 'never)
3900 :style radio :selected (eq 'never vhdl-include-group-comments)]
3901 ["Declarations"
3902 (customize-set-variable 'vhdl-include-group-comments 'decl)
3903 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3904 ["Always"
3905 (customize-set-variable 'vhdl-include-group-comments 'always)
3906 :style radio :selected (eq 'always vhdl-include-group-comments)])
3907 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
3908 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3909 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3910 ("Testbench"
3911 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3912 ["Architecture Name..."
3913 (customize-option 'vhdl-testbench-architecture-name) t]
3914 ["Configuration Name..."
3915 (customize-option 'vhdl-testbench-configuration-name) t]
3916 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3917 ["Include Header"
3918 (customize-set-variable 'vhdl-testbench-include-header
3919 (not vhdl-testbench-include-header))
3920 :style toggle :selected vhdl-testbench-include-header]
3921 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3922 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3923 ["Initialize Signals"
3924 (customize-set-variable 'vhdl-testbench-initialize-signals
3925 (not vhdl-testbench-initialize-signals))
3926 :style toggle :selected vhdl-testbench-initialize-signals]
3927 ["Include Library Clause"
3928 (customize-set-variable 'vhdl-testbench-include-library
3929 (not vhdl-testbench-include-library))
3930 :style toggle :selected vhdl-testbench-include-library]
3931 ["Include Configuration"
3932 (customize-set-variable 'vhdl-testbench-include-configuration
3933 (not vhdl-testbench-include-configuration))
3934 :style toggle :selected vhdl-testbench-include-configuration]
3935 ("Create Files"
3936 ["None"
3937 (customize-set-variable 'vhdl-testbench-create-files 'none)
3938 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3939 ["Single"
3940 (customize-set-variable 'vhdl-testbench-create-files 'single)
3941 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3942 ["Separate"
3943 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3944 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3945 ["Testbench Entity File Name..."
3946 (customize-option 'vhdl-testbench-entity-file-name) t]
3947 ["Testbench Architecture File Name..."
3948 (customize-option 'vhdl-testbench-architecture-file-name) t])
3949 "--"
3950 ["Customize Group..." (customize-group 'vhdl-port) t])
3951 ("Compose"
3952 ["Architecture Name..."
3953 (customize-option 'vhdl-compose-architecture-name) t]
3954 ["Configuration Name..."
3955 (customize-option 'vhdl-compose-configuration-name) t]
3956 ["Components Package Name..."
3957 (customize-option 'vhdl-components-package-name) t]
3958 ["Use Components Package"
3959 (customize-set-variable 'vhdl-use-components-package
3960 (not vhdl-use-components-package))
3961 :style toggle :selected vhdl-use-components-package]
3962 ["Include Header"
3963 (customize-set-variable 'vhdl-compose-include-header
3964 (not vhdl-compose-include-header))
3965 :style toggle :selected vhdl-compose-include-header]
3966 ("Create Entity/Architecture Files"
3967 ["None"
3968 (customize-set-variable 'vhdl-compose-create-files 'none)
3969 :style radio :selected (eq 'none vhdl-compose-create-files)]
3970 ["Single"
3971 (customize-set-variable 'vhdl-compose-create-files 'single)
3972 :style radio :selected (eq 'single vhdl-compose-create-files)]
3973 ["Separate"
3974 (customize-set-variable 'vhdl-compose-create-files 'separate)
3975 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3976 ["Create Configuration File"
3977 (customize-set-variable 'vhdl-compose-configuration-create-file
3978 (not vhdl-compose-configuration-create-file))
3979 :style toggle :selected vhdl-compose-configuration-create-file]
3980 ["Hierarchical Configuration"
3981 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3982 (not vhdl-compose-configuration-hierarchical))
3983 :style toggle :selected vhdl-compose-configuration-hierarchical]
3984 ["Use Subconfiguration"
3985 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3986 (not vhdl-compose-configuration-use-subconfiguration))
3987 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3988 "--"
3989 ["Customize Group..." (customize-group 'vhdl-compose) t])
3990 ("Comment"
3991 ["Self Insert Comments"
3992 (customize-set-variable 'vhdl-self-insert-comments
3993 (not vhdl-self-insert-comments))
3994 :style toggle :selected vhdl-self-insert-comments]
3995 ["Prompt for Comments"
3996 (customize-set-variable 'vhdl-prompt-for-comments
3997 (not vhdl-prompt-for-comments))
3998 :style toggle :selected vhdl-prompt-for-comments]
3999 ["Inline Comment Column..."
4000 (customize-option 'vhdl-inline-comment-column) t]
4001 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
4002 "--"
4003 ["Customize Group..." (customize-group 'vhdl-comment) t])
4004 ("Beautify"
4005 ["Auto Align Templates"
4006 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
4007 :style toggle :selected vhdl-auto-align]
4008 ["Align Line Groups"
4009 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
4010 :style toggle :selected vhdl-align-groups]
4011 ["Group Separation String..."
4012 (customize-option 'vhdl-align-group-separate) t]
4013 ["Align Lines with Same Indent"
4014 (customize-set-variable 'vhdl-align-same-indent
4015 (not vhdl-align-same-indent))
4016 :style toggle :selected vhdl-align-same-indent]
4017 ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
4018 "--"
4019 ["Customize Group..." (customize-group 'vhdl-beautify) t])
4020 ("Highlight"
4021 ["Highlighting On/Off..."
4022 (customize-option
4023 (if (fboundp 'global-font-lock-mode)
4024 'global-font-lock-mode 'font-lock-auto-fontify)) t]
4025 ["Highlight Keywords"
4026 (progn (customize-set-variable 'vhdl-highlight-keywords
4027 (not vhdl-highlight-keywords))
4028 (vhdl-fontify-buffer))
4029 :style toggle :selected vhdl-highlight-keywords]
4030 ["Highlight Names"
4031 (progn (customize-set-variable 'vhdl-highlight-names
4032 (not vhdl-highlight-names))
4033 (vhdl-fontify-buffer))
4034 :style toggle :selected vhdl-highlight-names]
4035 ["Highlight Special Words"
4036 (progn (customize-set-variable 'vhdl-highlight-special-words
4037 (not vhdl-highlight-special-words))
4038 (vhdl-fontify-buffer))
4039 :style toggle :selected vhdl-highlight-special-words]
4040 ["Highlight Forbidden Words"
4041 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4042 (not vhdl-highlight-forbidden-words))
4043 (vhdl-fontify-buffer))
4044 :style toggle :selected vhdl-highlight-forbidden-words]
4045 ["Highlight Verilog Keywords"
4046 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4047 (not vhdl-highlight-verilog-keywords))
4048 (vhdl-fontify-buffer))
4049 :style toggle :selected vhdl-highlight-verilog-keywords]
4050 ["Highlight \"translate_off\""
4051 (progn (customize-set-variable 'vhdl-highlight-translate-off
4052 (not vhdl-highlight-translate-off))
4053 (vhdl-fontify-buffer))
4054 :style toggle :selected vhdl-highlight-translate-off]
4055 ["Case Sensitive Highlighting"
4056 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4057 (not vhdl-highlight-case-sensitive))
4058 (vhdl-fontify-buffer))
4059 :style toggle :selected vhdl-highlight-case-sensitive]
4060 ["Special Syntax Definition..."
4061 (customize-option 'vhdl-special-syntax-alist) t]
4062 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
4063 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
4064 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
4065 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
4066 "--"
4067 ["Customize Group..." (customize-group 'vhdl-highlight) t])
4068 ("Speedbar"
4069 ["Auto Open at Startup"
4070 (customize-set-variable 'vhdl-speedbar-auto-open
4071 (not vhdl-speedbar-auto-open))
4072 :style toggle :selected vhdl-speedbar-auto-open]
4073 ("Default Displaying Mode"
4074 ["Files"
4075 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
4076 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
4077 ["Directory Hierarchy"
4078 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
4079 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
4080 ["Project Hierarchy"
4081 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
4082 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
4083 ["Indentation Offset..."
4084 (customize-option 'speedbar-indentation-width) t]
4085 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
4086 ["Jump to Unit when Opening"
4087 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4088 (not vhdl-speedbar-jump-to-unit))
4089 :style toggle :selected vhdl-speedbar-jump-to-unit]
4090 ["Update Hierarchy on File Saving"
4091 (customize-set-variable 'vhdl-speedbar-update-on-saving
4092 (not vhdl-speedbar-update-on-saving))
4093 :style toggle :selected vhdl-speedbar-update-on-saving]
4094 ("Save in Cache File"
4095 ["Hierarchy Information"
4096 (customize-set-variable 'vhdl-speedbar-save-cache
4097 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4098 (delq 'hierarchy vhdl-speedbar-save-cache)
4099 (cons 'hierarchy vhdl-speedbar-save-cache)))
4100 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4101 ["Displaying Status"
4102 (customize-set-variable 'vhdl-speedbar-save-cache
4103 (if (memq 'display vhdl-speedbar-save-cache)
4104 (delq 'display vhdl-speedbar-save-cache)
4105 (cons 'display vhdl-speedbar-save-cache)))
4106 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4107 ["Cache File Name..."
4108 (customize-option 'vhdl-speedbar-cache-file-name) t]
4109 "--"
4110 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4111 ("Menu"
4112 ["Add Index Menu when Loading File"
4113 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4114 (vhdl-index-menu-init))
4115 :style toggle :selected vhdl-index-menu]
4116 ["Add Source File Menu when Loading File"
4117 (progn (customize-set-variable 'vhdl-source-file-menu
4118 (not vhdl-source-file-menu))
4119 (vhdl-add-source-files-menu))
4120 :style toggle :selected vhdl-source-file-menu]
4121 ["Add Hideshow Menu at Startup"
4122 (progn (customize-set-variable 'vhdl-hideshow-menu
4123 (not vhdl-hideshow-menu))
4124 (vhdl-activate-customizations))
4125 :style toggle :selected vhdl-hideshow-menu]
4126 ["Hide Everything Initially"
4127 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4128 :style toggle :selected vhdl-hide-all-init]
4129 "--"
4130 ["Customize Group..." (customize-group 'vhdl-menu) t])
4131 ("Print"
4132 ["In Two Column Format"
4133 (progn (customize-set-variable 'vhdl-print-two-column
4134 (not vhdl-print-two-column))
4135 (message "Activate new setting by saving options and restarting Emacs"))
4136 :style toggle :selected vhdl-print-two-column]
4137 ["Use Customized Faces"
4138 (progn (customize-set-variable 'vhdl-print-customize-faces
4139 (not vhdl-print-customize-faces))
4140 (message "Activate new setting by saving options and restarting Emacs"))
4141 :style toggle :selected vhdl-print-customize-faces]
4142 "--"
4143 ["Customize Group..." (customize-group 'vhdl-print) t])
4144 ("Miscellaneous"
4145 ["Use Intelligent Tab"
4146 (progn (customize-set-variable 'vhdl-intelligent-tab
4147 (not vhdl-intelligent-tab))
4148 (vhdl-activate-customizations))
4149 :style toggle :selected vhdl-intelligent-tab]
4150 ["Indent Syntax-Based"
4151 (customize-set-variable 'vhdl-indent-syntax-based
4152 (not vhdl-indent-syntax-based))
4153 :style toggle :selected vhdl-indent-syntax-based]
4154 ["Indent Comments Like Next Code Line"
4155 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4156 (not vhdl-indent-comment-like-next-code-line))
4157 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4158 ["Word Completion is Case Sensitive"
4159 (customize-set-variable 'vhdl-word-completion-case-sensitive
4160 (not vhdl-word-completion-case-sensitive))
4161 :style toggle :selected vhdl-word-completion-case-sensitive]
4162 ["Word Completion in Minibuffer"
4163 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4164 (not vhdl-word-completion-in-minibuffer))
4165 (message "Activate new setting by saving options and restarting Emacs"))
4166 :style toggle :selected vhdl-word-completion-in-minibuffer]
4167 ["Underscore is Part of Word"
4168 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4169 (not vhdl-underscore-is-part-of-word))
4170 (vhdl-activate-customizations))
4171 :style toggle :selected vhdl-underscore-is-part-of-word]
4172 "--"
4173 ["Customize Group..." (customize-group 'vhdl-misc) t])
4174 ["Related..." (customize-browse 'vhdl-related) t]
4175 "--"
4176 ["Save Options" customize-save-customized t]
4177 ["Activate Options" vhdl-activate-customizations t]
4178 ["Browse Options..." vhdl-customize t])))
4180 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4181 "VHDL Mode menu.")
4183 (defun vhdl-update-mode-menu ()
4184 "Update VHDL Mode menu."
4185 (interactive)
4186 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4187 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4188 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4189 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4190 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4193 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4195 (defconst vhdl-imenu-generic-expression
4197 ("Subprogram"
4198 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4200 ("Instance"
4201 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4203 ("Component"
4204 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4206 ("Procedural"
4207 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4209 ("Process"
4210 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4212 ("Block"
4213 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4215 ("Package"
4216 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4218 ("Configuration"
4219 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4221 ("Architecture"
4222 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4224 ("Entity"
4225 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4228 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4230 (defun vhdl-index-menu-init ()
4231 "Initialize index menu."
4232 (set (make-local-variable 'imenu-case-fold-search) t)
4233 (set (make-local-variable 'imenu-generic-expression)
4234 vhdl-imenu-generic-expression)
4235 (when (and vhdl-index-menu (fboundp 'imenu))
4236 (imenu-add-to-menubar "Index")))
4238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4239 ;; Source file menu (using `easy-menu.el')
4241 (defvar vhdl-sources-menu nil)
4243 (defun vhdl-directory-files (directory &optional full match)
4244 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4245 message."
4246 (if (not (file-directory-p directory))
4247 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4248 (let ((dir (directory-files directory full match)))
4249 (setq dir (delete "." dir))
4250 (setq dir (delete ".." dir))
4251 dir)))
4253 (defun vhdl-get-source-files (&optional full directory)
4254 "Get list of VHDL source files in DIRECTORY or current directory."
4255 (let ((mode-alist auto-mode-alist)
4256 filename-regexp)
4257 ;; create regular expressions for matching file names
4258 (setq filename-regexp "\\`[^.].*\\(")
4259 (while mode-alist
4260 (when (eq (cdar mode-alist) 'vhdl-mode)
4261 (setq filename-regexp
4262 (concat filename-regexp (caar mode-alist) "\\|")))
4263 (setq mode-alist (cdr mode-alist)))
4264 (setq filename-regexp
4265 (concat (substring filename-regexp 0
4266 (string-match "\\\\|$" filename-regexp)) "\\)"))
4267 ;; find files
4268 (vhdl-directory-files
4269 (or directory default-directory) full filename-regexp)))
4271 (defun vhdl-add-source-files-menu ()
4272 "Scan directory for all VHDL source files and generate menu.
4273 The directory of the current source file is scanned."
4274 (interactive)
4275 (message "Scanning directory for source files ...")
4276 (let ((newmap (current-local-map))
4277 (file-list (vhdl-get-source-files))
4278 menu-list found)
4279 ;; Create list for menu
4280 (setq found nil)
4281 (while file-list
4282 (setq found t)
4283 (push (vector (car file-list) (list 'find-file (car file-list)) t)
4284 menu-list)
4285 (setq file-list (cdr file-list)))
4286 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4287 (when found (push "--" menu-list))
4288 (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
4289 (push "Sources" menu-list)
4290 ;; Create menu
4291 (easy-menu-add menu-list)
4292 (easy-menu-define vhdl-sources-menu newmap
4293 "VHDL source files menu" menu-list))
4294 (message ""))
4297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4298 ;;; Mode definition
4299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4300 ;; performs all buffer local initializations
4302 ;;;###autoload
4303 (define-derived-mode vhdl-mode prog-mode
4304 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4305 (vhdl-electric-mode "e")
4306 (vhdl-stutter-mode "s"))
4307 "Major mode for editing VHDL code.
4309 Usage:
4310 ------
4312 TEMPLATE INSERTION (electrification):
4313 After typing a VHDL keyword and entering `SPC', you are prompted for
4314 arguments while a template is generated for that VHDL construct. Typing
4315 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4316 template generation. Optional arguments are indicated by square
4317 brackets and removed if the queried string is left empty. Prompts for
4318 mandatory arguments remain in the code if the queried string is left
4319 empty. They can be queried again by `C-c C-t C-q'. Enabled
4320 electrification is indicated by `/e' in the mode line.
4322 Typing `M-SPC' after a keyword inserts a space without calling the
4323 template generator. Automatic template generation (i.e.
4324 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4325 setting option `vhdl-electric-mode' (see OPTIONS).
4327 Template generators can be invoked from the VHDL menu, by key
4328 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4329 the keyword (i.e. first word of menu entry not in parenthesis) and
4330 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4331 conf, comp, cons, func, inst, pack, sig, var.
4333 Template styles can be customized in customization group
4334 `vhdl-template' \(see OPTIONS).
4337 HEADER INSERTION:
4338 A file header can be inserted by `C-c C-t C-h'. A file footer
4339 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4340 See customization group `vhdl-header'.
4343 STUTTERING:
4344 Double striking of some keys inserts cumbersome VHDL syntax elements.
4345 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4346 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4347 the mode line. The stuttering keys and their effects are:
4349 ;; --> \" : \" [ --> ( -- --> comment
4350 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4351 .. --> \" => \" ] --> ) --- --> horizontal line
4352 ,, --> \" <= \" ]] --> ] ---- --> display comment
4353 == --> \" == \" '' --> \\\"
4356 WORD COMPLETION:
4357 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4358 word in the buffer that starts alike, inserts it and adjusts case.
4359 Re-typing `TAB' toggles through alternative word completions. This also
4360 works in the minibuffer (i.e. in template generator prompts).
4362 Typing `TAB' after `(' looks for and inserts complete parenthesized
4363 expressions (e.g. for array index ranges). All keywords as well as
4364 standard types and subprograms of VHDL have predefined abbreviations
4365 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4366 beginning with \"std\").
4368 Typing `TAB' after a non-word character indents the line if at the
4369 beginning of a line (i.e. no preceding non-blank characters), and
4370 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4371 stop.
4374 COMMENTS:
4375 `--' puts a single comment.
4376 `---' draws a horizontal line for separating code segments.
4377 `----' inserts a display comment, i.e. two horizontal lines
4378 with a comment in between.
4379 `--CR' comments out code on that line. Re-hitting CR comments
4380 out following lines.
4381 `C-c C-c' comments out a region if not commented out,
4382 uncomments a region if already commented out. Option
4383 `comment-style' defines where the comment characters
4384 should be placed (beginning of line, indent, etc.).
4386 You are prompted for comments after object definitions (i.e. signals,
4387 variables, constants, ports) and after subprogram and process
4388 specifications if option `vhdl-prompt-for-comments' is non-nil.
4389 Comments are automatically inserted as additional labels (e.g. after
4390 begin statements) and as help comments if `vhdl-self-insert-comments' is
4391 non-nil.
4393 Inline comments (i.e. comments after a piece of code on the same line)
4394 are indented at least to `vhdl-inline-comment-column'. Comments go at
4395 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4396 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4397 in a comment automatically opens a new comment line. `M-q' re-fills
4398 multi-line comments.
4401 INDENTATION:
4402 `TAB' indents a line if at the beginning of the line. The amount of
4403 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4404 always indents the current line (is bound to `TAB' if option
4405 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4406 the entire region.
4408 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4409 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4410 indented normally (nil) or relative to the opening parenthesis (non-nil)
4411 according to option `vhdl-argument-list-indent'.
4413 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4414 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4415 and vice versa.
4417 Syntax-based indentation can be very slow in large files. Option
4418 `vhdl-indent-syntax-based' allows you to use faster but simpler indentation.
4420 Option `vhdl-indent-comment-like-next-code-line' controls whether
4421 comment lines are indented like the preceding or like the following code
4422 line.
4425 ALIGNMENT:
4426 The alignment functions align operators, keywords, and inline comments
4427 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4428 separated by blank lines, `C-c C-a C-i' a block of lines with same
4429 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4430 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4431 C-a C-d' all lines within the declarative part of a design unit. `C-c
4432 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4433 for a group of lines, and `C-c C-a M-c' for a region.
4435 If option `vhdl-align-groups' is non-nil, groups of code lines
4436 separated by special lines (see option `vhdl-align-group-separate') are
4437 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4438 blocks of lines with same indent are aligned separately. Some templates
4439 are automatically aligned after generation if option `vhdl-auto-align'
4440 is non-nil.
4442 Alignment tries to align inline comments at
4443 `vhdl-inline-comment-column' and tries inline comment not to exceed
4444 `vhdl-end-comment-column'.
4446 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4447 symbols are surrounded by one space, and multiple spaces are eliminated.
4450 CODE FILLING:
4451 Code filling allows you to condense code (e.g. sensitivity lists or port
4452 maps) by removing comments and newlines and re-wrapping so that all
4453 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4454 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4455 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4456 `C-c C-f M-f' an entire region.
4459 CODE BEAUTIFICATION:
4460 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4461 buffer respectively. This includes indentation, alignment, and case
4462 fixing. Code beautification can also be run non-interactively using the
4463 command:
4465 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4468 PORT TRANSLATION:
4469 Generic and port clauses from entity or component declarations can be
4470 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4471 as component instantiations and corresponding internal constants and
4472 signals, as a generic map with constants as actual generics, and as
4473 internal signal initializations (menu).
4475 To include formals in component instantiations, see option
4476 `vhdl-association-list-with-formals'. To include comments in pasting,
4477 see options `vhdl-include-...-comments'.
4479 A clause with several generic/port names on the same line can be
4480 flattened (`C-c C-p C-f') so that only one name per line exists. The
4481 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4482 outputs and vice versa, which can be useful in testbenches. (This
4483 reversion is done on the internal data structure and is only reflected
4484 in subsequent paste operations.)
4486 Names for actual ports, instances, testbenches, and
4487 design-under-test instances can be derived from existing names according
4488 to options `vhdl-...-name'. See customization group `vhdl-port'.
4491 SUBPROGRAM TRANSLATION:
4492 Similar functionality exists for copying/pasting the interface of
4493 subprograms (function/procedure). A subprogram interface can be copied
4494 and then pasted as a subprogram declaration, body or call (uses
4495 association list with formals).
4498 TESTBENCH GENERATION:
4499 A copied port can also be pasted as a testbench. The generated
4500 testbench includes an entity, an architecture, and an optional
4501 configuration. The architecture contains the component declaration and
4502 instantiation of the DUT as well as internal constant and signal
4503 declarations. Additional user-defined templates can be inserted. The
4504 names used for entity/architecture/configuration/DUT as well as the file
4505 structure to be generated can be customized. See customization group
4506 `vhdl-testbench'.
4509 KEY BINDINGS:
4510 Key bindings (`C-c ...') exist for most commands (see in menu).
4513 VHDL MENU:
4514 All commands can be found in the VHDL menu including their key bindings.
4517 FILE BROWSER:
4518 The speedbar allows browsing of directories and file contents. It can
4519 be accessed from the VHDL menu and is automatically opened if option
4520 `vhdl-speedbar-auto-open' is non-nil.
4522 In speedbar, open files and directories with `mouse-2' on the name and
4523 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4526 DESIGN HIERARCHY BROWSER:
4527 The speedbar can also be used for browsing the hierarchy of design units
4528 contained in the source files of the current directory or the specified
4529 projects (see option `vhdl-project-alist').
4531 The speedbar can be switched between file, directory hierarchy and
4532 project hierarchy browsing mode in the speedbar menu or by typing `f',
4533 `h' or `H' in speedbar.
4535 In speedbar, open design units with `mouse-2' on the name and browse
4536 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4537 from entities and components (in packages). Individual design units and
4538 complete designs can directly be compiled (\"Make\" menu entry).
4540 The hierarchy is automatically updated upon saving a modified source
4541 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4542 hierarchy is only updated for projects that have been opened once in the
4543 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4544 options in group `vhdl-speedbar').
4546 Simple design consistency checks are done during scanning, such as
4547 multiple declarations of the same unit or missing primary units that are
4548 required by secondary units.
4551 STRUCTURAL COMPOSITION:
4552 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4553 for a new component. Subcomponents (i.e. component declaration and
4554 instantiation) can be automatically placed from a previously read port
4555 \(`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4556 all subcomponents can be automatically connected using internal signals
4557 and ports (`C-c C-m C-w') following these rules:
4558 - subcomponent actual ports with same name are considered to be
4559 connected by a signal (internal signal or port)
4560 - signals that are only inputs to subcomponents are considered as
4561 inputs to this component -> input port created
4562 - signals that are only outputs from subcomponents are considered as
4563 outputs from this component -> output port created
4564 - signals that are inputs to AND outputs from subcomponents are
4565 considered as internal connections -> internal signal created
4567 Purpose: With appropriate naming conventions it is possible to
4568 create higher design levels with only a few mouse clicks or key
4569 strokes. A new design level can be created by simply generating a new
4570 component, placing the required subcomponents from the hierarchy
4571 browser, and wiring everything automatically.
4573 Note: Automatic wiring only works reliably on templates of new
4574 components and component instantiations that were created by VHDL mode.
4576 Component declarations can be placed in a components package (option
4577 `vhdl-use-components-package') which can be automatically generated for
4578 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4579 component instantiation is also supported (option
4580 `vhdl-use-direct-instantiation').
4582 Configuration declarations can automatically be generated either from
4583 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4584 the speedbar menu (for the architecture under the cursor). The
4585 configurations can optionally be hierarchical (i.e. include all
4586 component levels of a hierarchical design, option
4587 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4588 (option `vhdl-compose-configuration-use-subconfiguration'). For
4589 subcomponents in hierarchical configurations, the most-recently-analyzed
4590 (mra) architecture is selected. If another architecture is desired, it
4591 can be marked as most-recently-analyzed (speedbar menu) before
4592 generating the configuration.
4594 Note: Configurations of subcomponents (i.e. hierarchical configuration
4595 declarations) are currently not considered when displaying
4596 configurations in speedbar.
4598 See the options group `vhdl-compose' for all relevant user options.
4601 SOURCE FILE COMPILATION:
4602 The syntax of the current buffer can be analyzed by calling a VHDL
4603 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4604 option `vhdl-compiler'. The available compilers are listed in option
4605 `vhdl-compiler-alist' including all required compilation command,
4606 command options, compilation directory, and error message syntax
4607 information. New compilers can be added.
4609 All the source files of an entire design can be compiled by the `make'
4610 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4613 MAKEFILE GENERATION:
4614 Makefiles can be generated automatically by an internal generation
4615 routine (`C-c M-k'). The library unit dependency information is
4616 obtained from the hierarchy browser. Makefile generation can be
4617 customized for each compiler in option `vhdl-compiler-alist'.
4619 Makefile generation can also be run non-interactively using the
4620 command:
4622 emacs -batch -l ~/.emacs -l vhdl-mode
4623 [-compiler compilername] [-project projectname]
4624 -f vhdl-generate-makefile
4626 The Makefile's default target \"all\" compiles the entire design, the
4627 target \"clean\" removes it and the target \"library\" creates the
4628 library directory if not existent. These target names can be customized
4629 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4630 target for each primary library unit which allows selective compilation
4631 of this unit, its secondary units and its subhierarchy (example:
4632 compilation of a design specified by a configuration). User specific
4633 parts can be inserted into a Makefile with option
4634 `vhdl-makefile-generation-hook'.
4636 Limitations:
4637 - Only library units and dependencies within the current library are
4638 considered. Makefiles for designs that span multiple libraries are
4639 not (yet) supported.
4640 - Only one-level configurations are supported (also hierarchical),
4641 but configurations that go down several levels are not.
4642 - The \"others\" keyword in configurations is not supported.
4645 PROJECTS:
4646 Projects can be defined in option `vhdl-project-alist' and a current
4647 project be selected using option `vhdl-project' (permanently) or from
4648 the menu or speedbar (temporarily). For each project, title and
4649 description strings (for the file headers), source files/directories
4650 (for the hierarchy browser and Makefile generation), library name, and
4651 compiler-dependent options, exceptions and compilation directory can be
4652 specified. Compilation settings overwrite the settings of option
4653 `vhdl-compiler-alist'.
4655 Project setups can be exported (i.e. written to a file) and imported.
4656 Imported setups are not automatically saved in `vhdl-project-alist' but
4657 can be saved afterwards in its customization buffer. When starting
4658 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4659 vhdl-mode\") in a directory with an existing project setup file, it is
4660 automatically loaded and its project activated if option
4661 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4662 files can be specified in option `vhdl-project-file-name'. Multiple
4663 project setups can be automatically loaded from global directories.
4664 This is an alternative to specifying project setups with option
4665 `vhdl-project-alist'.
4668 SPECIAL MENUES:
4669 As an alternative to the speedbar, an index menu can be added (set
4670 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4671 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4672 file) for browsing the file contents (is not populated if buffer is
4673 larger than 256000). Also, a source file menu can be
4674 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4675 current directory for VHDL source files.
4678 VHDL STANDARDS:
4679 The VHDL standards to be used are specified in option `vhdl-standard'.
4680 Available standards are: VHDL'87/'93(02), VHDL-AMS, and Math Packages.
4683 KEYWORD CASE:
4684 Lower and upper case for keywords and standardized types, attributes,
4685 and enumeration values is supported. If the option
4686 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4687 lower case and are converted into upper case automatically (not for
4688 types, attributes, and enumeration values). The case of keywords,
4689 types, attributes,and enumeration values can be fixed for an entire
4690 region (menu) or buffer (`C-c C-x C-c') according to the options
4691 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4694 HIGHLIGHTING (fontification):
4695 Keywords and standardized types, attributes, enumeration values, and
4696 function names (controlled by option `vhdl-highlight-keywords'), as well
4697 as comments, strings, and template prompts are highlighted using
4698 different colors. Unit, subprogram, signal, variable, constant,
4699 parameter and generic/port names in declarations as well as labels are
4700 highlighted if option `vhdl-highlight-names' is non-nil.
4702 Additional reserved words or words with a forbidden syntax (e.g. words
4703 that should be avoided) can be specified in option
4704 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4705 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4706 keywords are highlighted as forbidden words if option
4707 `vhdl-highlight-verilog-keywords' is non-nil.
4709 Words with special syntax can be highlighted by specifying their
4710 syntax and color in option `vhdl-special-syntax-alist' and by setting
4711 option `vhdl-highlight-special-words' to non-nil. This allows you to
4712 establish some naming conventions (e.g. to distinguish different kinds
4713 of signals or other objects by using name suffices) and to support them
4714 visually.
4716 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4717 to support case-sensitive highlighting. However, keywords are then only
4718 highlighted if written in lower case.
4720 Code between \"translate_off\" and \"translate_on\" pragmas is
4721 highlighted using a different background color if option
4722 `vhdl-highlight-translate-off' is non-nil.
4724 For documentation and customization of the used colors see
4725 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4726 highlighting of matching parenthesis, see customization group
4727 `paren-showing'. Automatic buffer highlighting is turned on/off by
4728 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4731 USER MODELS:
4732 VHDL models (templates) can be specified by the user and made accessible
4733 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4734 electrification. See option `vhdl-model-alist'.
4737 HIDE/SHOW:
4738 The code of blocks, processes, subprograms, component declarations and
4739 instantiations, generic/port clauses, and configuration declarations can
4740 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4741 the code (see customization group `vhdl-menu'). XEmacs: limited
4742 functionality due to old `hideshow.el' package.
4745 CODE UPDATING:
4746 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4747 current process, `C-c C-u M-s' of all processes in the current buffer.
4748 Limitations:
4749 - Only declared local signals (ports, signals declared in
4750 architecture and blocks) are automatically inserted.
4751 - Global signals declared in packages are not automatically inserted.
4752 Insert them once manually (will be kept afterwards).
4753 - Out parameters of procedures are considered to be read.
4754 Use option `vhdl-entity-file-name' to specify the entity file name
4755 \(used to obtain the port names).
4756 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4757 specify whether to include array indices and record fields in
4758 sensitivity lists.
4761 CODE FIXING:
4762 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4763 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4766 PRINTING:
4767 PostScript printing with different faces (an optimized set of faces is
4768 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4769 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4770 PostScript printing commands. Option `vhdl-print-two-column' defines
4771 appropriate default settings for nice landscape two-column printing.
4772 The paper format can be set by option `ps-paper-type'. Do not forget to
4773 switch `ps-print-color-p' to nil for printing on black-and-white
4774 printers.
4777 OPTIONS:
4778 User options allow customization of VHDL Mode. All options are
4779 accessible from the \"Options\" menu entry. Simple options (switches
4780 and choices) can directly be changed, while for complex options a
4781 customization buffer is opened. Changed options can be saved for future
4782 sessions using the \"Save Options\" menu entry.
4784 Options and their detailed descriptions can also be accessed by using
4785 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4786 customize-group' for groups). Some customizations only take effect
4787 after some action (read the NOTE in the option documentation).
4788 Customization can also be done globally (i.e. site-wide, read the
4789 INSTALL file).
4791 Not all options are described in this documentation, so go and see
4792 what other useful user options there are (`M-x vhdl-customize' or menu)!
4795 FILE EXTENSIONS:
4796 As default, files with extensions \".vhd\" and \".vhdl\" are
4797 automatically recognized as VHDL source files. To add an extension
4798 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4800 \(push '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist)
4803 HINTS:
4804 - To start Emacs with open VHDL hierarchy browser without having to load
4805 a VHDL file first, use the command:
4807 emacs -l vhdl-mode -f speedbar-frame-mode
4809 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4811 - Some features only work on properly indented code.
4814 RELEASE NOTES:
4815 See also the release notes (menu) for added features in new releases.
4818 Maintenance:
4819 ------------
4821 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4822 Add a description of the problem and include a reproducible test case.
4824 Questions and enhancement requests can be sent to <reto@gnu.org>.
4826 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4827 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4828 releases. You are kindly invited to participate in beta testing. Subscribe
4829 to above mailing lists by sending an email to <reto@gnu.org>.
4831 VHDL Mode is officially distributed at
4832 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4833 where the latest version can be found.
4836 Known problems:
4837 ---------------
4839 - XEmacs: Incorrect start-up when automatically opening speedbar.
4840 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4841 - Indentation incorrect for new 'postponed' VHDL keyword.
4842 - Indentation incorrect for 'protected body' construct.
4845 The VHDL Mode Authors
4846 Reto Zimmermann and Rod Whitby
4848 Key bindings:
4849 -------------
4851 \\{vhdl-mode-map}"
4852 :abbrev-table vhdl-mode-abbrev-table
4854 ;; set local variables
4855 (set (make-local-variable 'paragraph-start)
4856 "\\s-*\\(--+\\s-*$\\|$\\)")
4857 (set (make-local-variable 'paragraph-separate) paragraph-start)
4858 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4859 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4860 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4861 (set (make-local-variable 'comment-start) "--")
4862 (set (make-local-variable 'comment-end) "")
4863 (when vhdl-emacs-21
4864 (set (make-local-variable 'comment-padding) ""))
4865 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4866 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4867 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4868 (set (make-local-variable 'comment-multi-line) nil)
4869 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4870 (set (make-local-variable 'hippie-expand-verbose) nil)
4872 ;; setup the comment indent variable in a Emacs version portable way
4873 ;; ignore any byte compiler warnings you might get here
4874 (when (boundp 'comment-indent-function)
4875 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4877 ;; initialize font locking
4878 (set (make-local-variable 'font-lock-defaults)
4879 (list
4880 '(nil vhdl-font-lock-keywords) nil
4881 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4882 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4883 (set (make-local-variable 'syntax-propertize-function)
4884 (syntax-propertize-rules
4885 ;; Mark single quotes as having string quote syntax in
4886 ;; 'c' instances.
4887 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4888 (set (make-local-variable 'font-lock-syntactic-keywords)
4889 vhdl-font-lock-syntactic-keywords))
4890 (unless vhdl-emacs-21
4891 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4892 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4893 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4894 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4896 ;; variables for source file compilation
4897 (when vhdl-compile-use-local-error-regexp
4898 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4899 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4901 ;; add index menu
4902 (vhdl-index-menu-init)
4903 ;; add source file menu
4904 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4905 ;; add VHDL menu
4906 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4907 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4908 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4909 ;; initialize hideshow and add menu
4910 (vhdl-hideshow-init)
4911 (run-hooks 'menu-bar-update-hook)
4913 ;; miscellaneous
4914 (vhdl-ps-print-init)
4915 (vhdl-write-file-hooks-init)
4916 (message "VHDL Mode %s.%s" vhdl-version
4917 (if noninteractive "" " See menu for documentation and release notes.")))
4919 (defun vhdl-activate-customizations ()
4920 "Activate all customizations on local variables."
4921 (interactive)
4922 (vhdl-mode-map-init)
4923 (use-local-map vhdl-mode-map)
4924 (set-syntax-table vhdl-mode-syntax-table)
4925 (setq comment-column vhdl-inline-comment-column)
4926 (setq end-comment-column vhdl-end-comment-column)
4927 (vhdl-write-file-hooks-init)
4928 (vhdl-update-mode-menu)
4929 (vhdl-hideshow-init)
4930 (run-hooks 'menu-bar-update-hook))
4932 (defun vhdl-write-file-hooks-init ()
4933 "Add/remove hooks when buffer is saved."
4934 (if vhdl-modify-date-on-saving
4935 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4936 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4937 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4938 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4940 (defun vhdl-process-command-line-option (option)
4941 "Process command line options for VHDL Mode."
4942 (cond
4943 ;; set compiler
4944 ((equal option "-compiler")
4945 (vhdl-set-compiler (car command-line-args-left))
4946 (setq command-line-args-left (cdr command-line-args-left)))
4947 ;; set project
4948 ((equal option "-project")
4949 (vhdl-set-project (car command-line-args-left))
4950 (setq command-line-args-left (cdr command-line-args-left)))))
4952 ;; make Emacs process VHDL Mode options
4953 (setq command-switch-alist
4954 (append command-switch-alist
4955 '(("-compiler" . vhdl-process-command-line-option)
4956 ("-project" . vhdl-process-command-line-option))))
4959 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4960 ;;; Keywords and standardized words
4961 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4963 (defconst vhdl-02-keywords
4965 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4966 "assert" "attribute"
4967 "begin" "block" "body" "buffer" "bus"
4968 "case" "component" "configuration" "constant"
4969 "disconnect" "downto"
4970 "else" "elsif" "end" "entity" "exit"
4971 "file" "for" "function"
4972 "generate" "generic" "group" "guarded"
4973 "if" "impure" "in" "inertial" "inout" "is"
4974 "label" "library" "linkage" "literal" "loop"
4975 "map" "mod"
4976 "nand" "new" "next" "nor" "not" "null"
4977 "of" "on" "open" "or" "others" "out"
4978 "package" "port" "postponed" "procedure" "process" "protected" "pure"
4979 "range" "record" "register" "reject" "rem" "report" "return"
4980 "rol" "ror"
4981 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4982 "then" "to" "transport" "type"
4983 "unaffected" "units" "until" "use"
4984 "variable"
4985 "wait" "when" "while" "with"
4986 "xnor" "xor"
4988 "List of VHDL'02 keywords.")
4990 (defconst vhdl-ams-keywords
4992 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4993 "reference" "spectrum" "subnature" "terminal" "through"
4994 "tolerance"
4996 "List of VHDL-AMS keywords.")
4998 (defconst vhdl-verilog-keywords
5000 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
5001 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
5002 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
5003 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
5004 "endprimitive" "endspecify" "endtable" "endtask" "event"
5005 "for" "force" "forever" "fork" "function"
5006 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
5007 "macromodule" "makefile" "medium" "module"
5008 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
5009 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
5010 "pullup"
5011 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
5012 "rtranif0" "rtranif1"
5013 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
5014 "strong1" "supply" "supply0" "supply1"
5015 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5016 "triand" "trior" "trireg"
5017 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
5019 "List of Verilog keywords as candidate for additional reserved words.")
5021 (defconst vhdl-02-types
5023 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
5024 "real" "time" "natural" "positive" "string" "line" "text" "side"
5025 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
5026 "std_logic" "std_logic_vector"
5027 "std_ulogic" "std_ulogic_vector"
5029 "List of VHDL'02 standardized types.")
5031 (defconst vhdl-ams-types
5032 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5034 ;; package `standard'
5035 "domain_type" "real_vector"
5036 ;; package `energy_systems'
5037 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5038 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5039 "real_across_vector" "real_through_vector"
5040 ;; package `electrical_systems'
5041 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5042 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5043 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5044 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5045 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5046 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5047 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5048 "electric_flux_density_vector" "electric_field_strength_vector"
5049 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5050 "inductance_vector" "reluctance_vector" "ground"
5051 ;; package `mechanical_systems'
5052 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5053 "damping" "momentum" "angle" "torque" "angular_velocity"
5054 "angular_acceleration" "moment_inertia" "angular_momentum"
5055 "angular_stiffness" "angular_damping" "translational"
5056 "translational_vector" "translational_velocity"
5057 "translational_velocity_vector" "rotational" "rotational_vector"
5058 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5059 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5060 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5061 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5062 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5063 "angular_momentum_vector" "angular_stiffness_vector"
5064 "angular_damping_vector" "anchor" "translational_v_ref"
5065 "rotational_v_ref" "translational_v" "rotational_v"
5066 ;; package `radiant_systems'
5067 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5068 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5069 "illuminance_vector" "irradiance_vector"
5070 ;; package `thermal_systems'
5071 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5072 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5073 "heat_flow_vector" "thermal_capacitance_vector"
5074 "thermal_resistance_vector" "thermal_conductance_vector"
5075 ;; package `fluidic_systems'
5076 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5077 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5078 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5079 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5080 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5081 "density_vector" "viscosity_vector" "fresistance_vector"
5082 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5083 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5084 "cfinertance_vector"
5086 "List of VHDL-AMS standardized types.")
5088 (defconst vhdl-math-types
5090 "complex" "complex_polar" "positive_real" "principal_value"
5092 "List of Math Packages standardized types.")
5094 (defconst vhdl-02-attributes
5096 "base" "left" "right" "high" "low" "pos" "val" "succ"
5097 "pred" "leftof" "rightof" "range" "reverse_range"
5098 "length" "delayed" "stable" "quiet" "transaction"
5099 "event" "active" "last_event" "last_active" "last_value"
5100 "driving" "driving_value" "ascending" "value" "image"
5101 "simple_name" "instance_name" "path_name"
5102 "foreign"
5104 "List of VHDL'02 standardized attributes.")
5106 (defconst vhdl-ams-attributes
5108 "across" "through"
5109 "reference" "contribution" "tolerance"
5110 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5111 "ramp" "slew"
5113 "List of VHDL-AMS standardized attributes.")
5115 (defconst vhdl-02-enum-values
5117 "true" "false"
5118 "note" "warning" "error" "failure"
5119 "read_mode" "write_mode" "append_mode"
5120 "open_ok" "status_error" "name_error" "mode_error"
5121 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5122 "right" "left"
5124 "List of VHDL'02 standardized enumeration values.")
5126 (defconst vhdl-ams-enum-values
5128 "quiescent_domain" "time_domain" "frequency_domain"
5129 ;; from `nature_pkg' package
5130 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5132 "List of VHDL-AMS standardized enumeration values.")
5134 (defconst vhdl-ams-constants
5135 ;; standard: IEEE Std 1076.1.1-2004
5137 ;; package `fundamental_constants'
5138 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5139 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5140 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5141 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5142 ;; package `material_constants'
5143 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5144 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5145 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5147 "List of VHDL-AMS standardized constants.")
5149 (defconst vhdl-math-constants
5150 ;; standard: IEEE Std 1076.2-1996
5152 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5153 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5154 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5155 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5156 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5157 "math_sqrt_pi"
5159 "List of Math Packages standardized constants.")
5161 (defconst vhdl-02-functions
5163 "now" "resolved" "rising_edge" "falling_edge"
5164 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5165 "endfile"
5166 "resize" "is_X" "std_match"
5167 "shift_left" "shift_right" "rotate_left" "rotate_right"
5168 "to_unsigned" "to_signed" "to_integer"
5169 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5170 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5171 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5172 "shl" "shr" "ext" "sxt"
5173 "deallocate"
5175 "List of VHDL'02 standardized functions.")
5177 (defconst vhdl-ams-functions
5179 ;; package `standard'
5180 "frequency"
5182 "List of VHDL-AMS standardized functions.")
5184 (defconst vhdl-math-functions
5185 ;; standard: IEEE Std 1076.2-1996
5187 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5188 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5189 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5190 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5191 "tan" "tanh" "trunc" "uniform"
5193 "List of Math Packages standardized functions.")
5195 (defconst vhdl-02-packages
5197 "std_logic_1164" "numeric_std" "numeric_bit"
5198 "standard" "textio"
5199 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5200 "std_logic_misc" "std_logic_textio"
5201 "ieee" "std" "work"
5203 "List of VHDL'02 standardized packages and libraries.")
5205 (defconst vhdl-ams-packages
5207 "fundamental_constants" "material_constants" "energy_systems"
5208 "electrical_systems" "mechanical_systems" "radiant_systems"
5209 "thermal_systems" "fluidic_systems"
5211 "List of VHDL-AMS standardized packages and libraries.")
5213 (defconst vhdl-math-packages
5215 "math_real" "math_complex"
5217 "List of Math Packages standardized packages and libraries.")
5219 (defvar vhdl-keywords nil
5220 "List of VHDL keywords.")
5222 (defvar vhdl-types nil
5223 "List of VHDL standardized types.")
5225 (defvar vhdl-attributes nil
5226 "List of VHDL standardized attributes.")
5228 (defvar vhdl-enum-values nil
5229 "List of VHDL standardized enumeration values.")
5231 (defvar vhdl-constants nil
5232 "List of VHDL standardized constants.")
5234 (defvar vhdl-functions nil
5235 "List of VHDL standardized functions.")
5237 (defvar vhdl-packages nil
5238 "List of VHDL standardized packages and libraries.")
5240 (defvar vhdl-reserved-words nil
5241 "List of additional reserved words.")
5243 (defvar vhdl-keywords-regexp nil
5244 "Regexp for VHDL keywords.")
5246 (defvar vhdl-types-regexp nil
5247 "Regexp for VHDL standardized types.")
5249 (defvar vhdl-attributes-regexp nil
5250 "Regexp for VHDL standardized attributes.")
5252 (defvar vhdl-enum-values-regexp nil
5253 "Regexp for VHDL standardized enumeration values.")
5255 (defvar vhdl-constants-regexp nil
5256 "Regexp for VHDL standardized constants.")
5258 (defvar vhdl-functions-regexp nil
5259 "Regexp for VHDL standardized functions.")
5261 (defvar vhdl-packages-regexp nil
5262 "Regexp for VHDL standardized packages and libraries.")
5264 (defvar vhdl-reserved-words-regexp nil
5265 "Regexp for additional reserved words.")
5267 (defvar vhdl-directive-keywords-regexp nil
5268 "Regexp for compiler directive keywords.")
5270 (defun vhdl-upcase-list (condition list)
5271 "Upcase all elements in LIST based on CONDITION."
5272 (when condition
5273 (let ((tmp-list list))
5274 (while tmp-list
5275 (setcar tmp-list (upcase (car tmp-list)))
5276 (setq tmp-list (cdr tmp-list)))))
5277 list)
5279 (defun vhdl-words-init ()
5280 "Initialize reserved words."
5281 (setq vhdl-keywords
5282 (vhdl-upcase-list
5283 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5284 (append vhdl-02-keywords
5285 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5286 (setq vhdl-types
5287 (vhdl-upcase-list
5288 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5289 (append vhdl-02-types
5290 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5291 (when (vhdl-standard-p 'math) vhdl-math-types))))
5292 (setq vhdl-attributes
5293 (vhdl-upcase-list
5294 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5295 (append vhdl-02-attributes
5296 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5297 (setq vhdl-enum-values
5298 (vhdl-upcase-list
5299 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5300 (append vhdl-02-enum-values
5301 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5302 (setq vhdl-constants
5303 (vhdl-upcase-list
5304 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5305 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5306 (when (vhdl-standard-p 'math) vhdl-math-constants)
5307 '(""))))
5308 (setq vhdl-functions
5309 (append vhdl-02-functions
5310 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5311 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5312 (setq vhdl-packages
5313 (append vhdl-02-packages
5314 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5315 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5316 (setq vhdl-reserved-words
5317 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5318 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5319 '("")))
5320 (setq vhdl-keywords-regexp
5321 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5322 (setq vhdl-types-regexp
5323 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5324 (setq vhdl-attributes-regexp
5325 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5326 (setq vhdl-enum-values-regexp
5327 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5328 (setq vhdl-constants-regexp
5329 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5330 (setq vhdl-functions-regexp
5331 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5332 (setq vhdl-packages-regexp
5333 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5334 (setq vhdl-reserved-words-regexp
5335 (concat "\\<\\("
5336 (unless (equal vhdl-forbidden-syntax "")
5337 (concat vhdl-forbidden-syntax "\\|"))
5338 (regexp-opt vhdl-reserved-words)
5339 "\\)\\>"))
5340 (setq vhdl-directive-keywords-regexp
5341 (concat "\\<\\(" (mapconcat 'regexp-quote
5342 vhdl-directive-keywords "\\|") "\\)\\>"))
5343 (vhdl-abbrev-list-init))
5345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5346 ;; Words to expand
5348 (defvar vhdl-abbrev-list nil
5349 "Predefined abbreviations for VHDL.")
5351 (defun vhdl-abbrev-list-init ()
5352 (setq vhdl-abbrev-list
5353 (append
5354 (list vhdl-upper-case-keywords) vhdl-keywords
5355 (list vhdl-upper-case-types) vhdl-types
5356 (list vhdl-upper-case-attributes) vhdl-attributes
5357 (list vhdl-upper-case-enum-values) vhdl-enum-values
5358 (list vhdl-upper-case-constants) vhdl-constants
5359 (list nil) vhdl-functions
5360 (list nil) vhdl-packages)))
5362 ;; initialize reserved words for VHDL Mode
5363 (vhdl-words-init)
5366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5367 ;;; Indentation
5368 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5371 ;; Syntax analysis
5373 ;; constant regular expressions for looking at various constructs
5375 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5376 "Regexp describing a VHDL symbol.
5377 We cannot use just `word' syntax class since `_' cannot be in word
5378 class. Putting underscore in word class breaks forward word movement
5379 behavior that users are familiar with.")
5381 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5382 "Regexp describing a case statement header key.")
5384 (defconst vhdl-label-key
5385 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5386 "Regexp describing a VHDL label.")
5388 ;; Macro definitions:
5390 (defmacro vhdl-point (position)
5391 "Return the value of point at certain commonly referenced POSITIONs.
5392 POSITION can be one of the following symbols:
5394 bol -- beginning of line
5395 eol -- end of line
5396 bod -- beginning of defun
5397 boi -- back to indentation
5398 eoi -- last whitespace on line
5399 ionl -- indentation of next line
5400 iopl -- indentation of previous line
5401 bonl -- beginning of next line
5402 bopl -- beginning of previous line
5404 This function does not modify point or mark."
5405 (or (and (eq 'quote (car-safe position))
5406 (null (cddr position)))
5407 (error "ERROR: Bad buffer position requested: %s" position))
5408 (setq position (nth 1 position))
5409 `(let ((here (point)))
5410 ,@(cond
5411 ((eq position 'bol) '((beginning-of-line)))
5412 ((eq position 'eol) '((end-of-line)))
5413 ((eq position 'bod) '((save-match-data
5414 (vhdl-beginning-of-defun))))
5415 ((eq position 'boi) '((back-to-indentation)))
5416 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5417 ((eq position 'bonl) '((forward-line 1)))
5418 ((eq position 'bopl) '((forward-line -1)))
5419 ((eq position 'iopl)
5420 '((forward-line -1)
5421 (back-to-indentation)))
5422 ((eq position 'ionl)
5423 '((forward-line 1)
5424 (back-to-indentation)))
5425 (t (error "ERROR: Unknown buffer position requested: %s" position))
5427 (prog1
5428 (point)
5429 (goto-char here))
5430 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5431 ;; doesn't hurt for v19
5432 ,@nil
5435 (defmacro vhdl-safe (&rest body)
5436 "Safely execute BODY, return nil if an error occurred."
5437 `(condition-case nil
5438 (progn ,@body)
5439 (error nil)))
5441 (defmacro vhdl-add-syntax (symbol &optional relpos)
5442 "A simple macro to append the syntax in SYMBOL to the syntax list.
5443 Try to increase performance by using this macro."
5444 `(setq vhdl-syntactic-context
5445 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5447 (defmacro vhdl-has-syntax (symbol)
5448 "A simple macro to return check the syntax list.
5449 Try to increase performance by using this macro."
5450 `(assoc ,symbol vhdl-syntactic-context))
5452 ;; Syntactic element offset manipulation:
5454 (defun vhdl-read-offset (langelem)
5455 "Read new offset value for LANGELEM from minibuffer.
5456 Return a valid value only."
5457 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5458 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5459 (prompt "Offset: ")
5460 offset input interned)
5461 (while (not offset)
5462 (setq input (read-string prompt oldoff)
5463 offset (cond ((string-equal "+" input) '+)
5464 ((string-equal "-" input) '-)
5465 ((string-equal "++" input) '++)
5466 ((string-equal "--" input) '--)
5467 ((string-match "^-?[0-9]+$" input)
5468 (string-to-number input))
5469 ((fboundp (setq interned (intern input)))
5470 interned)
5471 ((boundp interned) interned)
5472 ;; error, but don't signal one, keep trying
5473 ;; to read an input value
5474 (t (ding)
5475 (setq prompt errmsg)
5476 nil))))
5477 offset))
5479 (defun vhdl-set-offset (symbol offset &optional add-p)
5480 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5481 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5482 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5483 `vhdl-offsets-alist' if it doesn't already appear there."
5484 (interactive
5485 (let* ((langelem
5486 (intern (completing-read
5487 (concat "Syntactic symbol to change"
5488 (if current-prefix-arg " or add" "")
5489 ": ")
5490 (mapcar
5491 (function
5492 (lambda (langelem)
5493 (cons (format "%s" (car langelem)) nil)))
5494 vhdl-offsets-alist)
5495 nil (not current-prefix-arg)
5496 ;; initial contents tries to be the last element
5497 ;; on the syntactic analysis list for the current
5498 ;; line
5499 (let* ((syntax (vhdl-get-syntactic-context))
5500 (len (length syntax))
5501 (ic (format "%s" (car (nth (1- len) syntax)))))
5504 (offset (vhdl-read-offset langelem)))
5505 (list langelem offset current-prefix-arg)))
5506 ;; sanity check offset
5507 (or (eq offset '+)
5508 (eq offset '-)
5509 (eq offset '++)
5510 (eq offset '--)
5511 (integerp offset)
5512 (fboundp offset)
5513 (boundp offset)
5514 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5515 offset))
5516 (let ((entry (assq symbol vhdl-offsets-alist)))
5517 (if entry
5518 (setcdr entry offset)
5519 (if add-p
5520 (setq vhdl-offsets-alist
5521 (cons (cons symbol offset) vhdl-offsets-alist))
5522 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5523 (vhdl-keep-region-active))
5525 (defun vhdl-set-style (style &optional local)
5526 "Set `vhdl-mode' variables to use one of several different indentation styles.
5527 STYLE is a string representing the desired style and optional LOCAL is
5528 a flag which, if non-nil, means to make the style variables being
5529 changed buffer local, instead of the default, which is to set the
5530 global variables. Interactively, the flag comes from the prefix
5531 argument. The styles are chosen from the `vhdl-style-alist' variable."
5532 (interactive (list (completing-read "Use which VHDL indentation style? "
5533 vhdl-style-alist nil t)
5534 current-prefix-arg))
5535 (let ((vars (cdr (assoc style vhdl-style-alist))))
5536 (or vars
5537 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5538 ;; set all the variables
5539 (mapc
5540 (function
5541 (lambda (varentry)
5542 (let ((var (car varentry))
5543 (val (cdr varentry)))
5544 ;; special case for vhdl-offsets-alist
5545 (if (not (eq var 'vhdl-offsets-alist))
5546 (set (if local (make-local-variable var) var) val)
5547 ;; reset vhdl-offsets-alist to the default value first
5548 (set (if local (make-local-variable var) var)
5549 (copy-alist vhdl-offsets-alist-default))
5550 ;; now set the langelems that are different
5551 (mapcar
5552 (function
5553 (lambda (langentry)
5554 (let ((langelem (car langentry))
5555 (offset (cdr langentry)))
5556 (vhdl-set-offset langelem offset)
5558 val))
5560 vars))
5561 (vhdl-keep-region-active))
5563 (defun vhdl-get-offset (langelem)
5564 "Get offset from LANGELEM which is a cons cell of the form:
5565 \(SYMBOL . RELPOS). The symbol is matched against
5566 vhdl-offsets-alist and the offset found there is either returned,
5567 or added to the indentation at RELPOS. If RELPOS is nil, then
5568 the offset is simply returned."
5569 (let* ((symbol (car langelem))
5570 (relpos (cdr langelem))
5571 (match (assq symbol vhdl-offsets-alist))
5572 (offset (cdr-safe match)))
5573 ;; offset can be a number, a function, a variable, or one of the
5574 ;; symbols + or -
5575 (cond
5576 ((not match)
5577 (if vhdl-strict-syntax-p
5578 (error "ERROR: Don't know how to indent a %s" symbol)
5579 (setq offset 0
5580 relpos 0)))
5581 ((eq offset '+) (setq offset vhdl-basic-offset))
5582 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5583 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5584 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5585 ((and (not (numberp offset))
5586 (fboundp offset))
5587 (setq offset (funcall offset langelem)))
5588 ((not (numberp offset))
5589 (setq offset (eval offset)))
5591 (+ (if (and relpos
5592 (< relpos (vhdl-point 'bol)))
5593 (save-excursion
5594 (goto-char relpos)
5595 (current-column))
5597 offset)))
5599 ;; Syntactic support functions:
5601 (defun vhdl-in-comment-p ()
5602 "Check if point is in a comment."
5603 (eq (vhdl-in-literal) 'comment))
5605 (defun vhdl-in-string-p ()
5606 "Check if point is in a string."
5607 (eq (vhdl-in-literal) 'string))
5609 (defun vhdl-in-quote-p ()
5610 "Check if point is in a quote ('x')."
5611 (or (and (> (point) (point-min))
5612 (< (1+ (point)) (point-max))
5613 (= (char-before (point)) ?\')
5614 (= (char-after (1+ (point))) ?\'))
5615 (and (> (1- (point)) (point-min))
5616 (< (point) (point-max))
5617 (= (char-before (1- (point))) ?\')
5618 (= (char-after (point)) ?\'))))
5620 (defun vhdl-in-literal ()
5621 "Determine if point is in a VHDL literal."
5622 (save-excursion
5623 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5624 (cond
5625 ((nth 3 state) 'string)
5626 ((nth 4 state) 'comment)
5627 ((vhdl-beginning-of-macro) 'pound)
5628 (t nil)))))
5630 (defun vhdl-in-extended-identifier-p ()
5631 "Determine if point is inside extended identifier (delimited by '\')."
5632 (save-match-data
5633 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5634 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5636 (defun vhdl-forward-comment (&optional direction)
5637 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5638 negative, skip forward otherwise."
5639 (interactive "p")
5640 (if (and direction (< direction 0))
5641 ;; skip backwards
5642 (progn
5643 (skip-chars-backward " \t\n\r\f")
5644 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5645 (goto-char (match-beginning 3))
5646 (skip-chars-backward " \t\n\r\f")))
5647 ;; skip forwards
5648 (skip-chars-forward " \t\n\r\f")
5649 (while (looking-at "--.*")
5650 (goto-char (match-end 0))
5651 (skip-chars-forward " \t\n\r\f"))))
5653 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5654 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5655 (defalias 'vhdl-forward-comment 'forward-comment))
5657 (defun vhdl-back-to-indentation ()
5658 "Move point to the first non-whitespace character on this line."
5659 (interactive)
5660 (beginning-of-line 1)
5661 (skip-syntax-forward " " (vhdl-point 'eol)))
5663 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5664 (when (featurep 'xemacs)
5665 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5667 ;; This is the best we can do in Win-Emacs.
5668 (defun vhdl-win-il (&optional lim)
5669 "Determine if point is in a VHDL literal."
5670 (save-excursion
5671 (let* ((here (point))
5672 (state nil)
5673 (match nil)
5674 (lim (or lim (vhdl-point 'bod))))
5675 (goto-char lim )
5676 (while (< (point) here)
5677 (setq match
5678 (and (re-search-forward "--\\|[\"']"
5679 here 'move)
5680 (buffer-substring (match-beginning 0) (match-end 0))))
5681 (setq state
5682 (cond
5683 ;; no match
5684 ((null match) nil)
5685 ;; looking at the opening of a VHDL style comment
5686 ((string= "--" match)
5687 (if (<= here (progn (end-of-line) (point))) 'comment))
5688 ;; looking at the opening of a double quote string
5689 ((string= "\"" match)
5690 (if (not (save-restriction
5691 ;; this seems to be necessary since the
5692 ;; re-search-forward will not work without it
5693 (narrow-to-region (point) here)
5694 (re-search-forward
5695 ;; this regexp matches a double quote
5696 ;; which is preceded by an even number
5697 ;; of backslashes, including zero
5698 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5699 'string))
5700 ;; looking at the opening of a single quote string
5701 ((string= "'" match)
5702 (if (not (save-restriction
5703 ;; see comments from above
5704 (narrow-to-region (point) here)
5705 (re-search-forward
5706 ;; this matches a single quote which is
5707 ;; preceded by zero or two backslashes.
5708 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5709 here 'move)))
5710 'string))
5711 (t nil)))
5712 ) ; end-while
5713 state)))
5715 (and (string-match "Win-Emacs" emacs-version)
5716 (fset 'vhdl-in-literal 'vhdl-win-il))
5718 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5719 ;; defined as lexical whitespace or comments. Search no farther back
5720 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5721 ;; used for backward skipping, (point-max) is used for forward
5722 ;; skipping.
5724 (defun vhdl-forward-syntactic-ws (&optional lim)
5725 "Forward skip of syntactic whitespace."
5726 (let* ((here (point-max))
5727 (hugenum (point-max)))
5728 (while (/= here (point))
5729 (setq here (point))
5730 (vhdl-forward-comment hugenum)
5731 ;; skip preprocessor directives
5732 (when (and (eq (char-after) ?#)
5733 (= (vhdl-point 'boi) (point)))
5734 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5735 (= (forward-line 1) 0)))
5736 (end-of-line)))
5737 (if lim (goto-char (min (point) lim)))))
5740 ;; This is the best we can do in Win-Emacs.
5741 (defun vhdl-win-fsws (&optional lim)
5742 "Forward skip syntactic whitespace for Win-Emacs."
5743 (let ((lim (or lim (point-max)))
5744 stop)
5745 (while (not stop)
5746 (skip-chars-forward " \t\n\r\f" lim)
5747 (cond
5748 ;; vhdl comment
5749 ((looking-at "--") (end-of-line))
5750 ;; none of the above
5751 (t (setq stop t))))))
5753 (and (string-match "Win-Emacs" emacs-version)
5754 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5756 (defun vhdl-beginning-of-macro (&optional lim)
5757 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5758 (let ((here (point)))
5759 (beginning-of-line)
5760 (while (eq (char-before (1- (point))) ?\\)
5761 (forward-line -1))
5762 (back-to-indentation)
5763 (if (and (<= (point) here)
5764 (eq (char-after) ?#))
5766 (goto-char here)
5767 nil)))
5769 (defun vhdl-backward-syntactic-ws (&optional lim)
5770 "Backward skip over syntactic whitespace."
5771 (let* ((here (point-min))
5772 (hugenum (- (point-max))))
5773 (while (/= here (point))
5774 (setq here (point))
5775 (vhdl-forward-comment hugenum)
5776 (vhdl-beginning-of-macro))
5777 (if lim (goto-char (max (point) lim)))))
5779 ;; This is the best we can do in Win-Emacs.
5780 (defun vhdl-win-bsws (&optional lim)
5781 "Backward skip syntactic whitespace for Win-Emacs."
5782 (let ((lim (or lim (vhdl-point 'bod)))
5783 stop)
5784 (while (not stop)
5785 (skip-chars-backward " \t\n\r\f" lim)
5786 (cond
5787 ;; vhdl comment
5788 ((eq (vhdl-in-literal) 'comment)
5789 (skip-chars-backward "^-" lim)
5790 (skip-chars-backward "-" lim)
5791 (while (not (or (and (= (following-char) ?-)
5792 (= (char-after (1+ (point))) ?-))
5793 (<= (point) lim)))
5794 (skip-chars-backward "^-" lim)
5795 (skip-chars-backward "-" lim)))
5796 ;; none of the above
5797 (t (setq stop t))))))
5799 (and (string-match "Win-Emacs" emacs-version)
5800 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5802 ;; Functions to help finding the correct indentation column:
5804 (defun vhdl-first-word (point)
5805 "If the keyword at POINT is at boi, then return (current-column) at
5806 that point, else nil."
5807 (save-excursion
5808 (and (goto-char point)
5809 (eq (point) (vhdl-point 'boi))
5810 (current-column))))
5812 (defun vhdl-last-word (point)
5813 "If the keyword at POINT is at eoi, then return (current-column) at
5814 that point, else nil."
5815 (save-excursion
5816 (and (goto-char point)
5817 (save-excursion (or (eq (progn (forward-sexp) (point))
5818 (vhdl-point 'eoi))
5819 (looking-at "\\s-*\\(--\\)?")))
5820 (current-column))))
5822 ;; Core syntactic evaluation functions:
5824 (defconst vhdl-libunit-re
5825 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5827 (defun vhdl-libunit-p ()
5828 (and
5829 (save-excursion
5830 (forward-sexp)
5831 (skip-chars-forward " \t\n\r\f")
5832 (not (looking-at "is\\b[^_]")))
5833 (save-excursion
5834 (backward-sexp)
5835 (and (not (looking-at "use\\b[^_]"))
5836 (progn
5837 (forward-sexp)
5838 (vhdl-forward-syntactic-ws)
5839 (/= (following-char) ?:))))
5842 (defconst vhdl-defun-re
5843 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5845 (defun vhdl-defun-p ()
5846 (save-excursion
5847 (if (looking-at "block\\|process\\|procedural")
5848 ;; "block", "process", "procedural":
5849 (save-excursion
5850 (backward-sexp)
5851 (not (looking-at "end\\s-+\\w")))
5852 ;; "architecture", "configuration", "entity",
5853 ;; "package", "procedure", "function":
5854 t)))
5856 (defun vhdl-corresponding-defun ()
5857 "If the word at the current position corresponds to a \"defun\"
5858 keyword, then return a string that can be used to find the
5859 corresponding \"begin\" keyword, else return nil."
5860 (save-excursion
5861 (and (looking-at vhdl-defun-re)
5862 (vhdl-defun-p)
5863 (if (looking-at "block\\|process\\|procedural")
5864 ;; "block", "process". "procedural:
5865 (buffer-substring (match-beginning 0) (match-end 0))
5866 ;; "architecture", "configuration", "entity", "package",
5867 ;; "procedure", "function":
5868 "is"))))
5870 (defconst vhdl-begin-fwd-re
5871 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5872 "A regular expression for searching forward that matches all known
5873 \"begin\" keywords.")
5875 (defconst vhdl-begin-bwd-re
5876 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5877 "A regular expression for searching backward that matches all known
5878 \"begin\" keywords.")
5880 (defun vhdl-begin-p (&optional lim)
5881 "Return t if we are looking at a real \"begin\" keyword.
5882 Assumes that the caller will make sure that we are looking at
5883 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5884 the middle of an identifier that just happens to contain a \"begin\"
5885 keyword."
5886 (cond
5887 ;; "[architecture|case|configuration|entity|package|
5888 ;; procedure|function] ... is":
5889 ((and (looking-at "i")
5890 (save-excursion
5891 ;; Skip backward over first sexp (needed to skip over a
5892 ;; procedure interface list, and is harmless in other
5893 ;; situations). Note that we need "return" in the
5894 ;; following search list so that we don't run into
5895 ;; semicolons in the function interface list.
5896 (backward-sexp)
5897 (let (foundp)
5898 (while (and (not foundp)
5899 (re-search-backward
5900 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5901 lim 'move))
5902 (if (or (= (preceding-char) ?_)
5903 (vhdl-in-literal))
5904 (backward-char)
5905 (setq foundp t))))
5906 (and (/= (following-char) ?\;)
5907 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5909 ;; "begin", "then", "use":
5910 ((looking-at "be\\|t\\|use")
5912 ;; "else":
5913 ((and (looking-at "e")
5914 ;; make sure that the "else" isn't inside a
5915 ;; conditional signal assignment.
5916 (save-excursion
5917 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5918 (or (eq (following-char) ?\;)
5919 (eq (point) lim))))
5921 ;; "block", "generate", "loop", "process", "procedural",
5922 ;; "units", "record", "protected body":
5923 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
5924 (save-excursion
5925 (backward-sexp)
5926 (not (looking-at "end\\s-+\\w"))))
5928 ;; "component":
5929 ((and (looking-at "c")
5930 (save-excursion
5931 (backward-sexp)
5932 (not (looking-at "end\\s-+\\w")))
5933 ;; look out for the dreaded entity class in an attribute
5934 (save-excursion
5935 (vhdl-backward-syntactic-ws lim)
5936 (/= (preceding-char) ?:)))
5938 ;; "for" (inside configuration declaration):
5939 ((and (looking-at "f")
5940 (save-excursion
5941 (backward-sexp)
5942 (not (looking-at "end\\s-+\\w")))
5943 (vhdl-has-syntax 'configuration))
5947 (defun vhdl-corresponding-mid (&optional lim)
5948 (cond
5949 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5950 "begin")
5951 ((looking-at "then\\|use")
5952 "<else>")
5954 "end")))
5956 (defun vhdl-corresponding-end (&optional lim)
5957 "If the word at the current position corresponds to a \"begin\"
5958 keyword, then return a vector containing enough information to find
5959 the corresponding \"end\" keyword, else return nil. The keyword to
5960 search forward for is aref 0. The column in which the keyword must
5961 appear is aref 1 or nil if any column is suitable.
5962 Assumes that the caller will make sure that we are not in the middle
5963 of an identifier that just happens to contain a \"begin\" keyword."
5964 (save-excursion
5965 (and (looking-at vhdl-begin-fwd-re)
5966 (or (not (looking-at "\\<use\\>"))
5967 (save-excursion (back-to-indentation)
5968 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
5969 (/= (preceding-char) ?_)
5970 (not (vhdl-in-literal))
5971 (vhdl-begin-p lim)
5972 (cond
5973 ;; "is", "generate", "loop":
5974 ((looking-at "[igl]")
5975 (vector "end"
5976 (and (vhdl-last-word (point))
5977 (or (vhdl-first-word (point))
5978 (save-excursion
5979 (vhdl-beginning-of-statement-1 lim)
5980 (vhdl-backward-skip-label lim)
5981 (vhdl-first-word (point)))))))
5982 ;; "begin", "else", "for":
5983 ((looking-at "be\\|[ef]")
5984 (vector "end"
5985 (and (vhdl-last-word (point))
5986 (or (vhdl-first-word (point))
5987 (save-excursion
5988 (vhdl-beginning-of-statement-1 lim)
5989 (vhdl-backward-skip-label lim)
5990 (vhdl-first-word (point)))))))
5991 ;; "component", "units", "record", "protected body":
5992 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
5993 ;; The first end found will close the block
5994 (vector "end" nil))
5995 ;; "block", "process", "procedural":
5996 ((looking-at "bl\\|p")
5997 (vector "end"
5998 (or (vhdl-first-word (point))
5999 (save-excursion
6000 (vhdl-beginning-of-statement-1 lim)
6001 (vhdl-backward-skip-label lim)
6002 (vhdl-first-word (point))))))
6003 ;; "then":
6004 ((looking-at "t\\|use")
6005 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
6006 (and (vhdl-last-word (point))
6007 (or (vhdl-first-word (point))
6008 (save-excursion
6009 (vhdl-beginning-of-statement-1 lim)
6010 (vhdl-backward-skip-label lim)
6011 (vhdl-first-word (point)))))))
6012 ))))
6014 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
6016 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
6018 (defun vhdl-end-p (&optional lim)
6019 "Return t if we are looking at a real \"end\" keyword.
6020 Assumes that the caller will make sure that we are looking at
6021 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
6022 the middle of an identifier that just happens to contain an \"end\"
6023 keyword."
6024 (or (not (looking-at "else"))
6025 ;; make sure that the "else" isn't inside a conditional signal
6026 ;; assignment.
6027 (save-excursion
6028 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6029 (or (eq (following-char) ?\;)
6030 (eq (point) lim)
6031 (vhdl-in-literal)))))
6033 (defun vhdl-corresponding-begin (&optional lim)
6034 "If the word at the current position corresponds to an \"end\"
6035 keyword, then return a vector containing enough information to find
6036 the corresponding \"begin\" keyword, else return nil. The keyword to
6037 search backward for is aref 0. The column in which the keyword must
6038 appear is aref 1 or nil if any column is suitable. The supplementary
6039 keyword to search forward for is aref 2 or nil if this is not
6040 required. If aref 3 is t, then the \"begin\" keyword may be found in
6041 the middle of a statement.
6042 Assumes that the caller will make sure that we are not in the middle
6043 of an identifier that just happens to contain an \"end\" keyword."
6044 (save-excursion
6045 (let (pos)
6046 (if (and (looking-at vhdl-end-fwd-re)
6047 (not (vhdl-in-literal))
6048 (vhdl-end-p lim))
6049 (if (looking-at "el")
6050 ;; "else", "elsif":
6051 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
6052 ;; "end ...":
6053 (setq pos (point))
6054 (forward-sexp)
6055 (skip-chars-forward " \t\n\r\f")
6056 (cond
6057 ;; "end if":
6058 ((looking-at "if\\b[^_]")
6059 (vector "else\\|elsif\\|if"
6060 (vhdl-first-word pos)
6061 "else\\|then\\|use" nil))
6062 ;; "end component":
6063 ((looking-at "component\\b[^_]")
6064 (vector (buffer-substring (match-beginning 1)
6065 (match-end 1))
6066 (vhdl-first-word pos)
6067 nil nil))
6068 ;; "end units", "end record", "end protected":
6069 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6070 (vector (buffer-substring (match-beginning 1)
6071 (match-end 1))
6072 (vhdl-first-word pos)
6073 nil t))
6074 ;; "end block", "end process", "end procedural":
6075 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6076 (vector "begin" (vhdl-first-word pos) nil nil))
6077 ;; "end case":
6078 ((looking-at "case\\b[^_]")
6079 (vector "case" (vhdl-first-word pos) "is" nil))
6080 ;; "end generate":
6081 ((looking-at "generate\\b[^_]")
6082 (vector "generate\\|for\\|if"
6083 (vhdl-first-word pos)
6084 "generate" nil))
6085 ;; "end loop":
6086 ((looking-at "loop\\b[^_]")
6087 (vector "loop\\|while\\|for"
6088 (vhdl-first-word pos)
6089 "loop" nil))
6090 ;; "end for" (inside configuration declaration):
6091 ((looking-at "for\\b[^_]")
6092 (vector "for" (vhdl-first-word pos) nil nil))
6093 ;; "end [id]":
6095 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
6096 (vhdl-first-word pos)
6097 ;; return an alist of (statement . keyword) mappings
6099 ;; "begin ... end [id]":
6100 ("begin" . nil)
6101 ;; "architecture ... is ... begin ... end [id]":
6102 ("architecture" . "is")
6103 ;; "configuration ... is ... end [id]":
6104 ("configuration" . "is")
6105 ;; "entity ... is ... end [id]":
6106 ("entity" . "is")
6107 ;; "package ... is ... end [id]":
6108 ("package" . "is")
6109 ;; "procedure ... is ... begin ... end [id]":
6110 ("procedure" . "is")
6111 ;; "function ... is ... begin ... end [id]":
6112 ("function" . "is")
6114 nil))
6115 ))) ; "end ..."
6118 (defconst vhdl-leader-re
6119 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6121 (defun vhdl-end-of-leader ()
6122 (save-excursion
6123 (cond ((looking-at "block\\|process\\|procedural")
6124 (if (save-excursion
6125 (forward-sexp)
6126 (skip-chars-forward " \t\n\r\f")
6127 (= (following-char) ?\())
6128 (forward-sexp 2)
6129 (forward-sexp))
6130 (when (looking-at "[ \t\n\r\f]*is")
6131 (goto-char (match-end 0)))
6132 (point))
6133 ((looking-at "component")
6134 (forward-sexp 2)
6135 (when (looking-at "[ \t\n\r\f]*is")
6136 (goto-char (match-end 0)))
6137 (point))
6138 ((looking-at "for")
6139 (forward-sexp 2)
6140 (skip-chars-forward " \t\n\r\f")
6141 (while (looking-at "[,:(]")
6142 (forward-sexp)
6143 (skip-chars-forward " \t\n\r\f"))
6144 (point))
6145 (t nil)
6148 (defconst vhdl-trailer-re
6149 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6151 (defconst vhdl-statement-fwd-re
6152 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6153 "A regular expression for searching forward that matches all known
6154 \"statement\" keywords.")
6156 (defconst vhdl-statement-bwd-re
6157 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6158 "A regular expression for searching backward that matches all known
6159 \"statement\" keywords.")
6161 (defun vhdl-statement-p (&optional lim)
6162 "Return t if we are looking at a real \"statement\" keyword.
6163 Assumes that the caller will make sure that we are looking at
6164 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6165 in the middle of an identifier that just happens to contain a
6166 \"statement\" keyword."
6167 (cond
6168 ;; "for" ... "generate":
6169 ((and (looking-at "f")
6170 ;; Make sure it's the start of a parameter specification.
6171 (save-excursion
6172 (forward-sexp 2)
6173 (skip-chars-forward " \t\n\r\f")
6174 (looking-at "in\\b[^_]"))
6175 ;; Make sure it's not an "end for".
6176 (save-excursion
6177 (backward-sexp)
6178 (not (looking-at "end\\s-+\\w"))))
6180 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6181 ((and (looking-at "i")
6182 ;; Make sure it's not an "end if".
6183 (save-excursion
6184 (backward-sexp)
6185 (not (looking-at "end\\s-+\\w"))))
6187 ;; "while" ... "loop":
6188 ((looking-at "w")
6192 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6193 "Regexp describing a case statement alternative key.")
6195 (defun vhdl-case-alternative-p (&optional lim)
6196 "Return t if we are looking at a real case alternative.
6197 Assumes that the caller will make sure that we are looking at
6198 vhdl-case-alternative-re, and are not inside a literal, and that
6199 we are not in the middle of an identifier that just happens to
6200 contain a \"when\" keyword."
6201 (save-excursion
6202 (let (foundp)
6203 (while (and (not foundp)
6204 (re-search-backward ";\\|<=" lim 'move))
6205 (if (or (= (preceding-char) ?_)
6206 (vhdl-in-literal))
6207 (backward-char)
6208 (setq foundp t)))
6209 (or (eq (following-char) ?\;)
6210 (eq (point) lim)))
6213 ;; Core syntactic movement functions:
6215 (defconst vhdl-b-t-b-re
6216 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6218 (defun vhdl-backward-to-block (&optional lim)
6219 "Move backward to the previous \"begin\" or \"end\" keyword."
6220 (let (foundp)
6221 (while (and (not foundp)
6222 (re-search-backward vhdl-b-t-b-re lim 'move))
6223 (if (or (= (preceding-char) ?_)
6224 (vhdl-in-literal))
6225 (backward-char)
6226 (cond
6227 ;; "begin" keyword:
6228 ((and (looking-at vhdl-begin-fwd-re)
6229 (or (not (looking-at "\\<use\\>"))
6230 (save-excursion (back-to-indentation)
6231 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6232 (/= (preceding-char) ?_)
6233 (vhdl-begin-p lim))
6234 (setq foundp 'begin))
6235 ;; "end" keyword:
6236 ((and (looking-at vhdl-end-fwd-re)
6237 (/= (preceding-char) ?_)
6238 (vhdl-end-p lim))
6239 (setq foundp 'end))
6242 foundp
6245 (defun vhdl-forward-sexp (&optional count lim)
6246 "Move forward across one balanced expression (sexp).
6247 With COUNT, do it that many times."
6248 (interactive "p")
6249 (let ((count (or count 1))
6250 (case-fold-search t)
6251 end-vec target)
6252 (save-excursion
6253 (while (> count 0)
6254 ;; skip whitespace
6255 (skip-chars-forward " \t\n\r\f")
6256 ;; Check for an unbalanced "end" keyword
6257 (if (and (looking-at vhdl-end-fwd-re)
6258 (/= (preceding-char) ?_)
6259 (not (vhdl-in-literal))
6260 (vhdl-end-p lim)
6261 (not (looking-at "else")))
6262 (error
6263 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6264 ;; If the current keyword is a "begin" keyword, then find the
6265 ;; corresponding "end" keyword.
6266 (if (setq end-vec (vhdl-corresponding-end lim))
6267 (let (
6268 ;; end-re is the statement keyword to search for
6269 (end-re
6270 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6271 ;; column is either the statement keyword target column
6272 ;; or nil
6273 (column (aref end-vec 1))
6274 (eol (vhdl-point 'eol))
6275 foundp literal placeholder)
6276 ;; Look for the statement keyword.
6277 (while (and (not foundp)
6278 (re-search-forward end-re nil t)
6279 (setq placeholder (match-end 1))
6280 (goto-char (match-beginning 0)))
6281 ;; If we are in a literal, or not in the right target
6282 ;; column and not on the same line as the begin, then
6283 ;; try again.
6284 (if (or (and column
6285 (/= (current-indentation) column)
6286 (> (point) eol))
6287 (= (preceding-char) ?_)
6288 (setq literal (vhdl-in-literal)))
6289 (if (eq literal 'comment)
6290 (end-of-line)
6291 (forward-char))
6292 ;; An "else" keyword corresponds to both the opening brace
6293 ;; of the following sexp and the closing brace of the
6294 ;; previous sexp.
6295 (if (not (looking-at "else"))
6296 (goto-char placeholder))
6297 (setq foundp t))
6299 (if (not foundp)
6300 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6302 ;; If the current keyword is not a "begin" keyword, then just
6303 ;; perform the normal forward-sexp.
6304 (forward-sexp)
6306 (setq count (1- count))
6308 (setq target (point)))
6309 (goto-char target)
6310 nil))
6312 (defun vhdl-backward-sexp (&optional count lim)
6313 "Move backward across one balanced expression (sexp).
6314 With COUNT, do it that many times. LIM bounds any required backward
6315 searches."
6316 (interactive "p")
6317 (let ((count (or count 1))
6318 (case-fold-search t)
6319 begin-vec target)
6320 (save-excursion
6321 (while (> count 0)
6322 ;; Perform the normal backward-sexp, unless we are looking at
6323 ;; "else" - an "else" keyword corresponds to both the opening brace
6324 ;; of the following sexp and the closing brace of the previous sexp.
6325 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6326 (/= (preceding-char) ?_)
6327 (not (vhdl-in-literal)))
6329 (backward-sexp)
6330 (if (and (looking-at vhdl-begin-fwd-re)
6331 (or (not (looking-at "\\<use\\>"))
6332 (save-excursion
6333 (back-to-indentation)
6334 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6335 (/= (preceding-char) ?_)
6336 (not (vhdl-in-literal))
6337 (vhdl-begin-p lim))
6338 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6339 ;; If the current keyword is an "end" keyword, then find the
6340 ;; corresponding "begin" keyword.
6341 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6342 (/= (preceding-char) ?_))
6343 (let (
6344 ;; begin-re is the statement keyword to search for
6345 (begin-re
6346 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6347 ;; column is either the statement keyword target column
6348 ;; or nil
6349 (column (aref begin-vec 1))
6350 ;; internal-p controls where the statement keyword can
6351 ;; be found.
6352 (internal-p (aref begin-vec 3))
6353 (last-backward (point)) last-forward
6354 foundp literal keyword)
6355 ;; Look for the statement keyword.
6356 (while (and (not foundp)
6357 (re-search-backward begin-re lim t)
6358 (setq keyword
6359 (buffer-substring (match-beginning 1)
6360 (match-end 1))))
6361 ;; If we are in a literal or in the wrong column,
6362 ;; then try again.
6363 (if (or (and column
6364 (and (/= (current-indentation) column)
6365 ;; possibly accept current-column as
6366 ;; well as current-indentation.
6367 (or (not internal-p)
6368 (/= (current-column) column))))
6369 (= (preceding-char) ?_)
6370 (vhdl-in-literal))
6371 (backward-char)
6372 ;; If there is a supplementary keyword, then
6373 ;; search forward for it.
6374 (if (and (setq begin-re (aref begin-vec 2))
6375 (or (not (listp begin-re))
6376 ;; If begin-re is an alist, then find the
6377 ;; element corresponding to the actual
6378 ;; keyword that we found.
6379 (progn
6380 (setq begin-re
6381 (assoc keyword begin-re))
6382 (and begin-re
6383 (setq begin-re (cdr begin-re))))))
6384 (and
6385 (setq begin-re
6386 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6387 (save-excursion
6388 (setq last-forward (point))
6389 ;; Look for the supplementary keyword
6390 ;; (bounded by the backward search start
6391 ;; point).
6392 (while (and (not foundp)
6393 (re-search-forward begin-re
6394 last-backward t)
6395 (goto-char (match-beginning 1)))
6396 ;; If we are in a literal, then try again.
6397 (if (or (= (preceding-char) ?_)
6398 (setq literal
6399 (vhdl-in-literal)))
6400 (if (eq literal 'comment)
6401 (goto-char
6402 (min (vhdl-point 'eol) last-backward))
6403 (forward-char))
6404 ;; We have found the supplementary keyword.
6405 ;; Save the position of the keyword in foundp.
6406 (setq foundp (point)))
6408 foundp)
6409 ;; If the supplementary keyword was found, then
6410 ;; move point to the supplementary keyword.
6411 (goto-char foundp))
6412 ;; If there was no supplementary keyword, then
6413 ;; point is already at the statement keyword.
6414 (setq foundp t)))
6415 ) ; end of the search for the statement keyword
6416 (if (not foundp)
6417 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6419 (setq count (1- count))
6421 (setq target (point)))
6422 (goto-char target)
6423 nil))
6425 (defun vhdl-backward-up-list (&optional count limit)
6426 "Move backward out of one level of blocks.
6427 With argument, do this that many times."
6428 (interactive "p")
6429 (let ((count (or count 1))
6430 target)
6431 (save-excursion
6432 (while (> count 0)
6433 (if (looking-at vhdl-defun-re)
6434 (error "ERROR: Unbalanced blocks"))
6435 (vhdl-backward-to-block limit)
6436 (setq count (1- count)))
6437 (setq target (point)))
6438 (goto-char target)))
6440 (defun vhdl-end-of-defun (&optional count)
6441 "Move forward to the end of a VHDL defun."
6442 (interactive)
6443 (let ((case-fold-search t))
6444 (vhdl-beginning-of-defun)
6445 (if (not (looking-at "block\\|process\\|procedural"))
6446 (re-search-forward "\\bis\\b"))
6447 (vhdl-forward-sexp)))
6449 (defun vhdl-mark-defun ()
6450 "Put mark at end of this \"defun\", point at beginning."
6451 (interactive)
6452 (let ((case-fold-search t))
6453 (push-mark)
6454 (vhdl-beginning-of-defun)
6455 (push-mark)
6456 (if (not (looking-at "block\\|process\\|procedural"))
6457 (re-search-forward "\\bis\\b"))
6458 (vhdl-forward-sexp)
6459 (exchange-point-and-mark)))
6461 (defun vhdl-beginning-of-libunit ()
6462 "Move backward to the beginning of a VHDL library unit.
6463 Returns the location of the corresponding begin keyword, unless search
6464 stops due to beginning or end of buffer.
6465 Note that if point is between the \"libunit\" keyword and the
6466 corresponding \"begin\" keyword, then that libunit will not be
6467 recognized, and the search will continue backwards. If point is
6468 at the \"begin\" keyword, then the defun will be recognized. The
6469 returned point is at the first character of the \"libunit\" keyword."
6470 (let ((last-forward (point))
6471 (last-backward
6472 ;; Just in case we are actually sitting on the "begin"
6473 ;; keyword, allow for the keyword and an extra character,
6474 ;; as this will be used when looking forward for the
6475 ;; "begin" keyword.
6476 (save-excursion (forward-word 1) (1+ (point))))
6477 foundp literal placeholder)
6478 ;; Find the "libunit" keyword.
6479 (while (and (not foundp)
6480 (re-search-backward vhdl-libunit-re nil 'move))
6481 ;; If we are in a literal, or not at a real libunit, then try again.
6482 (if (or (= (preceding-char) ?_)
6483 (vhdl-in-literal)
6484 (not (vhdl-libunit-p)))
6485 (backward-char)
6486 ;; Find the corresponding "begin" keyword.
6487 (setq last-forward (point))
6488 (while (and (not foundp)
6489 (re-search-forward "\\bis\\b[^_]" last-backward t)
6490 (setq placeholder (match-beginning 0)))
6491 (if (or (= (preceding-char) ?_)
6492 (setq literal (vhdl-in-literal)))
6493 ;; It wasn't a real keyword, so keep searching.
6494 (if (eq literal 'comment)
6495 (goto-char
6496 (min (vhdl-point 'eol) last-backward))
6497 (forward-char))
6498 ;; We have found the begin keyword, loop will exit.
6499 (setq foundp placeholder)))
6500 ;; Go back to the libunit keyword
6501 (goto-char last-forward)))
6502 foundp))
6504 (defun vhdl-beginning-of-defun (&optional count)
6505 "Move backward to the beginning of a VHDL defun.
6506 With argument, do it that many times.
6507 Returns the location of the corresponding begin keyword, unless search
6508 stops due to beginning or end of buffer."
6509 ;; Note that if point is between the "defun" keyword and the
6510 ;; corresponding "begin" keyword, then that defun will not be
6511 ;; recognized, and the search will continue backwards. If point is
6512 ;; at the "begin" keyword, then the defun will be recognized. The
6513 ;; returned point is at the first character of the "defun" keyword.
6514 (interactive "p")
6515 (let ((count (or count 1))
6516 (case-fold-search t)
6517 (last-forward (point))
6518 foundp)
6519 (while (> count 0)
6520 (setq foundp nil)
6521 (goto-char last-forward)
6522 (let ((last-backward
6523 ;; Just in case we are actually sitting on the "begin"
6524 ;; keyword, allow for the keyword and an extra character,
6525 ;; as this will be used when looking forward for the
6526 ;; "begin" keyword.
6527 (save-excursion (forward-word 1) (1+ (point))))
6528 begin-string literal)
6529 (while (and (not foundp)
6530 (re-search-backward vhdl-defun-re nil 'move))
6531 ;; If we are in a literal, then try again.
6532 (if (or (= (preceding-char) ?_)
6533 (vhdl-in-literal))
6534 (backward-char)
6535 (if (setq begin-string (vhdl-corresponding-defun))
6536 ;; This is a real defun keyword.
6537 ;; Find the corresponding "begin" keyword.
6538 ;; Look for the begin keyword.
6539 (progn
6540 ;; Save the search start point.
6541 (setq last-forward (point))
6542 (while (and (not foundp)
6543 (search-forward begin-string last-backward t))
6544 (if (or (= (preceding-char) ?_)
6545 (save-match-data
6546 (setq literal (vhdl-in-literal))))
6547 ;; It wasn't a real keyword, so keep searching.
6548 (if (eq literal 'comment)
6549 (goto-char
6550 (min (vhdl-point 'eol) last-backward))
6551 (forward-char))
6552 ;; We have found the begin keyword, loop will exit.
6553 (setq foundp (match-beginning 0)))
6555 ;; Go back to the defun keyword
6556 (goto-char last-forward)) ; end search for begin keyword
6558 ) ; end of the search for the defun keyword
6560 (setq count (1- count))
6562 (vhdl-keep-region-active)
6563 foundp))
6565 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6566 "Go to the beginning of the innermost VHDL statement.
6567 With prefix arg, go back N - 1 statements. If already at the
6568 beginning of a statement then go to the beginning of the preceding
6569 one. If within a string or comment, or next to a comment (only
6570 whitespace between), move by sentences instead of statements.
6572 When called from a program, this function takes 3 optional args: the
6573 prefix arg, a buffer position limit which is the farthest back to
6574 search, and an argument indicating an interactive call."
6575 (interactive "p\np")
6576 (let ((count (or count 1))
6577 (case-fold-search t)
6578 (lim (or lim (point-min)))
6579 (here (point))
6580 state)
6581 (save-excursion
6582 (goto-char lim)
6583 (setq state (parse-partial-sexp (point) here nil nil)))
6584 (if (and interactive
6585 (or (nth 3 state)
6586 (nth 4 state)
6587 (looking-at (concat "[ \t]*" comment-start-skip))))
6588 (forward-sentence (- count))
6589 (while (> count 0)
6590 (vhdl-beginning-of-statement-1 lim)
6591 (setq count (1- count))))
6592 ;; its possible we've been left up-buf of lim
6593 (goto-char (max (point) lim))
6595 (vhdl-keep-region-active))
6597 (defconst vhdl-e-o-s-re
6598 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6600 (defun vhdl-end-of-statement ()
6601 "Very simple implementation."
6602 (interactive)
6603 (re-search-forward vhdl-e-o-s-re))
6605 (defconst vhdl-b-o-s-re
6606 (concat ";[^_]\\|\([^_]\\|\)[^_]\\|\\bwhen\\b[^_]\\|"
6607 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6609 (defun vhdl-beginning-of-statement-1 (&optional lim)
6610 "Move to the start of the current statement, or the previous
6611 statement if already at the beginning of one."
6612 (let ((lim (or lim (point-min)))
6613 (here (point))
6614 (pos (point))
6615 donep)
6616 ;; go backwards one balanced expression, but be careful of
6617 ;; unbalanced paren being reached
6618 (if (not (vhdl-safe (progn (backward-sexp) t)))
6619 (progn
6620 (backward-up-list 1)
6621 (forward-char)
6622 (vhdl-forward-syntactic-ws here)
6623 (setq donep t)))
6624 (while (and (not donep)
6625 (not (bobp))
6626 ;; look backwards for a statement boundary
6627 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6628 (if (or (= (preceding-char) ?_)
6629 (vhdl-in-literal))
6630 (backward-char)
6631 (cond
6632 ;; If we are looking at an open paren, then stop after it
6633 ((eq (following-char) ?\()
6634 (forward-char)
6635 (vhdl-forward-syntactic-ws here)
6636 (setq donep t))
6637 ;; If we are looking at a close paren, then skip it
6638 ((eq (following-char) ?\))
6639 (forward-char)
6640 (setq pos (point))
6641 (backward-sexp)
6642 (if (< (point) lim)
6643 (progn (goto-char pos)
6644 (vhdl-forward-syntactic-ws here)
6645 (setq donep t))))
6646 ;; If we are looking at a semicolon, then stop
6647 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6648 (progn
6649 (forward-char)
6650 (vhdl-forward-syntactic-ws here)
6651 (setq donep t)))
6652 ;; If we are looking at a "begin", then stop
6653 ((and (looking-at vhdl-begin-fwd-re)
6654 (or (not (looking-at "\\<use\\>"))
6655 (save-excursion
6656 (back-to-indentation)
6657 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6658 (/= (preceding-char) ?_)
6659 (vhdl-begin-p nil))
6660 ;; If it's a leader "begin", then find the
6661 ;; right place
6662 (if (looking-at vhdl-leader-re)
6663 (save-excursion
6664 ;; set a default stop point at the begin
6665 (setq pos (point))
6666 ;; is the start point inside the leader area ?
6667 (goto-char (vhdl-end-of-leader))
6668 (vhdl-forward-syntactic-ws here)
6669 (if (< (point) here)
6670 ;; start point was not inside leader area
6671 ;; set stop point at word after leader
6672 (setq pos (point))))
6673 (forward-word 1)
6674 (vhdl-forward-syntactic-ws here)
6675 (setq pos (point)))
6676 (goto-char pos)
6677 (setq donep t))
6678 ;; If we are looking at a "statement", then stop
6679 ((and (looking-at vhdl-statement-fwd-re)
6680 (/= (preceding-char) ?_)
6681 (vhdl-statement-p nil))
6682 (setq donep t))
6683 ;; If we are looking at a case alternative key, then stop
6684 ((and (looking-at vhdl-case-alternative-re)
6685 (vhdl-case-alternative-p lim))
6686 (save-excursion
6687 ;; set a default stop point at the when
6688 (setq pos (point))
6689 ;; is the start point inside the case alternative key ?
6690 (looking-at vhdl-case-alternative-re)
6691 (goto-char (match-end 0))
6692 (vhdl-forward-syntactic-ws here)
6693 (if (< (point) here)
6694 ;; start point was not inside the case alternative key
6695 ;; set stop point at word after case alternative keyleader
6696 (setq pos (point))))
6697 (goto-char pos)
6698 (setq donep t))
6699 ;; Bogus find, continue
6701 (backward-char)))))
6704 ;; Defuns for calculating the current syntactic state:
6706 (defun vhdl-get-library-unit (bod placeholder)
6707 "If there is an enclosing library unit at BOD, with its \"begin\"
6708 keyword at PLACEHOLDER, then return the library unit type."
6709 (let ((here (vhdl-point 'bol)))
6710 (if (save-excursion
6711 (goto-char placeholder)
6712 (vhdl-safe (vhdl-forward-sexp 1 bod))
6713 (<= here (point)))
6714 (save-excursion
6715 (goto-char bod)
6716 (cond
6717 ((looking-at "e") 'entity)
6718 ((looking-at "a") 'architecture)
6719 ((looking-at "c") 'configuration)
6720 ((looking-at "p")
6721 (save-excursion
6722 (goto-char bod)
6723 (forward-sexp)
6724 (vhdl-forward-syntactic-ws here)
6725 (if (looking-at "body\\b[^_]")
6726 'package-body 'package))))))
6729 (defun vhdl-get-block-state (&optional lim)
6730 "Finds and records all the closest opens.
6731 LIM is the furthest back we need to search (it should be the
6732 previous libunit keyword)."
6733 (let ((here (point))
6734 (lim (or lim (point-min)))
6735 keyword sexp-start sexp-mid sexp-end
6736 preceding-sexp containing-sexp
6737 containing-begin containing-mid containing-paren)
6738 (save-excursion
6739 ;; Find the containing-paren, and use that as the limit
6740 (if (setq containing-paren
6741 (save-restriction
6742 (narrow-to-region lim (point))
6743 (vhdl-safe (scan-lists (point) -1 1))))
6744 (setq lim containing-paren))
6745 ;; Look backwards for "begin" and "end" keywords.
6746 (while (and (> (point) lim)
6747 (not containing-sexp))
6748 (setq keyword (vhdl-backward-to-block lim))
6749 (cond
6750 ((eq keyword 'begin)
6751 ;; Found a "begin" keyword
6752 (setq sexp-start (point))
6753 (setq sexp-mid (vhdl-corresponding-mid lim))
6754 (setq sexp-end (vhdl-safe
6755 (save-excursion
6756 (vhdl-forward-sexp 1 lim) (point))))
6757 (if (and sexp-end (<= sexp-end here))
6758 ;; we want to record this sexp, but we only want to
6759 ;; record the last-most of any of them before here
6760 (or preceding-sexp
6761 (setq preceding-sexp sexp-start))
6762 ;; we're contained in this sexp so put sexp-start on
6763 ;; front of list
6764 (setq containing-sexp sexp-start)
6765 (setq containing-mid sexp-mid)
6766 (setq containing-begin t)))
6767 ((eq keyword 'end)
6768 ;; Found an "end" keyword
6769 (forward-sexp)
6770 (setq sexp-end (point))
6771 (setq sexp-mid nil)
6772 (setq sexp-start
6773 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6774 (progn (backward-sexp) (point))))
6775 ;; we want to record this sexp, but we only want to
6776 ;; record the last-most of any of them before here
6777 (or preceding-sexp
6778 (setq preceding-sexp sexp-start)))
6780 ;; Check if the containing-paren should be the containing-sexp
6781 (if (and containing-paren
6782 (or (null containing-sexp)
6783 (< containing-sexp containing-paren)))
6784 (setq containing-sexp containing-paren
6785 preceding-sexp nil
6786 containing-begin nil
6787 containing-mid nil))
6788 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6792 (defconst vhdl-s-c-a-re
6793 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6795 (defun vhdl-skip-case-alternative (&optional lim)
6796 "Skip forward over case/when bodies, with optional maximal
6797 limit. If no next case alternative is found, nil is returned and
6798 point is not moved."
6799 (let ((lim (or lim (point-max)))
6800 (here (point))
6801 donep foundp)
6802 (while (and (< (point) lim)
6803 (not donep))
6804 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6805 (save-match-data
6806 (not (vhdl-in-literal)))
6807 (/= (match-beginning 0) here))
6808 (progn
6809 (goto-char (match-beginning 0))
6810 (cond
6811 ((and (looking-at "case")
6812 (re-search-forward "\\bis[^_]" lim t))
6813 (backward-sexp)
6814 (vhdl-forward-sexp))
6816 (setq donep t
6817 foundp t))))))
6818 (if (not foundp)
6819 (goto-char here))
6820 foundp))
6822 (defun vhdl-backward-skip-label (&optional lim)
6823 "Skip backward over a label, with optional maximal
6824 limit. If label is not found, nil is returned and point
6825 is not moved."
6826 (let ((lim (or lim (point-min)))
6827 placeholder)
6828 (if (save-excursion
6829 (vhdl-backward-syntactic-ws lim)
6830 (and (eq (preceding-char) ?:)
6831 (progn
6832 (backward-sexp)
6833 (setq placeholder (point))
6834 (looking-at vhdl-label-key))))
6835 (goto-char placeholder))
6838 (defun vhdl-forward-skip-label (&optional lim)
6839 "Skip forward over a label, with optional maximal
6840 limit. If label is not found, nil is returned and point
6841 is not moved."
6842 (let ((lim (or lim (point-max))))
6843 (if (looking-at vhdl-label-key)
6844 (progn
6845 (goto-char (match-end 0))
6846 (vhdl-forward-syntactic-ws lim)))
6849 (defun vhdl-get-syntactic-context ()
6850 "Guess the syntactic description of the current line of VHDL code."
6851 (save-excursion
6852 (save-restriction
6853 (beginning-of-line)
6854 (let* ((indent-point (point))
6855 (case-fold-search t)
6856 vec literal containing-sexp preceding-sexp
6857 containing-begin containing-mid containing-leader
6858 char-before-ip char-after-ip begin-after-ip end-after-ip
6859 placeholder lim library-unit
6862 ;; Reset the syntactic context
6863 (setq vhdl-syntactic-context nil)
6865 (save-excursion
6866 ;; Move to the start of the previous library unit, and
6867 ;; record the position of the "begin" keyword.
6868 (setq placeholder (vhdl-beginning-of-libunit))
6869 ;; The position of the "libunit" keyword gives us a gross
6870 ;; limit point.
6871 (setq lim (point))
6874 ;; If there is a previous library unit, and we are enclosed by
6875 ;; it, then set the syntax accordingly.
6876 (and placeholder
6877 (setq library-unit (vhdl-get-library-unit lim placeholder))
6878 (vhdl-add-syntax library-unit lim))
6880 ;; Find the surrounding state.
6881 (if (setq vec (vhdl-get-block-state lim))
6882 (progn
6883 (setq containing-sexp (aref vec 0))
6884 (setq preceding-sexp (aref vec 1))
6885 (setq containing-begin (aref vec 2))
6886 (setq containing-mid (aref vec 3))
6889 ;; set the limit on the farthest back we need to search
6890 (setq lim (if containing-sexp
6891 (save-excursion
6892 (goto-char containing-sexp)
6893 ;; set containing-leader if required
6894 (if (looking-at vhdl-leader-re)
6895 (setq containing-leader (vhdl-end-of-leader)))
6896 (vhdl-point 'bol))
6897 (point-min)))
6899 ;; cache char before and after indent point, and move point to
6900 ;; the most likely position to perform the majority of tests
6901 (goto-char indent-point)
6902 (skip-chars-forward " \t")
6903 (setq literal (vhdl-in-literal))
6904 (setq char-after-ip (following-char))
6905 (setq begin-after-ip (and
6906 (not literal)
6907 (looking-at vhdl-begin-fwd-re)
6908 (or (not (looking-at "\\<use\\>"))
6909 (save-excursion
6910 (back-to-indentation)
6911 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6912 (vhdl-begin-p)))
6913 (setq end-after-ip (and
6914 (not literal)
6915 (looking-at vhdl-end-fwd-re)
6916 (vhdl-end-p)))
6917 (vhdl-backward-syntactic-ws lim)
6918 (setq char-before-ip (preceding-char))
6919 (goto-char indent-point)
6920 (skip-chars-forward " \t")
6922 ;; now figure out syntactic qualities of the current line
6923 (cond
6924 ;; CASE 1: in a string or comment.
6925 ((memq literal '(string comment))
6926 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6927 ;; CASE 2: Line is at top level.
6928 ((null containing-sexp)
6929 ;; Find the point to which indentation will be relative
6930 (save-excursion
6931 (if (null preceding-sexp)
6932 ;; CASE 2X.1
6933 ;; no preceding-sexp -> use the preceding statement
6934 (vhdl-beginning-of-statement-1 lim)
6935 ;; CASE 2X.2
6936 ;; if there is a preceding-sexp then indent relative to it
6937 (goto-char preceding-sexp)
6938 ;; if not at boi, then the block-opening keyword is
6939 ;; probably following a label, so we need a different
6940 ;; relpos
6941 (if (/= (point) (vhdl-point 'boi))
6942 ;; CASE 2X.3
6943 (vhdl-beginning-of-statement-1 lim)))
6944 ;; v-b-o-s could have left us at point-min
6945 (and (bobp)
6946 ;; CASE 2X.4
6947 (vhdl-forward-syntactic-ws indent-point))
6948 (setq placeholder (point)))
6949 (cond
6950 ;; CASE 2A : we are looking at a block-open
6951 (begin-after-ip
6952 (vhdl-add-syntax 'block-open placeholder))
6953 ;; CASE 2B: we are looking at a block-close
6954 (end-after-ip
6955 (vhdl-add-syntax 'block-close placeholder))
6956 ;; CASE 2C: we are looking at a top-level statement
6957 ((progn
6958 (vhdl-backward-syntactic-ws lim)
6959 (or (bobp)
6960 (and (= (preceding-char) ?\;)
6961 (not (vhdl-in-quote-p)))))
6962 (vhdl-add-syntax 'statement placeholder))
6963 ;; CASE 2D: we are looking at a top-level statement-cont
6965 (vhdl-beginning-of-statement-1 lim)
6966 ;; v-b-o-s could have left us at point-min
6967 (and (bobp)
6968 ;; CASE 2D.1
6969 (vhdl-forward-syntactic-ws indent-point))
6970 (vhdl-add-syntax 'statement-cont (point)))
6971 )) ; end CASE 2
6972 ;; CASE 3: line is inside parentheses. Most likely we are
6973 ;; either in a subprogram argument (interface) list, or a
6974 ;; continued expression containing parentheses.
6975 ((null containing-begin)
6976 (vhdl-backward-syntactic-ws containing-sexp)
6977 (cond
6978 ;; CASE 3A: we are looking at the arglist closing paren
6979 ((eq char-after-ip ?\))
6980 (goto-char containing-sexp)
6981 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6982 ;; CASE 3B: we are looking at the first argument in an empty
6983 ;; argument list.
6984 ((eq char-before-ip ?\()
6985 (goto-char containing-sexp)
6986 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6987 ;; CASE 3C: we are looking at an arglist continuation line,
6988 ;; but the preceding argument is on the same line as the
6989 ;; opening paren. This case includes multi-line
6990 ;; expression paren groupings.
6991 ((and (save-excursion
6992 (goto-char (1+ containing-sexp))
6993 (skip-chars-forward " \t")
6994 (not (eolp))
6995 (not (looking-at "--")))
6996 (save-excursion
6997 (vhdl-beginning-of-statement-1 containing-sexp)
6998 (skip-chars-backward " \t(")
6999 (while (and (= (preceding-char) ?\;)
7000 (not (vhdl-in-quote-p)))
7001 (vhdl-beginning-of-statement-1 containing-sexp)
7002 (skip-chars-backward " \t("))
7003 (<= (point) containing-sexp)))
7004 (goto-char containing-sexp)
7005 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
7006 ;; CASE 3D: we are looking at just a normal arglist
7007 ;; continuation line
7008 (t (vhdl-beginning-of-statement-1 containing-sexp)
7009 (vhdl-forward-syntactic-ws indent-point)
7010 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
7012 ;; CASE 4: A block mid open
7013 ((and begin-after-ip
7014 (looking-at containing-mid))
7015 (goto-char containing-sexp)
7016 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7017 (if (looking-at vhdl-trailer-re)
7018 ;; CASE 4.1
7019 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7020 (vhdl-backward-skip-label (vhdl-point 'boi))
7021 (vhdl-add-syntax 'block-open (point)))
7022 ;; CASE 5: block close brace
7023 (end-after-ip
7024 (goto-char containing-sexp)
7025 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7026 (if (looking-at vhdl-trailer-re)
7027 ;; CASE 5.1
7028 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7029 (vhdl-backward-skip-label (vhdl-point 'boi))
7030 (vhdl-add-syntax 'block-close (point)))
7031 ;; CASE 6: A continued statement
7032 ((and (/= char-before-ip ?\;)
7033 ;; check it's not a trailer begin keyword, or a begin
7034 ;; keyword immediately following a label.
7035 (not (and begin-after-ip
7036 (or (looking-at vhdl-trailer-re)
7037 (save-excursion
7038 (vhdl-backward-skip-label containing-sexp)))))
7039 ;; check it's not a statement keyword
7040 (not (and (looking-at vhdl-statement-fwd-re)
7041 (vhdl-statement-p)))
7042 ;; see if the b-o-s is before the indent point
7043 (> indent-point
7044 (save-excursion
7045 (vhdl-beginning-of-statement-1 containing-sexp)
7046 ;; If we ended up after a leader, then this will
7047 ;; move us forward to the start of the first
7048 ;; statement. Note that a containing sexp here is
7049 ;; always a keyword, not a paren, so this will
7050 ;; have no effect if we hit the containing-sexp.
7051 (vhdl-forward-syntactic-ws indent-point)
7052 (setq placeholder (point))))
7053 ;; check it's not a block-intro
7054 (/= placeholder containing-sexp)
7055 ;; check it's not a case block-intro
7056 (save-excursion
7057 (goto-char placeholder)
7058 (or (not (looking-at vhdl-case-alternative-re))
7059 (> (match-end 0) indent-point))))
7060 ;; Make placeholder skip a label, but only if it puts us
7061 ;; before the indent point at the start of a line.
7062 (let ((new placeholder))
7063 (if (and (> indent-point
7064 (save-excursion
7065 (goto-char placeholder)
7066 (vhdl-forward-skip-label indent-point)
7067 (setq new (point))))
7068 (save-excursion
7069 (goto-char new)
7070 (eq new (progn (back-to-indentation) (point)))))
7071 (setq placeholder new)))
7072 (vhdl-add-syntax 'statement-cont placeholder)
7073 (if begin-after-ip
7074 (vhdl-add-syntax 'block-open)))
7075 ;; Statement. But what kind?
7076 ;; CASE 7: A case alternative key
7077 ((and (looking-at vhdl-case-alternative-re)
7078 (vhdl-case-alternative-p containing-sexp))
7079 ;; for a case alternative key, we set relpos to the first
7080 ;; non-whitespace char on the line containing the "case"
7081 ;; keyword.
7082 (goto-char containing-sexp)
7083 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7084 (if (looking-at vhdl-trailer-re)
7085 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7086 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
7087 ;; CASE 8: statement catchall
7089 ;; we know its a statement, but we need to find out if it is
7090 ;; the first statement in a block
7091 (if containing-leader
7092 (goto-char containing-leader)
7093 (goto-char containing-sexp)
7094 ;; Note that a containing sexp here is always a keyword,
7095 ;; not a paren, so skip over the keyword.
7096 (forward-sexp))
7097 ;; move to the start of the first statement
7098 (vhdl-forward-syntactic-ws indent-point)
7099 (setq placeholder (point))
7100 ;; we want to ignore case alternatives keys when skipping forward
7101 (let (incase-p)
7102 (while (looking-at vhdl-case-alternative-re)
7103 (setq incase-p (point))
7104 ;; we also want to skip over the body of the
7105 ;; case/when statement if that doesn't put us at
7106 ;; after the indent-point
7107 (while (vhdl-skip-case-alternative indent-point))
7108 ;; set up the match end
7109 (looking-at vhdl-case-alternative-re)
7110 (goto-char (match-end 0))
7111 ;; move to the start of the first case alternative statement
7112 (vhdl-forward-syntactic-ws indent-point)
7113 (setq placeholder (point)))
7114 (cond
7115 ;; CASE 8A: we saw a case/when statement so we must be
7116 ;; in a switch statement. find out if we are at the
7117 ;; statement just after a case alternative key
7118 ((and incase-p
7119 (= (point) indent-point))
7120 ;; relpos is the "when" keyword
7121 (vhdl-add-syntax 'statement-case-intro incase-p))
7122 ;; CASE 8B: any old statement
7123 ((< (point) indent-point)
7124 ;; relpos is the first statement of the block
7125 (vhdl-add-syntax 'statement placeholder)
7126 (if begin-after-ip
7127 (vhdl-add-syntax 'block-open)))
7128 ;; CASE 8C: first statement in a block
7130 (goto-char containing-sexp)
7131 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7132 (if (looking-at vhdl-trailer-re)
7133 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7134 (vhdl-backward-skip-label (vhdl-point 'boi))
7135 (vhdl-add-syntax 'statement-block-intro (point))
7136 (if begin-after-ip
7137 (vhdl-add-syntax 'block-open)))
7141 ;; now we need to look at any modifiers
7142 (goto-char indent-point)
7143 (skip-chars-forward " \t")
7144 (if (looking-at "--")
7145 (vhdl-add-syntax 'comment))
7146 (if (eq literal 'pound)
7147 (vhdl-add-syntax 'cpp-macro))
7148 ;; return the syntax
7149 vhdl-syntactic-context))))
7151 ;; Standard indentation line-ups:
7153 (defun vhdl-lineup-arglist (langelem)
7154 "Lineup the current arglist line with the arglist appearing just
7155 after the containing paren which starts the arglist."
7156 (save-excursion
7157 (let* ((containing-sexp
7158 (save-excursion
7159 ;; arglist-cont-nonempty gives relpos ==
7160 ;; to boi of containing-sexp paren. This
7161 ;; is good when offset is +, but bad
7162 ;; when it is vhdl-lineup-arglist, so we
7163 ;; have to special case a kludge here.
7164 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7165 (progn
7166 (beginning-of-line)
7167 (backward-up-list 1)
7168 (skip-chars-forward " \t" (vhdl-point 'eol)))
7169 (goto-char (cdr langelem)))
7170 (point)))
7171 (cs-curcol (save-excursion
7172 (goto-char (cdr langelem))
7173 (current-column))))
7174 (if (save-excursion
7175 (beginning-of-line)
7176 (looking-at "[ \t]*)"))
7177 (progn (goto-char (match-end 0))
7178 (backward-sexp)
7179 (forward-char)
7180 (vhdl-forward-syntactic-ws)
7181 (- (current-column) cs-curcol))
7182 (goto-char containing-sexp)
7183 (or (eolp)
7184 (let ((eol (vhdl-point 'eol))
7185 (here (progn
7186 (forward-char)
7187 (skip-chars-forward " \t")
7188 (point))))
7189 (vhdl-forward-syntactic-ws)
7190 (if (< (point) eol)
7191 (goto-char here))))
7192 (- (current-column) cs-curcol)
7193 ))))
7195 (defun vhdl-lineup-arglist-intro (langelem)
7196 "Lineup an arglist-intro line to just after the open paren."
7197 (save-excursion
7198 (let ((cs-curcol (save-excursion
7199 (goto-char (cdr langelem))
7200 (current-column)))
7201 (ce-curcol (save-excursion
7202 (beginning-of-line)
7203 (backward-up-list 1)
7204 (skip-chars-forward " \t" (vhdl-point 'eol))
7205 (current-column))))
7206 (- ce-curcol cs-curcol -1))))
7208 (defun vhdl-lineup-comment (langelem)
7209 "Support old behavior for comment indentation. We look at
7210 vhdl-comment-only-line-offset to decide how to indent comment
7211 only-lines."
7212 (save-excursion
7213 (back-to-indentation)
7214 ;; at or to the right of comment-column
7215 (if (>= (current-column) comment-column)
7216 (vhdl-comment-indent)
7217 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7218 (if (not (bolp))
7219 (or (car-safe vhdl-comment-only-line-offset)
7220 vhdl-comment-only-line-offset)
7221 (or (cdr-safe vhdl-comment-only-line-offset)
7222 (car-safe vhdl-comment-only-line-offset)
7223 -1000 ;jam it against the left side
7224 )))))
7226 (defun vhdl-lineup-statement-cont (langelem)
7227 "Line up statement-cont after the assignment operator."
7228 (save-excursion
7229 (let* ((relpos (cdr langelem))
7230 (assignp (save-excursion
7231 (goto-char (vhdl-point 'boi))
7232 (and (re-search-forward "\\(<\\|:\\|=\\)="
7233 (vhdl-point 'eol) t)
7234 (- (point) (vhdl-point 'boi)))))
7235 (curcol (progn
7236 (goto-char relpos)
7237 (current-column)))
7238 foundp)
7239 (while (and (not foundp)
7240 (< (point) (vhdl-point 'eol)))
7241 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7242 (if (vhdl-in-literal)
7243 (forward-char)
7244 (if (= (preceding-char) ?\()
7245 ;; skip over any parenthesized expressions
7246 (goto-char (min (vhdl-point 'eol)
7247 (scan-lists (point) 1 1)))
7248 ;; found an assignment operator (not at eol)
7249 (setq foundp (not (looking-at "\\s-*$"))))))
7250 (if (not foundp)
7251 ;; there's no assignment operator on the line
7252 vhdl-basic-offset
7253 ;; calculate indentation column after assign and ws, unless
7254 ;; our line contains an assignment operator
7255 (if (not assignp)
7256 (progn
7257 (forward-char)
7258 (skip-chars-forward " \t")
7259 (setq assignp 0)))
7260 (- (current-column) assignp curcol))
7263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7264 ;; Progress reporting
7266 (defvar vhdl-progress-info nil
7267 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7269 (defun vhdl-update-progress-info (string pos)
7270 "Update progress information."
7271 (when (and vhdl-progress-info (not noninteractive)
7272 (< vhdl-progress-interval
7273 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7274 (let ((delta (- (aref vhdl-progress-info 1)
7275 (aref vhdl-progress-info 0))))
7276 (if (= 0 delta)
7277 (message (concat string "... (100%s)") "%")
7278 (message (concat string "... (%2d%s)")
7279 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
7280 delta) "%")))
7281 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7284 ;; Indentation commands
7286 (defun vhdl-electric-tab (&optional prefix-arg)
7287 "If preceding character is part of a word or a paren then hippie-expand,
7288 else if right of non whitespace on line then insert tab,
7289 else if last command was a tab or return then dedent one step or if a comment
7290 toggle between normal indent and inline comment indent,
7291 else indent `correctly'."
7292 (interactive "*P")
7293 (vhdl-prepare-search-2
7294 (cond
7295 ;; indent region if region is active
7296 ((and (not (featurep 'xemacs)) (use-region-p))
7297 (vhdl-indent-region (region-beginning) (region-end) nil))
7298 ;; expand word
7299 ((= (char-syntax (preceding-char)) ?w)
7300 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7301 (case-replace nil)
7302 (hippie-expand-only-buffers
7303 (or (and (boundp 'hippie-expand-only-buffers)
7304 hippie-expand-only-buffers)
7305 '(vhdl-mode))))
7306 (vhdl-expand-abbrev prefix-arg)))
7307 ;; expand parenthesis
7308 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7309 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7310 (case-replace nil))
7311 (vhdl-expand-paren prefix-arg)))
7312 ;; insert tab
7313 ((> (current-column) (current-indentation))
7314 (insert-tab))
7315 ;; toggle comment indent
7316 ((and (looking-at "--")
7317 (or (eq last-command 'vhdl-electric-tab)
7318 (eq last-command 'vhdl-electric-return)))
7319 (cond ((= (current-indentation) 0) ; no indent
7320 (indent-to 1)
7321 (indent-according-to-mode))
7322 ((< (current-indentation) comment-column) ; normal indent
7323 (indent-to comment-column)
7324 (indent-according-to-mode))
7325 (t ; inline comment indent
7326 (delete-region (line-beginning-position) (point)))))
7327 ;; dedent
7328 ((and (>= (current-indentation) vhdl-basic-offset)
7329 (or (eq last-command 'vhdl-electric-tab)
7330 (eq last-command 'vhdl-electric-return)))
7331 (backward-delete-char-untabify vhdl-basic-offset nil))
7332 ;; indent line
7333 (t (indent-according-to-mode)))
7334 (setq this-command 'vhdl-electric-tab)))
7336 (defun vhdl-electric-return ()
7337 "newline-and-indent or indent-new-comment-line if in comment and preceding
7338 character is a space."
7339 (interactive)
7340 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7341 (indent-new-comment-line)
7342 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7343 (not (vhdl-in-comment-p)))
7344 (vhdl-fix-case-word -1))
7345 (newline-and-indent)))
7347 (defun vhdl-indent-line ()
7348 "Indent the current line as VHDL code. Returns the amount of
7349 indentation change."
7350 (interactive)
7351 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7352 (pos (- (point-max) (point)))
7353 (is-comment nil)
7354 (indent
7355 (if syntax
7356 ;; indent syntax-based
7357 (if (and (eq (caar syntax) 'comment)
7358 (>= (vhdl-get-offset (car syntax)) comment-column))
7359 ;; special case: comments at or right of comment-column
7360 (vhdl-get-offset (car syntax))
7361 ;; align comments like following code line
7362 (when vhdl-indent-comment-like-next-code-line
7363 (save-excursion
7364 (while (eq (caar syntax) 'comment)
7365 (setq is-comment t)
7366 (beginning-of-line 2)
7367 (setq syntax (vhdl-get-syntactic-context)))))
7368 (when is-comment
7369 (push (cons 'comment nil) syntax))
7370 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7371 ;; indent like previous nonblank line
7372 (save-excursion (beginning-of-line)
7373 (re-search-backward "^[^\n]" nil t)
7374 (current-indentation))))
7375 (shift-amt (- indent (current-indentation))))
7376 (and vhdl-echo-syntactic-information-p
7377 (message "syntax: %s, indent= %d" syntax indent))
7378 (let ((has-formfeed
7379 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7380 (when (or (not (zerop shift-amt)) has-formfeed)
7381 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7382 (beginning-of-line)
7383 (when has-formfeed (insert "\f"))
7384 (indent-to indent)))
7385 (if (< (point) (vhdl-point 'boi))
7386 (back-to-indentation)
7387 ;; If initial point was within line's indentation, position after
7388 ;; the indentation. Else stay at same point in text.
7389 (when (> (- (point-max) pos) (point))
7390 (goto-char (- (point-max) pos))))
7391 (run-hooks 'vhdl-special-indent-hook)
7392 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7393 shift-amt))
7395 (defun vhdl-indent-region (beg end &optional column)
7396 "Indent region as VHDL code.
7397 Adds progress reporting to `indent-region'."
7398 (interactive "r\nP")
7399 (when vhdl-progress-interval
7400 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7401 (count-lines (point-min) end) 0)))
7402 (indent-region beg end column)
7403 (when vhdl-progress-interval (message "Indenting...done"))
7404 (setq vhdl-progress-info nil))
7406 (defun vhdl-indent-buffer ()
7407 "Indent whole buffer as VHDL code.
7408 Calls `indent-region' for whole buffer and adds progress reporting."
7409 (interactive)
7410 (vhdl-indent-region (point-min) (point-max)))
7412 (defun vhdl-indent-group ()
7413 "Indent group of lines between empty lines."
7414 (interactive)
7415 (let ((beg (save-excursion
7416 (if (re-search-backward vhdl-align-group-separate nil t)
7417 (point-marker)
7418 (point-min-marker))))
7419 (end (save-excursion
7420 (if (re-search-forward vhdl-align-group-separate nil t)
7421 (point-marker)
7422 (point-max-marker)))))
7423 (vhdl-indent-region beg end)))
7425 (defun vhdl-indent-sexp (&optional endpos)
7426 "Indent each line of the list starting just after point.
7427 If optional arg ENDPOS is given, indent each line, stopping when
7428 ENDPOS is encountered."
7429 (interactive)
7430 (save-excursion
7431 (let ((beg (point))
7432 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7433 (indent-region beg end nil))))
7435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7436 ;; Miscellaneous commands
7438 (defun vhdl-show-syntactic-information ()
7439 "Show syntactic information for current line."
7440 (interactive)
7441 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7442 (vhdl-keep-region-active))
7444 ;; Verification and regression functions:
7446 (defun vhdl-regress-line (&optional arg)
7447 "Check syntactic information for current line."
7448 (interactive "P")
7449 (let ((expected (save-excursion
7450 (end-of-line)
7451 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7452 (forward-char 4)
7453 (read (current-buffer)))))
7454 (actual (vhdl-get-syntactic-context))
7455 (expurgated))
7456 ;; remove the library unit symbols
7457 (mapc
7458 (function
7459 (lambda (elt)
7460 (if (memq (car elt) '(entity configuration package
7461 package-body architecture))
7463 (setq expurgated (append expurgated (list elt))))))
7464 actual)
7465 (if (and (not arg) expected (listp expected))
7466 (if (not (equal expected expurgated))
7467 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7468 (save-excursion
7469 (beginning-of-line)
7470 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7471 (end-of-line)
7472 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7473 (delete-region (point) (line-end-position)))
7474 (insert " -- ")
7475 (insert (format "%s" expurgated))))))
7476 (vhdl-keep-region-active))
7479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7480 ;;; Alignment, beautifying
7481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7483 (defconst vhdl-align-alist
7485 ;; after some keywords
7486 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7487 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7488 ;; before ':'
7489 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7490 ;; after direction specifications
7491 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7492 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7493 ;; before "==", ":=", "=>", and "<="
7494 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7495 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7496 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7497 ;; before some keywords
7498 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7499 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7500 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7501 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7502 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7503 ;; before "=>" since "when/else ... =>" can occur
7504 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7506 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7507 It is searched in order. If REGEXP is found anywhere in the first
7508 line of a region to be aligned, ALIGN-PATTERN will be used for that
7509 region. ALIGN-PATTERN must include the whitespace to be expanded or
7510 contracted. It may also provide regexps for the text surrounding the
7511 whitespace. SUBEXP specifies which sub-expression of
7512 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7514 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7515 ;; Align code
7517 (defvar vhdl-align-try-all-clauses t
7518 "If REGEXP is not found on the first line of the region that clause
7519 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7521 (defun vhdl-do-group (function &optional spacing)
7522 "Apply FUNCTION on group of lines between empty lines."
7523 (let
7524 ;; search for group beginning
7525 ((beg (save-excursion
7526 (if (re-search-backward vhdl-align-group-separate nil t)
7527 (progn (beginning-of-line 2) (back-to-indentation) (point))
7528 (point-min))))
7529 ;; search for group end
7530 (end (save-excursion
7531 (if (re-search-forward vhdl-align-group-separate nil t)
7532 (progn (beginning-of-line) (point))
7533 (point-max)))))
7534 ;; run FUNCTION
7535 (funcall function beg end spacing)))
7537 (defun vhdl-do-list (function &optional spacing)
7538 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7539 parentheses."
7540 (let (beg end)
7541 (save-excursion
7542 ;; search for beginning of balanced group of parentheses
7543 (setq beg (vhdl-re-search-backward "[()]" nil t))
7544 (while (looking-at ")")
7545 (forward-char) (backward-sexp)
7546 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7547 ;; search for end of balanced group of parentheses
7548 (when beg
7549 (forward-list)
7550 (setq end (point))
7551 (goto-char (1+ beg))
7552 (skip-chars-forward " \t\n\r\f")
7553 (setq beg (point))))
7554 ;; run FUNCTION
7555 (if beg
7556 (funcall function beg end spacing)
7557 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7559 (defun vhdl-do-same-indent (function &optional spacing)
7560 "Apply FUNCTION to block of lines with same indent."
7561 (let ((indent (current-indentation))
7562 beg end)
7563 ;; search for first line with same indent
7564 (save-excursion
7565 (while (and (not (bobp))
7566 (or (looking-at "^\\s-*\\(--.*\\)?$")
7567 (= (current-indentation) indent)))
7568 (unless (looking-at "^\\s-*$")
7569 (back-to-indentation) (setq beg (point)))
7570 (beginning-of-line -0)))
7571 ;; search for last line with same indent
7572 (save-excursion
7573 (while (and (not (eobp))
7574 (or (looking-at "^\\s-*\\(--.*\\)?$")
7575 (= (current-indentation) indent)))
7576 (if (looking-at "^\\s-*$")
7577 (beginning-of-line 2)
7578 (beginning-of-line 2)
7579 (setq end (point)))))
7580 ;; run FUNCTION
7581 (funcall function beg end spacing)))
7583 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7584 "Attempt to align a range of lines based on the content of the
7585 lines. The definition of `alignment-list' determines the matching
7586 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7587 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7588 indentation is done before aligning."
7589 (interactive "r\np")
7590 (setq alignment-list (or alignment-list vhdl-align-alist))
7591 (setq spacing (or spacing 1))
7592 (save-excursion
7593 (let (bol indent)
7594 (goto-char end)
7595 (setq end (point-marker))
7596 (goto-char begin)
7597 (setq bol (setq begin (progn (beginning-of-line) (point))))
7598 (when indent
7599 (indent-region bol end nil))))
7600 (let ((copy (copy-alist alignment-list)))
7601 (vhdl-prepare-search-2
7602 (while copy
7603 (save-excursion
7604 (goto-char begin)
7605 (let (element
7606 (eol (point-at-eol)))
7607 (setq element (nth 0 copy))
7608 (when (and (or (and (listp (car element))
7609 (memq major-mode (car element)))
7610 (eq major-mode (car element)))
7611 (or vhdl-align-try-all-clauses
7612 (re-search-forward (car (cdr element)) eol t)))
7613 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7614 (car (cdr (cdr (cdr element)))) spacing))
7615 (setq copy (cdr copy))))))))
7617 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7618 "Align a range of lines from BEGIN to END. The regular expression
7619 MATCH must match exactly one field: the whitespace to be
7620 contracted/expanded. The alignment column will equal the
7621 rightmost column of the widest whitespace block. SPACING is
7622 the amount of extra spaces to add to the calculated maximum required.
7623 SPACING defaults to 1 so that at least one space is inserted after
7624 the token in MATCH."
7625 (setq spacing (or spacing 1))
7626 (setq substr (or substr 1))
7627 (save-excursion
7628 (let (distance (max 0) (lines 0) bol eol width)
7629 ;; Determine the greatest whitespace distance to the alignment
7630 ;; character
7631 (goto-char begin)
7632 (setq eol (point-at-eol)
7633 bol (setq begin (progn (beginning-of-line) (point))))
7634 (while (< bol end)
7635 (save-excursion
7636 (when (and (vhdl-re-search-forward match eol t)
7637 (save-excursion
7638 (goto-char (match-beginning 0))
7639 (forward-char)
7640 (and (not (vhdl-in-literal))
7641 (not (vhdl-in-quote-p))
7642 (not (vhdl-in-extended-identifier-p))))
7643 (not (looking-at "\\s-*$")))
7644 (setq distance (- (match-beginning substr) bol))
7645 (when (> distance max)
7646 (setq max distance))))
7647 (forward-line)
7648 (setq bol (point)
7649 eol (point-at-eol))
7650 (setq lines (1+ lines)))
7651 ;; Now insert enough maxs to push each assignment operator to
7652 ;; the same column. We need to use 'lines' as a counter, since
7653 ;; the location of the mark may change
7654 (goto-char (setq bol begin))
7655 (setq eol (point-at-eol))
7656 (while (> lines 0)
7657 (when (and (vhdl-re-search-forward match eol t)
7658 (save-excursion
7659 (goto-char (match-beginning 0))
7660 (forward-char)
7661 (and (not (vhdl-in-literal))
7662 (not (vhdl-in-quote-p))
7663 (not (vhdl-in-extended-identifier-p))))
7664 (not (looking-at "\\s-*$"))
7665 (> (match-beginning 0) ; not if at boi
7666 (save-excursion (back-to-indentation) (point))))
7667 (setq width (- (match-end substr) (match-beginning substr)))
7668 (setq distance (- (match-beginning substr) bol))
7669 (goto-char (match-beginning substr))
7670 (delete-char width)
7671 (insert-char ? (+ (- max distance) spacing)))
7672 (beginning-of-line)
7673 (forward-line)
7674 (setq bol (point)
7675 eol (point-at-eol))
7676 (setq lines (1- lines))))))
7678 (defun vhdl-align-region-groups (beg end &optional spacing
7679 no-message no-comments)
7680 "Align region, treat groups of lines separately."
7681 (interactive "r\nP")
7682 (save-excursion
7683 (let (orig pos)
7684 (goto-char beg)
7685 (beginning-of-line)
7686 (setq orig (point-marker))
7687 (setq beg (point))
7688 (goto-char end)
7689 (setq end (point-marker))
7690 (untabify beg end)
7691 (unless no-message
7692 (when vhdl-progress-interval
7693 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7694 (count-lines (point-min) end) 0))))
7695 (when (nth 0 vhdl-beautify-options)
7696 (vhdl-fixup-whitespace-region beg end t))
7697 (goto-char beg)
7698 (if (not vhdl-align-groups)
7699 ;; align entire region
7700 (progn (vhdl-align-region-1 beg end spacing)
7701 (unless no-comments
7702 (vhdl-align-inline-comment-region-1 beg end)))
7703 ;; align groups
7704 (while (and (< beg end)
7705 (re-search-forward vhdl-align-group-separate end t))
7706 (setq pos (point-marker))
7707 (vhdl-align-region-1 beg pos spacing)
7708 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7709 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7710 (setq beg (1+ pos))
7711 (goto-char beg))
7712 ;; align last group
7713 (when (< beg end)
7714 (vhdl-align-region-1 beg end spacing)
7715 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7716 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7717 (when vhdl-indent-tabs-mode
7718 (tabify orig end))
7719 (unless no-message
7720 (when vhdl-progress-interval (message "Aligning...done"))
7721 (setq vhdl-progress-info nil)))))
7723 (defun vhdl-align-region (beg end &optional spacing)
7724 "Align region, treat blocks with same indent and argument lists separately."
7725 (interactive "r\nP")
7726 (if (not vhdl-align-same-indent)
7727 ;; align entire region
7728 (vhdl-align-region-groups beg end spacing)
7729 ;; align blocks with same indent and argument lists
7730 (save-excursion
7731 (let ((cur-beg beg)
7732 indent cur-end)
7733 (when vhdl-progress-interval
7734 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7735 (count-lines (point-min) end) 0)))
7736 (goto-char end)
7737 (setq end (point-marker))
7738 (goto-char cur-beg)
7739 (while (< (point) end)
7740 ;; is argument list opening?
7741 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7742 (point) (vhdl-point 'eol)))))
7743 ;; determine region for argument list
7744 (progn (goto-char cur-beg)
7745 (forward-sexp)
7746 (setq cur-end (point))
7747 (beginning-of-line 2))
7748 ;; determine region with same indent
7749 (setq indent (current-indentation))
7750 (setq cur-beg (point))
7751 (setq cur-end (vhdl-point 'bonl))
7752 (beginning-of-line 2)
7753 (while (and (< (point) end)
7754 (or (looking-at "^\\s-*\\(--.*\\)?$")
7755 (= (current-indentation) indent))
7756 (<= (save-excursion
7757 (nth 0 (parse-partial-sexp
7758 (point) (vhdl-point 'eol)))) 0))
7759 (unless (looking-at "^\\s-*$")
7760 (setq cur-end (vhdl-point 'bonl)))
7761 (beginning-of-line 2)))
7762 ;; align region
7763 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7764 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7765 (when vhdl-progress-interval (message "Aligning...done"))
7766 (setq vhdl-progress-info nil)))))
7768 (defun vhdl-align-group (&optional spacing)
7769 "Align group of lines between empty lines."
7770 (interactive)
7771 (vhdl-do-group 'vhdl-align-region spacing))
7773 (defun vhdl-align-list (&optional spacing)
7774 "Align the lines of a list surrounded by a balanced group of parentheses."
7775 (interactive)
7776 (vhdl-do-list 'vhdl-align-region-groups spacing))
7778 (defun vhdl-align-same-indent (&optional spacing)
7779 "Align block of lines with same indent."
7780 (interactive)
7781 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7783 (defun vhdl-align-declarations (&optional spacing)
7784 "Align the lines within the declarative part of a design unit."
7785 (interactive)
7786 (let (beg end)
7787 (vhdl-prepare-search-2
7788 (save-excursion
7789 ;; search for declarative part
7790 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7791 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7792 (setq beg (point))
7793 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7794 (setq end (point)))))
7795 (if beg
7796 (vhdl-align-region-groups beg end spacing)
7797 (error "ERROR: Not within the declarative part of a design unit"))))
7799 (defun vhdl-align-buffer ()
7800 "Align buffer."
7801 (interactive)
7802 (vhdl-align-region (point-min) (point-max)))
7804 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7805 ;; Align inline comments
7807 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7808 "Align inline comments in region."
7809 (save-excursion
7810 (let ((start-max comment-column)
7811 (length-max 0)
7812 comment-list start-list tmp-list start length
7813 cur-start prev-start no-code)
7814 (setq spacing (or spacing 2))
7815 (vhdl-prepare-search-2
7816 (goto-char beg)
7817 ;; search for comment start positions and lengths
7818 (while (< (point) end)
7819 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7820 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7821 (not (save-excursion (goto-char (match-beginning 2))
7822 (vhdl-in-literal))))
7823 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7824 (setq length (- (match-end 2) (match-beginning 2)))
7825 (setq start-max (max start start-max))
7826 (setq length-max (max length length-max))
7827 (push (cons start length) comment-list))
7828 (beginning-of-line 2))
7829 (setq comment-list
7830 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7831 ;; reduce start positions
7832 (setq start-list (list (caar comment-list)))
7833 (setq comment-list (cdr comment-list))
7834 (while comment-list
7835 (unless (or (= (caar comment-list) (car start-list))
7836 (<= (+ (car start-list) (cdar comment-list))
7837 end-comment-column))
7838 (push (caar comment-list) start-list))
7839 (setq comment-list (cdr comment-list)))
7840 ;; align lines as nicely as possible
7841 (goto-char beg)
7842 (while (< (point) end)
7843 (setq cur-start nil)
7844 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7845 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7846 (not (save-excursion
7847 (goto-char (match-beginning 3))
7848 (vhdl-in-literal))))
7849 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7850 (>= (- (match-end 2) (match-beginning 2))
7851 comment-column))))
7852 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7853 (setq length (- (match-end 3) (match-beginning 3)))
7854 (setq no-code (= (match-beginning 1) (match-end 1)))
7855 ;; insert minimum whitespace
7856 (goto-char (match-end 2))
7857 (delete-region (match-beginning 2) (match-end 2))
7858 (insert-char ?\ spacing)
7859 (setq tmp-list start-list)
7860 ;; insert additional whitespace to align
7861 (setq cur-start
7862 (cond
7863 ;; align comment-only line to inline comment of previous line
7864 ((and no-code prev-start
7865 (<= length (- end-comment-column prev-start)))
7866 prev-start)
7867 ;; align all comments at `start-max' if this is possible
7868 ((<= (+ start-max length-max) end-comment-column)
7869 start-max)
7870 ;; align at `comment-column' if possible
7871 ((and (<= start comment-column)
7872 (<= length (- end-comment-column comment-column)))
7873 comment-column)
7874 ;; align at left-most possible start position otherwise
7876 (while (and tmp-list (< (car tmp-list) start))
7877 (setq tmp-list (cdr tmp-list)))
7878 (car tmp-list))))
7879 (indent-to cur-start))
7880 (setq prev-start cur-start)
7881 (beginning-of-line 2))))))
7883 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7884 "Align inline comments within a region. Groups of code lines separated by
7885 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7886 (interactive "r\nP")
7887 (save-excursion
7888 (let (orig pos)
7889 (goto-char beg)
7890 (beginning-of-line)
7891 (setq orig (point-marker))
7892 (setq beg (point))
7893 (goto-char end)
7894 (setq end (point-marker))
7895 (untabify beg end)
7896 (unless no-message (message "Aligning inline comments..."))
7897 (goto-char beg)
7898 (if (not vhdl-align-groups)
7899 ;; align entire region
7900 (vhdl-align-inline-comment-region-1 beg end spacing)
7901 ;; align groups
7902 (while (and (< beg end)
7903 (re-search-forward vhdl-align-group-separate end t))
7904 (setq pos (point-marker))
7905 (vhdl-align-inline-comment-region-1 beg pos spacing)
7906 (setq beg (1+ pos))
7907 (goto-char beg))
7908 ;; align last group
7909 (when (< beg end)
7910 (vhdl-align-inline-comment-region-1 beg end spacing)))
7911 (when vhdl-indent-tabs-mode
7912 (tabify orig end))
7913 (unless no-message (message "Aligning inline comments...done")))))
7915 (defun vhdl-align-inline-comment-group (&optional spacing)
7916 "Align inline comments within a group of lines between empty lines."
7917 (interactive)
7918 (save-excursion
7919 (let ((start (point))
7920 beg end)
7921 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7922 (point-marker) (point-max)))
7923 (goto-char start)
7924 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7925 (point) (point-min)))
7926 (untabify beg end)
7927 (message "Aligning inline comments...")
7928 (vhdl-align-inline-comment-region-1 beg end)
7929 (when vhdl-indent-tabs-mode
7930 (tabify beg end))
7931 (message "Aligning inline comments...done"))))
7933 (defun vhdl-align-inline-comment-buffer ()
7934 "Align inline comments within buffer. Groups of code lines separated by
7935 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7936 (interactive)
7937 (vhdl-align-inline-comment-region (point-min) (point-max)))
7939 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7940 ;; Fixup whitespace
7942 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7943 "Fixup whitespace in region. Surround operator symbols by one space,
7944 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7945 end of line, do nothing in comments and strings."
7946 (interactive "r")
7947 (unless no-message (message "Fixing up whitespace..."))
7948 (save-excursion
7949 (goto-char end)
7950 (setq end (point-marker))
7951 ;; have no space before and one space after `,' and ';'
7952 (goto-char beg)
7953 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7954 (if (match-string 1)
7955 (goto-char (match-end 1))
7956 (replace-match "\\3 " nil nil nil 2)))
7957 ;; have no space after `('
7958 (goto-char beg)
7959 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
7960 (if (match-string 1)
7961 (goto-char (match-end 1))
7962 (replace-match "\\2")))
7963 ;; have no space before `)'
7964 (goto-char beg)
7965 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7966 (if (match-string 1)
7967 (goto-char (match-end 1))
7968 (replace-match "\\2")))
7969 ;; surround operator symbols by one space
7970 (goto-char beg)
7971 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
7972 (if (or (match-string 1)
7973 (<= (match-beginning 0) ; not if at boi
7974 (save-excursion (back-to-indentation) (point))))
7975 (goto-char (match-end 0))
7976 (replace-match "\\3 \\4 \\5")
7977 (goto-char (match-end 2))))
7978 ;; eliminate multiple spaces and spaces at end of line
7979 (goto-char beg)
7980 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7981 (and (looking-at "--.*") (re-search-forward "--.*" end t))
7982 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7983 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7984 (progn (replace-match "" nil nil) t))
7985 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7986 (progn (replace-match ";" nil nil) t))
7987 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7988 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7989 (progn (replace-match " " nil nil) t))
7990 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7991 (progn (replace-match " " nil nil) t))
7992 (and (looking-at "-") (re-search-forward "-" end t))
7993 (re-search-forward "[^ \t\"-]+" end t))))
7994 (unless no-message (message "Fixing up whitespace...done")))
7996 (defun vhdl-fixup-whitespace-buffer ()
7997 "Fixup whitespace in buffer. Surround operator symbols by one space,
7998 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7999 end of line, do nothing in comments."
8000 (interactive)
8001 (vhdl-fixup-whitespace-region (point-min) (point-max)))
8003 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8004 ;; Case fixing
8006 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
8007 "Convert all words matching WORD-REGEXP in region to lower or upper case,
8008 depending on parameter UPPER-CASE."
8009 (let ((case-replace nil)
8010 (last-update 0))
8011 (vhdl-prepare-search-2
8012 (save-excursion
8013 (goto-char end)
8014 (setq end (point-marker))
8015 (goto-char beg)
8016 (while (re-search-forward word-regexp end t)
8017 (or (vhdl-in-literal)
8018 (if upper-case
8019 (upcase-word -1)
8020 (downcase-word -1)))
8021 (when (and count vhdl-progress-interval (not noninteractive)
8022 (< vhdl-progress-interval
8023 (- (nth 1 (current-time)) last-update)))
8024 (message "Fixing case... (%2d%s)"
8025 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
8026 "%")
8027 (setq last-update (nth 1 (current-time)))))
8028 (goto-char end)))))
8030 (defun vhdl-fix-case-region (beg end &optional arg)
8031 "Convert all VHDL words in region to lower or upper case, depending on
8032 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8033 (interactive "r\nP")
8034 (vhdl-fix-case-region-1
8035 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
8036 (vhdl-fix-case-region-1
8037 beg end vhdl-upper-case-types vhdl-types-regexp 1)
8038 (vhdl-fix-case-region-1
8039 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
8040 (vhdl-fix-case-region-1
8041 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
8042 (vhdl-fix-case-region-1
8043 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
8044 (when vhdl-progress-interval (message "Fixing case...done")))
8046 (defun vhdl-fix-case-buffer ()
8047 "Convert all VHDL words in buffer to lower or upper case, depending on
8048 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8049 (interactive)
8050 (vhdl-fix-case-region (point-min) (point-max)))
8052 (defun vhdl-fix-case-word (&optional arg)
8053 "Convert word after cursor to upper case if necessary."
8054 (interactive "p")
8055 (save-excursion
8056 (when arg (backward-word 1))
8057 (vhdl-prepare-search-1
8058 (when (and vhdl-upper-case-keywords
8059 (looking-at vhdl-keywords-regexp))
8060 (upcase-word 1))
8061 (when (and vhdl-upper-case-types
8062 (looking-at vhdl-types-regexp))
8063 (upcase-word 1))
8064 (when (and vhdl-upper-case-attributes
8065 (looking-at vhdl-attributes-regexp))
8066 (upcase-word 1))
8067 (when (and vhdl-upper-case-enum-values
8068 (looking-at vhdl-enum-values-regexp))
8069 (upcase-word 1))
8070 (when (and vhdl-upper-case-constants
8071 (looking-at vhdl-constants-regexp))
8072 (upcase-word 1)))))
8074 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8075 ;; Fix statements
8076 ;; - force each statement to be on a separate line except when on same line
8077 ;; with 'end' keyword
8079 (defun vhdl-fix-statement-region (beg end &optional arg)
8080 "Force statements in region on separate line except when on same line
8081 with 'end' keyword (necessary for correct indentation).
8082 Currently supported keywords: 'begin', 'if'."
8083 (interactive "r\nP")
8084 (vhdl-prepare-search-2
8085 (let (point)
8086 (save-excursion
8087 (goto-char end)
8088 (setq end (point-marker))
8089 (goto-char beg)
8090 ;; `begin' keyword
8091 (while (re-search-forward
8092 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
8093 (goto-char (match-end 0))
8094 (setq point (point-marker))
8095 (when (and (match-string 1)
8096 (or (not (match-string 2))
8097 (save-excursion (goto-char (match-end 2))
8098 (vhdl-in-literal)))
8099 (not (save-excursion (goto-char (match-beginning 1))
8100 (vhdl-in-literal))))
8101 (goto-char (match-beginning 1))
8102 (insert "\n")
8103 (indent-according-to-mode))
8104 (goto-char point))
8105 (goto-char beg)
8106 ;; `for', `if' keywords
8107 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
8108 (goto-char (match-end 1))
8109 (setq point (point-marker))
8110 ;; exception: in literal or preceded by `end', `wait' or label
8111 (when (and (not (save-excursion (goto-char (match-beginning 1))
8112 (vhdl-in-literal)))
8113 (save-excursion
8114 (beginning-of-line 1)
8115 (save-match-data
8116 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8117 (match-beginning 1) t)
8118 (not (string-match
8119 "\\(\\<end\\>\\|\\<wait .*\\|\\w+\\s-*:\\)\\s-*$"
8120 (match-string 1)))))))
8121 (goto-char (match-beginning 1))
8122 (insert "\n")
8123 (indent-according-to-mode))
8124 (goto-char point))))))
8126 (defun vhdl-fix-statement-buffer ()
8127 "Force statements in buffer on separate line except when on same line
8128 with 'end' keyword (necessary for correct indentation)."
8129 (interactive)
8130 (vhdl-fix-statement-region (point-min) (point-max)))
8132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8133 ;; Trailing spaces
8135 (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
8136 "Remove trailing spaces in region."
8137 (interactive "r\nP")
8138 (save-excursion
8139 (goto-char end)
8140 (setq end (point-marker))
8141 (goto-char beg)
8142 (while (re-search-forward "[ \t]+$" end t)
8143 (unless (vhdl-in-literal)
8144 (replace-match "" nil nil)))))
8146 (defun vhdl-remove-trailing-spaces ()
8147 "Remove trailing spaces in buffer."
8148 (interactive)
8149 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8152 ;; Beautify
8154 (defun vhdl-beautify-region (beg end)
8155 "Beautify region by applying indentation, whitespace fixup, alignment, and
8156 case fixing to a region. Calls functions `vhdl-indent-buffer',
8157 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8158 `vhdl-fix-case-buffer'."
8159 (interactive "r")
8160 (setq end (save-excursion (goto-char end) (point-marker)))
8161 (save-excursion ; remove DOS EOL characters in UNIX file
8162 (goto-char beg)
8163 (while (search-forward " " nil t)
8164 (replace-match "" nil t)))
8165 (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
8166 (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
8167 (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
8168 (when (nth 3 vhdl-beautify-options)
8169 (let ((vhdl-align-groups t)) (vhdl-align-region beg end)))
8170 (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
8171 (when (nth 0 vhdl-beautify-options)
8172 (vhdl-remove-trailing-spaces-region beg end)
8173 (if vhdl-indent-tabs-mode (tabify beg end) (untabify beg end))))
8175 (defun vhdl-beautify-buffer ()
8176 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8177 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8178 buffer."
8179 (interactive)
8180 (vhdl-beautify-region (point-min) (point-max))
8181 (when noninteractive (save-buffer)))
8183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8184 ;; Code filling
8186 (defun vhdl-fill-region (beg end &optional arg)
8187 "Fill lines for a region of code."
8188 (interactive "r\np")
8189 (save-excursion
8190 (goto-char beg)
8191 (let ((margin (if arg (current-indentation) (current-column))))
8192 (goto-char end)
8193 (setq end (point-marker))
8194 ;; remove inline comments, newlines and whitespace
8195 (vhdl-comment-kill-region beg end)
8196 (vhdl-comment-kill-inline-region beg end)
8197 (subst-char-in-region beg (1- end) ?\n ?\ )
8198 (vhdl-fixup-whitespace-region beg end)
8199 ;; wrap and end-comment-column
8200 (goto-char beg)
8201 (while (re-search-forward "\\s-" end t)
8202 (when(> (current-column) vhdl-end-comment-column)
8203 (backward-char)
8204 (when (re-search-backward "\\s-" beg t)
8205 (replace-match "\n")
8206 (indent-to margin)))))))
8208 (defun vhdl-fill-group ()
8209 "Fill group of lines between empty lines."
8210 (interactive)
8211 (vhdl-do-group 'vhdl-fill-region))
8213 (defun vhdl-fill-list ()
8214 "Fill the lines of a list surrounded by a balanced group of parentheses."
8215 (interactive)
8216 (vhdl-do-list 'vhdl-fill-region))
8218 (defun vhdl-fill-same-indent ()
8219 "Fill the lines of block of lines with same indent."
8220 (interactive)
8221 (vhdl-do-same-indent 'vhdl-fill-region))
8224 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8225 ;;; Code updating/fixing
8226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8228 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8229 ;; Sensitivity list update
8231 ;; Strategy:
8232 ;; - no sensitivity list is generated for processes with wait statements
8233 ;; - otherwise, do the following:
8234 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8235 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8236 ;; manually entered global signals)
8237 ;; 3. signals from 1. and 2. form the list of visible signals
8238 ;; 4. search for if/elsif conditions containing an event (sequential code)
8239 ;; 5. scan for strings that are within syntactical regions where signals are
8240 ;; read but not within sequential code, and that correspond to visible
8241 ;; signals
8242 ;; 6. replace sensitivity list by list of signals from 5.
8244 (defun vhdl-update-sensitivity-list-process ()
8245 "Update sensitivity list of current process."
8246 (interactive)
8247 (save-excursion
8248 (vhdl-prepare-search-2
8249 (end-of-line)
8250 ;; look whether in process
8251 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8252 (equal (upcase (match-string 2)) "PROCESS")
8253 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8254 (error "ERROR: Not within a process")
8255 (message "Updating sensitivity list...")
8256 (vhdl-update-sensitivity-list)
8257 (message "Updating sensitivity list...done")))))
8259 (defun vhdl-update-sensitivity-list-buffer ()
8260 "Update sensitivity list of all processes in current buffer."
8261 (interactive)
8262 (save-excursion
8263 (vhdl-prepare-search-2
8264 (goto-char (point-min))
8265 (message "Updating sensitivity lists...")
8266 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8267 (goto-char (match-beginning 0))
8268 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8269 (message "Updating sensitivity lists...done")))
8270 (when noninteractive (save-buffer)))
8272 (defun vhdl-update-sensitivity-list ()
8273 "Update sensitivity list."
8274 (let ((proc-beg (point))
8275 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8276 (proc-mid (vhdl-re-search-backward
8277 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8278 seq-region-list)
8279 (cond
8280 ;; error if 'begin' keyword missing
8281 ((not (match-string 2))
8282 (error "ERROR: No 'begin' keyword found"))
8283 ;; search for wait statement (no sensitivity list allowed)
8284 ((progn (goto-char proc-mid)
8285 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8286 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8287 ;; combinational process (update sensitivity list)
8289 (let
8290 ;; scan for visible signals
8291 ((visible-list (vhdl-get-visible-signals))
8292 ;; define syntactic regions where signals are read
8293 (scan-regions-list
8294 '(;; right-hand side of signal/variable assignment
8295 ;; (special case: "<=" is relational operator in a condition)
8296 ((vhdl-re-search-forward "[<:]=" proc-end t)
8297 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8298 ;; if condition
8299 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
8300 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8301 ;; elsif condition
8302 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
8303 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8304 ;; while loop condition
8305 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
8306 (vhdl-re-search-forward "\\<loop\\>" proc-end t))
8307 ;; exit/next condition
8308 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8309 (vhdl-re-search-forward ";" proc-end t))
8310 ;; assert condition
8311 ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
8312 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8313 ;; case expression
8314 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
8315 (vhdl-re-search-forward "\\<is\\>" proc-end t))
8316 ;; parameter list of procedure call, array index
8317 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8318 (1- (point)))
8319 (progn (backward-char) (forward-sexp)
8320 (while (looking-at "(") (forward-sexp)) (point)))))
8321 name field read-list sens-list signal-list tmp-list
8322 sens-beg sens-end beg end margin)
8323 ;; scan for signals in old sensitivity list
8324 (goto-char proc-beg)
8325 (vhdl-re-search-forward "\\<process\\>" proc-mid t)
8326 (if (not (looking-at "[ \t\n\r\f]*("))
8327 (setq sens-beg (point))
8328 (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8329 (goto-char (match-end 1))
8330 (forward-sexp)
8331 (setq sens-end (1- (point)))
8332 (goto-char sens-beg)
8333 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
8334 (setq sens-list
8335 (cons (downcase (match-string 0)) sens-list))
8336 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
8337 (setq signal-list (append visible-list sens-list))
8338 ;; search for sequential parts
8339 (goto-char proc-mid)
8340 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8341 (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
8342 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8343 (goto-char end)
8344 (backward-word 1)
8345 (vhdl-forward-sexp)
8346 (push (cons end (point)) seq-region-list)
8347 (beginning-of-line)))
8348 ;; scan for signals read in process
8349 (while scan-regions-list
8350 (goto-char proc-mid)
8351 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8352 (setq end (eval (nth 1 (car scan-regions-list)))))
8353 (goto-char beg)
8354 (unless (or (vhdl-in-literal)
8355 (and seq-region-list
8356 (let ((tmp-list seq-region-list))
8357 (while (and tmp-list
8358 (< (point) (caar tmp-list)))
8359 (setq tmp-list (cdr tmp-list)))
8360 (and tmp-list (< (point) (cdar tmp-list))))))
8361 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8362 (setq name (match-string 1))
8363 ;; get array index range
8364 (when vhdl-array-index-record-field-in-sensitivity-list
8365 (setq field (match-string 2))
8366 ;; not use if it includes a variable name
8367 (save-match-data
8368 (setq tmp-list visible-list)
8369 (while (and field tmp-list)
8370 (when (string-match
8371 (concat "\\<" (car tmp-list) "\\>") field)
8372 (setq field nil))
8373 (setq tmp-list (cdr tmp-list)))))
8374 (when (and (not (match-string 6)) ; not when formal parameter
8375 (not (and (match-string 5) ; not event attribute
8376 (not (member (downcase (match-string 5))
8377 '("event" "last_event" "transaction")))))
8378 (member (downcase name) signal-list))
8379 ;; not add if name or name+field already exists
8380 (unless
8381 (or (member-ignore-case name read-list)
8382 (member-ignore-case (concat name field) read-list))
8383 (push (concat name field) read-list))
8384 (setq tmp-list read-list)
8385 ;; remove existing name+field if name is added
8386 (save-match-data
8387 (while tmp-list
8388 (when (string-match (concat "^" name field "[(.]")
8389 (car tmp-list))
8390 (setq read-list (delete (car tmp-list) read-list)))
8391 (setq tmp-list (cdr tmp-list)))))
8392 (goto-char (match-end 1)))))
8393 (setq scan-regions-list (cdr scan-regions-list)))
8394 ;; update sensitivity list
8395 (goto-char sens-beg)
8396 (if sens-end
8397 (delete-region sens-beg sens-end)
8398 (when read-list
8399 (insert " ()") (backward-char)))
8400 (setq read-list (sort read-list 'string<))
8401 (when read-list
8402 (setq margin (current-column))
8403 (insert (car read-list))
8404 (setq read-list (cdr read-list))
8405 (while read-list
8406 (insert ",")
8407 (if (<= (+ (current-column) (length (car read-list)) 2)
8408 end-comment-column)
8409 (insert " ")
8410 (insert "\n") (indent-to margin))
8411 (insert (car read-list))
8412 (setq read-list (cdr read-list)))))))))
8414 (defun vhdl-get-visible-signals ()
8415 "Get all signals visible in the current block."
8416 (let (beg end signal-list entity-name file-name)
8417 (vhdl-prepare-search-2
8418 ;; get entity name
8419 (save-excursion
8420 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8421 (not (equal "END" (upcase (match-string 1))))
8422 (setq entity-name (match-string 2)))
8423 (error "ERROR: Not within an architecture")))
8424 ;; search for signals declared in entity port clause
8425 (save-excursion
8426 (goto-char (point-min))
8427 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8428 (setq file-name
8429 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8430 "." (file-name-extension (buffer-file-name)))))
8431 (vhdl-visit-file
8432 file-name t
8433 (vhdl-prepare-search-2
8434 (goto-char (point-min))
8435 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8436 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8437 (when (setq beg (vhdl-re-search-forward
8438 "\\<port[ \t\n\r\f]*("
8439 (save-excursion
8440 (re-search-forward "^end\\>" nil t)) t))
8441 (setq end (save-excursion
8442 (backward-char) (forward-sexp) (point)))
8443 (vhdl-forward-syntactic-ws)
8444 (while (< (point) end)
8445 (when (looking-at "signal[ \t\n\r\f]+")
8446 (goto-char (match-end 0)))
8447 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8448 (setq signal-list
8449 (cons (downcase (match-string 1)) signal-list))
8450 (goto-char (match-end 0))
8451 (vhdl-forward-syntactic-ws))
8452 (re-search-forward ";" end 1)
8453 (vhdl-forward-syntactic-ws)))))))
8454 ;; search for signals declared in architecture declarative part
8455 (save-excursion
8456 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8457 (not (equal "END" (upcase (match-string 1))))
8458 (setq end (re-search-forward "^begin\\>" nil t))))
8459 (error "ERROR: No architecture declarative part found")
8460 ;; scan for all declared signal and alias names
8461 (goto-char beg)
8462 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8463 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8464 (if (match-string 2)
8465 ;; scan signal name
8466 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8467 (setq signal-list
8468 (cons (downcase (match-string 1)) signal-list))
8469 (goto-char (match-end 0)))
8470 ;; scan alias name, check is alias of (declared) signal
8471 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8472 (member (downcase (match-string 2)) signal-list))
8473 (setq signal-list
8474 (cons (downcase (match-string 1)) signal-list))
8475 (goto-char (match-end 0))))
8476 (setq beg (point))))))
8477 ;; search for signals declared in surrounding block declarative parts
8478 (save-excursion
8479 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*\\(block\\|\\(for\\|if\\).*\\<generate\\>\\)\\|\\(end\\)\\s-+block\\)\\>" nil t))
8480 (match-string 4))
8481 (goto-char (match-end 4))
8482 (vhdl-backward-sexp)
8483 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*\\(block\\|generate\\)\\>" nil t))
8484 beg)
8485 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8486 ;; scan for all declared signal names
8487 (goto-char beg)
8488 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8489 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8490 (if (match-string 2)
8491 ;; scan signal name
8492 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8493 (setq signal-list
8494 (cons (downcase (match-string 1)) signal-list))
8495 (goto-char (match-end 0)))
8496 ;; scan alias name, check is alias of (declared) signal
8497 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8498 (member (downcase (match-string 2)) signal-list))
8499 (setq signal-list
8500 (cons (downcase (match-string 1)) signal-list))
8501 (goto-char (match-end 0))))))
8502 (goto-char beg)))
8503 signal-list)))
8505 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8506 ;; Generic/port clause fixing
8508 (defun vhdl-fix-clause-buffer ()
8509 "Fix all generic/port clauses in current buffer."
8510 (interactive)
8511 (save-excursion
8512 (vhdl-prepare-search-2
8513 (goto-char (point-min))
8514 (message "Fixing generic/port clauses...")
8515 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8516 (goto-char (match-end 0))
8517 (condition-case nil (vhdl-fix-clause) (error "")))
8518 (message "Fixing generic/port clauses...done"))))
8520 (defun vhdl-fix-clause ()
8521 "Fix closing parenthesis within generic/port clause."
8522 (interactive)
8523 (save-excursion
8524 (vhdl-prepare-search-2
8525 (let ((pos (point))
8526 beg end)
8527 (end-of-line)
8528 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8529 (error "ERROR: Not within a generic/port clause")
8530 ;; search for end of clause
8531 (goto-char (match-end 0))
8532 (setq beg (1- (point)))
8533 (vhdl-forward-syntactic-ws)
8534 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8535 (goto-char (1- (match-end 0)))
8536 (setq end (point-marker))
8537 (forward-char)
8538 (vhdl-forward-syntactic-ws))
8539 (goto-char end)
8540 (when (> pos (point-at-eol))
8541 (error "ERROR: Not within a generic/port clause"))
8542 ;; delete closing parenthesis on separate line (not supported style)
8543 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8544 (vhdl-line-kill)
8545 (vhdl-backward-syntactic-ws)
8546 (setq end (point-marker))
8547 (insert ";"))
8548 ;; delete superfluous parentheses
8549 (while (progn (goto-char beg)
8550 (condition-case () (forward-sexp)
8551 (error (goto-char (point-max))))
8552 (< (point) end))
8553 (delete-char -1))
8554 ;; add closing parenthesis
8555 (when (> (point) end)
8556 (goto-char end)
8557 (insert ")")))))))
8560 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8561 ;;; Electrification
8562 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8564 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8565 "Syntax of prompt inserted by template generators.")
8567 (defvar vhdl-template-invoked-by-hook nil
8568 "Indicates whether a template has been invoked by a hook or by key or menu.
8569 Used for undoing after template abortion.")
8571 ;; correct different behavior of function `unread-command-events' in XEmacs
8572 (defun vhdl-character-to-event (arg))
8573 (defalias 'vhdl-character-to-event
8574 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8576 (defun vhdl-work-library ()
8577 "Return the working library name of the current project or \"work\" if no
8578 project is defined."
8579 (vhdl-resolve-env-variable
8580 (or (nth 6 (vhdl-aget vhdl-project-alist vhdl-project))
8581 vhdl-default-library)))
8583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8584 ;; Enabling/disabling
8586 (define-minor-mode vhdl-electric-mode
8587 "Toggle VHDL electric mode.
8588 With a prefix argument ARG, enable the mode if ARG is positive,
8589 and disable it otherwise. If called from Lisp, enable it if ARG
8590 is omitted or nil."
8591 :global t :group 'vhdl-mode)
8593 (define-minor-mode vhdl-stutter-mode
8594 "Toggle VHDL stuttering mode.
8595 With a prefix argument ARG, enable the mode if ARG is positive,
8596 and disable it otherwise. If called from Lisp, enable it if ARG
8597 is omitted or nil."
8598 :global t :group 'vhdl-mode)
8600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8601 ;; Stuttering
8603 (defun vhdl-electric-dash (count)
8604 "-- starts a comment, --- draws a horizontal line,
8605 ---- starts a display comment."
8606 (interactive "p")
8607 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8608 (cond
8609 ((and abbrev-start-location (= abbrev-start-location (point)))
8610 (setq abbrev-start-location nil)
8611 (goto-char last-abbrev-location)
8612 (beginning-of-line nil)
8613 (vhdl-comment-display))
8614 ((/= (preceding-char) ?-) ; standard dash (minus)
8615 (self-insert-command count))
8616 (t (self-insert-command count)
8617 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8618 (let ((next-input (read-char)))
8619 (if (= next-input ?-) ; triple dash
8620 (progn
8621 (vhdl-comment-display-line)
8622 (message
8623 "Enter '-' for display comment, else continue coding")
8624 (let ((next-input (read-char)))
8625 (if (= next-input ?-) ; four dashes
8626 (vhdl-comment-display t)
8627 (setq unread-command-events ; pushback the char
8628 (list (vhdl-character-to-event next-input))))))
8629 (setq unread-command-events ; pushback the char
8630 (list (vhdl-character-to-event next-input)))
8631 (vhdl-comment-insert)))))
8632 (self-insert-command count)))
8634 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8635 (interactive "p")
8636 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8637 (if (= (preceding-char) ?\()
8638 (progn (delete-char -1) (insert-char ?\[ 1))
8639 (insert-char ?\( 1))
8640 (self-insert-command count)))
8642 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8643 (interactive "p")
8644 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8645 (progn
8646 (if (= (preceding-char) ?\))
8647 (progn (delete-char -1) (insert-char ?\] 1))
8648 (insert-char ?\) 1))
8649 (blink-matching-open))
8650 (self-insert-command count)))
8652 (defun vhdl-electric-quote (count) "'' --> \""
8653 (interactive "p")
8654 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8655 (if (= (preceding-char) vhdl-last-input-event)
8656 (progn (delete-char -1) (insert-char ?\" 1))
8657 (insert-char ?\' 1))
8658 (self-insert-command count)))
8660 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8661 (interactive "p")
8662 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8663 (cond ((= (preceding-char) vhdl-last-input-event)
8664 (progn (delete-char -1)
8665 (unless (eq (preceding-char) ? ) (insert " "))
8666 (insert ": ")
8667 (setq this-command 'vhdl-electric-colon)))
8668 ((and
8669 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8670 (progn (delete-char -1) (insert "= ")))
8671 (t (insert-char ?\; 1)))
8672 (self-insert-command count)))
8674 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8675 (interactive "p")
8676 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8677 (cond ((= (preceding-char) vhdl-last-input-event)
8678 (progn (delete-char -1)
8679 (unless (eq (preceding-char) ? ) (insert " "))
8680 (insert "<= ")))
8681 (t (insert-char ?\, 1)))
8682 (self-insert-command count)))
8684 (defun vhdl-electric-period (count) "'..' --> ' => '"
8685 (interactive "p")
8686 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8687 (cond ((= (preceding-char) vhdl-last-input-event)
8688 (progn (delete-char -1)
8689 (unless (eq (preceding-char) ? ) (insert " "))
8690 (insert "=> ")))
8691 (t (insert-char ?\. 1)))
8692 (self-insert-command count)))
8694 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8695 (interactive "p")
8696 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8697 (cond ((= (preceding-char) vhdl-last-input-event)
8698 (progn (delete-char -1)
8699 (unless (eq (preceding-char) ? ) (insert " "))
8700 (insert "== ")))
8701 (t (insert-char ?\= 1)))
8702 (self-insert-command count)))
8704 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8705 ;; VHDL templates
8707 (defun vhdl-template-paired-parens ()
8708 "Insert a pair of round parentheses, placing point between them."
8709 (interactive)
8710 (insert "()")
8711 (backward-char))
8713 (defun vhdl-template-alias ()
8714 "Insert alias declaration."
8715 (interactive)
8716 (let ((start (point)))
8717 (vhdl-insert-keyword "ALIAS ")
8718 (when (vhdl-template-field "name" nil t start (point))
8719 (insert " : ")
8720 (unless (vhdl-template-field
8721 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8722 nil t)
8723 (delete-char -3))
8724 (vhdl-insert-keyword " IS ")
8725 (vhdl-template-field "name" ";")
8726 (vhdl-comment-insert-inline))))
8728 (defun vhdl-template-architecture ()
8729 "Insert architecture."
8730 (interactive)
8731 (let ((margin (current-indentation))
8732 (start (point))
8733 arch-name)
8734 (vhdl-insert-keyword "ARCHITECTURE ")
8735 (when (setq arch-name
8736 (vhdl-template-field "name" nil t start (point)))
8737 (vhdl-insert-keyword " OF ")
8738 (if (save-excursion
8739 (vhdl-prepare-search-1
8740 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8741 (insert (match-string 1))
8742 (vhdl-template-field "entity name"))
8743 (vhdl-insert-keyword " IS\n")
8744 (vhdl-template-begin-end
8745 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8746 (memq vhdl-insert-empty-lines '(unit all))))))
8748 (defun vhdl-template-array (kind &optional secondary)
8749 "Insert array type definition."
8750 (interactive)
8751 (let ((start (point)))
8752 (vhdl-insert-keyword "ARRAY (")
8753 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8754 secondary)
8755 (vhdl-insert-keyword ") OF ")
8756 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8757 (vhdl-insert-keyword ";"))))
8759 (defun vhdl-template-assert ()
8760 "Insert an assertion statement."
8761 (interactive)
8762 (let ((start (point)))
8763 (vhdl-insert-keyword "ASSERT ")
8764 (when vhdl-conditions-in-parenthesis (insert "("))
8765 (when (vhdl-template-field "condition (negated)" nil t start (point))
8766 (when vhdl-conditions-in-parenthesis (insert ")"))
8767 (setq start (point))
8768 (vhdl-insert-keyword " REPORT ")
8769 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8770 (delete-region start (point)))
8771 (setq start (point))
8772 (vhdl-insert-keyword " SEVERITY ")
8773 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8774 (delete-region start (point)))
8775 (insert ";"))))
8777 (defun vhdl-template-attribute ()
8778 "Insert an attribute declaration or specification."
8779 (interactive)
8780 (if (eq (vhdl-decision-query
8781 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8782 (vhdl-template-attribute-spec)
8783 (vhdl-template-attribute-decl)))
8785 (defun vhdl-template-attribute-decl ()
8786 "Insert an attribute declaration."
8787 (interactive)
8788 (let ((start (point)))
8789 (vhdl-insert-keyword "ATTRIBUTE ")
8790 (when (vhdl-template-field "name" " : " t start (point))
8791 (vhdl-template-field "type" ";")
8792 (vhdl-comment-insert-inline))))
8794 (defun vhdl-template-attribute-spec ()
8795 "Insert an attribute specification."
8796 (interactive)
8797 (let ((start (point)))
8798 (vhdl-insert-keyword "ATTRIBUTE ")
8799 (when (vhdl-template-field "name" nil t start (point))
8800 (vhdl-insert-keyword " OF ")
8801 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8802 (vhdl-template-field "entity class")
8803 (vhdl-insert-keyword " IS ")
8804 (vhdl-template-field "expression" ";"))))
8806 (defun vhdl-template-block ()
8807 "Insert a block."
8808 (interactive)
8809 (let ((margin (current-indentation))
8810 (start (point))
8811 label)
8812 (vhdl-insert-keyword ": BLOCK ")
8813 (goto-char start)
8814 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8815 (forward-word 1)
8816 (forward-char 1)
8817 (insert "(")
8818 (if (vhdl-template-field "[guard expression]" nil t)
8819 (insert ")")
8820 (delete-char -2))
8821 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8822 (insert "\n")
8823 (vhdl-template-begin-end "BLOCK" label margin)
8824 (vhdl-comment-block))))
8826 (defun vhdl-template-block-configuration ()
8827 "Insert a block configuration statement."
8828 (interactive)
8829 (let ((margin (current-indentation))
8830 (start (point)))
8831 (vhdl-insert-keyword "FOR ")
8832 (when (vhdl-template-field "block name" nil t start (point))
8833 (vhdl-insert-keyword "\n\n")
8834 (indent-to margin)
8835 (vhdl-insert-keyword "END FOR;")
8836 (end-of-line 0)
8837 (indent-to (+ margin vhdl-basic-offset)))))
8839 (defun vhdl-template-break ()
8840 "Insert a break statement."
8841 (interactive)
8842 (let (position)
8843 (vhdl-insert-keyword "BREAK")
8844 (setq position (point))
8845 (insert " ")
8846 (while (or
8847 (progn (vhdl-insert-keyword "FOR ")
8848 (if (vhdl-template-field "[quantity name]" " USE " t)
8849 (progn (vhdl-template-field "quantity name" " => ") t)
8850 (delete-region (point)
8851 (progn (forward-word -1) (point)))
8852 nil))
8853 (vhdl-template-field "[quantity name]" " => " t))
8854 (vhdl-template-field "expression")
8855 (setq position (point))
8856 (insert ", "))
8857 (delete-region position (point))
8858 (unless (vhdl-sequential-statement-p)
8859 (vhdl-insert-keyword " ON ")
8860 (if (vhdl-template-field "[sensitivity list]" nil t)
8861 (setq position (point))
8862 (delete-region position (point))))
8863 (vhdl-insert-keyword " WHEN ")
8864 (when vhdl-conditions-in-parenthesis (insert "("))
8865 (if (vhdl-template-field "[condition]" nil t)
8866 (when vhdl-conditions-in-parenthesis (insert ")"))
8867 (delete-region position (point)))
8868 (insert ";")))
8870 (defun vhdl-template-case (&optional kind)
8871 "Insert a case statement."
8872 (interactive)
8873 (let ((margin (current-indentation))
8874 (start (point))
8875 label)
8876 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
8877 (not (vhdl-standard-p 'ams))) 'is 'use)))
8878 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8879 (vhdl-insert-keyword "CASE ")
8880 (vhdl-insert-keyword ": CASE ")
8881 (goto-char start)
8882 (setq label (vhdl-template-field "[label]" nil t))
8883 (unless label (delete-char 2))
8884 (forward-word 1)
8885 (forward-char 1))
8886 (when (vhdl-template-field "expression" nil t start (point))
8887 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8888 (indent-to margin)
8889 (vhdl-insert-keyword "END CASE")
8890 (when label (insert " " label))
8891 (insert ";")
8892 (forward-line -1)
8893 (indent-to (+ margin vhdl-basic-offset))
8894 (vhdl-insert-keyword "WHEN ")
8895 (let ((position (point)))
8896 (insert " => ;\n")
8897 (indent-to (+ margin vhdl-basic-offset))
8898 (vhdl-insert-keyword "WHEN OTHERS => null;")
8899 (goto-char position)))))
8901 (defun vhdl-template-case-is ()
8902 "Insert a sequential case statement."
8903 (interactive)
8904 (vhdl-template-case 'is))
8906 (defun vhdl-template-case-use ()
8907 "Insert a simultaneous case statement."
8908 (interactive)
8909 (vhdl-template-case 'use))
8911 (defun vhdl-template-component ()
8912 "Insert a component declaration."
8913 (interactive)
8914 (vhdl-template-component-decl))
8916 (defun vhdl-template-component-conf ()
8917 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8918 since these are almost equivalent)."
8919 (interactive)
8920 (let ((margin (current-indentation))
8921 (result (vhdl-template-configuration-spec t)))
8922 (when result
8923 (insert "\n")
8924 (indent-to margin)
8925 (vhdl-insert-keyword "END FOR;")
8926 (when (eq result 'no-use)
8927 (end-of-line -0)))))
8929 (defun vhdl-template-component-decl ()
8930 "Insert a component declaration."
8931 (interactive)
8932 (let ((margin (current-indentation))
8933 (start (point))
8934 name end-column)
8935 (vhdl-insert-keyword "COMPONENT ")
8936 (when (setq name (vhdl-template-field "name" nil t start (point)))
8937 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8938 (insert "\n\n")
8939 (indent-to margin)
8940 (vhdl-insert-keyword "END COMPONENT")
8941 (unless (vhdl-standard-p '87) (insert " " name))
8942 (insert ";")
8943 (setq end-column (current-column))
8944 (end-of-line -0)
8945 (indent-to (+ margin vhdl-basic-offset))
8946 (vhdl-template-generic-list t t)
8947 (insert "\n")
8948 (indent-to (+ margin vhdl-basic-offset))
8949 (vhdl-template-port-list t)
8950 (beginning-of-line 2)
8951 (forward-char end-column))))
8953 (defun vhdl-template-component-inst ()
8954 "Insert a component instantiation statement."
8955 (interactive)
8956 (let ((margin (current-indentation))
8957 (start (point))
8958 unit position)
8959 (when (vhdl-template-field "instance label" nil t start (point))
8960 (insert ": ")
8961 (if (not (vhdl-use-direct-instantiation))
8962 (vhdl-template-field "component name")
8963 ;; direct instantiation
8964 (setq unit (vhdl-template-field
8965 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8966 (setq unit (upcase (or unit "")))
8967 (cond ((equal unit "ENTITY")
8968 (let ((begin (point)))
8969 (vhdl-template-field "library name" "." t begin (point) nil
8970 (vhdl-work-library))
8971 (vhdl-template-field "entity name" "(")
8972 (if (vhdl-template-field "[architecture name]" nil t)
8973 (insert ")")
8974 (delete-char -1))))
8975 ((equal unit "CONFIGURATION")
8976 (vhdl-template-field "library name" "." nil nil nil nil
8977 (vhdl-work-library))
8978 (vhdl-template-field "configuration name"))
8979 (t (vhdl-template-field "component name"))))
8980 (insert "\n")
8981 (indent-to (+ margin vhdl-basic-offset))
8982 (setq position (point))
8983 (vhdl-insert-keyword "GENERIC ")
8984 (when (vhdl-template-map position t t)
8985 (insert "\n")
8986 (indent-to (+ margin vhdl-basic-offset)))
8987 (setq position (point))
8988 (vhdl-insert-keyword "PORT ")
8989 (unless (vhdl-template-map position t t)
8990 (delete-region (line-beginning-position) (point))
8991 (delete-char -1))
8992 (insert ";"))))
8994 (defun vhdl-template-conditional-signal-asst ()
8995 "Insert a conditional signal assignment."
8996 (interactive)
8997 (when (vhdl-template-field "target signal")
8998 (insert " <= ")
8999 (let ((margin (current-column))
9000 (start (point))
9001 position)
9002 (vhdl-template-field "waveform")
9003 (setq position (point))
9004 (vhdl-insert-keyword " WHEN ")
9005 (when vhdl-conditions-in-parenthesis (insert "("))
9006 (while (and (vhdl-template-field "[condition]" nil t)
9007 (progn
9008 (when vhdl-conditions-in-parenthesis (insert ")"))
9009 (setq position (point))
9010 (vhdl-insert-keyword " ELSE")
9011 (insert "\n")
9012 (indent-to margin)
9013 (vhdl-template-field "[waveform]" nil t)))
9014 (setq position (point))
9015 (vhdl-insert-keyword " WHEN ")
9016 (when vhdl-conditions-in-parenthesis (insert "(")))
9017 (delete-region position (point))
9018 (insert ";")
9019 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9021 (defun vhdl-template-configuration ()
9022 "Insert a configuration specification if within an architecture,
9023 a block or component configuration if within a configuration declaration,
9024 a configuration declaration if not within a design unit."
9025 (interactive)
9026 (vhdl-prepare-search-1
9027 (cond
9028 ((and (save-excursion ; architecture body
9029 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
9030 (equal "ARCHITECTURE" (upcase (match-string 1))))
9031 (vhdl-template-configuration-spec))
9032 ((and (save-excursion ; configuration declaration
9033 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9034 (equal "CONFIGURATION" (upcase (match-string 1))))
9035 (if (eq (vhdl-decision-query
9036 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
9037 (vhdl-template-component-conf)
9038 (vhdl-template-block-configuration)))
9039 (t (vhdl-template-configuration-decl))))) ; otherwise
9041 (defun vhdl-template-configuration-spec (&optional optional-use)
9042 "Insert a configuration specification."
9043 (interactive)
9044 (let ((margin (current-indentation))
9045 (start (point))
9046 aspect position)
9047 (vhdl-insert-keyword "FOR ")
9048 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9049 t start (point))
9050 (vhdl-template-field "component name" "\n")
9051 (indent-to (+ margin vhdl-basic-offset))
9052 (setq start (point))
9053 (vhdl-insert-keyword "USE ")
9054 (if (and optional-use
9055 (not (setq aspect (vhdl-template-field
9056 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
9057 (progn (delete-region start (point)) 'no-use)
9058 (unless optional-use
9059 (setq aspect (vhdl-template-field
9060 "ENTITY | CONFIGURATION | OPEN" " ")))
9061 (setq aspect (upcase (or aspect "")))
9062 (cond ((equal aspect "ENTITY")
9063 (vhdl-template-field "library name" "." nil nil nil nil
9064 (vhdl-work-library))
9065 (vhdl-template-field "entity name" "(")
9066 (if (vhdl-template-field "[architecture name]" nil t)
9067 (insert ")")
9068 (delete-char -1))
9069 (insert "\n")
9070 (indent-to (+ margin (* 2 vhdl-basic-offset)))
9071 (setq position (point))
9072 (vhdl-insert-keyword "GENERIC ")
9073 (when (vhdl-template-map position t t)
9074 (insert "\n")
9075 (indent-to (+ margin (* 2 vhdl-basic-offset))))
9076 (setq position (point))
9077 (vhdl-insert-keyword "PORT ")
9078 (unless (vhdl-template-map position t t)
9079 (delete-region (line-beginning-position) (point))
9080 (delete-char -1))
9081 (insert ";")
9083 ((equal aspect "CONFIGURATION")
9084 (vhdl-template-field "library name" "." nil nil nil nil
9085 (vhdl-work-library))
9086 (vhdl-template-field "configuration name" ";"))
9087 (t (delete-char -1) (insert ";") t))))))
9090 (defun vhdl-template-configuration-decl ()
9091 "Insert a configuration declaration."
9092 (interactive)
9093 (let ((margin (current-indentation))
9094 (start (point))
9095 entity-exists string name position)
9096 (vhdl-insert-keyword "CONFIGURATION ")
9097 (when (setq name (vhdl-template-field "name" nil t start (point)))
9098 (vhdl-insert-keyword " OF ")
9099 (save-excursion
9100 (vhdl-prepare-search-1
9101 (setq entity-exists (vhdl-re-search-backward
9102 "\\<entity \\(\\w*\\) is\\>" nil t))
9103 (setq string (match-string 1))))
9104 (if (and entity-exists (not (equal string "")))
9105 (insert string)
9106 (vhdl-template-field "entity name"))
9107 (vhdl-insert-keyword " IS\n")
9108 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9109 (indent-to (+ margin vhdl-basic-offset))
9110 (setq position (point))
9111 (insert "\n")
9112 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9113 (indent-to margin)
9114 (vhdl-insert-keyword "END ")
9115 (unless (vhdl-standard-p '87)
9116 (vhdl-insert-keyword "CONFIGURATION "))
9117 (insert name ";")
9118 (goto-char position))))
9120 (defun vhdl-template-constant ()
9121 "Insert a constant declaration."
9122 (interactive)
9123 (let ((start (point))
9124 (in-arglist (vhdl-in-argument-list-p)))
9125 (vhdl-insert-keyword "CONSTANT ")
9126 (when (vhdl-template-field "name" nil t start (point))
9127 (insert " : ")
9128 (when in-arglist (vhdl-insert-keyword "IN "))
9129 (vhdl-template-field "type")
9130 (if in-arglist
9131 (progn (insert ";")
9132 (vhdl-comment-insert-inline))
9133 (let ((position (point)))
9134 (insert " := ")
9135 (unless (vhdl-template-field "[initialization]" nil t)
9136 (delete-region position (point)))
9137 (insert ";")
9138 (vhdl-comment-insert-inline))))))
9140 (defun vhdl-template-default ()
9141 "Insert nothing."
9142 (interactive)
9143 (insert " ")
9144 (unexpand-abbrev)
9145 (backward-word 1)
9146 (vhdl-case-word 1)
9147 (forward-char 1))
9149 (defun vhdl-template-default-indent ()
9150 "Insert nothing and indent."
9151 (interactive)
9152 (insert " ")
9153 (unexpand-abbrev)
9154 (backward-word 1)
9155 (vhdl-case-word 1)
9156 (forward-char 1)
9157 (indent-according-to-mode))
9159 (defun vhdl-template-disconnect ()
9160 "Insert a disconnect statement."
9161 (interactive)
9162 (let ((start (point)))
9163 (vhdl-insert-keyword "DISCONNECT ")
9164 (when (vhdl-template-field "signal names | OTHERS | ALL"
9165 " : " t start (point))
9166 (vhdl-template-field "type")
9167 (vhdl-insert-keyword " AFTER ")
9168 (vhdl-template-field "time expression" ";"))))
9170 (defun vhdl-template-else ()
9171 "Insert an else statement."
9172 (interactive)
9173 (let (margin)
9174 (vhdl-prepare-search-1
9175 (vhdl-insert-keyword "ELSE")
9176 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
9177 (equal "WHEN" (upcase (match-string 1))))
9178 (insert " ")
9179 (indent-according-to-mode)
9180 (setq margin (current-indentation))
9181 (insert "\n")
9182 (indent-to (+ margin vhdl-basic-offset))))))
9184 (defun vhdl-template-elsif ()
9185 "Insert an elsif statement."
9186 (interactive)
9187 (let ((start (point))
9188 margin)
9189 (vhdl-insert-keyword "ELSIF ")
9190 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
9191 (when vhdl-conditions-in-parenthesis (insert "("))
9192 (when (vhdl-template-field "condition" nil t start (point))
9193 (when vhdl-conditions-in-parenthesis (insert ")"))
9194 (indent-according-to-mode)
9195 (setq margin (current-indentation))
9196 (vhdl-insert-keyword
9197 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
9198 (indent-to (+ margin vhdl-basic-offset))))))
9200 (defun vhdl-template-entity ()
9201 "Insert an entity."
9202 (interactive)
9203 (let ((margin (current-indentation))
9204 (start (point))
9205 name end-column)
9206 (vhdl-insert-keyword "ENTITY ")
9207 (when (setq name (vhdl-template-field "name" nil t start (point)))
9208 (vhdl-insert-keyword " IS\n\n")
9209 (indent-to margin)
9210 (vhdl-insert-keyword "END ")
9211 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9212 (insert name ";")
9213 (setq end-column (current-column))
9214 (end-of-line -0)
9215 (indent-to (+ margin vhdl-basic-offset))
9216 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9217 (indent-to (+ margin vhdl-basic-offset))
9218 (when (vhdl-template-generic-list t)
9219 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9220 (insert "\n")
9221 (indent-to (+ margin vhdl-basic-offset))
9222 (when (vhdl-template-port-list t)
9223 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9224 (beginning-of-line 2)
9225 (forward-char end-column))))
9227 (defun vhdl-template-exit ()
9228 "Insert an exit statement."
9229 (interactive)
9230 (let ((start (point)))
9231 (vhdl-insert-keyword "EXIT ")
9232 (if (vhdl-template-field "[loop label]" nil t start (point))
9233 (let ((position (point)))
9234 (vhdl-insert-keyword " WHEN ")
9235 (when vhdl-conditions-in-parenthesis (insert "("))
9236 (if (vhdl-template-field "[condition]" nil t)
9237 (when vhdl-conditions-in-parenthesis (insert ")"))
9238 (delete-region position (point))))
9239 (delete-char -1))
9240 (insert ";")))
9242 (defun vhdl-template-file ()
9243 "Insert a file declaration."
9244 (interactive)
9245 (let ((start (point)))
9246 (vhdl-insert-keyword "FILE ")
9247 (when (vhdl-template-field "name" nil t start (point))
9248 (insert " : ")
9249 (vhdl-template-field "type")
9250 (unless (vhdl-standard-p '87)
9251 (vhdl-insert-keyword " OPEN ")
9252 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9253 nil t)
9254 (delete-char -6)))
9255 (vhdl-insert-keyword " IS ")
9256 (when (vhdl-standard-p '87)
9257 (vhdl-template-field "[IN | OUT]" " " t))
9258 (vhdl-template-field "filename-string" nil nil nil nil t)
9259 (insert ";")
9260 (vhdl-comment-insert-inline))))
9262 (defun vhdl-template-for ()
9263 "Insert a block or component configuration if within a configuration
9264 declaration, a configuration specification if within an architecture
9265 declarative part (and not within a subprogram), a for-loop if within a
9266 sequential statement part (subprogram or process), and a for-generate
9267 otherwise."
9268 (interactive)
9269 (vhdl-prepare-search-1
9270 (cond
9271 ((vhdl-sequential-statement-p) ; sequential statement
9272 (vhdl-template-for-loop))
9273 ((and (save-excursion ; configuration declaration
9274 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9275 (equal "CONFIGURATION" (upcase (match-string 1))))
9276 (if (eq (vhdl-decision-query
9277 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9278 (vhdl-template-component-conf)
9279 (vhdl-template-block-configuration)))
9280 ((and (save-excursion
9281 (re-search-backward ; architecture declarative part
9282 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9283 (equal "ARCHITECTURE" (upcase (match-string 1))))
9284 (vhdl-template-configuration-spec))
9285 (t (vhdl-template-for-generate))))) ; concurrent statement
9287 (defun vhdl-template-for-generate ()
9288 "Insert a for-generate."
9289 (interactive)
9290 (let ((margin (current-indentation))
9291 (start (point))
9292 label position)
9293 (vhdl-insert-keyword ": FOR ")
9294 (setq position (point-marker))
9295 (goto-char start)
9296 (when (setq label (vhdl-template-field "label" nil t start position))
9297 (goto-char position)
9298 (vhdl-template-field "loop variable")
9299 (vhdl-insert-keyword " IN ")
9300 (vhdl-template-field "range")
9301 (vhdl-template-generate-body margin label))))
9303 (defun vhdl-template-for-loop ()
9304 "Insert a for loop."
9305 (interactive)
9306 (let ((margin (current-indentation))
9307 (start (point))
9308 label index)
9309 (if (not (eq vhdl-optional-labels 'all))
9310 (vhdl-insert-keyword "FOR ")
9311 (vhdl-insert-keyword ": FOR ")
9312 (goto-char start)
9313 (setq label (vhdl-template-field "[label]" nil t))
9314 (unless label (delete-char 2))
9315 (forward-word 1)
9316 (forward-char 1))
9317 (when (setq index (vhdl-template-field "loop variable"
9318 nil t start (point)))
9319 (vhdl-insert-keyword " IN ")
9320 (vhdl-template-field "range")
9321 (vhdl-insert-keyword " LOOP\n\n")
9322 (indent-to margin)
9323 (vhdl-insert-keyword "END LOOP")
9324 (if label
9325 (insert " " label ";")
9326 (insert ";")
9327 (when vhdl-self-insert-comments (insert " -- " index)))
9328 (forward-line -1)
9329 (indent-to (+ margin vhdl-basic-offset)))))
9331 (defun vhdl-template-function (&optional kind)
9332 "Insert a function declaration or body."
9333 (interactive)
9334 (let ((margin (current-indentation))
9335 (start (point))
9336 name)
9337 (vhdl-insert-keyword "FUNCTION ")
9338 (when (setq name (vhdl-template-field "name" nil t start (point)))
9339 (vhdl-template-argument-list t)
9340 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9341 (end-of-line)
9342 (insert "\n")
9343 (indent-to (+ margin vhdl-basic-offset))
9344 (vhdl-insert-keyword "RETURN ")
9345 (vhdl-template-field "type")
9346 (if (if kind (eq kind 'body)
9347 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9348 (progn (vhdl-insert-keyword " IS\n")
9349 (vhdl-template-begin-end
9350 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9351 (vhdl-comment-block))
9352 (insert ";")))))
9354 (defun vhdl-template-function-decl ()
9355 "Insert a function declaration."
9356 (interactive)
9357 (vhdl-template-function 'decl))
9359 (defun vhdl-template-function-body ()
9360 "Insert a function declaration."
9361 (interactive)
9362 (vhdl-template-function 'body))
9364 (defun vhdl-template-generate ()
9365 "Insert a generation scheme."
9366 (interactive)
9367 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9368 (vhdl-template-if-generate)
9369 (vhdl-template-for-generate)))
9371 (defun vhdl-template-generic ()
9372 "Insert generic declaration, or generic map in instantiation statements."
9373 (interactive)
9374 (let ((start (point)))
9375 (vhdl-prepare-search-1
9376 (cond
9377 ((and (save-excursion ; entity declaration
9378 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9379 (equal "ENTITY" (upcase (match-string 1))))
9380 (vhdl-template-generic-list nil))
9381 ((or (save-excursion
9382 (or (beginning-of-line)
9383 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9384 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9385 (vhdl-insert-keyword "GENERIC ")
9386 (vhdl-template-map start))
9387 (t (vhdl-template-generic-list nil t))))))
9389 (defun vhdl-template-group ()
9390 "Insert group or group template declaration."
9391 (interactive)
9392 (let ((start (point)))
9393 (if (eq (vhdl-decision-query
9394 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9395 (vhdl-template-group-template)
9396 (vhdl-template-group-decl))))
9398 (defun vhdl-template-group-decl ()
9399 "Insert group declaration."
9400 (interactive)
9401 (let ((start (point)))
9402 (vhdl-insert-keyword "GROUP ")
9403 (when (vhdl-template-field "name" " : " t start (point))
9404 (vhdl-template-field "template name" " (")
9405 (vhdl-template-field "constituent list" ");")
9406 (vhdl-comment-insert-inline))))
9408 (defun vhdl-template-group-template ()
9409 "Insert group template declaration."
9410 (interactive)
9411 (let ((start (point)))
9412 (vhdl-insert-keyword "GROUP ")
9413 (when (vhdl-template-field "template name" nil t start (point))
9414 (vhdl-insert-keyword " IS (")
9415 (vhdl-template-field "entity class list" ");")
9416 (vhdl-comment-insert-inline))))
9418 (defun vhdl-template-if ()
9419 "Insert a sequential if statement or an if-generate statement."
9420 (interactive)
9421 (if (vhdl-sequential-statement-p)
9422 (vhdl-template-if-then)
9423 (if (and (vhdl-standard-p 'ams)
9424 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9425 (vhdl-template-if-use)
9426 (vhdl-template-if-generate))))
9428 (defun vhdl-template-if-generate ()
9429 "Insert an if-generate."
9430 (interactive)
9431 (let ((margin (current-indentation))
9432 (start (point))
9433 label position)
9434 (vhdl-insert-keyword ": IF ")
9435 (setq position (point-marker))
9436 (goto-char start)
9437 (when (setq label (vhdl-template-field "label" nil t start position))
9438 (goto-char position)
9439 (when vhdl-conditions-in-parenthesis (insert "("))
9440 (vhdl-template-field "condition")
9441 (when vhdl-conditions-in-parenthesis (insert ")"))
9442 (vhdl-template-generate-body margin label))))
9444 (defun vhdl-template-if-then-use (kind)
9445 "Insert a sequential if statement."
9446 (interactive)
9447 (let ((margin (current-indentation))
9448 (start (point))
9449 label)
9450 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9451 (vhdl-insert-keyword "IF ")
9452 (vhdl-insert-keyword ": IF ")
9453 (goto-char start)
9454 (setq label (vhdl-template-field "[label]" nil t))
9455 (unless label (delete-char 2))
9456 (forward-word 1)
9457 (forward-char 1))
9458 (when vhdl-conditions-in-parenthesis (insert "("))
9459 (when (vhdl-template-field "condition" nil t start (point))
9460 (when vhdl-conditions-in-parenthesis (insert ")"))
9461 (vhdl-insert-keyword
9462 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9463 (indent-to margin)
9464 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9465 (when label (insert " " label))
9466 (insert ";")
9467 (forward-line -1)
9468 (indent-to (+ margin vhdl-basic-offset)))))
9470 (defun vhdl-template-if-then ()
9471 "Insert a sequential if statement."
9472 (interactive)
9473 (vhdl-template-if-then-use 'then))
9475 (defun vhdl-template-if-use ()
9476 "Insert a simultaneous if statement."
9477 (interactive)
9478 (vhdl-template-if-then-use 'use))
9480 (defun vhdl-template-instance ()
9481 "Insert a component instantiation statement."
9482 (interactive)
9483 (vhdl-template-component-inst))
9485 (defun vhdl-template-library ()
9486 "Insert a library specification."
9487 (interactive)
9488 (let ((margin (current-indentation))
9489 (start (point))
9490 name end-pos)
9491 (vhdl-insert-keyword "LIBRARY ")
9492 (when (setq name (vhdl-template-field "names" nil t start (point)))
9493 (insert ";")
9494 (unless (string-match "," name)
9495 (setq end-pos (point))
9496 (insert "\n")
9497 (indent-to margin)
9498 (vhdl-insert-keyword "USE ")
9499 (insert name)
9500 (vhdl-insert-keyword "..ALL;")
9501 (backward-char 5)
9502 (if (vhdl-template-field "package name")
9503 (forward-char 5)
9504 (delete-region end-pos (+ (point) 5)))))))
9506 (defun vhdl-template-limit ()
9507 "Insert a limit."
9508 (interactive)
9509 (let ((start (point)))
9510 (vhdl-insert-keyword "LIMIT ")
9511 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9512 t start (point))
9513 (vhdl-template-field "type")
9514 (vhdl-insert-keyword " WITH ")
9515 (vhdl-template-field "real expression" ";"))))
9517 (defun vhdl-template-loop ()
9518 "Insert a loop."
9519 (interactive)
9520 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9521 (cond ((eq char ?w)
9522 (vhdl-template-while-loop))
9523 ((eq char ?f)
9524 (vhdl-template-for-loop))
9525 (t (vhdl-template-bare-loop)))))
9527 (defun vhdl-template-bare-loop ()
9528 "Insert a loop."
9529 (interactive)
9530 (let ((margin (current-indentation))
9531 (start (point))
9532 label)
9533 (if (not (eq vhdl-optional-labels 'all))
9534 (vhdl-insert-keyword "LOOP ")
9535 (vhdl-insert-keyword ": LOOP ")
9536 (goto-char start)
9537 (setq label (vhdl-template-field "[label]" nil t))
9538 (unless label (delete-char 2))
9539 (forward-word 1)
9540 (delete-char 1))
9541 (insert "\n\n")
9542 (indent-to margin)
9543 (vhdl-insert-keyword "END LOOP")
9544 (insert (if label (concat " " label ";") ";"))
9545 (forward-line -1)
9546 (indent-to (+ margin vhdl-basic-offset))))
9548 (defun vhdl-template-map (&optional start optional secondary)
9549 "Insert a map specification with association list."
9550 (interactive)
9551 (let ((start (or start (point)))
9552 margin end-pos)
9553 (vhdl-insert-keyword "MAP (")
9554 (if (not vhdl-association-list-with-formals)
9555 (if (vhdl-template-field
9556 (concat (and optional "[") "association list" (and optional "]"))
9557 ")" (or (not secondary) optional)
9558 (and (not secondary) start) (point))
9560 (if (and optional secondary) (delete-region start (point)))
9561 nil)
9562 (if vhdl-argument-list-indent
9563 (setq margin (current-column))
9564 (setq margin (+ (current-indentation) vhdl-basic-offset))
9565 (insert "\n")
9566 (indent-to margin))
9567 (if (vhdl-template-field
9568 (concat (and optional "[") "formal" (and optional "]"))
9569 " => " (or (not secondary) optional)
9570 (and (not secondary) start) (point))
9571 (progn
9572 (vhdl-template-field "actual" ",")
9573 (setq end-pos (point))
9574 (insert "\n")
9575 (indent-to margin)
9576 (while (vhdl-template-field "[formal]" " => " t)
9577 (vhdl-template-field "actual" ",")
9578 (setq end-pos (point))
9579 (insert "\n")
9580 (indent-to margin))
9581 (delete-region end-pos (point))
9582 (delete-char -1)
9583 (insert ")")
9584 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9586 (when (and optional secondary) (delete-region start (point)))
9587 nil))))
9589 (defun vhdl-template-modify (&optional noerror)
9590 "Actualize modification date."
9591 (interactive)
9592 (vhdl-prepare-search-2
9593 (save-excursion
9594 (goto-char (point-min))
9595 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9596 (progn (delete-region (point) (progn (end-of-line) (point)))
9597 (vhdl-template-insert-date))
9598 (unless noerror
9599 (error "ERROR: Modification date prefix string \"%s\" not found"
9600 vhdl-modify-date-prefix-string))))))
9603 (defun vhdl-template-modify-noerror ()
9604 "Call `vhdl-template-modify' with NOERROR non-nil."
9605 (vhdl-template-modify t))
9607 (defun vhdl-template-nature ()
9608 "Insert a nature declaration."
9609 (interactive)
9610 (let ((start (point))
9611 name mid-pos end-pos)
9612 (vhdl-insert-keyword "NATURE ")
9613 (when (setq name (vhdl-template-field "name" nil t start (point)))
9614 (vhdl-insert-keyword " IS ")
9615 (let ((definition
9616 (upcase
9617 (or (vhdl-template-field
9618 "across type | ARRAY | RECORD")
9619 ""))))
9620 (cond ((equal definition "")
9621 (insert ";"))
9622 ((equal definition "ARRAY")
9623 (delete-region (point) (progn (forward-word -1) (point)))
9624 (vhdl-template-array 'nature t))
9625 ((equal definition "RECORD")
9626 (setq mid-pos (point-marker))
9627 (delete-region (point) (progn (forward-word -1) (point)))
9628 (vhdl-template-record 'nature name t))
9630 (vhdl-insert-keyword " ACROSS ")
9631 (vhdl-template-field "through type")
9632 (vhdl-insert-keyword " THROUGH ")
9633 (vhdl-template-field "reference name")
9634 (vhdl-insert-keyword " REFERENCE;")))
9635 (when mid-pos
9636 (setq end-pos (point-marker))
9637 (goto-char mid-pos)
9638 (end-of-line))
9639 (vhdl-comment-insert-inline)
9640 (when end-pos (goto-char end-pos))))))
9642 (defun vhdl-template-next ()
9643 "Insert a next statement."
9644 (interactive)
9645 (let ((start (point)))
9646 (vhdl-insert-keyword "NEXT ")
9647 (if (vhdl-template-field "[loop label]" nil t start (point))
9648 (let ((position (point)))
9649 (vhdl-insert-keyword " WHEN ")
9650 (when vhdl-conditions-in-parenthesis (insert "("))
9651 (if (vhdl-template-field "[condition]" nil t)
9652 (when vhdl-conditions-in-parenthesis (insert ")"))
9653 (delete-region position (point))))
9654 (delete-char -1))
9655 (insert ";")))
9657 (defun vhdl-template-others ()
9658 "Insert an others aggregate."
9659 (interactive)
9660 (let ((start (point)))
9661 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9662 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9663 (vhdl-insert-keyword "OTHERS => '")
9664 (when (vhdl-template-field "value" nil t start (point))
9665 (insert "')")))
9666 (vhdl-insert-keyword "OTHERS "))))
9668 (defun vhdl-template-package (&optional kind)
9669 "Insert a package specification or body."
9670 (interactive)
9671 (let ((margin (current-indentation))
9672 (start (point))
9673 name body position)
9674 (vhdl-insert-keyword "PACKAGE ")
9675 (setq body (if kind (eq kind 'body)
9676 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9677 (when body
9678 (vhdl-insert-keyword "BODY ")
9679 (when (save-excursion
9680 (vhdl-prepare-search-1
9681 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9682 (insert (setq name (match-string 1)))))
9683 (when (or name
9684 (setq name (vhdl-template-field "name" nil t start (point))))
9685 (vhdl-insert-keyword " IS\n")
9686 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9687 (indent-to (+ margin vhdl-basic-offset))
9688 (setq position (point))
9689 (insert "\n")
9690 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9691 (indent-to margin)
9692 (vhdl-insert-keyword "END ")
9693 (unless (vhdl-standard-p '87)
9694 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9695 (insert (or name "") ";")
9696 (goto-char position))))
9698 (defun vhdl-template-package-decl ()
9699 "Insert a package specification."
9700 (interactive)
9701 (vhdl-template-package 'decl))
9703 (defun vhdl-template-package-body ()
9704 "Insert a package body."
9705 (interactive)
9706 (vhdl-template-package 'body))
9708 (defun vhdl-template-port ()
9709 "Insert a port declaration, or port map in instantiation statements."
9710 (interactive)
9711 (let ((start (point)))
9712 (vhdl-prepare-search-1
9713 (cond
9714 ((and (save-excursion ; entity declaration
9715 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9716 (equal "ENTITY" (upcase (match-string 1))))
9717 (vhdl-template-port-list nil))
9718 ((or (save-excursion
9719 (or (beginning-of-line)
9720 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9721 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9722 (vhdl-insert-keyword "PORT ")
9723 (vhdl-template-map start))
9724 (t (vhdl-template-port-list nil))))))
9726 (defun vhdl-template-procedural ()
9727 "Insert a procedural."
9728 (interactive)
9729 (let ((margin (current-indentation))
9730 (start (point))
9731 (case-fold-search t)
9732 label)
9733 (vhdl-insert-keyword "PROCEDURAL ")
9734 (when (memq vhdl-optional-labels '(process all))
9735 (goto-char start)
9736 (insert ": ")
9737 (goto-char start)
9738 (setq label (vhdl-template-field "[label]" nil t))
9739 (unless label (delete-char 2))
9740 (forward-word 1)
9741 (forward-char 1))
9742 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9743 (insert "\n")
9744 (vhdl-template-begin-end "PROCEDURAL" label margin)
9745 (vhdl-comment-block)))
9747 (defun vhdl-template-procedure (&optional kind)
9748 "Insert a procedure declaration or body."
9749 (interactive)
9750 (let ((margin (current-indentation))
9751 (start (point))
9752 name)
9753 (vhdl-insert-keyword "PROCEDURE ")
9754 (when (setq name (vhdl-template-field "name" nil t start (point)))
9755 (vhdl-template-argument-list)
9756 (if (if kind (eq kind 'body)
9757 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9758 (progn (vhdl-insert-keyword " IS")
9759 (when vhdl-auto-align
9760 (vhdl-align-region-groups start (point) 1))
9761 (end-of-line) (insert "\n")
9762 (vhdl-template-begin-end
9763 (unless (vhdl-standard-p '87) "PROCEDURE")
9764 name margin)
9765 (vhdl-comment-block))
9766 (insert ";")
9767 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9768 (end-of-line)))))
9770 (defun vhdl-template-procedure-decl ()
9771 "Insert a procedure declaration."
9772 (interactive)
9773 (vhdl-template-procedure 'decl))
9775 (defun vhdl-template-procedure-body ()
9776 "Insert a procedure body."
9777 (interactive)
9778 (vhdl-template-procedure 'body))
9780 (defun vhdl-template-process (&optional kind)
9781 "Insert a process."
9782 (interactive)
9783 (let ((margin (current-indentation))
9784 (start (point))
9785 (reset-kind vhdl-reset-kind)
9786 label seq input-signals clock reset final-pos)
9787 (setq seq (if kind (eq kind 'seq)
9788 (eq (vhdl-decision-query
9789 "process" "(c)ombinational or (s)equential?" t) ?s)))
9790 (vhdl-insert-keyword "PROCESS ")
9791 (when (memq vhdl-optional-labels '(process all))
9792 (goto-char start)
9793 (insert ": ")
9794 (goto-char start)
9795 (setq label (vhdl-template-field "[label]" nil t))
9796 (unless label (delete-char 2))
9797 (forward-word 1)
9798 (forward-char 1))
9799 (insert "(")
9800 (if (not seq)
9801 (unless (setq input-signals
9802 (vhdl-template-field "[sensitivity list]" ")" t))
9803 (setq input-signals "")
9804 (delete-char -2))
9805 (setq clock (or (and (not (equal "" vhdl-clock-name))
9806 (progn (insert vhdl-clock-name) vhdl-clock-name))
9807 (vhdl-template-field "clock name") "<clock>"))
9808 (when (eq reset-kind 'query)
9809 (setq reset-kind
9810 (if (eq (vhdl-decision-query
9811 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9812 'async
9813 'sync)))
9814 (when (eq reset-kind 'async)
9815 (insert ", ")
9816 (setq reset (or (and (not (equal "" vhdl-reset-name))
9817 (progn (insert vhdl-reset-name) vhdl-reset-name))
9818 (vhdl-template-field "reset name") "<reset>")))
9819 (insert ")"))
9820 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9821 (insert "\n")
9822 (vhdl-template-begin-end "PROCESS" label margin)
9823 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9824 (when vhdl-prompt-for-comments
9825 (setq final-pos (point-marker))
9826 (vhdl-prepare-search-2
9827 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9828 (vhdl-re-search-backward "\\<process\\>" nil t))
9829 (end-of-line -0)
9830 (if (bobp)
9831 (progn (insert "\n") (forward-line -1))
9832 (insert "\n"))
9833 (indent-to margin)
9834 (insert "-- purpose: ")
9835 (if (not (vhdl-template-field "[description]" nil t))
9836 (vhdl-line-kill-entire)
9837 (insert "\n")
9838 (indent-to margin)
9839 (insert "-- type : ")
9840 (insert (if seq "sequential" "combinational") "\n")
9841 (indent-to margin)
9842 (insert "-- inputs : ")
9843 (if (not seq)
9844 (insert input-signals)
9845 (insert clock ", ")
9846 (when reset (insert reset ", "))
9847 (unless (vhdl-template-field "[signal names]" nil t)
9848 (delete-char -2)))
9849 (insert "\n")
9850 (indent-to margin)
9851 (insert "-- outputs: ")
9852 (vhdl-template-field "[signal names]" nil t))))
9853 (goto-char final-pos))))
9855 (defun vhdl-template-process-comb ()
9856 "Insert a combinational process."
9857 (interactive)
9858 (vhdl-template-process 'comb))
9860 (defun vhdl-template-process-seq ()
9861 "Insert a sequential process."
9862 (interactive)
9863 (vhdl-template-process 'seq))
9865 (defun vhdl-template-quantity ()
9866 "Insert a quantity declaration."
9867 (interactive)
9868 (if (vhdl-in-argument-list-p)
9869 (let ((start (point)))
9870 (vhdl-insert-keyword "QUANTITY ")
9871 (when (vhdl-template-field "names" nil t start (point))
9872 (insert " : ")
9873 (vhdl-template-field "[IN | OUT]" " " t)
9874 (vhdl-template-field "type")
9875 (insert ";")
9876 (vhdl-comment-insert-inline)))
9877 (let ((char (vhdl-decision-query
9878 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9879 (cond ((eq char ?f) (vhdl-template-quantity-free))
9880 ((eq char ?b) (vhdl-template-quantity-branch))
9881 ((eq char ?s) (vhdl-template-quantity-source))
9882 (t (vhdl-template-undo (point) (point)))))))
9884 (defun vhdl-template-quantity-free ()
9885 "Insert a free quantity declaration."
9886 (interactive)
9887 (vhdl-insert-keyword "QUANTITY ")
9888 (vhdl-template-field "names")
9889 (insert " : ")
9890 (vhdl-template-field "type")
9891 (let ((position (point)))
9892 (insert " := ")
9893 (unless (vhdl-template-field "[initialization]" nil t)
9894 (delete-region position (point)))
9895 (insert ";")
9896 (vhdl-comment-insert-inline)))
9898 (defun vhdl-template-quantity-branch ()
9899 "Insert a branch quantity declaration."
9900 (interactive)
9901 (let (position)
9902 (vhdl-insert-keyword "QUANTITY ")
9903 (when (vhdl-template-field "[across names]" " " t)
9904 (vhdl-insert-keyword "ACROSS "))
9905 (when (vhdl-template-field "[through names]" " " t)
9906 (vhdl-insert-keyword "THROUGH "))
9907 (vhdl-template-field "plus terminal name")
9908 (setq position (point))
9909 (vhdl-insert-keyword " TO ")
9910 (unless (vhdl-template-field "[minus terminal name]" nil t)
9911 (delete-region position (point)))
9912 (insert ";")
9913 (vhdl-comment-insert-inline)))
9915 (defun vhdl-template-quantity-source ()
9916 "Insert a source quantity declaration."
9917 (interactive)
9918 (vhdl-insert-keyword "QUANTITY ")
9919 (vhdl-template-field "names")
9920 (insert " : ")
9921 (vhdl-template-field "type" " ")
9922 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9923 (progn (vhdl-insert-keyword "NOISE ")
9924 (vhdl-template-field "power expression"))
9925 (vhdl-insert-keyword "SPECTRUM ")
9926 (vhdl-template-field "magnitude expression" ", ")
9927 (vhdl-template-field "phase expression"))
9928 (insert ";")
9929 (vhdl-comment-insert-inline))
9931 (defun vhdl-template-record (kind &optional name secondary)
9932 "Insert a record type declaration."
9933 (interactive)
9934 (let ((margin (current-indentation))
9935 (start (point))
9936 (first t))
9937 (vhdl-insert-keyword "RECORD\n")
9938 (indent-to (+ margin vhdl-basic-offset))
9939 (when (or (vhdl-template-field "element names"
9940 nil (not secondary) start (point))
9941 secondary)
9942 (while (or first (vhdl-template-field "[element names]" nil t))
9943 (insert " : ")
9944 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9945 (vhdl-comment-insert-inline)
9946 (insert "\n")
9947 (indent-to (+ margin vhdl-basic-offset))
9948 (setq first nil))
9949 (delete-region (line-beginning-position) (point))
9950 (indent-to margin)
9951 (vhdl-insert-keyword "END RECORD")
9952 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9953 (insert ";")
9954 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9956 (defun vhdl-template-report ()
9957 "Insert a report statement."
9958 (interactive)
9959 (let ((start (point)))
9960 (vhdl-insert-keyword "REPORT ")
9961 (if (equal "\"\"" (vhdl-template-field
9962 "string expression" nil t start (point) t))
9963 (delete-char -2)
9964 (setq start (point))
9965 (vhdl-insert-keyword " SEVERITY ")
9966 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9967 (delete-region start (point)))
9968 (insert ";"))))
9970 (defun vhdl-template-return ()
9971 "Insert a return statement."
9972 (interactive)
9973 (let ((start (point)))
9974 (vhdl-insert-keyword "RETURN ")
9975 (unless (vhdl-template-field "[expression]" nil t start (point))
9976 (delete-char -1))
9977 (insert ";")))
9979 (defun vhdl-template-selected-signal-asst ()
9980 "Insert a selected signal assignment."
9981 (interactive)
9982 (let ((margin (current-indentation))
9983 (start (point))
9984 (choices t))
9985 (let ((position (point)))
9986 (vhdl-insert-keyword " SELECT ")
9987 (goto-char position))
9988 (vhdl-insert-keyword "WITH ")
9989 (when (vhdl-template-field "selector expression"
9990 nil t start (+ (point) 7))
9991 (forward-word 1)
9992 (delete-char 1)
9993 (insert "\n")
9994 (indent-to (+ margin vhdl-basic-offset))
9995 (vhdl-template-field "target signal" " <= ")
9996 (insert "\n")
9997 (indent-to (+ margin vhdl-basic-offset))
9998 (vhdl-template-field "waveform")
9999 (vhdl-insert-keyword " WHEN ")
10000 (vhdl-template-field "choices" ",")
10001 (insert "\n")
10002 (indent-to (+ margin vhdl-basic-offset))
10003 (while (and choices (vhdl-template-field "[waveform]" nil t))
10004 (vhdl-insert-keyword " WHEN ")
10005 (if (setq choices (vhdl-template-field "[choices]" "," t))
10006 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10007 (vhdl-insert-keyword "OTHERS")))
10008 (when choices
10009 (fixup-whitespace)
10010 (delete-char -2))
10011 (insert ";")
10012 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10014 (defun vhdl-template-signal ()
10015 "Insert a signal declaration."
10016 (interactive)
10017 (let ((start (point))
10018 (in-arglist (vhdl-in-argument-list-p)))
10019 (vhdl-insert-keyword "SIGNAL ")
10020 (when (vhdl-template-field "names" nil t start (point))
10021 (insert " : ")
10022 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10023 (vhdl-template-field "type")
10024 (if in-arglist
10025 (progn (insert ";")
10026 (vhdl-comment-insert-inline))
10027 (let ((position (point)))
10028 (insert " := ")
10029 (unless (vhdl-template-field "[initialization]" nil t)
10030 (delete-region position (point)))
10031 (insert ";")
10032 (vhdl-comment-insert-inline))))))
10034 (defun vhdl-template-subnature ()
10035 "Insert a subnature declaration."
10036 (interactive)
10037 (let ((start (point))
10038 position)
10039 (vhdl-insert-keyword "SUBNATURE ")
10040 (when (vhdl-template-field "name" nil t start (point))
10041 (vhdl-insert-keyword " IS ")
10042 (vhdl-template-field "nature" " (")
10043 (if (vhdl-template-field "[index range]" nil t)
10044 (insert ")")
10045 (delete-char -2))
10046 (setq position (point))
10047 (vhdl-insert-keyword " TOLERANCE ")
10048 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10049 nil t nil nil t))
10050 (delete-region position (point))
10051 (vhdl-insert-keyword " ACROSS ")
10052 (vhdl-template-field "string expression" nil nil nil nil t)
10053 (vhdl-insert-keyword " THROUGH"))
10054 (insert ";")
10055 (vhdl-comment-insert-inline))))
10057 (defun vhdl-template-subprogram-body ()
10058 "Insert a subprogram body."
10059 (interactive)
10060 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10061 (vhdl-template-function-body)
10062 (vhdl-template-procedure-body)))
10064 (defun vhdl-template-subprogram-decl ()
10065 "Insert a subprogram declaration."
10066 (interactive)
10067 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10068 (vhdl-template-function-decl)
10069 (vhdl-template-procedure-decl)))
10071 (defun vhdl-template-subtype ()
10072 "Insert a subtype declaration."
10073 (interactive)
10074 (let ((start (point)))
10075 (vhdl-insert-keyword "SUBTYPE ")
10076 (when (vhdl-template-field "name" nil t start (point))
10077 (vhdl-insert-keyword " IS ")
10078 (vhdl-template-field "type" " ")
10079 (unless
10080 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
10081 (delete-char -1))
10082 (insert ";")
10083 (vhdl-comment-insert-inline))))
10085 (defun vhdl-template-terminal ()
10086 "Insert a terminal declaration."
10087 (interactive)
10088 (let ((start (point)))
10089 (vhdl-insert-keyword "TERMINAL ")
10090 (when (vhdl-template-field "names" nil t start (point))
10091 (insert " : ")
10092 (vhdl-template-field "nature")
10093 (insert ";")
10094 (vhdl-comment-insert-inline))))
10096 (defun vhdl-template-type ()
10097 "Insert a type declaration."
10098 (interactive)
10099 (let ((start (point))
10100 name mid-pos end-pos)
10101 (vhdl-insert-keyword "TYPE ")
10102 (when (setq name (vhdl-template-field "name" nil t start (point)))
10103 (vhdl-insert-keyword " IS ")
10104 (let ((definition
10105 (upcase
10106 (or (vhdl-template-field
10107 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
10108 ""))))
10109 (cond ((equal definition "")
10110 (delete-char -4)
10111 (insert ";"))
10112 ((equal definition "ARRAY")
10113 (delete-region (point) (progn (forward-word -1) (point)))
10114 (vhdl-template-array 'type t))
10115 ((equal definition "RECORD")
10116 (setq mid-pos (point-marker))
10117 (delete-region (point) (progn (forward-word -1) (point)))
10118 (vhdl-template-record 'type name t))
10119 ((equal definition "ACCESS")
10120 (insert " ")
10121 (vhdl-template-field "type" ";"))
10122 ((equal definition "FILE")
10123 (vhdl-insert-keyword " OF ")
10124 (vhdl-template-field "type" ";"))
10125 ((equal definition "ENUM")
10126 (kill-word -1)
10127 (insert "(")
10128 (setq end-pos (point-marker))
10129 (insert ");"))
10130 (t (insert ";")))
10131 (when mid-pos
10132 (setq end-pos (point-marker))
10133 (goto-char mid-pos)
10134 (end-of-line))
10135 (vhdl-comment-insert-inline)
10136 (when end-pos (goto-char end-pos))))))
10138 (defun vhdl-template-use ()
10139 "Insert a use clause."
10140 (interactive)
10141 (let ((start (point)))
10142 (vhdl-prepare-search-1
10143 (vhdl-insert-keyword "USE ")
10144 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10145 (vhdl-insert-keyword "..ALL;")
10146 (backward-char 6)
10147 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
10148 (forward-char 1)
10149 (vhdl-template-field "package name")
10150 (forward-char 5))))))
10152 (defun vhdl-template-variable ()
10153 "Insert a variable declaration."
10154 (interactive)
10155 (let ((start (point))
10156 (in-arglist (vhdl-in-argument-list-p)))
10157 (vhdl-prepare-search-2
10158 (if (or (save-excursion
10159 (progn (vhdl-beginning-of-block)
10160 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10161 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
10162 (vhdl-insert-keyword "VARIABLE ")
10163 (if (vhdl-standard-p '87)
10164 (error "ERROR: Not within sequential block")
10165 (vhdl-insert-keyword "SHARED VARIABLE "))))
10166 (when (vhdl-template-field "names" nil t start (point))
10167 (insert " : ")
10168 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10169 (vhdl-template-field "type")
10170 (if in-arglist
10171 (progn (insert ";")
10172 (vhdl-comment-insert-inline))
10173 (let ((position (point)))
10174 (insert " := ")
10175 (unless (vhdl-template-field "[initialization]" nil t)
10176 (delete-region position (point)))
10177 (insert ";")
10178 (vhdl-comment-insert-inline))))))
10180 (defun vhdl-template-wait ()
10181 "Insert a wait statement."
10182 (interactive)
10183 (vhdl-insert-keyword "WAIT ")
10184 (unless (vhdl-template-field
10185 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10186 nil t)
10187 (delete-char -1))
10188 (insert ";"))
10190 (defun vhdl-template-when ()
10191 "Indent correctly if within a case statement."
10192 (interactive)
10193 (let ((position (point))
10194 margin)
10195 (vhdl-prepare-search-2
10196 (if (and (= (current-column) (current-indentation))
10197 (vhdl-re-search-forward "\\<end\\>" nil t)
10198 (looking-at "\\s-*\\<case\\>"))
10199 (progn
10200 (setq margin (current-indentation))
10201 (goto-char position)
10202 (delete-horizontal-space)
10203 (indent-to (+ margin vhdl-basic-offset)))
10204 (goto-char position)))
10205 (vhdl-insert-keyword "WHEN ")))
10207 (defun vhdl-template-while-loop ()
10208 "Insert a while loop."
10209 (interactive)
10210 (let* ((margin (current-indentation))
10211 (start (point))
10212 label)
10213 (if (not (eq vhdl-optional-labels 'all))
10214 (vhdl-insert-keyword "WHILE ")
10215 (vhdl-insert-keyword ": WHILE ")
10216 (goto-char start)
10217 (setq label (vhdl-template-field "[label]" nil t))
10218 (unless label (delete-char 2))
10219 (forward-word 1)
10220 (forward-char 1))
10221 (when vhdl-conditions-in-parenthesis (insert "("))
10222 (when (vhdl-template-field "condition" nil t start (point))
10223 (when vhdl-conditions-in-parenthesis (insert ")"))
10224 (vhdl-insert-keyword " LOOP\n\n")
10225 (indent-to margin)
10226 (vhdl-insert-keyword "END LOOP")
10227 (insert (if label (concat " " label ";") ";"))
10228 (forward-line -1)
10229 (indent-to (+ margin vhdl-basic-offset)))))
10231 (defun vhdl-template-with ()
10232 "Insert a with statement (i.e. selected signal assignment)."
10233 (interactive)
10234 (vhdl-prepare-search-1
10235 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10236 (equal ";" (match-string 1)))
10237 (vhdl-template-selected-signal-asst)
10238 (vhdl-insert-keyword "WITH "))))
10240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10241 ;; Special templates
10243 (defun vhdl-template-clocked-wait ()
10244 "Insert a wait statement for rising/falling clock edge."
10245 (interactive)
10246 (let ((start (point))
10247 clock)
10248 (vhdl-insert-keyword "WAIT UNTIL ")
10249 (when (setq clock
10250 (or (and (not (equal "" vhdl-clock-name))
10251 (progn (insert vhdl-clock-name) vhdl-clock-name))
10252 (vhdl-template-field "clock name" nil t start (point))))
10253 (insert "'event")
10254 (vhdl-insert-keyword " AND ")
10255 (insert clock)
10256 (insert
10257 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10258 (vhdl-comment-insert-inline
10259 (concat (if vhdl-clock-rising-edge "rising" "falling")
10260 " clock edge")))))
10262 (defun vhdl-template-seq-process (clock reset reset-kind)
10263 "Insert a template for the body of a sequential process."
10264 (let ((margin (current-indentation))
10265 position)
10266 (vhdl-insert-keyword "IF ")
10267 (when vhdl-conditions-in-parenthesis (insert "("))
10268 (when (eq reset-kind 'async)
10269 (insert reset " = "
10270 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10271 (when vhdl-conditions-in-parenthesis (insert ")"))
10272 (vhdl-insert-keyword " THEN")
10273 (vhdl-comment-insert-inline
10274 (concat "asynchronous reset (active "
10275 (if vhdl-reset-active-high "high" "low") ")"))
10276 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10277 (setq position (point))
10278 (insert "\n") (indent-to margin)
10279 (vhdl-insert-keyword "ELSIF ")
10280 (when vhdl-conditions-in-parenthesis (insert "(")))
10281 (if (eq vhdl-clock-edge-condition 'function)
10282 (insert (if vhdl-clock-rising-edge "rising" "falling")
10283 "_edge(" clock ")")
10284 (insert clock "'event")
10285 (vhdl-insert-keyword " AND ")
10286 (insert clock " = "
10287 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10288 (when vhdl-conditions-in-parenthesis (insert ")"))
10289 (vhdl-insert-keyword " THEN")
10290 (vhdl-comment-insert-inline
10291 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10292 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10293 (when (eq reset-kind 'sync)
10294 (vhdl-insert-keyword "IF ")
10295 (when vhdl-conditions-in-parenthesis (insert "("))
10296 (setq reset (or (and (not (equal "" vhdl-reset-name))
10297 (progn (insert vhdl-reset-name) vhdl-reset-name))
10298 (vhdl-template-field "reset name") "<reset>"))
10299 (insert " = "
10300 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10301 (when vhdl-conditions-in-parenthesis (insert ")"))
10302 (vhdl-insert-keyword " THEN")
10303 (vhdl-comment-insert-inline
10304 (concat "synchronous reset (active "
10305 (if vhdl-reset-active-high "high" "low") ")"))
10306 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10307 (setq position (point))
10308 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10309 (vhdl-insert-keyword "ELSE")
10310 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10311 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10312 (vhdl-insert-keyword "END IF;"))
10313 (when (eq reset-kind 'none)
10314 (setq position (point)))
10315 (insert "\n") (indent-to margin)
10316 (vhdl-insert-keyword "END IF;")
10317 (goto-char position)
10318 reset))
10320 (defun vhdl-template-standard-package (library package)
10321 "Insert specification of a standard package. Include a library
10322 specification, if not already there."
10323 (let ((margin (current-indentation)))
10324 (unless (equal library "std")
10325 (unless (or (save-excursion
10326 (vhdl-prepare-search-1
10327 (and (not (bobp))
10328 (re-search-backward
10329 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10330 library "\\|end\\)\\>") nil t)
10331 (match-string 2))))
10332 (equal (downcase library) "work"))
10333 (vhdl-insert-keyword "LIBRARY ")
10334 (insert library ";")
10335 (when package
10336 (insert "\n")
10337 (indent-to margin))))
10338 (when package
10339 (vhdl-insert-keyword "USE ")
10340 (insert library "." package)
10341 (vhdl-insert-keyword ".ALL;"))))
10343 (defun vhdl-template-package-numeric-bit ()
10344 "Insert specification of `numeric_bit' package."
10345 (interactive)
10346 (vhdl-template-standard-package "ieee" "numeric_bit"))
10348 (defun vhdl-template-package-numeric-std ()
10349 "Insert specification of `numeric_std' package."
10350 (interactive)
10351 (vhdl-template-standard-package "ieee" "numeric_std"))
10353 (defun vhdl-template-package-std-logic-1164 ()
10354 "Insert specification of `std_logic_1164' package."
10355 (interactive)
10356 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10358 (defun vhdl-template-package-std-logic-arith ()
10359 "Insert specification of `std_logic_arith' package."
10360 (interactive)
10361 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10363 (defun vhdl-template-package-std-logic-misc ()
10364 "Insert specification of `std_logic_misc' package."
10365 (interactive)
10366 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10368 (defun vhdl-template-package-std-logic-signed ()
10369 "Insert specification of `std_logic_signed' package."
10370 (interactive)
10371 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10373 (defun vhdl-template-package-std-logic-textio ()
10374 "Insert specification of `std_logic_textio' package."
10375 (interactive)
10376 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10378 (defun vhdl-template-package-std-logic-unsigned ()
10379 "Insert specification of `std_logic_unsigned' package."
10380 (interactive)
10381 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10383 (defun vhdl-template-package-textio ()
10384 "Insert specification of `textio' package."
10385 (interactive)
10386 (vhdl-template-standard-package "std" "textio"))
10388 (defun vhdl-template-package-fundamental-constants ()
10389 "Insert specification of `fundamental_constants' package."
10390 (interactive)
10391 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10393 (defun vhdl-template-package-material-constants ()
10394 "Insert specification of `material_constants' package."
10395 (interactive)
10396 (vhdl-template-standard-package "ieee" "material_constants"))
10398 (defun vhdl-template-package-energy-systems ()
10399 "Insert specification of `energy_systems' package."
10400 (interactive)
10401 (vhdl-template-standard-package "ieee" "energy_systems"))
10403 (defun vhdl-template-package-electrical-systems ()
10404 "Insert specification of `electrical_systems' package."
10405 (interactive)
10406 (vhdl-template-standard-package "ieee" "electrical_systems"))
10408 (defun vhdl-template-package-mechanical-systems ()
10409 "Insert specification of `mechanical_systems' package."
10410 (interactive)
10411 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10413 (defun vhdl-template-package-radiant-systems ()
10414 "Insert specification of `radiant_systems' package."
10415 (interactive)
10416 (vhdl-template-standard-package "ieee" "radiant_systems"))
10418 (defun vhdl-template-package-thermal-systems ()
10419 "Insert specification of `thermal_systems' package."
10420 (interactive)
10421 (vhdl-template-standard-package "ieee" "thermal_systems"))
10423 (defun vhdl-template-package-fluidic-systems ()
10424 "Insert specification of `fluidic_systems' package."
10425 (interactive)
10426 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10428 (defun vhdl-template-package-math-complex ()
10429 "Insert specification of `math_complex' package."
10430 (interactive)
10431 (vhdl-template-standard-package "ieee" "math_complex"))
10433 (defun vhdl-template-package-math-real ()
10434 "Insert specification of `math_real' package."
10435 (interactive)
10436 (vhdl-template-standard-package "ieee" "math_real"))
10438 (defun vhdl-template-directive (directive)
10439 "Insert directive."
10440 (unless (= (current-indentation) (current-column))
10441 (delete-horizontal-space)
10442 (insert " "))
10443 (insert "-- pragma " directive))
10445 (defun vhdl-template-directive-translate-on ()
10446 "Insert directive 'translate_on'."
10447 (interactive)
10448 (vhdl-template-directive "translate_on"))
10450 (defun vhdl-template-directive-translate-off ()
10451 "Insert directive 'translate_off'."
10452 (interactive)
10453 (vhdl-template-directive "translate_off"))
10455 (defun vhdl-template-directive-synthesis-on ()
10456 "Insert directive 'synthesis_on'."
10457 (interactive)
10458 (vhdl-template-directive "synthesis_on"))
10460 (defun vhdl-template-directive-synthesis-off ()
10461 "Insert directive 'synthesis_off'."
10462 (interactive)
10463 (vhdl-template-directive "synthesis_off"))
10465 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10466 ;; Header and footer templates
10468 (defun vhdl-template-header (&optional file-title)
10469 "Insert a VHDL file header."
10470 (interactive)
10471 (unless (equal vhdl-file-header "")
10472 (let (pos)
10473 (save-excursion
10474 (goto-char (point-min))
10475 (vhdl-insert-string-or-file vhdl-file-header)
10476 (setq pos (point-marker)))
10477 (vhdl-template-replace-header-keywords
10478 (point-min-marker) pos file-title))))
10480 (defun vhdl-template-footer ()
10481 "Insert a VHDL file footer."
10482 (interactive)
10483 (unless (equal vhdl-file-footer "")
10484 (let (pos)
10485 (save-excursion
10486 (goto-char (point-max))
10487 (setq pos (point-marker))
10488 (vhdl-insert-string-or-file vhdl-file-footer)
10489 (unless (= (preceding-char) ?\n)
10490 (insert "\n")))
10491 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10493 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10494 is-model)
10495 "Replace keywords in header and footer."
10496 (let ((project-title (or (nth 0 (vhdl-aget vhdl-project-alist vhdl-project))
10497 ""))
10498 (project-desc (or (nth 9 (vhdl-aget vhdl-project-alist vhdl-project))
10499 ""))
10500 pos)
10501 (vhdl-prepare-search-2
10502 (save-excursion
10503 (goto-char beg)
10504 (while (search-forward "<projectdesc>" end t)
10505 (replace-match project-desc t t))
10506 (goto-char beg)
10507 (while (search-forward "<filename>" end t)
10508 (replace-match (buffer-name) t t))
10509 (goto-char beg)
10510 (while (search-forward "<copyright>" end t)
10511 (replace-match vhdl-copyright-string t t))
10512 (goto-char beg)
10513 (while (search-forward "<author>" end t)
10514 (replace-match "" t t)
10515 (insert (user-full-name))
10516 (when user-mail-address (insert " <" user-mail-address ">")))
10517 (goto-char beg)
10518 (while (search-forward "<authorfull>" end t)
10519 (replace-match (user-full-name) t t))
10520 (goto-char beg)
10521 (while (search-forward "<login>" end t)
10522 (replace-match (user-login-name) t t))
10523 (goto-char beg)
10524 (while (search-forward "<project>" end t)
10525 (replace-match project-title t t))
10526 (goto-char beg)
10527 (while (search-forward "<company>" end t)
10528 (replace-match vhdl-company-name t t))
10529 (goto-char beg)
10530 (while (search-forward "<platform>" end t)
10531 (replace-match vhdl-platform-spec t t))
10532 (goto-char beg)
10533 (while (search-forward "<standard>" end t)
10534 (replace-match
10535 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10536 ((vhdl-standard-p '93) "'93/02"))
10537 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10538 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10539 (goto-char beg)
10540 ;; Replace <RCS> with $, so that RCS for the source is
10541 ;; not over-enthusiastic with replacements
10542 (while (search-forward "<RCS>" end t)
10543 (replace-match "$" nil t))
10544 (goto-char beg)
10545 (while (search-forward "<date>" end t)
10546 (replace-match "" t t)
10547 (vhdl-template-insert-date))
10548 (goto-char beg)
10549 (while (search-forward "<year>" end t)
10550 (replace-match (format-time-string "%Y" nil) t t))
10551 (goto-char beg)
10552 (when file-title
10553 (while (search-forward "<title string>" end t)
10554 (replace-match file-title t t))
10555 (goto-char beg))
10556 (let (string)
10557 (while (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10558 (save-match-data
10559 (setq string (read-string (concat (match-string 1) ": "))))
10560 (replace-match string t t)))
10561 (goto-char beg)
10562 (when (and (not is-model) (search-forward "<cursor>" end t))
10563 (replace-match "" t t)
10564 (setq pos (point))))
10565 (when pos (goto-char pos))
10566 (unless is-model
10567 (when (or (not project-title) (equal project-title ""))
10568 (message "You can specify a project title in user option `vhdl-project-alist'"))
10569 (when (or (not project-desc) (equal project-desc ""))
10570 (message "You can specify a project description in user option `vhdl-project-alist'"))
10571 (when (equal vhdl-platform-spec "")
10572 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10573 (when (equal vhdl-company-name "")
10574 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10576 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10577 ;; Comment templates and functions
10579 (defun vhdl-comment-indent ()
10580 "Indent comments."
10581 (let* ((position (point))
10582 (col
10583 (progn
10584 (forward-line -1)
10585 (if (re-search-forward "--" position t)
10586 (- (current-column) 2) ; existing comment at bol stays there
10587 (goto-char position)
10588 (skip-chars-backward " \t")
10589 (max comment-column ; else indent to comment column
10590 (1+ (current-column))))))) ; except leave at least one space
10591 (goto-char position)
10592 col))
10594 (defun vhdl-comment-insert ()
10595 "Start a comment at the end of the line.
10596 If on line with code, indent at least `comment-column'.
10597 If starting after end-comment-column, start a new line."
10598 (interactive)
10599 (when (> (current-column) end-comment-column) (newline-and-indent))
10600 (if (or (looking-at "\\s-*$") ; end of line
10601 (and (not unread-command-events) ; called with key binding or menu
10602 (not (end-of-line))))
10603 (let (margin)
10604 (while (= (preceding-char) ?-) (delete-char -1))
10605 (setq margin (current-column))
10606 (delete-horizontal-space)
10607 (if (bolp)
10608 (progn (indent-to margin) (insert "--"))
10609 (insert " ")
10610 (indent-to comment-column)
10611 (insert "--"))
10612 (if (not unread-command-events) (insert " ")))
10613 ;; else code following current point implies commenting out code
10614 (let (next-input code)
10615 (while (= (preceding-char) ?-) (delete-char -2))
10616 (while (= (setq next-input (read-char)) 13) ; CR
10617 (insert "--") ; or have a space after it?
10618 (forward-char -2)
10619 (forward-line 1)
10620 (message "Enter CR if commenting out a line of code.")
10621 (setq code t))
10622 (unless code
10623 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10624 (setq unread-command-events
10625 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10627 (defun vhdl-comment-display (&optional line-exists)
10628 "Add 2 comment lines at the current indent, making a display comment."
10629 (interactive)
10630 (let ((margin (current-indentation)))
10631 (unless line-exists (vhdl-comment-display-line))
10632 (insert "\n") (indent-to margin)
10633 (insert "\n") (indent-to margin)
10634 (vhdl-comment-display-line)
10635 (end-of-line -0)
10636 (insert "-- ")))
10638 (defun vhdl-comment-display-line ()
10639 "Displays one line of dashes."
10640 (interactive)
10641 (while (= (preceding-char) ?-) (delete-char -2))
10642 (insert "--")
10643 (let* ((col (current-column))
10644 (len (- end-comment-column col)))
10645 (insert-char vhdl-comment-display-line-char len)))
10647 (defun vhdl-comment-append-inline ()
10648 "Append empty inline comment to current line."
10649 (interactive)
10650 (end-of-line)
10651 (delete-horizontal-space)
10652 (insert " ")
10653 (indent-to comment-column)
10654 (insert "-- "))
10656 (defun vhdl-comment-insert-inline (&optional string always-insert)
10657 "Insert inline comment."
10658 (when (or (and string (or vhdl-self-insert-comments always-insert))
10659 (and (not string) vhdl-prompt-for-comments))
10660 (let ((position (point)))
10661 (insert " ")
10662 (indent-to comment-column)
10663 (insert "-- ")
10664 (if (not (or (and string (progn (insert string) t))
10665 (vhdl-template-field "[comment]" nil t)))
10666 (delete-region position (point))
10667 (while (= (preceding-char) ?\ ) (delete-char -1))))))
10669 (defun vhdl-comment-block ()
10670 "Insert comment for code block."
10671 (when vhdl-prompt-for-comments
10672 (let ((final-pos (point-marker)))
10673 (vhdl-prepare-search-2
10674 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10675 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10676 (let (margin)
10677 (back-to-indentation)
10678 (setq margin (current-column))
10679 (end-of-line -0)
10680 (if (bobp)
10681 (progn (insert "\n") (forward-line -1))
10682 (insert "\n"))
10683 (indent-to margin)
10684 (insert "-- purpose: ")
10685 (unless (vhdl-template-field "[description]" nil t)
10686 (vhdl-line-kill-entire)))))
10687 (goto-char final-pos))))
10689 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10690 "Comment out region if not commented out, uncomment otherwise."
10691 (interactive "r\nP")
10692 (save-excursion
10693 (goto-char (1- end))
10694 (end-of-line)
10695 (setq end (point-marker))
10696 (goto-char beg)
10697 (beginning-of-line)
10698 (setq beg (point))
10699 (if (looking-at (concat "\\s-*" comment-start))
10700 (comment-region beg end '(4))
10701 (comment-region beg end))))
10703 (defun vhdl-comment-uncomment-line (&optional arg)
10704 "Comment out line if not commented out, uncomment otherwise."
10705 (interactive "p")
10706 (save-excursion
10707 (beginning-of-line)
10708 (let ((position (point)))
10709 (forward-line (or arg 1))
10710 (vhdl-comment-uncomment-region position (point)))))
10712 (defun vhdl-comment-kill-region (beg end)
10713 "Kill comments in region."
10714 (interactive "r")
10715 (save-excursion
10716 (goto-char end)
10717 (setq end (point-marker))
10718 (goto-char beg)
10719 (beginning-of-line)
10720 (while (< (point) end)
10721 (if (looking-at "^\\(\\s-*--.*\n\\)")
10722 (progn (delete-region (match-beginning 1) (match-end 1)))
10723 (beginning-of-line 2)))))
10725 (defun vhdl-comment-kill-inline-region (beg end)
10726 "Kill inline comments in region."
10727 (interactive "r")
10728 (save-excursion
10729 (goto-char end)
10730 (setq end (point-marker))
10731 (goto-char beg)
10732 (beginning-of-line)
10733 (while (< (point) end)
10734 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10735 (delete-region (match-beginning 1) (match-end 1)))
10736 (beginning-of-line 2))))
10738 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10739 ;; Subtemplates
10741 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10742 "Insert a begin ... end pair with optional name after the end.
10743 Point is left between them."
10744 (let (position)
10745 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10746 (indent-to margin)
10747 (vhdl-insert-keyword "BEGIN")
10748 (when (and (or construct name) vhdl-self-insert-comments)
10749 (insert " --")
10750 (when construct (insert " ") (vhdl-insert-keyword construct))
10751 (when name (insert " " name)))
10752 (insert "\n")
10753 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10754 (indent-to (+ margin vhdl-basic-offset))
10755 (setq position (point))
10756 (insert "\n")
10757 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10758 (indent-to margin)
10759 (vhdl-insert-keyword "END")
10760 (when construct (insert " ") (vhdl-insert-keyword construct))
10761 (insert (if name (concat " " name) "") ";")
10762 (goto-char position)))
10764 (defun vhdl-template-argument-list (&optional is-function)
10765 "Read from user a procedure or function argument list."
10766 (insert " (")
10767 (let ((margin (current-column))
10768 (start (point))
10769 (end-pos (point))
10770 not-empty interface semicolon-pos)
10771 (unless vhdl-argument-list-indent
10772 (setq margin (+ (current-indentation) vhdl-basic-offset))
10773 (insert "\n")
10774 (indent-to margin))
10775 (setq interface (vhdl-template-field
10776 (concat "[CONSTANT | SIGNAL"
10777 (unless is-function " | VARIABLE") "]") " " t))
10778 (while (vhdl-template-field "[names]" nil t)
10779 (setq not-empty t)
10780 (insert " : ")
10781 (unless is-function
10782 (if (and interface (equal (upcase interface) "CONSTANT"))
10783 (vhdl-insert-keyword "IN ")
10784 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10785 (vhdl-template-field "type")
10786 (setq semicolon-pos (point))
10787 (insert ";")
10788 (vhdl-comment-insert-inline)
10789 (setq end-pos (point))
10790 (insert "\n")
10791 (indent-to margin)
10792 (setq interface (vhdl-template-field
10793 (concat "[CONSTANT | SIGNAL"
10794 (unless is-function " | VARIABLE") "]") " " t)))
10795 (delete-region end-pos (point))
10796 (when semicolon-pos (goto-char semicolon-pos))
10797 (if not-empty
10798 (progn (delete-char 1) (insert ")"))
10799 (delete-char -2))))
10801 (defun vhdl-template-generic-list (optional &optional no-value)
10802 "Read from user a generic spec argument list."
10803 (let (margin
10804 (start (point)))
10805 (vhdl-insert-keyword "GENERIC (")
10806 (setq margin (current-column))
10807 (unless vhdl-argument-list-indent
10808 (let ((position (point)))
10809 (back-to-indentation)
10810 (setq margin (+ (current-column) vhdl-basic-offset))
10811 (goto-char position)
10812 (insert "\n")
10813 (indent-to margin)))
10814 (let ((vhdl-generics (vhdl-template-field
10815 (concat (and optional "[") "name"
10816 (and no-value "s") (and optional "]"))
10817 nil optional)))
10818 (if (not vhdl-generics)
10819 (if optional
10820 (progn (vhdl-line-kill-entire) (end-of-line -0)
10821 (unless vhdl-argument-list-indent
10822 (vhdl-line-kill-entire) (end-of-line -0)))
10823 (vhdl-template-undo start (point))
10824 nil )
10825 (insert " : ")
10826 (let (semicolon-pos end-pos)
10827 (while vhdl-generics
10828 (vhdl-template-field "type")
10829 (if no-value
10830 (progn (setq semicolon-pos (point))
10831 (insert ";"))
10832 (insert " := ")
10833 (unless (vhdl-template-field "[value]" nil t)
10834 (delete-char -4))
10835 (setq semicolon-pos (point))
10836 (insert ";"))
10837 (vhdl-comment-insert-inline)
10838 (setq end-pos (point))
10839 (insert "\n")
10840 (indent-to margin)
10841 (setq vhdl-generics (vhdl-template-field
10842 (concat "[name" (and no-value "s") "]")
10843 " : " t)))
10844 (delete-region end-pos (point))
10845 (goto-char semicolon-pos)
10846 (insert ")")
10847 (end-of-line)
10848 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10849 t)))))
10851 (defun vhdl-template-port-list (optional)
10852 "Read from user a port spec argument list."
10853 (let ((start (point))
10854 margin vhdl-ports object)
10855 (vhdl-insert-keyword "PORT (")
10856 (setq margin (current-column))
10857 (unless vhdl-argument-list-indent
10858 (let ((position (point)))
10859 (back-to-indentation)
10860 (setq margin (+ (current-column) vhdl-basic-offset))
10861 (goto-char position)
10862 (insert "\n")
10863 (indent-to margin)))
10864 (when (vhdl-standard-p 'ams)
10865 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10866 " " t)))
10867 (setq vhdl-ports (vhdl-template-field
10868 (concat (and optional "[") "names" (and optional "]"))
10869 nil optional))
10870 (if (not vhdl-ports)
10871 (if optional
10872 (progn (vhdl-line-kill-entire) (end-of-line -0)
10873 (unless vhdl-argument-list-indent
10874 (vhdl-line-kill-entire) (end-of-line -0)))
10875 (vhdl-template-undo start (point))
10876 nil)
10877 (insert " : ")
10878 (let (semicolon-pos end-pos)
10879 (while vhdl-ports
10880 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10881 (vhdl-template-field "IN | OUT | INOUT" " "))
10882 ((equal "QUANTITY" (upcase object))
10883 (vhdl-template-field "[IN | OUT]" " " t)))
10884 (vhdl-template-field
10885 (if (and object (equal "TERMINAL" (upcase object)))
10886 "nature" "type"))
10887 (setq semicolon-pos (point))
10888 (insert ";")
10889 (vhdl-comment-insert-inline)
10890 (setq end-pos (point))
10891 (insert "\n")
10892 (indent-to margin)
10893 (when (vhdl-standard-p 'ams)
10894 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10895 " " t)))
10896 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10897 (delete-region end-pos (point))
10898 (goto-char semicolon-pos)
10899 (insert ")")
10900 (end-of-line)
10901 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10902 t))))
10904 (defun vhdl-template-generate-body (margin label)
10905 "Insert body for generate template."
10906 (vhdl-insert-keyword " GENERATE")
10907 (insert "\n\n")
10908 (indent-to margin)
10909 (vhdl-insert-keyword "END GENERATE ")
10910 (insert label ";")
10911 (end-of-line 0)
10912 (indent-to (+ margin vhdl-basic-offset)))
10914 (defun vhdl-template-insert-date ()
10915 "Insert date in appropriate format."
10916 (interactive)
10917 (insert
10918 (cond
10919 ;; 'american, 'european, 'scientific kept for backward compatibility
10920 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10921 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10922 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10923 (t (format-time-string vhdl-date-format nil)))))
10925 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10926 ;; Help functions
10928 (defun vhdl-electric-space (count)
10929 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10930 if in comment and past end-comment-column."
10931 (interactive "p")
10932 (cond ((vhdl-in-comment-p)
10933 (self-insert-command count)
10934 (cond ((>= (current-column) (+ 2 end-comment-column))
10935 (backward-char 1)
10936 (skip-chars-backward "^ \t\n\r\f")
10937 (indent-new-comment-line)
10938 (skip-chars-forward "^ \t\n\r\f")
10939 (forward-char 1))
10940 ((>= (current-column) end-comment-column)
10941 (indent-new-comment-line))
10942 (t nil)))
10943 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10944 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10945 (vhdl-prepare-search-1
10946 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10947 (self-insert-command count))
10948 (t (self-insert-command count))))
10950 (defun vhdl-template-field (prompt &optional follow-string optional
10951 begin end is-string default)
10952 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10953 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10954 an empty string is inserted, return nil and call `vhdl-template-undo' for
10955 the region between BEGIN and END. IS-STRING indicates whether a string
10956 with double-quotes is to be inserted. DEFAULT specifies a default string."
10957 (let ((position (point))
10958 string)
10959 (insert "<" prompt ">")
10960 (setq string
10961 (condition-case ()
10962 (read-from-minibuffer (concat prompt ": ")
10963 (or (and is-string '("\"\"" . 2)) default)
10964 vhdl-minibuffer-local-map)
10965 (quit (if (and optional begin end)
10966 (progn (beep) "")
10967 (keyboard-quit)))))
10968 (when (or (not (equal string "")) optional)
10969 (delete-region position (point)))
10970 (when (and (equal string "") optional begin end)
10971 (vhdl-template-undo begin end)
10972 (message "Template aborted"))
10973 (unless (equal string "")
10974 (insert string)
10975 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10976 vhdl-keywords-regexp)
10977 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10978 vhdl-types-regexp)
10979 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10980 (concat "'" vhdl-attributes-regexp))
10981 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10982 vhdl-enum-values-regexp)
10983 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
10984 vhdl-constants-regexp))
10985 (when (or (not (equal string "")) (not optional))
10986 (insert (or follow-string "")))
10987 (if (equal string "") nil string)))
10989 (defun vhdl-decision-query (string prompt &optional optional)
10990 "Query a decision from the user."
10991 (let ((start (point)))
10992 (when string (vhdl-insert-keyword (concat string " ")))
10993 (message "%s" (or prompt ""))
10994 (let ((char (read-char)))
10995 (delete-region start (point))
10996 (if (and optional (eq char ?\r))
10997 (progn (insert " ")
10998 (unexpand-abbrev)
10999 (throw 'abort "ERROR: Template aborted"))
11000 char))))
11002 (defun vhdl-insert-keyword (keyword)
11003 "Insert KEYWORD and adjust case."
11004 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
11006 (defun vhdl-case-keyword (keyword)
11007 "Adjust case of KEYWORD."
11008 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
11010 (defun vhdl-case-word (num)
11011 "Adjust case of following NUM words."
11012 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
11014 (defun vhdl-minibuffer-tab (&optional prefix-arg)
11015 "If preceding character is part of a word or a paren then hippie-expand,
11016 else insert tab (used for word completion in VHDL minibuffer)."
11017 (interactive "P")
11018 (cond
11019 ;; expand word
11020 ((= (char-syntax (preceding-char)) ?w)
11021 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11022 (case-replace nil)
11023 (hippie-expand-only-buffers
11024 (or (and (boundp 'hippie-expand-only-buffers)
11025 hippie-expand-only-buffers)
11026 '(vhdl-mode))))
11027 (vhdl-expand-abbrev prefix-arg)))
11028 ;; expand parenthesis
11029 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
11030 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11031 (case-replace nil))
11032 (vhdl-expand-paren prefix-arg)))
11033 ;; insert tab
11034 (t (insert-tab))))
11036 (defun vhdl-template-search-prompt ()
11037 "Search for left out template prompts and query again."
11038 (interactive)
11039 (vhdl-prepare-search-2
11040 (when (or (re-search-forward
11041 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
11042 (re-search-backward
11043 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
11044 (let ((string (match-string 1)))
11045 (replace-match "")
11046 (vhdl-template-field string)))))
11048 (defun vhdl-template-undo (begin end)
11049 "Undo aborted template by deleting region and unexpanding the keyword."
11050 (cond (vhdl-template-invoked-by-hook
11051 (goto-char end)
11052 (insert " ")
11053 (delete-region begin end)
11054 (unexpand-abbrev))
11055 (t (delete-region begin end))))
11057 (defun vhdl-insert-string-or-file (string)
11058 "Insert STRING or file contents if STRING is an existing file name."
11059 (unless (equal string "")
11060 (let ((file-name
11061 (progn (string-match "^\\([^\n]+\\)" string)
11062 (vhdl-resolve-env-variable (match-string 1 string)))))
11063 (if (file-exists-p file-name)
11064 (forward-char (cadr (insert-file-contents file-name)))
11065 (insert string)))))
11067 (defun vhdl-beginning-of-block ()
11068 "Move cursor to the beginning of the enclosing block."
11069 (let (pos)
11070 (vhdl-prepare-search-2
11071 (save-excursion
11072 (beginning-of-line)
11073 ;; search backward for block beginning or end
11074 (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
11075 ;; not consider subprogram declarations
11076 (or (and (match-string 5)
11077 (save-match-data
11078 (save-excursion
11079 (goto-char (match-end 5))
11080 (forward-word 1)
11081 (vhdl-forward-syntactic-ws)
11082 (when (looking-at "(")
11083 (forward-sexp))
11084 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11085 (match-string 1)))
11086 ;; not consider configuration specifications
11087 (and (match-string 6)
11088 (save-match-data
11089 (save-excursion
11090 (vhdl-end-of-block)
11091 (beginning-of-line)
11092 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11093 (match-string 2))
11094 ;; skip subblock if block end found
11095 (vhdl-beginning-of-block))))
11096 (when pos (goto-char pos))))
11098 (defun vhdl-end-of-block ()
11099 "Move cursor to the end of the enclosing block."
11100 (let (pos)
11101 (vhdl-prepare-search-2
11102 (save-excursion
11103 (end-of-line)
11104 ;; search forward for block beginning or end
11105 (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
11106 ;; not consider subprogram declarations
11107 (or (and (match-string 5)
11108 (save-match-data
11109 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11110 (match-string 1)))
11111 ;; not consider configuration specifications
11112 (and (match-string 6)
11113 (save-match-data
11114 (save-excursion
11115 (vhdl-end-of-block)
11116 (beginning-of-line)
11117 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11118 (not (match-string 2)))
11119 ;; skip subblock if block beginning found
11120 (vhdl-end-of-block))))
11121 (when pos (goto-char pos))))
11123 (defun vhdl-sequential-statement-p ()
11124 "Check if point is within sequential statement part."
11125 (let ((start (point)))
11126 (save-excursion
11127 (vhdl-prepare-search-2
11128 ;; is sequential statement if ...
11129 (and (re-search-backward "^\\s-*begin\\>" nil t)
11130 ;; ... point is between "begin" and "end" of ...
11131 (progn (vhdl-end-of-block)
11132 (< start (point)))
11133 ;; ... a sequential block
11134 (progn (vhdl-beginning-of-block)
11135 (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\\)\\)\\>")))))))
11137 (defun vhdl-in-argument-list-p ()
11138 "Check if within an argument list."
11139 (save-excursion
11140 (vhdl-prepare-search-2
11141 (or (string-match "arglist"
11142 (format "%s" (caar (vhdl-get-syntactic-context))))
11143 (progn (beginning-of-line)
11144 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11147 ;; Abbrev hooks
11149 (defun vhdl-hooked-abbrev (func)
11150 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11151 but not if inside a comment or quote."
11152 (if (or (vhdl-in-literal)
11153 (save-excursion
11154 (forward-word -1)
11155 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11156 (progn
11157 (insert " ")
11158 (unexpand-abbrev)
11159 (backward-word 1)
11160 (vhdl-case-word 1)
11161 (delete-char 1))
11162 (if (not vhdl-electric-mode)
11163 (progn
11164 (insert " ")
11165 (unexpand-abbrev)
11166 (backward-word 1)
11167 (vhdl-case-word 1)
11168 (delete-char 1))
11169 (let ((invoke-char vhdl-last-input-event)
11170 (abbrev-mode -1)
11171 (vhdl-template-invoked-by-hook t))
11172 (let ((caught (catch 'abort
11173 (funcall func))))
11174 (when (stringp caught) (message "%s" caught)))
11175 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
11176 ;; delete CR which is still in event queue
11177 (if (fboundp 'enqueue-eval-event)
11178 (enqueue-eval-event 'delete-char -1)
11179 (setq unread-command-events ; push back a delete char
11180 (list (vhdl-character-to-event ?\177))))))))
11182 (defun vhdl-template-alias-hook ()
11183 (vhdl-hooked-abbrev 'vhdl-template-alias))
11184 (defun vhdl-template-architecture-hook ()
11185 (vhdl-hooked-abbrev 'vhdl-template-architecture))
11186 (defun vhdl-template-assert-hook ()
11187 (vhdl-hooked-abbrev 'vhdl-template-assert))
11188 (defun vhdl-template-attribute-hook ()
11189 (vhdl-hooked-abbrev 'vhdl-template-attribute))
11190 (defun vhdl-template-block-hook ()
11191 (vhdl-hooked-abbrev 'vhdl-template-block))
11192 (defun vhdl-template-break-hook ()
11193 (vhdl-hooked-abbrev 'vhdl-template-break))
11194 (defun vhdl-template-case-hook ()
11195 (vhdl-hooked-abbrev 'vhdl-template-case))
11196 (defun vhdl-template-component-hook ()
11197 (vhdl-hooked-abbrev 'vhdl-template-component))
11198 (defun vhdl-template-instance-hook ()
11199 (vhdl-hooked-abbrev 'vhdl-template-instance))
11200 (defun vhdl-template-conditional-signal-asst-hook ()
11201 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
11202 (defun vhdl-template-configuration-hook ()
11203 (vhdl-hooked-abbrev 'vhdl-template-configuration))
11204 (defun vhdl-template-constant-hook ()
11205 (vhdl-hooked-abbrev 'vhdl-template-constant))
11206 (defun vhdl-template-disconnect-hook ()
11207 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
11208 (defun vhdl-template-display-comment-hook ()
11209 (vhdl-hooked-abbrev 'vhdl-comment-display))
11210 (defun vhdl-template-else-hook ()
11211 (vhdl-hooked-abbrev 'vhdl-template-else))
11212 (defun vhdl-template-elsif-hook ()
11213 (vhdl-hooked-abbrev 'vhdl-template-elsif))
11214 (defun vhdl-template-entity-hook ()
11215 (vhdl-hooked-abbrev 'vhdl-template-entity))
11216 (defun vhdl-template-exit-hook ()
11217 (vhdl-hooked-abbrev 'vhdl-template-exit))
11218 (defun vhdl-template-file-hook ()
11219 (vhdl-hooked-abbrev 'vhdl-template-file))
11220 (defun vhdl-template-for-hook ()
11221 (vhdl-hooked-abbrev 'vhdl-template-for))
11222 (defun vhdl-template-function-hook ()
11223 (vhdl-hooked-abbrev 'vhdl-template-function))
11224 (defun vhdl-template-generic-hook ()
11225 (vhdl-hooked-abbrev 'vhdl-template-generic))
11226 (defun vhdl-template-group-hook ()
11227 (vhdl-hooked-abbrev 'vhdl-template-group))
11228 (defun vhdl-template-library-hook ()
11229 (vhdl-hooked-abbrev 'vhdl-template-library))
11230 (defun vhdl-template-limit-hook ()
11231 (vhdl-hooked-abbrev 'vhdl-template-limit))
11232 (defun vhdl-template-if-hook ()
11233 (vhdl-hooked-abbrev 'vhdl-template-if))
11234 (defun vhdl-template-bare-loop-hook ()
11235 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
11236 (defun vhdl-template-map-hook ()
11237 (vhdl-hooked-abbrev 'vhdl-template-map))
11238 (defun vhdl-template-nature-hook ()
11239 (vhdl-hooked-abbrev 'vhdl-template-nature))
11240 (defun vhdl-template-next-hook ()
11241 (vhdl-hooked-abbrev 'vhdl-template-next))
11242 (defun vhdl-template-others-hook ()
11243 (vhdl-hooked-abbrev 'vhdl-template-others))
11244 (defun vhdl-template-package-hook ()
11245 (vhdl-hooked-abbrev 'vhdl-template-package))
11246 (defun vhdl-template-port-hook ()
11247 (vhdl-hooked-abbrev 'vhdl-template-port))
11248 (defun vhdl-template-procedural-hook ()
11249 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11250 (defun vhdl-template-procedure-hook ()
11251 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11252 (defun vhdl-template-process-hook ()
11253 (vhdl-hooked-abbrev 'vhdl-template-process))
11254 (defun vhdl-template-quantity-hook ()
11255 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11256 (defun vhdl-template-report-hook ()
11257 (vhdl-hooked-abbrev 'vhdl-template-report))
11258 (defun vhdl-template-return-hook ()
11259 (vhdl-hooked-abbrev 'vhdl-template-return))
11260 (defun vhdl-template-selected-signal-asst-hook ()
11261 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11262 (defun vhdl-template-signal-hook ()
11263 (vhdl-hooked-abbrev 'vhdl-template-signal))
11264 (defun vhdl-template-subnature-hook ()
11265 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11266 (defun vhdl-template-subtype-hook ()
11267 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11268 (defun vhdl-template-terminal-hook ()
11269 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11270 (defun vhdl-template-type-hook ()
11271 (vhdl-hooked-abbrev 'vhdl-template-type))
11272 (defun vhdl-template-use-hook ()
11273 (vhdl-hooked-abbrev 'vhdl-template-use))
11274 (defun vhdl-template-variable-hook ()
11275 (vhdl-hooked-abbrev 'vhdl-template-variable))
11276 (defun vhdl-template-wait-hook ()
11277 (vhdl-hooked-abbrev 'vhdl-template-wait))
11278 (defun vhdl-template-when-hook ()
11279 (vhdl-hooked-abbrev 'vhdl-template-when))
11280 (defun vhdl-template-while-loop-hook ()
11281 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11282 (defun vhdl-template-with-hook ()
11283 (vhdl-hooked-abbrev 'vhdl-template-with))
11284 (defun vhdl-template-and-hook ()
11285 (vhdl-hooked-abbrev 'vhdl-template-and))
11286 (defun vhdl-template-or-hook ()
11287 (vhdl-hooked-abbrev 'vhdl-template-or))
11288 (defun vhdl-template-nand-hook ()
11289 (vhdl-hooked-abbrev 'vhdl-template-nand))
11290 (defun vhdl-template-nor-hook ()
11291 (vhdl-hooked-abbrev 'vhdl-template-nor))
11292 (defun vhdl-template-xor-hook ()
11293 (vhdl-hooked-abbrev 'vhdl-template-xor))
11294 (defun vhdl-template-xnor-hook ()
11295 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11296 (defun vhdl-template-not-hook ()
11297 (vhdl-hooked-abbrev 'vhdl-template-not))
11299 (defun vhdl-template-default-hook ()
11300 (vhdl-hooked-abbrev 'vhdl-template-default))
11301 (defun vhdl-template-default-indent-hook ()
11302 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11305 ;; Template insertion from completion list
11307 (defun vhdl-template-insert-construct (name)
11308 "Insert the built-in construct template with NAME."
11309 (interactive
11310 (list (let ((completion-ignore-case t))
11311 (completing-read "Construct name: "
11312 vhdl-template-construct-alist nil t))))
11313 (vhdl-template-insert-fun
11314 (cadr (assoc name vhdl-template-construct-alist))))
11316 (defun vhdl-template-insert-package (name)
11317 "Insert the built-in package template with NAME."
11318 (interactive
11319 (list (let ((completion-ignore-case t))
11320 (completing-read "Package name: "
11321 vhdl-template-package-alist nil t))))
11322 (vhdl-template-insert-fun
11323 (cadr (assoc name vhdl-template-package-alist))))
11325 (defun vhdl-template-insert-directive (name)
11326 "Insert the built-in directive template with NAME."
11327 (interactive
11328 (list (let ((completion-ignore-case t))
11329 (completing-read "Directive name: "
11330 vhdl-template-directive-alist nil t))))
11331 (vhdl-template-insert-fun
11332 (cadr (assoc name vhdl-template-directive-alist))))
11334 (defun vhdl-template-insert-fun (fun)
11335 "Call FUN to insert a built-in template."
11336 (let ((caught (catch 'abort (when fun (funcall fun)))))
11337 (when (stringp caught) (message "%s" caught))))
11340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11341 ;;; Models
11342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11344 (defun vhdl-model-insert (model-name)
11345 "Insert the user model with name MODEL-NAME."
11346 (interactive
11347 (let ((completion-ignore-case t))
11348 (list (completing-read "Model name: " vhdl-model-alist))))
11349 (indent-according-to-mode)
11350 (let ((start (point-marker))
11351 (margin (current-indentation))
11352 model position prompt string end)
11353 (vhdl-prepare-search-2
11354 (when (setq model (assoc model-name vhdl-model-alist))
11355 ;; insert model
11356 (beginning-of-line)
11357 (delete-horizontal-space)
11358 (goto-char start)
11359 (vhdl-insert-string-or-file (nth 1 model))
11360 (setq end (point-marker))
11361 ;; indent code
11362 (goto-char start)
11363 (beginning-of-line)
11364 (while (< (point) end)
11365 (unless (looking-at "^$")
11366 (insert-char ? margin))
11367 (beginning-of-line 2))
11368 (goto-char start)
11369 ;; insert clock
11370 (unless (equal "" vhdl-clock-name)
11371 (while (re-search-forward "<clock>" end t)
11372 (replace-match vhdl-clock-name)))
11373 (goto-char start)
11374 ;; insert reset
11375 (unless (equal "" vhdl-reset-name)
11376 (while (re-search-forward "<reset>" end t)
11377 (replace-match vhdl-reset-name)))
11378 ;; replace header prompts
11379 (vhdl-template-replace-header-keywords start end nil t)
11380 (goto-char start)
11381 ;; query other prompts
11382 (while (re-search-forward
11383 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11384 (unless (equal "cursor" (match-string 1))
11385 (setq position (match-beginning 1))
11386 (setq prompt (match-string 1))
11387 (replace-match "")
11388 (setq string (vhdl-template-field prompt nil t))
11389 ;; replace occurrences of same prompt
11390 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11391 (replace-match (or string "")))
11392 (goto-char position)))
11393 (goto-char start)
11394 ;; goto final position
11395 (if (re-search-forward "<cursor>" end t)
11396 (replace-match "")
11397 (goto-char end))))))
11399 (defun vhdl-model-defun ()
11400 "Define help and hook functions for user models."
11401 (let ((model-alist vhdl-model-alist)
11402 model-name model-keyword)
11403 (while model-alist
11404 ;; define functions for user models that can be invoked from menu and key
11405 ;; bindings and which themselves call `vhdl-model-insert' with the model
11406 ;; name as argument
11407 (setq model-name (nth 0 (car model-alist)))
11408 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11409 ,(concat "Insert model for \"" model-name "\".")
11410 (interactive)
11411 (vhdl-model-insert ,model-name)))
11412 ;; define hooks for user models that are invoked from keyword abbrevs
11413 (setq model-keyword (nth 3 (car model-alist)))
11414 (unless (equal model-keyword "")
11415 (eval `(defun
11416 ,(vhdl-function-name
11417 "vhdl-model" model-name "hook") ()
11418 (vhdl-hooked-abbrev
11419 ',(vhdl-function-name "vhdl-model" model-name)))))
11420 (setq model-alist (cdr model-alist)))))
11422 (vhdl-model-defun)
11425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11426 ;;; Port translation
11427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11429 (defvar vhdl-port-list nil
11430 "Variable to hold last port map parsed.")
11431 ;; structure: (parenthesized expression means list of such entries)
11432 ;; (ent-name
11433 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11434 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11435 ;; (lib-name pack-key))
11437 (defun vhdl-parse-string (string &optional optional)
11438 "Check that the text following point matches the regexp in STRING."
11439 (if (looking-at string)
11440 (progn (goto-char (match-end 0))
11441 (when (vhdl-in-literal)
11442 (end-of-line))
11443 (point))
11444 (unless optional
11445 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11446 (vhdl-current-line) string)))
11447 nil))
11449 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11450 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11451 (vhdl-prepare-search-1
11452 (if (string-match (car regexp-cons) string)
11453 (if adjust-case
11454 (funcall vhdl-file-name-case
11455 (replace-match (cdr regexp-cons) t nil string))
11456 (replace-match (cdr regexp-cons) t nil string))
11457 string)))
11459 (defun vhdl-parse-group-comment ()
11460 "Parse comment and empty lines between groups of lines."
11461 (let ((start (point))
11462 string)
11463 (vhdl-forward-comment (point-max))
11464 (setq string (buffer-substring-no-properties start (point)))
11465 (vhdl-forward-syntactic-ws)
11466 ;; strip off leading blanks and first newline
11467 (while (string-match "^\\(\\s-+\\)" string)
11468 (setq string (concat (substring string 0 (match-beginning 1))
11469 (substring string (match-end 1)))))
11470 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11471 (substring string 1)
11472 string)))
11474 (defun vhdl-paste-group-comment (string indent)
11475 "Paste comment and empty lines from STRING between groups of lines
11476 with INDENT."
11477 (let ((pos (point-marker)))
11478 (when (> indent 0)
11479 (while (string-match "^\\(--\\)" string)
11480 (setq string (concat (substring string 0 (match-beginning 1))
11481 (make-string indent ? )
11482 (substring string (match-beginning 1))))))
11483 (beginning-of-line)
11484 (insert string)
11485 (goto-char pos)))
11487 (defvar vhdl-port-flattened nil
11488 "Indicates whether a port has been flattened.")
11490 (defun vhdl-port-flatten (&optional as-alist)
11491 "Flatten port list so that only one generic/port exists per line.
11492 This operation is performed on an internally stored port and is only
11493 reflected in a subsequent paste operation."
11494 (interactive)
11495 (if (not vhdl-port-list)
11496 (error "ERROR: No port has been read")
11497 (message "Flattening port for next paste...")
11498 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11499 (old-vhdl-port-list (cdr vhdl-port-list))
11500 old-port-list new-port-list old-port new-port names)
11501 ;; traverse port list and flatten entries
11502 (while (cdr old-vhdl-port-list)
11503 (setq old-port-list (car old-vhdl-port-list))
11504 (setq new-port-list nil)
11505 (while old-port-list
11506 (setq old-port (car old-port-list))
11507 (setq names (car old-port))
11508 (while names
11509 (setq new-port (cons (if as-alist (car names) (list (car names)))
11510 (cdr old-port)))
11511 (setq new-port-list (append new-port-list (list new-port)))
11512 (setq names (cdr names)))
11513 (setq old-port-list (cdr old-port-list)))
11514 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11515 (setq new-vhdl-port-list (append new-vhdl-port-list
11516 (list new-port-list))))
11517 (setq vhdl-port-list
11518 (append new-vhdl-port-list (list old-vhdl-port-list))
11519 vhdl-port-flattened t)
11520 (message "Flattening port for next paste...done"))))
11522 (defvar vhdl-port-reversed-direction nil
11523 "Indicates whether port directions are reversed.")
11525 (defun vhdl-port-reverse-direction ()
11526 "Reverse direction for all ports (useful in testbenches).
11527 This operation is performed on an internally stored port and is only
11528 reflected in a subsequent paste operation."
11529 (interactive)
11530 (if (not vhdl-port-list)
11531 (error "ERROR: No port has been read")
11532 (message "Reversing port directions for next paste...")
11533 (let ((port-list (nth 2 vhdl-port-list))
11534 port-dir-car port-dir)
11535 ;; traverse port list and reverse directions
11536 (while port-list
11537 (setq port-dir-car (cddr (car port-list))
11538 port-dir (car port-dir-car))
11539 (setcar port-dir-car
11540 (cond ((equal port-dir "in") "out")
11541 ((equal port-dir "IN") "OUT")
11542 ((equal port-dir "out") "in")
11543 ((equal port-dir "OUT") "IN")
11544 (t port-dir)))
11545 (setq port-list (cdr port-list)))
11546 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11547 (message "Reversing port directions for next paste...done"))))
11549 (defun vhdl-port-copy ()
11550 "Get generic and port information from an entity or component declaration."
11551 (interactive)
11552 (save-excursion
11553 (let (parse-error end-of-list
11554 decl-type name generic-list port-list context-clause
11555 object names direct type init comment group-comment)
11556 (vhdl-prepare-search-2
11557 (setq
11558 parse-error
11559 (catch 'parse
11560 ;; check if within entity or component declaration
11561 (end-of-line)
11562 (when (or (not (re-search-backward
11563 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11564 (equal "END" (upcase (match-string 1))))
11565 (throw 'parse "ERROR: Not within an entity or component declaration"))
11566 (setq decl-type (downcase (match-string-no-properties 1)))
11567 (forward-word 1)
11568 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11569 (setq name (match-string-no-properties 1))
11570 (message "Reading port of %s \"%s\"..." decl-type name)
11571 (vhdl-forward-syntactic-ws)
11572 ;; parse generic clause
11573 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11574 ;; parse group comment and spacing
11575 (setq group-comment (vhdl-parse-group-comment))
11576 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11577 (while (not end-of-list)
11578 ;; parse names (accept extended identifiers)
11579 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11580 (setq names (list (match-string-no-properties 1)))
11581 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11582 (setq names
11583 (append names (list (match-string-no-properties 1)))))
11584 ;; parse type
11585 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11586 (setq type (match-string-no-properties 1))
11587 (when (vhdl-in-comment-p) ; if stuck in comment
11588 (setq type (concat type (and (vhdl-parse-string ".*")
11589 (match-string-no-properties 0)))))
11590 (setq comment nil)
11591 (while (looking-at "(")
11592 (setq type
11593 (concat type
11594 (buffer-substring-no-properties
11595 (point) (progn (forward-sexp) (point)))
11596 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11597 (match-string-no-properties 1)))))
11598 ;; special case: closing parenthesis is on separate line
11599 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11600 (setq comment (substring type (match-beginning 2)))
11601 (setq type (substring type 0 (match-beginning 1))))
11602 ;; strip of trailing group-comment
11603 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11604 (setq type (substring type 0 (match-end 1)))
11605 ;; parse initialization expression
11606 (setq init nil)
11607 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11608 (vhdl-parse-string "\\([^();\n]*\\)")
11609 (setq init (match-string-no-properties 1))
11610 (while (looking-at "(")
11611 (setq init
11612 (concat init
11613 (buffer-substring-no-properties
11614 (point) (progn (forward-sexp) (point)))
11615 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11616 (match-string-no-properties 1))))))
11617 ;; special case: closing parenthesis is on separate line
11618 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11619 (setq comment (substring init (match-beginning 2)))
11620 (setq init (substring init 0 (match-beginning 1)))
11621 (vhdl-forward-syntactic-ws))
11622 (skip-chars-forward " \t")
11623 ;; parse inline comment, special case: as above, no initial.
11624 (unless comment
11625 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11626 (match-string-no-properties 1))))
11627 (vhdl-forward-syntactic-ws)
11628 (setq end-of-list (vhdl-parse-string ")" t))
11629 (vhdl-parse-string "\\s-*;\\s-*")
11630 ;; parse inline comment
11631 (unless comment
11632 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11633 (match-string-no-properties 1))))
11634 ;; save everything in list
11635 (setq generic-list (append generic-list
11636 (list (list names type init
11637 comment group-comment))))
11638 ;; parse group comment and spacing
11639 (setq group-comment (vhdl-parse-group-comment))))
11640 ;; parse port clause
11641 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11642 ;; parse group comment and spacing
11643 (setq group-comment (vhdl-parse-group-comment))
11644 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11645 (while (not end-of-list)
11646 ;; parse object
11647 (setq object
11648 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11649 (match-string-no-properties 1)))
11650 ;; parse names (accept extended identifiers)
11651 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11652 (setq names (list (match-string-no-properties 1)))
11653 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11654 (setq names (append names (list (match-string-no-properties 1)))))
11655 ;; parse direction
11656 (vhdl-parse-string ":[ \t\n\r\f]*")
11657 (setq direct
11658 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11659 (match-string-no-properties 1)))
11660 ;; parse type
11661 (vhdl-parse-string "\\([^();\n]+\\)")
11662 (setq type (match-string-no-properties 1))
11663 (when (vhdl-in-comment-p) ; if stuck in comment
11664 (setq type (concat type (and (vhdl-parse-string ".*")
11665 (match-string-no-properties 0)))))
11666 (setq comment nil)
11667 (while (looking-at "(")
11668 (setq type (concat type
11669 (buffer-substring-no-properties
11670 (point) (progn (forward-sexp) (point)))
11671 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11672 (match-string-no-properties 1)))))
11673 ;; special case: closing parenthesis is on separate line
11674 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11675 (setq comment (substring type (match-beginning 2)))
11676 (setq type (substring type 0 (match-beginning 1))))
11677 ;; strip of trailing group-comment
11678 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11679 (setq type (substring type 0 (match-end 1)))
11680 (vhdl-forward-syntactic-ws)
11681 (setq end-of-list (vhdl-parse-string ")" t))
11682 (vhdl-parse-string "\\s-*;\\s-*")
11683 ;; parse inline comment
11684 (unless comment
11685 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11686 (match-string-no-properties 1))))
11687 ;; save everything in list
11688 (setq port-list (append port-list
11689 (list (list names object direct type
11690 comment group-comment))))
11691 ;; parse group comment and spacing
11692 (setq group-comment (vhdl-parse-group-comment))))
11693 ;; parse context clause
11694 (setq context-clause (vhdl-scan-context-clause))
11695 ; ;; add surrounding package to context clause
11696 ; (when (and (equal decl-type "component")
11697 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11698 ; (setq context-clause
11699 ; (append context-clause
11700 ; (list (cons (vhdl-work-library)
11701 ; (match-string-no-properties 1))))))
11702 (message "Reading port of %s \"%s\"...done" decl-type name)
11703 nil)))
11704 ;; finish parsing
11705 (if parse-error
11706 (error parse-error)
11707 (setq vhdl-port-list (list name generic-list port-list context-clause)
11708 vhdl-port-reversed-direction nil
11709 vhdl-port-flattened nil)))))
11711 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11712 "Paste a context clause."
11713 (let ((margin (current-indentation))
11714 (clause-list (nth 3 vhdl-port-list))
11715 clause)
11716 (while clause-list
11717 (setq clause (car clause-list))
11718 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11719 (downcase exclude-pack-name)))
11720 (save-excursion
11721 (re-search-backward
11722 (concat "^\\s-*use\\s-+" (car clause)
11723 "\." (cdr clause) "\\>") nil t)))
11724 (vhdl-template-standard-package (car clause) (cdr clause))
11725 (insert "\n"))
11726 (setq clause-list (cdr clause-list)))))
11728 (defun vhdl-port-paste-generic (&optional no-init)
11729 "Paste a generic clause."
11730 (let ((margin (current-indentation))
11731 (generic-list (nth 1 vhdl-port-list))
11732 list-margin start names generic)
11733 ;; paste generic clause
11734 (when generic-list
11735 (setq start (point))
11736 (vhdl-insert-keyword "GENERIC (")
11737 (unless vhdl-argument-list-indent
11738 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11739 (setq list-margin (current-column))
11740 (while generic-list
11741 (setq generic (car generic-list))
11742 ;; paste group comment and spacing
11743 (when (memq vhdl-include-group-comments '(decl always))
11744 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11745 ;; paste names
11746 (setq names (nth 0 generic))
11747 (while names
11748 (insert (car names))
11749 (setq names (cdr names))
11750 (when names (insert ", ")))
11751 ;; paste type
11752 (insert " : " (nth 1 generic))
11753 ;; paste initialization
11754 (when (and (not no-init) (nth 2 generic))
11755 (insert " := " (nth 2 generic)))
11756 (unless (cdr generic-list) (insert ")"))
11757 (insert ";")
11758 ;; paste comment
11759 (when (and vhdl-include-port-comments (nth 3 generic))
11760 (vhdl-comment-insert-inline (nth 3 generic) t))
11761 (setq generic-list (cdr generic-list))
11762 (when generic-list (insert "\n") (indent-to list-margin)))
11763 ;; align generic clause
11764 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11766 (defun vhdl-port-paste-port ()
11767 "Paste a port clause."
11768 (let ((margin (current-indentation))
11769 (port-list (nth 2 vhdl-port-list))
11770 list-margin start names port)
11771 ;; paste port clause
11772 (when port-list
11773 (setq start (point))
11774 (vhdl-insert-keyword "PORT (")
11775 (unless vhdl-argument-list-indent
11776 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11777 (setq list-margin (current-column))
11778 (while port-list
11779 (setq port (car port-list))
11780 ;; paste group comment and spacing
11781 (when (memq vhdl-include-group-comments '(decl always))
11782 (vhdl-paste-group-comment (nth 5 port) list-margin))
11783 ;; paste object
11784 (when (nth 1 port) (insert (nth 1 port) " "))
11785 ;; paste names
11786 (setq names (nth 0 port))
11787 (while names
11788 (insert (car names))
11789 (setq names (cdr names))
11790 (when names (insert ", ")))
11791 ;; paste direction
11792 (insert " : ")
11793 (when (nth 2 port) (insert (nth 2 port) " "))
11794 ;; paste type
11795 (insert (nth 3 port))
11796 (unless (cdr port-list) (insert ")"))
11797 (insert ";")
11798 ;; paste comment
11799 (when (and vhdl-include-port-comments (nth 4 port))
11800 (vhdl-comment-insert-inline (nth 4 port) t))
11801 (setq port-list (cdr port-list))
11802 (when port-list (insert "\n") (indent-to list-margin)))
11803 ;; align port clause
11804 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11806 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11807 "Paste as an entity or component declaration."
11808 (unless no-indent (indent-according-to-mode))
11809 (let ((margin (current-indentation))
11810 (name (nth 0 vhdl-port-list)))
11811 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11812 (insert name)
11813 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11814 (vhdl-insert-keyword " IS"))
11815 ;; paste generic and port clause
11816 (when (nth 1 vhdl-port-list)
11817 (insert "\n")
11818 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11819 (insert "\n"))
11820 (indent-to (+ margin vhdl-basic-offset))
11821 (vhdl-port-paste-generic (eq kind 'component)))
11822 (when (nth 2 vhdl-port-list)
11823 (insert "\n")
11824 (when (and (memq vhdl-insert-empty-lines '(unit all))
11825 (eq kind 'entity))
11826 (insert "\n"))
11827 (indent-to (+ margin vhdl-basic-offset)))
11828 (vhdl-port-paste-port)
11829 (insert "\n")
11830 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11831 (insert "\n"))
11832 (indent-to margin)
11833 (vhdl-insert-keyword "END")
11834 (if (eq kind 'entity)
11835 (progn
11836 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11837 (insert " " name))
11838 (vhdl-insert-keyword " COMPONENT")
11839 (unless (vhdl-standard-p '87) (insert " " name)))
11840 (insert ";")))
11842 (defun vhdl-port-paste-entity (&optional no-indent)
11843 "Paste as an entity declaration."
11844 (interactive)
11845 (if (not vhdl-port-list)
11846 (error "ERROR: No port read")
11847 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11848 (vhdl-port-paste-declaration 'entity no-indent)
11849 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11851 (defun vhdl-port-paste-component (&optional no-indent)
11852 "Paste as a component declaration."
11853 (interactive)
11854 (if (not vhdl-port-list)
11855 (error "ERROR: No port read")
11856 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11857 (vhdl-port-paste-declaration 'component no-indent)
11858 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11860 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11861 "Paste as a generic map."
11862 (interactive)
11863 (unless secondary (indent-according-to-mode))
11864 (let ((margin (current-indentation))
11865 list-margin start generic
11866 (generic-list (nth 1 vhdl-port-list)))
11867 (when generic-list
11868 (setq start (point))
11869 (vhdl-insert-keyword "GENERIC MAP (")
11870 (if (not vhdl-association-list-with-formals)
11871 ;; paste list of actual generics
11872 (while generic-list
11873 (insert (if no-constants
11874 (car (nth 0 (car generic-list)))
11875 (or (nth 2 (car generic-list)) " ")))
11876 (setq generic-list (cdr generic-list))
11877 (insert (if generic-list ", " ")"))
11878 (when (and (not generic-list) secondary
11879 (null (nth 2 vhdl-port-list)))
11880 (insert ";")))
11881 (unless vhdl-argument-list-indent
11882 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11883 (setq list-margin (current-column))
11884 (while generic-list
11885 (setq generic (car generic-list))
11886 ;; paste group comment and spacing
11887 (when (eq vhdl-include-group-comments 'always)
11888 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11889 ;; paste formal and actual generic
11890 (insert (car (nth 0 generic)) " => "
11891 (if no-constants
11892 (vhdl-replace-string vhdl-actual-generic-name
11893 (car (nth 0 generic)))
11894 (or (nth 2 generic) "")))
11895 (setq generic-list (cdr generic-list))
11896 (insert (if generic-list "," ")"))
11897 (when (and (not generic-list) secondary
11898 (null (nth 2 vhdl-port-list)))
11899 (insert ";"))
11900 ;; paste comment
11901 (when (or vhdl-include-type-comments
11902 (and vhdl-include-port-comments (nth 3 generic)))
11903 (vhdl-comment-insert-inline
11904 (concat
11905 (when vhdl-include-type-comments
11906 (concat "[" (nth 1 generic) "] "))
11907 (when vhdl-include-port-comments (nth 3 generic))) t))
11908 (when generic-list (insert "\n") (indent-to list-margin)))
11909 ;; align generic map
11910 (when vhdl-auto-align
11911 (vhdl-align-region-groups start (point) 1 t))))))
11913 (defun vhdl-port-paste-port-map ()
11914 "Paste as a port map."
11915 (let ((margin (current-indentation))
11916 list-margin start port
11917 (port-list (nth 2 vhdl-port-list)))
11918 (when port-list
11919 (setq start (point))
11920 (vhdl-insert-keyword "PORT MAP (")
11921 (if (not vhdl-association-list-with-formals)
11922 ;; paste list of actual ports
11923 (while port-list
11924 (insert (vhdl-replace-string vhdl-actual-port-name
11925 (car (nth 0 (car port-list)))))
11926 (setq port-list (cdr port-list))
11927 (insert (if port-list ", " ")")))
11928 (unless vhdl-argument-list-indent
11929 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11930 (setq list-margin (current-column))
11931 (while port-list
11932 (setq port (car port-list))
11933 ;; paste group comment and spacing
11934 (when (eq vhdl-include-group-comments 'always)
11935 (vhdl-paste-group-comment (nth 5 port) list-margin))
11936 ;; paste formal and actual port
11937 (insert (car (nth 0 port)) " => ")
11938 (insert (vhdl-replace-string vhdl-actual-port-name
11939 (car (nth 0 port))))
11940 (setq port-list (cdr port-list))
11941 (insert (if port-list "," ");"))
11942 ;; paste comment
11943 (when (or (and vhdl-include-direction-comments (nth 2 port))
11944 vhdl-include-type-comments
11945 (and vhdl-include-port-comments (nth 4 port)))
11946 (vhdl-comment-insert-inline
11947 (concat
11948 (cond ((and vhdl-include-direction-comments
11949 vhdl-include-type-comments)
11950 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11951 (nth 3 port) "] "))
11952 ((and vhdl-include-direction-comments (nth 2 port))
11953 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11954 (vhdl-include-direction-comments " ")
11955 (vhdl-include-type-comments
11956 (concat "[" (nth 3 port) "] ")))
11957 (when vhdl-include-port-comments (nth 4 port))) t))
11958 (when port-list (insert "\n") (indent-to list-margin)))
11959 ;; align port clause
11960 (when vhdl-auto-align
11961 (vhdl-align-region-groups start (point) 1))))))
11963 (defun vhdl-port-paste-instance (&optional name no-indent title)
11964 "Paste as an instantiation."
11965 (interactive)
11966 (if (not vhdl-port-list)
11967 (error "ERROR: No port read")
11968 (let ((orig-vhdl-port-list vhdl-port-list))
11969 ;; flatten local copy of port list (must be flat for port mapping)
11970 (vhdl-port-flatten)
11971 (unless no-indent (indent-according-to-mode))
11972 (let ((margin (current-indentation)))
11973 ;; paste instantiation
11974 (cond (name
11975 (insert name))
11976 ((equal (cdr vhdl-instance-name) "")
11977 (setq name (vhdl-template-field "instance name")))
11978 ((string-match "\%d" (cdr vhdl-instance-name))
11979 (let ((n 1))
11980 (while (save-excursion
11981 (setq name (format (vhdl-replace-string
11982 vhdl-instance-name
11983 (nth 0 vhdl-port-list)) n))
11984 (goto-char (point-min))
11985 (vhdl-re-search-forward name nil t))
11986 (setq n (1+ n)))
11987 (insert name)))
11988 (t (insert (vhdl-replace-string vhdl-instance-name
11989 (nth 0 vhdl-port-list)))))
11990 (message "Pasting port as instantiation \"%s\"..." name)
11991 (insert ": ")
11992 (when title
11993 (save-excursion
11994 (beginning-of-line)
11995 (indent-to vhdl-basic-offset)
11996 (insert "-- instance \"" name "\"\n")))
11997 (if (not (vhdl-use-direct-instantiation))
11998 (insert (nth 0 vhdl-port-list))
11999 (vhdl-insert-keyword "ENTITY ")
12000 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
12001 (when (nth 1 vhdl-port-list)
12002 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12003 (vhdl-port-paste-generic-map t t))
12004 (when (nth 2 vhdl-port-list)
12005 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12006 (vhdl-port-paste-port-map))
12007 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
12008 (insert ";"))
12009 (message "Pasting port as instantiation \"%s\"...done" name))
12010 (setq vhdl-port-list orig-vhdl-port-list))))
12012 (defun vhdl-port-paste-constants (&optional no-indent)
12013 "Paste generics as constants."
12014 (interactive)
12015 (if (not vhdl-port-list)
12016 (error "ERROR: No port read")
12017 (let ((orig-vhdl-port-list vhdl-port-list))
12018 (message "Pasting port as constants...")
12019 ;; flatten local copy of port list (must be flat for constant initial.)
12020 (vhdl-port-flatten)
12021 (unless no-indent (indent-according-to-mode))
12022 (let ((margin (current-indentation))
12023 start generic name
12024 (generic-list (nth 1 vhdl-port-list)))
12025 (when generic-list
12026 (setq start (point))
12027 (while generic-list
12028 (setq generic (car generic-list))
12029 ;; paste group comment and spacing
12030 (when (memq vhdl-include-group-comments '(decl always))
12031 (vhdl-paste-group-comment (nth 4 generic) margin))
12032 (vhdl-insert-keyword "CONSTANT ")
12033 ;; paste generic constants
12034 (setq name (nth 0 generic))
12035 (when name
12036 (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
12037 ;; paste type
12038 (insert " : " (nth 1 generic))
12039 ;; paste initialization
12040 (when (nth 2 generic)
12041 (insert " := " (nth 2 generic)))
12042 (insert ";")
12043 ;; paste comment
12044 (when (and vhdl-include-port-comments (nth 3 generic))
12045 (vhdl-comment-insert-inline (nth 3 generic) t))
12046 (setq generic-list (cdr generic-list))
12047 (when generic-list (insert "\n") (indent-to margin))))
12048 ;; align signal list
12049 (when vhdl-auto-align
12050 (vhdl-align-region-groups start (point) 1))))
12051 (message "Pasting port as constants...done")
12052 (setq vhdl-port-list orig-vhdl-port-list))))
12054 (defun vhdl-port-paste-signals (&optional initialize no-indent)
12055 "Paste ports as internal signals."
12056 (interactive)
12057 (if (not vhdl-port-list)
12058 (error "ERROR: No port read")
12059 (message "Pasting port as signals...")
12060 (unless no-indent (indent-according-to-mode))
12061 (let ((margin (current-indentation))
12062 start port names type generic-list port-name constant-name pos
12063 (port-list (nth 2 vhdl-port-list)))
12064 (when port-list
12065 (setq start (point))
12066 (while port-list
12067 (setq port (car port-list))
12068 ;; paste group comment and spacing
12069 (when (memq vhdl-include-group-comments '(decl always))
12070 (vhdl-paste-group-comment (nth 5 port) margin))
12071 ;; paste object
12072 (if (nth 1 port)
12073 (insert (nth 1 port) " ")
12074 (vhdl-insert-keyword "SIGNAL "))
12075 ;; paste actual port signals
12076 (setq names (nth 0 port))
12077 (while names
12078 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
12079 (setq names (cdr names))
12080 (when names (insert ", ")))
12081 ;; paste type
12082 (setq type (nth 3 port))
12083 (setq generic-list (nth 1 vhdl-port-list))
12084 (vhdl-prepare-search-1
12085 (setq pos 0)
12086 ;; replace formal by actual generics
12087 (while generic-list
12088 (setq port-name (car (nth 0 (car generic-list))))
12089 (while (string-match (concat "\\<" port-name "\\>") type pos)
12090 (setq constant-name
12091 (save-match-data (vhdl-replace-string
12092 vhdl-actual-generic-name port-name)))
12093 (setq type (replace-match constant-name t nil type))
12094 (setq pos (match-end 0)))
12095 (setq generic-list (cdr generic-list))))
12096 (insert " : " type)
12097 ;; paste initialization (inputs only)
12098 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
12099 (insert " := "
12100 (cond ((string-match "integer" (nth 3 port)) "0")
12101 ((string-match "natural" (nth 3 port)) "0")
12102 ((string-match "positive" (nth 3 port)) "0")
12103 ((string-match "real" (nth 3 port)) "0.0")
12104 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12105 (t "'0'"))))
12106 (insert ";")
12107 ;; paste comment
12108 (when (or (and vhdl-include-direction-comments (nth 2 port))
12109 (and vhdl-include-port-comments (nth 4 port)))
12110 (vhdl-comment-insert-inline
12111 (concat
12112 (cond ((and vhdl-include-direction-comments (nth 2 port))
12113 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12114 (vhdl-include-direction-comments " "))
12115 (when vhdl-include-port-comments (nth 4 port))) t))
12116 (setq port-list (cdr port-list))
12117 (when port-list (insert "\n") (indent-to margin)))
12118 ;; align signal list
12119 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12120 (message "Pasting port as signals...done")))
12122 (defun vhdl-port-paste-initializations (&optional no-indent)
12123 "Paste ports as signal initializations."
12124 (interactive)
12125 (if (not vhdl-port-list)
12126 (error "ERROR: No port read")
12127 (let ((orig-vhdl-port-list vhdl-port-list))
12128 (message "Pasting port as initializations...")
12129 ;; flatten local copy of port list (must be flat for signal initial.)
12130 (vhdl-port-flatten)
12131 (unless no-indent (indent-according-to-mode))
12132 (let ((margin (current-indentation))
12133 start port name
12134 (port-list (nth 2 vhdl-port-list)))
12135 (when port-list
12136 (setq start (point))
12137 (while port-list
12138 (setq port (car port-list))
12139 ;; paste actual port signal (inputs only)
12140 (when (equal "IN" (upcase (nth 2 port)))
12141 (setq name (car (nth 0 port)))
12142 (insert (vhdl-replace-string vhdl-actual-port-name name))
12143 ;; paste initialization
12144 (insert " <= "
12145 (cond ((string-match "integer" (nth 3 port)) "0")
12146 ((string-match "natural" (nth 3 port)) "0")
12147 ((string-match "positive" (nth 3 port)) "0")
12148 ((string-match "real" (nth 3 port)) "0.0")
12149 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12150 (t "'0'"))
12151 ";"))
12152 (setq port-list (cdr port-list))
12153 (when (and port-list
12154 (equal "IN" (upcase (nth 2 (car port-list)))))
12155 (insert "\n") (indent-to margin)))
12156 ;; align signal list
12157 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12158 (message "Pasting port as initializations...done")
12159 (setq vhdl-port-list orig-vhdl-port-list))))
12161 (defun vhdl-port-paste-testbench ()
12162 "Paste as a bare-bones testbench."
12163 (interactive)
12164 (if (not vhdl-port-list)
12165 (error "ERROR: No port read")
12166 (let ((case-fold-search t)
12167 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12168 (nth 0 vhdl-port-list)))
12169 (source-buffer (current-buffer))
12170 arch-name config-name ent-file-name arch-file-name
12171 ent-buffer arch-buffer position)
12172 ;; open entity file
12173 (unless (eq vhdl-testbench-create-files 'none)
12174 (setq ent-file-name
12175 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12176 ent-name t)
12177 "." (file-name-extension (buffer-file-name))))
12178 (if (file-exists-p ent-file-name)
12179 (if (y-or-n-p
12180 (concat "File \"" ent-file-name "\" exists; overwrite? "))
12181 (progn (find-file ent-file-name)
12182 (erase-buffer)
12183 (set-buffer-modified-p nil))
12184 (if (eq vhdl-testbench-create-files 'separate)
12185 (setq ent-file-name nil)
12186 (error "ERROR: Pasting port as testbench...aborted")))
12187 (find-file ent-file-name)))
12188 (unless (and (eq vhdl-testbench-create-files 'separate)
12189 (null ent-file-name))
12190 ;; paste entity header
12191 (if vhdl-testbench-include-header
12192 (progn (vhdl-template-header
12193 (concat "Testbench for design \""
12194 (nth 0 vhdl-port-list) "\""))
12195 (goto-char (point-max)))
12196 (vhdl-comment-display-line) (insert "\n\n"))
12197 ;; paste std_logic_1164 package
12198 (when vhdl-testbench-include-library
12199 (vhdl-template-package-std-logic-1164)
12200 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12201 ;; paste entity declaration
12202 (vhdl-insert-keyword "ENTITY ")
12203 (insert ent-name)
12204 (vhdl-insert-keyword " IS")
12205 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
12206 (insert "\n")
12207 (vhdl-insert-keyword "END ")
12208 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12209 (insert ent-name ";")
12210 (insert "\n\n")
12211 (vhdl-comment-display-line) (insert "\n"))
12212 ;; get architecture name
12213 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
12214 (read-from-minibuffer "architecture name: "
12215 nil vhdl-minibuffer-local-map)
12216 (vhdl-replace-string vhdl-testbench-architecture-name
12217 (nth 0 vhdl-port-list))))
12218 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
12219 ;; open architecture file
12220 (if (not (eq vhdl-testbench-create-files 'separate))
12221 (insert "\n")
12222 (setq ent-buffer (current-buffer))
12223 (setq arch-file-name
12224 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12225 (concat ent-name " " arch-name) t)
12226 "." (file-name-extension (buffer-file-name))))
12227 (when (and (file-exists-p arch-file-name)
12228 (not (y-or-n-p (concat "File \"" arch-file-name
12229 "\" exists; overwrite? "))))
12230 (error "ERROR: Pasting port as testbench...aborted"))
12231 (find-file arch-file-name)
12232 (erase-buffer)
12233 (set-buffer-modified-p nil)
12234 ;; paste architecture header
12235 (if vhdl-testbench-include-header
12236 (progn (vhdl-template-header
12237 (concat "Testbench architecture for design \""
12238 (nth 0 vhdl-port-list) "\""))
12239 (goto-char (point-max)))
12240 (vhdl-comment-display-line) (insert "\n\n")))
12241 ;; paste architecture body
12242 (vhdl-insert-keyword "ARCHITECTURE ")
12243 (insert arch-name)
12244 (vhdl-insert-keyword " OF ")
12245 (insert ent-name)
12246 (vhdl-insert-keyword " IS")
12247 (insert "\n\n") (indent-to vhdl-basic-offset)
12248 ;; paste component declaration
12249 (unless (vhdl-use-direct-instantiation)
12250 (vhdl-port-paste-component t)
12251 (insert "\n\n") (indent-to vhdl-basic-offset))
12252 ;; paste constants
12253 (when (nth 1 vhdl-port-list)
12254 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
12255 (vhdl-port-paste-constants t)
12256 (insert "\n\n") (indent-to vhdl-basic-offset))
12257 ;; paste internal signals
12258 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
12259 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
12260 (insert "\n")
12261 ;; paste custom declarations
12262 (unless (equal "" vhdl-testbench-declarations)
12263 (insert "\n")
12264 (setq position (point))
12265 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12266 (vhdl-indent-region position (point)))
12267 (setq position (point))
12268 (insert "\n\n")
12269 (vhdl-comment-display-line) (insert "\n")
12270 (when vhdl-testbench-include-configuration
12271 (setq config-name (vhdl-replace-string
12272 vhdl-testbench-configuration-name
12273 (concat ent-name " " arch-name)))
12274 (insert "\n")
12275 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12276 (vhdl-insert-keyword " OF ") (insert ent-name)
12277 (vhdl-insert-keyword " IS\n")
12278 (indent-to vhdl-basic-offset)
12279 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12280 (indent-to vhdl-basic-offset)
12281 (vhdl-insert-keyword "END FOR;\n")
12282 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12283 (vhdl-comment-display-line) (insert "\n"))
12284 (goto-char position)
12285 (vhdl-template-begin-end
12286 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12287 ;; paste instantiation
12288 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12289 (vhdl-port-paste-instance
12290 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12291 (insert "\n")
12292 ;; paste custom statements
12293 (unless (equal "" vhdl-testbench-statements)
12294 (insert "\n")
12295 (setq position (point))
12296 (vhdl-insert-string-or-file vhdl-testbench-statements)
12297 (vhdl-indent-region position (point)))
12298 (insert "\n")
12299 (indent-to vhdl-basic-offset)
12300 (unless (eq vhdl-testbench-create-files 'none)
12301 (setq arch-buffer (current-buffer))
12302 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12303 (set-buffer arch-buffer) (save-buffer))
12304 (message "%s"
12305 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12306 ent-name arch-name)
12307 (and ent-file-name
12308 (format "\n File created: \"%s\"" ent-file-name))
12309 (and arch-file-name
12310 (format "\n File created: \"%s\"" arch-file-name)))))))
12313 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12314 ;;; Subprogram interface translation
12315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12317 (defvar vhdl-subprog-list nil
12318 "Variable to hold last subprogram interface parsed.")
12319 ;; structure: (parenthesized expression means list of such entries)
12320 ;; (subprog-name kind
12321 ;; ((names) object direct type init comment group-comment)
12322 ;; return-type return-comment group-comment)
12324 (defvar vhdl-subprog-flattened nil
12325 "Indicates whether an subprogram interface has been flattened.")
12327 (defun vhdl-subprog-flatten ()
12328 "Flatten interface list so that only one parameter exists per line."
12329 (interactive)
12330 (if (not vhdl-subprog-list)
12331 (error "ERROR: No subprogram interface has been read")
12332 (message "Flattening subprogram interface...")
12333 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12334 new-subprog-list old-subprog new-subprog names)
12335 ;; traverse parameter list and flatten entries
12336 (while old-subprog-list
12337 (setq old-subprog (car old-subprog-list))
12338 (setq names (car old-subprog))
12339 (while names
12340 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12341 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12342 (setq names (cdr names)))
12343 (setq old-subprog-list (cdr old-subprog-list)))
12344 (setq vhdl-subprog-list
12345 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12346 new-subprog-list (nth 3 vhdl-subprog-list)
12347 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12348 vhdl-subprog-flattened t)
12349 (message "Flattening subprogram interface...done"))))
12351 (defun vhdl-subprog-copy ()
12352 "Get interface information from a subprogram specification."
12353 (interactive)
12354 (save-excursion
12355 (let (parse-error pos end-of-list
12356 name kind param-list object names direct type init
12357 comment group-comment
12358 return-type return-comment return-group-comment)
12359 (vhdl-prepare-search-2
12360 (setq
12361 parse-error
12362 (catch 'parse
12363 ;; check if within function declaration
12364 (setq pos (point))
12365 (end-of-line)
12366 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12367 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12368 (goto-char (match-end 0))
12369 (save-excursion (backward-char)
12370 (forward-sexp)
12371 (<= pos (point))))
12372 (throw 'parse "ERROR: Not within a subprogram specification"))
12373 (setq name (match-string-no-properties 5))
12374 (setq kind (if (match-string 2) 'procedure 'function))
12375 (setq end-of-list (not (match-string 7)))
12376 (message "Reading interface of subprogram \"%s\"..." name)
12377 ;; parse parameter list
12378 (setq group-comment (vhdl-parse-group-comment))
12379 (setq end-of-list (or end-of-list
12380 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12381 (while (not end-of-list)
12382 ;; parse object
12383 (setq object
12384 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12385 (match-string-no-properties 1)))
12386 ;; parse names (accept extended identifiers)
12387 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12388 (setq names (list (match-string-no-properties 1)))
12389 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12390 (setq names (append names (list (match-string-no-properties 1)))))
12391 ;; parse direction
12392 (vhdl-parse-string ":[ \t\n\r\f]*")
12393 (setq direct
12394 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12395 (match-string-no-properties 1)))
12396 ;; parse type
12397 (vhdl-parse-string "\\([^():;\n]+\\)")
12398 (setq type (match-string-no-properties 1))
12399 (setq comment nil)
12400 (while (looking-at "(")
12401 (setq type
12402 (concat type
12403 (buffer-substring-no-properties
12404 (point) (progn (forward-sexp) (point)))
12405 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12406 (match-string-no-properties 1)))))
12407 ;; special case: closing parenthesis is on separate line
12408 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12409 (setq comment (substring type (match-beginning 2)))
12410 (setq type (substring type 0 (match-beginning 1))))
12411 ;; strip off trailing group-comment
12412 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12413 (setq type (substring type 0 (match-end 1)))
12414 ;; parse initialization expression
12415 (setq init nil)
12416 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12417 (vhdl-parse-string "\\([^();\n]*\\)")
12418 (setq init (match-string-no-properties 1))
12419 (while (looking-at "(")
12420 (setq init
12421 (concat init
12422 (buffer-substring-no-properties
12423 (point) (progn (forward-sexp) (point)))
12424 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12425 (match-string-no-properties 1))))))
12426 ;; special case: closing parenthesis is on separate line
12427 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12428 (setq comment (substring init (match-beginning 2)))
12429 (setq init (substring init 0 (match-beginning 1)))
12430 (vhdl-forward-syntactic-ws))
12431 (skip-chars-forward " \t")
12432 ;; parse inline comment, special case: as above, no initial.
12433 (unless comment
12434 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12435 (match-string-no-properties 1))))
12436 (vhdl-forward-syntactic-ws)
12437 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12438 ;; parse inline comment
12439 (unless comment
12440 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12441 (match-string-no-properties 1))))
12442 (setq return-group-comment (vhdl-parse-group-comment))
12443 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12444 ;; parse return type
12445 (when (match-string 3)
12446 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12447 (setq return-type (match-string-no-properties 1))
12448 (when (and return-type
12449 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12450 (setq return-comment (substring return-type (match-beginning 2)))
12451 (setq return-type (substring return-type 0 (match-beginning 1))))
12452 ;; strip of trailing group-comment
12453 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12454 (setq return-type (substring return-type 0 (match-end 1)))
12455 ;; parse return comment
12456 (unless return-comment
12457 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12458 (match-string-no-properties 1)))))
12459 ;; parse inline comment
12460 (unless comment
12461 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12462 (match-string-no-properties 1))))
12463 ;; save everything in list
12464 (setq param-list (append param-list
12465 (list (list names object direct type init
12466 comment group-comment))))
12467 ;; parse group comment and spacing
12468 (setq group-comment (vhdl-parse-group-comment)))
12469 (message "Reading interface of subprogram \"%s\"...done" name)
12470 nil)))
12471 ;; finish parsing
12472 (if parse-error
12473 (error parse-error)
12474 (setq vhdl-subprog-list
12475 (list name kind param-list return-type return-comment
12476 return-group-comment)
12477 vhdl-subprog-flattened nil)))))
12479 (defun vhdl-subprog-paste-specification (kind)
12480 "Paste as a subprogram specification."
12481 (indent-according-to-mode)
12482 (let ((margin (current-column))
12483 (param-list (nth 2 vhdl-subprog-list))
12484 list-margin start names param)
12485 ;; paste keyword and name
12486 (vhdl-insert-keyword
12487 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12488 (insert (nth 0 vhdl-subprog-list))
12489 (if (not param-list)
12490 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12491 (setq start (point))
12492 ;; paste parameter list
12493 (insert " (")
12494 (unless vhdl-argument-list-indent
12495 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12496 (setq list-margin (current-column))
12497 (while param-list
12498 (setq param (car param-list))
12499 ;; paste group comment and spacing
12500 (when (memq vhdl-include-group-comments (list kind 'always))
12501 (vhdl-paste-group-comment (nth 6 param) list-margin))
12502 ;; paste object
12503 (when (nth 1 param) (insert (nth 1 param) " "))
12504 ;; paste names
12505 (setq names (nth 0 param))
12506 (while names
12507 (insert (car names))
12508 (setq names (cdr names))
12509 (when names (insert ", ")))
12510 ;; paste direction
12511 (insert " : ")
12512 (when (nth 2 param) (insert (nth 2 param) " "))
12513 ;; paste type
12514 (insert (nth 3 param))
12515 ;; paste initialization
12516 (when (nth 4 param) (insert " := " (nth 4 param)))
12517 ;; terminate line
12518 (if (cdr param-list)
12519 (insert ";")
12520 (insert ")")
12521 (when (null (nth 3 vhdl-subprog-list))
12522 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12523 ;; paste comment
12524 (when (and vhdl-include-port-comments (nth 5 param))
12525 (vhdl-comment-insert-inline (nth 5 param) t))
12526 (setq param-list (cdr param-list))
12527 (when param-list (insert "\n") (indent-to list-margin)))
12528 (when (nth 3 vhdl-subprog-list)
12529 (insert "\n") (indent-to list-margin)
12530 ;; paste group comment and spacing
12531 (when (memq vhdl-include-group-comments (list kind 'always))
12532 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12533 ;; paste return type
12534 (insert "return " (nth 3 vhdl-subprog-list))
12535 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12536 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12537 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12538 ;; align parameter list
12539 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12540 ;; paste body
12541 (when (eq kind 'body)
12542 (insert "\n")
12543 (vhdl-template-begin-end
12544 (unless (vhdl-standard-p '87)
12545 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12546 (nth 0 vhdl-subprog-list) margin))))
12548 (defun vhdl-subprog-paste-declaration ()
12549 "Paste as a subprogram declaration."
12550 (interactive)
12551 (if (not vhdl-subprog-list)
12552 (error "ERROR: No subprogram interface read")
12553 (message "Pasting interface as subprogram declaration \"%s\"..."
12554 (car vhdl-subprog-list))
12555 ;; paste specification
12556 (vhdl-subprog-paste-specification 'decl)
12557 (message "Pasting interface as subprogram declaration \"%s\"...done"
12558 (car vhdl-subprog-list))))
12560 (defun vhdl-subprog-paste-body ()
12561 "Paste as a subprogram body."
12562 (interactive)
12563 (if (not vhdl-subprog-list)
12564 (error "ERROR: No subprogram interface read")
12565 (message "Pasting interface as subprogram body \"%s\"..."
12566 (car vhdl-subprog-list))
12567 ;; paste specification and body
12568 (vhdl-subprog-paste-specification 'body)
12569 (message "Pasting interface as subprogram body \"%s\"...done"
12570 (car vhdl-subprog-list))))
12572 (defun vhdl-subprog-paste-call ()
12573 "Paste as a subprogram call."
12574 (interactive)
12575 (if (not vhdl-subprog-list)
12576 (error "ERROR: No subprogram interface read")
12577 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12578 param-list margin list-margin param start)
12579 ;; flatten local copy of interface list (must be flat for parameter mapping)
12580 (vhdl-subprog-flatten)
12581 (setq param-list (nth 2 vhdl-subprog-list))
12582 (indent-according-to-mode)
12583 (setq margin (current-indentation))
12584 (message "Pasting interface as subprogram call \"%s\"..."
12585 (car vhdl-subprog-list))
12586 ;; paste name
12587 (insert (nth 0 vhdl-subprog-list))
12588 (if (not param-list)
12589 (insert ";")
12590 (setq start (point))
12591 ;; paste parameter list
12592 (insert " (")
12593 (unless vhdl-argument-list-indent
12594 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12595 (setq list-margin (current-column))
12596 (while param-list
12597 (setq param (car param-list))
12598 ;; paste group comment and spacing
12599 (when (eq vhdl-include-group-comments 'always)
12600 (vhdl-paste-group-comment (nth 6 param) list-margin))
12601 ;; paste formal port
12602 (insert (car (nth 0 param)) " => ")
12603 (setq param-list (cdr param-list))
12604 (insert (if param-list "," ");"))
12605 ;; paste comment
12606 (when (and vhdl-include-port-comments (nth 5 param))
12607 (vhdl-comment-insert-inline (nth 5 param)))
12608 (when param-list (insert "\n") (indent-to list-margin)))
12609 ;; align parameter list
12610 (when vhdl-auto-align
12611 (vhdl-align-region-groups start (point) 1)))
12612 (message "Pasting interface as subprogram call \"%s\"...done"
12613 (car vhdl-subprog-list))
12614 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12617 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12618 ;;; Miscellaneous
12619 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12622 ;; Hippie expand customization
12624 (defvar vhdl-expand-upper-case nil)
12626 (defun vhdl-try-expand-abbrev (old)
12627 "Try expanding abbreviations from `vhdl-abbrev-list'."
12628 (unless old
12629 (he-init-string (he-dabbrev-beg) (point))
12630 (setq he-expand-list
12631 (let ((abbrev-list vhdl-abbrev-list)
12632 (sel-abbrev-list '()))
12633 (while abbrev-list
12634 (when (or (not (stringp (car abbrev-list)))
12635 (string-match
12636 (concat "^" he-search-string) (car abbrev-list)))
12637 (setq sel-abbrev-list
12638 (cons (car abbrev-list) sel-abbrev-list)))
12639 (setq abbrev-list (cdr abbrev-list)))
12640 (nreverse sel-abbrev-list))))
12641 (while (and he-expand-list
12642 (or (not (stringp (car he-expand-list)))
12643 (he-string-member (car he-expand-list) he-tried-table t)))
12644 (unless (stringp (car he-expand-list))
12645 (setq vhdl-expand-upper-case (car he-expand-list)))
12646 (setq he-expand-list (cdr he-expand-list)))
12647 (if (null he-expand-list)
12648 (progn (when old (he-reset-string))
12649 nil)
12650 (he-substitute-string
12651 (if vhdl-expand-upper-case
12652 (upcase (car he-expand-list))
12653 (car he-expand-list))
12655 (setq he-expand-list (cdr he-expand-list))
12658 (defun vhdl-he-list-beg ()
12659 "Also looks at the word before `(' in order to better match parenthesized
12660 expressions (e.g. for index ranges of types and signals)."
12661 (save-excursion
12662 (condition-case ()
12663 (progn (backward-up-list 1)
12664 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12665 (error ()))
12666 (point)))
12668 ;; override `he-list-beg' from `hippie-exp'
12669 (unless (and (boundp 'viper-mode) viper-mode)
12670 (defalias 'he-list-beg 'vhdl-he-list-beg))
12672 ;; function for expanding abbrevs and dabbrevs
12673 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12674 '(try-expand-dabbrev
12675 try-expand-dabbrev-all-buffers
12676 vhdl-try-expand-abbrev)))
12678 ;; function for expanding parenthesis
12679 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12680 '(try-expand-list
12681 try-expand-list-all-buffers)))
12683 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12684 ;; Line handling functions
12686 (defun vhdl-current-line ()
12687 "Return the line number of the line containing point."
12688 (save-restriction
12689 (widen)
12690 (1+ (count-lines (point-min) (point-at-bol)))))
12692 (defun vhdl-line-kill-entire (&optional arg)
12693 "Delete entire line."
12694 (interactive "p")
12695 (beginning-of-line)
12696 (kill-line (or arg 1)))
12698 (defun vhdl-line-kill (&optional arg)
12699 "Kill current line."
12700 (interactive "p")
12701 (vhdl-line-kill-entire arg))
12703 (defun vhdl-line-copy (&optional arg)
12704 "Copy current line."
12705 (interactive "p")
12706 (save-excursion
12707 (let ((position (point-at-bol)))
12708 (forward-line (or arg 1))
12709 (copy-region-as-kill position (point)))))
12711 (defun vhdl-line-yank ()
12712 "Yank entire line."
12713 (interactive)
12714 (beginning-of-line)
12715 (yank))
12717 (defun vhdl-line-expand (&optional prefix-arg)
12718 "Hippie-expand current line."
12719 (interactive "P")
12720 (require 'hippie-exp)
12721 (let ((case-fold-search t) (case-replace nil)
12722 (hippie-expand-try-functions-list
12723 '(try-expand-line try-expand-line-all-buffers)))
12724 (hippie-expand prefix-arg)))
12726 (defun vhdl-line-transpose-next (&optional arg)
12727 "Interchange this line with next line."
12728 (interactive "p")
12729 (forward-line 1)
12730 (transpose-lines (or arg 1))
12731 (forward-line -1))
12733 (defun vhdl-line-transpose-previous (&optional arg)
12734 "Interchange this line with previous line."
12735 (interactive "p")
12736 (forward-line 1)
12737 (transpose-lines (- 0 (or arg 0)))
12738 (forward-line -1))
12740 (defun vhdl-line-open ()
12741 "Open a new line and indent."
12742 (interactive)
12743 (end-of-line -0)
12744 (newline-and-indent))
12746 (defun vhdl-delete-indentation ()
12747 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12748 it works within comments too."
12749 (interactive)
12750 (let ((fill-prefix "-- "))
12751 (delete-indentation)))
12753 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12754 ;; Move functions
12756 (defun vhdl-forward-same-indent ()
12757 "Move forward to next line with same indent."
12758 (interactive)
12759 (let ((pos (point))
12760 (indent (current-indentation)))
12761 (beginning-of-line 2)
12762 (while (and (not (eobp))
12763 (or (looking-at "^\\s-*\\(--.*\\)?$")
12764 (> (current-indentation) indent)))
12765 (beginning-of-line 2))
12766 (if (= (current-indentation) indent)
12767 (back-to-indentation)
12768 (message "No following line with same indent found in this block")
12769 (goto-char pos)
12770 nil)))
12772 (defun vhdl-backward-same-indent ()
12773 "Move backward to previous line with same indent."
12774 (interactive)
12775 (let ((pos (point))
12776 (indent (current-indentation)))
12777 (beginning-of-line -0)
12778 (while (and (not (bobp))
12779 (or (looking-at "^\\s-*\\(--.*\\)?$")
12780 (> (current-indentation) indent)))
12781 (beginning-of-line -0))
12782 (if (= (current-indentation) indent)
12783 (back-to-indentation)
12784 (message "No preceding line with same indent found in this block")
12785 (goto-char pos)
12786 nil)))
12788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12789 ;; Statistics
12791 (defun vhdl-statistics-buffer ()
12792 "Get some file statistics."
12793 (interactive)
12794 (let ((no-stats 0)
12795 (no-code-lines 0)
12796 (no-empty-lines 0)
12797 (no-comm-lines 0)
12798 (no-comments 0)
12799 (no-lines (count-lines (point-min) (point-max))))
12800 (save-excursion
12801 ;; count statements
12802 (goto-char (point-min))
12803 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12804 (if (match-string 1)
12805 (goto-char (match-end 1))
12806 (setq no-stats (1+ no-stats))))
12807 ;; count code lines
12808 (goto-char (point-min))
12809 (while (not (eobp))
12810 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12811 (setq no-code-lines (1+ no-code-lines)))
12812 (beginning-of-line 2))
12813 ;; count empty lines
12814 (goto-char (point-min))
12815 (while (and (re-search-forward "^\\s-*$" nil t)
12816 (not (eq (point) (point-max))))
12817 (if (match-string 1)
12818 (goto-char (match-end 1))
12819 (setq no-empty-lines (1+ no-empty-lines))
12820 (unless (eq (point) (point-max))
12821 (forward-char))))
12822 ;; count comment-only lines
12823 (goto-char (point-min))
12824 (while (re-search-forward "^\\s-*--.*" nil t)
12825 (if (match-string 1)
12826 (goto-char (match-end 1))
12827 (setq no-comm-lines (1+ no-comm-lines))))
12828 ;; count comments
12829 (goto-char (point-min))
12830 (while (re-search-forward "--.*" nil t)
12831 (if (match-string 1)
12832 (goto-char (match-end 1))
12833 (setq no-comments (1+ no-comments)))))
12834 ;; print results
12835 (message "\n\
12836 File statistics: \"%s\"\n\
12837 -----------------------\n\
12838 # statements : %5d\n\
12839 # code lines : %5d\n\
12840 # empty lines : %5d\n\
12841 # comment lines : %5d\n\
12842 # comments : %5d\n\
12843 # total lines : %5d\n\ "
12844 (buffer-file-name) no-stats no-code-lines no-empty-lines
12845 no-comm-lines no-comments no-lines)
12846 (unless vhdl-emacs-21 (vhdl-show-messages))))
12848 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12849 ;; Help functions
12851 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12852 "Like `re-search-forward', but does not match within literals."
12853 (let (pos)
12854 (save-excursion
12855 (while (and (setq pos (re-search-forward regexp bound noerror count))
12856 (vhdl-in-literal))))
12857 (when pos (goto-char pos))
12858 pos))
12860 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12861 "Like `re-search-backward', but does not match within literals."
12862 (let (pos)
12863 (save-excursion
12864 (while (and (setq pos (re-search-backward regexp bound noerror count))
12865 (vhdl-in-literal))))
12866 (when pos (goto-char pos))
12867 pos))
12870 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12871 ;;; Project
12872 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12874 (defun vhdl-set-project (name)
12875 "Set current project to NAME."
12876 (interactive
12877 (list (let ((completion-ignore-case t))
12878 (completing-read "Project name: " vhdl-project-alist nil t))))
12879 (cond ((equal name "")
12880 (setq vhdl-project nil)
12881 (message "Current VHDL project: None"))
12882 ((assoc name vhdl-project-alist)
12883 (setq vhdl-project name)
12884 (message "Current VHDL project: \"%s\"" name))
12886 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12887 (vhdl-speedbar-update-current-project))
12889 (defun vhdl-set-default-project ()
12890 "Set current project as default on startup."
12891 (interactive)
12892 (customize-set-variable 'vhdl-project vhdl-project)
12893 (customize-save-customized))
12895 (defun vhdl-toggle-project (name token indent)
12896 "Set current project to NAME or unset if NAME is current project."
12897 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12899 (defun vhdl-export-project (file-name)
12900 "Write project setup for current project."
12901 (interactive
12902 (let ((name (vhdl-resolve-env-variable
12903 (vhdl-replace-string
12904 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12905 (concat (subst-char-in-string
12906 ? ?_ (or (vhdl-project-p)
12907 (error "ERROR: No current project")))
12908 " " (user-login-name))))))
12909 (list (read-file-name
12910 "Write project file: "
12911 (when (file-name-absolute-p name) "") nil nil name))))
12912 (setq file-name (abbreviate-file-name file-name))
12913 (let ((orig-buffer (current-buffer)))
12914 (unless (file-exists-p (file-name-directory file-name))
12915 (make-directory (file-name-directory file-name) t))
12916 (if (not (file-writable-p file-name))
12917 (error "ERROR: File not writable: \"%s\"" file-name)
12918 (set-buffer (find-file-noselect file-name t t))
12919 (erase-buffer)
12920 (insert ";; -*- Emacs-Lisp -*-\n\n"
12921 ";;; " (file-name-nondirectory file-name)
12922 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12923 ";; Project : " vhdl-project "\n"
12924 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12925 (user-login-name) "\n\n\n"
12926 ";; project name\n"
12927 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12928 ";; project setup\n"
12929 "(vhdl-aput 'vhdl-project-alist vhdl-project\n'")
12930 (pp (vhdl-aget vhdl-project-alist vhdl-project) (current-buffer))
12931 (insert ")\n")
12932 (save-buffer)
12933 (kill-buffer (current-buffer))
12934 (set-buffer orig-buffer))))
12936 (defun vhdl-import-project (file-name &optional auto not-make-current)
12937 "Read project setup and set current project."
12938 (interactive
12939 (let ((name (vhdl-resolve-env-variable
12940 (vhdl-replace-string
12941 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12942 (concat "" " " (user-login-name))))))
12943 (list (read-file-name
12944 "Read project file: " (when (file-name-absolute-p name) "") nil t
12945 (file-name-directory name)))))
12946 (when (file-exists-p file-name)
12947 (condition-case ()
12948 (let ((current-project vhdl-project))
12949 (load-file file-name)
12950 (when (/= (length (vhdl-aget vhdl-project-alist vhdl-project)) 10)
12951 (vhdl-adelete 'vhdl-project-alist vhdl-project)
12952 (error ""))
12953 (if not-make-current
12954 (setq vhdl-project current-project)
12955 (setq vhdl-compiler
12956 (caar (nth 4 (vhdl-aget vhdl-project-alist vhdl-project)))))
12957 (vhdl-update-mode-menu)
12958 (vhdl-speedbar-refresh)
12959 (unless not-make-current
12960 (message "Current VHDL project: \"%s\"; compiler: \"%s\"%s"
12961 vhdl-project vhdl-compiler (if auto " (auto-loaded)" ""))))
12962 (error (vhdl-warning
12963 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12965 (defun vhdl-duplicate-project ()
12966 "Duplicate setup of current project."
12967 (interactive)
12968 (let ((new-name (read-from-minibuffer "New project name: "))
12969 (project-entry (vhdl-aget vhdl-project-alist vhdl-project)))
12970 (setq vhdl-project-alist
12971 (append vhdl-project-alist
12972 (list (cons new-name project-entry))))
12973 (vhdl-update-mode-menu)))
12975 (defun vhdl-auto-load-project ()
12976 "Automatically load project setup at startup."
12977 (let ((file-name-list vhdl-project-file-name)
12978 file-list list-length)
12979 (while file-name-list
12980 (setq file-list
12981 (append file-list
12982 (file-expand-wildcards
12983 (vhdl-resolve-env-variable
12984 (vhdl-replace-string
12985 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12986 (concat "\*" " " (user-login-name)))))))
12987 (setq list-length (or list-length (length file-list)))
12988 (setq file-name-list (cdr file-name-list)))
12989 (while file-list
12990 (vhdl-import-project (expand-file-name (car file-list)) t
12991 (not (> list-length 0)))
12992 (setq list-length (1- list-length))
12993 (setq file-list (cdr file-list)))))
12995 ;; automatically load project setup when idle after startup
12996 (when (memq 'startup vhdl-project-auto-load)
12997 (if noninteractive
12998 (vhdl-auto-load-project)
12999 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
13002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13003 ;;; Hideshow
13004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13005 ;; (using `hideshow.el')
13007 (defconst vhdl-hs-start-regexp
13008 (concat
13009 "\\(^\\)\\s-*\\("
13010 ;; generic/port clause
13011 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
13012 ;; component
13013 "component\\>\\|"
13014 ;; component instantiation
13015 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
13016 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13017 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
13018 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
13019 ;; subprogram
13020 "\\(function\\|procedure\\)\\>\\|"
13021 ;; process, block
13022 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13023 ;; configuration declaration
13024 "configuration\\>"
13025 "\\)")
13026 "Regexp to match start of construct to hide.")
13028 (defun vhdl-hs-forward-sexp-func (count)
13029 "Find end of construct to hide (for hideshow). Only searches forward."
13030 (let ((pos (point)))
13031 (vhdl-prepare-search-2
13032 (beginning-of-line)
13033 (cond
13034 ;; generic/port clause
13035 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13036 (goto-char (match-end 0))
13037 (backward-char)
13038 (forward-sexp))
13039 ;; component declaration
13040 ((looking-at "^\\s-*component\\>")
13041 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
13042 ;; component instantiation
13043 ((looking-at
13044 (concat
13045 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13046 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13047 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13048 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13049 (goto-char (match-end 0))
13050 (backward-char)
13051 (forward-sexp)
13052 (setq pos (point))
13053 (vhdl-forward-syntactic-ws)
13054 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13055 (goto-char (match-end 0))
13056 (backward-char)
13057 (forward-sexp)
13058 (setq pos (point)))
13059 (goto-char pos))
13060 ;; subprogram declaration/body
13061 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13062 (goto-char (match-end 0))
13063 (vhdl-forward-syntactic-ws)
13064 (when (looking-at "(")
13065 (forward-sexp))
13066 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
13067 (vhdl-in-literal)))
13068 ;; subprogram body
13069 (when (match-string 2)
13070 (re-search-forward "^\\s-*\\<begin\\>" nil t)
13071 (backward-word 1)
13072 (vhdl-forward-sexp)))
13073 ;; block (recursive)
13074 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13075 (goto-char (match-end 0))
13076 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
13077 (match-beginning 2))
13078 (vhdl-hs-forward-sexp-func count)))
13079 ;; process
13080 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13081 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
13082 ;; configuration declaration
13083 ((looking-at "^\\s-*configuration\\>")
13084 (forward-word 4)
13085 (vhdl-forward-sexp))
13086 (t (goto-char pos))))))
13088 (defun vhdl-hideshow-init ()
13089 "Initialize `hideshow'."
13090 (when vhdl-hideshow-menu
13091 (vhdl-hs-minor-mode 1)))
13093 (defun vhdl-hs-minor-mode (&optional arg)
13094 "Toggle hideshow minor mode and update menu bar."
13095 (interactive "P")
13096 (require 'hideshow)
13097 ;; check for hideshow version 5.x
13098 (if (not (boundp 'hs-block-start-mdata-select))
13099 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13100 ;; initialize hideshow
13101 (unless (assoc 'vhdl-mode hs-special-modes-alist)
13102 (setq hs-special-modes-alist
13103 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
13104 'vhdl-hs-forward-sexp-func nil)
13105 hs-special-modes-alist)))
13106 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
13107 (if vhdl-hide-all-init
13108 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
13109 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
13110 (hs-minor-mode arg)
13111 (force-mode-line-update))) ; hack to update menu bar
13114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13115 ;;; Font locking
13116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13117 ;; (using `font-lock.el')
13119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13120 ;; Help functions
13122 (defun vhdl-within-translate-off ()
13123 "Return point if within translate-off region, else nil."
13124 (and (save-excursion
13125 (re-search-backward
13126 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
13127 (equal "off" (match-string 1))
13128 (point)))
13130 (defun vhdl-start-translate-off (limit)
13131 "Return point before translate-off pragma if before LIMIT, else nil."
13132 (when (re-search-forward
13133 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
13134 (match-beginning 0)))
13136 (defun vhdl-end-translate-off (limit)
13137 "Return point after translate-on pragma if before LIMIT, else nil."
13138 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
13140 (defun vhdl-match-translate-off (limit)
13141 "Match a translate-off block, setting match-data and returning t, else nil."
13142 (when (< (point) limit)
13143 (let ((start (or (vhdl-within-translate-off)
13144 (vhdl-start-translate-off limit)))
13145 (case-fold-search t))
13146 (when start
13147 (let ((end (or (vhdl-end-translate-off limit) limit)))
13148 (set-match-data (list start end))
13149 (goto-char end))))))
13151 (defun vhdl-font-lock-match-item (limit)
13152 "Match, and move over, any declaration item after point. Adapted from
13153 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13154 (condition-case nil
13155 (save-restriction
13156 (narrow-to-region (point-min) limit)
13157 ;; match item
13158 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13159 (save-match-data
13160 (goto-char (match-end 1))
13161 ;; move to next item
13162 (if (looking-at "\\(\\s-*,\\)")
13163 (goto-char (match-end 1))
13164 (end-of-line) t))))
13165 (error t)))
13167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13168 ;; Syntax definitions
13170 (defconst vhdl-font-lock-syntactic-keywords
13171 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
13172 "Mark single quotes as having string quote syntax in 'c' instances.")
13174 (defvar vhdl-font-lock-keywords nil
13175 "Regular expressions to highlight in VHDL Mode.")
13177 (defvar vhdl-font-lock-keywords-0
13178 ;; set in `vhdl-font-lock-init' because dependent on user options
13179 "For consideration as a value of `vhdl-font-lock-keywords'.
13180 This does highlighting of template prompts and directives (pragmas).")
13182 (defvar vhdl-font-lock-keywords-1 nil
13183 ;; set in `vhdl-font-lock-init' because dependent on user options
13184 "For consideration as a value of `vhdl-font-lock-keywords'.
13185 This does highlighting of keywords and standard identifiers.")
13187 (defconst vhdl-font-lock-keywords-2
13188 (list
13189 ;; highlight names of units, subprograms, and components when declared
13190 (list
13191 (concat
13192 "^\\s-*\\("
13193 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
13194 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13195 "\\)\\s-+\\(\\w+\\)")
13196 5 'font-lock-function-name-face)
13198 ;; highlight entity names of architectures and configurations
13199 (list
13200 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13201 2 'font-lock-function-name-face)
13203 ;; highlight labels of common constructs
13204 (list
13205 (concat
13206 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13207 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13208 "postponed\\|process\\|"
13209 (when (vhdl-standard-p 'ams) "procedural\\|")
13210 "with\\|while"
13211 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13212 1 'font-lock-function-name-face)
13214 ;; highlight label and component name of component instantiations
13215 (list
13216 (concat
13217 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13218 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13219 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13221 ;; highlight label and instantiated unit of component instantiations
13222 (list
13223 (concat
13224 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13225 "\\(component\\|configuration\\|entity\\)\\s-+"
13226 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13227 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13228 '(5 font-lock-function-name-face nil t)
13229 '(7 font-lock-function-name-face nil t))
13231 ;; highlight names and labels at end of constructs
13232 (list
13233 (concat
13234 "^\\s-*end\\s-+\\(\\("
13235 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
13236 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
13237 "procedure\\|\\(postponed\\s-+\\)?process\\|"
13238 (when (vhdl-standard-p 'ams) "procedural\\|")
13239 "units"
13240 "\\)\\s-+\\)?\\(\\w*\\)")
13241 5 'font-lock-function-name-face)
13243 ;; highlight labels in exit and next statements
13244 (list
13245 (concat
13246 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13247 3 'font-lock-function-name-face)
13249 ;; highlight entity name in attribute specifications
13250 (list
13251 (concat
13252 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13253 1 'font-lock-function-name-face)
13255 ;; highlight labels in block and component specifications
13256 (list
13257 (concat
13258 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13259 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13260 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13262 ;; highlight names in library clauses
13263 (list "^\\s-*library\\>"
13264 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13266 ;; highlight names in use clauses
13267 (list
13268 (concat
13269 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13270 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13271 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
13272 '(7 font-lock-function-name-face nil t))
13274 ;; highlight attribute name in attribute declarations/specifications
13275 (list
13276 (concat
13277 "^\\s-*attribute\\s-+\\(\\w+\\)")
13278 1 'vhdl-font-lock-attribute-face)
13280 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13281 (list
13282 (concat
13283 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13284 5 'font-lock-type-face)
13286 ;; highlight signal/variable/constant declaration names
13287 (list "\\(:[^=]\\)"
13288 '(vhdl-font-lock-match-item
13289 (progn (goto-char (match-beginning 1))
13290 (skip-syntax-backward " ")
13291 (skip-syntax-backward "w_")
13292 (skip-syntax-backward " ")
13293 (while (= (preceding-char) ?,)
13294 (backward-char 1)
13295 (skip-syntax-backward " ")
13296 (skip-syntax-backward "w_")
13297 (skip-syntax-backward " ")))
13298 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13300 ;; highlight formal parameters in component instantiations and subprogram
13301 ;; calls
13302 (list "\\(=>\\)"
13303 '(vhdl-font-lock-match-item
13304 (progn (goto-char (match-beginning 1))
13305 (skip-syntax-backward " ")
13306 (while (= (preceding-char) ?\)) (backward-sexp))
13307 (skip-syntax-backward "w_")
13308 (skip-syntax-backward " ")
13309 (when (memq (preceding-char) '(?n ?N ?|))
13310 (goto-char (point-max))))
13311 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13313 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13314 ;; variables
13315 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13316 '(vhdl-font-lock-match-item
13317 (progn (goto-char (match-end 1)) (match-beginning 2))
13318 nil (1 font-lock-variable-name-face)))
13320 "For consideration as a value of `vhdl-font-lock-keywords'.
13321 This does context sensitive highlighting of names and labels.")
13323 (defvar vhdl-font-lock-keywords-3 nil
13324 ;; set in `vhdl-font-lock-init' because dependent on user options
13325 "For consideration as a value of `vhdl-font-lock-keywords'.
13326 This does highlighting of words with special syntax.")
13328 (defvar vhdl-font-lock-keywords-4 nil
13329 ;; set in `vhdl-font-lock-init' because dependent on user options
13330 "For consideration as a value of `vhdl-font-lock-keywords'.
13331 This does highlighting of additional reserved words.")
13333 (defconst vhdl-font-lock-keywords-5
13334 ;; background highlight translate-off regions
13335 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13336 "For consideration as a value of `vhdl-font-lock-keywords'.
13337 This does background highlighting of translate-off regions.")
13339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13340 ;; Font and color definitions
13342 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13343 "Face name to use for prompts.")
13345 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13346 "Face name to use for standardized attributes.")
13348 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13349 "Face name to use for standardized enumeration values.")
13351 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13352 "Face name to use for standardized functions and packages.")
13354 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13355 "Face name to use for directives.")
13357 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13358 "Face name to use for additional reserved words.")
13360 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13361 "Face name to use for translate-off regions.")
13363 ;; face names to use for words with special syntax.
13364 (let ((syntax-alist vhdl-special-syntax-alist)
13365 name)
13366 (while syntax-alist
13367 (setq name (vhdl-function-name
13368 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13369 (eval `(defvar ,name ',name
13370 ,(concat "Face name to use for "
13371 (nth 0 (car syntax-alist)) ".")))
13372 (setq syntax-alist (cdr syntax-alist))))
13374 (defgroup vhdl-highlight-faces nil
13375 "Faces for highlighting."
13376 :group 'vhdl-highlight)
13378 ;; add faces used from `font-lock'
13379 (custom-add-to-group
13380 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13381 (custom-add-to-group
13382 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13383 (custom-add-to-group
13384 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13385 (custom-add-to-group
13386 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13387 (custom-add-to-group
13388 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13389 (custom-add-to-group
13390 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13392 (defface vhdl-font-lock-prompt-face
13393 '((((min-colors 88) (class color) (background light))
13394 (:foreground "Red1" :bold t))
13395 (((class color) (background light)) (:foreground "Red" :bold t))
13396 (((class color) (background dark)) (:foreground "Pink" :bold t))
13397 (t (:inverse-video t)))
13398 "Font lock mode face used to highlight prompts."
13399 :group 'vhdl-highlight-faces)
13401 (defface vhdl-font-lock-attribute-face
13402 '((((class color) (background light)) (:foreground "Orchid"))
13403 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13404 (t (:italic t :bold t)))
13405 "Font lock mode face used to highlight standardized attributes."
13406 :group 'vhdl-highlight-faces)
13408 (defface vhdl-font-lock-enumvalue-face
13409 '((((class color) (background light)) (:foreground "SaddleBrown"))
13410 (((class color) (background dark)) (:foreground "BurlyWood"))
13411 (t (:italic t :bold t)))
13412 "Font lock mode face used to highlight standardized enumeration values."
13413 :group 'vhdl-highlight-faces)
13415 (defface vhdl-font-lock-function-face
13416 '((((class color) (background light)) (:foreground "Cyan4"))
13417 (((class color) (background dark)) (:foreground "Orchid1"))
13418 (t (:italic t :bold t)))
13419 "Font lock mode face used to highlight standardized functions and packages."
13420 :group 'vhdl-highlight-faces)
13422 (defface vhdl-font-lock-directive-face
13423 '((((class color) (background light)) (:foreground "CadetBlue"))
13424 (((class color) (background dark)) (:foreground "Aquamarine"))
13425 (t (:italic t :bold t)))
13426 "Font lock mode face used to highlight directives."
13427 :group 'vhdl-highlight-faces)
13429 (defface vhdl-font-lock-reserved-words-face
13430 '((((class color) (background light)) (:foreground "Orange" :bold t))
13431 (((min-colors 88) (class color) (background dark))
13432 (:foreground "Yellow1" :bold t))
13433 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13434 (t ()))
13435 "Font lock mode face used to highlight additional reserved words."
13436 :group 'vhdl-highlight-faces)
13438 (defface vhdl-font-lock-translate-off-face
13439 '((((class color) (background light)) (:background "LightGray"))
13440 (((class color) (background dark)) (:background "DimGray"))
13441 (t ()))
13442 "Font lock mode face used to background highlight translate-off regions."
13443 :group 'vhdl-highlight-faces)
13445 ;; font lock mode faces used to highlight words with special syntax.
13446 (let ((syntax-alist vhdl-special-syntax-alist))
13447 (while syntax-alist
13448 (eval `(defface ,(vhdl-function-name
13449 "vhdl-font-lock" (caar syntax-alist) "face")
13450 '((((class color) (background light))
13451 (:foreground ,(nth 2 (car syntax-alist))))
13452 (((class color) (background dark))
13453 (:foreground ,(nth 3 (car syntax-alist))))
13454 (t ()))
13455 ,(concat "Font lock mode face used to highlight "
13456 (nth 0 (car syntax-alist)) ".")
13457 :group 'vhdl-highlight-faces))
13458 (setq syntax-alist (cdr syntax-alist))))
13460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13461 ;; Font lock initialization
13463 (defun vhdl-font-lock-init ()
13464 "Initialize fontification."
13465 ;; highlight template prompts and directives
13466 (setq vhdl-font-lock-keywords-0
13467 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13468 vhdl-template-prompt-syntax ">\\)")
13469 2 'vhdl-font-lock-prompt-face t)
13470 (list (concat "--\\s-*"
13471 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13472 2 'vhdl-font-lock-directive-face t)
13473 ;; highlight c-preprocessor directives
13474 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13475 '(1 font-lock-builtin-face)
13476 '(3 font-lock-variable-name-face nil t))))
13477 ;; highlight keywords and standardized types, attributes, enumeration
13478 ;; values, and subprograms
13479 (setq vhdl-font-lock-keywords-1
13480 (list
13481 (list (concat "'" vhdl-attributes-regexp)
13482 1 'vhdl-font-lock-attribute-face)
13483 (list vhdl-types-regexp 1 'font-lock-type-face)
13484 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13485 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13486 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13487 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13488 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13489 ;; highlight words with special syntax.
13490 (setq vhdl-font-lock-keywords-3
13491 (let ((syntax-alist vhdl-special-syntax-alist)
13492 keywords)
13493 (while syntax-alist
13494 (setq keywords
13495 (cons
13496 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13497 (vhdl-function-name
13498 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13499 (nth 4 (car syntax-alist)))
13500 keywords))
13501 (setq syntax-alist (cdr syntax-alist)))
13502 keywords))
13503 ;; highlight additional reserved words
13504 (setq vhdl-font-lock-keywords-4
13505 (list (list vhdl-reserved-words-regexp 1
13506 'vhdl-font-lock-reserved-words-face)))
13507 ;; highlight everything together
13508 (setq vhdl-font-lock-keywords
13509 (append
13510 vhdl-font-lock-keywords-0
13511 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13512 (when (or vhdl-highlight-forbidden-words
13513 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13514 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13515 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13516 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13518 ;; initialize fontification for VHDL Mode
13519 (vhdl-font-lock-init)
13521 (defun vhdl-fontify-buffer ()
13522 "Re-initialize fontification and fontify buffer."
13523 (interactive)
13524 (setq font-lock-defaults
13525 `(vhdl-font-lock-keywords
13526 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13527 beginning-of-line))
13528 (when (fboundp 'font-lock-unset-defaults)
13529 (font-lock-unset-defaults)) ; not implemented in XEmacs
13530 (font-lock-set-defaults)
13531 (font-lock-mode nil)
13532 (font-lock-mode t))
13534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13535 ;; Initialization for PostScript printing
13537 (defun vhdl-ps-print-settings ()
13538 "Initialize custom face and page settings for PostScript printing."
13539 ;; define custom face settings
13540 (unless (or (not vhdl-print-customize-faces)
13541 ps-print-color-p)
13542 (set (make-local-variable 'ps-bold-faces)
13543 '(font-lock-keyword-face
13544 font-lock-type-face
13545 vhdl-font-lock-attribute-face
13546 vhdl-font-lock-enumvalue-face
13547 vhdl-font-lock-directive-face))
13548 (set (make-local-variable 'ps-italic-faces)
13549 '(font-lock-comment-face
13550 font-lock-function-name-face
13551 font-lock-type-face
13552 vhdl-font-lock-attribute-face
13553 vhdl-font-lock-enumvalue-face
13554 vhdl-font-lock-directive-face))
13555 (set (make-local-variable 'ps-underlined-faces)
13556 '(font-lock-string-face))
13557 (setq ps-always-build-face-reference t))
13558 ;; define page settings, so that a line containing 79 characters (default)
13559 ;; fits into one column
13560 (when vhdl-print-two-column
13561 (set (make-local-variable 'ps-landscape-mode) t)
13562 (set (make-local-variable 'ps-number-of-columns) 2)
13563 (set (make-local-variable 'ps-font-size) 7.0)
13564 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13565 (set (make-local-variable 'ps-header-font-size) 9.0)
13566 (set (make-local-variable 'ps-header-offset) 12.0)
13567 (when (eq ps-paper-type 'letter)
13568 (set (make-local-variable 'ps-inter-column) 40.0)
13569 (set (make-local-variable 'ps-left-margin) 40.0)
13570 (set (make-local-variable 'ps-right-margin) 40.0))))
13572 (defun vhdl-ps-print-init ()
13573 "Initialize PostScript printing."
13574 (if (featurep 'xemacs)
13575 (when (boundp 'ps-print-color-p)
13576 (vhdl-ps-print-settings))
13577 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13578 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13581 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13582 ;;; Hierarchy browser (using `speedbar.el')
13583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13584 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13585 ;; directory by using the speedbar.
13587 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13588 ;; Variables
13590 (defvar vhdl-entity-alist nil
13591 "Cache with entities and corresponding architectures for each
13592 project/directory.")
13593 ;; structure: (parenthesized expression means list of such entries)
13594 ;; (cache-key
13595 ;; (ent-key ent-name ent-file ent-line
13596 ;; (arch-key arch-name arch-file arch-line
13597 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13598 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13599 ;; (lib-name pack-key))
13600 ;; mra-key (lib-name pack-key))
13602 (defvar vhdl-config-alist nil
13603 "Cache with configurations for each project/directory.")
13604 ;; structure: (parenthesized expression means list of such entries)
13605 ;; (cache-key
13606 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13607 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13608 ;; inst-conf-key inst-lib-key)
13609 ;; (lib-name pack-key)))
13611 (defvar vhdl-package-alist nil
13612 "Cache with packages for each project/directory.")
13613 ;; structure: (parenthesized expression means list of such entries)
13614 ;; (cache-key
13615 ;; (pack-key pack-name pack-file pack-line
13616 ;; (comp-key comp-name comp-file comp-line)
13617 ;; (func-key func-name func-file func-line)
13618 ;; (lib-name pack-key)
13619 ;; pack-body-file pack-body-line
13620 ;; (func-key func-name func-body-file func-body-line)
13621 ;; (lib-name pack-key)))
13623 (defvar vhdl-ent-inst-alist nil
13624 "Cache with instantiated entities for each project/directory.")
13625 ;; structure: (parenthesized expression means list of such entries)
13626 ;; (cache-key (inst-ent-key))
13628 (defvar vhdl-file-alist nil
13629 "Cache with design units in each file for each project/directory.")
13630 ;; structure: (parenthesized expression means list of such entries)
13631 ;; (cache-key
13632 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13633 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13635 (defvar vhdl-directory-alist nil
13636 "Cache with source directories for each project.")
13637 ;; structure: (parenthesized expression means list of such entries)
13638 ;; (cache-key (directory))
13640 (defvar vhdl-speedbar-shown-unit-alist nil
13641 "Alist of design units simultaneously open in the current speedbar for each
13642 directory and project.")
13644 (defvar vhdl-speedbar-shown-project-list nil
13645 "List of projects simultaneously open in the current speedbar.")
13647 (defvar vhdl-updated-project-list nil
13648 "List of projects and directories with updated files.")
13650 (defvar vhdl-modified-file-list nil
13651 "List of modified files to be rescanned for hierarchy updating.")
13653 (defvar vhdl-speedbar-hierarchy-depth 0
13654 "Depth of instantiation hierarchy to display.")
13656 (defvar vhdl-speedbar-show-projects nil
13657 "Non-nil means project hierarchy is displayed in speedbar, directory
13658 hierarchy otherwise.")
13660 (defun vhdl-get-end-of-unit ()
13661 "Return position of end of current unit."
13662 (let ((pos (point)))
13663 (save-excursion
13664 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13665 (save-excursion
13666 (goto-char (match-beginning 0))
13667 (vhdl-backward-syntactic-ws)
13668 (and (/= (preceding-char) ?\;) (not (bobp))))))
13669 (re-search-backward "^[ \t]*end\\>" pos 1)
13670 (point))))
13672 (defun vhdl-match-string-downcase (num &optional string)
13673 "Like `match-string-no-properties' with down-casing."
13674 (let ((match (match-string-no-properties num string)))
13675 (and match (downcase match))))
13678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13679 ;; Scan functions
13681 (defun vhdl-scan-context-clause ()
13682 "Scan the context clause that precedes a design unit."
13683 (let (lib-alist)
13684 (save-excursion
13685 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13686 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13687 (equal "USE" (upcase (match-string 1))))
13688 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13689 (push (cons (match-string-no-properties 1)
13690 (vhdl-match-string-downcase 2))
13691 lib-alist)))))
13692 lib-alist))
13694 (defun vhdl-scan-directory-contents (name &optional project update num-string
13695 non-final)
13696 "Scan contents of VHDL files in directory or file pattern NAME."
13697 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13698 (let* ((dir-name (match-string 1 name))
13699 (file-pattern (match-string 2 name))
13700 (is-directory (= 0 (length file-pattern)))
13701 (file-list
13702 (if update
13703 (list name)
13704 (if is-directory
13705 (vhdl-get-source-files t dir-name)
13706 (vhdl-directory-files
13707 dir-name t (wildcard-to-regexp file-pattern)))))
13708 (key (or project dir-name))
13709 (file-exclude-regexp
13710 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
13711 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13712 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13713 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13714 ent-alist conf-alist pack-alist ent-inst-list file-alist
13715 tmp-list tmp-entry no-files files-exist big-files)
13716 (when (or project update)
13717 (setq ent-alist (vhdl-aget vhdl-entity-alist key)
13718 conf-alist (vhdl-aget vhdl-config-alist key)
13719 pack-alist (vhdl-aget vhdl-package-alist key)
13720 ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist key))
13721 file-alist (vhdl-aget vhdl-file-alist key)))
13722 (when (and (not is-directory) (null file-list))
13723 (message "No such file: \"%s\"" name))
13724 (setq files-exist file-list)
13725 (when file-list
13726 (setq no-files (length file-list))
13727 (message "Scanning %s %s\"%s\"..."
13728 (if is-directory "directory" "files") (or num-string "") name)
13729 ;; exclude files
13730 (unless (equal file-exclude-regexp "")
13731 (let ((case-fold-search nil)
13732 file-tmp-list)
13733 (while file-list
13734 (unless (string-match file-exclude-regexp (car file-list))
13735 (push (car file-list) file-tmp-list))
13736 (setq file-list (cdr file-list)))
13737 (setq file-list (nreverse file-tmp-list))))
13738 ;; do for all files
13739 (while file-list
13740 (unless noninteractive
13741 (message "Scanning %s %s\"%s\"... (%2d%s)"
13742 (if is-directory "directory" "files")
13743 (or num-string "") name
13744 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13745 (let ((file-name (abbreviate-file-name (car file-list)))
13746 ent-list arch-list arch-ent-list conf-list
13747 pack-list pack-body-list inst-list inst-ent-list)
13748 ;; scan file
13749 (vhdl-visit-file
13750 file-name nil
13751 (vhdl-prepare-search-2
13752 (save-excursion
13753 ;; scan for design units
13754 (if (and limit-design-file-size
13755 (< limit-design-file-size (buffer-size)))
13756 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13757 (setq big-files t))
13758 ;; scan for entities
13759 (goto-char (point-min))
13760 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13761 (let* ((ent-name (match-string-no-properties 1))
13762 (ent-key (downcase ent-name))
13763 (ent-entry (vhdl-aget ent-alist ent-key))
13764 (lib-alist (vhdl-scan-context-clause)))
13765 (if (nth 1 ent-entry)
13766 (vhdl-warning-when-idle
13767 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13768 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13769 file-name (vhdl-current-line))
13770 (push ent-key ent-list)
13771 (vhdl-aput 'ent-alist ent-key
13772 (list ent-name file-name (vhdl-current-line)
13773 (nth 3 ent-entry) (nth 4 ent-entry)
13774 lib-alist)))))
13775 ;; scan for architectures
13776 (goto-char (point-min))
13777 (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)
13778 (let* ((arch-name (match-string-no-properties 1))
13779 (arch-key (downcase arch-name))
13780 (ent-name (match-string-no-properties 2))
13781 (ent-key (downcase ent-name))
13782 (ent-entry (vhdl-aget ent-alist ent-key))
13783 (arch-alist (nth 3 ent-entry))
13784 (arch-entry (vhdl-aget arch-alist arch-key))
13785 (lib-arch-alist (vhdl-scan-context-clause)))
13786 (if arch-entry
13787 (vhdl-warning-when-idle
13788 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13789 arch-name ent-name (nth 1 arch-entry)
13790 (nth 2 arch-entry) file-name (vhdl-current-line))
13791 (setq arch-list (cons arch-key arch-list)
13792 arch-ent-list (cons ent-key arch-ent-list))
13793 (vhdl-aput 'arch-alist arch-key
13794 (list arch-name file-name (vhdl-current-line)
13795 nil lib-arch-alist))
13796 (vhdl-aput 'ent-alist ent-key
13797 (list (or (nth 0 ent-entry) ent-name)
13798 (nth 1 ent-entry) (nth 2 ent-entry)
13799 (vhdl-sort-alist arch-alist)
13800 arch-key (nth 5 ent-entry))))))
13801 ;; scan for configurations
13802 (goto-char (point-min))
13803 (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)
13804 (let* ((conf-name (match-string-no-properties 1))
13805 (conf-key (downcase conf-name))
13806 (conf-entry (vhdl-aget conf-alist conf-key))
13807 (ent-name (match-string-no-properties 2))
13808 (ent-key (downcase ent-name))
13809 (lib-alist (vhdl-scan-context-clause))
13810 (conf-line (vhdl-current-line))
13811 (end-of-unit (vhdl-get-end-of-unit))
13812 arch-key comp-conf-list inst-key-list
13813 inst-comp-key inst-ent-key inst-arch-key
13814 inst-conf-key inst-lib-key)
13815 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13816 (setq arch-key (vhdl-match-string-downcase 1)))
13817 (if conf-entry
13818 (vhdl-warning-when-idle
13819 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13820 conf-name ent-name (nth 1 conf-entry)
13821 (nth 2 conf-entry) file-name conf-line)
13822 (push conf-key conf-list)
13823 ;; scan for subconfigurations and subentities
13824 (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)
13825 (setq inst-comp-key (vhdl-match-string-downcase 3)
13826 inst-key-list (split-string
13827 (vhdl-match-string-downcase 1)
13828 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13829 (vhdl-forward-syntactic-ws)
13830 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13831 (setq
13832 inst-lib-key (vhdl-match-string-downcase 3)
13833 inst-ent-key (and (match-string 2)
13834 (vhdl-match-string-downcase 4))
13835 inst-arch-key (and (match-string 2)
13836 (vhdl-match-string-downcase 6))
13837 inst-conf-key (and (not (match-string 2))
13838 (vhdl-match-string-downcase 4)))
13839 (while inst-key-list
13840 (setq comp-conf-list
13841 (cons (list (car inst-key-list)
13842 inst-comp-key inst-ent-key
13843 inst-arch-key inst-conf-key
13844 inst-lib-key)
13845 comp-conf-list))
13846 (setq inst-key-list (cdr inst-key-list)))))
13847 (vhdl-aput 'conf-alist conf-key
13848 (list conf-name file-name conf-line ent-key
13849 arch-key comp-conf-list lib-alist)))))
13850 ;; scan for packages
13851 (goto-char (point-min))
13852 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13853 (let* ((pack-name (match-string-no-properties 2))
13854 (pack-key (downcase pack-name))
13855 (is-body (match-string-no-properties 1))
13856 (pack-entry (vhdl-aget pack-alist pack-key))
13857 (pack-line (vhdl-current-line))
13858 (end-of-unit (vhdl-get-end-of-unit))
13859 comp-name func-name comp-alist func-alist lib-alist)
13860 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13861 (vhdl-warning-when-idle
13862 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13863 (if is-body " body" "") pack-name
13864 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13865 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13866 file-name (vhdl-current-line))
13867 ;; scan for context clauses
13868 (setq lib-alist (vhdl-scan-context-clause))
13869 ;; scan for component and subprogram declarations/bodies
13870 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13871 (if (equal (upcase (match-string 1)) "COMPONENT")
13872 (setq comp-name (match-string-no-properties 2)
13873 comp-alist
13874 (cons (list (downcase comp-name) comp-name
13875 file-name (vhdl-current-line))
13876 comp-alist))
13877 (setq func-name (match-string-no-properties 2)
13878 func-alist
13879 (cons (list (downcase func-name) func-name
13880 file-name (vhdl-current-line))
13881 func-alist))))
13882 (setq func-alist (nreverse func-alist))
13883 (setq comp-alist (nreverse comp-alist))
13884 (if is-body
13885 (push pack-key pack-body-list)
13886 (push pack-key pack-list))
13887 (vhdl-aput
13888 'pack-alist pack-key
13889 (if is-body
13890 (list (or (nth 0 pack-entry) pack-name)
13891 (nth 1 pack-entry) (nth 2 pack-entry)
13892 (nth 3 pack-entry) (nth 4 pack-entry)
13893 (nth 5 pack-entry)
13894 file-name pack-line func-alist lib-alist)
13895 (list pack-name file-name pack-line
13896 comp-alist func-alist lib-alist
13897 (nth 6 pack-entry) (nth 7 pack-entry)
13898 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13899 ;; scan for hierarchy
13900 (if (and limit-hier-file-size
13901 (< limit-hier-file-size (buffer-size)))
13902 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13903 (setq big-files t))
13904 ;; scan for architectures
13905 (goto-char (point-min))
13906 (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)
13907 (let* ((ent-name (match-string-no-properties 2))
13908 (ent-key (downcase ent-name))
13909 (arch-name (match-string-no-properties 1))
13910 (arch-key (downcase arch-name))
13911 (ent-entry (vhdl-aget ent-alist ent-key))
13912 (arch-alist (nth 3 ent-entry))
13913 (arch-entry (vhdl-aget arch-alist arch-key))
13914 (beg-of-unit (point))
13915 (end-of-unit (vhdl-get-end-of-unit))
13916 (inst-no 0)
13917 inst-alist inst-path)
13918 ;; scan for contained instantiations
13919 (while (and (re-search-forward
13920 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
13921 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
13922 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
13923 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
13924 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13925 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13926 (or (not limit-hier-inst-no)
13927 (<= (if (or (match-string 14)
13928 (match-string 16))
13929 inst-no
13930 (setq inst-no (1+ inst-no)))
13931 limit-hier-inst-no)))
13932 (cond
13933 ;; block/generate beginning found
13934 ((match-string 14)
13935 (setq inst-path
13936 (cons (match-string-no-properties 1) inst-path)))
13937 ;; block/generate end found
13938 ((match-string 16)
13939 (setq inst-path (cdr inst-path)))
13940 ;; instantiation found
13942 (let* ((inst-name (match-string-no-properties 1))
13943 (inst-key (downcase inst-name))
13944 (inst-comp-name
13945 (or (match-string-no-properties 3)
13946 (match-string-no-properties 6)))
13947 (inst-ent-key
13948 (or (and (match-string 8)
13949 (vhdl-match-string-downcase 11))
13950 (and inst-comp-name
13951 (downcase inst-comp-name))))
13952 (inst-arch-key (vhdl-match-string-downcase 13))
13953 (inst-conf-key
13954 (and (not (match-string 8))
13955 (vhdl-match-string-downcase 11)))
13956 (inst-lib-key (vhdl-match-string-downcase 10)))
13957 (goto-char (match-end 1))
13958 (setq inst-list (cons inst-key inst-list)
13959 inst-ent-list
13960 (cons inst-ent-key inst-ent-list))
13961 (setq inst-alist
13962 (append
13963 inst-alist
13964 (list (list inst-key inst-name file-name
13965 (vhdl-current-line) inst-comp-name
13966 inst-ent-key inst-arch-key
13967 inst-conf-key inst-lib-key
13968 (reverse inst-path)))))))))
13969 ;; scan for contained configuration specifications
13970 (goto-char beg-of-unit)
13971 (while (re-search-forward
13972 (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]*\\)*"
13973 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
13974 (let* ((inst-comp-name (match-string-no-properties 3))
13975 (inst-ent-key
13976 (and (match-string 6)
13977 (vhdl-match-string-downcase 9)))
13978 (inst-arch-key (vhdl-match-string-downcase 11))
13979 (inst-conf-key
13980 (and (not (match-string 6))
13981 (vhdl-match-string-downcase 9)))
13982 (inst-lib-key (vhdl-match-string-downcase 8))
13983 (inst-key-list
13984 (split-string (vhdl-match-string-downcase 1)
13985 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13986 (tmp-inst-alist inst-alist)
13987 inst-entry)
13988 (while tmp-inst-alist
13989 (when (and (or (equal "all" (car inst-key-list))
13990 (member (nth 0 (car tmp-inst-alist))
13991 inst-key-list))
13992 (equal
13993 (downcase
13994 (or (nth 4 (car tmp-inst-alist)) ""))
13995 (downcase inst-comp-name)))
13996 (setq inst-entry (car tmp-inst-alist))
13997 (setq inst-ent-list
13998 (cons (or inst-ent-key (nth 5 inst-entry))
13999 (vhdl-delete
14000 (nth 5 inst-entry) inst-ent-list)))
14001 (setq inst-entry
14002 (list (nth 0 inst-entry) (nth 1 inst-entry)
14003 (nth 2 inst-entry) (nth 3 inst-entry)
14004 (nth 4 inst-entry)
14005 (or inst-ent-key (nth 5 inst-entry))
14006 (or inst-arch-key (nth 6 inst-entry))
14007 inst-conf-key inst-lib-key))
14008 (setcar tmp-inst-alist inst-entry))
14009 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
14010 ;; save in cache
14011 (vhdl-aput 'arch-alist arch-key
14012 (list (nth 0 arch-entry) (nth 1 arch-entry)
14013 (nth 2 arch-entry) inst-alist
14014 (nth 4 arch-entry)))
14015 (vhdl-aput 'ent-alist ent-key
14016 (list (nth 0 ent-entry) (nth 1 ent-entry)
14017 (nth 2 ent-entry)
14018 (vhdl-sort-alist arch-alist)
14019 (nth 4 ent-entry) (nth 5 ent-entry)))
14020 (when (and limit-hier-inst-no
14021 (> inst-no limit-hier-inst-no))
14022 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
14023 (setq big-files t))
14024 (goto-char end-of-unit))))
14025 ;; remember design units for this file
14026 (vhdl-aput 'file-alist file-name
14027 (list ent-list arch-list arch-ent-list conf-list
14028 pack-list pack-body-list
14029 inst-list inst-ent-list))
14030 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
14031 (setq file-list (cdr file-list))))
14032 (when (or (and (not project) files-exist)
14033 (and project (not non-final)))
14034 ;; consistency checks:
14035 ;; check whether each architecture has a corresponding entity
14036 (setq tmp-list ent-alist)
14037 (while tmp-list
14038 (when (null (nth 2 (car tmp-list)))
14039 (setq tmp-entry (car (nth 4 (car tmp-list))))
14040 (vhdl-warning-when-idle
14041 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14042 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
14043 (nth 3 tmp-entry)))
14044 (setq tmp-list (cdr tmp-list)))
14045 ;; check whether configuration has a corresponding entity/architecture
14046 (setq tmp-list conf-alist)
14047 (while tmp-list
14048 (if (setq tmp-entry (vhdl-aget ent-alist (nth 4 (car tmp-list))))
14049 (unless (vhdl-aget (nth 3 tmp-entry) (nth 5 (car tmp-list)))
14050 (setq tmp-entry (car tmp-list))
14051 (vhdl-warning-when-idle
14052 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14053 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
14054 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14055 (setq tmp-entry (car tmp-list))
14056 (vhdl-warning-when-idle
14057 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14058 (nth 1 tmp-entry) (nth 4 tmp-entry)
14059 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14060 (setq tmp-list (cdr tmp-list)))
14061 ;; check whether each package body has a package declaration
14062 (setq tmp-list pack-alist)
14063 (while tmp-list
14064 (when (null (nth 2 (car tmp-list)))
14065 (setq tmp-entry (car tmp-list))
14066 (vhdl-warning-when-idle
14067 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14068 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
14069 (setq tmp-list (cdr tmp-list)))
14070 ;; sort lists
14071 (setq ent-alist (vhdl-sort-alist ent-alist))
14072 (setq conf-alist (vhdl-sort-alist conf-alist))
14073 (setq pack-alist (vhdl-sort-alist pack-alist))
14074 ;; remember updated directory/project
14075 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
14076 ;; clear directory alists
14077 (unless project
14078 (vhdl-adelete 'vhdl-entity-alist key)
14079 (vhdl-adelete 'vhdl-config-alist key)
14080 (vhdl-adelete 'vhdl-package-alist key)
14081 (vhdl-adelete 'vhdl-ent-inst-alist key)
14082 (vhdl-adelete 'vhdl-file-alist key))
14083 ;; put directory contents into cache
14084 (vhdl-aput 'vhdl-entity-alist key ent-alist)
14085 (vhdl-aput 'vhdl-config-alist key conf-alist)
14086 (vhdl-aput 'vhdl-package-alist key pack-alist)
14087 (vhdl-aput 'vhdl-ent-inst-alist key (list ent-inst-list))
14088 (vhdl-aput 'vhdl-file-alist key file-alist)
14089 ;; final messages
14090 (message "Scanning %s %s\"%s\"...done"
14091 (if is-directory "directory" "files") (or num-string "") name)
14092 (unless project (message "Scanning directory...done"))
14093 (when big-files
14094 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14095 ;; save cache when scanned non-interactively
14096 (when (or (not project) (not non-final))
14097 (when (and noninteractive vhdl-speedbar-save-cache)
14098 (vhdl-save-cache key)))
14101 (defun vhdl-scan-project-contents (project)
14102 "Scan the contents of all VHDL files found in the directories and files
14103 of PROJECT."
14104 (let ((dir-list (or (nth 2 (vhdl-aget vhdl-project-alist project)) '("")))
14105 (default-dir (vhdl-resolve-env-variable
14106 (nth 1 (vhdl-aget vhdl-project-alist project))))
14107 (file-exclude-regexp
14108 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
14109 dir-list-tmp dir dir-name num-dir act-dir recursive)
14110 ;; clear project alists
14111 (vhdl-adelete 'vhdl-entity-alist project)
14112 (vhdl-adelete 'vhdl-config-alist project)
14113 (vhdl-adelete 'vhdl-package-alist project)
14114 (vhdl-adelete 'vhdl-ent-inst-alist project)
14115 (vhdl-adelete 'vhdl-file-alist project)
14116 ;; expand directory names by default-directory
14117 (message "Collecting source files...")
14118 (while dir-list
14119 (setq dir (vhdl-resolve-env-variable (car dir-list)))
14120 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
14121 (setq recursive (match-string 1 dir)
14122 dir-name (match-string 3 dir))
14123 (setq dir-list-tmp
14124 (cons (concat recursive
14125 (if (file-name-absolute-p dir-name) "" default-dir)
14126 dir-name)
14127 dir-list-tmp))
14128 (setq dir-list (cdr dir-list)))
14129 ;; resolve path wildcards
14130 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
14131 ;; expand directories
14132 (while dir-list-tmp
14133 (setq dir (car dir-list-tmp))
14134 ;; get subdirectories
14135 (if (string-match "-r \\(.*[/\\]\\)" dir)
14136 (setq dir-list (append dir-list (vhdl-get-subdirs
14137 (match-string 1 dir))))
14138 (setq dir-list (append dir-list (list dir))))
14139 (setq dir-list-tmp (cdr dir-list-tmp)))
14140 ;; exclude files
14141 (unless (equal file-exclude-regexp "")
14142 (let ((case-fold-search nil))
14143 (while dir-list
14144 (unless (string-match file-exclude-regexp (car dir-list))
14145 (push (car dir-list) dir-list-tmp))
14146 (setq dir-list (cdr dir-list)))
14147 (setq dir-list (nreverse dir-list-tmp))))
14148 (message "Collecting source files...done")
14149 ;; scan for design units for each directory in DIR-LIST
14150 (setq dir-list-tmp nil
14151 num-dir (length dir-list)
14152 act-dir 1)
14153 (while dir-list
14154 (setq dir-name (abbreviate-file-name
14155 (expand-file-name (car dir-list))))
14156 (vhdl-scan-directory-contents dir-name project nil
14157 (format "(%s/%s) " act-dir num-dir)
14158 (cdr dir-list))
14159 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
14160 (setq dir-list (cdr dir-list)
14161 act-dir (1+ act-dir)))
14162 (vhdl-aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
14163 (message "Scanning project \"%s\"...done" project)))
14165 (defun vhdl-update-file-contents (file-name)
14166 "Update hierarchy information by contents of current buffer."
14167 (setq file-name (abbreviate-file-name file-name))
14168 (let* ((dir-name (file-name-directory file-name))
14169 (directory-alist vhdl-directory-alist)
14170 updated)
14171 (while directory-alist
14172 (when (member dir-name (nth 1 (car directory-alist)))
14173 (let* ((vhdl-project (nth 0 (car directory-alist)))
14174 (project (vhdl-project-p))
14175 (ent-alist (vhdl-aget vhdl-entity-alist
14176 (or project dir-name)))
14177 (conf-alist (vhdl-aget vhdl-config-alist
14178 (or project dir-name)))
14179 (pack-alist (vhdl-aget vhdl-package-alist
14180 (or project dir-name)))
14181 (ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist
14182 (or project dir-name))))
14183 (file-alist (vhdl-aget vhdl-file-alist (or project dir-name)))
14184 (file-entry (vhdl-aget file-alist file-name))
14185 (ent-list (nth 0 file-entry))
14186 (arch-list (nth 1 file-entry))
14187 (arch-ent-list (nth 2 file-entry))
14188 (conf-list (nth 3 file-entry))
14189 (pack-list (nth 4 file-entry))
14190 (pack-body-list (nth 5 file-entry))
14191 (inst-ent-list (nth 7 file-entry))
14192 (cache-key (or project dir-name))
14193 arch-alist key ent-key entry)
14194 ;; delete design units previously contained in this file:
14195 ;; entities
14196 (while ent-list
14197 (setq key (car ent-list)
14198 entry (vhdl-aget ent-alist key))
14199 (when (equal file-name (nth 1 entry))
14200 (if (nth 3 entry)
14201 (vhdl-aput 'ent-alist key
14202 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14203 (vhdl-adelete 'ent-alist key)))
14204 (setq ent-list (cdr ent-list)))
14205 ;; architectures
14206 (while arch-list
14207 (setq key (car arch-list)
14208 ent-key (car arch-ent-list)
14209 entry (vhdl-aget ent-alist ent-key)
14210 arch-alist (nth 3 entry))
14211 (when (equal file-name (nth 1 (vhdl-aget arch-alist key)))
14212 (vhdl-adelete 'arch-alist key)
14213 (if (or (nth 1 entry) arch-alist)
14214 (vhdl-aput 'ent-alist ent-key
14215 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14216 arch-alist (nth 4 entry) (nth 5 entry)))
14217 (vhdl-adelete 'ent-alist ent-key)))
14218 (setq arch-list (cdr arch-list)
14219 arch-ent-list (cdr arch-ent-list)))
14220 ;; configurations
14221 (while conf-list
14222 (setq key (car conf-list))
14223 (when (equal file-name (nth 1 (vhdl-aget conf-alist key)))
14224 (vhdl-adelete 'conf-alist key))
14225 (setq conf-list (cdr conf-list)))
14226 ;; package declarations
14227 (while pack-list
14228 (setq key (car pack-list)
14229 entry (vhdl-aget pack-alist key))
14230 (when (equal file-name (nth 1 entry))
14231 (if (nth 6 entry)
14232 (vhdl-aput 'pack-alist key
14233 (list (nth 0 entry) nil nil nil nil nil
14234 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14235 (nth 9 entry)))
14236 (vhdl-adelete 'pack-alist key)))
14237 (setq pack-list (cdr pack-list)))
14238 ;; package bodies
14239 (while pack-body-list
14240 (setq key (car pack-body-list)
14241 entry (vhdl-aget pack-alist key))
14242 (when (equal file-name (nth 6 entry))
14243 (if (nth 1 entry)
14244 (vhdl-aput 'pack-alist key
14245 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14246 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14247 nil nil nil nil))
14248 (vhdl-adelete 'pack-alist key)))
14249 (setq pack-body-list (cdr pack-body-list)))
14250 ;; instantiated entities
14251 (while inst-ent-list
14252 (setq ent-inst-list
14253 (vhdl-delete (car inst-ent-list) ent-inst-list))
14254 (setq inst-ent-list (cdr inst-ent-list)))
14255 ;; update caches
14256 (vhdl-aput-delete-if-nil 'vhdl-entity-alist cache-key ent-alist)
14257 (vhdl-aput-delete-if-nil 'vhdl-config-alist cache-key conf-alist)
14258 (vhdl-aput-delete-if-nil 'vhdl-package-alist cache-key pack-alist)
14259 (vhdl-aput-delete-if-nil 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14260 ;; scan file
14261 (vhdl-scan-directory-contents file-name project t)
14262 (when (or (and vhdl-speedbar-show-projects project)
14263 (and (not vhdl-speedbar-show-projects) (not project)))
14264 (vhdl-speedbar-refresh project))
14265 (setq updated t)))
14266 (setq directory-alist (cdr directory-alist)))
14267 updated))
14269 (defun vhdl-update-hierarchy ()
14270 "Update directory and hierarchy information in speedbar."
14271 (let ((file-list (reverse vhdl-modified-file-list))
14272 updated)
14273 (when (and vhdl-speedbar-update-on-saving file-list)
14274 (while file-list
14275 (setq updated
14276 (or (vhdl-update-file-contents (car file-list))
14277 updated))
14278 (setq file-list (cdr file-list)))
14279 (setq vhdl-modified-file-list nil)
14280 (vhdl-speedbar-update-current-unit)
14281 (when updated (message "Updating hierarchy...done")))))
14283 ;; structure (parenthesized expression means list of such entries)
14284 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14285 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14286 ;; comp-lib-name level)
14287 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14288 conf-inst-alist level indent
14289 &optional include-top ent-hier)
14290 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14291 entity ENT-KEY."
14292 (let* ((ent-entry (vhdl-aget ent-alist ent-key))
14293 (arch-entry (if arch-key (vhdl-aget (nth 3 ent-entry) arch-key)
14294 (cdar (last (nth 3 ent-entry)))))
14295 (inst-alist (nth 3 arch-entry))
14296 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14297 hier-list subcomp-list tmp-list inst-key inst-comp-name
14298 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14299 (when (= level 0) (message "Extract design hierarchy..."))
14300 (when include-top
14301 (setq level (1+ level)))
14302 (when (member ent-key ent-hier)
14303 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14304 ;; process all instances
14305 (while inst-alist
14306 (setq inst-entry (car inst-alist)
14307 inst-key (nth 0 inst-entry)
14308 inst-comp-name (nth 4 inst-entry)
14309 inst-conf-key (nth 7 inst-entry))
14310 ;; search entry in configuration's instantiations list
14311 (setq tmp-list conf-inst-alist)
14312 (while (and tmp-list
14313 (not (and (member (nth 0 (car tmp-list))
14314 (list "all" inst-key))
14315 (equal (nth 1 (car tmp-list))
14316 (downcase (or inst-comp-name ""))))))
14317 (setq tmp-list (cdr tmp-list)))
14318 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14319 (setq inst-conf-entry (vhdl-aget conf-alist inst-conf-key))
14320 (when (and inst-conf-key (not inst-conf-entry))
14321 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14322 ;; determine entity
14323 (setq inst-ent-key
14324 (or (nth 2 (car tmp-list)) ; from configuration
14325 (nth 3 inst-conf-entry) ; from subconfiguration
14326 (nth 3 (vhdl-aget conf-alist (nth 7 inst-entry)))
14327 ; from configuration spec.
14328 (nth 5 inst-entry))) ; from direct instantiation
14329 (setq inst-ent-entry (vhdl-aget ent-alist inst-ent-key))
14330 ;; determine architecture
14331 (setq inst-arch-key
14332 (or (nth 3 (car tmp-list)) ; from configuration
14333 (nth 4 inst-conf-entry) ; from subconfiguration
14334 (nth 6 inst-entry) ; from direct instantiation
14335 (nth 4 (vhdl-aget conf-alist (nth 7 inst-entry)))
14336 ; from configuration spec.
14337 (nth 4 inst-ent-entry) ; MRA
14338 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14339 (setq inst-arch-entry (vhdl-aget (nth 3 inst-ent-entry) inst-arch-key))
14340 ;; set library
14341 (setq inst-lib-key
14342 (or (nth 5 (car tmp-list)) ; from configuration
14343 (nth 8 inst-entry))) ; from direct instantiation
14344 ;; gather information for this instance
14345 (setq comp-entry
14346 (list (nth 1 inst-entry)
14347 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14348 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14349 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14350 (or (nth 0 inst-arch-entry) inst-arch-key)
14351 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14352 (or (nth 0 inst-conf-entry) inst-conf-key)
14353 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14354 inst-lib-key level))
14355 ;; get subcomponent hierarchy
14356 (setq subcomp-list (vhdl-get-hierarchy
14357 ent-alist conf-alist
14358 inst-ent-key inst-arch-key inst-conf-key
14359 (nth 5 inst-conf-entry)
14360 (1+ level) indent nil (cons ent-key ent-hier)))
14361 ;; add to list
14362 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14363 (setq inst-alist (cdr inst-alist)))
14364 (when include-top
14365 (setq hier-list
14366 (cons (list nil nil (nth 0 ent-entry)
14367 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14368 (nth 0 arch-entry)
14369 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14370 nil nil
14371 nil (1- level))
14372 hier-list)))
14373 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14374 hier-list))
14376 (defun vhdl-get-instantiations (ent-key indent)
14377 "Get all instantiations of entity ENT-KEY."
14378 (let ((ent-alist (vhdl-aget vhdl-entity-alist
14379 (vhdl-speedbar-line-key indent)))
14380 arch-alist inst-alist ent-inst-list
14381 ent-entry arch-entry inst-entry)
14382 (while ent-alist
14383 (setq ent-entry (car ent-alist))
14384 (setq arch-alist (nth 4 ent-entry))
14385 (while arch-alist
14386 (setq arch-entry (car arch-alist))
14387 (setq inst-alist (nth 4 arch-entry))
14388 (while inst-alist
14389 (setq inst-entry (car inst-alist))
14390 (when (equal ent-key (nth 5 inst-entry))
14391 (setq ent-inst-list
14392 (cons (list (nth 1 inst-entry)
14393 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14394 (nth 1 ent-entry)
14395 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14396 (nth 1 arch-entry)
14397 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14398 ent-inst-list)))
14399 (setq inst-alist (cdr inst-alist)))
14400 (setq arch-alist (cdr arch-alist)))
14401 (setq ent-alist (cdr ent-alist)))
14402 (nreverse ent-inst-list)))
14404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14405 ;; Caching in file
14407 (defun vhdl-save-caches ()
14408 "Save all updated hierarchy caches to file."
14409 (interactive)
14410 (condition-case nil
14411 (when vhdl-speedbar-save-cache
14412 ;; update hierarchy
14413 (vhdl-update-hierarchy)
14414 (let ((project-list vhdl-updated-project-list))
14415 (message "Saving hierarchy caches...")
14416 ;; write updated project caches
14417 (while project-list
14418 (vhdl-save-cache (car project-list))
14419 (setq project-list (cdr project-list)))
14420 (message "Saving hierarchy caches...done")))
14421 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14422 (sit-for 2)))))
14424 (defun vhdl-save-cache (key)
14425 "Save current hierarchy cache to file."
14426 (let* ((orig-buffer (current-buffer))
14427 (vhdl-project key)
14428 (project (vhdl-project-p))
14429 (default-directory key)
14430 (directory (abbreviate-file-name (vhdl-default-directory)))
14431 (file-name (vhdl-resolve-env-variable
14432 (vhdl-replace-string
14433 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14434 (concat
14435 (subst-char-in-string ? ?_ (or project "dir"))
14436 " " (user-login-name)))))
14437 (file-dir-name (expand-file-name file-name directory))
14438 (cache-key (or project directory))
14439 (key (if project "project" "directory")))
14440 (unless (file-exists-p (file-name-directory file-dir-name))
14441 (make-directory (file-name-directory file-dir-name) t))
14442 (if (not (file-writable-p file-dir-name))
14443 (progn (vhdl-warning (format "File not writable: \"%s\""
14444 (abbreviate-file-name file-dir-name)))
14445 (sit-for 2))
14446 (message "Saving cache: \"%s\"" file-dir-name)
14447 (set-buffer (find-file-noselect file-dir-name t t))
14448 (erase-buffer)
14449 (insert ";; -*- Emacs-Lisp -*-\n\n"
14450 ";;; " (file-name-nondirectory file-name)
14451 " - design hierarchy cache file for Emacs VHDL Mode "
14452 vhdl-version "\n")
14453 (insert "\n;; " (if project "Project " "Directory") " : ")
14454 (if project (insert project) (prin1 directory (current-buffer)))
14455 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14456 (user-login-name) "\n\n"
14457 "\n;; version number\n"
14458 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14459 "\n;; " (if project "project" "directory") " name"
14460 "\n(setq " key " ")
14461 (prin1 (or project directory) (current-buffer))
14462 (insert ")\n")
14463 (when (member 'hierarchy vhdl-speedbar-save-cache)
14464 (insert "\n;; entity and architecture cache\n"
14465 "(vhdl-aput 'vhdl-entity-alist " key " '")
14466 (print (vhdl-aget vhdl-entity-alist cache-key) (current-buffer))
14467 (insert ")\n\n;; configuration cache\n"
14468 "(vhdl-aput 'vhdl-config-alist " key " '")
14469 (print (vhdl-aget vhdl-config-alist cache-key) (current-buffer))
14470 (insert ")\n\n;; package cache\n"
14471 "(vhdl-aput 'vhdl-package-alist " key " '")
14472 (print (vhdl-aget vhdl-package-alist cache-key) (current-buffer))
14473 (insert ")\n\n;; instantiated entities cache\n"
14474 "(vhdl-aput 'vhdl-ent-inst-alist " key " '")
14475 (print (vhdl-aget vhdl-ent-inst-alist cache-key) (current-buffer))
14476 (insert ")\n\n;; design units per file cache\n"
14477 "(vhdl-aput 'vhdl-file-alist " key " '")
14478 (print (vhdl-aget vhdl-file-alist cache-key) (current-buffer))
14479 (when project
14480 (insert ")\n\n;; source directories in project cache\n"
14481 "(vhdl-aput 'vhdl-directory-alist " key " '")
14482 (print (vhdl-aget vhdl-directory-alist cache-key) (current-buffer)))
14483 (insert ")\n"))
14484 (when (member 'display vhdl-speedbar-save-cache)
14485 (insert "\n;; shown design units cache\n"
14486 "(vhdl-aput 'vhdl-speedbar-shown-unit-alist " key " '")
14487 (print (vhdl-aget vhdl-speedbar-shown-unit-alist cache-key)
14488 (current-buffer))
14489 (insert ")\n"))
14490 (setq vhdl-updated-project-list
14491 (delete cache-key vhdl-updated-project-list))
14492 (save-buffer)
14493 (kill-buffer (current-buffer))
14494 (set-buffer orig-buffer))))
14496 (defun vhdl-load-cache (key)
14497 "Load hierarchy cache information from file."
14498 (let* ((vhdl-project key)
14499 (default-directory key)
14500 (directory (vhdl-default-directory))
14501 (file-name (vhdl-resolve-env-variable
14502 (vhdl-replace-string
14503 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14504 (concat
14505 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14506 " " (user-login-name)))))
14507 (file-dir-name (expand-file-name file-name directory))
14508 vhdl-cache-version)
14509 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14510 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14511 (when (file-exists-p file-dir-name)
14512 (condition-case ()
14513 (progn (load-file file-dir-name)
14514 (string< (mapconcat
14515 (lambda (a) (format "%3d" (string-to-number a)))
14516 (split-string "3.33" "\\.") "")
14517 (mapconcat
14518 (lambda (a) (format "%3d" (string-to-number a)))
14519 (split-string vhdl-cache-version "\\.") "")))
14520 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14521 nil))))))
14523 (defun vhdl-require-hierarchy-info ()
14524 "Make sure that hierarchy information is available. Load cache or scan files
14525 if required."
14526 (if (vhdl-project-p)
14527 (unless (or (assoc vhdl-project vhdl-file-alist)
14528 (vhdl-load-cache vhdl-project))
14529 (vhdl-scan-project-contents vhdl-project))
14530 (let ((directory (abbreviate-file-name default-directory)))
14531 (unless (or (assoc directory vhdl-file-alist)
14532 (vhdl-load-cache directory))
14533 (vhdl-scan-directory-contents directory)))))
14535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14536 ;; Add hierarchy browser functionality to speedbar
14538 (defvar vhdl-speedbar-mode-map nil
14539 "Keymap used when in the VHDL hierarchy browser mode.")
14541 (defvar vhdl-speedbar-menu-items nil
14542 "Additional menu-items to add to speedbar frame.")
14544 (declare-function speedbar-add-supported-extension "speedbar" (extension))
14545 (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
14546 (declare-function speedbar-make-specialized-keymap "speedbar" ())
14547 (declare-function speedbar-change-initial-expansion-list "speedbar"
14548 (new-default))
14549 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
14551 (defun vhdl-speedbar-initialize ()
14552 "Initialize speedbar."
14553 ;; general settings
14554 ;; VHDL file extensions (extracted from `auto-mode-alist')
14555 (let ((mode-alist auto-mode-alist))
14556 (while mode-alist
14557 (when (eq (cdar mode-alist) 'vhdl-mode)
14558 (speedbar-add-supported-extension (caar mode-alist)))
14559 (setq mode-alist (cdr mode-alist))))
14560 ;; hierarchy browser settings
14561 (when (boundp 'speedbar-mode-functions-list)
14562 ;; special functions
14563 (speedbar-add-mode-functions-list
14564 '("vhdl directory"
14565 (speedbar-item-info . vhdl-speedbar-item-info)
14566 (speedbar-line-directory . speedbar-files-line-path)))
14567 (speedbar-add-mode-functions-list
14568 '("vhdl project"
14569 (speedbar-item-info . vhdl-speedbar-item-info)
14570 (speedbar-line-directory . vhdl-speedbar-line-project)))
14571 ;; keymap
14572 (unless vhdl-speedbar-mode-map
14573 (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
14574 (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
14575 (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
14576 (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
14577 (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
14578 (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
14579 (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
14580 (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
14581 (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
14582 (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
14583 (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
14584 (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
14585 (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
14586 (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
14587 (let ((key 0))
14588 (while (<= key 9)
14589 (define-key vhdl-speedbar-mode-map (int-to-string key)
14590 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14591 (setq key (1+ key)))))
14592 (define-key speedbar-mode-map "h"
14593 (lambda () (interactive)
14594 (speedbar-change-initial-expansion-list "vhdl directory")))
14595 (define-key speedbar-mode-map "H"
14596 (lambda () (interactive)
14597 (speedbar-change-initial-expansion-list "vhdl project")))
14598 ;; menu
14599 (unless vhdl-speedbar-menu-items
14600 (setq
14601 vhdl-speedbar-menu-items
14602 `(["Edit" speedbar-edit-line t]
14603 ["Expand" speedbar-expand-line
14604 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14605 ["Contract" vhdl-speedbar-contract-level t]
14606 ["Expand All" vhdl-speedbar-expand-all t]
14607 ["Contract All" vhdl-speedbar-contract-all t]
14608 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14609 (while (<= key 9)
14610 (setq menu-list
14611 (cons `[,(if (= key 0) "All" (int-to-string key))
14612 (vhdl-speedbar-set-depth ,key)
14613 :style radio
14614 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14615 :keys ,(int-to-string key)]
14616 menu-list))
14617 (setq key (1+ key)))
14618 (nreverse menu-list))
14619 "--"
14620 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14621 (or (vhdl-speedbar-check-unit 'entity)
14622 (vhdl-speedbar-check-unit 'subprogram))]
14623 ["Place Component" vhdl-speedbar-place-component
14624 (vhdl-speedbar-check-unit 'entity)]
14625 ["Generate Configuration" vhdl-speedbar-configuration
14626 (vhdl-speedbar-check-unit 'architecture)]
14627 ["Select as MRA" vhdl-speedbar-select-mra
14628 (vhdl-speedbar-check-unit 'architecture)]
14629 ["Make" vhdl-speedbar-make-design
14630 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14631 ["Generate Makefile" vhdl-speedbar-generate-makefile
14632 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14633 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14634 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14635 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14636 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14637 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14638 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14639 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14640 ;; hook-ups
14641 (speedbar-add-expansion-list
14642 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14643 vhdl-speedbar-display-directory))
14644 (speedbar-add-expansion-list
14645 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14646 vhdl-speedbar-display-projects))
14647 (setq speedbar-stealthy-function-list
14648 (append
14649 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14650 ("vhdl project" vhdl-speedbar-update-current-project
14651 vhdl-speedbar-update-current-unit))
14652 speedbar-stealthy-function-list))
14653 (when (eq vhdl-speedbar-display-mode 'directory)
14654 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14655 (when (eq vhdl-speedbar-display-mode 'project)
14656 (setq speedbar-initial-expansion-list-name "vhdl project"))
14657 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14659 (defun vhdl-speedbar (&optional arg)
14660 "Open/close speedbar."
14661 (interactive)
14662 (if (not (fboundp 'speedbar))
14663 (error "WARNING: Speedbar is not available or not installed")
14664 (condition-case ()
14665 (speedbar-frame-mode arg)
14666 (error (error "WARNING: An error occurred while opening speedbar")))))
14668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14669 ;; Display functions
14671 (defvar vhdl-speedbar-last-selected-project nil
14672 "Name of last selected project.")
14674 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14675 ;;; (defmacro speedbar-with-writable (&rest forms)
14676 ;;; "Allow the buffer to be writable and evaluate FORMS."
14677 ;;; (list 'let '((inhibit-read-only t))
14678 ;;; (cons 'progn forms)))
14679 ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
14681 (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
14682 (declare-function speedbar-directory-buttons "speedbar" (directory _index))
14683 (declare-function speedbar-file-lists "speedbar" (directory))
14685 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14686 "Display directory and hierarchy information in speedbar."
14687 (setq vhdl-speedbar-show-projects nil)
14688 (setq speedbar-ignored-directory-regexp
14689 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14690 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14691 (setq speedbar-last-selected-file nil)
14692 (speedbar-with-writable
14693 (condition-case nil
14694 (progn
14695 ;; insert directory path
14696 (speedbar-directory-buttons directory depth)
14697 ;; insert subdirectories
14698 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14699 ;; scan and insert hierarchy of current directory
14700 (vhdl-speedbar-insert-dir-hierarchy directory depth
14701 speedbar-power-click)
14702 ;; expand subdirectories
14703 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14704 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14706 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14707 "Display projects and hierarchy information in speedbar."
14708 (setq vhdl-speedbar-show-projects t)
14709 (setq speedbar-ignored-directory-regexp ".")
14710 (setq speedbar-last-selected-file nil)
14711 (setq vhdl-speedbar-last-selected-project nil)
14712 (speedbar-with-writable
14713 (condition-case nil
14714 ;; insert projects
14715 (vhdl-speedbar-insert-projects)
14716 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14717 (setq speedbar-full-text-cache nil)) ; prevent caching
14719 (declare-function speedbar-make-tag-line "speedbar"
14720 (type char func data tag tfunc tdata tface depth))
14722 (defun vhdl-speedbar-insert-projects ()
14723 "Insert all projects in speedbar."
14724 (vhdl-speedbar-make-title-line "Projects:")
14725 (let ((project-alist (if vhdl-project-sort
14726 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14727 vhdl-project-alist))
14728 (vhdl-speedbar-update-current-unit nil))
14729 ;; insert projects
14730 (while project-alist
14731 (speedbar-make-tag-line
14732 'angle ?+ 'vhdl-speedbar-expand-project
14733 (caar project-alist) (caar project-alist)
14734 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14735 (setq project-alist (cdr project-alist)))
14736 (setq project-alist vhdl-project-alist)
14737 ;; expand projects
14738 (while project-alist
14739 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14740 (goto-char (point-min))
14741 (when (re-search-forward
14742 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14743 (goto-char (match-end 1))
14744 (speedbar-do-function-pointer)))
14745 (setq project-alist (cdr project-alist)))))
14747 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14748 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14749 otherwise use cached data."
14750 (when (or rescan (and (not (assoc project vhdl-file-alist))
14751 (not (vhdl-load-cache project))))
14752 (vhdl-scan-project-contents project))
14753 ;; insert design hierarchy
14754 (vhdl-speedbar-insert-hierarchy
14755 (vhdl-aget vhdl-entity-alist project)
14756 (vhdl-aget vhdl-config-alist project)
14757 (vhdl-aget vhdl-package-alist project)
14758 (car (vhdl-aget vhdl-ent-inst-alist project)) indent)
14759 (insert (int-to-string indent) ":\n")
14760 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14761 (put-text-property (1- (point)) (point) 'invisible nil)
14762 ;; expand design units
14763 (vhdl-speedbar-expand-units project))
14765 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14766 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14767 otherwise use cached data."
14768 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14769 (not (vhdl-load-cache directory))))
14770 (vhdl-scan-directory-contents directory))
14771 ;; insert design hierarchy
14772 (vhdl-speedbar-insert-hierarchy
14773 (vhdl-aget vhdl-entity-alist directory)
14774 (vhdl-aget vhdl-config-alist directory)
14775 (vhdl-aget vhdl-package-alist directory)
14776 (car (vhdl-aget vhdl-ent-inst-alist directory)) depth)
14777 ;; expand design units
14778 (vhdl-speedbar-expand-units directory)
14779 (vhdl-aput 'vhdl-directory-alist directory (list (list directory))))
14781 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14782 ent-inst-list depth)
14783 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14784 (if (not (or ent-alist conf-alist pack-alist))
14785 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14786 (let (ent-entry conf-entry pack-entry)
14787 ;; insert entities
14788 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14789 (while ent-alist
14790 (setq ent-entry (car ent-alist))
14791 (speedbar-make-tag-line
14792 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14793 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14794 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14795 'vhdl-speedbar-entity-face depth)
14796 (unless (nth 2 ent-entry)
14797 (end-of-line 0) (insert "!") (forward-char 1))
14798 (unless (member (nth 0 ent-entry) ent-inst-list)
14799 (end-of-line 0) (insert " (top)") (forward-char 1))
14800 (setq ent-alist (cdr ent-alist)))
14801 ;; insert configurations
14802 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14803 (while conf-alist
14804 (setq conf-entry (car conf-alist))
14805 (speedbar-make-tag-line
14806 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14807 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14808 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14809 'vhdl-speedbar-configuration-face depth)
14810 (setq conf-alist (cdr conf-alist)))
14811 ;; insert packages
14812 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14813 (while pack-alist
14814 (setq pack-entry (car pack-alist))
14815 (vhdl-speedbar-make-pack-line
14816 (nth 0 pack-entry) (nth 1 pack-entry)
14817 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14818 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14819 depth)
14820 (setq pack-alist (cdr pack-alist))))))
14822 (declare-function speedbar-line-directory "speedbar" (&optional depth))
14824 (defun vhdl-speedbar-rescan-hierarchy ()
14825 "Rescan hierarchy for the directory or project under the cursor."
14826 (interactive)
14827 (let (key path)
14828 (cond
14829 ;; current project
14830 (vhdl-speedbar-show-projects
14831 (setq key (vhdl-speedbar-line-project))
14832 (vhdl-scan-project-contents key))
14833 ;; top-level directory
14834 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14835 (re-search-forward "[0-9]+:" nil t)
14836 (vhdl-scan-directory-contents
14837 (abbreviate-file-name (speedbar-line-directory))))
14838 ;; current directory
14839 (t (setq path (speedbar-line-directory))
14840 (string-match "^\\(.+[/\\]\\)" path)
14841 (vhdl-scan-directory-contents
14842 (abbreviate-file-name (match-string 1 path)))))
14843 (vhdl-speedbar-refresh key)))
14845 (declare-function speedbar-goto-this-file "speedbar" (file))
14847 (defun vhdl-speedbar-expand-dirs (directory)
14848 "Expand subdirectories in DIRECTORY according to
14849 `speedbar-shown-directories'."
14850 ;; (nicked from `speedbar-default-directory-list')
14851 (let ((sf (cdr (reverse speedbar-shown-directories)))
14852 (vhdl-speedbar-update-current-unit nil))
14853 (setq speedbar-shown-directories
14854 (list (expand-file-name default-directory)))
14855 (while sf
14856 (when (speedbar-goto-this-file (car sf))
14857 (beginning-of-line)
14858 (when (looking-at "[0-9]+:\\s-*<")
14859 (goto-char (match-end 0))
14860 (speedbar-do-function-pointer)))
14861 (setq sf (cdr sf))))
14862 (vhdl-speedbar-update-current-unit nil t))
14864 (defun vhdl-speedbar-expand-units (key)
14865 "Expand design units in directory/project KEY according to
14866 `vhdl-speedbar-shown-unit-alist'."
14867 (let ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
14868 (vhdl-speedbar-update-current-unit nil)
14869 vhdl-updated-project-list)
14870 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
14871 (vhdl-prepare-search-1
14872 (while unit-alist ; expand units
14873 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14874 (beginning-of-line)
14875 (let ((arch-alist (nth 1 (car unit-alist)))
14876 position)
14877 (when (looking-at "^[0-9]+:\\s-*\\[")
14878 (goto-char (match-end 0))
14879 (setq position (point))
14880 (speedbar-do-function-pointer)
14881 (select-frame speedbar-frame)
14882 (while arch-alist ; expand architectures
14883 (goto-char position)
14884 (when (re-search-forward
14885 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14886 (car arch-alist) "\\>\\)") nil t)
14887 (beginning-of-line)
14888 (when (looking-at "^[0-9]+:\\s-*{")
14889 (goto-char (match-end 0))
14890 (speedbar-do-function-pointer)
14891 (select-frame speedbar-frame)))
14892 (setq arch-alist (cdr arch-alist))))
14893 (setq unit-alist (cdr unit-alist))))))
14894 (vhdl-speedbar-update-current-unit nil t))
14896 (declare-function speedbar-center-buffer-smartly "speedbar" ())
14898 (defun vhdl-speedbar-contract-level ()
14899 "Contract current level in current directory/project."
14900 (interactive)
14901 (when (or (save-excursion
14902 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14903 (and (save-excursion
14904 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14905 (re-search-backward
14906 (format "^[0-%d]:\\s-*[[{<]-"
14907 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14908 (goto-char (match-end 0))
14909 (speedbar-do-function-pointer)
14910 (speedbar-center-buffer-smartly)))
14912 (defun vhdl-speedbar-contract-all ()
14913 "Contract all expanded design units in current directory/project."
14914 (interactive)
14915 (if (and vhdl-speedbar-show-projects
14916 (save-excursion (beginning-of-line) (looking-at "^0:")))
14917 (progn (setq vhdl-speedbar-shown-project-list nil)
14918 (vhdl-speedbar-refresh))
14919 (let ((key (vhdl-speedbar-line-key)))
14920 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
14921 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14922 (when (memq 'display vhdl-speedbar-save-cache)
14923 (add-to-list 'vhdl-updated-project-list key)))))
14925 (defun vhdl-speedbar-expand-all ()
14926 "Expand all design units in current directory/project."
14927 (interactive)
14928 (let* ((key (vhdl-speedbar-line-key))
14929 (ent-alist (vhdl-aget vhdl-entity-alist key))
14930 (conf-alist (vhdl-aget vhdl-config-alist key))
14931 (pack-alist (vhdl-aget vhdl-package-alist key))
14932 arch-alist unit-alist subunit-alist)
14933 (add-to-list 'vhdl-speedbar-shown-project-list key)
14934 (while ent-alist
14935 (setq arch-alist (nth 4 (car ent-alist)))
14936 (setq subunit-alist nil)
14937 (while arch-alist
14938 (push (caar arch-alist) subunit-alist)
14939 (setq arch-alist (cdr arch-alist)))
14940 (push (list (caar ent-alist) subunit-alist) unit-alist)
14941 (setq ent-alist (cdr ent-alist)))
14942 (while conf-alist
14943 (push (list (caar conf-alist)) unit-alist)
14944 (setq conf-alist (cdr conf-alist)))
14945 (while pack-alist
14946 (push (list (caar pack-alist)) unit-alist)
14947 (setq pack-alist (cdr pack-alist)))
14948 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14949 (vhdl-speedbar-refresh)
14950 (when (memq 'display vhdl-speedbar-save-cache)
14951 (add-to-list 'vhdl-updated-project-list key))))
14953 (declare-function speedbar-change-expand-button-char "speedbar" (char))
14954 (declare-function speedbar-delete-subblock "speedbar" (indent))
14956 (defun vhdl-speedbar-expand-project (text token indent)
14957 "Expand/contract the project under the cursor."
14958 (cond
14959 ((string-match "+" text) ; expand project
14960 (speedbar-change-expand-button-char ?-)
14961 (unless (member token vhdl-speedbar-shown-project-list)
14962 (setq vhdl-speedbar-shown-project-list
14963 (cons token vhdl-speedbar-shown-project-list)))
14964 (speedbar-with-writable
14965 (save-excursion
14966 (end-of-line) (forward-char 1)
14967 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14968 speedbar-power-click))))
14969 ((string-match "-" text) ; contract project
14970 (speedbar-change-expand-button-char ?+)
14971 (setq vhdl-speedbar-shown-project-list
14972 (delete token vhdl-speedbar-shown-project-list))
14973 (speedbar-delete-subblock indent))
14974 (t (error "Nothing to display")))
14975 (when (equal (selected-frame) speedbar-frame)
14976 (speedbar-center-buffer-smartly)))
14978 (defun vhdl-speedbar-expand-entity (text token indent)
14979 "Expand/contract the entity under the cursor."
14980 (cond
14981 ((string-match "+" text) ; expand entity
14982 (let* ((key (vhdl-speedbar-line-key indent))
14983 (ent-alist (vhdl-aget vhdl-entity-alist key))
14984 (ent-entry (vhdl-aget ent-alist token))
14985 (arch-alist (nth 3 ent-entry))
14986 (inst-alist (vhdl-get-instantiations token indent))
14987 (subpack-alist (nth 5 ent-entry))
14988 (multiple-arch (> (length arch-alist) 1))
14989 arch-entry inst-entry)
14990 (if (not (or arch-alist inst-alist subpack-alist))
14991 (speedbar-change-expand-button-char ??)
14992 (speedbar-change-expand-button-char ?-)
14993 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14994 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
14995 (vhdl-aput 'unit-alist token nil)
14996 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14997 (speedbar-with-writable
14998 (save-excursion
14999 (end-of-line) (forward-char 1)
15000 ;; insert architectures
15001 (when arch-alist
15002 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
15003 (while arch-alist
15004 (setq arch-entry (car arch-alist))
15005 (speedbar-make-tag-line
15006 'curly ?+ 'vhdl-speedbar-expand-architecture
15007 (cons token (nth 0 arch-entry))
15008 (nth 1 arch-entry) 'vhdl-speedbar-find-file
15009 (cons (nth 2 arch-entry) (nth 3 arch-entry))
15010 'vhdl-speedbar-architecture-face (1+ indent))
15011 (when (and multiple-arch
15012 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
15013 (end-of-line 0) (insert " (mra)") (forward-char 1))
15014 (setq arch-alist (cdr arch-alist)))
15015 ;; insert instantiations
15016 (when inst-alist
15017 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
15018 (while inst-alist
15019 (setq inst-entry (car inst-alist))
15020 (vhdl-speedbar-make-inst-line
15021 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
15022 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
15023 nil nil nil (1+ indent) 0 " in ")
15024 (setq inst-alist (cdr inst-alist)))
15025 ;; insert required packages
15026 (vhdl-speedbar-insert-subpackages
15027 subpack-alist (1+ indent) indent)))
15028 (when (memq 'display vhdl-speedbar-save-cache)
15029 (add-to-list 'vhdl-updated-project-list key))
15030 (vhdl-speedbar-update-current-unit t t))))
15031 ((string-match "-" text) ; contract entity
15032 (speedbar-change-expand-button-char ?+)
15033 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
15034 (let* ((key (vhdl-speedbar-line-key indent))
15035 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15036 (vhdl-adelete 'unit-alist token)
15037 (if unit-alist
15038 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15039 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15040 (speedbar-delete-subblock indent)
15041 (when (memq 'display vhdl-speedbar-save-cache)
15042 (add-to-list 'vhdl-updated-project-list key))))
15043 (t (error "Nothing to display")))
15044 (when (equal (selected-frame) speedbar-frame)
15045 (speedbar-center-buffer-smartly)))
15047 (defun vhdl-speedbar-expand-architecture (text token indent)
15048 "Expand/contract the architecture under the cursor."
15049 (cond
15050 ((string-match "+" text) ; expand architecture
15051 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15052 (ent-alist (vhdl-aget vhdl-entity-alist key))
15053 (conf-alist (vhdl-aget vhdl-config-alist key))
15054 (hier-alist (vhdl-get-hierarchy
15055 ent-alist conf-alist (car token) (cdr token) nil nil
15056 0 (1- indent)))
15057 (ent-entry (vhdl-aget ent-alist (car token)))
15058 (arch-entry (vhdl-aget (nth 3 ent-entry) (cdr token)))
15059 (subpack-alist (nth 4 arch-entry))
15060 entry)
15061 (if (not (or hier-alist subpack-alist))
15062 (speedbar-change-expand-button-char ??)
15063 (speedbar-change-expand-button-char ?-)
15064 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15065 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15066 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15067 (vhdl-aput 'unit-alist (car token)
15068 (list (cons (cdr token) arch-alist)))
15069 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15070 (speedbar-with-writable
15071 (save-excursion
15072 (end-of-line) (forward-char 1)
15073 ;; insert instance hierarchy
15074 (when hier-alist
15075 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15076 (1+ indent)))
15077 (while hier-alist
15078 (setq entry (car hier-alist))
15079 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15080 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15081 (vhdl-speedbar-make-inst-line
15082 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15083 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15084 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
15085 (setq hier-alist (cdr hier-alist)))
15086 ;; insert required packages
15087 (vhdl-speedbar-insert-subpackages
15088 subpack-alist (1+ indent) (1- indent))))
15089 (when (memq 'display vhdl-speedbar-save-cache)
15090 (add-to-list 'vhdl-updated-project-list key))
15091 (vhdl-speedbar-update-current-unit t t))))
15092 ((string-match "-" text) ; contract architecture
15093 (speedbar-change-expand-button-char ?+)
15094 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15095 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15096 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15097 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15098 (vhdl-aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
15099 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15100 (speedbar-delete-subblock indent)
15101 (when (memq 'display vhdl-speedbar-save-cache)
15102 (add-to-list 'vhdl-updated-project-list key))))
15103 (t (error "Nothing to display")))
15104 (when (equal (selected-frame) speedbar-frame)
15105 (speedbar-center-buffer-smartly)))
15107 (defun vhdl-speedbar-expand-config (text token indent)
15108 "Expand/contract the configuration under the cursor."
15109 (cond
15110 ((string-match "+" text) ; expand configuration
15111 (let* ((key (vhdl-speedbar-line-key indent))
15112 (conf-alist (vhdl-aget vhdl-config-alist key))
15113 (conf-entry (vhdl-aget conf-alist token))
15114 (ent-alist (vhdl-aget vhdl-entity-alist key))
15115 (hier-alist (vhdl-get-hierarchy
15116 ent-alist conf-alist (nth 3 conf-entry)
15117 (nth 4 conf-entry) token (nth 5 conf-entry)
15118 0 indent t))
15119 (subpack-alist (nth 6 conf-entry))
15120 entry)
15121 (if (not (or hier-alist subpack-alist))
15122 (speedbar-change-expand-button-char ??)
15123 (speedbar-change-expand-button-char ?-)
15124 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15125 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15126 (vhdl-aput 'unit-alist token nil)
15127 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15128 (speedbar-with-writable
15129 (save-excursion
15130 (end-of-line) (forward-char 1)
15131 ;; insert instance hierarchy
15132 (when hier-alist
15133 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
15134 (while hier-alist
15135 (setq entry (car hier-alist))
15136 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15137 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15138 (vhdl-speedbar-make-inst-line
15139 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15140 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15141 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
15142 (setq hier-alist (cdr hier-alist)))
15143 ;; insert required packages
15144 (vhdl-speedbar-insert-subpackages
15145 subpack-alist (1+ indent) indent)))
15146 (when (memq 'display vhdl-speedbar-save-cache)
15147 (add-to-list 'vhdl-updated-project-list key))
15148 (vhdl-speedbar-update-current-unit t t))))
15149 ((string-match "-" text) ; contract configuration
15150 (speedbar-change-expand-button-char ?+)
15151 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15152 (let* ((key (vhdl-speedbar-line-key indent))
15153 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15154 (vhdl-adelete 'unit-alist token)
15155 (if unit-alist
15156 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15157 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15158 (speedbar-delete-subblock indent)
15159 (when (memq 'display vhdl-speedbar-save-cache)
15160 (add-to-list 'vhdl-updated-project-list key))))
15161 (t (error "Nothing to display")))
15162 (when (equal (selected-frame) speedbar-frame)
15163 (speedbar-center-buffer-smartly)))
15165 (defun vhdl-speedbar-expand-package (text token indent)
15166 "Expand/contract the package under the cursor."
15167 (cond
15168 ((string-match "+" text) ; expand package
15169 (let* ((key (vhdl-speedbar-line-key indent))
15170 (pack-alist (vhdl-aget vhdl-package-alist key))
15171 (pack-entry (vhdl-aget pack-alist token))
15172 (comp-alist (nth 3 pack-entry))
15173 (func-alist (nth 4 pack-entry))
15174 (func-body-alist (nth 8 pack-entry))
15175 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
15176 comp-entry func-entry func-body-entry)
15177 (if (not (or comp-alist func-alist subpack-alist))
15178 (speedbar-change-expand-button-char ??)
15179 (speedbar-change-expand-button-char ?-)
15180 ;; add package to `vhdl-speedbar-shown-unit-alist'
15181 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15182 (vhdl-aput 'unit-alist token nil)
15183 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15184 (speedbar-with-writable
15185 (save-excursion
15186 (end-of-line) (forward-char 1)
15187 ;; insert components
15188 (when comp-alist
15189 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
15190 (while comp-alist
15191 (setq comp-entry (car comp-alist))
15192 (speedbar-make-tag-line
15193 nil nil nil
15194 (cons token (nth 0 comp-entry))
15195 (nth 1 comp-entry) 'vhdl-speedbar-find-file
15196 (cons (nth 2 comp-entry) (nth 3 comp-entry))
15197 'vhdl-speedbar-entity-face (1+ indent))
15198 (setq comp-alist (cdr comp-alist)))
15199 ;; insert subprograms
15200 (when func-alist
15201 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
15202 (while func-alist
15203 (setq func-entry (car func-alist)
15204 func-body-entry (vhdl-aget func-body-alist
15205 (car func-entry)))
15206 (when (nth 2 func-entry)
15207 (vhdl-speedbar-make-subprogram-line
15208 (nth 1 func-entry)
15209 (cons (nth 2 func-entry) (nth 3 func-entry))
15210 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
15211 (1+ indent)))
15212 (setq func-alist (cdr func-alist)))
15213 ;; insert required packages
15214 (vhdl-speedbar-insert-subpackages
15215 subpack-alist (1+ indent) indent)))
15216 (when (memq 'display vhdl-speedbar-save-cache)
15217 (add-to-list 'vhdl-updated-project-list key))
15218 (vhdl-speedbar-update-current-unit t t))))
15219 ((string-match "-" text) ; contract package
15220 (speedbar-change-expand-button-char ?+)
15221 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15222 (let* ((key (vhdl-speedbar-line-key indent))
15223 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15224 (vhdl-adelete 'unit-alist token)
15225 (if unit-alist
15226 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15227 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15228 (speedbar-delete-subblock indent)
15229 (when (memq 'display vhdl-speedbar-save-cache)
15230 (add-to-list 'vhdl-updated-project-list key))))
15231 (t (error "Nothing to display")))
15232 (when (equal (selected-frame) speedbar-frame)
15233 (speedbar-center-buffer-smartly)))
15235 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15236 "Insert required packages."
15237 (let* ((pack-alist (vhdl-aget vhdl-package-alist
15238 (vhdl-speedbar-line-key dir-indent)))
15239 pack-key lib-name pack-entry)
15240 (when subpack-alist
15241 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15242 (while subpack-alist
15243 (setq pack-key (cdar subpack-alist)
15244 lib-name (caar subpack-alist))
15245 (setq pack-entry (vhdl-aget pack-alist pack-key))
15246 (vhdl-speedbar-make-subpack-line
15247 (or (nth 0 pack-entry) pack-key) lib-name
15248 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15249 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15250 (setq subpack-alist (cdr subpack-alist)))))
15252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15253 ;; Display help functions
15255 (defvar vhdl-speedbar-update-current-unit t
15256 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15258 (defun vhdl-speedbar-update-current-project ()
15259 "Highlight project that is currently active."
15260 (when (and vhdl-speedbar-show-projects
15261 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15262 (and (boundp 'speedbar-frame)
15263 (frame-live-p speedbar-frame)))
15264 (let ((last-frame (selected-frame))
15265 (project-alist vhdl-project-alist)
15266 pos)
15267 (select-frame speedbar-frame)
15268 (speedbar-with-writable
15269 (save-excursion
15270 (while project-alist
15271 (goto-char (point-min))
15272 (when (re-search-forward
15273 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15274 (put-text-property (match-beginning 1) (match-end 1) 'face
15275 (if (equal (caar project-alist) vhdl-project)
15276 'speedbar-selected-face
15277 'speedbar-directory-face))
15278 (when (equal (caar project-alist) vhdl-project)
15279 (setq pos (1- (match-beginning 1)))))
15280 (setq project-alist (cdr project-alist))))
15281 (when pos (goto-char pos)))
15282 (select-frame last-frame)
15283 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15286 (declare-function speedbar-position-cursor-on-line "speedbar" ())
15288 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15289 "Highlight all design units that are contained in the current file.
15290 NO-POSITION non-nil means do not re-position cursor."
15291 (let ((last-frame (selected-frame))
15292 (project-list vhdl-speedbar-shown-project-list)
15293 file-alist pos file-name)
15294 ;; get current file name
15295 (if (fboundp 'speedbar-select-attached-frame)
15296 (speedbar-select-attached-frame)
15297 (select-frame speedbar-attached-frame))
15298 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15299 (when (and vhdl-speedbar-update-current-unit
15300 (or always (not (equal file-name speedbar-last-selected-file))))
15301 (if vhdl-speedbar-show-projects
15302 (while project-list
15303 (setq file-alist (append file-alist
15304 (vhdl-aget vhdl-file-alist
15305 (car project-list))))
15306 (setq project-list (cdr project-list)))
15307 (setq file-alist
15308 (vhdl-aget vhdl-file-alist
15309 (abbreviate-file-name default-directory))))
15310 (select-frame speedbar-frame)
15311 (set-buffer speedbar-buffer)
15312 (speedbar-with-writable
15313 (vhdl-prepare-search-1
15314 (save-excursion
15315 ;; unhighlight last units
15316 (let* ((file-entry (vhdl-aget file-alist
15317 speedbar-last-selected-file)))
15318 (vhdl-speedbar-update-units
15319 "\\[.\\] " (nth 0 file-entry)
15320 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15321 (vhdl-speedbar-update-units
15322 "{.} " (nth 1 file-entry)
15323 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15324 (vhdl-speedbar-update-units
15325 "\\[.\\] " (nth 3 file-entry)
15326 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15327 (vhdl-speedbar-update-units
15328 "[]>] " (nth 4 file-entry)
15329 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15330 (vhdl-speedbar-update-units
15331 "\\[.\\].+(" '("body")
15332 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15333 (vhdl-speedbar-update-units
15334 "> " (nth 6 file-entry)
15335 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15336 ;; highlight current units
15337 (let* ((file-entry (vhdl-aget file-alist file-name)))
15338 (setq
15339 pos (vhdl-speedbar-update-units
15340 "\\[.\\] " (nth 0 file-entry)
15341 file-name 'vhdl-speedbar-entity-selected-face pos)
15342 pos (vhdl-speedbar-update-units
15343 "{.} " (nth 1 file-entry)
15344 file-name 'vhdl-speedbar-architecture-selected-face pos)
15345 pos (vhdl-speedbar-update-units
15346 "\\[.\\] " (nth 3 file-entry)
15347 file-name 'vhdl-speedbar-configuration-selected-face pos)
15348 pos (vhdl-speedbar-update-units
15349 "[]>] " (nth 4 file-entry)
15350 file-name 'vhdl-speedbar-package-selected-face pos)
15351 pos (vhdl-speedbar-update-units
15352 "\\[.\\].+(" '("body")
15353 file-name 'vhdl-speedbar-package-selected-face pos)
15354 pos (vhdl-speedbar-update-units
15355 "> " (nth 6 file-entry)
15356 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15357 ;; move speedbar so the first highlighted unit is visible
15358 (when (and pos (not no-position))
15359 (goto-char pos)
15360 (speedbar-center-buffer-smartly)
15361 (speedbar-position-cursor-on-line))
15362 (setq speedbar-last-selected-file file-name))
15363 (select-frame last-frame)
15366 (defun vhdl-speedbar-update-units (text unit-list file-name face
15367 &optional pos)
15368 "Help function to highlight design units."
15369 (while unit-list
15370 (goto-char (point-min))
15371 (while (re-search-forward
15372 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15373 (when (equal file-name (car (get-text-property
15374 (match-beginning 1) 'speedbar-token)))
15375 (setq pos (or pos (point-marker)))
15376 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15377 (setq unit-list (cdr unit-list)))
15378 pos)
15380 (declare-function speedbar-make-button "speedbar"
15381 (start end face mouse function &optional token))
15383 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15384 ent-name ent-file-marker
15385 arch-name arch-file-marker
15386 conf-name conf-file-marker
15387 lib-name depth offset delimiter)
15388 "Insert instantiation entry."
15389 (let ((start (point))
15390 visible-start)
15391 (insert (int-to-string depth) ":")
15392 (put-text-property start (point) 'invisible t)
15393 (setq visible-start (point))
15394 (insert-char ? (* depth speedbar-indentation-width))
15395 (while (> offset 0)
15396 (insert "|")
15397 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15398 (setq offset (1- offset)))
15399 (put-text-property visible-start (point) 'invisible nil)
15400 (setq start (point))
15401 (insert ">")
15402 (speedbar-make-button start (point) nil nil nil)
15403 (setq visible-start (point))
15404 (insert " ")
15405 (setq start (point))
15406 (if (not inst-name)
15407 (insert "(top)")
15408 (insert inst-name)
15409 (speedbar-make-button
15410 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15411 'vhdl-speedbar-find-file inst-file-marker))
15412 (insert delimiter)
15413 (when ent-name
15414 (setq start (point))
15415 (insert ent-name)
15416 (speedbar-make-button
15417 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15418 'vhdl-speedbar-find-file ent-file-marker)
15419 (when arch-name
15420 (insert " (")
15421 (setq start (point))
15422 (insert arch-name)
15423 (speedbar-make-button
15424 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15425 'vhdl-speedbar-find-file arch-file-marker)
15426 (insert ")"))
15427 (when conf-name
15428 (insert " (")
15429 (setq start (point))
15430 (insert conf-name)
15431 (speedbar-make-button
15432 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15433 'vhdl-speedbar-find-file conf-file-marker)
15434 (insert ")")))
15435 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15436 (setq start (point))
15437 (insert " (" lib-name ")")
15438 (put-text-property (+ 2 start) (1- (point)) 'face
15439 'vhdl-speedbar-library-face))
15440 (insert-char ?\n 1)
15441 (put-text-property visible-start (point) 'invisible nil)))
15443 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15444 body-file-marker depth)
15445 "Insert package entry."
15446 (let ((start (point))
15447 visible-start)
15448 (insert (int-to-string depth) ":")
15449 (put-text-property start (point) 'invisible t)
15450 (setq visible-start (point))
15451 (insert-char ? (* depth speedbar-indentation-width))
15452 (put-text-property visible-start (point) 'invisible nil)
15453 (setq start (point))
15454 (insert "[+]")
15455 (speedbar-make-button
15456 start (point) 'speedbar-button-face 'speedbar-highlight-face
15457 'vhdl-speedbar-expand-package pack-key)
15458 (setq visible-start (point))
15459 (insert-char ? 1 nil)
15460 (setq start (point))
15461 (insert pack-name)
15462 (speedbar-make-button
15463 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15464 'vhdl-speedbar-find-file pack-file-marker)
15465 (unless (car pack-file-marker)
15466 (insert "!"))
15467 (when (car body-file-marker)
15468 (insert " (")
15469 (setq start (point))
15470 (insert "body")
15471 (speedbar-make-button
15472 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15473 'vhdl-speedbar-find-file body-file-marker)
15474 (insert ")"))
15475 (insert-char ?\n 1)
15476 (put-text-property visible-start (point) 'invisible nil)))
15478 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15479 pack-body-file-marker depth)
15480 "Insert used package entry."
15481 (let ((start (point))
15482 visible-start)
15483 (insert (int-to-string depth) ":")
15484 (put-text-property start (point) 'invisible t)
15485 (setq visible-start (point))
15486 (insert-char ? (* depth speedbar-indentation-width))
15487 (put-text-property visible-start (point) 'invisible nil)
15488 (setq start (point))
15489 (insert ">")
15490 (speedbar-make-button start (point) nil nil nil)
15491 (setq visible-start (point))
15492 (insert " ")
15493 (setq start (point))
15494 (insert pack-name)
15495 (speedbar-make-button
15496 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15497 'vhdl-speedbar-find-file pack-file-marker)
15498 (when (car pack-body-file-marker)
15499 (insert " (")
15500 (setq start (point))
15501 (insert "body")
15502 (speedbar-make-button
15503 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15504 'vhdl-speedbar-find-file pack-body-file-marker)
15505 (insert ")"))
15506 (setq start (point))
15507 (insert " (" lib-name ")")
15508 (put-text-property (+ 2 start) (1- (point)) 'face
15509 'vhdl-speedbar-library-face)
15510 (insert-char ?\n 1)
15511 (put-text-property visible-start (point) 'invisible nil)))
15513 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15514 func-body-file-marker
15515 depth)
15516 "Insert subprogram entry."
15517 (let ((start (point))
15518 visible-start)
15519 (insert (int-to-string depth) ":")
15520 (put-text-property start (point) 'invisible t)
15521 (setq visible-start (point))
15522 (insert-char ? (* depth speedbar-indentation-width))
15523 (put-text-property visible-start (point) 'invisible nil)
15524 (setq start (point))
15525 (insert ">")
15526 (speedbar-make-button start (point) nil nil nil)
15527 (setq visible-start (point))
15528 (insert " ")
15529 (setq start (point))
15530 (insert func-name)
15531 (speedbar-make-button
15532 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15533 'vhdl-speedbar-find-file func-file-marker)
15534 (when (car func-body-file-marker)
15535 (insert " (")
15536 (setq start (point))
15537 (insert "body")
15538 (speedbar-make-button
15539 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15540 'vhdl-speedbar-find-file func-body-file-marker)
15541 (insert ")"))
15542 (insert-char ?\n 1)
15543 (put-text-property visible-start (point) 'invisible nil)))
15545 (defun vhdl-speedbar-make-title-line (text &optional depth)
15546 "Insert design unit title entry."
15547 (let ((start (point))
15548 visible-start)
15549 (when depth
15550 (insert (int-to-string depth) ":")
15551 (put-text-property start (point) 'invisible t))
15552 (setq visible-start (point))
15553 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15554 (setq start (point))
15555 (insert text)
15556 (speedbar-make-button start (point) nil nil nil nil)
15557 (insert-char ?\n 1)
15558 (put-text-property visible-start (point) 'invisible nil)))
15560 (defun vhdl-speedbar-insert-dirs (files level)
15561 "Insert subdirectories."
15562 (let ((dirs (car files)))
15563 (while dirs
15564 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15565 (car dirs) 'speedbar-dir-follow nil
15566 'speedbar-directory-face level)
15567 (setq dirs (cdr dirs)))))
15569 (declare-function speedbar-reset-scanners "speedbar" ())
15571 (defun vhdl-speedbar-dired (text token indent)
15572 "Speedbar click handler for directory expand button in hierarchy mode."
15573 (cond ((string-match "+" text) ; we have to expand this dir
15574 (setq speedbar-shown-directories
15575 (cons (expand-file-name
15576 (concat (speedbar-line-directory indent) token "/"))
15577 speedbar-shown-directories))
15578 (speedbar-change-expand-button-char ?-)
15579 (speedbar-reset-scanners)
15580 (speedbar-with-writable
15581 (save-excursion
15582 (end-of-line) (forward-char 1)
15583 (vhdl-speedbar-insert-dirs
15584 (speedbar-file-lists
15585 (concat (speedbar-line-directory indent) token "/"))
15586 (1+ indent))
15587 (speedbar-reset-scanners)
15588 (vhdl-speedbar-insert-dir-hierarchy
15589 (abbreviate-file-name
15590 (concat (speedbar-line-directory indent) token "/"))
15591 (1+ indent) speedbar-power-click)))
15592 (vhdl-speedbar-update-current-unit t t))
15593 ((string-match "-" text) ; we have to contract this node
15594 (speedbar-reset-scanners)
15595 (let ((oldl speedbar-shown-directories)
15596 (newl nil)
15597 (td (expand-file-name
15598 (concat (speedbar-line-directory indent) token))))
15599 (while oldl
15600 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15601 (push (car oldl) newl))
15602 (setq oldl (cdr oldl)))
15603 (setq speedbar-shown-directories (nreverse newl)))
15604 (speedbar-change-expand-button-char ?+)
15605 (speedbar-delete-subblock indent))
15606 (t (error "Nothing to display")))
15607 (when (equal (selected-frame) speedbar-frame)
15608 (speedbar-center-buffer-smartly)))
15610 (declare-function speedbar-files-item-info "speedbar" ())
15612 (defun vhdl-speedbar-item-info ()
15613 "Derive and display information about this line item."
15614 (save-excursion
15615 (beginning-of-line)
15616 ;; skip invisible number info
15617 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15618 (cond
15619 ;; project/directory entry
15620 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15621 (if vhdl-speedbar-show-projects
15622 (message "Project \"%s\"" (match-string-no-properties 1))
15623 (speedbar-files-item-info)))
15624 ;; design unit entry
15625 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15626 (goto-char (match-end 1))
15627 (let ((face (get-text-property (point) 'face)))
15628 (message
15629 "%s \"%s\" in \"%s\""
15630 ;; design unit kind
15631 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15632 (eq face 'vhdl-speedbar-entity-selected-face))
15633 (if (equal (match-string 2) ">") "Component" "Entity"))
15634 ((or (eq face 'vhdl-speedbar-architecture-face)
15635 (eq face 'vhdl-speedbar-architecture-selected-face))
15636 "Architecture")
15637 ((or (eq face 'vhdl-speedbar-configuration-face)
15638 (eq face 'vhdl-speedbar-configuration-selected-face))
15639 "Configuration")
15640 ((or (eq face 'vhdl-speedbar-package-face)
15641 (eq face 'vhdl-speedbar-package-selected-face))
15642 "Package")
15643 ((or (eq face 'vhdl-speedbar-instantiation-face)
15644 (eq face 'vhdl-speedbar-instantiation-selected-face))
15645 "Instantiation")
15646 ((eq face 'vhdl-speedbar-subprogram-face)
15647 "Subprogram")
15648 (t ""))
15649 ;; design unit name
15650 (buffer-substring-no-properties
15651 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15652 (match-end 1))
15653 ;; file name
15654 (file-relative-name
15655 (or (car (get-text-property (point) 'speedbar-token))
15656 "?")
15657 (vhdl-default-directory)))))
15658 (t (message "")))))
15660 (declare-function speedbar-line-text "speedbar" (&optional p))
15662 (defun vhdl-speedbar-line-text ()
15663 "Calls `speedbar-line-text' and removes text properties."
15664 (let ((string (speedbar-line-text)))
15665 (set-text-properties 0 (length string) nil string)
15666 string))
15668 (defun vhdl-speedbar-higher-text ()
15669 "Get speedbar-line-text of higher level."
15670 (let (depth string)
15671 (save-excursion
15672 (beginning-of-line)
15673 (looking-at "^\\([0-9]+\\):")
15674 (setq depth (string-to-number (match-string 1)))
15675 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15676 (setq string (match-string 1))
15677 (set-text-properties 0 (length string) nil string)
15678 string))))
15680 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15681 ;; Help functions
15683 (defun vhdl-speedbar-line-key (&optional indent)
15684 "Get currently displayed directory of project name."
15685 (if vhdl-speedbar-show-projects
15686 (vhdl-speedbar-line-project)
15687 (abbreviate-file-name
15688 (file-name-as-directory (speedbar-line-directory indent)))))
15690 (defun vhdl-speedbar-line-project (&optional indent)
15691 "Get currently displayed project name."
15692 (and vhdl-speedbar-show-projects
15693 (save-excursion
15694 (end-of-line)
15695 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15696 (match-string-no-properties 1))))
15698 (defun vhdl-add-modified-file ()
15699 "Add file to `vhdl-modified-file-list'."
15700 (when vhdl-file-alist
15701 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15702 nil)
15704 (defun vhdl-resolve-paths (path-list)
15705 "Resolve path wildcards in PATH-LIST."
15706 (let (path-list-1 path-list-2 path-beg path-end dir)
15707 ;; eliminate non-existent directories
15708 (while path-list
15709 (setq dir (car path-list))
15710 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15711 (if (file-directory-p (match-string 2 dir))
15712 (push dir path-list-1)
15713 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15714 (setq path-list (cdr path-list)))
15715 ;; resolve path wildcards
15716 (while path-list-1
15717 (setq dir (car path-list-1))
15718 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15719 (progn
15720 (setq path-beg (match-string 1 dir)
15721 path-end (match-string 5 dir))
15722 (setq path-list-1
15723 (append
15724 (mapcar
15725 (function
15726 (lambda (var) (concat path-beg var path-end)))
15727 (let ((all-list (vhdl-directory-files
15728 (match-string 2 dir) t
15729 (concat "\\<" (wildcard-to-regexp
15730 (match-string 4 dir)))))
15731 dir-list)
15732 (while all-list
15733 (when (file-directory-p (car all-list))
15734 (push (car all-list) dir-list))
15735 (setq all-list (cdr all-list)))
15736 dir-list))
15737 (cdr path-list-1))))
15738 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15739 (when (file-directory-p (match-string 2 dir))
15740 (push dir path-list-2))
15741 (setq path-list-1 (cdr path-list-1))))
15742 (nreverse path-list-2)))
15744 (defun vhdl-speedbar-goto-this-unit (directory unit)
15745 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15746 (let ((dest (point)))
15747 (if (and (if vhdl-speedbar-show-projects
15748 (progn (goto-char (point-min)) t)
15749 (speedbar-goto-this-file directory))
15750 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15751 (progn (speedbar-position-cursor-on-line)
15753 (goto-char dest)
15754 nil)))
15756 (declare-function speedbar-find-file-in-frame "speedbar" (file))
15757 (declare-function speedbar-set-timer "speedbar" (timeout))
15758 ;; speedbar loads dframe at runtime.
15759 (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
15761 (defun vhdl-speedbar-find-file (text token indent)
15762 "When user clicks on TEXT, load file with name and position in TOKEN.
15763 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15764 is already shown in a buffer."
15765 (if (not (car token))
15766 (error "ERROR: File cannot be found")
15767 (let ((buffer (get-file-buffer (car token))))
15768 (speedbar-find-file-in-frame (car token))
15769 (when (or vhdl-speedbar-jump-to-unit buffer)
15770 (goto-char (point-min))
15771 (forward-line (1- (cdr token)))
15772 (recenter))
15773 (vhdl-speedbar-update-current-unit t t)
15774 (speedbar-set-timer dframe-update-speed)
15775 (dframe-maybee-jump-to-attached-frame))))
15777 (defun vhdl-speedbar-port-copy ()
15778 "Copy the port of the entity/component or subprogram under the cursor."
15779 (interactive)
15780 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15781 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15782 (error "ERROR: No entity/component or subprogram under cursor")
15783 (beginning-of-line)
15784 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15785 (condition-case info
15786 (let ((token (get-text-property
15787 (match-beginning 3) 'speedbar-token)))
15788 (vhdl-visit-file (car token) t
15789 (progn (goto-char (point-min))
15790 (forward-line (1- (cdr token)))
15791 (end-of-line)
15792 (if is-entity
15793 (vhdl-port-copy)
15794 (vhdl-subprog-copy)))))
15795 (error (error "ERROR: %s not scanned successfully\n (%s)"
15796 (if is-entity "Port" "Interface") (cadr info))))
15797 (error "ERROR: No entity/component or subprogram on current line")))))
15799 (defun vhdl-speedbar-place-component ()
15800 "Place the entity/component under the cursor as component."
15801 (interactive)
15802 (if (not (vhdl-speedbar-check-unit 'entity))
15803 (error "ERROR: No entity/component under cursor")
15804 (vhdl-speedbar-port-copy)
15805 (if (fboundp 'speedbar-select-attached-frame)
15806 (speedbar-select-attached-frame)
15807 (select-frame speedbar-attached-frame))
15808 (vhdl-compose-place-component)
15809 (select-frame speedbar-frame)))
15811 (defun vhdl-speedbar-configuration ()
15812 "Generate configuration for the architecture under the cursor."
15813 (interactive)
15814 (if (not (vhdl-speedbar-check-unit 'architecture))
15815 (error "ERROR: No architecture under cursor")
15816 (let ((arch-name (vhdl-speedbar-line-text))
15817 (ent-name (vhdl-speedbar-higher-text)))
15818 (if (fboundp 'speedbar-select-attached-frame)
15819 (speedbar-select-attached-frame)
15820 (select-frame speedbar-attached-frame))
15821 (vhdl-compose-configuration ent-name arch-name))))
15823 (defun vhdl-speedbar-select-mra ()
15824 "Select the architecture under the cursor as MRA."
15825 (interactive)
15826 (if (not (vhdl-speedbar-check-unit 'architecture))
15827 (error "ERROR: No architecture under cursor")
15828 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15829 (ent-key (downcase (vhdl-speedbar-higher-text)))
15830 (ent-alist (vhdl-aget
15831 vhdl-entity-alist
15832 (or (vhdl-project-p)
15833 (abbreviate-file-name default-directory))))
15834 (ent-entry (vhdl-aget ent-alist ent-key)))
15835 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15836 (speedbar-refresh))))
15838 (declare-function speedbar-line-file "speedbar" (&optional p))
15840 (defun vhdl-speedbar-make-design ()
15841 "Make (compile) design unit or directory/project under the cursor."
15842 (interactive)
15843 (if (not (save-excursion (beginning-of-line)
15844 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15845 (error "ERROR: No primary design unit or directory/project under cursor")
15846 (let ((is-unit (match-string 2))
15847 (unit-name (vhdl-speedbar-line-text))
15848 (vhdl-project (vhdl-speedbar-line-project))
15849 (directory (file-name-as-directory
15850 (or (speedbar-line-file) (speedbar-line-directory)))))
15851 (if (fboundp 'speedbar-select-attached-frame)
15852 (speedbar-select-attached-frame)
15853 (select-frame speedbar-attached-frame))
15854 (let ((default-directory directory))
15855 (vhdl-make (and is-unit unit-name))))))
15857 (defun vhdl-speedbar-generate-makefile ()
15858 "Generate Makefile for directory/project under the cursor."
15859 (interactive)
15860 (let ((vhdl-project (vhdl-speedbar-line-project))
15861 (default-directory (file-name-as-directory
15862 (or (speedbar-line-file) (speedbar-line-directory)))))
15863 (vhdl-generate-makefile)))
15865 (defun vhdl-speedbar-check-unit (design-unit)
15866 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15867 expansion function)."
15868 (save-excursion
15869 (speedbar-position-cursor-on-line)
15870 (cond ((eq design-unit 'entity)
15871 (memq (get-text-property (match-end 0) 'face)
15872 '(vhdl-speedbar-entity-face
15873 vhdl-speedbar-entity-selected-face)))
15874 ((eq design-unit 'architecture)
15875 (memq (get-text-property (match-end 0) 'face)
15876 '(vhdl-speedbar-architecture-face
15877 vhdl-speedbar-architecture-selected-face)))
15878 ((eq design-unit 'subprogram)
15879 (eq (get-text-property (match-end 0) 'face)
15880 'vhdl-speedbar-subprogram-face))
15881 (t nil))))
15883 (defun vhdl-speedbar-set-depth (depth)
15884 "Set hierarchy display depth to DEPTH and refresh speedbar."
15885 (setq vhdl-speedbar-hierarchy-depth depth)
15886 (speedbar-refresh))
15888 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15889 ;; Fontification
15891 (defface vhdl-speedbar-entity-face
15892 '((((class color) (background light)) (:foreground "ForestGreen"))
15893 (((class color) (background dark)) (:foreground "PaleGreen")))
15894 "Face used for displaying entity names."
15895 :group 'speedbar-faces)
15897 (defface vhdl-speedbar-architecture-face
15898 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15899 (((class color) (background light)) (:foreground "Blue"))
15901 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15902 "Face used for displaying architecture names."
15903 :group 'speedbar-faces)
15905 (defface vhdl-speedbar-configuration-face
15906 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15907 (((class color) (background dark)) (:foreground "Salmon")))
15908 "Face used for displaying configuration names."
15909 :group 'speedbar-faces)
15911 (defface vhdl-speedbar-package-face
15912 '((((class color) (background light)) (:foreground "Grey50"))
15913 (((class color) (background dark)) (:foreground "Grey80")))
15914 "Face used for displaying package names."
15915 :group 'speedbar-faces)
15917 (defface vhdl-speedbar-library-face
15918 '((((class color) (background light)) (:foreground "Purple"))
15919 (((class color) (background dark)) (:foreground "Orchid1")))
15920 "Face used for displaying library names."
15921 :group 'speedbar-faces)
15923 (defface vhdl-speedbar-instantiation-face
15924 '((((class color) (background light)) (:foreground "Brown"))
15925 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15926 (((class color) (background dark)) (:foreground "Yellow")))
15927 "Face used for displaying instantiation names."
15928 :group 'speedbar-faces)
15930 (defface vhdl-speedbar-subprogram-face
15931 '((((class color) (background light)) (:foreground "Orchid4"))
15932 (((class color) (background dark)) (:foreground "BurlyWood2")))
15933 "Face used for displaying subprogram names."
15934 :group 'speedbar-faces)
15936 (defface vhdl-speedbar-entity-selected-face
15937 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15938 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15939 "Face used for displaying entity names."
15940 :group 'speedbar-faces)
15942 (defface vhdl-speedbar-architecture-selected-face
15943 '((((min-colors 88) (class color) (background light)) (:foreground
15944 "Blue1" :underline t))
15945 (((class color) (background light)) (:foreground "Blue" :underline t))
15946 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15947 "Face used for displaying architecture names."
15948 :group 'speedbar-faces)
15950 (defface vhdl-speedbar-configuration-selected-face
15951 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15952 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15953 "Face used for displaying configuration names."
15954 :group 'speedbar-faces)
15956 (defface vhdl-speedbar-package-selected-face
15957 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15958 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15959 "Face used for displaying package names."
15960 :group 'speedbar-faces)
15962 (defface vhdl-speedbar-instantiation-selected-face
15963 '((((class color) (background light)) (:foreground "Brown" :underline t))
15964 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15965 "Face used for displaying instantiation names."
15966 :group 'speedbar-faces)
15968 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15969 ;; Initialization
15971 ;; add speedbar
15972 (when (fboundp 'speedbar)
15973 (let ((current-frame (selected-frame)))
15974 (condition-case ()
15975 (when (and vhdl-speedbar-auto-open
15976 (not (and (boundp 'speedbar-frame)
15977 (frame-live-p speedbar-frame))))
15978 (speedbar-frame-mode 1))
15979 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar")))
15980 (select-frame current-frame)))
15982 ;; initialize speedbar
15983 (if (not (boundp 'speedbar-frame))
15984 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15985 (vhdl-speedbar-initialize)
15986 (when speedbar-frame (vhdl-speedbar-refresh)))
15989 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15990 ;;; Structural composition
15991 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15993 (defun vhdl-get-components-package-name ()
15994 "Return the name of the components package."
15995 (let ((project (vhdl-project-p)))
15996 (if project
15997 (vhdl-replace-string (car vhdl-components-package-name)
15998 (subst-char-in-string ? ?_ project))
15999 (cdr vhdl-components-package-name))))
16001 (defun vhdl-compose-new-component ()
16002 "Create entity and architecture for new component."
16003 (interactive)
16004 (let* ((case-fold-search t)
16005 (ent-name (read-from-minibuffer "entity name: "
16006 nil vhdl-minibuffer-local-map))
16007 (arch-name
16008 (if (equal (cdr vhdl-compose-architecture-name) "")
16009 (read-from-minibuffer "architecture name: "
16010 nil vhdl-minibuffer-local-map)
16011 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
16012 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
16013 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
16014 ;; open entity file
16015 (unless (eq vhdl-compose-create-files 'none)
16016 (setq ent-file-name
16017 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16018 "." (file-name-extension (buffer-file-name))))
16019 (when (and (file-exists-p ent-file-name)
16020 (not (y-or-n-p (concat "File \"" ent-file-name
16021 "\" exists; overwrite? "))))
16022 (error "ERROR: Creating component...aborted"))
16023 (find-file ent-file-name)
16024 (erase-buffer)
16025 (set-buffer-modified-p nil))
16026 ;; insert header
16027 (if vhdl-compose-include-header
16028 (progn (vhdl-template-header)
16029 (setq end-pos (point))
16030 (goto-char (point-max)))
16031 (vhdl-comment-display-line) (insert "\n\n"))
16032 ;; insert library clause
16033 (vhdl-template-package-std-logic-1164)
16034 (when vhdl-use-components-package
16035 (insert "\n")
16036 (vhdl-template-standard-package (vhdl-work-library)
16037 (vhdl-get-components-package-name)))
16038 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
16039 ;; insert entity declaration
16040 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
16041 (vhdl-insert-keyword " IS\n")
16042 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16043 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
16044 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16045 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16046 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
16047 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16048 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16049 (vhdl-insert-keyword "END ")
16050 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
16051 (insert ent-name ";\n\n")
16052 (vhdl-comment-display-line) (insert "\n")
16053 ;; open architecture file
16054 (if (not (eq vhdl-compose-create-files 'separate))
16055 (insert "\n")
16056 (goto-char (or end-pos (point-min)))
16057 (setq ent-buffer (current-buffer))
16058 (setq arch-file-name
16059 (concat (vhdl-replace-string vhdl-architecture-file-name
16060 (concat ent-name " " arch-name) t)
16061 "." (file-name-extension (buffer-file-name))))
16062 (when (and (file-exists-p arch-file-name)
16063 (not (y-or-n-p (concat "File \"" arch-file-name
16064 "\" exists; overwrite? "))))
16065 (error "ERROR: Creating component...aborted"))
16066 (find-file arch-file-name)
16067 (erase-buffer)
16068 (set-buffer-modified-p nil)
16069 ;; insert header
16070 (if vhdl-compose-include-header
16071 (progn (vhdl-template-header)
16072 (goto-char (point-max)))
16073 (vhdl-comment-display-line) (insert "\n\n")))
16074 ;; insert architecture body
16075 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
16076 (vhdl-insert-keyword " OF ") (insert ent-name)
16077 (vhdl-insert-keyword " IS\n\n")
16078 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16079 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
16080 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16081 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
16082 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16083 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16084 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
16085 (vhdl-insert-keyword "BEGIN")
16086 (when vhdl-self-insert-comments
16087 (insert " -- ")
16088 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16089 (insert arch-name))
16090 (insert "\n\n")
16091 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16092 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
16093 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16094 (vhdl-insert-keyword "END ")
16095 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16096 (insert arch-name ";\n\n")
16097 ;; insert footer and save
16098 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16099 (vhdl-template-footer)
16100 (vhdl-comment-display-line) (insert "\n"))
16101 (goto-char (or end-pos (point-min)))
16102 (setq arch-buffer (current-buffer))
16103 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
16104 (set-buffer arch-buffer) (save-buffer)
16105 (message "%s"
16106 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
16107 (and ent-file-name
16108 (format "\n File created: \"%s\"" ent-file-name))
16109 (and arch-file-name
16110 (format "\n File created: \"%s\"" arch-file-name))))))
16112 (defun vhdl-compose-place-component ()
16113 "Place new component by pasting current port as component declaration and
16114 component instantiation."
16115 (interactive)
16116 (if (not vhdl-port-list)
16117 (error "ERROR: No port has been read")
16118 (save-excursion
16119 (vhdl-prepare-search-2
16120 (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)
16121 (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))
16122 (error "ERROR: No architecture found"))
16123 (let* ((ent-name (match-string 1))
16124 (ent-file-name
16125 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16126 "." (file-name-extension (buffer-file-name))))
16127 (orig-buffer (current-buffer)))
16128 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
16129 ;; place component declaration
16130 (unless (or vhdl-use-components-package
16131 (vhdl-use-direct-instantiation)
16132 (save-excursion
16133 (re-search-forward
16134 (concat "^\\s-*component\\s-+"
16135 (car vhdl-port-list) "\\>") nil t)))
16136 (re-search-forward "^begin\\>" nil)
16137 (beginning-of-line)
16138 (skip-chars-backward " \t\n\r\f")
16139 (insert "\n\n") (indent-to vhdl-basic-offset)
16140 (vhdl-port-paste-component t))
16141 ;; place component instantiation
16142 (re-search-forward "^end\\>" nil)
16143 (beginning-of-line)
16144 (skip-chars-backward " \t\n\r\f")
16145 (insert "\n\n") (indent-to vhdl-basic-offset)
16146 (vhdl-port-paste-instance nil t t)
16147 ;; place use clause for used packages
16148 (when (nth 3 vhdl-port-list)
16149 ;; open entity file
16150 (when (file-exists-p ent-file-name)
16151 (find-file ent-file-name))
16152 (goto-char (point-min))
16153 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16154 (error "ERROR: Entity not found: \"%s\"" ent-name))
16155 (goto-char (match-beginning 0))
16156 (if (and (save-excursion
16157 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
16158 (match-string 1))
16159 (progn (goto-char (match-end 0))
16160 (beginning-of-line 2))
16161 (insert "\n")
16162 (backward-char))
16163 (vhdl-port-paste-context-clause)
16164 (switch-to-buffer orig-buffer))
16165 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
16167 (defun vhdl-compose-wire-components ()
16168 "Connect components."
16169 (interactive)
16170 (save-excursion
16171 (vhdl-prepare-search-2
16172 (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)
16173 (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))
16174 (error "ERROR: No architecture found"))
16175 (let* ((ent-name (match-string 1))
16176 (ent-file-name
16177 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16178 "." (file-name-extension (buffer-file-name))))
16179 (arch-decl-pos (point-marker))
16180 (arch-stat-pos (re-search-forward "^begin\\>" nil))
16181 (arch-end-pos (re-search-forward "^end\\>" nil))
16182 (pack-name (vhdl-get-components-package-name))
16183 (pack-file-name
16184 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16185 "." (file-name-extension (buffer-file-name))))
16186 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16187 port-alist generic-alist inst-alist
16188 signal-name signal-entry signal-alist local-list written-list
16189 single-in-list multi-in-list single-out-list multi-out-list
16190 constant-name constant-entry constant-alist single-list multi-list
16191 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16192 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16193 signal-beg-pos signal-pos
16194 constant-temp-pos port-temp-pos signal-temp-pos)
16195 (message "Wiring components...")
16196 ;; process all instances
16197 (goto-char arch-stat-pos)
16198 (while (re-search-forward
16199 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16200 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16201 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16202 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16203 "[ \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)
16204 (setq inst-name (match-string-no-properties 1)
16205 comp-name (match-string-no-properties 4)
16206 comp-ent-name (match-string-no-properties 12)
16207 has-generic (or (match-string 7) (match-string 17)))
16208 ;; get port ...
16209 (if comp-name
16210 ;; ... from component declaration
16211 (vhdl-visit-file
16212 (when vhdl-use-components-package pack-file-name) t
16213 (save-excursion
16214 (goto-char (point-min))
16215 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
16216 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
16217 (vhdl-port-copy)))
16218 ;; ... from entity declaration (direct instantiation)
16219 (setq comp-ent-file-name
16220 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
16221 "." (file-name-extension (buffer-file-name))))
16222 (vhdl-visit-file
16223 comp-ent-file-name t
16224 (save-excursion
16225 (goto-char (point-min))
16226 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
16227 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
16228 (vhdl-port-copy))))
16229 (vhdl-port-flatten t)
16230 (setq generic-alist (nth 1 vhdl-port-list)
16231 port-alist (nth 2 vhdl-port-list)
16232 vhdl-port-list nil)
16233 (setq constant-alist nil
16234 signal-alist nil)
16235 (when has-generic
16236 ;; process all constants in generic map
16237 (vhdl-forward-syntactic-ws)
16238 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16239 (setq constant-name (match-string-no-properties 3))
16240 (setq constant-entry
16241 (cons constant-name
16242 (if (match-string 1)
16243 (or (vhdl-aget generic-alist (match-string 2))
16244 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16245 (cdar generic-alist))))
16246 (push constant-entry constant-alist)
16247 (setq constant-name (downcase constant-name))
16248 (if (or (member constant-name single-list)
16249 (member constant-name multi-list))
16250 (progn (setq single-list (delete constant-name single-list))
16251 (add-to-list 'multi-list constant-name))
16252 (add-to-list 'single-list constant-name))
16253 (unless (match-string 1)
16254 (setq generic-alist (cdr generic-alist)))
16255 (vhdl-forward-syntactic-ws))
16256 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16257 ;; process all signals in port map
16258 (vhdl-forward-syntactic-ws)
16259 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16260 (setq signal-name (match-string-no-properties 3))
16261 (setq signal-entry
16262 (cons signal-name
16263 (if (match-string 1)
16264 (or (vhdl-aget port-alist (match-string 2))
16265 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16266 (cdar port-alist))))
16267 (push signal-entry signal-alist)
16268 (setq signal-name (downcase signal-name))
16269 (if (equal (upcase (nth 2 signal-entry)) "IN")
16270 ;; input signal
16271 (cond
16272 ((member signal-name local-list)
16273 nil)
16274 ((or (member signal-name single-out-list)
16275 (member signal-name multi-out-list))
16276 (setq single-out-list (delete signal-name single-out-list))
16277 (setq multi-out-list (delete signal-name multi-out-list))
16278 (add-to-list 'local-list signal-name))
16279 ((member signal-name single-in-list)
16280 (setq single-in-list (delete signal-name single-in-list))
16281 (add-to-list 'multi-in-list signal-name))
16282 ((not (member signal-name multi-in-list))
16283 (add-to-list 'single-in-list signal-name)))
16284 ;; output signal
16285 (cond
16286 ((member signal-name local-list)
16287 nil)
16288 ((or (member signal-name single-in-list)
16289 (member signal-name multi-in-list))
16290 (setq single-in-list (delete signal-name single-in-list))
16291 (setq multi-in-list (delete signal-name multi-in-list))
16292 (add-to-list 'local-list signal-name))
16293 ((member signal-name single-out-list)
16294 (setq single-out-list (delete signal-name single-out-list))
16295 (add-to-list 'multi-out-list signal-name))
16296 ((not (member signal-name multi-out-list))
16297 (add-to-list 'single-out-list signal-name))))
16298 (unless (match-string 1)
16299 (setq port-alist (cdr port-alist)))
16300 (vhdl-forward-syntactic-ws))
16301 (push (list inst-name (nreverse constant-alist)
16302 (nreverse signal-alist)) inst-alist))
16303 ;; prepare signal insertion
16304 (vhdl-goto-marker arch-decl-pos)
16305 (forward-line 1)
16306 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16307 (setq signal-pos (point-marker))
16308 (while (progn (vhdl-forward-syntactic-ws)
16309 (looking-at "signal\\>"))
16310 (beginning-of-line 2)
16311 (delete-region signal-pos (point)))
16312 (setq signal-beg-pos signal-pos)
16313 ;; open entity file
16314 (when (file-exists-p ent-file-name)
16315 (find-file ent-file-name))
16316 (goto-char (point-min))
16317 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16318 (error "ERROR: Entity not found: \"%s\"" ent-name))
16319 ;; prepare generic clause insertion
16320 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16321 (match-string 1))
16322 (goto-char (match-beginning 0))
16323 (indent-to vhdl-basic-offset)
16324 (insert "generic ();\n\n")
16325 (backward-char 4))
16326 (backward-char)
16327 (setq generic-pos (point-marker))
16328 (forward-sexp) (end-of-line)
16329 (delete-region generic-pos (point)) (delete-char 1)
16330 (insert "(\n")
16331 (when multi-list
16332 (insert "\n")
16333 (indent-to (* 2 vhdl-basic-offset))
16334 (insert "-- global generics\n"))
16335 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16336 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16337 ;; prepare port clause insertion
16338 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16339 (match-string 1))
16340 (goto-char (match-beginning 0))
16341 (indent-to vhdl-basic-offset)
16342 (insert "port ();\n\n")
16343 (backward-char 4))
16344 (backward-char)
16345 (setq port-in-pos (point-marker))
16346 (forward-sexp) (end-of-line)
16347 (delete-region port-in-pos (point)) (delete-char 1)
16348 (insert "(\n")
16349 (when (or multi-in-list multi-out-list)
16350 (insert "\n")
16351 (indent-to (* 2 vhdl-basic-offset))
16352 (insert "-- global ports\n"))
16353 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16354 port-out-pos (point-marker) port-inst-pos (point-marker)
16355 port-end-pos (point-marker))
16356 ;; insert generics, ports and signals
16357 (setq inst-alist (nreverse inst-alist))
16358 (while inst-alist
16359 (setq inst-name (nth 0 (car inst-alist))
16360 constant-alist (nth 1 (car inst-alist))
16361 signal-alist (nth 2 (car inst-alist))
16362 constant-temp-pos generic-inst-pos
16363 port-temp-pos port-inst-pos
16364 signal-temp-pos signal-pos)
16365 ;; generics
16366 (while constant-alist
16367 (setq constant-name (downcase (caar constant-alist))
16368 constant-entry (car constant-alist))
16369 (unless (string-match "^[0-9]+" constant-name)
16370 (cond ((member constant-name written-list)
16371 nil)
16372 ((member constant-name multi-list)
16373 (vhdl-goto-marker generic-pos)
16374 (setq generic-end-pos
16375 (vhdl-max-marker
16376 generic-end-pos
16377 (vhdl-compose-insert-generic constant-entry)))
16378 (setq generic-pos (point-marker))
16379 (add-to-list 'written-list constant-name))
16381 (vhdl-goto-marker
16382 (vhdl-max-marker generic-inst-pos generic-pos))
16383 (setq generic-end-pos
16384 (vhdl-compose-insert-generic constant-entry))
16385 (setq generic-inst-pos (point-marker))
16386 (add-to-list 'written-list constant-name))))
16387 (setq constant-alist (cdr constant-alist)))
16388 (when (/= constant-temp-pos generic-inst-pos)
16389 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16390 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16391 (insert "-- generics for \"" inst-name "\"\n")
16392 (vhdl-goto-marker generic-inst-pos))
16393 ;; ports and signals
16394 (while signal-alist
16395 (setq signal-name (downcase (caar signal-alist))
16396 signal-entry (car signal-alist))
16397 (cond ((member signal-name written-list)
16398 nil)
16399 ((member signal-name multi-in-list)
16400 (vhdl-goto-marker port-in-pos)
16401 (setq port-end-pos
16402 (vhdl-max-marker
16403 port-end-pos (vhdl-compose-insert-port signal-entry)))
16404 (setq port-in-pos (point-marker))
16405 (add-to-list 'written-list signal-name))
16406 ((member signal-name multi-out-list)
16407 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16408 (setq port-end-pos
16409 (vhdl-max-marker
16410 port-end-pos (vhdl-compose-insert-port signal-entry)))
16411 (setq port-out-pos (point-marker))
16412 (add-to-list 'written-list signal-name))
16413 ((or (member signal-name single-in-list)
16414 (member signal-name single-out-list))
16415 (vhdl-goto-marker
16416 (vhdl-max-marker
16417 port-inst-pos
16418 (vhdl-max-marker port-out-pos port-in-pos)))
16419 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16420 (setq port-inst-pos (point-marker))
16421 (add-to-list 'written-list signal-name))
16422 ((equal (upcase (nth 2 signal-entry)) "OUT")
16423 (vhdl-goto-marker signal-pos)
16424 (vhdl-compose-insert-signal signal-entry)
16425 (setq signal-pos (point-marker))
16426 (add-to-list 'written-list signal-name)))
16427 (setq signal-alist (cdr signal-alist)))
16428 (when (/= port-temp-pos port-inst-pos)
16429 (vhdl-goto-marker
16430 (vhdl-max-marker port-temp-pos
16431 (vhdl-max-marker port-in-pos port-out-pos)))
16432 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16433 (insert "-- ports to \"" inst-name "\"\n")
16434 (vhdl-goto-marker port-inst-pos))
16435 (when (/= signal-temp-pos signal-pos)
16436 (vhdl-goto-marker signal-temp-pos)
16437 (insert "\n") (indent-to vhdl-basic-offset)
16438 (insert "-- outputs of \"" inst-name "\"\n")
16439 (vhdl-goto-marker signal-pos))
16440 (setq inst-alist (cdr inst-alist)))
16441 ;; finalize generic/port clause
16442 (vhdl-goto-marker generic-end-pos) (backward-char)
16443 (when (= generic-beg-pos generic-end-pos)
16444 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16445 (insert ";") (backward-char))
16446 (insert ")")
16447 (vhdl-goto-marker port-end-pos) (backward-char)
16448 (when (= port-beg-pos port-end-pos)
16449 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16450 (insert ";") (backward-char))
16451 (insert ")")
16452 ;; align everything
16453 (when vhdl-auto-align
16454 (vhdl-goto-marker generic-beg-pos)
16455 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16456 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16457 (vhdl-goto-marker signal-beg-pos)
16458 (vhdl-align-region-groups signal-beg-pos signal-pos))
16459 (switch-to-buffer (marker-buffer signal-beg-pos))
16460 (message "Wiring components...done")))))
16462 (defun vhdl-compose-insert-generic (entry)
16463 "Insert ENTRY as generic declaration."
16464 (let (pos)
16465 (indent-to (* 2 vhdl-basic-offset))
16466 (insert (nth 0 entry) " : " (nth 1 entry))
16467 (when (nth 2 entry)
16468 (insert " := " (nth 2 entry)))
16469 (insert ";")
16470 (setq pos (point-marker))
16471 (when (and vhdl-include-port-comments (nth 3 entry))
16472 (vhdl-comment-insert-inline (nth 3 entry) t))
16473 (insert "\n")
16474 pos))
16476 (defun vhdl-compose-insert-port (entry)
16477 "Insert ENTRY as port declaration."
16478 (let (pos)
16479 (indent-to (* 2 vhdl-basic-offset))
16480 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16481 (setq pos (point-marker))
16482 (when (and vhdl-include-port-comments (nth 4 entry))
16483 (vhdl-comment-insert-inline (nth 4 entry) t))
16484 (insert "\n")
16485 pos))
16487 (defun vhdl-compose-insert-signal (entry)
16488 "Insert ENTRY as signal declaration."
16489 (indent-to vhdl-basic-offset)
16490 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16491 (when (and vhdl-include-port-comments (nth 4 entry))
16492 (vhdl-comment-insert-inline (nth 4 entry) t))
16493 (insert "\n"))
16495 (defun vhdl-compose-components-package ()
16496 "Generate a package containing component declarations for all entities in the
16497 current project/directory."
16498 (interactive)
16499 (vhdl-require-hierarchy-info)
16500 (let* ((project (vhdl-project-p))
16501 (pack-name (vhdl-get-components-package-name))
16502 (pack-file-name
16503 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16504 "." (file-name-extension (buffer-file-name))))
16505 (ent-alist (vhdl-aget vhdl-entity-alist
16506 (or project
16507 (abbreviate-file-name default-directory))))
16508 (lazy-lock-minimum-size 0)
16509 clause-pos component-pos)
16510 (message "Generating components package \"%s\"..." pack-name)
16511 ;; open package file
16512 (when (and (file-exists-p pack-file-name)
16513 (not (y-or-n-p (concat "File \"" pack-file-name
16514 "\" exists; overwrite? "))))
16515 (error "ERROR: Generating components package...aborted"))
16516 (find-file pack-file-name)
16517 (erase-buffer)
16518 ;; insert header
16519 (if vhdl-compose-include-header
16520 (progn (vhdl-template-header
16521 (concat "Components package (generated by Emacs VHDL Mode "
16522 vhdl-version ")"))
16523 (goto-char (point-max)))
16524 (vhdl-comment-display-line) (insert "\n\n"))
16525 ;; insert std_logic_1164 package
16526 (vhdl-template-package-std-logic-1164)
16527 (insert "\n") (setq clause-pos (point-marker))
16528 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16529 ;; insert package declaration
16530 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16531 (vhdl-insert-keyword " IS\n\n")
16532 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16533 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16534 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16535 (indent-to vhdl-basic-offset)
16536 (setq component-pos (point-marker))
16537 (insert "\n\n") (vhdl-insert-keyword "END ")
16538 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16539 (insert pack-name ";\n\n")
16540 ;; insert footer
16541 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16542 (vhdl-template-footer)
16543 (vhdl-comment-display-line) (insert "\n"))
16544 ;; insert component declarations
16545 (while ent-alist
16546 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16547 (progn (goto-char (point-min))
16548 (forward-line (1- (nth 3 (car ent-alist))))
16549 (end-of-line)
16550 (vhdl-port-copy)))
16551 (goto-char component-pos)
16552 (vhdl-port-paste-component t)
16553 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16554 (setq component-pos (point-marker))
16555 (goto-char clause-pos)
16556 (vhdl-port-paste-context-clause pack-name)
16557 (setq clause-pos (point-marker))
16558 (setq ent-alist (cdr ent-alist)))
16559 (goto-char (point-min))
16560 (save-buffer)
16561 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16562 pack-name pack-file-name)))
16564 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16565 conf-alist inst-alist
16566 &optional insert-conf)
16567 "Generate block configuration for architecture."
16568 (let ((margin (current-indentation))
16569 (beg (point-at-bol))
16570 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16571 ;; insert block configuration (for architecture)
16572 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16573 (setq margin (+ margin vhdl-basic-offset))
16574 ;; process all instances
16575 (while inst-alist
16576 (setq inst-entry (car inst-alist))
16577 ;; is component?
16578 (when (nth 4 inst-entry)
16579 (setq insert-conf t)
16580 (setq inst-path (nth 9 inst-entry))
16581 ;; skip common path with previous instance
16582 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16583 (setq inst-path (cdr inst-path)
16584 inst-prev-path (cdr inst-prev-path)))
16585 ;; insert block configuration end (for previous block/generate)
16586 (while inst-prev-path
16587 (setq margin (- margin vhdl-basic-offset))
16588 (indent-to margin)
16589 (vhdl-insert-keyword "END FOR;\n")
16590 (setq inst-prev-path (cdr inst-prev-path)))
16591 ;; insert block configuration beginning (for current block/generate)
16592 (indent-to margin)
16593 (while inst-path
16594 (setq margin (+ margin vhdl-basic-offset))
16595 (vhdl-insert-keyword "FOR ")
16596 (insert (car inst-path) "\n")
16597 (indent-to margin)
16598 (setq inst-path (cdr inst-path)))
16599 ;; insert component configuration beginning
16600 (vhdl-insert-keyword "FOR ")
16601 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16602 ;; find subconfiguration
16603 (setq conf-key (nth 7 inst-entry))
16604 (setq tmp-alist conf-alist)
16605 ;; use first configuration found for instance's entity
16606 (while (and tmp-alist (null conf-key))
16607 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16608 (setq conf-key (nth 0 (car tmp-alist))))
16609 (setq tmp-alist (cdr tmp-alist)))
16610 (setq conf-entry (vhdl-aget conf-alist conf-key))
16611 ;; insert binding indication ...
16612 ;; ... with subconfiguration (if exists)
16613 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16614 (progn
16615 (indent-to (+ margin vhdl-basic-offset))
16616 (vhdl-insert-keyword "USE CONFIGURATION ")
16617 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16618 (insert ";\n"))
16619 ;; ... with entity (if exists)
16620 (setq ent-entry (vhdl-aget ent-alist (nth 5 inst-entry)))
16621 (when ent-entry
16622 (indent-to (+ margin vhdl-basic-offset))
16623 (vhdl-insert-keyword "USE ENTITY ")
16624 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16625 ;; insert architecture name (if architecture exists)
16626 (when (nth 3 ent-entry)
16627 (setq arch-name
16628 ;; choose architecture name a) from configuration,
16629 ;; b) from mra, or c) from first architecture
16630 (or (nth 0 (vhdl-aget (nth 3 ent-entry)
16631 (or (nth 6 inst-entry)
16632 (nth 4 ent-entry))))
16633 (nth 1 (car (nth 3 ent-entry)))))
16634 (insert "(" arch-name ")"))
16635 (insert ";\n")
16636 ;; insert block configuration (for architecture of subcomponent)
16637 (when (and vhdl-compose-configuration-hierarchical
16638 (nth 3 ent-entry))
16639 (indent-to (+ margin vhdl-basic-offset))
16640 (vhdl-compose-configuration-architecture
16641 (nth 0 ent-entry) arch-name ent-alist conf-alist
16642 (nth 3 (vhdl-aget (nth 3 ent-entry) (downcase arch-name)))))))
16643 ;; insert component configuration end
16644 (indent-to margin)
16645 (vhdl-insert-keyword "END FOR;\n")
16646 (setq inst-prev-path (nth 9 inst-entry)))
16647 (setq inst-alist (cdr inst-alist)))
16648 ;; insert block configuration end (for block/generate)
16649 (while inst-prev-path
16650 (setq margin (- margin vhdl-basic-offset))
16651 (indent-to margin)
16652 (vhdl-insert-keyword "END FOR;\n")
16653 (setq inst-prev-path (cdr inst-prev-path)))
16654 (indent-to (- margin vhdl-basic-offset))
16655 ;; insert block configuration end or remove beginning (for architecture)
16656 (if insert-conf
16657 (vhdl-insert-keyword "END FOR;\n")
16658 (delete-region beg (point)))))
16660 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16661 "Generate configuration declaration."
16662 (interactive)
16663 (vhdl-require-hierarchy-info)
16664 (let ((ent-alist (vhdl-aget vhdl-entity-alist
16665 (or (vhdl-project-p)
16666 (abbreviate-file-name default-directory))))
16667 (conf-alist (vhdl-aget vhdl-config-alist
16668 (or (vhdl-project-p)
16669 (abbreviate-file-name default-directory))))
16670 (from-speedbar ent-name)
16671 inst-alist conf-name conf-file-name pos)
16672 (vhdl-prepare-search-2
16673 ;; get entity and architecture name
16674 (unless ent-name
16675 (save-excursion
16676 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16677 (not (equal "END" (upcase (match-string 1))))
16678 (setq ent-name (match-string-no-properties 3))
16679 (setq arch-name (match-string-no-properties 2)))
16680 (error "ERROR: Not within an architecture"))))
16681 (setq conf-name (vhdl-replace-string
16682 vhdl-compose-configuration-name
16683 (concat ent-name " " arch-name)))
16684 (setq inst-alist
16685 (nth 3 (vhdl-aget (nth 3 (vhdl-aget ent-alist (downcase ent-name)))
16686 (downcase arch-name)))))
16687 (message "Generating configuration \"%s\"..." conf-name)
16688 (if vhdl-compose-configuration-create-file
16689 ;; open configuration file
16690 (progn
16691 (setq conf-file-name
16692 (concat (vhdl-replace-string vhdl-configuration-file-name
16693 conf-name t)
16694 "." (file-name-extension (buffer-file-name))))
16695 (when (and (file-exists-p conf-file-name)
16696 (not (y-or-n-p (concat "File \"" conf-file-name
16697 "\" exists; overwrite? "))))
16698 (error "ERROR: Creating configuration...aborted"))
16699 (find-file conf-file-name)
16700 (erase-buffer)
16701 (set-buffer-modified-p nil)
16702 ;; insert header
16703 (if vhdl-compose-include-header
16704 (progn (vhdl-template-header
16705 (concat "Configuration declaration for design \""
16706 ent-name "(" arch-name ")\""))
16707 (goto-char (point-max)))
16708 (vhdl-comment-display-line) (insert "\n\n")))
16709 ;; goto end of architecture
16710 (unless from-speedbar
16711 (re-search-forward "^end\\>" nil)
16712 (end-of-line) (insert "\n\n")
16713 (vhdl-comment-display-line) (insert "\n\n")))
16714 ;; insert library clause
16715 (setq pos (point))
16716 (vhdl-template-standard-package (vhdl-work-library) nil)
16717 (when (/= pos (point))
16718 (insert "\n\n"))
16719 ;; insert configuration
16720 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16721 (vhdl-insert-keyword " OF ") (insert ent-name)
16722 (vhdl-insert-keyword " IS\n")
16723 (indent-to vhdl-basic-offset)
16724 ;; insert block configuration (for architecture)
16725 (vhdl-compose-configuration-architecture
16726 ent-name arch-name ent-alist conf-alist inst-alist t)
16727 (vhdl-insert-keyword "END ") (insert conf-name ";")
16728 (when conf-file-name
16729 ;; insert footer and save
16730 (insert "\n\n")
16731 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16732 (vhdl-template-footer)
16733 (vhdl-comment-display-line) (insert "\n"))
16734 (save-buffer))
16735 (message "%s"
16736 (concat (format "Generating configuration \"%s\"...done" conf-name)
16737 (and conf-file-name
16738 (format "\n File created: \"%s\"" conf-file-name))))))
16741 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16742 ;;; Compilation / Makefile generation
16743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16744 ;; (using `compile.el')
16746 (defvar vhdl-compile-post-command ""
16747 "String appended to compile command after file name.")
16749 (defun vhdl-makefile-name ()
16750 "Return the Makefile name of the current project or the current compiler if
16751 no project is defined."
16752 (let ((project-alist (vhdl-aget vhdl-project-alist vhdl-project))
16753 (compiler-alist (vhdl-aget vhdl-compiler-alist vhdl-compiler)))
16754 (vhdl-replace-string
16755 (cons "\\(.*\\)\n\\(.*\\)"
16756 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16757 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16759 (defun vhdl-compile-directory ()
16760 "Return the directory where compilation/make should be run."
16761 (let* ((project (vhdl-aget vhdl-project-alist (vhdl-project-p t)))
16762 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
16763 (directory (vhdl-resolve-env-variable
16764 (if project
16765 (vhdl-replace-string
16766 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16767 (nth 6 compiler)))))
16768 (file-name-as-directory
16769 (if (file-name-absolute-p directory)
16770 directory
16771 (expand-file-name directory (vhdl-default-directory))))))
16773 (defun vhdl-uniquify (in-list)
16774 "Remove duplicate elements from IN-LIST."
16775 (let (out-list)
16776 (while in-list
16777 (add-to-list 'out-list (car in-list))
16778 (setq in-list (cdr in-list)))
16779 out-list))
16781 (defun vhdl-set-compiler (name)
16782 "Set current compiler to NAME."
16783 (interactive
16784 (list (let ((completion-ignore-case t))
16785 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16786 (if (assoc name vhdl-compiler-alist)
16787 (progn (setq vhdl-compiler name)
16788 (message "Current compiler: \"%s\"" vhdl-compiler))
16789 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16791 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16792 ;; Compilation
16794 (defun vhdl-compile-init ()
16795 "Initialize for compilation."
16796 (when (and (not vhdl-emacs-22)
16797 (or (null compilation-error-regexp-alist)
16798 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16799 compilation-error-regexp-alist))))
16800 ;; `compilation-error-regexp-alist'
16801 (let ((commands-alist vhdl-compiler-alist)
16802 regexp-alist sublist)
16803 (while commands-alist
16804 (setq sublist (nth 11 (car commands-alist)))
16805 (unless (or (equal "" (car sublist))
16806 (assoc (car sublist) regexp-alist))
16807 (push (list (nth 0 sublist)
16808 (if (and (featurep 'xemacs) (not (nth 1 sublist)))
16810 (nth 1 sublist))
16811 (nth 2 sublist) (nth 3 sublist))
16812 regexp-alist))
16813 (setq commands-alist (cdr commands-alist)))
16814 (setq compilation-error-regexp-alist
16815 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16816 ;; `compilation-file-regexp-alist'
16817 (let ((commands-alist vhdl-compiler-alist)
16818 regexp-alist sublist)
16819 ;; matches vhdl-mode file name output
16820 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16821 (while commands-alist
16822 (setq sublist (nth 12 (car commands-alist)))
16823 (unless (or (equal "" (car sublist))
16824 (assoc (car sublist) regexp-alist))
16825 (push sublist regexp-alist))
16826 (setq commands-alist (cdr commands-alist)))
16827 (setq compilation-file-regexp-alist
16828 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16830 (defvar vhdl-compile-file-name nil
16831 "Name of file to be compiled.")
16833 (defun vhdl-compile-print-file-name ()
16834 "Function called within `compile' to print out file name for compilers that
16835 do not print any file names."
16836 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16838 (defun vhdl-get-compile-options (project compiler file-name
16839 &optional file-options-only)
16840 "Get compiler options. Returning nil means do not compile this file."
16841 (let* ((compiler-options (nth 1 compiler))
16842 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
16843 (project-options (nth 0 project-entry))
16844 (exception-list (and file-name (nth 2 project-entry)))
16845 (work-library (vhdl-work-library))
16846 (case-fold-search nil)
16847 file-options)
16848 (while (and exception-list
16849 (not (string-match (caar exception-list) file-name)))
16850 (setq exception-list (cdr exception-list)))
16851 (if (and exception-list (not (cdar exception-list)))
16853 (if (and file-options-only (not exception-list))
16854 'default
16855 (setq file-options (cdar exception-list))
16856 ;; insert library name in compiler-specific options
16857 (setq compiler-options
16858 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16859 work-library))
16860 ;; insert compiler-specific options in project-specific options
16861 (when project-options
16862 (setq project-options
16863 (vhdl-replace-string
16864 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16865 (concat work-library "\n" compiler-options))))
16866 ;; insert project-specific options in file-specific options
16867 (when file-options
16868 (setq file-options
16869 (vhdl-replace-string
16870 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16871 (concat work-library "\n" compiler-options "\n"
16872 project-options))))
16873 ;; return options
16874 (or file-options project-options compiler-options)))))
16876 (defun vhdl-get-make-options (project compiler)
16877 "Get make options."
16878 (let* ((compiler-options (nth 3 compiler))
16879 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
16880 (project-options (nth 1 project-entry))
16881 (makefile-name (vhdl-makefile-name)))
16882 ;; insert Makefile name in compiler-specific options
16883 (setq compiler-options
16884 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16885 makefile-name))
16886 ;; insert compiler-specific options in project-specific options
16887 (when project-options
16888 (setq project-options
16889 (vhdl-replace-string
16890 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16891 (concat makefile-name "\n" compiler-options))))
16892 ;; return options
16893 (or project-options compiler-options)))
16895 (defun vhdl-compile ()
16896 "Compile current buffer using the VHDL compiler specified in
16897 `vhdl-compiler'."
16898 (interactive)
16899 (vhdl-compile-init)
16900 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
16901 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
16902 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16903 (command (nth 0 compiler))
16904 (default-directory (vhdl-compile-directory))
16905 (file-name (if vhdl-compile-absolute-path
16906 (buffer-file-name)
16907 (file-relative-name (buffer-file-name))))
16908 (options (vhdl-get-compile-options project compiler file-name))
16909 compilation-process-setup-function)
16910 (unless (file-directory-p default-directory)
16911 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16912 ;; put file name into quotes if it contains spaces
16913 (when (string-match " " file-name)
16914 (setq file-name (concat "\"" file-name "\"")))
16915 ;; print out file name if compiler does not
16916 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
16917 (buffer-file-name)
16918 (file-relative-name (buffer-file-name))))
16919 (when (and (= 0 (nth 1 (nth 10 compiler)))
16920 (= 0 (nth 1 (nth 11 compiler))))
16921 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16922 ;; run compilation
16923 (if options
16924 (when command
16925 (compile (concat command " " options " " file-name
16926 (unless (equal vhdl-compile-post-command "")
16927 (concat " " vhdl-compile-post-command)))))
16928 (vhdl-warning "Your project settings tell me not to compile this file"))))
16930 (defvar vhdl-make-target "all"
16931 "Default target for `vhdl-make' command.")
16933 (defun vhdl-make (&optional target)
16934 "Call make command for compilation of all updated source files (requires
16935 `Makefile'). Optional argument TARGET allows you to compile the design
16936 specified by a target."
16937 (interactive)
16938 (setq vhdl-make-target
16939 (or target (read-from-minibuffer "Target: " vhdl-make-target
16940 vhdl-minibuffer-local-map)))
16941 (vhdl-compile-init)
16942 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
16943 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
16944 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16945 (command (nth 2 compiler))
16946 (options (vhdl-get-make-options project compiler))
16947 (default-directory (vhdl-compile-directory)))
16948 (unless (file-directory-p default-directory)
16949 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16950 ;; run make
16951 (compile (concat (if (equal command "") "make" command)
16952 " " options " " vhdl-make-target))))
16954 ;; Emacs 22+ setup
16955 (defvar vhdl-error-regexp-emacs-alist
16956 ;; Get regexps from `vhdl-compiler-alist'
16957 (let ((compiler-alist vhdl-compiler-alist)
16958 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
16959 (while compiler-alist
16960 ;; only add regexps for currently selected compiler
16961 (when (or (not vhdl-compile-use-local-error-regexp)
16962 (equal vhdl-compiler (nth 0 (car compiler-alist))))
16963 ;; add error message regexps
16964 (setq error-regexp-alist
16965 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
16966 (nth 11 (car compiler-alist)))
16967 error-regexp-alist))
16968 ;; add filename regexps
16969 (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
16970 (setq error-regexp-alist
16971 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
16972 (nth 12 (car compiler-alist)))
16973 error-regexp-alist))))
16974 (setq compiler-alist (cdr compiler-alist)))
16975 error-regexp-alist)
16976 "List of regexps for VHDL compilers. For Emacs 22+.")
16978 ;; Add error regexps using compilation-mode-hook.
16979 (defun vhdl-error-regexp-add-emacs ()
16980 "Set up Emacs compile for VHDL."
16981 (interactive)
16982 (when (and (boundp 'compilation-error-regexp-alist-alist)
16983 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
16984 ;; remove all other compilers
16985 (when vhdl-compile-use-local-error-regexp
16986 (setq compilation-error-regexp-alist nil))
16987 ;; add VHDL compilers
16988 (mapcar
16989 (lambda (item)
16990 (push (car item) compilation-error-regexp-alist)
16991 (push item compilation-error-regexp-alist-alist))
16992 vhdl-error-regexp-emacs-alist)))
16994 (when vhdl-emacs-22
16995 (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
16997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16998 ;; Makefile generation
17000 (defun vhdl-generate-makefile ()
17001 "Generate `Makefile'."
17002 (interactive)
17003 (let* ((compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17004 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17005 (command (nth 4 compiler)))
17006 ;; generate makefile
17007 (if command
17008 (let ((default-directory (vhdl-compile-directory)))
17009 (compile (vhdl-replace-string
17010 (cons "\\(.*\\) \\(.*\\)" command)
17011 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
17012 (vhdl-generate-makefile-1))))
17014 (defun vhdl-get-packages (lib-alist work-library)
17015 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
17016 (let (pack-list)
17017 (while lib-alist
17018 (when (equal (downcase (caar lib-alist)) (downcase work-library))
17019 (push (cdar lib-alist) pack-list))
17020 (setq lib-alist (cdr lib-alist)))
17021 pack-list))
17023 (defun vhdl-generate-makefile-1 ()
17024 "Generate Makefile for current project or directory."
17025 ;; scan hierarchy if required
17026 (if (vhdl-project-p)
17027 (unless (or (assoc vhdl-project vhdl-file-alist)
17028 (vhdl-load-cache vhdl-project))
17029 (vhdl-scan-project-contents vhdl-project))
17030 (let ((directory (abbreviate-file-name default-directory)))
17031 (unless (or (assoc directory vhdl-file-alist)
17032 (vhdl-load-cache directory))
17033 (vhdl-scan-directory-contents directory))))
17034 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
17035 (project (vhdl-project-p))
17036 (ent-alist (vhdl-aget vhdl-entity-alist (or project directory)))
17037 (conf-alist (vhdl-aget vhdl-config-alist (or project directory)))
17038 (pack-alist (vhdl-aget vhdl-package-alist (or project directory)))
17039 (regexp-list (or (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17040 '("\\1.vhd" "\\2_\\1.vhd" "\\1.vhd"
17041 "\\1.vhd" "\\1_body.vhd" identity)))
17042 (mapping-exist
17043 (if (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler)) t nil))
17044 (ent-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 0 regexp-list)))
17045 (arch-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
17046 (conf-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 2 regexp-list)))
17047 (pack-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 3 regexp-list)))
17048 (pack-body-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 4 regexp-list)))
17049 (adjust-case (nth 5 regexp-list))
17050 (work-library (downcase (vhdl-work-library)))
17051 (compile-directory (expand-file-name (vhdl-compile-directory)
17052 default-directory))
17053 (makefile-name (vhdl-makefile-name))
17054 rule-alist arch-alist inst-alist
17055 target-list depend-list unit-list prim-list second-list subcomp-list
17056 lib-alist lib-body-alist pack-list all-pack-list
17057 ent-key ent-file-name arch-key arch-file-name ent-arch-key
17058 conf-key conf-file-name pack-key pack-file-name
17059 ent-entry arch-entry conf-entry pack-entry inst-entry
17060 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
17061 tmp-key tmp-list rule)
17062 ;; check prerequisites
17063 (unless (file-exists-p compile-directory)
17064 (make-directory compile-directory t))
17065 (unless mapping-exist
17066 (vhdl-warning
17067 (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\""
17068 vhdl-compiler vhdl-compiler) t))
17069 (message "Generating makefile \"%s\"..." makefile-name)
17070 ;; rules for all entities
17071 (setq tmp-list ent-alist)
17072 (while ent-alist
17073 (setq ent-entry (car ent-alist)
17074 ent-key (nth 0 ent-entry))
17075 (when (nth 2 ent-entry)
17076 (setq ent-file-name (if vhdl-compile-absolute-path
17077 (nth 2 ent-entry)
17078 (file-relative-name (nth 2 ent-entry)
17079 compile-directory))
17080 arch-alist (nth 4 ent-entry)
17081 lib-alist (nth 6 ent-entry)
17082 rule (vhdl-aget rule-alist ent-file-name)
17083 target-list (nth 0 rule)
17084 depend-list (nth 1 rule)
17085 second-list nil
17086 subcomp-list nil)
17087 (setq tmp-key (vhdl-replace-string
17088 ent-regexp
17089 (funcall adjust-case
17090 (concat ent-key " " work-library))))
17091 (push (cons ent-key tmp-key) unit-list)
17092 ;; rule target for this entity
17093 (push ent-key target-list)
17094 ;; rule dependencies for all used packages
17095 (setq pack-list (vhdl-get-packages lib-alist work-library))
17096 (setq depend-list (append depend-list pack-list))
17097 (setq all-pack-list pack-list)
17098 ;; add rule
17099 (vhdl-aput 'rule-alist ent-file-name (list target-list depend-list))
17100 ;; rules for all corresponding architectures
17101 (while arch-alist
17102 (setq arch-entry (car arch-alist)
17103 arch-key (nth 0 arch-entry)
17104 ent-arch-key (concat ent-key "-" arch-key)
17105 arch-file-name (if vhdl-compile-absolute-path
17106 (nth 2 arch-entry)
17107 (file-relative-name (nth 2 arch-entry)
17108 compile-directory))
17109 inst-alist (nth 4 arch-entry)
17110 lib-alist (nth 5 arch-entry)
17111 rule (vhdl-aget rule-alist arch-file-name)
17112 target-list (nth 0 rule)
17113 depend-list (nth 1 rule))
17114 (setq tmp-key (vhdl-replace-string
17115 arch-regexp
17116 (funcall adjust-case
17117 (concat arch-key " " ent-key " "
17118 work-library))))
17119 (setq unit-list
17120 (cons (cons ent-arch-key tmp-key) unit-list))
17121 (push ent-arch-key second-list)
17122 ;; rule target for this architecture
17123 (push ent-arch-key target-list)
17124 ;; rule dependency for corresponding entity
17125 (push ent-key depend-list)
17126 ;; rule dependencies for contained component instantiations
17127 (while inst-alist
17128 (setq inst-entry (car inst-alist))
17129 (when (or (null (nth 8 inst-entry))
17130 (equal (downcase (nth 8 inst-entry)) work-library))
17131 (setq inst-ent-key (or (nth 7 inst-entry)
17132 (nth 5 inst-entry)))
17133 (setq depend-list (cons inst-ent-key depend-list)
17134 subcomp-list (cons inst-ent-key subcomp-list)))
17135 (setq inst-alist (cdr inst-alist)))
17136 ;; rule dependencies for all used packages
17137 (setq pack-list (vhdl-get-packages lib-alist work-library))
17138 (setq depend-list (append depend-list pack-list))
17139 (setq all-pack-list (append all-pack-list pack-list))
17140 ;; add rule
17141 (vhdl-aput 'rule-alist arch-file-name (list target-list depend-list))
17142 (setq arch-alist (cdr arch-alist)))
17143 (push (list ent-key second-list (append subcomp-list all-pack-list))
17144 prim-list))
17145 (setq ent-alist (cdr ent-alist)))
17146 (setq ent-alist tmp-list)
17147 ;; rules for all configurations
17148 (setq tmp-list conf-alist)
17149 (while conf-alist
17150 (setq conf-entry (car conf-alist)
17151 conf-key (nth 0 conf-entry)
17152 conf-file-name (if vhdl-compile-absolute-path
17153 (nth 2 conf-entry)
17154 (file-relative-name (nth 2 conf-entry)
17155 compile-directory))
17156 ent-key (nth 4 conf-entry)
17157 arch-key (nth 5 conf-entry)
17158 inst-alist (nth 6 conf-entry)
17159 lib-alist (nth 7 conf-entry)
17160 rule (vhdl-aget rule-alist conf-file-name)
17161 target-list (nth 0 rule)
17162 depend-list (nth 1 rule)
17163 subcomp-list (list ent-key))
17164 (setq tmp-key (vhdl-replace-string
17165 conf-regexp
17166 (funcall adjust-case
17167 (concat conf-key " " work-library))))
17168 (push (cons conf-key tmp-key) unit-list)
17169 ;; rule target for this configuration
17170 (push conf-key target-list)
17171 ;; rule dependency for corresponding entity and architecture
17172 (setq depend-list
17173 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
17174 ;; rule dependencies for used packages
17175 (setq pack-list (vhdl-get-packages lib-alist work-library))
17176 (setq depend-list (append depend-list pack-list))
17177 ;; rule dependencies for contained component configurations
17178 (while inst-alist
17179 (setq inst-entry (car inst-alist))
17180 (setq inst-ent-key (nth 2 inst-entry)
17181 inst-conf-key (nth 4 inst-entry))
17182 (when (equal (downcase (nth 5 inst-entry)) work-library)
17183 (when inst-ent-key
17184 (setq depend-list (cons inst-ent-key depend-list)
17185 subcomp-list (cons inst-ent-key subcomp-list)))
17186 (when inst-conf-key
17187 (setq depend-list (cons inst-conf-key depend-list)
17188 subcomp-list (cons inst-conf-key subcomp-list))))
17189 (setq inst-alist (cdr inst-alist)))
17190 ;; add rule
17191 (vhdl-aput 'rule-alist conf-file-name (list target-list depend-list))
17192 (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
17193 (setq conf-alist (cdr conf-alist)))
17194 (setq conf-alist tmp-list)
17195 ;; rules for all packages
17196 (setq tmp-list pack-alist)
17197 (while pack-alist
17198 (setq pack-entry (car pack-alist)
17199 pack-key (nth 0 pack-entry)
17200 pack-body-key nil)
17201 (when (nth 2 pack-entry)
17202 (setq pack-file-name (if vhdl-compile-absolute-path
17203 (nth 2 pack-entry)
17204 (file-relative-name (nth 2 pack-entry)
17205 compile-directory))
17206 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
17207 rule (vhdl-aget rule-alist pack-file-name)
17208 target-list (nth 0 rule) depend-list (nth 1 rule))
17209 (setq tmp-key (vhdl-replace-string
17210 pack-regexp
17211 (funcall adjust-case
17212 (concat pack-key " " work-library))))
17213 (push (cons pack-key tmp-key) unit-list)
17214 ;; rule target for this package
17215 (push pack-key target-list)
17216 ;; rule dependencies for all used packages
17217 (setq pack-list (vhdl-get-packages lib-alist work-library))
17218 (setq depend-list (append depend-list pack-list))
17219 (setq all-pack-list pack-list)
17220 ;; add rule
17221 (vhdl-aput 'rule-alist pack-file-name (list target-list depend-list))
17222 ;; rules for this package's body
17223 (when (nth 7 pack-entry)
17224 (setq pack-body-key (concat pack-key "-body")
17225 pack-body-file-name (if vhdl-compile-absolute-path
17226 (nth 7 pack-entry)
17227 (file-relative-name (nth 7 pack-entry)
17228 compile-directory))
17229 rule (vhdl-aget rule-alist pack-body-file-name)
17230 target-list (nth 0 rule)
17231 depend-list (nth 1 rule))
17232 (setq tmp-key (vhdl-replace-string
17233 pack-body-regexp
17234 (funcall adjust-case
17235 (concat pack-key " " work-library))))
17236 (setq unit-list
17237 (cons (cons pack-body-key tmp-key) unit-list))
17238 ;; rule target for this package's body
17239 (push pack-body-key target-list)
17240 ;; rule dependency for corresponding package declaration
17241 (push pack-key depend-list)
17242 ;; rule dependencies for all used packages
17243 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
17244 (setq depend-list (append depend-list pack-list))
17245 (setq all-pack-list (append all-pack-list pack-list))
17246 ;; add rule
17247 (vhdl-aput 'rule-alist pack-body-file-name
17248 (list target-list depend-list)))
17249 (setq prim-list
17250 (cons (list pack-key (when pack-body-key (list pack-body-key))
17251 all-pack-list)
17252 prim-list)))
17253 (setq pack-alist (cdr pack-alist)))
17254 (setq pack-alist tmp-list)
17255 ;; generate Makefile
17256 (let* ((project (vhdl-aget vhdl-project-alist project))
17257 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17258 (compiler-id (nth 9 compiler))
17259 (library-directory
17260 (vhdl-resolve-env-variable
17261 (vhdl-replace-string
17262 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
17263 compiler-id)))
17264 (makefile-path-name (expand-file-name
17265 makefile-name compile-directory))
17266 (orig-buffer (current-buffer))
17267 cell second-list subcomp-list options unit-key unit-name)
17268 ;; sort lists
17269 (setq unit-list (vhdl-sort-alist unit-list))
17270 (setq prim-list (vhdl-sort-alist prim-list))
17271 (setq tmp-list rule-alist)
17272 (while tmp-list ; pre-sort rule targets
17273 (setq cell (cdar tmp-list))
17274 (setcar cell (sort (car cell) 'string<))
17275 (setq tmp-list (cdr tmp-list)))
17276 (setq rule-alist ; sort by first rule target
17277 (sort rule-alist
17278 (function (lambda (a b)
17279 (string< (car (cadr a)) (car (cadr b)))))))
17280 ;; open and clear Makefile
17281 (set-buffer (find-file-noselect makefile-path-name t t))
17282 (erase-buffer)
17283 (insert "# -*- Makefile -*-\n"
17284 "### " (file-name-nondirectory makefile-name)
17285 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17286 "\n")
17287 (if project
17288 (insert "\n# Project : " (nth 0 project))
17289 (insert "\n# Directory : \"" directory "\""))
17290 (insert "\n# Platform : " vhdl-compiler
17291 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17292 (user-login-name) "\n")
17293 ;; insert compile and option variable settings
17294 (insert "\n\n# Define compilation command and options\n"
17295 "\nCOMPILE = " (nth 0 compiler)
17296 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
17297 (if (equal vhdl-compile-post-command "") ""
17298 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
17299 "\n")
17300 ;; insert library paths
17301 (setq library-directory
17302 (directory-file-name
17303 (if (file-name-absolute-p library-directory)
17304 library-directory
17305 (file-relative-name
17306 (expand-file-name library-directory directory)
17307 compile-directory))))
17308 (insert "\n\n# Define library paths\n"
17309 "\nLIBRARY-" work-library " = " library-directory "\n")
17310 (unless mapping-exist
17311 (insert "LIBRARY-" work-library "-make = " "$(LIBRARY-" work-library
17312 ")/make" "\n"))
17313 ;; insert variable definitions for all library unit files
17314 (insert "\n\n# Define library unit files\n")
17315 (setq tmp-list unit-list)
17316 (while unit-list
17317 (insert "\nUNIT-" work-library "-" (caar unit-list)
17318 " = \\\n\t$(LIBRARY-" work-library
17319 (if mapping-exist "" "-make") ")/" (cdar unit-list))
17320 (setq unit-list (cdr unit-list)))
17321 ;; insert variable definition for list of all library unit files
17322 (insert "\n\n\n# Define list of all library unit files\n"
17323 "\nALL_UNITS =")
17324 (setq unit-list tmp-list)
17325 (while unit-list
17326 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17327 (setq unit-list (cdr unit-list)))
17328 (insert "\n")
17329 (setq unit-list tmp-list)
17330 ;; insert `make all' rule
17331 (insert "\n\n\n# Rule for compiling entire design\n"
17332 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17333 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17334 " \\\n\t\t$(ALL_UNITS)\n")
17335 ;; insert `make clean' rule
17336 (insert "\n\n# Rule for cleaning entire design\n"
17337 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17338 "\n\t-rm -f $(ALL_UNITS)\n")
17339 ;; insert `make library' rule
17340 (insert "\n\n# Rule for creating library directory\n"
17341 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17342 " \\\n\t\t$(LIBRARY-" work-library ")"
17343 (if mapping-exist ""
17344 (concat " \\\n\t\t$(LIBRARY-" work-library "-make)\n"))
17345 "\n"
17346 "\n$(LIBRARY-" work-library ") :"
17347 "\n\t"
17348 (vhdl-replace-string
17349 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17350 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17351 "\n")
17352 (unless mapping-exist
17353 (insert "\n$(LIBRARY-" work-library "-make) :"
17354 "\n\t"
17355 "mkdir -p $(LIBRARY-" work-library "-make)\n"))
17356 ;; insert '.PHONY' declaration
17357 (insert "\n\n.PHONY : "
17358 (nth 0 vhdl-makefile-default-targets) " "
17359 (nth 1 vhdl-makefile-default-targets) " "
17360 (nth 2 vhdl-makefile-default-targets) "\n")
17361 ;; insert rule for each library unit
17362 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17363 (while prim-list
17364 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17365 (setq subcomp-list
17366 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17367 (setq unit-key (caar prim-list)
17368 unit-name (or (nth 0 (vhdl-aget ent-alist unit-key))
17369 (nth 0 (vhdl-aget conf-alist unit-key))
17370 (nth 0 (vhdl-aget pack-alist unit-key))))
17371 (insert "\n" unit-key)
17372 (unless (equal unit-key unit-name)
17373 (insert " \\\n" unit-name))
17374 (insert " :"
17375 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
17376 (while subcomp-list
17377 (when (and (assoc (car subcomp-list) unit-list)
17378 (not (equal unit-key (car subcomp-list))))
17379 (insert " \\\n\t\t" (car subcomp-list)))
17380 (setq subcomp-list (cdr subcomp-list)))
17381 (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17382 (while second-list
17383 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17384 (setq second-list (cdr second-list)))
17385 (insert "\n")
17386 (setq prim-list (cdr prim-list)))
17387 ;; insert rule for each library unit file
17388 (insert "\n\n# Rules for compiling single library unit files\n")
17389 (while rule-alist
17390 (setq rule (car rule-alist))
17391 ;; get compiler options for this file
17392 (setq options
17393 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17394 ;; insert rule if file is supposed to be compiled
17395 (setq target-list (nth 1 rule)
17396 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17397 ;; insert targets
17398 (setq tmp-list target-list)
17399 (while target-list
17400 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17401 (if (cdr target-list) " \\" " :"))
17402 (setq target-list (cdr target-list)))
17403 (setq target-list tmp-list)
17404 ;; insert file name as first dependency
17405 (insert " \\\n\t\t" (nth 0 rule))
17406 ;; insert dependencies (except if also target or unit does not exist)
17407 (while depend-list
17408 (when (and (not (member (car depend-list) target-list))
17409 (assoc (car depend-list) unit-list))
17410 (insert " \\\n\t\t"
17411 "$(UNIT-" work-library "-" (car depend-list) ")"))
17412 (setq depend-list (cdr depend-list)))
17413 ;; insert compile command
17414 (if options
17415 (insert "\n\t$(COMPILE) "
17416 (if (eq options 'default) "$(OPTIONS)" options) " "
17417 (nth 0 rule)
17418 (if (equal vhdl-compile-post-command "") ""
17419 " $(POST-COMPILE)") "\n")
17420 (insert "\n"))
17421 (unless (and options mapping-exist)
17422 (setq tmp-list target-list)
17423 (while target-list
17424 (insert "\t@touch $(UNIT-" work-library "-" (car target-list) ")\n")
17425 (setq target-list (cdr target-list)))
17426 (setq target-list tmp-list))
17427 (setq rule-alist (cdr rule-alist)))
17429 (insert "\n\n### " makefile-name " ends here\n")
17430 ;; run Makefile generation hook
17431 (run-hooks 'vhdl-makefile-generation-hook)
17432 (message "Generating makefile \"%s\"...done" makefile-name)
17433 ;; save and close file
17434 (if (file-writable-p makefile-path-name)
17435 (progn (save-buffer)
17436 (kill-buffer (current-buffer))
17437 (set-buffer orig-buffer)
17438 (when (fboundp 'add-to-history)
17439 (add-to-history 'file-name-history makefile-path-name)))
17440 (vhdl-warning-when-idle
17441 (format "File not writable: \"%s\""
17442 (abbreviate-file-name makefile-path-name)))
17443 (switch-to-buffer (current-buffer))))))
17446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17447 ;;; Bug reports
17448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17449 ;; (using `reporter.el')
17451 (defconst vhdl-mode-help-address
17452 "Reto Zimmermann <reto@gnu.org>"
17453 "Address for VHDL Mode bug reports.")
17455 (defun vhdl-submit-bug-report ()
17456 "Submit via mail a bug report on VHDL Mode."
17457 (interactive)
17458 ;; load in reporter
17459 (and
17460 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17461 (let ((reporter-prompt-for-summary-p t))
17462 (reporter-submit-bug-report
17463 vhdl-mode-help-address
17464 (concat "VHDL Mode " vhdl-version)
17465 (list
17466 ;; report all important user options
17467 'vhdl-offsets-alist
17468 'vhdl-comment-only-line-offset
17469 'tab-width
17470 'vhdl-electric-mode
17471 'vhdl-stutter-mode
17472 'vhdl-indent-tabs-mode
17473 'vhdl-project-alist
17474 'vhdl-project
17475 'vhdl-project-file-name
17476 'vhdl-project-auto-load
17477 'vhdl-project-sort
17478 'vhdl-compiler-alist
17479 'vhdl-compiler
17480 'vhdl-compile-use-local-error-regexp
17481 'vhdl-makefile-default-targets
17482 'vhdl-makefile-generation-hook
17483 'vhdl-default-library
17484 'vhdl-standard
17485 'vhdl-basic-offset
17486 'vhdl-upper-case-keywords
17487 'vhdl-upper-case-types
17488 'vhdl-upper-case-attributes
17489 'vhdl-upper-case-enum-values
17490 'vhdl-upper-case-constants
17491 'vhdl-use-direct-instantiation
17492 'vhdl-array-index-record-field-in-sensitivity-list
17493 'vhdl-compose-configuration-name
17494 'vhdl-entity-file-name
17495 'vhdl-architecture-file-name
17496 'vhdl-configuration-file-name
17497 'vhdl-package-file-name
17498 'vhdl-file-name-case
17499 'vhdl-electric-keywords
17500 'vhdl-optional-labels
17501 'vhdl-insert-empty-lines
17502 'vhdl-argument-list-indent
17503 'vhdl-association-list-with-formals
17504 'vhdl-conditions-in-parenthesis
17505 'vhdl-zero-string
17506 'vhdl-one-string
17507 'vhdl-file-header
17508 'vhdl-file-footer
17509 'vhdl-company-name
17510 'vhdl-copyright-string
17511 'vhdl-platform-spec
17512 'vhdl-date-format
17513 'vhdl-modify-date-prefix-string
17514 'vhdl-modify-date-on-saving
17515 'vhdl-reset-kind
17516 'vhdl-reset-active-high
17517 'vhdl-clock-rising-edge
17518 'vhdl-clock-edge-condition
17519 'vhdl-clock-name
17520 'vhdl-reset-name
17521 'vhdl-model-alist
17522 'vhdl-include-port-comments
17523 'vhdl-include-direction-comments
17524 'vhdl-include-type-comments
17525 'vhdl-include-group-comments
17526 'vhdl-actual-generic-name
17527 'vhdl-actual-port-name
17528 'vhdl-instance-name
17529 'vhdl-testbench-entity-name
17530 'vhdl-testbench-architecture-name
17531 'vhdl-testbench-configuration-name
17532 'vhdl-testbench-dut-name
17533 'vhdl-testbench-include-header
17534 'vhdl-testbench-declarations
17535 'vhdl-testbench-statements
17536 'vhdl-testbench-initialize-signals
17537 'vhdl-testbench-include-library
17538 'vhdl-testbench-include-configuration
17539 'vhdl-testbench-create-files
17540 'vhdl-testbench-entity-file-name
17541 'vhdl-testbench-architecture-file-name
17542 'vhdl-compose-create-files
17543 'vhdl-compose-configuration-create-file
17544 'vhdl-compose-configuration-hierarchical
17545 'vhdl-compose-configuration-use-subconfiguration
17546 'vhdl-compose-include-header
17547 'vhdl-compose-architecture-name
17548 'vhdl-components-package-name
17549 'vhdl-use-components-package
17550 'vhdl-self-insert-comments
17551 'vhdl-prompt-for-comments
17552 'vhdl-inline-comment-column
17553 'vhdl-end-comment-column
17554 'vhdl-auto-align
17555 'vhdl-align-groups
17556 'vhdl-align-group-separate
17557 'vhdl-align-same-indent
17558 'vhdl-highlight-keywords
17559 'vhdl-highlight-names
17560 'vhdl-highlight-special-words
17561 'vhdl-highlight-forbidden-words
17562 'vhdl-highlight-verilog-keywords
17563 'vhdl-highlight-translate-off
17564 'vhdl-highlight-case-sensitive
17565 'vhdl-special-syntax-alist
17566 'vhdl-forbidden-words
17567 'vhdl-forbidden-syntax
17568 'vhdl-directive-keywords
17569 'vhdl-speedbar-auto-open
17570 'vhdl-speedbar-display-mode
17571 'vhdl-speedbar-scan-limit
17572 'vhdl-speedbar-jump-to-unit
17573 'vhdl-speedbar-update-on-saving
17574 'vhdl-speedbar-save-cache
17575 'vhdl-speedbar-cache-file-name
17576 'vhdl-index-menu
17577 'vhdl-source-file-menu
17578 'vhdl-hideshow-menu
17579 'vhdl-hide-all-init
17580 'vhdl-print-two-column
17581 'vhdl-print-customize-faces
17582 'vhdl-intelligent-tab
17583 'vhdl-indent-syntax-based
17584 'vhdl-indent-comment-like-next-code-line
17585 'vhdl-word-completion-case-sensitive
17586 'vhdl-word-completion-in-minibuffer
17587 'vhdl-underscore-is-part-of-word
17588 'vhdl-mode-hook)
17589 (function
17590 (lambda ()
17591 (insert
17592 (if vhdl-special-indent-hook
17593 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17594 "vhdl-special-indent-hook is set to '"
17595 (format "%s" vhdl-special-indent-hook)
17596 ".\nPerhaps this is your problem?\n"
17597 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17598 "\n"))))
17600 "Hi Reto,"))))
17603 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17604 ;;; Documentation
17605 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17607 (defconst vhdl-doc-release-notes nil
17609 Release Notes for VHDL Mode 3.34
17610 ================================
17612 - Added support for GNU Emacs 22/23/24:
17613 - Compilation error parsing fixed for new `compile.el' package.
17615 - Port translation: Derive actual generic name from formal generic name.
17617 - New user options:
17618 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17621 Release Notes for VHDL Mode 3.33
17622 ================================
17624 New Features
17625 ------------
17627 CONFIGURATION DECLARATION GENERATION:
17628 - Automatic generation of a configuration declaration for a design.
17629 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17632 Key Bindings
17633 ------------
17635 For Emacs compliance the following key bindings have been changed:
17637 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17638 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17639 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17640 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17643 User Options
17644 ------------
17646 `vhdl-configuration-file-name': (new)
17647 Specify how the configuration file name is obtained.
17648 `vhdl-compose-configuration-name': (new)
17649 Specify how the configuration name is obtained.
17650 `vhdl-compose-configuration-create-file': (new)
17651 Specify whether a new file should be created for a configuration.
17652 `vhdl-compose-configuration-hierarchical': (new)
17653 Specify whether hierarchical configurations should be created.
17654 `vhdl-compose-configuration-use-subconfiguration': (new)
17655 Specify whether subconfigurations should be used inside configurations.
17656 `vhdl-makefile-default-targets': (new)
17657 Customize names of Makefile default targets.
17658 `vhdl-indent-comment-like-next-code-line': (new)
17659 Specify whether comment lines are indented like following code line.
17660 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17661 Specify whether to include array indices / record fields in sensitivity list.
17665 (defconst vhdl-doc-keywords nil
17667 Reserved words in VHDL
17668 ----------------------
17670 VHDL'93/02 (IEEE Std 1076-1993/2002):
17671 `vhdl-02-keywords' : keywords
17672 `vhdl-02-types' : standardized types
17673 `vhdl-02-attributes' : standardized attributes
17674 `vhdl-02-enum-values' : standardized enumeration values
17675 `vhdl-02-functions' : standardized functions
17676 `vhdl-02-packages' : standardized packages and libraries
17678 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17679 `vhdl-ams-keywords' : keywords
17680 `vhdl-ams-types' : standardized types
17681 `vhdl-ams-attributes' : standardized attributes
17682 `vhdl-ams-enum-values' : standardized enumeration values
17683 `vhdl-ams-constants' : standardized constants
17684 `vhdl-ams-functions' : standardized functions
17686 Math Packages (IEEE Std 1076.2):
17687 `vhdl-math-types' : standardized types
17688 `vhdl-math-constants' : standardized constants
17689 `vhdl-math-functions' : standardized functions
17690 `vhdl-math-packages' : standardized packages
17692 Forbidden words:
17693 `vhdl-verilog-keywords' : Verilog reserved words
17695 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17698 (defconst vhdl-doc-coding-style nil
17700 For VHDL coding style and naming convention guidelines, see the following
17701 references:
17703 \[1] Ben Cohen.
17704 \"VHDL Coding Styles and Methodologies\".
17705 Kluwer Academic Publishers, 1999.
17706 http://members.aol.com/vhdlcohen/vhdl/
17708 \[2] Michael Keating and Pierre Bricaud.
17709 \"Reuse Methodology Manual, Second Edition\".
17710 Kluwer Academic Publishers, 1999.
17711 http://www.openmore.com/openmore/rmm2.html
17713 \[3] European Space Agency.
17714 \"VHDL Modelling Guidelines\".
17715 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17717 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17718 to visually support naming conventions.")
17721 (defun vhdl-version ()
17722 "Echo the current version of VHDL Mode in the minibuffer."
17723 (interactive)
17724 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17725 (vhdl-keep-region-active))
17727 (defun vhdl-doc-variable (variable)
17728 "Display VARIABLE's documentation in *Help* buffer."
17729 (interactive)
17730 (unless (featurep 'xemacs)
17731 (help-setup-xref (list #'vhdl-doc-variable variable)
17732 (called-interactively-p 'interactive)))
17733 (with-output-to-temp-buffer
17734 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17735 (princ (documentation-property variable 'variable-documentation))
17736 (with-current-buffer standard-output
17737 (help-mode))
17738 (help-print-return-message)))
17740 (defun vhdl-doc-mode ()
17741 "Display VHDL Mode documentation in *Help* buffer."
17742 (interactive)
17743 (unless (featurep 'xemacs)
17744 (help-setup-xref (list #'vhdl-doc-mode)
17745 (called-interactively-p 'interactive)))
17746 (with-output-to-temp-buffer
17747 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17748 (princ mode-name)
17749 (princ " mode:\n")
17750 (princ (documentation 'vhdl-mode))
17751 (with-current-buffer standard-output
17752 (help-mode))
17753 (help-print-return-message)))
17756 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17758 (provide 'vhdl-mode)
17760 ;;; vhdl-mode.el ends here