1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2003 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., 59 Temple Place - Suite 330,
32 ;; Boston, MA 02111-1307, 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 GNU 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-face' : standardized types
1384 `vhdl-font-lock-attribute-face': standardized attributes
1385 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1386 `vhdl-font-lock-function-face' : 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-font-lock-attribute-face': 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-font-lock-reserved-words-face') 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-font-lock-reserved-words-face') 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-font-lock-translate-off-face').
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
1504 \"vhdl-font-lock-\" + name + \"-face\".
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."
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 (format "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 (define-key vhdl-mode-map "\t" 'indent-according-to-mode))
2683 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2684 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2685 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2686 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2687 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2688 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2689 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2690 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2691 (when (vhdl-standard-p 'ams)
2692 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2694 ;; initialize mode map for VHDL Mode
2695 (vhdl-mode-map-init)
2697 ;; define special minibuffer keymap for enabling word completion in minibuffer
2698 ;; (useful in template generator prompts)
2699 (defvar vhdl-minibuffer-local-map (copy-keymap minibuffer-local-map)
2700 "Keymap for minibuffer used in VHDL Mode.")
2702 (when vhdl-word-completion-in-minibuffer
2703 (define-key vhdl-minibuffer-local-map "\t" 'vhdl-minibuffer-tab))
2705 ;; set up electric character functions to work with
2706 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2710 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2711 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2712 '(vhdl-electric-space
2714 vhdl-electric-return
2716 vhdl-electric-open-bracket
2717 vhdl-electric-close-bracket
2719 vhdl-electric-semicolon
2721 vhdl-electric-period
2722 vhdl-electric-equal))
2724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2727 (defvar vhdl-mode-syntax-table nil
2728 "Syntax table used in `vhdl-mode' buffers.")
2730 (defvar vhdl-mode-ext-syntax-table nil
2731 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2733 (defun vhdl-mode-syntax-table-init ()
2734 "Initialize `vhdl-mode-syntax-table'."
2735 (setq vhdl-mode-syntax-table (make-syntax-table))
2736 ;; define punctuation
2737 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2738 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2739 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2740 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
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)
2754 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2755 ;; define underscore
2756 (when vhdl-underscore-is-part-of-word
2757 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2758 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2759 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2760 ;; and \n and \^M end a comment
2761 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2762 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2763 ;; define parentheses to match
2764 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2765 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2766 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2767 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2768 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2769 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2770 ;; extended syntax table including '_' (for simpler search regexps)
2771 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2772 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2774 ;; initialize syntax table for VHDL Mode
2775 (vhdl-mode-syntax-table-init)
2777 (defvar vhdl-syntactic-context nil
2778 "Buffer local variable containing syntactic analysis list.")
2779 (make-variable-buffer-local 'vhdl-syntactic-context)
2781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2782 ;; Abbrev ook bindings
2784 (defvar vhdl-mode-abbrev-table nil
2785 "Abbrev table to use in `vhdl-mode' buffers.")
2787 (defun vhdl-mode-abbrev-table-init ()
2788 "Initialize `vhdl-mode-abbrev-table'."
2789 (when vhdl-mode-abbrev-table (clear-abbrev-table vhdl-mode-abbrev-table))
2790 (define-abbrev-table 'vhdl-mode-abbrev-table
2792 (when (memq 'vhdl vhdl-electric-keywords)
2795 ("--" "" vhdl-template-display-comment-hook 0)
2796 ("abs" "" vhdl-template-default-hook 0)
2797 ("access" "" vhdl-template-default-hook 0)
2798 ("after" "" vhdl-template-default-hook 0)
2799 ("alias" "" vhdl-template-alias-hook 0)
2800 ("all" "" vhdl-template-default-hook 0)
2801 ("and" "" vhdl-template-default-hook 0)
2802 ("arch" "" vhdl-template-architecture-hook 0)
2803 ("architecture" "" vhdl-template-architecture-hook 0)
2804 ("array" "" vhdl-template-default-hook 0)
2805 ("assert" "" vhdl-template-assert-hook 0)
2806 ("attr" "" vhdl-template-attribute-hook 0)
2807 ("attribute" "" vhdl-template-attribute-hook 0)
2808 ("begin" "" vhdl-template-default-indent-hook 0)
2809 ("block" "" vhdl-template-block-hook 0)
2810 ("body" "" vhdl-template-default-hook 0)
2811 ("buffer" "" vhdl-template-default-hook 0)
2812 ("bus" "" vhdl-template-default-hook 0)
2813 ("case" "" vhdl-template-case-hook 0)
2814 ("comp" "" vhdl-template-component-hook 0)
2815 ("component" "" vhdl-template-component-hook 0)
2816 ("cond" "" vhdl-template-conditional-signal-asst-hook 0)
2817 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0)
2818 ("conf" "" vhdl-template-configuration-hook 0)
2819 ("configuration" "" vhdl-template-configuration-hook 0)
2820 ("cons" "" vhdl-template-constant-hook 0)
2821 ("constant" "" vhdl-template-constant-hook 0)
2822 ("disconnect" "" vhdl-template-disconnect-hook 0)
2823 ("downto" "" vhdl-template-default-hook 0)
2824 ("else" "" vhdl-template-else-hook 0)
2825 ("elseif" "" vhdl-template-elsif-hook 0)
2826 ("elsif" "" vhdl-template-elsif-hook 0)
2827 ("end" "" vhdl-template-default-indent-hook 0)
2828 ("entity" "" vhdl-template-entity-hook 0)
2829 ("exit" "" vhdl-template-exit-hook 0)
2830 ("file" "" vhdl-template-file-hook 0)
2831 ("for" "" vhdl-template-for-hook 0)
2832 ("func" "" vhdl-template-function-hook 0)
2833 ("function" "" vhdl-template-function-hook 0)
2834 ("generic" "" vhdl-template-generic-hook 0)
2835 ("group" "" vhdl-template-group-hook 0)
2836 ("guarded" "" vhdl-template-default-hook 0)
2837 ("if" "" vhdl-template-if-hook 0)
2838 ("impure" "" vhdl-template-default-hook 0)
2839 ("in" "" vhdl-template-default-hook 0)
2840 ("inertial" "" vhdl-template-default-hook 0)
2841 ("inout" "" vhdl-template-default-hook 0)
2842 ("inst" "" vhdl-template-instance-hook 0)
2843 ("instance" "" vhdl-template-instance-hook 0)
2844 ("is" "" vhdl-template-default-hook 0)
2845 ("label" "" vhdl-template-default-hook 0)
2846 ("library" "" vhdl-template-library-hook 0)
2847 ("linkage" "" vhdl-template-default-hook 0)
2848 ("literal" "" vhdl-template-default-hook 0)
2849 ("loop" "" vhdl-template-bare-loop-hook 0)
2850 ("map" "" vhdl-template-map-hook 0)
2851 ("mod" "" vhdl-template-default-hook 0)
2852 ("nand" "" vhdl-template-default-hook 0)
2853 ("new" "" vhdl-template-default-hook 0)
2854 ("next" "" vhdl-template-next-hook 0)
2855 ("nor" "" vhdl-template-default-hook 0)
2856 ("not" "" vhdl-template-default-hook 0)
2857 ("null" "" vhdl-template-default-hook 0)
2858 ("of" "" vhdl-template-default-hook 0)
2859 ("on" "" vhdl-template-default-hook 0)
2860 ("open" "" vhdl-template-default-hook 0)
2861 ("or" "" vhdl-template-default-hook 0)
2862 ("others" "" vhdl-template-others-hook 0)
2863 ("out" "" vhdl-template-default-hook 0)
2864 ("pack" "" vhdl-template-package-hook 0)
2865 ("package" "" vhdl-template-package-hook 0)
2866 ("port" "" vhdl-template-port-hook 0)
2867 ("postponed" "" vhdl-template-default-hook 0)
2868 ("procedure" "" vhdl-template-procedure-hook 0)
2869 ("process" "" vhdl-template-process-hook 0)
2870 ("pure" "" vhdl-template-default-hook 0)
2871 ("range" "" vhdl-template-default-hook 0)
2872 ("record" "" vhdl-template-default-hook 0)
2873 ("register" "" vhdl-template-default-hook 0)
2874 ("reject" "" vhdl-template-default-hook 0)
2875 ("rem" "" vhdl-template-default-hook 0)
2876 ("report" "" vhdl-template-report-hook 0)
2877 ("return" "" vhdl-template-return-hook 0)
2878 ("rol" "" vhdl-template-default-hook 0)
2879 ("ror" "" vhdl-template-default-hook 0)
2880 ("select" "" vhdl-template-selected-signal-asst-hook 0)
2881 ("severity" "" vhdl-template-default-hook 0)
2882 ("shared" "" vhdl-template-default-hook 0)
2883 ("sig" "" vhdl-template-signal-hook 0)
2884 ("signal" "" vhdl-template-signal-hook 0)
2885 ("sla" "" vhdl-template-default-hook 0)
2886 ("sll" "" vhdl-template-default-hook 0)
2887 ("sra" "" vhdl-template-default-hook 0)
2888 ("srl" "" vhdl-template-default-hook 0)
2889 ("subtype" "" vhdl-template-subtype-hook 0)
2890 ("then" "" vhdl-template-default-hook 0)
2891 ("to" "" vhdl-template-default-hook 0)
2892 ("transport" "" vhdl-template-default-hook 0)
2893 ("type" "" vhdl-template-type-hook 0)
2894 ("unaffected" "" vhdl-template-default-hook 0)
2895 ("units" "" vhdl-template-default-hook 0)
2896 ("until" "" vhdl-template-default-hook 0)
2897 ("use" "" vhdl-template-use-hook 0)
2898 ("var" "" vhdl-template-variable-hook 0)
2899 ("variable" "" vhdl-template-variable-hook 0)
2900 ("wait" "" vhdl-template-wait-hook 0)
2901 ("when" "" vhdl-template-when-hook 0)
2902 ("while" "" vhdl-template-while-loop-hook 0)
2903 ("with" "" vhdl-template-with-hook 0)
2904 ("xnor" "" vhdl-template-default-hook 0)
2905 ("xor" "" vhdl-template-default-hook 0)
2907 ;; VHDL-AMS keywords
2908 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2910 ("across" "" vhdl-template-default-hook 0)
2911 ("break" "" vhdl-template-break-hook 0)
2912 ("limit" "" vhdl-template-limit-hook 0)
2913 ("nature" "" vhdl-template-nature-hook 0)
2914 ("noise" "" vhdl-template-default-hook 0)
2915 ("procedural" "" vhdl-template-procedural-hook 0)
2916 ("quantity" "" vhdl-template-quantity-hook 0)
2917 ("reference" "" vhdl-template-default-hook 0)
2918 ("spectrum" "" vhdl-template-default-hook 0)
2919 ("subnature" "" vhdl-template-subnature-hook 0)
2920 ("terminal" "" vhdl-template-terminal-hook 0)
2921 ("through" "" vhdl-template-default-hook 0)
2922 ("tolerance" "" vhdl-template-default-hook 0)
2924 ;; user model keywords
2925 (when (memq 'user vhdl-electric-keywords)
2926 (let ((alist vhdl-model-alist)
2927 abbrev-list keyword)
2929 (setq keyword (nth 3 (car alist)))
2930 (unless (equal keyword "")
2932 (cons (list keyword ""
2934 "vhdl-model" (nth 0 (car alist)) "hook") 0)
2936 (setq alist (cdr alist)))
2939 ;; initialize abbrev table for VHDL Mode
2940 (vhdl-mode-abbrev-table-init)
2942 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2943 ;; Template completion lists
2945 (defvar vhdl-template-construct-alist nil
2946 "List of built-in construct templates.")
2948 (defun vhdl-template-construct-alist-init ()
2949 "Initialize `vhdl-template-construct-alist'."
2951 vhdl-template-construct-alist
2954 ("alias declaration" vhdl-template-alias)
2955 ("architecture body" vhdl-template-architecture)
2956 ("assertion" vhdl-template-assert)
2957 ("attribute declaration" vhdl-template-attribute-decl)
2958 ("attribute specification" vhdl-template-attribute-spec)
2959 ("block configuration" vhdl-template-block-configuration)
2960 ("block statement" vhdl-template-block)
2961 ("case statement" vhdl-template-case-is)
2962 ("component configuration" vhdl-template-component-conf)
2963 ("component declaration" vhdl-template-component-decl)
2964 ("component instantiation statement" vhdl-template-component-inst)
2965 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
2966 ("configuration declaration" vhdl-template-configuration-decl)
2967 ("configuration specification" vhdl-template-configuration-spec)
2968 ("constant declaration" vhdl-template-constant)
2969 ("disconnection specification" vhdl-template-disconnect)
2970 ("entity declaration" vhdl-template-entity)
2971 ("exit statement" vhdl-template-exit)
2972 ("file declaration" vhdl-template-file)
2973 ("generate statement" vhdl-template-generate)
2974 ("generic clause" vhdl-template-generic)
2975 ("group declaration" vhdl-template-group-decl)
2976 ("group template declaration" vhdl-template-group-template)
2977 ("if statement" vhdl-template-if-then)
2978 ("library clause" vhdl-template-library)
2979 ("loop statement" vhdl-template-loop)
2980 ("next statement" vhdl-template-next)
2981 ("package declaration" vhdl-template-package-decl)
2982 ("package body" vhdl-template-package-body)
2983 ("port clause" vhdl-template-port)
2984 ("process statement" vhdl-template-process)
2985 ("report statement" vhdl-template-report)
2986 ("return statement" vhdl-template-return)
2987 ("selected signal assignment" vhdl-template-selected-signal-asst)
2988 ("signal declaration" vhdl-template-signal)
2989 ("subprogram declaration" vhdl-template-subprogram-decl)
2990 ("subprogram body" vhdl-template-subprogram-body)
2991 ("subtype declaration" vhdl-template-subtype)
2992 ("type declaration" vhdl-template-type)
2993 ("use clause" vhdl-template-use)
2994 ("variable declaration" vhdl-template-variable)
2995 ("wait statement" vhdl-template-wait)
2997 (when (vhdl-standard-p 'ams)
2999 ("break statement" vhdl-template-break)
3000 ("nature declaration" vhdl-template-nature)
3001 ("quantity declaration" vhdl-template-quantity)
3002 ("simultaneous case statement" vhdl-template-case-use)
3003 ("simultaneous if statement" vhdl-template-if-use)
3004 ("simultaneous procedural statement" vhdl-template-procedural)
3005 ("step limit specification" vhdl-template-limit)
3006 ("subnature declaration" vhdl-template-subnature)
3007 ("terminal declaration" vhdl-template-terminal)
3010 ;; initialize for VHDL Mode
3011 (vhdl-template-construct-alist-init)
3013 (defvar vhdl-template-package-alist nil
3014 "List of built-in package templates.")
3016 (defun vhdl-template-package-alist-init ()
3017 "Initialize `vhdl-template-package-alist'."
3019 vhdl-template-package-alist
3022 ("numeric_bit" vhdl-template-package-numeric-bit)
3023 ("numeric_std" vhdl-template-package-numeric-std)
3024 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3025 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3026 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3027 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3028 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3029 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3030 ("textio" vhdl-template-package-textio)
3032 (when (vhdl-standard-p 'math)
3034 ("math_complex" vhdl-template-package-math-complex)
3035 ("math_real" vhdl-template-package-math-real)
3038 ;; initialize for VHDL Mode
3039 (vhdl-template-package-alist-init)
3041 (defvar vhdl-template-directive-alist
3043 ("translate_on" vhdl-template-directive-translate-on)
3044 ("translate_off" vhdl-template-directive-translate-off)
3045 ("synthesis_on" vhdl-template-directive-synthesis-on)
3046 ("synthesis_off" vhdl-template-directive-synthesis-off)
3048 "List of built-in directive templates.")
3051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3053 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3056 ;; VHDL menu (using `easy-menu.el')
3058 (defun vhdl-customize ()
3059 "Call the customize function with `vhdl' as argument."
3061 (customize-browse 'vhdl))
3063 (defun vhdl-create-mode-menu ()
3064 "Create VHDL Mode menu."
3068 ["None" (vhdl-set-project "")
3069 :style radio :selected (null vhdl-project)]
3071 ;; add menu entries for defined projects
3072 (let ((project-alist vhdl-project-alist) menu-list name)
3073 (while project-alist
3074 (setq name (caar project-alist))
3076 (cons `[,name (vhdl-set-project ,name)
3077 :style radio :selected (equal ,name vhdl-project)]
3079 (setq project-alist (cdr project-alist)))
3081 (if vhdl-project-sort
3083 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3084 (nreverse menu-list)))
3085 (vhdl-menu-split menu-list "Project"))
3087 ["Select Project..." vhdl-set-project t]
3089 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3090 ["Import Project..." vhdl-import-project
3091 :keys "C-c C-p C-m" :active t]
3092 ["Export Project" vhdl-export-project vhdl-project]
3094 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3097 ["Compile Buffer" vhdl-compile t]
3098 ["Stop Compilation" kill-compilation t]
3100 ["Make" vhdl-make t]
3101 ["Generate Makefile" vhdl-generate-makefile t]
3103 ["Next Error" next-error t]
3104 ["Previous Error" previous-error t]
3105 ["First Error" first-error t]
3109 ;; add menu entries for defined compilers
3110 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3112 (setq name (caar comp-alist))
3114 (cons `[,name (setq vhdl-compiler ,name)
3115 :style radio :selected (equal ,name vhdl-compiler)]
3117 (setq comp-alist (cdr comp-alist)))
3118 (setq menu-list (nreverse menu-list))
3119 (vhdl-menu-split menu-list "Compiler"))
3121 ["Select Compiler..." vhdl-set-compiler t]
3123 ["Customize Compiler..."
3124 (customize-option 'vhdl-compiler-alist) t])))
3129 ["Alias" vhdl-template-alias t]
3130 ["Architecture" vhdl-template-architecture t]
3131 ["Assert" vhdl-template-assert t]
3132 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3133 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3134 ["Block" vhdl-template-block t]
3135 ["Case" vhdl-template-case-is t]
3136 ["Component (Decl)" vhdl-template-component-decl t]
3137 ["(Component) Instance" vhdl-template-component-inst t]
3138 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3139 ["Configuration (Block)" vhdl-template-block-configuration t]
3140 ["Configuration (Comp)" vhdl-template-component-conf t]
3141 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3142 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3143 ["Constant" vhdl-template-constant t]
3144 ["Disconnect" vhdl-template-disconnect t]
3145 ["Else" vhdl-template-else t]
3146 ["Elsif" vhdl-template-elsif t]
3147 ["Entity" vhdl-template-entity t]
3148 ["Exit" vhdl-template-exit t]
3149 ["File" vhdl-template-file t]
3150 ["For (Generate)" vhdl-template-for-generate t]
3151 ["For (Loop)" vhdl-template-for-loop t]
3152 ["Function (Body)" vhdl-template-function-body t]
3153 ["Function (Decl)" vhdl-template-function-decl t]
3154 ["Generic" vhdl-template-generic t]
3155 ["Group (Decl)" vhdl-template-group-decl t]
3156 ["Group (Template)" vhdl-template-group-template t])
3158 ["If (Generate)" vhdl-template-if-generate t]
3159 ["If (Then)" vhdl-template-if-then t]
3160 ["Library" vhdl-template-library t]
3161 ["Loop" vhdl-template-bare-loop t]
3162 ["Map" vhdl-template-map t]
3163 ["Next" vhdl-template-next t]
3164 ["Others (Aggregate)" vhdl-template-others t]
3165 ["Package (Decl)" vhdl-template-package-decl t]
3166 ["Package (Body)" vhdl-template-package-body t]
3167 ["Port" vhdl-template-port t]
3168 ["Procedure (Body)" vhdl-template-procedure-body t]
3169 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3170 ["Process (Comb)" vhdl-template-process-comb t]
3171 ["Process (Seq)" vhdl-template-process-seq t]
3172 ["Report" vhdl-template-report t]
3173 ["Return" vhdl-template-return t]
3174 ["Select" vhdl-template-selected-signal-asst t]
3175 ["Signal" vhdl-template-signal t]
3176 ["Subtype" vhdl-template-subtype t]
3177 ["Type" vhdl-template-type t]
3178 ["Use" vhdl-template-use t]
3179 ["Variable" vhdl-template-variable t]
3180 ["Wait" vhdl-template-wait t]
3181 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3182 ["When" vhdl-template-when t]
3183 ["While (Loop)" vhdl-template-while-loop t]
3184 ["With" vhdl-template-with t]))
3185 (when (vhdl-standard-p 'ams)
3186 '(("VHDL-AMS Construct"
3187 ["Break" vhdl-template-break t]
3188 ["Case (Use)" vhdl-template-case-use t]
3189 ["If (Use)" vhdl-template-if-use t]
3190 ["Limit" vhdl-template-limit t]
3191 ["Nature" vhdl-template-nature t]
3192 ["Procedural" vhdl-template-procedural t]
3193 ["Quantity (Free)" vhdl-template-quantity-free t]
3194 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3195 ["Quantity (Source)" vhdl-template-quantity-source t]
3196 ["Subnature" vhdl-template-subnature t]
3197 ["Terminal" vhdl-template-terminal t])))
3198 '(["Insert Construct..." vhdl-template-insert-construct
3199 :keys "C-c C-i C-t"]
3204 (when (vhdl-standard-p 'math)
3205 '(["math_complex" vhdl-template-package-math-complex t]
3206 ["math_real" vhdl-template-package-math-real t]))
3207 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3208 ["numeric_std" vhdl-template-package-numeric-std t]
3209 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3210 ["textio" vhdl-template-package-textio t]
3212 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3213 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3214 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3215 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3216 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3218 ["Insert Package..." vhdl-template-insert-package
3219 :keys "C-c C-i C-p"])))
3221 ["translate_on" vhdl-template-directive-translate-on t]
3222 ["translate_off" vhdl-template-directive-translate-off t]
3223 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3224 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3226 ["Insert Directive..." vhdl-template-insert-directive
3227 :keys "C-c C-i C-d"])
3229 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3230 ["Insert Footer" vhdl-template-footer t]
3231 ["Insert Date" vhdl-template-insert-date t]
3232 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3234 ["Query Next Prompt" vhdl-template-search-prompt t]))
3237 ;; add menu entries for defined models
3238 (let ((model-alist vhdl-model-alist) menu-list model)
3240 (setq model (car model-alist))
3245 (vhdl-function-name "vhdl-model" (nth 0 model))
3246 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3248 (setq model-alist (cdr model-alist)))
3249 (setq menu-list (nreverse menu-list))
3250 (vhdl-menu-split menu-list "Model"))
3252 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3253 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3255 ["Copy" vhdl-port-copy t]
3257 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3258 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3259 ["Paste As Instance" vhdl-port-paste-instance
3260 :keys "C-c C-p C-i" :active vhdl-port-list]
3261 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3262 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3263 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3264 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3266 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3268 ["Flatten" vhdl-port-flatten
3269 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3270 ["Reverse Direction" vhdl-port-reverse-direction
3271 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3273 ["New Component" vhdl-compose-new-component t]
3274 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3275 ["Wire Components" vhdl-compose-wire-components t]
3277 ["Generate Components Package" vhdl-compose-components-package t])
3279 ["Copy" vhdl-subprog-copy t]
3281 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3282 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3283 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3285 ["Flatten" vhdl-subprog-flatten
3286 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3289 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3291 ["Insert Inline Comment" vhdl-comment-append-inline t]
3292 ["Insert Horizontal Line" vhdl-comment-display-line t]
3293 ["Insert Display Comment" vhdl-comment-display t]
3295 ["Fill Comment" fill-paragraph t]
3296 ["Fill Comment Region" fill-region (mark)]
3297 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3298 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3300 ["Kill" vhdl-line-kill t]
3301 ["Copy" vhdl-line-copy t]
3302 ["Yank" vhdl-line-yank t]
3303 ["Expand" vhdl-line-expand t]
3305 ["Transpose Next" vhdl-line-transpose-next t]
3306 ["Transpose Prev" vhdl-line-transpose-previous t]
3307 ["Open" vhdl-line-open t]
3308 ["Join" vhdl-delete-indentation t]
3310 ["Goto" goto-line t]
3311 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3313 ["Forward Statement" vhdl-end-of-statement t]
3314 ["Backward Statement" vhdl-beginning-of-statement t]
3315 ["Forward Expression" vhdl-forward-sexp t]
3316 ["Backward Expression" vhdl-backward-sexp t]
3317 ["Forward Same Indent" vhdl-forward-same-indent t]
3318 ["Backward Same Indent" vhdl-backward-same-indent t]
3319 ["Forward Function" vhdl-end-of-defun t]
3320 ["Backward Function" vhdl-beginning-of-defun t]
3321 ["Mark Function" vhdl-mark-defun t])
3324 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3325 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3326 ["Region" vhdl-indent-region (mark)]
3327 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3329 ["Group" vhdl-align-group t]
3330 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3331 ["List" vhdl-align-list t]
3332 ["Declarations" vhdl-align-declarations t]
3333 ["Region" vhdl-align-region (mark)]
3334 ["Buffer" vhdl-align-buffer t]
3336 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3337 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3338 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3340 ["List" vhdl-fill-list t]
3341 ["Group" vhdl-fill-group t]
3342 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3343 ["Region" vhdl-fill-region (mark)])
3345 ["Region" vhdl-beautify-region (mark)]
3346 ["Buffer" vhdl-beautify-buffer t])
3348 ["Generic/Port Clause" vhdl-fix-clause t]
3350 ["Case Region" vhdl-fix-case-region (mark)]
3351 ["Case Buffer" vhdl-fix-case-buffer t]
3353 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3354 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3356 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3358 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3359 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3361 ["Fontify Buffer" vhdl-fontify-buffer t]
3362 ["Statistics Buffer" vhdl-statistics-buffer t]
3363 ["Show Messages" vhdl-show-messages t]
3364 ["Syntactic Info" vhdl-show-syntactic-information t]
3366 ["Speedbar" vhdl-speedbar t]
3367 ["Hide/Show" vhdl-hs-minor-mode t]
3370 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3371 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3372 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3373 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3374 ["Version" vhdl-version t]
3375 ["Bug Report..." vhdl-submit-bug-report t]
3380 (progn (customize-set-variable 'vhdl-electric-mode
3381 (not vhdl-electric-mode))
3382 (vhdl-mode-line-update))
3383 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3385 (progn (customize-set-variable 'vhdl-stutter-mode
3386 (not vhdl-stutter-mode))
3387 (vhdl-mode-line-update))
3388 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3390 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3391 (not vhdl-indent-tabs-mode))
3392 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3393 :style toggle :selected vhdl-indent-tabs-mode]
3395 ["Customize Group..." (customize-group 'vhdl-mode) t])
3397 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3399 '("Selected Project at Startup"
3400 ["None" (progn (customize-set-variable 'vhdl-project nil)
3401 (vhdl-set-project ""))
3402 :style radio :selected (null vhdl-project)]
3404 ;; add menu entries for defined projects
3405 (let ((project-alist vhdl-project-alist) menu-list name)
3406 (while project-alist
3407 (setq name (caar project-alist))
3409 (cons `[,name (progn (customize-set-variable
3410 'vhdl-project ,name)
3411 (vhdl-set-project ,name))
3412 :style radio :selected (equal ,name vhdl-project)]
3414 (setq project-alist (cdr project-alist)))
3415 (setq menu-list (nreverse menu-list))
3416 (vhdl-menu-split menu-list "Project")))
3417 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3418 ("Auto Load Setup File"
3420 (customize-set-variable 'vhdl-project-auto-load
3421 (if (memq 'startup vhdl-project-auto-load)
3422 (delq 'startup vhdl-project-auto-load)
3423 (cons 'startup vhdl-project-auto-load)))
3424 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3426 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3427 :style toggle :selected vhdl-project-sort]
3429 ["Customize Group..." (customize-group 'vhdl-project) t])
3431 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3433 '("Selected Compiler at Startup")
3434 ;; add menu entries for defined compilers
3435 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3437 (setq name (caar comp-alist))
3439 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3440 :style radio :selected (equal ,name vhdl-compiler)]
3442 (setq comp-alist (cdr comp-alist)))
3443 (setq menu-list (nreverse menu-list))
3444 (vhdl-menu-split menu-list "Compler")))
3445 ["Use Local Error Regexp"
3446 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3447 (not vhdl-compile-use-local-error-regexp))
3448 :style toggle :selected vhdl-compile-use-local-error-regexp]
3449 ["Makefile Generation Hook..."
3450 (customize-option 'vhdl-makefile-generation-hook) t]
3451 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3453 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3457 (progn (customize-set-variable 'vhdl-standard
3458 (list '87 (cadr vhdl-standard)))
3459 (vhdl-activate-customizations))
3460 :style radio :selected (eq '87 (car vhdl-standard))]
3462 (progn (customize-set-variable 'vhdl-standard
3463 (list '93 (cadr vhdl-standard)))
3464 (vhdl-activate-customizations))
3465 :style radio :selected (eq '93 (car vhdl-standard))]
3468 (progn (customize-set-variable
3469 'vhdl-standard (list (car vhdl-standard)
3470 (if (memq 'ams (cadr vhdl-standard))
3471 (delq 'ams (cadr vhdl-standard))
3472 (cons 'ams (cadr vhdl-standard)))))
3473 (vhdl-activate-customizations))
3474 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3476 (progn (customize-set-variable
3477 'vhdl-standard (list (car vhdl-standard)
3478 (if (memq 'math (cadr vhdl-standard))
3479 (delq 'math (cadr vhdl-standard))
3480 (cons 'math (cadr vhdl-standard)))))
3481 (vhdl-activate-customizations))
3482 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3483 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3484 ["Upper Case Keywords"
3485 (customize-set-variable 'vhdl-upper-case-keywords
3486 (not vhdl-upper-case-keywords))
3487 :style toggle :selected vhdl-upper-case-keywords]
3489 (customize-set-variable 'vhdl-upper-case-types
3490 (not vhdl-upper-case-types))
3491 :style toggle :selected vhdl-upper-case-types]
3492 ["Upper Case Attributes"
3493 (customize-set-variable 'vhdl-upper-case-attributes
3494 (not vhdl-upper-case-attributes))
3495 :style toggle :selected vhdl-upper-case-attributes]
3496 ["Upper Case Enumeration Values"
3497 (customize-set-variable 'vhdl-upper-case-enum-values
3498 (not vhdl-upper-case-enum-values))
3499 :style toggle :selected vhdl-upper-case-enum-values]
3500 ["Upper Case Constants"
3501 (customize-set-variable 'vhdl-upper-case-constants
3502 (not vhdl-upper-case-constants))
3503 :style toggle :selected vhdl-upper-case-constants]
3504 ("Use Direct Instantiation"
3506 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3507 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3509 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3510 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3512 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3513 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3515 ["Customize Group..." (customize-group 'vhdl-style) t])
3517 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3518 ["Architecture File Name..."
3519 (customize-option 'vhdl-architecture-file-name) t]
3520 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3523 (customize-set-variable 'vhdl-file-name-case 'identity)
3524 :style radio :selected (eq 'identity vhdl-file-name-case)]
3526 (customize-set-variable 'vhdl-file-name-case 'downcase)
3527 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3529 (customize-set-variable 'vhdl-file-name-case 'upcase)
3530 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3532 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3533 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3535 ["Customize Group..." (customize-group 'vhdl-naming) t])
3537 ("Electric Keywords"
3539 (customize-set-variable 'vhdl-electric-keywords
3540 (if (memq 'vhdl vhdl-electric-keywords)
3541 (delq 'vhdl vhdl-electric-keywords)
3542 (cons 'vhdl vhdl-electric-keywords)))
3543 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3544 ["User Model Keywords"
3545 (customize-set-variable 'vhdl-electric-keywords
3546 (if (memq 'user vhdl-electric-keywords)
3547 (delq 'user vhdl-electric-keywords)
3548 (cons 'user vhdl-electric-keywords)))
3549 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3550 ("Insert Optional Labels"
3552 (customize-set-variable 'vhdl-optional-labels 'none)
3553 :style radio :selected (eq 'none vhdl-optional-labels)]
3555 (customize-set-variable 'vhdl-optional-labels 'process)
3556 :style radio :selected (eq 'process vhdl-optional-labels)]
3558 (customize-set-variable 'vhdl-optional-labels 'all)
3559 :style radio :selected (eq 'all vhdl-optional-labels)])
3560 ("Insert Empty Lines"
3562 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3563 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3564 ["Design Units Only"
3565 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3566 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3568 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3569 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3570 ["Argument List Indent"
3571 (customize-set-variable 'vhdl-argument-list-indent
3572 (not vhdl-argument-list-indent))
3573 :style toggle :selected vhdl-argument-list-indent]
3574 ["Association List with Formals"
3575 (customize-set-variable 'vhdl-association-list-with-formals
3576 (not vhdl-association-list-with-formals))
3577 :style toggle :selected vhdl-association-list-with-formals]
3578 ["Conditions in Parenthesis"
3579 (customize-set-variable 'vhdl-conditions-in-parenthesis
3580 (not vhdl-conditions-in-parenthesis))
3581 :style toggle :selected vhdl-conditions-in-parenthesis]
3582 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3583 ["One String..." (customize-option 'vhdl-one-string) t]
3585 ["Header String..." (customize-option 'vhdl-file-header) t]
3586 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3587 ["Company Name..." (customize-option 'vhdl-company-name) t]
3588 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3589 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3590 ["Date Format..." (customize-option 'vhdl-date-format) t]
3591 ["Modify Date Prefix String..."
3592 (customize-option 'vhdl-modify-date-prefix-string) t]
3593 ["Modify Date on Saving"
3594 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3595 (not vhdl-modify-date-on-saving))
3596 (vhdl-activate-customizations))
3597 :style toggle :selected vhdl-modify-date-on-saving])
3598 ("Sequential Process"
3601 (customize-set-variable 'vhdl-reset-kind 'none)
3602 :style radio :selected (eq 'none vhdl-reset-kind)]
3604 (customize-set-variable 'vhdl-reset-kind 'sync)
3605 :style radio :selected (eq 'sync vhdl-reset-kind)]
3607 (customize-set-variable 'vhdl-reset-kind 'async)
3608 :style radio :selected (eq 'async vhdl-reset-kind)])
3609 ["Reset is Active High"
3610 (customize-set-variable 'vhdl-reset-active-high
3611 (not vhdl-reset-active-high))
3612 :style toggle :selected vhdl-reset-active-high]
3613 ["Use Rising Clock Edge"
3614 (customize-set-variable 'vhdl-clock-rising-edge
3615 (not vhdl-clock-rising-edge))
3616 :style toggle :selected vhdl-clock-rising-edge]
3617 ("Clock Edge Condition"
3619 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3620 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3621 ["Function \"rising_edge\""
3622 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3623 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3624 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3625 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3627 ["Customize Group..." (customize-group 'vhdl-template) t])
3629 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3631 ["Include Port Comments"
3632 (customize-set-variable 'vhdl-include-port-comments
3633 (not vhdl-include-port-comments))
3634 :style toggle :selected vhdl-include-port-comments]
3635 ["Include Direction Comments"
3636 (customize-set-variable 'vhdl-include-direction-comments
3637 (not vhdl-include-direction-comments))
3638 :style toggle :selected vhdl-include-direction-comments]
3639 ["Include Type Comments"
3640 (customize-set-variable 'vhdl-include-type-comments
3641 (not vhdl-include-type-comments))
3642 :style toggle :selected vhdl-include-type-comments]
3643 ("Include Group Comments"
3645 (customize-set-variable 'vhdl-include-group-comments 'never)
3646 :style radio :selected (eq 'never vhdl-include-group-comments)]
3648 (customize-set-variable 'vhdl-include-group-comments 'decl)
3649 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3651 (customize-set-variable 'vhdl-include-group-comments 'always)
3652 :style radio :selected (eq 'always vhdl-include-group-comments)])
3653 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3654 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3656 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3657 ["Architecture Name..."
3658 (customize-option 'vhdl-testbench-architecture-name) t]
3659 ["Configuration Name..."
3660 (customize-option 'vhdl-testbench-configuration-name) t]
3661 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3663 (customize-set-variable 'vhdl-testbench-include-header
3664 (not vhdl-testbench-include-header))
3665 :style toggle :selected vhdl-testbench-include-header]
3666 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3667 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3668 ["Initialize Signals"
3669 (customize-set-variable 'vhdl-testbench-initialize-signals
3670 (not vhdl-testbench-initialize-signals))
3671 :style toggle :selected vhdl-testbench-initialize-signals]
3672 ["Include Library Clause"
3673 (customize-set-variable 'vhdl-testbench-include-library
3674 (not vhdl-testbench-include-library))
3675 :style toggle :selected vhdl-testbench-include-library]
3676 ["Include Configuration"
3677 (customize-set-variable 'vhdl-testbench-include-configuration
3678 (not vhdl-testbench-include-configuration))
3679 :style toggle :selected vhdl-testbench-include-configuration]
3682 (customize-set-variable 'vhdl-testbench-create-files 'none)
3683 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3685 (customize-set-variable 'vhdl-testbench-create-files 'single)
3686 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3688 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3689 :style radio :selected (eq 'separate vhdl-testbench-create-files)]))
3691 ["Customize Group..." (customize-group 'vhdl-port) t])
3695 (customize-set-variable 'vhdl-compose-create-files 'none)
3696 :style radio :selected (eq 'none vhdl-compose-create-files)]
3698 (customize-set-variable 'vhdl-compose-create-files 'single)
3699 :style radio :selected (eq 'single vhdl-compose-create-files)]
3701 (customize-set-variable 'vhdl-compose-create-files 'separate)
3702 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3704 (customize-set-variable 'vhdl-compose-include-header
3705 (not vhdl-compose-include-header))
3706 :style toggle :selected vhdl-compose-include-header]
3707 ["Architecture Name..."
3708 (customize-option 'vhdl-compose-architecture-name) t]
3709 ["Components Package Name..."
3710 (customize-option 'vhdl-components-package-name) t]
3711 ["Use Components Package"
3712 (customize-set-variable 'vhdl-use-components-package
3713 (not vhdl-use-components-package))
3714 :style toggle :selected vhdl-use-components-package]
3716 ["Customize Group..." (customize-group 'vhdl-compose) t])
3718 ["Self Insert Comments"
3719 (customize-set-variable 'vhdl-self-insert-comments
3720 (not vhdl-self-insert-comments))
3721 :style toggle :selected vhdl-self-insert-comments]
3722 ["Prompt for Comments"
3723 (customize-set-variable 'vhdl-prompt-for-comments
3724 (not vhdl-prompt-for-comments))
3725 :style toggle :selected vhdl-prompt-for-comments]
3726 ["Inline Comment Column..."
3727 (customize-option 'vhdl-inline-comment-column) t]
3728 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3730 ["Customize Group..." (customize-group 'vhdl-comment) t])
3732 ["Auto Align Templates"
3733 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3734 :style toggle :selected vhdl-auto-align]
3735 ["Align Line Groups"
3736 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3737 :style toggle :selected vhdl-align-groups]
3738 ["Group Separation String..."
3739 (customize-set-variable 'vhdl-align-group-separate) t]
3740 ["Align Lines with Same Indent"
3741 (customize-set-variable 'vhdl-align-same-indent
3742 (not vhdl-align-same-indent))
3743 :style toggle :selected vhdl-align-same-indent]
3745 ["Customize Group..." (customize-group 'vhdl-align) t])
3747 ["Highlighting On/Off..."
3749 (if vhdl-xemacs 'font-lock-auto-fontify 'global-font-lock-mode)) t]
3750 ["Highlight Keywords"
3751 (progn (customize-set-variable 'vhdl-highlight-keywords
3752 (not vhdl-highlight-keywords))
3753 (vhdl-fontify-buffer))
3754 :style toggle :selected vhdl-highlight-keywords]
3756 (progn (customize-set-variable 'vhdl-highlight-names
3757 (not vhdl-highlight-names))
3758 (vhdl-fontify-buffer))
3759 :style toggle :selected vhdl-highlight-names]
3760 ["Highlight Special Words"
3761 (progn (customize-set-variable 'vhdl-highlight-special-words
3762 (not vhdl-highlight-special-words))
3763 (vhdl-fontify-buffer))
3764 :style toggle :selected vhdl-highlight-special-words]
3765 ["Highlight Forbidden Words"
3766 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3767 (not vhdl-highlight-forbidden-words))
3768 (vhdl-fontify-buffer))
3769 :style toggle :selected vhdl-highlight-forbidden-words]
3770 ["Highlight Verilog Keywords"
3771 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3772 (not vhdl-highlight-verilog-keywords))
3773 (vhdl-fontify-buffer))
3774 :style toggle :selected vhdl-highlight-verilog-keywords]
3775 ["Highlight \"translate_off\""
3776 (progn (customize-set-variable 'vhdl-highlight-translate-off
3777 (not vhdl-highlight-translate-off))
3778 (vhdl-fontify-buffer))
3779 :style toggle :selected vhdl-highlight-translate-off]
3780 ["Case Sensitive Highlighting"
3781 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3782 (not vhdl-highlight-case-sensitive))
3783 (vhdl-fontify-buffer))
3784 :style toggle :selected vhdl-highlight-case-sensitive]
3785 ["Special Syntax Definition..."
3786 (customize-option 'vhdl-special-syntax-alist) t]
3787 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3788 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3789 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3790 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3792 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3794 ["Auto Open at Startup"
3795 (customize-set-variable 'vhdl-speedbar-auto-open
3796 (not vhdl-speedbar-auto-open))
3797 :style toggle :selected vhdl-speedbar-auto-open]
3798 ("Default Displaying Mode"
3800 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3801 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3802 ["Directory Hierarchy"
3803 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3804 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3805 ["Project Hierarchy"
3806 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3807 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3808 ["Indentation Offset..."
3809 (customize-option 'speedbar-indentation-width) t]
3810 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3811 ["Jump to Unit when Opening"
3812 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3813 (not vhdl-speedbar-jump-to-unit))
3814 :style toggle :selected vhdl-speedbar-jump-to-unit]
3815 ["Update Hierarchy on File Saving"
3816 (customize-set-variable 'vhdl-speedbar-update-on-saving
3817 (not vhdl-speedbar-update-on-saving))
3818 :style toggle :selected vhdl-speedbar-update-on-saving]
3819 ("Save in Cache File"
3820 ["Hierarchy Information"
3821 (customize-set-variable 'vhdl-speedbar-save-cache
3822 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3823 (delq 'hierarchy vhdl-speedbar-save-cache)
3824 (cons 'hierarchy vhdl-speedbar-save-cache)))
3825 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3826 ["Displaying Status"
3827 (customize-set-variable 'vhdl-speedbar-save-cache
3828 (if (memq 'display vhdl-speedbar-save-cache)
3829 (delq 'display vhdl-speedbar-save-cache)
3830 (cons 'display vhdl-speedbar-save-cache)))
3831 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3832 ["Cache File Name..."
3833 (customize-option 'vhdl-speedbar-cache-file-name) t]
3835 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3837 ["Add Index Menu when Loading File"
3838 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3839 (vhdl-index-menu-init))
3840 :style toggle :selected vhdl-index-menu]
3841 ["Add Source File Menu when Loading File"
3842 (progn (customize-set-variable 'vhdl-source-file-menu
3843 (not vhdl-source-file-menu))
3844 (vhdl-add-source-files-menu))
3845 :style toggle :selected vhdl-source-file-menu]
3846 ["Add Hideshow Menu at Startup"
3847 (progn (customize-set-variable 'vhdl-hideshow-menu
3848 (not vhdl-hideshow-menu))
3849 (vhdl-activate-customizations))
3850 :style toggle :selected vhdl-hideshow-menu]
3851 ["Hide Everything Initially"
3852 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3853 :style toggle :selected vhdl-hide-all-init]
3855 ["Customize Group..." (customize-group 'vhdl-menu) t])
3857 ["In Two Column Format"
3858 (progn (customize-set-variable 'vhdl-print-two-column
3859 (not vhdl-print-two-column))
3860 (message "Activate new setting by saving options and restarting Emacs"))
3861 :style toggle :selected vhdl-print-two-column]
3862 ["Use Customized Faces"
3863 (progn (customize-set-variable 'vhdl-print-customize-faces
3864 (not vhdl-print-customize-faces))
3865 (message "Activate new setting by saving options and restarting Emacs"))
3866 :style toggle :selected vhdl-print-customize-faces]
3868 ["Customize Group..." (customize-group 'vhdl-print) t])
3870 ["Use Intelligent Tab"
3871 (progn (customize-set-variable 'vhdl-intelligent-tab
3872 (not vhdl-intelligent-tab))
3873 (vhdl-activate-customizations))
3874 :style toggle :selected vhdl-intelligent-tab]
3875 ["Indent Syntax-Based"
3876 (customize-set-variable 'vhdl-indent-syntax-based
3877 (not vhdl-indent-syntax-based))
3878 :style toggle :selected vhdl-indent-syntax-based]
3879 ["Word Completion is Case Sensitive"
3880 (customize-set-variable 'vhdl-word-completion-case-sensitive
3881 (not vhdl-word-completion-case-sensitive))
3882 :style toggle :selected vhdl-word-completion-case-sensitive]
3883 ["Word Completion in Minibuffer"
3884 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3885 (not vhdl-word-completion-in-minibuffer))
3886 (message "Activate new setting by saving options and restarting Emacs"))
3887 :style toggle :selected vhdl-word-completion-in-minibuffer]
3888 ["Underscore is Part of Word"
3889 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3890 (not vhdl-underscore-is-part-of-word))
3891 (vhdl-activate-customizations))
3892 :style toggle :selected vhdl-underscore-is-part-of-word]
3894 ["Customize Group..." (customize-group 'vhdl-misc) t])
3895 ["Related..." (customize-browse 'vhdl-related) t]
3897 ["Save Options" customize-save-customized t]
3898 ["Activate Options" vhdl-activate-customizations t]
3899 ["Browse Options..." vhdl-customize t])))
3901 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3904 (defun vhdl-update-mode-menu ()
3905 "Update VHDL Mode menu."
3907 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
3908 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
3909 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
3910 (easy-menu-define vhdl-mode-menu vhdl-mode-map
3911 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
3913 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3914 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
3916 (defconst vhdl-imenu-generic-expression
3919 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
3922 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
3925 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3928 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
3931 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
3934 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
3937 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3940 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3943 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3946 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3949 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
3951 (defun vhdl-index-menu-init ()
3952 "Initialize index menu."
3953 (set (make-local-variable 'imenu-case-fold-search) t)
3954 (set (make-local-variable 'imenu-generic-expression)
3955 vhdl-imenu-generic-expression)
3956 (when (and vhdl-index-menu (fboundp 'imenu))
3957 (if (or (not (boundp 'font-lock-maximum-size))
3958 (> font-lock-maximum-size (buffer-size)))
3959 (imenu-add-to-menubar "Index")
3960 (message "Scanning buffer for index...buffer too big"))))
3962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3963 ;; Source file menu (using `easy-menu.el')
3965 (defvar vhdl-sources-menu nil)
3967 (defun vhdl-directory-files (directory &optional full match)
3968 "Call `directory-files' if DIRECTORY exists, otherwise generate error
3970 (if (not (file-directory-p directory))
3971 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
3972 (let ((dir (directory-files directory full match)))
3973 (setq dir (delete "." dir))
3974 (setq dir (delete ".." dir))
3977 (defun vhdl-get-source-files (&optional full directory)
3978 "Get list of VHDL source files in DIRECTORY or current directory."
3979 (let ((mode-alist auto-mode-alist)
3981 ;; create regular expressions for matching file names
3982 (setq filename-regexp "\\`[^.].*\\(")
3984 (when (eq (cdar mode-alist) 'vhdl-mode)
3985 (setq filename-regexp
3986 (concat filename-regexp (caar mode-alist) "\\|")))
3987 (setq mode-alist (cdr mode-alist)))
3988 (setq filename-regexp
3989 (concat (substring filename-regexp 0
3990 (string-match "\\\\|$" filename-regexp)) "\\)"))
3992 (vhdl-directory-files
3993 (or directory default-directory) full filename-regexp)))
3995 (defun vhdl-add-source-files-menu ()
3996 "Scan directory for all VHDL source files and generate menu.
3997 The directory of the current source file is scanned."
3999 (message "Scanning directory for source files ...")
4000 (let ((newmap (current-local-map))
4001 (file-list (vhdl-get-source-files))
4003 ;; Create list for menu
4007 (setq menu-list (cons (vector (car file-list)
4008 (list 'find-file (car file-list)) t)
4010 (setq file-list (cdr file-list)))
4011 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4012 (when found (setq menu-list (cons "--" menu-list)))
4013 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4014 (setq menu-list (cons "Sources" menu-list))
4016 (easy-menu-add menu-list)
4017 (easy-menu-define vhdl-sources-menu newmap
4018 "VHDL source files menu" menu-list))
4022 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4024 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4025 ;; performs all buffer local initializations
4029 "Major mode for editing VHDL code.
4034 TEMPLATE INSERTION (electrification):
4035 After typing a VHDL keyword and entering `SPC', you are prompted for
4036 arguments while a template is generated for that VHDL construct. Typing
4037 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4038 template generation. Optional arguments are indicated by square
4039 brackets and removed if the queried string is left empty. Prompts for
4040 mandatory arguments remain in the code if the queried string is left
4041 empty. They can be queried again by `C-c C-t C-q'. Enabled
4042 electrification is indicated by `/e' in the modeline.
4044 Typing `M-SPC' after a keyword inserts a space without calling the
4045 template generator. Automatic template generation (i.e.
4046 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4047 setting option `vhdl-electric-mode' (see OPTIONS).
4049 Template generators can be invoked from the VHDL menu, by key
4050 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4051 the keyword (i.e. first word of menu entry not in parenthesis) and
4052 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4053 conf, comp, cons, func, inst, pack, sig, var.
4055 Template styles can be customized in customization group
4056 `vhdl-template' \(see OPTIONS).
4060 A file header can be inserted by `C-c C-t C-h'. A file footer
4061 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4062 See customization group `vhdl-header'.
4066 Double striking of some keys inserts cumbersome VHDL syntax elements.
4067 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4068 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4069 the modeline. The stuttering keys and their effects are:
4071 ;; --> \" : \" [ --> ( -- --> comment
4072 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4073 .. --> \" => \" ] --> ) --- --> horizontal line
4074 ,, --> \" <= \" ]] --> ] ---- --> display comment
4075 == --> \" == \" '' --> \\\"
4079 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4080 word in the buffer that starts alike, inserts it and adjusts case.
4081 Re-typing `TAB' toggles through alternative word completions. This also
4082 works in the minibuffer (i.e. in template generator prompts).
4084 Typing `TAB' after `(' looks for and inserts complete parenthesized
4085 expressions (e.g. for array index ranges). All keywords as well as
4086 standard types and subprograms of VHDL have predefined abbreviations
4087 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4088 beginning with \"std\").
4090 Typing `TAB' after a non-word character indents the line if at the
4091 beginning of a line (i.e. no preceding non-blank characters), and
4092 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4097 `--' puts a single comment.
4098 `---' draws a horizontal line for separating code segments.
4099 `----' inserts a display comment, i.e. two horizontal lines
4100 with a comment in between.
4101 `--CR' comments out code on that line. Re-hitting CR comments
4102 out following lines.
4103 `C-c c' comments out a region if not commented out,
4104 uncomments a region if already commented out.
4106 You are prompted for comments after object definitions (i.e. signals,
4107 variables, constants, ports) and after subprogram and process
4108 specifications if option `vhdl-prompt-for-comments' is non-nil.
4109 Comments are automatically inserted as additional labels (e.g. after
4110 begin statements) and as help comments if `vhdl-self-insert-comments' is
4113 Inline comments (i.e. comments after a piece of code on the same line)
4114 are indented at least to `vhdl-inline-comment-column'. Comments go at
4115 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4116 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4117 in a comment automatically opens a new comment line. `M-q' re-fills
4118 multi-line comments.
4122 `TAB' indents a line if at the beginning of the line. The amount of
4123 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4124 always indents the current line (is bound to `TAB' if option
4125 `vhdl-intelligent-tab' is nil).
4127 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4128 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4129 indented normally (nil) or relative to the opening parenthesis (non-nil)
4130 according to option `vhdl-argument-list-indent'.
4132 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4133 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4136 Syntax-based indentation can be very slow in large files. Option
4137 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4141 The alignment functions align operators, keywords, and inline comments
4142 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4143 separated by blank lines, `C-c C-a C-i' a block of lines with same
4144 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4145 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4146 C-a C-d' all lines within the declarative part of a design unit. `C-c
4147 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4148 for a group of lines, and `C-c C-a M-c' for a region.
4150 If option `vhdl-align-groups' is non-nil, groups of code lines
4151 separated by special lines (see option `vhdl-align-group-separate') are
4152 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4153 blocks of lines with same indent are aligned separately. Some templates
4154 are automatically aligned after generation if option `vhdl-auto-align'
4157 Alignment tries to align inline comments at
4158 `vhdl-inline-comment-column' and tries inline comment not to exceed
4159 `vhdl-end-comment-column'.
4161 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4162 symbols are surrounded by one space, and multiple spaces are eliminated.
4166 | Code filling allows to condens code (e.g. sensitivity lists or port
4167 | maps) by removing comments and newlines and re-wrapping so that all
4168 | lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4169 | enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4170 | blank lines, `C-c C-f C-i' a block of lines with same indent, and
4171 | `C-c C-f M-f' an entire region.
4174 CODE BEAUTIFICATION:
4175 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4176 buffer respectively. This inludes indentation, alignment, and case
4177 fixing. Code beautification can also be run non-interactively using the
4180 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4184 Generic and port clauses from entity or component declarations can be
4185 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4186 as component instantiations and corresponding internal constants and
4187 signals, as a generic map with constants as actual generics, and as
4188 internal signal initializations (menu).
4190 To include formals in component instantiations, see option
4191 `vhdl-association-list-with-formals'. To include comments in pasting,
4192 see options `vhdl-include-...-comments'.
4194 A clause with several generic/port names on the same line can be
4195 flattened (`C-c C-p C-f') so that only one name per line exists. The
4196 | direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4197 | outputs and vice versa, which can be useful in testbenches. (This
4198 | reversion is done on the internal data structure and is only reflected
4199 | in subsequent paste operations.)
4201 Names for actual ports, instances, testbenches, and
4202 design-under-test instances can be derived from existing names according
4203 to options `vhdl-...-name'. See customization group `vhdl-port'.
4206 | SUBPROGRAM TRANSLATION:
4207 | Similar functionality exists for copying/pasting the interface of
4208 | subprograms (function/procedure). A subprogram interface can be copied
4209 | and then pasted as a subprogram declaration, body or call (uses
4210 | association list with formals).
4213 TESTBENCH GENERATION:
4214 A copied port can also be pasted as a testbench. The generated
4215 testbench includes an entity, an architecture, and an optional
4216 configuration. The architecture contains the component declaration and
4217 instantiation of the DUT as well as internal constant and signal
4218 declarations. Additional user-defined templates can be inserted. The
4219 names used for entity/architecture/configuration/DUT as well as the file
4220 structure to be generated can be customized. See customization group
4225 Key bindings (`C-c ...') exist for most commands (see in menu).
4229 All commands can be found in the VHDL menu including their key bindings.
4233 The speedbar allows browsing of directories and file contents. It can
4234 be accessed from the VHDL menu and is automatically opened if option
4235 `vhdl-speedbar-auto-open' is non-nil.
4237 In speedbar, open files and directories with `mouse-2' on the name and
4238 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4241 DESIGN HIERARCHY BROWSER:
4242 The speedbar can also be used for browsing the hierarchy of design units
4243 contained in the source files of the current directory or the specified
4244 projects (see option `vhdl-project-alist').
4246 The speedbar can be switched between file, directory hierarchy and
4247 project hierarchy browsing mode in the speedbar menu or by typing `f',
4248 `h' or `H' in speedbar.
4250 In speedbar, open design units with `mouse-2' on the name and browse
4251 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4252 from entities and components (in packages). Individual design units and
4253 complete designs can directly be compiled (\"Make\" menu entry).
4255 The hierarchy is automatically updated upon saving a modified source
4256 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4257 hierarchy is only updated for projects that have been opened once in the
4258 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4259 options in group `vhdl-speedbar').
4261 Simple design consistency checks are done during scanning, such as
4262 multiple declarations of the same unit or missing primary units that are
4263 required by secondary units.
4266 | STRUCTURAL COMPOSITION:
4267 | Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4268 | for a new component. Subcomponents (i.e. component declaration and
4269 | instantiation) can be automatically placed from a previously read port
4270 | \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4271 | all subcomponents can be automatically connected using internal signals
4272 | and ports (`C-c C-c C-w') following these rules:
4273 | - subcomponent actual ports with same name are considered to be
4274 | connected by a signal (internal signal or port)
4275 | - signals that are only inputs to subcomponents are considered as
4276 | inputs to this component -> input port created
4277 | - signals that are only outputs from subcomponents are considered as
4278 | outputs from this component -> output port created
4279 | - signals that are inputs to AND outputs from subcomponents are
4280 | considered as internal connections -> internal signal created
4282 | Component declarations can be placed in a components package (option
4283 | `vhdl-use-components-package') which can be automatically generated for
4284 | an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4285 | component instantiation is also supported (option
4286 | `vhdl-use-direct-instantiation').
4288 | Purpose: With appropriate naming conventions it is possible to
4289 | create higher design levels with only a few mouse clicks or key
4290 | strokes. A new design level can be created by simply generating a new
4291 | component, placing the required subcomponents from the hierarchy
4292 | browser, and wiring everything automatically.
4294 | Note: Automatic wiring only works reliably on templates of new
4295 | components and component instantiations that were created by VHDL mode.
4297 | See the options group `vhdl-compose' for all relevant user options.
4300 SOURCE FILE COMPILATION:
4301 The syntax of the current buffer can be analyzed by calling a VHDL
4302 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4303 option `vhdl-compiler'. The available compilers are listed in option
4304 `vhdl-compiler-alist' including all required compilation command,
4305 command options, compilation directory, and error message syntax
4306 information. New compilers can be added.
4308 All the source files of an entire design can be compiled by the `make'
4309 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4312 MAKEFILE GENERATION:
4313 Makefiles can be generated automatically by an internal generation
4314 routine (`C-c M-k'). The library unit dependency information is
4315 obtained from the hierarchy browser. Makefile generation can be
4316 customized for each compiler in option `vhdl-compiler-alist'.
4318 Makefile generation can also be run non-interactively using the
4321 emacs -batch -l ~/.emacs -l vhdl-mode
4322 [-compiler compilername] [-project projectname]
4323 -f vhdl-generate-makefile
4325 The Makefile's default target \"all\" compiles the entire design, the
4326 target \"clean\" removes it and the target \"library\" creates the
4327 library directory if not existent. The Makefile also includes a target
4328 for each primary library unit which allows selective compilation of this
4329 unit, its secondary units and its subhierarchy (example: compilation of
4330 a design specified by a configuration). User specific parts can be
4331 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4334 - Only library units and dependencies within the current library are
4335 considered. Makefiles for designs that span multiple libraries are
4336 not (yet) supported.
4337 - Only one-level configurations are supported (also hierarchical),
4338 but configurations that go down several levels are not.
4339 - The \"others\" keyword in configurations is not supported.
4343 Projects can be defined in option `vhdl-project-alist' and a current
4344 project be selected using option `vhdl-project' (permanently) or from
4345 the menu or speedbar (temporarily). For each project, title and
4346 description strings (for the file headers), source files/directories
4347 (for the hierarchy browser and Makefile generation), library name, and
4348 compiler-dependent options, exceptions and compilation directory can be
4349 specified. Compilation settings overwrite the settings of option
4350 `vhdl-compiler-alist'.
4352 Project setups can be exported (i.e. written to a file) and imported.
4353 Imported setups are not automatically saved in `vhdl-project-alist' but
4354 can be saved afterwards in its customization buffer. When starting
4355 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4356 vhdl-mode\") in a directory with an existing project setup file, it is
4357 automatically loaded and its project activated if option
4358 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4359 files can be specified in option `vhdl-project-file-name'. Multiple
4360 project setups can be automatically loaded from global directories.
4361 This is an alternative to specifying project setups with option
4362 `vhdl-project-alist'.
4366 As an alternative to the speedbar, an index menu can be added (set
4367 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4368 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4369 file) for browsing the file contents (is not populated if buffer is
4370 larger than `font-lock-maximum-size'). Also, a source file menu can be
4371 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4372 current directory for VHDL source files.
4376 The VHDL standards to be used are specified in option `vhdl-standard'.
4377 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4381 Lower and upper case for keywords and standardized types, attributes,
4382 and enumeration values is supported. If the option
4383 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4384 lower case and are converted into upper case automatically (not for
4385 types, attributes, and enumeration values). The case of keywords,
4386 types, attributes,and enumeration values can be fixed for an entire
4387 region (menu) or buffer (`C-c C-x C-c') according to the options
4388 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4391 HIGHLIGHTING (fontification):
4392 Keywords and standardized types, attributes, enumeration values, and
4393 function names (controlled by option `vhdl-highlight-keywords'), as well
4394 as comments, strings, and template prompts are highlighted using
4395 different colors. Unit, subprogram, signal, variable, constant,
4396 parameter and generic/port names in declarations as well as labels are
4397 highlighted if option `vhdl-highlight-names' is non-nil.
4399 Additional reserved words or words with a forbidden syntax (e.g. words
4400 that should be avoided) can be specified in option
4401 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4402 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4403 keywords are highlighted as forbidden words if option
4404 `vhdl-highlight-verilog-keywords' is non-nil.
4406 Words with special syntax can be highlighted by specifying their
4407 syntax and color in option `vhdl-special-syntax-alist' and by setting
4408 option `vhdl-highlight-special-words' to non-nil. This allows to
4409 establish some naming conventions (e.g. to distinguish different kinds
4410 of signals or other objects by using name suffices) and to support them
4413 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4414 to support case-sensitive highlighting. However, keywords are then only
4415 highlighted if written in lower case.
4417 Code between \"translate_off\" and \"translate_on\" pragmas is
4418 highlighted using a different background color if option
4419 `vhdl-highlight-translate-off' is non-nil.
4421 For documentation and customization of the used colors see
4422 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4423 highlighting of matching parenthesis, see customization group
4424 `paren-showing'. Automatic buffer highlighting is turned on/off by
4425 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4429 VHDL models (templates) can be specified by the user and made accessible
4430 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4431 electrification. See option `vhdl-model-alist'.
4435 The code of blocks, processes, subprograms, component declarations and
4436 instantiations, generic/port clauses, and configuration declarations can
4437 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4438 the code (see customization group `vhdl-menu'). XEmacs: limited
4439 functionality due to old `hideshow.el' package.
4443 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4444 current process, `C-c C-u M-s' of all processes in the current buffer.
4446 - Only declared local signals (ports, signals declared in
4447 architecture and blocks) are automatically inserted.
4448 - Global signals declared in packages are not automatically inserted.
4449 Insert them once manually (will be kept afterwards).
4450 - Out parameters of procedures are considered to be read.
4451 Use option `vhdl-entity-file-name' to specify the entity file name
4452 \(used to obtain the port names).
4456 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4457 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4461 Postscript printing with different faces (an optimized set of faces is
4462 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4463 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4464 postscript printing commands. Option `vhdl-print-two-column' defines
4465 appropriate default settings for nice landscape two-column printing.
4466 The paper format can be set by option `ps-paper-type'. Do not forget to
4467 switch `ps-print-color-p' to nil for printing on black-and-white
4472 User options allow customization of VHDL Mode. All options are
4473 accessible from the \"Options\" menu entry. Simple options (switches
4474 and choices) can directly be changed, while for complex options a
4475 customization buffer is opened. Changed options can be saved for future
4476 sessions using the \"Save Options\" menu entry.
4478 Options and their detailed descriptions can also be accessed by using
4479 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4480 customize-group' for groups). Some customizations only take effect
4481 after some action (read the NOTE in the option documentation).
4482 Customization can also be done globally (i.e. site-wide, read the
4485 Not all options are described in this documentation, so go and see
4486 what other useful user options there are (`M-x vhdl-customize' or menu)!
4490 As default, files with extensions \".vhd\" and \".vhdl\" are
4491 automatically recognized as VHDL source files. To add an extension
4492 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4494 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4498 - To start Emacs with open VHDL hierarchy browser without having to load
4499 a VHDL file first, use the command:
4501 emacs -l vhdl-mode -f speedbar-frame-mode
4503 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4505 - Some features only work on properly indented code.
4509 See also the release notes (menu) for added features in new releases.
4515 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4516 Add a description of the problem and include a reproducible test case.
4518 Questions and enhancement requests can be sent to <reto@gnu.org>.
4520 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4521 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4522 releases. You are kindly invited to participate in beta testing. Subscribe
4523 to above mailing lists by sending an email to <reto@gnu.org>.
4525 VHDL Mode is officially distributed at
4526 http://opensource.ethz.ch/emacs/vhdl-mode.html
4527 where the latest version can be found.
4533 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4534 - XEmacs: Incorrect start-up when automatically opening speedbar.
4535 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4538 The VHDL Mode Authors
4539 Reto Zimmermann and Rod Whitby
4546 (kill-all-local-variables)
4547 (setq major-mode 'vhdl-mode)
4548 (setq mode-name "VHDL")
4550 ;; set maps and tables
4551 (use-local-map vhdl-mode-map)
4552 (set-syntax-table vhdl-mode-syntax-table)
4553 (setq local-abbrev-table vhdl-mode-abbrev-table)
4555 ;; set local variables
4556 (set (make-local-variable 'paragraph-start)
4557 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4558 (set (make-local-variable 'paragraph-separate) paragraph-start)
4559 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4560 (set (make-local-variable 'require-final-newline) t)
4561 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4562 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4563 (set (make-local-variable 'comment-start) "--")
4564 (set (make-local-variable 'comment-end) "")
4566 (set (make-local-variable 'comment-padding) ""))
4567 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4568 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4569 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4570 (set (make-local-variable 'comment-multi-line) nil)
4571 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4572 (set (make-local-variable 'hippie-expand-verbose) nil)
4574 ;; setup the comment indent variable in a Emacs version portable way
4575 ;; ignore any byte compiler warnings you might get here
4576 (when (boundp 'comment-indent-function)
4577 (make-local-variable 'comment-indent-function)
4578 (setq comment-indent-function 'vhdl-comment-indent))
4580 ;; initialize font locking
4581 (set (make-local-variable 'font-lock-defaults)
4583 '(nil vhdl-font-lock-keywords) nil
4584 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4585 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4586 (unless vhdl-emacs-21
4587 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4588 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4589 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4590 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4591 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4592 ; (turn-on-font-lock)
4594 ;; variables for source file compilation
4595 (when vhdl-compile-use-local-error-regexp
4596 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4597 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4600 (vhdl-index-menu-init)
4601 ;; add source file menu
4602 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4604 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4605 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4606 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4607 ;; initialize hideshow and add menu
4608 (vhdl-hideshow-init)
4609 (run-hooks 'menu-bar-update-hook)
4612 (vhdl-ps-print-init)
4613 (vhdl-write-file-hooks-init)
4614 (vhdl-mode-line-update)
4615 (message "VHDL Mode %s.%s" vhdl-version
4616 (if noninteractive "" " See menu for documentation and release notes."))
4619 (run-hooks 'vhdl-mode-hook))
4621 (defun vhdl-activate-customizations ()
4622 "Activate all customizations on local variables."
4624 (vhdl-mode-map-init)
4625 (use-local-map vhdl-mode-map)
4626 (set-syntax-table vhdl-mode-syntax-table)
4627 (setq comment-column vhdl-inline-comment-column)
4628 (setq end-comment-column vhdl-end-comment-column)
4629 (vhdl-write-file-hooks-init)
4630 (vhdl-update-mode-menu)
4631 (vhdl-hideshow-init)
4632 (run-hooks 'menu-bar-update-hook)
4633 (vhdl-mode-line-update))
4635 (defun vhdl-write-file-hooks-init ()
4636 "Add/remove hooks when buffer is saved."
4637 (if vhdl-modify-date-on-saving
4638 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4639 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4640 (make-local-variable 'after-save-hook)
4641 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4643 (defun vhdl-process-command-line-option (option)
4644 "Process command line options for VHDL Mode."
4647 ((equal option "-compiler")
4648 (vhdl-set-compiler (car command-line-args-left))
4649 (setq command-line-args-left (cdr command-line-args-left)))
4651 ((equal option "-project")
4652 (vhdl-set-project (car command-line-args-left))
4653 (setq command-line-args-left (cdr command-line-args-left)))))
4655 ;; make Emacs process VHDL Mode options
4656 (setq command-switch-alist
4657 (append command-switch-alist
4658 '(("-compiler" . vhdl-process-command-line-option)
4659 ("-project" . vhdl-process-command-line-option))))
4662 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4663 ;;; Keywords and standardized words
4664 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4666 (defconst vhdl-93-keywords
4668 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4669 "assert" "attribute"
4670 "begin" "block" "body" "buffer" "bus"
4671 "case" "component" "configuration" "constant"
4672 "disconnect" "downto"
4673 "else" "elsif" "end" "entity" "exit"
4674 "file" "for" "function"
4675 "generate" "generic" "group" "guarded"
4676 "if" "impure" "in" "inertial" "inout" "is"
4677 "label" "library" "linkage" "literal" "loop"
4679 "nand" "new" "next" "nor" "not" "null"
4680 "of" "on" "open" "or" "others" "out"
4681 "package" "port" "postponed" "procedure" "process" "pure"
4682 "range" "record" "register" "reject" "rem" "report" "return"
4684 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4685 "then" "to" "transport" "type"
4686 "unaffected" "units" "until" "use"
4688 "wait" "when" "while" "with"
4691 "List of VHDL'93 keywords.")
4693 (defconst vhdl-ams-keywords
4695 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4696 "reference" "spectrum" "subnature" "terminal" "through"
4699 "List of VHDL-AMS keywords.")
4701 (defconst vhdl-verilog-keywords
4703 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4704 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4705 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4706 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4707 "endprimitive" "endspecify" "endtable" "endtask" "event"
4708 "for" "force" "forever" "fork" "function"
4709 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4710 "macromodule" "makefile" "medium" "module"
4711 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4712 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4714 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4715 "rtranif0" "rtranif1"
4716 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4717 "strong1" "supply" "supply0" "supply1"
4718 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4719 "triand" "trior" "trireg"
4720 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4722 "List of Verilog keywords as candidate for additional reserved words.")
4724 (defconst vhdl-93-types
4726 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4727 "real" "time" "natural" "positive" "string" "line" "text" "side"
4728 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4729 "std_logic" "std_logic_vector"
4730 "std_ulogic" "std_ulogic_vector"
4732 "List of VHDL'93 standardized types.")
4734 (defconst vhdl-ams-types
4736 "domain_type" "real_vector"
4737 ;; from `nature_pkg' package
4738 "voltage" "current" "electrical" "position" "velocity" "force"
4739 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4740 "pressure" "flowrate" "fluid"
4742 "List of VHDL-AMS standardized types.")
4744 (defconst vhdl-math-types
4746 "complex" "complex_polar"
4748 "List of Math Packages standardized types.")
4750 (defconst vhdl-93-attributes
4752 "base" "left" "right" "high" "low" "pos" "val" "succ"
4753 "pred" "leftof" "rightof" "range" "reverse_range"
4754 "length" "delayed" "stable" "quiet" "transaction"
4755 "event" "active" "last_event" "last_active" "last_value"
4756 "driving" "driving_value" "ascending" "value" "image"
4757 "simple_name" "instance_name" "path_name"
4760 "List of VHDL'93 standardized attributes.")
4762 (defconst vhdl-ams-attributes
4765 "reference" "contribution" "tolerance"
4766 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4769 "List of VHDL-AMS standardized attributes.")
4771 (defconst vhdl-93-enum-values
4774 "note" "warning" "error" "failure"
4775 "read_mode" "write_mode" "append_mode"
4776 "open_ok" "status_error" "name_error" "mode_error"
4777 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4780 "List of VHDL'93 standardized enumeration values.")
4782 (defconst vhdl-ams-enum-values
4784 "quiescent_domain" "time_domain" "frequency_domain"
4785 ;; from `nature_pkg' package
4786 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4788 "List of VHDL-AMS standardized enumeration values.")
4790 (defconst vhdl-math-constants
4792 "math_e" "math_1_over_e"
4793 "math_pi" "math_two_pi" "math_1_over_pi"
4794 "math_half_pi" "math_q_pi" "math_3_half_pi"
4795 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4796 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4797 "math_deg_to_rad" "math_rad_to_deg"
4798 "cbase_1" "cbase_j" "czero"
4800 "List of Math Packages standardized constants.")
4802 (defconst vhdl-93-functions
4804 "now" "resolved" "rising_edge" "falling_edge"
4805 "read" "readline" "write" "writeline" "endfile"
4806 "resize" "is_X" "std_match"
4807 "shift_left" "shift_right" "rotate_left" "rotate_right"
4808 "to_unsigned" "to_signed" "to_integer"
4809 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4810 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4811 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4812 "shl" "shr" "ext" "sxt"
4815 "List of VHDL'93 standardized functions.")
4817 (defconst vhdl-ams-functions
4821 "List of VHDL-AMS standardized functions.")
4823 (defconst vhdl-math-functions
4825 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4826 "sqrt" "cbrt" "exp" "log"
4827 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4828 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4829 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4831 "List of Math Packages standardized functions.")
4833 (defconst vhdl-93-packages
4835 "std_logic_1164" "numeric_std" "numeric_bit"
4837 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4838 "std_logic_misc" "std_logic_textio"
4841 "List of VHDL'93 standardized packages and libraries.")
4843 (defconst vhdl-ams-packages
4845 ;; from `nature_pkg' package
4848 "List of VHDL-AMS standardized packages and libraries.")
4850 (defconst vhdl-math-packages
4852 "math_real" "math_complex"
4854 "List of Math Packages standardized packages and libraries.")
4856 (defvar vhdl-keywords nil
4857 "List of VHDL keywords.")
4859 (defvar vhdl-types nil
4860 "List of VHDL standardized types.")
4862 (defvar vhdl-attributes nil
4863 "List of VHDL standardized attributes.")
4865 (defvar vhdl-enum-values nil
4866 "List of VHDL standardized enumeration values.")
4868 (defvar vhdl-constants nil
4869 "List of VHDL standardized constants.")
4871 (defvar vhdl-functions nil
4872 "List of VHDL standardized functions.")
4874 (defvar vhdl-packages nil
4875 "List of VHDL standardized packages and libraries.")
4877 (defvar vhdl-reserved-words nil
4878 "List of additional reserved words.")
4880 (defvar vhdl-keywords-regexp nil
4881 "Regexp for VHDL keywords.")
4883 (defvar vhdl-types-regexp nil
4884 "Regexp for VHDL standardized types.")
4886 (defvar vhdl-attributes-regexp nil
4887 "Regexp for VHDL standardized attributes.")
4889 (defvar vhdl-enum-values-regexp nil
4890 "Regexp for VHDL standardized enumeration values.")
4892 (defvar vhdl-functions-regexp nil
4893 "Regexp for VHDL standardized functions.")
4895 (defvar vhdl-packages-regexp nil
4896 "Regexp for VHDL standardized packages and libraries.")
4898 (defvar vhdl-reserved-words-regexp nil
4899 "Regexp for additional reserved words.")
4901 (defvar vhdl-directive-keywords-regexp nil
4902 "Regexp for compiler directive keywords.")
4904 (defun vhdl-words-init ()
4905 "Initialize reserved words."
4907 (append vhdl-93-keywords
4908 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
4910 (append vhdl-93-types
4911 (when (vhdl-standard-p 'ams) vhdl-ams-types)
4912 (when (vhdl-standard-p 'math) vhdl-math-types)))
4913 (setq vhdl-attributes
4914 (append vhdl-93-attributes
4915 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
4916 (setq vhdl-enum-values
4917 (append vhdl-93-enum-values
4918 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
4919 (setq vhdl-constants
4920 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
4921 (setq vhdl-functions
4922 (append vhdl-93-functions
4923 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
4924 (when (vhdl-standard-p 'math) vhdl-math-functions)))
4926 (append vhdl-93-packages
4927 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
4928 (when (vhdl-standard-p 'math) vhdl-math-packages)))
4929 (setq vhdl-reserved-words
4930 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
4931 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
4933 (setq vhdl-keywords-regexp
4934 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
4935 (setq vhdl-types-regexp
4936 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
4937 (setq vhdl-attributes-regexp
4938 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
4939 (setq vhdl-enum-values-regexp
4940 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
4941 (setq vhdl-functions-regexp
4942 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
4943 (setq vhdl-packages-regexp
4944 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
4945 (setq vhdl-reserved-words-regexp
4947 (unless (equal vhdl-forbidden-syntax "")
4948 (concat vhdl-forbidden-syntax "\\|"))
4949 (regexp-opt vhdl-reserved-words)
4951 (setq vhdl-directive-keywords-regexp
4952 (concat "\\<\\(" (mapconcat 'regexp-quote
4953 vhdl-directive-keywords "\\|") "\\)\\>"))
4954 (vhdl-abbrev-list-init))
4956 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4959 (defvar vhdl-abbrev-list nil
4960 "Predefined abbreviations for VHDL.")
4962 (defun vhdl-abbrev-list-init ()
4963 (setq vhdl-abbrev-list
4965 (list vhdl-upper-case-keywords) vhdl-keywords
4966 (list vhdl-upper-case-types) vhdl-types
4967 (list vhdl-upper-case-attributes) vhdl-attributes
4968 (list vhdl-upper-case-enum-values) vhdl-enum-values
4969 (list vhdl-upper-case-constants) vhdl-constants
4970 (list nil) vhdl-functions
4971 (list nil) vhdl-packages)))
4973 ;; initialize reserved words for VHDL Mode
4977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4979 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4981 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4984 ;; constant regular expressions for looking at various constructs
4986 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
4987 "Regexp describing a VHDL symbol.
4988 We cannot use just `word' syntax class since `_' cannot be in word
4989 class. Putting underscore in word class breaks forward word movement
4990 behavior that users are familiar with.")
4992 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
4993 "Regexp describing a case statement header key.")
4995 (defconst vhdl-label-key
4996 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
4997 "Regexp describing a VHDL label.")
4999 ;; Macro definitions:
5001 (defmacro vhdl-point (position)
5002 "Return the value of point at certain commonly referenced POSITIONs.
5003 POSITION can be one of the following symbols:
5005 bol -- beginning of line
5007 bod -- beginning of defun
5008 boi -- back to indentation
5009 eoi -- last whitespace on line
5010 ionl -- indentation of next line
5011 iopl -- indentation of previous line
5012 bonl -- beginning of next line
5013 bopl -- beginning of previous line
5015 This function does not modify point or mark."
5016 (or (and (eq 'quote (car-safe position))
5017 (null (cddr position)))
5018 (error "ERROR: Bad buffer position requested: %s" position))
5019 (setq position (nth 1 position))
5020 `(let ((here (point)))
5022 ((eq position 'bol) '((beginning-of-line)))
5023 ((eq position 'eol) '((end-of-line)))
5024 ((eq position 'bod) '((save-match-data
5025 (vhdl-beginning-of-defun))))
5026 ((eq position 'boi) '((back-to-indentation)))
5027 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5028 ((eq position 'bonl) '((forward-line 1)))
5029 ((eq position 'bopl) '((forward-line -1)))
5030 ((eq position 'iopl)
5032 (back-to-indentation)))
5033 ((eq position 'ionl)
5035 (back-to-indentation)))
5036 (t (error "ERROR: Unknown buffer position requested: %s" position))
5041 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5042 ;; doesn't hurt for v19
5046 (defmacro vhdl-safe (&rest body)
5047 "Safely execute BODY, return nil if an error occurred."
5048 `(condition-case nil
5052 (defmacro vhdl-add-syntax (symbol &optional relpos)
5053 "A simple macro to append the syntax in SYMBOL to the syntax list.
5054 Try to increase performance by using this macro."
5055 `(setq vhdl-syntactic-context
5056 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5058 (defmacro vhdl-has-syntax (symbol)
5059 "A simple macro to return check the syntax list.
5060 Try to increase performance by using this macro."
5061 `(assoc ,symbol vhdl-syntactic-context))
5063 ;; Syntactic element offset manipulation:
5065 (defun vhdl-read-offset (langelem)
5066 "Read new offset value for LANGELEM from minibuffer.
5067 Return a legal value only."
5068 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5069 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5071 offset input interned)
5073 (setq input (read-string prompt oldoff)
5074 offset (cond ((string-equal "+" input) '+)
5075 ((string-equal "-" input) '-)
5076 ((string-equal "++" input) '++)
5077 ((string-equal "--" input) '--)
5078 ((string-match "^-?[0-9]+$" input)
5079 (string-to-int input))
5080 ((fboundp (setq interned (intern input)))
5082 ((boundp interned) interned)
5083 ;; error, but don't signal one, keep trying
5084 ;; to read an input value
5086 (setq prompt errmsg)
5090 (defun vhdl-set-offset (symbol offset &optional add-p)
5091 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5092 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5093 offset for that syntactic element. Optional ADD says to add SYMBOL to
5094 `vhdl-offsets-alist' if it doesn't already appear there."
5097 (intern (completing-read
5098 (concat "Syntactic symbol to change"
5099 (if current-prefix-arg " or add" "")
5104 (cons (format "%s" (car langelem)) nil)))
5106 nil (not current-prefix-arg)
5107 ;; initial contents tries to be the last element
5108 ;; on the syntactic analysis list for the current
5110 (let* ((syntax (vhdl-get-syntactic-context))
5111 (len (length syntax))
5112 (ic (format "%s" (car (nth (1- len) syntax)))))
5115 (offset (vhdl-read-offset langelem)))
5116 (list langelem offset current-prefix-arg)))
5117 ;; sanity check offset
5125 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5127 (let ((entry (assq symbol vhdl-offsets-alist)))
5129 (setcdr entry offset)
5131 (setq vhdl-offsets-alist
5132 (cons (cons symbol offset) vhdl-offsets-alist))
5133 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5134 (vhdl-keep-region-active))
5136 (defun vhdl-set-style (style &optional local)
5137 "Set `vhdl-mode' variables to use one of several different indentation styles.
5138 STYLE is a string representing the desired style and optional LOCAL is
5139 a flag which, if non-nil, means to make the style variables being
5140 changed buffer local, instead of the default, which is to set the
5141 global variables. Interactively, the flag comes from the prefix
5142 argument. The styles are chosen from the `vhdl-style-alist' variable."
5143 (interactive (list (completing-read "Use which VHDL indentation style? "
5144 vhdl-style-alist nil t)
5145 current-prefix-arg))
5146 (let ((vars (cdr (assoc style vhdl-style-alist))))
5148 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5149 ;; set all the variables
5153 (let ((var (car varentry))
5154 (val (cdr varentry)))
5156 (make-local-variable var))
5157 ;; special case for vhdl-offsets-alist
5158 (if (not (eq var 'vhdl-offsets-alist))
5160 ;; reset vhdl-offsets-alist to the default value first
5161 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5162 ;; now set the langelems that are different
5166 (let ((langelem (car langentry))
5167 (offset (cdr langentry)))
5168 (vhdl-set-offset langelem offset)
5173 (vhdl-keep-region-active))
5175 (defun vhdl-get-offset (langelem)
5176 "Get offset from LANGELEM which is a cons cell of the form:
5177 \(SYMBOL . RELPOS). The symbol is matched against
5178 vhdl-offsets-alist and the offset found there is either returned,
5179 or added to the indentation at RELPOS. If RELPOS is nil, then
5180 the offset is simply returned."
5181 (let* ((symbol (car langelem))
5182 (relpos (cdr langelem))
5183 (match (assq symbol vhdl-offsets-alist))
5184 (offset (cdr-safe match)))
5185 ;; offset can be a number, a function, a variable, or one of the
5189 (if vhdl-strict-syntax-p
5190 (error "ERROR: Don't know how to indent a %s" symbol)
5193 ((eq offset '+) (setq offset vhdl-basic-offset))
5194 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5195 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5196 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5197 ((and (not (numberp offset))
5199 (setq offset (funcall offset langelem)))
5200 ((not (numberp offset))
5201 (setq offset (eval offset)))
5204 (< relpos (vhdl-point 'bol)))
5211 ;; Syntactic support functions:
5213 (defun vhdl-in-comment-p ()
5214 "Check if point is in a comment."
5215 (eq (vhdl-in-literal) 'comment))
5217 (defun vhdl-in-string-p ()
5218 "Check if point is in a string."
5219 (eq (vhdl-in-literal) 'string))
5221 (defun vhdl-in-literal ()
5222 "Determine if point is in a VHDL literal."
5224 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5226 ((nth 3 state) 'string)
5227 ((nth 4 state) 'comment)
5230 (defun vhdl-forward-comment (&optional direction)
5231 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5232 negative, skip forward otherwise."
5234 (if (and direction (< direction 0))
5237 (skip-chars-backward " \t\n")
5238 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5239 (goto-char (match-beginning 3))
5240 (skip-chars-backward " \t\n")))
5242 (skip-chars-forward " \t\n")
5243 (while (looking-at "--.*")
5244 (goto-char (match-end 0))
5245 (skip-chars-forward " \t\n"))))
5247 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5248 (unless (and vhdl-xemacs (string< "21.2" emacs-version))
5249 (defalias 'vhdl-forward-comment 'forward-comment))
5251 ;; This is the best we can do in Win-Emacs.
5252 (defun vhdl-win-il (&optional lim)
5253 "Determine if point is in a VHDL literal."
5255 (let* ((here (point))
5258 (lim (or lim (vhdl-point 'bod))))
5260 (while (< (point) here)
5262 (and (re-search-forward "--\\|[\"']"
5264 (buffer-substring (match-beginning 0) (match-end 0))))
5269 ;; looking at the opening of a VHDL style comment
5270 ((string= "--" match)
5271 (if (<= here (progn (end-of-line) (point))) 'comment))
5272 ;; looking at the opening of a double quote string
5273 ((string= "\"" match)
5274 (if (not (save-restriction
5275 ;; this seems to be necessary since the
5276 ;; re-search-forward will not work without it
5277 (narrow-to-region (point) here)
5279 ;; this regexp matches a double quote
5280 ;; which is preceded by an even number
5281 ;; of backslashes, including zero
5282 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5284 ;; looking at the opening of a single quote string
5285 ((string= "'" match)
5286 (if (not (save-restriction
5287 ;; see comments from above
5288 (narrow-to-region (point) here)
5290 ;; this matches a single quote which is
5291 ;; preceded by zero or two backslashes.
5292 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5299 (and (string-match "Win-Emacs" emacs-version)
5300 (fset 'vhdl-in-literal 'vhdl-win-il))
5302 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5303 ;; defined as lexical whitespace or comments. Search no farther back
5304 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5305 ;; used for backward skipping, (point-max) is used for forward
5308 (defun vhdl-forward-syntactic-ws (&optional lim)
5309 "Forward skip of syntactic whitespace."
5311 (let* ((lim (or lim (point-max)))
5313 (hugenum (point-max)))
5314 (narrow-to-region lim (point))
5315 (while (/= here (point))
5317 (vhdl-forward-comment hugenum)))))
5319 ;; This is the best we can do in Win-Emacs.
5320 (defun vhdl-win-fsws (&optional lim)
5321 "Forward skip syntactic whitespace for Win-Emacs."
5322 (let ((lim (or lim (point-max)))
5325 (skip-chars-forward " \t\n\r\f" lim)
5328 ((looking-at "--") (end-of-line))
5329 ;; none of the above
5330 (t (setq stop t))))))
5332 (and (string-match "Win-Emacs" emacs-version)
5333 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5335 (defun vhdl-backward-syntactic-ws (&optional lim)
5336 "Backward skip over syntactic whitespace."
5338 (let* ((lim (or lim (point-min)))
5340 (hugenum (- (point-max))))
5343 (narrow-to-region lim (point))
5344 (while (/= here (point))
5346 (vhdl-forward-comment hugenum)))))))
5348 ;; This is the best we can do in Win-Emacs.
5349 (defun vhdl-win-bsws (&optional lim)
5350 "Backward skip syntactic whitespace for Win-Emacs."
5351 (let ((lim (or lim (vhdl-point 'bod)))
5354 (skip-chars-backward " \t\n\r\f" lim)
5357 ((eq (vhdl-in-literal) 'comment)
5358 (skip-chars-backward "^-" lim)
5359 (skip-chars-backward "-" lim)
5360 (while (not (or (and (= (following-char) ?-)
5361 (= (char-after (1+ (point))) ?-))
5363 (skip-chars-backward "^-" lim)
5364 (skip-chars-backward "-" lim)))
5365 ;; none of the above
5366 (t (setq stop t))))))
5368 (and (string-match "Win-Emacs" emacs-version)
5369 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5371 ;; Functions to help finding the correct indentation column:
5373 (defun vhdl-first-word (point)
5374 "If the keyword at POINT is at boi, then return (current-column) at
5375 that point, else nil."
5377 (and (goto-char point)
5378 (eq (point) (vhdl-point 'boi))
5381 (defun vhdl-last-word (point)
5382 "If the keyword at POINT is at eoi, then return (current-column) at
5383 that point, else nil."
5385 (and (goto-char point)
5386 (save-excursion (or (eq (progn (forward-sexp) (point))
5388 (looking-at "\\s-*\\(--\\)?")))
5391 ;; Core syntactic evaluation functions:
5393 (defconst vhdl-libunit-re
5394 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5396 (defun vhdl-libunit-p ()
5400 (skip-chars-forward " \t\n")
5401 (not (looking-at "is\\b[^_]")))
5404 (and (not (looking-at "use\\b[^_]"))
5407 (vhdl-forward-syntactic-ws)
5408 (/= (following-char) ?:))))
5411 (defconst vhdl-defun-re
5412 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5414 (defun vhdl-defun-p ()
5416 (if (looking-at "block\\|process\\|procedural")
5417 ;; "block", "process", "procedural":
5420 (not (looking-at "end\\s-+\\w")))
5421 ;; "architecture", "configuration", "entity",
5422 ;; "package", "procedure", "function":
5425 (defun vhdl-corresponding-defun ()
5426 "If the word at the current position corresponds to a \"defun\"
5427 keyword, then return a string that can be used to find the
5428 corresponding \"begin\" keyword, else return nil."
5430 (and (looking-at vhdl-defun-re)
5432 (if (looking-at "block\\|process\\|procedural")
5433 ;; "block", "process". "procedural:
5434 (buffer-substring (match-beginning 0) (match-end 0))
5435 ;; "architecture", "configuration", "entity", "package",
5436 ;; "procedure", "function":
5439 (defconst vhdl-begin-fwd-re
5440 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5441 "A regular expression for searching forward that matches all known
5442 \"begin\" keywords.")
5444 (defconst vhdl-begin-bwd-re
5445 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5446 "A regular expression for searching backward that matches all known
5447 \"begin\" keywords.")
5449 (defun vhdl-begin-p (&optional lim)
5450 "Return t if we are looking at a real \"begin\" keyword.
5451 Assumes that the caller will make sure that we are looking at
5452 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5453 the middle of an identifier that just happens to contain a \"begin\"
5456 ;; "[architecture|case|configuration|entity|package|
5457 ;; procedure|function] ... is":
5458 ((and (looking-at "i")
5460 ;; Skip backward over first sexp (needed to skip over a
5461 ;; procedure interface list, and is harmless in other
5462 ;; situations). Note that we need "return" in the
5463 ;; following search list so that we don't run into
5464 ;; semicolons in the function interface list.
5467 (while (and (not foundp)
5469 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5471 (if (or (= (preceding-char) ?_)
5475 (and (/= (following-char) ?\;)
5476 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5479 ((looking-at "be\\|t")
5482 ((and (looking-at "e")
5483 ;; make sure that the "else" isn't inside a
5484 ;; conditional signal assignment.
5486 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5487 (or (eq (following-char) ?\;)
5490 ;; "block", "generate", "loop", "process", "procedural",
5491 ;; "units", "record":
5492 ((and (looking-at "bl\\|[glpur]")
5495 (not (looking-at "end\\s-+\\w"))))
5498 ((and (looking-at "c")
5501 (not (looking-at "end\\s-+\\w")))
5502 ;; look out for the dreaded entity class in an attribute
5504 (vhdl-backward-syntactic-ws lim)
5505 (/= (preceding-char) ?:)))
5507 ;; "for" (inside configuration declaration):
5508 ((and (looking-at "f")
5511 (not (looking-at "end\\s-+\\w")))
5512 (vhdl-has-syntax 'configuration))
5516 (defun vhdl-corresponding-mid (&optional lim)
5518 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5520 ((looking-at "then")
5525 (defun vhdl-corresponding-end (&optional lim)
5526 "If the word at the current position corresponds to a \"begin\"
5527 keyword, then return a vector containing enough information to find
5528 the corresponding \"end\" keyword, else return nil. The keyword to
5529 search forward for is aref 0. The column in which the keyword must
5530 appear is aref 1 or nil if any column is suitable.
5531 Assumes that the caller will make sure that we are not in the middle
5532 of an identifier that just happens to contain a \"begin\" keyword."
5534 (and (looking-at vhdl-begin-fwd-re)
5535 (/= (preceding-char) ?_)
5536 (not (vhdl-in-literal))
5539 ;; "is", "generate", "loop":
5540 ((looking-at "[igl]")
5542 (and (vhdl-last-word (point))
5543 (or (vhdl-first-word (point))
5545 (vhdl-beginning-of-statement-1 lim)
5546 (vhdl-backward-skip-label lim)
5547 (vhdl-first-word (point)))))))
5548 ;; "begin", "else", "for":
5549 ((looking-at "be\\|[ef]")
5551 (and (vhdl-last-word (point))
5552 (or (vhdl-first-word (point))
5554 (vhdl-beginning-of-statement-1 lim)
5555 (vhdl-backward-skip-label lim)
5556 (vhdl-first-word (point)))))))
5557 ;; "component", "units", "record":
5558 ((looking-at "[cur]")
5559 ;; The first end found will close the block
5561 ;; "block", "process", "procedural":
5562 ((looking-at "bl\\|p")
5564 (or (vhdl-first-word (point))
5566 (vhdl-beginning-of-statement-1 lim)
5567 (vhdl-backward-skip-label lim)
5568 (vhdl-first-word (point))))))
5571 (vector "elsif\\|else\\|end\\s-+if"
5572 (and (vhdl-last-word (point))
5573 (or (vhdl-first-word (point))
5575 (vhdl-beginning-of-statement-1 lim)
5576 (vhdl-backward-skip-label lim)
5577 (vhdl-first-word (point)))))))
5580 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5582 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5584 (defun vhdl-end-p (&optional lim)
5585 "Return t if we are looking at a real \"end\" keyword.
5586 Assumes that the caller will make sure that we are looking at
5587 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5588 the middle of an identifier that just happens to contain an \"end\"
5590 (or (not (looking-at "else"))
5591 ;; make sure that the "else" isn't inside a conditional signal
5594 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5595 (or (eq (following-char) ?\;)
5596 (eq (point) lim)))))
5598 (defun vhdl-corresponding-begin (&optional lim)
5599 "If the word at the current position corresponds to an \"end\"
5600 keyword, then return a vector containing enough information to find
5601 the corresponding \"begin\" keyword, else return nil. The keyword to
5602 search backward for is aref 0. The column in which the keyword must
5603 appear is aref 1 or nil if any column is suitable. The supplementary
5604 keyword to search forward for is aref 2 or nil if this is not
5605 required. If aref 3 is t, then the \"begin\" keyword may be found in
5606 the middle of a statement.
5607 Assumes that the caller will make sure that we are not in the middle
5608 of an identifier that just happens to contain an \"end\" keyword."
5611 (if (and (looking-at vhdl-end-fwd-re)
5612 (not (vhdl-in-literal))
5614 (if (looking-at "el")
5616 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5620 (skip-chars-forward " \t\n")
5623 ((looking-at "if\\b[^_]")
5624 (vector "else\\|elsif\\|if"
5625 (vhdl-first-word pos)
5628 ((looking-at "component\\b[^_]")
5629 (vector (buffer-substring (match-beginning 1)
5631 (vhdl-first-word pos)
5633 ;; "end units", "end record":
5634 ((looking-at "\\(units\\|record\\)\\b[^_]")
5635 (vector (buffer-substring (match-beginning 1)
5637 (vhdl-first-word pos)
5639 ;; "end block", "end process", "end procedural":
5640 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5641 (vector "begin" (vhdl-first-word pos) nil nil))
5643 ((looking-at "case\\b[^_]")
5644 (vector "case" (vhdl-first-word pos) "is" nil))
5646 ((looking-at "generate\\b[^_]")
5647 (vector "generate\\|for\\|if"
5648 (vhdl-first-word pos)
5651 ((looking-at "loop\\b[^_]")
5652 (vector "loop\\|while\\|for"
5653 (vhdl-first-word pos)
5655 ;; "end for" (inside configuration declaration):
5656 ((looking-at "for\\b[^_]")
5657 (vector "for" (vhdl-first-word pos) nil nil))
5660 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5661 (vhdl-first-word pos)
5662 ;; return an alist of (statement . keyword) mappings
5664 ;; "begin ... end [id]":
5666 ;; "architecture ... is ... begin ... end [id]":
5667 ("architecture" . "is")
5668 ;; "configuration ... is ... end [id]":
5669 ("configuration" . "is")
5670 ;; "entity ... is ... end [id]":
5672 ;; "package ... is ... end [id]":
5674 ;; "procedure ... is ... begin ... end [id]":
5675 ("procedure" . "is")
5676 ;; "function ... is ... begin ... end [id]":
5683 (defconst vhdl-leader-re
5684 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5686 (defun vhdl-end-of-leader ()
5688 (cond ((looking-at "block\\|process\\|procedural")
5691 (skip-chars-forward " \t\n")
5692 (= (following-char) ?\())
5695 (when (looking-at "[ \t\n]*is")
5696 (goto-char (match-end 0)))
5698 ((looking-at "component")
5700 (when (looking-at "[ \t\n]*is")
5701 (goto-char (match-end 0)))
5705 (skip-chars-forward " \t\n")
5706 (while (looking-at "[,:(]")
5708 (skip-chars-forward " \t\n"))
5713 (defconst vhdl-trailer-re
5714 "\\b\\(is\\|then\\|generate\\|loop\\)\\b[^_]")
5716 (defconst vhdl-statement-fwd-re
5717 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5718 "A regular expression for searching forward that matches all known
5719 \"statement\" keywords.")
5721 (defconst vhdl-statement-bwd-re
5722 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5723 "A regular expression for searching backward that matches all known
5724 \"statement\" keywords.")
5726 (defun vhdl-statement-p (&optional lim)
5727 "Return t if we are looking at a real \"statement\" keyword.
5728 Assumes that the caller will make sure that we are looking at
5729 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5730 in the middle of an identifier that just happens to contain a
5731 \"statement\" keyword."
5733 ;; "for" ... "generate":
5734 ((and (looking-at "f")
5735 ;; Make sure it's the start of a parameter specification.
5738 (skip-chars-forward " \t\n")
5739 (looking-at "in\\b[^_]"))
5740 ;; Make sure it's not an "end for".
5743 (not (looking-at "end\\s-+\\w"))))
5745 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5746 ((and (looking-at "i")
5747 ;; Make sure it's not an "end if".
5750 (not (looking-at "end\\s-+\\w"))))
5752 ;; "while" ... "loop":
5757 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5758 "Regexp describing a case statement alternative key.")
5760 (defun vhdl-case-alternative-p (&optional lim)
5761 "Return t if we are looking at a real case alternative.
5762 Assumes that the caller will make sure that we are looking at
5763 vhdl-case-alternative-re, and are not inside a literal, and that
5764 we are not in the middle of an identifier that just happens to
5765 contain a \"when\" keyword."
5768 (while (and (not foundp)
5769 (re-search-backward ";\\|<=" lim 'move))
5770 (if (or (= (preceding-char) ?_)
5774 (or (eq (following-char) ?\;)
5778 ;; Core syntactic movement functions:
5780 (defconst vhdl-b-t-b-re
5781 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5783 (defun vhdl-backward-to-block (&optional lim)
5784 "Move backward to the previous \"begin\" or \"end\" keyword."
5786 (while (and (not foundp)
5787 (re-search-backward vhdl-b-t-b-re lim 'move))
5788 (if (or (= (preceding-char) ?_)
5793 ((and (looking-at vhdl-begin-fwd-re)
5794 (/= (preceding-char) ?_)
5796 (setq foundp 'begin))
5798 ((and (looking-at vhdl-end-fwd-re)
5799 (/= (preceding-char) ?_)
5807 (defun vhdl-forward-sexp (&optional count lim)
5808 "Move forward across one balanced expression (sexp).
5809 With COUNT, do it that many times."
5811 (let ((count (or count 1))
5812 (case-fold-search t)
5817 (skip-chars-forward " \t\n")
5818 ;; Check for an unbalanced "end" keyword
5819 (if (and (looking-at vhdl-end-fwd-re)
5820 (/= (preceding-char) ?_)
5821 (not (vhdl-in-literal))
5823 (not (looking-at "else")))
5825 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5826 ;; If the current keyword is a "begin" keyword, then find the
5827 ;; corresponding "end" keyword.
5828 (if (setq end-vec (vhdl-corresponding-end lim))
5830 ;; end-re is the statement keyword to search for
5832 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5833 ;; column is either the statement keyword target column
5835 (column (aref end-vec 1))
5836 (eol (vhdl-point 'eol))
5837 foundp literal placeholder)
5838 ;; Look for the statement keyword.
5839 (while (and (not foundp)
5840 (re-search-forward end-re nil t)
5841 (setq placeholder (match-end 1))
5842 (goto-char (match-beginning 0)))
5843 ;; If we are in a literal, or not in the right target
5844 ;; column and not on the same line as the begin, then
5847 (/= (current-indentation) column)
5849 (= (preceding-char) ?_)
5850 (setq literal (vhdl-in-literal)))
5851 (if (eq literal 'comment)
5854 ;; An "else" keyword corresponds to both the opening brace
5855 ;; of the following sexp and the closing brace of the
5857 (if (not (looking-at "else"))
5858 (goto-char placeholder))
5862 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
5864 ;; If the current keyword is not a "begin" keyword, then just
5865 ;; perform the normal forward-sexp.
5868 (setq count (1- count))
5870 (setq target (point)))
5874 (defun vhdl-backward-sexp (&optional count lim)
5875 "Move backward across one balanced expression (sexp).
5876 With COUNT, do it that many times. LIM bounds any required backward
5879 (let ((count (or count 1))
5880 (case-fold-search t)
5884 ;; Perform the normal backward-sexp, unless we are looking at
5885 ;; "else" - an "else" keyword corresponds to both the opening brace
5886 ;; of the following sexp and the closing brace of the previous sexp.
5887 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
5888 (/= (preceding-char) ?_)
5889 (not (vhdl-in-literal)))
5892 (if (and (looking-at vhdl-begin-fwd-re)
5893 (/= (preceding-char) ?_)
5894 (not (vhdl-in-literal))
5896 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
5897 ;; If the current keyword is an "end" keyword, then find the
5898 ;; corresponding "begin" keyword.
5899 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
5900 (/= (preceding-char) ?_))
5902 ;; begin-re is the statement keyword to search for
5904 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
5905 ;; column is either the statement keyword target column
5907 (column (aref begin-vec 1))
5908 ;; internal-p controls where the statement keyword can
5910 (internal-p (aref begin-vec 3))
5911 (last-backward (point)) last-forward
5912 foundp literal keyword)
5913 ;; Look for the statement keyword.
5914 (while (and (not foundp)
5915 (re-search-backward begin-re lim t)
5917 (buffer-substring (match-beginning 1)
5919 ;; If we are in a literal or in the wrong column,
5922 (and (/= (current-indentation) column)
5923 ;; possibly accept current-column as
5924 ;; well as current-indentation.
5925 (or (not internal-p)
5926 (/= (current-column) column))))
5927 (= (preceding-char) ?_)
5930 ;; If there is a supplementary keyword, then
5931 ;; search forward for it.
5932 (if (and (setq begin-re (aref begin-vec 2))
5933 (or (not (listp begin-re))
5934 ;; If begin-re is an alist, then find the
5935 ;; element corresponding to the actual
5936 ;; keyword that we found.
5939 (assoc keyword begin-re))
5941 (setq begin-re (cdr begin-re))))))
5944 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
5946 (setq last-forward (point))
5947 ;; Look for the supplementary keyword
5948 ;; (bounded by the backward search start
5950 (while (and (not foundp)
5951 (re-search-forward begin-re
5953 (goto-char (match-beginning 1)))
5954 ;; If we are in a literal, then try again.
5955 (if (or (= (preceding-char) ?_)
5958 (if (eq literal 'comment)
5960 (min (vhdl-point 'eol) last-backward))
5962 ;; We have found the supplementary keyword.
5963 ;; Save the position of the keyword in foundp.
5964 (setq foundp (point)))
5967 ;; If the supplementary keyword was found, then
5968 ;; move point to the supplementary keyword.
5970 ;; If there was no supplementary keyword, then
5971 ;; point is already at the statement keyword.
5973 ) ; end of the search for the statement keyword
5975 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
5977 (setq count (1- count))
5979 (setq target (point)))
5983 (defun vhdl-backward-up-list (&optional count limit)
5984 "Move backward out of one level of blocks.
5985 With argument, do this that many times."
5987 (let ((count (or count 1))
5991 (if (looking-at vhdl-defun-re)
5992 (error "ERROR: Unbalanced blocks"))
5993 (vhdl-backward-to-block limit)
5994 (setq count (1- count)))
5995 (setq target (point)))
5996 (goto-char target)))
5998 (defun vhdl-end-of-defun (&optional count)
5999 "Move forward to the end of a VHDL defun."
6001 (let ((case-fold-search t))
6002 (vhdl-beginning-of-defun)
6003 (if (not (looking-at "block\\|process\\|procedural"))
6004 (re-search-forward "\\bis\\b"))
6005 (vhdl-forward-sexp)))
6007 (defun vhdl-mark-defun ()
6008 "Put mark at end of this \"defun\", point at beginning."
6010 (let ((case-fold-search t))
6012 (vhdl-beginning-of-defun)
6014 (if (not (looking-at "block\\|process\\|procedural"))
6015 (re-search-forward "\\bis\\b"))
6017 (exchange-point-and-mark)))
6019 (defun vhdl-beginning-of-libunit ()
6020 "Move backward to the beginning of a VHDL library unit.
6021 Returns the location of the corresponding begin keyword, unless search
6022 stops due to beginning or end of buffer.
6023 Note that if point is between the \"libunit\" keyword and the
6024 corresponding \"begin\" keyword, then that libunit will not be
6025 recognised, and the search will continue backwards. If point is
6026 at the \"begin\" keyword, then the defun will be recognised. The
6027 returned point is at the first character of the \"libunit\" keyword."
6028 (let ((last-forward (point))
6030 ;; Just in case we are actually sitting on the "begin"
6031 ;; keyword, allow for the keyword and an extra character,
6032 ;; as this will be used when looking forward for the
6034 (save-excursion (forward-word 1) (1+ (point))))
6035 foundp literal placeholder)
6036 ;; Find the "libunit" keyword.
6037 (while (and (not foundp)
6038 (re-search-backward vhdl-libunit-re nil 'move))
6039 ;; If we are in a literal, or not at a real libunit, then try again.
6040 (if (or (= (preceding-char) ?_)
6042 (not (vhdl-libunit-p)))
6044 ;; Find the corresponding "begin" keyword.
6045 (setq last-forward (point))
6046 (while (and (not foundp)
6047 (re-search-forward "\\bis\\b[^_]" last-backward t)
6048 (setq placeholder (match-beginning 0)))
6049 (if (or (= (preceding-char) ?_)
6050 (setq literal (vhdl-in-literal)))
6051 ;; It wasn't a real keyword, so keep searching.
6052 (if (eq literal 'comment)
6054 (min (vhdl-point 'eol) last-backward))
6056 ;; We have found the begin keyword, loop will exit.
6057 (setq foundp placeholder)))
6058 ;; Go back to the libunit keyword
6059 (goto-char last-forward)))
6062 (defun vhdl-beginning-of-defun (&optional count)
6063 "Move backward to the beginning of a VHDL defun.
6064 With argument, do it that many times.
6065 Returns the location of the corresponding begin keyword, unless search
6066 stops due to beginning or end of buffer."
6067 ;; Note that if point is between the "defun" keyword and the
6068 ;; corresponding "begin" keyword, then that defun will not be
6069 ;; recognised, and the search will continue backwards. If point is
6070 ;; at the "begin" keyword, then the defun will be recognised. The
6071 ;; returned point is at the first character of the "defun" keyword.
6073 (let ((count (or count 1))
6074 (case-fold-search t)
6075 (last-forward (point))
6079 (goto-char last-forward)
6080 (let ((last-backward
6081 ;; Just in case we are actually sitting on the "begin"
6082 ;; keyword, allow for the keyword and an extra character,
6083 ;; as this will be used when looking forward for the
6085 (save-excursion (forward-word 1) (1+ (point))))
6086 begin-string literal)
6087 (while (and (not foundp)
6088 (re-search-backward vhdl-defun-re nil 'move))
6089 ;; If we are in a literal, then try again.
6090 (if (or (= (preceding-char) ?_)
6093 (if (setq begin-string (vhdl-corresponding-defun))
6094 ;; This is a real defun keyword.
6095 ;; Find the corresponding "begin" keyword.
6096 ;; Look for the begin keyword.
6098 ;; Save the search start point.
6099 (setq last-forward (point))
6100 (while (and (not foundp)
6101 (search-forward begin-string last-backward t))
6102 (if (or (= (preceding-char) ?_)
6104 (setq literal (vhdl-in-literal))))
6105 ;; It wasn't a real keyword, so keep searching.
6106 (if (eq literal 'comment)
6108 (min (vhdl-point 'eol) last-backward))
6110 ;; We have found the begin keyword, loop will exit.
6111 (setq foundp (match-beginning 0)))
6113 ;; Go back to the defun keyword
6114 (goto-char last-forward)) ; end search for begin keyword
6116 ) ; end of the search for the defun keyword
6118 (setq count (1- count))
6120 (vhdl-keep-region-active)
6123 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6124 "Go to the beginning of the innermost VHDL statement.
6125 With prefix arg, go back N - 1 statements. If already at the
6126 beginning of a statement then go to the beginning of the preceding
6127 one. If within a string or comment, or next to a comment (only
6128 whitespace between), move by sentences instead of statements.
6130 When called from a program, this function takes 3 optional args: the
6131 prefix arg, and a buffer position limit which is the farthest back to
6132 search, and something whose meaning I don't understand."
6133 (interactive "p\np")
6134 (let ((count (or count 1))
6135 (case-fold-search t)
6136 (lim (or lim (point-min)))
6141 (setq state (parse-partial-sexp (point) here nil nil)))
6142 (if (and interactive
6145 (looking-at (concat "[ \t]*" comment-start-skip))))
6146 (forward-sentence (- count))
6148 (vhdl-beginning-of-statement-1 lim)
6149 (setq count (1- count))))
6150 ;; its possible we've been left up-buf of lim
6151 (goto-char (max (point) lim))
6153 (vhdl-keep-region-active))
6155 (defconst vhdl-e-o-s-re
6156 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6158 (defun vhdl-end-of-statement ()
6159 "Very simple implementation."
6161 (re-search-forward vhdl-e-o-s-re))
6163 (defconst vhdl-b-o-s-re
6164 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6165 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6167 (defun vhdl-beginning-of-statement-1 (&optional lim)
6168 "Move to the start of the current statement, or the previous
6169 statement if already at the beginning of one."
6170 (let ((lim (or lim (point-min)))
6174 ;; go backwards one balanced expression, but be careful of
6175 ;; unbalanced paren being reached
6176 (if (not (vhdl-safe (progn (backward-sexp) t)))
6178 (backward-up-list 1)
6180 (vhdl-forward-syntactic-ws here)
6182 (while (and (not donep)
6184 ;; look backwards for a statement boundary
6185 (re-search-backward vhdl-b-o-s-re lim 'move))
6186 (if (or (= (preceding-char) ?_)
6190 ;; If we are looking at an open paren, then stop after it
6191 ((eq (following-char) ?\()
6193 (vhdl-forward-syntactic-ws here)
6195 ;; If we are looking at a close paren, then skip it
6196 ((eq (following-char) ?\))
6201 (progn (goto-char pos)
6202 (vhdl-forward-syntactic-ws here)
6204 ;; If we are looking at a semicolon, then stop
6205 ((eq (following-char) ?\;)
6208 (vhdl-forward-syntactic-ws here)
6210 ;; If we are looking at a "begin", then stop
6211 ((and (looking-at vhdl-begin-fwd-re)
6212 (/= (preceding-char) ?_)
6214 ;; If it's a leader "begin", then find the
6216 (if (looking-at vhdl-leader-re)
6218 ;; set a default stop point at the begin
6220 ;; is the start point inside the leader area ?
6221 (goto-char (vhdl-end-of-leader))
6222 (vhdl-forward-syntactic-ws here)
6223 (if (< (point) here)
6224 ;; start point was not inside leader area
6225 ;; set stop point at word after leader
6226 (setq pos (point))))
6228 (vhdl-forward-syntactic-ws here)
6232 ;; If we are looking at a "statement", then stop
6233 ((and (looking-at vhdl-statement-fwd-re)
6234 (/= (preceding-char) ?_)
6235 (vhdl-statement-p nil))
6237 ;; If we are looking at a case alternative key, then stop
6238 ((and (looking-at vhdl-case-alternative-re)
6239 (vhdl-case-alternative-p lim))
6241 ;; set a default stop point at the when
6243 ;; is the start point inside the case alternative key ?
6244 (looking-at vhdl-case-alternative-re)
6245 (goto-char (match-end 0))
6246 (vhdl-forward-syntactic-ws here)
6247 (if (< (point) here)
6248 ;; start point was not inside the case alternative key
6249 ;; set stop point at word after case alternative keyleader
6250 (setq pos (point))))
6253 ;; Bogus find, continue
6258 ;; Defuns for calculating the current syntactic state:
6260 (defun vhdl-get-library-unit (bod placeholder)
6261 "If there is an enclosing library unit at bod, with it's \"begin\"
6262 keyword at placeholder, then return the library unit type."
6263 (let ((here (vhdl-point 'bol)))
6265 (goto-char placeholder)
6266 (vhdl-safe (vhdl-forward-sexp 1 bod))
6271 ((looking-at "e") 'entity)
6272 ((looking-at "a") 'architecture)
6273 ((looking-at "c") 'configuration)
6278 (vhdl-forward-syntactic-ws here)
6279 (if (looking-at "body\\b[^_]")
6280 'package-body 'package))))))
6283 (defun vhdl-get-block-state (&optional lim)
6284 "Finds and records all the closest opens.
6285 lim is the furthest back we need to search (it should be the
6286 previous libunit keyword)."
6287 (let ((here (point))
6288 (lim (or lim (point-min)))
6289 keyword sexp-start sexp-mid sexp-end
6290 preceding-sexp containing-sexp
6291 containing-begin containing-mid containing-paren)
6293 ;; Find the containing-paren, and use that as the limit
6294 (if (setq containing-paren
6296 (narrow-to-region lim (point))
6297 (vhdl-safe (scan-lists (point) -1 1))))
6298 (setq lim containing-paren))
6299 ;; Look backwards for "begin" and "end" keywords.
6300 (while (and (> (point) lim)
6301 (not containing-sexp))
6302 (setq keyword (vhdl-backward-to-block lim))
6304 ((eq keyword 'begin)
6305 ;; Found a "begin" keyword
6306 (setq sexp-start (point))
6307 (setq sexp-mid (vhdl-corresponding-mid lim))
6308 (setq sexp-end (vhdl-safe
6310 (vhdl-forward-sexp 1 lim) (point))))
6311 (if (and sexp-end (<= sexp-end here))
6312 ;; we want to record this sexp, but we only want to
6313 ;; record the last-most of any of them before here
6315 (setq preceding-sexp sexp-start))
6316 ;; we're contained in this sexp so put sexp-start on
6318 (setq containing-sexp sexp-start)
6319 (setq containing-mid sexp-mid)
6320 (setq containing-begin t)))
6322 ;; Found an "end" keyword
6324 (setq sexp-end (point))
6327 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6328 (progn (backward-sexp) (point))))
6329 ;; we want to record this sexp, but we only want to
6330 ;; record the last-most of any of them before here
6332 (setq preceding-sexp sexp-start)))
6334 ;; Check if the containing-paren should be the containing-sexp
6335 (if (and containing-paren
6336 (or (null containing-sexp)
6337 (< containing-sexp containing-paren)))
6338 (setq containing-sexp containing-paren
6340 containing-begin nil
6341 containing-mid nil))
6342 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6346 (defconst vhdl-s-c-a-re
6347 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6349 (defun vhdl-skip-case-alternative (&optional lim)
6350 "Skip forward over case/when bodies, with optional maximal
6351 limit. If no next case alternative is found, nil is returned and point
6353 (let ((lim (or lim (point-max)))
6356 (while (and (< (point) lim)
6358 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6360 (not (vhdl-in-literal)))
6361 (/= (match-beginning 0) here))
6363 (goto-char (match-beginning 0))
6365 ((and (looking-at "case")
6366 (re-search-forward "\\bis[^_]" lim t))
6368 (vhdl-forward-sexp))
6376 (defun vhdl-backward-skip-label (&optional lim)
6377 "Skip backward over a label, with optional maximal
6378 limit. If label is not found, nil is returned and point
6380 (let ((lim (or lim (point-min)))
6383 (vhdl-backward-syntactic-ws lim)
6384 (and (eq (preceding-char) ?:)
6387 (setq placeholder (point))
6388 (looking-at vhdl-label-key))))
6389 (goto-char placeholder))
6392 (defun vhdl-forward-skip-label (&optional lim)
6393 "Skip forward over a label, with optional maximal
6394 limit. If label is not found, nil is returned and point
6396 (let ((lim (or lim (point-max))))
6397 (if (looking-at vhdl-label-key)
6399 (goto-char (match-end 0))
6400 (vhdl-forward-syntactic-ws lim)))
6403 (defun vhdl-get-syntactic-context ()
6404 "Guess the syntactic description of the current line of VHDL code."
6408 (let* ((indent-point (point))
6409 (case-fold-search t)
6410 vec literal containing-sexp preceding-sexp
6411 containing-begin containing-mid containing-leader
6412 char-before-ip char-after-ip begin-after-ip end-after-ip
6413 placeholder lim library-unit
6416 ;; Reset the syntactic context
6417 (setq vhdl-syntactic-context nil)
6420 ;; Move to the start of the previous library unit, and
6421 ;; record the position of the "begin" keyword.
6422 (setq placeholder (vhdl-beginning-of-libunit))
6423 ;; The position of the "libunit" keyword gives us a gross
6428 ;; If there is a previous library unit, and we are enclosed by
6429 ;; it, then set the syntax accordingly.
6431 (setq library-unit (vhdl-get-library-unit lim placeholder))
6432 (vhdl-add-syntax library-unit lim))
6434 ;; Find the surrounding state.
6435 (if (setq vec (vhdl-get-block-state lim))
6437 (setq containing-sexp (aref vec 0))
6438 (setq preceding-sexp (aref vec 1))
6439 (setq containing-begin (aref vec 2))
6440 (setq containing-mid (aref vec 3))
6443 ;; set the limit on the farthest back we need to search
6444 (setq lim (if containing-sexp
6446 (goto-char containing-sexp)
6447 ;; set containing-leader if required
6448 (if (looking-at vhdl-leader-re)
6449 (setq containing-leader (vhdl-end-of-leader)))
6453 ;; cache char before and after indent point, and move point to
6454 ;; the most likely position to perform the majority of tests
6455 (goto-char indent-point)
6456 (skip-chars-forward " \t")
6457 (setq literal (vhdl-in-literal))
6458 (setq char-after-ip (following-char))
6459 (setq begin-after-ip (and
6461 (looking-at vhdl-begin-fwd-re)
6463 (setq end-after-ip (and
6465 (looking-at vhdl-end-fwd-re)
6467 (vhdl-backward-syntactic-ws lim)
6468 (setq char-before-ip (preceding-char))
6469 (goto-char indent-point)
6470 (skip-chars-forward " \t")
6472 ;; now figure out syntactic qualities of the current line
6474 ;; CASE 1: in a string or comment.
6475 ((memq literal '(string comment))
6476 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6477 ;; CASE 2: Line is at top level.
6478 ((null containing-sexp)
6479 ;; Find the point to which indentation will be relative
6481 (if (null preceding-sexp)
6483 ;; no preceding-sexp -> use the preceding statement
6484 (vhdl-beginning-of-statement-1 lim)
6486 ;; if there is a preceding-sexp then indent relative to it
6487 (goto-char preceding-sexp)
6488 ;; if not at boi, then the block-opening keyword is
6489 ;; probably following a label, so we need a different
6491 (if (/= (point) (vhdl-point 'boi))
6493 (vhdl-beginning-of-statement-1 lim)))
6494 ;; v-b-o-s could have left us at point-min
6497 (vhdl-forward-syntactic-ws indent-point))
6498 (setq placeholder (point)))
6500 ;; CASE 2A : we are looking at a block-open
6502 (vhdl-add-syntax 'block-open placeholder))
6503 ;; CASE 2B: we are looking at a block-close
6505 (vhdl-add-syntax 'block-close placeholder))
6506 ;; CASE 2C: we are looking at a top-level statement
6508 (vhdl-backward-syntactic-ws lim)
6510 (= (preceding-char) ?\;)))
6511 (vhdl-add-syntax 'statement placeholder))
6512 ;; CASE 2D: we are looking at a top-level statement-cont
6514 (vhdl-beginning-of-statement-1 lim)
6515 ;; v-b-o-s could have left us at point-min
6518 (vhdl-forward-syntactic-ws indent-point))
6519 (vhdl-add-syntax 'statement-cont (point)))
6521 ;; CASE 3: line is inside parentheses. Most likely we are
6522 ;; either in a subprogram argument (interface) list, or a
6523 ;; continued expression containing parentheses.
6524 ((null containing-begin)
6525 (vhdl-backward-syntactic-ws containing-sexp)
6527 ;; CASE 3A: we are looking at the arglist closing paren
6528 ((eq char-after-ip ?\))
6529 (goto-char containing-sexp)
6530 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6531 ;; CASE 3B: we are looking at the first argument in an empty
6533 ((eq char-before-ip ?\()
6534 (goto-char containing-sexp)
6535 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6536 ;; CASE 3C: we are looking at an arglist continuation line,
6537 ;; but the preceding argument is on the same line as the
6538 ;; opening paren. This case includes multi-line
6539 ;; expression paren groupings.
6540 ((and (save-excursion
6541 (goto-char (1+ containing-sexp))
6542 (skip-chars-forward " \t")
6544 (not (looking-at "--")))
6546 (vhdl-beginning-of-statement-1 containing-sexp)
6547 (skip-chars-backward " \t(")
6548 (<= (point) containing-sexp)))
6549 (goto-char containing-sexp)
6550 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6551 ;; CASE 3D: we are looking at just a normal arglist
6552 ;; continuation line
6553 (t (vhdl-beginning-of-statement-1 containing-sexp)
6554 (vhdl-forward-syntactic-ws indent-point)
6555 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6557 ;; CASE 4: A block mid open
6558 ((and begin-after-ip
6559 (looking-at containing-mid))
6560 (goto-char containing-sexp)
6561 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6562 (if (looking-at vhdl-trailer-re)
6564 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6565 (vhdl-backward-skip-label (vhdl-point 'boi))
6566 (vhdl-add-syntax 'block-open (point)))
6567 ;; CASE 5: block close brace
6569 (goto-char containing-sexp)
6570 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6571 (if (looking-at vhdl-trailer-re)
6573 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6574 (vhdl-backward-skip-label (vhdl-point 'boi))
6575 (vhdl-add-syntax 'block-close (point)))
6576 ;; CASE 6: A continued statement
6577 ((and (/= char-before-ip ?\;)
6578 ;; check it's not a trailer begin keyword, or a begin
6579 ;; keyword immediately following a label.
6580 (not (and begin-after-ip
6581 (or (looking-at vhdl-trailer-re)
6583 (vhdl-backward-skip-label containing-sexp)))))
6584 ;; check it's not a statement keyword
6585 (not (and (looking-at vhdl-statement-fwd-re)
6586 (vhdl-statement-p)))
6587 ;; see if the b-o-s is before the indent point
6590 (vhdl-beginning-of-statement-1 containing-sexp)
6591 ;; If we ended up after a leader, then this will
6592 ;; move us forward to the start of the first
6593 ;; statement. Note that a containing sexp here is
6594 ;; always a keyword, not a paren, so this will
6595 ;; have no effect if we hit the containing-sexp.
6596 (vhdl-forward-syntactic-ws indent-point)
6597 (setq placeholder (point))))
6598 ;; check it's not a block-intro
6599 (/= placeholder containing-sexp)
6600 ;; check it's not a case block-intro
6602 (goto-char placeholder)
6603 (or (not (looking-at vhdl-case-alternative-re))
6604 (> (match-end 0) indent-point))))
6605 ;; Make placeholder skip a label, but only if it puts us
6606 ;; before the indent point at the start of a line.
6607 (let ((new placeholder))
6608 (if (and (> indent-point
6610 (goto-char placeholder)
6611 (vhdl-forward-skip-label indent-point)
6612 (setq new (point))))
6615 (eq new (progn (back-to-indentation) (point)))))
6616 (setq placeholder new)))
6617 (vhdl-add-syntax 'statement-cont placeholder)
6619 (vhdl-add-syntax 'block-open)))
6620 ;; Statement. But what kind?
6621 ;; CASE 7: A case alternative key
6622 ((and (looking-at vhdl-case-alternative-re)
6623 (vhdl-case-alternative-p containing-sexp))
6624 ;; for a case alternative key, we set relpos to the first
6625 ;; non-whitespace char on the line containing the "case"
6627 (goto-char containing-sexp)
6628 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6629 (if (looking-at vhdl-trailer-re)
6630 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6631 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6632 ;; CASE 8: statement catchall
6634 ;; we know its a statement, but we need to find out if it is
6635 ;; the first statement in a block
6636 (if containing-leader
6637 (goto-char containing-leader)
6638 (goto-char containing-sexp)
6639 ;; Note that a containing sexp here is always a keyword,
6640 ;; not a paren, so skip over the keyword.
6642 ;; move to the start of the first statement
6643 (vhdl-forward-syntactic-ws indent-point)
6644 (setq placeholder (point))
6645 ;; we want to ignore case alternatives keys when skipping forward
6647 (while (looking-at vhdl-case-alternative-re)
6648 (setq incase-p (point))
6649 ;; we also want to skip over the body of the
6650 ;; case/when statement if that doesn't put us at
6651 ;; after the indent-point
6652 (while (vhdl-skip-case-alternative indent-point))
6653 ;; set up the match end
6654 (looking-at vhdl-case-alternative-re)
6655 (goto-char (match-end 0))
6656 ;; move to the start of the first case alternative statement
6657 (vhdl-forward-syntactic-ws indent-point)
6658 (setq placeholder (point)))
6660 ;; CASE 8A: we saw a case/when statement so we must be
6661 ;; in a switch statement. find out if we are at the
6662 ;; statement just after a case alternative key
6664 (= (point) indent-point))
6665 ;; relpos is the "when" keyword
6666 (vhdl-add-syntax 'statement-case-intro incase-p))
6667 ;; CASE 8B: any old statement
6668 ((< (point) indent-point)
6669 ;; relpos is the first statement of the block
6670 (vhdl-add-syntax 'statement placeholder)
6672 (vhdl-add-syntax 'block-open)))
6673 ;; CASE 8C: first statement in a block
6675 (goto-char containing-sexp)
6676 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6677 (if (looking-at vhdl-trailer-re)
6678 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6679 (vhdl-backward-skip-label (vhdl-point 'boi))
6680 (vhdl-add-syntax 'statement-block-intro (point))
6682 (vhdl-add-syntax 'block-open)))
6686 ;; now we need to look at any modifiers
6687 (goto-char indent-point)
6688 (skip-chars-forward " \t")
6689 (if (looking-at "--")
6690 (vhdl-add-syntax 'comment))
6691 ;; return the syntax
6692 vhdl-syntactic-context))))
6694 ;; Standard indentation line-ups:
6696 (defun vhdl-lineup-arglist (langelem)
6697 "Lineup the current arglist line with the arglist appearing just
6698 after the containing paren which starts the arglist."
6700 (let* ((containing-sexp
6702 ;; arglist-cont-nonempty gives relpos ==
6703 ;; to boi of containing-sexp paren. This
6704 ;; is good when offset is +, but bad
6705 ;; when it is vhdl-lineup-arglist, so we
6706 ;; have to special case a kludge here.
6707 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6710 (backward-up-list 1)
6711 (skip-chars-forward " \t" (vhdl-point 'eol)))
6712 (goto-char (cdr langelem)))
6714 (cs-curcol (save-excursion
6715 (goto-char (cdr langelem))
6719 (looking-at "[ \t]*)"))
6720 (progn (goto-char (match-end 0))
6723 (vhdl-forward-syntactic-ws)
6724 (- (current-column) cs-curcol))
6725 (goto-char containing-sexp)
6727 (let ((eol (vhdl-point 'eol))
6730 (skip-chars-forward " \t")
6732 (vhdl-forward-syntactic-ws)
6735 (- (current-column) cs-curcol)
6738 (defun vhdl-lineup-arglist-intro (langelem)
6739 "Lineup an arglist-intro line to just after the open paren."
6741 (let ((cs-curcol (save-excursion
6742 (goto-char (cdr langelem))
6744 (ce-curcol (save-excursion
6746 (backward-up-list 1)
6747 (skip-chars-forward " \t" (vhdl-point 'eol))
6749 (- ce-curcol cs-curcol -1))))
6751 (defun vhdl-lineup-comment (langelem)
6752 "Support old behavior for comment indentation. We look at
6753 vhdl-comment-only-line-offset to decide how to indent comment
6756 (back-to-indentation)
6757 ;; at or to the right of comment-column
6758 (if (>= (current-column) comment-column)
6759 (vhdl-comment-indent)
6760 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6762 (or (car-safe vhdl-comment-only-line-offset)
6763 vhdl-comment-only-line-offset)
6764 (or (cdr-safe vhdl-comment-only-line-offset)
6765 (car-safe vhdl-comment-only-line-offset)
6766 -1000 ;jam it against the left side
6769 (defun vhdl-lineup-statement-cont (langelem)
6770 "Line up statement-cont after the assignment operator."
6772 (let* ((relpos (cdr langelem))
6773 (assignp (save-excursion
6774 (goto-char (vhdl-point 'boi))
6775 (and (re-search-forward "\\(<\\|:\\)="
6776 (vhdl-point 'eol) t)
6777 (- (point) (vhdl-point 'boi)))))
6782 (while (and (not foundp)
6783 (< (point) (vhdl-point 'eol)))
6784 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6785 (if (vhdl-in-literal)
6787 (if (= (preceding-char) ?\()
6788 ;; skip over any parenthesized expressions
6789 (goto-char (min (vhdl-point 'eol)
6790 (scan-lists (point) 1 1)))
6791 ;; found an assignment operator (not at eol)
6792 (setq foundp (not (looking-at "\\s-*$"))))))
6794 ;; there's no assignment operator on the line
6796 ;; calculate indentation column after assign and ws, unless
6797 ;; our line contains an assignment operator
6801 (skip-chars-forward " \t")
6803 (- (current-column) assignp curcol))
6806 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6807 ;; Progress reporting
6809 (defvar vhdl-progress-info nil
6810 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6812 (defun vhdl-update-progress-info (string pos)
6813 "Update progress information."
6814 (when (and vhdl-progress-info (not noninteractive)
6815 (< vhdl-progress-interval
6816 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6817 (message (concat string "... (%2d%s)")
6818 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6819 (- (aref vhdl-progress-info 1)
6820 (aref vhdl-progress-info 0))) "%")
6821 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6823 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6824 ;; Indentation commands
6826 (defun vhdl-electric-tab (&optional prefix-arg)
6827 "If preceeding character is part of a word or a paren then hippie-expand,
6828 else if right of non whitespace on line then insert tab,
6829 else if last command was a tab or return then dedent one step or if a comment
6830 toggle between normal indent and inline comment indent,
6831 else indent `correctly'."
6833 (vhdl-prepare-search-2
6836 ((= (char-syntax (preceding-char)) ?w)
6837 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6839 (hippie-expand-only-buffers
6840 (or (and (boundp 'hippie-expand-only-buffers)
6841 hippie-expand-only-buffers)
6843 (vhdl-expand-abbrev prefix-arg)))
6844 ;; expand parenthesis
6845 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6846 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6848 (vhdl-expand-paren prefix-arg)))
6850 ((> (current-column) (current-indentation))
6852 ;; toggle comment indent
6853 ((and (looking-at "--")
6854 (or (eq last-command 'vhdl-electric-tab)
6855 (eq last-command 'vhdl-electric-return)))
6856 (cond ((= (current-indentation) 0) ; no indent
6858 (indent-according-to-mode))
6859 ((< (current-indentation) comment-column) ; normal indent
6860 (indent-to comment-column)
6861 (indent-according-to-mode))
6862 (t ; inline comment indent
6865 ((and (>= (current-indentation) vhdl-basic-offset)
6866 (or (eq last-command 'vhdl-electric-tab)
6867 (eq last-command 'vhdl-electric-return)))
6868 (backward-delete-char-untabify vhdl-basic-offset nil))
6870 (t (indent-according-to-mode)))
6871 (setq this-command 'vhdl-electric-tab)))
6873 (defun vhdl-electric-return ()
6874 "newline-and-indent or indent-new-comment-line if in comment and preceding
6875 character is a space."
6877 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
6878 (indent-new-comment-line)
6879 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
6880 (vhdl-fix-case-word -1))
6881 (newline-and-indent)))
6883 (defun vhdl-indent-line ()
6884 "Indent the current line as VHDL code. Returns the amount of
6885 indentation change."
6887 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
6888 (pos (- (point-max) (point)))
6891 ;; indent syntax-based
6892 (if (and (eq (caar syntax) 'comment)
6893 (>= (vhdl-get-offset (car syntax)) comment-column))
6894 ;; special case: comments at or right of comment-column
6895 (vhdl-get-offset (car syntax))
6896 (apply '+ (mapcar 'vhdl-get-offset syntax)))
6897 ;; indent like previous nonblank line
6898 (save-excursion (beginning-of-line)
6899 (re-search-backward "^[^\n]" nil t)
6900 (current-indentation))))
6901 (shift-amt (- indent (current-indentation))))
6902 (and vhdl-echo-syntactic-information-p
6903 (message "syntax: %s, indent= %d" syntax indent))
6904 (unless (zerop shift-amt)
6905 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
6908 (if (< (point) (vhdl-point 'boi))
6909 (back-to-indentation)
6910 ;; If initial point was within line's indentation, position after
6911 ;; the indentation. Else stay at same point in text.
6912 (when (> (- (point-max) pos) (point))
6913 (goto-char (- (point-max) pos))))
6914 (run-hooks 'vhdl-special-indent-hook)
6915 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
6918 (defun vhdl-indent-region (beg end column)
6919 "Indent region as VHDL code.
6920 Adds progress reporting to `indent-region'."
6921 (interactive "r\nP")
6922 (when vhdl-progress-interval
6923 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
6924 (count-lines (point-min) end) 0)))
6925 (indent-region beg end column)
6926 (when vhdl-progress-interval (message "Indenting...done"))
6927 (setq vhdl-progress-info nil))
6929 (defun vhdl-indent-buffer ()
6930 "Indent whole buffer as VHDL code.
6931 Calls `indent-region' for whole buffer and adds progress reporting."
6933 (vhdl-indent-region (point-min) (point-max) nil))
6935 (defun vhdl-indent-group ()
6936 "Indent group of lines between empty lines."
6938 (let ((beg (save-excursion
6939 (if (re-search-backward vhdl-align-group-separate nil t)
6941 (point-min-marker))))
6942 (end (save-excursion
6943 (if (re-search-forward vhdl-align-group-separate nil t)
6945 (point-max-marker)))))
6946 (vhdl-indent-region beg end nil)))
6948 (defun vhdl-indent-sexp (&optional endpos)
6949 "Indent each line of the list starting just after point.
6950 If optional arg ENDPOS is given, indent each line, stopping when
6951 ENDPOS is encountered."
6955 (end (progn (vhdl-forward-sexp nil endpos) (point))))
6956 (indent-region beg end nil))))
6958 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6959 ;; Miscellaneous commands
6961 (defun vhdl-show-syntactic-information ()
6962 "Show syntactic information for current line."
6964 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
6965 (vhdl-keep-region-active))
6967 ;; Verification and regression functions:
6969 (defun vhdl-regress-line (&optional arg)
6970 "Check syntactic information for current line."
6972 (let ((expected (save-excursion
6974 (when (search-backward " -- ((" (vhdl-point 'bol) t)
6976 (read (current-buffer)))))
6977 (actual (vhdl-get-syntactic-context))
6979 ;; remove the library unit symbols
6983 (if (memq (car elt) '(entity configuration package
6984 package-body architecture))
6986 (setq expurgated (append expurgated (list elt))))))
6988 (if (and (not arg) expected (listp expected))
6989 (if (not (equal expected expurgated))
6990 (error "ERROR: Should be: %s, is: %s" expected expurgated))
6993 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
6995 (if (search-backward " -- ((" (vhdl-point 'bol) t)
6998 (insert (format "%s" expurgated))))))
6999 (vhdl-keep-region-active))
7002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7003 ;;; Alignment, whitespace fixup, beautifying
7004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7006 (defconst vhdl-align-alist
7008 ;; after some keywords
7009 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7010 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7012 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7013 ;; after direction specifications
7014 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7015 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7016 ;; before "==", ":=", "=>", and "<="
7017 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7018 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7019 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7020 ;; before some keywords
7021 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7022 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7023 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7024 ;; before "=>" since "when/else ... =>" can occur
7025 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7027 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7028 It is searched in order. If REGEXP is found anywhere in the first
7029 line of a region to be aligned, ALIGN-PATTERN will be used for that
7030 region. ALIGN-PATTERN must include the whitespace to be expanded or
7031 contracted. It may also provide regexps for the text surrounding the
7032 whitespace. SUBEXP specifies which sub-expression of
7033 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7035 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7038 (defvar vhdl-align-try-all-clauses t
7039 "If REGEXP is not found on the first line of the region that clause
7040 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7042 (defun vhdl-do-group (function &optional spacing)
7043 "Apply FUNCTION on group of lines between empty lines."
7045 ;; search for group beginning
7046 ((beg (save-excursion
7047 (if (re-search-backward vhdl-align-group-separate nil t)
7048 (progn (beginning-of-line 2) (back-to-indentation) (point))
7050 ;; search for group end
7051 (end (save-excursion
7052 (if (re-search-forward vhdl-align-group-separate nil t)
7053 (progn (beginning-of-line) (point))
7056 (funcall function beg end spacing)))
7058 (defun vhdl-do-list (function &optional spacing)
7059 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7063 ;; search for beginning of balanced group of parentheses
7064 (setq beg (vhdl-re-search-backward "[()]" nil t))
7065 (while (looking-at ")")
7066 (forward-char) (backward-sexp)
7067 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7068 ;; search for end of balanced group of parentheses
7072 (goto-char (1+ beg))
7073 (skip-chars-forward " \t\n")
7074 (setq beg (point))))
7077 (funcall function beg end spacing)
7078 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7080 (defun vhdl-do-same-indent (function &optional spacing)
7081 "Apply FUNCTION to block of lines with same indent."
7082 (let ((indent (current-indentation))
7084 ;; search for first line with same indent
7086 (while (and (not (bobp))
7087 (or (looking-at "^\\s-*\\(--.*\\)?$")
7088 (= (current-indentation) indent)))
7089 (unless (looking-at "^\\s-*$")
7090 (back-to-indentation) (setq beg (point)))
7091 (beginning-of-line -0)))
7092 ;; search for last line with same indent
7094 (while (and (not (eobp))
7095 (or (looking-at "^\\s-*\\(--.*\\)?$")
7096 (= (current-indentation) indent)))
7097 (if (looking-at "^\\s-*$")
7098 (beginning-of-line 2)
7099 (beginning-of-line 2)
7100 (setq end (point)))))
7102 (funcall function beg end spacing)))
7104 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7105 "Attempt to align a range of lines based on the content of the
7106 lines. The definition of `alignment-list' determines the matching
7107 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7108 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7109 indentation is done before aligning."
7110 (interactive "r\np")
7111 (setq alignment-list (or alignment-list vhdl-align-alist))
7112 (setq spacing (or spacing 1))
7116 (setq end (point-marker))
7118 (setq bol (setq begin (progn (beginning-of-line) (point))))
7119 ; (untabify bol end)
7121 (indent-region bol end nil))))
7122 (let ((copy (copy-alist alignment-list)))
7123 (vhdl-prepare-search-2
7128 (eol (save-excursion (progn (end-of-line) (point)))))
7129 (setq element (nth 0 copy))
7130 (when (and (or (and (listp (car element))
7131 (memq major-mode (car element)))
7132 (eq major-mode (car element)))
7133 (or vhdl-align-try-all-clauses
7134 (re-search-forward (car (cdr element)) eol t)))
7135 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7136 (car (cdr (cdr (cdr element)))) spacing))
7137 (setq copy (cdr copy))))))))
7139 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7140 "Align a range of lines from BEGIN to END. The regular expression
7141 MATCH must match exactly one fields: the whitespace to be
7142 contracted/expanded. The alignment column will equal the
7143 rightmost column of the widest whitespace block. SPACING is
7144 the amount of extra spaces to add to the calculated maximum required.
7145 SPACING defaults to 1 so that at least one space is inserted after
7146 the token in MATCH."
7147 (setq spacing (or spacing 1))
7148 (setq substr (or substr 1))
7150 (let (distance (max 0) (lines 0) bol eol width)
7151 ;; Determine the greatest whitespace distance to the alignment
7154 (setq eol (progn (end-of-line) (point))
7155 bol (setq begin (progn (beginning-of-line) (point))))
7158 (when (and (re-search-forward match eol t)
7159 (not (vhdl-in-literal)))
7160 (setq distance (- (match-beginning substr) bol))
7161 (when (> distance max)
7162 (setq max distance))))
7165 eol (save-excursion (end-of-line) (point)))
7166 (setq lines (1+ lines)))
7167 ;; Now insert enough maxs to push each assignment operator to
7168 ;; the same column. We need to use 'lines' as a counter, since
7169 ;; the location of the mark may change
7170 (goto-char (setq bol begin))
7171 (setq eol (save-excursion (end-of-line) (point)))
7173 (when (and (re-search-forward match eol t)
7174 (not (vhdl-in-literal)))
7175 (setq width (- (match-end substr) (match-beginning substr)))
7176 (setq distance (- (match-beginning substr) bol))
7177 (goto-char (match-beginning substr))
7179 (insert-char ? (+ (- max distance) spacing)))
7183 eol (save-excursion (end-of-line) (point)))
7184 (setq lines (1- lines))))))
7186 (defun vhdl-align-region-groups (beg end &optional spacing
7187 no-message no-comments)
7188 "Align region, treat groups of lines separately."
7189 (interactive "r\nP")
7194 (setq orig (point-marker))
7197 (setq end (point-marker))
7200 (when vhdl-progress-interval
7201 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7202 (count-lines (point-min) end) 0))))
7203 (vhdl-fixup-whitespace-region beg end t)
7205 (if (not vhdl-align-groups)
7206 ;; align entire region
7207 (progn (vhdl-align-region-1 beg end spacing)
7209 (vhdl-align-inline-comment-region-1 beg end)))
7211 (while (and (< beg end)
7212 (re-search-forward vhdl-align-group-separate end t))
7213 (setq pos (point-marker))
7214 (vhdl-align-region-1 beg pos spacing)
7215 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7216 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7221 (vhdl-align-region-1 beg end spacing)
7222 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7223 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7224 (when vhdl-indent-tabs-mode
7227 (when vhdl-progress-interval (message "Aligning...done"))
7228 (setq vhdl-progress-info nil)))))
7230 (defun vhdl-align-region (beg end &optional spacing)
7231 "Align region, treat blocks with same indent and argument lists separately."
7232 (interactive "r\nP")
7233 (if (not vhdl-align-same-indent)
7234 ;; align entire region
7235 (vhdl-align-region-groups beg end spacing)
7236 ;; align blocks with same indent and argument lists
7240 (when vhdl-progress-interval
7241 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7242 (count-lines (point-min) end) 0)))
7244 (setq end (point-marker))
7246 (while (< (point) end)
7247 ;; is argument list opening?
7248 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7249 (point) (vhdl-point 'eol)))))
7250 ;; determine region for argument list
7251 (progn (goto-char cur-beg)
7253 (setq cur-end (point))
7254 (beginning-of-line 2))
7255 ;; determine region with same indent
7256 (setq indent (current-indentation))
7257 (setq cur-beg (point))
7258 (setq cur-end (vhdl-point 'bonl))
7259 (beginning-of-line 2)
7260 (while (and (< (point) end)
7261 (or (looking-at "^\\s-*\\(--.*\\)?$")
7262 (= (current-indentation) indent))
7264 (nth 0 (parse-partial-sexp
7265 (point) (vhdl-point 'eol)))) 0))
7266 (unless (looking-at "^\\s-*$")
7267 (setq cur-end (vhdl-point 'bonl)))
7268 (beginning-of-line 2)))
7270 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7271 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7272 (when vhdl-progress-interval (message "Aligning...done"))
7273 (setq vhdl-progress-info nil)))))
7275 (defun vhdl-align-group (&optional spacing)
7276 "Align group of lines between empty lines."
7278 (vhdl-do-group 'vhdl-align-region spacing))
7280 (defun vhdl-align-list (&optional spacing)
7281 "Align the lines of a list surrounded by a balanced group of parentheses."
7283 (vhdl-do-list 'vhdl-align-region-groups spacing))
7285 (defun vhdl-align-same-indent (&optional spacing)
7286 "Align block of lines with same indent."
7288 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7290 (defun vhdl-align-declarations (&optional spacing)
7291 "Align the lines within the declarative part of a design unit."
7294 (vhdl-prepare-search-2
7296 ;; search for declarative part
7297 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7298 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7300 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7301 (setq end (point)))))
7303 (vhdl-align-region-groups beg end spacing)
7304 (error "ERROR: Not within the declarative part of a design unit"))))
7306 (defun vhdl-align-buffer ()
7309 (vhdl-align-region (point-min) (point-max)))
7311 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7312 ;; Align inline comments
7314 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7315 "Align inline comments in region."
7317 (let ((start-max comment-column)
7319 comment-list start-list tmp-list start length
7320 cur-start prev-start no-code)
7321 (setq spacing (or spacing 2))
7322 (vhdl-prepare-search-2
7324 ;; search for comment start positions and lengths
7325 (while (< (point) end)
7326 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7327 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7328 (not (save-excursion (goto-char (match-beginning 2))
7329 (vhdl-in-literal))))
7330 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7331 (setq length (- (match-end 2) (match-beginning 2)))
7332 (setq start-max (max start start-max))
7333 (setq length-max (max length length-max))
7334 (setq comment-list (cons (cons start length) comment-list)))
7335 (beginning-of-line 2))
7337 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7338 ;; reduce start positions
7339 (setq start-list (list (caar comment-list)))
7340 (setq comment-list (cdr comment-list))
7342 (unless (or (= (caar comment-list) (car start-list))
7343 (<= (+ (car start-list) (cdar comment-list))
7344 end-comment-column))
7345 (setq start-list (cons (caar comment-list) start-list)))
7346 (setq comment-list (cdr comment-list)))
7347 ;; align lines as nicely as possible
7349 (while (< (point) end)
7350 (setq cur-start nil)
7351 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7352 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7353 (not (save-excursion
7354 (goto-char (match-beginning 3))
7355 (vhdl-in-literal))))
7356 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7357 (>= (- (match-end 2) (match-beginning 2))
7359 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7360 (setq length (- (match-end 3) (match-beginning 3)))
7361 (setq no-code (= (match-beginning 1) (match-end 1)))
7362 ;; insert minimum whitespace
7363 (goto-char (match-end 2))
7364 (delete-region (match-beginning 2) (match-end 2))
7365 (insert-char ?\ spacing)
7366 (setq tmp-list start-list)
7367 ;; insert additional whitespace to align
7370 ;; align comment-only line to inline comment of previous line
7371 ((and no-code prev-start
7372 (<= length (- end-comment-column prev-start)))
7374 ;; align all comments at `start-max' if this is possible
7375 ((<= (+ start-max length-max) end-comment-column)
7377 ;; align at `comment-column' if possible
7378 ((and (<= start comment-column)
7379 (<= length (- end-comment-column comment-column)))
7381 ;; align at left-most possible start position otherwise
7383 (while (and tmp-list (< (car tmp-list) start))
7384 (setq tmp-list (cdr tmp-list)))
7386 (indent-to cur-start))
7387 (setq prev-start cur-start)
7388 (beginning-of-line 2))))))
7390 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7391 "Align inline comments within a region. Groups of code lines separated by
7392 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7393 (interactive "r\nP")
7398 (setq orig (point-marker))
7401 (setq end (point-marker))
7403 (unless no-message (message "Aligning inline comments..."))
7405 (if (not vhdl-align-groups)
7406 ;; align entire region
7407 (vhdl-align-inline-comment-region-1 beg end spacing)
7409 (while (and (< beg end)
7410 (re-search-forward vhdl-align-group-separate end t))
7411 (setq pos (point-marker))
7412 (vhdl-align-inline-comment-region-1 beg pos spacing)
7417 (vhdl-align-inline-comment-region-1 beg end spacing)))
7418 (when vhdl-indent-tabs-mode
7420 (unless no-message (message "Aligning inline comments...done")))))
7422 (defun vhdl-align-inline-comment-group (&optional spacing)
7423 "Align inline comments within a group of lines between empty lines."
7426 (let ((start (point))
7428 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7429 (point-marker) (point-max)))
7431 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7432 (point) (point-min)))
7434 (message "Aligning inline comments...")
7435 (vhdl-align-inline-comment-region-1 beg end)
7436 (when vhdl-indent-tabs-mode
7438 (message "Aligning inline comments...done"))))
7440 (defun vhdl-align-inline-comment-buffer ()
7441 "Align inline comments within buffer. Groups of code lines separated by
7442 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7444 (vhdl-align-inline-comment-region (point-min) (point-max)))
7446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7449 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7450 "Fixup whitespace in region. Surround operator symbols by one space,
7451 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7452 end of line, do nothing in comments and strings."
7454 (unless no-message (message "Fixing up whitespace..."))
7457 (setq end (point-marker))
7458 ;; have no space before and one space after `,' and ';'
7460 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7461 (if (match-string 1)
7462 (goto-char (match-end 1))
7463 (replace-match "\\3 " nil nil nil 3)))
7464 ;; have no space after `('
7466 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\((\\)\\s-+" end t)
7467 (if (match-string 1)
7468 (goto-char (match-end 1))
7469 (replace-match "\\2")))
7470 ;; have no space before `)'
7472 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7473 (if (match-string 1)
7474 (goto-char (match-end 1))
7475 (replace-match "\\2")))
7476 ;; surround operator symbols by one space
7478 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7479 (if (match-string 1)
7480 (goto-char (match-end 1))
7481 (replace-match "\\3 \\4 \\5")
7482 (goto-char (match-end 4))))
7483 ;; eliminate multiple spaces and spaces at end of line
7485 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7486 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7487 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7488 (progn (replace-match "" nil nil) t))
7489 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7490 (progn (replace-match ";" nil nil) t))
7491 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7492 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7493 (progn (replace-match " " nil nil) t))
7494 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7495 (progn (replace-match " " nil nil) t))
7496 (re-search-forward "[^ \t-]+" end t))))
7497 (unless no-message (message "Fixing up whitespace...done")))
7499 (defun vhdl-fixup-whitespace-buffer ()
7500 "Fixup whitespace in buffer. Surround operator symbols by one space,
7501 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7502 end of line, do nothing in comments."
7504 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7506 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7509 (defun vhdl-beautify-region (beg end)
7510 "Beautify region by applying indentation, whitespace fixup, alignment, and
7511 case fixing to a region. Calls functions `vhdl-indent-buffer',
7512 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7513 `vhdl-fix-case-buffer'."
7515 (setq end (save-excursion (goto-char end) (point-marker)))
7516 (vhdl-indent-region beg end nil)
7517 (let ((vhdl-align-groups t))
7518 (vhdl-align-region beg end))
7519 (vhdl-fix-case-region beg end))
7521 (defun vhdl-beautify-buffer ()
7522 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7523 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7526 (vhdl-beautify-region (point-min) (point-max))
7527 (when noninteractive (save-buffer)))
7529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7532 (defun vhdl-fill-region (beg end &optional arg)
7533 "Fill lines for a region of code."
7534 (interactive "r\np")
7537 (let ((margin (if interactive (current-indentation) (current-column))))
7539 (setq end (point-marker))
7540 ;; remove inline comments, newlines and whitespace
7541 (vhdl-comment-kill-region beg end)
7542 (vhdl-comment-kill-inline-region beg end)
7543 (subst-char-in-region beg (1- end) ?\n ?\ )
7544 (vhdl-fixup-whitespace-region beg end)
7545 ;; wrap and end-comment-column
7547 (while (re-search-forward "\\s-" end t)
7548 (when(> (current-column) vhdl-end-comment-column)
7550 (when (re-search-backward "\\s-" beg t)
7551 (replace-match "\n")
7552 (indent-to margin)))))))
7554 (defun vhdl-fill-group ()
7555 "Fill group of lines between empty lines."
7557 (vhdl-do-group 'vhdl-fill-region))
7559 (defun vhdl-fill-list ()
7560 "Fill the lines of a list surrounded by a balanced group of parentheses."
7562 (vhdl-do-list 'vhdl-fill-region))
7564 (defun vhdl-fill-same-indent ()
7565 "Fill the lines of block of lines with same indent."
7567 (vhdl-do-same-indent 'vhdl-fill-region))
7570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7571 ;;; Code updating/fixing
7572 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7574 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7575 ;; Sensitivity list update
7578 ;; - no sensitivity list is generated for processes with wait statements
7579 ;; - otherwise, do the following:
7580 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7581 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7582 ;; manually entered global signals)
7583 ;; 3. signals from 1. and 2. form the list of visible signals
7584 ;; 4. search for if/elsif conditions containing an event (sequential code)
7585 ;; 5. scan for strings that are within syntactical regions where signals are
7586 ;; read but not within sequential code, and that correspond to visible
7588 ;; 6. replace sensitivity list by list of signals from 5.
7590 (defun vhdl-update-sensitivity-list-process ()
7591 "Update sensitivity list of current process."
7594 (vhdl-prepare-search-2
7596 ;; look whether in process
7597 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7598 (equal (upcase (match-string 2)) "PROCESS")
7599 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7600 (error "ERROR: Not within a process")
7601 (message "Updating sensitivity list...")
7602 (vhdl-update-sensitivity-list)
7603 (message "Updating sensitivity list...done")))))
7605 (defun vhdl-update-sensitivity-list-buffer ()
7606 "Update sensitivity list of all processes in current buffer."
7609 (vhdl-prepare-search-2
7610 (goto-char (point-min))
7611 (message "Updating sensitivity lists...")
7612 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7613 (goto-char (match-beginning 0))
7614 (condition-case nil (vhdl-update-sensitivity-list) (error)))
7615 (message "Updating sensitivity lists...done"))))
7617 (defun vhdl-update-sensitivity-list ()
7618 "Update sensitivity list."
7619 (let ((proc-beg (point))
7620 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7621 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7624 ;; search for wait statement (no sensitivity list allowed)
7625 ((progn (goto-char proc-mid)
7626 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7627 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7628 ;; combinational process (update sensitivity list)
7631 ;; scan for visible signals
7632 ((visible-list (vhdl-get-visible-signals))
7633 ;; define syntactic regions where signals are read
7635 '(;; right-hand side of signal/variable assignment
7636 ;; (special case: "<=" is relational operator in a condition)
7637 ((re-search-forward "[<:]=" proc-end t)
7638 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7640 ((re-search-forward "^\\s-*if\\>" proc-end t)
7641 (re-search-forward "\\<then\\>" proc-end t))
7643 ((re-search-forward "\\<elsif\\>" proc-end t)
7644 (re-search-forward "\\<then\\>" proc-end t))
7645 ;; while loop condition
7646 ((re-search-forward "^\\s-*while\\>" proc-end t)
7647 (re-search-forward "\\<loop\\>" proc-end t))
7648 ;; exit/next condition
7649 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7650 (re-search-forward ";" proc-end t))
7652 ((re-search-forward "\\<assert\\>" proc-end t)
7653 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7655 ((re-search-forward "^\\s-*case\\>" proc-end t)
7656 (re-search-forward "\\<is\\>" proc-end t))
7657 ;; parameter list of procedure call
7658 ((re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7659 (progn (backward-char) (forward-sexp) (point)))))
7660 name read-list sens-list signal-list
7661 sens-beg sens-end beg end margin)
7662 ;; scan for signals in old sensitivity list
7663 (goto-char proc-beg)
7664 (re-search-forward "\\<process\\>" proc-mid t)
7665 (if (not (looking-at "[ \t\n]*("))
7666 (setq sens-beg (point))
7667 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7668 (goto-char (match-end 1))
7670 (setq sens-end (1- (point)))
7671 (goto-char sens-beg)
7672 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7674 (cons (downcase (match-string 0)) sens-list))
7675 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7676 (setq signal-list (append visible-list sens-list))
7677 ;; search for sequential parts
7678 (goto-char proc-mid)
7679 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7680 (setq end (re-search-forward "\\<then\\>" proc-end t))
7681 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7685 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7686 (beginning-of-line)))
7687 ;; scan for signals read in process
7688 (while scan-regions-list
7689 (goto-char proc-mid)
7690 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7691 (setq end (eval (nth 1 (car scan-regions-list)))))
7693 (unless (or (vhdl-in-literal)
7694 (and seq-region-list
7695 (let ((tmp-list seq-region-list))
7696 (while (and tmp-list
7697 (< (point) (caar tmp-list)))
7698 (setq tmp-list (cdr tmp-list)))
7699 (and tmp-list (< (point) (cdar tmp-list))))))
7700 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>" end t)
7701 (setq name (match-string 1))
7702 (when (member (downcase name) signal-list)
7703 (add-to-list 'read-list name)))))
7704 (setq scan-regions-list (cdr scan-regions-list)))
7705 ;; update sensitivity list
7706 (goto-char sens-beg)
7708 (delete-region sens-beg sens-end)
7710 (insert " ()") (backward-char)))
7711 (setq read-list (sort read-list 'string<))
7713 (setq margin (current-column))
7714 (insert (car read-list))
7715 (setq read-list (cdr read-list))
7718 (if (<= (+ (current-column) (length (car read-list)) 2)
7721 (insert "\n") (indent-to margin))
7722 (insert (car read-list))
7723 (setq read-list (cdr read-list)))))))))
7725 (defun vhdl-get-visible-signals ()
7726 "Get all signals visible in the current block."
7728 (let (beg end signal-list entity-name file-name)
7729 ;; search for signals declared in surrounding block declarative parts
7731 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7733 (goto-char (match-end 2))
7734 (vhdl-backward-sexp)
7735 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7737 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7738 ;; scan for all declared signal names
7740 (while (re-search-forward "^\\s-*signal\\>" end t)
7741 (while (and (not (looking-at "[ \t\n]*:"))
7742 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7744 (cons (downcase (match-string 1)) signal-list))))
7746 ;; search for signals declared in architecture declarative part
7747 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7748 (not (equal "END" (upcase (match-string 1))))
7749 (setq entity-name (match-string 2))
7750 (setq end (re-search-forward "^begin\\>" nil t))))
7751 (error "ERROR: No architecture declarative part found")
7752 ;; scan for all declared signal names
7754 (while (re-search-forward "^\\s-*signal\\>" end t)
7755 (while (and (not (looking-at "[ \t\n]*:"))
7756 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7758 (cons (downcase (match-string 1)) signal-list)))))
7759 ;; search for signals declared in entity port clause
7760 (goto-char (point-min))
7761 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7763 (concat (vhdl-replace-string vhdl-entity-file-name entity-name)
7764 "." (file-name-extension (buffer-file-name)))))
7767 (vhdl-prepare-search-2
7768 (goto-char (point-min))
7769 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7770 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7771 (when (setq beg (re-search-forward
7772 "^\\s-*port[ \t\n]*("
7774 (re-search-forward "^end\\>" nil t)) t))
7775 (setq end (save-excursion
7776 (backward-char) (forward-sexp) (point)))
7777 (vhdl-forward-syntactic-ws)
7778 (while (< (point) end)
7779 (while (and (not (looking-at "[ \t\n]*:"))
7780 (re-search-forward "[ \t\n,]*\\(\\w+\\)" end t))
7782 (cons (downcase (match-string 1)) signal-list)))
7783 (re-search-forward ";" end 1)
7784 (vhdl-forward-syntactic-ws))))))
7787 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7788 ;; Generic/port clause fixing
7790 (defun vhdl-fix-clause ()
7791 "Fix closing parenthesis within generic/port clause."
7794 (vhdl-prepare-search-2
7797 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7798 (error "ERROR: Not within a generic/port clause")
7799 ;; search for end of clause
7800 (goto-char (match-end 0))
7801 (setq beg (1- (point)))
7802 (vhdl-forward-syntactic-ws)
7803 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7804 (goto-char (1- (match-end 0)))
7805 (setq end (point-marker))
7807 (vhdl-forward-syntactic-ws))
7809 (when (> pos (save-excursion (end-of-line) (point)))
7810 (error "ERROR: Not within a generic/port clause"))
7811 ;; delete closing parenthesis on separate line (not supported style)
7812 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7814 (vhdl-backward-syntactic-ws)
7815 (setq end (point-marker))
7817 ;; delete superfluous parentheses
7818 (while (progn (goto-char beg)
7819 (condition-case () (forward-sexp)
7820 (error (goto-char (point-max))))
7822 (delete-backward-char 1))
7823 ;; add closing parenthesis
7824 (when (> (point) end)
7828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7831 (defun vhdl-remove-trailing-spaces ()
7832 "Remove trailing spaces in the whole buffer."
7836 (goto-char (point-min))
7837 (while (re-search-forward "[ \t]+$" (point-max) t)
7838 (unless (vhdl-in-literal)
7839 (replace-match "" nil nil))))))
7842 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7846 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
7847 "Syntax of prompt inserted by template generators.")
7849 (defvar vhdl-template-invoked-by-hook nil
7850 "Indicates whether a template has been invoked by a hook or by key or menu.
7851 Used for undoing after template abortion.")
7853 ;; correct different behavior of function `unread-command-events' in XEmacs
7854 (defun vhdl-character-to-event (arg))
7855 (defalias 'vhdl-character-to-event
7856 (if vhdl-xemacs 'character-to-event 'identity))
7858 (defun vhdl-work-library ()
7859 "Return the working library name of the current project or \"work\" if no
7860 project is defined."
7861 (vhdl-resolve-env-variable
7862 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
7864 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7865 ;; Enabling/disabling
7867 (defun vhdl-mode-line-update ()
7868 "Update the modeline string for VHDL major mode."
7869 (setq mode-name (concat "VHDL"
7870 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
7871 (and vhdl-electric-mode "e")
7872 (and vhdl-stutter-mode "s")))
7873 (force-mode-line-update t))
7875 (defun vhdl-electric-mode (arg)
7876 "Toggle VHDL electric mode.
7877 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7879 (setq vhdl-electric-mode
7880 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
7881 ((> arg 0) t) (t nil)))
7882 (vhdl-mode-line-update))
7884 (defun vhdl-stutter-mode (arg)
7885 "Toggle VHDL stuttering mode.
7886 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7888 (setq vhdl-stutter-mode
7889 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
7890 ((> arg 0) t) (t nil)))
7891 (vhdl-mode-line-update))
7893 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7896 (defun vhdl-electric-dash (count)
7897 "-- starts a comment, --- draws a horizontal line,
7898 ---- starts a display comment"
7900 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
7902 ((and abbrev-start-location (= abbrev-start-location (point)))
7903 (setq abbrev-start-location nil)
7904 (goto-char last-abbrev-location)
7905 (beginning-of-line nil)
7906 (vhdl-comment-display))
7907 ((/= (preceding-char) ?-) ; standard dash (minus)
7908 (self-insert-command count))
7909 (t (self-insert-command count)
7910 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
7911 (let ((next-input (read-char)))
7912 (if (= next-input ?-) ; triple dash
7914 (vhdl-comment-display-line)
7916 "Enter '-' for display comment, else continue coding")
7917 (let ((next-input (read-char)))
7918 (if (= next-input ?-) ; four dashes
7919 (vhdl-comment-display t)
7920 (setq unread-command-events ; pushback the char
7921 (list (vhdl-character-to-event next-input))))))
7922 (setq unread-command-events ; pushback the char
7923 (list (vhdl-character-to-event next-input)))
7924 (vhdl-comment-insert)))))
7925 (self-insert-command count)))
7927 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
7929 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7930 (if (= (preceding-char) ?\()
7931 (progn (delete-char -1) (insert-char ?\[ 1))
7932 (insert-char ?\( 1))
7933 (self-insert-command count)))
7935 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
7937 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7939 (if (= (preceding-char) ?\))
7940 (progn (delete-char -1) (insert-char ?\] 1))
7941 (insert-char ?\) 1))
7942 (blink-matching-open))
7943 (self-insert-command count)))
7945 (defun vhdl-electric-quote (count) "'' --> \""
7947 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7948 (if (= (preceding-char) last-input-char)
7949 (progn (delete-backward-char 1) (insert-char ?\" 1))
7950 (insert-char ?\' 1))
7951 (self-insert-command count)))
7953 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
7955 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7956 (cond ((= (preceding-char) last-input-char)
7957 (progn (delete-char -1)
7958 (unless (eq (preceding-char) ? ) (insert " "))
7960 (setq this-command 'vhdl-electric-colon)))
7962 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
7963 (progn (delete-char -1) (insert "= ")))
7964 (t (insert-char ?\; 1)))
7965 (self-insert-command count)))
7967 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
7969 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7970 (cond ((= (preceding-char) last-input-char)
7971 (progn (delete-char -1)
7972 (unless (eq (preceding-char) ? ) (insert " "))
7974 (t (insert-char ?\, 1)))
7975 (self-insert-command count)))
7977 (defun vhdl-electric-period (count) "'..' --> ' => '"
7979 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7980 (cond ((= (preceding-char) last-input-char)
7981 (progn (delete-char -1)
7982 (unless (eq (preceding-char) ? ) (insert " "))
7984 (t (insert-char ?\. 1)))
7985 (self-insert-command count)))
7987 (defun vhdl-electric-equal (count) "'==' --> ' == '"
7989 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7990 (cond ((= (preceding-char) last-input-char)
7991 (progn (delete-char -1)
7992 (unless (eq (preceding-char) ? ) (insert " "))
7994 (t (insert-char ?\= 1)))
7995 (self-insert-command count)))
7997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8000 (defun vhdl-template-paired-parens ()
8001 "Insert a pair of round parentheses, placing point between them."
8006 (defun vhdl-template-alias ()
8007 "Insert alias declaration."
8009 (let ((start (point)))
8010 (vhdl-insert-keyword "ALIAS ")
8011 (when (vhdl-template-field "name" nil t start (point))
8013 (unless (vhdl-template-field
8014 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8016 (delete-backward-char 3))
8017 (vhdl-insert-keyword " IS ")
8018 (vhdl-template-field "name" ";")
8019 (vhdl-comment-insert-inline))))
8021 (defun vhdl-template-architecture ()
8022 "Insert architecture."
8024 (let ((margin (current-indentation))
8027 (vhdl-insert-keyword "ARCHITECTURE ")
8028 (when (setq arch-name
8029 (vhdl-template-field "name" nil t start (point)))
8030 (vhdl-insert-keyword " OF ")
8032 (vhdl-prepare-search-1
8033 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8034 (insert (match-string 1))
8035 (vhdl-template-field "entity name"))
8036 (vhdl-insert-keyword " IS\n")
8037 (vhdl-template-begin-end
8038 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8039 (memq vhdl-insert-empty-lines '(unit all))))))
8041 (defun vhdl-template-array (kind &optional secondary)
8042 "Insert array type definition."
8044 (let ((start (point)))
8045 (vhdl-insert-keyword "ARRAY (")
8046 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8048 (vhdl-insert-keyword ") OF ")
8049 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8050 (vhdl-insert-keyword ";"))))
8052 (defun vhdl-template-assert ()
8053 "Insert an assertion statement."
8055 (let ((start (point)))
8056 (vhdl-insert-keyword "ASSERT ")
8057 (when vhdl-conditions-in-parenthesis (insert "("))
8058 (when (vhdl-template-field "condition (negated)" nil t start (point))
8059 (when vhdl-conditions-in-parenthesis (insert ")"))
8060 (setq start (point))
8061 (vhdl-insert-keyword " REPORT ")
8062 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8063 (delete-region start (point)))
8064 (setq start (point))
8065 (vhdl-insert-keyword " SEVERITY ")
8066 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8067 (delete-region start (point)))
8070 (defun vhdl-template-attribute ()
8071 "Insert an attribute declaration or specification."
8073 (if (eq (vhdl-decision-query
8074 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8075 (vhdl-template-attribute-spec)
8076 (vhdl-template-attribute-decl)))
8078 (defun vhdl-template-attribute-decl ()
8079 "Insert an attribute declaration."
8081 (let ((start (point)))
8082 (vhdl-insert-keyword "ATTRIBUTE ")
8083 (when (vhdl-template-field "name" " : " t start (point))
8084 (vhdl-template-field "type" ";")
8085 (vhdl-comment-insert-inline))))
8087 (defun vhdl-template-attribute-spec ()
8088 "Insert an attribute specification."
8090 (let ((start (point)))
8091 (vhdl-insert-keyword "ATTRIBUTE ")
8092 (when (vhdl-template-field "name" nil t start (point))
8093 (vhdl-insert-keyword " OF ")
8094 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8095 (vhdl-template-field "entity class")
8096 (vhdl-insert-keyword " IS ")
8097 (vhdl-template-field "expression" ";"))))
8099 (defun vhdl-template-block ()
8102 (let ((margin (current-indentation))
8105 (vhdl-insert-keyword ": BLOCK ")
8107 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8111 (if (vhdl-template-field "[guard expression]" nil t)
8114 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8116 (vhdl-template-begin-end "BLOCK" label margin)
8117 (vhdl-comment-block))))
8119 (defun vhdl-template-block-configuration ()
8120 "Insert a block configuration statement."
8122 (let ((margin (current-indentation))
8124 (vhdl-insert-keyword "FOR ")
8125 (when (vhdl-template-field "block name" nil t start (point))
8126 (vhdl-insert-keyword "\n\n")
8128 (vhdl-insert-keyword "END FOR;")
8130 (indent-to (+ margin vhdl-basic-offset)))))
8132 (defun vhdl-template-break ()
8133 "Insert a break statement."
8136 (vhdl-insert-keyword "BREAK")
8137 (setq position (point))
8140 (progn (vhdl-insert-keyword "FOR ")
8141 (if (vhdl-template-field "[quantity name]" " USE " t)
8142 (progn (vhdl-template-field "quantity name" " => ") t)
8143 (kill-word -1) nil))
8144 (vhdl-template-field "[quantity name]" " => " t))
8145 (vhdl-template-field "expression")
8146 (setq position (point))
8148 (delete-region position (point))
8149 (unless (vhdl-sequential-statement-p)
8150 (vhdl-insert-keyword " ON ")
8151 (if (vhdl-template-field "[sensitivity list]" nil t)
8152 (setq position (point))
8153 (delete-region position (point))))
8154 (vhdl-insert-keyword " WHEN ")
8155 (when vhdl-conditions-in-parenthesis (insert "("))
8156 (if (vhdl-template-field "[condition]" nil t)
8157 (when vhdl-conditions-in-parenthesis (insert ")"))
8158 (delete-region position (point)))
8161 (defun vhdl-template-case (&optional kind)
8162 "Insert a case statement."
8164 (let ((margin (current-indentation))
8167 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8168 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8169 (vhdl-insert-keyword "CASE ")
8170 (vhdl-insert-keyword ": CASE ")
8172 (setq label (vhdl-template-field "[label]" nil t))
8173 (unless label (delete-char 2))
8176 (when (vhdl-template-field "expression" nil t start (point))
8177 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8179 (vhdl-insert-keyword "END CASE")
8180 (when label (insert " " label))
8183 (indent-to (+ margin vhdl-basic-offset))
8184 (vhdl-insert-keyword "WHEN ")
8185 (let ((position (point)))
8187 (indent-to (+ margin vhdl-basic-offset))
8188 (vhdl-insert-keyword "WHEN OTHERS => null;")
8189 (goto-char position)))))
8191 (defun vhdl-template-case-is ()
8192 "Insert a sequential case statement."
8194 (vhdl-template-case 'is))
8196 (defun vhdl-template-case-use ()
8197 "Insert a simultaneous case statement."
8199 (vhdl-template-case 'use))
8201 (defun vhdl-template-component ()
8202 "Insert a component declaration."
8204 (vhdl-template-component-decl))
8206 (defun vhdl-template-component-conf ()
8207 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8208 since these are almost equivalent)."
8210 (let ((margin (current-indentation))
8211 (result (vhdl-template-configuration-spec t)))
8215 (vhdl-insert-keyword "END FOR;")
8216 (when (eq result 'no-use)
8217 (end-of-line -0)))))
8219 (defun vhdl-template-component-decl ()
8220 "Insert a component declaration."
8222 (let ((margin (current-indentation))
8225 (vhdl-insert-keyword "COMPONENT ")
8226 (when (setq name (vhdl-template-field "name" nil t start (point)))
8227 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8230 (vhdl-insert-keyword "END COMPONENT")
8231 (unless (vhdl-standard-p '87) (insert " " name))
8233 (setq end-column (current-column))
8235 (indent-to (+ margin vhdl-basic-offset))
8236 (vhdl-template-generic-list t t)
8238 (indent-to (+ margin vhdl-basic-offset))
8239 (vhdl-template-port-list t)
8240 (beginning-of-line 2)
8241 (forward-char end-column))))
8243 (defun vhdl-template-component-inst ()
8244 "Insert a component instantiation statement."
8246 (let ((margin (current-indentation))
8249 (when (vhdl-template-field "instance label" nil t start (point))
8251 (if (not (vhdl-use-direct-instantiation))
8252 (vhdl-template-field "component name")
8253 ;; direct instantiation
8254 (setq unit (vhdl-template-field
8255 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8256 (setq unit (upcase (or unit "")))
8257 (cond ((equal unit "ENTITY")
8258 (vhdl-template-field "library name" "." nil nil nil nil
8259 (vhdl-work-library))
8260 (vhdl-template-field "entity name" "(")
8261 (if (vhdl-template-field "[architecture name]" nil t)
8264 ((equal unit "CONFIGURATION")
8265 (vhdl-template-field "library name" "." nil nil nil nil
8266 (vhdl-work-library))
8267 (vhdl-template-field "configuration name"))
8268 (t (vhdl-template-field "component name"))))
8270 (indent-to (+ margin vhdl-basic-offset))
8271 (setq position (point))
8272 (vhdl-insert-keyword "GENERIC ")
8273 (when (vhdl-template-map position t t)
8275 (indent-to (+ margin vhdl-basic-offset)))
8276 (setq position (point))
8277 (vhdl-insert-keyword "PORT ")
8278 (unless (vhdl-template-map position t t)
8283 (defun vhdl-template-conditional-signal-asst ()
8284 "Insert a conditional signal assignment."
8286 (when (vhdl-template-field "target signal")
8288 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8290 (let ((margin (current-column))
8293 (vhdl-template-field "waveform")
8294 (setq position (point))
8295 (vhdl-insert-keyword " WHEN ")
8296 (when vhdl-conditions-in-parenthesis (insert "("))
8297 (while (and (vhdl-template-field "[condition]" nil t)
8299 (when vhdl-conditions-in-parenthesis (insert ")"))
8300 (setq position (point))
8301 (vhdl-insert-keyword " ELSE")
8304 (vhdl-template-field "[waveform]" nil t)))
8305 (setq position (point))
8306 (vhdl-insert-keyword " WHEN ")
8307 (when vhdl-conditions-in-parenthesis (insert "(")))
8308 (delete-region position (point))
8310 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8312 (defun vhdl-template-configuration ()
8313 "Insert a configuration specification if within an architecture,
8314 a block or component configuration if within a configuration declaration,
8315 a configuration declaration if not within a design unit."
8317 (vhdl-prepare-search-1
8319 ((and (save-excursion ; architecture body
8320 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8321 (equal "ARCHITECTURE" (upcase (match-string 1))))
8322 (vhdl-template-configuration-spec))
8323 ((and (save-excursion ; configuration declaration
8324 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8325 (equal "CONFIGURATION" (upcase (match-string 1))))
8326 (if (eq (vhdl-decision-query
8327 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8328 (vhdl-template-component-conf)
8329 (vhdl-template-block-configuration)))
8330 (t (vhdl-template-configuration-decl))))) ; otherwise
8332 (defun vhdl-template-configuration-spec (&optional optional-use)
8333 "Insert a configuration specification."
8335 (let ((margin (current-indentation))
8338 (vhdl-insert-keyword "FOR ")
8339 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8341 (vhdl-template-field "component name" "\n")
8342 (indent-to (+ margin vhdl-basic-offset))
8343 (setq start (point))
8344 (vhdl-insert-keyword "USE ")
8345 (if (and optional-use
8346 (not (setq aspect (vhdl-template-field
8347 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8348 (progn (delete-region start (point)) 'no-use)
8349 (unless optional-use
8350 (setq aspect (vhdl-template-field
8351 "ENTITY | CONFIGURATION | OPEN" " ")))
8352 (setq aspect (upcase (or aspect "")))
8353 (cond ((equal aspect "ENTITY")
8354 (vhdl-template-field "library name" "." nil nil nil nil
8355 (vhdl-work-library))
8356 (vhdl-template-field "entity name" "(")
8357 (if (vhdl-template-field "[architecture name]" nil t)
8361 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8362 (setq position (point))
8363 (vhdl-insert-keyword "GENERIC ")
8364 (when (vhdl-template-map position t t)
8366 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8367 (setq position (point))
8368 (vhdl-insert-keyword "PORT ")
8369 (unless (vhdl-template-map position t t)
8374 ((equal aspect "CONFIGURATION")
8375 (vhdl-template-field "library name" "." nil nil nil nil
8376 (vhdl-work-library))
8377 (vhdl-template-field "configuration name" ";"))
8378 (t (delete-backward-char 1) (insert ";") t))))))
8381 (defun vhdl-template-configuration-decl ()
8382 "Insert a configuration declaration."
8384 (let ((margin (current-indentation))
8386 entity-exists string name position)
8387 (vhdl-insert-keyword "CONFIGURATION ")
8388 (when (setq name (vhdl-template-field "name" nil t start (point)))
8389 (vhdl-insert-keyword " OF ")
8391 (vhdl-prepare-search-1
8392 (setq entity-exists (vhdl-re-search-backward
8393 "\\<entity \\(\\w*\\) is\\>" nil t))
8394 (setq string (match-string 1))))
8395 (if (and entity-exists (not (equal string "")))
8397 (vhdl-template-field "entity name"))
8398 (vhdl-insert-keyword " IS\n")
8399 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8400 (indent-to (+ margin vhdl-basic-offset))
8401 (setq position (point))
8403 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8405 (vhdl-insert-keyword "END ")
8406 (unless (vhdl-standard-p '87)
8407 (vhdl-insert-keyword "CONFIGURATION "))
8409 (goto-char position))))
8411 (defun vhdl-template-constant ()
8412 "Insert a constant declaration."
8414 (let ((start (point))
8415 (in-arglist (vhdl-in-argument-list-p)))
8416 (vhdl-insert-keyword "CONSTANT ")
8417 (when (vhdl-template-field "name" nil t start (point))
8419 (when in-arglist (vhdl-insert-keyword "IN "))
8420 (vhdl-template-field "type")
8423 (vhdl-comment-insert-inline))
8424 (let ((position (point)))
8426 (unless (vhdl-template-field "[initialization]" nil t)
8427 (delete-region position (point)))
8429 (vhdl-comment-insert-inline))))))
8431 (defun vhdl-template-default ()
8440 (defun vhdl-template-default-indent ()
8441 "Insert nothing and indent."
8448 (indent-according-to-mode))
8450 (defun vhdl-template-disconnect ()
8451 "Insert a disconnect statement."
8453 (let ((start (point)))
8454 (vhdl-insert-keyword "DISCONNECT ")
8455 (when (vhdl-template-field "signal names | OTHERS | ALL"
8456 " : " t start (point))
8457 (vhdl-template-field "type")
8458 (vhdl-insert-keyword " AFTER ")
8459 (vhdl-template-field "time expression" ";"))))
8461 (defun vhdl-template-else ()
8462 "Insert an else statement."
8465 (vhdl-prepare-search-1
8466 (vhdl-insert-keyword "ELSE")
8467 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8468 (equal "WHEN" (upcase (match-string 1))))
8470 (indent-according-to-mode)
8471 (setq margin (current-indentation))
8473 (indent-to (+ margin vhdl-basic-offset))))))
8475 (defun vhdl-template-elsif ()
8476 "Insert an elsif statement."
8478 (let ((start (point))
8480 (vhdl-insert-keyword "ELSIF ")
8481 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8482 (when vhdl-conditions-in-parenthesis (insert "("))
8483 (when (vhdl-template-field "condition" nil t start (point))
8484 (when vhdl-conditions-in-parenthesis (insert ")"))
8485 (indent-according-to-mode)
8486 (setq margin (current-indentation))
8487 (vhdl-insert-keyword
8488 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8489 (indent-to (+ margin vhdl-basic-offset))))))
8491 (defun vhdl-template-entity ()
8494 (let ((margin (current-indentation))
8497 (vhdl-insert-keyword "ENTITY ")
8498 (when (setq name (vhdl-template-field "name" nil t start (point)))
8499 (vhdl-insert-keyword " IS\n\n")
8501 (vhdl-insert-keyword "END ")
8502 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8504 (setq end-column (current-column))
8506 (indent-to (+ margin vhdl-basic-offset))
8507 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8508 (indent-to (+ margin vhdl-basic-offset))
8509 (when (vhdl-template-generic-list t)
8510 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8512 (indent-to (+ margin vhdl-basic-offset))
8513 (when (vhdl-template-port-list t)
8514 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8515 (beginning-of-line 2)
8516 (forward-char end-column))))
8518 (defun vhdl-template-exit ()
8519 "Insert an exit statement."
8521 (let ((start (point)))
8522 (vhdl-insert-keyword "EXIT ")
8523 (if (vhdl-template-field "[loop label]" nil t start (point))
8524 (let ((position (point)))
8525 (vhdl-insert-keyword " WHEN ")
8526 (when vhdl-conditions-in-parenthesis (insert "("))
8527 (if (vhdl-template-field "[condition]" nil t)
8528 (when vhdl-conditions-in-parenthesis (insert ")"))
8529 (delete-region position (point))))
8533 (defun vhdl-template-file ()
8534 "Insert a file declaration."
8536 (let ((start (point)))
8537 (vhdl-insert-keyword "FILE ")
8538 (when (vhdl-template-field "name" nil t start (point))
8540 (vhdl-template-field "type")
8541 (unless (vhdl-standard-p '87)
8542 (vhdl-insert-keyword " OPEN ")
8543 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8545 (delete-backward-char 6)))
8546 (vhdl-insert-keyword " IS ")
8547 (when (vhdl-standard-p '87)
8548 (vhdl-template-field "[IN | OUT]" " " t))
8549 (vhdl-template-field "filename-string" nil nil nil nil t)
8551 (vhdl-comment-insert-inline))))
8553 (defun vhdl-template-for ()
8554 "Insert a block or component configuration if within a configuration
8555 declaration, a configuration specification if within an architecture
8556 declarative part (and not within a subprogram), a for-loop if within a
8557 sequential statement part (subprogram or process), and a for-generate
8560 (vhdl-prepare-search-1
8562 ((vhdl-sequential-statement-p) ; sequential statement
8563 (vhdl-template-for-loop))
8564 ((and (save-excursion ; configuration declaration
8565 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8566 (equal "CONFIGURATION" (upcase (match-string 1))))
8567 (if (eq (vhdl-decision-query
8568 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8569 (vhdl-template-component-conf)
8570 (vhdl-template-block-configuration)))
8571 ((and (save-excursion
8572 (re-search-backward ; architecture declarative part
8573 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8574 (equal "ARCHITECTURE" (upcase (match-string 1))))
8575 (vhdl-template-configuration-spec))
8576 (t (vhdl-template-for-generate))))) ; concurrent statement
8578 (defun vhdl-template-for-generate ()
8579 "Insert a for-generate."
8581 (let ((margin (current-indentation))
8584 (vhdl-insert-keyword ": FOR ")
8585 (setq position (point-marker))
8587 (when (setq label (vhdl-template-field "label" nil t start position))
8588 (goto-char position)
8589 (vhdl-template-field "loop variable")
8590 (vhdl-insert-keyword " IN ")
8591 (vhdl-template-field "range")
8592 (vhdl-template-generate-body margin label))))
8594 (defun vhdl-template-for-loop ()
8595 "Insert a for loop."
8597 (let ((margin (current-indentation))
8600 (if (not (eq vhdl-optional-labels 'all))
8601 (vhdl-insert-keyword "FOR ")
8602 (vhdl-insert-keyword ": FOR ")
8604 (setq label (vhdl-template-field "[label]" nil t))
8605 (unless label (delete-char 2))
8608 (when (setq index (vhdl-template-field "loop variable"
8609 nil t start (point)))
8610 (vhdl-insert-keyword " IN ")
8611 (vhdl-template-field "range")
8612 (vhdl-insert-keyword " LOOP\n\n")
8614 (vhdl-insert-keyword "END LOOP")
8616 (insert " " label ";")
8618 (when vhdl-self-insert-comments (insert " -- " index)))
8620 (indent-to (+ margin vhdl-basic-offset)))))
8622 (defun vhdl-template-function (&optional kind)
8623 "Insert a function declaration or body."
8625 (let ((margin (current-indentation))
8628 (vhdl-insert-keyword "FUNCTION ")
8629 (when (setq name (vhdl-template-field "name" nil t start (point)))
8630 (vhdl-template-argument-list t)
8631 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8634 (indent-to (+ margin vhdl-basic-offset))
8635 (vhdl-insert-keyword "RETURN ")
8636 (vhdl-template-field "type")
8637 (if (if kind (eq kind 'body)
8638 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8639 (progn (vhdl-insert-keyword " IS\n")
8640 (vhdl-template-begin-end
8641 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8642 (vhdl-comment-block))
8645 (defun vhdl-template-function-decl ()
8646 "Insert a function declaration."
8648 (vhdl-template-function 'decl))
8650 (defun vhdl-template-function-body ()
8651 "Insert a function declaration."
8653 (vhdl-template-function 'body))
8655 (defun vhdl-template-generate ()
8656 "Insert a generation scheme."
8658 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8659 (vhdl-template-if-generate)
8660 (vhdl-template-for-generate)))
8662 (defun vhdl-template-generic ()
8663 "Insert generic declaration, or generic map in instantiation statements."
8665 (let ((start (point)))
8666 (vhdl-prepare-search-1
8668 ((and (save-excursion ; entity declaration
8669 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8670 (equal "ENTITY" (upcase (match-string 1))))
8671 (vhdl-template-generic-list nil))
8672 ((or (save-excursion
8673 (or (beginning-of-line)
8674 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8675 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8676 (vhdl-insert-keyword "GENERIC ")
8677 (vhdl-template-map start))
8678 (t (vhdl-template-generic-list nil t))))))
8680 (defun vhdl-template-group ()
8681 "Insert group or group template declaration."
8683 (let ((start (point)))
8684 (if (eq (vhdl-decision-query
8685 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8686 (vhdl-template-group-template)
8687 (vhdl-template-group-decl))))
8689 (defun vhdl-template-group-decl ()
8690 "Insert group declaration."
8692 (let ((start (point)))
8693 (vhdl-insert-keyword "GROUP ")
8694 (when (vhdl-template-field "name" " : " t start (point))
8695 (vhdl-template-field "template name" " (")
8696 (vhdl-template-field "constituent list" ");")
8697 (vhdl-comment-insert-inline))))
8699 (defun vhdl-template-group-template ()
8700 "Insert group template declaration."
8702 (let ((start (point)))
8703 (vhdl-insert-keyword "GROUP ")
8704 (when (vhdl-template-field "template name" nil t start (point))
8705 (vhdl-insert-keyword " IS (")
8706 (vhdl-template-field "entity class list" ");")
8707 (vhdl-comment-insert-inline))))
8709 (defun vhdl-template-if ()
8710 "Insert a sequential if statement or an if-generate statement."
8712 (if (vhdl-sequential-statement-p)
8713 (vhdl-template-if-then)
8714 (if (and (vhdl-standard-p 'ams)
8715 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8716 (vhdl-template-if-use)
8717 (vhdl-template-if-generate))))
8719 (defun vhdl-template-if-generate ()
8720 "Insert an if-generate."
8722 (let ((margin (current-indentation))
8725 (vhdl-insert-keyword ": IF ")
8726 (setq position (point-marker))
8728 (when (setq label (vhdl-template-field "label" nil t start position))
8729 (goto-char position)
8730 (when vhdl-conditions-in-parenthesis (insert "("))
8731 (vhdl-template-field "condition")
8732 (when vhdl-conditions-in-parenthesis (insert ")"))
8733 (vhdl-template-generate-body margin label))))
8735 (defun vhdl-template-if-then-use (kind)
8736 "Insert a sequential if statement."
8738 (let ((margin (current-indentation))
8741 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8742 (vhdl-insert-keyword "IF ")
8743 (vhdl-insert-keyword ": IF ")
8745 (setq label (vhdl-template-field "[label]" nil t))
8746 (unless label (delete-char 2))
8749 (when vhdl-conditions-in-parenthesis (insert "("))
8750 (when (vhdl-template-field "condition" nil t start (point))
8751 (when vhdl-conditions-in-parenthesis (insert ")"))
8752 (vhdl-insert-keyword
8753 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8755 (vhdl-insert-keyword "END IF")
8756 (when label (insert " " label))
8759 (indent-to (+ margin vhdl-basic-offset)))))
8761 (defun vhdl-template-if-then ()
8762 "Insert a sequential if statement."
8764 (vhdl-template-if-then-use 'then))
8766 (defun vhdl-template-if-use ()
8767 "Insert a simultaneous if statement."
8769 (vhdl-template-if-then-use 'use))
8771 (defun vhdl-template-instance ()
8772 "Insert a component instantiation statement."
8774 (vhdl-template-component-inst))
8776 (defun vhdl-template-library ()
8777 "Insert a library specification."
8779 (let ((margin (current-indentation))
8782 (vhdl-insert-keyword "LIBRARY ")
8783 (when (setq name (vhdl-template-field "names" nil t start (point)))
8785 (unless (string-match "," name)
8786 (setq end-pos (point))
8789 (vhdl-insert-keyword "USE ")
8791 (vhdl-insert-keyword "..ALL;")
8793 (if (vhdl-template-field "package name")
8795 (delete-region end-pos (+ (point) 5)))))))
8797 (defun vhdl-template-limit ()
8800 (let ((start (point)))
8801 (vhdl-insert-keyword "LIMIT ")
8802 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8804 (vhdl-template-field "type")
8805 (vhdl-insert-keyword " WITH ")
8806 (vhdl-template-field "real expression" ";"))))
8808 (defun vhdl-template-loop ()
8811 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8813 (vhdl-template-while-loop))
8815 (vhdl-template-for-loop))
8816 (t (vhdl-template-bare-loop)))))
8818 (defun vhdl-template-bare-loop ()
8821 (let ((margin (current-indentation))
8824 (if (not (eq vhdl-optional-labels 'all))
8825 (vhdl-insert-keyword "LOOP ")
8826 (vhdl-insert-keyword ": LOOP ")
8828 (setq label (vhdl-template-field "[label]" nil t))
8829 (unless label (delete-char 2))
8834 (vhdl-insert-keyword "END LOOP")
8835 (insert (if label (concat " " label ";") ";"))
8837 (indent-to (+ margin vhdl-basic-offset))))
8839 (defun vhdl-template-map (&optional start optional secondary)
8840 "Insert a map specification with association list."
8842 (let ((start (or start (point)))
8844 (vhdl-insert-keyword "MAP (")
8845 (if (not vhdl-association-list-with-formals)
8846 (if (vhdl-template-field
8847 (concat (and optional "[") "association list" (and optional "]"))
8848 ")" (or (not secondary) optional)
8849 (and (not secondary) start) (point))
8851 (if (and optional secondary) (delete-region start (point)))
8853 (if vhdl-argument-list-indent
8854 (setq margin (current-column))
8855 (setq margin (+ (current-indentation) vhdl-basic-offset))
8858 (if (vhdl-template-field
8859 (concat (and optional "[") "formal" (and optional "]"))
8860 " => " (or (not secondary) optional)
8861 (and (not secondary) start) (point))
8863 (vhdl-template-field "actual" ",")
8864 (setq end-pos (point))
8867 (while (vhdl-template-field "[formal]" " => " t)
8868 (vhdl-template-field "actual" ",")
8869 (setq end-pos (point))
8872 (delete-region end-pos (point))
8873 (delete-backward-char 1)
8875 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8877 (when (and optional secondary) (delete-region start (point)))
8880 (defun vhdl-template-modify (&optional noerror)
8881 "Actualize modification date."
8883 (vhdl-prepare-search-2
8885 (goto-char (point-min))
8886 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
8887 (progn (delete-region (point) (progn (end-of-line) (point)))
8888 (vhdl-template-insert-date))
8890 (error (concat "ERROR: Modification date prefix string \""
8891 vhdl-modify-date-prefix-string "\" not found")))))))
8893 (defun vhdl-template-modify-noerror ()
8894 "Call `vhdl-template-modify' with NOERROR non-nil."
8895 (vhdl-template-modify t))
8897 (defun vhdl-template-nature ()
8898 "Insert a nature declaration."
8900 (let ((start (point))
8901 name mid-pos end-pos)
8902 (vhdl-insert-keyword "NATURE ")
8903 (when (setq name (vhdl-template-field "name" nil t start (point)))
8904 (vhdl-insert-keyword " IS ")
8907 (or (vhdl-template-field
8908 "across type | ARRAY | RECORD")
8910 (cond ((equal definition "")
8912 ((equal definition "ARRAY")
8914 (vhdl-template-array 'nature t))
8915 ((equal definition "RECORD")
8916 (setq mid-pos (point-marker))
8918 (vhdl-template-record 'nature name t))
8920 (vhdl-insert-keyword " ACROSS ")
8921 (vhdl-template-field "through type")
8922 (vhdl-insert-keyword " THROUGH ")
8923 (vhdl-template-field "reference name")
8924 (vhdl-insert-keyword " REFERENCE;")))
8926 (setq end-pos (point-marker))
8929 (vhdl-comment-insert-inline)
8930 (when end-pos (goto-char end-pos))))))
8932 (defun vhdl-template-next ()
8933 "Insert a next statement."
8935 (let ((start (point)))
8936 (vhdl-insert-keyword "NEXT ")
8937 (if (vhdl-template-field "[loop label]" nil t start (point))
8938 (let ((position (point)))
8939 (vhdl-insert-keyword " WHEN ")
8940 (when vhdl-conditions-in-parenthesis (insert "("))
8941 (if (vhdl-template-field "[condition]" nil t)
8942 (when vhdl-conditions-in-parenthesis (insert ")"))
8943 (delete-region position (point))))
8947 (defun vhdl-template-others ()
8948 "Insert an others aggregate."
8950 (let ((start (point)))
8951 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
8952 (progn (unless vhdl-template-invoked-by-hook (insert "("))
8953 (vhdl-insert-keyword "OTHERS => '")
8954 (when (vhdl-template-field "value" nil t start (point))
8956 (vhdl-insert-keyword "OTHERS "))))
8958 (defun vhdl-template-package (&optional kind)
8959 "Insert a package specification or body."
8961 (let ((margin (current-indentation))
8964 (vhdl-insert-keyword "PACKAGE ")
8965 (setq body (if kind (eq kind 'body)
8966 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
8968 (vhdl-insert-keyword "BODY ")
8969 (when (save-excursion
8970 (vhdl-prepare-search-1
8971 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
8972 (insert (setq name (match-string 1)))))
8974 (setq name (vhdl-template-field "name" nil t start (point))))
8975 (vhdl-insert-keyword " IS\n")
8976 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8977 (indent-to (+ margin vhdl-basic-offset))
8978 (setq position (point))
8980 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8982 (vhdl-insert-keyword "END ")
8983 (unless (vhdl-standard-p '87)
8984 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
8985 (insert (or name "") ";")
8986 (goto-char position))))
8988 (defun vhdl-template-package-decl ()
8989 "Insert a package specification."
8991 (vhdl-template-package 'decl))
8993 (defun vhdl-template-package-body ()
8994 "Insert a package body."
8996 (vhdl-template-package 'body))
8998 (defun vhdl-template-port ()
8999 "Insert a port declaration, or port map in instantiation statements."
9001 (let ((start (point)))
9002 (vhdl-prepare-search-1
9004 ((and (save-excursion ; entity declaration
9005 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9006 (equal "ENTITY" (upcase (match-string 1))))
9007 (vhdl-template-port-list nil))
9008 ((or (save-excursion
9009 (or (beginning-of-line)
9010 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9011 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9012 (vhdl-insert-keyword "PORT ")
9013 (vhdl-template-map start))
9014 (t (vhdl-template-port-list nil))))))
9016 (defun vhdl-template-procedural ()
9017 "Insert a procedural."
9019 (let ((margin (current-indentation))
9021 (case-fold-search t)
9023 (vhdl-insert-keyword "PROCEDURAL ")
9024 (when (memq vhdl-optional-labels '(process all))
9028 (setq label (vhdl-template-field "[label]" nil t))
9029 (unless label (delete-char 2))
9032 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9034 (vhdl-template-begin-end "PROCEDURAL" label margin)
9035 (vhdl-comment-block)))
9037 (defun vhdl-template-procedure (&optional kind)
9038 "Insert a procedure declaration or body."
9040 (let ((margin (current-indentation))
9043 (vhdl-insert-keyword "PROCEDURE ")
9044 (when (setq name (vhdl-template-field "name" nil t start (point)))
9045 (vhdl-template-argument-list)
9046 (if (if kind (eq kind 'body)
9047 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9048 (progn (vhdl-insert-keyword " IS")
9049 (when vhdl-auto-align
9050 (vhdl-align-region-groups start (point) 1))
9051 (end-of-line) (insert "\n")
9052 (vhdl-template-begin-end
9053 (unless (vhdl-standard-p '87) "PROCEDURE")
9055 (vhdl-comment-block))
9057 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9060 (defun vhdl-template-procedure-decl ()
9061 "Insert a procedure declaration."
9063 (vhdl-template-procedure 'decl))
9065 (defun vhdl-template-procedure-body ()
9066 "Insert a procedure body."
9068 (vhdl-template-procedure 'body))
9070 (defun vhdl-template-process (&optional kind)
9073 (let ((margin (current-indentation))
9075 label seq input-signals clock reset final-pos)
9076 (setq seq (if kind (eq kind 'seq)
9077 (eq (vhdl-decision-query
9078 "process" "(c)ombinational or (s)equential?" t) ?s)))
9079 (vhdl-insert-keyword "PROCESS ")
9080 (when (memq vhdl-optional-labels '(process all))
9084 (setq label (vhdl-template-field "[label]" nil t))
9085 (unless label (delete-char 2))
9090 (unless (setq input-signals
9091 (vhdl-template-field "[sensitivity list]" ")" t))
9092 (setq input-signals "")
9094 (setq clock (or (and (not (equal "" vhdl-clock-name))
9095 (progn (insert vhdl-clock-name) vhdl-clock-name))
9096 (vhdl-template-field "clock name") "<clock>"))
9097 (when (eq vhdl-reset-kind 'async)
9099 (setq reset (or (and (not (equal "" vhdl-reset-name))
9100 (progn (insert vhdl-reset-name) vhdl-reset-name))
9101 (vhdl-template-field "reset name") "<reset>")))
9103 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9105 (vhdl-template-begin-end "PROCESS" label margin)
9106 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9107 (when vhdl-prompt-for-comments
9108 (setq final-pos (point-marker))
9109 (vhdl-prepare-search-2
9110 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9111 (vhdl-re-search-backward "\\<process\\>" nil t))
9114 (progn (insert "\n") (forward-line -1))
9117 (insert "-- purpose: ")
9118 (if (not (vhdl-template-field "[description]" nil t))
9119 (vhdl-line-kill-entire)
9122 (insert "-- type : ")
9123 (insert (if seq "sequential" "combinational") "\n")
9125 (insert "-- inputs : ")
9127 (insert input-signals)
9129 (when reset (insert reset ", "))
9130 (unless (vhdl-template-field "[signal names]" nil t)
9134 (insert "-- outputs: ")
9135 (vhdl-template-field "[signal names]" nil t))))
9136 (goto-char final-pos))))
9138 (defun vhdl-template-process-comb ()
9139 "Insert a combinational process."
9141 (vhdl-template-process 'comb))
9143 (defun vhdl-template-process-seq ()
9144 "Insert a sequential process."
9146 (vhdl-template-process 'seq))
9148 (defun vhdl-template-quantity ()
9149 "Insert a quantity declaration."
9151 (if (vhdl-in-argument-list-p)
9152 (let ((start (point)))
9153 (vhdl-insert-keyword "QUANTITY ")
9154 (when (vhdl-template-field "names" nil t start (point))
9156 (vhdl-template-field "[IN | OUT]" " " t)
9157 (vhdl-template-field "type")
9159 (vhdl-comment-insert-inline)))
9160 (let ((char (vhdl-decision-query
9161 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9162 (cond ((eq char ?f) (vhdl-template-quantity-free))
9163 ((eq char ?b) (vhdl-template-quantity-branch))
9164 ((eq char ?s) (vhdl-template-quantity-source))
9165 (t (vhdl-template-undo (point) (point)))))))
9167 (defun vhdl-template-quantity-free ()
9168 "Insert a free quantity declaration."
9170 (vhdl-insert-keyword "QUANTITY ")
9171 (vhdl-template-field "names")
9173 (vhdl-template-field "type")
9174 (let ((position (point)))
9176 (unless (vhdl-template-field "[initialization]" nil t)
9177 (delete-region position (point)))
9179 (vhdl-comment-insert-inline)))
9181 (defun vhdl-template-quantity-branch ()
9182 "Insert a branch quantity declaration."
9185 (vhdl-insert-keyword "QUANTITY ")
9186 (when (vhdl-template-field "[across names]" " " t)
9187 (vhdl-insert-keyword "ACROSS "))
9188 (when (vhdl-template-field "[through names]" " " t)
9189 (vhdl-insert-keyword "THROUGH "))
9190 (vhdl-template-field "plus terminal name")
9191 (setq position (point))
9192 (vhdl-insert-keyword " TO ")
9193 (unless (vhdl-template-field "[minus terminal name]" nil t)
9194 (delete-region position (point)))
9196 (vhdl-comment-insert-inline)))
9198 (defun vhdl-template-quantity-source ()
9199 "Insert a source quantity declaration."
9201 (vhdl-insert-keyword "QUANTITY ")
9202 (vhdl-template-field "names")
9204 (vhdl-template-field "type" " ")
9205 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9206 (progn (vhdl-insert-keyword "NOISE ")
9207 (vhdl-template-field "power expression"))
9208 (vhdl-insert-keyword "SPECTRUM ")
9209 (vhdl-template-field "magnitude expression" ", ")
9210 (vhdl-template-field "phase expression"))
9212 (vhdl-comment-insert-inline))
9214 (defun vhdl-template-record (kind &optional name secondary)
9215 "Insert a record type declaration."
9217 (let ((margin (current-column))
9220 (vhdl-insert-keyword "RECORD\n")
9221 (indent-to (+ margin vhdl-basic-offset))
9222 (when (or (vhdl-template-field "element names"
9223 nil (not secondary) start (point))
9225 (while (or first (vhdl-template-field "[element names]" nil t))
9227 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9228 (vhdl-comment-insert-inline)
9230 (indent-to (+ margin vhdl-basic-offset))
9234 (vhdl-insert-keyword "END RECORD")
9235 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9237 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9239 (defun vhdl-template-report ()
9240 "Insert a report statement."
9242 (let ((start (point)))
9243 (vhdl-insert-keyword "REPORT ")
9244 (if (equal "\"\"" (vhdl-template-field
9245 "string expression" nil t start (point) t))
9246 (delete-backward-char 2)
9247 (setq start (point))
9248 (vhdl-insert-keyword " SEVERITY ")
9249 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9250 (delete-region start (point)))
9253 (defun vhdl-template-return ()
9254 "Insert a return statement."
9256 (let ((start (point)))
9257 (vhdl-insert-keyword "RETURN ")
9258 (unless (vhdl-template-field "[expression]" nil t start (point))
9262 (defun vhdl-template-selected-signal-asst ()
9263 "Insert a selected signal assignment."
9265 (let ((margin (current-indentation))
9268 (let ((position (point)))
9269 (vhdl-insert-keyword " SELECT ")
9270 (goto-char position))
9271 (vhdl-insert-keyword "WITH ")
9272 (when (vhdl-template-field "selector expression"
9273 nil t start (+ (point) 7))
9277 (indent-to (+ margin vhdl-basic-offset))
9278 (vhdl-template-field "target signal" " <= ")
9279 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9281 (indent-to (+ margin vhdl-basic-offset))
9282 (vhdl-template-field "waveform")
9283 (vhdl-insert-keyword " WHEN ")
9284 (vhdl-template-field "choices" ",")
9286 (indent-to (+ margin vhdl-basic-offset))
9287 (while (and choices (vhdl-template-field "[waveform]" nil t))
9288 (vhdl-insert-keyword " WHEN ")
9289 (if (setq choices (vhdl-template-field "[choices]" "," t))
9290 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9291 (vhdl-insert-keyword "OTHERS")))
9296 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9298 (defun vhdl-template-signal ()
9299 "Insert a signal declaration."
9301 (let ((start (point))
9302 (in-arglist (vhdl-in-argument-list-p)))
9303 (vhdl-insert-keyword "SIGNAL ")
9304 (when (vhdl-template-field "names" nil t start (point))
9306 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9307 (vhdl-template-field "type")
9310 (vhdl-comment-insert-inline))
9311 (let ((position (point)))
9313 (unless (vhdl-template-field "[initialization]" nil t)
9314 (delete-region position (point)))
9316 (vhdl-comment-insert-inline))))))
9318 (defun vhdl-template-subnature ()
9319 "Insert a subnature declaration."
9321 (let ((start (point))
9323 (vhdl-insert-keyword "SUBNATURE ")
9324 (when (vhdl-template-field "name" nil t start (point))
9325 (vhdl-insert-keyword " IS ")
9326 (vhdl-template-field "nature" " (")
9327 (if (vhdl-template-field "[index range]" nil t)
9330 (setq position (point))
9331 (vhdl-insert-keyword " TOLERANCE ")
9332 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9334 (delete-region position (point))
9335 (vhdl-insert-keyword " ACROSS ")
9336 (vhdl-template-field "string expression" nil nil nil nil t)
9337 (vhdl-insert-keyword " THROUGH"))
9339 (vhdl-comment-insert-inline))))
9341 (defun vhdl-template-subprogram-body ()
9342 "Insert a subprogram body."
9344 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9345 (vhdl-template-function-body)
9346 (vhdl-template-procedure-body)))
9348 (defun vhdl-template-subprogram-decl ()
9349 "Insert a subprogram declaration."
9351 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9352 (vhdl-template-function-decl)
9353 (vhdl-template-procedure-decl)))
9355 (defun vhdl-template-subtype ()
9356 "Insert a subtype declaration."
9358 (let ((start (point)))
9359 (vhdl-insert-keyword "SUBTYPE ")
9360 (when (vhdl-template-field "name" nil t start (point))
9361 (vhdl-insert-keyword " IS ")
9362 (vhdl-template-field "type" " ")
9364 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9367 (vhdl-comment-insert-inline))))
9369 (defun vhdl-template-terminal ()
9370 "Insert a terminal declaration."
9372 (let ((start (point)))
9373 (vhdl-insert-keyword "TERMINAL ")
9374 (when (vhdl-template-field "names" nil t start (point))
9376 (vhdl-template-field "nature")
9378 (vhdl-comment-insert-inline))))
9380 (defun vhdl-template-type ()
9381 "Insert a type declaration."
9383 (let ((start (point))
9384 name mid-pos end-pos)
9385 (vhdl-insert-keyword "TYPE ")
9386 (when (setq name (vhdl-template-field "name" nil t start (point)))
9387 (vhdl-insert-keyword " IS ")
9390 (or (vhdl-template-field
9391 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9393 (cond ((equal definition "")
9394 (delete-backward-char 4)
9396 ((equal definition "ARRAY")
9398 (vhdl-template-array 'type t))
9399 ((equal definition "RECORD")
9400 (setq mid-pos (point-marker))
9402 (vhdl-template-record 'type name t))
9403 ((equal definition "ACCESS")
9405 (vhdl-template-field "type" ";"))
9406 ((equal definition "FILE")
9407 (vhdl-insert-keyword " OF ")
9408 (vhdl-template-field "type" ";"))
9411 (setq end-pos (point-marker))
9414 (vhdl-comment-insert-inline)
9415 (when end-pos (goto-char end-pos))))))
9417 (defun vhdl-template-use ()
9418 "Insert a use clause."
9420 (let ((start (point)))
9421 (vhdl-prepare-search-1
9422 (vhdl-insert-keyword "USE ")
9423 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9424 (vhdl-insert-keyword "..ALL;")
9426 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9428 (vhdl-template-field "package name")
9429 (forward-char 5))))))
9431 (defun vhdl-template-variable ()
9432 "Insert a variable declaration."
9434 (let ((start (point))
9435 (in-arglist (vhdl-in-argument-list-p)))
9436 (vhdl-prepare-search-2
9437 (if (or (save-excursion
9438 (and (vhdl-re-search-backward
9439 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9441 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9442 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9443 (vhdl-insert-keyword "VARIABLE ")
9444 (vhdl-insert-keyword "SHARED VARIABLE ")))
9445 (when (vhdl-template-field "names" nil t start (point))
9447 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9448 (vhdl-template-field "type")
9451 (vhdl-comment-insert-inline))
9452 (let ((position (point)))
9454 (unless (vhdl-template-field "[initialization]" nil t)
9455 (delete-region position (point)))
9457 (vhdl-comment-insert-inline))))))
9459 (defun vhdl-template-wait ()
9460 "Insert a wait statement."
9462 (vhdl-insert-keyword "WAIT ")
9463 (unless (vhdl-template-field
9464 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9469 (defun vhdl-template-when ()
9470 "Indent correctly if within a case statement."
9472 (let ((position (point))
9474 (vhdl-prepare-search-2
9475 (if (and (= (current-column) (current-indentation))
9476 (vhdl-re-search-forward "\\<end\\>" nil t)
9477 (looking-at "\\s-*\\<case\\>"))
9479 (setq margin (current-indentation))
9480 (goto-char position)
9481 (delete-horizontal-space)
9482 (indent-to (+ margin vhdl-basic-offset)))
9483 (goto-char position)))
9484 (vhdl-insert-keyword "WHEN ")))
9486 (defun vhdl-template-while-loop ()
9487 "Insert a while loop."
9489 (let* ((margin (current-indentation))
9492 (if (not (eq vhdl-optional-labels 'all))
9493 (vhdl-insert-keyword "WHILE ")
9494 (vhdl-insert-keyword ": WHILE ")
9496 (setq label (vhdl-template-field "[label]" nil t))
9497 (unless label (delete-char 2))
9500 (when vhdl-conditions-in-parenthesis (insert "("))
9501 (when (vhdl-template-field "condition" nil t start (point))
9502 (when vhdl-conditions-in-parenthesis (insert ")"))
9503 (vhdl-insert-keyword " LOOP\n\n")
9505 (vhdl-insert-keyword "END LOOP")
9506 (insert (if label (concat " " label ";") ";"))
9508 (indent-to (+ margin vhdl-basic-offset)))))
9510 (defun vhdl-template-with ()
9511 "Insert a with statement (i.e. selected signal assignment)."
9513 (vhdl-prepare-search-1
9514 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9515 (equal ";" (match-string 1)))
9516 (vhdl-template-selected-signal-asst)
9517 (vhdl-insert-keyword "WITH "))))
9519 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9520 ;; Special templates
9522 (defun vhdl-template-clocked-wait ()
9523 "Insert a wait statement for rising/falling clock edge."
9525 (let ((start (point))
9527 (vhdl-insert-keyword "WAIT UNTIL ")
9529 (or (and (not (equal "" vhdl-clock-name))
9530 (progn (insert vhdl-clock-name) vhdl-clock-name))
9531 (vhdl-template-field "clock name" nil t start (point))))
9533 (vhdl-insert-keyword " AND ")
9536 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9537 (vhdl-comment-insert-inline
9538 (concat (if vhdl-clock-rising-edge "rising" "falling")
9541 (defun vhdl-template-seq-process (clock reset)
9542 "Insert a template for the body of a sequential process."
9543 (let ((margin (current-indentation))
9545 (vhdl-insert-keyword "IF ")
9546 (when (eq vhdl-reset-kind 'async)
9548 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9549 (vhdl-insert-keyword " THEN")
9550 (vhdl-comment-insert-inline
9551 (concat "asynchronous reset (active "
9552 (if vhdl-reset-active-high "high" "low") ")"))
9553 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9554 (setq position (point))
9555 (insert "\n") (indent-to margin)
9556 (vhdl-insert-keyword "ELSIF "))
9557 (if (eq vhdl-clock-edge-condition 'function)
9558 (insert (if vhdl-clock-rising-edge "rising" "falling")
9560 (insert clock "'event")
9561 (vhdl-insert-keyword " AND ")
9563 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9564 (vhdl-insert-keyword " THEN")
9565 (vhdl-comment-insert-inline
9566 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9567 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9568 (when (eq vhdl-reset-kind 'sync)
9569 (vhdl-insert-keyword "IF ")
9570 (setq reset (or (and (not (equal "" vhdl-reset-name))
9571 (progn (insert vhdl-reset-name) vhdl-reset-name))
9572 (vhdl-template-field "reset name") "<reset>"))
9574 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9575 (vhdl-insert-keyword " THEN")
9576 (vhdl-comment-insert-inline
9577 (concat "synchronous reset (active "
9578 (if vhdl-reset-active-high "high" "low") ")"))
9579 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9580 (setq position (point))
9581 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9582 (vhdl-insert-keyword "ELSE")
9583 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9584 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9585 (vhdl-insert-keyword "END IF;"))
9586 (when (eq vhdl-reset-kind 'none)
9587 (setq position (point)))
9588 (insert "\n") (indent-to margin)
9589 (vhdl-insert-keyword "END IF;")
9590 (goto-char position)
9593 (defun vhdl-template-standard-package (library package)
9594 "Insert specification of a standard package. Include a library
9595 specification, if not already there."
9596 (let ((margin (current-indentation)))
9597 (unless (equal library "std")
9598 (unless (or (save-excursion
9599 (vhdl-prepare-search-1
9602 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9603 library "\\|end\\)\\>") nil t)
9605 (equal (downcase library) "work"))
9606 (vhdl-insert-keyword "LIBRARY ")
9607 (insert library ";\n")
9609 (vhdl-insert-keyword "USE ")
9610 (insert library "." package)
9611 (vhdl-insert-keyword ".ALL;"))))
9613 (defun vhdl-template-package-math-complex ()
9614 "Insert specification of `math_complex' package."
9616 (vhdl-template-standard-package "ieee" "math_complex"))
9618 (defun vhdl-template-package-math-real ()
9619 "Insert specification of `math_real' package."
9621 (vhdl-template-standard-package "ieee" "math_real"))
9623 (defun vhdl-template-package-numeric-bit ()
9624 "Insert specification of `numeric_bit' package."
9626 (vhdl-template-standard-package "ieee" "numeric_bit"))
9628 (defun vhdl-template-package-numeric-std ()
9629 "Insert specification of `numeric_std' package."
9631 (vhdl-template-standard-package "ieee" "numeric_std"))
9633 (defun vhdl-template-package-std-logic-1164 ()
9634 "Insert specification of `std_logic_1164' package."
9636 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9638 (defun vhdl-template-package-std-logic-arith ()
9639 "Insert specification of `std_logic_arith' package."
9641 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9643 (defun vhdl-template-package-std-logic-misc ()
9644 "Insert specification of `std_logic_misc' package."
9646 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9648 (defun vhdl-template-package-std-logic-signed ()
9649 "Insert specification of `std_logic_signed' package."
9651 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9653 (defun vhdl-template-package-std-logic-textio ()
9654 "Insert specification of `std_logic_textio' package."
9656 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9658 (defun vhdl-template-package-std-logic-unsigned ()
9659 "Insert specification of `std_logic_unsigned' package."
9661 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9663 (defun vhdl-template-package-textio ()
9664 "Insert specification of `textio' package."
9666 (vhdl-template-standard-package "std" "textio"))
9668 (defun vhdl-template-directive (directive)
9670 (unless (= (current-indentation) (current-column))
9671 (delete-horizontal-space)
9673 (insert "-- pragma " directive))
9675 (defun vhdl-template-directive-translate-on ()
9676 "Insert directive 'translate_on'."
9678 (vhdl-template-directive "translate_on"))
9680 (defun vhdl-template-directive-translate-off ()
9681 "Insert directive 'translate_off'."
9683 (vhdl-template-directive "translate_off"))
9685 (defun vhdl-template-directive-synthesis-on ()
9686 "Insert directive 'synthesis_on'."
9688 (vhdl-template-directive "synthesis_on"))
9690 (defun vhdl-template-directive-synthesis-off ()
9691 "Insert directive 'synthesis_off'."
9693 (vhdl-template-directive "synthesis_off"))
9695 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9696 ;; Header and footer templates
9698 (defun vhdl-template-header (&optional file-title)
9699 "Insert a VHDL file header."
9701 (unless (equal vhdl-file-header "")
9704 (goto-char (point-min))
9705 (vhdl-insert-string-or-file vhdl-file-header)
9706 (setq pos (point-marker)))
9707 (vhdl-template-replace-header-keywords
9708 (point-min-marker) pos file-title))))
9710 (defun vhdl-template-footer ()
9711 "Insert a VHDL file footer."
9713 (unless (equal vhdl-file-footer "")
9716 (goto-char (point-max))
9717 (setq pos (point-marker))
9718 (vhdl-insert-string-or-file vhdl-file-footer)
9719 (unless (= (preceding-char) ?\n)
9721 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9723 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9725 "Replace keywords in header and footer."
9726 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9727 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9729 (vhdl-prepare-search-2
9732 (while (search-forward "<projectdesc>" end t)
9733 (replace-match project-desc t t))
9735 (while (search-forward "<filename>" end t)
9736 (replace-match (buffer-name) t t))
9738 (while (search-forward "<copyright>" end t)
9739 (replace-match vhdl-copyright-string t t))
9741 (while (search-forward "<author>" end t)
9742 (replace-match "" t t)
9743 (insert (user-full-name))
9744 (when user-mail-address (insert " <" user-mail-address ">")))
9746 (while (search-forward "<login>" end t)
9747 (replace-match (user-login-name) t t))
9749 (while (search-forward "<project>" end t)
9750 (replace-match project-title t t))
9752 (while (search-forward "<company>" end t)
9753 (replace-match vhdl-company-name t t))
9755 (while (search-forward "<platform>" end t)
9756 (replace-match vhdl-platform-spec t t))
9758 (while (search-forward "<standard>" end t)
9760 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9761 ((vhdl-standard-p '93) "'93"))
9762 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9763 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9765 ;; Replace <RCS> with $, so that RCS for the source is
9766 ;; not over-enthusiastic with replacements
9767 (while (search-forward "<RCS>" end t)
9768 (replace-match "$" nil t))
9770 (while (search-forward "<date>" end t)
9771 (replace-match "" t t)
9772 (vhdl-template-insert-date))
9774 (while (search-forward "<year>" end t)
9775 (replace-match (format-time-string "%Y" nil) t t))
9778 (while (search-forward "<title string>" end t)
9779 (replace-match file-title t t))
9783 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9784 (setq string (read-string (concat (match-string 1) ": ")))
9785 (replace-match string t t)))
9787 (when (and (not is-model) (search-forward "<cursor>" end t))
9788 (replace-match "" t t)
9789 (setq pos (point))))
9790 (when pos (goto-char pos))
9792 (when (or (not project-title) (equal project-title ""))
9793 (message "You can specify a project title in user option `vhdl-project-alist'"))
9794 (when (or (not project-desc) (equal project-desc ""))
9795 (message "You can specify a project description in user option `vhdl-project-alist'"))
9796 (when (equal vhdl-platform-spec "")
9797 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9798 (when (equal vhdl-company-name "")
9799 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9801 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9802 ;; Comment templates and functions
9804 (defun vhdl-comment-indent ()
9806 (let* ((position (point))
9810 (if (re-search-forward "--" position t)
9811 (- (current-column) 2) ; existing comment at bol stays there
9812 (goto-char position)
9813 (skip-chars-backward " \t")
9814 (max comment-column ; else indent to comment column
9815 (1+ (current-column))))))) ; except leave at least one space
9816 (goto-char position)
9819 (defun vhdl-comment-insert ()
9820 "Start a comment at the end of the line.
9821 If on line with code, indent at least `comment-column'.
9822 If starting after end-comment-column, start a new line."
9824 (when (> (current-column) end-comment-column) (newline-and-indent))
9825 (if (or (looking-at "\\s-*$") ; end of line
9826 (and (not unread-command-events) ; called with key binding or menu
9827 (not (end-of-line))))
9829 (while (= (preceding-char) ?-) (delete-char -1))
9830 (setq margin (current-column))
9831 (delete-horizontal-space)
9833 (progn (indent-to margin) (insert "--"))
9835 (indent-to comment-column)
9837 (if (not unread-command-events) (insert " ")))
9838 ;; else code following current point implies commenting out code
9839 (let (next-input code)
9840 (while (= (preceding-char) ?-) (delete-char -2))
9841 (while (= (setq next-input (read-char)) 13) ; CR
9842 (insert "--") ; or have a space after it?
9845 (message "Enter CR if commenting out a line of code.")
9848 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
9849 (setq unread-command-events
9850 (list (vhdl-character-to-event next-input)))))) ; pushback the char
9852 (defun vhdl-comment-display (&optional line-exists)
9853 "Add 2 comment lines at the current indent, making a display comment."
9855 (let ((margin (current-indentation)))
9856 (unless line-exists (vhdl-comment-display-line))
9857 (insert "\n") (indent-to margin)
9858 (insert "\n") (indent-to margin)
9859 (vhdl-comment-display-line)
9863 (defun vhdl-comment-display-line ()
9864 "Displays one line of dashes."
9866 (while (= (preceding-char) ?-) (delete-char -2))
9867 (let* ((col (current-column))
9868 (len (- end-comment-column col)))
9869 (insert-char ?- len)))
9871 (defun vhdl-comment-append-inline ()
9872 "Append empty inline comment to current line."
9875 (delete-horizontal-space)
9877 (indent-to comment-column)
9880 (defun vhdl-comment-insert-inline (&optional string always-insert)
9881 "Insert inline comment."
9882 (when (or (and string (or vhdl-self-insert-comments always-insert))
9883 (and (not string) vhdl-prompt-for-comments))
9884 (let ((position (point)))
9886 (indent-to comment-column)
9888 (if (not (or (and string (progn (insert string) t))
9889 (vhdl-template-field "[comment]" nil t)))
9890 (delete-region position (point))
9891 (while (= (preceding-char) ? ) (delete-backward-char 1))
9892 ; (when (> (current-column) end-comment-column)
9893 ; (setq position (point-marker))
9894 ; (re-search-backward "-- ")
9896 ; (indent-to comment-column)
9897 ; (goto-char position))
9900 (defun vhdl-comment-block ()
9901 "Insert comment for code block."
9902 (when vhdl-prompt-for-comments
9903 (let ((final-pos (point-marker)))
9904 (vhdl-prepare-search-2
9905 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
9906 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
9908 (back-to-indentation)
9909 (setq margin (current-column))
9912 (progn (insert "\n") (forward-line -1))
9915 (insert "-- purpose: ")
9916 (unless (vhdl-template-field "[description]" nil t)
9917 (vhdl-line-kill-entire)))))
9918 (goto-char final-pos))))
9920 (defun vhdl-comment-uncomment-region (beg end &optional arg)
9921 "Comment out region if not commented out, uncomment otherwise."
9922 (interactive "r\nP")
9924 (goto-char (1- end))
9926 (setq end (point-marker))
9930 (if (looking-at comment-start)
9931 (comment-region beg end '(4))
9932 (comment-region beg end))))
9934 (defun vhdl-comment-uncomment-line (&optional arg)
9935 "Comment out line if not commented out, uncomment otherwise."
9939 (let ((position (point)))
9940 (forward-line (or arg 1))
9941 (vhdl-comment-uncomment-region position (point)))))
9943 (defun vhdl-comment-kill-region (beg end)
9944 "Kill comments in region."
9948 (setq end (point-marker))
9951 (while (< (point) end)
9952 (if (looking-at "^\\(\\s-*--.*\n\\)")
9953 (progn (delete-region (match-beginning 1) (match-end 1)))
9954 (beginning-of-line 2)))))
9956 (defun vhdl-comment-kill-inline-region (beg end)
9957 "Kill inline comments in region."
9961 (setq end (point-marker))
9964 (while (< (point) end)
9965 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
9966 (delete-region (match-beginning 1) (match-end 1)))
9967 (beginning-of-line 2))))
9969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9972 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
9973 "Insert a begin ... end pair with optional name after the end.
9974 Point is left between them."
9976 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9978 (vhdl-insert-keyword "BEGIN")
9979 (when (and (or construct name) vhdl-self-insert-comments)
9981 (when construct (insert " ") (vhdl-insert-keyword construct))
9982 (when name (insert " " name)))
9984 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9985 (indent-to (+ margin vhdl-basic-offset))
9986 (setq position (point))
9988 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9990 (vhdl-insert-keyword "END")
9991 (when construct (insert " ") (vhdl-insert-keyword construct))
9992 (insert (if name (concat " " name) "") ";")
9993 (goto-char position)))
9995 (defun vhdl-template-argument-list (&optional is-function)
9996 "Read from user a procedure or function argument list."
9998 (let ((margin (current-column))
10001 not-empty interface semicolon-pos)
10002 (unless vhdl-argument-list-indent
10003 (setq margin (+ (current-indentation) vhdl-basic-offset))
10005 (indent-to margin))
10006 (setq interface (vhdl-template-field
10007 (concat "[CONSTANT | SIGNAL"
10008 (unless is-function " | VARIABLE") "]") " " t))
10009 (while (vhdl-template-field "[names]" nil t)
10012 (unless is-function
10013 (if (and interface (equal (upcase interface) "CONSTANT"))
10014 (vhdl-insert-keyword "IN ")
10015 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10016 (vhdl-template-field "type")
10017 (setq semicolon-pos (point))
10019 (vhdl-comment-insert-inline)
10020 (setq end-pos (point))
10023 (setq interface (vhdl-template-field
10024 (concat "[CONSTANT | SIGNAL"
10025 (unless is-function " | VARIABLE") "]") " " t)))
10026 (delete-region end-pos (point))
10027 (when semicolon-pos (goto-char semicolon-pos))
10029 (progn (delete-char 1) (insert ")"))
10030 (delete-backward-char 2))))
10032 (defun vhdl-template-generic-list (optional &optional no-value)
10033 "Read from user a generic spec argument list."
10036 (vhdl-insert-keyword "GENERIC (")
10037 (setq margin (current-column))
10038 (unless vhdl-argument-list-indent
10039 (let ((position (point)))
10040 (back-to-indentation)
10041 (setq margin (+ (current-column) vhdl-basic-offset))
10042 (goto-char position)
10044 (indent-to margin)))
10045 (let ((vhdl-generics (vhdl-template-field
10046 (concat (and optional "[") "name"
10047 (and no-value "s") (and optional "]"))
10049 (if (not vhdl-generics)
10051 (progn (vhdl-line-kill-entire) (end-of-line -0)
10052 (unless vhdl-argument-list-indent
10053 (vhdl-line-kill-entire) (end-of-line -0)))
10054 (vhdl-template-undo start (point))
10057 (let (semicolon-pos end-pos)
10058 (while vhdl-generics
10059 (vhdl-template-field "type")
10061 (progn (setq semicolon-pos (point))
10064 (unless (vhdl-template-field "[value]" nil t)
10066 (setq semicolon-pos (point))
10068 (vhdl-comment-insert-inline)
10069 (setq end-pos (point))
10072 (setq vhdl-generics (vhdl-template-field
10073 (concat "[name" (and no-value "s") "]")
10075 (delete-region end-pos (point))
10076 (goto-char semicolon-pos)
10079 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10082 (defun vhdl-template-port-list (optional)
10083 "Read from user a port spec argument list."
10084 (let ((start (point))
10085 margin vhdl-ports object)
10086 (vhdl-insert-keyword "PORT (")
10087 (setq margin (current-column))
10088 (unless vhdl-argument-list-indent
10089 (let ((position (point)))
10090 (back-to-indentation)
10091 (setq margin (+ (current-column) vhdl-basic-offset))
10092 (goto-char position)
10094 (indent-to margin)))
10095 (when (vhdl-standard-p 'ams)
10096 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10098 (setq vhdl-ports (vhdl-template-field
10099 (concat (and optional "[") "names" (and optional "]"))
10101 (if (not vhdl-ports)
10103 (progn (vhdl-line-kill-entire) (end-of-line -0)
10104 (unless vhdl-argument-list-indent
10105 (vhdl-line-kill-entire) (end-of-line -0)))
10106 (vhdl-template-undo start (point))
10109 (let (semicolon-pos end-pos)
10111 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10112 (vhdl-template-field "IN | OUT | INOUT" " "))
10113 ((equal "QUANTITY" (upcase object))
10114 (vhdl-template-field "[IN | OUT]" " " t)))
10115 (vhdl-template-field
10116 (if (and object (equal "TERMINAL" (upcase object)))
10118 (setq semicolon-pos (point))
10120 (vhdl-comment-insert-inline)
10121 (setq end-pos (point))
10124 (when (vhdl-standard-p 'ams)
10125 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10127 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10128 (delete-region end-pos (point))
10129 (goto-char semicolon-pos)
10132 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10135 (defun vhdl-template-generate-body (margin label)
10136 "Insert body for generate template."
10137 (vhdl-insert-keyword " GENERATE")
10138 ; (if (not (vhdl-standard-p '87))
10139 ; (vhdl-template-begin-end "GENERATE" label margin)
10142 (vhdl-insert-keyword "END GENERATE ")
10145 (indent-to (+ margin vhdl-basic-offset)))
10147 (defun vhdl-template-insert-date ()
10148 "Insert date in appropriate format."
10152 ;; 'american, 'european, 'scientific kept for backward compatibility
10153 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10154 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10155 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10156 (t (format-time-string vhdl-date-format nil)))))
10158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10161 (defun vhdl-electric-space (count)
10162 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10163 if in comment and past end-comment-column."
10165 (cond ((vhdl-in-comment-p)
10166 (self-insert-command count)
10167 (cond ((>= (current-column) (+ 2 end-comment-column))
10169 (skip-chars-backward "^ \t\n")
10170 (indent-new-comment-line)
10171 (skip-chars-forward "^ \t\n")
10173 ((>= (current-column) end-comment-column)
10174 (indent-new-comment-line))
10176 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10177 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10178 (vhdl-prepare-search-1
10179 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10180 (self-insert-command count))
10181 (t (self-insert-command count))))
10183 (defun vhdl-template-field (prompt &optional follow-string optional
10184 begin end is-string default)
10185 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10186 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10187 an empty string is inserted, return nil and call `vhdl-template-undo' for
10188 the region between BEGIN and END. IS-STRING indicates whether a string
10189 with double-quotes is to be inserted. DEFAULT specifies a default string."
10190 (let ((position (point))
10192 (insert "<" prompt ">")
10195 (read-from-minibuffer (concat prompt ": ")
10196 (or (and is-string '("\"\"" . 2)) default)
10197 vhdl-minibuffer-local-map)
10198 (quit (if (and optional begin end)
10200 (keyboard-quit)))))
10201 (when (or (not (equal string "")) optional)
10202 (delete-region position (point)))
10203 (when (and (equal string "") optional begin end)
10204 (vhdl-template-undo begin end)
10205 (message "Template aborted"))
10206 (unless (equal string "")
10208 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10209 vhdl-keywords-regexp)
10210 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10212 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10213 (concat "'" vhdl-attributes-regexp))
10214 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10215 vhdl-enum-values-regexp))
10216 (when (or (not (equal string "")) (not optional))
10217 (insert (or follow-string "")))
10218 (if (equal string "") nil string)))
10220 (defun vhdl-decision-query (string prompt &optional optional)
10221 "Query a decision from the user."
10222 (let ((start (point)))
10223 (when string (vhdl-insert-keyword (concat string " ")))
10225 (let ((char (read-char)))
10226 (delete-region start (point))
10227 (if (and optional (eq char ?\r))
10228 (progn (insert " ")
10230 (throw 'abort "ERROR: Template aborted"))
10233 (defun vhdl-insert-keyword (keyword)
10234 "Insert KEYWORD and adjust case."
10235 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10237 (defun vhdl-case-keyword (keyword)
10238 "Adjust case of KEYWORD."
10239 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10241 (defun vhdl-case-word (num)
10242 "Adjust case or following NUM words."
10243 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10245 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10246 "If preceeding character is part of a word or a paren then hippie-expand,
10247 else insert tab (used for word completion in VHDL minibuffer)."
10251 ((= (char-syntax (preceding-char)) ?w)
10252 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10254 (hippie-expand-only-buffers
10255 (or (and (boundp 'hippie-expand-only-buffers)
10256 hippie-expand-only-buffers)
10258 (vhdl-expand-abbrev prefix-arg)))
10259 ;; expand parenthesis
10260 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10261 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10262 (case-replace nil))
10263 (vhdl-expand-paren prefix-arg)))
10267 (defun vhdl-template-search-prompt ()
10268 "Search for left out template prompts and query again."
10270 (vhdl-prepare-search-2
10271 (when (or (re-search-forward
10272 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10273 (re-search-backward
10274 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10275 (let ((string (match-string 1)))
10277 (vhdl-template-field string)))))
10279 (defun vhdl-template-undo (begin end)
10280 "Undo aborted template by deleting region and unexpanding the keyword."
10281 (cond (vhdl-template-invoked-by-hook
10284 (delete-region begin end)
10286 (t (delete-region begin end))))
10288 (defun vhdl-insert-string-or-file (string)
10289 "Insert STRING or file contents if STRING is an existing file name."
10290 (unless (equal string "")
10292 (progn (string-match "^\\([^\n]+\\)" string)
10293 (vhdl-resolve-env-variable (match-string 1 string)))))
10294 (if (file-exists-p file-name)
10295 (forward-char (cadr (insert-file-contents file-name)))
10296 (insert string)))))
10298 (defun vhdl-beginning-of-block ()
10299 "Move cursor to the beginning of the enclosing block."
10302 (beginning-of-line)
10303 ;; search backward for block beginning or end
10304 (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))
10305 ;; not consider subprogram declarations
10306 (or (and (match-string 5)
10309 (goto-char (match-end 5))
10310 (forward-word 1) (forward-sexp)
10311 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10313 ;; not consider configuration specifications
10314 (and (match-string 6)
10317 (vhdl-end-of-block)
10318 (beginning-of-line)
10319 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10321 ;; skip subblock if block end found
10322 (vhdl-beginning-of-block)))
10323 (when pos (goto-char pos))))
10325 (defun vhdl-end-of-block ()
10326 "Move cursor to the end of the enclosing block."
10330 ;; search forward for block beginning or end
10331 (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))
10332 ;; not consider subprogram declarations
10333 (or (and (match-string 5)
10335 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10337 ;; not consider configuration specifications
10338 (and (match-string 6)
10341 (vhdl-end-of-block)
10342 (beginning-of-line)
10343 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10344 (not (match-string 2)))
10345 ;; skip subblock if block beginning found
10346 (vhdl-end-of-block)))
10347 (when pos (goto-char pos))))
10349 (defun vhdl-sequential-statement-p ()
10350 "Check if point is within sequential statement part."
10351 (let ((start (point)))
10353 (vhdl-prepare-search-2
10354 ;; is sequential statement if ...
10355 (and (re-search-backward "^\\s-*begin\\>" nil t)
10356 ;; ... point is between "begin" and "end" of ...
10357 (progn (vhdl-end-of-block)
10359 ;; ... a sequential block
10360 (progn (vhdl-beginning-of-block)
10361 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10363 (defun vhdl-in-argument-list-p ()
10364 "Check if within an argument list."
10366 (vhdl-prepare-search-2
10367 (or (string-match "arglist"
10368 (format "%s" (caar (vhdl-get-syntactic-context))))
10369 (progn (beginning-of-line)
10370 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10375 (defun vhdl-hooked-abbrev (func)
10376 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10377 but not if inside a comment or quote)."
10378 (if (or (vhdl-in-literal)
10381 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10386 (if (not vhdl-electric-mode)
10393 (let ((invoke-char last-command-char)
10395 (vhdl-template-invoked-by-hook t))
10396 (let ((caught (catch 'abort
10398 (when (stringp caught) (message caught)))
10399 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10400 ;; delete CR which is still in event queue
10402 (enqueue-eval-event 'delete-char -1)
10403 (setq unread-command-events ; push back a delete char
10404 (list (vhdl-character-to-event ?\177))))))))
10406 (defun vhdl-template-alias-hook ()
10407 (vhdl-hooked-abbrev 'vhdl-template-alias))
10408 (defun vhdl-template-architecture-hook ()
10409 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10410 (defun vhdl-template-assert-hook ()
10411 (vhdl-hooked-abbrev 'vhdl-template-assert))
10412 (defun vhdl-template-attribute-hook ()
10413 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10414 (defun vhdl-template-block-hook ()
10415 (vhdl-hooked-abbrev 'vhdl-template-block))
10416 (defun vhdl-template-break-hook ()
10417 (vhdl-hooked-abbrev 'vhdl-template-break))
10418 (defun vhdl-template-case-hook ()
10419 (vhdl-hooked-abbrev 'vhdl-template-case))
10420 (defun vhdl-template-component-hook ()
10421 (vhdl-hooked-abbrev 'vhdl-template-component))
10422 (defun vhdl-template-instance-hook ()
10423 (vhdl-hooked-abbrev 'vhdl-template-instance))
10424 (defun vhdl-template-conditional-signal-asst-hook ()
10425 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10426 (defun vhdl-template-configuration-hook ()
10427 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10428 (defun vhdl-template-constant-hook ()
10429 (vhdl-hooked-abbrev 'vhdl-template-constant))
10430 (defun vhdl-template-disconnect-hook ()
10431 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10432 (defun vhdl-template-display-comment-hook ()
10433 (vhdl-hooked-abbrev 'vhdl-comment-display))
10434 (defun vhdl-template-else-hook ()
10435 (vhdl-hooked-abbrev 'vhdl-template-else))
10436 (defun vhdl-template-elsif-hook ()
10437 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10438 (defun vhdl-template-entity-hook ()
10439 (vhdl-hooked-abbrev 'vhdl-template-entity))
10440 (defun vhdl-template-exit-hook ()
10441 (vhdl-hooked-abbrev 'vhdl-template-exit))
10442 (defun vhdl-template-file-hook ()
10443 (vhdl-hooked-abbrev 'vhdl-template-file))
10444 (defun vhdl-template-for-hook ()
10445 (vhdl-hooked-abbrev 'vhdl-template-for))
10446 (defun vhdl-template-function-hook ()
10447 (vhdl-hooked-abbrev 'vhdl-template-function))
10448 (defun vhdl-template-generic-hook ()
10449 (vhdl-hooked-abbrev 'vhdl-template-generic))
10450 (defun vhdl-template-group-hook ()
10451 (vhdl-hooked-abbrev 'vhdl-template-group))
10452 (defun vhdl-template-library-hook ()
10453 (vhdl-hooked-abbrev 'vhdl-template-library))
10454 (defun vhdl-template-limit-hook ()
10455 (vhdl-hooked-abbrev 'vhdl-template-limit))
10456 (defun vhdl-template-if-hook ()
10457 (vhdl-hooked-abbrev 'vhdl-template-if))
10458 (defun vhdl-template-bare-loop-hook ()
10459 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10460 (defun vhdl-template-map-hook ()
10461 (vhdl-hooked-abbrev 'vhdl-template-map))
10462 (defun vhdl-template-nature-hook ()
10463 (vhdl-hooked-abbrev 'vhdl-template-nature))
10464 (defun vhdl-template-next-hook ()
10465 (vhdl-hooked-abbrev 'vhdl-template-next))
10466 (defun vhdl-template-others-hook ()
10467 (vhdl-hooked-abbrev 'vhdl-template-others))
10468 (defun vhdl-template-package-hook ()
10469 (vhdl-hooked-abbrev 'vhdl-template-package))
10470 (defun vhdl-template-port-hook ()
10471 (vhdl-hooked-abbrev 'vhdl-template-port))
10472 (defun vhdl-template-procedural-hook ()
10473 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10474 (defun vhdl-template-procedure-hook ()
10475 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10476 (defun vhdl-template-process-hook ()
10477 (vhdl-hooked-abbrev 'vhdl-template-process))
10478 (defun vhdl-template-quantity-hook ()
10479 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10480 (defun vhdl-template-report-hook ()
10481 (vhdl-hooked-abbrev 'vhdl-template-report))
10482 (defun vhdl-template-return-hook ()
10483 (vhdl-hooked-abbrev 'vhdl-template-return))
10484 (defun vhdl-template-selected-signal-asst-hook ()
10485 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10486 (defun vhdl-template-signal-hook ()
10487 (vhdl-hooked-abbrev 'vhdl-template-signal))
10488 (defun vhdl-template-subnature-hook ()
10489 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10490 (defun vhdl-template-subtype-hook ()
10491 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10492 (defun vhdl-template-terminal-hook ()
10493 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10494 (defun vhdl-template-type-hook ()
10495 (vhdl-hooked-abbrev 'vhdl-template-type))
10496 (defun vhdl-template-use-hook ()
10497 (vhdl-hooked-abbrev 'vhdl-template-use))
10498 (defun vhdl-template-variable-hook ()
10499 (vhdl-hooked-abbrev 'vhdl-template-variable))
10500 (defun vhdl-template-wait-hook ()
10501 (vhdl-hooked-abbrev 'vhdl-template-wait))
10502 (defun vhdl-template-when-hook ()
10503 (vhdl-hooked-abbrev 'vhdl-template-when))
10504 (defun vhdl-template-while-loop-hook ()
10505 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10506 (defun vhdl-template-with-hook ()
10507 (vhdl-hooked-abbrev 'vhdl-template-with))
10508 (defun vhdl-template-and-hook ()
10509 (vhdl-hooked-abbrev 'vhdl-template-and))
10510 (defun vhdl-template-or-hook ()
10511 (vhdl-hooked-abbrev 'vhdl-template-or))
10512 (defun vhdl-template-nand-hook ()
10513 (vhdl-hooked-abbrev 'vhdl-template-nand))
10514 (defun vhdl-template-nor-hook ()
10515 (vhdl-hooked-abbrev 'vhdl-template-nor))
10516 (defun vhdl-template-xor-hook ()
10517 (vhdl-hooked-abbrev 'vhdl-template-xor))
10518 (defun vhdl-template-xnor-hook ()
10519 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10520 (defun vhdl-template-not-hook ()
10521 (vhdl-hooked-abbrev 'vhdl-template-not))
10523 (defun vhdl-template-default-hook ()
10524 (vhdl-hooked-abbrev 'vhdl-template-default))
10525 (defun vhdl-template-default-indent-hook ()
10526 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10528 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10529 ;; Template insertion from completion list
10531 (defun vhdl-template-insert-construct (name)
10532 "Insert the built-in construct template with NAME."
10534 (list (let ((completion-ignore-case t))
10535 (completing-read "Construct name: "
10536 vhdl-template-construct-alist nil t))))
10537 (vhdl-template-insert-fun
10538 (cadr (assoc name vhdl-template-construct-alist))))
10540 (defun vhdl-template-insert-package (name)
10541 "Insert the built-in package template with NAME."
10543 (list (let ((completion-ignore-case t))
10544 (completing-read "Package name: "
10545 vhdl-template-package-alist nil t))))
10546 (vhdl-template-insert-fun
10547 (cadr (assoc name vhdl-template-package-alist))))
10549 (defun vhdl-template-insert-directive (name)
10550 "Insert the built-in directive template with NAME."
10552 (list (let ((completion-ignore-case t))
10553 (completing-read "Directive name: "
10554 vhdl-template-directive-alist nil t))))
10555 (vhdl-template-insert-fun
10556 (cadr (assoc name vhdl-template-directive-alist))))
10558 (defun vhdl-template-insert-fun (fun)
10559 "Call FUN to insert a built-in template."
10560 (let ((caught (catch 'abort (when fun (funcall fun)))))
10561 (when (stringp caught) (message caught))))
10564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10568 (defun vhdl-model-insert (model-name)
10569 "Insert the user model with name MODEL-NAME."
10571 (let ((completion-ignore-case t))
10572 (list (completing-read "Model name: " vhdl-model-alist))))
10573 (indent-according-to-mode)
10574 (let ((start (point-marker))
10575 (margin (current-indentation))
10576 model position prompt string end)
10577 (vhdl-prepare-search-2
10578 (when (setq model (assoc model-name vhdl-model-alist))
10580 (beginning-of-line)
10581 (delete-horizontal-space)
10583 (vhdl-insert-string-or-file (nth 1 model))
10584 (setq end (point-marker))
10587 (beginning-of-line)
10588 (while (< (point) end)
10589 (unless (looking-at "^$")
10590 (insert-char ? margin))
10591 (beginning-of-line 2))
10594 (unless (equal "" vhdl-clock-name)
10595 (while (re-search-forward "<clock>" end t)
10596 (replace-match vhdl-clock-name)))
10599 (unless (equal "" vhdl-reset-name)
10600 (while (re-search-forward "<reset>" end t)
10601 (replace-match vhdl-reset-name)))
10602 ;; replace header prompts
10603 (vhdl-template-replace-header-keywords start end nil t)
10605 ;; query other prompts
10606 (while (re-search-forward
10607 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10608 (unless (equal "cursor" (match-string 1))
10609 (setq position (match-beginning 1))
10610 (setq prompt (match-string 1))
10612 (setq string (vhdl-template-field prompt nil t))
10613 ;; replace occurrences of same prompt
10614 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10615 (replace-match (or string "")))
10616 (goto-char position)))
10618 ;; goto final position
10619 (if (re-search-forward "<cursor>" end t)
10621 (goto-char end))))))
10623 (defun vhdl-model-defun ()
10624 "Define help and hook functions for user models."
10625 (let ((model-alist vhdl-model-alist)
10626 model-name model-keyword)
10628 ;; define functions for user models that can be invoked from menu and key
10629 ;; bindings and which themselves call `vhdl-model-insert' with the model
10630 ;; name as argument
10631 (setq model-name (nth 0 (car model-alist)))
10632 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10633 ,(concat "Insert model for \"" model-name "\".")
10635 (vhdl-model-insert ,model-name)))
10636 ;; define hooks for user models that are invoked from keyword abbrevs
10637 (setq model-keyword (nth 3 (car model-alist)))
10638 (unless (equal model-keyword "")
10640 ,(vhdl-function-name
10641 "vhdl-model" model-name "hook") ()
10642 (vhdl-hooked-abbrev
10643 ',(vhdl-function-name "vhdl-model" model-name)))))
10644 (setq model-alist (cdr model-alist)))))
10649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10650 ;;; Port translation
10651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10653 (defvar vhdl-port-list nil
10654 "Variable to hold last port map parsed.")
10655 ;; structure: (parenthesised expression means list of such entries)
10657 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10658 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10659 ;; (lib-name pack-key))
10661 (defun vhdl-parse-string (string &optional optional)
10662 "Check that the text following point matches the regexp in STRING."
10663 (if (looking-at string)
10664 (goto-char (match-end 0))
10666 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10667 (vhdl-current-line) string)))
10670 (defun vhdl-replace-string (regexp-cons string)
10671 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10672 (vhdl-prepare-search-1
10673 (if (string-match (car regexp-cons) string)
10674 (funcall vhdl-file-name-case
10675 (replace-match (cdr regexp-cons) t nil string))
10678 (defun vhdl-parse-group-comment ()
10679 "Parse comment and empty lines between groups of lines."
10680 (let ((start (point))
10682 (vhdl-forward-comment (point-max))
10683 (setq string (buffer-substring-no-properties start (point)))
10684 ;; strip off leading blanks and first newline
10685 (while (string-match "^\\(\\s-+\\)" string)
10686 (setq string (concat (substring string 0 (match-beginning 1))
10687 (substring string (match-end 1)))))
10688 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10689 (substring string 1)
10692 (defun vhdl-paste-group-comment (string indent)
10693 "Paste comment and empty lines from STRING between groups of lines
10695 (let ((pos (point-marker)))
10697 (while (string-match "^\\(--\\)" string)
10698 (setq string (concat (substring string 0 (match-beginning 1))
10699 (make-string indent ? )
10700 (substring string (match-beginning 1))))))
10701 (beginning-of-line)
10705 (defvar vhdl-port-flattened nil
10706 "Indicates whether a port has been flattened.")
10708 (defun vhdl-port-flatten (&optional as-alist)
10709 "Flatten port list so that only one generic/port exists per line."
10711 (if (not vhdl-port-list)
10712 (error "ERROR: No port has been read")
10713 (message "Flattening port...")
10714 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10715 (old-vhdl-port-list (cdr vhdl-port-list))
10716 old-port-list new-port-list old-port new-port names)
10717 ;; traverse port list and flatten entries
10718 (while (cdr old-vhdl-port-list)
10719 (setq old-port-list (car old-vhdl-port-list))
10720 (setq new-port-list nil)
10721 (while old-port-list
10722 (setq old-port (car old-port-list))
10723 (setq names (car old-port))
10725 (setq new-port (cons (if as-alist (car names) (list (car names)))
10727 (setq new-port-list (append new-port-list (list new-port)))
10728 (setq names (cdr names)))
10729 (setq old-port-list (cdr old-port-list)))
10730 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10731 (setq new-vhdl-port-list (append new-vhdl-port-list
10732 (list new-port-list))))
10733 (setq vhdl-port-list
10734 (append new-vhdl-port-list (list old-vhdl-port-list))
10735 vhdl-port-flattened t)
10736 (message "Flattening port...done"))))
10738 (defvar vhdl-port-reversed-direction nil
10739 "Indicates whether port directions are reversed.")
10741 (defun vhdl-port-reverse-direction ()
10742 "Reverse direction for all ports (useful in testbenches)."
10744 (if (not vhdl-port-list)
10745 (error "ERROR: No port has been read")
10746 (message "Reversing port directions...")
10747 (let ((port-list (nth 2 vhdl-port-list))
10748 port-dir-car port-dir)
10749 ;; traverse port list and reverse directions
10751 (setq port-dir-car (cddr (car port-list))
10752 port-dir (car port-dir-car))
10753 (setcar port-dir-car
10754 (cond ((equal port-dir "in") "out")
10755 ((equal port-dir "out") "in")
10757 (setq port-list (cdr port-list)))
10758 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10759 (message "Reversing port directions...done"))))
10761 (defun vhdl-port-copy ()
10762 "Get generic and port information from an entity or component declaration."
10765 (let (parse-error end-of-list
10766 decl-type name generic-list port-list context-clause
10767 object names direct type init comment group-comment)
10768 (vhdl-prepare-search-2
10772 ;; check if within entity or component declaration
10774 (when (or (not (re-search-backward
10775 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10776 (equal "END" (upcase (match-string 1))))
10777 (throw 'parse "ERROR: Not within an entity or component declaration"))
10778 (setq decl-type (downcase (match-string-no-properties 1)))
10780 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10781 (setq name (match-string-no-properties 1))
10782 (message "Reading port of %s \"%s\"..." decl-type name)
10783 (vhdl-forward-syntactic-ws)
10784 ;; parse generic clause
10785 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10786 ;; parse group comment and spacing
10787 (setq group-comment (vhdl-parse-group-comment))
10788 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10789 (while (not end-of-list)
10791 (vhdl-parse-string "\\(\\w+\\)[ \t\n]*")
10792 (setq names (list (match-string-no-properties 1)))
10793 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
10795 (append names (list (match-string-no-properties 1)))))
10797 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
10798 (setq type (match-string-no-properties 1))
10800 (while (looking-at "(")
10803 (buffer-substring-no-properties
10804 (point) (progn (forward-sexp) (point)))
10805 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
10806 (match-string-no-properties 1)))))
10807 ;; special case: closing parenthesis is on separate line
10808 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10809 (setq comment (substring type (match-beginning 2)))
10810 (setq type (substring type 0 (match-beginning 1))))
10811 ;; strip of trailing group-comment
10812 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10813 (setq type (substring type 0 (match-end 1)))
10814 ;; parse initialization expression
10816 (when (vhdl-parse-string ":=[ \t\n]*" t)
10817 (vhdl-parse-string "\\([^();\n]*\\)")
10818 (setq init (match-string-no-properties 1))
10819 (while (looking-at "(")
10822 (buffer-substring-no-properties
10823 (point) (progn (forward-sexp) (point)))
10824 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10825 (match-string-no-properties 1))))))
10826 ;; special case: closing parenthesis is on separate line
10827 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10828 (setq comment (substring init (match-beginning 2)))
10829 (setq init (substring init 0 (match-beginning 1)))
10830 (vhdl-forward-syntactic-ws))
10831 (skip-chars-forward " \t")
10832 ;; parse inline comment, special case: as above, no initial.
10834 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10835 (match-string-no-properties 1))))
10836 (vhdl-forward-syntactic-ws)
10837 (setq end-of-list (vhdl-parse-string ")" t))
10838 (vhdl-parse-string "\\s-*;\\s-*")
10839 ;; parse inline comment
10841 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10842 (match-string-no-properties 1))))
10843 ;; save everything in list
10844 (setq generic-list (append generic-list
10845 (list (list names type init
10846 comment group-comment))))
10847 ;; parse group comment and spacing
10848 (setq group-comment (vhdl-parse-group-comment))))
10849 ;; parse port clause
10850 (when (vhdl-parse-string "port[ \t\n]*(" t)
10851 ;; parse group comment and spacing
10852 (setq group-comment (vhdl-parse-group-comment))
10853 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10854 (while (not end-of-list)
10857 (and (vhdl-parse-string "\\(signal\\|quantity\\|terminal\\)[ \t\n]*" t)
10858 (match-string-no-properties 1)))
10859 ;; parse names (accept extended identifiers)
10860 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10861 (setq names (list (match-string-no-properties 1)))
10862 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
10863 (setq names (append names (list (match-string-no-properties 1)))))
10865 (vhdl-parse-string ":[ \t\n]*")
10867 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
10868 (match-string-no-properties 1)))
10870 (vhdl-parse-string "\\([^();\n]+\\)")
10871 (setq type (match-string-no-properties 1))
10873 (while (looking-at "(")
10874 (setq type (concat type
10875 (buffer-substring-no-properties
10876 (point) (progn (forward-sexp) (point)))
10877 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10878 (match-string-no-properties 1)))))
10879 ;; special case: closing parenthesis is on separate line
10880 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10881 (setq comment (substring type (match-beginning 2)))
10882 (setq type (substring type 0 (match-beginning 1))))
10883 ;; strip of trailing group-comment
10884 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10885 (setq type (substring type 0 (match-end 1)))
10886 (vhdl-forward-syntactic-ws)
10887 (setq end-of-list (vhdl-parse-string ")" t))
10888 (vhdl-parse-string "\\s-*;\\s-*")
10889 ;; parse inline comment
10891 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10892 (match-string-no-properties 1))))
10893 ;; save everything in list
10894 (setq port-list (append port-list
10895 (list (list names object direct type
10896 comment group-comment))))
10897 ;; parse group comment and spacing
10898 (setq group-comment (vhdl-parse-group-comment))))
10899 ; (vhdl-parse-string "end\\>")
10900 ;; parse context clause
10901 (setq context-clause (vhdl-scan-context-clause))
10902 ; ;; add surrounding package to context clause
10903 ; (when (and (equal decl-type "component")
10904 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
10905 ; (setq context-clause
10906 ; (append context-clause
10907 ; (list (cons (vhdl-work-library)
10908 ; (match-string-no-properties 1))))))
10909 (message "Reading port of %s \"%s\"...done" decl-type name)
10913 (error parse-error)
10914 (setq vhdl-port-list (list name generic-list port-list context-clause)
10915 vhdl-port-reversed-direction nil
10916 vhdl-port-flattened nil)))))
10918 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
10919 "Paste a context clause."
10920 (let ((margin (current-indentation))
10921 (clause-list (nth 3 vhdl-port-list))
10924 (setq clause (car clause-list))
10925 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
10926 (downcase exclude-pack-name)))
10928 (re-search-backward
10929 (concat "^\\s-*use\\s-+" (car clause)
10930 "\." (cdr clause) "\\>") nil t)))
10931 (vhdl-template-standard-package (car clause) (cdr clause))
10933 (setq clause-list (cdr clause-list)))))
10935 (defun vhdl-port-paste-generic (&optional no-init)
10936 "Paste a generic clause."
10937 (let ((margin (current-indentation))
10938 (generic-list (nth 1 vhdl-port-list))
10939 list-margin start names generic)
10940 ;; paste generic clause
10942 (setq start (point))
10943 (vhdl-insert-keyword "GENERIC (")
10944 (unless vhdl-argument-list-indent
10945 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10946 (setq list-margin (current-column))
10947 (while generic-list
10948 (setq generic (car generic-list))
10949 ;; paste group comment and spacing
10950 (when (memq vhdl-include-group-comments '(decl always))
10951 (vhdl-paste-group-comment (nth 4 generic) list-margin))
10953 (setq names (nth 0 generic))
10955 (insert (car names))
10956 (setq names (cdr names))
10957 (when names (insert ", ")))
10959 (insert " : " (nth 1 generic))
10960 ;; paste initialization
10961 (when (and (not no-init) (nth 2 generic))
10962 (insert " := " (nth 2 generic)))
10963 (unless (cdr generic-list) (insert ")"))
10966 (when (and vhdl-include-port-comments (nth 3 generic))
10967 (vhdl-comment-insert-inline (nth 3 generic) t))
10968 (setq generic-list (cdr generic-list))
10969 (when generic-list (insert "\n") (indent-to list-margin)))
10970 ;; align generic clause
10971 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
10973 (defun vhdl-port-paste-port ()
10974 "Paste a port clause."
10975 (let ((margin (current-indentation))
10976 (port-list (nth 2 vhdl-port-list))
10977 list-margin start names port)
10978 ;; paste port clause
10980 (setq start (point))
10981 (vhdl-insert-keyword "PORT (")
10982 (unless vhdl-argument-list-indent
10983 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10984 (setq list-margin (current-column))
10986 (setq port (car port-list))
10987 ;; paste group comment and spacing
10988 (when (memq vhdl-include-group-comments '(decl always))
10989 (vhdl-paste-group-comment (nth 5 port) list-margin))
10991 (when (nth 1 port) (insert (nth 1 port) " "))
10993 (setq names (nth 0 port))
10995 (insert (car names))
10996 (setq names (cdr names))
10997 (when names (insert ", ")))
11000 (when (nth 2 port) (insert (nth 2 port) " "))
11002 (insert (nth 3 port))
11003 (unless (cdr port-list) (insert ")"))
11006 (when (and vhdl-include-port-comments (nth 4 port))
11007 (vhdl-comment-insert-inline (nth 4 port) t))
11008 (setq port-list (cdr port-list))
11009 (when port-list (insert "\n") (indent-to list-margin)))
11010 ;; align port clause
11011 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11013 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11014 "Paste as an entity or component declaration."
11015 (unless no-indent (indent-according-to-mode))
11016 (let ((margin (current-indentation))
11017 (name (nth 0 vhdl-port-list)))
11018 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11020 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11021 (vhdl-insert-keyword " IS"))
11022 ;; paste generic and port clause
11023 (when (nth 1 vhdl-port-list)
11025 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11027 (indent-to (+ margin vhdl-basic-offset))
11028 (vhdl-port-paste-generic (eq kind 'component)))
11029 (when (nth 2 vhdl-port-list)
11031 (when (and (memq vhdl-insert-empty-lines '(unit all))
11034 (indent-to (+ margin vhdl-basic-offset)))
11035 (vhdl-port-paste-port)
11037 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11040 (vhdl-insert-keyword "END")
11041 (if (eq kind 'entity)
11043 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11045 (vhdl-insert-keyword " COMPONENT")
11046 (unless (vhdl-standard-p '87) (insert " " name)))
11049 (defun vhdl-port-paste-entity (&optional no-indent)
11050 "Paste as an entity declaration."
11052 (if (not vhdl-port-list)
11053 (error "ERROR: No port read")
11054 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11055 (vhdl-port-paste-declaration 'entity no-indent)
11056 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11058 (defun vhdl-port-paste-component (&optional no-indent)
11059 "Paste as a component declaration."
11061 (if (not vhdl-port-list)
11062 (error "ERROR: No port read")
11063 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11064 (vhdl-port-paste-declaration 'component no-indent)
11065 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11067 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11068 "Paste as a generic map."
11070 (unless secondary (indent-according-to-mode))
11071 (let ((margin (current-indentation))
11072 list-margin start generic
11073 (generic-list (nth 1 vhdl-port-list)))
11075 (setq start (point))
11076 (vhdl-insert-keyword "GENERIC MAP (")
11077 (if (not vhdl-association-list-with-formals)
11078 ;; paste list of actual generics
11079 (while generic-list
11080 (insert (if no-constants
11081 (car (nth 0 (car generic-list)))
11082 (or (nth 2 (car generic-list)) " ")))
11083 (setq generic-list (cdr generic-list))
11084 (insert (if generic-list ", " ")")))
11085 (unless vhdl-argument-list-indent
11086 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11087 (setq list-margin (current-column))
11088 (while generic-list
11089 (setq generic (car generic-list))
11090 ;; paste group comment and spacing
11091 (when (eq vhdl-include-group-comments 'always)
11092 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11093 ;; paste formal and actual generic
11094 (insert (car (nth 0 generic)) " => "
11096 (car (nth 0 generic))
11097 (or (nth 2 generic) "")))
11098 (setq generic-list (cdr generic-list))
11099 (insert (if generic-list "," ")"))
11101 (when (or vhdl-include-type-comments
11102 (and vhdl-include-port-comments (nth 3 generic)))
11103 (vhdl-comment-insert-inline
11105 (when vhdl-include-type-comments
11106 (concat "[" (nth 1 generic) "] "))
11107 (when vhdl-include-port-comments (nth 3 generic))) t))
11108 (when generic-list (insert "\n") (indent-to list-margin)))
11109 ;; align generic map
11110 (when vhdl-auto-align
11111 (vhdl-align-region-groups start (point) 1 t))))))
11113 (defun vhdl-port-paste-port-map ()
11114 "Paste as a port map."
11115 (let ((margin (current-indentation))
11116 list-margin start port
11117 (port-list (nth 2 vhdl-port-list)))
11119 (setq start (point))
11120 (vhdl-insert-keyword "PORT MAP (")
11121 (if (not vhdl-association-list-with-formals)
11122 ;; paste list of actual ports
11124 (insert (vhdl-replace-string vhdl-actual-port-name
11125 (car (nth 0 (car port-list)))))
11126 (setq port-list (cdr port-list))
11127 (insert (if port-list ", " ");")))
11128 (unless vhdl-argument-list-indent
11129 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11130 (setq list-margin (current-column))
11132 (setq port (car port-list))
11133 ;; paste group comment and spacing
11134 (when (eq vhdl-include-group-comments 'always)
11135 (vhdl-paste-group-comment (nth 5 port) list-margin))
11136 ;; paste formal and actual port
11137 (insert (car (nth 0 port)) " => ")
11138 (insert (vhdl-replace-string vhdl-actual-port-name
11139 (car (nth 0 port))))
11140 (setq port-list (cdr port-list))
11141 (insert (if port-list "," ");"))
11143 (when (or vhdl-include-direction-comments
11144 vhdl-include-type-comments
11145 (and vhdl-include-port-comments (nth 4 port)))
11146 (vhdl-comment-insert-inline
11148 (cond ((and vhdl-include-direction-comments
11149 vhdl-include-type-comments)
11150 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11151 (nth 3 port) "] "))
11152 ((and vhdl-include-direction-comments (nth 2 port))
11153 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11154 (vhdl-include-direction-comments " ")
11155 (vhdl-include-type-comments
11156 (concat "[" (nth 3 port) "] ")))
11157 (when vhdl-include-port-comments (nth 4 port))) t))
11158 (when port-list (insert "\n") (indent-to list-margin)))
11159 ;; align port clause
11160 (when vhdl-auto-align
11161 (vhdl-align-region-groups start (point) 1))))))
11163 (defun vhdl-port-paste-instance (&optional name no-indent title)
11164 "Paste as an instantiation."
11166 (if (not vhdl-port-list)
11167 (error "ERROR: No port read")
11168 (let ((orig-vhdl-port-list vhdl-port-list))
11169 ;; flatten local copy of port list (must be flat for port mapping)
11170 (vhdl-port-flatten)
11171 (unless no-indent (indent-according-to-mode))
11172 (let ((margin (current-indentation)))
11173 ;; paste instantiation
11176 ((equal (cdr vhdl-instance-name) "")
11177 (setq name (vhdl-template-field "instance name")))
11178 ((string-match "\%d" (cdr vhdl-instance-name))
11180 (while (save-excursion
11181 (setq name (format (vhdl-replace-string
11183 (nth 0 vhdl-port-list)) n))
11184 (goto-char (point-min))
11185 (vhdl-re-search-forward name nil t))
11188 (t (insert (vhdl-replace-string vhdl-instance-name
11189 (nth 0 vhdl-port-list)))))
11190 (message "Pasting port as instantiation \"%s\"..." name)
11194 (beginning-of-line)
11195 (indent-to vhdl-basic-offset)
11196 (insert "-- instance \"" name "\"\n")))
11197 (if (not (vhdl-use-direct-instantiation))
11198 (insert (nth 0 vhdl-port-list))
11199 (vhdl-insert-keyword "ENTITY ")
11200 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11201 (when (nth 1 vhdl-port-list)
11202 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11203 (vhdl-port-paste-generic-map t t))
11204 (when (nth 2 vhdl-port-list)
11205 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11206 (vhdl-port-paste-port-map))
11207 (message "Pasting port as instantiation \"%s\"...done" name))
11208 (setq vhdl-port-list orig-vhdl-port-list))))
11210 (defun vhdl-port-paste-constants (&optional no-indent)
11211 "Paste generics as constants."
11213 (if (not vhdl-port-list)
11214 (error "ERROR: No port read")
11215 (let ((orig-vhdl-port-list vhdl-port-list))
11216 (message "Pasting port as constants...")
11217 ;; flatten local copy of port list (must be flat for constant initial.)
11218 (vhdl-port-flatten)
11219 (unless no-indent (indent-according-to-mode))
11220 (let ((margin (current-indentation))
11222 (generic-list (nth 1 vhdl-port-list)))
11224 (setq start (point))
11225 (while generic-list
11226 (setq generic (car generic-list))
11227 ;; paste group comment and spacing
11228 (when (memq vhdl-include-group-comments '(decl always))
11229 (vhdl-paste-group-comment (nth 4 generic) margin))
11230 (vhdl-insert-keyword "CONSTANT ")
11231 ;; paste generic constants
11232 (setq name (nth 0 generic))
11234 (insert (car name))
11236 (insert " : " (nth 1 generic))
11237 ;; paste initialization
11238 (when (nth 2 generic)
11239 (insert " := " (nth 2 generic)))
11242 (when (and vhdl-include-port-comments (nth 3 generic))
11243 (vhdl-comment-insert-inline (nth 3 generic) t))
11244 (setq generic-list (cdr generic-list))
11245 (when generic-list (insert "\n") (indent-to margin))))
11246 ;; align signal list
11247 (when vhdl-auto-align
11248 (vhdl-align-region-groups start (point) 1))))
11249 (message "Pasting port as constants...done")
11250 (setq vhdl-port-list orig-vhdl-port-list))))
11252 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11253 "Paste ports as internal signals."
11255 (if (not vhdl-port-list)
11256 (error "ERROR: No port read")
11257 (message "Pasting port as signals...")
11258 (unless no-indent (indent-according-to-mode))
11259 (let ((margin (current-indentation))
11261 (port-list (nth 2 vhdl-port-list)))
11263 (setq start (point))
11265 (setq port (car port-list))
11266 ;; paste group comment and spacing
11267 (when (memq vhdl-include-group-comments '(decl always))
11268 (vhdl-paste-group-comment (nth 5 port) margin))
11271 (insert (nth 1 port) " ")
11272 (vhdl-insert-keyword "SIGNAL "))
11273 ;; paste actual port signals
11274 (setq names (nth 0 port))
11276 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11277 (setq names (cdr names))
11278 (when names (insert ", ")))
11280 (insert " : " (nth 3 port))
11281 ;; paste initialization (inputs only)
11282 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11283 (insert " := " (if (string-match "(.+)" (nth 3 port))
11284 "(others => '0')" "'0'")))
11287 (when (or vhdl-include-direction-comments
11288 (and vhdl-include-port-comments (nth 4 port)))
11289 (vhdl-comment-insert-inline
11291 (cond ((and vhdl-include-direction-comments (nth 2 port))
11292 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11293 (vhdl-include-direction-comments " "))
11294 (when vhdl-include-port-comments (nth 4 port))) t))
11295 (setq port-list (cdr port-list))
11296 (when port-list (insert "\n") (indent-to margin)))
11297 ;; align signal list
11298 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11299 (message "Pasting port as signals...done")))
11301 (defun vhdl-port-paste-initializations (&optional no-indent)
11302 "Paste ports as signal initializations."
11304 (if (not vhdl-port-list)
11305 (error "ERROR: No port read")
11306 (let ((orig-vhdl-port-list vhdl-port-list))
11307 (message "Pasting port as initializations...")
11308 ;; flatten local copy of port list (must be flat for signal initial.)
11309 (vhdl-port-flatten)
11310 (unless no-indent (indent-according-to-mode))
11311 (let ((margin (current-indentation))
11313 (port-list (nth 2 vhdl-port-list)))
11315 (setq start (point))
11317 (setq port (car port-list))
11318 ;; paste actual port signal (inputs only)
11319 (when (equal "IN" (upcase (nth 2 port)))
11320 (setq name (car (nth 0 port)))
11321 (insert (vhdl-replace-string vhdl-actual-port-name name))
11322 ;; paste initialization
11323 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11324 "(others => '0')" "'0'") ";"))
11325 (setq port-list (cdr port-list))
11326 (when (and port-list
11327 (equal "IN" (upcase (nth 2 (car port-list)))))
11328 (insert "\n") (indent-to margin)))
11329 ;; align signal list
11330 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11331 (message "Pasting port as initializations...done")
11332 (setq vhdl-port-list orig-vhdl-port-list))))
11334 (defun vhdl-port-paste-testbench ()
11335 "Paste as a bare-bones testbench."
11337 (if (not vhdl-port-list)
11338 (error "ERROR: No port read")
11339 (let ((case-fold-search t)
11340 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11341 (nth 0 vhdl-port-list)))
11342 (source-buffer (current-buffer))
11343 arch-name config-name ent-file-name arch-file-name
11344 ent-buffer arch-buffer position)
11345 ;; open entity file
11346 (unless (eq vhdl-testbench-create-files 'none)
11347 (setq ent-file-name
11348 (concat ent-name "." (file-name-extension (buffer-file-name))))
11349 (if (file-exists-p ent-file-name)
11351 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11352 (progn (find-file ent-file-name)
11354 (set-buffer-modified-p nil))
11355 (if (eq vhdl-testbench-create-files 'separate)
11356 (setq ent-file-name nil)
11357 (error "ERROR: Pasting port as testbench...aborted")))
11358 (find-file ent-file-name)))
11359 (unless (and (eq vhdl-testbench-create-files 'separate)
11360 (null ent-file-name))
11361 ;; paste entity header
11362 (if vhdl-testbench-include-header
11363 (progn (vhdl-template-header
11364 (concat "Testbench for design \""
11365 (nth 0 vhdl-port-list) "\""))
11366 (goto-char (point-max)))
11367 (vhdl-comment-display-line) (insert "\n\n"))
11368 ;; paste std_logic_1164 package
11369 (when vhdl-testbench-include-library
11370 (vhdl-template-package-std-logic-1164)
11371 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11372 ;; paste entity declaration
11373 (vhdl-insert-keyword "ENTITY ")
11375 (vhdl-insert-keyword " IS")
11376 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11378 (vhdl-insert-keyword "END ")
11379 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11380 (insert ent-name ";")
11382 (vhdl-comment-display-line) (insert "\n"))
11383 ;; get architecture name
11384 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11385 (read-from-minibuffer "architecture name: "
11386 nil vhdl-minibuffer-local-map)
11387 (vhdl-replace-string vhdl-testbench-architecture-name
11388 (nth 0 vhdl-port-list))))
11389 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11390 ;; open architecture file
11391 (if (not (eq vhdl-testbench-create-files 'separate))
11393 (setq ent-buffer (current-buffer))
11394 (setq arch-file-name
11395 (concat ent-name "_" arch-name "."
11396 (file-name-extension (buffer-file-name))))
11397 (when (and (file-exists-p arch-file-name)
11398 (not (y-or-n-p (concat "File \"" arch-file-name
11399 "\" exists; overwrite? "))))
11400 (error "ERROR: Pasting port as testbench...aborted"))
11401 (find-file arch-file-name)
11403 (set-buffer-modified-p nil)
11404 ;; paste architecture header
11405 (if vhdl-testbench-include-header
11406 (progn (vhdl-template-header
11407 (concat "Testbench architecture for design \""
11408 (nth 0 vhdl-port-list) "\""))
11409 (goto-char (point-max)))
11410 (vhdl-comment-display-line) (insert "\n\n")))
11411 ;; paste architecture body
11412 (vhdl-insert-keyword "ARCHITECTURE ")
11414 (vhdl-insert-keyword " OF ")
11416 (vhdl-insert-keyword " IS")
11417 (insert "\n\n") (indent-to vhdl-basic-offset)
11418 ;; paste component declaration
11419 (unless (vhdl-use-direct-instantiation)
11420 (vhdl-port-paste-component t)
11421 (insert "\n\n") (indent-to vhdl-basic-offset))
11423 (when (nth 1 vhdl-port-list)
11424 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11425 (vhdl-port-paste-constants t)
11426 (insert "\n\n") (indent-to vhdl-basic-offset))
11427 ;; paste internal signals
11428 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11429 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11431 ;; paste custom declarations
11432 (unless (equal "" vhdl-testbench-declarations)
11434 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11435 (setq position (point))
11437 (vhdl-comment-display-line) (insert "\n")
11438 (when vhdl-testbench-include-configuration
11439 (setq config-name (vhdl-replace-string
11440 vhdl-testbench-configuration-name
11441 (concat ent-name " " arch-name)))
11443 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11444 (vhdl-insert-keyword " OF ") (insert ent-name)
11445 (vhdl-insert-keyword " IS\n")
11446 (indent-to vhdl-basic-offset)
11447 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11448 (indent-to vhdl-basic-offset)
11449 (vhdl-insert-keyword "END FOR;\n")
11450 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11451 (vhdl-comment-display-line) (insert "\n"))
11452 (goto-char position)
11453 (vhdl-template-begin-end
11454 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11455 ;; paste instantiation
11456 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11457 (vhdl-port-paste-instance
11458 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11460 ;; paste custom statements
11461 (unless (equal "" vhdl-testbench-statements)
11463 (vhdl-insert-string-or-file vhdl-testbench-statements))
11465 (indent-to vhdl-basic-offset)
11466 (unless (eq vhdl-testbench-create-files 'none)
11467 (setq arch-buffer (current-buffer))
11468 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11469 (set-buffer arch-buffer) (save-buffer))
11471 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11472 ent-name arch-name)
11474 (format "\n File created: \"%s\"" ent-file-name))
11475 (and arch-file-name
11476 (format "\n File created: \"%s\"" arch-file-name)))))))
11479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11480 ;;; Subprogram interface translation
11481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11483 (defvar vhdl-subprog-list nil
11484 "Variable to hold last subprogram interface parsed.")
11485 ;; structure: (parenthesised expression means list of such entries)
11486 ;; (subprog-name kind
11487 ;; ((names) object direct type init comment group-comment)
11488 ;; return-type return-comment group-comment)
11490 (defvar vhdl-subprog-flattened nil
11491 "Indicates whether an subprogram interface has been flattened.")
11493 (defun vhdl-subprog-flatten ()
11494 "Flatten interface list so that only one parameter exists per line."
11496 (if (not vhdl-subprog-list)
11497 (error "ERROR: No subprogram interface has been read")
11498 (message "Flattening subprogram interface...")
11499 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11500 new-subprog-list old-subprog new-subprog names)
11501 ;; traverse parameter list and flatten entries
11502 (while old-subprog-list
11503 (setq old-subprog (car old-subprog-list))
11504 (setq names (car old-subprog))
11506 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11507 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11508 (setq names (cdr names)))
11509 (setq old-subprog-list (cdr old-subprog-list)))
11510 (setq vhdl-subprog-list
11511 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11512 new-subprog-list (nth 3 vhdl-subprog-list)
11513 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11514 vhdl-subprog-flattened t)
11515 (message "Flattening subprogram interface...done"))))
11517 (defun vhdl-subprog-copy ()
11518 "Get interface information from a subprogram specification."
11521 (let (parse-error pos end-of-list
11522 name kind param-list object names direct type init
11523 comment group-comment
11524 return-type return-comment return-group-comment)
11525 (vhdl-prepare-search-2
11529 ;; check if within function declaration
11532 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11533 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11534 (goto-char (match-end 0))
11535 (save-excursion (backward-char)
11538 (throw 'parse "ERROR: Not within a subprogram specification"))
11539 (setq name (match-string-no-properties 5))
11540 (setq kind (if (match-string 2) 'procedure 'function))
11541 (setq end-of-list (not (match-string 7)))
11542 (message "Reading interface of subprogram \"%s\"..." name)
11543 ;; parse parameter list
11544 (setq group-comment (vhdl-parse-group-comment))
11545 (setq end-of-list (or end-of-list
11546 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11547 (while (not end-of-list)
11550 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11551 (match-string-no-properties 1)))
11552 ;; parse names (accept extended identifiers)
11553 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11554 (setq names (list (match-string-no-properties 1)))
11555 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11556 (setq names (append names (list (match-string-no-properties 1)))))
11558 (vhdl-parse-string ":[ \t\n]*")
11560 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11561 (match-string-no-properties 1)))
11563 (vhdl-parse-string "\\([^():;\n]+\\)")
11564 (setq type (match-string-no-properties 1))
11566 (while (looking-at "(")
11569 (buffer-substring-no-properties
11570 (point) (progn (forward-sexp) (point)))
11571 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11572 (match-string-no-properties 1)))))
11573 ;; special case: closing parenthesis is on separate line
11574 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11575 (setq comment (substring type (match-beginning 2)))
11576 (setq type (substring type 0 (match-beginning 1))))
11577 ;; strip off trailing group-comment
11578 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11579 (setq type (substring type 0 (match-end 1)))
11580 ;; parse initialization expression
11582 (when (vhdl-parse-string ":=[ \t\n]*" t)
11583 (vhdl-parse-string "\\([^();\n]*\\)")
11584 (setq init (match-string-no-properties 1))
11585 (while (looking-at "(")
11588 (buffer-substring-no-properties
11589 (point) (progn (forward-sexp) (point)))
11590 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11591 (match-string-no-properties 1))))))
11592 ;; special case: closing parenthesis is on separate line
11593 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11594 (setq comment (substring init (match-beginning 2)))
11595 (setq init (substring init 0 (match-beginning 1)))
11596 (vhdl-forward-syntactic-ws))
11597 (skip-chars-forward " \t")
11598 ;; parse inline comment, special case: as above, no initial.
11600 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11601 (match-string-no-properties 1))))
11602 (vhdl-forward-syntactic-ws)
11603 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11604 ;; parse inline comment
11606 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11607 (match-string-no-properties 1))))
11608 (setq return-group-comment (vhdl-parse-group-comment))
11609 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11610 ;; parse return type
11611 (when (match-string 3)
11612 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11613 (setq return-type (match-string-no-properties 1))
11614 (when (and return-type
11615 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11616 (setq return-comment (substring return-type (match-beginning 2)))
11617 (setq return-type (substring return-type 0 (match-beginning 1))))
11618 ;; strip of trailing group-comment
11619 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11620 (setq return-type (substring return-type 0 (match-end 1)))
11621 ;; parse return comment
11622 (unless return-comment
11623 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11624 (match-string-no-properties 1)))))
11625 ;; parse inline comment
11627 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11628 (match-string-no-properties 1))))
11629 ;; save everything in list
11630 (setq param-list (append param-list
11631 (list (list names object direct type init
11632 comment group-comment))))
11633 ;; parse group comment and spacing
11634 (setq group-comment (vhdl-parse-group-comment)))
11635 (message "Reading interface of subprogram \"%s\"...done" name)
11639 (error parse-error)
11640 (setq vhdl-subprog-list
11641 (list name kind param-list return-type return-comment
11642 return-group-comment)
11643 vhdl-subprog-flattened nil)))))
11645 (defun vhdl-subprog-paste-specification (kind)
11646 "Paste as a subprogram specification."
11647 (indent-according-to-mode)
11648 (let ((margin (current-column))
11649 (param-list (nth 2 vhdl-subprog-list))
11650 list-margin start names param)
11651 ;; paste keyword and name
11652 (vhdl-insert-keyword
11653 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11654 (insert (nth 0 vhdl-subprog-list))
11655 (if (not param-list)
11656 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11657 (setq start (point))
11658 ;; paste parameter list
11660 (unless vhdl-argument-list-indent
11661 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11662 (setq list-margin (current-column))
11664 (setq param (car param-list))
11665 ;; paste group comment and spacing
11666 (when (memq vhdl-include-group-comments (list kind 'always))
11667 (vhdl-paste-group-comment (nth 6 param) list-margin))
11669 (when (nth 1 param) (insert (nth 1 param) " "))
11671 (setq names (nth 0 param))
11673 (insert (car names))
11674 (setq names (cdr names))
11675 (when names (insert ", ")))
11678 (when (nth 2 param) (insert (nth 2 param) " "))
11680 (insert (nth 3 param))
11681 ;; paste initialization
11682 (when (nth 4 param) (insert " := " (nth 4 param)))
11684 (if (cdr param-list)
11687 (when (null (nth 3 vhdl-subprog-list))
11688 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11690 (when (and vhdl-include-port-comments (nth 5 param))
11691 (vhdl-comment-insert-inline (nth 5 param) t))
11692 (setq param-list (cdr param-list))
11693 (when param-list (insert "\n") (indent-to list-margin)))
11694 (when (nth 3 vhdl-subprog-list)
11695 (insert "\n") (indent-to list-margin)
11696 ;; paste group comment and spacing
11697 (when (memq vhdl-include-group-comments (list kind 'always))
11698 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11699 ;; paste return type
11700 (insert "return " (nth 3 vhdl-subprog-list))
11701 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11702 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11703 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11704 ;; align parameter list
11705 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11707 (when (eq kind 'body)
11709 (vhdl-template-begin-end
11710 (unless (vhdl-standard-p '87)
11711 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11712 (nth 0 vhdl-subprog-list) margin))))
11714 (defun vhdl-subprog-paste-declaration ()
11715 "Paste as a subprogram declaration."
11717 (if (not vhdl-subprog-list)
11718 (error "ERROR: No subprogram interface read")
11719 (message "Pasting interface as subprogram declaration \"%s\"..."
11720 (car vhdl-subprog-list))
11721 ;; paste specification
11722 (vhdl-subprog-paste-specification 'decl)
11723 (message "Pasting interface as subprogram declaration \"%s\"...done"
11724 (car vhdl-subprog-list))))
11726 (defun vhdl-subprog-paste-body ()
11727 "Paste as a subprogram body."
11729 (if (not vhdl-subprog-list)
11730 (error "ERROR: No subprogram interface read")
11731 (message "Pasting interface as subprogram body \"%s\"..."
11732 (car vhdl-subprog-list))
11733 ;; paste specification and body
11734 (vhdl-subprog-paste-specification 'body)
11735 (message "Pasting interface as subprogram body \"%s\"...done"
11736 (car vhdl-subprog-list))))
11738 (defun vhdl-subprog-paste-call ()
11739 "Paste as a subprogram call."
11741 (if (not vhdl-subprog-list)
11742 (error "ERROR: No subprogram interface read")
11743 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11744 param-list margin list-margin param start)
11745 ;; flatten local copy of interface list (must be flat for parameter mapping)
11746 (vhdl-subprog-flatten)
11747 (setq param-list (nth 2 vhdl-subprog-list))
11748 (indent-according-to-mode)
11749 (setq margin (current-indentation))
11750 (message "Pasting interface as subprogram call \"%s\"..."
11751 (car vhdl-subprog-list))
11753 (insert (nth 0 vhdl-subprog-list))
11754 (if (not param-list)
11756 (setq start (point))
11757 ;; paste parameter list
11759 (unless vhdl-argument-list-indent
11760 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11761 (setq list-margin (current-column))
11763 (setq param (car param-list))
11764 ;; paste group comment and spacing
11765 (when (eq vhdl-include-group-comments 'always)
11766 (vhdl-paste-group-comment (nth 6 param) list-margin))
11767 ;; paste formal port
11768 (insert (car (nth 0 param)) " => ")
11769 (setq param-list (cdr param-list))
11770 (insert (if param-list "," ");"))
11772 (when (and vhdl-include-port-comments (nth 5 param))
11773 (vhdl-comment-insert-inline (nth 5 param)))
11774 (when param-list (insert "\n") (indent-to list-margin)))
11775 ;; align parameter list
11776 (when vhdl-auto-align
11777 (vhdl-align-region-groups start (point) 1)))
11778 (message "Pasting interface as subprogram call \"%s\"...done"
11779 (car vhdl-subprog-list))
11780 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11785 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11787 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11788 ;; Hippie expand customization
11790 (defvar vhdl-expand-upper-case nil)
11792 (defun vhdl-try-expand-abbrev (old)
11793 "Try expanding abbreviations from `vhdl-abbrev-list'."
11795 (he-init-string (he-dabbrev-beg) (point))
11796 (setq he-expand-list
11797 (let ((abbrev-list vhdl-abbrev-list)
11798 (sel-abbrev-list '()))
11800 (when (or (not (stringp (car abbrev-list)))
11802 (concat "^" he-search-string) (car abbrev-list)))
11803 (setq sel-abbrev-list
11804 (cons (car abbrev-list) sel-abbrev-list)))
11805 (setq abbrev-list (cdr abbrev-list)))
11806 (nreverse sel-abbrev-list))))
11807 (while (and he-expand-list
11808 (or (not (stringp (car he-expand-list)))
11809 (he-string-member (car he-expand-list) he-tried-table t)))
11810 ; (equal (car he-expand-list) he-search-string)))
11811 (unless (stringp (car he-expand-list))
11812 (setq vhdl-expand-upper-case (car he-expand-list)))
11813 (setq he-expand-list (cdr he-expand-list)))
11814 (if (null he-expand-list)
11815 (progn (when old (he-reset-string))
11817 (he-substitute-string
11818 (if vhdl-expand-upper-case
11819 (upcase (car he-expand-list))
11820 (car he-expand-list))
11822 (setq he-expand-list (cdr he-expand-list))
11825 (defun vhdl-he-list-beg ()
11826 "Also looks at the word before `(' in order to better match parenthesized
11827 expressions (e.g. for index ranges of types and signals)."
11830 (progn (backward-up-list 1)
11831 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
11835 ;; override `he-list-beg' from `hippie-exp'
11836 (unless (and (boundp 'viper-mode) viper-mode)
11837 (defalias 'he-list-beg 'vhdl-he-list-beg))
11839 ;; function for expanding abbrevs and dabbrevs
11840 (defun vhdl-expand-abbrev (arg))
11841 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
11842 '(try-expand-dabbrev
11843 try-expand-dabbrev-all-buffers
11844 vhdl-try-expand-abbrev)))
11846 ;; function for expanding parenthesis
11847 (defun vhdl-expand-paren (arg))
11848 (fset 'vhdl-expand-paren (make-hippie-expand-function
11850 try-expand-list-all-buffers)))
11852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11855 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
11856 "Convert all words matching word-regexp in region to lower or upper case,
11857 depending on parameter upper-case."
11858 (let ((case-replace nil)
11860 (vhdl-prepare-search-2
11863 (setq end (point-marker))
11865 (while (re-search-forward word-regexp end t)
11866 (or (vhdl-in-literal)
11869 (downcase-word -1)))
11870 (when (and count vhdl-progress-interval (not noninteractive)
11871 (< vhdl-progress-interval
11872 (- (nth 1 (current-time)) last-update)))
11873 (message "Fixing case... (%2d%s)"
11874 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
11876 (setq last-update (nth 1 (current-time)))))
11877 (goto-char end)))))
11879 (defun vhdl-fix-case-region (beg end &optional arg)
11880 "Convert all VHDL words in region to lower or upper case, depending on
11881 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
11882 (interactive "r\nP")
11883 (vhdl-fix-case-region-1
11884 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
11885 (vhdl-fix-case-region-1
11886 beg end vhdl-upper-case-types vhdl-types-regexp 1)
11887 (vhdl-fix-case-region-1
11888 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
11889 (vhdl-fix-case-region-1
11890 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
11891 (when vhdl-progress-interval (message "Fixing case...done")))
11893 (defun vhdl-fix-case-buffer ()
11894 "Convert all VHDL words in buffer to lower or upper case, depending on
11895 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
11897 (vhdl-fix-case-region (point-min) (point-max)))
11899 (defun vhdl-fix-case-word (&optional arg)
11900 "Convert word after cursor to upper case if necessary."
11903 (when arg (backward-word 1))
11904 (vhdl-prepare-search-1
11905 (when (and vhdl-upper-case-keywords
11906 (looking-at vhdl-keywords-regexp))
11908 (when (and vhdl-upper-case-types
11909 (looking-at vhdl-types-regexp))
11911 (when (and vhdl-upper-case-attributes
11912 (looking-at vhdl-attributes-regexp))
11914 (when (and vhdl-upper-case-enum-values
11915 (looking-at vhdl-enum-values-regexp))
11916 (upcase-word 1)))))
11918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11919 ;; Line handling functions
11921 (defun vhdl-current-line ()
11922 "Return the line number of the line containing point."
11926 (beginning-of-line)
11927 (1+ (count-lines 1 (point))))))
11929 (defun vhdl-line-kill-entire (&optional arg)
11930 "Delete entire line."
11932 (beginning-of-line)
11933 (kill-line (or arg 1)))
11935 (defun vhdl-line-kill (&optional arg)
11936 "Kill current line."
11938 (vhdl-line-kill-entire arg))
11940 (defun vhdl-line-copy (&optional arg)
11941 "Copy current line."
11944 (beginning-of-line)
11945 (let ((position (point)))
11946 (forward-line (or arg 1))
11947 (copy-region-as-kill position (point)))))
11949 (defun vhdl-line-yank ()
11950 "Yank entire line."
11952 (beginning-of-line)
11955 (defun vhdl-line-expand (&optional prefix-arg)
11956 "Hippie-expand current line."
11958 (let ((case-fold-search t) (case-replace nil)
11959 (hippie-expand-try-functions-list
11960 '(try-expand-line try-expand-line-all-buffers)))
11961 (hippie-expand prefix-arg)))
11963 (defun vhdl-line-transpose-next (&optional arg)
11964 "Interchange this line with next line."
11967 (transpose-lines (or arg 1))
11970 (defun vhdl-line-transpose-previous (&optional arg)
11971 "Interchange this line with previous line."
11974 (transpose-lines (- 0 (or arg 0)))
11977 (defun vhdl-line-open ()
11978 "Open a new line and indent."
11981 (newline-and-indent))
11983 (defun vhdl-delete-indentation ()
11984 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
11985 it works within comments too."
11987 (let ((fill-prefix "-- "))
11988 (delete-indentation)))
11990 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11993 (defun vhdl-forward-same-indent ()
11994 "Move forward to next line with same indent."
11996 (let ((pos (point))
11997 (indent (current-indentation)))
11998 (beginning-of-line 2)
11999 (while (and (not (eobp))
12000 (or (looking-at "^\\s-*\\(--.*\\)?$")
12001 (> (current-indentation) indent)))
12002 (beginning-of-line 2))
12003 (if (= (current-indentation) indent)
12004 (back-to-indentation)
12005 (message "No following line with same indent found in this block")
12009 (defun vhdl-backward-same-indent ()
12010 "Move backward to previous line with same indent."
12012 (let ((pos (point))
12013 (indent (current-indentation)))
12014 (beginning-of-line -0)
12015 (while (and (not (bobp))
12016 (or (looking-at "^\\s-*\\(--.*\\)?$")
12017 (> (current-indentation) indent)))
12018 (beginning-of-line -0))
12019 (if (= (current-indentation) indent)
12020 (back-to-indentation)
12021 (message "No preceding line with same indent found in this block")
12025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12028 (defun vhdl-statistics-buffer ()
12029 "Get some file statistics."
12033 (no-lines (count-lines (point-min) (point-max))))
12035 ;; count statements
12036 (goto-char (point-min))
12037 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12038 (if (match-string 1)
12039 (goto-char (match-end 1))
12040 (setq no-stats (1+ no-stats))))
12041 ;; count code lines
12042 (goto-char (point-min))
12043 (while (not (eobp))
12044 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12045 (setq no-code-lines (1+ no-code-lines)))
12046 (beginning-of-line 2)))
12049 File statistics: \"%s\"\n\
12050 ---------------------\n\
12051 # statements : %5d\n\
12052 # code lines : %5d\n\
12053 # total lines : %5d\n\ "
12054 (buffer-file-name) no-stats no-code-lines no-lines)
12055 (unless vhdl-emacs-21 (vhdl-show-messages))))
12057 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12060 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12061 "Like `re-search-forward', but does not match within literals."
12064 (while (and (setq pos (re-search-forward regexp bound noerror count))
12065 (vhdl-in-literal))))
12066 (when pos (goto-char pos))
12069 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12070 "Like `re-search-backward', but does not match within literals."
12073 (while (and (setq pos (re-search-backward regexp bound noerror count))
12074 (vhdl-in-literal))))
12075 (when pos (goto-char pos))
12079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12083 (defun vhdl-set-project (name)
12084 "Set current project to NAME."
12086 (list (let ((completion-ignore-case t))
12087 (completing-read "Project name: " vhdl-project-alist nil t))))
12088 (cond ((equal name "")
12089 (setq vhdl-project nil)
12090 (message "Current VHDL project: None"))
12091 ((assoc name vhdl-project-alist)
12092 (setq vhdl-project name)
12093 (message "Current VHDL project: \"%s\"" name))
12095 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12096 (vhdl-speedbar-update-current-project))
12098 (defun vhdl-toggle-project (name token indent)
12099 "Set current project to NAME or unset if NAME is current project."
12100 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12102 (defun vhdl-export-project (file-name)
12103 "Write project setup for current project."
12105 (let ((name (vhdl-resolve-env-variable
12106 (vhdl-replace-string
12107 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12108 (concat (subst-char-in-string
12109 ? ?_ (or (vhdl-project-p)
12110 (error "ERROR: No current project")))
12111 " " (user-login-name))))))
12112 (list (read-file-name
12113 "Write project file: "
12114 (when (file-name-absolute-p name) "") nil nil name))))
12115 (setq file-name (abbreviate-file-name file-name))
12116 (let ((orig-buffer (current-buffer)))
12117 (unless (file-exists-p (file-name-directory file-name))
12118 (make-directory (file-name-directory file-name) t))
12119 (if (not (file-writable-p file-name))
12120 (error "ERROR: File not writable: \"%s\"" file-name)
12121 (set-buffer (find-file-noselect file-name t t))
12123 (insert ";; -*- Emacs-Lisp -*-\n\n"
12124 ";;; " (file-name-nondirectory file-name)
12125 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12126 ";; Project : " vhdl-project "\n"
12127 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12128 (user-login-name) "\n\n\n"
12129 ";; project name\n"
12130 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12131 ";; project setup\n"
12132 "(aput 'vhdl-project-alist vhdl-project\n'")
12133 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12136 (kill-buffer (current-buffer))
12137 (set-buffer orig-buffer))))
12139 (defun vhdl-import-project (file-name &optional auto not-make-current)
12140 "Read project setup and set current project."
12142 (let ((name (vhdl-resolve-env-variable
12143 (vhdl-replace-string
12144 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12145 (concat "" " " (user-login-name))))))
12146 (list (read-file-name
12147 "Read project file: " (when (file-name-absolute-p name) "") nil t
12148 (file-name-directory name)))))
12149 (when (file-exists-p file-name)
12151 (let ((current-project vhdl-project))
12152 (load-file file-name)
12153 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12154 (adelete 'vhdl-project-alist vhdl-project)
12156 (when not-make-current
12157 (setq vhdl-project current-project))
12158 (vhdl-update-mode-menu)
12159 (vhdl-speedbar-refresh)
12160 (unless not-make-current
12161 (message "Current VHDL project: \"%s\"%s"
12162 vhdl-project (if auto " (auto-loaded)" ""))))
12163 (error (vhdl-warning
12164 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12166 (defun vhdl-duplicate-project ()
12167 "Duplicate setup of current project."
12169 (let ((new-name (read-from-minibuffer "New project name: "))
12170 (project-entry (aget vhdl-project-alist vhdl-project t)))
12171 (setq vhdl-project-alist
12172 (append vhdl-project-alist
12173 (list (cons new-name project-entry))))
12174 (vhdl-update-mode-menu)))
12176 (defun vhdl-auto-load-project ()
12177 "Automatically load project setup at startup."
12178 (let ((file-name-list vhdl-project-file-name)
12179 file-list list-length)
12180 (while file-name-list
12183 (file-expand-wildcards
12184 (vhdl-resolve-env-variable
12185 (vhdl-replace-string
12186 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12187 (concat "\*" " " (user-login-name)))))))
12188 (setq list-length (or list-length (length file-list)))
12189 (setq file-name-list (cdr file-name-list)))
12191 (vhdl-import-project (expand-file-name (car file-list)) t
12192 (not (> list-length 0)))
12193 (setq list-length (1- list-length))
12194 (setq file-list (cdr file-list)))))
12196 ;; automatically load project setup when idle after startup
12197 (when (memq 'startup vhdl-project-auto-load)
12199 (vhdl-auto-load-project)
12200 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12206 ;; (using `hideshow.el')
12208 (defconst vhdl-hs-start-regexp
12211 ;; generic/port clause
12212 "\\(generic\\|port\\)[ \t\n]*(\\|"
12215 ;; component instantiation
12216 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12217 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12218 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12219 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12221 "\\(function\\|procedure\\)\\>\\|"
12223 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12224 ;; configuration declaration
12227 "Regexp to match start of construct to hide.")
12229 (defun vhdl-hs-forward-sexp-func (count)
12230 "Find end of construct to hide (for hideshow). Only searches forward."
12231 (let ((pos (point)))
12232 (vhdl-prepare-search-2
12233 (beginning-of-line)
12235 ;; generic/port clause
12236 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12237 (goto-char (match-end 0))
12240 ;; component declaration
12241 ((looking-at "^\\s-*component\\>")
12242 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12243 ;; component instantiation
12246 "^\\s-*\\w+\\s-*:[ \t\n]*"
12247 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12248 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12249 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12250 (goto-char (match-end 0))
12254 (vhdl-forward-syntactic-ws)
12255 (when (looking-at "port\\s-+map[ \t\n]*(")
12256 (goto-char (match-end 0))
12259 (setq pos (point)))
12261 ;; subprogram declaration/body
12262 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12263 (goto-char (match-end 0))
12264 (vhdl-forward-syntactic-ws)
12265 (when (looking-at "(")
12267 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12268 (vhdl-in-literal)))
12270 (when (match-string 2)
12271 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12273 (vhdl-forward-sexp)))
12274 ;; block (recursive)
12275 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12276 (goto-char (match-end 0))
12277 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12278 (match-beginning 2))
12279 (vhdl-hs-forward-sexp-func count)))
12281 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12282 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12283 ;; configuration declaration
12284 ((looking-at "^\\s-*configuration\\>")
12286 (vhdl-forward-sexp))
12287 (t (goto-char pos))))))
12289 (defun vhdl-hideshow-init ()
12290 "Initialize `hideshow'."
12291 (when vhdl-hideshow-menu
12292 (vhdl-hs-minor-mode 1)))
12294 (defun vhdl-hs-minor-mode (&optional arg)
12295 "Toggle hideshow minor mode and update menu bar."
12297 (require 'hideshow)
12298 ;; check for hideshow version 5.x
12299 (if (not (boundp 'hs-block-start-mdata-select))
12300 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12301 ;; initialize hideshow
12302 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12303 (setq hs-special-modes-alist
12304 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12305 'vhdl-hs-forward-sexp-func nil)
12306 hs-special-modes-alist)))
12307 (make-local-variable 'hs-minor-mode-hook)
12308 (if vhdl-hide-all-init
12309 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12310 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12311 (hs-minor-mode arg)
12312 (vhdl-mode-line-update))) ; hack to update menu bar
12315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12318 ;; (using `font-lock.el')
12320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12323 (defun vhdl-within-translate-off ()
12324 "Return point if within translate-off region, else nil."
12325 (and (save-excursion
12326 (re-search-backward
12327 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12328 (equal "off" (match-string 1))
12331 (defun vhdl-start-translate-off (limit)
12332 "Return point before translate-off pragma if before LIMIT, else nil."
12333 (when (re-search-forward
12334 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12335 (match-beginning 0)))
12337 (defun vhdl-end-translate-off (limit)
12338 "Return point after translate-on pragma if before LIMIT, else nil."
12339 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12341 (defun vhdl-match-translate-off (limit)
12342 "Match a translate-off block, setting match-data and returning t, else nil."
12343 (when (< (point) limit)
12344 (let ((start (or (vhdl-within-translate-off)
12345 (vhdl-start-translate-off limit)))
12346 (case-fold-search t))
12348 (let ((end (or (vhdl-end-translate-off limit) limit)))
12349 (set-match-data (list start end))
12350 (goto-char end))))))
12352 (defun vhdl-font-lock-match-item (limit)
12353 "Match, and move over, any declaration item after point. Adapted from
12354 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12355 (condition-case nil
12357 (narrow-to-region (point-min) limit)
12359 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12361 (goto-char (match-end 1))
12362 ;; move to next item
12363 (if (looking-at "\\(\\s-*,\\)")
12364 (goto-char (match-end 1))
12365 (end-of-line) t))))
12368 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12369 ;; Syntax definitions
12371 (defconst vhdl-font-lock-syntactic-keywords
12372 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12373 "Mark single quotes as having string quote syntax in 'c' instances.")
12375 (defvar vhdl-font-lock-keywords nil
12376 "Regular expressions to highlight in VHDL Mode.")
12378 (defvar vhdl-font-lock-keywords-0
12379 ;; set in `vhdl-font-lock-init' because dependent on user options
12380 "For consideration as a value of `vhdl-font-lock-keywords'.
12381 This does highlighting of template prompts and directives (pragmas).")
12383 (defvar vhdl-font-lock-keywords-1 nil
12384 ;; set in `vhdl-font-lock-init' because dependent on user options
12385 "For consideration as a value of `vhdl-font-lock-keywords'.
12386 This does highlighting of keywords and standard identifiers.")
12388 (defconst vhdl-font-lock-keywords-2
12390 ;; highlight names of units, subprograms, and components when declared
12394 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12395 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12396 "\\)\\s-+\\(\\w+\\)")
12397 5 'font-lock-function-name-face)
12399 ;; highlight entity names of architectures and configurations
12401 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12402 2 'font-lock-function-name-face)
12404 ;; highlight labels of common constructs
12407 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12408 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12409 "postponed\\|process\\|"
12410 (when (vhdl-standard-p 'ams) "procedural\\|")
12412 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\)*\\s-*<=\\)")
12413 1 'font-lock-function-name-face)
12415 ;; highlight label and component name of component instantiations
12418 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12419 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12420 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12422 ;; highlight label and instantiated unit of component instantiations
12425 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12426 "\\(component\\|configuration\\|entity\\)\\s-+"
12427 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12428 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12429 '(5 font-lock-function-name-face nil t)
12430 '(7 font-lock-function-name-face nil t))
12432 ;; highlight names and labels at end of constructs
12435 "^\\s-*end\\s-+\\(\\("
12436 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12437 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12438 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12439 (when (vhdl-standard-p 'ams) "procedural\\|")
12441 "\\)\\s-+\\)?\\(\\w*\\)")
12442 5 'font-lock-function-name-face)
12444 ;; highlight labels in exit and next statements
12447 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12448 3 'font-lock-function-name-face)
12450 ;; highlight entity name in attribute specifications
12453 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12454 1 'font-lock-function-name-face)
12456 ;; highlight labels in block and component specifications
12459 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12460 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12461 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12463 ;; highlight names in library clauses
12464 (list "^\\s-*library\\>"
12465 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12467 ;; highlight names in use clauses
12470 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12471 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12472 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12473 '(7 font-lock-function-name-face nil t))
12475 ;; highlight attribute name in attribute declarations/specifications
12478 "^\\s-*attribute\\s-+\\(\\w+\\)")
12479 1 'vhdl-font-lock-attribute-face)
12481 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12484 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12485 3 'font-lock-type-face)
12487 ;; highlight signal/variable/constant declaration names
12488 (list "\\(:[^=]\\)"
12489 '(vhdl-font-lock-match-item
12490 (progn (goto-char (match-beginning 1))
12491 (skip-syntax-backward " ")
12492 (skip-syntax-backward "w_")
12493 (skip-syntax-backward " ")
12494 (while (= (preceding-char) ?,)
12496 (skip-syntax-backward " ")
12497 (skip-syntax-backward "w_")
12498 (skip-syntax-backward " ")))
12499 ; (skip-chars-backward "^-(\n\";")
12500 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12502 ;; highlight formal parameters in component instantiations and subprogram
12505 '(vhdl-font-lock-match-item
12506 (progn (goto-char (match-beginning 1))
12507 (skip-syntax-backward " ")
12508 (while (= (preceding-char) ?\)) (backward-sexp))
12509 (skip-syntax-backward "w_")
12510 (skip-syntax-backward " ")
12511 (when (memq (preceding-char) '(?n ?N))
12512 (goto-char (point-max))))
12513 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12515 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12517 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12518 '(vhdl-font-lock-match-item
12519 (progn (goto-char (match-end 1)) (match-beginning 2))
12520 nil (1 font-lock-variable-name-face)))
12522 "For consideration as a value of `vhdl-font-lock-keywords'.
12523 This does context sensitive highlighting of names and labels.")
12525 (defvar vhdl-font-lock-keywords-3 nil
12526 ;; set in `vhdl-font-lock-init' because dependent on user options
12527 "For consideration as a value of `vhdl-font-lock-keywords'.
12528 This does highlighting of words with special syntax.")
12530 (defvar vhdl-font-lock-keywords-4 nil
12531 ;; set in `vhdl-font-lock-init' because dependent on user options
12532 "For consideration as a value of `vhdl-font-lock-keywords'.
12533 This does highlighting of additional reserved words.")
12535 (defconst vhdl-font-lock-keywords-5
12536 ;; background highlight translate-off regions
12537 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12538 "For consideration as a value of `vhdl-font-lock-keywords'.
12539 This does background highlighting of translate-off regions.")
12541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12542 ;; Font and color definitions
12544 (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
12545 "Face name to use for prompts.")
12547 (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12548 "Face name to use for standardized attributes.")
12550 (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12551 "Face name to use for standardized enumeration values.")
12553 (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12554 "Face name to use for standardized functions and packages.")
12556 (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12557 "Face name to use for directives.")
12559 (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12560 "Face name to use for additional reserved words.")
12562 (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12563 "Face name to use for translate-off regions.")
12565 ;; face names to use for words with special syntax.
12566 (let ((syntax-alist vhdl-special-syntax-alist)
12568 (while syntax-alist
12569 (setq name (vhdl-function-name
12570 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12571 (eval `(defvar ,name ',name
12572 ,(concat "Face name to use for "
12573 (nth 0 (car syntax-alist)) ".")))
12574 (setq syntax-alist (cdr syntax-alist))))
12576 (defgroup vhdl-highlight-faces nil
12577 "Faces for highlighting."
12578 :group 'vhdl-highlight)
12580 ;; add faces used from `font-lock'
12581 (custom-add-to-group
12582 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12583 (custom-add-to-group
12584 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12585 (custom-add-to-group
12586 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12587 (custom-add-to-group
12588 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12589 (custom-add-to-group
12590 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12591 (custom-add-to-group
12592 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12594 (defface vhdl-font-lock-prompt-face
12595 '((((class color) (background light)) (:foreground "Red" :bold t))
12596 (((class color) (background dark)) (:foreground "Pink" :bold t))
12597 (t (:inverse-video t)))
12598 "Font lock mode face used to highlight prompts."
12599 :group 'vhdl-highlight-faces
12600 :group 'font-lock-highlighting-faces)
12602 (defface vhdl-font-lock-attribute-face
12603 '((((class color) (background light)) (:foreground "Orchid"))
12604 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12605 (t (:italic t :bold t)))
12606 "Font lock mode face used to highlight standardized attributes."
12607 :group 'vhdl-highlight-faces
12608 :group 'font-lock-highlighting-faces)
12610 (defface vhdl-font-lock-enumvalue-face
12611 '((((class color) (background light)) (:foreground "SaddleBrown"))
12612 (((class color) (background dark)) (:foreground "BurlyWood"))
12613 (t (:italic t :bold t)))
12614 "Font lock mode face used to highlight standardized enumeration values."
12615 :group 'vhdl-highlight-faces
12616 :group 'font-lock-highlighting-faces)
12618 (defface vhdl-font-lock-function-face
12619 '((((class color) (background light)) (:foreground "Cyan4"))
12620 (((class color) (background dark)) (:foreground "Orchid1"))
12621 (t (:italic t :bold t)))
12622 "Font lock mode face used to highlight standardized functions and packages."
12623 :group 'vhdl-highlight-faces
12624 :group 'font-lock-highlighting-faces)
12626 (defface vhdl-font-lock-directive-face
12627 '((((class color) (background light)) (:foreground "CadetBlue"))
12628 (((class color) (background dark)) (:foreground "Aquamarine"))
12629 (t (:italic t :bold t)))
12630 "Font lock mode face used to highlight directives."
12631 :group 'vhdl-highlight-faces
12632 :group 'font-lock-highlighting-faces)
12634 (defface vhdl-font-lock-reserved-words-face
12635 '((((class color) (background light)) (:foreground "Orange" :bold t))
12636 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12638 "Font lock mode face used to highlight additional reserved words."
12639 :group 'vhdl-highlight-faces
12640 :group 'font-lock-highlighting-faces)
12642 (defface vhdl-font-lock-translate-off-face
12643 '((((class color) (background light)) (:background "LightGray"))
12644 (((class color) (background dark)) (:background "DimGray"))
12646 "Font lock mode face used to background highlight translate-off regions."
12647 :group 'vhdl-highlight-faces
12648 :group 'font-lock-highlighting-faces)
12650 ;; font lock mode faces used to highlight words with special syntax.
12651 (let ((syntax-alist vhdl-special-syntax-alist))
12652 (while syntax-alist
12653 (eval `(defface ,(vhdl-function-name
12654 "vhdl-font-lock" (caar syntax-alist) "face")
12655 '((((class color) (background light))
12656 (:foreground ,(nth 2 (car syntax-alist))))
12657 (((class color) (background dark))
12658 (:foreground ,(nth 3 (car syntax-alist))))
12660 ,(concat "Font lock mode face used to highlight "
12661 (nth 0 (car syntax-alist)) ".")
12662 :group 'vhdl-highlight-faces
12663 :group 'font-lock-highlighting-faces))
12664 (setq syntax-alist (cdr syntax-alist))))
12666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12667 ;; Font lock initialization
12669 (defun vhdl-font-lock-init ()
12670 "Initialize fontification."
12671 ;; highlight template prompts and directives
12672 (setq vhdl-font-lock-keywords-0
12673 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12674 vhdl-template-prompt-syntax ">\\)")
12675 2 'vhdl-font-lock-prompt-face t)
12676 (list (concat "--\\s-*"
12677 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12678 2 'vhdl-font-lock-directive-face t)))
12679 ;; highlight keywords and standardized types, attributes, enumeration
12680 ;; values, and subprograms
12681 (setq vhdl-font-lock-keywords-1
12683 (list (concat "'" vhdl-attributes-regexp)
12684 1 'vhdl-font-lock-attribute-face)
12685 (list vhdl-types-regexp 1 'font-lock-type-face)
12686 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12687 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12688 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12689 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12690 ;; highlight words with special syntax.
12691 (setq vhdl-font-lock-keywords-3
12692 (let ((syntax-alist vhdl-special-syntax-alist)
12694 (while syntax-alist
12697 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12698 (vhdl-function-name
12699 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12701 (setq syntax-alist (cdr syntax-alist)))
12703 ;; highlight additional reserved words
12704 (setq vhdl-font-lock-keywords-4
12705 (list (list vhdl-reserved-words-regexp 1
12706 'vhdl-font-lock-reserved-words-face)))
12707 ;; highlight everything together
12708 (setq vhdl-font-lock-keywords
12710 vhdl-font-lock-keywords-0
12711 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12712 (when (or vhdl-highlight-forbidden-words
12713 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12714 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12715 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12716 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12718 ;; initialize fontification for VHDL Mode
12719 (vhdl-font-lock-init)
12721 (defun vhdl-fontify-buffer ()
12722 "Re-initialize fontification and fontify buffer."
12724 (setq font-lock-defaults
12726 'vhdl-font-lock-keywords nil
12727 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12728 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12729 (when (fboundp 'font-lock-unset-defaults)
12730 (font-lock-unset-defaults)) ; not implemented in XEmacs
12731 (font-lock-set-defaults)
12732 (font-lock-mode nil)
12733 (font-lock-mode t))
12735 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12736 ;; Initialization for postscript printing
12738 (defun vhdl-ps-print-settings ()
12739 "Initialize custom face and page settings for postscript printing."
12740 ;; define custom face settings
12741 (unless (or (not vhdl-print-customize-faces)
12743 (set (make-local-variable 'ps-bold-faces)
12744 '(font-lock-keyword-face
12745 font-lock-type-face
12746 vhdl-font-lock-attribute-face
12747 vhdl-font-lock-enumvalue-face
12748 vhdl-font-lock-directive-face))
12749 (set (make-local-variable 'ps-italic-faces)
12750 '(font-lock-comment-face
12751 font-lock-function-name-face
12752 font-lock-type-face
12753 vhdl-font-lock-attribute-face
12754 vhdl-font-lock-enumvalue-face
12755 vhdl-font-lock-directive-face))
12756 (set (make-local-variable 'ps-underlined-faces)
12757 '(font-lock-string-face))
12758 (setq ps-always-build-face-reference t))
12759 ;; define page settings, so that a line containing 79 characters (default)
12760 ;; fits into one column
12761 (when vhdl-print-two-column
12762 (set (make-local-variable 'ps-landscape-mode) t)
12763 (set (make-local-variable 'ps-number-of-columns) 2)
12764 (set (make-local-variable 'ps-font-size) 7.0)
12765 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12766 (set (make-local-variable 'ps-header-font-size) 9.0)
12767 (set (make-local-variable 'ps-header-offset) 12.0)
12768 (when (eq ps-paper-type 'letter)
12769 (set (make-local-variable 'ps-inter-column) 40.0)
12770 (set (make-local-variable 'ps-left-margin) 40.0)
12771 (set (make-local-variable 'ps-right-margin) 40.0))))
12773 (defun vhdl-ps-print-init ()
12774 "Initialize postscript printing."
12776 (when (boundp 'ps-print-color-p)
12777 (vhdl-ps-print-settings))
12778 (make-local-variable 'ps-print-hook)
12779 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12782 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12783 ;;; Hierarchy browser (using `speedbar.el')
12784 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12785 ;; Allows displaying the hierarchy of all VHDL design units contained in a
12786 ;; directory by using the speedbar.
12788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12791 (defvar vhdl-entity-alist nil
12792 "Cache with entities and corresponding architectures for each
12793 project/directory.")
12794 ;; structure: (parenthesised expression means list of such entries)
12796 ;; (ent-key ent-name ent-file ent-line
12797 ;; (arch-key arch-name arch-file arch-line
12798 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12799 ;; inst-arch-key inst-conf-key inst-lib-key)
12800 ;; (lib-name pack-key))
12801 ;; (lib-name pack-key))
12803 (defvar vhdl-config-alist nil
12804 "Cache with configurations for each project/directory.")
12805 ;; structure: (parenthesised expression means list of such entries)
12807 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
12808 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
12809 ;; inst-conf-key inst-lib-key)
12810 ;; (lib-name pack-key)))
12812 (defvar vhdl-package-alist nil
12813 "Cache with packages for each project/directory.")
12814 ;; structure: (parenthesised expression means list of such entries)
12816 ;; (pack-key pack-name pack-file pack-line
12817 ;; (comp-key comp-name comp-file comp-line)
12818 ;; (func-key func-name func-file func-line)
12819 ;; (lib-name pack-key)
12820 ;; pack-body-file pack-body-line
12821 ;; (func-key func-name func-body-file func-body-line)
12822 ;; (lib-name pack-key)))
12824 (defvar vhdl-ent-inst-alist nil
12825 "Cache with instantiated entities for each project/directory.")
12826 ;; structure: (parenthesised expression means list of such entries)
12827 ;; (cache-key (inst-ent-key))
12829 (defvar vhdl-file-alist nil
12830 "Cache with design units in each file for each project/directory.")
12831 ;; structure: (parenthesised expression means list of such entries)
12833 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
12834 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
12836 (defvar vhdl-directory-alist nil
12837 "Cache with source directories for each project.")
12838 ;; structure: (parenthesised expression means list of such entries)
12839 ;; (cache-key (directory))
12841 (defvar vhdl-speedbar-shown-unit-alist nil
12842 "Alist of design units simultaneously open in the current speedbar for each
12843 directory and project.")
12845 (defvar vhdl-speedbar-shown-project-list nil
12846 "List of projects simultaneously open in the current speedbar.")
12848 (defvar vhdl-updated-project-list nil
12849 "List of projects and directories with updated files.")
12851 (defvar vhdl-modified-file-list nil
12852 "List of modified files to be rescanned for hierarchy updating.")
12854 (defvar vhdl-speedbar-hierarchy-depth 0
12855 "Depth of instantiation hierarchy to display.")
12857 (defvar vhdl-speedbar-show-projects nil
12858 "Non-nil means project hierarchy is displayed in speedbar, directory
12859 hierarchy otherwise.")
12861 (defun vhdl-get-end-of-unit ()
12862 "Return position of end of current unit."
12863 (let ((pos (point)))
12865 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
12867 (goto-char (match-beginning 0))
12868 (vhdl-backward-syntactic-ws)
12869 (and (/= (preceding-char) ?\;) (not (bobp))))))
12870 (re-search-backward "^[ \t]*end\\>" pos 1)
12873 (defun vhdl-match-string-downcase (num &optional string)
12874 "Like `match-string-no-properties' with down-casing."
12875 (let ((match (match-string-no-properties num string)))
12876 (and match (downcase match))))
12879 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12882 (defun vhdl-scan-context-clause ()
12883 "Scan the context clause that preceeds a design unit."
12886 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
12887 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
12888 (equal "USE" (upcase (match-string 1))))
12889 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
12890 (setq lib-alist (cons (cons (match-string-no-properties 1)
12891 (vhdl-match-string-downcase 2))
12895 (defun vhdl-scan-directory-contents (name &optional project update num-string
12897 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
12898 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
12899 ; (unless (file-directory-p (match-string 1 name))
12900 ; (message "No such directory: \"%s\"" (match-string 1 name)))
12901 (let* ((dir-name (match-string 1 name))
12902 (file-pattern (match-string 2 name))
12903 (is-directory (= 0 (length file-pattern)))
12908 (vhdl-get-source-files t dir-name)
12909 (vhdl-directory-files
12910 dir-name t (wildcard-to-regexp file-pattern)))))
12911 (key (or project dir-name))
12912 (file-exclude-regexp
12913 (or (nth 3 (aget vhdl-project-alist project)) ""))
12914 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
12915 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
12916 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
12917 ent-alist conf-alist pack-alist ent-inst-list file-alist
12918 tmp-list tmp-entry no-files files-exist big-files)
12919 (when (or project update)
12920 (setq ent-alist (aget vhdl-entity-alist key t)
12921 conf-alist (aget vhdl-config-alist key t)
12922 pack-alist (aget vhdl-package-alist key t)
12923 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
12924 file-alist (aget vhdl-file-alist key t)))
12925 (when (and (not is-directory) (null file-list))
12926 (message "No such file: \"%s\"" name))
12927 (setq files-exist file-list)
12929 (setq no-files (length file-list))
12930 (message "Scanning %s %s\"%s\"..."
12931 (if is-directory "directory" "files") (or num-string "") name)
12933 (unless (equal file-exclude-regexp "")
12934 (let ((case-fold-search nil)
12937 (unless (string-match file-exclude-regexp (car file-list))
12938 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
12939 (setq file-list (cdr file-list)))
12940 (setq file-list (nreverse file-tmp-list))))
12941 ;; do for all files
12943 (unless noninteractive
12944 (message "Scanning %s %s\"%s\"... (%2d%s)"
12945 (if is-directory "directory" "files")
12946 (or num-string "") name
12947 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
12948 (let ((file-name (abbreviate-file-name (car file-list)))
12949 ent-list arch-list arch-ent-list conf-list
12950 pack-list pack-body-list inst-list inst-ent-list)
12954 (vhdl-prepare-search-2
12956 ;; scan for design units
12957 (if (and limit-design-file-size
12958 (< limit-design-file-size (buffer-size)))
12959 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
12960 (setq big-files t))
12961 ;; scan for entities
12962 (goto-char (point-min))
12963 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12964 (let* ((ent-name (match-string-no-properties 1))
12965 (ent-key (downcase ent-name))
12966 (ent-entry (aget ent-alist ent-key t))
12967 (arch-alist (nth 3 ent-entry))
12968 (lib-alist (vhdl-scan-context-clause)))
12969 (if (nth 1 ent-entry)
12970 (vhdl-warning-when-idle
12971 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12972 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
12973 file-name (vhdl-current-line))
12974 (setq ent-list (cons ent-key ent-list))
12975 (aput 'ent-alist ent-key
12976 (list ent-name file-name (vhdl-current-line)
12977 arch-alist lib-alist)))))
12978 ;; scan for architectures
12979 (goto-char (point-min))
12980 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12981 (let* ((arch-name (match-string-no-properties 1))
12982 (arch-key (downcase arch-name))
12983 (ent-name (match-string-no-properties 2))
12984 (ent-key (downcase ent-name))
12985 (ent-entry (aget ent-alist ent-key t))
12986 (arch-alist (nth 3 ent-entry))
12987 (arch-entry (aget arch-alist arch-key t))
12988 (lib-arch-alist (vhdl-scan-context-clause)))
12990 (vhdl-warning-when-idle
12991 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12992 arch-name ent-name (nth 1 arch-entry)
12993 (nth 2 arch-entry) file-name (vhdl-current-line))
12994 (setq arch-list (cons arch-key arch-list)
12995 arch-ent-list (cons ent-key arch-ent-list))
12996 (aput 'arch-alist arch-key
12997 (list arch-name file-name (vhdl-current-line) nil
12999 (aput 'ent-alist ent-key
13000 (list (or (nth 0 ent-entry) ent-name)
13001 (nth 1 ent-entry) (nth 2 ent-entry)
13002 (vhdl-sort-alist arch-alist)
13003 (nth 4 ent-entry))))))
13004 ;; scan for configurations
13005 (goto-char (point-min))
13006 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13007 (let* ((conf-name (match-string-no-properties 1))
13008 (conf-key (downcase conf-name))
13009 (conf-entry (aget conf-alist conf-key t))
13010 (ent-name (match-string-no-properties 2))
13011 (ent-key (downcase ent-name))
13012 (lib-alist (vhdl-scan-context-clause))
13013 (conf-line (vhdl-current-line))
13014 (end-of-unit (vhdl-get-end-of-unit))
13015 arch-key comp-conf-list inst-key-list
13016 inst-comp-key inst-ent-key inst-arch-key
13017 inst-conf-key inst-lib-key)
13018 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13019 (setq arch-key (vhdl-match-string-downcase 1)))
13021 (vhdl-warning-when-idle
13022 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13023 conf-name ent-name (nth 1 conf-entry)
13024 (nth 2 conf-entry) file-name conf-line)
13025 (setq conf-list (cons conf-key conf-list))
13026 ;; scan for subconfigurations and subentities
13027 (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)
13028 (setq inst-comp-key (vhdl-match-string-downcase 3)
13029 inst-key-list (split-string
13030 (vhdl-match-string-downcase 1)
13031 "[ \t\n]*,[ \t\n]*"))
13032 (vhdl-forward-syntactic-ws)
13033 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13035 inst-lib-key (vhdl-match-string-downcase 3)
13036 inst-ent-key (and (match-string 2)
13037 (vhdl-match-string-downcase 4))
13038 inst-arch-key (and (match-string 2)
13039 (vhdl-match-string-downcase 6))
13040 inst-conf-key (and (not (match-string 2))
13041 (vhdl-match-string-downcase 4)))
13042 (while inst-key-list
13043 (setq comp-conf-list
13044 (cons (list (car inst-key-list)
13045 inst-comp-key inst-ent-key
13046 inst-arch-key inst-conf-key
13049 (setq inst-key-list (cdr inst-key-list)))))
13050 (aput 'conf-alist conf-key
13051 (list conf-name file-name conf-line ent-key
13052 arch-key comp-conf-list lib-alist)))))
13053 ;; scan for packages
13054 (goto-char (point-min))
13055 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13056 (let* ((pack-name (match-string-no-properties 2))
13057 (pack-key (downcase pack-name))
13058 (is-body (match-string-no-properties 1))
13059 (pack-entry (aget pack-alist pack-key t))
13060 (pack-line (vhdl-current-line))
13061 (end-of-unit (vhdl-get-end-of-unit))
13062 comp-name func-name comp-alist func-alist lib-alist)
13063 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13064 (vhdl-warning-when-idle
13065 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13066 (if is-body " body" "") pack-name
13067 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13068 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13069 file-name (vhdl-current-line))
13070 ;; scan for context clauses
13071 (setq lib-alist (vhdl-scan-context-clause))
13072 ;; scan for component and subprogram declarations/bodies
13073 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13074 (if (equal (upcase (match-string 1)) "COMPONENT")
13075 (setq comp-name (match-string-no-properties 2)
13077 (cons (list (downcase comp-name) comp-name
13078 file-name (vhdl-current-line))
13080 (setq func-name (match-string-no-properties 2)
13082 (cons (list (downcase func-name) func-name
13083 file-name (vhdl-current-line))
13085 (setq func-alist (nreverse func-alist))
13086 (setq comp-alist (nreverse comp-alist))
13088 (setq pack-body-list (cons pack-key pack-body-list))
13089 (setq pack-list (cons pack-key pack-list)))
13091 'pack-alist pack-key
13093 (list (or (nth 0 pack-entry) pack-name)
13094 (nth 1 pack-entry) (nth 2 pack-entry)
13095 (nth 3 pack-entry) (nth 4 pack-entry)
13097 file-name pack-line func-alist lib-alist)
13098 (list pack-name file-name pack-line
13099 comp-alist func-alist lib-alist
13100 (nth 6 pack-entry) (nth 7 pack-entry)
13101 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13102 ;; scan for hierarchy
13103 (if (and limit-hier-file-size
13104 (< limit-hier-file-size (buffer-size)))
13105 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13106 (setq big-files t))
13107 ;; scan for architectures
13108 (goto-char (point-min))
13109 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13110 (let* ((ent-name (match-string-no-properties 2))
13111 (ent-key (downcase ent-name))
13112 (arch-name (match-string-no-properties 1))
13113 (arch-key (downcase arch-name))
13114 (ent-entry (aget ent-alist ent-key t))
13115 (arch-alist (nth 3 ent-entry))
13116 (arch-entry (aget arch-alist arch-key t))
13117 (beg-of-unit (point))
13118 (end-of-unit (vhdl-get-end-of-unit))
13121 ;; scan for contained instantiations
13122 (while (and (re-search-forward
13123 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13124 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13125 "component[ \t\n]+\\(\\w+\\)\\|"
13126 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\)") end-of-unit t)
13127 (or (not limit-hier-inst-no)
13128 (<= (setq inst-no (1+ inst-no))
13129 limit-hier-inst-no)))
13130 (let* ((inst-name (match-string-no-properties 1))
13131 (inst-key (downcase inst-name))
13133 (or (match-string-no-properties 3)
13134 (match-string-no-properties 6)))
13136 (or (and (match-string 8)
13137 (vhdl-match-string-downcase 11))
13138 (and inst-comp-name
13139 (downcase inst-comp-name))))
13140 (inst-arch-key (vhdl-match-string-downcase 13))
13142 (and (not (match-string 8))
13143 (vhdl-match-string-downcase 11)))
13144 (inst-lib-key (vhdl-match-string-downcase 10)))
13145 (goto-char (match-end 1))
13146 (setq inst-list (cons inst-key inst-list)
13147 inst-ent-list (cons inst-ent-key inst-ent-list))
13151 (list (list inst-key inst-name file-name
13152 (vhdl-current-line) inst-comp-name
13153 inst-ent-key inst-arch-key
13154 inst-conf-key inst-lib-key))))))
13155 ;; scan for contained configuration specifications
13156 (goto-char beg-of-unit)
13157 (while (re-search-forward
13158 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13159 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13160 (let* ((inst-comp-name (match-string-no-properties 3))
13162 (and (match-string 6)
13163 (vhdl-match-string-downcase 9)))
13164 (inst-arch-key (vhdl-match-string-downcase 11))
13166 (and (not (match-string 6))
13167 (vhdl-match-string-downcase 9)))
13168 (inst-lib-key (vhdl-match-string-downcase 8))
13170 (split-string (vhdl-match-string-downcase 1)
13171 "[ \t\n]*,[ \t\n]*"))
13172 (tmp-inst-alist inst-alist)
13174 (while tmp-inst-alist
13175 (when (and (or (equal "all" (car inst-key-list))
13176 (member (nth 0 (car tmp-inst-alist))
13180 (or (nth 4 (car tmp-inst-alist)) ""))
13181 (downcase inst-comp-name)))
13182 (setq inst-entry (car tmp-inst-alist))
13183 (setq inst-ent-list
13184 (cons (or inst-ent-key (nth 5 inst-entry))
13186 (nth 5 inst-entry) inst-ent-list)))
13188 (list (nth 0 inst-entry) (nth 1 inst-entry)
13189 (nth 2 inst-entry) (nth 3 inst-entry)
13191 (or inst-ent-key (nth 5 inst-entry))
13192 (or inst-arch-key (nth 6 inst-entry))
13193 inst-conf-key inst-lib-key))
13194 (setcar tmp-inst-alist inst-entry))
13195 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13197 (aput 'arch-alist arch-key
13198 (list (nth 0 arch-entry) (nth 1 arch-entry)
13199 (nth 2 arch-entry) inst-alist
13200 (nth 4 arch-entry)))
13201 (aput 'ent-alist ent-key
13202 (list (nth 0 ent-entry) (nth 1 ent-entry)
13203 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13204 (nth 4 ent-entry)))
13205 (when (and limit-hier-inst-no
13206 (> inst-no limit-hier-inst-no))
13207 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13208 (setq big-files t))
13209 (goto-char end-of-unit))))
13210 ;; remember design units for this file
13211 (aput 'file-alist file-name
13212 (list ent-list arch-list arch-ent-list conf-list
13213 pack-list pack-body-list inst-list inst-ent-list))
13214 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13215 (setq file-list (cdr file-list))))
13216 (when (or (and (not project) files-exist)
13217 (and project (not non-final)))
13218 ;; consistency checks:
13219 ;; check whether each architecture has a corresponding entity
13220 (setq tmp-list ent-alist)
13222 (when (null (nth 2 (car tmp-list)))
13223 (setq tmp-entry (car (nth 4 (car tmp-list))))
13224 (vhdl-warning-when-idle
13225 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13226 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13227 (nth 3 tmp-entry)))
13228 (setq tmp-list (cdr tmp-list)))
13229 ;; check whether configuration has a corresponding entity/architecture
13230 (setq tmp-list conf-alist)
13232 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13233 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13234 (setq tmp-entry (car tmp-list))
13235 (vhdl-warning-when-idle
13236 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13237 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13238 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13239 (setq tmp-entry (car tmp-list))
13240 (vhdl-warning-when-idle
13241 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13242 (nth 1 tmp-entry) (nth 4 tmp-entry)
13243 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13244 (setq tmp-list (cdr tmp-list)))
13245 ;; check whether each package body has a package declaration
13246 (setq tmp-list pack-alist)
13248 (when (null (nth 2 (car tmp-list)))
13249 (setq tmp-entry (car tmp-list))
13250 (vhdl-warning-when-idle
13251 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13252 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13253 (setq tmp-list (cdr tmp-list)))
13255 (setq ent-alist (vhdl-sort-alist ent-alist))
13256 (setq conf-alist (vhdl-sort-alist conf-alist))
13257 (setq pack-alist (vhdl-sort-alist pack-alist))
13258 ;; remember updated directory/project
13259 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13260 ;; clear directory alists
13262 (adelete 'vhdl-entity-alist key)
13263 (adelete 'vhdl-config-alist key)
13264 (adelete 'vhdl-package-alist key)
13265 (adelete 'vhdl-ent-inst-alist key)
13266 (adelete 'vhdl-file-alist key))
13267 ;; put directory contents into cache
13268 (aput 'vhdl-entity-alist key ent-alist)
13269 (aput 'vhdl-config-alist key conf-alist)
13270 (aput 'vhdl-package-alist key pack-alist)
13271 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13272 (aput 'vhdl-file-alist key file-alist)
13274 (message "Scanning %s %s\"%s\"...done"
13275 (if is-directory "directory" "files") (or num-string "") name)
13276 (unless project (message "Scanning directory...done"))
13278 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13279 ;; save cache when scanned non-interactively
13280 (when (or (not project) (not non-final))
13281 (when (and noninteractive vhdl-speedbar-save-cache)
13282 (vhdl-save-cache key)))
13285 (defun vhdl-scan-project-contents (project)
13286 "Scan the contents of all VHDL files found in the directories and files
13288 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13289 (default-dir (vhdl-resolve-env-variable
13290 (nth 1 (aget vhdl-project-alist project))))
13291 (file-exclude-regexp
13292 (or (nth 3 (aget vhdl-project-alist project)) ""))
13293 dir-list-tmp dir dir-name num-dir act-dir recursive)
13294 ;; clear project alists
13295 (adelete 'vhdl-entity-alist project)
13296 (adelete 'vhdl-config-alist project)
13297 (adelete 'vhdl-package-alist project)
13298 (adelete 'vhdl-ent-inst-alist project)
13299 (adelete 'vhdl-file-alist project)
13300 ;; expand directory names by default-directory
13301 (message "Collecting source files...")
13303 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13304 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13305 (setq recursive (match-string 1 dir)
13306 dir-name (match-string 3 dir))
13308 (cons (concat recursive
13309 (if (file-name-absolute-p dir-name) "" default-dir)
13312 (setq dir-list (cdr dir-list)))
13313 ;; resolve path wildcards
13314 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13315 ;; expand directories
13316 (while dir-list-tmp
13317 (setq dir (car dir-list-tmp))
13318 ;; get subdirectories
13319 (if (string-match "-r \\(.*[/\\]\\)" dir)
13320 (setq dir-list (append dir-list (vhdl-get-subdirs
13321 (match-string 1 dir))))
13322 (setq dir-list (append dir-list (list dir))))
13323 (setq dir-list-tmp (cdr dir-list-tmp)))
13325 (unless (equal file-exclude-regexp "")
13326 (let ((case-fold-search nil))
13328 (unless (string-match file-exclude-regexp (car dir-list))
13329 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13330 (setq dir-list (cdr dir-list)))
13331 (setq dir-list (nreverse dir-list-tmp))))
13332 (message "Collecting source files...done")
13333 ;; scan for design units for each directory in DIR-LIST
13334 (setq dir-list-tmp nil
13335 num-dir (length dir-list)
13338 (setq dir-name (abbreviate-file-name
13339 (expand-file-name (car dir-list))))
13340 (vhdl-scan-directory-contents dir-name project nil
13341 (format "(%s/%s) " act-dir num-dir)
13343 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13344 (setq dir-list (cdr dir-list)
13345 act-dir (1+ act-dir)))
13346 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13347 (message "Scanning project \"%s\"...done" project)))
13349 (defun vhdl-update-file-contents (file-name)
13350 "Update hierarchy information by contents of current buffer."
13351 (setq file-name (abbreviate-file-name file-name))
13352 (let* ((dir-name (file-name-directory file-name))
13353 (directory-alist vhdl-directory-alist)
13355 (while directory-alist
13356 (when (member dir-name (nth 1 (car directory-alist)))
13357 (let* ((vhdl-project (nth 0 (car directory-alist)))
13358 (project (vhdl-project-p))
13359 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13360 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13361 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13362 (ent-inst-list (car (aget vhdl-ent-inst-alist
13363 (or project dir-name) t)))
13364 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13365 (file-entry (aget file-alist file-name t))
13366 (ent-list (nth 0 file-entry))
13367 (arch-list (nth 1 file-entry))
13368 (arch-ent-list (nth 2 file-entry))
13369 (conf-list (nth 3 file-entry))
13370 (pack-list (nth 4 file-entry))
13371 (pack-body-list (nth 5 file-entry))
13372 (inst-ent-list (nth 7 file-entry))
13373 (cache-key (or project dir-name))
13374 arch-alist key ent-key entry)
13375 ;; delete design units previously contained in this file:
13378 (setq key (car ent-list)
13379 entry (aget ent-alist key t))
13380 (when (equal file-name (nth 1 entry))
13382 (aput 'ent-alist key
13383 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13384 (adelete 'ent-alist key)))
13385 (setq ent-list (cdr ent-list)))
13388 (setq key (car arch-list)
13389 ent-key (car arch-ent-list)
13390 entry (aget ent-alist ent-key t)
13391 arch-alist (nth 3 entry))
13392 (when (equal file-name (nth 1 (aget arch-alist key t)))
13393 (adelete 'arch-alist key)
13394 (if (or (nth 1 entry) arch-alist)
13395 (aput 'ent-alist ent-key
13396 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13397 arch-alist (nth 4 entry)))
13398 (adelete 'ent-alist ent-key)))
13399 (setq arch-list (cdr arch-list)
13400 arch-ent-list (cdr arch-ent-list)))
13403 (setq key (car conf-list))
13404 (when (equal file-name (nth 1 (aget conf-alist key t)))
13405 (adelete 'conf-alist key))
13406 (setq conf-list (cdr conf-list)))
13407 ;; package declarations
13409 (setq key (car pack-list)
13410 entry (aget pack-alist key t))
13411 (when (equal file-name (nth 1 entry))
13413 (aput 'pack-alist key
13414 (list (nth 0 entry) nil nil nil nil nil
13415 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13417 (adelete 'pack-alist key)))
13418 (setq pack-list (cdr pack-list)))
13420 (while pack-body-list
13421 (setq key (car pack-body-list)
13422 entry (aget pack-alist key t))
13423 (when (equal file-name (nth 6 entry))
13425 (aput 'pack-alist key
13426 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13427 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13429 (adelete 'pack-alist key)))
13430 (setq pack-body-list (cdr pack-body-list)))
13431 ;; instantiated entities
13432 (while inst-ent-list
13433 (setq ent-inst-list
13434 (vhdl-delete (car inst-ent-list) ent-inst-list))
13435 (setq inst-ent-list (cdr inst-ent-list)))
13437 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13438 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13439 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13440 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13442 (vhdl-scan-directory-contents file-name project t)
13443 (when (or (and vhdl-speedbar-show-projects project)
13444 (and (not vhdl-speedbar-show-projects) (not project)))
13445 (vhdl-speedbar-refresh project))
13447 (setq directory-alist (cdr directory-alist)))
13450 (defun vhdl-update-hierarchy ()
13451 "Update directory and hierarchy information in speedbar."
13452 (let ((file-list (reverse vhdl-modified-file-list))
13454 (when (and vhdl-speedbar-update-on-saving file-list)
13457 (or (vhdl-update-file-contents (car file-list))
13459 (setq file-list (cdr file-list)))
13460 (setq vhdl-modified-file-list nil)
13461 (when updated (message "Updating hierarchy...done")))))
13463 ;; structure (parenthesised expression means list of such entries)
13464 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13465 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13466 ;; comp-lib-name level)
13467 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13468 conf-inst-alist level indent
13469 &optional include-top ent-hier)
13470 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13472 (let* ((ent-entry (aget ent-alist ent-key t))
13473 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13474 (cdar (last (nth 3 ent-entry)))))
13475 (inst-alist (nth 3 arch-entry))
13476 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13477 hier-list subcomp-list tmp-list inst-key inst-comp-name
13478 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13479 (when (= level 0) (message "Extract design hierarchy..."))
13481 (setq level (1+ level)))
13482 (when (member ent-key ent-hier)
13483 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13484 ;; check configured architecture (already checked during scanning)
13485 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13486 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13487 ;; process all instances
13489 (setq inst-entry (car inst-alist)
13490 inst-key (nth 0 inst-entry)
13491 inst-comp-name (nth 4 inst-entry)
13492 inst-conf-key (nth 7 inst-entry))
13493 ;; search entry in configuration's instantiations list
13494 (setq tmp-list conf-inst-alist)
13495 (while (and tmp-list
13496 (not (and (member (nth 0 (car tmp-list))
13497 (list "all" inst-key))
13498 (equal (nth 1 (car tmp-list))
13499 (downcase (or inst-comp-name ""))))))
13500 (setq tmp-list (cdr tmp-list)))
13501 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13502 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13503 (when (and inst-conf-key (not inst-conf-entry))
13504 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13505 ;; determine entity
13507 (or (nth 2 (car tmp-list)) ; from configuration
13508 (nth 3 inst-conf-entry) ; from subconfiguration
13509 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13510 ; from configuration spec.
13511 (nth 5 inst-entry))) ; from direct instantiation
13512 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13513 ;; determine architecture
13514 (setq inst-arch-key
13515 (or (nth 3 (car tmp-list)) ; from configuration
13516 (nth 4 inst-conf-entry) ; from subconfiguration
13517 (nth 6 inst-entry) ; from direct instantiation
13518 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13519 ; from configuration spec.
13520 (caar (nth 3 inst-ent-entry)))) ; random (simplified MRA)
13521 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13524 (or (nth 5 (car tmp-list)) ; from configuration
13525 (nth 8 inst-entry))) ; from direct instantiation
13526 ;; gather information for this instance
13528 (list (nth 1 inst-entry)
13529 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13530 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13531 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13532 (or (nth 0 inst-arch-entry) inst-arch-key)
13533 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13534 (or (nth 0 inst-conf-entry) inst-conf-key)
13535 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13536 inst-lib-key level))
13537 ;; get subcomponent hierarchy
13538 (setq subcomp-list (vhdl-get-hierarchy
13539 ent-alist conf-alist
13540 inst-ent-key inst-arch-key inst-conf-key
13541 (nth 5 inst-conf-entry)
13542 (1+ level) indent nil (cons ent-key ent-hier)))
13544 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13545 (setq inst-alist (cdr inst-alist)))
13548 (cons (list nil nil (nth 0 ent-entry)
13549 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13551 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13555 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13558 (defun vhdl-get-instantiations (ent-key indent)
13559 "Get all instantiations of entity ENT-KEY."
13560 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13561 arch-alist inst-alist ent-inst-list
13562 ent-entry arch-entry inst-entry)
13564 (setq ent-entry (car ent-alist))
13565 (setq arch-alist (nth 4 ent-entry))
13567 (setq arch-entry (car arch-alist))
13568 (setq inst-alist (nth 4 arch-entry))
13570 (setq inst-entry (car inst-alist))
13571 (when (equal ent-key (nth 5 inst-entry))
13572 (setq ent-inst-list
13573 (cons (list (nth 1 inst-entry)
13574 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13576 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13578 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13580 (setq inst-alist (cdr inst-alist)))
13581 (setq arch-alist (cdr arch-alist)))
13582 (setq ent-alist (cdr ent-alist)))
13583 (nreverse ent-inst-list)))
13585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13588 (defun vhdl-save-caches ()
13589 "Save all updated hierarchy caches to file."
13591 (condition-case nil
13592 (when vhdl-speedbar-save-cache
13593 ;; update hierarchy
13594 (vhdl-update-hierarchy)
13595 (let ((project-list vhdl-updated-project-list))
13596 (message "Saving hierarchy caches...")
13597 ;; write updated project caches
13598 (while project-list
13599 (vhdl-save-cache (car project-list))
13600 (setq project-list (cdr project-list)))
13601 (message "Saving hierarchy caches...done")))
13602 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13605 (defun vhdl-save-cache (key)
13606 "Save current hierarchy cache to file."
13607 (let* ((orig-buffer (current-buffer))
13609 (project (vhdl-project-p))
13610 (default-directory key)
13611 (directory (abbreviate-file-name (vhdl-default-directory)))
13612 (file-name (vhdl-resolve-env-variable
13613 (vhdl-replace-string
13614 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13616 (subst-char-in-string ? ?_ (or project "dir"))
13617 " " (user-login-name)))))
13618 (file-dir-name (expand-file-name file-name directory))
13619 (cache-key (or project directory))
13620 (key (if project "project" "directory")))
13621 (unless (file-exists-p (file-name-directory file-dir-name))
13622 (make-directory (file-name-directory file-dir-name) t))
13623 (if (not (file-writable-p file-dir-name))
13624 (progn (vhdl-warning (format "File not writable: \"%s\""
13625 (abbreviate-file-name file-dir-name)))
13627 (message "Saving cache: \"%s\"" file-dir-name)
13628 (set-buffer (find-file-noselect file-dir-name t t))
13630 (insert ";; -*- Emacs-Lisp -*-\n\n"
13631 ";;; " (file-name-nondirectory file-name)
13632 " - design hierarchy cache file for Emacs VHDL Mode "
13634 (insert "\n;; " (if project "Project " "Directory") " : ")
13635 (if project (insert project) (prin1 directory (current-buffer)))
13636 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13637 (user-login-name) "\n\n"
13638 "\n;; version number\n"
13639 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13640 "\n;; " (if project "project" "directory") " name"
13641 "\n(setq " key " ")
13642 (prin1 (or project directory) (current-buffer))
13644 (when (member 'hierarchy vhdl-speedbar-save-cache)
13645 (insert "\n;; entity and architecture cache\n"
13646 "(aput 'vhdl-entity-alist " key " '")
13647 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13648 (insert ")\n\n;; configuration cache\n"
13649 "(aput 'vhdl-config-alist " key " '")
13650 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13651 (insert ")\n\n;; package cache\n"
13652 "(aput 'vhdl-package-alist " key " '")
13653 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13654 (insert ")\n\n;; instantiated entities cache\n"
13655 "(aput 'vhdl-ent-inst-alist " key " '")
13656 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13657 (insert ")\n\n;; design units per file cache\n"
13658 "(aput 'vhdl-file-alist " key " '")
13659 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13661 (insert ")\n\n;; source directories in project cache\n"
13662 "(aput 'vhdl-directory-alist " key " '")
13663 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13665 (when (member 'display vhdl-speedbar-save-cache)
13666 (insert "\n;; shown design units cache\n"
13667 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13668 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13671 (setq vhdl-updated-project-list
13672 (delete cache-key vhdl-updated-project-list))
13674 (kill-buffer (current-buffer))
13675 (set-buffer orig-buffer))))
13677 (defun vhdl-load-cache (key)
13678 "Load hierarchy cache information from file."
13679 (let* ((vhdl-project key)
13680 (default-directory key)
13681 (directory (vhdl-default-directory))
13682 (file-name (vhdl-resolve-env-variable
13683 (vhdl-replace-string
13684 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13686 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13687 " " (user-login-name)))))
13688 (file-dir-name (expand-file-name file-name directory))
13689 vhdl-cache-version)
13690 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13691 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13692 (when (file-exists-p file-dir-name)
13694 (progn (load-file file-dir-name)
13695 (string< (mapconcat
13696 (lambda (a) (format "%3d" (string-to-int a)))
13697 (split-string "3.31.14" "\\.") "")
13699 (lambda (a) (format "%3d" (string-to-int a)))
13700 (split-string vhdl-cache-version "\\.") "")))
13701 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13704 (defun vhdl-require-hierarchy-info ()
13705 "Make sure that hierarchy information is available. Load cache or scan files
13707 (if (vhdl-project-p)
13708 (unless (or (assoc vhdl-project vhdl-file-alist)
13709 (vhdl-load-cache vhdl-project))
13710 (vhdl-scan-project-contents vhdl-project))
13711 (let ((directory (abbreviate-file-name default-directory)))
13712 (unless (or (assoc directory vhdl-file-alist)
13713 (vhdl-load-cache directory))
13714 (vhdl-scan-directory-contents directory)))))
13716 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13717 ;; Add hierarchy browser functionality to speedbar
13719 (defvar vhdl-speedbar-key-map nil
13720 "Keymap used when in the VHDL hierarchy browser mode.")
13722 (defvar vhdl-speedbar-menu-items nil
13723 "Additional menu-items to add to speedbar frame.")
13725 (defun vhdl-speedbar-initialize ()
13726 "Initialize speedbar."
13727 ;; general settings
13728 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13729 ;; VHDL file extensions (extracted from `auto-mode-alist')
13730 (let ((mode-alist auto-mode-alist))
13732 (when (eq (cdar mode-alist) 'vhdl-mode)
13733 (speedbar-add-supported-extension (caar mode-alist)))
13734 (setq mode-alist (cdr mode-alist))))
13735 ;; hierarchy browser settings
13736 (when (boundp 'speedbar-mode-functions-list)
13737 ;; special functions
13738 (speedbar-add-mode-functions-list
13740 (speedbar-item-info . vhdl-speedbar-item-info)
13741 (speedbar-line-path . speedbar-files-line-path)))
13742 (speedbar-add-mode-functions-list
13744 (speedbar-item-info . vhdl-speedbar-item-info)
13745 (speedbar-line-path . vhdl-speedbar-line-project)))
13747 (unless vhdl-speedbar-key-map
13748 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13749 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13750 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13751 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13752 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13753 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13754 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13755 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13756 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13757 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13758 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13759 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13762 (define-key vhdl-speedbar-key-map (int-to-string key)
13763 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13764 (setq key (1+ key)))))
13765 (define-key speedbar-key-map "h"
13766 (lambda () (interactive)
13767 (speedbar-change-initial-expansion-list "vhdl directory")))
13768 (define-key speedbar-key-map "H"
13769 (lambda () (interactive)
13770 (speedbar-change-initial-expansion-list "vhdl project")))
13772 (unless vhdl-speedbar-menu-items
13774 vhdl-speedbar-menu-items
13775 `(["Edit" speedbar-edit-line t]
13776 ["Expand" speedbar-expand-line
13777 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13778 ["Contract" vhdl-speedbar-contract-level t]
13779 ["Expand All" vhdl-speedbar-expand-all t]
13780 ["Contract All" vhdl-speedbar-contract-all t]
13781 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13784 (cons `[,(if (= key 0) "All" (int-to-string key))
13785 (vhdl-speedbar-set-depth ,key)
13787 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13788 :keys ,(int-to-string key)]
13790 (setq key (1+ key)))
13791 (nreverse menu-list))
13793 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13794 (or (vhdl-speedbar-check-unit 'entity)
13795 (vhdl-speedbar-check-unit 'subprogram))]
13796 ["Place Component" vhdl-speedbar-place-component
13797 (vhdl-speedbar-check-unit 'entity)]
13798 ["Make" vhdl-speedbar-make-design
13799 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
13800 ["Generate Makefile" vhdl-speedbar-generate-makefile
13801 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
13802 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
13803 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13804 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
13805 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
13806 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13807 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
13808 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
13810 (speedbar-add-expansion-list
13811 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13812 vhdl-speedbar-display-directory))
13813 (speedbar-add-expansion-list
13814 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13815 vhdl-speedbar-display-projects))
13816 (setq speedbar-stealthy-function-list
13818 '(("vhdl directory" vhdl-speedbar-update-current-unit)
13819 ("vhdl project" vhdl-speedbar-update-current-project
13820 vhdl-speedbar-update-current-unit)
13821 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
13822 ; (speedbar-extension-list-to-regex
13823 ; speedbar-ignored-path-expressions))))
13825 speedbar-stealthy-function-list))
13826 (when (eq vhdl-speedbar-display-mode 'directory)
13827 (setq speedbar-initial-expansion-list-name "vhdl directory"))
13828 (when (eq vhdl-speedbar-display-mode 'project)
13829 (setq speedbar-initial-expansion-list-name "vhdl project"))
13830 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
13832 (defun vhdl-speedbar (&optional arg)
13833 "Open/close speedbar."
13835 (if (not (fboundp 'speedbar))
13836 (error "WARNING: Speedbar is not available or not installed")
13838 (speedbar-frame-mode arg)
13839 (error (error "WARNING: An error occurred while opening speedbar")))))
13841 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13842 ;; Display functions
13844 (defvar vhdl-speedbar-last-selected-project nil
13845 "Name of last selected project.")
13847 ;; macros must be defined in the file they are used (copied from `speedbar.el')
13848 (defmacro speedbar-with-writable (&rest forms)
13849 "Allow the buffer to be writable and evaluate FORMS."
13850 (list 'let '((inhibit-read-only t))
13851 (cons 'progn forms)))
13852 (put 'speedbar-with-writable 'lisp-indent-function 0)
13854 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
13855 "Display directory and hierarchy information in speedbar."
13856 (setq vhdl-speedbar-show-projects nil)
13857 (setq speedbar-ignored-path-regexp
13858 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
13859 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
13860 (setq speedbar-last-selected-file nil)
13861 (speedbar-with-writable
13862 (condition-case nil
13864 ;; insert directory path
13865 (speedbar-directory-buttons directory depth)
13866 ;; insert subdirectories
13867 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
13868 ;; scan and insert hierarchy of current directory
13869 (vhdl-speedbar-insert-dir-hierarchy directory depth
13870 speedbar-power-click)
13871 ;; expand subdirectories
13872 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
13873 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
13875 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
13876 "Display projects and hierarchy information in speedbar."
13877 (setq vhdl-speedbar-show-projects t)
13878 (setq speedbar-ignored-path-regexp ".")
13879 (setq speedbar-last-selected-file nil)
13880 (setq vhdl-speedbar-last-selected-project nil)
13881 (speedbar-with-writable
13882 (condition-case nil
13884 (vhdl-speedbar-insert-projects)
13885 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
13886 (setq speedbar-full-text-cache nil)) ; prevent caching
13888 (defun vhdl-speedbar-insert-projects ()
13889 "Insert all projects in speedbar."
13890 (vhdl-speedbar-make-title-line "Projects:")
13891 (let ((project-alist (if vhdl-project-sort
13892 (vhdl-sort-alist (copy-alist vhdl-project-alist))
13893 vhdl-project-alist))
13894 (vhdl-speedbar-update-current-unit nil))
13896 (while project-alist
13897 (speedbar-make-tag-line
13898 'angle ?+ 'vhdl-speedbar-expand-project
13899 (caar project-alist) (caar project-alist)
13900 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
13901 (setq project-alist (cdr project-alist)))
13902 (setq project-alist vhdl-project-alist)
13904 (while project-alist
13905 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
13906 (goto-char (point-min))
13907 (when (re-search-forward
13908 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
13909 (goto-char (match-end 1))
13910 (speedbar-do-function-pointer)))
13911 (setq project-alist (cdr project-alist))))
13912 ; (vhdl-speedbar-update-current-project)
13913 ; (vhdl-speedbar-update-current-unit nil t)
13916 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
13917 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
13918 otherwise use cached data."
13919 (when (or rescan (and (not (assoc project vhdl-file-alist))
13920 (not (vhdl-load-cache project))))
13921 (vhdl-scan-project-contents project))
13922 ;; insert design hierarchy
13923 (vhdl-speedbar-insert-hierarchy
13924 (aget vhdl-entity-alist project t)
13925 (aget vhdl-config-alist project t)
13926 (aget vhdl-package-alist project t)
13927 (car (aget vhdl-ent-inst-alist project t)) indent)
13928 (insert (int-to-string indent) ":\n")
13929 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
13930 (put-text-property (1- (point)) (point) 'invisible nil)
13931 ;; expand design units
13932 (vhdl-speedbar-expand-units project))
13934 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
13935 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
13936 otherwise use cached data."
13937 (when (or rescan (and (not (assoc directory vhdl-file-alist))
13938 (not (vhdl-load-cache directory))))
13939 (vhdl-scan-directory-contents directory))
13940 ;; insert design hierarchy
13941 (vhdl-speedbar-insert-hierarchy
13942 (aget vhdl-entity-alist directory t)
13943 (aget vhdl-config-alist directory t)
13944 (aget vhdl-package-alist directory t)
13945 (car (aget vhdl-ent-inst-alist directory t)) depth)
13946 ;; expand design units
13947 (vhdl-speedbar-expand-units directory)
13948 (aput 'vhdl-directory-alist directory (list (list directory))))
13950 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
13951 ent-inst-list depth)
13952 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
13953 (if (not (or ent-alist conf-alist pack-alist))
13954 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
13955 (let (ent-entry conf-entry pack-entry)
13957 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
13959 (setq ent-entry (car ent-alist))
13960 (speedbar-make-tag-line
13961 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
13962 (nth 1 ent-entry) 'vhdl-speedbar-find-file
13963 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13964 'vhdl-speedbar-entity-face depth)
13965 (unless (nth 2 ent-entry)
13966 (end-of-line 0) (insert "!") (forward-char 1))
13967 (unless (member (nth 0 ent-entry) ent-inst-list)
13968 (end-of-line 0) (insert " (top)") (forward-char 1))
13969 (setq ent-alist (cdr ent-alist)))
13970 ;; insert configurations
13971 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
13973 (setq conf-entry (car conf-alist))
13974 (speedbar-make-tag-line
13975 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
13976 (nth 1 conf-entry) 'vhdl-speedbar-find-file
13977 (cons (nth 2 conf-entry) (nth 3 conf-entry))
13978 'vhdl-speedbar-configuration-face depth)
13979 (setq conf-alist (cdr conf-alist)))
13981 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
13983 (setq pack-entry (car pack-alist))
13984 (vhdl-speedbar-make-pack-line
13985 (nth 0 pack-entry) (nth 1 pack-entry)
13986 (cons (nth 2 pack-entry) (nth 3 pack-entry))
13987 (cons (nth 7 pack-entry) (nth 8 pack-entry))
13989 (setq pack-alist (cdr pack-alist))))))
13991 (defun vhdl-speedbar-rescan-hierarchy ()
13992 "Rescan hierarchy for the directory or project under the cursor."
13997 (vhdl-speedbar-show-projects
13998 (setq key (vhdl-speedbar-line-project))
13999 (vhdl-scan-project-contents key))
14000 ;; top-level directory
14001 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14002 (re-search-forward "[0-9]+:" nil t)
14003 (vhdl-scan-directory-contents
14004 (abbreviate-file-name (speedbar-line-path))))
14005 ;; current directory
14006 (t (setq path (speedbar-line-path))
14007 (string-match "^\\(.+[/\\]\\)" path)
14008 (vhdl-scan-directory-contents
14009 (abbreviate-file-name (match-string 1 path)))))
14010 (vhdl-speedbar-refresh key)))
14012 (defun vhdl-speedbar-expand-dirs (directory)
14013 "Expand subdirectories in DIRECTORY according to
14014 `speedbar-shown-directories'."
14015 ;; (nicked from `speedbar-default-directory-list')
14016 (let ((sf (cdr (reverse speedbar-shown-directories)))
14017 (vhdl-speedbar-update-current-unit nil))
14018 (setq speedbar-shown-directories
14019 (list (expand-file-name default-directory)))
14021 (when (speedbar-goto-this-file (car sf))
14022 (beginning-of-line)
14023 (when (looking-at "[0-9]+:\\s-*<")
14024 (goto-char (match-end 0))
14025 (speedbar-do-function-pointer)))
14026 (setq sf (cdr sf))))
14027 (vhdl-speedbar-update-current-unit nil t))
14029 (defun vhdl-speedbar-expand-units (key)
14030 "Expand design units in directory/project KEY according to
14031 `vhdl-speedbar-shown-unit-alist'."
14032 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14033 (vhdl-speedbar-update-current-unit nil)
14034 vhdl-updated-project-list)
14035 (adelete 'vhdl-speedbar-shown-unit-alist key)
14036 (vhdl-prepare-search-1
14037 (while unit-alist ; expand units
14038 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14039 (beginning-of-line)
14040 (let ((arch-alist (nth 1 (car unit-alist)))
14042 (when (looking-at "^[0-9]+:\\s-*\\[")
14043 (goto-char (match-end 0))
14044 (setq position (point))
14045 (speedbar-do-function-pointer)
14046 (select-frame speedbar-frame)
14047 (while arch-alist ; expand architectures
14048 (goto-char position)
14049 (when (re-search-forward
14050 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14051 (car arch-alist) "\\>\\)") nil t)
14052 (beginning-of-line)
14053 (when (looking-at "^[0-9]+:\\s-*{")
14054 (goto-char (match-end 0))
14055 (speedbar-do-function-pointer)
14056 (select-frame speedbar-frame)))
14057 (setq arch-alist (cdr arch-alist))))
14058 (setq unit-alist (cdr unit-alist))))))
14059 (vhdl-speedbar-update-current-unit nil t))
14061 (defun vhdl-speedbar-contract-level ()
14062 "Contract current level in current directory/project."
14064 (when (or (save-excursion
14065 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14066 (and (save-excursion
14067 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14068 (re-search-backward
14069 (format "^[0-%d]:\\s-*[[{<]-"
14070 (max (1- (string-to-int (match-string 1))) 0)) nil t)))
14071 (goto-char (match-end 0))
14072 (speedbar-do-function-pointer)
14073 (speedbar-center-buffer-smartly)))
14075 (defun vhdl-speedbar-contract-all ()
14076 "Contract all expanded design units in current directory/project."
14078 (if (and vhdl-speedbar-show-projects
14079 (save-excursion (beginning-of-line) (looking-at "^0:")))
14080 (progn (setq vhdl-speedbar-shown-project-list nil)
14081 (vhdl-speedbar-refresh))
14082 (let ((key (vhdl-speedbar-line-key)))
14083 (adelete 'vhdl-speedbar-shown-unit-alist key)
14084 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14085 (when (memq 'display vhdl-speedbar-save-cache)
14086 (add-to-list 'vhdl-updated-project-list key)))))
14088 (defun vhdl-speedbar-expand-all ()
14089 "Expand all design units in current directory/project."
14091 (let* ((key (vhdl-speedbar-line-key))
14092 (ent-alist (aget vhdl-entity-alist key t))
14093 (conf-alist (aget vhdl-config-alist key t))
14094 (pack-alist (aget vhdl-package-alist key t))
14095 arch-alist unit-alist subunit-alist)
14096 (add-to-list 'vhdl-speedbar-shown-project-list key)
14098 (setq arch-alist (nth 4 (car ent-alist)))
14099 (setq subunit-alist nil)
14101 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14102 (setq arch-alist (cdr arch-alist)))
14103 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14104 (setq ent-alist (cdr ent-alist)))
14106 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14107 (setq conf-alist (cdr conf-alist)))
14109 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14110 (setq pack-alist (cdr pack-alist)))
14111 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14112 (vhdl-speedbar-refresh)
14113 (when (memq 'display vhdl-speedbar-save-cache)
14114 (add-to-list 'vhdl-updated-project-list key))))
14116 (defun vhdl-speedbar-expand-project (text token indent)
14117 "Expand/contract the project under the cursor."
14119 ((string-match "+" text) ; expand project
14120 (speedbar-change-expand-button-char ?-)
14121 (unless (member token vhdl-speedbar-shown-project-list)
14122 (setq vhdl-speedbar-shown-project-list
14123 (cons token vhdl-speedbar-shown-project-list)))
14124 (speedbar-with-writable
14126 (end-of-line) (forward-char 1)
14127 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14128 speedbar-power-click))))
14129 ((string-match "-" text) ; contract project
14130 (speedbar-change-expand-button-char ?+)
14131 (setq vhdl-speedbar-shown-project-list
14132 (delete token vhdl-speedbar-shown-project-list))
14133 (speedbar-delete-subblock indent))
14134 (t (error "Nothing to display")))
14135 (when (equal (selected-frame) speedbar-frame)
14136 (speedbar-center-buffer-smartly)))
14138 (defun vhdl-speedbar-expand-entity (text token indent)
14139 "Expand/contract the entity under the cursor."
14141 ((string-match "+" text) ; expand entity
14142 (let* ((key (vhdl-speedbar-line-key indent))
14143 (ent-alist (aget vhdl-entity-alist key t))
14144 (ent-entry (aget ent-alist token t))
14145 (arch-alist (nth 3 ent-entry))
14146 (inst-alist (vhdl-get-instantiations token indent))
14147 (subpack-alist (nth 4 ent-entry))
14148 arch-entry inst-entry)
14149 (if (not (or arch-alist inst-alist subpack-alist))
14150 (speedbar-change-expand-button-char ??)
14151 (speedbar-change-expand-button-char ?-)
14152 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14153 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14154 (aput 'unit-alist token nil)
14155 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14156 (speedbar-with-writable
14158 (end-of-line) (forward-char 1)
14159 ;; insert architectures
14161 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14163 (setq arch-entry (car arch-alist))
14164 (speedbar-make-tag-line
14165 'curly ?+ 'vhdl-speedbar-expand-architecture
14166 (cons token (nth 0 arch-entry))
14167 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14168 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14169 'vhdl-speedbar-architecture-face (1+ indent))
14170 (setq arch-alist (cdr arch-alist)))
14171 ;; insert instantiations
14173 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14175 (setq inst-entry (car inst-alist))
14176 (vhdl-speedbar-make-inst-line
14177 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14178 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14179 nil nil nil (1+ indent) 0 " in ")
14180 (setq inst-alist (cdr inst-alist)))
14181 ;; insert required packages
14182 (vhdl-speedbar-insert-subpackages
14183 subpack-alist (1+ indent) indent)))
14184 (when (memq 'display vhdl-speedbar-save-cache)
14185 (add-to-list 'vhdl-updated-project-list key))
14186 (vhdl-speedbar-update-current-unit t t))))
14187 ((string-match "-" text) ; contract entity
14188 (speedbar-change-expand-button-char ?+)
14189 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14190 (let* ((key (vhdl-speedbar-line-key indent))
14191 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14192 (adelete 'unit-alist token)
14194 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14195 (adelete 'vhdl-speedbar-shown-unit-alist key))
14196 (speedbar-delete-subblock indent)
14197 (when (memq 'display vhdl-speedbar-save-cache)
14198 (add-to-list 'vhdl-updated-project-list key))))
14199 (t (error "Nothing to display")))
14200 (when (equal (selected-frame) speedbar-frame)
14201 (speedbar-center-buffer-smartly)))
14203 (defun vhdl-speedbar-expand-architecture (text token indent)
14204 "Expand/contract the architecture under the cursor."
14206 ((string-match "+" text) ; expand architecture
14207 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14208 (ent-alist (aget vhdl-entity-alist key t))
14209 (conf-alist (aget vhdl-config-alist key t))
14210 (hier-alist (vhdl-get-hierarchy
14211 ent-alist conf-alist (car token) (cdr token) nil nil
14213 (ent-entry (aget ent-alist (car token) t))
14214 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14215 (subpack-alist (nth 4 arch-entry))
14217 (if (not (or hier-alist subpack-alist))
14218 (speedbar-change-expand-button-char ??)
14219 (speedbar-change-expand-button-char ?-)
14220 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14221 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14222 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14223 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14224 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14225 (speedbar-with-writable
14227 (end-of-line) (forward-char 1)
14228 ;; insert instance hierarchy
14230 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14233 (setq entry (car hier-alist))
14234 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14235 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14236 (vhdl-speedbar-make-inst-line
14237 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14238 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14239 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14240 (setq hier-alist (cdr hier-alist)))
14241 ;; insert required packages
14242 (vhdl-speedbar-insert-subpackages
14243 subpack-alist (1+ indent) (1- indent))))
14244 (when (memq 'display vhdl-speedbar-save-cache)
14245 (add-to-list 'vhdl-updated-project-list key))
14246 (vhdl-speedbar-update-current-unit t t))))
14247 ((string-match "-" text) ; contract architecture
14248 (speedbar-change-expand-button-char ?+)
14249 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14250 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14251 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14252 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14253 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14254 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14255 (speedbar-delete-subblock indent)
14256 (when (memq 'display vhdl-speedbar-save-cache)
14257 (add-to-list 'vhdl-updated-project-list key))))
14258 (t (error "Nothing to display")))
14259 (when (equal (selected-frame) speedbar-frame)
14260 (speedbar-center-buffer-smartly)))
14262 (defun vhdl-speedbar-expand-config (text token indent)
14263 "Expand/contract the configuration under the cursor."
14265 ((string-match "+" text) ; expand configuration
14266 (let* ((key (vhdl-speedbar-line-key indent))
14267 (conf-alist (aget vhdl-config-alist key t))
14268 (conf-entry (aget conf-alist token))
14269 (ent-alist (aget vhdl-entity-alist key t))
14270 (hier-alist (vhdl-get-hierarchy
14271 ent-alist conf-alist (nth 3 conf-entry)
14272 (nth 4 conf-entry) token (nth 5 conf-entry)
14274 (subpack-alist (nth 6 conf-entry))
14276 (if (not (or hier-alist subpack-alist))
14277 (speedbar-change-expand-button-char ??)
14278 (speedbar-change-expand-button-char ?-)
14279 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14280 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14281 (aput 'unit-alist token nil)
14282 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14283 (speedbar-with-writable
14285 (end-of-line) (forward-char 1)
14286 ;; insert instance hierarchy
14288 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14290 (setq entry (car hier-alist))
14291 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14292 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14293 (vhdl-speedbar-make-inst-line
14294 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14295 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14296 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14297 (setq hier-alist (cdr hier-alist)))
14298 ;; insert required packages
14299 (vhdl-speedbar-insert-subpackages
14300 subpack-alist (1+ indent) indent)))
14301 (when (memq 'display vhdl-speedbar-save-cache)
14302 (add-to-list 'vhdl-updated-project-list key))
14303 (vhdl-speedbar-update-current-unit t t))))
14304 ((string-match "-" text) ; contract configuration
14305 (speedbar-change-expand-button-char ?+)
14306 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14307 (let* ((key (vhdl-speedbar-line-key indent))
14308 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14309 (adelete 'unit-alist token)
14311 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14312 (adelete 'vhdl-speedbar-shown-unit-alist key))
14313 (speedbar-delete-subblock indent)
14314 (when (memq 'display vhdl-speedbar-save-cache)
14315 (add-to-list 'vhdl-updated-project-list key))))
14316 (t (error "Nothing to display")))
14317 (when (equal (selected-frame) speedbar-frame)
14318 (speedbar-center-buffer-smartly)))
14320 (defun vhdl-speedbar-expand-package (text token indent)
14321 "Expand/contract the package under the cursor."
14323 ((string-match "+" text) ; expand package
14324 (let* ((key (vhdl-speedbar-line-key indent))
14325 (pack-alist (aget vhdl-package-alist key t))
14326 (pack-entry (aget pack-alist token t))
14327 (comp-alist (nth 3 pack-entry))
14328 (func-alist (nth 4 pack-entry))
14329 (func-body-alist (nth 8 pack-entry))
14330 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14331 comp-entry func-entry func-body-entry)
14332 (if (not (or comp-alist func-alist subpack-alist))
14333 (speedbar-change-expand-button-char ??)
14334 (speedbar-change-expand-button-char ?-)
14335 ;; add package to `vhdl-speedbar-shown-unit-alist'
14336 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14337 (aput 'unit-alist token nil)
14338 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14339 (speedbar-with-writable
14341 (end-of-line) (forward-char 1)
14342 ;; insert components
14344 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14346 (setq comp-entry (car comp-alist))
14347 (speedbar-make-tag-line
14349 (cons token (nth 0 comp-entry))
14350 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14351 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14352 'vhdl-speedbar-entity-face (1+ indent))
14353 (setq comp-alist (cdr comp-alist)))
14354 ;; insert subprograms
14356 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14358 (setq func-entry (car func-alist)
14359 func-body-entry (aget func-body-alist (car func-entry) t))
14360 (when (nth 2 func-entry)
14361 (vhdl-speedbar-make-subprogram-line
14363 (cons (nth 2 func-entry) (nth 3 func-entry))
14364 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14366 (setq func-alist (cdr func-alist)))
14367 ;; insert required packages
14368 (vhdl-speedbar-insert-subpackages
14369 subpack-alist (1+ indent) indent)))
14370 (when (memq 'display vhdl-speedbar-save-cache)
14371 (add-to-list 'vhdl-updated-project-list key))
14372 (vhdl-speedbar-update-current-unit t t))))
14373 ((string-match "-" text) ; contract package
14374 (speedbar-change-expand-button-char ?+)
14375 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14376 (let* ((key (vhdl-speedbar-line-key indent))
14377 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14378 (adelete 'unit-alist token)
14380 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14381 (adelete 'vhdl-speedbar-shown-unit-alist key))
14382 (speedbar-delete-subblock indent)
14383 (when (memq 'display vhdl-speedbar-save-cache)
14384 (add-to-list 'vhdl-updated-project-list key))))
14385 (t (error "Nothing to display")))
14386 (when (equal (selected-frame) speedbar-frame)
14387 (speedbar-center-buffer-smartly)))
14389 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14390 "Insert required packages."
14391 (let* ((pack-alist (aget vhdl-package-alist
14392 (vhdl-speedbar-line-key dir-indent) t))
14393 pack-key lib-name pack-entry)
14394 (when subpack-alist
14395 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14396 (while subpack-alist
14397 (setq pack-key (cdar subpack-alist)
14398 lib-name (caar subpack-alist))
14399 (setq pack-entry (aget pack-alist pack-key t))
14400 (vhdl-speedbar-make-subpack-line
14401 (or (nth 0 pack-entry) pack-key) lib-name
14402 (cons (nth 1 pack-entry) (nth 2 pack-entry)) indent)
14403 (setq subpack-alist (cdr subpack-alist)))))
14405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14406 ;; Display help functions
14408 (defvar vhdl-speedbar-update-current-unit t
14409 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14411 (defun vhdl-speedbar-update-current-project ()
14412 "Highlight project that is currently active."
14413 (when (and vhdl-speedbar-show-projects
14414 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14415 (and (boundp 'speedbar-frame)
14416 (frame-live-p speedbar-frame)))
14417 (let ((last-frame (selected-frame))
14418 (project-alist vhdl-project-alist)
14420 (select-frame speedbar-frame)
14421 (speedbar-with-writable
14423 (while project-alist
14424 (goto-char (point-min))
14425 (when (re-search-forward
14426 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14427 (put-text-property (match-beginning 1) (match-end 1) 'face
14428 (if (equal (caar project-alist) vhdl-project)
14429 'speedbar-selected-face
14430 'speedbar-directory-face))
14431 (when (equal (caar project-alist) vhdl-project)
14432 (setq pos (1- (match-beginning 1)))))
14433 (setq project-alist (cdr project-alist))))
14434 (when pos (goto-char pos)))
14435 (select-frame last-frame)
14436 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14439 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14440 "Highlight all design units that are contained in the current file.
14441 NO-POSITION non-nil means do not re-position cursor."
14442 (let ((last-frame (selected-frame))
14443 (project-list vhdl-speedbar-shown-project-list)
14444 file-alist pos file-name)
14445 ;; get current file name
14446 (if (fboundp 'speedbar-select-attached-frame)
14447 (speedbar-select-attached-frame)
14448 (select-frame speedbar-attached-frame))
14449 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14450 (when (and vhdl-speedbar-update-current-unit
14451 (or always (not (equal file-name speedbar-last-selected-file))))
14452 (if vhdl-speedbar-show-projects
14453 (while project-list
14454 (setq file-alist (append file-alist (aget vhdl-file-alist
14455 (car project-list) t)))
14456 (setq project-list (cdr project-list)))
14457 (setq file-alist (aget vhdl-file-alist
14458 (abbreviate-file-name default-directory) t)))
14459 (select-frame speedbar-frame)
14460 (set-buffer speedbar-buffer)
14461 (speedbar-with-writable
14462 (vhdl-prepare-search-1
14464 ;; unhighlight last units
14465 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14466 (vhdl-speedbar-update-units
14467 "\\[.\\] " (nth 0 file-entry)
14468 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14469 (vhdl-speedbar-update-units
14470 "{.} " (nth 1 file-entry)
14471 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14472 (vhdl-speedbar-update-units
14473 "\\[.\\] " (nth 3 file-entry)
14474 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14475 (vhdl-speedbar-update-units
14476 "[]>] " (nth 4 file-entry)
14477 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14478 (vhdl-speedbar-update-units
14479 "\\[.\\].+(" '("body")
14480 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14481 (vhdl-speedbar-update-units
14482 "> " (nth 6 file-entry)
14483 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14484 ;; highlight current units
14485 (let* ((file-entry (aget file-alist file-name t)))
14487 pos (vhdl-speedbar-update-units
14488 "\\[.\\] " (nth 0 file-entry)
14489 file-name 'vhdl-speedbar-entity-selected-face pos)
14490 pos (vhdl-speedbar-update-units
14491 "{.} " (nth 1 file-entry)
14492 file-name 'vhdl-speedbar-architecture-selected-face pos)
14493 pos (vhdl-speedbar-update-units
14494 "\\[.\\] " (nth 3 file-entry)
14495 file-name 'vhdl-speedbar-configuration-selected-face pos)
14496 pos (vhdl-speedbar-update-units
14497 "[]>] " (nth 4 file-entry)
14498 file-name 'vhdl-speedbar-package-selected-face pos)
14499 pos (vhdl-speedbar-update-units
14500 "\\[.\\].+(" '("body")
14501 file-name 'vhdl-speedbar-package-selected-face pos)
14502 pos (vhdl-speedbar-update-units
14503 "> " (nth 6 file-entry)
14504 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
14505 ;; move speedbar so the first highlighted unit is visible
14506 (when (and pos (not no-position))
14508 (speedbar-center-buffer-smartly)
14509 (speedbar-position-cursor-on-line))
14510 (setq speedbar-last-selected-file file-name))
14511 (select-frame last-frame)
14514 (defun vhdl-speedbar-update-units (text unit-list file-name face
14516 "Help function to highlight design units."
14518 (goto-char (point-min))
14519 (while (re-search-forward
14520 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14521 (when (equal file-name (car (get-text-property
14522 (match-beginning 1) 'speedbar-token)))
14523 (setq pos (or pos (point-marker)))
14524 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14525 (setq unit-list (cdr unit-list)))
14528 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14529 ent-name ent-file-marker
14530 arch-name arch-file-marker
14531 conf-name conf-file-marker
14532 lib-name depth offset delimiter)
14533 "Insert instantiation entry."
14534 (let ((start (point))
14536 (insert (int-to-string depth) ":")
14537 (put-text-property start (point) 'invisible t)
14538 (setq visible-start (point))
14539 (insert-char ? (* depth speedbar-indentation-width))
14540 (while (> offset 0)
14542 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14543 (setq offset (1- offset)))
14544 (put-text-property visible-start (point) 'invisible nil)
14545 (setq start (point))
14547 (speedbar-make-button start (point) nil nil nil)
14548 (setq visible-start (point))
14550 (setq start (point))
14551 (if (not inst-name)
14554 (speedbar-make-button
14555 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14556 'vhdl-speedbar-find-file inst-file-marker))
14559 (setq start (point))
14561 (speedbar-make-button
14562 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14563 'vhdl-speedbar-find-file ent-file-marker)
14566 (setq start (point))
14568 (speedbar-make-button
14569 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14570 'vhdl-speedbar-find-file arch-file-marker)
14574 (setq start (point))
14576 (speedbar-make-button
14577 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14578 'vhdl-speedbar-find-file conf-file-marker)
14580 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14581 (setq start (point))
14582 (insert " (" lib-name ")")
14583 (put-text-property (+ 2 start) (1- (point)) 'face
14584 'vhdl-speedbar-library-face))
14585 (insert-char ?\n 1)
14586 (put-text-property visible-start (point) 'invisible nil)))
14588 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14589 body-file-marker depth)
14590 "Insert package entry."
14591 (let ((start (point))
14593 (insert (int-to-string depth) ":")
14594 (put-text-property start (point) 'invisible t)
14595 (setq visible-start (point))
14596 (insert-char ? (* depth speedbar-indentation-width))
14597 (put-text-property visible-start (point) 'invisible nil)
14598 (setq start (point))
14600 (speedbar-make-button
14601 start (point) 'speedbar-button-face 'speedbar-highlight-face
14602 'vhdl-speedbar-expand-package pack-key)
14603 (setq visible-start (point))
14604 (insert-char ? 1 nil)
14605 (setq start (point))
14607 (speedbar-make-button
14608 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14609 'vhdl-speedbar-find-file pack-file-marker)
14610 (unless (car pack-file-marker)
14612 (when (car body-file-marker)
14614 (setq start (point))
14616 (speedbar-make-button
14617 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14618 'vhdl-speedbar-find-file body-file-marker)
14620 (insert-char ?\n 1)
14621 (put-text-property visible-start (point) 'invisible nil)))
14623 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14625 "Insert used package entry."
14626 (let ((start (point))
14628 (insert (int-to-string depth) ":")
14629 (put-text-property start (point) 'invisible t)
14630 (setq visible-start (point))
14631 (insert-char ? (* depth speedbar-indentation-width))
14632 (put-text-property visible-start (point) 'invisible nil)
14633 (setq start (point))
14635 (speedbar-make-button start (point) nil nil nil)
14636 (setq visible-start (point))
14638 (setq start (point))
14640 (speedbar-make-button
14641 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14642 'vhdl-speedbar-find-file pack-file-marker)
14643 (setq start (point))
14644 (insert " (" lib-name ")")
14645 (put-text-property (+ 2 start) (1- (point)) 'face
14646 'vhdl-speedbar-library-face)
14647 (insert-char ?\n 1)
14648 (put-text-property visible-start (point) 'invisible nil)))
14650 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14651 func-body-file-marker
14653 "Insert subprogram entry."
14654 (let ((start (point))
14656 (insert (int-to-string depth) ":")
14657 (put-text-property start (point) 'invisible t)
14658 (setq visible-start (point))
14659 (insert-char ? (* depth speedbar-indentation-width))
14660 (put-text-property visible-start (point) 'invisible nil)
14661 (setq start (point))
14663 (speedbar-make-button start (point) nil nil nil)
14664 (setq visible-start (point))
14666 (setq start (point))
14668 (speedbar-make-button
14669 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14670 'vhdl-speedbar-find-file func-file-marker)
14671 (when (car func-body-file-marker)
14673 (setq start (point))
14675 (speedbar-make-button
14676 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14677 'vhdl-speedbar-find-file func-body-file-marker)
14679 (insert-char ?\n 1)
14680 (put-text-property visible-start (point) 'invisible nil)))
14682 (defun vhdl-speedbar-make-title-line (text &optional depth)
14683 "Insert design unit title entry."
14684 (let ((start (point))
14687 (insert (int-to-string depth) ":")
14688 (put-text-property start (point) 'invisible t))
14689 (setq visible-start (point))
14690 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14691 (setq start (point))
14693 (speedbar-make-button start (point) nil nil nil nil)
14694 (insert-char ?\n 1)
14695 (put-text-property visible-start (point) 'invisible nil)))
14697 (defun vhdl-speedbar-insert-dirs (files level)
14698 "Insert subdirectories."
14699 (let ((dirs (car files)))
14701 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14702 (car dirs) 'speedbar-dir-follow nil
14703 'speedbar-directory-face level)
14704 (setq dirs (cdr dirs)))))
14706 (defun vhdl-speedbar-dired (text token indent)
14707 "Speedbar click handler for directory expand button in hierarchy mode."
14708 (cond ((string-match "+" text) ; we have to expand this dir
14709 (setq speedbar-shown-directories
14710 (cons (expand-file-name
14711 (concat (speedbar-line-path indent) token "/"))
14712 speedbar-shown-directories))
14713 (speedbar-change-expand-button-char ?-)
14714 (speedbar-reset-scanners)
14715 (speedbar-with-writable
14717 (end-of-line) (forward-char 1)
14718 (vhdl-speedbar-insert-dirs
14719 (speedbar-file-lists
14720 (concat (speedbar-line-path indent) token "/"))
14722 (speedbar-reset-scanners)
14723 (vhdl-speedbar-insert-dir-hierarchy
14724 (abbreviate-file-name
14725 (concat (speedbar-line-path indent) token "/"))
14726 (1+ indent) speedbar-power-click)))
14727 (vhdl-speedbar-update-current-unit t t))
14728 ((string-match "-" text) ; we have to contract this node
14729 (speedbar-reset-scanners)
14730 (let ((oldl speedbar-shown-directories)
14732 (td (expand-file-name
14733 (concat (speedbar-line-path indent) token))))
14735 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14736 (setq newl (cons (car oldl) newl)))
14737 (setq oldl (cdr oldl)))
14738 (setq speedbar-shown-directories (nreverse newl)))
14739 (speedbar-change-expand-button-char ?+)
14740 (speedbar-delete-subblock indent))
14741 (t (error "Nothing to display")))
14742 (when (equal (selected-frame) speedbar-frame)
14743 (speedbar-center-buffer-smartly)))
14745 (defun vhdl-speedbar-item-info ()
14746 "Derive and display information about this line item."
14748 (beginning-of-line)
14749 ;; skip invisible number info
14750 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
14752 ;; project/directory entry
14753 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14754 (if vhdl-speedbar-show-projects
14755 (message "Project \"%s\"" (match-string-no-properties 1))
14756 (speedbar-files-item-info)))
14757 ;; design unit entry
14758 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14759 (goto-char (match-end 1))
14760 (let ((face (get-text-property (point) 'face)))
14762 "%s \"%s\" in \"%s\""
14763 ;; design unit kind
14764 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14765 (eq face 'vhdl-speedbar-entity-selected-face))
14766 (if (equal (match-string 2) ">") "Component" "Entity"))
14767 ((or (eq face 'vhdl-speedbar-architecture-face)
14768 (eq face 'vhdl-speedbar-architecture-selected-face))
14770 ((or (eq face 'vhdl-speedbar-configuration-face)
14771 (eq face 'vhdl-speedbar-configuration-selected-face))
14773 ((or (eq face 'vhdl-speedbar-package-face)
14774 (eq face 'vhdl-speedbar-package-selected-face))
14776 ((or (eq face 'vhdl-speedbar-instantiation-face)
14777 (eq face 'vhdl-speedbar-instantiation-selected-face))
14779 ((eq face 'vhdl-speedbar-subprogram-face)
14782 ;; design unit name
14783 (buffer-substring-no-properties
14784 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14787 (file-relative-name
14788 (or (car (get-text-property (point) 'speedbar-token))
14790 (vhdl-default-directory)))))
14791 (t (message "")))))
14793 (defun vhdl-speedbar-line-text ()
14794 "Calls `speedbar-line-text' and removes text properties."
14795 (let ((string (speedbar-line-text)))
14796 (set-text-properties 0 (length string) nil string)
14799 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14802 (defun vhdl-speedbar-line-key (&optional indent)
14803 "Get currently displayed directory of project name."
14804 (if vhdl-speedbar-show-projects
14805 (vhdl-speedbar-line-project)
14806 (abbreviate-file-name
14807 (file-name-as-directory (speedbar-line-path indent)))))
14809 (defun vhdl-speedbar-line-project (&optional indent)
14810 "Get currently displayed project name."
14811 (and vhdl-speedbar-show-projects
14814 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
14815 (match-string-no-properties 1))))
14817 (defun vhdl-add-modified-file ()
14818 "Add file to `vhdl-modified-file-list'."
14819 (when vhdl-file-alist
14820 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
14823 (defun vhdl-resolve-paths (path-list)
14824 "Resolve path wildcards in PATH-LIST."
14825 (let (path-list-1 path-list-2 path-beg path-end dir)
14826 ;; eliminate non-existent directories
14828 (setq dir (car path-list))
14829 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
14830 (if (file-directory-p (match-string 2 dir))
14831 (setq path-list-1 (cons dir path-list-1))
14832 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
14833 (setq path-list (cdr path-list)))
14834 ;; resolve path wildcards
14836 (setq dir (car path-list-1))
14837 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
14839 (setq path-beg (match-string 1 dir)
14840 path-end (match-string 5 dir))
14845 (lambda (var) (concat path-beg var path-end)))
14846 (let ((all-list (vhdl-directory-files
14847 (match-string 2 dir) t
14848 (concat "\\<" (wildcard-to-regexp
14849 (match-string 4 dir)))))
14852 (when (file-directory-p (car all-list))
14853 (setq dir-list (cons (car all-list) dir-list)))
14854 (setq all-list (cdr all-list)))
14856 (cdr path-list-1))))
14857 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
14858 (when (file-directory-p (match-string 2 dir))
14859 (setq path-list-2 (cons dir path-list-2)))
14860 (setq path-list-1 (cdr path-list-1))))
14861 (nreverse path-list-2)))
14863 (defun vhdl-speedbar-goto-this-unit (directory unit)
14864 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
14865 (let ((dest (point)))
14866 (if (and (if vhdl-speedbar-show-projects
14867 (progn (goto-char (point-min)) t)
14868 (speedbar-goto-this-file directory))
14869 (re-search-forward (concat "[]}] " unit "\\>") nil t))
14870 (progn (speedbar-position-cursor-on-line)
14875 (defun vhdl-speedbar-find-file (text token indent)
14876 "When user clicks on TEXT, load file with name and position in TOKEN.
14877 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
14878 is already shown in a buffer."
14879 (if (not (car token))
14880 (error "ERROR: File cannot be found")
14881 (let ((buffer (get-file-buffer (car token))))
14882 (speedbar-find-file-in-frame (car token))
14883 (when (or vhdl-speedbar-jump-to-unit buffer)
14884 (goto-line (cdr token))
14886 (vhdl-speedbar-update-current-unit t t)
14887 (speedbar-set-timer speedbar-update-speed)
14888 (speedbar-maybee-jump-to-attached-frame))))
14890 (defun vhdl-speedbar-port-copy ()
14891 "Copy the port of the entity/component or subprogram under the cursor."
14893 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
14894 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
14895 (error "ERROR: No entity/component or subprogram under cursor")
14896 (beginning-of-line)
14897 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
14898 (condition-case info
14899 (let ((token (get-text-property
14900 (match-beginning 3) 'speedbar-token)))
14901 (vhdl-visit-file (car token) t
14902 (progn (goto-line (cdr token))
14906 (vhdl-subprog-copy)))))
14907 (error (error "ERROR: %s not scanned successfully\n (%s)"
14908 (if is-entity "Port" "Interface") (cadr info))))
14909 (error "ERROR: No entity/component or subprogram on current line")))))
14911 (defun vhdl-speedbar-place-component ()
14912 "Place the entity/component under the cursor as component."
14914 (if (not (vhdl-speedbar-check-unit 'entity))
14915 (error "ERROR: No entity/component under cursor.")
14916 (vhdl-speedbar-port-copy)
14917 (if (fboundp 'speedbar-select-attached-frame)
14918 (speedbar-select-attached-frame)
14919 (select-frame speedbar-attached-frame))
14920 (vhdl-compose-place-component)
14921 (select-frame speedbar-frame)))
14923 (defun vhdl-speedbar-make-design ()
14924 "Make (compile) design unit or directory/project under the cursor."
14926 (if (not (save-excursion (beginning-of-line)
14927 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
14928 (error "ERROR: No primary design unit or directory/project under cursor")
14929 (let ((is-unit (match-string 2))
14930 (unit-name (vhdl-speedbar-line-text))
14931 (vhdl-project (vhdl-speedbar-line-project))
14932 (directory (file-name-as-directory
14933 (or (speedbar-line-file) (speedbar-line-path)))))
14934 (if (fboundp 'speedbar-select-attached-frame)
14935 (speedbar-select-attached-frame)
14936 (select-frame speedbar-attached-frame))
14937 (let ((default-directory directory))
14938 (vhdl-make (and is-unit unit-name))))))
14940 (defun vhdl-speedbar-generate-makefile ()
14941 "Generate Makefile for directory/project under the cursor."
14943 (let ((vhdl-project (vhdl-speedbar-line-project))
14944 (default-directory (file-name-as-directory
14945 (or (speedbar-line-file) (speedbar-line-path)))))
14946 (vhdl-generate-makefile)))
14948 (defun vhdl-speedbar-check-unit (design-unit)
14949 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
14950 expansion function)."
14952 (speedbar-position-cursor-on-line)
14953 (cond ((eq design-unit 'entity)
14954 (memq (get-text-property (match-end 0) 'face)
14955 '(vhdl-speedbar-entity-face
14956 vhdl-speedbar-entity-selected-face)))
14957 ((eq design-unit 'subprogram)
14958 (eq (get-text-property (match-end 0) 'face)
14959 'vhdl-speedbar-subprogram-face))
14962 (defun vhdl-speedbar-set-depth (depth)
14963 "Set hierarchy display depth to DEPTH and refresh speedbar."
14964 (setq vhdl-speedbar-hierarchy-depth depth)
14965 (speedbar-refresh))
14967 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14970 (defface vhdl-speedbar-entity-face
14971 '((((class color) (background light)) (:foreground "ForestGreen"))
14972 (((class color) (background dark)) (:foreground "PaleGreen")))
14973 "Face used for displaying entity names."
14974 :group 'speedbar-faces)
14976 (defface vhdl-speedbar-architecture-face
14977 '((((class color) (background light)) (:foreground "Blue"))
14978 (((class color) (background dark)) (:foreground "LightSkyBlue")))
14979 "Face used for displaying architecture names."
14980 :group 'speedbar-faces)
14982 (defface vhdl-speedbar-configuration-face
14983 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
14984 (((class color) (background dark)) (:foreground "Salmon")))
14985 "Face used for displaying configuration names."
14986 :group 'speedbar-faces)
14988 (defface vhdl-speedbar-package-face
14989 '((((class color) (background light)) (:foreground "Grey50"))
14990 (((class color) (background dark)) (:foreground "Grey80")))
14991 "Face used for displaying package names."
14992 :group 'speedbar-faces)
14994 (defface vhdl-speedbar-library-face
14995 '((((class color) (background light)) (:foreground "Purple"))
14996 (((class color) (background dark)) (:foreground "Orchid1")))
14997 "Face used for displaying library names."
14998 :group 'speedbar-faces)
15000 (defface vhdl-speedbar-instantiation-face
15001 '((((class color) (background light)) (:foreground "Brown"))
15002 (((class color) (background dark)) (:foreground "Yellow")))
15003 "Face used for displaying instantiation names."
15004 :group 'speedbar-faces)
15006 (defface vhdl-speedbar-subprogram-face
15007 '((((class color) (background light)) (:foreground "Orchid4"))
15008 (((class color) (background dark)) (:foreground "BurlyWood2")))
15009 "Face used for displaying subprogram names."
15010 :group 'speedbar-faces)
15012 (defface vhdl-speedbar-entity-selected-face
15013 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15014 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15015 "Face used for displaying entity names."
15016 :group 'speedbar-faces)
15018 (defface vhdl-speedbar-architecture-selected-face
15019 '((((class color) (background light)) (:foreground "Blue" :underline t))
15020 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15021 "Face used for displaying architecture names."
15022 :group 'speedbar-faces)
15024 (defface vhdl-speedbar-configuration-selected-face
15025 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15026 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15027 "Face used for displaying configuration names."
15028 :group 'speedbar-faces)
15030 (defface vhdl-speedbar-package-selected-face
15031 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15032 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15033 "Face used for displaying package names."
15034 :group 'speedbar-faces)
15036 (defface vhdl-speedbar-instantiation-selected-face
15037 '((((class color) (background light)) (:foreground "Brown" :underline t))
15038 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15039 "Face used for displaying instantiation names."
15040 :group 'speedbar-faces)
15042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15046 (when (fboundp 'speedbar)
15048 (when (and vhdl-speedbar-auto-open
15049 (not (and (boundp 'speedbar-frame)
15050 (frame-live-p speedbar-frame))))
15051 (speedbar-frame-mode 1)
15052 (if (fboundp 'speedbar-select-attached-frame)
15053 (speedbar-select-attached-frame)
15054 (select-frame speedbar-attached-frame)))
15055 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15057 ;; initialize speedbar
15058 (if (not (boundp 'speedbar-frame))
15059 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15060 (vhdl-speedbar-initialize)
15061 (when speedbar-frame (vhdl-speedbar-refresh)))
15064 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15065 ;;; Structural composition
15066 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15068 (defun vhdl-get-components-package-name ()
15069 "Return the name of the components package."
15070 (let ((project (vhdl-project-p)))
15072 (vhdl-replace-string (car vhdl-components-package-name)
15073 (subst-char-in-string ? ?_ project))
15074 (cdr vhdl-components-package-name))))
15076 (defun vhdl-compose-new-component ()
15077 "Create entity and architecture for new component."
15079 (let* ((case-fold-search t)
15080 (ent-name (read-from-minibuffer "entity name: "
15081 nil vhdl-minibuffer-local-map))
15083 (if (equal (cdr vhdl-compose-architecture-name) "")
15084 (read-from-minibuffer "architecture name: "
15085 nil vhdl-minibuffer-local-map)
15086 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15087 ent-file-name arch-file-name ent-buffer arch-buffer project)
15088 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15089 ;; open entity file
15090 (unless (eq vhdl-compose-create-files 'none)
15091 (setq ent-file-name
15092 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15093 "." (file-name-extension (buffer-file-name))))
15094 (when (and (file-exists-p ent-file-name)
15095 (not (y-or-n-p (concat "File \"" ent-file-name
15096 "\" exists; overwrite? "))))
15097 (error "ERROR: Creating component...aborted"))
15098 (find-file ent-file-name)
15100 (set-buffer-modified-p nil))
15102 (if vhdl-compose-include-header
15103 (progn (vhdl-template-header)
15104 (goto-char (point-max)))
15105 (vhdl-comment-display-line) (insert "\n\n"))
15106 ;; insert library clause
15107 (vhdl-template-package-std-logic-1164)
15108 (when vhdl-use-components-package
15110 (vhdl-template-standard-package (vhdl-work-library)
15111 (vhdl-get-components-package-name)))
15112 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15113 ;; insert entity declaration
15114 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15115 (vhdl-insert-keyword " IS\n")
15116 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15117 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15118 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15119 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15120 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15121 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15122 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15123 (vhdl-insert-keyword "END ")
15124 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15125 (insert ent-name ";\n\n")
15126 (vhdl-comment-display-line) (insert "\n")
15127 ;; open architecture file
15128 (if (not (eq vhdl-compose-create-files 'separate))
15130 (setq ent-buffer (current-buffer))
15131 (setq arch-file-name
15132 (concat (vhdl-replace-string vhdl-architecture-file-name
15133 (concat ent-name " " arch-name))
15134 "." (file-name-extension (buffer-file-name))))
15135 (when (and (file-exists-p arch-file-name)
15136 (not (y-or-n-p (concat "File \"" arch-file-name
15137 "\" exists; overwrite? "))))
15138 (error "ERROR: Creating component...aborted"))
15139 (find-file arch-file-name)
15141 (set-buffer-modified-p nil)
15143 (if vhdl-compose-include-header
15144 (progn (vhdl-template-header)
15145 (goto-char (point-max)))
15146 (vhdl-comment-display-line) (insert "\n\n")))
15147 ;; insert architecture body
15148 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15149 (vhdl-insert-keyword " OF ") (insert ent-name)
15150 (vhdl-insert-keyword " IS\n\n")
15151 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15152 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15153 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15154 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15155 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15156 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15157 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15158 (vhdl-insert-keyword "BEGIN")
15159 (when vhdl-self-insert-comments
15161 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15162 (insert arch-name))
15164 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15165 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15166 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15167 (vhdl-insert-keyword "END ")
15168 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15169 (insert arch-name ";\n\n")
15171 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15172 (vhdl-template-footer)
15173 (vhdl-comment-display-line) (insert "\n"))
15174 (goto-char (point-min))
15175 (setq arch-buffer (current-buffer))
15176 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15177 (set-buffer arch-buffer) (save-buffer)
15179 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15181 (format "\n File created: \"%s\"" ent-file-name))
15182 (and arch-file-name
15183 (format "\n File created: \"%s\"" arch-file-name))))))
15185 (defun vhdl-compose-place-component ()
15186 "Place new component by pasting current port as component declaration and
15187 component instantiation."
15189 (if (not vhdl-port-list)
15190 (error "ERROR: No port has been read")
15192 (vhdl-prepare-search-2
15193 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15194 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15195 (error "ERROR: No architecture found"))
15196 (let* ((ent-name (match-string 1))
15198 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15199 "." (file-name-extension (buffer-file-name))))
15200 (orig-buffer (current-buffer)))
15201 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15202 ;; place component declaration
15203 (unless (or vhdl-use-components-package
15204 (vhdl-use-direct-instantiation)
15207 (concat "^\\s-*component\\s-+"
15208 (car vhdl-port-list) "\\>") nil t)))
15209 (re-search-forward "^begin\\>" nil)
15210 (beginning-of-line)
15211 (skip-chars-backward " \t\n")
15212 (insert "\n\n") (indent-to vhdl-basic-offset)
15213 (vhdl-port-paste-component t))
15214 ;; place component instantiation
15215 (re-search-forward "^end\\>" nil)
15216 (beginning-of-line)
15217 (skip-chars-backward " \t\n")
15218 (insert "\n\n") (indent-to vhdl-basic-offset)
15219 (vhdl-port-paste-instance nil t t)
15220 ;; place use clause for used packages
15221 (when (nth 3 vhdl-port-list)
15222 ;; open entity file
15223 (when (file-exists-p ent-file-name)
15224 (find-file ent-file-name))
15225 (goto-char (point-min))
15226 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15227 (error "ERROR: Entity not found: \"%s\"" ent-name))
15228 (goto-char (match-beginning 0))
15229 (if (and (save-excursion
15230 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15232 (progn (goto-char (match-end 0))
15233 (beginning-of-line 2))
15236 (vhdl-port-paste-context-clause)
15237 (switch-to-buffer orig-buffer))
15238 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15240 (defun vhdl-compose-wire-components ()
15241 "Connect components."
15244 (vhdl-prepare-search-2
15245 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15246 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15247 (error "ERROR: No architecture found"))
15248 (let* ((ent-name (match-string 1))
15250 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15251 "." (file-name-extension (buffer-file-name))))
15252 (arch-decl-pos (point-marker))
15253 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15254 (arch-end-pos (re-search-forward "^end\\>" nil))
15255 (pack-name (vhdl-get-components-package-name))
15257 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15258 "." (file-name-extension (buffer-file-name))))
15259 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15260 port-alist generic-alist inst-alist
15261 signal-name signal-entry signal-alist local-list written-list
15262 single-in-list multi-in-list single-out-list multi-out-list
15263 constant-name constant-entry constant-alist single-list multi-list
15264 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15265 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15266 signal-beg-pos signal-pos
15267 constant-temp-pos port-temp-pos signal-temp-pos)
15268 (message "Wiring components...")
15269 ;; process all instances
15270 (goto-char arch-stat-pos)
15271 (while (re-search-forward
15272 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15273 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15274 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15275 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15276 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15277 (setq inst-name (match-string-no-properties 1)
15278 comp-name (match-string-no-properties 4)
15279 comp-ent-name (match-string-no-properties 12)
15280 has-generic (or (match-string 7) (match-string 17)))
15283 ;; ... from component declaration
15285 (when vhdl-use-components-package pack-file-name) t
15287 (goto-char (point-min))
15288 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15289 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15291 ;; ... from entity declaration (direct instantiation)
15292 (setq comp-ent-file-name
15293 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name)
15294 "." (file-name-extension (buffer-file-name))))
15296 comp-ent-file-name t
15298 (goto-char (point-min))
15299 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15300 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15301 (vhdl-port-copy))))
15302 (vhdl-port-flatten t)
15303 (setq generic-alist (nth 1 vhdl-port-list)
15304 port-alist (nth 2 vhdl-port-list))
15305 (setq constant-alist nil
15308 ;; process all constants in generic map
15309 (vhdl-forward-syntactic-ws)
15310 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15311 (setq constant-name (match-string-no-properties 3))
15312 (setq constant-entry
15313 (cons constant-name
15314 (if (match-string 1)
15315 (or (aget generic-alist (match-string 2) t)
15316 (error (format "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15317 (cdar generic-alist))))
15318 (setq constant-alist (cons constant-entry constant-alist))
15319 (setq constant-name (downcase constant-name))
15320 (if (or (member constant-name single-list)
15321 (member constant-name multi-list))
15322 (progn (setq single-list (delete constant-name single-list))
15323 (add-to-list 'multi-list constant-name))
15324 (add-to-list 'single-list constant-name))
15325 (unless (match-string 1)
15326 (setq generic-alist (cdr generic-alist)))
15327 (vhdl-forward-syntactic-ws))
15328 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15329 ;; process all signals in port map
15330 (vhdl-forward-syntactic-ws)
15331 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15332 (setq signal-name (match-string-no-properties 3))
15333 (setq signal-entry (cons signal-name
15334 (if (match-string 1)
15335 (or (aget port-alist (match-string 2) t)
15336 (error (format "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15337 (cdar port-alist))))
15338 (setq signal-alist (cons signal-entry signal-alist))
15339 (setq signal-name (downcase signal-name))
15340 (if (equal (upcase (nth 2 signal-entry)) "IN")
15343 ((member signal-name local-list)
15345 ((or (member signal-name single-out-list)
15346 (member signal-name multi-out-list))
15347 (setq single-out-list (delete signal-name single-out-list))
15348 (setq multi-out-list (delete signal-name multi-out-list))
15349 (add-to-list 'local-list signal-name))
15350 ((member signal-name single-in-list)
15351 (setq single-in-list (delete signal-name single-in-list))
15352 (add-to-list 'multi-in-list signal-name))
15353 ((not (member signal-name multi-in-list))
15354 (add-to-list 'single-in-list signal-name)))
15357 ((member signal-name local-list)
15359 ((or (member signal-name single-in-list)
15360 (member signal-name multi-in-list))
15361 (setq single-in-list (delete signal-name single-in-list))
15362 (setq multi-in-list (delete signal-name multi-in-list))
15363 (add-to-list 'local-list signal-name))
15364 ((member signal-name single-out-list)
15365 (setq single-out-list (delete signal-name single-out-list))
15366 (add-to-list 'multi-out-list signal-name))
15367 ((not (member signal-name multi-out-list))
15368 (add-to-list 'single-out-list signal-name))))
15369 (unless (match-string 1)
15370 (setq port-alist (cdr port-alist)))
15371 (vhdl-forward-syntactic-ws))
15372 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15373 (nreverse signal-alist)) inst-alist)))
15374 ;; prepare signal insertion
15375 (vhdl-goto-marker arch-decl-pos)
15377 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15378 (setq signal-pos (point-marker))
15379 (while (progn (vhdl-forward-syntactic-ws)
15380 (looking-at "signal\\>"))
15381 (beginning-of-line 2)
15382 (delete-region signal-pos (point)))
15383 (setq signal-beg-pos signal-pos)
15384 ;; open entity file
15385 (when (file-exists-p ent-file-name)
15386 (find-file ent-file-name))
15387 (goto-char (point-min))
15388 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15389 (error "ERROR: Entity not found: \"%s\"" ent-name))
15390 ;; prepare generic clause insertion
15391 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15393 (goto-char (match-beginning 0))
15394 (indent-to vhdl-basic-offset)
15395 (insert "generic ();\n\n")
15398 (setq generic-pos (point-marker))
15399 (forward-sexp) (end-of-line)
15400 (delete-region generic-pos (point)) (delete-char 1)
15404 (indent-to (* 2 vhdl-basic-offset))
15405 (insert "-- global generics\n"))
15406 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15407 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15408 ;; prepare port clause insertion
15409 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15411 (goto-char (match-beginning 0))
15412 (indent-to vhdl-basic-offset)
15413 (insert "port ();\n\n")
15416 (setq port-in-pos (point-marker))
15417 (forward-sexp) (end-of-line)
15418 (delete-region port-in-pos (point)) (delete-char 1)
15420 (when (or multi-in-list multi-out-list)
15422 (indent-to (* 2 vhdl-basic-offset))
15423 (insert "-- global ports\n"))
15424 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15425 port-out-pos (point-marker) port-inst-pos (point-marker)
15426 port-end-pos (point-marker))
15427 ;; insert generics, ports and signals
15428 (setq inst-alist (nreverse inst-alist))
15430 (setq inst-name (nth 0 (car inst-alist))
15431 constant-alist (nth 1 (car inst-alist))
15432 signal-alist (nth 2 (car inst-alist))
15433 constant-temp-pos generic-inst-pos
15434 port-temp-pos port-inst-pos
15435 signal-temp-pos signal-pos)
15437 (while constant-alist
15438 (setq constant-name (downcase (caar constant-alist))
15439 constant-entry (car constant-alist))
15440 (cond ((member constant-name written-list)
15442 ((member constant-name multi-list)
15443 (vhdl-goto-marker generic-pos)
15444 (setq generic-end-pos
15447 (vhdl-compose-insert-generic constant-entry)))
15448 (setq generic-pos (point-marker))
15449 (add-to-list 'written-list constant-name))
15452 (vhdl-max-marker generic-inst-pos generic-pos))
15453 (setq generic-end-pos
15454 (vhdl-compose-insert-generic constant-entry))
15455 (setq generic-inst-pos (point-marker))
15456 (add-to-list 'written-list constant-name)))
15457 (setq constant-alist (cdr constant-alist)))
15458 (when (/= constant-temp-pos generic-inst-pos)
15459 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15460 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15461 (insert "-- generics for \"" inst-name "\"\n")
15462 (vhdl-goto-marker generic-inst-pos))
15463 ;; ports and signals
15464 (while signal-alist
15465 (setq signal-name (downcase (caar signal-alist))
15466 signal-entry (car signal-alist))
15467 (cond ((member signal-name written-list)
15469 ((member signal-name multi-in-list)
15470 (vhdl-goto-marker port-in-pos)
15473 port-end-pos (vhdl-compose-insert-port signal-entry)))
15474 (setq port-in-pos (point-marker))
15475 (add-to-list 'written-list signal-name))
15476 ((member signal-name multi-out-list)
15477 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15480 port-end-pos (vhdl-compose-insert-port signal-entry)))
15481 (setq port-out-pos (point-marker))
15482 (add-to-list 'written-list signal-name))
15483 ((or (member signal-name single-in-list)
15484 (member signal-name single-out-list))
15488 (vhdl-max-marker port-out-pos port-in-pos)))
15489 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15490 (setq port-inst-pos (point-marker))
15491 (add-to-list 'written-list signal-name))
15492 ((equal (upcase (nth 2 signal-entry)) "OUT")
15493 (vhdl-goto-marker signal-pos)
15494 (vhdl-compose-insert-signal signal-entry)
15495 (setq signal-pos (point-marker))
15496 (add-to-list 'written-list signal-name)))
15497 (setq signal-alist (cdr signal-alist)))
15498 (when (/= port-temp-pos port-inst-pos)
15500 (vhdl-max-marker port-temp-pos
15501 (vhdl-max-marker port-in-pos port-out-pos)))
15502 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15503 (insert "-- ports to \"" inst-name "\"\n")
15504 (vhdl-goto-marker port-inst-pos))
15505 (when (/= signal-temp-pos signal-pos)
15506 (vhdl-goto-marker signal-temp-pos)
15507 (insert "\n") (indent-to vhdl-basic-offset)
15508 (insert "-- outputs of \"" inst-name "\"\n")
15509 (vhdl-goto-marker signal-pos))
15510 (setq inst-alist (cdr inst-alist)))
15511 ;; finalize generic/port clause
15512 (vhdl-goto-marker generic-end-pos) (backward-char)
15513 (when (= generic-beg-pos generic-end-pos)
15514 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15515 (insert ";") (backward-char))
15517 (vhdl-goto-marker port-end-pos) (backward-char)
15518 (when (= port-beg-pos port-end-pos)
15519 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15520 (insert ";") (backward-char))
15522 ;; align everything
15523 (when vhdl-auto-align
15524 (vhdl-goto-marker generic-beg-pos)
15525 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15526 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15527 (vhdl-goto-marker signal-beg-pos)
15528 (vhdl-align-region-groups signal-beg-pos signal-pos))
15529 (switch-to-buffer (marker-buffer signal-beg-pos))
15530 (message "Wiring components...done")))))
15532 (defun vhdl-compose-insert-generic (entry)
15533 "Insert ENTRY as generic declaration."
15535 (indent-to (* 2 vhdl-basic-offset))
15536 (insert (nth 0 entry) " : " (nth 1 entry))
15537 (when (nth 2 entry)
15538 (insert " := " (nth 2 entry)))
15540 (setq pos (point-marker))
15541 (when (and vhdl-include-port-comments (nth 3 entry))
15542 (vhdl-comment-insert-inline (nth 3 entry) t))
15546 (defun vhdl-compose-insert-port (entry)
15547 "Insert ENTRY as port declaration."
15549 (indent-to (* 2 vhdl-basic-offset))
15550 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15551 (setq pos (point-marker))
15552 (when (and vhdl-include-port-comments (nth 4 entry))
15553 (vhdl-comment-insert-inline (nth 4 entry) t))
15557 (defun vhdl-compose-insert-signal (entry)
15558 "Insert ENTRY as signal declaration."
15559 (indent-to vhdl-basic-offset)
15560 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15561 (when (and vhdl-include-port-comments (nth 4 entry))
15562 (vhdl-comment-insert-inline (nth 4 entry) t))
15565 (defun vhdl-compose-components-package ()
15566 "Generate a package containing component declarations for all entities in the
15567 current project/directory."
15569 (vhdl-require-hierarchy-info)
15570 (let* ((project (vhdl-project-p))
15571 (pack-name (vhdl-get-components-package-name))
15573 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15574 "." (file-name-extension (buffer-file-name))))
15575 (ent-alist (aget vhdl-entity-alist
15576 (or project default-directory) t))
15577 (lazy-lock-minimum-size 0)
15578 clause-pos component-pos)
15579 (message "Generating components package \"%s\"..." pack-name)
15580 ;; open package file
15581 (when (and (file-exists-p pack-file-name)
15582 (not (y-or-n-p (concat "File \"" pack-file-name
15583 "\" exists; overwrite? "))))
15584 (error "ERROR: Generating components package...aborted"))
15585 (find-file pack-file-name)
15588 (if vhdl-compose-include-header
15589 (progn (vhdl-template-header
15590 (concat "Components package (generated by Emacs VHDL Mode "
15592 (goto-char (point-max)))
15593 (vhdl-comment-display-line) (insert "\n\n"))
15594 ;; insert std_logic_1164 package
15595 (vhdl-template-package-std-logic-1164)
15596 (insert "\n") (setq clause-pos (point-marker))
15597 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15598 ;; insert package declaration
15599 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15600 (vhdl-insert-keyword " IS\n\n")
15601 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15602 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15603 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15604 (indent-to vhdl-basic-offset)
15605 (setq component-pos (point-marker))
15606 (insert "\n\n") (vhdl-insert-keyword "END ")
15607 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15608 (insert pack-name ";\n\n")
15610 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15611 (vhdl-template-footer)
15612 (vhdl-comment-display-line) (insert "\n"))
15613 ;; insert component declarations
15615 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15616 (progn (goto-line (nth 3 (car ent-alist)))
15619 (goto-char component-pos)
15620 (vhdl-port-paste-component t)
15621 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15622 (setq component-pos (point-marker))
15623 (goto-char clause-pos)
15624 (vhdl-port-paste-context-clause pack-name)
15625 (setq clause-pos (point-marker))
15626 (setq ent-alist (cdr ent-alist)))
15627 (goto-char (point-min))
15629 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15630 pack-name pack-file-name)))
15633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15634 ;;; Compilation / Makefile generation
15635 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15636 ;; (using `compile.el')
15638 (defun vhdl-makefile-name ()
15639 "Return the Makefile name of the current project or the current compiler if
15640 no project is defined."
15641 (let ((project-alist (aget vhdl-project-alist vhdl-project))
15642 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
15643 (vhdl-replace-string
15644 (cons "\\(.*\\)\n\\(.*\\)"
15645 (or (nth 8 project-alist) (nth 8 compiler-alist)))
15646 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
15648 (defun vhdl-compile-directory ()
15649 "Return the directory where compilation/make should be run."
15650 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
15651 (compiler (aget vhdl-compiler-alist vhdl-compiler))
15652 (directory (vhdl-resolve-env-variable
15654 (vhdl-replace-string
15655 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
15656 (nth 6 compiler)))))
15657 (file-name-as-directory
15658 (if (file-name-absolute-p directory)
15660 (expand-file-name directory (vhdl-default-directory))))))
15662 (defun vhdl-uniquify (in-list)
15663 "Remove duplicate elements from IN-LIST."
15666 (add-to-list 'out-list (car in-list))
15667 (setq in-list (cdr in-list)))
15670 (defun vhdl-set-compiler (name)
15671 "Set current compiler to NAME."
15673 (list (let ((completion-ignore-case t))
15674 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
15675 (if (assoc name vhdl-compiler-alist)
15676 (progn (setq vhdl-compiler name)
15677 (message "Current compiler: \"%s\"" vhdl-compiler))
15678 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
15680 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15683 (defun vhdl-compile-init ()
15684 "Initialize for compilation."
15685 (when (or (null compilation-error-regexp-alist)
15686 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
15687 compilation-error-regexp-alist)))
15688 ;; `compilation-error-regexp-alist'
15689 (let ((commands-alist vhdl-compiler-alist)
15690 regexp-alist sublist)
15691 (while commands-alist
15692 (setq sublist (nth 11 (car commands-alist)))
15693 (unless (or (equal "" (car sublist))
15694 (assoc (car sublist) regexp-alist))
15695 (setq regexp-alist (cons (list (nth 0 sublist)
15696 (if (= 0 (nth 1 sublist))
15697 (if vhdl-xemacs 9 nil)
15699 (nth 2 sublist) (nth 3 sublist))
15701 (setq commands-alist (cdr commands-alist)))
15702 (setq compilation-error-regexp-alist
15703 (append compilation-error-regexp-alist (nreverse regexp-alist))))
15704 ;; `compilation-file-regexp-alist'
15705 (let ((commands-alist vhdl-compiler-alist)
15706 regexp-alist sublist)
15707 ;; matches vhdl-mode file name output
15708 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
15709 (while commands-alist
15710 (setq sublist (nth 12 (car commands-alist)))
15711 (unless (or (equal "" (car sublist))
15712 (assoc (car sublist) regexp-alist))
15713 (setq regexp-alist (cons sublist regexp-alist)))
15714 (setq commands-alist (cdr commands-alist)))
15715 (setq compilation-file-regexp-alist
15716 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
15718 (defvar vhdl-compile-file-name nil
15719 "Name of file to be compiled.")
15721 (defun vhdl-compile-print-file-name ()
15722 "Function called within `compile' to print out file name for compilers that
15723 do not print any file names."
15724 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
15726 (defun vhdl-get-compile-options (project compiler file-name
15727 &optional file-options-only)
15728 "Get compiler options. Returning nil means do not compile this file."
15729 (let* ((compiler-options (nth 1 compiler))
15730 (project-entry (aget (nth 4 project) vhdl-compiler))
15731 (project-options (nth 0 project-entry))
15732 (exception-list (and file-name (nth 2 project-entry)))
15733 (work-library (vhdl-work-library))
15734 (case-fold-search nil)
15736 (while (and exception-list
15737 (not (string-match (caar exception-list) file-name)))
15738 (setq exception-list (cdr exception-list)))
15739 (if (and exception-list (not (cdar exception-list)))
15741 (if (and file-options-only (not exception-list))
15743 (setq file-options (cdar exception-list))
15744 ;; insert library name in compiler-specific options
15745 (setq compiler-options
15746 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
15748 ;; insert compiler-specific options in project-specific options
15749 (when project-options
15750 (setq project-options
15751 (vhdl-replace-string
15752 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15753 (concat work-library "\n" compiler-options))))
15754 ;; insert project-specific options in file-specific options
15757 (vhdl-replace-string
15758 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
15759 (concat work-library "\n" compiler-options "\n"
15760 project-options))))
15762 (or file-options project-options compiler-options)))))
15764 (defun vhdl-get-make-options (project compiler)
15765 "Get make options."
15766 (let* ((compiler-options (nth 3 compiler))
15767 (project-entry (aget (nth 4 project) vhdl-compiler))
15768 (project-options (nth 1 project-entry))
15769 (makefile-name (vhdl-makefile-name)))
15770 ;; insert Makefile name in compiler-specific options
15771 (setq compiler-options
15772 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
15774 ;; insert compiler-specific options in project-specific options
15775 (when project-options
15776 (setq project-options
15777 (vhdl-replace-string
15778 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15779 (concat makefile-name "\n" compiler-options))))
15781 (or project-options compiler-options)))
15783 (defun vhdl-compile ()
15784 "Compile current buffer using the VHDL compiler specified in
15787 (vhdl-compile-init)
15788 (let* ((project (aget vhdl-project-alist vhdl-project))
15789 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
15790 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15791 (command (nth 0 compiler))
15792 (file-name (buffer-file-name))
15793 (options (vhdl-get-compile-options project compiler file-name))
15794 (default-directory (vhdl-compile-directory))
15795 compilation-process-setup-function)
15796 (unless (file-directory-p default-directory)
15797 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15798 ;; put file name into quotes if it contains spaces
15799 (when (string-match " " file-name)
15800 (setq file-name (concat "\"" file-name "\"")))
15801 ;; print out file name if compiler does not
15802 (setq vhdl-compile-file-name (buffer-file-name))
15803 (when (and (= 0 (nth 1 (nth 10 compiler)))
15804 (= 0 (nth 1 (nth 11 compiler))))
15805 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
15809 (compile (concat command " " options " " file-name)))
15810 (vhdl-warning "Your project settings tell me not to compile this file"))))
15812 (defun vhdl-make (&optional target)
15813 "Call make command for compilation of all updated source files (requires
15814 `Makefile'). Optional argument TARGET allows to compile the design
15815 specified by a target."
15817 (vhdl-compile-init)
15818 (let* ((project (aget vhdl-project-alist vhdl-project))
15819 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15820 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15821 (command (nth 2 compiler))
15822 (options (vhdl-get-make-options project compiler))
15823 (default-directory (vhdl-compile-directory)))
15824 (unless (file-directory-p default-directory)
15825 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15827 (compile (concat (if (equal command "") "make" command)
15828 " " options " " target))))
15830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15831 ;; Makefile generation
15833 (defun vhdl-generate-makefile ()
15834 "Generate `Makefile'."
15836 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15837 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15838 (command (nth 4 compiler)))
15839 ;; generate makefile
15841 (let ((default-directory (vhdl-compile-directory)))
15842 (compile (vhdl-replace-string
15843 (cons "\\(.*\\) \\(.*\\)" command)
15844 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
15845 (vhdl-generate-makefile-1))))
15847 (defun vhdl-get-packages (lib-alist work-library)
15848 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
15851 (when (equal (downcase (caar lib-alist)) (downcase work-library))
15852 (setq pack-list (cons (cdar lib-alist) pack-list)))
15853 (setq lib-alist (cdr lib-alist)))
15856 (defun vhdl-generate-makefile-1 ()
15857 "Generate Makefile for current project or directory."
15858 ;; scan hierarchy if required
15859 (if (vhdl-project-p)
15860 (unless (or (assoc vhdl-project vhdl-file-alist)
15861 (vhdl-load-cache vhdl-project))
15862 (vhdl-scan-project-contents vhdl-project))
15863 (let ((directory (abbreviate-file-name default-directory)))
15864 (unless (or (assoc directory vhdl-file-alist)
15865 (vhdl-load-cache directory))
15866 (vhdl-scan-directory-contents directory))))
15867 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
15868 (project (vhdl-project-p))
15869 (ent-alist (aget vhdl-entity-alist (or project directory) t))
15870 (conf-alist (aget vhdl-config-alist (or project directory) t))
15871 (pack-alist (aget vhdl-package-alist (or project directory) t))
15872 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
15873 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
15874 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
15875 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
15876 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
15877 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
15878 (adjust-case (nth 5 regexp-list))
15879 (work-library (downcase (vhdl-work-library)))
15880 (compile-directory (expand-file-name (vhdl-compile-directory)
15881 default-directory))
15882 (makefile-name (vhdl-makefile-name))
15883 rule-alist arch-alist inst-alist
15884 target-list depend-list unit-list prim-list second-list subcomp-list
15885 lib-alist lib-body-alist pack-list all-pack-list
15886 ent-key ent-file-name arch-key arch-file-name ent-arch-key
15887 conf-key conf-file-name pack-key pack-file-name
15888 ent-entry arch-entry conf-entry pack-entry inst-entry
15889 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
15890 tmp-key tmp-list rule)
15891 ;; check prerequisites
15892 (unless (file-exists-p compile-directory)
15893 (make-directory compile-directory t))
15894 (unless regexp-list
15895 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
15897 (message "Generating makefile \"%s\"..." makefile-name)
15898 ;; rules for all entities
15899 (setq tmp-list ent-alist)
15901 (setq ent-entry (car ent-alist)
15902 ent-key (nth 0 ent-entry))
15903 (when (nth 2 ent-entry)
15904 (setq ent-file-name (file-relative-name
15905 (nth 2 ent-entry) compile-directory)
15906 arch-alist (nth 4 ent-entry)
15907 lib-alist (nth 5 ent-entry)
15908 rule (aget rule-alist ent-file-name)
15909 target-list (nth 0 rule)
15910 depend-list (nth 1 rule)
15913 (setq tmp-key (vhdl-replace-string
15914 ent-regexp (funcall adjust-case ent-key)))
15915 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
15916 ;; rule target for this entity
15917 (setq target-list (cons ent-key target-list))
15918 ;; rule dependencies for all used packages
15919 (setq pack-list (vhdl-get-packages lib-alist work-library))
15920 (setq depend-list (append depend-list pack-list))
15921 (setq all-pack-list pack-list)
15923 (aput 'rule-alist ent-file-name (list target-list depend-list))
15924 ;; rules for all corresponding architectures
15926 (setq arch-entry (car arch-alist)
15927 arch-key (nth 0 arch-entry)
15928 ent-arch-key (concat ent-key "-" arch-key)
15929 arch-file-name (file-relative-name (nth 2 arch-entry)
15931 inst-alist (nth 4 arch-entry)
15932 lib-alist (nth 5 arch-entry)
15933 rule (aget rule-alist arch-file-name)
15934 target-list (nth 0 rule)
15935 depend-list (nth 1 rule))
15936 (setq tmp-key (vhdl-replace-string
15938 (funcall adjust-case (concat arch-key " " ent-key))))
15940 (cons (cons ent-arch-key tmp-key) unit-list))
15941 (setq second-list (cons ent-arch-key second-list))
15942 ;; rule target for this architecture
15943 (setq target-list (cons ent-arch-key target-list))
15944 ;; rule dependency for corresponding entity
15945 (setq depend-list (cons ent-key depend-list))
15946 ;; rule dependencies for contained component instantiations
15948 (setq inst-entry (car inst-alist))
15949 (when (or (null (nth 8 inst-entry))
15950 (equal (downcase (nth 8 inst-entry)) work-library))
15951 (setq inst-ent-key (or (nth 7 inst-entry)
15952 (nth 5 inst-entry)))
15953 (setq depend-list (cons inst-ent-key depend-list)
15954 subcomp-list (cons inst-ent-key subcomp-list)))
15955 (setq inst-alist (cdr inst-alist)))
15956 ;; rule dependencies for all used packages
15957 (setq pack-list (vhdl-get-packages lib-alist work-library))
15958 (setq depend-list (append depend-list pack-list))
15959 (setq all-pack-list (append all-pack-list pack-list))
15961 (aput 'rule-alist arch-file-name (list target-list depend-list))
15962 (setq arch-alist (cdr arch-alist)))
15963 (setq prim-list (cons (list ent-key second-list
15964 (append subcomp-list all-pack-list))
15966 (setq ent-alist (cdr ent-alist)))
15967 (setq ent-alist tmp-list)
15968 ;; rules for all configurations
15969 (setq tmp-list conf-alist)
15971 (setq conf-entry (car conf-alist)
15972 conf-key (nth 0 conf-entry)
15973 conf-file-name (file-relative-name
15974 (nth 2 conf-entry) compile-directory)
15975 ent-key (nth 4 conf-entry)
15976 arch-key (nth 5 conf-entry)
15977 inst-alist (nth 6 conf-entry)
15978 lib-alist (nth 7 conf-entry)
15979 rule (aget rule-alist conf-file-name)
15980 target-list (nth 0 rule)
15981 depend-list (nth 1 rule)
15982 subcomp-list (list ent-key))
15983 (setq tmp-key (vhdl-replace-string
15984 conf-regexp (funcall adjust-case conf-key)))
15985 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
15986 ;; rule target for this configuration
15987 (setq target-list (cons conf-key target-list))
15988 ;; rule dependency for corresponding entity and architecture
15990 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
15991 ;; rule dependencies for used packages
15992 (setq pack-list (vhdl-get-packages lib-alist work-library))
15993 (setq depend-list (append depend-list pack-list))
15994 ;; rule dependencies for contained component configurations
15996 (setq inst-entry (car inst-alist))
15997 (setq inst-ent-key (nth 2 inst-entry)
15998 ; comp-arch-key (nth 2 inst-entry))
15999 inst-conf-key (nth 4 inst-entry))
16000 (when (equal (downcase (nth 5 inst-entry)) work-library)
16002 (setq depend-list (cons inst-ent-key depend-list)
16003 subcomp-list (cons inst-ent-key subcomp-list)))
16004 ; (when comp-arch-key
16005 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16007 (when inst-conf-key
16008 (setq depend-list (cons inst-conf-key depend-list)
16009 subcomp-list (cons inst-conf-key subcomp-list))))
16010 (setq inst-alist (cdr inst-alist)))
16012 (aput 'rule-alist conf-file-name (list target-list depend-list))
16013 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16015 (setq conf-alist (cdr conf-alist)))
16016 (setq conf-alist tmp-list)
16017 ;; rules for all packages
16018 (setq tmp-list pack-alist)
16020 (setq pack-entry (car pack-alist)
16021 pack-key (nth 0 pack-entry)
16023 (when (nth 2 pack-entry)
16024 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16026 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16027 rule (aget rule-alist pack-file-name)
16028 target-list (nth 0 rule) depend-list (nth 1 rule))
16029 (setq tmp-key (vhdl-replace-string
16030 pack-regexp (funcall adjust-case pack-key)))
16031 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16032 ;; rule target for this package
16033 (setq target-list (cons pack-key target-list))
16034 ;; rule dependencies for all used packages
16035 (setq pack-list (vhdl-get-packages lib-alist work-library))
16036 (setq depend-list (append depend-list pack-list))
16037 (setq all-pack-list pack-list)
16039 (aput 'rule-alist pack-file-name (list target-list depend-list))
16040 ;; rules for this package's body
16041 (when (nth 7 pack-entry)
16042 (setq pack-body-key (concat pack-key "-body")
16043 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16045 rule (aget rule-alist pack-body-file-name)
16046 target-list (nth 0 rule)
16047 depend-list (nth 1 rule))
16048 (setq tmp-key (vhdl-replace-string
16049 pack-body-regexp (funcall adjust-case pack-key)))
16051 (cons (cons pack-body-key tmp-key) unit-list))
16052 ;; rule target for this package's body
16053 (setq target-list (cons pack-body-key target-list))
16054 ;; rule dependency for corresponding package declaration
16055 (setq depend-list (cons pack-key depend-list))
16056 ;; rule dependencies for all used packages
16057 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16058 (setq depend-list (append depend-list pack-list))
16059 (setq all-pack-list (append all-pack-list pack-list))
16061 (aput 'rule-alist pack-body-file-name
16062 (list target-list depend-list)))
16064 (cons (list pack-key (when pack-body-key (list pack-body-key))
16067 (setq pack-alist (cdr pack-alist)))
16068 (setq pack-alist tmp-list)
16069 ;; generate Makefile
16070 (let* ((project (aget vhdl-project-alist project))
16071 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16072 (compiler-id (nth 9 compiler))
16074 (vhdl-resolve-env-variable
16075 (vhdl-replace-string
16076 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16078 (makefile-path-name (expand-file-name
16079 makefile-name compile-directory))
16080 (orig-buffer (current-buffer))
16081 cell second-list subcomp-list options unit-key unit-name)
16083 (setq unit-list (vhdl-sort-alist unit-list))
16084 (setq prim-list (vhdl-sort-alist prim-list))
16085 (setq tmp-list rule-alist)
16086 (while tmp-list ; pre-sort rule targets
16087 (setq cell (cdar tmp-list))
16088 (setcar cell (sort (car cell) 'string<))
16089 (setq tmp-list (cdr tmp-list)))
16090 (setq rule-alist ; sort by first rule target
16092 (function (lambda (a b)
16093 (string< (car (cadr a)) (car (cadr b)))))))
16094 ;; open and clear Makefile
16095 (set-buffer (find-file-noselect makefile-path-name t t))
16097 (insert "# -*- Makefile -*-\n"
16098 "### " (file-name-nondirectory makefile-name)
16099 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16102 (insert "\n# Project : " (nth 0 project))
16103 (insert "\n# Directory : \"" directory "\""))
16104 (insert "\n# Platform : " vhdl-compiler
16105 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16106 (user-login-name) "\n")
16107 ;; insert compile and option variable settings
16108 (insert "\n\n# Define compilation command and options\n"
16109 "\nCOMPILE = " (nth 0 compiler)
16110 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16112 ;; insert library paths
16113 (setq library-directory
16114 (directory-file-name
16115 (if (file-name-absolute-p library-directory)
16117 (file-relative-name
16118 (expand-file-name library-directory directory)
16119 compile-directory))))
16120 (insert "\n\n# Define library paths\n"
16121 "\nLIBRARY-" work-library " = " library-directory "\n")
16122 ;; insert variable definitions for all library unit files
16123 (insert "\n\n# Define library unit files\n")
16124 (setq tmp-list unit-list)
16126 (insert "\nUNIT-" work-library "-" (caar unit-list)
16127 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16128 (setq unit-list (cdr unit-list)))
16129 ;; insert variable definition for list of all library unit files
16130 (insert "\n\n\n# Define list of all library unit files\n"
16132 (setq unit-list tmp-list)
16134 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16135 (setq unit-list (cdr unit-list)))
16137 (setq unit-list tmp-list)
16138 ;; insert `make all' rule
16139 (insert "\n\n\n# Rule for compiling entire design\n"
16142 " \\\n\t\t$(ALL_UNITS)\n")
16143 ;; insert `make clean' rule
16144 (insert "\n\n# Rule for cleaning entire design\n"
16146 "\n\t-rm -f $(ALL_UNITS)\n")
16147 ;; insert `make library' rule
16148 (insert "\n\n# Rule for creating library directory\n"
16150 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16151 "\n$(LIBRARY-" work-library ") :"
16153 (vhdl-replace-string
16154 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16155 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16157 ;; insert rule for each library unit
16158 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16160 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16162 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16163 (setq unit-key (caar prim-list)
16164 unit-name (or (nth 0 (aget ent-alist unit-key t))
16165 (nth 0 (aget conf-alist unit-key t))
16166 (nth 0 (aget pack-alist unit-key t))))
16167 (insert "\n" unit-key)
16168 (unless (equal unit-key unit-name)
16169 (insert " \\\n" unit-name))
16172 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16174 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16175 (setq second-list (cdr second-list)))
16176 (while subcomp-list
16177 (when (assoc (car subcomp-list) unit-list)
16178 (insert " \\\n\t\t" (car subcomp-list)))
16179 (setq subcomp-list (cdr subcomp-list)))
16181 (setq prim-list (cdr prim-list)))
16182 ;; insert rule for each library unit file
16183 (insert "\n\n# Rules for compiling single library unit files\n")
16185 (setq rule (car rule-alist))
16186 ;; get compiler options for this file
16188 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16189 ;; insert rule if file is supposed to be compiled
16190 (setq target-list (nth 1 rule)
16191 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16193 (setq tmp-list target-list)
16195 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16196 (if (cdr target-list) " \\" " :"))
16197 (setq target-list (cdr target-list)))
16198 (setq target-list tmp-list)
16199 ;; insert file name as first dependency
16200 (insert " \\\n\t\t" (nth 0 rule))
16201 ;; insert dependencies (except if also target or unit does not exist)
16203 (when (and (not (member (car depend-list) target-list))
16204 (assoc (car depend-list) unit-list))
16205 (insert " \\\n\t\t"
16206 "$(UNIT-" work-library "-" (car depend-list) ")"))
16207 (setq depend-list (cdr depend-list)))
16208 ;; insert compile command
16210 (insert "\n\t$(COMPILE) "
16211 (if (eq options 'default) "$(OPTIONS)" options) " "
16213 (setq tmp-list target-list)
16215 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16216 (if (cdr target-list) " \\" "\n"))
16217 (setq target-list (cdr target-list)))
16218 (setq target-list tmp-list))
16219 (setq rule-alist (cdr rule-alist)))
16220 (insert "\n\n### " makefile-name " ends here\n")
16221 ;; run Makefile generation hook
16222 (run-hooks 'vhdl-makefile-generation-hook)
16223 (message "Generating makefile \"%s\"...done" makefile-name)
16224 ;; save and close file
16225 (if (file-writable-p makefile-path-name)
16226 (progn (save-buffer)
16227 (kill-buffer (current-buffer))
16228 (set-buffer orig-buffer)
16229 (setq file-name-history
16230 (cons makefile-path-name file-name-history)))
16231 (vhdl-warning-when-idle
16232 (format "File not writable: \"%s\""
16233 (abbreviate-file-name makefile-path-name)))
16234 (switch-to-buffer (current-buffer))))))
16237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16240 ;; (using `reporter.el')
16242 (defconst vhdl-mode-help-address
16243 "Reto Zimmermann <reto@gnu.org>"
16244 "Address for VHDL Mode bug reports.")
16246 (defun vhdl-submit-bug-report ()
16247 "Submit via mail a bug report on VHDL Mode."
16249 ;; load in reporter
16251 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16252 (let ((reporter-prompt-for-summary-p t))
16253 (reporter-submit-bug-report
16254 vhdl-mode-help-address
16255 (concat "VHDL Mode " vhdl-version)
16257 ;; report all important user options
16258 'vhdl-offsets-alist
16259 'vhdl-comment-only-line-offset
16261 'vhdl-electric-mode
16263 'vhdl-indent-tabs-mode
16264 'vhdl-project-alist
16266 'vhdl-project-file-name
16267 'vhdl-project-auto-load
16269 'vhdl-compiler-alist
16271 'vhdl-compile-use-local-error-regexp
16272 'vhdl-makefile-generation-hook
16273 'vhdl-default-library
16276 'vhdl-upper-case-keywords
16277 'vhdl-upper-case-types
16278 'vhdl-upper-case-attributes
16279 'vhdl-upper-case-enum-values
16280 'vhdl-upper-case-constants
16281 'vhdl-use-direct-instantiation
16282 'vhdl-entity-file-name
16283 'vhdl-architecture-file-name
16284 'vhdl-package-file-name
16285 'vhdl-file-name-case
16286 'vhdl-electric-keywords
16287 'vhdl-optional-labels
16288 'vhdl-insert-empty-lines
16289 'vhdl-argument-list-indent
16290 'vhdl-association-list-with-formals
16291 'vhdl-conditions-in-parenthesis
16297 'vhdl-copyright-string
16298 'vhdl-platform-spec
16300 'vhdl-modify-date-prefix-string
16301 'vhdl-modify-date-on-saving
16303 'vhdl-reset-active-high
16304 'vhdl-clock-rising-edge
16305 'vhdl-clock-edge-condition
16309 'vhdl-include-port-comments
16310 'vhdl-include-direction-comments
16311 'vhdl-include-type-comments
16312 'vhdl-include-group-comments
16313 'vhdl-actual-port-name
16314 'vhdl-instance-name
16315 'vhdl-testbench-entity-name
16316 'vhdl-testbench-architecture-name
16317 'vhdl-testbench-configuration-name
16318 'vhdl-testbench-dut-name
16319 'vhdl-testbench-include-header
16320 'vhdl-testbench-declarations
16321 'vhdl-testbench-statements
16322 'vhdl-testbench-initialize-signals
16323 'vhdl-testbench-include-library
16324 'vhdl-testbench-include-configuration
16325 'vhdl-testbench-create-files
16326 'vhdl-compose-create-files
16327 'vhdl-compose-include-header
16328 'vhdl-compose-architecture-name
16329 'vhdl-components-package-name
16330 'vhdl-use-components-package
16331 'vhdl-self-insert-comments
16332 'vhdl-prompt-for-comments
16333 'vhdl-inline-comment-column
16334 'vhdl-end-comment-column
16337 'vhdl-align-group-separate
16338 'vhdl-align-same-indent
16339 'vhdl-highlight-keywords
16340 'vhdl-highlight-names
16341 'vhdl-highlight-special-words
16342 'vhdl-highlight-forbidden-words
16343 'vhdl-highlight-verilog-keywords
16344 'vhdl-highlight-translate-off
16345 'vhdl-highlight-case-sensitive
16346 'vhdl-special-syntax-alist
16347 'vhdl-forbidden-words
16348 'vhdl-forbidden-syntax
16349 'vhdl-directive-keywords
16350 'vhdl-speedbar-auto-open
16351 'vhdl-speedbar-display-mode
16352 'vhdl-speedbar-scan-limit
16353 'vhdl-speedbar-jump-to-unit
16354 'vhdl-speedbar-update-on-saving
16355 'vhdl-speedbar-save-cache
16356 'vhdl-speedbar-cache-file-name
16358 'vhdl-source-file-menu
16359 'vhdl-hideshow-menu
16360 'vhdl-hide-all-init
16361 'vhdl-print-two-column
16362 'vhdl-print-customize-faces
16363 'vhdl-intelligent-tab
16364 'vhdl-indent-syntax-based
16365 'vhdl-word-completion-case-sensitive
16366 'vhdl-word-completion-in-minibuffer
16367 'vhdl-underscore-is-part-of-word
16372 (if vhdl-special-indent-hook
16373 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16374 "vhdl-special-indent-hook is set to '"
16375 (format "%s" vhdl-special-indent-hook)
16376 ".\nPerhaps this is your problem?\n"
16377 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16385 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16387 (defconst vhdl-doc-release-notes nil
16389 Release Notes for VHDL Mode 3.32
16390 ================================
16393 - Enhanced Features
16401 STRUCTURAL COMPOSITION:
16402 - Enables simple structural composition similar to graphical editors.
16403 Simplifies the creation of higher design levels where subcomponents
16404 are simply sticked together:
16405 1. Create a skeleton for a new component
16406 2. Place subcomponents in it directly from the hierarchy browser
16407 3. Automatically connect all subcomponents and create the ports
16408 for the new component (based on names of actual ports)
16409 - Automatic generation of a components package (package containing
16410 component declarations for all entities).
16411 - Find more information in the online documentation (`C-c C-h').
16414 - Reverse direction of ports (useful for testbenches).
16416 SUBPROGRAM TRANSLATION:
16417 - Copy/paste of subprogram interfaces (similar to port translation).
16420 - Condense code using code-sensitive block filling.
16423 - Calculate number of code lines and statements in a buffer.
16429 TESTBENCH GENERATION:
16430 - Enhanced templates and user option default values.
16432 Emacs 21 compatibility/enhancements:
16433 - `lazy-lock-mode' is not used anymore (built-in `jit-lock-mode' is faster).
16435 And many other minor fixes and enhancements.
16441 `vhdl-project-file-name': (enhanced)
16442 Include user name in project setup file name.
16443 `vhdl-speedbar-cache-file-name': (enhanced, changed default)
16444 Include user name in cache file name.
16445 `vhdl-default-library': (new)
16446 Default working library if no project is active.
16447 `vhdl-architecture-file-name': (new)
16448 Specify how the architecture file name is obtained.
16449 `vhdl-package-file-name': (new)
16450 Specify how the package file name is obtained.
16451 `vhdl-file-name-case': (new)
16452 Allows to change case when deriving file names.
16453 `vhdl-compose-create-files': (new)
16454 Specify whether new files should be created for a new component.
16455 `vhdl-compose-include-header': (new)
16456 Specify whether a header is included in a new component's file.
16457 `vhdl-compose-architecture-name': (new)
16458 Specify how a new component's architecture name is obtained.
16459 `vhdl-components-package-name': (new)
16460 Specify how the name for the components package is obtained.
16461 `vhdl-use-components-package': (new)
16462 Specify whether component declarations go in a components package.
16463 `vhdl-use-direct-instantiation': (new)
16464 Specify whether to use VHDL'93 direct component instantiation.
16465 `vhdl-instance-name': (changed default)
16466 Allows insertion of a running number to generate unique instance names.
16467 `vhdl-testbench-entity-header', `vhdl-testbench-architecture-header':(obsolete)
16468 Headers are now automatically derived from the standard header.
16469 `vhdl-testbench-include-header': (new)
16470 Specify whether a header is included in testbench files.
16471 `vhdl-testbench-declaration', `vhdl-testbench-statements': (changed default)
16472 Non-empty default values for more complete testbench templates.
16478 - Changed key binding for `vhdl-comment-uncomment-region': `C-c c'
16479 (`C-c C-c ...' is now used for structural composition).
16481 - Automatic buffer highlighting (font-lock) is now controlled by option
16482 `global-font-lock-mode' in GNU Emacs (`font-lock-auto-fontify' in XEmacs).
16483 \(Important: You MUST customize this option in order to turn automatic
16484 buffer highlighting on.)
16488 (defconst vhdl-doc-keywords nil
16490 Reserved words in VHDL
16491 ----------------------
16493 VHDL'93 (IEEE Std 1076-1993):
16494 `vhdl-93-keywords' : keywords
16495 `vhdl-93-types' : standardized types
16496 `vhdl-93-attributes' : standardized attributes
16497 `vhdl-93-enum-values' : standardized enumeration values
16498 `vhdl-93-functions' : standardized functions
16499 `vhdl-93-packages' : standardized packages and libraries
16501 VHDL-AMS (IEEE Std 1076.1):
16502 `vhdl-ams-keywords' : keywords
16503 `vhdl-ams-types' : standardized types
16504 `vhdl-ams-attributes' : standardized attributes
16505 `vhdl-ams-enum-values' : standardized enumeration values
16506 `vhdl-ams-functions' : standardized functions
16508 Math Packages (IEEE Std 1076.2):
16509 `vhdl-math-types' : standardized types
16510 `vhdl-math-constants' : standardized constants
16511 `vhdl-math-functions' : standardized functions
16512 `vhdl-math-packages' : standardized packages
16515 `vhdl-verilog-keywords' : Verilog reserved words
16517 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16520 (defconst vhdl-doc-coding-style nil
16522 For VHDL coding style and naming convention guidelines, see the following
16526 \"VHDL Coding Styles and Methodologies\".
16527 Kluwer Academic Publishers, 1999.
16528 http://members.aol.com/vhdlcohen/vhdl/
16530 \[2] Michael Keating and Pierre Bricaud.
16531 \"Reuse Methodology Manual, Second Edition\".
16532 Kluwer Academic Publishers, 1999.
16533 http://www.openmore.com/openmore/rmm2.html
16535 \[3] European Space Agency.
16536 \"VHDL Modelling Guidelines\".
16537 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16539 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16540 to visually support naming conventions.")
16543 (defun vhdl-version ()
16544 "Echo the current version of VHDL Mode in the minibuffer."
16546 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16547 (vhdl-keep-region-active))
16549 (defun vhdl-doc-variable (variable)
16550 "Display VARIABLE's documentation in *Help* buffer."
16552 (with-output-to-temp-buffer "*Help*"
16553 (princ (documentation-property variable 'variable-documentation))
16554 (unless vhdl-xemacs
16555 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16557 (set-buffer standard-output)
16559 (print-help-return-message)))
16561 (defun vhdl-doc-mode ()
16562 "Display VHDL Mode documentation in *Help* buffer."
16564 (with-output-to-temp-buffer "*Help*"
16567 (princ (documentation 'vhdl-mode))
16568 (unless vhdl-xemacs
16569 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16571 (set-buffer standard-output)
16573 (print-help-return-message)))
16576 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16578 (provide 'vhdl-mode)
16580 ;;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
16581 ;;; vhdl-mode.el ends here