1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2003, 2004, 2005 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://opensource.ethz.ch/emacs/vhdl-mode.html
11 (defconst vhdl-version
"3.32.12"
12 "VHDL Mode version number.")
14 (defconst vhdl-time-stamp
"2003-02-28"
15 "VHDL Mode time stamp for last update.")
17 ;; This file is part of GNU Emacs.
19 ;; GNU Emacs is free software; you can redistribute it and/or modify
20 ;; it under the terms of the GNU General Public License as published by
21 ;; the Free Software Foundation; either version 2, or (at your option)
24 ;; GNU Emacs is distributed in the hope that it will be useful,
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;; GNU General Public License for more details.
29 ;; You should have received a copy of the GNU General Public License
30 ;; along with GNU Emacs; see the file COPYING. If not, write to the
31 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
32 ;; Boston, MA 02110-1301, USA.
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;; This package provides an Emacs major mode for editing VHDL code.
39 ;; It includes the following features:
41 ;; - Syntax highlighting
43 ;; - Template insertion (electrification)
44 ;; - Insertion of file headers
45 ;; - Insertion of user-specified models
46 ;; - Port translation / testbench generation
47 ;; - Sensitivity list updating
49 ;; - Design hierarchy browser
50 ;; - Source file compilation (syntax analysis)
51 ;; - Makefile generation
53 ;; - Word/keyword completion
55 ;; - Code fixing/alignment/beautification
56 ;; - Postscript printing
57 ;; - VHDL'87/'93 and VHDL-AMS supported
58 ;; - Comprehensive menu
59 ;; - Fully customizable
60 ;; - Works under GNU Emacs (recommended) and XEmacs
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
65 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 ;; supported: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X
71 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
73 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 ;; Prerequisites: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X.
78 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
79 ;; or into an arbitrary directory that is added to the load path by the
80 ;; following line in your Emacs start-up file `.emacs':
82 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
84 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
85 ;; directory. Otherwise, byte-compile the source file:
86 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
87 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
89 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
90 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
91 ;; (not required in Emacs 20.X):
93 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
94 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
96 ;; More detailed installation instructions are included in the official
97 ;; VHDL Mode distribution.
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
102 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
105 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
106 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
108 ;; Many thanks to all the users who sent me bug reports and enhancement
110 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
111 ;; enhancement suggestions and the fruitful discussions.
112 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
113 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
115 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
116 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
117 ;; giving me the opportunity to develop this code.
118 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
119 ;; of the Swiss Government.
121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126 (defconst vhdl-xemacs
(string-match "XEmacs" emacs-version
)
127 "Non-nil if XEmacs is used.")
129 (defconst vhdl-emacs-21
(and (= emacs-major-version
21) (not vhdl-xemacs
))
130 "Non-nil if Emacs 21 is used.")
133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
137 ;; help function for user options
138 (defun vhdl-custom-set (variable value
&rest functions
)
139 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
140 (if (fboundp 'custom-set-default
)
141 (custom-set-default variable value
)
142 (set-default variable value
))
144 (when (fboundp (car functions
)) (funcall (car functions
)))
145 (setq functions
(cdr functions
))))
147 (defun vhdl-widget-directory-validate (widget)
148 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
150 (let ((val (widget-value widget
)))
151 (unless (string-match "^\\(\\|.*/\\)$" val
)
152 (widget-put widget
:error
"Invalid directory entry: must end with '/'")
155 ;; help string for user options
156 (defconst vhdl-name-doc-string
"
158 FROM REGEXP is a regular expression matching the original name:
159 \".*\" matches the entire string
160 \"\\(...\\)\" matches a substring
161 TO STRING specifies the string to be inserted as new name:
162 \"\\&\" means substitute entire matched text
163 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
165 \".*\" \"\\&\" inserts original string
166 \".*\" \"\\&_i\" attaches \"_i\" to original string
167 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
168 \".*\" \"foo\" inserts constant string \"foo\"
169 \".*\" \"\" inserts empty string")
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
175 "Customizations for VHDL Mode."
178 ; :version "20.4" ; comment out for XEmacs
181 (defgroup vhdl-mode nil
182 "Customizations for modes."
185 (defcustom vhdl-electric-mode t
186 "*Non-nil enables electrification (automatic template generation).
187 If nil, template generators can still be invoked through key bindings and
188 menu. Is indicated in the modeline by \"/e\" after the mode name and can be
189 toggled by `\\[vhdl-electric-mode]'."
193 (defcustom vhdl-stutter-mode t
194 "*Non-nil enables stuttering.
195 Is indicated in the modeline by \"/s\" after the mode name and can be toggled
196 by `\\[vhdl-stutter-mode]'."
200 (defcustom vhdl-indent-tabs-mode nil
201 "*Non-nil means indentation can insert tabs.
202 Overrides local variable `indent-tabs-mode'."
207 (defgroup vhdl-compile nil
208 "Customizations for compilation."
211 (defcustom vhdl-compiler-alist
213 ;; Cadence Leapfrog: cv -file test.vhd
214 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
215 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
216 nil
"mkdir \\1" "./" "work/" "Makefile" "leapfrog"
217 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
218 ("\\1/entity" "\\2/\\1" "\\1/configuration"
219 "\\1/package" "\\1/body" downcase
))
220 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
221 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
222 ;; (PLL_400X_TOP) is not declared [10.3].
223 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
224 nil
"mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
225 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
227 ;; Ikos Voyager: analyze test.vhd
229 ;; E L4/C5: this library unit is inaccessible
230 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
231 nil
"mkdir \\1" "./" "work/" "Makefile" "ikos"
232 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
233 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
235 ;; ModelSim, Model Technology: vcom test.vhd
236 ;; ERROR: test.vhd(14): Unknown identifier: positiv
237 ;; WARNING[2]: test.vhd(85): Possible infinite loop
238 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
239 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
240 nil
"vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
241 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
242 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
243 "\\1/_primary.dat" "\\1/body.dat" downcase
))
244 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
245 ;; test.vhd:34: error message
246 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
247 nil
"mkdir \\1" "./" "work/" "Makefile" "provhdl"
248 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
249 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
250 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase
))
251 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
252 ;; ERROR: test.vhd(24): near "dnd": expecting: END
253 ;; WARNING[4]: test.vhd(30): A space is required between ...
254 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
255 nil
"mkdir \\1" "./" "work/" "Makefile" "quickhdl"
256 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
257 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
258 "\\1/_primary.dat" "\\1/body.dat" downcase
))
259 ;; Savant: scram -publish-cc test.vhd
260 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
261 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
262 nil
"mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
263 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
264 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
265 "\\1_config.vhdl" "\\1_package.vhdl"
266 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase
))
267 ;; Simili: vhdlp -work test.vhd
268 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
269 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
270 nil
"mkdir \\1" "./" "work/" "Makefile" "simili"
271 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
272 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
273 "\\1/prim.var" "\\1/_body.var" downcase
))
274 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
275 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
276 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
277 nil
"mkdir \\1" "./" "work/" "Makefile" "speedwave"
278 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
280 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
281 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
282 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
283 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys"
284 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
285 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase
))
286 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
287 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
288 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
289 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
290 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
291 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase
))
293 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
294 ("Synplify" "n/a" "n/a" "make" "-f \\1"
295 nil
"mkdir \\1" "./" "work/" "Makefile" "synplify"
296 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
298 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
299 ;; Compiling "test.vhd" line 1...
300 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
301 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
302 nil
"mkdir \\1" "./" "work/" "Makefile" "vantage"
303 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
304 ("^ *Compiling \"\\(.+\\)\" " 1)
306 ;; VeriBest: vc vhdl test.vhd
307 ;; (no file name printed out!)
308 ;; 32: Z <= A and BitA ;
310 ;; [Error] Name BITA is unknown
311 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
312 nil
"mkdir \\1" "./" "work/" "Makefile" "veribest"
313 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
315 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
316 ;; Compiling "test.vhd" line 1...
317 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
318 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
319 nil
"mkdir \\1" "./" "work/" "Makefile" "viewlogic"
320 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
321 ("^ *Compiling \"\\(.+\\)\" " 1)
324 "*List of available VHDL compilers and their properties.
325 Each list entry specifies the following items for a compiler:
327 Compiler name : name used in option `vhdl-compiler' to choose compiler
328 Compile command : command used for source file compilation
329 Compile options : compile options (\"\\1\" inserts library name)
330 Make command : command used for compilation using a Makefile
331 Make options : make options (\"\\1\" inserts Makefile name)
332 Generate Makefile: use built-in function or command to generate a Makefile
333 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
334 Library command : command to create library directory \(\"\\1\" inserts
335 library directory, \"\\2\" inserts library name)
336 Compile directory: where compilation is run and the Makefile is placed
337 Library directory: directory of default library
338 Makefile name : name of Makefile (default is \"Makefile\")
339 ID string : compiler identification string (see `vhdl-project-alist')
341 Regexp : regular expression to match error messages
342 File subexp index: index of subexpression that matches the file name
343 Line subexp index: index of subexpression that matches the line number
344 Column subexp idx: index of subexpression that matches the column number
346 Regexp : regular expression to match a file name message
347 File subexp index: index of subexpression that matches the file name
348 Unit-to-file name mapping: mapping of library unit names to names of files
349 generated by the compiler (used for Makefile generation)
350 To string : string a name is mapped to (\"\\1\" inserts the unit name,
351 \"\\2\" inserts the entity name for architectures)
352 Case adjustment : adjust case of inserted unit names
354 Compile options allows insertion of the library name (see `vhdl-project-alist')
355 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
357 For Makefile generation, the built-in function can be used (requires
358 specification of the unit-to-file name mapping). Alternatively, an
359 external command can be specified. Work directory allows specification of
360 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
361 used for Makefile generation). To use another library name than \"work\",
362 customize `vhdl-project-alist'. The library command is inserted in Makefiles
363 to automatically create the library directory if not existent.
365 Compile options, compile directory, library directory, and Makefile name are
366 overwritten by the project settings if a project is defined (see
367 `vhdl-project-alist'). Directory paths are relative to the source file
370 Some compilers do not include the file name in the error message, but print
371 out a file name message in advance. In this case, set \"File Subexp Index\"
372 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
373 If no file name at all is printed out, set both \"File Message\" entries to 0
374 \(a default file name message will be printed out instead, does not work in
377 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
378 assigning its name to option `vhdl-compiler'.
380 Please send any missing or erroneous compiler properties to the maintainer for
383 NOTE: Reflect the new setting in the choice list of option `vhdl-compiler'
384 by restarting Emacs."
386 (list :tag
"Compiler" :indent
2
387 (string :tag
"Compiler name ")
388 (string :tag
"Compile command ")
389 (string :tag
"Compile options " "-work \\1")
390 (string :tag
"Make command " "make")
391 (string :tag
"Make options " "-f \\1")
392 (choice :tag
"Generate Makefile "
393 (const :tag
"Built-in function" nil
)
394 (string :tag
"Command" "vmake \\2 > \\1"))
395 (string :tag
"Library command " "mkdir \\1")
396 (directory :tag
"Compile directory "
397 :validate vhdl-widget-directory-validate
"./")
398 (directory :tag
"Library directory "
399 :validate vhdl-widget-directory-validate
"work/")
400 (file :tag
"Makefile name " "Makefile")
401 (string :tag
"ID string ")
402 (list :tag
"Error message" :indent
4
403 (regexp :tag
"Regexp ")
404 (integer :tag
"File subexp index")
405 (integer :tag
"Line subexp index")
406 (integer :tag
"Column subexp idx"))
407 (list :tag
"File message" :indent
4
408 (regexp :tag
"Regexp ")
409 (integer :tag
"File subexp index"))
410 (choice :tag
"Unit-to-file name mapping"
411 :format
"%t: %[Value Menu%] %v\n"
412 (const :tag
"Not defined" nil
)
413 (list :tag
"To string" :indent
4
414 (string :tag
"Entity " "\\1.vhd")
415 (string :tag
"Architecture " "\\2_\\1.vhd")
416 (string :tag
"Configuration " "\\1.vhd")
417 (string :tag
"Package " "\\1.vhd")
418 (string :tag
"Package Body " "\\1_body.vhd")
419 (choice :tag
"Case adjustment "
420 (const :tag
"None" identity
)
421 (const :tag
"Upcase" upcase
)
422 (const :tag
"Downcase" downcase
))))))
423 :set
(lambda (variable value
)
424 (vhdl-custom-set variable value
'vhdl-update-mode-menu
))
425 :group
'vhdl-compile
)
427 (defcustom vhdl-compiler
"ModelSim"
428 "*Specifies the VHDL compiler to be used for syntax analysis.
429 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
430 :type
(let ((alist vhdl-compiler-alist
) list
)
432 (setq list
(cons (list 'const
(caar alist
)) list
))
433 (setq alist
(cdr alist
)))
434 (append '(choice) (nreverse list
)))
435 :group
'vhdl-compile
)
437 (defcustom vhdl-compile-use-local-error-regexp t
438 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
439 In this case, only error message regexps for VHDL compilers are active if
440 compilation is started from a VHDL buffer. Otherwise, the error message
441 regexps are appended to the predefined global regexps, and all regexps are
442 active all the time. Note that by doing that, the predefined global regexps
443 might result in erroneous parsing of error messages for some VHDL compilers.
445 NOTE: Activate the new setting by restarting Emacs."
447 :group
'vhdl-compile
)
449 (defcustom vhdl-makefile-generation-hook nil
450 "*Functions to run at the end of Makefile generation.
451 Allows to insert user specific parts into a Makefile.
455 \(re-search-backward \"^# Rule for compiling entire design\")
456 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
458 :group
'vhdl-compile
)
460 (defcustom vhdl-default-library
"work"
461 "*Name of default library.
462 Is overwritten by project settings if a project is active."
464 :group
'vhdl-compile
)
467 (defgroup vhdl-project nil
468 "Customizations for projects."
471 (defcustom vhdl-project-alist
472 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
473 "~/example1/" ("src/system/" "src/components/") ""
474 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil
)
475 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" .
"-optimize \\3") (".*_tb\\.vhd" . nil
))))
476 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
477 ("Example 2" "Individual source files, multiple compilers in different directories"
478 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
479 nil
"\\1/" "work" "\\1/work/" "Makefile" "")
480 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
481 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
482 nil
"./" "work" "work-\\1/" "Makefile-\\1" "\
483 -------------------------------------------------------------------------------
484 -- This is a multi-line project description
485 -- that can be used as a project dependent part of the file header.
487 "*List of projects and their properties.
488 Name : name used in option `vhdl-project' to choose project
489 Title : title of project (single-line string)
490 Default directory: default project directory (absolute path)
491 Sources : a) source files : path + \"/\" + file name
492 b) directory : path + \"/\"
493 c) directory tree: \"-r \" + path + \"/\"
494 Exclude regexp : matches file/directory names to be excluded as sources
495 Compile options : project-specific options for each compiler
496 Compiler name : name of compiler for which these options are valid
497 Compile options: project-specific compiler options
498 (\"\\1\" inserts library name, \"\\2\" default options)
499 Make options: project-specific make options
500 (\"\\1\" inserts Makefile name, \"\\2\" default options)
501 Exceptions : file-specific exceptions
502 File name regexp: matches file names for which exceptions are valid
503 - Options : file-specific compiler options string
504 (\"\\1\" inserts library name, \"\\2\" default options,
505 \"\\3\" project-specific options)
506 - Do not compile: do not compile this file (in Makefile)
507 Compile directory: where compilation is run and the Makefile is placed
508 \(\"\\1\" inserts compiler ID string)
509 Library name : name of library (default is \"work\")
510 Library directory: path to library (\"\\1\" inserts compiler ID string)
511 Makefile name : name of Makefile
512 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
513 Description : description of project (multi-line string)
515 Project title and description are used to insert into the file header (see
516 option `vhdl-file-header').
518 The default directory must have an absolute path (use `M-TAB' for completion).
519 All other paths can be absolute or relative to the default directory. All
520 paths must end with '/'.
522 The design units found in the sources (files and directories) are shown in the
523 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
524 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
525 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
526 specified, the default directory is taken as source directory. Otherwise,
527 the default directory is only taken as source directory if there is a sources
528 entry with the empty string or \"./\". Exclude regexp allows to filter out
529 specific file and directory names from the list of sources (e.g. CVS
532 Files are compiled in the compile directory. Makefiles are also placed into
533 the compile directory. Library directory specifies which directory the
534 compiler compiles into (used to generate the Makefile).
536 Since different compile/library directories and Makefiles may exist for
537 different compilers within one project, these paths and names allow the
538 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
539 Compile options, compile directory, library directory, and Makefile name
540 overwrite the settings of the current compiler.
542 File-specific compiler options (highest priority) overwrite project-specific
543 options which overwrite default options (lowest priority). Lower priority
544 options can be inserted in higher priority options. This allows to reuse
545 default options (e.g. \"-file\") in project- or file-specific options (e.g.
548 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
549 by restarting Emacs."
551 (list :tag
"Project" :indent
2
552 (string :tag
"Name ")
553 (string :tag
"Title ")
554 (directory :tag
"Default directory"
555 :validate vhdl-widget-directory-validate
556 ,(abbreviate-file-name default-directory
))
557 (repeat :tag
"Sources " :indent
4
558 (directory :format
" %v" "./"))
559 (regexp :tag
"Exclude regexp ")
561 :tag
"Compile options " :indent
4
562 (list :tag
"Compiler" :indent
6
563 ,(let ((alist vhdl-compiler-alist
) list
)
565 (setq list
(cons (list 'const
(caar alist
)) list
))
566 (setq alist
(cdr alist
)))
567 (append '(choice :tag
"Compiler name")
569 (string :tag
"Compile options" "\\2")
570 (string :tag
"Make options " "\\2")
572 :tag
"Exceptions " :indent
8
574 (regexp :tag
"File name regexp ")
575 (choice :format
"%[Value Menu%] %v"
576 (string :tag
"Options" "\\3")
577 (const :tag
"Do not compile" nil
))))))
578 (directory :tag
"Compile directory"
579 :validate vhdl-widget-directory-validate
"./")
580 (string :tag
"Library name " "work")
581 (directory :tag
"Library directory"
582 :validate vhdl-widget-directory-validate
"work/")
583 (file :tag
"Makefile name " "Makefile")
584 (string :tag
"Description: (type `C-j' for newline)"
585 :format
"%t\n%v\n")))
586 :set
(lambda (variable value
)
587 (vhdl-custom-set variable value
588 'vhdl-update-mode-menu
589 'vhdl-speedbar-refresh
))
590 :group
'vhdl-project
)
592 (defcustom vhdl-project nil
593 "*Specifies the default for the current project.
594 Select a project name from the ones defined in option `vhdl-project-alist'.
595 Is used to determine the project title and description to be inserted in file
596 headers and the source files/directories to be scanned in the hierarchy
597 browser. The current project can also be changed temporarily in the menu."
598 :type
(let ((alist vhdl-project-alist
) list
)
600 (setq list
(cons (list 'const
(caar alist
)) list
))
601 (setq alist
(cdr alist
)))
602 (append '(choice (const :tag
"None" nil
) (const :tag
"--"))
604 :group
'vhdl-project
)
606 (defcustom vhdl-project-file-name
'("\\1.prj")
607 "*List of file names/paths for importing/exporting project setups.
608 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
609 replaced by the user name (allows to have user-specific project setups).
610 The first entry is used as file name to import/export individual project
611 setups. All entries are used to automatically import project setups at
612 startup (see option `vhdl-project-auto-load'). Projects loaded from the
613 first entry are automatically made current. Hint: specify local project
614 setups in first entry, global setups in following entries; loading a local
615 project setup will make it current, while loading the global setups
616 is done without changing the current project.
617 Names can also have an absolute path (i.e. project setups can be stored
618 in global directories)."
619 :type
'(repeat (string :tag
"File name" "\\1.prj"))
620 :group
'vhdl-project
)
622 (defcustom vhdl-project-auto-load
'(startup)
623 "*Automatically load project setups from files.
624 All project setup files that match the file names specified in option
625 `vhdl-project-file-name' are automatically loaded. The project of the
626 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
628 A project setup file can be obtained by exporting a project (see menu).
629 At startup: project setup file is loaded at Emacs startup"
630 :type
'(set (const :tag
"At startup" startup
))
631 :group
'vhdl-project
)
633 (defcustom vhdl-project-sort t
634 "*Non-nil means projects are displayed in alphabetical order."
636 :group
'vhdl-project
)
639 (defgroup vhdl-style nil
640 "Customizations for coding styles."
642 :group
'vhdl-template
644 :group
'vhdl-compose
)
646 (defcustom vhdl-standard
'(87 nil
)
647 "*VHDL standards used.
649 VHDL'87 : IEEE Std 1076-1987
650 VHDL'93 : IEEE Std 1076-1993
651 Additional standards:
652 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
653 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
655 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
656 \"Activate Options\"."
657 :type
'(list (choice :tag
"Basic standard"
658 (const :tag
"VHDL'87" 87)
659 (const :tag
"VHDL'93" 93))
660 (set :tag
"Additional standards" :indent
2
661 (const :tag
"VHDL-AMS" ams
)
662 (const :tag
"Math packages" math
)))
663 :set
(lambda (variable value
)
664 (vhdl-custom-set variable value
665 'vhdl-template-map-init
666 'vhdl-mode-abbrev-table-init
667 'vhdl-template-construct-alist-init
668 'vhdl-template-package-alist-init
669 'vhdl-update-mode-menu
670 'vhdl-words-init
'vhdl-font-lock-init
))
673 (defcustom vhdl-basic-offset
2
674 "*Amount of basic offset used for indentation.
675 This value is used by + and - symbols in `vhdl-offsets-alist'."
679 (defcustom vhdl-upper-case-keywords nil
680 "*Non-nil means convert keywords to upper case.
681 This is done when typed or expanded or by the fix case functions."
683 :set
(lambda (variable value
)
684 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
687 (defcustom vhdl-upper-case-types nil
688 "*Non-nil means convert standardized types to upper case.
689 This is done when expanded or by the fix case functions."
691 :set
(lambda (variable value
)
692 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
695 (defcustom vhdl-upper-case-attributes nil
696 "*Non-nil means convert standardized attributes to upper case.
697 This is done when expanded or by the fix case functions."
699 :set
(lambda (variable value
)
700 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
703 (defcustom vhdl-upper-case-enum-values nil
704 "*Non-nil means convert standardized enumeration values to upper case.
705 This is done when expanded or by the fix case functions."
707 :set
(lambda (variable value
)
708 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
711 (defcustom vhdl-upper-case-constants t
712 "*Non-nil means convert standardized constants to upper case.
713 This is done when expanded."
715 :set
(lambda (variable value
)
716 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
719 (defcustom vhdl-use-direct-instantiation
'standard
720 "*Non-nil means use VHDL'93 direct component instantiation.
722 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
724 :type
'(choice (const :tag
"Never" never
)
725 (const :tag
"Standard" standard
)
726 (const :tag
"Always" always
))
730 (defgroup vhdl-naming nil
731 "Customizations for naming conventions."
734 (defcustom vhdl-entity-file-name
'(".*" .
"\\&")
736 "*Specifies how the entity file name is obtained.
737 The entity file name can be obtained by modifying the entity name (e.g.
738 attaching or stripping off a substring). The file extension is automatically
739 taken from the file name of the current buffer."
740 vhdl-name-doc-string
)
741 :type
'(cons (regexp :tag
"From regexp")
742 (string :tag
"To string "))
744 :group
'vhdl-compose
)
746 (defcustom vhdl-architecture-file-name
'("\\(.*\\) \\(.*\\)" .
"\\1_\\2")
748 "*Specifies how the architecture file name is obtained.
749 The architecture file name can be obtained by modifying the entity
750 and/or architecture name (e.g. attaching or stripping off a substring). The
751 string that is matched against the regexp is the concatenation of the entity
752 and the architecture name separated by a space. This gives access to both
753 names (see default setting as example)."
754 vhdl-name-doc-string
)
755 :type
'(cons (regexp :tag
"From regexp")
756 (string :tag
"To string "))
758 :group
'vhdl-compose
)
760 (defcustom vhdl-package-file-name
'(".*" .
"\\&")
762 "*Specifies how the package file name is obtained.
763 The package file name can be obtained by modifying the package name (e.g.
764 attaching or stripping off a substring). The file extension is automatically
765 taken from the file name of the current buffer."
766 vhdl-name-doc-string
)
767 :type
'(cons (regexp :tag
"From regexp")
768 (string :tag
"To string "))
770 :group
'vhdl-compose
)
772 (defcustom vhdl-file-name-case
'identity
773 "*Specifies how to change case for obtaining file names.
774 When deriving a file name from a VHDL unit name, case can be changed as
776 As Is: case is not changed (taken as is)
777 Lower Case: whole name is changed to lower case
778 Upper Case: whole name is changed to upper case
779 Capitalize: first letter of each word in name is capitalized"
780 :type
'(choice (const :tag
"As Is" identity
)
781 (const :tag
"Lower Case" downcase
)
782 (const :tag
"Upper Case" upcase
)
783 (const :tag
"Capitalize" capitalize
))
785 :group
'vhdl-compose
)
788 (defgroup vhdl-template nil
789 "Customizations for electrification."
792 (defcustom vhdl-electric-keywords
'(vhdl user
)
793 "*Type of keywords for which electrification is enabled.
794 VHDL keywords: invoke built-in templates
795 User keywords: invoke user models (see option `vhdl-model-alist')"
796 :type
'(set (const :tag
"VHDL keywords" vhdl
)
797 (const :tag
"User model keywords" user
))
798 :set
(lambda (variable value
)
799 (vhdl-custom-set variable value
'vhdl-mode-abbrev-table-init
))
800 :group
'vhdl-template
)
802 (defcustom vhdl-optional-labels
'process
803 "*Constructs for which labels are to be queried.
804 Template generators prompt for optional labels for:
806 Processes only: processes only (also procedurals in VHDL-AMS)
807 All constructs: all constructs with optional labels and keyword END"
808 :type
'(choice (const :tag
"None" none
)
809 (const :tag
"Processes only" process
)
810 (const :tag
"All constructs" all
))
811 :group
'vhdl-template
)
813 (defcustom vhdl-insert-empty-lines
'unit
814 "*Specifies whether to insert empty lines in some templates.
815 This improves readability of code. Empty lines are inserted in:
817 Design units only: entities, architectures, configurations, packages only
818 All constructs : also all constructs with BEGIN...END parts
820 Replaces option `vhdl-additional-empty-lines'."
821 :type
'(choice (const :tag
"None" none
)
822 (const :tag
"Design units only" unit
)
823 (const :tag
"All constructs" all
))
824 :group
'vhdl-template
826 :group
'vhdl-compose
)
828 (defcustom vhdl-argument-list-indent nil
829 "*Non-nil means indent argument lists relative to opening parenthesis.
830 That is, argument, association, and port lists start on the same line as the
831 opening parenthesis and subsequent lines are indented accordingly.
832 Otherwise, lists start on a new line and are indented as normal code."
834 :group
'vhdl-template
836 :group
'vhdl-compose
)
838 (defcustom vhdl-association-list-with-formals t
839 "*Non-nil means write association lists with formal parameters.
840 Templates prompt for formal and actual parameters (ports/generics).
841 When pasting component instantiations, formals are included.
842 If nil, only a list of actual parameters is entered."
844 :group
'vhdl-template
846 :group
'vhdl-compose
)
848 (defcustom vhdl-conditions-in-parenthesis nil
849 "*Non-nil means place parenthesis around condition expressions."
851 :group
'vhdl-template
)
853 (defcustom vhdl-zero-string
"'0'"
854 "*String to use for a logic zero."
856 :group
'vhdl-template
)
858 (defcustom vhdl-one-string
"'1'"
859 "*String to use for a logic one."
861 :group
'vhdl-template
)
864 (defgroup vhdl-header nil
865 "Customizations for file header."
866 :group
'vhdl-template
867 :group
'vhdl-compose
)
869 (defcustom vhdl-file-header
"\
870 -------------------------------------------------------------------------------
871 -- Title : <title string>
872 -- Project : <project>
873 -------------------------------------------------------------------------------
876 -- Company : <company>
878 -- Last update: <date>
879 -- Platform : <platform>
880 -- Standard : <standard>
881 <projectdesc>-------------------------------------------------------------------------------
882 -- Description: <cursor>
883 <copyright>-------------------------------------------------------------------------------
885 -- Date Version Author Description
886 -- <date> 1.0 <login>\tCreated
887 -------------------------------------------------------------------------------
890 "*String or file to insert as file header.
891 If the string specifies an existing file name, the contents of the file is
892 inserted, otherwise the string itself is inserted as file header.
893 Type `C-j' for newlines.
894 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
895 if the header needs to be version controlled.
897 The following keywords for template generation are supported:
898 <filename> : replaced by the name of the buffer
899 <author> : replaced by the user name and email address
900 \(`user-full-name',`mail-host-address', `user-mail-address')
901 <login> : replaced by user login name (`user-login-name')
902 <company> : replaced by contents of option `vhdl-company-name'
903 <date> : replaced by the current date
904 <year> : replaced by the current year
905 <project> : replaced by title of current project (`vhdl-project')
906 <projectdesc> : replaced by description of current project (`vhdl-project')
907 <copyright> : replaced by copyright string (`vhdl-copyright-string')
908 <platform> : replaced by contents of option `vhdl-platform-spec'
909 <standard> : replaced by the VHDL language standard(s) used
910 <... string> : replaced by a queried string (\"...\" is the prompt word)
911 <title string>: replaced by file title in automatically generated files
912 <cursor> : final cursor position
914 The (multi-line) project description <projectdesc> can be used as a project
915 dependent part of the file header and can also contain the above keywords."
919 (defcustom vhdl-file-footer
""
920 "*String or file to insert as file footer.
921 If the string specifies an existing file name, the contents of the file is
922 inserted, otherwise the string itself is inserted as file footer (i.e. at
923 the end of the file).
924 Type `C-j' for newlines.
925 The same keywords as in option `vhdl-file-header' can be used."
929 (defcustom vhdl-company-name
""
930 "*Name of company to insert in file header.
931 See option `vhdl-file-header'."
935 (defcustom vhdl-copyright-string
"\
936 -------------------------------------------------------------------------------
937 -- Copyright (c) <year> <company>
939 "*Copyright string to insert in file header.
940 Can be multi-line string (type `C-j' for newline) and contain other file
941 header keywords (see option `vhdl-file-header')."
945 (defcustom vhdl-platform-spec
""
946 "*Specification of VHDL platform to insert in file header.
947 The platform specification should contain names and versions of the
948 simulation and synthesis tools used.
949 See option `vhdl-file-header'."
953 (defcustom vhdl-date-format
"%Y-%m-%d"
954 "*Specifies the date format to use in the header.
955 This string is passed as argument to the command `format-time-string'.
956 For more information on format strings, see the documentation for the
957 `format-time-string' command (C-h f `format-time-string')."
961 (defcustom vhdl-modify-date-prefix-string
"-- Last update: "
962 "*Prefix string of modification date in VHDL file header.
963 If actualization of the modification date is called (menu,
964 `\\[vhdl-template-modify]'), this string is searched and the rest
965 of the line replaced by the current date."
969 (defcustom vhdl-modify-date-on-saving t
970 "*Non-nil means update the modification date when the buffer is saved.
971 Calls function `\\[vhdl-template-modify]').
973 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
974 \"Activate Options\"."
979 (defgroup vhdl-sequential-process nil
980 "Customizations for sequential processes."
981 :group
'vhdl-template
)
983 (defcustom vhdl-reset-kind
'async
984 "*Specifies which kind of reset to use in sequential processes."
985 :type
'(choice (const :tag
"None" none
)
986 (const :tag
"Synchronous" sync
)
987 (const :tag
"Asynchronous" async
))
988 :group
'vhdl-sequential-process
)
990 (defcustom vhdl-reset-active-high nil
991 "*Non-nil means reset in sequential processes is active high.
992 Nil means active low."
994 :group
'vhdl-sequential-process
)
996 (defcustom vhdl-clock-rising-edge t
997 "*Non-nil means rising edge of clock triggers sequential processes.
998 Nil means falling edge."
1000 :group
'vhdl-sequential-process
)
1002 (defcustom vhdl-clock-edge-condition
'standard
1003 "*Syntax of the clock edge condition.
1004 Standard: \"clk'event and clk = '1'\"
1005 Function: \"rising_edge(clk)\""
1006 :type
'(choice (const :tag
"Standard" standard
)
1007 (const :tag
"Function" function
))
1008 :group
'vhdl-sequential-process
)
1010 (defcustom vhdl-clock-name
""
1011 "*Name of clock signal to use in templates."
1013 :group
'vhdl-sequential-process
)
1015 (defcustom vhdl-reset-name
""
1016 "*Name of reset signal to use in templates."
1018 :group
'vhdl-sequential-process
)
1021 (defgroup vhdl-model nil
1022 "Customizations for user models."
1025 (defcustom vhdl-model-alist
1027 "<label> : process (<clock>, <reset>)
1028 begin -- process <label>
1029 if <reset> = '0' then -- asynchronous reset (active low)
1031 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1032 if <enable> = '1' then -- synchronous load
1036 end process <label>;"
1038 "*List of user models.
1039 VHDL models (templates) can be specified by the user in this list. They can be
1040 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1041 electrification (i.e. overriding existing or creating new keywords, see
1042 option `vhdl-electric-keywords').
1043 Name : name of model (string of words and spaces)
1044 String : string or name of file to be inserted as model (newline: `C-j')
1045 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1046 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1047 Keyword : keyword to invoke model
1049 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1050 A prompt that appears several times is queried once and replaced throughout
1051 the model. Special prompts are:
1052 <clock> : name specified in `vhdl-clock-name' (if not empty)
1053 <reset> : name specified in `vhdl-reset-name' (if not empty)
1054 <cursor>: final cursor position
1055 File header prompts (see variable `vhdl-file-header') are automatically
1056 replaced, so that user models can also be used to insert different types of
1059 If the string specifies an existing file name, the contents of the file is
1060 inserted, otherwise the string itself is inserted.
1061 The code within the models should be correctly indented.
1062 Type `C-j' for newlines.
1064 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1065 \"Activate Options\"."
1066 :type
'(repeat (list :tag
"Model" :indent
2
1067 (string :tag
"Name ")
1068 (string :tag
"String : (type `C-j' for newline)"
1070 (sexp :tag
"Key binding" x
)
1071 (string :tag
"Keyword " :format
"%t: %v\n")))
1072 :set
(lambda (variable value
)
1073 (vhdl-custom-set variable value
1074 'vhdl-model-map-init
1076 'vhdl-mode-abbrev-table-init
1077 'vhdl-update-mode-menu
))
1081 (defgroup vhdl-port nil
1082 "Customizations for port translation functions."
1084 :group
'vhdl-compose
)
1086 (defcustom vhdl-include-port-comments nil
1087 "*Non-nil means include port comments when a port is pasted."
1091 (defcustom vhdl-include-direction-comments nil
1092 "*Non-nil means include port direction in instantiations as comments."
1096 (defcustom vhdl-include-type-comments nil
1097 "*Non-nil means include generic/port type in instantiations as comments."
1101 (defcustom vhdl-include-group-comments
'never
1102 "*Specifies whether to include group comments and spacings.
1103 The comments and empty lines between groups of ports are pasted:
1105 Declarations: in entity/component/constant/signal declarations only
1106 Always : also in generic/port maps"
1107 :type
'(choice (const :tag
"Never" never
)
1108 (const :tag
"Declarations" decl
)
1109 (const :tag
"Always" always
))
1112 (defcustom vhdl-actual-port-name
'(".*" .
"\\&")
1114 "*Specifies how actual port names are obtained from formal port names.
1115 In a component instantiation, an actual port name can be obtained by
1116 modifying the formal port name (e.g. attaching or stripping off a substring)."
1117 vhdl-name-doc-string
)
1118 :type
'(cons (regexp :tag
"From regexp")
1119 (string :tag
"To string "))
1122 (defcustom vhdl-instance-name
'(".*" .
"\\&_%d")
1124 "*Specifies how an instance name is obtained.
1125 The instance name can be obtained by modifying the name of the component to be
1126 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1127 by a unique number (starting with 1).
1128 If TO STRING is empty, the instance name is queried."
1129 vhdl-name-doc-string
)
1130 :type
'(cons (regexp :tag
"From regexp")
1131 (string :tag
"To string "))
1135 (defgroup vhdl-testbench nil
1136 "Customizations for testbench generation."
1139 (defcustom vhdl-testbench-entity-name
'(".*" .
"\\&_tb")
1141 "*Specifies how the testbench entity name is obtained.
1142 The entity name of a testbench can be obtained by modifying the name of
1143 the component to be tested (e.g. attaching or stripping off a substring)."
1144 vhdl-name-doc-string
)
1145 :type
'(cons (regexp :tag
"From regexp")
1146 (string :tag
"To string "))
1147 :group
'vhdl-testbench
)
1149 (defcustom vhdl-testbench-architecture-name
'(".*" .
"")
1151 "*Specifies how the testbench architecture name is obtained.
1152 The testbench architecture name can be obtained by modifying the name of
1153 the component to be tested (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-testbench
)
1160 (defcustom vhdl-testbench-configuration-name
1161 '("\\(.*\\) \\(.*\\)" .
"\\1_\\2_cfg")
1163 "*Specifies how the testbench configuration name is obtained.
1164 The configuration name of a testbench can be obtained by modifying the entity
1165 and/or architecture name (e.g. attaching or stripping off a substring). The
1166 string that is matched against the regexp is the concatenation of the entity
1167 and the architecture name separated by a space. This gives access to both
1168 names (see default setting as example)."
1169 vhdl-name-doc-string
)
1170 :type
'(cons (regexp :tag
"From regexp")
1171 (string :tag
"To string "))
1172 :group
'vhdl-testbench
)
1174 (defcustom vhdl-testbench-dut-name
'(".*" .
"DUT")
1176 "*Specifies how a DUT instance name is obtained.
1177 The design-under-test instance name (i.e. the component instantiated in the
1178 testbench) can be obtained by modifying the component name (e.g. attaching
1179 or stripping off a substring)."
1180 vhdl-name-doc-string
)
1181 :type
'(cons (regexp :tag
"From regexp")
1182 (string :tag
"To string "))
1183 :group
'vhdl-testbench
)
1185 (defcustom vhdl-testbench-include-header t
1186 "*Non-nil means include a header in automatically generated files."
1188 :group
'vhdl-testbench
)
1190 (defcustom vhdl-testbench-declarations
"\
1192 signal Clk : std_logic := '1';
1194 "*String or file to be inserted in the testbench declarative part.
1195 If the string specifies an existing file name, the contents of the file is
1196 inserted, otherwise the string itself is inserted in the testbench
1197 architecture before the BEGIN keyword.
1198 Type `C-j' for newlines."
1200 :group
'vhdl-testbench
)
1202 (defcustom vhdl-testbench-statements
"\
1204 Clk <= not Clk after 10 ns;
1206 -- waveform generation
1207 WaveGen_Proc: process
1209 -- insert signal assignments here
1211 wait until Clk = '1';
1212 end process WaveGen_Proc;
1214 "*String or file to be inserted in the testbench statement part.
1215 If the string specifies an existing file name, the contents of the file is
1216 inserted, otherwise the string itself is inserted in the testbench
1217 architecture before the END keyword.
1218 Type `C-j' for newlines."
1220 :group
'vhdl-testbench
)
1222 (defcustom vhdl-testbench-initialize-signals nil
1223 "*Non-nil means initialize signals with `0' when declared in testbench."
1225 :group
'vhdl-testbench
)
1227 (defcustom vhdl-testbench-include-library t
1228 "*Non-nil means a library/use clause for std_logic_1164 is included."
1230 :group
'vhdl-testbench
)
1232 (defcustom vhdl-testbench-include-configuration t
1233 "*Non-nil means a testbench configuration is attached at the end."
1235 :group
'vhdl-testbench
)
1237 (defcustom vhdl-testbench-create-files
'single
1238 "*Specifies whether new files should be created for the testbench.
1239 testbench entity and architecture are inserted:
1240 None : in current buffer
1241 Single file : in new single file
1242 Separate files: in two separate files
1243 Note that the files have the same name as the contained design unit."
1244 :type
'(choice (const :tag
"None" none
)
1245 (const :tag
"Single file" single
)
1246 (const :tag
"Separate files" separate
))
1247 :group
'vhdl-testbench
)
1250 (defgroup vhdl-compose nil
1251 "Customizations for structural composition."
1254 (defcustom vhdl-compose-create-files
'single
1255 "*Specifies whether new files should be created for the new component.
1256 The component's entity and architecture are inserted:
1257 None : in current buffer
1258 Single file : in new single file
1259 Separate files: in two separate files
1260 The file names are obtained from variables `vhdl-entity-file-name' and
1261 `vhdl-architecture-file-name'."
1262 :type
'(choice (const :tag
"None" none
)
1263 (const :tag
"Single file" single
)
1264 (const :tag
"Separate files" separate
))
1265 :group
'vhdl-compose
)
1267 (defcustom vhdl-compose-include-header t
1268 "*Non-nil means include a header in automatically generated files."
1270 :group
'vhdl-compose
)
1272 (defcustom vhdl-compose-architecture-name
'(".*" .
"str")
1274 "*Specifies how the component architecture name is obtained.
1275 The component architecture name can be obtained by modifying the entity name
1276 \(e.g. attaching or stripping off a substring).
1277 If TO STRING is empty, the architecture name is queried."
1278 vhdl-name-doc-string
)
1279 :type
'(cons (regexp :tag
"From regexp")
1280 (string :tag
"To string "))
1281 :group
'vhdl-compose
)
1283 (defcustom vhdl-components-package-name
1284 '((".*" .
"\\&_components") .
"components")
1286 "*Specifies how the name for the components package is obtained.
1287 The components package is a package containing all component declarations for
1288 the current design. Its name can be obtained by modifying the project name
1289 \(e.g. attaching or stripping off a substring). If no project is defined, the
1290 DIRECTORY entry is chosen."
1291 vhdl-name-doc-string
)
1292 :type
'(cons (cons :tag
"Project" :indent
2
1293 (regexp :tag
"From regexp")
1294 (string :tag
"To string "))
1295 (string :tag
"Directory:\n String "))
1296 :group
'vhdl-compose
)
1298 (defcustom vhdl-use-components-package nil
1299 "*Non-nil means use a separate components package for component declarations.
1300 Otherwise, component declarations are inserted and searched for in the
1301 architecture declarative parts."
1303 :group
'vhdl-compose
)
1306 (defgroup vhdl-comment nil
1307 "Customizations for comments."
1310 (defcustom vhdl-self-insert-comments t
1311 "*Non-nil means various templates automatically insert help comments."
1313 :group
'vhdl-comment
)
1315 (defcustom vhdl-prompt-for-comments t
1316 "*Non-nil means various templates prompt for user definable comments."
1318 :group
'vhdl-comment
)
1320 (defcustom vhdl-inline-comment-column
40
1321 "*Column to indent and align inline comments to.
1322 Overrides local option `comment-column'.
1324 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1325 \"Activate Options\"."
1327 :group
'vhdl-comment
)
1329 (defcustom vhdl-end-comment-column
79
1330 "*End of comment column.
1331 Comments that exceed this column number are wrapped.
1333 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1334 \"Activate Options\"."
1336 :group
'vhdl-comment
)
1338 (defvar end-comment-column
)
1341 (defgroup vhdl-align nil
1342 "Customizations for alignment."
1345 (defcustom vhdl-auto-align t
1346 "*Non-nil means align some templates automatically after generation."
1350 (defcustom vhdl-align-groups t
1351 "*Non-nil means align groups of code lines separately.
1352 A group of code lines is a region of consecutive lines between two lines that
1353 match the regexp in option `vhdl-align-group-separate'."
1357 (defcustom vhdl-align-group-separate
"^\\s-*$"
1358 "*Regexp for matching a line that separates groups of lines for alignment.
1360 \"^\\s-*$\": matches an empty line
1361 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1365 (defcustom vhdl-align-same-indent t
1366 "*Non-nil means align blocks with same indent separately.
1367 When a region or the entire buffer is aligned, the code is divided into
1368 blocks of same indent which are aligned separately (except for argument/port
1369 lists). This gives nicer alignment in most cases.
1370 Option `vhdl-align-groups' still applies within these blocks."
1375 (defgroup vhdl-highlight nil
1376 "Customizations for highlighting."
1379 (defcustom vhdl-highlight-keywords t
1380 "*Non-nil means highlight VHDL keywords and other standardized words.
1381 The following faces are used:
1382 `font-lock-keyword-face' : keywords
1383 `font-lock-type' : standardized types
1384 `vhdl-attribute' : standardized attributes
1385 `vhdl-enumvalue' : standardized enumeration values
1386 `vhdl-function' : standardized function and package names
1388 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1389 entry \"Fontify Buffer\")."
1391 :set
(lambda (variable value
)
1392 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1393 :group
'vhdl-highlight
)
1395 (defcustom vhdl-highlight-names t
1396 "*Non-nil means highlight declaration names and construct labels.
1397 The following faces are used:
1398 `font-lock-function-name-face' : names in declarations of units,
1399 subprograms, components, as well as labels of VHDL constructs
1400 `font-lock-type-face' : names in type/nature declarations
1401 `vhdl-attribute' : names in attribute declarations
1402 `font-lock-variable-name-face' : names in declarations of signals,
1403 variables, constants, subprogram parameters, generics, and ports
1405 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1406 entry \"Fontify Buffer\")."
1408 :set
(lambda (variable value
)
1409 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1410 :group
'vhdl-highlight
)
1412 (defcustom vhdl-highlight-special-words nil
1413 "*Non-nil means highlight words with special syntax.
1414 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1415 are highlighted accordingly.
1416 Can be used for visual support of naming conventions.
1418 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1419 entry \"Fontify Buffer\")."
1421 :set
(lambda (variable value
)
1422 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1423 :group
'vhdl-highlight
)
1425 (defcustom vhdl-highlight-forbidden-words nil
1426 "*Non-nil means highlight forbidden words.
1427 The reserved words specified in option `vhdl-forbidden-words' or having the
1428 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1429 warning color (face `vhdl-reserved-word') to indicate not to
1432 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1433 entry \"Fontify Buffer\")."
1435 :set
(lambda (variable value
)
1436 (vhdl-custom-set variable value
1437 'vhdl-words-init
'vhdl-font-lock-init
))
1438 :group
'vhdl-highlight
)
1440 (defcustom vhdl-highlight-verilog-keywords nil
1441 "*Non-nil means highlight Verilog keywords as reserved words.
1442 Verilog keywords are highlighted in a warning color (face
1443 `vhdl-reserved-word') to indicate not to use them.
1445 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1446 entry \"Fontify Buffer\")."
1448 :set
(lambda (variable value
)
1449 (vhdl-custom-set variable value
1450 'vhdl-words-init
'vhdl-font-lock-init
))
1451 :group
'vhdl-highlight
)
1453 (defcustom vhdl-highlight-translate-off nil
1454 "*Non-nil means background-highlight code excluded from translation.
1455 That is, all code between \"-- pragma translate_off\" and
1456 \"-- pragma translate_on\" is highlighted using a different background color
1457 \(face `vhdl-translate-off').
1458 Note: this might slow down on-the-fly fontification (and thus editing).
1460 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1461 entry \"Fontify Buffer\")."
1463 :set
(lambda (variable value
)
1464 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1465 :group
'vhdl-highlight
)
1467 (defcustom vhdl-highlight-case-sensitive nil
1468 "*Non-nil means consider case for highlighting.
1470 non-nil also upper-case VHDL words are highlighted, but case of words with
1471 special syntax is not considered
1472 nil only lower-case VHDL words are highlighted, but case of words with
1473 special syntax is considered
1474 Overrides local option `font-lock-keywords-case-fold-search'.
1476 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1477 entry \"Fontify Buffer\")."
1479 :group
'vhdl-highlight
)
1481 (defcustom vhdl-special-syntax-alist
1482 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1483 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1484 ("variable" "\\w+_v" "Grey50" "Grey80"))
1485 "*List of special syntax to be highlighted.
1486 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1487 syntax (as regular expression) are highlighted in the corresponding color.
1489 Name : string of words and spaces
1490 Regexp : regular expression describing word syntax
1491 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1492 Color (light): foreground color for light background
1493 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1494 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1495 Color (dark) : foreground color for dark background
1496 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1497 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1499 Can be used for visual support of naming conventions, such as highlighting
1500 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1501 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1502 common substrings or name suffices.
1503 For each entry, a new face is generated with the specified colors and name
1506 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1507 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1508 :type
'(repeat (list :tag
"Face" :indent
2
1509 (string :tag
"Name ")
1510 (regexp :tag
"Regexp " "\\w+_")
1511 (string :tag
"Color (light)")
1512 (string :tag
"Color (dark) ")))
1513 :set
(lambda (variable value
)
1514 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1515 :group
'vhdl-highlight
)
1517 (defcustom vhdl-forbidden-words
'()
1518 "*List of forbidden words to be highlighted.
1519 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1520 words are highlighted in a warning color to indicate not to use them.
1522 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1523 entry \"Fontify Buffer\")."
1524 :type
'(repeat (string :format
"%v"))
1525 :set
(lambda (variable value
)
1526 (vhdl-custom-set variable value
1527 'vhdl-words-init
'vhdl-font-lock-init
))
1528 :group
'vhdl-highlight
)
1530 (defcustom vhdl-forbidden-syntax
""
1531 "*Syntax of forbidden words to be highlighted.
1532 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1533 syntax are highlighted in a warning color to indicate not to use them.
1534 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1535 highlights identifiers with 10 or more characters).
1537 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1538 entry \"Fontify Buffer\")."
1540 :set
(lambda (variable value
)
1541 (vhdl-custom-set variable value
1542 'vhdl-words-init
'vhdl-font-lock-init
))
1543 :group
'vhdl-highlight
)
1545 (defcustom vhdl-directive-keywords
'("pragma" "synopsys")
1546 "*List of compiler directive keywords recognized for highlighting.
1548 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1549 entry \"Fontify Buffer\")."
1550 :type
'(repeat (string :format
"%v"))
1551 :set
(lambda (variable value
)
1552 (vhdl-custom-set variable value
1553 'vhdl-words-init
'vhdl-font-lock-init
))
1554 :group
'vhdl-highlight
)
1557 (defgroup vhdl-speedbar nil
1558 "Customizations for speedbar."
1561 (defcustom vhdl-speedbar-auto-open nil
1562 "*Non-nil means automatically open speedbar at startup.
1563 Alternatively, the speedbar can be opened from the VHDL menu."
1565 :group
'vhdl-speedbar
)
1567 (defcustom vhdl-speedbar-display-mode
'files
1568 "*Specifies the default displaying mode when opening speedbar.
1569 Alternatively, the displaying mode can be selected from the speedbar menu or
1570 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1571 :type
'(choice (const :tag
"Files" files
)
1572 (const :tag
"Directory hierarchy" directory
)
1573 (const :tag
"Project hierarchy" project
))
1574 :group
'vhdl-speedbar
)
1576 (defcustom vhdl-speedbar-scan-limit
'(10000000 (1000000 50))
1577 "*Limits scanning of large files and netlists.
1578 Design units: maximum file size to scan for design units
1579 Hierarchy (instances of subcomponents):
1580 File size: maximum file size to scan for instances (in bytes)
1581 Instances per arch: maximum number of instances to scan per architecture
1583 \"None\" always means that there is no limit.
1584 In case of files not or incompletely scanned, a warning message and the file
1585 names are printed out.
1586 Background: scanning for instances is considerably slower than scanning for
1587 design units, especially when there are many instances. These limits should
1588 prevent the scanning of large netlists."
1589 :type
'(list (choice :tag
"Design units"
1590 :format
"%t : %[Value Menu%] %v"
1591 (const :tag
"None" nil
)
1592 (integer :tag
"File size"))
1593 (list :tag
"Hierarchy" :indent
2
1594 (choice :tag
"File size"
1595 :format
"%t : %[Value Menu%] %v"
1596 (const :tag
"None" nil
)
1597 (integer :tag
"Size "))
1598 (choice :tag
"Instances per arch"
1599 (const :tag
"None" nil
)
1600 (integer :tag
"Number "))))
1601 :group
'vhdl-speedbar
)
1603 (defcustom vhdl-speedbar-jump-to-unit t
1604 "*Non-nil means jump to the design unit code when opened in a buffer.
1605 The buffer cursor position is left unchanged otherwise."
1607 :group
'vhdl-speedbar
)
1609 (defcustom vhdl-speedbar-update-on-saving t
1610 "*Automatically update design hierarchy when buffer is saved."
1612 :group
'vhdl-speedbar
)
1614 (defcustom vhdl-speedbar-save-cache
'(hierarchy display
)
1615 "*Automatically save modified hierarchy caches when exiting Emacs.
1616 Hierarchy: design hierarchy information
1617 Display: displaying information (which design units to expand)"
1618 :type
'(set (const :tag
"Hierarchy" hierarchy
)
1619 (const :tag
"Display" display
))
1620 :group
'vhdl-speedbar
)
1622 (defcustom vhdl-speedbar-cache-file-name
".emacs-vhdl-cache-\\1-\\2"
1623 "*Name of file for saving hierarchy cache.
1624 \"\\1\" is replaced by the project name if a project is specified,
1625 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1626 different users to have cache files in the same directory). Can also have
1627 an absolute path (i.e. all caches can be stored in one global directory)."
1629 :group
'vhdl-speedbar
)
1632 (defgroup vhdl-menu nil
1633 "Customizations for menues."
1636 (defcustom vhdl-index-menu nil
1637 "*Non-nil means add an index menu for a source file when loading.
1638 Alternatively, the speedbar can be used. Note that the index menu scans a file
1639 when it is opened, while speedbar only scans the file upon request."
1643 (defcustom vhdl-source-file-menu nil
1644 "*Non-nil means add a menu of all source files in current directory.
1645 Alternatively, the speedbar can be used."
1649 (defcustom vhdl-hideshow-menu nil
1650 "*Non-nil means add hideshow menu and functionality at startup.
1651 Hideshow can also be enabled from the VHDL Mode menu.
1652 Hideshow allows hiding code of various VHDL constructs.
1654 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1655 \"Activate Options\"."
1659 (defcustom vhdl-hide-all-init nil
1660 "*Non-nil means hide all design units initially after a file is loaded."
1665 (defgroup vhdl-print nil
1666 "Customizations for printing."
1669 (defcustom vhdl-print-two-column t
1670 "*Non-nil means print code in two columns and landscape format.
1671 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1672 prints VHDL files in a nice two-column landscape style.
1674 NOTE: Activate the new setting by restarting Emacs.
1675 Overrides `ps-print' settings locally."
1679 (defcustom vhdl-print-customize-faces t
1680 "*Non-nil means use an optimized set of faces for postscript printing.
1682 NOTE: Activate the new setting by restarting Emacs.
1683 Overrides `ps-print' settings locally."
1688 (defgroup vhdl-misc nil
1689 "Miscellaneous customizations."
1692 (defcustom vhdl-intelligent-tab t
1693 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1694 That is, if preceeding character is part of a word then complete word,
1695 else if not at beginning of line then insert tab,
1696 else if last command was a `TAB' or `RET' then dedent one step,
1697 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1698 If nil, TAB always indents current line (i.e. `TAB' is bound to
1699 `indent-according-to-mode').
1701 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1702 \"Activate Options\"."
1706 (defcustom vhdl-indent-syntax-based t
1707 "*Non-nil means indent lines of code based on their syntactic context.
1708 Otherwise, a line is indented like the previous nonblank line. This can be
1709 useful in large files where syntax-based indentation gets very slow."
1713 (defcustom vhdl-word-completion-case-sensitive nil
1714 "*Non-nil means word completion using `TAB' is case sensitive.
1715 That is, `TAB' completes words that start with the same letters and case.
1716 Otherwise, case is ignored."
1720 (defcustom vhdl-word-completion-in-minibuffer t
1721 "*Non-nil enables word completion in minibuffer (for template prompts).
1723 NOTE: Activate the new setting by restarting Emacs."
1727 (defcustom vhdl-underscore-is-part-of-word nil
1728 "*Non-nil means consider the underscore character `_' as part of word.
1729 An identifier containing underscores is then treated as a single word in
1730 select and move operations. All parts of an identifier separated by underscore
1731 are treated as single words otherwise.
1733 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1734 \"Activate Options\"."
1736 :set
(lambda (variable value
)
1737 (vhdl-custom-set variable value
'vhdl-mode-syntax-table-init
))
1741 (defgroup vhdl-related nil
1742 "Related general customizations."
1745 ;; add related general customizations
1746 (custom-add-to-group 'vhdl-related
'hideshow
'custom-group
)
1748 (custom-add-to-group 'vhdl-related
'paren-mode
'custom-variable
)
1749 (custom-add-to-group 'vhdl-related
'paren-showing
'custom-group
))
1750 (custom-add-to-group 'vhdl-related
'ps-print
'custom-group
)
1751 (custom-add-to-group 'vhdl-related
'speedbar
'custom-group
)
1752 (custom-add-to-group 'vhdl-related
'line-number-mode
'custom-variable
)
1754 (custom-add-to-group 'vhdl-related
'transient-mark-mode
'custom-variable
))
1755 (custom-add-to-group 'vhdl-related
'user-full-name
'custom-variable
)
1756 (custom-add-to-group 'vhdl-related
'mail-host-address
'custom-variable
)
1757 (custom-add-to-group 'vhdl-related
'user-mail-address
'custom-variable
)
1759 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1760 ;; Internal variables
1762 (defvar vhdl-menu-max-size
20
1763 "*Specifies the maximum size of a menu before splitting it into submenues.")
1765 (defvar vhdl-progress-interval
1
1766 "*Interval used to update progress status during long operations.
1767 If a number, percentage complete gets updated after each interval of
1768 that many seconds. To inhibit all messages, set this option to nil.")
1770 (defvar vhdl-inhibit-startup-warnings-p nil
1771 "*If non-nil, inhibits start up compatibility warnings.")
1773 (defvar vhdl-strict-syntax-p nil
1774 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1775 If the syntactic symbol for a particular line does not match a symbol
1776 in the offsets alist, an error is generated, otherwise no error is
1777 reported and the syntactic symbol is ignored.")
1779 (defvar vhdl-echo-syntactic-information-p nil
1780 "*If non-nil, syntactic info is echoed when the line is indented.")
1782 (defconst vhdl-offsets-alist-default
1787 (statement-cont . vhdl-lineup-statement-cont
)
1788 (statement-block-intro .
+)
1789 (statement-case-intro .
+)
1790 (case-alternative .
+)
1791 (comment . vhdl-lineup-comment
)
1794 (arglist-cont-nonempty . vhdl-lineup-arglist
)
1795 (arglist-close . vhdl-lineup-arglist
)
1802 "Default settings for offsets of syntactic elements.
1803 Do not change this constant! See the variable `vhdl-offsets-alist' for
1806 (defvar vhdl-offsets-alist
(copy-alist vhdl-offsets-alist-default
)
1807 "*Association list of syntactic element symbols and indentation offsets.
1808 As described below, each cons cell in this list has the form:
1810 (SYNTACTIC-SYMBOL . OFFSET)
1812 When a line is indented, `vhdl-mode' first determines the syntactic
1813 context of the line by generating a list of symbols called syntactic
1814 elements. This list can contain more than one syntactic element and
1815 the global variable `vhdl-syntactic-context' contains the context list
1816 for the line being indented. Each element in this list is actually a
1817 cons cell of the syntactic symbol and a buffer position. This buffer
1818 position is call the relative indent point for the line. Some
1819 syntactic symbols may not have a relative indent point associated with
1822 After the syntactic context list for a line is generated, `vhdl-mode'
1823 calculates the absolute indentation for the line by looking at each
1824 syntactic element in the list. First, it compares the syntactic
1825 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1826 finds a match, it adds the OFFSET to the column of the relative indent
1827 point. The sum of this calculation for each element in the syntactic
1828 list is the absolute offset for line being indented.
1830 If the syntactic element does not match any in the `vhdl-offsets-alist',
1831 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1832 the element is ignored.
1834 Actually, OFFSET can be an integer, a function, a variable, or one of
1835 the following symbols: `+', `-', `++', or `--'. These latter
1836 designate positive or negative multiples of `vhdl-basic-offset',
1837 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1838 called with a single argument containing the cons of the syntactic
1839 element symbol and the relative indent point. The function should
1840 return an integer offset.
1842 Here is the current list of valid syntactic element symbols:
1844 string -- inside multi-line string
1845 block-open -- statement block open
1846 block-close -- statement block close
1847 statement -- a VHDL statement
1848 statement-cont -- a continuation of a VHDL statement
1849 statement-block-intro -- the first line in a new statement block
1850 statement-case-intro -- the first line in a case alternative block
1851 case-alternative -- a case statement alternative clause
1852 comment -- a line containing only a comment
1853 arglist-intro -- the first line in an argument list
1854 arglist-cont -- subsequent argument list lines when no
1855 arguments follow on the same line as the
1856 the arglist opening paren
1857 arglist-cont-nonempty -- subsequent argument list lines when at
1858 least one argument follows on the same
1859 line as the arglist opening paren
1860 arglist-close -- the solo close paren of an argument list
1861 entity -- inside an entity declaration
1862 configuration -- inside a configuration declaration
1863 package -- inside a package declaration
1864 architecture -- inside an architecture body
1865 package-body -- inside a package body")
1867 (defvar vhdl-comment-only-line-offset
0
1868 "*Extra offset for line which contains only the start of a comment.
1869 Can contain an integer or a cons cell of the form:
1871 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1873 Where NON-ANCHORED-OFFSET is the amount of offset given to
1874 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1875 the amount of offset to give column-zero anchored comment-only lines.
1876 Just an integer as value is equivalent to (<val> . 0)")
1878 (defvar vhdl-special-indent-hook nil
1879 "*Hook for user defined special indentation adjustments.
1880 This hook gets called after a line is indented by the mode.")
1882 (defvar vhdl-style-alist
1884 (vhdl-basic-offset .
4)
1885 (vhdl-offsets-alist .
())))
1886 "Styles of Indentation.
1887 Elements of this alist are of the form:
1889 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1891 where STYLE-STRING is a short descriptive string used to select a
1892 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1893 value for that variable when using the selected style.
1895 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1896 case, the VALUE is a list containing elements of the form:
1898 (SYNTACTIC-SYMBOL . VALUE)
1900 as described in `vhdl-offsets-alist'. These are passed directly to
1901 `vhdl-set-offset' so there is no need to set every syntactic symbol in
1902 your style, only those that are different from the default.")
1904 ;; dynamically append the default value of most variables
1905 (or (assoc "Default" vhdl-style-alist
)
1906 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1907 vhdl-strict-syntax-p
1908 vhdl-echo-syntactic-information-p
1911 vhdl-comment-only-line-offset
))
1912 (default (cons "Default"
1916 (cons var
(symbol-value var
))))
1918 (setq vhdl-style-alist
(cons default vhdl-style-alist
))))
1920 (defvar vhdl-mode-hook nil
1921 "*Hook called by `vhdl-mode'.")
1924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1925 ;;; Required packages
1926 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1930 (require 'compile
) ; XEmacs
1932 (require 'hippie-exp
)
1934 ;; optional (minimize warning messages during compile)
1936 (require 'font-lock
)
1938 (require 'speedbar
))
1941 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1943 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1945 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1946 ;; XEmacs compatibility
1949 (defun vhdl-keep-region-active ()
1950 "Do whatever is necessary to keep the region active in XEmacs.
1951 Ignore byte-compiler warnings you might see."
1952 (and (boundp 'zmacs-region-stays
)
1953 (setq zmacs-region-stays t
)))
1955 ;; `wildcard-to-regexp' is included only in XEmacs 21
1956 (unless (fboundp 'wildcard-to-regexp
)
1957 (defun wildcard-to-regexp (wildcard)
1958 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
1959 (let* ((i (string-match "[*?]" wildcard
))
1960 (result (substring wildcard
0 i
))
1961 (len (length wildcard
)))
1964 (let ((ch (aref wildcard i
)))
1965 (setq result
(concat result
1966 (cond ((eq ch ?
*) "[^\000]*")
1967 ((eq ch ??
) "[^\000]")
1968 (t (char-to-string ch
)))))
1970 (concat "\\`" result
"\\'"))))
1972 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
1973 ;; `regexp-opt' accelerates fontification by 10-20%
1974 (unless (fboundp 'regexp-opt
)
1975 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
1976 (defun regexp-opt (strings &optional paren
)
1977 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
1978 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
))))
1980 ;; `match-string-no-properties' undefined (XEmacs, what else?)
1981 (unless (fboundp 'match-string-no-properties
)
1982 (defalias 'match-string-no-properties
'match-string
))
1984 ;; `subst-char-in-string' undefined (XEmacs)
1985 (unless (fboundp 'subst-char-in-string
)
1986 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
1987 (let ((i (length string
))
1988 (newstr (if inplace string
(copy-sequence string
))))
1991 (if (eq (aref newstr i
) fromchar
) (aset newstr i tochar
)))
1994 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
1995 (when (and vhdl-xemacs
(string< itimer-version
"1.09")
1996 (not noninteractive
))
1998 (when (string< itimer-version
"1.09")
1999 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2000 (beep) (sit-for 5)))
2002 ;; `file-expand-wildcards' undefined (XEmacs)
2003 (unless (fboundp 'file-expand-wildcards
)
2004 (defun file-expand-wildcards (pattern &optional full
)
2005 "Taken from Emacs' `files.el'."
2006 (let* ((nondir (file-name-nondirectory pattern
))
2007 (dirpart (file-name-directory pattern
))
2008 (dirs (if (and dirpart
(string-match "[[*?]" dirpart
))
2009 (mapcar 'file-name-as-directory
2010 (file-expand-wildcards (directory-file-name dirpart
)))
2014 (when (or (null (car dirs
)) ; Possible if DIRPART is not wild.
2015 (file-directory-p (directory-file-name (car dirs
))))
2016 (let ((this-dir-contents
2018 (mapcar #'(lambda (name)
2019 (unless (string-match "\\`\\.\\.?\\'"
2020 (file-name-nondirectory name
))
2022 (directory-files (or (car dirs
) ".") full
2023 (wildcard-to-regexp nondir
))))))
2026 (if (and (car dirs
) (not full
))
2027 (mapcar (function (lambda (name) (concat (car dirs
) name
)))
2031 (setq dirs
(cdr dirs
)))
2034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2035 ;; Compatibility with older VHDL Mode versions
2037 (defvar vhdl-warnings nil
2038 "Warnings to tell the user during start up.")
2040 (defun vhdl-run-when-idle (secs repeat function
)
2041 "Wait until idle, then run FUNCTION."
2042 (if (fboundp 'start-itimer
)
2043 (start-itimer "vhdl-mode" function secs repeat t
)
2044 ; (run-with-idle-timer secs repeat function)))
2045 ;; explicitely activate timer (necessary when Emacs is already idle)
2046 (aset (run-with-idle-timer secs repeat function
) 0 nil
)))
2048 (defun vhdl-warning-when-idle (&rest args
)
2049 "Wait until idle, then print out warning STRING and beep."
2051 (vhdl-warning (apply 'format args
) t
)
2052 (unless vhdl-warnings
2053 (vhdl-run-when-idle .1 nil
'vhdl-print-warnings
))
2054 (setq vhdl-warnings
(cons (apply 'format args
) vhdl-warnings
))))
2056 (defun vhdl-warning (string &optional nobeep
)
2057 "Print out warning STRING and beep."
2058 (message (concat "WARNING: " string
))
2059 (unless (or nobeep noninteractive
) (beep)))
2061 (defun vhdl-print-warnings ()
2062 "Print out messages in variable `vhdl-warnings'."
2063 (let ((no-warnings (length vhdl-warnings
)))
2064 (setq vhdl-warnings
(nreverse vhdl-warnings
))
2065 (while vhdl-warnings
2066 (message (concat "WARNING: " (car vhdl-warnings
)))
2067 (setq vhdl-warnings
(cdr vhdl-warnings
)))
2069 (when (> no-warnings
1)
2070 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2072 ;; Backward compatibility checks and fixes
2073 ;; option `vhdl-compiler' changed format
2074 (unless (stringp vhdl-compiler
)
2075 (setq vhdl-compiler
"ModelSim")
2076 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2078 ;; option `vhdl-standard' changed format
2079 (unless (listp vhdl-standard
)
2080 (setq vhdl-standard
'(87 nil
))
2081 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2083 ;; option `vhdl-model-alist' changed format
2084 (when (= (length (car vhdl-model-alist
)) 3)
2085 (let ((old-alist vhdl-model-alist
)
2088 (setq new-alist
(cons (append (car old-alist
) '("")) new-alist
))
2089 (setq old-alist
(cdr old-alist
)))
2090 (setq vhdl-model-alist
(nreverse new-alist
)))
2091 (customize-save-variable 'vhdl-model-alist vhdl-model-alist
))
2093 ;; option `vhdl-project-alist' changed format
2094 (when (= (length (car vhdl-project-alist
)) 3)
2095 (let ((old-alist vhdl-project-alist
)
2098 (setq new-alist
(cons (append (car old-alist
) '("")) new-alist
))
2099 (setq old-alist
(cdr old-alist
)))
2100 (setq vhdl-project-alist
(nreverse new-alist
)))
2101 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2103 ;; option `vhdl-project-alist' changed format (3.31.1)
2104 (when (= (length (car vhdl-project-alist
)) 4)
2105 (let ((old-alist vhdl-project-alist
)
2108 (setq elem
(car old-alist
))
2110 (cons (list (nth 0 elem
) (nth 1 elem
) "" (nth 2 elem
)
2111 nil
"./" "work" "work/" "Makefile" (nth 3 elem
))
2113 (setq old-alist
(cdr old-alist
)))
2114 (setq vhdl-project-alist
(nreverse new-alist
)))
2115 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2117 ;; option `vhdl-project-alist' changed format (3.31.12)
2118 (when (= (length (car vhdl-project-alist
)) 10)
2119 (let ((tmp-alist vhdl-project-alist
))
2121 (setcdr (nthcdr 3 (car tmp-alist
))
2122 (cons "" (nthcdr 4 (car tmp-alist
))))
2123 (setq tmp-alist
(cdr tmp-alist
))))
2124 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2126 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2127 (when (= (length (car vhdl-compiler-alist
)) 7)
2128 (let ((old-alist vhdl-compiler-alist
)
2131 (setq elem
(car old-alist
))
2133 (cons (list (nth 0 elem
) (nth 1 elem
) "" "make -f \\1"
2134 (if (equal (nth 3 elem
) "") nil
(nth 3 elem
))
2135 (nth 4 elem
) "work/" "Makefile" (downcase (nth 0 elem
))
2136 (nth 5 elem
) (nth 6 elem
) nil
)
2138 (setq old-alist
(cdr old-alist
)))
2139 (setq vhdl-compiler-alist
(nreverse new-alist
)))
2140 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2142 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2143 (when (= (length (car vhdl-compiler-alist
)) 12)
2144 (let ((tmp-alist vhdl-compiler-alist
))
2146 (setcdr (nthcdr 4 (car tmp-alist
))
2147 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist
))))
2148 (setq tmp-alist
(cdr tmp-alist
))))
2149 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2151 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2152 (when (= (length (car vhdl-compiler-alist
)) 13)
2153 (let ((tmp-alist vhdl-compiler-alist
))
2155 (setcdr (nthcdr 3 (car tmp-alist
))
2156 (cons "" (nthcdr 4 (car tmp-alist
))))
2157 (setq tmp-alist
(cdr tmp-alist
))))
2158 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2160 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2161 (when (= (length (nth 11 (car vhdl-compiler-alist
))) 3)
2162 (let ((tmp-alist vhdl-compiler-alist
))
2164 (setcdr (nthcdr 2 (nth 11 (car tmp-alist
)))
2166 (setq tmp-alist
(cdr tmp-alist
))))
2167 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2169 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2170 (when (equal vhdl-project
"")
2171 (setq vhdl-project nil
)
2172 (customize-save-variable 'vhdl-project vhdl-project
))
2174 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2175 (when (stringp vhdl-project-file-name
)
2176 (setq vhdl-project-file-name
(list vhdl-project-file-name
))
2177 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name
))
2179 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2180 (if (not (boundp 'speedbar-indentation-width
))
2181 (defvar speedbar-indentation-width
2)
2182 ;; set default to 2 if not already customized
2183 (unless (get 'speedbar-indentation-width
'saved-value
)
2184 (setq speedbar-indentation-width
2)))
2187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2188 ;;; Help functions / inline substitutions / macros
2189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2191 (defun vhdl-standard-p (standard)
2192 "Check if STANDARD is specified as used standard."
2193 (or (eq standard
(car vhdl-standard
))
2194 (memq standard
(cadr vhdl-standard
))))
2196 (defun vhdl-project-p (&optional warning
)
2197 "Return non-nil if a project is displayed, i.e. directories or files are
2199 (if (assoc vhdl-project vhdl-project-alist
)
2201 (when (and vhdl-project warning
)
2202 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project
))
2205 (defun vhdl-resolve-env-variable (string)
2206 "Resolve environment variables in STRING."
2207 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string
)
2208 (setq string
(concat (match-string 1 string
)
2209 (getenv (match-string 2 string
))
2210 (match-string 4 string
))))
2213 (defun vhdl-default-directory ()
2214 "Return the default directory of the current project or the directory of the
2215 current buffer if no project is defined."
2216 (if (vhdl-project-p)
2217 (expand-file-name (vhdl-resolve-env-variable
2218 (nth 1 (aget vhdl-project-alist vhdl-project
))))
2221 (defmacro vhdl-prepare-search-1
(&rest body
)
2222 "Enable case insensitive search and switch to syntax table that includes '_',
2223 then execute BODY, and finally restore the old environment. Used for
2224 consistent searching."
2225 `(let ((case-fold-search t
) ; case insensitive search
2226 (current-syntax-table (syntax-table))
2228 (restore-prog ; program to restore enviroment
2230 ;; restore syntax table
2231 (set-syntax-table current-syntax-table
))))
2232 ;; use extended syntax table
2233 (set-syntax-table vhdl-mode-ext-syntax-table
)
2234 ;; execute BODY safely
2236 (condition-case info
2238 (error (eval restore-prog
) ; restore environment on error
2239 (error (cadr info
))))) ; pass error up
2240 ;; restore environment
2244 (defmacro vhdl-prepare-search-2
(&rest body
)
2245 "Enable case insensitive search, switch to syntax table that includes '_',
2246 and remove `intangible' overlays, then execute BODY, and finally restore the
2247 old environment. Used for consistent searching."
2248 `(let ((case-fold-search t
) ; case insensitive search
2249 (current-syntax-table (syntax-table))
2250 result overlay-all-list overlay-intangible-list overlay
2251 (restore-prog ; program to restore enviroment
2253 ;; restore syntax table
2254 (set-syntax-table current-syntax-table
)
2255 ;; restore `intangible' overlays
2256 (when (fboundp 'overlay-lists
)
2257 (while overlay-intangible-list
2258 (overlay-put (car overlay-intangible-list
) 'intangible t
)
2259 (setq overlay-intangible-list
2260 (cdr overlay-intangible-list
)))))))
2261 ;; use extended syntax table
2262 (set-syntax-table vhdl-mode-ext-syntax-table
)
2263 ;; remove `intangible' overlays
2264 (when (fboundp 'overlay-lists
)
2265 (setq overlay-all-list
(overlay-lists))
2266 (setq overlay-all-list
2267 (append (car overlay-all-list
) (cdr overlay-all-list
)))
2268 (while overlay-all-list
2269 (setq overlay
(car overlay-all-list
))
2270 (when (memq 'intangible
(overlay-properties overlay
))
2271 (setq overlay-intangible-list
2272 (cons overlay overlay-intangible-list
))
2273 (overlay-put overlay
'intangible nil
))
2274 (setq overlay-all-list
(cdr overlay-all-list
))))
2275 ;; execute BODY safely
2277 (condition-case info
2279 (error (eval restore-prog
) ; restore environment on error
2280 (error (cadr info
))))) ; pass error up
2281 ;; restore environment
2285 (defmacro vhdl-visit-file
(file-name issue-error
&rest body
)
2286 "Visit file FILE-NAME and execute BODY."
2287 `(if (null ,file-name
)
2289 (unless (file-directory-p ,file-name
)
2290 (let ((source-buffer (current-buffer))
2291 (visiting-buffer (find-buffer-visiting ,file-name
))
2293 (when (or (and visiting-buffer
(set-buffer visiting-buffer
))
2295 (progn (set-buffer (create-file-buffer ,file-name
))
2296 (setq file-opened t
)
2297 (vhdl-insert-file-contents ,file-name
)
2298 (modify-syntax-entry ?\-
". 12" (syntax-table))
2299 (modify-syntax-entry ?
\n ">" (syntax-table))
2300 (modify-syntax-entry ?\^M
">" (syntax-table))
2301 (modify-syntax-entry ?_
"w" (syntax-table))
2306 (when file-opened
(kill-buffer (current-buffer)))
2307 (set-buffer source-buffer
)
2308 (error "ERROR: File cannot be opened: \"%s\"" ,file-name
))
2309 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name
) t
)
2311 (condition-case info
2316 (when file-opened
(kill-buffer (current-buffer)))
2317 (set-buffer source-buffer
)
2318 (error (cadr info
)))
2319 (vhdl-warning (cadr info
))))))
2320 (when file-opened
(kill-buffer (current-buffer)))
2321 (set-buffer source-buffer
)))))
2323 (defun vhdl-insert-file-contents (filename)
2324 "Nicked from `insert-file-contents-literally', but allow coding system
2326 (let ((format-alist nil
)
2327 (after-insert-file-functions nil
)
2328 (jka-compr-compression-info-list nil
))
2329 (insert-file-contents filename t
)))
2331 (defun vhdl-sort-alist (alist)
2333 (sort alist
(function (lambda (a b
) (string< (car a
) (car b
))))))
2335 (defun vhdl-get-subdirs (directory)
2336 "Recursively get subdirectories of DIRECTORY."
2337 (let ((dir-list (list (file-name-as-directory directory
)))
2339 (setq file-list
(vhdl-directory-files directory t
"\\w.*"))
2341 (when (file-directory-p (car file-list
))
2342 (setq dir-list
(append dir-list
(vhdl-get-subdirs (car file-list
)))))
2343 (setq file-list
(cdr file-list
)))
2346 (defun vhdl-aput (alist-symbol key
&optional value
)
2347 "As `aput', but delete key-value pair if VALUE is nil."
2349 (aput alist-symbol key value
)
2350 (adelete alist-symbol key
)))
2352 (defun vhdl-delete (elt list
)
2353 "Delete by side effect the first occurrence of ELT as a member of LIST."
2354 (setq list
(cons nil list
))
2356 (while (and (cdr list1
) (not (equal elt
(cadr list1
))))
2357 (setq list1
(cdr list1
)))
2359 (setcdr list1
(cddr list1
))))
2362 (defun vhdl-speedbar-refresh (&optional key
)
2363 "Refresh directory or project with name KEY."
2364 (when (and (boundp 'speedbar-frame
)
2365 (frame-live-p speedbar-frame
))
2367 (last-frame (selected-frame)))
2370 (select-frame speedbar-frame
)
2371 (when (save-excursion
2372 (goto-char (point-min))
2373 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key
"$") nil t
))
2374 (goto-char (match-end 1))
2375 (speedbar-do-function-pointer)
2377 (speedbar-do-function-pointer)
2378 (message "Refreshing speedbar...done"))
2379 (select-frame last-frame
)))))
2381 (defun vhdl-show-messages ()
2382 "Get *Messages* buffer to show recent messages."
2384 (display-buffer (if vhdl-xemacs
" *Message-Log*" "*Messages*")))
2386 (defun vhdl-use-direct-instantiation ()
2387 "Return whether direct instantiation is used."
2388 (or (eq vhdl-use-direct-instantiation
'always
)
2389 (and (eq vhdl-use-direct-instantiation
'standard
)
2390 (not (vhdl-standard-p '87)))))
2392 (defun vhdl-max-marker (marker1 marker2
)
2393 "Return larger marker."
2394 (if (> marker1 marker2
) marker1 marker2
))
2396 (defun vhdl-goto-marker (marker)
2397 "Goto marker in appropriate buffer."
2398 (when (markerp marker
)
2399 (set-buffer (marker-buffer marker
)))
2402 (defun vhdl-menu-split (list title
)
2403 "Split menu LIST into several submenues, if number of
2404 elements > `vhdl-menu-max-size'."
2405 (if (> (length list
) vhdl-menu-max-size
)
2412 (setq sublist
(cons (car remain
) sublist
))
2413 (setq remain
(cdr remain
))
2415 (if (= i vhdl-menu-max-size
)
2417 (setq result
(cons (cons (format "%s %s" title menuno
)
2418 (nreverse sublist
)) result
))
2420 (setq menuno
(+ menuno
1))
2421 (setq sublist
'()))))
2423 (setq result
(cons (cons (format "%s %s" title menuno
)
2424 (nreverse sublist
)) result
)))
2429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2431 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2433 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2436 (defvar vhdl-template-map nil
2437 "Keymap for VHDL templates.")
2439 (defun vhdl-template-map-init ()
2440 "Initialize `vhdl-template-map'."
2441 (setq vhdl-template-map
(make-sparse-keymap))
2442 ;; key bindings for VHDL templates
2443 (define-key vhdl-template-map
"al" 'vhdl-template-alias
)
2444 (define-key vhdl-template-map
"ar" 'vhdl-template-architecture
)
2445 (define-key vhdl-template-map
"at" 'vhdl-template-assert
)
2446 (define-key vhdl-template-map
"ad" 'vhdl-template-attribute-decl
)
2447 (define-key vhdl-template-map
"as" 'vhdl-template-attribute-spec
)
2448 (define-key vhdl-template-map
"bl" 'vhdl-template-block
)
2449 (define-key vhdl-template-map
"ca" 'vhdl-template-case-is
)
2450 (define-key vhdl-template-map
"cd" 'vhdl-template-component-decl
)
2451 (define-key vhdl-template-map
"ci" 'vhdl-template-component-inst
)
2452 (define-key vhdl-template-map
"cs" 'vhdl-template-conditional-signal-asst
)
2453 (define-key vhdl-template-map
"Cb" 'vhdl-template-block-configuration
)
2454 (define-key vhdl-template-map
"Cc" 'vhdl-template-component-conf
)
2455 (define-key vhdl-template-map
"Cd" 'vhdl-template-configuration-decl
)
2456 (define-key vhdl-template-map
"Cs" 'vhdl-template-configuration-spec
)
2457 (define-key vhdl-template-map
"co" 'vhdl-template-constant
)
2458 (define-key vhdl-template-map
"di" 'vhdl-template-disconnect
)
2459 (define-key vhdl-template-map
"el" 'vhdl-template-else
)
2460 (define-key vhdl-template-map
"ei" 'vhdl-template-elsif
)
2461 (define-key vhdl-template-map
"en" 'vhdl-template-entity
)
2462 (define-key vhdl-template-map
"ex" 'vhdl-template-exit
)
2463 (define-key vhdl-template-map
"fi" 'vhdl-template-file
)
2464 (define-key vhdl-template-map
"fg" 'vhdl-template-for-generate
)
2465 (define-key vhdl-template-map
"fl" 'vhdl-template-for-loop
)
2466 (define-key vhdl-template-map
"\C-f" 'vhdl-template-footer
)
2467 (define-key vhdl-template-map
"fb" 'vhdl-template-function-body
)
2468 (define-key vhdl-template-map
"fd" 'vhdl-template-function-decl
)
2469 (define-key vhdl-template-map
"ge" 'vhdl-template-generic
)
2470 (define-key vhdl-template-map
"gd" 'vhdl-template-group-decl
)
2471 (define-key vhdl-template-map
"gt" 'vhdl-template-group-template
)
2472 (define-key vhdl-template-map
"\C-h" 'vhdl-template-header
)
2473 (define-key vhdl-template-map
"ig" 'vhdl-template-if-generate
)
2474 (define-key vhdl-template-map
"it" 'vhdl-template-if-then
)
2475 (define-key vhdl-template-map
"li" 'vhdl-template-library
)
2476 (define-key vhdl-template-map
"lo" 'vhdl-template-bare-loop
)
2477 (define-key vhdl-template-map
"\C-m" 'vhdl-template-modify
)
2478 (define-key vhdl-template-map
"\C-t" 'vhdl-template-insert-date
)
2479 (define-key vhdl-template-map
"ma" 'vhdl-template-map
)
2480 (define-key vhdl-template-map
"ne" 'vhdl-template-next
)
2481 (define-key vhdl-template-map
"ot" 'vhdl-template-others
)
2482 (define-key vhdl-template-map
"Pd" 'vhdl-template-package-decl
)
2483 (define-key vhdl-template-map
"Pb" 'vhdl-template-package-body
)
2484 (define-key vhdl-template-map
"(" 'vhdl-template-paired-parens
)
2485 (define-key vhdl-template-map
"po" 'vhdl-template-port
)
2486 (define-key vhdl-template-map
"pb" 'vhdl-template-procedure-body
)
2487 (define-key vhdl-template-map
"pd" 'vhdl-template-procedure-decl
)
2488 (define-key vhdl-template-map
"pc" 'vhdl-template-process-comb
)
2489 (define-key vhdl-template-map
"ps" 'vhdl-template-process-seq
)
2490 (define-key vhdl-template-map
"rp" 'vhdl-template-report
)
2491 (define-key vhdl-template-map
"rt" 'vhdl-template-return
)
2492 (define-key vhdl-template-map
"ss" 'vhdl-template-selected-signal-asst
)
2493 (define-key vhdl-template-map
"si" 'vhdl-template-signal
)
2494 (define-key vhdl-template-map
"su" 'vhdl-template-subtype
)
2495 (define-key vhdl-template-map
"ty" 'vhdl-template-type
)
2496 (define-key vhdl-template-map
"us" 'vhdl-template-use
)
2497 (define-key vhdl-template-map
"va" 'vhdl-template-variable
)
2498 (define-key vhdl-template-map
"wa" 'vhdl-template-wait
)
2499 (define-key vhdl-template-map
"wl" 'vhdl-template-while-loop
)
2500 (define-key vhdl-template-map
"wi" 'vhdl-template-with
)
2501 (define-key vhdl-template-map
"wc" 'vhdl-template-clocked-wait
)
2502 (define-key vhdl-template-map
"\C-pb" 'vhdl-template-package-numeric-bit
)
2503 (define-key vhdl-template-map
"\C-pn" 'vhdl-template-package-numeric-std
)
2504 (define-key vhdl-template-map
"\C-ps" 'vhdl-template-package-std-logic-1164
)
2505 (define-key vhdl-template-map
"\C-pA" 'vhdl-template-package-std-logic-arith
)
2506 (define-key vhdl-template-map
"\C-pM" 'vhdl-template-package-std-logic-misc
)
2507 (define-key vhdl-template-map
"\C-pS" 'vhdl-template-package-std-logic-signed
)
2508 (define-key vhdl-template-map
"\C-pT" 'vhdl-template-package-std-logic-textio
)
2509 (define-key vhdl-template-map
"\C-pU" 'vhdl-template-package-std-logic-unsigned
)
2510 (define-key vhdl-template-map
"\C-pt" 'vhdl-template-package-textio
)
2511 (define-key vhdl-template-map
"\C-dn" 'vhdl-template-directive-translate-on
)
2512 (define-key vhdl-template-map
"\C-df" 'vhdl-template-directive-translate-off
)
2513 (define-key vhdl-template-map
"\C-dN" 'vhdl-template-directive-synthesis-on
)
2514 (define-key vhdl-template-map
"\C-dF" 'vhdl-template-directive-synthesis-off
)
2515 (define-key vhdl-template-map
"\C-q" 'vhdl-template-search-prompt
)
2516 (when (vhdl-standard-p 'ams
)
2517 (define-key vhdl-template-map
"br" 'vhdl-template-break
)
2518 (define-key vhdl-template-map
"cu" 'vhdl-template-case-use
)
2519 (define-key vhdl-template-map
"iu" 'vhdl-template-if-use
)
2520 (define-key vhdl-template-map
"lm" 'vhdl-template-limit
)
2521 (define-key vhdl-template-map
"na" 'vhdl-template-nature
)
2522 (define-key vhdl-template-map
"pa" 'vhdl-template-procedural
)
2523 (define-key vhdl-template-map
"qf" 'vhdl-template-quantity-free
)
2524 (define-key vhdl-template-map
"qb" 'vhdl-template-quantity-branch
)
2525 (define-key vhdl-template-map
"qs" 'vhdl-template-quantity-source
)
2526 (define-key vhdl-template-map
"sn" 'vhdl-template-subnature
)
2527 (define-key vhdl-template-map
"te" 'vhdl-template-terminal
)
2529 (when (vhdl-standard-p 'math
)
2530 (define-key vhdl-template-map
"\C-pc" 'vhdl-template-package-math-complex
)
2531 (define-key vhdl-template-map
"\C-pr" 'vhdl-template-package-math-real
)
2534 ;; initialize template map for VHDL Mode
2535 (vhdl-template-map-init)
2537 (defun vhdl-function-name (prefix string
&optional postfix
)
2538 "Generate a Lisp function name.
2539 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2540 STRING are replaced by `-' and substrings are converted to lower case."
2541 (let ((name prefix
))
2542 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string
)
2544 (concat name
"-" (downcase (substring string
0 (match-end 1)))))
2545 (setq string
(substring string
(match-beginning 2))))
2546 (when postfix
(setq name
(concat name
"-" postfix
)))
2549 (defvar vhdl-model-map nil
2550 "Keymap for VHDL models.")
2552 (defun vhdl-model-map-init ()
2553 "Initialize `vhdl-model-map'."
2554 (setq vhdl-model-map
(make-sparse-keymap))
2555 ;; key bindings for VHDL models
2556 (let ((model-alist vhdl-model-alist
) model
)
2558 (setq model
(car model-alist
))
2559 (define-key vhdl-model-map
(nth 2 model
)
2560 (vhdl-function-name "vhdl-model" (nth 0 model
)))
2561 (setq model-alist
(cdr model-alist
)))))
2563 ;; initialize user model map for VHDL Mode
2564 (vhdl-model-map-init)
2566 (defvar vhdl-mode-map nil
2567 "Keymap for VHDL Mode.")
2569 (defun vhdl-mode-map-init ()
2570 "Initialize `vhdl-mode-map'."
2571 (setq vhdl-mode-map
(make-sparse-keymap))
2572 ;; template key bindings
2573 (define-key vhdl-mode-map
"\C-c\C-t" vhdl-template-map
)
2574 ;; model key bindings
2575 (define-key vhdl-mode-map
"\C-c\C-m" vhdl-model-map
)
2576 ;; standard key bindings
2577 (define-key vhdl-mode-map
"\M-a" 'vhdl-beginning-of-statement
)
2578 (define-key vhdl-mode-map
"\M-e" 'vhdl-end-of-statement
)
2579 (define-key vhdl-mode-map
"\M-\C-f" 'vhdl-forward-sexp
)
2580 (define-key vhdl-mode-map
"\M-\C-b" 'vhdl-backward-sexp
)
2581 (define-key vhdl-mode-map
"\M-\C-u" 'vhdl-backward-up-list
)
2582 (define-key vhdl-mode-map
"\M-\C-a" 'vhdl-backward-same-indent
)
2583 (define-key vhdl-mode-map
"\M-\C-e" 'vhdl-forward-same-indent
)
2584 (unless vhdl-xemacs
; would override `M-backspace' in XEmacs
2585 (define-key vhdl-mode-map
"\M-\C-h" 'vhdl-mark-defun
))
2586 (define-key vhdl-mode-map
"\M-\C-q" 'vhdl-indent-sexp
)
2587 (define-key vhdl-mode-map
"\M-^" 'vhdl-delete-indentation
)
2588 ;; backspace/delete key bindings
2589 (define-key vhdl-mode-map
[backspace] 'backward-delete-char-untabify)
2590 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2591 (define-key vhdl-mode-map [delete] 'delete-char)
2592 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2593 ;; mode specific key bindings
2594 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2595 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2596 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2597 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2598 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2599 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2600 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2601 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2602 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2603 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2604 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2605 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2606 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2607 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2608 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2609 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2610 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2611 (if vhdl-xemacs ; `... C-g' not allowed in XEmacs
2612 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2613 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2614 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2615 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2616 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2617 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2618 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2619 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2620 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2621 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2622 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2623 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2624 (define-key vhdl-mode-map "\C-c\C-c\C-n" 'vhdl-compose-new-component)
2625 (define-key vhdl-mode-map "\C-c\C-c\C-p" 'vhdl-compose-place-component)
2626 (define-key vhdl-mode-map "\C-c\C-c\C-w" 'vhdl-compose-wire-components)
2627 (define-key vhdl-mode-map "\C-c\C-c\C-k" 'vhdl-compose-components-package)
2628 (define-key vhdl-mode-map "\C-cc" 'vhdl-comment-uncomment-region)
2629 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2630 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2631 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2632 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2633 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2634 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2635 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2636 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2637 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2638 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2639 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2640 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2641 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2642 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2643 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2644 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2645 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2646 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2647 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2648 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2649 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2650 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2651 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2652 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2653 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2654 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2655 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2656 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2657 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2658 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2659 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2660 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2661 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2662 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2663 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2664 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2665 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2666 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2667 (define-key vhdl-mode-map "\C-cf" 'vhdl-fontify-buffer)
2668 (define-key vhdl-mode-map "\C-cs" 'vhdl-statistics-buffer)
2669 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2670 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2671 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2672 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2673 ;; insert commands bindings
2674 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2675 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2676 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2677 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2678 ;; electric key bindings
2679 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2680 (if vhdl-intelligent-tab
2681 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab)
2682 ;; The default binding of TAB already calls `indent-according-to-mode'.
2683 ;; (define-key vhdl-mode-map "\t" 'indent-according-to-mode)
2685 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2686 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2687 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2688 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2689 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2690 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2691 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2692 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2693 (when (vhdl-standard-p 'ams)
2694 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2696 ;; initialize mode map for VHDL Mode
2697 (vhdl-mode-map-init)
2699 ;; define special minibuffer keymap for enabling word completion in minibuffer
2700 ;; (useful in template generator prompts)
2701 (defvar vhdl-minibuffer-local-map
2702 (let ((map (make-sparse-keymap)))
2703 (set-keymap-parent map minibuffer-local-map)
2704 (when vhdl-word-completion-in-minibuffer
2705 (define-key map "\t" 'vhdl-minibuffer-tab))
2707 "Keymap for minibuffer used in VHDL Mode.")
2709 ;; set up electric character functions to work with
2710 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2714 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2715 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2716 '(vhdl-electric-space
2718 vhdl-electric-return
2720 vhdl-electric-open-bracket
2721 vhdl-electric-close-bracket
2723 vhdl-electric-semicolon
2725 vhdl-electric-period
2726 vhdl-electric-equal))
2728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2731 (defvar vhdl-mode-syntax-table nil
2732 "Syntax table used in `vhdl-mode' buffers.")
2734 (defvar vhdl-mode-ext-syntax-table nil
2735 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2737 (defun vhdl-mode-syntax-table-init ()
2738 "Initialize `vhdl-mode-syntax-table'."
2739 (setq vhdl-mode-syntax-table (make-syntax-table))
2740 ;; define punctuation
2741 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2742 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2743 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2744 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2745 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2746 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2747 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2748 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2749 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2750 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2751 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2752 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2753 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2754 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2755 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2756 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2758 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2759 ;; define underscore
2760 (when vhdl-underscore-is-part-of-word
2761 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2762 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2763 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2764 ;; and \n and \^M end a comment
2765 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2766 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2767 ;; define parentheses to match
2768 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2769 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2770 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2771 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2772 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2773 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2774 ;; extended syntax table including '_' (for simpler search regexps)
2775 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2776 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2778 ;; initialize syntax table for VHDL Mode
2779 (vhdl-mode-syntax-table-init)
2781 (defvar vhdl-syntactic-context nil
2782 "Buffer local variable containing syntactic analysis list.")
2783 (make-variable-buffer-local 'vhdl-syntactic-context)
2785 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2786 ;; Abbrev ook bindings
2788 (defvar vhdl-mode-abbrev-table nil
2789 "Abbrev table to use in `vhdl-mode' buffers.")
2791 (defun vhdl-mode-abbrev-table-init ()
2792 "Initialize `vhdl-mode-abbrev-table'."
2793 (when vhdl-mode-abbrev-table (clear-abbrev-table vhdl-mode-abbrev-table))
2794 (define-abbrev-table 'vhdl-mode-abbrev-table
2796 (when (memq 'vhdl vhdl-electric-keywords)
2799 ("--" "" vhdl-template-display-comment-hook 0 t)
2800 ("abs" "" vhdl-template-default-hook 0 t)
2801 ("access" "" vhdl-template-default-hook 0 t)
2802 ("after" "" vhdl-template-default-hook 0 t)
2803 ("alias" "" vhdl-template-alias-hook 0 t)
2804 ("all" "" vhdl-template-default-hook 0 t)
2805 ("and" "" vhdl-template-default-hook 0 t)
2806 ("arch" "" vhdl-template-architecture-hook 0 t)
2807 ("architecture" "" vhdl-template-architecture-hook 0 t)
2808 ("array" "" vhdl-template-default-hook 0 t)
2809 ("assert" "" vhdl-template-assert-hook 0 t)
2810 ("attr" "" vhdl-template-attribute-hook 0 t)
2811 ("attribute" "" vhdl-template-attribute-hook 0 t)
2812 ("begin" "" vhdl-template-default-indent-hook 0 t)
2813 ("block" "" vhdl-template-block-hook 0 t)
2814 ("body" "" vhdl-template-default-hook 0 t)
2815 ("buffer" "" vhdl-template-default-hook 0 t)
2816 ("bus" "" vhdl-template-default-hook 0 t)
2817 ("case" "" vhdl-template-case-hook 0 t)
2818 ("comp" "" vhdl-template-component-hook 0 t)
2819 ("component" "" vhdl-template-component-hook 0 t)
2820 ("cond" "" vhdl-template-conditional-signal-asst-hook 0 t)
2821 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0 t)
2822 ("conf" "" vhdl-template-configuration-hook 0 t)
2823 ("configuration" "" vhdl-template-configuration-hook 0 t)
2824 ("cons" "" vhdl-template-constant-hook 0 t)
2825 ("constant" "" vhdl-template-constant-hook 0 t)
2826 ("disconnect" "" vhdl-template-disconnect-hook 0 t)
2827 ("downto" "" vhdl-template-default-hook 0 t)
2828 ("else" "" vhdl-template-else-hook 0 t)
2829 ("elseif" "" vhdl-template-elsif-hook 0 t)
2830 ("elsif" "" vhdl-template-elsif-hook 0 t)
2831 ("end" "" vhdl-template-default-indent-hook 0 t)
2832 ("entity" "" vhdl-template-entity-hook 0 t)
2833 ("exit" "" vhdl-template-exit-hook 0 t)
2834 ("file" "" vhdl-template-file-hook 0 t)
2835 ("for" "" vhdl-template-for-hook 0 t)
2836 ("func" "" vhdl-template-function-hook 0 t)
2837 ("function" "" vhdl-template-function-hook 0 t)
2838 ("generic" "" vhdl-template-generic-hook 0 t)
2839 ("group" "" vhdl-template-group-hook 0 t)
2840 ("guarded" "" vhdl-template-default-hook 0 t)
2841 ("if" "" vhdl-template-if-hook 0 t)
2842 ("impure" "" vhdl-template-default-hook 0 t)
2843 ("in" "" vhdl-template-default-hook 0 t)
2844 ("inertial" "" vhdl-template-default-hook 0 t)
2845 ("inout" "" vhdl-template-default-hook 0 t)
2846 ("inst" "" vhdl-template-instance-hook 0 t)
2847 ("instance" "" vhdl-template-instance-hook 0 t)
2848 ("is" "" vhdl-template-default-hook 0 t)
2849 ("label" "" vhdl-template-default-hook 0 t)
2850 ("library" "" vhdl-template-library-hook 0 t)
2851 ("linkage" "" vhdl-template-default-hook 0 t)
2852 ("literal" "" vhdl-template-default-hook 0 t)
2853 ("loop" "" vhdl-template-bare-loop-hook 0 t)
2854 ("map" "" vhdl-template-map-hook 0 t)
2855 ("mod" "" vhdl-template-default-hook 0 t)
2856 ("nand" "" vhdl-template-default-hook 0 t)
2857 ("new" "" vhdl-template-default-hook 0 t)
2858 ("next" "" vhdl-template-next-hook 0 t)
2859 ("nor" "" vhdl-template-default-hook 0 t)
2860 ("not" "" vhdl-template-default-hook 0 t)
2861 ("null" "" vhdl-template-default-hook 0 t)
2862 ("of" "" vhdl-template-default-hook 0 t)
2863 ("on" "" vhdl-template-default-hook 0 t)
2864 ("open" "" vhdl-template-default-hook 0 t)
2865 ("or" "" vhdl-template-default-hook 0 t)
2866 ("others" "" vhdl-template-others-hook 0 t)
2867 ("out" "" vhdl-template-default-hook 0 t)
2868 ("pack" "" vhdl-template-package-hook 0 t)
2869 ("package" "" vhdl-template-package-hook 0 t)
2870 ("port" "" vhdl-template-port-hook 0 t)
2871 ("postponed" "" vhdl-template-default-hook 0 t)
2872 ("procedure" "" vhdl-template-procedure-hook 0 t)
2873 ("process" "" vhdl-template-process-hook 0 t)
2874 ("pure" "" vhdl-template-default-hook 0 t)
2875 ("range" "" vhdl-template-default-hook 0 t)
2876 ("record" "" vhdl-template-default-hook 0 t)
2877 ("register" "" vhdl-template-default-hook 0 t)
2878 ("reject" "" vhdl-template-default-hook 0 t)
2879 ("rem" "" vhdl-template-default-hook 0 t)
2880 ("report" "" vhdl-template-report-hook 0 t)
2881 ("return" "" vhdl-template-return-hook 0 t)
2882 ("rol" "" vhdl-template-default-hook 0 t)
2883 ("ror" "" vhdl-template-default-hook 0 t)
2884 ("select" "" vhdl-template-selected-signal-asst-hook 0 t)
2885 ("severity" "" vhdl-template-default-hook 0 t)
2886 ("shared" "" vhdl-template-default-hook 0 t)
2887 ("sig" "" vhdl-template-signal-hook 0 t)
2888 ("signal" "" vhdl-template-signal-hook 0 t)
2889 ("sla" "" vhdl-template-default-hook 0 t)
2890 ("sll" "" vhdl-template-default-hook 0 t)
2891 ("sra" "" vhdl-template-default-hook 0 t)
2892 ("srl" "" vhdl-template-default-hook 0 t)
2893 ("subtype" "" vhdl-template-subtype-hook 0 t)
2894 ("then" "" vhdl-template-default-hook 0 t)
2895 ("to" "" vhdl-template-default-hook 0 t)
2896 ("transport" "" vhdl-template-default-hook 0 t)
2897 ("type" "" vhdl-template-type-hook 0 t)
2898 ("unaffected" "" vhdl-template-default-hook 0 t)
2899 ("units" "" vhdl-template-default-hook 0 t)
2900 ("until" "" vhdl-template-default-hook 0 t)
2901 ("use" "" vhdl-template-use-hook 0 t)
2902 ("var" "" vhdl-template-variable-hook 0 t)
2903 ("variable" "" vhdl-template-variable-hook 0 t)
2904 ("wait" "" vhdl-template-wait-hook 0 t)
2905 ("when" "" vhdl-template-when-hook 0 t)
2906 ("while" "" vhdl-template-while-loop-hook 0 t)
2907 ("with" "" vhdl-template-with-hook 0 t)
2908 ("xnor" "" vhdl-template-default-hook 0 t)
2909 ("xor" "" vhdl-template-default-hook 0 t)
2911 ;; VHDL-AMS keywords
2912 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2914 ("across" "" vhdl-template-default-hook 0 t)
2915 ("break" "" vhdl-template-break-hook 0 t)
2916 ("limit" "" vhdl-template-limit-hook 0 t)
2917 ("nature" "" vhdl-template-nature-hook 0 t)
2918 ("noise" "" vhdl-template-default-hook 0 t)
2919 ("procedural" "" vhdl-template-procedural-hook 0 t)
2920 ("quantity" "" vhdl-template-quantity-hook 0 t)
2921 ("reference" "" vhdl-template-default-hook 0 t)
2922 ("spectrum" "" vhdl-template-default-hook 0 t)
2923 ("subnature" "" vhdl-template-subnature-hook 0 t)
2924 ("terminal" "" vhdl-template-terminal-hook 0 t)
2925 ("through" "" vhdl-template-default-hook 0 t)
2926 ("tolerance" "" vhdl-template-default-hook 0 t)
2928 ;; user model keywords
2929 (when (memq 'user vhdl-electric-keywords)
2930 (let ((alist vhdl-model-alist)
2931 abbrev-list keyword)
2933 (setq keyword (nth 3 (car alist)))
2934 (unless (equal keyword "")
2936 (cons (list keyword ""
2938 "vhdl-model" (nth 0 (car alist)) "hook") 0 t)
2940 (setq alist (cdr alist)))
2943 ;; initialize abbrev table for VHDL Mode
2944 (vhdl-mode-abbrev-table-init)
2946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2947 ;; Template completion lists
2949 (defvar vhdl-template-construct-alist nil
2950 "List of built-in construct templates.")
2952 (defun vhdl-template-construct-alist-init ()
2953 "Initialize `vhdl-template-construct-alist'."
2955 vhdl-template-construct-alist
2958 ("alias declaration" vhdl-template-alias)
2959 ("architecture body" vhdl-template-architecture)
2960 ("assertion" vhdl-template-assert)
2961 ("attribute declaration" vhdl-template-attribute-decl)
2962 ("attribute specification" vhdl-template-attribute-spec)
2963 ("block configuration" vhdl-template-block-configuration)
2964 ("block statement" vhdl-template-block)
2965 ("case statement" vhdl-template-case-is)
2966 ("component configuration" vhdl-template-component-conf)
2967 ("component declaration" vhdl-template-component-decl)
2968 ("component instantiation statement" vhdl-template-component-inst)
2969 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
2970 ("configuration declaration" vhdl-template-configuration-decl)
2971 ("configuration specification" vhdl-template-configuration-spec)
2972 ("constant declaration" vhdl-template-constant)
2973 ("disconnection specification" vhdl-template-disconnect)
2974 ("entity declaration" vhdl-template-entity)
2975 ("exit statement" vhdl-template-exit)
2976 ("file declaration" vhdl-template-file)
2977 ("generate statement" vhdl-template-generate)
2978 ("generic clause" vhdl-template-generic)
2979 ("group declaration" vhdl-template-group-decl)
2980 ("group template declaration" vhdl-template-group-template)
2981 ("if statement" vhdl-template-if-then)
2982 ("library clause" vhdl-template-library)
2983 ("loop statement" vhdl-template-loop)
2984 ("next statement" vhdl-template-next)
2985 ("package declaration" vhdl-template-package-decl)
2986 ("package body" vhdl-template-package-body)
2987 ("port clause" vhdl-template-port)
2988 ("process statement" vhdl-template-process)
2989 ("report statement" vhdl-template-report)
2990 ("return statement" vhdl-template-return)
2991 ("selected signal assignment" vhdl-template-selected-signal-asst)
2992 ("signal declaration" vhdl-template-signal)
2993 ("subprogram declaration" vhdl-template-subprogram-decl)
2994 ("subprogram body" vhdl-template-subprogram-body)
2995 ("subtype declaration" vhdl-template-subtype)
2996 ("type declaration" vhdl-template-type)
2997 ("use clause" vhdl-template-use)
2998 ("variable declaration" vhdl-template-variable)
2999 ("wait statement" vhdl-template-wait)
3001 (when (vhdl-standard-p 'ams)
3003 ("break statement" vhdl-template-break)
3004 ("nature declaration" vhdl-template-nature)
3005 ("quantity declaration" vhdl-template-quantity)
3006 ("simultaneous case statement" vhdl-template-case-use)
3007 ("simultaneous if statement" vhdl-template-if-use)
3008 ("simultaneous procedural statement" vhdl-template-procedural)
3009 ("step limit specification" vhdl-template-limit)
3010 ("subnature declaration" vhdl-template-subnature)
3011 ("terminal declaration" vhdl-template-terminal)
3014 ;; initialize for VHDL Mode
3015 (vhdl-template-construct-alist-init)
3017 (defvar vhdl-template-package-alist nil
3018 "List of built-in package templates.")
3020 (defun vhdl-template-package-alist-init ()
3021 "Initialize `vhdl-template-package-alist'."
3023 vhdl-template-package-alist
3026 ("numeric_bit" vhdl-template-package-numeric-bit)
3027 ("numeric_std" vhdl-template-package-numeric-std)
3028 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3029 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3030 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3031 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3032 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3033 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3034 ("textio" vhdl-template-package-textio)
3036 (when (vhdl-standard-p 'math)
3038 ("math_complex" vhdl-template-package-math-complex)
3039 ("math_real" vhdl-template-package-math-real)
3042 ;; initialize for VHDL Mode
3043 (vhdl-template-package-alist-init)
3045 (defvar vhdl-template-directive-alist
3047 ("translate_on" vhdl-template-directive-translate-on)
3048 ("translate_off" vhdl-template-directive-translate-off)
3049 ("synthesis_on" vhdl-template-directive-synthesis-on)
3050 ("synthesis_off" vhdl-template-directive-synthesis-off)
3052 "List of built-in directive templates.")
3055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3057 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3059 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3060 ;; VHDL menu (using `easy-menu.el')
3062 (defun vhdl-customize ()
3063 "Call the customize function with `vhdl' as argument."
3065 (customize-browse 'vhdl))
3067 (defun vhdl-create-mode-menu ()
3068 "Create VHDL Mode menu."
3072 ["None" (vhdl-set-project "")
3073 :style radio :selected (null vhdl-project)]
3075 ;; add menu entries for defined projects
3076 (let ((project-alist vhdl-project-alist) menu-list name)
3077 (while project-alist
3078 (setq name (caar project-alist))
3080 (cons `[,name (vhdl-set-project ,name)
3081 :style radio :selected (equal ,name vhdl-project)]
3083 (setq project-alist (cdr project-alist)))
3085 (if vhdl-project-sort
3087 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3088 (nreverse menu-list)))
3089 (vhdl-menu-split menu-list "Project"))
3091 ["Select Project..." vhdl-set-project t]
3093 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3094 ["Import Project..." vhdl-import-project
3095 :keys "C-c C-p C-m" :active t]
3096 ["Export Project" vhdl-export-project vhdl-project]
3098 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3101 ["Compile Buffer" vhdl-compile t]
3102 ["Stop Compilation" kill-compilation t]
3104 ["Make" vhdl-make t]
3105 ["Generate Makefile" vhdl-generate-makefile t]
3107 ["Next Error" next-error t]
3108 ["Previous Error" previous-error t]
3109 ["First Error" first-error t]
3113 ;; add menu entries for defined compilers
3114 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3116 (setq name (caar comp-alist))
3118 (cons `[,name (setq vhdl-compiler ,name)
3119 :style radio :selected (equal ,name vhdl-compiler)]
3121 (setq comp-alist (cdr comp-alist)))
3122 (setq menu-list (nreverse menu-list))
3123 (vhdl-menu-split menu-list "Compiler"))
3125 ["Select Compiler..." vhdl-set-compiler t]
3127 ["Customize Compiler..."
3128 (customize-option 'vhdl-compiler-alist) t])))
3133 ["Alias" vhdl-template-alias t]
3134 ["Architecture" vhdl-template-architecture t]
3135 ["Assert" vhdl-template-assert t]
3136 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3137 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3138 ["Block" vhdl-template-block t]
3139 ["Case" vhdl-template-case-is t]
3140 ["Component (Decl)" vhdl-template-component-decl t]
3141 ["(Component) Instance" vhdl-template-component-inst t]
3142 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3143 ["Configuration (Block)" vhdl-template-block-configuration t]
3144 ["Configuration (Comp)" vhdl-template-component-conf t]
3145 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3146 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3147 ["Constant" vhdl-template-constant t]
3148 ["Disconnect" vhdl-template-disconnect t]
3149 ["Else" vhdl-template-else t]
3150 ["Elsif" vhdl-template-elsif t]
3151 ["Entity" vhdl-template-entity t]
3152 ["Exit" vhdl-template-exit t]
3153 ["File" vhdl-template-file t]
3154 ["For (Generate)" vhdl-template-for-generate t]
3155 ["For (Loop)" vhdl-template-for-loop t]
3156 ["Function (Body)" vhdl-template-function-body t]
3157 ["Function (Decl)" vhdl-template-function-decl t]
3158 ["Generic" vhdl-template-generic t]
3159 ["Group (Decl)" vhdl-template-group-decl t]
3160 ["Group (Template)" vhdl-template-group-template t])
3162 ["If (Generate)" vhdl-template-if-generate t]
3163 ["If (Then)" vhdl-template-if-then t]
3164 ["Library" vhdl-template-library t]
3165 ["Loop" vhdl-template-bare-loop t]
3166 ["Map" vhdl-template-map t]
3167 ["Next" vhdl-template-next t]
3168 ["Others (Aggregate)" vhdl-template-others t]
3169 ["Package (Decl)" vhdl-template-package-decl t]
3170 ["Package (Body)" vhdl-template-package-body t]
3171 ["Port" vhdl-template-port t]
3172 ["Procedure (Body)" vhdl-template-procedure-body t]
3173 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3174 ["Process (Comb)" vhdl-template-process-comb t]
3175 ["Process (Seq)" vhdl-template-process-seq t]
3176 ["Report" vhdl-template-report t]
3177 ["Return" vhdl-template-return t]
3178 ["Select" vhdl-template-selected-signal-asst t]
3179 ["Signal" vhdl-template-signal t]
3180 ["Subtype" vhdl-template-subtype t]
3181 ["Type" vhdl-template-type t]
3182 ["Use" vhdl-template-use t]
3183 ["Variable" vhdl-template-variable t]
3184 ["Wait" vhdl-template-wait t]
3185 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3186 ["When" vhdl-template-when t]
3187 ["While (Loop)" vhdl-template-while-loop t]
3188 ["With" vhdl-template-with t]))
3189 (when (vhdl-standard-p 'ams)
3190 '(("VHDL-AMS Construct"
3191 ["Break" vhdl-template-break t]
3192 ["Case (Use)" vhdl-template-case-use t]
3193 ["If (Use)" vhdl-template-if-use t]
3194 ["Limit" vhdl-template-limit t]
3195 ["Nature" vhdl-template-nature t]
3196 ["Procedural" vhdl-template-procedural t]
3197 ["Quantity (Free)" vhdl-template-quantity-free t]
3198 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3199 ["Quantity (Source)" vhdl-template-quantity-source t]
3200 ["Subnature" vhdl-template-subnature t]
3201 ["Terminal" vhdl-template-terminal t])))
3202 '(["Insert Construct..." vhdl-template-insert-construct
3203 :keys "C-c C-i C-t"]
3208 (when (vhdl-standard-p 'math)
3209 '(["math_complex" vhdl-template-package-math-complex t]
3210 ["math_real" vhdl-template-package-math-real t]))
3211 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3212 ["numeric_std" vhdl-template-package-numeric-std t]
3213 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3214 ["textio" vhdl-template-package-textio t]
3216 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3217 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3218 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3219 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3220 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3222 ["Insert Package..." vhdl-template-insert-package
3223 :keys "C-c C-i C-p"])))
3225 ["translate_on" vhdl-template-directive-translate-on t]
3226 ["translate_off" vhdl-template-directive-translate-off t]
3227 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3228 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3230 ["Insert Directive..." vhdl-template-insert-directive
3231 :keys "C-c C-i C-d"])
3233 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3234 ["Insert Footer" vhdl-template-footer t]
3235 ["Insert Date" vhdl-template-insert-date t]
3236 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3238 ["Query Next Prompt" vhdl-template-search-prompt t]))
3241 ;; add menu entries for defined models
3242 (let ((model-alist vhdl-model-alist) menu-list model)
3244 (setq model (car model-alist))
3249 (vhdl-function-name "vhdl-model" (nth 0 model))
3250 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3252 (setq model-alist (cdr model-alist)))
3253 (setq menu-list (nreverse menu-list))
3254 (vhdl-menu-split menu-list "Model"))
3256 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3257 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3259 ["Copy" vhdl-port-copy t]
3261 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3262 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3263 ["Paste As Instance" vhdl-port-paste-instance
3264 :keys "C-c C-p C-i" :active vhdl-port-list]
3265 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3266 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3267 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3268 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3270 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3272 ["Flatten" vhdl-port-flatten
3273 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3274 ["Reverse Direction" vhdl-port-reverse-direction
3275 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3277 ["New Component" vhdl-compose-new-component t]
3278 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3279 ["Wire Components" vhdl-compose-wire-components t]
3281 ["Generate Components Package" vhdl-compose-components-package t])
3283 ["Copy" vhdl-subprog-copy t]
3285 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3286 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3287 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3289 ["Flatten" vhdl-subprog-flatten
3290 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3293 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3295 ["Insert Inline Comment" vhdl-comment-append-inline t]
3296 ["Insert Horizontal Line" vhdl-comment-display-line t]
3297 ["Insert Display Comment" vhdl-comment-display t]
3299 ["Fill Comment" fill-paragraph t]
3300 ["Fill Comment Region" fill-region (mark)]
3301 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3302 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3304 ["Kill" vhdl-line-kill t]
3305 ["Copy" vhdl-line-copy t]
3306 ["Yank" vhdl-line-yank t]
3307 ["Expand" vhdl-line-expand t]
3309 ["Transpose Next" vhdl-line-transpose-next t]
3310 ["Transpose Prev" vhdl-line-transpose-previous t]
3311 ["Open" vhdl-line-open t]
3312 ["Join" vhdl-delete-indentation t]
3314 ["Goto" goto-line t]
3315 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3317 ["Forward Statement" vhdl-end-of-statement t]
3318 ["Backward Statement" vhdl-beginning-of-statement t]
3319 ["Forward Expression" vhdl-forward-sexp t]
3320 ["Backward Expression" vhdl-backward-sexp t]
3321 ["Forward Same Indent" vhdl-forward-same-indent t]
3322 ["Backward Same Indent" vhdl-backward-same-indent t]
3323 ["Forward Function" vhdl-end-of-defun t]
3324 ["Backward Function" vhdl-beginning-of-defun t]
3325 ["Mark Function" vhdl-mark-defun t])
3328 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3329 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3330 ["Region" vhdl-indent-region (mark)]
3331 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3333 ["Group" vhdl-align-group t]
3334 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3335 ["List" vhdl-align-list t]
3336 ["Declarations" vhdl-align-declarations t]
3337 ["Region" vhdl-align-region (mark)]
3338 ["Buffer" vhdl-align-buffer t]
3340 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3341 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3342 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3344 ["List" vhdl-fill-list t]
3345 ["Group" vhdl-fill-group t]
3346 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3347 ["Region" vhdl-fill-region (mark)])
3349 ["Region" vhdl-beautify-region (mark)]
3350 ["Buffer" vhdl-beautify-buffer t])
3352 ["Generic/Port Clause" vhdl-fix-clause t]
3354 ["Case Region" vhdl-fix-case-region (mark)]
3355 ["Case Buffer" vhdl-fix-case-buffer t]
3357 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3358 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3360 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3362 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3363 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3365 ["Fontify Buffer" vhdl-fontify-buffer t]
3366 ["Statistics Buffer" vhdl-statistics-buffer t]
3367 ["Show Messages" vhdl-show-messages t]
3368 ["Syntactic Info" vhdl-show-syntactic-information t]
3370 ["Speedbar" vhdl-speedbar t]
3371 ["Hide/Show" vhdl-hs-minor-mode t]
3374 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3375 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3376 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3377 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3378 ["Version" vhdl-version t]
3379 ["Bug Report..." vhdl-submit-bug-report t]
3384 (progn (customize-set-variable 'vhdl-electric-mode
3385 (not vhdl-electric-mode))
3386 (vhdl-mode-line-update))
3387 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3389 (progn (customize-set-variable 'vhdl-stutter-mode
3390 (not vhdl-stutter-mode))
3391 (vhdl-mode-line-update))
3392 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3394 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3395 (not vhdl-indent-tabs-mode))
3396 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3397 :style toggle :selected vhdl-indent-tabs-mode]
3399 ["Customize Group..." (customize-group 'vhdl-mode) t])
3401 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3403 '("Selected Project at Startup"
3404 ["None" (progn (customize-set-variable 'vhdl-project nil)
3405 (vhdl-set-project ""))
3406 :style radio :selected (null vhdl-project)]
3408 ;; add menu entries for defined projects
3409 (let ((project-alist vhdl-project-alist) menu-list name)
3410 (while project-alist
3411 (setq name (caar project-alist))
3413 (cons `[,name (progn (customize-set-variable
3414 'vhdl-project ,name)
3415 (vhdl-set-project ,name))
3416 :style radio :selected (equal ,name vhdl-project)]
3418 (setq project-alist (cdr project-alist)))
3419 (setq menu-list (nreverse menu-list))
3420 (vhdl-menu-split menu-list "Project")))
3421 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3422 ("Auto Load Setup File"
3424 (customize-set-variable 'vhdl-project-auto-load
3425 (if (memq 'startup vhdl-project-auto-load)
3426 (delq 'startup vhdl-project-auto-load)
3427 (cons 'startup vhdl-project-auto-load)))
3428 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3430 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3431 :style toggle :selected vhdl-project-sort]
3433 ["Customize Group..." (customize-group 'vhdl-project) t])
3435 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3437 '("Selected Compiler at Startup")
3438 ;; add menu entries for defined compilers
3439 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3441 (setq name (caar comp-alist))
3443 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3444 :style radio :selected (equal ,name vhdl-compiler)]
3446 (setq comp-alist (cdr comp-alist)))
3447 (setq menu-list (nreverse menu-list))
3448 (vhdl-menu-split menu-list "Compler")))
3449 ["Use Local Error Regexp"
3450 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3451 (not vhdl-compile-use-local-error-regexp))
3452 :style toggle :selected vhdl-compile-use-local-error-regexp]
3453 ["Makefile Generation Hook..."
3454 (customize-option 'vhdl-makefile-generation-hook) t]
3455 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3457 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3461 (progn (customize-set-variable 'vhdl-standard
3462 (list '87 (cadr vhdl-standard)))
3463 (vhdl-activate-customizations))
3464 :style radio :selected (eq '87 (car vhdl-standard))]
3466 (progn (customize-set-variable 'vhdl-standard
3467 (list '93 (cadr vhdl-standard)))
3468 (vhdl-activate-customizations))
3469 :style radio :selected (eq '93 (car vhdl-standard))]
3472 (progn (customize-set-variable
3473 'vhdl-standard (list (car vhdl-standard)
3474 (if (memq 'ams (cadr vhdl-standard))
3475 (delq 'ams (cadr vhdl-standard))
3476 (cons 'ams (cadr vhdl-standard)))))
3477 (vhdl-activate-customizations))
3478 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3480 (progn (customize-set-variable
3481 'vhdl-standard (list (car vhdl-standard)
3482 (if (memq 'math (cadr vhdl-standard))
3483 (delq 'math (cadr vhdl-standard))
3484 (cons 'math (cadr vhdl-standard)))))
3485 (vhdl-activate-customizations))
3486 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3487 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3488 ["Upper Case Keywords"
3489 (customize-set-variable 'vhdl-upper-case-keywords
3490 (not vhdl-upper-case-keywords))
3491 :style toggle :selected vhdl-upper-case-keywords]
3493 (customize-set-variable 'vhdl-upper-case-types
3494 (not vhdl-upper-case-types))
3495 :style toggle :selected vhdl-upper-case-types]
3496 ["Upper Case Attributes"
3497 (customize-set-variable 'vhdl-upper-case-attributes
3498 (not vhdl-upper-case-attributes))
3499 :style toggle :selected vhdl-upper-case-attributes]
3500 ["Upper Case Enumeration Values"
3501 (customize-set-variable 'vhdl-upper-case-enum-values
3502 (not vhdl-upper-case-enum-values))
3503 :style toggle :selected vhdl-upper-case-enum-values]
3504 ["Upper Case Constants"
3505 (customize-set-variable 'vhdl-upper-case-constants
3506 (not vhdl-upper-case-constants))
3507 :style toggle :selected vhdl-upper-case-constants]
3508 ("Use Direct Instantiation"
3510 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3511 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3513 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3514 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3516 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3517 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3519 ["Customize Group..." (customize-group 'vhdl-style) t])
3521 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3522 ["Architecture File Name..."
3523 (customize-option 'vhdl-architecture-file-name) t]
3524 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3527 (customize-set-variable 'vhdl-file-name-case 'identity)
3528 :style radio :selected (eq 'identity vhdl-file-name-case)]
3530 (customize-set-variable 'vhdl-file-name-case 'downcase)
3531 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3533 (customize-set-variable 'vhdl-file-name-case 'upcase)
3534 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3536 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3537 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3539 ["Customize Group..." (customize-group 'vhdl-naming) t])
3541 ("Electric Keywords"
3543 (customize-set-variable 'vhdl-electric-keywords
3544 (if (memq 'vhdl vhdl-electric-keywords)
3545 (delq 'vhdl vhdl-electric-keywords)
3546 (cons 'vhdl vhdl-electric-keywords)))
3547 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3548 ["User Model Keywords"
3549 (customize-set-variable 'vhdl-electric-keywords
3550 (if (memq 'user vhdl-electric-keywords)
3551 (delq 'user vhdl-electric-keywords)
3552 (cons 'user vhdl-electric-keywords)))
3553 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3554 ("Insert Optional Labels"
3556 (customize-set-variable 'vhdl-optional-labels 'none)
3557 :style radio :selected (eq 'none vhdl-optional-labels)]
3559 (customize-set-variable 'vhdl-optional-labels 'process)
3560 :style radio :selected (eq 'process vhdl-optional-labels)]
3562 (customize-set-variable 'vhdl-optional-labels 'all)
3563 :style radio :selected (eq 'all vhdl-optional-labels)])
3564 ("Insert Empty Lines"
3566 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3567 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3568 ["Design Units Only"
3569 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3570 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3572 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3573 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3574 ["Argument List Indent"
3575 (customize-set-variable 'vhdl-argument-list-indent
3576 (not vhdl-argument-list-indent))
3577 :style toggle :selected vhdl-argument-list-indent]
3578 ["Association List with Formals"
3579 (customize-set-variable 'vhdl-association-list-with-formals
3580 (not vhdl-association-list-with-formals))
3581 :style toggle :selected vhdl-association-list-with-formals]
3582 ["Conditions in Parenthesis"
3583 (customize-set-variable 'vhdl-conditions-in-parenthesis
3584 (not vhdl-conditions-in-parenthesis))
3585 :style toggle :selected vhdl-conditions-in-parenthesis]
3586 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3587 ["One String..." (customize-option 'vhdl-one-string) t]
3589 ["Header String..." (customize-option 'vhdl-file-header) t]
3590 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3591 ["Company Name..." (customize-option 'vhdl-company-name) t]
3592 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3593 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3594 ["Date Format..." (customize-option 'vhdl-date-format) t]
3595 ["Modify Date Prefix String..."
3596 (customize-option 'vhdl-modify-date-prefix-string) t]
3597 ["Modify Date on Saving"
3598 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3599 (not vhdl-modify-date-on-saving))
3600 (vhdl-activate-customizations))
3601 :style toggle :selected vhdl-modify-date-on-saving])
3602 ("Sequential Process"
3605 (customize-set-variable 'vhdl-reset-kind 'none)
3606 :style radio :selected (eq 'none vhdl-reset-kind)]
3608 (customize-set-variable 'vhdl-reset-kind 'sync)
3609 :style radio :selected (eq 'sync vhdl-reset-kind)]
3611 (customize-set-variable 'vhdl-reset-kind 'async)
3612 :style radio :selected (eq 'async vhdl-reset-kind)])
3613 ["Reset is Active High"
3614 (customize-set-variable 'vhdl-reset-active-high
3615 (not vhdl-reset-active-high))
3616 :style toggle :selected vhdl-reset-active-high]
3617 ["Use Rising Clock Edge"
3618 (customize-set-variable 'vhdl-clock-rising-edge
3619 (not vhdl-clock-rising-edge))
3620 :style toggle :selected vhdl-clock-rising-edge]
3621 ("Clock Edge Condition"
3623 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3624 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3625 ["Function \"rising_edge\""
3626 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3627 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3628 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3629 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3631 ["Customize Group..." (customize-group 'vhdl-template) t])
3633 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3635 ["Include Port Comments"
3636 (customize-set-variable 'vhdl-include-port-comments
3637 (not vhdl-include-port-comments))
3638 :style toggle :selected vhdl-include-port-comments]
3639 ["Include Direction Comments"
3640 (customize-set-variable 'vhdl-include-direction-comments
3641 (not vhdl-include-direction-comments))
3642 :style toggle :selected vhdl-include-direction-comments]
3643 ["Include Type Comments"
3644 (customize-set-variable 'vhdl-include-type-comments
3645 (not vhdl-include-type-comments))
3646 :style toggle :selected vhdl-include-type-comments]
3647 ("Include Group Comments"
3649 (customize-set-variable 'vhdl-include-group-comments 'never)
3650 :style radio :selected (eq 'never vhdl-include-group-comments)]
3652 (customize-set-variable 'vhdl-include-group-comments 'decl)
3653 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3655 (customize-set-variable 'vhdl-include-group-comments 'always)
3656 :style radio :selected (eq 'always vhdl-include-group-comments)])
3657 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3658 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3660 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3661 ["Architecture Name..."
3662 (customize-option 'vhdl-testbench-architecture-name) t]
3663 ["Configuration Name..."
3664 (customize-option 'vhdl-testbench-configuration-name) t]
3665 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3667 (customize-set-variable 'vhdl-testbench-include-header
3668 (not vhdl-testbench-include-header))
3669 :style toggle :selected vhdl-testbench-include-header]
3670 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3671 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3672 ["Initialize Signals"
3673 (customize-set-variable 'vhdl-testbench-initialize-signals
3674 (not vhdl-testbench-initialize-signals))
3675 :style toggle :selected vhdl-testbench-initialize-signals]
3676 ["Include Library Clause"
3677 (customize-set-variable 'vhdl-testbench-include-library
3678 (not vhdl-testbench-include-library))
3679 :style toggle :selected vhdl-testbench-include-library]
3680 ["Include Configuration"
3681 (customize-set-variable 'vhdl-testbench-include-configuration
3682 (not vhdl-testbench-include-configuration))
3683 :style toggle :selected vhdl-testbench-include-configuration]
3686 (customize-set-variable 'vhdl-testbench-create-files 'none)
3687 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3689 (customize-set-variable 'vhdl-testbench-create-files 'single)
3690 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3692 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3693 :style radio :selected (eq 'separate vhdl-testbench-create-files)]))
3695 ["Customize Group..." (customize-group 'vhdl-port) t])
3699 (customize-set-variable 'vhdl-compose-create-files 'none)
3700 :style radio :selected (eq 'none vhdl-compose-create-files)]
3702 (customize-set-variable 'vhdl-compose-create-files 'single)
3703 :style radio :selected (eq 'single vhdl-compose-create-files)]
3705 (customize-set-variable 'vhdl-compose-create-files 'separate)
3706 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3708 (customize-set-variable 'vhdl-compose-include-header
3709 (not vhdl-compose-include-header))
3710 :style toggle :selected vhdl-compose-include-header]
3711 ["Architecture Name..."
3712 (customize-option 'vhdl-compose-architecture-name) t]
3713 ["Components Package Name..."
3714 (customize-option 'vhdl-components-package-name) t]
3715 ["Use Components Package"
3716 (customize-set-variable 'vhdl-use-components-package
3717 (not vhdl-use-components-package))
3718 :style toggle :selected vhdl-use-components-package]
3720 ["Customize Group..." (customize-group 'vhdl-compose) t])
3722 ["Self Insert Comments"
3723 (customize-set-variable 'vhdl-self-insert-comments
3724 (not vhdl-self-insert-comments))
3725 :style toggle :selected vhdl-self-insert-comments]
3726 ["Prompt for Comments"
3727 (customize-set-variable 'vhdl-prompt-for-comments
3728 (not vhdl-prompt-for-comments))
3729 :style toggle :selected vhdl-prompt-for-comments]
3730 ["Inline Comment Column..."
3731 (customize-option 'vhdl-inline-comment-column) t]
3732 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3734 ["Customize Group..." (customize-group 'vhdl-comment) t])
3736 ["Auto Align Templates"
3737 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3738 :style toggle :selected vhdl-auto-align]
3739 ["Align Line Groups"
3740 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3741 :style toggle :selected vhdl-align-groups]
3742 ["Group Separation String..."
3743 (customize-set-variable 'vhdl-align-group-separate) t]
3744 ["Align Lines with Same Indent"
3745 (customize-set-variable 'vhdl-align-same-indent
3746 (not vhdl-align-same-indent))
3747 :style toggle :selected vhdl-align-same-indent]
3749 ["Customize Group..." (customize-group 'vhdl-align) t])
3751 ["Highlighting On/Off..."
3753 (if (fboundp 'global-font-lock-mode)
3754 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3755 ["Highlight Keywords"
3756 (progn (customize-set-variable 'vhdl-highlight-keywords
3757 (not vhdl-highlight-keywords))
3758 (vhdl-fontify-buffer))
3759 :style toggle :selected vhdl-highlight-keywords]
3761 (progn (customize-set-variable 'vhdl-highlight-names
3762 (not vhdl-highlight-names))
3763 (vhdl-fontify-buffer))
3764 :style toggle :selected vhdl-highlight-names]
3765 ["Highlight Special Words"
3766 (progn (customize-set-variable 'vhdl-highlight-special-words
3767 (not vhdl-highlight-special-words))
3768 (vhdl-fontify-buffer))
3769 :style toggle :selected vhdl-highlight-special-words]
3770 ["Highlight Forbidden Words"
3771 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3772 (not vhdl-highlight-forbidden-words))
3773 (vhdl-fontify-buffer))
3774 :style toggle :selected vhdl-highlight-forbidden-words]
3775 ["Highlight Verilog Keywords"
3776 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3777 (not vhdl-highlight-verilog-keywords))
3778 (vhdl-fontify-buffer))
3779 :style toggle :selected vhdl-highlight-verilog-keywords]
3780 ["Highlight \"translate_off\""
3781 (progn (customize-set-variable 'vhdl-highlight-translate-off
3782 (not vhdl-highlight-translate-off))
3783 (vhdl-fontify-buffer))
3784 :style toggle :selected vhdl-highlight-translate-off]
3785 ["Case Sensitive Highlighting"
3786 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3787 (not vhdl-highlight-case-sensitive))
3788 (vhdl-fontify-buffer))
3789 :style toggle :selected vhdl-highlight-case-sensitive]
3790 ["Special Syntax Definition..."
3791 (customize-option 'vhdl-special-syntax-alist) t]
3792 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3793 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3794 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3795 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3797 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3799 ["Auto Open at Startup"
3800 (customize-set-variable 'vhdl-speedbar-auto-open
3801 (not vhdl-speedbar-auto-open))
3802 :style toggle :selected vhdl-speedbar-auto-open]
3803 ("Default Displaying Mode"
3805 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3806 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3807 ["Directory Hierarchy"
3808 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3809 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3810 ["Project Hierarchy"
3811 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3812 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3813 ["Indentation Offset..."
3814 (customize-option 'speedbar-indentation-width) t]
3815 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3816 ["Jump to Unit when Opening"
3817 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3818 (not vhdl-speedbar-jump-to-unit))
3819 :style toggle :selected vhdl-speedbar-jump-to-unit]
3820 ["Update Hierarchy on File Saving"
3821 (customize-set-variable 'vhdl-speedbar-update-on-saving
3822 (not vhdl-speedbar-update-on-saving))
3823 :style toggle :selected vhdl-speedbar-update-on-saving]
3824 ("Save in Cache File"
3825 ["Hierarchy Information"
3826 (customize-set-variable 'vhdl-speedbar-save-cache
3827 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3828 (delq 'hierarchy vhdl-speedbar-save-cache)
3829 (cons 'hierarchy vhdl-speedbar-save-cache)))
3830 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3831 ["Displaying Status"
3832 (customize-set-variable 'vhdl-speedbar-save-cache
3833 (if (memq 'display vhdl-speedbar-save-cache)
3834 (delq 'display vhdl-speedbar-save-cache)
3835 (cons 'display vhdl-speedbar-save-cache)))
3836 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3837 ["Cache File Name..."
3838 (customize-option 'vhdl-speedbar-cache-file-name) t]
3840 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3842 ["Add Index Menu when Loading File"
3843 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3844 (vhdl-index-menu-init))
3845 :style toggle :selected vhdl-index-menu]
3846 ["Add Source File Menu when Loading File"
3847 (progn (customize-set-variable 'vhdl-source-file-menu
3848 (not vhdl-source-file-menu))
3849 (vhdl-add-source-files-menu))
3850 :style toggle :selected vhdl-source-file-menu]
3851 ["Add Hideshow Menu at Startup"
3852 (progn (customize-set-variable 'vhdl-hideshow-menu
3853 (not vhdl-hideshow-menu))
3854 (vhdl-activate-customizations))
3855 :style toggle :selected vhdl-hideshow-menu]
3856 ["Hide Everything Initially"
3857 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3858 :style toggle :selected vhdl-hide-all-init]
3860 ["Customize Group..." (customize-group 'vhdl-menu) t])
3862 ["In Two Column Format"
3863 (progn (customize-set-variable 'vhdl-print-two-column
3864 (not vhdl-print-two-column))
3865 (message "Activate new setting by saving options and restarting Emacs"))
3866 :style toggle :selected vhdl-print-two-column]
3867 ["Use Customized Faces"
3868 (progn (customize-set-variable 'vhdl-print-customize-faces
3869 (not vhdl-print-customize-faces))
3870 (message "Activate new setting by saving options and restarting Emacs"))
3871 :style toggle :selected vhdl-print-customize-faces]
3873 ["Customize Group..." (customize-group 'vhdl-print) t])
3875 ["Use Intelligent Tab"
3876 (progn (customize-set-variable 'vhdl-intelligent-tab
3877 (not vhdl-intelligent-tab))
3878 (vhdl-activate-customizations))
3879 :style toggle :selected vhdl-intelligent-tab]
3880 ["Indent Syntax-Based"
3881 (customize-set-variable 'vhdl-indent-syntax-based
3882 (not vhdl-indent-syntax-based))
3883 :style toggle :selected vhdl-indent-syntax-based]
3884 ["Word Completion is Case Sensitive"
3885 (customize-set-variable 'vhdl-word-completion-case-sensitive
3886 (not vhdl-word-completion-case-sensitive))
3887 :style toggle :selected vhdl-word-completion-case-sensitive]
3888 ["Word Completion in Minibuffer"
3889 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3890 (not vhdl-word-completion-in-minibuffer))
3891 (message "Activate new setting by saving options and restarting Emacs"))
3892 :style toggle :selected vhdl-word-completion-in-minibuffer]
3893 ["Underscore is Part of Word"
3894 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3895 (not vhdl-underscore-is-part-of-word))
3896 (vhdl-activate-customizations))
3897 :style toggle :selected vhdl-underscore-is-part-of-word]
3899 ["Customize Group..." (customize-group 'vhdl-misc) t])
3900 ["Related..." (customize-browse 'vhdl-related) t]
3902 ["Save Options" customize-save-customized t]
3903 ["Activate Options" vhdl-activate-customizations t]
3904 ["Browse Options..." vhdl-customize t])))
3906 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3909 (defun vhdl-update-mode-menu ()
3910 "Update VHDL Mode menu."
3912 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
3913 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
3914 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
3915 (easy-menu-define vhdl-mode-menu vhdl-mode-map
3916 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
3918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3919 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
3921 (defconst vhdl-imenu-generic-expression
3924 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
3927 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
3930 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3933 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
3936 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
3939 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
3942 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3945 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3948 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3951 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3954 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
3956 (defun vhdl-index-menu-init ()
3957 "Initialize index menu."
3958 (set (make-local-variable 'imenu-case-fold-search) t)
3959 (set (make-local-variable 'imenu-generic-expression)
3960 vhdl-imenu-generic-expression)
3961 (when (and vhdl-index-menu (fboundp 'imenu))
3962 (if (or (not (boundp 'font-lock-maximum-size))
3963 (> font-lock-maximum-size (buffer-size)))
3964 (imenu-add-to-menubar "Index")
3965 (message "Scanning buffer for index...buffer too big"))))
3967 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3968 ;; Source file menu (using `easy-menu.el')
3970 (defvar vhdl-sources-menu nil)
3972 (defun vhdl-directory-files (directory &optional full match)
3973 "Call `directory-files' if DIRECTORY exists, otherwise generate error
3975 (if (not (file-directory-p directory))
3976 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
3977 (let ((dir (directory-files directory full match)))
3978 (setq dir (delete "." dir))
3979 (setq dir (delete ".." dir))
3982 (defun vhdl-get-source-files (&optional full directory)
3983 "Get list of VHDL source files in DIRECTORY or current directory."
3984 (let ((mode-alist auto-mode-alist)
3986 ;; create regular expressions for matching file names
3987 (setq filename-regexp "\\`[^.].*\\(")
3989 (when (eq (cdar mode-alist) 'vhdl-mode)
3990 (setq filename-regexp
3991 (concat filename-regexp (caar mode-alist) "\\|")))
3992 (setq mode-alist (cdr mode-alist)))
3993 (setq filename-regexp
3994 (concat (substring filename-regexp 0
3995 (string-match "\\\\|$" filename-regexp)) "\\)"))
3997 (vhdl-directory-files
3998 (or directory default-directory) full filename-regexp)))
4000 (defun vhdl-add-source-files-menu ()
4001 "Scan directory for all VHDL source files and generate menu.
4002 The directory of the current source file is scanned."
4004 (message "Scanning directory for source files ...")
4005 (let ((newmap (current-local-map))
4006 (file-list (vhdl-get-source-files))
4008 ;; Create list for menu
4012 (setq menu-list (cons (vector (car file-list)
4013 (list 'find-file (car file-list)) t)
4015 (setq file-list (cdr file-list)))
4016 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4017 (when found (setq menu-list (cons "--" menu-list)))
4018 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4019 (setq menu-list (cons "Sources" menu-list))
4021 (easy-menu-add menu-list)
4022 (easy-menu-define vhdl-sources-menu newmap
4023 "VHDL source files menu" menu-list))
4027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4030 ;; performs all buffer local initializations
4034 "Major mode for editing VHDL code.
4039 TEMPLATE INSERTION (electrification):
4040 After typing a VHDL keyword and entering `SPC', you are prompted for
4041 arguments while a template is generated for that VHDL construct. Typing
4042 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4043 template generation. Optional arguments are indicated by square
4044 brackets and removed if the queried string is left empty. Prompts for
4045 mandatory arguments remain in the code if the queried string is left
4046 empty. They can be queried again by `C-c C-t C-q'. Enabled
4047 electrification is indicated by `/e' in the modeline.
4049 Typing `M-SPC' after a keyword inserts a space without calling the
4050 template generator. Automatic template generation (i.e.
4051 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4052 setting option `vhdl-electric-mode' (see OPTIONS).
4054 Template generators can be invoked from the VHDL menu, by key
4055 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4056 the keyword (i.e. first word of menu entry not in parenthesis) and
4057 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4058 conf, comp, cons, func, inst, pack, sig, var.
4060 Template styles can be customized in customization group
4061 `vhdl-template' \(see OPTIONS).
4065 A file header can be inserted by `C-c C-t C-h'. A file footer
4066 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4067 See customization group `vhdl-header'.
4071 Double striking of some keys inserts cumbersome VHDL syntax elements.
4072 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4073 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4074 the modeline. The stuttering keys and their effects are:
4076 ;; --> \" : \" [ --> ( -- --> comment
4077 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4078 .. --> \" => \" ] --> ) --- --> horizontal line
4079 ,, --> \" <= \" ]] --> ] ---- --> display comment
4080 == --> \" == \" '' --> \\\"
4084 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4085 word in the buffer that starts alike, inserts it and adjusts case.
4086 Re-typing `TAB' toggles through alternative word completions. This also
4087 works in the minibuffer (i.e. in template generator prompts).
4089 Typing `TAB' after `(' looks for and inserts complete parenthesized
4090 expressions (e.g. for array index ranges). All keywords as well as
4091 standard types and subprograms of VHDL have predefined abbreviations
4092 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4093 beginning with \"std\").
4095 Typing `TAB' after a non-word character indents the line if at the
4096 beginning of a line (i.e. no preceding non-blank characters), and
4097 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4102 `--' puts a single comment.
4103 `---' draws a horizontal line for separating code segments.
4104 `----' inserts a display comment, i.e. two horizontal lines
4105 with a comment in between.
4106 `--CR' comments out code on that line. Re-hitting CR comments
4107 out following lines.
4108 `C-c c' comments out a region if not commented out,
4109 uncomments a region if already commented out.
4111 You are prompted for comments after object definitions (i.e. signals,
4112 variables, constants, ports) and after subprogram and process
4113 specifications if option `vhdl-prompt-for-comments' is non-nil.
4114 Comments are automatically inserted as additional labels (e.g. after
4115 begin statements) and as help comments if `vhdl-self-insert-comments' is
4118 Inline comments (i.e. comments after a piece of code on the same line)
4119 are indented at least to `vhdl-inline-comment-column'. Comments go at
4120 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4121 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4122 in a comment automatically opens a new comment line. `M-q' re-fills
4123 multi-line comments.
4127 `TAB' indents a line if at the beginning of the line. The amount of
4128 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4129 always indents the current line (is bound to `TAB' if option
4130 `vhdl-intelligent-tab' is nil).
4132 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4133 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4134 indented normally (nil) or relative to the opening parenthesis (non-nil)
4135 according to option `vhdl-argument-list-indent'.
4137 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4138 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4141 Syntax-based indentation can be very slow in large files. Option
4142 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4146 The alignment functions align operators, keywords, and inline comments
4147 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4148 separated by blank lines, `C-c C-a C-i' a block of lines with same
4149 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4150 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4151 C-a C-d' all lines within the declarative part of a design unit. `C-c
4152 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4153 for a group of lines, and `C-c C-a M-c' for a region.
4155 If option `vhdl-align-groups' is non-nil, groups of code lines
4156 separated by special lines (see option `vhdl-align-group-separate') are
4157 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4158 blocks of lines with same indent are aligned separately. Some templates
4159 are automatically aligned after generation if option `vhdl-auto-align'
4162 Alignment tries to align inline comments at
4163 `vhdl-inline-comment-column' and tries inline comment not to exceed
4164 `vhdl-end-comment-column'.
4166 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4167 symbols are surrounded by one space, and multiple spaces are eliminated.
4171 | Code filling allows to condens code (e.g. sensitivity lists or port
4172 | maps) by removing comments and newlines and re-wrapping so that all
4173 | lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4174 | enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4175 | blank lines, `C-c C-f C-i' a block of lines with same indent, and
4176 | `C-c C-f M-f' an entire region.
4179 CODE BEAUTIFICATION:
4180 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4181 buffer respectively. This inludes indentation, alignment, and case
4182 fixing. Code beautification can also be run non-interactively using the
4185 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4189 Generic and port clauses from entity or component declarations can be
4190 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4191 as component instantiations and corresponding internal constants and
4192 signals, as a generic map with constants as actual generics, and as
4193 internal signal initializations (menu).
4195 To include formals in component instantiations, see option
4196 `vhdl-association-list-with-formals'. To include comments in pasting,
4197 see options `vhdl-include-...-comments'.
4199 A clause with several generic/port names on the same line can be
4200 flattened (`C-c C-p C-f') so that only one name per line exists. The
4201 | direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4202 | outputs and vice versa, which can be useful in testbenches. (This
4203 | reversion is done on the internal data structure and is only reflected
4204 | in subsequent paste operations.)
4206 Names for actual ports, instances, testbenches, and
4207 design-under-test instances can be derived from existing names according
4208 to options `vhdl-...-name'. See customization group `vhdl-port'.
4211 | SUBPROGRAM TRANSLATION:
4212 | Similar functionality exists for copying/pasting the interface of
4213 | subprograms (function/procedure). A subprogram interface can be copied
4214 | and then pasted as a subprogram declaration, body or call (uses
4215 | association list with formals).
4218 TESTBENCH GENERATION:
4219 A copied port can also be pasted as a testbench. The generated
4220 testbench includes an entity, an architecture, and an optional
4221 configuration. The architecture contains the component declaration and
4222 instantiation of the DUT as well as internal constant and signal
4223 declarations. Additional user-defined templates can be inserted. The
4224 names used for entity/architecture/configuration/DUT as well as the file
4225 structure to be generated can be customized. See customization group
4230 Key bindings (`C-c ...') exist for most commands (see in menu).
4234 All commands can be found in the VHDL menu including their key bindings.
4238 The speedbar allows browsing of directories and file contents. It can
4239 be accessed from the VHDL menu and is automatically opened if option
4240 `vhdl-speedbar-auto-open' is non-nil.
4242 In speedbar, open files and directories with `mouse-2' on the name and
4243 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4246 DESIGN HIERARCHY BROWSER:
4247 The speedbar can also be used for browsing the hierarchy of design units
4248 contained in the source files of the current directory or the specified
4249 projects (see option `vhdl-project-alist').
4251 The speedbar can be switched between file, directory hierarchy and
4252 project hierarchy browsing mode in the speedbar menu or by typing `f',
4253 `h' or `H' in speedbar.
4255 In speedbar, open design units with `mouse-2' on the name and browse
4256 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4257 from entities and components (in packages). Individual design units and
4258 complete designs can directly be compiled (\"Make\" menu entry).
4260 The hierarchy is automatically updated upon saving a modified source
4261 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4262 hierarchy is only updated for projects that have been opened once in the
4263 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4264 options in group `vhdl-speedbar').
4266 Simple design consistency checks are done during scanning, such as
4267 multiple declarations of the same unit or missing primary units that are
4268 required by secondary units.
4271 | STRUCTURAL COMPOSITION:
4272 | Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4273 | for a new component. Subcomponents (i.e. component declaration and
4274 | instantiation) can be automatically placed from a previously read port
4275 | \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4276 | all subcomponents can be automatically connected using internal signals
4277 | and ports (`C-c C-c C-w') following these rules:
4278 | - subcomponent actual ports with same name are considered to be
4279 | connected by a signal (internal signal or port)
4280 | - signals that are only inputs to subcomponents are considered as
4281 | inputs to this component -> input port created
4282 | - signals that are only outputs from subcomponents are considered as
4283 | outputs from this component -> output port created
4284 | - signals that are inputs to AND outputs from subcomponents are
4285 | considered as internal connections -> internal signal created
4287 | Component declarations can be placed in a components package (option
4288 | `vhdl-use-components-package') which can be automatically generated for
4289 | an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4290 | component instantiation is also supported (option
4291 | `vhdl-use-direct-instantiation').
4293 | Purpose: With appropriate naming conventions it is possible to
4294 | create higher design levels with only a few mouse clicks or key
4295 | strokes. A new design level can be created by simply generating a new
4296 | component, placing the required subcomponents from the hierarchy
4297 | browser, and wiring everything automatically.
4299 | Note: Automatic wiring only works reliably on templates of new
4300 | components and component instantiations that were created by VHDL mode.
4302 | See the options group `vhdl-compose' for all relevant user options.
4305 SOURCE FILE COMPILATION:
4306 The syntax of the current buffer can be analyzed by calling a VHDL
4307 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4308 option `vhdl-compiler'. The available compilers are listed in option
4309 `vhdl-compiler-alist' including all required compilation command,
4310 command options, compilation directory, and error message syntax
4311 information. New compilers can be added.
4313 All the source files of an entire design can be compiled by the `make'
4314 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4317 MAKEFILE GENERATION:
4318 Makefiles can be generated automatically by an internal generation
4319 routine (`C-c M-k'). The library unit dependency information is
4320 obtained from the hierarchy browser. Makefile generation can be
4321 customized for each compiler in option `vhdl-compiler-alist'.
4323 Makefile generation can also be run non-interactively using the
4326 emacs -batch -l ~/.emacs -l vhdl-mode
4327 [-compiler compilername] [-project projectname]
4328 -f vhdl-generate-makefile
4330 The Makefile's default target \"all\" compiles the entire design, the
4331 target \"clean\" removes it and the target \"library\" creates the
4332 library directory if not existent. The Makefile also includes a target
4333 for each primary library unit which allows selective compilation of this
4334 unit, its secondary units and its subhierarchy (example: compilation of
4335 a design specified by a configuration). User specific parts can be
4336 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4339 - Only library units and dependencies within the current library are
4340 considered. Makefiles for designs that span multiple libraries are
4341 not (yet) supported.
4342 - Only one-level configurations are supported (also hierarchical),
4343 but configurations that go down several levels are not.
4344 - The \"others\" keyword in configurations is not supported.
4348 Projects can be defined in option `vhdl-project-alist' and a current
4349 project be selected using option `vhdl-project' (permanently) or from
4350 the menu or speedbar (temporarily). For each project, title and
4351 description strings (for the file headers), source files/directories
4352 (for the hierarchy browser and Makefile generation), library name, and
4353 compiler-dependent options, exceptions and compilation directory can be
4354 specified. Compilation settings overwrite the settings of option
4355 `vhdl-compiler-alist'.
4357 Project setups can be exported (i.e. written to a file) and imported.
4358 Imported setups are not automatically saved in `vhdl-project-alist' but
4359 can be saved afterwards in its customization buffer. When starting
4360 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4361 vhdl-mode\") in a directory with an existing project setup file, it is
4362 automatically loaded and its project activated if option
4363 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4364 files can be specified in option `vhdl-project-file-name'. Multiple
4365 project setups can be automatically loaded from global directories.
4366 This is an alternative to specifying project setups with option
4367 `vhdl-project-alist'.
4371 As an alternative to the speedbar, an index menu can be added (set
4372 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4373 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4374 file) for browsing the file contents (is not populated if buffer is
4375 larger than `font-lock-maximum-size'). Also, a source file menu can be
4376 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4377 current directory for VHDL source files.
4381 The VHDL standards to be used are specified in option `vhdl-standard'.
4382 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4386 Lower and upper case for keywords and standardized types, attributes,
4387 and enumeration values is supported. If the option
4388 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4389 lower case and are converted into upper case automatically (not for
4390 types, attributes, and enumeration values). The case of keywords,
4391 types, attributes,and enumeration values can be fixed for an entire
4392 region (menu) or buffer (`C-c C-x C-c') according to the options
4393 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4396 HIGHLIGHTING (fontification):
4397 Keywords and standardized types, attributes, enumeration values, and
4398 function names (controlled by option `vhdl-highlight-keywords'), as well
4399 as comments, strings, and template prompts are highlighted using
4400 different colors. Unit, subprogram, signal, variable, constant,
4401 parameter and generic/port names in declarations as well as labels are
4402 highlighted if option `vhdl-highlight-names' is non-nil.
4404 Additional reserved words or words with a forbidden syntax (e.g. words
4405 that should be avoided) can be specified in option
4406 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4407 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4408 keywords are highlighted as forbidden words if option
4409 `vhdl-highlight-verilog-keywords' is non-nil.
4411 Words with special syntax can be highlighted by specifying their
4412 syntax and color in option `vhdl-special-syntax-alist' and by setting
4413 option `vhdl-highlight-special-words' to non-nil. This allows to
4414 establish some naming conventions (e.g. to distinguish different kinds
4415 of signals or other objects by using name suffices) and to support them
4418 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4419 to support case-sensitive highlighting. However, keywords are then only
4420 highlighted if written in lower case.
4422 Code between \"translate_off\" and \"translate_on\" pragmas is
4423 highlighted using a different background color if option
4424 `vhdl-highlight-translate-off' is non-nil.
4426 For documentation and customization of the used colors see
4427 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4428 highlighting of matching parenthesis, see customization group
4429 `paren-showing'. Automatic buffer highlighting is turned on/off by
4430 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4434 VHDL models (templates) can be specified by the user and made accessible
4435 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4436 electrification. See option `vhdl-model-alist'.
4440 The code of blocks, processes, subprograms, component declarations and
4441 instantiations, generic/port clauses, and configuration declarations can
4442 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4443 the code (see customization group `vhdl-menu'). XEmacs: limited
4444 functionality due to old `hideshow.el' package.
4448 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4449 current process, `C-c C-u M-s' of all processes in the current buffer.
4451 - Only declared local signals (ports, signals declared in
4452 architecture and blocks) are automatically inserted.
4453 - Global signals declared in packages are not automatically inserted.
4454 Insert them once manually (will be kept afterwards).
4455 - Out parameters of procedures are considered to be read.
4456 Use option `vhdl-entity-file-name' to specify the entity file name
4457 \(used to obtain the port names).
4461 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4462 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4466 Postscript printing with different faces (an optimized set of faces is
4467 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4468 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4469 postscript printing commands. Option `vhdl-print-two-column' defines
4470 appropriate default settings for nice landscape two-column printing.
4471 The paper format can be set by option `ps-paper-type'. Do not forget to
4472 switch `ps-print-color-p' to nil for printing on black-and-white
4477 User options allow customization of VHDL Mode. All options are
4478 accessible from the \"Options\" menu entry. Simple options (switches
4479 and choices) can directly be changed, while for complex options a
4480 customization buffer is opened. Changed options can be saved for future
4481 sessions using the \"Save Options\" menu entry.
4483 Options and their detailed descriptions can also be accessed by using
4484 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4485 customize-group' for groups). Some customizations only take effect
4486 after some action (read the NOTE in the option documentation).
4487 Customization can also be done globally (i.e. site-wide, read the
4490 Not all options are described in this documentation, so go and see
4491 what other useful user options there are (`M-x vhdl-customize' or menu)!
4495 As default, files with extensions \".vhd\" and \".vhdl\" are
4496 automatically recognized as VHDL source files. To add an extension
4497 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4499 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4503 - To start Emacs with open VHDL hierarchy browser without having to load
4504 a VHDL file first, use the command:
4506 emacs -l vhdl-mode -f speedbar-frame-mode
4508 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4510 - Some features only work on properly indented code.
4514 See also the release notes (menu) for added features in new releases.
4520 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4521 Add a description of the problem and include a reproducible test case.
4523 Questions and enhancement requests can be sent to <reto@gnu.org>.
4525 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4526 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4527 releases. You are kindly invited to participate in beta testing. Subscribe
4528 to above mailing lists by sending an email to <reto@gnu.org>.
4530 VHDL Mode is officially distributed at
4531 http://opensource.ethz.ch/emacs/vhdl-mode.html
4532 where the latest version can be found.
4538 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4539 - XEmacs: Incorrect start-up when automatically opening speedbar.
4540 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4543 The VHDL Mode Authors
4544 Reto Zimmermann and Rod Whitby
4551 (kill-all-local-variables)
4552 (setq major-mode 'vhdl-mode)
4553 (setq mode-name "VHDL")
4555 ;; set maps and tables
4556 (use-local-map vhdl-mode-map)
4557 (set-syntax-table vhdl-mode-syntax-table)
4558 (setq local-abbrev-table vhdl-mode-abbrev-table)
4560 ;; set local variables
4561 (set (make-local-variable 'paragraph-start)
4562 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4563 (set (make-local-variable 'paragraph-separate) paragraph-start)
4564 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4565 (set (make-local-variable 'require-final-newline)
4566 mode-require-final-newline)
4567 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4568 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4569 (set (make-local-variable 'comment-start) "--")
4570 (set (make-local-variable 'comment-end) "")
4571 (set (make-local-variable 'comment-padding) "")
4572 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4573 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4574 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4575 (set (make-local-variable 'comment-multi-line) nil)
4576 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4577 (set (make-local-variable 'hippie-expand-verbose) nil)
4579 ;; setup the comment indent variable in a Emacs version portable way
4580 ;; ignore any byte compiler warnings you might get here
4581 (when (boundp 'comment-indent-function)
4582 (make-local-variable 'comment-indent-function)
4583 (setq comment-indent-function 'vhdl-comment-indent))
4585 ;; initialize font locking
4586 (set (make-local-variable 'font-lock-defaults)
4588 '(nil vhdl-font-lock-keywords) nil
4589 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4590 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4591 (unless vhdl-emacs-21
4592 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4593 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4594 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4595 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4596 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4597 ; (turn-on-font-lock)
4599 ;; variables for source file compilation
4600 (when vhdl-compile-use-local-error-regexp
4601 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4602 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4605 (vhdl-index-menu-init)
4606 ;; add source file menu
4607 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4609 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4610 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4611 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4612 ;; initialize hideshow and add menu
4613 (vhdl-hideshow-init)
4614 (run-hooks 'menu-bar-update-hook)
4617 (vhdl-ps-print-init)
4618 (vhdl-write-file-hooks-init)
4619 (vhdl-mode-line-update)
4620 (message "VHDL Mode %s.%s" vhdl-version
4621 (if noninteractive "" " See menu for documentation and release notes."))
4624 (run-mode-hooks 'vhdl-mode-hook))
4626 (defun vhdl-activate-customizations ()
4627 "Activate all customizations on local variables."
4629 (vhdl-mode-map-init)
4630 (use-local-map vhdl-mode-map)
4631 (set-syntax-table vhdl-mode-syntax-table)
4632 (setq comment-column vhdl-inline-comment-column)
4633 (setq end-comment-column vhdl-end-comment-column)
4634 (vhdl-write-file-hooks-init)
4635 (vhdl-update-mode-menu)
4636 (vhdl-hideshow-init)
4637 (run-hooks 'menu-bar-update-hook)
4638 (vhdl-mode-line-update))
4640 (defun vhdl-write-file-hooks-init ()
4641 "Add/remove hooks when buffer is saved."
4642 (if vhdl-modify-date-on-saving
4643 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4644 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4645 (make-local-variable 'after-save-hook)
4646 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4648 (defun vhdl-process-command-line-option (option)
4649 "Process command line options for VHDL Mode."
4652 ((equal option "-compiler")
4653 (vhdl-set-compiler (car command-line-args-left))
4654 (setq command-line-args-left (cdr command-line-args-left)))
4656 ((equal option "-project")
4657 (vhdl-set-project (car command-line-args-left))
4658 (setq command-line-args-left (cdr command-line-args-left)))))
4660 ;; make Emacs process VHDL Mode options
4661 (setq command-switch-alist
4662 (append command-switch-alist
4663 '(("-compiler" . vhdl-process-command-line-option)
4664 ("-project" . vhdl-process-command-line-option))))
4667 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4668 ;;; Keywords and standardized words
4669 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4671 (defconst vhdl-93-keywords
4673 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4674 "assert" "attribute"
4675 "begin" "block" "body" "buffer" "bus"
4676 "case" "component" "configuration" "constant"
4677 "disconnect" "downto"
4678 "else" "elsif" "end" "entity" "exit"
4679 "file" "for" "function"
4680 "generate" "generic" "group" "guarded"
4681 "if" "impure" "in" "inertial" "inout" "is"
4682 "label" "library" "linkage" "literal" "loop"
4684 "nand" "new" "next" "nor" "not" "null"
4685 "of" "on" "open" "or" "others" "out"
4686 "package" "port" "postponed" "procedure" "process" "pure"
4687 "range" "record" "register" "reject" "rem" "report" "return"
4689 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4690 "then" "to" "transport" "type"
4691 "unaffected" "units" "until" "use"
4693 "wait" "when" "while" "with"
4696 "List of VHDL'93 keywords.")
4698 (defconst vhdl-ams-keywords
4700 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4701 "reference" "spectrum" "subnature" "terminal" "through"
4704 "List of VHDL-AMS keywords.")
4706 (defconst vhdl-verilog-keywords
4708 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4709 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4710 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4711 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4712 "endprimitive" "endspecify" "endtable" "endtask" "event"
4713 "for" "force" "forever" "fork" "function"
4714 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4715 "macromodule" "makefile" "medium" "module"
4716 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4717 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4719 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4720 "rtranif0" "rtranif1"
4721 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4722 "strong1" "supply" "supply0" "supply1"
4723 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4724 "triand" "trior" "trireg"
4725 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4727 "List of Verilog keywords as candidate for additional reserved words.")
4729 (defconst vhdl-93-types
4731 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4732 "real" "time" "natural" "positive" "string" "line" "text" "side"
4733 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4734 "std_logic" "std_logic_vector"
4735 "std_ulogic" "std_ulogic_vector"
4737 "List of VHDL'93 standardized types.")
4739 (defconst vhdl-ams-types
4741 "domain_type" "real_vector"
4742 ;; from `nature_pkg' package
4743 "voltage" "current" "electrical" "position" "velocity" "force"
4744 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4745 "pressure" "flowrate" "fluid"
4747 "List of VHDL-AMS standardized types.")
4749 (defconst vhdl-math-types
4751 "complex" "complex_polar"
4753 "List of Math Packages standardized types.")
4755 (defconst vhdl-93-attributes
4757 "base" "left" "right" "high" "low" "pos" "val" "succ"
4758 "pred" "leftof" "rightof" "range" "reverse_range"
4759 "length" "delayed" "stable" "quiet" "transaction"
4760 "event" "active" "last_event" "last_active" "last_value"
4761 "driving" "driving_value" "ascending" "value" "image"
4762 "simple_name" "instance_name" "path_name"
4765 "List of VHDL'93 standardized attributes.")
4767 (defconst vhdl-ams-attributes
4770 "reference" "contribution" "tolerance"
4771 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4774 "List of VHDL-AMS standardized attributes.")
4776 (defconst vhdl-93-enum-values
4779 "note" "warning" "error" "failure"
4780 "read_mode" "write_mode" "append_mode"
4781 "open_ok" "status_error" "name_error" "mode_error"
4782 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4785 "List of VHDL'93 standardized enumeration values.")
4787 (defconst vhdl-ams-enum-values
4789 "quiescent_domain" "time_domain" "frequency_domain"
4790 ;; from `nature_pkg' package
4791 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4793 "List of VHDL-AMS standardized enumeration values.")
4795 (defconst vhdl-math-constants
4797 "math_e" "math_1_over_e"
4798 "math_pi" "math_two_pi" "math_1_over_pi"
4799 "math_half_pi" "math_q_pi" "math_3_half_pi"
4800 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4801 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4802 "math_deg_to_rad" "math_rad_to_deg"
4803 "cbase_1" "cbase_j" "czero"
4805 "List of Math Packages standardized constants.")
4807 (defconst vhdl-93-functions
4809 "now" "resolved" "rising_edge" "falling_edge"
4810 "read" "readline" "write" "writeline" "endfile"
4811 "resize" "is_X" "std_match"
4812 "shift_left" "shift_right" "rotate_left" "rotate_right"
4813 "to_unsigned" "to_signed" "to_integer"
4814 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4815 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4816 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4817 "shl" "shr" "ext" "sxt"
4820 "List of VHDL'93 standardized functions.")
4822 (defconst vhdl-ams-functions
4826 "List of VHDL-AMS standardized functions.")
4828 (defconst vhdl-math-functions
4830 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4831 "sqrt" "cbrt" "exp" "log"
4832 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4833 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4834 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4836 "List of Math Packages standardized functions.")
4838 (defconst vhdl-93-packages
4840 "std_logic_1164" "numeric_std" "numeric_bit"
4842 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4843 "std_logic_misc" "std_logic_textio"
4846 "List of VHDL'93 standardized packages and libraries.")
4848 (defconst vhdl-ams-packages
4850 ;; from `nature_pkg' package
4853 "List of VHDL-AMS standardized packages and libraries.")
4855 (defconst vhdl-math-packages
4857 "math_real" "math_complex"
4859 "List of Math Packages standardized packages and libraries.")
4861 (defvar vhdl-keywords nil
4862 "List of VHDL keywords.")
4864 (defvar vhdl-types nil
4865 "List of VHDL standardized types.")
4867 (defvar vhdl-attributes nil
4868 "List of VHDL standardized attributes.")
4870 (defvar vhdl-enum-values nil
4871 "List of VHDL standardized enumeration values.")
4873 (defvar vhdl-constants nil
4874 "List of VHDL standardized constants.")
4876 (defvar vhdl-functions nil
4877 "List of VHDL standardized functions.")
4879 (defvar vhdl-packages nil
4880 "List of VHDL standardized packages and libraries.")
4882 (defvar vhdl-reserved-words nil
4883 "List of additional reserved words.")
4885 (defvar vhdl-keywords-regexp nil
4886 "Regexp for VHDL keywords.")
4888 (defvar vhdl-types-regexp nil
4889 "Regexp for VHDL standardized types.")
4891 (defvar vhdl-attributes-regexp nil
4892 "Regexp for VHDL standardized attributes.")
4894 (defvar vhdl-enum-values-regexp nil
4895 "Regexp for VHDL standardized enumeration values.")
4897 (defvar vhdl-functions-regexp nil
4898 "Regexp for VHDL standardized functions.")
4900 (defvar vhdl-packages-regexp nil
4901 "Regexp for VHDL standardized packages and libraries.")
4903 (defvar vhdl-reserved-words-regexp nil
4904 "Regexp for additional reserved words.")
4906 (defvar vhdl-directive-keywords-regexp nil
4907 "Regexp for compiler directive keywords.")
4909 (defun vhdl-words-init ()
4910 "Initialize reserved words."
4912 (append vhdl-93-keywords
4913 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
4915 (append vhdl-93-types
4916 (when (vhdl-standard-p 'ams) vhdl-ams-types)
4917 (when (vhdl-standard-p 'math) vhdl-math-types)))
4918 (setq vhdl-attributes
4919 (append vhdl-93-attributes
4920 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
4921 (setq vhdl-enum-values
4922 (append vhdl-93-enum-values
4923 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
4924 (setq vhdl-constants
4925 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
4926 (setq vhdl-functions
4927 (append vhdl-93-functions
4928 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
4929 (when (vhdl-standard-p 'math) vhdl-math-functions)))
4931 (append vhdl-93-packages
4932 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
4933 (when (vhdl-standard-p 'math) vhdl-math-packages)))
4934 (setq vhdl-reserved-words
4935 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
4936 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
4938 (setq vhdl-keywords-regexp
4939 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
4940 (setq vhdl-types-regexp
4941 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
4942 (setq vhdl-attributes-regexp
4943 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
4944 (setq vhdl-enum-values-regexp
4945 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
4946 (setq vhdl-functions-regexp
4947 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
4948 (setq vhdl-packages-regexp
4949 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
4950 (setq vhdl-reserved-words-regexp
4952 (unless (equal vhdl-forbidden-syntax "")
4953 (concat vhdl-forbidden-syntax "\\|"))
4954 (regexp-opt vhdl-reserved-words)
4956 (setq vhdl-directive-keywords-regexp
4957 (concat "\\<\\(" (mapconcat 'regexp-quote
4958 vhdl-directive-keywords "\\|") "\\)\\>"))
4959 (vhdl-abbrev-list-init))
4961 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4964 (defvar vhdl-abbrev-list nil
4965 "Predefined abbreviations for VHDL.")
4967 (defun vhdl-abbrev-list-init ()
4968 (setq vhdl-abbrev-list
4970 (list vhdl-upper-case-keywords) vhdl-keywords
4971 (list vhdl-upper-case-types) vhdl-types
4972 (list vhdl-upper-case-attributes) vhdl-attributes
4973 (list vhdl-upper-case-enum-values) vhdl-enum-values
4974 (list vhdl-upper-case-constants) vhdl-constants
4975 (list nil) vhdl-functions
4976 (list nil) vhdl-packages)))
4978 ;; initialize reserved words for VHDL Mode
4982 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4984 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4986 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4989 ;; constant regular expressions for looking at various constructs
4991 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
4992 "Regexp describing a VHDL symbol.
4993 We cannot use just `word' syntax class since `_' cannot be in word
4994 class. Putting underscore in word class breaks forward word movement
4995 behavior that users are familiar with.")
4997 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
4998 "Regexp describing a case statement header key.")
5000 (defconst vhdl-label-key
5001 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5002 "Regexp describing a VHDL label.")
5004 ;; Macro definitions:
5006 (defmacro vhdl-point (position)
5007 "Return the value of point at certain commonly referenced POSITIONs.
5008 POSITION can be one of the following symbols:
5010 bol -- beginning of line
5012 bod -- beginning of defun
5013 boi -- back to indentation
5014 eoi -- last whitespace on line
5015 ionl -- indentation of next line
5016 iopl -- indentation of previous line
5017 bonl -- beginning of next line
5018 bopl -- beginning of previous line
5020 This function does not modify point or mark."
5021 (or (and (eq 'quote (car-safe position))
5022 (null (cddr position)))
5023 (error "ERROR: Bad buffer position requested: %s" position))
5024 (setq position (nth 1 position))
5025 `(let ((here (point)))
5027 ((eq position 'bol) '((beginning-of-line)))
5028 ((eq position 'eol) '((end-of-line)))
5029 ((eq position 'bod) '((save-match-data
5030 (vhdl-beginning-of-defun))))
5031 ((eq position 'boi) '((back-to-indentation)))
5032 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5033 ((eq position 'bonl) '((forward-line 1)))
5034 ((eq position 'bopl) '((forward-line -1)))
5035 ((eq position 'iopl)
5037 (back-to-indentation)))
5038 ((eq position 'ionl)
5040 (back-to-indentation)))
5041 (t (error "ERROR: Unknown buffer position requested: %s" position))
5046 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5047 ;; doesn't hurt for v19
5051 (defmacro vhdl-safe (&rest body)
5052 "Safely execute BODY, return nil if an error occurred."
5053 `(condition-case nil
5057 (defmacro vhdl-add-syntax (symbol &optional relpos)
5058 "A simple macro to append the syntax in SYMBOL to the syntax list.
5059 Try to increase performance by using this macro."
5060 `(setq vhdl-syntactic-context
5061 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5063 (defmacro vhdl-has-syntax (symbol)
5064 "A simple macro to return check the syntax list.
5065 Try to increase performance by using this macro."
5066 `(assoc ,symbol vhdl-syntactic-context))
5068 ;; Syntactic element offset manipulation:
5070 (defun vhdl-read-offset (langelem)
5071 "Read new offset value for LANGELEM from minibuffer.
5072 Return a valid value only."
5073 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5074 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5076 offset input interned)
5078 (setq input (read-string prompt oldoff)
5079 offset (cond ((string-equal "+" input) '+)
5080 ((string-equal "-" input) '-)
5081 ((string-equal "++" input) '++)
5082 ((string-equal "--" input) '--)
5083 ((string-match "^-?[0-9]+$" input)
5084 (string-to-number input))
5085 ((fboundp (setq interned (intern input)))
5087 ((boundp interned) interned)
5088 ;; error, but don't signal one, keep trying
5089 ;; to read an input value
5091 (setq prompt errmsg)
5095 (defun vhdl-set-offset (symbol offset &optional add-p)
5096 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5097 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5098 offset for that syntactic element. Optional ADD says to add SYMBOL to
5099 `vhdl-offsets-alist' if it doesn't already appear there."
5102 (intern (completing-read
5103 (concat "Syntactic symbol to change"
5104 (if current-prefix-arg " or add" "")
5109 (cons (format "%s" (car langelem)) nil)))
5111 nil (not current-prefix-arg)
5112 ;; initial contents tries to be the last element
5113 ;; on the syntactic analysis list for the current
5115 (let* ((syntax (vhdl-get-syntactic-context))
5116 (len (length syntax))
5117 (ic (format "%s" (car (nth (1- len) syntax)))))
5120 (offset (vhdl-read-offset langelem)))
5121 (list langelem offset current-prefix-arg)))
5122 ;; sanity check offset
5130 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5132 (let ((entry (assq symbol vhdl-offsets-alist)))
5134 (setcdr entry offset)
5136 (setq vhdl-offsets-alist
5137 (cons (cons symbol offset) vhdl-offsets-alist))
5138 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5139 (vhdl-keep-region-active))
5141 (defun vhdl-set-style (style &optional local)
5142 "Set `vhdl-mode' variables to use one of several different indentation styles.
5143 STYLE is a string representing the desired style and optional LOCAL is
5144 a flag which, if non-nil, means to make the style variables being
5145 changed buffer local, instead of the default, which is to set the
5146 global variables. Interactively, the flag comes from the prefix
5147 argument. The styles are chosen from the `vhdl-style-alist' variable."
5148 (interactive (list (completing-read "Use which VHDL indentation style? "
5149 vhdl-style-alist nil t)
5150 current-prefix-arg))
5151 (let ((vars (cdr (assoc style vhdl-style-alist))))
5153 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5154 ;; set all the variables
5158 (let ((var (car varentry))
5159 (val (cdr varentry)))
5161 (make-local-variable var))
5162 ;; special case for vhdl-offsets-alist
5163 (if (not (eq var 'vhdl-offsets-alist))
5165 ;; reset vhdl-offsets-alist to the default value first
5166 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5167 ;; now set the langelems that are different
5171 (let ((langelem (car langentry))
5172 (offset (cdr langentry)))
5173 (vhdl-set-offset langelem offset)
5178 (vhdl-keep-region-active))
5180 (defun vhdl-get-offset (langelem)
5181 "Get offset from LANGELEM which is a cons cell of the form:
5182 \(SYMBOL . RELPOS). The symbol is matched against
5183 vhdl-offsets-alist and the offset found there is either returned,
5184 or added to the indentation at RELPOS. If RELPOS is nil, then
5185 the offset is simply returned."
5186 (let* ((symbol (car langelem))
5187 (relpos (cdr langelem))
5188 (match (assq symbol vhdl-offsets-alist))
5189 (offset (cdr-safe match)))
5190 ;; offset can be a number, a function, a variable, or one of the
5194 (if vhdl-strict-syntax-p
5195 (error "ERROR: Don't know how to indent a %s" symbol)
5198 ((eq offset '+) (setq offset vhdl-basic-offset))
5199 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5200 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5201 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5202 ((and (not (numberp offset))
5204 (setq offset (funcall offset langelem)))
5205 ((not (numberp offset))
5206 (setq offset (eval offset)))
5209 (< relpos (vhdl-point 'bol)))
5216 ;; Syntactic support functions:
5218 (defun vhdl-in-comment-p ()
5219 "Check if point is in a comment."
5220 (eq (vhdl-in-literal) 'comment))
5222 (defun vhdl-in-string-p ()
5223 "Check if point is in a string."
5224 (eq (vhdl-in-literal) 'string))
5226 (defun vhdl-in-literal ()
5227 "Determine if point is in a VHDL literal."
5229 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5231 ((nth 3 state) 'string)
5232 ((nth 4 state) 'comment)
5235 (defun vhdl-forward-comment (&optional direction)
5236 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5237 negative, skip forward otherwise."
5239 (if (and direction (< direction 0))
5242 (skip-chars-backward " \t\n")
5243 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5244 (goto-char (match-beginning 3))
5245 (skip-chars-backward " \t\n")))
5247 (skip-chars-forward " \t\n")
5248 (while (looking-at "--.*")
5249 (goto-char (match-end 0))
5250 (skip-chars-forward " \t\n"))))
5252 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5253 (unless (and vhdl-xemacs (string< "21.2" emacs-version))
5254 (defalias 'vhdl-forward-comment 'forward-comment))
5256 ;; This is the best we can do in Win-Emacs.
5257 (defun vhdl-win-il (&optional lim)
5258 "Determine if point is in a VHDL literal."
5260 (let* ((here (point))
5263 (lim (or lim (vhdl-point 'bod))))
5265 (while (< (point) here)
5267 (and (re-search-forward "--\\|[\"']"
5269 (buffer-substring (match-beginning 0) (match-end 0))))
5274 ;; looking at the opening of a VHDL style comment
5275 ((string= "--" match)
5276 (if (<= here (progn (end-of-line) (point))) 'comment))
5277 ;; looking at the opening of a double quote string
5278 ((string= "\"" match)
5279 (if (not (save-restriction
5280 ;; this seems to be necessary since the
5281 ;; re-search-forward will not work without it
5282 (narrow-to-region (point) here)
5284 ;; this regexp matches a double quote
5285 ;; which is preceded by an even number
5286 ;; of backslashes, including zero
5287 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5289 ;; looking at the opening of a single quote string
5290 ((string= "'" match)
5291 (if (not (save-restriction
5292 ;; see comments from above
5293 (narrow-to-region (point) here)
5295 ;; this matches a single quote which is
5296 ;; preceded by zero or two backslashes.
5297 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5304 (and (string-match "Win-Emacs" emacs-version)
5305 (fset 'vhdl-in-literal 'vhdl-win-il))
5307 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5308 ;; defined as lexical whitespace or comments. Search no farther back
5309 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5310 ;; used for backward skipping, (point-max) is used for forward
5313 (defun vhdl-forward-syntactic-ws (&optional lim)
5314 "Forward skip of syntactic whitespace."
5316 (let* ((lim (or lim (point-max)))
5318 (hugenum (point-max)))
5319 (narrow-to-region lim (point))
5320 (while (/= here (point))
5322 (vhdl-forward-comment hugenum)))))
5324 ;; This is the best we can do in Win-Emacs.
5325 (defun vhdl-win-fsws (&optional lim)
5326 "Forward skip syntactic whitespace for Win-Emacs."
5327 (let ((lim (or lim (point-max)))
5330 (skip-chars-forward " \t\n\r\f" lim)
5333 ((looking-at "--") (end-of-line))
5334 ;; none of the above
5335 (t (setq stop t))))))
5337 (and (string-match "Win-Emacs" emacs-version)
5338 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5340 (defun vhdl-backward-syntactic-ws (&optional lim)
5341 "Backward skip over syntactic whitespace."
5343 (let* ((lim (or lim (point-min)))
5345 (hugenum (- (point-max))))
5348 (narrow-to-region lim (point))
5349 (while (/= here (point))
5351 (vhdl-forward-comment hugenum)))))))
5353 ;; This is the best we can do in Win-Emacs.
5354 (defun vhdl-win-bsws (&optional lim)
5355 "Backward skip syntactic whitespace for Win-Emacs."
5356 (let ((lim (or lim (vhdl-point 'bod)))
5359 (skip-chars-backward " \t\n\r\f" lim)
5362 ((eq (vhdl-in-literal) 'comment)
5363 (skip-chars-backward "^-" lim)
5364 (skip-chars-backward "-" lim)
5365 (while (not (or (and (= (following-char) ?-)
5366 (= (char-after (1+ (point))) ?-))
5368 (skip-chars-backward "^-" lim)
5369 (skip-chars-backward "-" lim)))
5370 ;; none of the above
5371 (t (setq stop t))))))
5373 (and (string-match "Win-Emacs" emacs-version)
5374 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5376 ;; Functions to help finding the correct indentation column:
5378 (defun vhdl-first-word (point)
5379 "If the keyword at POINT is at boi, then return (current-column) at
5380 that point, else nil."
5382 (and (goto-char point)
5383 (eq (point) (vhdl-point 'boi))
5386 (defun vhdl-last-word (point)
5387 "If the keyword at POINT is at eoi, then return (current-column) at
5388 that point, else nil."
5390 (and (goto-char point)
5391 (save-excursion (or (eq (progn (forward-sexp) (point))
5393 (looking-at "\\s-*\\(--\\)?")))
5396 ;; Core syntactic evaluation functions:
5398 (defconst vhdl-libunit-re
5399 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5401 (defun vhdl-libunit-p ()
5405 (skip-chars-forward " \t\n")
5406 (not (looking-at "is\\b[^_]")))
5409 (and (not (looking-at "use\\b[^_]"))
5412 (vhdl-forward-syntactic-ws)
5413 (/= (following-char) ?:))))
5416 (defconst vhdl-defun-re
5417 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5419 (defun vhdl-defun-p ()
5421 (if (looking-at "block\\|process\\|procedural")
5422 ;; "block", "process", "procedural":
5425 (not (looking-at "end\\s-+\\w")))
5426 ;; "architecture", "configuration", "entity",
5427 ;; "package", "procedure", "function":
5430 (defun vhdl-corresponding-defun ()
5431 "If the word at the current position corresponds to a \"defun\"
5432 keyword, then return a string that can be used to find the
5433 corresponding \"begin\" keyword, else return nil."
5435 (and (looking-at vhdl-defun-re)
5437 (if (looking-at "block\\|process\\|procedural")
5438 ;; "block", "process". "procedural:
5439 (buffer-substring (match-beginning 0) (match-end 0))
5440 ;; "architecture", "configuration", "entity", "package",
5441 ;; "procedure", "function":
5444 (defconst vhdl-begin-fwd-re
5445 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5446 "A regular expression for searching forward that matches all known
5447 \"begin\" keywords.")
5449 (defconst vhdl-begin-bwd-re
5450 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5451 "A regular expression for searching backward that matches all known
5452 \"begin\" keywords.")
5454 (defun vhdl-begin-p (&optional lim)
5455 "Return t if we are looking at a real \"begin\" keyword.
5456 Assumes that the caller will make sure that we are looking at
5457 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5458 the middle of an identifier that just happens to contain a \"begin\"
5461 ;; "[architecture|case|configuration|entity|package|
5462 ;; procedure|function] ... is":
5463 ((and (looking-at "i")
5465 ;; Skip backward over first sexp (needed to skip over a
5466 ;; procedure interface list, and is harmless in other
5467 ;; situations). Note that we need "return" in the
5468 ;; following search list so that we don't run into
5469 ;; semicolons in the function interface list.
5472 (while (and (not foundp)
5474 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5476 (if (or (= (preceding-char) ?_)
5480 (and (/= (following-char) ?\;)
5481 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5484 ((looking-at "be\\|t")
5487 ((and (looking-at "e")
5488 ;; make sure that the "else" isn't inside a
5489 ;; conditional signal assignment.
5491 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5492 (or (eq (following-char) ?\;)
5495 ;; "block", "generate", "loop", "process", "procedural",
5496 ;; "units", "record":
5497 ((and (looking-at "bl\\|[glpur]")
5500 (not (looking-at "end\\s-+\\w"))))
5503 ((and (looking-at "c")
5506 (not (looking-at "end\\s-+\\w")))
5507 ;; look out for the dreaded entity class in an attribute
5509 (vhdl-backward-syntactic-ws lim)
5510 (/= (preceding-char) ?:)))
5512 ;; "for" (inside configuration declaration):
5513 ((and (looking-at "f")
5516 (not (looking-at "end\\s-+\\w")))
5517 (vhdl-has-syntax 'configuration))
5521 (defun vhdl-corresponding-mid (&optional lim)
5523 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5525 ((looking-at "then")
5530 (defun vhdl-corresponding-end (&optional lim)
5531 "If the word at the current position corresponds to a \"begin\"
5532 keyword, then return a vector containing enough information to find
5533 the corresponding \"end\" keyword, else return nil. The keyword to
5534 search forward for is aref 0. The column in which the keyword must
5535 appear is aref 1 or nil if any column is suitable.
5536 Assumes that the caller will make sure that we are not in the middle
5537 of an identifier that just happens to contain a \"begin\" keyword."
5539 (and (looking-at vhdl-begin-fwd-re)
5540 (/= (preceding-char) ?_)
5541 (not (vhdl-in-literal))
5544 ;; "is", "generate", "loop":
5545 ((looking-at "[igl]")
5547 (and (vhdl-last-word (point))
5548 (or (vhdl-first-word (point))
5550 (vhdl-beginning-of-statement-1 lim)
5551 (vhdl-backward-skip-label lim)
5552 (vhdl-first-word (point)))))))
5553 ;; "begin", "else", "for":
5554 ((looking-at "be\\|[ef]")
5556 (and (vhdl-last-word (point))
5557 (or (vhdl-first-word (point))
5559 (vhdl-beginning-of-statement-1 lim)
5560 (vhdl-backward-skip-label lim)
5561 (vhdl-first-word (point)))))))
5562 ;; "component", "units", "record":
5563 ((looking-at "[cur]")
5564 ;; The first end found will close the block
5566 ;; "block", "process", "procedural":
5567 ((looking-at "bl\\|p")
5569 (or (vhdl-first-word (point))
5571 (vhdl-beginning-of-statement-1 lim)
5572 (vhdl-backward-skip-label lim)
5573 (vhdl-first-word (point))))))
5576 (vector "elsif\\|else\\|end\\s-+if"
5577 (and (vhdl-last-word (point))
5578 (or (vhdl-first-word (point))
5580 (vhdl-beginning-of-statement-1 lim)
5581 (vhdl-backward-skip-label lim)
5582 (vhdl-first-word (point)))))))
5585 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5587 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5589 (defun vhdl-end-p (&optional lim)
5590 "Return t if we are looking at a real \"end\" keyword.
5591 Assumes that the caller will make sure that we are looking at
5592 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5593 the middle of an identifier that just happens to contain an \"end\"
5595 (or (not (looking-at "else"))
5596 ;; make sure that the "else" isn't inside a conditional signal
5599 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5600 (or (eq (following-char) ?\;)
5601 (eq (point) lim)))))
5603 (defun vhdl-corresponding-begin (&optional lim)
5604 "If the word at the current position corresponds to an \"end\"
5605 keyword, then return a vector containing enough information to find
5606 the corresponding \"begin\" keyword, else return nil. The keyword to
5607 search backward for is aref 0. The column in which the keyword must
5608 appear is aref 1 or nil if any column is suitable. The supplementary
5609 keyword to search forward for is aref 2 or nil if this is not
5610 required. If aref 3 is t, then the \"begin\" keyword may be found in
5611 the middle of a statement.
5612 Assumes that the caller will make sure that we are not in the middle
5613 of an identifier that just happens to contain an \"end\" keyword."
5616 (if (and (looking-at vhdl-end-fwd-re)
5617 (not (vhdl-in-literal))
5619 (if (looking-at "el")
5621 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5625 (skip-chars-forward " \t\n")
5628 ((looking-at "if\\b[^_]")
5629 (vector "else\\|elsif\\|if"
5630 (vhdl-first-word pos)
5633 ((looking-at "component\\b[^_]")
5634 (vector (buffer-substring (match-beginning 1)
5636 (vhdl-first-word pos)
5638 ;; "end units", "end record":
5639 ((looking-at "\\(units\\|record\\)\\b[^_]")
5640 (vector (buffer-substring (match-beginning 1)
5642 (vhdl-first-word pos)
5644 ;; "end block", "end process", "end procedural":
5645 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5646 (vector "begin" (vhdl-first-word pos) nil nil))
5648 ((looking-at "case\\b[^_]")
5649 (vector "case" (vhdl-first-word pos) "is" nil))
5651 ((looking-at "generate\\b[^_]")
5652 (vector "generate\\|for\\|if"
5653 (vhdl-first-word pos)
5656 ((looking-at "loop\\b[^_]")
5657 (vector "loop\\|while\\|for"
5658 (vhdl-first-word pos)
5660 ;; "end for" (inside configuration declaration):
5661 ((looking-at "for\\b[^_]")
5662 (vector "for" (vhdl-first-word pos) nil nil))
5665 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5666 (vhdl-first-word pos)
5667 ;; return an alist of (statement . keyword) mappings
5669 ;; "begin ... end [id]":
5671 ;; "architecture ... is ... begin ... end [id]":
5672 ("architecture" . "is")
5673 ;; "configuration ... is ... end [id]":
5674 ("configuration" . "is")
5675 ;; "entity ... is ... end [id]":
5677 ;; "package ... is ... end [id]":
5679 ;; "procedure ... is ... begin ... end [id]":
5680 ("procedure" . "is")
5681 ;; "function ... is ... begin ... end [id]":
5688 (defconst vhdl-leader-re
5689 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5691 (defun vhdl-end-of-leader ()
5693 (cond ((looking-at "block\\|process\\|procedural")
5696 (skip-chars-forward " \t\n")
5697 (= (following-char) ?\())
5700 (when (looking-at "[ \t\n]*is")
5701 (goto-char (match-end 0)))
5703 ((looking-at "component")
5705 (when (looking-at "[ \t\n]*is")
5706 (goto-char (match-end 0)))
5710 (skip-chars-forward " \t\n")
5711 (while (looking-at "[,:(]")
5713 (skip-chars-forward " \t\n"))
5718 (defconst vhdl-trailer-re
5719 "\\b\\(is\\|then\\|generate\\|loop\\)\\b[^_]")
5721 (defconst vhdl-statement-fwd-re
5722 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5723 "A regular expression for searching forward that matches all known
5724 \"statement\" keywords.")
5726 (defconst vhdl-statement-bwd-re
5727 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5728 "A regular expression for searching backward that matches all known
5729 \"statement\" keywords.")
5731 (defun vhdl-statement-p (&optional lim)
5732 "Return t if we are looking at a real \"statement\" keyword.
5733 Assumes that the caller will make sure that we are looking at
5734 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5735 in the middle of an identifier that just happens to contain a
5736 \"statement\" keyword."
5738 ;; "for" ... "generate":
5739 ((and (looking-at "f")
5740 ;; Make sure it's the start of a parameter specification.
5743 (skip-chars-forward " \t\n")
5744 (looking-at "in\\b[^_]"))
5745 ;; Make sure it's not an "end for".
5748 (not (looking-at "end\\s-+\\w"))))
5750 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5751 ((and (looking-at "i")
5752 ;; Make sure it's not an "end if".
5755 (not (looking-at "end\\s-+\\w"))))
5757 ;; "while" ... "loop":
5762 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5763 "Regexp describing a case statement alternative key.")
5765 (defun vhdl-case-alternative-p (&optional lim)
5766 "Return t if we are looking at a real case alternative.
5767 Assumes that the caller will make sure that we are looking at
5768 vhdl-case-alternative-re, and are not inside a literal, and that
5769 we are not in the middle of an identifier that just happens to
5770 contain a \"when\" keyword."
5773 (while (and (not foundp)
5774 (re-search-backward ";\\|<=" lim 'move))
5775 (if (or (= (preceding-char) ?_)
5779 (or (eq (following-char) ?\;)
5783 ;; Core syntactic movement functions:
5785 (defconst vhdl-b-t-b-re
5786 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5788 (defun vhdl-backward-to-block (&optional lim)
5789 "Move backward to the previous \"begin\" or \"end\" keyword."
5791 (while (and (not foundp)
5792 (re-search-backward vhdl-b-t-b-re lim 'move))
5793 (if (or (= (preceding-char) ?_)
5798 ((and (looking-at vhdl-begin-fwd-re)
5799 (/= (preceding-char) ?_)
5801 (setq foundp 'begin))
5803 ((and (looking-at vhdl-end-fwd-re)
5804 (/= (preceding-char) ?_)
5812 (defun vhdl-forward-sexp (&optional count lim)
5813 "Move forward across one balanced expression (sexp).
5814 With COUNT, do it that many times."
5816 (let ((count (or count 1))
5817 (case-fold-search t)
5822 (skip-chars-forward " \t\n")
5823 ;; Check for an unbalanced "end" keyword
5824 (if (and (looking-at vhdl-end-fwd-re)
5825 (/= (preceding-char) ?_)
5826 (not (vhdl-in-literal))
5828 (not (looking-at "else")))
5830 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5831 ;; If the current keyword is a "begin" keyword, then find the
5832 ;; corresponding "end" keyword.
5833 (if (setq end-vec (vhdl-corresponding-end lim))
5835 ;; end-re is the statement keyword to search for
5837 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5838 ;; column is either the statement keyword target column
5840 (column (aref end-vec 1))
5841 (eol (vhdl-point 'eol))
5842 foundp literal placeholder)
5843 ;; Look for the statement keyword.
5844 (while (and (not foundp)
5845 (re-search-forward end-re nil t)
5846 (setq placeholder (match-end 1))
5847 (goto-char (match-beginning 0)))
5848 ;; If we are in a literal, or not in the right target
5849 ;; column and not on the same line as the begin, then
5852 (/= (current-indentation) column)
5854 (= (preceding-char) ?_)
5855 (setq literal (vhdl-in-literal)))
5856 (if (eq literal 'comment)
5859 ;; An "else" keyword corresponds to both the opening brace
5860 ;; of the following sexp and the closing brace of the
5862 (if (not (looking-at "else"))
5863 (goto-char placeholder))
5867 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
5869 ;; If the current keyword is not a "begin" keyword, then just
5870 ;; perform the normal forward-sexp.
5873 (setq count (1- count))
5875 (setq target (point)))
5879 (defun vhdl-backward-sexp (&optional count lim)
5880 "Move backward across one balanced expression (sexp).
5881 With COUNT, do it that many times. LIM bounds any required backward
5884 (let ((count (or count 1))
5885 (case-fold-search t)
5889 ;; Perform the normal backward-sexp, unless we are looking at
5890 ;; "else" - an "else" keyword corresponds to both the opening brace
5891 ;; of the following sexp and the closing brace of the previous sexp.
5892 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
5893 (/= (preceding-char) ?_)
5894 (not (vhdl-in-literal)))
5897 (if (and (looking-at vhdl-begin-fwd-re)
5898 (/= (preceding-char) ?_)
5899 (not (vhdl-in-literal))
5901 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
5902 ;; If the current keyword is an "end" keyword, then find the
5903 ;; corresponding "begin" keyword.
5904 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
5905 (/= (preceding-char) ?_))
5907 ;; begin-re is the statement keyword to search for
5909 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
5910 ;; column is either the statement keyword target column
5912 (column (aref begin-vec 1))
5913 ;; internal-p controls where the statement keyword can
5915 (internal-p (aref begin-vec 3))
5916 (last-backward (point)) last-forward
5917 foundp literal keyword)
5918 ;; Look for the statement keyword.
5919 (while (and (not foundp)
5920 (re-search-backward begin-re lim t)
5922 (buffer-substring (match-beginning 1)
5924 ;; If we are in a literal or in the wrong column,
5927 (and (/= (current-indentation) column)
5928 ;; possibly accept current-column as
5929 ;; well as current-indentation.
5930 (or (not internal-p)
5931 (/= (current-column) column))))
5932 (= (preceding-char) ?_)
5935 ;; If there is a supplementary keyword, then
5936 ;; search forward for it.
5937 (if (and (setq begin-re (aref begin-vec 2))
5938 (or (not (listp begin-re))
5939 ;; If begin-re is an alist, then find the
5940 ;; element corresponding to the actual
5941 ;; keyword that we found.
5944 (assoc keyword begin-re))
5946 (setq begin-re (cdr begin-re))))))
5949 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
5951 (setq last-forward (point))
5952 ;; Look for the supplementary keyword
5953 ;; (bounded by the backward search start
5955 (while (and (not foundp)
5956 (re-search-forward begin-re
5958 (goto-char (match-beginning 1)))
5959 ;; If we are in a literal, then try again.
5960 (if (or (= (preceding-char) ?_)
5963 (if (eq literal 'comment)
5965 (min (vhdl-point 'eol) last-backward))
5967 ;; We have found the supplementary keyword.
5968 ;; Save the position of the keyword in foundp.
5969 (setq foundp (point)))
5972 ;; If the supplementary keyword was found, then
5973 ;; move point to the supplementary keyword.
5975 ;; If there was no supplementary keyword, then
5976 ;; point is already at the statement keyword.
5978 ) ; end of the search for the statement keyword
5980 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
5982 (setq count (1- count))
5984 (setq target (point)))
5988 (defun vhdl-backward-up-list (&optional count limit)
5989 "Move backward out of one level of blocks.
5990 With argument, do this that many times."
5992 (let ((count (or count 1))
5996 (if (looking-at vhdl-defun-re)
5997 (error "ERROR: Unbalanced blocks"))
5998 (vhdl-backward-to-block limit)
5999 (setq count (1- count)))
6000 (setq target (point)))
6001 (goto-char target)))
6003 (defun vhdl-end-of-defun (&optional count)
6004 "Move forward to the end of a VHDL defun."
6006 (let ((case-fold-search t))
6007 (vhdl-beginning-of-defun)
6008 (if (not (looking-at "block\\|process\\|procedural"))
6009 (re-search-forward "\\bis\\b"))
6010 (vhdl-forward-sexp)))
6012 (defun vhdl-mark-defun ()
6013 "Put mark at end of this \"defun\", point at beginning."
6015 (let ((case-fold-search t))
6017 (vhdl-beginning-of-defun)
6019 (if (not (looking-at "block\\|process\\|procedural"))
6020 (re-search-forward "\\bis\\b"))
6022 (exchange-point-and-mark)))
6024 (defun vhdl-beginning-of-libunit ()
6025 "Move backward to the beginning of a VHDL library unit.
6026 Returns the location of the corresponding begin keyword, unless search
6027 stops due to beginning or end of buffer.
6028 Note that if point is between the \"libunit\" keyword and the
6029 corresponding \"begin\" keyword, then that libunit will not be
6030 recognized, and the search will continue backwards. If point is
6031 at the \"begin\" keyword, then the defun will be recognized. The
6032 returned point is at the first character of the \"libunit\" keyword."
6033 (let ((last-forward (point))
6035 ;; Just in case we are actually sitting on the "begin"
6036 ;; keyword, allow for the keyword and an extra character,
6037 ;; as this will be used when looking forward for the
6039 (save-excursion (forward-word 1) (1+ (point))))
6040 foundp literal placeholder)
6041 ;; Find the "libunit" keyword.
6042 (while (and (not foundp)
6043 (re-search-backward vhdl-libunit-re nil 'move))
6044 ;; If we are in a literal, or not at a real libunit, then try again.
6045 (if (or (= (preceding-char) ?_)
6047 (not (vhdl-libunit-p)))
6049 ;; Find the corresponding "begin" keyword.
6050 (setq last-forward (point))
6051 (while (and (not foundp)
6052 (re-search-forward "\\bis\\b[^_]" last-backward t)
6053 (setq placeholder (match-beginning 0)))
6054 (if (or (= (preceding-char) ?_)
6055 (setq literal (vhdl-in-literal)))
6056 ;; It wasn't a real keyword, so keep searching.
6057 (if (eq literal 'comment)
6059 (min (vhdl-point 'eol) last-backward))
6061 ;; We have found the begin keyword, loop will exit.
6062 (setq foundp placeholder)))
6063 ;; Go back to the libunit keyword
6064 (goto-char last-forward)))
6067 (defun vhdl-beginning-of-defun (&optional count)
6068 "Move backward to the beginning of a VHDL defun.
6069 With argument, do it that many times.
6070 Returns the location of the corresponding begin keyword, unless search
6071 stops due to beginning or end of buffer."
6072 ;; Note that if point is between the "defun" keyword and the
6073 ;; corresponding "begin" keyword, then that defun will not be
6074 ;; recognised, and the search will continue backwards. If point is
6075 ;; at the "begin" keyword, then the defun will be recognised. The
6076 ;; returned point is at the first character of the "defun" keyword.
6078 (let ((count (or count 1))
6079 (case-fold-search t)
6080 (last-forward (point))
6084 (goto-char last-forward)
6085 (let ((last-backward
6086 ;; Just in case we are actually sitting on the "begin"
6087 ;; keyword, allow for the keyword and an extra character,
6088 ;; as this will be used when looking forward for the
6090 (save-excursion (forward-word 1) (1+ (point))))
6091 begin-string literal)
6092 (while (and (not foundp)
6093 (re-search-backward vhdl-defun-re nil 'move))
6094 ;; If we are in a literal, then try again.
6095 (if (or (= (preceding-char) ?_)
6098 (if (setq begin-string (vhdl-corresponding-defun))
6099 ;; This is a real defun keyword.
6100 ;; Find the corresponding "begin" keyword.
6101 ;; Look for the begin keyword.
6103 ;; Save the search start point.
6104 (setq last-forward (point))
6105 (while (and (not foundp)
6106 (search-forward begin-string last-backward t))
6107 (if (or (= (preceding-char) ?_)
6109 (setq literal (vhdl-in-literal))))
6110 ;; It wasn't a real keyword, so keep searching.
6111 (if (eq literal 'comment)
6113 (min (vhdl-point 'eol) last-backward))
6115 ;; We have found the begin keyword, loop will exit.
6116 (setq foundp (match-beginning 0)))
6118 ;; Go back to the defun keyword
6119 (goto-char last-forward)) ; end search for begin keyword
6121 ) ; end of the search for the defun keyword
6123 (setq count (1- count))
6125 (vhdl-keep-region-active)
6128 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6129 "Go to the beginning of the innermost VHDL statement.
6130 With prefix arg, go back N - 1 statements. If already at the
6131 beginning of a statement then go to the beginning of the preceding
6132 one. If within a string or comment, or next to a comment (only
6133 whitespace between), move by sentences instead of statements.
6135 When called from a program, this function takes 3 optional args: the
6136 prefix arg, and a buffer position limit which is the farthest back to
6137 search, and something whose meaning I don't understand."
6138 (interactive "p\np")
6139 (let ((count (or count 1))
6140 (case-fold-search t)
6141 (lim (or lim (point-min)))
6146 (setq state (parse-partial-sexp (point) here nil nil)))
6147 (if (and interactive
6150 (looking-at (concat "[ \t]*" comment-start-skip))))
6151 (forward-sentence (- count))
6153 (vhdl-beginning-of-statement-1 lim)
6154 (setq count (1- count))))
6155 ;; its possible we've been left up-buf of lim
6156 (goto-char (max (point) lim))
6158 (vhdl-keep-region-active))
6160 (defconst vhdl-e-o-s-re
6161 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6163 (defun vhdl-end-of-statement ()
6164 "Very simple implementation."
6166 (re-search-forward vhdl-e-o-s-re))
6168 (defconst vhdl-b-o-s-re
6169 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6170 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6172 (defun vhdl-beginning-of-statement-1 (&optional lim)
6173 "Move to the start of the current statement, or the previous
6174 statement if already at the beginning of one."
6175 (let ((lim (or lim (point-min)))
6179 ;; go backwards one balanced expression, but be careful of
6180 ;; unbalanced paren being reached
6181 (if (not (vhdl-safe (progn (backward-sexp) t)))
6183 (backward-up-list 1)
6185 (vhdl-forward-syntactic-ws here)
6187 (while (and (not donep)
6189 ;; look backwards for a statement boundary
6190 (re-search-backward vhdl-b-o-s-re lim 'move))
6191 (if (or (= (preceding-char) ?_)
6195 ;; If we are looking at an open paren, then stop after it
6196 ((eq (following-char) ?\()
6198 (vhdl-forward-syntactic-ws here)
6200 ;; If we are looking at a close paren, then skip it
6201 ((eq (following-char) ?\))
6206 (progn (goto-char pos)
6207 (vhdl-forward-syntactic-ws here)
6209 ;; If we are looking at a semicolon, then stop
6210 ((eq (following-char) ?\;)
6213 (vhdl-forward-syntactic-ws here)
6215 ;; If we are looking at a "begin", then stop
6216 ((and (looking-at vhdl-begin-fwd-re)
6217 (/= (preceding-char) ?_)
6219 ;; If it's a leader "begin", then find the
6221 (if (looking-at vhdl-leader-re)
6223 ;; set a default stop point at the begin
6225 ;; is the start point inside the leader area ?
6226 (goto-char (vhdl-end-of-leader))
6227 (vhdl-forward-syntactic-ws here)
6228 (if (< (point) here)
6229 ;; start point was not inside leader area
6230 ;; set stop point at word after leader
6231 (setq pos (point))))
6233 (vhdl-forward-syntactic-ws here)
6237 ;; If we are looking at a "statement", then stop
6238 ((and (looking-at vhdl-statement-fwd-re)
6239 (/= (preceding-char) ?_)
6240 (vhdl-statement-p nil))
6242 ;; If we are looking at a case alternative key, then stop
6243 ((and (looking-at vhdl-case-alternative-re)
6244 (vhdl-case-alternative-p lim))
6246 ;; set a default stop point at the when
6248 ;; is the start point inside the case alternative key ?
6249 (looking-at vhdl-case-alternative-re)
6250 (goto-char (match-end 0))
6251 (vhdl-forward-syntactic-ws here)
6252 (if (< (point) here)
6253 ;; start point was not inside the case alternative key
6254 ;; set stop point at word after case alternative keyleader
6255 (setq pos (point))))
6258 ;; Bogus find, continue
6263 ;; Defuns for calculating the current syntactic state:
6265 (defun vhdl-get-library-unit (bod placeholder)
6266 "If there is an enclosing library unit at bod, with it's \"begin\"
6267 keyword at placeholder, then return the library unit type."
6268 (let ((here (vhdl-point 'bol)))
6270 (goto-char placeholder)
6271 (vhdl-safe (vhdl-forward-sexp 1 bod))
6276 ((looking-at "e") 'entity)
6277 ((looking-at "a") 'architecture)
6278 ((looking-at "c") 'configuration)
6283 (vhdl-forward-syntactic-ws here)
6284 (if (looking-at "body\\b[^_]")
6285 'package-body 'package))))))
6288 (defun vhdl-get-block-state (&optional lim)
6289 "Finds and records all the closest opens.
6290 lim is the furthest back we need to search (it should be the
6291 previous libunit keyword)."
6292 (let ((here (point))
6293 (lim (or lim (point-min)))
6294 keyword sexp-start sexp-mid sexp-end
6295 preceding-sexp containing-sexp
6296 containing-begin containing-mid containing-paren)
6298 ;; Find the containing-paren, and use that as the limit
6299 (if (setq containing-paren
6301 (narrow-to-region lim (point))
6302 (vhdl-safe (scan-lists (point) -1 1))))
6303 (setq lim containing-paren))
6304 ;; Look backwards for "begin" and "end" keywords.
6305 (while (and (> (point) lim)
6306 (not containing-sexp))
6307 (setq keyword (vhdl-backward-to-block lim))
6309 ((eq keyword 'begin)
6310 ;; Found a "begin" keyword
6311 (setq sexp-start (point))
6312 (setq sexp-mid (vhdl-corresponding-mid lim))
6313 (setq sexp-end (vhdl-safe
6315 (vhdl-forward-sexp 1 lim) (point))))
6316 (if (and sexp-end (<= sexp-end here))
6317 ;; we want to record this sexp, but we only want to
6318 ;; record the last-most of any of them before here
6320 (setq preceding-sexp sexp-start))
6321 ;; we're contained in this sexp so put sexp-start on
6323 (setq containing-sexp sexp-start)
6324 (setq containing-mid sexp-mid)
6325 (setq containing-begin t)))
6327 ;; Found an "end" keyword
6329 (setq sexp-end (point))
6332 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6333 (progn (backward-sexp) (point))))
6334 ;; we want to record this sexp, but we only want to
6335 ;; record the last-most of any of them before here
6337 (setq preceding-sexp sexp-start)))
6339 ;; Check if the containing-paren should be the containing-sexp
6340 (if (and containing-paren
6341 (or (null containing-sexp)
6342 (< containing-sexp containing-paren)))
6343 (setq containing-sexp containing-paren
6345 containing-begin nil
6346 containing-mid nil))
6347 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6351 (defconst vhdl-s-c-a-re
6352 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6354 (defun vhdl-skip-case-alternative (&optional lim)
6355 "Skip forward over case/when bodies, with optional maximal
6356 limit. If no next case alternative is found, nil is returned and point
6358 (let ((lim (or lim (point-max)))
6361 (while (and (< (point) lim)
6363 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6365 (not (vhdl-in-literal)))
6366 (/= (match-beginning 0) here))
6368 (goto-char (match-beginning 0))
6370 ((and (looking-at "case")
6371 (re-search-forward "\\bis[^_]" lim t))
6373 (vhdl-forward-sexp))
6381 (defun vhdl-backward-skip-label (&optional lim)
6382 "Skip backward over a label, with optional maximal
6383 limit. If label is not found, nil is returned and point
6385 (let ((lim (or lim (point-min)))
6388 (vhdl-backward-syntactic-ws lim)
6389 (and (eq (preceding-char) ?:)
6392 (setq placeholder (point))
6393 (looking-at vhdl-label-key))))
6394 (goto-char placeholder))
6397 (defun vhdl-forward-skip-label (&optional lim)
6398 "Skip forward over a label, with optional maximal
6399 limit. If label is not found, nil is returned and point
6401 (let ((lim (or lim (point-max))))
6402 (if (looking-at vhdl-label-key)
6404 (goto-char (match-end 0))
6405 (vhdl-forward-syntactic-ws lim)))
6408 (defun vhdl-get-syntactic-context ()
6409 "Guess the syntactic description of the current line of VHDL code."
6413 (let* ((indent-point (point))
6414 (case-fold-search t)
6415 vec literal containing-sexp preceding-sexp
6416 containing-begin containing-mid containing-leader
6417 char-before-ip char-after-ip begin-after-ip end-after-ip
6418 placeholder lim library-unit
6421 ;; Reset the syntactic context
6422 (setq vhdl-syntactic-context nil)
6425 ;; Move to the start of the previous library unit, and
6426 ;; record the position of the "begin" keyword.
6427 (setq placeholder (vhdl-beginning-of-libunit))
6428 ;; The position of the "libunit" keyword gives us a gross
6433 ;; If there is a previous library unit, and we are enclosed by
6434 ;; it, then set the syntax accordingly.
6436 (setq library-unit (vhdl-get-library-unit lim placeholder))
6437 (vhdl-add-syntax library-unit lim))
6439 ;; Find the surrounding state.
6440 (if (setq vec (vhdl-get-block-state lim))
6442 (setq containing-sexp (aref vec 0))
6443 (setq preceding-sexp (aref vec 1))
6444 (setq containing-begin (aref vec 2))
6445 (setq containing-mid (aref vec 3))
6448 ;; set the limit on the farthest back we need to search
6449 (setq lim (if containing-sexp
6451 (goto-char containing-sexp)
6452 ;; set containing-leader if required
6453 (if (looking-at vhdl-leader-re)
6454 (setq containing-leader (vhdl-end-of-leader)))
6458 ;; cache char before and after indent point, and move point to
6459 ;; the most likely position to perform the majority of tests
6460 (goto-char indent-point)
6461 (skip-chars-forward " \t")
6462 (setq literal (vhdl-in-literal))
6463 (setq char-after-ip (following-char))
6464 (setq begin-after-ip (and
6466 (looking-at vhdl-begin-fwd-re)
6468 (setq end-after-ip (and
6470 (looking-at vhdl-end-fwd-re)
6472 (vhdl-backward-syntactic-ws lim)
6473 (setq char-before-ip (preceding-char))
6474 (goto-char indent-point)
6475 (skip-chars-forward " \t")
6477 ;; now figure out syntactic qualities of the current line
6479 ;; CASE 1: in a string or comment.
6480 ((memq literal '(string comment))
6481 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6482 ;; CASE 2: Line is at top level.
6483 ((null containing-sexp)
6484 ;; Find the point to which indentation will be relative
6486 (if (null preceding-sexp)
6488 ;; no preceding-sexp -> use the preceding statement
6489 (vhdl-beginning-of-statement-1 lim)
6491 ;; if there is a preceding-sexp then indent relative to it
6492 (goto-char preceding-sexp)
6493 ;; if not at boi, then the block-opening keyword is
6494 ;; probably following a label, so we need a different
6496 (if (/= (point) (vhdl-point 'boi))
6498 (vhdl-beginning-of-statement-1 lim)))
6499 ;; v-b-o-s could have left us at point-min
6502 (vhdl-forward-syntactic-ws indent-point))
6503 (setq placeholder (point)))
6505 ;; CASE 2A : we are looking at a block-open
6507 (vhdl-add-syntax 'block-open placeholder))
6508 ;; CASE 2B: we are looking at a block-close
6510 (vhdl-add-syntax 'block-close placeholder))
6511 ;; CASE 2C: we are looking at a top-level statement
6513 (vhdl-backward-syntactic-ws lim)
6515 (= (preceding-char) ?\;)))
6516 (vhdl-add-syntax 'statement placeholder))
6517 ;; CASE 2D: we are looking at a top-level statement-cont
6519 (vhdl-beginning-of-statement-1 lim)
6520 ;; v-b-o-s could have left us at point-min
6523 (vhdl-forward-syntactic-ws indent-point))
6524 (vhdl-add-syntax 'statement-cont (point)))
6526 ;; CASE 3: line is inside parentheses. Most likely we are
6527 ;; either in a subprogram argument (interface) list, or a
6528 ;; continued expression containing parentheses.
6529 ((null containing-begin)
6530 (vhdl-backward-syntactic-ws containing-sexp)
6532 ;; CASE 3A: we are looking at the arglist closing paren
6533 ((eq char-after-ip ?\))
6534 (goto-char containing-sexp)
6535 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6536 ;; CASE 3B: we are looking at the first argument in an empty
6538 ((eq char-before-ip ?\()
6539 (goto-char containing-sexp)
6540 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6541 ;; CASE 3C: we are looking at an arglist continuation line,
6542 ;; but the preceding argument is on the same line as the
6543 ;; opening paren. This case includes multi-line
6544 ;; expression paren groupings.
6545 ((and (save-excursion
6546 (goto-char (1+ containing-sexp))
6547 (skip-chars-forward " \t")
6549 (not (looking-at "--")))
6551 (vhdl-beginning-of-statement-1 containing-sexp)
6552 (skip-chars-backward " \t(")
6553 (<= (point) containing-sexp)))
6554 (goto-char containing-sexp)
6555 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6556 ;; CASE 3D: we are looking at just a normal arglist
6557 ;; continuation line
6558 (t (vhdl-beginning-of-statement-1 containing-sexp)
6559 (vhdl-forward-syntactic-ws indent-point)
6560 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6562 ;; CASE 4: A block mid open
6563 ((and begin-after-ip
6564 (looking-at containing-mid))
6565 (goto-char containing-sexp)
6566 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6567 (if (looking-at vhdl-trailer-re)
6569 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6570 (vhdl-backward-skip-label (vhdl-point 'boi))
6571 (vhdl-add-syntax 'block-open (point)))
6572 ;; CASE 5: block close brace
6574 (goto-char containing-sexp)
6575 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6576 (if (looking-at vhdl-trailer-re)
6578 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6579 (vhdl-backward-skip-label (vhdl-point 'boi))
6580 (vhdl-add-syntax 'block-close (point)))
6581 ;; CASE 6: A continued statement
6582 ((and (/= char-before-ip ?\;)
6583 ;; check it's not a trailer begin keyword, or a begin
6584 ;; keyword immediately following a label.
6585 (not (and begin-after-ip
6586 (or (looking-at vhdl-trailer-re)
6588 (vhdl-backward-skip-label containing-sexp)))))
6589 ;; check it's not a statement keyword
6590 (not (and (looking-at vhdl-statement-fwd-re)
6591 (vhdl-statement-p)))
6592 ;; see if the b-o-s is before the indent point
6595 (vhdl-beginning-of-statement-1 containing-sexp)
6596 ;; If we ended up after a leader, then this will
6597 ;; move us forward to the start of the first
6598 ;; statement. Note that a containing sexp here is
6599 ;; always a keyword, not a paren, so this will
6600 ;; have no effect if we hit the containing-sexp.
6601 (vhdl-forward-syntactic-ws indent-point)
6602 (setq placeholder (point))))
6603 ;; check it's not a block-intro
6604 (/= placeholder containing-sexp)
6605 ;; check it's not a case block-intro
6607 (goto-char placeholder)
6608 (or (not (looking-at vhdl-case-alternative-re))
6609 (> (match-end 0) indent-point))))
6610 ;; Make placeholder skip a label, but only if it puts us
6611 ;; before the indent point at the start of a line.
6612 (let ((new placeholder))
6613 (if (and (> indent-point
6615 (goto-char placeholder)
6616 (vhdl-forward-skip-label indent-point)
6617 (setq new (point))))
6620 (eq new (progn (back-to-indentation) (point)))))
6621 (setq placeholder new)))
6622 (vhdl-add-syntax 'statement-cont placeholder)
6624 (vhdl-add-syntax 'block-open)))
6625 ;; Statement. But what kind?
6626 ;; CASE 7: A case alternative key
6627 ((and (looking-at vhdl-case-alternative-re)
6628 (vhdl-case-alternative-p containing-sexp))
6629 ;; for a case alternative key, we set relpos to the first
6630 ;; non-whitespace char on the line containing the "case"
6632 (goto-char containing-sexp)
6633 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6634 (if (looking-at vhdl-trailer-re)
6635 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6636 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6637 ;; CASE 8: statement catchall
6639 ;; we know its a statement, but we need to find out if it is
6640 ;; the first statement in a block
6641 (if containing-leader
6642 (goto-char containing-leader)
6643 (goto-char containing-sexp)
6644 ;; Note that a containing sexp here is always a keyword,
6645 ;; not a paren, so skip over the keyword.
6647 ;; move to the start of the first statement
6648 (vhdl-forward-syntactic-ws indent-point)
6649 (setq placeholder (point))
6650 ;; we want to ignore case alternatives keys when skipping forward
6652 (while (looking-at vhdl-case-alternative-re)
6653 (setq incase-p (point))
6654 ;; we also want to skip over the body of the
6655 ;; case/when statement if that doesn't put us at
6656 ;; after the indent-point
6657 (while (vhdl-skip-case-alternative indent-point))
6658 ;; set up the match end
6659 (looking-at vhdl-case-alternative-re)
6660 (goto-char (match-end 0))
6661 ;; move to the start of the first case alternative statement
6662 (vhdl-forward-syntactic-ws indent-point)
6663 (setq placeholder (point)))
6665 ;; CASE 8A: we saw a case/when statement so we must be
6666 ;; in a switch statement. find out if we are at the
6667 ;; statement just after a case alternative key
6669 (= (point) indent-point))
6670 ;; relpos is the "when" keyword
6671 (vhdl-add-syntax 'statement-case-intro incase-p))
6672 ;; CASE 8B: any old statement
6673 ((< (point) indent-point)
6674 ;; relpos is the first statement of the block
6675 (vhdl-add-syntax 'statement placeholder)
6677 (vhdl-add-syntax 'block-open)))
6678 ;; CASE 8C: first statement in a block
6680 (goto-char containing-sexp)
6681 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6682 (if (looking-at vhdl-trailer-re)
6683 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6684 (vhdl-backward-skip-label (vhdl-point 'boi))
6685 (vhdl-add-syntax 'statement-block-intro (point))
6687 (vhdl-add-syntax 'block-open)))
6691 ;; now we need to look at any modifiers
6692 (goto-char indent-point)
6693 (skip-chars-forward " \t")
6694 (if (looking-at "--")
6695 (vhdl-add-syntax 'comment))
6696 ;; return the syntax
6697 vhdl-syntactic-context))))
6699 ;; Standard indentation line-ups:
6701 (defun vhdl-lineup-arglist (langelem)
6702 "Lineup the current arglist line with the arglist appearing just
6703 after the containing paren which starts the arglist."
6705 (let* ((containing-sexp
6707 ;; arglist-cont-nonempty gives relpos ==
6708 ;; to boi of containing-sexp paren. This
6709 ;; is good when offset is +, but bad
6710 ;; when it is vhdl-lineup-arglist, so we
6711 ;; have to special case a kludge here.
6712 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6715 (backward-up-list 1)
6716 (skip-chars-forward " \t" (vhdl-point 'eol)))
6717 (goto-char (cdr langelem)))
6719 (cs-curcol (save-excursion
6720 (goto-char (cdr langelem))
6724 (looking-at "[ \t]*)"))
6725 (progn (goto-char (match-end 0))
6728 (vhdl-forward-syntactic-ws)
6729 (- (current-column) cs-curcol))
6730 (goto-char containing-sexp)
6732 (let ((eol (vhdl-point 'eol))
6735 (skip-chars-forward " \t")
6737 (vhdl-forward-syntactic-ws)
6740 (- (current-column) cs-curcol)
6743 (defun vhdl-lineup-arglist-intro (langelem)
6744 "Lineup an arglist-intro line to just after the open paren."
6746 (let ((cs-curcol (save-excursion
6747 (goto-char (cdr langelem))
6749 (ce-curcol (save-excursion
6751 (backward-up-list 1)
6752 (skip-chars-forward " \t" (vhdl-point 'eol))
6754 (- ce-curcol cs-curcol -1))))
6756 (defun vhdl-lineup-comment (langelem)
6757 "Support old behavior for comment indentation. We look at
6758 vhdl-comment-only-line-offset to decide how to indent comment
6761 (back-to-indentation)
6762 ;; at or to the right of comment-column
6763 (if (>= (current-column) comment-column)
6764 (vhdl-comment-indent)
6765 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6767 (or (car-safe vhdl-comment-only-line-offset)
6768 vhdl-comment-only-line-offset)
6769 (or (cdr-safe vhdl-comment-only-line-offset)
6770 (car-safe vhdl-comment-only-line-offset)
6771 -1000 ;jam it against the left side
6774 (defun vhdl-lineup-statement-cont (langelem)
6775 "Line up statement-cont after the assignment operator."
6777 (let* ((relpos (cdr langelem))
6778 (assignp (save-excursion
6779 (goto-char (vhdl-point 'boi))
6780 (and (re-search-forward "\\(<\\|:\\)="
6781 (vhdl-point 'eol) t)
6782 (- (point) (vhdl-point 'boi)))))
6787 (while (and (not foundp)
6788 (< (point) (vhdl-point 'eol)))
6789 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6790 (if (vhdl-in-literal)
6792 (if (= (preceding-char) ?\()
6793 ;; skip over any parenthesized expressions
6794 (goto-char (min (vhdl-point 'eol)
6795 (scan-lists (point) 1 1)))
6796 ;; found an assignment operator (not at eol)
6797 (setq foundp (not (looking-at "\\s-*$"))))))
6799 ;; there's no assignment operator on the line
6801 ;; calculate indentation column after assign and ws, unless
6802 ;; our line contains an assignment operator
6806 (skip-chars-forward " \t")
6808 (- (current-column) assignp curcol))
6811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6812 ;; Progress reporting
6814 (defvar vhdl-progress-info nil
6815 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6817 (defun vhdl-update-progress-info (string pos)
6818 "Update progress information."
6819 (when (and vhdl-progress-info (not noninteractive)
6820 (< vhdl-progress-interval
6821 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6822 (message (concat string "... (%2d%s)")
6823 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6824 (- (aref vhdl-progress-info 1)
6825 (aref vhdl-progress-info 0))) "%")
6826 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6829 ;; Indentation commands
6831 (defun vhdl-electric-tab (&optional prefix-arg)
6832 "If preceeding character is part of a word or a paren then hippie-expand,
6833 else if right of non whitespace on line then insert tab,
6834 else if last command was a tab or return then dedent one step or if a comment
6835 toggle between normal indent and inline comment indent,
6836 else indent `correctly'."
6838 (vhdl-prepare-search-2
6841 ((= (char-syntax (preceding-char)) ?w)
6842 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6844 (hippie-expand-only-buffers
6845 (or (and (boundp 'hippie-expand-only-buffers)
6846 hippie-expand-only-buffers)
6848 (vhdl-expand-abbrev prefix-arg)))
6849 ;; expand parenthesis
6850 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6851 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6853 (vhdl-expand-paren prefix-arg)))
6855 ((> (current-column) (current-indentation))
6857 ;; toggle comment indent
6858 ((and (looking-at "--")
6859 (or (eq last-command 'vhdl-electric-tab)
6860 (eq last-command 'vhdl-electric-return)))
6861 (cond ((= (current-indentation) 0) ; no indent
6863 (indent-according-to-mode))
6864 ((< (current-indentation) comment-column) ; normal indent
6865 (indent-to comment-column)
6866 (indent-according-to-mode))
6867 (t ; inline comment indent
6870 ((and (>= (current-indentation) vhdl-basic-offset)
6871 (or (eq last-command 'vhdl-electric-tab)
6872 (eq last-command 'vhdl-electric-return)))
6873 (backward-delete-char-untabify vhdl-basic-offset nil))
6875 (t (indent-according-to-mode)))
6876 (setq this-command 'vhdl-electric-tab)))
6878 (defun vhdl-electric-return ()
6879 "newline-and-indent or indent-new-comment-line if in comment and preceding
6880 character is a space."
6882 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
6883 (indent-new-comment-line)
6884 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
6885 (vhdl-fix-case-word -1))
6886 (newline-and-indent)))
6888 (defun vhdl-indent-line ()
6889 "Indent the current line as VHDL code. Returns the amount of
6890 indentation change."
6892 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
6893 (pos (- (point-max) (point)))
6896 ;; indent syntax-based
6897 (if (and (eq (caar syntax) 'comment)
6898 (>= (vhdl-get-offset (car syntax)) comment-column))
6899 ;; special case: comments at or right of comment-column
6900 (vhdl-get-offset (car syntax))
6901 (apply '+ (mapcar 'vhdl-get-offset syntax)))
6902 ;; indent like previous nonblank line
6903 (save-excursion (beginning-of-line)
6904 (re-search-backward "^[^\n]" nil t)
6905 (current-indentation))))
6906 (shift-amt (- indent (current-indentation))))
6907 (and vhdl-echo-syntactic-information-p
6908 (message "syntax: %s, indent= %d" syntax indent))
6909 (unless (zerop shift-amt)
6910 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
6913 (if (< (point) (vhdl-point 'boi))
6914 (back-to-indentation)
6915 ;; If initial point was within line's indentation, position after
6916 ;; the indentation. Else stay at same point in text.
6917 (when (> (- (point-max) pos) (point))
6918 (goto-char (- (point-max) pos))))
6919 (run-hooks 'vhdl-special-indent-hook)
6920 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
6923 (defun vhdl-indent-region (beg end column)
6924 "Indent region as VHDL code.
6925 Adds progress reporting to `indent-region'."
6926 (interactive "r\nP")
6927 (when vhdl-progress-interval
6928 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
6929 (count-lines (point-min) end) 0)))
6930 (indent-region beg end column)
6931 (when vhdl-progress-interval (message "Indenting...done"))
6932 (setq vhdl-progress-info nil))
6934 (defun vhdl-indent-buffer ()
6935 "Indent whole buffer as VHDL code.
6936 Calls `indent-region' for whole buffer and adds progress reporting."
6938 (vhdl-indent-region (point-min) (point-max) nil))
6940 (defun vhdl-indent-group ()
6941 "Indent group of lines between empty lines."
6943 (let ((beg (save-excursion
6944 (if (re-search-backward vhdl-align-group-separate nil t)
6946 (point-min-marker))))
6947 (end (save-excursion
6948 (if (re-search-forward vhdl-align-group-separate nil t)
6950 (point-max-marker)))))
6951 (vhdl-indent-region beg end nil)))
6953 (defun vhdl-indent-sexp (&optional endpos)
6954 "Indent each line of the list starting just after point.
6955 If optional arg ENDPOS is given, indent each line, stopping when
6956 ENDPOS is encountered."
6960 (end (progn (vhdl-forward-sexp nil endpos) (point))))
6961 (indent-region beg end nil))))
6963 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6964 ;; Miscellaneous commands
6966 (defun vhdl-show-syntactic-information ()
6967 "Show syntactic information for current line."
6969 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
6970 (vhdl-keep-region-active))
6972 ;; Verification and regression functions:
6974 (defun vhdl-regress-line (&optional arg)
6975 "Check syntactic information for current line."
6977 (let ((expected (save-excursion
6979 (when (search-backward " -- ((" (vhdl-point 'bol) t)
6981 (read (current-buffer)))))
6982 (actual (vhdl-get-syntactic-context))
6984 ;; remove the library unit symbols
6988 (if (memq (car elt) '(entity configuration package
6989 package-body architecture))
6991 (setq expurgated (append expurgated (list elt))))))
6993 (if (and (not arg) expected (listp expected))
6994 (if (not (equal expected expurgated))
6995 (error "ERROR: Should be: %s, is: %s" expected expurgated))
6998 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7000 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7003 (insert (format "%s" expurgated))))))
7004 (vhdl-keep-region-active))
7007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7008 ;;; Alignment, whitespace fixup, beautifying
7009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7011 (defconst vhdl-align-alist
7013 ;; after some keywords
7014 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7015 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7017 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7018 ;; after direction specifications
7019 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7020 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7021 ;; before "==", ":=", "=>", and "<="
7022 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7023 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7024 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7025 ;; before some keywords
7026 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7027 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7028 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7029 ;; before "=>" since "when/else ... =>" can occur
7030 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7032 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7033 It is searched in order. If REGEXP is found anywhere in the first
7034 line of a region to be aligned, ALIGN-PATTERN will be used for that
7035 region. ALIGN-PATTERN must include the whitespace to be expanded or
7036 contracted. It may also provide regexps for the text surrounding the
7037 whitespace. SUBEXP specifies which sub-expression of
7038 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7043 (defvar vhdl-align-try-all-clauses t
7044 "If REGEXP is not found on the first line of the region that clause
7045 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7047 (defun vhdl-do-group (function &optional spacing)
7048 "Apply FUNCTION on group of lines between empty lines."
7050 ;; search for group beginning
7051 ((beg (save-excursion
7052 (if (re-search-backward vhdl-align-group-separate nil t)
7053 (progn (beginning-of-line 2) (back-to-indentation) (point))
7055 ;; search for group end
7056 (end (save-excursion
7057 (if (re-search-forward vhdl-align-group-separate nil t)
7058 (progn (beginning-of-line) (point))
7061 (funcall function beg end spacing)))
7063 (defun vhdl-do-list (function &optional spacing)
7064 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7068 ;; search for beginning of balanced group of parentheses
7069 (setq beg (vhdl-re-search-backward "[()]" nil t))
7070 (while (looking-at ")")
7071 (forward-char) (backward-sexp)
7072 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7073 ;; search for end of balanced group of parentheses
7077 (goto-char (1+ beg))
7078 (skip-chars-forward " \t\n")
7079 (setq beg (point))))
7082 (funcall function beg end spacing)
7083 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7085 (defun vhdl-do-same-indent (function &optional spacing)
7086 "Apply FUNCTION to block of lines with same indent."
7087 (let ((indent (current-indentation))
7089 ;; search for first line with same indent
7091 (while (and (not (bobp))
7092 (or (looking-at "^\\s-*\\(--.*\\)?$")
7093 (= (current-indentation) indent)))
7094 (unless (looking-at "^\\s-*$")
7095 (back-to-indentation) (setq beg (point)))
7096 (beginning-of-line -0)))
7097 ;; search for last line with same indent
7099 (while (and (not (eobp))
7100 (or (looking-at "^\\s-*\\(--.*\\)?$")
7101 (= (current-indentation) indent)))
7102 (if (looking-at "^\\s-*$")
7103 (beginning-of-line 2)
7104 (beginning-of-line 2)
7105 (setq end (point)))))
7107 (funcall function beg end spacing)))
7109 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7110 "Attempt to align a range of lines based on the content of the
7111 lines. The definition of `alignment-list' determines the matching
7112 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7113 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7114 indentation is done before aligning."
7115 (interactive "r\np")
7116 (setq alignment-list (or alignment-list vhdl-align-alist))
7117 (setq spacing (or spacing 1))
7121 (setq end (point-marker))
7123 (setq bol (setq begin (progn (beginning-of-line) (point))))
7124 ; (untabify bol end)
7126 (indent-region bol end nil))))
7127 (let ((copy (copy-alist alignment-list)))
7128 (vhdl-prepare-search-2
7133 (eol (save-excursion (progn (end-of-line) (point)))))
7134 (setq element (nth 0 copy))
7135 (when (and (or (and (listp (car element))
7136 (memq major-mode (car element)))
7137 (eq major-mode (car element)))
7138 (or vhdl-align-try-all-clauses
7139 (re-search-forward (car (cdr element)) eol t)))
7140 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7141 (car (cdr (cdr (cdr element)))) spacing))
7142 (setq copy (cdr copy))))))))
7144 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7145 "Align a range of lines from BEGIN to END. The regular expression
7146 MATCH must match exactly one fields: the whitespace to be
7147 contracted/expanded. The alignment column will equal the
7148 rightmost column of the widest whitespace block. SPACING is
7149 the amount of extra spaces to add to the calculated maximum required.
7150 SPACING defaults to 1 so that at least one space is inserted after
7151 the token in MATCH."
7152 (setq spacing (or spacing 1))
7153 (setq substr (or substr 1))
7155 (let (distance (max 0) (lines 0) bol eol width)
7156 ;; Determine the greatest whitespace distance to the alignment
7159 (setq eol (progn (end-of-line) (point))
7160 bol (setq begin (progn (beginning-of-line) (point))))
7163 (when (and (re-search-forward match eol t)
7164 (not (vhdl-in-literal)))
7165 (setq distance (- (match-beginning substr) bol))
7166 (when (> distance max)
7167 (setq max distance))))
7170 eol (save-excursion (end-of-line) (point)))
7171 (setq lines (1+ lines)))
7172 ;; Now insert enough maxs to push each assignment operator to
7173 ;; the same column. We need to use 'lines' as a counter, since
7174 ;; the location of the mark may change
7175 (goto-char (setq bol begin))
7176 (setq eol (save-excursion (end-of-line) (point)))
7178 (when (and (re-search-forward match eol t)
7179 (not (vhdl-in-literal)))
7180 (setq width (- (match-end substr) (match-beginning substr)))
7181 (setq distance (- (match-beginning substr) bol))
7182 (goto-char (match-beginning substr))
7184 (insert-char ? (+ (- max distance) spacing)))
7188 eol (save-excursion (end-of-line) (point)))
7189 (setq lines (1- lines))))))
7191 (defun vhdl-align-region-groups (beg end &optional spacing
7192 no-message no-comments)
7193 "Align region, treat groups of lines separately."
7194 (interactive "r\nP")
7199 (setq orig (point-marker))
7202 (setq end (point-marker))
7205 (when vhdl-progress-interval
7206 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7207 (count-lines (point-min) end) 0))))
7208 (vhdl-fixup-whitespace-region beg end t)
7210 (if (not vhdl-align-groups)
7211 ;; align entire region
7212 (progn (vhdl-align-region-1 beg end spacing)
7214 (vhdl-align-inline-comment-region-1 beg end)))
7216 (while (and (< beg end)
7217 (re-search-forward vhdl-align-group-separate end t))
7218 (setq pos (point-marker))
7219 (vhdl-align-region-1 beg pos spacing)
7220 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7221 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7226 (vhdl-align-region-1 beg end spacing)
7227 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7228 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7229 (when vhdl-indent-tabs-mode
7232 (when vhdl-progress-interval (message "Aligning...done"))
7233 (setq vhdl-progress-info nil)))))
7235 (defun vhdl-align-region (beg end &optional spacing)
7236 "Align region, treat blocks with same indent and argument lists separately."
7237 (interactive "r\nP")
7238 (if (not vhdl-align-same-indent)
7239 ;; align entire region
7240 (vhdl-align-region-groups beg end spacing)
7241 ;; align blocks with same indent and argument lists
7245 (when vhdl-progress-interval
7246 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7247 (count-lines (point-min) end) 0)))
7249 (setq end (point-marker))
7251 (while (< (point) end)
7252 ;; is argument list opening?
7253 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7254 (point) (vhdl-point 'eol)))))
7255 ;; determine region for argument list
7256 (progn (goto-char cur-beg)
7258 (setq cur-end (point))
7259 (beginning-of-line 2))
7260 ;; determine region with same indent
7261 (setq indent (current-indentation))
7262 (setq cur-beg (point))
7263 (setq cur-end (vhdl-point 'bonl))
7264 (beginning-of-line 2)
7265 (while (and (< (point) end)
7266 (or (looking-at "^\\s-*\\(--.*\\)?$")
7267 (= (current-indentation) indent))
7269 (nth 0 (parse-partial-sexp
7270 (point) (vhdl-point 'eol)))) 0))
7271 (unless (looking-at "^\\s-*$")
7272 (setq cur-end (vhdl-point 'bonl)))
7273 (beginning-of-line 2)))
7275 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7276 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7277 (when vhdl-progress-interval (message "Aligning...done"))
7278 (setq vhdl-progress-info nil)))))
7280 (defun vhdl-align-group (&optional spacing)
7281 "Align group of lines between empty lines."
7283 (vhdl-do-group 'vhdl-align-region spacing))
7285 (defun vhdl-align-list (&optional spacing)
7286 "Align the lines of a list surrounded by a balanced group of parentheses."
7288 (vhdl-do-list 'vhdl-align-region-groups spacing))
7290 (defun vhdl-align-same-indent (&optional spacing)
7291 "Align block of lines with same indent."
7293 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7295 (defun vhdl-align-declarations (&optional spacing)
7296 "Align the lines within the declarative part of a design unit."
7299 (vhdl-prepare-search-2
7301 ;; search for declarative part
7302 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7303 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7305 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7306 (setq end (point)))))
7308 (vhdl-align-region-groups beg end spacing)
7309 (error "ERROR: Not within the declarative part of a design unit"))))
7311 (defun vhdl-align-buffer ()
7314 (vhdl-align-region (point-min) (point-max)))
7316 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7317 ;; Align inline comments
7319 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7320 "Align inline comments in region."
7322 (let ((start-max comment-column)
7324 comment-list start-list tmp-list start length
7325 cur-start prev-start no-code)
7326 (setq spacing (or spacing 2))
7327 (vhdl-prepare-search-2
7329 ;; search for comment start positions and lengths
7330 (while (< (point) end)
7331 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7332 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7333 (not (save-excursion (goto-char (match-beginning 2))
7334 (vhdl-in-literal))))
7335 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7336 (setq length (- (match-end 2) (match-beginning 2)))
7337 (setq start-max (max start start-max))
7338 (setq length-max (max length length-max))
7339 (setq comment-list (cons (cons start length) comment-list)))
7340 (beginning-of-line 2))
7342 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7343 ;; reduce start positions
7344 (setq start-list (list (caar comment-list)))
7345 (setq comment-list (cdr comment-list))
7347 (unless (or (= (caar comment-list) (car start-list))
7348 (<= (+ (car start-list) (cdar comment-list))
7349 end-comment-column))
7350 (setq start-list (cons (caar comment-list) start-list)))
7351 (setq comment-list (cdr comment-list)))
7352 ;; align lines as nicely as possible
7354 (while (< (point) end)
7355 (setq cur-start nil)
7356 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7357 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7358 (not (save-excursion
7359 (goto-char (match-beginning 3))
7360 (vhdl-in-literal))))
7361 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7362 (>= (- (match-end 2) (match-beginning 2))
7364 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7365 (setq length (- (match-end 3) (match-beginning 3)))
7366 (setq no-code (= (match-beginning 1) (match-end 1)))
7367 ;; insert minimum whitespace
7368 (goto-char (match-end 2))
7369 (delete-region (match-beginning 2) (match-end 2))
7370 (insert-char ?\ spacing)
7371 (setq tmp-list start-list)
7372 ;; insert additional whitespace to align
7375 ;; align comment-only line to inline comment of previous line
7376 ((and no-code prev-start
7377 (<= length (- end-comment-column prev-start)))
7379 ;; align all comments at `start-max' if this is possible
7380 ((<= (+ start-max length-max) end-comment-column)
7382 ;; align at `comment-column' if possible
7383 ((and (<= start comment-column)
7384 (<= length (- end-comment-column comment-column)))
7386 ;; align at left-most possible start position otherwise
7388 (while (and tmp-list (< (car tmp-list) start))
7389 (setq tmp-list (cdr tmp-list)))
7391 (indent-to cur-start))
7392 (setq prev-start cur-start)
7393 (beginning-of-line 2))))))
7395 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7396 "Align inline comments within a region. Groups of code lines separated by
7397 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7398 (interactive "r\nP")
7403 (setq orig (point-marker))
7406 (setq end (point-marker))
7408 (unless no-message (message "Aligning inline comments..."))
7410 (if (not vhdl-align-groups)
7411 ;; align entire region
7412 (vhdl-align-inline-comment-region-1 beg end spacing)
7414 (while (and (< beg end)
7415 (re-search-forward vhdl-align-group-separate end t))
7416 (setq pos (point-marker))
7417 (vhdl-align-inline-comment-region-1 beg pos spacing)
7422 (vhdl-align-inline-comment-region-1 beg end spacing)))
7423 (when vhdl-indent-tabs-mode
7425 (unless no-message (message "Aligning inline comments...done")))))
7427 (defun vhdl-align-inline-comment-group (&optional spacing)
7428 "Align inline comments within a group of lines between empty lines."
7431 (let ((start (point))
7433 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7434 (point-marker) (point-max)))
7436 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7437 (point) (point-min)))
7439 (message "Aligning inline comments...")
7440 (vhdl-align-inline-comment-region-1 beg end)
7441 (when vhdl-indent-tabs-mode
7443 (message "Aligning inline comments...done"))))
7445 (defun vhdl-align-inline-comment-buffer ()
7446 "Align inline comments within buffer. Groups of code lines separated by
7447 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7449 (vhdl-align-inline-comment-region (point-min) (point-max)))
7451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7454 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7455 "Fixup whitespace in region. Surround operator symbols by one space,
7456 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7457 end of line, do nothing in comments and strings."
7459 (unless no-message (message "Fixing up whitespace..."))
7462 (setq end (point-marker))
7463 ;; have no space before and one space after `,' and ';'
7465 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7466 (if (match-string 1)
7467 (goto-char (match-end 1))
7468 (replace-match "\\3 " nil nil nil 3)))
7469 ;; have no space after `('
7471 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\((\\)\\s-+" end t)
7472 (if (match-string 1)
7473 (goto-char (match-end 1))
7474 (replace-match "\\2")))
7475 ;; have no space before `)'
7477 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7478 (if (match-string 1)
7479 (goto-char (match-end 1))
7480 (replace-match "\\2")))
7481 ;; surround operator symbols by one space
7483 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7484 (if (match-string 1)
7485 (goto-char (match-end 1))
7487 (goto-char (match-beginning 4))
7488 (unless (eq (preceding-char) ?\ )
7490 (goto-char (match-end 4))
7491 (unless (eq (following-char) ?\ )
7493 (goto-char (match-end 4))))
7494 ;; eliminate multiple spaces and spaces at end of line
7496 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7497 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7498 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7499 (progn (replace-match "" nil nil) t))
7500 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7501 (progn (replace-match ";" nil nil) t))
7502 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7503 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7504 (progn (replace-match " " nil nil) t))
7505 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7506 (progn (replace-match " " nil nil) t))
7507 (re-search-forward "[^ \t-]+" end t))))
7508 (unless no-message (message "Fixing up whitespace...done")))
7510 (defun vhdl-fixup-whitespace-buffer ()
7511 "Fixup whitespace in buffer. Surround operator symbols by one space,
7512 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7513 end of line, do nothing in comments."
7515 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7517 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7520 (defun vhdl-beautify-region (beg end)
7521 "Beautify region by applying indentation, whitespace fixup, alignment, and
7522 case fixing to a region. Calls functions `vhdl-indent-buffer',
7523 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7524 `vhdl-fix-case-buffer'."
7526 (setq end (save-excursion (goto-char end) (point-marker)))
7527 (vhdl-indent-region beg end nil)
7528 (let ((vhdl-align-groups t))
7529 (vhdl-align-region beg end))
7530 (vhdl-fix-case-region beg end))
7532 (defun vhdl-beautify-buffer ()
7533 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7534 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7537 (vhdl-beautify-region (point-min) (point-max))
7538 (when noninteractive (save-buffer)))
7540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7543 (defun vhdl-fill-region (beg end &optional arg)
7544 "Fill lines for a region of code."
7545 (interactive "r\np")
7548 (let ((margin (if arg (current-indentation) (current-column))))
7550 (setq end (point-marker))
7551 ;; remove inline comments, newlines and whitespace
7552 (vhdl-comment-kill-region beg end)
7553 (vhdl-comment-kill-inline-region beg end)
7554 (subst-char-in-region beg (1- end) ?\n ?\ )
7555 (vhdl-fixup-whitespace-region beg end)
7556 ;; wrap and end-comment-column
7558 (while (re-search-forward "\\s-" end t)
7559 (when(> (current-column) vhdl-end-comment-column)
7561 (when (re-search-backward "\\s-" beg t)
7562 (replace-match "\n")
7563 (indent-to margin)))))))
7565 (defun vhdl-fill-group ()
7566 "Fill group of lines between empty lines."
7568 (vhdl-do-group 'vhdl-fill-region))
7570 (defun vhdl-fill-list ()
7571 "Fill the lines of a list surrounded by a balanced group of parentheses."
7573 (vhdl-do-list 'vhdl-fill-region))
7575 (defun vhdl-fill-same-indent ()
7576 "Fill the lines of block of lines with same indent."
7578 (vhdl-do-same-indent 'vhdl-fill-region))
7581 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7582 ;;; Code updating/fixing
7583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7586 ;; Sensitivity list update
7589 ;; - no sensitivity list is generated for processes with wait statements
7590 ;; - otherwise, do the following:
7591 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7592 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7593 ;; manually entered global signals)
7594 ;; 3. signals from 1. and 2. form the list of visible signals
7595 ;; 4. search for if/elsif conditions containing an event (sequential code)
7596 ;; 5. scan for strings that are within syntactical regions where signals are
7597 ;; read but not within sequential code, and that correspond to visible
7599 ;; 6. replace sensitivity list by list of signals from 5.
7601 (defun vhdl-update-sensitivity-list-process ()
7602 "Update sensitivity list of current process."
7605 (vhdl-prepare-search-2
7607 ;; look whether in process
7608 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7609 (equal (upcase (match-string 2)) "PROCESS")
7610 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7611 (error "ERROR: Not within a process")
7612 (message "Updating sensitivity list...")
7613 (vhdl-update-sensitivity-list)
7614 (message "Updating sensitivity list...done")))))
7616 (defun vhdl-update-sensitivity-list-buffer ()
7617 "Update sensitivity list of all processes in current buffer."
7620 (vhdl-prepare-search-2
7621 (goto-char (point-min))
7622 (message "Updating sensitivity lists...")
7623 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7624 (goto-char (match-beginning 0))
7625 (condition-case nil (vhdl-update-sensitivity-list) (error)))
7626 (message "Updating sensitivity lists...done"))))
7628 (defun vhdl-update-sensitivity-list ()
7629 "Update sensitivity list."
7630 (let ((proc-beg (point))
7631 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7632 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7635 ;; search for wait statement (no sensitivity list allowed)
7636 ((progn (goto-char proc-mid)
7637 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7638 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7639 ;; combinational process (update sensitivity list)
7642 ;; scan for visible signals
7643 ((visible-list (vhdl-get-visible-signals))
7644 ;; define syntactic regions where signals are read
7646 '(;; right-hand side of signal/variable assignment
7647 ;; (special case: "<=" is relational operator in a condition)
7648 ((re-search-forward "[<:]=" proc-end t)
7649 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7651 ((re-search-forward "^\\s-*if\\>" proc-end t)
7652 (re-search-forward "\\<then\\>" proc-end t))
7654 ((re-search-forward "\\<elsif\\>" proc-end t)
7655 (re-search-forward "\\<then\\>" proc-end t))
7656 ;; while loop condition
7657 ((re-search-forward "^\\s-*while\\>" proc-end t)
7658 (re-search-forward "\\<loop\\>" proc-end t))
7659 ;; exit/next condition
7660 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7661 (re-search-forward ";" proc-end t))
7663 ((re-search-forward "\\<assert\\>" proc-end t)
7664 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7666 ((re-search-forward "^\\s-*case\\>" proc-end t)
7667 (re-search-forward "\\<is\\>" proc-end t))
7668 ;; parameter list of procedure call
7669 ((re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7670 (progn (backward-char) (forward-sexp) (point)))))
7671 name read-list sens-list signal-list
7672 sens-beg sens-end beg end margin)
7673 ;; scan for signals in old sensitivity list
7674 (goto-char proc-beg)
7675 (re-search-forward "\\<process\\>" proc-mid t)
7676 (if (not (looking-at "[ \t\n]*("))
7677 (setq sens-beg (point))
7678 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7679 (goto-char (match-end 1))
7681 (setq sens-end (1- (point)))
7682 (goto-char sens-beg)
7683 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7685 (cons (downcase (match-string 0)) sens-list))
7686 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7687 (setq signal-list (append visible-list sens-list))
7688 ;; search for sequential parts
7689 (goto-char proc-mid)
7690 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7691 (setq end (re-search-forward "\\<then\\>" proc-end t))
7692 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7696 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7697 (beginning-of-line)))
7698 ;; scan for signals read in process
7699 (while scan-regions-list
7700 (goto-char proc-mid)
7701 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7702 (setq end (eval (nth 1 (car scan-regions-list)))))
7704 (unless (or (vhdl-in-literal)
7705 (and seq-region-list
7706 (let ((tmp-list seq-region-list))
7707 (while (and tmp-list
7708 (< (point) (caar tmp-list)))
7709 (setq tmp-list (cdr tmp-list)))
7710 (and tmp-list (< (point) (cdar tmp-list))))))
7711 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>" end t)
7712 (setq name (match-string 1))
7713 (when (member (downcase name) signal-list)
7714 (add-to-list 'read-list name)))))
7715 (setq scan-regions-list (cdr scan-regions-list)))
7716 ;; update sensitivity list
7717 (goto-char sens-beg)
7719 (delete-region sens-beg sens-end)
7721 (insert " ()") (backward-char)))
7722 (setq read-list (sort read-list 'string<))
7724 (setq margin (current-column))
7725 (insert (car read-list))
7726 (setq read-list (cdr read-list))
7729 (if (<= (+ (current-column) (length (car read-list)) 2)
7732 (insert "\n") (indent-to margin))
7733 (insert (car read-list))
7734 (setq read-list (cdr read-list)))))))))
7736 (defun vhdl-get-visible-signals ()
7737 "Get all signals visible in the current block."
7739 (let (beg end signal-list entity-name file-name)
7740 ;; search for signals declared in surrounding block declarative parts
7742 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7744 (goto-char (match-end 2))
7745 (vhdl-backward-sexp)
7746 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7748 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7749 ;; scan for all declared signal names
7751 (while (re-search-forward "^\\s-*signal\\>" end t)
7752 (while (and (not (looking-at "[ \t\n]*:"))
7753 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7755 (cons (downcase (match-string 1)) signal-list))))
7757 ;; search for signals declared in architecture declarative part
7758 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7759 (not (equal "END" (upcase (match-string 1))))
7760 (setq entity-name (match-string 2))
7761 (setq end (re-search-forward "^begin\\>" nil t))))
7762 (error "ERROR: No architecture declarative part found")
7763 ;; scan for all declared signal names
7765 (while (re-search-forward "^\\s-*signal\\>" end t)
7766 (while (and (not (looking-at "[ \t\n]*:"))
7767 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7769 (cons (downcase (match-string 1)) signal-list)))))
7770 ;; search for signals declared in entity port clause
7771 (goto-char (point-min))
7772 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7774 (concat (vhdl-replace-string vhdl-entity-file-name entity-name)
7775 "." (file-name-extension (buffer-file-name)))))
7778 (vhdl-prepare-search-2
7779 (goto-char (point-min))
7780 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7781 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7782 (when (setq beg (re-search-forward
7783 "^\\s-*port[ \t\n]*("
7785 (re-search-forward "^end\\>" nil t)) t))
7786 (setq end (save-excursion
7787 (backward-char) (forward-sexp) (point)))
7788 (vhdl-forward-syntactic-ws)
7789 (while (< (point) end)
7790 (while (and (not (looking-at "[ \t\n]*:"))
7791 (re-search-forward "[ \t\n,]*\\(\\w+\\)" end t))
7793 (cons (downcase (match-string 1)) signal-list)))
7794 (re-search-forward ";" end 1)
7795 (vhdl-forward-syntactic-ws))))))
7798 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7799 ;; Generic/port clause fixing
7801 (defun vhdl-fix-clause ()
7802 "Fix closing parenthesis within generic/port clause."
7805 (vhdl-prepare-search-2
7808 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7809 (error "ERROR: Not within a generic/port clause")
7810 ;; search for end of clause
7811 (goto-char (match-end 0))
7812 (setq beg (1- (point)))
7813 (vhdl-forward-syntactic-ws)
7814 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7815 (goto-char (1- (match-end 0)))
7816 (setq end (point-marker))
7818 (vhdl-forward-syntactic-ws))
7820 (when (> pos (save-excursion (end-of-line) (point)))
7821 (error "ERROR: Not within a generic/port clause"))
7822 ;; delete closing parenthesis on separate line (not supported style)
7823 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7825 (vhdl-backward-syntactic-ws)
7826 (setq end (point-marker))
7828 ;; delete superfluous parentheses
7829 (while (progn (goto-char beg)
7830 (condition-case () (forward-sexp)
7831 (error (goto-char (point-max))))
7833 (delete-backward-char 1))
7834 ;; add closing parenthesis
7835 (when (> (point) end)
7839 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7842 (defun vhdl-remove-trailing-spaces ()
7843 "Remove trailing spaces in the whole buffer."
7847 (goto-char (point-min))
7848 (while (re-search-forward "[ \t]+$" (point-max) t)
7849 (unless (vhdl-in-literal)
7850 (replace-match "" nil nil))))))
7853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7857 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
7858 "Syntax of prompt inserted by template generators.")
7860 (defvar vhdl-template-invoked-by-hook nil
7861 "Indicates whether a template has been invoked by a hook or by key or menu.
7862 Used for undoing after template abortion.")
7864 ;; correct different behavior of function `unread-command-events' in XEmacs
7865 (defun vhdl-character-to-event (arg))
7866 (defalias 'vhdl-character-to-event
7867 (if (fboundp 'character-to-event) 'character-to-event 'identity))
7869 (defun vhdl-work-library ()
7870 "Return the working library name of the current project or \"work\" if no
7871 project is defined."
7872 (vhdl-resolve-env-variable
7873 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
7875 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7876 ;; Enabling/disabling
7878 (defun vhdl-mode-line-update ()
7879 "Update the modeline string for VHDL major mode."
7880 (setq mode-name (concat "VHDL"
7881 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
7882 (and vhdl-electric-mode "e")
7883 (and vhdl-stutter-mode "s")))
7884 (force-mode-line-update t))
7886 (defun vhdl-electric-mode (arg)
7887 "Toggle VHDL electric mode.
7888 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7890 (setq vhdl-electric-mode
7891 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
7892 ((> arg 0) t) (t nil)))
7893 (vhdl-mode-line-update))
7895 (defun vhdl-stutter-mode (arg)
7896 "Toggle VHDL stuttering mode.
7897 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7899 (setq vhdl-stutter-mode
7900 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
7901 ((> arg 0) t) (t nil)))
7902 (vhdl-mode-line-update))
7904 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7907 (defun vhdl-electric-dash (count)
7908 "-- starts a comment, --- draws a horizontal line,
7909 ---- starts a display comment"
7911 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
7913 ((and abbrev-start-location (= abbrev-start-location (point)))
7914 (setq abbrev-start-location nil)
7915 (goto-char last-abbrev-location)
7916 (beginning-of-line nil)
7917 (vhdl-comment-display))
7918 ((/= (preceding-char) ?-) ; standard dash (minus)
7919 (self-insert-command count))
7920 (t (self-insert-command count)
7921 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
7922 (let ((next-input (read-char)))
7923 (if (= next-input ?-) ; triple dash
7925 (vhdl-comment-display-line)
7927 "Enter '-' for display comment, else continue coding")
7928 (let ((next-input (read-char)))
7929 (if (= next-input ?-) ; four dashes
7930 (vhdl-comment-display t)
7931 (setq unread-command-events ; pushback the char
7932 (list (vhdl-character-to-event next-input))))))
7933 (setq unread-command-events ; pushback the char
7934 (list (vhdl-character-to-event next-input)))
7935 (vhdl-comment-insert)))))
7936 (self-insert-command count)))
7938 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
7940 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7941 (if (= (preceding-char) ?\()
7942 (progn (delete-char -1) (insert-char ?\[ 1))
7943 (insert-char ?\( 1))
7944 (self-insert-command count)))
7946 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
7948 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7950 (if (= (preceding-char) ?\))
7951 (progn (delete-char -1) (insert-char ?\] 1))
7952 (insert-char ?\) 1))
7953 (blink-matching-open))
7954 (self-insert-command count)))
7956 (defun vhdl-electric-quote (count) "'' --> \""
7958 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7959 (if (= (preceding-char) last-input-char)
7960 (progn (delete-backward-char 1) (insert-char ?\" 1))
7961 (insert-char ?\' 1))
7962 (self-insert-command count)))
7964 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
7966 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7967 (cond ((= (preceding-char) last-input-char)
7968 (progn (delete-char -1)
7969 (unless (eq (preceding-char) ? ) (insert " "))
7971 (setq this-command 'vhdl-electric-colon)))
7973 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
7974 (progn (delete-char -1) (insert "= ")))
7975 (t (insert-char ?\; 1)))
7976 (self-insert-command count)))
7978 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
7980 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7981 (cond ((= (preceding-char) last-input-char)
7982 (progn (delete-char -1)
7983 (unless (eq (preceding-char) ? ) (insert " "))
7985 (t (insert-char ?\, 1)))
7986 (self-insert-command count)))
7988 (defun vhdl-electric-period (count) "'..' --> ' => '"
7990 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7991 (cond ((= (preceding-char) last-input-char)
7992 (progn (delete-char -1)
7993 (unless (eq (preceding-char) ? ) (insert " "))
7995 (t (insert-char ?\. 1)))
7996 (self-insert-command count)))
7998 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8000 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8001 (cond ((= (preceding-char) last-input-char)
8002 (progn (delete-char -1)
8003 (unless (eq (preceding-char) ? ) (insert " "))
8005 (t (insert-char ?\= 1)))
8006 (self-insert-command count)))
8008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8011 (defun vhdl-template-paired-parens ()
8012 "Insert a pair of round parentheses, placing point between them."
8017 (defun vhdl-template-alias ()
8018 "Insert alias declaration."
8020 (let ((start (point)))
8021 (vhdl-insert-keyword "ALIAS ")
8022 (when (vhdl-template-field "name" nil t start (point))
8024 (unless (vhdl-template-field
8025 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8027 (delete-backward-char 3))
8028 (vhdl-insert-keyword " IS ")
8029 (vhdl-template-field "name" ";")
8030 (vhdl-comment-insert-inline))))
8032 (defun vhdl-template-architecture ()
8033 "Insert architecture."
8035 (let ((margin (current-indentation))
8038 (vhdl-insert-keyword "ARCHITECTURE ")
8039 (when (setq arch-name
8040 (vhdl-template-field "name" nil t start (point)))
8041 (vhdl-insert-keyword " OF ")
8043 (vhdl-prepare-search-1
8044 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8045 (insert (match-string 1))
8046 (vhdl-template-field "entity name"))
8047 (vhdl-insert-keyword " IS\n")
8048 (vhdl-template-begin-end
8049 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8050 (memq vhdl-insert-empty-lines '(unit all))))))
8052 (defun vhdl-template-array (kind &optional secondary)
8053 "Insert array type definition."
8055 (let ((start (point)))
8056 (vhdl-insert-keyword "ARRAY (")
8057 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8059 (vhdl-insert-keyword ") OF ")
8060 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8061 (vhdl-insert-keyword ";"))))
8063 (defun vhdl-template-assert ()
8064 "Insert an assertion statement."
8066 (let ((start (point)))
8067 (vhdl-insert-keyword "ASSERT ")
8068 (when vhdl-conditions-in-parenthesis (insert "("))
8069 (when (vhdl-template-field "condition (negated)" nil t start (point))
8070 (when vhdl-conditions-in-parenthesis (insert ")"))
8071 (setq start (point))
8072 (vhdl-insert-keyword " REPORT ")
8073 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8074 (delete-region start (point)))
8075 (setq start (point))
8076 (vhdl-insert-keyword " SEVERITY ")
8077 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8078 (delete-region start (point)))
8081 (defun vhdl-template-attribute ()
8082 "Insert an attribute declaration or specification."
8084 (if (eq (vhdl-decision-query
8085 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8086 (vhdl-template-attribute-spec)
8087 (vhdl-template-attribute-decl)))
8089 (defun vhdl-template-attribute-decl ()
8090 "Insert an attribute declaration."
8092 (let ((start (point)))
8093 (vhdl-insert-keyword "ATTRIBUTE ")
8094 (when (vhdl-template-field "name" " : " t start (point))
8095 (vhdl-template-field "type" ";")
8096 (vhdl-comment-insert-inline))))
8098 (defun vhdl-template-attribute-spec ()
8099 "Insert an attribute specification."
8101 (let ((start (point)))
8102 (vhdl-insert-keyword "ATTRIBUTE ")
8103 (when (vhdl-template-field "name" nil t start (point))
8104 (vhdl-insert-keyword " OF ")
8105 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8106 (vhdl-template-field "entity class")
8107 (vhdl-insert-keyword " IS ")
8108 (vhdl-template-field "expression" ";"))))
8110 (defun vhdl-template-block ()
8113 (let ((margin (current-indentation))
8116 (vhdl-insert-keyword ": BLOCK ")
8118 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8122 (if (vhdl-template-field "[guard expression]" nil t)
8125 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8127 (vhdl-template-begin-end "BLOCK" label margin)
8128 (vhdl-comment-block))))
8130 (defun vhdl-template-block-configuration ()
8131 "Insert a block configuration statement."
8133 (let ((margin (current-indentation))
8135 (vhdl-insert-keyword "FOR ")
8136 (when (vhdl-template-field "block name" nil t start (point))
8137 (vhdl-insert-keyword "\n\n")
8139 (vhdl-insert-keyword "END FOR;")
8141 (indent-to (+ margin vhdl-basic-offset)))))
8143 (defun vhdl-template-break ()
8144 "Insert a break statement."
8147 (vhdl-insert-keyword "BREAK")
8148 (setq position (point))
8151 (progn (vhdl-insert-keyword "FOR ")
8152 (if (vhdl-template-field "[quantity name]" " USE " t)
8153 (progn (vhdl-template-field "quantity name" " => ") t)
8154 (kill-word -1) nil))
8155 (vhdl-template-field "[quantity name]" " => " t))
8156 (vhdl-template-field "expression")
8157 (setq position (point))
8159 (delete-region position (point))
8160 (unless (vhdl-sequential-statement-p)
8161 (vhdl-insert-keyword " ON ")
8162 (if (vhdl-template-field "[sensitivity list]" nil t)
8163 (setq position (point))
8164 (delete-region position (point))))
8165 (vhdl-insert-keyword " WHEN ")
8166 (when vhdl-conditions-in-parenthesis (insert "("))
8167 (if (vhdl-template-field "[condition]" nil t)
8168 (when vhdl-conditions-in-parenthesis (insert ")"))
8169 (delete-region position (point)))
8172 (defun vhdl-template-case (&optional kind)
8173 "Insert a case statement."
8175 (let ((margin (current-indentation))
8178 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8179 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8180 (vhdl-insert-keyword "CASE ")
8181 (vhdl-insert-keyword ": CASE ")
8183 (setq label (vhdl-template-field "[label]" nil t))
8184 (unless label (delete-char 2))
8187 (when (vhdl-template-field "expression" nil t start (point))
8188 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8190 (vhdl-insert-keyword "END CASE")
8191 (when label (insert " " label))
8194 (indent-to (+ margin vhdl-basic-offset))
8195 (vhdl-insert-keyword "WHEN ")
8196 (let ((position (point)))
8198 (indent-to (+ margin vhdl-basic-offset))
8199 (vhdl-insert-keyword "WHEN OTHERS => null;")
8200 (goto-char position)))))
8202 (defun vhdl-template-case-is ()
8203 "Insert a sequential case statement."
8205 (vhdl-template-case 'is))
8207 (defun vhdl-template-case-use ()
8208 "Insert a simultaneous case statement."
8210 (vhdl-template-case 'use))
8212 (defun vhdl-template-component ()
8213 "Insert a component declaration."
8215 (vhdl-template-component-decl))
8217 (defun vhdl-template-component-conf ()
8218 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8219 since these are almost equivalent)."
8221 (let ((margin (current-indentation))
8222 (result (vhdl-template-configuration-spec t)))
8226 (vhdl-insert-keyword "END FOR;")
8227 (when (eq result 'no-use)
8228 (end-of-line -0)))))
8230 (defun vhdl-template-component-decl ()
8231 "Insert a component declaration."
8233 (let ((margin (current-indentation))
8236 (vhdl-insert-keyword "COMPONENT ")
8237 (when (setq name (vhdl-template-field "name" nil t start (point)))
8238 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8241 (vhdl-insert-keyword "END COMPONENT")
8242 (unless (vhdl-standard-p '87) (insert " " name))
8244 (setq end-column (current-column))
8246 (indent-to (+ margin vhdl-basic-offset))
8247 (vhdl-template-generic-list t t)
8249 (indent-to (+ margin vhdl-basic-offset))
8250 (vhdl-template-port-list t)
8251 (beginning-of-line 2)
8252 (forward-char end-column))))
8254 (defun vhdl-template-component-inst ()
8255 "Insert a component instantiation statement."
8257 (let ((margin (current-indentation))
8260 (when (vhdl-template-field "instance label" nil t start (point))
8262 (if (not (vhdl-use-direct-instantiation))
8263 (vhdl-template-field "component name")
8264 ;; direct instantiation
8265 (setq unit (vhdl-template-field
8266 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8267 (setq unit (upcase (or unit "")))
8268 (cond ((equal unit "ENTITY")
8269 (vhdl-template-field "library name" "." nil nil nil nil
8270 (vhdl-work-library))
8271 (vhdl-template-field "entity name" "(")
8272 (if (vhdl-template-field "[architecture name]" nil t)
8275 ((equal unit "CONFIGURATION")
8276 (vhdl-template-field "library name" "." nil nil nil nil
8277 (vhdl-work-library))
8278 (vhdl-template-field "configuration name"))
8279 (t (vhdl-template-field "component name"))))
8281 (indent-to (+ margin vhdl-basic-offset))
8282 (setq position (point))
8283 (vhdl-insert-keyword "GENERIC ")
8284 (when (vhdl-template-map position t t)
8286 (indent-to (+ margin vhdl-basic-offset)))
8287 (setq position (point))
8288 (vhdl-insert-keyword "PORT ")
8289 (unless (vhdl-template-map position t t)
8294 (defun vhdl-template-conditional-signal-asst ()
8295 "Insert a conditional signal assignment."
8297 (when (vhdl-template-field "target signal")
8299 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8301 (let ((margin (current-column))
8304 (vhdl-template-field "waveform")
8305 (setq position (point))
8306 (vhdl-insert-keyword " WHEN ")
8307 (when vhdl-conditions-in-parenthesis (insert "("))
8308 (while (and (vhdl-template-field "[condition]" nil t)
8310 (when vhdl-conditions-in-parenthesis (insert ")"))
8311 (setq position (point))
8312 (vhdl-insert-keyword " ELSE")
8315 (vhdl-template-field "[waveform]" nil t)))
8316 (setq position (point))
8317 (vhdl-insert-keyword " WHEN ")
8318 (when vhdl-conditions-in-parenthesis (insert "(")))
8319 (delete-region position (point))
8321 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8323 (defun vhdl-template-configuration ()
8324 "Insert a configuration specification if within an architecture,
8325 a block or component configuration if within a configuration declaration,
8326 a configuration declaration if not within a design unit."
8328 (vhdl-prepare-search-1
8330 ((and (save-excursion ; architecture body
8331 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8332 (equal "ARCHITECTURE" (upcase (match-string 1))))
8333 (vhdl-template-configuration-spec))
8334 ((and (save-excursion ; configuration declaration
8335 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8336 (equal "CONFIGURATION" (upcase (match-string 1))))
8337 (if (eq (vhdl-decision-query
8338 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8339 (vhdl-template-component-conf)
8340 (vhdl-template-block-configuration)))
8341 (t (vhdl-template-configuration-decl))))) ; otherwise
8343 (defun vhdl-template-configuration-spec (&optional optional-use)
8344 "Insert a configuration specification."
8346 (let ((margin (current-indentation))
8349 (vhdl-insert-keyword "FOR ")
8350 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8352 (vhdl-template-field "component name" "\n")
8353 (indent-to (+ margin vhdl-basic-offset))
8354 (setq start (point))
8355 (vhdl-insert-keyword "USE ")
8356 (if (and optional-use
8357 (not (setq aspect (vhdl-template-field
8358 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8359 (progn (delete-region start (point)) 'no-use)
8360 (unless optional-use
8361 (setq aspect (vhdl-template-field
8362 "ENTITY | CONFIGURATION | OPEN" " ")))
8363 (setq aspect (upcase (or aspect "")))
8364 (cond ((equal aspect "ENTITY")
8365 (vhdl-template-field "library name" "." nil nil nil nil
8366 (vhdl-work-library))
8367 (vhdl-template-field "entity name" "(")
8368 (if (vhdl-template-field "[architecture name]" nil t)
8372 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8373 (setq position (point))
8374 (vhdl-insert-keyword "GENERIC ")
8375 (when (vhdl-template-map position t t)
8377 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8378 (setq position (point))
8379 (vhdl-insert-keyword "PORT ")
8380 (unless (vhdl-template-map position t t)
8385 ((equal aspect "CONFIGURATION")
8386 (vhdl-template-field "library name" "." nil nil nil nil
8387 (vhdl-work-library))
8388 (vhdl-template-field "configuration name" ";"))
8389 (t (delete-backward-char 1) (insert ";") t))))))
8392 (defun vhdl-template-configuration-decl ()
8393 "Insert a configuration declaration."
8395 (let ((margin (current-indentation))
8397 entity-exists string name position)
8398 (vhdl-insert-keyword "CONFIGURATION ")
8399 (when (setq name (vhdl-template-field "name" nil t start (point)))
8400 (vhdl-insert-keyword " OF ")
8402 (vhdl-prepare-search-1
8403 (setq entity-exists (vhdl-re-search-backward
8404 "\\<entity \\(\\w*\\) is\\>" nil t))
8405 (setq string (match-string 1))))
8406 (if (and entity-exists (not (equal string "")))
8408 (vhdl-template-field "entity name"))
8409 (vhdl-insert-keyword " IS\n")
8410 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8411 (indent-to (+ margin vhdl-basic-offset))
8412 (setq position (point))
8414 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8416 (vhdl-insert-keyword "END ")
8417 (unless (vhdl-standard-p '87)
8418 (vhdl-insert-keyword "CONFIGURATION "))
8420 (goto-char position))))
8422 (defun vhdl-template-constant ()
8423 "Insert a constant declaration."
8425 (let ((start (point))
8426 (in-arglist (vhdl-in-argument-list-p)))
8427 (vhdl-insert-keyword "CONSTANT ")
8428 (when (vhdl-template-field "name" nil t start (point))
8430 (when in-arglist (vhdl-insert-keyword "IN "))
8431 (vhdl-template-field "type")
8434 (vhdl-comment-insert-inline))
8435 (let ((position (point)))
8437 (unless (vhdl-template-field "[initialization]" nil t)
8438 (delete-region position (point)))
8440 (vhdl-comment-insert-inline))))))
8442 (defun vhdl-template-default ()
8451 (defun vhdl-template-default-indent ()
8452 "Insert nothing and indent."
8459 (indent-according-to-mode))
8461 (defun vhdl-template-disconnect ()
8462 "Insert a disconnect statement."
8464 (let ((start (point)))
8465 (vhdl-insert-keyword "DISCONNECT ")
8466 (when (vhdl-template-field "signal names | OTHERS | ALL"
8467 " : " t start (point))
8468 (vhdl-template-field "type")
8469 (vhdl-insert-keyword " AFTER ")
8470 (vhdl-template-field "time expression" ";"))))
8472 (defun vhdl-template-else ()
8473 "Insert an else statement."
8476 (vhdl-prepare-search-1
8477 (vhdl-insert-keyword "ELSE")
8478 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8479 (equal "WHEN" (upcase (match-string 1))))
8481 (indent-according-to-mode)
8482 (setq margin (current-indentation))
8484 (indent-to (+ margin vhdl-basic-offset))))))
8486 (defun vhdl-template-elsif ()
8487 "Insert an elsif statement."
8489 (let ((start (point))
8491 (vhdl-insert-keyword "ELSIF ")
8492 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8493 (when vhdl-conditions-in-parenthesis (insert "("))
8494 (when (vhdl-template-field "condition" nil t start (point))
8495 (when vhdl-conditions-in-parenthesis (insert ")"))
8496 (indent-according-to-mode)
8497 (setq margin (current-indentation))
8498 (vhdl-insert-keyword
8499 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8500 (indent-to (+ margin vhdl-basic-offset))))))
8502 (defun vhdl-template-entity ()
8505 (let ((margin (current-indentation))
8508 (vhdl-insert-keyword "ENTITY ")
8509 (when (setq name (vhdl-template-field "name" nil t start (point)))
8510 (vhdl-insert-keyword " IS\n\n")
8512 (vhdl-insert-keyword "END ")
8513 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8515 (setq end-column (current-column))
8517 (indent-to (+ margin vhdl-basic-offset))
8518 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8519 (indent-to (+ margin vhdl-basic-offset))
8520 (when (vhdl-template-generic-list t)
8521 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8523 (indent-to (+ margin vhdl-basic-offset))
8524 (when (vhdl-template-port-list t)
8525 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8526 (beginning-of-line 2)
8527 (forward-char end-column))))
8529 (defun vhdl-template-exit ()
8530 "Insert an exit statement."
8532 (let ((start (point)))
8533 (vhdl-insert-keyword "EXIT ")
8534 (if (vhdl-template-field "[loop label]" nil t start (point))
8535 (let ((position (point)))
8536 (vhdl-insert-keyword " WHEN ")
8537 (when vhdl-conditions-in-parenthesis (insert "("))
8538 (if (vhdl-template-field "[condition]" nil t)
8539 (when vhdl-conditions-in-parenthesis (insert ")"))
8540 (delete-region position (point))))
8544 (defun vhdl-template-file ()
8545 "Insert a file declaration."
8547 (let ((start (point)))
8548 (vhdl-insert-keyword "FILE ")
8549 (when (vhdl-template-field "name" nil t start (point))
8551 (vhdl-template-field "type")
8552 (unless (vhdl-standard-p '87)
8553 (vhdl-insert-keyword " OPEN ")
8554 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8556 (delete-backward-char 6)))
8557 (vhdl-insert-keyword " IS ")
8558 (when (vhdl-standard-p '87)
8559 (vhdl-template-field "[IN | OUT]" " " t))
8560 (vhdl-template-field "filename-string" nil nil nil nil t)
8562 (vhdl-comment-insert-inline))))
8564 (defun vhdl-template-for ()
8565 "Insert a block or component configuration if within a configuration
8566 declaration, a configuration specification if within an architecture
8567 declarative part (and not within a subprogram), a for-loop if within a
8568 sequential statement part (subprogram or process), and a for-generate
8571 (vhdl-prepare-search-1
8573 ((vhdl-sequential-statement-p) ; sequential statement
8574 (vhdl-template-for-loop))
8575 ((and (save-excursion ; configuration declaration
8576 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8577 (equal "CONFIGURATION" (upcase (match-string 1))))
8578 (if (eq (vhdl-decision-query
8579 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8580 (vhdl-template-component-conf)
8581 (vhdl-template-block-configuration)))
8582 ((and (save-excursion
8583 (re-search-backward ; architecture declarative part
8584 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8585 (equal "ARCHITECTURE" (upcase (match-string 1))))
8586 (vhdl-template-configuration-spec))
8587 (t (vhdl-template-for-generate))))) ; concurrent statement
8589 (defun vhdl-template-for-generate ()
8590 "Insert a for-generate."
8592 (let ((margin (current-indentation))
8595 (vhdl-insert-keyword ": FOR ")
8596 (setq position (point-marker))
8598 (when (setq label (vhdl-template-field "label" nil t start position))
8599 (goto-char position)
8600 (vhdl-template-field "loop variable")
8601 (vhdl-insert-keyword " IN ")
8602 (vhdl-template-field "range")
8603 (vhdl-template-generate-body margin label))))
8605 (defun vhdl-template-for-loop ()
8606 "Insert a for loop."
8608 (let ((margin (current-indentation))
8611 (if (not (eq vhdl-optional-labels 'all))
8612 (vhdl-insert-keyword "FOR ")
8613 (vhdl-insert-keyword ": FOR ")
8615 (setq label (vhdl-template-field "[label]" nil t))
8616 (unless label (delete-char 2))
8619 (when (setq index (vhdl-template-field "loop variable"
8620 nil t start (point)))
8621 (vhdl-insert-keyword " IN ")
8622 (vhdl-template-field "range")
8623 (vhdl-insert-keyword " LOOP\n\n")
8625 (vhdl-insert-keyword "END LOOP")
8627 (insert " " label ";")
8629 (when vhdl-self-insert-comments (insert " -- " index)))
8631 (indent-to (+ margin vhdl-basic-offset)))))
8633 (defun vhdl-template-function (&optional kind)
8634 "Insert a function declaration or body."
8636 (let ((margin (current-indentation))
8639 (vhdl-insert-keyword "FUNCTION ")
8640 (when (setq name (vhdl-template-field "name" nil t start (point)))
8641 (vhdl-template-argument-list t)
8642 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8645 (indent-to (+ margin vhdl-basic-offset))
8646 (vhdl-insert-keyword "RETURN ")
8647 (vhdl-template-field "type")
8648 (if (if kind (eq kind 'body)
8649 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8650 (progn (vhdl-insert-keyword " IS\n")
8651 (vhdl-template-begin-end
8652 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8653 (vhdl-comment-block))
8656 (defun vhdl-template-function-decl ()
8657 "Insert a function declaration."
8659 (vhdl-template-function 'decl))
8661 (defun vhdl-template-function-body ()
8662 "Insert a function declaration."
8664 (vhdl-template-function 'body))
8666 (defun vhdl-template-generate ()
8667 "Insert a generation scheme."
8669 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8670 (vhdl-template-if-generate)
8671 (vhdl-template-for-generate)))
8673 (defun vhdl-template-generic ()
8674 "Insert generic declaration, or generic map in instantiation statements."
8676 (let ((start (point)))
8677 (vhdl-prepare-search-1
8679 ((and (save-excursion ; entity declaration
8680 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8681 (equal "ENTITY" (upcase (match-string 1))))
8682 (vhdl-template-generic-list nil))
8683 ((or (save-excursion
8684 (or (beginning-of-line)
8685 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8686 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8687 (vhdl-insert-keyword "GENERIC ")
8688 (vhdl-template-map start))
8689 (t (vhdl-template-generic-list nil t))))))
8691 (defun vhdl-template-group ()
8692 "Insert group or group template declaration."
8694 (let ((start (point)))
8695 (if (eq (vhdl-decision-query
8696 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8697 (vhdl-template-group-template)
8698 (vhdl-template-group-decl))))
8700 (defun vhdl-template-group-decl ()
8701 "Insert group declaration."
8703 (let ((start (point)))
8704 (vhdl-insert-keyword "GROUP ")
8705 (when (vhdl-template-field "name" " : " t start (point))
8706 (vhdl-template-field "template name" " (")
8707 (vhdl-template-field "constituent list" ");")
8708 (vhdl-comment-insert-inline))))
8710 (defun vhdl-template-group-template ()
8711 "Insert group template declaration."
8713 (let ((start (point)))
8714 (vhdl-insert-keyword "GROUP ")
8715 (when (vhdl-template-field "template name" nil t start (point))
8716 (vhdl-insert-keyword " IS (")
8717 (vhdl-template-field "entity class list" ");")
8718 (vhdl-comment-insert-inline))))
8720 (defun vhdl-template-if ()
8721 "Insert a sequential if statement or an if-generate statement."
8723 (if (vhdl-sequential-statement-p)
8724 (vhdl-template-if-then)
8725 (if (and (vhdl-standard-p 'ams)
8726 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8727 (vhdl-template-if-use)
8728 (vhdl-template-if-generate))))
8730 (defun vhdl-template-if-generate ()
8731 "Insert an if-generate."
8733 (let ((margin (current-indentation))
8736 (vhdl-insert-keyword ": IF ")
8737 (setq position (point-marker))
8739 (when (setq label (vhdl-template-field "label" nil t start position))
8740 (goto-char position)
8741 (when vhdl-conditions-in-parenthesis (insert "("))
8742 (vhdl-template-field "condition")
8743 (when vhdl-conditions-in-parenthesis (insert ")"))
8744 (vhdl-template-generate-body margin label))))
8746 (defun vhdl-template-if-then-use (kind)
8747 "Insert a sequential if statement."
8749 (let ((margin (current-indentation))
8752 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8753 (vhdl-insert-keyword "IF ")
8754 (vhdl-insert-keyword ": IF ")
8756 (setq label (vhdl-template-field "[label]" nil t))
8757 (unless label (delete-char 2))
8760 (when vhdl-conditions-in-parenthesis (insert "("))
8761 (when (vhdl-template-field "condition" nil t start (point))
8762 (when vhdl-conditions-in-parenthesis (insert ")"))
8763 (vhdl-insert-keyword
8764 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8766 (vhdl-insert-keyword "END IF")
8767 (when label (insert " " label))
8770 (indent-to (+ margin vhdl-basic-offset)))))
8772 (defun vhdl-template-if-then ()
8773 "Insert a sequential if statement."
8775 (vhdl-template-if-then-use 'then))
8777 (defun vhdl-template-if-use ()
8778 "Insert a simultaneous if statement."
8780 (vhdl-template-if-then-use 'use))
8782 (defun vhdl-template-instance ()
8783 "Insert a component instantiation statement."
8785 (vhdl-template-component-inst))
8787 (defun vhdl-template-library ()
8788 "Insert a library specification."
8790 (let ((margin (current-indentation))
8793 (vhdl-insert-keyword "LIBRARY ")
8794 (when (setq name (vhdl-template-field "names" nil t start (point)))
8796 (unless (string-match "," name)
8797 (setq end-pos (point))
8800 (vhdl-insert-keyword "USE ")
8802 (vhdl-insert-keyword "..ALL;")
8804 (if (vhdl-template-field "package name")
8806 (delete-region end-pos (+ (point) 5)))))))
8808 (defun vhdl-template-limit ()
8811 (let ((start (point)))
8812 (vhdl-insert-keyword "LIMIT ")
8813 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8815 (vhdl-template-field "type")
8816 (vhdl-insert-keyword " WITH ")
8817 (vhdl-template-field "real expression" ";"))))
8819 (defun vhdl-template-loop ()
8822 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8824 (vhdl-template-while-loop))
8826 (vhdl-template-for-loop))
8827 (t (vhdl-template-bare-loop)))))
8829 (defun vhdl-template-bare-loop ()
8832 (let ((margin (current-indentation))
8835 (if (not (eq vhdl-optional-labels 'all))
8836 (vhdl-insert-keyword "LOOP ")
8837 (vhdl-insert-keyword ": LOOP ")
8839 (setq label (vhdl-template-field "[label]" nil t))
8840 (unless label (delete-char 2))
8845 (vhdl-insert-keyword "END LOOP")
8846 (insert (if label (concat " " label ";") ";"))
8848 (indent-to (+ margin vhdl-basic-offset))))
8850 (defun vhdl-template-map (&optional start optional secondary)
8851 "Insert a map specification with association list."
8853 (let ((start (or start (point)))
8855 (vhdl-insert-keyword "MAP (")
8856 (if (not vhdl-association-list-with-formals)
8857 (if (vhdl-template-field
8858 (concat (and optional "[") "association list" (and optional "]"))
8859 ")" (or (not secondary) optional)
8860 (and (not secondary) start) (point))
8862 (if (and optional secondary) (delete-region start (point)))
8864 (if vhdl-argument-list-indent
8865 (setq margin (current-column))
8866 (setq margin (+ (current-indentation) vhdl-basic-offset))
8869 (if (vhdl-template-field
8870 (concat (and optional "[") "formal" (and optional "]"))
8871 " => " (or (not secondary) optional)
8872 (and (not secondary) start) (point))
8874 (vhdl-template-field "actual" ",")
8875 (setq end-pos (point))
8878 (while (vhdl-template-field "[formal]" " => " t)
8879 (vhdl-template-field "actual" ",")
8880 (setq end-pos (point))
8883 (delete-region end-pos (point))
8884 (delete-backward-char 1)
8886 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8888 (when (and optional secondary) (delete-region start (point)))
8891 (defun vhdl-template-modify (&optional noerror)
8892 "Actualize modification date."
8894 (vhdl-prepare-search-2
8896 (goto-char (point-min))
8897 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
8898 (progn (delete-region (point) (progn (end-of-line) (point)))
8899 (vhdl-template-insert-date))
8901 (error (concat "ERROR: Modification date prefix string \""
8902 vhdl-modify-date-prefix-string "\" not found")))))))
8904 (defun vhdl-template-modify-noerror ()
8905 "Call `vhdl-template-modify' with NOERROR non-nil."
8906 (vhdl-template-modify t))
8908 (defun vhdl-template-nature ()
8909 "Insert a nature declaration."
8911 (let ((start (point))
8912 name mid-pos end-pos)
8913 (vhdl-insert-keyword "NATURE ")
8914 (when (setq name (vhdl-template-field "name" nil t start (point)))
8915 (vhdl-insert-keyword " IS ")
8918 (or (vhdl-template-field
8919 "across type | ARRAY | RECORD")
8921 (cond ((equal definition "")
8923 ((equal definition "ARRAY")
8925 (vhdl-template-array 'nature t))
8926 ((equal definition "RECORD")
8927 (setq mid-pos (point-marker))
8929 (vhdl-template-record 'nature name t))
8931 (vhdl-insert-keyword " ACROSS ")
8932 (vhdl-template-field "through type")
8933 (vhdl-insert-keyword " THROUGH ")
8934 (vhdl-template-field "reference name")
8935 (vhdl-insert-keyword " REFERENCE;")))
8937 (setq end-pos (point-marker))
8940 (vhdl-comment-insert-inline)
8941 (when end-pos (goto-char end-pos))))))
8943 (defun vhdl-template-next ()
8944 "Insert a next statement."
8946 (let ((start (point)))
8947 (vhdl-insert-keyword "NEXT ")
8948 (if (vhdl-template-field "[loop label]" nil t start (point))
8949 (let ((position (point)))
8950 (vhdl-insert-keyword " WHEN ")
8951 (when vhdl-conditions-in-parenthesis (insert "("))
8952 (if (vhdl-template-field "[condition]" nil t)
8953 (when vhdl-conditions-in-parenthesis (insert ")"))
8954 (delete-region position (point))))
8958 (defun vhdl-template-others ()
8959 "Insert an others aggregate."
8961 (let ((start (point)))
8962 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
8963 (progn (unless vhdl-template-invoked-by-hook (insert "("))
8964 (vhdl-insert-keyword "OTHERS => '")
8965 (when (vhdl-template-field "value" nil t start (point))
8967 (vhdl-insert-keyword "OTHERS "))))
8969 (defun vhdl-template-package (&optional kind)
8970 "Insert a package specification or body."
8972 (let ((margin (current-indentation))
8975 (vhdl-insert-keyword "PACKAGE ")
8976 (setq body (if kind (eq kind 'body)
8977 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
8979 (vhdl-insert-keyword "BODY ")
8980 (when (save-excursion
8981 (vhdl-prepare-search-1
8982 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
8983 (insert (setq name (match-string 1)))))
8985 (setq name (vhdl-template-field "name" nil t start (point))))
8986 (vhdl-insert-keyword " IS\n")
8987 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8988 (indent-to (+ margin vhdl-basic-offset))
8989 (setq position (point))
8991 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8993 (vhdl-insert-keyword "END ")
8994 (unless (vhdl-standard-p '87)
8995 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
8996 (insert (or name "") ";")
8997 (goto-char position))))
8999 (defun vhdl-template-package-decl ()
9000 "Insert a package specification."
9002 (vhdl-template-package 'decl))
9004 (defun vhdl-template-package-body ()
9005 "Insert a package body."
9007 (vhdl-template-package 'body))
9009 (defun vhdl-template-port ()
9010 "Insert a port declaration, or port map in instantiation statements."
9012 (let ((start (point)))
9013 (vhdl-prepare-search-1
9015 ((and (save-excursion ; entity declaration
9016 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9017 (equal "ENTITY" (upcase (match-string 1))))
9018 (vhdl-template-port-list nil))
9019 ((or (save-excursion
9020 (or (beginning-of-line)
9021 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9022 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9023 (vhdl-insert-keyword "PORT ")
9024 (vhdl-template-map start))
9025 (t (vhdl-template-port-list nil))))))
9027 (defun vhdl-template-procedural ()
9028 "Insert a procedural."
9030 (let ((margin (current-indentation))
9032 (case-fold-search t)
9034 (vhdl-insert-keyword "PROCEDURAL ")
9035 (when (memq vhdl-optional-labels '(process all))
9039 (setq label (vhdl-template-field "[label]" nil t))
9040 (unless label (delete-char 2))
9043 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9045 (vhdl-template-begin-end "PROCEDURAL" label margin)
9046 (vhdl-comment-block)))
9048 (defun vhdl-template-procedure (&optional kind)
9049 "Insert a procedure declaration or body."
9051 (let ((margin (current-indentation))
9054 (vhdl-insert-keyword "PROCEDURE ")
9055 (when (setq name (vhdl-template-field "name" nil t start (point)))
9056 (vhdl-template-argument-list)
9057 (if (if kind (eq kind 'body)
9058 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9059 (progn (vhdl-insert-keyword " IS")
9060 (when vhdl-auto-align
9061 (vhdl-align-region-groups start (point) 1))
9062 (end-of-line) (insert "\n")
9063 (vhdl-template-begin-end
9064 (unless (vhdl-standard-p '87) "PROCEDURE")
9066 (vhdl-comment-block))
9068 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9071 (defun vhdl-template-procedure-decl ()
9072 "Insert a procedure declaration."
9074 (vhdl-template-procedure 'decl))
9076 (defun vhdl-template-procedure-body ()
9077 "Insert a procedure body."
9079 (vhdl-template-procedure 'body))
9081 (defun vhdl-template-process (&optional kind)
9084 (let ((margin (current-indentation))
9086 label seq input-signals clock reset final-pos)
9087 (setq seq (if kind (eq kind 'seq)
9088 (eq (vhdl-decision-query
9089 "process" "(c)ombinational or (s)equential?" t) ?s)))
9090 (vhdl-insert-keyword "PROCESS ")
9091 (when (memq vhdl-optional-labels '(process all))
9095 (setq label (vhdl-template-field "[label]" nil t))
9096 (unless label (delete-char 2))
9101 (unless (setq input-signals
9102 (vhdl-template-field "[sensitivity list]" ")" t))
9103 (setq input-signals "")
9105 (setq clock (or (and (not (equal "" vhdl-clock-name))
9106 (progn (insert vhdl-clock-name) vhdl-clock-name))
9107 (vhdl-template-field "clock name") "<clock>"))
9108 (when (eq vhdl-reset-kind 'async)
9110 (setq reset (or (and (not (equal "" vhdl-reset-name))
9111 (progn (insert vhdl-reset-name) vhdl-reset-name))
9112 (vhdl-template-field "reset name") "<reset>")))
9114 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9116 (vhdl-template-begin-end "PROCESS" label margin)
9117 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9118 (when vhdl-prompt-for-comments
9119 (setq final-pos (point-marker))
9120 (vhdl-prepare-search-2
9121 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9122 (vhdl-re-search-backward "\\<process\\>" nil t))
9125 (progn (insert "\n") (forward-line -1))
9128 (insert "-- purpose: ")
9129 (if (not (vhdl-template-field "[description]" nil t))
9130 (vhdl-line-kill-entire)
9133 (insert "-- type : ")
9134 (insert (if seq "sequential" "combinational") "\n")
9136 (insert "-- inputs : ")
9138 (insert input-signals)
9140 (when reset (insert reset ", "))
9141 (unless (vhdl-template-field "[signal names]" nil t)
9145 (insert "-- outputs: ")
9146 (vhdl-template-field "[signal names]" nil t))))
9147 (goto-char final-pos))))
9149 (defun vhdl-template-process-comb ()
9150 "Insert a combinational process."
9152 (vhdl-template-process 'comb))
9154 (defun vhdl-template-process-seq ()
9155 "Insert a sequential process."
9157 (vhdl-template-process 'seq))
9159 (defun vhdl-template-quantity ()
9160 "Insert a quantity declaration."
9162 (if (vhdl-in-argument-list-p)
9163 (let ((start (point)))
9164 (vhdl-insert-keyword "QUANTITY ")
9165 (when (vhdl-template-field "names" nil t start (point))
9167 (vhdl-template-field "[IN | OUT]" " " t)
9168 (vhdl-template-field "type")
9170 (vhdl-comment-insert-inline)))
9171 (let ((char (vhdl-decision-query
9172 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9173 (cond ((eq char ?f) (vhdl-template-quantity-free))
9174 ((eq char ?b) (vhdl-template-quantity-branch))
9175 ((eq char ?s) (vhdl-template-quantity-source))
9176 (t (vhdl-template-undo (point) (point)))))))
9178 (defun vhdl-template-quantity-free ()
9179 "Insert a free quantity declaration."
9181 (vhdl-insert-keyword "QUANTITY ")
9182 (vhdl-template-field "names")
9184 (vhdl-template-field "type")
9185 (let ((position (point)))
9187 (unless (vhdl-template-field "[initialization]" nil t)
9188 (delete-region position (point)))
9190 (vhdl-comment-insert-inline)))
9192 (defun vhdl-template-quantity-branch ()
9193 "Insert a branch quantity declaration."
9196 (vhdl-insert-keyword "QUANTITY ")
9197 (when (vhdl-template-field "[across names]" " " t)
9198 (vhdl-insert-keyword "ACROSS "))
9199 (when (vhdl-template-field "[through names]" " " t)
9200 (vhdl-insert-keyword "THROUGH "))
9201 (vhdl-template-field "plus terminal name")
9202 (setq position (point))
9203 (vhdl-insert-keyword " TO ")
9204 (unless (vhdl-template-field "[minus terminal name]" nil t)
9205 (delete-region position (point)))
9207 (vhdl-comment-insert-inline)))
9209 (defun vhdl-template-quantity-source ()
9210 "Insert a source quantity declaration."
9212 (vhdl-insert-keyword "QUANTITY ")
9213 (vhdl-template-field "names")
9215 (vhdl-template-field "type" " ")
9216 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9217 (progn (vhdl-insert-keyword "NOISE ")
9218 (vhdl-template-field "power expression"))
9219 (vhdl-insert-keyword "SPECTRUM ")
9220 (vhdl-template-field "magnitude expression" ", ")
9221 (vhdl-template-field "phase expression"))
9223 (vhdl-comment-insert-inline))
9225 (defun vhdl-template-record (kind &optional name secondary)
9226 "Insert a record type declaration."
9228 (let ((margin (current-column))
9231 (vhdl-insert-keyword "RECORD\n")
9232 (indent-to (+ margin vhdl-basic-offset))
9233 (when (or (vhdl-template-field "element names"
9234 nil (not secondary) start (point))
9236 (while (or first (vhdl-template-field "[element names]" nil t))
9238 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9239 (vhdl-comment-insert-inline)
9241 (indent-to (+ margin vhdl-basic-offset))
9245 (vhdl-insert-keyword "END RECORD")
9246 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9248 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9250 (defun vhdl-template-report ()
9251 "Insert a report statement."
9253 (let ((start (point)))
9254 (vhdl-insert-keyword "REPORT ")
9255 (if (equal "\"\"" (vhdl-template-field
9256 "string expression" nil t start (point) t))
9257 (delete-backward-char 2)
9258 (setq start (point))
9259 (vhdl-insert-keyword " SEVERITY ")
9260 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9261 (delete-region start (point)))
9264 (defun vhdl-template-return ()
9265 "Insert a return statement."
9267 (let ((start (point)))
9268 (vhdl-insert-keyword "RETURN ")
9269 (unless (vhdl-template-field "[expression]" nil t start (point))
9273 (defun vhdl-template-selected-signal-asst ()
9274 "Insert a selected signal assignment."
9276 (let ((margin (current-indentation))
9279 (let ((position (point)))
9280 (vhdl-insert-keyword " SELECT ")
9281 (goto-char position))
9282 (vhdl-insert-keyword "WITH ")
9283 (when (vhdl-template-field "selector expression"
9284 nil t start (+ (point) 7))
9288 (indent-to (+ margin vhdl-basic-offset))
9289 (vhdl-template-field "target signal" " <= ")
9290 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9292 (indent-to (+ margin vhdl-basic-offset))
9293 (vhdl-template-field "waveform")
9294 (vhdl-insert-keyword " WHEN ")
9295 (vhdl-template-field "choices" ",")
9297 (indent-to (+ margin vhdl-basic-offset))
9298 (while (and choices (vhdl-template-field "[waveform]" nil t))
9299 (vhdl-insert-keyword " WHEN ")
9300 (if (setq choices (vhdl-template-field "[choices]" "," t))
9301 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9302 (vhdl-insert-keyword "OTHERS")))
9307 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9309 (defun vhdl-template-signal ()
9310 "Insert a signal declaration."
9312 (let ((start (point))
9313 (in-arglist (vhdl-in-argument-list-p)))
9314 (vhdl-insert-keyword "SIGNAL ")
9315 (when (vhdl-template-field "names" nil t start (point))
9317 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9318 (vhdl-template-field "type")
9321 (vhdl-comment-insert-inline))
9322 (let ((position (point)))
9324 (unless (vhdl-template-field "[initialization]" nil t)
9325 (delete-region position (point)))
9327 (vhdl-comment-insert-inline))))))
9329 (defun vhdl-template-subnature ()
9330 "Insert a subnature declaration."
9332 (let ((start (point))
9334 (vhdl-insert-keyword "SUBNATURE ")
9335 (when (vhdl-template-field "name" nil t start (point))
9336 (vhdl-insert-keyword " IS ")
9337 (vhdl-template-field "nature" " (")
9338 (if (vhdl-template-field "[index range]" nil t)
9341 (setq position (point))
9342 (vhdl-insert-keyword " TOLERANCE ")
9343 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9345 (delete-region position (point))
9346 (vhdl-insert-keyword " ACROSS ")
9347 (vhdl-template-field "string expression" nil nil nil nil t)
9348 (vhdl-insert-keyword " THROUGH"))
9350 (vhdl-comment-insert-inline))))
9352 (defun vhdl-template-subprogram-body ()
9353 "Insert a subprogram body."
9355 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9356 (vhdl-template-function-body)
9357 (vhdl-template-procedure-body)))
9359 (defun vhdl-template-subprogram-decl ()
9360 "Insert a subprogram declaration."
9362 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9363 (vhdl-template-function-decl)
9364 (vhdl-template-procedure-decl)))
9366 (defun vhdl-template-subtype ()
9367 "Insert a subtype declaration."
9369 (let ((start (point)))
9370 (vhdl-insert-keyword "SUBTYPE ")
9371 (when (vhdl-template-field "name" nil t start (point))
9372 (vhdl-insert-keyword " IS ")
9373 (vhdl-template-field "type" " ")
9375 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9378 (vhdl-comment-insert-inline))))
9380 (defun vhdl-template-terminal ()
9381 "Insert a terminal declaration."
9383 (let ((start (point)))
9384 (vhdl-insert-keyword "TERMINAL ")
9385 (when (vhdl-template-field "names" nil t start (point))
9387 (vhdl-template-field "nature")
9389 (vhdl-comment-insert-inline))))
9391 (defun vhdl-template-type ()
9392 "Insert a type declaration."
9394 (let ((start (point))
9395 name mid-pos end-pos)
9396 (vhdl-insert-keyword "TYPE ")
9397 (when (setq name (vhdl-template-field "name" nil t start (point)))
9398 (vhdl-insert-keyword " IS ")
9401 (or (vhdl-template-field
9402 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9404 (cond ((equal definition "")
9405 (delete-backward-char 4)
9407 ((equal definition "ARRAY")
9409 (vhdl-template-array 'type t))
9410 ((equal definition "RECORD")
9411 (setq mid-pos (point-marker))
9413 (vhdl-template-record 'type name t))
9414 ((equal definition "ACCESS")
9416 (vhdl-template-field "type" ";"))
9417 ((equal definition "FILE")
9418 (vhdl-insert-keyword " OF ")
9419 (vhdl-template-field "type" ";"))
9422 (setq end-pos (point-marker))
9425 (vhdl-comment-insert-inline)
9426 (when end-pos (goto-char end-pos))))))
9428 (defun vhdl-template-use ()
9429 "Insert a use clause."
9431 (let ((start (point)))
9432 (vhdl-prepare-search-1
9433 (vhdl-insert-keyword "USE ")
9434 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9435 (vhdl-insert-keyword "..ALL;")
9437 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9439 (vhdl-template-field "package name")
9440 (forward-char 5))))))
9442 (defun vhdl-template-variable ()
9443 "Insert a variable declaration."
9445 (let ((start (point))
9446 (in-arglist (vhdl-in-argument-list-p)))
9447 (vhdl-prepare-search-2
9448 (if (or (save-excursion
9449 (and (vhdl-re-search-backward
9450 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9452 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9453 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9454 (vhdl-insert-keyword "VARIABLE ")
9455 (vhdl-insert-keyword "SHARED VARIABLE ")))
9456 (when (vhdl-template-field "names" nil t start (point))
9458 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9459 (vhdl-template-field "type")
9462 (vhdl-comment-insert-inline))
9463 (let ((position (point)))
9465 (unless (vhdl-template-field "[initialization]" nil t)
9466 (delete-region position (point)))
9468 (vhdl-comment-insert-inline))))))
9470 (defun vhdl-template-wait ()
9471 "Insert a wait statement."
9473 (vhdl-insert-keyword "WAIT ")
9474 (unless (vhdl-template-field
9475 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9480 (defun vhdl-template-when ()
9481 "Indent correctly if within a case statement."
9483 (let ((position (point))
9485 (vhdl-prepare-search-2
9486 (if (and (= (current-column) (current-indentation))
9487 (vhdl-re-search-forward "\\<end\\>" nil t)
9488 (looking-at "\\s-*\\<case\\>"))
9490 (setq margin (current-indentation))
9491 (goto-char position)
9492 (delete-horizontal-space)
9493 (indent-to (+ margin vhdl-basic-offset)))
9494 (goto-char position)))
9495 (vhdl-insert-keyword "WHEN ")))
9497 (defun vhdl-template-while-loop ()
9498 "Insert a while loop."
9500 (let* ((margin (current-indentation))
9503 (if (not (eq vhdl-optional-labels 'all))
9504 (vhdl-insert-keyword "WHILE ")
9505 (vhdl-insert-keyword ": WHILE ")
9507 (setq label (vhdl-template-field "[label]" nil t))
9508 (unless label (delete-char 2))
9511 (when vhdl-conditions-in-parenthesis (insert "("))
9512 (when (vhdl-template-field "condition" nil t start (point))
9513 (when vhdl-conditions-in-parenthesis (insert ")"))
9514 (vhdl-insert-keyword " LOOP\n\n")
9516 (vhdl-insert-keyword "END LOOP")
9517 (insert (if label (concat " " label ";") ";"))
9519 (indent-to (+ margin vhdl-basic-offset)))))
9521 (defun vhdl-template-with ()
9522 "Insert a with statement (i.e. selected signal assignment)."
9524 (vhdl-prepare-search-1
9525 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9526 (equal ";" (match-string 1)))
9527 (vhdl-template-selected-signal-asst)
9528 (vhdl-insert-keyword "WITH "))))
9530 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9531 ;; Special templates
9533 (defun vhdl-template-clocked-wait ()
9534 "Insert a wait statement for rising/falling clock edge."
9536 (let ((start (point))
9538 (vhdl-insert-keyword "WAIT UNTIL ")
9540 (or (and (not (equal "" vhdl-clock-name))
9541 (progn (insert vhdl-clock-name) vhdl-clock-name))
9542 (vhdl-template-field "clock name" nil t start (point))))
9544 (vhdl-insert-keyword " AND ")
9547 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9548 (vhdl-comment-insert-inline
9549 (concat (if vhdl-clock-rising-edge "rising" "falling")
9552 (defun vhdl-template-seq-process (clock reset)
9553 "Insert a template for the body of a sequential process."
9554 (let ((margin (current-indentation))
9556 (vhdl-insert-keyword "IF ")
9557 (when (eq vhdl-reset-kind 'async)
9559 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9560 (vhdl-insert-keyword " THEN")
9561 (vhdl-comment-insert-inline
9562 (concat "asynchronous reset (active "
9563 (if vhdl-reset-active-high "high" "low") ")"))
9564 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9565 (setq position (point))
9566 (insert "\n") (indent-to margin)
9567 (vhdl-insert-keyword "ELSIF "))
9568 (if (eq vhdl-clock-edge-condition 'function)
9569 (insert (if vhdl-clock-rising-edge "rising" "falling")
9571 (insert clock "'event")
9572 (vhdl-insert-keyword " AND ")
9574 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9575 (vhdl-insert-keyword " THEN")
9576 (vhdl-comment-insert-inline
9577 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9578 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9579 (when (eq vhdl-reset-kind 'sync)
9580 (vhdl-insert-keyword "IF ")
9581 (setq reset (or (and (not (equal "" vhdl-reset-name))
9582 (progn (insert vhdl-reset-name) vhdl-reset-name))
9583 (vhdl-template-field "reset name") "<reset>"))
9585 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9586 (vhdl-insert-keyword " THEN")
9587 (vhdl-comment-insert-inline
9588 (concat "synchronous reset (active "
9589 (if vhdl-reset-active-high "high" "low") ")"))
9590 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9591 (setq position (point))
9592 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9593 (vhdl-insert-keyword "ELSE")
9594 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9595 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9596 (vhdl-insert-keyword "END IF;"))
9597 (when (eq vhdl-reset-kind 'none)
9598 (setq position (point)))
9599 (insert "\n") (indent-to margin)
9600 (vhdl-insert-keyword "END IF;")
9601 (goto-char position)
9604 (defun vhdl-template-standard-package (library package)
9605 "Insert specification of a standard package. Include a library
9606 specification, if not already there."
9607 (let ((margin (current-indentation)))
9608 (unless (equal library "std")
9609 (unless (or (save-excursion
9610 (vhdl-prepare-search-1
9613 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9614 library "\\|end\\)\\>") nil t)
9616 (equal (downcase library) "work"))
9617 (vhdl-insert-keyword "LIBRARY ")
9618 (insert library ";\n")
9620 (vhdl-insert-keyword "USE ")
9621 (insert library "." package)
9622 (vhdl-insert-keyword ".ALL;"))))
9624 (defun vhdl-template-package-math-complex ()
9625 "Insert specification of `math_complex' package."
9627 (vhdl-template-standard-package "ieee" "math_complex"))
9629 (defun vhdl-template-package-math-real ()
9630 "Insert specification of `math_real' package."
9632 (vhdl-template-standard-package "ieee" "math_real"))
9634 (defun vhdl-template-package-numeric-bit ()
9635 "Insert specification of `numeric_bit' package."
9637 (vhdl-template-standard-package "ieee" "numeric_bit"))
9639 (defun vhdl-template-package-numeric-std ()
9640 "Insert specification of `numeric_std' package."
9642 (vhdl-template-standard-package "ieee" "numeric_std"))
9644 (defun vhdl-template-package-std-logic-1164 ()
9645 "Insert specification of `std_logic_1164' package."
9647 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9649 (defun vhdl-template-package-std-logic-arith ()
9650 "Insert specification of `std_logic_arith' package."
9652 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9654 (defun vhdl-template-package-std-logic-misc ()
9655 "Insert specification of `std_logic_misc' package."
9657 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9659 (defun vhdl-template-package-std-logic-signed ()
9660 "Insert specification of `std_logic_signed' package."
9662 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9664 (defun vhdl-template-package-std-logic-textio ()
9665 "Insert specification of `std_logic_textio' package."
9667 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9669 (defun vhdl-template-package-std-logic-unsigned ()
9670 "Insert specification of `std_logic_unsigned' package."
9672 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9674 (defun vhdl-template-package-textio ()
9675 "Insert specification of `textio' package."
9677 (vhdl-template-standard-package "std" "textio"))
9679 (defun vhdl-template-directive (directive)
9681 (unless (= (current-indentation) (current-column))
9682 (delete-horizontal-space)
9684 (insert "-- pragma " directive))
9686 (defun vhdl-template-directive-translate-on ()
9687 "Insert directive 'translate_on'."
9689 (vhdl-template-directive "translate_on"))
9691 (defun vhdl-template-directive-translate-off ()
9692 "Insert directive 'translate_off'."
9694 (vhdl-template-directive "translate_off"))
9696 (defun vhdl-template-directive-synthesis-on ()
9697 "Insert directive 'synthesis_on'."
9699 (vhdl-template-directive "synthesis_on"))
9701 (defun vhdl-template-directive-synthesis-off ()
9702 "Insert directive 'synthesis_off'."
9704 (vhdl-template-directive "synthesis_off"))
9706 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9707 ;; Header and footer templates
9709 (defun vhdl-template-header (&optional file-title)
9710 "Insert a VHDL file header."
9712 (unless (equal vhdl-file-header "")
9715 (goto-char (point-min))
9716 (vhdl-insert-string-or-file vhdl-file-header)
9717 (setq pos (point-marker)))
9718 (vhdl-template-replace-header-keywords
9719 (point-min-marker) pos file-title))))
9721 (defun vhdl-template-footer ()
9722 "Insert a VHDL file footer."
9724 (unless (equal vhdl-file-footer "")
9727 (goto-char (point-max))
9728 (setq pos (point-marker))
9729 (vhdl-insert-string-or-file vhdl-file-footer)
9730 (unless (= (preceding-char) ?\n)
9732 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9734 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9736 "Replace keywords in header and footer."
9737 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9738 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9740 (vhdl-prepare-search-2
9743 (while (search-forward "<projectdesc>" end t)
9744 (replace-match project-desc t t))
9746 (while (search-forward "<filename>" end t)
9747 (replace-match (buffer-name) t t))
9749 (while (search-forward "<copyright>" end t)
9750 (replace-match vhdl-copyright-string t t))
9752 (while (search-forward "<author>" end t)
9753 (replace-match "" t t)
9754 (insert (user-full-name))
9755 (when user-mail-address (insert " <" user-mail-address ">")))
9757 (while (search-forward "<login>" end t)
9758 (replace-match (user-login-name) t t))
9760 (while (search-forward "<project>" end t)
9761 (replace-match project-title t t))
9763 (while (search-forward "<company>" end t)
9764 (replace-match vhdl-company-name t t))
9766 (while (search-forward "<platform>" end t)
9767 (replace-match vhdl-platform-spec t t))
9769 (while (search-forward "<standard>" end t)
9771 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9772 ((vhdl-standard-p '93) "'93"))
9773 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9774 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9776 ;; Replace <RCS> with $, so that RCS for the source is
9777 ;; not over-enthusiastic with replacements
9778 (while (search-forward "<RCS>" end t)
9779 (replace-match "$" nil t))
9781 (while (search-forward "<date>" end t)
9782 (replace-match "" t t)
9783 (vhdl-template-insert-date))
9785 (while (search-forward "<year>" end t)
9786 (replace-match (format-time-string "%Y" nil) t t))
9789 (while (search-forward "<title string>" end t)
9790 (replace-match file-title t t))
9794 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9795 (setq string (read-string (concat (match-string 1) ": ")))
9796 (replace-match string t t)))
9798 (when (and (not is-model) (search-forward "<cursor>" end t))
9799 (replace-match "" t t)
9800 (setq pos (point))))
9801 (when pos (goto-char pos))
9803 (when (or (not project-title) (equal project-title ""))
9804 (message "You can specify a project title in user option `vhdl-project-alist'"))
9805 (when (or (not project-desc) (equal project-desc ""))
9806 (message "You can specify a project description in user option `vhdl-project-alist'"))
9807 (when (equal vhdl-platform-spec "")
9808 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9809 (when (equal vhdl-company-name "")
9810 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9812 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9813 ;; Comment templates and functions
9815 (defun vhdl-comment-indent ()
9817 (let* ((position (point))
9821 (if (re-search-forward "--" position t)
9822 (- (current-column) 2) ; existing comment at bol stays there
9823 (goto-char position)
9824 (skip-chars-backward " \t")
9825 (max comment-column ; else indent to comment column
9826 (1+ (current-column))))))) ; except leave at least one space
9827 (goto-char position)
9830 (defun vhdl-comment-insert ()
9831 "Start a comment at the end of the line.
9832 If on line with code, indent at least `comment-column'.
9833 If starting after end-comment-column, start a new line."
9835 (when (> (current-column) end-comment-column) (newline-and-indent))
9836 (if (or (looking-at "\\s-*$") ; end of line
9837 (and (not unread-command-events) ; called with key binding or menu
9838 (not (end-of-line))))
9840 (while (= (preceding-char) ?-) (delete-char -1))
9841 (setq margin (current-column))
9842 (delete-horizontal-space)
9844 (progn (indent-to margin) (insert "--"))
9846 (indent-to comment-column)
9848 (if (not unread-command-events) (insert " ")))
9849 ;; else code following current point implies commenting out code
9850 (let (next-input code)
9851 (while (= (preceding-char) ?-) (delete-char -2))
9852 (while (= (setq next-input (read-char)) 13) ; CR
9853 (insert "--") ; or have a space after it?
9856 (message "Enter CR if commenting out a line of code.")
9859 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
9860 (setq unread-command-events
9861 (list (vhdl-character-to-event next-input)))))) ; pushback the char
9863 (defun vhdl-comment-display (&optional line-exists)
9864 "Add 2 comment lines at the current indent, making a display comment."
9866 (let ((margin (current-indentation)))
9867 (unless line-exists (vhdl-comment-display-line))
9868 (insert "\n") (indent-to margin)
9869 (insert "\n") (indent-to margin)
9870 (vhdl-comment-display-line)
9874 (defun vhdl-comment-display-line ()
9875 "Displays one line of dashes."
9877 (while (= (preceding-char) ?-) (delete-char -2))
9878 (let* ((col (current-column))
9879 (len (- end-comment-column col)))
9880 (insert-char ?- len)))
9882 (defun vhdl-comment-append-inline ()
9883 "Append empty inline comment to current line."
9886 (delete-horizontal-space)
9888 (indent-to comment-column)
9891 (defun vhdl-comment-insert-inline (&optional string always-insert)
9892 "Insert inline comment."
9893 (when (or (and string (or vhdl-self-insert-comments always-insert))
9894 (and (not string) vhdl-prompt-for-comments))
9895 (let ((position (point)))
9897 (indent-to comment-column)
9899 (if (not (or (and string (progn (insert string) t))
9900 (vhdl-template-field "[comment]" nil t)))
9901 (delete-region position (point))
9902 (while (= (preceding-char) ? ) (delete-backward-char 1))
9903 ; (when (> (current-column) end-comment-column)
9904 ; (setq position (point-marker))
9905 ; (re-search-backward "-- ")
9907 ; (indent-to comment-column)
9908 ; (goto-char position))
9911 (defun vhdl-comment-block ()
9912 "Insert comment for code block."
9913 (when vhdl-prompt-for-comments
9914 (let ((final-pos (point-marker)))
9915 (vhdl-prepare-search-2
9916 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
9917 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
9919 (back-to-indentation)
9920 (setq margin (current-column))
9923 (progn (insert "\n") (forward-line -1))
9926 (insert "-- purpose: ")
9927 (unless (vhdl-template-field "[description]" nil t)
9928 (vhdl-line-kill-entire)))))
9929 (goto-char final-pos))))
9931 (defun vhdl-comment-uncomment-region (beg end &optional arg)
9932 "Comment out region if not commented out, uncomment otherwise."
9933 (interactive "r\nP")
9935 (goto-char (1- end))
9937 (setq end (point-marker))
9941 (if (looking-at comment-start)
9942 (comment-region beg end '(4))
9943 (comment-region beg end))))
9945 (defun vhdl-comment-uncomment-line (&optional arg)
9946 "Comment out line if not commented out, uncomment otherwise."
9950 (let ((position (point)))
9951 (forward-line (or arg 1))
9952 (vhdl-comment-uncomment-region position (point)))))
9954 (defun vhdl-comment-kill-region (beg end)
9955 "Kill comments in region."
9959 (setq end (point-marker))
9962 (while (< (point) end)
9963 (if (looking-at "^\\(\\s-*--.*\n\\)")
9964 (progn (delete-region (match-beginning 1) (match-end 1)))
9965 (beginning-of-line 2)))))
9967 (defun vhdl-comment-kill-inline-region (beg end)
9968 "Kill inline comments in region."
9972 (setq end (point-marker))
9975 (while (< (point) end)
9976 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
9977 (delete-region (match-beginning 1) (match-end 1)))
9978 (beginning-of-line 2))))
9980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9983 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
9984 "Insert a begin ... end pair with optional name after the end.
9985 Point is left between them."
9987 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9989 (vhdl-insert-keyword "BEGIN")
9990 (when (and (or construct name) vhdl-self-insert-comments)
9992 (when construct (insert " ") (vhdl-insert-keyword construct))
9993 (when name (insert " " name)))
9995 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9996 (indent-to (+ margin vhdl-basic-offset))
9997 (setq position (point))
9999 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10001 (vhdl-insert-keyword "END")
10002 (when construct (insert " ") (vhdl-insert-keyword construct))
10003 (insert (if name (concat " " name) "") ";")
10004 (goto-char position)))
10006 (defun vhdl-template-argument-list (&optional is-function)
10007 "Read from user a procedure or function argument list."
10009 (let ((margin (current-column))
10012 not-empty interface semicolon-pos)
10013 (unless vhdl-argument-list-indent
10014 (setq margin (+ (current-indentation) vhdl-basic-offset))
10016 (indent-to margin))
10017 (setq interface (vhdl-template-field
10018 (concat "[CONSTANT | SIGNAL"
10019 (unless is-function " | VARIABLE") "]") " " t))
10020 (while (vhdl-template-field "[names]" nil t)
10023 (unless is-function
10024 (if (and interface (equal (upcase interface) "CONSTANT"))
10025 (vhdl-insert-keyword "IN ")
10026 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10027 (vhdl-template-field "type")
10028 (setq semicolon-pos (point))
10030 (vhdl-comment-insert-inline)
10031 (setq end-pos (point))
10034 (setq interface (vhdl-template-field
10035 (concat "[CONSTANT | SIGNAL"
10036 (unless is-function " | VARIABLE") "]") " " t)))
10037 (delete-region end-pos (point))
10038 (when semicolon-pos (goto-char semicolon-pos))
10040 (progn (delete-char 1) (insert ")"))
10041 (delete-backward-char 2))))
10043 (defun vhdl-template-generic-list (optional &optional no-value)
10044 "Read from user a generic spec argument list."
10047 (vhdl-insert-keyword "GENERIC (")
10048 (setq margin (current-column))
10049 (unless vhdl-argument-list-indent
10050 (let ((position (point)))
10051 (back-to-indentation)
10052 (setq margin (+ (current-column) vhdl-basic-offset))
10053 (goto-char position)
10055 (indent-to margin)))
10056 (let ((vhdl-generics (vhdl-template-field
10057 (concat (and optional "[") "name"
10058 (and no-value "s") (and optional "]"))
10060 (if (not vhdl-generics)
10062 (progn (vhdl-line-kill-entire) (end-of-line -0)
10063 (unless vhdl-argument-list-indent
10064 (vhdl-line-kill-entire) (end-of-line -0)))
10065 (vhdl-template-undo start (point))
10068 (let (semicolon-pos end-pos)
10069 (while vhdl-generics
10070 (vhdl-template-field "type")
10072 (progn (setq semicolon-pos (point))
10075 (unless (vhdl-template-field "[value]" nil t)
10077 (setq semicolon-pos (point))
10079 (vhdl-comment-insert-inline)
10080 (setq end-pos (point))
10083 (setq vhdl-generics (vhdl-template-field
10084 (concat "[name" (and no-value "s") "]")
10086 (delete-region end-pos (point))
10087 (goto-char semicolon-pos)
10090 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10093 (defun vhdl-template-port-list (optional)
10094 "Read from user a port spec argument list."
10095 (let ((start (point))
10096 margin vhdl-ports object)
10097 (vhdl-insert-keyword "PORT (")
10098 (setq margin (current-column))
10099 (unless vhdl-argument-list-indent
10100 (let ((position (point)))
10101 (back-to-indentation)
10102 (setq margin (+ (current-column) vhdl-basic-offset))
10103 (goto-char position)
10105 (indent-to margin)))
10106 (when (vhdl-standard-p 'ams)
10107 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10109 (setq vhdl-ports (vhdl-template-field
10110 (concat (and optional "[") "names" (and optional "]"))
10112 (if (not vhdl-ports)
10114 (progn (vhdl-line-kill-entire) (end-of-line -0)
10115 (unless vhdl-argument-list-indent
10116 (vhdl-line-kill-entire) (end-of-line -0)))
10117 (vhdl-template-undo start (point))
10120 (let (semicolon-pos end-pos)
10122 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10123 (vhdl-template-field "IN | OUT | INOUT" " "))
10124 ((equal "QUANTITY" (upcase object))
10125 (vhdl-template-field "[IN | OUT]" " " t)))
10126 (vhdl-template-field
10127 (if (and object (equal "TERMINAL" (upcase object)))
10129 (setq semicolon-pos (point))
10131 (vhdl-comment-insert-inline)
10132 (setq end-pos (point))
10135 (when (vhdl-standard-p 'ams)
10136 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10138 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10139 (delete-region end-pos (point))
10140 (goto-char semicolon-pos)
10143 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10146 (defun vhdl-template-generate-body (margin label)
10147 "Insert body for generate template."
10148 (vhdl-insert-keyword " GENERATE")
10149 ; (if (not (vhdl-standard-p '87))
10150 ; (vhdl-template-begin-end "GENERATE" label margin)
10153 (vhdl-insert-keyword "END GENERATE ")
10156 (indent-to (+ margin vhdl-basic-offset)))
10158 (defun vhdl-template-insert-date ()
10159 "Insert date in appropriate format."
10163 ;; 'american, 'european, 'scientific kept for backward compatibility
10164 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10165 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10166 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10167 (t (format-time-string vhdl-date-format nil)))))
10169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10172 (defun vhdl-electric-space (count)
10173 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10174 if in comment and past end-comment-column."
10176 (cond ((vhdl-in-comment-p)
10177 (self-insert-command count)
10178 (cond ((>= (current-column) (+ 2 end-comment-column))
10180 (skip-chars-backward "^ \t\n")
10181 (indent-new-comment-line)
10182 (skip-chars-forward "^ \t\n")
10184 ((>= (current-column) end-comment-column)
10185 (indent-new-comment-line))
10187 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10188 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10189 (vhdl-prepare-search-1
10190 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10191 (self-insert-command count))
10192 (t (self-insert-command count))))
10194 (defun vhdl-template-field (prompt &optional follow-string optional
10195 begin end is-string default)
10196 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10197 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10198 an empty string is inserted, return nil and call `vhdl-template-undo' for
10199 the region between BEGIN and END. IS-STRING indicates whether a string
10200 with double-quotes is to be inserted. DEFAULT specifies a default string."
10201 (let ((position (point))
10203 (insert "<" prompt ">")
10206 (read-from-minibuffer (concat prompt ": ")
10207 (or (and is-string '("\"\"" . 2)) default)
10208 vhdl-minibuffer-local-map)
10209 (quit (if (and optional begin end)
10211 (keyboard-quit)))))
10212 (when (or (not (equal string "")) optional)
10213 (delete-region position (point)))
10214 (when (and (equal string "") optional begin end)
10215 (vhdl-template-undo begin end)
10216 (message "Template aborted"))
10217 (unless (equal string "")
10219 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10220 vhdl-keywords-regexp)
10221 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10223 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10224 (concat "'" vhdl-attributes-regexp))
10225 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10226 vhdl-enum-values-regexp))
10227 (when (or (not (equal string "")) (not optional))
10228 (insert (or follow-string "")))
10229 (if (equal string "") nil string)))
10231 (defun vhdl-decision-query (string prompt &optional optional)
10232 "Query a decision from the user."
10233 (let ((start (point)))
10234 (when string (vhdl-insert-keyword (concat string " ")))
10236 (let ((char (read-char)))
10237 (delete-region start (point))
10238 (if (and optional (eq char ?\r))
10239 (progn (insert " ")
10241 (throw 'abort "ERROR: Template aborted"))
10244 (defun vhdl-insert-keyword (keyword)
10245 "Insert KEYWORD and adjust case."
10246 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10248 (defun vhdl-case-keyword (keyword)
10249 "Adjust case of KEYWORD."
10250 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10252 (defun vhdl-case-word (num)
10253 "Adjust case or following NUM words."
10254 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10256 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10257 "If preceeding character is part of a word or a paren then hippie-expand,
10258 else insert tab (used for word completion in VHDL minibuffer)."
10262 ((= (char-syntax (preceding-char)) ?w)
10263 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10265 (hippie-expand-only-buffers
10266 (or (and (boundp 'hippie-expand-only-buffers)
10267 hippie-expand-only-buffers)
10269 (vhdl-expand-abbrev prefix-arg)))
10270 ;; expand parenthesis
10271 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10272 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10273 (case-replace nil))
10274 (vhdl-expand-paren prefix-arg)))
10278 (defun vhdl-template-search-prompt ()
10279 "Search for left out template prompts and query again."
10281 (vhdl-prepare-search-2
10282 (when (or (re-search-forward
10283 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10284 (re-search-backward
10285 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10286 (let ((string (match-string 1)))
10288 (vhdl-template-field string)))))
10290 (defun vhdl-template-undo (begin end)
10291 "Undo aborted template by deleting region and unexpanding the keyword."
10292 (cond (vhdl-template-invoked-by-hook
10295 (delete-region begin end)
10297 (t (delete-region begin end))))
10299 (defun vhdl-insert-string-or-file (string)
10300 "Insert STRING or file contents if STRING is an existing file name."
10301 (unless (equal string "")
10303 (progn (string-match "^\\([^\n]+\\)" string)
10304 (vhdl-resolve-env-variable (match-string 1 string)))))
10305 (if (file-exists-p file-name)
10306 (forward-char (cadr (insert-file-contents file-name)))
10307 (insert string)))))
10309 (defun vhdl-beginning-of-block ()
10310 "Move cursor to the beginning of the enclosing block."
10313 (beginning-of-line)
10314 ;; search backward for block beginning or end
10315 (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\|record\\|units\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(postponed[ \t\n]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\)\\)\\>" nil t))
10316 ;; not consider subprogram declarations
10317 (or (and (match-string 5)
10320 (goto-char (match-end 5))
10321 (forward-word 1) (forward-sexp)
10322 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10324 ;; not consider configuration specifications
10325 (and (match-string 6)
10328 (vhdl-end-of-block)
10329 (beginning-of-line)
10330 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10332 ;; skip subblock if block end found
10333 (vhdl-beginning-of-block)))
10334 (when pos (goto-char pos))))
10336 (defun vhdl-end-of-block ()
10337 "Move cursor to the end of the enclosing block."
10341 ;; search forward for block beginning or end
10342 (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\|record\\|units\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(postponed[ \t\n]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\)\\)\\>" nil t))
10343 ;; not consider subprogram declarations
10344 (or (and (match-string 5)
10346 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10348 ;; not consider configuration specifications
10349 (and (match-string 6)
10352 (vhdl-end-of-block)
10353 (beginning-of-line)
10354 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10355 (not (match-string 2)))
10356 ;; skip subblock if block beginning found
10357 (vhdl-end-of-block)))
10358 (when pos (goto-char pos))))
10360 (defun vhdl-sequential-statement-p ()
10361 "Check if point is within sequential statement part."
10362 (let ((start (point)))
10364 (vhdl-prepare-search-2
10365 ;; is sequential statement if ...
10366 (and (re-search-backward "^\\s-*begin\\>" nil t)
10367 ;; ... point is between "begin" and "end" of ...
10368 (progn (vhdl-end-of-block)
10370 ;; ... a sequential block
10371 (progn (vhdl-beginning-of-block)
10372 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10374 (defun vhdl-in-argument-list-p ()
10375 "Check if within an argument list."
10377 (vhdl-prepare-search-2
10378 (or (string-match "arglist"
10379 (format "%s" (caar (vhdl-get-syntactic-context))))
10380 (progn (beginning-of-line)
10381 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10386 (defun vhdl-hooked-abbrev (func)
10387 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10388 but not if inside a comment or quote)."
10389 (if (or (vhdl-in-literal)
10392 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10397 (if (not vhdl-electric-mode)
10404 (let ((invoke-char last-command-char)
10406 (vhdl-template-invoked-by-hook t))
10407 (let ((caught (catch 'abort
10409 (when (stringp caught) (message caught)))
10410 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10411 ;; delete CR which is still in event queue
10412 (if (fboundp 'enqueue-eval-event)
10413 (enqueue-eval-event 'delete-char -1)
10414 (setq unread-command-events ; push back a delete char
10415 (list (vhdl-character-to-event ?\177))))))))
10417 (defun vhdl-template-alias-hook ()
10418 (vhdl-hooked-abbrev 'vhdl-template-alias))
10419 (defun vhdl-template-architecture-hook ()
10420 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10421 (defun vhdl-template-assert-hook ()
10422 (vhdl-hooked-abbrev 'vhdl-template-assert))
10423 (defun vhdl-template-attribute-hook ()
10424 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10425 (defun vhdl-template-block-hook ()
10426 (vhdl-hooked-abbrev 'vhdl-template-block))
10427 (defun vhdl-template-break-hook ()
10428 (vhdl-hooked-abbrev 'vhdl-template-break))
10429 (defun vhdl-template-case-hook ()
10430 (vhdl-hooked-abbrev 'vhdl-template-case))
10431 (defun vhdl-template-component-hook ()
10432 (vhdl-hooked-abbrev 'vhdl-template-component))
10433 (defun vhdl-template-instance-hook ()
10434 (vhdl-hooked-abbrev 'vhdl-template-instance))
10435 (defun vhdl-template-conditional-signal-asst-hook ()
10436 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10437 (defun vhdl-template-configuration-hook ()
10438 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10439 (defun vhdl-template-constant-hook ()
10440 (vhdl-hooked-abbrev 'vhdl-template-constant))
10441 (defun vhdl-template-disconnect-hook ()
10442 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10443 (defun vhdl-template-display-comment-hook ()
10444 (vhdl-hooked-abbrev 'vhdl-comment-display))
10445 (defun vhdl-template-else-hook ()
10446 (vhdl-hooked-abbrev 'vhdl-template-else))
10447 (defun vhdl-template-elsif-hook ()
10448 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10449 (defun vhdl-template-entity-hook ()
10450 (vhdl-hooked-abbrev 'vhdl-template-entity))
10451 (defun vhdl-template-exit-hook ()
10452 (vhdl-hooked-abbrev 'vhdl-template-exit))
10453 (defun vhdl-template-file-hook ()
10454 (vhdl-hooked-abbrev 'vhdl-template-file))
10455 (defun vhdl-template-for-hook ()
10456 (vhdl-hooked-abbrev 'vhdl-template-for))
10457 (defun vhdl-template-function-hook ()
10458 (vhdl-hooked-abbrev 'vhdl-template-function))
10459 (defun vhdl-template-generic-hook ()
10460 (vhdl-hooked-abbrev 'vhdl-template-generic))
10461 (defun vhdl-template-group-hook ()
10462 (vhdl-hooked-abbrev 'vhdl-template-group))
10463 (defun vhdl-template-library-hook ()
10464 (vhdl-hooked-abbrev 'vhdl-template-library))
10465 (defun vhdl-template-limit-hook ()
10466 (vhdl-hooked-abbrev 'vhdl-template-limit))
10467 (defun vhdl-template-if-hook ()
10468 (vhdl-hooked-abbrev 'vhdl-template-if))
10469 (defun vhdl-template-bare-loop-hook ()
10470 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10471 (defun vhdl-template-map-hook ()
10472 (vhdl-hooked-abbrev 'vhdl-template-map))
10473 (defun vhdl-template-nature-hook ()
10474 (vhdl-hooked-abbrev 'vhdl-template-nature))
10475 (defun vhdl-template-next-hook ()
10476 (vhdl-hooked-abbrev 'vhdl-template-next))
10477 (defun vhdl-template-others-hook ()
10478 (vhdl-hooked-abbrev 'vhdl-template-others))
10479 (defun vhdl-template-package-hook ()
10480 (vhdl-hooked-abbrev 'vhdl-template-package))
10481 (defun vhdl-template-port-hook ()
10482 (vhdl-hooked-abbrev 'vhdl-template-port))
10483 (defun vhdl-template-procedural-hook ()
10484 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10485 (defun vhdl-template-procedure-hook ()
10486 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10487 (defun vhdl-template-process-hook ()
10488 (vhdl-hooked-abbrev 'vhdl-template-process))
10489 (defun vhdl-template-quantity-hook ()
10490 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10491 (defun vhdl-template-report-hook ()
10492 (vhdl-hooked-abbrev 'vhdl-template-report))
10493 (defun vhdl-template-return-hook ()
10494 (vhdl-hooked-abbrev 'vhdl-template-return))
10495 (defun vhdl-template-selected-signal-asst-hook ()
10496 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10497 (defun vhdl-template-signal-hook ()
10498 (vhdl-hooked-abbrev 'vhdl-template-signal))
10499 (defun vhdl-template-subnature-hook ()
10500 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10501 (defun vhdl-template-subtype-hook ()
10502 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10503 (defun vhdl-template-terminal-hook ()
10504 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10505 (defun vhdl-template-type-hook ()
10506 (vhdl-hooked-abbrev 'vhdl-template-type))
10507 (defun vhdl-template-use-hook ()
10508 (vhdl-hooked-abbrev 'vhdl-template-use))
10509 (defun vhdl-template-variable-hook ()
10510 (vhdl-hooked-abbrev 'vhdl-template-variable))
10511 (defun vhdl-template-wait-hook ()
10512 (vhdl-hooked-abbrev 'vhdl-template-wait))
10513 (defun vhdl-template-when-hook ()
10514 (vhdl-hooked-abbrev 'vhdl-template-when))
10515 (defun vhdl-template-while-loop-hook ()
10516 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10517 (defun vhdl-template-with-hook ()
10518 (vhdl-hooked-abbrev 'vhdl-template-with))
10519 (defun vhdl-template-and-hook ()
10520 (vhdl-hooked-abbrev 'vhdl-template-and))
10521 (defun vhdl-template-or-hook ()
10522 (vhdl-hooked-abbrev 'vhdl-template-or))
10523 (defun vhdl-template-nand-hook ()
10524 (vhdl-hooked-abbrev 'vhdl-template-nand))
10525 (defun vhdl-template-nor-hook ()
10526 (vhdl-hooked-abbrev 'vhdl-template-nor))
10527 (defun vhdl-template-xor-hook ()
10528 (vhdl-hooked-abbrev 'vhdl-template-xor))
10529 (defun vhdl-template-xnor-hook ()
10530 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10531 (defun vhdl-template-not-hook ()
10532 (vhdl-hooked-abbrev 'vhdl-template-not))
10534 (defun vhdl-template-default-hook ()
10535 (vhdl-hooked-abbrev 'vhdl-template-default))
10536 (defun vhdl-template-default-indent-hook ()
10537 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10540 ;; Template insertion from completion list
10542 (defun vhdl-template-insert-construct (name)
10543 "Insert the built-in construct template with NAME."
10545 (list (let ((completion-ignore-case t))
10546 (completing-read "Construct name: "
10547 vhdl-template-construct-alist nil t))))
10548 (vhdl-template-insert-fun
10549 (cadr (assoc name vhdl-template-construct-alist))))
10551 (defun vhdl-template-insert-package (name)
10552 "Insert the built-in package template with NAME."
10554 (list (let ((completion-ignore-case t))
10555 (completing-read "Package name: "
10556 vhdl-template-package-alist nil t))))
10557 (vhdl-template-insert-fun
10558 (cadr (assoc name vhdl-template-package-alist))))
10560 (defun vhdl-template-insert-directive (name)
10561 "Insert the built-in directive template with NAME."
10563 (list (let ((completion-ignore-case t))
10564 (completing-read "Directive name: "
10565 vhdl-template-directive-alist nil t))))
10566 (vhdl-template-insert-fun
10567 (cadr (assoc name vhdl-template-directive-alist))))
10569 (defun vhdl-template-insert-fun (fun)
10570 "Call FUN to insert a built-in template."
10571 (let ((caught (catch 'abort (when fun (funcall fun)))))
10572 (when (stringp caught) (message caught))))
10575 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10577 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10579 (defun vhdl-model-insert (model-name)
10580 "Insert the user model with name MODEL-NAME."
10582 (let ((completion-ignore-case t))
10583 (list (completing-read "Model name: " vhdl-model-alist))))
10584 (indent-according-to-mode)
10585 (let ((start (point-marker))
10586 (margin (current-indentation))
10587 model position prompt string end)
10588 (vhdl-prepare-search-2
10589 (when (setq model (assoc model-name vhdl-model-alist))
10591 (beginning-of-line)
10592 (delete-horizontal-space)
10594 (vhdl-insert-string-or-file (nth 1 model))
10595 (setq end (point-marker))
10598 (beginning-of-line)
10599 (while (< (point) end)
10600 (unless (looking-at "^$")
10601 (insert-char ? margin))
10602 (beginning-of-line 2))
10605 (unless (equal "" vhdl-clock-name)
10606 (while (re-search-forward "<clock>" end t)
10607 (replace-match vhdl-clock-name)))
10610 (unless (equal "" vhdl-reset-name)
10611 (while (re-search-forward "<reset>" end t)
10612 (replace-match vhdl-reset-name)))
10613 ;; replace header prompts
10614 (vhdl-template-replace-header-keywords start end nil t)
10616 ;; query other prompts
10617 (while (re-search-forward
10618 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10619 (unless (equal "cursor" (match-string 1))
10620 (setq position (match-beginning 1))
10621 (setq prompt (match-string 1))
10623 (setq string (vhdl-template-field prompt nil t))
10624 ;; replace occurrences of same prompt
10625 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10626 (replace-match (or string "")))
10627 (goto-char position)))
10629 ;; goto final position
10630 (if (re-search-forward "<cursor>" end t)
10632 (goto-char end))))))
10634 (defun vhdl-model-defun ()
10635 "Define help and hook functions for user models."
10636 (let ((model-alist vhdl-model-alist)
10637 model-name model-keyword)
10639 ;; define functions for user models that can be invoked from menu and key
10640 ;; bindings and which themselves call `vhdl-model-insert' with the model
10641 ;; name as argument
10642 (setq model-name (nth 0 (car model-alist)))
10643 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10644 ,(concat "Insert model for \"" model-name "\".")
10646 (vhdl-model-insert ,model-name)))
10647 ;; define hooks for user models that are invoked from keyword abbrevs
10648 (setq model-keyword (nth 3 (car model-alist)))
10649 (unless (equal model-keyword "")
10651 ,(vhdl-function-name
10652 "vhdl-model" model-name "hook") ()
10653 (vhdl-hooked-abbrev
10654 ',(vhdl-function-name "vhdl-model" model-name)))))
10655 (setq model-alist (cdr model-alist)))))
10660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10661 ;;; Port translation
10662 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10664 (defvar vhdl-port-list nil
10665 "Variable to hold last port map parsed.")
10666 ;; structure: (parenthesised expression means list of such entries)
10668 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10669 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10670 ;; (lib-name pack-key))
10672 (defun vhdl-parse-string (string &optional optional)
10673 "Check that the text following point matches the regexp in STRING."
10674 (if (looking-at string)
10675 (goto-char (match-end 0))
10677 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10678 (vhdl-current-line) string)))
10681 (defun vhdl-replace-string (regexp-cons string)
10682 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10683 (vhdl-prepare-search-1
10684 (if (string-match (car regexp-cons) string)
10685 (funcall vhdl-file-name-case
10686 (replace-match (cdr regexp-cons) t nil string))
10689 (defun vhdl-parse-group-comment ()
10690 "Parse comment and empty lines between groups of lines."
10691 (let ((start (point))
10693 (vhdl-forward-comment (point-max))
10694 (setq string (buffer-substring-no-properties start (point)))
10695 ;; strip off leading blanks and first newline
10696 (while (string-match "^\\(\\s-+\\)" string)
10697 (setq string (concat (substring string 0 (match-beginning 1))
10698 (substring string (match-end 1)))))
10699 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10700 (substring string 1)
10703 (defun vhdl-paste-group-comment (string indent)
10704 "Paste comment and empty lines from STRING between groups of lines
10706 (let ((pos (point-marker)))
10708 (while (string-match "^\\(--\\)" string)
10709 (setq string (concat (substring string 0 (match-beginning 1))
10710 (make-string indent ? )
10711 (substring string (match-beginning 1))))))
10712 (beginning-of-line)
10716 (defvar vhdl-port-flattened nil
10717 "Indicates whether a port has been flattened.")
10719 (defun vhdl-port-flatten (&optional as-alist)
10720 "Flatten port list so that only one generic/port exists per line."
10722 (if (not vhdl-port-list)
10723 (error "ERROR: No port has been read")
10724 (message "Flattening port...")
10725 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10726 (old-vhdl-port-list (cdr vhdl-port-list))
10727 old-port-list new-port-list old-port new-port names)
10728 ;; traverse port list and flatten entries
10729 (while (cdr old-vhdl-port-list)
10730 (setq old-port-list (car old-vhdl-port-list))
10731 (setq new-port-list nil)
10732 (while old-port-list
10733 (setq old-port (car old-port-list))
10734 (setq names (car old-port))
10736 (setq new-port (cons (if as-alist (car names) (list (car names)))
10738 (setq new-port-list (append new-port-list (list new-port)))
10739 (setq names (cdr names)))
10740 (setq old-port-list (cdr old-port-list)))
10741 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10742 (setq new-vhdl-port-list (append new-vhdl-port-list
10743 (list new-port-list))))
10744 (setq vhdl-port-list
10745 (append new-vhdl-port-list (list old-vhdl-port-list))
10746 vhdl-port-flattened t)
10747 (message "Flattening port...done"))))
10749 (defvar vhdl-port-reversed-direction nil
10750 "Indicates whether port directions are reversed.")
10752 (defun vhdl-port-reverse-direction ()
10753 "Reverse direction for all ports (useful in testbenches)."
10755 (if (not vhdl-port-list)
10756 (error "ERROR: No port has been read")
10757 (message "Reversing port directions...")
10758 (let ((port-list (nth 2 vhdl-port-list))
10759 port-dir-car port-dir)
10760 ;; traverse port list and reverse directions
10762 (setq port-dir-car (cddr (car port-list))
10763 port-dir (car port-dir-car))
10764 (setcar port-dir-car
10765 (cond ((equal port-dir "in") "out")
10766 ((equal port-dir "out") "in")
10768 (setq port-list (cdr port-list)))
10769 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10770 (message "Reversing port directions...done"))))
10772 (defun vhdl-port-copy ()
10773 "Get generic and port information from an entity or component declaration."
10776 (let (parse-error end-of-list
10777 decl-type name generic-list port-list context-clause
10778 object names direct type init comment group-comment)
10779 (vhdl-prepare-search-2
10783 ;; check if within entity or component declaration
10785 (when (or (not (re-search-backward
10786 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10787 (equal "END" (upcase (match-string 1))))
10788 (throw 'parse "ERROR: Not within an entity or component declaration"))
10789 (setq decl-type (downcase (match-string-no-properties 1)))
10791 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10792 (setq name (match-string-no-properties 1))
10793 (message "Reading port of %s \"%s\"..." decl-type name)
10794 (vhdl-forward-syntactic-ws)
10795 ;; parse generic clause
10796 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10797 ;; parse group comment and spacing
10798 (setq group-comment (vhdl-parse-group-comment))
10799 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10800 (while (not end-of-list)
10802 (vhdl-parse-string "\\(\\w+\\)[ \t\n]*")
10803 (setq names (list (match-string-no-properties 1)))
10804 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
10806 (append names (list (match-string-no-properties 1)))))
10808 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
10809 (setq type (match-string-no-properties 1))
10811 (while (looking-at "(")
10814 (buffer-substring-no-properties
10815 (point) (progn (forward-sexp) (point)))
10816 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
10817 (match-string-no-properties 1)))))
10818 ;; special case: closing parenthesis is on separate line
10819 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10820 (setq comment (substring type (match-beginning 2)))
10821 (setq type (substring type 0 (match-beginning 1))))
10822 ;; strip of trailing group-comment
10823 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10824 (setq type (substring type 0 (match-end 1)))
10825 ;; parse initialization expression
10827 (when (vhdl-parse-string ":=[ \t\n]*" t)
10828 (vhdl-parse-string "\\([^();\n]*\\)")
10829 (setq init (match-string-no-properties 1))
10830 (while (looking-at "(")
10833 (buffer-substring-no-properties
10834 (point) (progn (forward-sexp) (point)))
10835 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10836 (match-string-no-properties 1))))))
10837 ;; special case: closing parenthesis is on separate line
10838 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10839 (setq comment (substring init (match-beginning 2)))
10840 (setq init (substring init 0 (match-beginning 1)))
10841 (vhdl-forward-syntactic-ws))
10842 (skip-chars-forward " \t")
10843 ;; parse inline comment, special case: as above, no initial.
10845 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10846 (match-string-no-properties 1))))
10847 (vhdl-forward-syntactic-ws)
10848 (setq end-of-list (vhdl-parse-string ")" t))
10849 (vhdl-parse-string "\\s-*;\\s-*")
10850 ;; parse inline comment
10852 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10853 (match-string-no-properties 1))))
10854 ;; save everything in list
10855 (setq generic-list (append generic-list
10856 (list (list names type init
10857 comment group-comment))))
10858 ;; parse group comment and spacing
10859 (setq group-comment (vhdl-parse-group-comment))))
10860 ;; parse port clause
10861 (when (vhdl-parse-string "port[ \t\n]*(" t)
10862 ;; parse group comment and spacing
10863 (setq group-comment (vhdl-parse-group-comment))
10864 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10865 (while (not end-of-list)
10868 (and (vhdl-parse-string "\\(signal\\|quantity\\|terminal\\)[ \t\n]*" t)
10869 (match-string-no-properties 1)))
10870 ;; parse names (accept extended identifiers)
10871 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10872 (setq names (list (match-string-no-properties 1)))
10873 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
10874 (setq names (append names (list (match-string-no-properties 1)))))
10876 (vhdl-parse-string ":[ \t\n]*")
10878 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
10879 (match-string-no-properties 1)))
10881 (vhdl-parse-string "\\([^();\n]+\\)")
10882 (setq type (match-string-no-properties 1))
10884 (while (looking-at "(")
10885 (setq type (concat type
10886 (buffer-substring-no-properties
10887 (point) (progn (forward-sexp) (point)))
10888 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10889 (match-string-no-properties 1)))))
10890 ;; special case: closing parenthesis is on separate line
10891 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10892 (setq comment (substring type (match-beginning 2)))
10893 (setq type (substring type 0 (match-beginning 1))))
10894 ;; strip of trailing group-comment
10895 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10896 (setq type (substring type 0 (match-end 1)))
10897 (vhdl-forward-syntactic-ws)
10898 (setq end-of-list (vhdl-parse-string ")" t))
10899 (vhdl-parse-string "\\s-*;\\s-*")
10900 ;; parse inline comment
10902 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10903 (match-string-no-properties 1))))
10904 ;; save everything in list
10905 (setq port-list (append port-list
10906 (list (list names object direct type
10907 comment group-comment))))
10908 ;; parse group comment and spacing
10909 (setq group-comment (vhdl-parse-group-comment))))
10910 ; (vhdl-parse-string "end\\>")
10911 ;; parse context clause
10912 (setq context-clause (vhdl-scan-context-clause))
10913 ; ;; add surrounding package to context clause
10914 ; (when (and (equal decl-type "component")
10915 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
10916 ; (setq context-clause
10917 ; (append context-clause
10918 ; (list (cons (vhdl-work-library)
10919 ; (match-string-no-properties 1))))))
10920 (message "Reading port of %s \"%s\"...done" decl-type name)
10924 (error parse-error)
10925 (setq vhdl-port-list (list name generic-list port-list context-clause)
10926 vhdl-port-reversed-direction nil
10927 vhdl-port-flattened nil)))))
10929 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
10930 "Paste a context clause."
10931 (let ((margin (current-indentation))
10932 (clause-list (nth 3 vhdl-port-list))
10935 (setq clause (car clause-list))
10936 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
10937 (downcase exclude-pack-name)))
10939 (re-search-backward
10940 (concat "^\\s-*use\\s-+" (car clause)
10941 "\." (cdr clause) "\\>") nil t)))
10942 (vhdl-template-standard-package (car clause) (cdr clause))
10944 (setq clause-list (cdr clause-list)))))
10946 (defun vhdl-port-paste-generic (&optional no-init)
10947 "Paste a generic clause."
10948 (let ((margin (current-indentation))
10949 (generic-list (nth 1 vhdl-port-list))
10950 list-margin start names generic)
10951 ;; paste generic clause
10953 (setq start (point))
10954 (vhdl-insert-keyword "GENERIC (")
10955 (unless vhdl-argument-list-indent
10956 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10957 (setq list-margin (current-column))
10958 (while generic-list
10959 (setq generic (car generic-list))
10960 ;; paste group comment and spacing
10961 (when (memq vhdl-include-group-comments '(decl always))
10962 (vhdl-paste-group-comment (nth 4 generic) list-margin))
10964 (setq names (nth 0 generic))
10966 (insert (car names))
10967 (setq names (cdr names))
10968 (when names (insert ", ")))
10970 (insert " : " (nth 1 generic))
10971 ;; paste initialization
10972 (when (and (not no-init) (nth 2 generic))
10973 (insert " := " (nth 2 generic)))
10974 (unless (cdr generic-list) (insert ")"))
10977 (when (and vhdl-include-port-comments (nth 3 generic))
10978 (vhdl-comment-insert-inline (nth 3 generic) t))
10979 (setq generic-list (cdr generic-list))
10980 (when generic-list (insert "\n") (indent-to list-margin)))
10981 ;; align generic clause
10982 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
10984 (defun vhdl-port-paste-port ()
10985 "Paste a port clause."
10986 (let ((margin (current-indentation))
10987 (port-list (nth 2 vhdl-port-list))
10988 list-margin start names port)
10989 ;; paste port clause
10991 (setq start (point))
10992 (vhdl-insert-keyword "PORT (")
10993 (unless vhdl-argument-list-indent
10994 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10995 (setq list-margin (current-column))
10997 (setq port (car port-list))
10998 ;; paste group comment and spacing
10999 (when (memq vhdl-include-group-comments '(decl always))
11000 (vhdl-paste-group-comment (nth 5 port) list-margin))
11002 (when (nth 1 port) (insert (nth 1 port) " "))
11004 (setq names (nth 0 port))
11006 (insert (car names))
11007 (setq names (cdr names))
11008 (when names (insert ", ")))
11011 (when (nth 2 port) (insert (nth 2 port) " "))
11013 (insert (nth 3 port))
11014 (unless (cdr port-list) (insert ")"))
11017 (when (and vhdl-include-port-comments (nth 4 port))
11018 (vhdl-comment-insert-inline (nth 4 port) t))
11019 (setq port-list (cdr port-list))
11020 (when port-list (insert "\n") (indent-to list-margin)))
11021 ;; align port clause
11022 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11024 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11025 "Paste as an entity or component declaration."
11026 (unless no-indent (indent-according-to-mode))
11027 (let ((margin (current-indentation))
11028 (name (nth 0 vhdl-port-list)))
11029 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11031 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11032 (vhdl-insert-keyword " IS"))
11033 ;; paste generic and port clause
11034 (when (nth 1 vhdl-port-list)
11036 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11038 (indent-to (+ margin vhdl-basic-offset))
11039 (vhdl-port-paste-generic (eq kind 'component)))
11040 (when (nth 2 vhdl-port-list)
11042 (when (and (memq vhdl-insert-empty-lines '(unit all))
11045 (indent-to (+ margin vhdl-basic-offset)))
11046 (vhdl-port-paste-port)
11048 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11051 (vhdl-insert-keyword "END")
11052 (if (eq kind 'entity)
11054 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11056 (vhdl-insert-keyword " COMPONENT")
11057 (unless (vhdl-standard-p '87) (insert " " name)))
11060 (defun vhdl-port-paste-entity (&optional no-indent)
11061 "Paste as an entity declaration."
11063 (if (not vhdl-port-list)
11064 (error "ERROR: No port read")
11065 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11066 (vhdl-port-paste-declaration 'entity no-indent)
11067 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11069 (defun vhdl-port-paste-component (&optional no-indent)
11070 "Paste as a component declaration."
11072 (if (not vhdl-port-list)
11073 (error "ERROR: No port read")
11074 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11075 (vhdl-port-paste-declaration 'component no-indent)
11076 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11078 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11079 "Paste as a generic map."
11081 (unless secondary (indent-according-to-mode))
11082 (let ((margin (current-indentation))
11083 list-margin start generic
11084 (generic-list (nth 1 vhdl-port-list)))
11086 (setq start (point))
11087 (vhdl-insert-keyword "GENERIC MAP (")
11088 (if (not vhdl-association-list-with-formals)
11089 ;; paste list of actual generics
11090 (while generic-list
11091 (insert (if no-constants
11092 (car (nth 0 (car generic-list)))
11093 (or (nth 2 (car generic-list)) " ")))
11094 (setq generic-list (cdr generic-list))
11095 (insert (if generic-list ", " ")")))
11096 (unless vhdl-argument-list-indent
11097 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11098 (setq list-margin (current-column))
11099 (while generic-list
11100 (setq generic (car generic-list))
11101 ;; paste group comment and spacing
11102 (when (eq vhdl-include-group-comments 'always)
11103 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11104 ;; paste formal and actual generic
11105 (insert (car (nth 0 generic)) " => "
11107 (car (nth 0 generic))
11108 (or (nth 2 generic) "")))
11109 (setq generic-list (cdr generic-list))
11110 (insert (if generic-list "," ")"))
11112 (when (or vhdl-include-type-comments
11113 (and vhdl-include-port-comments (nth 3 generic)))
11114 (vhdl-comment-insert-inline
11116 (when vhdl-include-type-comments
11117 (concat "[" (nth 1 generic) "] "))
11118 (when vhdl-include-port-comments (nth 3 generic))) t))
11119 (when generic-list (insert "\n") (indent-to list-margin)))
11120 ;; align generic map
11121 (when vhdl-auto-align
11122 (vhdl-align-region-groups start (point) 1 t))))))
11124 (defun vhdl-port-paste-port-map ()
11125 "Paste as a port map."
11126 (let ((margin (current-indentation))
11127 list-margin start port
11128 (port-list (nth 2 vhdl-port-list)))
11130 (setq start (point))
11131 (vhdl-insert-keyword "PORT MAP (")
11132 (if (not vhdl-association-list-with-formals)
11133 ;; paste list of actual ports
11135 (insert (vhdl-replace-string vhdl-actual-port-name
11136 (car (nth 0 (car port-list)))))
11137 (setq port-list (cdr port-list))
11138 (insert (if port-list ", " ");")))
11139 (unless vhdl-argument-list-indent
11140 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11141 (setq list-margin (current-column))
11143 (setq port (car port-list))
11144 ;; paste group comment and spacing
11145 (when (eq vhdl-include-group-comments 'always)
11146 (vhdl-paste-group-comment (nth 5 port) list-margin))
11147 ;; paste formal and actual port
11148 (insert (car (nth 0 port)) " => ")
11149 (insert (vhdl-replace-string vhdl-actual-port-name
11150 (car (nth 0 port))))
11151 (setq port-list (cdr port-list))
11152 (insert (if port-list "," ");"))
11154 (when (or vhdl-include-direction-comments
11155 vhdl-include-type-comments
11156 (and vhdl-include-port-comments (nth 4 port)))
11157 (vhdl-comment-insert-inline
11159 (cond ((and vhdl-include-direction-comments
11160 vhdl-include-type-comments)
11161 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11162 (nth 3 port) "] "))
11163 ((and vhdl-include-direction-comments (nth 2 port))
11164 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11165 (vhdl-include-direction-comments " ")
11166 (vhdl-include-type-comments
11167 (concat "[" (nth 3 port) "] ")))
11168 (when vhdl-include-port-comments (nth 4 port))) t))
11169 (when port-list (insert "\n") (indent-to list-margin)))
11170 ;; align port clause
11171 (when vhdl-auto-align
11172 (vhdl-align-region-groups start (point) 1))))))
11174 (defun vhdl-port-paste-instance (&optional name no-indent title)
11175 "Paste as an instantiation."
11177 (if (not vhdl-port-list)
11178 (error "ERROR: No port read")
11179 (let ((orig-vhdl-port-list vhdl-port-list))
11180 ;; flatten local copy of port list (must be flat for port mapping)
11181 (vhdl-port-flatten)
11182 (unless no-indent (indent-according-to-mode))
11183 (let ((margin (current-indentation)))
11184 ;; paste instantiation
11187 ((equal (cdr vhdl-instance-name) "")
11188 (setq name (vhdl-template-field "instance name")))
11189 ((string-match "\%d" (cdr vhdl-instance-name))
11191 (while (save-excursion
11192 (setq name (format (vhdl-replace-string
11194 (nth 0 vhdl-port-list)) n))
11195 (goto-char (point-min))
11196 (vhdl-re-search-forward name nil t))
11199 (t (insert (vhdl-replace-string vhdl-instance-name
11200 (nth 0 vhdl-port-list)))))
11201 (message "Pasting port as instantiation \"%s\"..." name)
11205 (beginning-of-line)
11206 (indent-to vhdl-basic-offset)
11207 (insert "-- instance \"" name "\"\n")))
11208 (if (not (vhdl-use-direct-instantiation))
11209 (insert (nth 0 vhdl-port-list))
11210 (vhdl-insert-keyword "ENTITY ")
11211 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11212 (when (nth 1 vhdl-port-list)
11213 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11214 (vhdl-port-paste-generic-map t t))
11215 (when (nth 2 vhdl-port-list)
11216 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11217 (vhdl-port-paste-port-map))
11218 (message "Pasting port as instantiation \"%s\"...done" name))
11219 (setq vhdl-port-list orig-vhdl-port-list))))
11221 (defun vhdl-port-paste-constants (&optional no-indent)
11222 "Paste generics as constants."
11224 (if (not vhdl-port-list)
11225 (error "ERROR: No port read")
11226 (let ((orig-vhdl-port-list vhdl-port-list))
11227 (message "Pasting port as constants...")
11228 ;; flatten local copy of port list (must be flat for constant initial.)
11229 (vhdl-port-flatten)
11230 (unless no-indent (indent-according-to-mode))
11231 (let ((margin (current-indentation))
11233 (generic-list (nth 1 vhdl-port-list)))
11235 (setq start (point))
11236 (while generic-list
11237 (setq generic (car generic-list))
11238 ;; paste group comment and spacing
11239 (when (memq vhdl-include-group-comments '(decl always))
11240 (vhdl-paste-group-comment (nth 4 generic) margin))
11241 (vhdl-insert-keyword "CONSTANT ")
11242 ;; paste generic constants
11243 (setq name (nth 0 generic))
11245 (insert (car name))
11247 (insert " : " (nth 1 generic))
11248 ;; paste initialization
11249 (when (nth 2 generic)
11250 (insert " := " (nth 2 generic)))
11253 (when (and vhdl-include-port-comments (nth 3 generic))
11254 (vhdl-comment-insert-inline (nth 3 generic) t))
11255 (setq generic-list (cdr generic-list))
11256 (when generic-list (insert "\n") (indent-to margin))))
11257 ;; align signal list
11258 (when vhdl-auto-align
11259 (vhdl-align-region-groups start (point) 1))))
11260 (message "Pasting port as constants...done")
11261 (setq vhdl-port-list orig-vhdl-port-list))))
11263 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11264 "Paste ports as internal signals."
11266 (if (not vhdl-port-list)
11267 (error "ERROR: No port read")
11268 (message "Pasting port as signals...")
11269 (unless no-indent (indent-according-to-mode))
11270 (let ((margin (current-indentation))
11272 (port-list (nth 2 vhdl-port-list)))
11274 (setq start (point))
11276 (setq port (car port-list))
11277 ;; paste group comment and spacing
11278 (when (memq vhdl-include-group-comments '(decl always))
11279 (vhdl-paste-group-comment (nth 5 port) margin))
11282 (insert (nth 1 port) " ")
11283 (vhdl-insert-keyword "SIGNAL "))
11284 ;; paste actual port signals
11285 (setq names (nth 0 port))
11287 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11288 (setq names (cdr names))
11289 (when names (insert ", ")))
11291 (insert " : " (nth 3 port))
11292 ;; paste initialization (inputs only)
11293 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11294 (insert " := " (if (string-match "(.+)" (nth 3 port))
11295 "(others => '0')" "'0'")))
11298 (when (or vhdl-include-direction-comments
11299 (and vhdl-include-port-comments (nth 4 port)))
11300 (vhdl-comment-insert-inline
11302 (cond ((and vhdl-include-direction-comments (nth 2 port))
11303 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11304 (vhdl-include-direction-comments " "))
11305 (when vhdl-include-port-comments (nth 4 port))) t))
11306 (setq port-list (cdr port-list))
11307 (when port-list (insert "\n") (indent-to margin)))
11308 ;; align signal list
11309 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11310 (message "Pasting port as signals...done")))
11312 (defun vhdl-port-paste-initializations (&optional no-indent)
11313 "Paste ports as signal initializations."
11315 (if (not vhdl-port-list)
11316 (error "ERROR: No port read")
11317 (let ((orig-vhdl-port-list vhdl-port-list))
11318 (message "Pasting port as initializations...")
11319 ;; flatten local copy of port list (must be flat for signal initial.)
11320 (vhdl-port-flatten)
11321 (unless no-indent (indent-according-to-mode))
11322 (let ((margin (current-indentation))
11324 (port-list (nth 2 vhdl-port-list)))
11326 (setq start (point))
11328 (setq port (car port-list))
11329 ;; paste actual port signal (inputs only)
11330 (when (equal "IN" (upcase (nth 2 port)))
11331 (setq name (car (nth 0 port)))
11332 (insert (vhdl-replace-string vhdl-actual-port-name name))
11333 ;; paste initialization
11334 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11335 "(others => '0')" "'0'") ";"))
11336 (setq port-list (cdr port-list))
11337 (when (and port-list
11338 (equal "IN" (upcase (nth 2 (car port-list)))))
11339 (insert "\n") (indent-to margin)))
11340 ;; align signal list
11341 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11342 (message "Pasting port as initializations...done")
11343 (setq vhdl-port-list orig-vhdl-port-list))))
11345 (defun vhdl-port-paste-testbench ()
11346 "Paste as a bare-bones testbench."
11348 (if (not vhdl-port-list)
11349 (error "ERROR: No port read")
11350 (let ((case-fold-search t)
11351 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11352 (nth 0 vhdl-port-list)))
11353 (source-buffer (current-buffer))
11354 arch-name config-name ent-file-name arch-file-name
11355 ent-buffer arch-buffer position)
11356 ;; open entity file
11357 (unless (eq vhdl-testbench-create-files 'none)
11358 (setq ent-file-name
11359 (concat ent-name "." (file-name-extension (buffer-file-name))))
11360 (if (file-exists-p ent-file-name)
11362 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11363 (progn (find-file ent-file-name)
11365 (set-buffer-modified-p nil))
11366 (if (eq vhdl-testbench-create-files 'separate)
11367 (setq ent-file-name nil)
11368 (error "ERROR: Pasting port as testbench...aborted")))
11369 (find-file ent-file-name)))
11370 (unless (and (eq vhdl-testbench-create-files 'separate)
11371 (null ent-file-name))
11372 ;; paste entity header
11373 (if vhdl-testbench-include-header
11374 (progn (vhdl-template-header
11375 (concat "Testbench for design \""
11376 (nth 0 vhdl-port-list) "\""))
11377 (goto-char (point-max)))
11378 (vhdl-comment-display-line) (insert "\n\n"))
11379 ;; paste std_logic_1164 package
11380 (when vhdl-testbench-include-library
11381 (vhdl-template-package-std-logic-1164)
11382 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11383 ;; paste entity declaration
11384 (vhdl-insert-keyword "ENTITY ")
11386 (vhdl-insert-keyword " IS")
11387 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11389 (vhdl-insert-keyword "END ")
11390 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11391 (insert ent-name ";")
11393 (vhdl-comment-display-line) (insert "\n"))
11394 ;; get architecture name
11395 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11396 (read-from-minibuffer "architecture name: "
11397 nil vhdl-minibuffer-local-map)
11398 (vhdl-replace-string vhdl-testbench-architecture-name
11399 (nth 0 vhdl-port-list))))
11400 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11401 ;; open architecture file
11402 (if (not (eq vhdl-testbench-create-files 'separate))
11404 (setq ent-buffer (current-buffer))
11405 (setq arch-file-name
11406 (concat ent-name "_" arch-name "."
11407 (file-name-extension (buffer-file-name))))
11408 (when (and (file-exists-p arch-file-name)
11409 (not (y-or-n-p (concat "File \"" arch-file-name
11410 "\" exists; overwrite? "))))
11411 (error "ERROR: Pasting port as testbench...aborted"))
11412 (find-file arch-file-name)
11414 (set-buffer-modified-p nil)
11415 ;; paste architecture header
11416 (if vhdl-testbench-include-header
11417 (progn (vhdl-template-header
11418 (concat "Testbench architecture for design \""
11419 (nth 0 vhdl-port-list) "\""))
11420 (goto-char (point-max)))
11421 (vhdl-comment-display-line) (insert "\n\n")))
11422 ;; paste architecture body
11423 (vhdl-insert-keyword "ARCHITECTURE ")
11425 (vhdl-insert-keyword " OF ")
11427 (vhdl-insert-keyword " IS")
11428 (insert "\n\n") (indent-to vhdl-basic-offset)
11429 ;; paste component declaration
11430 (unless (vhdl-use-direct-instantiation)
11431 (vhdl-port-paste-component t)
11432 (insert "\n\n") (indent-to vhdl-basic-offset))
11434 (when (nth 1 vhdl-port-list)
11435 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11436 (vhdl-port-paste-constants t)
11437 (insert "\n\n") (indent-to vhdl-basic-offset))
11438 ;; paste internal signals
11439 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11440 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11442 ;; paste custom declarations
11443 (unless (equal "" vhdl-testbench-declarations)
11445 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11446 (setq position (point))
11448 (vhdl-comment-display-line) (insert "\n")
11449 (when vhdl-testbench-include-configuration
11450 (setq config-name (vhdl-replace-string
11451 vhdl-testbench-configuration-name
11452 (concat ent-name " " arch-name)))
11454 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11455 (vhdl-insert-keyword " OF ") (insert ent-name)
11456 (vhdl-insert-keyword " IS\n")
11457 (indent-to vhdl-basic-offset)
11458 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11459 (indent-to vhdl-basic-offset)
11460 (vhdl-insert-keyword "END FOR;\n")
11461 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11462 (vhdl-comment-display-line) (insert "\n"))
11463 (goto-char position)
11464 (vhdl-template-begin-end
11465 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11466 ;; paste instantiation
11467 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11468 (vhdl-port-paste-instance
11469 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11471 ;; paste custom statements
11472 (unless (equal "" vhdl-testbench-statements)
11474 (vhdl-insert-string-or-file vhdl-testbench-statements))
11476 (indent-to vhdl-basic-offset)
11477 (unless (eq vhdl-testbench-create-files 'none)
11478 (setq arch-buffer (current-buffer))
11479 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11480 (set-buffer arch-buffer) (save-buffer))
11482 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11483 ent-name arch-name)
11485 (format "\n File created: \"%s\"" ent-file-name))
11486 (and arch-file-name
11487 (format "\n File created: \"%s\"" arch-file-name)))))))
11490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11491 ;;; Subprogram interface translation
11492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11494 (defvar vhdl-subprog-list nil
11495 "Variable to hold last subprogram interface parsed.")
11496 ;; structure: (parenthesised expression means list of such entries)
11497 ;; (subprog-name kind
11498 ;; ((names) object direct type init comment group-comment)
11499 ;; return-type return-comment group-comment)
11501 (defvar vhdl-subprog-flattened nil
11502 "Indicates whether an subprogram interface has been flattened.")
11504 (defun vhdl-subprog-flatten ()
11505 "Flatten interface list so that only one parameter exists per line."
11507 (if (not vhdl-subprog-list)
11508 (error "ERROR: No subprogram interface has been read")
11509 (message "Flattening subprogram interface...")
11510 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11511 new-subprog-list old-subprog new-subprog names)
11512 ;; traverse parameter list and flatten entries
11513 (while old-subprog-list
11514 (setq old-subprog (car old-subprog-list))
11515 (setq names (car old-subprog))
11517 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11518 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11519 (setq names (cdr names)))
11520 (setq old-subprog-list (cdr old-subprog-list)))
11521 (setq vhdl-subprog-list
11522 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11523 new-subprog-list (nth 3 vhdl-subprog-list)
11524 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11525 vhdl-subprog-flattened t)
11526 (message "Flattening subprogram interface...done"))))
11528 (defun vhdl-subprog-copy ()
11529 "Get interface information from a subprogram specification."
11532 (let (parse-error pos end-of-list
11533 name kind param-list object names direct type init
11534 comment group-comment
11535 return-type return-comment return-group-comment)
11536 (vhdl-prepare-search-2
11540 ;; check if within function declaration
11543 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11544 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11545 (goto-char (match-end 0))
11546 (save-excursion (backward-char)
11549 (throw 'parse "ERROR: Not within a subprogram specification"))
11550 (setq name (match-string-no-properties 5))
11551 (setq kind (if (match-string 2) 'procedure 'function))
11552 (setq end-of-list (not (match-string 7)))
11553 (message "Reading interface of subprogram \"%s\"..." name)
11554 ;; parse parameter list
11555 (setq group-comment (vhdl-parse-group-comment))
11556 (setq end-of-list (or end-of-list
11557 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11558 (while (not end-of-list)
11561 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11562 (match-string-no-properties 1)))
11563 ;; parse names (accept extended identifiers)
11564 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11565 (setq names (list (match-string-no-properties 1)))
11566 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11567 (setq names (append names (list (match-string-no-properties 1)))))
11569 (vhdl-parse-string ":[ \t\n]*")
11571 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11572 (match-string-no-properties 1)))
11574 (vhdl-parse-string "\\([^():;\n]+\\)")
11575 (setq type (match-string-no-properties 1))
11577 (while (looking-at "(")
11580 (buffer-substring-no-properties
11581 (point) (progn (forward-sexp) (point)))
11582 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11583 (match-string-no-properties 1)))))
11584 ;; special case: closing parenthesis is on separate line
11585 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11586 (setq comment (substring type (match-beginning 2)))
11587 (setq type (substring type 0 (match-beginning 1))))
11588 ;; strip off trailing group-comment
11589 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11590 (setq type (substring type 0 (match-end 1)))
11591 ;; parse initialization expression
11593 (when (vhdl-parse-string ":=[ \t\n]*" t)
11594 (vhdl-parse-string "\\([^();\n]*\\)")
11595 (setq init (match-string-no-properties 1))
11596 (while (looking-at "(")
11599 (buffer-substring-no-properties
11600 (point) (progn (forward-sexp) (point)))
11601 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11602 (match-string-no-properties 1))))))
11603 ;; special case: closing parenthesis is on separate line
11604 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11605 (setq comment (substring init (match-beginning 2)))
11606 (setq init (substring init 0 (match-beginning 1)))
11607 (vhdl-forward-syntactic-ws))
11608 (skip-chars-forward " \t")
11609 ;; parse inline comment, special case: as above, no initial.
11611 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11612 (match-string-no-properties 1))))
11613 (vhdl-forward-syntactic-ws)
11614 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11615 ;; parse inline comment
11617 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11618 (match-string-no-properties 1))))
11619 (setq return-group-comment (vhdl-parse-group-comment))
11620 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11621 ;; parse return type
11622 (when (match-string 3)
11623 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11624 (setq return-type (match-string-no-properties 1))
11625 (when (and return-type
11626 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11627 (setq return-comment (substring return-type (match-beginning 2)))
11628 (setq return-type (substring return-type 0 (match-beginning 1))))
11629 ;; strip of trailing group-comment
11630 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11631 (setq return-type (substring return-type 0 (match-end 1)))
11632 ;; parse return comment
11633 (unless return-comment
11634 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11635 (match-string-no-properties 1)))))
11636 ;; parse inline comment
11638 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11639 (match-string-no-properties 1))))
11640 ;; save everything in list
11641 (setq param-list (append param-list
11642 (list (list names object direct type init
11643 comment group-comment))))
11644 ;; parse group comment and spacing
11645 (setq group-comment (vhdl-parse-group-comment)))
11646 (message "Reading interface of subprogram \"%s\"...done" name)
11650 (error parse-error)
11651 (setq vhdl-subprog-list
11652 (list name kind param-list return-type return-comment
11653 return-group-comment)
11654 vhdl-subprog-flattened nil)))))
11656 (defun vhdl-subprog-paste-specification (kind)
11657 "Paste as a subprogram specification."
11658 (indent-according-to-mode)
11659 (let ((margin (current-column))
11660 (param-list (nth 2 vhdl-subprog-list))
11661 list-margin start names param)
11662 ;; paste keyword and name
11663 (vhdl-insert-keyword
11664 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11665 (insert (nth 0 vhdl-subprog-list))
11666 (if (not param-list)
11667 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11668 (setq start (point))
11669 ;; paste parameter list
11671 (unless vhdl-argument-list-indent
11672 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11673 (setq list-margin (current-column))
11675 (setq param (car param-list))
11676 ;; paste group comment and spacing
11677 (when (memq vhdl-include-group-comments (list kind 'always))
11678 (vhdl-paste-group-comment (nth 6 param) list-margin))
11680 (when (nth 1 param) (insert (nth 1 param) " "))
11682 (setq names (nth 0 param))
11684 (insert (car names))
11685 (setq names (cdr names))
11686 (when names (insert ", ")))
11689 (when (nth 2 param) (insert (nth 2 param) " "))
11691 (insert (nth 3 param))
11692 ;; paste initialization
11693 (when (nth 4 param) (insert " := " (nth 4 param)))
11695 (if (cdr param-list)
11698 (when (null (nth 3 vhdl-subprog-list))
11699 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11701 (when (and vhdl-include-port-comments (nth 5 param))
11702 (vhdl-comment-insert-inline (nth 5 param) t))
11703 (setq param-list (cdr param-list))
11704 (when param-list (insert "\n") (indent-to list-margin)))
11705 (when (nth 3 vhdl-subprog-list)
11706 (insert "\n") (indent-to list-margin)
11707 ;; paste group comment and spacing
11708 (when (memq vhdl-include-group-comments (list kind 'always))
11709 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11710 ;; paste return type
11711 (insert "return " (nth 3 vhdl-subprog-list))
11712 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11713 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11714 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11715 ;; align parameter list
11716 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11718 (when (eq kind 'body)
11720 (vhdl-template-begin-end
11721 (unless (vhdl-standard-p '87)
11722 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11723 (nth 0 vhdl-subprog-list) margin))))
11725 (defun vhdl-subprog-paste-declaration ()
11726 "Paste as a subprogram declaration."
11728 (if (not vhdl-subprog-list)
11729 (error "ERROR: No subprogram interface read")
11730 (message "Pasting interface as subprogram declaration \"%s\"..."
11731 (car vhdl-subprog-list))
11732 ;; paste specification
11733 (vhdl-subprog-paste-specification 'decl)
11734 (message "Pasting interface as subprogram declaration \"%s\"...done"
11735 (car vhdl-subprog-list))))
11737 (defun vhdl-subprog-paste-body ()
11738 "Paste as a subprogram body."
11740 (if (not vhdl-subprog-list)
11741 (error "ERROR: No subprogram interface read")
11742 (message "Pasting interface as subprogram body \"%s\"..."
11743 (car vhdl-subprog-list))
11744 ;; paste specification and body
11745 (vhdl-subprog-paste-specification 'body)
11746 (message "Pasting interface as subprogram body \"%s\"...done"
11747 (car vhdl-subprog-list))))
11749 (defun vhdl-subprog-paste-call ()
11750 "Paste as a subprogram call."
11752 (if (not vhdl-subprog-list)
11753 (error "ERROR: No subprogram interface read")
11754 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11755 param-list margin list-margin param start)
11756 ;; flatten local copy of interface list (must be flat for parameter mapping)
11757 (vhdl-subprog-flatten)
11758 (setq param-list (nth 2 vhdl-subprog-list))
11759 (indent-according-to-mode)
11760 (setq margin (current-indentation))
11761 (message "Pasting interface as subprogram call \"%s\"..."
11762 (car vhdl-subprog-list))
11764 (insert (nth 0 vhdl-subprog-list))
11765 (if (not param-list)
11767 (setq start (point))
11768 ;; paste parameter list
11770 (unless vhdl-argument-list-indent
11771 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11772 (setq list-margin (current-column))
11774 (setq param (car param-list))
11775 ;; paste group comment and spacing
11776 (when (eq vhdl-include-group-comments 'always)
11777 (vhdl-paste-group-comment (nth 6 param) list-margin))
11778 ;; paste formal port
11779 (insert (car (nth 0 param)) " => ")
11780 (setq param-list (cdr param-list))
11781 (insert (if param-list "," ");"))
11783 (when (and vhdl-include-port-comments (nth 5 param))
11784 (vhdl-comment-insert-inline (nth 5 param)))
11785 (when param-list (insert "\n") (indent-to list-margin)))
11786 ;; align parameter list
11787 (when vhdl-auto-align
11788 (vhdl-align-region-groups start (point) 1)))
11789 (message "Pasting interface as subprogram call \"%s\"...done"
11790 (car vhdl-subprog-list))
11791 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11794 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11798 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11799 ;; Hippie expand customization
11801 (defvar vhdl-expand-upper-case nil)
11803 (defun vhdl-try-expand-abbrev (old)
11804 "Try expanding abbreviations from `vhdl-abbrev-list'."
11806 (he-init-string (he-dabbrev-beg) (point))
11807 (setq he-expand-list
11808 (let ((abbrev-list vhdl-abbrev-list)
11809 (sel-abbrev-list '()))
11811 (when (or (not (stringp (car abbrev-list)))
11813 (concat "^" he-search-string) (car abbrev-list)))
11814 (setq sel-abbrev-list
11815 (cons (car abbrev-list) sel-abbrev-list)))
11816 (setq abbrev-list (cdr abbrev-list)))
11817 (nreverse sel-abbrev-list))))
11818 (while (and he-expand-list
11819 (or (not (stringp (car he-expand-list)))
11820 (he-string-member (car he-expand-list) he-tried-table t)))
11821 ; (equal (car he-expand-list) he-search-string)))
11822 (unless (stringp (car he-expand-list))
11823 (setq vhdl-expand-upper-case (car he-expand-list)))
11824 (setq he-expand-list (cdr he-expand-list)))
11825 (if (null he-expand-list)
11826 (progn (when old (he-reset-string))
11828 (he-substitute-string
11829 (if vhdl-expand-upper-case
11830 (upcase (car he-expand-list))
11831 (car he-expand-list))
11833 (setq he-expand-list (cdr he-expand-list))
11836 (defun vhdl-he-list-beg ()
11837 "Also looks at the word before `(' in order to better match parenthesized
11838 expressions (e.g. for index ranges of types and signals)."
11841 (progn (backward-up-list 1)
11842 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
11846 ;; override `he-list-beg' from `hippie-exp'
11847 (unless (and (boundp 'viper-mode) viper-mode)
11848 (defalias 'he-list-beg 'vhdl-he-list-beg))
11850 ;; function for expanding abbrevs and dabbrevs
11851 (defun vhdl-expand-abbrev (arg))
11852 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
11853 '(try-expand-dabbrev
11854 try-expand-dabbrev-all-buffers
11855 vhdl-try-expand-abbrev)))
11857 ;; function for expanding parenthesis
11858 (defun vhdl-expand-paren (arg))
11859 (fset 'vhdl-expand-paren (make-hippie-expand-function
11861 try-expand-list-all-buffers)))
11863 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11866 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
11867 "Convert all words matching word-regexp in region to lower or upper case,
11868 depending on parameter upper-case."
11869 (let ((case-replace nil)
11871 (vhdl-prepare-search-2
11874 (setq end (point-marker))
11876 (while (re-search-forward word-regexp end t)
11877 (or (vhdl-in-literal)
11880 (downcase-word -1)))
11881 (when (and count vhdl-progress-interval (not noninteractive)
11882 (< vhdl-progress-interval
11883 (- (nth 1 (current-time)) last-update)))
11884 (message "Fixing case... (%2d%s)"
11885 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
11887 (setq last-update (nth 1 (current-time)))))
11888 (goto-char end)))))
11890 (defun vhdl-fix-case-region (beg end &optional arg)
11891 "Convert all VHDL words in region to lower or upper case, depending on
11892 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
11893 (interactive "r\nP")
11894 (vhdl-fix-case-region-1
11895 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
11896 (vhdl-fix-case-region-1
11897 beg end vhdl-upper-case-types vhdl-types-regexp 1)
11898 (vhdl-fix-case-region-1
11899 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
11900 (vhdl-fix-case-region-1
11901 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
11902 (when vhdl-progress-interval (message "Fixing case...done")))
11904 (defun vhdl-fix-case-buffer ()
11905 "Convert all VHDL words in buffer to lower or upper case, depending on
11906 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
11908 (vhdl-fix-case-region (point-min) (point-max)))
11910 (defun vhdl-fix-case-word (&optional arg)
11911 "Convert word after cursor to upper case if necessary."
11914 (when arg (backward-word 1))
11915 (vhdl-prepare-search-1
11916 (when (and vhdl-upper-case-keywords
11917 (looking-at vhdl-keywords-regexp))
11919 (when (and vhdl-upper-case-types
11920 (looking-at vhdl-types-regexp))
11922 (when (and vhdl-upper-case-attributes
11923 (looking-at vhdl-attributes-regexp))
11925 (when (and vhdl-upper-case-enum-values
11926 (looking-at vhdl-enum-values-regexp))
11927 (upcase-word 1)))))
11929 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11930 ;; Line handling functions
11932 (defun vhdl-current-line ()
11933 "Return the line number of the line containing point."
11936 (1+ (count-lines (point-min) (line-beginning-position)))))
11938 (defun vhdl-line-kill-entire (&optional arg)
11939 "Delete entire line."
11941 (beginning-of-line)
11942 (kill-line (or arg 1)))
11944 (defun vhdl-line-kill (&optional arg)
11945 "Kill current line."
11947 (vhdl-line-kill-entire arg))
11949 (defun vhdl-line-copy (&optional arg)
11950 "Copy current line."
11953 (beginning-of-line)
11954 (let ((position (point)))
11955 (forward-line (or arg 1))
11956 (copy-region-as-kill position (point)))))
11958 (defun vhdl-line-yank ()
11959 "Yank entire line."
11961 (beginning-of-line)
11964 (defun vhdl-line-expand (&optional prefix-arg)
11965 "Hippie-expand current line."
11967 (let ((case-fold-search t) (case-replace nil)
11968 (hippie-expand-try-functions-list
11969 '(try-expand-line try-expand-line-all-buffers)))
11970 (hippie-expand prefix-arg)))
11972 (defun vhdl-line-transpose-next (&optional arg)
11973 "Interchange this line with next line."
11976 (transpose-lines (or arg 1))
11979 (defun vhdl-line-transpose-previous (&optional arg)
11980 "Interchange this line with previous line."
11983 (transpose-lines (- 0 (or arg 0)))
11986 (defun vhdl-line-open ()
11987 "Open a new line and indent."
11990 (newline-and-indent))
11992 (defun vhdl-delete-indentation ()
11993 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
11994 it works within comments too."
11996 (let ((fill-prefix "-- "))
11997 (delete-indentation)))
11999 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12002 (defun vhdl-forward-same-indent ()
12003 "Move forward to next line with same indent."
12005 (let ((pos (point))
12006 (indent (current-indentation)))
12007 (beginning-of-line 2)
12008 (while (and (not (eobp))
12009 (or (looking-at "^\\s-*\\(--.*\\)?$")
12010 (> (current-indentation) indent)))
12011 (beginning-of-line 2))
12012 (if (= (current-indentation) indent)
12013 (back-to-indentation)
12014 (message "No following line with same indent found in this block")
12018 (defun vhdl-backward-same-indent ()
12019 "Move backward to previous line with same indent."
12021 (let ((pos (point))
12022 (indent (current-indentation)))
12023 (beginning-of-line -0)
12024 (while (and (not (bobp))
12025 (or (looking-at "^\\s-*\\(--.*\\)?$")
12026 (> (current-indentation) indent)))
12027 (beginning-of-line -0))
12028 (if (= (current-indentation) indent)
12029 (back-to-indentation)
12030 (message "No preceding line with same indent found in this block")
12034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12037 (defun vhdl-statistics-buffer ()
12038 "Get some file statistics."
12042 (no-lines (count-lines (point-min) (point-max))))
12044 ;; count statements
12045 (goto-char (point-min))
12046 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12047 (if (match-string 1)
12048 (goto-char (match-end 1))
12049 (setq no-stats (1+ no-stats))))
12050 ;; count code lines
12051 (goto-char (point-min))
12052 (while (not (eobp))
12053 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12054 (setq no-code-lines (1+ no-code-lines)))
12055 (beginning-of-line 2)))
12058 File statistics: \"%s\"\n\
12059 ---------------------\n\
12060 # statements : %5d\n\
12061 # code lines : %5d\n\
12062 # total lines : %5d\n\ "
12063 (buffer-file-name) no-stats no-code-lines no-lines)))
12065 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12068 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12069 "Like `re-search-forward', but does not match within literals."
12072 (while (and (setq pos (re-search-forward regexp bound noerror count))
12073 (vhdl-in-literal))))
12074 (when pos (goto-char pos))
12077 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12078 "Like `re-search-backward', but does not match within literals."
12081 (while (and (setq pos (re-search-backward regexp bound noerror count))
12082 (vhdl-in-literal))))
12083 (when pos (goto-char pos))
12087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12091 (defun vhdl-set-project (name)
12092 "Set current project to NAME."
12094 (list (let ((completion-ignore-case t))
12095 (completing-read "Project name: " vhdl-project-alist nil t))))
12096 (cond ((equal name "")
12097 (setq vhdl-project nil)
12098 (message "Current VHDL project: None"))
12099 ((assoc name vhdl-project-alist)
12100 (setq vhdl-project name)
12101 (message "Current VHDL project: \"%s\"" name))
12103 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12104 (vhdl-speedbar-update-current-project))
12106 (defun vhdl-toggle-project (name token indent)
12107 "Set current project to NAME or unset if NAME is current project."
12108 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12110 (defun vhdl-export-project (file-name)
12111 "Write project setup for current project."
12113 (let ((name (vhdl-resolve-env-variable
12114 (vhdl-replace-string
12115 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12116 (concat (subst-char-in-string
12117 ? ?_ (or (vhdl-project-p)
12118 (error "ERROR: No current project")))
12119 " " (user-login-name))))))
12120 (list (read-file-name
12121 "Write project file: "
12122 (when (file-name-absolute-p name) "") nil nil name))))
12123 (setq file-name (abbreviate-file-name file-name))
12124 (let ((orig-buffer (current-buffer)))
12125 (unless (file-exists-p (file-name-directory file-name))
12126 (make-directory (file-name-directory file-name) t))
12127 (if (not (file-writable-p file-name))
12128 (error "ERROR: File not writable: \"%s\"" file-name)
12129 (set-buffer (find-file-noselect file-name t t))
12131 (insert ";; -*- Emacs-Lisp -*-\n\n"
12132 ";;; " (file-name-nondirectory file-name)
12133 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12134 ";; Project : " vhdl-project "\n"
12135 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12136 (user-login-name) "\n\n\n"
12137 ";; project name\n"
12138 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12139 ";; project setup\n"
12140 "(aput 'vhdl-project-alist vhdl-project\n'")
12141 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12144 (kill-buffer (current-buffer))
12145 (set-buffer orig-buffer))))
12147 (defun vhdl-import-project (file-name &optional auto not-make-current)
12148 "Read project setup and set current project."
12150 (let ((name (vhdl-resolve-env-variable
12151 (vhdl-replace-string
12152 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12153 (concat "" " " (user-login-name))))))
12154 (list (read-file-name
12155 "Read project file: " (when (file-name-absolute-p name) "") nil t
12156 (file-name-directory name)))))
12157 (when (file-exists-p file-name)
12159 (let ((current-project vhdl-project))
12160 (load-file file-name)
12161 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12162 (adelete 'vhdl-project-alist vhdl-project)
12164 (when not-make-current
12165 (setq vhdl-project current-project))
12166 (vhdl-update-mode-menu)
12167 (vhdl-speedbar-refresh)
12168 (unless not-make-current
12169 (message "Current VHDL project: \"%s\"%s"
12170 vhdl-project (if auto " (auto-loaded)" ""))))
12171 (error (vhdl-warning
12172 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12174 (defun vhdl-duplicate-project ()
12175 "Duplicate setup of current project."
12177 (let ((new-name (read-from-minibuffer "New project name: "))
12178 (project-entry (aget vhdl-project-alist vhdl-project t)))
12179 (setq vhdl-project-alist
12180 (append vhdl-project-alist
12181 (list (cons new-name project-entry))))
12182 (vhdl-update-mode-menu)))
12184 (defun vhdl-auto-load-project ()
12185 "Automatically load project setup at startup."
12186 (let ((file-name-list vhdl-project-file-name)
12187 file-list list-length)
12188 (while file-name-list
12191 (file-expand-wildcards
12192 (vhdl-resolve-env-variable
12193 (vhdl-replace-string
12194 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12195 (concat "\*" " " (user-login-name)))))))
12196 (setq list-length (or list-length (length file-list)))
12197 (setq file-name-list (cdr file-name-list)))
12199 (vhdl-import-project (expand-file-name (car file-list)) t
12200 (not (> list-length 0)))
12201 (setq list-length (1- list-length))
12202 (setq file-list (cdr file-list)))))
12204 ;; automatically load project setup when idle after startup
12205 (when (memq 'startup vhdl-project-auto-load)
12207 (vhdl-auto-load-project)
12208 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12213 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12214 ;; (using `hideshow.el')
12216 (defconst vhdl-hs-start-regexp
12219 ;; generic/port clause
12220 "\\(generic\\|port\\)[ \t\n]*(\\|"
12223 ;; component instantiation
12224 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12225 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12226 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12227 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12229 "\\(function\\|procedure\\)\\>\\|"
12231 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12232 ;; configuration declaration
12235 "Regexp to match start of construct to hide.")
12237 (defun vhdl-hs-forward-sexp-func (count)
12238 "Find end of construct to hide (for hideshow). Only searches forward."
12239 (let ((pos (point)))
12240 (vhdl-prepare-search-2
12241 (beginning-of-line)
12243 ;; generic/port clause
12244 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12245 (goto-char (match-end 0))
12248 ;; component declaration
12249 ((looking-at "^\\s-*component\\>")
12250 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12251 ;; component instantiation
12254 "^\\s-*\\w+\\s-*:[ \t\n]*"
12255 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12256 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12257 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12258 (goto-char (match-end 0))
12262 (vhdl-forward-syntactic-ws)
12263 (when (looking-at "port\\s-+map[ \t\n]*(")
12264 (goto-char (match-end 0))
12267 (setq pos (point)))
12269 ;; subprogram declaration/body
12270 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12271 (goto-char (match-end 0))
12272 (vhdl-forward-syntactic-ws)
12273 (when (looking-at "(")
12275 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12276 (vhdl-in-literal)))
12278 (when (match-string 2)
12279 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12281 (vhdl-forward-sexp)))
12282 ;; block (recursive)
12283 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12284 (goto-char (match-end 0))
12285 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12286 (match-beginning 2))
12287 (vhdl-hs-forward-sexp-func count)))
12289 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12290 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12291 ;; configuration declaration
12292 ((looking-at "^\\s-*configuration\\>")
12294 (vhdl-forward-sexp))
12295 (t (goto-char pos))))))
12297 (defun vhdl-hideshow-init ()
12298 "Initialize `hideshow'."
12299 (when vhdl-hideshow-menu
12300 (vhdl-hs-minor-mode 1)))
12302 (defun vhdl-hs-minor-mode (&optional arg)
12303 "Toggle hideshow minor mode and update menu bar."
12305 (require 'hideshow)
12306 ;; check for hideshow version 5.x
12307 (if (not (boundp 'hs-block-start-mdata-select))
12308 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12309 ;; initialize hideshow
12310 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12311 (setq hs-special-modes-alist
12312 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12313 'vhdl-hs-forward-sexp-func nil)
12314 hs-special-modes-alist)))
12315 (make-local-variable 'hs-minor-mode-hook)
12316 (if vhdl-hide-all-init
12317 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12318 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12319 (hs-minor-mode arg)
12320 (vhdl-mode-line-update))) ; hack to update menu bar
12323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12326 ;; (using `font-lock.el')
12328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12331 (defun vhdl-within-translate-off ()
12332 "Return point if within translate-off region, else nil."
12333 (and (save-excursion
12334 (re-search-backward
12335 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12336 (equal "off" (match-string 1))
12339 (defun vhdl-start-translate-off (limit)
12340 "Return point before translate-off pragma if before LIMIT, else nil."
12341 (when (re-search-forward
12342 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12343 (match-beginning 0)))
12345 (defun vhdl-end-translate-off (limit)
12346 "Return point after translate-on pragma if before LIMIT, else nil."
12347 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12349 (defun vhdl-match-translate-off (limit)
12350 "Match a translate-off block, setting match-data and returning t, else nil."
12351 (when (< (point) limit)
12352 (let ((start (or (vhdl-within-translate-off)
12353 (vhdl-start-translate-off limit)))
12354 (case-fold-search t))
12356 (let ((end (or (vhdl-end-translate-off limit) limit)))
12357 (set-match-data (list start end))
12358 (goto-char end))))))
12360 (defun vhdl-font-lock-match-item (limit)
12361 "Match, and move over, any declaration item after point. Adapted from
12362 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12363 (condition-case nil
12365 (narrow-to-region (point-min) limit)
12367 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12369 (goto-char (match-end 1))
12370 ;; move to next item
12371 (if (looking-at "\\s-*,")
12372 (goto-char (match-end 0))
12373 (end-of-line) t))))
12376 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12377 ;; Syntax definitions
12379 (defconst vhdl-font-lock-syntactic-keywords
12380 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12381 "Mark single quotes as having string quote syntax in 'c' instances.")
12383 (defvar vhdl-font-lock-keywords nil
12384 "Regular expressions to highlight in VHDL Mode.")
12386 (defvar vhdl-font-lock-keywords-0
12387 ;; set in `vhdl-font-lock-init' because dependent on user options
12388 "For consideration as a value of `vhdl-font-lock-keywords'.
12389 This does highlighting of template prompts and directives (pragmas).")
12391 (defvar vhdl-font-lock-keywords-1 nil
12392 ;; set in `vhdl-font-lock-init' because dependent on user options
12393 "For consideration as a value of `vhdl-font-lock-keywords'.
12394 This does highlighting of keywords and standard identifiers.")
12396 (defconst vhdl-font-lock-keywords-2
12398 ;; highlight names of units, subprograms, and components when declared
12402 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12403 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12404 "\\)\\s-+\\(\\w+\\)")
12405 5 'font-lock-function-name-face)
12407 ;; highlight entity names of architectures and configurations
12409 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12410 2 'font-lock-function-name-face)
12412 ;; highlight labels of common constructs
12415 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12416 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12417 "postponed\\|process\\|"
12418 (when (vhdl-standard-p 'ams) "procedural\\|")
12420 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\)*\\s-*<=\\)")
12421 1 'font-lock-function-name-face)
12423 ;; highlight label and component name of component instantiations
12426 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12427 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12428 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12430 ;; highlight label and instantiated unit of component instantiations
12433 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12434 "\\(component\\|configuration\\|entity\\)\\s-+"
12435 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12436 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12437 '(5 font-lock-function-name-face nil t)
12438 '(7 font-lock-function-name-face nil t))
12440 ;; highlight names and labels at end of constructs
12443 "^\\s-*end\\s-+\\(\\("
12444 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12445 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12446 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12447 (when (vhdl-standard-p 'ams) "procedural\\|")
12449 "\\)\\s-+\\)?\\(\\w*\\)")
12450 5 'font-lock-function-name-face)
12452 ;; highlight labels in exit and next statements
12455 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12456 3 'font-lock-function-name-face)
12458 ;; highlight entity name in attribute specifications
12461 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12462 1 'font-lock-function-name-face)
12464 ;; highlight labels in block and component specifications
12467 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12468 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12469 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12471 ;; highlight names in library clauses
12472 (list "^\\s-*library\\>"
12473 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12475 ;; highlight names in use clauses
12478 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12479 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12480 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12481 '(7 font-lock-function-name-face nil t))
12483 ;; highlight attribute name in attribute declarations/specifications
12486 "^\\s-*attribute\\s-+\\(\\w+\\)")
12489 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12492 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12493 3 'font-lock-type-face)
12495 ;; highlight signal/variable/constant declaration names
12496 (list "\\(:[^=]\\)"
12497 '(vhdl-font-lock-match-item
12498 (progn (goto-char (match-beginning 1))
12499 (skip-syntax-backward " ")
12500 (skip-syntax-backward "w_")
12501 (skip-syntax-backward " ")
12502 (while (= (preceding-char) ?,)
12504 (skip-syntax-backward " ")
12505 (skip-syntax-backward "w_")
12506 (skip-syntax-backward " ")))
12507 ; (skip-chars-backward "^-(\n\";")
12508 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12510 ;; highlight formal parameters in component instantiations and subprogram
12513 '(vhdl-font-lock-match-item
12514 (progn (goto-char (match-beginning 1))
12515 (skip-syntax-backward " ")
12516 (while (= (preceding-char) ?\)) (backward-sexp))
12517 (skip-syntax-backward "w_")
12518 (skip-syntax-backward " ")
12519 (when (memq (preceding-char) '(?n ?N))
12520 (goto-char (point-max))))
12521 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12523 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12525 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12526 '(vhdl-font-lock-match-item
12527 (progn (goto-char (match-end 1)) (match-beginning 2))
12528 nil (1 font-lock-variable-name-face)))
12530 "For consideration as a value of `vhdl-font-lock-keywords'.
12531 This does context sensitive highlighting of names and labels.")
12533 (defvar vhdl-font-lock-keywords-3 nil
12534 ;; set in `vhdl-font-lock-init' because dependent on user options
12535 "For consideration as a value of `vhdl-font-lock-keywords'.
12536 This does highlighting of words with special syntax.")
12538 (defvar vhdl-font-lock-keywords-4 nil
12539 ;; set in `vhdl-font-lock-init' because dependent on user options
12540 "For consideration as a value of `vhdl-font-lock-keywords'.
12541 This does highlighting of additional reserved words.")
12543 (defconst vhdl-font-lock-keywords-5
12544 ;; background highlight translate-off regions
12545 '((vhdl-match-translate-off (0 vhdl-translate-off-face append)))
12546 "For consideration as a value of `vhdl-font-lock-keywords'.
12547 This does background highlighting of translate-off regions.")
12549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12550 ;; Font and color definitions
12552 (defvar vhdl-prompt-face 'vhdl-prompt
12553 "Face name to use for prompts.")
12555 (defvar vhdl-attribute-face 'vhdl-attribute
12556 "Face name to use for standardized attributes.")
12558 (defvar vhdl-enumvalue-face 'vhdl-enumvalue
12559 "Face name to use for standardized enumeration values.")
12561 (defvar vhdl-function-face 'vhdl-function
12562 "Face name to use for standardized functions and packages.")
12564 (defvar vhdl-directive-face 'vhdl-directive
12565 "Face name to use for directives.")
12567 (defvar vhdl-reserved-words-face 'vhdl-reserved-words
12568 "Face name to use for additional reserved words.")
12570 (defvar vhdl-translate-off-face 'vhdl-translate-off
12571 "Face name to use for translate-off regions.")
12573 ;; face names to use for words with special syntax.
12574 (let ((syntax-alist vhdl-special-syntax-alist)
12576 (while syntax-alist
12577 (setq name (vhdl-function-name "vhdl" (nth 0 (car syntax-alist))))
12578 (eval `(defvar ,name ',name
12579 ,(concat "Face name to use for "
12580 (nth 0 (car syntax-alist)) ".")))
12581 (setq syntax-alist (cdr syntax-alist))))
12583 (defgroup vhdl-highlight-faces nil
12584 "Faces for highlighting."
12585 :group 'vhdl-highlight)
12587 ;; add faces used from `font-lock'
12588 (custom-add-to-group
12589 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12590 (custom-add-to-group
12591 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12592 (custom-add-to-group
12593 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12594 (custom-add-to-group
12595 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12596 (custom-add-to-group
12597 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12598 (custom-add-to-group
12599 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12601 (defface vhdl-prompt
12602 '((((min-colors 88) (class color) (background light))
12603 (:foreground "Red1" :bold t))
12604 (((class color) (background light)) (:foreground "Red" :bold t))
12605 (((class color) (background dark)) (:foreground "Pink" :bold t))
12606 (t (:inverse-video t)))
12607 "Font lock mode face used to highlight prompts."
12608 :group 'vhdl-highlight-faces
12609 :group 'font-lock-highlighting-faces)
12610 ;; backward-compatibility alias
12611 (put 'vhdl-font-lock-prompt-face 'face-alias 'vhdl-prompt)
12613 (defface vhdl-attribute
12614 '((((class color) (background light)) (:foreground "Orchid"))
12615 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12616 (t (:italic t :bold t)))
12617 "Font lock mode face used to highlight standardized attributes."
12618 :group 'vhdl-highlight-faces
12619 :group 'font-lock-highlighting-faces)
12620 ;; backward-compatibility alias
12621 (put 'vhdl-font-lock-attribute-face 'face-alias 'vhdl-attribute)
12623 (defface vhdl-enumvalue
12624 '((((class color) (background light)) (:foreground "SaddleBrown"))
12625 (((class color) (background dark)) (:foreground "BurlyWood"))
12626 (t (:italic t :bold t)))
12627 "Font lock mode face used to highlight standardized enumeration values."
12628 :group 'vhdl-highlight-faces
12629 :group 'font-lock-highlighting-faces)
12630 ;; backward-compatibility alias
12631 (put 'vhdl-font-lock-enumvalue-face 'face-alias 'vhdl-enumvalue)
12633 (defface vhdl-function
12634 '((((class color) (background light)) (:foreground "Cyan4"))
12635 (((class color) (background dark)) (:foreground "Orchid1"))
12636 (t (:italic t :bold t)))
12637 "Font lock mode face used to highlight standardized functions and packages."
12638 :group 'vhdl-highlight-faces
12639 :group 'font-lock-highlighting-faces)
12640 ;; backward-compatibility alias
12641 (put 'vhdl-font-lock-function-face 'face-alias 'vhdl-function)
12643 (defface vhdl-directive
12644 '((((class color) (background light)) (:foreground "CadetBlue"))
12645 (((class color) (background dark)) (:foreground "Aquamarine"))
12646 (t (:italic t :bold t)))
12647 "Font lock mode face used to highlight directives."
12648 :group 'vhdl-highlight-faces
12649 :group 'font-lock-highlighting-faces)
12650 ;; backward-compatibility alias
12651 (put 'vhdl-font-lock-directive-face 'face-alias 'vhdl-directive)
12653 (defface vhdl-reserved-word
12654 '((((class color) (background light)) (:foreground "Orange" :bold t))
12655 (((min-colors 88) (class color) (background dark))
12656 (:foreground "Yellow1" :bold t))
12657 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12659 "Font lock mode face used to highlight additional reserved words."
12660 :group 'vhdl-highlight-faces
12661 :group 'font-lock-highlighting-faces)
12662 ;; backward-compatibility alias
12663 (put 'vhdl-font-lock-reserved-words-face 'face-alias 'vhdl-reserved-word)
12665 (defface vhdl-translate-off
12666 '((((class color) (background light)) (:background "LightGray"))
12667 (((class color) (background dark)) (:background "DimGray"))
12669 "Font lock mode face used to background highlight translate-off regions."
12670 :group 'vhdl-highlight-faces
12671 :group 'font-lock-highlighting-faces)
12672 ;; backward-compatibility alias
12673 (put 'vhdl-font-lock-translate-off-face 'face-alias 'vhdl-translate-off)
12675 ;; font lock mode faces used to highlight words with special syntax.
12676 (let ((syntax-alist vhdl-special-syntax-alist))
12677 (while syntax-alist
12678 (eval `(defface ,(vhdl-function-name "vhdl" (caar syntax-alist))
12679 '((((class color) (background light))
12680 (:foreground ,(nth 2 (car syntax-alist))))
12681 (((class color) (background dark))
12682 (:foreground ,(nth 3 (car syntax-alist))))
12684 ,(concat "Font lock mode face used to highlight "
12685 (nth 0 (car syntax-alist)) ".")
12686 :group 'vhdl-highlight-faces
12687 :group 'font-lock-highlighting-faces))
12688 (setq syntax-alist (cdr syntax-alist))))
12690 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12691 ;; Font lock initialization
12693 (defun vhdl-font-lock-init ()
12694 "Initialize fontification."
12695 ;; highlight template prompts and directives
12696 (setq vhdl-font-lock-keywords-0
12697 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12698 vhdl-template-prompt-syntax ">\\)")
12700 (list (concat "--\\s-*"
12701 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12702 2 'vhdl-directive t)))
12703 ;; highlight keywords and standardized types, attributes, enumeration
12704 ;; values, and subprograms
12705 (setq vhdl-font-lock-keywords-1
12707 (list (concat "'" vhdl-attributes-regexp) 1 'vhdl-attribute)
12708 (list vhdl-types-regexp 1 'font-lock-type-face)
12709 (list vhdl-functions-regexp 1 'vhdl-function)
12710 (list vhdl-packages-regexp 1 'vhdl-function)
12711 (list vhdl-enum-values-regexp 1 'vhdl-enumvalue)
12712 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12713 ;; highlight words with special syntax.
12714 (setq vhdl-font-lock-keywords-3
12715 (let ((syntax-alist vhdl-special-syntax-alist)
12717 (while syntax-alist
12720 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12721 (vhdl-function-name
12722 "vhdl" (nth 0 (car syntax-alist))))
12724 (setq syntax-alist (cdr syntax-alist)))
12726 ;; highlight additional reserved words
12727 (setq vhdl-font-lock-keywords-4
12728 (list (list vhdl-reserved-words-regexp 1 'vhdl-reserved-word)))
12729 ;; highlight everything together
12730 (setq vhdl-font-lock-keywords
12732 vhdl-font-lock-keywords-0
12733 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12734 (when (or vhdl-highlight-forbidden-words
12735 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12736 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12737 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12738 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12740 ;; initialize fontification for VHDL Mode
12741 (vhdl-font-lock-init)
12743 (defun vhdl-fontify-buffer ()
12744 "Re-initialize fontification and fontify buffer."
12746 (setq font-lock-defaults
12748 'vhdl-font-lock-keywords nil
12749 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12750 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12751 (when (fboundp 'font-lock-unset-defaults)
12752 (font-lock-unset-defaults)) ; not implemented in XEmacs
12753 (font-lock-set-defaults) ;What for? --Stef
12754 (font-lock-mode nil)
12755 (font-lock-mode t))
12757 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12758 ;; Initialization for postscript printing
12760 (defun vhdl-ps-print-settings ()
12761 "Initialize custom face and page settings for postscript printing."
12762 ;; define custom face settings
12763 (unless (or (not vhdl-print-customize-faces)
12765 (set (make-local-variable 'ps-bold-faces)
12766 '(font-lock-keyword-face font-lock-type-face
12767 vhdl-attribute vhdl-enumvalue vhdl-directive))
12768 (set (make-local-variable 'ps-italic-faces)
12769 '(font-lock-comment-face
12770 font-lock-function-name-face font-lock-type-face
12771 vhdl-attribute vhdl-enumvalue vhdl-directive))
12772 (set (make-local-variable 'ps-underlined-faces)
12773 '(font-lock-string-face))
12774 (setq ps-always-build-face-reference t))
12775 ;; define page settings, so that a line containing 79 characters (default)
12776 ;; fits into one column
12777 (when vhdl-print-two-column
12778 (set (make-local-variable 'ps-landscape-mode) t)
12779 (set (make-local-variable 'ps-number-of-columns) 2)
12780 (set (make-local-variable 'ps-font-size) 7.0)
12781 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12782 (set (make-local-variable 'ps-header-font-size) 9.0)
12783 (set (make-local-variable 'ps-header-offset) 12.0)
12784 (when (eq ps-paper-type 'letter)
12785 (set (make-local-variable 'ps-inter-column) 40.0)
12786 (set (make-local-variable 'ps-left-margin) 40.0)
12787 (set (make-local-variable 'ps-right-margin) 40.0))))
12789 (defun vhdl-ps-print-init ()
12790 "Initialize postscript printing."
12792 (when (boundp 'ps-print-color-p)
12793 (vhdl-ps-print-settings))
12794 (make-local-variable 'ps-print-hook)
12795 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12798 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12799 ;;; Hierarchy browser (using `speedbar.el')
12800 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12801 ;; Allows displaying the hierarchy of all VHDL design units contained in a
12802 ;; directory by using the speedbar.
12804 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12807 (defvar vhdl-entity-alist nil
12808 "Cache with entities and corresponding architectures for each
12809 project/directory.")
12810 ;; structure: (parenthesised expression means list of such entries)
12812 ;; (ent-key ent-name ent-file ent-line
12813 ;; (arch-key arch-name arch-file arch-line
12814 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12815 ;; inst-arch-key inst-conf-key inst-lib-key)
12816 ;; (lib-name pack-key))
12817 ;; (lib-name pack-key))
12819 (defvar vhdl-config-alist nil
12820 "Cache with configurations for each project/directory.")
12821 ;; structure: (parenthesised expression means list of such entries)
12823 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
12824 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
12825 ;; inst-conf-key inst-lib-key)
12826 ;; (lib-name pack-key)))
12828 (defvar vhdl-package-alist nil
12829 "Cache with packages for each project/directory.")
12830 ;; structure: (parenthesised expression means list of such entries)
12832 ;; (pack-key pack-name pack-file pack-line
12833 ;; (comp-key comp-name comp-file comp-line)
12834 ;; (func-key func-name func-file func-line)
12835 ;; (lib-name pack-key)
12836 ;; pack-body-file pack-body-line
12837 ;; (func-key func-name func-body-file func-body-line)
12838 ;; (lib-name pack-key)))
12840 (defvar vhdl-ent-inst-alist nil
12841 "Cache with instantiated entities for each project/directory.")
12842 ;; structure: (parenthesised expression means list of such entries)
12843 ;; (cache-key (inst-ent-key))
12845 (defvar vhdl-file-alist nil
12846 "Cache with design units in each file for each project/directory.")
12847 ;; structure: (parenthesised expression means list of such entries)
12849 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
12850 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
12852 (defvar vhdl-directory-alist nil
12853 "Cache with source directories for each project.")
12854 ;; structure: (parenthesised expression means list of such entries)
12855 ;; (cache-key (directory))
12857 (defvar vhdl-speedbar-shown-unit-alist nil
12858 "Alist of design units simultaneously open in the current speedbar for each
12859 directory and project.")
12861 (defvar vhdl-speedbar-shown-project-list nil
12862 "List of projects simultaneously open in the current speedbar.")
12864 (defvar vhdl-updated-project-list nil
12865 "List of projects and directories with updated files.")
12867 (defvar vhdl-modified-file-list nil
12868 "List of modified files to be rescanned for hierarchy updating.")
12870 (defvar vhdl-speedbar-hierarchy-depth 0
12871 "Depth of instantiation hierarchy to display.")
12873 (defvar vhdl-speedbar-show-projects nil
12874 "Non-nil means project hierarchy is displayed in speedbar, directory
12875 hierarchy otherwise.")
12877 (defun vhdl-get-end-of-unit ()
12878 "Return position of end of current unit."
12879 (let ((pos (point)))
12881 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
12883 (goto-char (match-beginning 0))
12884 (vhdl-backward-syntactic-ws)
12885 (and (/= (preceding-char) ?\;) (not (bobp))))))
12886 (re-search-backward "^[ \t]*end\\>" pos 1)
12889 (defun vhdl-match-string-downcase (num &optional string)
12890 "Like `match-string-no-properties' with down-casing."
12891 (let ((match (match-string-no-properties num string)))
12892 (and match (downcase match))))
12895 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12898 (defun vhdl-scan-context-clause ()
12899 "Scan the context clause that preceeds a design unit."
12902 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
12903 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
12904 (equal "USE" (upcase (match-string 1))))
12905 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
12906 (setq lib-alist (cons (cons (match-string-no-properties 1)
12907 (vhdl-match-string-downcase 2))
12911 (defun vhdl-scan-directory-contents (name &optional project update num-string
12913 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
12914 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
12915 ; (unless (file-directory-p (match-string 1 name))
12916 ; (message "No such directory: \"%s\"" (match-string 1 name)))
12917 (let* ((dir-name (match-string 1 name))
12918 (file-pattern (match-string 2 name))
12919 (is-directory (= 0 (length file-pattern)))
12924 (vhdl-get-source-files t dir-name)
12925 (vhdl-directory-files
12926 dir-name t (wildcard-to-regexp file-pattern)))))
12927 (key (or project dir-name))
12928 (file-exclude-regexp
12929 (or (nth 3 (aget vhdl-project-alist project)) ""))
12930 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
12931 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
12932 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
12933 ent-alist conf-alist pack-alist ent-inst-list file-alist
12934 tmp-list tmp-entry no-files files-exist big-files)
12935 (when (or project update)
12936 (setq ent-alist (aget vhdl-entity-alist key t)
12937 conf-alist (aget vhdl-config-alist key t)
12938 pack-alist (aget vhdl-package-alist key t)
12939 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
12940 file-alist (aget vhdl-file-alist key t)))
12941 (when (and (not is-directory) (null file-list))
12942 (message "No such file: \"%s\"" name))
12943 (setq files-exist file-list)
12945 (setq no-files (length file-list))
12946 (message "Scanning %s %s\"%s\"..."
12947 (if is-directory "directory" "files") (or num-string "") name)
12949 (unless (equal file-exclude-regexp "")
12950 (let ((case-fold-search nil)
12953 (unless (string-match file-exclude-regexp (car file-list))
12954 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
12955 (setq file-list (cdr file-list)))
12956 (setq file-list (nreverse file-tmp-list))))
12957 ;; do for all files
12959 (unless noninteractive
12960 (message "Scanning %s %s\"%s\"... (%2d%s)"
12961 (if is-directory "directory" "files")
12962 (or num-string "") name
12963 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
12964 (let ((file-name (abbreviate-file-name (car file-list)))
12965 ent-list arch-list arch-ent-list conf-list
12966 pack-list pack-body-list inst-list inst-ent-list)
12970 (vhdl-prepare-search-2
12972 ;; scan for design units
12973 (if (and limit-design-file-size
12974 (< limit-design-file-size (buffer-size)))
12975 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
12976 (setq big-files t))
12977 ;; scan for entities
12978 (goto-char (point-min))
12979 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12980 (let* ((ent-name (match-string-no-properties 1))
12981 (ent-key (downcase ent-name))
12982 (ent-entry (aget ent-alist ent-key t))
12983 (arch-alist (nth 3 ent-entry))
12984 (lib-alist (vhdl-scan-context-clause)))
12985 (if (nth 1 ent-entry)
12986 (vhdl-warning-when-idle
12987 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12988 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
12989 file-name (vhdl-current-line))
12990 (setq ent-list (cons ent-key ent-list))
12991 (aput 'ent-alist ent-key
12992 (list ent-name file-name (vhdl-current-line)
12993 arch-alist lib-alist)))))
12994 ;; scan for architectures
12995 (goto-char (point-min))
12996 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12997 (let* ((arch-name (match-string-no-properties 1))
12998 (arch-key (downcase arch-name))
12999 (ent-name (match-string-no-properties 2))
13000 (ent-key (downcase ent-name))
13001 (ent-entry (aget ent-alist ent-key t))
13002 (arch-alist (nth 3 ent-entry))
13003 (arch-entry (aget arch-alist arch-key t))
13004 (lib-arch-alist (vhdl-scan-context-clause)))
13006 (vhdl-warning-when-idle
13007 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13008 arch-name ent-name (nth 1 arch-entry)
13009 (nth 2 arch-entry) file-name (vhdl-current-line))
13010 (setq arch-list (cons arch-key arch-list)
13011 arch-ent-list (cons ent-key arch-ent-list))
13012 (aput 'arch-alist arch-key
13013 (list arch-name file-name (vhdl-current-line) nil
13015 (aput 'ent-alist ent-key
13016 (list (or (nth 0 ent-entry) ent-name)
13017 (nth 1 ent-entry) (nth 2 ent-entry)
13018 (vhdl-sort-alist arch-alist)
13019 (nth 4 ent-entry))))))
13020 ;; scan for configurations
13021 (goto-char (point-min))
13022 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13023 (let* ((conf-name (match-string-no-properties 1))
13024 (conf-key (downcase conf-name))
13025 (conf-entry (aget conf-alist conf-key t))
13026 (ent-name (match-string-no-properties 2))
13027 (ent-key (downcase ent-name))
13028 (lib-alist (vhdl-scan-context-clause))
13029 (conf-line (vhdl-current-line))
13030 (end-of-unit (vhdl-get-end-of-unit))
13031 arch-key comp-conf-list inst-key-list
13032 inst-comp-key inst-ent-key inst-arch-key
13033 inst-conf-key inst-lib-key)
13034 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13035 (setq arch-key (vhdl-match-string-downcase 1)))
13037 (vhdl-warning-when-idle
13038 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13039 conf-name ent-name (nth 1 conf-entry)
13040 (nth 2 conf-entry) file-name conf-line)
13041 (setq conf-list (cons conf-key conf-list))
13042 ;; scan for subconfigurations and subentities
13043 (while (re-search-forward "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+" end-of-unit t)
13044 (setq inst-comp-key (vhdl-match-string-downcase 3)
13045 inst-key-list (split-string
13046 (vhdl-match-string-downcase 1)
13047 "[ \t\n]*,[ \t\n]*"))
13048 (vhdl-forward-syntactic-ws)
13049 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13051 inst-lib-key (vhdl-match-string-downcase 3)
13052 inst-ent-key (and (match-string 2)
13053 (vhdl-match-string-downcase 4))
13054 inst-arch-key (and (match-string 2)
13055 (vhdl-match-string-downcase 6))
13056 inst-conf-key (and (not (match-string 2))
13057 (vhdl-match-string-downcase 4)))
13058 (while inst-key-list
13059 (setq comp-conf-list
13060 (cons (list (car inst-key-list)
13061 inst-comp-key inst-ent-key
13062 inst-arch-key inst-conf-key
13065 (setq inst-key-list (cdr inst-key-list)))))
13066 (aput 'conf-alist conf-key
13067 (list conf-name file-name conf-line ent-key
13068 arch-key comp-conf-list lib-alist)))))
13069 ;; scan for packages
13070 (goto-char (point-min))
13071 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13072 (let* ((pack-name (match-string-no-properties 2))
13073 (pack-key (downcase pack-name))
13074 (is-body (match-string-no-properties 1))
13075 (pack-entry (aget pack-alist pack-key t))
13076 (pack-line (vhdl-current-line))
13077 (end-of-unit (vhdl-get-end-of-unit))
13078 comp-name func-name comp-alist func-alist lib-alist)
13079 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13080 (vhdl-warning-when-idle
13081 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13082 (if is-body " body" "") pack-name
13083 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13084 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13085 file-name (vhdl-current-line))
13086 ;; scan for context clauses
13087 (setq lib-alist (vhdl-scan-context-clause))
13088 ;; scan for component and subprogram declarations/bodies
13089 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13090 (if (equal (upcase (match-string 1)) "COMPONENT")
13091 (setq comp-name (match-string-no-properties 2)
13093 (cons (list (downcase comp-name) comp-name
13094 file-name (vhdl-current-line))
13096 (setq func-name (match-string-no-properties 2)
13098 (cons (list (downcase func-name) func-name
13099 file-name (vhdl-current-line))
13101 (setq func-alist (nreverse func-alist))
13102 (setq comp-alist (nreverse comp-alist))
13104 (setq pack-body-list (cons pack-key pack-body-list))
13105 (setq pack-list (cons pack-key pack-list)))
13107 'pack-alist pack-key
13109 (list (or (nth 0 pack-entry) pack-name)
13110 (nth 1 pack-entry) (nth 2 pack-entry)
13111 (nth 3 pack-entry) (nth 4 pack-entry)
13113 file-name pack-line func-alist lib-alist)
13114 (list pack-name file-name pack-line
13115 comp-alist func-alist lib-alist
13116 (nth 6 pack-entry) (nth 7 pack-entry)
13117 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13118 ;; scan for hierarchy
13119 (if (and limit-hier-file-size
13120 (< limit-hier-file-size (buffer-size)))
13121 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13122 (setq big-files t))
13123 ;; scan for architectures
13124 (goto-char (point-min))
13125 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13126 (let* ((ent-name (match-string-no-properties 2))
13127 (ent-key (downcase ent-name))
13128 (arch-name (match-string-no-properties 1))
13129 (arch-key (downcase arch-name))
13130 (ent-entry (aget ent-alist ent-key t))
13131 (arch-alist (nth 3 ent-entry))
13132 (arch-entry (aget arch-alist arch-key t))
13133 (beg-of-unit (point))
13134 (end-of-unit (vhdl-get-end-of-unit))
13137 ;; scan for contained instantiations
13138 (while (and (re-search-forward
13139 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13140 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13141 "component[ \t\n]+\\(\\w+\\)\\|"
13142 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\)") end-of-unit t)
13143 (or (not limit-hier-inst-no)
13144 (<= (setq inst-no (1+ inst-no))
13145 limit-hier-inst-no)))
13146 (let* ((inst-name (match-string-no-properties 1))
13147 (inst-key (downcase inst-name))
13149 (or (match-string-no-properties 3)
13150 (match-string-no-properties 6)))
13152 (or (and (match-string 8)
13153 (vhdl-match-string-downcase 11))
13154 (and inst-comp-name
13155 (downcase inst-comp-name))))
13156 (inst-arch-key (vhdl-match-string-downcase 13))
13158 (and (not (match-string 8))
13159 (vhdl-match-string-downcase 11)))
13160 (inst-lib-key (vhdl-match-string-downcase 10)))
13161 (goto-char (match-end 1))
13162 (setq inst-list (cons inst-key inst-list)
13163 inst-ent-list (cons inst-ent-key inst-ent-list))
13167 (list (list inst-key inst-name file-name
13168 (vhdl-current-line) inst-comp-name
13169 inst-ent-key inst-arch-key
13170 inst-conf-key inst-lib-key))))))
13171 ;; scan for contained configuration specifications
13172 (goto-char beg-of-unit)
13173 (while (re-search-forward
13174 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13175 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13176 (let* ((inst-comp-name (match-string-no-properties 3))
13178 (and (match-string 6)
13179 (vhdl-match-string-downcase 9)))
13180 (inst-arch-key (vhdl-match-string-downcase 11))
13182 (and (not (match-string 6))
13183 (vhdl-match-string-downcase 9)))
13184 (inst-lib-key (vhdl-match-string-downcase 8))
13186 (split-string (vhdl-match-string-downcase 1)
13187 "[ \t\n]*,[ \t\n]*"))
13188 (tmp-inst-alist inst-alist)
13190 (while tmp-inst-alist
13191 (when (and (or (equal "all" (car inst-key-list))
13192 (member (nth 0 (car tmp-inst-alist))
13196 (or (nth 4 (car tmp-inst-alist)) ""))
13197 (downcase inst-comp-name)))
13198 (setq inst-entry (car tmp-inst-alist))
13199 (setq inst-ent-list
13200 (cons (or inst-ent-key (nth 5 inst-entry))
13202 (nth 5 inst-entry) inst-ent-list)))
13204 (list (nth 0 inst-entry) (nth 1 inst-entry)
13205 (nth 2 inst-entry) (nth 3 inst-entry)
13207 (or inst-ent-key (nth 5 inst-entry))
13208 (or inst-arch-key (nth 6 inst-entry))
13209 inst-conf-key inst-lib-key))
13210 (setcar tmp-inst-alist inst-entry))
13211 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13213 (aput 'arch-alist arch-key
13214 (list (nth 0 arch-entry) (nth 1 arch-entry)
13215 (nth 2 arch-entry) inst-alist
13216 (nth 4 arch-entry)))
13217 (aput 'ent-alist ent-key
13218 (list (nth 0 ent-entry) (nth 1 ent-entry)
13219 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13220 (nth 4 ent-entry)))
13221 (when (and limit-hier-inst-no
13222 (> inst-no limit-hier-inst-no))
13223 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13224 (setq big-files t))
13225 (goto-char end-of-unit))))
13226 ;; remember design units for this file
13227 (aput 'file-alist file-name
13228 (list ent-list arch-list arch-ent-list conf-list
13229 pack-list pack-body-list inst-list inst-ent-list))
13230 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13231 (setq file-list (cdr file-list))))
13232 (when (or (and (not project) files-exist)
13233 (and project (not non-final)))
13234 ;; consistency checks:
13235 ;; check whether each architecture has a corresponding entity
13236 (setq tmp-list ent-alist)
13238 (when (null (nth 2 (car tmp-list)))
13239 (setq tmp-entry (car (nth 4 (car tmp-list))))
13240 (vhdl-warning-when-idle
13241 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13242 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13243 (nth 3 tmp-entry)))
13244 (setq tmp-list (cdr tmp-list)))
13245 ;; check whether configuration has a corresponding entity/architecture
13246 (setq tmp-list conf-alist)
13248 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13249 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13250 (setq tmp-entry (car tmp-list))
13251 (vhdl-warning-when-idle
13252 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13253 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13254 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13255 (setq tmp-entry (car tmp-list))
13256 (vhdl-warning-when-idle
13257 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13258 (nth 1 tmp-entry) (nth 4 tmp-entry)
13259 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13260 (setq tmp-list (cdr tmp-list)))
13261 ;; check whether each package body has a package declaration
13262 (setq tmp-list pack-alist)
13264 (when (null (nth 2 (car tmp-list)))
13265 (setq tmp-entry (car tmp-list))
13266 (vhdl-warning-when-idle
13267 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13268 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13269 (setq tmp-list (cdr tmp-list)))
13271 (setq ent-alist (vhdl-sort-alist ent-alist))
13272 (setq conf-alist (vhdl-sort-alist conf-alist))
13273 (setq pack-alist (vhdl-sort-alist pack-alist))
13274 ;; remember updated directory/project
13275 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13276 ;; clear directory alists
13278 (adelete 'vhdl-entity-alist key)
13279 (adelete 'vhdl-config-alist key)
13280 (adelete 'vhdl-package-alist key)
13281 (adelete 'vhdl-ent-inst-alist key)
13282 (adelete 'vhdl-file-alist key))
13283 ;; put directory contents into cache
13284 (aput 'vhdl-entity-alist key ent-alist)
13285 (aput 'vhdl-config-alist key conf-alist)
13286 (aput 'vhdl-package-alist key pack-alist)
13287 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13288 (aput 'vhdl-file-alist key file-alist)
13290 (message "Scanning %s %s\"%s\"...done"
13291 (if is-directory "directory" "files") (or num-string "") name)
13292 (unless project (message "Scanning directory...done"))
13294 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13295 ;; save cache when scanned non-interactively
13296 (when (or (not project) (not non-final))
13297 (when (and noninteractive vhdl-speedbar-save-cache)
13298 (vhdl-save-cache key)))
13301 (defun vhdl-scan-project-contents (project)
13302 "Scan the contents of all VHDL files found in the directories and files
13304 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13305 (default-dir (vhdl-resolve-env-variable
13306 (nth 1 (aget vhdl-project-alist project))))
13307 (file-exclude-regexp
13308 (or (nth 3 (aget vhdl-project-alist project)) ""))
13309 dir-list-tmp dir dir-name num-dir act-dir recursive)
13310 ;; clear project alists
13311 (adelete 'vhdl-entity-alist project)
13312 (adelete 'vhdl-config-alist project)
13313 (adelete 'vhdl-package-alist project)
13314 (adelete 'vhdl-ent-inst-alist project)
13315 (adelete 'vhdl-file-alist project)
13316 ;; expand directory names by default-directory
13317 (message "Collecting source files...")
13319 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13320 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13321 (setq recursive (match-string 1 dir)
13322 dir-name (match-string 3 dir))
13324 (cons (concat recursive
13325 (if (file-name-absolute-p dir-name) "" default-dir)
13328 (setq dir-list (cdr dir-list)))
13329 ;; resolve path wildcards
13330 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13331 ;; expand directories
13332 (while dir-list-tmp
13333 (setq dir (car dir-list-tmp))
13334 ;; get subdirectories
13335 (if (string-match "-r \\(.*[/\\]\\)" dir)
13336 (setq dir-list (append dir-list (vhdl-get-subdirs
13337 (match-string 1 dir))))
13338 (setq dir-list (append dir-list (list dir))))
13339 (setq dir-list-tmp (cdr dir-list-tmp)))
13341 (unless (equal file-exclude-regexp "")
13342 (let ((case-fold-search nil))
13344 (unless (string-match file-exclude-regexp (car dir-list))
13345 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13346 (setq dir-list (cdr dir-list)))
13347 (setq dir-list (nreverse dir-list-tmp))))
13348 (message "Collecting source files...done")
13349 ;; scan for design units for each directory in DIR-LIST
13350 (setq dir-list-tmp nil
13351 num-dir (length dir-list)
13354 (setq dir-name (abbreviate-file-name
13355 (expand-file-name (car dir-list))))
13356 (vhdl-scan-directory-contents dir-name project nil
13357 (format "(%s/%s) " act-dir num-dir)
13359 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13360 (setq dir-list (cdr dir-list)
13361 act-dir (1+ act-dir)))
13362 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13363 (message "Scanning project \"%s\"...done" project)))
13365 (defun vhdl-update-file-contents (file-name)
13366 "Update hierarchy information by contents of current buffer."
13367 (setq file-name (abbreviate-file-name file-name))
13368 (let* ((dir-name (file-name-directory file-name))
13369 (directory-alist vhdl-directory-alist)
13371 (while directory-alist
13372 (when (member dir-name (nth 1 (car directory-alist)))
13373 (let* ((vhdl-project (nth 0 (car directory-alist)))
13374 (project (vhdl-project-p))
13375 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13376 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13377 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13378 (ent-inst-list (car (aget vhdl-ent-inst-alist
13379 (or project dir-name) t)))
13380 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13381 (file-entry (aget file-alist file-name t))
13382 (ent-list (nth 0 file-entry))
13383 (arch-list (nth 1 file-entry))
13384 (arch-ent-list (nth 2 file-entry))
13385 (conf-list (nth 3 file-entry))
13386 (pack-list (nth 4 file-entry))
13387 (pack-body-list (nth 5 file-entry))
13388 (inst-ent-list (nth 7 file-entry))
13389 (cache-key (or project dir-name))
13390 arch-alist key ent-key entry)
13391 ;; delete design units previously contained in this file:
13394 (setq key (car ent-list)
13395 entry (aget ent-alist key t))
13396 (when (equal file-name (nth 1 entry))
13398 (aput 'ent-alist key
13399 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13400 (adelete 'ent-alist key)))
13401 (setq ent-list (cdr ent-list)))
13404 (setq key (car arch-list)
13405 ent-key (car arch-ent-list)
13406 entry (aget ent-alist ent-key t)
13407 arch-alist (nth 3 entry))
13408 (when (equal file-name (nth 1 (aget arch-alist key t)))
13409 (adelete 'arch-alist key)
13410 (if (or (nth 1 entry) arch-alist)
13411 (aput 'ent-alist ent-key
13412 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13413 arch-alist (nth 4 entry)))
13414 (adelete 'ent-alist ent-key)))
13415 (setq arch-list (cdr arch-list)
13416 arch-ent-list (cdr arch-ent-list)))
13419 (setq key (car conf-list))
13420 (when (equal file-name (nth 1 (aget conf-alist key t)))
13421 (adelete 'conf-alist key))
13422 (setq conf-list (cdr conf-list)))
13423 ;; package declarations
13425 (setq key (car pack-list)
13426 entry (aget pack-alist key t))
13427 (when (equal file-name (nth 1 entry))
13429 (aput 'pack-alist key
13430 (list (nth 0 entry) nil nil nil nil nil
13431 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13433 (adelete 'pack-alist key)))
13434 (setq pack-list (cdr pack-list)))
13436 (while pack-body-list
13437 (setq key (car pack-body-list)
13438 entry (aget pack-alist key t))
13439 (when (equal file-name (nth 6 entry))
13441 (aput 'pack-alist key
13442 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13443 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13445 (adelete 'pack-alist key)))
13446 (setq pack-body-list (cdr pack-body-list)))
13447 ;; instantiated entities
13448 (while inst-ent-list
13449 (setq ent-inst-list
13450 (vhdl-delete (car inst-ent-list) ent-inst-list))
13451 (setq inst-ent-list (cdr inst-ent-list)))
13453 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13454 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13455 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13456 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13458 (vhdl-scan-directory-contents file-name project t)
13459 (when (or (and vhdl-speedbar-show-projects project)
13460 (and (not vhdl-speedbar-show-projects) (not project)))
13461 (vhdl-speedbar-refresh project))
13463 (setq directory-alist (cdr directory-alist)))
13466 (defun vhdl-update-hierarchy ()
13467 "Update directory and hierarchy information in speedbar."
13468 (let ((file-list (reverse vhdl-modified-file-list))
13470 (when (and vhdl-speedbar-update-on-saving file-list)
13473 (or (vhdl-update-file-contents (car file-list))
13475 (setq file-list (cdr file-list)))
13476 (setq vhdl-modified-file-list nil)
13477 (when updated (message "Updating hierarchy...done")))))
13479 ;; structure (parenthesised expression means list of such entries)
13480 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13481 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13482 ;; comp-lib-name level)
13483 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13484 conf-inst-alist level indent
13485 &optional include-top ent-hier)
13486 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13488 (let* ((ent-entry (aget ent-alist ent-key t))
13489 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13490 (cdar (last (nth 3 ent-entry)))))
13491 (inst-alist (nth 3 arch-entry))
13492 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13493 hier-list subcomp-list tmp-list inst-key inst-comp-name
13494 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13495 (when (= level 0) (message "Extract design hierarchy..."))
13497 (setq level (1+ level)))
13498 (when (member ent-key ent-hier)
13499 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13500 ;; check configured architecture (already checked during scanning)
13501 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13502 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13503 ;; process all instances
13505 (setq inst-entry (car inst-alist)
13506 inst-key (nth 0 inst-entry)
13507 inst-comp-name (nth 4 inst-entry)
13508 inst-conf-key (nth 7 inst-entry))
13509 ;; search entry in configuration's instantiations list
13510 (setq tmp-list conf-inst-alist)
13511 (while (and tmp-list
13512 (not (and (member (nth 0 (car tmp-list))
13513 (list "all" inst-key))
13514 (equal (nth 1 (car tmp-list))
13515 (downcase (or inst-comp-name ""))))))
13516 (setq tmp-list (cdr tmp-list)))
13517 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13518 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13519 (when (and inst-conf-key (not inst-conf-entry))
13520 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13521 ;; determine entity
13523 (or (nth 2 (car tmp-list)) ; from configuration
13524 (nth 3 inst-conf-entry) ; from subconfiguration
13525 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13526 ; from configuration spec.
13527 (nth 5 inst-entry))) ; from direct instantiation
13528 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13529 ;; determine architecture
13530 (setq inst-arch-key
13531 (or (nth 3 (car tmp-list)) ; from configuration
13532 (nth 4 inst-conf-entry) ; from subconfiguration
13533 (nth 6 inst-entry) ; from direct instantiation
13534 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13535 ; from configuration spec.
13536 (caar (nth 3 inst-ent-entry)))) ; random (simplified MRA)
13537 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13540 (or (nth 5 (car tmp-list)) ; from configuration
13541 (nth 8 inst-entry))) ; from direct instantiation
13542 ;; gather information for this instance
13544 (list (nth 1 inst-entry)
13545 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13546 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13547 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13548 (or (nth 0 inst-arch-entry) inst-arch-key)
13549 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13550 (or (nth 0 inst-conf-entry) inst-conf-key)
13551 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13552 inst-lib-key level))
13553 ;; get subcomponent hierarchy
13554 (setq subcomp-list (vhdl-get-hierarchy
13555 ent-alist conf-alist
13556 inst-ent-key inst-arch-key inst-conf-key
13557 (nth 5 inst-conf-entry)
13558 (1+ level) indent nil (cons ent-key ent-hier)))
13560 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13561 (setq inst-alist (cdr inst-alist)))
13564 (cons (list nil nil (nth 0 ent-entry)
13565 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13567 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13571 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13574 (defun vhdl-get-instantiations (ent-key indent)
13575 "Get all instantiations of entity ENT-KEY."
13576 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13577 arch-alist inst-alist ent-inst-list
13578 ent-entry arch-entry inst-entry)
13580 (setq ent-entry (car ent-alist))
13581 (setq arch-alist (nth 4 ent-entry))
13583 (setq arch-entry (car arch-alist))
13584 (setq inst-alist (nth 4 arch-entry))
13586 (setq inst-entry (car inst-alist))
13587 (when (equal ent-key (nth 5 inst-entry))
13588 (setq ent-inst-list
13589 (cons (list (nth 1 inst-entry)
13590 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13592 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13594 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13596 (setq inst-alist (cdr inst-alist)))
13597 (setq arch-alist (cdr arch-alist)))
13598 (setq ent-alist (cdr ent-alist)))
13599 (nreverse ent-inst-list)))
13601 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13604 (defun vhdl-save-caches ()
13605 "Save all updated hierarchy caches to file."
13607 (condition-case nil
13608 (when vhdl-speedbar-save-cache
13609 ;; update hierarchy
13610 (vhdl-update-hierarchy)
13611 (let ((project-list vhdl-updated-project-list))
13612 (message "Saving hierarchy caches...")
13613 ;; write updated project caches
13614 (while project-list
13615 (vhdl-save-cache (car project-list))
13616 (setq project-list (cdr project-list)))
13617 (message "Saving hierarchy caches...done")))
13618 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13621 (defun vhdl-save-cache (key)
13622 "Save current hierarchy cache to file."
13623 (let* ((orig-buffer (current-buffer))
13625 (project (vhdl-project-p))
13626 (default-directory key)
13627 (directory (abbreviate-file-name (vhdl-default-directory)))
13628 (file-name (vhdl-resolve-env-variable
13629 (vhdl-replace-string
13630 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13632 (subst-char-in-string ? ?_ (or project "dir"))
13633 " " (user-login-name)))))
13634 (file-dir-name (expand-file-name file-name directory))
13635 (cache-key (or project directory))
13636 (key (if project "project" "directory")))
13637 (unless (file-exists-p (file-name-directory file-dir-name))
13638 (make-directory (file-name-directory file-dir-name) t))
13639 (if (not (file-writable-p file-dir-name))
13640 (progn (vhdl-warning (format "File not writable: \"%s\""
13641 (abbreviate-file-name file-dir-name)))
13643 (message "Saving cache: \"%s\"" file-dir-name)
13644 (set-buffer (find-file-noselect file-dir-name t t))
13646 (insert ";; -*- Emacs-Lisp -*-\n\n"
13647 ";;; " (file-name-nondirectory file-name)
13648 " - design hierarchy cache file for Emacs VHDL Mode "
13650 (insert "\n;; " (if project "Project " "Directory") " : ")
13651 (if project (insert project) (prin1 directory (current-buffer)))
13652 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13653 (user-login-name) "\n\n"
13654 "\n;; version number\n"
13655 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13656 "\n;; " (if project "project" "directory") " name"
13657 "\n(setq " key " ")
13658 (prin1 (or project directory) (current-buffer))
13660 (when (member 'hierarchy vhdl-speedbar-save-cache)
13661 (insert "\n;; entity and architecture cache\n"
13662 "(aput 'vhdl-entity-alist " key " '")
13663 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13664 (insert ")\n\n;; configuration cache\n"
13665 "(aput 'vhdl-config-alist " key " '")
13666 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13667 (insert ")\n\n;; package cache\n"
13668 "(aput 'vhdl-package-alist " key " '")
13669 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13670 (insert ")\n\n;; instantiated entities cache\n"
13671 "(aput 'vhdl-ent-inst-alist " key " '")
13672 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13673 (insert ")\n\n;; design units per file cache\n"
13674 "(aput 'vhdl-file-alist " key " '")
13675 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13677 (insert ")\n\n;; source directories in project cache\n"
13678 "(aput 'vhdl-directory-alist " key " '")
13679 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13681 (when (member 'display vhdl-speedbar-save-cache)
13682 (insert "\n;; shown design units cache\n"
13683 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13684 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13687 (setq vhdl-updated-project-list
13688 (delete cache-key vhdl-updated-project-list))
13690 (kill-buffer (current-buffer))
13691 (set-buffer orig-buffer))))
13693 (defun vhdl-load-cache (key)
13694 "Load hierarchy cache information from file."
13695 (let* ((vhdl-project key)
13696 (default-directory key)
13697 (directory (vhdl-default-directory))
13698 (file-name (vhdl-resolve-env-variable
13699 (vhdl-replace-string
13700 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13702 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13703 " " (user-login-name)))))
13704 (file-dir-name (expand-file-name file-name directory))
13705 vhdl-cache-version)
13706 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13707 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13708 (when (file-exists-p file-dir-name)
13710 (progn (load-file file-dir-name)
13711 (string< (mapconcat
13712 (lambda (a) (format "%3d" (string-to-number a)))
13713 (split-string "3.31.14" "\\.") "")
13715 (lambda (a) (format "%3d" (string-to-number a)))
13716 (split-string vhdl-cache-version "\\.") "")))
13717 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13720 (defun vhdl-require-hierarchy-info ()
13721 "Make sure that hierarchy information is available. Load cache or scan files
13723 (if (vhdl-project-p)
13724 (unless (or (assoc vhdl-project vhdl-file-alist)
13725 (vhdl-load-cache vhdl-project))
13726 (vhdl-scan-project-contents vhdl-project))
13727 (let ((directory (abbreviate-file-name default-directory)))
13728 (unless (or (assoc directory vhdl-file-alist)
13729 (vhdl-load-cache directory))
13730 (vhdl-scan-directory-contents directory)))))
13732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13733 ;; Add hierarchy browser functionality to speedbar
13735 (defvar vhdl-speedbar-key-map nil
13736 "Keymap used when in the VHDL hierarchy browser mode.")
13738 (defvar vhdl-speedbar-menu-items nil
13739 "Additional menu-items to add to speedbar frame.")
13741 (defun vhdl-speedbar-initialize ()
13742 "Initialize speedbar."
13743 ;; general settings
13744 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13745 ;; VHDL file extensions (extracted from `auto-mode-alist')
13746 (let ((mode-alist auto-mode-alist))
13748 (when (eq (cdar mode-alist) 'vhdl-mode)
13749 (speedbar-add-supported-extension (caar mode-alist)))
13750 (setq mode-alist (cdr mode-alist))))
13751 ;; hierarchy browser settings
13752 (when (boundp 'speedbar-mode-functions-list)
13753 ;; special functions
13754 (speedbar-add-mode-functions-list
13756 (speedbar-item-info . vhdl-speedbar-item-info)
13757 (speedbar-line-path . speedbar-files-line-path)))
13758 (speedbar-add-mode-functions-list
13760 (speedbar-item-info . vhdl-speedbar-item-info)
13761 (speedbar-line-path . vhdl-speedbar-line-project)))
13763 (unless vhdl-speedbar-key-map
13764 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13765 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13766 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13767 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13768 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13769 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13770 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13771 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13772 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13773 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13774 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13775 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13778 (define-key vhdl-speedbar-key-map (int-to-string key)
13779 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13780 (setq key (1+ key)))))
13781 (define-key speedbar-key-map "h"
13782 (lambda () (interactive)
13783 (speedbar-change-initial-expansion-list "vhdl directory")))
13784 (define-key speedbar-key-map "H"
13785 (lambda () (interactive)
13786 (speedbar-change-initial-expansion-list "vhdl project")))
13788 (unless vhdl-speedbar-menu-items
13790 vhdl-speedbar-menu-items
13791 `(["Edit" speedbar-edit-line t]
13792 ["Expand" speedbar-expand-line
13793 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13794 ["Contract" vhdl-speedbar-contract-level t]
13795 ["Expand All" vhdl-speedbar-expand-all t]
13796 ["Contract All" vhdl-speedbar-contract-all t]
13797 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13800 (cons `[,(if (= key 0) "All" (int-to-string key))
13801 (vhdl-speedbar-set-depth ,key)
13803 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13804 :keys ,(int-to-string key)]
13806 (setq key (1+ key)))
13807 (nreverse menu-list))
13809 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13810 (or (vhdl-speedbar-check-unit 'entity)
13811 (vhdl-speedbar-check-unit 'subprogram))]
13812 ["Place Component" vhdl-speedbar-place-component
13813 (vhdl-speedbar-check-unit 'entity)]
13814 ["Make" vhdl-speedbar-make-design
13815 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
13816 ["Generate Makefile" vhdl-speedbar-generate-makefile
13817 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
13818 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
13819 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13820 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
13821 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
13822 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13823 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
13824 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
13826 (speedbar-add-expansion-list
13827 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13828 vhdl-speedbar-display-directory))
13829 (speedbar-add-expansion-list
13830 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13831 vhdl-speedbar-display-projects))
13832 (setq speedbar-stealthy-function-list
13834 '(("vhdl directory" vhdl-speedbar-update-current-unit)
13835 ("vhdl project" vhdl-speedbar-update-current-project
13836 vhdl-speedbar-update-current-unit)
13837 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
13838 ; (speedbar-extension-list-to-regex
13839 ; speedbar-ignored-path-expressions))))
13841 speedbar-stealthy-function-list))
13842 (when (eq vhdl-speedbar-display-mode 'directory)
13843 (setq speedbar-initial-expansion-list-name "vhdl directory"))
13844 (when (eq vhdl-speedbar-display-mode 'project)
13845 (setq speedbar-initial-expansion-list-name "vhdl project"))
13846 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
13848 (defun vhdl-speedbar (&optional arg)
13849 "Open/close speedbar."
13851 (if (not (fboundp 'speedbar))
13852 (error "WARNING: Speedbar is not available or not installed")
13854 (speedbar-frame-mode arg)
13855 (error (error "WARNING: An error occurred while opening speedbar")))))
13857 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13858 ;; Display functions
13860 (defvar vhdl-speedbar-last-selected-project nil
13861 "Name of last selected project.")
13863 ;; macros must be defined in the file they are used (copied from `speedbar.el')
13864 (defmacro speedbar-with-writable (&rest forms)
13865 "Allow the buffer to be writable and evaluate FORMS."
13866 (list 'let '((inhibit-read-only t))
13867 (cons 'progn forms)))
13868 (put 'speedbar-with-writable 'lisp-indent-function 0)
13870 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
13871 "Display directory and hierarchy information in speedbar."
13872 (setq vhdl-speedbar-show-projects nil)
13873 (setq speedbar-ignored-path-regexp
13874 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
13875 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
13876 (setq speedbar-last-selected-file nil)
13877 (speedbar-with-writable
13878 (condition-case nil
13880 ;; insert directory path
13881 (speedbar-directory-buttons directory depth)
13882 ;; insert subdirectories
13883 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
13884 ;; scan and insert hierarchy of current directory
13885 (vhdl-speedbar-insert-dir-hierarchy directory depth
13886 speedbar-power-click)
13887 ;; expand subdirectories
13888 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
13889 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
13891 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
13892 "Display projects and hierarchy information in speedbar."
13893 (setq vhdl-speedbar-show-projects t)
13894 (setq speedbar-ignored-path-regexp ".")
13895 (setq speedbar-last-selected-file nil)
13896 (setq vhdl-speedbar-last-selected-project nil)
13897 (speedbar-with-writable
13898 (condition-case nil
13900 (vhdl-speedbar-insert-projects)
13901 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
13902 (setq speedbar-full-text-cache nil)) ; prevent caching
13904 (defun vhdl-speedbar-insert-projects ()
13905 "Insert all projects in speedbar."
13906 (vhdl-speedbar-make-title-line "Projects:")
13907 (let ((project-alist (if vhdl-project-sort
13908 (vhdl-sort-alist (copy-alist vhdl-project-alist))
13909 vhdl-project-alist))
13910 (vhdl-speedbar-update-current-unit nil))
13912 (while project-alist
13913 (speedbar-make-tag-line
13914 'angle ?+ 'vhdl-speedbar-expand-project
13915 (caar project-alist) (caar project-alist)
13916 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
13917 (setq project-alist (cdr project-alist)))
13918 (setq project-alist vhdl-project-alist)
13920 (while project-alist
13921 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
13922 (goto-char (point-min))
13923 (when (re-search-forward
13924 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
13925 (goto-char (match-end 1))
13926 (speedbar-do-function-pointer)))
13927 (setq project-alist (cdr project-alist))))
13928 ; (vhdl-speedbar-update-current-project)
13929 ; (vhdl-speedbar-update-current-unit nil t)
13932 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
13933 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
13934 otherwise use cached data."
13935 (when (or rescan (and (not (assoc project vhdl-file-alist))
13936 (not (vhdl-load-cache project))))
13937 (vhdl-scan-project-contents project))
13938 ;; insert design hierarchy
13939 (vhdl-speedbar-insert-hierarchy
13940 (aget vhdl-entity-alist project t)
13941 (aget vhdl-config-alist project t)
13942 (aget vhdl-package-alist project t)
13943 (car (aget vhdl-ent-inst-alist project t)) indent)
13944 (insert (int-to-string indent) ":\n")
13945 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
13946 (put-text-property (1- (point)) (point) 'invisible nil)
13947 ;; expand design units
13948 (vhdl-speedbar-expand-units project))
13950 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
13951 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
13952 otherwise use cached data."
13953 (when (or rescan (and (not (assoc directory vhdl-file-alist))
13954 (not (vhdl-load-cache directory))))
13955 (vhdl-scan-directory-contents directory))
13956 ;; insert design hierarchy
13957 (vhdl-speedbar-insert-hierarchy
13958 (aget vhdl-entity-alist directory t)
13959 (aget vhdl-config-alist directory t)
13960 (aget vhdl-package-alist directory t)
13961 (car (aget vhdl-ent-inst-alist directory t)) depth)
13962 ;; expand design units
13963 (vhdl-speedbar-expand-units directory)
13964 (aput 'vhdl-directory-alist directory (list (list directory))))
13966 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
13967 ent-inst-list depth)
13968 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
13969 (if (not (or ent-alist conf-alist pack-alist))
13970 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
13971 (let (ent-entry conf-entry pack-entry)
13973 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
13975 (setq ent-entry (car ent-alist))
13976 (speedbar-make-tag-line
13977 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
13978 (nth 1 ent-entry) 'vhdl-speedbar-find-file
13979 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13980 'vhdl-speedbar-entity depth)
13981 (unless (nth 2 ent-entry)
13982 (end-of-line 0) (insert "!") (forward-char 1))
13983 (unless (member (nth 0 ent-entry) ent-inst-list)
13984 (end-of-line 0) (insert " (top)") (forward-char 1))
13985 (setq ent-alist (cdr ent-alist)))
13986 ;; insert configurations
13987 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
13989 (setq conf-entry (car conf-alist))
13990 (speedbar-make-tag-line
13991 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
13992 (nth 1 conf-entry) 'vhdl-speedbar-find-file
13993 (cons (nth 2 conf-entry) (nth 3 conf-entry))
13994 'vhdl-speedbar-configuration depth)
13995 (setq conf-alist (cdr conf-alist)))
13997 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
13999 (setq pack-entry (car pack-alist))
14000 (vhdl-speedbar-make-pack-line
14001 (nth 0 pack-entry) (nth 1 pack-entry)
14002 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14003 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14005 (setq pack-alist (cdr pack-alist))))))
14007 (defun vhdl-speedbar-rescan-hierarchy ()
14008 "Rescan hierarchy for the directory or project under the cursor."
14013 (vhdl-speedbar-show-projects
14014 (setq key (vhdl-speedbar-line-project))
14015 (vhdl-scan-project-contents key))
14016 ;; top-level directory
14017 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14018 (re-search-forward "[0-9]+:" nil t)
14019 (vhdl-scan-directory-contents
14020 (abbreviate-file-name (speedbar-line-path))))
14021 ;; current directory
14022 (t (setq path (speedbar-line-path))
14023 (string-match "^\\(.+[/\\]\\)" path)
14024 (vhdl-scan-directory-contents
14025 (abbreviate-file-name (match-string 1 path)))))
14026 (vhdl-speedbar-refresh key)))
14028 (defun vhdl-speedbar-expand-dirs (directory)
14029 "Expand subdirectories in DIRECTORY according to
14030 `speedbar-shown-directories'."
14031 ;; (nicked from `speedbar-default-directory-list')
14032 (let ((sf (cdr (reverse speedbar-shown-directories)))
14033 (vhdl-speedbar-update-current-unit nil))
14034 (setq speedbar-shown-directories
14035 (list (expand-file-name default-directory)))
14037 (when (speedbar-goto-this-file (car sf))
14038 (beginning-of-line)
14039 (when (looking-at "[0-9]+:\\s-*<")
14040 (goto-char (match-end 0))
14041 (speedbar-do-function-pointer)))
14042 (setq sf (cdr sf))))
14043 (vhdl-speedbar-update-current-unit nil t))
14045 (defun vhdl-speedbar-expand-units (key)
14046 "Expand design units in directory/project KEY according to
14047 `vhdl-speedbar-shown-unit-alist'."
14048 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14049 (vhdl-speedbar-update-current-unit nil)
14050 vhdl-updated-project-list)
14051 (adelete 'vhdl-speedbar-shown-unit-alist key)
14052 (vhdl-prepare-search-1
14053 (while unit-alist ; expand units
14054 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14055 (beginning-of-line)
14056 (let ((arch-alist (nth 1 (car unit-alist)))
14058 (when (looking-at "^[0-9]+:\\s-*\\[")
14059 (goto-char (match-end 0))
14060 (setq position (point))
14061 (speedbar-do-function-pointer)
14062 (select-frame speedbar-frame)
14063 (while arch-alist ; expand architectures
14064 (goto-char position)
14065 (when (re-search-forward
14066 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14067 (car arch-alist) "\\>\\)") nil t)
14068 (beginning-of-line)
14069 (when (looking-at "^[0-9]+:\\s-*{")
14070 (goto-char (match-end 0))
14071 (speedbar-do-function-pointer)
14072 (select-frame speedbar-frame)))
14073 (setq arch-alist (cdr arch-alist))))
14074 (setq unit-alist (cdr unit-alist))))))
14075 (vhdl-speedbar-update-current-unit nil t))
14077 (defun vhdl-speedbar-contract-level ()
14078 "Contract current level in current directory/project."
14080 (when (or (save-excursion
14081 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14082 (and (save-excursion
14083 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14084 (re-search-backward
14085 (format "^[0-%d]:\\s-*[[{<]-"
14086 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14087 (goto-char (match-end 0))
14088 (speedbar-do-function-pointer)
14089 (speedbar-center-buffer-smartly)))
14091 (defun vhdl-speedbar-contract-all ()
14092 "Contract all expanded design units in current directory/project."
14094 (if (and vhdl-speedbar-show-projects
14095 (save-excursion (beginning-of-line) (looking-at "^0:")))
14096 (progn (setq vhdl-speedbar-shown-project-list nil)
14097 (vhdl-speedbar-refresh))
14098 (let ((key (vhdl-speedbar-line-key)))
14099 (adelete 'vhdl-speedbar-shown-unit-alist key)
14100 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14101 (when (memq 'display vhdl-speedbar-save-cache)
14102 (add-to-list 'vhdl-updated-project-list key)))))
14104 (defun vhdl-speedbar-expand-all ()
14105 "Expand all design units in current directory/project."
14107 (let* ((key (vhdl-speedbar-line-key))
14108 (ent-alist (aget vhdl-entity-alist key t))
14109 (conf-alist (aget vhdl-config-alist key t))
14110 (pack-alist (aget vhdl-package-alist key t))
14111 arch-alist unit-alist subunit-alist)
14112 (add-to-list 'vhdl-speedbar-shown-project-list key)
14114 (setq arch-alist (nth 4 (car ent-alist)))
14115 (setq subunit-alist nil)
14117 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14118 (setq arch-alist (cdr arch-alist)))
14119 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14120 (setq ent-alist (cdr ent-alist)))
14122 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14123 (setq conf-alist (cdr conf-alist)))
14125 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14126 (setq pack-alist (cdr pack-alist)))
14127 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14128 (vhdl-speedbar-refresh)
14129 (when (memq 'display vhdl-speedbar-save-cache)
14130 (add-to-list 'vhdl-updated-project-list key))))
14132 (defun vhdl-speedbar-expand-project (text token indent)
14133 "Expand/contract the project under the cursor."
14135 ((string-match "+" text) ; expand project
14136 (speedbar-change-expand-button-char ?-)
14137 (unless (member token vhdl-speedbar-shown-project-list)
14138 (setq vhdl-speedbar-shown-project-list
14139 (cons token vhdl-speedbar-shown-project-list)))
14140 (speedbar-with-writable
14142 (end-of-line) (forward-char 1)
14143 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14144 speedbar-power-click))))
14145 ((string-match "-" text) ; contract project
14146 (speedbar-change-expand-button-char ?+)
14147 (setq vhdl-speedbar-shown-project-list
14148 (delete token vhdl-speedbar-shown-project-list))
14149 (speedbar-delete-subblock indent))
14150 (t (error "Nothing to display")))
14151 (when (equal (selected-frame) speedbar-frame)
14152 (speedbar-center-buffer-smartly)))
14154 (defun vhdl-speedbar-expand-entity (text token indent)
14155 "Expand/contract the entity under the cursor."
14157 ((string-match "+" text) ; expand entity
14158 (let* ((key (vhdl-speedbar-line-key indent))
14159 (ent-alist (aget vhdl-entity-alist key t))
14160 (ent-entry (aget ent-alist token t))
14161 (arch-alist (nth 3 ent-entry))
14162 (inst-alist (vhdl-get-instantiations token indent))
14163 (subpack-alist (nth 4 ent-entry))
14164 arch-entry inst-entry)
14165 (if (not (or arch-alist inst-alist subpack-alist))
14166 (speedbar-change-expand-button-char ??)
14167 (speedbar-change-expand-button-char ?-)
14168 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14169 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14170 (aput 'unit-alist token nil)
14171 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14172 (speedbar-with-writable
14174 (end-of-line) (forward-char 1)
14175 ;; insert architectures
14177 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14179 (setq arch-entry (car arch-alist))
14180 (speedbar-make-tag-line
14181 'curly ?+ 'vhdl-speedbar-expand-architecture
14182 (cons token (nth 0 arch-entry))
14183 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14184 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14185 'vhdl-speedbar-architecture (1+ indent))
14186 (setq arch-alist (cdr arch-alist)))
14187 ;; insert instantiations
14189 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14191 (setq inst-entry (car inst-alist))
14192 (vhdl-speedbar-make-inst-line
14193 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14194 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14195 nil nil nil (1+ indent) 0 " in ")
14196 (setq inst-alist (cdr inst-alist)))
14197 ;; insert required packages
14198 (vhdl-speedbar-insert-subpackages
14199 subpack-alist (1+ indent) indent)))
14200 (when (memq 'display vhdl-speedbar-save-cache)
14201 (add-to-list 'vhdl-updated-project-list key))
14202 (vhdl-speedbar-update-current-unit t t))))
14203 ((string-match "-" text) ; contract entity
14204 (speedbar-change-expand-button-char ?+)
14205 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14206 (let* ((key (vhdl-speedbar-line-key indent))
14207 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14208 (adelete 'unit-alist token)
14210 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14211 (adelete 'vhdl-speedbar-shown-unit-alist key))
14212 (speedbar-delete-subblock indent)
14213 (when (memq 'display vhdl-speedbar-save-cache)
14214 (add-to-list 'vhdl-updated-project-list key))))
14215 (t (error "Nothing to display")))
14216 (when (equal (selected-frame) speedbar-frame)
14217 (speedbar-center-buffer-smartly)))
14219 (defun vhdl-speedbar-expand-architecture (text token indent)
14220 "Expand/contract the architecture under the cursor."
14222 ((string-match "+" text) ; expand architecture
14223 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14224 (ent-alist (aget vhdl-entity-alist key t))
14225 (conf-alist (aget vhdl-config-alist key t))
14226 (hier-alist (vhdl-get-hierarchy
14227 ent-alist conf-alist (car token) (cdr token) nil nil
14229 (ent-entry (aget ent-alist (car token) t))
14230 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14231 (subpack-alist (nth 4 arch-entry))
14233 (if (not (or hier-alist subpack-alist))
14234 (speedbar-change-expand-button-char ??)
14235 (speedbar-change-expand-button-char ?-)
14236 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14237 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14238 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14239 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14240 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14241 (speedbar-with-writable
14243 (end-of-line) (forward-char 1)
14244 ;; insert instance hierarchy
14246 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14249 (setq entry (car hier-alist))
14250 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14251 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14252 (vhdl-speedbar-make-inst-line
14253 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14254 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14255 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14256 (setq hier-alist (cdr hier-alist)))
14257 ;; insert required packages
14258 (vhdl-speedbar-insert-subpackages
14259 subpack-alist (1+ indent) (1- indent))))
14260 (when (memq 'display vhdl-speedbar-save-cache)
14261 (add-to-list 'vhdl-updated-project-list key))
14262 (vhdl-speedbar-update-current-unit t t))))
14263 ((string-match "-" text) ; contract architecture
14264 (speedbar-change-expand-button-char ?+)
14265 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14266 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14267 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14268 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14269 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14270 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14271 (speedbar-delete-subblock indent)
14272 (when (memq 'display vhdl-speedbar-save-cache)
14273 (add-to-list 'vhdl-updated-project-list key))))
14274 (t (error "Nothing to display")))
14275 (when (equal (selected-frame) speedbar-frame)
14276 (speedbar-center-buffer-smartly)))
14278 (defun vhdl-speedbar-expand-config (text token indent)
14279 "Expand/contract the configuration under the cursor."
14281 ((string-match "+" text) ; expand configuration
14282 (let* ((key (vhdl-speedbar-line-key indent))
14283 (conf-alist (aget vhdl-config-alist key t))
14284 (conf-entry (aget conf-alist token))
14285 (ent-alist (aget vhdl-entity-alist key t))
14286 (hier-alist (vhdl-get-hierarchy
14287 ent-alist conf-alist (nth 3 conf-entry)
14288 (nth 4 conf-entry) token (nth 5 conf-entry)
14290 (subpack-alist (nth 6 conf-entry))
14292 (if (not (or hier-alist subpack-alist))
14293 (speedbar-change-expand-button-char ??)
14294 (speedbar-change-expand-button-char ?-)
14295 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14296 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14297 (aput 'unit-alist token nil)
14298 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14299 (speedbar-with-writable
14301 (end-of-line) (forward-char 1)
14302 ;; insert instance hierarchy
14304 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14306 (setq entry (car hier-alist))
14307 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14308 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14309 (vhdl-speedbar-make-inst-line
14310 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14311 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14312 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14313 (setq hier-alist (cdr hier-alist)))
14314 ;; insert required packages
14315 (vhdl-speedbar-insert-subpackages
14316 subpack-alist (1+ indent) indent)))
14317 (when (memq 'display vhdl-speedbar-save-cache)
14318 (add-to-list 'vhdl-updated-project-list key))
14319 (vhdl-speedbar-update-current-unit t t))))
14320 ((string-match "-" text) ; contract configuration
14321 (speedbar-change-expand-button-char ?+)
14322 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14323 (let* ((key (vhdl-speedbar-line-key indent))
14324 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14325 (adelete 'unit-alist token)
14327 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14328 (adelete 'vhdl-speedbar-shown-unit-alist key))
14329 (speedbar-delete-subblock indent)
14330 (when (memq 'display vhdl-speedbar-save-cache)
14331 (add-to-list 'vhdl-updated-project-list key))))
14332 (t (error "Nothing to display")))
14333 (when (equal (selected-frame) speedbar-frame)
14334 (speedbar-center-buffer-smartly)))
14336 (defun vhdl-speedbar-expand-package (text token indent)
14337 "Expand/contract the package under the cursor."
14339 ((string-match "+" text) ; expand package
14340 (let* ((key (vhdl-speedbar-line-key indent))
14341 (pack-alist (aget vhdl-package-alist key t))
14342 (pack-entry (aget pack-alist token t))
14343 (comp-alist (nth 3 pack-entry))
14344 (func-alist (nth 4 pack-entry))
14345 (func-body-alist (nth 8 pack-entry))
14346 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14347 comp-entry func-entry func-body-entry)
14348 (if (not (or comp-alist func-alist subpack-alist))
14349 (speedbar-change-expand-button-char ??)
14350 (speedbar-change-expand-button-char ?-)
14351 ;; add package to `vhdl-speedbar-shown-unit-alist'
14352 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14353 (aput 'unit-alist token nil)
14354 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14355 (speedbar-with-writable
14357 (end-of-line) (forward-char 1)
14358 ;; insert components
14360 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14362 (setq comp-entry (car comp-alist))
14363 (speedbar-make-tag-line
14365 (cons token (nth 0 comp-entry))
14366 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14367 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14368 'vhdl-speedbar-entity (1+ indent))
14369 (setq comp-alist (cdr comp-alist)))
14370 ;; insert subprograms
14372 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14374 (setq func-entry (car func-alist)
14375 func-body-entry (aget func-body-alist (car func-entry) t))
14376 (when (nth 2 func-entry)
14377 (vhdl-speedbar-make-subprogram-line
14379 (cons (nth 2 func-entry) (nth 3 func-entry))
14380 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14382 (setq func-alist (cdr func-alist)))
14383 ;; insert required packages
14384 (vhdl-speedbar-insert-subpackages
14385 subpack-alist (1+ indent) indent)))
14386 (when (memq 'display vhdl-speedbar-save-cache)
14387 (add-to-list 'vhdl-updated-project-list key))
14388 (vhdl-speedbar-update-current-unit t t))))
14389 ((string-match "-" text) ; contract package
14390 (speedbar-change-expand-button-char ?+)
14391 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14392 (let* ((key (vhdl-speedbar-line-key indent))
14393 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14394 (adelete 'unit-alist token)
14396 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14397 (adelete 'vhdl-speedbar-shown-unit-alist key))
14398 (speedbar-delete-subblock indent)
14399 (when (memq 'display vhdl-speedbar-save-cache)
14400 (add-to-list 'vhdl-updated-project-list key))))
14401 (t (error "Nothing to display")))
14402 (when (equal (selected-frame) speedbar-frame)
14403 (speedbar-center-buffer-smartly)))
14405 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14406 "Insert required packages."
14407 (let* ((pack-alist (aget vhdl-package-alist
14408 (vhdl-speedbar-line-key dir-indent) t))
14409 pack-key lib-name pack-entry)
14410 (when subpack-alist
14411 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14412 (while subpack-alist
14413 (setq pack-key (cdar subpack-alist)
14414 lib-name (caar subpack-alist))
14415 (setq pack-entry (aget pack-alist pack-key t))
14416 (vhdl-speedbar-make-subpack-line
14417 (or (nth 0 pack-entry) pack-key) lib-name
14418 (cons (nth 1 pack-entry) (nth 2 pack-entry)) indent)
14419 (setq subpack-alist (cdr subpack-alist)))))
14421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14422 ;; Display help functions
14424 (defvar vhdl-speedbar-update-current-unit t
14425 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14427 (defun vhdl-speedbar-update-current-project ()
14428 "Highlight project that is currently active."
14429 (when (and vhdl-speedbar-show-projects
14430 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14431 (and (boundp 'speedbar-frame)
14432 (frame-live-p speedbar-frame)))
14433 (let ((last-frame (selected-frame))
14434 (project-alist vhdl-project-alist)
14436 (select-frame speedbar-frame)
14437 (speedbar-with-writable
14439 (while project-alist
14440 (goto-char (point-min))
14441 (when (re-search-forward
14442 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14443 (put-text-property (match-beginning 1) (match-end 1) 'face
14444 (if (equal (caar project-alist) vhdl-project)
14445 'speedbar-selected-face
14446 'speedbar-directory-face))
14447 (when (equal (caar project-alist) vhdl-project)
14448 (setq pos (1- (match-beginning 1)))))
14449 (setq project-alist (cdr project-alist))))
14450 (when pos (goto-char pos)))
14451 (select-frame last-frame)
14452 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14455 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14456 "Highlight all design units that are contained in the current file.
14457 NO-POSITION non-nil means do not re-position cursor."
14458 (let ((last-frame (selected-frame))
14459 (project-list vhdl-speedbar-shown-project-list)
14460 file-alist pos file-name)
14461 ;; get current file name
14462 (if (fboundp 'speedbar-select-attached-frame)
14463 (speedbar-select-attached-frame)
14464 (select-frame speedbar-attached-frame))
14465 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14466 (when (and vhdl-speedbar-update-current-unit
14467 (or always (not (equal file-name speedbar-last-selected-file))))
14468 (if vhdl-speedbar-show-projects
14469 (while project-list
14470 (setq file-alist (append file-alist (aget vhdl-file-alist
14471 (car project-list) t)))
14472 (setq project-list (cdr project-list)))
14473 (setq file-alist (aget vhdl-file-alist
14474 (abbreviate-file-name default-directory) t)))
14475 (select-frame speedbar-frame)
14476 (set-buffer speedbar-buffer)
14477 (speedbar-with-writable
14478 (vhdl-prepare-search-1
14480 ;; unhighlight last units
14481 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14482 (vhdl-speedbar-update-units
14483 "\\[.\\] " (nth 0 file-entry)
14484 speedbar-last-selected-file 'vhdl-speedbar-entity)
14485 (vhdl-speedbar-update-units
14486 "{.} " (nth 1 file-entry)
14487 speedbar-last-selected-file 'vhdl-speedbar-architecture)
14488 (vhdl-speedbar-update-units
14489 "\\[.\\] " (nth 3 file-entry)
14490 speedbar-last-selected-file 'vhdl-speedbar-configuration)
14491 (vhdl-speedbar-update-units
14492 "[]>] " (nth 4 file-entry)
14493 speedbar-last-selected-file 'vhdl-speedbar-package)
14494 (vhdl-speedbar-update-units
14495 "\\[.\\].+(" '("body")
14496 speedbar-last-selected-file 'vhdl-speedbar-package)
14497 (vhdl-speedbar-update-units
14498 "> " (nth 6 file-entry)
14499 speedbar-last-selected-file 'vhdl-speedbar-instantiation))
14500 ;; highlight current units
14501 (let* ((file-entry (aget file-alist file-name t)))
14503 pos (vhdl-speedbar-update-units
14504 "\\[.\\] " (nth 0 file-entry)
14505 file-name 'vhdl-speedbar-entity-selected pos)
14506 pos (vhdl-speedbar-update-units
14507 "{.} " (nth 1 file-entry)
14508 file-name 'vhdl-speedbar-architecture-selected pos)
14509 pos (vhdl-speedbar-update-units
14510 "\\[.\\] " (nth 3 file-entry)
14511 file-name 'vhdl-speedbar-configuration-selected pos)
14512 pos (vhdl-speedbar-update-units
14513 "[]>] " (nth 4 file-entry)
14514 file-name 'vhdl-speedbar-package-selected pos)
14515 pos (vhdl-speedbar-update-units
14516 "\\[.\\].+(" '("body")
14517 file-name 'vhdl-speedbar-package-selected pos)
14518 pos (vhdl-speedbar-update-units
14519 "> " (nth 6 file-entry)
14520 file-name 'vhdl-speedbar-instantiation-selected pos))))))
14521 ;; move speedbar so the first highlighted unit is visible
14522 (when (and pos (not no-position))
14524 (speedbar-center-buffer-smartly)
14525 (speedbar-position-cursor-on-line))
14526 (setq speedbar-last-selected-file file-name))
14527 (select-frame last-frame)
14530 (defun vhdl-speedbar-update-units (text unit-list file-name face
14532 "Help function to highlight design units."
14534 (goto-char (point-min))
14535 (while (re-search-forward
14536 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14537 (when (equal file-name (car (get-text-property
14538 (match-beginning 1) 'speedbar-token)))
14539 (setq pos (or pos (point-marker)))
14540 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14541 (setq unit-list (cdr unit-list)))
14544 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14545 ent-name ent-file-marker
14546 arch-name arch-file-marker
14547 conf-name conf-file-marker
14548 lib-name depth offset delimiter)
14549 "Insert instantiation entry."
14550 (let ((start (point))
14552 (insert (int-to-string depth) ":")
14553 (put-text-property start (point) 'invisible t)
14554 (setq visible-start (point))
14555 (insert-char ? (* depth speedbar-indentation-width))
14556 (while (> offset 0)
14558 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14559 (setq offset (1- offset)))
14560 (put-text-property visible-start (point) 'invisible nil)
14561 (setq start (point))
14563 (speedbar-make-button start (point) nil nil nil)
14564 (setq visible-start (point))
14566 (setq start (point))
14567 (if (not inst-name)
14570 (speedbar-make-button
14571 start (point) 'vhdl-speedbar-instantiation 'speedbar-highlight-face
14572 'vhdl-speedbar-find-file inst-file-marker))
14575 (setq start (point))
14577 (speedbar-make-button
14578 start (point) 'vhdl-speedbar-entity 'speedbar-highlight-face
14579 'vhdl-speedbar-find-file ent-file-marker)
14582 (setq start (point))
14584 (speedbar-make-button
14585 start (point) 'vhdl-speedbar-architecture 'speedbar-highlight-face
14586 'vhdl-speedbar-find-file arch-file-marker)
14590 (setq start (point))
14592 (speedbar-make-button
14593 start (point) 'vhdl-speedbar-configuration 'speedbar-highlight-face
14594 'vhdl-speedbar-find-file conf-file-marker)
14596 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14597 (setq start (point))
14598 (insert " (" lib-name ")")
14599 (put-text-property (+ 2 start) (1- (point)) 'face
14600 'vhdl-speedbar-library))
14601 (insert-char ?\n 1)
14602 (put-text-property visible-start (point) 'invisible nil)))
14604 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14605 body-file-marker depth)
14606 "Insert package entry."
14607 (let ((start (point))
14609 (insert (int-to-string depth) ":")
14610 (put-text-property start (point) 'invisible t)
14611 (setq visible-start (point))
14612 (insert-char ? (* depth speedbar-indentation-width))
14613 (put-text-property visible-start (point) 'invisible nil)
14614 (setq start (point))
14616 (speedbar-make-button
14617 start (point) 'speedbar-button-face 'speedbar-highlight-face
14618 'vhdl-speedbar-expand-package pack-key)
14619 (setq visible-start (point))
14620 (insert-char ? 1 nil)
14621 (setq start (point))
14623 (speedbar-make-button
14624 start (point) 'vhdl-speedbar-package 'speedbar-highlight-face
14625 'vhdl-speedbar-find-file pack-file-marker)
14626 (unless (car pack-file-marker)
14628 (when (car body-file-marker)
14630 (setq start (point))
14632 (speedbar-make-button
14633 start (point) 'vhdl-speedbar-package 'speedbar-highlight-face
14634 'vhdl-speedbar-find-file body-file-marker)
14636 (insert-char ?\n 1)
14637 (put-text-property visible-start (point) 'invisible nil)))
14639 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14641 "Insert used package entry."
14642 (let ((start (point))
14644 (insert (int-to-string depth) ":")
14645 (put-text-property start (point) 'invisible t)
14646 (setq visible-start (point))
14647 (insert-char ? (* depth speedbar-indentation-width))
14648 (put-text-property visible-start (point) 'invisible nil)
14649 (setq start (point))
14651 (speedbar-make-button start (point) nil nil nil)
14652 (setq visible-start (point))
14654 (setq start (point))
14656 (speedbar-make-button
14657 start (point) 'vhdl-speedbar-package 'speedbar-highlight-face
14658 'vhdl-speedbar-find-file pack-file-marker)
14659 (setq start (point))
14660 (insert " (" lib-name ")")
14661 (put-text-property (+ 2 start) (1- (point)) 'face
14662 'vhdl-speedbar-library)
14663 (insert-char ?\n 1)
14664 (put-text-property visible-start (point) 'invisible nil)))
14666 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14667 func-body-file-marker
14669 "Insert subprogram entry."
14670 (let ((start (point))
14672 (insert (int-to-string depth) ":")
14673 (put-text-property start (point) 'invisible t)
14674 (setq visible-start (point))
14675 (insert-char ? (* depth speedbar-indentation-width))
14676 (put-text-property visible-start (point) 'invisible nil)
14677 (setq start (point))
14679 (speedbar-make-button start (point) nil nil nil)
14680 (setq visible-start (point))
14682 (setq start (point))
14684 (speedbar-make-button
14685 start (point) 'vhdl-speedbar-subprogram 'speedbar-highlight-face
14686 'vhdl-speedbar-find-file func-file-marker)
14687 (when (car func-body-file-marker)
14689 (setq start (point))
14691 (speedbar-make-button
14692 start (point) 'vhdl-speedbar-subprogram 'speedbar-highlight-face
14693 'vhdl-speedbar-find-file func-body-file-marker)
14695 (insert-char ?\n 1)
14696 (put-text-property visible-start (point) 'invisible nil)))
14698 (defun vhdl-speedbar-make-title-line (text &optional depth)
14699 "Insert design unit title entry."
14700 (let ((start (point))
14703 (insert (int-to-string depth) ":")
14704 (put-text-property start (point) 'invisible t))
14705 (setq visible-start (point))
14706 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14707 (setq start (point))
14709 (speedbar-make-button start (point) nil nil nil nil)
14710 (insert-char ?\n 1)
14711 (put-text-property visible-start (point) 'invisible nil)))
14713 (defun vhdl-speedbar-insert-dirs (files level)
14714 "Insert subdirectories."
14715 (let ((dirs (car files)))
14717 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14718 (car dirs) 'speedbar-dir-follow nil
14719 'speedbar-directory-face level)
14720 (setq dirs (cdr dirs)))))
14722 (defun vhdl-speedbar-dired (text token indent)
14723 "Speedbar click handler for directory expand button in hierarchy mode."
14724 (cond ((string-match "+" text) ; we have to expand this dir
14725 (setq speedbar-shown-directories
14726 (cons (expand-file-name
14727 (concat (speedbar-line-path indent) token "/"))
14728 speedbar-shown-directories))
14729 (speedbar-change-expand-button-char ?-)
14730 (speedbar-reset-scanners)
14731 (speedbar-with-writable
14733 (end-of-line) (forward-char 1)
14734 (vhdl-speedbar-insert-dirs
14735 (speedbar-file-lists
14736 (concat (speedbar-line-path indent) token "/"))
14738 (speedbar-reset-scanners)
14739 (vhdl-speedbar-insert-dir-hierarchy
14740 (abbreviate-file-name
14741 (concat (speedbar-line-path indent) token "/"))
14742 (1+ indent) speedbar-power-click)))
14743 (vhdl-speedbar-update-current-unit t t))
14744 ((string-match "-" text) ; we have to contract this node
14745 (speedbar-reset-scanners)
14746 (let ((oldl speedbar-shown-directories)
14748 (td (expand-file-name
14749 (concat (speedbar-line-path indent) token))))
14751 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14752 (setq newl (cons (car oldl) newl)))
14753 (setq oldl (cdr oldl)))
14754 (setq speedbar-shown-directories (nreverse newl)))
14755 (speedbar-change-expand-button-char ?+)
14756 (speedbar-delete-subblock indent))
14757 (t (error "Nothing to display")))
14758 (when (equal (selected-frame) speedbar-frame)
14759 (speedbar-center-buffer-smartly)))
14761 (defun vhdl-speedbar-item-info ()
14762 "Derive and display information about this line item."
14764 (beginning-of-line)
14765 ;; skip invisible number info
14766 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
14768 ;; project/directory entry
14769 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14770 (if vhdl-speedbar-show-projects
14771 (message "Project \"%s\"" (match-string-no-properties 1))
14772 (speedbar-files-item-info)))
14773 ;; design unit entry
14774 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14775 (goto-char (match-end 1))
14776 (let ((face (get-text-property (point) 'face)))
14778 "%s \"%s\" in \"%s\""
14779 ;; design unit kind
14780 (cond ((or (eq face 'vhdl-speedbar-entity)
14781 (eq face 'vhdl-speedbar-entity-selected))
14782 (if (equal (match-string 2) ">") "Component" "Entity"))
14783 ((or (eq face 'vhdl-speedbar-architecture)
14784 (eq face 'vhdl-speedbar-architecture-selected))
14786 ((or (eq face 'vhdl-speedbar-configuration)
14787 (eq face 'vhdl-speedbar-configuration-selected))
14789 ((or (eq face 'vhdl-speedbar-package)
14790 (eq face 'vhdl-speedbar-package-selected))
14792 ((or (eq face 'vhdl-speedbar-instantiation)
14793 (eq face 'vhdl-speedbar-instantiation-selected))
14795 ((eq face 'vhdl-speedbar-subprogram)
14798 ;; design unit name
14799 (buffer-substring-no-properties
14800 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14803 (file-relative-name
14804 (or (car (get-text-property (point) 'speedbar-token))
14806 (vhdl-default-directory)))))
14807 (t (message "")))))
14809 (defun vhdl-speedbar-line-text ()
14810 "Calls `speedbar-line-text' and removes text properties."
14811 (let ((string (speedbar-line-text)))
14812 (set-text-properties 0 (length string) nil string)
14815 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14818 (defun vhdl-speedbar-line-key (&optional indent)
14819 "Get currently displayed directory of project name."
14820 (if vhdl-speedbar-show-projects
14821 (vhdl-speedbar-line-project)
14822 (abbreviate-file-name
14823 (file-name-as-directory (speedbar-line-path indent)))))
14825 (defun vhdl-speedbar-line-project (&optional indent)
14826 "Get currently displayed project name."
14827 (and vhdl-speedbar-show-projects
14830 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
14831 (match-string-no-properties 1))))
14833 (defun vhdl-add-modified-file ()
14834 "Add file to `vhdl-modified-file-list'."
14835 (when vhdl-file-alist
14836 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
14839 (defun vhdl-resolve-paths (path-list)
14840 "Resolve path wildcards in PATH-LIST."
14841 (let (path-list-1 path-list-2 path-beg path-end dir)
14842 ;; eliminate non-existent directories
14844 (setq dir (car path-list))
14845 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
14846 (if (file-directory-p (match-string 2 dir))
14847 (setq path-list-1 (cons dir path-list-1))
14848 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
14849 (setq path-list (cdr path-list)))
14850 ;; resolve path wildcards
14852 (setq dir (car path-list-1))
14853 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
14855 (setq path-beg (match-string 1 dir)
14856 path-end (match-string 5 dir))
14861 (lambda (var) (concat path-beg var path-end)))
14862 (let ((all-list (vhdl-directory-files
14863 (match-string 2 dir) t
14864 (concat "\\<" (wildcard-to-regexp
14865 (match-string 4 dir)))))
14868 (when (file-directory-p (car all-list))
14869 (setq dir-list (cons (car all-list) dir-list)))
14870 (setq all-list (cdr all-list)))
14872 (cdr path-list-1))))
14873 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
14874 (when (file-directory-p (match-string 2 dir))
14875 (setq path-list-2 (cons dir path-list-2)))
14876 (setq path-list-1 (cdr path-list-1))))
14877 (nreverse path-list-2)))
14879 (defun vhdl-speedbar-goto-this-unit (directory unit)
14880 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
14881 (let ((dest (point)))
14882 (if (and (if vhdl-speedbar-show-projects
14883 (progn (goto-char (point-min)) t)
14884 (speedbar-goto-this-file directory))
14885 (re-search-forward (concat "[]}] " unit "\\>") nil t))
14886 (progn (speedbar-position-cursor-on-line)
14891 (defun vhdl-speedbar-find-file (text token indent)
14892 "When user clicks on TEXT, load file with name and position in TOKEN.
14893 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
14894 is already shown in a buffer."
14895 (if (not (car token))
14896 (error "ERROR: File cannot be found")
14897 (let ((buffer (get-file-buffer (car token))))
14898 (speedbar-find-file-in-frame (car token))
14899 (when (or vhdl-speedbar-jump-to-unit buffer)
14900 (goto-line (cdr token))
14902 (vhdl-speedbar-update-current-unit t t)
14903 (speedbar-set-timer speedbar-update-speed)
14904 (speedbar-maybee-jump-to-attached-frame))))
14906 (defun vhdl-speedbar-port-copy ()
14907 "Copy the port of the entity/component or subprogram under the cursor."
14909 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
14910 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
14911 (error "ERROR: No entity/component or subprogram under cursor")
14912 (beginning-of-line)
14913 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
14914 (condition-case info
14915 (let ((token (get-text-property
14916 (match-beginning 3) 'speedbar-token)))
14917 (vhdl-visit-file (car token) t
14918 (progn (goto-line (cdr token))
14922 (vhdl-subprog-copy)))))
14923 (error (error "ERROR: %s not scanned successfully\n (%s)"
14924 (if is-entity "Port" "Interface") (cadr info))))
14925 (error "ERROR: No entity/component or subprogram on current line")))))
14927 (defun vhdl-speedbar-place-component ()
14928 "Place the entity/component under the cursor as component."
14930 (if (not (vhdl-speedbar-check-unit 'entity))
14931 (error "ERROR: No entity/component under cursor")
14932 (vhdl-speedbar-port-copy)
14933 (if (fboundp 'speedbar-select-attached-frame)
14934 (speedbar-select-attached-frame)
14935 (select-frame speedbar-attached-frame))
14936 (vhdl-compose-place-component)
14937 (select-frame speedbar-frame)))
14939 (defun vhdl-speedbar-make-design ()
14940 "Make (compile) design unit or directory/project under the cursor."
14942 (if (not (save-excursion (beginning-of-line)
14943 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
14944 (error "ERROR: No primary design unit or directory/project under cursor")
14945 (let ((is-unit (match-string 2))
14946 (unit-name (vhdl-speedbar-line-text))
14947 (vhdl-project (vhdl-speedbar-line-project))
14948 (directory (file-name-as-directory
14949 (or (speedbar-line-file) (speedbar-line-path)))))
14950 (if (fboundp 'speedbar-select-attached-frame)
14951 (speedbar-select-attached-frame)
14952 (select-frame speedbar-attached-frame))
14953 (let ((default-directory directory))
14954 (vhdl-make (and is-unit unit-name))))))
14956 (defun vhdl-speedbar-generate-makefile ()
14957 "Generate Makefile for directory/project under the cursor."
14959 (let ((vhdl-project (vhdl-speedbar-line-project))
14960 (default-directory (file-name-as-directory
14961 (or (speedbar-line-file) (speedbar-line-path)))))
14962 (vhdl-generate-makefile)))
14964 (defun vhdl-speedbar-check-unit (design-unit)
14965 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
14966 expansion function)."
14968 (speedbar-position-cursor-on-line)
14969 (cond ((eq design-unit 'entity)
14970 (memq (get-text-property (match-end 0) 'face)
14971 '(vhdl-speedbar-entity
14972 vhdl-speedbar-entity-selected)))
14973 ((eq design-unit 'subprogram)
14974 (eq (get-text-property (match-end 0) 'face)
14975 'vhdl-speedbar-subprogram))
14978 (defun vhdl-speedbar-set-depth (depth)
14979 "Set hierarchy display depth to DEPTH and refresh speedbar."
14980 (setq vhdl-speedbar-hierarchy-depth depth)
14981 (speedbar-refresh))
14983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14986 (defface vhdl-speedbar-entity
14987 '((((class color) (background light)) (:foreground "ForestGreen"))
14988 (((class color) (background dark)) (:foreground "PaleGreen")))
14989 "Face used for displaying entity names."
14990 :group 'speedbar-faces)
14991 ;; backward-compatibility alias
14992 (put 'vhdl-speedbar-entity-face 'face-alias 'vhdl-speedbar-entity)
14994 (defface vhdl-speedbar-architecture
14995 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
14996 (((class color) (background light)) (:foreground "Blue"))
14997 (((class color) (background dark)) (:foreground "LightSkyBlue")))
14998 "Face used for displaying architecture names."
14999 :group 'speedbar-faces)
15000 ;; backward-compatibility alias
15001 (put 'vhdl-speedbar-architecture-face 'face-alias 'vhdl-speedbar-architecture)
15003 (defface vhdl-speedbar-configuration
15004 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15005 (((class color) (background dark)) (:foreground "Salmon")))
15006 "Face used for displaying configuration names."
15007 :group 'speedbar-faces)
15008 ;; backward-compatibility alias
15009 (put 'vhdl-speedbar-configuration-face 'face-alias 'vhdl-speedbar-configuration)
15011 (defface vhdl-speedbar-package
15012 '((((class color) (background light)) (:foreground "Grey50"))
15013 (((class color) (background dark)) (:foreground "Grey80")))
15014 "Face used for displaying package names."
15015 :group 'speedbar-faces)
15016 ;; backward-compatibility alias
15017 (put 'vhdl-speedbar-package-face 'face-alias 'vhdl-speedbar-package)
15019 (defface vhdl-speedbar-library
15020 '((((class color) (background light)) (:foreground "Purple"))
15021 (((class color) (background dark)) (:foreground "Orchid1")))
15022 "Face used for displaying library names."
15023 :group 'speedbar-faces)
15024 ;; backward-compatibility alias
15025 (put 'vhdl-speedbar-library-face 'face-alias 'vhdl-speedbar-library)
15027 (defface vhdl-speedbar-instantiation
15028 '((((class color) (background light)) (:foreground "Brown"))
15029 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15030 (((class color) (background dark)) (:foreground "Yellow")))
15031 "Face used for displaying instantiation names."
15032 :group 'speedbar-faces)
15033 ;; backward-compatibility alias
15034 (put 'vhdl-speedbar-instantiation-face 'face-alias 'vhdl-speedbar-instantiation)
15036 (defface vhdl-speedbar-subprogram
15037 '((((class color) (background light)) (:foreground "Orchid4"))
15038 (((class color) (background dark)) (:foreground "BurlyWood2")))
15039 "Face used for displaying subprogram names."
15040 :group 'speedbar-faces)
15041 ;; backward-compatibility alias
15042 (put 'vhdl-speedbar-subprogram-face 'face-alias 'vhdl-speedbar-subprogram)
15044 (defface vhdl-speedbar-entity-selected
15045 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15046 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15047 "Face used for displaying entity names."
15048 :group 'speedbar-faces)
15049 ;; backward-compatibility alias
15050 (put 'vhdl-speedbar-entity-selected-face 'face-alias 'vhdl-speedbar-entity-selected)
15052 (defface vhdl-speedbar-architecture-selected
15053 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15054 (((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15055 (((class color) (background light)) (:foreground "Blue" :underline t))
15056 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15057 "Face used for displaying architecture names."
15058 :group 'speedbar-faces)
15059 ;; backward-compatibility alias
15060 (put 'vhdl-speedbar-architecture-selected-face 'face-alias 'vhdl-speedbar-architecture-selected)
15062 (defface vhdl-speedbar-configuration-selected
15063 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15064 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15065 "Face used for displaying configuration names."
15066 :group 'speedbar-faces)
15067 ;; backward-compatibility alias
15068 (put 'vhdl-speedbar-configuration-selected-face 'face-alias 'vhdl-speedbar-configuration-selected)
15070 (defface vhdl-speedbar-package-selected
15071 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15072 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15073 "Face used for displaying package names."
15074 :group 'speedbar-faces)
15075 ;; backward-compatibility alias
15076 (put 'vhdl-speedbar-package-selected-face 'face-alias 'vhdl-speedbar-package-selected)
15078 (defface vhdl-speedbar-instantiation-selected
15079 '((((class color) (background light)) (:foreground "Brown" :underline t))
15080 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1" :underline t))
15081 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15082 "Face used for displaying instantiation names."
15083 :group 'speedbar-faces)
15084 ;; backward-compatibility alias
15085 (put 'vhdl-speedbar-instantiation-selected-face 'face-alias 'vhdl-speedbar-instantiation-selected)
15087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15091 (when (fboundp 'speedbar)
15093 (when (and vhdl-speedbar-auto-open
15094 (not (and (boundp 'speedbar-frame)
15095 (frame-live-p speedbar-frame))))
15096 (speedbar-frame-mode 1)
15097 (if (fboundp 'speedbar-select-attached-frame)
15098 (speedbar-select-attached-frame)
15099 (select-frame speedbar-attached-frame)))
15100 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15102 ;; initialize speedbar
15103 (if (not (boundp 'speedbar-frame))
15104 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15105 (vhdl-speedbar-initialize)
15106 (when speedbar-frame (vhdl-speedbar-refresh)))
15109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15110 ;;; Structural composition
15111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15113 (defun vhdl-get-components-package-name ()
15114 "Return the name of the components package."
15115 (let ((project (vhdl-project-p)))
15117 (vhdl-replace-string (car vhdl-components-package-name)
15118 (subst-char-in-string ? ?_ project))
15119 (cdr vhdl-components-package-name))))
15121 (defun vhdl-compose-new-component ()
15122 "Create entity and architecture for new component."
15124 (let* ((case-fold-search t)
15125 (ent-name (read-from-minibuffer "entity name: "
15126 nil vhdl-minibuffer-local-map))
15128 (if (equal (cdr vhdl-compose-architecture-name) "")
15129 (read-from-minibuffer "architecture name: "
15130 nil vhdl-minibuffer-local-map)
15131 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15132 ent-file-name arch-file-name ent-buffer arch-buffer project)
15133 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15134 ;; open entity file
15135 (unless (eq vhdl-compose-create-files 'none)
15136 (setq ent-file-name
15137 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15138 "." (file-name-extension (buffer-file-name))))
15139 (when (and (file-exists-p ent-file-name)
15140 (not (y-or-n-p (concat "File \"" ent-file-name
15141 "\" exists; overwrite? "))))
15142 (error "ERROR: Creating component...aborted"))
15143 (find-file ent-file-name)
15145 (set-buffer-modified-p nil))
15147 (if vhdl-compose-include-header
15148 (progn (vhdl-template-header)
15149 (goto-char (point-max)))
15150 (vhdl-comment-display-line) (insert "\n\n"))
15151 ;; insert library clause
15152 (vhdl-template-package-std-logic-1164)
15153 (when vhdl-use-components-package
15155 (vhdl-template-standard-package (vhdl-work-library)
15156 (vhdl-get-components-package-name)))
15157 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15158 ;; insert entity declaration
15159 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15160 (vhdl-insert-keyword " IS\n")
15161 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15162 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15163 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15164 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15165 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15166 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15167 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15168 (vhdl-insert-keyword "END ")
15169 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15170 (insert ent-name ";\n\n")
15171 (vhdl-comment-display-line) (insert "\n")
15172 ;; open architecture file
15173 (if (not (eq vhdl-compose-create-files 'separate))
15175 (setq ent-buffer (current-buffer))
15176 (setq arch-file-name
15177 (concat (vhdl-replace-string vhdl-architecture-file-name
15178 (concat ent-name " " arch-name))
15179 "." (file-name-extension (buffer-file-name))))
15180 (when (and (file-exists-p arch-file-name)
15181 (not (y-or-n-p (concat "File \"" arch-file-name
15182 "\" exists; overwrite? "))))
15183 (error "ERROR: Creating component...aborted"))
15184 (find-file arch-file-name)
15186 (set-buffer-modified-p nil)
15188 (if vhdl-compose-include-header
15189 (progn (vhdl-template-header)
15190 (goto-char (point-max)))
15191 (vhdl-comment-display-line) (insert "\n\n")))
15192 ;; insert architecture body
15193 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15194 (vhdl-insert-keyword " OF ") (insert ent-name)
15195 (vhdl-insert-keyword " IS\n\n")
15196 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15197 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15198 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15199 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15200 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15201 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15202 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15203 (vhdl-insert-keyword "BEGIN")
15204 (when vhdl-self-insert-comments
15206 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15207 (insert arch-name))
15209 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15210 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15211 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15212 (vhdl-insert-keyword "END ")
15213 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15214 (insert arch-name ";\n\n")
15216 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15217 (vhdl-template-footer)
15218 (vhdl-comment-display-line) (insert "\n"))
15219 (goto-char (point-min))
15220 (setq arch-buffer (current-buffer))
15221 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15222 (set-buffer arch-buffer) (save-buffer)
15224 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15226 (format "\n File created: \"%s\"" ent-file-name))
15227 (and arch-file-name
15228 (format "\n File created: \"%s\"" arch-file-name))))))
15230 (defun vhdl-compose-place-component ()
15231 "Place new component by pasting current port as component declaration and
15232 component instantiation."
15234 (if (not vhdl-port-list)
15235 (error "ERROR: No port has been read")
15237 (vhdl-prepare-search-2
15238 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15239 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15240 (error "ERROR: No architecture found"))
15241 (let* ((ent-name (match-string 1))
15243 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15244 "." (file-name-extension (buffer-file-name))))
15245 (orig-buffer (current-buffer)))
15246 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15247 ;; place component declaration
15248 (unless (or vhdl-use-components-package
15249 (vhdl-use-direct-instantiation)
15252 (concat "^\\s-*component\\s-+"
15253 (car vhdl-port-list) "\\>") nil t)))
15254 (re-search-forward "^begin\\>" nil)
15255 (beginning-of-line)
15256 (skip-chars-backward " \t\n")
15257 (insert "\n\n") (indent-to vhdl-basic-offset)
15258 (vhdl-port-paste-component t))
15259 ;; place component instantiation
15260 (re-search-forward "^end\\>" nil)
15261 (beginning-of-line)
15262 (skip-chars-backward " \t\n")
15263 (insert "\n\n") (indent-to vhdl-basic-offset)
15264 (vhdl-port-paste-instance nil t t)
15265 ;; place use clause for used packages
15266 (when (nth 3 vhdl-port-list)
15267 ;; open entity file
15268 (when (file-exists-p ent-file-name)
15269 (find-file ent-file-name))
15270 (goto-char (point-min))
15271 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15272 (error "ERROR: Entity not found: \"%s\"" ent-name))
15273 (goto-char (match-beginning 0))
15274 (if (and (save-excursion
15275 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15277 (progn (goto-char (match-end 0))
15278 (beginning-of-line 2))
15281 (vhdl-port-paste-context-clause)
15282 (switch-to-buffer orig-buffer))
15283 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15285 (defun vhdl-compose-wire-components ()
15286 "Connect components."
15289 (vhdl-prepare-search-2
15290 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15291 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15292 (error "ERROR: No architecture found"))
15293 (let* ((ent-name (match-string 1))
15295 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15296 "." (file-name-extension (buffer-file-name))))
15297 (arch-decl-pos (point-marker))
15298 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15299 (arch-end-pos (re-search-forward "^end\\>" nil))
15300 (pack-name (vhdl-get-components-package-name))
15302 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15303 "." (file-name-extension (buffer-file-name))))
15304 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15305 port-alist generic-alist inst-alist
15306 signal-name signal-entry signal-alist local-list written-list
15307 single-in-list multi-in-list single-out-list multi-out-list
15308 constant-name constant-entry constant-alist single-list multi-list
15309 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15310 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15311 signal-beg-pos signal-pos
15312 constant-temp-pos port-temp-pos signal-temp-pos)
15313 (message "Wiring components...")
15314 ;; process all instances
15315 (goto-char arch-stat-pos)
15316 (while (re-search-forward
15317 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15318 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15319 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15320 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15321 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15322 (setq inst-name (match-string-no-properties 1)
15323 comp-name (match-string-no-properties 4)
15324 comp-ent-name (match-string-no-properties 12)
15325 has-generic (or (match-string 7) (match-string 17)))
15328 ;; ... from component declaration
15330 (when vhdl-use-components-package pack-file-name) t
15332 (goto-char (point-min))
15333 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15334 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15336 ;; ... from entity declaration (direct instantiation)
15337 (setq comp-ent-file-name
15338 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name)
15339 "." (file-name-extension (buffer-file-name))))
15341 comp-ent-file-name t
15343 (goto-char (point-min))
15344 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15345 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15346 (vhdl-port-copy))))
15347 (vhdl-port-flatten t)
15348 (setq generic-alist (nth 1 vhdl-port-list)
15349 port-alist (nth 2 vhdl-port-list))
15350 (setq constant-alist nil
15353 ;; process all constants in generic map
15354 (vhdl-forward-syntactic-ws)
15355 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15356 (setq constant-name (match-string-no-properties 3))
15357 (setq constant-entry
15358 (cons constant-name
15359 (if (match-string 1)
15360 (or (aget generic-alist (match-string 2) t)
15361 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15362 (cdar generic-alist))))
15363 (setq constant-alist (cons constant-entry constant-alist))
15364 (setq constant-name (downcase constant-name))
15365 (if (or (member constant-name single-list)
15366 (member constant-name multi-list))
15367 (progn (setq single-list (delete constant-name single-list))
15368 (add-to-list 'multi-list constant-name))
15369 (add-to-list 'single-list constant-name))
15370 (unless (match-string 1)
15371 (setq generic-alist (cdr generic-alist)))
15372 (vhdl-forward-syntactic-ws))
15373 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15374 ;; process all signals in port map
15375 (vhdl-forward-syntactic-ws)
15376 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15377 (setq signal-name (match-string-no-properties 3))
15378 (setq signal-entry (cons signal-name
15379 (if (match-string 1)
15380 (or (aget port-alist (match-string 2) t)
15381 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15382 (cdar port-alist))))
15383 (setq signal-alist (cons signal-entry signal-alist))
15384 (setq signal-name (downcase signal-name))
15385 (if (equal (upcase (nth 2 signal-entry)) "IN")
15388 ((member signal-name local-list)
15390 ((or (member signal-name single-out-list)
15391 (member signal-name multi-out-list))
15392 (setq single-out-list (delete signal-name single-out-list))
15393 (setq multi-out-list (delete signal-name multi-out-list))
15394 (add-to-list 'local-list signal-name))
15395 ((member signal-name single-in-list)
15396 (setq single-in-list (delete signal-name single-in-list))
15397 (add-to-list 'multi-in-list signal-name))
15398 ((not (member signal-name multi-in-list))
15399 (add-to-list 'single-in-list signal-name)))
15402 ((member signal-name local-list)
15404 ((or (member signal-name single-in-list)
15405 (member signal-name multi-in-list))
15406 (setq single-in-list (delete signal-name single-in-list))
15407 (setq multi-in-list (delete signal-name multi-in-list))
15408 (add-to-list 'local-list signal-name))
15409 ((member signal-name single-out-list)
15410 (setq single-out-list (delete signal-name single-out-list))
15411 (add-to-list 'multi-out-list signal-name))
15412 ((not (member signal-name multi-out-list))
15413 (add-to-list 'single-out-list signal-name))))
15414 (unless (match-string 1)
15415 (setq port-alist (cdr port-alist)))
15416 (vhdl-forward-syntactic-ws))
15417 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15418 (nreverse signal-alist)) inst-alist)))
15419 ;; prepare signal insertion
15420 (vhdl-goto-marker arch-decl-pos)
15422 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15423 (setq signal-pos (point-marker))
15424 (while (progn (vhdl-forward-syntactic-ws)
15425 (looking-at "signal\\>"))
15426 (beginning-of-line 2)
15427 (delete-region signal-pos (point)))
15428 (setq signal-beg-pos signal-pos)
15429 ;; open entity file
15430 (when (file-exists-p ent-file-name)
15431 (find-file ent-file-name))
15432 (goto-char (point-min))
15433 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15434 (error "ERROR: Entity not found: \"%s\"" ent-name))
15435 ;; prepare generic clause insertion
15436 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15438 (goto-char (match-beginning 0))
15439 (indent-to vhdl-basic-offset)
15440 (insert "generic ();\n\n")
15443 (setq generic-pos (point-marker))
15444 (forward-sexp) (end-of-line)
15445 (delete-region generic-pos (point)) (delete-char 1)
15449 (indent-to (* 2 vhdl-basic-offset))
15450 (insert "-- global generics\n"))
15451 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15452 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15453 ;; prepare port clause insertion
15454 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15456 (goto-char (match-beginning 0))
15457 (indent-to vhdl-basic-offset)
15458 (insert "port ();\n\n")
15461 (setq port-in-pos (point-marker))
15462 (forward-sexp) (end-of-line)
15463 (delete-region port-in-pos (point)) (delete-char 1)
15465 (when (or multi-in-list multi-out-list)
15467 (indent-to (* 2 vhdl-basic-offset))
15468 (insert "-- global ports\n"))
15469 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15470 port-out-pos (point-marker) port-inst-pos (point-marker)
15471 port-end-pos (point-marker))
15472 ;; insert generics, ports and signals
15473 (setq inst-alist (nreverse inst-alist))
15475 (setq inst-name (nth 0 (car inst-alist))
15476 constant-alist (nth 1 (car inst-alist))
15477 signal-alist (nth 2 (car inst-alist))
15478 constant-temp-pos generic-inst-pos
15479 port-temp-pos port-inst-pos
15480 signal-temp-pos signal-pos)
15482 (while constant-alist
15483 (setq constant-name (downcase (caar constant-alist))
15484 constant-entry (car constant-alist))
15485 (cond ((member constant-name written-list)
15487 ((member constant-name multi-list)
15488 (vhdl-goto-marker generic-pos)
15489 (setq generic-end-pos
15492 (vhdl-compose-insert-generic constant-entry)))
15493 (setq generic-pos (point-marker))
15494 (add-to-list 'written-list constant-name))
15497 (vhdl-max-marker generic-inst-pos generic-pos))
15498 (setq generic-end-pos
15499 (vhdl-compose-insert-generic constant-entry))
15500 (setq generic-inst-pos (point-marker))
15501 (add-to-list 'written-list constant-name)))
15502 (setq constant-alist (cdr constant-alist)))
15503 (when (/= constant-temp-pos generic-inst-pos)
15504 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15505 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15506 (insert "-- generics for \"" inst-name "\"\n")
15507 (vhdl-goto-marker generic-inst-pos))
15508 ;; ports and signals
15509 (while signal-alist
15510 (setq signal-name (downcase (caar signal-alist))
15511 signal-entry (car signal-alist))
15512 (cond ((member signal-name written-list)
15514 ((member signal-name multi-in-list)
15515 (vhdl-goto-marker port-in-pos)
15518 port-end-pos (vhdl-compose-insert-port signal-entry)))
15519 (setq port-in-pos (point-marker))
15520 (add-to-list 'written-list signal-name))
15521 ((member signal-name multi-out-list)
15522 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15525 port-end-pos (vhdl-compose-insert-port signal-entry)))
15526 (setq port-out-pos (point-marker))
15527 (add-to-list 'written-list signal-name))
15528 ((or (member signal-name single-in-list)
15529 (member signal-name single-out-list))
15533 (vhdl-max-marker port-out-pos port-in-pos)))
15534 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15535 (setq port-inst-pos (point-marker))
15536 (add-to-list 'written-list signal-name))
15537 ((equal (upcase (nth 2 signal-entry)) "OUT")
15538 (vhdl-goto-marker signal-pos)
15539 (vhdl-compose-insert-signal signal-entry)
15540 (setq signal-pos (point-marker))
15541 (add-to-list 'written-list signal-name)))
15542 (setq signal-alist (cdr signal-alist)))
15543 (when (/= port-temp-pos port-inst-pos)
15545 (vhdl-max-marker port-temp-pos
15546 (vhdl-max-marker port-in-pos port-out-pos)))
15547 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15548 (insert "-- ports to \"" inst-name "\"\n")
15549 (vhdl-goto-marker port-inst-pos))
15550 (when (/= signal-temp-pos signal-pos)
15551 (vhdl-goto-marker signal-temp-pos)
15552 (insert "\n") (indent-to vhdl-basic-offset)
15553 (insert "-- outputs of \"" inst-name "\"\n")
15554 (vhdl-goto-marker signal-pos))
15555 (setq inst-alist (cdr inst-alist)))
15556 ;; finalize generic/port clause
15557 (vhdl-goto-marker generic-end-pos) (backward-char)
15558 (when (= generic-beg-pos generic-end-pos)
15559 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15560 (insert ";") (backward-char))
15562 (vhdl-goto-marker port-end-pos) (backward-char)
15563 (when (= port-beg-pos port-end-pos)
15564 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15565 (insert ";") (backward-char))
15567 ;; align everything
15568 (when vhdl-auto-align
15569 (vhdl-goto-marker generic-beg-pos)
15570 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15571 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15572 (vhdl-goto-marker signal-beg-pos)
15573 (vhdl-align-region-groups signal-beg-pos signal-pos))
15574 (switch-to-buffer (marker-buffer signal-beg-pos))
15575 (message "Wiring components...done")))))
15577 (defun vhdl-compose-insert-generic (entry)
15578 "Insert ENTRY as generic declaration."
15580 (indent-to (* 2 vhdl-basic-offset))
15581 (insert (nth 0 entry) " : " (nth 1 entry))
15582 (when (nth 2 entry)
15583 (insert " := " (nth 2 entry)))
15585 (setq pos (point-marker))
15586 (when (and vhdl-include-port-comments (nth 3 entry))
15587 (vhdl-comment-insert-inline (nth 3 entry) t))
15591 (defun vhdl-compose-insert-port (entry)
15592 "Insert ENTRY as port declaration."
15594 (indent-to (* 2 vhdl-basic-offset))
15595 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15596 (setq pos (point-marker))
15597 (when (and vhdl-include-port-comments (nth 4 entry))
15598 (vhdl-comment-insert-inline (nth 4 entry) t))
15602 (defun vhdl-compose-insert-signal (entry)
15603 "Insert ENTRY as signal declaration."
15604 (indent-to vhdl-basic-offset)
15605 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15606 (when (and vhdl-include-port-comments (nth 4 entry))
15607 (vhdl-comment-insert-inline (nth 4 entry) t))
15610 (defun vhdl-compose-components-package ()
15611 "Generate a package containing component declarations for all entities in the
15612 current project/directory."
15614 (vhdl-require-hierarchy-info)
15615 (let* ((project (vhdl-project-p))
15616 (pack-name (vhdl-get-components-package-name))
15618 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15619 "." (file-name-extension (buffer-file-name))))
15620 (ent-alist (aget vhdl-entity-alist
15621 (or project default-directory) t))
15622 (lazy-lock-minimum-size 0)
15623 clause-pos component-pos)
15624 (message "Generating components package \"%s\"..." pack-name)
15625 ;; open package file
15626 (when (and (file-exists-p pack-file-name)
15627 (not (y-or-n-p (concat "File \"" pack-file-name
15628 "\" exists; overwrite? "))))
15629 (error "ERROR: Generating components package...aborted"))
15630 (find-file pack-file-name)
15633 (if vhdl-compose-include-header
15634 (progn (vhdl-template-header
15635 (concat "Components package (generated by Emacs VHDL Mode "
15637 (goto-char (point-max)))
15638 (vhdl-comment-display-line) (insert "\n\n"))
15639 ;; insert std_logic_1164 package
15640 (vhdl-template-package-std-logic-1164)
15641 (insert "\n") (setq clause-pos (point-marker))
15642 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15643 ;; insert package declaration
15644 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15645 (vhdl-insert-keyword " IS\n\n")
15646 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15647 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15648 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15649 (indent-to vhdl-basic-offset)
15650 (setq component-pos (point-marker))
15651 (insert "\n\n") (vhdl-insert-keyword "END ")
15652 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15653 (insert pack-name ";\n\n")
15655 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15656 (vhdl-template-footer)
15657 (vhdl-comment-display-line) (insert "\n"))
15658 ;; insert component declarations
15660 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15661 (progn (goto-line (nth 3 (car ent-alist)))
15664 (goto-char component-pos)
15665 (vhdl-port-paste-component t)
15666 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15667 (setq component-pos (point-marker))
15668 (goto-char clause-pos)
15669 (vhdl-port-paste-context-clause pack-name)
15670 (setq clause-pos (point-marker))
15671 (setq ent-alist (cdr ent-alist)))
15672 (goto-char (point-min))
15674 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15675 pack-name pack-file-name)))
15678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15679 ;;; Compilation / Makefile generation
15680 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15681 ;; (using `compile.el')
15683 (defun vhdl-makefile-name ()
15684 "Return the Makefile name of the current project or the current compiler if
15685 no project is defined."
15686 (let ((project-alist (aget vhdl-project-alist vhdl-project))
15687 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
15688 (vhdl-replace-string
15689 (cons "\\(.*\\)\n\\(.*\\)"
15690 (or (nth 8 project-alist) (nth 8 compiler-alist)))
15691 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
15693 (defun vhdl-compile-directory ()
15694 "Return the directory where compilation/make should be run."
15695 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
15696 (compiler (aget vhdl-compiler-alist vhdl-compiler))
15697 (directory (vhdl-resolve-env-variable
15699 (vhdl-replace-string
15700 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
15701 (nth 6 compiler)))))
15702 (file-name-as-directory
15703 (if (file-name-absolute-p directory)
15705 (expand-file-name directory (vhdl-default-directory))))))
15707 (defun vhdl-uniquify (in-list)
15708 "Remove duplicate elements from IN-LIST."
15711 (add-to-list 'out-list (car in-list))
15712 (setq in-list (cdr in-list)))
15715 (defun vhdl-set-compiler (name)
15716 "Set current compiler to NAME."
15718 (list (let ((completion-ignore-case t))
15719 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
15720 (if (assoc name vhdl-compiler-alist)
15721 (progn (setq vhdl-compiler name)
15722 (message "Current compiler: \"%s\"" vhdl-compiler))
15723 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
15725 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15728 (defun vhdl-compile-init ()
15729 "Initialize for compilation."
15730 (when (or (null compilation-error-regexp-alist)
15731 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
15732 compilation-error-regexp-alist)))
15733 ;; `compilation-error-regexp-alist'
15734 (let ((commands-alist vhdl-compiler-alist)
15735 regexp-alist sublist)
15736 (while commands-alist
15737 (setq sublist (nth 11 (car commands-alist)))
15738 (unless (or (equal "" (car sublist))
15739 (assoc (car sublist) regexp-alist))
15740 (setq regexp-alist (cons (list (nth 0 sublist)
15741 (if (= 0 (nth 1 sublist))
15742 (if vhdl-xemacs 9 nil)
15744 (nth 2 sublist) (nth 3 sublist))
15746 (setq commands-alist (cdr commands-alist)))
15747 (setq compilation-error-regexp-alist
15748 (append compilation-error-regexp-alist (nreverse regexp-alist))))
15749 ;; `compilation-file-regexp-alist'
15750 (let ((commands-alist vhdl-compiler-alist)
15751 regexp-alist sublist)
15752 ;; matches vhdl-mode file name output
15753 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
15754 (while commands-alist
15755 (setq sublist (nth 12 (car commands-alist)))
15756 (unless (or (equal "" (car sublist))
15757 (assoc (car sublist) regexp-alist))
15758 (setq regexp-alist (cons sublist regexp-alist)))
15759 (setq commands-alist (cdr commands-alist)))
15760 (setq compilation-file-regexp-alist
15761 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
15763 (defvar vhdl-compile-file-name nil
15764 "Name of file to be compiled.")
15766 (defun vhdl-compile-print-file-name ()
15767 "Function called within `compile' to print out file name for compilers that
15768 do not print any file names."
15769 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
15771 (defun vhdl-get-compile-options (project compiler file-name
15772 &optional file-options-only)
15773 "Get compiler options. Returning nil means do not compile this file."
15774 (let* ((compiler-options (nth 1 compiler))
15775 (project-entry (aget (nth 4 project) vhdl-compiler))
15776 (project-options (nth 0 project-entry))
15777 (exception-list (and file-name (nth 2 project-entry)))
15778 (work-library (vhdl-work-library))
15779 (case-fold-search nil)
15781 (while (and exception-list
15782 (not (string-match (caar exception-list) file-name)))
15783 (setq exception-list (cdr exception-list)))
15784 (if (and exception-list (not (cdar exception-list)))
15786 (if (and file-options-only (not exception-list))
15788 (setq file-options (cdar exception-list))
15789 ;; insert library name in compiler-specific options
15790 (setq compiler-options
15791 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
15793 ;; insert compiler-specific options in project-specific options
15794 (when project-options
15795 (setq project-options
15796 (vhdl-replace-string
15797 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15798 (concat work-library "\n" compiler-options))))
15799 ;; insert project-specific options in file-specific options
15802 (vhdl-replace-string
15803 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
15804 (concat work-library "\n" compiler-options "\n"
15805 project-options))))
15807 (or file-options project-options compiler-options)))))
15809 (defun vhdl-get-make-options (project compiler)
15810 "Get make options."
15811 (let* ((compiler-options (nth 3 compiler))
15812 (project-entry (aget (nth 4 project) vhdl-compiler))
15813 (project-options (nth 1 project-entry))
15814 (makefile-name (vhdl-makefile-name)))
15815 ;; insert Makefile name in compiler-specific options
15816 (setq compiler-options
15817 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
15819 ;; insert compiler-specific options in project-specific options
15820 (when project-options
15821 (setq project-options
15822 (vhdl-replace-string
15823 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15824 (concat makefile-name "\n" compiler-options))))
15826 (or project-options compiler-options)))
15828 (defun vhdl-compile ()
15829 "Compile current buffer using the VHDL compiler specified in
15832 (vhdl-compile-init)
15833 (let* ((project (aget vhdl-project-alist vhdl-project))
15834 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
15835 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15836 (command (nth 0 compiler))
15837 (file-name (buffer-file-name))
15838 (options (vhdl-get-compile-options project compiler file-name))
15839 (default-directory (vhdl-compile-directory))
15840 compilation-process-setup-function)
15841 (unless (file-directory-p default-directory)
15842 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15843 ;; put file name into quotes if it contains spaces
15844 (when (string-match " " file-name)
15845 (setq file-name (concat "\"" file-name "\"")))
15846 ;; print out file name if compiler does not
15847 (setq vhdl-compile-file-name (buffer-file-name))
15848 (when (and (= 0 (nth 1 (nth 10 compiler)))
15849 (= 0 (nth 1 (nth 11 compiler))))
15850 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
15854 (compile (concat command " " options " " file-name)))
15855 (vhdl-warning "Your project settings tell me not to compile this file"))))
15857 (defun vhdl-make (&optional target)
15858 "Call make command for compilation of all updated source files (requires
15859 `Makefile'). Optional argument TARGET allows to compile the design
15860 specified by a target."
15862 (vhdl-compile-init)
15863 (let* ((project (aget vhdl-project-alist vhdl-project))
15864 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15865 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15866 (command (nth 2 compiler))
15867 (options (vhdl-get-make-options project compiler))
15868 (default-directory (vhdl-compile-directory)))
15869 (unless (file-directory-p default-directory)
15870 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15872 (compile (concat (if (equal command "") "make" command)
15873 " " options " " target))))
15875 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15876 ;; Makefile generation
15878 (defun vhdl-generate-makefile ()
15879 "Generate `Makefile'."
15881 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15882 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15883 (command (nth 4 compiler)))
15884 ;; generate makefile
15886 (let ((default-directory (vhdl-compile-directory)))
15887 (compile (vhdl-replace-string
15888 (cons "\\(.*\\) \\(.*\\)" command)
15889 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
15890 (vhdl-generate-makefile-1))))
15892 (defun vhdl-get-packages (lib-alist work-library)
15893 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
15896 (when (equal (downcase (caar lib-alist)) (downcase work-library))
15897 (setq pack-list (cons (cdar lib-alist) pack-list)))
15898 (setq lib-alist (cdr lib-alist)))
15901 (defun vhdl-generate-makefile-1 ()
15902 "Generate Makefile for current project or directory."
15903 ;; scan hierarchy if required
15904 (if (vhdl-project-p)
15905 (unless (or (assoc vhdl-project vhdl-file-alist)
15906 (vhdl-load-cache vhdl-project))
15907 (vhdl-scan-project-contents vhdl-project))
15908 (let ((directory (abbreviate-file-name default-directory)))
15909 (unless (or (assoc directory vhdl-file-alist)
15910 (vhdl-load-cache directory))
15911 (vhdl-scan-directory-contents directory))))
15912 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
15913 (project (vhdl-project-p))
15914 (ent-alist (aget vhdl-entity-alist (or project directory) t))
15915 (conf-alist (aget vhdl-config-alist (or project directory) t))
15916 (pack-alist (aget vhdl-package-alist (or project directory) t))
15917 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
15918 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
15919 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
15920 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
15921 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
15922 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
15923 (adjust-case (nth 5 regexp-list))
15924 (work-library (downcase (vhdl-work-library)))
15925 (compile-directory (expand-file-name (vhdl-compile-directory)
15926 default-directory))
15927 (makefile-name (vhdl-makefile-name))
15928 rule-alist arch-alist inst-alist
15929 target-list depend-list unit-list prim-list second-list subcomp-list
15930 lib-alist lib-body-alist pack-list all-pack-list
15931 ent-key ent-file-name arch-key arch-file-name ent-arch-key
15932 conf-key conf-file-name pack-key pack-file-name
15933 ent-entry arch-entry conf-entry pack-entry inst-entry
15934 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
15935 tmp-key tmp-list rule)
15936 ;; check prerequisites
15937 (unless (file-exists-p compile-directory)
15938 (make-directory compile-directory t))
15939 (unless regexp-list
15940 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
15942 (message "Generating makefile \"%s\"..." makefile-name)
15943 ;; rules for all entities
15944 (setq tmp-list ent-alist)
15946 (setq ent-entry (car ent-alist)
15947 ent-key (nth 0 ent-entry))
15948 (when (nth 2 ent-entry)
15949 (setq ent-file-name (file-relative-name
15950 (nth 2 ent-entry) compile-directory)
15951 arch-alist (nth 4 ent-entry)
15952 lib-alist (nth 5 ent-entry)
15953 rule (aget rule-alist ent-file-name)
15954 target-list (nth 0 rule)
15955 depend-list (nth 1 rule)
15958 (setq tmp-key (vhdl-replace-string
15959 ent-regexp (funcall adjust-case ent-key)))
15960 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
15961 ;; rule target for this entity
15962 (setq target-list (cons ent-key target-list))
15963 ;; rule dependencies for all used packages
15964 (setq pack-list (vhdl-get-packages lib-alist work-library))
15965 (setq depend-list (append depend-list pack-list))
15966 (setq all-pack-list pack-list)
15968 (aput 'rule-alist ent-file-name (list target-list depend-list))
15969 ;; rules for all corresponding architectures
15971 (setq arch-entry (car arch-alist)
15972 arch-key (nth 0 arch-entry)
15973 ent-arch-key (concat ent-key "-" arch-key)
15974 arch-file-name (file-relative-name (nth 2 arch-entry)
15976 inst-alist (nth 4 arch-entry)
15977 lib-alist (nth 5 arch-entry)
15978 rule (aget rule-alist arch-file-name)
15979 target-list (nth 0 rule)
15980 depend-list (nth 1 rule))
15981 (setq tmp-key (vhdl-replace-string
15983 (funcall adjust-case (concat arch-key " " ent-key))))
15985 (cons (cons ent-arch-key tmp-key) unit-list))
15986 (setq second-list (cons ent-arch-key second-list))
15987 ;; rule target for this architecture
15988 (setq target-list (cons ent-arch-key target-list))
15989 ;; rule dependency for corresponding entity
15990 (setq depend-list (cons ent-key depend-list))
15991 ;; rule dependencies for contained component instantiations
15993 (setq inst-entry (car inst-alist))
15994 (when (or (null (nth 8 inst-entry))
15995 (equal (downcase (nth 8 inst-entry)) work-library))
15996 (setq inst-ent-key (or (nth 7 inst-entry)
15997 (nth 5 inst-entry)))
15998 (setq depend-list (cons inst-ent-key depend-list)
15999 subcomp-list (cons inst-ent-key subcomp-list)))
16000 (setq inst-alist (cdr inst-alist)))
16001 ;; rule dependencies for all used packages
16002 (setq pack-list (vhdl-get-packages lib-alist work-library))
16003 (setq depend-list (append depend-list pack-list))
16004 (setq all-pack-list (append all-pack-list pack-list))
16006 (aput 'rule-alist arch-file-name (list target-list depend-list))
16007 (setq arch-alist (cdr arch-alist)))
16008 (setq prim-list (cons (list ent-key second-list
16009 (append subcomp-list all-pack-list))
16011 (setq ent-alist (cdr ent-alist)))
16012 (setq ent-alist tmp-list)
16013 ;; rules for all configurations
16014 (setq tmp-list conf-alist)
16016 (setq conf-entry (car conf-alist)
16017 conf-key (nth 0 conf-entry)
16018 conf-file-name (file-relative-name
16019 (nth 2 conf-entry) compile-directory)
16020 ent-key (nth 4 conf-entry)
16021 arch-key (nth 5 conf-entry)
16022 inst-alist (nth 6 conf-entry)
16023 lib-alist (nth 7 conf-entry)
16024 rule (aget rule-alist conf-file-name)
16025 target-list (nth 0 rule)
16026 depend-list (nth 1 rule)
16027 subcomp-list (list ent-key))
16028 (setq tmp-key (vhdl-replace-string
16029 conf-regexp (funcall adjust-case conf-key)))
16030 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16031 ;; rule target for this configuration
16032 (setq target-list (cons conf-key target-list))
16033 ;; rule dependency for corresponding entity and architecture
16035 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16036 ;; rule dependencies for used packages
16037 (setq pack-list (vhdl-get-packages lib-alist work-library))
16038 (setq depend-list (append depend-list pack-list))
16039 ;; rule dependencies for contained component configurations
16041 (setq inst-entry (car inst-alist))
16042 (setq inst-ent-key (nth 2 inst-entry)
16043 ; comp-arch-key (nth 2 inst-entry))
16044 inst-conf-key (nth 4 inst-entry))
16045 (when (equal (downcase (nth 5 inst-entry)) work-library)
16047 (setq depend-list (cons inst-ent-key depend-list)
16048 subcomp-list (cons inst-ent-key subcomp-list)))
16049 ; (when comp-arch-key
16050 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16052 (when inst-conf-key
16053 (setq depend-list (cons inst-conf-key depend-list)
16054 subcomp-list (cons inst-conf-key subcomp-list))))
16055 (setq inst-alist (cdr inst-alist)))
16057 (aput 'rule-alist conf-file-name (list target-list depend-list))
16058 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16060 (setq conf-alist (cdr conf-alist)))
16061 (setq conf-alist tmp-list)
16062 ;; rules for all packages
16063 (setq tmp-list pack-alist)
16065 (setq pack-entry (car pack-alist)
16066 pack-key (nth 0 pack-entry)
16068 (when (nth 2 pack-entry)
16069 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16071 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16072 rule (aget rule-alist pack-file-name)
16073 target-list (nth 0 rule) depend-list (nth 1 rule))
16074 (setq tmp-key (vhdl-replace-string
16075 pack-regexp (funcall adjust-case pack-key)))
16076 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16077 ;; rule target for this package
16078 (setq target-list (cons pack-key target-list))
16079 ;; rule dependencies for all used packages
16080 (setq pack-list (vhdl-get-packages lib-alist work-library))
16081 (setq depend-list (append depend-list pack-list))
16082 (setq all-pack-list pack-list)
16084 (aput 'rule-alist pack-file-name (list target-list depend-list))
16085 ;; rules for this package's body
16086 (when (nth 7 pack-entry)
16087 (setq pack-body-key (concat pack-key "-body")
16088 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16090 rule (aget rule-alist pack-body-file-name)
16091 target-list (nth 0 rule)
16092 depend-list (nth 1 rule))
16093 (setq tmp-key (vhdl-replace-string
16094 pack-body-regexp (funcall adjust-case pack-key)))
16096 (cons (cons pack-body-key tmp-key) unit-list))
16097 ;; rule target for this package's body
16098 (setq target-list (cons pack-body-key target-list))
16099 ;; rule dependency for corresponding package declaration
16100 (setq depend-list (cons pack-key depend-list))
16101 ;; rule dependencies for all used packages
16102 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16103 (setq depend-list (append depend-list pack-list))
16104 (setq all-pack-list (append all-pack-list pack-list))
16106 (aput 'rule-alist pack-body-file-name
16107 (list target-list depend-list)))
16109 (cons (list pack-key (when pack-body-key (list pack-body-key))
16112 (setq pack-alist (cdr pack-alist)))
16113 (setq pack-alist tmp-list)
16114 ;; generate Makefile
16115 (let* ((project (aget vhdl-project-alist project))
16116 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16117 (compiler-id (nth 9 compiler))
16119 (vhdl-resolve-env-variable
16120 (vhdl-replace-string
16121 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16123 (makefile-path-name (expand-file-name
16124 makefile-name compile-directory))
16125 (orig-buffer (current-buffer))
16126 cell second-list subcomp-list options unit-key unit-name)
16128 (setq unit-list (vhdl-sort-alist unit-list))
16129 (setq prim-list (vhdl-sort-alist prim-list))
16130 (setq tmp-list rule-alist)
16131 (while tmp-list ; pre-sort rule targets
16132 (setq cell (cdar tmp-list))
16133 (setcar cell (sort (car cell) 'string<))
16134 (setq tmp-list (cdr tmp-list)))
16135 (setq rule-alist ; sort by first rule target
16137 (function (lambda (a b)
16138 (string< (car (cadr a)) (car (cadr b)))))))
16139 ;; open and clear Makefile
16140 (set-buffer (find-file-noselect makefile-path-name t t))
16142 (insert "# -*- Makefile -*-\n"
16143 "### " (file-name-nondirectory makefile-name)
16144 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16147 (insert "\n# Project : " (nth 0 project))
16148 (insert "\n# Directory : \"" directory "\""))
16149 (insert "\n# Platform : " vhdl-compiler
16150 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16151 (user-login-name) "\n")
16152 ;; insert compile and option variable settings
16153 (insert "\n\n# Define compilation command and options\n"
16154 "\nCOMPILE = " (nth 0 compiler)
16155 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16157 ;; insert library paths
16158 (setq library-directory
16159 (directory-file-name
16160 (if (file-name-absolute-p library-directory)
16162 (file-relative-name
16163 (expand-file-name library-directory directory)
16164 compile-directory))))
16165 (insert "\n\n# Define library paths\n"
16166 "\nLIBRARY-" work-library " = " library-directory "\n")
16167 ;; insert variable definitions for all library unit files
16168 (insert "\n\n# Define library unit files\n")
16169 (setq tmp-list unit-list)
16171 (insert "\nUNIT-" work-library "-" (caar unit-list)
16172 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16173 (setq unit-list (cdr unit-list)))
16174 ;; insert variable definition for list of all library unit files
16175 (insert "\n\n\n# Define list of all library unit files\n"
16177 (setq unit-list tmp-list)
16179 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16180 (setq unit-list (cdr unit-list)))
16182 (setq unit-list tmp-list)
16183 ;; insert `make all' rule
16184 (insert "\n\n\n# Rule for compiling entire design\n"
16187 " \\\n\t\t$(ALL_UNITS)\n")
16188 ;; insert `make clean' rule
16189 (insert "\n\n# Rule for cleaning entire design\n"
16191 "\n\t-rm -f $(ALL_UNITS)\n")
16192 ;; insert `make library' rule
16193 (insert "\n\n# Rule for creating library directory\n"
16195 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16196 "\n$(LIBRARY-" work-library ") :"
16198 (vhdl-replace-string
16199 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16200 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16202 ;; insert rule for each library unit
16203 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16205 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16207 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16208 (setq unit-key (caar prim-list)
16209 unit-name (or (nth 0 (aget ent-alist unit-key t))
16210 (nth 0 (aget conf-alist unit-key t))
16211 (nth 0 (aget pack-alist unit-key t))))
16212 (insert "\n" unit-key)
16213 (unless (equal unit-key unit-name)
16214 (insert " \\\n" unit-name))
16217 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16219 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16220 (setq second-list (cdr second-list)))
16221 (while subcomp-list
16222 (when (assoc (car subcomp-list) unit-list)
16223 (insert " \\\n\t\t" (car subcomp-list)))
16224 (setq subcomp-list (cdr subcomp-list)))
16226 (setq prim-list (cdr prim-list)))
16227 ;; insert rule for each library unit file
16228 (insert "\n\n# Rules for compiling single library unit files\n")
16230 (setq rule (car rule-alist))
16231 ;; get compiler options for this file
16233 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16234 ;; insert rule if file is supposed to be compiled
16235 (setq target-list (nth 1 rule)
16236 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16238 (setq tmp-list target-list)
16240 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16241 (if (cdr target-list) " \\" " :"))
16242 (setq target-list (cdr target-list)))
16243 (setq target-list tmp-list)
16244 ;; insert file name as first dependency
16245 (insert " \\\n\t\t" (nth 0 rule))
16246 ;; insert dependencies (except if also target or unit does not exist)
16248 (when (and (not (member (car depend-list) target-list))
16249 (assoc (car depend-list) unit-list))
16250 (insert " \\\n\t\t"
16251 "$(UNIT-" work-library "-" (car depend-list) ")"))
16252 (setq depend-list (cdr depend-list)))
16253 ;; insert compile command
16255 (insert "\n\t$(COMPILE) "
16256 (if (eq options 'default) "$(OPTIONS)" options) " "
16258 (setq tmp-list target-list)
16260 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16261 (if (cdr target-list) " \\" "\n"))
16262 (setq target-list (cdr target-list)))
16263 (setq target-list tmp-list))
16264 (setq rule-alist (cdr rule-alist)))
16265 (insert "\n\n### " makefile-name " ends here\n")
16266 ;; run Makefile generation hook
16267 (run-hooks 'vhdl-makefile-generation-hook)
16268 (message "Generating makefile \"%s\"...done" makefile-name)
16269 ;; save and close file
16270 (if (file-writable-p makefile-path-name)
16271 (progn (save-buffer)
16272 (kill-buffer (current-buffer))
16273 (set-buffer orig-buffer)
16274 (setq file-name-history
16275 (cons makefile-path-name file-name-history)))
16276 (vhdl-warning-when-idle
16277 (format "File not writable: \"%s\""
16278 (abbreviate-file-name makefile-path-name)))
16279 (switch-to-buffer (current-buffer))))))
16282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16284 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16285 ;; (using `reporter.el')
16287 (defconst vhdl-mode-help-address
16288 "Reto Zimmermann <reto@gnu.org>"
16289 "Address for VHDL Mode bug reports.")
16291 (defun vhdl-submit-bug-report ()
16292 "Submit via mail a bug report on VHDL Mode."
16294 ;; load in reporter
16296 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16297 (let ((reporter-prompt-for-summary-p t))
16298 (reporter-submit-bug-report
16299 vhdl-mode-help-address
16300 (concat "VHDL Mode " vhdl-version)
16302 ;; report all important user options
16303 'vhdl-offsets-alist
16304 'vhdl-comment-only-line-offset
16306 'vhdl-electric-mode
16308 'vhdl-indent-tabs-mode
16309 'vhdl-project-alist
16311 'vhdl-project-file-name
16312 'vhdl-project-auto-load
16314 'vhdl-compiler-alist
16316 'vhdl-compile-use-local-error-regexp
16317 'vhdl-makefile-generation-hook
16318 'vhdl-default-library
16321 'vhdl-upper-case-keywords
16322 'vhdl-upper-case-types
16323 'vhdl-upper-case-attributes
16324 'vhdl-upper-case-enum-values
16325 'vhdl-upper-case-constants
16326 'vhdl-use-direct-instantiation
16327 'vhdl-entity-file-name
16328 'vhdl-architecture-file-name
16329 'vhdl-package-file-name
16330 'vhdl-file-name-case
16331 'vhdl-electric-keywords
16332 'vhdl-optional-labels
16333 'vhdl-insert-empty-lines
16334 'vhdl-argument-list-indent
16335 'vhdl-association-list-with-formals
16336 'vhdl-conditions-in-parenthesis
16342 'vhdl-copyright-string
16343 'vhdl-platform-spec
16345 'vhdl-modify-date-prefix-string
16346 'vhdl-modify-date-on-saving
16348 'vhdl-reset-active-high
16349 'vhdl-clock-rising-edge
16350 'vhdl-clock-edge-condition
16354 'vhdl-include-port-comments
16355 'vhdl-include-direction-comments
16356 'vhdl-include-type-comments
16357 'vhdl-include-group-comments
16358 'vhdl-actual-port-name
16359 'vhdl-instance-name
16360 'vhdl-testbench-entity-name
16361 'vhdl-testbench-architecture-name
16362 'vhdl-testbench-configuration-name
16363 'vhdl-testbench-dut-name
16364 'vhdl-testbench-include-header
16365 'vhdl-testbench-declarations
16366 'vhdl-testbench-statements
16367 'vhdl-testbench-initialize-signals
16368 'vhdl-testbench-include-library
16369 'vhdl-testbench-include-configuration
16370 'vhdl-testbench-create-files
16371 'vhdl-compose-create-files
16372 'vhdl-compose-include-header
16373 'vhdl-compose-architecture-name
16374 'vhdl-components-package-name
16375 'vhdl-use-components-package
16376 'vhdl-self-insert-comments
16377 'vhdl-prompt-for-comments
16378 'vhdl-inline-comment-column
16379 'vhdl-end-comment-column
16382 'vhdl-align-group-separate
16383 'vhdl-align-same-indent
16384 'vhdl-highlight-keywords
16385 'vhdl-highlight-names
16386 'vhdl-highlight-special-words
16387 'vhdl-highlight-forbidden-words
16388 'vhdl-highlight-verilog-keywords
16389 'vhdl-highlight-translate-off
16390 'vhdl-highlight-case-sensitive
16391 'vhdl-special-syntax-alist
16392 'vhdl-forbidden-words
16393 'vhdl-forbidden-syntax
16394 'vhdl-directive-keywords
16395 'vhdl-speedbar-auto-open
16396 'vhdl-speedbar-display-mode
16397 'vhdl-speedbar-scan-limit
16398 'vhdl-speedbar-jump-to-unit
16399 'vhdl-speedbar-update-on-saving
16400 'vhdl-speedbar-save-cache
16401 'vhdl-speedbar-cache-file-name
16403 'vhdl-source-file-menu
16404 'vhdl-hideshow-menu
16405 'vhdl-hide-all-init
16406 'vhdl-print-two-column
16407 'vhdl-print-customize-faces
16408 'vhdl-intelligent-tab
16409 'vhdl-indent-syntax-based
16410 'vhdl-word-completion-case-sensitive
16411 'vhdl-word-completion-in-minibuffer
16412 'vhdl-underscore-is-part-of-word
16417 (if vhdl-special-indent-hook
16418 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16419 "vhdl-special-indent-hook is set to '"
16420 (format "%s" vhdl-special-indent-hook)
16421 ".\nPerhaps this is your problem?\n"
16422 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16432 (defconst vhdl-doc-release-notes nil
16434 Release Notes for VHDL Mode 3.32
16435 ================================
16438 - Enhanced Features
16446 STRUCTURAL COMPOSITION:
16447 - Enables simple structural composition similar to graphical editors.
16448 Simplifies the creation of higher design levels where subcomponents
16449 are simply sticked together:
16450 1. Create a skeleton for a new component
16451 2. Place subcomponents in it directly from the hierarchy browser
16452 3. Automatically connect all subcomponents and create the ports
16453 for the new component (based on names of actual ports)
16454 - Automatic generation of a components package (package containing
16455 component declarations for all entities).
16456 - Find more information in the online documentation (`C-c C-h').
16459 - Reverse direction of ports (useful for testbenches).
16461 SUBPROGRAM TRANSLATION:
16462 - Copy/paste of subprogram interfaces (similar to port translation).
16465 - Condense code using code-sensitive block filling.
16468 - Calculate number of code lines and statements in a buffer.
16474 TESTBENCH GENERATION:
16475 - Enhanced templates and user option default values.
16477 Emacs 21 compatibility/enhancements:
16478 - `lazy-lock-mode' is not used anymore (built-in `jit-lock-mode' is faster).
16480 And many other minor fixes and enhancements.
16486 `vhdl-project-file-name': (enhanced)
16487 Include user name in project setup file name.
16488 `vhdl-speedbar-cache-file-name': (enhanced, changed default)
16489 Include user name in cache file name.
16490 `vhdl-default-library': (new)
16491 Default working library if no project is active.
16492 `vhdl-architecture-file-name': (new)
16493 Specify how the architecture file name is obtained.
16494 `vhdl-package-file-name': (new)
16495 Specify how the package file name is obtained.
16496 `vhdl-file-name-case': (new)
16497 Allows to change case when deriving file names.
16498 `vhdl-compose-create-files': (new)
16499 Specify whether new files should be created for a new component.
16500 `vhdl-compose-include-header': (new)
16501 Specify whether a header is included in a new component's file.
16502 `vhdl-compose-architecture-name': (new)
16503 Specify how a new component's architecture name is obtained.
16504 `vhdl-components-package-name': (new)
16505 Specify how the name for the components package is obtained.
16506 `vhdl-use-components-package': (new)
16507 Specify whether component declarations go in a components package.
16508 `vhdl-use-direct-instantiation': (new)
16509 Specify whether to use VHDL'93 direct component instantiation.
16510 `vhdl-instance-name': (changed default)
16511 Allows insertion of a running number to generate unique instance names.
16512 `vhdl-testbench-entity-header', `vhdl-testbench-architecture-header':(obsolete)
16513 Headers are now automatically derived from the standard header.
16514 `vhdl-testbench-include-header': (new)
16515 Specify whether a header is included in testbench files.
16516 `vhdl-testbench-declaration', `vhdl-testbench-statements': (changed default)
16517 Non-empty default values for more complete testbench templates.
16523 - Changed key binding for `vhdl-comment-uncomment-region': `C-c c'
16524 (`C-c C-c ...' is now used for structural composition).
16526 - Automatic buffer highlighting (font-lock) is now controlled by option
16527 `global-font-lock-mode' in GNU Emacs (`font-lock-auto-fontify' in XEmacs).
16528 \(Important: You MUST customize this option in order to turn automatic
16529 buffer highlighting on.)
16533 (defconst vhdl-doc-keywords nil
16535 Reserved words in VHDL
16536 ----------------------
16538 VHDL'93 (IEEE Std 1076-1993):
16539 `vhdl-93-keywords' : keywords
16540 `vhdl-93-types' : standardized types
16541 `vhdl-93-attributes' : standardized attributes
16542 `vhdl-93-enum-values' : standardized enumeration values
16543 `vhdl-93-functions' : standardized functions
16544 `vhdl-93-packages' : standardized packages and libraries
16546 VHDL-AMS (IEEE Std 1076.1):
16547 `vhdl-ams-keywords' : keywords
16548 `vhdl-ams-types' : standardized types
16549 `vhdl-ams-attributes' : standardized attributes
16550 `vhdl-ams-enum-values' : standardized enumeration values
16551 `vhdl-ams-functions' : standardized functions
16553 Math Packages (IEEE Std 1076.2):
16554 `vhdl-math-types' : standardized types
16555 `vhdl-math-constants' : standardized constants
16556 `vhdl-math-functions' : standardized functions
16557 `vhdl-math-packages' : standardized packages
16560 `vhdl-verilog-keywords' : Verilog reserved words
16562 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16565 (defconst vhdl-doc-coding-style nil
16567 For VHDL coding style and naming convention guidelines, see the following
16571 \"VHDL Coding Styles and Methodologies\".
16572 Kluwer Academic Publishers, 1999.
16573 http://members.aol.com/vhdlcohen/vhdl/
16575 \[2] Michael Keating and Pierre Bricaud.
16576 \"Reuse Methodology Manual, Second Edition\".
16577 Kluwer Academic Publishers, 1999.
16578 http://www.openmore.com/openmore/rmm2.html
16580 \[3] European Space Agency.
16581 \"VHDL Modelling Guidelines\".
16582 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16584 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16585 to visually support naming conventions.")
16588 (defun vhdl-version ()
16589 "Echo the current version of VHDL Mode in the minibuffer."
16591 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16592 (vhdl-keep-region-active))
16594 (defun vhdl-doc-variable (variable)
16595 "Display VARIABLE's documentation in *Help* buffer."
16597 (unless vhdl-xemacs
16598 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16599 (with-output-to-temp-buffer (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16600 (princ (documentation-property variable 'variable-documentation))
16601 (with-current-buffer standard-output
16603 (print-help-return-message)))
16605 (defun vhdl-doc-mode ()
16606 "Display VHDL Mode documentation in *Help* buffer."
16608 (unless vhdl-xemacs
16609 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16610 (with-output-to-temp-buffer (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16613 (princ (documentation 'vhdl-mode))
16614 (with-current-buffer standard-output
16616 (print-help-return-message)))
16619 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16621 (provide 'vhdl-mode)
16623 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
16624 ;;; vhdl-mode.el ends here