Merge from origin/emacs-24
[emacs.git] / lisp / progmodes / vhdl-mode.el
blob8d6d2a292938e420daf415aad55dad13a8705a17
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.37.1"
17 "VHDL Mode version number.")
19 (defconst vhdl-time-stamp "2015-01-15"
20 "VHDL Mode time stamp for last update.")
22 ;; This file is part of GNU Emacs.
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;; Commentary:
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;; This package provides an Emacs major mode for editing VHDL code.
42 ;; It includes the following features:
44 ;; - Syntax highlighting
45 ;; - Indentation
46 ;; - Template insertion (electrification)
47 ;; - Insertion of file headers
48 ;; - Insertion of user-specified models
49 ;; - Port translation / testbench generation
50 ;; - Structural composition
51 ;; - Configuration generation
52 ;; - Sensitivity list updating
53 ;; - File browser
54 ;; - Design hierarchy browser
55 ;; - Source file compilation (syntax analysis)
56 ;; - Makefile generation
57 ;; - Code hiding
58 ;; - Word/keyword completion
59 ;; - Block commenting
60 ;; - Code fixing/alignment/beautification
61 ;; - PostScript printing
62 ;; - VHDL'87/'93/'02/'08 and VHDL-AMS supported
63 ;; - Comprehensive menu
64 ;; - Fully customizable
65 ;; - Works under GNU Emacs (recommended) and XEmacs
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; Documentation
70 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; Emacs Versions
75 ;; this updated version was only tested on: GNU Emacs 24.1
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 ;; Installation
80 ;; Prerequisites: GNU Emacs 20/21/22/23/24, XEmacs 20/21.
82 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
83 ;; or into an arbitrary directory that is added to the load path by the
84 ;; following line in your Emacs start-up file `.emacs':
86 ;; (push (expand-file-name "<directory-name>") load-path)
88 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
89 ;; directory. Otherwise, byte-compile the source file:
90 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
91 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
93 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
94 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
95 ;; (not required in Emacs 20 and higher):
97 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
98 ;; (push '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist)
100 ;; More detailed installation instructions are included in the official
101 ;; VHDL Mode distribution.
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104 ;; Acknowledgments
106 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
107 ;; and Steve Grout.
109 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
110 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
112 ;; Many thanks to all the users who sent me bug reports and enhancement
113 ;; requests.
114 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
115 ;; enhancement suggestions and the fruitful discussions.
116 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
117 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
119 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
120 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
121 ;; giving me the opportunity to develop this code.
122 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
123 ;; of the Swiss Government.
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127 ;;; Code:
129 ;; Emacs 21+ handling
130 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
131 "Non-nil if GNU Emacs 21, 22, ... is used.")
132 ;; Emacs 22+ handling
133 (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
134 "Non-nil if GNU Emacs 22, ... is used.")
136 (defvar compilation-file-regexp-alist)
137 (defvar conf-alist)
138 (defvar conf-entry)
139 (defvar conf-key)
140 (defvar ent-alist)
141 (defvar itimer-version)
142 (defvar lazy-lock-defer-contextually)
143 (defvar lazy-lock-defer-on-scrolling)
144 (defvar lazy-lock-defer-on-the-fly)
145 (defvar speedbar-attached-frame)
148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149 ;;; Variables
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;; help function for user options
153 (defun vhdl-custom-set (variable value &rest functions)
154 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
155 (if (fboundp 'custom-set-default)
156 (custom-set-default variable value)
157 (set-default variable value))
158 (while functions
159 (when (fboundp (car functions)) (funcall (car functions)))
160 (setq functions (cdr functions))))
162 (defun vhdl-widget-directory-validate (widget)
163 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
164 '/' or is empty)."
165 (let ((val (widget-value widget)))
166 (unless (string-match "^\\(\\|.*/\\)$" val)
167 (widget-put widget :error "Invalid directory entry: must end with '/'")
168 widget)))
170 ;; help string for user options
171 (defconst vhdl-name-doc-string "
173 FROM REGEXP is a regular expression matching the original name:
174 \".*\" matches the entire string
175 \"\\(...\\)\" matches a substring
176 TO STRING specifies the string to be inserted as new name:
177 \"\\&\" means substitute entire matched text
178 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
179 Examples:
180 \".*\" \"\\&\" inserts original string
181 \".*\" \"\\&_i\" attaches \"_i\" to original string
182 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
183 \".*\" \"foo\" inserts constant string \"foo\"
184 \".*\" \"\" inserts empty string")
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ;; User variables (customization options)
189 (defgroup vhdl nil
190 "Customizations for VHDL Mode."
191 :prefix "vhdl-"
192 :group 'languages
193 ; :version "21.2" ; comment out for XEmacs
196 (defgroup vhdl-mode nil
197 "Customizations for modes."
198 :group 'vhdl)
200 (defcustom vhdl-indent-tabs-mode nil
201 "Non-nil means indentation can insert tabs.
202 Overrides local variable `indent-tabs-mode'."
203 :type 'boolean
204 :group 'vhdl-mode)
207 (defgroup vhdl-compile nil
208 "Customizations for compilation."
209 :group 'vhdl)
211 (defcustom vhdl-compiler-alist
213 ;; 60: docal <= false;
214 ;; ^^^^^
215 ;; [Error] Assignment error: variable is illegal target of signal assignment
216 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
217 nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
218 ("^\\s-+\\([0-9]+\\):\\s-+" nil 1 nil) ("^Compiling file \\(.+\\)" 1)
219 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
220 "PACK/\\1.vif" "BODY/\\1.vif" upcase))
221 ;; Aldec
222 ;; COMP96 ERROR COMP96_0018: "Identifier expected." "test.vhd" 66 3
223 ("Aldec" "vcom" "-work \\1" "make" "-f \\1"
224 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
225 ("^.* ERROR [^:]+: \".*\" \"\\([^ \t\n]+\\)\" \\([0-9]+\\) \\([0-9]+\\)" 1 2 3) ("" 0)
226 nil)
227 ;; Cadence Leapfrog: cv -file test.vhd
228 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
229 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
230 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
231 ("^duluth: \\*E,[0-9]+ (\\([^ \t\n]+\\),\\([0-9]+\\)):" 1 2 nil) ("" 0)
232 ("\\1/entity" "\\2/\\1" "\\1/configuration"
233 "\\1/package" "\\1/body" downcase))
234 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
235 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
236 ;; (PLL_400X_TOP) is not declared [10.3].
237 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
238 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
239 ("^ncvhdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
240 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
241 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
242 ;; ghdl vhdl
243 ;; ghdl -a bad_counter.vhdl
244 ;; bad_counter.vhdl:13:14: operator "=" is overloaded
245 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
246 nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
247 ("^ghdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
248 ("\\1/entity" "\\2/\\1" "\\1/configuration"
249 "\\1/package" "\\1/body" downcase))
250 ;; IBM Compiler
251 ;; 00 COACHDL* | [CCHDL-1]: File: adder.vhd, line.column: 120.6
252 ("IBM Compiler" "g2tvc" "-src" "precomp" "\\1"
253 nil "mkdir \\1" "./" "work/" "Makefile" "ibm"
254 ("^[0-9]+ COACHDL.*: File: \\([^ \t\n]+\\), *line.column: \\([0-9]+\\).\\([0-9]+\\)" 1 2 3) (" " 0)
255 nil)
256 ;; Ikos Voyager: analyze test.vhd
257 ;; analyze test.vhd
258 ;; E L4/C5: this library unit is inaccessible
259 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
260 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
261 ("^E L\\([0-9]+\\)/C\\([0-9]+\\):" nil 1 2)
262 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
263 nil)
264 ;; ModelSim, Model Technology: vcom test.vhd
265 ;; ERROR: test.vhd(14): Unknown identifier: positiv
266 ;; WARNING[2]: test.vhd(85): Possible infinite loop
267 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
268 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
269 ("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 VHDL'08 : IEEE Std 1076-2008
720 Additional standards:
721 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
722 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
724 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
725 \"Activate Options\"."
726 :type '(list (choice :tag "Basic standard"
727 (const :tag "VHDL'87" 87)
728 (const :tag "VHDL'93/02" 93)
729 (const :tag "VHDL'08" 08))
730 (set :tag "Additional standards" :indent 2
731 (const :tag "VHDL-AMS" ams)
732 (const :tag "Math packages" math)))
733 :set (lambda (variable value)
734 (vhdl-custom-set variable value
735 'vhdl-template-map-init
736 'vhdl-mode-abbrev-table-init
737 'vhdl-template-construct-alist-init
738 'vhdl-template-package-alist-init
739 'vhdl-update-mode-menu
740 'vhdl-words-init 'vhdl-font-lock-init))
741 :group 'vhdl-style)
743 (defcustom vhdl-basic-offset 2
744 "Amount of basic offset used for indentation.
745 This value is used by + and - symbols in `vhdl-offsets-alist'."
746 :type 'integer
747 :group 'vhdl-style)
749 (defcustom vhdl-upper-case-keywords nil
750 "Non-nil means convert keywords to upper case.
751 This is done when typed or expanded or by the fix case functions."
752 :type 'boolean
753 :set (lambda (variable value)
754 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
755 :group 'vhdl-style)
757 (defcustom vhdl-upper-case-types nil
758 "Non-nil means convert standardized types to upper case.
759 This is done when expanded or by the fix case functions."
760 :type 'boolean
761 :set (lambda (variable value)
762 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
763 :group 'vhdl-style)
765 (defcustom vhdl-upper-case-attributes nil
766 "Non-nil means convert standardized attributes to upper case.
767 This is done when expanded or by the fix case functions."
768 :type 'boolean
769 :set (lambda (variable value)
770 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
771 :group 'vhdl-style)
773 (defcustom vhdl-upper-case-enum-values nil
774 "Non-nil means convert standardized enumeration values to upper case.
775 This is done when expanded or by the fix case functions."
776 :type 'boolean
777 :set (lambda (variable value)
778 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
779 :group 'vhdl-style)
781 (defcustom vhdl-upper-case-constants t
782 "Non-nil means convert standardized constants to upper case.
783 This is done when expanded."
784 :type 'boolean
785 :set (lambda (variable value)
786 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
787 :group 'vhdl-style)
789 (defcustom vhdl-use-direct-instantiation 'standard
790 "Non-nil means use VHDL'93 direct component instantiation.
791 Never : never
792 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
793 Always : always"
794 :type '(choice (const :tag "Never" never)
795 (const :tag "Standard" standard)
796 (const :tag "Always" always))
797 :group 'vhdl-style)
799 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
800 "Non-nil means include array indices / record fields in sensitivity list.
801 If a signal read in a process is a record field or pointed to by an array
802 index, the record field or array index is included with the record name in
803 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
804 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
805 :type 'boolean
806 :version "24.3"
807 :group 'vhdl-style)
809 (defgroup vhdl-naming nil
810 "Customizations for naming conventions."
811 :group 'vhdl)
813 (defcustom vhdl-entity-file-name '(".*" . "\\&")
814 (concat
815 "Specifies how the entity file name is obtained.
816 The entity file name can be obtained by modifying the entity name (e.g.
817 attaching or stripping off a substring). The file extension is automatically
818 taken from the file name of the current buffer."
819 vhdl-name-doc-string)
820 :type '(cons (regexp :tag "From regexp")
821 (string :tag "To string "))
822 :group 'vhdl-naming
823 :group 'vhdl-compose)
825 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
826 (concat
827 "Specifies how the architecture file name is obtained.
828 The architecture file name can be obtained by modifying the entity
829 and/or architecture name (e.g. attaching or stripping off a substring). The
830 file extension is automatically taken from the file name of the current
831 buffer. The string that is matched against the regexp is the concatenation
832 of the entity and the architecture name separated by a space. This gives
833 access to both names (see default setting as example)."
834 vhdl-name-doc-string)
835 :type '(cons (regexp :tag "From regexp")
836 (string :tag "To string "))
837 :group 'vhdl-naming
838 :group 'vhdl-compose)
840 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
841 (concat
842 "Specifies how the configuration file name is obtained.
843 The configuration file name can be obtained by modifying the configuration
844 name (e.g. attaching or stripping off a substring). The file extension is
845 automatically taken from the file name of the current buffer."
846 vhdl-name-doc-string)
847 :type '(cons (regexp :tag "From regexp")
848 (string :tag "To string "))
849 :group 'vhdl-naming
850 :group 'vhdl-compose)
852 (defcustom vhdl-package-file-name '(".*" . "\\&")
853 (concat
854 "Specifies how the package file name is obtained.
855 The package file name can be obtained by modifying the package name (e.g.
856 attaching or stripping off a substring). The file extension is automatically
857 taken from the file name of the current buffer. Package files can be created
858 in a different directory by prepending a relative or absolute path to the
859 file name."
860 vhdl-name-doc-string)
861 :type '(cons (regexp :tag "From regexp")
862 (string :tag "To string "))
863 :group 'vhdl-naming
864 :group 'vhdl-compose)
866 (defcustom vhdl-file-name-case 'identity
867 "Specifies how to change case for obtaining file names.
868 When deriving a file name from a VHDL unit name, case can be changed as
869 follows:
870 As Is: case is not changed (taken as is)
871 Lower Case: whole name is changed to lower case
872 Upper Case: whole name is changed to upper case
873 Capitalize: first letter of each word in name is capitalized"
874 :type '(choice (const :tag "As Is" identity)
875 (const :tag "Lower Case" downcase)
876 (const :tag "Upper Case" upcase)
877 (const :tag "Capitalize" capitalize))
878 :group 'vhdl-naming
879 :group 'vhdl-compose)
882 (defgroup vhdl-template nil
883 "Customizations for electrification."
884 :group 'vhdl)
886 (defcustom vhdl-electric-keywords '(vhdl user)
887 "Type of keywords for which electrification is enabled.
888 VHDL keywords: invoke built-in templates
889 User keywords: invoke user models (see option `vhdl-model-alist')"
890 :type '(set (const :tag "VHDL keywords" vhdl)
891 (const :tag "User model keywords" user))
892 :set (lambda (variable value)
893 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
894 :group 'vhdl-template)
896 (defcustom vhdl-optional-labels 'process
897 "Constructs for which labels are to be queried.
898 Template generators prompt for optional labels for:
899 None : no constructs
900 Processes only: processes only (also procedurals in VHDL-AMS)
901 All constructs: all constructs with optional labels and keyword END"
902 :type '(choice (const :tag "None" none)
903 (const :tag "Processes only" process)
904 (const :tag "All constructs" all))
905 :group 'vhdl-template)
907 (defcustom vhdl-insert-empty-lines 'unit
908 "Specifies whether to insert empty lines in some templates.
909 This improves readability of code. Empty lines are inserted in:
910 None : no constructs
911 Design units only: entities, architectures, configurations, packages only
912 All constructs : also all constructs with BEGIN...END parts
914 Replaces option `vhdl-additional-empty-lines'."
915 :type '(choice (const :tag "None" none)
916 (const :tag "Design units only" unit)
917 (const :tag "All constructs" all))
918 :group 'vhdl-template
919 :group 'vhdl-port
920 :group 'vhdl-compose)
922 (defcustom vhdl-argument-list-indent nil
923 "Non-nil means indent argument lists relative to opening parenthesis.
924 That is, argument, association, and port lists start on the same line as the
925 opening parenthesis and subsequent lines are indented accordingly.
926 Otherwise, lists start on a new line and are indented as normal code."
927 :type 'boolean
928 :group 'vhdl-template
929 :group 'vhdl-port
930 :group 'vhdl-compose)
932 (defcustom vhdl-association-list-with-formals t
933 "Non-nil means write association lists with formal parameters.
934 Templates prompt for formal and actual parameters (ports/generics).
935 When pasting component instantiations, formals are included.
936 If nil, only a list of actual parameters is entered."
937 :type 'boolean
938 :group 'vhdl-template
939 :group 'vhdl-port
940 :group 'vhdl-compose)
942 (defcustom vhdl-conditions-in-parenthesis nil
943 "Non-nil means place parenthesis around condition expressions."
944 :type 'boolean
945 :group 'vhdl-template)
947 (defcustom vhdl-sensitivity-list-all t
948 "Non-nil means use 'all' keyword in sensitivity list."
949 :version "25.1"
950 :type 'boolean
951 :group 'vhdl-template)
953 (defcustom vhdl-zero-string "'0'"
954 "String to use for a logic zero."
955 :type 'string
956 :group 'vhdl-template)
958 (defcustom vhdl-one-string "'1'"
959 "String to use for a logic one."
960 :type 'string
961 :group 'vhdl-template)
964 (defgroup vhdl-header nil
965 "Customizations for file header."
966 :group 'vhdl-template
967 :group 'vhdl-compose)
969 (defcustom vhdl-file-header "\
970 -------------------------------------------------------------------------------
971 -- Title : <title string>
972 -- Project : <project>
973 -------------------------------------------------------------------------------
974 -- File : <filename>
975 -- Author : <author>
976 -- Company : <company>
977 -- Created : <date>
978 -- Last update: <date>
979 -- Platform : <platform>
980 -- Standard : <standard>
981 <projectdesc>-------------------------------------------------------------------------------
982 -- Description: <cursor>
983 <copyright>-------------------------------------------------------------------------------
984 -- Revisions :
985 -- Date Version Author Description
986 -- <date> 1.0 <login>\tCreated
987 -------------------------------------------------------------------------------
990 "String or file to insert as file header.
991 If the string specifies an existing file name, the contents of the file is
992 inserted, otherwise the string itself is inserted as file header.
993 Type `C-j' for newlines.
994 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
995 if the header needs to be version controlled.
997 The following keywords for template generation are supported:
998 <filename> : replaced by the name of the buffer
999 <author> : replaced by the user name and email address
1000 \(`user-full-name',`mail-host-address', `user-mail-address')
1001 <authorfull> : replaced by the user full name (`user-full-name')
1002 <login> : replaced by user login name (`user-login-name')
1003 <company> : replaced by contents of option `vhdl-company-name'
1004 <date> : replaced by the current date
1005 <year> : replaced by the current year
1006 <project> : replaced by title of current project (`vhdl-project')
1007 <projectdesc> : replaced by description of current project (`vhdl-project')
1008 <copyright> : replaced by copyright string (`vhdl-copyright-string')
1009 <platform> : replaced by contents of option `vhdl-platform-spec'
1010 <standard> : replaced by the VHDL language standard(s) used
1011 <... string> : replaced by a queried string (\"...\" is the prompt word)
1012 <title string>: replaced by file title in automatically generated files
1013 <cursor> : final cursor position
1015 The (multi-line) project description <projectdesc> can be used as a project
1016 dependent part of the file header and can also contain the above keywords."
1017 :type 'string
1018 :group 'vhdl-header)
1020 (defcustom vhdl-file-footer ""
1021 "String or file to insert as file footer.
1022 If the string specifies an existing file name, the contents of the file is
1023 inserted, otherwise the string itself is inserted as file footer (i.e. at
1024 the end of the file).
1025 Type `C-j' for newlines.
1026 The same keywords as in option `vhdl-file-header' can be used."
1027 :type 'string
1028 :group 'vhdl-header)
1030 (defcustom vhdl-company-name ""
1031 "Name of company to insert in file header.
1032 See option `vhdl-file-header'."
1033 :type 'string
1034 :group 'vhdl-header)
1036 (defcustom vhdl-copyright-string "\
1037 -------------------------------------------------------------------------------
1038 -- Copyright (c) <year> <company>
1040 "Copyright string to insert in file header.
1041 Can be multi-line string (type `C-j' for newline) and contain other file
1042 header keywords (see option `vhdl-file-header')."
1043 :type 'string
1044 :group 'vhdl-header)
1046 (defcustom vhdl-platform-spec ""
1047 "Specification of VHDL platform to insert in file header.
1048 The platform specification should contain names and versions of the
1049 simulation and synthesis tools used.
1050 See option `vhdl-file-header'."
1051 :type 'string
1052 :group 'vhdl-header)
1054 (defcustom vhdl-date-format "%Y-%m-%d"
1055 "Specifies the date format to use in the header.
1056 This string is passed as argument to the command `format-time-string'.
1057 For more information on format strings, see the documentation for the
1058 `format-time-string' command (C-h f `format-time-string')."
1059 :type 'string
1060 :group 'vhdl-header)
1062 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1063 "Prefix string of modification date in VHDL file header.
1064 If actualization of the modification date is called (menu,
1065 `\\[vhdl-template-modify]'), this string is searched and the rest
1066 of the line replaced by the current date."
1067 :type 'string
1068 :group 'vhdl-header)
1070 (defcustom vhdl-modify-date-on-saving t
1071 "Non-nil means update the modification date when the buffer is saved.
1072 Calls function `\\[vhdl-template-modify]').
1074 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1075 \"Activate Options\"."
1076 :type 'boolean
1077 :group 'vhdl-header)
1080 (defgroup vhdl-sequential-process nil
1081 "Customizations for sequential processes."
1082 :group 'vhdl-template)
1084 (defcustom vhdl-reset-kind 'async
1085 "Specifies which kind of reset to use in sequential processes."
1086 :type '(choice (const :tag "None" none)
1087 (const :tag "Synchronous" sync)
1088 (const :tag "Asynchronous" async)
1089 (const :tag "Query" query))
1090 :group 'vhdl-sequential-process)
1092 (defcustom vhdl-reset-active-high nil
1093 "Non-nil means reset in sequential processes is active high.
1094 Otherwise, reset is active low."
1095 :type 'boolean
1096 :group 'vhdl-sequential-process)
1098 (defcustom vhdl-clock-rising-edge t
1099 "Non-nil means rising edge of clock triggers sequential processes.
1100 Otherwise, falling edge triggers."
1101 :type 'boolean
1102 :group 'vhdl-sequential-process)
1104 (defcustom vhdl-clock-edge-condition 'standard
1105 "Syntax of the clock edge condition.
1106 Standard: \"clk'event and clk = '1'\"
1107 Function: \"rising_edge(clk)\""
1108 :type '(choice (const :tag "Standard" standard)
1109 (const :tag "Function" function))
1110 :group 'vhdl-sequential-process)
1112 (defcustom vhdl-clock-name ""
1113 "Name of clock signal to use in templates."
1114 :type 'string
1115 :group 'vhdl-sequential-process)
1117 (defcustom vhdl-reset-name ""
1118 "Name of reset signal to use in templates."
1119 :type 'string
1120 :group 'vhdl-sequential-process)
1123 (defgroup vhdl-model nil
1124 "Customizations for user models."
1125 :group 'vhdl)
1127 (defcustom vhdl-model-alist
1128 '(("Example Model"
1129 "<label> : process (<clock>, <reset>)
1130 begin -- process <label>
1131 if <reset> = '0' then -- asynchronous reset (active low)
1132 <cursor>
1133 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1134 if <enable> = '1' then -- synchronous load
1136 end if;
1137 end if;
1138 end process <label>;"
1139 "e" ""))
1140 "List of user models.
1141 VHDL models (templates) can be specified by the user in this list. They can be
1142 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1143 electrification (i.e. overriding existing or creating new keywords, see
1144 option `vhdl-electric-keywords').
1145 Name : name of model (string of words and spaces)
1146 String : string or name of file to be inserted as model (newline: `C-j')
1147 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1148 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1149 Keyword : keyword to invoke model
1151 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1152 A prompt that appears several times is queried once and replaced throughout
1153 the model. Special prompts are:
1154 <clock> : name specified in `vhdl-clock-name' (if not empty)
1155 <reset> : name specified in `vhdl-reset-name' (if not empty)
1156 <cursor>: final cursor position
1157 File header prompts (see variable `vhdl-file-header') are automatically
1158 replaced, so that user models can also be used to insert different types of
1159 headers.
1161 If the string specifies an existing file name, the contents of the file is
1162 inserted, otherwise the string itself is inserted.
1163 The code within the models should be correctly indented.
1164 Type `C-j' for newlines.
1166 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1167 \"Activate Options\"."
1168 :type '(repeat (list :tag "Model" :indent 2
1169 (string :tag "Name ")
1170 (string :tag "String : (type `C-j' for newline)"
1171 :format "%t\n%v")
1172 (sexp :tag "Key binding" x)
1173 (string :tag "Keyword " :format "%t: %v\n")))
1174 :set (lambda (variable value)
1175 (vhdl-custom-set variable value
1176 'vhdl-model-map-init
1177 'vhdl-model-defun
1178 'vhdl-mode-abbrev-table-init
1179 'vhdl-update-mode-menu))
1180 :group 'vhdl-model)
1183 (defgroup vhdl-compose nil
1184 "Customizations for structural composition."
1185 :group 'vhdl)
1187 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1188 (concat
1189 "Specifies how the component architecture name is obtained.
1190 The component architecture name can be obtained by modifying the entity name
1191 \(e.g. attaching or stripping off a substring).
1192 If TO STRING is empty, the architecture name is queried."
1193 vhdl-name-doc-string)
1194 :type '(cons (regexp :tag "From regexp")
1195 (string :tag "To string "))
1196 :group 'vhdl-compose)
1198 (defcustom vhdl-compose-configuration-name
1199 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1200 (concat
1201 "Specifies how the configuration name is obtained.
1202 The configuration name can be obtained by modifying the entity and/or
1203 architecture name (e.g. attaching or stripping off a substring). The string
1204 that is matched against the regexp is the concatenation of the entity and the
1205 architecture name separated by a space. This gives access to both names (see
1206 default setting as example)."
1207 vhdl-name-doc-string)
1208 :type '(cons (regexp :tag "From regexp")
1209 (string :tag "To string "))
1210 :group 'vhdl-compose)
1212 (defcustom vhdl-components-package-name
1213 '((".*" . "\\&_components") . "components")
1214 (concat
1215 "Specifies how the name for the components package is obtained.
1216 The components package is a package containing all component declarations for
1217 the current design. Its name can be obtained by modifying the project name
1218 \(e.g. attaching or stripping off a substring). If no project is defined, the
1219 DIRECTORY entry is chosen."
1220 vhdl-name-doc-string)
1221 :type '(cons (cons :tag "Project" :indent 2
1222 (regexp :tag "From regexp")
1223 (string :tag "To string "))
1224 (string :tag "Directory:\n String "))
1225 :group 'vhdl-compose)
1227 (defcustom vhdl-use-components-package nil
1228 "Non-nil means use a separate components package for component declarations.
1229 Otherwise, component declarations are inserted and searched for in the
1230 architecture declarative parts."
1231 :type 'boolean
1232 :group 'vhdl-compose)
1234 (defcustom vhdl-compose-include-header t
1235 "Non-nil means include a header in automatically generated files."
1236 :type 'boolean
1237 :group 'vhdl-compose)
1239 (defcustom vhdl-compose-create-files 'single
1240 "Specifies whether new files should be created for the new component.
1241 The component's entity and architecture are inserted:
1242 None : in current buffer
1243 Single file : in new single file
1244 Separate files: in two separate files
1245 The file names are obtained from variables `vhdl-entity-file-name' and
1246 `vhdl-architecture-file-name'."
1247 :type '(choice (const :tag "None" none)
1248 (const :tag "Single file" single)
1249 (const :tag "Separate files" separate))
1250 :group 'vhdl-compose)
1252 (defcustom vhdl-compose-configuration-create-file nil
1253 "Specifies whether a new file should be created for the configuration.
1254 If non-nil, a new file is created for the configuration.
1255 The file name is obtained from variable `vhdl-configuration-file-name'."
1256 :type 'boolean
1257 :group 'vhdl-compose)
1259 (defcustom vhdl-compose-configuration-hierarchical t
1260 "Specifies whether hierarchical configurations should be created.
1261 If non-nil, automatically created configurations are hierarchical and include
1262 the whole hierarchy of subcomponents. Otherwise the configuration only
1263 includes one level of subcomponents."
1264 :type 'boolean
1265 :group 'vhdl-compose)
1267 (defcustom vhdl-compose-configuration-use-subconfiguration t
1268 "Specifies whether subconfigurations should be used inside configurations.
1269 If non-nil, automatically created configurations use configurations in binding
1270 indications for subcomponents, if such configurations exist. Otherwise,
1271 entities are used in binding indications for subcomponents."
1272 :type 'boolean
1273 :group 'vhdl-compose)
1276 (defgroup vhdl-port nil
1277 "Customizations for port translation functions."
1278 :group 'vhdl
1279 :group 'vhdl-compose)
1281 (defcustom vhdl-include-port-comments nil
1282 "Non-nil means include port comments when a port is pasted."
1283 :type 'boolean
1284 :group 'vhdl-port)
1286 (defcustom vhdl-include-direction-comments nil
1287 "Non-nil means include port direction in instantiations as comments."
1288 :type 'boolean
1289 :group 'vhdl-port)
1291 (defcustom vhdl-include-type-comments nil
1292 "Non-nil means include generic/port type in instantiations as comments."
1293 :type 'boolean
1294 :group 'vhdl-port)
1296 (defcustom vhdl-include-group-comments 'never
1297 "Specifies whether to include group comments and spacings.
1298 The comments and empty lines between groups of ports are pasted:
1299 Never : never
1300 Declarations: in entity/component/constant/signal declarations only
1301 Always : also in generic/port maps"
1302 :type '(choice (const :tag "Never" never)
1303 (const :tag "Declarations" decl)
1304 (const :tag "Always" always))
1305 :group 'vhdl-port)
1307 (defcustom vhdl-actual-generic-name '(".*" . "\\&")
1308 (concat
1309 "Specifies how actual generic names are obtained from formal generic names.
1310 In a component instantiation, an actual generic name can be
1311 obtained by modifying the formal generic name (e.g. attaching or stripping
1312 off a substring)."
1313 vhdl-name-doc-string)
1314 :type '(cons (regexp :tag "From regexp")
1315 (string :tag "To string "))
1316 :group 'vhdl-port
1317 :version "24.4")
1319 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1320 (concat
1321 "Specifies how actual port names are obtained from formal port names.
1322 In a component instantiation, an actual port name can be obtained by
1323 modifying the formal port name (e.g. attaching or stripping off a substring)."
1324 vhdl-name-doc-string)
1325 :type '(cons (regexp :tag "From regexp")
1326 (string :tag "To string "))
1327 :group 'vhdl-port)
1329 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1330 (concat
1331 "Specifies how an instance name is obtained.
1332 The instance name can be obtained by modifying the name of the component to be
1333 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1334 by a unique number (starting with 1).
1335 If TO STRING is empty, the instance name is queried."
1336 vhdl-name-doc-string)
1337 :type '(cons (regexp :tag "From regexp")
1338 (string :tag "To string "))
1339 :group 'vhdl-port)
1342 (defgroup vhdl-testbench nil
1343 "Customizations for testbench generation."
1344 :group 'vhdl-port)
1346 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1347 (concat
1348 "Specifies how the testbench entity name is obtained.
1349 The entity name of a testbench can be obtained by modifying the name of
1350 the component to be tested (e.g. attaching or stripping off a substring)."
1351 vhdl-name-doc-string)
1352 :type '(cons (regexp :tag "From regexp")
1353 (string :tag "To string "))
1354 :group 'vhdl-testbench)
1356 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1357 (concat
1358 "Specifies how the testbench architecture name is obtained.
1359 The testbench architecture name can be obtained by modifying the name of
1360 the component to be tested (e.g. attaching or stripping off a substring).
1361 If TO STRING is empty, the architecture name is queried."
1362 vhdl-name-doc-string)
1363 :type '(cons (regexp :tag "From regexp")
1364 (string :tag "To string "))
1365 :group 'vhdl-testbench)
1367 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1368 (concat
1369 "Specifies how the testbench configuration name is obtained.
1370 The configuration name of a testbench can be obtained by modifying the entity
1371 and/or architecture name (e.g. attaching or stripping off a substring). The
1372 string that is matched against the regexp is the concatenation of the entity
1373 and the architecture name separated by a space. This gives access to both
1374 names (see default setting as example)."
1375 vhdl-name-doc-string)
1376 :type '(cons (regexp :tag "From regexp")
1377 (string :tag "To string "))
1378 :group 'vhdl-testbench)
1380 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1381 (concat
1382 "Specifies how a DUT instance name is obtained.
1383 The design-under-test instance name (i.e. the component instantiated in the
1384 testbench) can be obtained by modifying the component name (e.g. attaching
1385 or stripping off a substring)."
1386 vhdl-name-doc-string)
1387 :type '(cons (regexp :tag "From regexp")
1388 (string :tag "To string "))
1389 :group 'vhdl-testbench)
1391 (defcustom vhdl-testbench-include-header t
1392 "Non-nil means include a header in automatically generated files."
1393 :type 'boolean
1394 :group 'vhdl-testbench)
1396 (defcustom vhdl-testbench-declarations "\
1397 -- clock
1398 signal Clk : std_logic := '1';
1400 "String or file to be inserted in the testbench declarative part.
1401 If the string specifies an existing file name, the contents of the file is
1402 inserted, otherwise the string itself is inserted in the testbench
1403 architecture before the BEGIN keyword.
1404 Type `C-j' for newlines."
1405 :type 'string
1406 :group 'vhdl-testbench)
1408 (defcustom vhdl-testbench-statements "\
1409 -- clock generation
1410 Clk <= not Clk after 10 ns;
1412 -- waveform generation
1413 WaveGen_Proc: process
1414 begin
1415 -- insert signal assignments here
1417 wait until Clk = '1';
1418 end process WaveGen_Proc;
1420 "String or file to be inserted in the testbench statement part.
1421 If the string specifies an existing file name, the contents of the file is
1422 inserted, otherwise the string itself is inserted in the testbench
1423 architecture before the END keyword.
1424 Type `C-j' for newlines."
1425 :type 'string
1426 :group 'vhdl-testbench)
1428 (defcustom vhdl-testbench-initialize-signals nil
1429 "Non-nil means initialize signals with `0' when declared in testbench."
1430 :type 'boolean
1431 :group 'vhdl-testbench)
1433 (defcustom vhdl-testbench-include-library t
1434 "Non-nil means a library/use clause for std_logic_1164 is included."
1435 :type 'boolean
1436 :group 'vhdl-testbench)
1438 (defcustom vhdl-testbench-include-configuration t
1439 "Non-nil means a testbench configuration is attached at the end."
1440 :type 'boolean
1441 :group 'vhdl-testbench)
1443 (defcustom vhdl-testbench-create-files 'single
1444 "Specifies whether new files should be created for the testbench.
1445 testbench entity and architecture are inserted:
1446 None : in current buffer
1447 Single file : in new single file
1448 Separate files: in two separate files
1449 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1450 and `vhdl-testbench-architecture-file-name'."
1451 :type '(choice (const :tag "None" none)
1452 (const :tag "Single file" single)
1453 (const :tag "Separate files" separate))
1454 :group 'vhdl-testbench)
1456 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1457 (concat
1458 "Specifies how the testbench entity file name is obtained.
1459 The entity file name can be obtained by modifying the testbench entity name
1460 \(e.g. attaching or stripping off a substring). The file extension is
1461 automatically taken from the file name of the current buffer. Testbench
1462 files can be created in a different directory by prepending a relative or
1463 absolute path to the file name."
1464 vhdl-name-doc-string)
1465 :type '(cons (regexp :tag "From regexp")
1466 (string :tag "To string "))
1467 :group 'vhdl-testbench)
1469 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1470 (concat
1471 "Specifies how the testbench architecture file name is obtained.
1472 The architecture file name can be obtained by modifying the testbench entity
1473 and/or architecture name (e.g. attaching or stripping off a substring). The
1474 string that is matched against the regexp is the concatenation of the entity
1475 and the architecture name separated by a space. This gives access to both
1476 names (see default setting as example). Testbench files can be created in
1477 a different directory by prepending a relative or absolute path to the file
1478 name."
1479 vhdl-name-doc-string)
1480 :type '(cons (regexp :tag "From regexp")
1481 (string :tag "To string "))
1482 :group 'vhdl-testbench)
1485 (defgroup vhdl-comment nil
1486 "Customizations for comments."
1487 :group 'vhdl)
1489 (defcustom vhdl-self-insert-comments t
1490 "Non-nil means various templates automatically insert help comments."
1491 :type 'boolean
1492 :group 'vhdl-comment)
1494 (defcustom vhdl-prompt-for-comments t
1495 "Non-nil means various templates prompt for user definable comments."
1496 :type 'boolean
1497 :group 'vhdl-comment)
1499 (defcustom vhdl-inline-comment-column 40
1500 "Column to indent and align inline comments to.
1501 Overrides local option `comment-column'.
1503 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1504 \"Activate Options\"."
1505 :type 'integer
1506 :group 'vhdl-comment)
1508 (defcustom vhdl-end-comment-column 79
1509 "End of comment column.
1510 Comments that exceed this column number are wrapped.
1512 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1513 \"Activate Options\"."
1514 :type 'integer
1515 :group 'vhdl-comment)
1517 (defvar end-comment-column)
1520 (defgroup vhdl-beautify nil
1521 "Customizations for beautification."
1522 :group 'vhdl)
1524 (defcustom vhdl-auto-align t
1525 "Non-nil means align some templates automatically after generation."
1526 :type 'boolean
1527 :group 'vhdl-beautify)
1529 (defcustom vhdl-align-groups t
1530 "Non-nil means align groups of code lines separately.
1531 A group of code lines is a region of consecutive lines between two lines that
1532 match the regexp in option `vhdl-align-group-separate'."
1533 :type 'boolean
1534 :group 'vhdl-beautify)
1536 (defcustom vhdl-align-group-separate "^\\s-*$"
1537 "Regexp for matching a line that separates groups of lines for alignment.
1538 Examples:
1539 \"^\\s-*$\": matches an empty line
1540 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1541 :type 'regexp
1542 :group 'vhdl-beautify)
1544 (defcustom vhdl-align-same-indent t
1545 "Non-nil means align blocks with same indent separately.
1546 When a region or the entire buffer is aligned, the code is divided into
1547 blocks of same indent which are aligned separately (except for argument/port
1548 lists). This gives nicer alignment in most cases.
1549 Option `vhdl-align-groups' still applies within these blocks."
1550 :type 'boolean
1551 :group 'vhdl-beautify)
1553 (defcustom vhdl-beautify-options '(t t t t t)
1554 "List of options for beautifying code.
1555 Allows you to disable individual features of code beautification."
1556 :type '(list (boolean :tag "Whitespace cleanup ")
1557 (boolean :tag "Single statement per line")
1558 (boolean :tag "Indentation ")
1559 (boolean :tag "Alignment ")
1560 (boolean :tag "Case fixing "))
1561 :group 'vhdl-beautify
1562 :version "24.4")
1565 (defgroup vhdl-highlight nil
1566 "Customizations for highlighting."
1567 :group 'vhdl)
1569 (defcustom vhdl-highlight-keywords t
1570 "Non-nil means highlight VHDL keywords and other standardized words.
1571 The following faces are used:
1572 `font-lock-keyword-face' : keywords
1573 `font-lock-type-face' : standardized types
1574 `vhdl-font-lock-attribute-face': standardized attributes
1575 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1576 `vhdl-font-lock-function-face' : standardized function and package names
1578 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1579 entry \"Fontify Buffer\")."
1580 :type 'boolean
1581 :set (lambda (variable value)
1582 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1583 :group 'vhdl-highlight)
1585 (defcustom vhdl-highlight-names t
1586 "Non-nil means highlight declaration names and construct labels.
1587 The following faces are used:
1588 `font-lock-function-name-face' : names in declarations of units,
1589 subprograms, components, as well as labels of VHDL constructs
1590 `font-lock-type-face' : names in type/nature declarations
1591 `vhdl-font-lock-attribute-face': names in attribute declarations
1592 `font-lock-variable-name-face' : names in declarations of signals,
1593 variables, constants, subprogram parameters, generics, and ports
1595 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1596 entry \"Fontify Buffer\")."
1597 :type 'boolean
1598 :set (lambda (variable value)
1599 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1600 :group 'vhdl-highlight)
1602 (defcustom vhdl-highlight-special-words nil
1603 "Non-nil means highlight words with special syntax.
1604 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1605 are highlighted accordingly.
1606 Can be used for visual support of naming conventions.
1608 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1609 entry \"Fontify Buffer\")."
1610 :type 'boolean
1611 :set (lambda (variable value)
1612 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1613 :group 'vhdl-highlight)
1615 (defcustom vhdl-highlight-forbidden-words nil
1616 "Non-nil means highlight forbidden words.
1617 The reserved words specified in option `vhdl-forbidden-words' or having the
1618 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1619 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1620 use them.
1622 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1623 entry \"Fontify Buffer\")."
1624 :type 'boolean
1625 :set (lambda (variable value)
1626 (vhdl-custom-set variable value
1627 'vhdl-words-init 'vhdl-font-lock-init))
1628 :group 'vhdl-highlight)
1630 (defcustom vhdl-highlight-verilog-keywords nil
1631 "Non-nil means highlight Verilog keywords as reserved words.
1632 Verilog keywords are highlighted in a warning color (face
1633 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1635 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1636 entry \"Fontify Buffer\")."
1637 :type 'boolean
1638 :set (lambda (variable value)
1639 (vhdl-custom-set variable value
1640 'vhdl-words-init 'vhdl-font-lock-init))
1641 :group 'vhdl-highlight)
1643 (defcustom vhdl-highlight-translate-off nil
1644 "Non-nil means background-highlight code excluded from translation.
1645 That is, all code between \"-- pragma translate_off\" and
1646 \"-- pragma translate_on\" is highlighted using a different background color
1647 \(face `vhdl-font-lock-translate-off-face').
1648 Note: this might slow down on-the-fly fontification (and thus editing).
1650 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1651 entry \"Fontify Buffer\")."
1652 :type 'boolean
1653 :set (lambda (variable value)
1654 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1655 :group 'vhdl-highlight)
1657 (defcustom vhdl-highlight-case-sensitive nil
1658 "Non-nil means consider case for highlighting.
1659 Possible trade-off:
1660 non-nil also upper-case VHDL words are highlighted, but case of words with
1661 special syntax is not considered
1662 nil only lower-case VHDL words are highlighted, but case of words with
1663 special syntax is considered
1664 Overrides local option `font-lock-keywords-case-fold-search'.
1666 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1667 entry \"Fontify Buffer\")."
1668 :type 'boolean
1669 :group 'vhdl-highlight)
1671 (defcustom vhdl-special-syntax-alist
1672 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1673 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1674 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1675 "List of special syntax to be highlighted.
1676 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1677 syntax (as regular expression) are highlighted in the corresponding color.
1679 Name : string of words and spaces
1680 Regexp : regular expression describing word syntax
1681 (e.g. \"\\\\=\<\\\w+_c\\\\=\>\" matches word with suffix \"_c\")
1682 expression must start with \"\\\\=\<\" and end with \"\\\\=\>\"
1683 if only whole words should be matched (no substrings)
1684 Color (light): foreground color for light background
1685 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1686 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1687 Color (dark) : foreground color for dark background
1688 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1689 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1690 In comments : If non-nil, words are also highlighted inside comments
1692 Can be used for visual support of naming conventions, such as highlighting
1693 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1694 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1695 common substrings or name suffices.
1696 For each entry, a new face is generated with the specified colors and name
1697 \"vhdl-font-lock-\" + name + \"-face\".
1699 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1700 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1701 :type '(repeat (list :tag "Face" :indent 2
1702 (string :tag "Name ")
1703 (regexp :tag "Regexp " "\\w+_")
1704 (string :tag "Color (light)")
1705 (string :tag "Color (dark) ")
1706 (boolean :tag "In comments ")))
1707 :set (lambda (variable value)
1708 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1709 :group 'vhdl-highlight)
1711 (defcustom vhdl-forbidden-words '()
1712 "List of forbidden words to be highlighted.
1713 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1714 words are highlighted in a warning color to indicate not to use them.
1716 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1717 entry \"Fontify Buffer\")."
1718 :type '(repeat (string :format "%v"))
1719 :set (lambda (variable value)
1720 (vhdl-custom-set variable value
1721 'vhdl-words-init 'vhdl-font-lock-init))
1722 :group 'vhdl-highlight)
1724 (defcustom vhdl-forbidden-syntax ""
1725 "Syntax of forbidden words to be highlighted.
1726 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1727 syntax are highlighted in a warning color to indicate not to use them.
1728 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1729 highlights identifiers with 10 or more characters).
1731 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1732 entry \"Fontify Buffer\")."
1733 :type 'regexp
1734 :set (lambda (variable value)
1735 (vhdl-custom-set variable value
1736 'vhdl-words-init 'vhdl-font-lock-init))
1737 :group 'vhdl-highlight)
1739 (defcustom vhdl-directive-keywords '("psl" "pragma" "synopsys")
1740 "List of compiler directive keywords recognized for highlighting.
1742 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1743 entry \"Fontify Buffer\")."
1744 :type '(repeat (string :format "%v"))
1745 :set (lambda (variable value)
1746 (vhdl-custom-set variable value
1747 'vhdl-words-init 'vhdl-font-lock-init))
1748 :group 'vhdl-highlight)
1751 (defgroup vhdl-speedbar nil
1752 "Customizations for speedbar."
1753 :group 'vhdl)
1755 (defcustom vhdl-speedbar-auto-open nil
1756 "Non-nil means automatically open speedbar at startup.
1757 Alternatively, the speedbar can be opened from the VHDL menu."
1758 :type 'boolean
1759 :group 'vhdl-speedbar)
1761 (defcustom vhdl-speedbar-display-mode 'files
1762 "Specifies the default displaying mode when opening speedbar.
1763 Alternatively, the displaying mode can be selected from the speedbar menu or
1764 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1765 :type '(choice (const :tag "Files" files)
1766 (const :tag "Directory hierarchy" directory)
1767 (const :tag "Project hierarchy" project))
1768 :group 'vhdl-speedbar)
1770 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1771 "Limits scanning of large files and netlists.
1772 Design units: maximum file size to scan for design units
1773 Hierarchy (instances of subcomponents):
1774 File size: maximum file size to scan for instances (in bytes)
1775 Instances per arch: maximum number of instances to scan per architecture
1777 \"None\" always means that there is no limit.
1778 In case of files not or incompletely scanned, a warning message and the file
1779 names are printed out.
1780 Background: scanning for instances is considerably slower than scanning for
1781 design units, especially when there are many instances. These limits should
1782 prevent the scanning of large netlists."
1783 :type '(list (choice :tag "Design units"
1784 :format "%t : %[Value Menu%] %v"
1785 (const :tag "None" nil)
1786 (integer :tag "File size"))
1787 (list :tag "Hierarchy" :indent 2
1788 (choice :tag "File size"
1789 :format "%t : %[Value Menu%] %v"
1790 (const :tag "None" nil)
1791 (integer :tag "Size "))
1792 (choice :tag "Instances per arch"
1793 (const :tag "None" nil)
1794 (integer :tag "Number "))))
1795 :group 'vhdl-speedbar)
1797 (defcustom vhdl-speedbar-jump-to-unit t
1798 "Non-nil means jump to the design unit code when opened in a buffer.
1799 The buffer cursor position is left unchanged otherwise."
1800 :type 'boolean
1801 :group 'vhdl-speedbar)
1803 (defcustom vhdl-speedbar-update-on-saving t
1804 "Automatically update design hierarchy when buffer is saved."
1805 :type 'boolean
1806 :group 'vhdl-speedbar)
1808 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1809 "Automatically save modified hierarchy caches when exiting Emacs.
1810 Hierarchy: design hierarchy information
1811 Display: displaying information (which design units to expand)"
1812 :type '(set (const :tag "Hierarchy" hierarchy)
1813 (const :tag "Display" display))
1814 :group 'vhdl-speedbar)
1816 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1817 "Name of file for saving hierarchy cache.
1818 \"\\1\" is replaced by the project name if a project is specified,
1819 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1820 different users to have cache files in the same directory). Can also have
1821 an absolute path (i.e. all caches can be stored in one global directory)."
1822 :type 'string
1823 :group 'vhdl-speedbar)
1826 (defgroup vhdl-menu nil
1827 "Customizations for menus."
1828 :group 'vhdl)
1830 (defcustom vhdl-index-menu nil
1831 "Non-nil means add an index menu for a source file when loading.
1832 Alternatively, the speedbar can be used. Note that the index menu scans a file
1833 when it is opened, while speedbar only scans the file upon request."
1834 :type 'boolean
1835 :group 'vhdl-menu)
1837 (defcustom vhdl-source-file-menu nil
1838 "Non-nil means add a menu of all source files in current directory.
1839 Alternatively, the speedbar can be used."
1840 :type 'boolean
1841 :group 'vhdl-menu)
1843 (defcustom vhdl-hideshow-menu nil
1844 "Non-nil means add hideshow menu and functionality at startup.
1845 Hideshow can also be enabled from the VHDL Mode menu.
1846 Hideshow allows hiding code of various VHDL constructs.
1848 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1849 \"Activate Options\"."
1850 :type 'boolean
1851 :group 'vhdl-menu)
1853 (defcustom vhdl-hide-all-init nil
1854 "Non-nil means hide all design units initially after a file is loaded."
1855 :type 'boolean
1856 :group 'vhdl-menu)
1859 (defgroup vhdl-print nil
1860 "Customizations for printing."
1861 :group 'vhdl)
1863 (defcustom vhdl-print-two-column t
1864 "Non-nil means print code in two columns and landscape format.
1865 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1866 prints VHDL files in a nice two-column landscape style.
1868 NOTE: Activate the new setting by restarting Emacs.
1869 Overrides `ps-print' settings locally."
1870 :type 'boolean
1871 :group 'vhdl-print)
1873 (defcustom vhdl-print-customize-faces t
1874 "Non-nil means use an optimized set of faces for PostScript printing.
1876 NOTE: Activate the new setting by restarting Emacs.
1877 Overrides `ps-print' settings locally."
1878 :type 'boolean
1879 :group 'vhdl-print)
1882 (defgroup vhdl-misc nil
1883 "Miscellaneous customizations."
1884 :group 'vhdl)
1886 (defcustom vhdl-intelligent-tab t
1887 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1888 That is, if preceding character is part of a word then complete word,
1889 else if not at beginning of line then insert tab,
1890 else if last command was a `TAB' or `RET' then dedent one step,
1891 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1892 If nil, TAB always indents current line (i.e. `TAB' is bound to
1893 `indent-according-to-mode').
1895 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1896 \"Activate Options\"."
1897 :type 'boolean
1898 :group 'vhdl-misc)
1900 (defcustom vhdl-indent-syntax-based t
1901 "Non-nil means indent lines of code based on their syntactic context.
1902 Otherwise, a line is indented like the previous nonblank line. This can be
1903 useful in large files where syntax-based indentation gets very slow."
1904 :type 'boolean
1905 :group 'vhdl-misc)
1907 (defcustom vhdl-indent-comment-like-next-code-line t
1908 "Non-nil means comment lines are indented like the following code line.
1909 Otherwise, comment lines are indented like the preceding code line.
1910 Indenting comment lines like the following code line gives nicer indentation
1911 when comments precede the code that they refer to."
1912 :type 'boolean
1913 :version "24.3"
1914 :group 'vhdl-misc)
1916 (defcustom vhdl-word-completion-case-sensitive nil
1917 "Non-nil means word completion using `TAB' is case sensitive.
1918 That is, `TAB' completes words that start with the same letters and case.
1919 Otherwise, case is ignored."
1920 :type 'boolean
1921 :group 'vhdl-misc)
1923 (defcustom vhdl-word-completion-in-minibuffer t
1924 "Non-nil enables word completion in minibuffer (for template prompts).
1926 NOTE: Activate the new setting by restarting Emacs."
1927 :type 'boolean
1928 :group 'vhdl-misc)
1930 (defcustom vhdl-underscore-is-part-of-word nil
1931 "Non-nil means consider the underscore character `_' as part of word.
1932 An identifier containing underscores is then treated as a single word in
1933 select and move operations. All parts of an identifier separated by underscore
1934 are treated as single words otherwise."
1935 :type 'boolean
1936 :group 'vhdl-misc)
1937 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1938 'superword-mode "24.4")
1941 (defgroup vhdl-related nil
1942 "Related general customizations."
1943 :group 'vhdl)
1945 ;; add related general customizations
1946 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1947 (if (featurep 'xemacs)
1948 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1949 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1950 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1951 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1952 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1953 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1954 (unless (featurep 'xemacs)
1955 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1956 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1957 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1958 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1961 ;; Hidden user variables
1963 (defvar vhdl-compile-absolute-path nil
1964 "If non-nil, use absolute instead of relative path for compiled files.")
1966 (defvar vhdl-comment-display-line-char ?-
1967 "Character to use in comment display line.")
1969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1970 ;; Internal variables
1972 (defvar vhdl-menu-max-size 20
1973 "Specifies the maximum size of a menu before splitting it into submenus.")
1975 (defvar vhdl-progress-interval 1
1976 "Interval used to update progress status during long operations.
1977 If a number, percentage complete gets updated after each interval of
1978 that many seconds. To inhibit all messages, set this option to nil.")
1980 (defvar vhdl-inhibit-startup-warnings-p nil
1981 "If non-nil, inhibits start up compatibility warnings.")
1983 (defvar vhdl-strict-syntax-p nil
1984 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1985 If the syntactic symbol for a particular line does not match a symbol
1986 in the offsets alist, an error is generated, otherwise no error is
1987 reported and the syntactic symbol is ignored.")
1989 (defvar vhdl-echo-syntactic-information-p nil
1990 "If non-nil, syntactic info is echoed when the line is indented.")
1992 (defconst vhdl-offsets-alist-default
1993 '((string . -1000)
1994 (cpp-macro . -1000)
1995 (block-open . 0)
1996 (block-close . 0)
1997 (statement . 0)
1998 (statement-cont . vhdl-lineup-statement-cont)
1999 (statement-block-intro . +)
2000 (statement-case-intro . +)
2001 (case-alternative . +)
2002 (comment . vhdl-lineup-comment)
2003 (arglist-intro . +)
2004 (arglist-cont . 0)
2005 (arglist-cont-nonempty . vhdl-lineup-arglist)
2006 (arglist-close . vhdl-lineup-arglist)
2007 (entity . 0)
2008 (configuration . 0)
2009 (package . 0)
2010 (architecture . 0)
2011 (package-body . 0)
2012 (context . 0)
2013 (directive . 0)
2015 "Default settings for offsets of syntactic elements.
2016 Do not change this constant! See the variable `vhdl-offsets-alist' for
2017 more information.")
2019 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
2020 "Association list of syntactic element symbols and indentation offsets.
2021 As described below, each cons cell in this list has the form:
2023 (SYNTACTIC-SYMBOL . OFFSET)
2025 When a line is indented, `vhdl-mode' first determines the syntactic
2026 context of the line by generating a list of symbols called syntactic
2027 elements. This list can contain more than one syntactic element and
2028 the global variable `vhdl-syntactic-context' contains the context list
2029 for the line being indented. Each element in this list is actually a
2030 cons cell of the syntactic symbol and a buffer position. This buffer
2031 position is call the relative indent point for the line. Some
2032 syntactic symbols may not have a relative indent point associated with
2033 them.
2035 After the syntactic context list for a line is generated, `vhdl-mode'
2036 calculates the absolute indentation for the line by looking at each
2037 syntactic element in the list. First, it compares the syntactic
2038 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2039 finds a match, it adds the OFFSET to the column of the relative indent
2040 point. The sum of this calculation for each element in the syntactic
2041 list is the absolute offset for line being indented.
2043 If the syntactic element does not match any in the `vhdl-offsets-alist',
2044 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2045 the element is ignored.
2047 Actually, OFFSET can be an integer, a function, a variable, or one of
2048 the following symbols: `+', `-', `++', or `--'. These latter
2049 designate positive or negative multiples of `vhdl-basic-offset',
2050 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2051 called with a single argument containing the cons of the syntactic
2052 element symbol and the relative indent point. The function should
2053 return an integer offset.
2055 Here is the current list of valid syntactic element symbols:
2057 string -- inside multi-line string
2058 block-open -- statement block open
2059 block-close -- statement block close
2060 statement -- a VHDL statement
2061 statement-cont -- a continuation of a VHDL statement
2062 statement-block-intro -- the first line in a new statement block
2063 statement-case-intro -- the first line in a case alternative block
2064 case-alternative -- a case statement alternative clause
2065 comment -- a line containing only a comment
2066 arglist-intro -- the first line in an argument list
2067 arglist-cont -- subsequent argument list lines when no
2068 arguments follow on the same line as
2069 the arglist opening paren
2070 arglist-cont-nonempty -- subsequent argument list lines when at
2071 least one argument follows on the same
2072 line as the arglist opening paren
2073 arglist-close -- the solo close paren of an argument list
2074 entity -- inside an entity declaration
2075 configuration -- inside a configuration declaration
2076 package -- inside a package declaration
2077 architecture -- inside an architecture body
2078 package-body -- inside a package body
2079 context -- inside a context declaration")
2081 (defvar vhdl-comment-only-line-offset 0
2082 "Extra offset for line which contains only the start of a comment.
2083 Can contain an integer or a cons cell of the form:
2085 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2087 Where NON-ANCHORED-OFFSET is the amount of offset given to
2088 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2089 the amount of offset to give column-zero anchored comment-only lines.
2090 Just an integer as value is equivalent to (<val> . 0)")
2092 (defvar vhdl-special-indent-hook nil
2093 "Hook for user defined special indentation adjustments.
2094 This hook gets called after a line is indented by the mode.")
2096 (defvar vhdl-style-alist
2097 '(("IEEE"
2098 (vhdl-basic-offset . 4)
2099 (vhdl-offsets-alist . ())))
2100 "Styles of Indentation.
2101 Elements of this alist are of the form:
2103 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2105 where STYLE-STRING is a short descriptive string used to select a
2106 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2107 value for that variable when using the selected style.
2109 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2110 case, the VALUE is a list containing elements of the form:
2112 (SYNTACTIC-SYMBOL . VALUE)
2114 as described in `vhdl-offsets-alist'. These are passed directly to
2115 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2116 your style, only those that are different from the default.")
2118 ;; dynamically append the default value of most variables
2119 (or (assoc "Default" vhdl-style-alist)
2120 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2121 vhdl-strict-syntax-p
2122 vhdl-echo-syntactic-information-p
2123 vhdl-basic-offset
2124 vhdl-offsets-alist
2125 vhdl-comment-only-line-offset))
2126 (default (cons "Default"
2127 (mapcar
2128 (function
2129 (lambda (var)
2130 (cons var (symbol-value var))))
2131 varlist))))
2132 (push default vhdl-style-alist)))
2134 (defvar vhdl-mode-hook nil
2135 "Hook called by `vhdl-mode'.")
2138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2139 ;;; Required packages
2140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2142 ;; mandatory
2143 (require 'compile) ; XEmacs
2144 (require 'easymenu)
2145 (require 'hippie-exp)
2147 ;; optional (minimize warning messages during compile)
2148 (unless (featurep 'xemacs)
2149 (eval-when-compile
2150 (require 'font-lock)
2151 (require 'ps-print)
2152 (require 'speedbar))) ; for speedbar-with-writable
2154 (defun vhdl-aput (alist-symbol key &optional value)
2155 "Insert a key-value pair into an alist.
2156 The alist is referenced by ALIST-SYMBOL. The key-value pair is made
2157 from KEY and VALUE. If the key-value pair referenced by KEY can be
2158 found in the alist, the value of KEY will be set to VALUE. If the
2159 key-value pair cannot be found in the alist, it will be inserted into
2160 the head of the alist."
2161 (let* ((alist (symbol-value alist-symbol))
2162 (elem (assoc key alist)))
2163 (if elem
2164 (setcdr elem value)
2165 (set alist-symbol (cons (cons key value) alist)))))
2167 (defun vhdl-adelete (alist-symbol key)
2168 "Delete a key-value pair from the alist.
2169 Alist is referenced by ALIST-SYMBOL and the key-value pair to remove
2170 is pair matching KEY."
2171 (let ((alist (symbol-value alist-symbol)) alist-cdr)
2172 (while (equal key (caar alist))
2173 (setq alist (cdr alist))
2174 (set alist-symbol alist))
2175 (while (setq alist-cdr (cdr alist))
2176 (if (equal key (caar alist-cdr))
2177 (setcdr alist (cdr alist-cdr))
2178 (setq alist alist-cdr)))))
2180 (defun vhdl-aget (alist key)
2181 "Return the value in ALIST that is associated with KEY. If KEY is
2182 not found, then nil is returned."
2183 (cdr (assoc key alist)))
2185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2186 ;;; Compatibility
2187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2190 ;; XEmacs compatibility
2192 ;; active regions
2193 (defun vhdl-keep-region-active ()
2194 "Do whatever is necessary to keep the region active in XEmacs.
2195 Ignore byte-compiler warnings you might see."
2196 (and (featurep 'xemacs)
2197 (setq zmacs-region-stays t)))
2199 ;; `wildcard-to-regexp' is included only in XEmacs 21
2200 (unless (fboundp 'wildcard-to-regexp)
2201 (defun wildcard-to-regexp (wildcard)
2202 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2203 (let* ((i (string-match "[*?]" wildcard))
2204 (result (substring wildcard 0 i))
2205 (len (length wildcard)))
2206 (when i
2207 (while (< i len)
2208 (let ((ch (aref wildcard i)))
2209 (setq result (concat result
2210 (cond ((eq ch ?*) "[^\000]*")
2211 ((eq ch ??) "[^\000]")
2212 (t (char-to-string ch)))))
2213 (setq i (1+ i)))))
2214 (concat "\\`" result "\\'"))))
2216 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2217 ;; `regexp-opt' accelerates fontification by 10-20%
2218 (unless (fboundp 'regexp-opt)
2219 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2220 (defun regexp-opt (strings &optional paren)
2221 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2222 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2224 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2225 (unless (fboundp 'match-string-no-properties)
2226 (defalias 'match-string-no-properties 'match-string))
2228 ;; `subst-char-in-string' undefined (XEmacs)
2229 (unless (fboundp 'subst-char-in-string)
2230 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2231 (let ((i (length string))
2232 (newstr (if inplace string (copy-sequence string))))
2233 (while (> i 0)
2234 (setq i (1- i))
2235 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2236 newstr)))
2238 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2239 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2240 (not noninteractive))
2241 (load "itimer")
2242 (when (string< itimer-version "1.09")
2243 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2244 (beep) (sit-for 5)))
2246 ;; `file-expand-wildcards' undefined (XEmacs)
2247 (unless (fboundp 'file-expand-wildcards)
2248 (defun file-expand-wildcards (pattern &optional full)
2249 "Taken from Emacs's `files.el'."
2250 (let* ((nondir (file-name-nondirectory pattern))
2251 (dirpart (file-name-directory pattern))
2252 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2253 (mapcar 'file-name-as-directory
2254 (file-expand-wildcards (directory-file-name dirpart)))
2255 (list dirpart)))
2256 contents)
2257 (while dirs
2258 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2259 (file-directory-p (directory-file-name (car dirs))))
2260 (let ((this-dir-contents
2261 (delq nil
2262 (mapcar #'(lambda (name)
2263 (unless (string-match "\\`\\.\\.?\\'"
2264 (file-name-nondirectory name))
2265 name))
2266 (directory-files (or (car dirs) ".") full
2267 (wildcard-to-regexp nondir))))))
2268 (setq contents
2269 (nconc
2270 (if (and (car dirs) (not full))
2271 (mapcar (function (lambda (name) (concat (car dirs) name)))
2272 this-dir-contents)
2273 this-dir-contents)
2274 contents))))
2275 (setq dirs (cdr dirs)))
2276 contents)))
2278 ;; `member-ignore-case' undefined (XEmacs)
2279 (unless (fboundp 'member-ignore-case)
2280 (defalias 'member-ignore-case 'member))
2282 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2283 ;; behavior in XEmacs
2284 (defvar vhdl-last-input-event)
2285 (if (featurep 'xemacs)
2286 (defvaralias 'vhdl-last-input-event 'last-input-char)
2287 (defvaralias 'vhdl-last-input-event 'last-input-event))
2289 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2290 ;;;(unless (fboundp 'help-print-return-message)
2291 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2294 ;; Compatibility with older VHDL Mode versions
2296 (defvar vhdl-warnings nil
2297 "Warnings to tell the user during start up.")
2299 (defun vhdl-run-when-idle (secs repeat function)
2300 "Wait until idle, then run FUNCTION."
2301 (if (fboundp 'start-itimer)
2302 (start-itimer "vhdl-mode" function secs repeat t)
2303 ;; explicitly activate timer (necessary when Emacs is already idle)
2304 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2306 (defun vhdl-warning-when-idle (&rest args)
2307 "Wait until idle, then print out warning STRING and beep."
2308 (if noninteractive
2309 (vhdl-warning (apply 'format args) t)
2310 (unless vhdl-warnings
2311 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2312 (push (apply 'format args) vhdl-warnings)))
2314 (defun vhdl-warning (string &optional nobeep)
2315 "Print out warning STRING and beep."
2316 (message "WARNING: %s" string)
2317 (unless (or nobeep noninteractive) (beep)))
2319 (defun vhdl-print-warnings ()
2320 "Print out messages in variable `vhdl-warnings'."
2321 (let ((no-warnings (length vhdl-warnings)))
2322 (setq vhdl-warnings (nreverse vhdl-warnings))
2323 (while vhdl-warnings
2324 (message "WARNING: %s" (car vhdl-warnings))
2325 (setq vhdl-warnings (cdr vhdl-warnings)))
2326 (beep)
2327 (when (> no-warnings 1)
2328 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2330 ;; Backward compatibility checks and fixes
2331 ;; option `vhdl-compiler' changed format
2332 (unless (stringp vhdl-compiler)
2333 (setq vhdl-compiler "ModelSim")
2334 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2336 ;; option `vhdl-standard' changed format
2337 (unless (listp vhdl-standard)
2338 (setq vhdl-standard '(87 nil))
2339 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2341 ;; option `vhdl-model-alist' changed format
2342 (when (= (length (car vhdl-model-alist)) 3)
2343 (let ((old-alist vhdl-model-alist)
2344 new-alist)
2345 (while old-alist
2346 (push (append (car old-alist) '("")) new-alist)
2347 (setq old-alist (cdr old-alist)))
2348 (setq vhdl-model-alist (nreverse new-alist)))
2349 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2351 ;; option `vhdl-project-alist' changed format
2352 (when (= (length (car vhdl-project-alist)) 3)
2353 (let ((old-alist vhdl-project-alist)
2354 new-alist)
2355 (while old-alist
2356 (push (append (car old-alist) '("")) new-alist)
2357 (setq old-alist (cdr old-alist)))
2358 (setq vhdl-project-alist (nreverse new-alist)))
2359 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2361 ;; option `vhdl-project-alist' changed format (3.31.1)
2362 (when (= (length (car vhdl-project-alist)) 4)
2363 (let ((old-alist vhdl-project-alist)
2364 new-alist elem)
2365 (while old-alist
2366 (setq elem (car old-alist))
2367 (setq new-alist
2368 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2369 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2370 new-alist))
2371 (setq old-alist (cdr old-alist)))
2372 (setq vhdl-project-alist (nreverse new-alist)))
2373 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2375 ;; option `vhdl-project-alist' changed format (3.31.12)
2376 (when (= (length (car vhdl-project-alist)) 10)
2377 (let ((tmp-alist vhdl-project-alist))
2378 (while tmp-alist
2379 (setcdr (nthcdr 3 (car tmp-alist))
2380 (cons "" (nthcdr 4 (car tmp-alist))))
2381 (setq tmp-alist (cdr tmp-alist))))
2382 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2384 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2385 (when (= (length (car vhdl-compiler-alist)) 7)
2386 (let ((old-alist vhdl-compiler-alist)
2387 new-alist elem)
2388 (while old-alist
2389 (setq elem (car old-alist))
2390 (setq new-alist
2391 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2392 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2393 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2394 (nth 5 elem) (nth 6 elem) nil)
2395 new-alist))
2396 (setq old-alist (cdr old-alist)))
2397 (setq vhdl-compiler-alist (nreverse new-alist)))
2398 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2400 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2401 (when (= (length (car vhdl-compiler-alist)) 12)
2402 (let ((tmp-alist vhdl-compiler-alist))
2403 (while tmp-alist
2404 (setcdr (nthcdr 4 (car tmp-alist))
2405 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2406 (setq tmp-alist (cdr tmp-alist))))
2407 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2409 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2410 (when (= (length (car vhdl-compiler-alist)) 13)
2411 (let ((tmp-alist vhdl-compiler-alist))
2412 (while tmp-alist
2413 (setcdr (nthcdr 3 (car tmp-alist))
2414 (cons "" (nthcdr 4 (car tmp-alist))))
2415 (setq tmp-alist (cdr tmp-alist))))
2416 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2418 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2419 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2420 (let ((tmp-alist vhdl-compiler-alist))
2421 (while tmp-alist
2422 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2423 '(0 . nil))
2424 (setq tmp-alist (cdr tmp-alist))))
2425 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2427 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2428 (when (equal vhdl-project "")
2429 (setq vhdl-project nil)
2430 (customize-save-variable 'vhdl-project vhdl-project))
2432 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2433 (when (stringp vhdl-project-file-name)
2434 (setq vhdl-project-file-name (list vhdl-project-file-name))
2435 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2437 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2438 (if (not (boundp 'speedbar-indentation-width))
2439 (defvar speedbar-indentation-width 2)
2440 ;; set default to 2 if not already customized
2441 (unless (get 'speedbar-indentation-width 'saved-value)
2442 (setq speedbar-indentation-width 2)))
2444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2445 ;;; Help functions / inline substitutions / macros
2446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2448 (defun vhdl-standard-p (standard)
2449 "Check if STANDARD is specified as used standard."
2450 (or (eq standard (car vhdl-standard))
2451 (memq standard (cadr vhdl-standard))))
2453 (defun vhdl-project-p (&optional warning)
2454 "Return non-nil if a project is displayed, i.e. directories or files are
2455 specified."
2456 (if (assoc vhdl-project vhdl-project-alist)
2457 vhdl-project
2458 (when (and vhdl-project warning)
2459 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2460 nil))
2462 (defun vhdl-resolve-env-variable (string)
2463 "Resolve environment variables in STRING."
2464 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2465 (setq string (concat (match-string 1 string)
2466 (getenv (match-string 2 string))
2467 (match-string 4 string))))
2468 string)
2470 (defun vhdl-default-directory ()
2471 "Return the default directory of the current project or the directory of the
2472 current buffer if no project is defined."
2473 (if (vhdl-project-p)
2474 (expand-file-name (vhdl-resolve-env-variable
2475 (nth 1 (vhdl-aget vhdl-project-alist vhdl-project))))
2476 default-directory))
2478 (defmacro vhdl-prepare-search-1 (&rest body)
2479 "Enable case insensitive search and switch to syntax table that includes '_',
2480 then execute BODY, and finally restore the old environment. Used for
2481 consistent searching."
2482 `(let ((case-fold-search t)) ; case insensitive search
2483 ;; use extended syntax table
2484 (with-syntax-table vhdl-mode-ext-syntax-table
2485 ,@body)))
2487 (defmacro vhdl-prepare-search-2 (&rest body)
2488 "Enable case insensitive search, switch to syntax table that includes '_',
2489 and remove `intangible' overlays, then execute BODY, and finally restore the
2490 old environment. Used for consistent searching."
2491 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2492 `(let ((case-fold-search t) ; case insensitive search
2493 (current-syntax-table (syntax-table))
2494 overlay-all-list overlay-intangible-list overlay)
2495 ;; use extended syntax table
2496 (set-syntax-table vhdl-mode-ext-syntax-table)
2497 ;; remove `intangible' overlays
2498 (when (fboundp 'overlay-lists)
2499 (setq overlay-all-list (overlay-lists))
2500 (setq overlay-all-list
2501 (append (car overlay-all-list) (cdr overlay-all-list)))
2502 (while overlay-all-list
2503 (setq overlay (car overlay-all-list))
2504 (when (memq 'intangible (overlay-properties overlay))
2505 (setq overlay-intangible-list
2506 (cons overlay overlay-intangible-list))
2507 (overlay-put overlay 'intangible nil))
2508 (setq overlay-all-list (cdr overlay-all-list))))
2509 ;; execute BODY safely
2510 (unwind-protect
2511 (progn ,@body)
2512 ;; restore syntax table
2513 (set-syntax-table current-syntax-table)
2514 ;; restore `intangible' overlays
2515 (when (fboundp 'overlay-lists)
2516 (while overlay-intangible-list
2517 (overlay-put (car overlay-intangible-list) 'intangible t)
2518 (setq overlay-intangible-list
2519 (cdr overlay-intangible-list)))))))
2521 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2522 "Visit file FILE-NAME and execute BODY."
2523 `(if (null ,file-name)
2524 (progn ,@body)
2525 (unless (file-directory-p ,file-name)
2526 (let ((source-buffer (current-buffer))
2527 (visiting-buffer (find-buffer-visiting ,file-name))
2528 file-opened)
2529 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2530 (condition-case ()
2531 (progn (set-buffer (create-file-buffer ,file-name))
2532 (setq file-opened t)
2533 (vhdl-insert-file-contents ,file-name)
2534 ;; FIXME: This modifies a global syntax-table!
2535 (modify-syntax-entry ?\- ". 12" (syntax-table))
2536 (modify-syntax-entry ?\n ">" (syntax-table))
2537 (modify-syntax-entry ?\^M ">" (syntax-table))
2538 (modify-syntax-entry ?_ "w" (syntax-table))
2540 (error
2541 (if ,issue-error
2542 (progn
2543 (when file-opened (kill-buffer (current-buffer)))
2544 (set-buffer source-buffer)
2545 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2546 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2547 nil))))
2548 (condition-case info
2549 (progn ,@body)
2550 (error
2551 (if ,issue-error
2552 (progn
2553 (when file-opened (kill-buffer (current-buffer)))
2554 (set-buffer source-buffer)
2555 (error (cadr info)))
2556 (vhdl-warning (cadr info))))))
2557 (when file-opened (kill-buffer (current-buffer)))
2558 (set-buffer source-buffer)))))
2560 (defun vhdl-insert-file-contents (filename)
2561 "Nicked from `insert-file-contents-literally', but allow coding system
2562 conversion."
2563 (let ((format-alist nil)
2564 (after-insert-file-functions nil)
2565 (jka-compr-compression-info-list nil))
2566 (insert-file-contents filename t)))
2568 (defun vhdl-sort-alist (alist)
2569 "Sort ALIST."
2570 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2572 (defun vhdl-get-subdirs (directory)
2573 "Recursively get subdirectories of DIRECTORY."
2574 (let ((dir-list (list (file-name-as-directory directory)))
2575 file-list)
2576 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2577 (while file-list
2578 (when (file-directory-p (car file-list))
2579 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2580 (setq file-list (cdr file-list)))
2581 dir-list))
2583 (defun vhdl-aput-delete-if-nil (alist-symbol key &optional value)
2584 "As `aput', but delete key-value pair if VALUE is nil."
2585 (if value
2586 (vhdl-aput alist-symbol key value)
2587 (vhdl-adelete alist-symbol key)))
2589 (defun vhdl-delete (elt list)
2590 "Delete by side effect the first occurrence of ELT as a member of LIST."
2591 (push nil list)
2592 (let ((list1 list))
2593 (while (and (cdr list1) (not (equal elt (cadr list1))))
2594 (setq list1 (cdr list1)))
2595 (when list
2596 (setcdr list1 (cddr list1))))
2597 (cdr list))
2599 (declare-function speedbar-refresh "speedbar" (&optional arg))
2600 (declare-function speedbar-do-function-pointer "speedbar" ())
2602 (defun vhdl-speedbar-refresh (&optional key)
2603 "Refresh directory or project with name KEY."
2604 (when (and (boundp 'speedbar-frame)
2605 (frame-live-p speedbar-frame))
2606 (let ((pos (point))
2607 (last-frame (selected-frame)))
2608 (if (null key)
2609 (speedbar-refresh)
2610 (select-frame speedbar-frame)
2611 (when (save-excursion
2612 (goto-char (point-min))
2613 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2614 (goto-char (match-end 1))
2615 (speedbar-do-function-pointer)
2616 (backward-char 2)
2617 (speedbar-do-function-pointer)
2618 (message "Refreshing speedbar...done"))
2619 (select-frame last-frame)))))
2621 (defun vhdl-show-messages ()
2622 "Get *Messages* buffer to show recent messages."
2623 (interactive)
2624 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2626 (defun vhdl-use-direct-instantiation ()
2627 "Return whether direct instantiation is used."
2628 (or (eq vhdl-use-direct-instantiation 'always)
2629 (and (eq vhdl-use-direct-instantiation 'standard)
2630 (not (vhdl-standard-p '87)))))
2632 (defun vhdl-max-marker (marker1 marker2)
2633 "Return larger marker."
2634 (if (> marker1 marker2) marker1 marker2))
2636 (defun vhdl-goto-marker (marker)
2637 "Goto marker in appropriate buffer."
2638 (when (markerp marker)
2639 (set-buffer (marker-buffer marker)))
2640 (goto-char marker))
2642 (defun vhdl-menu-split (list title)
2643 "Split menu LIST into several submenus, if number of
2644 elements > `vhdl-menu-max-size'."
2645 (if (> (length list) vhdl-menu-max-size)
2646 (let ((remain list)
2647 (result '())
2648 (sublist '())
2649 (menuno 1)
2650 (i 0))
2651 (while remain
2652 (push (car remain) sublist)
2653 (setq remain (cdr remain))
2654 (setq i (+ i 1))
2655 (if (= i vhdl-menu-max-size)
2656 (progn
2657 (push (cons (format "%s %s" title menuno)
2658 (nreverse sublist)) result)
2659 (setq i 0)
2660 (setq menuno (+ menuno 1))
2661 (setq sublist '()))))
2662 (and sublist
2663 (push (cons (format "%s %s" title menuno)
2664 (nreverse sublist)) result))
2665 (nreverse result))
2666 list))
2669 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2670 ;;; Bindings
2671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2673 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2674 ;; Key bindings
2676 (defvar vhdl-template-map nil
2677 "Keymap for VHDL templates.")
2679 (defun vhdl-template-map-init ()
2680 "Initialize `vhdl-template-map'."
2681 (setq vhdl-template-map (make-sparse-keymap))
2682 ;; key bindings for VHDL templates
2683 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2684 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2685 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2686 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2687 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2688 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2689 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2690 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2691 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2692 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2693 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2694 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2695 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2696 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2697 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2698 (define-key vhdl-template-map "ct" 'vhdl-template-context)
2699 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2700 (define-key vhdl-template-map "el" 'vhdl-template-else)
2701 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2702 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2703 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2704 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2705 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2706 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2707 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2708 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2709 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2710 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2711 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2712 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2713 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2714 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2715 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2716 (define-key vhdl-template-map "li" 'vhdl-template-library)
2717 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2718 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2719 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2720 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2721 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2722 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2723 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2724 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2725 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2726 (define-key vhdl-template-map "po" 'vhdl-template-port)
2727 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2728 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2729 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2730 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2731 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2732 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2733 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2734 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2735 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2736 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2737 (define-key vhdl-template-map "us" 'vhdl-template-use)
2738 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2739 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2740 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2741 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2742 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2743 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2744 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2745 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2746 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2747 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2748 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2749 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2750 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2751 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2752 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2753 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2754 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2755 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2756 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2757 (when (vhdl-standard-p 'ams)
2758 (define-key vhdl-template-map "br" 'vhdl-template-break)
2759 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2760 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2761 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2762 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2763 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2764 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2765 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2766 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2767 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2768 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2770 (when (vhdl-standard-p 'math)
2771 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2772 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2775 ;; initialize template map for VHDL Mode
2776 (vhdl-template-map-init)
2778 (defun vhdl-function-name (prefix string &optional postfix)
2779 "Generate a Lisp function name.
2780 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2781 STRING are replaced by `-' and substrings are converted to lower case."
2782 (let ((name prefix))
2783 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2784 (setq name
2785 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2786 (setq string (substring string (match-beginning 2))))
2787 (when postfix (setq name (concat name "-" postfix)))
2788 (intern name)))
2790 (defvar vhdl-model-map nil
2791 "Keymap for VHDL models.")
2793 (defun vhdl-model-map-init ()
2794 "Initialize `vhdl-model-map'."
2795 (setq vhdl-model-map (make-sparse-keymap))
2796 ;; key bindings for VHDL models
2797 (let ((model-alist vhdl-model-alist) model)
2798 (while model-alist
2799 (setq model (car model-alist))
2800 (define-key vhdl-model-map (nth 2 model)
2801 (vhdl-function-name "vhdl-model" (nth 0 model)))
2802 (setq model-alist (cdr model-alist)))))
2804 ;; initialize user model map for VHDL Mode
2805 (vhdl-model-map-init)
2807 (defvar vhdl-mode-map nil
2808 "Keymap for VHDL Mode.")
2810 (defun vhdl-mode-map-init ()
2811 "Initialize `vhdl-mode-map'."
2812 (setq vhdl-mode-map (make-sparse-keymap))
2813 ;; template key bindings
2814 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2815 ;; model key bindings
2816 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2817 ;; standard key bindings
2818 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2819 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2820 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2821 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2822 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2823 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2824 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2825 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2826 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2827 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2828 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2829 ;; mode specific key bindings
2830 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2831 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2832 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2833 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2834 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2835 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2836 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2837 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2838 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2839 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2840 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2841 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2842 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2843 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2844 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2845 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2846 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2847 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2848 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2849 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2850 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2851 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2852 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2853 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2854 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2855 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2856 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2857 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2858 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2859 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2860 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2861 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2862 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2863 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2864 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2865 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2866 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2867 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2868 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2869 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2870 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2871 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2872 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2873 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2874 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2875 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2876 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2877 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2878 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2879 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2880 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2881 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2882 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2883 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2884 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2885 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2886 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2887 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2888 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2889 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2890 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2891 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2892 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2893 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2894 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2895 (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
2896 (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
2897 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2898 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2899 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2900 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2901 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2902 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2903 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2904 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2905 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2906 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2907 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2908 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2909 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2910 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2911 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2912 ;; insert commands bindings
2913 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2914 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2915 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2916 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2917 ;; electric key bindings
2918 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2919 (when vhdl-intelligent-tab
2920 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2921 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2922 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2923 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2924 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2925 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2926 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2927 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2928 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2929 (when (vhdl-standard-p 'ams)
2930 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2932 ;; initialize mode map for VHDL Mode
2933 (vhdl-mode-map-init)
2935 ;; define special minibuffer keymap for enabling word completion in minibuffer
2936 ;; (useful in template generator prompts)
2937 (defvar vhdl-minibuffer-local-map
2938 (let ((map (make-sparse-keymap)))
2939 (set-keymap-parent map minibuffer-local-map)
2940 (when vhdl-word-completion-in-minibuffer
2941 (define-key map "\t" 'vhdl-minibuffer-tab))
2942 map)
2943 "Keymap for minibuffer used in VHDL Mode.")
2945 ;; set up electric character functions to work with
2946 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2947 (mapc
2948 (function
2949 (lambda (sym)
2950 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2951 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2952 '(vhdl-electric-space
2953 vhdl-electric-tab
2954 vhdl-electric-return
2955 vhdl-electric-dash
2956 vhdl-electric-open-bracket
2957 vhdl-electric-close-bracket
2958 vhdl-electric-quote
2959 vhdl-electric-semicolon
2960 vhdl-electric-comma
2961 vhdl-electric-period
2962 vhdl-electric-equal))
2964 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2965 ;; Syntax table
2967 (defvar vhdl-mode-syntax-table
2968 (let ((st (make-syntax-table)))
2969 ;; define punctuation
2970 (modify-syntax-entry ?\# "." st)
2971 (modify-syntax-entry ?\$ "." st)
2972 (modify-syntax-entry ?\% "." st)
2973 (modify-syntax-entry ?\& "." st)
2974 (modify-syntax-entry ?\' "." st)
2975 (modify-syntax-entry ?\* "." st)
2976 (modify-syntax-entry ?\+ "." st)
2977 (modify-syntax-entry ?\. "." st)
2978 ;;; (modify-syntax-entry ?\/ "." st)
2979 (modify-syntax-entry ?\: "." st)
2980 (modify-syntax-entry ?\; "." st)
2981 (modify-syntax-entry ?\< "." st)
2982 (modify-syntax-entry ?\= "." st)
2983 (modify-syntax-entry ?\> "." st)
2984 (modify-syntax-entry ?\\ "." st)
2985 (modify-syntax-entry ?\| "." st)
2986 ;; define string
2987 (modify-syntax-entry ?\" "\"" st)
2988 ;; define underscore
2989 (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
2990 ;; single-line comments
2991 (modify-syntax-entry ?\- ". 12b" st)
2992 ;; multi-line comments
2993 (modify-syntax-entry ?\/ ". 14b" st)
2994 (modify-syntax-entry ?* ". 23" st)
2995 (modify-syntax-entry ?\n "> b" st)
2996 (modify-syntax-entry ?\^M "> b" st)
2997 ;; define parentheses to match
2998 (modify-syntax-entry ?\( "()" st)
2999 (modify-syntax-entry ?\) ")(" st)
3000 (modify-syntax-entry ?\[ "(]" st)
3001 (modify-syntax-entry ?\] ")[" st)
3002 (modify-syntax-entry ?\{ "(}" st)
3003 (modify-syntax-entry ?\} "){" st)
3005 "Syntax table used in `vhdl-mode' buffers.")
3007 (defvar vhdl-mode-ext-syntax-table
3008 ;; Extended syntax table including '_' (for simpler search regexps).
3009 (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
3010 (modify-syntax-entry ?_ "w" st)
3012 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
3014 (defvar vhdl-syntactic-context nil
3015 "Buffer local variable containing syntactic analysis list.")
3016 (make-variable-buffer-local 'vhdl-syntactic-context)
3018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3019 ;; Abbrev hook bindings
3021 (defvar vhdl-mode-abbrev-table nil
3022 "Abbrev table to use in `vhdl-mode' buffers.")
3024 (defun vhdl-mode-abbrev-table-init ()
3025 "Initialize `vhdl-mode-abbrev-table'."
3026 (define-abbrev-table 'vhdl-mode-abbrev-table
3027 (append
3028 (when (memq 'vhdl vhdl-electric-keywords)
3029 ;; VHDL'02 keywords
3030 (mapcar (if (featurep 'xemacs)
3031 (lambda (x) (list (car x) "" (cdr x) 0))
3032 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3034 ("--" . vhdl-template-display-comment-hook)
3035 ("abs" . vhdl-template-default-hook)
3036 ("access" . vhdl-template-default-hook)
3037 ("after" . vhdl-template-default-hook)
3038 ("alias" . vhdl-template-alias-hook)
3039 ("all" . vhdl-template-default-hook)
3040 ("and" . vhdl-template-default-hook)
3041 ("arch" . vhdl-template-architecture-hook)
3042 ("architecture" . vhdl-template-architecture-hook)
3043 ("array" . vhdl-template-default-hook)
3044 ("assert" . vhdl-template-assert-hook)
3045 ("attr" . vhdl-template-attribute-hook)
3046 ("attribute" . vhdl-template-attribute-hook)
3047 ("begin" . vhdl-template-default-indent-hook)
3048 ("block" . vhdl-template-block-hook)
3049 ("body" . vhdl-template-default-hook)
3050 ("buffer" . vhdl-template-default-hook)
3051 ("bus" . vhdl-template-default-hook)
3052 ("case" . vhdl-template-case-hook)
3053 ("comp" . vhdl-template-component-hook)
3054 ("component" . vhdl-template-component-hook)
3055 ("cond" . vhdl-template-conditional-signal-asst-hook)
3056 ("conditional" . vhdl-template-conditional-signal-asst-hook)
3057 ("conf" . vhdl-template-configuration-hook)
3058 ("configuration" . vhdl-template-configuration-hook)
3059 ("cons" . vhdl-template-constant-hook)
3060 ("constant" . vhdl-template-constant-hook)
3061 ("context" . vhdl-template-context-hook)
3062 ("disconnect" . vhdl-template-disconnect-hook)
3063 ("downto" . vhdl-template-default-hook)
3064 ("else" . vhdl-template-else-hook)
3065 ("elseif" . vhdl-template-elsif-hook)
3066 ("elsif" . vhdl-template-elsif-hook)
3067 ("end" . vhdl-template-default-indent-hook)
3068 ("entity" . vhdl-template-entity-hook)
3069 ("exit" . vhdl-template-exit-hook)
3070 ("file" . vhdl-template-file-hook)
3071 ("for" . vhdl-template-for-hook)
3072 ("func" . vhdl-template-function-hook)
3073 ("function" . vhdl-template-function-hook)
3074 ("generic" . vhdl-template-generic-hook)
3075 ("group" . vhdl-template-group-hook)
3076 ("guarded" . vhdl-template-default-hook)
3077 ("if" . vhdl-template-if-hook)
3078 ("impure" . vhdl-template-default-hook)
3079 ("in" . vhdl-template-default-hook)
3080 ("inertial" . vhdl-template-default-hook)
3081 ("inout" . vhdl-template-default-hook)
3082 ("inst" . vhdl-template-instance-hook)
3083 ("instance" . vhdl-template-instance-hook)
3084 ("is" . vhdl-template-default-hook)
3085 ("label" . vhdl-template-default-hook)
3086 ("library" . vhdl-template-library-hook)
3087 ("linkage" . vhdl-template-default-hook)
3088 ("literal" . vhdl-template-default-hook)
3089 ("loop" . vhdl-template-bare-loop-hook)
3090 ("map" . vhdl-template-map-hook)
3091 ("mod" . vhdl-template-default-hook)
3092 ("nand" . vhdl-template-default-hook)
3093 ("new" . vhdl-template-default-hook)
3094 ("next" . vhdl-template-next-hook)
3095 ("nor" . vhdl-template-default-hook)
3096 ("not" . vhdl-template-default-hook)
3097 ("null" . vhdl-template-default-hook)
3098 ("of" . vhdl-template-default-hook)
3099 ("on" . vhdl-template-default-hook)
3100 ("open" . vhdl-template-default-hook)
3101 ("or" . vhdl-template-default-hook)
3102 ("others" . vhdl-template-others-hook)
3103 ("out" . vhdl-template-default-hook)
3104 ("pack" . vhdl-template-package-hook)
3105 ("package" . vhdl-template-package-hook)
3106 ("port" . vhdl-template-port-hook)
3107 ("postponed" . vhdl-template-default-hook)
3108 ("procedure" . vhdl-template-procedure-hook)
3109 ("process" . vhdl-template-process-hook)
3110 ("pure" . vhdl-template-default-hook)
3111 ("range" . vhdl-template-default-hook)
3112 ("record" . vhdl-template-default-hook)
3113 ("register" . vhdl-template-default-hook)
3114 ("reject" . vhdl-template-default-hook)
3115 ("rem" . vhdl-template-default-hook)
3116 ("report" . vhdl-template-report-hook)
3117 ("return" . vhdl-template-return-hook)
3118 ("rol" . vhdl-template-default-hook)
3119 ("ror" . vhdl-template-default-hook)
3120 ("select" . vhdl-template-selected-signal-asst-hook)
3121 ("severity" . vhdl-template-default-hook)
3122 ("shared" . vhdl-template-default-hook)
3123 ("sig" . vhdl-template-signal-hook)
3124 ("signal" . vhdl-template-signal-hook)
3125 ("sla" . vhdl-template-default-hook)
3126 ("sll" . vhdl-template-default-hook)
3127 ("sra" . vhdl-template-default-hook)
3128 ("srl" . vhdl-template-default-hook)
3129 ("subtype" . vhdl-template-subtype-hook)
3130 ("then" . vhdl-template-default-hook)
3131 ("to" . vhdl-template-default-hook)
3132 ("transport" . vhdl-template-default-hook)
3133 ("type" . vhdl-template-type-hook)
3134 ("unaffected" . vhdl-template-default-hook)
3135 ("units" . vhdl-template-default-hook)
3136 ("until" . vhdl-template-default-hook)
3137 ("use" . vhdl-template-use-hook)
3138 ("var" . vhdl-template-variable-hook)
3139 ("variable" . vhdl-template-variable-hook)
3140 ("wait" . vhdl-template-wait-hook)
3141 ("when" . vhdl-template-when-hook)
3142 ("while" . vhdl-template-while-loop-hook)
3143 ("with" . vhdl-template-with-hook)
3144 ("xnor" . vhdl-template-default-hook)
3145 ("xor" . vhdl-template-default-hook)
3147 ;; VHDL-AMS keywords
3148 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3149 (mapcar (if (featurep 'xemacs)
3150 (lambda (x) (list (car x) "" (cdr x) 0))
3151 (lambda (x) (list (car x) "" (cdr x) 0 'system)))
3153 ("across" . vhdl-template-default-hook)
3154 ("break" . vhdl-template-break-hook)
3155 ("limit" . vhdl-template-limit-hook)
3156 ("nature" . vhdl-template-nature-hook)
3157 ("noise" . vhdl-template-default-hook)
3158 ("procedural" . vhdl-template-procedural-hook)
3159 ("quantity" . vhdl-template-quantity-hook)
3160 ("reference" . vhdl-template-default-hook)
3161 ("spectrum" . vhdl-template-default-hook)
3162 ("subnature" . vhdl-template-subnature-hook)
3163 ("terminal" . vhdl-template-terminal-hook)
3164 ("through" . vhdl-template-default-hook)
3165 ("tolerance" . vhdl-template-default-hook)
3167 ;; user model keywords
3168 (when (memq 'user vhdl-electric-keywords)
3169 (let (abbrev-list keyword)
3170 (dolist (elem vhdl-model-alist)
3171 (setq keyword (nth 3 elem))
3172 (unless (equal keyword "")
3173 (push (list keyword ""
3174 (vhdl-function-name
3175 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3176 abbrev-list)))
3177 abbrev-list)))))
3179 ;; initialize abbrev table for VHDL Mode
3180 (vhdl-mode-abbrev-table-init)
3182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3183 ;; Template completion lists
3185 (defvar vhdl-template-construct-alist nil
3186 "List of built-in construct templates.")
3188 (defun vhdl-template-construct-alist-init ()
3189 "Initialize `vhdl-template-construct-alist'."
3190 (setq
3191 vhdl-template-construct-alist
3192 (append
3194 ("alias declaration" vhdl-template-alias)
3195 ("architecture body" vhdl-template-architecture)
3196 ("assertion" vhdl-template-assert)
3197 ("attribute declaration" vhdl-template-attribute-decl)
3198 ("attribute specification" vhdl-template-attribute-spec)
3199 ("block configuration" vhdl-template-block-configuration)
3200 ("block statement" vhdl-template-block)
3201 ("case statement" vhdl-template-case-is)
3202 ("component configuration" vhdl-template-component-conf)
3203 ("component declaration" vhdl-template-component-decl)
3204 ("component instantiation statement" vhdl-template-component-inst)
3205 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3206 ("configuration declaration" vhdl-template-configuration-decl)
3207 ("configuration specification" vhdl-template-configuration-spec)
3208 ("constant declaration" vhdl-template-constant)
3209 ("context declaration" vhdl-template-context)
3210 ("disconnection specification" vhdl-template-disconnect)
3211 ("entity declaration" vhdl-template-entity)
3212 ("exit statement" vhdl-template-exit)
3213 ("file declaration" vhdl-template-file)
3214 ("generate statement" vhdl-template-generate)
3215 ("generic clause" vhdl-template-generic)
3216 ("group declaration" vhdl-template-group-decl)
3217 ("group template declaration" vhdl-template-group-template)
3218 ("if statement" vhdl-template-if-then)
3219 ("library clause" vhdl-template-library)
3220 ("loop statement" vhdl-template-loop)
3221 ("next statement" vhdl-template-next)
3222 ("package declaration" vhdl-template-package-decl)
3223 ("package body" vhdl-template-package-body)
3224 ("port clause" vhdl-template-port)
3225 ("process statement" vhdl-template-process)
3226 ("report statement" vhdl-template-report)
3227 ("return statement" vhdl-template-return)
3228 ("selected signal assignment" vhdl-template-selected-signal-asst)
3229 ("signal declaration" vhdl-template-signal)
3230 ("subprogram declaration" vhdl-template-subprogram-decl)
3231 ("subprogram body" vhdl-template-subprogram-body)
3232 ("subtype declaration" vhdl-template-subtype)
3233 ("type declaration" vhdl-template-type)
3234 ("use clause" vhdl-template-use)
3235 ("variable declaration" vhdl-template-variable)
3236 ("wait statement" vhdl-template-wait)
3238 (when (vhdl-standard-p 'ams)
3240 ("break statement" vhdl-template-break)
3241 ("nature declaration" vhdl-template-nature)
3242 ("quantity declaration" vhdl-template-quantity)
3243 ("simultaneous case statement" vhdl-template-case-use)
3244 ("simultaneous if statement" vhdl-template-if-use)
3245 ("simultaneous procedural statement" vhdl-template-procedural)
3246 ("step limit specification" vhdl-template-limit)
3247 ("subnature declaration" vhdl-template-subnature)
3248 ("terminal declaration" vhdl-template-terminal)
3249 )))))
3251 ;; initialize for VHDL Mode
3252 (vhdl-template-construct-alist-init)
3254 (defvar vhdl-template-package-alist nil
3255 "List of built-in package templates.")
3257 (defun vhdl-template-package-alist-init ()
3258 "Initialize `vhdl-template-package-alist'."
3259 (setq
3260 vhdl-template-package-alist
3261 (append
3263 ("numeric_bit" vhdl-template-package-numeric-bit)
3264 ("numeric_std" vhdl-template-package-numeric-std)
3265 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3266 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3267 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3268 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3269 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3270 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3271 ("textio" vhdl-template-package-textio)
3273 (when (vhdl-standard-p 'math)
3275 ("math_complex" vhdl-template-package-math-complex)
3276 ("math_real" vhdl-template-package-math-real)
3277 )))))
3279 ;; initialize for VHDL Mode
3280 (vhdl-template-package-alist-init)
3282 (defvar vhdl-template-directive-alist
3284 ("translate_on" vhdl-template-directive-translate-on)
3285 ("translate_off" vhdl-template-directive-translate-off)
3286 ("synthesis_on" vhdl-template-directive-synthesis-on)
3287 ("synthesis_off" vhdl-template-directive-synthesis-off)
3289 "List of built-in directive templates.")
3292 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3293 ;;; Menus
3294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3297 ;; VHDL menu (using `easy-menu.el')
3299 (defun vhdl-customize ()
3300 "Call the customize function with `vhdl' as argument."
3301 (interactive)
3302 (customize-browse 'vhdl))
3304 (defun vhdl-create-mode-menu ()
3305 "Create VHDL Mode menu."
3306 `("VHDL"
3307 ,(append
3308 '("Project"
3309 ["None" (vhdl-set-project "")
3310 :style radio :selected (null vhdl-project)]
3311 "--")
3312 ;; add menu entries for defined projects
3313 (let ((project-alist vhdl-project-alist) menu-list name)
3314 (while project-alist
3315 (setq name (caar project-alist))
3316 (setq menu-list
3317 (cons `[,name (vhdl-set-project ,name)
3318 :style radio :selected (equal ,name vhdl-project)]
3319 menu-list))
3320 (setq project-alist (cdr project-alist)))
3321 (setq menu-list
3322 (if vhdl-project-sort
3323 (sort menu-list
3324 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3325 (nreverse menu-list)))
3326 (vhdl-menu-split menu-list "Project"))
3327 '("--" "--"
3328 ["Select Project..." vhdl-set-project t]
3329 ["Set As Default Project" vhdl-set-default-project t]
3330 "--"
3331 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3332 ["Import Project..." vhdl-import-project
3333 :keys "C-c C-p C-m" :active t]
3334 ["Export Project" vhdl-export-project vhdl-project]
3335 "--"
3336 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3337 "--"
3338 ("Compile"
3339 ["Compile Buffer" vhdl-compile t]
3340 ["Stop Compilation" kill-compilation t]
3341 "--"
3342 ["Make" vhdl-make t]
3343 ["Generate Makefile" vhdl-generate-makefile t]
3344 "--"
3345 ["Next Error" next-error t]
3346 ["Previous Error" previous-error t]
3347 ["First Error" first-error t]
3348 "--"
3349 ,(append
3350 '("Compiler")
3351 ;; add menu entries for defined compilers
3352 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3353 (while comp-alist
3354 (setq name (caar comp-alist))
3355 (setq menu-list
3356 (cons `[,name (setq vhdl-compiler ,name)
3357 :style radio :selected (equal ,name vhdl-compiler)]
3358 menu-list))
3359 (setq comp-alist (cdr comp-alist)))
3360 (setq menu-list (nreverse menu-list))
3361 (vhdl-menu-split menu-list "Compiler"))
3362 '("--" "--"
3363 ["Select Compiler..." vhdl-set-compiler t]
3364 "--"
3365 ["Customize Compiler..."
3366 (customize-option 'vhdl-compiler-alist) t])))
3367 "--"
3368 ,(append
3369 '("Template"
3370 ("VHDL Construct 1"
3371 ["Alias" vhdl-template-alias t]
3372 ["Architecture" vhdl-template-architecture t]
3373 ["Assert" vhdl-template-assert t]
3374 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3375 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3376 ["Block" vhdl-template-block t]
3377 ["Case" vhdl-template-case-is t]
3378 ["Component (Decl)" vhdl-template-component-decl t]
3379 ["(Component) Instance" vhdl-template-component-inst t]
3380 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3381 ["Configuration (Block)" vhdl-template-block-configuration t]
3382 ["Configuration (Comp)" vhdl-template-component-conf t]
3383 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3384 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3385 ["Constant" vhdl-template-constant t]
3386 ["Context" vhdl-template-context t]
3387 ["Disconnect" vhdl-template-disconnect t]
3388 ["Else" vhdl-template-else t]
3389 ["Elsif" vhdl-template-elsif t]
3390 ["Entity" vhdl-template-entity t]
3391 ["Exit" vhdl-template-exit t]
3392 ["File" vhdl-template-file t]
3393 ["For (Generate)" vhdl-template-for-generate t]
3394 ["For (Loop)" vhdl-template-for-loop t]
3395 ["Function (Body)" vhdl-template-function-body t]
3396 ["Function (Decl)" vhdl-template-function-decl t]
3397 ["Generic" vhdl-template-generic t]
3398 ["Group (Decl)" vhdl-template-group-decl t]
3399 ["Group (Template)" vhdl-template-group-template t])
3400 ("VHDL Construct 2"
3401 ["If (Generate)" vhdl-template-if-generate t]
3402 ["If (Then)" vhdl-template-if-then t]
3403 ["Library" vhdl-template-library t]
3404 ["Loop" vhdl-template-bare-loop t]
3405 ["Map" vhdl-template-map t]
3406 ["Next" vhdl-template-next t]
3407 ["Others (Aggregate)" vhdl-template-others t]
3408 ["Package (Decl)" vhdl-template-package-decl t]
3409 ["Package (Body)" vhdl-template-package-body t]
3410 ["Port" vhdl-template-port t]
3411 ["Procedure (Body)" vhdl-template-procedure-body t]
3412 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3413 ["Process (Comb)" vhdl-template-process-comb t]
3414 ["Process (Seq)" vhdl-template-process-seq t]
3415 ["Report" vhdl-template-report t]
3416 ["Return" vhdl-template-return t]
3417 ["Select" vhdl-template-selected-signal-asst t]
3418 ["Signal" vhdl-template-signal t]
3419 ["Subtype" vhdl-template-subtype t]
3420 ["Type" vhdl-template-type t]
3421 ["Use" vhdl-template-use t]
3422 ["Variable" vhdl-template-variable t]
3423 ["Wait" vhdl-template-wait t]
3424 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3425 ["When" vhdl-template-when t]
3426 ["While (Loop)" vhdl-template-while-loop t]
3427 ["With" vhdl-template-with t]))
3428 (when (vhdl-standard-p 'ams)
3429 '(("VHDL-AMS Construct"
3430 ["Break" vhdl-template-break t]
3431 ["Case (Use)" vhdl-template-case-use t]
3432 ["If (Use)" vhdl-template-if-use t]
3433 ["Limit" vhdl-template-limit t]
3434 ["Nature" vhdl-template-nature t]
3435 ["Procedural" vhdl-template-procedural t]
3436 ["Quantity (Free)" vhdl-template-quantity-free t]
3437 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3438 ["Quantity (Source)" vhdl-template-quantity-source t]
3439 ["Subnature" vhdl-template-subnature t]
3440 ["Terminal" vhdl-template-terminal t])))
3441 '(["Insert Construct..." vhdl-template-insert-construct
3442 :keys "C-c C-i C-t"]
3443 "--")
3444 (list
3445 (append
3446 '("Package")
3447 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3448 ["numeric_std" vhdl-template-package-numeric-std t]
3449 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3450 ["textio" vhdl-template-package-textio t]
3451 "--"
3452 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3453 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3454 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3455 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3456 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3457 "--")
3458 (when (vhdl-standard-p 'ams)
3459 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3460 ["material_constants" vhdl-template-package-material-constants t]
3461 ["energy_systems" vhdl-template-package-energy-systems t]
3462 ["electrical_systems" vhdl-template-package-electrical-systems t]
3463 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3464 ["radiant_systems" vhdl-template-package-radiant-systems t]
3465 ["thermal_systems" vhdl-template-package-thermal-systems t]
3466 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3467 "--"))
3468 (when (vhdl-standard-p 'math)
3469 '(["math_complex" vhdl-template-package-math-complex t]
3470 ["math_real" vhdl-template-package-math-real t]
3471 "--"))
3472 '(["Insert Package..." vhdl-template-insert-package
3473 :keys "C-c C-i C-p"])))
3474 '(("Directive"
3475 ["translate_on" vhdl-template-directive-translate-on t]
3476 ["translate_off" vhdl-template-directive-translate-off t]
3477 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3478 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3479 "--"
3480 ["Insert Directive..." vhdl-template-insert-directive
3481 :keys "C-c C-i C-d"])
3482 "--"
3483 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3484 ["Insert Footer" vhdl-template-footer t]
3485 ["Insert Date" vhdl-template-insert-date t]
3486 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3487 "--"
3488 ["Query Next Prompt" vhdl-template-search-prompt t]))
3489 ,(append
3490 '("Model")
3491 ;; add menu entries for defined models
3492 (let ((model-alist vhdl-model-alist) menu-list model)
3493 (while model-alist
3494 (setq model (car model-alist))
3495 (setq menu-list
3496 (cons
3497 (vector
3498 (nth 0 model)
3499 (vhdl-function-name "vhdl-model" (nth 0 model))
3500 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3501 menu-list))
3502 (setq model-alist (cdr model-alist)))
3503 (setq menu-list (nreverse menu-list))
3504 (vhdl-menu-split menu-list "Model"))
3505 '("--" "--"
3506 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3507 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3508 ("Port"
3509 ["Copy" vhdl-port-copy t]
3510 "--"
3511 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3512 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3513 ["Paste As Instance" vhdl-port-paste-instance
3514 :keys "C-c C-p C-i" :active vhdl-port-list]
3515 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3516 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3517 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3518 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3519 "--"
3520 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3521 "--"
3522 ["Flatten" vhdl-port-flatten
3523 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3524 ["Reverse Direction" vhdl-port-reverse-direction
3525 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3526 ("Compose"
3527 ["New Component" vhdl-compose-new-component t]
3528 ["Copy Component" vhdl-port-copy t]
3529 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3530 ["Wire Components" vhdl-compose-wire-components t]
3531 "--"
3532 ["Generate Configuration" vhdl-compose-configuration t]
3533 ["Generate Components Package" vhdl-compose-components-package t])
3534 ("Subprogram"
3535 ["Copy" vhdl-subprog-copy t]
3536 "--"
3537 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3538 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3539 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3540 "--"
3541 ["Flatten" vhdl-subprog-flatten
3542 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3543 "--"
3544 ("Comment"
3545 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3546 "--"
3547 ["Insert Inline Comment" vhdl-comment-append-inline t]
3548 ["Insert Horizontal Line" vhdl-comment-display-line t]
3549 ["Insert Display Comment" vhdl-comment-display t]
3550 "--"
3551 ["Fill Comment" fill-paragraph t]
3552 ["Fill Comment Region" fill-region (mark)]
3553 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3554 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3555 ("Line"
3556 ["Kill" vhdl-line-kill t]
3557 ["Copy" vhdl-line-copy t]
3558 ["Yank" vhdl-line-yank t]
3559 ["Expand" vhdl-line-expand t]
3560 "--"
3561 ["Transpose Next" vhdl-line-transpose-next t]
3562 ["Transpose Prev" vhdl-line-transpose-previous t]
3563 ["Open" vhdl-line-open t]
3564 ["Join" vhdl-delete-indentation t]
3565 "--"
3566 ["Goto" goto-line t]
3567 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3568 ("Move"
3569 ["Forward Statement" vhdl-end-of-statement t]
3570 ["Backward Statement" vhdl-beginning-of-statement t]
3571 ["Forward Expression" vhdl-forward-sexp t]
3572 ["Backward Expression" vhdl-backward-sexp t]
3573 ["Forward Same Indent" vhdl-forward-same-indent t]
3574 ["Backward Same Indent" vhdl-backward-same-indent t]
3575 ["Forward Function" vhdl-end-of-defun t]
3576 ["Backward Function" vhdl-beginning-of-defun t]
3577 ["Mark Function" vhdl-mark-defun t])
3578 "--"
3579 ("Indent"
3580 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3581 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3582 ["Region" vhdl-indent-region (mark)]
3583 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3584 ("Align"
3585 ["Group" vhdl-align-group t]
3586 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3587 ["List" vhdl-align-list t]
3588 ["Declarations" vhdl-align-declarations t]
3589 ["Region" vhdl-align-region (mark)]
3590 ["Buffer" vhdl-align-buffer t]
3591 "--"
3592 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3593 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3594 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3595 ("Fill"
3596 ["List" vhdl-fill-list t]
3597 ["Group" vhdl-fill-group t]
3598 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3599 ["Region" vhdl-fill-region (mark)])
3600 ("Beautify"
3601 ["Region" vhdl-beautify-region (mark)]
3602 ["Buffer" vhdl-beautify-buffer t])
3603 ("Fix"
3604 ["Generic/Port Clause" vhdl-fix-clause t]
3605 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3606 "--"
3607 ["Case Region" vhdl-fix-case-region (mark)]
3608 ["Case Buffer" vhdl-fix-case-buffer t]
3609 "--"
3610 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3611 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3612 "--"
3613 ["Statement Region" vhdl-fix-statement-region (mark)]
3614 ["Statement Buffer" vhdl-fix-statement-buffer t]
3615 "--"
3616 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3617 ("Update"
3618 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3619 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3620 "--"
3621 ["Fontify Buffer" vhdl-fontify-buffer t]
3622 ["Statistics Buffer" vhdl-statistics-buffer t]
3623 ["Show Messages" vhdl-show-messages t]
3624 ["Syntactic Info" vhdl-show-syntactic-information t]
3625 "--"
3626 ["Speedbar" vhdl-speedbar t]
3627 ["Hide/Show" vhdl-hs-minor-mode t]
3628 "--"
3629 ("Documentation"
3630 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3631 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3632 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3633 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3634 ["Version" vhdl-version t]
3635 ["Bug Report..." vhdl-submit-bug-report t]
3636 "--"
3637 ("Options"
3638 ("Mode"
3639 ["Electric Mode"
3640 (progn (customize-set-variable 'vhdl-electric-mode
3641 (not vhdl-electric-mode))
3642 (vhdl-mode-line-update))
3643 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3644 ["Stutter Mode"
3645 (progn (customize-set-variable 'vhdl-stutter-mode
3646 (not vhdl-stutter-mode))
3647 (vhdl-mode-line-update))
3648 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3649 ["Indent Tabs Mode"
3650 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3651 (not vhdl-indent-tabs-mode))
3652 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3653 :style toggle :selected vhdl-indent-tabs-mode]
3654 "--"
3655 ["Customize Group..." (customize-group 'vhdl-mode) t])
3656 ("Project"
3657 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3658 ,(append
3659 '("Selected Project at Startup"
3660 ["None" (progn (customize-set-variable 'vhdl-project nil)
3661 (vhdl-set-project ""))
3662 :style radio :selected (null vhdl-project)]
3663 "--")
3664 ;; add menu entries for defined projects
3665 (let ((project-alist vhdl-project-alist) menu-list name)
3666 (while project-alist
3667 (setq name (caar project-alist))
3668 (setq menu-list
3669 (cons `[,name (progn (customize-set-variable
3670 'vhdl-project ,name)
3671 (vhdl-set-project ,name))
3672 :style radio :selected (equal ,name vhdl-project)]
3673 menu-list))
3674 (setq project-alist (cdr project-alist)))
3675 (setq menu-list (nreverse menu-list))
3676 (vhdl-menu-split menu-list "Project")))
3677 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3678 ("Auto Load Setup File"
3679 ["At Startup"
3680 (customize-set-variable 'vhdl-project-auto-load
3681 (if (memq 'startup vhdl-project-auto-load)
3682 (delq 'startup vhdl-project-auto-load)
3683 (cons 'startup vhdl-project-auto-load)))
3684 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3685 ["Sort Projects"
3686 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3687 :style toggle :selected vhdl-project-sort]
3688 "--"
3689 ["Customize Group..." (customize-group 'vhdl-project) t])
3690 ("Compiler"
3691 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3692 ,(append
3693 '("Selected Compiler at Startup")
3694 ;; add menu entries for defined compilers
3695 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3696 (while comp-alist
3697 (setq name (caar comp-alist))
3698 (setq menu-list
3699 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3700 :style radio :selected (equal ,name vhdl-compiler)]
3701 menu-list))
3702 (setq comp-alist (cdr comp-alist)))
3703 (setq menu-list (nreverse menu-list))
3704 (vhdl-menu-split menu-list "Compiler")))
3705 ["Use Local Error Regexp"
3706 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3707 (not vhdl-compile-use-local-error-regexp))
3708 :style toggle :selected vhdl-compile-use-local-error-regexp]
3709 ["Makefile Default Targets..."
3710 (customize-option 'vhdl-makefile-default-targets) t]
3711 ["Makefile Generation Hook..."
3712 (customize-option 'vhdl-makefile-generation-hook) t]
3713 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3714 "--"
3715 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3716 ("Style"
3717 ("VHDL Standard"
3718 ["VHDL'87"
3719 (progn (customize-set-variable 'vhdl-standard
3720 (list '87 (cadr vhdl-standard)))
3721 (vhdl-activate-customizations))
3722 :style radio :selected (eq '87 (car vhdl-standard))]
3723 ["VHDL'93/02"
3724 (progn (customize-set-variable 'vhdl-standard
3725 (list '93 (cadr vhdl-standard)))
3726 (vhdl-activate-customizations))
3727 :style radio :selected (eq '93 (car vhdl-standard))]
3728 ["VHDL'08"
3729 (progn (customize-set-variable 'vhdl-standard
3730 (list '08 (cadr vhdl-standard)))
3731 (vhdl-activate-customizations))
3732 :style radio :selected (eq '08 (car vhdl-standard))]
3733 "--"
3734 ["VHDL-AMS"
3735 (progn (customize-set-variable
3736 'vhdl-standard (list (car vhdl-standard)
3737 (if (memq 'ams (cadr vhdl-standard))
3738 (delq 'ams (cadr vhdl-standard))
3739 (cons 'ams (cadr vhdl-standard)))))
3740 (vhdl-activate-customizations))
3741 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3742 ["Math Packages"
3743 (progn (customize-set-variable
3744 'vhdl-standard (list (car vhdl-standard)
3745 (if (memq 'math (cadr vhdl-standard))
3746 (delq 'math (cadr vhdl-standard))
3747 (cons 'math (cadr vhdl-standard)))))
3748 (vhdl-activate-customizations))
3749 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3750 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3751 ["Upper Case Keywords"
3752 (customize-set-variable 'vhdl-upper-case-keywords
3753 (not vhdl-upper-case-keywords))
3754 :style toggle :selected vhdl-upper-case-keywords]
3755 ["Upper Case Types"
3756 (customize-set-variable 'vhdl-upper-case-types
3757 (not vhdl-upper-case-types))
3758 :style toggle :selected vhdl-upper-case-types]
3759 ["Upper Case Attributes"
3760 (customize-set-variable 'vhdl-upper-case-attributes
3761 (not vhdl-upper-case-attributes))
3762 :style toggle :selected vhdl-upper-case-attributes]
3763 ["Upper Case Enumeration Values"
3764 (customize-set-variable 'vhdl-upper-case-enum-values
3765 (not vhdl-upper-case-enum-values))
3766 :style toggle :selected vhdl-upper-case-enum-values]
3767 ["Upper Case Constants"
3768 (customize-set-variable 'vhdl-upper-case-constants
3769 (not vhdl-upper-case-constants))
3770 :style toggle :selected vhdl-upper-case-constants]
3771 ("Use Direct Instantiation"
3772 ["Never"
3773 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3774 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3775 ["Standard"
3776 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3777 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3778 ["Always"
3779 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3780 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3781 ["Include Array Index and Record Field in Sensitivity List"
3782 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3783 (not vhdl-array-index-record-field-in-sensitivity-list))
3784 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3785 "--"
3786 ["Customize Group..." (customize-group 'vhdl-style) t])
3787 ("Naming"
3788 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3789 ["Architecture File Name..."
3790 (customize-option 'vhdl-architecture-file-name) t]
3791 ["Configuration File Name..."
3792 (customize-option 'vhdl-configuration-file-name) t]
3793 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3794 ("File Name Case"
3795 ["As Is"
3796 (customize-set-variable 'vhdl-file-name-case 'identity)
3797 :style radio :selected (eq 'identity vhdl-file-name-case)]
3798 ["Lower Case"
3799 (customize-set-variable 'vhdl-file-name-case 'downcase)
3800 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3801 ["Upper Case"
3802 (customize-set-variable 'vhdl-file-name-case 'upcase)
3803 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3804 ["Capitalize"
3805 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3806 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3807 "--"
3808 ["Customize Group..." (customize-group 'vhdl-naming) t])
3809 ("Template"
3810 ("Electric Keywords"
3811 ["VHDL Keywords"
3812 (customize-set-variable 'vhdl-electric-keywords
3813 (if (memq 'vhdl vhdl-electric-keywords)
3814 (delq 'vhdl vhdl-electric-keywords)
3815 (cons 'vhdl vhdl-electric-keywords)))
3816 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3817 ["User Model Keywords"
3818 (customize-set-variable 'vhdl-electric-keywords
3819 (if (memq 'user vhdl-electric-keywords)
3820 (delq 'user vhdl-electric-keywords)
3821 (cons 'user vhdl-electric-keywords)))
3822 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3823 ("Insert Optional Labels"
3824 ["None"
3825 (customize-set-variable 'vhdl-optional-labels 'none)
3826 :style radio :selected (eq 'none vhdl-optional-labels)]
3827 ["Processes Only"
3828 (customize-set-variable 'vhdl-optional-labels 'process)
3829 :style radio :selected (eq 'process vhdl-optional-labels)]
3830 ["All Constructs"
3831 (customize-set-variable 'vhdl-optional-labels 'all)
3832 :style radio :selected (eq 'all vhdl-optional-labels)])
3833 ("Insert Empty Lines"
3834 ["None"
3835 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3836 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3837 ["Design Units Only"
3838 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3839 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3840 ["All Constructs"
3841 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3842 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3843 ["Argument List Indent"
3844 (customize-set-variable 'vhdl-argument-list-indent
3845 (not vhdl-argument-list-indent))
3846 :style toggle :selected vhdl-argument-list-indent]
3847 ["Association List with Formals"
3848 (customize-set-variable 'vhdl-association-list-with-formals
3849 (not vhdl-association-list-with-formals))
3850 :style toggle :selected vhdl-association-list-with-formals]
3851 ["Conditions in Parenthesis"
3852 (customize-set-variable 'vhdl-conditions-in-parenthesis
3853 (not vhdl-conditions-in-parenthesis))
3854 :style toggle :selected vhdl-conditions-in-parenthesis]
3855 ["Sensitivity List uses 'all'"
3856 (customize-set-variable 'vhdl-sensitivity-list-all
3857 (not vhdl-sensitivity-list-all))
3858 :style toggle :selected vhdl-sensitivity-list-all]
3859 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3860 ["One String..." (customize-option 'vhdl-one-string) t]
3861 ("File Header"
3862 ["Header String..." (customize-option 'vhdl-file-header) t]
3863 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3864 ["Company Name..." (customize-option 'vhdl-company-name) t]
3865 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3866 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3867 ["Date Format..." (customize-option 'vhdl-date-format) t]
3868 ["Modify Date Prefix String..."
3869 (customize-option 'vhdl-modify-date-prefix-string) t]
3870 ["Modify Date on Saving"
3871 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3872 (not vhdl-modify-date-on-saving))
3873 (vhdl-activate-customizations))
3874 :style toggle :selected vhdl-modify-date-on-saving])
3875 ("Sequential Process"
3876 ("Kind of Reset"
3877 ["None"
3878 (customize-set-variable 'vhdl-reset-kind 'none)
3879 :style radio :selected (eq 'none vhdl-reset-kind)]
3880 ["Synchronous"
3881 (customize-set-variable 'vhdl-reset-kind 'sync)
3882 :style radio :selected (eq 'sync vhdl-reset-kind)]
3883 ["Asynchronous"
3884 (customize-set-variable 'vhdl-reset-kind 'async)
3885 :style radio :selected (eq 'async vhdl-reset-kind)]
3886 ["Query"
3887 (customize-set-variable 'vhdl-reset-kind 'query)
3888 :style radio :selected (eq 'query vhdl-reset-kind)])
3889 ["Reset is Active High"
3890 (customize-set-variable 'vhdl-reset-active-high
3891 (not vhdl-reset-active-high))
3892 :style toggle :selected vhdl-reset-active-high]
3893 ["Use Rising Clock Edge"
3894 (customize-set-variable 'vhdl-clock-rising-edge
3895 (not vhdl-clock-rising-edge))
3896 :style toggle :selected vhdl-clock-rising-edge]
3897 ("Clock Edge Condition"
3898 ["Standard"
3899 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3900 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3901 ["Function \"rising_edge\""
3902 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3903 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3904 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3905 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3906 "--"
3907 ["Customize Group..." (customize-group 'vhdl-template) t])
3908 ("Model"
3909 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3910 ("Port"
3911 ["Include Port Comments"
3912 (customize-set-variable 'vhdl-include-port-comments
3913 (not vhdl-include-port-comments))
3914 :style toggle :selected vhdl-include-port-comments]
3915 ["Include Direction Comments"
3916 (customize-set-variable 'vhdl-include-direction-comments
3917 (not vhdl-include-direction-comments))
3918 :style toggle :selected vhdl-include-direction-comments]
3919 ["Include Type Comments"
3920 (customize-set-variable 'vhdl-include-type-comments
3921 (not vhdl-include-type-comments))
3922 :style toggle :selected vhdl-include-type-comments]
3923 ("Include Group Comments"
3924 ["Never"
3925 (customize-set-variable 'vhdl-include-group-comments 'never)
3926 :style radio :selected (eq 'never vhdl-include-group-comments)]
3927 ["Declarations"
3928 (customize-set-variable 'vhdl-include-group-comments 'decl)
3929 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3930 ["Always"
3931 (customize-set-variable 'vhdl-include-group-comments 'always)
3932 :style radio :selected (eq 'always vhdl-include-group-comments)])
3933 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
3934 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3935 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3936 ("Testbench"
3937 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3938 ["Architecture Name..."
3939 (customize-option 'vhdl-testbench-architecture-name) t]
3940 ["Configuration Name..."
3941 (customize-option 'vhdl-testbench-configuration-name) t]
3942 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3943 ["Include Header"
3944 (customize-set-variable 'vhdl-testbench-include-header
3945 (not vhdl-testbench-include-header))
3946 :style toggle :selected vhdl-testbench-include-header]
3947 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3948 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3949 ["Initialize Signals"
3950 (customize-set-variable 'vhdl-testbench-initialize-signals
3951 (not vhdl-testbench-initialize-signals))
3952 :style toggle :selected vhdl-testbench-initialize-signals]
3953 ["Include Library Clause"
3954 (customize-set-variable 'vhdl-testbench-include-library
3955 (not vhdl-testbench-include-library))
3956 :style toggle :selected vhdl-testbench-include-library]
3957 ["Include Configuration"
3958 (customize-set-variable 'vhdl-testbench-include-configuration
3959 (not vhdl-testbench-include-configuration))
3960 :style toggle :selected vhdl-testbench-include-configuration]
3961 ("Create Files"
3962 ["None"
3963 (customize-set-variable 'vhdl-testbench-create-files 'none)
3964 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3965 ["Single"
3966 (customize-set-variable 'vhdl-testbench-create-files 'single)
3967 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3968 ["Separate"
3969 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3970 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3971 ["Testbench Entity File Name..."
3972 (customize-option 'vhdl-testbench-entity-file-name) t]
3973 ["Testbench Architecture File Name..."
3974 (customize-option 'vhdl-testbench-architecture-file-name) t])
3975 "--"
3976 ["Customize Group..." (customize-group 'vhdl-port) t])
3977 ("Compose"
3978 ["Architecture Name..."
3979 (customize-option 'vhdl-compose-architecture-name) t]
3980 ["Configuration Name..."
3981 (customize-option 'vhdl-compose-configuration-name) t]
3982 ["Components Package Name..."
3983 (customize-option 'vhdl-components-package-name) t]
3984 ["Use Components Package"
3985 (customize-set-variable 'vhdl-use-components-package
3986 (not vhdl-use-components-package))
3987 :style toggle :selected vhdl-use-components-package]
3988 ["Include Header"
3989 (customize-set-variable 'vhdl-compose-include-header
3990 (not vhdl-compose-include-header))
3991 :style toggle :selected vhdl-compose-include-header]
3992 ("Create Entity/Architecture Files"
3993 ["None"
3994 (customize-set-variable 'vhdl-compose-create-files 'none)
3995 :style radio :selected (eq 'none vhdl-compose-create-files)]
3996 ["Single"
3997 (customize-set-variable 'vhdl-compose-create-files 'single)
3998 :style radio :selected (eq 'single vhdl-compose-create-files)]
3999 ["Separate"
4000 (customize-set-variable 'vhdl-compose-create-files 'separate)
4001 :style radio :selected (eq 'separate vhdl-compose-create-files)])
4002 ["Create Configuration File"
4003 (customize-set-variable 'vhdl-compose-configuration-create-file
4004 (not vhdl-compose-configuration-create-file))
4005 :style toggle :selected vhdl-compose-configuration-create-file]
4006 ["Hierarchical Configuration"
4007 (customize-set-variable 'vhdl-compose-configuration-hierarchical
4008 (not vhdl-compose-configuration-hierarchical))
4009 :style toggle :selected vhdl-compose-configuration-hierarchical]
4010 ["Use Subconfiguration"
4011 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
4012 (not vhdl-compose-configuration-use-subconfiguration))
4013 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
4014 "--"
4015 ["Customize Group..." (customize-group 'vhdl-compose) t])
4016 ("Comment"
4017 ["Self Insert Comments"
4018 (customize-set-variable 'vhdl-self-insert-comments
4019 (not vhdl-self-insert-comments))
4020 :style toggle :selected vhdl-self-insert-comments]
4021 ["Prompt for Comments"
4022 (customize-set-variable 'vhdl-prompt-for-comments
4023 (not vhdl-prompt-for-comments))
4024 :style toggle :selected vhdl-prompt-for-comments]
4025 ["Inline Comment Column..."
4026 (customize-option 'vhdl-inline-comment-column) t]
4027 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
4028 "--"
4029 ["Customize Group..." (customize-group 'vhdl-comment) t])
4030 ("Beautify"
4031 ["Auto Align Templates"
4032 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
4033 :style toggle :selected vhdl-auto-align]
4034 ["Align Line Groups"
4035 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
4036 :style toggle :selected vhdl-align-groups]
4037 ["Group Separation String..."
4038 (customize-option 'vhdl-align-group-separate) t]
4039 ["Align Lines with Same Indent"
4040 (customize-set-variable 'vhdl-align-same-indent
4041 (not vhdl-align-same-indent))
4042 :style toggle :selected vhdl-align-same-indent]
4043 ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
4044 "--"
4045 ["Customize Group..." (customize-group 'vhdl-beautify) t])
4046 ("Highlight"
4047 ["Highlighting On/Off..."
4048 (customize-option
4049 (if (fboundp 'global-font-lock-mode)
4050 'global-font-lock-mode 'font-lock-auto-fontify)) t]
4051 ["Highlight Keywords"
4052 (progn (customize-set-variable 'vhdl-highlight-keywords
4053 (not vhdl-highlight-keywords))
4054 (vhdl-fontify-buffer))
4055 :style toggle :selected vhdl-highlight-keywords]
4056 ["Highlight Names"
4057 (progn (customize-set-variable 'vhdl-highlight-names
4058 (not vhdl-highlight-names))
4059 (vhdl-fontify-buffer))
4060 :style toggle :selected vhdl-highlight-names]
4061 ["Highlight Special Words"
4062 (progn (customize-set-variable 'vhdl-highlight-special-words
4063 (not vhdl-highlight-special-words))
4064 (vhdl-fontify-buffer))
4065 :style toggle :selected vhdl-highlight-special-words]
4066 ["Highlight Forbidden Words"
4067 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4068 (not vhdl-highlight-forbidden-words))
4069 (vhdl-fontify-buffer))
4070 :style toggle :selected vhdl-highlight-forbidden-words]
4071 ["Highlight Verilog Keywords"
4072 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4073 (not vhdl-highlight-verilog-keywords))
4074 (vhdl-fontify-buffer))
4075 :style toggle :selected vhdl-highlight-verilog-keywords]
4076 ["Highlight \"translate_off\""
4077 (progn (customize-set-variable 'vhdl-highlight-translate-off
4078 (not vhdl-highlight-translate-off))
4079 (vhdl-fontify-buffer))
4080 :style toggle :selected vhdl-highlight-translate-off]
4081 ["Case Sensitive Highlighting"
4082 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4083 (not vhdl-highlight-case-sensitive))
4084 (vhdl-fontify-buffer))
4085 :style toggle :selected vhdl-highlight-case-sensitive]
4086 ["Special Syntax Definition..."
4087 (customize-option 'vhdl-special-syntax-alist) t]
4088 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
4089 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
4090 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
4091 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
4092 "--"
4093 ["Customize Group..." (customize-group 'vhdl-highlight) t])
4094 ("Speedbar"
4095 ["Auto Open at Startup"
4096 (customize-set-variable 'vhdl-speedbar-auto-open
4097 (not vhdl-speedbar-auto-open))
4098 :style toggle :selected vhdl-speedbar-auto-open]
4099 ("Default Displaying Mode"
4100 ["Files"
4101 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
4102 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
4103 ["Directory Hierarchy"
4104 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
4105 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
4106 ["Project Hierarchy"
4107 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
4108 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
4109 ["Indentation Offset..."
4110 (customize-option 'speedbar-indentation-width) t]
4111 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
4112 ["Jump to Unit when Opening"
4113 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4114 (not vhdl-speedbar-jump-to-unit))
4115 :style toggle :selected vhdl-speedbar-jump-to-unit]
4116 ["Update Hierarchy on File Saving"
4117 (customize-set-variable 'vhdl-speedbar-update-on-saving
4118 (not vhdl-speedbar-update-on-saving))
4119 :style toggle :selected vhdl-speedbar-update-on-saving]
4120 ("Save in Cache File"
4121 ["Hierarchy Information"
4122 (customize-set-variable 'vhdl-speedbar-save-cache
4123 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4124 (delq 'hierarchy vhdl-speedbar-save-cache)
4125 (cons 'hierarchy vhdl-speedbar-save-cache)))
4126 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4127 ["Displaying Status"
4128 (customize-set-variable 'vhdl-speedbar-save-cache
4129 (if (memq 'display vhdl-speedbar-save-cache)
4130 (delq 'display vhdl-speedbar-save-cache)
4131 (cons 'display vhdl-speedbar-save-cache)))
4132 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4133 ["Cache File Name..."
4134 (customize-option 'vhdl-speedbar-cache-file-name) t]
4135 "--"
4136 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4137 ("Menu"
4138 ["Add Index Menu when Loading File"
4139 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4140 (vhdl-index-menu-init))
4141 :style toggle :selected vhdl-index-menu]
4142 ["Add Source File Menu when Loading File"
4143 (progn (customize-set-variable 'vhdl-source-file-menu
4144 (not vhdl-source-file-menu))
4145 (vhdl-add-source-files-menu))
4146 :style toggle :selected vhdl-source-file-menu]
4147 ["Add Hideshow Menu at Startup"
4148 (progn (customize-set-variable 'vhdl-hideshow-menu
4149 (not vhdl-hideshow-menu))
4150 (vhdl-activate-customizations))
4151 :style toggle :selected vhdl-hideshow-menu]
4152 ["Hide Everything Initially"
4153 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4154 :style toggle :selected vhdl-hide-all-init]
4155 "--"
4156 ["Customize Group..." (customize-group 'vhdl-menu) t])
4157 ("Print"
4158 ["In Two Column Format"
4159 (progn (customize-set-variable 'vhdl-print-two-column
4160 (not vhdl-print-two-column))
4161 (message "Activate new setting by saving options and restarting Emacs"))
4162 :style toggle :selected vhdl-print-two-column]
4163 ["Use Customized Faces"
4164 (progn (customize-set-variable 'vhdl-print-customize-faces
4165 (not vhdl-print-customize-faces))
4166 (message "Activate new setting by saving options and restarting Emacs"))
4167 :style toggle :selected vhdl-print-customize-faces]
4168 "--"
4169 ["Customize Group..." (customize-group 'vhdl-print) t])
4170 ("Miscellaneous"
4171 ["Use Intelligent Tab"
4172 (progn (customize-set-variable 'vhdl-intelligent-tab
4173 (not vhdl-intelligent-tab))
4174 (vhdl-activate-customizations))
4175 :style toggle :selected vhdl-intelligent-tab]
4176 ["Indent Syntax-Based"
4177 (customize-set-variable 'vhdl-indent-syntax-based
4178 (not vhdl-indent-syntax-based))
4179 :style toggle :selected vhdl-indent-syntax-based]
4180 ["Indent Comments Like Next Code Line"
4181 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4182 (not vhdl-indent-comment-like-next-code-line))
4183 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4184 ["Word Completion is Case Sensitive"
4185 (customize-set-variable 'vhdl-word-completion-case-sensitive
4186 (not vhdl-word-completion-case-sensitive))
4187 :style toggle :selected vhdl-word-completion-case-sensitive]
4188 ["Word Completion in Minibuffer"
4189 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4190 (not vhdl-word-completion-in-minibuffer))
4191 (message "Activate new setting by saving options and restarting Emacs"))
4192 :style toggle :selected vhdl-word-completion-in-minibuffer]
4193 ["Underscore is Part of Word"
4194 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4195 (not vhdl-underscore-is-part-of-word))
4196 (vhdl-activate-customizations))
4197 :style toggle :selected vhdl-underscore-is-part-of-word]
4198 "--"
4199 ["Customize Group..." (customize-group 'vhdl-misc) t])
4200 ["Related..." (customize-browse 'vhdl-related) t]
4201 "--"
4202 ["Save Options" customize-save-customized t]
4203 ["Activate Options" vhdl-activate-customizations t]
4204 ["Browse Options..." vhdl-customize t])))
4206 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4207 "VHDL Mode menu.")
4209 (defun vhdl-update-mode-menu ()
4210 "Update VHDL Mode menu."
4211 (interactive)
4212 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4213 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4214 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4215 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4216 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4219 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4221 (defconst vhdl-imenu-generic-expression
4223 ("Subprogram"
4224 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4226 ("Instance"
4227 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4229 ("Component"
4230 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4232 ("Procedural"
4233 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4235 ("Process"
4236 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4238 ("Block"
4239 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4241 ("Package"
4242 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4244 ("Configuration"
4245 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4247 ("Architecture"
4248 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4250 ("Entity"
4251 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4253 ("Context"
4254 "^\\s-*\\(context\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4257 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4259 (defun vhdl-index-menu-init ()
4260 "Initialize index menu."
4261 (set (make-local-variable 'imenu-case-fold-search) t)
4262 (set (make-local-variable 'imenu-generic-expression)
4263 vhdl-imenu-generic-expression)
4264 (when (and vhdl-index-menu (fboundp 'imenu))
4265 (imenu-add-to-menubar "Index")))
4267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4268 ;; Source file menu (using `easy-menu.el')
4270 (defvar vhdl-sources-menu nil)
4272 (defun vhdl-directory-files (directory &optional full match)
4273 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4274 message."
4275 (if (not (file-directory-p directory))
4276 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4277 (let ((dir (directory-files directory full match)))
4278 (setq dir (delete "." dir))
4279 (setq dir (delete ".." dir))
4280 dir)))
4282 (defun vhdl-get-source-files (&optional full directory)
4283 "Get list of VHDL source files in DIRECTORY or current directory."
4284 (let ((mode-alist auto-mode-alist)
4285 filename-regexp)
4286 ;; create regular expressions for matching file names
4287 (setq filename-regexp "\\`[^.].*\\(")
4288 (while mode-alist
4289 (when (eq (cdar mode-alist) 'vhdl-mode)
4290 (setq filename-regexp
4291 (concat filename-regexp (caar mode-alist) "\\|")))
4292 (setq mode-alist (cdr mode-alist)))
4293 (setq filename-regexp
4294 (concat (substring filename-regexp 0
4295 (string-match "\\\\|$" filename-regexp)) "\\)"))
4296 ;; find files
4297 (vhdl-directory-files
4298 (or directory default-directory) full filename-regexp)))
4300 (defun vhdl-add-source-files-menu ()
4301 "Scan directory for all VHDL source files and generate menu.
4302 The directory of the current source file is scanned."
4303 (interactive)
4304 (message "Scanning directory for source files ...")
4305 (let ((newmap (current-local-map))
4306 (file-list (vhdl-get-source-files))
4307 menu-list found)
4308 ;; Create list for menu
4309 (setq found nil)
4310 (while file-list
4311 (setq found t)
4312 (push (vector (car file-list) (list 'find-file (car file-list)) t)
4313 menu-list)
4314 (setq file-list (cdr file-list)))
4315 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4316 (when found (push "--" menu-list))
4317 (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
4318 (push "Sources" menu-list)
4319 ;; Create menu
4320 (easy-menu-add menu-list)
4321 (easy-menu-define vhdl-sources-menu newmap
4322 "VHDL source files menu" menu-list))
4323 (message ""))
4326 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4327 ;;; Mode definition
4328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4329 ;; performs all buffer local initializations
4331 ;;;###autoload
4332 (define-derived-mode vhdl-mode prog-mode
4333 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4334 (vhdl-electric-mode "e")
4335 (vhdl-stutter-mode "s"))
4336 "Major mode for editing VHDL code.
4338 Usage:
4339 ------
4341 TEMPLATE INSERTION (electrification):
4342 After typing a VHDL keyword and entering `SPC', you are prompted for
4343 arguments while a template is generated for that VHDL construct. Typing
4344 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4345 template generation. Optional arguments are indicated by square
4346 brackets and removed if the queried string is left empty. Prompts for
4347 mandatory arguments remain in the code if the queried string is left
4348 empty. They can be queried again by `C-c C-t C-q'. Enabled
4349 electrification is indicated by `/e' in the mode line.
4351 Typing `M-SPC' after a keyword inserts a space without calling the
4352 template generator. Automatic template generation (i.e.
4353 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4354 setting option `vhdl-electric-mode' (see OPTIONS).
4356 Template generators can be invoked from the VHDL menu, by key
4357 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4358 the keyword (i.e. first word of menu entry not in parenthesis) and
4359 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4360 conf, comp, cons, func, inst, pack, sig, var.
4362 Template styles can be customized in customization group
4363 `vhdl-template' \(see OPTIONS).
4366 HEADER INSERTION:
4367 A file header can be inserted by `C-c C-t C-h'. A file footer
4368 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4369 See customization group `vhdl-header'.
4372 STUTTERING:
4373 Double striking of some keys inserts cumbersome VHDL syntax elements.
4374 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4375 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4376 the mode line. The stuttering keys and their effects are:
4378 ;; --> \" : \" [ --> ( -- --> comment
4379 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4380 .. --> \" => \" ] --> ) --- --> horizontal line
4381 ,, --> \" <= \" ]] --> ] ---- --> display comment
4382 == --> \" == \" '' --> \\\"
4385 WORD COMPLETION:
4386 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4387 word in the buffer that starts alike, inserts it and adjusts case.
4388 Re-typing `TAB' toggles through alternative word completions. This also
4389 works in the minibuffer (i.e. in template generator prompts).
4391 Typing `TAB' after `(' looks for and inserts complete parenthesized
4392 expressions (e.g. for array index ranges). All keywords as well as
4393 standard types and subprograms of VHDL have predefined abbreviations
4394 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4395 beginning with \"std\").
4397 Typing `TAB' after a non-word character indents the line if at the
4398 beginning of a line (i.e. no preceding non-blank characters), and
4399 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4400 stop.
4403 COMMENTS:
4404 `--' puts a single comment.
4405 `---' draws a horizontal line for separating code segments.
4406 `----' inserts a display comment, i.e. two horizontal lines
4407 with a comment in between.
4408 `--CR' comments out code on that line. Re-hitting CR comments
4409 out following lines.
4410 `C-c C-c' comments out a region if not commented out,
4411 uncomments a region if already commented out. Option
4412 `comment-style' defines where the comment characters
4413 should be placed (beginning of line, indent, etc.).
4415 You are prompted for comments after object definitions (i.e. signals,
4416 variables, constants, ports) and after subprogram and process
4417 specifications if option `vhdl-prompt-for-comments' is non-nil.
4418 Comments are automatically inserted as additional labels (e.g. after
4419 begin statements) and as help comments if `vhdl-self-insert-comments' is
4420 non-nil.
4422 Inline comments (i.e. comments after a piece of code on the same line)
4423 are indented at least to `vhdl-inline-comment-column'. Comments go at
4424 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4425 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4426 in a comment automatically opens a new comment line. `M-q' re-fills
4427 multi-line comments.
4430 INDENTATION:
4431 `TAB' indents a line if at the beginning of the line. The amount of
4432 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4433 always indents the current line (is bound to `TAB' if option
4434 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4435 the entire region.
4437 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4438 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4439 indented normally (nil) or relative to the opening parenthesis (non-nil)
4440 according to option `vhdl-argument-list-indent'.
4442 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4443 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4444 and vice versa.
4446 Syntax-based indentation can be very slow in large files. Option
4447 `vhdl-indent-syntax-based' allows you to use faster but simpler indentation.
4449 Option `vhdl-indent-comment-like-next-code-line' controls whether
4450 comment lines are indented like the preceding or like the following code
4451 line.
4454 ALIGNMENT:
4455 The alignment functions align operators, keywords, and inline comments
4456 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4457 separated by blank lines, `C-c C-a C-i' a block of lines with same
4458 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4459 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4460 C-a C-d' all lines within the declarative part of a design unit. `C-c
4461 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4462 for a group of lines, and `C-c C-a M-c' for a region.
4464 If option `vhdl-align-groups' is non-nil, groups of code lines
4465 separated by special lines (see option `vhdl-align-group-separate') are
4466 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4467 blocks of lines with same indent are aligned separately. Some templates
4468 are automatically aligned after generation if option `vhdl-auto-align'
4469 is non-nil.
4471 Alignment tries to align inline comments at
4472 `vhdl-inline-comment-column' and tries inline comment not to exceed
4473 `vhdl-end-comment-column'.
4475 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4476 symbols are surrounded by one space, and multiple spaces are eliminated.
4479 CODE FILLING:
4480 Code filling allows you to condense code (e.g. sensitivity lists or port
4481 maps) by removing comments and newlines and re-wrapping so that all
4482 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4483 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4484 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4485 `C-c C-f M-f' an entire region.
4488 CODE BEAUTIFICATION:
4489 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4490 buffer respectively. This includes indentation, alignment, and case
4491 fixing. Code beautification can also be run non-interactively using the
4492 command:
4494 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4497 PORT TRANSLATION:
4498 Generic and port clauses from entity or component declarations can be
4499 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4500 as component instantiations and corresponding internal constants and
4501 signals, as a generic map with constants as actual generics, and as
4502 internal signal initializations (menu).
4504 To include formals in component instantiations, see option
4505 `vhdl-association-list-with-formals'. To include comments in pasting,
4506 see options `vhdl-include-...-comments'.
4508 A clause with several generic/port names on the same line can be
4509 flattened (`C-c C-p C-f') so that only one name per line exists. The
4510 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4511 outputs and vice versa, which can be useful in testbenches. (This
4512 reversion is done on the internal data structure and is only reflected
4513 in subsequent paste operations.)
4515 Names for actual ports, instances, testbenches, and
4516 design-under-test instances can be derived from existing names according
4517 to options `vhdl-...-name'. See customization group `vhdl-port'.
4520 SUBPROGRAM TRANSLATION:
4521 Similar functionality exists for copying/pasting the interface of
4522 subprograms (function/procedure). A subprogram interface can be copied
4523 and then pasted as a subprogram declaration, body or call (uses
4524 association list with formals).
4527 TESTBENCH GENERATION:
4528 A copied port can also be pasted as a testbench. The generated
4529 testbench includes an entity, an architecture, and an optional
4530 configuration. The architecture contains the component declaration and
4531 instantiation of the DUT as well as internal constant and signal
4532 declarations. Additional user-defined templates can be inserted. The
4533 names used for entity/architecture/configuration/DUT as well as the file
4534 structure to be generated can be customized. See customization group
4535 `vhdl-testbench'.
4538 KEY BINDINGS:
4539 Key bindings (`C-c ...') exist for most commands (see in menu).
4542 VHDL MENU:
4543 All commands can be found in the VHDL menu including their key bindings.
4546 FILE BROWSER:
4547 The speedbar allows browsing of directories and file contents. It can
4548 be accessed from the VHDL menu and is automatically opened if option
4549 `vhdl-speedbar-auto-open' is non-nil.
4551 In speedbar, open files and directories with `mouse-2' on the name and
4552 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4555 DESIGN HIERARCHY BROWSER:
4556 The speedbar can also be used for browsing the hierarchy of design units
4557 contained in the source files of the current directory or the specified
4558 projects (see option `vhdl-project-alist').
4560 The speedbar can be switched between file, directory hierarchy and
4561 project hierarchy browsing mode in the speedbar menu or by typing `f',
4562 `h' or `H' in speedbar.
4564 In speedbar, open design units with `mouse-2' on the name and browse
4565 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4566 from entities and components (in packages). Individual design units and
4567 complete designs can directly be compiled (\"Make\" menu entry).
4569 The hierarchy is automatically updated upon saving a modified source
4570 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4571 hierarchy is only updated for projects that have been opened once in the
4572 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4573 options in group `vhdl-speedbar').
4575 Simple design consistency checks are done during scanning, such as
4576 multiple declarations of the same unit or missing primary units that are
4577 required by secondary units.
4580 STRUCTURAL COMPOSITION:
4581 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4582 for a new component. Subcomponents (i.e. component declaration and
4583 instantiation) can be automatically placed from a previously read port
4584 \(`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4585 all subcomponents can be automatically connected using internal signals
4586 and ports (`C-c C-m C-w') following these rules:
4587 - subcomponent actual ports with same name are considered to be
4588 connected by a signal (internal signal or port)
4589 - signals that are only inputs to subcomponents are considered as
4590 inputs to this component -> input port created
4591 - signals that are only outputs from subcomponents are considered as
4592 outputs from this component -> output port created
4593 - signals that are inputs to AND outputs from subcomponents are
4594 considered as internal connections -> internal signal created
4596 Purpose: With appropriate naming conventions it is possible to
4597 create higher design levels with only a few mouse clicks or key
4598 strokes. A new design level can be created by simply generating a new
4599 component, placing the required subcomponents from the hierarchy
4600 browser, and wiring everything automatically.
4602 Note: Automatic wiring only works reliably on templates of new
4603 components and component instantiations that were created by VHDL mode.
4605 Component declarations can be placed in a components package (option
4606 `vhdl-use-components-package') which can be automatically generated for
4607 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4608 component instantiation is also supported (option
4609 `vhdl-use-direct-instantiation').
4611 Configuration declarations can automatically be generated either from
4612 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4613 the speedbar menu (for the architecture under the cursor). The
4614 configurations can optionally be hierarchical (i.e. include all
4615 component levels of a hierarchical design, option
4616 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4617 (option `vhdl-compose-configuration-use-subconfiguration'). For
4618 subcomponents in hierarchical configurations, the most-recently-analyzed
4619 (mra) architecture is selected. If another architecture is desired, it
4620 can be marked as most-recently-analyzed (speedbar menu) before
4621 generating the configuration.
4623 Note: Configurations of subcomponents (i.e. hierarchical configuration
4624 declarations) are currently not considered when displaying
4625 configurations in speedbar.
4627 See the options group `vhdl-compose' for all relevant user options.
4630 SOURCE FILE COMPILATION:
4631 The syntax of the current buffer can be analyzed by calling a VHDL
4632 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4633 option `vhdl-compiler'. The available compilers are listed in option
4634 `vhdl-compiler-alist' including all required compilation command,
4635 command options, compilation directory, and error message syntax
4636 information. New compilers can be added.
4638 All the source files of an entire design can be compiled by the `make'
4639 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4642 MAKEFILE GENERATION:
4643 Makefiles can be generated automatically by an internal generation
4644 routine (`C-c M-k'). The library unit dependency information is
4645 obtained from the hierarchy browser. Makefile generation can be
4646 customized for each compiler in option `vhdl-compiler-alist'.
4648 Makefile generation can also be run non-interactively using the
4649 command:
4651 emacs -batch -l ~/.emacs -l vhdl-mode
4652 [-compiler compilername] [-project projectname]
4653 -f vhdl-generate-makefile
4655 The Makefile's default target \"all\" compiles the entire design, the
4656 target \"clean\" removes it and the target \"library\" creates the
4657 library directory if not existent. These target names can be customized
4658 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4659 target for each primary library unit which allows selective compilation
4660 of this unit, its secondary units and its subhierarchy (example:
4661 compilation of a design specified by a configuration). User specific
4662 parts can be inserted into a Makefile with option
4663 `vhdl-makefile-generation-hook'.
4665 Limitations:
4666 - Only library units and dependencies within the current library are
4667 considered. Makefiles for designs that span multiple libraries are
4668 not (yet) supported.
4669 - Only one-level configurations are supported (also hierarchical),
4670 but configurations that go down several levels are not.
4671 - The \"others\" keyword in configurations is not supported.
4674 PROJECTS:
4675 Projects can be defined in option `vhdl-project-alist' and a current
4676 project be selected using option `vhdl-project' (permanently) or from
4677 the menu or speedbar (temporarily). For each project, title and
4678 description strings (for the file headers), source files/directories
4679 (for the hierarchy browser and Makefile generation), library name, and
4680 compiler-dependent options, exceptions and compilation directory can be
4681 specified. Compilation settings overwrite the settings of option
4682 `vhdl-compiler-alist'.
4684 Project setups can be exported (i.e. written to a file) and imported.
4685 Imported setups are not automatically saved in `vhdl-project-alist' but
4686 can be saved afterwards in its customization buffer. When starting
4687 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4688 vhdl-mode\") in a directory with an existing project setup file, it is
4689 automatically loaded and its project activated if option
4690 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4691 files can be specified in option `vhdl-project-file-name'. Multiple
4692 project setups can be automatically loaded from global directories.
4693 This is an alternative to specifying project setups with option
4694 `vhdl-project-alist'.
4697 SPECIAL MENUES:
4698 As an alternative to the speedbar, an index menu can be added (set
4699 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4700 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4701 file) for browsing the file contents (is not populated if buffer is
4702 larger than 256000). Also, a source file menu can be
4703 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4704 current directory for VHDL source files.
4707 VHDL STANDARDS:
4708 The VHDL standards to be used are specified in option `vhdl-standard'.
4709 Available standards are: VHDL'87/'93(02)/'08, VHDL-AMS, and Math Packages.
4712 KEYWORD CASE:
4713 Lower and upper case for keywords and standardized types, attributes,
4714 and enumeration values is supported. If the option
4715 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4716 lower case and are converted into upper case automatically (not for
4717 types, attributes, and enumeration values). The case of keywords,
4718 types, attributes,and enumeration values can be fixed for an entire
4719 region (menu) or buffer (`C-c C-x C-c') according to the options
4720 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4723 HIGHLIGHTING (fontification):
4724 Keywords and standardized types, attributes, enumeration values, and
4725 function names (controlled by option `vhdl-highlight-keywords'), as well
4726 as comments, strings, and template prompts are highlighted using
4727 different colors. Unit, subprogram, signal, variable, constant,
4728 parameter and generic/port names in declarations as well as labels are
4729 highlighted if option `vhdl-highlight-names' is non-nil.
4731 Additional reserved words or words with a forbidden syntax (e.g. words
4732 that should be avoided) can be specified in option
4733 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4734 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4735 keywords are highlighted as forbidden words if option
4736 `vhdl-highlight-verilog-keywords' is non-nil.
4738 Words with special syntax can be highlighted by specifying their
4739 syntax and color in option `vhdl-special-syntax-alist' and by setting
4740 option `vhdl-highlight-special-words' to non-nil. This allows you to
4741 establish some naming conventions (e.g. to distinguish different kinds
4742 of signals or other objects by using name suffices) and to support them
4743 visually.
4745 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4746 to support case-sensitive highlighting. However, keywords are then only
4747 highlighted if written in lower case.
4749 Code between \"translate_off\" and \"translate_on\" pragmas is
4750 highlighted using a different background color if option
4751 `vhdl-highlight-translate-off' is non-nil.
4753 For documentation and customization of the used colors see
4754 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4755 highlighting of matching parenthesis, see customization group
4756 `paren-showing'. Automatic buffer highlighting is turned on/off by
4757 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4760 USER MODELS:
4761 VHDL models (templates) can be specified by the user and made accessible
4762 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4763 electrification. See option `vhdl-model-alist'.
4766 HIDE/SHOW:
4767 The code of blocks, processes, subprograms, component declarations and
4768 instantiations, generic/port clauses, and configuration declarations can
4769 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4770 the code (see customization group `vhdl-menu'). XEmacs: limited
4771 functionality due to old `hideshow.el' package.
4774 CODE UPDATING:
4775 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4776 current process, `C-c C-u M-s' of all processes in the current buffer.
4777 Limitations:
4778 - Only declared local signals (ports, signals declared in
4779 architecture and blocks) are automatically inserted.
4780 - Global signals declared in packages are not automatically inserted.
4781 Insert them once manually (will be kept afterwards).
4782 - Out parameters of procedures are considered to be read.
4783 Use option `vhdl-entity-file-name' to specify the entity file name
4784 \(used to obtain the port names).
4785 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4786 specify whether to include array indices and record fields in
4787 sensitivity lists.
4790 CODE FIXING:
4791 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4792 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4795 PRINTING:
4796 PostScript printing with different faces (an optimized set of faces is
4797 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4798 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4799 PostScript printing commands. Option `vhdl-print-two-column' defines
4800 appropriate default settings for nice landscape two-column printing.
4801 The paper format can be set by option `ps-paper-type'. Do not forget to
4802 switch `ps-print-color-p' to nil for printing on black-and-white
4803 printers.
4806 OPTIONS:
4807 User options allow customization of VHDL Mode. All options are
4808 accessible from the \"Options\" menu entry. Simple options (switches
4809 and choices) can directly be changed, while for complex options a
4810 customization buffer is opened. Changed options can be saved for future
4811 sessions using the \"Save Options\" menu entry.
4813 Options and their detailed descriptions can also be accessed by using
4814 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4815 customize-group' for groups). Some customizations only take effect
4816 after some action (read the NOTE in the option documentation).
4817 Customization can also be done globally (i.e. site-wide, read the
4818 INSTALL file).
4820 Not all options are described in this documentation, so go and see
4821 what other useful user options there are (`M-x vhdl-customize' or menu)!
4824 FILE EXTENSIONS:
4825 As default, files with extensions \".vhd\" and \".vhdl\" are
4826 automatically recognized as VHDL source files. To add an extension
4827 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4829 \(push '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist)
4832 HINTS:
4833 - To start Emacs with open VHDL hierarchy browser without having to load
4834 a VHDL file first, use the command:
4836 emacs -l vhdl-mode -f speedbar-frame-mode
4838 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4840 - Some features only work on properly indented code.
4843 RELEASE NOTES:
4844 See also the release notes (menu) for added features in new releases.
4847 Maintenance:
4848 ------------
4850 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4851 Add a description of the problem and include a reproducible test case.
4853 Questions and enhancement requests can be sent to <reto@gnu.org>.
4855 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4856 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4857 releases. You are kindly invited to participate in beta testing. Subscribe
4858 to above mailing lists by sending an email to <reto@gnu.org>.
4860 VHDL Mode is officially distributed at
4861 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4862 where the latest version can be found.
4865 Known problems:
4866 ---------------
4868 - XEmacs: Incorrect start-up when automatically opening speedbar.
4869 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4870 - Indentation incorrect for new 'postponed' VHDL keyword.
4871 - Indentation incorrect for 'protected body' construct.
4874 The VHDL Mode Authors
4875 Reto Zimmermann and Rod Whitby
4877 Key bindings:
4878 -------------
4880 \\{vhdl-mode-map}"
4881 :abbrev-table vhdl-mode-abbrev-table
4883 ;; set local variables
4884 (set (make-local-variable 'paragraph-start)
4885 "\\s-*\\(--+\\s-*$\\|$\\)")
4886 (set (make-local-variable 'paragraph-separate) paragraph-start)
4887 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4888 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4889 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4890 (set (make-local-variable 'comment-start) "--")
4891 (set (make-local-variable 'comment-end) "")
4892 (when vhdl-emacs-21
4893 (set (make-local-variable 'comment-padding) ""))
4894 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4895 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4896 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4897 (set (make-local-variable 'comment-multi-line) nil)
4898 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4899 (set (make-local-variable 'hippie-expand-verbose) nil)
4901 ;; setup the comment indent variable in a Emacs version portable way
4902 ;; ignore any byte compiler warnings you might get here
4903 (when (boundp 'comment-indent-function)
4904 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4906 ;; initialize font locking
4907 (set (make-local-variable 'font-lock-defaults)
4908 (list
4909 '(nil vhdl-font-lock-keywords) nil
4910 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4911 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4912 (set (make-local-variable 'syntax-propertize-function)
4913 (syntax-propertize-rules
4914 ;; Mark single quotes as having string quote syntax in
4915 ;; 'c' instances.
4916 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4917 (set (make-local-variable 'font-lock-syntactic-keywords)
4918 vhdl-font-lock-syntactic-keywords))
4919 (unless vhdl-emacs-21
4920 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4921 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4922 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4923 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4925 ;; variables for source file compilation
4926 (when vhdl-compile-use-local-error-regexp
4927 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4928 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4930 ;; add index menu
4931 (vhdl-index-menu-init)
4932 ;; add source file menu
4933 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4934 ;; add VHDL menu
4935 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4936 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4937 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4938 ;; initialize hideshow and add menu
4939 (vhdl-hideshow-init)
4940 (run-hooks 'menu-bar-update-hook)
4942 ;; miscellaneous
4943 (vhdl-ps-print-init)
4944 (vhdl-write-file-hooks-init)
4945 (message "VHDL Mode %s.%s" vhdl-version
4946 (if noninteractive "" " See menu for documentation and release notes.")))
4948 (defun vhdl-activate-customizations ()
4949 "Activate all customizations on local variables."
4950 (interactive)
4951 (vhdl-mode-map-init)
4952 (use-local-map vhdl-mode-map)
4953 (set-syntax-table vhdl-mode-syntax-table)
4954 (setq comment-column vhdl-inline-comment-column)
4955 (setq end-comment-column vhdl-end-comment-column)
4956 (vhdl-write-file-hooks-init)
4957 (vhdl-update-mode-menu)
4958 (vhdl-hideshow-init)
4959 (run-hooks 'menu-bar-update-hook))
4961 (defun vhdl-write-file-hooks-init ()
4962 "Add/remove hooks when buffer is saved."
4963 (if vhdl-modify-date-on-saving
4964 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4965 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4966 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4967 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4969 (defun vhdl-process-command-line-option (option)
4970 "Process command line options for VHDL Mode."
4971 (cond
4972 ;; set compiler
4973 ((equal option "-compiler")
4974 (vhdl-set-compiler (car command-line-args-left))
4975 (setq command-line-args-left (cdr command-line-args-left)))
4976 ;; set project
4977 ((equal option "-project")
4978 (vhdl-set-project (car command-line-args-left))
4979 (setq command-line-args-left (cdr command-line-args-left)))))
4981 ;; make Emacs process VHDL Mode options
4982 (setq command-switch-alist
4983 (append command-switch-alist
4984 '(("-compiler" . vhdl-process-command-line-option)
4985 ("-project" . vhdl-process-command-line-option))))
4988 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4989 ;;; Keywords and standardized words
4990 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4992 (defconst vhdl-02-keywords
4994 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4995 "assert" "attribute"
4996 "begin" "block" "body" "buffer" "bus"
4997 "case" "component" "configuration" "constant"
4998 "disconnect" "downto"
4999 "else" "elsif" "end" "entity" "exit"
5000 "file" "for" "function"
5001 "generate" "generic" "group" "guarded"
5002 "if" "impure" "in" "inertial" "inout" "is"
5003 "label" "library" "linkage" "literal" "loop"
5004 "map" "mod"
5005 "nand" "new" "next" "nor" "not" "null"
5006 "of" "on" "open" "or" "others" "out"
5007 "package" "port" "postponed" "procedure" "process" "protected" "pure"
5008 "range" "record" "register" "reject" "rem" "report" "return"
5009 "rol" "ror"
5010 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
5011 "then" "to" "transport" "type"
5012 "unaffected" "units" "until" "use"
5013 "variable"
5014 "wait" "when" "while" "with"
5015 "xnor" "xor"
5017 "List of VHDL'02 keywords.")
5019 (defconst vhdl-08-keywords
5021 "context" "force" "property" "release" "sequence"
5023 "List of VHDL'08 keywords.")
5025 (defconst vhdl-ams-keywords
5027 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
5028 "reference" "spectrum" "subnature" "terminal" "through"
5029 "tolerance"
5031 "List of VHDL-AMS keywords.")
5033 (defconst vhdl-verilog-keywords
5035 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
5036 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
5037 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
5038 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
5039 "endprimitive" "endspecify" "endtable" "endtask" "event"
5040 "for" "force" "forever" "fork" "function"
5041 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
5042 "macromodule" "makefile" "medium" "module"
5043 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
5044 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
5045 "pullup"
5046 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
5047 "rtranif0" "rtranif1"
5048 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
5049 "strong1" "supply" "supply0" "supply1"
5050 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5051 "triand" "trior" "trireg"
5052 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
5054 "List of Verilog keywords as candidate for additional reserved words.")
5056 (defconst vhdl-02-types
5058 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
5059 "real" "time" "natural" "positive" "string" "line" "text" "side"
5060 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
5061 "std_logic" "std_logic_vector"
5062 "std_ulogic" "std_ulogic_vector"
5064 "List of VHDL'02 standardized types.")
5066 (defconst vhdl-08-types
5068 "boolean_vector" "integer_vector" "real_vector" "time_vector"
5070 "List of VHDL'08 standardized types.")
5072 (defconst vhdl-ams-types
5073 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5075 ;; package `standard'
5076 "domain_type" "real_vector"
5077 ;; package `energy_systems'
5078 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5079 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5080 "real_across_vector" "real_through_vector"
5081 ;; package `electrical_systems'
5082 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5083 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5084 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5085 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5086 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5087 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5088 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5089 "electric_flux_density_vector" "electric_field_strength_vector"
5090 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5091 "inductance_vector" "reluctance_vector" "ground"
5092 ;; package `mechanical_systems'
5093 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5094 "damping" "momentum" "angle" "torque" "angular_velocity"
5095 "angular_acceleration" "moment_inertia" "angular_momentum"
5096 "angular_stiffness" "angular_damping" "translational"
5097 "translational_vector" "translational_velocity"
5098 "translational_velocity_vector" "rotational" "rotational_vector"
5099 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5100 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5101 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5102 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5103 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5104 "angular_momentum_vector" "angular_stiffness_vector"
5105 "angular_damping_vector" "anchor" "translational_v_ref"
5106 "rotational_v_ref" "translational_v" "rotational_v"
5107 ;; package `radiant_systems'
5108 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5109 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5110 "illuminance_vector" "irradiance_vector"
5111 ;; package `thermal_systems'
5112 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5113 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5114 "heat_flow_vector" "thermal_capacitance_vector"
5115 "thermal_resistance_vector" "thermal_conductance_vector"
5116 ;; package `fluidic_systems'
5117 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5118 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5119 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5120 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5121 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5122 "density_vector" "viscosity_vector" "fresistance_vector"
5123 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5124 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5125 "cfinertance_vector"
5127 "List of VHDL-AMS standardized types.")
5129 (defconst vhdl-math-types
5131 "complex" "complex_polar" "positive_real" "principal_value"
5133 "List of Math Packages standardized types.")
5135 (defconst vhdl-02-attributes
5137 "base" "left" "right" "high" "low" "pos" "val" "succ"
5138 "pred" "leftof" "rightof" "range" "reverse_range"
5139 "length" "delayed" "stable" "quiet" "transaction"
5140 "event" "active" "last_event" "last_active" "last_value"
5141 "driving" "driving_value" "ascending" "value" "image"
5142 "simple_name" "instance_name" "path_name"
5143 "foreign"
5145 "List of VHDL'02 standardized attributes.")
5147 (defconst vhdl-08-attributes
5149 "instance_name" "path_name"
5151 "List of VHDL'08 standardized attributes.")
5153 (defconst vhdl-ams-attributes
5155 "across" "through"
5156 "reference" "contribution" "tolerance"
5157 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5158 "ramp" "slew"
5160 "List of VHDL-AMS standardized attributes.")
5162 (defconst vhdl-02-enum-values
5164 "true" "false"
5165 "note" "warning" "error" "failure"
5166 "read_mode" "write_mode" "append_mode"
5167 "open_ok" "status_error" "name_error" "mode_error"
5168 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5169 "right" "left"
5171 "List of VHDL'02 standardized enumeration values.")
5173 (defconst vhdl-ams-enum-values
5175 "quiescent_domain" "time_domain" "frequency_domain"
5176 ;; from `nature_pkg' package
5177 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5179 "List of VHDL-AMS standardized enumeration values.")
5181 (defconst vhdl-ams-constants
5182 ;; standard: IEEE Std 1076.1.1-2004
5184 ;; package `fundamental_constants'
5185 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5186 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5187 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5188 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5189 ;; package `material_constants'
5190 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5191 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5192 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5194 "List of VHDL-AMS standardized constants.")
5196 (defconst vhdl-math-constants
5197 ;; standard: IEEE Std 1076.2-1996
5199 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5200 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5201 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5202 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5203 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5204 "math_sqrt_pi"
5206 "List of Math Packages standardized constants.")
5208 (defconst vhdl-02-functions
5210 "now" "resolved" "rising_edge" "falling_edge"
5211 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5212 "endfile"
5213 "resize" "is_X" "std_match"
5214 "shift_left" "shift_right" "rotate_left" "rotate_right"
5215 "to_unsigned" "to_signed" "to_integer"
5216 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5217 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5218 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5219 "shl" "shr" "ext" "sxt"
5220 "deallocate"
5222 "List of VHDL'02 standardized functions.")
5224 (defconst vhdl-08-functions
5226 "finish" "flush" "justify" "maximum" "minimum"
5227 "resolution_limit" "rising_edge" "stop" "swrite"
5228 "tee" "to_binarystring" "to_bstring" "to_hexstring" "to_hstring"
5229 "to_octalstring" "to_ostring" "to_string"
5231 "List of VHDL'08 standardized functions.")
5233 (defconst vhdl-ams-functions
5235 ;; package `standard'
5236 "frequency"
5238 "List of VHDL-AMS standardized functions.")
5240 (defconst vhdl-math-functions
5241 ;; standard: IEEE Std 1076.2-1996
5243 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5244 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5245 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5246 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5247 "tan" "tanh" "trunc" "uniform"
5249 "List of Math Packages standardized functions.")
5251 (defconst vhdl-02-packages
5253 "std_logic_1164" "numeric_std" "numeric_bit"
5254 "standard" "textio"
5255 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5256 "std_logic_misc" "std_logic_textio"
5257 "ieee" "std" "work"
5259 "List of VHDL'02 standardized packages and libraries.")
5261 (defconst vhdl-08-packages
5263 "env" "numeric_std_signed" "numeric_std_unsigned"
5264 "ieee_bit_context" "ieee_std_context" ;; contexts
5266 "List of VHDL'08 standardized packages and libraries.")
5268 (defconst vhdl-ams-packages
5270 "fundamental_constants" "material_constants" "energy_systems"
5271 "electrical_systems" "mechanical_systems" "radiant_systems"
5272 "thermal_systems" "fluidic_systems"
5274 "List of VHDL-AMS standardized packages and libraries.")
5276 (defconst vhdl-math-packages
5278 "math_real" "math_complex"
5280 "List of Math Packages standardized packages and libraries.")
5282 (defconst vhdl-08-directives
5284 "author" "author_info" "begin" "begin_protected" "comment"
5285 "data_block" "data_keyname" "data_keyowner" "data_method"
5286 "decrypt_license" "digest_block" "digest_key_method" "digest_keyname"
5287 "digest_keyowner" "digest_method"
5288 "encoding" "encrypt_agent" "encrypt_agent_info" "end" "end_protected"
5289 "key_block" "key_keyname" "key_keyowner" "key_method"
5290 "runtime_license" "viewport"
5292 "List of VHDL'08 standardized tool directives.")
5294 (defvar vhdl-keywords nil
5295 "List of VHDL keywords.")
5297 (defvar vhdl-types nil
5298 "List of VHDL standardized types.")
5300 (defvar vhdl-attributes nil
5301 "List of VHDL standardized attributes.")
5303 (defvar vhdl-enum-values nil
5304 "List of VHDL standardized enumeration values.")
5306 (defvar vhdl-constants nil
5307 "List of VHDL standardized constants.")
5309 (defvar vhdl-functions nil
5310 "List of VHDL standardized functions.")
5312 (defvar vhdl-packages nil
5313 "List of VHDL standardized packages and libraries.")
5315 (defvar vhdl-directives nil
5316 "List of VHDL standardized packages and libraries.")
5318 (defvar vhdl-reserved-words nil
5319 "List of additional reserved words.")
5321 (defvar vhdl-keywords-regexp nil
5322 "Regexp for VHDL keywords.")
5324 (defvar vhdl-types-regexp nil
5325 "Regexp for VHDL standardized types.")
5327 (defvar vhdl-attributes-regexp nil
5328 "Regexp for VHDL standardized attributes.")
5330 (defvar vhdl-enum-values-regexp nil
5331 "Regexp for VHDL standardized enumeration values.")
5333 (defvar vhdl-constants-regexp nil
5334 "Regexp for VHDL standardized constants.")
5336 (defvar vhdl-functions-regexp nil
5337 "Regexp for VHDL standardized functions.")
5339 (defvar vhdl-packages-regexp nil
5340 "Regexp for VHDL standardized packages and libraries.")
5342 (defvar vhdl-reserved-words-regexp nil
5343 "Regexp for additional reserved words.")
5345 (defvar vhdl-directive-keywords-regexp nil
5346 "Regexp for compiler directive keywords.")
5348 (defun vhdl-upcase-list (condition list)
5349 "Upcase all elements in LIST based on CONDITION."
5350 (when condition
5351 (let ((tmp-list list))
5352 (while tmp-list
5353 (setcar tmp-list (upcase (car tmp-list)))
5354 (setq tmp-list (cdr tmp-list)))))
5355 list)
5357 (defun vhdl-words-init ()
5358 "Initialize reserved words."
5359 (setq vhdl-keywords
5360 (vhdl-upcase-list
5361 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5362 (append vhdl-02-keywords
5363 (when (vhdl-standard-p '08) vhdl-08-keywords)
5364 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5365 (setq vhdl-types
5366 (vhdl-upcase-list
5367 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5368 (append vhdl-02-types
5369 (when (vhdl-standard-p '08) vhdl-08-types)
5370 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5371 (when (vhdl-standard-p 'math) vhdl-math-types))))
5372 (setq vhdl-attributes
5373 (vhdl-upcase-list
5374 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5375 (append vhdl-02-attributes
5376 (when (vhdl-standard-p '08) vhdl-08-attributes)
5377 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5378 (setq vhdl-enum-values
5379 (vhdl-upcase-list
5380 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5381 (append vhdl-02-enum-values
5382 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5383 (setq vhdl-constants
5384 (vhdl-upcase-list
5385 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5386 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5387 (when (vhdl-standard-p 'math) vhdl-math-constants)
5388 '(""))))
5389 (setq vhdl-functions
5390 (append vhdl-02-functions
5391 (when (vhdl-standard-p '08) vhdl-08-functions)
5392 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5393 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5394 (setq vhdl-packages
5395 (append vhdl-02-packages
5396 (when (vhdl-standard-p '08) vhdl-08-packages)
5397 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5398 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5399 (setq vhdl-directives
5400 (append (when (vhdl-standard-p '08) vhdl-08-directives)))
5401 (setq vhdl-reserved-words
5402 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5403 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5404 '("")))
5405 (setq vhdl-keywords-regexp
5406 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5407 (setq vhdl-types-regexp
5408 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5409 (setq vhdl-attributes-regexp
5410 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5411 (setq vhdl-enum-values-regexp
5412 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5413 (setq vhdl-constants-regexp
5414 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5415 (setq vhdl-functions-regexp
5416 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5417 (setq vhdl-packages-regexp
5418 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5419 (setq vhdl-reserved-words-regexp
5420 (concat "\\<\\("
5421 (unless (equal vhdl-forbidden-syntax "")
5422 (concat vhdl-forbidden-syntax "\\|"))
5423 (regexp-opt vhdl-reserved-words)
5424 "\\)\\>"))
5425 (setq vhdl-directive-keywords-regexp
5426 (concat "\\<\\(" (mapconcat 'regexp-quote
5427 vhdl-directive-keywords "\\|") "\\)\\>"))
5428 (vhdl-abbrev-list-init))
5430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5431 ;; Words to expand
5433 (defvar vhdl-abbrev-list nil
5434 "Predefined abbreviations for VHDL.")
5436 (defun vhdl-abbrev-list-init ()
5437 (setq vhdl-abbrev-list
5438 (append
5439 (list vhdl-upper-case-keywords) vhdl-keywords
5440 (list vhdl-upper-case-types) vhdl-types
5441 (list vhdl-upper-case-attributes) vhdl-attributes
5442 (list vhdl-upper-case-enum-values) vhdl-enum-values
5443 (list vhdl-upper-case-constants) vhdl-constants
5444 (list nil) vhdl-functions
5445 (list nil) vhdl-packages
5446 (list nil) vhdl-directives)))
5448 ;; initialize reserved words for VHDL Mode
5449 (vhdl-words-init)
5452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5453 ;;; Indentation
5454 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5456 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5457 ;; Syntax analysis
5459 ;; constant regular expressions for looking at various constructs
5461 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5462 "Regexp describing a VHDL symbol.
5463 We cannot use just `word' syntax class since `_' cannot be in word
5464 class. Putting underscore in word class breaks forward word movement
5465 behavior that users are familiar with.")
5467 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5468 "Regexp describing a case statement header key.")
5470 (defconst vhdl-label-key
5471 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5472 "Regexp describing a VHDL label.")
5474 ;; Macro definitions:
5476 (defmacro vhdl-point (position)
5477 "Return the value of point at certain commonly referenced POSITIONs.
5478 POSITION can be one of the following symbols:
5480 bol -- beginning of line
5481 eol -- end of line
5482 bod -- beginning of defun
5483 boi -- back to indentation
5484 eoi -- last whitespace on line
5485 ionl -- indentation of next line
5486 iopl -- indentation of previous line
5487 bonl -- beginning of next line
5488 bopl -- beginning of previous line
5490 This function does not modify point or mark."
5491 (or (and (eq 'quote (car-safe position))
5492 (null (cddr position)))
5493 (error "ERROR: Bad buffer position requested: %s" position))
5494 (setq position (nth 1 position))
5495 `(let ((here (point)))
5496 ,@(cond
5497 ((eq position 'bol) '((beginning-of-line)))
5498 ((eq position 'eol) '((end-of-line)))
5499 ((eq position 'bod) '((save-match-data
5500 (vhdl-beginning-of-defun))))
5501 ((eq position 'boi) '((back-to-indentation)))
5502 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5503 ((eq position 'bonl) '((forward-line 1)))
5504 ((eq position 'bopl) '((forward-line -1)))
5505 ((eq position 'iopl)
5506 '((forward-line -1)
5507 (back-to-indentation)))
5508 ((eq position 'ionl)
5509 '((forward-line 1)
5510 (back-to-indentation)))
5511 (t (error "ERROR: Unknown buffer position requested: %s" position))
5513 (prog1
5514 (point)
5515 (goto-char here))
5516 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5517 ;; doesn't hurt for v19
5518 ,@nil
5521 (defmacro vhdl-safe (&rest body)
5522 "Safely execute BODY, return nil if an error occurred."
5523 `(condition-case nil
5524 (progn ,@body)
5525 (error nil)))
5527 (defmacro vhdl-add-syntax (symbol &optional relpos)
5528 "A simple macro to append the syntax in SYMBOL to the syntax list.
5529 Try to increase performance by using this macro."
5530 `(setq vhdl-syntactic-context
5531 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5533 (defmacro vhdl-has-syntax (symbol)
5534 "A simple macro to return check the syntax list.
5535 Try to increase performance by using this macro."
5536 `(assoc ,symbol vhdl-syntactic-context))
5538 ;; Syntactic element offset manipulation:
5540 (defun vhdl-read-offset (langelem)
5541 "Read new offset value for LANGELEM from minibuffer.
5542 Return a valid value only."
5543 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5544 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5545 (prompt "Offset: ")
5546 offset input interned)
5547 (while (not offset)
5548 (setq input (read-string prompt oldoff)
5549 offset (cond ((string-equal "+" input) '+)
5550 ((string-equal "-" input) '-)
5551 ((string-equal "++" input) '++)
5552 ((string-equal "--" input) '--)
5553 ((string-match "^-?[0-9]+$" input)
5554 (string-to-number input))
5555 ((fboundp (setq interned (intern input)))
5556 interned)
5557 ((boundp interned) interned)
5558 ;; error, but don't signal one, keep trying
5559 ;; to read an input value
5560 (t (ding)
5561 (setq prompt errmsg)
5562 nil))))
5563 offset))
5565 (defun vhdl-set-offset (symbol offset &optional add-p)
5566 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5567 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5568 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5569 `vhdl-offsets-alist' if it doesn't already appear there."
5570 (interactive
5571 (let* ((langelem
5572 (intern (completing-read
5573 (concat "Syntactic symbol to change"
5574 (if current-prefix-arg " or add" "")
5575 ": ")
5576 (mapcar
5577 (function
5578 (lambda (langelem)
5579 (cons (format "%s" (car langelem)) nil)))
5580 vhdl-offsets-alist)
5581 nil (not current-prefix-arg)
5582 ;; initial contents tries to be the last element
5583 ;; on the syntactic analysis list for the current
5584 ;; line
5585 (let* ((syntax (vhdl-get-syntactic-context))
5586 (len (length syntax))
5587 (ic (format "%s" (car (nth (1- len) syntax)))))
5590 (offset (vhdl-read-offset langelem)))
5591 (list langelem offset current-prefix-arg)))
5592 ;; sanity check offset
5593 (or (eq offset '+)
5594 (eq offset '-)
5595 (eq offset '++)
5596 (eq offset '--)
5597 (integerp offset)
5598 (fboundp offset)
5599 (boundp offset)
5600 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5601 offset))
5602 (let ((entry (assq symbol vhdl-offsets-alist)))
5603 (if entry
5604 (setcdr entry offset)
5605 (if add-p
5606 (setq vhdl-offsets-alist
5607 (cons (cons symbol offset) vhdl-offsets-alist))
5608 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5609 (vhdl-keep-region-active))
5611 (defun vhdl-set-style (style &optional local)
5612 "Set `vhdl-mode' variables to use one of several different indentation styles.
5613 STYLE is a string representing the desired style and optional LOCAL is
5614 a flag which, if non-nil, means to make the style variables being
5615 changed buffer local, instead of the default, which is to set the
5616 global variables. Interactively, the flag comes from the prefix
5617 argument. The styles are chosen from the `vhdl-style-alist' variable."
5618 (interactive (list (completing-read "Use which VHDL indentation style? "
5619 vhdl-style-alist nil t)
5620 current-prefix-arg))
5621 (let ((vars (cdr (assoc style vhdl-style-alist))))
5622 (or vars
5623 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5624 ;; set all the variables
5625 (mapc
5626 (function
5627 (lambda (varentry)
5628 (let ((var (car varentry))
5629 (val (cdr varentry)))
5630 ;; special case for vhdl-offsets-alist
5631 (if (not (eq var 'vhdl-offsets-alist))
5632 (set (if local (make-local-variable var) var) val)
5633 ;; reset vhdl-offsets-alist to the default value first
5634 (set (if local (make-local-variable var) var)
5635 (copy-alist vhdl-offsets-alist-default))
5636 ;; now set the langelems that are different
5637 (mapcar
5638 (function
5639 (lambda (langentry)
5640 (let ((langelem (car langentry))
5641 (offset (cdr langentry)))
5642 (vhdl-set-offset langelem offset)
5644 val))
5646 vars))
5647 (vhdl-keep-region-active))
5649 (defun vhdl-get-offset (langelem)
5650 "Get offset from LANGELEM which is a cons cell of the form:
5651 \(SYMBOL . RELPOS). The symbol is matched against
5652 vhdl-offsets-alist and the offset found there is either returned,
5653 or added to the indentation at RELPOS. If RELPOS is nil, then
5654 the offset is simply returned."
5655 (let* ((symbol (car langelem))
5656 (relpos (cdr langelem))
5657 (match (assq symbol vhdl-offsets-alist))
5658 (offset (cdr-safe match)))
5659 ;; offset can be a number, a function, a variable, or one of the
5660 ;; symbols + or -
5661 (cond
5662 ((not match)
5663 (if vhdl-strict-syntax-p
5664 (error "ERROR: Don't know how to indent a %s" symbol)
5665 (setq offset 0
5666 relpos 0)))
5667 ((eq offset '+) (setq offset vhdl-basic-offset))
5668 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5669 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5670 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5671 ((and (not (numberp offset))
5672 (fboundp offset))
5673 (setq offset (funcall offset langelem)))
5674 ((not (numberp offset))
5675 (setq offset (eval offset)))
5677 (+ (if (and relpos
5678 (< relpos (vhdl-point 'bol)))
5679 (save-excursion
5680 (goto-char relpos)
5681 (current-column))
5683 offset)))
5685 ;; Syntactic support functions:
5687 (defun vhdl-in-comment-p (&optional pos)
5688 "Check if point is in a comment (include multi-line comments)."
5689 (let ((parse (lambda (p)
5690 (let ((c (char-after p)))
5691 (or (and c (eq (char-syntax c) ?<))
5692 (nth 4 (parse-partial-sexp
5693 (save-excursion
5694 (beginning-of-defun)
5695 (point)) p)))))))
5696 (save-excursion
5697 (goto-char (or pos (point)))
5698 (or (funcall parse (point))
5699 ;; `parse-partial-sexp's notion of comments doesn't span lines
5700 (progn
5701 (back-to-indentation)
5702 (unless (eolp)
5703 (forward-char)
5704 (funcall parse (point))))))))
5706 (defun vhdl-in-string-p ()
5707 "Check if point is in a string."
5708 (eq (vhdl-in-literal) 'string))
5710 (defun vhdl-in-quote-p ()
5711 "Check if point is in a quote ('x')."
5712 (or (and (> (point) (point-min))
5713 (< (1+ (point)) (point-max))
5714 (= (char-before (point)) ?\')
5715 (= (char-after (1+ (point))) ?\'))
5716 (and (> (1- (point)) (point-min))
5717 (< (point) (point-max))
5718 (= (char-before (1- (point))) ?\')
5719 (= (char-after (point)) ?\'))))
5721 (defun vhdl-in-literal ()
5722 "Determine if point is in a VHDL literal."
5723 (save-excursion
5724 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5725 (cond
5726 ((nth 3 state) 'string)
5727 ((nth 4 state) 'comment)
5728 ((vhdl-beginning-of-macro) 'pound)
5729 ((vhdl-beginning-of-directive) 'directive)
5730 ;; for multi-line comments
5731 ((and (vhdl-standard-p '08) (vhdl-in-comment-p)) 'comment)
5732 (t nil)))))
5734 (defun vhdl-in-extended-identifier-p ()
5735 "Determine if point is inside extended identifier (delimited by '\')."
5736 (save-match-data
5737 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5738 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5740 (defun vhdl-forward-comment (&optional direction)
5741 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5742 negative, skip forward otherwise."
5743 (interactive "p")
5744 (if (and direction (< direction 0))
5745 ;; skip backwards
5746 (progn
5747 (skip-chars-backward " \t\n\r\f")
5748 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5749 (goto-char (match-beginning 3))
5750 (skip-chars-backward " \t\n\r\f")))
5751 ;; skip forwards
5752 (skip-chars-forward " \t\n\r\f")
5753 (while (looking-at "--.*")
5754 (goto-char (match-end 0))
5755 (skip-chars-forward " \t\n\r\f"))))
5757 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5758 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5759 (defalias 'vhdl-forward-comment 'forward-comment))
5761 (defun vhdl-back-to-indentation ()
5762 "Move point to the first non-whitespace character on this line."
5763 (interactive)
5764 (beginning-of-line 1)
5765 (skip-syntax-forward " " (vhdl-point 'eol)))
5767 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5768 (when (featurep 'xemacs)
5769 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5771 ;; This is the best we can do in Win-Emacs.
5772 (defun vhdl-win-il (&optional lim)
5773 "Determine if point is in a VHDL literal."
5774 (save-excursion
5775 (let* ((here (point))
5776 (state nil)
5777 (match nil)
5778 (lim (or lim (vhdl-point 'bod))))
5779 (goto-char lim )
5780 (while (< (point) here)
5781 (setq match
5782 (and (re-search-forward "--\\|[\"']\\|`"
5783 here 'move)
5784 (buffer-substring (match-beginning 0) (match-end 0))))
5785 (setq state
5786 (cond
5787 ;; no match
5788 ((null match) nil)
5789 ;; looking at the opening of a VHDL style comment
5790 ((string= "--" match)
5791 (if (<= here (progn (end-of-line) (point))) 'comment))
5792 ;; looking at a directive
5793 ((string= "`" match)
5794 (if (<= here (progn (end-of-line) (point))) 'directive))
5795 ;; looking at the opening of a double quote string
5796 ((string= "\"" match)
5797 (if (not (save-restriction
5798 ;; this seems to be necessary since the
5799 ;; re-search-forward will not work without it
5800 (narrow-to-region (point) here)
5801 (re-search-forward
5802 ;; this regexp matches a double quote
5803 ;; which is preceded by an even number
5804 ;; of backslashes, including zero
5805 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5806 'string))
5807 ;; looking at the opening of a single quote string
5808 ((string= "'" match)
5809 (if (not (save-restriction
5810 ;; see comments from above
5811 (narrow-to-region (point) here)
5812 (re-search-forward
5813 ;; this matches a single quote which is
5814 ;; preceded by zero or two backslashes.
5815 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5816 here 'move)))
5817 'string))
5818 (t nil)))
5819 ) ; end-while
5820 state)))
5822 (and (string-match "Win-Emacs" emacs-version)
5823 (fset 'vhdl-in-literal 'vhdl-win-il))
5825 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5826 ;; defined as lexical whitespace or comments. Search no farther back
5827 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5828 ;; used for backward skipping, (point-max) is used for forward
5829 ;; skipping.
5831 (defun vhdl-forward-syntactic-ws (&optional lim)
5832 "Forward skip of syntactic whitespace."
5833 (let* ((here (point-max))
5834 (hugenum (point-max)))
5835 (while (/= here (point))
5836 (setq here (point))
5837 (vhdl-forward-comment hugenum)
5838 ;; skip preprocessor directives
5839 (when (and (or (eq (char-after) ?#) (eq (char-after) ?`))
5840 (= (vhdl-point 'boi) (point)))
5841 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5842 (= (forward-line 1) 0)))
5843 (end-of-line)))
5844 (if lim (goto-char (min (point) lim)))))
5847 ;; This is the best we can do in Win-Emacs.
5848 (defun vhdl-win-fsws (&optional lim)
5849 "Forward skip syntactic whitespace for Win-Emacs."
5850 (let ((lim (or lim (point-max)))
5851 stop)
5852 (while (not stop)
5853 (skip-chars-forward " \t\n\r\f" lim)
5854 (cond
5855 ;; vhdl comment
5856 ((looking-at "--") (end-of-line))
5857 ;; none of the above
5858 (t (setq stop t))))))
5860 (and (string-match "Win-Emacs" emacs-version)
5861 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5863 (defun vhdl-beginning-of-macro (&optional lim)
5864 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5865 (let ((here (point)))
5866 (beginning-of-line)
5867 (while (eq (char-before (1- (point))) ?\\)
5868 (forward-line -1))
5869 (back-to-indentation)
5870 (if (and (<= (point) here)
5871 (eq (char-after) ?#))
5873 (goto-char here)
5874 nil)))
5876 (defun vhdl-beginning-of-directive (&optional lim)
5877 "Go to the beginning of a directive (nicked from `cc-engine')."
5878 (let ((here (point)))
5879 (beginning-of-line)
5880 (while (eq (char-before (1- (point))) ?\\)
5881 (forward-line -1))
5882 (back-to-indentation)
5883 (if (and (<= (point) here)
5884 (eq (char-after) ?`))
5886 (goto-char here)
5887 nil)))
5889 (defun vhdl-backward-syntactic-ws (&optional lim)
5890 "Backward skip over syntactic whitespace."
5891 (let* ((here (point-min))
5892 (hugenum (- (point-max))))
5893 (while (/= here (point))
5894 (setq here (point))
5895 (vhdl-forward-comment hugenum)
5896 (vhdl-beginning-of-macro))
5897 (if lim (goto-char (max (point) lim)))))
5899 ;; This is the best we can do in Win-Emacs.
5900 (defun vhdl-win-bsws (&optional lim)
5901 "Backward skip syntactic whitespace for Win-Emacs."
5902 (let ((lim (or lim (vhdl-point 'bod)))
5903 stop)
5904 (while (not stop)
5905 (skip-chars-backward " \t\n\r\f" lim)
5906 (cond
5907 ;; vhdl comment
5908 ((eq (vhdl-in-literal) 'comment)
5909 (skip-chars-backward "^-" lim)
5910 (skip-chars-backward "-" lim)
5911 (while (not (or (and (= (following-char) ?-)
5912 (= (char-after (1+ (point))) ?-))
5913 (<= (point) lim)))
5914 (skip-chars-backward "^-" lim)
5915 (skip-chars-backward "-" lim)))
5916 ;; none of the above
5917 (t (setq stop t))))))
5919 (and (string-match "Win-Emacs" emacs-version)
5920 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5922 ;; Functions to help finding the correct indentation column:
5924 (defun vhdl-first-word (point)
5925 "If the keyword at POINT is at boi, then return (current-column) at
5926 that point, else nil."
5927 (save-excursion
5928 (and (goto-char point)
5929 (eq (point) (vhdl-point 'boi))
5930 (current-column))))
5932 (defun vhdl-last-word (point)
5933 "If the keyword at POINT is at eoi, then return (current-column) at
5934 that point, else nil."
5935 (save-excursion
5936 (and (goto-char point)
5937 (save-excursion (or (eq (progn (forward-sexp) (point))
5938 (vhdl-point 'eoi))
5939 (looking-at "\\s-*\\(--\\)?")))
5940 (current-column))))
5942 ;; Core syntactic evaluation functions:
5944 (defconst vhdl-libunit-re
5945 "\\b\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\b[^_]")
5947 (defun vhdl-libunit-p ()
5948 (and
5949 (save-excursion
5950 (forward-sexp)
5951 (skip-chars-forward " \t\n\r\f")
5952 (not (looking-at "is\\b[^_]")))
5953 (save-excursion
5954 (backward-sexp)
5955 (and (not (looking-at "use\\b[^_]"))
5956 (progn
5957 (forward-sexp)
5958 (vhdl-forward-syntactic-ws)
5959 (/= (following-char) ?:))))
5962 (defconst vhdl-defun-re
5963 "\\b\\(architecture\\|block\\|configuration\\|context\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5965 (defun vhdl-defun-p ()
5966 (save-excursion
5967 (if (looking-at "block\\|process\\|procedural")
5968 ;; "block", "process", "procedural":
5969 (save-excursion
5970 (backward-sexp)
5971 (not (looking-at "end\\s-+\\w")))
5972 ;; "architecture", "configuration", "context", "entity",
5973 ;; "package", "procedure", "function":
5974 t)))
5976 (defun vhdl-corresponding-defun ()
5977 "If the word at the current position corresponds to a \"defun\"
5978 keyword, then return a string that can be used to find the
5979 corresponding \"begin\" keyword, else return nil."
5980 (save-excursion
5981 (and (looking-at vhdl-defun-re)
5982 (vhdl-defun-p)
5983 (if (looking-at "block\\|process\\|procedural")
5984 ;; "block", "process". "procedural:
5985 (buffer-substring (match-beginning 0) (match-end 0))
5986 ;; "architecture", "configuration", "context", "entity", "package",
5987 ;; "procedure", "function":
5988 "is"))))
5990 (defconst vhdl-begin-fwd-re
5991 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5992 "A regular expression for searching forward that matches all known
5993 \"begin\" keywords.")
5995 (defconst vhdl-begin-bwd-re
5996 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5997 "A regular expression for searching backward that matches all known
5998 \"begin\" keywords.")
6000 (defun vhdl-begin-p (&optional lim)
6001 "Return t if we are looking at a real \"begin\" keyword.
6002 Assumes that the caller will make sure that we are looking at
6003 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
6004 the middle of an identifier that just happens to contain a \"begin\"
6005 keyword."
6006 (cond
6007 ;; "[architecture|case|configuration|context|entity|package|
6008 ;; procedure|function] ... is":
6009 ((and (looking-at "i")
6010 (save-excursion
6011 ;; Skip backward over first sexp (needed to skip over a
6012 ;; procedure interface list, and is harmless in other
6013 ;; situations). Note that we need "return" in the
6014 ;; following search list so that we don't run into
6015 ;; semicolons in the function interface list.
6016 (backward-sexp)
6017 (let (foundp)
6018 (while (and (not foundp)
6019 (re-search-backward
6020 ";\\|\\b\\(architecture\\|case\\|configuration\\|context\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
6021 lim 'move))
6022 (if (or (= (preceding-char) ?_)
6023 (vhdl-in-literal))
6024 (backward-char)
6025 (setq foundp t))))
6026 (and (/= (following-char) ?\;)
6027 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
6029 ;; "begin", "then", "use":
6030 ((looking-at "be\\|t\\|use")
6032 ;; "else":
6033 ((and (looking-at "e")
6034 ;; make sure that the "else" isn't inside a
6035 ;; conditional signal assignment.
6036 (save-excursion
6037 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6038 (or (eq (following-char) ?\;)
6039 (eq (point) lim))))
6041 ;; "block", "generate", "loop", "process", "procedural",
6042 ;; "units", "record", "protected body":
6043 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
6044 (save-excursion
6045 (backward-sexp)
6046 (not (looking-at "end\\s-+\\w"))))
6048 ;; "component":
6049 ((and (looking-at "c")
6050 (save-excursion
6051 (backward-sexp)
6052 (not (looking-at "end\\s-+\\w")))
6053 ;; look out for the dreaded entity class in an attribute
6054 (save-excursion
6055 (vhdl-backward-syntactic-ws lim)
6056 (/= (preceding-char) ?:)))
6058 ;; "for" (inside configuration declaration):
6059 ((and (looking-at "f")
6060 (save-excursion
6061 (backward-sexp)
6062 (not (looking-at "end\\s-+\\w")))
6063 (vhdl-has-syntax 'configuration))
6067 (defun vhdl-corresponding-mid (&optional lim)
6068 (cond
6069 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
6070 "begin")
6071 ((looking-at "then\\|use")
6072 "<else>")
6074 "end")))
6076 (defun vhdl-corresponding-end (&optional lim)
6077 "If the word at the current position corresponds to a \"begin\"
6078 keyword, then return a vector containing enough information to find
6079 the corresponding \"end\" keyword, else return nil. The keyword to
6080 search forward for is aref 0. The column in which the keyword must
6081 appear is aref 1 or nil if any column is suitable.
6082 Assumes that the caller will make sure that we are not in the middle
6083 of an identifier that just happens to contain a \"begin\" keyword."
6084 (save-excursion
6085 (and (looking-at vhdl-begin-fwd-re)
6086 (or (not (looking-at "\\<use\\>"))
6087 (save-excursion (back-to-indentation)
6088 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6089 (/= (preceding-char) ?_)
6090 (not (vhdl-in-literal))
6091 (vhdl-begin-p lim)
6092 (cond
6093 ;; "is", "generate", "loop":
6094 ((looking-at "[igl]")
6095 (vector "end"
6096 (and (vhdl-last-word (point))
6097 (or (vhdl-first-word (point))
6098 (save-excursion
6099 (vhdl-beginning-of-statement-1 lim)
6100 (vhdl-backward-skip-label lim)
6101 (vhdl-first-word (point)))))))
6102 ;; "begin", "else", "for":
6103 ((looking-at "be\\|[ef]")
6104 (vector "end"
6105 (and (vhdl-last-word (point))
6106 (or (vhdl-first-word (point))
6107 (save-excursion
6108 (vhdl-beginning-of-statement-1 lim)
6109 (vhdl-backward-skip-label lim)
6110 (vhdl-first-word (point)))))))
6111 ;; "component", "units", "record", "protected body":
6112 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
6113 ;; The first end found will close the block
6114 (vector "end" nil))
6115 ;; "block", "process", "procedural":
6116 ((looking-at "bl\\|p")
6117 (vector "end"
6118 (or (vhdl-first-word (point))
6119 (save-excursion
6120 (vhdl-beginning-of-statement-1 lim)
6121 (vhdl-backward-skip-label lim)
6122 (vhdl-first-word (point))))))
6123 ;; "then":
6124 ((looking-at "t\\|use")
6125 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
6126 (and (vhdl-last-word (point))
6127 (or (vhdl-first-word (point))
6128 (save-excursion
6129 (vhdl-beginning-of-statement-1 lim)
6130 (vhdl-backward-skip-label lim)
6131 (vhdl-first-word (point)))))))
6132 ))))
6134 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
6136 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
6138 (defun vhdl-end-p (&optional lim)
6139 "Return t if we are looking at a real \"end\" keyword.
6140 Assumes that the caller will make sure that we are looking at
6141 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
6142 the middle of an identifier that just happens to contain an \"end\"
6143 keyword."
6144 (or (not (looking-at "else"))
6145 ;; make sure that the "else" isn't inside a conditional signal
6146 ;; assignment.
6147 (save-excursion
6148 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
6149 (or (eq (following-char) ?\;)
6150 (eq (point) lim)
6151 (vhdl-in-literal)))))
6153 (defun vhdl-corresponding-begin (&optional lim)
6154 "If the word at the current position corresponds to an \"end\"
6155 keyword, then return a vector containing enough information to find
6156 the corresponding \"begin\" keyword, else return nil. The keyword to
6157 search backward for is aref 0. The column in which the keyword must
6158 appear is aref 1 or nil if any column is suitable. The supplementary
6159 keyword to search forward for is aref 2 or nil if this is not
6160 required. If aref 3 is t, then the \"begin\" keyword may be found in
6161 the middle of a statement.
6162 Assumes that the caller will make sure that we are not in the middle
6163 of an identifier that just happens to contain an \"end\" keyword."
6164 (save-excursion
6165 (let (pos)
6166 (if (and (looking-at vhdl-end-fwd-re)
6167 (not (vhdl-in-literal))
6168 (vhdl-end-p lim))
6169 (if (looking-at "el")
6170 ;; "else", "elsif":
6171 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
6172 ;; "end ...":
6173 (setq pos (point))
6174 (forward-sexp)
6175 (skip-chars-forward " \t\n\r\f")
6176 (cond
6177 ;; "end if":
6178 ((looking-at "if\\b[^_]")
6179 (vector "else\\|elsif\\|if"
6180 (vhdl-first-word pos)
6181 "else\\|then\\|use" nil))
6182 ;; "end component":
6183 ((looking-at "component\\b[^_]")
6184 (vector (buffer-substring (match-beginning 1)
6185 (match-end 1))
6186 (vhdl-first-word pos)
6187 nil nil))
6188 ;; "end units", "end record", "end protected":
6189 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6190 (vector (buffer-substring (match-beginning 1)
6191 (match-end 1))
6192 (vhdl-first-word pos)
6193 nil t))
6194 ;; "end block", "end process", "end procedural":
6195 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6196 (vector "begin" (vhdl-first-word pos) nil nil))
6197 ;; "end case":
6198 ((looking-at "case\\b[^_]")
6199 (vector "case" (vhdl-first-word pos) "is" nil))
6200 ;; "end generate":
6201 ((looking-at "generate\\b[^_]")
6202 (vector "generate\\|for\\|if"
6203 (vhdl-first-word pos)
6204 "generate" nil))
6205 ;; "end loop":
6206 ((looking-at "loop\\b[^_]")
6207 (vector "loop\\|while\\|for"
6208 (vhdl-first-word pos)
6209 "loop" nil))
6210 ;; "end for" (inside configuration declaration):
6211 ((looking-at "for\\b[^_]")
6212 (vector "for" (vhdl-first-word pos) nil nil))
6213 ;; "end [id]":
6215 (vector "begin\\|architecture\\|configuration\\|context\\|entity\\|package\\|procedure\\|function"
6216 (vhdl-first-word pos)
6217 ;; return an alist of (statement . keyword) mappings
6219 ;; "begin ... end [id]":
6220 ("begin" . nil)
6221 ;; "architecture ... is ... begin ... end [id]":
6222 ("architecture" . "is")
6223 ;; "configuration ... is ... end [id]":
6224 ("configuration" . "is")
6225 ;; "context ... is ... end [id]":
6226 ("context" . "is")
6227 ;; "entity ... is ... end [id]":
6228 ("entity" . "is")
6229 ;; "package ... is ... end [id]":
6230 ("package" . "is")
6231 ;; "procedure ... is ... begin ... end [id]":
6232 ("procedure" . "is")
6233 ;; "function ... is ... begin ... end [id]":
6234 ("function" . "is")
6236 nil))
6237 ))) ; "end ..."
6240 (defconst vhdl-leader-re
6241 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6243 (defun vhdl-end-of-leader ()
6244 (save-excursion
6245 (cond ((looking-at "block\\|process\\|procedural")
6246 (if (save-excursion
6247 (forward-sexp)
6248 (skip-chars-forward " \t\n\r\f")
6249 (= (following-char) ?\())
6250 (forward-sexp 2)
6251 (forward-sexp))
6252 (when (looking-at "[ \t\n\r\f]*is")
6253 (goto-char (match-end 0)))
6254 (point))
6255 ((looking-at "component")
6256 (forward-sexp 2)
6257 (when (looking-at "[ \t\n\r\f]*is")
6258 (goto-char (match-end 0)))
6259 (point))
6260 ((looking-at "for")
6261 (forward-sexp 2)
6262 (skip-chars-forward " \t\n\r\f")
6263 (while (looking-at "[,:(]")
6264 (forward-sexp)
6265 (skip-chars-forward " \t\n\r\f"))
6266 (point))
6267 (t nil)
6270 (defconst vhdl-trailer-re
6271 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6273 (defconst vhdl-statement-fwd-re
6274 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6275 "A regular expression for searching forward that matches all known
6276 \"statement\" keywords.")
6278 (defconst vhdl-statement-bwd-re
6279 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6280 "A regular expression for searching backward that matches all known
6281 \"statement\" keywords.")
6283 (defun vhdl-statement-p (&optional lim)
6284 "Return t if we are looking at a real \"statement\" keyword.
6285 Assumes that the caller will make sure that we are looking at
6286 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6287 in the middle of an identifier that just happens to contain a
6288 \"statement\" keyword."
6289 (cond
6290 ;; "for" ... "generate":
6291 ((and (looking-at "f")
6292 ;; Make sure it's the start of a parameter specification.
6293 (save-excursion
6294 (forward-sexp 2)
6295 (skip-chars-forward " \t\n\r\f")
6296 (looking-at "in\\b[^_]"))
6297 ;; Make sure it's not an "end for".
6298 (save-excursion
6299 (backward-sexp)
6300 (not (looking-at "end\\s-+\\w"))))
6302 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6303 ((and (looking-at "i")
6304 ;; Make sure it's not an "end if".
6305 (save-excursion
6306 (backward-sexp)
6307 (not (looking-at "end\\s-+\\w"))))
6309 ;; "while" ... "loop":
6310 ((looking-at "w")
6314 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6315 "Regexp describing a case statement alternative key.")
6317 (defun vhdl-case-alternative-p (&optional lim)
6318 "Return t if we are looking at a real case alternative.
6319 Assumes that the caller will make sure that we are looking at
6320 vhdl-case-alternative-re, and are not inside a literal, and that
6321 we are not in the middle of an identifier that just happens to
6322 contain a \"when\" keyword."
6323 (save-excursion
6324 (let (foundp)
6325 (while (and (not foundp)
6326 (re-search-backward ";\\|<=" lim 'move))
6327 (if (or (= (preceding-char) ?_)
6328 (vhdl-in-literal))
6329 (backward-char)
6330 (setq foundp t)))
6331 (or (eq (following-char) ?\;)
6332 (eq (point) lim)))
6335 ;; Core syntactic movement functions:
6337 (defconst vhdl-b-t-b-re
6338 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6340 (defun vhdl-backward-to-block (&optional lim)
6341 "Move backward to the previous \"begin\" or \"end\" keyword."
6342 (let (foundp)
6343 (while (and (not foundp)
6344 (re-search-backward vhdl-b-t-b-re lim 'move))
6345 (if (or (= (preceding-char) ?_)
6346 (vhdl-in-literal))
6347 (backward-char)
6348 (cond
6349 ;; "begin" keyword:
6350 ((and (looking-at vhdl-begin-fwd-re)
6351 (or (not (looking-at "\\<use\\>"))
6352 (save-excursion (back-to-indentation)
6353 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6354 (/= (preceding-char) ?_)
6355 (vhdl-begin-p lim))
6356 (setq foundp 'begin))
6357 ;; "end" keyword:
6358 ((and (looking-at vhdl-end-fwd-re)
6359 (/= (preceding-char) ?_)
6360 (vhdl-end-p lim))
6361 (setq foundp 'end))
6364 foundp
6367 (defun vhdl-forward-sexp (&optional count lim)
6368 "Move forward across one balanced expression (sexp).
6369 With COUNT, do it that many times."
6370 (interactive "p")
6371 (let ((count (or count 1))
6372 (case-fold-search t)
6373 end-vec target)
6374 (save-excursion
6375 (while (> count 0)
6376 ;; skip whitespace
6377 (skip-chars-forward " \t\n\r\f")
6378 ;; Check for an unbalanced "end" keyword
6379 (if (and (looking-at vhdl-end-fwd-re)
6380 (/= (preceding-char) ?_)
6381 (not (vhdl-in-literal))
6382 (vhdl-end-p lim)
6383 (not (looking-at "else")))
6384 (error
6385 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6386 ;; If the current keyword is a "begin" keyword, then find the
6387 ;; corresponding "end" keyword.
6388 (if (setq end-vec (vhdl-corresponding-end lim))
6389 (let (
6390 ;; end-re is the statement keyword to search for
6391 (end-re
6392 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6393 ;; column is either the statement keyword target column
6394 ;; or nil
6395 (column (aref end-vec 1))
6396 (eol (vhdl-point 'eol))
6397 foundp literal placeholder)
6398 ;; Look for the statement keyword.
6399 (while (and (not foundp)
6400 (re-search-forward end-re nil t)
6401 (setq placeholder (match-end 1))
6402 (goto-char (match-beginning 0)))
6403 ;; If we are in a literal, or not in the right target
6404 ;; column and not on the same line as the begin, then
6405 ;; try again.
6406 (if (or (and column
6407 (/= (current-indentation) column)
6408 (> (point) eol))
6409 (= (preceding-char) ?_)
6410 (setq literal (vhdl-in-literal)))
6411 (if (eq literal 'comment)
6412 (end-of-line)
6413 (forward-char))
6414 ;; An "else" keyword corresponds to both the opening brace
6415 ;; of the following sexp and the closing brace of the
6416 ;; previous sexp.
6417 (if (not (looking-at "else"))
6418 (goto-char placeholder))
6419 (setq foundp t))
6421 (if (not foundp)
6422 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6424 ;; If the current keyword is not a "begin" keyword, then just
6425 ;; perform the normal forward-sexp.
6426 (forward-sexp)
6428 (setq count (1- count))
6430 (setq target (point)))
6431 (goto-char target)
6432 nil))
6434 (defun vhdl-backward-sexp (&optional count lim)
6435 "Move backward across one balanced expression (sexp).
6436 With COUNT, do it that many times. LIM bounds any required backward
6437 searches."
6438 (interactive "p")
6439 (let ((count (or count 1))
6440 (case-fold-search t)
6441 begin-vec target)
6442 (save-excursion
6443 (while (> count 0)
6444 ;; Perform the normal backward-sexp, unless we are looking at
6445 ;; "else" - an "else" keyword corresponds to both the opening brace
6446 ;; of the following sexp and the closing brace of the previous sexp.
6447 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6448 (/= (preceding-char) ?_)
6449 (not (vhdl-in-literal)))
6451 (backward-sexp)
6452 (if (and (looking-at vhdl-begin-fwd-re)
6453 (or (not (looking-at "\\<use\\>"))
6454 (save-excursion
6455 (back-to-indentation)
6456 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6457 (/= (preceding-char) ?_)
6458 (not (vhdl-in-literal))
6459 (vhdl-begin-p lim))
6460 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6461 ;; If the current keyword is an "end" keyword, then find the
6462 ;; corresponding "begin" keyword.
6463 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6464 (/= (preceding-char) ?_))
6465 (let (
6466 ;; begin-re is the statement keyword to search for
6467 (begin-re
6468 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6469 ;; column is either the statement keyword target column
6470 ;; or nil
6471 (column (aref begin-vec 1))
6472 ;; internal-p controls where the statement keyword can
6473 ;; be found.
6474 (internal-p (aref begin-vec 3))
6475 (last-backward (point)) last-forward
6476 foundp literal keyword)
6477 ;; Look for the statement keyword.
6478 (while (and (not foundp)
6479 (re-search-backward begin-re lim t)
6480 (setq keyword
6481 (buffer-substring (match-beginning 1)
6482 (match-end 1))))
6483 ;; If we are in a literal or in the wrong column,
6484 ;; then try again.
6485 (if (or (and column
6486 (and (/= (current-indentation) column)
6487 ;; possibly accept current-column as
6488 ;; well as current-indentation.
6489 (or (not internal-p)
6490 (/= (current-column) column))))
6491 (= (preceding-char) ?_)
6492 (vhdl-in-literal))
6493 (backward-char)
6494 ;; If there is a supplementary keyword, then
6495 ;; search forward for it.
6496 (if (and (setq begin-re (aref begin-vec 2))
6497 (or (not (listp begin-re))
6498 ;; If begin-re is an alist, then find the
6499 ;; element corresponding to the actual
6500 ;; keyword that we found.
6501 (progn
6502 (setq begin-re
6503 (assoc keyword begin-re))
6504 (and begin-re
6505 (setq begin-re (cdr begin-re))))))
6506 (and
6507 (setq begin-re
6508 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6509 (save-excursion
6510 (setq last-forward (point))
6511 ;; Look for the supplementary keyword
6512 ;; (bounded by the backward search start
6513 ;; point).
6514 (while (and (not foundp)
6515 (re-search-forward begin-re
6516 last-backward t)
6517 (goto-char (match-beginning 1)))
6518 ;; If we are in a literal, then try again.
6519 (if (or (= (preceding-char) ?_)
6520 (setq literal
6521 (vhdl-in-literal)))
6522 (if (eq literal 'comment)
6523 (goto-char
6524 (min (vhdl-point 'eol) last-backward))
6525 (forward-char))
6526 ;; We have found the supplementary keyword.
6527 ;; Save the position of the keyword in foundp.
6528 (setq foundp (point)))
6530 foundp)
6531 ;; If the supplementary keyword was found, then
6532 ;; move point to the supplementary keyword.
6533 (goto-char foundp))
6534 ;; If there was no supplementary keyword, then
6535 ;; point is already at the statement keyword.
6536 (setq foundp t)))
6537 ) ; end of the search for the statement keyword
6538 (if (not foundp)
6539 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6541 (setq count (1- count))
6543 (setq target (point)))
6544 (goto-char target)
6545 nil))
6547 (defun vhdl-backward-up-list (&optional count limit)
6548 "Move backward out of one level of blocks.
6549 With argument, do this that many times."
6550 (interactive "p")
6551 (let ((count (or count 1))
6552 target)
6553 (save-excursion
6554 (while (> count 0)
6555 (if (looking-at vhdl-defun-re)
6556 (error "ERROR: Unbalanced blocks"))
6557 (vhdl-backward-to-block limit)
6558 (setq count (1- count)))
6559 (setq target (point)))
6560 (goto-char target)))
6562 (defun vhdl-end-of-defun (&optional count)
6563 "Move forward to the end of a VHDL defun."
6564 (interactive)
6565 (let ((case-fold-search t))
6566 (vhdl-beginning-of-defun)
6567 (if (not (looking-at "block\\|process\\|procedural"))
6568 (re-search-forward "\\bis\\b"))
6569 (vhdl-forward-sexp)))
6571 (defun vhdl-mark-defun ()
6572 "Put mark at end of this \"defun\", point at beginning."
6573 (interactive)
6574 (let ((case-fold-search t))
6575 (push-mark)
6576 (vhdl-beginning-of-defun)
6577 (push-mark)
6578 (if (not (looking-at "block\\|process\\|procedural"))
6579 (re-search-forward "\\bis\\b"))
6580 (vhdl-forward-sexp)
6581 (exchange-point-and-mark)))
6583 (defun vhdl-beginning-of-libunit ()
6584 "Move backward to the beginning of a VHDL library unit.
6585 Returns the location of the corresponding begin keyword, unless search
6586 stops due to beginning or end of buffer.
6587 Note that if point is between the \"libunit\" keyword and the
6588 corresponding \"begin\" keyword, then that libunit will not be
6589 recognized, and the search will continue backwards. If point is
6590 at the \"begin\" keyword, then the defun will be recognized. The
6591 returned point is at the first character of the \"libunit\" keyword."
6592 (let ((last-forward (point))
6593 (last-backward
6594 ;; Just in case we are actually sitting on the "begin"
6595 ;; keyword, allow for the keyword and an extra character,
6596 ;; as this will be used when looking forward for the
6597 ;; "begin" keyword.
6598 (save-excursion (forward-word 1) (1+ (point))))
6599 foundp literal placeholder)
6600 ;; Find the "libunit" keyword.
6601 (while (and (not foundp)
6602 (re-search-backward vhdl-libunit-re nil 'move))
6603 ;; If we are in a literal, or not at a real libunit, then try again.
6604 (if (or (= (preceding-char) ?_)
6605 (vhdl-in-literal)
6606 (not (vhdl-libunit-p)))
6607 (backward-char)
6608 ;; Find the corresponding "begin" keyword.
6609 (setq last-forward (point))
6610 (while (and (not foundp)
6611 (re-search-forward "\\bis\\b[^_]" last-backward t)
6612 (setq placeholder (match-beginning 0)))
6613 (if (or (= (preceding-char) ?_)
6614 (setq literal (vhdl-in-literal)))
6615 ;; It wasn't a real keyword, so keep searching.
6616 (if (eq literal 'comment)
6617 (goto-char
6618 (min (vhdl-point 'eol) last-backward))
6619 (forward-char))
6620 ;; We have found the begin keyword, loop will exit.
6621 (setq foundp placeholder)))
6622 ;; Go back to the libunit keyword
6623 (goto-char last-forward)))
6624 foundp))
6626 (defun vhdl-beginning-of-defun (&optional count)
6627 "Move backward to the beginning of a VHDL defun.
6628 With argument, do it that many times.
6629 Returns the location of the corresponding begin keyword, unless search
6630 stops due to beginning or end of buffer."
6631 ;; Note that if point is between the "defun" keyword and the
6632 ;; corresponding "begin" keyword, then that defun will not be
6633 ;; recognized, and the search will continue backwards. If point is
6634 ;; at the "begin" keyword, then the defun will be recognized. The
6635 ;; returned point is at the first character of the "defun" keyword.
6636 (interactive "p")
6637 (let ((count (or count 1))
6638 (case-fold-search t)
6639 (last-forward (point))
6640 foundp)
6641 (while (> count 0)
6642 (setq foundp nil)
6643 (goto-char last-forward)
6644 (let ((last-backward
6645 ;; Just in case we are actually sitting on the "begin"
6646 ;; keyword, allow for the keyword and an extra character,
6647 ;; as this will be used when looking forward for the
6648 ;; "begin" keyword.
6649 (save-excursion (forward-word 1) (1+ (point))))
6650 begin-string literal)
6651 (while (and (not foundp)
6652 (re-search-backward vhdl-defun-re nil 'move))
6653 ;; If we are in a literal, then try again.
6654 (if (or (= (preceding-char) ?_)
6655 (vhdl-in-literal))
6656 (backward-char)
6657 (if (setq begin-string (vhdl-corresponding-defun))
6658 ;; This is a real defun keyword.
6659 ;; Find the corresponding "begin" keyword.
6660 ;; Look for the begin keyword.
6661 (progn
6662 ;; Save the search start point.
6663 (setq last-forward (point))
6664 (while (and (not foundp)
6665 (search-forward begin-string last-backward t))
6666 (if (or (= (preceding-char) ?_)
6667 (save-match-data
6668 (setq literal (vhdl-in-literal))))
6669 ;; It wasn't a real keyword, so keep searching.
6670 (if (eq literal 'comment)
6671 (goto-char
6672 (min (vhdl-point 'eol) last-backward))
6673 (forward-char))
6674 ;; We have found the begin keyword, loop will exit.
6675 (setq foundp (match-beginning 0)))
6677 ;; Go back to the defun keyword
6678 (goto-char last-forward)) ; end search for begin keyword
6680 ) ; end of the search for the defun keyword
6682 (setq count (1- count))
6684 (vhdl-keep-region-active)
6685 foundp))
6687 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6688 "Go to the beginning of the innermost VHDL statement.
6689 With prefix arg, go back N - 1 statements. If already at the
6690 beginning of a statement then go to the beginning of the preceding
6691 one. If within a string or comment, or next to a comment (only
6692 whitespace between), move by sentences instead of statements.
6694 When called from a program, this function takes 3 optional args: the
6695 prefix arg, a buffer position limit which is the farthest back to
6696 search, and an argument indicating an interactive call."
6697 (interactive "p\np")
6698 (let ((count (or count 1))
6699 (case-fold-search t)
6700 (lim (or lim (point-min)))
6701 (here (point))
6702 state)
6703 (save-excursion
6704 (goto-char lim)
6705 (setq state (parse-partial-sexp (point) here nil nil)))
6706 (if (and interactive
6707 (or (nth 3 state)
6708 (nth 4 state)
6709 (looking-at (concat "[ \t]*" comment-start-skip))))
6710 (forward-sentence (- count))
6711 (while (> count 0)
6712 (vhdl-beginning-of-statement-1 lim)
6713 (setq count (1- count))))
6714 ;; its possible we've been left up-buf of lim
6715 (goto-char (max (point) lim))
6717 (vhdl-keep-region-active))
6719 (defconst vhdl-e-o-s-re
6720 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6722 (defun vhdl-end-of-statement ()
6723 "Very simple implementation."
6724 (interactive)
6725 (re-search-forward vhdl-e-o-s-re))
6727 (defconst vhdl-b-o-s-re
6728 (concat ";[^_]\\|\([^_]\\|\)[^_]\\|\\bwhen\\b[^_]\\|"
6729 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6731 (defun vhdl-beginning-of-statement-1 (&optional lim)
6732 "Move to the start of the current statement, or the previous
6733 statement if already at the beginning of one."
6734 (let ((lim (or lim (point-min)))
6735 (here (point))
6736 (pos (point))
6737 donep)
6738 ;; go backwards one balanced expression, but be careful of
6739 ;; unbalanced paren being reached
6740 (if (not (vhdl-safe (progn (backward-sexp) t)))
6741 (progn
6742 (backward-up-list 1)
6743 (forward-char)
6744 (vhdl-forward-syntactic-ws here)
6745 (setq donep t)))
6746 (while (and (not donep)
6747 (not (bobp))
6748 ;; look backwards for a statement boundary
6749 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6750 (if (or (= (preceding-char) ?_)
6751 (vhdl-in-literal))
6752 (backward-char)
6753 (cond
6754 ;; If we are looking at an open paren, then stop after it
6755 ((eq (following-char) ?\()
6756 (forward-char)
6757 (vhdl-forward-syntactic-ws here)
6758 (setq donep t))
6759 ;; If we are looking at a close paren, then skip it
6760 ((eq (following-char) ?\))
6761 (forward-char)
6762 (setq pos (point))
6763 (backward-sexp)
6764 (if (< (point) lim)
6765 (progn (goto-char pos)
6766 (vhdl-forward-syntactic-ws here)
6767 (setq donep t))))
6768 ;; If we are looking at a semicolon, then stop
6769 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6770 (progn
6771 (forward-char)
6772 (vhdl-forward-syntactic-ws here)
6773 (setq donep t)))
6774 ;; If we are looking at a "begin", then stop
6775 ((and (looking-at vhdl-begin-fwd-re)
6776 (or (not (looking-at "\\<use\\>"))
6777 (save-excursion
6778 (back-to-indentation)
6779 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6780 (/= (preceding-char) ?_)
6781 (vhdl-begin-p nil))
6782 ;; If it's a leader "begin", then find the
6783 ;; right place
6784 (if (looking-at vhdl-leader-re)
6785 (save-excursion
6786 ;; set a default stop point at the begin
6787 (setq pos (point))
6788 ;; is the start point inside the leader area ?
6789 (goto-char (vhdl-end-of-leader))
6790 (vhdl-forward-syntactic-ws here)
6791 (if (< (point) here)
6792 ;; start point was not inside leader area
6793 ;; set stop point at word after leader
6794 (setq pos (point))))
6795 (forward-word 1)
6796 (vhdl-forward-syntactic-ws here)
6797 (setq pos (point)))
6798 (goto-char pos)
6799 (setq donep t))
6800 ;; If we are looking at a "statement", then stop
6801 ((and (looking-at vhdl-statement-fwd-re)
6802 (/= (preceding-char) ?_)
6803 (vhdl-statement-p nil))
6804 (setq donep t))
6805 ;; If we are looking at a case alternative key, then stop
6806 ((and (looking-at vhdl-case-alternative-re)
6807 (vhdl-case-alternative-p lim))
6808 (save-excursion
6809 ;; set a default stop point at the when
6810 (setq pos (point))
6811 ;; is the start point inside the case alternative key ?
6812 (looking-at vhdl-case-alternative-re)
6813 (goto-char (match-end 0))
6814 (vhdl-forward-syntactic-ws here)
6815 (if (< (point) here)
6816 ;; start point was not inside the case alternative key
6817 ;; set stop point at word after case alternative keyleader
6818 (setq pos (point))))
6819 (goto-char pos)
6820 (setq donep t))
6821 ;; Bogus find, continue
6823 (backward-char)))))
6826 ;; Defuns for calculating the current syntactic state:
6828 (defun vhdl-get-library-unit (bod placeholder)
6829 "If there is an enclosing library unit at BOD, with its \"begin\"
6830 keyword at PLACEHOLDER, then return the library unit type."
6831 (let ((here (vhdl-point 'bol)))
6832 (if (save-excursion
6833 (goto-char placeholder)
6834 (vhdl-safe (vhdl-forward-sexp 1 bod))
6835 (<= here (point)))
6836 (save-excursion
6837 (goto-char bod)
6838 (cond
6839 ((looking-at "e") 'entity)
6840 ((looking-at "a") 'architecture)
6841 ((looking-at "conf") 'configuration)
6842 ((looking-at "cont") 'context)
6843 ((looking-at "p")
6844 (save-excursion
6845 (goto-char bod)
6846 (forward-sexp)
6847 (vhdl-forward-syntactic-ws here)
6848 (if (looking-at "body\\b[^_]")
6849 'package-body 'package))))))
6852 (defun vhdl-get-block-state (&optional lim)
6853 "Finds and records all the closest opens.
6854 LIM is the furthest back we need to search (it should be the
6855 previous libunit keyword)."
6856 (let ((here (point))
6857 (lim (or lim (point-min)))
6858 keyword sexp-start sexp-mid sexp-end
6859 preceding-sexp containing-sexp
6860 containing-begin containing-mid containing-paren)
6861 (save-excursion
6862 ;; Find the containing-paren, and use that as the limit
6863 (if (setq containing-paren
6864 (save-restriction
6865 (narrow-to-region lim (point))
6866 (vhdl-safe (scan-lists (point) -1 1))))
6867 (setq lim containing-paren))
6868 ;; Look backwards for "begin" and "end" keywords.
6869 (while (and (> (point) lim)
6870 (not containing-sexp))
6871 (setq keyword (vhdl-backward-to-block lim))
6872 (cond
6873 ((eq keyword 'begin)
6874 ;; Found a "begin" keyword
6875 (setq sexp-start (point))
6876 (setq sexp-mid (vhdl-corresponding-mid lim))
6877 (setq sexp-end (vhdl-safe
6878 (save-excursion
6879 (vhdl-forward-sexp 1 lim) (point))))
6880 (if (and sexp-end (<= sexp-end here))
6881 ;; we want to record this sexp, but we only want to
6882 ;; record the last-most of any of them before here
6883 (or preceding-sexp
6884 (setq preceding-sexp sexp-start))
6885 ;; we're contained in this sexp so put sexp-start on
6886 ;; front of list
6887 (setq containing-sexp sexp-start)
6888 (setq containing-mid sexp-mid)
6889 (setq containing-begin t)))
6890 ((eq keyword 'end)
6891 ;; Found an "end" keyword
6892 (forward-sexp)
6893 (setq sexp-end (point))
6894 (setq sexp-mid nil)
6895 (setq sexp-start
6896 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6897 (progn (backward-sexp) (point))))
6898 ;; we want to record this sexp, but we only want to
6899 ;; record the last-most of any of them before here
6900 (or preceding-sexp
6901 (setq preceding-sexp sexp-start)))
6903 ;; Check if the containing-paren should be the containing-sexp
6904 (if (and containing-paren
6905 (or (null containing-sexp)
6906 (< containing-sexp containing-paren)))
6907 (setq containing-sexp containing-paren
6908 preceding-sexp nil
6909 containing-begin nil
6910 containing-mid nil))
6911 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6915 (defconst vhdl-s-c-a-re
6916 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6918 (defun vhdl-skip-case-alternative (&optional lim)
6919 "Skip forward over case/when bodies, with optional maximal
6920 limit. If no next case alternative is found, nil is returned and
6921 point is not moved."
6922 (let ((lim (or lim (point-max)))
6923 (here (point))
6924 donep foundp)
6925 (while (and (< (point) lim)
6926 (not donep))
6927 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6928 (save-match-data
6929 (not (vhdl-in-literal)))
6930 (/= (match-beginning 0) here))
6931 (progn
6932 (goto-char (match-beginning 0))
6933 (cond
6934 ((and (looking-at "case")
6935 (re-search-forward "\\bis[^_]" lim t))
6936 (backward-sexp)
6937 (vhdl-forward-sexp))
6939 (setq donep t
6940 foundp t))))))
6941 (if (not foundp)
6942 (goto-char here))
6943 foundp))
6945 (defun vhdl-backward-skip-label (&optional lim)
6946 "Skip backward over a label, with optional maximal
6947 limit. If label is not found, nil is returned and point
6948 is not moved."
6949 (let ((lim (or lim (point-min)))
6950 placeholder)
6951 (if (save-excursion
6952 (vhdl-backward-syntactic-ws lim)
6953 (and (eq (preceding-char) ?:)
6954 (progn
6955 (backward-sexp)
6956 (setq placeholder (point))
6957 (looking-at vhdl-label-key))))
6958 (goto-char placeholder))
6961 (defun vhdl-forward-skip-label (&optional lim)
6962 "Skip forward over a label, with optional maximal
6963 limit. If label is not found, nil is returned and point
6964 is not moved."
6965 (let ((lim (or lim (point-max))))
6966 (if (looking-at vhdl-label-key)
6967 (progn
6968 (goto-char (match-end 0))
6969 (vhdl-forward-syntactic-ws lim)))
6972 (defun vhdl-get-syntactic-context ()
6973 "Guess the syntactic description of the current line of VHDL code."
6974 (save-excursion
6975 (save-restriction
6976 (beginning-of-line)
6977 (let* ((indent-point (point))
6978 (case-fold-search t)
6979 vec literal containing-sexp preceding-sexp
6980 containing-begin containing-mid containing-leader
6981 char-before-ip char-after-ip begin-after-ip end-after-ip
6982 placeholder lim library-unit
6985 ;; Reset the syntactic context
6986 (setq vhdl-syntactic-context nil)
6988 (save-excursion
6989 ;; Move to the start of the previous library unit, and
6990 ;; record the position of the "begin" keyword.
6991 (setq placeholder (vhdl-beginning-of-libunit))
6992 ;; The position of the "libunit" keyword gives us a gross
6993 ;; limit point.
6994 (setq lim (point))
6997 ;; If there is a previous library unit, and we are enclosed by
6998 ;; it, then set the syntax accordingly.
6999 (and placeholder
7000 (setq library-unit (vhdl-get-library-unit lim placeholder))
7001 (vhdl-add-syntax library-unit lim))
7003 ;; Find the surrounding state.
7004 (if (setq vec (vhdl-get-block-state lim))
7005 (progn
7006 (setq containing-sexp (aref vec 0))
7007 (setq preceding-sexp (aref vec 1))
7008 (setq containing-begin (aref vec 2))
7009 (setq containing-mid (aref vec 3))
7012 ;; set the limit on the farthest back we need to search
7013 (setq lim (if containing-sexp
7014 (save-excursion
7015 (goto-char containing-sexp)
7016 ;; set containing-leader if required
7017 (if (looking-at vhdl-leader-re)
7018 (setq containing-leader (vhdl-end-of-leader)))
7019 (vhdl-point 'bol))
7020 (point-min)))
7022 ;; cache char before and after indent point, and move point to
7023 ;; the most likely position to perform the majority of tests
7024 (goto-char indent-point)
7025 (skip-chars-forward " \t")
7026 (setq literal (vhdl-in-literal))
7027 (setq char-after-ip (following-char))
7028 (setq begin-after-ip (and
7029 (not literal)
7030 (looking-at vhdl-begin-fwd-re)
7031 (or (not (looking-at "\\<use\\>"))
7032 (save-excursion
7033 (back-to-indentation)
7034 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
7035 (vhdl-begin-p)))
7036 (setq end-after-ip (and
7037 (not literal)
7038 (looking-at vhdl-end-fwd-re)
7039 (vhdl-end-p)))
7040 (vhdl-backward-syntactic-ws lim)
7041 (setq char-before-ip (preceding-char))
7042 (goto-char indent-point)
7043 (skip-chars-forward " \t")
7045 ;; now figure out syntactic qualities of the current line
7046 (cond
7047 ;; CASE 1: in a string or comment.
7048 ((memq literal '(string comment))
7049 (vhdl-add-syntax literal (vhdl-point 'bopl)))
7050 ;; CASE 2: Line is at top level.
7051 ((null containing-sexp)
7052 ;; Find the point to which indentation will be relative
7053 (save-excursion
7054 (if (null preceding-sexp)
7055 ;; CASE 2X.1
7056 ;; no preceding-sexp -> use the preceding statement
7057 (vhdl-beginning-of-statement-1 lim)
7058 ;; CASE 2X.2
7059 ;; if there is a preceding-sexp then indent relative to it
7060 (goto-char preceding-sexp)
7061 ;; if not at boi, then the block-opening keyword is
7062 ;; probably following a label, so we need a different
7063 ;; relpos
7064 (if (/= (point) (vhdl-point 'boi))
7065 ;; CASE 2X.3
7066 (vhdl-beginning-of-statement-1 lim)))
7067 ;; v-b-o-s could have left us at point-min
7068 (and (bobp)
7069 ;; CASE 2X.4
7070 (vhdl-forward-syntactic-ws indent-point))
7071 (setq placeholder (point)))
7072 (cond
7073 ;; CASE 2A : we are looking at a block-open
7074 (begin-after-ip
7075 (vhdl-add-syntax 'block-open placeholder))
7076 ;; CASE 2B: we are looking at a block-close
7077 (end-after-ip
7078 (vhdl-add-syntax 'block-close placeholder))
7079 ;; CASE 2C: we are looking at a top-level statement
7080 ((progn
7081 (vhdl-backward-syntactic-ws lim)
7082 (or (bobp)
7083 (and (= (preceding-char) ?\;)
7084 (not (vhdl-in-quote-p)))))
7085 (vhdl-add-syntax 'statement placeholder))
7086 ;; CASE 2D: we are looking at a top-level statement-cont
7088 (vhdl-beginning-of-statement-1 lim)
7089 ;; v-b-o-s could have left us at point-min
7090 (and (bobp)
7091 ;; CASE 2D.1
7092 (vhdl-forward-syntactic-ws indent-point))
7093 (vhdl-add-syntax 'statement-cont (point)))
7094 )) ; end CASE 2
7095 ;; CASE 3: line is inside parentheses. Most likely we are
7096 ;; either in a subprogram argument (interface) list, or a
7097 ;; continued expression containing parentheses.
7098 ((null containing-begin)
7099 (vhdl-backward-syntactic-ws containing-sexp)
7100 (cond
7101 ;; CASE 3A: we are looking at the arglist closing paren
7102 ((eq char-after-ip ?\))
7103 (goto-char containing-sexp)
7104 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
7105 ;; CASE 3B: we are looking at the first argument in an empty
7106 ;; argument list.
7107 ((eq char-before-ip ?\()
7108 (goto-char containing-sexp)
7109 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
7110 ;; CASE 3C: we are looking at an arglist continuation line,
7111 ;; but the preceding argument is on the same line as the
7112 ;; opening paren. This case includes multi-line
7113 ;; expression paren groupings.
7114 ((and (save-excursion
7115 (goto-char (1+ containing-sexp))
7116 (skip-chars-forward " \t")
7117 (not (eolp))
7118 (not (looking-at "--\\|`")))
7119 (save-excursion
7120 (vhdl-beginning-of-statement-1 containing-sexp)
7121 (skip-chars-backward " \t(")
7122 (while (and (= (preceding-char) ?\;)
7123 (not (vhdl-in-quote-p)))
7124 (vhdl-beginning-of-statement-1 containing-sexp)
7125 (skip-chars-backward " \t("))
7126 (<= (point) containing-sexp)))
7127 (goto-char containing-sexp)
7128 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
7129 ;; CASE 3D: we are looking at just a normal arglist
7130 ;; continuation line
7131 (t (vhdl-beginning-of-statement-1 containing-sexp)
7132 (vhdl-forward-syntactic-ws indent-point)
7133 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
7135 ;; CASE 4: A block mid open
7136 ((and begin-after-ip
7137 (looking-at containing-mid))
7138 (goto-char containing-sexp)
7139 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7140 (if (looking-at vhdl-trailer-re)
7141 ;; CASE 4.1
7142 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7143 (vhdl-backward-skip-label (vhdl-point 'boi))
7144 (vhdl-add-syntax 'block-open (point)))
7145 ;; CASE 5: block close brace
7146 (end-after-ip
7147 (goto-char containing-sexp)
7148 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7149 (if (looking-at vhdl-trailer-re)
7150 ;; CASE 5.1
7151 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7152 (vhdl-backward-skip-label (vhdl-point 'boi))
7153 (vhdl-add-syntax 'block-close (point)))
7154 ;; CASE 6: A continued statement
7155 ((and (/= char-before-ip ?\;)
7156 ;; check it's not a trailer begin keyword, or a begin
7157 ;; keyword immediately following a label.
7158 (not (and begin-after-ip
7159 (or (looking-at vhdl-trailer-re)
7160 (save-excursion
7161 (vhdl-backward-skip-label containing-sexp)))))
7162 ;; check it's not a statement keyword
7163 (not (and (looking-at vhdl-statement-fwd-re)
7164 (vhdl-statement-p)))
7165 ;; see if the b-o-s is before the indent point
7166 (> indent-point
7167 (save-excursion
7168 (vhdl-beginning-of-statement-1 containing-sexp)
7169 ;; If we ended up after a leader, then this will
7170 ;; move us forward to the start of the first
7171 ;; statement. Note that a containing sexp here is
7172 ;; always a keyword, not a paren, so this will
7173 ;; have no effect if we hit the containing-sexp.
7174 (vhdl-forward-syntactic-ws indent-point)
7175 (setq placeholder (point))))
7176 ;; check it's not a block-intro
7177 (/= placeholder containing-sexp)
7178 ;; check it's not a case block-intro
7179 (save-excursion
7180 (goto-char placeholder)
7181 (or (not (looking-at vhdl-case-alternative-re))
7182 (> (match-end 0) indent-point))))
7183 ;; Make placeholder skip a label, but only if it puts us
7184 ;; before the indent point at the start of a line.
7185 (let ((new placeholder))
7186 (if (and (> indent-point
7187 (save-excursion
7188 (goto-char placeholder)
7189 (vhdl-forward-skip-label indent-point)
7190 (setq new (point))))
7191 (save-excursion
7192 (goto-char new)
7193 (eq new (progn (back-to-indentation) (point)))))
7194 (setq placeholder new)))
7195 (vhdl-add-syntax 'statement-cont placeholder)
7196 (if begin-after-ip
7197 (vhdl-add-syntax 'block-open)))
7198 ;; Statement. But what kind?
7199 ;; CASE 7: A case alternative key
7200 ((and (looking-at vhdl-case-alternative-re)
7201 (vhdl-case-alternative-p containing-sexp))
7202 ;; for a case alternative key, we set relpos to the first
7203 ;; non-whitespace char on the line containing the "case"
7204 ;; keyword.
7205 (goto-char containing-sexp)
7206 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7207 (if (looking-at vhdl-trailer-re)
7208 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7209 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
7210 ;; CASE 8: statement catchall
7212 ;; we know its a statement, but we need to find out if it is
7213 ;; the first statement in a block
7214 (if containing-leader
7215 (goto-char containing-leader)
7216 (goto-char containing-sexp)
7217 ;; Note that a containing sexp here is always a keyword,
7218 ;; not a paren, so skip over the keyword.
7219 (forward-sexp))
7220 ;; move to the start of the first statement
7221 (vhdl-forward-syntactic-ws indent-point)
7222 (setq placeholder (point))
7223 ;; we want to ignore case alternatives keys when skipping forward
7224 (let (incase-p)
7225 (while (looking-at vhdl-case-alternative-re)
7226 (setq incase-p (point))
7227 ;; we also want to skip over the body of the
7228 ;; case/when statement if that doesn't put us at
7229 ;; after the indent-point
7230 (while (vhdl-skip-case-alternative indent-point))
7231 ;; set up the match end
7232 (looking-at vhdl-case-alternative-re)
7233 (goto-char (match-end 0))
7234 ;; move to the start of the first case alternative statement
7235 (vhdl-forward-syntactic-ws indent-point)
7236 (setq placeholder (point)))
7237 (cond
7238 ;; CASE 8A: we saw a case/when statement so we must be
7239 ;; in a switch statement. find out if we are at the
7240 ;; statement just after a case alternative key
7241 ((and incase-p
7242 (= (point) indent-point))
7243 ;; relpos is the "when" keyword
7244 (vhdl-add-syntax 'statement-case-intro incase-p))
7245 ;; CASE 8B: any old statement
7246 ((< (point) indent-point)
7247 ;; relpos is the first statement of the block
7248 (vhdl-add-syntax 'statement placeholder)
7249 (if begin-after-ip
7250 (vhdl-add-syntax 'block-open)))
7251 ;; CASE 8C: first statement in a block
7253 (goto-char containing-sexp)
7254 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7255 (if (looking-at vhdl-trailer-re)
7256 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7257 (vhdl-backward-skip-label (vhdl-point 'boi))
7258 (vhdl-add-syntax 'statement-block-intro (point))
7259 (if begin-after-ip
7260 (vhdl-add-syntax 'block-open)))
7264 ;; now we need to look at any modifiers
7265 (goto-char indent-point)
7266 (skip-chars-forward " \t")
7267 (if (or (looking-at "--") (looking-at "/\\*"))
7268 (vhdl-add-syntax 'comment))
7269 (if (looking-at "`")
7270 (vhdl-add-syntax 'directive))
7271 (if (eq literal 'pound)
7272 (vhdl-add-syntax 'cpp-macro))
7273 ;; return the syntax
7274 vhdl-syntactic-context))))
7276 ;; Standard indentation line-ups:
7278 (defun vhdl-lineup-arglist (langelem)
7279 "Lineup the current arglist line with the arglist appearing just
7280 after the containing paren which starts the arglist."
7281 (save-excursion
7282 (let* ((containing-sexp
7283 (save-excursion
7284 ;; arglist-cont-nonempty gives relpos ==
7285 ;; to boi of containing-sexp paren. This
7286 ;; is good when offset is +, but bad
7287 ;; when it is vhdl-lineup-arglist, so we
7288 ;; have to special case a kludge here.
7289 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7290 (progn
7291 (beginning-of-line)
7292 (backward-up-list 1)
7293 (skip-chars-forward " \t" (vhdl-point 'eol)))
7294 (goto-char (cdr langelem)))
7295 (point)))
7296 (cs-curcol (save-excursion
7297 (goto-char (cdr langelem))
7298 (current-column))))
7299 (if (save-excursion
7300 (beginning-of-line)
7301 (looking-at "[ \t]*)"))
7302 (progn (goto-char (match-end 0))
7303 (backward-sexp)
7304 (forward-char)
7305 (vhdl-forward-syntactic-ws)
7306 (- (current-column) cs-curcol))
7307 (goto-char containing-sexp)
7308 (or (eolp)
7309 (let ((eol (vhdl-point 'eol))
7310 (here (progn
7311 (forward-char)
7312 (skip-chars-forward " \t")
7313 (point))))
7314 (vhdl-forward-syntactic-ws)
7315 (if (< (point) eol)
7316 (goto-char here))))
7317 (- (current-column) cs-curcol)
7318 ))))
7320 (defun vhdl-lineup-arglist-intro (langelem)
7321 "Lineup an arglist-intro line to just after the open paren."
7322 (save-excursion
7323 (let ((cs-curcol (save-excursion
7324 (goto-char (cdr langelem))
7325 (current-column)))
7326 (ce-curcol (save-excursion
7327 (beginning-of-line)
7328 (backward-up-list 1)
7329 (skip-chars-forward " \t" (vhdl-point 'eol))
7330 (current-column))))
7331 (- ce-curcol cs-curcol -1))))
7333 (defun vhdl-lineup-comment (langelem)
7334 "Support old behavior for comment indentation. We look at
7335 vhdl-comment-only-line-offset to decide how to indent comment
7336 only-lines."
7337 (save-excursion
7338 (back-to-indentation)
7339 ;; at or to the right of comment-column
7340 (if (>= (current-column) comment-column)
7341 (vhdl-comment-indent)
7342 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7343 (if (not (bolp))
7344 ;; inside multi-line comment
7345 (if (looking-at "\\*")
7347 ;; otherwise
7348 (or (car-safe vhdl-comment-only-line-offset)
7349 vhdl-comment-only-line-offset))
7350 (or (cdr-safe vhdl-comment-only-line-offset)
7351 (car-safe vhdl-comment-only-line-offset)
7352 -1000 ;jam it against the left side
7353 )))))
7355 (defun vhdl-lineup-statement-cont (langelem)
7356 "Line up statement-cont after the assignment operator."
7357 (save-excursion
7358 (let* ((relpos (cdr langelem))
7359 (assignp (save-excursion
7360 (goto-char (vhdl-point 'boi))
7361 (and (re-search-forward "\\(<\\|:\\|=\\)="
7362 (vhdl-point 'eol) t)
7363 (- (point) (vhdl-point 'boi)))))
7364 (curcol (progn
7365 (goto-char relpos)
7366 (current-column)))
7367 foundp)
7368 (while (and (not foundp)
7369 (< (point) (vhdl-point 'eol)))
7370 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7371 (if (vhdl-in-literal)
7372 (forward-char)
7373 (if (= (preceding-char) ?\()
7374 ;; skip over any parenthesized expressions
7375 (goto-char (min (vhdl-point 'eol)
7376 (scan-lists (point) 1 1)))
7377 ;; found an assignment operator (not at eol)
7378 (setq foundp (not (looking-at "\\s-*$"))))))
7379 (if (not foundp)
7380 ;; there's no assignment operator on the line
7381 vhdl-basic-offset
7382 ;; calculate indentation column after assign and ws, unless
7383 ;; our line contains an assignment operator
7384 (if (not assignp)
7385 (progn
7386 (forward-char)
7387 (skip-chars-forward " \t")
7388 (setq assignp 0)))
7389 (- (current-column) assignp curcol))
7392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7393 ;; Progress reporting
7395 (defvar vhdl-progress-info nil
7396 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7398 (defun vhdl-update-progress-info (string pos)
7399 "Update progress information."
7400 (when (and vhdl-progress-info (not noninteractive)
7401 (< vhdl-progress-interval
7402 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7403 (let ((delta (- (aref vhdl-progress-info 1)
7404 (aref vhdl-progress-info 0))))
7405 (if (= 0 delta)
7406 (message (concat string "... (100%s)") "%")
7407 (message (concat string "... (%2d%s)")
7408 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
7409 delta) "%")))
7410 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7412 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7413 ;; Indentation commands
7415 (defun vhdl-electric-tab (&optional prefix-arg)
7416 "If preceding character is part of a word or a paren then hippie-expand,
7417 else if right of non whitespace on line then insert tab,
7418 else if last command was a tab or return then dedent one step or if a comment
7419 toggle between normal indent and inline comment indent,
7420 else indent `correctly'."
7421 (interactive "*P")
7422 (vhdl-prepare-search-2
7423 (cond
7424 ;; indent region if region is active
7425 ((and (not (featurep 'xemacs)) (use-region-p))
7426 (vhdl-indent-region (region-beginning) (region-end) nil))
7427 ;; expand word
7428 ((= (char-syntax (preceding-char)) ?w)
7429 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7430 (case-replace nil)
7431 (hippie-expand-only-buffers
7432 (or (and (boundp 'hippie-expand-only-buffers)
7433 hippie-expand-only-buffers)
7434 '(vhdl-mode))))
7435 (vhdl-expand-abbrev prefix-arg)))
7436 ;; expand parenthesis
7437 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7438 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7439 (case-replace nil))
7440 (vhdl-expand-paren prefix-arg)))
7441 ;; insert tab
7442 ((> (current-column) (current-indentation))
7443 (insert-tab))
7444 ;; toggle comment indent
7445 ((and (looking-at "--")
7446 (or (eq last-command 'vhdl-electric-tab)
7447 (eq last-command 'vhdl-electric-return)))
7448 (cond ((= (current-indentation) 0) ; no indent
7449 (indent-to 1)
7450 (indent-according-to-mode))
7451 ((< (current-indentation) comment-column) ; normal indent
7452 (indent-to comment-column)
7453 (indent-according-to-mode))
7454 (t ; inline comment indent
7455 (delete-region (line-beginning-position) (point)))))
7456 ;; dedent
7457 ((and (>= (current-indentation) vhdl-basic-offset)
7458 (or (eq last-command 'vhdl-electric-tab)
7459 (eq last-command 'vhdl-electric-return)))
7460 (backward-delete-char-untabify vhdl-basic-offset nil))
7461 ;; indent line
7462 (t (indent-according-to-mode)))
7463 (setq this-command 'vhdl-electric-tab)))
7465 (defun vhdl-electric-return ()
7466 "newline-and-indent or indent-new-comment-line if in comment and preceding
7467 character is a space."
7468 (interactive)
7469 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7470 (indent-new-comment-line)
7471 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7472 (not (vhdl-in-comment-p)))
7473 (vhdl-fix-case-word -1))
7474 (newline-and-indent)))
7476 (defun vhdl-indent-line ()
7477 "Indent the current line as VHDL code. Returns the amount of
7478 indentation change."
7479 (interactive)
7480 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7481 (pos (- (point-max) (point)))
7482 (is-comment nil)
7483 (indent
7484 (if syntax
7485 ;; indent syntax-based
7486 (if (and (eq (caar syntax) 'comment)
7487 (>= (vhdl-get-offset (car syntax)) comment-column))
7488 ;; special case: comments at or right of comment-column
7489 (vhdl-get-offset (car syntax))
7490 ;; align comments like following code line
7491 (when vhdl-indent-comment-like-next-code-line
7492 (save-excursion
7493 (while (eq (caar syntax) 'comment)
7494 (setq is-comment t)
7495 (beginning-of-line 2)
7496 (setq syntax (vhdl-get-syntactic-context)))))
7497 (when is-comment
7498 (push (cons 'comment nil) syntax))
7499 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7500 ;; indent like previous nonblank line
7501 (save-excursion (beginning-of-line)
7502 (re-search-backward "^[^\n]" nil t)
7503 (current-indentation))))
7504 (shift-amt (- indent (current-indentation))))
7505 (and vhdl-echo-syntactic-information-p
7506 (message "syntax: %s, indent= %d" syntax indent))
7507 (let ((has-formfeed
7508 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7509 (when (or (not (zerop shift-amt)) has-formfeed)
7510 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7511 (beginning-of-line)
7512 (when has-formfeed (insert "\f"))
7513 (indent-to indent)))
7514 (if (< (point) (vhdl-point 'boi))
7515 (back-to-indentation)
7516 ;; If initial point was within line's indentation, position after
7517 ;; the indentation. Else stay at same point in text.
7518 (when (> (- (point-max) pos) (point))
7519 (goto-char (- (point-max) pos))))
7520 (run-hooks 'vhdl-special-indent-hook)
7521 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7522 shift-amt))
7524 (defun vhdl-indent-region (beg end &optional column)
7525 "Indent region as VHDL code.
7526 Adds progress reporting to `indent-region'."
7527 (interactive "r\nP")
7528 (when vhdl-progress-interval
7529 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7530 (count-lines (point-min) end) 0)))
7531 (indent-region beg end column)
7532 (when vhdl-progress-interval (message "Indenting...done"))
7533 (setq vhdl-progress-info nil))
7535 (defun vhdl-indent-buffer ()
7536 "Indent whole buffer as VHDL code.
7537 Calls `indent-region' for whole buffer and adds progress reporting."
7538 (interactive)
7539 (vhdl-indent-region (point-min) (point-max)))
7541 (defun vhdl-indent-group ()
7542 "Indent group of lines between empty lines."
7543 (interactive)
7544 (let ((beg (save-excursion
7545 (if (re-search-backward vhdl-align-group-separate nil t)
7546 (point-marker)
7547 (point-min-marker))))
7548 (end (save-excursion
7549 (if (re-search-forward vhdl-align-group-separate nil t)
7550 (point-marker)
7551 (point-max-marker)))))
7552 (vhdl-indent-region beg end)))
7554 (defun vhdl-indent-sexp (&optional endpos)
7555 "Indent each line of the list starting just after point.
7556 If optional arg ENDPOS is given, indent each line, stopping when
7557 ENDPOS is encountered."
7558 (interactive)
7559 (save-excursion
7560 (let ((beg (point))
7561 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7562 (indent-region beg end nil))))
7564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7565 ;; Miscellaneous commands
7567 (defun vhdl-show-syntactic-information ()
7568 "Show syntactic information for current line."
7569 (interactive)
7570 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7571 (vhdl-keep-region-active))
7573 ;; Verification and regression functions:
7575 (defun vhdl-regress-line (&optional arg)
7576 "Check syntactic information for current line."
7577 (interactive "P")
7578 (let ((expected (save-excursion
7579 (end-of-line)
7580 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7581 (forward-char 4)
7582 (read (current-buffer)))))
7583 (actual (vhdl-get-syntactic-context))
7584 (expurgated))
7585 ;; remove the library unit symbols
7586 (mapc
7587 (function
7588 (lambda (elt)
7589 (if (memq (car elt) '(entity configuration context package
7590 package-body architecture))
7592 (setq expurgated (append expurgated (list elt))))))
7593 actual)
7594 (if (and (not arg) expected (listp expected))
7595 (if (not (equal expected expurgated))
7596 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7597 (save-excursion
7598 (beginning-of-line)
7599 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7600 (end-of-line)
7601 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7602 (delete-region (point) (line-end-position)))
7603 (insert " -- ")
7604 (insert (format "%s" expurgated))))))
7605 (vhdl-keep-region-active))
7608 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7609 ;;; Alignment, beautifying
7610 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7612 (defconst vhdl-align-alist
7614 ;; after some keywords
7615 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7616 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7617 ;; before ':'
7618 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7619 ;; after direction specifications
7620 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7621 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7622 ;; before "==", ":=", "=>", and "<="
7623 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7624 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7625 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7626 ;; before some keywords
7627 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7628 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7629 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7630 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7631 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7632 ;; before "=>" since "when/else ... =>" can occur
7633 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7635 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7636 It is searched in order. If REGEXP is found anywhere in the first
7637 line of a region to be aligned, ALIGN-PATTERN will be used for that
7638 region. ALIGN-PATTERN must include the whitespace to be expanded or
7639 contracted. It may also provide regexps for the text surrounding the
7640 whitespace. SUBEXP specifies which sub-expression of
7641 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7644 ;; Align code
7646 (defvar vhdl-align-try-all-clauses t
7647 "If REGEXP is not found on the first line of the region that clause
7648 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7650 (defun vhdl-do-group (function &optional spacing)
7651 "Apply FUNCTION on group of lines between empty lines."
7652 (let
7653 ;; search for group beginning
7654 ((beg (save-excursion
7655 (if (re-search-backward vhdl-align-group-separate nil t)
7656 (progn (beginning-of-line 2) (back-to-indentation) (point))
7657 (point-min))))
7658 ;; search for group end
7659 (end (save-excursion
7660 (if (re-search-forward vhdl-align-group-separate nil t)
7661 (progn (beginning-of-line) (point))
7662 (point-max)))))
7663 ;; run FUNCTION
7664 (funcall function beg end spacing)))
7666 (defun vhdl-do-list (function &optional spacing)
7667 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7668 parentheses."
7669 (let (beg end)
7670 (save-excursion
7671 ;; search for beginning of balanced group of parentheses
7672 (setq beg (vhdl-re-search-backward "[()]" nil t))
7673 (while (looking-at ")")
7674 (forward-char) (backward-sexp)
7675 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7676 ;; search for end of balanced group of parentheses
7677 (when beg
7678 (forward-list)
7679 (setq end (point))
7680 (goto-char (1+ beg))
7681 (skip-chars-forward " \t\n\r\f")
7682 (setq beg (point))))
7683 ;; run FUNCTION
7684 (if beg
7685 (funcall function beg end spacing)
7686 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7688 (defun vhdl-do-same-indent (function &optional spacing)
7689 "Apply FUNCTION to block of lines with same indent."
7690 (let ((indent (current-indentation))
7691 beg end)
7692 ;; search for first line with same indent
7693 (save-excursion
7694 (while (and (not (bobp))
7695 (or (looking-at "^\\s-*\\(--.*\\)?$")
7696 (= (current-indentation) indent)))
7697 (unless (looking-at "^\\s-*$")
7698 (back-to-indentation) (setq beg (point)))
7699 (beginning-of-line -0)))
7700 ;; search for last line with same indent
7701 (save-excursion
7702 (while (and (not (eobp))
7703 (or (looking-at "^\\s-*\\(--.*\\)?$")
7704 (= (current-indentation) indent)))
7705 (if (looking-at "^\\s-*$")
7706 (beginning-of-line 2)
7707 (beginning-of-line 2)
7708 (setq end (point)))))
7709 ;; run FUNCTION
7710 (funcall function beg end spacing)))
7712 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7713 "Attempt to align a range of lines based on the content of the
7714 lines. The definition of `alignment-list' determines the matching
7715 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7716 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7717 indentation is done before aligning."
7718 (interactive "r\np")
7719 (setq alignment-list (or alignment-list vhdl-align-alist))
7720 (setq spacing (or spacing 1))
7721 (save-excursion
7722 (let (bol indent)
7723 (goto-char end)
7724 (setq end (point-marker))
7725 (goto-char begin)
7726 (setq bol (setq begin (progn (beginning-of-line) (point))))
7727 (when indent
7728 (indent-region bol end nil))))
7729 (let ((copy (copy-alist alignment-list)))
7730 (vhdl-prepare-search-2
7731 (while copy
7732 (save-excursion
7733 (goto-char begin)
7734 (let (element
7735 (eol (point-at-eol)))
7736 (setq element (nth 0 copy))
7737 (when (and (or (and (listp (car element))
7738 (memq major-mode (car element)))
7739 (eq major-mode (car element)))
7740 (or vhdl-align-try-all-clauses
7741 (re-search-forward (car (cdr element)) eol t)))
7742 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7743 (car (cdr (cdr (cdr element)))) spacing))
7744 (setq copy (cdr copy))))))))
7746 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7747 "Align a range of lines from BEGIN to END. The regular expression
7748 MATCH must match exactly one field: the whitespace to be
7749 contracted/expanded. The alignment column will equal the
7750 rightmost column of the widest whitespace block. SPACING is
7751 the amount of extra spaces to add to the calculated maximum required.
7752 SPACING defaults to 1 so that at least one space is inserted after
7753 the token in MATCH."
7754 (setq spacing (or spacing 1))
7755 (setq substr (or substr 1))
7756 (save-excursion
7757 (let (distance (max 0) (lines 0) bol eol width)
7758 ;; Determine the greatest whitespace distance to the alignment
7759 ;; character
7760 (goto-char begin)
7761 (setq eol (point-at-eol)
7762 bol (setq begin (progn (beginning-of-line) (point))))
7763 (while (< bol end)
7764 (save-excursion
7765 (when (and (vhdl-re-search-forward match eol t)
7766 (save-excursion
7767 (goto-char (match-beginning 0))
7768 (forward-char)
7769 (and (not (vhdl-in-literal))
7770 (not (vhdl-in-quote-p))
7771 (not (vhdl-in-extended-identifier-p))))
7772 (not (looking-at "\\s-*$")))
7773 (setq distance (- (match-beginning substr) bol))
7774 (when (> distance max)
7775 (setq max distance))))
7776 (forward-line)
7777 (setq bol (point)
7778 eol (point-at-eol))
7779 (setq lines (1+ lines)))
7780 ;; Now insert enough maxs to push each assignment operator to
7781 ;; the same column. We need to use 'lines' as a counter, since
7782 ;; the location of the mark may change
7783 (goto-char (setq bol begin))
7784 (setq eol (point-at-eol))
7785 (while (> lines 0)
7786 (when (and (vhdl-re-search-forward match eol t)
7787 (save-excursion
7788 (goto-char (match-beginning 0))
7789 (forward-char)
7790 (and (not (vhdl-in-literal))
7791 (not (vhdl-in-quote-p))
7792 (not (vhdl-in-extended-identifier-p))))
7793 (not (looking-at "\\s-*$"))
7794 (> (match-beginning 0) ; not if at boi
7795 (save-excursion (back-to-indentation) (point))))
7796 (setq width (- (match-end substr) (match-beginning substr)))
7797 (setq distance (- (match-beginning substr) bol))
7798 (goto-char (match-beginning substr))
7799 (delete-char width)
7800 (insert-char ? (+ (- max distance) spacing)))
7801 (beginning-of-line)
7802 (forward-line)
7803 (setq bol (point)
7804 eol (point-at-eol))
7805 (setq lines (1- lines))))))
7807 (defun vhdl-align-region-groups (beg end &optional spacing
7808 no-message no-comments)
7809 "Align region, treat groups of lines separately."
7810 (interactive "r\nP")
7811 (save-excursion
7812 (let (orig pos)
7813 (goto-char beg)
7814 (beginning-of-line)
7815 (setq orig (point-marker))
7816 (setq beg (point))
7817 (goto-char end)
7818 (setq end (point-marker))
7819 (untabify beg end)
7820 (unless no-message
7821 (when vhdl-progress-interval
7822 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7823 (count-lines (point-min) end) 0))))
7824 (when (nth 0 vhdl-beautify-options)
7825 (vhdl-fixup-whitespace-region beg end t))
7826 (goto-char beg)
7827 (if (not vhdl-align-groups)
7828 ;; align entire region
7829 (progn (vhdl-align-region-1 beg end spacing)
7830 (unless no-comments
7831 (vhdl-align-inline-comment-region-1 beg end)))
7832 ;; align groups
7833 (while (and (< beg end)
7834 (re-search-forward vhdl-align-group-separate end t))
7835 (setq pos (point-marker))
7836 (vhdl-align-region-1 beg pos spacing)
7837 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7838 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7839 (setq beg (1+ pos))
7840 (goto-char beg))
7841 ;; align last group
7842 (when (< beg end)
7843 (vhdl-align-region-1 beg end spacing)
7844 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7845 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7846 (when vhdl-indent-tabs-mode
7847 (tabify orig end))
7848 (unless no-message
7849 (when vhdl-progress-interval (message "Aligning...done"))
7850 (setq vhdl-progress-info nil)))))
7852 (defun vhdl-align-region (beg end &optional spacing)
7853 "Align region, treat blocks with same indent and argument lists separately."
7854 (interactive "r\nP")
7855 (if (not vhdl-align-same-indent)
7856 ;; align entire region
7857 (vhdl-align-region-groups beg end spacing)
7858 ;; align blocks with same indent and argument lists
7859 (save-excursion
7860 (let ((cur-beg beg)
7861 indent cur-end)
7862 (when vhdl-progress-interval
7863 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7864 (count-lines (point-min) end) 0)))
7865 (goto-char end)
7866 (setq end (point-marker))
7867 (goto-char cur-beg)
7868 (while (< (point) end)
7869 ;; is argument list opening?
7870 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7871 (point) (vhdl-point 'eol)))))
7872 ;; determine region for argument list
7873 (progn (goto-char cur-beg)
7874 (forward-sexp)
7875 (setq cur-end (point))
7876 (beginning-of-line 2))
7877 ;; determine region with same indent
7878 (setq indent (current-indentation))
7879 (setq cur-beg (point))
7880 (setq cur-end (vhdl-point 'bonl))
7881 (beginning-of-line 2)
7882 (while (and (< (point) end)
7883 (or (looking-at "^\\s-*\\(--.*\\)?$")
7884 (= (current-indentation) indent))
7885 (<= (save-excursion
7886 (nth 0 (parse-partial-sexp
7887 (point) (vhdl-point 'eol)))) 0))
7888 (unless (looking-at "^\\s-*$")
7889 (setq cur-end (vhdl-point 'bonl)))
7890 (beginning-of-line 2)))
7891 ;; align region
7892 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7893 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7894 (when vhdl-progress-interval (message "Aligning...done"))
7895 (setq vhdl-progress-info nil)))))
7897 (defun vhdl-align-group (&optional spacing)
7898 "Align group of lines between empty lines."
7899 (interactive)
7900 (vhdl-do-group 'vhdl-align-region spacing))
7902 (defun vhdl-align-list (&optional spacing)
7903 "Align the lines of a list surrounded by a balanced group of parentheses."
7904 (interactive)
7905 (vhdl-do-list 'vhdl-align-region-groups spacing))
7907 (defun vhdl-align-same-indent (&optional spacing)
7908 "Align block of lines with same indent."
7909 (interactive)
7910 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7912 (defun vhdl-align-declarations (&optional spacing)
7913 "Align the lines within the declarative part of a design unit."
7914 (interactive)
7915 (let (beg end)
7916 (vhdl-prepare-search-2
7917 (save-excursion
7918 ;; search for declarative part
7919 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|context\\|end\\|entity\\|package\\)\\>" nil t)
7920 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7921 (setq beg (point))
7922 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7923 (setq end (point)))))
7924 (if beg
7925 (vhdl-align-region-groups beg end spacing)
7926 (error "ERROR: Not within the declarative part of a design unit"))))
7928 (defun vhdl-align-buffer ()
7929 "Align buffer."
7930 (interactive)
7931 (vhdl-align-region (point-min) (point-max)))
7933 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7934 ;; Align inline comments
7936 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7937 "Align inline comments in region."
7938 (save-excursion
7939 (let ((start-max comment-column)
7940 (length-max 0)
7941 comment-list start-list tmp-list start length
7942 cur-start prev-start no-code)
7943 (setq spacing (or spacing 2))
7944 (vhdl-prepare-search-2
7945 (goto-char beg)
7946 ;; search for comment start positions and lengths
7947 (while (< (point) end)
7948 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7949 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7950 (not (save-excursion (goto-char (match-beginning 2))
7951 (vhdl-in-literal))))
7952 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7953 (setq length (- (match-end 2) (match-beginning 2)))
7954 (setq start-max (max start start-max))
7955 (setq length-max (max length length-max))
7956 (push (cons start length) comment-list))
7957 (beginning-of-line 2))
7958 (setq comment-list
7959 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7960 ;; reduce start positions
7961 (setq start-list (list (caar comment-list)))
7962 (setq comment-list (cdr comment-list))
7963 (while comment-list
7964 (unless (or (= (caar comment-list) (car start-list))
7965 (<= (+ (car start-list) (cdar comment-list))
7966 end-comment-column))
7967 (push (caar comment-list) start-list))
7968 (setq comment-list (cdr comment-list)))
7969 ;; align lines as nicely as possible
7970 (goto-char beg)
7971 (while (< (point) end)
7972 (setq cur-start nil)
7973 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7974 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7975 (not (save-excursion
7976 (goto-char (match-beginning 3))
7977 (vhdl-in-literal))))
7978 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7979 (>= (- (match-end 2) (match-beginning 2))
7980 comment-column))))
7981 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7982 (setq length (- (match-end 3) (match-beginning 3)))
7983 (setq no-code (= (match-beginning 1) (match-end 1)))
7984 ;; insert minimum whitespace
7985 (goto-char (match-end 2))
7986 (delete-region (match-beginning 2) (match-end 2))
7987 (insert-char ?\ spacing)
7988 (setq tmp-list start-list)
7989 ;; insert additional whitespace to align
7990 (setq cur-start
7991 (cond
7992 ;; align comment-only line to inline comment of previous line
7993 ((and no-code prev-start
7994 (<= length (- end-comment-column prev-start)))
7995 prev-start)
7996 ;; align all comments at `start-max' if this is possible
7997 ((<= (+ start-max length-max) end-comment-column)
7998 start-max)
7999 ;; align at `comment-column' if possible
8000 ((and (<= start comment-column)
8001 (<= length (- end-comment-column comment-column)))
8002 comment-column)
8003 ;; align at left-most possible start position otherwise
8005 (while (and tmp-list (< (car tmp-list) start))
8006 (setq tmp-list (cdr tmp-list)))
8007 (car tmp-list))))
8008 (indent-to cur-start))
8009 (setq prev-start cur-start)
8010 (beginning-of-line 2))))))
8012 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
8013 "Align inline comments within a region. Groups of code lines separated by
8014 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8015 (interactive "r\nP")
8016 (save-excursion
8017 (let (orig pos)
8018 (goto-char beg)
8019 (beginning-of-line)
8020 (setq orig (point-marker))
8021 (setq beg (point))
8022 (goto-char end)
8023 (setq end (point-marker))
8024 (untabify beg end)
8025 (unless no-message (message "Aligning inline comments..."))
8026 (goto-char beg)
8027 (if (not vhdl-align-groups)
8028 ;; align entire region
8029 (vhdl-align-inline-comment-region-1 beg end spacing)
8030 ;; align groups
8031 (while (and (< beg end)
8032 (re-search-forward vhdl-align-group-separate end t))
8033 (setq pos (point-marker))
8034 (vhdl-align-inline-comment-region-1 beg pos spacing)
8035 (setq beg (1+ pos))
8036 (goto-char beg))
8037 ;; align last group
8038 (when (< beg end)
8039 (vhdl-align-inline-comment-region-1 beg end spacing)))
8040 (when vhdl-indent-tabs-mode
8041 (tabify orig end))
8042 (unless no-message (message "Aligning inline comments...done")))))
8044 (defun vhdl-align-inline-comment-group (&optional spacing)
8045 "Align inline comments within a group of lines between empty lines."
8046 (interactive)
8047 (save-excursion
8048 (let ((start (point))
8049 beg end)
8050 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
8051 (point-marker) (point-max)))
8052 (goto-char start)
8053 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
8054 (point) (point-min)))
8055 (untabify beg end)
8056 (message "Aligning inline comments...")
8057 (vhdl-align-inline-comment-region-1 beg end)
8058 (when vhdl-indent-tabs-mode
8059 (tabify beg end))
8060 (message "Aligning inline comments...done"))))
8062 (defun vhdl-align-inline-comment-buffer ()
8063 "Align inline comments within buffer. Groups of code lines separated by
8064 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
8065 (interactive)
8066 (vhdl-align-inline-comment-region (point-min) (point-max)))
8068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8069 ;; Fixup whitespace
8071 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
8072 "Fixup whitespace in region. Surround operator symbols by one space,
8073 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8074 end of line, do nothing in comments and strings."
8075 (interactive "r")
8076 (unless no-message (message "Fixing up whitespace..."))
8077 (save-excursion
8078 (goto-char end)
8079 (setq end (point-marker))
8080 ;; have no space before and one space after `,' and ';'
8081 (goto-char beg)
8082 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
8083 (if (match-string 1)
8084 (goto-char (match-end 1))
8085 (replace-match "\\3 " nil nil nil 2)))
8086 ;; have no space after `('
8087 (goto-char beg)
8088 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
8089 (if (match-string 1)
8090 (goto-char (match-end 1))
8091 (replace-match "\\2")))
8092 ;; have no space before `)'
8093 (goto-char beg)
8094 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
8095 (if (match-string 1)
8096 (goto-char (match-end 1))
8097 (replace-match "\\2")))
8098 ;; surround operator symbols by one space
8099 (goto-char beg)
8100 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
8101 (if (or (match-string 1)
8102 (<= (match-beginning 0) ; not if at boi
8103 (save-excursion (back-to-indentation) (point))))
8104 (goto-char (match-end 0))
8105 (replace-match "\\3 \\4 \\5")
8106 (goto-char (match-end 2))))
8107 ;; eliminate multiple spaces and spaces at end of line
8108 (goto-char beg)
8109 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
8110 (and (looking-at "--.*") (re-search-forward "--.*" end t))
8111 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
8112 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
8113 (progn (replace-match "" nil nil) t))
8114 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
8115 (progn (replace-match ";" nil nil) t))
8116 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
8117 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
8118 (progn (replace-match " " nil nil) t))
8119 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
8120 (progn (replace-match " " nil nil) t))
8121 (and (looking-at "-") (re-search-forward "-" end t))
8122 (re-search-forward "[^ \t\"-]+" end t))))
8123 (unless no-message (message "Fixing up whitespace...done")))
8125 (defun vhdl-fixup-whitespace-buffer ()
8126 "Fixup whitespace in buffer. Surround operator symbols by one space,
8127 eliminate multiple spaces (except at beginning of line), eliminate spaces at
8128 end of line, do nothing in comments."
8129 (interactive)
8130 (vhdl-fixup-whitespace-region (point-min) (point-max)))
8132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8133 ;; Case fixing
8135 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
8136 "Convert all words matching WORD-REGEXP in region to lower or upper case,
8137 depending on parameter UPPER-CASE."
8138 (let ((case-replace nil)
8139 (last-update 0))
8140 (vhdl-prepare-search-2
8141 (save-excursion
8142 (goto-char end)
8143 (setq end (point-marker))
8144 (goto-char beg)
8145 (while (re-search-forward word-regexp end t)
8146 (or (vhdl-in-literal)
8147 (if upper-case
8148 (upcase-word -1)
8149 (downcase-word -1)))
8150 (when (and count vhdl-progress-interval (not noninteractive)
8151 (< vhdl-progress-interval
8152 (- (nth 1 (current-time)) last-update)))
8153 (message "Fixing case... (%2d%s)"
8154 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
8155 "%")
8156 (setq last-update (nth 1 (current-time)))))
8157 (goto-char end)))))
8159 (defun vhdl-fix-case-region (beg end &optional arg)
8160 "Convert all VHDL words in region to lower or upper case, depending on
8161 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8162 (interactive "r\nP")
8163 (vhdl-fix-case-region-1
8164 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
8165 (vhdl-fix-case-region-1
8166 beg end vhdl-upper-case-types vhdl-types-regexp 1)
8167 (vhdl-fix-case-region-1
8168 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
8169 (vhdl-fix-case-region-1
8170 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
8171 (vhdl-fix-case-region-1
8172 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
8173 (when vhdl-progress-interval (message "Fixing case...done")))
8175 (defun vhdl-fix-case-buffer ()
8176 "Convert all VHDL words in buffer to lower or upper case, depending on
8177 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8178 (interactive)
8179 (vhdl-fix-case-region (point-min) (point-max)))
8181 (defun vhdl-fix-case-word (&optional arg)
8182 "Convert word after cursor to upper case if necessary."
8183 (interactive "p")
8184 (save-excursion
8185 (when arg (backward-word 1))
8186 (vhdl-prepare-search-1
8187 (when (and vhdl-upper-case-keywords
8188 (looking-at vhdl-keywords-regexp))
8189 (upcase-word 1))
8190 (when (and vhdl-upper-case-types
8191 (looking-at vhdl-types-regexp))
8192 (upcase-word 1))
8193 (when (and vhdl-upper-case-attributes
8194 (looking-at vhdl-attributes-regexp))
8195 (upcase-word 1))
8196 (when (and vhdl-upper-case-enum-values
8197 (looking-at vhdl-enum-values-regexp))
8198 (upcase-word 1))
8199 (when (and vhdl-upper-case-constants
8200 (looking-at vhdl-constants-regexp))
8201 (upcase-word 1)))))
8203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8204 ;; Fix statements
8205 ;; - force each statement to be on a separate line except when on same line
8206 ;; with 'end' keyword
8208 (defun vhdl-fix-statement-region (beg end &optional arg)
8209 "Force statements in region on separate line except when on same line
8210 with 'end' keyword (necessary for correct indentation).
8211 Currently supported keywords: 'begin', 'if'."
8212 (interactive "r\nP")
8213 (vhdl-prepare-search-2
8214 (let (point)
8215 (save-excursion
8216 (goto-char end)
8217 (setq end (point-marker))
8218 (goto-char beg)
8219 ;; `begin' keyword
8220 (while (re-search-forward
8221 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
8222 (goto-char (match-end 0))
8223 (setq point (point-marker))
8224 (when (and (match-string 1)
8225 (or (not (match-string 2))
8226 (save-excursion (goto-char (match-end 2))
8227 (vhdl-in-literal)))
8228 (not (save-excursion (goto-char (match-beginning 1))
8229 (vhdl-in-literal))))
8230 (goto-char (match-beginning 1))
8231 (insert "\n")
8232 (indent-according-to-mode))
8233 (goto-char point))
8234 (goto-char beg)
8235 ;; `for', `if' keywords
8236 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
8237 (goto-char (match-end 1))
8238 (setq point (point-marker))
8239 ;; exception: in literal or preceded by `end', `wait' or label
8240 (when (and (not (save-excursion (goto-char (match-beginning 1))
8241 (vhdl-in-literal)))
8242 (save-excursion
8243 (beginning-of-line 1)
8244 (save-match-data
8245 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8246 (match-beginning 1) t)
8247 (not (string-match
8248 "\\(\\<end\\>\\|\\<wait .*\\|\\w+\\s-*:\\)\\s-*$"
8249 (match-string 1)))))))
8250 (goto-char (match-beginning 1))
8251 (insert "\n")
8252 (indent-according-to-mode))
8253 (goto-char point))))))
8255 (defun vhdl-fix-statement-buffer ()
8256 "Force statements in buffer on separate line except when on same line
8257 with 'end' keyword (necessary for correct indentation)."
8258 (interactive)
8259 (vhdl-fix-statement-region (point-min) (point-max)))
8261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8262 ;; Trailing spaces
8264 (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
8265 "Remove trailing spaces in region."
8266 (interactive "r\nP")
8267 (save-excursion
8268 (goto-char end)
8269 (setq end (point-marker))
8270 (goto-char beg)
8271 (while (re-search-forward "[ \t]+$" end t)
8272 (unless (vhdl-in-literal)
8273 (replace-match "" nil nil)))))
8275 (defun vhdl-remove-trailing-spaces ()
8276 "Remove trailing spaces in buffer."
8277 (interactive)
8278 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8281 ;; Beautify
8283 (defun vhdl-beautify-region (beg end)
8284 "Beautify region by applying indentation, whitespace fixup, alignment, and
8285 case fixing to a region. Calls functions `vhdl-indent-buffer',
8286 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8287 `vhdl-fix-case-buffer'."
8288 (interactive "r")
8289 (setq end (save-excursion (goto-char end) (point-marker)))
8290 (save-excursion ; remove DOS EOL characters in UNIX file
8291 (goto-char beg)
8292 (while (search-forward " " nil t)
8293 (replace-match "" nil t)))
8294 (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
8295 (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
8296 (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
8297 (when (nth 3 vhdl-beautify-options)
8298 (let ((vhdl-align-groups t)) (vhdl-align-region beg end)))
8299 (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
8300 (when (nth 0 vhdl-beautify-options)
8301 (vhdl-remove-trailing-spaces-region beg end)
8302 (if vhdl-indent-tabs-mode (tabify beg end) (untabify beg end))))
8304 (defun vhdl-beautify-buffer ()
8305 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8306 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8307 buffer."
8308 (interactive)
8309 (vhdl-beautify-region (point-min) (point-max))
8310 (when noninteractive (save-buffer)))
8312 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8313 ;; Code filling
8315 (defun vhdl-fill-region (beg end &optional arg)
8316 "Fill lines for a region of code."
8317 (interactive "r\np")
8318 (save-excursion
8319 (goto-char beg)
8320 (let ((margin (if arg (current-indentation) (current-column))))
8321 (goto-char end)
8322 (setq end (point-marker))
8323 ;; remove inline comments, newlines and whitespace
8324 (vhdl-comment-kill-region beg end)
8325 (vhdl-comment-kill-inline-region beg end)
8326 (subst-char-in-region beg (1- end) ?\n ?\ )
8327 (vhdl-fixup-whitespace-region beg end)
8328 ;; wrap and end-comment-column
8329 (goto-char beg)
8330 (while (re-search-forward "\\s-" end t)
8331 (when(> (current-column) vhdl-end-comment-column)
8332 (backward-char)
8333 (when (re-search-backward "\\s-" beg t)
8334 (replace-match "\n")
8335 (indent-to margin)))))))
8337 (defun vhdl-fill-group ()
8338 "Fill group of lines between empty lines."
8339 (interactive)
8340 (vhdl-do-group 'vhdl-fill-region))
8342 (defun vhdl-fill-list ()
8343 "Fill the lines of a list surrounded by a balanced group of parentheses."
8344 (interactive)
8345 (vhdl-do-list 'vhdl-fill-region))
8347 (defun vhdl-fill-same-indent ()
8348 "Fill the lines of block of lines with same indent."
8349 (interactive)
8350 (vhdl-do-same-indent 'vhdl-fill-region))
8353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8354 ;;; Code updating/fixing
8355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8357 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8358 ;; Sensitivity list update
8360 ;; Strategy:
8361 ;; - no sensitivity list is generated for processes with wait statements
8362 ;; - otherwise, do the following:
8363 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8364 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8365 ;; manually entered global signals)
8366 ;; 3. signals from 1. and 2. form the list of visible signals
8367 ;; 4. search for if/elsif conditions containing an event (sequential code)
8368 ;; 5. scan for strings that are within syntactical regions where signals are
8369 ;; read but not within sequential code, and that correspond to visible
8370 ;; signals
8371 ;; 6. replace sensitivity list by list of signals from 5.
8373 (defun vhdl-update-sensitivity-list-process ()
8374 "Update sensitivity list of current process."
8375 (interactive)
8376 (save-excursion
8377 (vhdl-prepare-search-2
8378 (end-of-line)
8379 ;; look whether in process
8380 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8381 (equal (upcase (match-string 2)) "PROCESS")
8382 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8383 (error "ERROR: Not within a process")
8384 (message "Updating sensitivity list...")
8385 (vhdl-update-sensitivity-list)
8386 (message "Updating sensitivity list...done")))))
8388 (defun vhdl-update-sensitivity-list-buffer ()
8389 "Update sensitivity list of all processes in current buffer."
8390 (interactive)
8391 (save-excursion
8392 (vhdl-prepare-search-2
8393 (goto-char (point-min))
8394 (message "Updating sensitivity lists...")
8395 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8396 (goto-char (match-beginning 0))
8397 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8398 (message "Updating sensitivity lists...done")))
8399 (when noninteractive (save-buffer)))
8401 (defun vhdl-update-sensitivity-list ()
8402 "Update sensitivity list."
8403 (let ((proc-beg (point))
8404 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8405 (proc-mid (vhdl-re-search-backward
8406 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8407 seq-region-list)
8408 (cond
8409 ;; error if 'begin' keyword missing
8410 ((not (match-string 2))
8411 (error "ERROR: No 'begin' keyword found"))
8412 ;; search for wait statement (no sensitivity list allowed)
8413 ((progn (goto-char proc-mid)
8414 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8415 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8416 ;; combinational process (update sensitivity list)
8418 (let
8419 ;; scan for visible signals
8420 ((visible-list (vhdl-get-visible-signals))
8421 ;; define syntactic regions where signals are read
8422 (scan-regions-list
8423 '(;; right-hand side of signal/variable assignment
8424 ;; (special case: "<=" is relational operator in a condition)
8425 ((vhdl-re-search-forward "[<:]=" proc-end t)
8426 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8427 ;; if condition
8428 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
8429 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8430 ;; elsif condition
8431 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
8432 (vhdl-re-search-forward "\\<then\\>" proc-end t))
8433 ;; while loop condition
8434 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
8435 (vhdl-re-search-forward "\\<loop\\>" proc-end t))
8436 ;; exit/next condition
8437 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8438 (vhdl-re-search-forward ";" proc-end t))
8439 ;; assert condition
8440 ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
8441 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8442 ;; case expression
8443 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
8444 (vhdl-re-search-forward "\\<is\\>" proc-end t))
8445 ;; parameter list of procedure call, array index
8446 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8447 (1- (point)))
8448 (progn (backward-char) (forward-sexp)
8449 (while (looking-at "(") (forward-sexp)) (point)))))
8450 name field read-list sens-list signal-list tmp-list
8451 sens-beg sens-end beg end margin)
8452 ;; scan for signals in old sensitivity list
8453 (goto-char proc-beg)
8454 (vhdl-re-search-forward "\\<process\\>" proc-mid t)
8455 (if (not (looking-at "[ \t\n\r\f]*("))
8456 (setq sens-beg (point))
8457 (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8458 (goto-char (match-end 1))
8459 (forward-sexp)
8460 (setq sens-end (1- (point)))
8461 (goto-char sens-beg)
8462 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
8463 (setq sens-list
8464 (cons (downcase (match-string 0)) sens-list))
8465 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
8466 (setq signal-list (append visible-list sens-list))
8467 ;; search for sequential parts
8468 (goto-char proc-mid)
8469 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8470 (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
8471 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8472 (goto-char end)
8473 (backward-word 1)
8474 (vhdl-forward-sexp)
8475 (push (cons end (point)) seq-region-list)
8476 (beginning-of-line)))
8477 ;; scan for signals read in process
8478 (while scan-regions-list
8479 (goto-char proc-mid)
8480 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8481 (setq end (eval (nth 1 (car scan-regions-list)))))
8482 (goto-char beg)
8483 (unless (or (vhdl-in-literal)
8484 (and seq-region-list
8485 (let ((tmp-list seq-region-list))
8486 (while (and tmp-list
8487 (< (point) (caar tmp-list)))
8488 (setq tmp-list (cdr tmp-list)))
8489 (and tmp-list (< (point) (cdar tmp-list))))))
8490 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8491 (setq name (match-string 1))
8492 ;; get array index range
8493 (when vhdl-array-index-record-field-in-sensitivity-list
8494 (setq field (match-string 2))
8495 ;; not use if it includes a variable name
8496 (save-match-data
8497 (setq tmp-list visible-list)
8498 (while (and field tmp-list)
8499 (when (string-match
8500 (concat "\\<" (car tmp-list) "\\>") field)
8501 (setq field nil))
8502 (setq tmp-list (cdr tmp-list)))))
8503 (when (and (not (match-string 6)) ; not when formal parameter
8504 (not (and (match-string 5) ; not event attribute
8505 (not (member (downcase (match-string 5))
8506 '("event" "last_event" "transaction")))))
8507 (member (downcase name) signal-list))
8508 ;; not add if name or name+field already exists
8509 (unless
8510 (or (member-ignore-case name read-list)
8511 (member-ignore-case (concat name field) read-list))
8512 (push (concat name field) read-list))
8513 (setq tmp-list read-list)
8514 ;; remove existing name+field if name is added
8515 (save-match-data
8516 (while tmp-list
8517 (when (string-match (concat "^" name field "[(.]")
8518 (car tmp-list))
8519 (setq read-list (delete (car tmp-list) read-list)))
8520 (setq tmp-list (cdr tmp-list)))))
8521 (goto-char (match-end 1)))))
8522 (setq scan-regions-list (cdr scan-regions-list)))
8523 ;; update sensitivity list
8524 (goto-char sens-beg)
8525 (if sens-end
8526 (delete-region sens-beg sens-end)
8527 (when read-list
8528 (insert " ()") (backward-char)))
8529 (setq read-list (sort read-list 'string<))
8530 (when read-list
8531 (setq margin (current-column))
8532 (insert (car read-list))
8533 (setq read-list (cdr read-list))
8534 (while read-list
8535 (insert ",")
8536 (if (<= (+ (current-column) (length (car read-list)) 2)
8537 end-comment-column)
8538 (insert " ")
8539 (insert "\n") (indent-to margin))
8540 (insert (car read-list))
8541 (setq read-list (cdr read-list)))))))))
8543 (defun vhdl-get-visible-signals ()
8544 "Get all signals visible in the current block."
8545 (let (beg end signal-list entity-name file-name)
8546 (vhdl-prepare-search-2
8547 ;; get entity name
8548 (save-excursion
8549 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8550 (not (equal "END" (upcase (match-string 1))))
8551 (setq entity-name (match-string 2)))
8552 (error "ERROR: Not within an architecture")))
8553 ;; search for signals declared in entity port clause
8554 (save-excursion
8555 (goto-char (point-min))
8556 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8557 (setq file-name
8558 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8559 "." (file-name-extension (buffer-file-name)))))
8560 (vhdl-visit-file
8561 file-name t
8562 (vhdl-prepare-search-2
8563 (goto-char (point-min))
8564 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8565 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8566 (when (setq beg (vhdl-re-search-forward
8567 "\\<port[ \t\n\r\f]*("
8568 (save-excursion
8569 (re-search-forward "^end\\>" nil t)) t))
8570 (setq end (save-excursion
8571 (backward-char) (forward-sexp) (point)))
8572 (vhdl-forward-syntactic-ws)
8573 (while (< (point) end)
8574 (when (looking-at "signal[ \t\n\r\f]+")
8575 (goto-char (match-end 0)))
8576 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8577 (setq signal-list
8578 (cons (downcase (match-string 1)) signal-list))
8579 (goto-char (match-end 0))
8580 (vhdl-forward-syntactic-ws))
8581 (re-search-forward ";" end 1)
8582 (vhdl-forward-syntactic-ws)))))))
8583 ;; search for signals declared in architecture declarative part
8584 (save-excursion
8585 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8586 (not (equal "END" (upcase (match-string 1))))
8587 (setq end (re-search-forward "^begin\\>" nil t))))
8588 (error "ERROR: No architecture declarative part found")
8589 ;; scan for all declared signal and alias names
8590 (goto-char beg)
8591 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8592 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8593 (if (match-string 2)
8594 ;; scan signal name
8595 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8596 (setq signal-list
8597 (cons (downcase (match-string 1)) signal-list))
8598 (goto-char (match-end 0)))
8599 ;; scan alias name, check is alias of (declared) signal
8600 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8601 (member (downcase (match-string 2)) signal-list))
8602 (setq signal-list
8603 (cons (downcase (match-string 1)) signal-list))
8604 (goto-char (match-end 0))))
8605 (setq beg (point))))))
8606 ;; search for signals declared in surrounding block declarative parts
8607 (save-excursion
8608 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*\\(block\\|\\(for\\|if\\).*\\<generate\\>\\)\\|\\(end\\)\\s-+block\\)\\>" nil t))
8609 (match-string 4))
8610 (goto-char (match-end 4))
8611 (vhdl-backward-sexp)
8612 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*\\(block\\|generate\\)\\>" nil t))
8613 beg)
8614 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8615 ;; scan for all declared signal names
8616 (goto-char beg)
8617 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8618 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8619 (if (match-string 2)
8620 ;; scan signal name
8621 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8622 (setq signal-list
8623 (cons (downcase (match-string 1)) signal-list))
8624 (goto-char (match-end 0)))
8625 ;; scan alias name, check is alias of (declared) signal
8626 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8627 (member (downcase (match-string 2)) signal-list))
8628 (setq signal-list
8629 (cons (downcase (match-string 1)) signal-list))
8630 (goto-char (match-end 0))))))
8631 (goto-char beg)))
8632 signal-list)))
8634 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8635 ;; Generic/port clause fixing
8637 (defun vhdl-fix-clause-buffer ()
8638 "Fix all generic/port clauses in current buffer."
8639 (interactive)
8640 (save-excursion
8641 (vhdl-prepare-search-2
8642 (goto-char (point-min))
8643 (message "Fixing generic/port clauses...")
8644 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8645 (goto-char (match-end 0))
8646 (condition-case nil (vhdl-fix-clause) (error "")))
8647 (message "Fixing generic/port clauses...done"))))
8649 (defun vhdl-fix-clause ()
8650 "Fix closing parenthesis within generic/port clause."
8651 (interactive)
8652 (save-excursion
8653 (vhdl-prepare-search-2
8654 (let ((pos (point))
8655 beg end)
8656 (end-of-line)
8657 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8658 (error "ERROR: Not within a generic/port clause")
8659 ;; search for end of clause
8660 (goto-char (match-end 0))
8661 (setq beg (1- (point)))
8662 (vhdl-forward-syntactic-ws)
8663 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8664 (goto-char (1- (match-end 0)))
8665 (setq end (point-marker))
8666 (forward-char)
8667 (vhdl-forward-syntactic-ws))
8668 (goto-char end)
8669 (when (> pos (point-at-eol))
8670 (error "ERROR: Not within a generic/port clause"))
8671 ;; delete closing parenthesis on separate line (not supported style)
8672 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8673 (vhdl-line-kill)
8674 (vhdl-backward-syntactic-ws)
8675 (setq end (point-marker))
8676 (insert ";"))
8677 ;; delete superfluous parentheses
8678 (while (progn (goto-char beg)
8679 (condition-case () (forward-sexp)
8680 (error (goto-char (point-max))))
8681 (< (point) end))
8682 (delete-char -1))
8683 ;; add closing parenthesis
8684 (when (> (point) end)
8685 (goto-char end)
8686 (insert ")")))))))
8689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8690 ;;; Electrification
8691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8693 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8694 "Syntax of prompt inserted by template generators.")
8696 (defvar vhdl-template-invoked-by-hook nil
8697 "Indicates whether a template has been invoked by a hook or by key or menu.
8698 Used for undoing after template abortion.")
8700 ;; correct different behavior of function `unread-command-events' in XEmacs
8701 (defun vhdl-character-to-event (arg))
8702 (defalias 'vhdl-character-to-event
8703 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8705 (defun vhdl-work-library ()
8706 "Return the working library name of the current project or \"work\" if no
8707 project is defined."
8708 (vhdl-resolve-env-variable
8709 (or (nth 6 (vhdl-aget vhdl-project-alist vhdl-project))
8710 vhdl-default-library)))
8712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8713 ;; Enabling/disabling
8715 (define-minor-mode vhdl-electric-mode
8716 "Toggle VHDL electric mode.
8717 With a prefix argument ARG, enable the mode if ARG is positive,
8718 and disable it otherwise. If called from Lisp, enable it if ARG
8719 is omitted or nil."
8720 :global t :group 'vhdl-mode)
8722 (define-minor-mode vhdl-stutter-mode
8723 "Toggle VHDL stuttering mode.
8724 With a prefix argument ARG, enable the mode if ARG is positive,
8725 and disable it otherwise. If called from Lisp, enable it if ARG
8726 is omitted or nil."
8727 :global t :group 'vhdl-mode)
8729 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8730 ;; Stuttering
8732 (defun vhdl-electric-dash (count)
8733 "-- starts a comment, --- draws a horizontal line,
8734 ---- starts a display comment."
8735 (interactive "p")
8736 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8737 (cond
8738 ((and abbrev-start-location (= abbrev-start-location (point)))
8739 (setq abbrev-start-location nil)
8740 (goto-char last-abbrev-location)
8741 (beginning-of-line nil)
8742 (vhdl-comment-display))
8743 ((/= (preceding-char) ?-) ; standard dash (minus)
8744 (self-insert-command count))
8745 (t (self-insert-command count)
8746 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8747 (let ((next-input (read-char)))
8748 (if (= next-input ?-) ; triple dash
8749 (progn
8750 (vhdl-comment-display-line)
8751 (message
8752 "Enter '-' for display comment, else continue coding")
8753 (let ((next-input (read-char)))
8754 (if (= next-input ?-) ; four dashes
8755 (vhdl-comment-display t)
8756 (setq unread-command-events ; pushback the char
8757 (list (vhdl-character-to-event next-input))))))
8758 (setq unread-command-events ; pushback the char
8759 (list (vhdl-character-to-event next-input)))
8760 (vhdl-comment-insert)))))
8761 (self-insert-command count)))
8763 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8764 (interactive "p")
8765 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8766 (if (= (preceding-char) ?\()
8767 (progn (delete-char -1) (insert-char ?\[ 1))
8768 (insert-char ?\( 1))
8769 (self-insert-command count)))
8771 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8772 (interactive "p")
8773 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8774 (progn
8775 (if (= (preceding-char) ?\))
8776 (progn (delete-char -1) (insert-char ?\] 1))
8777 (insert-char ?\) 1))
8778 (blink-matching-open))
8779 (self-insert-command count)))
8781 (defun vhdl-electric-quote (count) "'' --> \""
8782 (interactive "p")
8783 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8784 (if (= (preceding-char) vhdl-last-input-event)
8785 (progn (delete-char -1) (insert-char ?\" 1))
8786 (insert-char ?\' 1))
8787 (self-insert-command count)))
8789 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8790 (interactive "p")
8791 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8792 (cond ((= (preceding-char) vhdl-last-input-event)
8793 (progn (delete-char -1)
8794 (unless (eq (preceding-char) ? ) (insert " "))
8795 (insert ": ")
8796 (setq this-command 'vhdl-electric-colon)))
8797 ((and
8798 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8799 (progn (delete-char -1) (insert "= ")))
8800 (t (insert-char ?\; 1)))
8801 (self-insert-command count)))
8803 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8804 (interactive "p")
8805 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8806 (cond ((= (preceding-char) vhdl-last-input-event)
8807 (progn (delete-char -1)
8808 (unless (eq (preceding-char) ? ) (insert " "))
8809 (insert "<= ")))
8810 (t (insert-char ?\, 1)))
8811 (self-insert-command count)))
8813 (defun vhdl-electric-period (count) "'..' --> ' => '"
8814 (interactive "p")
8815 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8816 (cond ((= (preceding-char) vhdl-last-input-event)
8817 (progn (delete-char -1)
8818 (unless (eq (preceding-char) ? ) (insert " "))
8819 (insert "=> ")))
8820 (t (insert-char ?\. 1)))
8821 (self-insert-command count)))
8823 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8824 (interactive "p")
8825 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8826 (cond ((= (preceding-char) vhdl-last-input-event)
8827 (progn (delete-char -1)
8828 (unless (eq (preceding-char) ? ) (insert " "))
8829 (insert "== ")))
8830 (t (insert-char ?\= 1)))
8831 (self-insert-command count)))
8833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8834 ;; VHDL templates
8836 (defun vhdl-template-paired-parens ()
8837 "Insert a pair of round parentheses, placing point between them."
8838 (interactive)
8839 (insert "()")
8840 (backward-char))
8842 (defun vhdl-template-alias ()
8843 "Insert alias declaration."
8844 (interactive)
8845 (let ((start (point)))
8846 (vhdl-insert-keyword "ALIAS ")
8847 (when (vhdl-template-field "name" nil t start (point))
8848 (insert " : ")
8849 (unless (vhdl-template-field
8850 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8851 nil t)
8852 (delete-char -3))
8853 (vhdl-insert-keyword " IS ")
8854 (vhdl-template-field "name" ";")
8855 (vhdl-comment-insert-inline))))
8857 (defun vhdl-template-architecture ()
8858 "Insert architecture."
8859 (interactive)
8860 (let ((margin (current-indentation))
8861 (start (point))
8862 arch-name)
8863 (vhdl-insert-keyword "ARCHITECTURE ")
8864 (when (setq arch-name
8865 (vhdl-template-field "name" nil t start (point)))
8866 (vhdl-insert-keyword " OF ")
8867 (if (save-excursion
8868 (vhdl-prepare-search-1
8869 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8870 (insert (match-string 1))
8871 (vhdl-template-field "entity name"))
8872 (vhdl-insert-keyword " IS\n")
8873 (vhdl-template-begin-end
8874 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8875 (memq vhdl-insert-empty-lines '(unit all))))))
8877 (defun vhdl-template-array (kind &optional secondary)
8878 "Insert array type definition."
8879 (interactive)
8880 (let ((start (point)))
8881 (vhdl-insert-keyword "ARRAY (")
8882 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8883 secondary)
8884 (vhdl-insert-keyword ") OF ")
8885 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8886 (vhdl-insert-keyword ";"))))
8888 (defun vhdl-template-assert ()
8889 "Insert an assertion statement."
8890 (interactive)
8891 (let ((start (point)))
8892 (vhdl-insert-keyword "ASSERT ")
8893 (when vhdl-conditions-in-parenthesis (insert "("))
8894 (when (vhdl-template-field "condition (negated)" nil t start (point))
8895 (when vhdl-conditions-in-parenthesis (insert ")"))
8896 (setq start (point))
8897 (vhdl-insert-keyword " REPORT ")
8898 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8899 (delete-region start (point)))
8900 (setq start (point))
8901 (vhdl-insert-keyword " SEVERITY ")
8902 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8903 (delete-region start (point)))
8904 (insert ";"))))
8906 (defun vhdl-template-attribute ()
8907 "Insert an attribute declaration or specification."
8908 (interactive)
8909 (if (eq (vhdl-decision-query
8910 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8911 (vhdl-template-attribute-spec)
8912 (vhdl-template-attribute-decl)))
8914 (defun vhdl-template-attribute-decl ()
8915 "Insert an attribute declaration."
8916 (interactive)
8917 (let ((start (point)))
8918 (vhdl-insert-keyword "ATTRIBUTE ")
8919 (when (vhdl-template-field "name" " : " t start (point))
8920 (vhdl-template-field "type" ";")
8921 (vhdl-comment-insert-inline))))
8923 (defun vhdl-template-attribute-spec ()
8924 "Insert an attribute specification."
8925 (interactive)
8926 (let ((start (point)))
8927 (vhdl-insert-keyword "ATTRIBUTE ")
8928 (when (vhdl-template-field "name" nil t start (point))
8929 (vhdl-insert-keyword " OF ")
8930 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8931 (vhdl-template-field "entity class")
8932 (vhdl-insert-keyword " IS ")
8933 (vhdl-template-field "expression" ";"))))
8935 (defun vhdl-template-block ()
8936 "Insert a block."
8937 (interactive)
8938 (let ((margin (current-indentation))
8939 (start (point))
8940 label)
8941 (vhdl-insert-keyword ": BLOCK ")
8942 (goto-char start)
8943 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8944 (forward-word 1)
8945 (forward-char 1)
8946 (insert "(")
8947 (if (vhdl-template-field "[guard expression]" nil t)
8948 (insert ")")
8949 (delete-char -2))
8950 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8951 (insert "\n")
8952 (vhdl-template-begin-end "BLOCK" label margin)
8953 (vhdl-comment-block))))
8955 (defun vhdl-template-block-configuration ()
8956 "Insert a block configuration statement."
8957 (interactive)
8958 (let ((margin (current-indentation))
8959 (start (point)))
8960 (vhdl-insert-keyword "FOR ")
8961 (when (vhdl-template-field "block name" nil t start (point))
8962 (vhdl-insert-keyword "\n\n")
8963 (indent-to margin)
8964 (vhdl-insert-keyword "END FOR;")
8965 (end-of-line 0)
8966 (indent-to (+ margin vhdl-basic-offset)))))
8968 (defun vhdl-template-break ()
8969 "Insert a break statement."
8970 (interactive)
8971 (let (position)
8972 (vhdl-insert-keyword "BREAK")
8973 (setq position (point))
8974 (insert " ")
8975 (while (or
8976 (progn (vhdl-insert-keyword "FOR ")
8977 (if (vhdl-template-field "[quantity name]" " USE " t)
8978 (progn (vhdl-template-field "quantity name" " => ") t)
8979 (delete-region (point)
8980 (progn (forward-word -1) (point)))
8981 nil))
8982 (vhdl-template-field "[quantity name]" " => " t))
8983 (vhdl-template-field "expression")
8984 (setq position (point))
8985 (insert ", "))
8986 (delete-region position (point))
8987 (unless (vhdl-sequential-statement-p)
8988 (vhdl-insert-keyword " ON ")
8989 (if (vhdl-template-field "[sensitivity list]" nil t)
8990 (setq position (point))
8991 (delete-region position (point))))
8992 (vhdl-insert-keyword " WHEN ")
8993 (when vhdl-conditions-in-parenthesis (insert "("))
8994 (if (vhdl-template-field "[condition]" nil t)
8995 (when vhdl-conditions-in-parenthesis (insert ")"))
8996 (delete-region position (point)))
8997 (insert ";")))
8999 (defun vhdl-template-case (&optional kind)
9000 "Insert a case statement."
9001 (interactive)
9002 (let ((margin (current-indentation))
9003 (start (point))
9004 label)
9005 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
9006 (not (vhdl-standard-p 'ams))) 'is 'use)))
9007 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9008 (vhdl-insert-keyword "CASE ")
9009 (vhdl-insert-keyword ": CASE ")
9010 (goto-char start)
9011 (setq label (vhdl-template-field "[label]" nil t))
9012 (unless label (delete-char 2))
9013 (forward-word 1)
9014 (forward-char 1))
9015 (when (vhdl-template-field "expression" nil t start (point))
9016 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
9017 (indent-to margin)
9018 (vhdl-insert-keyword "END CASE")
9019 (when label (insert " " label))
9020 (insert ";")
9021 (forward-line -1)
9022 (indent-to (+ margin vhdl-basic-offset))
9023 (vhdl-insert-keyword "WHEN ")
9024 (let ((position (point)))
9025 (insert " => ;\n")
9026 (indent-to (+ margin vhdl-basic-offset))
9027 (vhdl-insert-keyword "WHEN OTHERS => null;")
9028 (goto-char position)))))
9030 (defun vhdl-template-case-is ()
9031 "Insert a sequential case statement."
9032 (interactive)
9033 (vhdl-template-case 'is))
9035 (defun vhdl-template-case-use ()
9036 "Insert a simultaneous case statement."
9037 (interactive)
9038 (vhdl-template-case 'use))
9040 (defun vhdl-template-component ()
9041 "Insert a component declaration."
9042 (interactive)
9043 (vhdl-template-component-decl))
9045 (defun vhdl-template-component-conf ()
9046 "Insert a component configuration (uses `vhdl-template-configuration-spec'
9047 since these are almost equivalent)."
9048 (interactive)
9049 (let ((margin (current-indentation))
9050 (result (vhdl-template-configuration-spec t)))
9051 (when result
9052 (insert "\n")
9053 (indent-to margin)
9054 (vhdl-insert-keyword "END FOR;")
9055 (when (eq result 'no-use)
9056 (end-of-line -0)))))
9058 (defun vhdl-template-component-decl ()
9059 "Insert a component declaration."
9060 (interactive)
9061 (let ((margin (current-indentation))
9062 (start (point))
9063 name end-column)
9064 (vhdl-insert-keyword "COMPONENT ")
9065 (when (setq name (vhdl-template-field "name" nil t start (point)))
9066 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9067 (insert "\n\n")
9068 (indent-to margin)
9069 (vhdl-insert-keyword "END COMPONENT")
9070 (unless (vhdl-standard-p '87) (insert " " name))
9071 (insert ";")
9072 (setq end-column (current-column))
9073 (end-of-line -0)
9074 (indent-to (+ margin vhdl-basic-offset))
9075 (vhdl-template-generic-list t t)
9076 (insert "\n")
9077 (indent-to (+ margin vhdl-basic-offset))
9078 (vhdl-template-port-list t)
9079 (beginning-of-line 2)
9080 (forward-char end-column))))
9082 (defun vhdl-template-component-inst ()
9083 "Insert a component instantiation statement."
9084 (interactive)
9085 (let ((margin (current-indentation))
9086 (start (point))
9087 unit position)
9088 (when (vhdl-template-field "instance label" nil t start (point))
9089 (insert ": ")
9090 (if (not (vhdl-use-direct-instantiation))
9091 (vhdl-template-field "component name")
9092 ;; direct instantiation
9093 (setq unit (vhdl-template-field
9094 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
9095 (setq unit (upcase (or unit "")))
9096 (cond ((equal unit "ENTITY")
9097 (let ((begin (point)))
9098 (vhdl-template-field "library name" "." t begin (point) nil
9099 (vhdl-work-library))
9100 (vhdl-template-field "entity name" "(")
9101 (if (vhdl-template-field "[architecture name]" nil t)
9102 (insert ")")
9103 (delete-char -1))))
9104 ((equal unit "CONFIGURATION")
9105 (vhdl-template-field "library name" "." nil nil nil nil
9106 (vhdl-work-library))
9107 (vhdl-template-field "configuration name"))
9108 (t (vhdl-template-field "component name"))))
9109 (insert "\n")
9110 (indent-to (+ margin vhdl-basic-offset))
9111 (setq position (point))
9112 (vhdl-insert-keyword "GENERIC ")
9113 (when (vhdl-template-map position t t)
9114 (insert "\n")
9115 (indent-to (+ margin vhdl-basic-offset)))
9116 (setq position (point))
9117 (vhdl-insert-keyword "PORT ")
9118 (unless (vhdl-template-map position t t)
9119 (delete-region (line-beginning-position) (point))
9120 (delete-char -1))
9121 (insert ";"))))
9123 (defun vhdl-template-conditional-signal-asst ()
9124 "Insert a conditional signal assignment."
9125 (interactive)
9126 (when (vhdl-template-field "target signal")
9127 (insert " <= ")
9128 (let ((margin (current-column))
9129 (start (point))
9130 position)
9131 (vhdl-template-field "waveform")
9132 (setq position (point))
9133 (vhdl-insert-keyword " WHEN ")
9134 (when vhdl-conditions-in-parenthesis (insert "("))
9135 (while (and (vhdl-template-field "[condition]" nil t)
9136 (progn
9137 (when vhdl-conditions-in-parenthesis (insert ")"))
9138 (setq position (point))
9139 (vhdl-insert-keyword " ELSE")
9140 (insert "\n")
9141 (indent-to margin)
9142 (vhdl-template-field "[waveform]" nil t)))
9143 (setq position (point))
9144 (vhdl-insert-keyword " WHEN ")
9145 (when vhdl-conditions-in-parenthesis (insert "(")))
9146 (delete-region position (point))
9147 (insert ";")
9148 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9150 (defun vhdl-template-configuration ()
9151 "Insert a configuration specification if within an architecture,
9152 a block or component configuration if within a configuration declaration,
9153 a configuration declaration if not within a design unit."
9154 (interactive)
9155 (vhdl-prepare-search-1
9156 (cond
9157 ((and (save-excursion ; architecture body
9158 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
9159 (equal "ARCHITECTURE" (upcase (match-string 1))))
9160 (vhdl-template-configuration-spec))
9161 ((and (save-excursion ; configuration declaration
9162 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9163 (equal "CONFIGURATION" (upcase (match-string 1))))
9164 (if (eq (vhdl-decision-query
9165 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
9166 (vhdl-template-component-conf)
9167 (vhdl-template-block-configuration)))
9168 (t (vhdl-template-configuration-decl))))) ; otherwise
9170 (defun vhdl-template-configuration-spec (&optional optional-use)
9171 "Insert a configuration specification."
9172 (interactive)
9173 (let ((margin (current-indentation))
9174 (start (point))
9175 aspect position)
9176 (vhdl-insert-keyword "FOR ")
9177 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9178 t start (point))
9179 (vhdl-template-field "component name" "\n")
9180 (indent-to (+ margin vhdl-basic-offset))
9181 (setq start (point))
9182 (vhdl-insert-keyword "USE ")
9183 (if (and optional-use
9184 (not (setq aspect (vhdl-template-field
9185 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
9186 (progn (delete-region start (point)) 'no-use)
9187 (unless optional-use
9188 (setq aspect (vhdl-template-field
9189 "ENTITY | CONFIGURATION | OPEN" " ")))
9190 (setq aspect (upcase (or aspect "")))
9191 (cond ((equal aspect "ENTITY")
9192 (vhdl-template-field "library name" "." nil nil nil nil
9193 (vhdl-work-library))
9194 (vhdl-template-field "entity name" "(")
9195 (if (vhdl-template-field "[architecture name]" nil t)
9196 (insert ")")
9197 (delete-char -1))
9198 (insert "\n")
9199 (indent-to (+ margin (* 2 vhdl-basic-offset)))
9200 (setq position (point))
9201 (vhdl-insert-keyword "GENERIC ")
9202 (when (vhdl-template-map position t t)
9203 (insert "\n")
9204 (indent-to (+ margin (* 2 vhdl-basic-offset))))
9205 (setq position (point))
9206 (vhdl-insert-keyword "PORT ")
9207 (unless (vhdl-template-map position t t)
9208 (delete-region (line-beginning-position) (point))
9209 (delete-char -1))
9210 (insert ";")
9212 ((equal aspect "CONFIGURATION")
9213 (vhdl-template-field "library name" "." nil nil nil nil
9214 (vhdl-work-library))
9215 (vhdl-template-field "configuration name" ";"))
9216 (t (delete-char -1) (insert ";") t))))))
9219 (defun vhdl-template-configuration-decl ()
9220 "Insert a configuration declaration."
9221 (interactive)
9222 (let ((margin (current-indentation))
9223 (start (point))
9224 entity-exists string name position)
9225 (vhdl-insert-keyword "CONFIGURATION ")
9226 (when (setq name (vhdl-template-field "name" nil t start (point)))
9227 (vhdl-insert-keyword " OF ")
9228 (save-excursion
9229 (vhdl-prepare-search-1
9230 (setq entity-exists (vhdl-re-search-backward
9231 "\\<entity \\(\\w*\\) is\\>" nil t))
9232 (setq string (match-string 1))))
9233 (if (and entity-exists (not (equal string "")))
9234 (insert string)
9235 (vhdl-template-field "entity name"))
9236 (vhdl-insert-keyword " IS\n")
9237 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9238 (indent-to (+ margin vhdl-basic-offset))
9239 (setq position (point))
9240 (insert "\n")
9241 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9242 (indent-to margin)
9243 (vhdl-insert-keyword "END ")
9244 (unless (vhdl-standard-p '87)
9245 (vhdl-insert-keyword "CONFIGURATION "))
9246 (insert name ";")
9247 (goto-char position))))
9249 (defun vhdl-template-constant ()
9250 "Insert a constant declaration."
9251 (interactive)
9252 (let ((start (point))
9253 (in-arglist (vhdl-in-argument-list-p)))
9254 (vhdl-insert-keyword "CONSTANT ")
9255 (when (vhdl-template-field "name" nil t start (point))
9256 (insert " : ")
9257 (when in-arglist (vhdl-insert-keyword "IN "))
9258 (vhdl-template-field "type")
9259 (if in-arglist
9260 (progn (insert ";")
9261 (vhdl-comment-insert-inline))
9262 (let ((position (point)))
9263 (insert " := ")
9264 (unless (vhdl-template-field "[initialization]" nil t)
9265 (delete-region position (point)))
9266 (insert ";")
9267 (vhdl-comment-insert-inline))))))
9269 (defun vhdl-template-context ()
9270 "Insert a context declaration."
9271 (interactive)
9272 (let ((margin (current-indentation))
9273 (start (point))
9274 entity-exists string name position)
9275 (vhdl-insert-keyword "CONTEXT ")
9276 (when (setq name (vhdl-template-field "name" nil t start (point)))
9277 (vhdl-insert-keyword " IS\n")
9278 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9279 (indent-to (+ margin vhdl-basic-offset))
9280 (setq position (point))
9281 (insert "\n")
9282 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9283 (indent-to margin)
9284 (vhdl-insert-keyword "END ")
9285 (unless (vhdl-standard-p '87)
9286 (vhdl-insert-keyword "CONTEXT "))
9287 (insert name ";")
9288 (goto-char position))))
9290 (defun vhdl-template-default ()
9291 "Insert nothing."
9292 (interactive)
9293 (insert " ")
9294 (unexpand-abbrev)
9295 (backward-word 1)
9296 (vhdl-case-word 1)
9297 (forward-char 1))
9299 (defun vhdl-template-default-indent ()
9300 "Insert nothing and indent."
9301 (interactive)
9302 (insert " ")
9303 (unexpand-abbrev)
9304 (backward-word 1)
9305 (vhdl-case-word 1)
9306 (forward-char 1)
9307 (indent-according-to-mode))
9309 (defun vhdl-template-disconnect ()
9310 "Insert a disconnect statement."
9311 (interactive)
9312 (let ((start (point)))
9313 (vhdl-insert-keyword "DISCONNECT ")
9314 (when (vhdl-template-field "signal names | OTHERS | ALL"
9315 " : " t start (point))
9316 (vhdl-template-field "type")
9317 (vhdl-insert-keyword " AFTER ")
9318 (vhdl-template-field "time expression" ";"))))
9320 (defun vhdl-template-else ()
9321 "Insert an else statement."
9322 (interactive)
9323 (let (margin)
9324 (vhdl-prepare-search-1
9325 (vhdl-insert-keyword "ELSE")
9326 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
9327 (equal "WHEN" (upcase (match-string 1))))
9328 (insert " ")
9329 (indent-according-to-mode)
9330 (setq margin (current-indentation))
9331 (insert "\n")
9332 (indent-to (+ margin vhdl-basic-offset))))))
9334 (defun vhdl-template-elsif ()
9335 "Insert an elsif statement."
9336 (interactive)
9337 (let ((start (point))
9338 margin)
9339 (vhdl-insert-keyword "ELSIF ")
9340 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
9341 (when vhdl-conditions-in-parenthesis (insert "("))
9342 (when (vhdl-template-field "condition" nil t start (point))
9343 (when vhdl-conditions-in-parenthesis (insert ")"))
9344 (indent-according-to-mode)
9345 (setq margin (current-indentation))
9346 (vhdl-insert-keyword
9347 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
9348 (indent-to (+ margin vhdl-basic-offset))))))
9350 (defun vhdl-template-entity ()
9351 "Insert an entity."
9352 (interactive)
9353 (let ((margin (current-indentation))
9354 (start (point))
9355 name end-column)
9356 (vhdl-insert-keyword "ENTITY ")
9357 (when (setq name (vhdl-template-field "name" nil t start (point)))
9358 (vhdl-insert-keyword " IS\n\n")
9359 (indent-to margin)
9360 (vhdl-insert-keyword "END ")
9361 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9362 (insert name ";")
9363 (setq end-column (current-column))
9364 (end-of-line -0)
9365 (indent-to (+ margin vhdl-basic-offset))
9366 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9367 (indent-to (+ margin vhdl-basic-offset))
9368 (when (vhdl-template-generic-list t)
9369 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9370 (insert "\n")
9371 (indent-to (+ margin vhdl-basic-offset))
9372 (when (vhdl-template-port-list t)
9373 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
9374 (beginning-of-line 2)
9375 (forward-char end-column))))
9377 (defun vhdl-template-exit ()
9378 "Insert an exit statement."
9379 (interactive)
9380 (let ((start (point)))
9381 (vhdl-insert-keyword "EXIT ")
9382 (if (vhdl-template-field "[loop label]" nil t start (point))
9383 (let ((position (point)))
9384 (vhdl-insert-keyword " WHEN ")
9385 (when vhdl-conditions-in-parenthesis (insert "("))
9386 (if (vhdl-template-field "[condition]" nil t)
9387 (when vhdl-conditions-in-parenthesis (insert ")"))
9388 (delete-region position (point))))
9389 (delete-char -1))
9390 (insert ";")))
9392 (defun vhdl-template-file ()
9393 "Insert a file declaration."
9394 (interactive)
9395 (let ((start (point)))
9396 (vhdl-insert-keyword "FILE ")
9397 (when (vhdl-template-field "name" nil t start (point))
9398 (insert " : ")
9399 (vhdl-template-field "type")
9400 (unless (vhdl-standard-p '87)
9401 (vhdl-insert-keyword " OPEN ")
9402 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9403 nil t)
9404 (delete-char -6)))
9405 (vhdl-insert-keyword " IS ")
9406 (when (vhdl-standard-p '87)
9407 (vhdl-template-field "[IN | OUT]" " " t))
9408 (vhdl-template-field "filename-string" nil nil nil nil t)
9409 (insert ";")
9410 (vhdl-comment-insert-inline))))
9412 (defun vhdl-template-for ()
9413 "Insert a block or component configuration if within a configuration
9414 declaration, a configuration specification if within an architecture
9415 declarative part (and not within a subprogram), a for-loop if within a
9416 sequential statement part (subprogram or process), and a for-generate
9417 otherwise."
9418 (interactive)
9419 (vhdl-prepare-search-1
9420 (cond
9421 ((vhdl-sequential-statement-p) ; sequential statement
9422 (vhdl-template-for-loop))
9423 ((and (save-excursion ; configuration declaration
9424 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9425 (equal "CONFIGURATION" (upcase (match-string 1))))
9426 (if (eq (vhdl-decision-query
9427 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9428 (vhdl-template-component-conf)
9429 (vhdl-template-block-configuration)))
9430 ((and (save-excursion
9431 (re-search-backward ; architecture declarative part
9432 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9433 (equal "ARCHITECTURE" (upcase (match-string 1))))
9434 (vhdl-template-configuration-spec))
9435 (t (vhdl-template-for-generate))))) ; concurrent statement
9437 (defun vhdl-template-for-generate ()
9438 "Insert a for-generate."
9439 (interactive)
9440 (let ((margin (current-indentation))
9441 (start (point))
9442 label position)
9443 (vhdl-insert-keyword ": FOR ")
9444 (setq position (point-marker))
9445 (goto-char start)
9446 (when (setq label (vhdl-template-field "label" nil t start position))
9447 (goto-char position)
9448 (vhdl-template-field "loop variable")
9449 (vhdl-insert-keyword " IN ")
9450 (vhdl-template-field "range")
9451 (vhdl-template-generate-body margin label))))
9453 (defun vhdl-template-for-loop ()
9454 "Insert a for loop."
9455 (interactive)
9456 (let ((margin (current-indentation))
9457 (start (point))
9458 label index)
9459 (if (not (eq vhdl-optional-labels 'all))
9460 (vhdl-insert-keyword "FOR ")
9461 (vhdl-insert-keyword ": FOR ")
9462 (goto-char start)
9463 (setq label (vhdl-template-field "[label]" nil t))
9464 (unless label (delete-char 2))
9465 (forward-word 1)
9466 (forward-char 1))
9467 (when (setq index (vhdl-template-field "loop variable"
9468 nil t start (point)))
9469 (vhdl-insert-keyword " IN ")
9470 (vhdl-template-field "range")
9471 (vhdl-insert-keyword " LOOP\n\n")
9472 (indent-to margin)
9473 (vhdl-insert-keyword "END LOOP")
9474 (if label
9475 (insert " " label ";")
9476 (insert ";")
9477 (when vhdl-self-insert-comments (insert " -- " index)))
9478 (forward-line -1)
9479 (indent-to (+ margin vhdl-basic-offset)))))
9481 (defun vhdl-template-function (&optional kind)
9482 "Insert a function declaration or body."
9483 (interactive)
9484 (let ((margin (current-indentation))
9485 (start (point))
9486 name)
9487 (vhdl-insert-keyword "FUNCTION ")
9488 (when (setq name (vhdl-template-field "name" nil t start (point)))
9489 (vhdl-template-argument-list t)
9490 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9491 (end-of-line)
9492 (insert "\n")
9493 (indent-to (+ margin vhdl-basic-offset))
9494 (vhdl-insert-keyword "RETURN ")
9495 (vhdl-template-field "type")
9496 (if (if kind (eq kind 'body)
9497 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9498 (progn (vhdl-insert-keyword " IS\n")
9499 (vhdl-template-begin-end
9500 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9501 (vhdl-comment-block))
9502 (insert ";")))))
9504 (defun vhdl-template-function-decl ()
9505 "Insert a function declaration."
9506 (interactive)
9507 (vhdl-template-function 'decl))
9509 (defun vhdl-template-function-body ()
9510 "Insert a function declaration."
9511 (interactive)
9512 (vhdl-template-function 'body))
9514 (defun vhdl-template-generate ()
9515 "Insert a generation scheme."
9516 (interactive)
9517 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9518 (vhdl-template-if-generate)
9519 (vhdl-template-for-generate)))
9521 (defun vhdl-template-generic ()
9522 "Insert generic declaration, or generic map in instantiation statements."
9523 (interactive)
9524 (let ((start (point)))
9525 (vhdl-prepare-search-1
9526 (cond
9527 ((and (save-excursion ; entity declaration
9528 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9529 (equal "ENTITY" (upcase (match-string 1))))
9530 (vhdl-template-generic-list nil))
9531 ((or (save-excursion
9532 (or (beginning-of-line)
9533 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9534 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9535 (vhdl-insert-keyword "GENERIC ")
9536 (vhdl-template-map start))
9537 (t (vhdl-template-generic-list nil t))))))
9539 (defun vhdl-template-group ()
9540 "Insert group or group template declaration."
9541 (interactive)
9542 (let ((start (point)))
9543 (if (eq (vhdl-decision-query
9544 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9545 (vhdl-template-group-template)
9546 (vhdl-template-group-decl))))
9548 (defun vhdl-template-group-decl ()
9549 "Insert group declaration."
9550 (interactive)
9551 (let ((start (point)))
9552 (vhdl-insert-keyword "GROUP ")
9553 (when (vhdl-template-field "name" " : " t start (point))
9554 (vhdl-template-field "template name" " (")
9555 (vhdl-template-field "constituent list" ");")
9556 (vhdl-comment-insert-inline))))
9558 (defun vhdl-template-group-template ()
9559 "Insert group template declaration."
9560 (interactive)
9561 (let ((start (point)))
9562 (vhdl-insert-keyword "GROUP ")
9563 (when (vhdl-template-field "template name" nil t start (point))
9564 (vhdl-insert-keyword " IS (")
9565 (vhdl-template-field "entity class list" ");")
9566 (vhdl-comment-insert-inline))))
9568 (defun vhdl-template-if ()
9569 "Insert a sequential if statement or an if-generate statement."
9570 (interactive)
9571 (if (vhdl-sequential-statement-p)
9572 (vhdl-template-if-then)
9573 (if (and (vhdl-standard-p 'ams)
9574 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9575 (vhdl-template-if-use)
9576 (vhdl-template-if-generate))))
9578 (defun vhdl-template-if-generate ()
9579 "Insert an if-generate."
9580 (interactive)
9581 (let ((margin (current-indentation))
9582 (start (point))
9583 label position)
9584 (vhdl-insert-keyword ": IF ")
9585 (setq position (point-marker))
9586 (goto-char start)
9587 (when (setq label (vhdl-template-field "label" nil t start position))
9588 (goto-char position)
9589 (when vhdl-conditions-in-parenthesis (insert "("))
9590 (vhdl-template-field "condition")
9591 (when vhdl-conditions-in-parenthesis (insert ")"))
9592 (vhdl-template-generate-body margin label))))
9594 (defun vhdl-template-if-then-use (kind)
9595 "Insert a sequential if statement."
9596 (interactive)
9597 (let ((margin (current-indentation))
9598 (start (point))
9599 label)
9600 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9601 (vhdl-insert-keyword "IF ")
9602 (vhdl-insert-keyword ": IF ")
9603 (goto-char start)
9604 (setq label (vhdl-template-field "[label]" nil t))
9605 (unless label (delete-char 2))
9606 (forward-word 1)
9607 (forward-char 1))
9608 (when vhdl-conditions-in-parenthesis (insert "("))
9609 (when (vhdl-template-field "condition" nil t start (point))
9610 (when vhdl-conditions-in-parenthesis (insert ")"))
9611 (vhdl-insert-keyword
9612 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9613 (indent-to margin)
9614 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9615 (when label (insert " " label))
9616 (insert ";")
9617 (forward-line -1)
9618 (indent-to (+ margin vhdl-basic-offset)))))
9620 (defun vhdl-template-if-then ()
9621 "Insert a sequential if statement."
9622 (interactive)
9623 (vhdl-template-if-then-use 'then))
9625 (defun vhdl-template-if-use ()
9626 "Insert a simultaneous if statement."
9627 (interactive)
9628 (vhdl-template-if-then-use 'use))
9630 (defun vhdl-template-instance ()
9631 "Insert a component instantiation statement."
9632 (interactive)
9633 (vhdl-template-component-inst))
9635 (defun vhdl-template-library ()
9636 "Insert a library specification."
9637 (interactive)
9638 (let ((margin (current-indentation))
9639 (start (point))
9640 name end-pos)
9641 (vhdl-insert-keyword "LIBRARY ")
9642 (when (setq name (vhdl-template-field "names" nil t start (point)))
9643 (insert ";")
9644 (unless (string-match "," name)
9645 (setq end-pos (point))
9646 (insert "\n")
9647 (indent-to margin)
9648 (vhdl-insert-keyword "USE ")
9649 (insert name)
9650 (vhdl-insert-keyword "..ALL;")
9651 (backward-char 5)
9652 (if (vhdl-template-field "package name")
9653 (forward-char 5)
9654 (delete-region end-pos (+ (point) 5)))))))
9656 (defun vhdl-template-limit ()
9657 "Insert a limit."
9658 (interactive)
9659 (let ((start (point)))
9660 (vhdl-insert-keyword "LIMIT ")
9661 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9662 t start (point))
9663 (vhdl-template-field "type")
9664 (vhdl-insert-keyword " WITH ")
9665 (vhdl-template-field "real expression" ";"))))
9667 (defun vhdl-template-loop ()
9668 "Insert a loop."
9669 (interactive)
9670 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9671 (cond ((eq char ?w)
9672 (vhdl-template-while-loop))
9673 ((eq char ?f)
9674 (vhdl-template-for-loop))
9675 (t (vhdl-template-bare-loop)))))
9677 (defun vhdl-template-bare-loop ()
9678 "Insert a loop."
9679 (interactive)
9680 (let ((margin (current-indentation))
9681 (start (point))
9682 label)
9683 (if (not (eq vhdl-optional-labels 'all))
9684 (vhdl-insert-keyword "LOOP ")
9685 (vhdl-insert-keyword ": LOOP ")
9686 (goto-char start)
9687 (setq label (vhdl-template-field "[label]" nil t))
9688 (unless label (delete-char 2))
9689 (forward-word 1)
9690 (delete-char 1))
9691 (insert "\n\n")
9692 (indent-to margin)
9693 (vhdl-insert-keyword "END LOOP")
9694 (insert (if label (concat " " label ";") ";"))
9695 (forward-line -1)
9696 (indent-to (+ margin vhdl-basic-offset))))
9698 (defun vhdl-template-map (&optional start optional secondary)
9699 "Insert a map specification with association list."
9700 (interactive)
9701 (let ((start (or start (point)))
9702 margin end-pos)
9703 (vhdl-insert-keyword "MAP (")
9704 (if (not vhdl-association-list-with-formals)
9705 (if (vhdl-template-field
9706 (concat (and optional "[") "association list" (and optional "]"))
9707 ")" (or (not secondary) optional)
9708 (and (not secondary) start) (point))
9710 (if (and optional secondary) (delete-region start (point)))
9711 nil)
9712 (if vhdl-argument-list-indent
9713 (setq margin (current-column))
9714 (setq margin (+ (current-indentation) vhdl-basic-offset))
9715 (insert "\n")
9716 (indent-to margin))
9717 (if (vhdl-template-field
9718 (concat (and optional "[") "formal" (and optional "]"))
9719 " => " (or (not secondary) optional)
9720 (and (not secondary) start) (point))
9721 (progn
9722 (vhdl-template-field "actual" ",")
9723 (setq end-pos (point))
9724 (insert "\n")
9725 (indent-to margin)
9726 (while (vhdl-template-field "[formal]" " => " t)
9727 (vhdl-template-field "actual" ",")
9728 (setq end-pos (point))
9729 (insert "\n")
9730 (indent-to margin))
9731 (delete-region end-pos (point))
9732 (delete-char -1)
9733 (insert ")")
9734 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9736 (when (and optional secondary) (delete-region start (point)))
9737 nil))))
9739 (defun vhdl-template-modify (&optional noerror)
9740 "Actualize modification date."
9741 (interactive)
9742 (vhdl-prepare-search-2
9743 (save-excursion
9744 (goto-char (point-min))
9745 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9746 (progn (delete-region (point) (progn (end-of-line) (point)))
9747 (vhdl-template-insert-date))
9748 (unless noerror
9749 (error "ERROR: Modification date prefix string \"%s\" not found"
9750 vhdl-modify-date-prefix-string))))))
9753 (defun vhdl-template-modify-noerror ()
9754 "Call `vhdl-template-modify' with NOERROR non-nil."
9755 (vhdl-template-modify t))
9757 (defun vhdl-template-nature ()
9758 "Insert a nature declaration."
9759 (interactive)
9760 (let ((start (point))
9761 name mid-pos end-pos)
9762 (vhdl-insert-keyword "NATURE ")
9763 (when (setq name (vhdl-template-field "name" nil t start (point)))
9764 (vhdl-insert-keyword " IS ")
9765 (let ((definition
9766 (upcase
9767 (or (vhdl-template-field
9768 "across type | ARRAY | RECORD")
9769 ""))))
9770 (cond ((equal definition "")
9771 (insert ";"))
9772 ((equal definition "ARRAY")
9773 (delete-region (point) (progn (forward-word -1) (point)))
9774 (vhdl-template-array 'nature t))
9775 ((equal definition "RECORD")
9776 (setq mid-pos (point-marker))
9777 (delete-region (point) (progn (forward-word -1) (point)))
9778 (vhdl-template-record 'nature name t))
9780 (vhdl-insert-keyword " ACROSS ")
9781 (vhdl-template-field "through type")
9782 (vhdl-insert-keyword " THROUGH ")
9783 (vhdl-template-field "reference name")
9784 (vhdl-insert-keyword " REFERENCE;")))
9785 (when mid-pos
9786 (setq end-pos (point-marker))
9787 (goto-char mid-pos)
9788 (end-of-line))
9789 (vhdl-comment-insert-inline)
9790 (when end-pos (goto-char end-pos))))))
9792 (defun vhdl-template-next ()
9793 "Insert a next statement."
9794 (interactive)
9795 (let ((start (point)))
9796 (vhdl-insert-keyword "NEXT ")
9797 (if (vhdl-template-field "[loop label]" nil t start (point))
9798 (let ((position (point)))
9799 (vhdl-insert-keyword " WHEN ")
9800 (when vhdl-conditions-in-parenthesis (insert "("))
9801 (if (vhdl-template-field "[condition]" nil t)
9802 (when vhdl-conditions-in-parenthesis (insert ")"))
9803 (delete-region position (point))))
9804 (delete-char -1))
9805 (insert ";")))
9807 (defun vhdl-template-others ()
9808 "Insert an others aggregate."
9809 (interactive)
9810 (let ((start (point)))
9811 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9812 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9813 (vhdl-insert-keyword "OTHERS => '")
9814 (when (vhdl-template-field "value" nil t start (point))
9815 (insert "')")))
9816 (vhdl-insert-keyword "OTHERS "))))
9818 (defun vhdl-template-package (&optional kind)
9819 "Insert a package specification or body."
9820 (interactive)
9821 (let ((margin (current-indentation))
9822 (start (point))
9823 name body position)
9824 (vhdl-insert-keyword "PACKAGE ")
9825 (setq body (if kind (eq kind 'body)
9826 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9827 (when body
9828 (vhdl-insert-keyword "BODY ")
9829 (when (save-excursion
9830 (vhdl-prepare-search-1
9831 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9832 (insert (setq name (match-string 1)))))
9833 (when (or name
9834 (setq name (vhdl-template-field "name" nil t start (point))))
9835 (vhdl-insert-keyword " IS\n")
9836 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9837 (indent-to (+ margin vhdl-basic-offset))
9838 (setq position (point))
9839 (insert "\n")
9840 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9841 (indent-to margin)
9842 (vhdl-insert-keyword "END ")
9843 (unless (vhdl-standard-p '87)
9844 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9845 (insert (or name "") ";")
9846 (goto-char position))))
9848 (defun vhdl-template-package-decl ()
9849 "Insert a package specification."
9850 (interactive)
9851 (vhdl-template-package 'decl))
9853 (defun vhdl-template-package-body ()
9854 "Insert a package body."
9855 (interactive)
9856 (vhdl-template-package 'body))
9858 (defun vhdl-template-port ()
9859 "Insert a port declaration, or port map in instantiation statements."
9860 (interactive)
9861 (let ((start (point)))
9862 (vhdl-prepare-search-1
9863 (cond
9864 ((and (save-excursion ; entity declaration
9865 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9866 (equal "ENTITY" (upcase (match-string 1))))
9867 (vhdl-template-port-list nil))
9868 ((or (save-excursion
9869 (or (beginning-of-line)
9870 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9871 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9872 (vhdl-insert-keyword "PORT ")
9873 (vhdl-template-map start))
9874 (t (vhdl-template-port-list nil))))))
9876 (defun vhdl-template-procedural ()
9877 "Insert a procedural."
9878 (interactive)
9879 (let ((margin (current-indentation))
9880 (start (point))
9881 (case-fold-search t)
9882 label)
9883 (vhdl-insert-keyword "PROCEDURAL ")
9884 (when (memq vhdl-optional-labels '(process all))
9885 (goto-char start)
9886 (insert ": ")
9887 (goto-char start)
9888 (setq label (vhdl-template-field "[label]" nil t))
9889 (unless label (delete-char 2))
9890 (forward-word 1)
9891 (forward-char 1))
9892 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9893 (insert "\n")
9894 (vhdl-template-begin-end "PROCEDURAL" label margin)
9895 (vhdl-comment-block)))
9897 (defun vhdl-template-procedure (&optional kind)
9898 "Insert a procedure declaration or body."
9899 (interactive)
9900 (let ((margin (current-indentation))
9901 (start (point))
9902 name)
9903 (vhdl-insert-keyword "PROCEDURE ")
9904 (when (setq name (vhdl-template-field "name" nil t start (point)))
9905 (vhdl-template-argument-list)
9906 (if (if kind (eq kind 'body)
9907 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9908 (progn (vhdl-insert-keyword " IS")
9909 (when vhdl-auto-align
9910 (vhdl-align-region-groups start (point) 1))
9911 (end-of-line) (insert "\n")
9912 (vhdl-template-begin-end
9913 (unless (vhdl-standard-p '87) "PROCEDURE")
9914 name margin)
9915 (vhdl-comment-block))
9916 (insert ";")
9917 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9918 (end-of-line)))))
9920 (defun vhdl-template-procedure-decl ()
9921 "Insert a procedure declaration."
9922 (interactive)
9923 (vhdl-template-procedure 'decl))
9925 (defun vhdl-template-procedure-body ()
9926 "Insert a procedure body."
9927 (interactive)
9928 (vhdl-template-procedure 'body))
9930 (defun vhdl-template-process (&optional kind)
9931 "Insert a process."
9932 (interactive)
9933 (let ((margin (current-indentation))
9934 (start (point))
9935 (reset-kind vhdl-reset-kind)
9936 label seq input-signals clock reset final-pos)
9937 (setq seq (if kind (eq kind 'seq)
9938 (eq (vhdl-decision-query
9939 "process" "(c)ombinational or (s)equential?" t) ?s)))
9940 (vhdl-insert-keyword "PROCESS ")
9941 (when (memq vhdl-optional-labels '(process all))
9942 (goto-char start)
9943 (insert ": ")
9944 (goto-char start)
9945 (setq label (vhdl-template-field "[label]" nil t))
9946 (unless label (delete-char 2))
9947 (forward-word 1)
9948 (forward-char 1))
9949 (insert "(")
9950 (if (not seq)
9951 (unless (or (and (vhdl-standard-p '08) vhdl-sensitivity-list-all
9952 (progn (insert "all)") (setq input-signals "all")))
9953 (setq input-signals
9954 (vhdl-template-field "[sensitivity list]" ")" t)))
9955 (setq input-signals "")
9956 (delete-char -2))
9957 (setq clock (or (and (not (equal "" vhdl-clock-name))
9958 (progn (insert vhdl-clock-name) vhdl-clock-name))
9959 (vhdl-template-field "clock name") "<clock>"))
9960 (when (eq reset-kind 'query)
9961 (setq reset-kind
9962 (if (eq (vhdl-decision-query
9963 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9964 'async
9965 'sync)))
9966 (when (eq reset-kind 'async)
9967 (insert ", ")
9968 (setq reset (or (and (not (equal "" vhdl-reset-name))
9969 (progn (insert vhdl-reset-name) vhdl-reset-name))
9970 (vhdl-template-field "reset name") "<reset>")))
9971 (insert ")"))
9972 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9973 (insert "\n")
9974 (vhdl-template-begin-end "PROCESS" label margin)
9975 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9976 (when vhdl-prompt-for-comments
9977 (setq final-pos (point-marker))
9978 (vhdl-prepare-search-2
9979 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9980 (vhdl-re-search-backward "\\<process\\>" nil t))
9981 (end-of-line -0)
9982 (if (bobp)
9983 (progn (insert "\n") (forward-line -1))
9984 (insert "\n"))
9985 (indent-to margin)
9986 (insert "-- purpose: ")
9987 (if (not (vhdl-template-field "[description]" nil t))
9988 (vhdl-line-kill-entire)
9989 (insert "\n")
9990 (indent-to margin)
9991 (insert "-- type : ")
9992 (insert (if seq "sequential" "combinational") "\n")
9993 (indent-to margin)
9994 (insert "-- inputs : ")
9995 (if (not seq)
9996 (insert input-signals)
9997 (insert clock ", ")
9998 (when reset (insert reset ", "))
9999 (unless (vhdl-template-field "[signal names]" nil t)
10000 (delete-char -2)))
10001 (insert "\n")
10002 (indent-to margin)
10003 (insert "-- outputs: ")
10004 (vhdl-template-field "[signal names]" nil t))))
10005 (goto-char final-pos))))
10007 (defun vhdl-template-process-comb ()
10008 "Insert a combinational process."
10009 (interactive)
10010 (vhdl-template-process 'comb))
10012 (defun vhdl-template-process-seq ()
10013 "Insert a sequential process."
10014 (interactive)
10015 (vhdl-template-process 'seq))
10017 (defun vhdl-template-quantity ()
10018 "Insert a quantity declaration."
10019 (interactive)
10020 (if (vhdl-in-argument-list-p)
10021 (let ((start (point)))
10022 (vhdl-insert-keyword "QUANTITY ")
10023 (when (vhdl-template-field "names" nil t start (point))
10024 (insert " : ")
10025 (vhdl-template-field "[IN | OUT]" " " t)
10026 (vhdl-template-field "type")
10027 (insert ";")
10028 (vhdl-comment-insert-inline)))
10029 (let ((char (vhdl-decision-query
10030 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
10031 (cond ((eq char ?f) (vhdl-template-quantity-free))
10032 ((eq char ?b) (vhdl-template-quantity-branch))
10033 ((eq char ?s) (vhdl-template-quantity-source))
10034 (t (vhdl-template-undo (point) (point)))))))
10036 (defun vhdl-template-quantity-free ()
10037 "Insert a free quantity declaration."
10038 (interactive)
10039 (vhdl-insert-keyword "QUANTITY ")
10040 (vhdl-template-field "names")
10041 (insert " : ")
10042 (vhdl-template-field "type")
10043 (let ((position (point)))
10044 (insert " := ")
10045 (unless (vhdl-template-field "[initialization]" nil t)
10046 (delete-region position (point)))
10047 (insert ";")
10048 (vhdl-comment-insert-inline)))
10050 (defun vhdl-template-quantity-branch ()
10051 "Insert a branch quantity declaration."
10052 (interactive)
10053 (let (position)
10054 (vhdl-insert-keyword "QUANTITY ")
10055 (when (vhdl-template-field "[across names]" " " t)
10056 (vhdl-insert-keyword "ACROSS "))
10057 (when (vhdl-template-field "[through names]" " " t)
10058 (vhdl-insert-keyword "THROUGH "))
10059 (vhdl-template-field "plus terminal name")
10060 (setq position (point))
10061 (vhdl-insert-keyword " TO ")
10062 (unless (vhdl-template-field "[minus terminal name]" nil t)
10063 (delete-region position (point)))
10064 (insert ";")
10065 (vhdl-comment-insert-inline)))
10067 (defun vhdl-template-quantity-source ()
10068 "Insert a source quantity declaration."
10069 (interactive)
10070 (vhdl-insert-keyword "QUANTITY ")
10071 (vhdl-template-field "names")
10072 (insert " : ")
10073 (vhdl-template-field "type" " ")
10074 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
10075 (progn (vhdl-insert-keyword "NOISE ")
10076 (vhdl-template-field "power expression"))
10077 (vhdl-insert-keyword "SPECTRUM ")
10078 (vhdl-template-field "magnitude expression" ", ")
10079 (vhdl-template-field "phase expression"))
10080 (insert ";")
10081 (vhdl-comment-insert-inline))
10083 (defun vhdl-template-record (kind &optional name secondary)
10084 "Insert a record type declaration."
10085 (interactive)
10086 (let ((margin (current-indentation))
10087 (start (point))
10088 (first t))
10089 (vhdl-insert-keyword "RECORD\n")
10090 (indent-to (+ margin vhdl-basic-offset))
10091 (when (or (vhdl-template-field "element names"
10092 nil (not secondary) start (point))
10093 secondary)
10094 (while (or first (vhdl-template-field "[element names]" nil t))
10095 (insert " : ")
10096 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
10097 (vhdl-comment-insert-inline)
10098 (insert "\n")
10099 (indent-to (+ margin vhdl-basic-offset))
10100 (setq first nil))
10101 (delete-region (line-beginning-position) (point))
10102 (indent-to margin)
10103 (vhdl-insert-keyword "END RECORD")
10104 (unless (vhdl-standard-p '87) (and name (insert " " name)))
10105 (insert ";")
10106 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10108 (defun vhdl-template-report ()
10109 "Insert a report statement."
10110 (interactive)
10111 (let ((start (point)))
10112 (vhdl-insert-keyword "REPORT ")
10113 (if (equal "\"\"" (vhdl-template-field
10114 "string expression" nil t start (point) t))
10115 (delete-char -2)
10116 (setq start (point))
10117 (vhdl-insert-keyword " SEVERITY ")
10118 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
10119 (delete-region start (point)))
10120 (insert ";"))))
10122 (defun vhdl-template-return ()
10123 "Insert a return statement."
10124 (interactive)
10125 (let ((start (point)))
10126 (vhdl-insert-keyword "RETURN ")
10127 (unless (vhdl-template-field "[expression]" nil t start (point))
10128 (delete-char -1))
10129 (insert ";")))
10131 (defun vhdl-template-selected-signal-asst ()
10132 "Insert a selected signal assignment."
10133 (interactive)
10134 (let ((margin (current-indentation))
10135 (start (point))
10136 (choices t))
10137 (let ((position (point)))
10138 (vhdl-insert-keyword " SELECT ")
10139 (goto-char position))
10140 (vhdl-insert-keyword "WITH ")
10141 (when (vhdl-template-field "selector expression"
10142 nil t start (+ (point) 7))
10143 (forward-word 1)
10144 (delete-char 1)
10145 (insert "\n")
10146 (indent-to (+ margin vhdl-basic-offset))
10147 (vhdl-template-field "target signal" " <= ")
10148 (insert "\n")
10149 (indent-to (+ margin vhdl-basic-offset))
10150 (vhdl-template-field "waveform")
10151 (vhdl-insert-keyword " WHEN ")
10152 (vhdl-template-field "choices" ",")
10153 (insert "\n")
10154 (indent-to (+ margin vhdl-basic-offset))
10155 (while (and choices (vhdl-template-field "[waveform]" nil t))
10156 (vhdl-insert-keyword " WHEN ")
10157 (if (setq choices (vhdl-template-field "[choices]" "," t))
10158 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10159 (vhdl-insert-keyword "OTHERS")))
10160 (when choices
10161 (fixup-whitespace)
10162 (delete-char -2))
10163 (insert ";")
10164 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
10166 (defun vhdl-template-signal ()
10167 "Insert a signal declaration."
10168 (interactive)
10169 (let ((start (point))
10170 (in-arglist (vhdl-in-argument-list-p)))
10171 (vhdl-insert-keyword "SIGNAL ")
10172 (when (vhdl-template-field "names" nil t start (point))
10173 (insert " : ")
10174 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10175 (vhdl-template-field "type")
10176 (if in-arglist
10177 (progn (insert ";")
10178 (vhdl-comment-insert-inline))
10179 (let ((position (point)))
10180 (insert " := ")
10181 (unless (vhdl-template-field "[initialization]" nil t)
10182 (delete-region position (point)))
10183 (insert ";")
10184 (vhdl-comment-insert-inline))))))
10186 (defun vhdl-template-subnature ()
10187 "Insert a subnature declaration."
10188 (interactive)
10189 (let ((start (point))
10190 position)
10191 (vhdl-insert-keyword "SUBNATURE ")
10192 (when (vhdl-template-field "name" nil t start (point))
10193 (vhdl-insert-keyword " IS ")
10194 (vhdl-template-field "nature" " (")
10195 (if (vhdl-template-field "[index range]" nil t)
10196 (insert ")")
10197 (delete-char -2))
10198 (setq position (point))
10199 (vhdl-insert-keyword " TOLERANCE ")
10200 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10201 nil t nil nil t))
10202 (delete-region position (point))
10203 (vhdl-insert-keyword " ACROSS ")
10204 (vhdl-template-field "string expression" nil nil nil nil t)
10205 (vhdl-insert-keyword " THROUGH"))
10206 (insert ";")
10207 (vhdl-comment-insert-inline))))
10209 (defun vhdl-template-subprogram-body ()
10210 "Insert a subprogram body."
10211 (interactive)
10212 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10213 (vhdl-template-function-body)
10214 (vhdl-template-procedure-body)))
10216 (defun vhdl-template-subprogram-decl ()
10217 "Insert a subprogram declaration."
10218 (interactive)
10219 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
10220 (vhdl-template-function-decl)
10221 (vhdl-template-procedure-decl)))
10223 (defun vhdl-template-subtype ()
10224 "Insert a subtype declaration."
10225 (interactive)
10226 (let ((start (point)))
10227 (vhdl-insert-keyword "SUBTYPE ")
10228 (when (vhdl-template-field "name" nil t start (point))
10229 (vhdl-insert-keyword " IS ")
10230 (vhdl-template-field "type" " ")
10231 (unless
10232 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
10233 (delete-char -1))
10234 (insert ";")
10235 (vhdl-comment-insert-inline))))
10237 (defun vhdl-template-terminal ()
10238 "Insert a terminal declaration."
10239 (interactive)
10240 (let ((start (point)))
10241 (vhdl-insert-keyword "TERMINAL ")
10242 (when (vhdl-template-field "names" nil t start (point))
10243 (insert " : ")
10244 (vhdl-template-field "nature")
10245 (insert ";")
10246 (vhdl-comment-insert-inline))))
10248 (defun vhdl-template-type ()
10249 "Insert a type declaration."
10250 (interactive)
10251 (let ((start (point))
10252 name mid-pos end-pos)
10253 (vhdl-insert-keyword "TYPE ")
10254 (when (setq name (vhdl-template-field "name" nil t start (point)))
10255 (vhdl-insert-keyword " IS ")
10256 (let ((definition
10257 (upcase
10258 (or (vhdl-template-field
10259 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
10260 ""))))
10261 (cond ((equal definition "")
10262 (delete-char -4)
10263 (insert ";"))
10264 ((equal definition "ARRAY")
10265 (delete-region (point) (progn (forward-word -1) (point)))
10266 (vhdl-template-array 'type t))
10267 ((equal definition "RECORD")
10268 (setq mid-pos (point-marker))
10269 (delete-region (point) (progn (forward-word -1) (point)))
10270 (vhdl-template-record 'type name t))
10271 ((equal definition "ACCESS")
10272 (insert " ")
10273 (vhdl-template-field "type" ";"))
10274 ((equal definition "FILE")
10275 (vhdl-insert-keyword " OF ")
10276 (vhdl-template-field "type" ";"))
10277 ((equal definition "ENUM")
10278 (kill-word -1)
10279 (insert "(")
10280 (setq end-pos (point-marker))
10281 (insert ");"))
10282 (t (insert ";")))
10283 (when mid-pos
10284 (setq end-pos (point-marker))
10285 (goto-char mid-pos)
10286 (end-of-line))
10287 (vhdl-comment-insert-inline)
10288 (when end-pos (goto-char end-pos))))))
10290 (defun vhdl-template-use ()
10291 "Insert a use clause."
10292 (interactive)
10293 (let ((start (point)))
10294 (vhdl-prepare-search-1
10295 (vhdl-insert-keyword "USE ")
10296 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10297 (vhdl-insert-keyword "..ALL;")
10298 (backward-char 6)
10299 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
10300 (forward-char 1)
10301 (vhdl-template-field "package name")
10302 (forward-char 5))))))
10304 (defun vhdl-template-variable ()
10305 "Insert a variable declaration."
10306 (interactive)
10307 (let ((start (point))
10308 (in-arglist (vhdl-in-argument-list-p)))
10309 (vhdl-prepare-search-2
10310 (if (or (save-excursion
10311 (progn (vhdl-beginning-of-block)
10312 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10313 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
10314 (vhdl-insert-keyword "VARIABLE ")
10315 (if (vhdl-standard-p '87)
10316 (error "ERROR: Not within sequential block")
10317 (vhdl-insert-keyword "SHARED VARIABLE "))))
10318 (when (vhdl-template-field "names" nil t start (point))
10319 (insert " : ")
10320 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
10321 (vhdl-template-field "type")
10322 (if in-arglist
10323 (progn (insert ";")
10324 (vhdl-comment-insert-inline))
10325 (let ((position (point)))
10326 (insert " := ")
10327 (unless (vhdl-template-field "[initialization]" nil t)
10328 (delete-region position (point)))
10329 (insert ";")
10330 (vhdl-comment-insert-inline))))))
10332 (defun vhdl-template-wait ()
10333 "Insert a wait statement."
10334 (interactive)
10335 (vhdl-insert-keyword "WAIT ")
10336 (unless (vhdl-template-field
10337 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10338 nil t)
10339 (delete-char -1))
10340 (insert ";"))
10342 (defun vhdl-template-when ()
10343 "Indent correctly if within a case statement."
10344 (interactive)
10345 (let ((position (point))
10346 margin)
10347 (vhdl-prepare-search-2
10348 (if (and (= (current-column) (current-indentation))
10349 (vhdl-re-search-forward "\\<end\\>" nil t)
10350 (looking-at "\\s-*\\<case\\>"))
10351 (progn
10352 (setq margin (current-indentation))
10353 (goto-char position)
10354 (delete-horizontal-space)
10355 (indent-to (+ margin vhdl-basic-offset)))
10356 (goto-char position)))
10357 (vhdl-insert-keyword "WHEN ")))
10359 (defun vhdl-template-while-loop ()
10360 "Insert a while loop."
10361 (interactive)
10362 (let* ((margin (current-indentation))
10363 (start (point))
10364 label)
10365 (if (not (eq vhdl-optional-labels 'all))
10366 (vhdl-insert-keyword "WHILE ")
10367 (vhdl-insert-keyword ": WHILE ")
10368 (goto-char start)
10369 (setq label (vhdl-template-field "[label]" nil t))
10370 (unless label (delete-char 2))
10371 (forward-word 1)
10372 (forward-char 1))
10373 (when vhdl-conditions-in-parenthesis (insert "("))
10374 (when (vhdl-template-field "condition" nil t start (point))
10375 (when vhdl-conditions-in-parenthesis (insert ")"))
10376 (vhdl-insert-keyword " LOOP\n\n")
10377 (indent-to margin)
10378 (vhdl-insert-keyword "END LOOP")
10379 (insert (if label (concat " " label ";") ";"))
10380 (forward-line -1)
10381 (indent-to (+ margin vhdl-basic-offset)))))
10383 (defun vhdl-template-with ()
10384 "Insert a with statement (i.e. selected signal assignment)."
10385 (interactive)
10386 (vhdl-prepare-search-1
10387 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10388 (equal ";" (match-string 1)))
10389 (vhdl-template-selected-signal-asst)
10390 (vhdl-insert-keyword "WITH "))))
10392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10393 ;; Special templates
10395 (defun vhdl-template-clocked-wait ()
10396 "Insert a wait statement for rising/falling clock edge."
10397 (interactive)
10398 (let ((start (point))
10399 clock)
10400 (vhdl-insert-keyword "WAIT UNTIL ")
10401 (when (setq clock
10402 (or (and (not (equal "" vhdl-clock-name))
10403 (progn (insert vhdl-clock-name) vhdl-clock-name))
10404 (vhdl-template-field "clock name" nil t start (point))))
10405 (insert "'event")
10406 (vhdl-insert-keyword " AND ")
10407 (insert clock)
10408 (insert
10409 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10410 (vhdl-comment-insert-inline
10411 (concat (if vhdl-clock-rising-edge "rising" "falling")
10412 " clock edge")))))
10414 (defun vhdl-template-seq-process (clock reset reset-kind)
10415 "Insert a template for the body of a sequential process."
10416 (let ((margin (current-indentation))
10417 position)
10418 (vhdl-insert-keyword "IF ")
10419 (when vhdl-conditions-in-parenthesis (insert "("))
10420 (when (eq reset-kind 'async)
10421 (insert reset " = "
10422 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10423 (when vhdl-conditions-in-parenthesis (insert ")"))
10424 (vhdl-insert-keyword " THEN")
10425 (vhdl-comment-insert-inline
10426 (concat "asynchronous reset (active "
10427 (if vhdl-reset-active-high "high" "low") ")"))
10428 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10429 (setq position (point))
10430 (insert "\n") (indent-to margin)
10431 (vhdl-insert-keyword "ELSIF ")
10432 (when vhdl-conditions-in-parenthesis (insert "(")))
10433 (if (eq vhdl-clock-edge-condition 'function)
10434 (insert (if vhdl-clock-rising-edge "rising" "falling")
10435 "_edge(" clock ")")
10436 (insert clock "'event")
10437 (vhdl-insert-keyword " AND ")
10438 (insert clock " = "
10439 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10440 (when vhdl-conditions-in-parenthesis (insert ")"))
10441 (vhdl-insert-keyword " THEN")
10442 (vhdl-comment-insert-inline
10443 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10444 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10445 (when (eq reset-kind 'sync)
10446 (vhdl-insert-keyword "IF ")
10447 (when vhdl-conditions-in-parenthesis (insert "("))
10448 (setq reset (or (and (not (equal "" vhdl-reset-name))
10449 (progn (insert vhdl-reset-name) vhdl-reset-name))
10450 (vhdl-template-field "reset name") "<reset>"))
10451 (insert " = "
10452 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10453 (when vhdl-conditions-in-parenthesis (insert ")"))
10454 (vhdl-insert-keyword " THEN")
10455 (vhdl-comment-insert-inline
10456 (concat "synchronous reset (active "
10457 (if vhdl-reset-active-high "high" "low") ")"))
10458 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10459 (setq position (point))
10460 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10461 (vhdl-insert-keyword "ELSE")
10462 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10463 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10464 (vhdl-insert-keyword "END IF;"))
10465 (when (eq reset-kind 'none)
10466 (setq position (point)))
10467 (insert "\n") (indent-to margin)
10468 (vhdl-insert-keyword "END IF;")
10469 (goto-char position)
10470 reset))
10472 (defun vhdl-template-standard-package (library package)
10473 "Insert specification of a standard package. Include a library
10474 specification, if not already there."
10475 (let ((margin (current-indentation)))
10476 (unless (equal library "std")
10477 (unless (or (save-excursion
10478 (vhdl-prepare-search-1
10479 (and (not (bobp))
10480 (re-search-backward
10481 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10482 library "\\|end\\)\\>") nil t)
10483 (match-string 2))))
10484 (equal (downcase library) "work"))
10485 (vhdl-insert-keyword "LIBRARY ")
10486 (insert library ";")
10487 (when package
10488 (insert "\n")
10489 (indent-to margin))))
10490 (when package
10491 (vhdl-insert-keyword "USE ")
10492 (insert library "." package)
10493 (vhdl-insert-keyword ".ALL;"))))
10495 (defun vhdl-template-package-numeric-bit ()
10496 "Insert specification of `numeric_bit' package."
10497 (interactive)
10498 (vhdl-template-standard-package "ieee" "numeric_bit"))
10500 (defun vhdl-template-package-numeric-std ()
10501 "Insert specification of `numeric_std' package."
10502 (interactive)
10503 (vhdl-template-standard-package "ieee" "numeric_std"))
10505 (defun vhdl-template-package-std-logic-1164 ()
10506 "Insert specification of `std_logic_1164' package."
10507 (interactive)
10508 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10510 (defun vhdl-template-package-std-logic-arith ()
10511 "Insert specification of `std_logic_arith' package."
10512 (interactive)
10513 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10515 (defun vhdl-template-package-std-logic-misc ()
10516 "Insert specification of `std_logic_misc' package."
10517 (interactive)
10518 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10520 (defun vhdl-template-package-std-logic-signed ()
10521 "Insert specification of `std_logic_signed' package."
10522 (interactive)
10523 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10525 (defun vhdl-template-package-std-logic-textio ()
10526 "Insert specification of `std_logic_textio' package."
10527 (interactive)
10528 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10530 (defun vhdl-template-package-std-logic-unsigned ()
10531 "Insert specification of `std_logic_unsigned' package."
10532 (interactive)
10533 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10535 (defun vhdl-template-package-textio ()
10536 "Insert specification of `textio' package."
10537 (interactive)
10538 (vhdl-template-standard-package "std" "textio"))
10540 (defun vhdl-template-package-fundamental-constants ()
10541 "Insert specification of `fundamental_constants' package."
10542 (interactive)
10543 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10545 (defun vhdl-template-package-material-constants ()
10546 "Insert specification of `material_constants' package."
10547 (interactive)
10548 (vhdl-template-standard-package "ieee" "material_constants"))
10550 (defun vhdl-template-package-energy-systems ()
10551 "Insert specification of `energy_systems' package."
10552 (interactive)
10553 (vhdl-template-standard-package "ieee" "energy_systems"))
10555 (defun vhdl-template-package-electrical-systems ()
10556 "Insert specification of `electrical_systems' package."
10557 (interactive)
10558 (vhdl-template-standard-package "ieee" "electrical_systems"))
10560 (defun vhdl-template-package-mechanical-systems ()
10561 "Insert specification of `mechanical_systems' package."
10562 (interactive)
10563 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10565 (defun vhdl-template-package-radiant-systems ()
10566 "Insert specification of `radiant_systems' package."
10567 (interactive)
10568 (vhdl-template-standard-package "ieee" "radiant_systems"))
10570 (defun vhdl-template-package-thermal-systems ()
10571 "Insert specification of `thermal_systems' package."
10572 (interactive)
10573 (vhdl-template-standard-package "ieee" "thermal_systems"))
10575 (defun vhdl-template-package-fluidic-systems ()
10576 "Insert specification of `fluidic_systems' package."
10577 (interactive)
10578 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10580 (defun vhdl-template-package-math-complex ()
10581 "Insert specification of `math_complex' package."
10582 (interactive)
10583 (vhdl-template-standard-package "ieee" "math_complex"))
10585 (defun vhdl-template-package-math-real ()
10586 "Insert specification of `math_real' package."
10587 (interactive)
10588 (vhdl-template-standard-package "ieee" "math_real"))
10590 (defun vhdl-template-directive (directive)
10591 "Insert directive."
10592 (unless (= (current-indentation) (current-column))
10593 (delete-horizontal-space)
10594 (insert " "))
10595 (insert "-- pragma " directive))
10597 (defun vhdl-template-directive-translate-on ()
10598 "Insert directive 'translate_on'."
10599 (interactive)
10600 (vhdl-template-directive "translate_on"))
10602 (defun vhdl-template-directive-translate-off ()
10603 "Insert directive 'translate_off'."
10604 (interactive)
10605 (vhdl-template-directive "translate_off"))
10607 (defun vhdl-template-directive-synthesis-on ()
10608 "Insert directive 'synthesis_on'."
10609 (interactive)
10610 (vhdl-template-directive "synthesis_on"))
10612 (defun vhdl-template-directive-synthesis-off ()
10613 "Insert directive 'synthesis_off'."
10614 (interactive)
10615 (vhdl-template-directive "synthesis_off"))
10617 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10618 ;; Header and footer templates
10620 (defun vhdl-template-header (&optional file-title)
10621 "Insert a VHDL file header."
10622 (interactive)
10623 (unless (equal vhdl-file-header "")
10624 (let (pos)
10625 (save-excursion
10626 (goto-char (point-min))
10627 (vhdl-insert-string-or-file vhdl-file-header)
10628 (setq pos (point-marker)))
10629 (vhdl-template-replace-header-keywords
10630 (point-min-marker) pos file-title))))
10632 (defun vhdl-template-footer ()
10633 "Insert a VHDL file footer."
10634 (interactive)
10635 (unless (equal vhdl-file-footer "")
10636 (let (pos)
10637 (save-excursion
10638 (goto-char (point-max))
10639 (setq pos (point-marker))
10640 (vhdl-insert-string-or-file vhdl-file-footer)
10641 (unless (= (preceding-char) ?\n)
10642 (insert "\n")))
10643 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10645 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10646 is-model)
10647 "Replace keywords in header and footer."
10648 (let ((project-title (or (nth 0 (vhdl-aget vhdl-project-alist vhdl-project))
10649 ""))
10650 (project-desc (or (nth 9 (vhdl-aget vhdl-project-alist vhdl-project))
10651 ""))
10652 pos)
10653 (vhdl-prepare-search-2
10654 (save-excursion
10655 (goto-char beg)
10656 (while (search-forward "<projectdesc>" end t)
10657 (replace-match project-desc t t))
10658 (goto-char beg)
10659 (while (search-forward "<filename>" end t)
10660 (replace-match (buffer-name) t t))
10661 (goto-char beg)
10662 (while (search-forward "<copyright>" end t)
10663 (replace-match vhdl-copyright-string t t))
10664 (goto-char beg)
10665 (while (search-forward "<author>" end t)
10666 (replace-match "" t t)
10667 (insert (user-full-name))
10668 (when user-mail-address (insert " <" user-mail-address ">")))
10669 (goto-char beg)
10670 (while (search-forward "<authorfull>" end t)
10671 (replace-match (user-full-name) t t))
10672 (goto-char beg)
10673 (while (search-forward "<login>" end t)
10674 (replace-match (user-login-name) t t))
10675 (goto-char beg)
10676 (while (search-forward "<project>" end t)
10677 (replace-match project-title t t))
10678 (goto-char beg)
10679 (while (search-forward "<company>" end t)
10680 (replace-match vhdl-company-name t t))
10681 (goto-char beg)
10682 (while (search-forward "<platform>" end t)
10683 (replace-match vhdl-platform-spec t t))
10684 (goto-char beg)
10685 (while (search-forward "<standard>" end t)
10686 (replace-match
10687 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10688 ((vhdl-standard-p '93) "'93/02")
10689 ((vhdl-standard-p '08) "'08"))
10690 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10691 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10692 (goto-char beg)
10693 ;; Replace <RCS> with $, so that RCS for the source is
10694 ;; not over-enthusiastic with replacements
10695 (while (search-forward "<RCS>" end t)
10696 (replace-match "$" nil t))
10697 (goto-char beg)
10698 (while (search-forward "<date>" end t)
10699 (replace-match "" t t)
10700 (vhdl-template-insert-date))
10701 (goto-char beg)
10702 (while (search-forward "<year>" end t)
10703 (replace-match (format-time-string "%Y" nil) t t))
10704 (goto-char beg)
10705 (when file-title
10706 (while (search-forward "<title string>" end t)
10707 (replace-match file-title t t))
10708 (goto-char beg))
10709 (let (string)
10710 (while (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10711 (save-match-data
10712 (setq string (read-string (concat (match-string 1) ": "))))
10713 (replace-match string t t)))
10714 (goto-char beg)
10715 (when (and (not is-model) (search-forward "<cursor>" end t))
10716 (replace-match "" t t)
10717 (setq pos (point))))
10718 (when pos (goto-char pos))
10719 (unless is-model
10720 (when (or (not project-title) (equal project-title ""))
10721 (message "You can specify a project title in user option `vhdl-project-alist'"))
10722 (when (or (not project-desc) (equal project-desc ""))
10723 (message "You can specify a project description in user option `vhdl-project-alist'"))
10724 (when (equal vhdl-platform-spec "")
10725 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10726 (when (equal vhdl-company-name "")
10727 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10729 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10730 ;; Comment templates and functions
10732 (defun vhdl-comment-indent ()
10733 "Indent comments."
10734 (let* ((position (point))
10735 (col
10736 (progn
10737 (forward-line -1)
10738 (if (re-search-forward "--" position t)
10739 (- (current-column) 2) ; existing comment at bol stays there
10740 (goto-char position)
10741 (skip-chars-backward " \t")
10742 (max comment-column ; else indent to comment column
10743 (1+ (current-column))))))) ; except leave at least one space
10744 (goto-char position)
10745 col))
10747 (defun vhdl-comment-insert ()
10748 "Start a comment at the end of the line.
10749 If on line with code, indent at least `comment-column'.
10750 If starting after end-comment-column, start a new line."
10751 (interactive)
10752 (when (> (current-column) end-comment-column) (newline-and-indent))
10753 (if (or (looking-at "\\s-*$") ; end of line
10754 (and (not unread-command-events) ; called with key binding or menu
10755 (not (end-of-line))))
10756 (let (margin)
10757 (while (= (preceding-char) ?-) (delete-char -1))
10758 (setq margin (current-column))
10759 (delete-horizontal-space)
10760 (if (bolp)
10761 (progn (indent-to margin) (insert "--"))
10762 (insert " ")
10763 (indent-to comment-column)
10764 (insert "--"))
10765 (if (not unread-command-events) (insert " ")))
10766 ;; else code following current point implies commenting out code
10767 (let (next-input code)
10768 (while (= (preceding-char) ?-) (delete-char -2))
10769 (while (= (setq next-input (read-char)) 13) ; CR
10770 (insert "--") ; or have a space after it?
10771 (forward-char -2)
10772 (forward-line 1)
10773 (message "Enter CR if commenting out a line of code.")
10774 (setq code t))
10775 (unless code
10776 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10777 (setq unread-command-events
10778 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10780 (defun vhdl-comment-display (&optional line-exists)
10781 "Add 2 comment lines at the current indent, making a display comment."
10782 (interactive)
10783 (let ((margin (current-indentation)))
10784 (unless line-exists (vhdl-comment-display-line))
10785 (insert "\n") (indent-to margin)
10786 (insert "\n") (indent-to margin)
10787 (vhdl-comment-display-line)
10788 (end-of-line -0)
10789 (insert "-- ")))
10791 (defun vhdl-comment-display-line ()
10792 "Displays one line of dashes."
10793 (interactive)
10794 (while (= (preceding-char) ?-) (delete-char -2))
10795 (insert "--")
10796 (let* ((col (current-column))
10797 (len (- end-comment-column col)))
10798 (insert-char vhdl-comment-display-line-char len)))
10800 (defun vhdl-comment-append-inline ()
10801 "Append empty inline comment to current line."
10802 (interactive)
10803 (end-of-line)
10804 (delete-horizontal-space)
10805 (insert " ")
10806 (indent-to comment-column)
10807 (insert "-- "))
10809 (defun vhdl-comment-insert-inline (&optional string always-insert)
10810 "Insert inline comment."
10811 (when (or (and string (or vhdl-self-insert-comments always-insert))
10812 (and (not string) vhdl-prompt-for-comments))
10813 (let ((position (point)))
10814 (insert " ")
10815 (indent-to comment-column)
10816 (insert "-- ")
10817 (if (not (or (and string (progn (insert string) t))
10818 (vhdl-template-field "[comment]" nil t)))
10819 (delete-region position (point))
10820 (while (= (preceding-char) ?\ ) (delete-char -1))))))
10822 (defun vhdl-comment-block ()
10823 "Insert comment for code block."
10824 (when vhdl-prompt-for-comments
10825 (let ((final-pos (point-marker)))
10826 (vhdl-prepare-search-2
10827 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10828 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10829 (let (margin)
10830 (back-to-indentation)
10831 (setq margin (current-column))
10832 (end-of-line -0)
10833 (if (bobp)
10834 (progn (insert "\n") (forward-line -1))
10835 (insert "\n"))
10836 (indent-to margin)
10837 (insert "-- purpose: ")
10838 (unless (vhdl-template-field "[description]" nil t)
10839 (vhdl-line-kill-entire)))))
10840 (goto-char final-pos))))
10842 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10843 "Comment out region if not commented out, uncomment otherwise."
10844 (interactive "r\nP")
10845 (save-excursion
10846 (goto-char (1- end))
10847 (end-of-line)
10848 (setq end (point-marker))
10849 (goto-char beg)
10850 (beginning-of-line)
10851 (setq beg (point))
10852 (if (looking-at (concat "\\s-*" comment-start))
10853 (comment-region beg end '(4))
10854 (comment-region beg end))))
10856 (defun vhdl-comment-uncomment-line (&optional arg)
10857 "Comment out line if not commented out, uncomment otherwise."
10858 (interactive "p")
10859 (save-excursion
10860 (beginning-of-line)
10861 (let ((position (point)))
10862 (forward-line (or arg 1))
10863 (vhdl-comment-uncomment-region position (point)))))
10865 (defun vhdl-comment-kill-region (beg end)
10866 "Kill comments in region."
10867 (interactive "r")
10868 (save-excursion
10869 (goto-char end)
10870 (setq end (point-marker))
10871 (goto-char beg)
10872 (beginning-of-line)
10873 (while (< (point) end)
10874 (if (looking-at "^\\(\\s-*--.*\n\\)")
10875 (progn (delete-region (match-beginning 1) (match-end 1)))
10876 (beginning-of-line 2)))))
10878 (defun vhdl-comment-kill-inline-region (beg end)
10879 "Kill inline comments in region."
10880 (interactive "r")
10881 (save-excursion
10882 (goto-char end)
10883 (setq end (point-marker))
10884 (goto-char beg)
10885 (beginning-of-line)
10886 (while (< (point) end)
10887 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10888 (delete-region (match-beginning 1) (match-end 1)))
10889 (beginning-of-line 2))))
10891 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10892 ;; Subtemplates
10894 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10895 "Insert a begin ... end pair with optional name after the end.
10896 Point is left between them."
10897 (let (position)
10898 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10899 (indent-to margin)
10900 (vhdl-insert-keyword "BEGIN")
10901 (when (and (or construct name) vhdl-self-insert-comments)
10902 (insert " --")
10903 (when construct (insert " ") (vhdl-insert-keyword construct))
10904 (when name (insert " " name)))
10905 (insert "\n")
10906 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10907 (indent-to (+ margin vhdl-basic-offset))
10908 (setq position (point))
10909 (insert "\n")
10910 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10911 (indent-to margin)
10912 (vhdl-insert-keyword "END")
10913 (when construct (insert " ") (vhdl-insert-keyword construct))
10914 (insert (if name (concat " " name) "") ";")
10915 (goto-char position)))
10917 (defun vhdl-template-argument-list (&optional is-function)
10918 "Read from user a procedure or function argument list."
10919 (insert " (")
10920 (let ((margin (current-column))
10921 (start (point))
10922 (end-pos (point))
10923 not-empty interface semicolon-pos)
10924 (unless vhdl-argument-list-indent
10925 (setq margin (+ (current-indentation) vhdl-basic-offset))
10926 (insert "\n")
10927 (indent-to margin))
10928 (setq interface (vhdl-template-field
10929 (concat "[CONSTANT | SIGNAL"
10930 (unless is-function " | VARIABLE") "]") " " t))
10931 (while (vhdl-template-field "[names]" nil t)
10932 (setq not-empty t)
10933 (insert " : ")
10934 (unless is-function
10935 (if (and interface (equal (upcase interface) "CONSTANT"))
10936 (vhdl-insert-keyword "IN ")
10937 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10938 (vhdl-template-field "type")
10939 (setq semicolon-pos (point))
10940 (insert ";")
10941 (vhdl-comment-insert-inline)
10942 (setq end-pos (point))
10943 (insert "\n")
10944 (indent-to margin)
10945 (setq interface (vhdl-template-field
10946 (concat "[CONSTANT | SIGNAL"
10947 (unless is-function " | VARIABLE") "]") " " t)))
10948 (delete-region end-pos (point))
10949 (when semicolon-pos (goto-char semicolon-pos))
10950 (if not-empty
10951 (progn (delete-char 1) (insert ")"))
10952 (delete-char -2))))
10954 (defun vhdl-template-generic-list (optional &optional no-value)
10955 "Read from user a generic spec argument list."
10956 (let (margin
10957 (start (point)))
10958 (vhdl-insert-keyword "GENERIC (")
10959 (setq margin (current-column))
10960 (unless vhdl-argument-list-indent
10961 (let ((position (point)))
10962 (back-to-indentation)
10963 (setq margin (+ (current-column) vhdl-basic-offset))
10964 (goto-char position)
10965 (insert "\n")
10966 (indent-to margin)))
10967 (let ((vhdl-generics (vhdl-template-field
10968 (concat (and optional "[") "name"
10969 (and no-value "s") (and optional "]"))
10970 nil optional)))
10971 (if (not vhdl-generics)
10972 (if optional
10973 (progn (vhdl-line-kill-entire) (end-of-line -0)
10974 (unless vhdl-argument-list-indent
10975 (vhdl-line-kill-entire) (end-of-line -0)))
10976 (vhdl-template-undo start (point))
10977 nil )
10978 (insert " : ")
10979 (let (semicolon-pos end-pos)
10980 (while vhdl-generics
10981 (vhdl-template-field "type")
10982 (if no-value
10983 (progn (setq semicolon-pos (point))
10984 (insert ";"))
10985 (insert " := ")
10986 (unless (vhdl-template-field "[value]" nil t)
10987 (delete-char -4))
10988 (setq semicolon-pos (point))
10989 (insert ";"))
10990 (vhdl-comment-insert-inline)
10991 (setq end-pos (point))
10992 (insert "\n")
10993 (indent-to margin)
10994 (setq vhdl-generics (vhdl-template-field
10995 (concat "[name" (and no-value "s") "]")
10996 " : " t)))
10997 (delete-region end-pos (point))
10998 (goto-char semicolon-pos)
10999 (insert ")")
11000 (end-of-line)
11001 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
11002 t)))))
11004 (defun vhdl-template-port-list (optional)
11005 "Read from user a port spec argument list."
11006 (let ((start (point))
11007 margin vhdl-ports object)
11008 (vhdl-insert-keyword "PORT (")
11009 (setq margin (current-column))
11010 (unless vhdl-argument-list-indent
11011 (let ((position (point)))
11012 (back-to-indentation)
11013 (setq margin (+ (current-column) vhdl-basic-offset))
11014 (goto-char position)
11015 (insert "\n")
11016 (indent-to margin)))
11017 (when (vhdl-standard-p 'ams)
11018 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11019 " " t)))
11020 (setq vhdl-ports (vhdl-template-field
11021 (concat (and optional "[") "names" (and optional "]"))
11022 nil optional))
11023 (if (not vhdl-ports)
11024 (if optional
11025 (progn (vhdl-line-kill-entire) (end-of-line -0)
11026 (unless vhdl-argument-list-indent
11027 (vhdl-line-kill-entire) (end-of-line -0)))
11028 (vhdl-template-undo start (point))
11029 nil)
11030 (insert " : ")
11031 (let (semicolon-pos end-pos)
11032 (while vhdl-ports
11033 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
11034 (vhdl-template-field "IN | OUT | INOUT" " "))
11035 ((equal "QUANTITY" (upcase object))
11036 (vhdl-template-field "[IN | OUT]" " " t)))
11037 (vhdl-template-field
11038 (if (and object (equal "TERMINAL" (upcase object)))
11039 "nature" "type"))
11040 (setq semicolon-pos (point))
11041 (insert ";")
11042 (vhdl-comment-insert-inline)
11043 (setq end-pos (point))
11044 (insert "\n")
11045 (indent-to margin)
11046 (when (vhdl-standard-p 'ams)
11047 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
11048 " " t)))
11049 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
11050 (delete-region end-pos (point))
11051 (goto-char semicolon-pos)
11052 (insert ")")
11053 (end-of-line)
11054 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
11055 t))))
11057 (defun vhdl-template-generate-body (margin label)
11058 "Insert body for generate template."
11059 (vhdl-insert-keyword " GENERATE")
11060 (insert "\n\n")
11061 (indent-to margin)
11062 (vhdl-insert-keyword "END GENERATE ")
11063 (insert label ";")
11064 (end-of-line 0)
11065 (indent-to (+ margin vhdl-basic-offset)))
11067 (defun vhdl-template-insert-date ()
11068 "Insert date in appropriate format."
11069 (interactive)
11070 (insert
11071 (cond
11072 ;; 'american, 'european, 'scientific kept for backward compatibility
11073 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
11074 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
11075 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
11076 (t (format-time-string vhdl-date-format nil)))))
11078 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11079 ;; Help functions
11081 (defun vhdl-electric-space (count)
11082 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
11083 if in comment and past end-comment-column."
11084 (interactive "p")
11085 (cond ((vhdl-in-comment-p)
11086 (self-insert-command count)
11087 (cond ((>= (current-column) (+ 2 end-comment-column))
11088 (backward-char 1)
11089 (skip-chars-backward "^ \t\n\r\f")
11090 (indent-new-comment-line)
11091 (skip-chars-forward "^ \t\n\r\f")
11092 (forward-char 1))
11093 ((>= (current-column) end-comment-column)
11094 (indent-new-comment-line))
11095 (t nil)))
11096 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
11097 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
11098 (vhdl-prepare-search-1
11099 (or (expand-abbrev) (vhdl-fix-case-word -1)))
11100 (self-insert-command count))
11101 (t (self-insert-command count))))
11103 (defun vhdl-template-field (prompt &optional follow-string optional
11104 begin end is-string default)
11105 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
11106 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
11107 an empty string is inserted, return nil and call `vhdl-template-undo' for
11108 the region between BEGIN and END. IS-STRING indicates whether a string
11109 with double-quotes is to be inserted. DEFAULT specifies a default string."
11110 (let ((position (point))
11111 string)
11112 (insert "<" prompt ">")
11113 (setq string
11114 (condition-case ()
11115 (read-from-minibuffer (concat prompt ": ")
11116 (or (and is-string '("\"\"" . 2)) default)
11117 vhdl-minibuffer-local-map)
11118 (quit (if (and optional begin end)
11119 (progn (beep) "")
11120 (keyboard-quit)))))
11121 (when (or (not (equal string "")) optional)
11122 (delete-region position (point)))
11123 (when (and (equal string "") optional begin end)
11124 (vhdl-template-undo begin end)
11125 (message "Template aborted"))
11126 (unless (equal string "")
11127 (insert string)
11128 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
11129 vhdl-keywords-regexp)
11130 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
11131 vhdl-types-regexp)
11132 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
11133 (concat "'" vhdl-attributes-regexp))
11134 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
11135 vhdl-enum-values-regexp)
11136 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
11137 vhdl-constants-regexp))
11138 (when (or (not (equal string "")) (not optional))
11139 (insert (or follow-string "")))
11140 (if (equal string "") nil string)))
11142 (defun vhdl-decision-query (string prompt &optional optional)
11143 "Query a decision from the user."
11144 (let ((start (point)))
11145 (when string (vhdl-insert-keyword (concat string " ")))
11146 (message "%s" (or prompt ""))
11147 (let ((char (read-char)))
11148 (delete-region start (point))
11149 (if (and optional (eq char ?\r))
11150 (progn (insert " ")
11151 (unexpand-abbrev)
11152 (throw 'abort "ERROR: Template aborted"))
11153 char))))
11155 (defun vhdl-insert-keyword (keyword)
11156 "Insert KEYWORD and adjust case."
11157 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
11159 (defun vhdl-case-keyword (keyword)
11160 "Adjust case of KEYWORD."
11161 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
11163 (defun vhdl-case-word (num)
11164 "Adjust case of following NUM words."
11165 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
11167 (defun vhdl-minibuffer-tab (&optional prefix-arg)
11168 "If preceding character is part of a word or a paren then hippie-expand,
11169 else insert tab (used for word completion in VHDL minibuffer)."
11170 (interactive "P")
11171 (cond
11172 ;; expand word
11173 ((= (char-syntax (preceding-char)) ?w)
11174 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11175 (case-replace nil)
11176 (hippie-expand-only-buffers
11177 (or (and (boundp 'hippie-expand-only-buffers)
11178 hippie-expand-only-buffers)
11179 '(vhdl-mode))))
11180 (vhdl-expand-abbrev prefix-arg)))
11181 ;; expand parenthesis
11182 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
11183 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
11184 (case-replace nil))
11185 (vhdl-expand-paren prefix-arg)))
11186 ;; insert tab
11187 (t (insert-tab))))
11189 (defun vhdl-template-search-prompt ()
11190 "Search for left out template prompts and query again."
11191 (interactive)
11192 (vhdl-prepare-search-2
11193 (when (or (re-search-forward
11194 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
11195 (re-search-backward
11196 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
11197 (let ((string (match-string 1)))
11198 (replace-match "")
11199 (vhdl-template-field string)))))
11201 (defun vhdl-template-undo (begin end)
11202 "Undo aborted template by deleting region and unexpanding the keyword."
11203 (cond (vhdl-template-invoked-by-hook
11204 (goto-char end)
11205 (insert " ")
11206 (delete-region begin end)
11207 (unexpand-abbrev))
11208 (t (delete-region begin end))))
11210 (defun vhdl-insert-string-or-file (string)
11211 "Insert STRING or file contents if STRING is an existing file name."
11212 (unless (equal string "")
11213 (let ((file-name
11214 (progn (string-match "^\\([^\n]+\\)" string)
11215 (vhdl-resolve-env-variable (match-string 1 string)))))
11216 (if (file-exists-p file-name)
11217 (forward-char (cadr (insert-file-contents file-name)))
11218 (insert string)))))
11220 (defun vhdl-beginning-of-block ()
11221 "Move cursor to the beginning of the enclosing block."
11222 (let (pos)
11223 (vhdl-prepare-search-2
11224 (save-excursion
11225 (beginning-of-line)
11226 ;; search backward for block beginning or end
11227 (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|context\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
11228 ;; not consider subprogram declarations
11229 (or (and (match-string 5)
11230 (save-match-data
11231 (save-excursion
11232 (goto-char (match-end 5))
11233 (forward-word 1)
11234 (vhdl-forward-syntactic-ws)
11235 (when (looking-at "(")
11236 (forward-sexp))
11237 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11238 (match-string 1)))
11239 ;; not consider configuration specifications
11240 (and (match-string 6)
11241 (save-match-data
11242 (save-excursion
11243 (vhdl-end-of-block)
11244 (beginning-of-line)
11245 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11246 (match-string 2))
11247 ;; skip subblock if block end found
11248 (vhdl-beginning-of-block))))
11249 (when pos (goto-char pos))))
11251 (defun vhdl-end-of-block ()
11252 "Move cursor to the end of the enclosing block."
11253 (let (pos)
11254 (vhdl-prepare-search-2
11255 (save-excursion
11256 (end-of-line)
11257 ;; search forward for block beginning or end
11258 (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|context\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
11259 ;; not consider subprogram declarations
11260 (or (and (match-string 5)
11261 (save-match-data
11262 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
11263 (match-string 1)))
11264 ;; not consider configuration specifications
11265 (and (match-string 6)
11266 (save-match-data
11267 (save-excursion
11268 (vhdl-end-of-block)
11269 (beginning-of-line)
11270 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11271 (not (match-string 2)))
11272 ;; skip subblock if block beginning found
11273 (vhdl-end-of-block))))
11274 (when pos (goto-char pos))))
11276 (defun vhdl-sequential-statement-p ()
11277 "Check if point is within sequential statement part."
11278 (let ((start (point)))
11279 (save-excursion
11280 (vhdl-prepare-search-2
11281 ;; is sequential statement if ...
11282 (and (re-search-backward "^\\s-*begin\\>" nil t)
11283 ;; ... point is between "begin" and "end" of ...
11284 (progn (vhdl-end-of-block)
11285 (< start (point)))
11286 ;; ... a sequential block
11287 (progn (vhdl-beginning-of-block)
11288 (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\\)\\)\\>")))))))
11290 (defun vhdl-in-argument-list-p ()
11291 "Check if within an argument list."
11292 (save-excursion
11293 (vhdl-prepare-search-2
11294 (or (string-match "arglist"
11295 (format "%s" (caar (vhdl-get-syntactic-context))))
11296 (progn (beginning-of-line)
11297 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11300 ;; Abbrev hooks
11302 (defun vhdl-hooked-abbrev (func)
11303 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11304 but not if inside a comment or quote."
11305 (if (or (vhdl-in-literal)
11306 (save-excursion
11307 (forward-word -1)
11308 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11309 (progn
11310 (insert " ")
11311 (unexpand-abbrev)
11312 (backward-word 1)
11313 (vhdl-case-word 1)
11314 (delete-char 1))
11315 (if (not vhdl-electric-mode)
11316 (progn
11317 (insert " ")
11318 (unexpand-abbrev)
11319 (backward-word 1)
11320 (vhdl-case-word 1)
11321 (delete-char 1))
11322 (let ((invoke-char vhdl-last-input-event)
11323 (abbrev-mode -1)
11324 (vhdl-template-invoked-by-hook t))
11325 (let ((caught (catch 'abort
11326 (funcall func))))
11327 (when (stringp caught) (message "%s" caught)))
11328 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
11329 ;; delete CR which is still in event queue
11330 (if (fboundp 'enqueue-eval-event)
11331 (enqueue-eval-event 'delete-char -1)
11332 (setq unread-command-events ; push back a delete char
11333 (list (vhdl-character-to-event ?\177))))))))
11335 (defun vhdl-template-alias-hook ()
11336 (vhdl-hooked-abbrev 'vhdl-template-alias))
11337 (defun vhdl-template-architecture-hook ()
11338 (vhdl-hooked-abbrev 'vhdl-template-architecture))
11339 (defun vhdl-template-assert-hook ()
11340 (vhdl-hooked-abbrev 'vhdl-template-assert))
11341 (defun vhdl-template-attribute-hook ()
11342 (vhdl-hooked-abbrev 'vhdl-template-attribute))
11343 (defun vhdl-template-block-hook ()
11344 (vhdl-hooked-abbrev 'vhdl-template-block))
11345 (defun vhdl-template-break-hook ()
11346 (vhdl-hooked-abbrev 'vhdl-template-break))
11347 (defun vhdl-template-case-hook ()
11348 (vhdl-hooked-abbrev 'vhdl-template-case))
11349 (defun vhdl-template-component-hook ()
11350 (vhdl-hooked-abbrev 'vhdl-template-component))
11351 (defun vhdl-template-instance-hook ()
11352 (vhdl-hooked-abbrev 'vhdl-template-instance))
11353 (defun vhdl-template-conditional-signal-asst-hook ()
11354 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
11355 (defun vhdl-template-configuration-hook ()
11356 (vhdl-hooked-abbrev 'vhdl-template-configuration))
11357 (defun vhdl-template-constant-hook ()
11358 (vhdl-hooked-abbrev 'vhdl-template-constant))
11359 (defun vhdl-template-context-hook ()
11360 (vhdl-hooked-abbrev 'vhdl-template-context))
11361 (defun vhdl-template-disconnect-hook ()
11362 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
11363 (defun vhdl-template-display-comment-hook ()
11364 (vhdl-hooked-abbrev 'vhdl-comment-display))
11365 (defun vhdl-template-else-hook ()
11366 (vhdl-hooked-abbrev 'vhdl-template-else))
11367 (defun vhdl-template-elsif-hook ()
11368 (vhdl-hooked-abbrev 'vhdl-template-elsif))
11369 (defun vhdl-template-entity-hook ()
11370 (vhdl-hooked-abbrev 'vhdl-template-entity))
11371 (defun vhdl-template-exit-hook ()
11372 (vhdl-hooked-abbrev 'vhdl-template-exit))
11373 (defun vhdl-template-file-hook ()
11374 (vhdl-hooked-abbrev 'vhdl-template-file))
11375 (defun vhdl-template-for-hook ()
11376 (vhdl-hooked-abbrev 'vhdl-template-for))
11377 (defun vhdl-template-function-hook ()
11378 (vhdl-hooked-abbrev 'vhdl-template-function))
11379 (defun vhdl-template-generic-hook ()
11380 (vhdl-hooked-abbrev 'vhdl-template-generic))
11381 (defun vhdl-template-group-hook ()
11382 (vhdl-hooked-abbrev 'vhdl-template-group))
11383 (defun vhdl-template-library-hook ()
11384 (vhdl-hooked-abbrev 'vhdl-template-library))
11385 (defun vhdl-template-limit-hook ()
11386 (vhdl-hooked-abbrev 'vhdl-template-limit))
11387 (defun vhdl-template-if-hook ()
11388 (vhdl-hooked-abbrev 'vhdl-template-if))
11389 (defun vhdl-template-bare-loop-hook ()
11390 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
11391 (defun vhdl-template-map-hook ()
11392 (vhdl-hooked-abbrev 'vhdl-template-map))
11393 (defun vhdl-template-nature-hook ()
11394 (vhdl-hooked-abbrev 'vhdl-template-nature))
11395 (defun vhdl-template-next-hook ()
11396 (vhdl-hooked-abbrev 'vhdl-template-next))
11397 (defun vhdl-template-others-hook ()
11398 (vhdl-hooked-abbrev 'vhdl-template-others))
11399 (defun vhdl-template-package-hook ()
11400 (vhdl-hooked-abbrev 'vhdl-template-package))
11401 (defun vhdl-template-port-hook ()
11402 (vhdl-hooked-abbrev 'vhdl-template-port))
11403 (defun vhdl-template-procedural-hook ()
11404 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11405 (defun vhdl-template-procedure-hook ()
11406 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11407 (defun vhdl-template-process-hook ()
11408 (vhdl-hooked-abbrev 'vhdl-template-process))
11409 (defun vhdl-template-quantity-hook ()
11410 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11411 (defun vhdl-template-report-hook ()
11412 (vhdl-hooked-abbrev 'vhdl-template-report))
11413 (defun vhdl-template-return-hook ()
11414 (vhdl-hooked-abbrev 'vhdl-template-return))
11415 (defun vhdl-template-selected-signal-asst-hook ()
11416 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11417 (defun vhdl-template-signal-hook ()
11418 (vhdl-hooked-abbrev 'vhdl-template-signal))
11419 (defun vhdl-template-subnature-hook ()
11420 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11421 (defun vhdl-template-subtype-hook ()
11422 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11423 (defun vhdl-template-terminal-hook ()
11424 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11425 (defun vhdl-template-type-hook ()
11426 (vhdl-hooked-abbrev 'vhdl-template-type))
11427 (defun vhdl-template-use-hook ()
11428 (vhdl-hooked-abbrev 'vhdl-template-use))
11429 (defun vhdl-template-variable-hook ()
11430 (vhdl-hooked-abbrev 'vhdl-template-variable))
11431 (defun vhdl-template-wait-hook ()
11432 (vhdl-hooked-abbrev 'vhdl-template-wait))
11433 (defun vhdl-template-when-hook ()
11434 (vhdl-hooked-abbrev 'vhdl-template-when))
11435 (defun vhdl-template-while-loop-hook ()
11436 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11437 (defun vhdl-template-with-hook ()
11438 (vhdl-hooked-abbrev 'vhdl-template-with))
11439 (defun vhdl-template-and-hook ()
11440 (vhdl-hooked-abbrev 'vhdl-template-and))
11441 (defun vhdl-template-or-hook ()
11442 (vhdl-hooked-abbrev 'vhdl-template-or))
11443 (defun vhdl-template-nand-hook ()
11444 (vhdl-hooked-abbrev 'vhdl-template-nand))
11445 (defun vhdl-template-nor-hook ()
11446 (vhdl-hooked-abbrev 'vhdl-template-nor))
11447 (defun vhdl-template-xor-hook ()
11448 (vhdl-hooked-abbrev 'vhdl-template-xor))
11449 (defun vhdl-template-xnor-hook ()
11450 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11451 (defun vhdl-template-not-hook ()
11452 (vhdl-hooked-abbrev 'vhdl-template-not))
11454 (defun vhdl-template-default-hook ()
11455 (vhdl-hooked-abbrev 'vhdl-template-default))
11456 (defun vhdl-template-default-indent-hook ()
11457 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11459 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11460 ;; Template insertion from completion list
11462 (defun vhdl-template-insert-construct (name)
11463 "Insert the built-in construct template with NAME."
11464 (interactive
11465 (list (let ((completion-ignore-case t))
11466 (completing-read "Construct name: "
11467 vhdl-template-construct-alist nil t))))
11468 (vhdl-template-insert-fun
11469 (cadr (assoc name vhdl-template-construct-alist))))
11471 (defun vhdl-template-insert-package (name)
11472 "Insert the built-in package template with NAME."
11473 (interactive
11474 (list (let ((completion-ignore-case t))
11475 (completing-read "Package name: "
11476 vhdl-template-package-alist nil t))))
11477 (vhdl-template-insert-fun
11478 (cadr (assoc name vhdl-template-package-alist))))
11480 (defun vhdl-template-insert-directive (name)
11481 "Insert the built-in directive template with NAME."
11482 (interactive
11483 (list (let ((completion-ignore-case t))
11484 (completing-read "Directive name: "
11485 vhdl-template-directive-alist nil t))))
11486 (vhdl-template-insert-fun
11487 (cadr (assoc name vhdl-template-directive-alist))))
11489 (defun vhdl-template-insert-fun (fun)
11490 "Call FUN to insert a built-in template."
11491 (let ((caught (catch 'abort (when fun (funcall fun)))))
11492 (when (stringp caught) (message "%s" caught))))
11495 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11496 ;;; Models
11497 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11499 (defun vhdl-model-insert (model-name)
11500 "Insert the user model with name MODEL-NAME."
11501 (interactive
11502 (let ((completion-ignore-case t))
11503 (list (completing-read "Model name: " vhdl-model-alist))))
11504 (indent-according-to-mode)
11505 (let ((start (point-marker))
11506 (margin (current-indentation))
11507 model position prompt string end)
11508 (vhdl-prepare-search-2
11509 (when (setq model (assoc model-name vhdl-model-alist))
11510 ;; insert model
11511 (beginning-of-line)
11512 (delete-horizontal-space)
11513 (goto-char start)
11514 (vhdl-insert-string-or-file (nth 1 model))
11515 (setq end (point-marker))
11516 ;; indent code
11517 (goto-char start)
11518 (beginning-of-line)
11519 (while (< (point) end)
11520 (unless (looking-at "^$")
11521 (insert-char ? margin))
11522 (beginning-of-line 2))
11523 (goto-char start)
11524 ;; insert clock
11525 (unless (equal "" vhdl-clock-name)
11526 (while (re-search-forward "<clock>" end t)
11527 (replace-match vhdl-clock-name)))
11528 (goto-char start)
11529 ;; insert reset
11530 (unless (equal "" vhdl-reset-name)
11531 (while (re-search-forward "<reset>" end t)
11532 (replace-match vhdl-reset-name)))
11533 ;; replace header prompts
11534 (vhdl-template-replace-header-keywords start end nil t)
11535 (goto-char start)
11536 ;; query other prompts
11537 (while (re-search-forward
11538 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11539 (unless (equal "cursor" (match-string 1))
11540 (setq position (match-beginning 1))
11541 (setq prompt (match-string 1))
11542 (replace-match "")
11543 (setq string (vhdl-template-field prompt nil t))
11544 ;; replace occurrences of same prompt
11545 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11546 (replace-match (or string "")))
11547 (goto-char position)))
11548 (goto-char start)
11549 ;; goto final position
11550 (if (re-search-forward "<cursor>" end t)
11551 (replace-match "")
11552 (goto-char end))))))
11554 (defun vhdl-model-defun ()
11555 "Define help and hook functions for user models."
11556 (let ((model-alist vhdl-model-alist)
11557 model-name model-keyword)
11558 (while model-alist
11559 ;; define functions for user models that can be invoked from menu and key
11560 ;; bindings and which themselves call `vhdl-model-insert' with the model
11561 ;; name as argument
11562 (setq model-name (nth 0 (car model-alist)))
11563 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11564 ,(concat "Insert model for \"" model-name "\".")
11565 (interactive)
11566 (vhdl-model-insert ,model-name)))
11567 ;; define hooks for user models that are invoked from keyword abbrevs
11568 (setq model-keyword (nth 3 (car model-alist)))
11569 (unless (equal model-keyword "")
11570 (eval `(defun
11571 ,(vhdl-function-name
11572 "vhdl-model" model-name "hook") ()
11573 (vhdl-hooked-abbrev
11574 ',(vhdl-function-name "vhdl-model" model-name)))))
11575 (setq model-alist (cdr model-alist)))))
11577 (vhdl-model-defun)
11580 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11581 ;;; Port translation
11582 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11584 (defvar vhdl-port-list nil
11585 "Variable to hold last port map parsed.")
11586 ;; structure: (parenthesized expression means list of such entries)
11587 ;; (ent-name
11588 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11589 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11590 ;; (lib-name pack-key))
11592 (defun vhdl-parse-string (string &optional optional)
11593 "Check that the text following point matches the regexp in STRING."
11594 (if (looking-at string)
11595 (progn (goto-char (match-end 0))
11596 (when (vhdl-in-literal)
11597 (end-of-line))
11598 (point))
11599 (unless optional
11600 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11601 (vhdl-current-line) string)))
11602 nil))
11604 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11605 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11606 (vhdl-prepare-search-1
11607 (if (string-match (car regexp-cons) string)
11608 (if adjust-case
11609 (funcall vhdl-file-name-case
11610 (replace-match (cdr regexp-cons) t nil string))
11611 (replace-match (cdr regexp-cons) t nil string))
11612 string)))
11614 (defun vhdl-parse-group-comment ()
11615 "Parse comment and empty lines between groups of lines."
11616 (let ((start (point))
11617 string)
11618 (vhdl-forward-comment (point-max))
11619 (setq string (buffer-substring-no-properties start (point)))
11620 (vhdl-forward-syntactic-ws)
11621 ;; strip off leading blanks and first newline
11622 (while (string-match "^\\(\\s-+\\)" string)
11623 (setq string (concat (substring string 0 (match-beginning 1))
11624 (substring string (match-end 1)))))
11625 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11626 (substring string 1)
11627 string)))
11629 (defun vhdl-paste-group-comment (string indent)
11630 "Paste comment and empty lines from STRING between groups of lines
11631 with INDENT."
11632 (let ((pos (point-marker)))
11633 (when (> indent 0)
11634 (while (string-match "^\\(--\\)" string)
11635 (setq string (concat (substring string 0 (match-beginning 1))
11636 (make-string indent ? )
11637 (substring string (match-beginning 1))))))
11638 (beginning-of-line)
11639 (insert string)
11640 (goto-char pos)))
11642 (defvar vhdl-port-flattened nil
11643 "Indicates whether a port has been flattened.")
11645 (defun vhdl-port-flatten (&optional as-alist)
11646 "Flatten port list so that only one generic/port exists per line.
11647 This operation is performed on an internally stored port and is only
11648 reflected in a subsequent paste operation."
11649 (interactive)
11650 (if (not vhdl-port-list)
11651 (error "ERROR: No port has been read")
11652 (message "Flattening port for next paste...")
11653 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11654 (old-vhdl-port-list (cdr vhdl-port-list))
11655 old-port-list new-port-list old-port new-port names)
11656 ;; traverse port list and flatten entries
11657 (while (cdr old-vhdl-port-list)
11658 (setq old-port-list (car old-vhdl-port-list))
11659 (setq new-port-list nil)
11660 (while old-port-list
11661 (setq old-port (car old-port-list))
11662 (setq names (car old-port))
11663 (while names
11664 (setq new-port (cons (if as-alist (car names) (list (car names)))
11665 (cdr old-port)))
11666 (setq new-port-list (append new-port-list (list new-port)))
11667 (setq names (cdr names)))
11668 (setq old-port-list (cdr old-port-list)))
11669 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11670 (setq new-vhdl-port-list (append new-vhdl-port-list
11671 (list new-port-list))))
11672 (setq vhdl-port-list
11673 (append new-vhdl-port-list (list old-vhdl-port-list))
11674 vhdl-port-flattened t)
11675 (message "Flattening port for next paste...done"))))
11677 (defvar vhdl-port-reversed-direction nil
11678 "Indicates whether port directions are reversed.")
11680 (defun vhdl-port-reverse-direction ()
11681 "Reverse direction for all ports (useful in testbenches).
11682 This operation is performed on an internally stored port and is only
11683 reflected in a subsequent paste operation."
11684 (interactive)
11685 (if (not vhdl-port-list)
11686 (error "ERROR: No port has been read")
11687 (message "Reversing port directions for next paste...")
11688 (let ((port-list (nth 2 vhdl-port-list))
11689 port-dir-car port-dir)
11690 ;; traverse port list and reverse directions
11691 (while port-list
11692 (setq port-dir-car (cddr (car port-list))
11693 port-dir (car port-dir-car))
11694 (setcar port-dir-car
11695 (cond ((equal port-dir "in") "out")
11696 ((equal port-dir "IN") "OUT")
11697 ((equal port-dir "out") "in")
11698 ((equal port-dir "OUT") "IN")
11699 (t port-dir)))
11700 (setq port-list (cdr port-list)))
11701 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11702 (message "Reversing port directions for next paste...done"))))
11704 (defun vhdl-port-copy ()
11705 "Get generic and port information from an entity or component declaration."
11706 (interactive)
11707 (save-excursion
11708 (let (parse-error end-of-list
11709 decl-type name generic-list port-list context-clause
11710 object names direct type init comment group-comment)
11711 (vhdl-prepare-search-2
11712 (setq
11713 parse-error
11714 (catch 'parse
11715 ;; check if within entity or component declaration
11716 (end-of-line)
11717 (when (or (not (re-search-backward
11718 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11719 (equal "END" (upcase (match-string 1))))
11720 (throw 'parse "ERROR: Not within an entity or component declaration"))
11721 (setq decl-type (downcase (match-string-no-properties 1)))
11722 (forward-word 1)
11723 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11724 (setq name (match-string-no-properties 1))
11725 (message "Reading port of %s \"%s\"..." decl-type name)
11726 (vhdl-forward-syntactic-ws)
11727 ;; parse generic clause
11728 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11729 ;; parse group comment and spacing
11730 (setq group-comment (vhdl-parse-group-comment))
11731 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11732 (while (not end-of-list)
11733 ;; parse names (accept extended identifiers)
11734 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11735 (setq names (list (match-string-no-properties 1)))
11736 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11737 (setq names
11738 (append names (list (match-string-no-properties 1)))))
11739 ;; parse type
11740 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11741 (setq type (match-string-no-properties 1))
11742 (when (vhdl-in-comment-p) ; if stuck in comment
11743 (setq type (concat type (and (vhdl-parse-string ".*")
11744 (match-string-no-properties 0)))))
11745 (setq comment nil)
11746 (while (looking-at "(")
11747 (setq type
11748 (concat type
11749 (buffer-substring-no-properties
11750 (point) (progn (forward-sexp) (point)))
11751 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11752 (match-string-no-properties 1)))))
11753 ;; special case: closing parenthesis is on separate line
11754 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11755 (setq comment (substring type (match-beginning 2)))
11756 (setq type (substring type 0 (match-beginning 1))))
11757 ;; strip of trailing group-comment
11758 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11759 (setq type (substring type 0 (match-end 1)))
11760 ;; parse initialization expression
11761 (setq init nil)
11762 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11763 (vhdl-parse-string "\\([^();\n]*\\)")
11764 (setq init (match-string-no-properties 1))
11765 (while (looking-at "(")
11766 (setq init
11767 (concat init
11768 (buffer-substring-no-properties
11769 (point) (progn (forward-sexp) (point)))
11770 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11771 (match-string-no-properties 1))))))
11772 ;; special case: closing parenthesis is on separate line
11773 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11774 (setq comment (substring init (match-beginning 2)))
11775 (setq init (substring init 0 (match-beginning 1)))
11776 (vhdl-forward-syntactic-ws))
11777 (skip-chars-forward " \t")
11778 ;; parse inline comment, special case: as above, no initial.
11779 (unless comment
11780 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11781 (match-string-no-properties 1))))
11782 (vhdl-forward-syntactic-ws)
11783 (setq end-of-list (vhdl-parse-string ")" t))
11784 (vhdl-parse-string "\\s-*;\\s-*")
11785 ;; parse inline comment
11786 (unless comment
11787 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11788 (match-string-no-properties 1))))
11789 ;; save everything in list
11790 (setq generic-list (append generic-list
11791 (list (list names type init
11792 comment group-comment))))
11793 ;; parse group comment and spacing
11794 (setq group-comment (vhdl-parse-group-comment))))
11795 ;; parse port clause
11796 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11797 ;; parse group comment and spacing
11798 (setq group-comment (vhdl-parse-group-comment))
11799 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11800 (while (not end-of-list)
11801 ;; parse object
11802 (setq object
11803 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11804 (match-string-no-properties 1)))
11805 ;; parse names (accept extended identifiers)
11806 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11807 (setq names (list (match-string-no-properties 1)))
11808 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11809 (setq names (append names (list (match-string-no-properties 1)))))
11810 ;; parse direction
11811 (vhdl-parse-string ":[ \t\n\r\f]*")
11812 (setq direct
11813 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11814 (match-string-no-properties 1)))
11815 ;; parse type
11816 (vhdl-parse-string "\\([^();\n]+\\)")
11817 (setq type (match-string-no-properties 1))
11818 (when (vhdl-in-comment-p) ; if stuck in comment
11819 (setq type (concat type (and (vhdl-parse-string ".*")
11820 (match-string-no-properties 0)))))
11821 (setq comment nil)
11822 (while (looking-at "(")
11823 (setq type (concat type
11824 (buffer-substring-no-properties
11825 (point) (progn (forward-sexp) (point)))
11826 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11827 (match-string-no-properties 1)))))
11828 ;; special case: closing parenthesis is on separate line
11829 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11830 (setq comment (substring type (match-beginning 2)))
11831 (setq type (substring type 0 (match-beginning 1))))
11832 ;; strip of trailing group-comment
11833 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11834 (setq type (substring type 0 (match-end 1)))
11835 (vhdl-forward-syntactic-ws)
11836 (setq end-of-list (vhdl-parse-string ")" t))
11837 (vhdl-parse-string "\\s-*;\\s-*")
11838 ;; parse inline comment
11839 (unless comment
11840 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11841 (match-string-no-properties 1))))
11842 ;; save everything in list
11843 (setq port-list (append port-list
11844 (list (list names object direct type
11845 comment group-comment))))
11846 ;; parse group comment and spacing
11847 (setq group-comment (vhdl-parse-group-comment))))
11848 ;; parse context clause
11849 (setq context-clause (vhdl-scan-context-clause))
11850 ; ;; add surrounding package to context clause
11851 ; (when (and (equal decl-type "component")
11852 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11853 ; (setq context-clause
11854 ; (append context-clause
11855 ; (list (cons (vhdl-work-library)
11856 ; (match-string-no-properties 1))))))
11857 (message "Reading port of %s \"%s\"...done" decl-type name)
11858 nil)))
11859 ;; finish parsing
11860 (if parse-error
11861 (error parse-error)
11862 (setq vhdl-port-list (list name generic-list port-list context-clause)
11863 vhdl-port-reversed-direction nil
11864 vhdl-port-flattened nil)))))
11866 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11867 "Paste a context clause."
11868 (let ((margin (current-indentation))
11869 (clause-list (nth 3 vhdl-port-list))
11870 clause)
11871 (while clause-list
11872 (setq clause (car clause-list))
11873 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11874 (downcase exclude-pack-name)))
11875 (save-excursion
11876 (re-search-backward
11877 (concat "^\\s-*use\\s-+" (car clause)
11878 "\." (cdr clause) "\\>") nil t)))
11879 (vhdl-template-standard-package (car clause) (cdr clause))
11880 (insert "\n"))
11881 (setq clause-list (cdr clause-list)))))
11883 (defun vhdl-port-paste-generic (&optional no-init)
11884 "Paste a generic clause."
11885 (let ((margin (current-indentation))
11886 (generic-list (nth 1 vhdl-port-list))
11887 list-margin start names generic)
11888 ;; paste generic clause
11889 (when generic-list
11890 (setq start (point))
11891 (vhdl-insert-keyword "GENERIC (")
11892 (unless vhdl-argument-list-indent
11893 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11894 (setq list-margin (current-column))
11895 (while generic-list
11896 (setq generic (car generic-list))
11897 ;; paste group comment and spacing
11898 (when (memq vhdl-include-group-comments '(decl always))
11899 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11900 ;; paste names
11901 (setq names (nth 0 generic))
11902 (while names
11903 (insert (car names))
11904 (setq names (cdr names))
11905 (when names (insert ", ")))
11906 ;; paste type
11907 (insert " : " (nth 1 generic))
11908 ;; paste initialization
11909 (when (and (not no-init) (nth 2 generic))
11910 (insert " := " (nth 2 generic)))
11911 (unless (cdr generic-list) (insert ")"))
11912 (insert ";")
11913 ;; paste comment
11914 (when (and vhdl-include-port-comments (nth 3 generic))
11915 (vhdl-comment-insert-inline (nth 3 generic) t))
11916 (setq generic-list (cdr generic-list))
11917 (when generic-list (insert "\n") (indent-to list-margin)))
11918 ;; align generic clause
11919 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11921 (defun vhdl-port-paste-port ()
11922 "Paste a port clause."
11923 (let ((margin (current-indentation))
11924 (port-list (nth 2 vhdl-port-list))
11925 list-margin start names port)
11926 ;; paste port clause
11927 (when port-list
11928 (setq start (point))
11929 (vhdl-insert-keyword "PORT (")
11930 (unless vhdl-argument-list-indent
11931 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11932 (setq list-margin (current-column))
11933 (while port-list
11934 (setq port (car port-list))
11935 ;; paste group comment and spacing
11936 (when (memq vhdl-include-group-comments '(decl always))
11937 (vhdl-paste-group-comment (nth 5 port) list-margin))
11938 ;; paste object
11939 (when (nth 1 port) (insert (nth 1 port) " "))
11940 ;; paste names
11941 (setq names (nth 0 port))
11942 (while names
11943 (insert (car names))
11944 (setq names (cdr names))
11945 (when names (insert ", ")))
11946 ;; paste direction
11947 (insert " : ")
11948 (when (nth 2 port) (insert (nth 2 port) " "))
11949 ;; paste type
11950 (insert (nth 3 port))
11951 (unless (cdr port-list) (insert ")"))
11952 (insert ";")
11953 ;; paste comment
11954 (when (and vhdl-include-port-comments (nth 4 port))
11955 (vhdl-comment-insert-inline (nth 4 port) t))
11956 (setq port-list (cdr port-list))
11957 (when port-list (insert "\n") (indent-to list-margin)))
11958 ;; align port clause
11959 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11961 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11962 "Paste as an entity or component declaration."
11963 (unless no-indent (indent-according-to-mode))
11964 (let ((margin (current-indentation))
11965 (name (nth 0 vhdl-port-list)))
11966 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11967 (insert name)
11968 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11969 (vhdl-insert-keyword " IS"))
11970 ;; paste generic and port clause
11971 (when (nth 1 vhdl-port-list)
11972 (insert "\n")
11973 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11974 (insert "\n"))
11975 (indent-to (+ margin vhdl-basic-offset))
11976 (vhdl-port-paste-generic (eq kind 'component)))
11977 (when (nth 2 vhdl-port-list)
11978 (insert "\n")
11979 (when (and (memq vhdl-insert-empty-lines '(unit all))
11980 (eq kind 'entity))
11981 (insert "\n"))
11982 (indent-to (+ margin vhdl-basic-offset)))
11983 (vhdl-port-paste-port)
11984 (insert "\n")
11985 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11986 (insert "\n"))
11987 (indent-to margin)
11988 (vhdl-insert-keyword "END")
11989 (if (eq kind 'entity)
11990 (progn
11991 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11992 (insert " " name))
11993 (vhdl-insert-keyword " COMPONENT")
11994 (unless (vhdl-standard-p '87) (insert " " name)))
11995 (insert ";")))
11997 (defun vhdl-port-paste-entity (&optional no-indent)
11998 "Paste as an entity declaration."
11999 (interactive)
12000 (if (not vhdl-port-list)
12001 (error "ERROR: No port read")
12002 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
12003 (vhdl-port-paste-declaration 'entity no-indent)
12004 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
12006 (defun vhdl-port-paste-component (&optional no-indent)
12007 "Paste as a component declaration."
12008 (interactive)
12009 (if (not vhdl-port-list)
12010 (error "ERROR: No port read")
12011 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
12012 (vhdl-port-paste-declaration 'component no-indent)
12013 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
12015 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
12016 "Paste as a generic map."
12017 (interactive)
12018 (unless secondary (indent-according-to-mode))
12019 (let ((margin (current-indentation))
12020 list-margin start generic
12021 (generic-list (nth 1 vhdl-port-list)))
12022 (when generic-list
12023 (setq start (point))
12024 (vhdl-insert-keyword "GENERIC MAP (")
12025 (if (not vhdl-association-list-with-formals)
12026 ;; paste list of actual generics
12027 (while generic-list
12028 (insert (if no-constants
12029 (car (nth 0 (car generic-list)))
12030 (or (nth 2 (car generic-list)) " ")))
12031 (setq generic-list (cdr generic-list))
12032 (insert (if generic-list ", " ")"))
12033 (when (and (not generic-list) secondary
12034 (null (nth 2 vhdl-port-list)))
12035 (insert ";")))
12036 (unless vhdl-argument-list-indent
12037 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12038 (setq list-margin (current-column))
12039 (while generic-list
12040 (setq generic (car generic-list))
12041 ;; paste group comment and spacing
12042 (when (eq vhdl-include-group-comments 'always)
12043 (vhdl-paste-group-comment (nth 4 generic) list-margin))
12044 ;; paste formal and actual generic
12045 (insert (car (nth 0 generic)) " => "
12046 (if no-constants
12047 (vhdl-replace-string vhdl-actual-generic-name
12048 (car (nth 0 generic)))
12049 (or (nth 2 generic) "")))
12050 (setq generic-list (cdr generic-list))
12051 (insert (if generic-list "," ")"))
12052 (when (and (not generic-list) secondary
12053 (null (nth 2 vhdl-port-list)))
12054 (insert ";"))
12055 ;; paste comment
12056 (when (or vhdl-include-type-comments
12057 (and vhdl-include-port-comments (nth 3 generic)))
12058 (vhdl-comment-insert-inline
12059 (concat
12060 (when vhdl-include-type-comments
12061 (concat "[" (nth 1 generic) "] "))
12062 (when vhdl-include-port-comments (nth 3 generic))) t))
12063 (when generic-list (insert "\n") (indent-to list-margin)))
12064 ;; align generic map
12065 (when vhdl-auto-align
12066 (vhdl-align-region-groups start (point) 1 t))))))
12068 (defun vhdl-port-paste-port-map ()
12069 "Paste as a port map."
12070 (let ((margin (current-indentation))
12071 list-margin start port
12072 (port-list (nth 2 vhdl-port-list)))
12073 (when port-list
12074 (setq start (point))
12075 (vhdl-insert-keyword "PORT MAP (")
12076 (if (not vhdl-association-list-with-formals)
12077 ;; paste list of actual ports
12078 (while port-list
12079 (insert (vhdl-replace-string vhdl-actual-port-name
12080 (car (nth 0 (car port-list)))))
12081 (setq port-list (cdr port-list))
12082 (insert (if port-list ", " ")")))
12083 (unless vhdl-argument-list-indent
12084 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12085 (setq list-margin (current-column))
12086 (while port-list
12087 (setq port (car port-list))
12088 ;; paste group comment and spacing
12089 (when (eq vhdl-include-group-comments 'always)
12090 (vhdl-paste-group-comment (nth 5 port) list-margin))
12091 ;; paste formal and actual port
12092 (insert (car (nth 0 port)) " => ")
12093 (insert (vhdl-replace-string vhdl-actual-port-name
12094 (car (nth 0 port))))
12095 (setq port-list (cdr port-list))
12096 (insert (if port-list "," ");"))
12097 ;; paste comment
12098 (when (or (and vhdl-include-direction-comments (nth 2 port))
12099 vhdl-include-type-comments
12100 (and vhdl-include-port-comments (nth 4 port)))
12101 (vhdl-comment-insert-inline
12102 (concat
12103 (cond ((and vhdl-include-direction-comments
12104 vhdl-include-type-comments)
12105 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
12106 (nth 3 port) "] "))
12107 ((and vhdl-include-direction-comments (nth 2 port))
12108 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12109 (vhdl-include-direction-comments " ")
12110 (vhdl-include-type-comments
12111 (concat "[" (nth 3 port) "] ")))
12112 (when vhdl-include-port-comments (nth 4 port))) t))
12113 (when port-list (insert "\n") (indent-to list-margin)))
12114 ;; align port clause
12115 (when vhdl-auto-align
12116 (vhdl-align-region-groups start (point) 1))))))
12118 (defun vhdl-port-paste-instance (&optional name no-indent title)
12119 "Paste as an instantiation."
12120 (interactive)
12121 (if (not vhdl-port-list)
12122 (error "ERROR: No port read")
12123 (let ((orig-vhdl-port-list vhdl-port-list))
12124 ;; flatten local copy of port list (must be flat for port mapping)
12125 (vhdl-port-flatten)
12126 (unless no-indent (indent-according-to-mode))
12127 (let ((margin (current-indentation)))
12128 ;; paste instantiation
12129 (cond (name
12130 (insert name))
12131 ((equal (cdr vhdl-instance-name) "")
12132 (setq name (vhdl-template-field "instance name")))
12133 ((string-match "\%d" (cdr vhdl-instance-name))
12134 (let ((n 1))
12135 (while (save-excursion
12136 (setq name (format (vhdl-replace-string
12137 vhdl-instance-name
12138 (nth 0 vhdl-port-list)) n))
12139 (goto-char (point-min))
12140 (vhdl-re-search-forward name nil t))
12141 (setq n (1+ n)))
12142 (insert name)))
12143 (t (insert (vhdl-replace-string vhdl-instance-name
12144 (nth 0 vhdl-port-list)))))
12145 (message "Pasting port as instantiation \"%s\"..." name)
12146 (insert ": ")
12147 (when title
12148 (save-excursion
12149 (beginning-of-line)
12150 (indent-to vhdl-basic-offset)
12151 (insert "-- instance \"" name "\"\n")))
12152 (if (not (vhdl-use-direct-instantiation))
12153 (insert (nth 0 vhdl-port-list))
12154 (vhdl-insert-keyword "ENTITY ")
12155 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
12156 (when (nth 1 vhdl-port-list)
12157 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12158 (vhdl-port-paste-generic-map t t))
12159 (when (nth 2 vhdl-port-list)
12160 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
12161 (vhdl-port-paste-port-map))
12162 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
12163 (insert ";"))
12164 (message "Pasting port as instantiation \"%s\"...done" name))
12165 (setq vhdl-port-list orig-vhdl-port-list))))
12167 (defun vhdl-port-paste-constants (&optional no-indent)
12168 "Paste generics as constants."
12169 (interactive)
12170 (if (not vhdl-port-list)
12171 (error "ERROR: No port read")
12172 (let ((orig-vhdl-port-list vhdl-port-list))
12173 (message "Pasting port as constants...")
12174 ;; flatten local copy of port list (must be flat for constant initial.)
12175 (vhdl-port-flatten)
12176 (unless no-indent (indent-according-to-mode))
12177 (let ((margin (current-indentation))
12178 start generic name
12179 (generic-list (nth 1 vhdl-port-list)))
12180 (when generic-list
12181 (setq start (point))
12182 (while generic-list
12183 (setq generic (car generic-list))
12184 ;; paste group comment and spacing
12185 (when (memq vhdl-include-group-comments '(decl always))
12186 (vhdl-paste-group-comment (nth 4 generic) margin))
12187 (vhdl-insert-keyword "CONSTANT ")
12188 ;; paste generic constants
12189 (setq name (nth 0 generic))
12190 (when name
12191 (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
12192 ;; paste type
12193 (insert " : " (nth 1 generic))
12194 ;; paste initialization
12195 (when (nth 2 generic)
12196 (insert " := " (nth 2 generic)))
12197 (insert ";")
12198 ;; paste comment
12199 (when (and vhdl-include-port-comments (nth 3 generic))
12200 (vhdl-comment-insert-inline (nth 3 generic) t))
12201 (setq generic-list (cdr generic-list))
12202 (when generic-list (insert "\n") (indent-to margin))))
12203 ;; align signal list
12204 (when vhdl-auto-align
12205 (vhdl-align-region-groups start (point) 1))))
12206 (message "Pasting port as constants...done")
12207 (setq vhdl-port-list orig-vhdl-port-list))))
12209 (defun vhdl-port-paste-signals (&optional initialize no-indent)
12210 "Paste ports as internal signals."
12211 (interactive)
12212 (if (not vhdl-port-list)
12213 (error "ERROR: No port read")
12214 (message "Pasting port as signals...")
12215 (unless no-indent (indent-according-to-mode))
12216 (let ((margin (current-indentation))
12217 start port names type generic-list port-name constant-name pos
12218 (port-list (nth 2 vhdl-port-list)))
12219 (when port-list
12220 (setq start (point))
12221 (while port-list
12222 (setq port (car port-list))
12223 ;; paste group comment and spacing
12224 (when (memq vhdl-include-group-comments '(decl always))
12225 (vhdl-paste-group-comment (nth 5 port) margin))
12226 ;; paste object
12227 (if (nth 1 port)
12228 (insert (nth 1 port) " ")
12229 (vhdl-insert-keyword "SIGNAL "))
12230 ;; paste actual port signals
12231 (setq names (nth 0 port))
12232 (while names
12233 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
12234 (setq names (cdr names))
12235 (when names (insert ", ")))
12236 ;; paste type
12237 (setq type (nth 3 port))
12238 (setq generic-list (nth 1 vhdl-port-list))
12239 (vhdl-prepare-search-1
12240 (setq pos 0)
12241 ;; replace formal by actual generics
12242 (while generic-list
12243 (setq port-name (car (nth 0 (car generic-list))))
12244 (while (string-match (concat "\\<" port-name "\\>") type pos)
12245 (setq constant-name
12246 (save-match-data (vhdl-replace-string
12247 vhdl-actual-generic-name port-name)))
12248 (setq type (replace-match constant-name t nil type))
12249 (setq pos (match-end 0)))
12250 (setq generic-list (cdr generic-list))))
12251 (insert " : " type)
12252 ;; paste initialization (inputs only)
12253 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
12254 (insert " := "
12255 (cond ((string-match "integer" (nth 3 port)) "0")
12256 ((string-match "natural" (nth 3 port)) "0")
12257 ((string-match "positive" (nth 3 port)) "0")
12258 ((string-match "real" (nth 3 port)) "0.0")
12259 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12260 (t "'0'"))))
12261 (insert ";")
12262 ;; paste comment
12263 (when (or (and vhdl-include-direction-comments (nth 2 port))
12264 (and vhdl-include-port-comments (nth 4 port)))
12265 (vhdl-comment-insert-inline
12266 (concat
12267 (cond ((and vhdl-include-direction-comments (nth 2 port))
12268 (format "%-6s" (concat "[" (nth 2 port) "] ")))
12269 (vhdl-include-direction-comments " "))
12270 (when vhdl-include-port-comments (nth 4 port))) t))
12271 (setq port-list (cdr port-list))
12272 (when port-list (insert "\n") (indent-to margin)))
12273 ;; align signal list
12274 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12275 (message "Pasting port as signals...done")))
12277 (defun vhdl-port-paste-initializations (&optional no-indent)
12278 "Paste ports as signal initializations."
12279 (interactive)
12280 (if (not vhdl-port-list)
12281 (error "ERROR: No port read")
12282 (let ((orig-vhdl-port-list vhdl-port-list))
12283 (message "Pasting port as initializations...")
12284 ;; flatten local copy of port list (must be flat for signal initial.)
12285 (vhdl-port-flatten)
12286 (unless no-indent (indent-according-to-mode))
12287 (let ((margin (current-indentation))
12288 start port name
12289 (port-list (nth 2 vhdl-port-list)))
12290 (when port-list
12291 (setq start (point))
12292 (while port-list
12293 (setq port (car port-list))
12294 ;; paste actual port signal (inputs only)
12295 (when (equal "IN" (upcase (nth 2 port)))
12296 (setq name (car (nth 0 port)))
12297 (insert (vhdl-replace-string vhdl-actual-port-name name))
12298 ;; paste initialization
12299 (insert " <= "
12300 (cond ((string-match "integer" (nth 3 port)) "0")
12301 ((string-match "natural" (nth 3 port)) "0")
12302 ((string-match "positive" (nth 3 port)) "0")
12303 ((string-match "real" (nth 3 port)) "0.0")
12304 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
12305 (t "'0'"))
12306 ";"))
12307 (setq port-list (cdr port-list))
12308 (when (and port-list
12309 (equal "IN" (upcase (nth 2 (car port-list)))))
12310 (insert "\n") (indent-to margin)))
12311 ;; align signal list
12312 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
12313 (message "Pasting port as initializations...done")
12314 (setq vhdl-port-list orig-vhdl-port-list))))
12316 (defun vhdl-port-paste-testbench ()
12317 "Paste as a bare-bones testbench."
12318 (interactive)
12319 (if (not vhdl-port-list)
12320 (error "ERROR: No port read")
12321 (let ((case-fold-search t)
12322 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12323 (nth 0 vhdl-port-list)))
12324 (source-buffer (current-buffer))
12325 arch-name config-name ent-file-name arch-file-name
12326 ent-buffer arch-buffer position)
12327 ;; open entity file
12328 (unless (eq vhdl-testbench-create-files 'none)
12329 (setq ent-file-name
12330 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12331 ent-name t)
12332 "." (file-name-extension (buffer-file-name))))
12333 (if (file-exists-p ent-file-name)
12334 (if (y-or-n-p
12335 (concat "File \"" ent-file-name "\" exists; overwrite? "))
12336 (progn (find-file ent-file-name)
12337 (erase-buffer)
12338 (set-buffer-modified-p nil))
12339 (if (eq vhdl-testbench-create-files 'separate)
12340 (setq ent-file-name nil)
12341 (error "ERROR: Pasting port as testbench...aborted")))
12342 (find-file ent-file-name)))
12343 (unless (and (eq vhdl-testbench-create-files 'separate)
12344 (null ent-file-name))
12345 ;; paste entity header
12346 (if vhdl-testbench-include-header
12347 (progn (vhdl-template-header
12348 (concat "Testbench for design \""
12349 (nth 0 vhdl-port-list) "\""))
12350 (goto-char (point-max)))
12351 (vhdl-comment-display-line) (insert "\n\n"))
12352 ;; paste std_logic_1164 package
12353 (when vhdl-testbench-include-library
12354 (vhdl-template-package-std-logic-1164)
12355 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12356 ;; paste entity declaration
12357 (vhdl-insert-keyword "ENTITY ")
12358 (insert ent-name)
12359 (vhdl-insert-keyword " IS")
12360 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
12361 (insert "\n")
12362 (vhdl-insert-keyword "END ")
12363 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12364 (insert ent-name ";")
12365 (insert "\n\n")
12366 (vhdl-comment-display-line) (insert "\n"))
12367 ;; get architecture name
12368 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
12369 (read-from-minibuffer "architecture name: "
12370 nil vhdl-minibuffer-local-map)
12371 (vhdl-replace-string vhdl-testbench-architecture-name
12372 (nth 0 vhdl-port-list))))
12373 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
12374 ;; open architecture file
12375 (if (not (eq vhdl-testbench-create-files 'separate))
12376 (insert "\n")
12377 (setq ent-buffer (current-buffer))
12378 (setq arch-file-name
12379 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12380 (concat ent-name " " arch-name) t)
12381 "." (file-name-extension (buffer-file-name))))
12382 (when (and (file-exists-p arch-file-name)
12383 (not (y-or-n-p (concat "File \"" arch-file-name
12384 "\" exists; overwrite? "))))
12385 (error "ERROR: Pasting port as testbench...aborted"))
12386 (find-file arch-file-name)
12387 (erase-buffer)
12388 (set-buffer-modified-p nil)
12389 ;; paste architecture header
12390 (if vhdl-testbench-include-header
12391 (progn (vhdl-template-header
12392 (concat "Testbench architecture for design \""
12393 (nth 0 vhdl-port-list) "\""))
12394 (goto-char (point-max)))
12395 (vhdl-comment-display-line) (insert "\n\n")))
12396 ;; paste architecture body
12397 (vhdl-insert-keyword "ARCHITECTURE ")
12398 (insert arch-name)
12399 (vhdl-insert-keyword " OF ")
12400 (insert ent-name)
12401 (vhdl-insert-keyword " IS")
12402 (insert "\n\n") (indent-to vhdl-basic-offset)
12403 ;; paste component declaration
12404 (unless (vhdl-use-direct-instantiation)
12405 (vhdl-port-paste-component t)
12406 (insert "\n\n") (indent-to vhdl-basic-offset))
12407 ;; paste constants
12408 (when (nth 1 vhdl-port-list)
12409 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
12410 (vhdl-port-paste-constants t)
12411 (insert "\n\n") (indent-to vhdl-basic-offset))
12412 ;; paste internal signals
12413 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
12414 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
12415 (insert "\n")
12416 ;; paste custom declarations
12417 (unless (equal "" vhdl-testbench-declarations)
12418 (insert "\n")
12419 (setq position (point))
12420 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12421 (vhdl-indent-region position (point)))
12422 (setq position (point))
12423 (insert "\n\n")
12424 (vhdl-comment-display-line) (insert "\n")
12425 (when vhdl-testbench-include-configuration
12426 (setq config-name (vhdl-replace-string
12427 vhdl-testbench-configuration-name
12428 (concat ent-name " " arch-name)))
12429 (insert "\n")
12430 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12431 (vhdl-insert-keyword " OF ") (insert ent-name)
12432 (vhdl-insert-keyword " IS\n")
12433 (indent-to vhdl-basic-offset)
12434 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12435 (indent-to vhdl-basic-offset)
12436 (vhdl-insert-keyword "END FOR;\n")
12437 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12438 (vhdl-comment-display-line) (insert "\n"))
12439 (goto-char position)
12440 (vhdl-template-begin-end
12441 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12442 ;; paste instantiation
12443 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12444 (vhdl-port-paste-instance
12445 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12446 (insert "\n")
12447 ;; paste custom statements
12448 (unless (equal "" vhdl-testbench-statements)
12449 (insert "\n")
12450 (setq position (point))
12451 (vhdl-insert-string-or-file vhdl-testbench-statements)
12452 (vhdl-indent-region position (point)))
12453 (insert "\n")
12454 (indent-to vhdl-basic-offset)
12455 (unless (eq vhdl-testbench-create-files 'none)
12456 (setq arch-buffer (current-buffer))
12457 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12458 (set-buffer arch-buffer) (save-buffer))
12459 (message "%s"
12460 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12461 ent-name arch-name)
12462 (and ent-file-name
12463 (format "\n File created: \"%s\"" ent-file-name))
12464 (and arch-file-name
12465 (format "\n File created: \"%s\"" arch-file-name)))))))
12468 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12469 ;;; Subprogram interface translation
12470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12472 (defvar vhdl-subprog-list nil
12473 "Variable to hold last subprogram interface parsed.")
12474 ;; structure: (parenthesized expression means list of such entries)
12475 ;; (subprog-name kind
12476 ;; ((names) object direct type init comment group-comment)
12477 ;; return-type return-comment group-comment)
12479 (defvar vhdl-subprog-flattened nil
12480 "Indicates whether an subprogram interface has been flattened.")
12482 (defun vhdl-subprog-flatten ()
12483 "Flatten interface list so that only one parameter exists per line."
12484 (interactive)
12485 (if (not vhdl-subprog-list)
12486 (error "ERROR: No subprogram interface has been read")
12487 (message "Flattening subprogram interface...")
12488 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12489 new-subprog-list old-subprog new-subprog names)
12490 ;; traverse parameter list and flatten entries
12491 (while old-subprog-list
12492 (setq old-subprog (car old-subprog-list))
12493 (setq names (car old-subprog))
12494 (while names
12495 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12496 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12497 (setq names (cdr names)))
12498 (setq old-subprog-list (cdr old-subprog-list)))
12499 (setq vhdl-subprog-list
12500 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12501 new-subprog-list (nth 3 vhdl-subprog-list)
12502 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12503 vhdl-subprog-flattened t)
12504 (message "Flattening subprogram interface...done"))))
12506 (defun vhdl-subprog-copy ()
12507 "Get interface information from a subprogram specification."
12508 (interactive)
12509 (save-excursion
12510 (let (parse-error pos end-of-list
12511 name kind param-list object names direct type init
12512 comment group-comment
12513 return-type return-comment return-group-comment)
12514 (vhdl-prepare-search-2
12515 (setq
12516 parse-error
12517 (catch 'parse
12518 ;; check if within function declaration
12519 (setq pos (point))
12520 (end-of-line)
12521 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12522 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12523 (goto-char (match-end 0))
12524 (save-excursion (backward-char)
12525 (forward-sexp)
12526 (<= pos (point))))
12527 (throw 'parse "ERROR: Not within a subprogram specification"))
12528 (setq name (match-string-no-properties 5))
12529 (setq kind (if (match-string 2) 'procedure 'function))
12530 (setq end-of-list (not (match-string 7)))
12531 (message "Reading interface of subprogram \"%s\"..." name)
12532 ;; parse parameter list
12533 (setq group-comment (vhdl-parse-group-comment))
12534 (setq end-of-list (or end-of-list
12535 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12536 (while (not end-of-list)
12537 ;; parse object
12538 (setq object
12539 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12540 (match-string-no-properties 1)))
12541 ;; parse names (accept extended identifiers)
12542 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12543 (setq names (list (match-string-no-properties 1)))
12544 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12545 (setq names (append names (list (match-string-no-properties 1)))))
12546 ;; parse direction
12547 (vhdl-parse-string ":[ \t\n\r\f]*")
12548 (setq direct
12549 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12550 (match-string-no-properties 1)))
12551 ;; parse type
12552 (vhdl-parse-string "\\([^():;\n]+\\)")
12553 (setq type (match-string-no-properties 1))
12554 (setq comment nil)
12555 (while (looking-at "(")
12556 (setq type
12557 (concat type
12558 (buffer-substring-no-properties
12559 (point) (progn (forward-sexp) (point)))
12560 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12561 (match-string-no-properties 1)))))
12562 ;; special case: closing parenthesis is on separate line
12563 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12564 (setq comment (substring type (match-beginning 2)))
12565 (setq type (substring type 0 (match-beginning 1))))
12566 ;; strip off trailing group-comment
12567 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12568 (setq type (substring type 0 (match-end 1)))
12569 ;; parse initialization expression
12570 (setq init nil)
12571 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12572 (vhdl-parse-string "\\([^();\n]*\\)")
12573 (setq init (match-string-no-properties 1))
12574 (while (looking-at "(")
12575 (setq init
12576 (concat init
12577 (buffer-substring-no-properties
12578 (point) (progn (forward-sexp) (point)))
12579 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12580 (match-string-no-properties 1))))))
12581 ;; special case: closing parenthesis is on separate line
12582 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12583 (setq comment (substring init (match-beginning 2)))
12584 (setq init (substring init 0 (match-beginning 1)))
12585 (vhdl-forward-syntactic-ws))
12586 (skip-chars-forward " \t")
12587 ;; parse inline comment, special case: as above, no initial.
12588 (unless comment
12589 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12590 (match-string-no-properties 1))))
12591 (vhdl-forward-syntactic-ws)
12592 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12593 ;; parse inline comment
12594 (unless comment
12595 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12596 (match-string-no-properties 1))))
12597 (setq return-group-comment (vhdl-parse-group-comment))
12598 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12599 ;; parse return type
12600 (when (match-string 3)
12601 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12602 (setq return-type (match-string-no-properties 1))
12603 (when (and return-type
12604 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12605 (setq return-comment (substring return-type (match-beginning 2)))
12606 (setq return-type (substring return-type 0 (match-beginning 1))))
12607 ;; strip of trailing group-comment
12608 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12609 (setq return-type (substring return-type 0 (match-end 1)))
12610 ;; parse return comment
12611 (unless return-comment
12612 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12613 (match-string-no-properties 1)))))
12614 ;; parse inline comment
12615 (unless comment
12616 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12617 (match-string-no-properties 1))))
12618 ;; save everything in list
12619 (setq param-list (append param-list
12620 (list (list names object direct type init
12621 comment group-comment))))
12622 ;; parse group comment and spacing
12623 (setq group-comment (vhdl-parse-group-comment)))
12624 (message "Reading interface of subprogram \"%s\"...done" name)
12625 nil)))
12626 ;; finish parsing
12627 (if parse-error
12628 (error parse-error)
12629 (setq vhdl-subprog-list
12630 (list name kind param-list return-type return-comment
12631 return-group-comment)
12632 vhdl-subprog-flattened nil)))))
12634 (defun vhdl-subprog-paste-specification (kind)
12635 "Paste as a subprogram specification."
12636 (indent-according-to-mode)
12637 (let ((margin (current-column))
12638 (param-list (nth 2 vhdl-subprog-list))
12639 list-margin start names param)
12640 ;; paste keyword and name
12641 (vhdl-insert-keyword
12642 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12643 (insert (nth 0 vhdl-subprog-list))
12644 (if (not param-list)
12645 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12646 (setq start (point))
12647 ;; paste parameter list
12648 (insert " (")
12649 (unless vhdl-argument-list-indent
12650 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12651 (setq list-margin (current-column))
12652 (while param-list
12653 (setq param (car param-list))
12654 ;; paste group comment and spacing
12655 (when (memq vhdl-include-group-comments (list kind 'always))
12656 (vhdl-paste-group-comment (nth 6 param) list-margin))
12657 ;; paste object
12658 (when (nth 1 param) (insert (nth 1 param) " "))
12659 ;; paste names
12660 (setq names (nth 0 param))
12661 (while names
12662 (insert (car names))
12663 (setq names (cdr names))
12664 (when names (insert ", ")))
12665 ;; paste direction
12666 (insert " : ")
12667 (when (nth 2 param) (insert (nth 2 param) " "))
12668 ;; paste type
12669 (insert (nth 3 param))
12670 ;; paste initialization
12671 (when (nth 4 param) (insert " := " (nth 4 param)))
12672 ;; terminate line
12673 (if (cdr param-list)
12674 (insert ";")
12675 (insert ")")
12676 (when (null (nth 3 vhdl-subprog-list))
12677 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12678 ;; paste comment
12679 (when (and vhdl-include-port-comments (nth 5 param))
12680 (vhdl-comment-insert-inline (nth 5 param) t))
12681 (setq param-list (cdr param-list))
12682 (when param-list (insert "\n") (indent-to list-margin)))
12683 (when (nth 3 vhdl-subprog-list)
12684 (insert "\n") (indent-to list-margin)
12685 ;; paste group comment and spacing
12686 (when (memq vhdl-include-group-comments (list kind 'always))
12687 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12688 ;; paste return type
12689 (insert "return " (nth 3 vhdl-subprog-list))
12690 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12691 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12692 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12693 ;; align parameter list
12694 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12695 ;; paste body
12696 (when (eq kind 'body)
12697 (insert "\n")
12698 (vhdl-template-begin-end
12699 (unless (vhdl-standard-p '87)
12700 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12701 (nth 0 vhdl-subprog-list) margin))))
12703 (defun vhdl-subprog-paste-declaration ()
12704 "Paste as a subprogram declaration."
12705 (interactive)
12706 (if (not vhdl-subprog-list)
12707 (error "ERROR: No subprogram interface read")
12708 (message "Pasting interface as subprogram declaration \"%s\"..."
12709 (car vhdl-subprog-list))
12710 ;; paste specification
12711 (vhdl-subprog-paste-specification 'decl)
12712 (message "Pasting interface as subprogram declaration \"%s\"...done"
12713 (car vhdl-subprog-list))))
12715 (defun vhdl-subprog-paste-body ()
12716 "Paste as a subprogram body."
12717 (interactive)
12718 (if (not vhdl-subprog-list)
12719 (error "ERROR: No subprogram interface read")
12720 (message "Pasting interface as subprogram body \"%s\"..."
12721 (car vhdl-subprog-list))
12722 ;; paste specification and body
12723 (vhdl-subprog-paste-specification 'body)
12724 (message "Pasting interface as subprogram body \"%s\"...done"
12725 (car vhdl-subprog-list))))
12727 (defun vhdl-subprog-paste-call ()
12728 "Paste as a subprogram call."
12729 (interactive)
12730 (if (not vhdl-subprog-list)
12731 (error "ERROR: No subprogram interface read")
12732 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12733 param-list margin list-margin param start)
12734 ;; flatten local copy of interface list (must be flat for parameter mapping)
12735 (vhdl-subprog-flatten)
12736 (setq param-list (nth 2 vhdl-subprog-list))
12737 (indent-according-to-mode)
12738 (setq margin (current-indentation))
12739 (message "Pasting interface as subprogram call \"%s\"..."
12740 (car vhdl-subprog-list))
12741 ;; paste name
12742 (insert (nth 0 vhdl-subprog-list))
12743 (if (not param-list)
12744 (insert ";")
12745 (setq start (point))
12746 ;; paste parameter list
12747 (insert " (")
12748 (unless vhdl-argument-list-indent
12749 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12750 (setq list-margin (current-column))
12751 (while param-list
12752 (setq param (car param-list))
12753 ;; paste group comment and spacing
12754 (when (eq vhdl-include-group-comments 'always)
12755 (vhdl-paste-group-comment (nth 6 param) list-margin))
12756 ;; paste formal port
12757 (insert (car (nth 0 param)) " => ")
12758 (setq param-list (cdr param-list))
12759 (insert (if param-list "," ");"))
12760 ;; paste comment
12761 (when (and vhdl-include-port-comments (nth 5 param))
12762 (vhdl-comment-insert-inline (nth 5 param)))
12763 (when param-list (insert "\n") (indent-to list-margin)))
12764 ;; align parameter list
12765 (when vhdl-auto-align
12766 (vhdl-align-region-groups start (point) 1)))
12767 (message "Pasting interface as subprogram call \"%s\"...done"
12768 (car vhdl-subprog-list))
12769 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12773 ;;; Miscellaneous
12774 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12777 ;; Hippie expand customization
12779 (defvar vhdl-expand-upper-case nil)
12781 (defun vhdl-try-expand-abbrev (old)
12782 "Try expanding abbreviations from `vhdl-abbrev-list'."
12783 (unless old
12784 (he-init-string (he-dabbrev-beg) (point))
12785 (setq he-expand-list
12786 (let ((abbrev-list vhdl-abbrev-list)
12787 (sel-abbrev-list '()))
12788 (while abbrev-list
12789 (when (or (not (stringp (car abbrev-list)))
12790 (string-match
12791 (concat "^" he-search-string) (car abbrev-list)))
12792 (setq sel-abbrev-list
12793 (cons (car abbrev-list) sel-abbrev-list)))
12794 (setq abbrev-list (cdr abbrev-list)))
12795 (nreverse sel-abbrev-list))))
12796 (while (and he-expand-list
12797 (or (not (stringp (car he-expand-list)))
12798 (he-string-member (car he-expand-list) he-tried-table t)))
12799 (unless (stringp (car he-expand-list))
12800 (setq vhdl-expand-upper-case (car he-expand-list)))
12801 (setq he-expand-list (cdr he-expand-list)))
12802 (if (null he-expand-list)
12803 (progn (when old (he-reset-string))
12804 nil)
12805 (he-substitute-string
12806 (if vhdl-expand-upper-case
12807 (upcase (car he-expand-list))
12808 (car he-expand-list))
12810 (setq he-expand-list (cdr he-expand-list))
12813 (defun vhdl-he-list-beg ()
12814 "Also looks at the word before `(' in order to better match parenthesized
12815 expressions (e.g. for index ranges of types and signals)."
12816 (save-excursion
12817 (condition-case ()
12818 (progn (backward-up-list 1)
12819 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12820 (error ()))
12821 (point)))
12823 ;; override `he-list-beg' from `hippie-exp'
12824 (unless (and (boundp 'viper-mode) viper-mode)
12825 (defalias 'he-list-beg 'vhdl-he-list-beg))
12827 ;; function for expanding abbrevs and dabbrevs
12828 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12829 '(try-expand-dabbrev
12830 try-expand-dabbrev-all-buffers
12831 vhdl-try-expand-abbrev)))
12833 ;; function for expanding parenthesis
12834 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12835 '(try-expand-list
12836 try-expand-list-all-buffers)))
12838 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12839 ;; Line handling functions
12841 (defun vhdl-current-line ()
12842 "Return the line number of the line containing point."
12843 (save-restriction
12844 (widen)
12845 (1+ (count-lines (point-min) (point-at-bol)))))
12847 (defun vhdl-line-kill-entire (&optional arg)
12848 "Delete entire line."
12849 (interactive "p")
12850 (beginning-of-line)
12851 (kill-line (or arg 1)))
12853 (defun vhdl-line-kill (&optional arg)
12854 "Kill current line."
12855 (interactive "p")
12856 (vhdl-line-kill-entire arg))
12858 (defun vhdl-line-copy (&optional arg)
12859 "Copy current line."
12860 (interactive "p")
12861 (save-excursion
12862 (let ((position (point-at-bol)))
12863 (forward-line (or arg 1))
12864 (copy-region-as-kill position (point)))))
12866 (defun vhdl-line-yank ()
12867 "Yank entire line."
12868 (interactive)
12869 (beginning-of-line)
12870 (yank))
12872 (defun vhdl-line-expand (&optional prefix-arg)
12873 "Hippie-expand current line."
12874 (interactive "P")
12875 (require 'hippie-exp)
12876 (let ((case-fold-search t) (case-replace nil)
12877 (hippie-expand-try-functions-list
12878 '(try-expand-line try-expand-line-all-buffers)))
12879 (hippie-expand prefix-arg)))
12881 (defun vhdl-line-transpose-next (&optional arg)
12882 "Interchange this line with next line."
12883 (interactive "p")
12884 (forward-line 1)
12885 (transpose-lines (or arg 1))
12886 (forward-line -1))
12888 (defun vhdl-line-transpose-previous (&optional arg)
12889 "Interchange this line with previous line."
12890 (interactive "p")
12891 (forward-line 1)
12892 (transpose-lines (- 0 (or arg 0)))
12893 (forward-line -1))
12895 (defun vhdl-line-open ()
12896 "Open a new line and indent."
12897 (interactive)
12898 (end-of-line -0)
12899 (newline-and-indent))
12901 (defun vhdl-delete-indentation ()
12902 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12903 it works within comments too."
12904 (interactive)
12905 (let ((fill-prefix "-- "))
12906 (delete-indentation)))
12908 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12909 ;; Move functions
12911 (defun vhdl-forward-same-indent ()
12912 "Move forward to next line with same indent."
12913 (interactive)
12914 (let ((pos (point))
12915 (indent (current-indentation)))
12916 (beginning-of-line 2)
12917 (while (and (not (eobp))
12918 (or (looking-at "^\\s-*\\(--.*\\)?$")
12919 (> (current-indentation) indent)))
12920 (beginning-of-line 2))
12921 (if (= (current-indentation) indent)
12922 (back-to-indentation)
12923 (message "No following line with same indent found in this block")
12924 (goto-char pos)
12925 nil)))
12927 (defun vhdl-backward-same-indent ()
12928 "Move backward to previous line with same indent."
12929 (interactive)
12930 (let ((pos (point))
12931 (indent (current-indentation)))
12932 (beginning-of-line -0)
12933 (while (and (not (bobp))
12934 (or (looking-at "^\\s-*\\(--.*\\)?$")
12935 (> (current-indentation) indent)))
12936 (beginning-of-line -0))
12937 (if (= (current-indentation) indent)
12938 (back-to-indentation)
12939 (message "No preceding line with same indent found in this block")
12940 (goto-char pos)
12941 nil)))
12943 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12944 ;; Statistics
12946 (defun vhdl-statistics-buffer ()
12947 "Get some file statistics."
12948 (interactive)
12949 (let ((no-stats 0)
12950 (no-code-lines 0)
12951 (no-empty-lines 0)
12952 (no-comm-lines 0)
12953 (no-comments 0)
12954 (no-lines (count-lines (point-min) (point-max))))
12955 (save-excursion
12956 ;; count statements
12957 (goto-char (point-min))
12958 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12959 (if (match-string 1)
12960 (goto-char (match-end 1))
12961 (setq no-stats (1+ no-stats))))
12962 ;; count code lines
12963 (goto-char (point-min))
12964 (while (not (eobp))
12965 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12966 (setq no-code-lines (1+ no-code-lines)))
12967 (beginning-of-line 2))
12968 ;; count empty lines
12969 (goto-char (point-min))
12970 (while (and (re-search-forward "^\\s-*$" nil t)
12971 (not (eq (point) (point-max))))
12972 (if (match-string 1)
12973 (goto-char (match-end 1))
12974 (setq no-empty-lines (1+ no-empty-lines))
12975 (unless (eq (point) (point-max))
12976 (forward-char))))
12977 ;; count comment-only lines
12978 (goto-char (point-min))
12979 (while (re-search-forward "^\\s-*--.*" nil t)
12980 (if (match-string 1)
12981 (goto-char (match-end 1))
12982 (setq no-comm-lines (1+ no-comm-lines))))
12983 ;; count comments
12984 (goto-char (point-min))
12985 (while (re-search-forward "--.*" nil t)
12986 (if (match-string 1)
12987 (goto-char (match-end 1))
12988 (setq no-comments (1+ no-comments)))))
12989 ;; print results
12990 (message "\n\
12991 File statistics: \"%s\"\n\
12992 -----------------------\n\
12993 # statements : %5d\n\
12994 # code lines : %5d\n\
12995 # empty lines : %5d\n\
12996 # comment lines : %5d\n\
12997 # comments : %5d\n\
12998 # total lines : %5d\n\ "
12999 (buffer-file-name) no-stats no-code-lines no-empty-lines
13000 no-comm-lines no-comments no-lines)
13001 (unless vhdl-emacs-21 (vhdl-show-messages))))
13003 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13004 ;; Help functions
13006 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
13007 "Like `re-search-forward', but does not match within literals."
13008 (let (pos)
13009 (save-excursion
13010 (while (and (setq pos (re-search-forward regexp bound noerror count))
13011 (vhdl-in-literal))))
13012 (when pos (goto-char pos))
13013 pos))
13015 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
13016 "Like `re-search-backward', but does not match within literals."
13017 (let (pos)
13018 (save-excursion
13019 (while (and (setq pos (re-search-backward regexp bound noerror count))
13020 (vhdl-in-literal))))
13021 (when pos (goto-char pos))
13022 pos))
13025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13026 ;;; Project
13027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13029 (defun vhdl-set-project (name)
13030 "Set current project to NAME."
13031 (interactive
13032 (list (let ((completion-ignore-case t))
13033 (completing-read "Project name: " vhdl-project-alist nil t))))
13034 (cond ((equal name "")
13035 (setq vhdl-project nil)
13036 (message "Current VHDL project: None"))
13037 ((assoc name vhdl-project-alist)
13038 (setq vhdl-project name)
13039 (message "Current VHDL project: \"%s\"" name))
13041 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
13042 (vhdl-speedbar-update-current-project))
13044 (defun vhdl-set-default-project ()
13045 "Set current project as default on startup."
13046 (interactive)
13047 (customize-set-variable 'vhdl-project vhdl-project)
13048 (customize-save-customized))
13050 (defun vhdl-toggle-project (name token indent)
13051 "Set current project to NAME or unset if NAME is current project."
13052 (vhdl-set-project (if (equal name vhdl-project) "" name)))
13054 (defun vhdl-export-project (file-name)
13055 "Write project setup for current project."
13056 (interactive
13057 (let ((name (vhdl-resolve-env-variable
13058 (vhdl-replace-string
13059 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13060 (concat (subst-char-in-string
13061 ? ?_ (or (vhdl-project-p)
13062 (error "ERROR: No current project")))
13063 " " (user-login-name))))))
13064 (list (read-file-name
13065 "Write project file: "
13066 (when (file-name-absolute-p name) "") nil nil name))))
13067 (setq file-name (abbreviate-file-name file-name))
13068 (let ((orig-buffer (current-buffer)))
13069 (unless (file-exists-p (file-name-directory file-name))
13070 (make-directory (file-name-directory file-name) t))
13071 (if (not (file-writable-p file-name))
13072 (error "ERROR: File not writable: \"%s\"" file-name)
13073 (set-buffer (find-file-noselect file-name t t))
13074 (erase-buffer)
13075 (insert ";; -*- Emacs-Lisp -*-\n\n"
13076 ";;; " (file-name-nondirectory file-name)
13077 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
13078 ";; Project : " vhdl-project "\n"
13079 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
13080 (user-login-name) "\n\n\n"
13081 ";; project name\n"
13082 "(setq vhdl-project \"" vhdl-project "\")\n\n"
13083 ";; project setup\n"
13084 "(vhdl-aput 'vhdl-project-alist vhdl-project\n'")
13085 (pp (vhdl-aget vhdl-project-alist vhdl-project) (current-buffer))
13086 (insert ")\n")
13087 (save-buffer)
13088 (kill-buffer (current-buffer))
13089 (set-buffer orig-buffer))))
13091 (defun vhdl-import-project (file-name &optional auto not-make-current)
13092 "Read project setup and set current project."
13093 (interactive
13094 (let ((name (vhdl-resolve-env-variable
13095 (vhdl-replace-string
13096 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
13097 (concat "" " " (user-login-name))))))
13098 (list (read-file-name
13099 "Read project file: " (when (file-name-absolute-p name) "") nil t
13100 (file-name-directory name)))))
13101 (when (file-exists-p file-name)
13102 (condition-case ()
13103 (let ((current-project vhdl-project))
13104 (load-file file-name)
13105 (when (/= (length (vhdl-aget vhdl-project-alist vhdl-project)) 10)
13106 (vhdl-adelete 'vhdl-project-alist vhdl-project)
13107 (error ""))
13108 (if not-make-current
13109 (setq vhdl-project current-project)
13110 (setq vhdl-compiler
13111 (caar (nth 4 (vhdl-aget vhdl-project-alist vhdl-project)))))
13112 (vhdl-update-mode-menu)
13113 (vhdl-speedbar-refresh)
13114 (unless not-make-current
13115 (message "Current VHDL project: \"%s\"; compiler: \"%s\"%s"
13116 vhdl-project vhdl-compiler (if auto " (auto-loaded)" ""))))
13117 (error (vhdl-warning
13118 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
13120 (defun vhdl-duplicate-project ()
13121 "Duplicate setup of current project."
13122 (interactive)
13123 (let ((new-name (read-from-minibuffer "New project name: "))
13124 (project-entry (vhdl-aget vhdl-project-alist vhdl-project)))
13125 (setq vhdl-project-alist
13126 (append vhdl-project-alist
13127 (list (cons new-name project-entry))))
13128 (vhdl-update-mode-menu)))
13130 (defun vhdl-auto-load-project ()
13131 "Automatically load project setup at startup."
13132 (let ((file-name-list vhdl-project-file-name)
13133 file-list list-length)
13134 (while file-name-list
13135 (setq file-list
13136 (append file-list
13137 (file-expand-wildcards
13138 (vhdl-resolve-env-variable
13139 (vhdl-replace-string
13140 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
13141 (concat "\*" " " (user-login-name)))))))
13142 (setq list-length (or list-length (length file-list)))
13143 (setq file-name-list (cdr file-name-list)))
13144 (while file-list
13145 (vhdl-import-project (expand-file-name (car file-list)) t
13146 (not (> list-length 0)))
13147 (setq list-length (1- list-length))
13148 (setq file-list (cdr file-list)))))
13150 ;; automatically load project setup when idle after startup
13151 (when (memq 'startup vhdl-project-auto-load)
13152 (if noninteractive
13153 (vhdl-auto-load-project)
13154 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
13157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13158 ;;; Hideshow
13159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13160 ;; (using `hideshow.el')
13162 (defconst vhdl-hs-start-regexp
13163 (concat
13164 "\\(^\\)\\s-*\\("
13165 ;; generic/port clause
13166 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
13167 ;; component
13168 "component\\>\\|"
13169 ;; component instantiation
13170 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
13171 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13172 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
13173 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
13174 ;; subprogram
13175 "\\(function\\|procedure\\)\\>\\|"
13176 ;; process, block
13177 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13178 ;; configuration declaration
13179 "configuration\\>"
13180 "\\)")
13181 "Regexp to match start of construct to hide.")
13183 (defun vhdl-hs-forward-sexp-func (count)
13184 "Find end of construct to hide (for hideshow). Only searches forward."
13185 (let ((pos (point)))
13186 (vhdl-prepare-search-2
13187 (beginning-of-line)
13188 (cond
13189 ;; generic/port clause
13190 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13191 (goto-char (match-end 0))
13192 (backward-char)
13193 (forward-sexp))
13194 ;; component declaration
13195 ((looking-at "^\\s-*component\\>")
13196 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
13197 ;; component instantiation
13198 ((looking-at
13199 (concat
13200 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13201 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13202 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13203 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13204 (goto-char (match-end 0))
13205 (backward-char)
13206 (forward-sexp)
13207 (setq pos (point))
13208 (vhdl-forward-syntactic-ws)
13209 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13210 (goto-char (match-end 0))
13211 (backward-char)
13212 (forward-sexp)
13213 (setq pos (point)))
13214 (goto-char pos))
13215 ;; subprogram declaration/body
13216 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13217 (goto-char (match-end 0))
13218 (vhdl-forward-syntactic-ws)
13219 (when (looking-at "(")
13220 (forward-sexp))
13221 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
13222 (vhdl-in-literal)))
13223 ;; subprogram body
13224 (when (match-string 2)
13225 (re-search-forward "^\\s-*\\<begin\\>" nil t)
13226 (backward-word 1)
13227 (vhdl-forward-sexp)))
13228 ;; block (recursive)
13229 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13230 (goto-char (match-end 0))
13231 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
13232 (match-beginning 2))
13233 (vhdl-hs-forward-sexp-func count)))
13234 ;; process
13235 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13236 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
13237 ;; configuration declaration
13238 ((looking-at "^\\s-*configuration\\>")
13239 (forward-word 4)
13240 (vhdl-forward-sexp))
13241 (t (goto-char pos))))))
13243 (defun vhdl-hideshow-init ()
13244 "Initialize `hideshow'."
13245 (when vhdl-hideshow-menu
13246 (vhdl-hs-minor-mode 1)))
13248 (defun vhdl-hs-minor-mode (&optional arg)
13249 "Toggle hideshow minor mode and update menu bar."
13250 (interactive "P")
13251 (require 'hideshow)
13252 ;; check for hideshow version 5.x
13253 (if (not (boundp 'hs-block-start-mdata-select))
13254 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13255 ;; initialize hideshow
13256 (unless (assoc 'vhdl-mode hs-special-modes-alist)
13257 (setq hs-special-modes-alist
13258 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
13259 'vhdl-hs-forward-sexp-func nil)
13260 hs-special-modes-alist)))
13261 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
13262 (if vhdl-hide-all-init
13263 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
13264 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
13265 (hs-minor-mode arg)
13266 (force-mode-line-update))) ; hack to update menu bar
13269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13270 ;;; Font locking
13271 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13272 ;; (using `font-lock.el')
13274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13275 ;; Help functions
13277 (defun vhdl-within-translate-off ()
13278 "Return point if within translate-off region, else nil."
13279 (and (save-excursion
13280 (re-search-backward
13281 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
13282 (equal "off" (match-string 1))
13283 (point)))
13285 (defun vhdl-start-translate-off (limit)
13286 "Return point before translate-off pragma if before LIMIT, else nil."
13287 (when (re-search-forward
13288 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
13289 (match-beginning 0)))
13291 (defun vhdl-end-translate-off (limit)
13292 "Return point after translate-on pragma if before LIMIT, else nil."
13293 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
13295 (defun vhdl-match-translate-off (limit)
13296 "Match a translate-off block, setting match-data and returning t, else nil."
13297 (when (< (point) limit)
13298 (let ((start (or (vhdl-within-translate-off)
13299 (vhdl-start-translate-off limit)))
13300 (case-fold-search t))
13301 (when start
13302 (let ((end (or (vhdl-end-translate-off limit) limit)))
13303 (set-match-data (list start end))
13304 (goto-char end))))))
13306 (defun vhdl-font-lock-match-item (limit)
13307 "Match, and move over, any declaration item after point. Adapted from
13308 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13309 (condition-case nil
13310 (save-restriction
13311 (narrow-to-region (point-min) limit)
13312 ;; match item
13313 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13314 (save-match-data
13315 (goto-char (match-end 1))
13316 ;; move to next item
13317 (if (looking-at "\\(\\s-*,\\)")
13318 (goto-char (match-end 1))
13319 (end-of-line) t))))
13320 (error t)))
13322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13323 ;; Syntax definitions
13325 (defconst vhdl-font-lock-syntactic-keywords
13326 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
13327 "Mark single quotes as having string quote syntax in 'c' instances.")
13329 (defvar vhdl-font-lock-keywords nil
13330 "Regular expressions to highlight in VHDL Mode.")
13332 (defvar vhdl-font-lock-keywords-0
13333 ;; set in `vhdl-font-lock-init' because dependent on user options
13334 "For consideration as a value of `vhdl-font-lock-keywords'.
13335 This does highlighting of template prompts and directives (pragmas).")
13337 (defvar vhdl-font-lock-keywords-1 nil
13338 ;; set in `vhdl-font-lock-init' because dependent on user options
13339 "For consideration as a value of `vhdl-font-lock-keywords'.
13340 This does highlighting of keywords and standard identifiers.")
13342 (defconst vhdl-font-lock-keywords-2
13343 (list
13344 ;; highlight names of units, subprograms, and components when declared
13345 (list
13346 (concat
13347 "^\\s-*\\("
13348 "architecture\\|configuration\\|context\\|entity\\|package"
13349 "\\(\\s-+body\\)?\\|"
13350 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13351 "\\)\\s-+\\(\\w+\\)")
13352 5 'font-lock-function-name-face)
13354 ;; highlight entity names of architectures and configurations
13355 (list
13356 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13357 2 'font-lock-function-name-face)
13359 ;; highlight labels of common constructs
13360 (list
13361 (concat
13362 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13363 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13364 "postponed\\|process\\|"
13365 (when (vhdl-standard-p 'ams) "procedural\\|")
13366 "with\\|while"
13367 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13368 1 'font-lock-function-name-face)
13370 ;; highlight label and component name of component instantiations
13371 (list
13372 (concat
13373 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13374 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13375 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13377 ;; highlight label and instantiated unit of component instantiations
13378 (list
13379 (concat
13380 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13381 "\\(component\\|configuration\\|entity\\)\\s-+"
13382 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13383 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13384 '(5 font-lock-function-name-face nil t)
13385 '(7 font-lock-function-name-face nil t))
13387 ;; highlight names and labels at end of constructs
13388 (list
13389 (concat
13390 "^\\s-*end\\s-+\\(\\("
13391 "architecture\\|block\\|case\\|component\\|configuration\\|context\\|"
13392 "entity\\|for\\|function\\|generate\\|if\\|loop\\|package"
13393 "\\(\\s-+body\\)?\\|procedure\\|\\(postponed\\s-+\\)?process\\|"
13394 (when (vhdl-standard-p 'ams) "procedural\\|")
13395 "units"
13396 "\\)\\s-+\\)?\\(\\w*\\)")
13397 5 'font-lock-function-name-face)
13399 ;; highlight labels in exit and next statements
13400 (list
13401 (concat
13402 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13403 3 'font-lock-function-name-face)
13405 ;; highlight entity name in attribute specifications
13406 (list
13407 (concat
13408 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13409 1 'font-lock-function-name-face)
13411 ;; highlight labels in block and component specifications
13412 (list
13413 (concat
13414 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13415 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13416 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13418 ;; highlight names in library clauses
13419 (list "^\\s-*library\\>"
13420 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13422 ;; highlight names in use clauses
13423 (list
13424 (concat
13425 "\\<\\(context\\|use\\)\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13426 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13427 '(4 font-lock-function-name-face) '(6 font-lock-function-name-face nil t)
13428 '(8 font-lock-function-name-face nil t))
13430 ;; highlight attribute name in attribute declarations/specifications
13431 (list
13432 (concat
13433 "^\\s-*attribute\\s-+\\(\\w+\\)")
13434 1 'vhdl-font-lock-attribute-face)
13436 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13437 (list
13438 (concat
13439 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13440 5 'font-lock-type-face)
13442 ;; highlight signal/variable/constant declaration names
13443 (list "\\(:[^=]\\)"
13444 '(vhdl-font-lock-match-item
13445 (progn (goto-char (match-beginning 1))
13446 (skip-syntax-backward " ")
13447 (skip-syntax-backward "w_")
13448 (skip-syntax-backward " ")
13449 (while (= (preceding-char) ?,)
13450 (backward-char 1)
13451 (skip-syntax-backward " ")
13452 (skip-syntax-backward "w_")
13453 (skip-syntax-backward " ")))
13454 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13456 ;; highlight formal parameters in component instantiations and subprogram
13457 ;; calls
13458 (list "\\(=>\\)"
13459 '(vhdl-font-lock-match-item
13460 (progn (goto-char (match-beginning 1))
13461 (skip-syntax-backward " ")
13462 (while (= (preceding-char) ?\)) (backward-sexp))
13463 (skip-syntax-backward "w_")
13464 (skip-syntax-backward " ")
13465 (when (memq (preceding-char) '(?n ?N ?|))
13466 (goto-char (point-max))))
13467 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13469 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13470 ;; variables
13471 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13472 '(vhdl-font-lock-match-item
13473 (progn (goto-char (match-end 1)) (match-beginning 2))
13474 nil (1 font-lock-variable-name-face)))
13476 ;; highlight tool directives
13477 (list
13478 (concat
13479 "^\\s-*\\(`\\w+\\)")
13480 1 'font-lock-preprocessor-face)
13482 "For consideration as a value of `vhdl-font-lock-keywords'.
13483 This does context sensitive highlighting of names and labels.")
13485 (defvar vhdl-font-lock-keywords-3 nil
13486 ;; set in `vhdl-font-lock-init' because dependent on user options
13487 "For consideration as a value of `vhdl-font-lock-keywords'.
13488 This does highlighting of words with special syntax.")
13490 (defvar vhdl-font-lock-keywords-4 nil
13491 ;; set in `vhdl-font-lock-init' because dependent on user options
13492 "For consideration as a value of `vhdl-font-lock-keywords'.
13493 This does highlighting of additional reserved words.")
13495 (defconst vhdl-font-lock-keywords-5
13496 ;; background highlight translate-off regions
13497 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13498 "For consideration as a value of `vhdl-font-lock-keywords'.
13499 This does background highlighting of translate-off regions.")
13501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13502 ;; Font and color definitions
13504 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13505 "Face name to use for prompts.")
13507 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13508 "Face name to use for standardized attributes.")
13510 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13511 "Face name to use for standardized enumeration values.")
13513 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13514 "Face name to use for standardized functions and packages.")
13516 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13517 "Face name to use for directives.")
13519 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13520 "Face name to use for additional reserved words.")
13522 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13523 "Face name to use for translate-off regions.")
13525 ;; face names to use for words with special syntax.
13526 (let ((syntax-alist vhdl-special-syntax-alist)
13527 name)
13528 (while syntax-alist
13529 (setq name (vhdl-function-name
13530 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13531 (eval `(defvar ,name ',name
13532 ,(concat "Face name to use for "
13533 (nth 0 (car syntax-alist)) ".")))
13534 (setq syntax-alist (cdr syntax-alist))))
13536 (defgroup vhdl-highlight-faces nil
13537 "Faces for highlighting."
13538 :group 'vhdl-highlight)
13540 ;; add faces used from `font-lock'
13541 (custom-add-to-group
13542 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13543 (custom-add-to-group
13544 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13545 (custom-add-to-group
13546 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13547 (custom-add-to-group
13548 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13549 (custom-add-to-group
13550 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13551 (custom-add-to-group
13552 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13554 (defface vhdl-font-lock-prompt-face
13555 '((((min-colors 88) (class color) (background light))
13556 (:foreground "Red1" :bold t))
13557 (((class color) (background light)) (:foreground "Red" :bold t))
13558 (((class color) (background dark)) (:foreground "Pink" :bold t))
13559 (t (:inverse-video t)))
13560 "Font lock mode face used to highlight prompts."
13561 :group 'vhdl-highlight-faces)
13563 (defface vhdl-font-lock-attribute-face
13564 '((((class color) (background light)) (:foreground "Orchid"))
13565 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13566 (t (:italic t :bold t)))
13567 "Font lock mode face used to highlight standardized attributes."
13568 :group 'vhdl-highlight-faces)
13570 (defface vhdl-font-lock-enumvalue-face
13571 '((((class color) (background light)) (:foreground "SaddleBrown"))
13572 (((class color) (background dark)) (:foreground "BurlyWood"))
13573 (t (:italic t :bold t)))
13574 "Font lock mode face used to highlight standardized enumeration values."
13575 :group 'vhdl-highlight-faces)
13577 (defface vhdl-font-lock-function-face
13578 '((((class color) (background light)) (:foreground "Cyan4"))
13579 (((class color) (background dark)) (:foreground "Orchid1"))
13580 (t (:italic t :bold t)))
13581 "Font lock mode face used to highlight standardized functions and packages."
13582 :group 'vhdl-highlight-faces)
13584 (defface vhdl-font-lock-directive-face
13585 '((((class color) (background light)) (:foreground "CadetBlue"))
13586 (((class color) (background dark)) (:foreground "Aquamarine"))
13587 (t (:italic t :bold t)))
13588 "Font lock mode face used to highlight directives."
13589 :group 'vhdl-highlight-faces)
13591 (defface vhdl-font-lock-reserved-words-face
13592 '((((class color) (background light)) (:foreground "Orange" :bold t))
13593 (((min-colors 88) (class color) (background dark))
13594 (:foreground "Yellow1" :bold t))
13595 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13596 (t ()))
13597 "Font lock mode face used to highlight additional reserved words."
13598 :group 'vhdl-highlight-faces)
13600 (defface vhdl-font-lock-translate-off-face
13601 '((((class color) (background light)) (:background "LightGray"))
13602 (((class color) (background dark)) (:background "DimGray"))
13603 (t ()))
13604 "Font lock mode face used to background highlight translate-off regions."
13605 :group 'vhdl-highlight-faces)
13607 ;; font lock mode faces used to highlight words with special syntax.
13608 (let ((syntax-alist vhdl-special-syntax-alist))
13609 (while syntax-alist
13610 (eval `(defface ,(vhdl-function-name
13611 "vhdl-font-lock" (caar syntax-alist) "face")
13612 '((((class color) (background light))
13613 (:foreground ,(nth 2 (car syntax-alist))))
13614 (((class color) (background dark))
13615 (:foreground ,(nth 3 (car syntax-alist))))
13616 (t ()))
13617 ,(concat "Font lock mode face used to highlight "
13618 (nth 0 (car syntax-alist)) ".")
13619 :group 'vhdl-highlight-faces))
13620 (setq syntax-alist (cdr syntax-alist))))
13622 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13623 ;; Font lock initialization
13625 (defun vhdl-font-lock-init ()
13626 "Initialize fontification."
13627 ;; highlight template prompts and directives
13628 (setq vhdl-font-lock-keywords-0
13629 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13630 vhdl-template-prompt-syntax ">\\)")
13631 2 'vhdl-font-lock-prompt-face t)
13632 (list (concat "--\\s-*"
13633 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13634 2 'vhdl-font-lock-directive-face t)
13635 ;; highlight c-preprocessor directives
13636 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13637 '(1 font-lock-builtin-face)
13638 '(3 font-lock-variable-name-face nil t))))
13639 ;; highlight keywords and standardized types, attributes, enumeration
13640 ;; values, and subprograms
13641 (setq vhdl-font-lock-keywords-1
13642 (list
13643 (list (concat "'" vhdl-attributes-regexp)
13644 1 'vhdl-font-lock-attribute-face)
13645 (list vhdl-types-regexp 1 'font-lock-type-face)
13646 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13647 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13648 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13649 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13650 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13651 ;; highlight words with special syntax.
13652 (setq vhdl-font-lock-keywords-3
13653 (let ((syntax-alist vhdl-special-syntax-alist)
13654 keywords)
13655 (while syntax-alist
13656 (setq keywords
13657 (cons
13658 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13659 (vhdl-function-name
13660 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13661 (nth 4 (car syntax-alist)))
13662 keywords))
13663 (setq syntax-alist (cdr syntax-alist)))
13664 keywords))
13665 ;; highlight additional reserved words
13666 (setq vhdl-font-lock-keywords-4
13667 (list (list vhdl-reserved-words-regexp 1
13668 'vhdl-font-lock-reserved-words-face)))
13669 ;; highlight everything together
13670 (setq vhdl-font-lock-keywords
13671 (append
13672 vhdl-font-lock-keywords-0
13673 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13674 (when (or vhdl-highlight-forbidden-words
13675 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13676 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13677 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13678 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13680 ;; initialize fontification for VHDL Mode
13681 (vhdl-font-lock-init)
13683 (defun vhdl-fontify-buffer ()
13684 "Re-initialize fontification and fontify buffer."
13685 (interactive)
13686 (setq font-lock-defaults
13687 `(vhdl-font-lock-keywords
13688 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13689 beginning-of-line))
13690 (when (fboundp 'font-lock-unset-defaults)
13691 (font-lock-unset-defaults)) ; not implemented in XEmacs
13692 (font-lock-set-defaults)
13693 (font-lock-mode nil)
13694 (font-lock-mode t))
13696 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13697 ;; Initialization for PostScript printing
13699 (defun vhdl-ps-print-settings ()
13700 "Initialize custom face and page settings for PostScript printing."
13701 ;; define custom face settings
13702 (unless (or (not vhdl-print-customize-faces)
13703 ps-print-color-p)
13704 (set (make-local-variable 'ps-bold-faces)
13705 '(font-lock-keyword-face
13706 font-lock-type-face
13707 vhdl-font-lock-attribute-face
13708 vhdl-font-lock-enumvalue-face
13709 vhdl-font-lock-directive-face))
13710 (set (make-local-variable 'ps-italic-faces)
13711 '(font-lock-comment-face
13712 font-lock-function-name-face
13713 font-lock-type-face
13714 vhdl-font-lock-attribute-face
13715 vhdl-font-lock-enumvalue-face
13716 vhdl-font-lock-directive-face))
13717 (set (make-local-variable 'ps-underlined-faces)
13718 '(font-lock-string-face))
13719 (setq ps-always-build-face-reference t))
13720 ;; define page settings, so that a line containing 79 characters (default)
13721 ;; fits into one column
13722 (when vhdl-print-two-column
13723 (set (make-local-variable 'ps-landscape-mode) t)
13724 (set (make-local-variable 'ps-number-of-columns) 2)
13725 (set (make-local-variable 'ps-font-size) 7.0)
13726 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13727 (set (make-local-variable 'ps-header-font-size) 9.0)
13728 (set (make-local-variable 'ps-header-offset) 12.0)
13729 (when (eq ps-paper-type 'letter)
13730 (set (make-local-variable 'ps-inter-column) 40.0)
13731 (set (make-local-variable 'ps-left-margin) 40.0)
13732 (set (make-local-variable 'ps-right-margin) 40.0))))
13734 (defun vhdl-ps-print-init ()
13735 "Initialize PostScript printing."
13736 (if (featurep 'xemacs)
13737 (when (boundp 'ps-print-color-p)
13738 (vhdl-ps-print-settings))
13739 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13740 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13744 ;;; Hierarchy browser (using `speedbar.el')
13745 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13746 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13747 ;; directory by using the speedbar.
13749 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13750 ;; Variables
13752 (defvar vhdl-entity-alist nil
13753 "Cache with entities and corresponding architectures for each
13754 project/directory.")
13755 ;; structure: (parenthesized expression means list of such entries)
13756 ;; (cache-key
13757 ;; (ent-key ent-name ent-file ent-line
13758 ;; (arch-key arch-name arch-file arch-line
13759 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13760 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13761 ;; (lib-name pack-key))
13762 ;; mra-key (lib-name pack-key))
13764 (defvar vhdl-config-alist nil
13765 "Cache with configurations for each project/directory.")
13766 ;; structure: (parenthesized expression means list of such entries)
13767 ;; (cache-key
13768 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13769 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13770 ;; inst-conf-key inst-lib-key)
13771 ;; (lib-name pack-key)))
13773 (defvar vhdl-package-alist nil
13774 "Cache with packages for each project/directory.")
13775 ;; structure: (parenthesized expression means list of such entries)
13776 ;; (cache-key
13777 ;; (pack-key pack-name pack-file pack-line
13778 ;; (comp-key comp-name comp-file comp-line)
13779 ;; (func-key func-name func-file func-line)
13780 ;; (lib-name pack-key)
13781 ;; pack-body-file pack-body-line
13782 ;; (func-key func-name func-body-file func-body-line)
13783 ;; (lib-name pack-key)))
13785 (defvar vhdl-ent-inst-alist nil
13786 "Cache with instantiated entities for each project/directory.")
13787 ;; structure: (parenthesized expression means list of such entries)
13788 ;; (cache-key (inst-ent-key))
13790 (defvar vhdl-file-alist nil
13791 "Cache with design units in each file for each project/directory.")
13792 ;; structure: (parenthesized expression means list of such entries)
13793 ;; (cache-key
13794 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13795 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13797 (defvar vhdl-directory-alist nil
13798 "Cache with source directories for each project.")
13799 ;; structure: (parenthesized expression means list of such entries)
13800 ;; (cache-key (directory))
13802 (defvar vhdl-speedbar-shown-unit-alist nil
13803 "Alist of design units simultaneously open in the current speedbar for each
13804 directory and project.")
13806 (defvar vhdl-speedbar-shown-project-list nil
13807 "List of projects simultaneously open in the current speedbar.")
13809 (defvar vhdl-updated-project-list nil
13810 "List of projects and directories with updated files.")
13812 (defvar vhdl-modified-file-list nil
13813 "List of modified files to be rescanned for hierarchy updating.")
13815 (defvar vhdl-speedbar-hierarchy-depth 0
13816 "Depth of instantiation hierarchy to display.")
13818 (defvar vhdl-speedbar-show-projects nil
13819 "Non-nil means project hierarchy is displayed in speedbar, directory
13820 hierarchy otherwise.")
13822 (defun vhdl-get-end-of-unit ()
13823 "Return position of end of current unit."
13824 (let ((pos (point)))
13825 (save-excursion
13826 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil 1)
13827 (save-excursion
13828 (goto-char (match-beginning 0))
13829 (vhdl-backward-syntactic-ws)
13830 (and (/= (preceding-char) ?\;) (not (bobp))))))
13831 (re-search-backward "^[ \t]*end\\>" pos 1)
13832 (point))))
13834 (defun vhdl-match-string-downcase (num &optional string)
13835 "Like `match-string-no-properties' with down-casing."
13836 (let ((match (match-string-no-properties num string)))
13837 (and match (downcase match))))
13840 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13841 ;; Scan functions
13843 (defun vhdl-scan-context-clause ()
13844 "Scan the context clause that precedes a design unit."
13845 (let (lib-alist)
13846 (save-excursion
13847 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil t)
13848 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13849 (equal "USE" (upcase (match-string 1))))
13850 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13851 (push (cons (match-string-no-properties 1)
13852 (vhdl-match-string-downcase 2))
13853 lib-alist)))))
13854 lib-alist))
13856 (defun vhdl-scan-directory-contents (name &optional project update num-string
13857 non-final)
13858 "Scan contents of VHDL files in directory or file pattern NAME."
13859 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13860 (let* ((dir-name (match-string 1 name))
13861 (file-pattern (match-string 2 name))
13862 (is-directory (= 0 (length file-pattern)))
13863 (file-list
13864 (if update
13865 (list name)
13866 (if is-directory
13867 (vhdl-get-source-files t dir-name)
13868 (vhdl-directory-files
13869 dir-name t (wildcard-to-regexp file-pattern)))))
13870 (key (or project dir-name))
13871 (file-exclude-regexp
13872 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
13873 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13874 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13875 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13876 ent-alist conf-alist pack-alist ent-inst-list file-alist
13877 tmp-list tmp-entry no-files files-exist big-files)
13878 (when (or project update)
13879 (setq ent-alist (vhdl-aget vhdl-entity-alist key)
13880 conf-alist (vhdl-aget vhdl-config-alist key)
13881 pack-alist (vhdl-aget vhdl-package-alist key)
13882 ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist key))
13883 file-alist (vhdl-aget vhdl-file-alist key)))
13884 (when (and (not is-directory) (null file-list))
13885 (message "No such file: \"%s\"" name))
13886 (setq files-exist file-list)
13887 (when file-list
13888 (setq no-files (length file-list))
13889 (message "Scanning %s %s\"%s\"..."
13890 (if is-directory "directory" "files") (or num-string "") name)
13891 ;; exclude files
13892 (unless (equal file-exclude-regexp "")
13893 (let ((case-fold-search nil)
13894 file-tmp-list)
13895 (while file-list
13896 (unless (string-match file-exclude-regexp (car file-list))
13897 (push (car file-list) file-tmp-list))
13898 (setq file-list (cdr file-list)))
13899 (setq file-list (nreverse file-tmp-list))))
13900 ;; do for all files
13901 (while file-list
13902 (unless noninteractive
13903 (message "Scanning %s %s\"%s\"... (%2d%s)"
13904 (if is-directory "directory" "files")
13905 (or num-string "") name
13906 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13907 (let ((file-name (abbreviate-file-name (car file-list)))
13908 ent-list arch-list arch-ent-list conf-list
13909 pack-list pack-body-list inst-list inst-ent-list)
13910 ;; scan file
13911 (vhdl-visit-file
13912 file-name nil
13913 (vhdl-prepare-search-2
13914 (save-excursion
13915 ;; scan for design units
13916 (if (and limit-design-file-size
13917 (< limit-design-file-size (buffer-size)))
13918 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13919 (setq big-files t))
13920 ;; scan for entities
13921 (goto-char (point-min))
13922 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13923 (let* ((ent-name (match-string-no-properties 1))
13924 (ent-key (downcase ent-name))
13925 (ent-entry (vhdl-aget ent-alist ent-key))
13926 (lib-alist (vhdl-scan-context-clause)))
13927 (if (nth 1 ent-entry)
13928 (vhdl-warning-when-idle
13929 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13930 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13931 file-name (vhdl-current-line))
13932 (push ent-key ent-list)
13933 (vhdl-aput 'ent-alist ent-key
13934 (list ent-name file-name (vhdl-current-line)
13935 (nth 3 ent-entry) (nth 4 ent-entry)
13936 lib-alist)))))
13937 ;; scan for architectures
13938 (goto-char (point-min))
13939 (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)
13940 (let* ((arch-name (match-string-no-properties 1))
13941 (arch-key (downcase arch-name))
13942 (ent-name (match-string-no-properties 2))
13943 (ent-key (downcase ent-name))
13944 (ent-entry (vhdl-aget ent-alist ent-key))
13945 (arch-alist (nth 3 ent-entry))
13946 (arch-entry (vhdl-aget arch-alist arch-key))
13947 (lib-arch-alist (vhdl-scan-context-clause)))
13948 (if arch-entry
13949 (vhdl-warning-when-idle
13950 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13951 arch-name ent-name (nth 1 arch-entry)
13952 (nth 2 arch-entry) file-name (vhdl-current-line))
13953 (setq arch-list (cons arch-key arch-list)
13954 arch-ent-list (cons ent-key arch-ent-list))
13955 (vhdl-aput 'arch-alist arch-key
13956 (list arch-name file-name (vhdl-current-line)
13957 nil lib-arch-alist))
13958 (vhdl-aput 'ent-alist ent-key
13959 (list (or (nth 0 ent-entry) ent-name)
13960 (nth 1 ent-entry) (nth 2 ent-entry)
13961 (vhdl-sort-alist arch-alist)
13962 arch-key (nth 5 ent-entry))))))
13963 ;; scan for configurations
13964 (goto-char (point-min))
13965 (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)
13966 (let* ((conf-name (match-string-no-properties 1))
13967 (conf-key (downcase conf-name))
13968 (conf-entry (vhdl-aget conf-alist conf-key))
13969 (ent-name (match-string-no-properties 2))
13970 (ent-key (downcase ent-name))
13971 (lib-alist (vhdl-scan-context-clause))
13972 (conf-line (vhdl-current-line))
13973 (end-of-unit (vhdl-get-end-of-unit))
13974 arch-key comp-conf-list inst-key-list
13975 inst-comp-key inst-ent-key inst-arch-key
13976 inst-conf-key inst-lib-key)
13977 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13978 (setq arch-key (vhdl-match-string-downcase 1)))
13979 (if conf-entry
13980 (vhdl-warning-when-idle
13981 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13982 conf-name ent-name (nth 1 conf-entry)
13983 (nth 2 conf-entry) file-name conf-line)
13984 (push conf-key conf-list)
13985 ;; scan for subconfigurations and subentities
13986 (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)
13987 (setq inst-comp-key (vhdl-match-string-downcase 3)
13988 inst-key-list (split-string
13989 (vhdl-match-string-downcase 1)
13990 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13991 (vhdl-forward-syntactic-ws)
13992 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13993 (setq
13994 inst-lib-key (vhdl-match-string-downcase 3)
13995 inst-ent-key (and (match-string 2)
13996 (vhdl-match-string-downcase 4))
13997 inst-arch-key (and (match-string 2)
13998 (vhdl-match-string-downcase 6))
13999 inst-conf-key (and (not (match-string 2))
14000 (vhdl-match-string-downcase 4)))
14001 (while inst-key-list
14002 (setq comp-conf-list
14003 (cons (list (car inst-key-list)
14004 inst-comp-key inst-ent-key
14005 inst-arch-key inst-conf-key
14006 inst-lib-key)
14007 comp-conf-list))
14008 (setq inst-key-list (cdr inst-key-list)))))
14009 (vhdl-aput 'conf-alist conf-key
14010 (list conf-name file-name conf-line ent-key
14011 arch-key comp-conf-list lib-alist)))))
14012 ;; scan for packages
14013 (goto-char (point-min))
14014 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
14015 (let* ((pack-name (match-string-no-properties 2))
14016 (pack-key (downcase pack-name))
14017 (is-body (match-string-no-properties 1))
14018 (pack-entry (vhdl-aget pack-alist pack-key))
14019 (pack-line (vhdl-current-line))
14020 (end-of-unit (vhdl-get-end-of-unit))
14021 comp-name func-name comp-alist func-alist lib-alist)
14022 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14023 (vhdl-warning-when-idle
14024 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
14025 (if is-body " body" "") pack-name
14026 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
14027 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
14028 file-name (vhdl-current-line))
14029 ;; scan for context clauses
14030 (setq lib-alist (vhdl-scan-context-clause))
14031 ;; scan for component and subprogram declarations/bodies
14032 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
14033 (if (equal (upcase (match-string 1)) "COMPONENT")
14034 (setq comp-name (match-string-no-properties 2)
14035 comp-alist
14036 (cons (list (downcase comp-name) comp-name
14037 file-name (vhdl-current-line))
14038 comp-alist))
14039 (setq func-name (match-string-no-properties 2)
14040 func-alist
14041 (cons (list (downcase func-name) func-name
14042 file-name (vhdl-current-line))
14043 func-alist))))
14044 (setq func-alist (nreverse func-alist))
14045 (setq comp-alist (nreverse comp-alist))
14046 (if is-body
14047 (push pack-key pack-body-list)
14048 (push pack-key pack-list))
14049 (vhdl-aput
14050 'pack-alist pack-key
14051 (if is-body
14052 (list (or (nth 0 pack-entry) pack-name)
14053 (nth 1 pack-entry) (nth 2 pack-entry)
14054 (nth 3 pack-entry) (nth 4 pack-entry)
14055 (nth 5 pack-entry)
14056 file-name pack-line func-alist lib-alist)
14057 (list pack-name file-name pack-line
14058 comp-alist func-alist lib-alist
14059 (nth 6 pack-entry) (nth 7 pack-entry)
14060 (nth 8 pack-entry) (nth 9 pack-entry))))))))
14061 ;; scan for hierarchy
14062 (if (and limit-hier-file-size
14063 (< limit-hier-file-size (buffer-size)))
14064 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
14065 (setq big-files t))
14066 ;; scan for architectures
14067 (goto-char (point-min))
14068 (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)
14069 (let* ((ent-name (match-string-no-properties 2))
14070 (ent-key (downcase ent-name))
14071 (arch-name (match-string-no-properties 1))
14072 (arch-key (downcase arch-name))
14073 (ent-entry (vhdl-aget ent-alist ent-key))
14074 (arch-alist (nth 3 ent-entry))
14075 (arch-entry (vhdl-aget arch-alist arch-key))
14076 (beg-of-unit (point))
14077 (end-of-unit (vhdl-get-end-of-unit))
14078 (inst-no 0)
14079 inst-alist inst-path)
14080 ;; scan for contained instantiations
14081 (while (and (re-search-forward
14082 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
14083 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
14084 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
14085 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
14086 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
14087 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
14088 (or (not limit-hier-inst-no)
14089 (<= (if (or (match-string 14)
14090 (match-string 16))
14091 inst-no
14092 (setq inst-no (1+ inst-no)))
14093 limit-hier-inst-no)))
14094 (cond
14095 ;; block/generate beginning found
14096 ((match-string 14)
14097 (setq inst-path
14098 (cons (match-string-no-properties 1) inst-path)))
14099 ;; block/generate end found
14100 ((match-string 16)
14101 (setq inst-path (cdr inst-path)))
14102 ;; instantiation found
14104 (let* ((inst-name (match-string-no-properties 1))
14105 (inst-key (downcase inst-name))
14106 (inst-comp-name
14107 (or (match-string-no-properties 3)
14108 (match-string-no-properties 6)))
14109 (inst-ent-key
14110 (or (and (match-string 8)
14111 (vhdl-match-string-downcase 11))
14112 (and inst-comp-name
14113 (downcase inst-comp-name))))
14114 (inst-arch-key (vhdl-match-string-downcase 13))
14115 (inst-conf-key
14116 (and (not (match-string 8))
14117 (vhdl-match-string-downcase 11)))
14118 (inst-lib-key (vhdl-match-string-downcase 10)))
14119 (goto-char (match-end 1))
14120 (setq inst-list (cons inst-key inst-list)
14121 inst-ent-list
14122 (cons inst-ent-key inst-ent-list))
14123 (setq inst-alist
14124 (append
14125 inst-alist
14126 (list (list inst-key inst-name file-name
14127 (vhdl-current-line) inst-comp-name
14128 inst-ent-key inst-arch-key
14129 inst-conf-key inst-lib-key
14130 (reverse inst-path)))))))))
14131 ;; scan for contained configuration specifications
14132 (goto-char beg-of-unit)
14133 (while (re-search-forward
14134 (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]*\\)*"
14135 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
14136 (let* ((inst-comp-name (match-string-no-properties 3))
14137 (inst-ent-key
14138 (and (match-string 6)
14139 (vhdl-match-string-downcase 9)))
14140 (inst-arch-key (vhdl-match-string-downcase 11))
14141 (inst-conf-key
14142 (and (not (match-string 6))
14143 (vhdl-match-string-downcase 9)))
14144 (inst-lib-key (vhdl-match-string-downcase 8))
14145 (inst-key-list
14146 (split-string (vhdl-match-string-downcase 1)
14147 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
14148 (tmp-inst-alist inst-alist)
14149 inst-entry)
14150 (while tmp-inst-alist
14151 (when (and (or (equal "all" (car inst-key-list))
14152 (member (nth 0 (car tmp-inst-alist))
14153 inst-key-list))
14154 (equal
14155 (downcase
14156 (or (nth 4 (car tmp-inst-alist)) ""))
14157 (downcase inst-comp-name)))
14158 (setq inst-entry (car tmp-inst-alist))
14159 (setq inst-ent-list
14160 (cons (or inst-ent-key (nth 5 inst-entry))
14161 (vhdl-delete
14162 (nth 5 inst-entry) inst-ent-list)))
14163 (setq inst-entry
14164 (list (nth 0 inst-entry) (nth 1 inst-entry)
14165 (nth 2 inst-entry) (nth 3 inst-entry)
14166 (nth 4 inst-entry)
14167 (or inst-ent-key (nth 5 inst-entry))
14168 (or inst-arch-key (nth 6 inst-entry))
14169 inst-conf-key inst-lib-key))
14170 (setcar tmp-inst-alist inst-entry))
14171 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
14172 ;; save in cache
14173 (vhdl-aput 'arch-alist arch-key
14174 (list (nth 0 arch-entry) (nth 1 arch-entry)
14175 (nth 2 arch-entry) inst-alist
14176 (nth 4 arch-entry)))
14177 (vhdl-aput 'ent-alist ent-key
14178 (list (nth 0 ent-entry) (nth 1 ent-entry)
14179 (nth 2 ent-entry)
14180 (vhdl-sort-alist arch-alist)
14181 (nth 4 ent-entry) (nth 5 ent-entry)))
14182 (when (and limit-hier-inst-no
14183 (> inst-no limit-hier-inst-no))
14184 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
14185 (setq big-files t))
14186 (goto-char end-of-unit))))
14187 ;; remember design units for this file
14188 (vhdl-aput 'file-alist file-name
14189 (list ent-list arch-list arch-ent-list conf-list
14190 pack-list pack-body-list
14191 inst-list inst-ent-list))
14192 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
14193 (setq file-list (cdr file-list))))
14194 (when (or (and (not project) files-exist)
14195 (and project (not non-final)))
14196 ;; consistency checks:
14197 ;; check whether each architecture has a corresponding entity
14198 (setq tmp-list ent-alist)
14199 (while tmp-list
14200 (when (null (nth 2 (car tmp-list)))
14201 (setq tmp-entry (car (nth 4 (car tmp-list))))
14202 (vhdl-warning-when-idle
14203 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14204 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
14205 (nth 3 tmp-entry)))
14206 (setq tmp-list (cdr tmp-list)))
14207 ;; check whether configuration has a corresponding entity/architecture
14208 (setq tmp-list conf-alist)
14209 (while tmp-list
14210 (if (setq tmp-entry (vhdl-aget ent-alist (nth 4 (car tmp-list))))
14211 (unless (vhdl-aget (nth 3 tmp-entry) (nth 5 (car tmp-list)))
14212 (setq tmp-entry (car tmp-list))
14213 (vhdl-warning-when-idle
14214 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14215 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
14216 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14217 (setq tmp-entry (car tmp-list))
14218 (vhdl-warning-when-idle
14219 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14220 (nth 1 tmp-entry) (nth 4 tmp-entry)
14221 (nth 2 tmp-entry) (nth 3 tmp-entry)))
14222 (setq tmp-list (cdr tmp-list)))
14223 ;; check whether each package body has a package declaration
14224 (setq tmp-list pack-alist)
14225 (while tmp-list
14226 (when (null (nth 2 (car tmp-list)))
14227 (setq tmp-entry (car tmp-list))
14228 (vhdl-warning-when-idle
14229 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14230 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
14231 (setq tmp-list (cdr tmp-list)))
14232 ;; sort lists
14233 (setq ent-alist (vhdl-sort-alist ent-alist))
14234 (setq conf-alist (vhdl-sort-alist conf-alist))
14235 (setq pack-alist (vhdl-sort-alist pack-alist))
14236 ;; remember updated directory/project
14237 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
14238 ;; clear directory alists
14239 (unless project
14240 (vhdl-adelete 'vhdl-entity-alist key)
14241 (vhdl-adelete 'vhdl-config-alist key)
14242 (vhdl-adelete 'vhdl-package-alist key)
14243 (vhdl-adelete 'vhdl-ent-inst-alist key)
14244 (vhdl-adelete 'vhdl-file-alist key))
14245 ;; put directory contents into cache
14246 (vhdl-aput 'vhdl-entity-alist key ent-alist)
14247 (vhdl-aput 'vhdl-config-alist key conf-alist)
14248 (vhdl-aput 'vhdl-package-alist key pack-alist)
14249 (vhdl-aput 'vhdl-ent-inst-alist key (list ent-inst-list))
14250 (vhdl-aput 'vhdl-file-alist key file-alist)
14251 ;; final messages
14252 (message "Scanning %s %s\"%s\"...done"
14253 (if is-directory "directory" "files") (or num-string "") name)
14254 (unless project (message "Scanning directory...done"))
14255 (when big-files
14256 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14257 ;; save cache when scanned non-interactively
14258 (when (or (not project) (not non-final))
14259 (when (and noninteractive vhdl-speedbar-save-cache)
14260 (vhdl-save-cache key)))
14263 (defun vhdl-scan-project-contents (project)
14264 "Scan the contents of all VHDL files found in the directories and files
14265 of PROJECT."
14266 (let ((dir-list (or (nth 2 (vhdl-aget vhdl-project-alist project)) '("")))
14267 (default-dir (vhdl-resolve-env-variable
14268 (nth 1 (vhdl-aget vhdl-project-alist project))))
14269 (file-exclude-regexp
14270 (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
14271 dir-list-tmp dir dir-name num-dir act-dir recursive)
14272 ;; clear project alists
14273 (vhdl-adelete 'vhdl-entity-alist project)
14274 (vhdl-adelete 'vhdl-config-alist project)
14275 (vhdl-adelete 'vhdl-package-alist project)
14276 (vhdl-adelete 'vhdl-ent-inst-alist project)
14277 (vhdl-adelete 'vhdl-file-alist project)
14278 ;; expand directory names by default-directory
14279 (message "Collecting source files...")
14280 (while dir-list
14281 (setq dir (vhdl-resolve-env-variable (car dir-list)))
14282 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
14283 (setq recursive (match-string 1 dir)
14284 dir-name (match-string 3 dir))
14285 (setq dir-list-tmp
14286 (cons (concat recursive
14287 (if (file-name-absolute-p dir-name) "" default-dir)
14288 dir-name)
14289 dir-list-tmp))
14290 (setq dir-list (cdr dir-list)))
14291 ;; resolve path wildcards
14292 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
14293 ;; expand directories
14294 (while dir-list-tmp
14295 (setq dir (car dir-list-tmp))
14296 ;; get subdirectories
14297 (if (string-match "-r \\(.*[/\\]\\)" dir)
14298 (setq dir-list (append dir-list (vhdl-get-subdirs
14299 (match-string 1 dir))))
14300 (setq dir-list (append dir-list (list dir))))
14301 (setq dir-list-tmp (cdr dir-list-tmp)))
14302 ;; exclude files
14303 (unless (equal file-exclude-regexp "")
14304 (let ((case-fold-search nil))
14305 (while dir-list
14306 (unless (string-match file-exclude-regexp (car dir-list))
14307 (push (car dir-list) dir-list-tmp))
14308 (setq dir-list (cdr dir-list)))
14309 (setq dir-list (nreverse dir-list-tmp))))
14310 (message "Collecting source files...done")
14311 ;; scan for design units for each directory in DIR-LIST
14312 (setq dir-list-tmp nil
14313 num-dir (length dir-list)
14314 act-dir 1)
14315 (while dir-list
14316 (setq dir-name (abbreviate-file-name
14317 (expand-file-name (car dir-list))))
14318 (vhdl-scan-directory-contents dir-name project nil
14319 (format "(%s/%s) " act-dir num-dir)
14320 (cdr dir-list))
14321 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
14322 (setq dir-list (cdr dir-list)
14323 act-dir (1+ act-dir)))
14324 (vhdl-aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
14325 (message "Scanning project \"%s\"...done" project)))
14327 (defun vhdl-update-file-contents (file-name)
14328 "Update hierarchy information by contents of current buffer."
14329 (setq file-name (abbreviate-file-name file-name))
14330 (let* ((dir-name (file-name-directory file-name))
14331 (directory-alist vhdl-directory-alist)
14332 updated)
14333 (while directory-alist
14334 (when (member dir-name (nth 1 (car directory-alist)))
14335 (let* ((vhdl-project (nth 0 (car directory-alist)))
14336 (project (vhdl-project-p))
14337 (ent-alist (vhdl-aget vhdl-entity-alist
14338 (or project dir-name)))
14339 (conf-alist (vhdl-aget vhdl-config-alist
14340 (or project dir-name)))
14341 (pack-alist (vhdl-aget vhdl-package-alist
14342 (or project dir-name)))
14343 (ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist
14344 (or project dir-name))))
14345 (file-alist (vhdl-aget vhdl-file-alist (or project dir-name)))
14346 (file-entry (vhdl-aget file-alist file-name))
14347 (ent-list (nth 0 file-entry))
14348 (arch-list (nth 1 file-entry))
14349 (arch-ent-list (nth 2 file-entry))
14350 (conf-list (nth 3 file-entry))
14351 (pack-list (nth 4 file-entry))
14352 (pack-body-list (nth 5 file-entry))
14353 (inst-ent-list (nth 7 file-entry))
14354 (cache-key (or project dir-name))
14355 arch-alist key ent-key entry)
14356 ;; delete design units previously contained in this file:
14357 ;; entities
14358 (while ent-list
14359 (setq key (car ent-list)
14360 entry (vhdl-aget ent-alist key))
14361 (when (equal file-name (nth 1 entry))
14362 (if (nth 3 entry)
14363 (vhdl-aput 'ent-alist key
14364 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14365 (vhdl-adelete 'ent-alist key)))
14366 (setq ent-list (cdr ent-list)))
14367 ;; architectures
14368 (while arch-list
14369 (setq key (car arch-list)
14370 ent-key (car arch-ent-list)
14371 entry (vhdl-aget ent-alist ent-key)
14372 arch-alist (nth 3 entry))
14373 (when (equal file-name (nth 1 (vhdl-aget arch-alist key)))
14374 (vhdl-adelete 'arch-alist key)
14375 (if (or (nth 1 entry) arch-alist)
14376 (vhdl-aput 'ent-alist ent-key
14377 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14378 arch-alist (nth 4 entry) (nth 5 entry)))
14379 (vhdl-adelete 'ent-alist ent-key)))
14380 (setq arch-list (cdr arch-list)
14381 arch-ent-list (cdr arch-ent-list)))
14382 ;; configurations
14383 (while conf-list
14384 (setq key (car conf-list))
14385 (when (equal file-name (nth 1 (vhdl-aget conf-alist key)))
14386 (vhdl-adelete 'conf-alist key))
14387 (setq conf-list (cdr conf-list)))
14388 ;; package declarations
14389 (while pack-list
14390 (setq key (car pack-list)
14391 entry (vhdl-aget pack-alist key))
14392 (when (equal file-name (nth 1 entry))
14393 (if (nth 6 entry)
14394 (vhdl-aput 'pack-alist key
14395 (list (nth 0 entry) nil nil nil nil nil
14396 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14397 (nth 9 entry)))
14398 (vhdl-adelete 'pack-alist key)))
14399 (setq pack-list (cdr pack-list)))
14400 ;; package bodies
14401 (while pack-body-list
14402 (setq key (car pack-body-list)
14403 entry (vhdl-aget pack-alist key))
14404 (when (equal file-name (nth 6 entry))
14405 (if (nth 1 entry)
14406 (vhdl-aput 'pack-alist key
14407 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14408 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14409 nil nil nil nil))
14410 (vhdl-adelete 'pack-alist key)))
14411 (setq pack-body-list (cdr pack-body-list)))
14412 ;; instantiated entities
14413 (while inst-ent-list
14414 (setq ent-inst-list
14415 (vhdl-delete (car inst-ent-list) ent-inst-list))
14416 (setq inst-ent-list (cdr inst-ent-list)))
14417 ;; update caches
14418 (vhdl-aput-delete-if-nil 'vhdl-entity-alist cache-key ent-alist)
14419 (vhdl-aput-delete-if-nil 'vhdl-config-alist cache-key conf-alist)
14420 (vhdl-aput-delete-if-nil 'vhdl-package-alist cache-key pack-alist)
14421 (vhdl-aput-delete-if-nil 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14422 ;; scan file
14423 (vhdl-scan-directory-contents file-name project t)
14424 (when (or (and vhdl-speedbar-show-projects project)
14425 (and (not vhdl-speedbar-show-projects) (not project)))
14426 (vhdl-speedbar-refresh project))
14427 (setq updated t)))
14428 (setq directory-alist (cdr directory-alist)))
14429 updated))
14431 (defun vhdl-update-hierarchy ()
14432 "Update directory and hierarchy information in speedbar."
14433 (let ((file-list (reverse vhdl-modified-file-list))
14434 updated)
14435 (when (and vhdl-speedbar-update-on-saving file-list)
14436 (while file-list
14437 (setq updated
14438 (or (vhdl-update-file-contents (car file-list))
14439 updated))
14440 (setq file-list (cdr file-list)))
14441 (setq vhdl-modified-file-list nil)
14442 (vhdl-speedbar-update-current-unit)
14443 (when updated (message "Updating hierarchy...done")))))
14445 ;; structure (parenthesized expression means list of such entries)
14446 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14447 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14448 ;; comp-lib-name level)
14449 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14450 conf-inst-alist level indent
14451 &optional include-top ent-hier)
14452 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14453 entity ENT-KEY."
14454 (let* ((ent-entry (vhdl-aget ent-alist ent-key))
14455 (arch-entry (if arch-key (vhdl-aget (nth 3 ent-entry) arch-key)
14456 (cdar (last (nth 3 ent-entry)))))
14457 (inst-alist (nth 3 arch-entry))
14458 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14459 hier-list subcomp-list tmp-list inst-key inst-comp-name
14460 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14461 (when (= level 0) (message "Extract design hierarchy..."))
14462 (when include-top
14463 (setq level (1+ level)))
14464 (when (member ent-key ent-hier)
14465 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14466 ;; process all instances
14467 (while inst-alist
14468 (setq inst-entry (car inst-alist)
14469 inst-key (nth 0 inst-entry)
14470 inst-comp-name (nth 4 inst-entry)
14471 inst-conf-key (nth 7 inst-entry))
14472 ;; search entry in configuration's instantiations list
14473 (setq tmp-list conf-inst-alist)
14474 (while (and tmp-list
14475 (not (and (member (nth 0 (car tmp-list))
14476 (list "all" inst-key))
14477 (equal (nth 1 (car tmp-list))
14478 (downcase (or inst-comp-name ""))))))
14479 (setq tmp-list (cdr tmp-list)))
14480 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14481 (setq inst-conf-entry (vhdl-aget conf-alist inst-conf-key))
14482 (when (and inst-conf-key (not inst-conf-entry))
14483 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14484 ;; determine entity
14485 (setq inst-ent-key
14486 (or (nth 2 (car tmp-list)) ; from configuration
14487 (nth 3 inst-conf-entry) ; from subconfiguration
14488 (nth 3 (vhdl-aget conf-alist (nth 7 inst-entry)))
14489 ; from configuration spec.
14490 (nth 5 inst-entry))) ; from direct instantiation
14491 (setq inst-ent-entry (vhdl-aget ent-alist inst-ent-key))
14492 ;; determine architecture
14493 (setq inst-arch-key
14494 (or (nth 3 (car tmp-list)) ; from configuration
14495 (nth 4 inst-conf-entry) ; from subconfiguration
14496 (nth 6 inst-entry) ; from direct instantiation
14497 (nth 4 (vhdl-aget conf-alist (nth 7 inst-entry)))
14498 ; from configuration spec.
14499 (nth 4 inst-ent-entry) ; MRA
14500 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14501 (setq inst-arch-entry (vhdl-aget (nth 3 inst-ent-entry) inst-arch-key))
14502 ;; set library
14503 (setq inst-lib-key
14504 (or (nth 5 (car tmp-list)) ; from configuration
14505 (nth 8 inst-entry))) ; from direct instantiation
14506 ;; gather information for this instance
14507 (setq comp-entry
14508 (list (nth 1 inst-entry)
14509 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14510 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14511 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14512 (or (nth 0 inst-arch-entry) inst-arch-key)
14513 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14514 (or (nth 0 inst-conf-entry) inst-conf-key)
14515 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14516 inst-lib-key level))
14517 ;; get subcomponent hierarchy
14518 (setq subcomp-list (vhdl-get-hierarchy
14519 ent-alist conf-alist
14520 inst-ent-key inst-arch-key inst-conf-key
14521 (nth 5 inst-conf-entry)
14522 (1+ level) indent nil (cons ent-key ent-hier)))
14523 ;; add to list
14524 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14525 (setq inst-alist (cdr inst-alist)))
14526 (when include-top
14527 (setq hier-list
14528 (cons (list nil nil (nth 0 ent-entry)
14529 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14530 (nth 0 arch-entry)
14531 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14532 nil nil
14533 nil (1- level))
14534 hier-list)))
14535 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14536 hier-list))
14538 (defun vhdl-get-instantiations (ent-key indent)
14539 "Get all instantiations of entity ENT-KEY."
14540 (let ((ent-alist (vhdl-aget vhdl-entity-alist
14541 (vhdl-speedbar-line-key indent)))
14542 arch-alist inst-alist ent-inst-list
14543 ent-entry arch-entry inst-entry)
14544 (while ent-alist
14545 (setq ent-entry (car ent-alist))
14546 (setq arch-alist (nth 4 ent-entry))
14547 (while arch-alist
14548 (setq arch-entry (car arch-alist))
14549 (setq inst-alist (nth 4 arch-entry))
14550 (while inst-alist
14551 (setq inst-entry (car inst-alist))
14552 (when (equal ent-key (nth 5 inst-entry))
14553 (setq ent-inst-list
14554 (cons (list (nth 1 inst-entry)
14555 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14556 (nth 1 ent-entry)
14557 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14558 (nth 1 arch-entry)
14559 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14560 ent-inst-list)))
14561 (setq inst-alist (cdr inst-alist)))
14562 (setq arch-alist (cdr arch-alist)))
14563 (setq ent-alist (cdr ent-alist)))
14564 (nreverse ent-inst-list)))
14566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14567 ;; Caching in file
14569 (defun vhdl-save-caches ()
14570 "Save all updated hierarchy caches to file."
14571 (interactive)
14572 (condition-case nil
14573 (when vhdl-speedbar-save-cache
14574 ;; update hierarchy
14575 (vhdl-update-hierarchy)
14576 (let ((project-list vhdl-updated-project-list))
14577 (message "Saving hierarchy caches...")
14578 ;; write updated project caches
14579 (while project-list
14580 (vhdl-save-cache (car project-list))
14581 (setq project-list (cdr project-list)))
14582 (message "Saving hierarchy caches...done")))
14583 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14584 (sit-for 2)))))
14586 (defun vhdl-save-cache (key)
14587 "Save current hierarchy cache to file."
14588 (let* ((orig-buffer (current-buffer))
14589 (vhdl-project key)
14590 (project (vhdl-project-p))
14591 (default-directory key)
14592 (directory (abbreviate-file-name (vhdl-default-directory)))
14593 (file-name (vhdl-resolve-env-variable
14594 (vhdl-replace-string
14595 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14596 (concat
14597 (subst-char-in-string ? ?_ (or project "dir"))
14598 " " (user-login-name)))))
14599 (file-dir-name (expand-file-name file-name directory))
14600 (cache-key (or project directory))
14601 (key (if project "project" "directory")))
14602 (unless (file-exists-p (file-name-directory file-dir-name))
14603 (make-directory (file-name-directory file-dir-name) t))
14604 (if (not (file-writable-p file-dir-name))
14605 (progn (vhdl-warning (format "File not writable: \"%s\""
14606 (abbreviate-file-name file-dir-name)))
14607 (sit-for 2))
14608 (message "Saving cache: \"%s\"" file-dir-name)
14609 (set-buffer (find-file-noselect file-dir-name t t))
14610 (erase-buffer)
14611 (insert ";; -*- Emacs-Lisp -*-\n\n"
14612 ";;; " (file-name-nondirectory file-name)
14613 " - design hierarchy cache file for Emacs VHDL Mode "
14614 vhdl-version "\n")
14615 (insert "\n;; " (if project "Project " "Directory") " : ")
14616 (if project (insert project) (prin1 directory (current-buffer)))
14617 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14618 (user-login-name) "\n\n"
14619 "\n;; version number\n"
14620 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14621 "\n;; " (if project "project" "directory") " name"
14622 "\n(setq " key " ")
14623 (prin1 (or project directory) (current-buffer))
14624 (insert ")\n")
14625 (when (member 'hierarchy vhdl-speedbar-save-cache)
14626 (insert "\n;; entity and architecture cache\n"
14627 "(vhdl-aput 'vhdl-entity-alist " key " '")
14628 (print (vhdl-aget vhdl-entity-alist cache-key) (current-buffer))
14629 (insert ")\n\n;; configuration cache\n"
14630 "(vhdl-aput 'vhdl-config-alist " key " '")
14631 (print (vhdl-aget vhdl-config-alist cache-key) (current-buffer))
14632 (insert ")\n\n;; package cache\n"
14633 "(vhdl-aput 'vhdl-package-alist " key " '")
14634 (print (vhdl-aget vhdl-package-alist cache-key) (current-buffer))
14635 (insert ")\n\n;; instantiated entities cache\n"
14636 "(vhdl-aput 'vhdl-ent-inst-alist " key " '")
14637 (print (vhdl-aget vhdl-ent-inst-alist cache-key) (current-buffer))
14638 (insert ")\n\n;; design units per file cache\n"
14639 "(vhdl-aput 'vhdl-file-alist " key " '")
14640 (print (vhdl-aget vhdl-file-alist cache-key) (current-buffer))
14641 (when project
14642 (insert ")\n\n;; source directories in project cache\n"
14643 "(vhdl-aput 'vhdl-directory-alist " key " '")
14644 (print (vhdl-aget vhdl-directory-alist cache-key) (current-buffer)))
14645 (insert ")\n"))
14646 (when (member 'display vhdl-speedbar-save-cache)
14647 (insert "\n;; shown design units cache\n"
14648 "(vhdl-aput 'vhdl-speedbar-shown-unit-alist " key " '")
14649 (print (vhdl-aget vhdl-speedbar-shown-unit-alist cache-key)
14650 (current-buffer))
14651 (insert ")\n"))
14652 (setq vhdl-updated-project-list
14653 (delete cache-key vhdl-updated-project-list))
14654 (save-buffer)
14655 (kill-buffer (current-buffer))
14656 (set-buffer orig-buffer))))
14658 (defun vhdl-load-cache (key)
14659 "Load hierarchy cache information from file."
14660 (let* ((vhdl-project key)
14661 (default-directory key)
14662 (directory (vhdl-default-directory))
14663 (file-name (vhdl-resolve-env-variable
14664 (vhdl-replace-string
14665 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14666 (concat
14667 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14668 " " (user-login-name)))))
14669 (file-dir-name (expand-file-name file-name directory))
14670 vhdl-cache-version)
14671 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14672 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14673 (when (file-exists-p file-dir-name)
14674 (condition-case ()
14675 (progn (load-file file-dir-name)
14676 (string< (mapconcat
14677 (lambda (a) (format "%3d" (string-to-number a)))
14678 (split-string "3.33" "\\.") "")
14679 (mapconcat
14680 (lambda (a) (format "%3d" (string-to-number a)))
14681 (split-string vhdl-cache-version "\\.") "")))
14682 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14683 nil))))))
14685 (defun vhdl-require-hierarchy-info ()
14686 "Make sure that hierarchy information is available. Load cache or scan files
14687 if required."
14688 (if (vhdl-project-p)
14689 (unless (or (assoc vhdl-project vhdl-file-alist)
14690 (vhdl-load-cache vhdl-project))
14691 (vhdl-scan-project-contents vhdl-project))
14692 (let ((directory (abbreviate-file-name default-directory)))
14693 (unless (or (assoc directory vhdl-file-alist)
14694 (vhdl-load-cache directory))
14695 (vhdl-scan-directory-contents directory)))))
14697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14698 ;; Add hierarchy browser functionality to speedbar
14700 (defvar vhdl-speedbar-mode-map nil
14701 "Keymap used when in the VHDL hierarchy browser mode.")
14703 (defvar vhdl-speedbar-menu-items nil
14704 "Additional menu-items to add to speedbar frame.")
14706 (declare-function speedbar-add-supported-extension "speedbar" (extension))
14707 (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
14708 (declare-function speedbar-make-specialized-keymap "speedbar" ())
14709 (declare-function speedbar-change-initial-expansion-list "speedbar"
14710 (new-default))
14711 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
14713 (defun vhdl-speedbar-initialize ()
14714 "Initialize speedbar."
14715 ;; general settings
14716 ;; VHDL file extensions (extracted from `auto-mode-alist')
14717 (let ((mode-alist auto-mode-alist))
14718 (while mode-alist
14719 (when (eq (cdar mode-alist) 'vhdl-mode)
14720 (speedbar-add-supported-extension (caar mode-alist)))
14721 (setq mode-alist (cdr mode-alist))))
14722 ;; hierarchy browser settings
14723 (when (boundp 'speedbar-mode-functions-list)
14724 ;; special functions
14725 (speedbar-add-mode-functions-list
14726 '("vhdl directory"
14727 (speedbar-item-info . vhdl-speedbar-item-info)
14728 (speedbar-line-directory . speedbar-files-line-path)))
14729 (speedbar-add-mode-functions-list
14730 '("vhdl project"
14731 (speedbar-item-info . vhdl-speedbar-item-info)
14732 (speedbar-line-directory . vhdl-speedbar-line-project)))
14733 ;; keymap
14734 (unless vhdl-speedbar-mode-map
14735 (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
14736 (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
14737 (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
14738 (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
14739 (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
14740 (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
14741 (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
14742 (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
14743 (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
14744 (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
14745 (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
14746 (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
14747 (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
14748 (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
14749 (let ((key 0))
14750 (while (<= key 9)
14751 (define-key vhdl-speedbar-mode-map (int-to-string key)
14752 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14753 (setq key (1+ key)))))
14754 (define-key speedbar-mode-map "h"
14755 (lambda () (interactive)
14756 (speedbar-change-initial-expansion-list "vhdl directory")))
14757 (define-key speedbar-mode-map "H"
14758 (lambda () (interactive)
14759 (speedbar-change-initial-expansion-list "vhdl project")))
14760 ;; menu
14761 (unless vhdl-speedbar-menu-items
14762 (setq
14763 vhdl-speedbar-menu-items
14764 `(["Edit" speedbar-edit-line t]
14765 ["Expand" speedbar-expand-line
14766 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14767 ["Contract" vhdl-speedbar-contract-level t]
14768 ["Expand All" vhdl-speedbar-expand-all t]
14769 ["Contract All" vhdl-speedbar-contract-all t]
14770 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14771 (while (<= key 9)
14772 (setq menu-list
14773 (cons `[,(if (= key 0) "All" (int-to-string key))
14774 (vhdl-speedbar-set-depth ,key)
14775 :style radio
14776 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14777 :keys ,(int-to-string key)]
14778 menu-list))
14779 (setq key (1+ key)))
14780 (nreverse menu-list))
14781 "--"
14782 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14783 (or (vhdl-speedbar-check-unit 'entity)
14784 (vhdl-speedbar-check-unit 'subprogram))]
14785 ["Place Component" vhdl-speedbar-place-component
14786 (vhdl-speedbar-check-unit 'entity)]
14787 ["Generate Configuration" vhdl-speedbar-configuration
14788 (vhdl-speedbar-check-unit 'architecture)]
14789 ["Select as MRA" vhdl-speedbar-select-mra
14790 (vhdl-speedbar-check-unit 'architecture)]
14791 ["Make" vhdl-speedbar-make-design
14792 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14793 ["Generate Makefile" vhdl-speedbar-generate-makefile
14794 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14795 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14796 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14797 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14798 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14799 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14800 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14801 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14802 ;; hook-ups
14803 (speedbar-add-expansion-list
14804 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14805 vhdl-speedbar-display-directory))
14806 (speedbar-add-expansion-list
14807 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14808 vhdl-speedbar-display-projects))
14809 (setq speedbar-stealthy-function-list
14810 (append
14811 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14812 ("vhdl project" vhdl-speedbar-update-current-project
14813 vhdl-speedbar-update-current-unit))
14814 speedbar-stealthy-function-list))
14815 (when (eq vhdl-speedbar-display-mode 'directory)
14816 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14817 (when (eq vhdl-speedbar-display-mode 'project)
14818 (setq speedbar-initial-expansion-list-name "vhdl project"))
14819 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14821 (defun vhdl-speedbar (&optional arg)
14822 "Open/close speedbar."
14823 (interactive)
14824 (if (not (fboundp 'speedbar))
14825 (error "WARNING: Speedbar is not available or not installed")
14826 (condition-case ()
14827 (speedbar-frame-mode arg)
14828 (error (error "WARNING: An error occurred while opening speedbar")))))
14830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14831 ;; Display functions
14833 (defvar vhdl-speedbar-last-selected-project nil
14834 "Name of last selected project.")
14836 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14837 ;;; (defmacro speedbar-with-writable (&rest forms)
14838 ;;; "Allow the buffer to be writable and evaluate FORMS."
14839 ;;; (list 'let '((inhibit-read-only t))
14840 ;;; (cons 'progn forms)))
14841 ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
14843 (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
14844 (declare-function speedbar-directory-buttons "speedbar" (directory _index))
14845 (declare-function speedbar-file-lists "speedbar" (directory))
14847 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14848 "Display directory and hierarchy information in speedbar."
14849 (setq vhdl-speedbar-show-projects nil)
14850 (setq speedbar-ignored-directory-regexp
14851 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14852 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14853 (setq speedbar-last-selected-file nil)
14854 (speedbar-with-writable
14855 (condition-case nil
14856 (progn
14857 ;; insert directory path
14858 (speedbar-directory-buttons directory depth)
14859 ;; insert subdirectories
14860 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14861 ;; scan and insert hierarchy of current directory
14862 (vhdl-speedbar-insert-dir-hierarchy directory depth
14863 speedbar-power-click)
14864 ;; expand subdirectories
14865 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14866 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14868 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14869 "Display projects and hierarchy information in speedbar."
14870 (setq vhdl-speedbar-show-projects t)
14871 (setq speedbar-ignored-directory-regexp ".")
14872 (setq speedbar-last-selected-file nil)
14873 (setq vhdl-speedbar-last-selected-project nil)
14874 (speedbar-with-writable
14875 (condition-case nil
14876 ;; insert projects
14877 (vhdl-speedbar-insert-projects)
14878 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14879 (setq speedbar-full-text-cache nil)) ; prevent caching
14881 (declare-function speedbar-make-tag-line "speedbar"
14882 (type char func data tag tfunc tdata tface depth))
14884 (defun vhdl-speedbar-insert-projects ()
14885 "Insert all projects in speedbar."
14886 (vhdl-speedbar-make-title-line "Projects:")
14887 (let ((project-alist (if vhdl-project-sort
14888 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14889 vhdl-project-alist))
14890 (vhdl-speedbar-update-current-unit nil))
14891 ;; insert projects
14892 (while project-alist
14893 (speedbar-make-tag-line
14894 'angle ?+ 'vhdl-speedbar-expand-project
14895 (caar project-alist) (caar project-alist)
14896 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14897 (setq project-alist (cdr project-alist)))
14898 (setq project-alist vhdl-project-alist)
14899 ;; expand projects
14900 (while project-alist
14901 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14902 (goto-char (point-min))
14903 (when (re-search-forward
14904 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14905 (goto-char (match-end 1))
14906 (speedbar-do-function-pointer)))
14907 (setq project-alist (cdr project-alist)))))
14909 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14910 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14911 otherwise use cached data."
14912 (when (or rescan (and (not (assoc project vhdl-file-alist))
14913 (not (vhdl-load-cache project))))
14914 (vhdl-scan-project-contents project))
14915 ;; insert design hierarchy
14916 (vhdl-speedbar-insert-hierarchy
14917 (vhdl-aget vhdl-entity-alist project)
14918 (vhdl-aget vhdl-config-alist project)
14919 (vhdl-aget vhdl-package-alist project)
14920 (car (vhdl-aget vhdl-ent-inst-alist project)) indent)
14921 (insert (int-to-string indent) ":\n")
14922 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14923 (put-text-property (1- (point)) (point) 'invisible nil)
14924 ;; expand design units
14925 (vhdl-speedbar-expand-units project))
14927 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14928 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14929 otherwise use cached data."
14930 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14931 (not (vhdl-load-cache directory))))
14932 (vhdl-scan-directory-contents directory))
14933 ;; insert design hierarchy
14934 (vhdl-speedbar-insert-hierarchy
14935 (vhdl-aget vhdl-entity-alist directory)
14936 (vhdl-aget vhdl-config-alist directory)
14937 (vhdl-aget vhdl-package-alist directory)
14938 (car (vhdl-aget vhdl-ent-inst-alist directory)) depth)
14939 ;; expand design units
14940 (vhdl-speedbar-expand-units directory)
14941 (vhdl-aput 'vhdl-directory-alist directory (list (list directory))))
14943 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14944 ent-inst-list depth)
14945 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14946 (if (not (or ent-alist conf-alist pack-alist))
14947 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14948 (let (ent-entry conf-entry pack-entry)
14949 ;; insert entities
14950 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14951 (while ent-alist
14952 (setq ent-entry (car ent-alist))
14953 (speedbar-make-tag-line
14954 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14955 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14956 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14957 'vhdl-speedbar-entity-face depth)
14958 (unless (nth 2 ent-entry)
14959 (end-of-line 0) (insert "!") (forward-char 1))
14960 (unless (member (nth 0 ent-entry) ent-inst-list)
14961 (end-of-line 0) (insert " (top)") (forward-char 1))
14962 (setq ent-alist (cdr ent-alist)))
14963 ;; insert configurations
14964 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14965 (while conf-alist
14966 (setq conf-entry (car conf-alist))
14967 (speedbar-make-tag-line
14968 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14969 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14970 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14971 'vhdl-speedbar-configuration-face depth)
14972 (setq conf-alist (cdr conf-alist)))
14973 ;; insert packages
14974 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14975 (while pack-alist
14976 (setq pack-entry (car pack-alist))
14977 (vhdl-speedbar-make-pack-line
14978 (nth 0 pack-entry) (nth 1 pack-entry)
14979 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14980 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14981 depth)
14982 (setq pack-alist (cdr pack-alist))))))
14984 (declare-function speedbar-line-directory "speedbar" (&optional depth))
14986 (defun vhdl-speedbar-rescan-hierarchy ()
14987 "Rescan hierarchy for the directory or project under the cursor."
14988 (interactive)
14989 (let (key path)
14990 (cond
14991 ;; current project
14992 (vhdl-speedbar-show-projects
14993 (setq key (vhdl-speedbar-line-project))
14994 (vhdl-scan-project-contents key))
14995 ;; top-level directory
14996 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14997 (re-search-forward "[0-9]+:" nil t)
14998 (vhdl-scan-directory-contents
14999 (abbreviate-file-name (speedbar-line-directory))))
15000 ;; current directory
15001 (t (setq path (speedbar-line-directory))
15002 (string-match "^\\(.+[/\\]\\)" path)
15003 (vhdl-scan-directory-contents
15004 (abbreviate-file-name (match-string 1 path)))))
15005 (vhdl-speedbar-refresh key)))
15007 (declare-function speedbar-goto-this-file "speedbar" (file))
15009 (defun vhdl-speedbar-expand-dirs (directory)
15010 "Expand subdirectories in DIRECTORY according to
15011 `speedbar-shown-directories'."
15012 ;; (nicked from `speedbar-default-directory-list')
15013 (let ((sf (cdr (reverse speedbar-shown-directories)))
15014 (vhdl-speedbar-update-current-unit nil))
15015 (setq speedbar-shown-directories
15016 (list (expand-file-name default-directory)))
15017 (while sf
15018 (when (speedbar-goto-this-file (car sf))
15019 (beginning-of-line)
15020 (when (looking-at "[0-9]+:\\s-*<")
15021 (goto-char (match-end 0))
15022 (speedbar-do-function-pointer)))
15023 (setq sf (cdr sf))))
15024 (vhdl-speedbar-update-current-unit nil t))
15026 (defun vhdl-speedbar-expand-units (key)
15027 "Expand design units in directory/project KEY according to
15028 `vhdl-speedbar-shown-unit-alist'."
15029 (let ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15030 (vhdl-speedbar-update-current-unit nil)
15031 vhdl-updated-project-list)
15032 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15033 (vhdl-prepare-search-1
15034 (while unit-alist ; expand units
15035 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
15036 (beginning-of-line)
15037 (let ((arch-alist (nth 1 (car unit-alist)))
15038 position)
15039 (when (looking-at "^[0-9]+:\\s-*\\[")
15040 (goto-char (match-end 0))
15041 (setq position (point))
15042 (speedbar-do-function-pointer)
15043 (select-frame speedbar-frame)
15044 (while arch-alist ; expand architectures
15045 (goto-char position)
15046 (when (re-search-forward
15047 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
15048 (car arch-alist) "\\>\\)") nil t)
15049 (beginning-of-line)
15050 (when (looking-at "^[0-9]+:\\s-*{")
15051 (goto-char (match-end 0))
15052 (speedbar-do-function-pointer)
15053 (select-frame speedbar-frame)))
15054 (setq arch-alist (cdr arch-alist))))
15055 (setq unit-alist (cdr unit-alist))))))
15056 (vhdl-speedbar-update-current-unit nil t))
15058 (declare-function speedbar-center-buffer-smartly "speedbar" ())
15060 (defun vhdl-speedbar-contract-level ()
15061 "Contract current level in current directory/project."
15062 (interactive)
15063 (when (or (save-excursion
15064 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
15065 (and (save-excursion
15066 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
15067 (re-search-backward
15068 (format "^[0-%d]:\\s-*[[{<]-"
15069 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
15070 (goto-char (match-end 0))
15071 (speedbar-do-function-pointer)
15072 (speedbar-center-buffer-smartly)))
15074 (defun vhdl-speedbar-contract-all ()
15075 "Contract all expanded design units in current directory/project."
15076 (interactive)
15077 (if (and vhdl-speedbar-show-projects
15078 (save-excursion (beginning-of-line) (looking-at "^0:")))
15079 (progn (setq vhdl-speedbar-shown-project-list nil)
15080 (vhdl-speedbar-refresh))
15081 (let ((key (vhdl-speedbar-line-key)))
15082 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
15083 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
15084 (when (memq 'display vhdl-speedbar-save-cache)
15085 (add-to-list 'vhdl-updated-project-list key)))))
15087 (defun vhdl-speedbar-expand-all ()
15088 "Expand all design units in current directory/project."
15089 (interactive)
15090 (let* ((key (vhdl-speedbar-line-key))
15091 (ent-alist (vhdl-aget vhdl-entity-alist key))
15092 (conf-alist (vhdl-aget vhdl-config-alist key))
15093 (pack-alist (vhdl-aget vhdl-package-alist key))
15094 arch-alist unit-alist subunit-alist)
15095 (add-to-list 'vhdl-speedbar-shown-project-list key)
15096 (while ent-alist
15097 (setq arch-alist (nth 4 (car ent-alist)))
15098 (setq subunit-alist nil)
15099 (while arch-alist
15100 (push (caar arch-alist) subunit-alist)
15101 (setq arch-alist (cdr arch-alist)))
15102 (push (list (caar ent-alist) subunit-alist) unit-alist)
15103 (setq ent-alist (cdr ent-alist)))
15104 (while conf-alist
15105 (push (list (caar conf-alist)) unit-alist)
15106 (setq conf-alist (cdr conf-alist)))
15107 (while pack-alist
15108 (push (list (caar pack-alist)) unit-alist)
15109 (setq pack-alist (cdr pack-alist)))
15110 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15111 (vhdl-speedbar-refresh)
15112 (when (memq 'display vhdl-speedbar-save-cache)
15113 (add-to-list 'vhdl-updated-project-list key))))
15115 (declare-function speedbar-change-expand-button-char "speedbar" (char))
15116 (declare-function speedbar-delete-subblock "speedbar" (indent))
15118 (defun vhdl-speedbar-expand-project (text token indent)
15119 "Expand/contract the project under the cursor."
15120 (cond
15121 ((string-match "+" text) ; expand project
15122 (speedbar-change-expand-button-char ?-)
15123 (unless (member token vhdl-speedbar-shown-project-list)
15124 (setq vhdl-speedbar-shown-project-list
15125 (cons token vhdl-speedbar-shown-project-list)))
15126 (speedbar-with-writable
15127 (save-excursion
15128 (end-of-line) (forward-char 1)
15129 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
15130 speedbar-power-click))))
15131 ((string-match "-" text) ; contract project
15132 (speedbar-change-expand-button-char ?+)
15133 (setq vhdl-speedbar-shown-project-list
15134 (delete token vhdl-speedbar-shown-project-list))
15135 (speedbar-delete-subblock indent))
15136 (t (error "Nothing to display")))
15137 (when (equal (selected-frame) speedbar-frame)
15138 (speedbar-center-buffer-smartly)))
15140 (defun vhdl-speedbar-expand-entity (text token indent)
15141 "Expand/contract the entity under the cursor."
15142 (cond
15143 ((string-match "+" text) ; expand entity
15144 (let* ((key (vhdl-speedbar-line-key indent))
15145 (ent-alist (vhdl-aget vhdl-entity-alist key))
15146 (ent-entry (vhdl-aget ent-alist token))
15147 (arch-alist (nth 3 ent-entry))
15148 (inst-alist (vhdl-get-instantiations token indent))
15149 (subpack-alist (nth 5 ent-entry))
15150 (multiple-arch (> (length arch-alist) 1))
15151 arch-entry inst-entry)
15152 (if (not (or arch-alist inst-alist subpack-alist))
15153 (speedbar-change-expand-button-char ??)
15154 (speedbar-change-expand-button-char ?-)
15155 ;; add entity to `vhdl-speedbar-shown-unit-alist'
15156 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15157 (vhdl-aput 'unit-alist token nil)
15158 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15159 (speedbar-with-writable
15160 (save-excursion
15161 (end-of-line) (forward-char 1)
15162 ;; insert architectures
15163 (when arch-alist
15164 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
15165 (while arch-alist
15166 (setq arch-entry (car arch-alist))
15167 (speedbar-make-tag-line
15168 'curly ?+ 'vhdl-speedbar-expand-architecture
15169 (cons token (nth 0 arch-entry))
15170 (nth 1 arch-entry) 'vhdl-speedbar-find-file
15171 (cons (nth 2 arch-entry) (nth 3 arch-entry))
15172 'vhdl-speedbar-architecture-face (1+ indent))
15173 (when (and multiple-arch
15174 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
15175 (end-of-line 0) (insert " (mra)") (forward-char 1))
15176 (setq arch-alist (cdr arch-alist)))
15177 ;; insert instantiations
15178 (when inst-alist
15179 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
15180 (while inst-alist
15181 (setq inst-entry (car inst-alist))
15182 (vhdl-speedbar-make-inst-line
15183 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
15184 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
15185 nil nil nil (1+ indent) 0 " in ")
15186 (setq inst-alist (cdr inst-alist)))
15187 ;; insert required packages
15188 (vhdl-speedbar-insert-subpackages
15189 subpack-alist (1+ indent) indent)))
15190 (when (memq 'display vhdl-speedbar-save-cache)
15191 (add-to-list 'vhdl-updated-project-list key))
15192 (vhdl-speedbar-update-current-unit t t))))
15193 ((string-match "-" text) ; contract entity
15194 (speedbar-change-expand-button-char ?+)
15195 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
15196 (let* ((key (vhdl-speedbar-line-key indent))
15197 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15198 (vhdl-adelete 'unit-alist token)
15199 (if unit-alist
15200 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15201 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15202 (speedbar-delete-subblock indent)
15203 (when (memq 'display vhdl-speedbar-save-cache)
15204 (add-to-list 'vhdl-updated-project-list key))))
15205 (t (error "Nothing to display")))
15206 (when (equal (selected-frame) speedbar-frame)
15207 (speedbar-center-buffer-smartly)))
15209 (defun vhdl-speedbar-expand-architecture (text token indent)
15210 "Expand/contract the architecture under the cursor."
15211 (cond
15212 ((string-match "+" text) ; expand architecture
15213 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15214 (ent-alist (vhdl-aget vhdl-entity-alist key))
15215 (conf-alist (vhdl-aget vhdl-config-alist key))
15216 (hier-alist (vhdl-get-hierarchy
15217 ent-alist conf-alist (car token) (cdr token) nil nil
15218 0 (1- indent)))
15219 (ent-entry (vhdl-aget ent-alist (car token)))
15220 (arch-entry (vhdl-aget (nth 3 ent-entry) (cdr token)))
15221 (subpack-alist (nth 4 arch-entry))
15222 entry)
15223 (if (not (or hier-alist subpack-alist))
15224 (speedbar-change-expand-button-char ??)
15225 (speedbar-change-expand-button-char ?-)
15226 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15227 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15228 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15229 (vhdl-aput 'unit-alist (car token)
15230 (list (cons (cdr token) arch-alist)))
15231 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15232 (speedbar-with-writable
15233 (save-excursion
15234 (end-of-line) (forward-char 1)
15235 ;; insert instance hierarchy
15236 (when hier-alist
15237 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15238 (1+ indent)))
15239 (while hier-alist
15240 (setq entry (car hier-alist))
15241 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15242 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15243 (vhdl-speedbar-make-inst-line
15244 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15245 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15246 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
15247 (setq hier-alist (cdr hier-alist)))
15248 ;; insert required packages
15249 (vhdl-speedbar-insert-subpackages
15250 subpack-alist (1+ indent) (1- indent))))
15251 (when (memq 'display vhdl-speedbar-save-cache)
15252 (add-to-list 'vhdl-updated-project-list key))
15253 (vhdl-speedbar-update-current-unit t t))))
15254 ((string-match "-" text) ; contract architecture
15255 (speedbar-change-expand-button-char ?+)
15256 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15257 (let* ((key (vhdl-speedbar-line-key (1- indent)))
15258 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
15259 (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
15260 (vhdl-aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
15261 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15262 (speedbar-delete-subblock indent)
15263 (when (memq 'display vhdl-speedbar-save-cache)
15264 (add-to-list 'vhdl-updated-project-list key))))
15265 (t (error "Nothing to display")))
15266 (when (equal (selected-frame) speedbar-frame)
15267 (speedbar-center-buffer-smartly)))
15269 (defun vhdl-speedbar-expand-config (text token indent)
15270 "Expand/contract the configuration under the cursor."
15271 (cond
15272 ((string-match "+" text) ; expand configuration
15273 (let* ((key (vhdl-speedbar-line-key indent))
15274 (conf-alist (vhdl-aget vhdl-config-alist key))
15275 (conf-entry (vhdl-aget conf-alist token))
15276 (ent-alist (vhdl-aget vhdl-entity-alist key))
15277 (hier-alist (vhdl-get-hierarchy
15278 ent-alist conf-alist (nth 3 conf-entry)
15279 (nth 4 conf-entry) token (nth 5 conf-entry)
15280 0 indent t))
15281 (subpack-alist (nth 6 conf-entry))
15282 entry)
15283 (if (not (or hier-alist subpack-alist))
15284 (speedbar-change-expand-button-char ??)
15285 (speedbar-change-expand-button-char ?-)
15286 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15287 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15288 (vhdl-aput 'unit-alist token nil)
15289 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15290 (speedbar-with-writable
15291 (save-excursion
15292 (end-of-line) (forward-char 1)
15293 ;; insert instance hierarchy
15294 (when hier-alist
15295 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
15296 (while hier-alist
15297 (setq entry (car hier-alist))
15298 (when (or (= vhdl-speedbar-hierarchy-depth 0)
15299 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
15300 (vhdl-speedbar-make-inst-line
15301 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
15302 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
15303 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
15304 (setq hier-alist (cdr hier-alist)))
15305 ;; insert required packages
15306 (vhdl-speedbar-insert-subpackages
15307 subpack-alist (1+ indent) indent)))
15308 (when (memq 'display vhdl-speedbar-save-cache)
15309 (add-to-list 'vhdl-updated-project-list key))
15310 (vhdl-speedbar-update-current-unit t t))))
15311 ((string-match "-" text) ; contract configuration
15312 (speedbar-change-expand-button-char ?+)
15313 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15314 (let* ((key (vhdl-speedbar-line-key indent))
15315 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15316 (vhdl-adelete 'unit-alist token)
15317 (if unit-alist
15318 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15319 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15320 (speedbar-delete-subblock indent)
15321 (when (memq 'display vhdl-speedbar-save-cache)
15322 (add-to-list 'vhdl-updated-project-list key))))
15323 (t (error "Nothing to display")))
15324 (when (equal (selected-frame) speedbar-frame)
15325 (speedbar-center-buffer-smartly)))
15327 (defun vhdl-speedbar-expand-package (text token indent)
15328 "Expand/contract the package under the cursor."
15329 (cond
15330 ((string-match "+" text) ; expand package
15331 (let* ((key (vhdl-speedbar-line-key indent))
15332 (pack-alist (vhdl-aget vhdl-package-alist key))
15333 (pack-entry (vhdl-aget pack-alist token))
15334 (comp-alist (nth 3 pack-entry))
15335 (func-alist (nth 4 pack-entry))
15336 (func-body-alist (nth 8 pack-entry))
15337 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
15338 comp-entry func-entry func-body-entry)
15339 (if (not (or comp-alist func-alist subpack-alist))
15340 (speedbar-change-expand-button-char ??)
15341 (speedbar-change-expand-button-char ?-)
15342 ;; add package to `vhdl-speedbar-shown-unit-alist'
15343 (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15344 (vhdl-aput 'unit-alist token nil)
15345 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
15346 (speedbar-with-writable
15347 (save-excursion
15348 (end-of-line) (forward-char 1)
15349 ;; insert components
15350 (when comp-alist
15351 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
15352 (while comp-alist
15353 (setq comp-entry (car comp-alist))
15354 (speedbar-make-tag-line
15355 nil nil nil
15356 (cons token (nth 0 comp-entry))
15357 (nth 1 comp-entry) 'vhdl-speedbar-find-file
15358 (cons (nth 2 comp-entry) (nth 3 comp-entry))
15359 'vhdl-speedbar-entity-face (1+ indent))
15360 (setq comp-alist (cdr comp-alist)))
15361 ;; insert subprograms
15362 (when func-alist
15363 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
15364 (while func-alist
15365 (setq func-entry (car func-alist)
15366 func-body-entry (vhdl-aget func-body-alist
15367 (car func-entry)))
15368 (when (nth 2 func-entry)
15369 (vhdl-speedbar-make-subprogram-line
15370 (nth 1 func-entry)
15371 (cons (nth 2 func-entry) (nth 3 func-entry))
15372 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
15373 (1+ indent)))
15374 (setq func-alist (cdr func-alist)))
15375 ;; insert required packages
15376 (vhdl-speedbar-insert-subpackages
15377 subpack-alist (1+ indent) indent)))
15378 (when (memq 'display vhdl-speedbar-save-cache)
15379 (add-to-list 'vhdl-updated-project-list key))
15380 (vhdl-speedbar-update-current-unit t t))))
15381 ((string-match "-" text) ; contract package
15382 (speedbar-change-expand-button-char ?+)
15383 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15384 (let* ((key (vhdl-speedbar-line-key indent))
15385 (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
15386 (vhdl-adelete 'unit-alist token)
15387 (if unit-alist
15388 (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15389 (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
15390 (speedbar-delete-subblock indent)
15391 (when (memq 'display vhdl-speedbar-save-cache)
15392 (add-to-list 'vhdl-updated-project-list key))))
15393 (t (error "Nothing to display")))
15394 (when (equal (selected-frame) speedbar-frame)
15395 (speedbar-center-buffer-smartly)))
15397 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15398 "Insert required packages."
15399 (let* ((pack-alist (vhdl-aget vhdl-package-alist
15400 (vhdl-speedbar-line-key dir-indent)))
15401 pack-key lib-name pack-entry)
15402 (when subpack-alist
15403 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15404 (while subpack-alist
15405 (setq pack-key (cdar subpack-alist)
15406 lib-name (caar subpack-alist))
15407 (setq pack-entry (vhdl-aget pack-alist pack-key))
15408 (vhdl-speedbar-make-subpack-line
15409 (or (nth 0 pack-entry) pack-key) lib-name
15410 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15411 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15412 (setq subpack-alist (cdr subpack-alist)))))
15414 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15415 ;; Display help functions
15417 (defvar vhdl-speedbar-update-current-unit t
15418 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15420 (defun vhdl-speedbar-update-current-project ()
15421 "Highlight project that is currently active."
15422 (when (and vhdl-speedbar-show-projects
15423 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15424 (and (boundp 'speedbar-frame)
15425 (frame-live-p speedbar-frame)))
15426 (let ((last-frame (selected-frame))
15427 (project-alist vhdl-project-alist)
15428 pos)
15429 (select-frame speedbar-frame)
15430 (speedbar-with-writable
15431 (save-excursion
15432 (while project-alist
15433 (goto-char (point-min))
15434 (when (re-search-forward
15435 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15436 (put-text-property (match-beginning 1) (match-end 1) 'face
15437 (if (equal (caar project-alist) vhdl-project)
15438 'speedbar-selected-face
15439 'speedbar-directory-face))
15440 (when (equal (caar project-alist) vhdl-project)
15441 (setq pos (1- (match-beginning 1)))))
15442 (setq project-alist (cdr project-alist))))
15443 (when pos (goto-char pos)))
15444 (select-frame last-frame)
15445 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15448 (declare-function speedbar-position-cursor-on-line "speedbar" ())
15450 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15451 "Highlight all design units that are contained in the current file.
15452 NO-POSITION non-nil means do not re-position cursor."
15453 (let ((last-frame (selected-frame))
15454 (project-list vhdl-speedbar-shown-project-list)
15455 file-alist pos file-name)
15456 ;; get current file name
15457 (if (fboundp 'speedbar-select-attached-frame)
15458 (speedbar-select-attached-frame)
15459 (select-frame speedbar-attached-frame))
15460 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15461 (when (and vhdl-speedbar-update-current-unit
15462 (or always (not (equal file-name speedbar-last-selected-file))))
15463 (if vhdl-speedbar-show-projects
15464 (while project-list
15465 (setq file-alist (append file-alist
15466 (vhdl-aget vhdl-file-alist
15467 (car project-list))))
15468 (setq project-list (cdr project-list)))
15469 (setq file-alist
15470 (vhdl-aget vhdl-file-alist
15471 (abbreviate-file-name default-directory))))
15472 (select-frame speedbar-frame)
15473 (set-buffer speedbar-buffer)
15474 (speedbar-with-writable
15475 (vhdl-prepare-search-1
15476 (save-excursion
15477 ;; unhighlight last units
15478 (let* ((file-entry (vhdl-aget file-alist
15479 speedbar-last-selected-file)))
15480 (vhdl-speedbar-update-units
15481 "\\[.\\] " (nth 0 file-entry)
15482 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15483 (vhdl-speedbar-update-units
15484 "{.} " (nth 1 file-entry)
15485 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15486 (vhdl-speedbar-update-units
15487 "\\[.\\] " (nth 3 file-entry)
15488 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15489 (vhdl-speedbar-update-units
15490 "[]>] " (nth 4 file-entry)
15491 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15492 (vhdl-speedbar-update-units
15493 "\\[.\\].+(" '("body")
15494 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15495 (vhdl-speedbar-update-units
15496 "> " (nth 6 file-entry)
15497 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15498 ;; highlight current units
15499 (let* ((file-entry (vhdl-aget file-alist file-name)))
15500 (setq
15501 pos (vhdl-speedbar-update-units
15502 "\\[.\\] " (nth 0 file-entry)
15503 file-name 'vhdl-speedbar-entity-selected-face pos)
15504 pos (vhdl-speedbar-update-units
15505 "{.} " (nth 1 file-entry)
15506 file-name 'vhdl-speedbar-architecture-selected-face pos)
15507 pos (vhdl-speedbar-update-units
15508 "\\[.\\] " (nth 3 file-entry)
15509 file-name 'vhdl-speedbar-configuration-selected-face pos)
15510 pos (vhdl-speedbar-update-units
15511 "[]>] " (nth 4 file-entry)
15512 file-name 'vhdl-speedbar-package-selected-face pos)
15513 pos (vhdl-speedbar-update-units
15514 "\\[.\\].+(" '("body")
15515 file-name 'vhdl-speedbar-package-selected-face pos)
15516 pos (vhdl-speedbar-update-units
15517 "> " (nth 6 file-entry)
15518 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15519 ;; move speedbar so the first highlighted unit is visible
15520 (when (and pos (not no-position))
15521 (goto-char pos)
15522 (speedbar-center-buffer-smartly)
15523 (speedbar-position-cursor-on-line))
15524 (setq speedbar-last-selected-file file-name))
15525 (select-frame last-frame)
15528 (defun vhdl-speedbar-update-units (text unit-list file-name face
15529 &optional pos)
15530 "Help function to highlight design units."
15531 (while unit-list
15532 (goto-char (point-min))
15533 (while (re-search-forward
15534 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15535 (when (equal file-name (car (get-text-property
15536 (match-beginning 1) 'speedbar-token)))
15537 (setq pos (or pos (point-marker)))
15538 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15539 (setq unit-list (cdr unit-list)))
15540 pos)
15542 (declare-function speedbar-make-button "speedbar"
15543 (start end face mouse function &optional token))
15545 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15546 ent-name ent-file-marker
15547 arch-name arch-file-marker
15548 conf-name conf-file-marker
15549 lib-name depth offset delimiter)
15550 "Insert instantiation entry."
15551 (let ((start (point))
15552 visible-start)
15553 (insert (int-to-string depth) ":")
15554 (put-text-property start (point) 'invisible t)
15555 (setq visible-start (point))
15556 (insert-char ? (* depth speedbar-indentation-width))
15557 (while (> offset 0)
15558 (insert "|")
15559 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15560 (setq offset (1- offset)))
15561 (put-text-property visible-start (point) 'invisible nil)
15562 (setq start (point))
15563 (insert ">")
15564 (speedbar-make-button start (point) nil nil nil)
15565 (setq visible-start (point))
15566 (insert " ")
15567 (setq start (point))
15568 (if (not inst-name)
15569 (insert "(top)")
15570 (insert inst-name)
15571 (speedbar-make-button
15572 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15573 'vhdl-speedbar-find-file inst-file-marker))
15574 (insert delimiter)
15575 (when ent-name
15576 (setq start (point))
15577 (insert ent-name)
15578 (speedbar-make-button
15579 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15580 'vhdl-speedbar-find-file ent-file-marker)
15581 (when arch-name
15582 (insert " (")
15583 (setq start (point))
15584 (insert arch-name)
15585 (speedbar-make-button
15586 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15587 'vhdl-speedbar-find-file arch-file-marker)
15588 (insert ")"))
15589 (when conf-name
15590 (insert " (")
15591 (setq start (point))
15592 (insert conf-name)
15593 (speedbar-make-button
15594 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15595 'vhdl-speedbar-find-file conf-file-marker)
15596 (insert ")")))
15597 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15598 (setq start (point))
15599 (insert " (" lib-name ")")
15600 (put-text-property (+ 2 start) (1- (point)) 'face
15601 'vhdl-speedbar-library-face))
15602 (insert-char ?\n 1)
15603 (put-text-property visible-start (point) 'invisible nil)))
15605 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15606 body-file-marker depth)
15607 "Insert package entry."
15608 (let ((start (point))
15609 visible-start)
15610 (insert (int-to-string depth) ":")
15611 (put-text-property start (point) 'invisible t)
15612 (setq visible-start (point))
15613 (insert-char ? (* depth speedbar-indentation-width))
15614 (put-text-property visible-start (point) 'invisible nil)
15615 (setq start (point))
15616 (insert "[+]")
15617 (speedbar-make-button
15618 start (point) 'speedbar-button-face 'speedbar-highlight-face
15619 'vhdl-speedbar-expand-package pack-key)
15620 (setq visible-start (point))
15621 (insert-char ? 1 nil)
15622 (setq start (point))
15623 (insert pack-name)
15624 (speedbar-make-button
15625 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15626 'vhdl-speedbar-find-file pack-file-marker)
15627 (unless (car pack-file-marker)
15628 (insert "!"))
15629 (when (car body-file-marker)
15630 (insert " (")
15631 (setq start (point))
15632 (insert "body")
15633 (speedbar-make-button
15634 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15635 'vhdl-speedbar-find-file body-file-marker)
15636 (insert ")"))
15637 (insert-char ?\n 1)
15638 (put-text-property visible-start (point) 'invisible nil)))
15640 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15641 pack-body-file-marker depth)
15642 "Insert used package entry."
15643 (let ((start (point))
15644 visible-start)
15645 (insert (int-to-string depth) ":")
15646 (put-text-property start (point) 'invisible t)
15647 (setq visible-start (point))
15648 (insert-char ? (* depth speedbar-indentation-width))
15649 (put-text-property visible-start (point) 'invisible nil)
15650 (setq start (point))
15651 (insert ">")
15652 (speedbar-make-button start (point) nil nil nil)
15653 (setq visible-start (point))
15654 (insert " ")
15655 (setq start (point))
15656 (insert pack-name)
15657 (speedbar-make-button
15658 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15659 'vhdl-speedbar-find-file pack-file-marker)
15660 (when (car pack-body-file-marker)
15661 (insert " (")
15662 (setq start (point))
15663 (insert "body")
15664 (speedbar-make-button
15665 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15666 'vhdl-speedbar-find-file pack-body-file-marker)
15667 (insert ")"))
15668 (setq start (point))
15669 (insert " (" lib-name ")")
15670 (put-text-property (+ 2 start) (1- (point)) 'face
15671 'vhdl-speedbar-library-face)
15672 (insert-char ?\n 1)
15673 (put-text-property visible-start (point) 'invisible nil)))
15675 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15676 func-body-file-marker
15677 depth)
15678 "Insert subprogram entry."
15679 (let ((start (point))
15680 visible-start)
15681 (insert (int-to-string depth) ":")
15682 (put-text-property start (point) 'invisible t)
15683 (setq visible-start (point))
15684 (insert-char ? (* depth speedbar-indentation-width))
15685 (put-text-property visible-start (point) 'invisible nil)
15686 (setq start (point))
15687 (insert ">")
15688 (speedbar-make-button start (point) nil nil nil)
15689 (setq visible-start (point))
15690 (insert " ")
15691 (setq start (point))
15692 (insert func-name)
15693 (speedbar-make-button
15694 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15695 'vhdl-speedbar-find-file func-file-marker)
15696 (when (car func-body-file-marker)
15697 (insert " (")
15698 (setq start (point))
15699 (insert "body")
15700 (speedbar-make-button
15701 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15702 'vhdl-speedbar-find-file func-body-file-marker)
15703 (insert ")"))
15704 (insert-char ?\n 1)
15705 (put-text-property visible-start (point) 'invisible nil)))
15707 (defun vhdl-speedbar-make-title-line (text &optional depth)
15708 "Insert design unit title entry."
15709 (let ((start (point))
15710 visible-start)
15711 (when depth
15712 (insert (int-to-string depth) ":")
15713 (put-text-property start (point) 'invisible t))
15714 (setq visible-start (point))
15715 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15716 (setq start (point))
15717 (insert text)
15718 (speedbar-make-button start (point) nil nil nil nil)
15719 (insert-char ?\n 1)
15720 (put-text-property visible-start (point) 'invisible nil)))
15722 (defun vhdl-speedbar-insert-dirs (files level)
15723 "Insert subdirectories."
15724 (let ((dirs (car files)))
15725 (while dirs
15726 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15727 (car dirs) 'speedbar-dir-follow nil
15728 'speedbar-directory-face level)
15729 (setq dirs (cdr dirs)))))
15731 (declare-function speedbar-reset-scanners "speedbar" ())
15733 (defun vhdl-speedbar-dired (text token indent)
15734 "Speedbar click handler for directory expand button in hierarchy mode."
15735 (cond ((string-match "+" text) ; we have to expand this dir
15736 (setq speedbar-shown-directories
15737 (cons (expand-file-name
15738 (concat (speedbar-line-directory indent) token "/"))
15739 speedbar-shown-directories))
15740 (speedbar-change-expand-button-char ?-)
15741 (speedbar-reset-scanners)
15742 (speedbar-with-writable
15743 (save-excursion
15744 (end-of-line) (forward-char 1)
15745 (vhdl-speedbar-insert-dirs
15746 (speedbar-file-lists
15747 (concat (speedbar-line-directory indent) token "/"))
15748 (1+ indent))
15749 (speedbar-reset-scanners)
15750 (vhdl-speedbar-insert-dir-hierarchy
15751 (abbreviate-file-name
15752 (concat (speedbar-line-directory indent) token "/"))
15753 (1+ indent) speedbar-power-click)))
15754 (vhdl-speedbar-update-current-unit t t))
15755 ((string-match "-" text) ; we have to contract this node
15756 (speedbar-reset-scanners)
15757 (let ((oldl speedbar-shown-directories)
15758 (newl nil)
15759 (td (expand-file-name
15760 (concat (speedbar-line-directory indent) token))))
15761 (while oldl
15762 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15763 (push (car oldl) newl))
15764 (setq oldl (cdr oldl)))
15765 (setq speedbar-shown-directories (nreverse newl)))
15766 (speedbar-change-expand-button-char ?+)
15767 (speedbar-delete-subblock indent))
15768 (t (error "Nothing to display")))
15769 (when (equal (selected-frame) speedbar-frame)
15770 (speedbar-center-buffer-smartly)))
15772 (declare-function speedbar-files-item-info "speedbar" ())
15774 (defun vhdl-speedbar-item-info ()
15775 "Derive and display information about this line item."
15776 (save-excursion
15777 (beginning-of-line)
15778 ;; skip invisible number info
15779 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15780 (cond
15781 ;; project/directory entry
15782 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15783 (if vhdl-speedbar-show-projects
15784 (message "Project \"%s\"" (match-string-no-properties 1))
15785 (speedbar-files-item-info)))
15786 ;; design unit entry
15787 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15788 (goto-char (match-end 1))
15789 (let ((face (get-text-property (point) 'face)))
15790 (message
15791 "%s \"%s\" in \"%s\""
15792 ;; design unit kind
15793 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15794 (eq face 'vhdl-speedbar-entity-selected-face))
15795 (if (equal (match-string 2) ">") "Component" "Entity"))
15796 ((or (eq face 'vhdl-speedbar-architecture-face)
15797 (eq face 'vhdl-speedbar-architecture-selected-face))
15798 "Architecture")
15799 ((or (eq face 'vhdl-speedbar-configuration-face)
15800 (eq face 'vhdl-speedbar-configuration-selected-face))
15801 "Configuration")
15802 ((or (eq face 'vhdl-speedbar-package-face)
15803 (eq face 'vhdl-speedbar-package-selected-face))
15804 "Package")
15805 ((or (eq face 'vhdl-speedbar-instantiation-face)
15806 (eq face 'vhdl-speedbar-instantiation-selected-face))
15807 "Instantiation")
15808 ((eq face 'vhdl-speedbar-subprogram-face)
15809 "Subprogram")
15810 (t ""))
15811 ;; design unit name
15812 (buffer-substring-no-properties
15813 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15814 (match-end 1))
15815 ;; file name
15816 (file-relative-name
15817 (or (car (get-text-property (point) 'speedbar-token))
15818 "?")
15819 (vhdl-default-directory)))))
15820 (t (message "")))))
15822 (declare-function speedbar-line-text "speedbar" (&optional p))
15824 (defun vhdl-speedbar-line-text ()
15825 "Calls `speedbar-line-text' and removes text properties."
15826 (let ((string (speedbar-line-text)))
15827 (set-text-properties 0 (length string) nil string)
15828 string))
15830 (defun vhdl-speedbar-higher-text ()
15831 "Get speedbar-line-text of higher level."
15832 (let (depth string)
15833 (save-excursion
15834 (beginning-of-line)
15835 (looking-at "^\\([0-9]+\\):")
15836 (setq depth (string-to-number (match-string 1)))
15837 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15838 (setq string (match-string 1))
15839 (set-text-properties 0 (length string) nil string)
15840 string))))
15842 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15843 ;; Help functions
15845 (defun vhdl-speedbar-line-key (&optional indent)
15846 "Get currently displayed directory of project name."
15847 (if vhdl-speedbar-show-projects
15848 (vhdl-speedbar-line-project)
15849 (abbreviate-file-name
15850 (file-name-as-directory (speedbar-line-directory indent)))))
15852 (defun vhdl-speedbar-line-project (&optional indent)
15853 "Get currently displayed project name."
15854 (and vhdl-speedbar-show-projects
15855 (save-excursion
15856 (end-of-line)
15857 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15858 (match-string-no-properties 1))))
15860 (defun vhdl-add-modified-file ()
15861 "Add file to `vhdl-modified-file-list'."
15862 (when vhdl-file-alist
15863 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15864 nil)
15866 (defun vhdl-resolve-paths (path-list)
15867 "Resolve path wildcards in PATH-LIST."
15868 (let (path-list-1 path-list-2 path-beg path-end dir)
15869 ;; eliminate non-existent directories
15870 (while path-list
15871 (setq dir (car path-list))
15872 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15873 (if (file-directory-p (match-string 2 dir))
15874 (push dir path-list-1)
15875 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15876 (setq path-list (cdr path-list)))
15877 ;; resolve path wildcards
15878 (while path-list-1
15879 (setq dir (car path-list-1))
15880 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15881 (progn
15882 (setq path-beg (match-string 1 dir)
15883 path-end (match-string 5 dir))
15884 (setq path-list-1
15885 (append
15886 (mapcar
15887 (function
15888 (lambda (var) (concat path-beg var path-end)))
15889 (let ((all-list (vhdl-directory-files
15890 (match-string 2 dir) t
15891 (concat "\\<" (wildcard-to-regexp
15892 (match-string 4 dir)))))
15893 dir-list)
15894 (while all-list
15895 (when (file-directory-p (car all-list))
15896 (push (car all-list) dir-list))
15897 (setq all-list (cdr all-list)))
15898 dir-list))
15899 (cdr path-list-1))))
15900 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15901 (when (file-directory-p (match-string 2 dir))
15902 (push dir path-list-2))
15903 (setq path-list-1 (cdr path-list-1))))
15904 (nreverse path-list-2)))
15906 (defun vhdl-speedbar-goto-this-unit (directory unit)
15907 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15908 (let ((dest (point)))
15909 (if (and (if vhdl-speedbar-show-projects
15910 (progn (goto-char (point-min)) t)
15911 (speedbar-goto-this-file directory))
15912 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15913 (progn (speedbar-position-cursor-on-line)
15915 (goto-char dest)
15916 nil)))
15918 (declare-function speedbar-find-file-in-frame "speedbar" (file))
15919 (declare-function speedbar-set-timer "speedbar" (timeout))
15920 ;; speedbar loads dframe at runtime.
15921 (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
15923 (defun vhdl-speedbar-find-file (text token indent)
15924 "When user clicks on TEXT, load file with name and position in TOKEN.
15925 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15926 is already shown in a buffer."
15927 (if (not (car token))
15928 (error "ERROR: File cannot be found")
15929 (let ((buffer (get-file-buffer (car token))))
15930 (speedbar-find-file-in-frame (car token))
15931 (when (or vhdl-speedbar-jump-to-unit buffer)
15932 (goto-char (point-min))
15933 (forward-line (1- (cdr token)))
15934 (recenter))
15935 (vhdl-speedbar-update-current-unit t t)
15936 (speedbar-set-timer dframe-update-speed)
15937 (dframe-maybee-jump-to-attached-frame))))
15939 (defun vhdl-speedbar-port-copy ()
15940 "Copy the port of the entity/component or subprogram under the cursor."
15941 (interactive)
15942 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15943 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15944 (error "ERROR: No entity/component or subprogram under cursor")
15945 (beginning-of-line)
15946 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15947 (condition-case info
15948 (let ((token (get-text-property
15949 (match-beginning 3) 'speedbar-token)))
15950 (vhdl-visit-file (car token) t
15951 (progn (goto-char (point-min))
15952 (forward-line (1- (cdr token)))
15953 (end-of-line)
15954 (if is-entity
15955 (vhdl-port-copy)
15956 (vhdl-subprog-copy)))))
15957 (error (error "ERROR: %s not scanned successfully\n (%s)"
15958 (if is-entity "Port" "Interface") (cadr info))))
15959 (error "ERROR: No entity/component or subprogram on current line")))))
15961 (defun vhdl-speedbar-place-component ()
15962 "Place the entity/component under the cursor as component."
15963 (interactive)
15964 (if (not (vhdl-speedbar-check-unit 'entity))
15965 (error "ERROR: No entity/component under cursor")
15966 (vhdl-speedbar-port-copy)
15967 (if (fboundp 'speedbar-select-attached-frame)
15968 (speedbar-select-attached-frame)
15969 (select-frame speedbar-attached-frame))
15970 (vhdl-compose-place-component)
15971 (select-frame speedbar-frame)))
15973 (defun vhdl-speedbar-configuration ()
15974 "Generate configuration for the architecture under the cursor."
15975 (interactive)
15976 (if (not (vhdl-speedbar-check-unit 'architecture))
15977 (error "ERROR: No architecture under cursor")
15978 (let ((arch-name (vhdl-speedbar-line-text))
15979 (ent-name (vhdl-speedbar-higher-text)))
15980 (if (fboundp 'speedbar-select-attached-frame)
15981 (speedbar-select-attached-frame)
15982 (select-frame speedbar-attached-frame))
15983 (vhdl-compose-configuration ent-name arch-name))))
15985 (defun vhdl-speedbar-select-mra ()
15986 "Select the architecture under the cursor as MRA."
15987 (interactive)
15988 (if (not (vhdl-speedbar-check-unit 'architecture))
15989 (error "ERROR: No architecture under cursor")
15990 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15991 (ent-key (downcase (vhdl-speedbar-higher-text)))
15992 (ent-alist (vhdl-aget
15993 vhdl-entity-alist
15994 (or (vhdl-project-p)
15995 (abbreviate-file-name default-directory))))
15996 (ent-entry (vhdl-aget ent-alist ent-key)))
15997 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15998 (speedbar-refresh))))
16000 (declare-function speedbar-line-file "speedbar" (&optional p))
16002 (defun vhdl-speedbar-make-design ()
16003 "Make (compile) design unit or directory/project under the cursor."
16004 (interactive)
16005 (if (not (save-excursion (beginning-of-line)
16006 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
16007 (error "ERROR: No primary design unit or directory/project under cursor")
16008 (let ((is-unit (match-string 2))
16009 (unit-name (vhdl-speedbar-line-text))
16010 (vhdl-project (vhdl-speedbar-line-project))
16011 (directory (file-name-as-directory
16012 (or (speedbar-line-file) (speedbar-line-directory)))))
16013 (if (fboundp 'speedbar-select-attached-frame)
16014 (speedbar-select-attached-frame)
16015 (select-frame speedbar-attached-frame))
16016 (let ((default-directory directory))
16017 (vhdl-make (and is-unit unit-name))))))
16019 (defun vhdl-speedbar-generate-makefile ()
16020 "Generate Makefile for directory/project under the cursor."
16021 (interactive)
16022 (let ((vhdl-project (vhdl-speedbar-line-project))
16023 (default-directory (file-name-as-directory
16024 (or (speedbar-line-file) (speedbar-line-directory)))))
16025 (vhdl-generate-makefile)))
16027 (defun vhdl-speedbar-check-unit (design-unit)
16028 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
16029 expansion function)."
16030 (save-excursion
16031 (speedbar-position-cursor-on-line)
16032 (cond ((eq design-unit 'entity)
16033 (memq (get-text-property (match-end 0) 'face)
16034 '(vhdl-speedbar-entity-face
16035 vhdl-speedbar-entity-selected-face)))
16036 ((eq design-unit 'architecture)
16037 (memq (get-text-property (match-end 0) 'face)
16038 '(vhdl-speedbar-architecture-face
16039 vhdl-speedbar-architecture-selected-face)))
16040 ((eq design-unit 'subprogram)
16041 (eq (get-text-property (match-end 0) 'face)
16042 'vhdl-speedbar-subprogram-face))
16043 (t nil))))
16045 (defun vhdl-speedbar-set-depth (depth)
16046 "Set hierarchy display depth to DEPTH and refresh speedbar."
16047 (setq vhdl-speedbar-hierarchy-depth depth)
16048 (speedbar-refresh))
16050 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16051 ;; Fontification
16053 (defface vhdl-speedbar-entity-face
16054 '((((class color) (background light)) (:foreground "ForestGreen"))
16055 (((class color) (background dark)) (:foreground "PaleGreen")))
16056 "Face used for displaying entity names."
16057 :group 'speedbar-faces)
16059 (defface vhdl-speedbar-architecture-face
16060 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
16061 (((class color) (background light)) (:foreground "Blue"))
16063 (((class color) (background dark)) (:foreground "LightSkyBlue")))
16064 "Face used for displaying architecture names."
16065 :group 'speedbar-faces)
16067 (defface vhdl-speedbar-configuration-face
16068 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
16069 (((class color) (background dark)) (:foreground "Salmon")))
16070 "Face used for displaying configuration names."
16071 :group 'speedbar-faces)
16073 (defface vhdl-speedbar-package-face
16074 '((((class color) (background light)) (:foreground "Grey50"))
16075 (((class color) (background dark)) (:foreground "Grey80")))
16076 "Face used for displaying package names."
16077 :group 'speedbar-faces)
16079 (defface vhdl-speedbar-library-face
16080 '((((class color) (background light)) (:foreground "Purple"))
16081 (((class color) (background dark)) (:foreground "Orchid1")))
16082 "Face used for displaying library names."
16083 :group 'speedbar-faces)
16085 (defface vhdl-speedbar-instantiation-face
16086 '((((class color) (background light)) (:foreground "Brown"))
16087 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
16088 (((class color) (background dark)) (:foreground "Yellow")))
16089 "Face used for displaying instantiation names."
16090 :group 'speedbar-faces)
16092 (defface vhdl-speedbar-subprogram-face
16093 '((((class color) (background light)) (:foreground "Orchid4"))
16094 (((class color) (background dark)) (:foreground "BurlyWood2")))
16095 "Face used for displaying subprogram names."
16096 :group 'speedbar-faces)
16098 (defface vhdl-speedbar-entity-selected-face
16099 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
16100 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
16101 "Face used for displaying entity names."
16102 :group 'speedbar-faces)
16104 (defface vhdl-speedbar-architecture-selected-face
16105 '((((min-colors 88) (class color) (background light)) (:foreground
16106 "Blue1" :underline t))
16107 (((class color) (background light)) (:foreground "Blue" :underline t))
16108 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
16109 "Face used for displaying architecture names."
16110 :group 'speedbar-faces)
16112 (defface vhdl-speedbar-configuration-selected-face
16113 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
16114 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
16115 "Face used for displaying configuration names."
16116 :group 'speedbar-faces)
16118 (defface vhdl-speedbar-package-selected-face
16119 '((((class color) (background light)) (:foreground "Grey50" :underline t))
16120 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
16121 "Face used for displaying package names."
16122 :group 'speedbar-faces)
16124 (defface vhdl-speedbar-instantiation-selected-face
16125 '((((class color) (background light)) (:foreground "Brown" :underline t))
16126 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
16127 "Face used for displaying instantiation names."
16128 :group 'speedbar-faces)
16130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16131 ;; Initialization
16133 ;; add speedbar
16134 (when (fboundp 'speedbar)
16135 (let ((current-frame (selected-frame)))
16136 (condition-case ()
16137 (when (and vhdl-speedbar-auto-open
16138 (not (and (boundp 'speedbar-frame)
16139 (frame-live-p speedbar-frame))))
16140 (speedbar-frame-mode 1))
16141 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar")))
16142 (select-frame current-frame)))
16144 ;; initialize speedbar
16145 (if (not (boundp 'speedbar-frame))
16146 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
16147 (vhdl-speedbar-initialize)
16148 (when speedbar-frame (vhdl-speedbar-refresh)))
16151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16152 ;;; Structural composition
16153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16155 (defun vhdl-get-components-package-name ()
16156 "Return the name of the components package."
16157 (let ((project (vhdl-project-p)))
16158 (if project
16159 (vhdl-replace-string (car vhdl-components-package-name)
16160 (subst-char-in-string ? ?_ project))
16161 (cdr vhdl-components-package-name))))
16163 (defun vhdl-compose-new-component ()
16164 "Create entity and architecture for new component."
16165 (interactive)
16166 (let* ((case-fold-search t)
16167 (ent-name (read-from-minibuffer "entity name: "
16168 nil vhdl-minibuffer-local-map))
16169 (arch-name
16170 (if (equal (cdr vhdl-compose-architecture-name) "")
16171 (read-from-minibuffer "architecture name: "
16172 nil vhdl-minibuffer-local-map)
16173 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
16174 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
16175 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
16176 ;; open entity file
16177 (unless (eq vhdl-compose-create-files 'none)
16178 (setq ent-file-name
16179 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16180 "." (file-name-extension (buffer-file-name))))
16181 (when (and (file-exists-p ent-file-name)
16182 (not (y-or-n-p (concat "File \"" ent-file-name
16183 "\" exists; overwrite? "))))
16184 (error "ERROR: Creating component...aborted"))
16185 (find-file ent-file-name)
16186 (erase-buffer)
16187 (set-buffer-modified-p nil))
16188 ;; insert header
16189 (if vhdl-compose-include-header
16190 (progn (vhdl-template-header)
16191 (setq end-pos (point))
16192 (goto-char (point-max)))
16193 (vhdl-comment-display-line) (insert "\n\n"))
16194 ;; insert library clause
16195 (vhdl-template-package-std-logic-1164)
16196 (when vhdl-use-components-package
16197 (insert "\n")
16198 (vhdl-template-standard-package (vhdl-work-library)
16199 (vhdl-get-components-package-name)))
16200 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
16201 ;; insert entity declaration
16202 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
16203 (vhdl-insert-keyword " IS\n")
16204 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16205 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
16206 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16207 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16208 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
16209 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
16210 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
16211 (vhdl-insert-keyword "END ")
16212 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
16213 (insert ent-name ";\n\n")
16214 (vhdl-comment-display-line) (insert "\n")
16215 ;; open architecture file
16216 (if (not (eq vhdl-compose-create-files 'separate))
16217 (insert "\n")
16218 (goto-char (or end-pos (point-min)))
16219 (setq ent-buffer (current-buffer))
16220 (setq arch-file-name
16221 (concat (vhdl-replace-string vhdl-architecture-file-name
16222 (concat ent-name " " arch-name) t)
16223 "." (file-name-extension (buffer-file-name))))
16224 (when (and (file-exists-p arch-file-name)
16225 (not (y-or-n-p (concat "File \"" arch-file-name
16226 "\" exists; overwrite? "))))
16227 (error "ERROR: Creating component...aborted"))
16228 (find-file arch-file-name)
16229 (erase-buffer)
16230 (set-buffer-modified-p nil)
16231 ;; insert header
16232 (if vhdl-compose-include-header
16233 (progn (vhdl-template-header)
16234 (goto-char (point-max)))
16235 (vhdl-comment-display-line) (insert "\n\n")))
16236 ;; insert architecture body
16237 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
16238 (vhdl-insert-keyword " OF ") (insert ent-name)
16239 (vhdl-insert-keyword " IS\n\n")
16240 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16241 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
16242 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16243 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
16244 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16245 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16246 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
16247 (vhdl-insert-keyword "BEGIN")
16248 (when vhdl-self-insert-comments
16249 (insert " -- ")
16250 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16251 (insert arch-name))
16252 (insert "\n\n")
16253 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16254 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
16255 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16256 (vhdl-insert-keyword "END ")
16257 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16258 (insert arch-name ";\n\n")
16259 ;; insert footer and save
16260 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16261 (vhdl-template-footer)
16262 (vhdl-comment-display-line) (insert "\n"))
16263 (goto-char (or end-pos (point-min)))
16264 (setq arch-buffer (current-buffer))
16265 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
16266 (set-buffer arch-buffer) (save-buffer)
16267 (message "%s"
16268 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
16269 (and ent-file-name
16270 (format "\n File created: \"%s\"" ent-file-name))
16271 (and arch-file-name
16272 (format "\n File created: \"%s\"" arch-file-name))))))
16274 (defun vhdl-compose-place-component ()
16275 "Place new component by pasting current port as component declaration and
16276 component instantiation."
16277 (interactive)
16278 (if (not vhdl-port-list)
16279 (error "ERROR: No port has been read")
16280 (save-excursion
16281 (vhdl-prepare-search-2
16282 (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)
16283 (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))
16284 (error "ERROR: No architecture found"))
16285 (let* ((ent-name (match-string 1))
16286 (ent-file-name
16287 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16288 "." (file-name-extension (buffer-file-name))))
16289 (orig-buffer (current-buffer)))
16290 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
16291 ;; place component declaration
16292 (unless (or vhdl-use-components-package
16293 (vhdl-use-direct-instantiation)
16294 (save-excursion
16295 (re-search-forward
16296 (concat "^\\s-*component\\s-+"
16297 (car vhdl-port-list) "\\>") nil t)))
16298 (re-search-forward "^begin\\>" nil)
16299 (beginning-of-line)
16300 (skip-chars-backward " \t\n\r\f")
16301 (insert "\n\n") (indent-to vhdl-basic-offset)
16302 (vhdl-port-paste-component t))
16303 ;; place component instantiation
16304 (re-search-forward "^end\\>" nil)
16305 (beginning-of-line)
16306 (skip-chars-backward " \t\n\r\f")
16307 (insert "\n\n") (indent-to vhdl-basic-offset)
16308 (vhdl-port-paste-instance nil t t)
16309 ;; place use clause for used packages
16310 (when (nth 3 vhdl-port-list)
16311 ;; open entity file
16312 (when (file-exists-p ent-file-name)
16313 (find-file ent-file-name))
16314 (goto-char (point-min))
16315 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16316 (error "ERROR: Entity not found: \"%s\"" ent-name))
16317 (goto-char (match-beginning 0))
16318 (if (and (save-excursion
16319 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
16320 (match-string 1))
16321 (progn (goto-char (match-end 0))
16322 (beginning-of-line 2))
16323 (insert "\n")
16324 (backward-char))
16325 (vhdl-port-paste-context-clause)
16326 (switch-to-buffer orig-buffer))
16327 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
16329 (defun vhdl-compose-wire-components ()
16330 "Connect components."
16331 (interactive)
16332 (save-excursion
16333 (vhdl-prepare-search-2
16334 (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)
16335 (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))
16336 (error "ERROR: No architecture found"))
16337 (let* ((ent-name (match-string 1))
16338 (ent-file-name
16339 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
16340 "." (file-name-extension (buffer-file-name))))
16341 (arch-decl-pos (point-marker))
16342 (arch-stat-pos (re-search-forward "^begin\\>" nil))
16343 (arch-end-pos (re-search-forward "^end\\>" nil))
16344 (pack-name (vhdl-get-components-package-name))
16345 (pack-file-name
16346 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16347 "." (file-name-extension (buffer-file-name))))
16348 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16349 port-alist generic-alist inst-alist
16350 signal-name signal-entry signal-alist local-list written-list
16351 single-in-list multi-in-list single-out-list multi-out-list
16352 constant-name constant-entry constant-alist single-list multi-list
16353 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16354 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16355 signal-beg-pos signal-pos
16356 constant-temp-pos port-temp-pos signal-temp-pos)
16357 (message "Wiring components...")
16358 ;; process all instances
16359 (goto-char arch-stat-pos)
16360 (while (re-search-forward
16361 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16362 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16363 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16364 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16365 "[ \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)
16366 (setq inst-name (match-string-no-properties 1)
16367 comp-name (match-string-no-properties 4)
16368 comp-ent-name (match-string-no-properties 12)
16369 has-generic (or (match-string 7) (match-string 17)))
16370 ;; get port ...
16371 (if comp-name
16372 ;; ... from component declaration
16373 (vhdl-visit-file
16374 (when vhdl-use-components-package pack-file-name) t
16375 (save-excursion
16376 (goto-char (point-min))
16377 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
16378 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
16379 (vhdl-port-copy)))
16380 ;; ... from entity declaration (direct instantiation)
16381 (setq comp-ent-file-name
16382 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
16383 "." (file-name-extension (buffer-file-name))))
16384 (vhdl-visit-file
16385 comp-ent-file-name t
16386 (save-excursion
16387 (goto-char (point-min))
16388 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
16389 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
16390 (vhdl-port-copy))))
16391 (vhdl-port-flatten t)
16392 (setq generic-alist (nth 1 vhdl-port-list)
16393 port-alist (nth 2 vhdl-port-list)
16394 vhdl-port-list nil)
16395 (setq constant-alist nil
16396 signal-alist nil)
16397 (when has-generic
16398 ;; process all constants in generic map
16399 (vhdl-forward-syntactic-ws)
16400 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16401 (setq constant-name (match-string-no-properties 3))
16402 (setq constant-entry
16403 (cons constant-name
16404 (if (match-string 1)
16405 (or (vhdl-aget generic-alist (match-string 2))
16406 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16407 (cdar generic-alist))))
16408 (push constant-entry constant-alist)
16409 (setq constant-name (downcase constant-name))
16410 (if (or (member constant-name single-list)
16411 (member constant-name multi-list))
16412 (progn (setq single-list (delete constant-name single-list))
16413 (add-to-list 'multi-list constant-name))
16414 (add-to-list 'single-list constant-name))
16415 (unless (match-string 1)
16416 (setq generic-alist (cdr generic-alist)))
16417 (vhdl-forward-syntactic-ws))
16418 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16419 ;; process all signals in port map
16420 (vhdl-forward-syntactic-ws)
16421 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16422 (setq signal-name (match-string-no-properties 3))
16423 (setq signal-entry
16424 (cons signal-name
16425 (if (match-string 1)
16426 (or (vhdl-aget port-alist (match-string 2))
16427 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16428 (cdar port-alist))))
16429 (push signal-entry signal-alist)
16430 (setq signal-name (downcase signal-name))
16431 (if (equal (upcase (nth 2 signal-entry)) "IN")
16432 ;; input signal
16433 (cond
16434 ((member signal-name local-list)
16435 nil)
16436 ((or (member signal-name single-out-list)
16437 (member signal-name multi-out-list))
16438 (setq single-out-list (delete signal-name single-out-list))
16439 (setq multi-out-list (delete signal-name multi-out-list))
16440 (add-to-list 'local-list signal-name))
16441 ((member signal-name single-in-list)
16442 (setq single-in-list (delete signal-name single-in-list))
16443 (add-to-list 'multi-in-list signal-name))
16444 ((not (member signal-name multi-in-list))
16445 (add-to-list 'single-in-list signal-name)))
16446 ;; output signal
16447 (cond
16448 ((member signal-name local-list)
16449 nil)
16450 ((or (member signal-name single-in-list)
16451 (member signal-name multi-in-list))
16452 (setq single-in-list (delete signal-name single-in-list))
16453 (setq multi-in-list (delete signal-name multi-in-list))
16454 (add-to-list 'local-list signal-name))
16455 ((member signal-name single-out-list)
16456 (setq single-out-list (delete signal-name single-out-list))
16457 (add-to-list 'multi-out-list signal-name))
16458 ((not (member signal-name multi-out-list))
16459 (add-to-list 'single-out-list signal-name))))
16460 (unless (match-string 1)
16461 (setq port-alist (cdr port-alist)))
16462 (vhdl-forward-syntactic-ws))
16463 (push (list inst-name (nreverse constant-alist)
16464 (nreverse signal-alist)) inst-alist))
16465 ;; prepare signal insertion
16466 (vhdl-goto-marker arch-decl-pos)
16467 (forward-line 1)
16468 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16469 (setq signal-pos (point-marker))
16470 (while (progn (vhdl-forward-syntactic-ws)
16471 (looking-at "signal\\>"))
16472 (beginning-of-line 2)
16473 (delete-region signal-pos (point)))
16474 (setq signal-beg-pos signal-pos)
16475 ;; open entity file
16476 (when (file-exists-p ent-file-name)
16477 (find-file ent-file-name))
16478 (goto-char (point-min))
16479 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16480 (error "ERROR: Entity not found: \"%s\"" ent-name))
16481 ;; prepare generic clause insertion
16482 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16483 (match-string 1))
16484 (goto-char (match-beginning 0))
16485 (indent-to vhdl-basic-offset)
16486 (insert "generic ();\n\n")
16487 (backward-char 4))
16488 (backward-char)
16489 (setq generic-pos (point-marker))
16490 (forward-sexp) (end-of-line)
16491 (delete-region generic-pos (point)) (delete-char 1)
16492 (insert "(\n")
16493 (when multi-list
16494 (insert "\n")
16495 (indent-to (* 2 vhdl-basic-offset))
16496 (insert "-- global generics\n"))
16497 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16498 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16499 ;; prepare port clause insertion
16500 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16501 (match-string 1))
16502 (goto-char (match-beginning 0))
16503 (indent-to vhdl-basic-offset)
16504 (insert "port ();\n\n")
16505 (backward-char 4))
16506 (backward-char)
16507 (setq port-in-pos (point-marker))
16508 (forward-sexp) (end-of-line)
16509 (delete-region port-in-pos (point)) (delete-char 1)
16510 (insert "(\n")
16511 (when (or multi-in-list multi-out-list)
16512 (insert "\n")
16513 (indent-to (* 2 vhdl-basic-offset))
16514 (insert "-- global ports\n"))
16515 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16516 port-out-pos (point-marker) port-inst-pos (point-marker)
16517 port-end-pos (point-marker))
16518 ;; insert generics, ports and signals
16519 (setq inst-alist (nreverse inst-alist))
16520 (while inst-alist
16521 (setq inst-name (nth 0 (car inst-alist))
16522 constant-alist (nth 1 (car inst-alist))
16523 signal-alist (nth 2 (car inst-alist))
16524 constant-temp-pos generic-inst-pos
16525 port-temp-pos port-inst-pos
16526 signal-temp-pos signal-pos)
16527 ;; generics
16528 (while constant-alist
16529 (setq constant-name (downcase (caar constant-alist))
16530 constant-entry (car constant-alist))
16531 (unless (string-match "^[0-9]+" constant-name)
16532 (cond ((member constant-name written-list)
16533 nil)
16534 ((member constant-name multi-list)
16535 (vhdl-goto-marker generic-pos)
16536 (setq generic-end-pos
16537 (vhdl-max-marker
16538 generic-end-pos
16539 (vhdl-compose-insert-generic constant-entry)))
16540 (setq generic-pos (point-marker))
16541 (add-to-list 'written-list constant-name))
16543 (vhdl-goto-marker
16544 (vhdl-max-marker generic-inst-pos generic-pos))
16545 (setq generic-end-pos
16546 (vhdl-compose-insert-generic constant-entry))
16547 (setq generic-inst-pos (point-marker))
16548 (add-to-list 'written-list constant-name))))
16549 (setq constant-alist (cdr constant-alist)))
16550 (when (/= constant-temp-pos generic-inst-pos)
16551 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16552 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16553 (insert "-- generics for \"" inst-name "\"\n")
16554 (vhdl-goto-marker generic-inst-pos))
16555 ;; ports and signals
16556 (while signal-alist
16557 (setq signal-name (downcase (caar signal-alist))
16558 signal-entry (car signal-alist))
16559 (cond ((member signal-name written-list)
16560 nil)
16561 ((member signal-name multi-in-list)
16562 (vhdl-goto-marker port-in-pos)
16563 (setq port-end-pos
16564 (vhdl-max-marker
16565 port-end-pos (vhdl-compose-insert-port signal-entry)))
16566 (setq port-in-pos (point-marker))
16567 (add-to-list 'written-list signal-name))
16568 ((member signal-name multi-out-list)
16569 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16570 (setq port-end-pos
16571 (vhdl-max-marker
16572 port-end-pos (vhdl-compose-insert-port signal-entry)))
16573 (setq port-out-pos (point-marker))
16574 (add-to-list 'written-list signal-name))
16575 ((or (member signal-name single-in-list)
16576 (member signal-name single-out-list))
16577 (vhdl-goto-marker
16578 (vhdl-max-marker
16579 port-inst-pos
16580 (vhdl-max-marker port-out-pos port-in-pos)))
16581 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16582 (setq port-inst-pos (point-marker))
16583 (add-to-list 'written-list signal-name))
16584 ((equal (upcase (nth 2 signal-entry)) "OUT")
16585 (vhdl-goto-marker signal-pos)
16586 (vhdl-compose-insert-signal signal-entry)
16587 (setq signal-pos (point-marker))
16588 (add-to-list 'written-list signal-name)))
16589 (setq signal-alist (cdr signal-alist)))
16590 (when (/= port-temp-pos port-inst-pos)
16591 (vhdl-goto-marker
16592 (vhdl-max-marker port-temp-pos
16593 (vhdl-max-marker port-in-pos port-out-pos)))
16594 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16595 (insert "-- ports to \"" inst-name "\"\n")
16596 (vhdl-goto-marker port-inst-pos))
16597 (when (/= signal-temp-pos signal-pos)
16598 (vhdl-goto-marker signal-temp-pos)
16599 (insert "\n") (indent-to vhdl-basic-offset)
16600 (insert "-- outputs of \"" inst-name "\"\n")
16601 (vhdl-goto-marker signal-pos))
16602 (setq inst-alist (cdr inst-alist)))
16603 ;; finalize generic/port clause
16604 (vhdl-goto-marker generic-end-pos) (backward-char)
16605 (when (= generic-beg-pos generic-end-pos)
16606 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16607 (insert ";") (backward-char))
16608 (insert ")")
16609 (vhdl-goto-marker port-end-pos) (backward-char)
16610 (when (= port-beg-pos port-end-pos)
16611 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16612 (insert ";") (backward-char))
16613 (insert ")")
16614 ;; align everything
16615 (when vhdl-auto-align
16616 (vhdl-goto-marker generic-beg-pos)
16617 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16618 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16619 (vhdl-goto-marker signal-beg-pos)
16620 (vhdl-align-region-groups signal-beg-pos signal-pos))
16621 (switch-to-buffer (marker-buffer signal-beg-pos))
16622 (message "Wiring components...done")))))
16624 (defun vhdl-compose-insert-generic (entry)
16625 "Insert ENTRY as generic declaration."
16626 (let (pos)
16627 (indent-to (* 2 vhdl-basic-offset))
16628 (insert (nth 0 entry) " : " (nth 1 entry))
16629 (when (nth 2 entry)
16630 (insert " := " (nth 2 entry)))
16631 (insert ";")
16632 (setq pos (point-marker))
16633 (when (and vhdl-include-port-comments (nth 3 entry))
16634 (vhdl-comment-insert-inline (nth 3 entry) t))
16635 (insert "\n")
16636 pos))
16638 (defun vhdl-compose-insert-port (entry)
16639 "Insert ENTRY as port declaration."
16640 (let (pos)
16641 (indent-to (* 2 vhdl-basic-offset))
16642 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16643 (setq pos (point-marker))
16644 (when (and vhdl-include-port-comments (nth 4 entry))
16645 (vhdl-comment-insert-inline (nth 4 entry) t))
16646 (insert "\n")
16647 pos))
16649 (defun vhdl-compose-insert-signal (entry)
16650 "Insert ENTRY as signal declaration."
16651 (indent-to vhdl-basic-offset)
16652 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16653 (when (and vhdl-include-port-comments (nth 4 entry))
16654 (vhdl-comment-insert-inline (nth 4 entry) t))
16655 (insert "\n"))
16657 (defun vhdl-compose-components-package ()
16658 "Generate a package containing component declarations for all entities in the
16659 current project/directory."
16660 (interactive)
16661 (vhdl-require-hierarchy-info)
16662 (let* ((project (vhdl-project-p))
16663 (pack-name (vhdl-get-components-package-name))
16664 (pack-file-name
16665 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16666 "." (file-name-extension (buffer-file-name))))
16667 (ent-alist (vhdl-aget vhdl-entity-alist
16668 (or project
16669 (abbreviate-file-name default-directory))))
16670 (lazy-lock-minimum-size 0)
16671 clause-pos component-pos)
16672 (message "Generating components package \"%s\"..." pack-name)
16673 ;; open package file
16674 (when (and (file-exists-p pack-file-name)
16675 (not (y-or-n-p (concat "File \"" pack-file-name
16676 "\" exists; overwrite? "))))
16677 (error "ERROR: Generating components package...aborted"))
16678 (find-file pack-file-name)
16679 (erase-buffer)
16680 ;; insert header
16681 (if vhdl-compose-include-header
16682 (progn (vhdl-template-header
16683 (concat "Components package (generated by Emacs VHDL Mode "
16684 vhdl-version ")"))
16685 (goto-char (point-max)))
16686 (vhdl-comment-display-line) (insert "\n\n"))
16687 ;; insert std_logic_1164 package
16688 (vhdl-template-package-std-logic-1164)
16689 (insert "\n") (setq clause-pos (point-marker))
16690 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16691 ;; insert package declaration
16692 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16693 (vhdl-insert-keyword " IS\n\n")
16694 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16695 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16696 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16697 (indent-to vhdl-basic-offset)
16698 (setq component-pos (point-marker))
16699 (insert "\n\n") (vhdl-insert-keyword "END ")
16700 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16701 (insert pack-name ";\n\n")
16702 ;; insert footer
16703 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16704 (vhdl-template-footer)
16705 (vhdl-comment-display-line) (insert "\n"))
16706 ;; insert component declarations
16707 (while ent-alist
16708 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16709 (progn (goto-char (point-min))
16710 (forward-line (1- (nth 3 (car ent-alist))))
16711 (end-of-line)
16712 (vhdl-port-copy)))
16713 (goto-char component-pos)
16714 (vhdl-port-paste-component t)
16715 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16716 (setq component-pos (point-marker))
16717 (goto-char clause-pos)
16718 (vhdl-port-paste-context-clause pack-name)
16719 (setq clause-pos (point-marker))
16720 (setq ent-alist (cdr ent-alist)))
16721 (goto-char (point-min))
16722 (save-buffer)
16723 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16724 pack-name pack-file-name)))
16726 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16727 conf-alist inst-alist
16728 &optional insert-conf)
16729 "Generate block configuration for architecture."
16730 (let ((margin (current-indentation))
16731 (beg (point-at-bol))
16732 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16733 ;; insert block configuration (for architecture)
16734 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16735 (setq margin (+ margin vhdl-basic-offset))
16736 ;; process all instances
16737 (while inst-alist
16738 (setq inst-entry (car inst-alist))
16739 ;; is component?
16740 (when (nth 4 inst-entry)
16741 (setq insert-conf t)
16742 (setq inst-path (nth 9 inst-entry))
16743 ;; skip common path with previous instance
16744 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16745 (setq inst-path (cdr inst-path)
16746 inst-prev-path (cdr inst-prev-path)))
16747 ;; insert block configuration end (for previous block/generate)
16748 (while inst-prev-path
16749 (setq margin (- margin vhdl-basic-offset))
16750 (indent-to margin)
16751 (vhdl-insert-keyword "END FOR;\n")
16752 (setq inst-prev-path (cdr inst-prev-path)))
16753 ;; insert block configuration beginning (for current block/generate)
16754 (indent-to margin)
16755 (while inst-path
16756 (setq margin (+ margin vhdl-basic-offset))
16757 (vhdl-insert-keyword "FOR ")
16758 (insert (car inst-path) "\n")
16759 (indent-to margin)
16760 (setq inst-path (cdr inst-path)))
16761 ;; insert component configuration beginning
16762 (vhdl-insert-keyword "FOR ")
16763 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16764 ;; find subconfiguration
16765 (setq conf-key (nth 7 inst-entry))
16766 (setq tmp-alist conf-alist)
16767 ;; use first configuration found for instance's entity
16768 (while (and tmp-alist (null conf-key))
16769 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16770 (setq conf-key (nth 0 (car tmp-alist))))
16771 (setq tmp-alist (cdr tmp-alist)))
16772 (setq conf-entry (vhdl-aget conf-alist conf-key))
16773 ;; insert binding indication ...
16774 ;; ... with subconfiguration (if exists)
16775 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16776 (progn
16777 (indent-to (+ margin vhdl-basic-offset))
16778 (vhdl-insert-keyword "USE CONFIGURATION ")
16779 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16780 (insert ";\n"))
16781 ;; ... with entity (if exists)
16782 (setq ent-entry (vhdl-aget ent-alist (nth 5 inst-entry)))
16783 (when ent-entry
16784 (indent-to (+ margin vhdl-basic-offset))
16785 (vhdl-insert-keyword "USE ENTITY ")
16786 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16787 ;; insert architecture name (if architecture exists)
16788 (when (nth 3 ent-entry)
16789 (setq arch-name
16790 ;; choose architecture name a) from configuration,
16791 ;; b) from mra, or c) from first architecture
16792 (or (nth 0 (vhdl-aget (nth 3 ent-entry)
16793 (or (nth 6 inst-entry)
16794 (nth 4 ent-entry))))
16795 (nth 1 (car (nth 3 ent-entry)))))
16796 (insert "(" arch-name ")"))
16797 (insert ";\n")
16798 ;; insert block configuration (for architecture of subcomponent)
16799 (when (and vhdl-compose-configuration-hierarchical
16800 (nth 3 ent-entry))
16801 (indent-to (+ margin vhdl-basic-offset))
16802 (vhdl-compose-configuration-architecture
16803 (nth 0 ent-entry) arch-name ent-alist conf-alist
16804 (nth 3 (vhdl-aget (nth 3 ent-entry) (downcase arch-name)))))))
16805 ;; insert component configuration end
16806 (indent-to margin)
16807 (vhdl-insert-keyword "END FOR;\n")
16808 (setq inst-prev-path (nth 9 inst-entry)))
16809 (setq inst-alist (cdr inst-alist)))
16810 ;; insert block configuration end (for block/generate)
16811 (while inst-prev-path
16812 (setq margin (- margin vhdl-basic-offset))
16813 (indent-to margin)
16814 (vhdl-insert-keyword "END FOR;\n")
16815 (setq inst-prev-path (cdr inst-prev-path)))
16816 (indent-to (- margin vhdl-basic-offset))
16817 ;; insert block configuration end or remove beginning (for architecture)
16818 (if insert-conf
16819 (vhdl-insert-keyword "END FOR;\n")
16820 (delete-region beg (point)))))
16822 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16823 "Generate configuration declaration."
16824 (interactive)
16825 (vhdl-require-hierarchy-info)
16826 (let ((ent-alist (vhdl-aget vhdl-entity-alist
16827 (or (vhdl-project-p)
16828 (abbreviate-file-name default-directory))))
16829 (conf-alist (vhdl-aget vhdl-config-alist
16830 (or (vhdl-project-p)
16831 (abbreviate-file-name default-directory))))
16832 (from-speedbar ent-name)
16833 inst-alist conf-name conf-file-name pos)
16834 (vhdl-prepare-search-2
16835 ;; get entity and architecture name
16836 (unless ent-name
16837 (save-excursion
16838 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16839 (not (equal "END" (upcase (match-string 1))))
16840 (setq ent-name (match-string-no-properties 3))
16841 (setq arch-name (match-string-no-properties 2)))
16842 (error "ERROR: Not within an architecture"))))
16843 (setq conf-name (vhdl-replace-string
16844 vhdl-compose-configuration-name
16845 (concat ent-name " " arch-name)))
16846 (setq inst-alist
16847 (nth 3 (vhdl-aget (nth 3 (vhdl-aget ent-alist (downcase ent-name)))
16848 (downcase arch-name)))))
16849 (message "Generating configuration \"%s\"..." conf-name)
16850 (if vhdl-compose-configuration-create-file
16851 ;; open configuration file
16852 (progn
16853 (setq conf-file-name
16854 (concat (vhdl-replace-string vhdl-configuration-file-name
16855 conf-name t)
16856 "." (file-name-extension (buffer-file-name))))
16857 (when (and (file-exists-p conf-file-name)
16858 (not (y-or-n-p (concat "File \"" conf-file-name
16859 "\" exists; overwrite? "))))
16860 (error "ERROR: Creating configuration...aborted"))
16861 (find-file conf-file-name)
16862 (erase-buffer)
16863 (set-buffer-modified-p nil)
16864 ;; insert header
16865 (if vhdl-compose-include-header
16866 (progn (vhdl-template-header
16867 (concat "Configuration declaration for design \""
16868 ent-name "(" arch-name ")\""))
16869 (goto-char (point-max)))
16870 (vhdl-comment-display-line) (insert "\n\n")))
16871 ;; goto end of architecture
16872 (unless from-speedbar
16873 (re-search-forward "^end\\>" nil)
16874 (end-of-line) (insert "\n\n")
16875 (vhdl-comment-display-line) (insert "\n\n")))
16876 ;; insert library clause
16877 (setq pos (point))
16878 (vhdl-template-standard-package (vhdl-work-library) nil)
16879 (when (/= pos (point))
16880 (insert "\n\n"))
16881 ;; insert configuration
16882 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16883 (vhdl-insert-keyword " OF ") (insert ent-name)
16884 (vhdl-insert-keyword " IS\n")
16885 (indent-to vhdl-basic-offset)
16886 ;; insert block configuration (for architecture)
16887 (vhdl-compose-configuration-architecture
16888 ent-name arch-name ent-alist conf-alist inst-alist t)
16889 (vhdl-insert-keyword "END ") (insert conf-name ";")
16890 (when conf-file-name
16891 ;; insert footer and save
16892 (insert "\n\n")
16893 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16894 (vhdl-template-footer)
16895 (vhdl-comment-display-line) (insert "\n"))
16896 (save-buffer))
16897 (message "%s"
16898 (concat (format "Generating configuration \"%s\"...done" conf-name)
16899 (and conf-file-name
16900 (format "\n File created: \"%s\"" conf-file-name))))))
16903 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16904 ;;; Compilation / Makefile generation
16905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16906 ;; (using `compile.el')
16908 (defvar vhdl-compile-post-command ""
16909 "String appended to compile command after file name.")
16911 (defun vhdl-makefile-name ()
16912 "Return the Makefile name of the current project or the current compiler if
16913 no project is defined."
16914 (let ((project-alist (vhdl-aget vhdl-project-alist vhdl-project))
16915 (compiler-alist (vhdl-aget vhdl-compiler-alist vhdl-compiler)))
16916 (vhdl-replace-string
16917 (cons "\\(.*\\)\n\\(.*\\)"
16918 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16919 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16921 (defun vhdl-compile-directory ()
16922 "Return the directory where compilation/make should be run."
16923 (let* ((project (vhdl-aget vhdl-project-alist (vhdl-project-p t)))
16924 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
16925 (directory (vhdl-resolve-env-variable
16926 (if project
16927 (vhdl-replace-string
16928 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16929 (nth 6 compiler)))))
16930 (file-name-as-directory
16931 (if (file-name-absolute-p directory)
16932 directory
16933 (expand-file-name directory (vhdl-default-directory))))))
16935 (defun vhdl-uniquify (in-list)
16936 "Remove duplicate elements from IN-LIST."
16937 (let (out-list)
16938 (while in-list
16939 (add-to-list 'out-list (car in-list))
16940 (setq in-list (cdr in-list)))
16941 out-list))
16943 (defun vhdl-set-compiler (name)
16944 "Set current compiler to NAME."
16945 (interactive
16946 (list (let ((completion-ignore-case t))
16947 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16948 (if (assoc name vhdl-compiler-alist)
16949 (progn (setq vhdl-compiler name)
16950 (message "Current compiler: \"%s\"" vhdl-compiler))
16951 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16954 ;; Compilation
16956 (defun vhdl-compile-init ()
16957 "Initialize for compilation."
16958 (when (and (not vhdl-emacs-22)
16959 (or (null compilation-error-regexp-alist)
16960 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16961 compilation-error-regexp-alist))))
16962 ;; `compilation-error-regexp-alist'
16963 (let ((commands-alist vhdl-compiler-alist)
16964 regexp-alist sublist)
16965 (while commands-alist
16966 (setq sublist (nth 11 (car commands-alist)))
16967 (unless (or (equal "" (car sublist))
16968 (assoc (car sublist) regexp-alist))
16969 (push (list (nth 0 sublist)
16970 (if (and (featurep 'xemacs) (not (nth 1 sublist)))
16972 (nth 1 sublist))
16973 (nth 2 sublist) (nth 3 sublist))
16974 regexp-alist))
16975 (setq commands-alist (cdr commands-alist)))
16976 (setq compilation-error-regexp-alist
16977 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16978 ;; `compilation-file-regexp-alist'
16979 (let ((commands-alist vhdl-compiler-alist)
16980 regexp-alist sublist)
16981 ;; matches vhdl-mode file name output
16982 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16983 (while commands-alist
16984 (setq sublist (nth 12 (car commands-alist)))
16985 (unless (or (equal "" (car sublist))
16986 (assoc (car sublist) regexp-alist))
16987 (push sublist regexp-alist))
16988 (setq commands-alist (cdr commands-alist)))
16989 (setq compilation-file-regexp-alist
16990 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16992 (defvar vhdl-compile-file-name nil
16993 "Name of file to be compiled.")
16995 (defun vhdl-compile-print-file-name ()
16996 "Function called within `compile' to print out file name for compilers that
16997 do not print any file names."
16998 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
17000 (defun vhdl-get-compile-options (project compiler file-name
17001 &optional file-options-only)
17002 "Get compiler options. Returning nil means do not compile this file."
17003 (let* ((compiler-options (nth 1 compiler))
17004 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17005 (project-options (nth 0 project-entry))
17006 (exception-list (and file-name (nth 2 project-entry)))
17007 (work-library (vhdl-work-library))
17008 (case-fold-search nil)
17009 file-options)
17010 (while (and exception-list
17011 (not (string-match (caar exception-list) file-name)))
17012 (setq exception-list (cdr exception-list)))
17013 (if (and exception-list (not (cdar exception-list)))
17015 (if (and file-options-only (not exception-list))
17016 'default
17017 (setq file-options (cdar exception-list))
17018 ;; insert library name in compiler-specific options
17019 (setq compiler-options
17020 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
17021 work-library))
17022 ;; insert compiler-specific options in project-specific options
17023 (when project-options
17024 (setq project-options
17025 (vhdl-replace-string
17026 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17027 (concat work-library "\n" compiler-options))))
17028 ;; insert project-specific options in file-specific options
17029 (when file-options
17030 (setq file-options
17031 (vhdl-replace-string
17032 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
17033 (concat work-library "\n" compiler-options "\n"
17034 project-options))))
17035 ;; return options
17036 (or file-options project-options compiler-options)))))
17038 (defun vhdl-get-make-options (project compiler)
17039 "Get make options."
17040 (let* ((compiler-options (nth 3 compiler))
17041 (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
17042 (project-options (nth 1 project-entry))
17043 (makefile-name (vhdl-makefile-name)))
17044 ;; insert Makefile name in compiler-specific options
17045 (setq compiler-options
17046 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
17047 makefile-name))
17048 ;; insert compiler-specific options in project-specific options
17049 (when project-options
17050 (setq project-options
17051 (vhdl-replace-string
17052 (cons "\\(.*\\)\n\\(.*\\)" project-options)
17053 (concat makefile-name "\n" compiler-options))))
17054 ;; return options
17055 (or project-options compiler-options)))
17057 (defun vhdl-compile ()
17058 "Compile current buffer using the VHDL compiler specified in
17059 `vhdl-compiler'."
17060 (interactive)
17061 (vhdl-compile-init)
17062 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17063 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17064 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17065 (command (nth 0 compiler))
17066 (default-directory (vhdl-compile-directory))
17067 (file-name (if vhdl-compile-absolute-path
17068 (buffer-file-name)
17069 (file-relative-name (buffer-file-name))))
17070 (options (vhdl-get-compile-options project compiler file-name))
17071 compilation-process-setup-function)
17072 (unless (file-directory-p default-directory)
17073 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17074 ;; put file name into quotes if it contains spaces
17075 (when (string-match " " file-name)
17076 (setq file-name (concat "\"" file-name "\"")))
17077 ;; print out file name if compiler does not
17078 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
17079 (buffer-file-name)
17080 (file-relative-name (buffer-file-name))))
17081 (when (and (= 0 (nth 1 (nth 10 compiler)))
17082 (= 0 (nth 1 (nth 11 compiler))))
17083 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
17084 ;; run compilation
17085 (if options
17086 (when command
17087 (compile (concat command " " options " " file-name
17088 (unless (equal vhdl-compile-post-command "")
17089 (concat " " vhdl-compile-post-command)))))
17090 (vhdl-warning "Your project settings tell me not to compile this file"))))
17092 (defvar vhdl-make-target "all"
17093 "Default target for `vhdl-make' command.")
17095 (defun vhdl-make (&optional target)
17096 "Call make command for compilation of all updated source files (requires
17097 `Makefile'). Optional argument TARGET allows you to compile the design
17098 specified by a target."
17099 (interactive)
17100 (setq vhdl-make-target
17101 (or target (read-from-minibuffer "Target: " vhdl-make-target
17102 vhdl-minibuffer-local-map)))
17103 (vhdl-compile-init)
17104 (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
17105 (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17106 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17107 (command (nth 2 compiler))
17108 (options (vhdl-get-make-options project compiler))
17109 (default-directory (vhdl-compile-directory)))
17110 (unless (file-directory-p default-directory)
17111 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
17112 ;; run make
17113 (compile (concat (if (equal command "") "make" command)
17114 " " options " " vhdl-make-target))))
17116 ;; Emacs 22+ setup
17117 (defvar vhdl-error-regexp-emacs-alist
17118 ;; Get regexps from `vhdl-compiler-alist'
17119 (let ((compiler-alist vhdl-compiler-alist)
17120 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
17121 (while compiler-alist
17122 ;; only add regexps for currently selected compiler
17123 (when (or (not vhdl-compile-use-local-error-regexp)
17124 (equal vhdl-compiler (nth 0 (car compiler-alist))))
17125 ;; add error message regexps
17126 (setq error-regexp-alist
17127 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
17128 (nth 11 (car compiler-alist)))
17129 error-regexp-alist))
17130 ;; add filename regexps
17131 (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
17132 (setq error-regexp-alist
17133 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
17134 (nth 12 (car compiler-alist)))
17135 error-regexp-alist))))
17136 (setq compiler-alist (cdr compiler-alist)))
17137 error-regexp-alist)
17138 "List of regexps for VHDL compilers. For Emacs 22+.")
17140 ;; Add error regexps using compilation-mode-hook.
17141 (defun vhdl-error-regexp-add-emacs ()
17142 "Set up Emacs compile for VHDL."
17143 (interactive)
17144 (when (and (boundp 'compilation-error-regexp-alist-alist)
17145 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
17146 ;; remove all other compilers
17147 (when vhdl-compile-use-local-error-regexp
17148 (setq compilation-error-regexp-alist nil))
17149 ;; add VHDL compilers
17150 (mapcar
17151 (lambda (item)
17152 (push (car item) compilation-error-regexp-alist)
17153 (push item compilation-error-regexp-alist-alist))
17154 vhdl-error-regexp-emacs-alist)))
17156 (when vhdl-emacs-22
17157 (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
17159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17160 ;; Makefile generation
17162 (defun vhdl-generate-makefile ()
17163 "Generate `Makefile'."
17164 (interactive)
17165 (let* ((compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
17166 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
17167 (command (nth 4 compiler)))
17168 ;; generate makefile
17169 (if command
17170 (let ((default-directory (vhdl-compile-directory)))
17171 (compile (vhdl-replace-string
17172 (cons "\\(.*\\) \\(.*\\)" command)
17173 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
17174 (vhdl-generate-makefile-1))))
17176 (defun vhdl-get-packages (lib-alist work-library)
17177 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
17178 (let (pack-list)
17179 (while lib-alist
17180 (when (equal (downcase (caar lib-alist)) (downcase work-library))
17181 (push (cdar lib-alist) pack-list))
17182 (setq lib-alist (cdr lib-alist)))
17183 pack-list))
17185 (defun vhdl-generate-makefile-1 ()
17186 "Generate Makefile for current project or directory."
17187 ;; scan hierarchy if required
17188 (if (vhdl-project-p)
17189 (unless (or (assoc vhdl-project vhdl-file-alist)
17190 (vhdl-load-cache vhdl-project))
17191 (vhdl-scan-project-contents vhdl-project))
17192 (let ((directory (abbreviate-file-name default-directory)))
17193 (unless (or (assoc directory vhdl-file-alist)
17194 (vhdl-load-cache directory))
17195 (vhdl-scan-directory-contents directory))))
17196 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
17197 (project (vhdl-project-p))
17198 (ent-alist (vhdl-aget vhdl-entity-alist (or project directory)))
17199 (conf-alist (vhdl-aget vhdl-config-alist (or project directory)))
17200 (pack-alist (vhdl-aget vhdl-package-alist (or project directory)))
17201 (regexp-list (or (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17202 '("\\1.vhd" "\\2_\\1.vhd" "\\1.vhd"
17203 "\\1.vhd" "\\1_body.vhd" identity)))
17204 (mapping-exist
17205 (if (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler)) t nil))
17206 (ent-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 0 regexp-list)))
17207 (arch-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
17208 (conf-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 2 regexp-list)))
17209 (pack-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 3 regexp-list)))
17210 (pack-body-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 4 regexp-list)))
17211 (adjust-case (nth 5 regexp-list))
17212 (work-library (downcase (vhdl-work-library)))
17213 (compile-directory (expand-file-name (vhdl-compile-directory)
17214 default-directory))
17215 (makefile-name (vhdl-makefile-name))
17216 rule-alist arch-alist inst-alist
17217 target-list depend-list unit-list prim-list second-list subcomp-list
17218 lib-alist lib-body-alist pack-list all-pack-list
17219 ent-key ent-file-name arch-key arch-file-name ent-arch-key
17220 conf-key conf-file-name pack-key pack-file-name
17221 ent-entry arch-entry conf-entry pack-entry inst-entry
17222 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
17223 tmp-key tmp-list rule)
17224 ;; check prerequisites
17225 (unless (file-exists-p compile-directory)
17226 (make-directory compile-directory t))
17227 (unless mapping-exist
17228 (vhdl-warning
17229 (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\""
17230 vhdl-compiler vhdl-compiler) t))
17231 (message "Generating makefile \"%s\"..." makefile-name)
17232 ;; rules for all entities
17233 (setq tmp-list ent-alist)
17234 (while ent-alist
17235 (setq ent-entry (car ent-alist)
17236 ent-key (nth 0 ent-entry))
17237 (when (nth 2 ent-entry)
17238 (setq ent-file-name (if vhdl-compile-absolute-path
17239 (nth 2 ent-entry)
17240 (file-relative-name (nth 2 ent-entry)
17241 compile-directory))
17242 arch-alist (nth 4 ent-entry)
17243 lib-alist (nth 6 ent-entry)
17244 rule (vhdl-aget rule-alist ent-file-name)
17245 target-list (nth 0 rule)
17246 depend-list (nth 1 rule)
17247 second-list nil
17248 subcomp-list nil)
17249 (setq tmp-key (vhdl-replace-string
17250 ent-regexp
17251 (funcall adjust-case
17252 (concat ent-key " " work-library))))
17253 (push (cons ent-key tmp-key) unit-list)
17254 ;; rule target for this entity
17255 (push ent-key target-list)
17256 ;; rule dependencies for all used packages
17257 (setq pack-list (vhdl-get-packages lib-alist work-library))
17258 (setq depend-list (append depend-list pack-list))
17259 (setq all-pack-list pack-list)
17260 ;; add rule
17261 (vhdl-aput 'rule-alist ent-file-name (list target-list depend-list))
17262 ;; rules for all corresponding architectures
17263 (while arch-alist
17264 (setq arch-entry (car arch-alist)
17265 arch-key (nth 0 arch-entry)
17266 ent-arch-key (concat ent-key "-" arch-key)
17267 arch-file-name (if vhdl-compile-absolute-path
17268 (nth 2 arch-entry)
17269 (file-relative-name (nth 2 arch-entry)
17270 compile-directory))
17271 inst-alist (nth 4 arch-entry)
17272 lib-alist (nth 5 arch-entry)
17273 rule (vhdl-aget rule-alist arch-file-name)
17274 target-list (nth 0 rule)
17275 depend-list (nth 1 rule))
17276 (setq tmp-key (vhdl-replace-string
17277 arch-regexp
17278 (funcall adjust-case
17279 (concat arch-key " " ent-key " "
17280 work-library))))
17281 (setq unit-list
17282 (cons (cons ent-arch-key tmp-key) unit-list))
17283 (push ent-arch-key second-list)
17284 ;; rule target for this architecture
17285 (push ent-arch-key target-list)
17286 ;; rule dependency for corresponding entity
17287 (push ent-key depend-list)
17288 ;; rule dependencies for contained component instantiations
17289 (while inst-alist
17290 (setq inst-entry (car inst-alist))
17291 (when (or (null (nth 8 inst-entry))
17292 (equal (downcase (nth 8 inst-entry)) work-library))
17293 (setq inst-ent-key (or (nth 7 inst-entry)
17294 (nth 5 inst-entry)))
17295 (setq depend-list (cons inst-ent-key depend-list)
17296 subcomp-list (cons inst-ent-key subcomp-list)))
17297 (setq inst-alist (cdr inst-alist)))
17298 ;; rule dependencies for all used packages
17299 (setq pack-list (vhdl-get-packages lib-alist work-library))
17300 (setq depend-list (append depend-list pack-list))
17301 (setq all-pack-list (append all-pack-list pack-list))
17302 ;; add rule
17303 (vhdl-aput 'rule-alist arch-file-name (list target-list depend-list))
17304 (setq arch-alist (cdr arch-alist)))
17305 (push (list ent-key second-list (append subcomp-list all-pack-list))
17306 prim-list))
17307 (setq ent-alist (cdr ent-alist)))
17308 (setq ent-alist tmp-list)
17309 ;; rules for all configurations
17310 (setq tmp-list conf-alist)
17311 (while conf-alist
17312 (setq conf-entry (car conf-alist)
17313 conf-key (nth 0 conf-entry)
17314 conf-file-name (if vhdl-compile-absolute-path
17315 (nth 2 conf-entry)
17316 (file-relative-name (nth 2 conf-entry)
17317 compile-directory))
17318 ent-key (nth 4 conf-entry)
17319 arch-key (nth 5 conf-entry)
17320 inst-alist (nth 6 conf-entry)
17321 lib-alist (nth 7 conf-entry)
17322 rule (vhdl-aget rule-alist conf-file-name)
17323 target-list (nth 0 rule)
17324 depend-list (nth 1 rule)
17325 subcomp-list (list ent-key))
17326 (setq tmp-key (vhdl-replace-string
17327 conf-regexp
17328 (funcall adjust-case
17329 (concat conf-key " " work-library))))
17330 (push (cons conf-key tmp-key) unit-list)
17331 ;; rule target for this configuration
17332 (push conf-key target-list)
17333 ;; rule dependency for corresponding entity and architecture
17334 (setq depend-list
17335 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
17336 ;; rule dependencies for used packages
17337 (setq pack-list (vhdl-get-packages lib-alist work-library))
17338 (setq depend-list (append depend-list pack-list))
17339 ;; rule dependencies for contained component configurations
17340 (while inst-alist
17341 (setq inst-entry (car inst-alist))
17342 (setq inst-ent-key (nth 2 inst-entry)
17343 inst-conf-key (nth 4 inst-entry))
17344 (when (equal (downcase (nth 5 inst-entry)) work-library)
17345 (when inst-ent-key
17346 (setq depend-list (cons inst-ent-key depend-list)
17347 subcomp-list (cons inst-ent-key subcomp-list)))
17348 (when inst-conf-key
17349 (setq depend-list (cons inst-conf-key depend-list)
17350 subcomp-list (cons inst-conf-key subcomp-list))))
17351 (setq inst-alist (cdr inst-alist)))
17352 ;; add rule
17353 (vhdl-aput 'rule-alist conf-file-name (list target-list depend-list))
17354 (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
17355 (setq conf-alist (cdr conf-alist)))
17356 (setq conf-alist tmp-list)
17357 ;; rules for all packages
17358 (setq tmp-list pack-alist)
17359 (while pack-alist
17360 (setq pack-entry (car pack-alist)
17361 pack-key (nth 0 pack-entry)
17362 pack-body-key nil)
17363 (when (nth 2 pack-entry)
17364 (setq pack-file-name (if vhdl-compile-absolute-path
17365 (nth 2 pack-entry)
17366 (file-relative-name (nth 2 pack-entry)
17367 compile-directory))
17368 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
17369 rule (vhdl-aget rule-alist pack-file-name)
17370 target-list (nth 0 rule) depend-list (nth 1 rule))
17371 (setq tmp-key (vhdl-replace-string
17372 pack-regexp
17373 (funcall adjust-case
17374 (concat pack-key " " work-library))))
17375 (push (cons pack-key tmp-key) unit-list)
17376 ;; rule target for this package
17377 (push pack-key target-list)
17378 ;; rule dependencies for all used packages
17379 (setq pack-list (vhdl-get-packages lib-alist work-library))
17380 (setq depend-list (append depend-list pack-list))
17381 (setq all-pack-list pack-list)
17382 ;; add rule
17383 (vhdl-aput 'rule-alist pack-file-name (list target-list depend-list))
17384 ;; rules for this package's body
17385 (when (nth 7 pack-entry)
17386 (setq pack-body-key (concat pack-key "-body")
17387 pack-body-file-name (if vhdl-compile-absolute-path
17388 (nth 7 pack-entry)
17389 (file-relative-name (nth 7 pack-entry)
17390 compile-directory))
17391 rule (vhdl-aget rule-alist pack-body-file-name)
17392 target-list (nth 0 rule)
17393 depend-list (nth 1 rule))
17394 (setq tmp-key (vhdl-replace-string
17395 pack-body-regexp
17396 (funcall adjust-case
17397 (concat pack-key " " work-library))))
17398 (setq unit-list
17399 (cons (cons pack-body-key tmp-key) unit-list))
17400 ;; rule target for this package's body
17401 (push pack-body-key target-list)
17402 ;; rule dependency for corresponding package declaration
17403 (push pack-key depend-list)
17404 ;; rule dependencies for all used packages
17405 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
17406 (setq depend-list (append depend-list pack-list))
17407 (setq all-pack-list (append all-pack-list pack-list))
17408 ;; add rule
17409 (vhdl-aput 'rule-alist pack-body-file-name
17410 (list target-list depend-list)))
17411 (setq prim-list
17412 (cons (list pack-key (when pack-body-key (list pack-body-key))
17413 all-pack-list)
17414 prim-list)))
17415 (setq pack-alist (cdr pack-alist)))
17416 (setq pack-alist tmp-list)
17417 ;; generate Makefile
17418 (let* ((project (vhdl-aget vhdl-project-alist project))
17419 (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
17420 (compiler-id (nth 9 compiler))
17421 (library-directory
17422 (vhdl-resolve-env-variable
17423 (vhdl-replace-string
17424 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
17425 compiler-id)))
17426 (makefile-path-name (expand-file-name
17427 makefile-name compile-directory))
17428 (orig-buffer (current-buffer))
17429 cell second-list subcomp-list options unit-key unit-name)
17430 ;; sort lists
17431 (setq unit-list (vhdl-sort-alist unit-list))
17432 (setq prim-list (vhdl-sort-alist prim-list))
17433 (setq tmp-list rule-alist)
17434 (while tmp-list ; pre-sort rule targets
17435 (setq cell (cdar tmp-list))
17436 (setcar cell (sort (car cell) 'string<))
17437 (setq tmp-list (cdr tmp-list)))
17438 (setq rule-alist ; sort by first rule target
17439 (sort rule-alist
17440 (function (lambda (a b)
17441 (string< (car (cadr a)) (car (cadr b)))))))
17442 ;; open and clear Makefile
17443 (set-buffer (find-file-noselect makefile-path-name t t))
17444 (erase-buffer)
17445 (insert "# -*- Makefile -*-\n"
17446 "### " (file-name-nondirectory makefile-name)
17447 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17448 "\n")
17449 (if project
17450 (insert "\n# Project : " (nth 0 project))
17451 (insert "\n# Directory : \"" directory "\""))
17452 (insert "\n# Platform : " vhdl-compiler
17453 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17454 (user-login-name) "\n")
17455 ;; insert compile and option variable settings
17456 (insert "\n\n# Define compilation command and options\n"
17457 "\nCOMPILE = " (nth 0 compiler)
17458 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
17459 (if (equal vhdl-compile-post-command "") ""
17460 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
17461 "\n")
17462 ;; insert library paths
17463 (setq library-directory
17464 (directory-file-name
17465 (if (file-name-absolute-p library-directory)
17466 library-directory
17467 (file-relative-name
17468 (expand-file-name library-directory directory)
17469 compile-directory))))
17470 (insert "\n\n# Define library paths\n"
17471 "\nLIBRARY-" work-library " = " library-directory "\n")
17472 (unless mapping-exist
17473 (insert "LIBRARY-" work-library "-make = " "$(LIBRARY-" work-library
17474 ")/make" "\n"))
17475 ;; insert variable definitions for all library unit files
17476 (insert "\n\n# Define library unit files\n")
17477 (setq tmp-list unit-list)
17478 (while unit-list
17479 (insert "\nUNIT-" work-library "-" (caar unit-list)
17480 " = \\\n\t$(LIBRARY-" work-library
17481 (if mapping-exist "" "-make") ")/" (cdar unit-list))
17482 (setq unit-list (cdr unit-list)))
17483 ;; insert variable definition for list of all library unit files
17484 (insert "\n\n\n# Define list of all library unit files\n"
17485 "\nALL_UNITS =")
17486 (setq unit-list tmp-list)
17487 (while unit-list
17488 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17489 (setq unit-list (cdr unit-list)))
17490 (insert "\n")
17491 (setq unit-list tmp-list)
17492 ;; insert `make all' rule
17493 (insert "\n\n\n# Rule for compiling entire design\n"
17494 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17495 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17496 " \\\n\t\t$(ALL_UNITS)\n")
17497 ;; insert `make clean' rule
17498 (insert "\n\n# Rule for cleaning entire design\n"
17499 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17500 "\n\t-rm -f $(ALL_UNITS)\n")
17501 ;; insert `make library' rule
17502 (insert "\n\n# Rule for creating library directory\n"
17503 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17504 " \\\n\t\t$(LIBRARY-" work-library ")"
17505 (if mapping-exist ""
17506 (concat " \\\n\t\t$(LIBRARY-" work-library "-make)\n"))
17507 "\n"
17508 "\n$(LIBRARY-" work-library ") :"
17509 "\n\t"
17510 (vhdl-replace-string
17511 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17512 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17513 "\n")
17514 (unless mapping-exist
17515 (insert "\n$(LIBRARY-" work-library "-make) :"
17516 "\n\t"
17517 "mkdir -p $(LIBRARY-" work-library "-make)\n"))
17518 ;; insert '.PHONY' declaration
17519 (insert "\n\n.PHONY : "
17520 (nth 0 vhdl-makefile-default-targets) " "
17521 (nth 1 vhdl-makefile-default-targets) " "
17522 (nth 2 vhdl-makefile-default-targets) "\n")
17523 ;; insert rule for each library unit
17524 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17525 (while prim-list
17526 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17527 (setq subcomp-list
17528 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17529 (setq unit-key (caar prim-list)
17530 unit-name (or (nth 0 (vhdl-aget ent-alist unit-key))
17531 (nth 0 (vhdl-aget conf-alist unit-key))
17532 (nth 0 (vhdl-aget pack-alist unit-key))))
17533 (insert "\n" unit-key)
17534 (unless (equal unit-key unit-name)
17535 (insert " \\\n" unit-name))
17536 (insert " :"
17537 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
17538 (while subcomp-list
17539 (when (and (assoc (car subcomp-list) unit-list)
17540 (not (equal unit-key (car subcomp-list))))
17541 (insert " \\\n\t\t" (car subcomp-list)))
17542 (setq subcomp-list (cdr subcomp-list)))
17543 (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17544 (while second-list
17545 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17546 (setq second-list (cdr second-list)))
17547 (insert "\n")
17548 (setq prim-list (cdr prim-list)))
17549 ;; insert rule for each library unit file
17550 (insert "\n\n# Rules for compiling single library unit files\n")
17551 (while rule-alist
17552 (setq rule (car rule-alist))
17553 ;; get compiler options for this file
17554 (setq options
17555 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17556 ;; insert rule if file is supposed to be compiled
17557 (setq target-list (nth 1 rule)
17558 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17559 ;; insert targets
17560 (setq tmp-list target-list)
17561 (while target-list
17562 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17563 (if (cdr target-list) " \\" " :"))
17564 (setq target-list (cdr target-list)))
17565 (setq target-list tmp-list)
17566 ;; insert file name as first dependency
17567 (insert " \\\n\t\t" (nth 0 rule))
17568 ;; insert dependencies (except if also target or unit does not exist)
17569 (while depend-list
17570 (when (and (not (member (car depend-list) target-list))
17571 (assoc (car depend-list) unit-list))
17572 (insert " \\\n\t\t"
17573 "$(UNIT-" work-library "-" (car depend-list) ")"))
17574 (setq depend-list (cdr depend-list)))
17575 ;; insert compile command
17576 (if options
17577 (insert "\n\t$(COMPILE) "
17578 (if (eq options 'default) "$(OPTIONS)" options) " "
17579 (nth 0 rule)
17580 (if (equal vhdl-compile-post-command "") ""
17581 " $(POST-COMPILE)") "\n")
17582 (insert "\n"))
17583 (unless (and options mapping-exist)
17584 (setq tmp-list target-list)
17585 (while target-list
17586 (insert "\t@touch $(UNIT-" work-library "-" (car target-list) ")\n")
17587 (setq target-list (cdr target-list)))
17588 (setq target-list tmp-list))
17589 (setq rule-alist (cdr rule-alist)))
17591 (insert "\n\n### " makefile-name " ends here\n")
17592 ;; run Makefile generation hook
17593 (run-hooks 'vhdl-makefile-generation-hook)
17594 (message "Generating makefile \"%s\"...done" makefile-name)
17595 ;; save and close file
17596 (if (file-writable-p makefile-path-name)
17597 (progn (save-buffer)
17598 (kill-buffer (current-buffer))
17599 (set-buffer orig-buffer)
17600 (when (fboundp 'add-to-history)
17601 (add-to-history 'file-name-history makefile-path-name)))
17602 (vhdl-warning-when-idle
17603 (format "File not writable: \"%s\""
17604 (abbreviate-file-name makefile-path-name)))
17605 (switch-to-buffer (current-buffer))))))
17608 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17609 ;;; Bug reports
17610 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17611 ;; (using `reporter.el')
17613 (defconst vhdl-mode-help-address
17614 "Reto Zimmermann <reto@gnu.org>"
17615 "Address for VHDL Mode bug reports.")
17617 (defun vhdl-submit-bug-report ()
17618 "Submit via mail a bug report on VHDL Mode."
17619 (interactive)
17620 ;; load in reporter
17621 (and
17622 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17623 (let ((reporter-prompt-for-summary-p t))
17624 (reporter-submit-bug-report
17625 vhdl-mode-help-address
17626 (concat "VHDL Mode " vhdl-version)
17627 (list
17628 ;; report all important user options
17629 'vhdl-offsets-alist
17630 'vhdl-comment-only-line-offset
17631 'tab-width
17632 'vhdl-electric-mode
17633 'vhdl-stutter-mode
17634 'vhdl-indent-tabs-mode
17635 'vhdl-project-alist
17636 'vhdl-project
17637 'vhdl-project-file-name
17638 'vhdl-project-auto-load
17639 'vhdl-project-sort
17640 'vhdl-compiler-alist
17641 'vhdl-compiler
17642 'vhdl-compile-use-local-error-regexp
17643 'vhdl-makefile-default-targets
17644 'vhdl-makefile-generation-hook
17645 'vhdl-default-library
17646 'vhdl-standard
17647 'vhdl-basic-offset
17648 'vhdl-upper-case-keywords
17649 'vhdl-upper-case-types
17650 'vhdl-upper-case-attributes
17651 'vhdl-upper-case-enum-values
17652 'vhdl-upper-case-constants
17653 'vhdl-use-direct-instantiation
17654 'vhdl-array-index-record-field-in-sensitivity-list
17655 'vhdl-compose-configuration-name
17656 'vhdl-entity-file-name
17657 'vhdl-architecture-file-name
17658 'vhdl-configuration-file-name
17659 'vhdl-package-file-name
17660 'vhdl-file-name-case
17661 'vhdl-electric-keywords
17662 'vhdl-optional-labels
17663 'vhdl-insert-empty-lines
17664 'vhdl-argument-list-indent
17665 'vhdl-association-list-with-formals
17666 'vhdl-conditions-in-parenthesis
17667 'vhdl-sensitivity-list-all
17668 'vhdl-zero-string
17669 'vhdl-one-string
17670 'vhdl-file-header
17671 'vhdl-file-footer
17672 'vhdl-company-name
17673 'vhdl-copyright-string
17674 'vhdl-platform-spec
17675 'vhdl-date-format
17676 'vhdl-modify-date-prefix-string
17677 'vhdl-modify-date-on-saving
17678 'vhdl-reset-kind
17679 'vhdl-reset-active-high
17680 'vhdl-clock-rising-edge
17681 'vhdl-clock-edge-condition
17682 'vhdl-clock-name
17683 'vhdl-reset-name
17684 'vhdl-model-alist
17685 'vhdl-include-port-comments
17686 'vhdl-include-direction-comments
17687 'vhdl-include-type-comments
17688 'vhdl-include-group-comments
17689 'vhdl-actual-generic-name
17690 'vhdl-actual-port-name
17691 'vhdl-instance-name
17692 'vhdl-testbench-entity-name
17693 'vhdl-testbench-architecture-name
17694 'vhdl-testbench-configuration-name
17695 'vhdl-testbench-dut-name
17696 'vhdl-testbench-include-header
17697 'vhdl-testbench-declarations
17698 'vhdl-testbench-statements
17699 'vhdl-testbench-initialize-signals
17700 'vhdl-testbench-include-library
17701 'vhdl-testbench-include-configuration
17702 'vhdl-testbench-create-files
17703 'vhdl-testbench-entity-file-name
17704 'vhdl-testbench-architecture-file-name
17705 'vhdl-compose-create-files
17706 'vhdl-compose-configuration-create-file
17707 'vhdl-compose-configuration-hierarchical
17708 'vhdl-compose-configuration-use-subconfiguration
17709 'vhdl-compose-include-header
17710 'vhdl-compose-architecture-name
17711 'vhdl-components-package-name
17712 'vhdl-use-components-package
17713 'vhdl-self-insert-comments
17714 'vhdl-prompt-for-comments
17715 'vhdl-inline-comment-column
17716 'vhdl-end-comment-column
17717 'vhdl-auto-align
17718 'vhdl-align-groups
17719 'vhdl-align-group-separate
17720 'vhdl-align-same-indent
17721 'vhdl-highlight-keywords
17722 'vhdl-highlight-names
17723 'vhdl-highlight-special-words
17724 'vhdl-highlight-forbidden-words
17725 'vhdl-highlight-verilog-keywords
17726 'vhdl-highlight-translate-off
17727 'vhdl-highlight-case-sensitive
17728 'vhdl-special-syntax-alist
17729 'vhdl-forbidden-words
17730 'vhdl-forbidden-syntax
17731 'vhdl-directive-keywords
17732 'vhdl-speedbar-auto-open
17733 'vhdl-speedbar-display-mode
17734 'vhdl-speedbar-scan-limit
17735 'vhdl-speedbar-jump-to-unit
17736 'vhdl-speedbar-update-on-saving
17737 'vhdl-speedbar-save-cache
17738 'vhdl-speedbar-cache-file-name
17739 'vhdl-index-menu
17740 'vhdl-source-file-menu
17741 'vhdl-hideshow-menu
17742 'vhdl-hide-all-init
17743 'vhdl-print-two-column
17744 'vhdl-print-customize-faces
17745 'vhdl-intelligent-tab
17746 'vhdl-indent-syntax-based
17747 'vhdl-indent-comment-like-next-code-line
17748 'vhdl-word-completion-case-sensitive
17749 'vhdl-word-completion-in-minibuffer
17750 'vhdl-underscore-is-part-of-word
17751 'vhdl-mode-hook)
17752 (function
17753 (lambda ()
17754 (insert
17755 (if vhdl-special-indent-hook
17756 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17757 "vhdl-special-indent-hook is set to '"
17758 (format "%s" vhdl-special-indent-hook)
17759 ".\nPerhaps this is your problem?\n"
17760 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17761 "\n"))))
17763 "Hi Reto,"))))
17766 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17767 ;;; Documentation
17768 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17770 (defconst vhdl-doc-release-notes nil
17772 Release Notes for VHDL Mode 3.37
17773 ================================
17775 - Added support for VHDL'08:
17776 - New keywords, types, functions, attributes, operators, packages
17777 - Context declaration
17778 - Block comments
17779 - Directives
17780 - 'all' keyword in sensitivity list
17783 Release Notes for VHDL Mode 3.34
17784 ================================
17786 - Added support for GNU Emacs 22/23/24:
17787 - Compilation error parsing fixed for new `compile.el' package.
17789 - Port translation: Derive actual generic name from formal generic name.
17791 - New user options:
17792 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17795 Release Notes for VHDL Mode 3.33
17796 ================================
17798 New Features
17799 ------------
17801 CONFIGURATION DECLARATION GENERATION:
17802 - Automatic generation of a configuration declaration for a design.
17803 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17806 Key Bindings
17807 ------------
17809 For Emacs compliance the following key bindings have been changed:
17811 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17812 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17813 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17814 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17817 User Options
17818 ------------
17820 `vhdl-configuration-file-name': (new)
17821 Specify how the configuration file name is obtained.
17822 `vhdl-compose-configuration-name': (new)
17823 Specify how the configuration name is obtained.
17824 `vhdl-compose-configuration-create-file': (new)
17825 Specify whether a new file should be created for a configuration.
17826 `vhdl-compose-configuration-hierarchical': (new)
17827 Specify whether hierarchical configurations should be created.
17828 `vhdl-compose-configuration-use-subconfiguration': (new)
17829 Specify whether subconfigurations should be used inside configurations.
17830 `vhdl-makefile-default-targets': (new)
17831 Customize names of Makefile default targets.
17832 `vhdl-indent-comment-like-next-code-line': (new)
17833 Specify whether comment lines are indented like following code line.
17834 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17835 Specify whether to include array indices / record fields in sensitivity list.
17839 (defconst vhdl-doc-keywords nil
17841 Reserved words in VHDL
17842 ----------------------
17844 VHDL'08 (IEEE Std 1076-2008):
17845 `vhdl-08-keywords' : keywords
17846 `vhdl-08-types' : standardized types
17847 `vhdl-08-attributes' : standardized attributes
17848 `vhdl-08-functions' : standardized functions
17849 `vhdl-08-packages' : standardized packages and libraries
17851 VHDL'93/02 (IEEE Std 1076-1993/2002):
17852 `vhdl-02-keywords' : keywords
17853 `vhdl-02-types' : standardized types
17854 `vhdl-02-attributes' : standardized attributes
17855 `vhdl-02-enum-values' : standardized enumeration values
17856 `vhdl-02-functions' : standardized functions
17857 `vhdl-02-packages' : standardized packages and libraries
17859 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17860 `vhdl-ams-keywords' : keywords
17861 `vhdl-ams-types' : standardized types
17862 `vhdl-ams-attributes' : standardized attributes
17863 `vhdl-ams-enum-values' : standardized enumeration values
17864 `vhdl-ams-constants' : standardized constants
17865 `vhdl-ams-functions' : standardized functions
17867 Math Packages (IEEE Std 1076.2):
17868 `vhdl-math-types' : standardized types
17869 `vhdl-math-constants' : standardized constants
17870 `vhdl-math-functions' : standardized functions
17871 `vhdl-math-packages' : standardized packages
17873 Forbidden words:
17874 `vhdl-verilog-keywords' : Verilog reserved words
17876 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17879 (defconst vhdl-doc-coding-style nil
17881 For VHDL coding style and naming convention guidelines, see the following
17882 references:
17884 \[1] Ben Cohen.
17885 \"VHDL Coding Styles and Methodologies\".
17886 Kluwer Academic Publishers, 1999.
17887 http://members.aol.com/vhdlcohen/vhdl/
17889 \[2] Michael Keating and Pierre Bricaud.
17890 \"Reuse Methodology Manual, Second Edition\".
17891 Kluwer Academic Publishers, 1999.
17892 http://www.openmore.com/openmore/rmm2.html
17894 \[3] European Space Agency.
17895 \"VHDL Modelling Guidelines\".
17896 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17898 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17899 to visually support naming conventions.")
17902 (defun vhdl-version ()
17903 "Echo the current version of VHDL Mode in the minibuffer."
17904 (interactive)
17905 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17906 (vhdl-keep-region-active))
17908 (defun vhdl-doc-variable (variable)
17909 "Display VARIABLE's documentation in *Help* buffer."
17910 (interactive)
17911 (unless (featurep 'xemacs)
17912 (help-setup-xref (list #'vhdl-doc-variable variable)
17913 (called-interactively-p 'interactive)))
17914 (with-output-to-temp-buffer
17915 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17916 (princ (documentation-property variable 'variable-documentation))
17917 (with-current-buffer standard-output
17918 (help-mode))
17919 (help-print-return-message)))
17921 (defun vhdl-doc-mode ()
17922 "Display VHDL Mode documentation in *Help* buffer."
17923 (interactive)
17924 (unless (featurep 'xemacs)
17925 (help-setup-xref (list #'vhdl-doc-mode)
17926 (called-interactively-p 'interactive)))
17927 (with-output-to-temp-buffer
17928 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17929 (princ mode-name)
17930 (princ " mode:\n")
17931 (princ (documentation 'vhdl-mode))
17932 (with-current-buffer standard-output
17933 (help-mode))
17934 (help-print-return-message)))
17937 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17939 (provide 'vhdl-mode)
17941 ;;; vhdl-mode.el ends here