1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2003, 2004, 2005 Free Software Foundation, Inc.
5 ;; Authors: Reto Zimmermann <reto@gnu.org>
6 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
7 ;; Maintainer: FSF (Because Reto Zimmermann seems to have disappeared)
8 ;; Keywords: languages vhdl
10 (defconst vhdl-version "3.32.12"
11 "VHDL Mode version number.")
13 (defconst vhdl-time-stamp "2003-02-28"
14 "VHDL Mode time stamp for last update.")
16 ;; This file is part of GNU Emacs.
18 ;; GNU Emacs is free software; you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation; either version 2, or (at your option)
23 ;; GNU Emacs is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs; see the file COPYING. If not, write to the
30 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
31 ;; Boston, MA 02110-1301, USA.
33 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;; This package provides an Emacs major mode for editing VHDL code.
38 ;; It includes the following features:
40 ;; - Syntax highlighting
42 ;; - Template insertion (electrification)
43 ;; - Insertion of file headers
44 ;; - Insertion of user-specified models
45 ;; - Port translation / testbench generation
46 ;; - Sensitivity list updating
48 ;; - Design hierarchy browser
49 ;; - Source file compilation (syntax analysis)
50 ;; - Makefile generation
52 ;; - Word/keyword completion
54 ;; - Code fixing/alignment/beautification
55 ;; - Postscript printing
56 ;; - VHDL'87/'93 and VHDL-AMS supported
57 ;; - Comprehensive menu
58 ;; - Fully customizable
59 ;; - Works under GNU Emacs (recommended) and XEmacs
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
66 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
69 ;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
70 ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
77 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
78 ;; or into an arbitrary directory that is added to the load path by the
79 ;; following line in your Emacs start-up file `.emacs':
81 ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
83 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
84 ;; directory. Otherwise, byte-compile the source file:
85 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
86 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
88 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
89 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
90 ;; (not required in Emacs 20.X):
92 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
93 ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
95 ;; More detailed installation instructions are included in the official
96 ;; VHDL Mode distribution.
98 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
101 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
104 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
105 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
107 ;; Many thanks to all the users who sent me bug reports and enhancement
109 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
110 ;; enhancement suggestions and the fruitful discussions.
111 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
112 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
114 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
115 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
116 ;; giving me the opportunity to develop this code.
117 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
118 ;; of the Swiss Government.
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
125 (defconst vhdl-xemacs (string-match "XEmacs" emacs-version)
126 "Non-nil if XEmacs is used.")
127 ;; Emacs 21+ handling
128 (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not vhdl-xemacs))
129 "Non-nil if Emacs 21, 22, ... is used.")
132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 ;; help function for user options
137 (defun vhdl-custom-set (variable value &rest functions)
138 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
139 (if (fboundp 'custom-set-default)
140 (custom-set-default variable value)
141 (set-default variable value))
143 (when (fboundp (car functions)) (funcall (car functions)))
144 (setq functions (cdr functions))))
146 (defun vhdl-widget-directory-validate (widget)
147 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
149 (let ((val (widget-value widget)))
150 (unless (string-match "^\\(\\|.*/\\)$" val)
151 (widget-put widget :error "Invalid directory entry: must end with '/'")
154 ;; help string for user options
155 (defconst vhdl-name-doc-string "
157 FROM REGEXP is a regular expression matching the original name:
158 \".*\" matches the entire string
159 \"\\(...\\)\" matches a substring
160 TO STRING specifies the string to be inserted as new name:
161 \"\\&\" means substitute entire matched text
162 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
164 \".*\" \"\\&\" inserts original string
165 \".*\" \"\\&_i\" attaches \"_i\" to original string
166 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
167 \".*\" \"foo\" inserts constant string \"foo\"
168 \".*\" \"\" inserts empty string")
170 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
174 "Customizations for VHDL Mode."
177 ; :version "20.4" ; comment out for XEmacs
180 (defgroup vhdl-mode nil
181 "Customizations for modes."
184 (defcustom vhdl-electric-mode t
185 "*Non-nil enables electrification (automatic template generation).
186 If nil, template generators can still be invoked through key bindings and
187 menu. Is indicated in the modeline by \"/e\" after the mode name and can be
188 toggled by `\\[vhdl-electric-mode]'."
192 (defcustom vhdl-stutter-mode t
193 "*Non-nil enables stuttering.
194 Is indicated in the modeline by \"/s\" after the mode name and can be toggled
195 by `\\[vhdl-stutter-mode]'."
199 (defcustom vhdl-indent-tabs-mode nil
200 "*Non-nil means indentation can insert tabs.
201 Overrides local variable `indent-tabs-mode'."
206 (defgroup vhdl-compile nil
207 "Customizations for compilation."
210 (defcustom vhdl-compiler-alist
212 ;; Cadence Leapfrog: cv -file test.vhd
213 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
214 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
215 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
216 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
217 ("\\1/entity" "\\2/\\1" "\\1/configuration"
218 "\\1/package" "\\1/body" downcase))
219 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
220 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
221 ;; (PLL_400X_TOP) is not declared [10.3].
222 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
223 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
224 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
226 ;; Ikos Voyager: analyze test.vhd
228 ;; E L4/C5: this library unit is inaccessible
229 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
230 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
231 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
232 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
234 ;; ModelSim, Model Technology: vcom test.vhd
235 ;; ERROR: test.vhd(14): Unknown identifier: positiv
236 ;; WARNING[2]: test.vhd(85): Possible infinite loop
237 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
238 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
239 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
240 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
241 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
242 "\\1/_primary.dat" "\\1/body.dat" downcase))
243 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
244 ;; test.vhd:34: error message
245 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
246 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
247 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
248 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
249 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
250 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
251 ;; ERROR: test.vhd(24): near "dnd": expecting: END
252 ;; WARNING[4]: test.vhd(30): A space is required between ...
253 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
254 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
255 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
256 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
257 "\\1/_primary.dat" "\\1/body.dat" downcase))
258 ;; Savant: scram -publish-cc test.vhd
259 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
260 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
261 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
262 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
263 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
264 "\\1_config.vhdl" "\\1_package.vhdl"
265 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
266 ;; Simili: vhdlp -work test.vhd
267 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
268 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
269 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
270 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
271 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
272 "\\1/prim.var" "\\1/_body.var" downcase))
273 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
274 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
275 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
276 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
277 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
279 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
280 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
281 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
282 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
283 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
284 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
285 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
286 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
287 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
288 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
289 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
290 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
292 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
293 ("Synplify" "n/a" "n/a" "make" "-f \\1"
294 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
295 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
297 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
298 ;; Compiling "test.vhd" line 1...
299 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
300 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
301 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
302 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
303 ("^ *Compiling \"\\(.+\\)\" " 1)
305 ;; VeriBest: vc vhdl test.vhd
306 ;; (no file name printed out!)
307 ;; 32: Z <= A and BitA ;
309 ;; [Error] Name BITA is unknown
310 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
311 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
312 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
314 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
315 ;; Compiling "test.vhd" line 1...
316 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
317 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
318 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
319 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
320 ("^ *Compiling \"\\(.+\\)\" " 1)
323 "*List of available VHDL compilers and their properties.
324 Each list entry specifies the following items for a compiler:
326 Compiler name : name used in option `vhdl-compiler' to choose compiler
327 Compile command : command used for source file compilation
328 Compile options : compile options (\"\\1\" inserts library name)
329 Make command : command used for compilation using a Makefile
330 Make options : make options (\"\\1\" inserts Makefile name)
331 Generate Makefile: use built-in function or command to generate a Makefile
332 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
333 Library command : command to create library directory \(\"\\1\" inserts
334 library directory, \"\\2\" inserts library name)
335 Compile directory: where compilation is run and the Makefile is placed
336 Library directory: directory of default library
337 Makefile name : name of Makefile (default is \"Makefile\")
338 ID string : compiler identification string (see `vhdl-project-alist')
340 Regexp : regular expression to match error messages
341 File subexp index: index of subexpression that matches the file name
342 Line subexp index: index of subexpression that matches the line number
343 Column subexp idx: index of subexpression that matches the column number
345 Regexp : regular expression to match a file name message
346 File subexp index: index of subexpression that matches the file name
347 Unit-to-file name mapping: mapping of library unit names to names of files
348 generated by the compiler (used for Makefile generation)
349 To string : string a name is mapped to (\"\\1\" inserts the unit name,
350 \"\\2\" inserts the entity name for architectures)
351 Case adjustment : adjust case of inserted unit names
353 Compile options allows insertion of the library name (see `vhdl-project-alist')
354 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
356 For Makefile generation, the built-in function can be used (requires
357 specification of the unit-to-file name mapping). Alternatively, an
358 external command can be specified. Work directory allows specification of
359 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
360 used for Makefile generation). To use another library name than \"work\",
361 customize `vhdl-project-alist'. The library command is inserted in Makefiles
362 to automatically create the library directory if not existent.
364 Compile options, compile directory, library directory, and Makefile name are
365 overwritten by the project settings if a project is defined (see
366 `vhdl-project-alist'). Directory paths are relative to the source file
369 Some compilers do not include the file name in the error message, but print
370 out a file name message in advance. In this case, set \"File Subexp Index\"
371 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
372 If no file name at all is printed out, set both \"File Message\" entries to 0
373 \(a default file name message will be printed out instead, does not work in
376 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
377 assigning its name to option `vhdl-compiler'.
379 Please send any missing or erroneous compiler properties to the maintainer for
382 NOTE: Reflect the new setting in the choice list of option `vhdl-compiler'
383 by restarting Emacs."
385 (list :tag "Compiler" :indent 2
386 (string :tag "Compiler name ")
387 (string :tag "Compile command ")
388 (string :tag "Compile options " "-work \\1")
389 (string :tag "Make command " "make")
390 (string :tag "Make options " "-f \\1")
391 (choice :tag "Generate Makefile "
392 (const :tag "Built-in function" nil)
393 (string :tag "Command" "vmake \\2 > \\1"))
394 (string :tag "Library command " "mkdir \\1")
395 (directory :tag "Compile directory "
396 :validate vhdl-widget-directory-validate "./")
397 (directory :tag "Library directory "
398 :validate vhdl-widget-directory-validate "work/")
399 (file :tag "Makefile name " "Makefile")
400 (string :tag "ID string ")
401 (list :tag "Error message" :indent 4
402 (regexp :tag "Regexp ")
403 (integer :tag "File subexp index")
404 (integer :tag "Line subexp index")
405 (integer :tag "Column subexp idx"))
406 (list :tag "File message" :indent 4
407 (regexp :tag "Regexp ")
408 (integer :tag "File subexp index"))
409 (choice :tag "Unit-to-file name mapping"
410 :format "%t: %[Value Menu%] %v\n"
411 (const :tag "Not defined" nil)
412 (list :tag "To string" :indent 4
413 (string :tag "Entity " "\\1.vhd")
414 (string :tag "Architecture " "\\2_\\1.vhd")
415 (string :tag "Configuration " "\\1.vhd")
416 (string :tag "Package " "\\1.vhd")
417 (string :tag "Package Body " "\\1_body.vhd")
418 (choice :tag "Case adjustment "
419 (const :tag "None" identity)
420 (const :tag "Upcase" upcase)
421 (const :tag "Downcase" downcase))))))
422 :set (lambda (variable value)
423 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
424 :group 'vhdl-compile)
426 (defcustom vhdl-compiler "ModelSim"
427 "*Specifies the VHDL compiler to be used for syntax analysis.
428 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
429 :type (let ((alist vhdl-compiler-alist) list)
431 (setq list (cons (list 'const (caar alist)) list))
432 (setq alist (cdr alist)))
433 (append '(choice) (nreverse list)))
434 :group 'vhdl-compile)
436 (defcustom vhdl-compile-use-local-error-regexp t
437 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
438 In this case, only error message regexps for VHDL compilers are active if
439 compilation is started from a VHDL buffer. Otherwise, the error message
440 regexps are appended to the predefined global regexps, and all regexps are
441 active all the time. Note that by doing that, the predefined global regexps
442 might result in erroneous parsing of error messages for some VHDL compilers.
444 NOTE: Activate the new setting by restarting Emacs."
446 :group 'vhdl-compile)
448 (defcustom vhdl-makefile-generation-hook nil
449 "*Functions to run at the end of Makefile generation.
450 Allows to insert user specific parts into a Makefile.
454 \(re-search-backward \"^# Rule for compiling entire design\")
455 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
457 :group 'vhdl-compile)
459 (defcustom vhdl-default-library "work"
460 "*Name of default library.
461 Is overwritten by project settings if a project is active."
463 :group 'vhdl-compile)
466 (defgroup vhdl-project nil
467 "Customizations for projects."
470 (defcustom vhdl-project-alist
471 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
472 "~/example1/" ("src/system/" "src/components/") ""
473 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
474 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
475 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
476 ("Example 2" "Individual source files, multiple compilers in different directories"
477 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
478 nil "\\1/" "work" "\\1/work/" "Makefile" "")
479 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
480 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
481 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
482 -------------------------------------------------------------------------------
483 -- This is a multi-line project description
484 -- that can be used as a project dependent part of the file header.
486 "*List of projects and their properties.
487 Name : name used in option `vhdl-project' to choose project
488 Title : title of project (single-line string)
489 Default directory: default project directory (absolute path)
490 Sources : a) source files : path + \"/\" + file name
491 b) directory : path + \"/\"
492 c) directory tree: \"-r \" + path + \"/\"
493 Exclude regexp : matches file/directory names to be excluded as sources
494 Compile options : project-specific options for each compiler
495 Compiler name : name of compiler for which these options are valid
496 Compile options: project-specific compiler options
497 (\"\\1\" inserts library name, \"\\2\" default options)
498 Make options: project-specific make options
499 (\"\\1\" inserts Makefile name, \"\\2\" default options)
500 Exceptions : file-specific exceptions
501 File name regexp: matches file names for which exceptions are valid
502 - Options : file-specific compiler options string
503 (\"\\1\" inserts library name, \"\\2\" default options,
504 \"\\3\" project-specific options)
505 - Do not compile: do not compile this file (in Makefile)
506 Compile directory: where compilation is run and the Makefile is placed
507 \(\"\\1\" inserts compiler ID string)
508 Library name : name of library (default is \"work\")
509 Library directory: path to library (\"\\1\" inserts compiler ID string)
510 Makefile name : name of Makefile
511 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
512 Description : description of project (multi-line string)
514 Project title and description are used to insert into the file header (see
515 option `vhdl-file-header').
517 The default directory must have an absolute path (use `M-TAB' for completion).
518 All other paths can be absolute or relative to the default directory. All
519 paths must end with '/'.
521 The design units found in the sources (files and directories) are shown in the
522 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
523 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
524 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
525 specified, the default directory is taken as source directory. Otherwise,
526 the default directory is only taken as source directory if there is a sources
527 entry with the empty string or \"./\". Exclude regexp allows to filter out
528 specific file and directory names from the list of sources (e.g. CVS
531 Files are compiled in the compile directory. Makefiles are also placed into
532 the compile directory. Library directory specifies which directory the
533 compiler compiles into (used to generate the Makefile).
535 Since different compile/library directories and Makefiles may exist for
536 different compilers within one project, these paths and names allow the
537 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
538 Compile options, compile directory, library directory, and Makefile name
539 overwrite the settings of the current compiler.
541 File-specific compiler options (highest priority) overwrite project-specific
542 options which overwrite default options (lowest priority). Lower priority
543 options can be inserted in higher priority options. This allows to reuse
544 default options (e.g. \"-file\") in project- or file-specific options (e.g.
547 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
548 by restarting Emacs."
550 (list :tag "Project" :indent 2
551 (string :tag "Name ")
552 (string :tag "Title ")
553 (directory :tag "Default directory"
554 :validate vhdl-widget-directory-validate
555 ,(abbreviate-file-name default-directory))
556 (repeat :tag "Sources " :indent 4
557 (directory :format " %v" "./"))
558 (regexp :tag "Exclude regexp ")
560 :tag "Compile options " :indent 4
561 (list :tag "Compiler" :indent 6
562 ,(let ((alist vhdl-compiler-alist) list)
564 (setq list (cons (list 'const (caar alist)) list))
565 (setq alist (cdr alist)))
566 (append '(choice :tag "Compiler name")
568 (string :tag "Compile options" "\\2")
569 (string :tag "Make options " "\\2")
571 :tag "Exceptions " :indent 8
573 (regexp :tag "File name regexp ")
574 (choice :format "%[Value Menu%] %v"
575 (string :tag "Options" "\\3")
576 (const :tag "Do not compile" nil))))))
577 (directory :tag "Compile directory"
578 :validate vhdl-widget-directory-validate "./")
579 (string :tag "Library name " "work")
580 (directory :tag "Library directory"
581 :validate vhdl-widget-directory-validate "work/")
582 (file :tag "Makefile name " "Makefile")
583 (string :tag "Description: (type `C-j' for newline)"
584 :format "%t\n%v\n")))
585 :set (lambda (variable value)
586 (vhdl-custom-set variable value
587 'vhdl-update-mode-menu
588 'vhdl-speedbar-refresh))
589 :group 'vhdl-project)
591 (defcustom vhdl-project nil
592 "*Specifies the default for the current project.
593 Select a project name from the ones defined in option `vhdl-project-alist'.
594 Is used to determine the project title and description to be inserted in file
595 headers and the source files/directories to be scanned in the hierarchy
596 browser. The current project can also be changed temporarily in the menu."
597 :type (let ((alist vhdl-project-alist) list)
599 (setq list (cons (list 'const (caar alist)) list))
600 (setq alist (cdr alist)))
601 (append '(choice (const :tag "None" nil) (const :tag "--"))
603 :group 'vhdl-project)
605 (defcustom vhdl-project-file-name '("\\1.prj")
606 "*List of file names/paths for importing/exporting project setups.
607 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
608 replaced by the user name (allows to have user-specific project setups).
609 The first entry is used as file name to import/export individual project
610 setups. All entries are used to automatically import project setups at
611 startup (see option `vhdl-project-auto-load'). Projects loaded from the
612 first entry are automatically made current. Hint: specify local project
613 setups in first entry, global setups in following entries; loading a local
614 project setup will make it current, while loading the global setups
615 is done without changing the current project.
616 Names can also have an absolute path (i.e. project setups can be stored
617 in global directories)."
618 :type '(repeat (string :tag "File name" "\\1.prj"))
619 :group 'vhdl-project)
621 (defcustom vhdl-project-auto-load '(startup)
622 "*Automatically load project setups from files.
623 All project setup files that match the file names specified in option
624 `vhdl-project-file-name' are automatically loaded. The project of the
625 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
627 A project setup file can be obtained by exporting a project (see menu).
628 At startup: project setup file is loaded at Emacs startup"
629 :type '(set (const :tag "At startup" startup))
630 :group 'vhdl-project)
632 (defcustom vhdl-project-sort t
633 "*Non-nil means projects are displayed in alphabetical order."
635 :group 'vhdl-project)
638 (defgroup vhdl-style nil
639 "Customizations for coding styles."
641 :group 'vhdl-template
643 :group 'vhdl-compose)
645 (defcustom vhdl-standard '(87 nil)
646 "*VHDL standards used.
648 VHDL'87 : IEEE Std 1076-1987
649 VHDL'93 : IEEE Std 1076-1993
650 Additional standards:
651 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
652 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
654 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
655 \"Activate Options\"."
656 :type '(list (choice :tag "Basic standard"
657 (const :tag "VHDL'87" 87)
658 (const :tag "VHDL'93" 93))
659 (set :tag "Additional standards" :indent 2
660 (const :tag "VHDL-AMS" ams)
661 (const :tag "Math packages" math)))
662 :set (lambda (variable value)
663 (vhdl-custom-set variable value
664 'vhdl-template-map-init
665 'vhdl-mode-abbrev-table-init
666 'vhdl-template-construct-alist-init
667 'vhdl-template-package-alist-init
668 'vhdl-update-mode-menu
669 'vhdl-words-init 'vhdl-font-lock-init))
672 (defcustom vhdl-basic-offset 2
673 "*Amount of basic offset used for indentation.
674 This value is used by + and - symbols in `vhdl-offsets-alist'."
678 (defcustom vhdl-upper-case-keywords nil
679 "*Non-nil means convert keywords to upper case.
680 This is done when typed or expanded or by the fix case functions."
682 :set (lambda (variable value)
683 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
686 (defcustom vhdl-upper-case-types nil
687 "*Non-nil means convert standardized types to upper case.
688 This is done when expanded or by the fix case functions."
690 :set (lambda (variable value)
691 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
694 (defcustom vhdl-upper-case-attributes nil
695 "*Non-nil means convert standardized attributes to upper case.
696 This is done when expanded or by the fix case functions."
698 :set (lambda (variable value)
699 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
702 (defcustom vhdl-upper-case-enum-values nil
703 "*Non-nil means convert standardized enumeration values to upper case.
704 This is done when expanded or by the fix case functions."
706 :set (lambda (variable value)
707 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
710 (defcustom vhdl-upper-case-constants t
711 "*Non-nil means convert standardized constants to upper case.
712 This is done when expanded."
714 :set (lambda (variable value)
715 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
718 (defcustom vhdl-use-direct-instantiation 'standard
719 "*Non-nil means use VHDL'93 direct component instantiation.
721 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
723 :type '(choice (const :tag "Never" never)
724 (const :tag "Standard" standard)
725 (const :tag "Always" always))
729 (defgroup vhdl-naming nil
730 "Customizations for naming conventions."
733 (defcustom vhdl-entity-file-name '(".*" . "\\&")
735 "*Specifies how the entity file name is obtained.
736 The entity file name can be obtained by modifying the entity name (e.g.
737 attaching or stripping off a substring). The file extension is automatically
738 taken from the file name of the current buffer."
739 vhdl-name-doc-string)
740 :type '(cons (regexp :tag "From regexp")
741 (string :tag "To string "))
743 :group 'vhdl-compose)
745 (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
747 "*Specifies how the architecture file name is obtained.
748 The architecture file name can be obtained by modifying the entity
749 and/or architecture name (e.g. attaching or stripping off a substring). The
750 string that is matched against the regexp is the concatenation of the entity
751 and the architecture name separated by a space. This gives access to both
752 names (see default setting as example)."
753 vhdl-name-doc-string)
754 :type '(cons (regexp :tag "From regexp")
755 (string :tag "To string "))
757 :group 'vhdl-compose)
759 (defcustom vhdl-package-file-name '(".*" . "\\&")
761 "*Specifies how the package file name is obtained.
762 The package file name can be obtained by modifying the package name (e.g.
763 attaching or stripping off a substring). The file extension is automatically
764 taken from the file name of the current buffer."
765 vhdl-name-doc-string)
766 :type '(cons (regexp :tag "From regexp")
767 (string :tag "To string "))
769 :group 'vhdl-compose)
771 (defcustom vhdl-file-name-case 'identity
772 "*Specifies how to change case for obtaining file names.
773 When deriving a file name from a VHDL unit name, case can be changed as
775 As Is: case is not changed (taken as is)
776 Lower Case: whole name is changed to lower case
777 Upper Case: whole name is changed to upper case
778 Capitalize: first letter of each word in name is capitalized"
779 :type '(choice (const :tag "As Is" identity)
780 (const :tag "Lower Case" downcase)
781 (const :tag "Upper Case" upcase)
782 (const :tag "Capitalize" capitalize))
784 :group 'vhdl-compose)
787 (defgroup vhdl-template nil
788 "Customizations for electrification."
791 (defcustom vhdl-electric-keywords '(vhdl user)
792 "*Type of keywords for which electrification is enabled.
793 VHDL keywords: invoke built-in templates
794 User keywords: invoke user models (see option `vhdl-model-alist')"
795 :type '(set (const :tag "VHDL keywords" vhdl)
796 (const :tag "User model keywords" user))
797 :set (lambda (variable value)
798 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
799 :group 'vhdl-template)
801 (defcustom vhdl-optional-labels 'process
802 "*Constructs for which labels are to be queried.
803 Template generators prompt for optional labels for:
805 Processes only: processes only (also procedurals in VHDL-AMS)
806 All constructs: all constructs with optional labels and keyword END"
807 :type '(choice (const :tag "None" none)
808 (const :tag "Processes only" process)
809 (const :tag "All constructs" all))
810 :group 'vhdl-template)
812 (defcustom vhdl-insert-empty-lines 'unit
813 "*Specifies whether to insert empty lines in some templates.
814 This improves readability of code. Empty lines are inserted in:
816 Design units only: entities, architectures, configurations, packages only
817 All constructs : also all constructs with BEGIN...END parts
819 Replaces option `vhdl-additional-empty-lines'."
820 :type '(choice (const :tag "None" none)
821 (const :tag "Design units only" unit)
822 (const :tag "All constructs" all))
823 :group 'vhdl-template
825 :group 'vhdl-compose)
827 (defcustom vhdl-argument-list-indent nil
828 "*Non-nil means indent argument lists relative to opening parenthesis.
829 That is, argument, association, and port lists start on the same line as the
830 opening parenthesis and subsequent lines are indented accordingly.
831 Otherwise, lists start on a new line and are indented as normal code."
833 :group 'vhdl-template
835 :group 'vhdl-compose)
837 (defcustom vhdl-association-list-with-formals t
838 "*Non-nil means write association lists with formal parameters.
839 Templates prompt for formal and actual parameters (ports/generics).
840 When pasting component instantiations, formals are included.
841 If nil, only a list of actual parameters is entered."
843 :group 'vhdl-template
845 :group 'vhdl-compose)
847 (defcustom vhdl-conditions-in-parenthesis nil
848 "*Non-nil means place parenthesis around condition expressions."
850 :group 'vhdl-template)
852 (defcustom vhdl-zero-string "'0'"
853 "*String to use for a logic zero."
855 :group 'vhdl-template)
857 (defcustom vhdl-one-string "'1'"
858 "*String to use for a logic one."
860 :group 'vhdl-template)
863 (defgroup vhdl-header nil
864 "Customizations for file header."
865 :group 'vhdl-template
866 :group 'vhdl-compose)
868 (defcustom vhdl-file-header "\
869 -------------------------------------------------------------------------------
870 -- Title : <title string>
871 -- Project : <project>
872 -------------------------------------------------------------------------------
875 -- Company : <company>
877 -- Last update: <date>
878 -- Platform : <platform>
879 -- Standard : <standard>
880 <projectdesc>-------------------------------------------------------------------------------
881 -- Description: <cursor>
882 <copyright>-------------------------------------------------------------------------------
884 -- Date Version Author Description
885 -- <date> 1.0 <login>\tCreated
886 -------------------------------------------------------------------------------
889 "*String or file to insert as file header.
890 If the string specifies an existing file name, the contents of the file is
891 inserted, otherwise the string itself is inserted as file header.
892 Type `C-j' for newlines.
893 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
894 if the header needs to be version controlled.
896 The following keywords for template generation are supported:
897 <filename> : replaced by the name of the buffer
898 <author> : replaced by the user name and email address
899 \(`user-full-name',`mail-host-address', `user-mail-address')
900 <login> : replaced by user login name (`user-login-name')
901 <company> : replaced by contents of option `vhdl-company-name'
902 <date> : replaced by the current date
903 <year> : replaced by the current year
904 <project> : replaced by title of current project (`vhdl-project')
905 <projectdesc> : replaced by description of current project (`vhdl-project')
906 <copyright> : replaced by copyright string (`vhdl-copyright-string')
907 <platform> : replaced by contents of option `vhdl-platform-spec'
908 <standard> : replaced by the VHDL language standard(s) used
909 <... string> : replaced by a queried string (\"...\" is the prompt word)
910 <title string>: replaced by file title in automatically generated files
911 <cursor> : final cursor position
913 The (multi-line) project description <projectdesc> can be used as a project
914 dependent part of the file header and can also contain the above keywords."
918 (defcustom vhdl-file-footer ""
919 "*String or file to insert as file footer.
920 If the string specifies an existing file name, the contents of the file is
921 inserted, otherwise the string itself is inserted as file footer (i.e. at
922 the end of the file).
923 Type `C-j' for newlines.
924 The same keywords as in option `vhdl-file-header' can be used."
928 (defcustom vhdl-company-name ""
929 "*Name of company to insert in file header.
930 See option `vhdl-file-header'."
934 (defcustom vhdl-copyright-string "\
935 -------------------------------------------------------------------------------
936 -- Copyright (c) <year> <company>
938 "*Copyright string to insert in file header.
939 Can be multi-line string (type `C-j' for newline) and contain other file
940 header keywords (see option `vhdl-file-header')."
944 (defcustom vhdl-platform-spec ""
945 "*Specification of VHDL platform to insert in file header.
946 The platform specification should contain names and versions of the
947 simulation and synthesis tools used.
948 See option `vhdl-file-header'."
952 (defcustom vhdl-date-format "%Y-%m-%d"
953 "*Specifies the date format to use in the header.
954 This string is passed as argument to the command `format-time-string'.
955 For more information on format strings, see the documentation for the
956 `format-time-string' command (C-h f `format-time-string')."
960 (defcustom vhdl-modify-date-prefix-string "-- Last update: "
961 "*Prefix string of modification date in VHDL file header.
962 If actualization of the modification date is called (menu,
963 `\\[vhdl-template-modify]'), this string is searched and the rest
964 of the line replaced by the current date."
968 (defcustom vhdl-modify-date-on-saving t
969 "*Non-nil means update the modification date when the buffer is saved.
970 Calls function `\\[vhdl-template-modify]').
972 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
973 \"Activate Options\"."
978 (defgroup vhdl-sequential-process nil
979 "Customizations for sequential processes."
980 :group 'vhdl-template)
982 (defcustom vhdl-reset-kind 'async
983 "*Specifies which kind of reset to use in sequential processes."
984 :type '(choice (const :tag "None" none)
985 (const :tag "Synchronous" sync)
986 (const :tag "Asynchronous" async))
987 :group 'vhdl-sequential-process)
989 (defcustom vhdl-reset-active-high nil
990 "*Non-nil means reset in sequential processes is active high.
991 Nil means active low."
993 :group 'vhdl-sequential-process)
995 (defcustom vhdl-clock-rising-edge t
996 "*Non-nil means rising edge of clock triggers sequential processes.
997 Nil means falling edge."
999 :group 'vhdl-sequential-process)
1001 (defcustom vhdl-clock-edge-condition 'standard
1002 "*Syntax of the clock edge condition.
1003 Standard: \"clk'event and clk = '1'\"
1004 Function: \"rising_edge(clk)\""
1005 :type '(choice (const :tag "Standard" standard)
1006 (const :tag "Function" function))
1007 :group 'vhdl-sequential-process)
1009 (defcustom vhdl-clock-name ""
1010 "*Name of clock signal to use in templates."
1012 :group 'vhdl-sequential-process)
1014 (defcustom vhdl-reset-name ""
1015 "*Name of reset signal to use in templates."
1017 :group 'vhdl-sequential-process)
1020 (defgroup vhdl-model nil
1021 "Customizations for user models."
1024 (defcustom vhdl-model-alist
1026 "<label> : process (<clock>, <reset>)
1027 begin -- process <label>
1028 if <reset> = '0' then -- asynchronous reset (active low)
1030 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1031 if <enable> = '1' then -- synchronous load
1035 end process <label>;"
1037 "*List of user models.
1038 VHDL models (templates) can be specified by the user in this list. They can be
1039 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1040 electrification (i.e. overriding existing or creating new keywords, see
1041 option `vhdl-electric-keywords').
1042 Name : name of model (string of words and spaces)
1043 String : string or name of file to be inserted as model (newline: `C-j')
1044 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1045 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1046 Keyword : keyword to invoke model
1048 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1049 A prompt that appears several times is queried once and replaced throughout
1050 the model. Special prompts are:
1051 <clock> : name specified in `vhdl-clock-name' (if not empty)
1052 <reset> : name specified in `vhdl-reset-name' (if not empty)
1053 <cursor>: final cursor position
1054 File header prompts (see variable `vhdl-file-header') are automatically
1055 replaced, so that user models can also be used to insert different types of
1058 If the string specifies an existing file name, the contents of the file is
1059 inserted, otherwise the string itself is inserted.
1060 The code within the models should be correctly indented.
1061 Type `C-j' for newlines.
1063 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1064 \"Activate Options\"."
1065 :type '(repeat (list :tag "Model" :indent 2
1066 (string :tag "Name ")
1067 (string :tag "String : (type `C-j' for newline)"
1069 (sexp :tag "Key binding" x)
1070 (string :tag "Keyword " :format "%t: %v\n")))
1071 :set (lambda (variable value)
1072 (vhdl-custom-set variable value
1073 'vhdl-model-map-init
1075 'vhdl-mode-abbrev-table-init
1076 'vhdl-update-mode-menu))
1080 (defgroup vhdl-port nil
1081 "Customizations for port translation functions."
1083 :group 'vhdl-compose)
1085 (defcustom vhdl-include-port-comments nil
1086 "*Non-nil means include port comments when a port is pasted."
1090 (defcustom vhdl-include-direction-comments nil
1091 "*Non-nil means include port direction in instantiations as comments."
1095 (defcustom vhdl-include-type-comments nil
1096 "*Non-nil means include generic/port type in instantiations as comments."
1100 (defcustom vhdl-include-group-comments 'never
1101 "*Specifies whether to include group comments and spacings.
1102 The comments and empty lines between groups of ports are pasted:
1104 Declarations: in entity/component/constant/signal declarations only
1105 Always : also in generic/port maps"
1106 :type '(choice (const :tag "Never" never)
1107 (const :tag "Declarations" decl)
1108 (const :tag "Always" always))
1111 (defcustom vhdl-actual-port-name '(".*" . "\\&")
1113 "*Specifies how actual port names are obtained from formal port names.
1114 In a component instantiation, an actual port name can be obtained by
1115 modifying the formal port name (e.g. attaching or stripping off a substring)."
1116 vhdl-name-doc-string)
1117 :type '(cons (regexp :tag "From regexp")
1118 (string :tag "To string "))
1121 (defcustom vhdl-instance-name '(".*" . "\\&_%d")
1123 "*Specifies how an instance name is obtained.
1124 The instance name can be obtained by modifying the name of the component to be
1125 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1126 by a unique number (starting with 1).
1127 If TO STRING is empty, the instance name is queried."
1128 vhdl-name-doc-string)
1129 :type '(cons (regexp :tag "From regexp")
1130 (string :tag "To string "))
1134 (defgroup vhdl-testbench nil
1135 "Customizations for testbench generation."
1138 (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1140 "*Specifies how the testbench entity name is obtained.
1141 The entity name of a testbench can be obtained by modifying the name of
1142 the component to be tested (e.g. attaching or stripping off a substring)."
1143 vhdl-name-doc-string)
1144 :type '(cons (regexp :tag "From regexp")
1145 (string :tag "To string "))
1146 :group 'vhdl-testbench)
1148 (defcustom vhdl-testbench-architecture-name '(".*" . "")
1150 "*Specifies how the testbench architecture name is obtained.
1151 The testbench architecture name can be obtained by modifying the name of
1152 the component to be tested (e.g. attaching or stripping off a substring).
1153 If TO STRING is empty, the architecture name is queried."
1154 vhdl-name-doc-string)
1155 :type '(cons (regexp :tag "From regexp")
1156 (string :tag "To string "))
1157 :group 'vhdl-testbench)
1159 (defcustom vhdl-testbench-configuration-name
1160 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1162 "*Specifies how the testbench configuration name is obtained.
1163 The configuration name of a testbench can be obtained by modifying the entity
1164 and/or architecture name (e.g. attaching or stripping off a substring). The
1165 string that is matched against the regexp is the concatenation of the entity
1166 and the architecture name separated by a space. This gives access to both
1167 names (see default setting as example)."
1168 vhdl-name-doc-string)
1169 :type '(cons (regexp :tag "From regexp")
1170 (string :tag "To string "))
1171 :group 'vhdl-testbench)
1173 (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1175 "*Specifies how a DUT instance name is obtained.
1176 The design-under-test instance name (i.e. the component instantiated in the
1177 testbench) can be obtained by modifying the component name (e.g. attaching
1178 or stripping off a substring)."
1179 vhdl-name-doc-string)
1180 :type '(cons (regexp :tag "From regexp")
1181 (string :tag "To string "))
1182 :group 'vhdl-testbench)
1184 (defcustom vhdl-testbench-include-header t
1185 "*Non-nil means include a header in automatically generated files."
1187 :group 'vhdl-testbench)
1189 (defcustom vhdl-testbench-declarations "\
1191 signal Clk : std_logic := '1';
1193 "*String or file to be inserted in the testbench declarative part.
1194 If the string specifies an existing file name, the contents of the file is
1195 inserted, otherwise the string itself is inserted in the testbench
1196 architecture before the BEGIN keyword.
1197 Type `C-j' for newlines."
1199 :group 'vhdl-testbench)
1201 (defcustom vhdl-testbench-statements "\
1203 Clk <= not Clk after 10 ns;
1205 -- waveform generation
1206 WaveGen_Proc: process
1208 -- insert signal assignments here
1210 wait until Clk = '1';
1211 end process WaveGen_Proc;
1213 "*String or file to be inserted in the testbench statement part.
1214 If the string specifies an existing file name, the contents of the file is
1215 inserted, otherwise the string itself is inserted in the testbench
1216 architecture before the END keyword.
1217 Type `C-j' for newlines."
1219 :group 'vhdl-testbench)
1221 (defcustom vhdl-testbench-initialize-signals nil
1222 "*Non-nil means initialize signals with `0' when declared in testbench."
1224 :group 'vhdl-testbench)
1226 (defcustom vhdl-testbench-include-library t
1227 "*Non-nil means a library/use clause for std_logic_1164 is included."
1229 :group 'vhdl-testbench)
1231 (defcustom vhdl-testbench-include-configuration t
1232 "*Non-nil means a testbench configuration is attached at the end."
1234 :group 'vhdl-testbench)
1236 (defcustom vhdl-testbench-create-files 'single
1237 "*Specifies whether new files should be created for the testbench.
1238 testbench entity and architecture are inserted:
1239 None : in current buffer
1240 Single file : in new single file
1241 Separate files: in two separate files
1242 Note that the files have the same name as the contained design unit."
1243 :type '(choice (const :tag "None" none)
1244 (const :tag "Single file" single)
1245 (const :tag "Separate files" separate))
1246 :group 'vhdl-testbench)
1249 (defgroup vhdl-compose nil
1250 "Customizations for structural composition."
1253 (defcustom vhdl-compose-create-files 'single
1254 "*Specifies whether new files should be created for the new component.
1255 The component's entity and architecture are inserted:
1256 None : in current buffer
1257 Single file : in new single file
1258 Separate files: in two separate files
1259 The file names are obtained from variables `vhdl-entity-file-name' and
1260 `vhdl-architecture-file-name'."
1261 :type '(choice (const :tag "None" none)
1262 (const :tag "Single file" single)
1263 (const :tag "Separate files" separate))
1264 :group 'vhdl-compose)
1266 (defcustom vhdl-compose-include-header t
1267 "*Non-nil means include a header in automatically generated files."
1269 :group 'vhdl-compose)
1271 (defcustom vhdl-compose-architecture-name '(".*" . "str")
1273 "*Specifies how the component architecture name is obtained.
1274 The component architecture name can be obtained by modifying the entity name
1275 \(e.g. attaching or stripping off a substring).
1276 If TO STRING is empty, the architecture name is queried."
1277 vhdl-name-doc-string)
1278 :type '(cons (regexp :tag "From regexp")
1279 (string :tag "To string "))
1280 :group 'vhdl-compose)
1282 (defcustom vhdl-components-package-name
1283 '((".*" . "\\&_components") . "components")
1285 "*Specifies how the name for the components package is obtained.
1286 The components package is a package containing all component declarations for
1287 the current design. Its name can be obtained by modifying the project name
1288 \(e.g. attaching or stripping off a substring). If no project is defined, the
1289 DIRECTORY entry is chosen."
1290 vhdl-name-doc-string)
1291 :type '(cons (cons :tag "Project" :indent 2
1292 (regexp :tag "From regexp")
1293 (string :tag "To string "))
1294 (string :tag "Directory:\n String "))
1295 :group 'vhdl-compose)
1297 (defcustom vhdl-use-components-package nil
1298 "*Non-nil means use a separate components package for component declarations.
1299 Otherwise, component declarations are inserted and searched for in the
1300 architecture declarative parts."
1302 :group 'vhdl-compose)
1305 (defgroup vhdl-comment nil
1306 "Customizations for comments."
1309 (defcustom vhdl-self-insert-comments t
1310 "*Non-nil means various templates automatically insert help comments."
1312 :group 'vhdl-comment)
1314 (defcustom vhdl-prompt-for-comments t
1315 "*Non-nil means various templates prompt for user definable comments."
1317 :group 'vhdl-comment)
1319 (defcustom vhdl-inline-comment-column 40
1320 "*Column to indent and align inline comments to.
1321 Overrides local option `comment-column'.
1323 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1324 \"Activate Options\"."
1326 :group 'vhdl-comment)
1328 (defcustom vhdl-end-comment-column 79
1329 "*End of comment column.
1330 Comments that exceed this column number are wrapped.
1332 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1333 \"Activate Options\"."
1335 :group 'vhdl-comment)
1337 (defvar end-comment-column)
1340 (defgroup vhdl-align nil
1341 "Customizations for alignment."
1344 (defcustom vhdl-auto-align t
1345 "*Non-nil means align some templates automatically after generation."
1349 (defcustom vhdl-align-groups t
1350 "*Non-nil means align groups of code lines separately.
1351 A group of code lines is a region of consecutive lines between two lines that
1352 match the regexp in option `vhdl-align-group-separate'."
1356 (defcustom vhdl-align-group-separate "^\\s-*$"
1357 "*Regexp for matching a line that separates groups of lines for alignment.
1359 \"^\\s-*$\": matches an empty line
1360 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1364 (defcustom vhdl-align-same-indent t
1365 "*Non-nil means align blocks with same indent separately.
1366 When a region or the entire buffer is aligned, the code is divided into
1367 blocks of same indent which are aligned separately (except for argument/port
1368 lists). This gives nicer alignment in most cases.
1369 Option `vhdl-align-groups' still applies within these blocks."
1374 (defgroup vhdl-highlight nil
1375 "Customizations for highlighting."
1378 (defcustom vhdl-highlight-keywords t
1379 "*Non-nil means highlight VHDL keywords and other standardized words.
1380 The following faces are used:
1381 `font-lock-keyword-face' : keywords
1382 `font-lock-type' : standardized types
1383 `vhdl-attribute' : standardized attributes
1384 `vhdl-enumvalue' : standardized enumeration values
1385 `vhdl-function' : standardized function and package names
1387 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1388 entry \"Fontify Buffer\")."
1390 :set (lambda (variable value)
1391 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1392 :group 'vhdl-highlight)
1394 (defcustom vhdl-highlight-names t
1395 "*Non-nil means highlight declaration names and construct labels.
1396 The following faces are used:
1397 `font-lock-function-name-face' : names in declarations of units,
1398 subprograms, components, as well as labels of VHDL constructs
1399 `font-lock-type-face' : names in type/nature declarations
1400 `vhdl-attribute' : names in attribute declarations
1401 `font-lock-variable-name-face' : names in declarations of signals,
1402 variables, constants, subprogram parameters, generics, and ports
1404 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1405 entry \"Fontify Buffer\")."
1407 :set (lambda (variable value)
1408 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1409 :group 'vhdl-highlight)
1411 (defcustom vhdl-highlight-special-words nil
1412 "*Non-nil means highlight words with special syntax.
1413 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1414 are highlighted accordingly.
1415 Can be used for visual support of naming conventions.
1417 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1418 entry \"Fontify Buffer\")."
1420 :set (lambda (variable value)
1421 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1422 :group 'vhdl-highlight)
1424 (defcustom vhdl-highlight-forbidden-words nil
1425 "*Non-nil means highlight forbidden words.
1426 The reserved words specified in option `vhdl-forbidden-words' or having the
1427 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1428 warning color (face `vhdl-reserved-word') to indicate not to
1431 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1432 entry \"Fontify Buffer\")."
1434 :set (lambda (variable value)
1435 (vhdl-custom-set variable value
1436 'vhdl-words-init 'vhdl-font-lock-init))
1437 :group 'vhdl-highlight)
1439 (defcustom vhdl-highlight-verilog-keywords nil
1440 "*Non-nil means highlight Verilog keywords as reserved words.
1441 Verilog keywords are highlighted in a warning color (face
1442 `vhdl-reserved-word') to indicate not to use them.
1444 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1445 entry \"Fontify Buffer\")."
1447 :set (lambda (variable value)
1448 (vhdl-custom-set variable value
1449 'vhdl-words-init 'vhdl-font-lock-init))
1450 :group 'vhdl-highlight)
1452 (defcustom vhdl-highlight-translate-off nil
1453 "*Non-nil means background-highlight code excluded from translation.
1454 That is, all code between \"-- pragma translate_off\" and
1455 \"-- pragma translate_on\" is highlighted using a different background color
1456 \(face `vhdl-translate-off').
1457 Note: this might slow down on-the-fly fontification (and thus editing).
1459 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1460 entry \"Fontify Buffer\")."
1462 :set (lambda (variable value)
1463 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1464 :group 'vhdl-highlight)
1466 (defcustom vhdl-highlight-case-sensitive nil
1467 "*Non-nil means consider case for highlighting.
1469 non-nil also upper-case VHDL words are highlighted, but case of words with
1470 special syntax is not considered
1471 nil only lower-case VHDL words are highlighted, but case of words with
1472 special syntax is considered
1473 Overrides local option `font-lock-keywords-case-fold-search'.
1475 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1476 entry \"Fontify Buffer\")."
1478 :group 'vhdl-highlight)
1480 (defcustom vhdl-special-syntax-alist
1481 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1482 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1483 ("variable" "\\w+_v" "Grey50" "Grey80"))
1484 "*List of special syntax to be highlighted.
1485 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1486 syntax (as regular expression) are highlighted in the corresponding color.
1488 Name : string of words and spaces
1489 Regexp : regular expression describing word syntax
1490 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1491 Color (light): foreground color for light background
1492 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1493 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1494 Color (dark) : foreground color for dark background
1495 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1496 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1498 Can be used for visual support of naming conventions, such as highlighting
1499 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1500 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1501 common substrings or name suffices.
1502 For each entry, a new face is generated with the specified colors and name
1505 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1506 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1507 :type '(repeat (list :tag "Face" :indent 2
1508 (string :tag "Name ")
1509 (regexp :tag "Regexp " "\\w+_")
1510 (string :tag "Color (light)")
1511 (string :tag "Color (dark) ")))
1512 :set (lambda (variable value)
1513 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1514 :group 'vhdl-highlight)
1516 (defcustom vhdl-forbidden-words '()
1517 "*List of forbidden words to be highlighted.
1518 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1519 words are highlighted in a warning color to indicate not to use them.
1521 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1522 entry \"Fontify Buffer\")."
1523 :type '(repeat (string :format "%v"))
1524 :set (lambda (variable value)
1525 (vhdl-custom-set variable value
1526 'vhdl-words-init 'vhdl-font-lock-init))
1527 :group 'vhdl-highlight)
1529 (defcustom vhdl-forbidden-syntax ""
1530 "*Syntax of forbidden words to be highlighted.
1531 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1532 syntax are highlighted in a warning color to indicate not to use them.
1533 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1534 highlights identifiers with 10 or more characters).
1536 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1537 entry \"Fontify Buffer\")."
1539 :set (lambda (variable value)
1540 (vhdl-custom-set variable value
1541 'vhdl-words-init 'vhdl-font-lock-init))
1542 :group 'vhdl-highlight)
1544 (defcustom vhdl-directive-keywords '("pragma" "synopsys")
1545 "*List of compiler directive keywords recognized for highlighting.
1547 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1548 entry \"Fontify Buffer\")."
1549 :type '(repeat (string :format "%v"))
1550 :set (lambda (variable value)
1551 (vhdl-custom-set variable value
1552 'vhdl-words-init 'vhdl-font-lock-init))
1553 :group 'vhdl-highlight)
1556 (defgroup vhdl-speedbar nil
1557 "Customizations for speedbar."
1560 (defcustom vhdl-speedbar-auto-open nil
1561 "*Non-nil means automatically open speedbar at startup.
1562 Alternatively, the speedbar can be opened from the VHDL menu."
1564 :group 'vhdl-speedbar)
1566 (defcustom vhdl-speedbar-display-mode 'files
1567 "*Specifies the default displaying mode when opening speedbar.
1568 Alternatively, the displaying mode can be selected from the speedbar menu or
1569 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1570 :type '(choice (const :tag "Files" files)
1571 (const :tag "Directory hierarchy" directory)
1572 (const :tag "Project hierarchy" project))
1573 :group 'vhdl-speedbar)
1575 (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1576 "*Limits scanning of large files and netlists.
1577 Design units: maximum file size to scan for design units
1578 Hierarchy (instances of subcomponents):
1579 File size: maximum file size to scan for instances (in bytes)
1580 Instances per arch: maximum number of instances to scan per architecture
1582 \"None\" always means that there is no limit.
1583 In case of files not or incompletely scanned, a warning message and the file
1584 names are printed out.
1585 Background: scanning for instances is considerably slower than scanning for
1586 design units, especially when there are many instances. These limits should
1587 prevent the scanning of large netlists."
1588 :type '(list (choice :tag "Design units"
1589 :format "%t : %[Value Menu%] %v"
1590 (const :tag "None" nil)
1591 (integer :tag "File size"))
1592 (list :tag "Hierarchy" :indent 2
1593 (choice :tag "File size"
1594 :format "%t : %[Value Menu%] %v"
1595 (const :tag "None" nil)
1596 (integer :tag "Size "))
1597 (choice :tag "Instances per arch"
1598 (const :tag "None" nil)
1599 (integer :tag "Number "))))
1600 :group 'vhdl-speedbar)
1602 (defcustom vhdl-speedbar-jump-to-unit t
1603 "*Non-nil means jump to the design unit code when opened in a buffer.
1604 The buffer cursor position is left unchanged otherwise."
1606 :group 'vhdl-speedbar)
1608 (defcustom vhdl-speedbar-update-on-saving t
1609 "*Automatically update design hierarchy when buffer is saved."
1611 :group 'vhdl-speedbar)
1613 (defcustom vhdl-speedbar-save-cache '(hierarchy display)
1614 "*Automatically save modified hierarchy caches when exiting Emacs.
1615 Hierarchy: design hierarchy information
1616 Display: displaying information (which design units to expand)"
1617 :type '(set (const :tag "Hierarchy" hierarchy)
1618 (const :tag "Display" display))
1619 :group 'vhdl-speedbar)
1621 (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1622 "*Name of file for saving hierarchy cache.
1623 \"\\1\" is replaced by the project name if a project is specified,
1624 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1625 different users to have cache files in the same directory). Can also have
1626 an absolute path (i.e. all caches can be stored in one global directory)."
1628 :group 'vhdl-speedbar)
1631 (defgroup vhdl-menu nil
1632 "Customizations for menues."
1635 (defcustom vhdl-index-menu nil
1636 "*Non-nil means add an index menu for a source file when loading.
1637 Alternatively, the speedbar can be used. Note that the index menu scans a file
1638 when it is opened, while speedbar only scans the file upon request."
1642 (defcustom vhdl-source-file-menu nil
1643 "*Non-nil means add a menu of all source files in current directory.
1644 Alternatively, the speedbar can be used."
1648 (defcustom vhdl-hideshow-menu nil
1649 "*Non-nil means add hideshow menu and functionality at startup.
1650 Hideshow can also be enabled from the VHDL Mode menu.
1651 Hideshow allows hiding code of various VHDL constructs.
1653 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1654 \"Activate Options\"."
1658 (defcustom vhdl-hide-all-init nil
1659 "*Non-nil means hide all design units initially after a file is loaded."
1664 (defgroup vhdl-print nil
1665 "Customizations for printing."
1668 (defcustom vhdl-print-two-column t
1669 "*Non-nil means print code in two columns and landscape format.
1670 Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1671 prints VHDL files in a nice two-column landscape style.
1673 NOTE: Activate the new setting by restarting Emacs.
1674 Overrides `ps-print' settings locally."
1678 (defcustom vhdl-print-customize-faces t
1679 "*Non-nil means use an optimized set of faces for postscript printing.
1681 NOTE: Activate the new setting by restarting Emacs.
1682 Overrides `ps-print' settings locally."
1687 (defgroup vhdl-misc nil
1688 "Miscellaneous customizations."
1691 (defcustom vhdl-intelligent-tab t
1692 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
1693 That is, if preceeding character is part of a word then complete word,
1694 else if not at beginning of line then insert tab,
1695 else if last command was a `TAB' or `RET' then dedent one step,
1696 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1697 If nil, TAB always indents current line (i.e. `TAB' is bound to
1698 `indent-according-to-mode').
1700 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1701 \"Activate Options\"."
1705 (defcustom vhdl-indent-syntax-based t
1706 "*Non-nil means indent lines of code based on their syntactic context.
1707 Otherwise, a line is indented like the previous nonblank line. This can be
1708 useful in large files where syntax-based indentation gets very slow."
1712 (defcustom vhdl-word-completion-case-sensitive nil
1713 "*Non-nil means word completion using `TAB' is case sensitive.
1714 That is, `TAB' completes words that start with the same letters and case.
1715 Otherwise, case is ignored."
1719 (defcustom vhdl-word-completion-in-minibuffer t
1720 "*Non-nil enables word completion in minibuffer (for template prompts).
1722 NOTE: Activate the new setting by restarting Emacs."
1726 (defcustom vhdl-underscore-is-part-of-word nil
1727 "*Non-nil means consider the underscore character `_' as part of word.
1728 An identifier containing underscores is then treated as a single word in
1729 select and move operations. All parts of an identifier separated by underscore
1730 are treated as single words otherwise.
1732 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1733 \"Activate Options\"."
1735 :set (lambda (variable value)
1736 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
1740 (defgroup vhdl-related nil
1741 "Related general customizations."
1744 ;; add related general customizations
1745 (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1747 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1748 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1749 (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1750 (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1751 (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1753 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1754 (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1755 (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1756 (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1758 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1759 ;; Internal variables
1761 (defvar vhdl-menu-max-size 20
1762 "*Specifies the maximum size of a menu before splitting it into submenues.")
1764 (defvar vhdl-progress-interval 1
1765 "*Interval used to update progress status during long operations.
1766 If a number, percentage complete gets updated after each interval of
1767 that many seconds. To inhibit all messages, set this option to nil.")
1769 (defvar vhdl-inhibit-startup-warnings-p nil
1770 "*If non-nil, inhibits start up compatibility warnings.")
1772 (defvar vhdl-strict-syntax-p nil
1773 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1774 If the syntactic symbol for a particular line does not match a symbol
1775 in the offsets alist, an error is generated, otherwise no error is
1776 reported and the syntactic symbol is ignored.")
1778 (defvar vhdl-echo-syntactic-information-p nil
1779 "*If non-nil, syntactic info is echoed when the line is indented.")
1781 (defconst vhdl-offsets-alist-default
1786 (statement-cont . vhdl-lineup-statement-cont)
1787 (statement-block-intro . +)
1788 (statement-case-intro . +)
1789 (case-alternative . +)
1790 (comment . vhdl-lineup-comment)
1793 (arglist-cont-nonempty . vhdl-lineup-arglist)
1794 (arglist-close . vhdl-lineup-arglist)
1801 "Default settings for offsets of syntactic elements.
1802 Do not change this constant! See the variable `vhdl-offsets-alist' for
1805 (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1806 "*Association list of syntactic element symbols and indentation offsets.
1807 As described below, each cons cell in this list has the form:
1809 (SYNTACTIC-SYMBOL . OFFSET)
1811 When a line is indented, `vhdl-mode' first determines the syntactic
1812 context of the line by generating a list of symbols called syntactic
1813 elements. This list can contain more than one syntactic element and
1814 the global variable `vhdl-syntactic-context' contains the context list
1815 for the line being indented. Each element in this list is actually a
1816 cons cell of the syntactic symbol and a buffer position. This buffer
1817 position is call the relative indent point for the line. Some
1818 syntactic symbols may not have a relative indent point associated with
1821 After the syntactic context list for a line is generated, `vhdl-mode'
1822 calculates the absolute indentation for the line by looking at each
1823 syntactic element in the list. First, it compares the syntactic
1824 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1825 finds a match, it adds the OFFSET to the column of the relative indent
1826 point. The sum of this calculation for each element in the syntactic
1827 list is the absolute offset for line being indented.
1829 If the syntactic element does not match any in the `vhdl-offsets-alist',
1830 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1831 the element is ignored.
1833 Actually, OFFSET can be an integer, a function, a variable, or one of
1834 the following symbols: `+', `-', `++', or `--'. These latter
1835 designate positive or negative multiples of `vhdl-basic-offset',
1836 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
1837 called with a single argument containing the cons of the syntactic
1838 element symbol and the relative indent point. The function should
1839 return an integer offset.
1841 Here is the current list of valid syntactic element symbols:
1843 string -- inside multi-line string
1844 block-open -- statement block open
1845 block-close -- statement block close
1846 statement -- a VHDL statement
1847 statement-cont -- a continuation of a VHDL statement
1848 statement-block-intro -- the first line in a new statement block
1849 statement-case-intro -- the first line in a case alternative block
1850 case-alternative -- a case statement alternative clause
1851 comment -- a line containing only a comment
1852 arglist-intro -- the first line in an argument list
1853 arglist-cont -- subsequent argument list lines when no
1854 arguments follow on the same line as the
1855 the arglist opening paren
1856 arglist-cont-nonempty -- subsequent argument list lines when at
1857 least one argument follows on the same
1858 line as the arglist opening paren
1859 arglist-close -- the solo close paren of an argument list
1860 entity -- inside an entity declaration
1861 configuration -- inside a configuration declaration
1862 package -- inside a package declaration
1863 architecture -- inside an architecture body
1864 package-body -- inside a package body")
1866 (defvar vhdl-comment-only-line-offset 0
1867 "*Extra offset for line which contains only the start of a comment.
1868 Can contain an integer or a cons cell of the form:
1870 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1872 Where NON-ANCHORED-OFFSET is the amount of offset given to
1873 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1874 the amount of offset to give column-zero anchored comment-only lines.
1875 Just an integer as value is equivalent to (<val> . 0)")
1877 (defvar vhdl-special-indent-hook nil
1878 "*Hook for user defined special indentation adjustments.
1879 This hook gets called after a line is indented by the mode.")
1881 (defvar vhdl-style-alist
1883 (vhdl-basic-offset . 4)
1884 (vhdl-offsets-alist . ())))
1885 "Styles of Indentation.
1886 Elements of this alist are of the form:
1888 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1890 where STYLE-STRING is a short descriptive string used to select a
1891 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
1892 value for that variable when using the selected style.
1894 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1895 case, the VALUE is a list containing elements of the form:
1897 (SYNTACTIC-SYMBOL . VALUE)
1899 as described in `vhdl-offsets-alist'. These are passed directly to
1900 `vhdl-set-offset' so there is no need to set every syntactic symbol in
1901 your style, only those that are different from the default.")
1903 ;; dynamically append the default value of most variables
1904 (or (assoc "Default" vhdl-style-alist)
1905 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1906 vhdl-strict-syntax-p
1907 vhdl-echo-syntactic-information-p
1910 vhdl-comment-only-line-offset))
1911 (default (cons "Default"
1915 (cons var (symbol-value var))))
1917 (setq vhdl-style-alist (cons default vhdl-style-alist))))
1919 (defvar vhdl-mode-hook nil
1920 "*Hook called by `vhdl-mode'.")
1923 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1924 ;;; Required packages
1925 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1929 (require 'compile) ; XEmacs
1931 (require 'hippie-exp)
1933 ;; optional (minimize warning messages during compile)
1935 (require 'font-lock)
1937 (require 'speedbar))
1940 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1942 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1945 ;; XEmacs compatibility
1948 (defun vhdl-keep-region-active ()
1949 "Do whatever is necessary to keep the region active in XEmacs.
1950 Ignore byte-compiler warnings you might see."
1951 (and (boundp 'zmacs-region-stays)
1952 (setq zmacs-region-stays t)))
1954 ;; `wildcard-to-regexp' is included only in XEmacs 21
1955 (unless (fboundp 'wildcard-to-regexp)
1956 (defun wildcard-to-regexp (wildcard)
1957 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
1958 (let* ((i (string-match "[*?]" wildcard))
1959 (result (substring wildcard 0 i))
1960 (len (length wildcard)))
1963 (let ((ch (aref wildcard i)))
1964 (setq result (concat result
1965 (cond ((eq ch ?*) "[^\000]*")
1966 ((eq ch ??) "[^\000]")
1967 (t (char-to-string ch)))))
1969 (concat "\\`" result "\\'"))))
1971 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
1972 ;; `regexp-opt' accelerates fontification by 10-20%
1973 (unless (fboundp 'regexp-opt)
1974 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
1975 (defun regexp-opt (strings &optional paren)
1976 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
1977 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
1979 ;; `match-string-no-properties' undefined (XEmacs, what else?)
1980 (unless (fboundp 'match-string-no-properties)
1981 (defalias 'match-string-no-properties 'match-string))
1983 ;; `subst-char-in-string' undefined (XEmacs)
1984 (unless (fboundp 'subst-char-in-string)
1985 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1986 (let ((i (length string))
1987 (newstr (if inplace string (copy-sequence string))))
1990 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
1993 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
1994 (when (and vhdl-xemacs (string< itimer-version "1.09")
1995 (not noninteractive))
1997 (when (string< itimer-version "1.09")
1998 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
1999 (beep) (sit-for 5)))
2001 ;; `file-expand-wildcards' undefined (XEmacs)
2002 (unless (fboundp 'file-expand-wildcards)
2003 (defun file-expand-wildcards (pattern &optional full)
2004 "Taken from Emacs' `files.el'."
2005 (let* ((nondir (file-name-nondirectory pattern))
2006 (dirpart (file-name-directory pattern))
2007 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2008 (mapcar 'file-name-as-directory
2009 (file-expand-wildcards (directory-file-name dirpart)))
2013 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2014 (file-directory-p (directory-file-name (car dirs))))
2015 (let ((this-dir-contents
2017 (mapcar #'(lambda (name)
2018 (unless (string-match "\\`\\.\\.?\\'"
2019 (file-name-nondirectory name))
2021 (directory-files (or (car dirs) ".") full
2022 (wildcard-to-regexp nondir))))))
2025 (if (and (car dirs) (not full))
2026 (mapcar (function (lambda (name) (concat (car dirs) name)))
2030 (setq dirs (cdr dirs)))
2033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2034 ;; Compatibility with older VHDL Mode versions
2036 (defvar vhdl-warnings nil
2037 "Warnings to tell the user during start up.")
2039 (defun vhdl-run-when-idle (secs repeat function)
2040 "Wait until idle, then run FUNCTION."
2041 (if (fboundp 'start-itimer)
2042 (start-itimer "vhdl-mode" function secs repeat t)
2043 ; (run-with-idle-timer secs repeat function)))
2044 ;; explicitely activate timer (necessary when Emacs is already idle)
2045 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2047 (defun vhdl-warning-when-idle (&rest args)
2048 "Wait until idle, then print out warning STRING and beep."
2050 (vhdl-warning (apply 'format args) t)
2051 (unless vhdl-warnings
2052 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2053 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2055 (defun vhdl-warning (string &optional nobeep)
2056 "Print out warning STRING and beep."
2057 (message (concat "WARNING: " string))
2058 (unless (or nobeep noninteractive) (beep)))
2060 (defun vhdl-print-warnings ()
2061 "Print out messages in variable `vhdl-warnings'."
2062 (let ((no-warnings (length vhdl-warnings)))
2063 (setq vhdl-warnings (nreverse vhdl-warnings))
2064 (while vhdl-warnings
2065 (message (concat "WARNING: " (car vhdl-warnings)))
2066 (setq vhdl-warnings (cdr vhdl-warnings)))
2068 (when (> no-warnings 1)
2069 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2071 ;; Backward compatibility checks and fixes
2072 ;; option `vhdl-compiler' changed format
2073 (unless (stringp vhdl-compiler)
2074 (setq vhdl-compiler "ModelSim")
2075 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2077 ;; option `vhdl-standard' changed format
2078 (unless (listp vhdl-standard)
2079 (setq vhdl-standard '(87 nil))
2080 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2082 ;; option `vhdl-model-alist' changed format
2083 (when (= (length (car vhdl-model-alist)) 3)
2084 (let ((old-alist vhdl-model-alist)
2087 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2088 (setq old-alist (cdr old-alist)))
2089 (setq vhdl-model-alist (nreverse new-alist)))
2090 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2092 ;; option `vhdl-project-alist' changed format
2093 (when (= (length (car vhdl-project-alist)) 3)
2094 (let ((old-alist vhdl-project-alist)
2097 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2098 (setq old-alist (cdr old-alist)))
2099 (setq vhdl-project-alist (nreverse new-alist)))
2100 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2102 ;; option `vhdl-project-alist' changed format (3.31.1)
2103 (when (= (length (car vhdl-project-alist)) 4)
2104 (let ((old-alist vhdl-project-alist)
2107 (setq elem (car old-alist))
2109 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2110 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2112 (setq old-alist (cdr old-alist)))
2113 (setq vhdl-project-alist (nreverse new-alist)))
2114 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2116 ;; option `vhdl-project-alist' changed format (3.31.12)
2117 (when (= (length (car vhdl-project-alist)) 10)
2118 (let ((tmp-alist vhdl-project-alist))
2120 (setcdr (nthcdr 3 (car tmp-alist))
2121 (cons "" (nthcdr 4 (car tmp-alist))))
2122 (setq tmp-alist (cdr tmp-alist))))
2123 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2125 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2126 (when (= (length (car vhdl-compiler-alist)) 7)
2127 (let ((old-alist vhdl-compiler-alist)
2130 (setq elem (car old-alist))
2132 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2133 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2134 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2135 (nth 5 elem) (nth 6 elem) nil)
2137 (setq old-alist (cdr old-alist)))
2138 (setq vhdl-compiler-alist (nreverse new-alist)))
2139 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2141 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2142 (when (= (length (car vhdl-compiler-alist)) 12)
2143 (let ((tmp-alist vhdl-compiler-alist))
2145 (setcdr (nthcdr 4 (car tmp-alist))
2146 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2147 (setq tmp-alist (cdr tmp-alist))))
2148 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2150 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2151 (when (= (length (car vhdl-compiler-alist)) 13)
2152 (let ((tmp-alist vhdl-compiler-alist))
2154 (setcdr (nthcdr 3 (car tmp-alist))
2155 (cons "" (nthcdr 4 (car tmp-alist))))
2156 (setq tmp-alist (cdr tmp-alist))))
2157 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2159 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2160 (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2161 (let ((tmp-alist vhdl-compiler-alist))
2163 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2165 (setq tmp-alist (cdr tmp-alist))))
2166 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2168 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2169 (when (equal vhdl-project "")
2170 (setq vhdl-project nil)
2171 (customize-save-variable 'vhdl-project vhdl-project))
2173 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2174 (when (stringp vhdl-project-file-name)
2175 (setq vhdl-project-file-name (list vhdl-project-file-name))
2176 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2178 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2179 (if (not (boundp 'speedbar-indentation-width))
2180 (defvar speedbar-indentation-width 2)
2181 ;; set default to 2 if not already customized
2182 (unless (get 'speedbar-indentation-width 'saved-value)
2183 (setq speedbar-indentation-width 2)))
2186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2187 ;;; Help functions / inline substitutions / macros
2188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2190 (defun vhdl-standard-p (standard)
2191 "Check if STANDARD is specified as used standard."
2192 (or (eq standard (car vhdl-standard))
2193 (memq standard (cadr vhdl-standard))))
2195 (defun vhdl-project-p (&optional warning)
2196 "Return non-nil if a project is displayed, i.e. directories or files are
2198 (if (assoc vhdl-project vhdl-project-alist)
2200 (when (and vhdl-project warning)
2201 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2204 (defun vhdl-resolve-env-variable (string)
2205 "Resolve environment variables in STRING."
2206 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2207 (setq string (concat (match-string 1 string)
2208 (getenv (match-string 2 string))
2209 (match-string 4 string))))
2212 (defun vhdl-default-directory ()
2213 "Return the default directory of the current project or the directory of the
2214 current buffer if no project is defined."
2215 (if (vhdl-project-p)
2216 (expand-file-name (vhdl-resolve-env-variable
2217 (nth 1 (aget vhdl-project-alist vhdl-project))))
2220 (defmacro vhdl-prepare-search-1 (&rest body)
2221 "Enable case insensitive search and switch to syntax table that includes '_',
2222 then execute BODY, and finally restore the old environment. Used for
2223 consistent searching."
2224 `(let ((case-fold-search t) ; case insensitive search
2225 (current-syntax-table (syntax-table))
2227 (restore-prog ; program to restore enviroment
2229 ;; restore syntax table
2230 (set-syntax-table current-syntax-table))))
2231 ;; use extended syntax table
2232 (set-syntax-table vhdl-mode-ext-syntax-table)
2233 ;; execute BODY safely
2235 (condition-case info
2237 (error (eval restore-prog) ; restore environment on error
2238 (error (cadr info))))) ; pass error up
2239 ;; restore environment
2243 (defmacro vhdl-prepare-search-2 (&rest body)
2244 "Enable case insensitive search, switch to syntax table that includes '_',
2245 and remove `intangible' overlays, then execute BODY, and finally restore the
2246 old environment. Used for consistent searching."
2247 `(let ((case-fold-search t) ; case insensitive search
2248 (current-syntax-table (syntax-table))
2249 result overlay-all-list overlay-intangible-list overlay
2250 (restore-prog ; program to restore enviroment
2252 ;; restore syntax table
2253 (set-syntax-table current-syntax-table)
2254 ;; restore `intangible' overlays
2255 (when (fboundp 'overlay-lists)
2256 (while overlay-intangible-list
2257 (overlay-put (car overlay-intangible-list) 'intangible t)
2258 (setq overlay-intangible-list
2259 (cdr overlay-intangible-list)))))))
2260 ;; use extended syntax table
2261 (set-syntax-table vhdl-mode-ext-syntax-table)
2262 ;; remove `intangible' overlays
2263 (when (fboundp 'overlay-lists)
2264 (setq overlay-all-list (overlay-lists))
2265 (setq overlay-all-list
2266 (append (car overlay-all-list) (cdr overlay-all-list)))
2267 (while overlay-all-list
2268 (setq overlay (car overlay-all-list))
2269 (when (memq 'intangible (overlay-properties overlay))
2270 (setq overlay-intangible-list
2271 (cons overlay overlay-intangible-list))
2272 (overlay-put overlay 'intangible nil))
2273 (setq overlay-all-list (cdr overlay-all-list))))
2274 ;; execute BODY safely
2276 (condition-case info
2278 (error (eval restore-prog) ; restore environment on error
2279 (error (cadr info))))) ; pass error up
2280 ;; restore environment
2284 (defmacro vhdl-visit-file (file-name issue-error &rest body)
2285 "Visit file FILE-NAME and execute BODY."
2286 `(if (null ,file-name)
2288 (unless (file-directory-p ,file-name)
2289 (let ((source-buffer (current-buffer))
2290 (visiting-buffer (find-buffer-visiting ,file-name))
2292 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2294 (progn (set-buffer (create-file-buffer ,file-name))
2295 (setq file-opened t)
2296 (vhdl-insert-file-contents ,file-name)
2297 (modify-syntax-entry ?\- ". 12" (syntax-table))
2298 (modify-syntax-entry ?\n ">" (syntax-table))
2299 (modify-syntax-entry ?\^M ">" (syntax-table))
2300 (modify-syntax-entry ?_ "w" (syntax-table))
2305 (when file-opened (kill-buffer (current-buffer)))
2306 (set-buffer source-buffer)
2307 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
2308 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2310 (condition-case info
2315 (when file-opened (kill-buffer (current-buffer)))
2316 (set-buffer source-buffer)
2317 (error (cadr info)))
2318 (vhdl-warning (cadr info))))))
2319 (when file-opened (kill-buffer (current-buffer)))
2320 (set-buffer source-buffer)))))
2322 (defun vhdl-insert-file-contents (filename)
2323 "Nicked from `insert-file-contents-literally', but allow coding system
2325 (let ((format-alist nil)
2326 (after-insert-file-functions nil)
2327 (jka-compr-compression-info-list nil))
2328 (insert-file-contents filename t)))
2330 (defun vhdl-sort-alist (alist)
2332 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2334 (defun vhdl-get-subdirs (directory)
2335 "Recursively get subdirectories of DIRECTORY."
2336 (let ((dir-list (list (file-name-as-directory directory)))
2338 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2340 (when (file-directory-p (car file-list))
2341 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2342 (setq file-list (cdr file-list)))
2345 (defun vhdl-aput (alist-symbol key &optional value)
2346 "As `aput', but delete key-value pair if VALUE is nil."
2348 (aput alist-symbol key value)
2349 (adelete alist-symbol key)))
2351 (defun vhdl-delete (elt list)
2352 "Delete by side effect the first occurrence of ELT as a member of LIST."
2353 (setq list (cons nil list))
2355 (while (and (cdr list1) (not (equal elt (cadr list1))))
2356 (setq list1 (cdr list1)))
2358 (setcdr list1 (cddr list1))))
2361 (defun vhdl-speedbar-refresh (&optional key)
2362 "Refresh directory or project with name KEY."
2363 (when (and (boundp 'speedbar-frame)
2364 (frame-live-p speedbar-frame))
2366 (last-frame (selected-frame)))
2369 (select-frame speedbar-frame)
2370 (when (save-excursion
2371 (goto-char (point-min))
2372 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2373 (goto-char (match-end 1))
2374 (speedbar-do-function-pointer)
2376 (speedbar-do-function-pointer)
2377 (message "Refreshing speedbar...done"))
2378 (select-frame last-frame)))))
2380 (defun vhdl-show-messages ()
2381 "Get *Messages* buffer to show recent messages."
2383 (display-buffer (if vhdl-xemacs " *Message-Log*" "*Messages*")))
2385 (defun vhdl-use-direct-instantiation ()
2386 "Return whether direct instantiation is used."
2387 (or (eq vhdl-use-direct-instantiation 'always)
2388 (and (eq vhdl-use-direct-instantiation 'standard)
2389 (not (vhdl-standard-p '87)))))
2391 (defun vhdl-max-marker (marker1 marker2)
2392 "Return larger marker."
2393 (if (> marker1 marker2) marker1 marker2))
2395 (defun vhdl-goto-marker (marker)
2396 "Goto marker in appropriate buffer."
2397 (when (markerp marker)
2398 (set-buffer (marker-buffer marker)))
2401 (defun vhdl-menu-split (list title)
2402 "Split menu LIST into several submenues, if number of
2403 elements > `vhdl-menu-max-size'."
2404 (if (> (length list) vhdl-menu-max-size)
2411 (setq sublist (cons (car remain) sublist))
2412 (setq remain (cdr remain))
2414 (if (= i vhdl-menu-max-size)
2416 (setq result (cons (cons (format "%s %s" title menuno)
2417 (nreverse sublist)) result))
2419 (setq menuno (+ menuno 1))
2420 (setq sublist '()))))
2422 (setq result (cons (cons (format "%s %s" title menuno)
2423 (nreverse sublist)) result)))
2428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2432 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2435 (defvar vhdl-template-map nil
2436 "Keymap for VHDL templates.")
2438 (defun vhdl-template-map-init ()
2439 "Initialize `vhdl-template-map'."
2440 (setq vhdl-template-map (make-sparse-keymap))
2441 ;; key bindings for VHDL templates
2442 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2443 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2444 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2445 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2446 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2447 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2448 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2449 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2450 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
2451 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2452 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2453 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2454 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2455 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2456 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2457 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2458 (define-key vhdl-template-map "el" 'vhdl-template-else)
2459 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2460 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2461 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2462 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2463 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2464 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2465 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2466 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2467 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2468 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2469 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2470 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2471 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2472 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2473 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2474 (define-key vhdl-template-map "li" 'vhdl-template-library)
2475 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2476 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2477 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2478 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2479 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2480 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2481 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2482 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2483 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2484 (define-key vhdl-template-map "po" 'vhdl-template-port)
2485 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2486 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2487 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2488 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2489 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2490 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2491 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2492 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2493 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2494 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2495 (define-key vhdl-template-map "us" 'vhdl-template-use)
2496 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2497 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2498 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2499 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2500 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2501 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2502 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2503 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2504 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2505 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2506 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2507 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2508 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2509 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2510 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2511 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2512 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2513 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2514 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2515 (when (vhdl-standard-p 'ams)
2516 (define-key vhdl-template-map "br" 'vhdl-template-break)
2517 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2518 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2519 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2520 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2521 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2522 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2523 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2524 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2525 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2526 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2528 (when (vhdl-standard-p 'math)
2529 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2530 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2533 ;; initialize template map for VHDL Mode
2534 (vhdl-template-map-init)
2536 (defun vhdl-function-name (prefix string &optional postfix)
2537 "Generate a Lisp function name.
2538 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2539 STRING are replaced by `-' and substrings are converted to lower case."
2540 (let ((name prefix))
2541 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2543 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2544 (setq string (substring string (match-beginning 2))))
2545 (when postfix (setq name (concat name "-" postfix)))
2548 (defvar vhdl-model-map nil
2549 "Keymap for VHDL models.")
2551 (defun vhdl-model-map-init ()
2552 "Initialize `vhdl-model-map'."
2553 (setq vhdl-model-map (make-sparse-keymap))
2554 ;; key bindings for VHDL models
2555 (let ((model-alist vhdl-model-alist) model)
2557 (setq model (car model-alist))
2558 (define-key vhdl-model-map (nth 2 model)
2559 (vhdl-function-name "vhdl-model" (nth 0 model)))
2560 (setq model-alist (cdr model-alist)))))
2562 ;; initialize user model map for VHDL Mode
2563 (vhdl-model-map-init)
2565 (defvar vhdl-mode-map nil
2566 "Keymap for VHDL Mode.")
2568 (defun vhdl-mode-map-init ()
2569 "Initialize `vhdl-mode-map'."
2570 (setq vhdl-mode-map (make-sparse-keymap))
2571 ;; template key bindings
2572 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2573 ;; model key bindings
2574 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
2575 ;; standard key bindings
2576 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2577 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2578 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2579 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2580 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2581 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2582 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2583 (unless vhdl-xemacs ; would override `M-backspace' in XEmacs
2584 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2585 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2586 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
2587 ;; backspace/delete key bindings
2588 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
2589 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2590 (define-key vhdl-mode-map [delete] 'delete-char)
2591 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
2592 ;; mode specific key bindings
2593 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2594 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2595 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2596 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2597 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2598 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2599 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
2600 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2601 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
2602 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
2603 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2604 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2605 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2606 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2607 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2608 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2609 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
2610 (if vhdl-xemacs ; `... C-g' not allowed in XEmacs
2611 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2612 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
2613 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
2614 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2615 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
2616 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2617 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2618 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2619 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2620 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2621 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2622 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2623 (define-key vhdl-mode-map "\C-c\C-c\C-n" 'vhdl-compose-new-component)
2624 (define-key vhdl-mode-map "\C-c\C-c\C-p" 'vhdl-compose-place-component)
2625 (define-key vhdl-mode-map "\C-c\C-c\C-w" 'vhdl-compose-wire-components)
2626 (define-key vhdl-mode-map "\C-c\C-c\C-k" 'vhdl-compose-components-package)
2627 (define-key vhdl-mode-map "\C-cc" 'vhdl-comment-uncomment-region)
2628 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2629 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
2630 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2631 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
2632 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
2633 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2634 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2635 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2636 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2637 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2638 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2639 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2640 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2641 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2642 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2643 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2644 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2645 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2646 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2647 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
2648 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2649 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2650 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2651 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2652 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2653 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2654 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2655 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2656 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
2657 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2658 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2659 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2660 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2661 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2662 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2663 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2664 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2665 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2666 (define-key vhdl-mode-map "\C-cf" 'vhdl-fontify-buffer)
2667 (define-key vhdl-mode-map "\C-cs" 'vhdl-statistics-buffer)
2668 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2669 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2670 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2671 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
2672 ;; insert commands bindings
2673 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
2674 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2675 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2676 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2677 ;; electric key bindings
2678 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2679 (if vhdl-intelligent-tab
2680 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab)
2681 ;; The default binding of TAB already calls `indent-according-to-mode'.
2682 ;; (define-key vhdl-mode-map "\t" 'indent-according-to-mode)
2684 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2685 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2686 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2687 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2688 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2689 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2690 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2691 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2692 (when (vhdl-standard-p 'ams)
2693 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2695 ;; initialize mode map for VHDL Mode
2696 (vhdl-mode-map-init)
2698 ;; define special minibuffer keymap for enabling word completion in minibuffer
2699 ;; (useful in template generator prompts)
2700 (defvar vhdl-minibuffer-local-map
2701 (let ((map (make-sparse-keymap)))
2702 (set-keymap-parent map minibuffer-local-map)
2703 (when vhdl-word-completion-in-minibuffer
2704 (define-key map "\t" 'vhdl-minibuffer-tab))
2706 "Keymap for minibuffer used in VHDL Mode.")
2708 ;; set up electric character functions to work with
2709 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2713 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2714 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2715 '(vhdl-electric-space
2717 vhdl-electric-return
2719 vhdl-electric-open-bracket
2720 vhdl-electric-close-bracket
2722 vhdl-electric-semicolon
2724 vhdl-electric-period
2725 vhdl-electric-equal))
2727 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2730 (defvar vhdl-mode-syntax-table nil
2731 "Syntax table used in `vhdl-mode' buffers.")
2733 (defvar vhdl-mode-ext-syntax-table nil
2734 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2736 (defun vhdl-mode-syntax-table-init ()
2737 "Initialize `vhdl-mode-syntax-table'."
2738 (setq vhdl-mode-syntax-table (make-syntax-table))
2739 ;; define punctuation
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)
2753 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2754 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2755 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2757 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2758 ;; define underscore
2759 (when vhdl-underscore-is-part-of-word
2760 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
2761 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2762 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2763 ;; and \n and \^M end a comment
2764 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2765 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2766 ;; define parentheses to match
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 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2771 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
2772 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2773 ;; extended syntax table including '_' (for simpler search regexps)
2774 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2775 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
2777 ;; initialize syntax table for VHDL Mode
2778 (vhdl-mode-syntax-table-init)
2780 (defvar vhdl-syntactic-context nil
2781 "Buffer local variable containing syntactic analysis list.")
2782 (make-variable-buffer-local 'vhdl-syntactic-context)
2784 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2785 ;; Abbrev ook bindings
2787 (defvar vhdl-mode-abbrev-table nil
2788 "Abbrev table to use in `vhdl-mode' buffers.")
2790 (defun vhdl-mode-abbrev-table-init ()
2791 "Initialize `vhdl-mode-abbrev-table'."
2792 (when vhdl-mode-abbrev-table (clear-abbrev-table vhdl-mode-abbrev-table))
2793 (define-abbrev-table 'vhdl-mode-abbrev-table
2795 (when (memq 'vhdl vhdl-electric-keywords)
2798 ("--" "" vhdl-template-display-comment-hook 0 t)
2799 ("abs" "" vhdl-template-default-hook 0 t)
2800 ("access" "" vhdl-template-default-hook 0 t)
2801 ("after" "" vhdl-template-default-hook 0 t)
2802 ("alias" "" vhdl-template-alias-hook 0 t)
2803 ("all" "" vhdl-template-default-hook 0 t)
2804 ("and" "" vhdl-template-default-hook 0 t)
2805 ("arch" "" vhdl-template-architecture-hook 0 t)
2806 ("architecture" "" vhdl-template-architecture-hook 0 t)
2807 ("array" "" vhdl-template-default-hook 0 t)
2808 ("assert" "" vhdl-template-assert-hook 0 t)
2809 ("attr" "" vhdl-template-attribute-hook 0 t)
2810 ("attribute" "" vhdl-template-attribute-hook 0 t)
2811 ("begin" "" vhdl-template-default-indent-hook 0 t)
2812 ("block" "" vhdl-template-block-hook 0 t)
2813 ("body" "" vhdl-template-default-hook 0 t)
2814 ("buffer" "" vhdl-template-default-hook 0 t)
2815 ("bus" "" vhdl-template-default-hook 0 t)
2816 ("case" "" vhdl-template-case-hook 0 t)
2817 ("comp" "" vhdl-template-component-hook 0 t)
2818 ("component" "" vhdl-template-component-hook 0 t)
2819 ("cond" "" vhdl-template-conditional-signal-asst-hook 0 t)
2820 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0 t)
2821 ("conf" "" vhdl-template-configuration-hook 0 t)
2822 ("configuration" "" vhdl-template-configuration-hook 0 t)
2823 ("cons" "" vhdl-template-constant-hook 0 t)
2824 ("constant" "" vhdl-template-constant-hook 0 t)
2825 ("disconnect" "" vhdl-template-disconnect-hook 0 t)
2826 ("downto" "" vhdl-template-default-hook 0 t)
2827 ("else" "" vhdl-template-else-hook 0 t)
2828 ("elseif" "" vhdl-template-elsif-hook 0 t)
2829 ("elsif" "" vhdl-template-elsif-hook 0 t)
2830 ("end" "" vhdl-template-default-indent-hook 0 t)
2831 ("entity" "" vhdl-template-entity-hook 0 t)
2832 ("exit" "" vhdl-template-exit-hook 0 t)
2833 ("file" "" vhdl-template-file-hook 0 t)
2834 ("for" "" vhdl-template-for-hook 0 t)
2835 ("func" "" vhdl-template-function-hook 0 t)
2836 ("function" "" vhdl-template-function-hook 0 t)
2837 ("generic" "" vhdl-template-generic-hook 0 t)
2838 ("group" "" vhdl-template-group-hook 0 t)
2839 ("guarded" "" vhdl-template-default-hook 0 t)
2840 ("if" "" vhdl-template-if-hook 0 t)
2841 ("impure" "" vhdl-template-default-hook 0 t)
2842 ("in" "" vhdl-template-default-hook 0 t)
2843 ("inertial" "" vhdl-template-default-hook 0 t)
2844 ("inout" "" vhdl-template-default-hook 0 t)
2845 ("inst" "" vhdl-template-instance-hook 0 t)
2846 ("instance" "" vhdl-template-instance-hook 0 t)
2847 ("is" "" vhdl-template-default-hook 0 t)
2848 ("label" "" vhdl-template-default-hook 0 t)
2849 ("library" "" vhdl-template-library-hook 0 t)
2850 ("linkage" "" vhdl-template-default-hook 0 t)
2851 ("literal" "" vhdl-template-default-hook 0 t)
2852 ("loop" "" vhdl-template-bare-loop-hook 0 t)
2853 ("map" "" vhdl-template-map-hook 0 t)
2854 ("mod" "" vhdl-template-default-hook 0 t)
2855 ("nand" "" vhdl-template-default-hook 0 t)
2856 ("new" "" vhdl-template-default-hook 0 t)
2857 ("next" "" vhdl-template-next-hook 0 t)
2858 ("nor" "" vhdl-template-default-hook 0 t)
2859 ("not" "" vhdl-template-default-hook 0 t)
2860 ("null" "" vhdl-template-default-hook 0 t)
2861 ("of" "" vhdl-template-default-hook 0 t)
2862 ("on" "" vhdl-template-default-hook 0 t)
2863 ("open" "" vhdl-template-default-hook 0 t)
2864 ("or" "" vhdl-template-default-hook 0 t)
2865 ("others" "" vhdl-template-others-hook 0 t)
2866 ("out" "" vhdl-template-default-hook 0 t)
2867 ("pack" "" vhdl-template-package-hook 0 t)
2868 ("package" "" vhdl-template-package-hook 0 t)
2869 ("port" "" vhdl-template-port-hook 0 t)
2870 ("postponed" "" vhdl-template-default-hook 0 t)
2871 ("procedure" "" vhdl-template-procedure-hook 0 t)
2872 ("process" "" vhdl-template-process-hook 0 t)
2873 ("pure" "" vhdl-template-default-hook 0 t)
2874 ("range" "" vhdl-template-default-hook 0 t)
2875 ("record" "" vhdl-template-default-hook 0 t)
2876 ("register" "" vhdl-template-default-hook 0 t)
2877 ("reject" "" vhdl-template-default-hook 0 t)
2878 ("rem" "" vhdl-template-default-hook 0 t)
2879 ("report" "" vhdl-template-report-hook 0 t)
2880 ("return" "" vhdl-template-return-hook 0 t)
2881 ("rol" "" vhdl-template-default-hook 0 t)
2882 ("ror" "" vhdl-template-default-hook 0 t)
2883 ("select" "" vhdl-template-selected-signal-asst-hook 0 t)
2884 ("severity" "" vhdl-template-default-hook 0 t)
2885 ("shared" "" vhdl-template-default-hook 0 t)
2886 ("sig" "" vhdl-template-signal-hook 0 t)
2887 ("signal" "" vhdl-template-signal-hook 0 t)
2888 ("sla" "" vhdl-template-default-hook 0 t)
2889 ("sll" "" vhdl-template-default-hook 0 t)
2890 ("sra" "" vhdl-template-default-hook 0 t)
2891 ("srl" "" vhdl-template-default-hook 0 t)
2892 ("subtype" "" vhdl-template-subtype-hook 0 t)
2893 ("then" "" vhdl-template-default-hook 0 t)
2894 ("to" "" vhdl-template-default-hook 0 t)
2895 ("transport" "" vhdl-template-default-hook 0 t)
2896 ("type" "" vhdl-template-type-hook 0 t)
2897 ("unaffected" "" vhdl-template-default-hook 0 t)
2898 ("units" "" vhdl-template-default-hook 0 t)
2899 ("until" "" vhdl-template-default-hook 0 t)
2900 ("use" "" vhdl-template-use-hook 0 t)
2901 ("var" "" vhdl-template-variable-hook 0 t)
2902 ("variable" "" vhdl-template-variable-hook 0 t)
2903 ("wait" "" vhdl-template-wait-hook 0 t)
2904 ("when" "" vhdl-template-when-hook 0 t)
2905 ("while" "" vhdl-template-while-loop-hook 0 t)
2906 ("with" "" vhdl-template-with-hook 0 t)
2907 ("xnor" "" vhdl-template-default-hook 0 t)
2908 ("xor" "" vhdl-template-default-hook 0 t)
2910 ;; VHDL-AMS keywords
2911 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2913 ("across" "" vhdl-template-default-hook 0 t)
2914 ("break" "" vhdl-template-break-hook 0 t)
2915 ("limit" "" vhdl-template-limit-hook 0 t)
2916 ("nature" "" vhdl-template-nature-hook 0 t)
2917 ("noise" "" vhdl-template-default-hook 0 t)
2918 ("procedural" "" vhdl-template-procedural-hook 0 t)
2919 ("quantity" "" vhdl-template-quantity-hook 0 t)
2920 ("reference" "" vhdl-template-default-hook 0 t)
2921 ("spectrum" "" vhdl-template-default-hook 0 t)
2922 ("subnature" "" vhdl-template-subnature-hook 0 t)
2923 ("terminal" "" vhdl-template-terminal-hook 0 t)
2924 ("through" "" vhdl-template-default-hook 0 t)
2925 ("tolerance" "" vhdl-template-default-hook 0 t)
2927 ;; user model keywords
2928 (when (memq 'user vhdl-electric-keywords)
2929 (let ((alist vhdl-model-alist)
2930 abbrev-list keyword)
2932 (setq keyword (nth 3 (car alist)))
2933 (unless (equal keyword "")
2935 (cons (list keyword ""
2937 "vhdl-model" (nth 0 (car alist)) "hook") 0 t)
2939 (setq alist (cdr alist)))
2942 ;; initialize abbrev table for VHDL Mode
2943 (vhdl-mode-abbrev-table-init)
2945 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2946 ;; Template completion lists
2948 (defvar vhdl-template-construct-alist nil
2949 "List of built-in construct templates.")
2951 (defun vhdl-template-construct-alist-init ()
2952 "Initialize `vhdl-template-construct-alist'."
2954 vhdl-template-construct-alist
2957 ("alias declaration" vhdl-template-alias)
2958 ("architecture body" vhdl-template-architecture)
2959 ("assertion" vhdl-template-assert)
2960 ("attribute declaration" vhdl-template-attribute-decl)
2961 ("attribute specification" vhdl-template-attribute-spec)
2962 ("block configuration" vhdl-template-block-configuration)
2963 ("block statement" vhdl-template-block)
2964 ("case statement" vhdl-template-case-is)
2965 ("component configuration" vhdl-template-component-conf)
2966 ("component declaration" vhdl-template-component-decl)
2967 ("component instantiation statement" vhdl-template-component-inst)
2968 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
2969 ("configuration declaration" vhdl-template-configuration-decl)
2970 ("configuration specification" vhdl-template-configuration-spec)
2971 ("constant declaration" vhdl-template-constant)
2972 ("disconnection specification" vhdl-template-disconnect)
2973 ("entity declaration" vhdl-template-entity)
2974 ("exit statement" vhdl-template-exit)
2975 ("file declaration" vhdl-template-file)
2976 ("generate statement" vhdl-template-generate)
2977 ("generic clause" vhdl-template-generic)
2978 ("group declaration" vhdl-template-group-decl)
2979 ("group template declaration" vhdl-template-group-template)
2980 ("if statement" vhdl-template-if-then)
2981 ("library clause" vhdl-template-library)
2982 ("loop statement" vhdl-template-loop)
2983 ("next statement" vhdl-template-next)
2984 ("package declaration" vhdl-template-package-decl)
2985 ("package body" vhdl-template-package-body)
2986 ("port clause" vhdl-template-port)
2987 ("process statement" vhdl-template-process)
2988 ("report statement" vhdl-template-report)
2989 ("return statement" vhdl-template-return)
2990 ("selected signal assignment" vhdl-template-selected-signal-asst)
2991 ("signal declaration" vhdl-template-signal)
2992 ("subprogram declaration" vhdl-template-subprogram-decl)
2993 ("subprogram body" vhdl-template-subprogram-body)
2994 ("subtype declaration" vhdl-template-subtype)
2995 ("type declaration" vhdl-template-type)
2996 ("use clause" vhdl-template-use)
2997 ("variable declaration" vhdl-template-variable)
2998 ("wait statement" vhdl-template-wait)
3000 (when (vhdl-standard-p 'ams)
3002 ("break statement" vhdl-template-break)
3003 ("nature declaration" vhdl-template-nature)
3004 ("quantity declaration" vhdl-template-quantity)
3005 ("simultaneous case statement" vhdl-template-case-use)
3006 ("simultaneous if statement" vhdl-template-if-use)
3007 ("simultaneous procedural statement" vhdl-template-procedural)
3008 ("step limit specification" vhdl-template-limit)
3009 ("subnature declaration" vhdl-template-subnature)
3010 ("terminal declaration" vhdl-template-terminal)
3013 ;; initialize for VHDL Mode
3014 (vhdl-template-construct-alist-init)
3016 (defvar vhdl-template-package-alist nil
3017 "List of built-in package templates.")
3019 (defun vhdl-template-package-alist-init ()
3020 "Initialize `vhdl-template-package-alist'."
3022 vhdl-template-package-alist
3025 ("numeric_bit" vhdl-template-package-numeric-bit)
3026 ("numeric_std" vhdl-template-package-numeric-std)
3027 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3028 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3029 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3030 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3031 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3032 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3033 ("textio" vhdl-template-package-textio)
3035 (when (vhdl-standard-p 'math)
3037 ("math_complex" vhdl-template-package-math-complex)
3038 ("math_real" vhdl-template-package-math-real)
3041 ;; initialize for VHDL Mode
3042 (vhdl-template-package-alist-init)
3044 (defvar vhdl-template-directive-alist
3046 ("translate_on" vhdl-template-directive-translate-on)
3047 ("translate_off" vhdl-template-directive-translate-off)
3048 ("synthesis_on" vhdl-template-directive-synthesis-on)
3049 ("synthesis_off" vhdl-template-directive-synthesis-off)
3051 "List of built-in directive templates.")
3054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3058 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3059 ;; VHDL menu (using `easy-menu.el')
3061 (defun vhdl-customize ()
3062 "Call the customize function with `vhdl' as argument."
3064 (customize-browse 'vhdl))
3066 (defun vhdl-create-mode-menu ()
3067 "Create VHDL Mode menu."
3071 ["None" (vhdl-set-project "")
3072 :style radio :selected (null vhdl-project)]
3074 ;; add menu entries for defined projects
3075 (let ((project-alist vhdl-project-alist) menu-list name)
3076 (while project-alist
3077 (setq name (caar project-alist))
3079 (cons `[,name (vhdl-set-project ,name)
3080 :style radio :selected (equal ,name vhdl-project)]
3082 (setq project-alist (cdr project-alist)))
3084 (if vhdl-project-sort
3086 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3087 (nreverse menu-list)))
3088 (vhdl-menu-split menu-list "Project"))
3090 ["Select Project..." vhdl-set-project t]
3092 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3093 ["Import Project..." vhdl-import-project
3094 :keys "C-c C-p C-m" :active t]
3095 ["Export Project" vhdl-export-project vhdl-project]
3097 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
3100 ["Compile Buffer" vhdl-compile t]
3101 ["Stop Compilation" kill-compilation t]
3103 ["Make" vhdl-make t]
3104 ["Generate Makefile" vhdl-generate-makefile t]
3106 ["Next Error" next-error t]
3107 ["Previous Error" previous-error t]
3108 ["First Error" first-error t]
3112 ;; add menu entries for defined compilers
3113 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3115 (setq name (caar comp-alist))
3117 (cons `[,name (setq vhdl-compiler ,name)
3118 :style radio :selected (equal ,name vhdl-compiler)]
3120 (setq comp-alist (cdr comp-alist)))
3121 (setq menu-list (nreverse menu-list))
3122 (vhdl-menu-split menu-list "Compiler"))
3124 ["Select Compiler..." vhdl-set-compiler t]
3126 ["Customize Compiler..."
3127 (customize-option 'vhdl-compiler-alist) t])))
3132 ["Alias" vhdl-template-alias t]
3133 ["Architecture" vhdl-template-architecture t]
3134 ["Assert" vhdl-template-assert t]
3135 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3136 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3137 ["Block" vhdl-template-block t]
3138 ["Case" vhdl-template-case-is t]
3139 ["Component (Decl)" vhdl-template-component-decl t]
3140 ["(Component) Instance" vhdl-template-component-inst t]
3141 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3142 ["Configuration (Block)" vhdl-template-block-configuration t]
3143 ["Configuration (Comp)" vhdl-template-component-conf t]
3144 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3145 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3146 ["Constant" vhdl-template-constant t]
3147 ["Disconnect" vhdl-template-disconnect t]
3148 ["Else" vhdl-template-else t]
3149 ["Elsif" vhdl-template-elsif t]
3150 ["Entity" vhdl-template-entity t]
3151 ["Exit" vhdl-template-exit t]
3152 ["File" vhdl-template-file t]
3153 ["For (Generate)" vhdl-template-for-generate t]
3154 ["For (Loop)" vhdl-template-for-loop t]
3155 ["Function (Body)" vhdl-template-function-body t]
3156 ["Function (Decl)" vhdl-template-function-decl t]
3157 ["Generic" vhdl-template-generic t]
3158 ["Group (Decl)" vhdl-template-group-decl t]
3159 ["Group (Template)" vhdl-template-group-template t])
3161 ["If (Generate)" vhdl-template-if-generate t]
3162 ["If (Then)" vhdl-template-if-then t]
3163 ["Library" vhdl-template-library t]
3164 ["Loop" vhdl-template-bare-loop t]
3165 ["Map" vhdl-template-map t]
3166 ["Next" vhdl-template-next t]
3167 ["Others (Aggregate)" vhdl-template-others t]
3168 ["Package (Decl)" vhdl-template-package-decl t]
3169 ["Package (Body)" vhdl-template-package-body t]
3170 ["Port" vhdl-template-port t]
3171 ["Procedure (Body)" vhdl-template-procedure-body t]
3172 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3173 ["Process (Comb)" vhdl-template-process-comb t]
3174 ["Process (Seq)" vhdl-template-process-seq t]
3175 ["Report" vhdl-template-report t]
3176 ["Return" vhdl-template-return t]
3177 ["Select" vhdl-template-selected-signal-asst t]
3178 ["Signal" vhdl-template-signal t]
3179 ["Subtype" vhdl-template-subtype t]
3180 ["Type" vhdl-template-type t]
3181 ["Use" vhdl-template-use t]
3182 ["Variable" vhdl-template-variable t]
3183 ["Wait" vhdl-template-wait t]
3184 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3185 ["When" vhdl-template-when t]
3186 ["While (Loop)" vhdl-template-while-loop t]
3187 ["With" vhdl-template-with t]))
3188 (when (vhdl-standard-p 'ams)
3189 '(("VHDL-AMS Construct"
3190 ["Break" vhdl-template-break t]
3191 ["Case (Use)" vhdl-template-case-use t]
3192 ["If (Use)" vhdl-template-if-use t]
3193 ["Limit" vhdl-template-limit t]
3194 ["Nature" vhdl-template-nature t]
3195 ["Procedural" vhdl-template-procedural t]
3196 ["Quantity (Free)" vhdl-template-quantity-free t]
3197 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3198 ["Quantity (Source)" vhdl-template-quantity-source t]
3199 ["Subnature" vhdl-template-subnature t]
3200 ["Terminal" vhdl-template-terminal t])))
3201 '(["Insert Construct..." vhdl-template-insert-construct
3202 :keys "C-c C-i C-t"]
3207 (when (vhdl-standard-p 'math)
3208 '(["math_complex" vhdl-template-package-math-complex t]
3209 ["math_real" vhdl-template-package-math-real t]))
3210 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3211 ["numeric_std" vhdl-template-package-numeric-std t]
3212 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3213 ["textio" vhdl-template-package-textio t]
3215 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3216 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3217 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3218 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3219 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3221 ["Insert Package..." vhdl-template-insert-package
3222 :keys "C-c C-i C-p"])))
3224 ["translate_on" vhdl-template-directive-translate-on t]
3225 ["translate_off" vhdl-template-directive-translate-off t]
3226 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3227 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3229 ["Insert Directive..." vhdl-template-insert-directive
3230 :keys "C-c C-i C-d"])
3232 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3233 ["Insert Footer" vhdl-template-footer t]
3234 ["Insert Date" vhdl-template-insert-date t]
3235 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
3237 ["Query Next Prompt" vhdl-template-search-prompt t]))
3240 ;; add menu entries for defined models
3241 (let ((model-alist vhdl-model-alist) menu-list model)
3243 (setq model (car model-alist))
3248 (vhdl-function-name "vhdl-model" (nth 0 model))
3249 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3251 (setq model-alist (cdr model-alist)))
3252 (setq menu-list (nreverse menu-list))
3253 (vhdl-menu-split menu-list "Model"))
3255 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3256 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3258 ["Copy" vhdl-port-copy t]
3260 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3261 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3262 ["Paste As Instance" vhdl-port-paste-instance
3263 :keys "C-c C-p C-i" :active vhdl-port-list]
3264 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3265 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3266 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3267 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
3269 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3271 ["Flatten" vhdl-port-flatten
3272 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3273 ["Reverse Direction" vhdl-port-reverse-direction
3274 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3276 ["New Component" vhdl-compose-new-component t]
3277 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3278 ["Wire Components" vhdl-compose-wire-components t]
3280 ["Generate Components Package" vhdl-compose-components-package t])
3282 ["Copy" vhdl-subprog-copy t]
3284 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3285 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3286 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3288 ["Flatten" vhdl-subprog-flatten
3289 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3292 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3294 ["Insert Inline Comment" vhdl-comment-append-inline t]
3295 ["Insert Horizontal Line" vhdl-comment-display-line t]
3296 ["Insert Display Comment" vhdl-comment-display t]
3298 ["Fill Comment" fill-paragraph t]
3299 ["Fill Comment Region" fill-region (mark)]
3300 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3301 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3303 ["Kill" vhdl-line-kill t]
3304 ["Copy" vhdl-line-copy t]
3305 ["Yank" vhdl-line-yank t]
3306 ["Expand" vhdl-line-expand t]
3308 ["Transpose Next" vhdl-line-transpose-next t]
3309 ["Transpose Prev" vhdl-line-transpose-previous t]
3310 ["Open" vhdl-line-open t]
3311 ["Join" vhdl-delete-indentation t]
3313 ["Goto" goto-line t]
3314 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3316 ["Forward Statement" vhdl-end-of-statement t]
3317 ["Backward Statement" vhdl-beginning-of-statement t]
3318 ["Forward Expression" vhdl-forward-sexp t]
3319 ["Backward Expression" vhdl-backward-sexp t]
3320 ["Forward Same Indent" vhdl-forward-same-indent t]
3321 ["Backward Same Indent" vhdl-backward-same-indent t]
3322 ["Forward Function" vhdl-end-of-defun t]
3323 ["Backward Function" vhdl-beginning-of-defun t]
3324 ["Mark Function" vhdl-mark-defun t])
3327 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3328 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
3329 ["Region" vhdl-indent-region (mark)]
3330 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3332 ["Group" vhdl-align-group t]
3333 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3334 ["List" vhdl-align-list t]
3335 ["Declarations" vhdl-align-declarations t]
3336 ["Region" vhdl-align-region (mark)]
3337 ["Buffer" vhdl-align-buffer t]
3339 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3340 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3341 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3343 ["List" vhdl-fill-list t]
3344 ["Group" vhdl-fill-group t]
3345 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3346 ["Region" vhdl-fill-region (mark)])
3348 ["Region" vhdl-beautify-region (mark)]
3349 ["Buffer" vhdl-beautify-buffer t])
3351 ["Generic/Port Clause" vhdl-fix-clause t]
3353 ["Case Region" vhdl-fix-case-region (mark)]
3354 ["Case Buffer" vhdl-fix-case-buffer t]
3356 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3357 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3359 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3361 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3362 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3364 ["Fontify Buffer" vhdl-fontify-buffer t]
3365 ["Statistics Buffer" vhdl-statistics-buffer t]
3366 ["Show Messages" vhdl-show-messages t]
3367 ["Syntactic Info" vhdl-show-syntactic-information t]
3369 ["Speedbar" vhdl-speedbar t]
3370 ["Hide/Show" vhdl-hs-minor-mode t]
3373 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3374 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
3375 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3376 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3377 ["Version" vhdl-version t]
3378 ["Bug Report..." vhdl-submit-bug-report t]
3383 (progn (customize-set-variable 'vhdl-electric-mode
3384 (not vhdl-electric-mode))
3385 (vhdl-mode-line-update))
3386 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3388 (progn (customize-set-variable 'vhdl-stutter-mode
3389 (not vhdl-stutter-mode))
3390 (vhdl-mode-line-update))
3391 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3393 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3394 (not vhdl-indent-tabs-mode))
3395 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3396 :style toggle :selected vhdl-indent-tabs-mode]
3398 ["Customize Group..." (customize-group 'vhdl-mode) t])
3400 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3402 '("Selected Project at Startup"
3403 ["None" (progn (customize-set-variable 'vhdl-project nil)
3404 (vhdl-set-project ""))
3405 :style radio :selected (null vhdl-project)]
3407 ;; add menu entries for defined projects
3408 (let ((project-alist vhdl-project-alist) menu-list name)
3409 (while project-alist
3410 (setq name (caar project-alist))
3412 (cons `[,name (progn (customize-set-variable
3413 'vhdl-project ,name)
3414 (vhdl-set-project ,name))
3415 :style radio :selected (equal ,name vhdl-project)]
3417 (setq project-alist (cdr project-alist)))
3418 (setq menu-list (nreverse menu-list))
3419 (vhdl-menu-split menu-list "Project")))
3420 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3421 ("Auto Load Setup File"
3423 (customize-set-variable 'vhdl-project-auto-load
3424 (if (memq 'startup vhdl-project-auto-load)
3425 (delq 'startup vhdl-project-auto-load)
3426 (cons 'startup vhdl-project-auto-load)))
3427 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3429 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3430 :style toggle :selected vhdl-project-sort]
3432 ["Customize Group..." (customize-group 'vhdl-project) t])
3434 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3436 '("Selected Compiler at Startup")
3437 ;; add menu entries for defined compilers
3438 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3440 (setq name (caar comp-alist))
3442 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3443 :style radio :selected (equal ,name vhdl-compiler)]
3445 (setq comp-alist (cdr comp-alist)))
3446 (setq menu-list (nreverse menu-list))
3447 (vhdl-menu-split menu-list "Compler")))
3448 ["Use Local Error Regexp"
3449 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3450 (not vhdl-compile-use-local-error-regexp))
3451 :style toggle :selected vhdl-compile-use-local-error-regexp]
3452 ["Makefile Generation Hook..."
3453 (customize-option 'vhdl-makefile-generation-hook) t]
3454 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3456 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3460 (progn (customize-set-variable 'vhdl-standard
3461 (list '87 (cadr vhdl-standard)))
3462 (vhdl-activate-customizations))
3463 :style radio :selected (eq '87 (car vhdl-standard))]
3465 (progn (customize-set-variable 'vhdl-standard
3466 (list '93 (cadr vhdl-standard)))
3467 (vhdl-activate-customizations))
3468 :style radio :selected (eq '93 (car vhdl-standard))]
3471 (progn (customize-set-variable
3472 'vhdl-standard (list (car vhdl-standard)
3473 (if (memq 'ams (cadr vhdl-standard))
3474 (delq 'ams (cadr vhdl-standard))
3475 (cons 'ams (cadr vhdl-standard)))))
3476 (vhdl-activate-customizations))
3477 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3479 (progn (customize-set-variable
3480 'vhdl-standard (list (car vhdl-standard)
3481 (if (memq 'math (cadr vhdl-standard))
3482 (delq 'math (cadr vhdl-standard))
3483 (cons 'math (cadr vhdl-standard)))))
3484 (vhdl-activate-customizations))
3485 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3486 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3487 ["Upper Case Keywords"
3488 (customize-set-variable 'vhdl-upper-case-keywords
3489 (not vhdl-upper-case-keywords))
3490 :style toggle :selected vhdl-upper-case-keywords]
3492 (customize-set-variable 'vhdl-upper-case-types
3493 (not vhdl-upper-case-types))
3494 :style toggle :selected vhdl-upper-case-types]
3495 ["Upper Case Attributes"
3496 (customize-set-variable 'vhdl-upper-case-attributes
3497 (not vhdl-upper-case-attributes))
3498 :style toggle :selected vhdl-upper-case-attributes]
3499 ["Upper Case Enumeration Values"
3500 (customize-set-variable 'vhdl-upper-case-enum-values
3501 (not vhdl-upper-case-enum-values))
3502 :style toggle :selected vhdl-upper-case-enum-values]
3503 ["Upper Case Constants"
3504 (customize-set-variable 'vhdl-upper-case-constants
3505 (not vhdl-upper-case-constants))
3506 :style toggle :selected vhdl-upper-case-constants]
3507 ("Use Direct Instantiation"
3509 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3510 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3512 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3513 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3515 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3516 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3518 ["Customize Group..." (customize-group 'vhdl-style) t])
3520 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3521 ["Architecture File Name..."
3522 (customize-option 'vhdl-architecture-file-name) t]
3523 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3526 (customize-set-variable 'vhdl-file-name-case 'identity)
3527 :style radio :selected (eq 'identity vhdl-file-name-case)]
3529 (customize-set-variable 'vhdl-file-name-case 'downcase)
3530 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3532 (customize-set-variable 'vhdl-file-name-case 'upcase)
3533 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3535 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3536 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3538 ["Customize Group..." (customize-group 'vhdl-naming) t])
3540 ("Electric Keywords"
3542 (customize-set-variable 'vhdl-electric-keywords
3543 (if (memq 'vhdl vhdl-electric-keywords)
3544 (delq 'vhdl vhdl-electric-keywords)
3545 (cons 'vhdl vhdl-electric-keywords)))
3546 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3547 ["User Model Keywords"
3548 (customize-set-variable 'vhdl-electric-keywords
3549 (if (memq 'user vhdl-electric-keywords)
3550 (delq 'user vhdl-electric-keywords)
3551 (cons 'user vhdl-electric-keywords)))
3552 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3553 ("Insert Optional Labels"
3555 (customize-set-variable 'vhdl-optional-labels 'none)
3556 :style radio :selected (eq 'none vhdl-optional-labels)]
3558 (customize-set-variable 'vhdl-optional-labels 'process)
3559 :style radio :selected (eq 'process vhdl-optional-labels)]
3561 (customize-set-variable 'vhdl-optional-labels 'all)
3562 :style radio :selected (eq 'all vhdl-optional-labels)])
3563 ("Insert Empty Lines"
3565 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3566 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3567 ["Design Units Only"
3568 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3569 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3571 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3572 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3573 ["Argument List Indent"
3574 (customize-set-variable 'vhdl-argument-list-indent
3575 (not vhdl-argument-list-indent))
3576 :style toggle :selected vhdl-argument-list-indent]
3577 ["Association List with Formals"
3578 (customize-set-variable 'vhdl-association-list-with-formals
3579 (not vhdl-association-list-with-formals))
3580 :style toggle :selected vhdl-association-list-with-formals]
3581 ["Conditions in Parenthesis"
3582 (customize-set-variable 'vhdl-conditions-in-parenthesis
3583 (not vhdl-conditions-in-parenthesis))
3584 :style toggle :selected vhdl-conditions-in-parenthesis]
3585 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3586 ["One String..." (customize-option 'vhdl-one-string) t]
3588 ["Header String..." (customize-option 'vhdl-file-header) t]
3589 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3590 ["Company Name..." (customize-option 'vhdl-company-name) t]
3591 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3592 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3593 ["Date Format..." (customize-option 'vhdl-date-format) t]
3594 ["Modify Date Prefix String..."
3595 (customize-option 'vhdl-modify-date-prefix-string) t]
3596 ["Modify Date on Saving"
3597 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3598 (not vhdl-modify-date-on-saving))
3599 (vhdl-activate-customizations))
3600 :style toggle :selected vhdl-modify-date-on-saving])
3601 ("Sequential Process"
3604 (customize-set-variable 'vhdl-reset-kind 'none)
3605 :style radio :selected (eq 'none vhdl-reset-kind)]
3607 (customize-set-variable 'vhdl-reset-kind 'sync)
3608 :style radio :selected (eq 'sync vhdl-reset-kind)]
3610 (customize-set-variable 'vhdl-reset-kind 'async)
3611 :style radio :selected (eq 'async vhdl-reset-kind)])
3612 ["Reset is Active High"
3613 (customize-set-variable 'vhdl-reset-active-high
3614 (not vhdl-reset-active-high))
3615 :style toggle :selected vhdl-reset-active-high]
3616 ["Use Rising Clock Edge"
3617 (customize-set-variable 'vhdl-clock-rising-edge
3618 (not vhdl-clock-rising-edge))
3619 :style toggle :selected vhdl-clock-rising-edge]
3620 ("Clock Edge Condition"
3622 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3623 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3624 ["Function \"rising_edge\""
3625 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3626 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3627 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3628 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3630 ["Customize Group..." (customize-group 'vhdl-template) t])
3632 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3634 ["Include Port Comments"
3635 (customize-set-variable 'vhdl-include-port-comments
3636 (not vhdl-include-port-comments))
3637 :style toggle :selected vhdl-include-port-comments]
3638 ["Include Direction Comments"
3639 (customize-set-variable 'vhdl-include-direction-comments
3640 (not vhdl-include-direction-comments))
3641 :style toggle :selected vhdl-include-direction-comments]
3642 ["Include Type Comments"
3643 (customize-set-variable 'vhdl-include-type-comments
3644 (not vhdl-include-type-comments))
3645 :style toggle :selected vhdl-include-type-comments]
3646 ("Include Group Comments"
3648 (customize-set-variable 'vhdl-include-group-comments 'never)
3649 :style radio :selected (eq 'never vhdl-include-group-comments)]
3651 (customize-set-variable 'vhdl-include-group-comments 'decl)
3652 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3654 (customize-set-variable 'vhdl-include-group-comments 'always)
3655 :style radio :selected (eq 'always vhdl-include-group-comments)])
3656 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3657 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3659 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3660 ["Architecture Name..."
3661 (customize-option 'vhdl-testbench-architecture-name) t]
3662 ["Configuration Name..."
3663 (customize-option 'vhdl-testbench-configuration-name) t]
3664 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3666 (customize-set-variable 'vhdl-testbench-include-header
3667 (not vhdl-testbench-include-header))
3668 :style toggle :selected vhdl-testbench-include-header]
3669 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3670 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3671 ["Initialize Signals"
3672 (customize-set-variable 'vhdl-testbench-initialize-signals
3673 (not vhdl-testbench-initialize-signals))
3674 :style toggle :selected vhdl-testbench-initialize-signals]
3675 ["Include Library Clause"
3676 (customize-set-variable 'vhdl-testbench-include-library
3677 (not vhdl-testbench-include-library))
3678 :style toggle :selected vhdl-testbench-include-library]
3679 ["Include Configuration"
3680 (customize-set-variable 'vhdl-testbench-include-configuration
3681 (not vhdl-testbench-include-configuration))
3682 :style toggle :selected vhdl-testbench-include-configuration]
3685 (customize-set-variable 'vhdl-testbench-create-files 'none)
3686 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3688 (customize-set-variable 'vhdl-testbench-create-files 'single)
3689 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3691 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3692 :style radio :selected (eq 'separate vhdl-testbench-create-files)]))
3694 ["Customize Group..." (customize-group 'vhdl-port) t])
3698 (customize-set-variable 'vhdl-compose-create-files 'none)
3699 :style radio :selected (eq 'none vhdl-compose-create-files)]
3701 (customize-set-variable 'vhdl-compose-create-files 'single)
3702 :style radio :selected (eq 'single vhdl-compose-create-files)]
3704 (customize-set-variable 'vhdl-compose-create-files 'separate)
3705 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3707 (customize-set-variable 'vhdl-compose-include-header
3708 (not vhdl-compose-include-header))
3709 :style toggle :selected vhdl-compose-include-header]
3710 ["Architecture Name..."
3711 (customize-option 'vhdl-compose-architecture-name) t]
3712 ["Components Package Name..."
3713 (customize-option 'vhdl-components-package-name) t]
3714 ["Use Components Package"
3715 (customize-set-variable 'vhdl-use-components-package
3716 (not vhdl-use-components-package))
3717 :style toggle :selected vhdl-use-components-package]
3719 ["Customize Group..." (customize-group 'vhdl-compose) t])
3721 ["Self Insert Comments"
3722 (customize-set-variable 'vhdl-self-insert-comments
3723 (not vhdl-self-insert-comments))
3724 :style toggle :selected vhdl-self-insert-comments]
3725 ["Prompt for Comments"
3726 (customize-set-variable 'vhdl-prompt-for-comments
3727 (not vhdl-prompt-for-comments))
3728 :style toggle :selected vhdl-prompt-for-comments]
3729 ["Inline Comment Column..."
3730 (customize-option 'vhdl-inline-comment-column) t]
3731 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3733 ["Customize Group..." (customize-group 'vhdl-comment) t])
3735 ["Auto Align Templates"
3736 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3737 :style toggle :selected vhdl-auto-align]
3738 ["Align Line Groups"
3739 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3740 :style toggle :selected vhdl-align-groups]
3741 ["Group Separation String..."
3742 (customize-set-variable 'vhdl-align-group-separate) t]
3743 ["Align Lines with Same Indent"
3744 (customize-set-variable 'vhdl-align-same-indent
3745 (not vhdl-align-same-indent))
3746 :style toggle :selected vhdl-align-same-indent]
3748 ["Customize Group..." (customize-group 'vhdl-align) t])
3750 ["Highlighting On/Off..."
3752 (if (fboundp 'global-font-lock-mode)
3753 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3754 ["Highlight Keywords"
3755 (progn (customize-set-variable 'vhdl-highlight-keywords
3756 (not vhdl-highlight-keywords))
3757 (vhdl-fontify-buffer))
3758 :style toggle :selected vhdl-highlight-keywords]
3760 (progn (customize-set-variable 'vhdl-highlight-names
3761 (not vhdl-highlight-names))
3762 (vhdl-fontify-buffer))
3763 :style toggle :selected vhdl-highlight-names]
3764 ["Highlight Special Words"
3765 (progn (customize-set-variable 'vhdl-highlight-special-words
3766 (not vhdl-highlight-special-words))
3767 (vhdl-fontify-buffer))
3768 :style toggle :selected vhdl-highlight-special-words]
3769 ["Highlight Forbidden Words"
3770 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3771 (not vhdl-highlight-forbidden-words))
3772 (vhdl-fontify-buffer))
3773 :style toggle :selected vhdl-highlight-forbidden-words]
3774 ["Highlight Verilog Keywords"
3775 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3776 (not vhdl-highlight-verilog-keywords))
3777 (vhdl-fontify-buffer))
3778 :style toggle :selected vhdl-highlight-verilog-keywords]
3779 ["Highlight \"translate_off\""
3780 (progn (customize-set-variable 'vhdl-highlight-translate-off
3781 (not vhdl-highlight-translate-off))
3782 (vhdl-fontify-buffer))
3783 :style toggle :selected vhdl-highlight-translate-off]
3784 ["Case Sensitive Highlighting"
3785 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3786 (not vhdl-highlight-case-sensitive))
3787 (vhdl-fontify-buffer))
3788 :style toggle :selected vhdl-highlight-case-sensitive]
3789 ["Special Syntax Definition..."
3790 (customize-option 'vhdl-special-syntax-alist) t]
3791 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3792 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3793 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3794 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3796 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3798 ["Auto Open at Startup"
3799 (customize-set-variable 'vhdl-speedbar-auto-open
3800 (not vhdl-speedbar-auto-open))
3801 :style toggle :selected vhdl-speedbar-auto-open]
3802 ("Default Displaying Mode"
3804 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3805 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3806 ["Directory Hierarchy"
3807 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3808 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3809 ["Project Hierarchy"
3810 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3811 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3812 ["Indentation Offset..."
3813 (customize-option 'speedbar-indentation-width) t]
3814 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3815 ["Jump to Unit when Opening"
3816 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3817 (not vhdl-speedbar-jump-to-unit))
3818 :style toggle :selected vhdl-speedbar-jump-to-unit]
3819 ["Update Hierarchy on File Saving"
3820 (customize-set-variable 'vhdl-speedbar-update-on-saving
3821 (not vhdl-speedbar-update-on-saving))
3822 :style toggle :selected vhdl-speedbar-update-on-saving]
3823 ("Save in Cache File"
3824 ["Hierarchy Information"
3825 (customize-set-variable 'vhdl-speedbar-save-cache
3826 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3827 (delq 'hierarchy vhdl-speedbar-save-cache)
3828 (cons 'hierarchy vhdl-speedbar-save-cache)))
3829 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3830 ["Displaying Status"
3831 (customize-set-variable 'vhdl-speedbar-save-cache
3832 (if (memq 'display vhdl-speedbar-save-cache)
3833 (delq 'display vhdl-speedbar-save-cache)
3834 (cons 'display vhdl-speedbar-save-cache)))
3835 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3836 ["Cache File Name..."
3837 (customize-option 'vhdl-speedbar-cache-file-name) t]
3839 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3841 ["Add Index Menu when Loading File"
3842 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3843 (vhdl-index-menu-init))
3844 :style toggle :selected vhdl-index-menu]
3845 ["Add Source File Menu when Loading File"
3846 (progn (customize-set-variable 'vhdl-source-file-menu
3847 (not vhdl-source-file-menu))
3848 (vhdl-add-source-files-menu))
3849 :style toggle :selected vhdl-source-file-menu]
3850 ["Add Hideshow Menu at Startup"
3851 (progn (customize-set-variable 'vhdl-hideshow-menu
3852 (not vhdl-hideshow-menu))
3853 (vhdl-activate-customizations))
3854 :style toggle :selected vhdl-hideshow-menu]
3855 ["Hide Everything Initially"
3856 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3857 :style toggle :selected vhdl-hide-all-init]
3859 ["Customize Group..." (customize-group 'vhdl-menu) t])
3861 ["In Two Column Format"
3862 (progn (customize-set-variable 'vhdl-print-two-column
3863 (not vhdl-print-two-column))
3864 (message "Activate new setting by saving options and restarting Emacs"))
3865 :style toggle :selected vhdl-print-two-column]
3866 ["Use Customized Faces"
3867 (progn (customize-set-variable 'vhdl-print-customize-faces
3868 (not vhdl-print-customize-faces))
3869 (message "Activate new setting by saving options and restarting Emacs"))
3870 :style toggle :selected vhdl-print-customize-faces]
3872 ["Customize Group..." (customize-group 'vhdl-print) t])
3874 ["Use Intelligent Tab"
3875 (progn (customize-set-variable 'vhdl-intelligent-tab
3876 (not vhdl-intelligent-tab))
3877 (vhdl-activate-customizations))
3878 :style toggle :selected vhdl-intelligent-tab]
3879 ["Indent Syntax-Based"
3880 (customize-set-variable 'vhdl-indent-syntax-based
3881 (not vhdl-indent-syntax-based))
3882 :style toggle :selected vhdl-indent-syntax-based]
3883 ["Word Completion is Case Sensitive"
3884 (customize-set-variable 'vhdl-word-completion-case-sensitive
3885 (not vhdl-word-completion-case-sensitive))
3886 :style toggle :selected vhdl-word-completion-case-sensitive]
3887 ["Word Completion in Minibuffer"
3888 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3889 (not vhdl-word-completion-in-minibuffer))
3890 (message "Activate new setting by saving options and restarting Emacs"))
3891 :style toggle :selected vhdl-word-completion-in-minibuffer]
3892 ["Underscore is Part of Word"
3893 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3894 (not vhdl-underscore-is-part-of-word))
3895 (vhdl-activate-customizations))
3896 :style toggle :selected vhdl-underscore-is-part-of-word]
3898 ["Customize Group..." (customize-group 'vhdl-misc) t])
3899 ["Related..." (customize-browse 'vhdl-related) t]
3901 ["Save Options" customize-save-customized t]
3902 ["Activate Options" vhdl-activate-customizations t]
3903 ["Browse Options..." vhdl-customize t])))
3905 (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3908 (defun vhdl-update-mode-menu ()
3909 "Update VHDL Mode menu."
3911 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
3912 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
3913 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
3914 (easy-menu-define vhdl-mode-menu vhdl-mode-map
3915 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
3917 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3918 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
3920 (defconst vhdl-imenu-generic-expression
3923 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
3926 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
3929 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3932 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
3935 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
3938 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
3941 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3944 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3947 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3950 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3953 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
3955 (defun vhdl-index-menu-init ()
3956 "Initialize index menu."
3957 (set (make-local-variable 'imenu-case-fold-search) t)
3958 (set (make-local-variable 'imenu-generic-expression)
3959 vhdl-imenu-generic-expression)
3960 (when (and vhdl-index-menu (fboundp 'imenu))
3961 (if (or (not (boundp 'font-lock-maximum-size))
3962 (> font-lock-maximum-size (buffer-size)))
3963 (imenu-add-to-menubar "Index")
3964 (message "Scanning buffer for index...buffer too big"))))
3966 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3967 ;; Source file menu (using `easy-menu.el')
3969 (defvar vhdl-sources-menu nil)
3971 (defun vhdl-directory-files (directory &optional full match)
3972 "Call `directory-files' if DIRECTORY exists, otherwise generate error
3974 (if (not (file-directory-p directory))
3975 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
3976 (let ((dir (directory-files directory full match)))
3977 (setq dir (delete "." dir))
3978 (setq dir (delete ".." dir))
3981 (defun vhdl-get-source-files (&optional full directory)
3982 "Get list of VHDL source files in DIRECTORY or current directory."
3983 (let ((mode-alist auto-mode-alist)
3985 ;; create regular expressions for matching file names
3986 (setq filename-regexp "\\`[^.].*\\(")
3988 (when (eq (cdar mode-alist) 'vhdl-mode)
3989 (setq filename-regexp
3990 (concat filename-regexp (caar mode-alist) "\\|")))
3991 (setq mode-alist (cdr mode-alist)))
3992 (setq filename-regexp
3993 (concat (substring filename-regexp 0
3994 (string-match "\\\\|$" filename-regexp)) "\\)"))
3996 (vhdl-directory-files
3997 (or directory default-directory) full filename-regexp)))
3999 (defun vhdl-add-source-files-menu ()
4000 "Scan directory for all VHDL source files and generate menu.
4001 The directory of the current source file is scanned."
4003 (message "Scanning directory for source files ...")
4004 (let ((newmap (current-local-map))
4005 (file-list (vhdl-get-source-files))
4007 ;; Create list for menu
4011 (setq menu-list (cons (vector (car file-list)
4012 (list 'find-file (car file-list)) t)
4014 (setq file-list (cdr file-list)))
4015 (setq menu-list (vhdl-menu-split menu-list "Sources"))
4016 (when found (setq menu-list (cons "--" menu-list)))
4017 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4018 (setq menu-list (cons "Sources" menu-list))
4020 (easy-menu-add menu-list)
4021 (easy-menu-define vhdl-sources-menu newmap
4022 "VHDL source files menu" menu-list))
4026 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4029 ;; performs all buffer local initializations
4033 "Major mode for editing VHDL code.
4038 TEMPLATE INSERTION (electrification):
4039 After typing a VHDL keyword and entering `SPC', you are prompted for
4040 arguments while a template is generated for that VHDL construct. Typing
4041 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4042 template generation. Optional arguments are indicated by square
4043 brackets and removed if the queried string is left empty. Prompts for
4044 mandatory arguments remain in the code if the queried string is left
4045 empty. They can be queried again by `C-c C-t C-q'. Enabled
4046 electrification is indicated by `/e' in the modeline.
4048 Typing `M-SPC' after a keyword inserts a space without calling the
4049 template generator. Automatic template generation (i.e.
4050 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4051 setting option `vhdl-electric-mode' (see OPTIONS).
4053 Template generators can be invoked from the VHDL menu, by key
4054 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4055 the keyword (i.e. first word of menu entry not in parenthesis) and
4056 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4057 conf, comp, cons, func, inst, pack, sig, var.
4059 Template styles can be customized in customization group
4060 `vhdl-template' \(see OPTIONS).
4064 A file header can be inserted by `C-c C-t C-h'. A file footer
4065 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4066 See customization group `vhdl-header'.
4070 Double striking of some keys inserts cumbersome VHDL syntax elements.
4071 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4072 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4073 the modeline. The stuttering keys and their effects are:
4075 ;; --> \" : \" [ --> ( -- --> comment
4076 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4077 .. --> \" => \" ] --> ) --- --> horizontal line
4078 ,, --> \" <= \" ]] --> ] ---- --> display comment
4079 == --> \" == \" '' --> \\\"
4083 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4084 word in the buffer that starts alike, inserts it and adjusts case.
4085 Re-typing `TAB' toggles through alternative word completions. This also
4086 works in the minibuffer (i.e. in template generator prompts).
4088 Typing `TAB' after `(' looks for and inserts complete parenthesized
4089 expressions (e.g. for array index ranges). All keywords as well as
4090 standard types and subprograms of VHDL have predefined abbreviations
4091 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4092 beginning with \"std\").
4094 Typing `TAB' after a non-word character indents the line if at the
4095 beginning of a line (i.e. no preceding non-blank characters), and
4096 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4101 `--' puts a single comment.
4102 `---' draws a horizontal line for separating code segments.
4103 `----' inserts a display comment, i.e. two horizontal lines
4104 with a comment in between.
4105 `--CR' comments out code on that line. Re-hitting CR comments
4106 out following lines.
4107 `C-c c' comments out a region if not commented out,
4108 uncomments a region if already commented out.
4110 You are prompted for comments after object definitions (i.e. signals,
4111 variables, constants, ports) and after subprogram and process
4112 specifications if option `vhdl-prompt-for-comments' is non-nil.
4113 Comments are automatically inserted as additional labels (e.g. after
4114 begin statements) and as help comments if `vhdl-self-insert-comments' is
4117 Inline comments (i.e. comments after a piece of code on the same line)
4118 are indented at least to `vhdl-inline-comment-column'. Comments go at
4119 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4120 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4121 in a comment automatically opens a new comment line. `M-q' re-fills
4122 multi-line comments.
4126 `TAB' indents a line if at the beginning of the line. The amount of
4127 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4128 always indents the current line (is bound to `TAB' if option
4129 `vhdl-intelligent-tab' is nil).
4131 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4132 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4133 indented normally (nil) or relative to the opening parenthesis (non-nil)
4134 according to option `vhdl-argument-list-indent'.
4136 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4137 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4140 Syntax-based indentation can be very slow in large files. Option
4141 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4145 The alignment functions align operators, keywords, and inline comments
4146 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4147 separated by blank lines, `C-c C-a C-i' a block of lines with same
4148 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4149 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4150 C-a C-d' all lines within the declarative part of a design unit. `C-c
4151 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4152 for a group of lines, and `C-c C-a M-c' for a region.
4154 If option `vhdl-align-groups' is non-nil, groups of code lines
4155 separated by special lines (see option `vhdl-align-group-separate') are
4156 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4157 blocks of lines with same indent are aligned separately. Some templates
4158 are automatically aligned after generation if option `vhdl-auto-align'
4161 Alignment tries to align inline comments at
4162 `vhdl-inline-comment-column' and tries inline comment not to exceed
4163 `vhdl-end-comment-column'.
4165 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4166 symbols are surrounded by one space, and multiple spaces are eliminated.
4170 | Code filling allows to condens code (e.g. sensitivity lists or port
4171 | maps) by removing comments and newlines and re-wrapping so that all
4172 | lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4173 | enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4174 | blank lines, `C-c C-f C-i' a block of lines with same indent, and
4175 | `C-c C-f M-f' an entire region.
4178 CODE BEAUTIFICATION:
4179 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4180 buffer respectively. This inludes indentation, alignment, and case
4181 fixing. Code beautification can also be run non-interactively using the
4184 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4188 Generic and port clauses from entity or component declarations can be
4189 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4190 as component instantiations and corresponding internal constants and
4191 signals, as a generic map with constants as actual generics, and as
4192 internal signal initializations (menu).
4194 To include formals in component instantiations, see option
4195 `vhdl-association-list-with-formals'. To include comments in pasting,
4196 see options `vhdl-include-...-comments'.
4198 A clause with several generic/port names on the same line can be
4199 flattened (`C-c C-p C-f') so that only one name per line exists. The
4200 | direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4201 | outputs and vice versa, which can be useful in testbenches. (This
4202 | reversion is done on the internal data structure and is only reflected
4203 | in subsequent paste operations.)
4205 Names for actual ports, instances, testbenches, and
4206 design-under-test instances can be derived from existing names according
4207 to options `vhdl-...-name'. See customization group `vhdl-port'.
4210 | SUBPROGRAM TRANSLATION:
4211 | Similar functionality exists for copying/pasting the interface of
4212 | subprograms (function/procedure). A subprogram interface can be copied
4213 | and then pasted as a subprogram declaration, body or call (uses
4214 | association list with formals).
4217 TESTBENCH GENERATION:
4218 A copied port can also be pasted as a testbench. The generated
4219 testbench includes an entity, an architecture, and an optional
4220 configuration. The architecture contains the component declaration and
4221 instantiation of the DUT as well as internal constant and signal
4222 declarations. Additional user-defined templates can be inserted. The
4223 names used for entity/architecture/configuration/DUT as well as the file
4224 structure to be generated can be customized. See customization group
4229 Key bindings (`C-c ...') exist for most commands (see in menu).
4233 All commands can be found in the VHDL menu including their key bindings.
4237 The speedbar allows browsing of directories and file contents. It can
4238 be accessed from the VHDL menu and is automatically opened if option
4239 `vhdl-speedbar-auto-open' is non-nil.
4241 In speedbar, open files and directories with `mouse-2' on the name and
4242 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4245 DESIGN HIERARCHY BROWSER:
4246 The speedbar can also be used for browsing the hierarchy of design units
4247 contained in the source files of the current directory or the specified
4248 projects (see option `vhdl-project-alist').
4250 The speedbar can be switched between file, directory hierarchy and
4251 project hierarchy browsing mode in the speedbar menu or by typing `f',
4252 `h' or `H' in speedbar.
4254 In speedbar, open design units with `mouse-2' on the name and browse
4255 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4256 from entities and components (in packages). Individual design units and
4257 complete designs can directly be compiled (\"Make\" menu entry).
4259 The hierarchy is automatically updated upon saving a modified source
4260 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4261 hierarchy is only updated for projects that have been opened once in the
4262 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4263 options in group `vhdl-speedbar').
4265 Simple design consistency checks are done during scanning, such as
4266 multiple declarations of the same unit or missing primary units that are
4267 required by secondary units.
4270 | STRUCTURAL COMPOSITION:
4271 | Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4272 | for a new component. Subcomponents (i.e. component declaration and
4273 | instantiation) can be automatically placed from a previously read port
4274 | \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4275 | all subcomponents can be automatically connected using internal signals
4276 | and ports (`C-c C-c C-w') following these rules:
4277 | - subcomponent actual ports with same name are considered to be
4278 | connected by a signal (internal signal or port)
4279 | - signals that are only inputs to subcomponents are considered as
4280 | inputs to this component -> input port created
4281 | - signals that are only outputs from subcomponents are considered as
4282 | outputs from this component -> output port created
4283 | - signals that are inputs to AND outputs from subcomponents are
4284 | considered as internal connections -> internal signal created
4286 | Component declarations can be placed in a components package (option
4287 | `vhdl-use-components-package') which can be automatically generated for
4288 | an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4289 | component instantiation is also supported (option
4290 | `vhdl-use-direct-instantiation').
4292 | Purpose: With appropriate naming conventions it is possible to
4293 | create higher design levels with only a few mouse clicks or key
4294 | strokes. A new design level can be created by simply generating a new
4295 | component, placing the required subcomponents from the hierarchy
4296 | browser, and wiring everything automatically.
4298 | Note: Automatic wiring only works reliably on templates of new
4299 | components and component instantiations that were created by VHDL mode.
4301 | See the options group `vhdl-compose' for all relevant user options.
4304 SOURCE FILE COMPILATION:
4305 The syntax of the current buffer can be analyzed by calling a VHDL
4306 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4307 option `vhdl-compiler'. The available compilers are listed in option
4308 `vhdl-compiler-alist' including all required compilation command,
4309 command options, compilation directory, and error message syntax
4310 information. New compilers can be added.
4312 All the source files of an entire design can be compiled by the `make'
4313 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4316 MAKEFILE GENERATION:
4317 Makefiles can be generated automatically by an internal generation
4318 routine (`C-c M-k'). The library unit dependency information is
4319 obtained from the hierarchy browser. Makefile generation can be
4320 customized for each compiler in option `vhdl-compiler-alist'.
4322 Makefile generation can also be run non-interactively using the
4325 emacs -batch -l ~/.emacs -l vhdl-mode
4326 [-compiler compilername] [-project projectname]
4327 -f vhdl-generate-makefile
4329 The Makefile's default target \"all\" compiles the entire design, the
4330 target \"clean\" removes it and the target \"library\" creates the
4331 library directory if not existent. The Makefile also includes a target
4332 for each primary library unit which allows selective compilation of this
4333 unit, its secondary units and its subhierarchy (example: compilation of
4334 a design specified by a configuration). User specific parts can be
4335 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4338 - Only library units and dependencies within the current library are
4339 considered. Makefiles for designs that span multiple libraries are
4340 not (yet) supported.
4341 - Only one-level configurations are supported (also hierarchical),
4342 but configurations that go down several levels are not.
4343 - The \"others\" keyword in configurations is not supported.
4347 Projects can be defined in option `vhdl-project-alist' and a current
4348 project be selected using option `vhdl-project' (permanently) or from
4349 the menu or speedbar (temporarily). For each project, title and
4350 description strings (for the file headers), source files/directories
4351 (for the hierarchy browser and Makefile generation), library name, and
4352 compiler-dependent options, exceptions and compilation directory can be
4353 specified. Compilation settings overwrite the settings of option
4354 `vhdl-compiler-alist'.
4356 Project setups can be exported (i.e. written to a file) and imported.
4357 Imported setups are not automatically saved in `vhdl-project-alist' but
4358 can be saved afterwards in its customization buffer. When starting
4359 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4360 vhdl-mode\") in a directory with an existing project setup file, it is
4361 automatically loaded and its project activated if option
4362 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4363 files can be specified in option `vhdl-project-file-name'. Multiple
4364 project setups can be automatically loaded from global directories.
4365 This is an alternative to specifying project setups with option
4366 `vhdl-project-alist'.
4370 As an alternative to the speedbar, an index menu can be added (set
4371 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4372 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4373 file) for browsing the file contents (is not populated if buffer is
4374 larger than `font-lock-maximum-size'). Also, a source file menu can be
4375 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4376 current directory for VHDL source files.
4380 The VHDL standards to be used are specified in option `vhdl-standard'.
4381 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4385 Lower and upper case for keywords and standardized types, attributes,
4386 and enumeration values is supported. If the option
4387 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4388 lower case and are converted into upper case automatically (not for
4389 types, attributes, and enumeration values). The case of keywords,
4390 types, attributes,and enumeration values can be fixed for an entire
4391 region (menu) or buffer (`C-c C-x C-c') according to the options
4392 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4395 HIGHLIGHTING (fontification):
4396 Keywords and standardized types, attributes, enumeration values, and
4397 function names (controlled by option `vhdl-highlight-keywords'), as well
4398 as comments, strings, and template prompts are highlighted using
4399 different colors. Unit, subprogram, signal, variable, constant,
4400 parameter and generic/port names in declarations as well as labels are
4401 highlighted if option `vhdl-highlight-names' is non-nil.
4403 Additional reserved words or words with a forbidden syntax (e.g. words
4404 that should be avoided) can be specified in option
4405 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4406 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4407 keywords are highlighted as forbidden words if option
4408 `vhdl-highlight-verilog-keywords' is non-nil.
4410 Words with special syntax can be highlighted by specifying their
4411 syntax and color in option `vhdl-special-syntax-alist' and by setting
4412 option `vhdl-highlight-special-words' to non-nil. This allows to
4413 establish some naming conventions (e.g. to distinguish different kinds
4414 of signals or other objects by using name suffices) and to support them
4417 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4418 to support case-sensitive highlighting. However, keywords are then only
4419 highlighted if written in lower case.
4421 Code between \"translate_off\" and \"translate_on\" pragmas is
4422 highlighted using a different background color if option
4423 `vhdl-highlight-translate-off' is non-nil.
4425 For documentation and customization of the used colors see
4426 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4427 highlighting of matching parenthesis, see customization group
4428 `paren-showing'. Automatic buffer highlighting is turned on/off by
4429 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4433 VHDL models (templates) can be specified by the user and made accessible
4434 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4435 electrification. See option `vhdl-model-alist'.
4439 The code of blocks, processes, subprograms, component declarations and
4440 instantiations, generic/port clauses, and configuration declarations can
4441 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4442 the code (see customization group `vhdl-menu'). XEmacs: limited
4443 functionality due to old `hideshow.el' package.
4447 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4448 current process, `C-c C-u M-s' of all processes in the current buffer.
4450 - Only declared local signals (ports, signals declared in
4451 architecture and blocks) are automatically inserted.
4452 - Global signals declared in packages are not automatically inserted.
4453 Insert them once manually (will be kept afterwards).
4454 - Out parameters of procedures are considered to be read.
4455 Use option `vhdl-entity-file-name' to specify the entity file name
4456 \(used to obtain the port names).
4460 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4461 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4465 Postscript printing with different faces (an optimized set of faces is
4466 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4467 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4468 postscript printing commands. Option `vhdl-print-two-column' defines
4469 appropriate default settings for nice landscape two-column printing.
4470 The paper format can be set by option `ps-paper-type'. Do not forget to
4471 switch `ps-print-color-p' to nil for printing on black-and-white
4476 User options allow customization of VHDL Mode. All options are
4477 accessible from the \"Options\" menu entry. Simple options (switches
4478 and choices) can directly be changed, while for complex options a
4479 customization buffer is opened. Changed options can be saved for future
4480 sessions using the \"Save Options\" menu entry.
4482 Options and their detailed descriptions can also be accessed by using
4483 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4484 customize-group' for groups). Some customizations only take effect
4485 after some action (read the NOTE in the option documentation).
4486 Customization can also be done globally (i.e. site-wide, read the
4489 Not all options are described in this documentation, so go and see
4490 what other useful user options there are (`M-x vhdl-customize' or menu)!
4494 As default, files with extensions \".vhd\" and \".vhdl\" are
4495 automatically recognized as VHDL source files. To add an extension
4496 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4498 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4502 - To start Emacs with open VHDL hierarchy browser without having to load
4503 a VHDL file first, use the command:
4505 emacs -l vhdl-mode -f speedbar-frame-mode
4507 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4509 - Some features only work on properly indented code.
4513 See also the release notes (menu) for added features in new releases.
4519 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4520 Add a description of the problem and include a reproducible test case.
4522 Questions and enhancement requests can be sent to <reto@gnu.org>.
4524 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4525 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4526 releases. You are kindly invited to participate in beta testing. Subscribe
4527 to above mailing lists by sending an email to <reto@gnu.org>.
4529 VHDL Mode is officially distributed at
4530 http://opensource.ethz.ch/emacs/vhdl-mode.html
4531 where the latest version can be found.
4537 - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
4538 - XEmacs: Incorrect start-up when automatically opening speedbar.
4539 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4542 The VHDL Mode Authors
4543 Reto Zimmermann and Rod Whitby
4550 (kill-all-local-variables)
4551 (setq major-mode 'vhdl-mode)
4552 (setq mode-name "VHDL")
4554 ;; set maps and tables
4555 (use-local-map vhdl-mode-map)
4556 (set-syntax-table vhdl-mode-syntax-table)
4557 (setq local-abbrev-table vhdl-mode-abbrev-table)
4559 ;; set local variables
4560 (set (make-local-variable 'paragraph-start)
4561 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4562 (set (make-local-variable 'paragraph-separate) paragraph-start)
4563 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
4564 (set (make-local-variable 'require-final-newline)
4565 mode-require-final-newline)
4566 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4567 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4568 (set (make-local-variable 'comment-start) "--")
4569 (set (make-local-variable 'comment-end) "")
4570 (set (make-local-variable 'comment-padding) "")
4571 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
4572 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4573 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
4574 (set (make-local-variable 'comment-multi-line) nil)
4575 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
4576 (set (make-local-variable 'hippie-expand-verbose) nil)
4578 ;; setup the comment indent variable in a Emacs version portable way
4579 ;; ignore any byte compiler warnings you might get here
4580 (when (boundp 'comment-indent-function)
4581 (make-local-variable 'comment-indent-function)
4582 (setq comment-indent-function 'vhdl-comment-indent))
4584 ;; initialize font locking
4585 (set (make-local-variable 'font-lock-defaults)
4587 '(nil vhdl-font-lock-keywords) nil
4588 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4589 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
4590 (unless vhdl-emacs-21
4591 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4592 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4593 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4594 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4595 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4596 ; (turn-on-font-lock)
4598 ;; variables for source file compilation
4599 (when vhdl-compile-use-local-error-regexp
4600 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4601 (set (make-local-variable 'compilation-file-regexp-alist) nil))
4604 (vhdl-index-menu-init)
4605 ;; add source file menu
4606 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
4608 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4609 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4610 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4611 ;; initialize hideshow and add menu
4612 (vhdl-hideshow-init)
4613 (run-hooks 'menu-bar-update-hook)
4616 (vhdl-ps-print-init)
4617 (vhdl-write-file-hooks-init)
4618 (vhdl-mode-line-update)
4619 (message "VHDL Mode %s.%s" vhdl-version
4620 (if noninteractive "" " See menu for documentation and release notes."))
4623 (run-mode-hooks 'vhdl-mode-hook))
4625 (defun vhdl-activate-customizations ()
4626 "Activate all customizations on local variables."
4628 (vhdl-mode-map-init)
4629 (use-local-map vhdl-mode-map)
4630 (set-syntax-table vhdl-mode-syntax-table)
4631 (setq comment-column vhdl-inline-comment-column)
4632 (setq end-comment-column vhdl-end-comment-column)
4633 (vhdl-write-file-hooks-init)
4634 (vhdl-update-mode-menu)
4635 (vhdl-hideshow-init)
4636 (run-hooks 'menu-bar-update-hook)
4637 (vhdl-mode-line-update))
4639 (defun vhdl-write-file-hooks-init ()
4640 "Add/remove hooks when buffer is saved."
4641 (if vhdl-modify-date-on-saving
4642 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
4643 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4644 (make-local-variable 'after-save-hook)
4645 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4647 (defun vhdl-process-command-line-option (option)
4648 "Process command line options for VHDL Mode."
4651 ((equal option "-compiler")
4652 (vhdl-set-compiler (car command-line-args-left))
4653 (setq command-line-args-left (cdr command-line-args-left)))
4655 ((equal option "-project")
4656 (vhdl-set-project (car command-line-args-left))
4657 (setq command-line-args-left (cdr command-line-args-left)))))
4659 ;; make Emacs process VHDL Mode options
4660 (setq command-switch-alist
4661 (append command-switch-alist
4662 '(("-compiler" . vhdl-process-command-line-option)
4663 ("-project" . vhdl-process-command-line-option))))
4666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4667 ;;; Keywords and standardized words
4668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4670 (defconst vhdl-93-keywords
4672 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4673 "assert" "attribute"
4674 "begin" "block" "body" "buffer" "bus"
4675 "case" "component" "configuration" "constant"
4676 "disconnect" "downto"
4677 "else" "elsif" "end" "entity" "exit"
4678 "file" "for" "function"
4679 "generate" "generic" "group" "guarded"
4680 "if" "impure" "in" "inertial" "inout" "is"
4681 "label" "library" "linkage" "literal" "loop"
4683 "nand" "new" "next" "nor" "not" "null"
4684 "of" "on" "open" "or" "others" "out"
4685 "package" "port" "postponed" "procedure" "process" "pure"
4686 "range" "record" "register" "reject" "rem" "report" "return"
4688 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4689 "then" "to" "transport" "type"
4690 "unaffected" "units" "until" "use"
4692 "wait" "when" "while" "with"
4695 "List of VHDL'93 keywords.")
4697 (defconst vhdl-ams-keywords
4699 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4700 "reference" "spectrum" "subnature" "terminal" "through"
4703 "List of VHDL-AMS keywords.")
4705 (defconst vhdl-verilog-keywords
4707 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4708 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4709 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4710 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4711 "endprimitive" "endspecify" "endtable" "endtask" "event"
4712 "for" "force" "forever" "fork" "function"
4713 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4714 "macromodule" "makefile" "medium" "module"
4715 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4716 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4718 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4719 "rtranif0" "rtranif1"
4720 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4721 "strong1" "supply" "supply0" "supply1"
4722 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4723 "triand" "trior" "trireg"
4724 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4726 "List of Verilog keywords as candidate for additional reserved words.")
4728 (defconst vhdl-93-types
4730 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4731 "real" "time" "natural" "positive" "string" "line" "text" "side"
4732 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4733 "std_logic" "std_logic_vector"
4734 "std_ulogic" "std_ulogic_vector"
4736 "List of VHDL'93 standardized types.")
4738 (defconst vhdl-ams-types
4740 "domain_type" "real_vector"
4741 ;; from `nature_pkg' package
4742 "voltage" "current" "electrical" "position" "velocity" "force"
4743 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4744 "pressure" "flowrate" "fluid"
4746 "List of VHDL-AMS standardized types.")
4748 (defconst vhdl-math-types
4750 "complex" "complex_polar"
4752 "List of Math Packages standardized types.")
4754 (defconst vhdl-93-attributes
4756 "base" "left" "right" "high" "low" "pos" "val" "succ"
4757 "pred" "leftof" "rightof" "range" "reverse_range"
4758 "length" "delayed" "stable" "quiet" "transaction"
4759 "event" "active" "last_event" "last_active" "last_value"
4760 "driving" "driving_value" "ascending" "value" "image"
4761 "simple_name" "instance_name" "path_name"
4764 "List of VHDL'93 standardized attributes.")
4766 (defconst vhdl-ams-attributes
4769 "reference" "contribution" "tolerance"
4770 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4773 "List of VHDL-AMS standardized attributes.")
4775 (defconst vhdl-93-enum-values
4778 "note" "warning" "error" "failure"
4779 "read_mode" "write_mode" "append_mode"
4780 "open_ok" "status_error" "name_error" "mode_error"
4781 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4784 "List of VHDL'93 standardized enumeration values.")
4786 (defconst vhdl-ams-enum-values
4788 "quiescent_domain" "time_domain" "frequency_domain"
4789 ;; from `nature_pkg' package
4790 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
4792 "List of VHDL-AMS standardized enumeration values.")
4794 (defconst vhdl-math-constants
4796 "math_e" "math_1_over_e"
4797 "math_pi" "math_two_pi" "math_1_over_pi"
4798 "math_half_pi" "math_q_pi" "math_3_half_pi"
4799 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4800 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4801 "math_deg_to_rad" "math_rad_to_deg"
4802 "cbase_1" "cbase_j" "czero"
4804 "List of Math Packages standardized constants.")
4806 (defconst vhdl-93-functions
4808 "now" "resolved" "rising_edge" "falling_edge"
4809 "read" "readline" "write" "writeline" "endfile"
4810 "resize" "is_X" "std_match"
4811 "shift_left" "shift_right" "rotate_left" "rotate_right"
4812 "to_unsigned" "to_signed" "to_integer"
4813 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4814 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4815 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4816 "shl" "shr" "ext" "sxt"
4819 "List of VHDL'93 standardized functions.")
4821 (defconst vhdl-ams-functions
4825 "List of VHDL-AMS standardized functions.")
4827 (defconst vhdl-math-functions
4829 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4830 "sqrt" "cbrt" "exp" "log"
4831 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4832 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4833 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4835 "List of Math Packages standardized functions.")
4837 (defconst vhdl-93-packages
4839 "std_logic_1164" "numeric_std" "numeric_bit"
4841 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4842 "std_logic_misc" "std_logic_textio"
4845 "List of VHDL'93 standardized packages and libraries.")
4847 (defconst vhdl-ams-packages
4849 ;; from `nature_pkg' package
4852 "List of VHDL-AMS standardized packages and libraries.")
4854 (defconst vhdl-math-packages
4856 "math_real" "math_complex"
4858 "List of Math Packages standardized packages and libraries.")
4860 (defvar vhdl-keywords nil
4861 "List of VHDL keywords.")
4863 (defvar vhdl-types nil
4864 "List of VHDL standardized types.")
4866 (defvar vhdl-attributes nil
4867 "List of VHDL standardized attributes.")
4869 (defvar vhdl-enum-values nil
4870 "List of VHDL standardized enumeration values.")
4872 (defvar vhdl-constants nil
4873 "List of VHDL standardized constants.")
4875 (defvar vhdl-functions nil
4876 "List of VHDL standardized functions.")
4878 (defvar vhdl-packages nil
4879 "List of VHDL standardized packages and libraries.")
4881 (defvar vhdl-reserved-words nil
4882 "List of additional reserved words.")
4884 (defvar vhdl-keywords-regexp nil
4885 "Regexp for VHDL keywords.")
4887 (defvar vhdl-types-regexp nil
4888 "Regexp for VHDL standardized types.")
4890 (defvar vhdl-attributes-regexp nil
4891 "Regexp for VHDL standardized attributes.")
4893 (defvar vhdl-enum-values-regexp nil
4894 "Regexp for VHDL standardized enumeration values.")
4896 (defvar vhdl-functions-regexp nil
4897 "Regexp for VHDL standardized functions.")
4899 (defvar vhdl-packages-regexp nil
4900 "Regexp for VHDL standardized packages and libraries.")
4902 (defvar vhdl-reserved-words-regexp nil
4903 "Regexp for additional reserved words.")
4905 (defvar vhdl-directive-keywords-regexp nil
4906 "Regexp for compiler directive keywords.")
4908 (defun vhdl-words-init ()
4909 "Initialize reserved words."
4911 (append vhdl-93-keywords
4912 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
4914 (append vhdl-93-types
4915 (when (vhdl-standard-p 'ams) vhdl-ams-types)
4916 (when (vhdl-standard-p 'math) vhdl-math-types)))
4917 (setq vhdl-attributes
4918 (append vhdl-93-attributes
4919 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
4920 (setq vhdl-enum-values
4921 (append vhdl-93-enum-values
4922 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
4923 (setq vhdl-constants
4924 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
4925 (setq vhdl-functions
4926 (append vhdl-93-functions
4927 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
4928 (when (vhdl-standard-p 'math) vhdl-math-functions)))
4930 (append vhdl-93-packages
4931 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
4932 (when (vhdl-standard-p 'math) vhdl-math-packages)))
4933 (setq vhdl-reserved-words
4934 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
4935 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
4937 (setq vhdl-keywords-regexp
4938 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
4939 (setq vhdl-types-regexp
4940 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
4941 (setq vhdl-attributes-regexp
4942 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
4943 (setq vhdl-enum-values-regexp
4944 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
4945 (setq vhdl-functions-regexp
4946 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
4947 (setq vhdl-packages-regexp
4948 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
4949 (setq vhdl-reserved-words-regexp
4951 (unless (equal vhdl-forbidden-syntax "")
4952 (concat vhdl-forbidden-syntax "\\|"))
4953 (regexp-opt vhdl-reserved-words)
4955 (setq vhdl-directive-keywords-regexp
4956 (concat "\\<\\(" (mapconcat 'regexp-quote
4957 vhdl-directive-keywords "\\|") "\\)\\>"))
4958 (vhdl-abbrev-list-init))
4960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4963 (defvar vhdl-abbrev-list nil
4964 "Predefined abbreviations for VHDL.")
4966 (defun vhdl-abbrev-list-init ()
4967 (setq vhdl-abbrev-list
4969 (list vhdl-upper-case-keywords) vhdl-keywords
4970 (list vhdl-upper-case-types) vhdl-types
4971 (list vhdl-upper-case-attributes) vhdl-attributes
4972 (list vhdl-upper-case-enum-values) vhdl-enum-values
4973 (list vhdl-upper-case-constants) vhdl-constants
4974 (list nil) vhdl-functions
4975 (list nil) vhdl-packages)))
4977 ;; initialize reserved words for VHDL Mode
4981 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4985 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4988 ;; constant regular expressions for looking at various constructs
4990 (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
4991 "Regexp describing a VHDL symbol.
4992 We cannot use just `word' syntax class since `_' cannot be in word
4993 class. Putting underscore in word class breaks forward word movement
4994 behavior that users are familiar with.")
4996 (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
4997 "Regexp describing a case statement header key.")
4999 (defconst vhdl-label-key
5000 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5001 "Regexp describing a VHDL label.")
5003 ;; Macro definitions:
5005 (defmacro vhdl-point (position)
5006 "Return the value of point at certain commonly referenced POSITIONs.
5007 POSITION can be one of the following symbols:
5009 bol -- beginning of line
5011 bod -- beginning of defun
5012 boi -- back to indentation
5013 eoi -- last whitespace on line
5014 ionl -- indentation of next line
5015 iopl -- indentation of previous line
5016 bonl -- beginning of next line
5017 bopl -- beginning of previous line
5019 This function does not modify point or mark."
5020 (or (and (eq 'quote (car-safe position))
5021 (null (cddr position)))
5022 (error "ERROR: Bad buffer position requested: %s" position))
5023 (setq position (nth 1 position))
5024 `(let ((here (point)))
5026 ((eq position 'bol) '((beginning-of-line)))
5027 ((eq position 'eol) '((end-of-line)))
5028 ((eq position 'bod) '((save-match-data
5029 (vhdl-beginning-of-defun))))
5030 ((eq position 'boi) '((back-to-indentation)))
5031 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
5032 ((eq position 'bonl) '((forward-line 1)))
5033 ((eq position 'bopl) '((forward-line -1)))
5034 ((eq position 'iopl)
5036 (back-to-indentation)))
5037 ((eq position 'ionl)
5039 (back-to-indentation)))
5040 (t (error "ERROR: Unknown buffer position requested: %s" position))
5045 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5046 ;; doesn't hurt for v19
5050 (defmacro vhdl-safe (&rest body)
5051 "Safely execute BODY, return nil if an error occurred."
5052 `(condition-case nil
5056 (defmacro vhdl-add-syntax (symbol &optional relpos)
5057 "A simple macro to append the syntax in SYMBOL to the syntax list.
5058 Try to increase performance by using this macro."
5059 `(setq vhdl-syntactic-context
5060 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
5062 (defmacro vhdl-has-syntax (symbol)
5063 "A simple macro to return check the syntax list.
5064 Try to increase performance by using this macro."
5065 `(assoc ,symbol vhdl-syntactic-context))
5067 ;; Syntactic element offset manipulation:
5069 (defun vhdl-read-offset (langelem)
5070 "Read new offset value for LANGELEM from minibuffer.
5071 Return a valid value only."
5072 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5073 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5075 offset input interned)
5077 (setq input (read-string prompt oldoff)
5078 offset (cond ((string-equal "+" input) '+)
5079 ((string-equal "-" input) '-)
5080 ((string-equal "++" input) '++)
5081 ((string-equal "--" input) '--)
5082 ((string-match "^-?[0-9]+$" input)
5083 (string-to-number input))
5084 ((fboundp (setq interned (intern input)))
5086 ((boundp interned) interned)
5087 ;; error, but don't signal one, keep trying
5088 ;; to read an input value
5090 (setq prompt errmsg)
5094 (defun vhdl-set-offset (symbol offset &optional add-p)
5095 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5096 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5097 offset for that syntactic element. Optional ADD says to add SYMBOL to
5098 `vhdl-offsets-alist' if it doesn't already appear there."
5101 (intern (completing-read
5102 (concat "Syntactic symbol to change"
5103 (if current-prefix-arg " or add" "")
5108 (cons (format "%s" (car langelem)) nil)))
5110 nil (not current-prefix-arg)
5111 ;; initial contents tries to be the last element
5112 ;; on the syntactic analysis list for the current
5114 (let* ((syntax (vhdl-get-syntactic-context))
5115 (len (length syntax))
5116 (ic (format "%s" (car (nth (1- len) syntax)))))
5119 (offset (vhdl-read-offset langelem)))
5120 (list langelem offset current-prefix-arg)))
5121 ;; sanity check offset
5129 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5131 (let ((entry (assq symbol vhdl-offsets-alist)))
5133 (setcdr entry offset)
5135 (setq vhdl-offsets-alist
5136 (cons (cons symbol offset) vhdl-offsets-alist))
5137 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
5138 (vhdl-keep-region-active))
5140 (defun vhdl-set-style (style &optional local)
5141 "Set `vhdl-mode' variables to use one of several different indentation styles.
5142 STYLE is a string representing the desired style and optional LOCAL is
5143 a flag which, if non-nil, means to make the style variables being
5144 changed buffer local, instead of the default, which is to set the
5145 global variables. Interactively, the flag comes from the prefix
5146 argument. The styles are chosen from the `vhdl-style-alist' variable."
5147 (interactive (list (completing-read "Use which VHDL indentation style? "
5148 vhdl-style-alist nil t)
5149 current-prefix-arg))
5150 (let ((vars (cdr (assoc style vhdl-style-alist))))
5152 (error "ERROR: Invalid VHDL indentation style `%s'" style))
5153 ;; set all the variables
5157 (let ((var (car varentry))
5158 (val (cdr varentry)))
5160 (make-local-variable var))
5161 ;; special case for vhdl-offsets-alist
5162 (if (not (eq var 'vhdl-offsets-alist))
5164 ;; reset vhdl-offsets-alist to the default value first
5165 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5166 ;; now set the langelems that are different
5170 (let ((langelem (car langentry))
5171 (offset (cdr langentry)))
5172 (vhdl-set-offset langelem offset)
5177 (vhdl-keep-region-active))
5179 (defun vhdl-get-offset (langelem)
5180 "Get offset from LANGELEM which is a cons cell of the form:
5181 \(SYMBOL . RELPOS). The symbol is matched against
5182 vhdl-offsets-alist and the offset found there is either returned,
5183 or added to the indentation at RELPOS. If RELPOS is nil, then
5184 the offset is simply returned."
5185 (let* ((symbol (car langelem))
5186 (relpos (cdr langelem))
5187 (match (assq symbol vhdl-offsets-alist))
5188 (offset (cdr-safe match)))
5189 ;; offset can be a number, a function, a variable, or one of the
5193 (if vhdl-strict-syntax-p
5194 (error "ERROR: Don't know how to indent a %s" symbol)
5197 ((eq offset '+) (setq offset vhdl-basic-offset))
5198 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5199 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5200 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5201 ((and (not (numberp offset))
5203 (setq offset (funcall offset langelem)))
5204 ((not (numberp offset))
5205 (setq offset (eval offset)))
5208 (< relpos (vhdl-point 'bol)))
5215 ;; Syntactic support functions:
5217 (defun vhdl-in-comment-p ()
5218 "Check if point is in a comment."
5219 (eq (vhdl-in-literal) 'comment))
5221 (defun vhdl-in-string-p ()
5222 "Check if point is in a string."
5223 (eq (vhdl-in-literal) 'string))
5225 (defun vhdl-in-literal ()
5226 "Determine if point is in a VHDL literal."
5228 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
5230 ((nth 3 state) 'string)
5231 ((nth 4 state) 'comment)
5234 (defun vhdl-forward-comment (&optional direction)
5235 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5236 negative, skip forward otherwise."
5238 (if (and direction (< direction 0))
5241 (skip-chars-backward " \t\n")
5242 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5243 (goto-char (match-beginning 3))
5244 (skip-chars-backward " \t\n")))
5246 (skip-chars-forward " \t\n")
5247 (while (looking-at "--.*")
5248 (goto-char (match-end 0))
5249 (skip-chars-forward " \t\n"))))
5251 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5252 (unless (and vhdl-xemacs (string< "21.2" emacs-version))
5253 (defalias 'vhdl-forward-comment 'forward-comment))
5255 ;; This is the best we can do in Win-Emacs.
5256 (defun vhdl-win-il (&optional lim)
5257 "Determine if point is in a VHDL literal."
5259 (let* ((here (point))
5262 (lim (or lim (vhdl-point 'bod))))
5264 (while (< (point) here)
5266 (and (re-search-forward "--\\|[\"']"
5268 (buffer-substring (match-beginning 0) (match-end 0))))
5273 ;; looking at the opening of a VHDL style comment
5274 ((string= "--" match)
5275 (if (<= here (progn (end-of-line) (point))) 'comment))
5276 ;; looking at the opening of a double quote string
5277 ((string= "\"" match)
5278 (if (not (save-restriction
5279 ;; this seems to be necessary since the
5280 ;; re-search-forward will not work without it
5281 (narrow-to-region (point) here)
5283 ;; this regexp matches a double quote
5284 ;; which is preceded by an even number
5285 ;; of backslashes, including zero
5286 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5288 ;; looking at the opening of a single quote string
5289 ((string= "'" match)
5290 (if (not (save-restriction
5291 ;; see comments from above
5292 (narrow-to-region (point) here)
5294 ;; this matches a single quote which is
5295 ;; preceded by zero or two backslashes.
5296 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5303 (and (string-match "Win-Emacs" emacs-version)
5304 (fset 'vhdl-in-literal 'vhdl-win-il))
5306 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5307 ;; defined as lexical whitespace or comments. Search no farther back
5308 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5309 ;; used for backward skipping, (point-max) is used for forward
5312 (defun vhdl-forward-syntactic-ws (&optional lim)
5313 "Forward skip of syntactic whitespace."
5315 (let* ((lim (or lim (point-max)))
5317 (hugenum (point-max)))
5318 (narrow-to-region lim (point))
5319 (while (/= here (point))
5321 (vhdl-forward-comment hugenum)))))
5323 ;; This is the best we can do in Win-Emacs.
5324 (defun vhdl-win-fsws (&optional lim)
5325 "Forward skip syntactic whitespace for Win-Emacs."
5326 (let ((lim (or lim (point-max)))
5329 (skip-chars-forward " \t\n\r\f" lim)
5332 ((looking-at "--") (end-of-line))
5333 ;; none of the above
5334 (t (setq stop t))))))
5336 (and (string-match "Win-Emacs" emacs-version)
5337 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5339 (defun vhdl-backward-syntactic-ws (&optional lim)
5340 "Backward skip over syntactic whitespace."
5342 (let* ((lim (or lim (point-min)))
5344 (hugenum (- (point-max))))
5347 (narrow-to-region lim (point))
5348 (while (/= here (point))
5350 (vhdl-forward-comment hugenum)))))))
5352 ;; This is the best we can do in Win-Emacs.
5353 (defun vhdl-win-bsws (&optional lim)
5354 "Backward skip syntactic whitespace for Win-Emacs."
5355 (let ((lim (or lim (vhdl-point 'bod)))
5358 (skip-chars-backward " \t\n\r\f" lim)
5361 ((eq (vhdl-in-literal) 'comment)
5362 (skip-chars-backward "^-" lim)
5363 (skip-chars-backward "-" lim)
5364 (while (not (or (and (= (following-char) ?-)
5365 (= (char-after (1+ (point))) ?-))
5367 (skip-chars-backward "^-" lim)
5368 (skip-chars-backward "-" lim)))
5369 ;; none of the above
5370 (t (setq stop t))))))
5372 (and (string-match "Win-Emacs" emacs-version)
5373 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5375 ;; Functions to help finding the correct indentation column:
5377 (defun vhdl-first-word (point)
5378 "If the keyword at POINT is at boi, then return (current-column) at
5379 that point, else nil."
5381 (and (goto-char point)
5382 (eq (point) (vhdl-point 'boi))
5385 (defun vhdl-last-word (point)
5386 "If the keyword at POINT is at eoi, then return (current-column) at
5387 that point, else nil."
5389 (and (goto-char point)
5390 (save-excursion (or (eq (progn (forward-sexp) (point))
5392 (looking-at "\\s-*\\(--\\)?")))
5395 ;; Core syntactic evaluation functions:
5397 (defconst vhdl-libunit-re
5398 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5400 (defun vhdl-libunit-p ()
5404 (skip-chars-forward " \t\n")
5405 (not (looking-at "is\\b[^_]")))
5408 (and (not (looking-at "use\\b[^_]"))
5411 (vhdl-forward-syntactic-ws)
5412 (/= (following-char) ?:))))
5415 (defconst vhdl-defun-re
5416 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5418 (defun vhdl-defun-p ()
5420 (if (looking-at "block\\|process\\|procedural")
5421 ;; "block", "process", "procedural":
5424 (not (looking-at "end\\s-+\\w")))
5425 ;; "architecture", "configuration", "entity",
5426 ;; "package", "procedure", "function":
5429 (defun vhdl-corresponding-defun ()
5430 "If the word at the current position corresponds to a \"defun\"
5431 keyword, then return a string that can be used to find the
5432 corresponding \"begin\" keyword, else return nil."
5434 (and (looking-at vhdl-defun-re)
5436 (if (looking-at "block\\|process\\|procedural")
5437 ;; "block", "process". "procedural:
5438 (buffer-substring (match-beginning 0) (match-end 0))
5439 ;; "architecture", "configuration", "entity", "package",
5440 ;; "procedure", "function":
5443 (defconst vhdl-begin-fwd-re
5444 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
5445 "A regular expression for searching forward that matches all known
5446 \"begin\" keywords.")
5448 (defconst vhdl-begin-bwd-re
5449 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
5450 "A regular expression for searching backward that matches all known
5451 \"begin\" keywords.")
5453 (defun vhdl-begin-p (&optional lim)
5454 "Return t if we are looking at a real \"begin\" keyword.
5455 Assumes that the caller will make sure that we are looking at
5456 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5457 the middle of an identifier that just happens to contain a \"begin\"
5460 ;; "[architecture|case|configuration|entity|package|
5461 ;; procedure|function] ... is":
5462 ((and (looking-at "i")
5464 ;; Skip backward over first sexp (needed to skip over a
5465 ;; procedure interface list, and is harmless in other
5466 ;; situations). Note that we need "return" in the
5467 ;; following search list so that we don't run into
5468 ;; semicolons in the function interface list.
5471 (while (and (not foundp)
5473 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5475 (if (or (= (preceding-char) ?_)
5479 (and (/= (following-char) ?\;)
5480 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5483 ((looking-at "be\\|t")
5486 ((and (looking-at "e")
5487 ;; make sure that the "else" isn't inside a
5488 ;; conditional signal assignment.
5490 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5491 (or (eq (following-char) ?\;)
5494 ;; "block", "generate", "loop", "process", "procedural",
5495 ;; "units", "record":
5496 ((and (looking-at "bl\\|[glpur]")
5499 (not (looking-at "end\\s-+\\w"))))
5502 ((and (looking-at "c")
5505 (not (looking-at "end\\s-+\\w")))
5506 ;; look out for the dreaded entity class in an attribute
5508 (vhdl-backward-syntactic-ws lim)
5509 (/= (preceding-char) ?:)))
5511 ;; "for" (inside configuration declaration):
5512 ((and (looking-at "f")
5515 (not (looking-at "end\\s-+\\w")))
5516 (vhdl-has-syntax 'configuration))
5520 (defun vhdl-corresponding-mid (&optional lim)
5522 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5524 ((looking-at "then")
5529 (defun vhdl-corresponding-end (&optional lim)
5530 "If the word at the current position corresponds to a \"begin\"
5531 keyword, then return a vector containing enough information to find
5532 the corresponding \"end\" keyword, else return nil. The keyword to
5533 search forward for is aref 0. The column in which the keyword must
5534 appear is aref 1 or nil if any column is suitable.
5535 Assumes that the caller will make sure that we are not in the middle
5536 of an identifier that just happens to contain a \"begin\" keyword."
5538 (and (looking-at vhdl-begin-fwd-re)
5539 (/= (preceding-char) ?_)
5540 (not (vhdl-in-literal))
5543 ;; "is", "generate", "loop":
5544 ((looking-at "[igl]")
5546 (and (vhdl-last-word (point))
5547 (or (vhdl-first-word (point))
5549 (vhdl-beginning-of-statement-1 lim)
5550 (vhdl-backward-skip-label lim)
5551 (vhdl-first-word (point)))))))
5552 ;; "begin", "else", "for":
5553 ((looking-at "be\\|[ef]")
5555 (and (vhdl-last-word (point))
5556 (or (vhdl-first-word (point))
5558 (vhdl-beginning-of-statement-1 lim)
5559 (vhdl-backward-skip-label lim)
5560 (vhdl-first-word (point)))))))
5561 ;; "component", "units", "record":
5562 ((looking-at "[cur]")
5563 ;; The first end found will close the block
5565 ;; "block", "process", "procedural":
5566 ((looking-at "bl\\|p")
5568 (or (vhdl-first-word (point))
5570 (vhdl-beginning-of-statement-1 lim)
5571 (vhdl-backward-skip-label lim)
5572 (vhdl-first-word (point))))))
5575 (vector "elsif\\|else\\|end\\s-+if"
5576 (and (vhdl-last-word (point))
5577 (or (vhdl-first-word (point))
5579 (vhdl-beginning-of-statement-1 lim)
5580 (vhdl-backward-skip-label lim)
5581 (vhdl-first-word (point)))))))
5584 (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5586 (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5588 (defun vhdl-end-p (&optional lim)
5589 "Return t if we are looking at a real \"end\" keyword.
5590 Assumes that the caller will make sure that we are looking at
5591 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5592 the middle of an identifier that just happens to contain an \"end\"
5594 (or (not (looking-at "else"))
5595 ;; make sure that the "else" isn't inside a conditional signal
5598 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5599 (or (eq (following-char) ?\;)
5600 (eq (point) lim)))))
5602 (defun vhdl-corresponding-begin (&optional lim)
5603 "If the word at the current position corresponds to an \"end\"
5604 keyword, then return a vector containing enough information to find
5605 the corresponding \"begin\" keyword, else return nil. The keyword to
5606 search backward for is aref 0. The column in which the keyword must
5607 appear is aref 1 or nil if any column is suitable. The supplementary
5608 keyword to search forward for is aref 2 or nil if this is not
5609 required. If aref 3 is t, then the \"begin\" keyword may be found in
5610 the middle of a statement.
5611 Assumes that the caller will make sure that we are not in the middle
5612 of an identifier that just happens to contain an \"end\" keyword."
5615 (if (and (looking-at vhdl-end-fwd-re)
5616 (not (vhdl-in-literal))
5618 (if (looking-at "el")
5620 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5624 (skip-chars-forward " \t\n")
5627 ((looking-at "if\\b[^_]")
5628 (vector "else\\|elsif\\|if"
5629 (vhdl-first-word pos)
5632 ((looking-at "component\\b[^_]")
5633 (vector (buffer-substring (match-beginning 1)
5635 (vhdl-first-word pos)
5637 ;; "end units", "end record":
5638 ((looking-at "\\(units\\|record\\)\\b[^_]")
5639 (vector (buffer-substring (match-beginning 1)
5641 (vhdl-first-word pos)
5643 ;; "end block", "end process", "end procedural":
5644 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
5645 (vector "begin" (vhdl-first-word pos) nil nil))
5647 ((looking-at "case\\b[^_]")
5648 (vector "case" (vhdl-first-word pos) "is" nil))
5650 ((looking-at "generate\\b[^_]")
5651 (vector "generate\\|for\\|if"
5652 (vhdl-first-word pos)
5655 ((looking-at "loop\\b[^_]")
5656 (vector "loop\\|while\\|for"
5657 (vhdl-first-word pos)
5659 ;; "end for" (inside configuration declaration):
5660 ((looking-at "for\\b[^_]")
5661 (vector "for" (vhdl-first-word pos) nil nil))
5664 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5665 (vhdl-first-word pos)
5666 ;; return an alist of (statement . keyword) mappings
5668 ;; "begin ... end [id]":
5670 ;; "architecture ... is ... begin ... end [id]":
5671 ("architecture" . "is")
5672 ;; "configuration ... is ... end [id]":
5673 ("configuration" . "is")
5674 ;; "entity ... is ... end [id]":
5676 ;; "package ... is ... end [id]":
5678 ;; "procedure ... is ... begin ... end [id]":
5679 ("procedure" . "is")
5680 ;; "function ... is ... begin ... end [id]":
5687 (defconst vhdl-leader-re
5688 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
5690 (defun vhdl-end-of-leader ()
5692 (cond ((looking-at "block\\|process\\|procedural")
5695 (skip-chars-forward " \t\n")
5696 (= (following-char) ?\())
5699 (when (looking-at "[ \t\n]*is")
5700 (goto-char (match-end 0)))
5702 ((looking-at "component")
5704 (when (looking-at "[ \t\n]*is")
5705 (goto-char (match-end 0)))
5709 (skip-chars-forward " \t\n")
5710 (while (looking-at "[,:(]")
5712 (skip-chars-forward " \t\n"))
5717 (defconst vhdl-trailer-re
5718 "\\b\\(is\\|then\\|generate\\|loop\\)\\b[^_]")
5720 (defconst vhdl-statement-fwd-re
5721 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5722 "A regular expression for searching forward that matches all known
5723 \"statement\" keywords.")
5725 (defconst vhdl-statement-bwd-re
5726 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5727 "A regular expression for searching backward that matches all known
5728 \"statement\" keywords.")
5730 (defun vhdl-statement-p (&optional lim)
5731 "Return t if we are looking at a real \"statement\" keyword.
5732 Assumes that the caller will make sure that we are looking at
5733 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5734 in the middle of an identifier that just happens to contain a
5735 \"statement\" keyword."
5737 ;; "for" ... "generate":
5738 ((and (looking-at "f")
5739 ;; Make sure it's the start of a parameter specification.
5742 (skip-chars-forward " \t\n")
5743 (looking-at "in\\b[^_]"))
5744 ;; Make sure it's not an "end for".
5747 (not (looking-at "end\\s-+\\w"))))
5749 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5750 ((and (looking-at "i")
5751 ;; Make sure it's not an "end if".
5754 (not (looking-at "end\\s-+\\w"))))
5756 ;; "while" ... "loop":
5761 (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5762 "Regexp describing a case statement alternative key.")
5764 (defun vhdl-case-alternative-p (&optional lim)
5765 "Return t if we are looking at a real case alternative.
5766 Assumes that the caller will make sure that we are looking at
5767 vhdl-case-alternative-re, and are not inside a literal, and that
5768 we are not in the middle of an identifier that just happens to
5769 contain a \"when\" keyword."
5772 (while (and (not foundp)
5773 (re-search-backward ";\\|<=" lim 'move))
5774 (if (or (= (preceding-char) ?_)
5778 (or (eq (following-char) ?\;)
5782 ;; Core syntactic movement functions:
5784 (defconst vhdl-b-t-b-re
5785 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5787 (defun vhdl-backward-to-block (&optional lim)
5788 "Move backward to the previous \"begin\" or \"end\" keyword."
5790 (while (and (not foundp)
5791 (re-search-backward vhdl-b-t-b-re lim 'move))
5792 (if (or (= (preceding-char) ?_)
5797 ((and (looking-at vhdl-begin-fwd-re)
5798 (/= (preceding-char) ?_)
5800 (setq foundp 'begin))
5802 ((and (looking-at vhdl-end-fwd-re)
5803 (/= (preceding-char) ?_)
5811 (defun vhdl-forward-sexp (&optional count lim)
5812 "Move forward across one balanced expression (sexp).
5813 With COUNT, do it that many times."
5815 (let ((count (or count 1))
5816 (case-fold-search t)
5821 (skip-chars-forward " \t\n")
5822 ;; Check for an unbalanced "end" keyword
5823 (if (and (looking-at vhdl-end-fwd-re)
5824 (/= (preceding-char) ?_)
5825 (not (vhdl-in-literal))
5827 (not (looking-at "else")))
5829 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
5830 ;; If the current keyword is a "begin" keyword, then find the
5831 ;; corresponding "end" keyword.
5832 (if (setq end-vec (vhdl-corresponding-end lim))
5834 ;; end-re is the statement keyword to search for
5836 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5837 ;; column is either the statement keyword target column
5839 (column (aref end-vec 1))
5840 (eol (vhdl-point 'eol))
5841 foundp literal placeholder)
5842 ;; Look for the statement keyword.
5843 (while (and (not foundp)
5844 (re-search-forward end-re nil t)
5845 (setq placeholder (match-end 1))
5846 (goto-char (match-beginning 0)))
5847 ;; If we are in a literal, or not in the right target
5848 ;; column and not on the same line as the begin, then
5851 (/= (current-indentation) column)
5853 (= (preceding-char) ?_)
5854 (setq literal (vhdl-in-literal)))
5855 (if (eq literal 'comment)
5858 ;; An "else" keyword corresponds to both the opening brace
5859 ;; of the following sexp and the closing brace of the
5861 (if (not (looking-at "else"))
5862 (goto-char placeholder))
5866 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
5868 ;; If the current keyword is not a "begin" keyword, then just
5869 ;; perform the normal forward-sexp.
5872 (setq count (1- count))
5874 (setq target (point)))
5878 (defun vhdl-backward-sexp (&optional count lim)
5879 "Move backward across one balanced expression (sexp).
5880 With COUNT, do it that many times. LIM bounds any required backward
5883 (let ((count (or count 1))
5884 (case-fold-search t)
5888 ;; Perform the normal backward-sexp, unless we are looking at
5889 ;; "else" - an "else" keyword corresponds to both the opening brace
5890 ;; of the following sexp and the closing brace of the previous sexp.
5891 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
5892 (/= (preceding-char) ?_)
5893 (not (vhdl-in-literal)))
5896 (if (and (looking-at vhdl-begin-fwd-re)
5897 (/= (preceding-char) ?_)
5898 (not (vhdl-in-literal))
5900 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
5901 ;; If the current keyword is an "end" keyword, then find the
5902 ;; corresponding "begin" keyword.
5903 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
5904 (/= (preceding-char) ?_))
5906 ;; begin-re is the statement keyword to search for
5908 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
5909 ;; column is either the statement keyword target column
5911 (column (aref begin-vec 1))
5912 ;; internal-p controls where the statement keyword can
5914 (internal-p (aref begin-vec 3))
5915 (last-backward (point)) last-forward
5916 foundp literal keyword)
5917 ;; Look for the statement keyword.
5918 (while (and (not foundp)
5919 (re-search-backward begin-re lim t)
5921 (buffer-substring (match-beginning 1)
5923 ;; If we are in a literal or in the wrong column,
5926 (and (/= (current-indentation) column)
5927 ;; possibly accept current-column as
5928 ;; well as current-indentation.
5929 (or (not internal-p)
5930 (/= (current-column) column))))
5931 (= (preceding-char) ?_)
5934 ;; If there is a supplementary keyword, then
5935 ;; search forward for it.
5936 (if (and (setq begin-re (aref begin-vec 2))
5937 (or (not (listp begin-re))
5938 ;; If begin-re is an alist, then find the
5939 ;; element corresponding to the actual
5940 ;; keyword that we found.
5943 (assoc keyword begin-re))
5945 (setq begin-re (cdr begin-re))))))
5948 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
5950 (setq last-forward (point))
5951 ;; Look for the supplementary keyword
5952 ;; (bounded by the backward search start
5954 (while (and (not foundp)
5955 (re-search-forward begin-re
5957 (goto-char (match-beginning 1)))
5958 ;; If we are in a literal, then try again.
5959 (if (or (= (preceding-char) ?_)
5962 (if (eq literal 'comment)
5964 (min (vhdl-point 'eol) last-backward))
5966 ;; We have found the supplementary keyword.
5967 ;; Save the position of the keyword in foundp.
5968 (setq foundp (point)))
5971 ;; If the supplementary keyword was found, then
5972 ;; move point to the supplementary keyword.
5974 ;; If there was no supplementary keyword, then
5975 ;; point is already at the statement keyword.
5977 ) ; end of the search for the statement keyword
5979 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
5981 (setq count (1- count))
5983 (setq target (point)))
5987 (defun vhdl-backward-up-list (&optional count limit)
5988 "Move backward out of one level of blocks.
5989 With argument, do this that many times."
5991 (let ((count (or count 1))
5995 (if (looking-at vhdl-defun-re)
5996 (error "ERROR: Unbalanced blocks"))
5997 (vhdl-backward-to-block limit)
5998 (setq count (1- count)))
5999 (setq target (point)))
6000 (goto-char target)))
6002 (defun vhdl-end-of-defun (&optional count)
6003 "Move forward to the end of a VHDL defun."
6005 (let ((case-fold-search t))
6006 (vhdl-beginning-of-defun)
6007 (if (not (looking-at "block\\|process\\|procedural"))
6008 (re-search-forward "\\bis\\b"))
6009 (vhdl-forward-sexp)))
6011 (defun vhdl-mark-defun ()
6012 "Put mark at end of this \"defun\", point at beginning."
6014 (let ((case-fold-search t))
6016 (vhdl-beginning-of-defun)
6018 (if (not (looking-at "block\\|process\\|procedural"))
6019 (re-search-forward "\\bis\\b"))
6021 (exchange-point-and-mark)))
6023 (defun vhdl-beginning-of-libunit ()
6024 "Move backward to the beginning of a VHDL library unit.
6025 Returns the location of the corresponding begin keyword, unless search
6026 stops due to beginning or end of buffer.
6027 Note that if point is between the \"libunit\" keyword and the
6028 corresponding \"begin\" keyword, then that libunit will not be
6029 recognized, and the search will continue backwards. If point is
6030 at the \"begin\" keyword, then the defun will be recognized. The
6031 returned point is at the first character of the \"libunit\" keyword."
6032 (let ((last-forward (point))
6034 ;; Just in case we are actually sitting on the "begin"
6035 ;; keyword, allow for the keyword and an extra character,
6036 ;; as this will be used when looking forward for the
6038 (save-excursion (forward-word 1) (1+ (point))))
6039 foundp literal placeholder)
6040 ;; Find the "libunit" keyword.
6041 (while (and (not foundp)
6042 (re-search-backward vhdl-libunit-re nil 'move))
6043 ;; If we are in a literal, or not at a real libunit, then try again.
6044 (if (or (= (preceding-char) ?_)
6046 (not (vhdl-libunit-p)))
6048 ;; Find the corresponding "begin" keyword.
6049 (setq last-forward (point))
6050 (while (and (not foundp)
6051 (re-search-forward "\\bis\\b[^_]" last-backward t)
6052 (setq placeholder (match-beginning 0)))
6053 (if (or (= (preceding-char) ?_)
6054 (setq literal (vhdl-in-literal)))
6055 ;; It wasn't a real keyword, so keep searching.
6056 (if (eq literal 'comment)
6058 (min (vhdl-point 'eol) last-backward))
6060 ;; We have found the begin keyword, loop will exit.
6061 (setq foundp placeholder)))
6062 ;; Go back to the libunit keyword
6063 (goto-char last-forward)))
6066 (defun vhdl-beginning-of-defun (&optional count)
6067 "Move backward to the beginning of a VHDL defun.
6068 With argument, do it that many times.
6069 Returns the location of the corresponding begin keyword, unless search
6070 stops due to beginning or end of buffer."
6071 ;; Note that if point is between the "defun" keyword and the
6072 ;; corresponding "begin" keyword, then that defun will not be
6073 ;; recognised, and the search will continue backwards. If point is
6074 ;; at the "begin" keyword, then the defun will be recognised. The
6075 ;; returned point is at the first character of the "defun" keyword.
6077 (let ((count (or count 1))
6078 (case-fold-search t)
6079 (last-forward (point))
6083 (goto-char last-forward)
6084 (let ((last-backward
6085 ;; Just in case we are actually sitting on the "begin"
6086 ;; keyword, allow for the keyword and an extra character,
6087 ;; as this will be used when looking forward for the
6089 (save-excursion (forward-word 1) (1+ (point))))
6090 begin-string literal)
6091 (while (and (not foundp)
6092 (re-search-backward vhdl-defun-re nil 'move))
6093 ;; If we are in a literal, then try again.
6094 (if (or (= (preceding-char) ?_)
6097 (if (setq begin-string (vhdl-corresponding-defun))
6098 ;; This is a real defun keyword.
6099 ;; Find the corresponding "begin" keyword.
6100 ;; Look for the begin keyword.
6102 ;; Save the search start point.
6103 (setq last-forward (point))
6104 (while (and (not foundp)
6105 (search-forward begin-string last-backward t))
6106 (if (or (= (preceding-char) ?_)
6108 (setq literal (vhdl-in-literal))))
6109 ;; It wasn't a real keyword, so keep searching.
6110 (if (eq literal 'comment)
6112 (min (vhdl-point 'eol) last-backward))
6114 ;; We have found the begin keyword, loop will exit.
6115 (setq foundp (match-beginning 0)))
6117 ;; Go back to the defun keyword
6118 (goto-char last-forward)) ; end search for begin keyword
6120 ) ; end of the search for the defun keyword
6122 (setq count (1- count))
6124 (vhdl-keep-region-active)
6127 (defun vhdl-beginning-of-statement (&optional count lim interactive)
6128 "Go to the beginning of the innermost VHDL statement.
6129 With prefix arg, go back N - 1 statements. If already at the
6130 beginning of a statement then go to the beginning of the preceding
6131 one. If within a string or comment, or next to a comment (only
6132 whitespace between), move by sentences instead of statements.
6134 When called from a program, this function takes 3 optional args: the
6135 prefix arg, and a buffer position limit which is the farthest back to
6136 search, and something whose meaning I don't understand."
6137 (interactive "p\np")
6138 (let ((count (or count 1))
6139 (case-fold-search t)
6140 (lim (or lim (point-min)))
6145 (setq state (parse-partial-sexp (point) here nil nil)))
6146 (if (and interactive
6149 (looking-at (concat "[ \t]*" comment-start-skip))))
6150 (forward-sentence (- count))
6152 (vhdl-beginning-of-statement-1 lim)
6153 (setq count (1- count))))
6154 ;; its possible we've been left up-buf of lim
6155 (goto-char (max (point) lim))
6157 (vhdl-keep-region-active))
6159 (defconst vhdl-e-o-s-re
6160 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6162 (defun vhdl-end-of-statement ()
6163 "Very simple implementation."
6165 (re-search-forward vhdl-e-o-s-re))
6167 (defconst vhdl-b-o-s-re
6168 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6169 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6171 (defun vhdl-beginning-of-statement-1 (&optional lim)
6172 "Move to the start of the current statement, or the previous
6173 statement if already at the beginning of one."
6174 (let ((lim (or lim (point-min)))
6178 ;; go backwards one balanced expression, but be careful of
6179 ;; unbalanced paren being reached
6180 (if (not (vhdl-safe (progn (backward-sexp) t)))
6182 (backward-up-list 1)
6184 (vhdl-forward-syntactic-ws here)
6186 (while (and (not donep)
6188 ;; look backwards for a statement boundary
6189 (re-search-backward vhdl-b-o-s-re lim 'move))
6190 (if (or (= (preceding-char) ?_)
6194 ;; If we are looking at an open paren, then stop after it
6195 ((eq (following-char) ?\()
6197 (vhdl-forward-syntactic-ws here)
6199 ;; If we are looking at a close paren, then skip it
6200 ((eq (following-char) ?\))
6205 (progn (goto-char pos)
6206 (vhdl-forward-syntactic-ws here)
6208 ;; If we are looking at a semicolon, then stop
6209 ((eq (following-char) ?\;)
6212 (vhdl-forward-syntactic-ws here)
6214 ;; If we are looking at a "begin", then stop
6215 ((and (looking-at vhdl-begin-fwd-re)
6216 (/= (preceding-char) ?_)
6218 ;; If it's a leader "begin", then find the
6220 (if (looking-at vhdl-leader-re)
6222 ;; set a default stop point at the begin
6224 ;; is the start point inside the leader area ?
6225 (goto-char (vhdl-end-of-leader))
6226 (vhdl-forward-syntactic-ws here)
6227 (if (< (point) here)
6228 ;; start point was not inside leader area
6229 ;; set stop point at word after leader
6230 (setq pos (point))))
6232 (vhdl-forward-syntactic-ws here)
6236 ;; If we are looking at a "statement", then stop
6237 ((and (looking-at vhdl-statement-fwd-re)
6238 (/= (preceding-char) ?_)
6239 (vhdl-statement-p nil))
6241 ;; If we are looking at a case alternative key, then stop
6242 ((and (looking-at vhdl-case-alternative-re)
6243 (vhdl-case-alternative-p lim))
6245 ;; set a default stop point at the when
6247 ;; is the start point inside the case alternative key ?
6248 (looking-at vhdl-case-alternative-re)
6249 (goto-char (match-end 0))
6250 (vhdl-forward-syntactic-ws here)
6251 (if (< (point) here)
6252 ;; start point was not inside the case alternative key
6253 ;; set stop point at word after case alternative keyleader
6254 (setq pos (point))))
6257 ;; Bogus find, continue
6262 ;; Defuns for calculating the current syntactic state:
6264 (defun vhdl-get-library-unit (bod placeholder)
6265 "If there is an enclosing library unit at bod, with it's \"begin\"
6266 keyword at placeholder, then return the library unit type."
6267 (let ((here (vhdl-point 'bol)))
6269 (goto-char placeholder)
6270 (vhdl-safe (vhdl-forward-sexp 1 bod))
6275 ((looking-at "e") 'entity)
6276 ((looking-at "a") 'architecture)
6277 ((looking-at "c") 'configuration)
6282 (vhdl-forward-syntactic-ws here)
6283 (if (looking-at "body\\b[^_]")
6284 'package-body 'package))))))
6287 (defun vhdl-get-block-state (&optional lim)
6288 "Finds and records all the closest opens.
6289 lim is the furthest back we need to search (it should be the
6290 previous libunit keyword)."
6291 (let ((here (point))
6292 (lim (or lim (point-min)))
6293 keyword sexp-start sexp-mid sexp-end
6294 preceding-sexp containing-sexp
6295 containing-begin containing-mid containing-paren)
6297 ;; Find the containing-paren, and use that as the limit
6298 (if (setq containing-paren
6300 (narrow-to-region lim (point))
6301 (vhdl-safe (scan-lists (point) -1 1))))
6302 (setq lim containing-paren))
6303 ;; Look backwards for "begin" and "end" keywords.
6304 (while (and (> (point) lim)
6305 (not containing-sexp))
6306 (setq keyword (vhdl-backward-to-block lim))
6308 ((eq keyword 'begin)
6309 ;; Found a "begin" keyword
6310 (setq sexp-start (point))
6311 (setq sexp-mid (vhdl-corresponding-mid lim))
6312 (setq sexp-end (vhdl-safe
6314 (vhdl-forward-sexp 1 lim) (point))))
6315 (if (and sexp-end (<= sexp-end here))
6316 ;; we want to record this sexp, but we only want to
6317 ;; record the last-most of any of them before here
6319 (setq preceding-sexp sexp-start))
6320 ;; we're contained in this sexp so put sexp-start on
6322 (setq containing-sexp sexp-start)
6323 (setq containing-mid sexp-mid)
6324 (setq containing-begin t)))
6326 ;; Found an "end" keyword
6328 (setq sexp-end (point))
6331 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6332 (progn (backward-sexp) (point))))
6333 ;; we want to record this sexp, but we only want to
6334 ;; record the last-most of any of them before here
6336 (setq preceding-sexp sexp-start)))
6338 ;; Check if the containing-paren should be the containing-sexp
6339 (if (and containing-paren
6340 (or (null containing-sexp)
6341 (< containing-sexp containing-paren)))
6342 (setq containing-sexp containing-paren
6344 containing-begin nil
6345 containing-mid nil))
6346 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6350 (defconst vhdl-s-c-a-re
6351 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6353 (defun vhdl-skip-case-alternative (&optional lim)
6354 "Skip forward over case/when bodies, with optional maximal
6355 limit. If no next case alternative is found, nil is returned and point
6357 (let ((lim (or lim (point-max)))
6360 (while (and (< (point) lim)
6362 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6364 (not (vhdl-in-literal)))
6365 (/= (match-beginning 0) here))
6367 (goto-char (match-beginning 0))
6369 ((and (looking-at "case")
6370 (re-search-forward "\\bis[^_]" lim t))
6372 (vhdl-forward-sexp))
6380 (defun vhdl-backward-skip-label (&optional lim)
6381 "Skip backward over a label, with optional maximal
6382 limit. If label is not found, nil is returned and point
6384 (let ((lim (or lim (point-min)))
6387 (vhdl-backward-syntactic-ws lim)
6388 (and (eq (preceding-char) ?:)
6391 (setq placeholder (point))
6392 (looking-at vhdl-label-key))))
6393 (goto-char placeholder))
6396 (defun vhdl-forward-skip-label (&optional lim)
6397 "Skip forward over a label, with optional maximal
6398 limit. If label is not found, nil is returned and point
6400 (let ((lim (or lim (point-max))))
6401 (if (looking-at vhdl-label-key)
6403 (goto-char (match-end 0))
6404 (vhdl-forward-syntactic-ws lim)))
6407 (defun vhdl-get-syntactic-context ()
6408 "Guess the syntactic description of the current line of VHDL code."
6412 (let* ((indent-point (point))
6413 (case-fold-search t)
6414 vec literal containing-sexp preceding-sexp
6415 containing-begin containing-mid containing-leader
6416 char-before-ip char-after-ip begin-after-ip end-after-ip
6417 placeholder lim library-unit
6420 ;; Reset the syntactic context
6421 (setq vhdl-syntactic-context nil)
6424 ;; Move to the start of the previous library unit, and
6425 ;; record the position of the "begin" keyword.
6426 (setq placeholder (vhdl-beginning-of-libunit))
6427 ;; The position of the "libunit" keyword gives us a gross
6432 ;; If there is a previous library unit, and we are enclosed by
6433 ;; it, then set the syntax accordingly.
6435 (setq library-unit (vhdl-get-library-unit lim placeholder))
6436 (vhdl-add-syntax library-unit lim))
6438 ;; Find the surrounding state.
6439 (if (setq vec (vhdl-get-block-state lim))
6441 (setq containing-sexp (aref vec 0))
6442 (setq preceding-sexp (aref vec 1))
6443 (setq containing-begin (aref vec 2))
6444 (setq containing-mid (aref vec 3))
6447 ;; set the limit on the farthest back we need to search
6448 (setq lim (if containing-sexp
6450 (goto-char containing-sexp)
6451 ;; set containing-leader if required
6452 (if (looking-at vhdl-leader-re)
6453 (setq containing-leader (vhdl-end-of-leader)))
6457 ;; cache char before and after indent point, and move point to
6458 ;; the most likely position to perform the majority of tests
6459 (goto-char indent-point)
6460 (skip-chars-forward " \t")
6461 (setq literal (vhdl-in-literal))
6462 (setq char-after-ip (following-char))
6463 (setq begin-after-ip (and
6465 (looking-at vhdl-begin-fwd-re)
6467 (setq end-after-ip (and
6469 (looking-at vhdl-end-fwd-re)
6471 (vhdl-backward-syntactic-ws lim)
6472 (setq char-before-ip (preceding-char))
6473 (goto-char indent-point)
6474 (skip-chars-forward " \t")
6476 ;; now figure out syntactic qualities of the current line
6478 ;; CASE 1: in a string or comment.
6479 ((memq literal '(string comment))
6480 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6481 ;; CASE 2: Line is at top level.
6482 ((null containing-sexp)
6483 ;; Find the point to which indentation will be relative
6485 (if (null preceding-sexp)
6487 ;; no preceding-sexp -> use the preceding statement
6488 (vhdl-beginning-of-statement-1 lim)
6490 ;; if there is a preceding-sexp then indent relative to it
6491 (goto-char preceding-sexp)
6492 ;; if not at boi, then the block-opening keyword is
6493 ;; probably following a label, so we need a different
6495 (if (/= (point) (vhdl-point 'boi))
6497 (vhdl-beginning-of-statement-1 lim)))
6498 ;; v-b-o-s could have left us at point-min
6501 (vhdl-forward-syntactic-ws indent-point))
6502 (setq placeholder (point)))
6504 ;; CASE 2A : we are looking at a block-open
6506 (vhdl-add-syntax 'block-open placeholder))
6507 ;; CASE 2B: we are looking at a block-close
6509 (vhdl-add-syntax 'block-close placeholder))
6510 ;; CASE 2C: we are looking at a top-level statement
6512 (vhdl-backward-syntactic-ws lim)
6514 (= (preceding-char) ?\;)))
6515 (vhdl-add-syntax 'statement placeholder))
6516 ;; CASE 2D: we are looking at a top-level statement-cont
6518 (vhdl-beginning-of-statement-1 lim)
6519 ;; v-b-o-s could have left us at point-min
6522 (vhdl-forward-syntactic-ws indent-point))
6523 (vhdl-add-syntax 'statement-cont (point)))
6525 ;; CASE 3: line is inside parentheses. Most likely we are
6526 ;; either in a subprogram argument (interface) list, or a
6527 ;; continued expression containing parentheses.
6528 ((null containing-begin)
6529 (vhdl-backward-syntactic-ws containing-sexp)
6531 ;; CASE 3A: we are looking at the arglist closing paren
6532 ((eq char-after-ip ?\))
6533 (goto-char containing-sexp)
6534 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6535 ;; CASE 3B: we are looking at the first argument in an empty
6537 ((eq char-before-ip ?\()
6538 (goto-char containing-sexp)
6539 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6540 ;; CASE 3C: we are looking at an arglist continuation line,
6541 ;; but the preceding argument is on the same line as the
6542 ;; opening paren. This case includes multi-line
6543 ;; expression paren groupings.
6544 ((and (save-excursion
6545 (goto-char (1+ containing-sexp))
6546 (skip-chars-forward " \t")
6548 (not (looking-at "--")))
6550 (vhdl-beginning-of-statement-1 containing-sexp)
6551 (skip-chars-backward " \t(")
6552 (<= (point) containing-sexp)))
6553 (goto-char containing-sexp)
6554 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6555 ;; CASE 3D: we are looking at just a normal arglist
6556 ;; continuation line
6557 (t (vhdl-beginning-of-statement-1 containing-sexp)
6558 (vhdl-forward-syntactic-ws indent-point)
6559 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6561 ;; CASE 4: A block mid open
6562 ((and begin-after-ip
6563 (looking-at containing-mid))
6564 (goto-char containing-sexp)
6565 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6566 (if (looking-at vhdl-trailer-re)
6568 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6569 (vhdl-backward-skip-label (vhdl-point 'boi))
6570 (vhdl-add-syntax 'block-open (point)))
6571 ;; CASE 5: block close brace
6573 (goto-char containing-sexp)
6574 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6575 (if (looking-at vhdl-trailer-re)
6577 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6578 (vhdl-backward-skip-label (vhdl-point 'boi))
6579 (vhdl-add-syntax 'block-close (point)))
6580 ;; CASE 6: A continued statement
6581 ((and (/= char-before-ip ?\;)
6582 ;; check it's not a trailer begin keyword, or a begin
6583 ;; keyword immediately following a label.
6584 (not (and begin-after-ip
6585 (or (looking-at vhdl-trailer-re)
6587 (vhdl-backward-skip-label containing-sexp)))))
6588 ;; check it's not a statement keyword
6589 (not (and (looking-at vhdl-statement-fwd-re)
6590 (vhdl-statement-p)))
6591 ;; see if the b-o-s is before the indent point
6594 (vhdl-beginning-of-statement-1 containing-sexp)
6595 ;; If we ended up after a leader, then this will
6596 ;; move us forward to the start of the first
6597 ;; statement. Note that a containing sexp here is
6598 ;; always a keyword, not a paren, so this will
6599 ;; have no effect if we hit the containing-sexp.
6600 (vhdl-forward-syntactic-ws indent-point)
6601 (setq placeholder (point))))
6602 ;; check it's not a block-intro
6603 (/= placeholder containing-sexp)
6604 ;; check it's not a case block-intro
6606 (goto-char placeholder)
6607 (or (not (looking-at vhdl-case-alternative-re))
6608 (> (match-end 0) indent-point))))
6609 ;; Make placeholder skip a label, but only if it puts us
6610 ;; before the indent point at the start of a line.
6611 (let ((new placeholder))
6612 (if (and (> indent-point
6614 (goto-char placeholder)
6615 (vhdl-forward-skip-label indent-point)
6616 (setq new (point))))
6619 (eq new (progn (back-to-indentation) (point)))))
6620 (setq placeholder new)))
6621 (vhdl-add-syntax 'statement-cont placeholder)
6623 (vhdl-add-syntax 'block-open)))
6624 ;; Statement. But what kind?
6625 ;; CASE 7: A case alternative key
6626 ((and (looking-at vhdl-case-alternative-re)
6627 (vhdl-case-alternative-p containing-sexp))
6628 ;; for a case alternative key, we set relpos to the first
6629 ;; non-whitespace char on the line containing the "case"
6631 (goto-char containing-sexp)
6632 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6633 (if (looking-at vhdl-trailer-re)
6634 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6635 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6636 ;; CASE 8: statement catchall
6638 ;; we know its a statement, but we need to find out if it is
6639 ;; the first statement in a block
6640 (if containing-leader
6641 (goto-char containing-leader)
6642 (goto-char containing-sexp)
6643 ;; Note that a containing sexp here is always a keyword,
6644 ;; not a paren, so skip over the keyword.
6646 ;; move to the start of the first statement
6647 (vhdl-forward-syntactic-ws indent-point)
6648 (setq placeholder (point))
6649 ;; we want to ignore case alternatives keys when skipping forward
6651 (while (looking-at vhdl-case-alternative-re)
6652 (setq incase-p (point))
6653 ;; we also want to skip over the body of the
6654 ;; case/when statement if that doesn't put us at
6655 ;; after the indent-point
6656 (while (vhdl-skip-case-alternative indent-point))
6657 ;; set up the match end
6658 (looking-at vhdl-case-alternative-re)
6659 (goto-char (match-end 0))
6660 ;; move to the start of the first case alternative statement
6661 (vhdl-forward-syntactic-ws indent-point)
6662 (setq placeholder (point)))
6664 ;; CASE 8A: we saw a case/when statement so we must be
6665 ;; in a switch statement. find out if we are at the
6666 ;; statement just after a case alternative key
6668 (= (point) indent-point))
6669 ;; relpos is the "when" keyword
6670 (vhdl-add-syntax 'statement-case-intro incase-p))
6671 ;; CASE 8B: any old statement
6672 ((< (point) indent-point)
6673 ;; relpos is the first statement of the block
6674 (vhdl-add-syntax 'statement placeholder)
6676 (vhdl-add-syntax 'block-open)))
6677 ;; CASE 8C: first statement in a block
6679 (goto-char containing-sexp)
6680 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6681 (if (looking-at vhdl-trailer-re)
6682 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6683 (vhdl-backward-skip-label (vhdl-point 'boi))
6684 (vhdl-add-syntax 'statement-block-intro (point))
6686 (vhdl-add-syntax 'block-open)))
6690 ;; now we need to look at any modifiers
6691 (goto-char indent-point)
6692 (skip-chars-forward " \t")
6693 (if (looking-at "--")
6694 (vhdl-add-syntax 'comment))
6695 ;; return the syntax
6696 vhdl-syntactic-context))))
6698 ;; Standard indentation line-ups:
6700 (defun vhdl-lineup-arglist (langelem)
6701 "Lineup the current arglist line with the arglist appearing just
6702 after the containing paren which starts the arglist."
6704 (let* ((containing-sexp
6706 ;; arglist-cont-nonempty gives relpos ==
6707 ;; to boi of containing-sexp paren. This
6708 ;; is good when offset is +, but bad
6709 ;; when it is vhdl-lineup-arglist, so we
6710 ;; have to special case a kludge here.
6711 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6714 (backward-up-list 1)
6715 (skip-chars-forward " \t" (vhdl-point 'eol)))
6716 (goto-char (cdr langelem)))
6718 (cs-curcol (save-excursion
6719 (goto-char (cdr langelem))
6723 (looking-at "[ \t]*)"))
6724 (progn (goto-char (match-end 0))
6727 (vhdl-forward-syntactic-ws)
6728 (- (current-column) cs-curcol))
6729 (goto-char containing-sexp)
6731 (let ((eol (vhdl-point 'eol))
6734 (skip-chars-forward " \t")
6736 (vhdl-forward-syntactic-ws)
6739 (- (current-column) cs-curcol)
6742 (defun vhdl-lineup-arglist-intro (langelem)
6743 "Lineup an arglist-intro line to just after the open paren."
6745 (let ((cs-curcol (save-excursion
6746 (goto-char (cdr langelem))
6748 (ce-curcol (save-excursion
6750 (backward-up-list 1)
6751 (skip-chars-forward " \t" (vhdl-point 'eol))
6753 (- ce-curcol cs-curcol -1))))
6755 (defun vhdl-lineup-comment (langelem)
6756 "Support old behavior for comment indentation. We look at
6757 vhdl-comment-only-line-offset to decide how to indent comment
6760 (back-to-indentation)
6761 ;; at or to the right of comment-column
6762 (if (>= (current-column) comment-column)
6763 (vhdl-comment-indent)
6764 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6766 (or (car-safe vhdl-comment-only-line-offset)
6767 vhdl-comment-only-line-offset)
6768 (or (cdr-safe vhdl-comment-only-line-offset)
6769 (car-safe vhdl-comment-only-line-offset)
6770 -1000 ;jam it against the left side
6773 (defun vhdl-lineup-statement-cont (langelem)
6774 "Line up statement-cont after the assignment operator."
6776 (let* ((relpos (cdr langelem))
6777 (assignp (save-excursion
6778 (goto-char (vhdl-point 'boi))
6779 (and (re-search-forward "\\(<\\|:\\)="
6780 (vhdl-point 'eol) t)
6781 (- (point) (vhdl-point 'boi)))))
6786 (while (and (not foundp)
6787 (< (point) (vhdl-point 'eol)))
6788 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
6789 (if (vhdl-in-literal)
6791 (if (= (preceding-char) ?\()
6792 ;; skip over any parenthesized expressions
6793 (goto-char (min (vhdl-point 'eol)
6794 (scan-lists (point) 1 1)))
6795 ;; found an assignment operator (not at eol)
6796 (setq foundp (not (looking-at "\\s-*$"))))))
6798 ;; there's no assignment operator on the line
6800 ;; calculate indentation column after assign and ws, unless
6801 ;; our line contains an assignment operator
6805 (skip-chars-forward " \t")
6807 (- (current-column) assignp curcol))
6810 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6811 ;; Progress reporting
6813 (defvar vhdl-progress-info nil
6814 "Array variable for progress information: 0 begin, 1 end, 2 time.")
6816 (defun vhdl-update-progress-info (string pos)
6817 "Update progress information."
6818 (when (and vhdl-progress-info (not noninteractive)
6819 (< vhdl-progress-interval
6820 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6821 (message (concat string "... (%2d%s)")
6822 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6823 (- (aref vhdl-progress-info 1)
6824 (aref vhdl-progress-info 0))) "%")
6825 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
6827 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6828 ;; Indentation commands
6830 (defun vhdl-electric-tab (&optional prefix-arg)
6831 "If preceeding character is part of a word or a paren then hippie-expand,
6832 else if right of non whitespace on line then insert tab,
6833 else if last command was a tab or return then dedent one step or if a comment
6834 toggle between normal indent and inline comment indent,
6835 else indent `correctly'."
6837 (vhdl-prepare-search-2
6840 ((= (char-syntax (preceding-char)) ?w)
6841 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6843 (hippie-expand-only-buffers
6844 (or (and (boundp 'hippie-expand-only-buffers)
6845 hippie-expand-only-buffers)
6847 (vhdl-expand-abbrev prefix-arg)))
6848 ;; expand parenthesis
6849 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6850 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6852 (vhdl-expand-paren prefix-arg)))
6854 ((> (current-column) (current-indentation))
6856 ;; toggle comment indent
6857 ((and (looking-at "--")
6858 (or (eq last-command 'vhdl-electric-tab)
6859 (eq last-command 'vhdl-electric-return)))
6860 (cond ((= (current-indentation) 0) ; no indent
6862 (indent-according-to-mode))
6863 ((< (current-indentation) comment-column) ; normal indent
6864 (indent-to comment-column)
6865 (indent-according-to-mode))
6866 (t ; inline comment indent
6869 ((and (>= (current-indentation) vhdl-basic-offset)
6870 (or (eq last-command 'vhdl-electric-tab)
6871 (eq last-command 'vhdl-electric-return)))
6872 (backward-delete-char-untabify vhdl-basic-offset nil))
6874 (t (indent-according-to-mode)))
6875 (setq this-command 'vhdl-electric-tab)))
6877 (defun vhdl-electric-return ()
6878 "newline-and-indent or indent-new-comment-line if in comment and preceding
6879 character is a space."
6881 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
6882 (indent-new-comment-line)
6883 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
6884 (vhdl-fix-case-word -1))
6885 (newline-and-indent)))
6887 (defun vhdl-indent-line ()
6888 "Indent the current line as VHDL code. Returns the amount of
6889 indentation change."
6891 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
6892 (pos (- (point-max) (point)))
6895 ;; indent syntax-based
6896 (if (and (eq (caar syntax) 'comment)
6897 (>= (vhdl-get-offset (car syntax)) comment-column))
6898 ;; special case: comments at or right of comment-column
6899 (vhdl-get-offset (car syntax))
6900 (apply '+ (mapcar 'vhdl-get-offset syntax)))
6901 ;; indent like previous nonblank line
6902 (save-excursion (beginning-of-line)
6903 (re-search-backward "^[^\n]" nil t)
6904 (current-indentation))))
6905 (shift-amt (- indent (current-indentation))))
6906 (and vhdl-echo-syntactic-information-p
6907 (message "syntax: %s, indent= %d" syntax indent))
6908 (unless (zerop shift-amt)
6909 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
6912 (if (< (point) (vhdl-point 'boi))
6913 (back-to-indentation)
6914 ;; If initial point was within line's indentation, position after
6915 ;; the indentation. Else stay at same point in text.
6916 (when (> (- (point-max) pos) (point))
6917 (goto-char (- (point-max) pos))))
6918 (run-hooks 'vhdl-special-indent-hook)
6919 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
6922 (defun vhdl-indent-region (beg end column)
6923 "Indent region as VHDL code.
6924 Adds progress reporting to `indent-region'."
6925 (interactive "r\nP")
6926 (when vhdl-progress-interval
6927 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
6928 (count-lines (point-min) end) 0)))
6929 (indent-region beg end column)
6930 (when vhdl-progress-interval (message "Indenting...done"))
6931 (setq vhdl-progress-info nil))
6933 (defun vhdl-indent-buffer ()
6934 "Indent whole buffer as VHDL code.
6935 Calls `indent-region' for whole buffer and adds progress reporting."
6937 (vhdl-indent-region (point-min) (point-max) nil))
6939 (defun vhdl-indent-group ()
6940 "Indent group of lines between empty lines."
6942 (let ((beg (save-excursion
6943 (if (re-search-backward vhdl-align-group-separate nil t)
6945 (point-min-marker))))
6946 (end (save-excursion
6947 (if (re-search-forward vhdl-align-group-separate nil t)
6949 (point-max-marker)))))
6950 (vhdl-indent-region beg end nil)))
6952 (defun vhdl-indent-sexp (&optional endpos)
6953 "Indent each line of the list starting just after point.
6954 If optional arg ENDPOS is given, indent each line, stopping when
6955 ENDPOS is encountered."
6959 (end (progn (vhdl-forward-sexp nil endpos) (point))))
6960 (indent-region beg end nil))))
6962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6963 ;; Miscellaneous commands
6965 (defun vhdl-show-syntactic-information ()
6966 "Show syntactic information for current line."
6968 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
6969 (vhdl-keep-region-active))
6971 ;; Verification and regression functions:
6973 (defun vhdl-regress-line (&optional arg)
6974 "Check syntactic information for current line."
6976 (let ((expected (save-excursion
6978 (when (search-backward " -- ((" (vhdl-point 'bol) t)
6980 (read (current-buffer)))))
6981 (actual (vhdl-get-syntactic-context))
6983 ;; remove the library unit symbols
6987 (if (memq (car elt) '(entity configuration package
6988 package-body architecture))
6990 (setq expurgated (append expurgated (list elt))))))
6992 (if (and (not arg) expected (listp expected))
6993 (if (not (equal expected expurgated))
6994 (error "ERROR: Should be: %s, is: %s" expected expurgated))
6997 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
6999 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7002 (insert (format "%s" expurgated))))))
7003 (vhdl-keep-region-active))
7006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7007 ;;; Alignment, whitespace fixup, beautifying
7008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7010 (defconst vhdl-align-alist
7012 ;; after some keywords
7013 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7014 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
7016 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7017 ;; after direction specifications
7018 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7019 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7020 ;; before "==", ":=", "=>", and "<="
7021 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
7022 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7023 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
7024 ;; before some keywords
7025 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7026 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7027 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7028 ;; before "=>" since "when/else ... =>" can occur
7029 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7031 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7032 It is searched in order. If REGEXP is found anywhere in the first
7033 line of a region to be aligned, ALIGN-PATTERN will be used for that
7034 region. ALIGN-PATTERN must include the whitespace to be expanded or
7035 contracted. It may also provide regexps for the text surrounding the
7036 whitespace. SUBEXP specifies which sub-expression of
7037 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7042 (defvar vhdl-align-try-all-clauses t
7043 "If REGEXP is not found on the first line of the region that clause
7044 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7046 (defun vhdl-do-group (function &optional spacing)
7047 "Apply FUNCTION on group of lines between empty lines."
7049 ;; search for group beginning
7050 ((beg (save-excursion
7051 (if (re-search-backward vhdl-align-group-separate nil t)
7052 (progn (beginning-of-line 2) (back-to-indentation) (point))
7054 ;; search for group end
7055 (end (save-excursion
7056 (if (re-search-forward vhdl-align-group-separate nil t)
7057 (progn (beginning-of-line) (point))
7060 (funcall function beg end spacing)))
7062 (defun vhdl-do-list (function &optional spacing)
7063 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7067 ;; search for beginning of balanced group of parentheses
7068 (setq beg (vhdl-re-search-backward "[()]" nil t))
7069 (while (looking-at ")")
7070 (forward-char) (backward-sexp)
7071 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7072 ;; search for end of balanced group of parentheses
7076 (goto-char (1+ beg))
7077 (skip-chars-forward " \t\n")
7078 (setq beg (point))))
7081 (funcall function beg end spacing)
7082 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7084 (defun vhdl-do-same-indent (function &optional spacing)
7085 "Apply FUNCTION to block of lines with same indent."
7086 (let ((indent (current-indentation))
7088 ;; search for first line with same indent
7090 (while (and (not (bobp))
7091 (or (looking-at "^\\s-*\\(--.*\\)?$")
7092 (= (current-indentation) indent)))
7093 (unless (looking-at "^\\s-*$")
7094 (back-to-indentation) (setq beg (point)))
7095 (beginning-of-line -0)))
7096 ;; search for last line with same indent
7098 (while (and (not (eobp))
7099 (or (looking-at "^\\s-*\\(--.*\\)?$")
7100 (= (current-indentation) indent)))
7101 (if (looking-at "^\\s-*$")
7102 (beginning-of-line 2)
7103 (beginning-of-line 2)
7104 (setq end (point)))))
7106 (funcall function beg end spacing)))
7108 (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
7109 "Attempt to align a range of lines based on the content of the
7110 lines. The definition of `alignment-list' determines the matching
7111 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7112 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7113 indentation is done before aligning."
7114 (interactive "r\np")
7115 (setq alignment-list (or alignment-list vhdl-align-alist))
7116 (setq spacing (or spacing 1))
7120 (setq end (point-marker))
7122 (setq bol (setq begin (progn (beginning-of-line) (point))))
7123 ; (untabify bol end)
7125 (indent-region bol end nil))))
7126 (let ((copy (copy-alist alignment-list)))
7127 (vhdl-prepare-search-2
7132 (eol (save-excursion (progn (end-of-line) (point)))))
7133 (setq element (nth 0 copy))
7134 (when (and (or (and (listp (car element))
7135 (memq major-mode (car element)))
7136 (eq major-mode (car element)))
7137 (or vhdl-align-try-all-clauses
7138 (re-search-forward (car (cdr element)) eol t)))
7139 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
7140 (car (cdr (cdr (cdr element)))) spacing))
7141 (setq copy (cdr copy))))))))
7143 (defun vhdl-align-region-2 (begin end match &optional substr spacing)
7144 "Align a range of lines from BEGIN to END. The regular expression
7145 MATCH must match exactly one fields: the whitespace to be
7146 contracted/expanded. The alignment column will equal the
7147 rightmost column of the widest whitespace block. SPACING is
7148 the amount of extra spaces to add to the calculated maximum required.
7149 SPACING defaults to 1 so that at least one space is inserted after
7150 the token in MATCH."
7151 (setq spacing (or spacing 1))
7152 (setq substr (or substr 1))
7154 (let (distance (max 0) (lines 0) bol eol width)
7155 ;; Determine the greatest whitespace distance to the alignment
7158 (setq eol (progn (end-of-line) (point))
7159 bol (setq begin (progn (beginning-of-line) (point))))
7162 (when (and (re-search-forward match eol t)
7163 (not (vhdl-in-literal)))
7164 (setq distance (- (match-beginning substr) bol))
7165 (when (> distance max)
7166 (setq max distance))))
7169 eol (save-excursion (end-of-line) (point)))
7170 (setq lines (1+ lines)))
7171 ;; Now insert enough maxs to push each assignment operator to
7172 ;; the same column. We need to use 'lines' as a counter, since
7173 ;; the location of the mark may change
7174 (goto-char (setq bol begin))
7175 (setq eol (save-excursion (end-of-line) (point)))
7177 (when (and (re-search-forward match eol t)
7178 (not (vhdl-in-literal)))
7179 (setq width (- (match-end substr) (match-beginning substr)))
7180 (setq distance (- (match-beginning substr) bol))
7181 (goto-char (match-beginning substr))
7183 (insert-char ? (+ (- max distance) spacing)))
7187 eol (save-excursion (end-of-line) (point)))
7188 (setq lines (1- lines))))))
7190 (defun vhdl-align-region-groups (beg end &optional spacing
7191 no-message no-comments)
7192 "Align region, treat groups of lines separately."
7193 (interactive "r\nP")
7198 (setq orig (point-marker))
7201 (setq end (point-marker))
7204 (when vhdl-progress-interval
7205 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7206 (count-lines (point-min) end) 0))))
7207 (vhdl-fixup-whitespace-region beg end t)
7209 (if (not vhdl-align-groups)
7210 ;; align entire region
7211 (progn (vhdl-align-region-1 beg end spacing)
7213 (vhdl-align-inline-comment-region-1 beg end)))
7215 (while (and (< beg end)
7216 (re-search-forward vhdl-align-group-separate end t))
7217 (setq pos (point-marker))
7218 (vhdl-align-region-1 beg pos spacing)
7219 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7220 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7225 (vhdl-align-region-1 beg end spacing)
7226 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7227 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7228 (when vhdl-indent-tabs-mode
7231 (when vhdl-progress-interval (message "Aligning...done"))
7232 (setq vhdl-progress-info nil)))))
7234 (defun vhdl-align-region (beg end &optional spacing)
7235 "Align region, treat blocks with same indent and argument lists separately."
7236 (interactive "r\nP")
7237 (if (not vhdl-align-same-indent)
7238 ;; align entire region
7239 (vhdl-align-region-groups beg end spacing)
7240 ;; align blocks with same indent and argument lists
7244 (when vhdl-progress-interval
7245 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7246 (count-lines (point-min) end) 0)))
7248 (setq end (point-marker))
7250 (while (< (point) end)
7251 ;; is argument list opening?
7252 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7253 (point) (vhdl-point 'eol)))))
7254 ;; determine region for argument list
7255 (progn (goto-char cur-beg)
7257 (setq cur-end (point))
7258 (beginning-of-line 2))
7259 ;; determine region with same indent
7260 (setq indent (current-indentation))
7261 (setq cur-beg (point))
7262 (setq cur-end (vhdl-point 'bonl))
7263 (beginning-of-line 2)
7264 (while (and (< (point) end)
7265 (or (looking-at "^\\s-*\\(--.*\\)?$")
7266 (= (current-indentation) indent))
7268 (nth 0 (parse-partial-sexp
7269 (point) (vhdl-point 'eol)))) 0))
7270 (unless (looking-at "^\\s-*$")
7271 (setq cur-end (vhdl-point 'bonl)))
7272 (beginning-of-line 2)))
7274 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7275 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7276 (when vhdl-progress-interval (message "Aligning...done"))
7277 (setq vhdl-progress-info nil)))))
7279 (defun vhdl-align-group (&optional spacing)
7280 "Align group of lines between empty lines."
7282 (vhdl-do-group 'vhdl-align-region spacing))
7284 (defun vhdl-align-list (&optional spacing)
7285 "Align the lines of a list surrounded by a balanced group of parentheses."
7287 (vhdl-do-list 'vhdl-align-region-groups spacing))
7289 (defun vhdl-align-same-indent (&optional spacing)
7290 "Align block of lines with same indent."
7292 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7294 (defun vhdl-align-declarations (&optional spacing)
7295 "Align the lines within the declarative part of a design unit."
7298 (vhdl-prepare-search-2
7300 ;; search for declarative part
7301 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7302 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7304 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7305 (setq end (point)))))
7307 (vhdl-align-region-groups beg end spacing)
7308 (error "ERROR: Not within the declarative part of a design unit"))))
7310 (defun vhdl-align-buffer ()
7313 (vhdl-align-region (point-min) (point-max)))
7315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7316 ;; Align inline comments
7318 (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7319 "Align inline comments in region."
7321 (let ((start-max comment-column)
7323 comment-list start-list tmp-list start length
7324 cur-start prev-start no-code)
7325 (setq spacing (or spacing 2))
7326 (vhdl-prepare-search-2
7328 ;; search for comment start positions and lengths
7329 (while (< (point) end)
7330 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7331 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7332 (not (save-excursion (goto-char (match-beginning 2))
7333 (vhdl-in-literal))))
7334 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7335 (setq length (- (match-end 2) (match-beginning 2)))
7336 (setq start-max (max start start-max))
7337 (setq length-max (max length length-max))
7338 (setq comment-list (cons (cons start length) comment-list)))
7339 (beginning-of-line 2))
7341 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7342 ;; reduce start positions
7343 (setq start-list (list (caar comment-list)))
7344 (setq comment-list (cdr comment-list))
7346 (unless (or (= (caar comment-list) (car start-list))
7347 (<= (+ (car start-list) (cdar comment-list))
7348 end-comment-column))
7349 (setq start-list (cons (caar comment-list) start-list)))
7350 (setq comment-list (cdr comment-list)))
7351 ;; align lines as nicely as possible
7353 (while (< (point) end)
7354 (setq cur-start nil)
7355 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7356 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7357 (not (save-excursion
7358 (goto-char (match-beginning 3))
7359 (vhdl-in-literal))))
7360 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7361 (>= (- (match-end 2) (match-beginning 2))
7363 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7364 (setq length (- (match-end 3) (match-beginning 3)))
7365 (setq no-code (= (match-beginning 1) (match-end 1)))
7366 ;; insert minimum whitespace
7367 (goto-char (match-end 2))
7368 (delete-region (match-beginning 2) (match-end 2))
7369 (insert-char ?\ spacing)
7370 (setq tmp-list start-list)
7371 ;; insert additional whitespace to align
7374 ;; align comment-only line to inline comment of previous line
7375 ((and no-code prev-start
7376 (<= length (- end-comment-column prev-start)))
7378 ;; align all comments at `start-max' if this is possible
7379 ((<= (+ start-max length-max) end-comment-column)
7381 ;; align at `comment-column' if possible
7382 ((and (<= start comment-column)
7383 (<= length (- end-comment-column comment-column)))
7385 ;; align at left-most possible start position otherwise
7387 (while (and tmp-list (< (car tmp-list) start))
7388 (setq tmp-list (cdr tmp-list)))
7390 (indent-to cur-start))
7391 (setq prev-start cur-start)
7392 (beginning-of-line 2))))))
7394 (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7395 "Align inline comments within a region. Groups of code lines separated by
7396 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7397 (interactive "r\nP")
7402 (setq orig (point-marker))
7405 (setq end (point-marker))
7407 (unless no-message (message "Aligning inline comments..."))
7409 (if (not vhdl-align-groups)
7410 ;; align entire region
7411 (vhdl-align-inline-comment-region-1 beg end spacing)
7413 (while (and (< beg end)
7414 (re-search-forward vhdl-align-group-separate end t))
7415 (setq pos (point-marker))
7416 (vhdl-align-inline-comment-region-1 beg pos spacing)
7421 (vhdl-align-inline-comment-region-1 beg end spacing)))
7422 (when vhdl-indent-tabs-mode
7424 (unless no-message (message "Aligning inline comments...done")))))
7426 (defun vhdl-align-inline-comment-group (&optional spacing)
7427 "Align inline comments within a group of lines between empty lines."
7430 (let ((start (point))
7432 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
7433 (point-marker) (point-max)))
7435 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7436 (point) (point-min)))
7438 (message "Aligning inline comments...")
7439 (vhdl-align-inline-comment-region-1 beg end)
7440 (when vhdl-indent-tabs-mode
7442 (message "Aligning inline comments...done"))))
7444 (defun vhdl-align-inline-comment-buffer ()
7445 "Align inline comments within buffer. Groups of code lines separated by
7446 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7448 (vhdl-align-inline-comment-region (point-min) (point-max)))
7450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7453 (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7454 "Fixup whitespace in region. Surround operator symbols by one space,
7455 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7456 end of line, do nothing in comments and strings."
7458 (unless no-message (message "Fixing up whitespace..."))
7461 (setq end (point-marker))
7462 ;; have no space before and one space after `,' and ';'
7464 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7465 (if (match-string 1)
7466 (goto-char (match-end 1))
7467 (replace-match "\\3 " nil nil nil 3)))
7468 ;; have no space after `('
7470 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\((\\)\\s-+" end t)
7471 (if (match-string 1)
7472 (goto-char (match-end 1))
7473 (replace-match "\\2")))
7474 ;; have no space before `)'
7476 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7477 (if (match-string 1)
7478 (goto-char (match-end 1))
7479 (replace-match "\\2")))
7480 ;; surround operator symbols by one space
7482 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7483 (if (match-string 1)
7484 (goto-char (match-end 1))
7486 (goto-char (match-beginning 4))
7487 (unless (eq (preceding-char) ?\ )
7489 (goto-char (match-end 4))
7490 (unless (eq (following-char) ?\ )
7492 (goto-char (match-end 4))))
7493 ;; eliminate multiple spaces and spaces at end of line
7495 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
7496 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
7497 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7498 (progn (replace-match "" nil nil) t))
7499 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7500 (progn (replace-match ";" nil nil) t))
7501 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7502 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
7503 (progn (replace-match " " nil nil) t))
7504 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
7505 (progn (replace-match " " nil nil) t))
7506 (re-search-forward "[^ \t-]+" end t))))
7507 (unless no-message (message "Fixing up whitespace...done")))
7509 (defun vhdl-fixup-whitespace-buffer ()
7510 "Fixup whitespace in buffer. Surround operator symbols by one space,
7511 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7512 end of line, do nothing in comments."
7514 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7519 (defun vhdl-beautify-region (beg end)
7520 "Beautify region by applying indentation, whitespace fixup, alignment, and
7521 case fixing to a region. Calls functions `vhdl-indent-buffer',
7522 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
7523 `vhdl-fix-case-buffer'."
7525 (setq end (save-excursion (goto-char end) (point-marker)))
7526 (vhdl-indent-region beg end nil)
7527 (let ((vhdl-align-groups t))
7528 (vhdl-align-region beg end))
7529 (vhdl-fix-case-region beg end))
7531 (defun vhdl-beautify-buffer ()
7532 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7533 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7536 (vhdl-beautify-region (point-min) (point-max))
7537 (when noninteractive (save-buffer)))
7539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7542 (defun vhdl-fill-region (beg end &optional arg)
7543 "Fill lines for a region of code."
7544 (interactive "r\np")
7547 (let ((margin (if arg (current-indentation) (current-column))))
7549 (setq end (point-marker))
7550 ;; remove inline comments, newlines and whitespace
7551 (vhdl-comment-kill-region beg end)
7552 (vhdl-comment-kill-inline-region beg end)
7553 (subst-char-in-region beg (1- end) ?\n ?\ )
7554 (vhdl-fixup-whitespace-region beg end)
7555 ;; wrap and end-comment-column
7557 (while (re-search-forward "\\s-" end t)
7558 (when(> (current-column) vhdl-end-comment-column)
7560 (when (re-search-backward "\\s-" beg t)
7561 (replace-match "\n")
7562 (indent-to margin)))))))
7564 (defun vhdl-fill-group ()
7565 "Fill group of lines between empty lines."
7567 (vhdl-do-group 'vhdl-fill-region))
7569 (defun vhdl-fill-list ()
7570 "Fill the lines of a list surrounded by a balanced group of parentheses."
7572 (vhdl-do-list 'vhdl-fill-region))
7574 (defun vhdl-fill-same-indent ()
7575 "Fill the lines of block of lines with same indent."
7577 (vhdl-do-same-indent 'vhdl-fill-region))
7580 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7581 ;;; Code updating/fixing
7582 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7584 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7585 ;; Sensitivity list update
7588 ;; - no sensitivity list is generated for processes with wait statements
7589 ;; - otherwise, do the following:
7590 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7591 ;; 2. scan for all signals already in the sensitivity list (in order to catch
7592 ;; manually entered global signals)
7593 ;; 3. signals from 1. and 2. form the list of visible signals
7594 ;; 4. search for if/elsif conditions containing an event (sequential code)
7595 ;; 5. scan for strings that are within syntactical regions where signals are
7596 ;; read but not within sequential code, and that correspond to visible
7598 ;; 6. replace sensitivity list by list of signals from 5.
7600 (defun vhdl-update-sensitivity-list-process ()
7601 "Update sensitivity list of current process."
7604 (vhdl-prepare-search-2
7606 ;; look whether in process
7607 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7608 (equal (upcase (match-string 2)) "PROCESS")
7609 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7610 (error "ERROR: Not within a process")
7611 (message "Updating sensitivity list...")
7612 (vhdl-update-sensitivity-list)
7613 (message "Updating sensitivity list...done")))))
7615 (defun vhdl-update-sensitivity-list-buffer ()
7616 "Update sensitivity list of all processes in current buffer."
7619 (vhdl-prepare-search-2
7620 (goto-char (point-min))
7621 (message "Updating sensitivity lists...")
7622 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7623 (goto-char (match-beginning 0))
7624 (condition-case nil (vhdl-update-sensitivity-list) (error)))
7625 (message "Updating sensitivity lists...done"))))
7627 (defun vhdl-update-sensitivity-list ()
7628 "Update sensitivity list."
7629 (let ((proc-beg (point))
7630 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7631 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7634 ;; search for wait statement (no sensitivity list allowed)
7635 ((progn (goto-char proc-mid)
7636 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7637 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7638 ;; combinational process (update sensitivity list)
7641 ;; scan for visible signals
7642 ((visible-list (vhdl-get-visible-signals))
7643 ;; define syntactic regions where signals are read
7645 '(;; right-hand side of signal/variable assignment
7646 ;; (special case: "<=" is relational operator in a condition)
7647 ((re-search-forward "[<:]=" proc-end t)
7648 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7650 ((re-search-forward "^\\s-*if\\>" proc-end t)
7651 (re-search-forward "\\<then\\>" proc-end t))
7653 ((re-search-forward "\\<elsif\\>" proc-end t)
7654 (re-search-forward "\\<then\\>" proc-end t))
7655 ;; while loop condition
7656 ((re-search-forward "^\\s-*while\\>" proc-end t)
7657 (re-search-forward "\\<loop\\>" proc-end t))
7658 ;; exit/next condition
7659 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7660 (re-search-forward ";" proc-end t))
7662 ((re-search-forward "\\<assert\\>" proc-end t)
7663 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7665 ((re-search-forward "^\\s-*case\\>" proc-end t)
7666 (re-search-forward "\\<is\\>" proc-end t))
7667 ;; parameter list of procedure call
7668 ((re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7669 (progn (backward-char) (forward-sexp) (point)))))
7670 name read-list sens-list signal-list
7671 sens-beg sens-end beg end margin)
7672 ;; scan for signals in old sensitivity list
7673 (goto-char proc-beg)
7674 (re-search-forward "\\<process\\>" proc-mid t)
7675 (if (not (looking-at "[ \t\n]*("))
7676 (setq sens-beg (point))
7677 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7678 (goto-char (match-end 1))
7680 (setq sens-end (1- (point)))
7681 (goto-char sens-beg)
7682 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7684 (cons (downcase (match-string 0)) sens-list))
7685 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7686 (setq signal-list (append visible-list sens-list))
7687 ;; search for sequential parts
7688 (goto-char proc-mid)
7689 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7690 (setq end (re-search-forward "\\<then\\>" proc-end t))
7691 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7695 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7696 (beginning-of-line)))
7697 ;; scan for signals read in process
7698 (while scan-regions-list
7699 (goto-char proc-mid)
7700 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7701 (setq end (eval (nth 1 (car scan-regions-list)))))
7703 (unless (or (vhdl-in-literal)
7704 (and seq-region-list
7705 (let ((tmp-list seq-region-list))
7706 (while (and tmp-list
7707 (< (point) (caar tmp-list)))
7708 (setq tmp-list (cdr tmp-list)))
7709 (and tmp-list (< (point) (cdar tmp-list))))))
7710 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>" end t)
7711 (setq name (match-string 1))
7712 (when (member (downcase name) signal-list)
7713 (add-to-list 'read-list name)))))
7714 (setq scan-regions-list (cdr scan-regions-list)))
7715 ;; update sensitivity list
7716 (goto-char sens-beg)
7718 (delete-region sens-beg sens-end)
7720 (insert " ()") (backward-char)))
7721 (setq read-list (sort read-list 'string<))
7723 (setq margin (current-column))
7724 (insert (car read-list))
7725 (setq read-list (cdr read-list))
7728 (if (<= (+ (current-column) (length (car read-list)) 2)
7731 (insert "\n") (indent-to margin))
7732 (insert (car read-list))
7733 (setq read-list (cdr read-list)))))))))
7735 (defun vhdl-get-visible-signals ()
7736 "Get all signals visible in the current block."
7738 (let (beg end signal-list entity-name file-name)
7739 ;; search for signals declared in surrounding block declarative parts
7741 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7743 (goto-char (match-end 2))
7744 (vhdl-backward-sexp)
7745 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7747 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7748 ;; scan for all declared signal names
7750 (while (re-search-forward "^\\s-*signal\\>" end t)
7751 (while (and (not (looking-at "[ \t\n]*:"))
7752 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7754 (cons (downcase (match-string 1)) signal-list))))
7756 ;; search for signals declared in architecture declarative part
7757 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7758 (not (equal "END" (upcase (match-string 1))))
7759 (setq entity-name (match-string 2))
7760 (setq end (re-search-forward "^begin\\>" nil t))))
7761 (error "ERROR: No architecture declarative part found")
7762 ;; scan for all declared signal names
7764 (while (re-search-forward "^\\s-*signal\\>" end t)
7765 (while (and (not (looking-at "[ \t\n]*:"))
7766 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7768 (cons (downcase (match-string 1)) signal-list)))))
7769 ;; search for signals declared in entity port clause
7770 (goto-char (point-min))
7771 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7773 (concat (vhdl-replace-string vhdl-entity-file-name entity-name)
7774 "." (file-name-extension (buffer-file-name)))))
7777 (vhdl-prepare-search-2
7778 (goto-char (point-min))
7779 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7780 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7781 (when (setq beg (re-search-forward
7782 "^\\s-*port[ \t\n]*("
7784 (re-search-forward "^end\\>" nil t)) t))
7785 (setq end (save-excursion
7786 (backward-char) (forward-sexp) (point)))
7787 (vhdl-forward-syntactic-ws)
7788 (while (< (point) end)
7789 (while (and (not (looking-at "[ \t\n]*:"))
7790 (re-search-forward "[ \t\n,]*\\(\\w+\\)" end t))
7792 (cons (downcase (match-string 1)) signal-list)))
7793 (re-search-forward ";" end 1)
7794 (vhdl-forward-syntactic-ws))))))
7797 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7798 ;; Generic/port clause fixing
7800 (defun vhdl-fix-clause ()
7801 "Fix closing parenthesis within generic/port clause."
7804 (vhdl-prepare-search-2
7807 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7808 (error "ERROR: Not within a generic/port clause")
7809 ;; search for end of clause
7810 (goto-char (match-end 0))
7811 (setq beg (1- (point)))
7812 (vhdl-forward-syntactic-ws)
7813 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7814 (goto-char (1- (match-end 0)))
7815 (setq end (point-marker))
7817 (vhdl-forward-syntactic-ws))
7819 (when (> pos (save-excursion (end-of-line) (point)))
7820 (error "ERROR: Not within a generic/port clause"))
7821 ;; delete closing parenthesis on separate line (not supported style)
7822 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7824 (vhdl-backward-syntactic-ws)
7825 (setq end (point-marker))
7827 ;; delete superfluous parentheses
7828 (while (progn (goto-char beg)
7829 (condition-case () (forward-sexp)
7830 (error (goto-char (point-max))))
7832 (delete-backward-char 1))
7833 ;; add closing parenthesis
7834 (when (> (point) end)
7838 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7841 (defun vhdl-remove-trailing-spaces ()
7842 "Remove trailing spaces in the whole buffer."
7846 (goto-char (point-min))
7847 (while (re-search-forward "[ \t]+$" (point-max) t)
7848 (unless (vhdl-in-literal)
7849 (replace-match "" nil nil))))))
7852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7854 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7856 (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
7857 "Syntax of prompt inserted by template generators.")
7859 (defvar vhdl-template-invoked-by-hook nil
7860 "Indicates whether a template has been invoked by a hook or by key or menu.
7861 Used for undoing after template abortion.")
7863 ;; correct different behavior of function `unread-command-events' in XEmacs
7864 (defun vhdl-character-to-event (arg))
7865 (defalias 'vhdl-character-to-event
7866 (if (fboundp 'character-to-event) 'character-to-event 'identity))
7868 (defun vhdl-work-library ()
7869 "Return the working library name of the current project or \"work\" if no
7870 project is defined."
7871 (vhdl-resolve-env-variable
7872 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
7874 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7875 ;; Enabling/disabling
7877 (defun vhdl-mode-line-update ()
7878 "Update the modeline string for VHDL major mode."
7879 (setq mode-name (concat "VHDL"
7880 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
7881 (and vhdl-electric-mode "e")
7882 (and vhdl-stutter-mode "s")))
7883 (force-mode-line-update t))
7885 (defun vhdl-electric-mode (arg)
7886 "Toggle VHDL electric mode.
7887 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7889 (setq vhdl-electric-mode
7890 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
7891 ((> arg 0) t) (t nil)))
7892 (vhdl-mode-line-update))
7894 (defun vhdl-stutter-mode (arg)
7895 "Toggle VHDL stuttering mode.
7896 Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7898 (setq vhdl-stutter-mode
7899 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
7900 ((> arg 0) t) (t nil)))
7901 (vhdl-mode-line-update))
7903 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7906 (defun vhdl-electric-dash (count)
7907 "-- starts a comment, --- draws a horizontal line,
7908 ---- starts a display comment"
7910 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
7912 ((and abbrev-start-location (= abbrev-start-location (point)))
7913 (setq abbrev-start-location nil)
7914 (goto-char last-abbrev-location)
7915 (beginning-of-line nil)
7916 (vhdl-comment-display))
7917 ((/= (preceding-char) ?-) ; standard dash (minus)
7918 (self-insert-command count))
7919 (t (self-insert-command count)
7920 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
7921 (let ((next-input (read-char)))
7922 (if (= next-input ?-) ; triple dash
7924 (vhdl-comment-display-line)
7926 "Enter '-' for display comment, else continue coding")
7927 (let ((next-input (read-char)))
7928 (if (= next-input ?-) ; four dashes
7929 (vhdl-comment-display t)
7930 (setq unread-command-events ; pushback the char
7931 (list (vhdl-character-to-event next-input))))))
7932 (setq unread-command-events ; pushback the char
7933 (list (vhdl-character-to-event next-input)))
7934 (vhdl-comment-insert)))))
7935 (self-insert-command count)))
7937 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
7939 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7940 (if (= (preceding-char) ?\()
7941 (progn (delete-char -1) (insert-char ?\[ 1))
7942 (insert-char ?\( 1))
7943 (self-insert-command count)))
7945 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
7947 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7949 (if (= (preceding-char) ?\))
7950 (progn (delete-char -1) (insert-char ?\] 1))
7951 (insert-char ?\) 1))
7952 (blink-matching-open))
7953 (self-insert-command count)))
7955 (defun vhdl-electric-quote (count) "'' --> \""
7957 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7958 (if (= (preceding-char) last-input-char)
7959 (progn (delete-backward-char 1) (insert-char ?\" 1))
7960 (insert-char ?\' 1))
7961 (self-insert-command count)))
7963 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
7965 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
7966 (cond ((= (preceding-char) last-input-char)
7967 (progn (delete-char -1)
7968 (unless (eq (preceding-char) ? ) (insert " "))
7970 (setq this-command 'vhdl-electric-colon)))
7972 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
7973 (progn (delete-char -1) (insert "= ")))
7974 (t (insert-char ?\; 1)))
7975 (self-insert-command count)))
7977 (defun vhdl-electric-comma (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-period (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 (defun vhdl-electric-equal (count) "'==' --> ' == '"
7999 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
8000 (cond ((= (preceding-char) last-input-char)
8001 (progn (delete-char -1)
8002 (unless (eq (preceding-char) ? ) (insert " "))
8004 (t (insert-char ?\= 1)))
8005 (self-insert-command count)))
8007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8010 (defun vhdl-template-paired-parens ()
8011 "Insert a pair of round parentheses, placing point between them."
8016 (defun vhdl-template-alias ()
8017 "Insert alias declaration."
8019 (let ((start (point)))
8020 (vhdl-insert-keyword "ALIAS ")
8021 (when (vhdl-template-field "name" nil t start (point))
8023 (unless (vhdl-template-field
8024 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8026 (delete-backward-char 3))
8027 (vhdl-insert-keyword " IS ")
8028 (vhdl-template-field "name" ";")
8029 (vhdl-comment-insert-inline))))
8031 (defun vhdl-template-architecture ()
8032 "Insert architecture."
8034 (let ((margin (current-indentation))
8037 (vhdl-insert-keyword "ARCHITECTURE ")
8038 (when (setq arch-name
8039 (vhdl-template-field "name" nil t start (point)))
8040 (vhdl-insert-keyword " OF ")
8042 (vhdl-prepare-search-1
8043 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8044 (insert (match-string 1))
8045 (vhdl-template-field "entity name"))
8046 (vhdl-insert-keyword " IS\n")
8047 (vhdl-template-begin-end
8048 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8049 (memq vhdl-insert-empty-lines '(unit all))))))
8051 (defun vhdl-template-array (kind &optional secondary)
8052 "Insert array type definition."
8054 (let ((start (point)))
8055 (vhdl-insert-keyword "ARRAY (")
8056 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8058 (vhdl-insert-keyword ") OF ")
8059 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8060 (vhdl-insert-keyword ";"))))
8062 (defun vhdl-template-assert ()
8063 "Insert an assertion statement."
8065 (let ((start (point)))
8066 (vhdl-insert-keyword "ASSERT ")
8067 (when vhdl-conditions-in-parenthesis (insert "("))
8068 (when (vhdl-template-field "condition (negated)" nil t start (point))
8069 (when vhdl-conditions-in-parenthesis (insert ")"))
8070 (setq start (point))
8071 (vhdl-insert-keyword " REPORT ")
8072 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8073 (delete-region start (point)))
8074 (setq start (point))
8075 (vhdl-insert-keyword " SEVERITY ")
8076 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8077 (delete-region start (point)))
8080 (defun vhdl-template-attribute ()
8081 "Insert an attribute declaration or specification."
8083 (if (eq (vhdl-decision-query
8084 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8085 (vhdl-template-attribute-spec)
8086 (vhdl-template-attribute-decl)))
8088 (defun vhdl-template-attribute-decl ()
8089 "Insert an attribute declaration."
8091 (let ((start (point)))
8092 (vhdl-insert-keyword "ATTRIBUTE ")
8093 (when (vhdl-template-field "name" " : " t start (point))
8094 (vhdl-template-field "type" ";")
8095 (vhdl-comment-insert-inline))))
8097 (defun vhdl-template-attribute-spec ()
8098 "Insert an attribute specification."
8100 (let ((start (point)))
8101 (vhdl-insert-keyword "ATTRIBUTE ")
8102 (when (vhdl-template-field "name" nil t start (point))
8103 (vhdl-insert-keyword " OF ")
8104 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8105 (vhdl-template-field "entity class")
8106 (vhdl-insert-keyword " IS ")
8107 (vhdl-template-field "expression" ";"))))
8109 (defun vhdl-template-block ()
8112 (let ((margin (current-indentation))
8115 (vhdl-insert-keyword ": BLOCK ")
8117 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8121 (if (vhdl-template-field "[guard expression]" nil t)
8124 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8126 (vhdl-template-begin-end "BLOCK" label margin)
8127 (vhdl-comment-block))))
8129 (defun vhdl-template-block-configuration ()
8130 "Insert a block configuration statement."
8132 (let ((margin (current-indentation))
8134 (vhdl-insert-keyword "FOR ")
8135 (when (vhdl-template-field "block name" nil t start (point))
8136 (vhdl-insert-keyword "\n\n")
8138 (vhdl-insert-keyword "END FOR;")
8140 (indent-to (+ margin vhdl-basic-offset)))))
8142 (defun vhdl-template-break ()
8143 "Insert a break statement."
8146 (vhdl-insert-keyword "BREAK")
8147 (setq position (point))
8150 (progn (vhdl-insert-keyword "FOR ")
8151 (if (vhdl-template-field "[quantity name]" " USE " t)
8152 (progn (vhdl-template-field "quantity name" " => ") t)
8153 (kill-word -1) nil))
8154 (vhdl-template-field "[quantity name]" " => " t))
8155 (vhdl-template-field "expression")
8156 (setq position (point))
8158 (delete-region position (point))
8159 (unless (vhdl-sequential-statement-p)
8160 (vhdl-insert-keyword " ON ")
8161 (if (vhdl-template-field "[sensitivity list]" nil t)
8162 (setq position (point))
8163 (delete-region position (point))))
8164 (vhdl-insert-keyword " WHEN ")
8165 (when vhdl-conditions-in-parenthesis (insert "("))
8166 (if (vhdl-template-field "[condition]" nil t)
8167 (when vhdl-conditions-in-parenthesis (insert ")"))
8168 (delete-region position (point)))
8171 (defun vhdl-template-case (&optional kind)
8172 "Insert a case statement."
8174 (let ((margin (current-indentation))
8177 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8178 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8179 (vhdl-insert-keyword "CASE ")
8180 (vhdl-insert-keyword ": CASE ")
8182 (setq label (vhdl-template-field "[label]" nil t))
8183 (unless label (delete-char 2))
8186 (when (vhdl-template-field "expression" nil t start (point))
8187 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
8189 (vhdl-insert-keyword "END CASE")
8190 (when label (insert " " label))
8193 (indent-to (+ margin vhdl-basic-offset))
8194 (vhdl-insert-keyword "WHEN ")
8195 (let ((position (point)))
8197 (indent-to (+ margin vhdl-basic-offset))
8198 (vhdl-insert-keyword "WHEN OTHERS => null;")
8199 (goto-char position)))))
8201 (defun vhdl-template-case-is ()
8202 "Insert a sequential case statement."
8204 (vhdl-template-case 'is))
8206 (defun vhdl-template-case-use ()
8207 "Insert a simultaneous case statement."
8209 (vhdl-template-case 'use))
8211 (defun vhdl-template-component ()
8212 "Insert a component declaration."
8214 (vhdl-template-component-decl))
8216 (defun vhdl-template-component-conf ()
8217 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8218 since these are almost equivalent)."
8220 (let ((margin (current-indentation))
8221 (result (vhdl-template-configuration-spec t)))
8225 (vhdl-insert-keyword "END FOR;")
8226 (when (eq result 'no-use)
8227 (end-of-line -0)))))
8229 (defun vhdl-template-component-decl ()
8230 "Insert a component declaration."
8232 (let ((margin (current-indentation))
8235 (vhdl-insert-keyword "COMPONENT ")
8236 (when (setq name (vhdl-template-field "name" nil t start (point)))
8237 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8240 (vhdl-insert-keyword "END COMPONENT")
8241 (unless (vhdl-standard-p '87) (insert " " name))
8243 (setq end-column (current-column))
8245 (indent-to (+ margin vhdl-basic-offset))
8246 (vhdl-template-generic-list t t)
8248 (indent-to (+ margin vhdl-basic-offset))
8249 (vhdl-template-port-list t)
8250 (beginning-of-line 2)
8251 (forward-char end-column))))
8253 (defun vhdl-template-component-inst ()
8254 "Insert a component instantiation statement."
8256 (let ((margin (current-indentation))
8259 (when (vhdl-template-field "instance label" nil t start (point))
8261 (if (not (vhdl-use-direct-instantiation))
8262 (vhdl-template-field "component name")
8263 ;; direct instantiation
8264 (setq unit (vhdl-template-field
8265 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8266 (setq unit (upcase (or unit "")))
8267 (cond ((equal unit "ENTITY")
8268 (vhdl-template-field "library name" "." nil nil nil nil
8269 (vhdl-work-library))
8270 (vhdl-template-field "entity name" "(")
8271 (if (vhdl-template-field "[architecture name]" nil t)
8274 ((equal unit "CONFIGURATION")
8275 (vhdl-template-field "library name" "." nil nil nil nil
8276 (vhdl-work-library))
8277 (vhdl-template-field "configuration name"))
8278 (t (vhdl-template-field "component name"))))
8280 (indent-to (+ margin vhdl-basic-offset))
8281 (setq position (point))
8282 (vhdl-insert-keyword "GENERIC ")
8283 (when (vhdl-template-map position t t)
8285 (indent-to (+ margin vhdl-basic-offset)))
8286 (setq position (point))
8287 (vhdl-insert-keyword "PORT ")
8288 (unless (vhdl-template-map position t t)
8293 (defun vhdl-template-conditional-signal-asst ()
8294 "Insert a conditional signal assignment."
8296 (when (vhdl-template-field "target signal")
8298 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8300 (let ((margin (current-column))
8303 (vhdl-template-field "waveform")
8304 (setq position (point))
8305 (vhdl-insert-keyword " WHEN ")
8306 (when vhdl-conditions-in-parenthesis (insert "("))
8307 (while (and (vhdl-template-field "[condition]" nil t)
8309 (when vhdl-conditions-in-parenthesis (insert ")"))
8310 (setq position (point))
8311 (vhdl-insert-keyword " ELSE")
8314 (vhdl-template-field "[waveform]" nil t)))
8315 (setq position (point))
8316 (vhdl-insert-keyword " WHEN ")
8317 (when vhdl-conditions-in-parenthesis (insert "(")))
8318 (delete-region position (point))
8320 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
8322 (defun vhdl-template-configuration ()
8323 "Insert a configuration specification if within an architecture,
8324 a block or component configuration if within a configuration declaration,
8325 a configuration declaration if not within a design unit."
8327 (vhdl-prepare-search-1
8329 ((and (save-excursion ; architecture body
8330 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8331 (equal "ARCHITECTURE" (upcase (match-string 1))))
8332 (vhdl-template-configuration-spec))
8333 ((and (save-excursion ; configuration declaration
8334 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8335 (equal "CONFIGURATION" (upcase (match-string 1))))
8336 (if (eq (vhdl-decision-query
8337 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8338 (vhdl-template-component-conf)
8339 (vhdl-template-block-configuration)))
8340 (t (vhdl-template-configuration-decl))))) ; otherwise
8342 (defun vhdl-template-configuration-spec (&optional optional-use)
8343 "Insert a configuration specification."
8345 (let ((margin (current-indentation))
8348 (vhdl-insert-keyword "FOR ")
8349 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
8351 (vhdl-template-field "component name" "\n")
8352 (indent-to (+ margin vhdl-basic-offset))
8353 (setq start (point))
8354 (vhdl-insert-keyword "USE ")
8355 (if (and optional-use
8356 (not (setq aspect (vhdl-template-field
8357 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8358 (progn (delete-region start (point)) 'no-use)
8359 (unless optional-use
8360 (setq aspect (vhdl-template-field
8361 "ENTITY | CONFIGURATION | OPEN" " ")))
8362 (setq aspect (upcase (or aspect "")))
8363 (cond ((equal aspect "ENTITY")
8364 (vhdl-template-field "library name" "." nil nil nil nil
8365 (vhdl-work-library))
8366 (vhdl-template-field "entity name" "(")
8367 (if (vhdl-template-field "[architecture name]" nil t)
8371 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8372 (setq position (point))
8373 (vhdl-insert-keyword "GENERIC ")
8374 (when (vhdl-template-map position t t)
8376 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8377 (setq position (point))
8378 (vhdl-insert-keyword "PORT ")
8379 (unless (vhdl-template-map position t t)
8384 ((equal aspect "CONFIGURATION")
8385 (vhdl-template-field "library name" "." nil nil nil nil
8386 (vhdl-work-library))
8387 (vhdl-template-field "configuration name" ";"))
8388 (t (delete-backward-char 1) (insert ";") t))))))
8391 (defun vhdl-template-configuration-decl ()
8392 "Insert a configuration declaration."
8394 (let ((margin (current-indentation))
8396 entity-exists string name position)
8397 (vhdl-insert-keyword "CONFIGURATION ")
8398 (when (setq name (vhdl-template-field "name" nil t start (point)))
8399 (vhdl-insert-keyword " OF ")
8401 (vhdl-prepare-search-1
8402 (setq entity-exists (vhdl-re-search-backward
8403 "\\<entity \\(\\w*\\) is\\>" nil t))
8404 (setq string (match-string 1))))
8405 (if (and entity-exists (not (equal string "")))
8407 (vhdl-template-field "entity name"))
8408 (vhdl-insert-keyword " IS\n")
8409 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8410 (indent-to (+ margin vhdl-basic-offset))
8411 (setq position (point))
8413 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8415 (vhdl-insert-keyword "END ")
8416 (unless (vhdl-standard-p '87)
8417 (vhdl-insert-keyword "CONFIGURATION "))
8419 (goto-char position))))
8421 (defun vhdl-template-constant ()
8422 "Insert a constant declaration."
8424 (let ((start (point))
8425 (in-arglist (vhdl-in-argument-list-p)))
8426 (vhdl-insert-keyword "CONSTANT ")
8427 (when (vhdl-template-field "name" nil t start (point))
8429 (when in-arglist (vhdl-insert-keyword "IN "))
8430 (vhdl-template-field "type")
8433 (vhdl-comment-insert-inline))
8434 (let ((position (point)))
8436 (unless (vhdl-template-field "[initialization]" nil t)
8437 (delete-region position (point)))
8439 (vhdl-comment-insert-inline))))))
8441 (defun vhdl-template-default ()
8450 (defun vhdl-template-default-indent ()
8451 "Insert nothing and indent."
8458 (indent-according-to-mode))
8460 (defun vhdl-template-disconnect ()
8461 "Insert a disconnect statement."
8463 (let ((start (point)))
8464 (vhdl-insert-keyword "DISCONNECT ")
8465 (when (vhdl-template-field "signal names | OTHERS | ALL"
8466 " : " t start (point))
8467 (vhdl-template-field "type")
8468 (vhdl-insert-keyword " AFTER ")
8469 (vhdl-template-field "time expression" ";"))))
8471 (defun vhdl-template-else ()
8472 "Insert an else statement."
8475 (vhdl-prepare-search-1
8476 (vhdl-insert-keyword "ELSE")
8477 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8478 (equal "WHEN" (upcase (match-string 1))))
8480 (indent-according-to-mode)
8481 (setq margin (current-indentation))
8483 (indent-to (+ margin vhdl-basic-offset))))))
8485 (defun vhdl-template-elsif ()
8486 "Insert an elsif statement."
8488 (let ((start (point))
8490 (vhdl-insert-keyword "ELSIF ")
8491 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8492 (when vhdl-conditions-in-parenthesis (insert "("))
8493 (when (vhdl-template-field "condition" nil t start (point))
8494 (when vhdl-conditions-in-parenthesis (insert ")"))
8495 (indent-according-to-mode)
8496 (setq margin (current-indentation))
8497 (vhdl-insert-keyword
8498 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8499 (indent-to (+ margin vhdl-basic-offset))))))
8501 (defun vhdl-template-entity ()
8504 (let ((margin (current-indentation))
8507 (vhdl-insert-keyword "ENTITY ")
8508 (when (setq name (vhdl-template-field "name" nil t start (point)))
8509 (vhdl-insert-keyword " IS\n\n")
8511 (vhdl-insert-keyword "END ")
8512 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8514 (setq end-column (current-column))
8516 (indent-to (+ margin vhdl-basic-offset))
8517 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8518 (indent-to (+ margin vhdl-basic-offset))
8519 (when (vhdl-template-generic-list t)
8520 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8522 (indent-to (+ margin vhdl-basic-offset))
8523 (when (vhdl-template-port-list t)
8524 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8525 (beginning-of-line 2)
8526 (forward-char end-column))))
8528 (defun vhdl-template-exit ()
8529 "Insert an exit statement."
8531 (let ((start (point)))
8532 (vhdl-insert-keyword "EXIT ")
8533 (if (vhdl-template-field "[loop label]" nil t start (point))
8534 (let ((position (point)))
8535 (vhdl-insert-keyword " WHEN ")
8536 (when vhdl-conditions-in-parenthesis (insert "("))
8537 (if (vhdl-template-field "[condition]" nil t)
8538 (when vhdl-conditions-in-parenthesis (insert ")"))
8539 (delete-region position (point))))
8543 (defun vhdl-template-file ()
8544 "Insert a file declaration."
8546 (let ((start (point)))
8547 (vhdl-insert-keyword "FILE ")
8548 (when (vhdl-template-field "name" nil t start (point))
8550 (vhdl-template-field "type")
8551 (unless (vhdl-standard-p '87)
8552 (vhdl-insert-keyword " OPEN ")
8553 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8555 (delete-backward-char 6)))
8556 (vhdl-insert-keyword " IS ")
8557 (when (vhdl-standard-p '87)
8558 (vhdl-template-field "[IN | OUT]" " " t))
8559 (vhdl-template-field "filename-string" nil nil nil nil t)
8561 (vhdl-comment-insert-inline))))
8563 (defun vhdl-template-for ()
8564 "Insert a block or component configuration if within a configuration
8565 declaration, a configuration specification if within an architecture
8566 declarative part (and not within a subprogram), a for-loop if within a
8567 sequential statement part (subprogram or process), and a for-generate
8570 (vhdl-prepare-search-1
8572 ((vhdl-sequential-statement-p) ; sequential statement
8573 (vhdl-template-for-loop))
8574 ((and (save-excursion ; configuration declaration
8575 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8576 (equal "CONFIGURATION" (upcase (match-string 1))))
8577 (if (eq (vhdl-decision-query
8578 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8579 (vhdl-template-component-conf)
8580 (vhdl-template-block-configuration)))
8581 ((and (save-excursion
8582 (re-search-backward ; architecture declarative part
8583 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8584 (equal "ARCHITECTURE" (upcase (match-string 1))))
8585 (vhdl-template-configuration-spec))
8586 (t (vhdl-template-for-generate))))) ; concurrent statement
8588 (defun vhdl-template-for-generate ()
8589 "Insert a for-generate."
8591 (let ((margin (current-indentation))
8594 (vhdl-insert-keyword ": FOR ")
8595 (setq position (point-marker))
8597 (when (setq label (vhdl-template-field "label" nil t start position))
8598 (goto-char position)
8599 (vhdl-template-field "loop variable")
8600 (vhdl-insert-keyword " IN ")
8601 (vhdl-template-field "range")
8602 (vhdl-template-generate-body margin label))))
8604 (defun vhdl-template-for-loop ()
8605 "Insert a for loop."
8607 (let ((margin (current-indentation))
8610 (if (not (eq vhdl-optional-labels 'all))
8611 (vhdl-insert-keyword "FOR ")
8612 (vhdl-insert-keyword ": FOR ")
8614 (setq label (vhdl-template-field "[label]" nil t))
8615 (unless label (delete-char 2))
8618 (when (setq index (vhdl-template-field "loop variable"
8619 nil t start (point)))
8620 (vhdl-insert-keyword " IN ")
8621 (vhdl-template-field "range")
8622 (vhdl-insert-keyword " LOOP\n\n")
8624 (vhdl-insert-keyword "END LOOP")
8626 (insert " " label ";")
8628 (when vhdl-self-insert-comments (insert " -- " index)))
8630 (indent-to (+ margin vhdl-basic-offset)))))
8632 (defun vhdl-template-function (&optional kind)
8633 "Insert a function declaration or body."
8635 (let ((margin (current-indentation))
8638 (vhdl-insert-keyword "FUNCTION ")
8639 (when (setq name (vhdl-template-field "name" nil t start (point)))
8640 (vhdl-template-argument-list t)
8641 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8644 (indent-to (+ margin vhdl-basic-offset))
8645 (vhdl-insert-keyword "RETURN ")
8646 (vhdl-template-field "type")
8647 (if (if kind (eq kind 'body)
8648 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
8649 (progn (vhdl-insert-keyword " IS\n")
8650 (vhdl-template-begin-end
8651 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8652 (vhdl-comment-block))
8655 (defun vhdl-template-function-decl ()
8656 "Insert a function declaration."
8658 (vhdl-template-function 'decl))
8660 (defun vhdl-template-function-body ()
8661 "Insert a function declaration."
8663 (vhdl-template-function 'body))
8665 (defun vhdl-template-generate ()
8666 "Insert a generation scheme."
8668 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8669 (vhdl-template-if-generate)
8670 (vhdl-template-for-generate)))
8672 (defun vhdl-template-generic ()
8673 "Insert generic declaration, or generic map in instantiation statements."
8675 (let ((start (point)))
8676 (vhdl-prepare-search-1
8678 ((and (save-excursion ; entity declaration
8679 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8680 (equal "ENTITY" (upcase (match-string 1))))
8681 (vhdl-template-generic-list nil))
8682 ((or (save-excursion
8683 (or (beginning-of-line)
8684 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
8685 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
8686 (vhdl-insert-keyword "GENERIC ")
8687 (vhdl-template-map start))
8688 (t (vhdl-template-generic-list nil t))))))
8690 (defun vhdl-template-group ()
8691 "Insert group or group template declaration."
8693 (let ((start (point)))
8694 (if (eq (vhdl-decision-query
8695 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8696 (vhdl-template-group-template)
8697 (vhdl-template-group-decl))))
8699 (defun vhdl-template-group-decl ()
8700 "Insert group declaration."
8702 (let ((start (point)))
8703 (vhdl-insert-keyword "GROUP ")
8704 (when (vhdl-template-field "name" " : " t start (point))
8705 (vhdl-template-field "template name" " (")
8706 (vhdl-template-field "constituent list" ");")
8707 (vhdl-comment-insert-inline))))
8709 (defun vhdl-template-group-template ()
8710 "Insert group template declaration."
8712 (let ((start (point)))
8713 (vhdl-insert-keyword "GROUP ")
8714 (when (vhdl-template-field "template name" nil t start (point))
8715 (vhdl-insert-keyword " IS (")
8716 (vhdl-template-field "entity class list" ");")
8717 (vhdl-comment-insert-inline))))
8719 (defun vhdl-template-if ()
8720 "Insert a sequential if statement or an if-generate statement."
8722 (if (vhdl-sequential-statement-p)
8723 (vhdl-template-if-then)
8724 (if (and (vhdl-standard-p 'ams)
8725 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8726 (vhdl-template-if-use)
8727 (vhdl-template-if-generate))))
8729 (defun vhdl-template-if-generate ()
8730 "Insert an if-generate."
8732 (let ((margin (current-indentation))
8735 (vhdl-insert-keyword ": IF ")
8736 (setq position (point-marker))
8738 (when (setq label (vhdl-template-field "label" nil t start position))
8739 (goto-char position)
8740 (when vhdl-conditions-in-parenthesis (insert "("))
8741 (vhdl-template-field "condition")
8742 (when vhdl-conditions-in-parenthesis (insert ")"))
8743 (vhdl-template-generate-body margin label))))
8745 (defun vhdl-template-if-then-use (kind)
8746 "Insert a sequential if statement."
8748 (let ((margin (current-indentation))
8751 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8752 (vhdl-insert-keyword "IF ")
8753 (vhdl-insert-keyword ": IF ")
8755 (setq label (vhdl-template-field "[label]" nil t))
8756 (unless label (delete-char 2))
8759 (when vhdl-conditions-in-parenthesis (insert "("))
8760 (when (vhdl-template-field "condition" nil t start (point))
8761 (when vhdl-conditions-in-parenthesis (insert ")"))
8762 (vhdl-insert-keyword
8763 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
8765 (vhdl-insert-keyword "END IF")
8766 (when label (insert " " label))
8769 (indent-to (+ margin vhdl-basic-offset)))))
8771 (defun vhdl-template-if-then ()
8772 "Insert a sequential if statement."
8774 (vhdl-template-if-then-use 'then))
8776 (defun vhdl-template-if-use ()
8777 "Insert a simultaneous if statement."
8779 (vhdl-template-if-then-use 'use))
8781 (defun vhdl-template-instance ()
8782 "Insert a component instantiation statement."
8784 (vhdl-template-component-inst))
8786 (defun vhdl-template-library ()
8787 "Insert a library specification."
8789 (let ((margin (current-indentation))
8792 (vhdl-insert-keyword "LIBRARY ")
8793 (when (setq name (vhdl-template-field "names" nil t start (point)))
8795 (unless (string-match "," name)
8796 (setq end-pos (point))
8799 (vhdl-insert-keyword "USE ")
8801 (vhdl-insert-keyword "..ALL;")
8803 (if (vhdl-template-field "package name")
8805 (delete-region end-pos (+ (point) 5)))))))
8807 (defun vhdl-template-limit ()
8810 (let ((start (point)))
8811 (vhdl-insert-keyword "LIMIT ")
8812 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8814 (vhdl-template-field "type")
8815 (vhdl-insert-keyword " WITH ")
8816 (vhdl-template-field "real expression" ";"))))
8818 (defun vhdl-template-loop ()
8821 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8823 (vhdl-template-while-loop))
8825 (vhdl-template-for-loop))
8826 (t (vhdl-template-bare-loop)))))
8828 (defun vhdl-template-bare-loop ()
8831 (let ((margin (current-indentation))
8834 (if (not (eq vhdl-optional-labels 'all))
8835 (vhdl-insert-keyword "LOOP ")
8836 (vhdl-insert-keyword ": LOOP ")
8838 (setq label (vhdl-template-field "[label]" nil t))
8839 (unless label (delete-char 2))
8844 (vhdl-insert-keyword "END LOOP")
8845 (insert (if label (concat " " label ";") ";"))
8847 (indent-to (+ margin vhdl-basic-offset))))
8849 (defun vhdl-template-map (&optional start optional secondary)
8850 "Insert a map specification with association list."
8852 (let ((start (or start (point)))
8854 (vhdl-insert-keyword "MAP (")
8855 (if (not vhdl-association-list-with-formals)
8856 (if (vhdl-template-field
8857 (concat (and optional "[") "association list" (and optional "]"))
8858 ")" (or (not secondary) optional)
8859 (and (not secondary) start) (point))
8861 (if (and optional secondary) (delete-region start (point)))
8863 (if vhdl-argument-list-indent
8864 (setq margin (current-column))
8865 (setq margin (+ (current-indentation) vhdl-basic-offset))
8868 (if (vhdl-template-field
8869 (concat (and optional "[") "formal" (and optional "]"))
8870 " => " (or (not secondary) optional)
8871 (and (not secondary) start) (point))
8873 (vhdl-template-field "actual" ",")
8874 (setq end-pos (point))
8877 (while (vhdl-template-field "[formal]" " => " t)
8878 (vhdl-template-field "actual" ",")
8879 (setq end-pos (point))
8882 (delete-region end-pos (point))
8883 (delete-backward-char 1)
8885 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
8887 (when (and optional secondary) (delete-region start (point)))
8890 (defun vhdl-template-modify (&optional noerror)
8891 "Actualize modification date."
8893 (vhdl-prepare-search-2
8895 (goto-char (point-min))
8896 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
8897 (progn (delete-region (point) (progn (end-of-line) (point)))
8898 (vhdl-template-insert-date))
8900 (error (concat "ERROR: Modification date prefix string \""
8901 vhdl-modify-date-prefix-string "\" not found")))))))
8903 (defun vhdl-template-modify-noerror ()
8904 "Call `vhdl-template-modify' with NOERROR non-nil."
8905 (vhdl-template-modify t))
8907 (defun vhdl-template-nature ()
8908 "Insert a nature declaration."
8910 (let ((start (point))
8911 name mid-pos end-pos)
8912 (vhdl-insert-keyword "NATURE ")
8913 (when (setq name (vhdl-template-field "name" nil t start (point)))
8914 (vhdl-insert-keyword " IS ")
8917 (or (vhdl-template-field
8918 "across type | ARRAY | RECORD")
8920 (cond ((equal definition "")
8922 ((equal definition "ARRAY")
8924 (vhdl-template-array 'nature t))
8925 ((equal definition "RECORD")
8926 (setq mid-pos (point-marker))
8928 (vhdl-template-record 'nature name t))
8930 (vhdl-insert-keyword " ACROSS ")
8931 (vhdl-template-field "through type")
8932 (vhdl-insert-keyword " THROUGH ")
8933 (vhdl-template-field "reference name")
8934 (vhdl-insert-keyword " REFERENCE;")))
8936 (setq end-pos (point-marker))
8939 (vhdl-comment-insert-inline)
8940 (when end-pos (goto-char end-pos))))))
8942 (defun vhdl-template-next ()
8943 "Insert a next statement."
8945 (let ((start (point)))
8946 (vhdl-insert-keyword "NEXT ")
8947 (if (vhdl-template-field "[loop label]" nil t start (point))
8948 (let ((position (point)))
8949 (vhdl-insert-keyword " WHEN ")
8950 (when vhdl-conditions-in-parenthesis (insert "("))
8951 (if (vhdl-template-field "[condition]" nil t)
8952 (when vhdl-conditions-in-parenthesis (insert ")"))
8953 (delete-region position (point))))
8957 (defun vhdl-template-others ()
8958 "Insert an others aggregate."
8960 (let ((start (point)))
8961 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
8962 (progn (unless vhdl-template-invoked-by-hook (insert "("))
8963 (vhdl-insert-keyword "OTHERS => '")
8964 (when (vhdl-template-field "value" nil t start (point))
8966 (vhdl-insert-keyword "OTHERS "))))
8968 (defun vhdl-template-package (&optional kind)
8969 "Insert a package specification or body."
8971 (let ((margin (current-indentation))
8974 (vhdl-insert-keyword "PACKAGE ")
8975 (setq body (if kind (eq kind 'body)
8976 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
8978 (vhdl-insert-keyword "BODY ")
8979 (when (save-excursion
8980 (vhdl-prepare-search-1
8981 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
8982 (insert (setq name (match-string 1)))))
8984 (setq name (vhdl-template-field "name" nil t start (point))))
8985 (vhdl-insert-keyword " IS\n")
8986 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8987 (indent-to (+ margin vhdl-basic-offset))
8988 (setq position (point))
8990 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8992 (vhdl-insert-keyword "END ")
8993 (unless (vhdl-standard-p '87)
8994 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
8995 (insert (or name "") ";")
8996 (goto-char position))))
8998 (defun vhdl-template-package-decl ()
8999 "Insert a package specification."
9001 (vhdl-template-package 'decl))
9003 (defun vhdl-template-package-body ()
9004 "Insert a package body."
9006 (vhdl-template-package 'body))
9008 (defun vhdl-template-port ()
9009 "Insert a port declaration, or port map in instantiation statements."
9011 (let ((start (point)))
9012 (vhdl-prepare-search-1
9014 ((and (save-excursion ; entity declaration
9015 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9016 (equal "ENTITY" (upcase (match-string 1))))
9017 (vhdl-template-port-list nil))
9018 ((or (save-excursion
9019 (or (beginning-of-line)
9020 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9021 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
9022 (vhdl-insert-keyword "PORT ")
9023 (vhdl-template-map start))
9024 (t (vhdl-template-port-list nil))))))
9026 (defun vhdl-template-procedural ()
9027 "Insert a procedural."
9029 (let ((margin (current-indentation))
9031 (case-fold-search t)
9033 (vhdl-insert-keyword "PROCEDURAL ")
9034 (when (memq vhdl-optional-labels '(process all))
9038 (setq label (vhdl-template-field "[label]" nil t))
9039 (unless label (delete-char 2))
9042 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9044 (vhdl-template-begin-end "PROCEDURAL" label margin)
9045 (vhdl-comment-block)))
9047 (defun vhdl-template-procedure (&optional kind)
9048 "Insert a procedure declaration or body."
9050 (let ((margin (current-indentation))
9053 (vhdl-insert-keyword "PROCEDURE ")
9054 (when (setq name (vhdl-template-field "name" nil t start (point)))
9055 (vhdl-template-argument-list)
9056 (if (if kind (eq kind 'body)
9057 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9058 (progn (vhdl-insert-keyword " IS")
9059 (when vhdl-auto-align
9060 (vhdl-align-region-groups start (point) 1))
9061 (end-of-line) (insert "\n")
9062 (vhdl-template-begin-end
9063 (unless (vhdl-standard-p '87) "PROCEDURE")
9065 (vhdl-comment-block))
9067 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
9070 (defun vhdl-template-procedure-decl ()
9071 "Insert a procedure declaration."
9073 (vhdl-template-procedure 'decl))
9075 (defun vhdl-template-procedure-body ()
9076 "Insert a procedure body."
9078 (vhdl-template-procedure 'body))
9080 (defun vhdl-template-process (&optional kind)
9083 (let ((margin (current-indentation))
9085 label seq input-signals clock reset final-pos)
9086 (setq seq (if kind (eq kind 'seq)
9087 (eq (vhdl-decision-query
9088 "process" "(c)ombinational or (s)equential?" t) ?s)))
9089 (vhdl-insert-keyword "PROCESS ")
9090 (when (memq vhdl-optional-labels '(process all))
9094 (setq label (vhdl-template-field "[label]" nil t))
9095 (unless label (delete-char 2))
9100 (unless (setq input-signals
9101 (vhdl-template-field "[sensitivity list]" ")" t))
9102 (setq input-signals "")
9104 (setq clock (or (and (not (equal "" vhdl-clock-name))
9105 (progn (insert vhdl-clock-name) vhdl-clock-name))
9106 (vhdl-template-field "clock name") "<clock>"))
9107 (when (eq vhdl-reset-kind 'async)
9109 (setq reset (or (and (not (equal "" vhdl-reset-name))
9110 (progn (insert vhdl-reset-name) vhdl-reset-name))
9111 (vhdl-template-field "reset name") "<reset>")))
9113 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9115 (vhdl-template-begin-end "PROCESS" label margin)
9116 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9117 (when vhdl-prompt-for-comments
9118 (setq final-pos (point-marker))
9119 (vhdl-prepare-search-2
9120 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9121 (vhdl-re-search-backward "\\<process\\>" nil t))
9124 (progn (insert "\n") (forward-line -1))
9127 (insert "-- purpose: ")
9128 (if (not (vhdl-template-field "[description]" nil t))
9129 (vhdl-line-kill-entire)
9132 (insert "-- type : ")
9133 (insert (if seq "sequential" "combinational") "\n")
9135 (insert "-- inputs : ")
9137 (insert input-signals)
9139 (when reset (insert reset ", "))
9140 (unless (vhdl-template-field "[signal names]" nil t)
9144 (insert "-- outputs: ")
9145 (vhdl-template-field "[signal names]" nil t))))
9146 (goto-char final-pos))))
9148 (defun vhdl-template-process-comb ()
9149 "Insert a combinational process."
9151 (vhdl-template-process 'comb))
9153 (defun vhdl-template-process-seq ()
9154 "Insert a sequential process."
9156 (vhdl-template-process 'seq))
9158 (defun vhdl-template-quantity ()
9159 "Insert a quantity declaration."
9161 (if (vhdl-in-argument-list-p)
9162 (let ((start (point)))
9163 (vhdl-insert-keyword "QUANTITY ")
9164 (when (vhdl-template-field "names" nil t start (point))
9166 (vhdl-template-field "[IN | OUT]" " " t)
9167 (vhdl-template-field "type")
9169 (vhdl-comment-insert-inline)))
9170 (let ((char (vhdl-decision-query
9171 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9172 (cond ((eq char ?f) (vhdl-template-quantity-free))
9173 ((eq char ?b) (vhdl-template-quantity-branch))
9174 ((eq char ?s) (vhdl-template-quantity-source))
9175 (t (vhdl-template-undo (point) (point)))))))
9177 (defun vhdl-template-quantity-free ()
9178 "Insert a free quantity declaration."
9180 (vhdl-insert-keyword "QUANTITY ")
9181 (vhdl-template-field "names")
9183 (vhdl-template-field "type")
9184 (let ((position (point)))
9186 (unless (vhdl-template-field "[initialization]" nil t)
9187 (delete-region position (point)))
9189 (vhdl-comment-insert-inline)))
9191 (defun vhdl-template-quantity-branch ()
9192 "Insert a branch quantity declaration."
9195 (vhdl-insert-keyword "QUANTITY ")
9196 (when (vhdl-template-field "[across names]" " " t)
9197 (vhdl-insert-keyword "ACROSS "))
9198 (when (vhdl-template-field "[through names]" " " t)
9199 (vhdl-insert-keyword "THROUGH "))
9200 (vhdl-template-field "plus terminal name")
9201 (setq position (point))
9202 (vhdl-insert-keyword " TO ")
9203 (unless (vhdl-template-field "[minus terminal name]" nil t)
9204 (delete-region position (point)))
9206 (vhdl-comment-insert-inline)))
9208 (defun vhdl-template-quantity-source ()
9209 "Insert a source quantity declaration."
9211 (vhdl-insert-keyword "QUANTITY ")
9212 (vhdl-template-field "names")
9214 (vhdl-template-field "type" " ")
9215 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9216 (progn (vhdl-insert-keyword "NOISE ")
9217 (vhdl-template-field "power expression"))
9218 (vhdl-insert-keyword "SPECTRUM ")
9219 (vhdl-template-field "magnitude expression" ", ")
9220 (vhdl-template-field "phase expression"))
9222 (vhdl-comment-insert-inline))
9224 (defun vhdl-template-record (kind &optional name secondary)
9225 "Insert a record type declaration."
9227 (let ((margin (current-column))
9230 (vhdl-insert-keyword "RECORD\n")
9231 (indent-to (+ margin vhdl-basic-offset))
9232 (when (or (vhdl-template-field "element names"
9233 nil (not secondary) start (point))
9235 (while (or first (vhdl-template-field "[element names]" nil t))
9237 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9238 (vhdl-comment-insert-inline)
9240 (indent-to (+ margin vhdl-basic-offset))
9244 (vhdl-insert-keyword "END RECORD")
9245 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9247 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9249 (defun vhdl-template-report ()
9250 "Insert a report statement."
9252 (let ((start (point)))
9253 (vhdl-insert-keyword "REPORT ")
9254 (if (equal "\"\"" (vhdl-template-field
9255 "string expression" nil t start (point) t))
9256 (delete-backward-char 2)
9257 (setq start (point))
9258 (vhdl-insert-keyword " SEVERITY ")
9259 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9260 (delete-region start (point)))
9263 (defun vhdl-template-return ()
9264 "Insert a return statement."
9266 (let ((start (point)))
9267 (vhdl-insert-keyword "RETURN ")
9268 (unless (vhdl-template-field "[expression]" nil t start (point))
9272 (defun vhdl-template-selected-signal-asst ()
9273 "Insert a selected signal assignment."
9275 (let ((margin (current-indentation))
9278 (let ((position (point)))
9279 (vhdl-insert-keyword " SELECT ")
9280 (goto-char position))
9281 (vhdl-insert-keyword "WITH ")
9282 (when (vhdl-template-field "selector expression"
9283 nil t start (+ (point) 7))
9287 (indent-to (+ margin vhdl-basic-offset))
9288 (vhdl-template-field "target signal" " <= ")
9289 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9291 (indent-to (+ margin vhdl-basic-offset))
9292 (vhdl-template-field "waveform")
9293 (vhdl-insert-keyword " WHEN ")
9294 (vhdl-template-field "choices" ",")
9296 (indent-to (+ margin vhdl-basic-offset))
9297 (while (and choices (vhdl-template-field "[waveform]" nil t))
9298 (vhdl-insert-keyword " WHEN ")
9299 (if (setq choices (vhdl-template-field "[choices]" "," t))
9300 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9301 (vhdl-insert-keyword "OTHERS")))
9306 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
9308 (defun vhdl-template-signal ()
9309 "Insert a signal declaration."
9311 (let ((start (point))
9312 (in-arglist (vhdl-in-argument-list-p)))
9313 (vhdl-insert-keyword "SIGNAL ")
9314 (when (vhdl-template-field "names" nil t start (point))
9316 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9317 (vhdl-template-field "type")
9320 (vhdl-comment-insert-inline))
9321 (let ((position (point)))
9323 (unless (vhdl-template-field "[initialization]" nil t)
9324 (delete-region position (point)))
9326 (vhdl-comment-insert-inline))))))
9328 (defun vhdl-template-subnature ()
9329 "Insert a subnature declaration."
9331 (let ((start (point))
9333 (vhdl-insert-keyword "SUBNATURE ")
9334 (when (vhdl-template-field "name" nil t start (point))
9335 (vhdl-insert-keyword " IS ")
9336 (vhdl-template-field "nature" " (")
9337 (if (vhdl-template-field "[index range]" nil t)
9340 (setq position (point))
9341 (vhdl-insert-keyword " TOLERANCE ")
9342 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9344 (delete-region position (point))
9345 (vhdl-insert-keyword " ACROSS ")
9346 (vhdl-template-field "string expression" nil nil nil nil t)
9347 (vhdl-insert-keyword " THROUGH"))
9349 (vhdl-comment-insert-inline))))
9351 (defun vhdl-template-subprogram-body ()
9352 "Insert a subprogram body."
9354 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9355 (vhdl-template-function-body)
9356 (vhdl-template-procedure-body)))
9358 (defun vhdl-template-subprogram-decl ()
9359 "Insert a subprogram declaration."
9361 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9362 (vhdl-template-function-decl)
9363 (vhdl-template-procedure-decl)))
9365 (defun vhdl-template-subtype ()
9366 "Insert a subtype declaration."
9368 (let ((start (point)))
9369 (vhdl-insert-keyword "SUBTYPE ")
9370 (when (vhdl-template-field "name" nil t start (point))
9371 (vhdl-insert-keyword " IS ")
9372 (vhdl-template-field "type" " ")
9374 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
9377 (vhdl-comment-insert-inline))))
9379 (defun vhdl-template-terminal ()
9380 "Insert a terminal declaration."
9382 (let ((start (point)))
9383 (vhdl-insert-keyword "TERMINAL ")
9384 (when (vhdl-template-field "names" nil t start (point))
9386 (vhdl-template-field "nature")
9388 (vhdl-comment-insert-inline))))
9390 (defun vhdl-template-type ()
9391 "Insert a type declaration."
9393 (let ((start (point))
9394 name mid-pos end-pos)
9395 (vhdl-insert-keyword "TYPE ")
9396 (when (setq name (vhdl-template-field "name" nil t start (point)))
9397 (vhdl-insert-keyword " IS ")
9400 (or (vhdl-template-field
9401 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9403 (cond ((equal definition "")
9404 (delete-backward-char 4)
9406 ((equal definition "ARRAY")
9408 (vhdl-template-array 'type t))
9409 ((equal definition "RECORD")
9410 (setq mid-pos (point-marker))
9412 (vhdl-template-record 'type name t))
9413 ((equal definition "ACCESS")
9415 (vhdl-template-field "type" ";"))
9416 ((equal definition "FILE")
9417 (vhdl-insert-keyword " OF ")
9418 (vhdl-template-field "type" ";"))
9421 (setq end-pos (point-marker))
9424 (vhdl-comment-insert-inline)
9425 (when end-pos (goto-char end-pos))))))
9427 (defun vhdl-template-use ()
9428 "Insert a use clause."
9430 (let ((start (point)))
9431 (vhdl-prepare-search-1
9432 (vhdl-insert-keyword "USE ")
9433 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9434 (vhdl-insert-keyword "..ALL;")
9436 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9438 (vhdl-template-field "package name")
9439 (forward-char 5))))))
9441 (defun vhdl-template-variable ()
9442 "Insert a variable declaration."
9444 (let ((start (point))
9445 (in-arglist (vhdl-in-argument-list-p)))
9446 (vhdl-prepare-search-2
9447 (if (or (save-excursion
9448 (and (vhdl-re-search-backward
9449 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9451 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9452 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9453 (vhdl-insert-keyword "VARIABLE ")
9454 (vhdl-insert-keyword "SHARED VARIABLE ")))
9455 (when (vhdl-template-field "names" nil t start (point))
9457 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9458 (vhdl-template-field "type")
9461 (vhdl-comment-insert-inline))
9462 (let ((position (point)))
9464 (unless (vhdl-template-field "[initialization]" nil t)
9465 (delete-region position (point)))
9467 (vhdl-comment-insert-inline))))))
9469 (defun vhdl-template-wait ()
9470 "Insert a wait statement."
9472 (vhdl-insert-keyword "WAIT ")
9473 (unless (vhdl-template-field
9474 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9479 (defun vhdl-template-when ()
9480 "Indent correctly if within a case statement."
9482 (let ((position (point))
9484 (vhdl-prepare-search-2
9485 (if (and (= (current-column) (current-indentation))
9486 (vhdl-re-search-forward "\\<end\\>" nil t)
9487 (looking-at "\\s-*\\<case\\>"))
9489 (setq margin (current-indentation))
9490 (goto-char position)
9491 (delete-horizontal-space)
9492 (indent-to (+ margin vhdl-basic-offset)))
9493 (goto-char position)))
9494 (vhdl-insert-keyword "WHEN ")))
9496 (defun vhdl-template-while-loop ()
9497 "Insert a while loop."
9499 (let* ((margin (current-indentation))
9502 (if (not (eq vhdl-optional-labels 'all))
9503 (vhdl-insert-keyword "WHILE ")
9504 (vhdl-insert-keyword ": WHILE ")
9506 (setq label (vhdl-template-field "[label]" nil t))
9507 (unless label (delete-char 2))
9510 (when vhdl-conditions-in-parenthesis (insert "("))
9511 (when (vhdl-template-field "condition" nil t start (point))
9512 (when vhdl-conditions-in-parenthesis (insert ")"))
9513 (vhdl-insert-keyword " LOOP\n\n")
9515 (vhdl-insert-keyword "END LOOP")
9516 (insert (if label (concat " " label ";") ";"))
9518 (indent-to (+ margin vhdl-basic-offset)))))
9520 (defun vhdl-template-with ()
9521 "Insert a with statement (i.e. selected signal assignment)."
9523 (vhdl-prepare-search-1
9524 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9525 (equal ";" (match-string 1)))
9526 (vhdl-template-selected-signal-asst)
9527 (vhdl-insert-keyword "WITH "))))
9529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9530 ;; Special templates
9532 (defun vhdl-template-clocked-wait ()
9533 "Insert a wait statement for rising/falling clock edge."
9535 (let ((start (point))
9537 (vhdl-insert-keyword "WAIT UNTIL ")
9539 (or (and (not (equal "" vhdl-clock-name))
9540 (progn (insert vhdl-clock-name) vhdl-clock-name))
9541 (vhdl-template-field "clock name" nil t start (point))))
9543 (vhdl-insert-keyword " AND ")
9546 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9547 (vhdl-comment-insert-inline
9548 (concat (if vhdl-clock-rising-edge "rising" "falling")
9551 (defun vhdl-template-seq-process (clock reset)
9552 "Insert a template for the body of a sequential process."
9553 (let ((margin (current-indentation))
9555 (vhdl-insert-keyword "IF ")
9556 (when (eq vhdl-reset-kind 'async)
9558 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9559 (vhdl-insert-keyword " THEN")
9560 (vhdl-comment-insert-inline
9561 (concat "asynchronous reset (active "
9562 (if vhdl-reset-active-high "high" "low") ")"))
9563 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9564 (setq position (point))
9565 (insert "\n") (indent-to margin)
9566 (vhdl-insert-keyword "ELSIF "))
9567 (if (eq vhdl-clock-edge-condition 'function)
9568 (insert (if vhdl-clock-rising-edge "rising" "falling")
9570 (insert clock "'event")
9571 (vhdl-insert-keyword " AND ")
9573 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9574 (vhdl-insert-keyword " THEN")
9575 (vhdl-comment-insert-inline
9576 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9577 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9578 (when (eq vhdl-reset-kind 'sync)
9579 (vhdl-insert-keyword "IF ")
9580 (setq reset (or (and (not (equal "" vhdl-reset-name))
9581 (progn (insert vhdl-reset-name) vhdl-reset-name))
9582 (vhdl-template-field "reset name") "<reset>"))
9584 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9585 (vhdl-insert-keyword " THEN")
9586 (vhdl-comment-insert-inline
9587 (concat "synchronous reset (active "
9588 (if vhdl-reset-active-high "high" "low") ")"))
9589 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9590 (setq position (point))
9591 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9592 (vhdl-insert-keyword "ELSE")
9593 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9594 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9595 (vhdl-insert-keyword "END IF;"))
9596 (when (eq vhdl-reset-kind 'none)
9597 (setq position (point)))
9598 (insert "\n") (indent-to margin)
9599 (vhdl-insert-keyword "END IF;")
9600 (goto-char position)
9603 (defun vhdl-template-standard-package (library package)
9604 "Insert specification of a standard package. Include a library
9605 specification, if not already there."
9606 (let ((margin (current-indentation)))
9607 (unless (equal library "std")
9608 (unless (or (save-excursion
9609 (vhdl-prepare-search-1
9612 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9613 library "\\|end\\)\\>") nil t)
9615 (equal (downcase library) "work"))
9616 (vhdl-insert-keyword "LIBRARY ")
9617 (insert library ";\n")
9619 (vhdl-insert-keyword "USE ")
9620 (insert library "." package)
9621 (vhdl-insert-keyword ".ALL;"))))
9623 (defun vhdl-template-package-math-complex ()
9624 "Insert specification of `math_complex' package."
9626 (vhdl-template-standard-package "ieee" "math_complex"))
9628 (defun vhdl-template-package-math-real ()
9629 "Insert specification of `math_real' package."
9631 (vhdl-template-standard-package "ieee" "math_real"))
9633 (defun vhdl-template-package-numeric-bit ()
9634 "Insert specification of `numeric_bit' package."
9636 (vhdl-template-standard-package "ieee" "numeric_bit"))
9638 (defun vhdl-template-package-numeric-std ()
9639 "Insert specification of `numeric_std' package."
9641 (vhdl-template-standard-package "ieee" "numeric_std"))
9643 (defun vhdl-template-package-std-logic-1164 ()
9644 "Insert specification of `std_logic_1164' package."
9646 (vhdl-template-standard-package "ieee" "std_logic_1164"))
9648 (defun vhdl-template-package-std-logic-arith ()
9649 "Insert specification of `std_logic_arith' package."
9651 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9653 (defun vhdl-template-package-std-logic-misc ()
9654 "Insert specification of `std_logic_misc' package."
9656 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9658 (defun vhdl-template-package-std-logic-signed ()
9659 "Insert specification of `std_logic_signed' package."
9661 (vhdl-template-standard-package "ieee" "std_logic_signed"))
9663 (defun vhdl-template-package-std-logic-textio ()
9664 "Insert specification of `std_logic_textio' package."
9666 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9668 (defun vhdl-template-package-std-logic-unsigned ()
9669 "Insert specification of `std_logic_unsigned' package."
9671 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9673 (defun vhdl-template-package-textio ()
9674 "Insert specification of `textio' package."
9676 (vhdl-template-standard-package "std" "textio"))
9678 (defun vhdl-template-directive (directive)
9680 (unless (= (current-indentation) (current-column))
9681 (delete-horizontal-space)
9683 (insert "-- pragma " directive))
9685 (defun vhdl-template-directive-translate-on ()
9686 "Insert directive 'translate_on'."
9688 (vhdl-template-directive "translate_on"))
9690 (defun vhdl-template-directive-translate-off ()
9691 "Insert directive 'translate_off'."
9693 (vhdl-template-directive "translate_off"))
9695 (defun vhdl-template-directive-synthesis-on ()
9696 "Insert directive 'synthesis_on'."
9698 (vhdl-template-directive "synthesis_on"))
9700 (defun vhdl-template-directive-synthesis-off ()
9701 "Insert directive 'synthesis_off'."
9703 (vhdl-template-directive "synthesis_off"))
9705 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9706 ;; Header and footer templates
9708 (defun vhdl-template-header (&optional file-title)
9709 "Insert a VHDL file header."
9711 (unless (equal vhdl-file-header "")
9714 (goto-char (point-min))
9715 (vhdl-insert-string-or-file vhdl-file-header)
9716 (setq pos (point-marker)))
9717 (vhdl-template-replace-header-keywords
9718 (point-min-marker) pos file-title))))
9720 (defun vhdl-template-footer ()
9721 "Insert a VHDL file footer."
9723 (unless (equal vhdl-file-footer "")
9726 (goto-char (point-max))
9727 (setq pos (point-marker))
9728 (vhdl-insert-string-or-file vhdl-file-footer)
9729 (unless (= (preceding-char) ?\n)
9731 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9733 (defun vhdl-template-replace-header-keywords (beg end &optional file-title
9735 "Replace keywords in header and footer."
9736 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9737 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9739 (vhdl-prepare-search-2
9742 (while (search-forward "<projectdesc>" end t)
9743 (replace-match project-desc t t))
9745 (while (search-forward "<filename>" end t)
9746 (replace-match (buffer-name) t t))
9748 (while (search-forward "<copyright>" end t)
9749 (replace-match vhdl-copyright-string t t))
9751 (while (search-forward "<author>" end t)
9752 (replace-match "" t t)
9753 (insert (user-full-name))
9754 (when user-mail-address (insert " <" user-mail-address ">")))
9756 (while (search-forward "<login>" end t)
9757 (replace-match (user-login-name) t t))
9759 (while (search-forward "<project>" end t)
9760 (replace-match project-title t t))
9762 (while (search-forward "<company>" end t)
9763 (replace-match vhdl-company-name t t))
9765 (while (search-forward "<platform>" end t)
9766 (replace-match vhdl-platform-spec t t))
9768 (while (search-forward "<standard>" end t)
9770 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9771 ((vhdl-standard-p '93) "'93"))
9772 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9773 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9775 ;; Replace <RCS> with $, so that RCS for the source is
9776 ;; not over-enthusiastic with replacements
9777 (while (search-forward "<RCS>" end t)
9778 (replace-match "$" nil t))
9780 (while (search-forward "<date>" end t)
9781 (replace-match "" t t)
9782 (vhdl-template-insert-date))
9784 (while (search-forward "<year>" end t)
9785 (replace-match (format-time-string "%Y" nil) t t))
9788 (while (search-forward "<title string>" end t)
9789 (replace-match file-title t t))
9793 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9794 (setq string (read-string (concat (match-string 1) ": ")))
9795 (replace-match string t t)))
9797 (when (and (not is-model) (search-forward "<cursor>" end t))
9798 (replace-match "" t t)
9799 (setq pos (point))))
9800 (when pos (goto-char pos))
9802 (when (or (not project-title) (equal project-title ""))
9803 (message "You can specify a project title in user option `vhdl-project-alist'"))
9804 (when (or (not project-desc) (equal project-desc ""))
9805 (message "You can specify a project description in user option `vhdl-project-alist'"))
9806 (when (equal vhdl-platform-spec "")
9807 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9808 (when (equal vhdl-company-name "")
9809 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9812 ;; Comment templates and functions
9814 (defun vhdl-comment-indent ()
9816 (let* ((position (point))
9820 (if (re-search-forward "--" position t)
9821 (- (current-column) 2) ; existing comment at bol stays there
9822 (goto-char position)
9823 (skip-chars-backward " \t")
9824 (max comment-column ; else indent to comment column
9825 (1+ (current-column))))))) ; except leave at least one space
9826 (goto-char position)
9829 (defun vhdl-comment-insert ()
9830 "Start a comment at the end of the line.
9831 If on line with code, indent at least `comment-column'.
9832 If starting after end-comment-column, start a new line."
9834 (when (> (current-column) end-comment-column) (newline-and-indent))
9835 (if (or (looking-at "\\s-*$") ; end of line
9836 (and (not unread-command-events) ; called with key binding or menu
9837 (not (end-of-line))))
9839 (while (= (preceding-char) ?-) (delete-char -1))
9840 (setq margin (current-column))
9841 (delete-horizontal-space)
9843 (progn (indent-to margin) (insert "--"))
9845 (indent-to comment-column)
9847 (if (not unread-command-events) (insert " ")))
9848 ;; else code following current point implies commenting out code
9849 (let (next-input code)
9850 (while (= (preceding-char) ?-) (delete-char -2))
9851 (while (= (setq next-input (read-char)) 13) ; CR
9852 (insert "--") ; or have a space after it?
9855 (message "Enter CR if commenting out a line of code.")
9858 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
9859 (setq unread-command-events
9860 (list (vhdl-character-to-event next-input)))))) ; pushback the char
9862 (defun vhdl-comment-display (&optional line-exists)
9863 "Add 2 comment lines at the current indent, making a display comment."
9865 (let ((margin (current-indentation)))
9866 (unless line-exists (vhdl-comment-display-line))
9867 (insert "\n") (indent-to margin)
9868 (insert "\n") (indent-to margin)
9869 (vhdl-comment-display-line)
9873 (defun vhdl-comment-display-line ()
9874 "Displays one line of dashes."
9876 (while (= (preceding-char) ?-) (delete-char -2))
9877 (let* ((col (current-column))
9878 (len (- end-comment-column col)))
9879 (insert-char ?- len)))
9881 (defun vhdl-comment-append-inline ()
9882 "Append empty inline comment to current line."
9885 (delete-horizontal-space)
9887 (indent-to comment-column)
9890 (defun vhdl-comment-insert-inline (&optional string always-insert)
9891 "Insert inline comment."
9892 (when (or (and string (or vhdl-self-insert-comments always-insert))
9893 (and (not string) vhdl-prompt-for-comments))
9894 (let ((position (point)))
9896 (indent-to comment-column)
9898 (if (not (or (and string (progn (insert string) t))
9899 (vhdl-template-field "[comment]" nil t)))
9900 (delete-region position (point))
9901 (while (= (preceding-char) ? ) (delete-backward-char 1))
9902 ; (when (> (current-column) end-comment-column)
9903 ; (setq position (point-marker))
9904 ; (re-search-backward "-- ")
9906 ; (indent-to comment-column)
9907 ; (goto-char position))
9910 (defun vhdl-comment-block ()
9911 "Insert comment for code block."
9912 (when vhdl-prompt-for-comments
9913 (let ((final-pos (point-marker)))
9914 (vhdl-prepare-search-2
9915 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
9916 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
9918 (back-to-indentation)
9919 (setq margin (current-column))
9922 (progn (insert "\n") (forward-line -1))
9925 (insert "-- purpose: ")
9926 (unless (vhdl-template-field "[description]" nil t)
9927 (vhdl-line-kill-entire)))))
9928 (goto-char final-pos))))
9930 (defun vhdl-comment-uncomment-region (beg end &optional arg)
9931 "Comment out region if not commented out, uncomment otherwise."
9932 (interactive "r\nP")
9934 (goto-char (1- end))
9936 (setq end (point-marker))
9940 (if (looking-at comment-start)
9941 (comment-region beg end '(4))
9942 (comment-region beg end))))
9944 (defun vhdl-comment-uncomment-line (&optional arg)
9945 "Comment out line if not commented out, uncomment otherwise."
9949 (let ((position (point)))
9950 (forward-line (or arg 1))
9951 (vhdl-comment-uncomment-region position (point)))))
9953 (defun vhdl-comment-kill-region (beg end)
9954 "Kill comments in region."
9958 (setq end (point-marker))
9961 (while (< (point) end)
9962 (if (looking-at "^\\(\\s-*--.*\n\\)")
9963 (progn (delete-region (match-beginning 1) (match-end 1)))
9964 (beginning-of-line 2)))))
9966 (defun vhdl-comment-kill-inline-region (beg end)
9967 "Kill inline comments in region."
9971 (setq end (point-marker))
9974 (while (< (point) end)
9975 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
9976 (delete-region (match-beginning 1) (match-end 1)))
9977 (beginning-of-line 2))))
9979 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9982 (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
9983 "Insert a begin ... end pair with optional name after the end.
9984 Point is left between them."
9986 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9988 (vhdl-insert-keyword "BEGIN")
9989 (when (and (or construct name) vhdl-self-insert-comments)
9991 (when construct (insert " ") (vhdl-insert-keyword construct))
9992 (when name (insert " " name)))
9994 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
9995 (indent-to (+ margin vhdl-basic-offset))
9996 (setq position (point))
9998 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
10000 (vhdl-insert-keyword "END")
10001 (when construct (insert " ") (vhdl-insert-keyword construct))
10002 (insert (if name (concat " " name) "") ";")
10003 (goto-char position)))
10005 (defun vhdl-template-argument-list (&optional is-function)
10006 "Read from user a procedure or function argument list."
10008 (let ((margin (current-column))
10011 not-empty interface semicolon-pos)
10012 (unless vhdl-argument-list-indent
10013 (setq margin (+ (current-indentation) vhdl-basic-offset))
10015 (indent-to margin))
10016 (setq interface (vhdl-template-field
10017 (concat "[CONSTANT | SIGNAL"
10018 (unless is-function " | VARIABLE") "]") " " t))
10019 (while (vhdl-template-field "[names]" nil t)
10022 (unless is-function
10023 (if (and interface (equal (upcase interface) "CONSTANT"))
10024 (vhdl-insert-keyword "IN ")
10025 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10026 (vhdl-template-field "type")
10027 (setq semicolon-pos (point))
10029 (vhdl-comment-insert-inline)
10030 (setq end-pos (point))
10033 (setq interface (vhdl-template-field
10034 (concat "[CONSTANT | SIGNAL"
10035 (unless is-function " | VARIABLE") "]") " " t)))
10036 (delete-region end-pos (point))
10037 (when semicolon-pos (goto-char semicolon-pos))
10039 (progn (delete-char 1) (insert ")"))
10040 (delete-backward-char 2))))
10042 (defun vhdl-template-generic-list (optional &optional no-value)
10043 "Read from user a generic spec argument list."
10046 (vhdl-insert-keyword "GENERIC (")
10047 (setq margin (current-column))
10048 (unless vhdl-argument-list-indent
10049 (let ((position (point)))
10050 (back-to-indentation)
10051 (setq margin (+ (current-column) vhdl-basic-offset))
10052 (goto-char position)
10054 (indent-to margin)))
10055 (let ((vhdl-generics (vhdl-template-field
10056 (concat (and optional "[") "name"
10057 (and no-value "s") (and optional "]"))
10059 (if (not vhdl-generics)
10061 (progn (vhdl-line-kill-entire) (end-of-line -0)
10062 (unless vhdl-argument-list-indent
10063 (vhdl-line-kill-entire) (end-of-line -0)))
10064 (vhdl-template-undo start (point))
10067 (let (semicolon-pos end-pos)
10068 (while vhdl-generics
10069 (vhdl-template-field "type")
10071 (progn (setq semicolon-pos (point))
10074 (unless (vhdl-template-field "[value]" nil t)
10076 (setq semicolon-pos (point))
10078 (vhdl-comment-insert-inline)
10079 (setq end-pos (point))
10082 (setq vhdl-generics (vhdl-template-field
10083 (concat "[name" (and no-value "s") "]")
10085 (delete-region end-pos (point))
10086 (goto-char semicolon-pos)
10089 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
10092 (defun vhdl-template-port-list (optional)
10093 "Read from user a port spec argument list."
10094 (let ((start (point))
10095 margin vhdl-ports object)
10096 (vhdl-insert-keyword "PORT (")
10097 (setq margin (current-column))
10098 (unless vhdl-argument-list-indent
10099 (let ((position (point)))
10100 (back-to-indentation)
10101 (setq margin (+ (current-column) vhdl-basic-offset))
10102 (goto-char position)
10104 (indent-to margin)))
10105 (when (vhdl-standard-p 'ams)
10106 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10108 (setq vhdl-ports (vhdl-template-field
10109 (concat (and optional "[") "names" (and optional "]"))
10111 (if (not vhdl-ports)
10113 (progn (vhdl-line-kill-entire) (end-of-line -0)
10114 (unless vhdl-argument-list-indent
10115 (vhdl-line-kill-entire) (end-of-line -0)))
10116 (vhdl-template-undo start (point))
10119 (let (semicolon-pos end-pos)
10121 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10122 (vhdl-template-field "IN | OUT | INOUT" " "))
10123 ((equal "QUANTITY" (upcase object))
10124 (vhdl-template-field "[IN | OUT]" " " t)))
10125 (vhdl-template-field
10126 (if (and object (equal "TERMINAL" (upcase object)))
10128 (setq semicolon-pos (point))
10130 (vhdl-comment-insert-inline)
10131 (setq end-pos (point))
10134 (when (vhdl-standard-p 'ams)
10135 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10137 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10138 (delete-region end-pos (point))
10139 (goto-char semicolon-pos)
10142 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
10145 (defun vhdl-template-generate-body (margin label)
10146 "Insert body for generate template."
10147 (vhdl-insert-keyword " GENERATE")
10148 ; (if (not (vhdl-standard-p '87))
10149 ; (vhdl-template-begin-end "GENERATE" label margin)
10152 (vhdl-insert-keyword "END GENERATE ")
10155 (indent-to (+ margin vhdl-basic-offset)))
10157 (defun vhdl-template-insert-date ()
10158 "Insert date in appropriate format."
10162 ;; 'american, 'european, 'scientific kept for backward compatibility
10163 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10164 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10165 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10166 (t (format-time-string vhdl-date-format nil)))))
10168 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10171 (defun vhdl-electric-space (count)
10172 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10173 if in comment and past end-comment-column."
10175 (cond ((vhdl-in-comment-p)
10176 (self-insert-command count)
10177 (cond ((>= (current-column) (+ 2 end-comment-column))
10179 (skip-chars-backward "^ \t\n")
10180 (indent-new-comment-line)
10181 (skip-chars-forward "^ \t\n")
10183 ((>= (current-column) end-comment-column)
10184 (indent-new-comment-line))
10186 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10187 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
10188 (vhdl-prepare-search-1
10189 (or (expand-abbrev) (vhdl-fix-case-word -1)))
10190 (self-insert-command count))
10191 (t (self-insert-command count))))
10193 (defun vhdl-template-field (prompt &optional follow-string optional
10194 begin end is-string default)
10195 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10196 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10197 an empty string is inserted, return nil and call `vhdl-template-undo' for
10198 the region between BEGIN and END. IS-STRING indicates whether a string
10199 with double-quotes is to be inserted. DEFAULT specifies a default string."
10200 (let ((position (point))
10202 (insert "<" prompt ">")
10205 (read-from-minibuffer (concat prompt ": ")
10206 (or (and is-string '("\"\"" . 2)) default)
10207 vhdl-minibuffer-local-map)
10208 (quit (if (and optional begin end)
10210 (keyboard-quit)))))
10211 (when (or (not (equal string "")) optional)
10212 (delete-region position (point)))
10213 (when (and (equal string "") optional begin end)
10214 (vhdl-template-undo begin end)
10215 (message "Template aborted"))
10216 (unless (equal string "")
10218 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
10219 vhdl-keywords-regexp)
10220 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10222 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10223 (concat "'" vhdl-attributes-regexp))
10224 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10225 vhdl-enum-values-regexp))
10226 (when (or (not (equal string "")) (not optional))
10227 (insert (or follow-string "")))
10228 (if (equal string "") nil string)))
10230 (defun vhdl-decision-query (string prompt &optional optional)
10231 "Query a decision from the user."
10232 (let ((start (point)))
10233 (when string (vhdl-insert-keyword (concat string " ")))
10235 (let ((char (read-char)))
10236 (delete-region start (point))
10237 (if (and optional (eq char ?\r))
10238 (progn (insert " ")
10240 (throw 'abort "ERROR: Template aborted"))
10243 (defun vhdl-insert-keyword (keyword)
10244 "Insert KEYWORD and adjust case."
10245 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
10247 (defun vhdl-case-keyword (keyword)
10248 "Adjust case of KEYWORD."
10249 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
10251 (defun vhdl-case-word (num)
10252 "Adjust case or following NUM words."
10253 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10255 (defun vhdl-minibuffer-tab (&optional prefix-arg)
10256 "If preceeding character is part of a word or a paren then hippie-expand,
10257 else insert tab (used for word completion in VHDL minibuffer)."
10261 ((= (char-syntax (preceding-char)) ?w)
10262 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10264 (hippie-expand-only-buffers
10265 (or (and (boundp 'hippie-expand-only-buffers)
10266 hippie-expand-only-buffers)
10268 (vhdl-expand-abbrev prefix-arg)))
10269 ;; expand parenthesis
10270 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10271 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10272 (case-replace nil))
10273 (vhdl-expand-paren prefix-arg)))
10277 (defun vhdl-template-search-prompt ()
10278 "Search for left out template prompts and query again."
10280 (vhdl-prepare-search-2
10281 (when (or (re-search-forward
10282 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10283 (re-search-backward
10284 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10285 (let ((string (match-string 1)))
10287 (vhdl-template-field string)))))
10289 (defun vhdl-template-undo (begin end)
10290 "Undo aborted template by deleting region and unexpanding the keyword."
10291 (cond (vhdl-template-invoked-by-hook
10294 (delete-region begin end)
10296 (t (delete-region begin end))))
10298 (defun vhdl-insert-string-or-file (string)
10299 "Insert STRING or file contents if STRING is an existing file name."
10300 (unless (equal string "")
10302 (progn (string-match "^\\([^\n]+\\)" string)
10303 (vhdl-resolve-env-variable (match-string 1 string)))))
10304 (if (file-exists-p file-name)
10305 (forward-char (cadr (insert-file-contents file-name)))
10306 (insert string)))))
10308 (defun vhdl-beginning-of-block ()
10309 "Move cursor to the beginning of the enclosing block."
10312 (beginning-of-line)
10313 ;; search backward for block beginning or end
10314 (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))
10315 ;; not consider subprogram declarations
10316 (or (and (match-string 5)
10319 (goto-char (match-end 5))
10320 (forward-word 1) (forward-sexp)
10321 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10323 ;; not consider configuration specifications
10324 (and (match-string 6)
10327 (vhdl-end-of-block)
10328 (beginning-of-line)
10329 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10331 ;; skip subblock if block end found
10332 (vhdl-beginning-of-block)))
10333 (when pos (goto-char pos))))
10335 (defun vhdl-end-of-block ()
10336 "Move cursor to the end of the enclosing block."
10340 ;; search forward for block beginning or end
10341 (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))
10342 ;; not consider subprogram declarations
10343 (or (and (match-string 5)
10345 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10347 ;; not consider configuration specifications
10348 (and (match-string 6)
10351 (vhdl-end-of-block)
10352 (beginning-of-line)
10353 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10354 (not (match-string 2)))
10355 ;; skip subblock if block beginning found
10356 (vhdl-end-of-block)))
10357 (when pos (goto-char pos))))
10359 (defun vhdl-sequential-statement-p ()
10360 "Check if point is within sequential statement part."
10361 (let ((start (point)))
10363 (vhdl-prepare-search-2
10364 ;; is sequential statement if ...
10365 (and (re-search-backward "^\\s-*begin\\>" nil t)
10366 ;; ... point is between "begin" and "end" of ...
10367 (progn (vhdl-end-of-block)
10369 ;; ... a sequential block
10370 (progn (vhdl-beginning-of-block)
10371 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
10373 (defun vhdl-in-argument-list-p ()
10374 "Check if within an argument list."
10376 (vhdl-prepare-search-2
10377 (or (string-match "arglist"
10378 (format "%s" (caar (vhdl-get-syntactic-context))))
10379 (progn (beginning-of-line)
10380 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
10382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10385 (defun vhdl-hooked-abbrev (func)
10386 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10387 but not if inside a comment or quote)."
10388 (if (or (vhdl-in-literal)
10391 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10396 (if (not vhdl-electric-mode)
10403 (let ((invoke-char last-command-char)
10405 (vhdl-template-invoked-by-hook t))
10406 (let ((caught (catch 'abort
10408 (when (stringp caught) (message caught)))
10409 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10410 ;; delete CR which is still in event queue
10411 (if (fboundp 'enqueue-eval-event)
10412 (enqueue-eval-event 'delete-char -1)
10413 (setq unread-command-events ; push back a delete char
10414 (list (vhdl-character-to-event ?\177))))))))
10416 (defun vhdl-template-alias-hook ()
10417 (vhdl-hooked-abbrev 'vhdl-template-alias))
10418 (defun vhdl-template-architecture-hook ()
10419 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10420 (defun vhdl-template-assert-hook ()
10421 (vhdl-hooked-abbrev 'vhdl-template-assert))
10422 (defun vhdl-template-attribute-hook ()
10423 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10424 (defun vhdl-template-block-hook ()
10425 (vhdl-hooked-abbrev 'vhdl-template-block))
10426 (defun vhdl-template-break-hook ()
10427 (vhdl-hooked-abbrev 'vhdl-template-break))
10428 (defun vhdl-template-case-hook ()
10429 (vhdl-hooked-abbrev 'vhdl-template-case))
10430 (defun vhdl-template-component-hook ()
10431 (vhdl-hooked-abbrev 'vhdl-template-component))
10432 (defun vhdl-template-instance-hook ()
10433 (vhdl-hooked-abbrev 'vhdl-template-instance))
10434 (defun vhdl-template-conditional-signal-asst-hook ()
10435 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10436 (defun vhdl-template-configuration-hook ()
10437 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10438 (defun vhdl-template-constant-hook ()
10439 (vhdl-hooked-abbrev 'vhdl-template-constant))
10440 (defun vhdl-template-disconnect-hook ()
10441 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10442 (defun vhdl-template-display-comment-hook ()
10443 (vhdl-hooked-abbrev 'vhdl-comment-display))
10444 (defun vhdl-template-else-hook ()
10445 (vhdl-hooked-abbrev 'vhdl-template-else))
10446 (defun vhdl-template-elsif-hook ()
10447 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10448 (defun vhdl-template-entity-hook ()
10449 (vhdl-hooked-abbrev 'vhdl-template-entity))
10450 (defun vhdl-template-exit-hook ()
10451 (vhdl-hooked-abbrev 'vhdl-template-exit))
10452 (defun vhdl-template-file-hook ()
10453 (vhdl-hooked-abbrev 'vhdl-template-file))
10454 (defun vhdl-template-for-hook ()
10455 (vhdl-hooked-abbrev 'vhdl-template-for))
10456 (defun vhdl-template-function-hook ()
10457 (vhdl-hooked-abbrev 'vhdl-template-function))
10458 (defun vhdl-template-generic-hook ()
10459 (vhdl-hooked-abbrev 'vhdl-template-generic))
10460 (defun vhdl-template-group-hook ()
10461 (vhdl-hooked-abbrev 'vhdl-template-group))
10462 (defun vhdl-template-library-hook ()
10463 (vhdl-hooked-abbrev 'vhdl-template-library))
10464 (defun vhdl-template-limit-hook ()
10465 (vhdl-hooked-abbrev 'vhdl-template-limit))
10466 (defun vhdl-template-if-hook ()
10467 (vhdl-hooked-abbrev 'vhdl-template-if))
10468 (defun vhdl-template-bare-loop-hook ()
10469 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10470 (defun vhdl-template-map-hook ()
10471 (vhdl-hooked-abbrev 'vhdl-template-map))
10472 (defun vhdl-template-nature-hook ()
10473 (vhdl-hooked-abbrev 'vhdl-template-nature))
10474 (defun vhdl-template-next-hook ()
10475 (vhdl-hooked-abbrev 'vhdl-template-next))
10476 (defun vhdl-template-others-hook ()
10477 (vhdl-hooked-abbrev 'vhdl-template-others))
10478 (defun vhdl-template-package-hook ()
10479 (vhdl-hooked-abbrev 'vhdl-template-package))
10480 (defun vhdl-template-port-hook ()
10481 (vhdl-hooked-abbrev 'vhdl-template-port))
10482 (defun vhdl-template-procedural-hook ()
10483 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10484 (defun vhdl-template-procedure-hook ()
10485 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10486 (defun vhdl-template-process-hook ()
10487 (vhdl-hooked-abbrev 'vhdl-template-process))
10488 (defun vhdl-template-quantity-hook ()
10489 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10490 (defun vhdl-template-report-hook ()
10491 (vhdl-hooked-abbrev 'vhdl-template-report))
10492 (defun vhdl-template-return-hook ()
10493 (vhdl-hooked-abbrev 'vhdl-template-return))
10494 (defun vhdl-template-selected-signal-asst-hook ()
10495 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10496 (defun vhdl-template-signal-hook ()
10497 (vhdl-hooked-abbrev 'vhdl-template-signal))
10498 (defun vhdl-template-subnature-hook ()
10499 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10500 (defun vhdl-template-subtype-hook ()
10501 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10502 (defun vhdl-template-terminal-hook ()
10503 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10504 (defun vhdl-template-type-hook ()
10505 (vhdl-hooked-abbrev 'vhdl-template-type))
10506 (defun vhdl-template-use-hook ()
10507 (vhdl-hooked-abbrev 'vhdl-template-use))
10508 (defun vhdl-template-variable-hook ()
10509 (vhdl-hooked-abbrev 'vhdl-template-variable))
10510 (defun vhdl-template-wait-hook ()
10511 (vhdl-hooked-abbrev 'vhdl-template-wait))
10512 (defun vhdl-template-when-hook ()
10513 (vhdl-hooked-abbrev 'vhdl-template-when))
10514 (defun vhdl-template-while-loop-hook ()
10515 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10516 (defun vhdl-template-with-hook ()
10517 (vhdl-hooked-abbrev 'vhdl-template-with))
10518 (defun vhdl-template-and-hook ()
10519 (vhdl-hooked-abbrev 'vhdl-template-and))
10520 (defun vhdl-template-or-hook ()
10521 (vhdl-hooked-abbrev 'vhdl-template-or))
10522 (defun vhdl-template-nand-hook ()
10523 (vhdl-hooked-abbrev 'vhdl-template-nand))
10524 (defun vhdl-template-nor-hook ()
10525 (vhdl-hooked-abbrev 'vhdl-template-nor))
10526 (defun vhdl-template-xor-hook ()
10527 (vhdl-hooked-abbrev 'vhdl-template-xor))
10528 (defun vhdl-template-xnor-hook ()
10529 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10530 (defun vhdl-template-not-hook ()
10531 (vhdl-hooked-abbrev 'vhdl-template-not))
10533 (defun vhdl-template-default-hook ()
10534 (vhdl-hooked-abbrev 'vhdl-template-default))
10535 (defun vhdl-template-default-indent-hook ()
10536 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10539 ;; Template insertion from completion list
10541 (defun vhdl-template-insert-construct (name)
10542 "Insert the built-in construct template with NAME."
10544 (list (let ((completion-ignore-case t))
10545 (completing-read "Construct name: "
10546 vhdl-template-construct-alist nil t))))
10547 (vhdl-template-insert-fun
10548 (cadr (assoc name vhdl-template-construct-alist))))
10550 (defun vhdl-template-insert-package (name)
10551 "Insert the built-in package template with NAME."
10553 (list (let ((completion-ignore-case t))
10554 (completing-read "Package name: "
10555 vhdl-template-package-alist nil t))))
10556 (vhdl-template-insert-fun
10557 (cadr (assoc name vhdl-template-package-alist))))
10559 (defun vhdl-template-insert-directive (name)
10560 "Insert the built-in directive template with NAME."
10562 (list (let ((completion-ignore-case t))
10563 (completing-read "Directive name: "
10564 vhdl-template-directive-alist nil t))))
10565 (vhdl-template-insert-fun
10566 (cadr (assoc name vhdl-template-directive-alist))))
10568 (defun vhdl-template-insert-fun (fun)
10569 "Call FUN to insert a built-in template."
10570 (let ((caught (catch 'abort (when fun (funcall fun)))))
10571 (when (stringp caught) (message caught))))
10574 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10576 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10578 (defun vhdl-model-insert (model-name)
10579 "Insert the user model with name MODEL-NAME."
10581 (let ((completion-ignore-case t))
10582 (list (completing-read "Model name: " vhdl-model-alist))))
10583 (indent-according-to-mode)
10584 (let ((start (point-marker))
10585 (margin (current-indentation))
10586 model position prompt string end)
10587 (vhdl-prepare-search-2
10588 (when (setq model (assoc model-name vhdl-model-alist))
10590 (beginning-of-line)
10591 (delete-horizontal-space)
10593 (vhdl-insert-string-or-file (nth 1 model))
10594 (setq end (point-marker))
10597 (beginning-of-line)
10598 (while (< (point) end)
10599 (unless (looking-at "^$")
10600 (insert-char ? margin))
10601 (beginning-of-line 2))
10604 (unless (equal "" vhdl-clock-name)
10605 (while (re-search-forward "<clock>" end t)
10606 (replace-match vhdl-clock-name)))
10609 (unless (equal "" vhdl-reset-name)
10610 (while (re-search-forward "<reset>" end t)
10611 (replace-match vhdl-reset-name)))
10612 ;; replace header prompts
10613 (vhdl-template-replace-header-keywords start end nil t)
10615 ;; query other prompts
10616 (while (re-search-forward
10617 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10618 (unless (equal "cursor" (match-string 1))
10619 (setq position (match-beginning 1))
10620 (setq prompt (match-string 1))
10622 (setq string (vhdl-template-field prompt nil t))
10623 ;; replace occurrences of same prompt
10624 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10625 (replace-match (or string "")))
10626 (goto-char position)))
10628 ;; goto final position
10629 (if (re-search-forward "<cursor>" end t)
10631 (goto-char end))))))
10633 (defun vhdl-model-defun ()
10634 "Define help and hook functions for user models."
10635 (let ((model-alist vhdl-model-alist)
10636 model-name model-keyword)
10638 ;; define functions for user models that can be invoked from menu and key
10639 ;; bindings and which themselves call `vhdl-model-insert' with the model
10640 ;; name as argument
10641 (setq model-name (nth 0 (car model-alist)))
10642 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10643 ,(concat "Insert model for \"" model-name "\".")
10645 (vhdl-model-insert ,model-name)))
10646 ;; define hooks for user models that are invoked from keyword abbrevs
10647 (setq model-keyword (nth 3 (car model-alist)))
10648 (unless (equal model-keyword "")
10650 ,(vhdl-function-name
10651 "vhdl-model" model-name "hook") ()
10652 (vhdl-hooked-abbrev
10653 ',(vhdl-function-name "vhdl-model" model-name)))))
10654 (setq model-alist (cdr model-alist)))))
10659 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10660 ;;; Port translation
10661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10663 (defvar vhdl-port-list nil
10664 "Variable to hold last port map parsed.")
10665 ;; structure: (parenthesised expression means list of such entries)
10667 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
10668 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
10669 ;; (lib-name pack-key))
10671 (defun vhdl-parse-string (string &optional optional)
10672 "Check that the text following point matches the regexp in STRING."
10673 (if (looking-at string)
10674 (goto-char (match-end 0))
10676 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10677 (vhdl-current-line) string)))
10680 (defun vhdl-replace-string (regexp-cons string)
10681 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
10682 (vhdl-prepare-search-1
10683 (if (string-match (car regexp-cons) string)
10684 (funcall vhdl-file-name-case
10685 (replace-match (cdr regexp-cons) t nil string))
10688 (defun vhdl-parse-group-comment ()
10689 "Parse comment and empty lines between groups of lines."
10690 (let ((start (point))
10692 (vhdl-forward-comment (point-max))
10693 (setq string (buffer-substring-no-properties start (point)))
10694 ;; strip off leading blanks and first newline
10695 (while (string-match "^\\(\\s-+\\)" string)
10696 (setq string (concat (substring string 0 (match-beginning 1))
10697 (substring string (match-end 1)))))
10698 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10699 (substring string 1)
10702 (defun vhdl-paste-group-comment (string indent)
10703 "Paste comment and empty lines from STRING between groups of lines
10705 (let ((pos (point-marker)))
10707 (while (string-match "^\\(--\\)" string)
10708 (setq string (concat (substring string 0 (match-beginning 1))
10709 (make-string indent ? )
10710 (substring string (match-beginning 1))))))
10711 (beginning-of-line)
10715 (defvar vhdl-port-flattened nil
10716 "Indicates whether a port has been flattened.")
10718 (defun vhdl-port-flatten (&optional as-alist)
10719 "Flatten port list so that only one generic/port exists per line."
10721 (if (not vhdl-port-list)
10722 (error "ERROR: No port has been read")
10723 (message "Flattening port...")
10724 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10725 (old-vhdl-port-list (cdr vhdl-port-list))
10726 old-port-list new-port-list old-port new-port names)
10727 ;; traverse port list and flatten entries
10728 (while (cdr old-vhdl-port-list)
10729 (setq old-port-list (car old-vhdl-port-list))
10730 (setq new-port-list nil)
10731 (while old-port-list
10732 (setq old-port (car old-port-list))
10733 (setq names (car old-port))
10735 (setq new-port (cons (if as-alist (car names) (list (car names)))
10737 (setq new-port-list (append new-port-list (list new-port)))
10738 (setq names (cdr names)))
10739 (setq old-port-list (cdr old-port-list)))
10740 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10741 (setq new-vhdl-port-list (append new-vhdl-port-list
10742 (list new-port-list))))
10743 (setq vhdl-port-list
10744 (append new-vhdl-port-list (list old-vhdl-port-list))
10745 vhdl-port-flattened t)
10746 (message "Flattening port...done"))))
10748 (defvar vhdl-port-reversed-direction nil
10749 "Indicates whether port directions are reversed.")
10751 (defun vhdl-port-reverse-direction ()
10752 "Reverse direction for all ports (useful in testbenches)."
10754 (if (not vhdl-port-list)
10755 (error "ERROR: No port has been read")
10756 (message "Reversing port directions...")
10757 (let ((port-list (nth 2 vhdl-port-list))
10758 port-dir-car port-dir)
10759 ;; traverse port list and reverse directions
10761 (setq port-dir-car (cddr (car port-list))
10762 port-dir (car port-dir-car))
10763 (setcar port-dir-car
10764 (cond ((equal port-dir "in") "out")
10765 ((equal port-dir "out") "in")
10767 (setq port-list (cdr port-list)))
10768 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10769 (message "Reversing port directions...done"))))
10771 (defun vhdl-port-copy ()
10772 "Get generic and port information from an entity or component declaration."
10775 (let (parse-error end-of-list
10776 decl-type name generic-list port-list context-clause
10777 object names direct type init comment group-comment)
10778 (vhdl-prepare-search-2
10782 ;; check if within entity or component declaration
10784 (when (or (not (re-search-backward
10785 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
10786 (equal "END" (upcase (match-string 1))))
10787 (throw 'parse "ERROR: Not within an entity or component declaration"))
10788 (setq decl-type (downcase (match-string-no-properties 1)))
10790 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10791 (setq name (match-string-no-properties 1))
10792 (message "Reading port of %s \"%s\"..." decl-type name)
10793 (vhdl-forward-syntactic-ws)
10794 ;; parse generic clause
10795 (when (vhdl-parse-string "generic[ \t\n]*(" t)
10796 ;; parse group comment and spacing
10797 (setq group-comment (vhdl-parse-group-comment))
10798 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10799 (while (not end-of-list)
10801 (vhdl-parse-string "\\(\\w+\\)[ \t\n]*")
10802 (setq names (list (match-string-no-properties 1)))
10803 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
10805 (append names (list (match-string-no-properties 1)))))
10807 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
10808 (setq type (match-string-no-properties 1))
10810 (while (looking-at "(")
10813 (buffer-substring-no-properties
10814 (point) (progn (forward-sexp) (point)))
10815 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
10816 (match-string-no-properties 1)))))
10817 ;; special case: closing parenthesis is on separate line
10818 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10819 (setq comment (substring type (match-beginning 2)))
10820 (setq type (substring type 0 (match-beginning 1))))
10821 ;; strip of trailing group-comment
10822 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10823 (setq type (substring type 0 (match-end 1)))
10824 ;; parse initialization expression
10826 (when (vhdl-parse-string ":=[ \t\n]*" t)
10827 (vhdl-parse-string "\\([^();\n]*\\)")
10828 (setq init (match-string-no-properties 1))
10829 (while (looking-at "(")
10832 (buffer-substring-no-properties
10833 (point) (progn (forward-sexp) (point)))
10834 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10835 (match-string-no-properties 1))))))
10836 ;; special case: closing parenthesis is on separate line
10837 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10838 (setq comment (substring init (match-beginning 2)))
10839 (setq init (substring init 0 (match-beginning 1)))
10840 (vhdl-forward-syntactic-ws))
10841 (skip-chars-forward " \t")
10842 ;; parse inline comment, special case: as above, no initial.
10844 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10845 (match-string-no-properties 1))))
10846 (vhdl-forward-syntactic-ws)
10847 (setq end-of-list (vhdl-parse-string ")" t))
10848 (vhdl-parse-string "\\s-*;\\s-*")
10849 ;; parse inline comment
10851 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10852 (match-string-no-properties 1))))
10853 ;; save everything in list
10854 (setq generic-list (append generic-list
10855 (list (list names type init
10856 comment group-comment))))
10857 ;; parse group comment and spacing
10858 (setq group-comment (vhdl-parse-group-comment))))
10859 ;; parse port clause
10860 (when (vhdl-parse-string "port[ \t\n]*(" t)
10861 ;; parse group comment and spacing
10862 (setq group-comment (vhdl-parse-group-comment))
10863 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
10864 (while (not end-of-list)
10867 (and (vhdl-parse-string "\\(signal\\|quantity\\|terminal\\)[ \t\n]*" t)
10868 (match-string-no-properties 1)))
10869 ;; parse names (accept extended identifiers)
10870 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10871 (setq names (list (match-string-no-properties 1)))
10872 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
10873 (setq names (append names (list (match-string-no-properties 1)))))
10875 (vhdl-parse-string ":[ \t\n]*")
10877 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
10878 (match-string-no-properties 1)))
10880 (vhdl-parse-string "\\([^();\n]+\\)")
10881 (setq type (match-string-no-properties 1))
10883 (while (looking-at "(")
10884 (setq type (concat type
10885 (buffer-substring-no-properties
10886 (point) (progn (forward-sexp) (point)))
10887 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
10888 (match-string-no-properties 1)))))
10889 ;; special case: closing parenthesis is on separate line
10890 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10891 (setq comment (substring type (match-beginning 2)))
10892 (setq type (substring type 0 (match-beginning 1))))
10893 ;; strip of trailing group-comment
10894 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10895 (setq type (substring type 0 (match-end 1)))
10896 (vhdl-forward-syntactic-ws)
10897 (setq end-of-list (vhdl-parse-string ")" t))
10898 (vhdl-parse-string "\\s-*;\\s-*")
10899 ;; parse inline comment
10901 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
10902 (match-string-no-properties 1))))
10903 ;; save everything in list
10904 (setq port-list (append port-list
10905 (list (list names object direct type
10906 comment group-comment))))
10907 ;; parse group comment and spacing
10908 (setq group-comment (vhdl-parse-group-comment))))
10909 ; (vhdl-parse-string "end\\>")
10910 ;; parse context clause
10911 (setq context-clause (vhdl-scan-context-clause))
10912 ; ;; add surrounding package to context clause
10913 ; (when (and (equal decl-type "component")
10914 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
10915 ; (setq context-clause
10916 ; (append context-clause
10917 ; (list (cons (vhdl-work-library)
10918 ; (match-string-no-properties 1))))))
10919 (message "Reading port of %s \"%s\"...done" decl-type name)
10923 (error parse-error)
10924 (setq vhdl-port-list (list name generic-list port-list context-clause)
10925 vhdl-port-reversed-direction nil
10926 vhdl-port-flattened nil)))))
10928 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
10929 "Paste a context clause."
10930 (let ((margin (current-indentation))
10931 (clause-list (nth 3 vhdl-port-list))
10934 (setq clause (car clause-list))
10935 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
10936 (downcase exclude-pack-name)))
10938 (re-search-backward
10939 (concat "^\\s-*use\\s-+" (car clause)
10940 "\." (cdr clause) "\\>") nil t)))
10941 (vhdl-template-standard-package (car clause) (cdr clause))
10943 (setq clause-list (cdr clause-list)))))
10945 (defun vhdl-port-paste-generic (&optional no-init)
10946 "Paste a generic clause."
10947 (let ((margin (current-indentation))
10948 (generic-list (nth 1 vhdl-port-list))
10949 list-margin start names generic)
10950 ;; paste generic clause
10952 (setq start (point))
10953 (vhdl-insert-keyword "GENERIC (")
10954 (unless vhdl-argument-list-indent
10955 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10956 (setq list-margin (current-column))
10957 (while generic-list
10958 (setq generic (car generic-list))
10959 ;; paste group comment and spacing
10960 (when (memq vhdl-include-group-comments '(decl always))
10961 (vhdl-paste-group-comment (nth 4 generic) list-margin))
10963 (setq names (nth 0 generic))
10965 (insert (car names))
10966 (setq names (cdr names))
10967 (when names (insert ", ")))
10969 (insert " : " (nth 1 generic))
10970 ;; paste initialization
10971 (when (and (not no-init) (nth 2 generic))
10972 (insert " := " (nth 2 generic)))
10973 (unless (cdr generic-list) (insert ")"))
10976 (when (and vhdl-include-port-comments (nth 3 generic))
10977 (vhdl-comment-insert-inline (nth 3 generic) t))
10978 (setq generic-list (cdr generic-list))
10979 (when generic-list (insert "\n") (indent-to list-margin)))
10980 ;; align generic clause
10981 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
10983 (defun vhdl-port-paste-port ()
10984 "Paste a port clause."
10985 (let ((margin (current-indentation))
10986 (port-list (nth 2 vhdl-port-list))
10987 list-margin start names port)
10988 ;; paste port clause
10990 (setq start (point))
10991 (vhdl-insert-keyword "PORT (")
10992 (unless vhdl-argument-list-indent
10993 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10994 (setq list-margin (current-column))
10996 (setq port (car port-list))
10997 ;; paste group comment and spacing
10998 (when (memq vhdl-include-group-comments '(decl always))
10999 (vhdl-paste-group-comment (nth 5 port) list-margin))
11001 (when (nth 1 port) (insert (nth 1 port) " "))
11003 (setq names (nth 0 port))
11005 (insert (car names))
11006 (setq names (cdr names))
11007 (when names (insert ", ")))
11010 (when (nth 2 port) (insert (nth 2 port) " "))
11012 (insert (nth 3 port))
11013 (unless (cdr port-list) (insert ")"))
11016 (when (and vhdl-include-port-comments (nth 4 port))
11017 (vhdl-comment-insert-inline (nth 4 port) t))
11018 (setq port-list (cdr port-list))
11019 (when port-list (insert "\n") (indent-to list-margin)))
11020 ;; align port clause
11021 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
11023 (defun vhdl-port-paste-declaration (kind &optional no-indent)
11024 "Paste as an entity or component declaration."
11025 (unless no-indent (indent-according-to-mode))
11026 (let ((margin (current-indentation))
11027 (name (nth 0 vhdl-port-list)))
11028 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11030 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11031 (vhdl-insert-keyword " IS"))
11032 ;; paste generic and port clause
11033 (when (nth 1 vhdl-port-list)
11035 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11037 (indent-to (+ margin vhdl-basic-offset))
11038 (vhdl-port-paste-generic (eq kind 'component)))
11039 (when (nth 2 vhdl-port-list)
11041 (when (and (memq vhdl-insert-empty-lines '(unit all))
11044 (indent-to (+ margin vhdl-basic-offset)))
11045 (vhdl-port-paste-port)
11047 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11050 (vhdl-insert-keyword "END")
11051 (if (eq kind 'entity)
11053 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11055 (vhdl-insert-keyword " COMPONENT")
11056 (unless (vhdl-standard-p '87) (insert " " name)))
11059 (defun vhdl-port-paste-entity (&optional no-indent)
11060 "Paste as an entity declaration."
11062 (if (not vhdl-port-list)
11063 (error "ERROR: No port read")
11064 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11065 (vhdl-port-paste-declaration 'entity no-indent)
11066 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
11068 (defun vhdl-port-paste-component (&optional no-indent)
11069 "Paste as a component declaration."
11071 (if (not vhdl-port-list)
11072 (error "ERROR: No port read")
11073 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11074 (vhdl-port-paste-declaration 'component no-indent)
11075 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
11077 (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11078 "Paste as a generic map."
11080 (unless secondary (indent-according-to-mode))
11081 (let ((margin (current-indentation))
11082 list-margin start generic
11083 (generic-list (nth 1 vhdl-port-list)))
11085 (setq start (point))
11086 (vhdl-insert-keyword "GENERIC MAP (")
11087 (if (not vhdl-association-list-with-formals)
11088 ;; paste list of actual generics
11089 (while generic-list
11090 (insert (if no-constants
11091 (car (nth 0 (car generic-list)))
11092 (or (nth 2 (car generic-list)) " ")))
11093 (setq generic-list (cdr generic-list))
11094 (insert (if generic-list ", " ")")))
11095 (unless vhdl-argument-list-indent
11096 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11097 (setq list-margin (current-column))
11098 (while generic-list
11099 (setq generic (car generic-list))
11100 ;; paste group comment and spacing
11101 (when (eq vhdl-include-group-comments 'always)
11102 (vhdl-paste-group-comment (nth 4 generic) list-margin))
11103 ;; paste formal and actual generic
11104 (insert (car (nth 0 generic)) " => "
11106 (car (nth 0 generic))
11107 (or (nth 2 generic) "")))
11108 (setq generic-list (cdr generic-list))
11109 (insert (if generic-list "," ")"))
11111 (when (or vhdl-include-type-comments
11112 (and vhdl-include-port-comments (nth 3 generic)))
11113 (vhdl-comment-insert-inline
11115 (when vhdl-include-type-comments
11116 (concat "[" (nth 1 generic) "] "))
11117 (when vhdl-include-port-comments (nth 3 generic))) t))
11118 (when generic-list (insert "\n") (indent-to list-margin)))
11119 ;; align generic map
11120 (when vhdl-auto-align
11121 (vhdl-align-region-groups start (point) 1 t))))))
11123 (defun vhdl-port-paste-port-map ()
11124 "Paste as a port map."
11125 (let ((margin (current-indentation))
11126 list-margin start port
11127 (port-list (nth 2 vhdl-port-list)))
11129 (setq start (point))
11130 (vhdl-insert-keyword "PORT MAP (")
11131 (if (not vhdl-association-list-with-formals)
11132 ;; paste list of actual ports
11134 (insert (vhdl-replace-string vhdl-actual-port-name
11135 (car (nth 0 (car port-list)))))
11136 (setq port-list (cdr port-list))
11137 (insert (if port-list ", " ");")))
11138 (unless vhdl-argument-list-indent
11139 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11140 (setq list-margin (current-column))
11142 (setq port (car port-list))
11143 ;; paste group comment and spacing
11144 (when (eq vhdl-include-group-comments 'always)
11145 (vhdl-paste-group-comment (nth 5 port) list-margin))
11146 ;; paste formal and actual port
11147 (insert (car (nth 0 port)) " => ")
11148 (insert (vhdl-replace-string vhdl-actual-port-name
11149 (car (nth 0 port))))
11150 (setq port-list (cdr port-list))
11151 (insert (if port-list "," ");"))
11153 (when (or vhdl-include-direction-comments
11154 vhdl-include-type-comments
11155 (and vhdl-include-port-comments (nth 4 port)))
11156 (vhdl-comment-insert-inline
11158 (cond ((and vhdl-include-direction-comments
11159 vhdl-include-type-comments)
11160 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11161 (nth 3 port) "] "))
11162 ((and vhdl-include-direction-comments (nth 2 port))
11163 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11164 (vhdl-include-direction-comments " ")
11165 (vhdl-include-type-comments
11166 (concat "[" (nth 3 port) "] ")))
11167 (when vhdl-include-port-comments (nth 4 port))) t))
11168 (when port-list (insert "\n") (indent-to list-margin)))
11169 ;; align port clause
11170 (when vhdl-auto-align
11171 (vhdl-align-region-groups start (point) 1))))))
11173 (defun vhdl-port-paste-instance (&optional name no-indent title)
11174 "Paste as an instantiation."
11176 (if (not vhdl-port-list)
11177 (error "ERROR: No port read")
11178 (let ((orig-vhdl-port-list vhdl-port-list))
11179 ;; flatten local copy of port list (must be flat for port mapping)
11180 (vhdl-port-flatten)
11181 (unless no-indent (indent-according-to-mode))
11182 (let ((margin (current-indentation)))
11183 ;; paste instantiation
11186 ((equal (cdr vhdl-instance-name) "")
11187 (setq name (vhdl-template-field "instance name")))
11188 ((string-match "\%d" (cdr vhdl-instance-name))
11190 (while (save-excursion
11191 (setq name (format (vhdl-replace-string
11193 (nth 0 vhdl-port-list)) n))
11194 (goto-char (point-min))
11195 (vhdl-re-search-forward name nil t))
11198 (t (insert (vhdl-replace-string vhdl-instance-name
11199 (nth 0 vhdl-port-list)))))
11200 (message "Pasting port as instantiation \"%s\"..." name)
11204 (beginning-of-line)
11205 (indent-to vhdl-basic-offset)
11206 (insert "-- instance \"" name "\"\n")))
11207 (if (not (vhdl-use-direct-instantiation))
11208 (insert (nth 0 vhdl-port-list))
11209 (vhdl-insert-keyword "ENTITY ")
11210 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
11211 (when (nth 1 vhdl-port-list)
11212 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11213 (vhdl-port-paste-generic-map t t))
11214 (when (nth 2 vhdl-port-list)
11215 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11216 (vhdl-port-paste-port-map))
11217 (message "Pasting port as instantiation \"%s\"...done" name))
11218 (setq vhdl-port-list orig-vhdl-port-list))))
11220 (defun vhdl-port-paste-constants (&optional no-indent)
11221 "Paste generics as constants."
11223 (if (not vhdl-port-list)
11224 (error "ERROR: No port read")
11225 (let ((orig-vhdl-port-list vhdl-port-list))
11226 (message "Pasting port as constants...")
11227 ;; flatten local copy of port list (must be flat for constant initial.)
11228 (vhdl-port-flatten)
11229 (unless no-indent (indent-according-to-mode))
11230 (let ((margin (current-indentation))
11232 (generic-list (nth 1 vhdl-port-list)))
11234 (setq start (point))
11235 (while generic-list
11236 (setq generic (car generic-list))
11237 ;; paste group comment and spacing
11238 (when (memq vhdl-include-group-comments '(decl always))
11239 (vhdl-paste-group-comment (nth 4 generic) margin))
11240 (vhdl-insert-keyword "CONSTANT ")
11241 ;; paste generic constants
11242 (setq name (nth 0 generic))
11244 (insert (car name))
11246 (insert " : " (nth 1 generic))
11247 ;; paste initialization
11248 (when (nth 2 generic)
11249 (insert " := " (nth 2 generic)))
11252 (when (and vhdl-include-port-comments (nth 3 generic))
11253 (vhdl-comment-insert-inline (nth 3 generic) t))
11254 (setq generic-list (cdr generic-list))
11255 (when generic-list (insert "\n") (indent-to margin))))
11256 ;; align signal list
11257 (when vhdl-auto-align
11258 (vhdl-align-region-groups start (point) 1))))
11259 (message "Pasting port as constants...done")
11260 (setq vhdl-port-list orig-vhdl-port-list))))
11262 (defun vhdl-port-paste-signals (&optional initialize no-indent)
11263 "Paste ports as internal signals."
11265 (if (not vhdl-port-list)
11266 (error "ERROR: No port read")
11267 (message "Pasting port as signals...")
11268 (unless no-indent (indent-according-to-mode))
11269 (let ((margin (current-indentation))
11271 (port-list (nth 2 vhdl-port-list)))
11273 (setq start (point))
11275 (setq port (car port-list))
11276 ;; paste group comment and spacing
11277 (when (memq vhdl-include-group-comments '(decl always))
11278 (vhdl-paste-group-comment (nth 5 port) margin))
11281 (insert (nth 1 port) " ")
11282 (vhdl-insert-keyword "SIGNAL "))
11283 ;; paste actual port signals
11284 (setq names (nth 0 port))
11286 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11287 (setq names (cdr names))
11288 (when names (insert ", ")))
11290 (insert " : " (nth 3 port))
11291 ;; paste initialization (inputs only)
11292 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11293 (insert " := " (if (string-match "(.+)" (nth 3 port))
11294 "(others => '0')" "'0'")))
11297 (when (or vhdl-include-direction-comments
11298 (and vhdl-include-port-comments (nth 4 port)))
11299 (vhdl-comment-insert-inline
11301 (cond ((and vhdl-include-direction-comments (nth 2 port))
11302 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11303 (vhdl-include-direction-comments " "))
11304 (when vhdl-include-port-comments (nth 4 port))) t))
11305 (setq port-list (cdr port-list))
11306 (when port-list (insert "\n") (indent-to margin)))
11307 ;; align signal list
11308 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11309 (message "Pasting port as signals...done")))
11311 (defun vhdl-port-paste-initializations (&optional no-indent)
11312 "Paste ports as signal initializations."
11314 (if (not vhdl-port-list)
11315 (error "ERROR: No port read")
11316 (let ((orig-vhdl-port-list vhdl-port-list))
11317 (message "Pasting port as initializations...")
11318 ;; flatten local copy of port list (must be flat for signal initial.)
11319 (vhdl-port-flatten)
11320 (unless no-indent (indent-according-to-mode))
11321 (let ((margin (current-indentation))
11323 (port-list (nth 2 vhdl-port-list)))
11325 (setq start (point))
11327 (setq port (car port-list))
11328 ;; paste actual port signal (inputs only)
11329 (when (equal "IN" (upcase (nth 2 port)))
11330 (setq name (car (nth 0 port)))
11331 (insert (vhdl-replace-string vhdl-actual-port-name name))
11332 ;; paste initialization
11333 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11334 "(others => '0')" "'0'") ";"))
11335 (setq port-list (cdr port-list))
11336 (when (and port-list
11337 (equal "IN" (upcase (nth 2 (car port-list)))))
11338 (insert "\n") (indent-to margin)))
11339 ;; align signal list
11340 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11341 (message "Pasting port as initializations...done")
11342 (setq vhdl-port-list orig-vhdl-port-list))))
11344 (defun vhdl-port-paste-testbench ()
11345 "Paste as a bare-bones testbench."
11347 (if (not vhdl-port-list)
11348 (error "ERROR: No port read")
11349 (let ((case-fold-search t)
11350 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11351 (nth 0 vhdl-port-list)))
11352 (source-buffer (current-buffer))
11353 arch-name config-name ent-file-name arch-file-name
11354 ent-buffer arch-buffer position)
11355 ;; open entity file
11356 (unless (eq vhdl-testbench-create-files 'none)
11357 (setq ent-file-name
11358 (concat ent-name "." (file-name-extension (buffer-file-name))))
11359 (if (file-exists-p ent-file-name)
11361 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11362 (progn (find-file ent-file-name)
11364 (set-buffer-modified-p nil))
11365 (if (eq vhdl-testbench-create-files 'separate)
11366 (setq ent-file-name nil)
11367 (error "ERROR: Pasting port as testbench...aborted")))
11368 (find-file ent-file-name)))
11369 (unless (and (eq vhdl-testbench-create-files 'separate)
11370 (null ent-file-name))
11371 ;; paste entity header
11372 (if vhdl-testbench-include-header
11373 (progn (vhdl-template-header
11374 (concat "Testbench for design \""
11375 (nth 0 vhdl-port-list) "\""))
11376 (goto-char (point-max)))
11377 (vhdl-comment-display-line) (insert "\n\n"))
11378 ;; paste std_logic_1164 package
11379 (when vhdl-testbench-include-library
11380 (vhdl-template-package-std-logic-1164)
11381 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11382 ;; paste entity declaration
11383 (vhdl-insert-keyword "ENTITY ")
11385 (vhdl-insert-keyword " IS")
11386 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
11388 (vhdl-insert-keyword "END ")
11389 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11390 (insert ent-name ";")
11392 (vhdl-comment-display-line) (insert "\n"))
11393 ;; get architecture name
11394 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11395 (read-from-minibuffer "architecture name: "
11396 nil vhdl-minibuffer-local-map)
11397 (vhdl-replace-string vhdl-testbench-architecture-name
11398 (nth 0 vhdl-port-list))))
11399 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11400 ;; open architecture file
11401 (if (not (eq vhdl-testbench-create-files 'separate))
11403 (setq ent-buffer (current-buffer))
11404 (setq arch-file-name
11405 (concat ent-name "_" arch-name "."
11406 (file-name-extension (buffer-file-name))))
11407 (when (and (file-exists-p arch-file-name)
11408 (not (y-or-n-p (concat "File \"" arch-file-name
11409 "\" exists; overwrite? "))))
11410 (error "ERROR: Pasting port as testbench...aborted"))
11411 (find-file arch-file-name)
11413 (set-buffer-modified-p nil)
11414 ;; paste architecture header
11415 (if vhdl-testbench-include-header
11416 (progn (vhdl-template-header
11417 (concat "Testbench architecture for design \""
11418 (nth 0 vhdl-port-list) "\""))
11419 (goto-char (point-max)))
11420 (vhdl-comment-display-line) (insert "\n\n")))
11421 ;; paste architecture body
11422 (vhdl-insert-keyword "ARCHITECTURE ")
11424 (vhdl-insert-keyword " OF ")
11426 (vhdl-insert-keyword " IS")
11427 (insert "\n\n") (indent-to vhdl-basic-offset)
11428 ;; paste component declaration
11429 (unless (vhdl-use-direct-instantiation)
11430 (vhdl-port-paste-component t)
11431 (insert "\n\n") (indent-to vhdl-basic-offset))
11433 (when (nth 1 vhdl-port-list)
11434 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11435 (vhdl-port-paste-constants t)
11436 (insert "\n\n") (indent-to vhdl-basic-offset))
11437 ;; paste internal signals
11438 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11439 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11441 ;; paste custom declarations
11442 (unless (equal "" vhdl-testbench-declarations)
11444 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11445 (setq position (point))
11447 (vhdl-comment-display-line) (insert "\n")
11448 (when vhdl-testbench-include-configuration
11449 (setq config-name (vhdl-replace-string
11450 vhdl-testbench-configuration-name
11451 (concat ent-name " " arch-name)))
11453 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11454 (vhdl-insert-keyword " OF ") (insert ent-name)
11455 (vhdl-insert-keyword " IS\n")
11456 (indent-to vhdl-basic-offset)
11457 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11458 (indent-to vhdl-basic-offset)
11459 (vhdl-insert-keyword "END FOR;\n")
11460 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11461 (vhdl-comment-display-line) (insert "\n"))
11462 (goto-char position)
11463 (vhdl-template-begin-end
11464 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11465 ;; paste instantiation
11466 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11467 (vhdl-port-paste-instance
11468 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11470 ;; paste custom statements
11471 (unless (equal "" vhdl-testbench-statements)
11473 (vhdl-insert-string-or-file vhdl-testbench-statements))
11475 (indent-to vhdl-basic-offset)
11476 (unless (eq vhdl-testbench-create-files 'none)
11477 (setq arch-buffer (current-buffer))
11478 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11479 (set-buffer arch-buffer) (save-buffer))
11481 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11482 ent-name arch-name)
11484 (format "\n File created: \"%s\"" ent-file-name))
11485 (and arch-file-name
11486 (format "\n File created: \"%s\"" arch-file-name)))))))
11489 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11490 ;;; Subprogram interface translation
11491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11493 (defvar vhdl-subprog-list nil
11494 "Variable to hold last subprogram interface parsed.")
11495 ;; structure: (parenthesised expression means list of such entries)
11496 ;; (subprog-name kind
11497 ;; ((names) object direct type init comment group-comment)
11498 ;; return-type return-comment group-comment)
11500 (defvar vhdl-subprog-flattened nil
11501 "Indicates whether an subprogram interface has been flattened.")
11503 (defun vhdl-subprog-flatten ()
11504 "Flatten interface list so that only one parameter exists per line."
11506 (if (not vhdl-subprog-list)
11507 (error "ERROR: No subprogram interface has been read")
11508 (message "Flattening subprogram interface...")
11509 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11510 new-subprog-list old-subprog new-subprog names)
11511 ;; traverse parameter list and flatten entries
11512 (while old-subprog-list
11513 (setq old-subprog (car old-subprog-list))
11514 (setq names (car old-subprog))
11516 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11517 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11518 (setq names (cdr names)))
11519 (setq old-subprog-list (cdr old-subprog-list)))
11520 (setq vhdl-subprog-list
11521 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11522 new-subprog-list (nth 3 vhdl-subprog-list)
11523 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11524 vhdl-subprog-flattened t)
11525 (message "Flattening subprogram interface...done"))))
11527 (defun vhdl-subprog-copy ()
11528 "Get interface information from a subprogram specification."
11531 (let (parse-error pos end-of-list
11532 name kind param-list object names direct type init
11533 comment group-comment
11534 return-type return-comment return-group-comment)
11535 (vhdl-prepare-search-2
11539 ;; check if within function declaration
11542 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11543 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11544 (goto-char (match-end 0))
11545 (save-excursion (backward-char)
11548 (throw 'parse "ERROR: Not within a subprogram specification"))
11549 (setq name (match-string-no-properties 5))
11550 (setq kind (if (match-string 2) 'procedure 'function))
11551 (setq end-of-list (not (match-string 7)))
11552 (message "Reading interface of subprogram \"%s\"..." name)
11553 ;; parse parameter list
11554 (setq group-comment (vhdl-parse-group-comment))
11555 (setq end-of-list (or end-of-list
11556 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11557 (while (not end-of-list)
11560 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11561 (match-string-no-properties 1)))
11562 ;; parse names (accept extended identifiers)
11563 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11564 (setq names (list (match-string-no-properties 1)))
11565 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11566 (setq names (append names (list (match-string-no-properties 1)))))
11568 (vhdl-parse-string ":[ \t\n]*")
11570 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11571 (match-string-no-properties 1)))
11573 (vhdl-parse-string "\\([^():;\n]+\\)")
11574 (setq type (match-string-no-properties 1))
11576 (while (looking-at "(")
11579 (buffer-substring-no-properties
11580 (point) (progn (forward-sexp) (point)))
11581 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11582 (match-string-no-properties 1)))))
11583 ;; special case: closing parenthesis is on separate line
11584 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11585 (setq comment (substring type (match-beginning 2)))
11586 (setq type (substring type 0 (match-beginning 1))))
11587 ;; strip off trailing group-comment
11588 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11589 (setq type (substring type 0 (match-end 1)))
11590 ;; parse initialization expression
11592 (when (vhdl-parse-string ":=[ \t\n]*" t)
11593 (vhdl-parse-string "\\([^();\n]*\\)")
11594 (setq init (match-string-no-properties 1))
11595 (while (looking-at "(")
11598 (buffer-substring-no-properties
11599 (point) (progn (forward-sexp) (point)))
11600 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11601 (match-string-no-properties 1))))))
11602 ;; special case: closing parenthesis is on separate line
11603 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11604 (setq comment (substring init (match-beginning 2)))
11605 (setq init (substring init 0 (match-beginning 1)))
11606 (vhdl-forward-syntactic-ws))
11607 (skip-chars-forward " \t")
11608 ;; parse inline comment, special case: as above, no initial.
11610 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11611 (match-string-no-properties 1))))
11612 (vhdl-forward-syntactic-ws)
11613 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11614 ;; parse inline comment
11616 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11617 (match-string-no-properties 1))))
11618 (setq return-group-comment (vhdl-parse-group-comment))
11619 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11620 ;; parse return type
11621 (when (match-string 3)
11622 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11623 (setq return-type (match-string-no-properties 1))
11624 (when (and return-type
11625 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11626 (setq return-comment (substring return-type (match-beginning 2)))
11627 (setq return-type (substring return-type 0 (match-beginning 1))))
11628 ;; strip of trailing group-comment
11629 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11630 (setq return-type (substring return-type 0 (match-end 1)))
11631 ;; parse return comment
11632 (unless return-comment
11633 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11634 (match-string-no-properties 1)))))
11635 ;; parse inline comment
11637 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11638 (match-string-no-properties 1))))
11639 ;; save everything in list
11640 (setq param-list (append param-list
11641 (list (list names object direct type init
11642 comment group-comment))))
11643 ;; parse group comment and spacing
11644 (setq group-comment (vhdl-parse-group-comment)))
11645 (message "Reading interface of subprogram \"%s\"...done" name)
11649 (error parse-error)
11650 (setq vhdl-subprog-list
11651 (list name kind param-list return-type return-comment
11652 return-group-comment)
11653 vhdl-subprog-flattened nil)))))
11655 (defun vhdl-subprog-paste-specification (kind)
11656 "Paste as a subprogram specification."
11657 (indent-according-to-mode)
11658 (let ((margin (current-column))
11659 (param-list (nth 2 vhdl-subprog-list))
11660 list-margin start names param)
11661 ;; paste keyword and name
11662 (vhdl-insert-keyword
11663 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11664 (insert (nth 0 vhdl-subprog-list))
11665 (if (not param-list)
11666 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11667 (setq start (point))
11668 ;; paste parameter list
11670 (unless vhdl-argument-list-indent
11671 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11672 (setq list-margin (current-column))
11674 (setq param (car param-list))
11675 ;; paste group comment and spacing
11676 (when (memq vhdl-include-group-comments (list kind 'always))
11677 (vhdl-paste-group-comment (nth 6 param) list-margin))
11679 (when (nth 1 param) (insert (nth 1 param) " "))
11681 (setq names (nth 0 param))
11683 (insert (car names))
11684 (setq names (cdr names))
11685 (when names (insert ", ")))
11688 (when (nth 2 param) (insert (nth 2 param) " "))
11690 (insert (nth 3 param))
11691 ;; paste initialization
11692 (when (nth 4 param) (insert " := " (nth 4 param)))
11694 (if (cdr param-list)
11697 (when (null (nth 3 vhdl-subprog-list))
11698 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11700 (when (and vhdl-include-port-comments (nth 5 param))
11701 (vhdl-comment-insert-inline (nth 5 param) t))
11702 (setq param-list (cdr param-list))
11703 (when param-list (insert "\n") (indent-to list-margin)))
11704 (when (nth 3 vhdl-subprog-list)
11705 (insert "\n") (indent-to list-margin)
11706 ;; paste group comment and spacing
11707 (when (memq vhdl-include-group-comments (list kind 'always))
11708 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11709 ;; paste return type
11710 (insert "return " (nth 3 vhdl-subprog-list))
11711 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11712 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11713 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11714 ;; align parameter list
11715 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11717 (when (eq kind 'body)
11719 (vhdl-template-begin-end
11720 (unless (vhdl-standard-p '87)
11721 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11722 (nth 0 vhdl-subprog-list) margin))))
11724 (defun vhdl-subprog-paste-declaration ()
11725 "Paste as a subprogram declaration."
11727 (if (not vhdl-subprog-list)
11728 (error "ERROR: No subprogram interface read")
11729 (message "Pasting interface as subprogram declaration \"%s\"..."
11730 (car vhdl-subprog-list))
11731 ;; paste specification
11732 (vhdl-subprog-paste-specification 'decl)
11733 (message "Pasting interface as subprogram declaration \"%s\"...done"
11734 (car vhdl-subprog-list))))
11736 (defun vhdl-subprog-paste-body ()
11737 "Paste as a subprogram body."
11739 (if (not vhdl-subprog-list)
11740 (error "ERROR: No subprogram interface read")
11741 (message "Pasting interface as subprogram body \"%s\"..."
11742 (car vhdl-subprog-list))
11743 ;; paste specification and body
11744 (vhdl-subprog-paste-specification 'body)
11745 (message "Pasting interface as subprogram body \"%s\"...done"
11746 (car vhdl-subprog-list))))
11748 (defun vhdl-subprog-paste-call ()
11749 "Paste as a subprogram call."
11751 (if (not vhdl-subprog-list)
11752 (error "ERROR: No subprogram interface read")
11753 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11754 param-list margin list-margin param start)
11755 ;; flatten local copy of interface list (must be flat for parameter mapping)
11756 (vhdl-subprog-flatten)
11757 (setq param-list (nth 2 vhdl-subprog-list))
11758 (indent-according-to-mode)
11759 (setq margin (current-indentation))
11760 (message "Pasting interface as subprogram call \"%s\"..."
11761 (car vhdl-subprog-list))
11763 (insert (nth 0 vhdl-subprog-list))
11764 (if (not param-list)
11766 (setq start (point))
11767 ;; paste parameter list
11769 (unless vhdl-argument-list-indent
11770 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11771 (setq list-margin (current-column))
11773 (setq param (car param-list))
11774 ;; paste group comment and spacing
11775 (when (eq vhdl-include-group-comments 'always)
11776 (vhdl-paste-group-comment (nth 6 param) list-margin))
11777 ;; paste formal port
11778 (insert (car (nth 0 param)) " => ")
11779 (setq param-list (cdr param-list))
11780 (insert (if param-list "," ");"))
11782 (when (and vhdl-include-port-comments (nth 5 param))
11783 (vhdl-comment-insert-inline (nth 5 param)))
11784 (when param-list (insert "\n") (indent-to list-margin)))
11785 ;; align parameter list
11786 (when vhdl-auto-align
11787 (vhdl-align-region-groups start (point) 1)))
11788 (message "Pasting interface as subprogram call \"%s\"...done"
11789 (car vhdl-subprog-list))
11790 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11793 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11795 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11797 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11798 ;; Hippie expand customization
11800 (defvar vhdl-expand-upper-case nil)
11802 (defun vhdl-try-expand-abbrev (old)
11803 "Try expanding abbreviations from `vhdl-abbrev-list'."
11805 (he-init-string (he-dabbrev-beg) (point))
11806 (setq he-expand-list
11807 (let ((abbrev-list vhdl-abbrev-list)
11808 (sel-abbrev-list '()))
11810 (when (or (not (stringp (car abbrev-list)))
11812 (concat "^" he-search-string) (car abbrev-list)))
11813 (setq sel-abbrev-list
11814 (cons (car abbrev-list) sel-abbrev-list)))
11815 (setq abbrev-list (cdr abbrev-list)))
11816 (nreverse sel-abbrev-list))))
11817 (while (and he-expand-list
11818 (or (not (stringp (car he-expand-list)))
11819 (he-string-member (car he-expand-list) he-tried-table t)))
11820 ; (equal (car he-expand-list) he-search-string)))
11821 (unless (stringp (car he-expand-list))
11822 (setq vhdl-expand-upper-case (car he-expand-list)))
11823 (setq he-expand-list (cdr he-expand-list)))
11824 (if (null he-expand-list)
11825 (progn (when old (he-reset-string))
11827 (he-substitute-string
11828 (if vhdl-expand-upper-case
11829 (upcase (car he-expand-list))
11830 (car he-expand-list))
11832 (setq he-expand-list (cdr he-expand-list))
11835 (defun vhdl-he-list-beg ()
11836 "Also looks at the word before `(' in order to better match parenthesized
11837 expressions (e.g. for index ranges of types and signals)."
11840 (progn (backward-up-list 1)
11841 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
11845 ;; override `he-list-beg' from `hippie-exp'
11846 (unless (and (boundp 'viper-mode) viper-mode)
11847 (defalias 'he-list-beg 'vhdl-he-list-beg))
11849 ;; function for expanding abbrevs and dabbrevs
11850 (defun vhdl-expand-abbrev (arg))
11851 (fset 'vhdl-expand-abbrev (make-hippie-expand-function
11852 '(try-expand-dabbrev
11853 try-expand-dabbrev-all-buffers
11854 vhdl-try-expand-abbrev)))
11856 ;; function for expanding parenthesis
11857 (defun vhdl-expand-paren (arg))
11858 (fset 'vhdl-expand-paren (make-hippie-expand-function
11860 try-expand-list-all-buffers)))
11862 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11865 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
11866 "Convert all words matching word-regexp in region to lower or upper case,
11867 depending on parameter upper-case."
11868 (let ((case-replace nil)
11870 (vhdl-prepare-search-2
11873 (setq end (point-marker))
11875 (while (re-search-forward word-regexp end t)
11876 (or (vhdl-in-literal)
11879 (downcase-word -1)))
11880 (when (and count vhdl-progress-interval (not noninteractive)
11881 (< vhdl-progress-interval
11882 (- (nth 1 (current-time)) last-update)))
11883 (message "Fixing case... (%2d%s)"
11884 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
11886 (setq last-update (nth 1 (current-time)))))
11887 (goto-char end)))))
11889 (defun vhdl-fix-case-region (beg end &optional arg)
11890 "Convert all VHDL words in region to lower or upper case, depending on
11891 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
11892 (interactive "r\nP")
11893 (vhdl-fix-case-region-1
11894 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
11895 (vhdl-fix-case-region-1
11896 beg end vhdl-upper-case-types vhdl-types-regexp 1)
11897 (vhdl-fix-case-region-1
11898 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
11899 (vhdl-fix-case-region-1
11900 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
11901 (when vhdl-progress-interval (message "Fixing case...done")))
11903 (defun vhdl-fix-case-buffer ()
11904 "Convert all VHDL words in buffer to lower or upper case, depending on
11905 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
11907 (vhdl-fix-case-region (point-min) (point-max)))
11909 (defun vhdl-fix-case-word (&optional arg)
11910 "Convert word after cursor to upper case if necessary."
11913 (when arg (backward-word 1))
11914 (vhdl-prepare-search-1
11915 (when (and vhdl-upper-case-keywords
11916 (looking-at vhdl-keywords-regexp))
11918 (when (and vhdl-upper-case-types
11919 (looking-at vhdl-types-regexp))
11921 (when (and vhdl-upper-case-attributes
11922 (looking-at vhdl-attributes-regexp))
11924 (when (and vhdl-upper-case-enum-values
11925 (looking-at vhdl-enum-values-regexp))
11926 (upcase-word 1)))))
11928 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11929 ;; Line handling functions
11931 (defun vhdl-current-line ()
11932 "Return the line number of the line containing point."
11935 (1+ (count-lines (point-min) (line-beginning-position)))))
11937 (defun vhdl-line-kill-entire (&optional arg)
11938 "Delete entire line."
11940 (beginning-of-line)
11941 (kill-line (or arg 1)))
11943 (defun vhdl-line-kill (&optional arg)
11944 "Kill current line."
11946 (vhdl-line-kill-entire arg))
11948 (defun vhdl-line-copy (&optional arg)
11949 "Copy current line."
11952 (beginning-of-line)
11953 (let ((position (point)))
11954 (forward-line (or arg 1))
11955 (copy-region-as-kill position (point)))))
11957 (defun vhdl-line-yank ()
11958 "Yank entire line."
11960 (beginning-of-line)
11963 (defun vhdl-line-expand (&optional prefix-arg)
11964 "Hippie-expand current line."
11966 (let ((case-fold-search t) (case-replace nil)
11967 (hippie-expand-try-functions-list
11968 '(try-expand-line try-expand-line-all-buffers)))
11969 (hippie-expand prefix-arg)))
11971 (defun vhdl-line-transpose-next (&optional arg)
11972 "Interchange this line with next line."
11975 (transpose-lines (or arg 1))
11978 (defun vhdl-line-transpose-previous (&optional arg)
11979 "Interchange this line with previous line."
11982 (transpose-lines (- 0 (or arg 0)))
11985 (defun vhdl-line-open ()
11986 "Open a new line and indent."
11989 (newline-and-indent))
11991 (defun vhdl-delete-indentation ()
11992 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
11993 it works within comments too."
11995 (let ((fill-prefix "-- "))
11996 (delete-indentation)))
11998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12001 (defun vhdl-forward-same-indent ()
12002 "Move forward to next line with same indent."
12004 (let ((pos (point))
12005 (indent (current-indentation)))
12006 (beginning-of-line 2)
12007 (while (and (not (eobp))
12008 (or (looking-at "^\\s-*\\(--.*\\)?$")
12009 (> (current-indentation) indent)))
12010 (beginning-of-line 2))
12011 (if (= (current-indentation) indent)
12012 (back-to-indentation)
12013 (message "No following line with same indent found in this block")
12017 (defun vhdl-backward-same-indent ()
12018 "Move backward to previous line with same indent."
12020 (let ((pos (point))
12021 (indent (current-indentation)))
12022 (beginning-of-line -0)
12023 (while (and (not (bobp))
12024 (or (looking-at "^\\s-*\\(--.*\\)?$")
12025 (> (current-indentation) indent)))
12026 (beginning-of-line -0))
12027 (if (= (current-indentation) indent)
12028 (back-to-indentation)
12029 (message "No preceding line with same indent found in this block")
12033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12036 (defun vhdl-statistics-buffer ()
12037 "Get some file statistics."
12041 (no-lines (count-lines (point-min) (point-max))))
12043 ;; count statements
12044 (goto-char (point-min))
12045 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12046 (if (match-string 1)
12047 (goto-char (match-end 1))
12048 (setq no-stats (1+ no-stats))))
12049 ;; count code lines
12050 (goto-char (point-min))
12051 (while (not (eobp))
12052 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12053 (setq no-code-lines (1+ no-code-lines)))
12054 (beginning-of-line 2)))
12057 File statistics: \"%s\"\n\
12058 ---------------------\n\
12059 # statements : %5d\n\
12060 # code lines : %5d\n\
12061 # total lines : %5d\n\ "
12062 (buffer-file-name) no-stats no-code-lines no-lines)))
12064 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12067 (defun vhdl-re-search-forward (regexp &optional bound noerror count)
12068 "Like `re-search-forward', but does not match within literals."
12071 (while (and (setq pos (re-search-forward regexp bound noerror count))
12072 (vhdl-in-literal))))
12073 (when pos (goto-char pos))
12076 (defun vhdl-re-search-backward (regexp &optional bound noerror count)
12077 "Like `re-search-backward', but does not match within literals."
12080 (while (and (setq pos (re-search-backward regexp bound noerror count))
12081 (vhdl-in-literal))))
12082 (when pos (goto-char pos))
12086 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12088 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12090 (defun vhdl-set-project (name)
12091 "Set current project to NAME."
12093 (list (let ((completion-ignore-case t))
12094 (completing-read "Project name: " vhdl-project-alist nil t))))
12095 (cond ((equal name "")
12096 (setq vhdl-project nil)
12097 (message "Current VHDL project: None"))
12098 ((assoc name vhdl-project-alist)
12099 (setq vhdl-project name)
12100 (message "Current VHDL project: \"%s\"" name))
12102 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12103 (vhdl-speedbar-update-current-project))
12105 (defun vhdl-toggle-project (name token indent)
12106 "Set current project to NAME or unset if NAME is current project."
12107 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12109 (defun vhdl-export-project (file-name)
12110 "Write project setup for current project."
12112 (let ((name (vhdl-resolve-env-variable
12113 (vhdl-replace-string
12114 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12115 (concat (subst-char-in-string
12116 ? ?_ (or (vhdl-project-p)
12117 (error "ERROR: No current project")))
12118 " " (user-login-name))))))
12119 (list (read-file-name
12120 "Write project file: "
12121 (when (file-name-absolute-p name) "") nil nil name))))
12122 (setq file-name (abbreviate-file-name file-name))
12123 (let ((orig-buffer (current-buffer)))
12124 (unless (file-exists-p (file-name-directory file-name))
12125 (make-directory (file-name-directory file-name) t))
12126 (if (not (file-writable-p file-name))
12127 (error "ERROR: File not writable: \"%s\"" file-name)
12128 (set-buffer (find-file-noselect file-name t t))
12130 (insert ";; -*- Emacs-Lisp -*-\n\n"
12131 ";;; " (file-name-nondirectory file-name)
12132 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12133 ";; Project : " vhdl-project "\n"
12134 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12135 (user-login-name) "\n\n\n"
12136 ";; project name\n"
12137 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12138 ";; project setup\n"
12139 "(aput 'vhdl-project-alist vhdl-project\n'")
12140 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12143 (kill-buffer (current-buffer))
12144 (set-buffer orig-buffer))))
12146 (defun vhdl-import-project (file-name &optional auto not-make-current)
12147 "Read project setup and set current project."
12149 (let ((name (vhdl-resolve-env-variable
12150 (vhdl-replace-string
12151 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12152 (concat "" " " (user-login-name))))))
12153 (list (read-file-name
12154 "Read project file: " (when (file-name-absolute-p name) "") nil t
12155 (file-name-directory name)))))
12156 (when (file-exists-p file-name)
12158 (let ((current-project vhdl-project))
12159 (load-file file-name)
12160 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12161 (adelete 'vhdl-project-alist vhdl-project)
12163 (when not-make-current
12164 (setq vhdl-project current-project))
12165 (vhdl-update-mode-menu)
12166 (vhdl-speedbar-refresh)
12167 (unless not-make-current
12168 (message "Current VHDL project: \"%s\"%s"
12169 vhdl-project (if auto " (auto-loaded)" ""))))
12170 (error (vhdl-warning
12171 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12173 (defun vhdl-duplicate-project ()
12174 "Duplicate setup of current project."
12176 (let ((new-name (read-from-minibuffer "New project name: "))
12177 (project-entry (aget vhdl-project-alist vhdl-project t)))
12178 (setq vhdl-project-alist
12179 (append vhdl-project-alist
12180 (list (cons new-name project-entry))))
12181 (vhdl-update-mode-menu)))
12183 (defun vhdl-auto-load-project ()
12184 "Automatically load project setup at startup."
12185 (let ((file-name-list vhdl-project-file-name)
12186 file-list list-length)
12187 (while file-name-list
12190 (file-expand-wildcards
12191 (vhdl-resolve-env-variable
12192 (vhdl-replace-string
12193 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12194 (concat "\*" " " (user-login-name)))))))
12195 (setq list-length (or list-length (length file-list)))
12196 (setq file-name-list (cdr file-name-list)))
12198 (vhdl-import-project (expand-file-name (car file-list)) t
12199 (not (> list-length 0)))
12200 (setq list-length (1- list-length))
12201 (setq file-list (cdr file-list)))))
12203 ;; automatically load project setup when idle after startup
12204 (when (memq 'startup vhdl-project-auto-load)
12206 (vhdl-auto-load-project)
12207 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
12210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12213 ;; (using `hideshow.el')
12215 (defconst vhdl-hs-start-regexp
12218 ;; generic/port clause
12219 "\\(generic\\|port\\)[ \t\n]*(\\|"
12222 ;; component instantiation
12223 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12224 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12225 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12226 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12228 "\\(function\\|procedure\\)\\>\\|"
12230 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12231 ;; configuration declaration
12234 "Regexp to match start of construct to hide.")
12236 (defun vhdl-hs-forward-sexp-func (count)
12237 "Find end of construct to hide (for hideshow). Only searches forward."
12238 (let ((pos (point)))
12239 (vhdl-prepare-search-2
12240 (beginning-of-line)
12242 ;; generic/port clause
12243 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12244 (goto-char (match-end 0))
12247 ;; component declaration
12248 ((looking-at "^\\s-*component\\>")
12249 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12250 ;; component instantiation
12253 "^\\s-*\\w+\\s-*:[ \t\n]*"
12254 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12255 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12256 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12257 (goto-char (match-end 0))
12261 (vhdl-forward-syntactic-ws)
12262 (when (looking-at "port\\s-+map[ \t\n]*(")
12263 (goto-char (match-end 0))
12266 (setq pos (point)))
12268 ;; subprogram declaration/body
12269 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12270 (goto-char (match-end 0))
12271 (vhdl-forward-syntactic-ws)
12272 (when (looking-at "(")
12274 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12275 (vhdl-in-literal)))
12277 (when (match-string 2)
12278 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12280 (vhdl-forward-sexp)))
12281 ;; block (recursive)
12282 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12283 (goto-char (match-end 0))
12284 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12285 (match-beginning 2))
12286 (vhdl-hs-forward-sexp-func count)))
12288 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12289 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12290 ;; configuration declaration
12291 ((looking-at "^\\s-*configuration\\>")
12293 (vhdl-forward-sexp))
12294 (t (goto-char pos))))))
12296 (defun vhdl-hideshow-init ()
12297 "Initialize `hideshow'."
12298 (when vhdl-hideshow-menu
12299 (vhdl-hs-minor-mode 1)))
12301 (defun vhdl-hs-minor-mode (&optional arg)
12302 "Toggle hideshow minor mode and update menu bar."
12304 (require 'hideshow)
12305 ;; check for hideshow version 5.x
12306 (if (not (boundp 'hs-block-start-mdata-select))
12307 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12308 ;; initialize hideshow
12309 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12310 (setq hs-special-modes-alist
12311 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12312 'vhdl-hs-forward-sexp-func nil)
12313 hs-special-modes-alist)))
12314 (make-local-variable 'hs-minor-mode-hook)
12315 (if vhdl-hide-all-init
12316 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12317 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12318 (hs-minor-mode arg)
12319 (vhdl-mode-line-update))) ; hack to update menu bar
12322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12325 ;; (using `font-lock.el')
12327 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12330 (defun vhdl-within-translate-off ()
12331 "Return point if within translate-off region, else nil."
12332 (and (save-excursion
12333 (re-search-backward
12334 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12335 (equal "off" (match-string 1))
12338 (defun vhdl-start-translate-off (limit)
12339 "Return point before translate-off pragma if before LIMIT, else nil."
12340 (when (re-search-forward
12341 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12342 (match-beginning 0)))
12344 (defun vhdl-end-translate-off (limit)
12345 "Return point after translate-on pragma if before LIMIT, else nil."
12346 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12348 (defun vhdl-match-translate-off (limit)
12349 "Match a translate-off block, setting match-data and returning t, else nil."
12350 (when (< (point) limit)
12351 (let ((start (or (vhdl-within-translate-off)
12352 (vhdl-start-translate-off limit)))
12353 (case-fold-search t))
12355 (let ((end (or (vhdl-end-translate-off limit) limit)))
12356 (set-match-data (list start end))
12357 (goto-char end))))))
12359 (defun vhdl-font-lock-match-item (limit)
12360 "Match, and move over, any declaration item after point. Adapted from
12361 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
12362 (condition-case nil
12364 (narrow-to-region (point-min) limit)
12366 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
12368 (goto-char (match-end 1))
12369 ;; move to next item
12370 (if (looking-at "\\s-*,")
12371 (goto-char (match-end 0))
12372 (end-of-line) t))))
12375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12376 ;; Syntax definitions
12378 (defconst vhdl-font-lock-syntactic-keywords
12379 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12380 "Mark single quotes as having string quote syntax in 'c' instances.")
12382 (defvar vhdl-font-lock-keywords nil
12383 "Regular expressions to highlight in VHDL Mode.")
12385 (defvar vhdl-font-lock-keywords-0
12386 ;; set in `vhdl-font-lock-init' because dependent on user options
12387 "For consideration as a value of `vhdl-font-lock-keywords'.
12388 This does highlighting of template prompts and directives (pragmas).")
12390 (defvar vhdl-font-lock-keywords-1 nil
12391 ;; set in `vhdl-font-lock-init' because dependent on user options
12392 "For consideration as a value of `vhdl-font-lock-keywords'.
12393 This does highlighting of keywords and standard identifiers.")
12395 (defconst vhdl-font-lock-keywords-2
12397 ;; highlight names of units, subprograms, and components when declared
12401 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12402 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
12403 "\\)\\s-+\\(\\w+\\)")
12404 5 'font-lock-function-name-face)
12406 ;; highlight entity names of architectures and configurations
12408 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12409 2 'font-lock-function-name-face)
12411 ;; highlight labels of common constructs
12414 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12415 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12416 "postponed\\|process\\|"
12417 (when (vhdl-standard-p 'ams) "procedural\\|")
12419 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\)*\\s-*<=\\)")
12420 1 'font-lock-function-name-face)
12422 ;; highlight label and component name of component instantiations
12425 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12426 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12427 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12429 ;; highlight label and instantiated unit of component instantiations
12432 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12433 "\\(component\\|configuration\\|entity\\)\\s-+"
12434 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12435 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12436 '(5 font-lock-function-name-face nil t)
12437 '(7 font-lock-function-name-face nil t))
12439 ;; highlight names and labels at end of constructs
12442 "^\\s-*end\\s-+\\(\\("
12443 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
12444 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12445 "procedure\\|\\(postponed\\s-+\\)?process\\|"
12446 (when (vhdl-standard-p 'ams) "procedural\\|")
12448 "\\)\\s-+\\)?\\(\\w*\\)")
12449 5 'font-lock-function-name-face)
12451 ;; highlight labels in exit and next statements
12454 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12455 3 'font-lock-function-name-face)
12457 ;; highlight entity name in attribute specifications
12460 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12461 1 'font-lock-function-name-face)
12463 ;; highlight labels in block and component specifications
12466 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12467 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12468 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12470 ;; highlight names in library clauses
12471 (list "^\\s-*library\\>"
12472 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12474 ;; highlight names in use clauses
12477 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12478 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12479 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12480 '(7 font-lock-function-name-face nil t))
12482 ;; highlight attribute name in attribute declarations/specifications
12485 "^\\s-*attribute\\s-+\\(\\w+\\)")
12488 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12491 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
12492 3 'font-lock-type-face)
12494 ;; highlight signal/variable/constant declaration names
12495 (list "\\(:[^=]\\)"
12496 '(vhdl-font-lock-match-item
12497 (progn (goto-char (match-beginning 1))
12498 (skip-syntax-backward " ")
12499 (skip-syntax-backward "w_")
12500 (skip-syntax-backward " ")
12501 (while (= (preceding-char) ?,)
12503 (skip-syntax-backward " ")
12504 (skip-syntax-backward "w_")
12505 (skip-syntax-backward " ")))
12506 ; (skip-chars-backward "^-(\n\";")
12507 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12509 ;; highlight formal parameters in component instantiations and subprogram
12512 '(vhdl-font-lock-match-item
12513 (progn (goto-char (match-beginning 1))
12514 (skip-syntax-backward " ")
12515 (while (= (preceding-char) ?\)) (backward-sexp))
12516 (skip-syntax-backward "w_")
12517 (skip-syntax-backward " ")
12518 (when (memq (preceding-char) '(?n ?N))
12519 (goto-char (point-max))))
12520 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12522 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12524 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
12525 '(vhdl-font-lock-match-item
12526 (progn (goto-char (match-end 1)) (match-beginning 2))
12527 nil (1 font-lock-variable-name-face)))
12529 "For consideration as a value of `vhdl-font-lock-keywords'.
12530 This does context sensitive highlighting of names and labels.")
12532 (defvar vhdl-font-lock-keywords-3 nil
12533 ;; set in `vhdl-font-lock-init' because dependent on user options
12534 "For consideration as a value of `vhdl-font-lock-keywords'.
12535 This does highlighting of words with special syntax.")
12537 (defvar vhdl-font-lock-keywords-4 nil
12538 ;; set in `vhdl-font-lock-init' because dependent on user options
12539 "For consideration as a value of `vhdl-font-lock-keywords'.
12540 This does highlighting of additional reserved words.")
12542 (defconst vhdl-font-lock-keywords-5
12543 ;; background highlight translate-off regions
12544 '((vhdl-match-translate-off (0 vhdl-translate-off-face append)))
12545 "For consideration as a value of `vhdl-font-lock-keywords'.
12546 This does background highlighting of translate-off regions.")
12548 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12549 ;; Font and color definitions
12551 (defvar vhdl-prompt-face 'vhdl-prompt
12552 "Face name to use for prompts.")
12554 (defvar vhdl-attribute-face 'vhdl-attribute
12555 "Face name to use for standardized attributes.")
12557 (defvar vhdl-enumvalue-face 'vhdl-enumvalue
12558 "Face name to use for standardized enumeration values.")
12560 (defvar vhdl-function-face 'vhdl-function
12561 "Face name to use for standardized functions and packages.")
12563 (defvar vhdl-directive-face 'vhdl-directive
12564 "Face name to use for directives.")
12566 (defvar vhdl-reserved-words-face 'vhdl-reserved-words
12567 "Face name to use for additional reserved words.")
12569 (defvar vhdl-translate-off-face 'vhdl-translate-off
12570 "Face name to use for translate-off regions.")
12572 ;; face names to use for words with special syntax.
12573 (let ((syntax-alist vhdl-special-syntax-alist)
12575 (while syntax-alist
12576 (setq name (vhdl-function-name "vhdl" (nth 0 (car syntax-alist))))
12577 (eval `(defvar ,name ',name
12578 ,(concat "Face name to use for "
12579 (nth 0 (car syntax-alist)) ".")))
12580 (setq syntax-alist (cdr syntax-alist))))
12582 (defgroup vhdl-highlight-faces nil
12583 "Faces for highlighting."
12584 :group 'vhdl-highlight)
12586 ;; add faces used from `font-lock'
12587 (custom-add-to-group
12588 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12589 (custom-add-to-group
12590 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12591 (custom-add-to-group
12592 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12593 (custom-add-to-group
12594 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12595 (custom-add-to-group
12596 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12597 (custom-add-to-group
12598 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12600 (defface vhdl-prompt
12601 '((((min-colors 88) (class color) (background light))
12602 (:foreground "Red1" :bold t))
12603 (((class color) (background light)) (:foreground "Red" :bold t))
12604 (((class color) (background dark)) (:foreground "Pink" :bold t))
12605 (t (:inverse-video t)))
12606 "Font lock mode face used to highlight prompts."
12607 :group 'vhdl-highlight-faces
12608 :group 'font-lock-highlighting-faces)
12609 ;; backward-compatibility alias
12610 (put 'vhdl-font-lock-prompt-face 'face-alias 'vhdl-prompt)
12612 (defface vhdl-attribute
12613 '((((class color) (background light)) (:foreground "Orchid"))
12614 (((class color) (background dark)) (:foreground "LightSteelBlue"))
12615 (t (:italic t :bold t)))
12616 "Font lock mode face used to highlight standardized attributes."
12617 :group 'vhdl-highlight-faces
12618 :group 'font-lock-highlighting-faces)
12619 ;; backward-compatibility alias
12620 (put 'vhdl-font-lock-attribute-face 'face-alias 'vhdl-attribute)
12622 (defface vhdl-enumvalue
12623 '((((class color) (background light)) (:foreground "SaddleBrown"))
12624 (((class color) (background dark)) (:foreground "BurlyWood"))
12625 (t (:italic t :bold t)))
12626 "Font lock mode face used to highlight standardized enumeration values."
12627 :group 'vhdl-highlight-faces
12628 :group 'font-lock-highlighting-faces)
12629 ;; backward-compatibility alias
12630 (put 'vhdl-font-lock-enumvalue-face 'face-alias 'vhdl-enumvalue)
12632 (defface vhdl-function
12633 '((((class color) (background light)) (:foreground "Cyan4"))
12634 (((class color) (background dark)) (:foreground "Orchid1"))
12635 (t (:italic t :bold t)))
12636 "Font lock mode face used to highlight standardized functions and packages."
12637 :group 'vhdl-highlight-faces
12638 :group 'font-lock-highlighting-faces)
12639 ;; backward-compatibility alias
12640 (put 'vhdl-font-lock-function-face 'face-alias 'vhdl-function)
12642 (defface vhdl-directive
12643 '((((class color) (background light)) (:foreground "CadetBlue"))
12644 (((class color) (background dark)) (:foreground "Aquamarine"))
12645 (t (:italic t :bold t)))
12646 "Font lock mode face used to highlight directives."
12647 :group 'vhdl-highlight-faces
12648 :group 'font-lock-highlighting-faces)
12649 ;; backward-compatibility alias
12650 (put 'vhdl-font-lock-directive-face 'face-alias 'vhdl-directive)
12652 (defface vhdl-reserved-word
12653 '((((class color) (background light)) (:foreground "Orange" :bold t))
12654 (((min-colors 88) (class color) (background dark))
12655 (:foreground "Yellow1" :bold t))
12656 (((class color) (background dark)) (:foreground "Yellow" :bold t))
12658 "Font lock mode face used to highlight additional reserved words."
12659 :group 'vhdl-highlight-faces
12660 :group 'font-lock-highlighting-faces)
12661 ;; backward-compatibility alias
12662 (put 'vhdl-font-lock-reserved-words-face 'face-alias 'vhdl-reserved-word)
12664 (defface vhdl-translate-off
12665 '((((class color) (background light)) (:background "LightGray"))
12666 (((class color) (background dark)) (:background "DimGray"))
12668 "Font lock mode face used to background highlight translate-off regions."
12669 :group 'vhdl-highlight-faces
12670 :group 'font-lock-highlighting-faces)
12671 ;; backward-compatibility alias
12672 (put 'vhdl-font-lock-translate-off-face 'face-alias 'vhdl-translate-off)
12674 ;; font lock mode faces used to highlight words with special syntax.
12675 (let ((syntax-alist vhdl-special-syntax-alist))
12676 (while syntax-alist
12677 (eval `(defface ,(vhdl-function-name "vhdl" (caar syntax-alist))
12678 '((((class color) (background light))
12679 (:foreground ,(nth 2 (car syntax-alist))))
12680 (((class color) (background dark))
12681 (:foreground ,(nth 3 (car syntax-alist))))
12683 ,(concat "Font lock mode face used to highlight "
12684 (nth 0 (car syntax-alist)) ".")
12685 :group 'vhdl-highlight-faces
12686 :group 'font-lock-highlighting-faces))
12687 (setq syntax-alist (cdr syntax-alist))))
12689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12690 ;; Font lock initialization
12692 (defun vhdl-font-lock-init ()
12693 "Initialize fontification."
12694 ;; highlight template prompts and directives
12695 (setq vhdl-font-lock-keywords-0
12696 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12697 vhdl-template-prompt-syntax ">\\)")
12699 (list (concat "--\\s-*"
12700 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12701 2 'vhdl-directive t)))
12702 ;; highlight keywords and standardized types, attributes, enumeration
12703 ;; values, and subprograms
12704 (setq vhdl-font-lock-keywords-1
12706 (list (concat "'" vhdl-attributes-regexp) 1 'vhdl-attribute)
12707 (list vhdl-types-regexp 1 'font-lock-type-face)
12708 (list vhdl-functions-regexp 1 'vhdl-function)
12709 (list vhdl-packages-regexp 1 'vhdl-function)
12710 (list vhdl-enum-values-regexp 1 'vhdl-enumvalue)
12711 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12712 ;; highlight words with special syntax.
12713 (setq vhdl-font-lock-keywords-3
12714 (let ((syntax-alist vhdl-special-syntax-alist)
12716 (while syntax-alist
12719 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12720 (vhdl-function-name
12721 "vhdl" (nth 0 (car syntax-alist))))
12723 (setq syntax-alist (cdr syntax-alist)))
12725 ;; highlight additional reserved words
12726 (setq vhdl-font-lock-keywords-4
12727 (list (list vhdl-reserved-words-regexp 1 'vhdl-reserved-word)))
12728 ;; highlight everything together
12729 (setq vhdl-font-lock-keywords
12731 vhdl-font-lock-keywords-0
12732 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12733 (when (or vhdl-highlight-forbidden-words
12734 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12735 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12736 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12737 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12739 ;; initialize fontification for VHDL Mode
12740 (vhdl-font-lock-init)
12742 (defun vhdl-fontify-buffer ()
12743 "Re-initialize fontification and fontify buffer."
12745 (setq font-lock-defaults
12747 'vhdl-font-lock-keywords nil
12748 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12749 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12750 (when (fboundp 'font-lock-unset-defaults)
12751 (font-lock-unset-defaults)) ; not implemented in XEmacs
12752 (font-lock-set-defaults) ;What for? --Stef
12753 (font-lock-mode nil)
12754 (font-lock-mode t))
12756 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12757 ;; Initialization for postscript printing
12759 (defun vhdl-ps-print-settings ()
12760 "Initialize custom face and page settings for postscript printing."
12761 ;; define custom face settings
12762 (unless (or (not vhdl-print-customize-faces)
12764 (set (make-local-variable 'ps-bold-faces)
12765 '(font-lock-keyword-face font-lock-type-face
12766 vhdl-attribute vhdl-enumvalue vhdl-directive))
12767 (set (make-local-variable 'ps-italic-faces)
12768 '(font-lock-comment-face
12769 font-lock-function-name-face font-lock-type-face
12770 vhdl-attribute vhdl-enumvalue vhdl-directive))
12771 (set (make-local-variable 'ps-underlined-faces)
12772 '(font-lock-string-face))
12773 (setq ps-always-build-face-reference t))
12774 ;; define page settings, so that a line containing 79 characters (default)
12775 ;; fits into one column
12776 (when vhdl-print-two-column
12777 (set (make-local-variable 'ps-landscape-mode) t)
12778 (set (make-local-variable 'ps-number-of-columns) 2)
12779 (set (make-local-variable 'ps-font-size) 7.0)
12780 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12781 (set (make-local-variable 'ps-header-font-size) 9.0)
12782 (set (make-local-variable 'ps-header-offset) 12.0)
12783 (when (eq ps-paper-type 'letter)
12784 (set (make-local-variable 'ps-inter-column) 40.0)
12785 (set (make-local-variable 'ps-left-margin) 40.0)
12786 (set (make-local-variable 'ps-right-margin) 40.0))))
12788 (defun vhdl-ps-print-init ()
12789 "Initialize postscript printing."
12791 (when (boundp 'ps-print-color-p)
12792 (vhdl-ps-print-settings))
12793 (make-local-variable 'ps-print-hook)
12794 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12797 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12798 ;;; Hierarchy browser (using `speedbar.el')
12799 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12800 ;; Allows displaying the hierarchy of all VHDL design units contained in a
12801 ;; directory by using the speedbar.
12803 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12806 (defvar vhdl-entity-alist nil
12807 "Cache with entities and corresponding architectures for each
12808 project/directory.")
12809 ;; structure: (parenthesised expression means list of such entries)
12811 ;; (ent-key ent-name ent-file ent-line
12812 ;; (arch-key arch-name arch-file arch-line
12813 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12814 ;; inst-arch-key inst-conf-key inst-lib-key)
12815 ;; (lib-name pack-key))
12816 ;; (lib-name pack-key))
12818 (defvar vhdl-config-alist nil
12819 "Cache with configurations for each project/directory.")
12820 ;; structure: (parenthesised expression means list of such entries)
12822 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
12823 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
12824 ;; inst-conf-key inst-lib-key)
12825 ;; (lib-name pack-key)))
12827 (defvar vhdl-package-alist nil
12828 "Cache with packages for each project/directory.")
12829 ;; structure: (parenthesised expression means list of such entries)
12831 ;; (pack-key pack-name pack-file pack-line
12832 ;; (comp-key comp-name comp-file comp-line)
12833 ;; (func-key func-name func-file func-line)
12834 ;; (lib-name pack-key)
12835 ;; pack-body-file pack-body-line
12836 ;; (func-key func-name func-body-file func-body-line)
12837 ;; (lib-name pack-key)))
12839 (defvar vhdl-ent-inst-alist nil
12840 "Cache with instantiated entities for each project/directory.")
12841 ;; structure: (parenthesised expression means list of such entries)
12842 ;; (cache-key (inst-ent-key))
12844 (defvar vhdl-file-alist nil
12845 "Cache with design units in each file for each project/directory.")
12846 ;; structure: (parenthesised expression means list of such entries)
12848 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
12849 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
12851 (defvar vhdl-directory-alist nil
12852 "Cache with source directories for each project.")
12853 ;; structure: (parenthesised expression means list of such entries)
12854 ;; (cache-key (directory))
12856 (defvar vhdl-speedbar-shown-unit-alist nil
12857 "Alist of design units simultaneously open in the current speedbar for each
12858 directory and project.")
12860 (defvar vhdl-speedbar-shown-project-list nil
12861 "List of projects simultaneously open in the current speedbar.")
12863 (defvar vhdl-updated-project-list nil
12864 "List of projects and directories with updated files.")
12866 (defvar vhdl-modified-file-list nil
12867 "List of modified files to be rescanned for hierarchy updating.")
12869 (defvar vhdl-speedbar-hierarchy-depth 0
12870 "Depth of instantiation hierarchy to display.")
12872 (defvar vhdl-speedbar-show-projects nil
12873 "Non-nil means project hierarchy is displayed in speedbar, directory
12874 hierarchy otherwise.")
12876 (defun vhdl-get-end-of-unit ()
12877 "Return position of end of current unit."
12878 (let ((pos (point)))
12880 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
12882 (goto-char (match-beginning 0))
12883 (vhdl-backward-syntactic-ws)
12884 (and (/= (preceding-char) ?\;) (not (bobp))))))
12885 (re-search-backward "^[ \t]*end\\>" pos 1)
12888 (defun vhdl-match-string-downcase (num &optional string)
12889 "Like `match-string-no-properties' with down-casing."
12890 (let ((match (match-string-no-properties num string)))
12891 (and match (downcase match))))
12894 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12897 (defun vhdl-scan-context-clause ()
12898 "Scan the context clause that preceeds a design unit."
12901 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
12902 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
12903 (equal "USE" (upcase (match-string 1))))
12904 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
12905 (setq lib-alist (cons (cons (match-string-no-properties 1)
12906 (vhdl-match-string-downcase 2))
12910 (defun vhdl-scan-directory-contents (name &optional project update num-string
12912 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
12913 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
12914 ; (unless (file-directory-p (match-string 1 name))
12915 ; (message "No such directory: \"%s\"" (match-string 1 name)))
12916 (let* ((dir-name (match-string 1 name))
12917 (file-pattern (match-string 2 name))
12918 (is-directory (= 0 (length file-pattern)))
12923 (vhdl-get-source-files t dir-name)
12924 (vhdl-directory-files
12925 dir-name t (wildcard-to-regexp file-pattern)))))
12926 (key (or project dir-name))
12927 (file-exclude-regexp
12928 (or (nth 3 (aget vhdl-project-alist project)) ""))
12929 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
12930 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
12931 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
12932 ent-alist conf-alist pack-alist ent-inst-list file-alist
12933 tmp-list tmp-entry no-files files-exist big-files)
12934 (when (or project update)
12935 (setq ent-alist (aget vhdl-entity-alist key t)
12936 conf-alist (aget vhdl-config-alist key t)
12937 pack-alist (aget vhdl-package-alist key t)
12938 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
12939 file-alist (aget vhdl-file-alist key t)))
12940 (when (and (not is-directory) (null file-list))
12941 (message "No such file: \"%s\"" name))
12942 (setq files-exist file-list)
12944 (setq no-files (length file-list))
12945 (message "Scanning %s %s\"%s\"..."
12946 (if is-directory "directory" "files") (or num-string "") name)
12948 (unless (equal file-exclude-regexp "")
12949 (let ((case-fold-search nil)
12952 (unless (string-match file-exclude-regexp (car file-list))
12953 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
12954 (setq file-list (cdr file-list)))
12955 (setq file-list (nreverse file-tmp-list))))
12956 ;; do for all files
12958 (unless noninteractive
12959 (message "Scanning %s %s\"%s\"... (%2d%s)"
12960 (if is-directory "directory" "files")
12961 (or num-string "") name
12962 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
12963 (let ((file-name (abbreviate-file-name (car file-list)))
12964 ent-list arch-list arch-ent-list conf-list
12965 pack-list pack-body-list inst-list inst-ent-list)
12969 (vhdl-prepare-search-2
12971 ;; scan for design units
12972 (if (and limit-design-file-size
12973 (< limit-design-file-size (buffer-size)))
12974 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
12975 (setq big-files t))
12976 ;; scan for entities
12977 (goto-char (point-min))
12978 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12979 (let* ((ent-name (match-string-no-properties 1))
12980 (ent-key (downcase ent-name))
12981 (ent-entry (aget ent-alist ent-key t))
12982 (arch-alist (nth 3 ent-entry))
12983 (lib-alist (vhdl-scan-context-clause)))
12984 (if (nth 1 ent-entry)
12985 (vhdl-warning-when-idle
12986 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12987 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
12988 file-name (vhdl-current-line))
12989 (setq ent-list (cons ent-key ent-list))
12990 (aput 'ent-alist ent-key
12991 (list ent-name file-name (vhdl-current-line)
12992 arch-alist lib-alist)))))
12993 ;; scan for architectures
12994 (goto-char (point-min))
12995 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12996 (let* ((arch-name (match-string-no-properties 1))
12997 (arch-key (downcase arch-name))
12998 (ent-name (match-string-no-properties 2))
12999 (ent-key (downcase ent-name))
13000 (ent-entry (aget ent-alist ent-key t))
13001 (arch-alist (nth 3 ent-entry))
13002 (arch-entry (aget arch-alist arch-key t))
13003 (lib-arch-alist (vhdl-scan-context-clause)))
13005 (vhdl-warning-when-idle
13006 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13007 arch-name ent-name (nth 1 arch-entry)
13008 (nth 2 arch-entry) file-name (vhdl-current-line))
13009 (setq arch-list (cons arch-key arch-list)
13010 arch-ent-list (cons ent-key arch-ent-list))
13011 (aput 'arch-alist arch-key
13012 (list arch-name file-name (vhdl-current-line) nil
13014 (aput 'ent-alist ent-key
13015 (list (or (nth 0 ent-entry) ent-name)
13016 (nth 1 ent-entry) (nth 2 ent-entry)
13017 (vhdl-sort-alist arch-alist)
13018 (nth 4 ent-entry))))))
13019 ;; scan for configurations
13020 (goto-char (point-min))
13021 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13022 (let* ((conf-name (match-string-no-properties 1))
13023 (conf-key (downcase conf-name))
13024 (conf-entry (aget conf-alist conf-key t))
13025 (ent-name (match-string-no-properties 2))
13026 (ent-key (downcase ent-name))
13027 (lib-alist (vhdl-scan-context-clause))
13028 (conf-line (vhdl-current-line))
13029 (end-of-unit (vhdl-get-end-of-unit))
13030 arch-key comp-conf-list inst-key-list
13031 inst-comp-key inst-ent-key inst-arch-key
13032 inst-conf-key inst-lib-key)
13033 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13034 (setq arch-key (vhdl-match-string-downcase 1)))
13036 (vhdl-warning-when-idle
13037 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13038 conf-name ent-name (nth 1 conf-entry)
13039 (nth 2 conf-entry) file-name conf-line)
13040 (setq conf-list (cons conf-key conf-list))
13041 ;; scan for subconfigurations and subentities
13042 (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)
13043 (setq inst-comp-key (vhdl-match-string-downcase 3)
13044 inst-key-list (split-string
13045 (vhdl-match-string-downcase 1)
13046 "[ \t\n]*,[ \t\n]*"))
13047 (vhdl-forward-syntactic-ws)
13048 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13050 inst-lib-key (vhdl-match-string-downcase 3)
13051 inst-ent-key (and (match-string 2)
13052 (vhdl-match-string-downcase 4))
13053 inst-arch-key (and (match-string 2)
13054 (vhdl-match-string-downcase 6))
13055 inst-conf-key (and (not (match-string 2))
13056 (vhdl-match-string-downcase 4)))
13057 (while inst-key-list
13058 (setq comp-conf-list
13059 (cons (list (car inst-key-list)
13060 inst-comp-key inst-ent-key
13061 inst-arch-key inst-conf-key
13064 (setq inst-key-list (cdr inst-key-list)))))
13065 (aput 'conf-alist conf-key
13066 (list conf-name file-name conf-line ent-key
13067 arch-key comp-conf-list lib-alist)))))
13068 ;; scan for packages
13069 (goto-char (point-min))
13070 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13071 (let* ((pack-name (match-string-no-properties 2))
13072 (pack-key (downcase pack-name))
13073 (is-body (match-string-no-properties 1))
13074 (pack-entry (aget pack-alist pack-key t))
13075 (pack-line (vhdl-current-line))
13076 (end-of-unit (vhdl-get-end-of-unit))
13077 comp-name func-name comp-alist func-alist lib-alist)
13078 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13079 (vhdl-warning-when-idle
13080 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13081 (if is-body " body" "") pack-name
13082 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13083 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13084 file-name (vhdl-current-line))
13085 ;; scan for context clauses
13086 (setq lib-alist (vhdl-scan-context-clause))
13087 ;; scan for component and subprogram declarations/bodies
13088 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13089 (if (equal (upcase (match-string 1)) "COMPONENT")
13090 (setq comp-name (match-string-no-properties 2)
13092 (cons (list (downcase comp-name) comp-name
13093 file-name (vhdl-current-line))
13095 (setq func-name (match-string-no-properties 2)
13097 (cons (list (downcase func-name) func-name
13098 file-name (vhdl-current-line))
13100 (setq func-alist (nreverse func-alist))
13101 (setq comp-alist (nreverse comp-alist))
13103 (setq pack-body-list (cons pack-key pack-body-list))
13104 (setq pack-list (cons pack-key pack-list)))
13106 'pack-alist pack-key
13108 (list (or (nth 0 pack-entry) pack-name)
13109 (nth 1 pack-entry) (nth 2 pack-entry)
13110 (nth 3 pack-entry) (nth 4 pack-entry)
13112 file-name pack-line func-alist lib-alist)
13113 (list pack-name file-name pack-line
13114 comp-alist func-alist lib-alist
13115 (nth 6 pack-entry) (nth 7 pack-entry)
13116 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13117 ;; scan for hierarchy
13118 (if (and limit-hier-file-size
13119 (< limit-hier-file-size (buffer-size)))
13120 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13121 (setq big-files t))
13122 ;; scan for architectures
13123 (goto-char (point-min))
13124 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13125 (let* ((ent-name (match-string-no-properties 2))
13126 (ent-key (downcase ent-name))
13127 (arch-name (match-string-no-properties 1))
13128 (arch-key (downcase arch-name))
13129 (ent-entry (aget ent-alist ent-key t))
13130 (arch-alist (nth 3 ent-entry))
13131 (arch-entry (aget arch-alist arch-key t))
13132 (beg-of-unit (point))
13133 (end-of-unit (vhdl-get-end-of-unit))
13136 ;; scan for contained instantiations
13137 (while (and (re-search-forward
13138 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13139 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13140 "component[ \t\n]+\\(\\w+\\)\\|"
13141 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\)") end-of-unit t)
13142 (or (not limit-hier-inst-no)
13143 (<= (setq inst-no (1+ inst-no))
13144 limit-hier-inst-no)))
13145 (let* ((inst-name (match-string-no-properties 1))
13146 (inst-key (downcase inst-name))
13148 (or (match-string-no-properties 3)
13149 (match-string-no-properties 6)))
13151 (or (and (match-string 8)
13152 (vhdl-match-string-downcase 11))
13153 (and inst-comp-name
13154 (downcase inst-comp-name))))
13155 (inst-arch-key (vhdl-match-string-downcase 13))
13157 (and (not (match-string 8))
13158 (vhdl-match-string-downcase 11)))
13159 (inst-lib-key (vhdl-match-string-downcase 10)))
13160 (goto-char (match-end 1))
13161 (setq inst-list (cons inst-key inst-list)
13162 inst-ent-list (cons inst-ent-key inst-ent-list))
13166 (list (list inst-key inst-name file-name
13167 (vhdl-current-line) inst-comp-name
13168 inst-ent-key inst-arch-key
13169 inst-conf-key inst-lib-key))))))
13170 ;; scan for contained configuration specifications
13171 (goto-char beg-of-unit)
13172 (while (re-search-forward
13173 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13174 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13175 (let* ((inst-comp-name (match-string-no-properties 3))
13177 (and (match-string 6)
13178 (vhdl-match-string-downcase 9)))
13179 (inst-arch-key (vhdl-match-string-downcase 11))
13181 (and (not (match-string 6))
13182 (vhdl-match-string-downcase 9)))
13183 (inst-lib-key (vhdl-match-string-downcase 8))
13185 (split-string (vhdl-match-string-downcase 1)
13186 "[ \t\n]*,[ \t\n]*"))
13187 (tmp-inst-alist inst-alist)
13189 (while tmp-inst-alist
13190 (when (and (or (equal "all" (car inst-key-list))
13191 (member (nth 0 (car tmp-inst-alist))
13195 (or (nth 4 (car tmp-inst-alist)) ""))
13196 (downcase inst-comp-name)))
13197 (setq inst-entry (car tmp-inst-alist))
13198 (setq inst-ent-list
13199 (cons (or inst-ent-key (nth 5 inst-entry))
13201 (nth 5 inst-entry) inst-ent-list)))
13203 (list (nth 0 inst-entry) (nth 1 inst-entry)
13204 (nth 2 inst-entry) (nth 3 inst-entry)
13206 (or inst-ent-key (nth 5 inst-entry))
13207 (or inst-arch-key (nth 6 inst-entry))
13208 inst-conf-key inst-lib-key))
13209 (setcar tmp-inst-alist inst-entry))
13210 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13212 (aput 'arch-alist arch-key
13213 (list (nth 0 arch-entry) (nth 1 arch-entry)
13214 (nth 2 arch-entry) inst-alist
13215 (nth 4 arch-entry)))
13216 (aput 'ent-alist ent-key
13217 (list (nth 0 ent-entry) (nth 1 ent-entry)
13218 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13219 (nth 4 ent-entry)))
13220 (when (and limit-hier-inst-no
13221 (> inst-no limit-hier-inst-no))
13222 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13223 (setq big-files t))
13224 (goto-char end-of-unit))))
13225 ;; remember design units for this file
13226 (aput 'file-alist file-name
13227 (list ent-list arch-list arch-ent-list conf-list
13228 pack-list pack-body-list inst-list inst-ent-list))
13229 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13230 (setq file-list (cdr file-list))))
13231 (when (or (and (not project) files-exist)
13232 (and project (not non-final)))
13233 ;; consistency checks:
13234 ;; check whether each architecture has a corresponding entity
13235 (setq tmp-list ent-alist)
13237 (when (null (nth 2 (car tmp-list)))
13238 (setq tmp-entry (car (nth 4 (car tmp-list))))
13239 (vhdl-warning-when-idle
13240 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13241 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13242 (nth 3 tmp-entry)))
13243 (setq tmp-list (cdr tmp-list)))
13244 ;; check whether configuration has a corresponding entity/architecture
13245 (setq tmp-list conf-alist)
13247 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13248 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13249 (setq tmp-entry (car tmp-list))
13250 (vhdl-warning-when-idle
13251 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13252 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13253 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13254 (setq tmp-entry (car tmp-list))
13255 (vhdl-warning-when-idle
13256 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13257 (nth 1 tmp-entry) (nth 4 tmp-entry)
13258 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13259 (setq tmp-list (cdr tmp-list)))
13260 ;; check whether each package body has a package declaration
13261 (setq tmp-list pack-alist)
13263 (when (null (nth 2 (car tmp-list)))
13264 (setq tmp-entry (car tmp-list))
13265 (vhdl-warning-when-idle
13266 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13267 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13268 (setq tmp-list (cdr tmp-list)))
13270 (setq ent-alist (vhdl-sort-alist ent-alist))
13271 (setq conf-alist (vhdl-sort-alist conf-alist))
13272 (setq pack-alist (vhdl-sort-alist pack-alist))
13273 ;; remember updated directory/project
13274 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13275 ;; clear directory alists
13277 (adelete 'vhdl-entity-alist key)
13278 (adelete 'vhdl-config-alist key)
13279 (adelete 'vhdl-package-alist key)
13280 (adelete 'vhdl-ent-inst-alist key)
13281 (adelete 'vhdl-file-alist key))
13282 ;; put directory contents into cache
13283 (aput 'vhdl-entity-alist key ent-alist)
13284 (aput 'vhdl-config-alist key conf-alist)
13285 (aput 'vhdl-package-alist key pack-alist)
13286 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13287 (aput 'vhdl-file-alist key file-alist)
13289 (message "Scanning %s %s\"%s\"...done"
13290 (if is-directory "directory" "files") (or num-string "") name)
13291 (unless project (message "Scanning directory...done"))
13293 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13294 ;; save cache when scanned non-interactively
13295 (when (or (not project) (not non-final))
13296 (when (and noninteractive vhdl-speedbar-save-cache)
13297 (vhdl-save-cache key)))
13300 (defun vhdl-scan-project-contents (project)
13301 "Scan the contents of all VHDL files found in the directories and files
13303 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13304 (default-dir (vhdl-resolve-env-variable
13305 (nth 1 (aget vhdl-project-alist project))))
13306 (file-exclude-regexp
13307 (or (nth 3 (aget vhdl-project-alist project)) ""))
13308 dir-list-tmp dir dir-name num-dir act-dir recursive)
13309 ;; clear project alists
13310 (adelete 'vhdl-entity-alist project)
13311 (adelete 'vhdl-config-alist project)
13312 (adelete 'vhdl-package-alist project)
13313 (adelete 'vhdl-ent-inst-alist project)
13314 (adelete 'vhdl-file-alist project)
13315 ;; expand directory names by default-directory
13316 (message "Collecting source files...")
13318 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13319 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13320 (setq recursive (match-string 1 dir)
13321 dir-name (match-string 3 dir))
13323 (cons (concat recursive
13324 (if (file-name-absolute-p dir-name) "" default-dir)
13327 (setq dir-list (cdr dir-list)))
13328 ;; resolve path wildcards
13329 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13330 ;; expand directories
13331 (while dir-list-tmp
13332 (setq dir (car dir-list-tmp))
13333 ;; get subdirectories
13334 (if (string-match "-r \\(.*[/\\]\\)" dir)
13335 (setq dir-list (append dir-list (vhdl-get-subdirs
13336 (match-string 1 dir))))
13337 (setq dir-list (append dir-list (list dir))))
13338 (setq dir-list-tmp (cdr dir-list-tmp)))
13340 (unless (equal file-exclude-regexp "")
13341 (let ((case-fold-search nil))
13343 (unless (string-match file-exclude-regexp (car dir-list))
13344 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13345 (setq dir-list (cdr dir-list)))
13346 (setq dir-list (nreverse dir-list-tmp))))
13347 (message "Collecting source files...done")
13348 ;; scan for design units for each directory in DIR-LIST
13349 (setq dir-list-tmp nil
13350 num-dir (length dir-list)
13353 (setq dir-name (abbreviate-file-name
13354 (expand-file-name (car dir-list))))
13355 (vhdl-scan-directory-contents dir-name project nil
13356 (format "(%s/%s) " act-dir num-dir)
13358 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
13359 (setq dir-list (cdr dir-list)
13360 act-dir (1+ act-dir)))
13361 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13362 (message "Scanning project \"%s\"...done" project)))
13364 (defun vhdl-update-file-contents (file-name)
13365 "Update hierarchy information by contents of current buffer."
13366 (setq file-name (abbreviate-file-name file-name))
13367 (let* ((dir-name (file-name-directory file-name))
13368 (directory-alist vhdl-directory-alist)
13370 (while directory-alist
13371 (when (member dir-name (nth 1 (car directory-alist)))
13372 (let* ((vhdl-project (nth 0 (car directory-alist)))
13373 (project (vhdl-project-p))
13374 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13375 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13376 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13377 (ent-inst-list (car (aget vhdl-ent-inst-alist
13378 (or project dir-name) t)))
13379 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13380 (file-entry (aget file-alist file-name t))
13381 (ent-list (nth 0 file-entry))
13382 (arch-list (nth 1 file-entry))
13383 (arch-ent-list (nth 2 file-entry))
13384 (conf-list (nth 3 file-entry))
13385 (pack-list (nth 4 file-entry))
13386 (pack-body-list (nth 5 file-entry))
13387 (inst-ent-list (nth 7 file-entry))
13388 (cache-key (or project dir-name))
13389 arch-alist key ent-key entry)
13390 ;; delete design units previously contained in this file:
13393 (setq key (car ent-list)
13394 entry (aget ent-alist key t))
13395 (when (equal file-name (nth 1 entry))
13397 (aput 'ent-alist key
13398 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13399 (adelete 'ent-alist key)))
13400 (setq ent-list (cdr ent-list)))
13403 (setq key (car arch-list)
13404 ent-key (car arch-ent-list)
13405 entry (aget ent-alist ent-key t)
13406 arch-alist (nth 3 entry))
13407 (when (equal file-name (nth 1 (aget arch-alist key t)))
13408 (adelete 'arch-alist key)
13409 (if (or (nth 1 entry) arch-alist)
13410 (aput 'ent-alist ent-key
13411 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13412 arch-alist (nth 4 entry)))
13413 (adelete 'ent-alist ent-key)))
13414 (setq arch-list (cdr arch-list)
13415 arch-ent-list (cdr arch-ent-list)))
13418 (setq key (car conf-list))
13419 (when (equal file-name (nth 1 (aget conf-alist key t)))
13420 (adelete 'conf-alist key))
13421 (setq conf-list (cdr conf-list)))
13422 ;; package declarations
13424 (setq key (car pack-list)
13425 entry (aget pack-alist key t))
13426 (when (equal file-name (nth 1 entry))
13428 (aput 'pack-alist key
13429 (list (nth 0 entry) nil nil nil nil nil
13430 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13432 (adelete 'pack-alist key)))
13433 (setq pack-list (cdr pack-list)))
13435 (while pack-body-list
13436 (setq key (car pack-body-list)
13437 entry (aget pack-alist key t))
13438 (when (equal file-name (nth 6 entry))
13440 (aput 'pack-alist key
13441 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13442 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13444 (adelete 'pack-alist key)))
13445 (setq pack-body-list (cdr pack-body-list)))
13446 ;; instantiated entities
13447 (while inst-ent-list
13448 (setq ent-inst-list
13449 (vhdl-delete (car inst-ent-list) ent-inst-list))
13450 (setq inst-ent-list (cdr inst-ent-list)))
13452 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13453 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13454 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13455 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13457 (vhdl-scan-directory-contents file-name project t)
13458 (when (or (and vhdl-speedbar-show-projects project)
13459 (and (not vhdl-speedbar-show-projects) (not project)))
13460 (vhdl-speedbar-refresh project))
13462 (setq directory-alist (cdr directory-alist)))
13465 (defun vhdl-update-hierarchy ()
13466 "Update directory and hierarchy information in speedbar."
13467 (let ((file-list (reverse vhdl-modified-file-list))
13469 (when (and vhdl-speedbar-update-on-saving file-list)
13472 (or (vhdl-update-file-contents (car file-list))
13474 (setq file-list (cdr file-list)))
13475 (setq vhdl-modified-file-list nil)
13476 (when updated (message "Updating hierarchy...done")))))
13478 ;; structure (parenthesised expression means list of such entries)
13479 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13480 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13481 ;; comp-lib-name level)
13482 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13483 conf-inst-alist level indent
13484 &optional include-top ent-hier)
13485 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13487 (let* ((ent-entry (aget ent-alist ent-key t))
13488 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13489 (cdar (last (nth 3 ent-entry)))))
13490 (inst-alist (nth 3 arch-entry))
13491 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13492 hier-list subcomp-list tmp-list inst-key inst-comp-name
13493 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
13494 (when (= level 0) (message "Extract design hierarchy..."))
13496 (setq level (1+ level)))
13497 (when (member ent-key ent-hier)
13498 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13499 ;; check configured architecture (already checked during scanning)
13500 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13501 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13502 ;; process all instances
13504 (setq inst-entry (car inst-alist)
13505 inst-key (nth 0 inst-entry)
13506 inst-comp-name (nth 4 inst-entry)
13507 inst-conf-key (nth 7 inst-entry))
13508 ;; search entry in configuration's instantiations list
13509 (setq tmp-list conf-inst-alist)
13510 (while (and tmp-list
13511 (not (and (member (nth 0 (car tmp-list))
13512 (list "all" inst-key))
13513 (equal (nth 1 (car tmp-list))
13514 (downcase (or inst-comp-name ""))))))
13515 (setq tmp-list (cdr tmp-list)))
13516 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13517 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13518 (when (and inst-conf-key (not inst-conf-entry))
13519 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13520 ;; determine entity
13522 (or (nth 2 (car tmp-list)) ; from configuration
13523 (nth 3 inst-conf-entry) ; from subconfiguration
13524 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13525 ; from configuration spec.
13526 (nth 5 inst-entry))) ; from direct instantiation
13527 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13528 ;; determine architecture
13529 (setq inst-arch-key
13530 (or (nth 3 (car tmp-list)) ; from configuration
13531 (nth 4 inst-conf-entry) ; from subconfiguration
13532 (nth 6 inst-entry) ; from direct instantiation
13533 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13534 ; from configuration spec.
13535 (caar (nth 3 inst-ent-entry)))) ; random (simplified MRA)
13536 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13539 (or (nth 5 (car tmp-list)) ; from configuration
13540 (nth 8 inst-entry))) ; from direct instantiation
13541 ;; gather information for this instance
13543 (list (nth 1 inst-entry)
13544 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13545 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13546 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13547 (or (nth 0 inst-arch-entry) inst-arch-key)
13548 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13549 (or (nth 0 inst-conf-entry) inst-conf-key)
13550 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13551 inst-lib-key level))
13552 ;; get subcomponent hierarchy
13553 (setq subcomp-list (vhdl-get-hierarchy
13554 ent-alist conf-alist
13555 inst-ent-key inst-arch-key inst-conf-key
13556 (nth 5 inst-conf-entry)
13557 (1+ level) indent nil (cons ent-key ent-hier)))
13559 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13560 (setq inst-alist (cdr inst-alist)))
13563 (cons (list nil nil (nth 0 ent-entry)
13564 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13566 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13570 (when (or (= level 0) (and include-top (= level 1))) (message ""))
13573 (defun vhdl-get-instantiations (ent-key indent)
13574 "Get all instantiations of entity ENT-KEY."
13575 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
13576 arch-alist inst-alist ent-inst-list
13577 ent-entry arch-entry inst-entry)
13579 (setq ent-entry (car ent-alist))
13580 (setq arch-alist (nth 4 ent-entry))
13582 (setq arch-entry (car arch-alist))
13583 (setq inst-alist (nth 4 arch-entry))
13585 (setq inst-entry (car inst-alist))
13586 (when (equal ent-key (nth 5 inst-entry))
13587 (setq ent-inst-list
13588 (cons (list (nth 1 inst-entry)
13589 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13591 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13593 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13595 (setq inst-alist (cdr inst-alist)))
13596 (setq arch-alist (cdr arch-alist)))
13597 (setq ent-alist (cdr ent-alist)))
13598 (nreverse ent-inst-list)))
13600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13603 (defun vhdl-save-caches ()
13604 "Save all updated hierarchy caches to file."
13606 (condition-case nil
13607 (when vhdl-speedbar-save-cache
13608 ;; update hierarchy
13609 (vhdl-update-hierarchy)
13610 (let ((project-list vhdl-updated-project-list))
13611 (message "Saving hierarchy caches...")
13612 ;; write updated project caches
13613 (while project-list
13614 (vhdl-save-cache (car project-list))
13615 (setq project-list (cdr project-list)))
13616 (message "Saving hierarchy caches...done")))
13617 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13620 (defun vhdl-save-cache (key)
13621 "Save current hierarchy cache to file."
13622 (let* ((orig-buffer (current-buffer))
13624 (project (vhdl-project-p))
13625 (default-directory key)
13626 (directory (abbreviate-file-name (vhdl-default-directory)))
13627 (file-name (vhdl-resolve-env-variable
13628 (vhdl-replace-string
13629 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13631 (subst-char-in-string ? ?_ (or project "dir"))
13632 " " (user-login-name)))))
13633 (file-dir-name (expand-file-name file-name directory))
13634 (cache-key (or project directory))
13635 (key (if project "project" "directory")))
13636 (unless (file-exists-p (file-name-directory file-dir-name))
13637 (make-directory (file-name-directory file-dir-name) t))
13638 (if (not (file-writable-p file-dir-name))
13639 (progn (vhdl-warning (format "File not writable: \"%s\""
13640 (abbreviate-file-name file-dir-name)))
13642 (message "Saving cache: \"%s\"" file-dir-name)
13643 (set-buffer (find-file-noselect file-dir-name t t))
13645 (insert ";; -*- Emacs-Lisp -*-\n\n"
13646 ";;; " (file-name-nondirectory file-name)
13647 " - design hierarchy cache file for Emacs VHDL Mode "
13649 (insert "\n;; " (if project "Project " "Directory") " : ")
13650 (if project (insert project) (prin1 directory (current-buffer)))
13651 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13652 (user-login-name) "\n\n"
13653 "\n;; version number\n"
13654 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13655 "\n;; " (if project "project" "directory") " name"
13656 "\n(setq " key " ")
13657 (prin1 (or project directory) (current-buffer))
13659 (when (member 'hierarchy vhdl-speedbar-save-cache)
13660 (insert "\n;; entity and architecture cache\n"
13661 "(aput 'vhdl-entity-alist " key " '")
13662 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13663 (insert ")\n\n;; configuration cache\n"
13664 "(aput 'vhdl-config-alist " key " '")
13665 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13666 (insert ")\n\n;; package cache\n"
13667 "(aput 'vhdl-package-alist " key " '")
13668 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13669 (insert ")\n\n;; instantiated entities cache\n"
13670 "(aput 'vhdl-ent-inst-alist " key " '")
13671 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13672 (insert ")\n\n;; design units per file cache\n"
13673 "(aput 'vhdl-file-alist " key " '")
13674 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13676 (insert ")\n\n;; source directories in project cache\n"
13677 "(aput 'vhdl-directory-alist " key " '")
13678 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13680 (when (member 'display vhdl-speedbar-save-cache)
13681 (insert "\n;; shown design units cache\n"
13682 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13683 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13686 (setq vhdl-updated-project-list
13687 (delete cache-key vhdl-updated-project-list))
13689 (kill-buffer (current-buffer))
13690 (set-buffer orig-buffer))))
13692 (defun vhdl-load-cache (key)
13693 "Load hierarchy cache information from file."
13694 (let* ((vhdl-project key)
13695 (default-directory key)
13696 (directory (vhdl-default-directory))
13697 (file-name (vhdl-resolve-env-variable
13698 (vhdl-replace-string
13699 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13701 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13702 " " (user-login-name)))))
13703 (file-dir-name (expand-file-name file-name directory))
13704 vhdl-cache-version)
13705 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13706 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13707 (when (file-exists-p file-dir-name)
13709 (progn (load-file file-dir-name)
13710 (string< (mapconcat
13711 (lambda (a) (format "%3d" (string-to-number a)))
13712 (split-string "3.31.14" "\\.") "")
13714 (lambda (a) (format "%3d" (string-to-number a)))
13715 (split-string vhdl-cache-version "\\.") "")))
13716 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13719 (defun vhdl-require-hierarchy-info ()
13720 "Make sure that hierarchy information is available. Load cache or scan files
13722 (if (vhdl-project-p)
13723 (unless (or (assoc vhdl-project vhdl-file-alist)
13724 (vhdl-load-cache vhdl-project))
13725 (vhdl-scan-project-contents vhdl-project))
13726 (let ((directory (abbreviate-file-name default-directory)))
13727 (unless (or (assoc directory vhdl-file-alist)
13728 (vhdl-load-cache directory))
13729 (vhdl-scan-directory-contents directory)))))
13731 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13732 ;; Add hierarchy browser functionality to speedbar
13734 (defvar vhdl-speedbar-key-map nil
13735 "Keymap used when in the VHDL hierarchy browser mode.")
13737 (defvar vhdl-speedbar-menu-items nil
13738 "Additional menu-items to add to speedbar frame.")
13740 (defun vhdl-speedbar-initialize ()
13741 "Initialize speedbar."
13742 ;; general settings
13743 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13744 ;; VHDL file extensions (extracted from `auto-mode-alist')
13745 (let ((mode-alist auto-mode-alist))
13747 (when (eq (cdar mode-alist) 'vhdl-mode)
13748 (speedbar-add-supported-extension (caar mode-alist)))
13749 (setq mode-alist (cdr mode-alist))))
13750 ;; hierarchy browser settings
13751 (when (boundp 'speedbar-mode-functions-list)
13752 ;; special functions
13753 (speedbar-add-mode-functions-list
13755 (speedbar-item-info . vhdl-speedbar-item-info)
13756 (speedbar-line-path . speedbar-files-line-path)))
13757 (speedbar-add-mode-functions-list
13759 (speedbar-item-info . vhdl-speedbar-item-info)
13760 (speedbar-line-path . vhdl-speedbar-line-project)))
13762 (unless vhdl-speedbar-key-map
13763 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13764 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13765 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13766 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
13767 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13768 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13769 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13770 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13771 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13772 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13773 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13774 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13777 (define-key vhdl-speedbar-key-map (int-to-string key)
13778 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13779 (setq key (1+ key)))))
13780 (define-key speedbar-key-map "h"
13781 (lambda () (interactive)
13782 (speedbar-change-initial-expansion-list "vhdl directory")))
13783 (define-key speedbar-key-map "H"
13784 (lambda () (interactive)
13785 (speedbar-change-initial-expansion-list "vhdl project")))
13787 (unless vhdl-speedbar-menu-items
13789 vhdl-speedbar-menu-items
13790 `(["Edit" speedbar-edit-line t]
13791 ["Expand" speedbar-expand-line
13792 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13793 ["Contract" vhdl-speedbar-contract-level t]
13794 ["Expand All" vhdl-speedbar-expand-all t]
13795 ["Contract All" vhdl-speedbar-contract-all t]
13796 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13799 (cons `[,(if (= key 0) "All" (int-to-string key))
13800 (vhdl-speedbar-set-depth ,key)
13802 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13803 :keys ,(int-to-string key)]
13805 (setq key (1+ key)))
13806 (nreverse menu-list))
13808 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13809 (or (vhdl-speedbar-check-unit 'entity)
13810 (vhdl-speedbar-check-unit 'subprogram))]
13811 ["Place Component" vhdl-speedbar-place-component
13812 (vhdl-speedbar-check-unit 'entity)]
13813 ["Make" vhdl-speedbar-make-design
13814 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
13815 ["Generate Makefile" vhdl-speedbar-generate-makefile
13816 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
13817 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
13818 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13819 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
13820 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
13821 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13822 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
13823 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
13825 (speedbar-add-expansion-list
13826 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13827 vhdl-speedbar-display-directory))
13828 (speedbar-add-expansion-list
13829 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13830 vhdl-speedbar-display-projects))
13831 (setq speedbar-stealthy-function-list
13833 '(("vhdl directory" vhdl-speedbar-update-current-unit)
13834 ("vhdl project" vhdl-speedbar-update-current-project
13835 vhdl-speedbar-update-current-unit)
13836 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
13837 ; (speedbar-extension-list-to-regex
13838 ; speedbar-ignored-path-expressions))))
13840 speedbar-stealthy-function-list))
13841 (when (eq vhdl-speedbar-display-mode 'directory)
13842 (setq speedbar-initial-expansion-list-name "vhdl directory"))
13843 (when (eq vhdl-speedbar-display-mode 'project)
13844 (setq speedbar-initial-expansion-list-name "vhdl project"))
13845 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
13847 (defun vhdl-speedbar (&optional arg)
13848 "Open/close speedbar."
13850 (if (not (fboundp 'speedbar))
13851 (error "WARNING: Speedbar is not available or not installed")
13853 (speedbar-frame-mode arg)
13854 (error (error "WARNING: An error occurred while opening speedbar")))))
13856 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13857 ;; Display functions
13859 (defvar vhdl-speedbar-last-selected-project nil
13860 "Name of last selected project.")
13862 ;; macros must be defined in the file they are used (copied from `speedbar.el')
13863 (defmacro speedbar-with-writable (&rest forms)
13864 "Allow the buffer to be writable and evaluate FORMS."
13865 (list 'let '((inhibit-read-only t))
13866 (cons 'progn forms)))
13867 (put 'speedbar-with-writable 'lisp-indent-function 0)
13869 (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
13870 "Display directory and hierarchy information in speedbar."
13871 (setq vhdl-speedbar-show-projects nil)
13872 (setq speedbar-ignored-path-regexp
13873 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
13874 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
13875 (setq speedbar-last-selected-file nil)
13876 (speedbar-with-writable
13877 (condition-case nil
13879 ;; insert directory path
13880 (speedbar-directory-buttons directory depth)
13881 ;; insert subdirectories
13882 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
13883 ;; scan and insert hierarchy of current directory
13884 (vhdl-speedbar-insert-dir-hierarchy directory depth
13885 speedbar-power-click)
13886 ;; expand subdirectories
13887 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
13888 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
13890 (defun vhdl-speedbar-display-projects (project depth &optional rescan)
13891 "Display projects and hierarchy information in speedbar."
13892 (setq vhdl-speedbar-show-projects t)
13893 (setq speedbar-ignored-path-regexp ".")
13894 (setq speedbar-last-selected-file nil)
13895 (setq vhdl-speedbar-last-selected-project nil)
13896 (speedbar-with-writable
13897 (condition-case nil
13899 (vhdl-speedbar-insert-projects)
13900 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
13901 (setq speedbar-full-text-cache nil)) ; prevent caching
13903 (defun vhdl-speedbar-insert-projects ()
13904 "Insert all projects in speedbar."
13905 (vhdl-speedbar-make-title-line "Projects:")
13906 (let ((project-alist (if vhdl-project-sort
13907 (vhdl-sort-alist (copy-alist vhdl-project-alist))
13908 vhdl-project-alist))
13909 (vhdl-speedbar-update-current-unit nil))
13911 (while project-alist
13912 (speedbar-make-tag-line
13913 'angle ?+ 'vhdl-speedbar-expand-project
13914 (caar project-alist) (caar project-alist)
13915 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
13916 (setq project-alist (cdr project-alist)))
13917 (setq project-alist vhdl-project-alist)
13919 (while project-alist
13920 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
13921 (goto-char (point-min))
13922 (when (re-search-forward
13923 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
13924 (goto-char (match-end 1))
13925 (speedbar-do-function-pointer)))
13926 (setq project-alist (cdr project-alist))))
13927 ; (vhdl-speedbar-update-current-project)
13928 ; (vhdl-speedbar-update-current-unit nil t)
13931 (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
13932 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
13933 otherwise use cached data."
13934 (when (or rescan (and (not (assoc project vhdl-file-alist))
13935 (not (vhdl-load-cache project))))
13936 (vhdl-scan-project-contents project))
13937 ;; insert design hierarchy
13938 (vhdl-speedbar-insert-hierarchy
13939 (aget vhdl-entity-alist project t)
13940 (aget vhdl-config-alist project t)
13941 (aget vhdl-package-alist project t)
13942 (car (aget vhdl-ent-inst-alist project t)) indent)
13943 (insert (int-to-string indent) ":\n")
13944 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
13945 (put-text-property (1- (point)) (point) 'invisible nil)
13946 ;; expand design units
13947 (vhdl-speedbar-expand-units project))
13949 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
13950 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
13951 otherwise use cached data."
13952 (when (or rescan (and (not (assoc directory vhdl-file-alist))
13953 (not (vhdl-load-cache directory))))
13954 (vhdl-scan-directory-contents directory))
13955 ;; insert design hierarchy
13956 (vhdl-speedbar-insert-hierarchy
13957 (aget vhdl-entity-alist directory t)
13958 (aget vhdl-config-alist directory t)
13959 (aget vhdl-package-alist directory t)
13960 (car (aget vhdl-ent-inst-alist directory t)) depth)
13961 ;; expand design units
13962 (vhdl-speedbar-expand-units directory)
13963 (aput 'vhdl-directory-alist directory (list (list directory))))
13965 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
13966 ent-inst-list depth)
13967 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
13968 (if (not (or ent-alist conf-alist pack-alist))
13969 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
13970 (let (ent-entry conf-entry pack-entry)
13972 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
13974 (setq ent-entry (car ent-alist))
13975 (speedbar-make-tag-line
13976 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
13977 (nth 1 ent-entry) 'vhdl-speedbar-find-file
13978 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13979 'vhdl-speedbar-entity depth)
13980 (unless (nth 2 ent-entry)
13981 (end-of-line 0) (insert "!") (forward-char 1))
13982 (unless (member (nth 0 ent-entry) ent-inst-list)
13983 (end-of-line 0) (insert " (top)") (forward-char 1))
13984 (setq ent-alist (cdr ent-alist)))
13985 ;; insert configurations
13986 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
13988 (setq conf-entry (car conf-alist))
13989 (speedbar-make-tag-line
13990 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
13991 (nth 1 conf-entry) 'vhdl-speedbar-find-file
13992 (cons (nth 2 conf-entry) (nth 3 conf-entry))
13993 'vhdl-speedbar-configuration depth)
13994 (setq conf-alist (cdr conf-alist)))
13996 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
13998 (setq pack-entry (car pack-alist))
13999 (vhdl-speedbar-make-pack-line
14000 (nth 0 pack-entry) (nth 1 pack-entry)
14001 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14002 (cons (nth 7 pack-entry) (nth 8 pack-entry))
14004 (setq pack-alist (cdr pack-alist))))))
14006 (defun vhdl-speedbar-rescan-hierarchy ()
14007 "Rescan hierarchy for the directory or project under the cursor."
14012 (vhdl-speedbar-show-projects
14013 (setq key (vhdl-speedbar-line-project))
14014 (vhdl-scan-project-contents key))
14015 ;; top-level directory
14016 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14017 (re-search-forward "[0-9]+:" nil t)
14018 (vhdl-scan-directory-contents
14019 (abbreviate-file-name (speedbar-line-path))))
14020 ;; current directory
14021 (t (setq path (speedbar-line-path))
14022 (string-match "^\\(.+[/\\]\\)" path)
14023 (vhdl-scan-directory-contents
14024 (abbreviate-file-name (match-string 1 path)))))
14025 (vhdl-speedbar-refresh key)))
14027 (defun vhdl-speedbar-expand-dirs (directory)
14028 "Expand subdirectories in DIRECTORY according to
14029 `speedbar-shown-directories'."
14030 ;; (nicked from `speedbar-default-directory-list')
14031 (let ((sf (cdr (reverse speedbar-shown-directories)))
14032 (vhdl-speedbar-update-current-unit nil))
14033 (setq speedbar-shown-directories
14034 (list (expand-file-name default-directory)))
14036 (when (speedbar-goto-this-file (car sf))
14037 (beginning-of-line)
14038 (when (looking-at "[0-9]+:\\s-*<")
14039 (goto-char (match-end 0))
14040 (speedbar-do-function-pointer)))
14041 (setq sf (cdr sf))))
14042 (vhdl-speedbar-update-current-unit nil t))
14044 (defun vhdl-speedbar-expand-units (key)
14045 "Expand design units in directory/project KEY according to
14046 `vhdl-speedbar-shown-unit-alist'."
14047 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14048 (vhdl-speedbar-update-current-unit nil)
14049 vhdl-updated-project-list)
14050 (adelete 'vhdl-speedbar-shown-unit-alist key)
14051 (vhdl-prepare-search-1
14052 (while unit-alist ; expand units
14053 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14054 (beginning-of-line)
14055 (let ((arch-alist (nth 1 (car unit-alist)))
14057 (when (looking-at "^[0-9]+:\\s-*\\[")
14058 (goto-char (match-end 0))
14059 (setq position (point))
14060 (speedbar-do-function-pointer)
14061 (select-frame speedbar-frame)
14062 (while arch-alist ; expand architectures
14063 (goto-char position)
14064 (when (re-search-forward
14065 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14066 (car arch-alist) "\\>\\)") nil t)
14067 (beginning-of-line)
14068 (when (looking-at "^[0-9]+:\\s-*{")
14069 (goto-char (match-end 0))
14070 (speedbar-do-function-pointer)
14071 (select-frame speedbar-frame)))
14072 (setq arch-alist (cdr arch-alist))))
14073 (setq unit-alist (cdr unit-alist))))))
14074 (vhdl-speedbar-update-current-unit nil t))
14076 (defun vhdl-speedbar-contract-level ()
14077 "Contract current level in current directory/project."
14079 (when (or (save-excursion
14080 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14081 (and (save-excursion
14082 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14083 (re-search-backward
14084 (format "^[0-%d]:\\s-*[[{<]-"
14085 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
14086 (goto-char (match-end 0))
14087 (speedbar-do-function-pointer)
14088 (speedbar-center-buffer-smartly)))
14090 (defun vhdl-speedbar-contract-all ()
14091 "Contract all expanded design units in current directory/project."
14093 (if (and vhdl-speedbar-show-projects
14094 (save-excursion (beginning-of-line) (looking-at "^0:")))
14095 (progn (setq vhdl-speedbar-shown-project-list nil)
14096 (vhdl-speedbar-refresh))
14097 (let ((key (vhdl-speedbar-line-key)))
14098 (adelete 'vhdl-speedbar-shown-unit-alist key)
14099 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14100 (when (memq 'display vhdl-speedbar-save-cache)
14101 (add-to-list 'vhdl-updated-project-list key)))))
14103 (defun vhdl-speedbar-expand-all ()
14104 "Expand all design units in current directory/project."
14106 (let* ((key (vhdl-speedbar-line-key))
14107 (ent-alist (aget vhdl-entity-alist key t))
14108 (conf-alist (aget vhdl-config-alist key t))
14109 (pack-alist (aget vhdl-package-alist key t))
14110 arch-alist unit-alist subunit-alist)
14111 (add-to-list 'vhdl-speedbar-shown-project-list key)
14113 (setq arch-alist (nth 4 (car ent-alist)))
14114 (setq subunit-alist nil)
14116 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14117 (setq arch-alist (cdr arch-alist)))
14118 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14119 (setq ent-alist (cdr ent-alist)))
14121 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14122 (setq conf-alist (cdr conf-alist)))
14124 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14125 (setq pack-alist (cdr pack-alist)))
14126 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14127 (vhdl-speedbar-refresh)
14128 (when (memq 'display vhdl-speedbar-save-cache)
14129 (add-to-list 'vhdl-updated-project-list key))))
14131 (defun vhdl-speedbar-expand-project (text token indent)
14132 "Expand/contract the project under the cursor."
14134 ((string-match "+" text) ; expand project
14135 (speedbar-change-expand-button-char ?-)
14136 (unless (member token vhdl-speedbar-shown-project-list)
14137 (setq vhdl-speedbar-shown-project-list
14138 (cons token vhdl-speedbar-shown-project-list)))
14139 (speedbar-with-writable
14141 (end-of-line) (forward-char 1)
14142 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14143 speedbar-power-click))))
14144 ((string-match "-" text) ; contract project
14145 (speedbar-change-expand-button-char ?+)
14146 (setq vhdl-speedbar-shown-project-list
14147 (delete token vhdl-speedbar-shown-project-list))
14148 (speedbar-delete-subblock indent))
14149 (t (error "Nothing to display")))
14150 (when (equal (selected-frame) speedbar-frame)
14151 (speedbar-center-buffer-smartly)))
14153 (defun vhdl-speedbar-expand-entity (text token indent)
14154 "Expand/contract the entity under the cursor."
14156 ((string-match "+" text) ; expand entity
14157 (let* ((key (vhdl-speedbar-line-key indent))
14158 (ent-alist (aget vhdl-entity-alist key t))
14159 (ent-entry (aget ent-alist token t))
14160 (arch-alist (nth 3 ent-entry))
14161 (inst-alist (vhdl-get-instantiations token indent))
14162 (subpack-alist (nth 4 ent-entry))
14163 arch-entry inst-entry)
14164 (if (not (or arch-alist inst-alist subpack-alist))
14165 (speedbar-change-expand-button-char ??)
14166 (speedbar-change-expand-button-char ?-)
14167 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14168 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14169 (aput 'unit-alist token nil)
14170 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14171 (speedbar-with-writable
14173 (end-of-line) (forward-char 1)
14174 ;; insert architectures
14176 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14178 (setq arch-entry (car arch-alist))
14179 (speedbar-make-tag-line
14180 'curly ?+ 'vhdl-speedbar-expand-architecture
14181 (cons token (nth 0 arch-entry))
14182 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14183 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14184 'vhdl-speedbar-architecture (1+ indent))
14185 (setq arch-alist (cdr arch-alist)))
14186 ;; insert instantiations
14188 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14190 (setq inst-entry (car inst-alist))
14191 (vhdl-speedbar-make-inst-line
14192 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14193 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14194 nil nil nil (1+ indent) 0 " in ")
14195 (setq inst-alist (cdr inst-alist)))
14196 ;; insert required packages
14197 (vhdl-speedbar-insert-subpackages
14198 subpack-alist (1+ indent) indent)))
14199 (when (memq 'display vhdl-speedbar-save-cache)
14200 (add-to-list 'vhdl-updated-project-list key))
14201 (vhdl-speedbar-update-current-unit t t))))
14202 ((string-match "-" text) ; contract entity
14203 (speedbar-change-expand-button-char ?+)
14204 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14205 (let* ((key (vhdl-speedbar-line-key indent))
14206 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14207 (adelete 'unit-alist token)
14209 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14210 (adelete 'vhdl-speedbar-shown-unit-alist key))
14211 (speedbar-delete-subblock indent)
14212 (when (memq 'display vhdl-speedbar-save-cache)
14213 (add-to-list 'vhdl-updated-project-list key))))
14214 (t (error "Nothing to display")))
14215 (when (equal (selected-frame) speedbar-frame)
14216 (speedbar-center-buffer-smartly)))
14218 (defun vhdl-speedbar-expand-architecture (text token indent)
14219 "Expand/contract the architecture under the cursor."
14221 ((string-match "+" text) ; expand architecture
14222 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14223 (ent-alist (aget vhdl-entity-alist key t))
14224 (conf-alist (aget vhdl-config-alist key t))
14225 (hier-alist (vhdl-get-hierarchy
14226 ent-alist conf-alist (car token) (cdr token) nil nil
14228 (ent-entry (aget ent-alist (car token) t))
14229 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14230 (subpack-alist (nth 4 arch-entry))
14232 (if (not (or hier-alist subpack-alist))
14233 (speedbar-change-expand-button-char ??)
14234 (speedbar-change-expand-button-char ?-)
14235 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14236 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14237 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14238 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14239 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14240 (speedbar-with-writable
14242 (end-of-line) (forward-char 1)
14243 ;; insert instance hierarchy
14245 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14248 (setq entry (car hier-alist))
14249 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14250 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14251 (vhdl-speedbar-make-inst-line
14252 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14253 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14254 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14255 (setq hier-alist (cdr hier-alist)))
14256 ;; insert required packages
14257 (vhdl-speedbar-insert-subpackages
14258 subpack-alist (1+ indent) (1- indent))))
14259 (when (memq 'display vhdl-speedbar-save-cache)
14260 (add-to-list 'vhdl-updated-project-list key))
14261 (vhdl-speedbar-update-current-unit t t))))
14262 ((string-match "-" text) ; contract architecture
14263 (speedbar-change-expand-button-char ?+)
14264 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14265 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14266 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14267 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14268 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14269 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14270 (speedbar-delete-subblock indent)
14271 (when (memq 'display vhdl-speedbar-save-cache)
14272 (add-to-list 'vhdl-updated-project-list key))))
14273 (t (error "Nothing to display")))
14274 (when (equal (selected-frame) speedbar-frame)
14275 (speedbar-center-buffer-smartly)))
14277 (defun vhdl-speedbar-expand-config (text token indent)
14278 "Expand/contract the configuration under the cursor."
14280 ((string-match "+" text) ; expand configuration
14281 (let* ((key (vhdl-speedbar-line-key indent))
14282 (conf-alist (aget vhdl-config-alist key t))
14283 (conf-entry (aget conf-alist token))
14284 (ent-alist (aget vhdl-entity-alist key t))
14285 (hier-alist (vhdl-get-hierarchy
14286 ent-alist conf-alist (nth 3 conf-entry)
14287 (nth 4 conf-entry) token (nth 5 conf-entry)
14289 (subpack-alist (nth 6 conf-entry))
14291 (if (not (or hier-alist subpack-alist))
14292 (speedbar-change-expand-button-char ??)
14293 (speedbar-change-expand-button-char ?-)
14294 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14295 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14296 (aput 'unit-alist token nil)
14297 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14298 (speedbar-with-writable
14300 (end-of-line) (forward-char 1)
14301 ;; insert instance hierarchy
14303 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
14305 (setq entry (car hier-alist))
14306 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14307 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14308 (vhdl-speedbar-make-inst-line
14309 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14310 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14311 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14312 (setq hier-alist (cdr hier-alist)))
14313 ;; insert required packages
14314 (vhdl-speedbar-insert-subpackages
14315 subpack-alist (1+ indent) indent)))
14316 (when (memq 'display vhdl-speedbar-save-cache)
14317 (add-to-list 'vhdl-updated-project-list key))
14318 (vhdl-speedbar-update-current-unit t t))))
14319 ((string-match "-" text) ; contract configuration
14320 (speedbar-change-expand-button-char ?+)
14321 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14322 (let* ((key (vhdl-speedbar-line-key indent))
14323 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14324 (adelete 'unit-alist token)
14326 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14327 (adelete 'vhdl-speedbar-shown-unit-alist key))
14328 (speedbar-delete-subblock indent)
14329 (when (memq 'display vhdl-speedbar-save-cache)
14330 (add-to-list 'vhdl-updated-project-list key))))
14331 (t (error "Nothing to display")))
14332 (when (equal (selected-frame) speedbar-frame)
14333 (speedbar-center-buffer-smartly)))
14335 (defun vhdl-speedbar-expand-package (text token indent)
14336 "Expand/contract the package under the cursor."
14338 ((string-match "+" text) ; expand package
14339 (let* ((key (vhdl-speedbar-line-key indent))
14340 (pack-alist (aget vhdl-package-alist key t))
14341 (pack-entry (aget pack-alist token t))
14342 (comp-alist (nth 3 pack-entry))
14343 (func-alist (nth 4 pack-entry))
14344 (func-body-alist (nth 8 pack-entry))
14345 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14346 comp-entry func-entry func-body-entry)
14347 (if (not (or comp-alist func-alist subpack-alist))
14348 (speedbar-change-expand-button-char ??)
14349 (speedbar-change-expand-button-char ?-)
14350 ;; add package to `vhdl-speedbar-shown-unit-alist'
14351 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14352 (aput 'unit-alist token nil)
14353 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14354 (speedbar-with-writable
14356 (end-of-line) (forward-char 1)
14357 ;; insert components
14359 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14361 (setq comp-entry (car comp-alist))
14362 (speedbar-make-tag-line
14364 (cons token (nth 0 comp-entry))
14365 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14366 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14367 'vhdl-speedbar-entity (1+ indent))
14368 (setq comp-alist (cdr comp-alist)))
14369 ;; insert subprograms
14371 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14373 (setq func-entry (car func-alist)
14374 func-body-entry (aget func-body-alist (car func-entry) t))
14375 (when (nth 2 func-entry)
14376 (vhdl-speedbar-make-subprogram-line
14378 (cons (nth 2 func-entry) (nth 3 func-entry))
14379 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14381 (setq func-alist (cdr func-alist)))
14382 ;; insert required packages
14383 (vhdl-speedbar-insert-subpackages
14384 subpack-alist (1+ indent) indent)))
14385 (when (memq 'display vhdl-speedbar-save-cache)
14386 (add-to-list 'vhdl-updated-project-list key))
14387 (vhdl-speedbar-update-current-unit t t))))
14388 ((string-match "-" text) ; contract package
14389 (speedbar-change-expand-button-char ?+)
14390 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14391 (let* ((key (vhdl-speedbar-line-key indent))
14392 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14393 (adelete 'unit-alist token)
14395 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14396 (adelete 'vhdl-speedbar-shown-unit-alist key))
14397 (speedbar-delete-subblock indent)
14398 (when (memq 'display vhdl-speedbar-save-cache)
14399 (add-to-list 'vhdl-updated-project-list key))))
14400 (t (error "Nothing to display")))
14401 (when (equal (selected-frame) speedbar-frame)
14402 (speedbar-center-buffer-smartly)))
14404 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14405 "Insert required packages."
14406 (let* ((pack-alist (aget vhdl-package-alist
14407 (vhdl-speedbar-line-key dir-indent) t))
14408 pack-key lib-name pack-entry)
14409 (when subpack-alist
14410 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14411 (while subpack-alist
14412 (setq pack-key (cdar subpack-alist)
14413 lib-name (caar subpack-alist))
14414 (setq pack-entry (aget pack-alist pack-key t))
14415 (vhdl-speedbar-make-subpack-line
14416 (or (nth 0 pack-entry) pack-key) lib-name
14417 (cons (nth 1 pack-entry) (nth 2 pack-entry)) indent)
14418 (setq subpack-alist (cdr subpack-alist)))))
14420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14421 ;; Display help functions
14423 (defvar vhdl-speedbar-update-current-unit t
14424 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14426 (defun vhdl-speedbar-update-current-project ()
14427 "Highlight project that is currently active."
14428 (when (and vhdl-speedbar-show-projects
14429 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14430 (and (boundp 'speedbar-frame)
14431 (frame-live-p speedbar-frame)))
14432 (let ((last-frame (selected-frame))
14433 (project-alist vhdl-project-alist)
14435 (select-frame speedbar-frame)
14436 (speedbar-with-writable
14438 (while project-alist
14439 (goto-char (point-min))
14440 (when (re-search-forward
14441 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14442 (put-text-property (match-beginning 1) (match-end 1) 'face
14443 (if (equal (caar project-alist) vhdl-project)
14444 'speedbar-selected-face
14445 'speedbar-directory-face))
14446 (when (equal (caar project-alist) vhdl-project)
14447 (setq pos (1- (match-beginning 1)))))
14448 (setq project-alist (cdr project-alist))))
14449 (when pos (goto-char pos)))
14450 (select-frame last-frame)
14451 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14454 (defun vhdl-speedbar-update-current-unit (&optional no-position always)
14455 "Highlight all design units that are contained in the current file.
14456 NO-POSITION non-nil means do not re-position cursor."
14457 (let ((last-frame (selected-frame))
14458 (project-list vhdl-speedbar-shown-project-list)
14459 file-alist pos file-name)
14460 ;; get current file name
14461 (if (fboundp 'speedbar-select-attached-frame)
14462 (speedbar-select-attached-frame)
14463 (select-frame speedbar-attached-frame))
14464 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
14465 (when (and vhdl-speedbar-update-current-unit
14466 (or always (not (equal file-name speedbar-last-selected-file))))
14467 (if vhdl-speedbar-show-projects
14468 (while project-list
14469 (setq file-alist (append file-alist (aget vhdl-file-alist
14470 (car project-list) t)))
14471 (setq project-list (cdr project-list)))
14472 (setq file-alist (aget vhdl-file-alist
14473 (abbreviate-file-name default-directory) t)))
14474 (select-frame speedbar-frame)
14475 (set-buffer speedbar-buffer)
14476 (speedbar-with-writable
14477 (vhdl-prepare-search-1
14479 ;; unhighlight last units
14480 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
14481 (vhdl-speedbar-update-units
14482 "\\[.\\] " (nth 0 file-entry)
14483 speedbar-last-selected-file 'vhdl-speedbar-entity)
14484 (vhdl-speedbar-update-units
14485 "{.} " (nth 1 file-entry)
14486 speedbar-last-selected-file 'vhdl-speedbar-architecture)
14487 (vhdl-speedbar-update-units
14488 "\\[.\\] " (nth 3 file-entry)
14489 speedbar-last-selected-file 'vhdl-speedbar-configuration)
14490 (vhdl-speedbar-update-units
14491 "[]>] " (nth 4 file-entry)
14492 speedbar-last-selected-file 'vhdl-speedbar-package)
14493 (vhdl-speedbar-update-units
14494 "\\[.\\].+(" '("body")
14495 speedbar-last-selected-file 'vhdl-speedbar-package)
14496 (vhdl-speedbar-update-units
14497 "> " (nth 6 file-entry)
14498 speedbar-last-selected-file 'vhdl-speedbar-instantiation))
14499 ;; highlight current units
14500 (let* ((file-entry (aget file-alist file-name t)))
14502 pos (vhdl-speedbar-update-units
14503 "\\[.\\] " (nth 0 file-entry)
14504 file-name 'vhdl-speedbar-entity-selected pos)
14505 pos (vhdl-speedbar-update-units
14506 "{.} " (nth 1 file-entry)
14507 file-name 'vhdl-speedbar-architecture-selected pos)
14508 pos (vhdl-speedbar-update-units
14509 "\\[.\\] " (nth 3 file-entry)
14510 file-name 'vhdl-speedbar-configuration-selected pos)
14511 pos (vhdl-speedbar-update-units
14512 "[]>] " (nth 4 file-entry)
14513 file-name 'vhdl-speedbar-package-selected pos)
14514 pos (vhdl-speedbar-update-units
14515 "\\[.\\].+(" '("body")
14516 file-name 'vhdl-speedbar-package-selected pos)
14517 pos (vhdl-speedbar-update-units
14518 "> " (nth 6 file-entry)
14519 file-name 'vhdl-speedbar-instantiation-selected pos))))))
14520 ;; move speedbar so the first highlighted unit is visible
14521 (when (and pos (not no-position))
14523 (speedbar-center-buffer-smartly)
14524 (speedbar-position-cursor-on-line))
14525 (setq speedbar-last-selected-file file-name))
14526 (select-frame last-frame)
14529 (defun vhdl-speedbar-update-units (text unit-list file-name face
14531 "Help function to highlight design units."
14533 (goto-char (point-min))
14534 (while (re-search-forward
14535 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14536 (when (equal file-name (car (get-text-property
14537 (match-beginning 1) 'speedbar-token)))
14538 (setq pos (or pos (point-marker)))
14539 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14540 (setq unit-list (cdr unit-list)))
14543 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
14544 ent-name ent-file-marker
14545 arch-name arch-file-marker
14546 conf-name conf-file-marker
14547 lib-name depth offset delimiter)
14548 "Insert instantiation entry."
14549 (let ((start (point))
14551 (insert (int-to-string depth) ":")
14552 (put-text-property start (point) 'invisible t)
14553 (setq visible-start (point))
14554 (insert-char ? (* depth speedbar-indentation-width))
14555 (while (> offset 0)
14557 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14558 (setq offset (1- offset)))
14559 (put-text-property visible-start (point) 'invisible nil)
14560 (setq start (point))
14562 (speedbar-make-button start (point) nil nil nil)
14563 (setq visible-start (point))
14565 (setq start (point))
14566 (if (not inst-name)
14569 (speedbar-make-button
14570 start (point) 'vhdl-speedbar-instantiation 'speedbar-highlight-face
14571 'vhdl-speedbar-find-file inst-file-marker))
14574 (setq start (point))
14576 (speedbar-make-button
14577 start (point) 'vhdl-speedbar-entity 'speedbar-highlight-face
14578 'vhdl-speedbar-find-file ent-file-marker)
14581 (setq start (point))
14583 (speedbar-make-button
14584 start (point) 'vhdl-speedbar-architecture 'speedbar-highlight-face
14585 'vhdl-speedbar-find-file arch-file-marker)
14589 (setq start (point))
14591 (speedbar-make-button
14592 start (point) 'vhdl-speedbar-configuration 'speedbar-highlight-face
14593 'vhdl-speedbar-find-file conf-file-marker)
14595 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
14596 (setq start (point))
14597 (insert " (" lib-name ")")
14598 (put-text-property (+ 2 start) (1- (point)) 'face
14599 'vhdl-speedbar-library))
14600 (insert-char ?\n 1)
14601 (put-text-property visible-start (point) 'invisible nil)))
14603 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14604 body-file-marker depth)
14605 "Insert package entry."
14606 (let ((start (point))
14608 (insert (int-to-string depth) ":")
14609 (put-text-property start (point) 'invisible t)
14610 (setq visible-start (point))
14611 (insert-char ? (* depth speedbar-indentation-width))
14612 (put-text-property visible-start (point) 'invisible nil)
14613 (setq start (point))
14615 (speedbar-make-button
14616 start (point) 'speedbar-button-face 'speedbar-highlight-face
14617 'vhdl-speedbar-expand-package pack-key)
14618 (setq visible-start (point))
14619 (insert-char ? 1 nil)
14620 (setq start (point))
14622 (speedbar-make-button
14623 start (point) 'vhdl-speedbar-package 'speedbar-highlight-face
14624 'vhdl-speedbar-find-file pack-file-marker)
14625 (unless (car pack-file-marker)
14627 (when (car body-file-marker)
14629 (setq start (point))
14631 (speedbar-make-button
14632 start (point) 'vhdl-speedbar-package 'speedbar-highlight-face
14633 'vhdl-speedbar-find-file body-file-marker)
14635 (insert-char ?\n 1)
14636 (put-text-property visible-start (point) 'invisible nil)))
14638 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14640 "Insert used package entry."
14641 (let ((start (point))
14643 (insert (int-to-string depth) ":")
14644 (put-text-property start (point) 'invisible t)
14645 (setq visible-start (point))
14646 (insert-char ? (* depth speedbar-indentation-width))
14647 (put-text-property visible-start (point) 'invisible nil)
14648 (setq start (point))
14650 (speedbar-make-button start (point) nil nil nil)
14651 (setq visible-start (point))
14653 (setq start (point))
14655 (speedbar-make-button
14656 start (point) 'vhdl-speedbar-package 'speedbar-highlight-face
14657 'vhdl-speedbar-find-file pack-file-marker)
14658 (setq start (point))
14659 (insert " (" lib-name ")")
14660 (put-text-property (+ 2 start) (1- (point)) 'face
14661 'vhdl-speedbar-library)
14662 (insert-char ?\n 1)
14663 (put-text-property visible-start (point) 'invisible nil)))
14665 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14666 func-body-file-marker
14668 "Insert subprogram entry."
14669 (let ((start (point))
14671 (insert (int-to-string depth) ":")
14672 (put-text-property start (point) 'invisible t)
14673 (setq visible-start (point))
14674 (insert-char ? (* depth speedbar-indentation-width))
14675 (put-text-property visible-start (point) 'invisible nil)
14676 (setq start (point))
14678 (speedbar-make-button start (point) nil nil nil)
14679 (setq visible-start (point))
14681 (setq start (point))
14683 (speedbar-make-button
14684 start (point) 'vhdl-speedbar-subprogram 'speedbar-highlight-face
14685 'vhdl-speedbar-find-file func-file-marker)
14686 (when (car func-body-file-marker)
14688 (setq start (point))
14690 (speedbar-make-button
14691 start (point) 'vhdl-speedbar-subprogram 'speedbar-highlight-face
14692 'vhdl-speedbar-find-file func-body-file-marker)
14694 (insert-char ?\n 1)
14695 (put-text-property visible-start (point) 'invisible nil)))
14697 (defun vhdl-speedbar-make-title-line (text &optional depth)
14698 "Insert design unit title entry."
14699 (let ((start (point))
14702 (insert (int-to-string depth) ":")
14703 (put-text-property start (point) 'invisible t))
14704 (setq visible-start (point))
14705 (insert-char ? (* (or depth 0) speedbar-indentation-width))
14706 (setq start (point))
14708 (speedbar-make-button start (point) nil nil nil nil)
14709 (insert-char ?\n 1)
14710 (put-text-property visible-start (point) 'invisible nil)))
14712 (defun vhdl-speedbar-insert-dirs (files level)
14713 "Insert subdirectories."
14714 (let ((dirs (car files)))
14716 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14717 (car dirs) 'speedbar-dir-follow nil
14718 'speedbar-directory-face level)
14719 (setq dirs (cdr dirs)))))
14721 (defun vhdl-speedbar-dired (text token indent)
14722 "Speedbar click handler for directory expand button in hierarchy mode."
14723 (cond ((string-match "+" text) ; we have to expand this dir
14724 (setq speedbar-shown-directories
14725 (cons (expand-file-name
14726 (concat (speedbar-line-path indent) token "/"))
14727 speedbar-shown-directories))
14728 (speedbar-change-expand-button-char ?-)
14729 (speedbar-reset-scanners)
14730 (speedbar-with-writable
14732 (end-of-line) (forward-char 1)
14733 (vhdl-speedbar-insert-dirs
14734 (speedbar-file-lists
14735 (concat (speedbar-line-path indent) token "/"))
14737 (speedbar-reset-scanners)
14738 (vhdl-speedbar-insert-dir-hierarchy
14739 (abbreviate-file-name
14740 (concat (speedbar-line-path indent) token "/"))
14741 (1+ indent) speedbar-power-click)))
14742 (vhdl-speedbar-update-current-unit t t))
14743 ((string-match "-" text) ; we have to contract this node
14744 (speedbar-reset-scanners)
14745 (let ((oldl speedbar-shown-directories)
14747 (td (expand-file-name
14748 (concat (speedbar-line-path indent) token))))
14750 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14751 (setq newl (cons (car oldl) newl)))
14752 (setq oldl (cdr oldl)))
14753 (setq speedbar-shown-directories (nreverse newl)))
14754 (speedbar-change-expand-button-char ?+)
14755 (speedbar-delete-subblock indent))
14756 (t (error "Nothing to display")))
14757 (when (equal (selected-frame) speedbar-frame)
14758 (speedbar-center-buffer-smartly)))
14760 (defun vhdl-speedbar-item-info ()
14761 "Derive and display information about this line item."
14763 (beginning-of-line)
14764 ;; skip invisible number info
14765 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
14767 ;; project/directory entry
14768 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14769 (if vhdl-speedbar-show-projects
14770 (message "Project \"%s\"" (match-string-no-properties 1))
14771 (speedbar-files-item-info)))
14772 ;; design unit entry
14773 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14774 (goto-char (match-end 1))
14775 (let ((face (get-text-property (point) 'face)))
14777 "%s \"%s\" in \"%s\""
14778 ;; design unit kind
14779 (cond ((or (eq face 'vhdl-speedbar-entity)
14780 (eq face 'vhdl-speedbar-entity-selected))
14781 (if (equal (match-string 2) ">") "Component" "Entity"))
14782 ((or (eq face 'vhdl-speedbar-architecture)
14783 (eq face 'vhdl-speedbar-architecture-selected))
14785 ((or (eq face 'vhdl-speedbar-configuration)
14786 (eq face 'vhdl-speedbar-configuration-selected))
14788 ((or (eq face 'vhdl-speedbar-package)
14789 (eq face 'vhdl-speedbar-package-selected))
14791 ((or (eq face 'vhdl-speedbar-instantiation)
14792 (eq face 'vhdl-speedbar-instantiation-selected))
14794 ((eq face 'vhdl-speedbar-subprogram)
14797 ;; design unit name
14798 (buffer-substring-no-properties
14799 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14802 (file-relative-name
14803 (or (car (get-text-property (point) 'speedbar-token))
14805 (vhdl-default-directory)))))
14806 (t (message "")))))
14808 (defun vhdl-speedbar-line-text ()
14809 "Calls `speedbar-line-text' and removes text properties."
14810 (let ((string (speedbar-line-text)))
14811 (set-text-properties 0 (length string) nil string)
14814 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14817 (defun vhdl-speedbar-line-key (&optional indent)
14818 "Get currently displayed directory of project name."
14819 (if vhdl-speedbar-show-projects
14820 (vhdl-speedbar-line-project)
14821 (abbreviate-file-name
14822 (file-name-as-directory (speedbar-line-path indent)))))
14824 (defun vhdl-speedbar-line-project (&optional indent)
14825 "Get currently displayed project name."
14826 (and vhdl-speedbar-show-projects
14829 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
14830 (match-string-no-properties 1))))
14832 (defun vhdl-add-modified-file ()
14833 "Add file to `vhdl-modified-file-list'."
14834 (when vhdl-file-alist
14835 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
14838 (defun vhdl-resolve-paths (path-list)
14839 "Resolve path wildcards in PATH-LIST."
14840 (let (path-list-1 path-list-2 path-beg path-end dir)
14841 ;; eliminate non-existent directories
14843 (setq dir (car path-list))
14844 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
14845 (if (file-directory-p (match-string 2 dir))
14846 (setq path-list-1 (cons dir path-list-1))
14847 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
14848 (setq path-list (cdr path-list)))
14849 ;; resolve path wildcards
14851 (setq dir (car path-list-1))
14852 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
14854 (setq path-beg (match-string 1 dir)
14855 path-end (match-string 5 dir))
14860 (lambda (var) (concat path-beg var path-end)))
14861 (let ((all-list (vhdl-directory-files
14862 (match-string 2 dir) t
14863 (concat "\\<" (wildcard-to-regexp
14864 (match-string 4 dir)))))
14867 (when (file-directory-p (car all-list))
14868 (setq dir-list (cons (car all-list) dir-list)))
14869 (setq all-list (cdr all-list)))
14871 (cdr path-list-1))))
14872 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
14873 (when (file-directory-p (match-string 2 dir))
14874 (setq path-list-2 (cons dir path-list-2)))
14875 (setq path-list-1 (cdr path-list-1))))
14876 (nreverse path-list-2)))
14878 (defun vhdl-speedbar-goto-this-unit (directory unit)
14879 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
14880 (let ((dest (point)))
14881 (if (and (if vhdl-speedbar-show-projects
14882 (progn (goto-char (point-min)) t)
14883 (speedbar-goto-this-file directory))
14884 (re-search-forward (concat "[]}] " unit "\\>") nil t))
14885 (progn (speedbar-position-cursor-on-line)
14890 (defun vhdl-speedbar-find-file (text token indent)
14891 "When user clicks on TEXT, load file with name and position in TOKEN.
14892 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
14893 is already shown in a buffer."
14894 (if (not (car token))
14895 (error "ERROR: File cannot be found")
14896 (let ((buffer (get-file-buffer (car token))))
14897 (speedbar-find-file-in-frame (car token))
14898 (when (or vhdl-speedbar-jump-to-unit buffer)
14899 (goto-line (cdr token))
14901 (vhdl-speedbar-update-current-unit t t)
14902 (speedbar-set-timer speedbar-update-speed)
14903 (speedbar-maybee-jump-to-attached-frame))))
14905 (defun vhdl-speedbar-port-copy ()
14906 "Copy the port of the entity/component or subprogram under the cursor."
14908 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
14909 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
14910 (error "ERROR: No entity/component or subprogram under cursor")
14911 (beginning-of-line)
14912 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
14913 (condition-case info
14914 (let ((token (get-text-property
14915 (match-beginning 3) 'speedbar-token)))
14916 (vhdl-visit-file (car token) t
14917 (progn (goto-line (cdr token))
14921 (vhdl-subprog-copy)))))
14922 (error (error "ERROR: %s not scanned successfully\n (%s)"
14923 (if is-entity "Port" "Interface") (cadr info))))
14924 (error "ERROR: No entity/component or subprogram on current line")))))
14926 (defun vhdl-speedbar-place-component ()
14927 "Place the entity/component under the cursor as component."
14929 (if (not (vhdl-speedbar-check-unit 'entity))
14930 (error "ERROR: No entity/component under cursor")
14931 (vhdl-speedbar-port-copy)
14932 (if (fboundp 'speedbar-select-attached-frame)
14933 (speedbar-select-attached-frame)
14934 (select-frame speedbar-attached-frame))
14935 (vhdl-compose-place-component)
14936 (select-frame speedbar-frame)))
14938 (defun vhdl-speedbar-make-design ()
14939 "Make (compile) design unit or directory/project under the cursor."
14941 (if (not (save-excursion (beginning-of-line)
14942 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
14943 (error "ERROR: No primary design unit or directory/project under cursor")
14944 (let ((is-unit (match-string 2))
14945 (unit-name (vhdl-speedbar-line-text))
14946 (vhdl-project (vhdl-speedbar-line-project))
14947 (directory (file-name-as-directory
14948 (or (speedbar-line-file) (speedbar-line-path)))))
14949 (if (fboundp 'speedbar-select-attached-frame)
14950 (speedbar-select-attached-frame)
14951 (select-frame speedbar-attached-frame))
14952 (let ((default-directory directory))
14953 (vhdl-make (and is-unit unit-name))))))
14955 (defun vhdl-speedbar-generate-makefile ()
14956 "Generate Makefile for directory/project under the cursor."
14958 (let ((vhdl-project (vhdl-speedbar-line-project))
14959 (default-directory (file-name-as-directory
14960 (or (speedbar-line-file) (speedbar-line-path)))))
14961 (vhdl-generate-makefile)))
14963 (defun vhdl-speedbar-check-unit (design-unit)
14964 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
14965 expansion function)."
14967 (speedbar-position-cursor-on-line)
14968 (cond ((eq design-unit 'entity)
14969 (memq (get-text-property (match-end 0) 'face)
14970 '(vhdl-speedbar-entity
14971 vhdl-speedbar-entity-selected)))
14972 ((eq design-unit 'subprogram)
14973 (eq (get-text-property (match-end 0) 'face)
14974 'vhdl-speedbar-subprogram))
14977 (defun vhdl-speedbar-set-depth (depth)
14978 "Set hierarchy display depth to DEPTH and refresh speedbar."
14979 (setq vhdl-speedbar-hierarchy-depth depth)
14980 (speedbar-refresh))
14982 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14985 (defface vhdl-speedbar-entity
14986 '((((class color) (background light)) (:foreground "ForestGreen"))
14987 (((class color) (background dark)) (:foreground "PaleGreen")))
14988 "Face used for displaying entity names."
14989 :group 'speedbar-faces)
14990 ;; backward-compatibility alias
14991 (put 'vhdl-speedbar-entity-face 'face-alias 'vhdl-speedbar-entity)
14993 (defface vhdl-speedbar-architecture
14994 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
14995 (((class color) (background light)) (:foreground "Blue"))
14996 (((class color) (background dark)) (:foreground "LightSkyBlue")))
14997 "Face used for displaying architecture names."
14998 :group 'speedbar-faces)
14999 ;; backward-compatibility alias
15000 (put 'vhdl-speedbar-architecture-face 'face-alias 'vhdl-speedbar-architecture)
15002 (defface vhdl-speedbar-configuration
15003 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15004 (((class color) (background dark)) (:foreground "Salmon")))
15005 "Face used for displaying configuration names."
15006 :group 'speedbar-faces)
15007 ;; backward-compatibility alias
15008 (put 'vhdl-speedbar-configuration-face 'face-alias 'vhdl-speedbar-configuration)
15010 (defface vhdl-speedbar-package
15011 '((((class color) (background light)) (:foreground "Grey50"))
15012 (((class color) (background dark)) (:foreground "Grey80")))
15013 "Face used for displaying package names."
15014 :group 'speedbar-faces)
15015 ;; backward-compatibility alias
15016 (put 'vhdl-speedbar-package-face 'face-alias 'vhdl-speedbar-package)
15018 (defface vhdl-speedbar-library
15019 '((((class color) (background light)) (:foreground "Purple"))
15020 (((class color) (background dark)) (:foreground "Orchid1")))
15021 "Face used for displaying library names."
15022 :group 'speedbar-faces)
15023 ;; backward-compatibility alias
15024 (put 'vhdl-speedbar-library-face 'face-alias 'vhdl-speedbar-library)
15026 (defface vhdl-speedbar-instantiation
15027 '((((class color) (background light)) (:foreground "Brown"))
15028 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
15029 (((class color) (background dark)) (:foreground "Yellow")))
15030 "Face used for displaying instantiation names."
15031 :group 'speedbar-faces)
15032 ;; backward-compatibility alias
15033 (put 'vhdl-speedbar-instantiation-face 'face-alias 'vhdl-speedbar-instantiation)
15035 (defface vhdl-speedbar-subprogram
15036 '((((class color) (background light)) (:foreground "Orchid4"))
15037 (((class color) (background dark)) (:foreground "BurlyWood2")))
15038 "Face used for displaying subprogram names."
15039 :group 'speedbar-faces)
15040 ;; backward-compatibility alias
15041 (put 'vhdl-speedbar-subprogram-face 'face-alias 'vhdl-speedbar-subprogram)
15043 (defface vhdl-speedbar-entity-selected
15044 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15045 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15046 "Face used for displaying entity names."
15047 :group 'speedbar-faces)
15048 ;; backward-compatibility alias
15049 (put 'vhdl-speedbar-entity-selected-face 'face-alias 'vhdl-speedbar-entity-selected)
15051 (defface vhdl-speedbar-architecture-selected
15052 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15053 (((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15054 (((class color) (background light)) (:foreground "Blue" :underline t))
15055 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15056 "Face used for displaying architecture names."
15057 :group 'speedbar-faces)
15058 ;; backward-compatibility alias
15059 (put 'vhdl-speedbar-architecture-selected-face 'face-alias 'vhdl-speedbar-architecture-selected)
15061 (defface vhdl-speedbar-configuration-selected
15062 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15063 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15064 "Face used for displaying configuration names."
15065 :group 'speedbar-faces)
15066 ;; backward-compatibility alias
15067 (put 'vhdl-speedbar-configuration-selected-face 'face-alias 'vhdl-speedbar-configuration-selected)
15069 (defface vhdl-speedbar-package-selected
15070 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15071 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15072 "Face used for displaying package names."
15073 :group 'speedbar-faces)
15074 ;; backward-compatibility alias
15075 (put 'vhdl-speedbar-package-selected-face 'face-alias 'vhdl-speedbar-package-selected)
15077 (defface vhdl-speedbar-instantiation-selected
15078 '((((class color) (background light)) (:foreground "Brown" :underline t))
15079 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1" :underline t))
15080 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15081 "Face used for displaying instantiation names."
15082 :group 'speedbar-faces)
15083 ;; backward-compatibility alias
15084 (put 'vhdl-speedbar-instantiation-selected-face 'face-alias 'vhdl-speedbar-instantiation-selected)
15086 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15090 (when (fboundp 'speedbar)
15092 (when (and vhdl-speedbar-auto-open
15093 (not (and (boundp 'speedbar-frame)
15094 (frame-live-p speedbar-frame))))
15095 (speedbar-frame-mode 1)
15096 (if (fboundp 'speedbar-select-attached-frame)
15097 (speedbar-select-attached-frame)
15098 (select-frame speedbar-attached-frame)))
15099 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15101 ;; initialize speedbar
15102 (if (not (boundp 'speedbar-frame))
15103 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15104 (vhdl-speedbar-initialize)
15105 (when speedbar-frame (vhdl-speedbar-refresh)))
15108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15109 ;;; Structural composition
15110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15112 (defun vhdl-get-components-package-name ()
15113 "Return the name of the components package."
15114 (let ((project (vhdl-project-p)))
15116 (vhdl-replace-string (car vhdl-components-package-name)
15117 (subst-char-in-string ? ?_ project))
15118 (cdr vhdl-components-package-name))))
15120 (defun vhdl-compose-new-component ()
15121 "Create entity and architecture for new component."
15123 (let* ((case-fold-search t)
15124 (ent-name (read-from-minibuffer "entity name: "
15125 nil vhdl-minibuffer-local-map))
15127 (if (equal (cdr vhdl-compose-architecture-name) "")
15128 (read-from-minibuffer "architecture name: "
15129 nil vhdl-minibuffer-local-map)
15130 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15131 ent-file-name arch-file-name ent-buffer arch-buffer project)
15132 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15133 ;; open entity file
15134 (unless (eq vhdl-compose-create-files 'none)
15135 (setq ent-file-name
15136 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15137 "." (file-name-extension (buffer-file-name))))
15138 (when (and (file-exists-p ent-file-name)
15139 (not (y-or-n-p (concat "File \"" ent-file-name
15140 "\" exists; overwrite? "))))
15141 (error "ERROR: Creating component...aborted"))
15142 (find-file ent-file-name)
15144 (set-buffer-modified-p nil))
15146 (if vhdl-compose-include-header
15147 (progn (vhdl-template-header)
15148 (goto-char (point-max)))
15149 (vhdl-comment-display-line) (insert "\n\n"))
15150 ;; insert library clause
15151 (vhdl-template-package-std-logic-1164)
15152 (when vhdl-use-components-package
15154 (vhdl-template-standard-package (vhdl-work-library)
15155 (vhdl-get-components-package-name)))
15156 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15157 ;; insert entity declaration
15158 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15159 (vhdl-insert-keyword " IS\n")
15160 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15161 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15162 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15163 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15164 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15165 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15166 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15167 (vhdl-insert-keyword "END ")
15168 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15169 (insert ent-name ";\n\n")
15170 (vhdl-comment-display-line) (insert "\n")
15171 ;; open architecture file
15172 (if (not (eq vhdl-compose-create-files 'separate))
15174 (setq ent-buffer (current-buffer))
15175 (setq arch-file-name
15176 (concat (vhdl-replace-string vhdl-architecture-file-name
15177 (concat ent-name " " arch-name))
15178 "." (file-name-extension (buffer-file-name))))
15179 (when (and (file-exists-p arch-file-name)
15180 (not (y-or-n-p (concat "File \"" arch-file-name
15181 "\" exists; overwrite? "))))
15182 (error "ERROR: Creating component...aborted"))
15183 (find-file arch-file-name)
15185 (set-buffer-modified-p nil)
15187 (if vhdl-compose-include-header
15188 (progn (vhdl-template-header)
15189 (goto-char (point-max)))
15190 (vhdl-comment-display-line) (insert "\n\n")))
15191 ;; insert architecture body
15192 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15193 (vhdl-insert-keyword " OF ") (insert ent-name)
15194 (vhdl-insert-keyword " IS\n\n")
15195 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15196 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15197 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15198 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15199 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15200 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15201 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15202 (vhdl-insert-keyword "BEGIN")
15203 (when vhdl-self-insert-comments
15205 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15206 (insert arch-name))
15208 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15209 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15210 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15211 (vhdl-insert-keyword "END ")
15212 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15213 (insert arch-name ";\n\n")
15215 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15216 (vhdl-template-footer)
15217 (vhdl-comment-display-line) (insert "\n"))
15218 (goto-char (point-min))
15219 (setq arch-buffer (current-buffer))
15220 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15221 (set-buffer arch-buffer) (save-buffer)
15223 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15225 (format "\n File created: \"%s\"" ent-file-name))
15226 (and arch-file-name
15227 (format "\n File created: \"%s\"" arch-file-name))))))
15229 (defun vhdl-compose-place-component ()
15230 "Place new component by pasting current port as component declaration and
15231 component instantiation."
15233 (if (not vhdl-port-list)
15234 (error "ERROR: No port has been read")
15236 (vhdl-prepare-search-2
15237 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15238 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15239 (error "ERROR: No architecture found"))
15240 (let* ((ent-name (match-string 1))
15242 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15243 "." (file-name-extension (buffer-file-name))))
15244 (orig-buffer (current-buffer)))
15245 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15246 ;; place component declaration
15247 (unless (or vhdl-use-components-package
15248 (vhdl-use-direct-instantiation)
15251 (concat "^\\s-*component\\s-+"
15252 (car vhdl-port-list) "\\>") nil t)))
15253 (re-search-forward "^begin\\>" nil)
15254 (beginning-of-line)
15255 (skip-chars-backward " \t\n")
15256 (insert "\n\n") (indent-to vhdl-basic-offset)
15257 (vhdl-port-paste-component t))
15258 ;; place component instantiation
15259 (re-search-forward "^end\\>" nil)
15260 (beginning-of-line)
15261 (skip-chars-backward " \t\n")
15262 (insert "\n\n") (indent-to vhdl-basic-offset)
15263 (vhdl-port-paste-instance nil t t)
15264 ;; place use clause for used packages
15265 (when (nth 3 vhdl-port-list)
15266 ;; open entity file
15267 (when (file-exists-p ent-file-name)
15268 (find-file ent-file-name))
15269 (goto-char (point-min))
15270 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15271 (error "ERROR: Entity not found: \"%s\"" ent-name))
15272 (goto-char (match-beginning 0))
15273 (if (and (save-excursion
15274 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15276 (progn (goto-char (match-end 0))
15277 (beginning-of-line 2))
15280 (vhdl-port-paste-context-clause)
15281 (switch-to-buffer orig-buffer))
15282 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15284 (defun vhdl-compose-wire-components ()
15285 "Connect components."
15288 (vhdl-prepare-search-2
15289 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15290 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15291 (error "ERROR: No architecture found"))
15292 (let* ((ent-name (match-string 1))
15294 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15295 "." (file-name-extension (buffer-file-name))))
15296 (arch-decl-pos (point-marker))
15297 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15298 (arch-end-pos (re-search-forward "^end\\>" nil))
15299 (pack-name (vhdl-get-components-package-name))
15301 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15302 "." (file-name-extension (buffer-file-name))))
15303 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15304 port-alist generic-alist inst-alist
15305 signal-name signal-entry signal-alist local-list written-list
15306 single-in-list multi-in-list single-out-list multi-out-list
15307 constant-name constant-entry constant-alist single-list multi-list
15308 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15309 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15310 signal-beg-pos signal-pos
15311 constant-temp-pos port-temp-pos signal-temp-pos)
15312 (message "Wiring components...")
15313 ;; process all instances
15314 (goto-char arch-stat-pos)
15315 (while (re-search-forward
15316 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15317 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15318 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15319 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15320 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15321 (setq inst-name (match-string-no-properties 1)
15322 comp-name (match-string-no-properties 4)
15323 comp-ent-name (match-string-no-properties 12)
15324 has-generic (or (match-string 7) (match-string 17)))
15327 ;; ... from component declaration
15329 (when vhdl-use-components-package pack-file-name) t
15331 (goto-char (point-min))
15332 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15333 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15335 ;; ... from entity declaration (direct instantiation)
15336 (setq comp-ent-file-name
15337 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name)
15338 "." (file-name-extension (buffer-file-name))))
15340 comp-ent-file-name t
15342 (goto-char (point-min))
15343 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15344 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15345 (vhdl-port-copy))))
15346 (vhdl-port-flatten t)
15347 (setq generic-alist (nth 1 vhdl-port-list)
15348 port-alist (nth 2 vhdl-port-list))
15349 (setq constant-alist nil
15352 ;; process all constants in generic map
15353 (vhdl-forward-syntactic-ws)
15354 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15355 (setq constant-name (match-string-no-properties 3))
15356 (setq constant-entry
15357 (cons constant-name
15358 (if (match-string 1)
15359 (or (aget generic-alist (match-string 2) t)
15360 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15361 (cdar generic-alist))))
15362 (setq constant-alist (cons constant-entry constant-alist))
15363 (setq constant-name (downcase constant-name))
15364 (if (or (member constant-name single-list)
15365 (member constant-name multi-list))
15366 (progn (setq single-list (delete constant-name single-list))
15367 (add-to-list 'multi-list constant-name))
15368 (add-to-list 'single-list constant-name))
15369 (unless (match-string 1)
15370 (setq generic-alist (cdr generic-alist)))
15371 (vhdl-forward-syntactic-ws))
15372 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15373 ;; process all signals in port map
15374 (vhdl-forward-syntactic-ws)
15375 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15376 (setq signal-name (match-string-no-properties 3))
15377 (setq signal-entry (cons signal-name
15378 (if (match-string 1)
15379 (or (aget port-alist (match-string 2) t)
15380 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
15381 (cdar port-alist))))
15382 (setq signal-alist (cons signal-entry signal-alist))
15383 (setq signal-name (downcase signal-name))
15384 (if (equal (upcase (nth 2 signal-entry)) "IN")
15387 ((member signal-name local-list)
15389 ((or (member signal-name single-out-list)
15390 (member signal-name multi-out-list))
15391 (setq single-out-list (delete signal-name single-out-list))
15392 (setq multi-out-list (delete signal-name multi-out-list))
15393 (add-to-list 'local-list signal-name))
15394 ((member signal-name single-in-list)
15395 (setq single-in-list (delete signal-name single-in-list))
15396 (add-to-list 'multi-in-list signal-name))
15397 ((not (member signal-name multi-in-list))
15398 (add-to-list 'single-in-list signal-name)))
15401 ((member signal-name local-list)
15403 ((or (member signal-name single-in-list)
15404 (member signal-name multi-in-list))
15405 (setq single-in-list (delete signal-name single-in-list))
15406 (setq multi-in-list (delete signal-name multi-in-list))
15407 (add-to-list 'local-list signal-name))
15408 ((member signal-name single-out-list)
15409 (setq single-out-list (delete signal-name single-out-list))
15410 (add-to-list 'multi-out-list signal-name))
15411 ((not (member signal-name multi-out-list))
15412 (add-to-list 'single-out-list signal-name))))
15413 (unless (match-string 1)
15414 (setq port-alist (cdr port-alist)))
15415 (vhdl-forward-syntactic-ws))
15416 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15417 (nreverse signal-alist)) inst-alist)))
15418 ;; prepare signal insertion
15419 (vhdl-goto-marker arch-decl-pos)
15421 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15422 (setq signal-pos (point-marker))
15423 (while (progn (vhdl-forward-syntactic-ws)
15424 (looking-at "signal\\>"))
15425 (beginning-of-line 2)
15426 (delete-region signal-pos (point)))
15427 (setq signal-beg-pos signal-pos)
15428 ;; open entity file
15429 (when (file-exists-p ent-file-name)
15430 (find-file ent-file-name))
15431 (goto-char (point-min))
15432 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15433 (error "ERROR: Entity not found: \"%s\"" ent-name))
15434 ;; prepare generic clause insertion
15435 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15437 (goto-char (match-beginning 0))
15438 (indent-to vhdl-basic-offset)
15439 (insert "generic ();\n\n")
15442 (setq generic-pos (point-marker))
15443 (forward-sexp) (end-of-line)
15444 (delete-region generic-pos (point)) (delete-char 1)
15448 (indent-to (* 2 vhdl-basic-offset))
15449 (insert "-- global generics\n"))
15450 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15451 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15452 ;; prepare port clause insertion
15453 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15455 (goto-char (match-beginning 0))
15456 (indent-to vhdl-basic-offset)
15457 (insert "port ();\n\n")
15460 (setq port-in-pos (point-marker))
15461 (forward-sexp) (end-of-line)
15462 (delete-region port-in-pos (point)) (delete-char 1)
15464 (when (or multi-in-list multi-out-list)
15466 (indent-to (* 2 vhdl-basic-offset))
15467 (insert "-- global ports\n"))
15468 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15469 port-out-pos (point-marker) port-inst-pos (point-marker)
15470 port-end-pos (point-marker))
15471 ;; insert generics, ports and signals
15472 (setq inst-alist (nreverse inst-alist))
15474 (setq inst-name (nth 0 (car inst-alist))
15475 constant-alist (nth 1 (car inst-alist))
15476 signal-alist (nth 2 (car inst-alist))
15477 constant-temp-pos generic-inst-pos
15478 port-temp-pos port-inst-pos
15479 signal-temp-pos signal-pos)
15481 (while constant-alist
15482 (setq constant-name (downcase (caar constant-alist))
15483 constant-entry (car constant-alist))
15484 (cond ((member constant-name written-list)
15486 ((member constant-name multi-list)
15487 (vhdl-goto-marker generic-pos)
15488 (setq generic-end-pos
15491 (vhdl-compose-insert-generic constant-entry)))
15492 (setq generic-pos (point-marker))
15493 (add-to-list 'written-list constant-name))
15496 (vhdl-max-marker generic-inst-pos generic-pos))
15497 (setq generic-end-pos
15498 (vhdl-compose-insert-generic constant-entry))
15499 (setq generic-inst-pos (point-marker))
15500 (add-to-list 'written-list constant-name)))
15501 (setq constant-alist (cdr constant-alist)))
15502 (when (/= constant-temp-pos generic-inst-pos)
15503 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15504 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15505 (insert "-- generics for \"" inst-name "\"\n")
15506 (vhdl-goto-marker generic-inst-pos))
15507 ;; ports and signals
15508 (while signal-alist
15509 (setq signal-name (downcase (caar signal-alist))
15510 signal-entry (car signal-alist))
15511 (cond ((member signal-name written-list)
15513 ((member signal-name multi-in-list)
15514 (vhdl-goto-marker port-in-pos)
15517 port-end-pos (vhdl-compose-insert-port signal-entry)))
15518 (setq port-in-pos (point-marker))
15519 (add-to-list 'written-list signal-name))
15520 ((member signal-name multi-out-list)
15521 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15524 port-end-pos (vhdl-compose-insert-port signal-entry)))
15525 (setq port-out-pos (point-marker))
15526 (add-to-list 'written-list signal-name))
15527 ((or (member signal-name single-in-list)
15528 (member signal-name single-out-list))
15532 (vhdl-max-marker port-out-pos port-in-pos)))
15533 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15534 (setq port-inst-pos (point-marker))
15535 (add-to-list 'written-list signal-name))
15536 ((equal (upcase (nth 2 signal-entry)) "OUT")
15537 (vhdl-goto-marker signal-pos)
15538 (vhdl-compose-insert-signal signal-entry)
15539 (setq signal-pos (point-marker))
15540 (add-to-list 'written-list signal-name)))
15541 (setq signal-alist (cdr signal-alist)))
15542 (when (/= port-temp-pos port-inst-pos)
15544 (vhdl-max-marker port-temp-pos
15545 (vhdl-max-marker port-in-pos port-out-pos)))
15546 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15547 (insert "-- ports to \"" inst-name "\"\n")
15548 (vhdl-goto-marker port-inst-pos))
15549 (when (/= signal-temp-pos signal-pos)
15550 (vhdl-goto-marker signal-temp-pos)
15551 (insert "\n") (indent-to vhdl-basic-offset)
15552 (insert "-- outputs of \"" inst-name "\"\n")
15553 (vhdl-goto-marker signal-pos))
15554 (setq inst-alist (cdr inst-alist)))
15555 ;; finalize generic/port clause
15556 (vhdl-goto-marker generic-end-pos) (backward-char)
15557 (when (= generic-beg-pos generic-end-pos)
15558 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15559 (insert ";") (backward-char))
15561 (vhdl-goto-marker port-end-pos) (backward-char)
15562 (when (= port-beg-pos port-end-pos)
15563 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15564 (insert ";") (backward-char))
15566 ;; align everything
15567 (when vhdl-auto-align
15568 (vhdl-goto-marker generic-beg-pos)
15569 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15570 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15571 (vhdl-goto-marker signal-beg-pos)
15572 (vhdl-align-region-groups signal-beg-pos signal-pos))
15573 (switch-to-buffer (marker-buffer signal-beg-pos))
15574 (message "Wiring components...done")))))
15576 (defun vhdl-compose-insert-generic (entry)
15577 "Insert ENTRY as generic declaration."
15579 (indent-to (* 2 vhdl-basic-offset))
15580 (insert (nth 0 entry) " : " (nth 1 entry))
15581 (when (nth 2 entry)
15582 (insert " := " (nth 2 entry)))
15584 (setq pos (point-marker))
15585 (when (and vhdl-include-port-comments (nth 3 entry))
15586 (vhdl-comment-insert-inline (nth 3 entry) t))
15590 (defun vhdl-compose-insert-port (entry)
15591 "Insert ENTRY as port declaration."
15593 (indent-to (* 2 vhdl-basic-offset))
15594 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15595 (setq pos (point-marker))
15596 (when (and vhdl-include-port-comments (nth 4 entry))
15597 (vhdl-comment-insert-inline (nth 4 entry) t))
15601 (defun vhdl-compose-insert-signal (entry)
15602 "Insert ENTRY as signal declaration."
15603 (indent-to vhdl-basic-offset)
15604 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15605 (when (and vhdl-include-port-comments (nth 4 entry))
15606 (vhdl-comment-insert-inline (nth 4 entry) t))
15609 (defun vhdl-compose-components-package ()
15610 "Generate a package containing component declarations for all entities in the
15611 current project/directory."
15613 (vhdl-require-hierarchy-info)
15614 (let* ((project (vhdl-project-p))
15615 (pack-name (vhdl-get-components-package-name))
15617 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15618 "." (file-name-extension (buffer-file-name))))
15619 (ent-alist (aget vhdl-entity-alist
15620 (or project default-directory) t))
15621 (lazy-lock-minimum-size 0)
15622 clause-pos component-pos)
15623 (message "Generating components package \"%s\"..." pack-name)
15624 ;; open package file
15625 (when (and (file-exists-p pack-file-name)
15626 (not (y-or-n-p (concat "File \"" pack-file-name
15627 "\" exists; overwrite? "))))
15628 (error "ERROR: Generating components package...aborted"))
15629 (find-file pack-file-name)
15632 (if vhdl-compose-include-header
15633 (progn (vhdl-template-header
15634 (concat "Components package (generated by Emacs VHDL Mode "
15636 (goto-char (point-max)))
15637 (vhdl-comment-display-line) (insert "\n\n"))
15638 ;; insert std_logic_1164 package
15639 (vhdl-template-package-std-logic-1164)
15640 (insert "\n") (setq clause-pos (point-marker))
15641 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15642 ;; insert package declaration
15643 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15644 (vhdl-insert-keyword " IS\n\n")
15645 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15646 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15647 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15648 (indent-to vhdl-basic-offset)
15649 (setq component-pos (point-marker))
15650 (insert "\n\n") (vhdl-insert-keyword "END ")
15651 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15652 (insert pack-name ";\n\n")
15654 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15655 (vhdl-template-footer)
15656 (vhdl-comment-display-line) (insert "\n"))
15657 ;; insert component declarations
15659 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15660 (progn (goto-line (nth 3 (car ent-alist)))
15663 (goto-char component-pos)
15664 (vhdl-port-paste-component t)
15665 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15666 (setq component-pos (point-marker))
15667 (goto-char clause-pos)
15668 (vhdl-port-paste-context-clause pack-name)
15669 (setq clause-pos (point-marker))
15670 (setq ent-alist (cdr ent-alist)))
15671 (goto-char (point-min))
15673 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15674 pack-name pack-file-name)))
15677 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15678 ;;; Compilation / Makefile generation
15679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15680 ;; (using `compile.el')
15682 (defun vhdl-makefile-name ()
15683 "Return the Makefile name of the current project or the current compiler if
15684 no project is defined."
15685 (let ((project-alist (aget vhdl-project-alist vhdl-project))
15686 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
15687 (vhdl-replace-string
15688 (cons "\\(.*\\)\n\\(.*\\)"
15689 (or (nth 8 project-alist) (nth 8 compiler-alist)))
15690 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
15692 (defun vhdl-compile-directory ()
15693 "Return the directory where compilation/make should be run."
15694 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
15695 (compiler (aget vhdl-compiler-alist vhdl-compiler))
15696 (directory (vhdl-resolve-env-variable
15698 (vhdl-replace-string
15699 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
15700 (nth 6 compiler)))))
15701 (file-name-as-directory
15702 (if (file-name-absolute-p directory)
15704 (expand-file-name directory (vhdl-default-directory))))))
15706 (defun vhdl-uniquify (in-list)
15707 "Remove duplicate elements from IN-LIST."
15710 (add-to-list 'out-list (car in-list))
15711 (setq in-list (cdr in-list)))
15714 (defun vhdl-set-compiler (name)
15715 "Set current compiler to NAME."
15717 (list (let ((completion-ignore-case t))
15718 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
15719 (if (assoc name vhdl-compiler-alist)
15720 (progn (setq vhdl-compiler name)
15721 (message "Current compiler: \"%s\"" vhdl-compiler))
15722 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
15724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15727 (defun vhdl-compile-init ()
15728 "Initialize for compilation."
15729 (when (or (null compilation-error-regexp-alist)
15730 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
15731 compilation-error-regexp-alist)))
15732 ;; `compilation-error-regexp-alist'
15733 (let ((commands-alist vhdl-compiler-alist)
15734 regexp-alist sublist)
15735 (while commands-alist
15736 (setq sublist (nth 11 (car commands-alist)))
15737 (unless (or (equal "" (car sublist))
15738 (assoc (car sublist) regexp-alist))
15739 (setq regexp-alist (cons (list (nth 0 sublist)
15740 (if (= 0 (nth 1 sublist))
15741 (if vhdl-xemacs 9 nil)
15743 (nth 2 sublist) (nth 3 sublist))
15745 (setq commands-alist (cdr commands-alist)))
15746 (setq compilation-error-regexp-alist
15747 (append compilation-error-regexp-alist (nreverse regexp-alist))))
15748 ;; `compilation-file-regexp-alist'
15749 (let ((commands-alist vhdl-compiler-alist)
15750 regexp-alist sublist)
15751 ;; matches vhdl-mode file name output
15752 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
15753 (while commands-alist
15754 (setq sublist (nth 12 (car commands-alist)))
15755 (unless (or (equal "" (car sublist))
15756 (assoc (car sublist) regexp-alist))
15757 (setq regexp-alist (cons sublist regexp-alist)))
15758 (setq commands-alist (cdr commands-alist)))
15759 (setq compilation-file-regexp-alist
15760 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
15762 (defvar vhdl-compile-file-name nil
15763 "Name of file to be compiled.")
15765 (defun vhdl-compile-print-file-name ()
15766 "Function called within `compile' to print out file name for compilers that
15767 do not print any file names."
15768 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
15770 (defun vhdl-get-compile-options (project compiler file-name
15771 &optional file-options-only)
15772 "Get compiler options. Returning nil means do not compile this file."
15773 (let* ((compiler-options (nth 1 compiler))
15774 (project-entry (aget (nth 4 project) vhdl-compiler))
15775 (project-options (nth 0 project-entry))
15776 (exception-list (and file-name (nth 2 project-entry)))
15777 (work-library (vhdl-work-library))
15778 (case-fold-search nil)
15780 (while (and exception-list
15781 (not (string-match (caar exception-list) file-name)))
15782 (setq exception-list (cdr exception-list)))
15783 (if (and exception-list (not (cdar exception-list)))
15785 (if (and file-options-only (not exception-list))
15787 (setq file-options (cdar exception-list))
15788 ;; insert library name in compiler-specific options
15789 (setq compiler-options
15790 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
15792 ;; insert compiler-specific options in project-specific options
15793 (when project-options
15794 (setq project-options
15795 (vhdl-replace-string
15796 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15797 (concat work-library "\n" compiler-options))))
15798 ;; insert project-specific options in file-specific options
15801 (vhdl-replace-string
15802 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
15803 (concat work-library "\n" compiler-options "\n"
15804 project-options))))
15806 (or file-options project-options compiler-options)))))
15808 (defun vhdl-get-make-options (project compiler)
15809 "Get make options."
15810 (let* ((compiler-options (nth 3 compiler))
15811 (project-entry (aget (nth 4 project) vhdl-compiler))
15812 (project-options (nth 1 project-entry))
15813 (makefile-name (vhdl-makefile-name)))
15814 ;; insert Makefile name in compiler-specific options
15815 (setq compiler-options
15816 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
15818 ;; insert compiler-specific options in project-specific options
15819 (when project-options
15820 (setq project-options
15821 (vhdl-replace-string
15822 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15823 (concat makefile-name "\n" compiler-options))))
15825 (or project-options compiler-options)))
15827 (defun vhdl-compile ()
15828 "Compile current buffer using the VHDL compiler specified in
15831 (vhdl-compile-init)
15832 (let* ((project (aget vhdl-project-alist vhdl-project))
15833 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
15834 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15835 (command (nth 0 compiler))
15836 (file-name (buffer-file-name))
15837 (options (vhdl-get-compile-options project compiler file-name))
15838 (default-directory (vhdl-compile-directory))
15839 compilation-process-setup-function)
15840 (unless (file-directory-p default-directory)
15841 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15842 ;; put file name into quotes if it contains spaces
15843 (when (string-match " " file-name)
15844 (setq file-name (concat "\"" file-name "\"")))
15845 ;; print out file name if compiler does not
15846 (setq vhdl-compile-file-name (buffer-file-name))
15847 (when (and (= 0 (nth 1 (nth 10 compiler)))
15848 (= 0 (nth 1 (nth 11 compiler))))
15849 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
15853 (compile (concat command " " options " " file-name)))
15854 (vhdl-warning "Your project settings tell me not to compile this file"))))
15856 (defun vhdl-make (&optional target)
15857 "Call make command for compilation of all updated source files (requires
15858 `Makefile'). Optional argument TARGET allows to compile the design
15859 specified by a target."
15861 (vhdl-compile-init)
15862 (let* ((project (aget vhdl-project-alist vhdl-project))
15863 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15864 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15865 (command (nth 2 compiler))
15866 (options (vhdl-get-make-options project compiler))
15867 (default-directory (vhdl-compile-directory)))
15868 (unless (file-directory-p default-directory)
15869 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15871 (compile (concat (if (equal command "") "make" command)
15872 " " options " " target))))
15874 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15875 ;; Makefile generation
15877 (defun vhdl-generate-makefile ()
15878 "Generate `Makefile'."
15880 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15881 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15882 (command (nth 4 compiler)))
15883 ;; generate makefile
15885 (let ((default-directory (vhdl-compile-directory)))
15886 (compile (vhdl-replace-string
15887 (cons "\\(.*\\) \\(.*\\)" command)
15888 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
15889 (vhdl-generate-makefile-1))))
15891 (defun vhdl-get-packages (lib-alist work-library)
15892 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
15895 (when (equal (downcase (caar lib-alist)) (downcase work-library))
15896 (setq pack-list (cons (cdar lib-alist) pack-list)))
15897 (setq lib-alist (cdr lib-alist)))
15900 (defun vhdl-generate-makefile-1 ()
15901 "Generate Makefile for current project or directory."
15902 ;; scan hierarchy if required
15903 (if (vhdl-project-p)
15904 (unless (or (assoc vhdl-project vhdl-file-alist)
15905 (vhdl-load-cache vhdl-project))
15906 (vhdl-scan-project-contents vhdl-project))
15907 (let ((directory (abbreviate-file-name default-directory)))
15908 (unless (or (assoc directory vhdl-file-alist)
15909 (vhdl-load-cache directory))
15910 (vhdl-scan-directory-contents directory))))
15911 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
15912 (project (vhdl-project-p))
15913 (ent-alist (aget vhdl-entity-alist (or project directory) t))
15914 (conf-alist (aget vhdl-config-alist (or project directory) t))
15915 (pack-alist (aget vhdl-package-alist (or project directory) t))
15916 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
15917 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
15918 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
15919 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
15920 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
15921 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
15922 (adjust-case (nth 5 regexp-list))
15923 (work-library (downcase (vhdl-work-library)))
15924 (compile-directory (expand-file-name (vhdl-compile-directory)
15925 default-directory))
15926 (makefile-name (vhdl-makefile-name))
15927 rule-alist arch-alist inst-alist
15928 target-list depend-list unit-list prim-list second-list subcomp-list
15929 lib-alist lib-body-alist pack-list all-pack-list
15930 ent-key ent-file-name arch-key arch-file-name ent-arch-key
15931 conf-key conf-file-name pack-key pack-file-name
15932 ent-entry arch-entry conf-entry pack-entry inst-entry
15933 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
15934 tmp-key tmp-list rule)
15935 ;; check prerequisites
15936 (unless (file-exists-p compile-directory)
15937 (make-directory compile-directory t))
15938 (unless regexp-list
15939 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
15941 (message "Generating makefile \"%s\"..." makefile-name)
15942 ;; rules for all entities
15943 (setq tmp-list ent-alist)
15945 (setq ent-entry (car ent-alist)
15946 ent-key (nth 0 ent-entry))
15947 (when (nth 2 ent-entry)
15948 (setq ent-file-name (file-relative-name
15949 (nth 2 ent-entry) compile-directory)
15950 arch-alist (nth 4 ent-entry)
15951 lib-alist (nth 5 ent-entry)
15952 rule (aget rule-alist ent-file-name)
15953 target-list (nth 0 rule)
15954 depend-list (nth 1 rule)
15957 (setq tmp-key (vhdl-replace-string
15958 ent-regexp (funcall adjust-case ent-key)))
15959 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
15960 ;; rule target for this entity
15961 (setq target-list (cons ent-key target-list))
15962 ;; rule dependencies for all used packages
15963 (setq pack-list (vhdl-get-packages lib-alist work-library))
15964 (setq depend-list (append depend-list pack-list))
15965 (setq all-pack-list pack-list)
15967 (aput 'rule-alist ent-file-name (list target-list depend-list))
15968 ;; rules for all corresponding architectures
15970 (setq arch-entry (car arch-alist)
15971 arch-key (nth 0 arch-entry)
15972 ent-arch-key (concat ent-key "-" arch-key)
15973 arch-file-name (file-relative-name (nth 2 arch-entry)
15975 inst-alist (nth 4 arch-entry)
15976 lib-alist (nth 5 arch-entry)
15977 rule (aget rule-alist arch-file-name)
15978 target-list (nth 0 rule)
15979 depend-list (nth 1 rule))
15980 (setq tmp-key (vhdl-replace-string
15982 (funcall adjust-case (concat arch-key " " ent-key))))
15984 (cons (cons ent-arch-key tmp-key) unit-list))
15985 (setq second-list (cons ent-arch-key second-list))
15986 ;; rule target for this architecture
15987 (setq target-list (cons ent-arch-key target-list))
15988 ;; rule dependency for corresponding entity
15989 (setq depend-list (cons ent-key depend-list))
15990 ;; rule dependencies for contained component instantiations
15992 (setq inst-entry (car inst-alist))
15993 (when (or (null (nth 8 inst-entry))
15994 (equal (downcase (nth 8 inst-entry)) work-library))
15995 (setq inst-ent-key (or (nth 7 inst-entry)
15996 (nth 5 inst-entry)))
15997 (setq depend-list (cons inst-ent-key depend-list)
15998 subcomp-list (cons inst-ent-key subcomp-list)))
15999 (setq inst-alist (cdr inst-alist)))
16000 ;; rule dependencies for all used packages
16001 (setq pack-list (vhdl-get-packages lib-alist work-library))
16002 (setq depend-list (append depend-list pack-list))
16003 (setq all-pack-list (append all-pack-list pack-list))
16005 (aput 'rule-alist arch-file-name (list target-list depend-list))
16006 (setq arch-alist (cdr arch-alist)))
16007 (setq prim-list (cons (list ent-key second-list
16008 (append subcomp-list all-pack-list))
16010 (setq ent-alist (cdr ent-alist)))
16011 (setq ent-alist tmp-list)
16012 ;; rules for all configurations
16013 (setq tmp-list conf-alist)
16015 (setq conf-entry (car conf-alist)
16016 conf-key (nth 0 conf-entry)
16017 conf-file-name (file-relative-name
16018 (nth 2 conf-entry) compile-directory)
16019 ent-key (nth 4 conf-entry)
16020 arch-key (nth 5 conf-entry)
16021 inst-alist (nth 6 conf-entry)
16022 lib-alist (nth 7 conf-entry)
16023 rule (aget rule-alist conf-file-name)
16024 target-list (nth 0 rule)
16025 depend-list (nth 1 rule)
16026 subcomp-list (list ent-key))
16027 (setq tmp-key (vhdl-replace-string
16028 conf-regexp (funcall adjust-case conf-key)))
16029 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16030 ;; rule target for this configuration
16031 (setq target-list (cons conf-key target-list))
16032 ;; rule dependency for corresponding entity and architecture
16034 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16035 ;; rule dependencies for used packages
16036 (setq pack-list (vhdl-get-packages lib-alist work-library))
16037 (setq depend-list (append depend-list pack-list))
16038 ;; rule dependencies for contained component configurations
16040 (setq inst-entry (car inst-alist))
16041 (setq inst-ent-key (nth 2 inst-entry)
16042 ; comp-arch-key (nth 2 inst-entry))
16043 inst-conf-key (nth 4 inst-entry))
16044 (when (equal (downcase (nth 5 inst-entry)) work-library)
16046 (setq depend-list (cons inst-ent-key depend-list)
16047 subcomp-list (cons inst-ent-key subcomp-list)))
16048 ; (when comp-arch-key
16049 ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16051 (when inst-conf-key
16052 (setq depend-list (cons inst-conf-key depend-list)
16053 subcomp-list (cons inst-conf-key subcomp-list))))
16054 (setq inst-alist (cdr inst-alist)))
16056 (aput 'rule-alist conf-file-name (list target-list depend-list))
16057 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16059 (setq conf-alist (cdr conf-alist)))
16060 (setq conf-alist tmp-list)
16061 ;; rules for all packages
16062 (setq tmp-list pack-alist)
16064 (setq pack-entry (car pack-alist)
16065 pack-key (nth 0 pack-entry)
16067 (when (nth 2 pack-entry)
16068 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16070 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16071 rule (aget rule-alist pack-file-name)
16072 target-list (nth 0 rule) depend-list (nth 1 rule))
16073 (setq tmp-key (vhdl-replace-string
16074 pack-regexp (funcall adjust-case pack-key)))
16075 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16076 ;; rule target for this package
16077 (setq target-list (cons pack-key target-list))
16078 ;; rule dependencies for all used packages
16079 (setq pack-list (vhdl-get-packages lib-alist work-library))
16080 (setq depend-list (append depend-list pack-list))
16081 (setq all-pack-list pack-list)
16083 (aput 'rule-alist pack-file-name (list target-list depend-list))
16084 ;; rules for this package's body
16085 (when (nth 7 pack-entry)
16086 (setq pack-body-key (concat pack-key "-body")
16087 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16089 rule (aget rule-alist pack-body-file-name)
16090 target-list (nth 0 rule)
16091 depend-list (nth 1 rule))
16092 (setq tmp-key (vhdl-replace-string
16093 pack-body-regexp (funcall adjust-case pack-key)))
16095 (cons (cons pack-body-key tmp-key) unit-list))
16096 ;; rule target for this package's body
16097 (setq target-list (cons pack-body-key target-list))
16098 ;; rule dependency for corresponding package declaration
16099 (setq depend-list (cons pack-key depend-list))
16100 ;; rule dependencies for all used packages
16101 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16102 (setq depend-list (append depend-list pack-list))
16103 (setq all-pack-list (append all-pack-list pack-list))
16105 (aput 'rule-alist pack-body-file-name
16106 (list target-list depend-list)))
16108 (cons (list pack-key (when pack-body-key (list pack-body-key))
16111 (setq pack-alist (cdr pack-alist)))
16112 (setq pack-alist tmp-list)
16113 ;; generate Makefile
16114 (let* ((project (aget vhdl-project-alist project))
16115 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16116 (compiler-id (nth 9 compiler))
16118 (vhdl-resolve-env-variable
16119 (vhdl-replace-string
16120 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16122 (makefile-path-name (expand-file-name
16123 makefile-name compile-directory))
16124 (orig-buffer (current-buffer))
16125 cell second-list subcomp-list options unit-key unit-name)
16127 (setq unit-list (vhdl-sort-alist unit-list))
16128 (setq prim-list (vhdl-sort-alist prim-list))
16129 (setq tmp-list rule-alist)
16130 (while tmp-list ; pre-sort rule targets
16131 (setq cell (cdar tmp-list))
16132 (setcar cell (sort (car cell) 'string<))
16133 (setq tmp-list (cdr tmp-list)))
16134 (setq rule-alist ; sort by first rule target
16136 (function (lambda (a b)
16137 (string< (car (cadr a)) (car (cadr b)))))))
16138 ;; open and clear Makefile
16139 (set-buffer (find-file-noselect makefile-path-name t t))
16141 (insert "# -*- Makefile -*-\n"
16142 "### " (file-name-nondirectory makefile-name)
16143 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16146 (insert "\n# Project : " (nth 0 project))
16147 (insert "\n# Directory : \"" directory "\""))
16148 (insert "\n# Platform : " vhdl-compiler
16149 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16150 (user-login-name) "\n")
16151 ;; insert compile and option variable settings
16152 (insert "\n\n# Define compilation command and options\n"
16153 "\nCOMPILE = " (nth 0 compiler)
16154 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16156 ;; insert library paths
16157 (setq library-directory
16158 (directory-file-name
16159 (if (file-name-absolute-p library-directory)
16161 (file-relative-name
16162 (expand-file-name library-directory directory)
16163 compile-directory))))
16164 (insert "\n\n# Define library paths\n"
16165 "\nLIBRARY-" work-library " = " library-directory "\n")
16166 ;; insert variable definitions for all library unit files
16167 (insert "\n\n# Define library unit files\n")
16168 (setq tmp-list unit-list)
16170 (insert "\nUNIT-" work-library "-" (caar unit-list)
16171 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16172 (setq unit-list (cdr unit-list)))
16173 ;; insert variable definition for list of all library unit files
16174 (insert "\n\n\n# Define list of all library unit files\n"
16176 (setq unit-list tmp-list)
16178 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16179 (setq unit-list (cdr unit-list)))
16181 (setq unit-list tmp-list)
16182 ;; insert `make all' rule
16183 (insert "\n\n\n# Rule for compiling entire design\n"
16186 " \\\n\t\t$(ALL_UNITS)\n")
16187 ;; insert `make clean' rule
16188 (insert "\n\n# Rule for cleaning entire design\n"
16190 "\n\t-rm -f $(ALL_UNITS)\n")
16191 ;; insert `make library' rule
16192 (insert "\n\n# Rule for creating library directory\n"
16194 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16195 "\n$(LIBRARY-" work-library ") :"
16197 (vhdl-replace-string
16198 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16199 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16201 ;; insert rule for each library unit
16202 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16204 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16206 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16207 (setq unit-key (caar prim-list)
16208 unit-name (or (nth 0 (aget ent-alist unit-key t))
16209 (nth 0 (aget conf-alist unit-key t))
16210 (nth 0 (aget pack-alist unit-key t))))
16211 (insert "\n" unit-key)
16212 (unless (equal unit-key unit-name)
16213 (insert " \\\n" unit-name))
16216 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16218 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16219 (setq second-list (cdr second-list)))
16220 (while subcomp-list
16221 (when (assoc (car subcomp-list) unit-list)
16222 (insert " \\\n\t\t" (car subcomp-list)))
16223 (setq subcomp-list (cdr subcomp-list)))
16225 (setq prim-list (cdr prim-list)))
16226 ;; insert rule for each library unit file
16227 (insert "\n\n# Rules for compiling single library unit files\n")
16229 (setq rule (car rule-alist))
16230 ;; get compiler options for this file
16232 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16233 ;; insert rule if file is supposed to be compiled
16234 (setq target-list (nth 1 rule)
16235 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16237 (setq tmp-list target-list)
16239 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16240 (if (cdr target-list) " \\" " :"))
16241 (setq target-list (cdr target-list)))
16242 (setq target-list tmp-list)
16243 ;; insert file name as first dependency
16244 (insert " \\\n\t\t" (nth 0 rule))
16245 ;; insert dependencies (except if also target or unit does not exist)
16247 (when (and (not (member (car depend-list) target-list))
16248 (assoc (car depend-list) unit-list))
16249 (insert " \\\n\t\t"
16250 "$(UNIT-" work-library "-" (car depend-list) ")"))
16251 (setq depend-list (cdr depend-list)))
16252 ;; insert compile command
16254 (insert "\n\t$(COMPILE) "
16255 (if (eq options 'default) "$(OPTIONS)" options) " "
16257 (setq tmp-list target-list)
16259 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16260 (if (cdr target-list) " \\" "\n"))
16261 (setq target-list (cdr target-list)))
16262 (setq target-list tmp-list))
16263 (setq rule-alist (cdr rule-alist)))
16264 (insert "\n\n### " makefile-name " ends here\n")
16265 ;; run Makefile generation hook
16266 (run-hooks 'vhdl-makefile-generation-hook)
16267 (message "Generating makefile \"%s\"...done" makefile-name)
16268 ;; save and close file
16269 (if (file-writable-p makefile-path-name)
16270 (progn (save-buffer)
16271 (kill-buffer (current-buffer))
16272 (set-buffer orig-buffer)
16273 (setq file-name-history
16274 (cons makefile-path-name file-name-history)))
16275 (vhdl-warning-when-idle
16276 (format "File not writable: \"%s\""
16277 (abbreviate-file-name makefile-path-name)))
16278 (switch-to-buffer (current-buffer))))))
16281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16284 ;; (using `reporter.el')
16286 (defconst vhdl-mode-help-address
16287 "Reto Zimmermann <reto@gnu.org>"
16288 "Address for VHDL Mode bug reports.")
16290 (defun vhdl-submit-bug-report ()
16291 "Submit via mail a bug report on VHDL Mode."
16293 ;; load in reporter
16295 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16296 (let ((reporter-prompt-for-summary-p t))
16297 (reporter-submit-bug-report
16298 vhdl-mode-help-address
16299 (concat "VHDL Mode " vhdl-version)
16301 ;; report all important user options
16302 'vhdl-offsets-alist
16303 'vhdl-comment-only-line-offset
16305 'vhdl-electric-mode
16307 'vhdl-indent-tabs-mode
16308 'vhdl-project-alist
16310 'vhdl-project-file-name
16311 'vhdl-project-auto-load
16313 'vhdl-compiler-alist
16315 'vhdl-compile-use-local-error-regexp
16316 'vhdl-makefile-generation-hook
16317 'vhdl-default-library
16320 'vhdl-upper-case-keywords
16321 'vhdl-upper-case-types
16322 'vhdl-upper-case-attributes
16323 'vhdl-upper-case-enum-values
16324 'vhdl-upper-case-constants
16325 'vhdl-use-direct-instantiation
16326 'vhdl-entity-file-name
16327 'vhdl-architecture-file-name
16328 'vhdl-package-file-name
16329 'vhdl-file-name-case
16330 'vhdl-electric-keywords
16331 'vhdl-optional-labels
16332 'vhdl-insert-empty-lines
16333 'vhdl-argument-list-indent
16334 'vhdl-association-list-with-formals
16335 'vhdl-conditions-in-parenthesis
16341 'vhdl-copyright-string
16342 'vhdl-platform-spec
16344 'vhdl-modify-date-prefix-string
16345 'vhdl-modify-date-on-saving
16347 'vhdl-reset-active-high
16348 'vhdl-clock-rising-edge
16349 'vhdl-clock-edge-condition
16353 'vhdl-include-port-comments
16354 'vhdl-include-direction-comments
16355 'vhdl-include-type-comments
16356 'vhdl-include-group-comments
16357 'vhdl-actual-port-name
16358 'vhdl-instance-name
16359 'vhdl-testbench-entity-name
16360 'vhdl-testbench-architecture-name
16361 'vhdl-testbench-configuration-name
16362 'vhdl-testbench-dut-name
16363 'vhdl-testbench-include-header
16364 'vhdl-testbench-declarations
16365 'vhdl-testbench-statements
16366 'vhdl-testbench-initialize-signals
16367 'vhdl-testbench-include-library
16368 'vhdl-testbench-include-configuration
16369 'vhdl-testbench-create-files
16370 'vhdl-compose-create-files
16371 'vhdl-compose-include-header
16372 'vhdl-compose-architecture-name
16373 'vhdl-components-package-name
16374 'vhdl-use-components-package
16375 'vhdl-self-insert-comments
16376 'vhdl-prompt-for-comments
16377 'vhdl-inline-comment-column
16378 'vhdl-end-comment-column
16381 'vhdl-align-group-separate
16382 'vhdl-align-same-indent
16383 'vhdl-highlight-keywords
16384 'vhdl-highlight-names
16385 'vhdl-highlight-special-words
16386 'vhdl-highlight-forbidden-words
16387 'vhdl-highlight-verilog-keywords
16388 'vhdl-highlight-translate-off
16389 'vhdl-highlight-case-sensitive
16390 'vhdl-special-syntax-alist
16391 'vhdl-forbidden-words
16392 'vhdl-forbidden-syntax
16393 'vhdl-directive-keywords
16394 'vhdl-speedbar-auto-open
16395 'vhdl-speedbar-display-mode
16396 'vhdl-speedbar-scan-limit
16397 'vhdl-speedbar-jump-to-unit
16398 'vhdl-speedbar-update-on-saving
16399 'vhdl-speedbar-save-cache
16400 'vhdl-speedbar-cache-file-name
16402 'vhdl-source-file-menu
16403 'vhdl-hideshow-menu
16404 'vhdl-hide-all-init
16405 'vhdl-print-two-column
16406 'vhdl-print-customize-faces
16407 'vhdl-intelligent-tab
16408 'vhdl-indent-syntax-based
16409 'vhdl-word-completion-case-sensitive
16410 'vhdl-word-completion-in-minibuffer
16411 'vhdl-underscore-is-part-of-word
16416 (if vhdl-special-indent-hook
16417 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16418 "vhdl-special-indent-hook is set to '"
16419 (format "%s" vhdl-special-indent-hook)
16420 ".\nPerhaps this is your problem?\n"
16421 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16431 (defconst vhdl-doc-release-notes nil
16433 Release Notes for VHDL Mode 3.32
16434 ================================
16437 - Enhanced Features
16445 STRUCTURAL COMPOSITION:
16446 - Enables simple structural composition similar to graphical editors.
16447 Simplifies the creation of higher design levels where subcomponents
16448 are simply sticked together:
16449 1. Create a skeleton for a new component
16450 2. Place subcomponents in it directly from the hierarchy browser
16451 3. Automatically connect all subcomponents and create the ports
16452 for the new component (based on names of actual ports)
16453 - Automatic generation of a components package (package containing
16454 component declarations for all entities).
16455 - Find more information in the online documentation (`C-c C-h').
16458 - Reverse direction of ports (useful for testbenches).
16460 SUBPROGRAM TRANSLATION:
16461 - Copy/paste of subprogram interfaces (similar to port translation).
16464 - Condense code using code-sensitive block filling.
16467 - Calculate number of code lines and statements in a buffer.
16473 TESTBENCH GENERATION:
16474 - Enhanced templates and user option default values.
16476 Emacs 21 compatibility/enhancements:
16477 - `lazy-lock-mode' is not used anymore (built-in `jit-lock-mode' is faster).
16479 And many other minor fixes and enhancements.
16485 `vhdl-project-file-name': (enhanced)
16486 Include user name in project setup file name.
16487 `vhdl-speedbar-cache-file-name': (enhanced, changed default)
16488 Include user name in cache file name.
16489 `vhdl-default-library': (new)
16490 Default working library if no project is active.
16491 `vhdl-architecture-file-name': (new)
16492 Specify how the architecture file name is obtained.
16493 `vhdl-package-file-name': (new)
16494 Specify how the package file name is obtained.
16495 `vhdl-file-name-case': (new)
16496 Allows to change case when deriving file names.
16497 `vhdl-compose-create-files': (new)
16498 Specify whether new files should be created for a new component.
16499 `vhdl-compose-include-header': (new)
16500 Specify whether a header is included in a new component's file.
16501 `vhdl-compose-architecture-name': (new)
16502 Specify how a new component's architecture name is obtained.
16503 `vhdl-components-package-name': (new)
16504 Specify how the name for the components package is obtained.
16505 `vhdl-use-components-package': (new)
16506 Specify whether component declarations go in a components package.
16507 `vhdl-use-direct-instantiation': (new)
16508 Specify whether to use VHDL'93 direct component instantiation.
16509 `vhdl-instance-name': (changed default)
16510 Allows insertion of a running number to generate unique instance names.
16511 `vhdl-testbench-entity-header', `vhdl-testbench-architecture-header':(obsolete)
16512 Headers are now automatically derived from the standard header.
16513 `vhdl-testbench-include-header': (new)
16514 Specify whether a header is included in testbench files.
16515 `vhdl-testbench-declaration', `vhdl-testbench-statements': (changed default)
16516 Non-empty default values for more complete testbench templates.
16522 - Changed key binding for `vhdl-comment-uncomment-region': `C-c c'
16523 (`C-c C-c ...' is now used for structural composition).
16525 - Automatic buffer highlighting (font-lock) is now controlled by option
16526 `global-font-lock-mode' in GNU Emacs (`font-lock-auto-fontify' in XEmacs).
16527 \(Important: You MUST customize this option in order to turn automatic
16528 buffer highlighting on.)
16532 (defconst vhdl-doc-keywords nil
16534 Reserved words in VHDL
16535 ----------------------
16537 VHDL'93 (IEEE Std 1076-1993):
16538 `vhdl-93-keywords' : keywords
16539 `vhdl-93-types' : standardized types
16540 `vhdl-93-attributes' : standardized attributes
16541 `vhdl-93-enum-values' : standardized enumeration values
16542 `vhdl-93-functions' : standardized functions
16543 `vhdl-93-packages' : standardized packages and libraries
16545 VHDL-AMS (IEEE Std 1076.1):
16546 `vhdl-ams-keywords' : keywords
16547 `vhdl-ams-types' : standardized types
16548 `vhdl-ams-attributes' : standardized attributes
16549 `vhdl-ams-enum-values' : standardized enumeration values
16550 `vhdl-ams-functions' : standardized functions
16552 Math Packages (IEEE Std 1076.2):
16553 `vhdl-math-types' : standardized types
16554 `vhdl-math-constants' : standardized constants
16555 `vhdl-math-functions' : standardized functions
16556 `vhdl-math-packages' : standardized packages
16559 `vhdl-verilog-keywords' : Verilog reserved words
16561 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16564 (defconst vhdl-doc-coding-style nil
16566 For VHDL coding style and naming convention guidelines, see the following
16570 \"VHDL Coding Styles and Methodologies\".
16571 Kluwer Academic Publishers, 1999.
16572 http://members.aol.com/vhdlcohen/vhdl/
16574 \[2] Michael Keating and Pierre Bricaud.
16575 \"Reuse Methodology Manual, Second Edition\".
16576 Kluwer Academic Publishers, 1999.
16577 http://www.openmore.com/openmore/rmm2.html
16579 \[3] European Space Agency.
16580 \"VHDL Modelling Guidelines\".
16581 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16583 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16584 to visually support naming conventions.")
16587 (defun vhdl-version ()
16588 "Echo the current version of VHDL Mode in the minibuffer."
16590 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
16591 (vhdl-keep-region-active))
16593 (defun vhdl-doc-variable (variable)
16594 "Display VARIABLE's documentation in *Help* buffer."
16596 (unless vhdl-xemacs
16597 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16598 (with-output-to-temp-buffer (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16599 (princ (documentation-property variable 'variable-documentation))
16600 (with-current-buffer standard-output
16602 (print-help-return-message)))
16604 (defun vhdl-doc-mode ()
16605 "Display VHDL Mode documentation in *Help* buffer."
16607 (unless vhdl-xemacs
16608 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16609 (with-output-to-temp-buffer (if (fboundp 'help-buffer) (help-buffer) "*Help*")
16612 (princ (documentation 'vhdl-mode))
16613 (with-current-buffer standard-output
16615 (print-help-return-message)))
16618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16620 (provide 'vhdl-mode)
16622 ;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
16623 ;;; vhdl-mode.el ends here