Prefer typical American spelling for "acknowledgment".
[emacs.git] / lisp / progmodes / vhdl-mode.el
blob607ccd8b7e7b14d6f3d0cee9e9e110f14ced8b61
1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2012 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.33.28"
17 "VHDL Mode version number.")
19 (defconst vhdl-time-stamp "2010-09-22"
20 "VHDL Mode time stamp for last update.")
22 ;; This file is part of GNU Emacs.
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;; Commentary:
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;; This package provides an Emacs major mode for editing VHDL code.
42 ;; It includes the following features:
44 ;; - Syntax highlighting
45 ;; - Indentation
46 ;; - Template insertion (electrification)
47 ;; - Insertion of file headers
48 ;; - Insertion of user-specified models
49 ;; - Port translation / testbench generation
50 ;; - Structural composition
51 ;; - Configuration generation
52 ;; - Sensitivity list updating
53 ;; - File browser
54 ;; - Design hierarchy browser
55 ;; - Source file compilation (syntax analysis)
56 ;; - Makefile generation
57 ;; - Code hiding
58 ;; - Word/keyword completion
59 ;; - Block commenting
60 ;; - Code fixing/alignment/beautification
61 ;; - PostScript printing
62 ;; - VHDL'87/'93 and VHDL-AMS supported
63 ;; - Comprehensive menu
64 ;; - Fully customizable
65 ;; - Works under GNU Emacs (recommended) and XEmacs
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;; Documentation
70 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; Emacs Versions
75 ;; supported: GNU Emacs 20.X/21.X/22.X,23.X, XEmacs 20.X/21.X
76 ;; tested on: GNU Emacs 20.4/21.3/22.1,23.X, XEmacs 21.1 (marginally)
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79 ;; Installation
81 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X/23.X, XEmacs 20.X/21.X.
83 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
84 ;; or into an arbitrary directory that is added to the load path by the
85 ;; following line in your Emacs start-up file `.emacs':
87 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
89 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
90 ;; directory. Otherwise, byte-compile the source file:
91 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
92 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
94 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
95 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
96 ;; (not required in Emacs 20 and higher):
98 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
99 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
101 ;; More detailed installation instructions are included in the official
102 ;; VHDL Mode distribution.
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105 ;; Acknowledgments
107 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
108 ;; and Steve Grout.
110 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
111 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
113 ;; Many thanks to all the users who sent me bug reports and enhancement
114 ;; requests.
115 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
116 ;; enhancement suggestions and the fruitful discussions.
117 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
118 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
120 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
121 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
122 ;; giving me the opportunity to develop this code.
123 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
124 ;; of the Swiss Government.
126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128 ;;; Code:
130 ;; Emacs 21+ handling
131 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
132 "Non-nil if GNU Emacs 21, 22, ... is used.")
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 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
214 nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
215 ("\\s-\\([0-9]+\\):" 0 1 0) ("Compiling file \\(.+\\)" 1)
216 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
217 "PACK/\\1.vif" "BODY/\\1.vif" upcase))
218 ;; Aldec
219 ;; COMP96 ERROR COMP96_0078: "Unknown identifier "Addr_Bits"." "<filename>" 40 30
220 ("Aldec" "vcom" "-93 -work \\1" "make" "-f \\1"
221 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
222 (".+?[ \t]+\\(?:ERROR\\)[^:]+:.+?\\(?:.+\"\\(.+?\\)\"[ \t]+\\([0-9]+\\)\\)" 1 2 0) ("" 0)
223 nil)
224 ;; Cadence Leapfrog: cv -file test.vhd
225 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
226 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
227 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
228 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
229 ("\\1/entity" "\\2/\\1" "\\1/configuration"
230 "\\1/package" "\\1/body" downcase))
231 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
232 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
233 ;; (PLL_400X_TOP) is not declared [10.3].
234 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
235 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
236 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
237 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
238 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
239 ;; ghdl vhdl: ghdl test.vhd
240 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
241 nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
242 ("ghdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
243 ("\\1/entity" "\\2/\\1" "\\1/configuration"
244 "\\1/package" "\\1/body" downcase))
245 ;; Ikos Voyager: analyze test.vhd
246 ;; analyze test.vhd
247 ;; E L4/C5: this library unit is inaccessible
248 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
249 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
250 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
251 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
252 nil)
253 ;; ModelSim, Model Technology: vcom test.vhd
254 ;; ERROR: test.vhd(14): Unknown identifier: positiv
255 ;; WARNING[2]: test.vhd(85): Possible infinite loop
256 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
257 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
258 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
259 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
260 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*:\\( *\[[0-9]+\]\\)? \\(.+\\)(\\([0-9]+\\)):" 3 4 0) ("" 0)
261 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
262 "\\1/_primary.dat" "\\1/body.dat" downcase))
263 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
264 ;; test.vhd:34: error message
265 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
266 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
267 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
268 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
269 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
270 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
271 ;; ERROR: test.vhd(24): near "dnd": expecting: END
272 ;; WARNING[4]: test.vhd(30): A space is required between ...
273 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
274 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
275 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
276 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
277 "\\1/_primary.dat" "\\1/body.dat" downcase))
278 ;; Savant: scram -publish-cc test.vhd
279 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
280 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
281 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
282 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
283 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
284 "\\1_config.vhdl" "\\1_package.vhdl"
285 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
286 ;; Simili: vhdlp -work test.vhd
287 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
288 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
289 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
290 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
291 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
292 "\\1/prim.var" "\\1/_body.var" downcase))
293 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
294 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
295 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
296 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
297 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
298 nil)
299 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
300 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
301 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
302 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
303 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
304 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
305 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
306 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
307 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
308 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
309 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
310 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
311 ;; Synplify:
312 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
313 ("Synplify" "n/a" "n/a" "make" "-f \\1"
314 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
315 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
316 nil)
317 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
318 ;; Compiling "test.vhd" line 1...
319 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
320 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
321 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
322 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
323 ("^ *Compiling \"\\(.+\\)\" " 1)
324 nil)
325 ;; VeriBest: vc vhdl test.vhd
326 ;; (no file name printed out!)
327 ;; 32: Z <= A and BitA ;
328 ;; ^^^^
329 ;; [Error] Name BITA is unknown
330 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
331 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
332 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
333 nil)
334 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
335 ;; Compiling "test.vhd" line 1...
336 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
337 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
338 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
339 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
340 ("^ *Compiling \"\\(.+\\)\" " 1)
341 nil)
342 ;; Xilinx XST:
343 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
344 ("Xilinx XST" "xflow" "" "make" "-f \\1"
345 nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
346 ("^ERROR:HDLParsers:[0-9]+ - \"\\(.+\\)\" Line \\([0-9]+\\)\." 1 2 0) ("" 0)
347 nil)
349 "List of available VHDL compilers and their properties.
350 Each list entry specifies the following items for a compiler:
351 Compiler:
352 Compiler name : name used in option `vhdl-compiler' to choose compiler
353 Compile command : command used for source file compilation
354 Compile options : compile options (\"\\1\" inserts library name)
355 Make command : command used for compilation using a Makefile
356 Make options : make options (\"\\1\" inserts Makefile name)
357 Generate Makefile: use built-in function or command to generate a Makefile
358 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
359 Library command : command to create library directory \(\"\\1\" inserts
360 library directory, \"\\2\" inserts library name)
361 Compile directory: where compilation is run and the Makefile is placed
362 Library directory: directory of default library
363 Makefile name : name of Makefile (default is \"Makefile\")
364 ID string : compiler identification string (see `vhdl-project-alist')
365 Error message:
366 Regexp : regular expression to match error messages (*)
367 File subexp index: index of subexpression that matches the file name
368 Line subexp index: index of subexpression that matches the line number
369 Column subexp idx: index of subexpression that matches the column number
370 File message:
371 Regexp : regular expression to match a file name message
372 File subexp index: index of subexpression that matches the file name
373 Unit-to-file name mapping: mapping of library unit names to names of files
374 generated by the compiler (used for Makefile generation)
375 To string : string a name is mapped to (\"\\1\" inserts the unit name,
376 \"\\2\" inserts the entity name for architectures)
377 Case adjustment : adjust case of inserted unit names
379 \(*) The regular expression must match the error message starting from the
380 beginning of the line (but not necessarily to the end of the line).
382 Compile options allows insertion of the library name (see `vhdl-project-alist')
383 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
385 For Makefile generation, the built-in function can be used (requires
386 specification of the unit-to-file name mapping). Alternatively, an
387 external command can be specified. Work directory allows specification of
388 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
389 used for Makefile generation). To use another library name than \"work\",
390 customize `vhdl-project-alist'. The library command is inserted in Makefiles
391 to automatically create the library directory if not existent.
393 Compile options, compile directory, library directory, and Makefile name are
394 overwritten by the project settings if a project is defined (see
395 `vhdl-project-alist'). Directory paths are relative to the source file
396 directory.
398 Some compilers do not include the file name in the error message, but print
399 out a file name message in advance. In this case, set \"File Subexp Index\"
400 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
401 If no file name at all is printed out, set both \"File Message\" entries to 0
402 \(a default file name message will be printed out instead, does not work in
403 XEmacs).
405 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
406 assigning its name to option `vhdl-compiler'.
408 Please send any missing or erroneous compiler properties to the maintainer for
409 updating.
411 NOTE: Activate new error and file message regexps and reflect the new setting
412 in the choice list of option `vhdl-compiler' by restarting Emacs."
413 :type '(repeat
414 (list :tag "Compiler" :indent 2
415 (string :tag "Compiler name ")
416 (string :tag "Compile command ")
417 (string :tag "Compile options " "-work \\1")
418 (string :tag "Make command " "make")
419 (string :tag "Make options " "-f \\1")
420 (choice :tag "Generate Makefile "
421 (const :tag "Built-in function" nil)
422 (string :tag "Command" "vmake \\2 > \\1"))
423 (string :tag "Library command " "mkdir \\1")
424 (directory :tag "Compile directory "
425 :validate vhdl-widget-directory-validate "./")
426 (directory :tag "Library directory "
427 :validate vhdl-widget-directory-validate "work/")
428 (file :tag "Makefile name " "Makefile")
429 (string :tag "ID string ")
430 (list :tag "Error message" :indent 4
431 (regexp :tag "Regexp ")
432 (integer :tag "File subexp index")
433 (integer :tag "Line subexp index")
434 (integer :tag "Column subexp idx"))
435 (list :tag "File message" :indent 4
436 (regexp :tag "Regexp ")
437 (integer :tag "File subexp index"))
438 (choice :tag "Unit-to-file name mapping"
439 :format "%t: %[Value Menu%] %v\n"
440 (const :tag "Not defined" nil)
441 (list :tag "To string" :indent 4
442 (string :tag "Entity " "\\1.vhd")
443 (string :tag "Architecture " "\\2_\\1.vhd")
444 (string :tag "Configuration " "\\1.vhd")
445 (string :tag "Package " "\\1.vhd")
446 (string :tag "Package Body " "\\1_body.vhd")
447 (choice :tag "Case adjustment "
448 (const :tag "None" identity)
449 (const :tag "Upcase" upcase)
450 (const :tag "Downcase" downcase))))))
451 :set (lambda (variable value)
452 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
453 :group 'vhdl-compile)
455 (defcustom vhdl-compiler "GHDL"
456 "Specifies the VHDL compiler to be used for syntax analysis.
457 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
458 :type (let ((alist vhdl-compiler-alist) list)
459 (while alist
460 (setq list (cons (list 'const (caar alist)) list))
461 (setq alist (cdr alist)))
462 (append '(choice) (nreverse list)))
463 :group 'vhdl-compile)
465 (defcustom vhdl-compile-use-local-error-regexp t
466 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
467 In this case, only error message regexps for VHDL compilers are active if
468 compilation is started from a VHDL buffer. Otherwise, the error message
469 regexps are appended to the predefined global regexps, and all regexps are
470 active all the time. Note that by doing that, the predefined global regexps
471 might result in erroneous parsing of error messages for some VHDL compilers.
473 NOTE: Activate the new setting by restarting Emacs."
474 :type 'boolean
475 :group 'vhdl-compile)
477 (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
478 "List of default target names in Makefiles.
479 Automatically generated Makefiles include three default targets to compile
480 the entire design, clean the entire design and to create the design library.
481 This option allows to change the names of these targets to avoid conflicts
482 with other user Makefiles."
483 :type '(list (string :tag "Compile entire design")
484 (string :tag "Clean entire design ")
485 (string :tag "Create design library"))
486 :group 'vhdl-compile)
488 (defcustom vhdl-makefile-generation-hook nil
489 "Functions to run at the end of Makefile generation.
490 Allows to insert user specific parts into a Makefile.
492 Example:
493 \(lambda nil
494 \(re-search-backward \"^# Rule for compiling entire design\")
495 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
496 :type 'hook
497 :group 'vhdl-compile)
499 (defcustom vhdl-default-library "work"
500 "Name of default library.
501 Is overwritten by project settings if a project is active."
502 :type 'string
503 :group 'vhdl-compile)
506 (defgroup vhdl-project nil
507 "Customizations for projects."
508 :group 'vhdl)
510 (defcustom vhdl-project-alist
511 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
512 "~/example1/" ("src/system/" "src/components/") ""
513 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
514 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
515 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
516 ("Example 2" "Individual source files, multiple compilers in different directories"
517 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
518 nil "\\1/" "work" "\\1/work/" "Makefile" "")
519 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
520 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
521 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
522 -------------------------------------------------------------------------------
523 -- This is a multi-line project description
524 -- that can be used as a project dependent part of the file header.
526 "List of projects and their properties.
527 Name : name used in option `vhdl-project' to choose project
528 Title : title of project (single-line string)
529 Default directory: default project directory (absolute path)
530 Sources : a) source files : path + \"/\" + file name
531 b) directory : path + \"/\"
532 c) directory tree: \"-r \" + path + \"/\"
533 Exclude regexp : matches file/directory names to be excluded as sources
534 Compile options : project-specific options for each compiler
535 Compiler name : name of compiler for which these options are valid
536 Compile options: project-specific compiler options
537 (\"\\1\" inserts library name, \"\\2\" default options)
538 Make options: project-specific make options
539 (\"\\1\" inserts Makefile name, \"\\2\" default options)
540 Exceptions : file-specific exceptions
541 File name regexp: matches file names for which exceptions are valid
542 - Options : file-specific compiler options string
543 (\"\\1\" inserts library name, \"\\2\" default options,
544 \"\\3\" project-specific options)
545 - Do not compile: do not compile this file (in Makefile)
546 Compile directory: where compilation is run and the Makefile is placed
547 \(\"\\1\" inserts compiler ID string)
548 Library name : name of library (default is \"work\")
549 Library directory: path to library (\"\\1\" inserts compiler ID string)
550 Makefile name : name of Makefile
551 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
552 Description : description of project (multi-line string)
554 Project title and description are used to insert into the file header (see
555 option `vhdl-file-header').
557 The default directory must have an absolute path (use `M-TAB' for completion).
558 All other paths can be absolute or relative to the default directory. All
559 paths must end with '/'.
561 The design units found in the sources (files and directories) are shown in the
562 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
563 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
564 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
565 specified, the default directory is taken as source directory. Otherwise,
566 the default directory is only taken as source directory if there is a sources
567 entry with the empty string or \"./\". Exclude regexp allows to filter out
568 specific file and directory names from the list of sources (e.g. CVS
569 directories).
571 Files are compiled in the compile directory. Makefiles are also placed into
572 the compile directory. Library directory specifies which directory the
573 compiler compiles into (used to generate the Makefile).
575 Since different compile/library directories and Makefiles may exist for
576 different compilers within one project, these paths and names allow the
577 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
578 Compile options, compile directory, library directory, and Makefile name
579 overwrite the settings of the current compiler.
581 File-specific compiler options (highest priority) overwrite project-specific
582 options which overwrite default options (lowest priority). Lower priority
583 options can be inserted in higher priority options. This allows to reuse
584 default options (e.g. \"-file\") in project- or file-specific options (e.g.
585 \"-93 -file\").
587 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
588 by restarting Emacs."
589 :type `(repeat
590 (list :tag "Project" :indent 2
591 (string :tag "Name ")
592 (string :tag "Title ")
593 (directory :tag "Default directory"
594 :validate vhdl-widget-directory-validate
595 ,(abbreviate-file-name default-directory))
596 (repeat :tag "Sources " :indent 4
597 (directory :format " %v" "./"))
598 (regexp :tag "Exclude regexp ")
599 (repeat
600 :tag "Compile options " :indent 4
601 (list :tag "Compiler" :indent 6
602 ,(let ((alist vhdl-compiler-alist) list)
603 (while alist
604 (setq list (cons (list 'const (caar alist)) list))
605 (setq alist (cdr alist)))
606 (append '(choice :tag "Compiler name")
607 (nreverse list)))
608 (string :tag "Compile options" "\\2")
609 (string :tag "Make options " "\\2")
610 (repeat
611 :tag "Exceptions " :indent 8
612 (cons :format "%v"
613 (regexp :tag "File name regexp ")
614 (choice :format "%[Value Menu%] %v"
615 (string :tag "Options" "\\3")
616 (const :tag "Do not compile" nil))))))
617 (directory :tag "Compile directory"
618 :validate vhdl-widget-directory-validate "./")
619 (string :tag "Library name " "work")
620 (directory :tag "Library directory"
621 :validate vhdl-widget-directory-validate "work/")
622 (file :tag "Makefile name " "Makefile")
623 (string :tag "Description: (type `C-j' for newline)"
624 :format "%t\n%v\n")))
625 :set (lambda (variable value)
626 (vhdl-custom-set variable value
627 'vhdl-update-mode-menu
628 'vhdl-speedbar-refresh))
629 :group 'vhdl-project)
631 (defcustom vhdl-project nil
632 "Specifies the default for the current project.
633 Select a project name from the ones defined in option `vhdl-project-alist'.
634 Is used to determine the project title and description to be inserted in file
635 headers and the source files/directories to be scanned in the hierarchy
636 browser. The current project can also be changed temporarily in the menu."
637 :type (let ((alist vhdl-project-alist) list)
638 (while alist
639 (setq list (cons (list 'const (caar alist)) list))
640 (setq alist (cdr alist)))
641 (append '(choice (const :tag "None" nil) (const :tag "--"))
642 (nreverse list)))
643 :group 'vhdl-project)
645 (defcustom vhdl-project-file-name '("\\1.prj")
646 "List of file names/paths for importing/exporting project setups.
647 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
648 replaced by the user name (allows to have user-specific project setups).
649 The first entry is used as file name to import/export individual project
650 setups. All entries are used to automatically import project setups at
651 startup (see option `vhdl-project-auto-load'). Projects loaded from the
652 first entry are automatically made current. Hint: specify local project
653 setups in first entry, global setups in following entries; loading a local
654 project setup will make it current, while loading the global setups
655 is done without changing the current project.
656 Names can also have an absolute path (i.e. project setups can be stored
657 in global directories)."
658 :type '(repeat (string :tag "File name" "\\1.prj"))
659 :group 'vhdl-project)
661 (defcustom vhdl-project-auto-load '(startup)
662 "Automatically load project setups from files.
663 All project setup files that match the file names specified in option
664 `vhdl-project-file-name' are automatically loaded. The project of the
665 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
666 entry is activated.
667 A project setup file can be obtained by exporting a project (see menu).
668 At startup: project setup file is loaded at Emacs startup"
669 :type '(set (const :tag "At startup" startup))
670 :group 'vhdl-project)
672 (defcustom vhdl-project-sort t
673 "Non-nil means projects are displayed in alphabetical order."
674 :type 'boolean
675 :group 'vhdl-project)
678 (defgroup vhdl-style nil
679 "Customizations for coding styles."
680 :group 'vhdl
681 :group 'vhdl-template
682 :group 'vhdl-port
683 :group 'vhdl-compose)
685 (defcustom vhdl-standard '(93 nil)
686 "VHDL standards used.
687 Basic standard:
688 VHDL'87 : IEEE Std 1076-1987
689 VHDL'93/02 : IEEE Std 1076-1993/2002
690 Additional standards:
691 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
692 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
694 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
695 \"Activate Options\"."
696 :type '(list (choice :tag "Basic standard"
697 (const :tag "VHDL'87" 87)
698 (const :tag "VHDL'93/02" 93))
699 (set :tag "Additional standards" :indent 2
700 (const :tag "VHDL-AMS" ams)
701 (const :tag "Math packages" math)))
702 :set (lambda (variable value)
703 (vhdl-custom-set variable value
704 'vhdl-template-map-init
705 'vhdl-mode-abbrev-table-init
706 'vhdl-template-construct-alist-init
707 'vhdl-template-package-alist-init
708 'vhdl-update-mode-menu
709 'vhdl-words-init 'vhdl-font-lock-init))
710 :group 'vhdl-style)
712 (defcustom vhdl-basic-offset 2
713 "Amount of basic offset used for indentation.
714 This value is used by + and - symbols in `vhdl-offsets-alist'."
715 :type 'integer
716 :group 'vhdl-style)
718 (defcustom vhdl-upper-case-keywords nil
719 "Non-nil means convert keywords to upper case.
720 This is done when typed or expanded or by the fix case functions."
721 :type 'boolean
722 :set (lambda (variable value)
723 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
724 :group 'vhdl-style)
726 (defcustom vhdl-upper-case-types nil
727 "Non-nil means convert standardized types to upper case.
728 This is done when expanded or by the fix case functions."
729 :type 'boolean
730 :set (lambda (variable value)
731 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
732 :group 'vhdl-style)
734 (defcustom vhdl-upper-case-attributes nil
735 "Non-nil means convert standardized attributes to upper case.
736 This is done when expanded or by the fix case functions."
737 :type 'boolean
738 :set (lambda (variable value)
739 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
740 :group 'vhdl-style)
742 (defcustom vhdl-upper-case-enum-values nil
743 "Non-nil means convert standardized enumeration values to upper case.
744 This is done when expanded or by the fix case functions."
745 :type 'boolean
746 :set (lambda (variable value)
747 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
748 :group 'vhdl-style)
750 (defcustom vhdl-upper-case-constants t
751 "Non-nil means convert standardized constants to upper case.
752 This is done when expanded."
753 :type 'boolean
754 :set (lambda (variable value)
755 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
756 :group 'vhdl-style)
758 (defcustom vhdl-use-direct-instantiation 'standard
759 "Non-nil means use VHDL'93 direct component instantiation.
760 Never : never
761 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
762 Always : always"
763 :type '(choice (const :tag "Never" never)
764 (const :tag "Standard" standard)
765 (const :tag "Always" always))
766 :group 'vhdl-style)
768 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
769 "Non-nil means include array indices / record fields in sensitivity list.
770 If a signal read in a process is a record field or pointed to by an array
771 index, the record field or array index is included with the record name in
772 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
773 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
774 :type 'boolean
775 :group 'vhdl-style)
777 (defgroup vhdl-naming nil
778 "Customizations for naming conventions."
779 :group 'vhdl)
781 (defcustom vhdl-entity-file-name '(".*" . "\\&")
782 (concat
783 "Specifies how the entity file name is obtained.
784 The entity file name can be obtained by modifying the entity name (e.g.
785 attaching or stripping off a substring). The file extension is automatically
786 taken from the file name of the current buffer."
787 vhdl-name-doc-string)
788 :type '(cons (regexp :tag "From regexp")
789 (string :tag "To string "))
790 :group 'vhdl-naming
791 :group 'vhdl-compose)
793 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
794 (concat
795 "Specifies how the architecture file name is obtained.
796 The architecture file name can be obtained by modifying the entity
797 and/or architecture name (e.g. attaching or stripping off a substring). The
798 file extension is automatically taken from the file name of the current
799 buffer. The string that is matched against the regexp is the concatenation
800 of the entity and the architecture name separated by a space. This gives
801 access to both names (see default setting as example)."
802 vhdl-name-doc-string)
803 :type '(cons (regexp :tag "From regexp")
804 (string :tag "To string "))
805 :group 'vhdl-naming
806 :group 'vhdl-compose)
808 (defcustom vhdl-configuration-file-name '(".*" . "\\&")
809 (concat
810 "Specifies how the configuration file name is obtained.
811 The configuration file name can be obtained by modifying the configuration
812 name (e.g. attaching or stripping off a substring). The file extension is
813 automatically taken from the file name of the current buffer."
814 vhdl-name-doc-string)
815 :type '(cons (regexp :tag "From regexp")
816 (string :tag "To string "))
817 :group 'vhdl-naming
818 :group 'vhdl-compose)
820 (defcustom vhdl-package-file-name '(".*" . "\\&")
821 (concat
822 "Specifies how the package file name is obtained.
823 The package file name can be obtained by modifying the package name (e.g.
824 attaching or stripping off a substring). The file extension is automatically
825 taken from the file name of the current buffer. Package files can be created
826 in a different directory by prepending a relative or absolute path to the
827 file name."
828 vhdl-name-doc-string)
829 :type '(cons (regexp :tag "From regexp")
830 (string :tag "To string "))
831 :group 'vhdl-naming
832 :group 'vhdl-compose)
834 (defcustom vhdl-file-name-case 'identity
835 "Specifies how to change case for obtaining file names.
836 When deriving a file name from a VHDL unit name, case can be changed as
837 follows:
838 As Is: case is not changed (taken as is)
839 Lower Case: whole name is changed to lower case
840 Upper Case: whole name is changed to upper case
841 Capitalize: first letter of each word in name is capitalized"
842 :type '(choice (const :tag "As Is" identity)
843 (const :tag "Lower Case" downcase)
844 (const :tag "Upper Case" upcase)
845 (const :tag "Capitalize" capitalize))
846 :group 'vhdl-naming
847 :group 'vhdl-compose)
850 (defgroup vhdl-template nil
851 "Customizations for electrification."
852 :group 'vhdl)
854 (defcustom vhdl-electric-keywords '(vhdl user)
855 "Type of keywords for which electrification is enabled.
856 VHDL keywords: invoke built-in templates
857 User keywords: invoke user models (see option `vhdl-model-alist')"
858 :type '(set (const :tag "VHDL keywords" vhdl)
859 (const :tag "User model keywords" user))
860 :set (lambda (variable value)
861 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
862 :group 'vhdl-template)
864 (defcustom vhdl-optional-labels 'process
865 "Constructs for which labels are to be queried.
866 Template generators prompt for optional labels for:
867 None : no constructs
868 Processes only: processes only (also procedurals in VHDL-AMS)
869 All constructs: all constructs with optional labels and keyword END"
870 :type '(choice (const :tag "None" none)
871 (const :tag "Processes only" process)
872 (const :tag "All constructs" all))
873 :group 'vhdl-template)
875 (defcustom vhdl-insert-empty-lines 'unit
876 "Specifies whether to insert empty lines in some templates.
877 This improves readability of code. Empty lines are inserted in:
878 None : no constructs
879 Design units only: entities, architectures, configurations, packages only
880 All constructs : also all constructs with BEGIN...END parts
882 Replaces option `vhdl-additional-empty-lines'."
883 :type '(choice (const :tag "None" none)
884 (const :tag "Design units only" unit)
885 (const :tag "All constructs" all))
886 :group 'vhdl-template
887 :group 'vhdl-port
888 :group 'vhdl-compose)
890 (defcustom vhdl-argument-list-indent nil
891 "Non-nil means indent argument lists relative to opening parenthesis.
892 That is, argument, association, and port lists start on the same line as the
893 opening parenthesis and subsequent lines are indented accordingly.
894 Otherwise, lists start on a new line and are indented as normal code."
895 :type 'boolean
896 :group 'vhdl-template
897 :group 'vhdl-port
898 :group 'vhdl-compose)
900 (defcustom vhdl-association-list-with-formals t
901 "Non-nil means write association lists with formal parameters.
902 Templates prompt for formal and actual parameters (ports/generics).
903 When pasting component instantiations, formals are included.
904 If nil, only a list of actual parameters is entered."
905 :type 'boolean
906 :group 'vhdl-template
907 :group 'vhdl-port
908 :group 'vhdl-compose)
910 (defcustom vhdl-conditions-in-parenthesis nil
911 "Non-nil means place parenthesis around condition expressions."
912 :type 'boolean
913 :group 'vhdl-template)
915 (defcustom vhdl-zero-string "'0'"
916 "String to use for a logic zero."
917 :type 'string
918 :group 'vhdl-template)
920 (defcustom vhdl-one-string "'1'"
921 "String to use for a logic one."
922 :type 'string
923 :group 'vhdl-template)
926 (defgroup vhdl-header nil
927 "Customizations for file header."
928 :group 'vhdl-template
929 :group 'vhdl-compose)
931 (defcustom vhdl-file-header "\
932 -------------------------------------------------------------------------------
933 -- Title : <title string>
934 -- Project : <project>
935 -------------------------------------------------------------------------------
936 -- File : <filename>
937 -- Author : <author>
938 -- Company : <company>
939 -- Created : <date>
940 -- Last update: <date>
941 -- Platform : <platform>
942 -- Standard : <standard>
943 <projectdesc>-------------------------------------------------------------------------------
944 -- Description: <cursor>
945 <copyright>-------------------------------------------------------------------------------
946 -- Revisions :
947 -- Date Version Author Description
948 -- <date> 1.0 <login>\tCreated
949 -------------------------------------------------------------------------------
952 "String or file to insert as file header.
953 If the string specifies an existing file name, the contents of the file is
954 inserted, otherwise the string itself is inserted as file header.
955 Type `C-j' for newlines.
956 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
957 if the header needs to be version controlled.
959 The following keywords for template generation are supported:
960 <filename> : replaced by the name of the buffer
961 <author> : replaced by the user name and email address
962 \(`user-full-name',`mail-host-address', `user-mail-address')
963 <authorfull> : replaced by the user full name (`user-full-name')
964 <login> : replaced by user login name (`user-login-name')
965 <company> : replaced by contents of option `vhdl-company-name'
966 <date> : replaced by the current date
967 <year> : replaced by the current year
968 <project> : replaced by title of current project (`vhdl-project')
969 <projectdesc> : replaced by description of current project (`vhdl-project')
970 <copyright> : replaced by copyright string (`vhdl-copyright-string')
971 <platform> : replaced by contents of option `vhdl-platform-spec'
972 <standard> : replaced by the VHDL language standard(s) used
973 <... string> : replaced by a queried string (\"...\" is the prompt word)
974 <title string>: replaced by file title in automatically generated files
975 <cursor> : final cursor position
977 The (multi-line) project description <projectdesc> can be used as a project
978 dependent part of the file header and can also contain the above keywords."
979 :type 'string
980 :group 'vhdl-header)
982 (defcustom vhdl-file-footer ""
983 "String or file to insert as file footer.
984 If the string specifies an existing file name, the contents of the file is
985 inserted, otherwise the string itself is inserted as file footer (i.e. at
986 the end of the file).
987 Type `C-j' for newlines.
988 The same keywords as in option `vhdl-file-header' can be used."
989 :type 'string
990 :group 'vhdl-header)
992 (defcustom vhdl-company-name ""
993 "Name of company to insert in file header.
994 See option `vhdl-file-header'."
995 :type 'string
996 :group 'vhdl-header)
998 (defcustom vhdl-copyright-string "\
999 -------------------------------------------------------------------------------
1000 -- Copyright (c) <year> <company>
1002 "Copyright string to insert in file header.
1003 Can be multi-line string (type `C-j' for newline) and contain other file
1004 header keywords (see option `vhdl-file-header')."
1005 :type 'string
1006 :group 'vhdl-header)
1008 (defcustom vhdl-platform-spec ""
1009 "Specification of VHDL platform to insert in file header.
1010 The platform specification should contain names and versions of the
1011 simulation and synthesis tools used.
1012 See option `vhdl-file-header'."
1013 :type 'string
1014 :group 'vhdl-header)
1016 (defcustom vhdl-date-format "%Y-%m-%d"
1017 "Specifies the date format to use in the header.
1018 This string is passed as argument to the command `format-time-string'.
1019 For more information on format strings, see the documentation for the
1020 `format-time-string' command (C-h f `format-time-string')."
1021 :type 'string
1022 :group 'vhdl-header)
1024 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
1025 "Prefix string of modification date in VHDL file header.
1026 If actualization of the modification date is called (menu,
1027 `\\[vhdl-template-modify]'), this string is searched and the rest
1028 of the line replaced by the current date."
1029 :type 'string
1030 :group 'vhdl-header)
1032 (defcustom vhdl-modify-date-on-saving t
1033 "Non-nil means update the modification date when the buffer is saved.
1034 Calls function `\\[vhdl-template-modify]').
1036 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1037 \"Activate Options\"."
1038 :type 'boolean
1039 :group 'vhdl-header)
1042 (defgroup vhdl-sequential-process nil
1043 "Customizations for sequential processes."
1044 :group 'vhdl-template)
1046 (defcustom vhdl-reset-kind 'async
1047 "Specifies which kind of reset to use in sequential processes."
1048 :type '(choice (const :tag "None" none)
1049 (const :tag "Synchronous" sync)
1050 (const :tag "Asynchronous" async)
1051 (const :tag "Query" query))
1052 :group 'vhdl-sequential-process)
1054 (defcustom vhdl-reset-active-high nil
1055 "Non-nil means reset in sequential processes is active high.
1056 Otherwise, reset is active low."
1057 :type 'boolean
1058 :group 'vhdl-sequential-process)
1060 (defcustom vhdl-clock-rising-edge t
1061 "Non-nil means rising edge of clock triggers sequential processes.
1062 Otherwise, falling edge triggers."
1063 :type 'boolean
1064 :group 'vhdl-sequential-process)
1066 (defcustom vhdl-clock-edge-condition 'standard
1067 "Syntax of the clock edge condition.
1068 Standard: \"clk'event and clk = '1'\"
1069 Function: \"rising_edge(clk)\""
1070 :type '(choice (const :tag "Standard" standard)
1071 (const :tag "Function" function))
1072 :group 'vhdl-sequential-process)
1074 (defcustom vhdl-clock-name ""
1075 "Name of clock signal to use in templates."
1076 :type 'string
1077 :group 'vhdl-sequential-process)
1079 (defcustom vhdl-reset-name ""
1080 "Name of reset signal to use in templates."
1081 :type 'string
1082 :group 'vhdl-sequential-process)
1085 (defgroup vhdl-model nil
1086 "Customizations for user models."
1087 :group 'vhdl)
1089 (defcustom vhdl-model-alist
1090 '(("Example Model"
1091 "<label> : process (<clock>, <reset>)
1092 begin -- process <label>
1093 if <reset> = '0' then -- asynchronous reset (active low)
1094 <cursor>
1095 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1096 if <enable> = '1' then -- synchronous load
1098 end if;
1099 end if;
1100 end process <label>;"
1101 "e" ""))
1102 "List of user models.
1103 VHDL models (templates) can be specified by the user in this list. They can be
1104 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1105 electrification (i.e. overriding existing or creating new keywords, see
1106 option `vhdl-electric-keywords').
1107 Name : name of model (string of words and spaces)
1108 String : string or name of file to be inserted as model (newline: `C-j')
1109 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1110 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1111 Keyword : keyword to invoke model
1113 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1114 A prompt that appears several times is queried once and replaced throughout
1115 the model. Special prompts are:
1116 <clock> : name specified in `vhdl-clock-name' (if not empty)
1117 <reset> : name specified in `vhdl-reset-name' (if not empty)
1118 <cursor>: final cursor position
1119 File header prompts (see variable `vhdl-file-header') are automatically
1120 replaced, so that user models can also be used to insert different types of
1121 headers.
1123 If the string specifies an existing file name, the contents of the file is
1124 inserted, otherwise the string itself is inserted.
1125 The code within the models should be correctly indented.
1126 Type `C-j' for newlines.
1128 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1129 \"Activate Options\"."
1130 :type '(repeat (list :tag "Model" :indent 2
1131 (string :tag "Name ")
1132 (string :tag "String : (type `C-j' for newline)"
1133 :format "%t\n%v")
1134 (sexp :tag "Key binding" x)
1135 (string :tag "Keyword " :format "%t: %v\n")))
1136 :set (lambda (variable value)
1137 (vhdl-custom-set variable value
1138 'vhdl-model-map-init
1139 'vhdl-model-defun
1140 'vhdl-mode-abbrev-table-init
1141 'vhdl-update-mode-menu))
1142 :group 'vhdl-model)
1145 (defgroup vhdl-compose nil
1146 "Customizations for structural composition."
1147 :group 'vhdl)
1149 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1150 (concat
1151 "Specifies how the component architecture name is obtained.
1152 The component architecture name can be obtained by modifying the entity name
1153 \(e.g. attaching or stripping off a substring).
1154 If TO STRING is empty, the architecture name is queried."
1155 vhdl-name-doc-string)
1156 :type '(cons (regexp :tag "From regexp")
1157 (string :tag "To string "))
1158 :group 'vhdl-compose)
1160 (defcustom vhdl-compose-configuration-name
1161 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1162 (concat
1163 "Specifies how the configuration name is obtained.
1164 The configuration name can be obtained by modifying the entity and/or
1165 architecture name (e.g. attaching or stripping off a substring). The string
1166 that is matched against the regexp is the concatenation of the entity and the
1167 architecture name separated by a space. This gives access to both names (see
1168 default setting as example)."
1169 vhdl-name-doc-string)
1170 :type '(cons (regexp :tag "From regexp")
1171 (string :tag "To string "))
1172 :group 'vhdl-compose)
1174 (defcustom vhdl-components-package-name
1175 '((".*" . "\\&_components") . "components")
1176 (concat
1177 "Specifies how the name for the components package is obtained.
1178 The components package is a package containing all component declarations for
1179 the current design. Its name can be obtained by modifying the project name
1180 \(e.g. attaching or stripping off a substring). If no project is defined, the
1181 DIRECTORY entry is chosen."
1182 vhdl-name-doc-string)
1183 :type '(cons (cons :tag "Project" :indent 2
1184 (regexp :tag "From regexp")
1185 (string :tag "To string "))
1186 (string :tag "Directory:\n String "))
1187 :group 'vhdl-compose)
1189 (defcustom vhdl-use-components-package nil
1190 "Non-nil means use a separate components package for component declarations.
1191 Otherwise, component declarations are inserted and searched for in the
1192 architecture declarative parts."
1193 :type 'boolean
1194 :group 'vhdl-compose)
1196 (defcustom vhdl-compose-include-header t
1197 "Non-nil means include a header in automatically generated files."
1198 :type 'boolean
1199 :group 'vhdl-compose)
1201 (defcustom vhdl-compose-create-files 'single
1202 "Specifies whether new files should be created for the new component.
1203 The component's entity and architecture are inserted:
1204 None : in current buffer
1205 Single file : in new single file
1206 Separate files: in two separate files
1207 The file names are obtained from variables `vhdl-entity-file-name' and
1208 `vhdl-architecture-file-name'."
1209 :type '(choice (const :tag "None" none)
1210 (const :tag "Single file" single)
1211 (const :tag "Separate files" separate))
1212 :group 'vhdl-compose)
1214 (defcustom vhdl-compose-configuration-create-file nil
1215 "Specifies whether a new file should be created for the configuration.
1216 If non-nil, a new file is created for the configuration.
1217 The file name is obtained from variable `vhdl-configuration-file-name'."
1218 :type 'boolean
1219 :group 'vhdl-compose)
1221 (defcustom vhdl-compose-configuration-hierarchical t
1222 "Specifies whether hierarchical configurations should be created.
1223 If non-nil, automatically created configurations are hierarchical and include
1224 the whole hierarchy of subcomponents. Otherwise the configuration only
1225 includes one level of subcomponents."
1226 :type 'boolean
1227 :group 'vhdl-compose)
1229 (defcustom vhdl-compose-configuration-use-subconfiguration t
1230 "Specifies whether subconfigurations should be used inside configurations.
1231 If non-nil, automatically created configurations use configurations in binding
1232 indications for subcomponents, if such configurations exist. Otherwise,
1233 entities are used in binding indications for subcomponents."
1234 :type 'boolean
1235 :group 'vhdl-compose)
1238 (defgroup vhdl-port nil
1239 "Customizations for port translation functions."
1240 :group 'vhdl
1241 :group 'vhdl-compose)
1243 (defcustom vhdl-include-port-comments nil
1244 "Non-nil means include port comments when a port is pasted."
1245 :type 'boolean
1246 :group 'vhdl-port)
1248 (defcustom vhdl-include-direction-comments nil
1249 "Non-nil means include port direction in instantiations as comments."
1250 :type 'boolean
1251 :group 'vhdl-port)
1253 (defcustom vhdl-include-type-comments nil
1254 "Non-nil means include generic/port type in instantiations as comments."
1255 :type 'boolean
1256 :group 'vhdl-port)
1258 (defcustom vhdl-include-group-comments 'never
1259 "Specifies whether to include group comments and spacings.
1260 The comments and empty lines between groups of ports are pasted:
1261 Never : never
1262 Declarations: in entity/component/constant/signal declarations only
1263 Always : also in generic/port maps"
1264 :type '(choice (const :tag "Never" never)
1265 (const :tag "Declarations" decl)
1266 (const :tag "Always" always))
1267 :group 'vhdl-port)
1269 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1270 (concat
1271 "Specifies how actual port names are obtained from formal port names.
1272 In a component instantiation, an actual port name can be obtained by
1273 modifying the formal port name (e.g. attaching or stripping off a substring)."
1274 vhdl-name-doc-string)
1275 :type '(cons (regexp :tag "From regexp")
1276 (string :tag "To string "))
1277 :group 'vhdl-port)
1279 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1280 (concat
1281 "Specifies how an instance name is obtained.
1282 The instance name can be obtained by modifying the name of the component to be
1283 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1284 by a unique number (starting with 1).
1285 If TO STRING is empty, the instance name is queried."
1286 vhdl-name-doc-string)
1287 :type '(cons (regexp :tag "From regexp")
1288 (string :tag "To string "))
1289 :group 'vhdl-port)
1292 (defgroup vhdl-testbench nil
1293 "Customizations for testbench generation."
1294 :group 'vhdl-port)
1296 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1297 (concat
1298 "Specifies how the testbench entity name is obtained.
1299 The entity name of a testbench can be obtained by modifying the name of
1300 the component to be tested (e.g. attaching or stripping off a substring)."
1301 vhdl-name-doc-string)
1302 :type '(cons (regexp :tag "From regexp")
1303 (string :tag "To string "))
1304 :group 'vhdl-testbench)
1306 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1307 (concat
1308 "Specifies how the testbench architecture name is obtained.
1309 The testbench architecture name can be obtained by modifying the name of
1310 the component to be tested (e.g. attaching or stripping off a substring).
1311 If TO STRING is empty, the architecture name is queried."
1312 vhdl-name-doc-string)
1313 :type '(cons (regexp :tag "From regexp")
1314 (string :tag "To string "))
1315 :group 'vhdl-testbench)
1317 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1318 (concat
1319 "Specifies how the testbench configuration name is obtained.
1320 The configuration name of a testbench can be obtained by modifying the entity
1321 and/or architecture name (e.g. attaching or stripping off a substring). The
1322 string that is matched against the regexp is the concatenation of the entity
1323 and the architecture name separated by a space. This gives access to both
1324 names (see default setting as example)."
1325 vhdl-name-doc-string)
1326 :type '(cons (regexp :tag "From regexp")
1327 (string :tag "To string "))
1328 :group 'vhdl-testbench)
1330 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1331 (concat
1332 "Specifies how a DUT instance name is obtained.
1333 The design-under-test instance name (i.e. the component instantiated in the
1334 testbench) can be obtained by modifying the component name (e.g. attaching
1335 or stripping off a substring)."
1336 vhdl-name-doc-string)
1337 :type '(cons (regexp :tag "From regexp")
1338 (string :tag "To string "))
1339 :group 'vhdl-testbench)
1341 (defcustom vhdl-testbench-include-header t
1342 "Non-nil means include a header in automatically generated files."
1343 :type 'boolean
1344 :group 'vhdl-testbench)
1346 (defcustom vhdl-testbench-declarations "\
1347 -- clock
1348 signal Clk : std_logic := '1';
1350 "String or file to be inserted in the testbench declarative part.
1351 If the string specifies an existing file name, the contents of the file is
1352 inserted, otherwise the string itself is inserted in the testbench
1353 architecture before the BEGIN keyword.
1354 Type `C-j' for newlines."
1355 :type 'string
1356 :group 'vhdl-testbench)
1358 (defcustom vhdl-testbench-statements "\
1359 -- clock generation
1360 Clk <= not Clk after 10 ns;
1362 -- waveform generation
1363 WaveGen_Proc: process
1364 begin
1365 -- insert signal assignments here
1367 wait until Clk = '1';
1368 end process WaveGen_Proc;
1370 "String or file to be inserted in the testbench statement part.
1371 If the string specifies an existing file name, the contents of the file is
1372 inserted, otherwise the string itself is inserted in the testbench
1373 architecture before the END keyword.
1374 Type `C-j' for newlines."
1375 :type 'string
1376 :group 'vhdl-testbench)
1378 (defcustom vhdl-testbench-initialize-signals nil
1379 "Non-nil means initialize signals with `0' when declared in testbench."
1380 :type 'boolean
1381 :group 'vhdl-testbench)
1383 (defcustom vhdl-testbench-include-library t
1384 "Non-nil means a library/use clause for std_logic_1164 is included."
1385 :type 'boolean
1386 :group 'vhdl-testbench)
1388 (defcustom vhdl-testbench-include-configuration t
1389 "Non-nil means a testbench configuration is attached at the end."
1390 :type 'boolean
1391 :group 'vhdl-testbench)
1393 (defcustom vhdl-testbench-create-files 'single
1394 "Specifies whether new files should be created for the testbench.
1395 testbench entity and architecture are inserted:
1396 None : in current buffer
1397 Single file : in new single file
1398 Separate files: in two separate files
1399 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1400 and `vhdl-testbench-architecture-file-name'."
1401 :type '(choice (const :tag "None" none)
1402 (const :tag "Single file" single)
1403 (const :tag "Separate files" separate))
1404 :group 'vhdl-testbench)
1406 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1407 (concat
1408 "Specifies how the testbench entity file name is obtained.
1409 The entity file name can be obtained by modifying the testbench entity name
1410 \(e.g. attaching or stripping off a substring). The file extension is
1411 automatically taken from the file name of the current buffer. Testbench
1412 files can be created in a different directory by prepending a relative or
1413 absolute path to the file name."
1414 vhdl-name-doc-string)
1415 :type '(cons (regexp :tag "From regexp")
1416 (string :tag "To string "))
1417 :group 'vhdl-testbench)
1419 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1420 (concat
1421 "Specifies how the testbench architecture file name is obtained.
1422 The architecture file name can be obtained by modifying the testbench entity
1423 and/or architecture name (e.g. attaching or stripping off a substring). The
1424 string that is matched against the regexp is the concatenation of the entity
1425 and the architecture name separated by a space. This gives access to both
1426 names (see default setting as example). Testbench files can be created in
1427 a different directory by prepending a relative or absolute path to the file
1428 name."
1429 vhdl-name-doc-string)
1430 :type '(cons (regexp :tag "From regexp")
1431 (string :tag "To string "))
1432 :group 'vhdl-testbench)
1435 (defgroup vhdl-comment nil
1436 "Customizations for comments."
1437 :group 'vhdl)
1439 (defcustom vhdl-self-insert-comments t
1440 "Non-nil means various templates automatically insert help comments."
1441 :type 'boolean
1442 :group 'vhdl-comment)
1444 (defcustom vhdl-prompt-for-comments t
1445 "Non-nil means various templates prompt for user definable comments."
1446 :type 'boolean
1447 :group 'vhdl-comment)
1449 (defcustom vhdl-inline-comment-column 40
1450 "Column to indent and align inline comments to.
1451 Overrides local option `comment-column'.
1453 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1454 \"Activate Options\"."
1455 :type 'integer
1456 :group 'vhdl-comment)
1458 (defcustom vhdl-end-comment-column 79
1459 "End of comment column.
1460 Comments that exceed this column number are wrapped.
1462 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1463 \"Activate Options\"."
1464 :type 'integer
1465 :group 'vhdl-comment)
1467 (defvar end-comment-column)
1470 (defgroup vhdl-align nil
1471 "Customizations for alignment."
1472 :group 'vhdl)
1474 (defcustom vhdl-auto-align t
1475 "Non-nil means align some templates automatically after generation."
1476 :type 'boolean
1477 :group 'vhdl-align)
1479 (defcustom vhdl-align-groups t
1480 "Non-nil means align groups of code lines separately.
1481 A group of code lines is a region of consecutive lines between two lines that
1482 match the regexp in option `vhdl-align-group-separate'."
1483 :type 'boolean
1484 :group 'vhdl-align)
1486 (defcustom vhdl-align-group-separate "^\\s-*$"
1487 "Regexp for matching a line that separates groups of lines for alignment.
1488 Examples:
1489 \"^\\s-*$\": matches an empty line
1490 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1491 :type 'regexp
1492 :group 'vhdl-align)
1494 (defcustom vhdl-align-same-indent t
1495 "Non-nil means align blocks with same indent separately.
1496 When a region or the entire buffer is aligned, the code is divided into
1497 blocks of same indent which are aligned separately (except for argument/port
1498 lists). This gives nicer alignment in most cases.
1499 Option `vhdl-align-groups' still applies within these blocks."
1500 :type 'boolean
1501 :group 'vhdl-align)
1504 (defgroup vhdl-highlight nil
1505 "Customizations for highlighting."
1506 :group 'vhdl)
1508 (defcustom vhdl-highlight-keywords t
1509 "Non-nil means highlight VHDL keywords and other standardized words.
1510 The following faces are used:
1511 `font-lock-keyword-face' : keywords
1512 `font-lock-type-face' : standardized types
1513 `vhdl-font-lock-attribute-face': standardized attributes
1514 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1515 `vhdl-font-lock-function-face' : standardized function and package names
1517 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1518 entry \"Fontify Buffer\")."
1519 :type 'boolean
1520 :set (lambda (variable value)
1521 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1522 :group 'vhdl-highlight)
1524 (defcustom vhdl-highlight-names t
1525 "Non-nil means highlight declaration names and construct labels.
1526 The following faces are used:
1527 `font-lock-function-name-face' : names in declarations of units,
1528 subprograms, components, as well as labels of VHDL constructs
1529 `font-lock-type-face' : names in type/nature declarations
1530 `vhdl-font-lock-attribute-face': names in attribute declarations
1531 `font-lock-variable-name-face' : names in declarations of signals,
1532 variables, constants, subprogram parameters, generics, and ports
1534 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1535 entry \"Fontify Buffer\")."
1536 :type 'boolean
1537 :set (lambda (variable value)
1538 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1539 :group 'vhdl-highlight)
1541 (defcustom vhdl-highlight-special-words nil
1542 "Non-nil means highlight words with special syntax.
1543 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1544 are highlighted accordingly.
1545 Can be used for visual support of naming conventions.
1547 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1548 entry \"Fontify Buffer\")."
1549 :type 'boolean
1550 :set (lambda (variable value)
1551 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1552 :group 'vhdl-highlight)
1554 (defcustom vhdl-highlight-forbidden-words nil
1555 "Non-nil means highlight forbidden words.
1556 The reserved words specified in option `vhdl-forbidden-words' or having the
1557 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1558 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1559 use them.
1561 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1562 entry \"Fontify Buffer\")."
1563 :type 'boolean
1564 :set (lambda (variable value)
1565 (vhdl-custom-set variable value
1566 'vhdl-words-init 'vhdl-font-lock-init))
1567 :group 'vhdl-highlight)
1569 (defcustom vhdl-highlight-verilog-keywords nil
1570 "Non-nil means highlight Verilog keywords as reserved words.
1571 Verilog keywords are highlighted in a warning color (face
1572 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1574 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1575 entry \"Fontify Buffer\")."
1576 :type 'boolean
1577 :set (lambda (variable value)
1578 (vhdl-custom-set variable value
1579 'vhdl-words-init 'vhdl-font-lock-init))
1580 :group 'vhdl-highlight)
1582 (defcustom vhdl-highlight-translate-off nil
1583 "Non-nil means background-highlight code excluded from translation.
1584 That is, all code between \"-- pragma translate_off\" and
1585 \"-- pragma translate_on\" is highlighted using a different background color
1586 \(face `vhdl-font-lock-translate-off-face').
1587 Note: this might slow down on-the-fly fontification (and thus editing).
1589 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1590 entry \"Fontify Buffer\")."
1591 :type 'boolean
1592 :set (lambda (variable value)
1593 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1594 :group 'vhdl-highlight)
1596 (defcustom vhdl-highlight-case-sensitive nil
1597 "Non-nil means consider case for highlighting.
1598 Possible trade-off:
1599 non-nil also upper-case VHDL words are highlighted, but case of words with
1600 special syntax is not considered
1601 nil only lower-case VHDL words are highlighted, but case of words with
1602 special syntax is considered
1603 Overrides local option `font-lock-keywords-case-fold-search'.
1605 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1606 entry \"Fontify Buffer\")."
1607 :type 'boolean
1608 :group 'vhdl-highlight)
1610 (defcustom vhdl-special-syntax-alist
1611 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
1612 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
1613 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
1614 "List of special syntax to be highlighted.
1615 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1616 syntax (as regular expression) are highlighted in the corresponding color.
1618 Name : string of words and spaces
1619 Regexp : regular expression describing word syntax
1620 (e.g. \"\\\\=\<\\\w+_c\\\\=\>\" matches word with suffix \"_c\")
1621 expression must start with \"\\\\=\<\" and end with \"\\\\=\>\"
1622 if only whole words should be matched (no substrings)
1623 Color (light): foreground color for light background
1624 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1625 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1626 Color (dark) : foreground color for dark background
1627 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1628 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1629 In comments : If non-nil, words are also highlighted inside comments
1631 Can be used for visual support of naming conventions, such as highlighting
1632 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1633 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1634 common substrings or name suffices.
1635 For each entry, a new face is generated with the specified colors and name
1636 \"vhdl-font-lock-\" + name + \"-face\".
1638 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1639 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1640 :type '(repeat (list :tag "Face" :indent 2
1641 (string :tag "Name ")
1642 (regexp :tag "Regexp " "\\w+_")
1643 (string :tag "Color (light)")
1644 (string :tag "Color (dark) ")
1645 (boolean :tag "In comments ")))
1646 :set (lambda (variable value)
1647 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1648 :group 'vhdl-highlight)
1650 (defcustom vhdl-forbidden-words '()
1651 "List of forbidden words to be highlighted.
1652 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1653 words are highlighted in a warning color to indicate not to use them.
1655 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1656 entry \"Fontify Buffer\")."
1657 :type '(repeat (string :format "%v"))
1658 :set (lambda (variable value)
1659 (vhdl-custom-set variable value
1660 'vhdl-words-init 'vhdl-font-lock-init))
1661 :group 'vhdl-highlight)
1663 (defcustom vhdl-forbidden-syntax ""
1664 "Syntax of forbidden words to be highlighted.
1665 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1666 syntax are highlighted in a warning color to indicate not to use them.
1667 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1668 highlights identifiers with 10 or more characters).
1670 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1671 entry \"Fontify Buffer\")."
1672 :type 'regexp
1673 :set (lambda (variable value)
1674 (vhdl-custom-set variable value
1675 'vhdl-words-init 'vhdl-font-lock-init))
1676 :group 'vhdl-highlight)
1678 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1679 "List of compiler directive keywords recognized for highlighting.
1681 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1682 entry \"Fontify Buffer\")."
1683 :type '(repeat (string :format "%v"))
1684 :set (lambda (variable value)
1685 (vhdl-custom-set variable value
1686 'vhdl-words-init 'vhdl-font-lock-init))
1687 :group 'vhdl-highlight)
1690 (defgroup vhdl-speedbar nil
1691 "Customizations for speedbar."
1692 :group 'vhdl)
1694 (defcustom vhdl-speedbar-auto-open nil
1695 "Non-nil means automatically open speedbar at startup.
1696 Alternatively, the speedbar can be opened from the VHDL menu."
1697 :type 'boolean
1698 :group 'vhdl-speedbar)
1700 (defcustom vhdl-speedbar-display-mode 'files
1701 "Specifies the default displaying mode when opening speedbar.
1702 Alternatively, the displaying mode can be selected from the speedbar menu or
1703 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1704 :type '(choice (const :tag "Files" files)
1705 (const :tag "Directory hierarchy" directory)
1706 (const :tag "Project hierarchy" project))
1707 :group 'vhdl-speedbar)
1709 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1710 "Limits scanning of large files and netlists.
1711 Design units: maximum file size to scan for design units
1712 Hierarchy (instances of subcomponents):
1713 File size: maximum file size to scan for instances (in bytes)
1714 Instances per arch: maximum number of instances to scan per architecture
1716 \"None\" always means that there is no limit.
1717 In case of files not or incompletely scanned, a warning message and the file
1718 names are printed out.
1719 Background: scanning for instances is considerably slower than scanning for
1720 design units, especially when there are many instances. These limits should
1721 prevent the scanning of large netlists."
1722 :type '(list (choice :tag "Design units"
1723 :format "%t : %[Value Menu%] %v"
1724 (const :tag "None" nil)
1725 (integer :tag "File size"))
1726 (list :tag "Hierarchy" :indent 2
1727 (choice :tag "File size"
1728 :format "%t : %[Value Menu%] %v"
1729 (const :tag "None" nil)
1730 (integer :tag "Size "))
1731 (choice :tag "Instances per arch"
1732 (const :tag "None" nil)
1733 (integer :tag "Number "))))
1734 :group 'vhdl-speedbar)
1736 (defcustom vhdl-speedbar-jump-to-unit t
1737 "Non-nil means jump to the design unit code when opened in a buffer.
1738 The buffer cursor position is left unchanged otherwise."
1739 :type 'boolean
1740 :group 'vhdl-speedbar)
1742 (defcustom vhdl-speedbar-update-on-saving t
1743 "Automatically update design hierarchy when buffer is saved."
1744 :type 'boolean
1745 :group 'vhdl-speedbar)
1747 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1748 "Automatically save modified hierarchy caches when exiting Emacs.
1749 Hierarchy: design hierarchy information
1750 Display: displaying information (which design units to expand)"
1751 :type '(set (const :tag "Hierarchy" hierarchy)
1752 (const :tag "Display" display))
1753 :group 'vhdl-speedbar)
1755 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1756 "Name of file for saving hierarchy cache.
1757 \"\\1\" is replaced by the project name if a project is specified,
1758 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1759 different users to have cache files in the same directory). Can also have
1760 an absolute path (i.e. all caches can be stored in one global directory)."
1761 :type 'string
1762 :group 'vhdl-speedbar)
1765 (defgroup vhdl-menu nil
1766 "Customizations for menus."
1767 :group 'vhdl)
1769 (defcustom vhdl-index-menu nil
1770 "Non-nil means add an index menu for a source file when loading.
1771 Alternatively, the speedbar can be used. Note that the index menu scans a file
1772 when it is opened, while speedbar only scans the file upon request."
1773 :type 'boolean
1774 :group 'vhdl-menu)
1776 (defcustom vhdl-source-file-menu nil
1777 "Non-nil means add a menu of all source files in current directory.
1778 Alternatively, the speedbar can be used."
1779 :type 'boolean
1780 :group 'vhdl-menu)
1782 (defcustom vhdl-hideshow-menu nil
1783 "Non-nil means add hideshow menu and functionality at startup.
1784 Hideshow can also be enabled from the VHDL Mode menu.
1785 Hideshow allows hiding code of various VHDL constructs.
1787 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1788 \"Activate Options\"."
1789 :type 'boolean
1790 :group 'vhdl-menu)
1792 (defcustom vhdl-hide-all-init nil
1793 "Non-nil means hide all design units initially after a file is loaded."
1794 :type 'boolean
1795 :group 'vhdl-menu)
1798 (defgroup vhdl-print nil
1799 "Customizations for printing."
1800 :group 'vhdl)
1802 (defcustom vhdl-print-two-column t
1803 "Non-nil means print code in two columns and landscape format.
1804 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1805 prints VHDL files in a nice two-column landscape style.
1807 NOTE: Activate the new setting by restarting Emacs.
1808 Overrides `ps-print' settings locally."
1809 :type 'boolean
1810 :group 'vhdl-print)
1812 (defcustom vhdl-print-customize-faces t
1813 "Non-nil means use an optimized set of faces for PostScript printing.
1815 NOTE: Activate the new setting by restarting Emacs.
1816 Overrides `ps-print' settings locally."
1817 :type 'boolean
1818 :group 'vhdl-print)
1821 (defgroup vhdl-misc nil
1822 "Miscellaneous customizations."
1823 :group 'vhdl)
1825 (defcustom vhdl-intelligent-tab t
1826 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1827 That is, if preceding character is part of a word then complete word,
1828 else if not at beginning of line then insert tab,
1829 else if last command was a `TAB' or `RET' then dedent one step,
1830 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1831 If nil, TAB always indents current line (i.e. `TAB' is bound to
1832 `indent-according-to-mode').
1834 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1835 \"Activate Options\"."
1836 :type 'boolean
1837 :group 'vhdl-misc)
1839 (defcustom vhdl-indent-syntax-based t
1840 "Non-nil means indent lines of code based on their syntactic context.
1841 Otherwise, a line is indented like the previous nonblank line. This can be
1842 useful in large files where syntax-based indentation gets very slow."
1843 :type 'boolean
1844 :group 'vhdl-misc)
1846 (defcustom vhdl-indent-comment-like-next-code-line t
1847 "*Non-nil means comment lines are indented like the following code line.
1848 Otherwise, comment lines are indented like the preceding code line.
1849 Indenting comment lines like the following code line gives nicer indentation
1850 when comments precede the code that they refer to."
1851 :type 'boolean
1852 :group 'vhdl-misc)
1854 (defcustom vhdl-word-completion-case-sensitive nil
1855 "Non-nil means word completion using `TAB' is case sensitive.
1856 That is, `TAB' completes words that start with the same letters and case.
1857 Otherwise, case is ignored."
1858 :type 'boolean
1859 :group 'vhdl-misc)
1861 (defcustom vhdl-word-completion-in-minibuffer t
1862 "Non-nil enables word completion in minibuffer (for template prompts).
1864 NOTE: Activate the new setting by restarting Emacs."
1865 :type 'boolean
1866 :group 'vhdl-misc)
1868 (defcustom vhdl-underscore-is-part-of-word nil
1869 "Non-nil means consider the underscore character `_' as part of word.
1870 An identifier containing underscores is then treated as a single word in
1871 select and move operations. All parts of an identifier separated by underscore
1872 are treated as single words otherwise.
1874 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1875 \"Activate Options\"."
1876 :type 'boolean
1877 :set (lambda (variable value)
1878 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1879 :group 'vhdl-misc)
1882 (defgroup vhdl-related nil
1883 "Related general customizations."
1884 :group 'vhdl)
1886 ;; add related general customizations
1887 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1888 (if (featurep 'xemacs)
1889 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1890 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1891 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1892 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1893 (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
1894 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1895 (unless (featurep 'xemacs)
1896 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1897 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1898 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1899 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1901 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1902 ;; Hidden user variables
1904 (defvar vhdl-compile-absolute-path nil
1905 "If non-nil, use absolute instead of relative path for compiled files.")
1907 (defvar vhdl-comment-display-line-char ?-
1908 "Character to use in comment display line.")
1910 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1911 ;; Internal variables
1913 (defvar vhdl-menu-max-size 20
1914 "Specifies the maximum size of a menu before splitting it into submenus.")
1916 (defvar vhdl-progress-interval 1
1917 "Interval used to update progress status during long operations.
1918 If a number, percentage complete gets updated after each interval of
1919 that many seconds. To inhibit all messages, set this option to nil.")
1921 (defvar vhdl-inhibit-startup-warnings-p nil
1922 "If non-nil, inhibits start up compatibility warnings.")
1924 (defvar vhdl-strict-syntax-p nil
1925 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1926 If the syntactic symbol for a particular line does not match a symbol
1927 in the offsets alist, an error is generated, otherwise no error is
1928 reported and the syntactic symbol is ignored.")
1930 (defvar vhdl-echo-syntactic-information-p nil
1931 "If non-nil, syntactic info is echoed when the line is indented.")
1933 (defconst vhdl-offsets-alist-default
1934 '((string . -1000)
1935 (cpp-macro . -1000)
1936 (block-open . 0)
1937 (block-close . 0)
1938 (statement . 0)
1939 (statement-cont . vhdl-lineup-statement-cont)
1940 (statement-block-intro . +)
1941 (statement-case-intro . +)
1942 (case-alternative . +)
1943 (comment . vhdl-lineup-comment)
1944 (arglist-intro . +)
1945 (arglist-cont . 0)
1946 (arglist-cont-nonempty . vhdl-lineup-arglist)
1947 (arglist-close . vhdl-lineup-arglist)
1948 (entity . 0)
1949 (configuration . 0)
1950 (package . 0)
1951 (architecture . 0)
1952 (package-body . 0)
1954 "Default settings for offsets of syntactic elements.
1955 Do not change this constant! See the variable `vhdl-offsets-alist' for
1956 more information.")
1958 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1959 "Association list of syntactic element symbols and indentation offsets.
1960 As described below, each cons cell in this list has the form:
1962 (SYNTACTIC-SYMBOL . OFFSET)
1964 When a line is indented, `vhdl-mode' first determines the syntactic
1965 context of the line by generating a list of symbols called syntactic
1966 elements. This list can contain more than one syntactic element and
1967 the global variable `vhdl-syntactic-context' contains the context list
1968 for the line being indented. Each element in this list is actually a
1969 cons cell of the syntactic symbol and a buffer position. This buffer
1970 position is call the relative indent point for the line. Some
1971 syntactic symbols may not have a relative indent point associated with
1972 them.
1974 After the syntactic context list for a line is generated, `vhdl-mode'
1975 calculates the absolute indentation for the line by looking at each
1976 syntactic element in the list. First, it compares the syntactic
1977 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1978 finds a match, it adds the OFFSET to the column of the relative indent
1979 point. The sum of this calculation for each element in the syntactic
1980 list is the absolute offset for line being indented.
1982 If the syntactic element does not match any in the `vhdl-offsets-alist',
1983 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1984 the element is ignored.
1986 Actually, OFFSET can be an integer, a function, a variable, or one of
1987 the following symbols: `+', `-', `++', or `--'. These latter
1988 designate positive or negative multiples of `vhdl-basic-offset',
1989 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1990 called with a single argument containing the cons of the syntactic
1991 element symbol and the relative indent point. The function should
1992 return an integer offset.
1994 Here is the current list of valid syntactic element symbols:
1996 string -- inside multi-line string
1997 block-open -- statement block open
1998 block-close -- statement block close
1999 statement -- a VHDL statement
2000 statement-cont -- a continuation of a VHDL statement
2001 statement-block-intro -- the first line in a new statement block
2002 statement-case-intro -- the first line in a case alternative block
2003 case-alternative -- a case statement alternative clause
2004 comment -- a line containing only a comment
2005 arglist-intro -- the first line in an argument list
2006 arglist-cont -- subsequent argument list lines when no
2007 arguments follow on the same line as
2008 the arglist opening paren
2009 arglist-cont-nonempty -- subsequent argument list lines when at
2010 least one argument follows on the same
2011 line as the arglist opening paren
2012 arglist-close -- the solo close paren of an argument list
2013 entity -- inside an entity declaration
2014 configuration -- inside a configuration declaration
2015 package -- inside a package declaration
2016 architecture -- inside an architecture body
2017 package-body -- inside a package body")
2019 (defvar vhdl-comment-only-line-offset 0
2020 "Extra offset for line which contains only the start of a comment.
2021 Can contain an integer or a cons cell of the form:
2023 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2025 Where NON-ANCHORED-OFFSET is the amount of offset given to
2026 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2027 the amount of offset to give column-zero anchored comment-only lines.
2028 Just an integer as value is equivalent to (<val> . 0)")
2030 (defvar vhdl-special-indent-hook nil
2031 "Hook for user defined special indentation adjustments.
2032 This hook gets called after a line is indented by the mode.")
2034 (defvar vhdl-style-alist
2035 '(("IEEE"
2036 (vhdl-basic-offset . 4)
2037 (vhdl-offsets-alist . ())))
2038 "Styles of Indentation.
2039 Elements of this alist are of the form:
2041 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2043 where STYLE-STRING is a short descriptive string used to select a
2044 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2045 value for that variable when using the selected style.
2047 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2048 case, the VALUE is a list containing elements of the form:
2050 (SYNTACTIC-SYMBOL . VALUE)
2052 as described in `vhdl-offsets-alist'. These are passed directly to
2053 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2054 your style, only those that are different from the default.")
2056 ;; dynamically append the default value of most variables
2057 (or (assoc "Default" vhdl-style-alist)
2058 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2059 vhdl-strict-syntax-p
2060 vhdl-echo-syntactic-information-p
2061 vhdl-basic-offset
2062 vhdl-offsets-alist
2063 vhdl-comment-only-line-offset))
2064 (default (cons "Default"
2065 (mapcar
2066 (function
2067 (lambda (var)
2068 (cons var (symbol-value var))))
2069 varlist))))
2070 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2072 (defvar vhdl-mode-hook nil
2073 "Hook called by `vhdl-mode'.")
2076 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2077 ;;; Required packages
2078 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2080 ;; mandatory
2081 (require 'assoc)
2082 (require 'compile) ; XEmacs
2083 (require 'easymenu)
2084 (require 'hippie-exp)
2086 ;; optional (minimize warning messages during compile)
2087 (eval-when-compile
2088 (require 'font-lock)
2089 (require 'ps-print)
2090 (require 'speedbar))
2093 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2094 ;;; Compatibility
2095 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2097 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2098 ;; XEmacs compatibility
2100 ;; active regions
2101 (defun vhdl-keep-region-active ()
2102 "Do whatever is necessary to keep the region active in XEmacs.
2103 Ignore byte-compiler warnings you might see."
2104 (and (featurep 'xemacs)
2105 (setq zmacs-region-stays t)))
2107 ;; `wildcard-to-regexp' is included only in XEmacs 21
2108 (unless (fboundp 'wildcard-to-regexp)
2109 (defun wildcard-to-regexp (wildcard)
2110 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2111 (let* ((i (string-match "[*?]" wildcard))
2112 (result (substring wildcard 0 i))
2113 (len (length wildcard)))
2114 (when i
2115 (while (< i len)
2116 (let ((ch (aref wildcard i)))
2117 (setq result (concat result
2118 (cond ((eq ch ?*) "[^\000]*")
2119 ((eq ch ??) "[^\000]")
2120 (t (char-to-string ch)))))
2121 (setq i (1+ i)))))
2122 (concat "\\`" result "\\'"))))
2124 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2125 ;; `regexp-opt' accelerates fontification by 10-20%
2126 (unless (fboundp 'regexp-opt)
2127 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2128 (defun regexp-opt (strings &optional paren)
2129 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2130 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2132 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2133 (unless (fboundp 'match-string-no-properties)
2134 (defalias 'match-string-no-properties 'match-string))
2136 ;; `subst-char-in-string' undefined (XEmacs)
2137 (unless (fboundp 'subst-char-in-string)
2138 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2139 (let ((i (length string))
2140 (newstr (if inplace string (copy-sequence string))))
2141 (while (> i 0)
2142 (setq i (1- i))
2143 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2144 newstr)))
2146 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2147 (when (and (featurep 'xemacs) (string< itimer-version "1.09")
2148 (not noninteractive))
2149 (load "itimer")
2150 (when (string< itimer-version "1.09")
2151 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2152 (beep) (sit-for 5)))
2154 ;; `file-expand-wildcards' undefined (XEmacs)
2155 (unless (fboundp 'file-expand-wildcards)
2156 (defun file-expand-wildcards (pattern &optional full)
2157 "Taken from Emacs's `files.el'."
2158 (let* ((nondir (file-name-nondirectory pattern))
2159 (dirpart (file-name-directory pattern))
2160 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2161 (mapcar 'file-name-as-directory
2162 (file-expand-wildcards (directory-file-name dirpart)))
2163 (list dirpart)))
2164 contents)
2165 (while dirs
2166 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2167 (file-directory-p (directory-file-name (car dirs))))
2168 (let ((this-dir-contents
2169 (delq nil
2170 (mapcar #'(lambda (name)
2171 (unless (string-match "\\`\\.\\.?\\'"
2172 (file-name-nondirectory name))
2173 name))
2174 (directory-files (or (car dirs) ".") full
2175 (wildcard-to-regexp nondir))))))
2176 (setq contents
2177 (nconc
2178 (if (and (car dirs) (not full))
2179 (mapcar (function (lambda (name) (concat (car dirs) name)))
2180 this-dir-contents)
2181 this-dir-contents)
2182 contents))))
2183 (setq dirs (cdr dirs)))
2184 contents)))
2186 ;; `member-ignore-case' undefined (XEmacs)
2187 (unless (fboundp 'member-ignore-case)
2188 (defalias 'member-ignore-case 'member))
2190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2191 ;; Compatibility with older VHDL Mode versions
2193 (defvar vhdl-warnings nil
2194 "Warnings to tell the user during start up.")
2196 (defun vhdl-run-when-idle (secs repeat function)
2197 "Wait until idle, then run FUNCTION."
2198 (if (fboundp 'start-itimer)
2199 (start-itimer "vhdl-mode" function secs repeat t)
2200 ; (run-with-idle-timer secs repeat function)))
2201 ;; explicitly activate timer (necessary when Emacs is already idle)
2202 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2204 (defun vhdl-warning-when-idle (&rest args)
2205 "Wait until idle, then print out warning STRING and beep."
2206 (if noninteractive
2207 (vhdl-warning (apply 'format args) t)
2208 (unless vhdl-warnings
2209 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2210 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2212 (defun vhdl-warning (string &optional nobeep)
2213 "Print out warning STRING and beep."
2214 (message "WARNING: %s" string)
2215 (unless (or nobeep noninteractive) (beep)))
2217 (defun vhdl-print-warnings ()
2218 "Print out messages in variable `vhdl-warnings'."
2219 (let ((no-warnings (length vhdl-warnings)))
2220 (setq vhdl-warnings (nreverse vhdl-warnings))
2221 (while vhdl-warnings
2222 (message "WARNING: %s" (car vhdl-warnings))
2223 (setq vhdl-warnings (cdr vhdl-warnings)))
2224 (beep)
2225 (when (> no-warnings 1)
2226 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2228 ;; Backward compatibility checks and fixes
2229 ;; option `vhdl-compiler' changed format
2230 (unless (stringp vhdl-compiler)
2231 (setq vhdl-compiler "ModelSim")
2232 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2234 ;; option `vhdl-standard' changed format
2235 (unless (listp vhdl-standard)
2236 (setq vhdl-standard '(87 nil))
2237 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2239 ;; option `vhdl-model-alist' changed format
2240 (when (= (length (car vhdl-model-alist)) 3)
2241 (let ((old-alist vhdl-model-alist)
2242 new-alist)
2243 (while old-alist
2244 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2245 (setq old-alist (cdr old-alist)))
2246 (setq vhdl-model-alist (nreverse new-alist)))
2247 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2249 ;; option `vhdl-project-alist' changed format
2250 (when (= (length (car vhdl-project-alist)) 3)
2251 (let ((old-alist vhdl-project-alist)
2252 new-alist)
2253 (while old-alist
2254 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2255 (setq old-alist (cdr old-alist)))
2256 (setq vhdl-project-alist (nreverse new-alist)))
2257 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2259 ;; option `vhdl-project-alist' changed format (3.31.1)
2260 (when (= (length (car vhdl-project-alist)) 4)
2261 (let ((old-alist vhdl-project-alist)
2262 new-alist elem)
2263 (while old-alist
2264 (setq elem (car old-alist))
2265 (setq new-alist
2266 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2267 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2268 new-alist))
2269 (setq old-alist (cdr old-alist)))
2270 (setq vhdl-project-alist (nreverse new-alist)))
2271 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2273 ;; option `vhdl-project-alist' changed format (3.31.12)
2274 (when (= (length (car vhdl-project-alist)) 10)
2275 (let ((tmp-alist vhdl-project-alist))
2276 (while tmp-alist
2277 (setcdr (nthcdr 3 (car tmp-alist))
2278 (cons "" (nthcdr 4 (car tmp-alist))))
2279 (setq tmp-alist (cdr tmp-alist))))
2280 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2282 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2283 (when (= (length (car vhdl-compiler-alist)) 7)
2284 (let ((old-alist vhdl-compiler-alist)
2285 new-alist elem)
2286 (while old-alist
2287 (setq elem (car old-alist))
2288 (setq new-alist
2289 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2290 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2291 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2292 (nth 5 elem) (nth 6 elem) nil)
2293 new-alist))
2294 (setq old-alist (cdr old-alist)))
2295 (setq vhdl-compiler-alist (nreverse new-alist)))
2296 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2298 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2299 (when (= (length (car vhdl-compiler-alist)) 12)
2300 (let ((tmp-alist vhdl-compiler-alist))
2301 (while tmp-alist
2302 (setcdr (nthcdr 4 (car tmp-alist))
2303 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2304 (setq tmp-alist (cdr tmp-alist))))
2305 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2307 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2308 (when (= (length (car vhdl-compiler-alist)) 13)
2309 (let ((tmp-alist vhdl-compiler-alist))
2310 (while tmp-alist
2311 (setcdr (nthcdr 3 (car tmp-alist))
2312 (cons "" (nthcdr 4 (car tmp-alist))))
2313 (setq tmp-alist (cdr tmp-alist))))
2314 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2316 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2317 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2318 (let ((tmp-alist vhdl-compiler-alist))
2319 (while tmp-alist
2320 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2321 '(0 . nil))
2322 (setq tmp-alist (cdr tmp-alist))))
2323 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2325 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2326 (when (equal vhdl-project "")
2327 (setq vhdl-project nil)
2328 (customize-save-variable 'vhdl-project vhdl-project))
2330 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2331 (when (stringp vhdl-project-file-name)
2332 (setq vhdl-project-file-name (list vhdl-project-file-name))
2333 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2335 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2336 (if (not (boundp 'speedbar-indentation-width))
2337 (defvar speedbar-indentation-width 2)
2338 ;; set default to 2 if not already customized
2339 (unless (get 'speedbar-indentation-width 'saved-value)
2340 (setq speedbar-indentation-width 2)))
2343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2344 ;;; Help functions / inline substitutions / macros
2345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2347 (defun vhdl-standard-p (standard)
2348 "Check if STANDARD is specified as used standard."
2349 (or (eq standard (car vhdl-standard))
2350 (memq standard (cadr vhdl-standard))))
2352 (defun vhdl-project-p (&optional warning)
2353 "Return non-nil if a project is displayed, i.e. directories or files are
2354 specified."
2355 (if (assoc vhdl-project vhdl-project-alist)
2356 vhdl-project
2357 (when (and vhdl-project warning)
2358 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2359 nil))
2361 (defun vhdl-resolve-env-variable (string)
2362 "Resolve environment variables in STRING."
2363 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2364 (setq string (concat (match-string 1 string)
2365 (getenv (match-string 2 string))
2366 (match-string 4 string))))
2367 string)
2369 (defun vhdl-default-directory ()
2370 "Return the default directory of the current project or the directory of the
2371 current buffer if no project is defined."
2372 (if (vhdl-project-p)
2373 (expand-file-name (vhdl-resolve-env-variable
2374 (nth 1 (aget vhdl-project-alist vhdl-project))))
2375 default-directory))
2377 (defmacro vhdl-prepare-search-1 (&rest body)
2378 "Enable case insensitive search and switch to syntax table that includes '_',
2379 then execute BODY, and finally restore the old environment. Used for
2380 consistent searching."
2381 `(let ((case-fold-search t)) ; case insensitive search
2382 ;; use extended syntax table
2383 (with-syntax-table vhdl-mode-ext-syntax-table
2384 ,@body)))
2386 (defmacro vhdl-prepare-search-2 (&rest body)
2387 "Enable case insensitive search, switch to syntax table that includes '_',
2388 and remove `intangible' overlays, then execute BODY, and finally restore the
2389 old environment. Used for consistent searching."
2390 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2391 `(let ((case-fold-search t) ; case insensitive search
2392 (current-syntax-table (syntax-table))
2393 overlay-all-list overlay-intangible-list overlay)
2394 ;; use extended syntax table
2395 (set-syntax-table vhdl-mode-ext-syntax-table)
2396 ;; remove `intangible' overlays
2397 (when (fboundp 'overlay-lists)
2398 (setq overlay-all-list (overlay-lists))
2399 (setq overlay-all-list
2400 (append (car overlay-all-list) (cdr overlay-all-list)))
2401 (while overlay-all-list
2402 (setq overlay (car overlay-all-list))
2403 (when (memq 'intangible (overlay-properties overlay))
2404 (setq overlay-intangible-list
2405 (cons overlay overlay-intangible-list))
2406 (overlay-put overlay 'intangible nil))
2407 (setq overlay-all-list (cdr overlay-all-list))))
2408 ;; execute BODY safely
2409 (unwind-protect
2410 (progn ,@body)
2411 ;; restore syntax table
2412 (set-syntax-table current-syntax-table)
2413 ;; restore `intangible' overlays
2414 (when (fboundp 'overlay-lists)
2415 (while overlay-intangible-list
2416 (overlay-put (car overlay-intangible-list) 'intangible t)
2417 (setq overlay-intangible-list
2418 (cdr overlay-intangible-list)))))))
2420 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2421 "Visit file FILE-NAME and execute BODY."
2422 `(if (null ,file-name)
2423 (progn ,@body)
2424 (unless (file-directory-p ,file-name)
2425 (let ((source-buffer (current-buffer))
2426 (visiting-buffer (find-buffer-visiting ,file-name))
2427 file-opened)
2428 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2429 (condition-case ()
2430 (progn (set-buffer (create-file-buffer ,file-name))
2431 (setq file-opened t)
2432 (vhdl-insert-file-contents ,file-name)
2433 (modify-syntax-entry ?\- ". 12" (syntax-table))
2434 (modify-syntax-entry ?\n ">" (syntax-table))
2435 (modify-syntax-entry ?\^M ">" (syntax-table))
2436 (modify-syntax-entry ?_ "w" (syntax-table))
2438 (error
2439 (if ,issue-error
2440 (progn
2441 (when file-opened (kill-buffer (current-buffer)))
2442 (set-buffer source-buffer)
2443 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2444 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2445 nil))))
2446 (condition-case info
2447 (progn ,@body)
2448 (error
2449 (if ,issue-error
2450 (progn
2451 (when file-opened (kill-buffer (current-buffer)))
2452 (set-buffer source-buffer)
2453 (error (cadr info)))
2454 (vhdl-warning (cadr info))))))
2455 (when file-opened (kill-buffer (current-buffer)))
2456 (set-buffer source-buffer)))))
2458 (defun vhdl-insert-file-contents (filename)
2459 "Nicked from `insert-file-contents-literally', but allow coding system
2460 conversion."
2461 (let ((format-alist nil)
2462 (after-insert-file-functions nil)
2463 (jka-compr-compression-info-list nil))
2464 (insert-file-contents filename t)))
2466 (defun vhdl-sort-alist (alist)
2467 "Sort ALIST."
2468 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2470 (defun vhdl-get-subdirs (directory)
2471 "Recursively get subdirectories of DIRECTORY."
2472 (let ((dir-list (list (file-name-as-directory directory)))
2473 file-list)
2474 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2475 (while file-list
2476 (when (file-directory-p (car file-list))
2477 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2478 (setq file-list (cdr file-list)))
2479 dir-list))
2481 (defun vhdl-aput (alist-symbol key &optional value)
2482 "As `aput', but delete key-value pair if VALUE is nil."
2483 (if value
2484 (aput alist-symbol key value)
2485 (adelete alist-symbol key)))
2487 (defun vhdl-delete (elt list)
2488 "Delete by side effect the first occurrence of ELT as a member of LIST."
2489 (setq list (cons nil list))
2490 (let ((list1 list))
2491 (while (and (cdr list1) (not (equal elt (cadr list1))))
2492 (setq list1 (cdr list1)))
2493 (when list
2494 (setcdr list1 (cddr list1))))
2495 (cdr list))
2497 (defun vhdl-speedbar-refresh (&optional key)
2498 "Refresh directory or project with name KEY."
2499 (when (and (boundp 'speedbar-frame)
2500 (frame-live-p speedbar-frame))
2501 (let ((pos (point))
2502 (last-frame (selected-frame)))
2503 (if (null key)
2504 (speedbar-refresh)
2505 (select-frame speedbar-frame)
2506 (when (save-excursion
2507 (goto-char (point-min))
2508 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2509 (goto-char (match-end 1))
2510 (speedbar-do-function-pointer)
2511 (backward-char 2)
2512 (speedbar-do-function-pointer)
2513 (message "Refreshing speedbar...done"))
2514 (select-frame last-frame)))))
2516 (defun vhdl-show-messages ()
2517 "Get *Messages* buffer to show recent messages."
2518 (interactive)
2519 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
2521 (defun vhdl-use-direct-instantiation ()
2522 "Return whether direct instantiation is used."
2523 (or (eq vhdl-use-direct-instantiation 'always)
2524 (and (eq vhdl-use-direct-instantiation 'standard)
2525 (not (vhdl-standard-p '87)))))
2527 (defun vhdl-max-marker (marker1 marker2)
2528 "Return larger marker."
2529 (if (> marker1 marker2) marker1 marker2))
2531 (defun vhdl-goto-marker (marker)
2532 "Goto marker in appropriate buffer."
2533 (when (markerp marker)
2534 (set-buffer (marker-buffer marker)))
2535 (goto-char marker))
2537 (defun vhdl-menu-split (list title)
2538 "Split menu LIST into several submenus, if number of
2539 elements > `vhdl-menu-max-size'."
2540 (if (> (length list) vhdl-menu-max-size)
2541 (let ((remain list)
2542 (result '())
2543 (sublist '())
2544 (menuno 1)
2545 (i 0))
2546 (while remain
2547 (setq sublist (cons (car remain) sublist))
2548 (setq remain (cdr remain))
2549 (setq i (+ i 1))
2550 (if (= i vhdl-menu-max-size)
2551 (progn
2552 (setq result (cons (cons (format "%s %s" title menuno)
2553 (nreverse sublist)) result))
2554 (setq i 0)
2555 (setq menuno (+ menuno 1))
2556 (setq sublist '()))))
2557 (and sublist
2558 (setq result (cons (cons (format "%s %s" title menuno)
2559 (nreverse sublist)) result)))
2560 (nreverse result))
2561 list))
2564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2565 ;;; Bindings
2566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2569 ;; Key bindings
2571 (defvar vhdl-template-map nil
2572 "Keymap for VHDL templates.")
2574 (defun vhdl-template-map-init ()
2575 "Initialize `vhdl-template-map'."
2576 (setq vhdl-template-map (make-sparse-keymap))
2577 ;; key bindings for VHDL templates
2578 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2579 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2580 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2581 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2582 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2583 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2584 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2585 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2586 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2587 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2588 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2589 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2590 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2591 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2592 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2593 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2594 (define-key vhdl-template-map "el" 'vhdl-template-else)
2595 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2596 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2597 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2598 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2599 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2600 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2601 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2602 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2603 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2604 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2605 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2606 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2607 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2608 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2609 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2610 (define-key vhdl-template-map "li" 'vhdl-template-library)
2611 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2612 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2613 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2614 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2615 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2616 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2617 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2618 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2619 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2620 (define-key vhdl-template-map "po" 'vhdl-template-port)
2621 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2622 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2623 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2624 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2625 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2626 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2627 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2628 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2629 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2630 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2631 (define-key vhdl-template-map "us" 'vhdl-template-use)
2632 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2633 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2634 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2635 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2636 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2637 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2638 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2639 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2640 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2641 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2642 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2643 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2644 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2645 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2646 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2647 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2648 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2649 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2650 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2651 (when (vhdl-standard-p 'ams)
2652 (define-key vhdl-template-map "br" 'vhdl-template-break)
2653 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2654 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2655 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2656 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2657 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2658 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2659 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2660 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2661 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2662 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2664 (when (vhdl-standard-p 'math)
2665 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2666 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2669 ;; initialize template map for VHDL Mode
2670 (vhdl-template-map-init)
2672 (defun vhdl-function-name (prefix string &optional postfix)
2673 "Generate a Lisp function name.
2674 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2675 STRING are replaced by `-' and substrings are converted to lower case."
2676 (let ((name prefix))
2677 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2678 (setq name
2679 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2680 (setq string (substring string (match-beginning 2))))
2681 (when postfix (setq name (concat name "-" postfix)))
2682 (intern name)))
2684 (defvar vhdl-model-map nil
2685 "Keymap for VHDL models.")
2687 (defun vhdl-model-map-init ()
2688 "Initialize `vhdl-model-map'."
2689 (setq vhdl-model-map (make-sparse-keymap))
2690 ;; key bindings for VHDL models
2691 (let ((model-alist vhdl-model-alist) model)
2692 (while model-alist
2693 (setq model (car model-alist))
2694 (define-key vhdl-model-map (nth 2 model)
2695 (vhdl-function-name "vhdl-model" (nth 0 model)))
2696 (setq model-alist (cdr model-alist)))))
2698 ;; initialize user model map for VHDL Mode
2699 (vhdl-model-map-init)
2701 (defvar vhdl-mode-map nil
2702 "Keymap for VHDL Mode.")
2704 (defun vhdl-mode-map-init ()
2705 "Initialize `vhdl-mode-map'."
2706 (setq vhdl-mode-map (make-sparse-keymap))
2707 ;; template key bindings
2708 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2709 ;; model key bindings
2710 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2711 ;; standard key bindings
2712 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2713 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2714 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2715 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2716 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2717 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2718 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2719 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
2720 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2721 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2722 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2723 ;; backspace/delete key bindings
2724 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2725 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2726 (define-key vhdl-mode-map [delete] 'delete-char)
2727 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2728 ;; mode specific key bindings
2729 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2730 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2731 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2732 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2733 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2734 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2735 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2736 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2737 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2738 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2739 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2740 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2741 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2742 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2743 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2744 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2745 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2746 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
2747 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2748 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2749 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2750 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2751 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2752 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2753 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2754 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2755 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2756 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2757 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2758 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2759 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2760 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2761 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2762 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2763 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2764 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
2765 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2766 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2767 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2768 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2769 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2770 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2771 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2772 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2773 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2774 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2775 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2776 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2777 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2778 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2779 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2780 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2781 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2782 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2783 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2784 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2785 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2786 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2787 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2788 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2789 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2790 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2791 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2792 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2793 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2794 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2795 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2796 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2797 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2798 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2799 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2800 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2801 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2802 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2803 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2804 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
2805 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2806 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2807 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2808 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2809 ;; insert commands bindings
2810 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2811 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2812 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2813 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2814 ;; electric key bindings
2815 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2816 (when vhdl-intelligent-tab
2817 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2818 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2819 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2820 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2821 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2822 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2823 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2824 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2825 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2826 (when (vhdl-standard-p 'ams)
2827 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2829 ;; initialize mode map for VHDL Mode
2830 (vhdl-mode-map-init)
2832 ;; define special minibuffer keymap for enabling word completion in minibuffer
2833 ;; (useful in template generator prompts)
2834 (defvar vhdl-minibuffer-local-map
2835 (let ((map (make-sparse-keymap)))
2836 (set-keymap-parent map minibuffer-local-map)
2837 (when vhdl-word-completion-in-minibuffer
2838 (define-key map "\t" 'vhdl-minibuffer-tab))
2839 map)
2840 "Keymap for minibuffer used in VHDL Mode.")
2842 ;; set up electric character functions to work with
2843 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2844 (mapc
2845 (function
2846 (lambda (sym)
2847 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2848 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2849 '(vhdl-electric-space
2850 vhdl-electric-tab
2851 vhdl-electric-return
2852 vhdl-electric-dash
2853 vhdl-electric-open-bracket
2854 vhdl-electric-close-bracket
2855 vhdl-electric-quote
2856 vhdl-electric-semicolon
2857 vhdl-electric-comma
2858 vhdl-electric-period
2859 vhdl-electric-equal))
2861 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2862 ;; Syntax table
2864 (defvar vhdl-mode-syntax-table nil
2865 "Syntax table used in `vhdl-mode' buffers.")
2867 (defvar vhdl-mode-ext-syntax-table nil
2868 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2870 (defun vhdl-mode-syntax-table-init ()
2871 "Initialize `vhdl-mode-syntax-table'."
2872 (setq vhdl-mode-syntax-table (make-syntax-table))
2873 ;; define punctuation
2874 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2875 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2876 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2877 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2878 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2879 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2880 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2881 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2882 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2883 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2884 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2885 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2886 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2887 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2888 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2889 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2890 ;; define string
2891 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2892 ;; define underscore
2893 (when vhdl-underscore-is-part-of-word
2894 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2895 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2896 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2897 ;; and \n and \^M end a comment
2898 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2899 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2900 ;; define parentheses to match
2901 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2902 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2903 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2904 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2905 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2906 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2907 ;; extended syntax table including '_' (for simpler search regexps)
2908 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2909 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2911 ;; initialize syntax table for VHDL Mode
2912 (vhdl-mode-syntax-table-init)
2914 (defvar vhdl-syntactic-context nil
2915 "Buffer local variable containing syntactic analysis list.")
2916 (make-variable-buffer-local 'vhdl-syntactic-context)
2918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2919 ;; Abbrev ook bindings
2921 (defvar vhdl-mode-abbrev-table nil
2922 "Abbrev table to use in `vhdl-mode' buffers.")
2924 (defun vhdl-mode-abbrev-table-init ()
2925 "Initialize `vhdl-mode-abbrev-table'."
2926 (define-abbrev-table 'vhdl-mode-abbrev-table
2927 (append
2928 (when (memq 'vhdl vhdl-electric-keywords)
2929 ;; VHDL'93 keywords
2930 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2932 ("--" . vhdl-template-display-comment-hook)
2933 ("abs" . vhdl-template-default-hook)
2934 ("access" . vhdl-template-default-hook)
2935 ("after" . vhdl-template-default-hook)
2936 ("alias" . vhdl-template-alias-hook)
2937 ("all" . vhdl-template-default-hook)
2938 ("and" . vhdl-template-default-hook)
2939 ("arch" . vhdl-template-architecture-hook)
2940 ("architecture" . vhdl-template-architecture-hook)
2941 ("array" . vhdl-template-default-hook)
2942 ("assert" . vhdl-template-assert-hook)
2943 ("attr" . vhdl-template-attribute-hook)
2944 ("attribute" . vhdl-template-attribute-hook)
2945 ("begin" . vhdl-template-default-indent-hook)
2946 ("block" . vhdl-template-block-hook)
2947 ("body" . vhdl-template-default-hook)
2948 ("buffer" . vhdl-template-default-hook)
2949 ("bus" . vhdl-template-default-hook)
2950 ("case" . vhdl-template-case-hook)
2951 ("comp" . vhdl-template-component-hook)
2952 ("component" . vhdl-template-component-hook)
2953 ("cond" . vhdl-template-conditional-signal-asst-hook)
2954 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2955 ("conf" . vhdl-template-configuration-hook)
2956 ("configuration" . vhdl-template-configuration-hook)
2957 ("cons" . vhdl-template-constant-hook)
2958 ("constant" . vhdl-template-constant-hook)
2959 ("disconnect" . vhdl-template-disconnect-hook)
2960 ("downto" . vhdl-template-default-hook)
2961 ("else" . vhdl-template-else-hook)
2962 ("elseif" . vhdl-template-elsif-hook)
2963 ("elsif" . vhdl-template-elsif-hook)
2964 ("end" . vhdl-template-default-indent-hook)
2965 ("entity" . vhdl-template-entity-hook)
2966 ("exit" . vhdl-template-exit-hook)
2967 ("file" . vhdl-template-file-hook)
2968 ("for" . vhdl-template-for-hook)
2969 ("func" . vhdl-template-function-hook)
2970 ("function" . vhdl-template-function-hook)
2971 ("generic" . vhdl-template-generic-hook)
2972 ("group" . vhdl-template-group-hook)
2973 ("guarded" . vhdl-template-default-hook)
2974 ("if" . vhdl-template-if-hook)
2975 ("impure" . vhdl-template-default-hook)
2976 ("in" . vhdl-template-default-hook)
2977 ("inertial" . vhdl-template-default-hook)
2978 ("inout" . vhdl-template-default-hook)
2979 ("inst" . vhdl-template-instance-hook)
2980 ("instance" . vhdl-template-instance-hook)
2981 ("is" . vhdl-template-default-hook)
2982 ("label" . vhdl-template-default-hook)
2983 ("library" . vhdl-template-library-hook)
2984 ("linkage" . vhdl-template-default-hook)
2985 ("literal" . vhdl-template-default-hook)
2986 ("loop" . vhdl-template-bare-loop-hook)
2987 ("map" . vhdl-template-map-hook)
2988 ("mod" . vhdl-template-default-hook)
2989 ("nand" . vhdl-template-default-hook)
2990 ("new" . vhdl-template-default-hook)
2991 ("next" . vhdl-template-next-hook)
2992 ("nor" . vhdl-template-default-hook)
2993 ("not" . vhdl-template-default-hook)
2994 ("null" . vhdl-template-default-hook)
2995 ("of" . vhdl-template-default-hook)
2996 ("on" . vhdl-template-default-hook)
2997 ("open" . vhdl-template-default-hook)
2998 ("or" . vhdl-template-default-hook)
2999 ("others" . vhdl-template-others-hook)
3000 ("out" . vhdl-template-default-hook)
3001 ("pack" . vhdl-template-package-hook)
3002 ("package" . vhdl-template-package-hook)
3003 ("port" . vhdl-template-port-hook)
3004 ("postponed" . vhdl-template-default-hook)
3005 ("procedure" . vhdl-template-procedure-hook)
3006 ("process" . vhdl-template-process-hook)
3007 ("pure" . vhdl-template-default-hook)
3008 ("range" . vhdl-template-default-hook)
3009 ("record" . vhdl-template-default-hook)
3010 ("register" . vhdl-template-default-hook)
3011 ("reject" . vhdl-template-default-hook)
3012 ("rem" . vhdl-template-default-hook)
3013 ("report" . vhdl-template-report-hook)
3014 ("return" . vhdl-template-return-hook)
3015 ("rol" . vhdl-template-default-hook)
3016 ("ror" . vhdl-template-default-hook)
3017 ("select" . vhdl-template-selected-signal-asst-hook)
3018 ("severity" . vhdl-template-default-hook)
3019 ("shared" . vhdl-template-default-hook)
3020 ("sig" . vhdl-template-signal-hook)
3021 ("signal" . vhdl-template-signal-hook)
3022 ("sla" . vhdl-template-default-hook)
3023 ("sll" . vhdl-template-default-hook)
3024 ("sra" . vhdl-template-default-hook)
3025 ("srl" . vhdl-template-default-hook)
3026 ("subtype" . vhdl-template-subtype-hook)
3027 ("then" . vhdl-template-default-hook)
3028 ("to" . vhdl-template-default-hook)
3029 ("transport" . vhdl-template-default-hook)
3030 ("type" . vhdl-template-type-hook)
3031 ("unaffected" . vhdl-template-default-hook)
3032 ("units" . vhdl-template-default-hook)
3033 ("until" . vhdl-template-default-hook)
3034 ("use" . vhdl-template-use-hook)
3035 ("var" . vhdl-template-variable-hook)
3036 ("variable" . vhdl-template-variable-hook)
3037 ("wait" . vhdl-template-wait-hook)
3038 ("when" . vhdl-template-when-hook)
3039 ("while" . vhdl-template-while-loop-hook)
3040 ("with" . vhdl-template-with-hook)
3041 ("xnor" . vhdl-template-default-hook)
3042 ("xor" . vhdl-template-default-hook)
3044 ;; VHDL-AMS keywords
3045 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3046 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
3048 ("across" . vhdl-template-default-hook)
3049 ("break" . vhdl-template-break-hook)
3050 ("limit" . vhdl-template-limit-hook)
3051 ("nature" . vhdl-template-nature-hook)
3052 ("noise" . vhdl-template-default-hook)
3053 ("procedural" . vhdl-template-procedural-hook)
3054 ("quantity" . vhdl-template-quantity-hook)
3055 ("reference" . vhdl-template-default-hook)
3056 ("spectrum" . vhdl-template-default-hook)
3057 ("subnature" . vhdl-template-subnature-hook)
3058 ("terminal" . vhdl-template-terminal-hook)
3059 ("through" . vhdl-template-default-hook)
3060 ("tolerance" . vhdl-template-default-hook)
3062 ;; user model keywords
3063 (when (memq 'user vhdl-electric-keywords)
3064 (let (abbrev-list keyword)
3065 (dolist (elem vhdl-model-alist)
3066 (setq keyword (nth 3 elem))
3067 (unless (equal keyword "")
3068 (push (list keyword ""
3069 (vhdl-function-name
3070 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3071 abbrev-list)))
3072 abbrev-list)))))
3074 ;; initialize abbrev table for VHDL Mode
3075 (vhdl-mode-abbrev-table-init)
3077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3078 ;; Template completion lists
3080 (defvar vhdl-template-construct-alist nil
3081 "List of built-in construct templates.")
3083 (defun vhdl-template-construct-alist-init ()
3084 "Initialize `vhdl-template-construct-alist'."
3085 (setq
3086 vhdl-template-construct-alist
3087 (append
3089 ("alias declaration" vhdl-template-alias)
3090 ("architecture body" vhdl-template-architecture)
3091 ("assertion" vhdl-template-assert)
3092 ("attribute declaration" vhdl-template-attribute-decl)
3093 ("attribute specification" vhdl-template-attribute-spec)
3094 ("block configuration" vhdl-template-block-configuration)
3095 ("block statement" vhdl-template-block)
3096 ("case statement" vhdl-template-case-is)
3097 ("component configuration" vhdl-template-component-conf)
3098 ("component declaration" vhdl-template-component-decl)
3099 ("component instantiation statement" vhdl-template-component-inst)
3100 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3101 ("configuration declaration" vhdl-template-configuration-decl)
3102 ("configuration specification" vhdl-template-configuration-spec)
3103 ("constant declaration" vhdl-template-constant)
3104 ("disconnection specification" vhdl-template-disconnect)
3105 ("entity declaration" vhdl-template-entity)
3106 ("exit statement" vhdl-template-exit)
3107 ("file declaration" vhdl-template-file)
3108 ("generate statement" vhdl-template-generate)
3109 ("generic clause" vhdl-template-generic)
3110 ("group declaration" vhdl-template-group-decl)
3111 ("group template declaration" vhdl-template-group-template)
3112 ("if statement" vhdl-template-if-then)
3113 ("library clause" vhdl-template-library)
3114 ("loop statement" vhdl-template-loop)
3115 ("next statement" vhdl-template-next)
3116 ("package declaration" vhdl-template-package-decl)
3117 ("package body" vhdl-template-package-body)
3118 ("port clause" vhdl-template-port)
3119 ("process statement" vhdl-template-process)
3120 ("report statement" vhdl-template-report)
3121 ("return statement" vhdl-template-return)
3122 ("selected signal assignment" vhdl-template-selected-signal-asst)
3123 ("signal declaration" vhdl-template-signal)
3124 ("subprogram declaration" vhdl-template-subprogram-decl)
3125 ("subprogram body" vhdl-template-subprogram-body)
3126 ("subtype declaration" vhdl-template-subtype)
3127 ("type declaration" vhdl-template-type)
3128 ("use clause" vhdl-template-use)
3129 ("variable declaration" vhdl-template-variable)
3130 ("wait statement" vhdl-template-wait)
3132 (when (vhdl-standard-p 'ams)
3134 ("break statement" vhdl-template-break)
3135 ("nature declaration" vhdl-template-nature)
3136 ("quantity declaration" vhdl-template-quantity)
3137 ("simultaneous case statement" vhdl-template-case-use)
3138 ("simultaneous if statement" vhdl-template-if-use)
3139 ("simultaneous procedural statement" vhdl-template-procedural)
3140 ("step limit specification" vhdl-template-limit)
3141 ("subnature declaration" vhdl-template-subnature)
3142 ("terminal declaration" vhdl-template-terminal)
3143 )))))
3145 ;; initialize for VHDL Mode
3146 (vhdl-template-construct-alist-init)
3148 (defvar vhdl-template-package-alist nil
3149 "List of built-in package templates.")
3151 (defun vhdl-template-package-alist-init ()
3152 "Initialize `vhdl-template-package-alist'."
3153 (setq
3154 vhdl-template-package-alist
3155 (append
3157 ("numeric_bit" vhdl-template-package-numeric-bit)
3158 ("numeric_std" vhdl-template-package-numeric-std)
3159 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3160 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3161 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3162 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3163 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3164 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3165 ("textio" vhdl-template-package-textio)
3167 (when (vhdl-standard-p 'math)
3169 ("math_complex" vhdl-template-package-math-complex)
3170 ("math_real" vhdl-template-package-math-real)
3171 )))))
3173 ;; initialize for VHDL Mode
3174 (vhdl-template-package-alist-init)
3176 (defvar vhdl-template-directive-alist
3178 ("translate_on" vhdl-template-directive-translate-on)
3179 ("translate_off" vhdl-template-directive-translate-off)
3180 ("synthesis_on" vhdl-template-directive-synthesis-on)
3181 ("synthesis_off" vhdl-template-directive-synthesis-off)
3183 "List of built-in directive templates.")
3186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3187 ;;; Menus
3188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3191 ;; VHDL menu (using `easy-menu.el')
3193 (defun vhdl-customize ()
3194 "Call the customize function with `vhdl' as argument."
3195 (interactive)
3196 (customize-browse 'vhdl))
3198 (defun vhdl-create-mode-menu ()
3199 "Create VHDL Mode menu."
3200 `("VHDL"
3201 ,(append
3202 '("Project"
3203 ["None" (vhdl-set-project "")
3204 :style radio :selected (null vhdl-project)]
3205 "--")
3206 ;; add menu entries for defined projects
3207 (let ((project-alist vhdl-project-alist) menu-list name)
3208 (while project-alist
3209 (setq name (caar project-alist))
3210 (setq menu-list
3211 (cons `[,name (vhdl-set-project ,name)
3212 :style radio :selected (equal ,name vhdl-project)]
3213 menu-list))
3214 (setq project-alist (cdr project-alist)))
3215 (setq menu-list
3216 (if vhdl-project-sort
3217 (sort menu-list
3218 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3219 (nreverse menu-list)))
3220 (vhdl-menu-split menu-list "Project"))
3221 '("--" "--"
3222 ["Select Project..." vhdl-set-project t]
3223 ["Set As Default Project" vhdl-set-default-project t]
3224 "--"
3225 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3226 ["Import Project..." vhdl-import-project
3227 :keys "C-c C-p C-m" :active t]
3228 ["Export Project" vhdl-export-project vhdl-project]
3229 "--"
3230 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3231 "--"
3232 ("Compile"
3233 ["Compile Buffer" vhdl-compile t]
3234 ["Stop Compilation" kill-compilation t]
3235 "--"
3236 ["Make" vhdl-make t]
3237 ["Generate Makefile" vhdl-generate-makefile t]
3238 "--"
3239 ["Next Error" next-error t]
3240 ["Previous Error" previous-error t]
3241 ["First Error" first-error t]
3242 "--"
3243 ,(append
3244 '("Compiler")
3245 ;; add menu entries for defined compilers
3246 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3247 (while comp-alist
3248 (setq name (caar comp-alist))
3249 (setq menu-list
3250 (cons `[,name (setq vhdl-compiler ,name)
3251 :style radio :selected (equal ,name vhdl-compiler)]
3252 menu-list))
3253 (setq comp-alist (cdr comp-alist)))
3254 (setq menu-list (nreverse menu-list))
3255 (vhdl-menu-split menu-list "Compiler"))
3256 '("--" "--"
3257 ["Select Compiler..." vhdl-set-compiler t]
3258 "--"
3259 ["Customize Compiler..."
3260 (customize-option 'vhdl-compiler-alist) t])))
3261 "--"
3262 ,(append
3263 '("Template"
3264 ("VHDL Construct 1"
3265 ["Alias" vhdl-template-alias t]
3266 ["Architecture" vhdl-template-architecture t]
3267 ["Assert" vhdl-template-assert t]
3268 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3269 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3270 ["Block" vhdl-template-block t]
3271 ["Case" vhdl-template-case-is t]
3272 ["Component (Decl)" vhdl-template-component-decl t]
3273 ["(Component) Instance" vhdl-template-component-inst t]
3274 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3275 ["Configuration (Block)" vhdl-template-block-configuration t]
3276 ["Configuration (Comp)" vhdl-template-component-conf t]
3277 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3278 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3279 ["Constant" vhdl-template-constant t]
3280 ["Disconnect" vhdl-template-disconnect t]
3281 ["Else" vhdl-template-else t]
3282 ["Elsif" vhdl-template-elsif t]
3283 ["Entity" vhdl-template-entity t]
3284 ["Exit" vhdl-template-exit t]
3285 ["File" vhdl-template-file t]
3286 ["For (Generate)" vhdl-template-for-generate t]
3287 ["For (Loop)" vhdl-template-for-loop t]
3288 ["Function (Body)" vhdl-template-function-body t]
3289 ["Function (Decl)" vhdl-template-function-decl t]
3290 ["Generic" vhdl-template-generic t]
3291 ["Group (Decl)" vhdl-template-group-decl t]
3292 ["Group (Template)" vhdl-template-group-template t])
3293 ("VHDL Construct 2"
3294 ["If (Generate)" vhdl-template-if-generate t]
3295 ["If (Then)" vhdl-template-if-then t]
3296 ["Library" vhdl-template-library t]
3297 ["Loop" vhdl-template-bare-loop t]
3298 ["Map" vhdl-template-map t]
3299 ["Next" vhdl-template-next t]
3300 ["Others (Aggregate)" vhdl-template-others t]
3301 ["Package (Decl)" vhdl-template-package-decl t]
3302 ["Package (Body)" vhdl-template-package-body t]
3303 ["Port" vhdl-template-port t]
3304 ["Procedure (Body)" vhdl-template-procedure-body t]
3305 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3306 ["Process (Comb)" vhdl-template-process-comb t]
3307 ["Process (Seq)" vhdl-template-process-seq t]
3308 ["Report" vhdl-template-report t]
3309 ["Return" vhdl-template-return t]
3310 ["Select" vhdl-template-selected-signal-asst t]
3311 ["Signal" vhdl-template-signal t]
3312 ["Subtype" vhdl-template-subtype t]
3313 ["Type" vhdl-template-type t]
3314 ["Use" vhdl-template-use t]
3315 ["Variable" vhdl-template-variable t]
3316 ["Wait" vhdl-template-wait t]
3317 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3318 ["When" vhdl-template-when t]
3319 ["While (Loop)" vhdl-template-while-loop t]
3320 ["With" vhdl-template-with t]))
3321 (when (vhdl-standard-p 'ams)
3322 '(("VHDL-AMS Construct"
3323 ["Break" vhdl-template-break t]
3324 ["Case (Use)" vhdl-template-case-use t]
3325 ["If (Use)" vhdl-template-if-use t]
3326 ["Limit" vhdl-template-limit t]
3327 ["Nature" vhdl-template-nature t]
3328 ["Procedural" vhdl-template-procedural t]
3329 ["Quantity (Free)" vhdl-template-quantity-free t]
3330 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3331 ["Quantity (Source)" vhdl-template-quantity-source t]
3332 ["Subnature" vhdl-template-subnature t]
3333 ["Terminal" vhdl-template-terminal t])))
3334 '(["Insert Construct..." vhdl-template-insert-construct
3335 :keys "C-c C-i C-t"]
3336 "--")
3337 (list
3338 (append
3339 '("Package")
3340 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3341 ["numeric_std" vhdl-template-package-numeric-std t]
3342 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3343 ["textio" vhdl-template-package-textio t]
3344 "--"
3345 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3346 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3347 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3348 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3349 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3350 "--")
3351 (when (vhdl-standard-p 'ams)
3352 '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
3353 ["material_constants" vhdl-template-package-material-constants t]
3354 ["energy_systems" vhdl-template-package-energy-systems t]
3355 ["electrical_systems" vhdl-template-package-electrical-systems t]
3356 ["mechanical_systems" vhdl-template-package-mechanical-systems t]
3357 ["radiant_systems" vhdl-template-package-radiant-systems t]
3358 ["thermal_systems" vhdl-template-package-thermal-systems t]
3359 ["fluidic_systems" vhdl-template-package-fluidic-systems t]
3360 "--"))
3361 (when (vhdl-standard-p 'math)
3362 '(["math_complex" vhdl-template-package-math-complex t]
3363 ["math_real" vhdl-template-package-math-real t]
3364 "--"))
3365 '(["Insert Package..." vhdl-template-insert-package
3366 :keys "C-c C-i C-p"])))
3367 '(("Directive"
3368 ["translate_on" vhdl-template-directive-translate-on t]
3369 ["translate_off" vhdl-template-directive-translate-off t]
3370 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3371 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3372 "--"
3373 ["Insert Directive..." vhdl-template-insert-directive
3374 :keys "C-c C-i C-d"])
3375 "--"
3376 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3377 ["Insert Footer" vhdl-template-footer t]
3378 ["Insert Date" vhdl-template-insert-date t]
3379 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3380 "--"
3381 ["Query Next Prompt" vhdl-template-search-prompt t]))
3382 ,(append
3383 '("Model")
3384 ;; add menu entries for defined models
3385 (let ((model-alist vhdl-model-alist) menu-list model)
3386 (while model-alist
3387 (setq model (car model-alist))
3388 (setq menu-list
3389 (cons
3390 (vector
3391 (nth 0 model)
3392 (vhdl-function-name "vhdl-model" (nth 0 model))
3393 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3394 menu-list))
3395 (setq model-alist (cdr model-alist)))
3396 (setq menu-list (nreverse menu-list))
3397 (vhdl-menu-split menu-list "Model"))
3398 '("--" "--"
3399 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3400 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3401 ("Port"
3402 ["Copy" vhdl-port-copy t]
3403 "--"
3404 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3405 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3406 ["Paste As Instance" vhdl-port-paste-instance
3407 :keys "C-c C-p C-i" :active vhdl-port-list]
3408 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3409 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3410 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3411 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3412 "--"
3413 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3414 "--"
3415 ["Flatten" vhdl-port-flatten
3416 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3417 ["Reverse Direction" vhdl-port-reverse-direction
3418 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3419 ("Compose"
3420 ["New Component" vhdl-compose-new-component t]
3421 ["Copy Component" vhdl-port-copy t]
3422 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3423 ["Wire Components" vhdl-compose-wire-components t]
3424 "--"
3425 ["Generate Configuration" vhdl-compose-configuration t]
3426 ["Generate Components Package" vhdl-compose-components-package t])
3427 ("Subprogram"
3428 ["Copy" vhdl-subprog-copy t]
3429 "--"
3430 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3431 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3432 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3433 "--"
3434 ["Flatten" vhdl-subprog-flatten
3435 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3436 "--"
3437 ("Comment"
3438 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3439 "--"
3440 ["Insert Inline Comment" vhdl-comment-append-inline t]
3441 ["Insert Horizontal Line" vhdl-comment-display-line t]
3442 ["Insert Display Comment" vhdl-comment-display t]
3443 "--"
3444 ["Fill Comment" fill-paragraph t]
3445 ["Fill Comment Region" fill-region (mark)]
3446 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3447 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3448 ("Line"
3449 ["Kill" vhdl-line-kill t]
3450 ["Copy" vhdl-line-copy t]
3451 ["Yank" vhdl-line-yank t]
3452 ["Expand" vhdl-line-expand t]
3453 "--"
3454 ["Transpose Next" vhdl-line-transpose-next t]
3455 ["Transpose Prev" vhdl-line-transpose-previous t]
3456 ["Open" vhdl-line-open t]
3457 ["Join" vhdl-delete-indentation t]
3458 "--"
3459 ["Goto" goto-line t]
3460 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3461 ("Move"
3462 ["Forward Statement" vhdl-end-of-statement t]
3463 ["Backward Statement" vhdl-beginning-of-statement t]
3464 ["Forward Expression" vhdl-forward-sexp t]
3465 ["Backward Expression" vhdl-backward-sexp t]
3466 ["Forward Same Indent" vhdl-forward-same-indent t]
3467 ["Backward Same Indent" vhdl-backward-same-indent t]
3468 ["Forward Function" vhdl-end-of-defun t]
3469 ["Backward Function" vhdl-beginning-of-defun t]
3470 ["Mark Function" vhdl-mark-defun t])
3471 "--"
3472 ("Indent"
3473 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3474 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3475 ["Region" vhdl-indent-region (mark)]
3476 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3477 ("Align"
3478 ["Group" vhdl-align-group t]
3479 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3480 ["List" vhdl-align-list t]
3481 ["Declarations" vhdl-align-declarations t]
3482 ["Region" vhdl-align-region (mark)]
3483 ["Buffer" vhdl-align-buffer t]
3484 "--"
3485 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3486 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3487 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3488 ("Fill"
3489 ["List" vhdl-fill-list t]
3490 ["Group" vhdl-fill-group t]
3491 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3492 ["Region" vhdl-fill-region (mark)])
3493 ("Beautify"
3494 ["Region" vhdl-beautify-region (mark)]
3495 ["Buffer" vhdl-beautify-buffer t])
3496 ("Fix"
3497 ["Generic/Port Clause" vhdl-fix-clause t]
3498 ["Generic/Port Clause Buffer" vhdl-fix-clause t]
3499 "--"
3500 ["Case Region" vhdl-fix-case-region (mark)]
3501 ["Case Buffer" vhdl-fix-case-buffer t]
3502 "--"
3503 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3504 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3505 "--"
3506 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3507 ("Update"
3508 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3509 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3510 "--"
3511 ["Fontify Buffer" vhdl-fontify-buffer t]
3512 ["Statistics Buffer" vhdl-statistics-buffer t]
3513 ["Show Messages" vhdl-show-messages t]
3514 ["Syntactic Info" vhdl-show-syntactic-information t]
3515 "--"
3516 ["Speedbar" vhdl-speedbar t]
3517 ["Hide/Show" vhdl-hs-minor-mode t]
3518 "--"
3519 ("Documentation"
3520 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3521 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3522 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3523 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3524 ["Version" vhdl-version t]
3525 ["Bug Report..." vhdl-submit-bug-report t]
3526 "--"
3527 ("Options"
3528 ("Mode"
3529 ["Electric Mode"
3530 (progn (customize-set-variable 'vhdl-electric-mode
3531 (not vhdl-electric-mode))
3532 (vhdl-mode-line-update))
3533 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3534 ["Stutter Mode"
3535 (progn (customize-set-variable 'vhdl-stutter-mode
3536 (not vhdl-stutter-mode))
3537 (vhdl-mode-line-update))
3538 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3539 ["Indent Tabs Mode"
3540 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3541 (not vhdl-indent-tabs-mode))
3542 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3543 :style toggle :selected vhdl-indent-tabs-mode]
3544 "--"
3545 ["Customize Group..." (customize-group 'vhdl-mode) t])
3546 ("Project"
3547 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3548 ,(append
3549 '("Selected Project at Startup"
3550 ["None" (progn (customize-set-variable 'vhdl-project nil)
3551 (vhdl-set-project ""))
3552 :style radio :selected (null vhdl-project)]
3553 "--")
3554 ;; add menu entries for defined projects
3555 (let ((project-alist vhdl-project-alist) menu-list name)
3556 (while project-alist
3557 (setq name (caar project-alist))
3558 (setq menu-list
3559 (cons `[,name (progn (customize-set-variable
3560 'vhdl-project ,name)
3561 (vhdl-set-project ,name))
3562 :style radio :selected (equal ,name vhdl-project)]
3563 menu-list))
3564 (setq project-alist (cdr project-alist)))
3565 (setq menu-list (nreverse menu-list))
3566 (vhdl-menu-split menu-list "Project")))
3567 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3568 ("Auto Load Setup File"
3569 ["At Startup"
3570 (customize-set-variable 'vhdl-project-auto-load
3571 (if (memq 'startup vhdl-project-auto-load)
3572 (delq 'startup vhdl-project-auto-load)
3573 (cons 'startup vhdl-project-auto-load)))
3574 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3575 ["Sort Projects"
3576 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3577 :style toggle :selected vhdl-project-sort]
3578 "--"
3579 ["Customize Group..." (customize-group 'vhdl-project) t])
3580 ("Compiler"
3581 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3582 ,(append
3583 '("Selected Compiler at Startup")
3584 ;; add menu entries for defined compilers
3585 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3586 (while comp-alist
3587 (setq name (caar comp-alist))
3588 (setq menu-list
3589 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3590 :style radio :selected (equal ,name vhdl-compiler)]
3591 menu-list))
3592 (setq comp-alist (cdr comp-alist)))
3593 (setq menu-list (nreverse menu-list))
3594 (vhdl-menu-split menu-list "Compiler")))
3595 ["Use Local Error Regexp"
3596 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3597 (not vhdl-compile-use-local-error-regexp))
3598 :style toggle :selected vhdl-compile-use-local-error-regexp]
3599 ["Makefile Default Targets..."
3600 (customize-option 'vhdl-makefile-default-targets) t]
3601 ["Makefile Generation Hook..."
3602 (customize-option 'vhdl-makefile-generation-hook) t]
3603 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3604 "--"
3605 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3606 ("Style"
3607 ("VHDL Standard"
3608 ["VHDL'87"
3609 (progn (customize-set-variable 'vhdl-standard
3610 (list '87 (cadr vhdl-standard)))
3611 (vhdl-activate-customizations))
3612 :style radio :selected (eq '87 (car vhdl-standard))]
3613 ["VHDL'93/02"
3614 (progn (customize-set-variable 'vhdl-standard
3615 (list '93 (cadr vhdl-standard)))
3616 (vhdl-activate-customizations))
3617 :style radio :selected (eq '93 (car vhdl-standard))]
3618 "--"
3619 ["VHDL-AMS"
3620 (progn (customize-set-variable
3621 'vhdl-standard (list (car vhdl-standard)
3622 (if (memq 'ams (cadr vhdl-standard))
3623 (delq 'ams (cadr vhdl-standard))
3624 (cons 'ams (cadr vhdl-standard)))))
3625 (vhdl-activate-customizations))
3626 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3627 ["Math Packages"
3628 (progn (customize-set-variable
3629 'vhdl-standard (list (car vhdl-standard)
3630 (if (memq 'math (cadr vhdl-standard))
3631 (delq 'math (cadr vhdl-standard))
3632 (cons 'math (cadr vhdl-standard)))))
3633 (vhdl-activate-customizations))
3634 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3635 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3636 ["Upper Case Keywords"
3637 (customize-set-variable 'vhdl-upper-case-keywords
3638 (not vhdl-upper-case-keywords))
3639 :style toggle :selected vhdl-upper-case-keywords]
3640 ["Upper Case Types"
3641 (customize-set-variable 'vhdl-upper-case-types
3642 (not vhdl-upper-case-types))
3643 :style toggle :selected vhdl-upper-case-types]
3644 ["Upper Case Attributes"
3645 (customize-set-variable 'vhdl-upper-case-attributes
3646 (not vhdl-upper-case-attributes))
3647 :style toggle :selected vhdl-upper-case-attributes]
3648 ["Upper Case Enumeration Values"
3649 (customize-set-variable 'vhdl-upper-case-enum-values
3650 (not vhdl-upper-case-enum-values))
3651 :style toggle :selected vhdl-upper-case-enum-values]
3652 ["Upper Case Constants"
3653 (customize-set-variable 'vhdl-upper-case-constants
3654 (not vhdl-upper-case-constants))
3655 :style toggle :selected vhdl-upper-case-constants]
3656 ("Use Direct Instantiation"
3657 ["Never"
3658 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3659 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3660 ["Standard"
3661 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3662 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3663 ["Always"
3664 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3665 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3666 ["Include Array Index and Record Field in Sensitivity List"
3667 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3668 (not vhdl-array-index-record-field-in-sensitivity-list))
3669 :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
3670 "--"
3671 ["Customize Group..." (customize-group 'vhdl-style) t])
3672 ("Naming"
3673 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3674 ["Architecture File Name..."
3675 (customize-option 'vhdl-architecture-file-name) t]
3676 ["Configuration File Name..."
3677 (customize-option 'vhdl-configuration-file-name) t]
3678 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3679 ("File Name Case"
3680 ["As Is"
3681 (customize-set-variable 'vhdl-file-name-case 'identity)
3682 :style radio :selected (eq 'identity vhdl-file-name-case)]
3683 ["Lower Case"
3684 (customize-set-variable 'vhdl-file-name-case 'downcase)
3685 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3686 ["Upper Case"
3687 (customize-set-variable 'vhdl-file-name-case 'upcase)
3688 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3689 ["Capitalize"
3690 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3691 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3692 "--"
3693 ["Customize Group..." (customize-group 'vhdl-naming) t])
3694 ("Template"
3695 ("Electric Keywords"
3696 ["VHDL Keywords"
3697 (customize-set-variable 'vhdl-electric-keywords
3698 (if (memq 'vhdl vhdl-electric-keywords)
3699 (delq 'vhdl vhdl-electric-keywords)
3700 (cons 'vhdl vhdl-electric-keywords)))
3701 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3702 ["User Model Keywords"
3703 (customize-set-variable 'vhdl-electric-keywords
3704 (if (memq 'user vhdl-electric-keywords)
3705 (delq 'user vhdl-electric-keywords)
3706 (cons 'user vhdl-electric-keywords)))
3707 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3708 ("Insert Optional Labels"
3709 ["None"
3710 (customize-set-variable 'vhdl-optional-labels 'none)
3711 :style radio :selected (eq 'none vhdl-optional-labels)]
3712 ["Processes Only"
3713 (customize-set-variable 'vhdl-optional-labels 'process)
3714 :style radio :selected (eq 'process vhdl-optional-labels)]
3715 ["All Constructs"
3716 (customize-set-variable 'vhdl-optional-labels 'all)
3717 :style radio :selected (eq 'all vhdl-optional-labels)])
3718 ("Insert Empty Lines"
3719 ["None"
3720 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3721 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3722 ["Design Units Only"
3723 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3724 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3725 ["All Constructs"
3726 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3727 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3728 ["Argument List Indent"
3729 (customize-set-variable 'vhdl-argument-list-indent
3730 (not vhdl-argument-list-indent))
3731 :style toggle :selected vhdl-argument-list-indent]
3732 ["Association List with Formals"
3733 (customize-set-variable 'vhdl-association-list-with-formals
3734 (not vhdl-association-list-with-formals))
3735 :style toggle :selected vhdl-association-list-with-formals]
3736 ["Conditions in Parenthesis"
3737 (customize-set-variable 'vhdl-conditions-in-parenthesis
3738 (not vhdl-conditions-in-parenthesis))
3739 :style toggle :selected vhdl-conditions-in-parenthesis]
3740 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3741 ["One String..." (customize-option 'vhdl-one-string) t]
3742 ("File Header"
3743 ["Header String..." (customize-option 'vhdl-file-header) t]
3744 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3745 ["Company Name..." (customize-option 'vhdl-company-name) t]
3746 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3747 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3748 ["Date Format..." (customize-option 'vhdl-date-format) t]
3749 ["Modify Date Prefix String..."
3750 (customize-option 'vhdl-modify-date-prefix-string) t]
3751 ["Modify Date on Saving"
3752 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3753 (not vhdl-modify-date-on-saving))
3754 (vhdl-activate-customizations))
3755 :style toggle :selected vhdl-modify-date-on-saving])
3756 ("Sequential Process"
3757 ("Kind of Reset"
3758 ["None"
3759 (customize-set-variable 'vhdl-reset-kind 'none)
3760 :style radio :selected (eq 'none vhdl-reset-kind)]
3761 ["Synchronous"
3762 (customize-set-variable 'vhdl-reset-kind 'sync)
3763 :style radio :selected (eq 'sync vhdl-reset-kind)]
3764 ["Asynchronous"
3765 (customize-set-variable 'vhdl-reset-kind 'async)
3766 :style radio :selected (eq 'async vhdl-reset-kind)]
3767 ["Query"
3768 (customize-set-variable 'vhdl-reset-kind 'query)
3769 :style radio :selected (eq 'query vhdl-reset-kind)])
3770 ["Reset is Active High"
3771 (customize-set-variable 'vhdl-reset-active-high
3772 (not vhdl-reset-active-high))
3773 :style toggle :selected vhdl-reset-active-high]
3774 ["Use Rising Clock Edge"
3775 (customize-set-variable 'vhdl-clock-rising-edge
3776 (not vhdl-clock-rising-edge))
3777 :style toggle :selected vhdl-clock-rising-edge]
3778 ("Clock Edge Condition"
3779 ["Standard"
3780 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3781 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3782 ["Function \"rising_edge\""
3783 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3784 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3785 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3786 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3787 "--"
3788 ["Customize Group..." (customize-group 'vhdl-template) t])
3789 ("Model"
3790 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3791 ("Port"
3792 ["Include Port Comments"
3793 (customize-set-variable 'vhdl-include-port-comments
3794 (not vhdl-include-port-comments))
3795 :style toggle :selected vhdl-include-port-comments]
3796 ["Include Direction Comments"
3797 (customize-set-variable 'vhdl-include-direction-comments
3798 (not vhdl-include-direction-comments))
3799 :style toggle :selected vhdl-include-direction-comments]
3800 ["Include Type Comments"
3801 (customize-set-variable 'vhdl-include-type-comments
3802 (not vhdl-include-type-comments))
3803 :style toggle :selected vhdl-include-type-comments]
3804 ("Include Group Comments"
3805 ["Never"
3806 (customize-set-variable 'vhdl-include-group-comments 'never)
3807 :style radio :selected (eq 'never vhdl-include-group-comments)]
3808 ["Declarations"
3809 (customize-set-variable 'vhdl-include-group-comments 'decl)
3810 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3811 ["Always"
3812 (customize-set-variable 'vhdl-include-group-comments 'always)
3813 :style radio :selected (eq 'always vhdl-include-group-comments)])
3814 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3815 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3816 ("Testbench"
3817 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3818 ["Architecture Name..."
3819 (customize-option 'vhdl-testbench-architecture-name) t]
3820 ["Configuration Name..."
3821 (customize-option 'vhdl-testbench-configuration-name) t]
3822 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3823 ["Include Header"
3824 (customize-set-variable 'vhdl-testbench-include-header
3825 (not vhdl-testbench-include-header))
3826 :style toggle :selected vhdl-testbench-include-header]
3827 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3828 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3829 ["Initialize Signals"
3830 (customize-set-variable 'vhdl-testbench-initialize-signals
3831 (not vhdl-testbench-initialize-signals))
3832 :style toggle :selected vhdl-testbench-initialize-signals]
3833 ["Include Library Clause"
3834 (customize-set-variable 'vhdl-testbench-include-library
3835 (not vhdl-testbench-include-library))
3836 :style toggle :selected vhdl-testbench-include-library]
3837 ["Include Configuration"
3838 (customize-set-variable 'vhdl-testbench-include-configuration
3839 (not vhdl-testbench-include-configuration))
3840 :style toggle :selected vhdl-testbench-include-configuration]
3841 ("Create Files"
3842 ["None"
3843 (customize-set-variable 'vhdl-testbench-create-files 'none)
3844 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3845 ["Single"
3846 (customize-set-variable 'vhdl-testbench-create-files 'single)
3847 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3848 ["Separate"
3849 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3850 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3851 ["Testbench Entity File Name..."
3852 (customize-option 'vhdl-testbench-entity-file-name) t]
3853 ["Testbench Architecture File Name..."
3854 (customize-option 'vhdl-testbench-architecture-file-name) t])
3855 "--"
3856 ["Customize Group..." (customize-group 'vhdl-port) t])
3857 ("Compose"
3858 ["Architecture Name..."
3859 (customize-option 'vhdl-compose-architecture-name) t]
3860 ["Configuration Name..."
3861 (customize-option 'vhdl-compose-configuration-name) t]
3862 ["Components Package Name..."
3863 (customize-option 'vhdl-components-package-name) t]
3864 ["Use Components Package"
3865 (customize-set-variable 'vhdl-use-components-package
3866 (not vhdl-use-components-package))
3867 :style toggle :selected vhdl-use-components-package]
3868 ["Include Header"
3869 (customize-set-variable 'vhdl-compose-include-header
3870 (not vhdl-compose-include-header))
3871 :style toggle :selected vhdl-compose-include-header]
3872 ("Create Entity/Architecture Files"
3873 ["None"
3874 (customize-set-variable 'vhdl-compose-create-files 'none)
3875 :style radio :selected (eq 'none vhdl-compose-create-files)]
3876 ["Single"
3877 (customize-set-variable 'vhdl-compose-create-files 'single)
3878 :style radio :selected (eq 'single vhdl-compose-create-files)]
3879 ["Separate"
3880 (customize-set-variable 'vhdl-compose-create-files 'separate)
3881 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3882 ["Create Configuration File"
3883 (customize-set-variable 'vhdl-compose-configuration-create-file
3884 (not vhdl-compose-configuration-create-file))
3885 :style toggle :selected vhdl-compose-configuration-create-file]
3886 ["Hierarchical Configuration"
3887 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3888 (not vhdl-compose-configuration-hierarchical))
3889 :style toggle :selected vhdl-compose-configuration-hierarchical]
3890 ["Use Subconfiguration"
3891 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3892 (not vhdl-compose-configuration-use-subconfiguration))
3893 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3894 "--"
3895 ["Customize Group..." (customize-group 'vhdl-compose) t])
3896 ("Comment"
3897 ["Self Insert Comments"
3898 (customize-set-variable 'vhdl-self-insert-comments
3899 (not vhdl-self-insert-comments))
3900 :style toggle :selected vhdl-self-insert-comments]
3901 ["Prompt for Comments"
3902 (customize-set-variable 'vhdl-prompt-for-comments
3903 (not vhdl-prompt-for-comments))
3904 :style toggle :selected vhdl-prompt-for-comments]
3905 ["Inline Comment Column..."
3906 (customize-option 'vhdl-inline-comment-column) t]
3907 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3908 "--"
3909 ["Customize Group..." (customize-group 'vhdl-comment) t])
3910 ("Align"
3911 ["Auto Align Templates"
3912 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3913 :style toggle :selected vhdl-auto-align]
3914 ["Align Line Groups"
3915 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3916 :style toggle :selected vhdl-align-groups]
3917 ["Group Separation String..."
3918 (customize-set-variable 'vhdl-align-group-separate) t]
3919 ["Align Lines with Same Indent"
3920 (customize-set-variable 'vhdl-align-same-indent
3921 (not vhdl-align-same-indent))
3922 :style toggle :selected vhdl-align-same-indent]
3923 "--"
3924 ["Customize Group..." (customize-group 'vhdl-align) t])
3925 ("Highlight"
3926 ["Highlighting On/Off..."
3927 (customize-option
3928 (if (fboundp 'global-font-lock-mode)
3929 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3930 ["Highlight Keywords"
3931 (progn (customize-set-variable 'vhdl-highlight-keywords
3932 (not vhdl-highlight-keywords))
3933 (vhdl-fontify-buffer))
3934 :style toggle :selected vhdl-highlight-keywords]
3935 ["Highlight Names"
3936 (progn (customize-set-variable 'vhdl-highlight-names
3937 (not vhdl-highlight-names))
3938 (vhdl-fontify-buffer))
3939 :style toggle :selected vhdl-highlight-names]
3940 ["Highlight Special Words"
3941 (progn (customize-set-variable 'vhdl-highlight-special-words
3942 (not vhdl-highlight-special-words))
3943 (vhdl-fontify-buffer))
3944 :style toggle :selected vhdl-highlight-special-words]
3945 ["Highlight Forbidden Words"
3946 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3947 (not vhdl-highlight-forbidden-words))
3948 (vhdl-fontify-buffer))
3949 :style toggle :selected vhdl-highlight-forbidden-words]
3950 ["Highlight Verilog Keywords"
3951 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3952 (not vhdl-highlight-verilog-keywords))
3953 (vhdl-fontify-buffer))
3954 :style toggle :selected vhdl-highlight-verilog-keywords]
3955 ["Highlight \"translate_off\""
3956 (progn (customize-set-variable 'vhdl-highlight-translate-off
3957 (not vhdl-highlight-translate-off))
3958 (vhdl-fontify-buffer))
3959 :style toggle :selected vhdl-highlight-translate-off]
3960 ["Case Sensitive Highlighting"
3961 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3962 (not vhdl-highlight-case-sensitive))
3963 (vhdl-fontify-buffer))
3964 :style toggle :selected vhdl-highlight-case-sensitive]
3965 ["Special Syntax Definition..."
3966 (customize-option 'vhdl-special-syntax-alist) t]
3967 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3968 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3969 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3970 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3971 "--"
3972 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3973 ("Speedbar"
3974 ["Auto Open at Startup"
3975 (customize-set-variable 'vhdl-speedbar-auto-open
3976 (not vhdl-speedbar-auto-open))
3977 :style toggle :selected vhdl-speedbar-auto-open]
3978 ("Default Displaying Mode"
3979 ["Files"
3980 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3981 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3982 ["Directory Hierarchy"
3983 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3984 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3985 ["Project Hierarchy"
3986 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3987 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3988 ["Indentation Offset..."
3989 (customize-option 'speedbar-indentation-width) t]
3990 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3991 ["Jump to Unit when Opening"
3992 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3993 (not vhdl-speedbar-jump-to-unit))
3994 :style toggle :selected vhdl-speedbar-jump-to-unit]
3995 ["Update Hierarchy on File Saving"
3996 (customize-set-variable 'vhdl-speedbar-update-on-saving
3997 (not vhdl-speedbar-update-on-saving))
3998 :style toggle :selected vhdl-speedbar-update-on-saving]
3999 ("Save in Cache File"
4000 ["Hierarchy Information"
4001 (customize-set-variable 'vhdl-speedbar-save-cache
4002 (if (memq 'hierarchy vhdl-speedbar-save-cache)
4003 (delq 'hierarchy vhdl-speedbar-save-cache)
4004 (cons 'hierarchy vhdl-speedbar-save-cache)))
4005 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
4006 ["Displaying Status"
4007 (customize-set-variable 'vhdl-speedbar-save-cache
4008 (if (memq 'display vhdl-speedbar-save-cache)
4009 (delq 'display vhdl-speedbar-save-cache)
4010 (cons 'display vhdl-speedbar-save-cache)))
4011 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
4012 ["Cache File Name..."
4013 (customize-option 'vhdl-speedbar-cache-file-name) t]
4014 "--"
4015 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
4016 ("Menu"
4017 ["Add Index Menu when Loading File"
4018 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
4019 (vhdl-index-menu-init))
4020 :style toggle :selected vhdl-index-menu]
4021 ["Add Source File Menu when Loading File"
4022 (progn (customize-set-variable 'vhdl-source-file-menu
4023 (not vhdl-source-file-menu))
4024 (vhdl-add-source-files-menu))
4025 :style toggle :selected vhdl-source-file-menu]
4026 ["Add Hideshow Menu at Startup"
4027 (progn (customize-set-variable 'vhdl-hideshow-menu
4028 (not vhdl-hideshow-menu))
4029 (vhdl-activate-customizations))
4030 :style toggle :selected vhdl-hideshow-menu]
4031 ["Hide Everything Initially"
4032 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
4033 :style toggle :selected vhdl-hide-all-init]
4034 "--"
4035 ["Customize Group..." (customize-group 'vhdl-menu) t])
4036 ("Print"
4037 ["In Two Column Format"
4038 (progn (customize-set-variable 'vhdl-print-two-column
4039 (not vhdl-print-two-column))
4040 (message "Activate new setting by saving options and restarting Emacs"))
4041 :style toggle :selected vhdl-print-two-column]
4042 ["Use Customized Faces"
4043 (progn (customize-set-variable 'vhdl-print-customize-faces
4044 (not vhdl-print-customize-faces))
4045 (message "Activate new setting by saving options and restarting Emacs"))
4046 :style toggle :selected vhdl-print-customize-faces]
4047 "--"
4048 ["Customize Group..." (customize-group 'vhdl-print) t])
4049 ("Miscellaneous"
4050 ["Use Intelligent Tab"
4051 (progn (customize-set-variable 'vhdl-intelligent-tab
4052 (not vhdl-intelligent-tab))
4053 (vhdl-activate-customizations))
4054 :style toggle :selected vhdl-intelligent-tab]
4055 ["Indent Syntax-Based"
4056 (customize-set-variable 'vhdl-indent-syntax-based
4057 (not vhdl-indent-syntax-based))
4058 :style toggle :selected vhdl-indent-syntax-based]
4059 ["Indent Comments Like Next Code Line"
4060 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4061 (not vhdl-indent-comment-like-next-code-line))
4062 :style toggle :selected vhdl-indent-comment-like-next-code-line]
4063 ["Word Completion is Case Sensitive"
4064 (customize-set-variable 'vhdl-word-completion-case-sensitive
4065 (not vhdl-word-completion-case-sensitive))
4066 :style toggle :selected vhdl-word-completion-case-sensitive]
4067 ["Word Completion in Minibuffer"
4068 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4069 (not vhdl-word-completion-in-minibuffer))
4070 (message "Activate new setting by saving options and restarting Emacs"))
4071 :style toggle :selected vhdl-word-completion-in-minibuffer]
4072 ["Underscore is Part of Word"
4073 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4074 (not vhdl-underscore-is-part-of-word))
4075 (vhdl-activate-customizations))
4076 :style toggle :selected vhdl-underscore-is-part-of-word]
4077 "--"
4078 ["Customize Group..." (customize-group 'vhdl-misc) t])
4079 ["Related..." (customize-browse 'vhdl-related) t]
4080 "--"
4081 ["Save Options" customize-save-customized t]
4082 ["Activate Options" vhdl-activate-customizations t]
4083 ["Browse Options..." vhdl-customize t])))
4085 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4086 "VHDL Mode menu.")
4088 (defun vhdl-update-mode-menu ()
4089 "Update VHDL Mode menu."
4090 (interactive)
4091 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4092 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4093 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4094 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4095 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
4097 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4098 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4100 (defconst vhdl-imenu-generic-expression
4102 ("Subprogram"
4103 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4105 ("Instance"
4106 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4108 ("Component"
4109 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4111 ("Procedural"
4112 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4114 ("Process"
4115 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4117 ("Block"
4118 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4120 ("Package"
4121 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4123 ("Configuration"
4124 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4126 ("Architecture"
4127 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4129 ("Entity"
4130 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4133 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4135 (defun vhdl-index-menu-init ()
4136 "Initialize index menu."
4137 (set (make-local-variable 'imenu-case-fold-search) t)
4138 (set (make-local-variable 'imenu-generic-expression)
4139 vhdl-imenu-generic-expression)
4140 (when (and vhdl-index-menu (fboundp 'imenu))
4141 (if (or (not (boundp 'font-lock-maximum-size))
4142 (> font-lock-maximum-size (buffer-size)))
4143 (imenu-add-to-menubar "Index")
4144 (message "Scanning buffer for index...buffer too big"))))
4146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4147 ;; Source file menu (using `easy-menu.el')
4149 (defvar vhdl-sources-menu nil)
4151 (defun vhdl-directory-files (directory &optional full match)
4152 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4153 message."
4154 (if (not (file-directory-p directory))
4155 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4156 (let ((dir (directory-files directory full match)))
4157 (setq dir (delete "." dir))
4158 (setq dir (delete ".." dir))
4159 dir)))
4161 (defun vhdl-get-source-files (&optional full directory)
4162 "Get list of VHDL source files in DIRECTORY or current directory."
4163 (let ((mode-alist auto-mode-alist)
4164 filename-regexp)
4165 ;; create regular expressions for matching file names
4166 (setq filename-regexp "\\`[^.].*\\(")
4167 (while mode-alist
4168 (when (eq (cdar mode-alist) 'vhdl-mode)
4169 (setq filename-regexp
4170 (concat filename-regexp (caar mode-alist) "\\|")))
4171 (setq mode-alist (cdr mode-alist)))
4172 (setq filename-regexp
4173 (concat (substring filename-regexp 0
4174 (string-match "\\\\|$" filename-regexp)) "\\)"))
4175 ;; find files
4176 (vhdl-directory-files
4177 (or directory default-directory) full filename-regexp)))
4179 (defun vhdl-add-source-files-menu ()
4180 "Scan directory for all VHDL source files and generate menu.
4181 The directory of the current source file is scanned."
4182 (interactive)
4183 (message "Scanning directory for source files ...")
4184 (let ((newmap (current-local-map))
4185 (file-list (vhdl-get-source-files))
4186 menu-list found)
4187 ;; Create list for menu
4188 (setq found nil)
4189 (while file-list
4190 (setq found t)
4191 (setq menu-list (cons (vector (car file-list)
4192 (list 'find-file (car file-list)) t)
4193 menu-list))
4194 (setq file-list (cdr file-list)))
4195 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4196 (when found (setq menu-list (cons "--" menu-list)))
4197 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4198 (setq menu-list (cons "Sources" menu-list))
4199 ;; Create menu
4200 (easy-menu-add menu-list)
4201 (easy-menu-define vhdl-sources-menu newmap
4202 "VHDL source files menu" menu-list))
4203 (message ""))
4206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4207 ;;; Mode definition
4208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4209 ;; performs all buffer local initializations
4211 ;;;###autoload
4212 (define-derived-mode vhdl-mode prog-mode
4213 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4214 (vhdl-electric-mode "e")
4215 (vhdl-stutter-mode "s"))
4216 "Major mode for editing VHDL code.
4218 Usage:
4219 ------
4221 TEMPLATE INSERTION (electrification):
4222 After typing a VHDL keyword and entering `SPC', you are prompted for
4223 arguments while a template is generated for that VHDL construct. Typing
4224 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4225 template generation. Optional arguments are indicated by square
4226 brackets and removed if the queried string is left empty. Prompts for
4227 mandatory arguments remain in the code if the queried string is left
4228 empty. They can be queried again by `C-c C-t C-q'. Enabled
4229 electrification is indicated by `/e' in the mode line.
4231 Typing `M-SPC' after a keyword inserts a space without calling the
4232 template generator. Automatic template generation (i.e.
4233 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4234 setting option `vhdl-electric-mode' (see OPTIONS).
4236 Template generators can be invoked from the VHDL menu, by key
4237 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4238 the keyword (i.e. first word of menu entry not in parenthesis) and
4239 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4240 conf, comp, cons, func, inst, pack, sig, var.
4242 Template styles can be customized in customization group
4243 `vhdl-template' \(see OPTIONS).
4246 HEADER INSERTION:
4247 A file header can be inserted by `C-c C-t C-h'. A file footer
4248 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4249 See customization group `vhdl-header'.
4252 STUTTERING:
4253 Double striking of some keys inserts cumbersome VHDL syntax elements.
4254 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4255 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4256 the mode line. The stuttering keys and their effects are:
4258 ;; --> \" : \" [ --> ( -- --> comment
4259 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4260 .. --> \" => \" ] --> ) --- --> horizontal line
4261 ,, --> \" <= \" ]] --> ] ---- --> display comment
4262 == --> \" == \" '' --> \\\"
4265 WORD COMPLETION:
4266 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4267 word in the buffer that starts alike, inserts it and adjusts case.
4268 Re-typing `TAB' toggles through alternative word completions. This also
4269 works in the minibuffer (i.e. in template generator prompts).
4271 Typing `TAB' after `(' looks for and inserts complete parenthesized
4272 expressions (e.g. for array index ranges). All keywords as well as
4273 standard types and subprograms of VHDL have predefined abbreviations
4274 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4275 beginning with \"std\").
4277 Typing `TAB' after a non-word character indents the line if at the
4278 beginning of a line (i.e. no preceding non-blank characters), and
4279 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4280 stop.
4283 COMMENTS:
4284 `--' puts a single comment.
4285 `---' draws a horizontal line for separating code segments.
4286 `----' inserts a display comment, i.e. two horizontal lines
4287 with a comment in between.
4288 `--CR' comments out code on that line. Re-hitting CR comments
4289 out following lines.
4290 `C-c C-c' comments out a region if not commented out,
4291 uncomments a region if already commented out. Option
4292 `comment-style' defines where the comment characters
4293 should be placed (beginning of line, indent, etc.).
4295 You are prompted for comments after object definitions (i.e. signals,
4296 variables, constants, ports) and after subprogram and process
4297 specifications if option `vhdl-prompt-for-comments' is non-nil.
4298 Comments are automatically inserted as additional labels (e.g. after
4299 begin statements) and as help comments if `vhdl-self-insert-comments' is
4300 non-nil.
4302 Inline comments (i.e. comments after a piece of code on the same line)
4303 are indented at least to `vhdl-inline-comment-column'. Comments go at
4304 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4305 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4306 in a comment automatically opens a new comment line. `M-q' re-fills
4307 multi-line comments.
4310 INDENTATION:
4311 `TAB' indents a line if at the beginning of the line. The amount of
4312 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4313 always indents the current line (is bound to `TAB' if option
4314 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4315 the entire region.
4317 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4318 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4319 indented normally (nil) or relative to the opening parenthesis (non-nil)
4320 according to option `vhdl-argument-list-indent'.
4322 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4323 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4324 and vice versa.
4326 Syntax-based indentation can be very slow in large files. Option
4327 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4329 Option `vhdl-indent-comment-like-next-code-line' controls whether
4330 comment lines are indented like the preceding or like the following code
4331 line.
4334 ALIGNMENT:
4335 The alignment functions align operators, keywords, and inline comments
4336 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4337 separated by blank lines, `C-c C-a C-i' a block of lines with same
4338 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4339 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4340 C-a C-d' all lines within the declarative part of a design unit. `C-c
4341 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4342 for a group of lines, and `C-c C-a M-c' for a region.
4344 If option `vhdl-align-groups' is non-nil, groups of code lines
4345 separated by special lines (see option `vhdl-align-group-separate') are
4346 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4347 blocks of lines with same indent are aligned separately. Some templates
4348 are automatically aligned after generation if option `vhdl-auto-align'
4349 is non-nil.
4351 Alignment tries to align inline comments at
4352 `vhdl-inline-comment-column' and tries inline comment not to exceed
4353 `vhdl-end-comment-column'.
4355 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4356 symbols are surrounded by one space, and multiple spaces are eliminated.
4359 CODE FILLING:
4360 Code filling allows to condense code (e.g. sensitivity lists or port
4361 maps) by removing comments and newlines and re-wrapping so that all
4362 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4363 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4364 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4365 `C-c C-f M-f' an entire region.
4368 CODE BEAUTIFICATION:
4369 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4370 buffer respectively. This includes indentation, alignment, and case
4371 fixing. Code beautification can also be run non-interactively using the
4372 command:
4374 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4377 PORT TRANSLATION:
4378 Generic and port clauses from entity or component declarations can be
4379 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4380 as component instantiations and corresponding internal constants and
4381 signals, as a generic map with constants as actual generics, and as
4382 internal signal initializations (menu).
4384 To include formals in component instantiations, see option
4385 `vhdl-association-list-with-formals'. To include comments in pasting,
4386 see options `vhdl-include-...-comments'.
4388 A clause with several generic/port names on the same line can be
4389 flattened (`C-c C-p C-f') so that only one name per line exists. The
4390 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4391 outputs and vice versa, which can be useful in testbenches. (This
4392 reversion is done on the internal data structure and is only reflected
4393 in subsequent paste operations.)
4395 Names for actual ports, instances, testbenches, and
4396 design-under-test instances can be derived from existing names according
4397 to options `vhdl-...-name'. See customization group `vhdl-port'.
4400 SUBPROGRAM TRANSLATION:
4401 Similar functionality exists for copying/pasting the interface of
4402 subprograms (function/procedure). A subprogram interface can be copied
4403 and then pasted as a subprogram declaration, body or call (uses
4404 association list with formals).
4407 TESTBENCH GENERATION:
4408 A copied port can also be pasted as a testbench. The generated
4409 testbench includes an entity, an architecture, and an optional
4410 configuration. The architecture contains the component declaration and
4411 instantiation of the DUT as well as internal constant and signal
4412 declarations. Additional user-defined templates can be inserted. The
4413 names used for entity/architecture/configuration/DUT as well as the file
4414 structure to be generated can be customized. See customization group
4415 `vhdl-testbench'.
4418 KEY BINDINGS:
4419 Key bindings (`C-c ...') exist for most commands (see in menu).
4422 VHDL MENU:
4423 All commands can be found in the VHDL menu including their key bindings.
4426 FILE BROWSER:
4427 The speedbar allows browsing of directories and file contents. It can
4428 be accessed from the VHDL menu and is automatically opened if option
4429 `vhdl-speedbar-auto-open' is non-nil.
4431 In speedbar, open files and directories with `mouse-2' on the name and
4432 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4435 DESIGN HIERARCHY BROWSER:
4436 The speedbar can also be used for browsing the hierarchy of design units
4437 contained in the source files of the current directory or the specified
4438 projects (see option `vhdl-project-alist').
4440 The speedbar can be switched between file, directory hierarchy and
4441 project hierarchy browsing mode in the speedbar menu or by typing `f',
4442 `h' or `H' in speedbar.
4444 In speedbar, open design units with `mouse-2' on the name and browse
4445 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4446 from entities and components (in packages). Individual design units and
4447 complete designs can directly be compiled (\"Make\" menu entry).
4449 The hierarchy is automatically updated upon saving a modified source
4450 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4451 hierarchy is only updated for projects that have been opened once in the
4452 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4453 options in group `vhdl-speedbar').
4455 Simple design consistency checks are done during scanning, such as
4456 multiple declarations of the same unit or missing primary units that are
4457 required by secondary units.
4460 STRUCTURAL COMPOSITION:
4461 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4462 for a new component. Subcomponents (i.e. component declaration and
4463 instantiation) can be automatically placed from a previously read port
4464 \(`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4465 all subcomponents can be automatically connected using internal signals
4466 and ports (`C-c C-m C-w') following these rules:
4467 - subcomponent actual ports with same name are considered to be
4468 connected by a signal (internal signal or port)
4469 - signals that are only inputs to subcomponents are considered as
4470 inputs to this component -> input port created
4471 - signals that are only outputs from subcomponents are considered as
4472 outputs from this component -> output port created
4473 - signals that are inputs to AND outputs from subcomponents are
4474 considered as internal connections -> internal signal created
4476 Purpose: With appropriate naming conventions it is possible to
4477 create higher design levels with only a few mouse clicks or key
4478 strokes. A new design level can be created by simply generating a new
4479 component, placing the required subcomponents from the hierarchy
4480 browser, and wiring everything automatically.
4482 Note: Automatic wiring only works reliably on templates of new
4483 components and component instantiations that were created by VHDL mode.
4485 Component declarations can be placed in a components package (option
4486 `vhdl-use-components-package') which can be automatically generated for
4487 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4488 component instantiation is also supported (option
4489 `vhdl-use-direct-instantiation').
4491 Configuration declarations can automatically be generated either from
4492 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4493 the speedbar menu (for the architecture under the cursor). The
4494 configurations can optionally be hierarchical (i.e. include all
4495 component levels of a hierarchical design, option
4496 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4497 (option `vhdl-compose-configuration-use-subconfiguration'). For
4498 subcomponents in hierarchical configurations, the most-recently-analyzed
4499 (mra) architecture is selected. If another architecture is desired, it
4500 can be marked as most-recently-analyzed (speedbar menu) before
4501 generating the configuration.
4503 Note: Configurations of subcomponents (i.e. hierarchical configuration
4504 declarations) are currently not considered when displaying
4505 configurations in speedbar.
4507 See the options group `vhdl-compose' for all relevant user options.
4510 SOURCE FILE COMPILATION:
4511 The syntax of the current buffer can be analyzed by calling a VHDL
4512 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4513 option `vhdl-compiler'. The available compilers are listed in option
4514 `vhdl-compiler-alist' including all required compilation command,
4515 command options, compilation directory, and error message syntax
4516 information. New compilers can be added.
4518 All the source files of an entire design can be compiled by the `make'
4519 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4522 MAKEFILE GENERATION:
4523 Makefiles can be generated automatically by an internal generation
4524 routine (`C-c M-k'). The library unit dependency information is
4525 obtained from the hierarchy browser. Makefile generation can be
4526 customized for each compiler in option `vhdl-compiler-alist'.
4528 Makefile generation can also be run non-interactively using the
4529 command:
4531 emacs -batch -l ~/.emacs -l vhdl-mode
4532 [-compiler compilername] [-project projectname]
4533 -f vhdl-generate-makefile
4535 The Makefile's default target \"all\" compiles the entire design, the
4536 target \"clean\" removes it and the target \"library\" creates the
4537 library directory if not existent. These target names can be customized
4538 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4539 target for each primary library unit which allows selective compilation
4540 of this unit, its secondary units and its subhierarchy (example:
4541 compilation of a design specified by a configuration). User specific
4542 parts can be inserted into a Makefile with option
4543 `vhdl-makefile-generation-hook'.
4545 Limitations:
4546 - Only library units and dependencies within the current library are
4547 considered. Makefiles for designs that span multiple libraries are
4548 not (yet) supported.
4549 - Only one-level configurations are supported (also hierarchical),
4550 but configurations that go down several levels are not.
4551 - The \"others\" keyword in configurations is not supported.
4554 PROJECTS:
4555 Projects can be defined in option `vhdl-project-alist' and a current
4556 project be selected using option `vhdl-project' (permanently) or from
4557 the menu or speedbar (temporarily). For each project, title and
4558 description strings (for the file headers), source files/directories
4559 (for the hierarchy browser and Makefile generation), library name, and
4560 compiler-dependent options, exceptions and compilation directory can be
4561 specified. Compilation settings overwrite the settings of option
4562 `vhdl-compiler-alist'.
4564 Project setups can be exported (i.e. written to a file) and imported.
4565 Imported setups are not automatically saved in `vhdl-project-alist' but
4566 can be saved afterwards in its customization buffer. When starting
4567 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4568 vhdl-mode\") in a directory with an existing project setup file, it is
4569 automatically loaded and its project activated if option
4570 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4571 files can be specified in option `vhdl-project-file-name'. Multiple
4572 project setups can be automatically loaded from global directories.
4573 This is an alternative to specifying project setups with option
4574 `vhdl-project-alist'.
4577 SPECIAL MENUES:
4578 As an alternative to the speedbar, an index menu can be added (set
4579 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4580 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4581 file) for browsing the file contents (is not populated if buffer is
4582 larger than `font-lock-maximum-size'). Also, a source file menu can be
4583 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4584 current directory for VHDL source files.
4587 VHDL STANDARDS:
4588 The VHDL standards to be used are specified in option `vhdl-standard'.
4589 Available standards are: VHDL'87/'93(02), VHDL-AMS, and Math Packages.
4592 KEYWORD CASE:
4593 Lower and upper case for keywords and standardized types, attributes,
4594 and enumeration values is supported. If the option
4595 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4596 lower case and are converted into upper case automatically (not for
4597 types, attributes, and enumeration values). The case of keywords,
4598 types, attributes,and enumeration values can be fixed for an entire
4599 region (menu) or buffer (`C-c C-x C-c') according to the options
4600 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4603 HIGHLIGHTING (fontification):
4604 Keywords and standardized types, attributes, enumeration values, and
4605 function names (controlled by option `vhdl-highlight-keywords'), as well
4606 as comments, strings, and template prompts are highlighted using
4607 different colors. Unit, subprogram, signal, variable, constant,
4608 parameter and generic/port names in declarations as well as labels are
4609 highlighted if option `vhdl-highlight-names' is non-nil.
4611 Additional reserved words or words with a forbidden syntax (e.g. words
4612 that should be avoided) can be specified in option
4613 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4614 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4615 keywords are highlighted as forbidden words if option
4616 `vhdl-highlight-verilog-keywords' is non-nil.
4618 Words with special syntax can be highlighted by specifying their
4619 syntax and color in option `vhdl-special-syntax-alist' and by setting
4620 option `vhdl-highlight-special-words' to non-nil. This allows to
4621 establish some naming conventions (e.g. to distinguish different kinds
4622 of signals or other objects by using name suffices) and to support them
4623 visually.
4625 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4626 to support case-sensitive highlighting. However, keywords are then only
4627 highlighted if written in lower case.
4629 Code between \"translate_off\" and \"translate_on\" pragmas is
4630 highlighted using a different background color if option
4631 `vhdl-highlight-translate-off' is non-nil.
4633 For documentation and customization of the used colors see
4634 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4635 highlighting of matching parenthesis, see customization group
4636 `paren-showing'. Automatic buffer highlighting is turned on/off by
4637 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4640 USER MODELS:
4641 VHDL models (templates) can be specified by the user and made accessible
4642 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4643 electrification. See option `vhdl-model-alist'.
4646 HIDE/SHOW:
4647 The code of blocks, processes, subprograms, component declarations and
4648 instantiations, generic/port clauses, and configuration declarations can
4649 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4650 the code (see customization group `vhdl-menu'). XEmacs: limited
4651 functionality due to old `hideshow.el' package.
4654 CODE UPDATING:
4655 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4656 current process, `C-c C-u M-s' of all processes in the current buffer.
4657 Limitations:
4658 - Only declared local signals (ports, signals declared in
4659 architecture and blocks) are automatically inserted.
4660 - Global signals declared in packages are not automatically inserted.
4661 Insert them once manually (will be kept afterwards).
4662 - Out parameters of procedures are considered to be read.
4663 Use option `vhdl-entity-file-name' to specify the entity file name
4664 \(used to obtain the port names).
4665 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4666 specify whether to include array indices and record fields in
4667 sensitivity lists.
4670 CODE FIXING:
4671 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4672 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4675 PRINTING:
4676 PostScript printing with different faces (an optimized set of faces is
4677 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4678 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4679 PostScript printing commands. Option `vhdl-print-two-column' defines
4680 appropriate default settings for nice landscape two-column printing.
4681 The paper format can be set by option `ps-paper-type'. Do not forget to
4682 switch `ps-print-color-p' to nil for printing on black-and-white
4683 printers.
4686 OPTIONS:
4687 User options allow customization of VHDL Mode. All options are
4688 accessible from the \"Options\" menu entry. Simple options (switches
4689 and choices) can directly be changed, while for complex options a
4690 customization buffer is opened. Changed options can be saved for future
4691 sessions using the \"Save Options\" menu entry.
4693 Options and their detailed descriptions can also be accessed by using
4694 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4695 customize-group' for groups). Some customizations only take effect
4696 after some action (read the NOTE in the option documentation).
4697 Customization can also be done globally (i.e. site-wide, read the
4698 INSTALL file).
4700 Not all options are described in this documentation, so go and see
4701 what other useful user options there are (`M-x vhdl-customize' or menu)!
4704 FILE EXTENSIONS:
4705 As default, files with extensions \".vhd\" and \".vhdl\" are
4706 automatically recognized as VHDL source files. To add an extension
4707 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4709 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4712 HINTS:
4713 - To start Emacs with open VHDL hierarchy browser without having to load
4714 a VHDL file first, use the command:
4716 emacs -l vhdl-mode -f speedbar-frame-mode
4718 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4720 - Some features only work on properly indented code.
4723 RELEASE NOTES:
4724 See also the release notes (menu) for added features in new releases.
4727 Maintenance:
4728 ------------
4730 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4731 Add a description of the problem and include a reproducible test case.
4733 Questions and enhancement requests can be sent to <reto@gnu.org>.
4735 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4736 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4737 releases. You are kindly invited to participate in beta testing. Subscribe
4738 to above mailing lists by sending an email to <reto@gnu.org>.
4740 VHDL Mode is officially distributed at
4741 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4742 where the latest version can be found.
4745 Known problems:
4746 ---------------
4748 - XEmacs: Incorrect start-up when automatically opening speedbar.
4749 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4750 - Indentation incorrect for new 'postponed' VHDL keyword.
4751 - Indentation incorrect for 'protected body' construct.
4754 The VHDL Mode Authors
4755 Reto Zimmermann and Rod Whitby
4757 Key bindings:
4758 -------------
4760 \\{vhdl-mode-map}"
4761 :abbrev-table vhdl-mode-abbrev-table
4763 ;; set local variables
4764 (set (make-local-variable 'paragraph-start)
4765 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4766 (set (make-local-variable 'paragraph-separate) paragraph-start)
4767 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4768 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4769 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4770 (set (make-local-variable 'comment-start) "--")
4771 (set (make-local-variable 'comment-end) "")
4772 (when vhdl-emacs-21
4773 (set (make-local-variable 'comment-padding) ""))
4774 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4775 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4776 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4777 (set (make-local-variable 'comment-multi-line) nil)
4778 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4779 (set (make-local-variable 'hippie-expand-verbose) nil)
4781 ;; setup the comment indent variable in a Emacs version portable way
4782 ;; ignore any byte compiler warnings you might get here
4783 (when (boundp 'comment-indent-function)
4784 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
4786 ;; initialize font locking
4787 (set (make-local-variable 'font-lock-defaults)
4788 (list
4789 '(nil vhdl-font-lock-keywords) nil
4790 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4791 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4792 (set (make-local-variable 'syntax-propertize-function)
4793 (syntax-propertize-rules
4794 ;; Mark single quotes as having string quote syntax in
4795 ;; 'c' instances.
4796 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4797 (set (make-local-variable 'font-lock-syntactic-keywords)
4798 vhdl-font-lock-syntactic-keywords))
4799 (unless vhdl-emacs-21
4800 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4801 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4802 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4803 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4804 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4805 ; (turn-on-font-lock)
4807 ;; variables for source file compilation
4808 (when vhdl-compile-use-local-error-regexp
4809 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4810 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4812 ;; add index menu
4813 (vhdl-index-menu-init)
4814 ;; add source file menu
4815 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4816 ;; add VHDL menu
4817 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4818 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4819 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4820 ;; initialize hideshow and add menu
4821 (vhdl-hideshow-init)
4822 (run-hooks 'menu-bar-update-hook)
4824 ;; miscellaneous
4825 (vhdl-ps-print-init)
4826 (vhdl-write-file-hooks-init)
4827 (message "VHDL Mode %s.%s" vhdl-version
4828 (if noninteractive "" " See menu for documentation and release notes.")))
4830 (defun vhdl-activate-customizations ()
4831 "Activate all customizations on local variables."
4832 (interactive)
4833 (vhdl-mode-map-init)
4834 (use-local-map vhdl-mode-map)
4835 (set-syntax-table vhdl-mode-syntax-table)
4836 (setq comment-column vhdl-inline-comment-column)
4837 (setq end-comment-column vhdl-end-comment-column)
4838 (vhdl-write-file-hooks-init)
4839 (vhdl-update-mode-menu)
4840 (vhdl-hideshow-init)
4841 (run-hooks 'menu-bar-update-hook))
4843 (defun vhdl-write-file-hooks-init ()
4844 "Add/remove hooks when buffer is saved."
4845 (if vhdl-modify-date-on-saving
4846 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4847 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4848 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4849 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
4851 (defun vhdl-process-command-line-option (option)
4852 "Process command line options for VHDL Mode."
4853 (cond
4854 ;; set compiler
4855 ((equal option "-compiler")
4856 (vhdl-set-compiler (car command-line-args-left))
4857 (setq command-line-args-left (cdr command-line-args-left)))
4858 ;; set project
4859 ((equal option "-project")
4860 (vhdl-set-project (car command-line-args-left))
4861 (setq command-line-args-left (cdr command-line-args-left)))))
4863 ;; make Emacs process VHDL Mode options
4864 (setq command-switch-alist
4865 (append command-switch-alist
4866 '(("-compiler" . vhdl-process-command-line-option)
4867 ("-project" . vhdl-process-command-line-option))))
4870 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4871 ;;; Keywords and standardized words
4872 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4874 (defconst vhdl-02-keywords
4876 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4877 "assert" "attribute"
4878 "begin" "block" "body" "buffer" "bus"
4879 "case" "component" "configuration" "constant"
4880 "disconnect" "downto"
4881 "else" "elsif" "end" "entity" "exit"
4882 "file" "for" "function"
4883 "generate" "generic" "group" "guarded"
4884 "if" "impure" "in" "inertial" "inout" "is"
4885 "label" "library" "linkage" "literal" "loop"
4886 "map" "mod"
4887 "nand" "new" "next" "nor" "not" "null"
4888 "of" "on" "open" "or" "others" "out"
4889 "package" "port" "postponed" "procedure" "process" "protected" "pure"
4890 "range" "record" "register" "reject" "rem" "report" "return"
4891 "rol" "ror"
4892 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4893 "then" "to" "transport" "type"
4894 "unaffected" "units" "until" "use"
4895 "variable"
4896 "wait" "when" "while" "with"
4897 "xnor" "xor"
4899 "List of VHDL'02 keywords.")
4901 (defconst vhdl-ams-keywords
4903 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4904 "reference" "spectrum" "subnature" "terminal" "through"
4905 "tolerance"
4907 "List of VHDL-AMS keywords.")
4909 (defconst vhdl-verilog-keywords
4911 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4912 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4913 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4914 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4915 "endprimitive" "endspecify" "endtable" "endtask" "event"
4916 "for" "force" "forever" "fork" "function"
4917 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4918 "macromodule" "makefile" "medium" "module"
4919 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4920 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4921 "pullup"
4922 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4923 "rtranif0" "rtranif1"
4924 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4925 "strong1" "supply" "supply0" "supply1"
4926 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4927 "triand" "trior" "trireg"
4928 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4930 "List of Verilog keywords as candidate for additional reserved words.")
4932 (defconst vhdl-02-types
4934 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4935 "real" "time" "natural" "positive" "string" "line" "text" "side"
4936 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4937 "std_logic" "std_logic_vector"
4938 "std_ulogic" "std_ulogic_vector"
4940 "List of VHDL'02 standardized types.")
4942 (defconst vhdl-ams-types
4943 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
4945 ;; package `standard'
4946 "domain_type" "real_vector"
4947 ;; package `energy_systems'
4948 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
4949 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
4950 "real_across_vector" "real_through_vector"
4951 ;; package `electrical_systems'
4952 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
4953 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
4954 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
4955 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
4956 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
4957 "magnetic_flux_vector" "charge_vector" "resistance_vector"
4958 "conductance_vector" "capacitance_vector" "electric_flux_vector"
4959 "electric_flux_density_vector" "electric_field_strength_vector"
4960 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
4961 "inductance_vector" "reluctance_vector" "ground"
4962 ;; package `mechanical_systems'
4963 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
4964 "damping" "momentum" "angle" "torque" "angular_velocity"
4965 "angular_acceleration" "moment_inertia" "angular_momentum"
4966 "angular_stiffness" "angular_damping" "translational"
4967 "translational_vector" "translational_velocity"
4968 "translational_velocity_vector" "rotational" "rotational_vector"
4969 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
4970 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
4971 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
4972 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
4973 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
4974 "angular_momentum_vector" "angular_stiffness_vector"
4975 "angular_damping_vector" "anchor" "translational_v_ref"
4976 "rotational_v_ref" "translational_v" "rotational_v"
4977 ;; package `radiant_systems'
4978 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
4979 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
4980 "illuminance_vector" "irradiance_vector"
4981 ;; package `thermal_systems'
4982 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
4983 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
4984 "heat_flow_vector" "thermal_capacitance_vector"
4985 "thermal_resistance_vector" "thermal_conductance_vector"
4986 ;; package `fluidic_systems'
4987 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
4988 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
4989 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
4990 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
4991 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
4992 "density_vector" "viscosity_vector" "fresistance_vector"
4993 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
4994 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
4995 "cfinertance_vector"
4997 "List of VHDL-AMS standardized types.")
4999 (defconst vhdl-math-types
5001 "complex" "complex_polar" "positive_real" "principal_value"
5003 "List of Math Packages standardized types.")
5005 (defconst vhdl-02-attributes
5007 "base" "left" "right" "high" "low" "pos" "val" "succ"
5008 "pred" "leftof" "rightof" "range" "reverse_range"
5009 "length" "delayed" "stable" "quiet" "transaction"
5010 "event" "active" "last_event" "last_active" "last_value"
5011 "driving" "driving_value" "ascending" "value" "image"
5012 "simple_name" "instance_name" "path_name"
5013 "foreign"
5015 "List of VHDL'02 standardized attributes.")
5017 (defconst vhdl-ams-attributes
5019 "across" "through"
5020 "reference" "contribution" "tolerance"
5021 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5022 "ramp" "slew"
5024 "List of VHDL-AMS standardized attributes.")
5026 (defconst vhdl-02-enum-values
5028 "true" "false"
5029 "note" "warning" "error" "failure"
5030 "read_mode" "write_mode" "append_mode"
5031 "open_ok" "status_error" "name_error" "mode_error"
5032 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5033 "right" "left"
5035 "List of VHDL'02 standardized enumeration values.")
5037 (defconst vhdl-ams-enum-values
5039 "quiescent_domain" "time_domain" "frequency_domain"
5040 ;; from `nature_pkg' package
5041 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5043 "List of VHDL-AMS standardized enumeration values.")
5045 (defconst vhdl-ams-constants
5046 ;; standard: IEEE Std 1076.1.1-2004
5048 ;; package `fundamental_constants'
5049 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5050 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5051 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5052 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5053 ;; package `material_constants'
5054 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5055 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5056 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5058 "List of VHDL-AMS standardized constants.")
5060 (defconst vhdl-math-constants
5061 ;; standard: IEEE Std 1076.2-1996
5063 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5064 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5065 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5066 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5067 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5068 "math_sqrt_pi"
5070 "List of Math Packages standardized constants.")
5072 (defconst vhdl-02-functions
5074 "now" "resolved" "rising_edge" "falling_edge"
5075 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5076 "endfile"
5077 "resize" "is_X" "std_match"
5078 "shift_left" "shift_right" "rotate_left" "rotate_right"
5079 "to_unsigned" "to_signed" "to_integer"
5080 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5081 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5082 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5083 "shl" "shr" "ext" "sxt"
5084 "deallocate"
5086 "List of VHDL'02 standardized functions.")
5088 (defconst vhdl-ams-functions
5090 ;; package `standard'
5091 "frequency"
5093 "List of VHDL-AMS standardized functions.")
5095 (defconst vhdl-math-functions
5096 ;; standard: IEEE Std 1076.2-1996
5098 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5099 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5100 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5101 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5102 "tan" "tanh" "trunc" "uniform"
5104 "List of Math Packages standardized functions.")
5106 (defconst vhdl-02-packages
5108 "std_logic_1164" "numeric_std" "numeric_bit"
5109 "standard" "textio"
5110 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5111 "std_logic_misc" "std_logic_textio"
5112 "ieee" "std" "work"
5114 "List of VHDL'02 standardized packages and libraries.")
5116 (defconst vhdl-ams-packages
5118 "fundamental_constants" "material_constants" "energy_systems"
5119 "electrical_systems" "mechanical_systems" "radiant_systems"
5120 "thermal_systems" "fluidic_systems"
5122 "List of VHDL-AMS standardized packages and libraries.")
5124 (defconst vhdl-math-packages
5126 "math_real" "math_complex"
5128 "List of Math Packages standardized packages and libraries.")
5130 (defvar vhdl-keywords nil
5131 "List of VHDL keywords.")
5133 (defvar vhdl-types nil
5134 "List of VHDL standardized types.")
5136 (defvar vhdl-attributes nil
5137 "List of VHDL standardized attributes.")
5139 (defvar vhdl-enum-values nil
5140 "List of VHDL standardized enumeration values.")
5142 (defvar vhdl-constants nil
5143 "List of VHDL standardized constants.")
5145 (defvar vhdl-functions nil
5146 "List of VHDL standardized functions.")
5148 (defvar vhdl-packages nil
5149 "List of VHDL standardized packages and libraries.")
5151 (defvar vhdl-reserved-words nil
5152 "List of additional reserved words.")
5154 (defvar vhdl-keywords-regexp nil
5155 "Regexp for VHDL keywords.")
5157 (defvar vhdl-types-regexp nil
5158 "Regexp for VHDL standardized types.")
5160 (defvar vhdl-attributes-regexp nil
5161 "Regexp for VHDL standardized attributes.")
5163 (defvar vhdl-enum-values-regexp nil
5164 "Regexp for VHDL standardized enumeration values.")
5166 (defvar vhdl-constants-regexp nil
5167 "Regexp for VHDL standardized constants.")
5169 (defvar vhdl-functions-regexp nil
5170 "Regexp for VHDL standardized functions.")
5172 (defvar vhdl-packages-regexp nil
5173 "Regexp for VHDL standardized packages and libraries.")
5175 (defvar vhdl-reserved-words-regexp nil
5176 "Regexp for additional reserved words.")
5178 (defvar vhdl-directive-keywords-regexp nil
5179 "Regexp for compiler directive keywords.")
5181 (defun vhdl-upcase-list (condition list)
5182 "Upcase all elements in LIST based on CONDITION."
5183 (when condition
5184 (let ((tmp-list list))
5185 (while tmp-list
5186 (setcar tmp-list (upcase (car tmp-list)))
5187 (setq tmp-list (cdr tmp-list)))))
5188 list)
5190 (defun vhdl-words-init ()
5191 "Initialize reserved words."
5192 (setq vhdl-keywords
5193 (vhdl-upcase-list
5194 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
5195 (append vhdl-02-keywords
5196 (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
5197 (setq vhdl-types
5198 (vhdl-upcase-list
5199 (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
5200 (append vhdl-02-types
5201 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5202 (when (vhdl-standard-p 'math) vhdl-math-types))))
5203 (setq vhdl-attributes
5204 (vhdl-upcase-list
5205 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
5206 (append vhdl-02-attributes
5207 (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
5208 (setq vhdl-enum-values
5209 (vhdl-upcase-list
5210 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
5211 (append vhdl-02-enum-values
5212 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
5213 (setq vhdl-constants
5214 (vhdl-upcase-list
5215 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
5216 (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
5217 (when (vhdl-standard-p 'math) vhdl-math-constants)
5218 '(""))))
5219 (setq vhdl-functions
5220 (append vhdl-02-functions
5221 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5222 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5223 (setq vhdl-packages
5224 (append vhdl-02-packages
5225 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5226 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5227 (setq vhdl-reserved-words
5228 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5229 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5230 '("")))
5231 (setq vhdl-keywords-regexp
5232 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5233 (setq vhdl-types-regexp
5234 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5235 (setq vhdl-attributes-regexp
5236 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5237 (setq vhdl-enum-values-regexp
5238 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5239 (setq vhdl-constants-regexp
5240 (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
5241 (setq vhdl-functions-regexp
5242 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5243 (setq vhdl-packages-regexp
5244 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5245 (setq vhdl-reserved-words-regexp
5246 (concat "\\<\\("
5247 (unless (equal vhdl-forbidden-syntax "")
5248 (concat vhdl-forbidden-syntax "\\|"))
5249 (regexp-opt vhdl-reserved-words)
5250 "\\)\\>"))
5251 (setq vhdl-directive-keywords-regexp
5252 (concat "\\<\\(" (mapconcat 'regexp-quote
5253 vhdl-directive-keywords "\\|") "\\)\\>"))
5254 (vhdl-abbrev-list-init))
5256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5257 ;; Words to expand
5259 (defvar vhdl-abbrev-list nil
5260 "Predefined abbreviations for VHDL.")
5262 (defun vhdl-abbrev-list-init ()
5263 (setq vhdl-abbrev-list
5264 (append
5265 (list vhdl-upper-case-keywords) vhdl-keywords
5266 (list vhdl-upper-case-types) vhdl-types
5267 (list vhdl-upper-case-attributes) vhdl-attributes
5268 (list vhdl-upper-case-enum-values) vhdl-enum-values
5269 (list vhdl-upper-case-constants) vhdl-constants
5270 (list nil) vhdl-functions
5271 (list nil) vhdl-packages)))
5273 ;; initialize reserved words for VHDL Mode
5274 (vhdl-words-init)
5277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5278 ;;; Indentation
5279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5282 ;; Syntax analysis
5284 ;; constant regular expressions for looking at various constructs
5286 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5287 "Regexp describing a VHDL symbol.
5288 We cannot use just `word' syntax class since `_' cannot be in word
5289 class. Putting underscore in word class breaks forward word movement
5290 behavior that users are familiar with.")
5292 (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5293 "Regexp describing a case statement header key.")
5295 (defconst vhdl-label-key
5296 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5297 "Regexp describing a VHDL label.")
5299 ;; Macro definitions:
5301 (defmacro vhdl-point (position)
5302 "Return the value of point at certain commonly referenced POSITIONs.
5303 POSITION can be one of the following symbols:
5305 bol -- beginning of line
5306 eol -- end of line
5307 bod -- beginning of defun
5308 boi -- back to indentation
5309 eoi -- last whitespace on line
5310 ionl -- indentation of next line
5311 iopl -- indentation of previous line
5312 bonl -- beginning of next line
5313 bopl -- beginning of previous line
5315 This function does not modify point or mark."
5316 (or (and (eq 'quote (car-safe position))
5317 (null (cddr position)))
5318 (error "ERROR: Bad buffer position requested: %s" position))
5319 (setq position (nth 1 position))
5320 `(let ((here (point)))
5321 ,@(cond
5322 ((eq position 'bol) '((beginning-of-line)))
5323 ((eq position 'eol) '((end-of-line)))
5324 ((eq position 'bod) '((save-match-data
5325 (vhdl-beginning-of-defun))))
5326 ((eq position 'boi) '((back-to-indentation)))
5327 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5328 ((eq position 'bonl) '((forward-line 1)))
5329 ((eq position 'bopl) '((forward-line -1)))
5330 ((eq position 'iopl)
5331 '((forward-line -1)
5332 (back-to-indentation)))
5333 ((eq position 'ionl)
5334 '((forward-line 1)
5335 (back-to-indentation)))
5336 (t (error "ERROR: Unknown buffer position requested: %s" position))
5338 (prog1
5339 (point)
5340 (goto-char here))
5341 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5342 ;; doesn't hurt for v19
5343 ,@nil
5346 (defmacro vhdl-safe (&rest body)
5347 "Safely execute BODY, return nil if an error occurred."
5348 `(condition-case nil
5349 (progn ,@body)
5350 (error nil)))
5352 (defmacro vhdl-add-syntax (symbol &optional relpos)
5353 "A simple macro to append the syntax in SYMBOL to the syntax list.
5354 Try to increase performance by using this macro."
5355 `(setq vhdl-syntactic-context
5356 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5358 (defmacro vhdl-has-syntax (symbol)
5359 "A simple macro to return check the syntax list.
5360 Try to increase performance by using this macro."
5361 `(assoc ,symbol vhdl-syntactic-context))
5363 ;; Syntactic element offset manipulation:
5365 (defun vhdl-read-offset (langelem)
5366 "Read new offset value for LANGELEM from minibuffer.
5367 Return a valid value only."
5368 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5369 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5370 (prompt "Offset: ")
5371 offset input interned)
5372 (while (not offset)
5373 (setq input (read-string prompt oldoff)
5374 offset (cond ((string-equal "+" input) '+)
5375 ((string-equal "-" input) '-)
5376 ((string-equal "++" input) '++)
5377 ((string-equal "--" input) '--)
5378 ((string-match "^-?[0-9]+$" input)
5379 (string-to-number input))
5380 ((fboundp (setq interned (intern input)))
5381 interned)
5382 ((boundp interned) interned)
5383 ;; error, but don't signal one, keep trying
5384 ;; to read an input value
5385 (t (ding)
5386 (setq prompt errmsg)
5387 nil))))
5388 offset))
5390 (defun vhdl-set-offset (symbol offset &optional add-p)
5391 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5392 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5393 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5394 `vhdl-offsets-alist' if it doesn't already appear there."
5395 (interactive
5396 (let* ((langelem
5397 (intern (completing-read
5398 (concat "Syntactic symbol to change"
5399 (if current-prefix-arg " or add" "")
5400 ": ")
5401 (mapcar
5402 (function
5403 (lambda (langelem)
5404 (cons (format "%s" (car langelem)) nil)))
5405 vhdl-offsets-alist)
5406 nil (not current-prefix-arg)
5407 ;; initial contents tries to be the last element
5408 ;; on the syntactic analysis list for the current
5409 ;; line
5410 (let* ((syntax (vhdl-get-syntactic-context))
5411 (len (length syntax))
5412 (ic (format "%s" (car (nth (1- len) syntax)))))
5415 (offset (vhdl-read-offset langelem)))
5416 (list langelem offset current-prefix-arg)))
5417 ;; sanity check offset
5418 (or (eq offset '+)
5419 (eq offset '-)
5420 (eq offset '++)
5421 (eq offset '--)
5422 (integerp offset)
5423 (fboundp offset)
5424 (boundp offset)
5425 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5426 offset))
5427 (let ((entry (assq symbol vhdl-offsets-alist)))
5428 (if entry
5429 (setcdr entry offset)
5430 (if add-p
5431 (setq vhdl-offsets-alist
5432 (cons (cons symbol offset) vhdl-offsets-alist))
5433 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5434 (vhdl-keep-region-active))
5436 (defun vhdl-set-style (style &optional local)
5437 "Set `vhdl-mode' variables to use one of several different indentation styles.
5438 STYLE is a string representing the desired style and optional LOCAL is
5439 a flag which, if non-nil, means to make the style variables being
5440 changed buffer local, instead of the default, which is to set the
5441 global variables. Interactively, the flag comes from the prefix
5442 argument. The styles are chosen from the `vhdl-style-alist' variable."
5443 (interactive (list (completing-read "Use which VHDL indentation style? "
5444 vhdl-style-alist nil t)
5445 current-prefix-arg))
5446 (let ((vars (cdr (assoc style vhdl-style-alist))))
5447 (or vars
5448 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5449 ;; set all the variables
5450 (mapc
5451 (function
5452 (lambda (varentry)
5453 (let ((var (car varentry))
5454 (val (cdr varentry)))
5455 ;; special case for vhdl-offsets-alist
5456 (if (not (eq var 'vhdl-offsets-alist))
5457 (set (if local (make-local-variable var) var) val)
5458 ;; reset vhdl-offsets-alist to the default value first
5459 (set (if local (make-local-variable var) var)
5460 (copy-alist vhdl-offsets-alist-default))
5461 ;; now set the langelems that are different
5462 (mapcar
5463 (function
5464 (lambda (langentry)
5465 (let ((langelem (car langentry))
5466 (offset (cdr langentry)))
5467 (vhdl-set-offset langelem offset)
5469 val))
5471 vars))
5472 (vhdl-keep-region-active))
5474 (defun vhdl-get-offset (langelem)
5475 "Get offset from LANGELEM which is a cons cell of the form:
5476 \(SYMBOL . RELPOS). The symbol is matched against
5477 vhdl-offsets-alist and the offset found there is either returned,
5478 or added to the indentation at RELPOS. If RELPOS is nil, then
5479 the offset is simply returned."
5480 (let* ((symbol (car langelem))
5481 (relpos (cdr langelem))
5482 (match (assq symbol vhdl-offsets-alist))
5483 (offset (cdr-safe match)))
5484 ;; offset can be a number, a function, a variable, or one of the
5485 ;; symbols + or -
5486 (cond
5487 ((not match)
5488 (if vhdl-strict-syntax-p
5489 (error "ERROR: Don't know how to indent a %s" symbol)
5490 (setq offset 0
5491 relpos 0)))
5492 ((eq offset '+) (setq offset vhdl-basic-offset))
5493 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5494 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5495 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5496 ((and (not (numberp offset))
5497 (fboundp offset))
5498 (setq offset (funcall offset langelem)))
5499 ((not (numberp offset))
5500 (setq offset (eval offset)))
5502 (+ (if (and relpos
5503 (< relpos (vhdl-point 'bol)))
5504 (save-excursion
5505 (goto-char relpos)
5506 (current-column))
5508 offset)))
5510 ;; Syntactic support functions:
5512 (defun vhdl-in-comment-p ()
5513 "Check if point is in a comment."
5514 (eq (vhdl-in-literal) 'comment))
5516 (defun vhdl-in-string-p ()
5517 "Check if point is in a string."
5518 (eq (vhdl-in-literal) 'string))
5520 (defun vhdl-in-quote-p ()
5521 "Check if point is in a quote ('x')."
5522 (or (and (> (point) (point-min))
5523 (< (1+ (point)) (point-max))
5524 (= (char-before (point)) ?\')
5525 (= (char-after (1+ (point))) ?\'))
5526 (and (> (1- (point)) (point-min))
5527 (< (point) (point-max))
5528 (= (char-before (1- (point))) ?\')
5529 (= (char-after (point)) ?\'))))
5531 (defun vhdl-in-literal ()
5532 "Determine if point is in a VHDL literal."
5533 (save-excursion
5534 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5535 (cond
5536 ((nth 3 state) 'string)
5537 ((nth 4 state) 'comment)
5538 ((vhdl-beginning-of-macro) 'pound)
5539 (t nil)))))
5541 (defun vhdl-in-extended-identifier-p ()
5542 "Determine if point is inside extended identifier (delimited by '\')."
5543 (save-match-data
5544 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
5545 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
5547 (defun vhdl-forward-comment (&optional direction)
5548 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5549 negative, skip forward otherwise."
5550 (interactive "p")
5551 (if (and direction (< direction 0))
5552 ;; skip backwards
5553 (progn
5554 (skip-chars-backward " \t\n\r\f")
5555 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5556 (goto-char (match-beginning 3))
5557 (skip-chars-backward " \t\n\r\f")))
5558 ;; skip forwards
5559 (skip-chars-forward " \t\n\r\f")
5560 (while (looking-at "--.*")
5561 (goto-char (match-end 0))
5562 (skip-chars-forward " \t\n\r\f"))))
5564 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5565 (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
5566 (defalias 'vhdl-forward-comment 'forward-comment))
5568 (defun vhdl-back-to-indentation ()
5569 "Move point to the first non-whitespace character on this line."
5570 (interactive)
5571 (beginning-of-line 1)
5572 (skip-syntax-forward " " (vhdl-point 'eol)))
5574 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5575 (when (featurep 'xemacs)
5576 (defalias 'back-to-indentation 'vhdl-back-to-indentation))
5578 ;; This is the best we can do in Win-Emacs.
5579 (defun vhdl-win-il (&optional lim)
5580 "Determine if point is in a VHDL literal."
5581 (save-excursion
5582 (let* ((here (point))
5583 (state nil)
5584 (match nil)
5585 (lim (or lim (vhdl-point 'bod))))
5586 (goto-char lim )
5587 (while (< (point) here)
5588 (setq match
5589 (and (re-search-forward "--\\|[\"']"
5590 here 'move)
5591 (buffer-substring (match-beginning 0) (match-end 0))))
5592 (setq state
5593 (cond
5594 ;; no match
5595 ((null match) nil)
5596 ;; looking at the opening of a VHDL style comment
5597 ((string= "--" match)
5598 (if (<= here (progn (end-of-line) (point))) 'comment))
5599 ;; looking at the opening of a double quote string
5600 ((string= "\"" match)
5601 (if (not (save-restriction
5602 ;; this seems to be necessary since the
5603 ;; re-search-forward will not work without it
5604 (narrow-to-region (point) here)
5605 (re-search-forward
5606 ;; this regexp matches a double quote
5607 ;; which is preceded by an even number
5608 ;; of backslashes, including zero
5609 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5610 'string))
5611 ;; looking at the opening of a single quote string
5612 ((string= "'" match)
5613 (if (not (save-restriction
5614 ;; see comments from above
5615 (narrow-to-region (point) here)
5616 (re-search-forward
5617 ;; this matches a single quote which is
5618 ;; preceded by zero or two backslashes.
5619 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5620 here 'move)))
5621 'string))
5622 (t nil)))
5623 ) ; end-while
5624 state)))
5626 (and (string-match "Win-Emacs" emacs-version)
5627 (fset 'vhdl-in-literal 'vhdl-win-il))
5629 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5630 ;; defined as lexical whitespace or comments. Search no farther back
5631 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5632 ;; used for backward skipping, (point-max) is used for forward
5633 ;; skipping.
5635 (defun vhdl-forward-syntactic-ws (&optional lim)
5636 "Forward skip of syntactic whitespace."
5637 (let* ((here (point-max))
5638 (hugenum (point-max)))
5639 (while (/= here (point))
5640 (setq here (point))
5641 (vhdl-forward-comment hugenum)
5642 ;; skip preprocessor directives
5643 (when (and (eq (char-after) ?#)
5644 (= (vhdl-point 'boi) (point)))
5645 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5646 (= (forward-line 1) 0)))
5647 (end-of-line)))
5648 (if lim (goto-char (min (point) lim)))))
5651 ;; This is the best we can do in Win-Emacs.
5652 (defun vhdl-win-fsws (&optional lim)
5653 "Forward skip syntactic whitespace for Win-Emacs."
5654 (let ((lim (or lim (point-max)))
5655 stop)
5656 (while (not stop)
5657 (skip-chars-forward " \t\n\r\f" lim)
5658 (cond
5659 ;; vhdl comment
5660 ((looking-at "--") (end-of-line))
5661 ;; none of the above
5662 (t (setq stop t))))))
5664 (and (string-match "Win-Emacs" emacs-version)
5665 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5667 (defun vhdl-beginning-of-macro (&optional lim)
5668 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5669 (let ((here (point)))
5670 (beginning-of-line)
5671 (while (eq (char-before (1- (point))) ?\\)
5672 (forward-line -1))
5673 (back-to-indentation)
5674 (if (and (<= (point) here)
5675 (eq (char-after) ?#))
5677 (goto-char here)
5678 nil)))
5680 (defun vhdl-backward-syntactic-ws (&optional lim)
5681 "Backward skip over syntactic whitespace."
5682 (let* ((here (point-min))
5683 (hugenum (- (point-max))))
5684 (while (/= here (point))
5685 (setq here (point))
5686 (vhdl-forward-comment hugenum)
5687 (vhdl-beginning-of-macro))
5688 (if lim (goto-char (max (point) lim)))))
5690 ;; This is the best we can do in Win-Emacs.
5691 (defun vhdl-win-bsws (&optional lim)
5692 "Backward skip syntactic whitespace for Win-Emacs."
5693 (let ((lim (or lim (vhdl-point 'bod)))
5694 stop)
5695 (while (not stop)
5696 (skip-chars-backward " \t\n\r\f" lim)
5697 (cond
5698 ;; vhdl comment
5699 ((eq (vhdl-in-literal) 'comment)
5700 (skip-chars-backward "^-" lim)
5701 (skip-chars-backward "-" lim)
5702 (while (not (or (and (= (following-char) ?-)
5703 (= (char-after (1+ (point))) ?-))
5704 (<= (point) lim)))
5705 (skip-chars-backward "^-" lim)
5706 (skip-chars-backward "-" lim)))
5707 ;; none of the above
5708 (t (setq stop t))))))
5710 (and (string-match "Win-Emacs" emacs-version)
5711 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5713 ;; Functions to help finding the correct indentation column:
5715 (defun vhdl-first-word (point)
5716 "If the keyword at POINT is at boi, then return (current-column) at
5717 that point, else nil."
5718 (save-excursion
5719 (and (goto-char point)
5720 (eq (point) (vhdl-point 'boi))
5721 (current-column))))
5723 (defun vhdl-last-word (point)
5724 "If the keyword at POINT is at eoi, then return (current-column) at
5725 that point, else nil."
5726 (save-excursion
5727 (and (goto-char point)
5728 (save-excursion (or (eq (progn (forward-sexp) (point))
5729 (vhdl-point 'eoi))
5730 (looking-at "\\s-*\\(--\\)?")))
5731 (current-column))))
5733 ;; Core syntactic evaluation functions:
5735 (defconst vhdl-libunit-re
5736 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5738 (defun vhdl-libunit-p ()
5739 (and
5740 (save-excursion
5741 (forward-sexp)
5742 (skip-chars-forward " \t\n\r\f")
5743 (not (looking-at "is\\b[^_]")))
5744 (save-excursion
5745 (backward-sexp)
5746 (and (not (looking-at "use\\b[^_]"))
5747 (progn
5748 (forward-sexp)
5749 (vhdl-forward-syntactic-ws)
5750 (/= (following-char) ?:))))
5753 (defconst vhdl-defun-re
5754 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5756 (defun vhdl-defun-p ()
5757 (save-excursion
5758 (if (looking-at "block\\|process\\|procedural")
5759 ;; "block", "process", "procedural":
5760 (save-excursion
5761 (backward-sexp)
5762 (not (looking-at "end\\s-+\\w")))
5763 ;; "architecture", "configuration", "entity",
5764 ;; "package", "procedure", "function":
5765 t)))
5767 (defun vhdl-corresponding-defun ()
5768 "If the word at the current position corresponds to a \"defun\"
5769 keyword, then return a string that can be used to find the
5770 corresponding \"begin\" keyword, else return nil."
5771 (save-excursion
5772 (and (looking-at vhdl-defun-re)
5773 (vhdl-defun-p)
5774 (if (looking-at "block\\|process\\|procedural")
5775 ;; "block", "process". "procedural:
5776 (buffer-substring (match-beginning 0) (match-end 0))
5777 ;; "architecture", "configuration", "entity", "package",
5778 ;; "procedure", "function":
5779 "is"))))
5781 (defconst vhdl-begin-fwd-re
5782 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5783 "A regular expression for searching forward that matches all known
5784 \"begin\" keywords.")
5786 (defconst vhdl-begin-bwd-re
5787 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5788 "A regular expression for searching backward that matches all known
5789 \"begin\" keywords.")
5791 (defun vhdl-begin-p (&optional lim)
5792 "Return t if we are looking at a real \"begin\" keyword.
5793 Assumes that the caller will make sure that we are looking at
5794 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5795 the middle of an identifier that just happens to contain a \"begin\"
5796 keyword."
5797 (cond
5798 ;; "[architecture|case|configuration|entity|package|
5799 ;; procedure|function] ... is":
5800 ((and (looking-at "i")
5801 (save-excursion
5802 ;; Skip backward over first sexp (needed to skip over a
5803 ;; procedure interface list, and is harmless in other
5804 ;; situations). Note that we need "return" in the
5805 ;; following search list so that we don't run into
5806 ;; semicolons in the function interface list.
5807 (backward-sexp)
5808 (let (foundp)
5809 (while (and (not foundp)
5810 (re-search-backward
5811 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5812 lim 'move))
5813 (if (or (= (preceding-char) ?_)
5814 (vhdl-in-literal))
5815 (backward-char)
5816 (setq foundp t))))
5817 (and (/= (following-char) ?\;)
5818 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5820 ;; "begin", "then", "use":
5821 ((looking-at "be\\|t\\|use")
5823 ;; "else":
5824 ((and (looking-at "e")
5825 ;; make sure that the "else" isn't inside a
5826 ;; conditional signal assignment.
5827 (save-excursion
5828 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5829 (or (eq (following-char) ?\;)
5830 (eq (point) lim))))
5832 ;; "block", "generate", "loop", "process", "procedural",
5833 ;; "units", "record", "protected body":
5834 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
5835 (save-excursion
5836 (backward-sexp)
5837 (not (looking-at "end\\s-+\\w"))))
5839 ;; "component":
5840 ((and (looking-at "c")
5841 (save-excursion
5842 (backward-sexp)
5843 (not (looking-at "end\\s-+\\w")))
5844 ;; look out for the dreaded entity class in an attribute
5845 (save-excursion
5846 (vhdl-backward-syntactic-ws lim)
5847 (/= (preceding-char) ?:)))
5849 ;; "for" (inside configuration declaration):
5850 ((and (looking-at "f")
5851 (save-excursion
5852 (backward-sexp)
5853 (not (looking-at "end\\s-+\\w")))
5854 (vhdl-has-syntax 'configuration))
5858 (defun vhdl-corresponding-mid (&optional lim)
5859 (cond
5860 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5861 "begin")
5862 ((looking-at "then\\|use")
5863 "<else>")
5865 "end")))
5867 (defun vhdl-corresponding-end (&optional lim)
5868 "If the word at the current position corresponds to a \"begin\"
5869 keyword, then return a vector containing enough information to find
5870 the corresponding \"end\" keyword, else return nil. The keyword to
5871 search forward for is aref 0. The column in which the keyword must
5872 appear is aref 1 or nil if any column is suitable.
5873 Assumes that the caller will make sure that we are not in the middle
5874 of an identifier that just happens to contain a \"begin\" keyword."
5875 (save-excursion
5876 (and (looking-at vhdl-begin-fwd-re)
5877 (or (not (looking-at "\\<use\\>"))
5878 (save-excursion (back-to-indentation)
5879 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
5880 (/= (preceding-char) ?_)
5881 (not (vhdl-in-literal))
5882 (vhdl-begin-p lim)
5883 (cond
5884 ;; "is", "generate", "loop":
5885 ((looking-at "[igl]")
5886 (vector "end"
5887 (and (vhdl-last-word (point))
5888 (or (vhdl-first-word (point))
5889 (save-excursion
5890 (vhdl-beginning-of-statement-1 lim)
5891 (vhdl-backward-skip-label lim)
5892 (vhdl-first-word (point)))))))
5893 ;; "begin", "else", "for":
5894 ((looking-at "be\\|[ef]")
5895 (vector "end"
5896 (and (vhdl-last-word (point))
5897 (or (vhdl-first-word (point))
5898 (save-excursion
5899 (vhdl-beginning-of-statement-1 lim)
5900 (vhdl-backward-skip-label lim)
5901 (vhdl-first-word (point)))))))
5902 ;; "component", "units", "record", "protected body":
5903 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
5904 ;; The first end found will close the block
5905 (vector "end" nil))
5906 ;; "block", "process", "procedural":
5907 ((looking-at "bl\\|p")
5908 (vector "end"
5909 (or (vhdl-first-word (point))
5910 (save-excursion
5911 (vhdl-beginning-of-statement-1 lim)
5912 (vhdl-backward-skip-label lim)
5913 (vhdl-first-word (point))))))
5914 ;; "then":
5915 ((looking-at "t\\|use")
5916 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
5917 (and (vhdl-last-word (point))
5918 (or (vhdl-first-word (point))
5919 (save-excursion
5920 (vhdl-beginning-of-statement-1 lim)
5921 (vhdl-backward-skip-label lim)
5922 (vhdl-first-word (point)))))))
5923 ))))
5925 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5927 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5929 (defun vhdl-end-p (&optional lim)
5930 "Return t if we are looking at a real \"end\" keyword.
5931 Assumes that the caller will make sure that we are looking at
5932 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5933 the middle of an identifier that just happens to contain an \"end\"
5934 keyword."
5935 (or (not (looking-at "else"))
5936 ;; make sure that the "else" isn't inside a conditional signal
5937 ;; assignment.
5938 (save-excursion
5939 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5940 (or (eq (following-char) ?\;)
5941 (eq (point) lim)
5942 (vhdl-in-literal)))))
5944 (defun vhdl-corresponding-begin (&optional lim)
5945 "If the word at the current position corresponds to an \"end\"
5946 keyword, then return a vector containing enough information to find
5947 the corresponding \"begin\" keyword, else return nil. The keyword to
5948 search backward for is aref 0. The column in which the keyword must
5949 appear is aref 1 or nil if any column is suitable. The supplementary
5950 keyword to search forward for is aref 2 or nil if this is not
5951 required. If aref 3 is t, then the \"begin\" keyword may be found in
5952 the middle of a statement.
5953 Assumes that the caller will make sure that we are not in the middle
5954 of an identifier that just happens to contain an \"end\" keyword."
5955 (save-excursion
5956 (let (pos)
5957 (if (and (looking-at vhdl-end-fwd-re)
5958 (not (vhdl-in-literal))
5959 (vhdl-end-p lim))
5960 (if (looking-at "el")
5961 ;; "else", "elsif":
5962 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
5963 ;; "end ...":
5964 (setq pos (point))
5965 (forward-sexp)
5966 (skip-chars-forward " \t\n\r\f")
5967 (cond
5968 ;; "end if":
5969 ((looking-at "if\\b[^_]")
5970 (vector "else\\|elsif\\|if"
5971 (vhdl-first-word pos)
5972 "else\\|then\\|use" nil))
5973 ;; "end component":
5974 ((looking-at "component\\b[^_]")
5975 (vector (buffer-substring (match-beginning 1)
5976 (match-end 1))
5977 (vhdl-first-word pos)
5978 nil nil))
5979 ;; "end units", "end record", "end protected":
5980 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
5981 (vector (buffer-substring (match-beginning 1)
5982 (match-end 1))
5983 (vhdl-first-word pos)
5984 nil t))
5985 ;; "end block", "end process", "end procedural":
5986 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5987 (vector "begin" (vhdl-first-word pos) nil nil))
5988 ;; "end case":
5989 ((looking-at "case\\b[^_]")
5990 (vector "case" (vhdl-first-word pos) "is" nil))
5991 ;; "end generate":
5992 ((looking-at "generate\\b[^_]")
5993 (vector "generate\\|for\\|if"
5994 (vhdl-first-word pos)
5995 "generate" nil))
5996 ;; "end loop":
5997 ((looking-at "loop\\b[^_]")
5998 (vector "loop\\|while\\|for"
5999 (vhdl-first-word pos)
6000 "loop" nil))
6001 ;; "end for" (inside configuration declaration):
6002 ((looking-at "for\\b[^_]")
6003 (vector "for" (vhdl-first-word pos) nil nil))
6004 ;; "end [id]":
6006 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
6007 (vhdl-first-word pos)
6008 ;; return an alist of (statement . keyword) mappings
6010 ;; "begin ... end [id]":
6011 ("begin" . nil)
6012 ;; "architecture ... is ... begin ... end [id]":
6013 ("architecture" . "is")
6014 ;; "configuration ... is ... end [id]":
6015 ("configuration" . "is")
6016 ;; "entity ... is ... end [id]":
6017 ("entity" . "is")
6018 ;; "package ... is ... end [id]":
6019 ("package" . "is")
6020 ;; "procedure ... is ... begin ... end [id]":
6021 ("procedure" . "is")
6022 ;; "function ... is ... begin ... end [id]":
6023 ("function" . "is")
6025 nil))
6026 ))) ; "end ..."
6029 (defconst vhdl-leader-re
6030 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6032 (defun vhdl-end-of-leader ()
6033 (save-excursion
6034 (cond ((looking-at "block\\|process\\|procedural")
6035 (if (save-excursion
6036 (forward-sexp)
6037 (skip-chars-forward " \t\n\r\f")
6038 (= (following-char) ?\())
6039 (forward-sexp 2)
6040 (forward-sexp))
6041 (when (looking-at "[ \t\n\r\f]*is")
6042 (goto-char (match-end 0)))
6043 (point))
6044 ((looking-at "component")
6045 (forward-sexp 2)
6046 (when (looking-at "[ \t\n\r\f]*is")
6047 (goto-char (match-end 0)))
6048 (point))
6049 ((looking-at "for")
6050 (forward-sexp 2)
6051 (skip-chars-forward " \t\n\r\f")
6052 (while (looking-at "[,:(]")
6053 (forward-sexp)
6054 (skip-chars-forward " \t\n\r\f"))
6055 (point))
6056 (t nil)
6059 (defconst vhdl-trailer-re
6060 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6062 (defconst vhdl-statement-fwd-re
6063 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6064 "A regular expression for searching forward that matches all known
6065 \"statement\" keywords.")
6067 (defconst vhdl-statement-bwd-re
6068 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6069 "A regular expression for searching backward that matches all known
6070 \"statement\" keywords.")
6072 (defun vhdl-statement-p (&optional lim)
6073 "Return t if we are looking at a real \"statement\" keyword.
6074 Assumes that the caller will make sure that we are looking at
6075 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6076 in the middle of an identifier that just happens to contain a
6077 \"statement\" keyword."
6078 (cond
6079 ;; "for" ... "generate":
6080 ((and (looking-at "f")
6081 ;; Make sure it's the start of a parameter specification.
6082 (save-excursion
6083 (forward-sexp 2)
6084 (skip-chars-forward " \t\n\r\f")
6085 (looking-at "in\\b[^_]"))
6086 ;; Make sure it's not an "end for".
6087 (save-excursion
6088 (backward-sexp)
6089 (not (looking-at "end\\s-+\\w"))))
6091 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6092 ((and (looking-at "i")
6093 ;; Make sure it's not an "end if".
6094 (save-excursion
6095 (backward-sexp)
6096 (not (looking-at "end\\s-+\\w"))))
6098 ;; "while" ... "loop":
6099 ((looking-at "w")
6103 (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
6104 "Regexp describing a case statement alternative key.")
6106 (defun vhdl-case-alternative-p (&optional lim)
6107 "Return t if we are looking at a real case alternative.
6108 Assumes that the caller will make sure that we are looking at
6109 vhdl-case-alternative-re, and are not inside a literal, and that
6110 we are not in the middle of an identifier that just happens to
6111 contain a \"when\" keyword."
6112 (save-excursion
6113 (let (foundp)
6114 (while (and (not foundp)
6115 (re-search-backward ";\\|<=" lim 'move))
6116 (if (or (= (preceding-char) ?_)
6117 (vhdl-in-literal))
6118 (backward-char)
6119 (setq foundp t)))
6120 (or (eq (following-char) ?\;)
6121 (eq (point) lim)))
6124 ;; Core syntactic movement functions:
6126 (defconst vhdl-b-t-b-re
6127 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
6129 (defun vhdl-backward-to-block (&optional lim)
6130 "Move backward to the previous \"begin\" or \"end\" keyword."
6131 (let (foundp)
6132 (while (and (not foundp)
6133 (re-search-backward vhdl-b-t-b-re lim 'move))
6134 (if (or (= (preceding-char) ?_)
6135 (vhdl-in-literal))
6136 (backward-char)
6137 (cond
6138 ;; "begin" keyword:
6139 ((and (looking-at vhdl-begin-fwd-re)
6140 (or (not (looking-at "\\<use\\>"))
6141 (save-excursion (back-to-indentation)
6142 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6143 (/= (preceding-char) ?_)
6144 (vhdl-begin-p lim))
6145 (setq foundp 'begin))
6146 ;; "end" keyword:
6147 ((and (looking-at vhdl-end-fwd-re)
6148 (/= (preceding-char) ?_)
6149 (vhdl-end-p lim))
6150 (setq foundp 'end))
6153 foundp
6156 (defun vhdl-forward-sexp (&optional count lim)
6157 "Move forward across one balanced expression (sexp).
6158 With COUNT, do it that many times."
6159 (interactive "p")
6160 (let ((count (or count 1))
6161 (case-fold-search t)
6162 end-vec target)
6163 (save-excursion
6164 (while (> count 0)
6165 ;; skip whitespace
6166 (skip-chars-forward " \t\n\r\f")
6167 ;; Check for an unbalanced "end" keyword
6168 (if (and (looking-at vhdl-end-fwd-re)
6169 (/= (preceding-char) ?_)
6170 (not (vhdl-in-literal))
6171 (vhdl-end-p lim)
6172 (not (looking-at "else")))
6173 (error
6174 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6175 ;; If the current keyword is a "begin" keyword, then find the
6176 ;; corresponding "end" keyword.
6177 (if (setq end-vec (vhdl-corresponding-end lim))
6178 (let (
6179 ;; end-re is the statement keyword to search for
6180 (end-re
6181 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
6182 ;; column is either the statement keyword target column
6183 ;; or nil
6184 (column (aref end-vec 1))
6185 (eol (vhdl-point 'eol))
6186 foundp literal placeholder)
6187 ;; Look for the statement keyword.
6188 (while (and (not foundp)
6189 (re-search-forward end-re nil t)
6190 (setq placeholder (match-end 1))
6191 (goto-char (match-beginning 0)))
6192 ;; If we are in a literal, or not in the right target
6193 ;; column and not on the same line as the begin, then
6194 ;; try again.
6195 (if (or (and column
6196 (/= (current-indentation) column)
6197 (> (point) eol))
6198 (= (preceding-char) ?_)
6199 (setq literal (vhdl-in-literal)))
6200 (if (eq literal 'comment)
6201 (end-of-line)
6202 (forward-char))
6203 ;; An "else" keyword corresponds to both the opening brace
6204 ;; of the following sexp and the closing brace of the
6205 ;; previous sexp.
6206 (if (not (looking-at "else"))
6207 (goto-char placeholder))
6208 (setq foundp t))
6210 (if (not foundp)
6211 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6213 ;; If the current keyword is not a "begin" keyword, then just
6214 ;; perform the normal forward-sexp.
6215 (forward-sexp)
6217 (setq count (1- count))
6219 (setq target (point)))
6220 (goto-char target)
6221 nil))
6223 (defun vhdl-backward-sexp (&optional count lim)
6224 "Move backward across one balanced expression (sexp).
6225 With COUNT, do it that many times. LIM bounds any required backward
6226 searches."
6227 (interactive "p")
6228 (let ((count (or count 1))
6229 (case-fold-search t)
6230 begin-vec target)
6231 (save-excursion
6232 (while (> count 0)
6233 ;; Perform the normal backward-sexp, unless we are looking at
6234 ;; "else" - an "else" keyword corresponds to both the opening brace
6235 ;; of the following sexp and the closing brace of the previous sexp.
6236 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6237 (/= (preceding-char) ?_)
6238 (not (vhdl-in-literal)))
6240 (backward-sexp)
6241 (if (and (looking-at vhdl-begin-fwd-re)
6242 (or (not (looking-at "\\<use\\>"))
6243 (save-excursion
6244 (back-to-indentation)
6245 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6246 (/= (preceding-char) ?_)
6247 (not (vhdl-in-literal))
6248 (vhdl-begin-p lim))
6249 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6250 ;; If the current keyword is an "end" keyword, then find the
6251 ;; corresponding "begin" keyword.
6252 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6253 (/= (preceding-char) ?_))
6254 (let (
6255 ;; begin-re is the statement keyword to search for
6256 (begin-re
6257 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6258 ;; column is either the statement keyword target column
6259 ;; or nil
6260 (column (aref begin-vec 1))
6261 ;; internal-p controls where the statement keyword can
6262 ;; be found.
6263 (internal-p (aref begin-vec 3))
6264 (last-backward (point)) last-forward
6265 foundp literal keyword)
6266 ;; Look for the statement keyword.
6267 (while (and (not foundp)
6268 (re-search-backward begin-re lim t)
6269 (setq keyword
6270 (buffer-substring (match-beginning 1)
6271 (match-end 1))))
6272 ;; If we are in a literal or in the wrong column,
6273 ;; then try again.
6274 (if (or (and column
6275 (and (/= (current-indentation) column)
6276 ;; possibly accept current-column as
6277 ;; well as current-indentation.
6278 (or (not internal-p)
6279 (/= (current-column) column))))
6280 (= (preceding-char) ?_)
6281 (vhdl-in-literal))
6282 (backward-char)
6283 ;; If there is a supplementary keyword, then
6284 ;; search forward for it.
6285 (if (and (setq begin-re (aref begin-vec 2))
6286 (or (not (listp begin-re))
6287 ;; If begin-re is an alist, then find the
6288 ;; element corresponding to the actual
6289 ;; keyword that we found.
6290 (progn
6291 (setq begin-re
6292 (assoc keyword begin-re))
6293 (and begin-re
6294 (setq begin-re (cdr begin-re))))))
6295 (and
6296 (setq begin-re
6297 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6298 (save-excursion
6299 (setq last-forward (point))
6300 ;; Look for the supplementary keyword
6301 ;; (bounded by the backward search start
6302 ;; point).
6303 (while (and (not foundp)
6304 (re-search-forward begin-re
6305 last-backward t)
6306 (goto-char (match-beginning 1)))
6307 ;; If we are in a literal, then try again.
6308 (if (or (= (preceding-char) ?_)
6309 (setq literal
6310 (vhdl-in-literal)))
6311 (if (eq literal 'comment)
6312 (goto-char
6313 (min (vhdl-point 'eol) last-backward))
6314 (forward-char))
6315 ;; We have found the supplementary keyword.
6316 ;; Save the position of the keyword in foundp.
6317 (setq foundp (point)))
6319 foundp)
6320 ;; If the supplementary keyword was found, then
6321 ;; move point to the supplementary keyword.
6322 (goto-char foundp))
6323 ;; If there was no supplementary keyword, then
6324 ;; point is already at the statement keyword.
6325 (setq foundp t)))
6326 ) ; end of the search for the statement keyword
6327 (if (not foundp)
6328 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6330 (setq count (1- count))
6332 (setq target (point)))
6333 (goto-char target)
6334 nil))
6336 (defun vhdl-backward-up-list (&optional count limit)
6337 "Move backward out of one level of blocks.
6338 With argument, do this that many times."
6339 (interactive "p")
6340 (let ((count (or count 1))
6341 target)
6342 (save-excursion
6343 (while (> count 0)
6344 (if (looking-at vhdl-defun-re)
6345 (error "ERROR: Unbalanced blocks"))
6346 (vhdl-backward-to-block limit)
6347 (setq count (1- count)))
6348 (setq target (point)))
6349 (goto-char target)))
6351 (defun vhdl-end-of-defun (&optional count)
6352 "Move forward to the end of a VHDL defun."
6353 (interactive)
6354 (let ((case-fold-search t))
6355 (vhdl-beginning-of-defun)
6356 (if (not (looking-at "block\\|process\\|procedural"))
6357 (re-search-forward "\\bis\\b"))
6358 (vhdl-forward-sexp)))
6360 (defun vhdl-mark-defun ()
6361 "Put mark at end of this \"defun\", point at beginning."
6362 (interactive)
6363 (let ((case-fold-search t))
6364 (push-mark)
6365 (vhdl-beginning-of-defun)
6366 (push-mark)
6367 (if (not (looking-at "block\\|process\\|procedural"))
6368 (re-search-forward "\\bis\\b"))
6369 (vhdl-forward-sexp)
6370 (exchange-point-and-mark)))
6372 (defun vhdl-beginning-of-libunit ()
6373 "Move backward to the beginning of a VHDL library unit.
6374 Returns the location of the corresponding begin keyword, unless search
6375 stops due to beginning or end of buffer.
6376 Note that if point is between the \"libunit\" keyword and the
6377 corresponding \"begin\" keyword, then that libunit will not be
6378 recognized, and the search will continue backwards. If point is
6379 at the \"begin\" keyword, then the defun will be recognized. The
6380 returned point is at the first character of the \"libunit\" keyword."
6381 (let ((last-forward (point))
6382 (last-backward
6383 ;; Just in case we are actually sitting on the "begin"
6384 ;; keyword, allow for the keyword and an extra character,
6385 ;; as this will be used when looking forward for the
6386 ;; "begin" keyword.
6387 (save-excursion (forward-word 1) (1+ (point))))
6388 foundp literal placeholder)
6389 ;; Find the "libunit" keyword.
6390 (while (and (not foundp)
6391 (re-search-backward vhdl-libunit-re nil 'move))
6392 ;; If we are in a literal, or not at a real libunit, then try again.
6393 (if (or (= (preceding-char) ?_)
6394 (vhdl-in-literal)
6395 (not (vhdl-libunit-p)))
6396 (backward-char)
6397 ;; Find the corresponding "begin" keyword.
6398 (setq last-forward (point))
6399 (while (and (not foundp)
6400 (re-search-forward "\\bis\\b[^_]" last-backward t)
6401 (setq placeholder (match-beginning 0)))
6402 (if (or (= (preceding-char) ?_)
6403 (setq literal (vhdl-in-literal)))
6404 ;; It wasn't a real keyword, so keep searching.
6405 (if (eq literal 'comment)
6406 (goto-char
6407 (min (vhdl-point 'eol) last-backward))
6408 (forward-char))
6409 ;; We have found the begin keyword, loop will exit.
6410 (setq foundp placeholder)))
6411 ;; Go back to the libunit keyword
6412 (goto-char last-forward)))
6413 foundp))
6415 (defun vhdl-beginning-of-defun (&optional count)
6416 "Move backward to the beginning of a VHDL defun.
6417 With argument, do it that many times.
6418 Returns the location of the corresponding begin keyword, unless search
6419 stops due to beginning or end of buffer."
6420 ;; Note that if point is between the "defun" keyword and the
6421 ;; corresponding "begin" keyword, then that defun will not be
6422 ;; recognized, and the search will continue backwards. If point is
6423 ;; at the "begin" keyword, then the defun will be recognized. The
6424 ;; returned point is at the first character of the "defun" keyword.
6425 (interactive "p")
6426 (let ((count (or count 1))
6427 (case-fold-search t)
6428 (last-forward (point))
6429 foundp)
6430 (while (> count 0)
6431 (setq foundp nil)
6432 (goto-char last-forward)
6433 (let ((last-backward
6434 ;; Just in case we are actually sitting on the "begin"
6435 ;; keyword, allow for the keyword and an extra character,
6436 ;; as this will be used when looking forward for the
6437 ;; "begin" keyword.
6438 (save-excursion (forward-word 1) (1+ (point))))
6439 begin-string literal)
6440 (while (and (not foundp)
6441 (re-search-backward vhdl-defun-re nil 'move))
6442 ;; If we are in a literal, then try again.
6443 (if (or (= (preceding-char) ?_)
6444 (vhdl-in-literal))
6445 (backward-char)
6446 (if (setq begin-string (vhdl-corresponding-defun))
6447 ;; This is a real defun keyword.
6448 ;; Find the corresponding "begin" keyword.
6449 ;; Look for the begin keyword.
6450 (progn
6451 ;; Save the search start point.
6452 (setq last-forward (point))
6453 (while (and (not foundp)
6454 (search-forward begin-string last-backward t))
6455 (if (or (= (preceding-char) ?_)
6456 (save-match-data
6457 (setq literal (vhdl-in-literal))))
6458 ;; It wasn't a real keyword, so keep searching.
6459 (if (eq literal 'comment)
6460 (goto-char
6461 (min (vhdl-point 'eol) last-backward))
6462 (forward-char))
6463 ;; We have found the begin keyword, loop will exit.
6464 (setq foundp (match-beginning 0)))
6466 ;; Go back to the defun keyword
6467 (goto-char last-forward)) ; end search for begin keyword
6469 ) ; end of the search for the defun keyword
6471 (setq count (1- count))
6473 (vhdl-keep-region-active)
6474 foundp))
6476 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6477 "Go to the beginning of the innermost VHDL statement.
6478 With prefix arg, go back N - 1 statements. If already at the
6479 beginning of a statement then go to the beginning of the preceding
6480 one. If within a string or comment, or next to a comment (only
6481 whitespace between), move by sentences instead of statements.
6483 When called from a program, this function takes 3 optional args: the
6484 prefix arg, a buffer position limit which is the farthest back to
6485 search, and an argument indicating an interactive call."
6486 (interactive "p\np")
6487 (let ((count (or count 1))
6488 (case-fold-search t)
6489 (lim (or lim (point-min)))
6490 (here (point))
6491 state)
6492 (save-excursion
6493 (goto-char lim)
6494 (setq state (parse-partial-sexp (point) here nil nil)))
6495 (if (and interactive
6496 (or (nth 3 state)
6497 (nth 4 state)
6498 (looking-at (concat "[ \t]*" comment-start-skip))))
6499 (forward-sentence (- count))
6500 (while (> count 0)
6501 (vhdl-beginning-of-statement-1 lim)
6502 (setq count (1- count))))
6503 ;; its possible we've been left up-buf of lim
6504 (goto-char (max (point) lim))
6506 (vhdl-keep-region-active))
6508 (defconst vhdl-e-o-s-re
6509 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6511 (defun vhdl-end-of-statement ()
6512 "Very simple implementation."
6513 (interactive)
6514 (re-search-forward vhdl-e-o-s-re))
6516 (defconst vhdl-b-o-s-re
6517 (concat ";[^_]\\|\([^_]\\|\)[^_]\\|\\bwhen\\b[^_]\\|"
6518 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6520 (defun vhdl-beginning-of-statement-1 (&optional lim)
6521 "Move to the start of the current statement, or the previous
6522 statement if already at the beginning of one."
6523 (let ((lim (or lim (point-min)))
6524 (here (point))
6525 (pos (point))
6526 donep)
6527 ;; go backwards one balanced expression, but be careful of
6528 ;; unbalanced paren being reached
6529 (if (not (vhdl-safe (progn (backward-sexp) t)))
6530 (progn
6531 (backward-up-list 1)
6532 (forward-char)
6533 (vhdl-forward-syntactic-ws here)
6534 (setq donep t)))
6535 (while (and (not donep)
6536 (not (bobp))
6537 ;; look backwards for a statement boundary
6538 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
6539 (if (or (= (preceding-char) ?_)
6540 (vhdl-in-literal))
6541 (backward-char)
6542 (cond
6543 ;; If we are looking at an open paren, then stop after it
6544 ((eq (following-char) ?\()
6545 (forward-char)
6546 (vhdl-forward-syntactic-ws here)
6547 (setq donep t))
6548 ;; If we are looking at a close paren, then skip it
6549 ((eq (following-char) ?\))
6550 (forward-char)
6551 (setq pos (point))
6552 (backward-sexp)
6553 (if (< (point) lim)
6554 (progn (goto-char pos)
6555 (vhdl-forward-syntactic-ws here)
6556 (setq donep t))))
6557 ;; If we are looking at a semicolon, then stop
6558 ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
6559 (progn
6560 (forward-char)
6561 (vhdl-forward-syntactic-ws here)
6562 (setq donep t)))
6563 ;; If we are looking at a "begin", then stop
6564 ((and (looking-at vhdl-begin-fwd-re)
6565 (or (not (looking-at "\\<use\\>"))
6566 (save-excursion
6567 (back-to-indentation)
6568 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6569 (/= (preceding-char) ?_)
6570 (vhdl-begin-p nil))
6571 ;; If it's a leader "begin", then find the
6572 ;; right place
6573 (if (looking-at vhdl-leader-re)
6574 (save-excursion
6575 ;; set a default stop point at the begin
6576 (setq pos (point))
6577 ;; is the start point inside the leader area ?
6578 (goto-char (vhdl-end-of-leader))
6579 (vhdl-forward-syntactic-ws here)
6580 (if (< (point) here)
6581 ;; start point was not inside leader area
6582 ;; set stop point at word after leader
6583 (setq pos (point))))
6584 (forward-word 1)
6585 (vhdl-forward-syntactic-ws here)
6586 (setq pos (point)))
6587 (goto-char pos)
6588 (setq donep t))
6589 ;; If we are looking at a "statement", then stop
6590 ((and (looking-at vhdl-statement-fwd-re)
6591 (/= (preceding-char) ?_)
6592 (vhdl-statement-p nil))
6593 (setq donep t))
6594 ;; If we are looking at a case alternative key, then stop
6595 ((and (looking-at vhdl-case-alternative-re)
6596 (vhdl-case-alternative-p lim))
6597 (save-excursion
6598 ;; set a default stop point at the when
6599 (setq pos (point))
6600 ;; is the start point inside the case alternative key ?
6601 (looking-at vhdl-case-alternative-re)
6602 (goto-char (match-end 0))
6603 (vhdl-forward-syntactic-ws here)
6604 (if (< (point) here)
6605 ;; start point was not inside the case alternative key
6606 ;; set stop point at word after case alternative keyleader
6607 (setq pos (point))))
6608 (goto-char pos)
6609 (setq donep t))
6610 ;; Bogus find, continue
6612 (backward-char)))))
6615 ;; Defuns for calculating the current syntactic state:
6617 (defun vhdl-get-library-unit (bod placeholder)
6618 "If there is an enclosing library unit at BOD, with its \"begin\"
6619 keyword at PLACEHOLDER, then return the library unit type."
6620 (let ((here (vhdl-point 'bol)))
6621 (if (save-excursion
6622 (goto-char placeholder)
6623 (vhdl-safe (vhdl-forward-sexp 1 bod))
6624 (<= here (point)))
6625 (save-excursion
6626 (goto-char bod)
6627 (cond
6628 ((looking-at "e") 'entity)
6629 ((looking-at "a") 'architecture)
6630 ((looking-at "c") 'configuration)
6631 ((looking-at "p")
6632 (save-excursion
6633 (goto-char bod)
6634 (forward-sexp)
6635 (vhdl-forward-syntactic-ws here)
6636 (if (looking-at "body\\b[^_]")
6637 'package-body 'package))))))
6640 (defun vhdl-get-block-state (&optional lim)
6641 "Finds and records all the closest opens.
6642 LIM is the furthest back we need to search (it should be the
6643 previous libunit keyword)."
6644 (let ((here (point))
6645 (lim (or lim (point-min)))
6646 keyword sexp-start sexp-mid sexp-end
6647 preceding-sexp containing-sexp
6648 containing-begin containing-mid containing-paren)
6649 (save-excursion
6650 ;; Find the containing-paren, and use that as the limit
6651 (if (setq containing-paren
6652 (save-restriction
6653 (narrow-to-region lim (point))
6654 (vhdl-safe (scan-lists (point) -1 1))))
6655 (setq lim containing-paren))
6656 ;; Look backwards for "begin" and "end" keywords.
6657 (while (and (> (point) lim)
6658 (not containing-sexp))
6659 (setq keyword (vhdl-backward-to-block lim))
6660 (cond
6661 ((eq keyword 'begin)
6662 ;; Found a "begin" keyword
6663 (setq sexp-start (point))
6664 (setq sexp-mid (vhdl-corresponding-mid lim))
6665 (setq sexp-end (vhdl-safe
6666 (save-excursion
6667 (vhdl-forward-sexp 1 lim) (point))))
6668 (if (and sexp-end (<= sexp-end here))
6669 ;; we want to record this sexp, but we only want to
6670 ;; record the last-most of any of them before here
6671 (or preceding-sexp
6672 (setq preceding-sexp sexp-start))
6673 ;; we're contained in this sexp so put sexp-start on
6674 ;; front of list
6675 (setq containing-sexp sexp-start)
6676 (setq containing-mid sexp-mid)
6677 (setq containing-begin t)))
6678 ((eq keyword 'end)
6679 ;; Found an "end" keyword
6680 (forward-sexp)
6681 (setq sexp-end (point))
6682 (setq sexp-mid nil)
6683 (setq sexp-start
6684 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6685 (progn (backward-sexp) (point))))
6686 ;; we want to record this sexp, but we only want to
6687 ;; record the last-most of any of them before here
6688 (or preceding-sexp
6689 (setq preceding-sexp sexp-start)))
6691 ;; Check if the containing-paren should be the containing-sexp
6692 (if (and containing-paren
6693 (or (null containing-sexp)
6694 (< containing-sexp containing-paren)))
6695 (setq containing-sexp containing-paren
6696 preceding-sexp nil
6697 containing-begin nil
6698 containing-mid nil))
6699 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6703 (defconst vhdl-s-c-a-re
6704 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6706 (defun vhdl-skip-case-alternative (&optional lim)
6707 "Skip forward over case/when bodies, with optional maximal
6708 limit. If no next case alternative is found, nil is returned and
6709 point is not moved."
6710 (let ((lim (or lim (point-max)))
6711 (here (point))
6712 donep foundp)
6713 (while (and (< (point) lim)
6714 (not donep))
6715 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6716 (save-match-data
6717 (not (vhdl-in-literal)))
6718 (/= (match-beginning 0) here))
6719 (progn
6720 (goto-char (match-beginning 0))
6721 (cond
6722 ((and (looking-at "case")
6723 (re-search-forward "\\bis[^_]" lim t))
6724 (backward-sexp)
6725 (vhdl-forward-sexp))
6727 (setq donep t
6728 foundp t))))))
6729 (if (not foundp)
6730 (goto-char here))
6731 foundp))
6733 (defun vhdl-backward-skip-label (&optional lim)
6734 "Skip backward over a label, with optional maximal
6735 limit. If label is not found, nil is returned and point
6736 is not moved."
6737 (let ((lim (or lim (point-min)))
6738 placeholder)
6739 (if (save-excursion
6740 (vhdl-backward-syntactic-ws lim)
6741 (and (eq (preceding-char) ?:)
6742 (progn
6743 (backward-sexp)
6744 (setq placeholder (point))
6745 (looking-at vhdl-label-key))))
6746 (goto-char placeholder))
6749 (defun vhdl-forward-skip-label (&optional lim)
6750 "Skip forward over a label, with optional maximal
6751 limit. If label is not found, nil is returned and point
6752 is not moved."
6753 (let ((lim (or lim (point-max))))
6754 (if (looking-at vhdl-label-key)
6755 (progn
6756 (goto-char (match-end 0))
6757 (vhdl-forward-syntactic-ws lim)))
6760 (defun vhdl-get-syntactic-context ()
6761 "Guess the syntactic description of the current line of VHDL code."
6762 (save-excursion
6763 (save-restriction
6764 (beginning-of-line)
6765 (let* ((indent-point (point))
6766 (case-fold-search t)
6767 vec literal containing-sexp preceding-sexp
6768 containing-begin containing-mid containing-leader
6769 char-before-ip char-after-ip begin-after-ip end-after-ip
6770 placeholder lim library-unit
6773 ;; Reset the syntactic context
6774 (setq vhdl-syntactic-context nil)
6776 (save-excursion
6777 ;; Move to the start of the previous library unit, and
6778 ;; record the position of the "begin" keyword.
6779 (setq placeholder (vhdl-beginning-of-libunit))
6780 ;; The position of the "libunit" keyword gives us a gross
6781 ;; limit point.
6782 (setq lim (point))
6785 ;; If there is a previous library unit, and we are enclosed by
6786 ;; it, then set the syntax accordingly.
6787 (and placeholder
6788 (setq library-unit (vhdl-get-library-unit lim placeholder))
6789 (vhdl-add-syntax library-unit lim))
6791 ;; Find the surrounding state.
6792 (if (setq vec (vhdl-get-block-state lim))
6793 (progn
6794 (setq containing-sexp (aref vec 0))
6795 (setq preceding-sexp (aref vec 1))
6796 (setq containing-begin (aref vec 2))
6797 (setq containing-mid (aref vec 3))
6800 ;; set the limit on the farthest back we need to search
6801 (setq lim (if containing-sexp
6802 (save-excursion
6803 (goto-char containing-sexp)
6804 ;; set containing-leader if required
6805 (if (looking-at vhdl-leader-re)
6806 (setq containing-leader (vhdl-end-of-leader)))
6807 (vhdl-point 'bol))
6808 (point-min)))
6810 ;; cache char before and after indent point, and move point to
6811 ;; the most likely position to perform the majority of tests
6812 (goto-char indent-point)
6813 (skip-chars-forward " \t")
6814 (setq literal (vhdl-in-literal))
6815 (setq char-after-ip (following-char))
6816 (setq begin-after-ip (and
6817 (not literal)
6818 (looking-at vhdl-begin-fwd-re)
6819 (or (not (looking-at "\\<use\\>"))
6820 (save-excursion
6821 (back-to-indentation)
6822 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6823 (vhdl-begin-p)))
6824 (setq end-after-ip (and
6825 (not literal)
6826 (looking-at vhdl-end-fwd-re)
6827 (vhdl-end-p)))
6828 (vhdl-backward-syntactic-ws lim)
6829 (setq char-before-ip (preceding-char))
6830 (goto-char indent-point)
6831 (skip-chars-forward " \t")
6833 ;; now figure out syntactic qualities of the current line
6834 (cond
6835 ;; CASE 1: in a string or comment.
6836 ((memq literal '(string comment))
6837 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6838 ;; CASE 2: Line is at top level.
6839 ((null containing-sexp)
6840 ;; Find the point to which indentation will be relative
6841 (save-excursion
6842 (if (null preceding-sexp)
6843 ;; CASE 2X.1
6844 ;; no preceding-sexp -> use the preceding statement
6845 (vhdl-beginning-of-statement-1 lim)
6846 ;; CASE 2X.2
6847 ;; if there is a preceding-sexp then indent relative to it
6848 (goto-char preceding-sexp)
6849 ;; if not at boi, then the block-opening keyword is
6850 ;; probably following a label, so we need a different
6851 ;; relpos
6852 (if (/= (point) (vhdl-point 'boi))
6853 ;; CASE 2X.3
6854 (vhdl-beginning-of-statement-1 lim)))
6855 ;; v-b-o-s could have left us at point-min
6856 (and (bobp)
6857 ;; CASE 2X.4
6858 (vhdl-forward-syntactic-ws indent-point))
6859 (setq placeholder (point)))
6860 (cond
6861 ;; CASE 2A : we are looking at a block-open
6862 (begin-after-ip
6863 (vhdl-add-syntax 'block-open placeholder))
6864 ;; CASE 2B: we are looking at a block-close
6865 (end-after-ip
6866 (vhdl-add-syntax 'block-close placeholder))
6867 ;; CASE 2C: we are looking at a top-level statement
6868 ((progn
6869 (vhdl-backward-syntactic-ws lim)
6870 (or (bobp)
6871 (and (= (preceding-char) ?\;)
6872 (not (vhdl-in-quote-p)))))
6873 (vhdl-add-syntax 'statement placeholder))
6874 ;; CASE 2D: we are looking at a top-level statement-cont
6876 (vhdl-beginning-of-statement-1 lim)
6877 ;; v-b-o-s could have left us at point-min
6878 (and (bobp)
6879 ;; CASE 2D.1
6880 (vhdl-forward-syntactic-ws indent-point))
6881 (vhdl-add-syntax 'statement-cont (point)))
6882 )) ; end CASE 2
6883 ;; CASE 3: line is inside parentheses. Most likely we are
6884 ;; either in a subprogram argument (interface) list, or a
6885 ;; continued expression containing parentheses.
6886 ((null containing-begin)
6887 (vhdl-backward-syntactic-ws containing-sexp)
6888 (cond
6889 ;; CASE 3A: we are looking at the arglist closing paren
6890 ((eq char-after-ip ?\))
6891 (goto-char containing-sexp)
6892 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6893 ;; CASE 3B: we are looking at the first argument in an empty
6894 ;; argument list.
6895 ((eq char-before-ip ?\()
6896 (goto-char containing-sexp)
6897 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6898 ;; CASE 3C: we are looking at an arglist continuation line,
6899 ;; but the preceding argument is on the same line as the
6900 ;; opening paren. This case includes multi-line
6901 ;; expression paren groupings.
6902 ((and (save-excursion
6903 (goto-char (1+ containing-sexp))
6904 (skip-chars-forward " \t")
6905 (not (eolp))
6906 (not (looking-at "--")))
6907 (save-excursion
6908 (vhdl-beginning-of-statement-1 containing-sexp)
6909 (skip-chars-backward " \t(")
6910 (while (and (= (preceding-char) ?\;)
6911 (not (vhdl-in-quote-p)))
6912 (vhdl-beginning-of-statement-1 containing-sexp)
6913 (skip-chars-backward " \t("))
6914 (<= (point) containing-sexp)))
6915 (goto-char containing-sexp)
6916 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6917 ;; CASE 3D: we are looking at just a normal arglist
6918 ;; continuation line
6919 (t (vhdl-beginning-of-statement-1 containing-sexp)
6920 (vhdl-forward-syntactic-ws indent-point)
6921 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6923 ;; CASE 4: A block mid open
6924 ((and begin-after-ip
6925 (looking-at containing-mid))
6926 (goto-char containing-sexp)
6927 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6928 (if (looking-at vhdl-trailer-re)
6929 ;; CASE 4.1
6930 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6931 (vhdl-backward-skip-label (vhdl-point 'boi))
6932 (vhdl-add-syntax 'block-open (point)))
6933 ;; CASE 5: block close brace
6934 (end-after-ip
6935 (goto-char containing-sexp)
6936 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6937 (if (looking-at vhdl-trailer-re)
6938 ;; CASE 5.1
6939 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6940 (vhdl-backward-skip-label (vhdl-point 'boi))
6941 (vhdl-add-syntax 'block-close (point)))
6942 ;; CASE 6: A continued statement
6943 ((and (/= char-before-ip ?\;)
6944 ;; check it's not a trailer begin keyword, or a begin
6945 ;; keyword immediately following a label.
6946 (not (and begin-after-ip
6947 (or (looking-at vhdl-trailer-re)
6948 (save-excursion
6949 (vhdl-backward-skip-label containing-sexp)))))
6950 ;; check it's not a statement keyword
6951 (not (and (looking-at vhdl-statement-fwd-re)
6952 (vhdl-statement-p)))
6953 ;; see if the b-o-s is before the indent point
6954 (> indent-point
6955 (save-excursion
6956 (vhdl-beginning-of-statement-1 containing-sexp)
6957 ;; If we ended up after a leader, then this will
6958 ;; move us forward to the start of the first
6959 ;; statement. Note that a containing sexp here is
6960 ;; always a keyword, not a paren, so this will
6961 ;; have no effect if we hit the containing-sexp.
6962 (vhdl-forward-syntactic-ws indent-point)
6963 (setq placeholder (point))))
6964 ;; check it's not a block-intro
6965 (/= placeholder containing-sexp)
6966 ;; check it's not a case block-intro
6967 (save-excursion
6968 (goto-char placeholder)
6969 (or (not (looking-at vhdl-case-alternative-re))
6970 (> (match-end 0) indent-point))))
6971 ;; Make placeholder skip a label, but only if it puts us
6972 ;; before the indent point at the start of a line.
6973 (let ((new placeholder))
6974 (if (and (> indent-point
6975 (save-excursion
6976 (goto-char placeholder)
6977 (vhdl-forward-skip-label indent-point)
6978 (setq new (point))))
6979 (save-excursion
6980 (goto-char new)
6981 (eq new (progn (back-to-indentation) (point)))))
6982 (setq placeholder new)))
6983 (vhdl-add-syntax 'statement-cont placeholder)
6984 (if begin-after-ip
6985 (vhdl-add-syntax 'block-open)))
6986 ;; Statement. But what kind?
6987 ;; CASE 7: A case alternative key
6988 ((and (looking-at vhdl-case-alternative-re)
6989 (vhdl-case-alternative-p containing-sexp))
6990 ;; for a case alternative key, we set relpos to the first
6991 ;; non-whitespace char on the line containing the "case"
6992 ;; keyword.
6993 (goto-char containing-sexp)
6994 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6995 (if (looking-at vhdl-trailer-re)
6996 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6997 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6998 ;; CASE 8: statement catchall
7000 ;; we know its a statement, but we need to find out if it is
7001 ;; the first statement in a block
7002 (if containing-leader
7003 (goto-char containing-leader)
7004 (goto-char containing-sexp)
7005 ;; Note that a containing sexp here is always a keyword,
7006 ;; not a paren, so skip over the keyword.
7007 (forward-sexp))
7008 ;; move to the start of the first statement
7009 (vhdl-forward-syntactic-ws indent-point)
7010 (setq placeholder (point))
7011 ;; we want to ignore case alternatives keys when skipping forward
7012 (let (incase-p)
7013 (while (looking-at vhdl-case-alternative-re)
7014 (setq incase-p (point))
7015 ;; we also want to skip over the body of the
7016 ;; case/when statement if that doesn't put us at
7017 ;; after the indent-point
7018 (while (vhdl-skip-case-alternative indent-point))
7019 ;; set up the match end
7020 (looking-at vhdl-case-alternative-re)
7021 (goto-char (match-end 0))
7022 ;; move to the start of the first case alternative statement
7023 (vhdl-forward-syntactic-ws indent-point)
7024 (setq placeholder (point)))
7025 (cond
7026 ;; CASE 8A: we saw a case/when statement so we must be
7027 ;; in a switch statement. find out if we are at the
7028 ;; statement just after a case alternative key
7029 ((and incase-p
7030 (= (point) indent-point))
7031 ;; relpos is the "when" keyword
7032 (vhdl-add-syntax 'statement-case-intro incase-p))
7033 ;; CASE 8B: any old statement
7034 ((< (point) indent-point)
7035 ;; relpos is the first statement of the block
7036 (vhdl-add-syntax 'statement placeholder)
7037 (if begin-after-ip
7038 (vhdl-add-syntax 'block-open)))
7039 ;; CASE 8C: first statement in a block
7041 (goto-char containing-sexp)
7042 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7043 (if (looking-at vhdl-trailer-re)
7044 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
7045 (vhdl-backward-skip-label (vhdl-point 'boi))
7046 (vhdl-add-syntax 'statement-block-intro (point))
7047 (if begin-after-ip
7048 (vhdl-add-syntax 'block-open)))
7052 ;; now we need to look at any modifiers
7053 (goto-char indent-point)
7054 (skip-chars-forward " \t")
7055 (if (looking-at "--")
7056 (vhdl-add-syntax 'comment))
7057 (if (eq literal 'pound)
7058 (vhdl-add-syntax 'cpp-macro))
7059 ;; return the syntax
7060 vhdl-syntactic-context))))
7062 ;; Standard indentation line-ups:
7064 (defun vhdl-lineup-arglist (langelem)
7065 "Lineup the current arglist line with the arglist appearing just
7066 after the containing paren which starts the arglist."
7067 (save-excursion
7068 (let* ((containing-sexp
7069 (save-excursion
7070 ;; arglist-cont-nonempty gives relpos ==
7071 ;; to boi of containing-sexp paren. This
7072 ;; is good when offset is +, but bad
7073 ;; when it is vhdl-lineup-arglist, so we
7074 ;; have to special case a kludge here.
7075 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
7076 (progn
7077 (beginning-of-line)
7078 (backward-up-list 1)
7079 (skip-chars-forward " \t" (vhdl-point 'eol)))
7080 (goto-char (cdr langelem)))
7081 (point)))
7082 (cs-curcol (save-excursion
7083 (goto-char (cdr langelem))
7084 (current-column))))
7085 (if (save-excursion
7086 (beginning-of-line)
7087 (looking-at "[ \t]*)"))
7088 (progn (goto-char (match-end 0))
7089 (backward-sexp)
7090 (forward-char)
7091 (vhdl-forward-syntactic-ws)
7092 (- (current-column) cs-curcol))
7093 (goto-char containing-sexp)
7094 (or (eolp)
7095 (let ((eol (vhdl-point 'eol))
7096 (here (progn
7097 (forward-char)
7098 (skip-chars-forward " \t")
7099 (point))))
7100 (vhdl-forward-syntactic-ws)
7101 (if (< (point) eol)
7102 (goto-char here))))
7103 (- (current-column) cs-curcol)
7104 ))))
7106 (defun vhdl-lineup-arglist-intro (langelem)
7107 "Lineup an arglist-intro line to just after the open paren."
7108 (save-excursion
7109 (let ((cs-curcol (save-excursion
7110 (goto-char (cdr langelem))
7111 (current-column)))
7112 (ce-curcol (save-excursion
7113 (beginning-of-line)
7114 (backward-up-list 1)
7115 (skip-chars-forward " \t" (vhdl-point 'eol))
7116 (current-column))))
7117 (- ce-curcol cs-curcol -1))))
7119 (defun vhdl-lineup-comment (langelem)
7120 "Support old behavior for comment indentation. We look at
7121 vhdl-comment-only-line-offset to decide how to indent comment
7122 only-lines."
7123 (save-excursion
7124 (back-to-indentation)
7125 ;; at or to the right of comment-column
7126 (if (>= (current-column) comment-column)
7127 (vhdl-comment-indent)
7128 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7129 (if (not (bolp))
7130 (or (car-safe vhdl-comment-only-line-offset)
7131 vhdl-comment-only-line-offset)
7132 (or (cdr-safe vhdl-comment-only-line-offset)
7133 (car-safe vhdl-comment-only-line-offset)
7134 -1000 ;jam it against the left side
7135 )))))
7137 (defun vhdl-lineup-statement-cont (langelem)
7138 "Line up statement-cont after the assignment operator."
7139 (save-excursion
7140 (let* ((relpos (cdr langelem))
7141 (assignp (save-excursion
7142 (goto-char (vhdl-point 'boi))
7143 (and (re-search-forward "\\(<\\|:\\|=\\)="
7144 (vhdl-point 'eol) t)
7145 (- (point) (vhdl-point 'boi)))))
7146 (curcol (progn
7147 (goto-char relpos)
7148 (current-column)))
7149 foundp)
7150 (while (and (not foundp)
7151 (< (point) (vhdl-point 'eol)))
7152 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
7153 (if (vhdl-in-literal)
7154 (forward-char)
7155 (if (= (preceding-char) ?\()
7156 ;; skip over any parenthesized expressions
7157 (goto-char (min (vhdl-point 'eol)
7158 (scan-lists (point) 1 1)))
7159 ;; found an assignment operator (not at eol)
7160 (setq foundp (not (looking-at "\\s-*$"))))))
7161 (if (not foundp)
7162 ;; there's no assignment operator on the line
7163 vhdl-basic-offset
7164 ;; calculate indentation column after assign and ws, unless
7165 ;; our line contains an assignment operator
7166 (if (not assignp)
7167 (progn
7168 (forward-char)
7169 (skip-chars-forward " \t")
7170 (setq assignp 0)))
7171 (- (current-column) assignp curcol))
7174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7175 ;; Progress reporting
7177 (defvar vhdl-progress-info nil
7178 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7180 (defun vhdl-update-progress-info (string pos)
7181 "Update progress information."
7182 (when (and vhdl-progress-info (not noninteractive)
7183 (< vhdl-progress-interval
7184 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
7185 (let ((delta (- (aref vhdl-progress-info 1)
7186 (aref vhdl-progress-info 0))))
7187 (if (= 0 delta)
7188 (message (concat string "... (100%s)") "%")
7189 (message (concat string "... (%2d%s)")
7190 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
7191 delta) "%")))
7192 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
7194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7195 ;; Indentation commands
7197 (defun vhdl-electric-tab (&optional prefix-arg)
7198 "If preceding character is part of a word or a paren then hippie-expand,
7199 else if right of non whitespace on line then insert tab,
7200 else if last command was a tab or return then dedent one step or if a comment
7201 toggle between normal indent and inline comment indent,
7202 else indent `correctly'."
7203 (interactive "*P")
7204 (vhdl-prepare-search-2
7205 (cond
7206 ;; indent region if region is active
7207 ((and (not (featurep 'xemacs)) (use-region-p))
7208 (vhdl-indent-region (region-beginning) (region-end) nil))
7209 ;; expand word
7210 ((= (char-syntax (preceding-char)) ?w)
7211 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7212 (case-replace nil)
7213 (hippie-expand-only-buffers
7214 (or (and (boundp 'hippie-expand-only-buffers)
7215 hippie-expand-only-buffers)
7216 '(vhdl-mode))))
7217 (vhdl-expand-abbrev prefix-arg)))
7218 ;; expand parenthesis
7219 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7220 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7221 (case-replace nil))
7222 (vhdl-expand-paren prefix-arg)))
7223 ;; insert tab
7224 ((> (current-column) (current-indentation))
7225 (insert-tab))
7226 ;; toggle comment indent
7227 ((and (looking-at "--")
7228 (or (eq last-command 'vhdl-electric-tab)
7229 (eq last-command 'vhdl-electric-return)))
7230 (cond ((= (current-indentation) 0) ; no indent
7231 (indent-to 1)
7232 (indent-according-to-mode))
7233 ((< (current-indentation) comment-column) ; normal indent
7234 (indent-to comment-column)
7235 (indent-according-to-mode))
7236 (t ; inline comment indent
7237 (delete-region (line-beginning-position) (point)))))
7238 ;; dedent
7239 ((and (>= (current-indentation) vhdl-basic-offset)
7240 (or (eq last-command 'vhdl-electric-tab)
7241 (eq last-command 'vhdl-electric-return)))
7242 (backward-delete-char-untabify vhdl-basic-offset nil))
7243 ;; indent line
7244 (t (indent-according-to-mode)))
7245 (setq this-command 'vhdl-electric-tab)))
7247 (defun vhdl-electric-return ()
7248 "newline-and-indent or indent-new-comment-line if in comment and preceding
7249 character is a space."
7250 (interactive)
7251 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7252 (indent-new-comment-line)
7253 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
7254 (not (vhdl-in-comment-p)))
7255 (vhdl-fix-case-word -1))
7256 (newline-and-indent)))
7258 (defun vhdl-indent-line ()
7259 "Indent the current line as VHDL code. Returns the amount of
7260 indentation change."
7261 (interactive)
7262 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
7263 (pos (- (point-max) (point)))
7264 (is-comment nil)
7265 (indent
7266 (if syntax
7267 ;; indent syntax-based
7268 (if (and (eq (caar syntax) 'comment)
7269 (>= (vhdl-get-offset (car syntax)) comment-column))
7270 ;; special case: comments at or right of comment-column
7271 (vhdl-get-offset (car syntax))
7272 ;; align comments like following code line
7273 (when vhdl-indent-comment-like-next-code-line
7274 (save-excursion
7275 (while (eq (caar syntax) 'comment)
7276 (setq is-comment t)
7277 (beginning-of-line 2)
7278 (setq syntax (vhdl-get-syntactic-context)))))
7279 (when is-comment
7280 (setq syntax (cons (cons 'comment nil) syntax)))
7281 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7282 ;; indent like previous nonblank line
7283 (save-excursion (beginning-of-line)
7284 (re-search-backward "^[^\n]" nil t)
7285 (current-indentation))))
7286 (shift-amt (- indent (current-indentation))))
7287 (and vhdl-echo-syntactic-information-p
7288 (message "syntax: %s, indent= %d" syntax indent))
7289 (let ((has-formfeed
7290 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7291 (when (or (not (zerop shift-amt)) has-formfeed)
7292 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7293 (beginning-of-line)
7294 (when has-formfeed (insert "\f"))
7295 (indent-to indent)))
7296 (if (< (point) (vhdl-point 'boi))
7297 (back-to-indentation)
7298 ;; If initial point was within line's indentation, position after
7299 ;; the indentation. Else stay at same point in text.
7300 (when (> (- (point-max) pos) (point))
7301 (goto-char (- (point-max) pos))))
7302 (run-hooks 'vhdl-special-indent-hook)
7303 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7304 shift-amt))
7306 (defun vhdl-indent-region (beg end &optional column)
7307 "Indent region as VHDL code.
7308 Adds progress reporting to `indent-region'."
7309 (interactive "r\nP")
7310 (when vhdl-progress-interval
7311 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7312 (count-lines (point-min) end) 0)))
7313 (indent-region beg end column)
7314 (when vhdl-progress-interval (message "Indenting...done"))
7315 (setq vhdl-progress-info nil))
7317 (defun vhdl-indent-buffer ()
7318 "Indent whole buffer as VHDL code.
7319 Calls `indent-region' for whole buffer and adds progress reporting."
7320 (interactive)
7321 (vhdl-indent-region (point-min) (point-max)))
7323 (defun vhdl-indent-group ()
7324 "Indent group of lines between empty lines."
7325 (interactive)
7326 (let ((beg (save-excursion
7327 (if (re-search-backward vhdl-align-group-separate nil t)
7328 (point-marker)
7329 (point-min-marker))))
7330 (end (save-excursion
7331 (if (re-search-forward vhdl-align-group-separate nil t)
7332 (point-marker)
7333 (point-max-marker)))))
7334 (vhdl-indent-region beg end)))
7336 (defun vhdl-indent-sexp (&optional endpos)
7337 "Indent each line of the list starting just after point.
7338 If optional arg ENDPOS is given, indent each line, stopping when
7339 ENDPOS is encountered."
7340 (interactive)
7341 (save-excursion
7342 (let ((beg (point))
7343 (end (progn (vhdl-forward-sexp nil endpos) (point))))
7344 (indent-region beg end nil))))
7346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7347 ;; Miscellaneous commands
7349 (defun vhdl-show-syntactic-information ()
7350 "Show syntactic information for current line."
7351 (interactive)
7352 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7353 (vhdl-keep-region-active))
7355 ;; Verification and regression functions:
7357 (defun vhdl-regress-line (&optional arg)
7358 "Check syntactic information for current line."
7359 (interactive "P")
7360 (let ((expected (save-excursion
7361 (end-of-line)
7362 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7363 (forward-char 4)
7364 (read (current-buffer)))))
7365 (actual (vhdl-get-syntactic-context))
7366 (expurgated))
7367 ;; remove the library unit symbols
7368 (mapc
7369 (function
7370 (lambda (elt)
7371 (if (memq (car elt) '(entity configuration package
7372 package-body architecture))
7374 (setq expurgated (append expurgated (list elt))))))
7375 actual)
7376 (if (and (not arg) expected (listp expected))
7377 (if (not (equal expected expurgated))
7378 (error "ERROR: Should be: %s, is: %s" expected expurgated))
7379 (save-excursion
7380 (beginning-of-line)
7381 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7382 (end-of-line)
7383 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7384 (delete-region (point) (line-end-position)))
7385 (insert " -- ")
7386 (insert (format "%s" expurgated))))))
7387 (vhdl-keep-region-active))
7390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7391 ;;; Alignment, whitespace fixup, beautifying
7392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7394 (defconst vhdl-align-alist
7396 ;; after some keywords
7397 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7398 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7399 ;; before ':'
7400 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7401 ;; after direction specifications
7402 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7403 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7404 ;; before "==", ":=", "=>", and "<="
7405 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7406 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7407 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7408 ;; before some keywords
7409 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7410 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7411 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7412 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7413 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7414 ;; before "=>" since "when/else ... =>" can occur
7415 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7417 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7418 It is searched in order. If REGEXP is found anywhere in the first
7419 line of a region to be aligned, ALIGN-PATTERN will be used for that
7420 region. ALIGN-PATTERN must include the whitespace to be expanded or
7421 contracted. It may also provide regexps for the text surrounding the
7422 whitespace. SUBEXP specifies which sub-expression of
7423 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7426 ;; Align code
7428 (defvar vhdl-align-try-all-clauses t
7429 "If REGEXP is not found on the first line of the region that clause
7430 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7432 (defun vhdl-do-group (function &optional spacing)
7433 "Apply FUNCTION on group of lines between empty lines."
7434 (let
7435 ;; search for group beginning
7436 ((beg (save-excursion
7437 (if (re-search-backward vhdl-align-group-separate nil t)
7438 (progn (beginning-of-line 2) (back-to-indentation) (point))
7439 (point-min))))
7440 ;; search for group end
7441 (end (save-excursion
7442 (if (re-search-forward vhdl-align-group-separate nil t)
7443 (progn (beginning-of-line) (point))
7444 (point-max)))))
7445 ;; run FUNCTION
7446 (funcall function beg end spacing)))
7448 (defun vhdl-do-list (function &optional spacing)
7449 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7450 parentheses."
7451 (let (beg end)
7452 (save-excursion
7453 ;; search for beginning of balanced group of parentheses
7454 (setq beg (vhdl-re-search-backward "[()]" nil t))
7455 (while (looking-at ")")
7456 (forward-char) (backward-sexp)
7457 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7458 ;; search for end of balanced group of parentheses
7459 (when beg
7460 (forward-list)
7461 (setq end (point))
7462 (goto-char (1+ beg))
7463 (skip-chars-forward " \t\n\r\f")
7464 (setq beg (point))))
7465 ;; run FUNCTION
7466 (if beg
7467 (funcall function beg end spacing)
7468 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7470 (defun vhdl-do-same-indent (function &optional spacing)
7471 "Apply FUNCTION to block of lines with same indent."
7472 (let ((indent (current-indentation))
7473 beg end)
7474 ;; search for first line with same indent
7475 (save-excursion
7476 (while (and (not (bobp))
7477 (or (looking-at "^\\s-*\\(--.*\\)?$")
7478 (= (current-indentation) indent)))
7479 (unless (looking-at "^\\s-*$")
7480 (back-to-indentation) (setq beg (point)))
7481 (beginning-of-line -0)))
7482 ;; search for last line with same indent
7483 (save-excursion
7484 (while (and (not (eobp))
7485 (or (looking-at "^\\s-*\\(--.*\\)?$")
7486 (= (current-indentation) indent)))
7487 (if (looking-at "^\\s-*$")
7488 (beginning-of-line 2)
7489 (beginning-of-line 2)
7490 (setq end (point)))))
7491 ;; run FUNCTION
7492 (funcall function beg end spacing)))
7494 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7495 "Attempt to align a range of lines based on the content of the
7496 lines. The definition of `alignment-list' determines the matching
7497 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7498 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7499 indentation is done before aligning."
7500 (interactive "r\np")
7501 (setq alignment-list (or alignment-list vhdl-align-alist))
7502 (setq spacing (or spacing 1))
7503 (save-excursion
7504 (let (bol indent)
7505 (goto-char end)
7506 (setq end (point-marker))
7507 (goto-char begin)
7508 (setq bol (setq begin (progn (beginning-of-line) (point))))
7509 ; (untabify bol end)
7510 (when indent
7511 (indent-region bol end nil))))
7512 (let ((copy (copy-alist alignment-list)))
7513 (vhdl-prepare-search-2
7514 (while copy
7515 (save-excursion
7516 (goto-char begin)
7517 (let (element
7518 (eol (point-at-eol)))
7519 (setq element (nth 0 copy))
7520 (when (and (or (and (listp (car element))
7521 (memq major-mode (car element)))
7522 (eq major-mode (car element)))
7523 (or vhdl-align-try-all-clauses
7524 (re-search-forward (car (cdr element)) eol t)))
7525 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7526 (car (cdr (cdr (cdr element)))) spacing))
7527 (setq copy (cdr copy))))))))
7529 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7530 "Align a range of lines from BEGIN to END. The regular expression
7531 MATCH must match exactly one field: the whitespace to be
7532 contracted/expanded. The alignment column will equal the
7533 rightmost column of the widest whitespace block. SPACING is
7534 the amount of extra spaces to add to the calculated maximum required.
7535 SPACING defaults to 1 so that at least one space is inserted after
7536 the token in MATCH."
7537 (setq spacing (or spacing 1))
7538 (setq substr (or substr 1))
7539 (save-excursion
7540 (let (distance (max 0) (lines 0) bol eol width)
7541 ;; Determine the greatest whitespace distance to the alignment
7542 ;; character
7543 (goto-char begin)
7544 (setq eol (point-at-eol)
7545 bol (setq begin (progn (beginning-of-line) (point))))
7546 (while (< bol end)
7547 (save-excursion
7548 (when (and (vhdl-re-search-forward match eol t)
7549 (save-excursion
7550 (goto-char (match-beginning 0))
7551 (forward-char)
7552 (and (not (vhdl-in-literal))
7553 (not (vhdl-in-quote-p))
7554 (not (vhdl-in-extended-identifier-p))))
7555 (not (looking-at "\\s-*$")))
7556 (setq distance (- (match-beginning substr) bol))
7557 (when (> distance max)
7558 (setq max distance))))
7559 (forward-line)
7560 (setq bol (point)
7561 eol (point-at-eol))
7562 (setq lines (1+ lines)))
7563 ;; Now insert enough maxs to push each assignment operator to
7564 ;; the same column. We need to use 'lines' as a counter, since
7565 ;; the location of the mark may change
7566 (goto-char (setq bol begin))
7567 (setq eol (point-at-eol))
7568 (while (> lines 0)
7569 (when (and (vhdl-re-search-forward match eol t)
7570 (save-excursion
7571 (goto-char (match-beginning 0))
7572 (forward-char)
7573 (and (not (vhdl-in-literal))
7574 (not (vhdl-in-quote-p))
7575 (not (vhdl-in-extended-identifier-p))))
7576 (not (looking-at "\\s-*$"))
7577 (> (match-beginning 0) ; not if at boi
7578 (save-excursion (back-to-indentation) (point))))
7579 (setq width (- (match-end substr) (match-beginning substr)))
7580 (setq distance (- (match-beginning substr) bol))
7581 (goto-char (match-beginning substr))
7582 (delete-char width)
7583 (insert-char ? (+ (- max distance) spacing)))
7584 (beginning-of-line)
7585 (forward-line)
7586 (setq bol (point)
7587 eol (point-at-eol))
7588 (setq lines (1- lines))))))
7590 (defun vhdl-align-region-groups (beg end &optional spacing
7591 no-message no-comments)
7592 "Align region, treat groups of lines separately."
7593 (interactive "r\nP")
7594 (save-excursion
7595 (let (orig pos)
7596 (goto-char beg)
7597 (beginning-of-line)
7598 (setq orig (point-marker))
7599 (setq beg (point))
7600 (goto-char end)
7601 (setq end (point-marker))
7602 (untabify beg end)
7603 (unless no-message
7604 (when vhdl-progress-interval
7605 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7606 (count-lines (point-min) end) 0))))
7607 (vhdl-fixup-whitespace-region beg end t)
7608 (goto-char beg)
7609 (if (not vhdl-align-groups)
7610 ;; align entire region
7611 (progn (vhdl-align-region-1 beg end spacing)
7612 (unless no-comments
7613 (vhdl-align-inline-comment-region-1 beg end)))
7614 ;; align groups
7615 (while (and (< beg end)
7616 (re-search-forward vhdl-align-group-separate end t))
7617 (setq pos (point-marker))
7618 (vhdl-align-region-1 beg pos spacing)
7619 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7620 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7621 (setq beg (1+ pos))
7622 (goto-char beg))
7623 ;; align last group
7624 (when (< beg end)
7625 (vhdl-align-region-1 beg end spacing)
7626 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7627 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7628 (when vhdl-indent-tabs-mode
7629 (tabify orig end))
7630 (unless no-message
7631 (when vhdl-progress-interval (message "Aligning...done"))
7632 (setq vhdl-progress-info nil)))))
7634 (defun vhdl-align-region (beg end &optional spacing)
7635 "Align region, treat blocks with same indent and argument lists separately."
7636 (interactive "r\nP")
7637 (if (not vhdl-align-same-indent)
7638 ;; align entire region
7639 (vhdl-align-region-groups beg end spacing)
7640 ;; align blocks with same indent and argument lists
7641 (save-excursion
7642 (let ((cur-beg beg)
7643 indent cur-end)
7644 (when vhdl-progress-interval
7645 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7646 (count-lines (point-min) end) 0)))
7647 (goto-char end)
7648 (setq end (point-marker))
7649 (goto-char cur-beg)
7650 (while (< (point) end)
7651 ;; is argument list opening?
7652 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7653 (point) (vhdl-point 'eol)))))
7654 ;; determine region for argument list
7655 (progn (goto-char cur-beg)
7656 (forward-sexp)
7657 (setq cur-end (point))
7658 (beginning-of-line 2))
7659 ;; determine region with same indent
7660 (setq indent (current-indentation))
7661 (setq cur-beg (point))
7662 (setq cur-end (vhdl-point 'bonl))
7663 (beginning-of-line 2)
7664 (while (and (< (point) end)
7665 (or (looking-at "^\\s-*\\(--.*\\)?$")
7666 (= (current-indentation) indent))
7667 (<= (save-excursion
7668 (nth 0 (parse-partial-sexp
7669 (point) (vhdl-point 'eol)))) 0))
7670 (unless (looking-at "^\\s-*$")
7671 (setq cur-end (vhdl-point 'bonl)))
7672 (beginning-of-line 2)))
7673 ;; align region
7674 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7675 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7676 (when vhdl-progress-interval (message "Aligning...done"))
7677 (setq vhdl-progress-info nil)))))
7679 (defun vhdl-align-group (&optional spacing)
7680 "Align group of lines between empty lines."
7681 (interactive)
7682 (vhdl-do-group 'vhdl-align-region spacing))
7684 (defun vhdl-align-list (&optional spacing)
7685 "Align the lines of a list surrounded by a balanced group of parentheses."
7686 (interactive)
7687 (vhdl-do-list 'vhdl-align-region-groups spacing))
7689 (defun vhdl-align-same-indent (&optional spacing)
7690 "Align block of lines with same indent."
7691 (interactive)
7692 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7694 (defun vhdl-align-declarations (&optional spacing)
7695 "Align the lines within the declarative part of a design unit."
7696 (interactive)
7697 (let (beg end)
7698 (vhdl-prepare-search-2
7699 (save-excursion
7700 ;; search for declarative part
7701 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7702 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7703 (setq beg (point))
7704 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7705 (setq end (point)))))
7706 (if beg
7707 (vhdl-align-region-groups beg end spacing)
7708 (error "ERROR: Not within the declarative part of a design unit"))))
7710 (defun vhdl-align-buffer ()
7711 "Align buffer."
7712 (interactive)
7713 (vhdl-align-region (point-min) (point-max)))
7715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7716 ;; Align inline comments
7718 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7719 "Align inline comments in region."
7720 (save-excursion
7721 (let ((start-max comment-column)
7722 (length-max 0)
7723 comment-list start-list tmp-list start length
7724 cur-start prev-start no-code)
7725 (setq spacing (or spacing 2))
7726 (vhdl-prepare-search-2
7727 (goto-char beg)
7728 ;; search for comment start positions and lengths
7729 (while (< (point) end)
7730 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7731 (looking-at "^\\(.*[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7732 (not (save-excursion (goto-char (match-beginning 2))
7733 (vhdl-in-literal))))
7734 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7735 (setq length (- (match-end 2) (match-beginning 2)))
7736 (setq start-max (max start start-max))
7737 (setq length-max (max length length-max))
7738 (setq comment-list (cons (cons start length) comment-list)))
7739 (beginning-of-line 2))
7740 (setq comment-list
7741 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7742 ;; reduce start positions
7743 (setq start-list (list (caar comment-list)))
7744 (setq comment-list (cdr comment-list))
7745 (while comment-list
7746 (unless (or (= (caar comment-list) (car start-list))
7747 (<= (+ (car start-list) (cdar comment-list))
7748 end-comment-column))
7749 (setq start-list (cons (caar comment-list) start-list)))
7750 (setq comment-list (cdr comment-list)))
7751 ;; align lines as nicely as possible
7752 (goto-char beg)
7753 (while (< (point) end)
7754 (setq cur-start nil)
7755 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7756 (or (and (looking-at "^\\(.*[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7757 (not (save-excursion
7758 (goto-char (match-beginning 3))
7759 (vhdl-in-literal))))
7760 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7761 (>= (- (match-end 2) (match-beginning 2))
7762 comment-column))))
7763 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7764 (setq length (- (match-end 3) (match-beginning 3)))
7765 (setq no-code (= (match-beginning 1) (match-end 1)))
7766 ;; insert minimum whitespace
7767 (goto-char (match-end 2))
7768 (delete-region (match-beginning 2) (match-end 2))
7769 (insert-char ?\ spacing)
7770 (setq tmp-list start-list)
7771 ;; insert additional whitespace to align
7772 (setq cur-start
7773 (cond
7774 ;; align comment-only line to inline comment of previous line
7775 ((and no-code prev-start
7776 (<= length (- end-comment-column prev-start)))
7777 prev-start)
7778 ;; align all comments at `start-max' if this is possible
7779 ((<= (+ start-max length-max) end-comment-column)
7780 start-max)
7781 ;; align at `comment-column' if possible
7782 ((and (<= start comment-column)
7783 (<= length (- end-comment-column comment-column)))
7784 comment-column)
7785 ;; align at left-most possible start position otherwise
7787 (while (and tmp-list (< (car tmp-list) start))
7788 (setq tmp-list (cdr tmp-list)))
7789 (car tmp-list))))
7790 (indent-to cur-start))
7791 (setq prev-start cur-start)
7792 (beginning-of-line 2))))))
7794 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7795 "Align inline comments within a region. Groups of code lines separated by
7796 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7797 (interactive "r\nP")
7798 (save-excursion
7799 (let (orig pos)
7800 (goto-char beg)
7801 (beginning-of-line)
7802 (setq orig (point-marker))
7803 (setq beg (point))
7804 (goto-char end)
7805 (setq end (point-marker))
7806 (untabify beg end)
7807 (unless no-message (message "Aligning inline comments..."))
7808 (goto-char beg)
7809 (if (not vhdl-align-groups)
7810 ;; align entire region
7811 (vhdl-align-inline-comment-region-1 beg end spacing)
7812 ;; align groups
7813 (while (and (< beg end)
7814 (re-search-forward vhdl-align-group-separate end t))
7815 (setq pos (point-marker))
7816 (vhdl-align-inline-comment-region-1 beg pos spacing)
7817 (setq beg (1+ pos))
7818 (goto-char beg))
7819 ;; align last group
7820 (when (< beg end)
7821 (vhdl-align-inline-comment-region-1 beg end spacing)))
7822 (when vhdl-indent-tabs-mode
7823 (tabify orig end))
7824 (unless no-message (message "Aligning inline comments...done")))))
7826 (defun vhdl-align-inline-comment-group (&optional spacing)
7827 "Align inline comments within a group of lines between empty lines."
7828 (interactive)
7829 (save-excursion
7830 (let ((start (point))
7831 beg end)
7832 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7833 (point-marker) (point-max)))
7834 (goto-char start)
7835 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7836 (point) (point-min)))
7837 (untabify beg end)
7838 (message "Aligning inline comments...")
7839 (vhdl-align-inline-comment-region-1 beg end)
7840 (when vhdl-indent-tabs-mode
7841 (tabify beg end))
7842 (message "Aligning inline comments...done"))))
7844 (defun vhdl-align-inline-comment-buffer ()
7845 "Align inline comments within buffer. Groups of code lines separated by
7846 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7847 (interactive)
7848 (vhdl-align-inline-comment-region (point-min) (point-max)))
7850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7851 ;; Fixup whitespace
7853 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7854 "Fixup whitespace in region. Surround operator symbols by one space,
7855 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7856 end of line, do nothing in comments and strings."
7857 (interactive "r")
7858 (unless no-message (message "Fixing up whitespace..."))
7859 (save-excursion
7860 (goto-char end)
7861 (setq end (point-marker))
7862 ;; have no space before and one space after `,' and ';'
7863 (goto-char beg)
7864 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7865 (if (match-string 1)
7866 (goto-char (match-end 1))
7867 (replace-match "\\3 " nil nil nil 2)))
7868 ;; have no space after `('
7869 (goto-char beg)
7870 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
7871 (if (match-string 1)
7872 (goto-char (match-end 1))
7873 (replace-match "\\2")))
7874 ;; have no space before `)'
7875 (goto-char beg)
7876 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7877 (if (match-string 1)
7878 (goto-char (match-end 1))
7879 (replace-match "\\2")))
7880 ;; surround operator symbols by one space
7881 (goto-char beg)
7882 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>]\\|$\\)\\)" end t)
7883 (if (or (match-string 1)
7884 (<= (match-beginning 0) ; not if at boi
7885 (save-excursion (back-to-indentation) (point))))
7886 (goto-char (match-end 0))
7887 (replace-match "\\3 \\4 \\5")
7888 (goto-char (match-end 2))))
7889 ;; eliminate multiple spaces and spaces at end of line
7890 (goto-char beg)
7891 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7892 (and (looking-at "--.*") (re-search-forward "--.*" end t))
7893 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7894 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7895 (progn (replace-match "" nil nil) t))
7896 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7897 (progn (replace-match ";" nil nil) t))
7898 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7899 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7900 (progn (replace-match " " nil nil) t))
7901 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7902 (progn (replace-match " " nil nil) t))
7903 (and (looking-at "-") (re-search-forward "-" end t))
7904 ; (re-search-forward "[^ \t-]+" end t))))
7905 (re-search-forward "[^ \t\"-]+" end t))))
7906 (unless no-message (message "Fixing up whitespace...done")))
7908 (defun vhdl-fixup-whitespace-buffer ()
7909 "Fixup whitespace in buffer. Surround operator symbols by one space,
7910 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7911 end of line, do nothing in comments."
7912 (interactive)
7913 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7915 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7916 ;; Beautify
7918 (defun vhdl-beautify-region (beg end)
7919 "Beautify region by applying indentation, whitespace fixup, alignment, and
7920 case fixing to a region. Calls functions `vhdl-indent-buffer',
7921 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7922 `vhdl-fix-case-buffer'."
7923 (interactive "r")
7924 (setq end (save-excursion (goto-char end) (point-marker)))
7925 (vhdl-indent-region beg end)
7926 (let ((vhdl-align-groups t))
7927 (vhdl-align-region beg end))
7928 (vhdl-fix-case-region beg end))
7930 (defun vhdl-beautify-buffer ()
7931 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7932 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7933 buffer."
7934 (interactive)
7935 (vhdl-beautify-region (point-min) (point-max))
7936 (when noninteractive (save-buffer)))
7938 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7939 ;; Code filling
7941 (defun vhdl-fill-region (beg end &optional arg)
7942 "Fill lines for a region of code."
7943 (interactive "r\np")
7944 (save-excursion
7945 (goto-char beg)
7946 (let ((margin (if arg (current-indentation) (current-column))))
7947 (goto-char end)
7948 (setq end (point-marker))
7949 ;; remove inline comments, newlines and whitespace
7950 (vhdl-comment-kill-region beg end)
7951 (vhdl-comment-kill-inline-region beg end)
7952 (subst-char-in-region beg (1- end) ?\n ?\ )
7953 (vhdl-fixup-whitespace-region beg end)
7954 ;; wrap and end-comment-column
7955 (goto-char beg)
7956 (while (re-search-forward "\\s-" end t)
7957 (when(> (current-column) vhdl-end-comment-column)
7958 (backward-char)
7959 (when (re-search-backward "\\s-" beg t)
7960 (replace-match "\n")
7961 (indent-to margin)))))))
7963 (defun vhdl-fill-group ()
7964 "Fill group of lines between empty lines."
7965 (interactive)
7966 (vhdl-do-group 'vhdl-fill-region))
7968 (defun vhdl-fill-list ()
7969 "Fill the lines of a list surrounded by a balanced group of parentheses."
7970 (interactive)
7971 (vhdl-do-list 'vhdl-fill-region))
7973 (defun vhdl-fill-same-indent ()
7974 "Fill the lines of block of lines with same indent."
7975 (interactive)
7976 (vhdl-do-same-indent 'vhdl-fill-region))
7979 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7980 ;;; Code updating/fixing
7981 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7984 ;; Sensitivity list update
7986 ;; Strategy:
7987 ;; - no sensitivity list is generated for processes with wait statements
7988 ;; - otherwise, do the following:
7989 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7990 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7991 ;; manually entered global signals)
7992 ;; 3. signals from 1. and 2. form the list of visible signals
7993 ;; 4. search for if/elsif conditions containing an event (sequential code)
7994 ;; 5. scan for strings that are within syntactical regions where signals are
7995 ;; read but not within sequential code, and that correspond to visible
7996 ;; signals
7997 ;; 6. replace sensitivity list by list of signals from 5.
7999 (defun vhdl-update-sensitivity-list-process ()
8000 "Update sensitivity list of current process."
8001 (interactive)
8002 (save-excursion
8003 (vhdl-prepare-search-2
8004 (end-of-line)
8005 ;; look whether in process
8006 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
8007 (equal (upcase (match-string 2)) "PROCESS")
8008 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
8009 (error "ERROR: Not within a process")
8010 (message "Updating sensitivity list...")
8011 (vhdl-update-sensitivity-list)
8012 (message "Updating sensitivity list...done")))))
8014 (defun vhdl-update-sensitivity-list-buffer ()
8015 "Update sensitivity list of all processes in current buffer."
8016 (interactive)
8017 (save-excursion
8018 (vhdl-prepare-search-2
8019 (goto-char (point-min))
8020 (message "Updating sensitivity lists...")
8021 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
8022 (goto-char (match-beginning 0))
8023 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
8024 (message "Updating sensitivity lists...done"))))
8026 (defun vhdl-update-sensitivity-list ()
8027 "Update sensitivity list."
8028 (let ((proc-beg (point))
8029 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
8030 (proc-mid (vhdl-re-search-backward
8031 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
8032 seq-region-list)
8033 (cond
8034 ;; error if 'begin' keyword missing
8035 ((not (match-string 2))
8036 (error "ERROR: No 'begin' keyword found"))
8037 ;; search for wait statement (no sensitivity list allowed)
8038 ((progn (goto-char proc-mid)
8039 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
8040 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8041 ;; combinational process (update sensitivity list)
8043 (let
8044 ;; scan for visible signals
8045 ((visible-list (vhdl-get-visible-signals))
8046 ;; define syntactic regions where signals are read
8047 (scan-regions-list
8048 '(;; right-hand side of signal/variable assignment
8049 ;; (special case: "<=" is relational operator in a condition)
8050 ((re-search-forward "[<:]=" proc-end t)
8051 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
8052 ;; if condition
8053 ((re-search-forward "^\\s-*if\\>" proc-end t)
8054 (re-search-forward "\\<then\\>" proc-end t))
8055 ;; elsif condition
8056 ((re-search-forward "\\<elsif\\>" proc-end t)
8057 (re-search-forward "\\<then\\>" proc-end t))
8058 ;; while loop condition
8059 ((re-search-forward "^\\s-*while\\>" proc-end t)
8060 (re-search-forward "\\<loop\\>" proc-end t))
8061 ;; exit/next condition
8062 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
8063 (re-search-forward ";" proc-end t))
8064 ;; assert condition
8065 ((re-search-forward "\\<assert\\>" proc-end t)
8066 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
8067 ;; case expression
8068 ((re-search-forward "^\\s-*case\\>" proc-end t)
8069 (re-search-forward "\\<is\\>" proc-end t))
8070 ;; parameter list of procedure call, array index
8071 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
8072 (1- (point)))
8073 (progn (backward-char) (forward-sexp)
8074 (while (looking-at "(") (forward-sexp)) (point)))))
8075 name field read-list sens-list signal-list
8076 sens-beg sens-end beg end margin)
8077 ;; scan for signals in old sensitivity list
8078 (goto-char proc-beg)
8079 (re-search-forward "\\<process\\>" proc-mid t)
8080 (if (not (looking-at "[ \t\n\r\f]*("))
8081 (setq sens-beg (point))
8082 (setq sens-beg (re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
8083 (goto-char (match-end 1))
8084 (forward-sexp)
8085 (setq sens-end (1- (point)))
8086 (goto-char sens-beg)
8087 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
8088 (setq sens-list
8089 (cons (downcase (match-string 0)) sens-list))
8090 (re-search-forward "\\s-*,\\s-*" sens-end t))))
8091 (setq signal-list (append visible-list sens-list))
8092 ;; search for sequential parts
8093 (goto-char proc-mid)
8094 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
8095 (setq end (re-search-forward "\\<then\\>" proc-end t))
8096 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
8097 (goto-char end)
8098 (backward-word 1)
8099 (vhdl-forward-sexp)
8100 (setq seq-region-list (cons (cons end (point)) seq-region-list))
8101 (beginning-of-line)))
8102 ;; scan for signals read in process
8103 (while scan-regions-list
8104 (goto-char proc-mid)
8105 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
8106 (setq end (eval (nth 1 (car scan-regions-list)))))
8107 (goto-char beg)
8108 (unless (or (vhdl-in-literal)
8109 (and seq-region-list
8110 (let ((tmp-list seq-region-list))
8111 (while (and tmp-list
8112 (< (point) (caar tmp-list)))
8113 (setq tmp-list (cdr tmp-list)))
8114 (and tmp-list (< (point) (cdar tmp-list))))))
8115 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
8116 (setq name (match-string 1))
8117 (when vhdl-array-index-record-field-in-sensitivity-list
8118 (setq field (match-string 2)))
8119 (when (and (not (match-string 6)) ; not when formal parameter
8120 (not (and (match-string 5) ; not event attribute
8121 (not (member (downcase (match-string 5))
8122 '("event" "last_event" "transaction")))))
8123 (member (downcase name) signal-list))
8124 (unless (member-ignore-case (concat name field) read-list)
8125 (setq read-list (cons (concat name field) read-list))))
8126 (goto-char (match-end 1)))))
8127 (setq scan-regions-list (cdr scan-regions-list)))
8128 ;; update sensitivity list
8129 (goto-char sens-beg)
8130 (if sens-end
8131 (delete-region sens-beg sens-end)
8132 (when read-list
8133 (insert " ()") (backward-char)))
8134 (setq read-list (sort read-list 'string<))
8135 (when read-list
8136 (setq margin (current-column))
8137 (insert (car read-list))
8138 (setq read-list (cdr read-list))
8139 (while read-list
8140 (insert ",")
8141 (if (<= (+ (current-column) (length (car read-list)) 2)
8142 end-comment-column)
8143 (insert " ")
8144 (insert "\n") (indent-to margin))
8145 (insert (car read-list))
8146 (setq read-list (cdr read-list)))))))))
8148 (defun vhdl-get-visible-signals ()
8149 "Get all signals visible in the current block."
8150 (let (beg end signal-list entity-name file-name)
8151 (vhdl-prepare-search-2
8152 ;; get entity name
8153 (save-excursion
8154 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
8155 (not (equal "END" (upcase (match-string 1))))
8156 (setq entity-name (match-string 2)))
8157 (error "ERROR: Not within an architecture")))
8158 ;; search for signals declared in entity port clause
8159 (save-excursion
8160 (goto-char (point-min))
8161 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
8162 (setq file-name
8163 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
8164 "." (file-name-extension (buffer-file-name)))))
8165 (vhdl-visit-file
8166 file-name t
8167 (vhdl-prepare-search-2
8168 (goto-char (point-min))
8169 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
8170 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
8171 (when (setq beg (vhdl-re-search-forward
8172 "\\<port[ \t\n\r\f]*("
8173 (save-excursion
8174 (re-search-forward "^end\\>" nil t)) t))
8175 (setq end (save-excursion
8176 (backward-char) (forward-sexp) (point)))
8177 (vhdl-forward-syntactic-ws)
8178 (while (< (point) end)
8179 (when (looking-at "signal[ \t\n\r\f]+")
8180 (goto-char (match-end 0)))
8181 (while (looking-at "\\(\\w+\\)[ \t\n\r\f,]+")
8182 (setq signal-list
8183 (cons (downcase (match-string 1)) signal-list))
8184 (goto-char (match-end 0))
8185 (vhdl-forward-syntactic-ws))
8186 (re-search-forward ";" end 1)
8187 (vhdl-forward-syntactic-ws)))))))
8188 ;; search for signals declared in architecture declarative part
8189 (save-excursion
8190 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
8191 (not (equal "END" (upcase (match-string 1))))
8192 (setq end (re-search-forward "^begin\\>" nil t))))
8193 (error "ERROR: No architecture declarative part found")
8194 ;; scan for all declared signal and alias names
8195 (goto-char beg)
8196 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8197 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8198 (if (match-string 2)
8199 ;; scan signal name
8200 (while (looking-at "[ \t\n\r\f,]+\\(\\w+\\)")
8201 (setq signal-list
8202 (cons (downcase (match-string 1)) signal-list))
8203 (goto-char (match-end 0)))
8204 ;; scan alias name, check is alias of (declared) signal
8205 (when (and (looking-at "[ \t\n\r\f]+\\(\\w+\\)[^;]*\\<is[ \t\n\r\f]+\\(\\w+\\)")
8206 (member (downcase (match-string 2)) signal-list))
8207 (setq signal-list
8208 (cons (downcase (match-string 1)) signal-list))
8209 (goto-char (match-end 0))))
8210 (setq beg (point))))))
8211 ;; search for signals declared in surrounding block declarative parts
8212 (save-excursion
8213 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
8214 (match-string 2))
8215 (goto-char (match-end 2))
8216 (vhdl-backward-sexp)
8217 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
8218 beg)
8219 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
8220 ;; scan for all declared signal names
8221 (goto-char beg)
8222 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
8223 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
8224 (if (match-string 2)
8225 ;; scan signal name
8226 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8227 (setq signal-list
8228 (cons (downcase (match-string 1)) signal-list))
8229 (goto-char (match-end 0)))
8230 ;; scan alias name, check is alias of (declared) signal
8231 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8232 (member (downcase (match-string 2)) signal-list))
8233 (setq signal-list
8234 (cons (downcase (match-string 1)) signal-list))
8235 (goto-char (match-end 0))))))
8236 (goto-char beg)))
8237 signal-list)))
8239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8240 ;; Generic/port clause fixing
8242 (defun vhdl-fix-clause-buffer ()
8243 "Fix all generic/port clauses in current buffer."
8244 (interactive)
8245 (save-excursion
8246 (vhdl-prepare-search-2
8247 (goto-char (point-min))
8248 (message "Fixing generic/port clauses...")
8249 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
8250 (goto-char (match-end 0))
8251 (condition-case nil (vhdl-fix-clause) (error "")))
8252 (message "Fixing generic/port clauses...done"))))
8254 (defun vhdl-fix-clause ()
8255 "Fix closing parenthesis within generic/port clause."
8256 (interactive)
8257 (save-excursion
8258 (vhdl-prepare-search-2
8259 (let ((pos (point))
8260 beg end)
8261 (end-of-line)
8262 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
8263 (error "ERROR: Not within a generic/port clause")
8264 ;; search for end of clause
8265 (goto-char (match-end 0))
8266 (setq beg (1- (point)))
8267 (vhdl-forward-syntactic-ws)
8268 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8269 (goto-char (1- (match-end 0)))
8270 (setq end (point-marker))
8271 (forward-char)
8272 (vhdl-forward-syntactic-ws))
8273 (goto-char end)
8274 (when (> pos (point-at-eol))
8275 (error "ERROR: Not within a generic/port clause"))
8276 ;; delete closing parenthesis on separate line (not supported style)
8277 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8278 (vhdl-line-kill)
8279 (vhdl-backward-syntactic-ws)
8280 (setq end (point-marker))
8281 (insert ";"))
8282 ;; delete superfluous parentheses
8283 (while (progn (goto-char beg)
8284 (condition-case () (forward-sexp)
8285 (error (goto-char (point-max))))
8286 (< (point) end))
8287 (delete-char -1))
8288 ;; add closing parenthesis
8289 (when (> (point) end)
8290 (goto-char end)
8291 (insert ")")))))))
8293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8294 ;; Miscellaneous
8296 (defun vhdl-remove-trailing-spaces ()
8297 "Remove trailing spaces in the whole buffer."
8298 (interactive)
8299 (save-match-data
8300 (save-excursion
8301 (goto-char (point-min))
8302 (while (re-search-forward "[ \t]+$" (point-max) t)
8303 (unless (vhdl-in-literal)
8304 (replace-match "" nil nil))))))
8307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8308 ;;; Electrification
8309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8311 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8312 "Syntax of prompt inserted by template generators.")
8314 (defvar vhdl-template-invoked-by-hook nil
8315 "Indicates whether a template has been invoked by a hook or by key or menu.
8316 Used for undoing after template abortion.")
8318 ;; correct different behavior of function `unread-command-events' in XEmacs
8319 (defun vhdl-character-to-event (arg))
8320 (defalias 'vhdl-character-to-event
8321 (if (fboundp 'character-to-event) 'character-to-event 'identity))
8323 (defun vhdl-work-library ()
8324 "Return the working library name of the current project or \"work\" if no
8325 project is defined."
8326 (vhdl-resolve-env-variable
8327 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
8329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8330 ;; Enabling/disabling
8332 (define-minor-mode vhdl-electric-mode
8333 "Toggle VHDL electric mode.
8334 With a prefix argument ARG, enable the mode if ARG is positive,
8335 and disable it otherwise. If called from Lisp, enable it if ARG
8336 is omitted or nil."
8337 :global t)
8339 (define-minor-mode vhdl-stutter-mode
8340 "Toggle VHDL stuttering mode.
8341 With a prefix argument ARG, enable the mode if ARG is positive,
8342 and disable it otherwise. If called from Lisp, enable it if ARG
8343 is omitted or nil."
8344 :global t)
8346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8347 ;; Stuttering
8349 (defun vhdl-electric-dash (count)
8350 "-- starts a comment, --- draws a horizontal line,
8351 ---- starts a display comment."
8352 (interactive "p")
8353 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
8354 (cond
8355 ((and abbrev-start-location (= abbrev-start-location (point)))
8356 (setq abbrev-start-location nil)
8357 (goto-char last-abbrev-location)
8358 (beginning-of-line nil)
8359 (vhdl-comment-display))
8360 ((/= (preceding-char) ?-) ; standard dash (minus)
8361 (self-insert-command count))
8362 (t (self-insert-command count)
8363 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8364 (let ((next-input (read-char)))
8365 (if (= next-input ?-) ; triple dash
8366 (progn
8367 (vhdl-comment-display-line)
8368 (message
8369 "Enter '-' for display comment, else continue coding")
8370 (let ((next-input (read-char)))
8371 (if (= next-input ?-) ; four dashes
8372 (vhdl-comment-display t)
8373 (setq unread-command-events ; pushback the char
8374 (list (vhdl-character-to-event next-input))))))
8375 (setq unread-command-events ; pushback the char
8376 (list (vhdl-character-to-event next-input)))
8377 (vhdl-comment-insert)))))
8378 (self-insert-command count)))
8380 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8381 (interactive "p")
8382 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8383 (if (= (preceding-char) ?\()
8384 (progn (delete-char -1) (insert-char ?\[ 1))
8385 (insert-char ?\( 1))
8386 (self-insert-command count)))
8388 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8389 (interactive "p")
8390 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8391 (progn
8392 (if (= (preceding-char) ?\))
8393 (progn (delete-char -1) (insert-char ?\] 1))
8394 (insert-char ?\) 1))
8395 (blink-matching-open))
8396 (self-insert-command count)))
8398 (defun vhdl-electric-quote (count) "'' --> \""
8399 (interactive "p")
8400 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8401 (if (= (preceding-char) last-input-event)
8402 (progn (delete-char -1) (insert-char ?\" 1))
8403 (insert-char ?\' 1))
8404 (self-insert-command count)))
8406 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8407 (interactive "p")
8408 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8409 (cond ((= (preceding-char) last-input-event)
8410 (progn (delete-char -1)
8411 (unless (eq (preceding-char) ? ) (insert " "))
8412 (insert ": ")
8413 (setq this-command 'vhdl-electric-colon)))
8414 ((and
8415 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8416 (progn (delete-char -1) (insert "= ")))
8417 (t (insert-char ?\; 1)))
8418 (self-insert-command count)))
8420 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8421 (interactive "p")
8422 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8423 (cond ((= (preceding-char) last-input-event)
8424 (progn (delete-char -1)
8425 (unless (eq (preceding-char) ? ) (insert " "))
8426 (insert "<= ")))
8427 (t (insert-char ?\, 1)))
8428 (self-insert-command count)))
8430 (defun vhdl-electric-period (count) "'..' --> ' => '"
8431 (interactive "p")
8432 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8433 (cond ((= (preceding-char) last-input-event)
8434 (progn (delete-char -1)
8435 (unless (eq (preceding-char) ? ) (insert " "))
8436 (insert "=> ")))
8437 (t (insert-char ?\. 1)))
8438 (self-insert-command count)))
8440 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8441 (interactive "p")
8442 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8443 (cond ((= (preceding-char) last-input-event)
8444 (progn (delete-char -1)
8445 (unless (eq (preceding-char) ? ) (insert " "))
8446 (insert "== ")))
8447 (t (insert-char ?\= 1)))
8448 (self-insert-command count)))
8450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8451 ;; VHDL templates
8453 (defun vhdl-template-paired-parens ()
8454 "Insert a pair of round parentheses, placing point between them."
8455 (interactive)
8456 (insert "()")
8457 (backward-char))
8459 (defun vhdl-template-alias ()
8460 "Insert alias declaration."
8461 (interactive)
8462 (let ((start (point)))
8463 (vhdl-insert-keyword "ALIAS ")
8464 (when (vhdl-template-field "name" nil t start (point))
8465 (insert " : ")
8466 (unless (vhdl-template-field
8467 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8468 nil t)
8469 (delete-char -3))
8470 (vhdl-insert-keyword " IS ")
8471 (vhdl-template-field "name" ";")
8472 (vhdl-comment-insert-inline))))
8474 (defun vhdl-template-architecture ()
8475 "Insert architecture."
8476 (interactive)
8477 (let ((margin (current-indentation))
8478 (start (point))
8479 arch-name)
8480 (vhdl-insert-keyword "ARCHITECTURE ")
8481 (when (setq arch-name
8482 (vhdl-template-field "name" nil t start (point)))
8483 (vhdl-insert-keyword " OF ")
8484 (if (save-excursion
8485 (vhdl-prepare-search-1
8486 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8487 (insert (match-string 1))
8488 (vhdl-template-field "entity name"))
8489 (vhdl-insert-keyword " IS\n")
8490 (vhdl-template-begin-end
8491 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8492 (memq vhdl-insert-empty-lines '(unit all))))))
8494 (defun vhdl-template-array (kind &optional secondary)
8495 "Insert array type definition."
8496 (interactive)
8497 (let ((start (point)))
8498 (vhdl-insert-keyword "ARRAY (")
8499 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8500 secondary)
8501 (vhdl-insert-keyword ") OF ")
8502 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8503 (vhdl-insert-keyword ";"))))
8505 (defun vhdl-template-assert ()
8506 "Insert an assertion statement."
8507 (interactive)
8508 (let ((start (point)))
8509 (vhdl-insert-keyword "ASSERT ")
8510 (when vhdl-conditions-in-parenthesis (insert "("))
8511 (when (vhdl-template-field "condition (negated)" nil t start (point))
8512 (when vhdl-conditions-in-parenthesis (insert ")"))
8513 (setq start (point))
8514 (vhdl-insert-keyword " REPORT ")
8515 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8516 (delete-region start (point)))
8517 (setq start (point))
8518 (vhdl-insert-keyword " SEVERITY ")
8519 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8520 (delete-region start (point)))
8521 (insert ";"))))
8523 (defun vhdl-template-attribute ()
8524 "Insert an attribute declaration or specification."
8525 (interactive)
8526 (if (eq (vhdl-decision-query
8527 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8528 (vhdl-template-attribute-spec)
8529 (vhdl-template-attribute-decl)))
8531 (defun vhdl-template-attribute-decl ()
8532 "Insert an attribute declaration."
8533 (interactive)
8534 (let ((start (point)))
8535 (vhdl-insert-keyword "ATTRIBUTE ")
8536 (when (vhdl-template-field "name" " : " t start (point))
8537 (vhdl-template-field "type" ";")
8538 (vhdl-comment-insert-inline))))
8540 (defun vhdl-template-attribute-spec ()
8541 "Insert an attribute specification."
8542 (interactive)
8543 (let ((start (point)))
8544 (vhdl-insert-keyword "ATTRIBUTE ")
8545 (when (vhdl-template-field "name" nil t start (point))
8546 (vhdl-insert-keyword " OF ")
8547 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8548 (vhdl-template-field "entity class")
8549 (vhdl-insert-keyword " IS ")
8550 (vhdl-template-field "expression" ";"))))
8552 (defun vhdl-template-block ()
8553 "Insert a block."
8554 (interactive)
8555 (let ((margin (current-indentation))
8556 (start (point))
8557 label)
8558 (vhdl-insert-keyword ": BLOCK ")
8559 (goto-char start)
8560 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8561 (forward-word 1)
8562 (forward-char 1)
8563 (insert "(")
8564 (if (vhdl-template-field "[guard expression]" nil t)
8565 (insert ")")
8566 (delete-char -2))
8567 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8568 (insert "\n")
8569 (vhdl-template-begin-end "BLOCK" label margin)
8570 (vhdl-comment-block))))
8572 (defun vhdl-template-block-configuration ()
8573 "Insert a block configuration statement."
8574 (interactive)
8575 (let ((margin (current-indentation))
8576 (start (point)))
8577 (vhdl-insert-keyword "FOR ")
8578 (when (vhdl-template-field "block name" nil t start (point))
8579 (vhdl-insert-keyword "\n\n")
8580 (indent-to margin)
8581 (vhdl-insert-keyword "END FOR;")
8582 (end-of-line 0)
8583 (indent-to (+ margin vhdl-basic-offset)))))
8585 (defun vhdl-template-break ()
8586 "Insert a break statement."
8587 (interactive)
8588 (let (position)
8589 (vhdl-insert-keyword "BREAK")
8590 (setq position (point))
8591 (insert " ")
8592 (while (or
8593 (progn (vhdl-insert-keyword "FOR ")
8594 (if (vhdl-template-field "[quantity name]" " USE " t)
8595 (progn (vhdl-template-field "quantity name" " => ") t)
8596 (delete-region (point)
8597 (progn (forward-word -1) (point)))
8598 nil))
8599 (vhdl-template-field "[quantity name]" " => " t))
8600 (vhdl-template-field "expression")
8601 (setq position (point))
8602 (insert ", "))
8603 (delete-region position (point))
8604 (unless (vhdl-sequential-statement-p)
8605 (vhdl-insert-keyword " ON ")
8606 (if (vhdl-template-field "[sensitivity list]" nil t)
8607 (setq position (point))
8608 (delete-region position (point))))
8609 (vhdl-insert-keyword " WHEN ")
8610 (when vhdl-conditions-in-parenthesis (insert "("))
8611 (if (vhdl-template-field "[condition]" nil t)
8612 (when vhdl-conditions-in-parenthesis (insert ")"))
8613 (delete-region position (point)))
8614 (insert ";")))
8616 (defun vhdl-template-case (&optional kind)
8617 "Insert a case statement."
8618 (interactive)
8619 (let ((margin (current-indentation))
8620 (start (point))
8621 label)
8622 (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
8623 (not (vhdl-standard-p 'ams))) 'is 'use)))
8624 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8625 (vhdl-insert-keyword "CASE ")
8626 (vhdl-insert-keyword ": CASE ")
8627 (goto-char start)
8628 (setq label (vhdl-template-field "[label]" nil t))
8629 (unless label (delete-char 2))
8630 (forward-word 1)
8631 (forward-char 1))
8632 (when (vhdl-template-field "expression" nil t start (point))
8633 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8634 (indent-to margin)
8635 (vhdl-insert-keyword "END CASE")
8636 (when label (insert " " label))
8637 (insert ";")
8638 (forward-line -1)
8639 (indent-to (+ margin vhdl-basic-offset))
8640 (vhdl-insert-keyword "WHEN ")
8641 (let ((position (point)))
8642 (insert " => ;\n")
8643 (indent-to (+ margin vhdl-basic-offset))
8644 (vhdl-insert-keyword "WHEN OTHERS => null;")
8645 (goto-char position)))))
8647 (defun vhdl-template-case-is ()
8648 "Insert a sequential case statement."
8649 (interactive)
8650 (vhdl-template-case 'is))
8652 (defun vhdl-template-case-use ()
8653 "Insert a simultaneous case statement."
8654 (interactive)
8655 (vhdl-template-case 'use))
8657 (defun vhdl-template-component ()
8658 "Insert a component declaration."
8659 (interactive)
8660 (vhdl-template-component-decl))
8662 (defun vhdl-template-component-conf ()
8663 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8664 since these are almost equivalent)."
8665 (interactive)
8666 (let ((margin (current-indentation))
8667 (result (vhdl-template-configuration-spec t)))
8668 (when result
8669 (insert "\n")
8670 (indent-to margin)
8671 (vhdl-insert-keyword "END FOR;")
8672 (when (eq result 'no-use)
8673 (end-of-line -0)))))
8675 (defun vhdl-template-component-decl ()
8676 "Insert a component declaration."
8677 (interactive)
8678 (let ((margin (current-indentation))
8679 (start (point))
8680 name end-column)
8681 (vhdl-insert-keyword "COMPONENT ")
8682 (when (setq name (vhdl-template-field "name" nil t start (point)))
8683 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8684 (insert "\n\n")
8685 (indent-to margin)
8686 (vhdl-insert-keyword "END COMPONENT")
8687 (unless (vhdl-standard-p '87) (insert " " name))
8688 (insert ";")
8689 (setq end-column (current-column))
8690 (end-of-line -0)
8691 (indent-to (+ margin vhdl-basic-offset))
8692 (vhdl-template-generic-list t t)
8693 (insert "\n")
8694 (indent-to (+ margin vhdl-basic-offset))
8695 (vhdl-template-port-list t)
8696 (beginning-of-line 2)
8697 (forward-char end-column))))
8699 (defun vhdl-template-component-inst ()
8700 "Insert a component instantiation statement."
8701 (interactive)
8702 (let ((margin (current-indentation))
8703 (start (point))
8704 unit position)
8705 (when (vhdl-template-field "instance label" nil t start (point))
8706 (insert ": ")
8707 (if (not (vhdl-use-direct-instantiation))
8708 (vhdl-template-field "component name")
8709 ;; direct instantiation
8710 (setq unit (vhdl-template-field
8711 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8712 (setq unit (upcase (or unit "")))
8713 (cond ((equal unit "ENTITY")
8714 (vhdl-template-field "library name" "." nil nil nil nil
8715 (vhdl-work-library))
8716 (vhdl-template-field "entity name" "(")
8717 (if (vhdl-template-field "[architecture name]" nil t)
8718 (insert ")")
8719 (delete-char -1)))
8720 ((equal unit "CONFIGURATION")
8721 (vhdl-template-field "library name" "." nil nil nil nil
8722 (vhdl-work-library))
8723 (vhdl-template-field "configuration name"))
8724 (t (vhdl-template-field "component name"))))
8725 (insert "\n")
8726 (indent-to (+ margin vhdl-basic-offset))
8727 (setq position (point))
8728 (vhdl-insert-keyword "GENERIC ")
8729 (when (vhdl-template-map position t t)
8730 (insert "\n")
8731 (indent-to (+ margin vhdl-basic-offset)))
8732 (setq position (point))
8733 (vhdl-insert-keyword "PORT ")
8734 (unless (vhdl-template-map position t t)
8735 (delete-region (line-beginning-position) (point))
8736 (delete-char -1))
8737 (insert ";"))))
8739 (defun vhdl-template-conditional-signal-asst ()
8740 "Insert a conditional signal assignment."
8741 (interactive)
8742 (when (vhdl-template-field "target signal")
8743 (insert " <= ")
8744 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8745 ; (insert " "))
8746 (let ((margin (current-column))
8747 (start (point))
8748 position)
8749 (vhdl-template-field "waveform")
8750 (setq position (point))
8751 (vhdl-insert-keyword " WHEN ")
8752 (when vhdl-conditions-in-parenthesis (insert "("))
8753 (while (and (vhdl-template-field "[condition]" nil t)
8754 (progn
8755 (when vhdl-conditions-in-parenthesis (insert ")"))
8756 (setq position (point))
8757 (vhdl-insert-keyword " ELSE")
8758 (insert "\n")
8759 (indent-to margin)
8760 (vhdl-template-field "[waveform]" nil t)))
8761 (setq position (point))
8762 (vhdl-insert-keyword " WHEN ")
8763 (when vhdl-conditions-in-parenthesis (insert "(")))
8764 (delete-region position (point))
8765 (insert ";")
8766 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8768 (defun vhdl-template-configuration ()
8769 "Insert a configuration specification if within an architecture,
8770 a block or component configuration if within a configuration declaration,
8771 a configuration declaration if not within a design unit."
8772 (interactive)
8773 (vhdl-prepare-search-1
8774 (cond
8775 ((and (save-excursion ; architecture body
8776 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8777 (equal "ARCHITECTURE" (upcase (match-string 1))))
8778 (vhdl-template-configuration-spec))
8779 ((and (save-excursion ; configuration declaration
8780 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8781 (equal "CONFIGURATION" (upcase (match-string 1))))
8782 (if (eq (vhdl-decision-query
8783 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8784 (vhdl-template-component-conf)
8785 (vhdl-template-block-configuration)))
8786 (t (vhdl-template-configuration-decl))))) ; otherwise
8788 (defun vhdl-template-configuration-spec (&optional optional-use)
8789 "Insert a configuration specification."
8790 (interactive)
8791 (let ((margin (current-indentation))
8792 (start (point))
8793 aspect position)
8794 (vhdl-insert-keyword "FOR ")
8795 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8796 t start (point))
8797 (vhdl-template-field "component name" "\n")
8798 (indent-to (+ margin vhdl-basic-offset))
8799 (setq start (point))
8800 (vhdl-insert-keyword "USE ")
8801 (if (and optional-use
8802 (not (setq aspect (vhdl-template-field
8803 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8804 (progn (delete-region start (point)) 'no-use)
8805 (unless optional-use
8806 (setq aspect (vhdl-template-field
8807 "ENTITY | CONFIGURATION | OPEN" " ")))
8808 (setq aspect (upcase (or aspect "")))
8809 (cond ((equal aspect "ENTITY")
8810 (vhdl-template-field "library name" "." nil nil nil nil
8811 (vhdl-work-library))
8812 (vhdl-template-field "entity name" "(")
8813 (if (vhdl-template-field "[architecture name]" nil t)
8814 (insert ")")
8815 (delete-char -1))
8816 (insert "\n")
8817 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8818 (setq position (point))
8819 (vhdl-insert-keyword "GENERIC ")
8820 (when (vhdl-template-map position t t)
8821 (insert "\n")
8822 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8823 (setq position (point))
8824 (vhdl-insert-keyword "PORT ")
8825 (unless (vhdl-template-map position t t)
8826 (delete-region (line-beginning-position) (point))
8827 (delete-char -1))
8828 (insert ";")
8830 ((equal aspect "CONFIGURATION")
8831 (vhdl-template-field "library name" "." nil nil nil nil
8832 (vhdl-work-library))
8833 (vhdl-template-field "configuration name" ";"))
8834 (t (delete-char -1) (insert ";") t))))))
8837 (defun vhdl-template-configuration-decl ()
8838 "Insert a configuration declaration."
8839 (interactive)
8840 (let ((margin (current-indentation))
8841 (start (point))
8842 entity-exists string name position)
8843 (vhdl-insert-keyword "CONFIGURATION ")
8844 (when (setq name (vhdl-template-field "name" nil t start (point)))
8845 (vhdl-insert-keyword " OF ")
8846 (save-excursion
8847 (vhdl-prepare-search-1
8848 (setq entity-exists (vhdl-re-search-backward
8849 "\\<entity \\(\\w*\\) is\\>" nil t))
8850 (setq string (match-string 1))))
8851 (if (and entity-exists (not (equal string "")))
8852 (insert string)
8853 (vhdl-template-field "entity name"))
8854 (vhdl-insert-keyword " IS\n")
8855 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8856 (indent-to (+ margin vhdl-basic-offset))
8857 (setq position (point))
8858 (insert "\n")
8859 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8860 (indent-to margin)
8861 (vhdl-insert-keyword "END ")
8862 (unless (vhdl-standard-p '87)
8863 (vhdl-insert-keyword "CONFIGURATION "))
8864 (insert name ";")
8865 (goto-char position))))
8867 (defun vhdl-template-constant ()
8868 "Insert a constant declaration."
8869 (interactive)
8870 (let ((start (point))
8871 (in-arglist (vhdl-in-argument-list-p)))
8872 (vhdl-insert-keyword "CONSTANT ")
8873 (when (vhdl-template-field "name" nil t start (point))
8874 (insert " : ")
8875 (when in-arglist (vhdl-insert-keyword "IN "))
8876 (vhdl-template-field "type")
8877 (if in-arglist
8878 (progn (insert ";")
8879 (vhdl-comment-insert-inline))
8880 (let ((position (point)))
8881 (insert " := ")
8882 (unless (vhdl-template-field "[initialization]" nil t)
8883 (delete-region position (point)))
8884 (insert ";")
8885 (vhdl-comment-insert-inline))))))
8887 (defun vhdl-template-default ()
8888 "Insert nothing."
8889 (interactive)
8890 (insert " ")
8891 (unexpand-abbrev)
8892 (backward-word 1)
8893 (vhdl-case-word 1)
8894 (forward-char 1))
8896 (defun vhdl-template-default-indent ()
8897 "Insert nothing and indent."
8898 (interactive)
8899 (insert " ")
8900 (unexpand-abbrev)
8901 (backward-word 1)
8902 (vhdl-case-word 1)
8903 (forward-char 1)
8904 (indent-according-to-mode))
8906 (defun vhdl-template-disconnect ()
8907 "Insert a disconnect statement."
8908 (interactive)
8909 (let ((start (point)))
8910 (vhdl-insert-keyword "DISCONNECT ")
8911 (when (vhdl-template-field "signal names | OTHERS | ALL"
8912 " : " t start (point))
8913 (vhdl-template-field "type")
8914 (vhdl-insert-keyword " AFTER ")
8915 (vhdl-template-field "time expression" ";"))))
8917 (defun vhdl-template-else ()
8918 "Insert an else statement."
8919 (interactive)
8920 (let (margin)
8921 (vhdl-prepare-search-1
8922 (vhdl-insert-keyword "ELSE")
8923 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8924 (equal "WHEN" (upcase (match-string 1))))
8925 (insert " ")
8926 (indent-according-to-mode)
8927 (setq margin (current-indentation))
8928 (insert "\n")
8929 (indent-to (+ margin vhdl-basic-offset))))))
8931 (defun vhdl-template-elsif ()
8932 "Insert an elsif statement."
8933 (interactive)
8934 (let ((start (point))
8935 margin)
8936 (vhdl-insert-keyword "ELSIF ")
8937 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8938 (when vhdl-conditions-in-parenthesis (insert "("))
8939 (when (vhdl-template-field "condition" nil t start (point))
8940 (when vhdl-conditions-in-parenthesis (insert ")"))
8941 (indent-according-to-mode)
8942 (setq margin (current-indentation))
8943 (vhdl-insert-keyword
8944 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8945 (indent-to (+ margin vhdl-basic-offset))))))
8947 (defun vhdl-template-entity ()
8948 "Insert an entity."
8949 (interactive)
8950 (let ((margin (current-indentation))
8951 (start (point))
8952 name end-column)
8953 (vhdl-insert-keyword "ENTITY ")
8954 (when (setq name (vhdl-template-field "name" nil t start (point)))
8955 (vhdl-insert-keyword " IS\n\n")
8956 (indent-to margin)
8957 (vhdl-insert-keyword "END ")
8958 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8959 (insert name ";")
8960 (setq end-column (current-column))
8961 (end-of-line -0)
8962 (indent-to (+ margin vhdl-basic-offset))
8963 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8964 (indent-to (+ margin vhdl-basic-offset))
8965 (when (vhdl-template-generic-list t)
8966 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8967 (insert "\n")
8968 (indent-to (+ margin vhdl-basic-offset))
8969 (when (vhdl-template-port-list t)
8970 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8971 (beginning-of-line 2)
8972 (forward-char end-column))))
8974 (defun vhdl-template-exit ()
8975 "Insert an exit statement."
8976 (interactive)
8977 (let ((start (point)))
8978 (vhdl-insert-keyword "EXIT ")
8979 (if (vhdl-template-field "[loop label]" nil t start (point))
8980 (let ((position (point)))
8981 (vhdl-insert-keyword " WHEN ")
8982 (when vhdl-conditions-in-parenthesis (insert "("))
8983 (if (vhdl-template-field "[condition]" nil t)
8984 (when vhdl-conditions-in-parenthesis (insert ")"))
8985 (delete-region position (point))))
8986 (delete-char -1))
8987 (insert ";")))
8989 (defun vhdl-template-file ()
8990 "Insert a file declaration."
8991 (interactive)
8992 (let ((start (point)))
8993 (vhdl-insert-keyword "FILE ")
8994 (when (vhdl-template-field "name" nil t start (point))
8995 (insert " : ")
8996 (vhdl-template-field "type")
8997 (unless (vhdl-standard-p '87)
8998 (vhdl-insert-keyword " OPEN ")
8999 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9000 nil t)
9001 (delete-char -6)))
9002 (vhdl-insert-keyword " IS ")
9003 (when (vhdl-standard-p '87)
9004 (vhdl-template-field "[IN | OUT]" " " t))
9005 (vhdl-template-field "filename-string" nil nil nil nil t)
9006 (insert ";")
9007 (vhdl-comment-insert-inline))))
9009 (defun vhdl-template-for ()
9010 "Insert a block or component configuration if within a configuration
9011 declaration, a configuration specification if within an architecture
9012 declarative part (and not within a subprogram), a for-loop if within a
9013 sequential statement part (subprogram or process), and a for-generate
9014 otherwise."
9015 (interactive)
9016 (vhdl-prepare-search-1
9017 (cond
9018 ((vhdl-sequential-statement-p) ; sequential statement
9019 (vhdl-template-for-loop))
9020 ((and (save-excursion ; configuration declaration
9021 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
9022 (equal "CONFIGURATION" (upcase (match-string 1))))
9023 (if (eq (vhdl-decision-query
9024 "for" "(b)lock or (c)omponent configuration?" t) ?c)
9025 (vhdl-template-component-conf)
9026 (vhdl-template-block-configuration)))
9027 ((and (save-excursion
9028 (re-search-backward ; architecture declarative part
9029 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
9030 (equal "ARCHITECTURE" (upcase (match-string 1))))
9031 (vhdl-template-configuration-spec))
9032 (t (vhdl-template-for-generate))))) ; concurrent statement
9034 (defun vhdl-template-for-generate ()
9035 "Insert a for-generate."
9036 (interactive)
9037 (let ((margin (current-indentation))
9038 (start (point))
9039 label position)
9040 (vhdl-insert-keyword ": FOR ")
9041 (setq position (point-marker))
9042 (goto-char start)
9043 (when (setq label (vhdl-template-field "label" nil t start position))
9044 (goto-char position)
9045 (vhdl-template-field "loop variable")
9046 (vhdl-insert-keyword " IN ")
9047 (vhdl-template-field "range")
9048 (vhdl-template-generate-body margin label))))
9050 (defun vhdl-template-for-loop ()
9051 "Insert a for loop."
9052 (interactive)
9053 (let ((margin (current-indentation))
9054 (start (point))
9055 label index)
9056 (if (not (eq vhdl-optional-labels 'all))
9057 (vhdl-insert-keyword "FOR ")
9058 (vhdl-insert-keyword ": FOR ")
9059 (goto-char start)
9060 (setq label (vhdl-template-field "[label]" nil t))
9061 (unless label (delete-char 2))
9062 (forward-word 1)
9063 (forward-char 1))
9064 (when (setq index (vhdl-template-field "loop variable"
9065 nil t start (point)))
9066 (vhdl-insert-keyword " IN ")
9067 (vhdl-template-field "range")
9068 (vhdl-insert-keyword " LOOP\n\n")
9069 (indent-to margin)
9070 (vhdl-insert-keyword "END LOOP")
9071 (if label
9072 (insert " " label ";")
9073 (insert ";")
9074 (when vhdl-self-insert-comments (insert " -- " index)))
9075 (forward-line -1)
9076 (indent-to (+ margin vhdl-basic-offset)))))
9078 (defun vhdl-template-function (&optional kind)
9079 "Insert a function declaration or body."
9080 (interactive)
9081 (let ((margin (current-indentation))
9082 (start (point))
9083 name)
9084 (vhdl-insert-keyword "FUNCTION ")
9085 (when (setq name (vhdl-template-field "name" nil t start (point)))
9086 (vhdl-template-argument-list t)
9087 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9088 (end-of-line)
9089 (insert "\n")
9090 (indent-to (+ margin vhdl-basic-offset))
9091 (vhdl-insert-keyword "RETURN ")
9092 (vhdl-template-field "type")
9093 (if (if kind (eq kind 'body)
9094 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9095 (progn (vhdl-insert-keyword " IS\n")
9096 (vhdl-template-begin-end
9097 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
9098 (vhdl-comment-block))
9099 (insert ";")))))
9101 (defun vhdl-template-function-decl ()
9102 "Insert a function declaration."
9103 (interactive)
9104 (vhdl-template-function 'decl))
9106 (defun vhdl-template-function-body ()
9107 "Insert a function declaration."
9108 (interactive)
9109 (vhdl-template-function 'body))
9111 (defun vhdl-template-generate ()
9112 "Insert a generation scheme."
9113 (interactive)
9114 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
9115 (vhdl-template-if-generate)
9116 (vhdl-template-for-generate)))
9118 (defun vhdl-template-generic ()
9119 "Insert generic declaration, or generic map in instantiation statements."
9120 (interactive)
9121 (let ((start (point)))
9122 (vhdl-prepare-search-1
9123 (cond
9124 ((and (save-excursion ; entity declaration
9125 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9126 (equal "ENTITY" (upcase (match-string 1))))
9127 (vhdl-template-generic-list nil))
9128 ((or (save-excursion
9129 (or (beginning-of-line)
9130 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9131 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9132 (vhdl-insert-keyword "GENERIC ")
9133 (vhdl-template-map start))
9134 (t (vhdl-template-generic-list nil t))))))
9136 (defun vhdl-template-group ()
9137 "Insert group or group template declaration."
9138 (interactive)
9139 (let ((start (point)))
9140 (if (eq (vhdl-decision-query
9141 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
9142 (vhdl-template-group-template)
9143 (vhdl-template-group-decl))))
9145 (defun vhdl-template-group-decl ()
9146 "Insert group declaration."
9147 (interactive)
9148 (let ((start (point)))
9149 (vhdl-insert-keyword "GROUP ")
9150 (when (vhdl-template-field "name" " : " t start (point))
9151 (vhdl-template-field "template name" " (")
9152 (vhdl-template-field "constituent list" ");")
9153 (vhdl-comment-insert-inline))))
9155 (defun vhdl-template-group-template ()
9156 "Insert group template declaration."
9157 (interactive)
9158 (let ((start (point)))
9159 (vhdl-insert-keyword "GROUP ")
9160 (when (vhdl-template-field "template name" nil t start (point))
9161 (vhdl-insert-keyword " IS (")
9162 (vhdl-template-field "entity class list" ");")
9163 (vhdl-comment-insert-inline))))
9165 (defun vhdl-template-if ()
9166 "Insert a sequential if statement or an if-generate statement."
9167 (interactive)
9168 (if (vhdl-sequential-statement-p)
9169 (vhdl-template-if-then)
9170 (if (and (vhdl-standard-p 'ams)
9171 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
9172 (vhdl-template-if-use)
9173 (vhdl-template-if-generate))))
9175 (defun vhdl-template-if-generate ()
9176 "Insert an if-generate."
9177 (interactive)
9178 (let ((margin (current-indentation))
9179 (start (point))
9180 label position)
9181 (vhdl-insert-keyword ": IF ")
9182 (setq position (point-marker))
9183 (goto-char start)
9184 (when (setq label (vhdl-template-field "label" nil t start position))
9185 (goto-char position)
9186 (when vhdl-conditions-in-parenthesis (insert "("))
9187 (vhdl-template-field "condition")
9188 (when vhdl-conditions-in-parenthesis (insert ")"))
9189 (vhdl-template-generate-body margin label))))
9191 (defun vhdl-template-if-then-use (kind)
9192 "Insert a sequential if statement."
9193 (interactive)
9194 (let ((margin (current-indentation))
9195 (start (point))
9196 label)
9197 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
9198 (vhdl-insert-keyword "IF ")
9199 (vhdl-insert-keyword ": IF ")
9200 (goto-char start)
9201 (setq label (vhdl-template-field "[label]" nil t))
9202 (unless label (delete-char 2))
9203 (forward-word 1)
9204 (forward-char 1))
9205 (when vhdl-conditions-in-parenthesis (insert "("))
9206 (when (vhdl-template-field "condition" nil t start (point))
9207 (when vhdl-conditions-in-parenthesis (insert ")"))
9208 (vhdl-insert-keyword
9209 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
9210 (indent-to margin)
9211 (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
9212 (when label (insert " " label))
9213 (insert ";")
9214 (forward-line -1)
9215 (indent-to (+ margin vhdl-basic-offset)))))
9217 (defun vhdl-template-if-then ()
9218 "Insert a sequential if statement."
9219 (interactive)
9220 (vhdl-template-if-then-use 'then))
9222 (defun vhdl-template-if-use ()
9223 "Insert a simultaneous if statement."
9224 (interactive)
9225 (vhdl-template-if-then-use 'use))
9227 (defun vhdl-template-instance ()
9228 "Insert a component instantiation statement."
9229 (interactive)
9230 (vhdl-template-component-inst))
9232 (defun vhdl-template-library ()
9233 "Insert a library specification."
9234 (interactive)
9235 (let ((margin (current-indentation))
9236 (start (point))
9237 name end-pos)
9238 (vhdl-insert-keyword "LIBRARY ")
9239 (when (setq name (vhdl-template-field "names" nil t start (point)))
9240 (insert ";")
9241 (unless (string-match "," name)
9242 (setq end-pos (point))
9243 (insert "\n")
9244 (indent-to margin)
9245 (vhdl-insert-keyword "USE ")
9246 (insert name)
9247 (vhdl-insert-keyword "..ALL;")
9248 (backward-char 5)
9249 (if (vhdl-template-field "package name")
9250 (forward-char 5)
9251 (delete-region end-pos (+ (point) 5)))))))
9253 (defun vhdl-template-limit ()
9254 "Insert a limit."
9255 (interactive)
9256 (let ((start (point)))
9257 (vhdl-insert-keyword "LIMIT ")
9258 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9259 t start (point))
9260 (vhdl-template-field "type")
9261 (vhdl-insert-keyword " WITH ")
9262 (vhdl-template-field "real expression" ";"))))
9264 (defun vhdl-template-loop ()
9265 "Insert a loop."
9266 (interactive)
9267 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9268 (cond ((eq char ?w)
9269 (vhdl-template-while-loop))
9270 ((eq char ?f)
9271 (vhdl-template-for-loop))
9272 (t (vhdl-template-bare-loop)))))
9274 (defun vhdl-template-bare-loop ()
9275 "Insert a loop."
9276 (interactive)
9277 (let ((margin (current-indentation))
9278 (start (point))
9279 label)
9280 (if (not (eq vhdl-optional-labels 'all))
9281 (vhdl-insert-keyword "LOOP ")
9282 (vhdl-insert-keyword ": LOOP ")
9283 (goto-char start)
9284 (setq label (vhdl-template-field "[label]" nil t))
9285 (unless label (delete-char 2))
9286 (forward-word 1)
9287 (delete-char 1))
9288 (insert "\n\n")
9289 (indent-to margin)
9290 (vhdl-insert-keyword "END LOOP")
9291 (insert (if label (concat " " label ";") ";"))
9292 (forward-line -1)
9293 (indent-to (+ margin vhdl-basic-offset))))
9295 (defun vhdl-template-map (&optional start optional secondary)
9296 "Insert a map specification with association list."
9297 (interactive)
9298 (let ((start (or start (point)))
9299 margin end-pos)
9300 (vhdl-insert-keyword "MAP (")
9301 (if (not vhdl-association-list-with-formals)
9302 (if (vhdl-template-field
9303 (concat (and optional "[") "association list" (and optional "]"))
9304 ")" (or (not secondary) optional)
9305 (and (not secondary) start) (point))
9307 (if (and optional secondary) (delete-region start (point)))
9308 nil)
9309 (if vhdl-argument-list-indent
9310 (setq margin (current-column))
9311 (setq margin (+ (current-indentation) vhdl-basic-offset))
9312 (insert "\n")
9313 (indent-to margin))
9314 (if (vhdl-template-field
9315 (concat (and optional "[") "formal" (and optional "]"))
9316 " => " (or (not secondary) optional)
9317 (and (not secondary) start) (point))
9318 (progn
9319 (vhdl-template-field "actual" ",")
9320 (setq end-pos (point))
9321 (insert "\n")
9322 (indent-to margin)
9323 (while (vhdl-template-field "[formal]" " => " t)
9324 (vhdl-template-field "actual" ",")
9325 (setq end-pos (point))
9326 (insert "\n")
9327 (indent-to margin))
9328 (delete-region end-pos (point))
9329 (delete-char -1)
9330 (insert ")")
9331 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9333 (when (and optional secondary) (delete-region start (point)))
9334 nil))))
9336 (defun vhdl-template-modify (&optional noerror)
9337 "Actualize modification date."
9338 (interactive)
9339 (vhdl-prepare-search-2
9340 (save-excursion
9341 (goto-char (point-min))
9342 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9343 (progn (delete-region (point) (progn (end-of-line) (point)))
9344 (vhdl-template-insert-date))
9345 (unless noerror
9346 (error "ERROR: Modification date prefix string \"%s\" not found"
9347 vhdl-modify-date-prefix-string))))))
9350 (defun vhdl-template-modify-noerror ()
9351 "Call `vhdl-template-modify' with NOERROR non-nil."
9352 (vhdl-template-modify t))
9354 (defun vhdl-template-nature ()
9355 "Insert a nature declaration."
9356 (interactive)
9357 (let ((start (point))
9358 name mid-pos end-pos)
9359 (vhdl-insert-keyword "NATURE ")
9360 (when (setq name (vhdl-template-field "name" nil t start (point)))
9361 (vhdl-insert-keyword " IS ")
9362 (let ((definition
9363 (upcase
9364 (or (vhdl-template-field
9365 "across type | ARRAY | RECORD")
9366 ""))))
9367 (cond ((equal definition "")
9368 (insert ";"))
9369 ((equal definition "ARRAY")
9370 (delete-region (point) (progn (forward-word -1) (point)))
9371 (vhdl-template-array 'nature t))
9372 ((equal definition "RECORD")
9373 (setq mid-pos (point-marker))
9374 (delete-region (point) (progn (forward-word -1) (point)))
9375 (vhdl-template-record 'nature name t))
9377 (vhdl-insert-keyword " ACROSS ")
9378 (vhdl-template-field "through type")
9379 (vhdl-insert-keyword " THROUGH ")
9380 (vhdl-template-field "reference name")
9381 (vhdl-insert-keyword " REFERENCE;")))
9382 (when mid-pos
9383 (setq end-pos (point-marker))
9384 (goto-char mid-pos)
9385 (end-of-line))
9386 (vhdl-comment-insert-inline)
9387 (when end-pos (goto-char end-pos))))))
9389 (defun vhdl-template-next ()
9390 "Insert a next statement."
9391 (interactive)
9392 (let ((start (point)))
9393 (vhdl-insert-keyword "NEXT ")
9394 (if (vhdl-template-field "[loop label]" nil t start (point))
9395 (let ((position (point)))
9396 (vhdl-insert-keyword " WHEN ")
9397 (when vhdl-conditions-in-parenthesis (insert "("))
9398 (if (vhdl-template-field "[condition]" nil t)
9399 (when vhdl-conditions-in-parenthesis (insert ")"))
9400 (delete-region position (point))))
9401 (delete-char -1))
9402 (insert ";")))
9404 (defun vhdl-template-others ()
9405 "Insert an others aggregate."
9406 (interactive)
9407 (let ((start (point)))
9408 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9409 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9410 (vhdl-insert-keyword "OTHERS => '")
9411 (when (vhdl-template-field "value" nil t start (point))
9412 (insert "')")))
9413 (vhdl-insert-keyword "OTHERS "))))
9415 (defun vhdl-template-package (&optional kind)
9416 "Insert a package specification or body."
9417 (interactive)
9418 (let ((margin (current-indentation))
9419 (start (point))
9420 name body position)
9421 (vhdl-insert-keyword "PACKAGE ")
9422 (setq body (if kind (eq kind 'body)
9423 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
9424 (when body
9425 (vhdl-insert-keyword "BODY ")
9426 (when (save-excursion
9427 (vhdl-prepare-search-1
9428 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9429 (insert (setq name (match-string 1)))))
9430 (when (or name
9431 (setq name (vhdl-template-field "name" nil t start (point))))
9432 (vhdl-insert-keyword " IS\n")
9433 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9434 (indent-to (+ margin vhdl-basic-offset))
9435 (setq position (point))
9436 (insert "\n")
9437 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9438 (indent-to margin)
9439 (vhdl-insert-keyword "END ")
9440 (unless (vhdl-standard-p '87)
9441 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9442 (insert (or name "") ";")
9443 (goto-char position))))
9445 (defun vhdl-template-package-decl ()
9446 "Insert a package specification."
9447 (interactive)
9448 (vhdl-template-package 'decl))
9450 (defun vhdl-template-package-body ()
9451 "Insert a package body."
9452 (interactive)
9453 (vhdl-template-package 'body))
9455 (defun vhdl-template-port ()
9456 "Insert a port declaration, or port map in instantiation statements."
9457 (interactive)
9458 (let ((start (point)))
9459 (vhdl-prepare-search-1
9460 (cond
9461 ((and (save-excursion ; entity declaration
9462 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9463 (equal "ENTITY" (upcase (match-string 1))))
9464 (vhdl-template-port-list nil))
9465 ((or (save-excursion
9466 (or (beginning-of-line)
9467 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9468 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9469 (vhdl-insert-keyword "PORT ")
9470 (vhdl-template-map start))
9471 (t (vhdl-template-port-list nil))))))
9473 (defun vhdl-template-procedural ()
9474 "Insert a procedural."
9475 (interactive)
9476 (let ((margin (current-indentation))
9477 (start (point))
9478 (case-fold-search t)
9479 label)
9480 (vhdl-insert-keyword "PROCEDURAL ")
9481 (when (memq vhdl-optional-labels '(process all))
9482 (goto-char start)
9483 (insert ": ")
9484 (goto-char start)
9485 (setq label (vhdl-template-field "[label]" nil t))
9486 (unless label (delete-char 2))
9487 (forward-word 1)
9488 (forward-char 1))
9489 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9490 (insert "\n")
9491 (vhdl-template-begin-end "PROCEDURAL" label margin)
9492 (vhdl-comment-block)))
9494 (defun vhdl-template-procedure (&optional kind)
9495 "Insert a procedure declaration or body."
9496 (interactive)
9497 (let ((margin (current-indentation))
9498 (start (point))
9499 name)
9500 (vhdl-insert-keyword "PROCEDURE ")
9501 (when (setq name (vhdl-template-field "name" nil t start (point)))
9502 (vhdl-template-argument-list)
9503 (if (if kind (eq kind 'body)
9504 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9505 (progn (vhdl-insert-keyword " IS")
9506 (when vhdl-auto-align
9507 (vhdl-align-region-groups start (point) 1))
9508 (end-of-line) (insert "\n")
9509 (vhdl-template-begin-end
9510 (unless (vhdl-standard-p '87) "PROCEDURE")
9511 name margin)
9512 (vhdl-comment-block))
9513 (insert ";")
9514 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9515 (end-of-line)))))
9517 (defun vhdl-template-procedure-decl ()
9518 "Insert a procedure declaration."
9519 (interactive)
9520 (vhdl-template-procedure 'decl))
9522 (defun vhdl-template-procedure-body ()
9523 "Insert a procedure body."
9524 (interactive)
9525 (vhdl-template-procedure 'body))
9527 (defun vhdl-template-process (&optional kind)
9528 "Insert a process."
9529 (interactive)
9530 (let ((margin (current-indentation))
9531 (start (point))
9532 (reset-kind vhdl-reset-kind)
9533 label seq input-signals clock reset final-pos)
9534 (setq seq (if kind (eq kind 'seq)
9535 (eq (vhdl-decision-query
9536 "process" "(c)ombinational or (s)equential?" t) ?s)))
9537 (vhdl-insert-keyword "PROCESS ")
9538 (when (memq vhdl-optional-labels '(process all))
9539 (goto-char start)
9540 (insert ": ")
9541 (goto-char start)
9542 (setq label (vhdl-template-field "[label]" nil t))
9543 (unless label (delete-char 2))
9544 (forward-word 1)
9545 (forward-char 1))
9546 (insert "(")
9547 (if (not seq)
9548 (unless (setq input-signals
9549 (vhdl-template-field "[sensitivity list]" ")" t))
9550 (setq input-signals "")
9551 (delete-char -2))
9552 (setq clock (or (and (not (equal "" vhdl-clock-name))
9553 (progn (insert vhdl-clock-name) vhdl-clock-name))
9554 (vhdl-template-field "clock name") "<clock>"))
9555 (when (eq reset-kind 'query)
9556 (setq reset-kind
9557 (if (eq (vhdl-decision-query
9558 "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
9559 'async
9560 'sync)))
9561 (when (eq reset-kind 'async)
9562 (insert ", ")
9563 (setq reset (or (and (not (equal "" vhdl-reset-name))
9564 (progn (insert vhdl-reset-name) vhdl-reset-name))
9565 (vhdl-template-field "reset name") "<reset>")))
9566 (insert ")"))
9567 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9568 (insert "\n")
9569 (vhdl-template-begin-end "PROCESS" label margin)
9570 (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
9571 (when vhdl-prompt-for-comments
9572 (setq final-pos (point-marker))
9573 (vhdl-prepare-search-2
9574 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9575 (vhdl-re-search-backward "\\<process\\>" nil t))
9576 (end-of-line -0)
9577 (if (bobp)
9578 (progn (insert "\n") (forward-line -1))
9579 (insert "\n"))
9580 (indent-to margin)
9581 (insert "-- purpose: ")
9582 (if (not (vhdl-template-field "[description]" nil t))
9583 (vhdl-line-kill-entire)
9584 (insert "\n")
9585 (indent-to margin)
9586 (insert "-- type : ")
9587 (insert (if seq "sequential" "combinational") "\n")
9588 (indent-to margin)
9589 (insert "-- inputs : ")
9590 (if (not seq)
9591 (insert input-signals)
9592 (insert clock ", ")
9593 (when reset (insert reset ", "))
9594 (unless (vhdl-template-field "[signal names]" nil t)
9595 (delete-char -2)))
9596 (insert "\n")
9597 (indent-to margin)
9598 (insert "-- outputs: ")
9599 (vhdl-template-field "[signal names]" nil t))))
9600 (goto-char final-pos))))
9602 (defun vhdl-template-process-comb ()
9603 "Insert a combinational process."
9604 (interactive)
9605 (vhdl-template-process 'comb))
9607 (defun vhdl-template-process-seq ()
9608 "Insert a sequential process."
9609 (interactive)
9610 (vhdl-template-process 'seq))
9612 (defun vhdl-template-quantity ()
9613 "Insert a quantity declaration."
9614 (interactive)
9615 (if (vhdl-in-argument-list-p)
9616 (let ((start (point)))
9617 (vhdl-insert-keyword "QUANTITY ")
9618 (when (vhdl-template-field "names" nil t start (point))
9619 (insert " : ")
9620 (vhdl-template-field "[IN | OUT]" " " t)
9621 (vhdl-template-field "type")
9622 (insert ";")
9623 (vhdl-comment-insert-inline)))
9624 (let ((char (vhdl-decision-query
9625 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9626 (cond ((eq char ?f) (vhdl-template-quantity-free))
9627 ((eq char ?b) (vhdl-template-quantity-branch))
9628 ((eq char ?s) (vhdl-template-quantity-source))
9629 (t (vhdl-template-undo (point) (point)))))))
9631 (defun vhdl-template-quantity-free ()
9632 "Insert a free quantity declaration."
9633 (interactive)
9634 (vhdl-insert-keyword "QUANTITY ")
9635 (vhdl-template-field "names")
9636 (insert " : ")
9637 (vhdl-template-field "type")
9638 (let ((position (point)))
9639 (insert " := ")
9640 (unless (vhdl-template-field "[initialization]" nil t)
9641 (delete-region position (point)))
9642 (insert ";")
9643 (vhdl-comment-insert-inline)))
9645 (defun vhdl-template-quantity-branch ()
9646 "Insert a branch quantity declaration."
9647 (interactive)
9648 (let (position)
9649 (vhdl-insert-keyword "QUANTITY ")
9650 (when (vhdl-template-field "[across names]" " " t)
9651 (vhdl-insert-keyword "ACROSS "))
9652 (when (vhdl-template-field "[through names]" " " t)
9653 (vhdl-insert-keyword "THROUGH "))
9654 (vhdl-template-field "plus terminal name")
9655 (setq position (point))
9656 (vhdl-insert-keyword " TO ")
9657 (unless (vhdl-template-field "[minus terminal name]" nil t)
9658 (delete-region position (point)))
9659 (insert ";")
9660 (vhdl-comment-insert-inline)))
9662 (defun vhdl-template-quantity-source ()
9663 "Insert a source quantity declaration."
9664 (interactive)
9665 (vhdl-insert-keyword "QUANTITY ")
9666 (vhdl-template-field "names")
9667 (insert " : ")
9668 (vhdl-template-field "type" " ")
9669 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9670 (progn (vhdl-insert-keyword "NOISE ")
9671 (vhdl-template-field "power expression"))
9672 (vhdl-insert-keyword "SPECTRUM ")
9673 (vhdl-template-field "magnitude expression" ", ")
9674 (vhdl-template-field "phase expression"))
9675 (insert ";")
9676 (vhdl-comment-insert-inline))
9678 (defun vhdl-template-record (kind &optional name secondary)
9679 "Insert a record type declaration."
9680 (interactive)
9681 (let ((margin (current-column))
9682 (start (point))
9683 (first t))
9684 (vhdl-insert-keyword "RECORD\n")
9685 (indent-to (+ margin vhdl-basic-offset))
9686 (when (or (vhdl-template-field "element names"
9687 nil (not secondary) start (point))
9688 secondary)
9689 (while (or first (vhdl-template-field "[element names]" nil t))
9690 (insert " : ")
9691 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9692 (vhdl-comment-insert-inline)
9693 (insert "\n")
9694 (indent-to (+ margin vhdl-basic-offset))
9695 (setq first nil))
9696 (delete-region (line-beginning-position) (point))
9697 (indent-to margin)
9698 (vhdl-insert-keyword "END RECORD")
9699 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9700 (insert ";")
9701 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9703 (defun vhdl-template-report ()
9704 "Insert a report statement."
9705 (interactive)
9706 (let ((start (point)))
9707 (vhdl-insert-keyword "REPORT ")
9708 (if (equal "\"\"" (vhdl-template-field
9709 "string expression" nil t start (point) t))
9710 (delete-char -2)
9711 (setq start (point))
9712 (vhdl-insert-keyword " SEVERITY ")
9713 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9714 (delete-region start (point)))
9715 (insert ";"))))
9717 (defun vhdl-template-return ()
9718 "Insert a return statement."
9719 (interactive)
9720 (let ((start (point)))
9721 (vhdl-insert-keyword "RETURN ")
9722 (unless (vhdl-template-field "[expression]" nil t start (point))
9723 (delete-char -1))
9724 (insert ";")))
9726 (defun vhdl-template-selected-signal-asst ()
9727 "Insert a selected signal assignment."
9728 (interactive)
9729 (let ((margin (current-indentation))
9730 (start (point))
9731 (choices t))
9732 (let ((position (point)))
9733 (vhdl-insert-keyword " SELECT ")
9734 (goto-char position))
9735 (vhdl-insert-keyword "WITH ")
9736 (when (vhdl-template-field "selector expression"
9737 nil t start (+ (point) 7))
9738 (forward-word 1)
9739 (delete-char 1)
9740 (insert "\n")
9741 (indent-to (+ margin vhdl-basic-offset))
9742 (vhdl-template-field "target signal" " <= ")
9743 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9744 (insert "\n")
9745 (indent-to (+ margin vhdl-basic-offset))
9746 (vhdl-template-field "waveform")
9747 (vhdl-insert-keyword " WHEN ")
9748 (vhdl-template-field "choices" ",")
9749 (insert "\n")
9750 (indent-to (+ margin vhdl-basic-offset))
9751 (while (and choices (vhdl-template-field "[waveform]" nil t))
9752 (vhdl-insert-keyword " WHEN ")
9753 (if (setq choices (vhdl-template-field "[choices]" "," t))
9754 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9755 (vhdl-insert-keyword "OTHERS")))
9756 (when choices
9757 (fixup-whitespace)
9758 (delete-char -2))
9759 (insert ";")
9760 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9762 (defun vhdl-template-signal ()
9763 "Insert a signal declaration."
9764 (interactive)
9765 (let ((start (point))
9766 (in-arglist (vhdl-in-argument-list-p)))
9767 (vhdl-insert-keyword "SIGNAL ")
9768 (when (vhdl-template-field "names" nil t start (point))
9769 (insert " : ")
9770 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9771 (vhdl-template-field "type")
9772 (if in-arglist
9773 (progn (insert ";")
9774 (vhdl-comment-insert-inline))
9775 (let ((position (point)))
9776 (insert " := ")
9777 (unless (vhdl-template-field "[initialization]" nil t)
9778 (delete-region position (point)))
9779 (insert ";")
9780 (vhdl-comment-insert-inline))))))
9782 (defun vhdl-template-subnature ()
9783 "Insert a subnature declaration."
9784 (interactive)
9785 (let ((start (point))
9786 position)
9787 (vhdl-insert-keyword "SUBNATURE ")
9788 (when (vhdl-template-field "name" nil t start (point))
9789 (vhdl-insert-keyword " IS ")
9790 (vhdl-template-field "nature" " (")
9791 (if (vhdl-template-field "[index range]" nil t)
9792 (insert ")")
9793 (delete-char -2))
9794 (setq position (point))
9795 (vhdl-insert-keyword " TOLERANCE ")
9796 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9797 nil t nil nil t))
9798 (delete-region position (point))
9799 (vhdl-insert-keyword " ACROSS ")
9800 (vhdl-template-field "string expression" nil nil nil nil t)
9801 (vhdl-insert-keyword " THROUGH"))
9802 (insert ";")
9803 (vhdl-comment-insert-inline))))
9805 (defun vhdl-template-subprogram-body ()
9806 "Insert a subprogram body."
9807 (interactive)
9808 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9809 (vhdl-template-function-body)
9810 (vhdl-template-procedure-body)))
9812 (defun vhdl-template-subprogram-decl ()
9813 "Insert a subprogram declaration."
9814 (interactive)
9815 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9816 (vhdl-template-function-decl)
9817 (vhdl-template-procedure-decl)))
9819 (defun vhdl-template-subtype ()
9820 "Insert a subtype declaration."
9821 (interactive)
9822 (let ((start (point)))
9823 (vhdl-insert-keyword "SUBTYPE ")
9824 (when (vhdl-template-field "name" nil t start (point))
9825 (vhdl-insert-keyword " IS ")
9826 (vhdl-template-field "type" " ")
9827 (unless
9828 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9829 (delete-char -1))
9830 (insert ";")
9831 (vhdl-comment-insert-inline))))
9833 (defun vhdl-template-terminal ()
9834 "Insert a terminal declaration."
9835 (interactive)
9836 (let ((start (point)))
9837 (vhdl-insert-keyword "TERMINAL ")
9838 (when (vhdl-template-field "names" nil t start (point))
9839 (insert " : ")
9840 (vhdl-template-field "nature")
9841 (insert ";")
9842 (vhdl-comment-insert-inline))))
9844 (defun vhdl-template-type ()
9845 "Insert a type declaration."
9846 (interactive)
9847 (let ((start (point))
9848 name mid-pos end-pos)
9849 (vhdl-insert-keyword "TYPE ")
9850 (when (setq name (vhdl-template-field "name" nil t start (point)))
9851 (vhdl-insert-keyword " IS ")
9852 (let ((definition
9853 (upcase
9854 (or (vhdl-template-field
9855 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9856 ""))))
9857 (cond ((equal definition "")
9858 (delete-char -4)
9859 (insert ";"))
9860 ((equal definition "ARRAY")
9861 (delete-region (point) (progn (forward-word -1) (point)))
9862 (vhdl-template-array 'type t))
9863 ((equal definition "RECORD")
9864 (setq mid-pos (point-marker))
9865 (delete-region (point) (progn (forward-word -1) (point)))
9866 (vhdl-template-record 'type name t))
9867 ((equal definition "ACCESS")
9868 (insert " ")
9869 (vhdl-template-field "type" ";"))
9870 ((equal definition "FILE")
9871 (vhdl-insert-keyword " OF ")
9872 (vhdl-template-field "type" ";"))
9873 (t (insert ";")))
9874 (when mid-pos
9875 (setq end-pos (point-marker))
9876 (goto-char mid-pos)
9877 (end-of-line))
9878 (vhdl-comment-insert-inline)
9879 (when end-pos (goto-char end-pos))))))
9881 (defun vhdl-template-use ()
9882 "Insert a use clause."
9883 (interactive)
9884 (let ((start (point)))
9885 (vhdl-prepare-search-1
9886 (vhdl-insert-keyword "USE ")
9887 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9888 (vhdl-insert-keyword "..ALL;")
9889 (backward-char 6)
9890 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9891 (forward-char 1)
9892 (vhdl-template-field "package name")
9893 (forward-char 5))))))
9895 (defun vhdl-template-variable ()
9896 "Insert a variable declaration."
9897 (interactive)
9898 (let ((start (point))
9899 (in-arglist (vhdl-in-argument-list-p)))
9900 (vhdl-prepare-search-2
9901 (if (or (save-excursion
9902 (progn (vhdl-beginning-of-block)
9903 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
9904 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9905 (vhdl-insert-keyword "VARIABLE ")
9906 (if (vhdl-standard-p '87)
9907 (error "ERROR: Not within sequential block")
9908 (vhdl-insert-keyword "SHARED VARIABLE "))))
9909 (when (vhdl-template-field "names" nil t start (point))
9910 (insert " : ")
9911 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9912 (vhdl-template-field "type")
9913 (if in-arglist
9914 (progn (insert ";")
9915 (vhdl-comment-insert-inline))
9916 (let ((position (point)))
9917 (insert " := ")
9918 (unless (vhdl-template-field "[initialization]" nil t)
9919 (delete-region position (point)))
9920 (insert ";")
9921 (vhdl-comment-insert-inline))))))
9923 (defun vhdl-template-wait ()
9924 "Insert a wait statement."
9925 (interactive)
9926 (vhdl-insert-keyword "WAIT ")
9927 (unless (vhdl-template-field
9928 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9929 nil t)
9930 (delete-char -1))
9931 (insert ";"))
9933 (defun vhdl-template-when ()
9934 "Indent correctly if within a case statement."
9935 (interactive)
9936 (let ((position (point))
9937 margin)
9938 (vhdl-prepare-search-2
9939 (if (and (= (current-column) (current-indentation))
9940 (vhdl-re-search-forward "\\<end\\>" nil t)
9941 (looking-at "\\s-*\\<case\\>"))
9942 (progn
9943 (setq margin (current-indentation))
9944 (goto-char position)
9945 (delete-horizontal-space)
9946 (indent-to (+ margin vhdl-basic-offset)))
9947 (goto-char position)))
9948 (vhdl-insert-keyword "WHEN ")))
9950 (defun vhdl-template-while-loop ()
9951 "Insert a while loop."
9952 (interactive)
9953 (let* ((margin (current-indentation))
9954 (start (point))
9955 label)
9956 (if (not (eq vhdl-optional-labels 'all))
9957 (vhdl-insert-keyword "WHILE ")
9958 (vhdl-insert-keyword ": WHILE ")
9959 (goto-char start)
9960 (setq label (vhdl-template-field "[label]" nil t))
9961 (unless label (delete-char 2))
9962 (forward-word 1)
9963 (forward-char 1))
9964 (when vhdl-conditions-in-parenthesis (insert "("))
9965 (when (vhdl-template-field "condition" nil t start (point))
9966 (when vhdl-conditions-in-parenthesis (insert ")"))
9967 (vhdl-insert-keyword " LOOP\n\n")
9968 (indent-to margin)
9969 (vhdl-insert-keyword "END LOOP")
9970 (insert (if label (concat " " label ";") ";"))
9971 (forward-line -1)
9972 (indent-to (+ margin vhdl-basic-offset)))))
9974 (defun vhdl-template-with ()
9975 "Insert a with statement (i.e. selected signal assignment)."
9976 (interactive)
9977 (vhdl-prepare-search-1
9978 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9979 (equal ";" (match-string 1)))
9980 (vhdl-template-selected-signal-asst)
9981 (vhdl-insert-keyword "WITH "))))
9983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9984 ;; Special templates
9986 (defun vhdl-template-clocked-wait ()
9987 "Insert a wait statement for rising/falling clock edge."
9988 (interactive)
9989 (let ((start (point))
9990 clock)
9991 (vhdl-insert-keyword "WAIT UNTIL ")
9992 (when (setq clock
9993 (or (and (not (equal "" vhdl-clock-name))
9994 (progn (insert vhdl-clock-name) vhdl-clock-name))
9995 (vhdl-template-field "clock name" nil t start (point))))
9996 (insert "'event")
9997 (vhdl-insert-keyword " AND ")
9998 (insert clock)
9999 (insert
10000 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
10001 (vhdl-comment-insert-inline
10002 (concat (if vhdl-clock-rising-edge "rising" "falling")
10003 " clock edge")))))
10005 (defun vhdl-template-seq-process (clock reset reset-kind)
10006 "Insert a template for the body of a sequential process."
10007 (let ((margin (current-indentation))
10008 position)
10009 (vhdl-insert-keyword "IF ")
10010 (when vhdl-conditions-in-parenthesis (insert "("))
10011 (when (eq reset-kind 'async)
10012 (insert reset " = "
10013 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10014 (when vhdl-conditions-in-parenthesis (insert ")"))
10015 (vhdl-insert-keyword " THEN")
10016 (vhdl-comment-insert-inline
10017 (concat "asynchronous reset (active "
10018 (if vhdl-reset-active-high "high" "low") ")"))
10019 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10020 (setq position (point))
10021 (insert "\n") (indent-to margin)
10022 (vhdl-insert-keyword "ELSIF ")
10023 (when vhdl-conditions-in-parenthesis (insert "(")))
10024 (if (eq vhdl-clock-edge-condition 'function)
10025 (insert (if vhdl-clock-rising-edge "rising" "falling")
10026 "_edge(" clock ")")
10027 (insert clock "'event")
10028 (vhdl-insert-keyword " AND ")
10029 (insert clock " = "
10030 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
10031 (when vhdl-conditions-in-parenthesis (insert ")"))
10032 (vhdl-insert-keyword " THEN")
10033 (vhdl-comment-insert-inline
10034 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
10035 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10036 (when (eq reset-kind 'sync)
10037 (vhdl-insert-keyword "IF ")
10038 (when vhdl-conditions-in-parenthesis (insert "("))
10039 (setq reset (or (and (not (equal "" vhdl-reset-name))
10040 (progn (insert vhdl-reset-name) vhdl-reset-name))
10041 (vhdl-template-field "reset name") "<reset>"))
10042 (insert " = "
10043 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
10044 (when vhdl-conditions-in-parenthesis (insert ")"))
10045 (vhdl-insert-keyword " THEN")
10046 (vhdl-comment-insert-inline
10047 (concat "synchronous reset (active "
10048 (if vhdl-reset-active-high "high" "low") ")"))
10049 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10050 (setq position (point))
10051 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10052 (vhdl-insert-keyword "ELSE")
10053 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
10054 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
10055 (vhdl-insert-keyword "END IF;"))
10056 (when (eq reset-kind 'none)
10057 (setq position (point)))
10058 (insert "\n") (indent-to margin)
10059 (vhdl-insert-keyword "END IF;")
10060 (goto-char position)
10061 reset))
10063 (defun vhdl-template-standard-package (library package)
10064 "Insert specification of a standard package. Include a library
10065 specification, if not already there."
10066 (let ((margin (current-indentation)))
10067 (unless (equal library "std")
10068 (unless (or (save-excursion
10069 (vhdl-prepare-search-1
10070 (and (not (bobp))
10071 (re-search-backward
10072 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10073 library "\\|end\\)\\>") nil t)
10074 (match-string 2))))
10075 (equal (downcase library) "work"))
10076 (vhdl-insert-keyword "LIBRARY ")
10077 (insert library ";")
10078 (when package
10079 (insert "\n")
10080 (indent-to margin))))
10081 (when package
10082 (vhdl-insert-keyword "USE ")
10083 (insert library "." package)
10084 (vhdl-insert-keyword ".ALL;"))))
10086 (defun vhdl-template-package-numeric-bit ()
10087 "Insert specification of `numeric_bit' package."
10088 (interactive)
10089 (vhdl-template-standard-package "ieee" "numeric_bit"))
10091 (defun vhdl-template-package-numeric-std ()
10092 "Insert specification of `numeric_std' package."
10093 (interactive)
10094 (vhdl-template-standard-package "ieee" "numeric_std"))
10096 (defun vhdl-template-package-std-logic-1164 ()
10097 "Insert specification of `std_logic_1164' package."
10098 (interactive)
10099 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10101 (defun vhdl-template-package-std-logic-arith ()
10102 "Insert specification of `std_logic_arith' package."
10103 (interactive)
10104 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10106 (defun vhdl-template-package-std-logic-misc ()
10107 "Insert specification of `std_logic_misc' package."
10108 (interactive)
10109 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10111 (defun vhdl-template-package-std-logic-signed ()
10112 "Insert specification of `std_logic_signed' package."
10113 (interactive)
10114 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10116 (defun vhdl-template-package-std-logic-textio ()
10117 "Insert specification of `std_logic_textio' package."
10118 (interactive)
10119 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10121 (defun vhdl-template-package-std-logic-unsigned ()
10122 "Insert specification of `std_logic_unsigned' package."
10123 (interactive)
10124 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10126 (defun vhdl-template-package-textio ()
10127 "Insert specification of `textio' package."
10128 (interactive)
10129 (vhdl-template-standard-package "std" "textio"))
10131 (defun vhdl-template-package-fundamental-constants ()
10132 "Insert specification of `fundamental_constants' package."
10133 (interactive)
10134 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10136 (defun vhdl-template-package-material-constants ()
10137 "Insert specification of `material_constants' package."
10138 (interactive)
10139 (vhdl-template-standard-package "ieee" "material_constants"))
10141 (defun vhdl-template-package-energy-systems ()
10142 "Insert specification of `energy_systems' package."
10143 (interactive)
10144 (vhdl-template-standard-package "ieee" "energy_systems"))
10146 (defun vhdl-template-package-electrical-systems ()
10147 "Insert specification of `electrical_systems' package."
10148 (interactive)
10149 (vhdl-template-standard-package "ieee" "electrical_systems"))
10151 (defun vhdl-template-package-mechanical-systems ()
10152 "Insert specification of `mechanical_systems' package."
10153 (interactive)
10154 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10156 (defun vhdl-template-package-radiant-systems ()
10157 "Insert specification of `radiant_systems' package."
10158 (interactive)
10159 (vhdl-template-standard-package "ieee" "radiant_systems"))
10161 (defun vhdl-template-package-thermal-systems ()
10162 "Insert specification of `thermal_systems' package."
10163 (interactive)
10164 (vhdl-template-standard-package "ieee" "thermal_systems"))
10166 (defun vhdl-template-package-fluidic-systems ()
10167 "Insert specification of `fluidic_systems' package."
10168 (interactive)
10169 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10171 (defun vhdl-template-package-math-complex ()
10172 "Insert specification of `math_complex' package."
10173 (interactive)
10174 (vhdl-template-standard-package "ieee" "math_complex"))
10176 (defun vhdl-template-package-math-real ()
10177 "Insert specification of `math_real' package."
10178 (interactive)
10179 (vhdl-template-standard-package "ieee" "math_real"))
10181 (defun vhdl-template-directive (directive)
10182 "Insert directive."
10183 (unless (= (current-indentation) (current-column))
10184 (delete-horizontal-space)
10185 (insert " "))
10186 (insert "-- pragma " directive))
10188 (defun vhdl-template-directive-translate-on ()
10189 "Insert directive 'translate_on'."
10190 (interactive)
10191 (vhdl-template-directive "translate_on"))
10193 (defun vhdl-template-directive-translate-off ()
10194 "Insert directive 'translate_off'."
10195 (interactive)
10196 (vhdl-template-directive "translate_off"))
10198 (defun vhdl-template-directive-synthesis-on ()
10199 "Insert directive 'synthesis_on'."
10200 (interactive)
10201 (vhdl-template-directive "synthesis_on"))
10203 (defun vhdl-template-directive-synthesis-off ()
10204 "Insert directive 'synthesis_off'."
10205 (interactive)
10206 (vhdl-template-directive "synthesis_off"))
10208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10209 ;; Header and footer templates
10211 (defun vhdl-template-header (&optional file-title)
10212 "Insert a VHDL file header."
10213 (interactive)
10214 (unless (equal vhdl-file-header "")
10215 (let (pos)
10216 (save-excursion
10217 (goto-char (point-min))
10218 (vhdl-insert-string-or-file vhdl-file-header)
10219 (setq pos (point-marker)))
10220 (vhdl-template-replace-header-keywords
10221 (point-min-marker) pos file-title))))
10223 (defun vhdl-template-footer ()
10224 "Insert a VHDL file footer."
10225 (interactive)
10226 (unless (equal vhdl-file-footer "")
10227 (let (pos)
10228 (save-excursion
10229 (goto-char (point-max))
10230 (setq pos (point-marker))
10231 (vhdl-insert-string-or-file vhdl-file-footer)
10232 (unless (= (preceding-char) ?\n)
10233 (insert "\n")))
10234 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
10236 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
10237 is-model)
10238 "Replace keywords in header and footer."
10239 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
10240 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
10241 pos)
10242 (vhdl-prepare-search-2
10243 (save-excursion
10244 (goto-char beg)
10245 (while (search-forward "<projectdesc>" end t)
10246 (replace-match project-desc t t))
10247 (goto-char beg)
10248 (while (search-forward "<filename>" end t)
10249 (replace-match (buffer-name) t t))
10250 (goto-char beg)
10251 (while (search-forward "<copyright>" end t)
10252 (replace-match vhdl-copyright-string t t))
10253 (goto-char beg)
10254 (while (search-forward "<author>" end t)
10255 (replace-match "" t t)
10256 (insert (user-full-name))
10257 (when user-mail-address (insert " <" user-mail-address ">")))
10258 (goto-char beg)
10259 (while (search-forward "<authorfull>" end t)
10260 (replace-match (user-full-name) t t))
10261 (goto-char beg)
10262 (while (search-forward "<login>" end t)
10263 (replace-match (user-login-name) t t))
10264 (goto-char beg)
10265 (while (search-forward "<project>" end t)
10266 (replace-match project-title t t))
10267 (goto-char beg)
10268 (while (search-forward "<company>" end t)
10269 (replace-match vhdl-company-name t t))
10270 (goto-char beg)
10271 (while (search-forward "<platform>" end t)
10272 (replace-match vhdl-platform-spec t t))
10273 (goto-char beg)
10274 (while (search-forward "<standard>" end t)
10275 (replace-match
10276 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10277 ((vhdl-standard-p '93) "'93/02"))
10278 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
10279 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
10280 (goto-char beg)
10281 ;; Replace <RCS> with $, so that RCS for the source is
10282 ;; not over-enthusiastic with replacements
10283 (while (search-forward "<RCS>" end t)
10284 (replace-match "$" nil t))
10285 (goto-char beg)
10286 (while (search-forward "<date>" end t)
10287 (replace-match "" t t)
10288 (vhdl-template-insert-date))
10289 (goto-char beg)
10290 (while (search-forward "<year>" end t)
10291 (replace-match (format-time-string "%Y" nil) t t))
10292 (goto-char beg)
10293 (when file-title
10294 (while (search-forward "<title string>" end t)
10295 (replace-match file-title t t))
10296 (goto-char beg))
10297 (let (string)
10298 (while
10299 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
10300 (setq string (read-string (concat (match-string 1) ": ")))
10301 (replace-match string t t)))
10302 (goto-char beg)
10303 (when (and (not is-model) (search-forward "<cursor>" end t))
10304 (replace-match "" t t)
10305 (setq pos (point))))
10306 (when pos (goto-char pos))
10307 (unless is-model
10308 (when (or (not project-title) (equal project-title ""))
10309 (message "You can specify a project title in user option `vhdl-project-alist'"))
10310 (when (or (not project-desc) (equal project-desc ""))
10311 (message "You can specify a project description in user option `vhdl-project-alist'"))
10312 (when (equal vhdl-platform-spec "")
10313 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10314 (when (equal vhdl-company-name "")
10315 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10318 ;; Comment templates and functions
10320 (defun vhdl-comment-indent ()
10321 "Indent comments."
10322 (let* ((position (point))
10323 (col
10324 (progn
10325 (forward-line -1)
10326 (if (re-search-forward "--" position t)
10327 (- (current-column) 2) ; existing comment at bol stays there
10328 (goto-char position)
10329 (skip-chars-backward " \t")
10330 (max comment-column ; else indent to comment column
10331 (1+ (current-column))))))) ; except leave at least one space
10332 (goto-char position)
10333 col))
10335 (defun vhdl-comment-insert ()
10336 "Start a comment at the end of the line.
10337 If on line with code, indent at least `comment-column'.
10338 If starting after end-comment-column, start a new line."
10339 (interactive)
10340 (when (> (current-column) end-comment-column) (newline-and-indent))
10341 (if (or (looking-at "\\s-*$") ; end of line
10342 (and (not unread-command-events) ; called with key binding or menu
10343 (not (end-of-line))))
10344 (let (margin)
10345 (while (= (preceding-char) ?-) (delete-char -1))
10346 (setq margin (current-column))
10347 (delete-horizontal-space)
10348 (if (bolp)
10349 (progn (indent-to margin) (insert "--"))
10350 (insert " ")
10351 (indent-to comment-column)
10352 (insert "--"))
10353 (if (not unread-command-events) (insert " ")))
10354 ;; else code following current point implies commenting out code
10355 (let (next-input code)
10356 (while (= (preceding-char) ?-) (delete-char -2))
10357 (while (= (setq next-input (read-char)) 13) ; CR
10358 (insert "--") ; or have a space after it?
10359 (forward-char -2)
10360 (forward-line 1)
10361 (message "Enter CR if commenting out a line of code.")
10362 (setq code t))
10363 (unless code
10364 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10365 (setq unread-command-events
10366 (list (vhdl-character-to-event next-input)))))) ; pushback the char
10368 (defun vhdl-comment-display (&optional line-exists)
10369 "Add 2 comment lines at the current indent, making a display comment."
10370 (interactive)
10371 (let ((margin (current-indentation)))
10372 (unless line-exists (vhdl-comment-display-line))
10373 (insert "\n") (indent-to margin)
10374 (insert "\n") (indent-to margin)
10375 (vhdl-comment-display-line)
10376 (end-of-line -0)
10377 (insert "-- ")))
10379 (defun vhdl-comment-display-line ()
10380 "Displays one line of dashes."
10381 (interactive)
10382 (while (= (preceding-char) ?-) (delete-char -2))
10383 (insert "--")
10384 (let* ((col (current-column))
10385 (len (- end-comment-column col)))
10386 (insert-char vhdl-comment-display-line-char len)))
10388 (defun vhdl-comment-append-inline ()
10389 "Append empty inline comment to current line."
10390 (interactive)
10391 (end-of-line)
10392 (delete-horizontal-space)
10393 (insert " ")
10394 (indent-to comment-column)
10395 (insert "-- "))
10397 (defun vhdl-comment-insert-inline (&optional string always-insert)
10398 "Insert inline comment."
10399 (when (or (and string (or vhdl-self-insert-comments always-insert))
10400 (and (not string) vhdl-prompt-for-comments))
10401 (let ((position (point)))
10402 (insert " ")
10403 (indent-to comment-column)
10404 (insert "-- ")
10405 (if (not (or (and string (progn (insert string) t))
10406 (vhdl-template-field "[comment]" nil t)))
10407 (delete-region position (point))
10408 (while (= (preceding-char) ?\ ) (delete-char -1))
10409 ;; (when (> (current-column) end-comment-column)
10410 ;; (setq position (point-marker))
10411 ;; (re-search-backward "-- ")
10412 ;; (insert "\n")
10413 ;; (indent-to comment-column)
10414 ;; (goto-char position))
10415 ))))
10417 (defun vhdl-comment-block ()
10418 "Insert comment for code block."
10419 (when vhdl-prompt-for-comments
10420 (let ((final-pos (point-marker)))
10421 (vhdl-prepare-search-2
10422 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
10423 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
10424 (let (margin)
10425 (back-to-indentation)
10426 (setq margin (current-column))
10427 (end-of-line -0)
10428 (if (bobp)
10429 (progn (insert "\n") (forward-line -1))
10430 (insert "\n"))
10431 (indent-to margin)
10432 (insert "-- purpose: ")
10433 (unless (vhdl-template-field "[description]" nil t)
10434 (vhdl-line-kill-entire)))))
10435 (goto-char final-pos))))
10437 (defun vhdl-comment-uncomment-region (beg end &optional arg)
10438 "Comment out region if not commented out, uncomment otherwise."
10439 (interactive "r\nP")
10440 (save-excursion
10441 (goto-char (1- end))
10442 (end-of-line)
10443 (setq end (point-marker))
10444 (goto-char beg)
10445 (beginning-of-line)
10446 (setq beg (point))
10447 (if (looking-at (concat "\\s-*" comment-start))
10448 (comment-region beg end '(4))
10449 (comment-region beg end))))
10451 (defun vhdl-comment-uncomment-line (&optional arg)
10452 "Comment out line if not commented out, uncomment otherwise."
10453 (interactive "p")
10454 (save-excursion
10455 (beginning-of-line)
10456 (let ((position (point)))
10457 (forward-line (or arg 1))
10458 (vhdl-comment-uncomment-region position (point)))))
10460 (defun vhdl-comment-kill-region (beg end)
10461 "Kill comments in region."
10462 (interactive "r")
10463 (save-excursion
10464 (goto-char end)
10465 (setq end (point-marker))
10466 (goto-char beg)
10467 (beginning-of-line)
10468 (while (< (point) end)
10469 (if (looking-at "^\\(\\s-*--.*\n\\)")
10470 (progn (delete-region (match-beginning 1) (match-end 1)))
10471 (beginning-of-line 2)))))
10473 (defun vhdl-comment-kill-inline-region (beg end)
10474 "Kill inline comments in region."
10475 (interactive "r")
10476 (save-excursion
10477 (goto-char end)
10478 (setq end (point-marker))
10479 (goto-char beg)
10480 (beginning-of-line)
10481 (while (< (point) end)
10482 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10483 (delete-region (match-beginning 1) (match-end 1)))
10484 (beginning-of-line 2))))
10486 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10487 ;; Subtemplates
10489 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
10490 "Insert a begin ... end pair with optional name after the end.
10491 Point is left between them."
10492 (let (position)
10493 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10494 (indent-to margin)
10495 (vhdl-insert-keyword "BEGIN")
10496 (when (and (or construct name) vhdl-self-insert-comments)
10497 (insert " --")
10498 (when construct (insert " ") (vhdl-insert-keyword construct))
10499 (when name (insert " " name)))
10500 (insert "\n")
10501 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10502 (indent-to (+ margin vhdl-basic-offset))
10503 (setq position (point))
10504 (insert "\n")
10505 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10506 (indent-to margin)
10507 (vhdl-insert-keyword "END")
10508 (when construct (insert " ") (vhdl-insert-keyword construct))
10509 (insert (if name (concat " " name) "") ";")
10510 (goto-char position)))
10512 (defun vhdl-template-argument-list (&optional is-function)
10513 "Read from user a procedure or function argument list."
10514 (insert " (")
10515 (let ((margin (current-column))
10516 (start (point))
10517 (end-pos (point))
10518 not-empty interface semicolon-pos)
10519 (unless vhdl-argument-list-indent
10520 (setq margin (+ (current-indentation) vhdl-basic-offset))
10521 (insert "\n")
10522 (indent-to margin))
10523 (setq interface (vhdl-template-field
10524 (concat "[CONSTANT | SIGNAL"
10525 (unless is-function " | VARIABLE") "]") " " t))
10526 (while (vhdl-template-field "[names]" nil t)
10527 (setq not-empty t)
10528 (insert " : ")
10529 (unless is-function
10530 (if (and interface (equal (upcase interface) "CONSTANT"))
10531 (vhdl-insert-keyword "IN ")
10532 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10533 (vhdl-template-field "type")
10534 (setq semicolon-pos (point))
10535 (insert ";")
10536 (vhdl-comment-insert-inline)
10537 (setq end-pos (point))
10538 (insert "\n")
10539 (indent-to margin)
10540 (setq interface (vhdl-template-field
10541 (concat "[CONSTANT | SIGNAL"
10542 (unless is-function " | VARIABLE") "]") " " t)))
10543 (delete-region end-pos (point))
10544 (when semicolon-pos (goto-char semicolon-pos))
10545 (if not-empty
10546 (progn (delete-char 1) (insert ")"))
10547 (delete-char -2))))
10549 (defun vhdl-template-generic-list (optional &optional no-value)
10550 "Read from user a generic spec argument list."
10551 (let (margin
10552 (start (point)))
10553 (vhdl-insert-keyword "GENERIC (")
10554 (setq margin (current-column))
10555 (unless vhdl-argument-list-indent
10556 (let ((position (point)))
10557 (back-to-indentation)
10558 (setq margin (+ (current-column) vhdl-basic-offset))
10559 (goto-char position)
10560 (insert "\n")
10561 (indent-to margin)))
10562 (let ((vhdl-generics (vhdl-template-field
10563 (concat (and optional "[") "name"
10564 (and no-value "s") (and optional "]"))
10565 nil optional)))
10566 (if (not vhdl-generics)
10567 (if optional
10568 (progn (vhdl-line-kill-entire) (end-of-line -0)
10569 (unless vhdl-argument-list-indent
10570 (vhdl-line-kill-entire) (end-of-line -0)))
10571 (vhdl-template-undo start (point))
10572 nil )
10573 (insert " : ")
10574 (let (semicolon-pos end-pos)
10575 (while vhdl-generics
10576 (vhdl-template-field "type")
10577 (if no-value
10578 (progn (setq semicolon-pos (point))
10579 (insert ";"))
10580 (insert " := ")
10581 (unless (vhdl-template-field "[value]" nil t)
10582 (delete-char -4))
10583 (setq semicolon-pos (point))
10584 (insert ";"))
10585 (vhdl-comment-insert-inline)
10586 (setq end-pos (point))
10587 (insert "\n")
10588 (indent-to margin)
10589 (setq vhdl-generics (vhdl-template-field
10590 (concat "[name" (and no-value "s") "]")
10591 " : " t)))
10592 (delete-region end-pos (point))
10593 (goto-char semicolon-pos)
10594 (insert ")")
10595 (end-of-line)
10596 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10597 t)))))
10599 (defun vhdl-template-port-list (optional)
10600 "Read from user a port spec argument list."
10601 (let ((start (point))
10602 margin vhdl-ports object)
10603 (vhdl-insert-keyword "PORT (")
10604 (setq margin (current-column))
10605 (unless vhdl-argument-list-indent
10606 (let ((position (point)))
10607 (back-to-indentation)
10608 (setq margin (+ (current-column) vhdl-basic-offset))
10609 (goto-char position)
10610 (insert "\n")
10611 (indent-to margin)))
10612 (when (vhdl-standard-p 'ams)
10613 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10614 " " t)))
10615 (setq vhdl-ports (vhdl-template-field
10616 (concat (and optional "[") "names" (and optional "]"))
10617 nil optional))
10618 (if (not vhdl-ports)
10619 (if optional
10620 (progn (vhdl-line-kill-entire) (end-of-line -0)
10621 (unless vhdl-argument-list-indent
10622 (vhdl-line-kill-entire) (end-of-line -0)))
10623 (vhdl-template-undo start (point))
10624 nil)
10625 (insert " : ")
10626 (let (semicolon-pos end-pos)
10627 (while vhdl-ports
10628 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10629 (vhdl-template-field "IN | OUT | INOUT" " "))
10630 ((equal "QUANTITY" (upcase object))
10631 (vhdl-template-field "[IN | OUT]" " " t)))
10632 (vhdl-template-field
10633 (if (and object (equal "TERMINAL" (upcase object)))
10634 "nature" "type"))
10635 (setq semicolon-pos (point))
10636 (insert ";")
10637 (vhdl-comment-insert-inline)
10638 (setq end-pos (point))
10639 (insert "\n")
10640 (indent-to margin)
10641 (when (vhdl-standard-p 'ams)
10642 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10643 " " t)))
10644 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10645 (delete-region end-pos (point))
10646 (goto-char semicolon-pos)
10647 (insert ")")
10648 (end-of-line)
10649 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10650 t))))
10652 (defun vhdl-template-generate-body (margin label)
10653 "Insert body for generate template."
10654 (vhdl-insert-keyword " GENERATE")
10655 ; (if (not (vhdl-standard-p '87))
10656 ; (vhdl-template-begin-end "GENERATE" label margin)
10657 (insert "\n\n")
10658 (indent-to margin)
10659 (vhdl-insert-keyword "END GENERATE ")
10660 (insert label ";")
10661 (end-of-line 0)
10662 (indent-to (+ margin vhdl-basic-offset)))
10664 (defun vhdl-template-insert-date ()
10665 "Insert date in appropriate format."
10666 (interactive)
10667 (insert
10668 (cond
10669 ;; 'american, 'european, 'scientific kept for backward compatibility
10670 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10671 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10672 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10673 (t (format-time-string vhdl-date-format nil)))))
10675 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10676 ;; Help functions
10678 (defun vhdl-electric-space (count)
10679 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10680 if in comment and past end-comment-column."
10681 (interactive "p")
10682 (cond ((vhdl-in-comment-p)
10683 (self-insert-command count)
10684 (cond ((>= (current-column) (+ 2 end-comment-column))
10685 (backward-char 1)
10686 (skip-chars-backward "^ \t\n\r\f")
10687 (indent-new-comment-line)
10688 (skip-chars-forward "^ \t\n\r\f")
10689 (forward-char 1))
10690 ((>= (current-column) end-comment-column)
10691 (indent-new-comment-line))
10692 (t nil)))
10693 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10694 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10695 (vhdl-prepare-search-1
10696 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10697 (self-insert-command count))
10698 (t (self-insert-command count))))
10700 (defun vhdl-template-field (prompt &optional follow-string optional
10701 begin end is-string default)
10702 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10703 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10704 an empty string is inserted, return nil and call `vhdl-template-undo' for
10705 the region between BEGIN and END. IS-STRING indicates whether a string
10706 with double-quotes is to be inserted. DEFAULT specifies a default string."
10707 (let ((position (point))
10708 string)
10709 (insert "<" prompt ">")
10710 (setq string
10711 (condition-case ()
10712 (read-from-minibuffer (concat prompt ": ")
10713 (or (and is-string '("\"\"" . 2)) default)
10714 vhdl-minibuffer-local-map)
10715 (quit (if (and optional begin end)
10716 (progn (beep) "")
10717 (keyboard-quit)))))
10718 (when (or (not (equal string "")) optional)
10719 (delete-region position (point)))
10720 (when (and (equal string "") optional begin end)
10721 (vhdl-template-undo begin end)
10722 (message "Template aborted"))
10723 (unless (equal string "")
10724 (insert string)
10725 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10726 vhdl-keywords-regexp)
10727 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10728 vhdl-types-regexp)
10729 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10730 (concat "'" vhdl-attributes-regexp))
10731 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10732 vhdl-enum-values-regexp)
10733 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
10734 vhdl-constants-regexp))
10735 (when (or (not (equal string "")) (not optional))
10736 (insert (or follow-string "")))
10737 (if (equal string "") nil string)))
10739 (defun vhdl-decision-query (string prompt &optional optional)
10740 "Query a decision from the user."
10741 (let ((start (point)))
10742 (when string (vhdl-insert-keyword (concat string " ")))
10743 (message "%s" (or prompt ""))
10744 (let ((char (read-char)))
10745 (delete-region start (point))
10746 (if (and optional (eq char ?\r))
10747 (progn (insert " ")
10748 (unexpand-abbrev)
10749 (throw 'abort "ERROR: Template aborted"))
10750 char))))
10752 (defun vhdl-insert-keyword (keyword)
10753 "Insert KEYWORD and adjust case."
10754 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10756 (defun vhdl-case-keyword (keyword)
10757 "Adjust case of KEYWORD."
10758 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10760 (defun vhdl-case-word (num)
10761 "Adjust case of following NUM words."
10762 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10764 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10765 "If preceding character is part of a word or a paren then hippie-expand,
10766 else insert tab (used for word completion in VHDL minibuffer)."
10767 (interactive "P")
10768 (cond
10769 ;; expand word
10770 ((= (char-syntax (preceding-char)) ?w)
10771 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10772 (case-replace nil)
10773 (hippie-expand-only-buffers
10774 (or (and (boundp 'hippie-expand-only-buffers)
10775 hippie-expand-only-buffers)
10776 '(vhdl-mode))))
10777 (vhdl-expand-abbrev prefix-arg)))
10778 ;; expand parenthesis
10779 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10780 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10781 (case-replace nil))
10782 (vhdl-expand-paren prefix-arg)))
10783 ;; insert tab
10784 (t (insert-tab))))
10786 (defun vhdl-template-search-prompt ()
10787 "Search for left out template prompts and query again."
10788 (interactive)
10789 (vhdl-prepare-search-2
10790 (when (or (re-search-forward
10791 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10792 (re-search-backward
10793 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10794 (let ((string (match-string 1)))
10795 (replace-match "")
10796 (vhdl-template-field string)))))
10798 (defun vhdl-template-undo (begin end)
10799 "Undo aborted template by deleting region and unexpanding the keyword."
10800 (cond (vhdl-template-invoked-by-hook
10801 (goto-char end)
10802 (insert " ")
10803 (delete-region begin end)
10804 (unexpand-abbrev))
10805 (t (delete-region begin end))))
10807 (defun vhdl-insert-string-or-file (string)
10808 "Insert STRING or file contents if STRING is an existing file name."
10809 (unless (equal string "")
10810 (let ((file-name
10811 (progn (string-match "^\\([^\n]+\\)" string)
10812 (vhdl-resolve-env-variable (match-string 1 string)))))
10813 (if (file-exists-p file-name)
10814 (forward-char (cadr (insert-file-contents file-name)))
10815 (insert string)))))
10817 (defun vhdl-beginning-of-block ()
10818 "Move cursor to the beginning of the enclosing block."
10819 (let (pos)
10820 (vhdl-prepare-search-2
10821 (save-excursion
10822 (beginning-of-line)
10823 ;; search backward for block beginning or end
10824 (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
10825 ;; not consider subprogram declarations
10826 (or (and (match-string 5)
10827 (save-match-data
10828 (save-excursion
10829 (goto-char (match-end 5))
10830 (forward-word 1)
10831 (vhdl-forward-syntactic-ws)
10832 (when (looking-at "(")
10833 (forward-sexp))
10834 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10835 (match-string 1)))
10836 ;; not consider configuration specifications
10837 (and (match-string 6)
10838 (save-match-data
10839 (save-excursion
10840 (vhdl-end-of-block)
10841 (beginning-of-line)
10842 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10843 (match-string 2))
10844 ;; skip subblock if block end found
10845 (vhdl-beginning-of-block))))
10846 (when pos (goto-char pos))))
10848 (defun vhdl-end-of-block ()
10849 "Move cursor to the end of the enclosing block."
10850 (let (pos)
10851 (vhdl-prepare-search-2
10852 (save-excursion
10853 (end-of-line)
10854 ;; search forward for block beginning or end
10855 (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
10856 ;; not consider subprogram declarations
10857 (or (and (match-string 5)
10858 (save-match-data
10859 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10860 (match-string 1)))
10861 ;; not consider configuration specifications
10862 (and (match-string 6)
10863 (save-match-data
10864 (save-excursion
10865 (vhdl-end-of-block)
10866 (beginning-of-line)
10867 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10868 (not (match-string 2)))
10869 ;; skip subblock if block beginning found
10870 (vhdl-end-of-block))))
10871 (when pos (goto-char pos))))
10873 (defun vhdl-sequential-statement-p ()
10874 "Check if point is within sequential statement part."
10875 (let ((start (point)))
10876 (save-excursion
10877 (vhdl-prepare-search-2
10878 ;; is sequential statement if ...
10879 (and (re-search-backward "^\\s-*begin\\>" nil t)
10880 ;; ... point is between "begin" and "end" of ...
10881 (progn (vhdl-end-of-block)
10882 (< start (point)))
10883 ;; ... a sequential block
10884 (progn (vhdl-beginning-of-block)
10885 (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\\)\\)\\>")))))))
10887 (defun vhdl-in-argument-list-p ()
10888 "Check if within an argument list."
10889 (save-excursion
10890 (vhdl-prepare-search-2
10891 (or (string-match "arglist"
10892 (format "%s" (caar (vhdl-get-syntactic-context))))
10893 (progn (beginning-of-line)
10894 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10896 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10897 ;; Abbrev hooks
10899 (defun vhdl-hooked-abbrev (func)
10900 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10901 but not if inside a comment or quote."
10902 (if (or (vhdl-in-literal)
10903 (save-excursion
10904 (forward-word -1)
10905 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10906 (progn
10907 (insert " ")
10908 (unexpand-abbrev)
10909 (backward-word 1)
10910 (vhdl-case-word 1)
10911 (delete-char 1))
10912 (if (not vhdl-electric-mode)
10913 (progn
10914 (insert " ")
10915 (unexpand-abbrev)
10916 (backward-word 1)
10917 (vhdl-case-word 1)
10918 (delete-char 1))
10919 (let ((invoke-char last-command-event)
10920 (abbrev-mode -1)
10921 (vhdl-template-invoked-by-hook t))
10922 (let ((caught (catch 'abort
10923 (funcall func))))
10924 (when (stringp caught) (message "%s" caught)))
10925 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10926 ;; delete CR which is still in event queue
10927 (if (fboundp 'enqueue-eval-event)
10928 (enqueue-eval-event 'delete-char -1)
10929 (setq unread-command-events ; push back a delete char
10930 (list (vhdl-character-to-event ?\177))))))))
10932 (defun vhdl-template-alias-hook ()
10933 (vhdl-hooked-abbrev 'vhdl-template-alias))
10934 (defun vhdl-template-architecture-hook ()
10935 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10936 (defun vhdl-template-assert-hook ()
10937 (vhdl-hooked-abbrev 'vhdl-template-assert))
10938 (defun vhdl-template-attribute-hook ()
10939 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10940 (defun vhdl-template-block-hook ()
10941 (vhdl-hooked-abbrev 'vhdl-template-block))
10942 (defun vhdl-template-break-hook ()
10943 (vhdl-hooked-abbrev 'vhdl-template-break))
10944 (defun vhdl-template-case-hook ()
10945 (vhdl-hooked-abbrev 'vhdl-template-case))
10946 (defun vhdl-template-component-hook ()
10947 (vhdl-hooked-abbrev 'vhdl-template-component))
10948 (defun vhdl-template-instance-hook ()
10949 (vhdl-hooked-abbrev 'vhdl-template-instance))
10950 (defun vhdl-template-conditional-signal-asst-hook ()
10951 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10952 (defun vhdl-template-configuration-hook ()
10953 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10954 (defun vhdl-template-constant-hook ()
10955 (vhdl-hooked-abbrev 'vhdl-template-constant))
10956 (defun vhdl-template-disconnect-hook ()
10957 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10958 (defun vhdl-template-display-comment-hook ()
10959 (vhdl-hooked-abbrev 'vhdl-comment-display))
10960 (defun vhdl-template-else-hook ()
10961 (vhdl-hooked-abbrev 'vhdl-template-else))
10962 (defun vhdl-template-elsif-hook ()
10963 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10964 (defun vhdl-template-entity-hook ()
10965 (vhdl-hooked-abbrev 'vhdl-template-entity))
10966 (defun vhdl-template-exit-hook ()
10967 (vhdl-hooked-abbrev 'vhdl-template-exit))
10968 (defun vhdl-template-file-hook ()
10969 (vhdl-hooked-abbrev 'vhdl-template-file))
10970 (defun vhdl-template-for-hook ()
10971 (vhdl-hooked-abbrev 'vhdl-template-for))
10972 (defun vhdl-template-function-hook ()
10973 (vhdl-hooked-abbrev 'vhdl-template-function))
10974 (defun vhdl-template-generic-hook ()
10975 (vhdl-hooked-abbrev 'vhdl-template-generic))
10976 (defun vhdl-template-group-hook ()
10977 (vhdl-hooked-abbrev 'vhdl-template-group))
10978 (defun vhdl-template-library-hook ()
10979 (vhdl-hooked-abbrev 'vhdl-template-library))
10980 (defun vhdl-template-limit-hook ()
10981 (vhdl-hooked-abbrev 'vhdl-template-limit))
10982 (defun vhdl-template-if-hook ()
10983 (vhdl-hooked-abbrev 'vhdl-template-if))
10984 (defun vhdl-template-bare-loop-hook ()
10985 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10986 (defun vhdl-template-map-hook ()
10987 (vhdl-hooked-abbrev 'vhdl-template-map))
10988 (defun vhdl-template-nature-hook ()
10989 (vhdl-hooked-abbrev 'vhdl-template-nature))
10990 (defun vhdl-template-next-hook ()
10991 (vhdl-hooked-abbrev 'vhdl-template-next))
10992 (defun vhdl-template-others-hook ()
10993 (vhdl-hooked-abbrev 'vhdl-template-others))
10994 (defun vhdl-template-package-hook ()
10995 (vhdl-hooked-abbrev 'vhdl-template-package))
10996 (defun vhdl-template-port-hook ()
10997 (vhdl-hooked-abbrev 'vhdl-template-port))
10998 (defun vhdl-template-procedural-hook ()
10999 (vhdl-hooked-abbrev 'vhdl-template-procedural))
11000 (defun vhdl-template-procedure-hook ()
11001 (vhdl-hooked-abbrev 'vhdl-template-procedure))
11002 (defun vhdl-template-process-hook ()
11003 (vhdl-hooked-abbrev 'vhdl-template-process))
11004 (defun vhdl-template-quantity-hook ()
11005 (vhdl-hooked-abbrev 'vhdl-template-quantity))
11006 (defun vhdl-template-report-hook ()
11007 (vhdl-hooked-abbrev 'vhdl-template-report))
11008 (defun vhdl-template-return-hook ()
11009 (vhdl-hooked-abbrev 'vhdl-template-return))
11010 (defun vhdl-template-selected-signal-asst-hook ()
11011 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
11012 (defun vhdl-template-signal-hook ()
11013 (vhdl-hooked-abbrev 'vhdl-template-signal))
11014 (defun vhdl-template-subnature-hook ()
11015 (vhdl-hooked-abbrev 'vhdl-template-subnature))
11016 (defun vhdl-template-subtype-hook ()
11017 (vhdl-hooked-abbrev 'vhdl-template-subtype))
11018 (defun vhdl-template-terminal-hook ()
11019 (vhdl-hooked-abbrev 'vhdl-template-terminal))
11020 (defun vhdl-template-type-hook ()
11021 (vhdl-hooked-abbrev 'vhdl-template-type))
11022 (defun vhdl-template-use-hook ()
11023 (vhdl-hooked-abbrev 'vhdl-template-use))
11024 (defun vhdl-template-variable-hook ()
11025 (vhdl-hooked-abbrev 'vhdl-template-variable))
11026 (defun vhdl-template-wait-hook ()
11027 (vhdl-hooked-abbrev 'vhdl-template-wait))
11028 (defun vhdl-template-when-hook ()
11029 (vhdl-hooked-abbrev 'vhdl-template-when))
11030 (defun vhdl-template-while-loop-hook ()
11031 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
11032 (defun vhdl-template-with-hook ()
11033 (vhdl-hooked-abbrev 'vhdl-template-with))
11034 (defun vhdl-template-and-hook ()
11035 (vhdl-hooked-abbrev 'vhdl-template-and))
11036 (defun vhdl-template-or-hook ()
11037 (vhdl-hooked-abbrev 'vhdl-template-or))
11038 (defun vhdl-template-nand-hook ()
11039 (vhdl-hooked-abbrev 'vhdl-template-nand))
11040 (defun vhdl-template-nor-hook ()
11041 (vhdl-hooked-abbrev 'vhdl-template-nor))
11042 (defun vhdl-template-xor-hook ()
11043 (vhdl-hooked-abbrev 'vhdl-template-xor))
11044 (defun vhdl-template-xnor-hook ()
11045 (vhdl-hooked-abbrev 'vhdl-template-xnor))
11046 (defun vhdl-template-not-hook ()
11047 (vhdl-hooked-abbrev 'vhdl-template-not))
11049 (defun vhdl-template-default-hook ()
11050 (vhdl-hooked-abbrev 'vhdl-template-default))
11051 (defun vhdl-template-default-indent-hook ()
11052 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
11054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11055 ;; Template insertion from completion list
11057 (defun vhdl-template-insert-construct (name)
11058 "Insert the built-in construct template with NAME."
11059 (interactive
11060 (list (let ((completion-ignore-case t))
11061 (completing-read "Construct name: "
11062 vhdl-template-construct-alist nil t))))
11063 (vhdl-template-insert-fun
11064 (cadr (assoc name vhdl-template-construct-alist))))
11066 (defun vhdl-template-insert-package (name)
11067 "Insert the built-in package template with NAME."
11068 (interactive
11069 (list (let ((completion-ignore-case t))
11070 (completing-read "Package name: "
11071 vhdl-template-package-alist nil t))))
11072 (vhdl-template-insert-fun
11073 (cadr (assoc name vhdl-template-package-alist))))
11075 (defun vhdl-template-insert-directive (name)
11076 "Insert the built-in directive template with NAME."
11077 (interactive
11078 (list (let ((completion-ignore-case t))
11079 (completing-read "Directive name: "
11080 vhdl-template-directive-alist nil t))))
11081 (vhdl-template-insert-fun
11082 (cadr (assoc name vhdl-template-directive-alist))))
11084 (defun vhdl-template-insert-fun (fun)
11085 "Call FUN to insert a built-in template."
11086 (let ((caught (catch 'abort (when fun (funcall fun)))))
11087 (when (stringp caught) (message "%s" caught))))
11090 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11091 ;;; Models
11092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11094 (defun vhdl-model-insert (model-name)
11095 "Insert the user model with name MODEL-NAME."
11096 (interactive
11097 (let ((completion-ignore-case t))
11098 (list (completing-read "Model name: " vhdl-model-alist))))
11099 (indent-according-to-mode)
11100 (let ((start (point-marker))
11101 (margin (current-indentation))
11102 model position prompt string end)
11103 (vhdl-prepare-search-2
11104 (when (setq model (assoc model-name vhdl-model-alist))
11105 ;; insert model
11106 (beginning-of-line)
11107 (delete-horizontal-space)
11108 (goto-char start)
11109 (vhdl-insert-string-or-file (nth 1 model))
11110 (setq end (point-marker))
11111 ;; indent code
11112 (goto-char start)
11113 (beginning-of-line)
11114 (while (< (point) end)
11115 (unless (looking-at "^$")
11116 (insert-char ? margin))
11117 (beginning-of-line 2))
11118 (goto-char start)
11119 ;; insert clock
11120 (unless (equal "" vhdl-clock-name)
11121 (while (re-search-forward "<clock>" end t)
11122 (replace-match vhdl-clock-name)))
11123 (goto-char start)
11124 ;; insert reset
11125 (unless (equal "" vhdl-reset-name)
11126 (while (re-search-forward "<reset>" end t)
11127 (replace-match vhdl-reset-name)))
11128 ;; replace header prompts
11129 (vhdl-template-replace-header-keywords start end nil t)
11130 (goto-char start)
11131 ;; query other prompts
11132 (while (re-search-forward
11133 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
11134 (unless (equal "cursor" (match-string 1))
11135 (setq position (match-beginning 1))
11136 (setq prompt (match-string 1))
11137 (replace-match "")
11138 (setq string (vhdl-template-field prompt nil t))
11139 ;; replace occurrences of same prompt
11140 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
11141 (replace-match (or string "")))
11142 (goto-char position)))
11143 (goto-char start)
11144 ;; goto final position
11145 (if (re-search-forward "<cursor>" end t)
11146 (replace-match "")
11147 (goto-char end))))))
11149 (defun vhdl-model-defun ()
11150 "Define help and hook functions for user models."
11151 (let ((model-alist vhdl-model-alist)
11152 model-name model-keyword)
11153 (while model-alist
11154 ;; define functions for user models that can be invoked from menu and key
11155 ;; bindings and which themselves call `vhdl-model-insert' with the model
11156 ;; name as argument
11157 (setq model-name (nth 0 (car model-alist)))
11158 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
11159 ,(concat "Insert model for \"" model-name "\".")
11160 (interactive)
11161 (vhdl-model-insert ,model-name)))
11162 ;; define hooks for user models that are invoked from keyword abbrevs
11163 (setq model-keyword (nth 3 (car model-alist)))
11164 (unless (equal model-keyword "")
11165 (eval `(defun
11166 ,(vhdl-function-name
11167 "vhdl-model" model-name "hook") ()
11168 (vhdl-hooked-abbrev
11169 ',(vhdl-function-name "vhdl-model" model-name)))))
11170 (setq model-alist (cdr model-alist)))))
11172 (vhdl-model-defun)
11175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11176 ;;; Port translation
11177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11179 (defvar vhdl-port-list nil
11180 "Variable to hold last port map parsed.")
11181 ;; structure: (parenthesized expression means list of such entries)
11182 ;; (ent-name
11183 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11184 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11185 ;; (lib-name pack-key))
11187 (defun vhdl-parse-string (string &optional optional)
11188 "Check that the text following point matches the regexp in STRING."
11189 (if (looking-at string)
11190 (progn (goto-char (match-end 0))
11191 (when (vhdl-in-literal)
11192 (end-of-line))
11193 (point))
11194 (unless optional
11195 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
11196 (vhdl-current-line) string)))
11197 nil))
11199 (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
11200 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11201 (vhdl-prepare-search-1
11202 (if (string-match (car regexp-cons) string)
11203 (if adjust-case
11204 (funcall vhdl-file-name-case
11205 (replace-match (cdr regexp-cons) t nil string))
11206 (replace-match (cdr regexp-cons) t nil string))
11207 string)))
11209 (defun vhdl-parse-group-comment ()
11210 "Parse comment and empty lines between groups of lines."
11211 (let ((start (point))
11212 string)
11213 (vhdl-forward-comment (point-max))
11214 (setq string (buffer-substring-no-properties start (point)))
11215 (vhdl-forward-syntactic-ws)
11216 ;; strip off leading blanks and first newline
11217 (while (string-match "^\\(\\s-+\\)" string)
11218 (setq string (concat (substring string 0 (match-beginning 1))
11219 (substring string (match-end 1)))))
11220 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
11221 (substring string 1)
11222 string)))
11224 (defun vhdl-paste-group-comment (string indent)
11225 "Paste comment and empty lines from STRING between groups of lines
11226 with INDENT."
11227 (let ((pos (point-marker)))
11228 (when (> indent 0)
11229 (while (string-match "^\\(--\\)" string)
11230 (setq string (concat (substring string 0 (match-beginning 1))
11231 (make-string indent ? )
11232 (substring string (match-beginning 1))))))
11233 (beginning-of-line)
11234 (insert string)
11235 (goto-char pos)))
11237 (defvar vhdl-port-flattened nil
11238 "Indicates whether a port has been flattened.")
11240 (defun vhdl-port-flatten (&optional as-alist)
11241 "Flatten port list so that only one generic/port exists per line.
11242 This operation is performed on an internally stored port and is only
11243 reflected in a subsequent paste operation."
11244 (interactive)
11245 (if (not vhdl-port-list)
11246 (error "ERROR: No port has been read")
11247 (message "Flattening port for next paste...")
11248 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
11249 (old-vhdl-port-list (cdr vhdl-port-list))
11250 old-port-list new-port-list old-port new-port names)
11251 ;; traverse port list and flatten entries
11252 (while (cdr old-vhdl-port-list)
11253 (setq old-port-list (car old-vhdl-port-list))
11254 (setq new-port-list nil)
11255 (while old-port-list
11256 (setq old-port (car old-port-list))
11257 (setq names (car old-port))
11258 (while names
11259 (setq new-port (cons (if as-alist (car names) (list (car names)))
11260 (cdr old-port)))
11261 (setq new-port-list (append new-port-list (list new-port)))
11262 (setq names (cdr names)))
11263 (setq old-port-list (cdr old-port-list)))
11264 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
11265 (setq new-vhdl-port-list (append new-vhdl-port-list
11266 (list new-port-list))))
11267 (setq vhdl-port-list
11268 (append new-vhdl-port-list (list old-vhdl-port-list))
11269 vhdl-port-flattened t)
11270 (message "Flattening port for next paste...done"))))
11272 (defvar vhdl-port-reversed-direction nil
11273 "Indicates whether port directions are reversed.")
11275 (defun vhdl-port-reverse-direction ()
11276 "Reverse direction for all ports (useful in testbenches).
11277 This operation is performed on an internally stored port and is only
11278 reflected in a subsequent paste operation."
11279 (interactive)
11280 (if (not vhdl-port-list)
11281 (error "ERROR: No port has been read")
11282 (message "Reversing port directions for next paste...")
11283 (let ((port-list (nth 2 vhdl-port-list))
11284 port-dir-car port-dir)
11285 ;; traverse port list and reverse directions
11286 (while port-list
11287 (setq port-dir-car (cddr (car port-list))
11288 port-dir (car port-dir-car))
11289 (setcar port-dir-car
11290 (cond ((equal port-dir "in") "out")
11291 ((equal port-dir "IN") "OUT")
11292 ((equal port-dir "out") "in")
11293 ((equal port-dir "OUT") "IN")
11294 (t port-dir)))
11295 (setq port-list (cdr port-list)))
11296 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
11297 (message "Reversing port directions for next paste...done"))))
11299 (defun vhdl-port-copy ()
11300 "Get generic and port information from an entity or component declaration."
11301 (interactive)
11302 (save-excursion
11303 (let (parse-error end-of-list
11304 decl-type name generic-list port-list context-clause
11305 object names direct type init comment group-comment)
11306 (vhdl-prepare-search-2
11307 (setq
11308 parse-error
11309 (catch 'parse
11310 ;; check if within entity or component declaration
11311 (end-of-line)
11312 (when (or (not (re-search-backward
11313 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
11314 (equal "END" (upcase (match-string 1))))
11315 (throw 'parse "ERROR: Not within an entity or component declaration"))
11316 (setq decl-type (downcase (match-string-no-properties 1)))
11317 (forward-word 1)
11318 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11319 (setq name (match-string-no-properties 1))
11320 (message "Reading port of %s \"%s\"..." decl-type name)
11321 (vhdl-forward-syntactic-ws)
11322 ;; parse generic clause
11323 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
11324 ;; parse group comment and spacing
11325 (setq group-comment (vhdl-parse-group-comment))
11326 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11327 (while (not end-of-list)
11328 ;; parse names (accept extended identifiers)
11329 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11330 (setq names (list (match-string-no-properties 1)))
11331 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11332 (setq names
11333 (append names (list (match-string-no-properties 1)))))
11334 ;; parse type
11335 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11336 (setq type (match-string-no-properties 1))
11337 (when (vhdl-in-comment-p) ; if stuck in comment
11338 (setq type (concat type (and (vhdl-parse-string ".*")
11339 (match-string-no-properties 0)))))
11340 (setq comment nil)
11341 (while (looking-at "(")
11342 (setq type
11343 (concat type
11344 (buffer-substring-no-properties
11345 (point) (progn (forward-sexp) (point)))
11346 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11347 (match-string-no-properties 1)))))
11348 ;; special case: closing parenthesis is on separate line
11349 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11350 (setq comment (substring type (match-beginning 2)))
11351 (setq type (substring type 0 (match-beginning 1))))
11352 ;; strip of trailing group-comment
11353 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11354 (setq type (substring type 0 (match-end 1)))
11355 ;; parse initialization expression
11356 (setq init nil)
11357 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
11358 (vhdl-parse-string "\\([^();\n]*\\)")
11359 (setq init (match-string-no-properties 1))
11360 (while (looking-at "(")
11361 (setq init
11362 (concat init
11363 (buffer-substring-no-properties
11364 (point) (progn (forward-sexp) (point)))
11365 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11366 (match-string-no-properties 1))))))
11367 ;; special case: closing parenthesis is on separate line
11368 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11369 (setq comment (substring init (match-beginning 2)))
11370 (setq init (substring init 0 (match-beginning 1)))
11371 (vhdl-forward-syntactic-ws))
11372 (skip-chars-forward " \t")
11373 ;; parse inline comment, special case: as above, no initial.
11374 (unless comment
11375 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11376 (match-string-no-properties 1))))
11377 (vhdl-forward-syntactic-ws)
11378 (setq end-of-list (vhdl-parse-string ")" t))
11379 (vhdl-parse-string "\\s-*;\\s-*")
11380 ;; parse inline comment
11381 (unless comment
11382 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11383 (match-string-no-properties 1))))
11384 ;; save everything in list
11385 (setq generic-list (append generic-list
11386 (list (list names type init
11387 comment group-comment))))
11388 ;; parse group comment and spacing
11389 (setq group-comment (vhdl-parse-group-comment))))
11390 ;; parse port clause
11391 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
11392 ;; parse group comment and spacing
11393 (setq group-comment (vhdl-parse-group-comment))
11394 (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
11395 (while (not end-of-list)
11396 ;; parse object
11397 (setq object
11398 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
11399 (match-string-no-properties 1)))
11400 ;; parse names (accept extended identifiers)
11401 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11402 (setq names (list (match-string-no-properties 1)))
11403 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
11404 (setq names (append names (list (match-string-no-properties 1)))))
11405 ;; parse direction
11406 (vhdl-parse-string ":[ \t\n\r\f]*")
11407 (setq direct
11408 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
11409 (match-string-no-properties 1)))
11410 ;; parse type
11411 (vhdl-parse-string "\\([^();\n]+\\)")
11412 (setq type (match-string-no-properties 1))
11413 (when (vhdl-in-comment-p) ; if stuck in comment
11414 (setq type (concat type (and (vhdl-parse-string ".*")
11415 (match-string-no-properties 0)))))
11416 (setq comment nil)
11417 (while (looking-at "(")
11418 (setq type (concat type
11419 (buffer-substring-no-properties
11420 (point) (progn (forward-sexp) (point)))
11421 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11422 (match-string-no-properties 1)))))
11423 ;; special case: closing parenthesis is on separate line
11424 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11425 (setq comment (substring type (match-beginning 2)))
11426 (setq type (substring type 0 (match-beginning 1))))
11427 ;; strip of trailing group-comment
11428 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11429 (setq type (substring type 0 (match-end 1)))
11430 (vhdl-forward-syntactic-ws)
11431 (setq end-of-list (vhdl-parse-string ")" t))
11432 (vhdl-parse-string "\\s-*;\\s-*")
11433 ;; parse inline comment
11434 (unless comment
11435 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11436 (match-string-no-properties 1))))
11437 ;; save everything in list
11438 (setq port-list (append port-list
11439 (list (list names object direct type
11440 comment group-comment))))
11441 ;; parse group comment and spacing
11442 (setq group-comment (vhdl-parse-group-comment))))
11443 ; (vhdl-parse-string "end\\>")
11444 ;; parse context clause
11445 (setq context-clause (vhdl-scan-context-clause))
11446 ; ;; add surrounding package to context clause
11447 ; (when (and (equal decl-type "component")
11448 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11449 ; (setq context-clause
11450 ; (append context-clause
11451 ; (list (cons (vhdl-work-library)
11452 ; (match-string-no-properties 1))))))
11453 (message "Reading port of %s \"%s\"...done" decl-type name)
11454 nil)))
11455 ;; finish parsing
11456 (if parse-error
11457 (error parse-error)
11458 (setq vhdl-port-list (list name generic-list port-list context-clause)
11459 vhdl-port-reversed-direction nil
11460 vhdl-port-flattened nil)))))
11462 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11463 "Paste a context clause."
11464 (let ((margin (current-indentation))
11465 (clause-list (nth 3 vhdl-port-list))
11466 clause)
11467 (while clause-list
11468 (setq clause (car clause-list))
11469 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11470 (downcase exclude-pack-name)))
11471 (save-excursion
11472 (re-search-backward
11473 (concat "^\\s-*use\\s-+" (car clause)
11474 "\." (cdr clause) "\\>") nil t)))
11475 (vhdl-template-standard-package (car clause) (cdr clause))
11476 (insert "\n"))
11477 (setq clause-list (cdr clause-list)))))
11479 (defun vhdl-port-paste-generic (&optional no-init)
11480 "Paste a generic clause."
11481 (let ((margin (current-indentation))
11482 (generic-list (nth 1 vhdl-port-list))
11483 list-margin start names generic)
11484 ;; paste generic clause
11485 (when generic-list
11486 (setq start (point))
11487 (vhdl-insert-keyword "GENERIC (")
11488 (unless vhdl-argument-list-indent
11489 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11490 (setq list-margin (current-column))
11491 (while generic-list
11492 (setq generic (car generic-list))
11493 ;; paste group comment and spacing
11494 (when (memq vhdl-include-group-comments '(decl always))
11495 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11496 ;; paste names
11497 (setq names (nth 0 generic))
11498 (while names
11499 (insert (car names))
11500 (setq names (cdr names))
11501 (when names (insert ", ")))
11502 ;; paste type
11503 (insert " : " (nth 1 generic))
11504 ;; paste initialization
11505 (when (and (not no-init) (nth 2 generic))
11506 (insert " := " (nth 2 generic)))
11507 (unless (cdr generic-list) (insert ")"))
11508 (insert ";")
11509 ;; paste comment
11510 (when (and vhdl-include-port-comments (nth 3 generic))
11511 (vhdl-comment-insert-inline (nth 3 generic) t))
11512 (setq generic-list (cdr generic-list))
11513 (when generic-list (insert "\n") (indent-to list-margin)))
11514 ;; align generic clause
11515 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
11517 (defun vhdl-port-paste-port ()
11518 "Paste a port clause."
11519 (let ((margin (current-indentation))
11520 (port-list (nth 2 vhdl-port-list))
11521 list-margin start names port)
11522 ;; paste port clause
11523 (when port-list
11524 (setq start (point))
11525 (vhdl-insert-keyword "PORT (")
11526 (unless vhdl-argument-list-indent
11527 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11528 (setq list-margin (current-column))
11529 (while port-list
11530 (setq port (car port-list))
11531 ;; paste group comment and spacing
11532 (when (memq vhdl-include-group-comments '(decl always))
11533 (vhdl-paste-group-comment (nth 5 port) list-margin))
11534 ;; paste object
11535 (when (nth 1 port) (insert (nth 1 port) " "))
11536 ;; paste names
11537 (setq names (nth 0 port))
11538 (while names
11539 (insert (car names))
11540 (setq names (cdr names))
11541 (when names (insert ", ")))
11542 ;; paste direction
11543 (insert " : ")
11544 (when (nth 2 port) (insert (nth 2 port) " "))
11545 ;; paste type
11546 (insert (nth 3 port))
11547 (unless (cdr port-list) (insert ")"))
11548 (insert ";")
11549 ;; paste comment
11550 (when (and vhdl-include-port-comments (nth 4 port))
11551 (vhdl-comment-insert-inline (nth 4 port) t))
11552 (setq port-list (cdr port-list))
11553 (when port-list (insert "\n") (indent-to list-margin)))
11554 ;; align port clause
11555 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11557 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11558 "Paste as an entity or component declaration."
11559 (unless no-indent (indent-according-to-mode))
11560 (let ((margin (current-indentation))
11561 (name (nth 0 vhdl-port-list)))
11562 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11563 (insert name)
11564 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11565 (vhdl-insert-keyword " IS"))
11566 ;; paste generic and port clause
11567 (when (nth 1 vhdl-port-list)
11568 (insert "\n")
11569 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11570 (insert "\n"))
11571 (indent-to (+ margin vhdl-basic-offset))
11572 (vhdl-port-paste-generic (eq kind 'component)))
11573 (when (nth 2 vhdl-port-list)
11574 (insert "\n")
11575 (when (and (memq vhdl-insert-empty-lines '(unit all))
11576 (eq kind 'entity))
11577 (insert "\n"))
11578 (indent-to (+ margin vhdl-basic-offset)))
11579 (vhdl-port-paste-port)
11580 (insert "\n")
11581 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11582 (insert "\n"))
11583 (indent-to margin)
11584 (vhdl-insert-keyword "END")
11585 (if (eq kind 'entity)
11586 (progn
11587 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11588 (insert " " name))
11589 (vhdl-insert-keyword " COMPONENT")
11590 (unless (vhdl-standard-p '87) (insert " " name)))
11591 (insert ";")))
11593 (defun vhdl-port-paste-entity (&optional no-indent)
11594 "Paste as an entity declaration."
11595 (interactive)
11596 (if (not vhdl-port-list)
11597 (error "ERROR: No port read")
11598 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11599 (vhdl-port-paste-declaration 'entity no-indent)
11600 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11602 (defun vhdl-port-paste-component (&optional no-indent)
11603 "Paste as a component declaration."
11604 (interactive)
11605 (if (not vhdl-port-list)
11606 (error "ERROR: No port read")
11607 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11608 (vhdl-port-paste-declaration 'component no-indent)
11609 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11611 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11612 "Paste as a generic map."
11613 (interactive)
11614 (unless secondary (indent-according-to-mode))
11615 (let ((margin (current-indentation))
11616 list-margin start generic
11617 (generic-list (nth 1 vhdl-port-list)))
11618 (when generic-list
11619 (setq start (point))
11620 (vhdl-insert-keyword "GENERIC MAP (")
11621 (if (not vhdl-association-list-with-formals)
11622 ;; paste list of actual generics
11623 (while generic-list
11624 (insert (if no-constants
11625 (car (nth 0 (car generic-list)))
11626 (or (nth 2 (car generic-list)) " ")))
11627 (setq generic-list (cdr generic-list))
11628 (insert (if generic-list ", " ")"))
11629 (when (and (not generic-list) secondary
11630 (null (nth 2 vhdl-port-list)))
11631 (insert ";")))
11632 (unless vhdl-argument-list-indent
11633 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11634 (setq list-margin (current-column))
11635 (while generic-list
11636 (setq generic (car generic-list))
11637 ;; paste group comment and spacing
11638 (when (eq vhdl-include-group-comments 'always)
11639 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11640 ;; paste formal and actual generic
11641 (insert (car (nth 0 generic)) " => "
11642 (if no-constants
11643 (car (nth 0 generic))
11644 (or (nth 2 generic) "")))
11645 (setq generic-list (cdr generic-list))
11646 (insert (if generic-list "," ")"))
11647 (when (and (not generic-list) secondary
11648 (null (nth 2 vhdl-port-list)))
11649 (insert ";"))
11650 ;; paste comment
11651 (when (or vhdl-include-type-comments
11652 (and vhdl-include-port-comments (nth 3 generic)))
11653 (vhdl-comment-insert-inline
11654 (concat
11655 (when vhdl-include-type-comments
11656 (concat "[" (nth 1 generic) "] "))
11657 (when vhdl-include-port-comments (nth 3 generic))) t))
11658 (when generic-list (insert "\n") (indent-to list-margin)))
11659 ;; align generic map
11660 (when vhdl-auto-align
11661 (vhdl-align-region-groups start (point) 1 t))))))
11663 (defun vhdl-port-paste-port-map ()
11664 "Paste as a port map."
11665 (let ((margin (current-indentation))
11666 list-margin start port
11667 (port-list (nth 2 vhdl-port-list)))
11668 (when port-list
11669 (setq start (point))
11670 (vhdl-insert-keyword "PORT MAP (")
11671 (if (not vhdl-association-list-with-formals)
11672 ;; paste list of actual ports
11673 (while port-list
11674 (insert (vhdl-replace-string vhdl-actual-port-name
11675 (car (nth 0 (car port-list)))))
11676 (setq port-list (cdr port-list))
11677 (insert (if port-list ", " ")")))
11678 (unless vhdl-argument-list-indent
11679 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11680 (setq list-margin (current-column))
11681 (while port-list
11682 (setq port (car port-list))
11683 ;; paste group comment and spacing
11684 (when (eq vhdl-include-group-comments 'always)
11685 (vhdl-paste-group-comment (nth 5 port) list-margin))
11686 ;; paste formal and actual port
11687 (insert (car (nth 0 port)) " => ")
11688 (insert (vhdl-replace-string vhdl-actual-port-name
11689 (car (nth 0 port))))
11690 (setq port-list (cdr port-list))
11691 (insert (if port-list "," ");"))
11692 ;; paste comment
11693 (when (or (and vhdl-include-direction-comments (nth 2 port))
11694 vhdl-include-type-comments
11695 (and vhdl-include-port-comments (nth 4 port)))
11696 (vhdl-comment-insert-inline
11697 (concat
11698 (cond ((and vhdl-include-direction-comments
11699 vhdl-include-type-comments)
11700 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11701 (nth 3 port) "] "))
11702 ((and vhdl-include-direction-comments (nth 2 port))
11703 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11704 (vhdl-include-direction-comments " ")
11705 (vhdl-include-type-comments
11706 (concat "[" (nth 3 port) "] ")))
11707 (when vhdl-include-port-comments (nth 4 port))) t))
11708 (when port-list (insert "\n") (indent-to list-margin)))
11709 ;; align port clause
11710 (when vhdl-auto-align
11711 (vhdl-align-region-groups start (point) 1))))))
11713 (defun vhdl-port-paste-instance (&optional name no-indent title)
11714 "Paste as an instantiation."
11715 (interactive)
11716 (if (not vhdl-port-list)
11717 (error "ERROR: No port read")
11718 (let ((orig-vhdl-port-list vhdl-port-list))
11719 ;; flatten local copy of port list (must be flat for port mapping)
11720 (vhdl-port-flatten)
11721 (unless no-indent (indent-according-to-mode))
11722 (let ((margin (current-indentation)))
11723 ;; paste instantiation
11724 (cond (name
11725 (insert name))
11726 ((equal (cdr vhdl-instance-name) "")
11727 (setq name (vhdl-template-field "instance name")))
11728 ((string-match "\%d" (cdr vhdl-instance-name))
11729 (let ((n 1))
11730 (while (save-excursion
11731 (setq name (format (vhdl-replace-string
11732 vhdl-instance-name
11733 (nth 0 vhdl-port-list)) n))
11734 (goto-char (point-min))
11735 (vhdl-re-search-forward name nil t))
11736 (setq n (1+ n)))
11737 (insert name)))
11738 (t (insert (vhdl-replace-string vhdl-instance-name
11739 (nth 0 vhdl-port-list)))))
11740 (message "Pasting port as instantiation \"%s\"..." name)
11741 (insert ": ")
11742 (when title
11743 (save-excursion
11744 (beginning-of-line)
11745 (indent-to vhdl-basic-offset)
11746 (insert "-- instance \"" name "\"\n")))
11747 (if (not (vhdl-use-direct-instantiation))
11748 (insert (nth 0 vhdl-port-list))
11749 (vhdl-insert-keyword "ENTITY ")
11750 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11751 (when (nth 1 vhdl-port-list)
11752 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11753 (vhdl-port-paste-generic-map t t))
11754 (when (nth 2 vhdl-port-list)
11755 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11756 (vhdl-port-paste-port-map))
11757 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11758 (insert ";"))
11759 (message "Pasting port as instantiation \"%s\"...done" name))
11760 (setq vhdl-port-list orig-vhdl-port-list))))
11762 (defun vhdl-port-paste-constants (&optional no-indent)
11763 "Paste generics as constants."
11764 (interactive)
11765 (if (not vhdl-port-list)
11766 (error "ERROR: No port read")
11767 (let ((orig-vhdl-port-list vhdl-port-list))
11768 (message "Pasting port as constants...")
11769 ;; flatten local copy of port list (must be flat for constant initial.)
11770 (vhdl-port-flatten)
11771 (unless no-indent (indent-according-to-mode))
11772 (let ((margin (current-indentation))
11773 start generic name
11774 (generic-list (nth 1 vhdl-port-list)))
11775 (when generic-list
11776 (setq start (point))
11777 (while generic-list
11778 (setq generic (car generic-list))
11779 ;; paste group comment and spacing
11780 (when (memq vhdl-include-group-comments '(decl always))
11781 (vhdl-paste-group-comment (nth 4 generic) margin))
11782 (vhdl-insert-keyword "CONSTANT ")
11783 ;; paste generic constants
11784 (setq name (nth 0 generic))
11785 (when name
11786 (insert (car name))
11787 ;; paste type
11788 (insert " : " (nth 1 generic))
11789 ;; paste initialization
11790 (when (nth 2 generic)
11791 (insert " := " (nth 2 generic)))
11792 (insert ";")
11793 ;; paste comment
11794 (when (and vhdl-include-port-comments (nth 3 generic))
11795 (vhdl-comment-insert-inline (nth 3 generic) t))
11796 (setq generic-list (cdr generic-list))
11797 (when generic-list (insert "\n") (indent-to margin))))
11798 ;; align signal list
11799 (when vhdl-auto-align
11800 (vhdl-align-region-groups start (point) 1))))
11801 (message "Pasting port as constants...done")
11802 (setq vhdl-port-list orig-vhdl-port-list))))
11804 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11805 "Paste ports as internal signals."
11806 (interactive)
11807 (if (not vhdl-port-list)
11808 (error "ERROR: No port read")
11809 (message "Pasting port as signals...")
11810 (unless no-indent (indent-according-to-mode))
11811 (let ((margin (current-indentation))
11812 start port names
11813 (port-list (nth 2 vhdl-port-list)))
11814 (when port-list
11815 (setq start (point))
11816 (while port-list
11817 (setq port (car port-list))
11818 ;; paste group comment and spacing
11819 (when (memq vhdl-include-group-comments '(decl always))
11820 (vhdl-paste-group-comment (nth 5 port) margin))
11821 ;; paste object
11822 (if (nth 1 port)
11823 (insert (nth 1 port) " ")
11824 (vhdl-insert-keyword "SIGNAL "))
11825 ;; paste actual port signals
11826 (setq names (nth 0 port))
11827 (while names
11828 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11829 (setq names (cdr names))
11830 (when names (insert ", ")))
11831 ;; paste type
11832 (insert " : " (nth 3 port))
11833 ;; paste initialization (inputs only)
11834 (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
11835 (insert " := "
11836 (cond ((string-match "integer" (nth 3 port)) "0")
11837 ((string-match "natural" (nth 3 port)) "0")
11838 ((string-match "positive" (nth 3 port)) "0")
11839 ((string-match "real" (nth 3 port)) "0.0")
11840 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
11841 (t "'0'"))))
11842 (insert ";")
11843 ;; paste comment
11844 (when (or (and vhdl-include-direction-comments (nth 2 port))
11845 (and vhdl-include-port-comments (nth 4 port)))
11846 (vhdl-comment-insert-inline
11847 (concat
11848 (cond ((and vhdl-include-direction-comments (nth 2 port))
11849 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11850 (vhdl-include-direction-comments " "))
11851 (when vhdl-include-port-comments (nth 4 port))) t))
11852 (setq port-list (cdr port-list))
11853 (when port-list (insert "\n") (indent-to margin)))
11854 ;; align signal list
11855 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11856 (message "Pasting port as signals...done")))
11858 (defun vhdl-port-paste-initializations (&optional no-indent)
11859 "Paste ports as signal initializations."
11860 (interactive)
11861 (if (not vhdl-port-list)
11862 (error "ERROR: No port read")
11863 (let ((orig-vhdl-port-list vhdl-port-list))
11864 (message "Pasting port as initializations...")
11865 ;; flatten local copy of port list (must be flat for signal initial.)
11866 (vhdl-port-flatten)
11867 (unless no-indent (indent-according-to-mode))
11868 (let ((margin (current-indentation))
11869 start port name
11870 (port-list (nth 2 vhdl-port-list)))
11871 (when port-list
11872 (setq start (point))
11873 (while port-list
11874 (setq port (car port-list))
11875 ;; paste actual port signal (inputs only)
11876 (when (equal "IN" (upcase (nth 2 port)))
11877 (setq name (car (nth 0 port)))
11878 (insert (vhdl-replace-string vhdl-actual-port-name name))
11879 ;; paste initialization
11880 (insert " <= "
11881 (cond ((string-match "integer" (nth 3 port)) "0")
11882 ((string-match "natural" (nth 3 port)) "0")
11883 ((string-match "positive" (nth 3 port)) "0")
11884 ((string-match "real" (nth 3 port)) "0.0")
11885 ((string-match "(.+)" (nth 3 port)) "(others => '0')")
11886 (t "'0'"))
11887 ";"))
11888 (setq port-list (cdr port-list))
11889 (when (and port-list
11890 (equal "IN" (upcase (nth 2 (car port-list)))))
11891 (insert "\n") (indent-to margin)))
11892 ;; align signal list
11893 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11894 (message "Pasting port as initializations...done")
11895 (setq vhdl-port-list orig-vhdl-port-list))))
11897 (defun vhdl-port-paste-testbench ()
11898 "Paste as a bare-bones testbench."
11899 (interactive)
11900 (if (not vhdl-port-list)
11901 (error "ERROR: No port read")
11902 (let ((case-fold-search t)
11903 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11904 (nth 0 vhdl-port-list)))
11905 (source-buffer (current-buffer))
11906 arch-name config-name ent-file-name arch-file-name
11907 ent-buffer arch-buffer position)
11908 ;; open entity file
11909 (unless (eq vhdl-testbench-create-files 'none)
11910 (setq ent-file-name
11911 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11912 ent-name t)
11913 "." (file-name-extension (buffer-file-name))))
11914 (if (file-exists-p ent-file-name)
11915 (if (y-or-n-p
11916 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11917 (progn (find-file ent-file-name)
11918 (erase-buffer)
11919 (set-buffer-modified-p nil))
11920 (if (eq vhdl-testbench-create-files 'separate)
11921 (setq ent-file-name nil)
11922 (error "ERROR: Pasting port as testbench...aborted")))
11923 (find-file ent-file-name)))
11924 (unless (and (eq vhdl-testbench-create-files 'separate)
11925 (null ent-file-name))
11926 ;; paste entity header
11927 (if vhdl-testbench-include-header
11928 (progn (vhdl-template-header
11929 (concat "Testbench for design \""
11930 (nth 0 vhdl-port-list) "\""))
11931 (goto-char (point-max)))
11932 (vhdl-comment-display-line) (insert "\n\n"))
11933 ;; paste std_logic_1164 package
11934 (when vhdl-testbench-include-library
11935 (vhdl-template-package-std-logic-1164)
11936 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11937 ;; paste entity declaration
11938 (vhdl-insert-keyword "ENTITY ")
11939 (insert ent-name)
11940 (vhdl-insert-keyword " IS")
11941 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11942 (insert "\n")
11943 (vhdl-insert-keyword "END ")
11944 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11945 (insert ent-name ";")
11946 (insert "\n\n")
11947 (vhdl-comment-display-line) (insert "\n"))
11948 ;; get architecture name
11949 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11950 (read-from-minibuffer "architecture name: "
11951 nil vhdl-minibuffer-local-map)
11952 (vhdl-replace-string vhdl-testbench-architecture-name
11953 (nth 0 vhdl-port-list))))
11954 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11955 ;; open architecture file
11956 (if (not (eq vhdl-testbench-create-files 'separate))
11957 (insert "\n")
11958 (setq ent-buffer (current-buffer))
11959 (setq arch-file-name
11960 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11961 (concat ent-name " " arch-name) t)
11962 "." (file-name-extension (buffer-file-name))))
11963 (when (and (file-exists-p arch-file-name)
11964 (not (y-or-n-p (concat "File \"" arch-file-name
11965 "\" exists; overwrite? "))))
11966 (error "ERROR: Pasting port as testbench...aborted"))
11967 (find-file arch-file-name)
11968 (erase-buffer)
11969 (set-buffer-modified-p nil)
11970 ;; paste architecture header
11971 (if vhdl-testbench-include-header
11972 (progn (vhdl-template-header
11973 (concat "Testbench architecture for design \""
11974 (nth 0 vhdl-port-list) "\""))
11975 (goto-char (point-max)))
11976 (vhdl-comment-display-line) (insert "\n\n")))
11977 ;; paste architecture body
11978 (vhdl-insert-keyword "ARCHITECTURE ")
11979 (insert arch-name)
11980 (vhdl-insert-keyword " OF ")
11981 (insert ent-name)
11982 (vhdl-insert-keyword " IS")
11983 (insert "\n\n") (indent-to vhdl-basic-offset)
11984 ;; paste component declaration
11985 (unless (vhdl-use-direct-instantiation)
11986 (vhdl-port-paste-component t)
11987 (insert "\n\n") (indent-to vhdl-basic-offset))
11988 ;; paste constants
11989 (when (nth 1 vhdl-port-list)
11990 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11991 (vhdl-port-paste-constants t)
11992 (insert "\n\n") (indent-to vhdl-basic-offset))
11993 ;; paste internal signals
11994 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11995 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11996 (insert "\n")
11997 ;; paste custom declarations
11998 (unless (equal "" vhdl-testbench-declarations)
11999 (insert "\n")
12000 (setq position (point))
12001 (vhdl-insert-string-or-file vhdl-testbench-declarations)
12002 (vhdl-indent-region position (point)))
12003 (setq position (point))
12004 (insert "\n\n")
12005 (vhdl-comment-display-line) (insert "\n")
12006 (when vhdl-testbench-include-configuration
12007 (setq config-name (vhdl-replace-string
12008 vhdl-testbench-configuration-name
12009 (concat ent-name " " arch-name)))
12010 (insert "\n")
12011 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
12012 (vhdl-insert-keyword " OF ") (insert ent-name)
12013 (vhdl-insert-keyword " IS\n")
12014 (indent-to vhdl-basic-offset)
12015 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
12016 (indent-to vhdl-basic-offset)
12017 (vhdl-insert-keyword "END FOR;\n")
12018 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
12019 (vhdl-comment-display-line) (insert "\n"))
12020 (goto-char position)
12021 (vhdl-template-begin-end
12022 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
12023 ;; paste instantiation
12024 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
12025 (vhdl-port-paste-instance
12026 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
12027 (insert "\n")
12028 ;; paste custom statements
12029 (unless (equal "" vhdl-testbench-statements)
12030 (insert "\n")
12031 (setq position (point))
12032 (vhdl-insert-string-or-file vhdl-testbench-statements)
12033 (vhdl-indent-region position (point)))
12034 (insert "\n")
12035 (indent-to vhdl-basic-offset)
12036 (unless (eq vhdl-testbench-create-files 'none)
12037 (setq arch-buffer (current-buffer))
12038 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
12039 (set-buffer arch-buffer) (save-buffer))
12040 (message "%s"
12041 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12042 ent-name arch-name)
12043 (and ent-file-name
12044 (format "\n File created: \"%s\"" ent-file-name))
12045 (and arch-file-name
12046 (format "\n File created: \"%s\"" arch-file-name)))))))
12049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12050 ;;; Subprogram interface translation
12051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12053 (defvar vhdl-subprog-list nil
12054 "Variable to hold last subprogram interface parsed.")
12055 ;; structure: (parenthesized expression means list of such entries)
12056 ;; (subprog-name kind
12057 ;; ((names) object direct type init comment group-comment)
12058 ;; return-type return-comment group-comment)
12060 (defvar vhdl-subprog-flattened nil
12061 "Indicates whether an subprogram interface has been flattened.")
12063 (defun vhdl-subprog-flatten ()
12064 "Flatten interface list so that only one parameter exists per line."
12065 (interactive)
12066 (if (not vhdl-subprog-list)
12067 (error "ERROR: No subprogram interface has been read")
12068 (message "Flattening subprogram interface...")
12069 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
12070 new-subprog-list old-subprog new-subprog names)
12071 ;; traverse parameter list and flatten entries
12072 (while old-subprog-list
12073 (setq old-subprog (car old-subprog-list))
12074 (setq names (car old-subprog))
12075 (while names
12076 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
12077 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
12078 (setq names (cdr names)))
12079 (setq old-subprog-list (cdr old-subprog-list)))
12080 (setq vhdl-subprog-list
12081 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
12082 new-subprog-list (nth 3 vhdl-subprog-list)
12083 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
12084 vhdl-subprog-flattened t)
12085 (message "Flattening subprogram interface...done"))))
12087 (defun vhdl-subprog-copy ()
12088 "Get interface information from a subprogram specification."
12089 (interactive)
12090 (save-excursion
12091 (let (parse-error pos end-of-list
12092 name kind param-list object names direct type init
12093 comment group-comment
12094 return-type return-comment return-group-comment)
12095 (vhdl-prepare-search-2
12096 (setq
12097 parse-error
12098 (catch 'parse
12099 ;; check if within function declaration
12100 (setq pos (point))
12101 (end-of-line)
12102 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12103 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
12104 (goto-char (match-end 0))
12105 (save-excursion (backward-char)
12106 (forward-sexp)
12107 (<= pos (point))))
12108 (throw 'parse "ERROR: Not within a subprogram specification"))
12109 (setq name (match-string-no-properties 5))
12110 (setq kind (if (match-string 2) 'procedure 'function))
12111 (setq end-of-list (not (match-string 7)))
12112 (message "Reading interface of subprogram \"%s\"..." name)
12113 ;; parse parameter list
12114 (setq group-comment (vhdl-parse-group-comment))
12115 (setq end-of-list (or end-of-list
12116 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
12117 (while (not end-of-list)
12118 ;; parse object
12119 (setq object
12120 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
12121 (match-string-no-properties 1)))
12122 ;; parse names (accept extended identifiers)
12123 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12124 (setq names (list (match-string-no-properties 1)))
12125 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
12126 (setq names (append names (list (match-string-no-properties 1)))))
12127 ;; parse direction
12128 (vhdl-parse-string ":[ \t\n\r\f]*")
12129 (setq direct
12130 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
12131 (match-string-no-properties 1)))
12132 ;; parse type
12133 (vhdl-parse-string "\\([^():;\n]+\\)")
12134 (setq type (match-string-no-properties 1))
12135 (setq comment nil)
12136 (while (looking-at "(")
12137 (setq type
12138 (concat type
12139 (buffer-substring-no-properties
12140 (point) (progn (forward-sexp) (point)))
12141 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
12142 (match-string-no-properties 1)))))
12143 ;; special case: closing parenthesis is on separate line
12144 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
12145 (setq comment (substring type (match-beginning 2)))
12146 (setq type (substring type 0 (match-beginning 1))))
12147 ;; strip off trailing group-comment
12148 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
12149 (setq type (substring type 0 (match-end 1)))
12150 ;; parse initialization expression
12151 (setq init nil)
12152 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
12153 (vhdl-parse-string "\\([^();\n]*\\)")
12154 (setq init (match-string-no-properties 1))
12155 (while (looking-at "(")
12156 (setq init
12157 (concat init
12158 (buffer-substring-no-properties
12159 (point) (progn (forward-sexp) (point)))
12160 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
12161 (match-string-no-properties 1))))))
12162 ;; special case: closing parenthesis is on separate line
12163 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
12164 (setq comment (substring init (match-beginning 2)))
12165 (setq init (substring init 0 (match-beginning 1)))
12166 (vhdl-forward-syntactic-ws))
12167 (skip-chars-forward " \t")
12168 ;; parse inline comment, special case: as above, no initial.
12169 (unless comment
12170 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12171 (match-string-no-properties 1))))
12172 (vhdl-forward-syntactic-ws)
12173 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
12174 ;; parse inline comment
12175 (unless comment
12176 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12177 (match-string-no-properties 1))))
12178 (setq return-group-comment (vhdl-parse-group-comment))
12179 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12180 ;; parse return type
12181 (when (match-string 3)
12182 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12183 (setq return-type (match-string-no-properties 1))
12184 (when (and return-type
12185 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
12186 (setq return-comment (substring return-type (match-beginning 2)))
12187 (setq return-type (substring return-type 0 (match-beginning 1))))
12188 ;; strip of trailing group-comment
12189 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
12190 (setq return-type (substring return-type 0 (match-end 1)))
12191 ;; parse return comment
12192 (unless return-comment
12193 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12194 (match-string-no-properties 1)))))
12195 ;; parse inline comment
12196 (unless comment
12197 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
12198 (match-string-no-properties 1))))
12199 ;; save everything in list
12200 (setq param-list (append param-list
12201 (list (list names object direct type init
12202 comment group-comment))))
12203 ;; parse group comment and spacing
12204 (setq group-comment (vhdl-parse-group-comment)))
12205 (message "Reading interface of subprogram \"%s\"...done" name)
12206 nil)))
12207 ;; finish parsing
12208 (if parse-error
12209 (error parse-error)
12210 (setq vhdl-subprog-list
12211 (list name kind param-list return-type return-comment
12212 return-group-comment)
12213 vhdl-subprog-flattened nil)))))
12215 (defun vhdl-subprog-paste-specification (kind)
12216 "Paste as a subprogram specification."
12217 (indent-according-to-mode)
12218 (let ((margin (current-column))
12219 (param-list (nth 2 vhdl-subprog-list))
12220 list-margin start names param)
12221 ;; paste keyword and name
12222 (vhdl-insert-keyword
12223 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
12224 (insert (nth 0 vhdl-subprog-list))
12225 (if (not param-list)
12226 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12227 (setq start (point))
12228 ;; paste parameter list
12229 (insert " (")
12230 (unless vhdl-argument-list-indent
12231 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12232 (setq list-margin (current-column))
12233 (while param-list
12234 (setq param (car param-list))
12235 ;; paste group comment and spacing
12236 (when (memq vhdl-include-group-comments (list kind 'always))
12237 (vhdl-paste-group-comment (nth 6 param) list-margin))
12238 ;; paste object
12239 (when (nth 1 param) (insert (nth 1 param) " "))
12240 ;; paste names
12241 (setq names (nth 0 param))
12242 (while names
12243 (insert (car names))
12244 (setq names (cdr names))
12245 (when names (insert ", ")))
12246 ;; paste direction
12247 (insert " : ")
12248 (when (nth 2 param) (insert (nth 2 param) " "))
12249 ;; paste type
12250 (insert (nth 3 param))
12251 ;; paste initialization
12252 (when (nth 4 param) (insert " := " (nth 4 param)))
12253 ;; terminate line
12254 (if (cdr param-list)
12255 (insert ";")
12256 (insert ")")
12257 (when (null (nth 3 vhdl-subprog-list))
12258 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
12259 ;; paste comment
12260 (when (and vhdl-include-port-comments (nth 5 param))
12261 (vhdl-comment-insert-inline (nth 5 param) t))
12262 (setq param-list (cdr param-list))
12263 (when param-list (insert "\n") (indent-to list-margin)))
12264 (when (nth 3 vhdl-subprog-list)
12265 (insert "\n") (indent-to list-margin)
12266 ;; paste group comment and spacing
12267 (when (memq vhdl-include-group-comments (list kind 'always))
12268 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
12269 ;; paste return type
12270 (insert "return " (nth 3 vhdl-subprog-list))
12271 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
12272 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
12273 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
12274 ;; align parameter list
12275 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
12276 ;; paste body
12277 (when (eq kind 'body)
12278 (insert "\n")
12279 (vhdl-template-begin-end
12280 (unless (vhdl-standard-p '87)
12281 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
12282 (nth 0 vhdl-subprog-list) margin))))
12284 (defun vhdl-subprog-paste-declaration ()
12285 "Paste as a subprogram declaration."
12286 (interactive)
12287 (if (not vhdl-subprog-list)
12288 (error "ERROR: No subprogram interface read")
12289 (message "Pasting interface as subprogram declaration \"%s\"..."
12290 (car vhdl-subprog-list))
12291 ;; paste specification
12292 (vhdl-subprog-paste-specification 'decl)
12293 (message "Pasting interface as subprogram declaration \"%s\"...done"
12294 (car vhdl-subprog-list))))
12296 (defun vhdl-subprog-paste-body ()
12297 "Paste as a subprogram body."
12298 (interactive)
12299 (if (not vhdl-subprog-list)
12300 (error "ERROR: No subprogram interface read")
12301 (message "Pasting interface as subprogram body \"%s\"..."
12302 (car vhdl-subprog-list))
12303 ;; paste specification and body
12304 (vhdl-subprog-paste-specification 'body)
12305 (message "Pasting interface as subprogram body \"%s\"...done"
12306 (car vhdl-subprog-list))))
12308 (defun vhdl-subprog-paste-call ()
12309 "Paste as a subprogram call."
12310 (interactive)
12311 (if (not vhdl-subprog-list)
12312 (error "ERROR: No subprogram interface read")
12313 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
12314 param-list margin list-margin param start)
12315 ;; flatten local copy of interface list (must be flat for parameter mapping)
12316 (vhdl-subprog-flatten)
12317 (setq param-list (nth 2 vhdl-subprog-list))
12318 (indent-according-to-mode)
12319 (setq margin (current-indentation))
12320 (message "Pasting interface as subprogram call \"%s\"..."
12321 (car vhdl-subprog-list))
12322 ;; paste name
12323 (insert (nth 0 vhdl-subprog-list))
12324 (if (not param-list)
12325 (insert ";")
12326 (setq start (point))
12327 ;; paste parameter list
12328 (insert " (")
12329 (unless vhdl-argument-list-indent
12330 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
12331 (setq list-margin (current-column))
12332 (while param-list
12333 (setq param (car param-list))
12334 ;; paste group comment and spacing
12335 (when (eq vhdl-include-group-comments 'always)
12336 (vhdl-paste-group-comment (nth 6 param) list-margin))
12337 ;; paste formal port
12338 (insert (car (nth 0 param)) " => ")
12339 (setq param-list (cdr param-list))
12340 (insert (if param-list "," ");"))
12341 ;; paste comment
12342 (when (and vhdl-include-port-comments (nth 5 param))
12343 (vhdl-comment-insert-inline (nth 5 param)))
12344 (when param-list (insert "\n") (indent-to list-margin)))
12345 ;; align parameter list
12346 (when vhdl-auto-align
12347 (vhdl-align-region-groups start (point) 1)))
12348 (message "Pasting interface as subprogram call \"%s\"...done"
12349 (car vhdl-subprog-list))
12350 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12354 ;;; Miscellaneous
12355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12357 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12358 ;; Hippie expand customization
12360 (defvar vhdl-expand-upper-case nil)
12362 (defun vhdl-try-expand-abbrev (old)
12363 "Try expanding abbreviations from `vhdl-abbrev-list'."
12364 (unless old
12365 (he-init-string (he-dabbrev-beg) (point))
12366 (setq he-expand-list
12367 (let ((abbrev-list vhdl-abbrev-list)
12368 (sel-abbrev-list '()))
12369 (while abbrev-list
12370 (when (or (not (stringp (car abbrev-list)))
12371 (string-match
12372 (concat "^" he-search-string) (car abbrev-list)))
12373 (setq sel-abbrev-list
12374 (cons (car abbrev-list) sel-abbrev-list)))
12375 (setq abbrev-list (cdr abbrev-list)))
12376 (nreverse sel-abbrev-list))))
12377 (while (and he-expand-list
12378 (or (not (stringp (car he-expand-list)))
12379 (he-string-member (car he-expand-list) he-tried-table t)))
12380 ; (equal (car he-expand-list) he-search-string)))
12381 (unless (stringp (car he-expand-list))
12382 (setq vhdl-expand-upper-case (car he-expand-list)))
12383 (setq he-expand-list (cdr he-expand-list)))
12384 (if (null he-expand-list)
12385 (progn (when old (he-reset-string))
12386 nil)
12387 (he-substitute-string
12388 (if vhdl-expand-upper-case
12389 (upcase (car he-expand-list))
12390 (car he-expand-list))
12392 (setq he-expand-list (cdr he-expand-list))
12395 (defun vhdl-he-list-beg ()
12396 "Also looks at the word before `(' in order to better match parenthesized
12397 expressions (e.g. for index ranges of types and signals)."
12398 (save-excursion
12399 (condition-case ()
12400 (progn (backward-up-list 1)
12401 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12402 (error ()))
12403 (point)))
12405 ;; override `he-list-beg' from `hippie-exp'
12406 (unless (and (boundp 'viper-mode) viper-mode)
12407 (defalias 'he-list-beg 'vhdl-he-list-beg))
12409 ;; function for expanding abbrevs and dabbrevs
12410 (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
12411 '(try-expand-dabbrev
12412 try-expand-dabbrev-all-buffers
12413 vhdl-try-expand-abbrev)))
12415 ;; function for expanding parenthesis
12416 (defalias 'vhdl-expand-paren (make-hippie-expand-function
12417 '(try-expand-list
12418 try-expand-list-all-buffers)))
12420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12421 ;; Case fixing
12423 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12424 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12425 depending on parameter UPPER-CASE."
12426 (let ((case-replace nil)
12427 (last-update 0))
12428 (vhdl-prepare-search-2
12429 (save-excursion
12430 (goto-char end)
12431 (setq end (point-marker))
12432 (goto-char beg)
12433 (while (re-search-forward word-regexp end t)
12434 (or (vhdl-in-literal)
12435 (if upper-case
12436 (upcase-word -1)
12437 (downcase-word -1)))
12438 (when (and count vhdl-progress-interval (not noninteractive)
12439 (< vhdl-progress-interval
12440 (- (nth 1 (current-time)) last-update)))
12441 (message "Fixing case... (%2d%s)"
12442 (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
12443 "%")
12444 (setq last-update (nth 1 (current-time)))))
12445 (goto-char end)))))
12447 (defun vhdl-fix-case-region (beg end &optional arg)
12448 "Convert all VHDL words in region to lower or upper case, depending on
12449 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12450 (interactive "r\nP")
12451 (vhdl-fix-case-region-1
12452 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
12453 (vhdl-fix-case-region-1
12454 beg end vhdl-upper-case-types vhdl-types-regexp 1)
12455 (vhdl-fix-case-region-1
12456 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12457 (vhdl-fix-case-region-1
12458 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12459 (vhdl-fix-case-region-1
12460 beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
12461 (when vhdl-progress-interval (message "Fixing case...done")))
12463 (defun vhdl-fix-case-buffer ()
12464 "Convert all VHDL words in buffer to lower or upper case, depending on
12465 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
12466 (interactive)
12467 (vhdl-fix-case-region (point-min) (point-max)))
12469 (defun vhdl-fix-case-word (&optional arg)
12470 "Convert word after cursor to upper case if necessary."
12471 (interactive "p")
12472 (save-excursion
12473 (when arg (backward-word 1))
12474 (vhdl-prepare-search-1
12475 (when (and vhdl-upper-case-keywords
12476 (looking-at vhdl-keywords-regexp))
12477 (upcase-word 1))
12478 (when (and vhdl-upper-case-types
12479 (looking-at vhdl-types-regexp))
12480 (upcase-word 1))
12481 (when (and vhdl-upper-case-attributes
12482 (looking-at vhdl-attributes-regexp))
12483 (upcase-word 1))
12484 (when (and vhdl-upper-case-enum-values
12485 (looking-at vhdl-enum-values-regexp))
12486 (upcase-word 1))
12487 (when (and vhdl-upper-case-constants
12488 (looking-at vhdl-constants-regexp))
12489 (upcase-word 1)))))
12491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12492 ;; Line handling functions
12494 (defun vhdl-current-line ()
12495 "Return the line number of the line containing point."
12496 (save-restriction
12497 (widen)
12498 (1+ (count-lines (point-min) (point-at-bol)))))
12500 (defun vhdl-line-kill-entire (&optional arg)
12501 "Delete entire line."
12502 (interactive "p")
12503 (beginning-of-line)
12504 (kill-line (or arg 1)))
12506 (defun vhdl-line-kill (&optional arg)
12507 "Kill current line."
12508 (interactive "p")
12509 (vhdl-line-kill-entire arg))
12511 (defun vhdl-line-copy (&optional arg)
12512 "Copy current line."
12513 (interactive "p")
12514 (save-excursion
12515 (let ((position (point-at-bol)))
12516 (forward-line (or arg 1))
12517 (copy-region-as-kill position (point)))))
12519 (defun vhdl-line-yank ()
12520 "Yank entire line."
12521 (interactive)
12522 (beginning-of-line)
12523 (yank))
12525 (defun vhdl-line-expand (&optional prefix-arg)
12526 "Hippie-expand current line."
12527 (interactive "P")
12528 (let ((case-fold-search t) (case-replace nil)
12529 (hippie-expand-try-functions-list
12530 '(try-expand-line try-expand-line-all-buffers)))
12531 (hippie-expand prefix-arg)))
12533 (defun vhdl-line-transpose-next (&optional arg)
12534 "Interchange this line with next line."
12535 (interactive "p")
12536 (forward-line 1)
12537 (transpose-lines (or arg 1))
12538 (forward-line -1))
12540 (defun vhdl-line-transpose-previous (&optional arg)
12541 "Interchange this line with previous line."
12542 (interactive "p")
12543 (forward-line 1)
12544 (transpose-lines (- 0 (or arg 0)))
12545 (forward-line -1))
12547 (defun vhdl-line-open ()
12548 "Open a new line and indent."
12549 (interactive)
12550 (end-of-line -0)
12551 (newline-and-indent))
12553 (defun vhdl-delete-indentation ()
12554 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12555 it works within comments too."
12556 (interactive)
12557 (let ((fill-prefix "-- "))
12558 (delete-indentation)))
12560 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12561 ;; Move functions
12563 (defun vhdl-forward-same-indent ()
12564 "Move forward to next line with same indent."
12565 (interactive)
12566 (let ((pos (point))
12567 (indent (current-indentation)))
12568 (beginning-of-line 2)
12569 (while (and (not (eobp))
12570 (or (looking-at "^\\s-*\\(--.*\\)?$")
12571 (> (current-indentation) indent)))
12572 (beginning-of-line 2))
12573 (if (= (current-indentation) indent)
12574 (back-to-indentation)
12575 (message "No following line with same indent found in this block")
12576 (goto-char pos)
12577 nil)))
12579 (defun vhdl-backward-same-indent ()
12580 "Move backward to previous line with same indent."
12581 (interactive)
12582 (let ((pos (point))
12583 (indent (current-indentation)))
12584 (beginning-of-line -0)
12585 (while (and (not (bobp))
12586 (or (looking-at "^\\s-*\\(--.*\\)?$")
12587 (> (current-indentation) indent)))
12588 (beginning-of-line -0))
12589 (if (= (current-indentation) indent)
12590 (back-to-indentation)
12591 (message "No preceding line with same indent found in this block")
12592 (goto-char pos)
12593 nil)))
12595 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12596 ;; Statistics
12598 (defun vhdl-statistics-buffer ()
12599 "Get some file statistics."
12600 (interactive)
12601 (let ((no-stats 0)
12602 (no-code-lines 0)
12603 (no-empty-lines 0)
12604 (no-comm-lines 0)
12605 (no-comments 0)
12606 (no-lines (count-lines (point-min) (point-max))))
12607 (save-excursion
12608 ;; count statements
12609 (goto-char (point-min))
12610 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12611 (if (match-string 1)
12612 (goto-char (match-end 1))
12613 (setq no-stats (1+ no-stats))))
12614 ;; count code lines
12615 (goto-char (point-min))
12616 (while (not (eobp))
12617 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12618 (setq no-code-lines (1+ no-code-lines)))
12619 (beginning-of-line 2))
12620 ;; count empty lines
12621 (goto-char (point-min))
12622 (while (and (re-search-forward "^\\s-*$" nil t)
12623 (not (eq (point) (point-max))))
12624 (if (match-string 1)
12625 (goto-char (match-end 1))
12626 (setq no-empty-lines (1+ no-empty-lines))
12627 (unless (eq (point) (point-max))
12628 (forward-char))))
12629 ;; count comment-only lines
12630 (goto-char (point-min))
12631 (while (re-search-forward "^\\s-*--.*" nil t)
12632 (if (match-string 1)
12633 (goto-char (match-end 1))
12634 (setq no-comm-lines (1+ no-comm-lines))))
12635 ;; count comments
12636 (goto-char (point-min))
12637 (while (re-search-forward "--.*" nil t)
12638 (if (match-string 1)
12639 (goto-char (match-end 1))
12640 (setq no-comments (1+ no-comments)))))
12641 ;; print results
12642 (message "\n\
12643 File statistics: \"%s\"\n\
12644 ---------------------\n\
12645 # statements : %5d\n\
12646 # code lines : %5d\n\
12647 # empty lines : %5d\n\
12648 # comment lines : %5d\n\
12649 # comments : %5d\n\
12650 # total lines : %5d\n\ "
12651 (buffer-file-name) no-stats no-code-lines no-empty-lines
12652 no-comm-lines no-comments no-lines)
12653 (unless vhdl-emacs-21 (vhdl-show-messages))))
12655 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12656 ;; Help functions
12658 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12659 "Like `re-search-forward', but does not match within literals."
12660 (let (pos)
12661 (save-excursion
12662 (while (and (setq pos (re-search-forward regexp bound noerror count))
12663 (vhdl-in-literal))))
12664 (when pos (goto-char pos))
12665 pos))
12667 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12668 "Like `re-search-backward', but does not match within literals."
12669 (let (pos)
12670 (save-excursion
12671 (while (and (setq pos (re-search-backward regexp bound noerror count))
12672 (vhdl-in-literal))))
12673 (when pos (goto-char pos))
12674 pos))
12677 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12678 ;;; Project
12679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12681 (defun vhdl-set-project (name)
12682 "Set current project to NAME."
12683 (interactive
12684 (list (let ((completion-ignore-case t))
12685 (completing-read "Project name: " vhdl-project-alist nil t))))
12686 (cond ((equal name "")
12687 (setq vhdl-project nil)
12688 (message "Current VHDL project: None"))
12689 ((assoc name vhdl-project-alist)
12690 (setq vhdl-project name)
12691 (message "Current VHDL project: \"%s\"" name))
12693 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12694 (vhdl-speedbar-update-current-project))
12696 (defun vhdl-set-default-project ()
12697 "Set current project as default on startup."
12698 (interactive)
12699 (customize-set-variable 'vhdl-project vhdl-project)
12700 (customize-save-customized))
12702 (defun vhdl-toggle-project (name token indent)
12703 "Set current project to NAME or unset if NAME is current project."
12704 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12706 (defun vhdl-export-project (file-name)
12707 "Write project setup for current project."
12708 (interactive
12709 (let ((name (vhdl-resolve-env-variable
12710 (vhdl-replace-string
12711 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12712 (concat (subst-char-in-string
12713 ? ?_ (or (vhdl-project-p)
12714 (error "ERROR: No current project")))
12715 " " (user-login-name))))))
12716 (list (read-file-name
12717 "Write project file: "
12718 (when (file-name-absolute-p name) "") nil nil name))))
12719 (setq file-name (abbreviate-file-name file-name))
12720 (let ((orig-buffer (current-buffer)))
12721 (unless (file-exists-p (file-name-directory file-name))
12722 (make-directory (file-name-directory file-name) t))
12723 (if (not (file-writable-p file-name))
12724 (error "ERROR: File not writable: \"%s\"" file-name)
12725 (set-buffer (find-file-noselect file-name t t))
12726 (erase-buffer)
12727 (insert ";; -*- Emacs-Lisp -*-\n\n"
12728 ";;; " (file-name-nondirectory file-name)
12729 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12730 ";; Project : " vhdl-project "\n"
12731 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12732 (user-login-name) "\n\n\n"
12733 ";; project name\n"
12734 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12735 ";; project setup\n"
12736 "(aput 'vhdl-project-alist vhdl-project\n'")
12737 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12738 (insert ")\n")
12739 (save-buffer)
12740 (kill-buffer (current-buffer))
12741 (set-buffer orig-buffer))))
12743 (defun vhdl-import-project (file-name &optional auto not-make-current)
12744 "Read project setup and set current project."
12745 (interactive
12746 (let ((name (vhdl-resolve-env-variable
12747 (vhdl-replace-string
12748 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12749 (concat "" " " (user-login-name))))))
12750 (list (read-file-name
12751 "Read project file: " (when (file-name-absolute-p name) "") nil t
12752 (file-name-directory name)))))
12753 (when (file-exists-p file-name)
12754 (condition-case ()
12755 (let ((current-project vhdl-project))
12756 (load-file file-name)
12757 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12758 (adelete 'vhdl-project-alist vhdl-project)
12759 (error ""))
12760 (when not-make-current
12761 (setq vhdl-project current-project))
12762 (vhdl-update-mode-menu)
12763 (vhdl-speedbar-refresh)
12764 (unless not-make-current
12765 (message "Current VHDL project: \"%s\"%s"
12766 vhdl-project (if auto " (auto-loaded)" ""))))
12767 (error (vhdl-warning
12768 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12770 (defun vhdl-duplicate-project ()
12771 "Duplicate setup of current project."
12772 (interactive)
12773 (let ((new-name (read-from-minibuffer "New project name: "))
12774 (project-entry (aget vhdl-project-alist vhdl-project t)))
12775 (setq vhdl-project-alist
12776 (append vhdl-project-alist
12777 (list (cons new-name project-entry))))
12778 (vhdl-update-mode-menu)))
12780 (defun vhdl-auto-load-project ()
12781 "Automatically load project setup at startup."
12782 (let ((file-name-list vhdl-project-file-name)
12783 file-list list-length)
12784 (while file-name-list
12785 (setq file-list
12786 (append file-list
12787 (file-expand-wildcards
12788 (vhdl-resolve-env-variable
12789 (vhdl-replace-string
12790 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12791 (concat "\*" " " (user-login-name)))))))
12792 (setq list-length (or list-length (length file-list)))
12793 (setq file-name-list (cdr file-name-list)))
12794 (while file-list
12795 (vhdl-import-project (expand-file-name (car file-list)) t
12796 (not (> list-length 0)))
12797 (setq list-length (1- list-length))
12798 (setq file-list (cdr file-list)))))
12800 ;; automatically load project setup when idle after startup
12801 (when (memq 'startup vhdl-project-auto-load)
12802 (if noninteractive
12803 (vhdl-auto-load-project)
12804 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12807 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12808 ;;; Hideshow
12809 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12810 ;; (using `hideshow.el')
12812 (defconst vhdl-hs-start-regexp
12813 (concat
12814 "\\(^\\)\\s-*\\("
12815 ;; generic/port clause
12816 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
12817 ;; component
12818 "component\\>\\|"
12819 ;; component instantiation
12820 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
12821 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
12822 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
12823 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
12824 ;; subprogram
12825 "\\(function\\|procedure\\)\\>\\|"
12826 ;; process, block
12827 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
12828 ;; configuration declaration
12829 "configuration\\>"
12830 "\\)")
12831 "Regexp to match start of construct to hide.")
12833 (defun vhdl-hs-forward-sexp-func (count)
12834 "Find end of construct to hide (for hideshow). Only searches forward."
12835 (let ((pos (point)))
12836 (vhdl-prepare-search-2
12837 (beginning-of-line)
12838 (cond
12839 ;; generic/port clause
12840 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
12841 (goto-char (match-end 0))
12842 (backward-char)
12843 (forward-sexp))
12844 ;; component declaration
12845 ((looking-at "^\\s-*component\\>")
12846 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12847 ;; component instantiation
12848 ((looking-at
12849 (concat
12850 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
12851 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
12852 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
12853 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
12854 (goto-char (match-end 0))
12855 (backward-char)
12856 (forward-sexp)
12857 (setq pos (point))
12858 (vhdl-forward-syntactic-ws)
12859 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
12860 (goto-char (match-end 0))
12861 (backward-char)
12862 (forward-sexp)
12863 (setq pos (point)))
12864 (goto-char pos))
12865 ;; subprogram declaration/body
12866 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12867 (goto-char (match-end 0))
12868 (vhdl-forward-syntactic-ws)
12869 (when (looking-at "(")
12870 (forward-sexp))
12871 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12872 (vhdl-in-literal)))
12873 ;; subprogram body
12874 (when (match-string 2)
12875 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12876 (backward-word 1)
12877 (vhdl-forward-sexp)))
12878 ;; block (recursive)
12879 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12880 (goto-char (match-end 0))
12881 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12882 (match-beginning 2))
12883 (vhdl-hs-forward-sexp-func count)))
12884 ;; process
12885 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12886 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12887 ;; configuration declaration
12888 ((looking-at "^\\s-*configuration\\>")
12889 (forward-word 4)
12890 (vhdl-forward-sexp))
12891 (t (goto-char pos))))))
12893 (defun vhdl-hideshow-init ()
12894 "Initialize `hideshow'."
12895 (when vhdl-hideshow-menu
12896 (vhdl-hs-minor-mode 1)))
12898 (defun vhdl-hs-minor-mode (&optional arg)
12899 "Toggle hideshow minor mode and update menu bar."
12900 (interactive "P")
12901 (require 'hideshow)
12902 ;; check for hideshow version 5.x
12903 (if (not (boundp 'hs-block-start-mdata-select))
12904 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12905 ;; initialize hideshow
12906 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12907 (setq hs-special-modes-alist
12908 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12909 'vhdl-hs-forward-sexp-func nil)
12910 hs-special-modes-alist)))
12911 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
12912 (if vhdl-hide-all-init
12913 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
12914 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
12915 (hs-minor-mode arg)
12916 (force-mode-line-update))) ; hack to update menu bar
12919 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12920 ;;; Font locking
12921 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12922 ;; (using `font-lock.el')
12924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12925 ;; Help functions
12927 (defun vhdl-within-translate-off ()
12928 "Return point if within translate-off region, else nil."
12929 (and (save-excursion
12930 (re-search-backward
12931 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12932 (equal "off" (match-string 1))
12933 (point)))
12935 (defun vhdl-start-translate-off (limit)
12936 "Return point before translate-off pragma if before LIMIT, else nil."
12937 (when (re-search-forward
12938 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12939 (match-beginning 0)))
12941 (defun vhdl-end-translate-off (limit)
12942 "Return point after translate-on pragma if before LIMIT, else nil."
12943 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12945 (defun vhdl-match-translate-off (limit)
12946 "Match a translate-off block, setting match-data and returning t, else nil."
12947 (when (< (point) limit)
12948 (let ((start (or (vhdl-within-translate-off)
12949 (vhdl-start-translate-off limit)))
12950 (case-fold-search t))
12951 (when start
12952 (let ((end (or (vhdl-end-translate-off limit) limit)))
12953 (set-match-data (list start end))
12954 (goto-char end))))))
12956 (defun vhdl-font-lock-match-item (limit)
12957 "Match, and move over, any declaration item after point. Adapted from
12958 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12959 (condition-case nil
12960 (save-restriction
12961 (narrow-to-region (point-min) limit)
12962 ;; match item
12963 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12964 (save-match-data
12965 (goto-char (match-end 1))
12966 ;; move to next item
12967 (if (looking-at "\\(\\s-*,\\)")
12968 (goto-char (match-end 1))
12969 (end-of-line) t))))
12970 (error t)))
12972 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12973 ;; Syntax definitions
12975 (defconst vhdl-font-lock-syntactic-keywords
12976 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12977 "Mark single quotes as having string quote syntax in 'c' instances.")
12979 (defvar vhdl-font-lock-keywords nil
12980 "Regular expressions to highlight in VHDL Mode.")
12982 (defvar vhdl-font-lock-keywords-0
12983 ;; set in `vhdl-font-lock-init' because dependent on user options
12984 "For consideration as a value of `vhdl-font-lock-keywords'.
12985 This does highlighting of template prompts and directives (pragmas).")
12987 (defvar vhdl-font-lock-keywords-1 nil
12988 ;; set in `vhdl-font-lock-init' because dependent on user options
12989 "For consideration as a value of `vhdl-font-lock-keywords'.
12990 This does highlighting of keywords and standard identifiers.")
12992 (defconst vhdl-font-lock-keywords-2
12993 (list
12994 ;; highlight names of units, subprograms, and components when declared
12995 (list
12996 (concat
12997 "^\\s-*\\("
12998 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12999 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13000 "\\)\\s-+\\(\\w+\\)")
13001 5 'font-lock-function-name-face)
13003 ;; highlight entity names of architectures and configurations
13004 (list
13005 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13006 2 'font-lock-function-name-face)
13008 ;; highlight labels of common constructs
13009 (list
13010 (concat
13011 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13012 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13013 "postponed\\|process\\|"
13014 (when (vhdl-standard-p 'ams) "procedural\\|")
13015 "with\\|while"
13016 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13017 1 'font-lock-function-name-face)
13019 ;; highlight label and component name of component instantiations
13020 (list
13021 (concat
13022 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13023 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13024 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
13026 ;; highlight label and instantiated unit of component instantiations
13027 (list
13028 (concat
13029 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13030 "\\(component\\|configuration\\|entity\\)\\s-+"
13031 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13032 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
13033 '(5 font-lock-function-name-face nil t)
13034 '(7 font-lock-function-name-face nil t))
13036 ;; highlight names and labels at end of constructs
13037 (list
13038 (concat
13039 "^\\s-*end\\s-+\\(\\("
13040 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
13041 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
13042 "procedure\\|\\(postponed\\s-+\\)?process\\|"
13043 (when (vhdl-standard-p 'ams) "procedural\\|")
13044 "units"
13045 "\\)\\s-+\\)?\\(\\w*\\)")
13046 5 'font-lock-function-name-face)
13048 ;; highlight labels in exit and next statements
13049 (list
13050 (concat
13051 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13052 3 'font-lock-function-name-face)
13054 ;; highlight entity name in attribute specifications
13055 (list
13056 (concat
13057 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13058 1 'font-lock-function-name-face)
13060 ;; highlight labels in block and component specifications
13061 (list
13062 (concat
13063 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13064 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13065 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
13067 ;; highlight names in library clauses
13068 (list "^\\s-*library\\>"
13069 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
13071 ;; highlight names in use clauses
13072 (list
13073 (concat
13074 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13075 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13076 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
13077 '(7 font-lock-function-name-face nil t))
13079 ;; highlight attribute name in attribute declarations/specifications
13080 (list
13081 (concat
13082 "^\\s-*attribute\\s-+\\(\\w+\\)")
13083 1 'vhdl-font-lock-attribute-face)
13085 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13086 (list
13087 (concat
13088 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13089 5 'font-lock-type-face)
13091 ;; highlight signal/variable/constant declaration names
13092 (list "\\(:[^=]\\)"
13093 '(vhdl-font-lock-match-item
13094 (progn (goto-char (match-beginning 1))
13095 (skip-syntax-backward " ")
13096 (skip-syntax-backward "w_")
13097 (skip-syntax-backward " ")
13098 (while (= (preceding-char) ?,)
13099 (backward-char 1)
13100 (skip-syntax-backward " ")
13101 (skip-syntax-backward "w_")
13102 (skip-syntax-backward " ")))
13103 ; (skip-chars-backward "^-(\n\";")
13104 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13106 ;; highlight formal parameters in component instantiations and subprogram
13107 ;; calls
13108 (list "\\(=>\\)"
13109 '(vhdl-font-lock-match-item
13110 (progn (goto-char (match-beginning 1))
13111 (skip-syntax-backward " ")
13112 (while (= (preceding-char) ?\)) (backward-sexp))
13113 (skip-syntax-backward "w_")
13114 (skip-syntax-backward " ")
13115 (when (memq (preceding-char) '(?n ?N ?|))
13116 (goto-char (point-max))))
13117 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
13119 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13120 ;; variables
13121 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13122 '(vhdl-font-lock-match-item
13123 (progn (goto-char (match-end 1)) (match-beginning 2))
13124 nil (1 font-lock-variable-name-face)))
13126 "For consideration as a value of `vhdl-font-lock-keywords'.
13127 This does context sensitive highlighting of names and labels.")
13129 (defvar vhdl-font-lock-keywords-3 nil
13130 ;; set in `vhdl-font-lock-init' because dependent on user options
13131 "For consideration as a value of `vhdl-font-lock-keywords'.
13132 This does highlighting of words with special syntax.")
13134 (defvar vhdl-font-lock-keywords-4 nil
13135 ;; set in `vhdl-font-lock-init' because dependent on user options
13136 "For consideration as a value of `vhdl-font-lock-keywords'.
13137 This does highlighting of additional reserved words.")
13139 (defconst vhdl-font-lock-keywords-5
13140 ;; background highlight translate-off regions
13141 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
13142 "For consideration as a value of `vhdl-font-lock-keywords'.
13143 This does background highlighting of translate-off regions.")
13145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13146 ;; Font and color definitions
13148 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
13149 "Face name to use for prompts.")
13151 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
13152 "Face name to use for standardized attributes.")
13154 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
13155 "Face name to use for standardized enumeration values.")
13157 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
13158 "Face name to use for standardized functions and packages.")
13160 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
13161 "Face name to use for directives.")
13163 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
13164 "Face name to use for additional reserved words.")
13166 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
13167 "Face name to use for translate-off regions.")
13169 ;; face names to use for words with special syntax.
13170 (let ((syntax-alist vhdl-special-syntax-alist)
13171 name)
13172 (while syntax-alist
13173 (setq name (vhdl-function-name
13174 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
13175 (eval `(defvar ,name ',name
13176 ,(concat "Face name to use for "
13177 (nth 0 (car syntax-alist)) ".")))
13178 (setq syntax-alist (cdr syntax-alist))))
13180 (defgroup vhdl-highlight-faces nil
13181 "Faces for highlighting."
13182 :group 'vhdl-highlight)
13184 ;; add faces used from `font-lock'
13185 (custom-add-to-group
13186 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
13187 (custom-add-to-group
13188 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
13189 (custom-add-to-group
13190 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
13191 (custom-add-to-group
13192 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
13193 (custom-add-to-group
13194 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
13195 (custom-add-to-group
13196 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
13198 (defface vhdl-font-lock-prompt-face
13199 '((((min-colors 88) (class color) (background light))
13200 (:foreground "Red1" :bold t))
13201 (((class color) (background light)) (:foreground "Red" :bold t))
13202 (((class color) (background dark)) (:foreground "Pink" :bold t))
13203 (t (:inverse-video t)))
13204 "Font lock mode face used to highlight prompts."
13205 :group 'vhdl-highlight-faces)
13207 (defface vhdl-font-lock-attribute-face
13208 '((((class color) (background light)) (:foreground "Orchid"))
13209 (((class color) (background dark)) (:foreground "LightSteelBlue"))
13210 (t (:italic t :bold t)))
13211 "Font lock mode face used to highlight standardized attributes."
13212 :group 'vhdl-highlight-faces)
13214 (defface vhdl-font-lock-enumvalue-face
13215 '((((class color) (background light)) (:foreground "SaddleBrown"))
13216 (((class color) (background dark)) (:foreground "BurlyWood"))
13217 (t (:italic t :bold t)))
13218 "Font lock mode face used to highlight standardized enumeration values."
13219 :group 'vhdl-highlight-faces)
13221 (defface vhdl-font-lock-function-face
13222 '((((class color) (background light)) (:foreground "Cyan4"))
13223 (((class color) (background dark)) (:foreground "Orchid1"))
13224 (t (:italic t :bold t)))
13225 "Font lock mode face used to highlight standardized functions and packages."
13226 :group 'vhdl-highlight-faces)
13228 (defface vhdl-font-lock-directive-face
13229 '((((class color) (background light)) (:foreground "CadetBlue"))
13230 (((class color) (background dark)) (:foreground "Aquamarine"))
13231 (t (:italic t :bold t)))
13232 "Font lock mode face used to highlight directives."
13233 :group 'vhdl-highlight-faces)
13235 (defface vhdl-font-lock-reserved-words-face
13236 '((((class color) (background light)) (:foreground "Orange" :bold t))
13237 (((min-colors 88) (class color) (background dark))
13238 (:foreground "Yellow1" :bold t))
13239 (((class color) (background dark)) (:foreground "Yellow" :bold t))
13240 (t ()))
13241 "Font lock mode face used to highlight additional reserved words."
13242 :group 'vhdl-highlight-faces)
13244 (defface vhdl-font-lock-translate-off-face
13245 '((((class color) (background light)) (:background "LightGray"))
13246 (((class color) (background dark)) (:background "DimGray"))
13247 (t ()))
13248 "Font lock mode face used to background highlight translate-off regions."
13249 :group 'vhdl-highlight-faces)
13251 ;; font lock mode faces used to highlight words with special syntax.
13252 (let ((syntax-alist vhdl-special-syntax-alist))
13253 (while syntax-alist
13254 (eval `(defface ,(vhdl-function-name
13255 "vhdl-font-lock" (caar syntax-alist) "face")
13256 '((((class color) (background light))
13257 (:foreground ,(nth 2 (car syntax-alist))))
13258 (((class color) (background dark))
13259 (:foreground ,(nth 3 (car syntax-alist))))
13260 (t ()))
13261 ,(concat "Font lock mode face used to highlight "
13262 (nth 0 (car syntax-alist)) ".")
13263 :group 'vhdl-highlight-faces))
13264 (setq syntax-alist (cdr syntax-alist))))
13266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13267 ;; Font lock initialization
13269 (defun vhdl-font-lock-init ()
13270 "Initialize fontification."
13271 ;; highlight template prompts and directives
13272 (setq vhdl-font-lock-keywords-0
13273 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13274 vhdl-template-prompt-syntax ">\\)")
13275 2 'vhdl-font-lock-prompt-face t)
13276 (list (concat "--\\s-*"
13277 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
13278 2 'vhdl-font-lock-directive-face t)
13279 ;; highlight c-preprocessor directives
13280 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13281 '(1 font-lock-builtin-face)
13282 '(3 font-lock-variable-name-face nil t))))
13283 ;; highlight keywords and standardized types, attributes, enumeration
13284 ;; values, and subprograms
13285 (setq vhdl-font-lock-keywords-1
13286 (list
13287 (list (concat "'" vhdl-attributes-regexp)
13288 1 'vhdl-font-lock-attribute-face)
13289 (list vhdl-types-regexp 1 'font-lock-type-face)
13290 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
13291 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
13292 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
13293 (list vhdl-constants-regexp 1 'font-lock-constant-face)
13294 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
13295 ;; highlight words with special syntax.
13296 (setq vhdl-font-lock-keywords-3
13297 (let ((syntax-alist vhdl-special-syntax-alist)
13298 keywords)
13299 (while syntax-alist
13300 (setq keywords
13301 (cons
13302 (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
13303 (vhdl-function-name
13304 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
13305 (nth 4 (car syntax-alist)))
13306 keywords))
13307 (setq syntax-alist (cdr syntax-alist)))
13308 keywords))
13309 ;; highlight additional reserved words
13310 (setq vhdl-font-lock-keywords-4
13311 (list (list vhdl-reserved-words-regexp 1
13312 'vhdl-font-lock-reserved-words-face)))
13313 ;; highlight everything together
13314 (setq vhdl-font-lock-keywords
13315 (append
13316 vhdl-font-lock-keywords-0
13317 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
13318 (when (or vhdl-highlight-forbidden-words
13319 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
13320 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
13321 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
13322 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
13324 ;; initialize fontification for VHDL Mode
13325 (vhdl-font-lock-init)
13327 (defun vhdl-fontify-buffer ()
13328 "Re-initialize fontification and fontify buffer."
13329 (interactive)
13330 (setq font-lock-defaults
13331 `(vhdl-font-lock-keywords
13332 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
13333 beginning-of-line))
13334 (when (fboundp 'font-lock-unset-defaults)
13335 (font-lock-unset-defaults)) ; not implemented in XEmacs
13336 (font-lock-set-defaults)
13337 (font-lock-mode nil)
13338 (font-lock-mode t))
13340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13341 ;; Initialization for PostScript printing
13343 (defun vhdl-ps-print-settings ()
13344 "Initialize custom face and page settings for PostScript printing."
13345 ;; define custom face settings
13346 (unless (or (not vhdl-print-customize-faces)
13347 ps-print-color-p)
13348 (set (make-local-variable 'ps-bold-faces)
13349 '(font-lock-keyword-face
13350 font-lock-type-face
13351 vhdl-font-lock-attribute-face
13352 vhdl-font-lock-enumvalue-face
13353 vhdl-font-lock-directive-face))
13354 (set (make-local-variable 'ps-italic-faces)
13355 '(font-lock-comment-face
13356 font-lock-function-name-face
13357 font-lock-type-face
13358 vhdl-font-lock-attribute-face
13359 vhdl-font-lock-enumvalue-face
13360 vhdl-font-lock-directive-face))
13361 (set (make-local-variable 'ps-underlined-faces)
13362 '(font-lock-string-face))
13363 (setq ps-always-build-face-reference t))
13364 ;; define page settings, so that a line containing 79 characters (default)
13365 ;; fits into one column
13366 (when vhdl-print-two-column
13367 (set (make-local-variable 'ps-landscape-mode) t)
13368 (set (make-local-variable 'ps-number-of-columns) 2)
13369 (set (make-local-variable 'ps-font-size) 7.0)
13370 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13371 (set (make-local-variable 'ps-header-font-size) 9.0)
13372 (set (make-local-variable 'ps-header-offset) 12.0)
13373 (when (eq ps-paper-type 'letter)
13374 (set (make-local-variable 'ps-inter-column) 40.0)
13375 (set (make-local-variable 'ps-left-margin) 40.0)
13376 (set (make-local-variable 'ps-right-margin) 40.0))))
13378 (defun vhdl-ps-print-init ()
13379 "Initialize PostScript printing."
13380 (if (featurep 'xemacs)
13381 (when (boundp 'ps-print-color-p)
13382 (vhdl-ps-print-settings))
13383 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
13384 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
13387 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13388 ;;; Hierarchy browser (using `speedbar.el')
13389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13390 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13391 ;; directory by using the speedbar.
13393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13394 ;; Variables
13396 (defvar vhdl-entity-alist nil
13397 "Cache with entities and corresponding architectures for each
13398 project/directory.")
13399 ;; structure: (parenthesized expression means list of such entries)
13400 ;; (cache-key
13401 ;; (ent-key ent-name ent-file ent-line
13402 ;; (arch-key arch-name arch-file arch-line
13403 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13404 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13405 ;; (lib-name pack-key))
13406 ;; mra-key (lib-name pack-key))
13408 (defvar vhdl-config-alist nil
13409 "Cache with configurations for each project/directory.")
13410 ;; structure: (parenthesized expression means list of such entries)
13411 ;; (cache-key
13412 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13413 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13414 ;; inst-conf-key inst-lib-key)
13415 ;; (lib-name pack-key)))
13417 (defvar vhdl-package-alist nil
13418 "Cache with packages for each project/directory.")
13419 ;; structure: (parenthesized expression means list of such entries)
13420 ;; (cache-key
13421 ;; (pack-key pack-name pack-file pack-line
13422 ;; (comp-key comp-name comp-file comp-line)
13423 ;; (func-key func-name func-file func-line)
13424 ;; (lib-name pack-key)
13425 ;; pack-body-file pack-body-line
13426 ;; (func-key func-name func-body-file func-body-line)
13427 ;; (lib-name pack-key)))
13429 (defvar vhdl-ent-inst-alist nil
13430 "Cache with instantiated entities for each project/directory.")
13431 ;; structure: (parenthesized expression means list of such entries)
13432 ;; (cache-key (inst-ent-key))
13434 (defvar vhdl-file-alist nil
13435 "Cache with design units in each file for each project/directory.")
13436 ;; structure: (parenthesized expression means list of such entries)
13437 ;; (cache-key
13438 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13439 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13441 (defvar vhdl-directory-alist nil
13442 "Cache with source directories for each project.")
13443 ;; structure: (parenthesized expression means list of such entries)
13444 ;; (cache-key (directory))
13446 (defvar vhdl-speedbar-shown-unit-alist nil
13447 "Alist of design units simultaneously open in the current speedbar for each
13448 directory and project.")
13450 (defvar vhdl-speedbar-shown-project-list nil
13451 "List of projects simultaneously open in the current speedbar.")
13453 (defvar vhdl-updated-project-list nil
13454 "List of projects and directories with updated files.")
13456 (defvar vhdl-modified-file-list nil
13457 "List of modified files to be rescanned for hierarchy updating.")
13459 (defvar vhdl-speedbar-hierarchy-depth 0
13460 "Depth of instantiation hierarchy to display.")
13462 (defvar vhdl-speedbar-show-projects nil
13463 "Non-nil means project hierarchy is displayed in speedbar, directory
13464 hierarchy otherwise.")
13466 (defun vhdl-get-end-of-unit ()
13467 "Return position of end of current unit."
13468 (let ((pos (point)))
13469 (save-excursion
13470 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13471 (save-excursion
13472 (goto-char (match-beginning 0))
13473 (vhdl-backward-syntactic-ws)
13474 (and (/= (preceding-char) ?\;) (not (bobp))))))
13475 (re-search-backward "^[ \t]*end\\>" pos 1)
13476 (point))))
13478 (defun vhdl-match-string-downcase (num &optional string)
13479 "Like `match-string-no-properties' with down-casing."
13480 (let ((match (match-string-no-properties num string)))
13481 (and match (downcase match))))
13484 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13485 ;; Scan functions
13487 (defun vhdl-scan-context-clause ()
13488 "Scan the context clause that precedes a design unit."
13489 (let (lib-alist)
13490 (save-excursion
13491 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13492 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13493 (equal "USE" (upcase (match-string 1))))
13494 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13495 (setq lib-alist (cons (cons (match-string-no-properties 1)
13496 (vhdl-match-string-downcase 2))
13497 lib-alist))))))
13498 lib-alist))
13500 (defun vhdl-scan-directory-contents (name &optional project update num-string
13501 non-final)
13502 "Scan contents of VHDL files in directory or file pattern NAME."
13503 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
13504 ; (unless (file-directory-p (match-string 1 name))
13505 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13506 (let* ((dir-name (match-string 1 name))
13507 (file-pattern (match-string 2 name))
13508 (is-directory (= 0 (length file-pattern)))
13509 (file-list
13510 (if update
13511 (list name)
13512 (if is-directory
13513 (vhdl-get-source-files t dir-name)
13514 (vhdl-directory-files
13515 dir-name t (wildcard-to-regexp file-pattern)))))
13516 (key (or project dir-name))
13517 (file-exclude-regexp
13518 (or (nth 3 (aget vhdl-project-alist project)) ""))
13519 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13520 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13521 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13522 ent-alist conf-alist pack-alist ent-inst-list file-alist
13523 tmp-list tmp-entry no-files files-exist big-files)
13524 (when (or project update)
13525 (setq ent-alist (aget vhdl-entity-alist key t)
13526 conf-alist (aget vhdl-config-alist key t)
13527 pack-alist (aget vhdl-package-alist key t)
13528 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13529 file-alist (aget vhdl-file-alist key t)))
13530 (when (and (not is-directory) (null file-list))
13531 (message "No such file: \"%s\"" name))
13532 (setq files-exist file-list)
13533 (when file-list
13534 (setq no-files (length file-list))
13535 (message "Scanning %s %s\"%s\"..."
13536 (if is-directory "directory" "files") (or num-string "") name)
13537 ;; exclude files
13538 (unless (equal file-exclude-regexp "")
13539 (let ((case-fold-search nil)
13540 file-tmp-list)
13541 (while file-list
13542 (unless (string-match file-exclude-regexp (car file-list))
13543 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13544 (setq file-list (cdr file-list)))
13545 (setq file-list (nreverse file-tmp-list))))
13546 ;; do for all files
13547 (while file-list
13548 (unless noninteractive
13549 (message "Scanning %s %s\"%s\"... (%2d%s)"
13550 (if is-directory "directory" "files")
13551 (or num-string "") name
13552 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13553 (let ((file-name (abbreviate-file-name (car file-list)))
13554 ent-list arch-list arch-ent-list conf-list
13555 pack-list pack-body-list inst-list inst-ent-list)
13556 ;; scan file
13557 (vhdl-visit-file
13558 file-name nil
13559 (vhdl-prepare-search-2
13560 (save-excursion
13561 ;; scan for design units
13562 (if (and limit-design-file-size
13563 (< limit-design-file-size (buffer-size)))
13564 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13565 (setq big-files t))
13566 ;; scan for entities
13567 (goto-char (point-min))
13568 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13569 (let* ((ent-name (match-string-no-properties 1))
13570 (ent-key (downcase ent-name))
13571 (ent-entry (aget ent-alist ent-key t))
13572 (lib-alist (vhdl-scan-context-clause)))
13573 (if (nth 1 ent-entry)
13574 (vhdl-warning-when-idle
13575 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13576 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13577 file-name (vhdl-current-line))
13578 (setq ent-list (cons ent-key ent-list))
13579 (aput 'ent-alist ent-key
13580 (list ent-name file-name (vhdl-current-line)
13581 (nth 3 ent-entry) (nth 4 ent-entry)
13582 lib-alist)))))
13583 ;; scan for architectures
13584 (goto-char (point-min))
13585 (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)
13586 (let* ((arch-name (match-string-no-properties 1))
13587 (arch-key (downcase arch-name))
13588 (ent-name (match-string-no-properties 2))
13589 (ent-key (downcase ent-name))
13590 (ent-entry (aget ent-alist ent-key t))
13591 (arch-alist (nth 3 ent-entry))
13592 (arch-entry (aget arch-alist arch-key t))
13593 (lib-arch-alist (vhdl-scan-context-clause)))
13594 (if arch-entry
13595 (vhdl-warning-when-idle
13596 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13597 arch-name ent-name (nth 1 arch-entry)
13598 (nth 2 arch-entry) file-name (vhdl-current-line))
13599 (setq arch-list (cons arch-key arch-list)
13600 arch-ent-list (cons ent-key arch-ent-list))
13601 (aput 'arch-alist arch-key
13602 (list arch-name file-name (vhdl-current-line) nil
13603 lib-arch-alist))
13604 (aput 'ent-alist ent-key
13605 (list (or (nth 0 ent-entry) ent-name)
13606 (nth 1 ent-entry) (nth 2 ent-entry)
13607 (vhdl-sort-alist arch-alist)
13608 arch-key (nth 5 ent-entry))))))
13609 ;; scan for configurations
13610 (goto-char (point-min))
13611 (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)
13612 (let* ((conf-name (match-string-no-properties 1))
13613 (conf-key (downcase conf-name))
13614 (conf-entry (aget conf-alist conf-key t))
13615 (ent-name (match-string-no-properties 2))
13616 (ent-key (downcase ent-name))
13617 (lib-alist (vhdl-scan-context-clause))
13618 (conf-line (vhdl-current-line))
13619 (end-of-unit (vhdl-get-end-of-unit))
13620 arch-key comp-conf-list inst-key-list
13621 inst-comp-key inst-ent-key inst-arch-key
13622 inst-conf-key inst-lib-key)
13623 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13624 (setq arch-key (vhdl-match-string-downcase 1)))
13625 (if conf-entry
13626 (vhdl-warning-when-idle
13627 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13628 conf-name ent-name (nth 1 conf-entry)
13629 (nth 2 conf-entry) file-name conf-line)
13630 (setq conf-list (cons conf-key conf-list))
13631 ;; scan for subconfigurations and subentities
13632 (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)
13633 (setq inst-comp-key (vhdl-match-string-downcase 3)
13634 inst-key-list (split-string
13635 (vhdl-match-string-downcase 1)
13636 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13637 (vhdl-forward-syntactic-ws)
13638 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13639 (setq
13640 inst-lib-key (vhdl-match-string-downcase 3)
13641 inst-ent-key (and (match-string 2)
13642 (vhdl-match-string-downcase 4))
13643 inst-arch-key (and (match-string 2)
13644 (vhdl-match-string-downcase 6))
13645 inst-conf-key (and (not (match-string 2))
13646 (vhdl-match-string-downcase 4)))
13647 (while inst-key-list
13648 (setq comp-conf-list
13649 (cons (list (car inst-key-list)
13650 inst-comp-key inst-ent-key
13651 inst-arch-key inst-conf-key
13652 inst-lib-key)
13653 comp-conf-list))
13654 (setq inst-key-list (cdr inst-key-list)))))
13655 (aput 'conf-alist conf-key
13656 (list conf-name file-name conf-line ent-key
13657 arch-key comp-conf-list lib-alist)))))
13658 ;; scan for packages
13659 (goto-char (point-min))
13660 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
13661 (let* ((pack-name (match-string-no-properties 2))
13662 (pack-key (downcase pack-name))
13663 (is-body (match-string-no-properties 1))
13664 (pack-entry (aget pack-alist pack-key t))
13665 (pack-line (vhdl-current-line))
13666 (end-of-unit (vhdl-get-end-of-unit))
13667 comp-name func-name comp-alist func-alist lib-alist)
13668 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13669 (vhdl-warning-when-idle
13670 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13671 (if is-body " body" "") pack-name
13672 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13673 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13674 file-name (vhdl-current-line))
13675 ;; scan for context clauses
13676 (setq lib-alist (vhdl-scan-context-clause))
13677 ;; scan for component and subprogram declarations/bodies
13678 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13679 (if (equal (upcase (match-string 1)) "COMPONENT")
13680 (setq comp-name (match-string-no-properties 2)
13681 comp-alist
13682 (cons (list (downcase comp-name) comp-name
13683 file-name (vhdl-current-line))
13684 comp-alist))
13685 (setq func-name (match-string-no-properties 2)
13686 func-alist
13687 (cons (list (downcase func-name) func-name
13688 file-name (vhdl-current-line))
13689 func-alist))))
13690 (setq func-alist (nreverse func-alist))
13691 (setq comp-alist (nreverse comp-alist))
13692 (if is-body
13693 (setq pack-body-list (cons pack-key pack-body-list))
13694 (setq pack-list (cons pack-key pack-list)))
13695 (aput
13696 'pack-alist pack-key
13697 (if is-body
13698 (list (or (nth 0 pack-entry) pack-name)
13699 (nth 1 pack-entry) (nth 2 pack-entry)
13700 (nth 3 pack-entry) (nth 4 pack-entry)
13701 (nth 5 pack-entry)
13702 file-name pack-line func-alist lib-alist)
13703 (list pack-name file-name pack-line
13704 comp-alist func-alist lib-alist
13705 (nth 6 pack-entry) (nth 7 pack-entry)
13706 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13707 ;; scan for hierarchy
13708 (if (and limit-hier-file-size
13709 (< limit-hier-file-size (buffer-size)))
13710 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13711 (setq big-files t))
13712 ;; scan for architectures
13713 (goto-char (point-min))
13714 (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)
13715 (let* ((ent-name (match-string-no-properties 2))
13716 (ent-key (downcase ent-name))
13717 (arch-name (match-string-no-properties 1))
13718 (arch-key (downcase arch-name))
13719 (ent-entry (aget ent-alist ent-key t))
13720 (arch-alist (nth 3 ent-entry))
13721 (arch-entry (aget arch-alist arch-key t))
13722 (beg-of-unit (point))
13723 (end-of-unit (vhdl-get-end-of-unit))
13724 (inst-no 0)
13725 inst-alist inst-path)
13726 ;; scan for contained instantiations
13727 (while (and (re-search-forward
13728 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
13729 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
13730 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
13731 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
13732 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13733 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
13734 (or (not limit-hier-inst-no)
13735 (<= (setq inst-no (1+ inst-no))
13736 limit-hier-inst-no)))
13737 (cond
13738 ;; block/generate beginning found
13739 ((match-string 14)
13740 (setq inst-path
13741 (cons (match-string-no-properties 1) inst-path)))
13742 ;; block/generate end found
13743 ((match-string 16)
13744 (setq inst-path (cdr inst-path)))
13745 ;; instantiation found
13747 (let* ((inst-name (match-string-no-properties 1))
13748 (inst-key (downcase inst-name))
13749 (inst-comp-name
13750 (or (match-string-no-properties 3)
13751 (match-string-no-properties 6)))
13752 (inst-ent-key
13753 (or (and (match-string 8)
13754 (vhdl-match-string-downcase 11))
13755 (and inst-comp-name
13756 (downcase inst-comp-name))))
13757 (inst-arch-key (vhdl-match-string-downcase 13))
13758 (inst-conf-key
13759 (and (not (match-string 8))
13760 (vhdl-match-string-downcase 11)))
13761 (inst-lib-key (vhdl-match-string-downcase 10)))
13762 (goto-char (match-end 1))
13763 (setq inst-list (cons inst-key inst-list)
13764 inst-ent-list
13765 (cons inst-ent-key inst-ent-list))
13766 (setq inst-alist
13767 (append
13768 inst-alist
13769 (list (list inst-key inst-name file-name
13770 (vhdl-current-line) inst-comp-name
13771 inst-ent-key inst-arch-key
13772 inst-conf-key inst-lib-key
13773 (reverse inst-path)))))))))
13774 ;; scan for contained configuration specifications
13775 (goto-char beg-of-unit)
13776 (while (re-search-forward
13777 (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]*\\)*"
13778 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
13779 (let* ((inst-comp-name (match-string-no-properties 3))
13780 (inst-ent-key
13781 (and (match-string 6)
13782 (vhdl-match-string-downcase 9)))
13783 (inst-arch-key (vhdl-match-string-downcase 11))
13784 (inst-conf-key
13785 (and (not (match-string 6))
13786 (vhdl-match-string-downcase 9)))
13787 (inst-lib-key (vhdl-match-string-downcase 8))
13788 (inst-key-list
13789 (split-string (vhdl-match-string-downcase 1)
13790 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13791 (tmp-inst-alist inst-alist)
13792 inst-entry)
13793 (while tmp-inst-alist
13794 (when (and (or (equal "all" (car inst-key-list))
13795 (member (nth 0 (car tmp-inst-alist))
13796 inst-key-list))
13797 (equal
13798 (downcase
13799 (or (nth 4 (car tmp-inst-alist)) ""))
13800 (downcase inst-comp-name)))
13801 (setq inst-entry (car tmp-inst-alist))
13802 (setq inst-ent-list
13803 (cons (or inst-ent-key (nth 5 inst-entry))
13804 (vhdl-delete
13805 (nth 5 inst-entry) inst-ent-list)))
13806 (setq inst-entry
13807 (list (nth 0 inst-entry) (nth 1 inst-entry)
13808 (nth 2 inst-entry) (nth 3 inst-entry)
13809 (nth 4 inst-entry)
13810 (or inst-ent-key (nth 5 inst-entry))
13811 (or inst-arch-key (nth 6 inst-entry))
13812 inst-conf-key inst-lib-key))
13813 (setcar tmp-inst-alist inst-entry))
13814 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13815 ;; save in cache
13816 (aput 'arch-alist arch-key
13817 (list (nth 0 arch-entry) (nth 1 arch-entry)
13818 (nth 2 arch-entry) inst-alist
13819 (nth 4 arch-entry)))
13820 (aput 'ent-alist ent-key
13821 (list (nth 0 ent-entry) (nth 1 ent-entry)
13822 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13823 (nth 4 ent-entry) (nth 5 ent-entry)))
13824 (when (and limit-hier-inst-no
13825 (> inst-no limit-hier-inst-no))
13826 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13827 (setq big-files t))
13828 (goto-char end-of-unit))))
13829 ;; remember design units for this file
13830 (aput 'file-alist file-name
13831 (list ent-list arch-list arch-ent-list conf-list
13832 pack-list pack-body-list inst-list inst-ent-list))
13833 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13834 (setq file-list (cdr file-list))))
13835 (when (or (and (not project) files-exist)
13836 (and project (not non-final)))
13837 ;; consistency checks:
13838 ;; check whether each architecture has a corresponding entity
13839 (setq tmp-list ent-alist)
13840 (while tmp-list
13841 (when (null (nth 2 (car tmp-list)))
13842 (setq tmp-entry (car (nth 4 (car tmp-list))))
13843 (vhdl-warning-when-idle
13844 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13845 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13846 (nth 3 tmp-entry)))
13847 (setq tmp-list (cdr tmp-list)))
13848 ;; check whether configuration has a corresponding entity/architecture
13849 (setq tmp-list conf-alist)
13850 (while tmp-list
13851 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13852 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13853 (setq tmp-entry (car tmp-list))
13854 (vhdl-warning-when-idle
13855 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13856 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13857 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13858 (setq tmp-entry (car tmp-list))
13859 (vhdl-warning-when-idle
13860 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13861 (nth 1 tmp-entry) (nth 4 tmp-entry)
13862 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13863 (setq tmp-list (cdr tmp-list)))
13864 ;; check whether each package body has a package declaration
13865 (setq tmp-list pack-alist)
13866 (while tmp-list
13867 (when (null (nth 2 (car tmp-list)))
13868 (setq tmp-entry (car tmp-list))
13869 (vhdl-warning-when-idle
13870 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13871 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13872 (setq tmp-list (cdr tmp-list)))
13873 ;; sort lists
13874 (setq ent-alist (vhdl-sort-alist ent-alist))
13875 (setq conf-alist (vhdl-sort-alist conf-alist))
13876 (setq pack-alist (vhdl-sort-alist pack-alist))
13877 ;; remember updated directory/project
13878 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13879 ;; clear directory alists
13880 (unless project
13881 (adelete 'vhdl-entity-alist key)
13882 (adelete 'vhdl-config-alist key)
13883 (adelete 'vhdl-package-alist key)
13884 (adelete 'vhdl-ent-inst-alist key)
13885 (adelete 'vhdl-file-alist key))
13886 ;; put directory contents into cache
13887 (aput 'vhdl-entity-alist key ent-alist)
13888 (aput 'vhdl-config-alist key conf-alist)
13889 (aput 'vhdl-package-alist key pack-alist)
13890 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13891 (aput 'vhdl-file-alist key file-alist)
13892 ;; final messages
13893 (message "Scanning %s %s\"%s\"...done"
13894 (if is-directory "directory" "files") (or num-string "") name)
13895 (unless project (message "Scanning directory...done"))
13896 (when big-files
13897 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13898 ;; save cache when scanned non-interactively
13899 (when (or (not project) (not non-final))
13900 (when (and noninteractive vhdl-speedbar-save-cache)
13901 (vhdl-save-cache key)))
13904 (defun vhdl-scan-project-contents (project)
13905 "Scan the contents of all VHDL files found in the directories and files
13906 of PROJECT."
13907 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13908 (default-dir (vhdl-resolve-env-variable
13909 (nth 1 (aget vhdl-project-alist project))))
13910 (file-exclude-regexp
13911 (or (nth 3 (aget vhdl-project-alist project)) ""))
13912 dir-list-tmp dir dir-name num-dir act-dir recursive)
13913 ;; clear project alists
13914 (adelete 'vhdl-entity-alist project)
13915 (adelete 'vhdl-config-alist project)
13916 (adelete 'vhdl-package-alist project)
13917 (adelete 'vhdl-ent-inst-alist project)
13918 (adelete 'vhdl-file-alist project)
13919 ;; expand directory names by default-directory
13920 (message "Collecting source files...")
13921 (while dir-list
13922 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13923 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13924 (setq recursive (match-string 1 dir)
13925 dir-name (match-string 3 dir))
13926 (setq dir-list-tmp
13927 (cons (concat recursive
13928 (if (file-name-absolute-p dir-name) "" default-dir)
13929 dir-name)
13930 dir-list-tmp))
13931 (setq dir-list (cdr dir-list)))
13932 ;; resolve path wildcards
13933 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13934 ;; expand directories
13935 (while dir-list-tmp
13936 (setq dir (car dir-list-tmp))
13937 ;; get subdirectories
13938 (if (string-match "-r \\(.*[/\\]\\)" dir)
13939 (setq dir-list (append dir-list (vhdl-get-subdirs
13940 (match-string 1 dir))))
13941 (setq dir-list (append dir-list (list dir))))
13942 (setq dir-list-tmp (cdr dir-list-tmp)))
13943 ;; exclude files
13944 (unless (equal file-exclude-regexp "")
13945 (let ((case-fold-search nil))
13946 (while dir-list
13947 (unless (string-match file-exclude-regexp (car dir-list))
13948 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13949 (setq dir-list (cdr dir-list)))
13950 (setq dir-list (nreverse dir-list-tmp))))
13951 (message "Collecting source files...done")
13952 ;; scan for design units for each directory in DIR-LIST
13953 (setq dir-list-tmp nil
13954 num-dir (length dir-list)
13955 act-dir 1)
13956 (while dir-list
13957 (setq dir-name (abbreviate-file-name
13958 (expand-file-name (car dir-list))))
13959 (vhdl-scan-directory-contents dir-name project nil
13960 (format "(%s/%s) " act-dir num-dir)
13961 (cdr dir-list))
13962 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13963 (setq dir-list (cdr dir-list)
13964 act-dir (1+ act-dir)))
13965 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13966 (message "Scanning project \"%s\"...done" project)))
13968 (defun vhdl-update-file-contents (file-name)
13969 "Update hierarchy information by contents of current buffer."
13970 (setq file-name (abbreviate-file-name file-name))
13971 (let* ((dir-name (file-name-directory file-name))
13972 (directory-alist vhdl-directory-alist)
13973 updated)
13974 (while directory-alist
13975 (when (member dir-name (nth 1 (car directory-alist)))
13976 (let* ((vhdl-project (nth 0 (car directory-alist)))
13977 (project (vhdl-project-p))
13978 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13979 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13980 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13981 (ent-inst-list (car (aget vhdl-ent-inst-alist
13982 (or project dir-name) t)))
13983 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13984 (file-entry (aget file-alist file-name t))
13985 (ent-list (nth 0 file-entry))
13986 (arch-list (nth 1 file-entry))
13987 (arch-ent-list (nth 2 file-entry))
13988 (conf-list (nth 3 file-entry))
13989 (pack-list (nth 4 file-entry))
13990 (pack-body-list (nth 5 file-entry))
13991 (inst-ent-list (nth 7 file-entry))
13992 (cache-key (or project dir-name))
13993 arch-alist key ent-key entry)
13994 ;; delete design units previously contained in this file:
13995 ;; entities
13996 (while ent-list
13997 (setq key (car ent-list)
13998 entry (aget ent-alist key t))
13999 (when (equal file-name (nth 1 entry))
14000 (if (nth 3 entry)
14001 (aput 'ent-alist key
14002 (list (nth 0 entry) nil nil (nth 3 entry) nil))
14003 (adelete 'ent-alist key)))
14004 (setq ent-list (cdr ent-list)))
14005 ;; architectures
14006 (while arch-list
14007 (setq key (car arch-list)
14008 ent-key (car arch-ent-list)
14009 entry (aget ent-alist ent-key t)
14010 arch-alist (nth 3 entry))
14011 (when (equal file-name (nth 1 (aget arch-alist key t)))
14012 (adelete 'arch-alist key)
14013 (if (or (nth 1 entry) arch-alist)
14014 (aput 'ent-alist ent-key
14015 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14016 arch-alist (nth 4 entry) (nth 5 entry)))
14017 (adelete 'ent-alist ent-key)))
14018 (setq arch-list (cdr arch-list)
14019 arch-ent-list (cdr arch-ent-list)))
14020 ;; configurations
14021 (while conf-list
14022 (setq key (car conf-list))
14023 (when (equal file-name (nth 1 (aget conf-alist key t)))
14024 (adelete 'conf-alist key))
14025 (setq conf-list (cdr conf-list)))
14026 ;; package declarations
14027 (while pack-list
14028 (setq key (car pack-list)
14029 entry (aget pack-alist key t))
14030 (when (equal file-name (nth 1 entry))
14031 (if (nth 6 entry)
14032 (aput 'pack-alist key
14033 (list (nth 0 entry) nil nil nil nil nil
14034 (nth 6 entry) (nth 7 entry) (nth 8 entry)
14035 (nth 9 entry)))
14036 (adelete 'pack-alist key)))
14037 (setq pack-list (cdr pack-list)))
14038 ;; package bodies
14039 (while pack-body-list
14040 (setq key (car pack-body-list)
14041 entry (aget pack-alist key t))
14042 (when (equal file-name (nth 6 entry))
14043 (if (nth 1 entry)
14044 (aput 'pack-alist key
14045 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
14046 (nth 3 entry) (nth 4 entry) (nth 5 entry)
14047 nil nil nil nil))
14048 (adelete 'pack-alist key)))
14049 (setq pack-body-list (cdr pack-body-list)))
14050 ;; instantiated entities
14051 (while inst-ent-list
14052 (setq ent-inst-list
14053 (vhdl-delete (car inst-ent-list) ent-inst-list))
14054 (setq inst-ent-list (cdr inst-ent-list)))
14055 ;; update caches
14056 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
14057 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
14058 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
14059 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
14060 ;; scan file
14061 (vhdl-scan-directory-contents file-name project t)
14062 (when (or (and vhdl-speedbar-show-projects project)
14063 (and (not vhdl-speedbar-show-projects) (not project)))
14064 (vhdl-speedbar-refresh project))
14065 (setq updated t)))
14066 (setq directory-alist (cdr directory-alist)))
14067 updated))
14069 (defun vhdl-update-hierarchy ()
14070 "Update directory and hierarchy information in speedbar."
14071 (let ((file-list (reverse vhdl-modified-file-list))
14072 updated)
14073 (when (and vhdl-speedbar-update-on-saving file-list)
14074 (while file-list
14075 (setq updated
14076 (or (vhdl-update-file-contents (car file-list))
14077 updated))
14078 (setq file-list (cdr file-list)))
14079 (setq vhdl-modified-file-list nil)
14080 (vhdl-speedbar-update-current-unit)
14081 (when updated (message "Updating hierarchy...done")))))
14083 ;; structure (parenthesized expression means list of such entries)
14084 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14085 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14086 ;; comp-lib-name level)
14087 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14088 conf-inst-alist level indent
14089 &optional include-top ent-hier)
14090 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14091 entity ENT-KEY."
14092 (let* ((ent-entry (aget ent-alist ent-key t))
14093 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
14094 (cdar (last (nth 3 ent-entry)))))
14095 (inst-alist (nth 3 arch-entry))
14096 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14097 hier-list subcomp-list tmp-list inst-key inst-comp-name
14098 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
14099 (when (= level 0) (message "Extract design hierarchy..."))
14100 (when include-top
14101 (setq level (1+ level)))
14102 (when (member ent-key ent-hier)
14103 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
14104 ;; check configured architecture (already checked during scanning)
14105 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
14106 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
14107 ;; process all instances
14108 (while inst-alist
14109 (setq inst-entry (car inst-alist)
14110 inst-key (nth 0 inst-entry)
14111 inst-comp-name (nth 4 inst-entry)
14112 inst-conf-key (nth 7 inst-entry))
14113 ;; search entry in configuration's instantiations list
14114 (setq tmp-list conf-inst-alist)
14115 (while (and tmp-list
14116 (not (and (member (nth 0 (car tmp-list))
14117 (list "all" inst-key))
14118 (equal (nth 1 (car tmp-list))
14119 (downcase (or inst-comp-name ""))))))
14120 (setq tmp-list (cdr tmp-list)))
14121 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
14122 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
14123 (when (and inst-conf-key (not inst-conf-entry))
14124 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
14125 ;; determine entity
14126 (setq inst-ent-key
14127 (or (nth 2 (car tmp-list)) ; from configuration
14128 (nth 3 inst-conf-entry) ; from subconfiguration
14129 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
14130 ; from configuration spec.
14131 (nth 5 inst-entry))) ; from direct instantiation
14132 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
14133 ;; determine architecture
14134 (setq inst-arch-key
14135 (or (nth 3 (car tmp-list)) ; from configuration
14136 (nth 4 inst-conf-entry) ; from subconfiguration
14137 (nth 6 inst-entry) ; from direct instantiation
14138 (nth 4 (aget conf-alist (nth 7 inst-entry)))
14139 ; from configuration spec.
14140 (nth 4 inst-ent-entry) ; MRA
14141 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
14142 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
14143 ;; set library
14144 (setq inst-lib-key
14145 (or (nth 5 (car tmp-list)) ; from configuration
14146 (nth 8 inst-entry))) ; from direct instantiation
14147 ;; gather information for this instance
14148 (setq comp-entry
14149 (list (nth 1 inst-entry)
14150 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14151 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
14152 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
14153 (or (nth 0 inst-arch-entry) inst-arch-key)
14154 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
14155 (or (nth 0 inst-conf-entry) inst-conf-key)
14156 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
14157 inst-lib-key level))
14158 ;; get subcomponent hierarchy
14159 (setq subcomp-list (vhdl-get-hierarchy
14160 ent-alist conf-alist
14161 inst-ent-key inst-arch-key inst-conf-key
14162 (nth 5 inst-conf-entry)
14163 (1+ level) indent nil (cons ent-key ent-hier)))
14164 ;; add to list
14165 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
14166 (setq inst-alist (cdr inst-alist)))
14167 (when include-top
14168 (setq hier-list
14169 (cons (list nil nil (nth 0 ent-entry)
14170 (cons (nth 1 ent-entry) (nth 2 ent-entry))
14171 (nth 0 arch-entry)
14172 (cons (nth 1 arch-entry) (nth 2 arch-entry))
14173 nil nil
14174 nil (1- level))
14175 hier-list)))
14176 (when (or (= level 0) (and include-top (= level 1))) (message ""))
14177 hier-list))
14179 (defun vhdl-get-instantiations (ent-key indent)
14180 "Get all instantiations of entity ENT-KEY."
14181 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
14182 arch-alist inst-alist ent-inst-list
14183 ent-entry arch-entry inst-entry)
14184 (while ent-alist
14185 (setq ent-entry (car ent-alist))
14186 (setq arch-alist (nth 4 ent-entry))
14187 (while arch-alist
14188 (setq arch-entry (car arch-alist))
14189 (setq inst-alist (nth 4 arch-entry))
14190 (while inst-alist
14191 (setq inst-entry (car inst-alist))
14192 (when (equal ent-key (nth 5 inst-entry))
14193 (setq ent-inst-list
14194 (cons (list (nth 1 inst-entry)
14195 (cons (nth 2 inst-entry) (nth 3 inst-entry))
14196 (nth 1 ent-entry)
14197 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14198 (nth 1 arch-entry)
14199 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
14200 ent-inst-list)))
14201 (setq inst-alist (cdr inst-alist)))
14202 (setq arch-alist (cdr arch-alist)))
14203 (setq ent-alist (cdr ent-alist)))
14204 (nreverse ent-inst-list)))
14206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14207 ;; Caching in file
14209 (defun vhdl-save-caches ()
14210 "Save all updated hierarchy caches to file."
14211 (interactive)
14212 (condition-case nil
14213 (when vhdl-speedbar-save-cache
14214 ;; update hierarchy
14215 (vhdl-update-hierarchy)
14216 (let ((project-list vhdl-updated-project-list))
14217 (message "Saving hierarchy caches...")
14218 ;; write updated project caches
14219 (while project-list
14220 (vhdl-save-cache (car project-list))
14221 (setq project-list (cdr project-list)))
14222 (message "Saving hierarchy caches...done")))
14223 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14224 (sit-for 2)))))
14226 (defun vhdl-save-cache (key)
14227 "Save current hierarchy cache to file."
14228 (let* ((orig-buffer (current-buffer))
14229 (vhdl-project key)
14230 (project (vhdl-project-p))
14231 (default-directory key)
14232 (directory (abbreviate-file-name (vhdl-default-directory)))
14233 (file-name (vhdl-resolve-env-variable
14234 (vhdl-replace-string
14235 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14236 (concat
14237 (subst-char-in-string ? ?_ (or project "dir"))
14238 " " (user-login-name)))))
14239 (file-dir-name (expand-file-name file-name directory))
14240 (cache-key (or project directory))
14241 (key (if project "project" "directory")))
14242 (unless (file-exists-p (file-name-directory file-dir-name))
14243 (make-directory (file-name-directory file-dir-name) t))
14244 (if (not (file-writable-p file-dir-name))
14245 (progn (vhdl-warning (format "File not writable: \"%s\""
14246 (abbreviate-file-name file-dir-name)))
14247 (sit-for 2))
14248 (message "Saving cache: \"%s\"" file-dir-name)
14249 (set-buffer (find-file-noselect file-dir-name t t))
14250 (erase-buffer)
14251 (insert ";; -*- Emacs-Lisp -*-\n\n"
14252 ";;; " (file-name-nondirectory file-name)
14253 " - design hierarchy cache file for Emacs VHDL Mode "
14254 vhdl-version "\n")
14255 (insert "\n;; " (if project "Project " "Directory") " : ")
14256 (if project (insert project) (prin1 directory (current-buffer)))
14257 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14258 (user-login-name) "\n\n"
14259 "\n;; version number\n"
14260 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
14261 "\n;; " (if project "project" "directory") " name"
14262 "\n(setq " key " ")
14263 (prin1 (or project directory) (current-buffer))
14264 (insert ")\n")
14265 (when (member 'hierarchy vhdl-speedbar-save-cache)
14266 (insert "\n;; entity and architecture cache\n"
14267 "(aput 'vhdl-entity-alist " key " '")
14268 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
14269 (insert ")\n\n;; configuration cache\n"
14270 "(aput 'vhdl-config-alist " key " '")
14271 (print (aget vhdl-config-alist cache-key t) (current-buffer))
14272 (insert ")\n\n;; package cache\n"
14273 "(aput 'vhdl-package-alist " key " '")
14274 (print (aget vhdl-package-alist cache-key t) (current-buffer))
14275 (insert ")\n\n;; instantiated entities cache\n"
14276 "(aput 'vhdl-ent-inst-alist " key " '")
14277 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
14278 (insert ")\n\n;; design units per file cache\n"
14279 "(aput 'vhdl-file-alist " key " '")
14280 (print (aget vhdl-file-alist cache-key t) (current-buffer))
14281 (when project
14282 (insert ")\n\n;; source directories in project cache\n"
14283 "(aput 'vhdl-directory-alist " key " '")
14284 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
14285 (insert ")\n"))
14286 (when (member 'display vhdl-speedbar-save-cache)
14287 (insert "\n;; shown design units cache\n"
14288 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
14289 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
14290 (current-buffer))
14291 (insert ")\n"))
14292 (setq vhdl-updated-project-list
14293 (delete cache-key vhdl-updated-project-list))
14294 (save-buffer)
14295 (kill-buffer (current-buffer))
14296 (set-buffer orig-buffer))))
14298 (defun vhdl-load-cache (key)
14299 "Load hierarchy cache information from file."
14300 (let* ((vhdl-project key)
14301 (default-directory key)
14302 (directory (vhdl-default-directory))
14303 (file-name (vhdl-resolve-env-variable
14304 (vhdl-replace-string
14305 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
14306 (concat
14307 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
14308 " " (user-login-name)))))
14309 (file-dir-name (expand-file-name file-name directory))
14310 vhdl-cache-version)
14311 (unless (memq 'vhdl-save-caches kill-emacs-hook)
14312 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
14313 (when (file-exists-p file-dir-name)
14314 (condition-case ()
14315 (progn (load-file file-dir-name)
14316 (string< (mapconcat
14317 (lambda (a) (format "%3d" (string-to-number a)))
14318 (split-string "3.33" "\\.") "")
14319 (mapconcat
14320 (lambda (a) (format "%3d" (string-to-number a)))
14321 (split-string vhdl-cache-version "\\.") "")))
14322 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
14323 nil))))))
14325 (defun vhdl-require-hierarchy-info ()
14326 "Make sure that hierarchy information is available. Load cache or scan files
14327 if required."
14328 (if (vhdl-project-p)
14329 (unless (or (assoc vhdl-project vhdl-file-alist)
14330 (vhdl-load-cache vhdl-project))
14331 (vhdl-scan-project-contents vhdl-project))
14332 (let ((directory (abbreviate-file-name default-directory)))
14333 (unless (or (assoc directory vhdl-file-alist)
14334 (vhdl-load-cache directory))
14335 (vhdl-scan-directory-contents directory)))))
14337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14338 ;; Add hierarchy browser functionality to speedbar
14340 (defvar vhdl-speedbar-key-map nil
14341 "Keymap used when in the VHDL hierarchy browser mode.")
14343 (defvar vhdl-speedbar-menu-items nil
14344 "Additional menu-items to add to speedbar frame.")
14346 (defun vhdl-speedbar-initialize ()
14347 "Initialize speedbar."
14348 ;; general settings
14349 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
14350 ;; VHDL file extensions (extracted from `auto-mode-alist')
14351 (let ((mode-alist auto-mode-alist))
14352 (while mode-alist
14353 (when (eq (cdar mode-alist) 'vhdl-mode)
14354 (speedbar-add-supported-extension (caar mode-alist)))
14355 (setq mode-alist (cdr mode-alist))))
14356 ;; hierarchy browser settings
14357 (when (boundp 'speedbar-mode-functions-list)
14358 ;; special functions
14359 (speedbar-add-mode-functions-list
14360 '("vhdl directory"
14361 (speedbar-item-info . vhdl-speedbar-item-info)
14362 (speedbar-line-directory . speedbar-files-line-path)))
14363 (speedbar-add-mode-functions-list
14364 '("vhdl project"
14365 (speedbar-item-info . vhdl-speedbar-item-info)
14366 (speedbar-line-directory . vhdl-speedbar-line-project)))
14367 ;; keymap
14368 (unless vhdl-speedbar-key-map
14369 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
14370 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14371 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14372 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
14373 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14374 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14375 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14376 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14377 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
14378 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14379 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
14380 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14381 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14382 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14383 (let ((key 0))
14384 (while (<= key 9)
14385 (define-key vhdl-speedbar-key-map (int-to-string key)
14386 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14387 (setq key (1+ key)))))
14388 (define-key speedbar-key-map "h"
14389 (lambda () (interactive)
14390 (speedbar-change-initial-expansion-list "vhdl directory")))
14391 (define-key speedbar-key-map "H"
14392 (lambda () (interactive)
14393 (speedbar-change-initial-expansion-list "vhdl project")))
14394 ;; menu
14395 (unless vhdl-speedbar-menu-items
14396 (setq
14397 vhdl-speedbar-menu-items
14398 `(["Edit" speedbar-edit-line t]
14399 ["Expand" speedbar-expand-line
14400 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14401 ["Contract" vhdl-speedbar-contract-level t]
14402 ["Expand All" vhdl-speedbar-expand-all t]
14403 ["Contract All" vhdl-speedbar-contract-all t]
14404 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14405 (while (<= key 9)
14406 (setq menu-list
14407 (cons `[,(if (= key 0) "All" (int-to-string key))
14408 (vhdl-speedbar-set-depth ,key)
14409 :style radio
14410 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14411 :keys ,(int-to-string key)]
14412 menu-list))
14413 (setq key (1+ key)))
14414 (nreverse menu-list))
14415 "--"
14416 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14417 (or (vhdl-speedbar-check-unit 'entity)
14418 (vhdl-speedbar-check-unit 'subprogram))]
14419 ["Place Component" vhdl-speedbar-place-component
14420 (vhdl-speedbar-check-unit 'entity)]
14421 ["Generate Configuration" vhdl-speedbar-configuration
14422 (vhdl-speedbar-check-unit 'architecture)]
14423 ["Select as MRA" vhdl-speedbar-select-mra
14424 (vhdl-speedbar-check-unit 'architecture)]
14425 ["Make" vhdl-speedbar-make-design
14426 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14427 ["Generate Makefile" vhdl-speedbar-generate-makefile
14428 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14429 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14430 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14431 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
14432 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14433 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14434 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
14435 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14436 ;; hook-ups
14437 (speedbar-add-expansion-list
14438 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14439 vhdl-speedbar-display-directory))
14440 (speedbar-add-expansion-list
14441 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14442 vhdl-speedbar-display-projects))
14443 (setq speedbar-stealthy-function-list
14444 (append
14445 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14446 ("vhdl project" vhdl-speedbar-update-current-project
14447 vhdl-speedbar-update-current-unit)
14448 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14449 ; (speedbar-extension-list-to-regex
14450 ; speedbar-ignored-path-expressions))))
14452 speedbar-stealthy-function-list))
14453 (when (eq vhdl-speedbar-display-mode 'directory)
14454 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14455 (when (eq vhdl-speedbar-display-mode 'project)
14456 (setq speedbar-initial-expansion-list-name "vhdl project"))
14457 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
14459 (defun vhdl-speedbar (&optional arg)
14460 "Open/close speedbar."
14461 (interactive)
14462 (if (not (fboundp 'speedbar))
14463 (error "WARNING: Speedbar is not available or not installed")
14464 (condition-case ()
14465 (speedbar-frame-mode arg)
14466 (error (error "WARNING: An error occurred while opening speedbar")))))
14468 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14469 ;; Display functions
14471 (defvar vhdl-speedbar-last-selected-project nil
14472 "Name of last selected project.")
14474 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14475 (defmacro speedbar-with-writable (&rest forms)
14476 "Allow the buffer to be writable and evaluate FORMS."
14477 (list 'let '((inhibit-read-only t))
14478 (cons 'progn forms)))
14479 (put 'speedbar-with-writable 'lisp-indent-function 0)
14481 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
14482 "Display directory and hierarchy information in speedbar."
14483 (setq vhdl-speedbar-show-projects nil)
14484 (setq speedbar-ignored-directory-regexp
14485 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
14486 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14487 (setq speedbar-last-selected-file nil)
14488 (speedbar-with-writable
14489 (condition-case nil
14490 (progn
14491 ;; insert directory path
14492 (speedbar-directory-buttons directory depth)
14493 ;; insert subdirectories
14494 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14495 ;; scan and insert hierarchy of current directory
14496 (vhdl-speedbar-insert-dir-hierarchy directory depth
14497 speedbar-power-click)
14498 ;; expand subdirectories
14499 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14500 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14502 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
14503 "Display projects and hierarchy information in speedbar."
14504 (setq vhdl-speedbar-show-projects t)
14505 (setq speedbar-ignored-directory-regexp ".")
14506 (setq speedbar-last-selected-file nil)
14507 (setq vhdl-speedbar-last-selected-project nil)
14508 (speedbar-with-writable
14509 (condition-case nil
14510 ;; insert projects
14511 (vhdl-speedbar-insert-projects)
14512 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14513 (setq speedbar-full-text-cache nil)) ; prevent caching
14515 (defun vhdl-speedbar-insert-projects ()
14516 "Insert all projects in speedbar."
14517 (vhdl-speedbar-make-title-line "Projects:")
14518 (let ((project-alist (if vhdl-project-sort
14519 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14520 vhdl-project-alist))
14521 (vhdl-speedbar-update-current-unit nil))
14522 ;; insert projects
14523 (while project-alist
14524 (speedbar-make-tag-line
14525 'angle ?+ 'vhdl-speedbar-expand-project
14526 (caar project-alist) (caar project-alist)
14527 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14528 (setq project-alist (cdr project-alist)))
14529 (setq project-alist vhdl-project-alist)
14530 ;; expand projects
14531 (while project-alist
14532 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14533 (goto-char (point-min))
14534 (when (re-search-forward
14535 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14536 (goto-char (match-end 1))
14537 (speedbar-do-function-pointer)))
14538 (setq project-alist (cdr project-alist))))
14539 ; (vhdl-speedbar-update-current-project)
14540 ; (vhdl-speedbar-update-current-unit nil t)
14543 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14544 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14545 otherwise use cached data."
14546 (when (or rescan (and (not (assoc project vhdl-file-alist))
14547 (not (vhdl-load-cache project))))
14548 (vhdl-scan-project-contents project))
14549 ;; insert design hierarchy
14550 (vhdl-speedbar-insert-hierarchy
14551 (aget vhdl-entity-alist project t)
14552 (aget vhdl-config-alist project t)
14553 (aget vhdl-package-alist project t)
14554 (car (aget vhdl-ent-inst-alist project t)) indent)
14555 (insert (int-to-string indent) ":\n")
14556 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14557 (put-text-property (1- (point)) (point) 'invisible nil)
14558 ;; expand design units
14559 (vhdl-speedbar-expand-units project))
14561 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14562 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14563 otherwise use cached data."
14564 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14565 (not (vhdl-load-cache directory))))
14566 (vhdl-scan-directory-contents directory))
14567 ;; insert design hierarchy
14568 (vhdl-speedbar-insert-hierarchy
14569 (aget vhdl-entity-alist directory t)
14570 (aget vhdl-config-alist directory t)
14571 (aget vhdl-package-alist directory t)
14572 (car (aget vhdl-ent-inst-alist directory t)) depth)
14573 ;; expand design units
14574 (vhdl-speedbar-expand-units directory)
14575 (aput 'vhdl-directory-alist directory (list (list directory))))
14577 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14578 ent-inst-list depth)
14579 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14580 (if (not (or ent-alist conf-alist pack-alist))
14581 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14582 (let (ent-entry conf-entry pack-entry)
14583 ;; insert entities
14584 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14585 (while ent-alist
14586 (setq ent-entry (car ent-alist))
14587 (speedbar-make-tag-line
14588 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
14589 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14590 (cons (nth 2 ent-entry) (nth 3 ent-entry))
14591 'vhdl-speedbar-entity-face depth)
14592 (unless (nth 2 ent-entry)
14593 (end-of-line 0) (insert "!") (forward-char 1))
14594 (unless (member (nth 0 ent-entry) ent-inst-list)
14595 (end-of-line 0) (insert " (top)") (forward-char 1))
14596 (setq ent-alist (cdr ent-alist)))
14597 ;; insert configurations
14598 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14599 (while conf-alist
14600 (setq conf-entry (car conf-alist))
14601 (speedbar-make-tag-line
14602 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14603 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14604 (cons (nth 2 conf-entry) (nth 3 conf-entry))
14605 'vhdl-speedbar-configuration-face depth)
14606 (setq conf-alist (cdr conf-alist)))
14607 ;; insert packages
14608 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14609 (while pack-alist
14610 (setq pack-entry (car pack-alist))
14611 (vhdl-speedbar-make-pack-line
14612 (nth 0 pack-entry) (nth 1 pack-entry)
14613 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14614 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14615 depth)
14616 (setq pack-alist (cdr pack-alist))))))
14618 (defun vhdl-speedbar-rescan-hierarchy ()
14619 "Rescan hierarchy for the directory or project under the cursor."
14620 (interactive)
14621 (let (key path)
14622 (cond
14623 ;; current project
14624 (vhdl-speedbar-show-projects
14625 (setq key (vhdl-speedbar-line-project))
14626 (vhdl-scan-project-contents key))
14627 ;; top-level directory
14628 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14629 (re-search-forward "[0-9]+:" nil t)
14630 (vhdl-scan-directory-contents
14631 (abbreviate-file-name (speedbar-line-directory))))
14632 ;; current directory
14633 (t (setq path (speedbar-line-directory))
14634 (string-match "^\\(.+[/\\]\\)" path)
14635 (vhdl-scan-directory-contents
14636 (abbreviate-file-name (match-string 1 path)))))
14637 (vhdl-speedbar-refresh key)))
14639 (defun vhdl-speedbar-expand-dirs (directory)
14640 "Expand subdirectories in DIRECTORY according to
14641 `speedbar-shown-directories'."
14642 ;; (nicked from `speedbar-default-directory-list')
14643 (let ((sf (cdr (reverse speedbar-shown-directories)))
14644 (vhdl-speedbar-update-current-unit nil))
14645 (setq speedbar-shown-directories
14646 (list (expand-file-name default-directory)))
14647 (while sf
14648 (when (speedbar-goto-this-file (car sf))
14649 (beginning-of-line)
14650 (when (looking-at "[0-9]+:\\s-*<")
14651 (goto-char (match-end 0))
14652 (speedbar-do-function-pointer)))
14653 (setq sf (cdr sf))))
14654 (vhdl-speedbar-update-current-unit nil t))
14656 (defun vhdl-speedbar-expand-units (key)
14657 "Expand design units in directory/project KEY according to
14658 `vhdl-speedbar-shown-unit-alist'."
14659 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14660 (vhdl-speedbar-update-current-unit nil)
14661 vhdl-updated-project-list)
14662 (adelete 'vhdl-speedbar-shown-unit-alist key)
14663 (vhdl-prepare-search-1
14664 (while unit-alist ; expand units
14665 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14666 (beginning-of-line)
14667 (let ((arch-alist (nth 1 (car unit-alist)))
14668 position)
14669 (when (looking-at "^[0-9]+:\\s-*\\[")
14670 (goto-char (match-end 0))
14671 (setq position (point))
14672 (speedbar-do-function-pointer)
14673 (select-frame speedbar-frame)
14674 (while arch-alist ; expand architectures
14675 (goto-char position)
14676 (when (re-search-forward
14677 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14678 (car arch-alist) "\\>\\)") nil t)
14679 (beginning-of-line)
14680 (when (looking-at "^[0-9]+:\\s-*{")
14681 (goto-char (match-end 0))
14682 (speedbar-do-function-pointer)
14683 (select-frame speedbar-frame)))
14684 (setq arch-alist (cdr arch-alist))))
14685 (setq unit-alist (cdr unit-alist))))))
14686 (vhdl-speedbar-update-current-unit nil t))
14688 (defun vhdl-speedbar-contract-level ()
14689 "Contract current level in current directory/project."
14690 (interactive)
14691 (when (or (save-excursion
14692 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14693 (and (save-excursion
14694 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14695 (re-search-backward
14696 (format "^[0-%d]:\\s-*[[{<]-"
14697 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14698 (goto-char (match-end 0))
14699 (speedbar-do-function-pointer)
14700 (speedbar-center-buffer-smartly)))
14702 (defun vhdl-speedbar-contract-all ()
14703 "Contract all expanded design units in current directory/project."
14704 (interactive)
14705 (if (and vhdl-speedbar-show-projects
14706 (save-excursion (beginning-of-line) (looking-at "^0:")))
14707 (progn (setq vhdl-speedbar-shown-project-list nil)
14708 (vhdl-speedbar-refresh))
14709 (let ((key (vhdl-speedbar-line-key)))
14710 (adelete 'vhdl-speedbar-shown-unit-alist key)
14711 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14712 (when (memq 'display vhdl-speedbar-save-cache)
14713 (add-to-list 'vhdl-updated-project-list key)))))
14715 (defun vhdl-speedbar-expand-all ()
14716 "Expand all design units in current directory/project."
14717 (interactive)
14718 (let* ((key (vhdl-speedbar-line-key))
14719 (ent-alist (aget vhdl-entity-alist key t))
14720 (conf-alist (aget vhdl-config-alist key t))
14721 (pack-alist (aget vhdl-package-alist key t))
14722 arch-alist unit-alist subunit-alist)
14723 (add-to-list 'vhdl-speedbar-shown-project-list key)
14724 (while ent-alist
14725 (setq arch-alist (nth 4 (car ent-alist)))
14726 (setq subunit-alist nil)
14727 (while arch-alist
14728 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14729 (setq arch-alist (cdr arch-alist)))
14730 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14731 (setq ent-alist (cdr ent-alist)))
14732 (while conf-alist
14733 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14734 (setq conf-alist (cdr conf-alist)))
14735 (while pack-alist
14736 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14737 (setq pack-alist (cdr pack-alist)))
14738 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14739 (vhdl-speedbar-refresh)
14740 (when (memq 'display vhdl-speedbar-save-cache)
14741 (add-to-list 'vhdl-updated-project-list key))))
14743 (defun vhdl-speedbar-expand-project (text token indent)
14744 "Expand/contract the project under the cursor."
14745 (cond
14746 ((string-match "+" text) ; expand project
14747 (speedbar-change-expand-button-char ?-)
14748 (unless (member token vhdl-speedbar-shown-project-list)
14749 (setq vhdl-speedbar-shown-project-list
14750 (cons token vhdl-speedbar-shown-project-list)))
14751 (speedbar-with-writable
14752 (save-excursion
14753 (end-of-line) (forward-char 1)
14754 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14755 speedbar-power-click))))
14756 ((string-match "-" text) ; contract project
14757 (speedbar-change-expand-button-char ?+)
14758 (setq vhdl-speedbar-shown-project-list
14759 (delete token vhdl-speedbar-shown-project-list))
14760 (speedbar-delete-subblock indent))
14761 (t (error "Nothing to display")))
14762 (when (equal (selected-frame) speedbar-frame)
14763 (speedbar-center-buffer-smartly)))
14765 (defun vhdl-speedbar-expand-entity (text token indent)
14766 "Expand/contract the entity under the cursor."
14767 (cond
14768 ((string-match "+" text) ; expand entity
14769 (let* ((key (vhdl-speedbar-line-key indent))
14770 (ent-alist (aget vhdl-entity-alist key t))
14771 (ent-entry (aget ent-alist token t))
14772 (arch-alist (nth 3 ent-entry))
14773 (inst-alist (vhdl-get-instantiations token indent))
14774 (subpack-alist (nth 5 ent-entry))
14775 (multiple-arch (> (length arch-alist) 1))
14776 arch-entry inst-entry)
14777 (if (not (or arch-alist inst-alist subpack-alist))
14778 (speedbar-change-expand-button-char ??)
14779 (speedbar-change-expand-button-char ?-)
14780 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14781 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14782 (aput 'unit-alist token nil)
14783 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14784 (speedbar-with-writable
14785 (save-excursion
14786 (end-of-line) (forward-char 1)
14787 ;; insert architectures
14788 (when arch-alist
14789 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14790 (while arch-alist
14791 (setq arch-entry (car arch-alist))
14792 (speedbar-make-tag-line
14793 'curly ?+ 'vhdl-speedbar-expand-architecture
14794 (cons token (nth 0 arch-entry))
14795 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14796 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14797 'vhdl-speedbar-architecture-face (1+ indent))
14798 (when (and multiple-arch
14799 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14800 (end-of-line 0) (insert " (mra)") (forward-char 1))
14801 (setq arch-alist (cdr arch-alist)))
14802 ;; insert instantiations
14803 (when inst-alist
14804 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14805 (while inst-alist
14806 (setq inst-entry (car inst-alist))
14807 (vhdl-speedbar-make-inst-line
14808 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14809 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14810 nil nil nil (1+ indent) 0 " in ")
14811 (setq inst-alist (cdr inst-alist)))
14812 ;; insert required packages
14813 (vhdl-speedbar-insert-subpackages
14814 subpack-alist (1+ indent) indent)))
14815 (when (memq 'display vhdl-speedbar-save-cache)
14816 (add-to-list 'vhdl-updated-project-list key))
14817 (vhdl-speedbar-update-current-unit t t))))
14818 ((string-match "-" text) ; contract entity
14819 (speedbar-change-expand-button-char ?+)
14820 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14821 (let* ((key (vhdl-speedbar-line-key indent))
14822 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14823 (adelete 'unit-alist token)
14824 (if unit-alist
14825 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14826 (adelete 'vhdl-speedbar-shown-unit-alist key))
14827 (speedbar-delete-subblock indent)
14828 (when (memq 'display vhdl-speedbar-save-cache)
14829 (add-to-list 'vhdl-updated-project-list key))))
14830 (t (error "Nothing to display")))
14831 (when (equal (selected-frame) speedbar-frame)
14832 (speedbar-center-buffer-smartly)))
14834 (defun vhdl-speedbar-expand-architecture (text token indent)
14835 "Expand/contract the architecture under the cursor."
14836 (cond
14837 ((string-match "+" text) ; expand architecture
14838 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14839 (ent-alist (aget vhdl-entity-alist key t))
14840 (conf-alist (aget vhdl-config-alist key t))
14841 (hier-alist (vhdl-get-hierarchy
14842 ent-alist conf-alist (car token) (cdr token) nil nil
14843 0 (1- indent)))
14844 (ent-entry (aget ent-alist (car token) t))
14845 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14846 (subpack-alist (nth 4 arch-entry))
14847 entry)
14848 (if (not (or hier-alist subpack-alist))
14849 (speedbar-change-expand-button-char ??)
14850 (speedbar-change-expand-button-char ?-)
14851 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14852 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14853 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14854 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14855 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14856 (speedbar-with-writable
14857 (save-excursion
14858 (end-of-line) (forward-char 1)
14859 ;; insert instance hierarchy
14860 (when hier-alist
14861 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14862 (1+ indent)))
14863 (while hier-alist
14864 (setq entry (car hier-alist))
14865 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14866 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14867 (vhdl-speedbar-make-inst-line
14868 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14869 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14870 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14871 (setq hier-alist (cdr hier-alist)))
14872 ;; insert required packages
14873 (vhdl-speedbar-insert-subpackages
14874 subpack-alist (1+ indent) (1- indent))))
14875 (when (memq 'display vhdl-speedbar-save-cache)
14876 (add-to-list 'vhdl-updated-project-list key))
14877 (vhdl-speedbar-update-current-unit t t))))
14878 ((string-match "-" text) ; contract architecture
14879 (speedbar-change-expand-button-char ?+)
14880 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14881 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14882 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14883 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14884 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14885 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14886 (speedbar-delete-subblock indent)
14887 (when (memq 'display vhdl-speedbar-save-cache)
14888 (add-to-list 'vhdl-updated-project-list key))))
14889 (t (error "Nothing to display")))
14890 (when (equal (selected-frame) speedbar-frame)
14891 (speedbar-center-buffer-smartly)))
14893 (defun vhdl-speedbar-expand-config (text token indent)
14894 "Expand/contract the configuration under the cursor."
14895 (cond
14896 ((string-match "+" text) ; expand configuration
14897 (let* ((key (vhdl-speedbar-line-key indent))
14898 (conf-alist (aget vhdl-config-alist key t))
14899 (conf-entry (aget conf-alist token))
14900 (ent-alist (aget vhdl-entity-alist key t))
14901 (hier-alist (vhdl-get-hierarchy
14902 ent-alist conf-alist (nth 3 conf-entry)
14903 (nth 4 conf-entry) token (nth 5 conf-entry)
14904 0 indent t))
14905 (subpack-alist (nth 6 conf-entry))
14906 entry)
14907 (if (not (or hier-alist subpack-alist))
14908 (speedbar-change-expand-button-char ??)
14909 (speedbar-change-expand-button-char ?-)
14910 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14911 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14912 (aput 'unit-alist token nil)
14913 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14914 (speedbar-with-writable
14915 (save-excursion
14916 (end-of-line) (forward-char 1)
14917 ;; insert instance hierarchy
14918 (when hier-alist
14919 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14920 (while hier-alist
14921 (setq entry (car hier-alist))
14922 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14923 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14924 (vhdl-speedbar-make-inst-line
14925 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14926 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14927 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14928 (setq hier-alist (cdr hier-alist)))
14929 ;; insert required packages
14930 (vhdl-speedbar-insert-subpackages
14931 subpack-alist (1+ indent) indent)))
14932 (when (memq 'display vhdl-speedbar-save-cache)
14933 (add-to-list 'vhdl-updated-project-list key))
14934 (vhdl-speedbar-update-current-unit t t))))
14935 ((string-match "-" text) ; contract configuration
14936 (speedbar-change-expand-button-char ?+)
14937 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14938 (let* ((key (vhdl-speedbar-line-key indent))
14939 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14940 (adelete 'unit-alist token)
14941 (if unit-alist
14942 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14943 (adelete 'vhdl-speedbar-shown-unit-alist key))
14944 (speedbar-delete-subblock indent)
14945 (when (memq 'display vhdl-speedbar-save-cache)
14946 (add-to-list 'vhdl-updated-project-list key))))
14947 (t (error "Nothing to display")))
14948 (when (equal (selected-frame) speedbar-frame)
14949 (speedbar-center-buffer-smartly)))
14951 (defun vhdl-speedbar-expand-package (text token indent)
14952 "Expand/contract the package under the cursor."
14953 (cond
14954 ((string-match "+" text) ; expand package
14955 (let* ((key (vhdl-speedbar-line-key indent))
14956 (pack-alist (aget vhdl-package-alist key t))
14957 (pack-entry (aget pack-alist token t))
14958 (comp-alist (nth 3 pack-entry))
14959 (func-alist (nth 4 pack-entry))
14960 (func-body-alist (nth 8 pack-entry))
14961 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14962 comp-entry func-entry func-body-entry)
14963 (if (not (or comp-alist func-alist subpack-alist))
14964 (speedbar-change-expand-button-char ??)
14965 (speedbar-change-expand-button-char ?-)
14966 ;; add package to `vhdl-speedbar-shown-unit-alist'
14967 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14968 (aput 'unit-alist token nil)
14969 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14970 (speedbar-with-writable
14971 (save-excursion
14972 (end-of-line) (forward-char 1)
14973 ;; insert components
14974 (when comp-alist
14975 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14976 (while comp-alist
14977 (setq comp-entry (car comp-alist))
14978 (speedbar-make-tag-line
14979 nil nil nil
14980 (cons token (nth 0 comp-entry))
14981 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14982 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14983 'vhdl-speedbar-entity-face (1+ indent))
14984 (setq comp-alist (cdr comp-alist)))
14985 ;; insert subprograms
14986 (when func-alist
14987 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14988 (while func-alist
14989 (setq func-entry (car func-alist)
14990 func-body-entry (aget func-body-alist (car func-entry) t))
14991 (when (nth 2 func-entry)
14992 (vhdl-speedbar-make-subprogram-line
14993 (nth 1 func-entry)
14994 (cons (nth 2 func-entry) (nth 3 func-entry))
14995 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14996 (1+ indent)))
14997 (setq func-alist (cdr func-alist)))
14998 ;; insert required packages
14999 (vhdl-speedbar-insert-subpackages
15000 subpack-alist (1+ indent) indent)))
15001 (when (memq 'display vhdl-speedbar-save-cache)
15002 (add-to-list 'vhdl-updated-project-list key))
15003 (vhdl-speedbar-update-current-unit t t))))
15004 ((string-match "-" text) ; contract package
15005 (speedbar-change-expand-button-char ?+)
15006 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15007 (let* ((key (vhdl-speedbar-line-key indent))
15008 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
15009 (adelete 'unit-alist token)
15010 (if unit-alist
15011 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
15012 (adelete 'vhdl-speedbar-shown-unit-alist key))
15013 (speedbar-delete-subblock indent)
15014 (when (memq 'display vhdl-speedbar-save-cache)
15015 (add-to-list 'vhdl-updated-project-list key))))
15016 (t (error "Nothing to display")))
15017 (when (equal (selected-frame) speedbar-frame)
15018 (speedbar-center-buffer-smartly)))
15020 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
15021 "Insert required packages."
15022 (let* ((pack-alist (aget vhdl-package-alist
15023 (vhdl-speedbar-line-key dir-indent) t))
15024 pack-key lib-name pack-entry)
15025 (when subpack-alist
15026 (vhdl-speedbar-make-title-line "Packages Used:" indent))
15027 (while subpack-alist
15028 (setq pack-key (cdar subpack-alist)
15029 lib-name (caar subpack-alist))
15030 (setq pack-entry (aget pack-alist pack-key t))
15031 (vhdl-speedbar-make-subpack-line
15032 (or (nth 0 pack-entry) pack-key) lib-name
15033 (cons (nth 1 pack-entry) (nth 2 pack-entry))
15034 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
15035 (setq subpack-alist (cdr subpack-alist)))))
15037 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15038 ;; Display help functions
15040 (defvar vhdl-speedbar-update-current-unit t
15041 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15043 (defun vhdl-speedbar-update-current-project ()
15044 "Highlight project that is currently active."
15045 (when (and vhdl-speedbar-show-projects
15046 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
15047 (and (boundp 'speedbar-frame)
15048 (frame-live-p speedbar-frame)))
15049 (let ((last-frame (selected-frame))
15050 (project-alist vhdl-project-alist)
15051 pos)
15052 (select-frame speedbar-frame)
15053 (speedbar-with-writable
15054 (save-excursion
15055 (while project-alist
15056 (goto-char (point-min))
15057 (when (re-search-forward
15058 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
15059 (put-text-property (match-beginning 1) (match-end 1) 'face
15060 (if (equal (caar project-alist) vhdl-project)
15061 'speedbar-selected-face
15062 'speedbar-directory-face))
15063 (when (equal (caar project-alist) vhdl-project)
15064 (setq pos (1- (match-beginning 1)))))
15065 (setq project-alist (cdr project-alist))))
15066 (when pos (goto-char pos)))
15067 (select-frame last-frame)
15068 (setq vhdl-speedbar-last-selected-project vhdl-project)))
15071 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
15072 "Highlight all design units that are contained in the current file.
15073 NO-POSITION non-nil means do not re-position cursor."
15074 (let ((last-frame (selected-frame))
15075 (project-list vhdl-speedbar-shown-project-list)
15076 file-alist pos file-name)
15077 ;; get current file name
15078 (if (fboundp 'speedbar-select-attached-frame)
15079 (speedbar-select-attached-frame)
15080 (select-frame speedbar-attached-frame))
15081 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
15082 (when (and vhdl-speedbar-update-current-unit
15083 (or always (not (equal file-name speedbar-last-selected-file))))
15084 (if vhdl-speedbar-show-projects
15085 (while project-list
15086 (setq file-alist (append file-alist (aget vhdl-file-alist
15087 (car project-list) t)))
15088 (setq project-list (cdr project-list)))
15089 (setq file-alist (aget vhdl-file-alist
15090 (abbreviate-file-name default-directory) t)))
15091 (select-frame speedbar-frame)
15092 (set-buffer speedbar-buffer)
15093 (speedbar-with-writable
15094 (vhdl-prepare-search-1
15095 (save-excursion
15096 ;; unhighlight last units
15097 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
15098 (vhdl-speedbar-update-units
15099 "\\[.\\] " (nth 0 file-entry)
15100 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
15101 (vhdl-speedbar-update-units
15102 "{.} " (nth 1 file-entry)
15103 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
15104 (vhdl-speedbar-update-units
15105 "\\[.\\] " (nth 3 file-entry)
15106 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
15107 (vhdl-speedbar-update-units
15108 "[]>] " (nth 4 file-entry)
15109 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15110 (vhdl-speedbar-update-units
15111 "\\[.\\].+(" '("body")
15112 speedbar-last-selected-file 'vhdl-speedbar-package-face)
15113 (vhdl-speedbar-update-units
15114 "> " (nth 6 file-entry)
15115 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
15116 ;; highlight current units
15117 (let* ((file-entry (aget file-alist file-name t)))
15118 (setq
15119 pos (vhdl-speedbar-update-units
15120 "\\[.\\] " (nth 0 file-entry)
15121 file-name 'vhdl-speedbar-entity-selected-face pos)
15122 pos (vhdl-speedbar-update-units
15123 "{.} " (nth 1 file-entry)
15124 file-name 'vhdl-speedbar-architecture-selected-face pos)
15125 pos (vhdl-speedbar-update-units
15126 "\\[.\\] " (nth 3 file-entry)
15127 file-name 'vhdl-speedbar-configuration-selected-face pos)
15128 pos (vhdl-speedbar-update-units
15129 "[]>] " (nth 4 file-entry)
15130 file-name 'vhdl-speedbar-package-selected-face pos)
15131 pos (vhdl-speedbar-update-units
15132 "\\[.\\].+(" '("body")
15133 file-name 'vhdl-speedbar-package-selected-face pos)
15134 pos (vhdl-speedbar-update-units
15135 "> " (nth 6 file-entry)
15136 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
15137 ;; move speedbar so the first highlighted unit is visible
15138 (when (and pos (not no-position))
15139 (goto-char pos)
15140 (speedbar-center-buffer-smartly)
15141 (speedbar-position-cursor-on-line))
15142 (setq speedbar-last-selected-file file-name))
15143 (select-frame last-frame)
15146 (defun vhdl-speedbar-update-units (text unit-list file-name face
15147 &optional pos)
15148 "Help function to highlight design units."
15149 (while unit-list
15150 (goto-char (point-min))
15151 (while (re-search-forward
15152 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
15153 (when (equal file-name (car (get-text-property
15154 (match-beginning 1) 'speedbar-token)))
15155 (setq pos (or pos (point-marker)))
15156 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
15157 (setq unit-list (cdr unit-list)))
15158 pos)
15160 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15161 ent-name ent-file-marker
15162 arch-name arch-file-marker
15163 conf-name conf-file-marker
15164 lib-name depth offset delimiter)
15165 "Insert instantiation entry."
15166 (let ((start (point))
15167 visible-start)
15168 (insert (int-to-string depth) ":")
15169 (put-text-property start (point) 'invisible t)
15170 (setq visible-start (point))
15171 (insert-char ? (* depth speedbar-indentation-width))
15172 (while (> offset 0)
15173 (insert "|")
15174 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
15175 (setq offset (1- offset)))
15176 (put-text-property visible-start (point) 'invisible nil)
15177 (setq start (point))
15178 (insert ">")
15179 (speedbar-make-button start (point) nil nil nil)
15180 (setq visible-start (point))
15181 (insert " ")
15182 (setq start (point))
15183 (if (not inst-name)
15184 (insert "(top)")
15185 (insert inst-name)
15186 (speedbar-make-button
15187 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
15188 'vhdl-speedbar-find-file inst-file-marker))
15189 (insert delimiter)
15190 (when ent-name
15191 (setq start (point))
15192 (insert ent-name)
15193 (speedbar-make-button
15194 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
15195 'vhdl-speedbar-find-file ent-file-marker)
15196 (when arch-name
15197 (insert " (")
15198 (setq start (point))
15199 (insert arch-name)
15200 (speedbar-make-button
15201 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
15202 'vhdl-speedbar-find-file arch-file-marker)
15203 (insert ")"))
15204 (when conf-name
15205 (insert " (")
15206 (setq start (point))
15207 (insert conf-name)
15208 (speedbar-make-button
15209 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
15210 'vhdl-speedbar-find-file conf-file-marker)
15211 (insert ")")))
15212 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
15213 (setq start (point))
15214 (insert " (" lib-name ")")
15215 (put-text-property (+ 2 start) (1- (point)) 'face
15216 'vhdl-speedbar-library-face))
15217 (insert-char ?\n 1)
15218 (put-text-property visible-start (point) 'invisible nil)))
15220 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15221 body-file-marker depth)
15222 "Insert package entry."
15223 (let ((start (point))
15224 visible-start)
15225 (insert (int-to-string depth) ":")
15226 (put-text-property start (point) 'invisible t)
15227 (setq visible-start (point))
15228 (insert-char ? (* depth speedbar-indentation-width))
15229 (put-text-property visible-start (point) 'invisible nil)
15230 (setq start (point))
15231 (insert "[+]")
15232 (speedbar-make-button
15233 start (point) 'speedbar-button-face 'speedbar-highlight-face
15234 'vhdl-speedbar-expand-package pack-key)
15235 (setq visible-start (point))
15236 (insert-char ? 1 nil)
15237 (setq start (point))
15238 (insert pack-name)
15239 (speedbar-make-button
15240 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15241 'vhdl-speedbar-find-file pack-file-marker)
15242 (unless (car pack-file-marker)
15243 (insert "!"))
15244 (when (car body-file-marker)
15245 (insert " (")
15246 (setq start (point))
15247 (insert "body")
15248 (speedbar-make-button
15249 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15250 'vhdl-speedbar-find-file body-file-marker)
15251 (insert ")"))
15252 (insert-char ?\n 1)
15253 (put-text-property visible-start (point) 'invisible nil)))
15255 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15256 pack-body-file-marker depth)
15257 "Insert used package entry."
15258 (let ((start (point))
15259 visible-start)
15260 (insert (int-to-string depth) ":")
15261 (put-text-property start (point) 'invisible t)
15262 (setq visible-start (point))
15263 (insert-char ? (* depth speedbar-indentation-width))
15264 (put-text-property visible-start (point) 'invisible nil)
15265 (setq start (point))
15266 (insert ">")
15267 (speedbar-make-button start (point) nil nil nil)
15268 (setq visible-start (point))
15269 (insert " ")
15270 (setq start (point))
15271 (insert pack-name)
15272 (speedbar-make-button
15273 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15274 'vhdl-speedbar-find-file pack-file-marker)
15275 (when (car pack-body-file-marker)
15276 (insert " (")
15277 (setq start (point))
15278 (insert "body")
15279 (speedbar-make-button
15280 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
15281 'vhdl-speedbar-find-file pack-body-file-marker)
15282 (insert ")"))
15283 (setq start (point))
15284 (insert " (" lib-name ")")
15285 (put-text-property (+ 2 start) (1- (point)) 'face
15286 'vhdl-speedbar-library-face)
15287 (insert-char ?\n 1)
15288 (put-text-property visible-start (point) 'invisible nil)))
15290 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15291 func-body-file-marker
15292 depth)
15293 "Insert subprogram entry."
15294 (let ((start (point))
15295 visible-start)
15296 (insert (int-to-string depth) ":")
15297 (put-text-property start (point) 'invisible t)
15298 (setq visible-start (point))
15299 (insert-char ? (* depth speedbar-indentation-width))
15300 (put-text-property visible-start (point) 'invisible nil)
15301 (setq start (point))
15302 (insert ">")
15303 (speedbar-make-button start (point) nil nil nil)
15304 (setq visible-start (point))
15305 (insert " ")
15306 (setq start (point))
15307 (insert func-name)
15308 (speedbar-make-button
15309 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15310 'vhdl-speedbar-find-file func-file-marker)
15311 (when (car func-body-file-marker)
15312 (insert " (")
15313 (setq start (point))
15314 (insert "body")
15315 (speedbar-make-button
15316 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
15317 'vhdl-speedbar-find-file func-body-file-marker)
15318 (insert ")"))
15319 (insert-char ?\n 1)
15320 (put-text-property visible-start (point) 'invisible nil)))
15322 (defun vhdl-speedbar-make-title-line (text &optional depth)
15323 "Insert design unit title entry."
15324 (let ((start (point))
15325 visible-start)
15326 (when depth
15327 (insert (int-to-string depth) ":")
15328 (put-text-property start (point) 'invisible t))
15329 (setq visible-start (point))
15330 (insert-char ? (* (or depth 0) speedbar-indentation-width))
15331 (setq start (point))
15332 (insert text)
15333 (speedbar-make-button start (point) nil nil nil nil)
15334 (insert-char ?\n 1)
15335 (put-text-property visible-start (point) 'invisible nil)))
15337 (defun vhdl-speedbar-insert-dirs (files level)
15338 "Insert subdirectories."
15339 (let ((dirs (car files)))
15340 (while dirs
15341 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
15342 (car dirs) 'speedbar-dir-follow nil
15343 'speedbar-directory-face level)
15344 (setq dirs (cdr dirs)))))
15346 (defun vhdl-speedbar-dired (text token indent)
15347 "Speedbar click handler for directory expand button in hierarchy mode."
15348 (cond ((string-match "+" text) ; we have to expand this dir
15349 (setq speedbar-shown-directories
15350 (cons (expand-file-name
15351 (concat (speedbar-line-directory indent) token "/"))
15352 speedbar-shown-directories))
15353 (speedbar-change-expand-button-char ?-)
15354 (speedbar-reset-scanners)
15355 (speedbar-with-writable
15356 (save-excursion
15357 (end-of-line) (forward-char 1)
15358 (vhdl-speedbar-insert-dirs
15359 (speedbar-file-lists
15360 (concat (speedbar-line-directory indent) token "/"))
15361 (1+ indent))
15362 (speedbar-reset-scanners)
15363 (vhdl-speedbar-insert-dir-hierarchy
15364 (abbreviate-file-name
15365 (concat (speedbar-line-directory indent) token "/"))
15366 (1+ indent) speedbar-power-click)))
15367 (vhdl-speedbar-update-current-unit t t))
15368 ((string-match "-" text) ; we have to contract this node
15369 (speedbar-reset-scanners)
15370 (let ((oldl speedbar-shown-directories)
15371 (newl nil)
15372 (td (expand-file-name
15373 (concat (speedbar-line-directory indent) token))))
15374 (while oldl
15375 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15376 (setq newl (cons (car oldl) newl)))
15377 (setq oldl (cdr oldl)))
15378 (setq speedbar-shown-directories (nreverse newl)))
15379 (speedbar-change-expand-button-char ?+)
15380 (speedbar-delete-subblock indent))
15381 (t (error "Nothing to display")))
15382 (when (equal (selected-frame) speedbar-frame)
15383 (speedbar-center-buffer-smartly)))
15385 (defun vhdl-speedbar-item-info ()
15386 "Derive and display information about this line item."
15387 (save-excursion
15388 (beginning-of-line)
15389 ;; skip invisible number info
15390 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15391 (cond
15392 ;; project/directory entry
15393 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15394 (if vhdl-speedbar-show-projects
15395 (message "Project \"%s\"" (match-string-no-properties 1))
15396 (speedbar-files-item-info)))
15397 ;; design unit entry
15398 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15399 (goto-char (match-end 1))
15400 (let ((face (get-text-property (point) 'face)))
15401 (message
15402 "%s \"%s\" in \"%s\""
15403 ;; design unit kind
15404 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15405 (eq face 'vhdl-speedbar-entity-selected-face))
15406 (if (equal (match-string 2) ">") "Component" "Entity"))
15407 ((or (eq face 'vhdl-speedbar-architecture-face)
15408 (eq face 'vhdl-speedbar-architecture-selected-face))
15409 "Architecture")
15410 ((or (eq face 'vhdl-speedbar-configuration-face)
15411 (eq face 'vhdl-speedbar-configuration-selected-face))
15412 "Configuration")
15413 ((or (eq face 'vhdl-speedbar-package-face)
15414 (eq face 'vhdl-speedbar-package-selected-face))
15415 "Package")
15416 ((or (eq face 'vhdl-speedbar-instantiation-face)
15417 (eq face 'vhdl-speedbar-instantiation-selected-face))
15418 "Instantiation")
15419 ((eq face 'vhdl-speedbar-subprogram-face)
15420 "Subprogram")
15421 (t ""))
15422 ;; design unit name
15423 (buffer-substring-no-properties
15424 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15425 (match-end 1))
15426 ;; file name
15427 (file-relative-name
15428 (or (car (get-text-property (point) 'speedbar-token))
15429 "?")
15430 (vhdl-default-directory)))))
15431 (t (message "")))))
15433 (defun vhdl-speedbar-line-text ()
15434 "Calls `speedbar-line-text' and removes text properties."
15435 (let ((string (speedbar-line-text)))
15436 (set-text-properties 0 (length string) nil string)
15437 string))
15439 (defun vhdl-speedbar-higher-text ()
15440 "Get speedbar-line-text of higher level."
15441 (let (depth string)
15442 (save-excursion
15443 (beginning-of-line)
15444 (looking-at "^\\([0-9]+\\):")
15445 (setq depth (string-to-number (match-string 1)))
15446 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15447 (setq string (match-string 1))
15448 (set-text-properties 0 (length string) nil string)
15449 string))))
15451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15452 ;; Help functions
15454 (defun vhdl-speedbar-line-key (&optional indent)
15455 "Get currently displayed directory of project name."
15456 (if vhdl-speedbar-show-projects
15457 (vhdl-speedbar-line-project)
15458 (abbreviate-file-name
15459 (file-name-as-directory (speedbar-line-directory indent)))))
15461 (defun vhdl-speedbar-line-project (&optional indent)
15462 "Get currently displayed project name."
15463 (and vhdl-speedbar-show-projects
15464 (save-excursion
15465 (end-of-line)
15466 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15467 (match-string-no-properties 1))))
15469 (defun vhdl-add-modified-file ()
15470 "Add file to `vhdl-modified-file-list'."
15471 (when vhdl-file-alist
15472 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15473 nil)
15475 (defun vhdl-resolve-paths (path-list)
15476 "Resolve path wildcards in PATH-LIST."
15477 (let (path-list-1 path-list-2 path-beg path-end dir)
15478 ;; eliminate non-existent directories
15479 (while path-list
15480 (setq dir (car path-list))
15481 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15482 (if (file-directory-p (match-string 2 dir))
15483 (setq path-list-1 (cons dir path-list-1))
15484 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
15485 (setq path-list (cdr path-list)))
15486 ;; resolve path wildcards
15487 (while path-list-1
15488 (setq dir (car path-list-1))
15489 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
15490 (progn
15491 (setq path-beg (match-string 1 dir)
15492 path-end (match-string 5 dir))
15493 (setq path-list-1
15494 (append
15495 (mapcar
15496 (function
15497 (lambda (var) (concat path-beg var path-end)))
15498 (let ((all-list (vhdl-directory-files
15499 (match-string 2 dir) t
15500 (concat "\\<" (wildcard-to-regexp
15501 (match-string 4 dir)))))
15502 dir-list)
15503 (while all-list
15504 (when (file-directory-p (car all-list))
15505 (setq dir-list (cons (car all-list) dir-list)))
15506 (setq all-list (cdr all-list)))
15507 dir-list))
15508 (cdr path-list-1))))
15509 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
15510 (when (file-directory-p (match-string 2 dir))
15511 (setq path-list-2 (cons dir path-list-2)))
15512 (setq path-list-1 (cdr path-list-1))))
15513 (nreverse path-list-2)))
15515 (defun vhdl-speedbar-goto-this-unit (directory unit)
15516 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15517 (let ((dest (point)))
15518 (if (and (if vhdl-speedbar-show-projects
15519 (progn (goto-char (point-min)) t)
15520 (speedbar-goto-this-file directory))
15521 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15522 (progn (speedbar-position-cursor-on-line)
15524 (goto-char dest)
15525 nil)))
15527 (defun vhdl-speedbar-find-file (text token indent)
15528 "When user clicks on TEXT, load file with name and position in TOKEN.
15529 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15530 is already shown in a buffer."
15531 (if (not (car token))
15532 (error "ERROR: File cannot be found")
15533 (let ((buffer (get-file-buffer (car token))))
15534 (speedbar-find-file-in-frame (car token))
15535 (when (or vhdl-speedbar-jump-to-unit buffer)
15536 (goto-char (point-min))
15537 (forward-line (1- (cdr token)))
15538 (recenter))
15539 (vhdl-speedbar-update-current-unit t t)
15540 (speedbar-set-timer dframe-update-speed)
15541 (speedbar-maybee-jump-to-attached-frame))))
15543 (defun vhdl-speedbar-port-copy ()
15544 "Copy the port of the entity/component or subprogram under the cursor."
15545 (interactive)
15546 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15547 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15548 (error "ERROR: No entity/component or subprogram under cursor")
15549 (beginning-of-line)
15550 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15551 (condition-case info
15552 (let ((token (get-text-property
15553 (match-beginning 3) 'speedbar-token)))
15554 (vhdl-visit-file (car token) t
15555 (progn (goto-char (point-min))
15556 (forward-line (1- (cdr token)))
15557 (end-of-line)
15558 (if is-entity
15559 (vhdl-port-copy)
15560 (vhdl-subprog-copy)))))
15561 (error (error "ERROR: %s not scanned successfully\n (%s)"
15562 (if is-entity "Port" "Interface") (cadr info))))
15563 (error "ERROR: No entity/component or subprogram on current line")))))
15565 (defun vhdl-speedbar-place-component ()
15566 "Place the entity/component under the cursor as component."
15567 (interactive)
15568 (if (not (vhdl-speedbar-check-unit 'entity))
15569 (error "ERROR: No entity/component under cursor")
15570 (vhdl-speedbar-port-copy)
15571 (if (fboundp 'speedbar-select-attached-frame)
15572 (speedbar-select-attached-frame)
15573 (select-frame speedbar-attached-frame))
15574 (vhdl-compose-place-component)
15575 (select-frame speedbar-frame)))
15577 (defun vhdl-speedbar-configuration ()
15578 "Generate configuration for the architecture under the cursor."
15579 (interactive)
15580 (if (not (vhdl-speedbar-check-unit 'architecture))
15581 (error "ERROR: No architecture under cursor")
15582 (let ((arch-name (vhdl-speedbar-line-text))
15583 (ent-name (vhdl-speedbar-higher-text)))
15584 (if (fboundp 'speedbar-select-attached-frame)
15585 (speedbar-select-attached-frame)
15586 (select-frame speedbar-attached-frame))
15587 (vhdl-compose-configuration ent-name arch-name))))
15589 (defun vhdl-speedbar-select-mra ()
15590 "Select the architecture under the cursor as MRA."
15591 (interactive)
15592 (if (not (vhdl-speedbar-check-unit 'architecture))
15593 (error "ERROR: No architecture under cursor")
15594 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15595 (ent-key (downcase (vhdl-speedbar-higher-text)))
15596 (ent-alist (aget vhdl-entity-alist
15597 (or (vhdl-project-p) default-directory) t))
15598 (ent-entry (aget ent-alist ent-key t)))
15599 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15600 (speedbar-refresh))))
15602 (defun vhdl-speedbar-make-design ()
15603 "Make (compile) design unit or directory/project under the cursor."
15604 (interactive)
15605 (if (not (save-excursion (beginning-of-line)
15606 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15607 (error "ERROR: No primary design unit or directory/project under cursor")
15608 (let ((is-unit (match-string 2))
15609 (unit-name (vhdl-speedbar-line-text))
15610 (vhdl-project (vhdl-speedbar-line-project))
15611 (directory (file-name-as-directory
15612 (or (speedbar-line-file) (speedbar-line-directory)))))
15613 (if (fboundp 'speedbar-select-attached-frame)
15614 (speedbar-select-attached-frame)
15615 (select-frame speedbar-attached-frame))
15616 (let ((default-directory directory))
15617 (vhdl-make (and is-unit unit-name))))))
15619 (defun vhdl-speedbar-generate-makefile ()
15620 "Generate Makefile for directory/project under the cursor."
15621 (interactive)
15622 (let ((vhdl-project (vhdl-speedbar-line-project))
15623 (default-directory (file-name-as-directory
15624 (or (speedbar-line-file) (speedbar-line-directory)))))
15625 (vhdl-generate-makefile)))
15627 (defun vhdl-speedbar-check-unit (design-unit)
15628 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15629 expansion function)."
15630 (save-excursion
15631 (speedbar-position-cursor-on-line)
15632 (cond ((eq design-unit 'entity)
15633 (memq (get-text-property (match-end 0) 'face)
15634 '(vhdl-speedbar-entity-face
15635 vhdl-speedbar-entity-selected-face)))
15636 ((eq design-unit 'architecture)
15637 (memq (get-text-property (match-end 0) 'face)
15638 '(vhdl-speedbar-architecture-face
15639 vhdl-speedbar-architecture-selected-face)))
15640 ((eq design-unit 'subprogram)
15641 (eq (get-text-property (match-end 0) 'face)
15642 'vhdl-speedbar-subprogram-face))
15643 (t nil))))
15645 (defun vhdl-speedbar-set-depth (depth)
15646 "Set hierarchy display depth to DEPTH and refresh speedbar."
15647 (setq vhdl-speedbar-hierarchy-depth depth)
15648 (speedbar-refresh))
15650 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15651 ;; Fontification
15653 (defface vhdl-speedbar-entity-face
15654 '((((class color) (background light)) (:foreground "ForestGreen"))
15655 (((class color) (background dark)) (:foreground "PaleGreen")))
15656 "Face used for displaying entity names."
15657 :group 'speedbar-faces)
15659 (defface vhdl-speedbar-architecture-face
15660 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15661 (((class color) (background light)) (:foreground "Blue"))
15663 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15664 "Face used for displaying architecture names."
15665 :group 'speedbar-faces)
15667 (defface vhdl-speedbar-configuration-face
15668 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15669 (((class color) (background dark)) (:foreground "Salmon")))
15670 "Face used for displaying configuration names."
15671 :group 'speedbar-faces)
15673 (defface vhdl-speedbar-package-face
15674 '((((class color) (background light)) (:foreground "Grey50"))
15675 (((class color) (background dark)) (:foreground "Grey80")))
15676 "Face used for displaying package names."
15677 :group 'speedbar-faces)
15679 (defface vhdl-speedbar-library-face
15680 '((((class color) (background light)) (:foreground "Purple"))
15681 (((class color) (background dark)) (:foreground "Orchid1")))
15682 "Face used for displaying library names."
15683 :group 'speedbar-faces)
15685 (defface vhdl-speedbar-instantiation-face
15686 '((((class color) (background light)) (:foreground "Brown"))
15687 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15688 (((class color) (background dark)) (:foreground "Yellow")))
15689 "Face used for displaying instantiation names."
15690 :group 'speedbar-faces)
15692 (defface vhdl-speedbar-subprogram-face
15693 '((((class color) (background light)) (:foreground "Orchid4"))
15694 (((class color) (background dark)) (:foreground "BurlyWood2")))
15695 "Face used for displaying subprogram names."
15696 :group 'speedbar-faces)
15698 (defface vhdl-speedbar-entity-selected-face
15699 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15700 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15701 "Face used for displaying entity names."
15702 :group 'speedbar-faces)
15704 (defface vhdl-speedbar-architecture-selected-face
15705 '((((min-colors 88) (class color) (background light)) (:foreground
15706 "Blue1" :underline t))
15707 (((class color) (background light)) (:foreground "Blue" :underline t))
15708 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15709 "Face used for displaying architecture names."
15710 :group 'speedbar-faces)
15712 (defface vhdl-speedbar-configuration-selected-face
15713 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15714 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15715 "Face used for displaying configuration names."
15716 :group 'speedbar-faces)
15718 (defface vhdl-speedbar-package-selected-face
15719 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15720 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15721 "Face used for displaying package names."
15722 :group 'speedbar-faces)
15724 (defface vhdl-speedbar-instantiation-selected-face
15725 '((((class color) (background light)) (:foreground "Brown" :underline t))
15726 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15727 "Face used for displaying instantiation names."
15728 :group 'speedbar-faces)
15730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15731 ;; Initialization
15733 ;; add speedbar
15734 (when (fboundp 'speedbar)
15735 (condition-case ()
15736 (when (and vhdl-speedbar-auto-open
15737 (not (and (boundp 'speedbar-frame)
15738 (frame-live-p speedbar-frame))))
15739 (speedbar-frame-mode 1)
15740 (if (fboundp 'speedbar-select-attached-frame)
15741 (speedbar-select-attached-frame)
15742 (select-frame speedbar-attached-frame)))
15743 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15745 ;; initialize speedbar
15746 (if (not (boundp 'speedbar-frame))
15747 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15748 (vhdl-speedbar-initialize)
15749 (when speedbar-frame (vhdl-speedbar-refresh)))
15752 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15753 ;;; Structural composition
15754 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15756 (defun vhdl-get-components-package-name ()
15757 "Return the name of the components package."
15758 (let ((project (vhdl-project-p)))
15759 (if project
15760 (vhdl-replace-string (car vhdl-components-package-name)
15761 (subst-char-in-string ? ?_ project))
15762 (cdr vhdl-components-package-name))))
15764 (defun vhdl-compose-new-component ()
15765 "Create entity and architecture for new component."
15766 (interactive)
15767 (let* ((case-fold-search t)
15768 (ent-name (read-from-minibuffer "entity name: "
15769 nil vhdl-minibuffer-local-map))
15770 (arch-name
15771 (if (equal (cdr vhdl-compose-architecture-name) "")
15772 (read-from-minibuffer "architecture name: "
15773 nil vhdl-minibuffer-local-map)
15774 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15775 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
15776 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15777 ;; open entity file
15778 (unless (eq vhdl-compose-create-files 'none)
15779 (setq ent-file-name
15780 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15781 "." (file-name-extension (buffer-file-name))))
15782 (when (and (file-exists-p ent-file-name)
15783 (not (y-or-n-p (concat "File \"" ent-file-name
15784 "\" exists; overwrite? "))))
15785 (error "ERROR: Creating component...aborted"))
15786 (find-file ent-file-name)
15787 (erase-buffer)
15788 (set-buffer-modified-p nil))
15789 ;; insert header
15790 (if vhdl-compose-include-header
15791 (progn (vhdl-template-header)
15792 (setq end-pos (point))
15793 (goto-char (point-max)))
15794 (vhdl-comment-display-line) (insert "\n\n"))
15795 ;; insert library clause
15796 (vhdl-template-package-std-logic-1164)
15797 (when vhdl-use-components-package
15798 (insert "\n")
15799 (vhdl-template-standard-package (vhdl-work-library)
15800 (vhdl-get-components-package-name)))
15801 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15802 ;; insert entity declaration
15803 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15804 (vhdl-insert-keyword " IS\n")
15805 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15806 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15807 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15808 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15809 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15810 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15811 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15812 (vhdl-insert-keyword "END ")
15813 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15814 (insert ent-name ";\n\n")
15815 (vhdl-comment-display-line) (insert "\n")
15816 ;; open architecture file
15817 (if (not (eq vhdl-compose-create-files 'separate))
15818 (insert "\n")
15819 (goto-char (or end-pos (point-min)))
15820 (setq ent-buffer (current-buffer))
15821 (setq arch-file-name
15822 (concat (vhdl-replace-string vhdl-architecture-file-name
15823 (concat ent-name " " arch-name) t)
15824 "." (file-name-extension (buffer-file-name))))
15825 (when (and (file-exists-p arch-file-name)
15826 (not (y-or-n-p (concat "File \"" arch-file-name
15827 "\" exists; overwrite? "))))
15828 (error "ERROR: Creating component...aborted"))
15829 (find-file arch-file-name)
15830 (erase-buffer)
15831 (set-buffer-modified-p nil)
15832 ;; insert header
15833 (if vhdl-compose-include-header
15834 (progn (vhdl-template-header)
15835 (goto-char (point-max)))
15836 (vhdl-comment-display-line) (insert "\n\n")))
15837 ;; insert architecture body
15838 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15839 (vhdl-insert-keyword " OF ") (insert ent-name)
15840 (vhdl-insert-keyword " IS\n\n")
15841 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15842 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15843 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15844 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15845 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15846 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15847 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15848 (vhdl-insert-keyword "BEGIN")
15849 (when vhdl-self-insert-comments
15850 (insert " -- ")
15851 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15852 (insert arch-name))
15853 (insert "\n\n")
15854 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15855 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15856 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15857 (vhdl-insert-keyword "END ")
15858 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15859 (insert arch-name ";\n\n")
15860 ;; insert footer and save
15861 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15862 (vhdl-template-footer)
15863 (vhdl-comment-display-line) (insert "\n"))
15864 (goto-char (or end-pos (point-min)))
15865 (setq arch-buffer (current-buffer))
15866 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15867 (set-buffer arch-buffer) (save-buffer)
15868 (message "%s"
15869 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15870 (and ent-file-name
15871 (format "\n File created: \"%s\"" ent-file-name))
15872 (and arch-file-name
15873 (format "\n File created: \"%s\"" arch-file-name))))))
15875 (defun vhdl-compose-place-component ()
15876 "Place new component by pasting current port as component declaration and
15877 component instantiation."
15878 (interactive)
15879 (if (not vhdl-port-list)
15880 (error "ERROR: No port has been read")
15881 (save-excursion
15882 (vhdl-prepare-search-2
15883 (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)
15884 (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))
15885 (error "ERROR: No architecture found"))
15886 (let* ((ent-name (match-string 1))
15887 (ent-file-name
15888 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15889 "." (file-name-extension (buffer-file-name))))
15890 (orig-buffer (current-buffer)))
15891 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15892 ;; place component declaration
15893 (unless (or vhdl-use-components-package
15894 (vhdl-use-direct-instantiation)
15895 (save-excursion
15896 (re-search-forward
15897 (concat "^\\s-*component\\s-+"
15898 (car vhdl-port-list) "\\>") nil t)))
15899 (re-search-forward "^begin\\>" nil)
15900 (beginning-of-line)
15901 (skip-chars-backward " \t\n\r\f")
15902 (insert "\n\n") (indent-to vhdl-basic-offset)
15903 (vhdl-port-paste-component t))
15904 ;; place component instantiation
15905 (re-search-forward "^end\\>" nil)
15906 (beginning-of-line)
15907 (skip-chars-backward " \t\n\r\f")
15908 (insert "\n\n") (indent-to vhdl-basic-offset)
15909 (vhdl-port-paste-instance nil t t)
15910 ;; place use clause for used packages
15911 (when (nth 3 vhdl-port-list)
15912 ;; open entity file
15913 (when (file-exists-p ent-file-name)
15914 (find-file ent-file-name))
15915 (goto-char (point-min))
15916 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
15917 (error "ERROR: Entity not found: \"%s\"" ent-name))
15918 (goto-char (match-beginning 0))
15919 (if (and (save-excursion
15920 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15921 (match-string 1))
15922 (progn (goto-char (match-end 0))
15923 (beginning-of-line 2))
15924 (insert "\n")
15925 (backward-char))
15926 (vhdl-port-paste-context-clause)
15927 (switch-to-buffer orig-buffer))
15928 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15930 (defun vhdl-compose-wire-components ()
15931 "Connect components."
15932 (interactive)
15933 (save-excursion
15934 (vhdl-prepare-search-2
15935 (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)
15936 (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))
15937 (error "ERROR: No architecture found"))
15938 (let* ((ent-name (match-string 1))
15939 (ent-file-name
15940 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
15941 "." (file-name-extension (buffer-file-name))))
15942 (arch-decl-pos (point-marker))
15943 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15944 (arch-end-pos (re-search-forward "^end\\>" nil))
15945 (pack-name (vhdl-get-components-package-name))
15946 (pack-file-name
15947 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
15948 "." (file-name-extension (buffer-file-name))))
15949 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15950 port-alist generic-alist inst-alist
15951 signal-name signal-entry signal-alist local-list written-list
15952 single-in-list multi-in-list single-out-list multi-out-list
15953 constant-name constant-entry constant-alist single-list multi-list
15954 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15955 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15956 signal-beg-pos signal-pos
15957 constant-temp-pos port-temp-pos signal-temp-pos)
15958 (message "Wiring components...")
15959 ;; process all instances
15960 (goto-char arch-stat-pos)
15961 (while (re-search-forward
15962 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
15963 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
15964 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
15965 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
15966 "[ \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)
15967 (setq inst-name (match-string-no-properties 1)
15968 comp-name (match-string-no-properties 4)
15969 comp-ent-name (match-string-no-properties 12)
15970 has-generic (or (match-string 7) (match-string 17)))
15971 ;; get port ...
15972 (if comp-name
15973 ;; ... from component declaration
15974 (vhdl-visit-file
15975 (when vhdl-use-components-package pack-file-name) t
15976 (save-excursion
15977 (goto-char (point-min))
15978 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
15979 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15980 (vhdl-port-copy)))
15981 ;; ... from entity declaration (direct instantiation)
15982 (setq comp-ent-file-name
15983 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
15984 "." (file-name-extension (buffer-file-name))))
15985 (vhdl-visit-file
15986 comp-ent-file-name t
15987 (save-excursion
15988 (goto-char (point-min))
15989 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
15990 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15991 (vhdl-port-copy))))
15992 (vhdl-port-flatten t)
15993 (setq generic-alist (nth 1 vhdl-port-list)
15994 port-alist (nth 2 vhdl-port-list)
15995 vhdl-port-list nil)
15996 (setq constant-alist nil
15997 signal-alist nil)
15998 (when has-generic
15999 ;; process all constants in generic map
16000 (vhdl-forward-syntactic-ws)
16001 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16002 (setq constant-name (match-string-no-properties 3))
16003 (setq constant-entry
16004 (cons constant-name
16005 (if (match-string 1)
16006 (or (aget generic-alist (match-string 2) t)
16007 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16008 (cdar generic-alist))))
16009 (setq constant-alist (cons constant-entry constant-alist))
16010 (setq constant-name (downcase constant-name))
16011 (if (or (member constant-name single-list)
16012 (member constant-name multi-list))
16013 (progn (setq single-list (delete constant-name single-list))
16014 (add-to-list 'multi-list constant-name))
16015 (add-to-list 'single-list constant-name))
16016 (unless (match-string 1)
16017 (setq generic-alist (cdr generic-alist)))
16018 (vhdl-forward-syntactic-ws))
16019 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
16020 ;; process all signals in port map
16021 (vhdl-forward-syntactic-ws)
16022 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
16023 (setq signal-name (match-string-no-properties 3))
16024 (setq signal-entry (cons signal-name
16025 (if (match-string 1)
16026 (or (aget port-alist (match-string 2) t)
16027 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
16028 (cdar port-alist))))
16029 (setq signal-alist (cons signal-entry signal-alist))
16030 (setq signal-name (downcase signal-name))
16031 (if (equal (upcase (nth 2 signal-entry)) "IN")
16032 ;; input signal
16033 (cond
16034 ((member signal-name local-list)
16035 nil)
16036 ((or (member signal-name single-out-list)
16037 (member signal-name multi-out-list))
16038 (setq single-out-list (delete signal-name single-out-list))
16039 (setq multi-out-list (delete signal-name multi-out-list))
16040 (add-to-list 'local-list signal-name))
16041 ((member signal-name single-in-list)
16042 (setq single-in-list (delete signal-name single-in-list))
16043 (add-to-list 'multi-in-list signal-name))
16044 ((not (member signal-name multi-in-list))
16045 (add-to-list 'single-in-list signal-name)))
16046 ;; output signal
16047 (cond
16048 ((member signal-name local-list)
16049 nil)
16050 ((or (member signal-name single-in-list)
16051 (member signal-name multi-in-list))
16052 (setq single-in-list (delete signal-name single-in-list))
16053 (setq multi-in-list (delete signal-name multi-in-list))
16054 (add-to-list 'local-list signal-name))
16055 ((member signal-name single-out-list)
16056 (setq single-out-list (delete signal-name single-out-list))
16057 (add-to-list 'multi-out-list signal-name))
16058 ((not (member signal-name multi-out-list))
16059 (add-to-list 'single-out-list signal-name))))
16060 (unless (match-string 1)
16061 (setq port-alist (cdr port-alist)))
16062 (vhdl-forward-syntactic-ws))
16063 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
16064 (nreverse signal-alist)) inst-alist)))
16065 ;; prepare signal insertion
16066 (vhdl-goto-marker arch-decl-pos)
16067 (forward-line 1)
16068 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
16069 (setq signal-pos (point-marker))
16070 (while (progn (vhdl-forward-syntactic-ws)
16071 (looking-at "signal\\>"))
16072 (beginning-of-line 2)
16073 (delete-region signal-pos (point)))
16074 (setq signal-beg-pos signal-pos)
16075 ;; open entity file
16076 (when (file-exists-p ent-file-name)
16077 (find-file ent-file-name))
16078 (goto-char (point-min))
16079 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
16080 (error "ERROR: Entity not found: \"%s\"" ent-name))
16081 ;; prepare generic clause insertion
16082 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16083 (match-string 1))
16084 (goto-char (match-beginning 0))
16085 (indent-to vhdl-basic-offset)
16086 (insert "generic ();\n\n")
16087 (backward-char 4))
16088 (backward-char)
16089 (setq generic-pos (point-marker))
16090 (forward-sexp) (end-of-line)
16091 (delete-region generic-pos (point)) (delete-char 1)
16092 (insert "(\n")
16093 (when multi-list
16094 (insert "\n")
16095 (indent-to (* 2 vhdl-basic-offset))
16096 (insert "-- global generics\n"))
16097 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
16098 generic-inst-pos (point-marker) generic-end-pos (point-marker))
16099 ;; prepare port clause insertion
16100 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
16101 (match-string 1))
16102 (goto-char (match-beginning 0))
16103 (indent-to vhdl-basic-offset)
16104 (insert "port ();\n\n")
16105 (backward-char 4))
16106 (backward-char)
16107 (setq port-in-pos (point-marker))
16108 (forward-sexp) (end-of-line)
16109 (delete-region port-in-pos (point)) (delete-char 1)
16110 (insert "(\n")
16111 (when (or multi-in-list multi-out-list)
16112 (insert "\n")
16113 (indent-to (* 2 vhdl-basic-offset))
16114 (insert "-- global ports\n"))
16115 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
16116 port-out-pos (point-marker) port-inst-pos (point-marker)
16117 port-end-pos (point-marker))
16118 ;; insert generics, ports and signals
16119 (setq inst-alist (nreverse inst-alist))
16120 (while inst-alist
16121 (setq inst-name (nth 0 (car inst-alist))
16122 constant-alist (nth 1 (car inst-alist))
16123 signal-alist (nth 2 (car inst-alist))
16124 constant-temp-pos generic-inst-pos
16125 port-temp-pos port-inst-pos
16126 signal-temp-pos signal-pos)
16127 ;; generics
16128 (while constant-alist
16129 (setq constant-name (downcase (caar constant-alist))
16130 constant-entry (car constant-alist))
16131 (cond ((member constant-name written-list)
16132 nil)
16133 ((member constant-name multi-list)
16134 (vhdl-goto-marker generic-pos)
16135 (setq generic-end-pos
16136 (vhdl-max-marker
16137 generic-end-pos
16138 (vhdl-compose-insert-generic constant-entry)))
16139 (setq generic-pos (point-marker))
16140 (add-to-list 'written-list constant-name))
16142 (vhdl-goto-marker
16143 (vhdl-max-marker generic-inst-pos generic-pos))
16144 (setq generic-end-pos
16145 (vhdl-compose-insert-generic constant-entry))
16146 (setq generic-inst-pos (point-marker))
16147 (add-to-list 'written-list constant-name)))
16148 (setq constant-alist (cdr constant-alist)))
16149 (when (/= constant-temp-pos generic-inst-pos)
16150 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
16151 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16152 (insert "-- generics for \"" inst-name "\"\n")
16153 (vhdl-goto-marker generic-inst-pos))
16154 ;; ports and signals
16155 (while signal-alist
16156 (setq signal-name (downcase (caar signal-alist))
16157 signal-entry (car signal-alist))
16158 (cond ((member signal-name written-list)
16159 nil)
16160 ((member signal-name multi-in-list)
16161 (vhdl-goto-marker port-in-pos)
16162 (setq port-end-pos
16163 (vhdl-max-marker
16164 port-end-pos (vhdl-compose-insert-port signal-entry)))
16165 (setq port-in-pos (point-marker))
16166 (add-to-list 'written-list signal-name))
16167 ((member signal-name multi-out-list)
16168 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
16169 (setq port-end-pos
16170 (vhdl-max-marker
16171 port-end-pos (vhdl-compose-insert-port signal-entry)))
16172 (setq port-out-pos (point-marker))
16173 (add-to-list 'written-list signal-name))
16174 ((or (member signal-name single-in-list)
16175 (member signal-name single-out-list))
16176 (vhdl-goto-marker
16177 (vhdl-max-marker
16178 port-inst-pos
16179 (vhdl-max-marker port-out-pos port-in-pos)))
16180 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
16181 (setq port-inst-pos (point-marker))
16182 (add-to-list 'written-list signal-name))
16183 ((equal (upcase (nth 2 signal-entry)) "OUT")
16184 (vhdl-goto-marker signal-pos)
16185 (vhdl-compose-insert-signal signal-entry)
16186 (setq signal-pos (point-marker))
16187 (add-to-list 'written-list signal-name)))
16188 (setq signal-alist (cdr signal-alist)))
16189 (when (/= port-temp-pos port-inst-pos)
16190 (vhdl-goto-marker
16191 (vhdl-max-marker port-temp-pos
16192 (vhdl-max-marker port-in-pos port-out-pos)))
16193 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16194 (insert "-- ports to \"" inst-name "\"\n")
16195 (vhdl-goto-marker port-inst-pos))
16196 (when (/= signal-temp-pos signal-pos)
16197 (vhdl-goto-marker signal-temp-pos)
16198 (insert "\n") (indent-to vhdl-basic-offset)
16199 (insert "-- outputs of \"" inst-name "\"\n")
16200 (vhdl-goto-marker signal-pos))
16201 (setq inst-alist (cdr inst-alist)))
16202 ;; finalize generic/port clause
16203 (vhdl-goto-marker generic-end-pos) (backward-char)
16204 (when (= generic-beg-pos generic-end-pos)
16205 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16206 (insert ";") (backward-char))
16207 (insert ")")
16208 (vhdl-goto-marker port-end-pos) (backward-char)
16209 (when (= port-beg-pos port-end-pos)
16210 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
16211 (insert ";") (backward-char))
16212 (insert ")")
16213 ;; align everything
16214 (when vhdl-auto-align
16215 (vhdl-goto-marker generic-beg-pos)
16216 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
16217 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
16218 (vhdl-goto-marker signal-beg-pos)
16219 (vhdl-align-region-groups signal-beg-pos signal-pos))
16220 (switch-to-buffer (marker-buffer signal-beg-pos))
16221 (message "Wiring components...done")))))
16223 (defun vhdl-compose-insert-generic (entry)
16224 "Insert ENTRY as generic declaration."
16225 (let (pos)
16226 (indent-to (* 2 vhdl-basic-offset))
16227 (insert (nth 0 entry) " : " (nth 1 entry))
16228 (when (nth 2 entry)
16229 (insert " := " (nth 2 entry)))
16230 (insert ";")
16231 (setq pos (point-marker))
16232 (when (and vhdl-include-port-comments (nth 3 entry))
16233 (vhdl-comment-insert-inline (nth 3 entry) t))
16234 (insert "\n")
16235 pos))
16237 (defun vhdl-compose-insert-port (entry)
16238 "Insert ENTRY as port declaration."
16239 (let (pos)
16240 (indent-to (* 2 vhdl-basic-offset))
16241 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
16242 (setq pos (point-marker))
16243 (when (and vhdl-include-port-comments (nth 4 entry))
16244 (vhdl-comment-insert-inline (nth 4 entry) t))
16245 (insert "\n")
16246 pos))
16248 (defun vhdl-compose-insert-signal (entry)
16249 "Insert ENTRY as signal declaration."
16250 (indent-to vhdl-basic-offset)
16251 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
16252 (when (and vhdl-include-port-comments (nth 4 entry))
16253 (vhdl-comment-insert-inline (nth 4 entry) t))
16254 (insert "\n"))
16256 (defun vhdl-compose-components-package ()
16257 "Generate a package containing component declarations for all entities in the
16258 current project/directory."
16259 (interactive)
16260 (vhdl-require-hierarchy-info)
16261 (let* ((project (vhdl-project-p))
16262 (pack-name (vhdl-get-components-package-name))
16263 (pack-file-name
16264 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
16265 "." (file-name-extension (buffer-file-name))))
16266 (ent-alist (aget vhdl-entity-alist
16267 (or project default-directory) t))
16268 (lazy-lock-minimum-size 0)
16269 clause-pos component-pos)
16270 (message "Generating components package \"%s\"..." pack-name)
16271 ;; open package file
16272 (when (and (file-exists-p pack-file-name)
16273 (not (y-or-n-p (concat "File \"" pack-file-name
16274 "\" exists; overwrite? "))))
16275 (error "ERROR: Generating components package...aborted"))
16276 (find-file pack-file-name)
16277 (erase-buffer)
16278 ;; insert header
16279 (if vhdl-compose-include-header
16280 (progn (vhdl-template-header
16281 (concat "Components package (generated by Emacs VHDL Mode "
16282 vhdl-version ")"))
16283 (goto-char (point-max)))
16284 (vhdl-comment-display-line) (insert "\n\n"))
16285 ;; insert std_logic_1164 package
16286 (vhdl-template-package-std-logic-1164)
16287 (insert "\n") (setq clause-pos (point-marker))
16288 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16289 ;; insert package declaration
16290 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
16291 (vhdl-insert-keyword " IS\n\n")
16292 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
16293 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
16294 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
16295 (indent-to vhdl-basic-offset)
16296 (setq component-pos (point-marker))
16297 (insert "\n\n") (vhdl-insert-keyword "END ")
16298 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16299 (insert pack-name ";\n\n")
16300 ;; insert footer
16301 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16302 (vhdl-template-footer)
16303 (vhdl-comment-display-line) (insert "\n"))
16304 ;; insert component declarations
16305 (while ent-alist
16306 (vhdl-visit-file (nth 2 (car ent-alist)) nil
16307 (progn (goto-char (point-min))
16308 (forward-line (1- (nth 3 (car ent-alist))))
16309 (end-of-line)
16310 (vhdl-port-copy)))
16311 (goto-char component-pos)
16312 (vhdl-port-paste-component t)
16313 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
16314 (setq component-pos (point-marker))
16315 (goto-char clause-pos)
16316 (vhdl-port-paste-context-clause pack-name)
16317 (setq clause-pos (point-marker))
16318 (setq ent-alist (cdr ent-alist)))
16319 (goto-char (point-min))
16320 (save-buffer)
16321 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16322 pack-name pack-file-name)))
16324 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16325 conf-alist inst-alist
16326 &optional insert-conf)
16327 "Generate block configuration for architecture."
16328 (let ((margin (current-indentation))
16329 (beg (point-at-bol))
16330 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
16331 ;; insert block configuration (for architecture)
16332 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
16333 (setq margin (+ margin vhdl-basic-offset))
16334 ;; process all instances
16335 (while inst-alist
16336 (setq inst-entry (car inst-alist))
16337 ;; is component?
16338 (when (nth 4 inst-entry)
16339 (setq insert-conf t)
16340 (setq inst-path (nth 9 inst-entry))
16341 ;; skip common path with previous instance
16342 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
16343 (setq inst-path (cdr inst-path)
16344 inst-prev-path (cdr inst-prev-path)))
16345 ;; insert block configuration end (for previous block/generate)
16346 (while inst-prev-path
16347 (setq margin (- margin vhdl-basic-offset))
16348 (indent-to margin)
16349 (vhdl-insert-keyword "END FOR;\n")
16350 (setq inst-prev-path (cdr inst-prev-path)))
16351 ;; insert block configuration beginning (for current block/generate)
16352 (indent-to margin)
16353 (while inst-path
16354 (setq margin (+ margin vhdl-basic-offset))
16355 (vhdl-insert-keyword "FOR ")
16356 (insert (car inst-path) "\n")
16357 (indent-to margin)
16358 (setq inst-path (cdr inst-path)))
16359 ;; insert component configuration beginning
16360 (vhdl-insert-keyword "FOR ")
16361 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
16362 ;; find subconfiguration
16363 (setq conf-key (nth 7 inst-entry))
16364 (setq tmp-alist conf-alist)
16365 ;; use first configuration found for instance's entity
16366 (while (and tmp-alist (null conf-key))
16367 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
16368 (setq conf-key (nth 0 (car tmp-alist))))
16369 (setq tmp-alist (cdr tmp-alist)))
16370 (setq conf-entry (aget conf-alist conf-key t))
16371 ;; insert binding indication ...
16372 ;; ... with subconfiguration (if exists)
16373 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16374 (progn
16375 (indent-to (+ margin vhdl-basic-offset))
16376 (vhdl-insert-keyword "USE CONFIGURATION ")
16377 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16378 (insert ";\n"))
16379 ;; ... with entity (if exists)
16380 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16381 (when ent-entry
16382 (indent-to (+ margin vhdl-basic-offset))
16383 (vhdl-insert-keyword "USE ENTITY ")
16384 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16385 ;; insert architecture name (if architecture exists)
16386 (when (nth 3 ent-entry)
16387 (setq arch-name
16388 ;; choose architecture name a) from configuration,
16389 ;; b) from mra, or c) from first architecture
16390 (or (nth 0 (aget (nth 3 ent-entry)
16391 (or (nth 6 inst-entry)
16392 (nth 4 ent-entry)) t))
16393 (nth 1 (car (nth 3 ent-entry)))))
16394 (insert "(" arch-name ")"))
16395 (insert ";\n")
16396 ;; insert block configuration (for architecture of subcomponent)
16397 (when (and vhdl-compose-configuration-hierarchical
16398 (nth 3 ent-entry))
16399 (indent-to (+ margin vhdl-basic-offset))
16400 (vhdl-compose-configuration-architecture
16401 (nth 0 ent-entry) arch-name ent-alist conf-alist
16402 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16403 ;; insert component configuration end
16404 (indent-to margin)
16405 (vhdl-insert-keyword "END FOR;\n")
16406 (setq inst-prev-path (nth 9 inst-entry)))
16407 (setq inst-alist (cdr inst-alist)))
16408 ;; insert block configuration end (for block/generate)
16409 (while inst-prev-path
16410 (setq margin (- margin vhdl-basic-offset))
16411 (indent-to margin)
16412 (vhdl-insert-keyword "END FOR;\n")
16413 (setq inst-prev-path (cdr inst-prev-path)))
16414 (indent-to (- margin vhdl-basic-offset))
16415 ;; insert block configuration end or remove beginning (for architecture)
16416 (if insert-conf
16417 (vhdl-insert-keyword "END FOR;\n")
16418 (delete-region beg (point)))))
16420 (defun vhdl-compose-configuration (&optional ent-name arch-name)
16421 "Generate configuration declaration."
16422 (interactive)
16423 (vhdl-require-hierarchy-info)
16424 (let ((ent-alist (aget vhdl-entity-alist
16425 (or (vhdl-project-p) default-directory) t))
16426 (conf-alist (aget vhdl-config-alist
16427 (or (vhdl-project-p) default-directory) t))
16428 (from-speedbar ent-name)
16429 inst-alist conf-name conf-file-name pos)
16430 (vhdl-prepare-search-2
16431 ;; get entity and architecture name
16432 (unless ent-name
16433 (save-excursion
16434 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16435 (not (equal "END" (upcase (match-string 1))))
16436 (setq ent-name (match-string-no-properties 3))
16437 (setq arch-name (match-string-no-properties 2)))
16438 (error "ERROR: Not within an architecture"))))
16439 (setq conf-name (vhdl-replace-string
16440 vhdl-compose-configuration-name
16441 (concat ent-name " " arch-name)))
16442 (setq inst-alist
16443 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16444 (downcase arch-name) t))))
16445 (message "Generating configuration \"%s\"..." conf-name)
16446 (if vhdl-compose-configuration-create-file
16447 ;; open configuration file
16448 (progn
16449 (setq conf-file-name
16450 (concat (vhdl-replace-string vhdl-configuration-file-name
16451 conf-name t)
16452 "." (file-name-extension (buffer-file-name))))
16453 (when (and (file-exists-p conf-file-name)
16454 (not (y-or-n-p (concat "File \"" conf-file-name
16455 "\" exists; overwrite? "))))
16456 (error "ERROR: Creating configuration...aborted"))
16457 (find-file conf-file-name)
16458 (erase-buffer)
16459 (set-buffer-modified-p nil)
16460 ;; insert header
16461 (if vhdl-compose-include-header
16462 (progn (vhdl-template-header
16463 (concat "Configuration declaration for design \""
16464 ent-name "(" arch-name ")\""))
16465 (goto-char (point-max)))
16466 (vhdl-comment-display-line) (insert "\n\n")))
16467 ;; goto end of architecture
16468 (unless from-speedbar
16469 (re-search-forward "^end\\>" nil)
16470 (end-of-line) (insert "\n\n")
16471 (vhdl-comment-display-line) (insert "\n\n")))
16472 ;; insert library clause
16473 (setq pos (point))
16474 (vhdl-template-standard-package (vhdl-work-library) nil)
16475 (when (/= pos (point))
16476 (insert "\n\n"))
16477 ;; insert configuration
16478 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16479 (vhdl-insert-keyword " OF ") (insert ent-name)
16480 (vhdl-insert-keyword " IS\n")
16481 (indent-to vhdl-basic-offset)
16482 ;; insert block configuration (for architecture)
16483 (vhdl-compose-configuration-architecture
16484 ent-name arch-name ent-alist conf-alist inst-alist t)
16485 (vhdl-insert-keyword "END ") (insert conf-name ";")
16486 (when conf-file-name
16487 ;; insert footer and save
16488 (insert "\n\n")
16489 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16490 (vhdl-template-footer)
16491 (vhdl-comment-display-line) (insert "\n"))
16492 (save-buffer))
16493 (message "%s"
16494 (concat (format "Generating configuration \"%s\"...done" conf-name)
16495 (and conf-file-name
16496 (format "\n File created: \"%s\"" conf-file-name))))))
16499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16500 ;;; Compilation / Makefile generation
16501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16502 ;; (using `compile.el')
16504 (defvar vhdl-compile-post-command ""
16505 "String appended to compile command after file name.")
16507 (defun vhdl-makefile-name ()
16508 "Return the Makefile name of the current project or the current compiler if
16509 no project is defined."
16510 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16511 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16512 (vhdl-replace-string
16513 (cons "\\(.*\\)\n\\(.*\\)"
16514 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16515 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16517 (defun vhdl-compile-directory ()
16518 "Return the directory where compilation/make should be run."
16519 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16520 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16521 (directory (vhdl-resolve-env-variable
16522 (if project
16523 (vhdl-replace-string
16524 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16525 (nth 6 compiler)))))
16526 (file-name-as-directory
16527 (if (file-name-absolute-p directory)
16528 directory
16529 (expand-file-name directory (vhdl-default-directory))))))
16531 (defun vhdl-uniquify (in-list)
16532 "Remove duplicate elements from IN-LIST."
16533 (let (out-list)
16534 (while in-list
16535 (add-to-list 'out-list (car in-list))
16536 (setq in-list (cdr in-list)))
16537 out-list))
16539 (defun vhdl-set-compiler (name)
16540 "Set current compiler to NAME."
16541 (interactive
16542 (list (let ((completion-ignore-case t))
16543 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16544 (if (assoc name vhdl-compiler-alist)
16545 (progn (setq vhdl-compiler name)
16546 (message "Current compiler: \"%s\"" vhdl-compiler))
16547 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16550 ;; Compilation
16552 (defun vhdl-compile-init ()
16553 "Initialize for compilation."
16554 (when (or (null compilation-error-regexp-alist)
16555 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16556 compilation-error-regexp-alist)))
16557 ;; `compilation-error-regexp-alist'
16558 (let ((commands-alist vhdl-compiler-alist)
16559 regexp-alist sublist)
16560 (while commands-alist
16561 (setq sublist (nth 11 (car commands-alist)))
16562 (unless (or (equal "" (car sublist))
16563 (assoc (car sublist) regexp-alist))
16564 (setq regexp-alist (cons (list (nth 0 sublist)
16565 (if (= 0 (nth 1 sublist))
16566 (if (featurep 'xemacs) 9 nil)
16567 (nth 1 sublist))
16568 (nth 2 sublist) (nth 3 sublist))
16569 regexp-alist)))
16570 (setq commands-alist (cdr commands-alist)))
16571 (setq compilation-error-regexp-alist
16572 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16573 ;; `compilation-file-regexp-alist'
16574 (let ((commands-alist vhdl-compiler-alist)
16575 regexp-alist sublist)
16576 ;; matches vhdl-mode file name output
16577 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16578 (while commands-alist
16579 (setq sublist (nth 12 (car commands-alist)))
16580 (unless (or (equal "" (car sublist))
16581 (assoc (car sublist) regexp-alist))
16582 (setq regexp-alist (cons sublist regexp-alist)))
16583 (setq commands-alist (cdr commands-alist)))
16584 (setq compilation-file-regexp-alist
16585 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16587 (defvar vhdl-compile-file-name nil
16588 "Name of file to be compiled.")
16590 (defun vhdl-compile-print-file-name ()
16591 "Function called within `compile' to print out file name for compilers that
16592 do not print any file names."
16593 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16595 (defun vhdl-get-compile-options (project compiler file-name
16596 &optional file-options-only)
16597 "Get compiler options. Returning nil means do not compile this file."
16598 (let* ((compiler-options (nth 1 compiler))
16599 (project-entry (aget (nth 4 project) vhdl-compiler))
16600 (project-options (nth 0 project-entry))
16601 (exception-list (and file-name (nth 2 project-entry)))
16602 (work-library (vhdl-work-library))
16603 (case-fold-search nil)
16604 file-options)
16605 (while (and exception-list
16606 (not (string-match (caar exception-list) file-name)))
16607 (setq exception-list (cdr exception-list)))
16608 (if (and exception-list (not (cdar exception-list)))
16610 (if (and file-options-only (not exception-list))
16611 'default
16612 (setq file-options (cdar exception-list))
16613 ;; insert library name in compiler-specific options
16614 (setq compiler-options
16615 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16616 work-library))
16617 ;; insert compiler-specific options in project-specific options
16618 (when project-options
16619 (setq project-options
16620 (vhdl-replace-string
16621 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16622 (concat work-library "\n" compiler-options))))
16623 ;; insert project-specific options in file-specific options
16624 (when file-options
16625 (setq file-options
16626 (vhdl-replace-string
16627 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16628 (concat work-library "\n" compiler-options "\n"
16629 project-options))))
16630 ;; return options
16631 (or file-options project-options compiler-options)))))
16633 (defun vhdl-get-make-options (project compiler)
16634 "Get make options."
16635 (let* ((compiler-options (nth 3 compiler))
16636 (project-entry (aget (nth 4 project) vhdl-compiler))
16637 (project-options (nth 1 project-entry))
16638 (makefile-name (vhdl-makefile-name)))
16639 ;; insert Makefile name in compiler-specific options
16640 (setq compiler-options
16641 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16642 makefile-name))
16643 ;; insert compiler-specific options in project-specific options
16644 (when project-options
16645 (setq project-options
16646 (vhdl-replace-string
16647 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16648 (concat makefile-name "\n" compiler-options))))
16649 ;; return options
16650 (or project-options compiler-options)))
16652 (defun vhdl-compile ()
16653 "Compile current buffer using the VHDL compiler specified in
16654 `vhdl-compiler'."
16655 (interactive)
16656 (vhdl-compile-init)
16657 (let* ((project (aget vhdl-project-alist vhdl-project))
16658 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16659 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16660 (command (nth 0 compiler))
16661 (default-directory (vhdl-compile-directory))
16662 (file-name (if vhdl-compile-absolute-path
16663 (buffer-file-name)
16664 (file-relative-name (buffer-file-name))))
16665 (options (vhdl-get-compile-options project compiler file-name))
16666 compilation-process-setup-function)
16667 (unless (file-directory-p default-directory)
16668 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16669 ;; put file name into quotes if it contains spaces
16670 (when (string-match " " file-name)
16671 (setq file-name (concat "\"" file-name "\"")))
16672 ;; print out file name if compiler does not
16673 (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
16674 (buffer-file-name)
16675 (file-relative-name (buffer-file-name))))
16676 (when (and (= 0 (nth 1 (nth 10 compiler)))
16677 (= 0 (nth 1 (nth 11 compiler))))
16678 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16679 ;; run compilation
16680 (if options
16681 (when command
16682 (compile (concat command " " options " " file-name
16683 (unless (equal vhdl-compile-post-command "")
16684 (concat " " vhdl-compile-post-command)))))
16685 (vhdl-warning "Your project settings tell me not to compile this file"))))
16687 (defvar vhdl-make-target "all"
16688 "Default target for `vhdl-make' command.")
16690 (defun vhdl-make (&optional target)
16691 "Call make command for compilation of all updated source files (requires
16692 `Makefile'). Optional argument TARGET allows to compile the design
16693 specified by a target."
16694 (interactive)
16695 (setq vhdl-make-target
16696 (or target (read-from-minibuffer "Target: " vhdl-make-target
16697 vhdl-minibuffer-local-map)))
16698 (vhdl-compile-init)
16699 (let* ((project (aget vhdl-project-alist vhdl-project))
16700 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16701 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16702 (command (nth 2 compiler))
16703 (options (vhdl-get-make-options project compiler))
16704 (default-directory (vhdl-compile-directory)))
16705 (unless (file-directory-p default-directory)
16706 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16707 ;; run make
16708 (compile (concat (if (equal command "") "make" command)
16709 " " options " " vhdl-make-target))))
16711 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16712 ;; Makefile generation
16714 (defun vhdl-generate-makefile ()
16715 "Generate `Makefile'."
16716 (interactive)
16717 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16718 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16719 (command (nth 4 compiler)))
16720 ;; generate makefile
16721 (if command
16722 (let ((default-directory (vhdl-compile-directory)))
16723 (compile (vhdl-replace-string
16724 (cons "\\(.*\\) \\(.*\\)" command)
16725 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16726 (vhdl-generate-makefile-1))))
16728 (defun vhdl-get-packages (lib-alist work-library)
16729 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16730 (let (pack-list)
16731 (while lib-alist
16732 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16733 (setq pack-list (cons (cdar lib-alist) pack-list)))
16734 (setq lib-alist (cdr lib-alist)))
16735 pack-list))
16737 (defun vhdl-generate-makefile-1 ()
16738 "Generate Makefile for current project or directory."
16739 ;; scan hierarchy if required
16740 (if (vhdl-project-p)
16741 (unless (or (assoc vhdl-project vhdl-file-alist)
16742 (vhdl-load-cache vhdl-project))
16743 (vhdl-scan-project-contents vhdl-project))
16744 (let ((directory (abbreviate-file-name default-directory)))
16745 (unless (or (assoc directory vhdl-file-alist)
16746 (vhdl-load-cache directory))
16747 (vhdl-scan-directory-contents directory))))
16748 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16749 (project (vhdl-project-p))
16750 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16751 (conf-alist (aget vhdl-config-alist (or project directory) t))
16752 (pack-alist (aget vhdl-package-alist (or project directory) t))
16753 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16754 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16755 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16756 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16757 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16758 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16759 (adjust-case (nth 5 regexp-list))
16760 (work-library (downcase (vhdl-work-library)))
16761 (compile-directory (expand-file-name (vhdl-compile-directory)
16762 default-directory))
16763 (makefile-name (vhdl-makefile-name))
16764 rule-alist arch-alist inst-alist
16765 target-list depend-list unit-list prim-list second-list subcomp-list
16766 lib-alist lib-body-alist pack-list all-pack-list
16767 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16768 conf-key conf-file-name pack-key pack-file-name
16769 ent-entry arch-entry conf-entry pack-entry inst-entry
16770 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16771 tmp-key tmp-list rule)
16772 ;; check prerequisites
16773 (unless (file-exists-p compile-directory)
16774 (make-directory compile-directory t))
16775 (unless regexp-list
16776 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16777 vhdl-compiler))
16778 (message "Generating makefile \"%s\"..." makefile-name)
16779 ;; rules for all entities
16780 (setq tmp-list ent-alist)
16781 (while ent-alist
16782 (setq ent-entry (car ent-alist)
16783 ent-key (nth 0 ent-entry))
16784 (when (nth 2 ent-entry)
16785 (setq ent-file-name (file-relative-name
16786 (nth 2 ent-entry) compile-directory)
16787 arch-alist (nth 4 ent-entry)
16788 lib-alist (nth 6 ent-entry)
16789 rule (aget rule-alist ent-file-name)
16790 target-list (nth 0 rule)
16791 depend-list (nth 1 rule)
16792 second-list nil
16793 subcomp-list nil)
16794 (setq tmp-key (vhdl-replace-string
16795 ent-regexp (funcall adjust-case ent-key)))
16796 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16797 ;; rule target for this entity
16798 (setq target-list (cons ent-key target-list))
16799 ;; rule dependencies for all used packages
16800 (setq pack-list (vhdl-get-packages lib-alist work-library))
16801 (setq depend-list (append depend-list pack-list))
16802 (setq all-pack-list pack-list)
16803 ;; add rule
16804 (aput 'rule-alist ent-file-name (list target-list depend-list))
16805 ;; rules for all corresponding architectures
16806 (while arch-alist
16807 (setq arch-entry (car arch-alist)
16808 arch-key (nth 0 arch-entry)
16809 ent-arch-key (concat ent-key "-" arch-key)
16810 arch-file-name (file-relative-name (nth 2 arch-entry)
16811 compile-directory)
16812 inst-alist (nth 4 arch-entry)
16813 lib-alist (nth 5 arch-entry)
16814 rule (aget rule-alist arch-file-name)
16815 target-list (nth 0 rule)
16816 depend-list (nth 1 rule))
16817 (setq tmp-key (vhdl-replace-string
16818 arch-regexp
16819 (funcall adjust-case (concat arch-key " " ent-key))))
16820 (setq unit-list
16821 (cons (cons ent-arch-key tmp-key) unit-list))
16822 (setq second-list (cons ent-arch-key second-list))
16823 ;; rule target for this architecture
16824 (setq target-list (cons ent-arch-key target-list))
16825 ;; rule dependency for corresponding entity
16826 (setq depend-list (cons ent-key depend-list))
16827 ;; rule dependencies for contained component instantiations
16828 (while inst-alist
16829 (setq inst-entry (car inst-alist))
16830 (when (or (null (nth 8 inst-entry))
16831 (equal (downcase (nth 8 inst-entry)) work-library))
16832 (setq inst-ent-key (or (nth 7 inst-entry)
16833 (nth 5 inst-entry)))
16834 (setq depend-list (cons inst-ent-key depend-list)
16835 subcomp-list (cons inst-ent-key subcomp-list)))
16836 (setq inst-alist (cdr inst-alist)))
16837 ;; rule dependencies for all used packages
16838 (setq pack-list (vhdl-get-packages lib-alist work-library))
16839 (setq depend-list (append depend-list pack-list))
16840 (setq all-pack-list (append all-pack-list pack-list))
16841 ;; add rule
16842 (aput 'rule-alist arch-file-name (list target-list depend-list))
16843 (setq arch-alist (cdr arch-alist)))
16844 (setq prim-list (cons (list ent-key second-list
16845 (append subcomp-list all-pack-list))
16846 prim-list)))
16847 (setq ent-alist (cdr ent-alist)))
16848 (setq ent-alist tmp-list)
16849 ;; rules for all configurations
16850 (setq tmp-list conf-alist)
16851 (while conf-alist
16852 (setq conf-entry (car conf-alist)
16853 conf-key (nth 0 conf-entry)
16854 conf-file-name (file-relative-name
16855 (nth 2 conf-entry) compile-directory)
16856 ent-key (nth 4 conf-entry)
16857 arch-key (nth 5 conf-entry)
16858 inst-alist (nth 6 conf-entry)
16859 lib-alist (nth 7 conf-entry)
16860 rule (aget rule-alist conf-file-name)
16861 target-list (nth 0 rule)
16862 depend-list (nth 1 rule)
16863 subcomp-list (list ent-key))
16864 (setq tmp-key (vhdl-replace-string
16865 conf-regexp (funcall adjust-case conf-key)))
16866 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16867 ;; rule target for this configuration
16868 (setq target-list (cons conf-key target-list))
16869 ;; rule dependency for corresponding entity and architecture
16870 (setq depend-list
16871 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16872 ;; rule dependencies for used packages
16873 (setq pack-list (vhdl-get-packages lib-alist work-library))
16874 (setq depend-list (append depend-list pack-list))
16875 ;; rule dependencies for contained component configurations
16876 (while inst-alist
16877 (setq inst-entry (car inst-alist))
16878 (setq inst-ent-key (nth 2 inst-entry)
16879 ; comp-arch-key (nth 2 inst-entry))
16880 inst-conf-key (nth 4 inst-entry))
16881 (when (equal (downcase (nth 5 inst-entry)) work-library)
16882 (when inst-ent-key
16883 (setq depend-list (cons inst-ent-key depend-list)
16884 subcomp-list (cons inst-ent-key subcomp-list)))
16885 ; (when comp-arch-key
16886 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16887 ; depend-list)))
16888 (when inst-conf-key
16889 (setq depend-list (cons inst-conf-key depend-list)
16890 subcomp-list (cons inst-conf-key subcomp-list))))
16891 (setq inst-alist (cdr inst-alist)))
16892 ;; add rule
16893 (aput 'rule-alist conf-file-name (list target-list depend-list))
16894 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16895 prim-list))
16896 (setq conf-alist (cdr conf-alist)))
16897 (setq conf-alist tmp-list)
16898 ;; rules for all packages
16899 (setq tmp-list pack-alist)
16900 (while pack-alist
16901 (setq pack-entry (car pack-alist)
16902 pack-key (nth 0 pack-entry)
16903 pack-body-key nil)
16904 (when (nth 2 pack-entry)
16905 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16906 compile-directory)
16907 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16908 rule (aget rule-alist pack-file-name)
16909 target-list (nth 0 rule) depend-list (nth 1 rule))
16910 (setq tmp-key (vhdl-replace-string
16911 pack-regexp (funcall adjust-case pack-key)))
16912 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16913 ;; rule target for this package
16914 (setq target-list (cons pack-key target-list))
16915 ;; rule dependencies for all used packages
16916 (setq pack-list (vhdl-get-packages lib-alist work-library))
16917 (setq depend-list (append depend-list pack-list))
16918 (setq all-pack-list pack-list)
16919 ;; add rule
16920 (aput 'rule-alist pack-file-name (list target-list depend-list))
16921 ;; rules for this package's body
16922 (when (nth 7 pack-entry)
16923 (setq pack-body-key (concat pack-key "-body")
16924 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16925 compile-directory)
16926 rule (aget rule-alist pack-body-file-name)
16927 target-list (nth 0 rule)
16928 depend-list (nth 1 rule))
16929 (setq tmp-key (vhdl-replace-string
16930 pack-body-regexp (funcall adjust-case pack-key)))
16931 (setq unit-list
16932 (cons (cons pack-body-key tmp-key) unit-list))
16933 ;; rule target for this package's body
16934 (setq target-list (cons pack-body-key target-list))
16935 ;; rule dependency for corresponding package declaration
16936 (setq depend-list (cons pack-key depend-list))
16937 ;; rule dependencies for all used packages
16938 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16939 (setq depend-list (append depend-list pack-list))
16940 (setq all-pack-list (append all-pack-list pack-list))
16941 ;; add rule
16942 (aput 'rule-alist pack-body-file-name
16943 (list target-list depend-list)))
16944 (setq prim-list
16945 (cons (list pack-key (when pack-body-key (list pack-body-key))
16946 all-pack-list)
16947 prim-list)))
16948 (setq pack-alist (cdr pack-alist)))
16949 (setq pack-alist tmp-list)
16950 ;; generate Makefile
16951 (let* ((project (aget vhdl-project-alist project))
16952 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16953 (compiler-id (nth 9 compiler))
16954 (library-directory
16955 (vhdl-resolve-env-variable
16956 (vhdl-replace-string
16957 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16958 compiler-id)))
16959 (makefile-path-name (expand-file-name
16960 makefile-name compile-directory))
16961 (orig-buffer (current-buffer))
16962 cell second-list subcomp-list options unit-key unit-name)
16963 ;; sort lists
16964 (setq unit-list (vhdl-sort-alist unit-list))
16965 (setq prim-list (vhdl-sort-alist prim-list))
16966 (setq tmp-list rule-alist)
16967 (while tmp-list ; pre-sort rule targets
16968 (setq cell (cdar tmp-list))
16969 (setcar cell (sort (car cell) 'string<))
16970 (setq tmp-list (cdr tmp-list)))
16971 (setq rule-alist ; sort by first rule target
16972 (sort rule-alist
16973 (function (lambda (a b)
16974 (string< (car (cadr a)) (car (cadr b)))))))
16975 ;; open and clear Makefile
16976 (set-buffer (find-file-noselect makefile-path-name t t))
16977 (erase-buffer)
16978 (insert "# -*- Makefile -*-\n"
16979 "### " (file-name-nondirectory makefile-name)
16980 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16981 "\n")
16982 (if project
16983 (insert "\n# Project : " (nth 0 project))
16984 (insert "\n# Directory : \"" directory "\""))
16985 (insert "\n# Platform : " vhdl-compiler
16986 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16987 (user-login-name) "\n")
16988 ;; insert compile and option variable settings
16989 (insert "\n\n# Define compilation command and options\n"
16990 "\nCOMPILE = " (nth 0 compiler)
16991 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16992 (if (equal vhdl-compile-post-command "") ""
16993 (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
16994 "\n")
16995 ;; insert library paths
16996 (setq library-directory
16997 (directory-file-name
16998 (if (file-name-absolute-p library-directory)
16999 library-directory
17000 (file-relative-name
17001 (expand-file-name library-directory directory)
17002 compile-directory))))
17003 (insert "\n\n# Define library paths\n"
17004 "\nLIBRARY-" work-library " = " library-directory "\n")
17005 ;; insert variable definitions for all library unit files
17006 (insert "\n\n# Define library unit files\n")
17007 (setq tmp-list unit-list)
17008 (while unit-list
17009 (insert "\nUNIT-" work-library "-" (caar unit-list)
17010 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
17011 (setq unit-list (cdr unit-list)))
17012 ;; insert variable definition for list of all library unit files
17013 (insert "\n\n\n# Define list of all library unit files\n"
17014 "\nALL_UNITS =")
17015 (setq unit-list tmp-list)
17016 (while unit-list
17017 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
17018 (setq unit-list (cdr unit-list)))
17019 (insert "\n")
17020 (setq unit-list tmp-list)
17021 ;; insert `make all' rule
17022 (insert "\n\n\n# Rule for compiling entire design\n"
17023 "\n" (nth 0 vhdl-makefile-default-targets) " :"
17024 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17025 " \\\n\t\t$(ALL_UNITS)\n")
17026 ;; insert `make clean' rule
17027 (insert "\n\n# Rule for cleaning entire design\n"
17028 "\n" (nth 1 vhdl-makefile-default-targets) " : "
17029 "\n\t-rm -f $(ALL_UNITS)\n")
17030 ;; insert `make library' rule
17031 (insert "\n\n# Rule for creating library directory\n"
17032 "\n" (nth 2 vhdl-makefile-default-targets) " :"
17033 " \\\n\t\t$(LIBRARY-" work-library ")\n"
17034 "\n$(LIBRARY-" work-library ") :"
17035 "\n\t"
17036 (vhdl-replace-string
17037 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
17038 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
17039 "\n")
17040 ;; insert '.PHONY' declaration
17041 (insert "\n\n.PHONY : "
17042 (nth 0 vhdl-makefile-default-targets) " "
17043 (nth 1 vhdl-makefile-default-targets) " "
17044 (nth 2 vhdl-makefile-default-targets) "\n")
17045 ;; insert rule for each library unit
17046 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17047 (while prim-list
17048 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
17049 (setq subcomp-list
17050 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
17051 (setq unit-key (caar prim-list)
17052 unit-name (or (nth 0 (aget ent-alist unit-key t))
17053 (nth 0 (aget conf-alist unit-key t))
17054 (nth 0 (aget pack-alist unit-key t))))
17055 (insert "\n" unit-key)
17056 (unless (equal unit-key unit-name)
17057 (insert " \\\n" unit-name))
17058 (insert " :"
17059 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
17060 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
17061 (while second-list
17062 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
17063 (setq second-list (cdr second-list)))
17064 (while subcomp-list
17065 (when (and (assoc (car subcomp-list) unit-list)
17066 (not (equal unit-key (car subcomp-list))))
17067 (insert " \\\n\t\t" (car subcomp-list)))
17068 (setq subcomp-list (cdr subcomp-list)))
17069 (insert "\n")
17070 (setq prim-list (cdr prim-list)))
17071 ;; insert rule for each library unit file
17072 (insert "\n\n# Rules for compiling single library unit files\n")
17073 (while rule-alist
17074 (setq rule (car rule-alist))
17075 ;; get compiler options for this file
17076 (setq options
17077 (vhdl-get-compile-options project compiler (nth 0 rule) t))
17078 ;; insert rule if file is supposed to be compiled
17079 (setq target-list (nth 1 rule)
17080 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
17081 ;; insert targets
17082 (setq tmp-list target-list)
17083 (while target-list
17084 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
17085 (if (cdr target-list) " \\" " :"))
17086 (setq target-list (cdr target-list)))
17087 (setq target-list tmp-list)
17088 ;; insert file name as first dependency
17089 (insert " \\\n\t\t" (nth 0 rule))
17090 ;; insert dependencies (except if also target or unit does not exist)
17091 (while depend-list
17092 (when (and (not (member (car depend-list) target-list))
17093 (assoc (car depend-list) unit-list))
17094 (insert " \\\n\t\t"
17095 "$(UNIT-" work-library "-" (car depend-list) ")"))
17096 (setq depend-list (cdr depend-list)))
17097 ;; insert compile command
17098 (if options
17099 (insert "\n\t$(COMPILE) "
17100 (if (eq options 'default) "$(OPTIONS)" options) " "
17101 (nth 0 rule)
17102 (if (equal vhdl-compile-post-command "") ""
17103 " $(POST-COMPILE)") "\n")
17104 (setq tmp-list target-list)
17105 (while target-list
17106 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
17107 (if (cdr target-list) " \\" "\n"))
17108 (setq target-list (cdr target-list)))
17109 (setq target-list tmp-list))
17110 (setq rule-alist (cdr rule-alist)))
17111 (insert "\n\n### " makefile-name " ends here\n")
17112 ;; run Makefile generation hook
17113 (run-hooks 'vhdl-makefile-generation-hook)
17114 (message "Generating makefile \"%s\"...done" makefile-name)
17115 ;; save and close file
17116 (if (file-writable-p makefile-path-name)
17117 (progn (save-buffer)
17118 (kill-buffer (current-buffer))
17119 (set-buffer orig-buffer)
17120 (add-to-history 'file-name-history makefile-path-name))
17121 (vhdl-warning-when-idle
17122 (format "File not writable: \"%s\""
17123 (abbreviate-file-name makefile-path-name)))
17124 (switch-to-buffer (current-buffer))))))
17127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17128 ;;; Bug reports
17129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17130 ;; (using `reporter.el')
17132 (defconst vhdl-mode-help-address
17133 "Reto Zimmermann <reto@gnu.org>"
17134 "Address for VHDL Mode bug reports.")
17136 (defun vhdl-submit-bug-report ()
17137 "Submit via mail a bug report on VHDL Mode."
17138 (interactive)
17139 ;; load in reporter
17140 (and
17141 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17142 (let ((reporter-prompt-for-summary-p t))
17143 (reporter-submit-bug-report
17144 vhdl-mode-help-address
17145 (concat "VHDL Mode " vhdl-version)
17146 (list
17147 ;; report all important user options
17148 'vhdl-offsets-alist
17149 'vhdl-comment-only-line-offset
17150 'tab-width
17151 'vhdl-electric-mode
17152 'vhdl-stutter-mode
17153 'vhdl-indent-tabs-mode
17154 'vhdl-project-alist
17155 'vhdl-project
17156 'vhdl-project-file-name
17157 'vhdl-project-auto-load
17158 'vhdl-project-sort
17159 'vhdl-compiler-alist
17160 'vhdl-compiler
17161 'vhdl-compile-use-local-error-regexp
17162 'vhdl-makefile-default-targets
17163 'vhdl-makefile-generation-hook
17164 'vhdl-default-library
17165 'vhdl-standard
17166 'vhdl-basic-offset
17167 'vhdl-upper-case-keywords
17168 'vhdl-upper-case-types
17169 'vhdl-upper-case-attributes
17170 'vhdl-upper-case-enum-values
17171 'vhdl-upper-case-constants
17172 'vhdl-use-direct-instantiation
17173 'vhdl-array-index-record-field-in-sensitivity-list
17174 'vhdl-compose-configuration-name
17175 'vhdl-entity-file-name
17176 'vhdl-architecture-file-name
17177 'vhdl-configuration-file-name
17178 'vhdl-package-file-name
17179 'vhdl-file-name-case
17180 'vhdl-electric-keywords
17181 'vhdl-optional-labels
17182 'vhdl-insert-empty-lines
17183 'vhdl-argument-list-indent
17184 'vhdl-association-list-with-formals
17185 'vhdl-conditions-in-parenthesis
17186 'vhdl-zero-string
17187 'vhdl-one-string
17188 'vhdl-file-header
17189 'vhdl-file-footer
17190 'vhdl-company-name
17191 'vhdl-copyright-string
17192 'vhdl-platform-spec
17193 'vhdl-date-format
17194 'vhdl-modify-date-prefix-string
17195 'vhdl-modify-date-on-saving
17196 'vhdl-reset-kind
17197 'vhdl-reset-active-high
17198 'vhdl-clock-rising-edge
17199 'vhdl-clock-edge-condition
17200 'vhdl-clock-name
17201 'vhdl-reset-name
17202 'vhdl-model-alist
17203 'vhdl-include-port-comments
17204 'vhdl-include-direction-comments
17205 'vhdl-include-type-comments
17206 'vhdl-include-group-comments
17207 'vhdl-actual-port-name
17208 'vhdl-instance-name
17209 'vhdl-testbench-entity-name
17210 'vhdl-testbench-architecture-name
17211 'vhdl-testbench-configuration-name
17212 'vhdl-testbench-dut-name
17213 'vhdl-testbench-include-header
17214 'vhdl-testbench-declarations
17215 'vhdl-testbench-statements
17216 'vhdl-testbench-initialize-signals
17217 'vhdl-testbench-include-library
17218 'vhdl-testbench-include-configuration
17219 'vhdl-testbench-create-files
17220 'vhdl-testbench-entity-file-name
17221 'vhdl-testbench-architecture-file-name
17222 'vhdl-compose-create-files
17223 'vhdl-compose-configuration-create-file
17224 'vhdl-compose-configuration-hierarchical
17225 'vhdl-compose-configuration-use-subconfiguration
17226 'vhdl-compose-include-header
17227 'vhdl-compose-architecture-name
17228 'vhdl-components-package-name
17229 'vhdl-use-components-package
17230 'vhdl-self-insert-comments
17231 'vhdl-prompt-for-comments
17232 'vhdl-inline-comment-column
17233 'vhdl-end-comment-column
17234 'vhdl-auto-align
17235 'vhdl-align-groups
17236 'vhdl-align-group-separate
17237 'vhdl-align-same-indent
17238 'vhdl-highlight-keywords
17239 'vhdl-highlight-names
17240 'vhdl-highlight-special-words
17241 'vhdl-highlight-forbidden-words
17242 'vhdl-highlight-verilog-keywords
17243 'vhdl-highlight-translate-off
17244 'vhdl-highlight-case-sensitive
17245 'vhdl-special-syntax-alist
17246 'vhdl-forbidden-words
17247 'vhdl-forbidden-syntax
17248 'vhdl-directive-keywords
17249 'vhdl-speedbar-auto-open
17250 'vhdl-speedbar-display-mode
17251 'vhdl-speedbar-scan-limit
17252 'vhdl-speedbar-jump-to-unit
17253 'vhdl-speedbar-update-on-saving
17254 'vhdl-speedbar-save-cache
17255 'vhdl-speedbar-cache-file-name
17256 'vhdl-index-menu
17257 'vhdl-source-file-menu
17258 'vhdl-hideshow-menu
17259 'vhdl-hide-all-init
17260 'vhdl-print-two-column
17261 'vhdl-print-customize-faces
17262 'vhdl-intelligent-tab
17263 'vhdl-indent-syntax-based
17264 'vhdl-indent-comment-like-next-code-line
17265 'vhdl-word-completion-case-sensitive
17266 'vhdl-word-completion-in-minibuffer
17267 'vhdl-underscore-is-part-of-word
17268 'vhdl-mode-hook)
17269 (function
17270 (lambda ()
17271 (insert
17272 (if vhdl-special-indent-hook
17273 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17274 "vhdl-special-indent-hook is set to '"
17275 (format "%s" vhdl-special-indent-hook)
17276 ".\nPerhaps this is your problem?\n"
17277 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17278 "\n"))))
17280 "Hi Reto,"))))
17283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17284 ;;; Documentation
17285 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17287 (defconst vhdl-doc-release-notes nil
17289 Release Notes for VHDL Mode 3.33
17290 ================================
17292 - New Features
17293 - User Options
17296 New Features
17297 ------------
17299 CONFIGURATION DECLARATION GENERATION:
17300 - Automatic generation of a configuration declaration for a design.
17301 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17304 Key Bindings
17305 ------------
17307 For Emacs compliance the following key bindings have been changed:
17309 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17310 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17311 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17312 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17315 User Options
17316 ------------
17318 `vhdl-configuration-file-name': (new)
17319 Specify how the configuration file name is obtained.
17320 `vhdl-compose-configuration-name': (new)
17321 Specify how the configuration name is obtained.
17322 `vhdl-compose-configuration-create-file': (new)
17323 Specify whether a new file should be created for a configuration.
17324 `vhdl-compose-configuration-hierarchical': (new)
17325 Specify whether hierarchical configurations should be created.
17326 `vhdl-compose-configuration-use-subconfiguration': (new)
17327 Specify whether subconfigurations should be used inside configurations.
17328 `vhdl-makefile-default-targets': (new)
17329 Customize names of Makefile default targets.
17330 `vhdl-indent-comment-like-next-code-line': (new)
17331 Specify whether comment lines are indented like following code line.
17332 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17333 Specify whether to include array indices / record fields in sensitivity list.
17337 (defconst vhdl-doc-keywords nil
17339 Reserved words in VHDL
17340 ----------------------
17342 VHDL'93/02 (IEEE Std 1076-1993/2002):
17343 `vhdl-02-keywords' : keywords
17344 `vhdl-02-types' : standardized types
17345 `vhdl-02-attributes' : standardized attributes
17346 `vhdl-02-enum-values' : standardized enumeration values
17347 `vhdl-02-functions' : standardized functions
17348 `vhdl-02-packages' : standardized packages and libraries
17350 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17351 `vhdl-ams-keywords' : keywords
17352 `vhdl-ams-types' : standardized types
17353 `vhdl-ams-attributes' : standardized attributes
17354 `vhdl-ams-enum-values' : standardized enumeration values
17355 `vhdl-ams-constants' : standardized constants
17356 `vhdl-ams-functions' : standardized functions
17358 Math Packages (IEEE Std 1076.2):
17359 `vhdl-math-types' : standardized types
17360 `vhdl-math-constants' : standardized constants
17361 `vhdl-math-functions' : standardized functions
17362 `vhdl-math-packages' : standardized packages
17364 Forbidden words:
17365 `vhdl-verilog-keywords' : Verilog reserved words
17367 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17370 (defconst vhdl-doc-coding-style nil
17372 For VHDL coding style and naming convention guidelines, see the following
17373 references:
17375 \[1] Ben Cohen.
17376 \"VHDL Coding Styles and Methodologies\".
17377 Kluwer Academic Publishers, 1999.
17378 http://members.aol.com/vhdlcohen/vhdl/
17380 \[2] Michael Keating and Pierre Bricaud.
17381 \"Reuse Methodology Manual, Second Edition\".
17382 Kluwer Academic Publishers, 1999.
17383 http://www.openmore.com/openmore/rmm2.html
17385 \[3] European Space Agency.
17386 \"VHDL Modelling Guidelines\".
17387 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17389 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17390 to visually support naming conventions.")
17393 (defun vhdl-version ()
17394 "Echo the current version of VHDL Mode in the minibuffer."
17395 (interactive)
17396 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
17397 (vhdl-keep-region-active))
17399 (defun vhdl-doc-variable (variable)
17400 "Display VARIABLE's documentation in *Help* buffer."
17401 (interactive)
17402 (unless (featurep 'xemacs)
17403 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
17404 (with-output-to-temp-buffer
17405 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17406 (princ (documentation-property variable 'variable-documentation))
17407 (with-current-buffer standard-output
17408 (help-mode))
17409 (help-print-return-message)))
17411 (defun vhdl-doc-mode ()
17412 "Display VHDL Mode documentation in *Help* buffer."
17413 (interactive)
17414 (unless (featurep 'xemacs)
17415 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
17416 (with-output-to-temp-buffer
17417 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
17418 (princ mode-name)
17419 (princ " mode:\n")
17420 (princ (documentation 'vhdl-mode))
17421 (with-current-buffer standard-output
17422 (help-mode))
17423 (help-print-return-message)))
17426 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17428 (provide 'vhdl-mode)
17430 ;;; vhdl-mode.el ends here