(compilation-error, compilation-warning)
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
CommitLineData
d2ddb974
KH
1;;; vhdl-mode.el --- major mode for editing VHDL code
2
034babe1 3;; Copyright (C) 1992-2003, 2004, 2005 Free Software Foundation, Inc.
3dcb36b7
JB
4
5;; Authors: Reto Zimmermann <reto@gnu.org>
6;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
0a2e512a 7;; Maintainer: Reto Zimmermann <reto@gnu.org>
5eabfe72 8;; Keywords: languages vhdl
0a2e512a 9;; WWW: http://opensource.ethz.ch/emacs/vhdl-mode.html
3dcb36b7 10
0a2e512a 11(defconst vhdl-version "3.33.6"
3dcb36b7
JB
12 "VHDL Mode version number.")
13
0a2e512a 14(defconst vhdl-time-stamp "2005-08-30"
3dcb36b7 15 "VHDL Mode time stamp for last update.")
d2ddb974
KH
16
17;; This file is part of GNU Emacs.
18
19;; GNU Emacs is free software; you can redistribute it and/or modify
20;; it under the terms of the GNU General Public License as published by
21;; the Free Software Foundation; either version 2, or (at your option)
22;; any later version.
23
24;; GNU Emacs is distributed in the hope that it will be useful,
25;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27;; GNU General Public License for more details.
28
29;; You should have received a copy of the GNU General Public License
30;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
31;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
32;; Boston, MA 02110-1301, USA.
d2ddb974 33
5eabfe72 34;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 35;;; Commentary:
5eabfe72 36;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
37
38;; This package provides an Emacs major mode for editing VHDL code.
39;; It includes the following features:
40
3dcb36b7
JB
41;; - Syntax highlighting
42;; - Indentation
43;; - Template insertion (electrification)
44;; - Insertion of file headers
5eabfe72 45;; - Insertion of user-specified models
3dcb36b7 46;; - Port translation / testbench generation
0a2e512a
RF
47;; - Structural composition
48;; - Configuration generation
3dcb36b7
JB
49;; - Sensitivity list updating
50;; - File browser
51;; - Design hierarchy browser
d2ddb974 52;; - Source file compilation (syntax analysis)
3dcb36b7
JB
53;; - Makefile generation
54;; - Code hiding
55;; - Word/keyword completion
56;; - Block commenting
57;; - Code fixing/alignment/beautification
58;; - Postscript printing
5eabfe72 59;; - VHDL'87/'93 and VHDL-AMS supported
3dcb36b7 60;; - Comprehensive menu
5eabfe72 61;; - Fully customizable
3dcb36b7 62;; - Works under GNU Emacs (recommended) and XEmacs
5eabfe72
KH
63
64;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 65;; Documentation
d2ddb974 66
3dcb36b7 67;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
d2ddb974 68
5eabfe72 69;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 70;; Emacs Versions
3dcb36b7 71
9e5538bc 72;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
3dcb36b7
JB
73;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
74
5eabfe72 75;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
76;; Installation
77
9e5538bc 78;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
3dcb36b7
JB
79
80;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
81;; or into an arbitrary directory that is added to the load path by the
82;; following line in your Emacs start-up file `.emacs':
83
84;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
d2ddb974 85
3dcb36b7
JB
86;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
87;; directory. Otherwise, byte-compile the source file:
88;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
89;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
90
91;; Add the following lines to the `site-start.el' file in the `site-lisp'
92;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
93;; (not required in Emacs 20.X):
94
95;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
96;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
97
98;; More detailed installation instructions are included in the official
99;; VHDL Mode distribution.
d2ddb974 100
5eabfe72 101;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 102;; Acknowledgements
d2ddb974
KH
103
104;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
5eabfe72 105;; and Steve Grout.
d2ddb974 106
5eabfe72 107;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
3dcb36b7 108;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
d2ddb974
KH
109
110;; Many thanks to all the users who sent me bug reports and enhancement
3dcb36b7
JB
111;; requests.
112;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
113;; enhancement suggestions and the fruitful discussions.
5eabfe72
KH
114;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
115;; Thanks to Ulf Klaperski for the indentation speedup hint.
116
117;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
118;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
119;; giving me the opportunity to develop this code.
120;; This work has been funded in part by MICROSWISS, a Microelectronics Program
121;; of the Swiss Government.
122
3dcb36b7 123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
124
125;;; Code:
126
3dcb36b7
JB
127;; XEmacs handling
128(defconst vhdl-xemacs (string-match "XEmacs" emacs-version)
129 "Non-nil if XEmacs is used.")
9e5538bc
TTN
130;; Emacs 21+ handling
131(defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not vhdl-xemacs))
0a2e512a
RF
132 "Non-nil if GNU Emacs 21, 22, ... is used.")
133(defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not vhdl-xemacs))
134 "Non-nil if GNU Emacs 22, ... is used.")
3dcb36b7 135
354617b5 136(defvar compilation-file-regexp-alist)
84c98ace
JB
137(defvar conf-alist)
138(defvar conf-entry)
139(defvar conf-key)
140(defvar ent-alist)
354617b5
JB
141(defvar itimer-version)
142(defvar lazy-lock-defer-contextually)
143(defvar lazy-lock-defer-on-scrolling)
144(defvar lazy-lock-defer-on-the-fly)
145
5eabfe72
KH
146;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
147;;; Variables
148;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 149
3dcb36b7 150;; help function for user options
5eabfe72
KH
151(defun vhdl-custom-set (variable value &rest functions)
152 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
153 (if (fboundp 'custom-set-default)
154 (custom-set-default variable value)
155 (set-default variable value))
156 (while functions
157 (when (fboundp (car functions)) (funcall (car functions)))
158 (setq functions (cdr functions))))
159
3dcb36b7
JB
160(defun vhdl-widget-directory-validate (widget)
161 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
162'/' or is empty)."
163 (let ((val (widget-value widget)))
164 (unless (string-match "^\\(\\|.*/\\)$" val)
165 (widget-put widget :error "Invalid directory entry: must end with '/'")
166 widget)))
167
168;; help string for user options
169(defconst vhdl-name-doc-string "
170
171FROM REGEXP is a regular expression matching the original name:
172 \".*\" matches the entire string
173 \"\\(...\\)\" matches a substring
174TO STRING specifies the string to be inserted as new name:
175 \"\\&\" means substitute entire matched text
176 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
177Examples:
178 \".*\" \"\\&\" inserts original string
179 \".*\" \"\\&_i\" attaches \"_i\" to original string
180 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
181 \".*\" \"foo\" inserts constant string \"foo\"
182 \".*\" \"\" inserts empty string")
183
5eabfe72
KH
184;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
185;; User variables
d2ddb974
KH
186
187(defgroup vhdl nil
188 "Customizations for VHDL Mode."
189 :prefix "vhdl-"
42dfe0ad 190 :group 'languages
0a2e512a 191; :version "21.2" ; comment out for XEmacs
5eabfe72 192 )
d2ddb974
KH
193
194(defgroup vhdl-mode nil
195 "Customizations for modes."
196 :group 'vhdl)
197
198(defcustom vhdl-electric-mode t
5eabfe72
KH
199 "*Non-nil enables electrification (automatic template generation).
200If nil, template generators can still be invoked through key bindings and
3dcb36b7 201menu. Is indicated in the modeline by \"/e\" after the mode name and can be
5eabfe72 202toggled by `\\[vhdl-electric-mode]'."
d2ddb974
KH
203 :type 'boolean
204 :group 'vhdl-mode)
205
206(defcustom vhdl-stutter-mode t
5eabfe72 207 "*Non-nil enables stuttering.
3dcb36b7 208Is indicated in the modeline by \"/s\" after the mode name and can be toggled
5eabfe72 209by `\\[vhdl-stutter-mode]'."
d2ddb974
KH
210 :type 'boolean
211 :group 'vhdl-mode)
212
5eabfe72
KH
213(defcustom vhdl-indent-tabs-mode nil
214 "*Non-nil means indentation can insert tabs.
d2ddb974
KH
215Overrides local variable `indent-tabs-mode'."
216 :type 'boolean
217 :group 'vhdl-mode)
218
219
220(defgroup vhdl-compile nil
221 "Customizations for compilation."
222 :group 'vhdl)
223
5eabfe72
KH
224(defcustom vhdl-compiler-alist
225 '(
3dcb36b7 226 ;; Cadence Leapfrog: cv -file test.vhd
5eabfe72 227 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
3dcb36b7
JB
228 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
229 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
230 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
231 ("\\1/entity" "\\2/\\1" "\\1/configuration"
232 "\\1/package" "\\1/body" downcase))
233 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
234 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
235 ;; (PLL_400X_TOP) is not declared [10.3].
236 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
237 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
238 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
0a2e512a
RF
239 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
240 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
5eabfe72 241 ;; Ikos Voyager: analyze test.vhd
3dcb36b7 242 ;; analyze test.vhd
5eabfe72 243 ;; E L4/C5: this library unit is inaccessible
3dcb36b7
JB
244 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
245 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
246 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
247 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
248 nil)
5eabfe72
KH
249 ;; ModelSim, Model Technology: vcom test.vhd
250 ;; ERROR: test.vhd(14): Unknown identifier: positiv
251 ;; WARNING[2]: test.vhd(85): Possible infinite loop
3dcb36b7
JB
252 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
253 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
254 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
255 ("\\(ERROR\\|WARNING\\|\\*\\* 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 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
259 ;; test.vhd:34: error message
260 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
261 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
262 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
263 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
264 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
5eabfe72
KH
265 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
266 ;; ERROR: test.vhd(24): near "dnd": expecting: END
267 ;; WARNING[4]: test.vhd(30): A space is required between ...
3dcb36b7
JB
268 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
269 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
270 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
271 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
272 "\\1/_primary.dat" "\\1/body.dat" downcase))
273 ;; Savant: scram -publish-cc test.vhd
274 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
275 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
276 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
277 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
278 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
279 "\\1_config.vhdl" "\\1_package.vhdl"
280 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
281 ;; Simili: vhdlp -work test.vhd
282 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
283 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
284 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
285 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
286 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
287 "\\1/prim.var" "\\1/_body.var" downcase))
288 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
289 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
290 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
291 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
292 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
293 nil)
294 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
5eabfe72 295 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
3dcb36b7
JB
296 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
297 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
298 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
299 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
300 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
301 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
302 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
303 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
304 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
305 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
306 ;; Synplify:
307 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
308 ("Synplify" "n/a" "n/a" "make" "-f \\1"
309 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
310 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
311 nil)
5eabfe72 312 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
313 ;; Compiling "test.vhd" line 1...
314 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
315 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
316 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
317 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
318 ("^ *Compiling \"\\(.+\\)\" " 1)
319 nil)
320 ;; VeriBest: vc vhdl test.vhd
321 ;; (no file name printed out!)
322 ;; 32: Z <= A and BitA ;
323 ;; ^^^^
324 ;; [Error] Name BITA is unknown
325 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
326 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
327 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
328 nil)
5eabfe72 329 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
330 ;; Compiling "test.vhd" line 1...
331 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
332 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
333 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
334 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
335 ("^ *Compiling \"\\(.+\\)\" " 1)
336 nil)
5eabfe72
KH
337 )
338 "*List of available VHDL compilers and their properties.
339Each list entry specifies the following items for a compiler:
340Compiler:
3dcb36b7
JB
341 Compiler name : name used in option `vhdl-compiler' to choose compiler
342 Compile command : command used for source file compilation
343 Compile options : compile options (\"\\1\" inserts library name)
344 Make command : command used for compilation using a Makefile
345 Make options : make options (\"\\1\" inserts Makefile name)
346 Generate Makefile: use built-in function or command to generate a Makefile
347 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
348 Library command : command to create library directory \(\"\\1\" inserts
349 library directory, \"\\2\" inserts library name)
350 Compile directory: where compilation is run and the Makefile is placed
351 Library directory: directory of default library
352 Makefile name : name of Makefile (default is \"Makefile\")
353 ID string : compiler identification string (see `vhdl-project-alist')
354Error message:
0a2e512a 355 Regexp : regular expression to match error messages (*)
3dcb36b7
JB
356 File subexp index: index of subexpression that matches the file name
357 Line subexp index: index of subexpression that matches the line number
358 Column subexp idx: index of subexpression that matches the column number
359File message:
5eabfe72 360 Regexp : regular expression to match a file name message
3dcb36b7
JB
361 File subexp index: index of subexpression that matches the file name
362Unit-to-file name mapping: mapping of library unit names to names of files
363 generated by the compiler (used for Makefile generation)
364 To string : string a name is mapped to (\"\\1\" inserts the unit name,
365 \"\\2\" inserts the entity name for architectures)
366 Case adjustment : adjust case of inserted unit names
367
0a2e512a 368\(*) The regular expression must match the error message starting from the
84c98ace 369 beginning of the line (but not necessarily to the end of the line).
0a2e512a 370
3dcb36b7
JB
371Compile options allows insertion of the library name (see `vhdl-project-alist')
372in order to set the compilers library option (e.g. \"vcom -work my_lib\").
373
374For Makefile generation, the built-in function can be used (requires
375specification of the unit-to-file name mapping). Alternatively, an
376external command can be specified. Work directory allows specification of
377an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
378used for Makefile generation). To use another library name than \"work\",
379customize `vhdl-project-alist'. The library command is inserted in Makefiles
380to automatically create the library directory if not existent.
381
382Compile options, compile directory, library directory, and Makefile name are
383overwritten by the project settings if a project is defined (see
384`vhdl-project-alist'). Directory paths are relative to the source file
385directory.
5eabfe72
KH
386
387Some compilers do not include the file name in the error message, but print
388out a file name message in advance. In this case, set \"File Subexp Index\"
3dcb36b7
JB
389under \"Error Message\" to 0 and fill out the \"File Message\" entries.
390If no file name at all is printed out, set both \"File Message\" entries to 0
391\(a default file name message will be printed out instead, does not work in
392XEmacs).
5eabfe72
KH
393
394A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
3dcb36b7 395assigning its name to option `vhdl-compiler'.
5eabfe72 396
3dcb36b7
JB
397Please send any missing or erroneous compiler properties to the maintainer for
398updating.
399
0a2e512a
RF
400NOTE: Activate new error and file message regexps and reflect the new setting
401 in the choice list of option `vhdl-compiler' by restarting Emacs."
3dcb36b7
JB
402 :type '(repeat
403 (list :tag "Compiler" :indent 2
404 (string :tag "Compiler name ")
405 (string :tag "Compile command ")
406 (string :tag "Compile options " "-work \\1")
407 (string :tag "Make command " "make")
408 (string :tag "Make options " "-f \\1")
409 (choice :tag "Generate Makefile "
410 (const :tag "Built-in function" nil)
411 (string :tag "Command" "vmake \\2 > \\1"))
412 (string :tag "Library command " "mkdir \\1")
413 (directory :tag "Compile directory "
414 :validate vhdl-widget-directory-validate "./")
415 (directory :tag "Library directory "
416 :validate vhdl-widget-directory-validate "work/")
417 (file :tag "Makefile name " "Makefile")
418 (string :tag "ID string ")
419 (list :tag "Error message" :indent 4
420 (regexp :tag "Regexp ")
421 (integer :tag "File subexp index")
422 (integer :tag "Line subexp index")
423 (integer :tag "Column subexp idx"))
424 (list :tag "File message" :indent 4
425 (regexp :tag "Regexp ")
426 (integer :tag "File subexp index"))
427 (choice :tag "Unit-to-file name mapping"
428 :format "%t: %[Value Menu%] %v\n"
429 (const :tag "Not defined" nil)
430 (list :tag "To string" :indent 4
431 (string :tag "Entity " "\\1.vhd")
432 (string :tag "Architecture " "\\2_\\1.vhd")
433 (string :tag "Configuration " "\\1.vhd")
434 (string :tag "Package " "\\1.vhd")
435 (string :tag "Package Body " "\\1_body.vhd")
436 (choice :tag "Case adjustment "
437 (const :tag "None" identity)
438 (const :tag "Upcase" upcase)
439 (const :tag "Downcase" downcase))))))
5eabfe72 440 :set (lambda (variable value)
0a2e512a 441 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
5eabfe72
KH
442 :group 'vhdl-compile)
443
444(defcustom vhdl-compiler "ModelSim"
445 "*Specifies the VHDL compiler to be used for syntax analysis.
3dcb36b7
JB
446Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
447 :type (let ((alist vhdl-compiler-alist) list)
448 (while alist
449 (setq list (cons (list 'const (caar alist)) list))
450 (setq alist (cdr alist)))
451 (append '(choice) (nreverse list)))
452 :group 'vhdl-compile)
453
454(defcustom vhdl-compile-use-local-error-regexp t
455 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
456In this case, only error message regexps for VHDL compilers are active if
457compilation is started from a VHDL buffer. Otherwise, the error message
458regexps are appended to the predefined global regexps, and all regexps are
459active all the time. Note that by doing that, the predefined global regexps
460might result in erroneous parsing of error messages for some VHDL compilers.
461
462NOTE: Activate the new setting by restarting Emacs."
463 :type 'boolean
d2ddb974
KH
464 :group 'vhdl-compile)
465
3dcb36b7
JB
466(defcustom vhdl-makefile-generation-hook nil
467 "*Functions to run at the end of Makefile generation.
468Allows to insert user specific parts into a Makefile.
469
470Example:
471 \(lambda nil
472 \(re-search-backward \"^# Rule for compiling entire design\")
473 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
474 :type 'hook
475 :group 'vhdl-compile)
476
477(defcustom vhdl-default-library "work"
478 "*Name of default library.
479Is overwritten by project settings if a project is active."
d2ddb974
KH
480 :type 'string
481 :group 'vhdl-compile)
482
483
3dcb36b7
JB
484(defgroup vhdl-project nil
485 "Customizations for projects."
d2ddb974
KH
486 :group 'vhdl)
487
3dcb36b7
JB
488(defcustom vhdl-project-alist
489 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
490 "~/example1/" ("src/system/" "src/components/") ""
491 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
492 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
493 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
494 ("Example 2" "Individual source files, multiple compilers in different directories"
495 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
496 nil "\\1/" "work" "\\1/work/" "Makefile" "")
497 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
498 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
499 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
500-------------------------------------------------------------------------------
501-- This is a multi-line project description
502-- that can be used as a project dependent part of the file header.
503"))
504 "*List of projects and their properties.
505 Name : name used in option `vhdl-project' to choose project
506 Title : title of project (single-line string)
507 Default directory: default project directory (absolute path)
508 Sources : a) source files : path + \"/\" + file name
509 b) directory : path + \"/\"
510 c) directory tree: \"-r \" + path + \"/\"
511 Exclude regexp : matches file/directory names to be excluded as sources
512 Compile options : project-specific options for each compiler
513 Compiler name : name of compiler for which these options are valid
514 Compile options: project-specific compiler options
515 (\"\\1\" inserts library name, \"\\2\" default options)
516 Make options: project-specific make options
517 (\"\\1\" inserts Makefile name, \"\\2\" default options)
518 Exceptions : file-specific exceptions
519 File name regexp: matches file names for which exceptions are valid
520 - Options : file-specific compiler options string
521 (\"\\1\" inserts library name, \"\\2\" default options,
522 \"\\3\" project-specific options)
523 - Do not compile: do not compile this file (in Makefile)
524 Compile directory: where compilation is run and the Makefile is placed
525 \(\"\\1\" inserts compiler ID string)
526 Library name : name of library (default is \"work\")
527 Library directory: path to library (\"\\1\" inserts compiler ID string)
528 Makefile name : name of Makefile
529 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
530 Description : description of project (multi-line string)
531
532Project title and description are used to insert into the file header (see
533option `vhdl-file-header').
534
535The default directory must have an absolute path (use `M-TAB' for completion).
536All other paths can be absolute or relative to the default directory. All
537paths must end with '/'.
538
539The design units found in the sources (files and directories) are shown in the
540hierarchy browser. Path and file name can contain wildcards `*' and `?' as
541well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
542Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
543specified, the default directory is taken as source directory. Otherwise,
544the default directory is only taken as source directory if there is a sources
545entry with the empty string or \"./\". Exclude regexp allows to filter out
546specific file and directory names from the list of sources (e.g. CVS
547directories).
548
549Files are compiled in the compile directory. Makefiles are also placed into
550the compile directory. Library directory specifies which directory the
551compiler compiles into (used to generate the Makefile).
552
553Since different compile/library directories and Makefiles may exist for
554different compilers within one project, these paths and names allow the
555insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
556Compile options, compile directory, library directory, and Makefile name
557overwrite the settings of the current compiler.
558
559File-specific compiler options (highest priority) overwrite project-specific
560options which overwrite default options (lowest priority). Lower priority
561options can be inserted in higher priority options. This allows to reuse
562default options (e.g. \"-file\") in project- or file-specific options (e.g.
563\"-93 -file\").
564
565NOTE: Reflect the new setting in the choice list of option `vhdl-project'
566 by restarting Emacs."
567 :type `(repeat
568 (list :tag "Project" :indent 2
569 (string :tag "Name ")
570 (string :tag "Title ")
571 (directory :tag "Default directory"
572 :validate vhdl-widget-directory-validate
573 ,(abbreviate-file-name default-directory))
574 (repeat :tag "Sources " :indent 4
575 (directory :format " %v" "./"))
576 (regexp :tag "Exclude regexp ")
577 (repeat
578 :tag "Compile options " :indent 4
579 (list :tag "Compiler" :indent 6
580 ,(let ((alist vhdl-compiler-alist) list)
581 (while alist
582 (setq list (cons (list 'const (caar alist)) list))
583 (setq alist (cdr alist)))
584 (append '(choice :tag "Compiler name")
585 (nreverse list)))
586 (string :tag "Compile options" "\\2")
587 (string :tag "Make options " "\\2")
588 (repeat
589 :tag "Exceptions " :indent 8
590 (cons :format "%v"
591 (regexp :tag "File name regexp ")
592 (choice :format "%[Value Menu%] %v"
593 (string :tag "Options" "\\3")
594 (const :tag "Do not compile" nil))))))
595 (directory :tag "Compile directory"
596 :validate vhdl-widget-directory-validate "./")
597 (string :tag "Library name " "work")
598 (directory :tag "Library directory"
599 :validate vhdl-widget-directory-validate "work/")
600 (file :tag "Makefile name " "Makefile")
601 (string :tag "Description: (type `C-j' for newline)"
602 :format "%t\n%v\n")))
603 :set (lambda (variable value)
0a2e512a 604 (vhdl-custom-set variable value
3dcb36b7
JB
605 'vhdl-update-mode-menu
606 'vhdl-speedbar-refresh))
607 :group 'vhdl-project)
608
609(defcustom vhdl-project nil
610 "*Specifies the default for the current project.
611Select a project name from the ones defined in option `vhdl-project-alist'.
612Is used to determine the project title and description to be inserted in file
613headers and the source files/directories to be scanned in the hierarchy
614browser. The current project can also be changed temporarily in the menu."
615 :type (let ((alist vhdl-project-alist) list)
616 (while alist
617 (setq list (cons (list 'const (caar alist)) list))
618 (setq alist (cdr alist)))
619 (append '(choice (const :tag "None" nil) (const :tag "--"))
620 (nreverse list)))
621 :group 'vhdl-project)
622
623(defcustom vhdl-project-file-name '("\\1.prj")
624 "*List of file names/paths for importing/exporting project setups.
625\"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
626replaced by the user name (allows to have user-specific project setups).
627The first entry is used as file name to import/export individual project
628setups. All entries are used to automatically import project setups at
629startup (see option `vhdl-project-auto-load'). Projects loaded from the
630first entry are automatically made current. Hint: specify local project
631setups in first entry, global setups in following entries; loading a local
632project setup will make it current, while loading the global setups
633is done without changing the current project.
634Names can also have an absolute path (i.e. project setups can be stored
635in global directories)."
636 :type '(repeat (string :tag "File name" "\\1.prj"))
637 :group 'vhdl-project)
638
639(defcustom vhdl-project-auto-load '(startup)
640 "*Automatically load project setups from files.
641All project setup files that match the file names specified in option
642`vhdl-project-file-name' are automatically loaded. The project of the
643\(alphabetically) last loaded setup of the first `vhdl-project-file-name'
644entry is activated.
645A project setup file can be obtained by exporting a project (see menu).
646 At startup: project setup file is loaded at Emacs startup"
647 :type '(set (const :tag "At startup" startup))
648 :group 'vhdl-project)
649
650(defcustom vhdl-project-sort t
651 "*Non-nil means projects are displayed in alphabetical order."
652 :type 'boolean
653 :group 'vhdl-project)
654
655
656(defgroup vhdl-style nil
657 "Customizations for coding styles."
658 :group 'vhdl
659 :group 'vhdl-template
660 :group 'vhdl-port
661 :group 'vhdl-compose)
662
5eabfe72
KH
663(defcustom vhdl-standard '(87 nil)
664 "*VHDL standards used.
665Basic standard:
666 VHDL'87 : IEEE Std 1076-1987
667 VHDL'93 : IEEE Std 1076-1993
668Additional standards:
669 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
3dcb36b7 670 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
5eabfe72 671
3dcb36b7
JB
672NOTE: Activate the new setting in a VHDL buffer by using the menu entry
673 \"Activate Options\"."
5eabfe72
KH
674 :type '(list (choice :tag "Basic standard"
675 (const :tag "VHDL'87" 87)
676 (const :tag "VHDL'93" 93))
677 (set :tag "Additional standards" :indent 2
678 (const :tag "VHDL-AMS" ams)
3dcb36b7 679 (const :tag "Math packages" math)))
5eabfe72 680 :set (lambda (variable value)
0a2e512a 681 (vhdl-custom-set variable value
5eabfe72
KH
682 'vhdl-template-map-init
683 'vhdl-mode-abbrev-table-init
684 'vhdl-template-construct-alist-init
685 'vhdl-template-package-alist-init
686 'vhdl-update-mode-menu
687 'vhdl-words-init 'vhdl-font-lock-init))
688 :group 'vhdl-style)
689
690(defcustom vhdl-basic-offset 2
d2ddb974
KH
691 "*Amount of basic offset used for indentation.
692This value is used by + and - symbols in `vhdl-offsets-alist'."
693 :type 'integer
694 :group 'vhdl-style)
695
d2ddb974 696(defcustom vhdl-upper-case-keywords nil
5eabfe72
KH
697 "*Non-nil means convert keywords to upper case.
698This is done when typed or expanded or by the fix case functions."
d2ddb974 699 :type 'boolean
5eabfe72 700 :set (lambda (variable value)
0a2e512a 701 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 702 :group 'vhdl-style)
d2ddb974
KH
703
704(defcustom vhdl-upper-case-types nil
5eabfe72
KH
705 "*Non-nil means convert standardized types to upper case.
706This is done when expanded or by the fix case functions."
d2ddb974 707 :type 'boolean
5eabfe72 708 :set (lambda (variable value)
0a2e512a 709 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 710 :group 'vhdl-style)
d2ddb974
KH
711
712(defcustom vhdl-upper-case-attributes nil
5eabfe72
KH
713 "*Non-nil means convert standardized attributes to upper case.
714This is done when expanded or by the fix case functions."
d2ddb974 715 :type 'boolean
5eabfe72 716 :set (lambda (variable value)
0a2e512a 717 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 718 :group 'vhdl-style)
d2ddb974
KH
719
720(defcustom vhdl-upper-case-enum-values nil
5eabfe72
KH
721 "*Non-nil means convert standardized enumeration values to upper case.
722This is done when expanded or by the fix case functions."
d2ddb974 723 :type 'boolean
5eabfe72 724 :set (lambda (variable value)
0a2e512a 725 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72
KH
726 :group 'vhdl-style)
727
728(defcustom vhdl-upper-case-constants t
729 "*Non-nil means convert standardized constants to upper case.
730This is done when expanded."
731 :type 'boolean
732 :set (lambda (variable value)
0a2e512a 733 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 734 :group 'vhdl-style)
d2ddb974 735
3dcb36b7
JB
736(defcustom vhdl-use-direct-instantiation 'standard
737 "*Non-nil means use VHDL'93 direct component instantiation.
738 Never : never
739 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
740 Always : always"
741 :type '(choice (const :tag "Never" never)
742 (const :tag "Standard" standard)
743 (const :tag "Always" always))
744 :group 'vhdl-style)
745
746
747(defgroup vhdl-naming nil
748 "Customizations for naming conventions."
749 :group 'vhdl)
750
751(defcustom vhdl-entity-file-name '(".*" . "\\&")
752 (concat
753 "*Specifies how the entity file name is obtained.
754The entity file name can be obtained by modifying the entity name (e.g.
755attaching or stripping off a substring). The file extension is automatically
756taken from the file name of the current buffer."
757 vhdl-name-doc-string)
758 :type '(cons (regexp :tag "From regexp")
759 (string :tag "To string "))
760 :group 'vhdl-naming
761 :group 'vhdl-compose)
d2ddb974 762
3dcb36b7
JB
763(defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
764 (concat
765 "*Specifies how the architecture file name is obtained.
766The architecture file name can be obtained by modifying the entity
767and/or architecture name (e.g. attaching or stripping off a substring). The
0a2e512a
RF
768file extension is automatically taken from the file name of the current
769buffer. The string that is matched against the regexp is the concatenation
770of the entity and the architecture name separated by a space. This gives
771access to both names (see default setting as example)."
772 vhdl-name-doc-string)
773 :type '(cons (regexp :tag "From regexp")
774 (string :tag "To string "))
775 :group 'vhdl-naming
776 :group 'vhdl-compose)
777
778(defcustom vhdl-configuration-file-name '(".*" . "\\&")
779 (concat
780 "*Specifies how the configuration file name is obtained.
781The configuration file name can be obtained by modifying the configuration
782name (e.g. attaching or stripping off a substring). The file extension is
783automatically taken from the file name of the current buffer."
3dcb36b7
JB
784 vhdl-name-doc-string)
785 :type '(cons (regexp :tag "From regexp")
786 (string :tag "To string "))
787 :group 'vhdl-naming
788 :group 'vhdl-compose)
789
790(defcustom vhdl-package-file-name '(".*" . "\\&")
791 (concat
792 "*Specifies how the package file name is obtained.
793The package file name can be obtained by modifying the package name (e.g.
794attaching or stripping off a substring). The file extension is automatically
0a2e512a
RF
795taken from the file name of the current buffer. Package files can be created
796in a different directory by prepending a relative or absolute path to the
797file name."
3dcb36b7
JB
798 vhdl-name-doc-string)
799 :type '(cons (regexp :tag "From regexp")
800 (string :tag "To string "))
801 :group 'vhdl-naming
802 :group 'vhdl-compose)
803
804(defcustom vhdl-file-name-case 'identity
805 "*Specifies how to change case for obtaining file names.
806When deriving a file name from a VHDL unit name, case can be changed as
807follows:
808 As Is: case is not changed (taken as is)
809 Lower Case: whole name is changed to lower case
810 Upper Case: whole name is changed to upper case
811 Capitalize: first letter of each word in name is capitalized"
812 :type '(choice (const :tag "As Is" identity)
813 (const :tag "Lower Case" downcase)
814 (const :tag "Upper Case" upcase)
815 (const :tag "Capitalize" capitalize))
816 :group 'vhdl-naming
817 :group 'vhdl-compose)
818
819
820(defgroup vhdl-template nil
5eabfe72 821 "Customizations for electrification."
d2ddb974
KH
822 :group 'vhdl)
823
5eabfe72
KH
824(defcustom vhdl-electric-keywords '(vhdl user)
825 "*Type of keywords for which electrification is enabled.
826 VHDL keywords: invoke built-in templates
3dcb36b7 827 User keywords: invoke user models (see option `vhdl-model-alist')"
5eabfe72 828 :type '(set (const :tag "VHDL keywords" vhdl)
3dcb36b7 829 (const :tag "User model keywords" user))
5eabfe72 830 :set (lambda (variable value)
0a2e512a 831 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
3dcb36b7 832 :group 'vhdl-template)
5eabfe72
KH
833
834(defcustom vhdl-optional-labels 'process
835 "*Constructs for which labels are to be queried.
836Template generators prompt for optional labels for:
837 None : no constructs
838 Processes only: processes only (also procedurals in VHDL-AMS)
839 All constructs: all constructs with optional labels and keyword END"
840 :type '(choice (const :tag "None" none)
841 (const :tag "Processes only" process)
842 (const :tag "All constructs" all))
3dcb36b7 843 :group 'vhdl-template)
d2ddb974 844
5eabfe72
KH
845(defcustom vhdl-insert-empty-lines 'unit
846 "*Specifies whether to insert empty lines in some templates.
847This improves readability of code. Empty lines are inserted in:
848 None : no constructs
849 Design units only: entities, architectures, configurations, packages only
850 All constructs : also all constructs with BEGIN...END parts
851
3dcb36b7 852Replaces option `vhdl-additional-empty-lines'."
5eabfe72
KH
853 :type '(choice (const :tag "None" none)
854 (const :tag "Design units only" unit)
855 (const :tag "All constructs" all))
3dcb36b7
JB
856 :group 'vhdl-template
857 :group 'vhdl-port
858 :group 'vhdl-compose)
5eabfe72
KH
859
860(defcustom vhdl-argument-list-indent nil
861 "*Non-nil means indent argument lists relative to opening parenthesis.
862That is, argument, association, and port lists start on the same line as the
863opening parenthesis and subsequent lines are indented accordingly.
864Otherwise, lists start on a new line and are indented as normal code."
d2ddb974 865 :type 'boolean
3dcb36b7
JB
866 :group 'vhdl-template
867 :group 'vhdl-port
868 :group 'vhdl-compose)
d2ddb974 869
5eabfe72
KH
870(defcustom vhdl-association-list-with-formals t
871 "*Non-nil means write association lists with formal parameters.
3dcb36b7
JB
872Templates prompt for formal and actual parameters (ports/generics).
873When pasting component instantiations, formals are included.
5eabfe72 874If nil, only a list of actual parameters is entered."
d2ddb974 875 :type 'boolean
3dcb36b7
JB
876 :group 'vhdl-template
877 :group 'vhdl-port
878 :group 'vhdl-compose)
d2ddb974
KH
879
880(defcustom vhdl-conditions-in-parenthesis nil
5eabfe72 881 "*Non-nil means place parenthesis around condition expressions."
d2ddb974 882 :type 'boolean
3dcb36b7 883 :group 'vhdl-template)
d2ddb974 884
5eabfe72
KH
885(defcustom vhdl-zero-string "'0'"
886 "*String to use for a logic zero."
887 :type 'string
3dcb36b7 888 :group 'vhdl-template)
5eabfe72
KH
889
890(defcustom vhdl-one-string "'1'"
891 "*String to use for a logic one."
892 :type 'string
3dcb36b7 893 :group 'vhdl-template)
5eabfe72
KH
894
895
896(defgroup vhdl-header nil
897 "Customizations for file header."
3dcb36b7
JB
898 :group 'vhdl-template
899 :group 'vhdl-compose)
d2ddb974 900
5eabfe72
KH
901(defcustom vhdl-file-header "\
902-------------------------------------------------------------------------------
903-- Title : <title string>
904-- Project : <project>
905-------------------------------------------------------------------------------
906-- File : <filename>
907-- Author : <author>
908-- Company : <company>
3dcb36b7 909-- Created : <date>
5eabfe72
KH
910-- Last update: <date>
911-- Platform : <platform>
3dcb36b7 912-- Standard : <standard>
5eabfe72
KH
913<projectdesc>-------------------------------------------------------------------------------
914-- Description: <cursor>
3dcb36b7 915<copyright>-------------------------------------------------------------------------------
5eabfe72
KH
916-- Revisions :
917-- Date Version Author Description
918-- <date> 1.0 <login>\tCreated
919-------------------------------------------------------------------------------
920
921"
922 "*String or file to insert as file header.
923If the string specifies an existing file name, the contents of the file is
924inserted, otherwise the string itself is inserted as file header.
925Type `C-j' for newlines.
d2ddb974
KH
926If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
927if the header needs to be version controlled.
928
929The following keywords for template generation are supported:
3dcb36b7
JB
930 <filename> : replaced by the name of the buffer
931 <author> : replaced by the user name and email address
932 \(`user-full-name',`mail-host-address', `user-mail-address')
933 <login> : replaced by user login name (`user-login-name')
934 <company> : replaced by contents of option `vhdl-company-name'
935 <date> : replaced by the current date
936 <year> : replaced by the current year
937 <project> : replaced by title of current project (`vhdl-project')
938 <projectdesc> : replaced by description of current project (`vhdl-project')
939 <copyright> : replaced by copyright string (`vhdl-copyright-string')
940 <platform> : replaced by contents of option `vhdl-platform-spec'
941 <standard> : replaced by the VHDL language standard(s) used
942 <... string> : replaced by a queried string (\"...\" is the prompt word)
943 <title string>: replaced by file title in automatically generated files
944 <cursor> : final cursor position
d2ddb974 945
5eabfe72
KH
946The (multi-line) project description <projectdesc> can be used as a project
947dependent part of the file header and can also contain the above keywords."
948 :type 'string
949 :group 'vhdl-header)
950
951(defcustom vhdl-file-footer ""
952 "*String or file to insert as file footer.
953If the string specifies an existing file name, the contents of the file is
954inserted, otherwise the string itself is inserted as file footer (i.e. at
955the end of the file).
3dcb36b7
JB
956Type `C-j' for newlines.
957The same keywords as in option `vhdl-file-header' can be used."
5eabfe72
KH
958 :type 'string
959 :group 'vhdl-header)
960
961(defcustom vhdl-company-name ""
3dcb36b7
JB
962 "*Name of company to insert in file header.
963See option `vhdl-file-header'."
964 :type 'string
965 :group 'vhdl-header)
966
967(defcustom vhdl-copyright-string "\
968-------------------------------------------------------------------------------
969-- Copyright (c) <year> <company>
970"
971 "*Copyright string to insert in file header.
972Can be multi-line string (type `C-j' for newline) and contain other file
973header keywords (see option `vhdl-file-header')."
5eabfe72
KH
974 :type 'string
975 :group 'vhdl-header)
976
977(defcustom vhdl-platform-spec ""
978 "*Specification of VHDL platform to insert in file header.
979The platform specification should contain names and versions of the
3dcb36b7
JB
980simulation and synthesis tools used.
981See option `vhdl-file-header'."
5eabfe72
KH
982 :type 'string
983 :group 'vhdl-header)
984
3dcb36b7 985(defcustom vhdl-date-format "%Y-%m-%d"
5eabfe72
KH
986 "*Specifies the date format to use in the header.
987This string is passed as argument to the command `format-time-string'.
988For more information on format strings, see the documentation for the
989`format-time-string' command (C-h f `format-time-string')."
990 :type 'string
991 :group 'vhdl-header)
d2ddb974 992
5eabfe72 993(defcustom vhdl-modify-date-prefix-string "-- Last update: "
d2ddb974 994 "*Prefix string of modification date in VHDL file header.
5eabfe72
KH
995If actualization of the modification date is called (menu,
996`\\[vhdl-template-modify]'), this string is searched and the rest
997of the line replaced by the current date."
d2ddb974 998 :type 'string
5eabfe72
KH
999 :group 'vhdl-header)
1000
1001(defcustom vhdl-modify-date-on-saving t
1002 "*Non-nil means update the modification date when the buffer is saved.
1003Calls function `\\[vhdl-template-modify]').
1004
3dcb36b7
JB
1005NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1006 \"Activate Options\"."
5eabfe72
KH
1007 :type 'boolean
1008 :group 'vhdl-header)
1009
1010
1011(defgroup vhdl-sequential-process nil
1012 "Customizations for sequential processes."
3dcb36b7 1013 :group 'vhdl-template)
d2ddb974 1014
5eabfe72
KH
1015(defcustom vhdl-reset-kind 'async
1016 "*Specifies which kind of reset to use in sequential processes."
1017 :type '(choice (const :tag "None" none)
1018 (const :tag "Synchronous" sync)
1019 (const :tag "Asynchronous" async))
1020 :group 'vhdl-sequential-process)
1021
1022(defcustom vhdl-reset-active-high nil
1023 "*Non-nil means reset in sequential processes is active high.
3dcb36b7 1024Nil means active low."
5eabfe72
KH
1025 :type 'boolean
1026 :group 'vhdl-sequential-process)
1027
1028(defcustom vhdl-clock-rising-edge t
1029 "*Non-nil means rising edge of clock triggers sequential processes.
3dcb36b7 1030Nil means falling edge."
5eabfe72
KH
1031 :type 'boolean
1032 :group 'vhdl-sequential-process)
1033
1034(defcustom vhdl-clock-edge-condition 'standard
1035 "*Syntax of the clock edge condition.
1036 Standard: \"clk'event and clk = '1'\"
1037 Function: \"rising_edge(clk)\""
1038 :type '(choice (const :tag "Standard" standard)
1039 (const :tag "Function" function))
1040 :group 'vhdl-sequential-process)
1041
1042(defcustom vhdl-clock-name ""
1043 "*Name of clock signal to use in templates."
d2ddb974 1044 :type 'string
5eabfe72 1045 :group 'vhdl-sequential-process)
d2ddb974 1046
5eabfe72
KH
1047(defcustom vhdl-reset-name ""
1048 "*Name of reset signal to use in templates."
d2ddb974 1049 :type 'string
5eabfe72
KH
1050 :group 'vhdl-sequential-process)
1051
1052
1053(defgroup vhdl-model nil
1054 "Customizations for user models."
1055 :group 'vhdl)
1056
1057(defcustom vhdl-model-alist
3dcb36b7 1058 '(("Example Model"
5eabfe72
KH
1059 "<label> : process (<clock>, <reset>)
1060begin -- process <label>
1061 if <reset> = '0' then -- asynchronous reset (active low)
1062 <cursor>
1063 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1064 if <enable> = '1' then -- synchronous load
84c98ace 1065
5eabfe72
KH
1066 end if;
1067 end if;
1068end process <label>;"
1069 "e" ""))
1070 "*List of user models.
1071VHDL models (templates) can be specified by the user in this list. They can be
1072invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1073electrification (i.e. overriding existing or creating new keywords, see
3dcb36b7 1074option `vhdl-electric-keywords').
5eabfe72
KH
1075 Name : name of model (string of words and spaces)
1076 String : string or name of file to be inserted as model (newline: `C-j')
1077 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1078 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1079 Keyword : keyword to invoke model
1080
1081The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1082A prompt that appears several times is queried once and replaced throughout
1083the model. Special prompts are:
1084 <clock> : name specified in `vhdl-clock-name' (if not empty)
1085 <reset> : name specified in `vhdl-reset-name' (if not empty)
1086 <cursor>: final cursor position
3dcb36b7
JB
1087File header prompts (see variable `vhdl-file-header') are automatically
1088replaced, so that user models can also be used to insert different types of
1089headers.
5eabfe72
KH
1090
1091If the string specifies an existing file name, the contents of the file is
1092inserted, otherwise the string itself is inserted.
1093The code within the models should be correctly indented.
1094Type `C-j' for newlines.
1095
3dcb36b7
JB
1096NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1097 \"Activate Options\"."
5eabfe72
KH
1098 :type '(repeat (list :tag "Model" :indent 2
1099 (string :tag "Name ")
1100 (string :tag "String : (type `C-j' for newline)"
1101 :format "%t\n%v")
3dcb36b7
JB
1102 (sexp :tag "Key binding" x)
1103 (string :tag "Keyword " :format "%t: %v\n")))
5eabfe72 1104 :set (lambda (variable value)
0a2e512a 1105 (vhdl-custom-set variable value
5eabfe72
KH
1106 'vhdl-model-map-init
1107 'vhdl-model-defun
1108 'vhdl-mode-abbrev-table-init
1109 'vhdl-update-mode-menu))
1110 :group 'vhdl-model)
1111
3dcb36b7 1112
0a2e512a
RF
1113(defgroup vhdl-compose nil
1114 "Customizations for structural composition."
1115 :group 'vhdl)
1116
1117(defcustom vhdl-compose-architecture-name '(".*" . "str")
1118 (concat
1119 "*Specifies how the component architecture name is obtained.
1120The component architecture name can be obtained by modifying the entity name
1121\(e.g. attaching or stripping off a substring).
1122If TO STRING is empty, the architecture name is queried."
1123 vhdl-name-doc-string)
1124 :type '(cons (regexp :tag "From regexp")
1125 (string :tag "To string "))
1126 :group 'vhdl-compose)
1127
1128(defcustom vhdl-compose-configuration-name
1129 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1130 (concat
1131 "*Specifies how the configuration name is obtained.
1132The configuration name can be obtained by modifying the entity and/or
1133architecture name (e.g. attaching or stripping off a substring). The string
1134that is matched against the regexp is the concatenation of the entity and the
1135architecture name separated by a space. This gives access to both names (see
1136default setting as example)."
1137 vhdl-name-doc-string)
1138 :type '(cons (regexp :tag "From regexp")
1139 (string :tag "To string "))
1140 :group 'vhdl-compose)
1141
1142(defcustom vhdl-components-package-name
1143 '((".*" . "\\&_components") . "components")
1144 (concat
1145 "*Specifies how the name for the components package is obtained.
1146The components package is a package containing all component declarations for
1147the current design. It's name can be obtained by modifying the project name
1148\(e.g. attaching or stripping off a substring). If no project is defined, the
1149DIRECTORY entry is chosen."
1150 vhdl-name-doc-string)
1151 :type '(cons (cons :tag "Project" :indent 2
1152 (regexp :tag "From regexp")
1153 (string :tag "To string "))
1154 (string :tag "Directory:\n String "))
1155 :group 'vhdl-compose)
1156
1157(defcustom vhdl-use-components-package nil
1158 "*Non-nil means use a separate components package for component declarations.
1159Otherwise, component declarations are inserted and searched for in the
1160architecture declarative parts."
1161 :type 'boolean
1162 :group 'vhdl-compose)
1163
1164(defcustom vhdl-compose-include-header t
1165 "*Non-nil means include a header in automatically generated files."
1166 :type 'boolean
1167 :group 'vhdl-compose)
1168
1169(defcustom vhdl-compose-create-files 'single
1170 "*Specifies whether new files should be created for the new component.
1171The component's entity and architecture are inserted:
1172 None : in current buffer
1173 Single file : in new single file
1174 Separate files: in two separate files
1175The file names are obtained from variables `vhdl-entity-file-name' and
1176`vhdl-architecture-file-name'."
1177 :type '(choice (const :tag "None" none)
1178 (const :tag "Single file" single)
1179 (const :tag "Separate files" separate))
1180 :group 'vhdl-compose)
1181
1182(defcustom vhdl-compose-configuration-create-file nil
1183 "*Specifies whether a new file should be created for the configuration.
1184If non-nil, a new file is created for the configuration.
1185The file name is obtained from variable `vhdl-configuration-file-name'."
1186 :type 'boolean
1187 :group 'vhdl-compose)
1188
1189(defcustom vhdl-compose-configuration-hierarchical t
1190 "*Specifies whether hierarchical configurations should be created.
1191If non-nil, automatically created configurations are hierarchical and include
1192the whole hierarchy of subcomponents. Otherwise the configuration only
1193includes one level of subcomponents."
1194 :type 'boolean
1195 :group 'vhdl-compose)
1196
1197(defcustom vhdl-compose-configuration-use-subconfiguration t
1198 "*Specifies whether subconfigurations should be used inside configurations.
1199If non-nil, automatically created configurations use configurations in binding
1200indications for subcomponents, if such configurations exist. Otherwise,
1201entities are used in binding indications for subcomponents."
1202 :type 'boolean
1203 :group 'vhdl-compose)
1204
1205
5eabfe72 1206(defgroup vhdl-port nil
3dcb36b7
JB
1207 "Customizations for port translation functions."
1208 :group 'vhdl
1209 :group 'vhdl-compose)
5eabfe72
KH
1210
1211(defcustom vhdl-include-port-comments nil
1212 "*Non-nil means include port comments when a port is pasted."
1213 :type 'boolean
1214 :group 'vhdl-port)
1215
1216(defcustom vhdl-include-direction-comments nil
3dcb36b7 1217 "*Non-nil means include port direction in instantiations as comments."
5eabfe72
KH
1218 :type 'boolean
1219 :group 'vhdl-port)
1220
3dcb36b7
JB
1221(defcustom vhdl-include-type-comments nil
1222 "*Non-nil means include generic/port type in instantiations as comments."
1223 :type 'boolean
1224 :group 'vhdl-port)
5eabfe72 1225
3dcb36b7
JB
1226(defcustom vhdl-include-group-comments 'never
1227 "*Specifies whether to include group comments and spacings.
1228The comments and empty lines between groups of ports are pasted:
1229 Never : never
1230 Declarations: in entity/component/constant/signal declarations only
1231 Always : also in generic/port maps"
1232 :type '(choice (const :tag "Never" never)
1233 (const :tag "Declarations" decl)
1234 (const :tag "Always" always))
1235 :group 'vhdl-port)
5eabfe72 1236
3dcb36b7 1237(defcustom vhdl-actual-port-name '(".*" . "\\&")
5eabfe72
KH
1238 (concat
1239 "*Specifies how actual port names are obtained from formal port names.
1240In a component instantiation, an actual port name can be obtained by
1241modifying the formal port name (e.g. attaching or stripping off a substring)."
1242 vhdl-name-doc-string)
3dcb36b7
JB
1243 :type '(cons (regexp :tag "From regexp")
1244 (string :tag "To string "))
5eabfe72
KH
1245 :group 'vhdl-port)
1246
3dcb36b7 1247(defcustom vhdl-instance-name '(".*" . "\\&_%d")
5eabfe72
KH
1248 (concat
1249 "*Specifies how an instance name is obtained.
1250The instance name can be obtained by modifying the name of the component to be
3dcb36b7
JB
1251instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1252by a unique number (starting with 1).
5eabfe72
KH
1253If TO STRING is empty, the instance name is queried."
1254 vhdl-name-doc-string)
3dcb36b7
JB
1255 :type '(cons (regexp :tag "From regexp")
1256 (string :tag "To string "))
1257 :group 'vhdl-port)
1258
1259
1260(defgroup vhdl-testbench nil
bc25429a 1261 "Customizations for testbench generation."
5eabfe72
KH
1262 :group 'vhdl-port)
1263
1264(defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1265 (concat
3dcb36b7
JB
1266 "*Specifies how the testbench entity name is obtained.
1267The entity name of a testbench can be obtained by modifying the name of
5eabfe72
KH
1268the component to be tested (e.g. attaching or stripping off a substring)."
1269 vhdl-name-doc-string)
3dcb36b7
JB
1270 :type '(cons (regexp :tag "From regexp")
1271 (string :tag "To string "))
1272 :group 'vhdl-testbench)
5eabfe72
KH
1273
1274(defcustom vhdl-testbench-architecture-name '(".*" . "")
1275 (concat
3dcb36b7
JB
1276 "*Specifies how the testbench architecture name is obtained.
1277The testbench architecture name can be obtained by modifying the name of
5eabfe72
KH
1278the component to be tested (e.g. attaching or stripping off a substring).
1279If TO STRING is empty, the architecture name is queried."
1280 vhdl-name-doc-string)
3dcb36b7
JB
1281 :type '(cons (regexp :tag "From regexp")
1282 (string :tag "To string "))
1283 :group 'vhdl-testbench)
1284
0a2e512a 1285(defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
3dcb36b7
JB
1286 (concat
1287 "*Specifies how the testbench configuration name is obtained.
1288The configuration name of a testbench can be obtained by modifying the entity
1289and/or architecture name (e.g. attaching or stripping off a substring). The
1290string that is matched against the regexp is the concatenation of the entity
1291and the architecture name separated by a space. This gives access to both
1292names (see default setting as example)."
1293 vhdl-name-doc-string)
1294 :type '(cons (regexp :tag "From regexp")
1295 (string :tag "To string "))
1296 :group 'vhdl-testbench)
5eabfe72
KH
1297
1298(defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1299 (concat
1300 "*Specifies how a DUT instance name is obtained.
1301The design-under-test instance name (i.e. the component instantiated in the
3dcb36b7 1302testbench) can be obtained by modifying the component name (e.g. attaching
5eabfe72
KH
1303or stripping off a substring)."
1304 vhdl-name-doc-string)
3dcb36b7
JB
1305 :type '(cons (regexp :tag "From regexp")
1306 (string :tag "To string "))
1307 :group 'vhdl-testbench)
5eabfe72 1308
3dcb36b7
JB
1309(defcustom vhdl-testbench-include-header t
1310 "*Non-nil means include a header in automatically generated files."
1311 :type 'boolean
1312 :group 'vhdl-testbench)
5eabfe72 1313
3dcb36b7
JB
1314(defcustom vhdl-testbench-declarations "\
1315 -- clock
1316 signal Clk : std_logic := '1';
1317"
1318 "*String or file to be inserted in the testbench declarative part.
5eabfe72 1319If the string specifies an existing file name, the contents of the file is
3dcb36b7 1320inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1321architecture before the BEGIN keyword.
1322Type `C-j' for newlines."
1323 :type 'string
3dcb36b7
JB
1324 :group 'vhdl-testbench)
1325
1326(defcustom vhdl-testbench-statements "\
1327 -- clock generation
1328 Clk <= not Clk after 10 ns;
5eabfe72 1329
3dcb36b7
JB
1330 -- waveform generation
1331 WaveGen_Proc: process
1332 begin
1333 -- insert signal assignments here
84c98ace 1334
3dcb36b7
JB
1335 wait until Clk = '1';
1336 end process WaveGen_Proc;
1337"
1338 "*String or file to be inserted in the testbench statement part.
5eabfe72 1339If the string specifies an existing file name, the contents of the file is
3dcb36b7 1340inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1341architecture before the END keyword.
1342Type `C-j' for newlines."
1343 :type 'string
3dcb36b7 1344 :group 'vhdl-testbench)
5eabfe72
KH
1345
1346(defcustom vhdl-testbench-initialize-signals nil
3dcb36b7 1347 "*Non-nil means initialize signals with `0' when declared in testbench."
5eabfe72 1348 :type 'boolean
3dcb36b7
JB
1349 :group 'vhdl-testbench)
1350
1351(defcustom vhdl-testbench-include-library t
1352 "*Non-nil means a library/use clause for std_logic_1164 is included."
1353 :type 'boolean
1354 :group 'vhdl-testbench)
1355
1356(defcustom vhdl-testbench-include-configuration t
1357 "*Non-nil means a testbench configuration is attached at the end."
1358 :type 'boolean
1359 :group 'vhdl-testbench)
5eabfe72
KH
1360
1361(defcustom vhdl-testbench-create-files 'single
3dcb36b7
JB
1362 "*Specifies whether new files should be created for the testbench.
1363testbench entity and architecture are inserted:
5eabfe72
KH
1364 None : in current buffer
1365 Single file : in new single file
1366 Separate files: in two separate files
0a2e512a
RF
1367The file names are obtained from variables `vhdl-testbench-entity-file-name'
1368and `vhdl-testbench-architecture-file-name'."
5eabfe72
KH
1369 :type '(choice (const :tag "None" none)
1370 (const :tag "Single file" single)
1371 (const :tag "Separate files" separate))
3dcb36b7
JB
1372 :group 'vhdl-testbench)
1373
0a2e512a 1374(defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
3dcb36b7 1375 (concat
0a2e512a
RF
1376 "*Specifies how the testbench entity file name is obtained.
1377The entity file name can be obtained by modifying the testbench entity name
1378\(e.g. attaching or stripping off a substring). The file extension is
1379automatically taken from the file name of the current buffer. Testbench
1380files can be created in a different directory by prepending a relative or
1381absolute path to the file name."
3dcb36b7
JB
1382 vhdl-name-doc-string)
1383 :type '(cons (regexp :tag "From regexp")
1384 (string :tag "To string "))
0a2e512a 1385 :group 'vhdl-testbench)
3dcb36b7 1386
0a2e512a 1387(defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
3dcb36b7 1388 (concat
0a2e512a
RF
1389 "*Specifies how the testbench architecture file name is obtained.
1390The architecture file name can be obtained by modifying the testbench entity
1391and/or architecture name (e.g. attaching or stripping off a substring). The
1392string that is matched against the regexp is the concatenation of the entity
1393and the architecture name separated by a space. This gives access to both
1394names (see default setting as example). Testbench files can be created in
1395a different directory by prepending a relative or absolute path to the file
1396name."
3dcb36b7 1397 vhdl-name-doc-string)
0a2e512a
RF
1398 :type '(cons (regexp :tag "From regexp")
1399 (string :tag "To string "))
1400 :group 'vhdl-testbench)
d2ddb974
KH
1401
1402
1403(defgroup vhdl-comment nil
1404 "Customizations for comments."
5eabfe72 1405 :group 'vhdl)
d2ddb974
KH
1406
1407(defcustom vhdl-self-insert-comments t
5eabfe72 1408 "*Non-nil means various templates automatically insert help comments."
d2ddb974
KH
1409 :type 'boolean
1410 :group 'vhdl-comment)
1411
1412(defcustom vhdl-prompt-for-comments t
5eabfe72 1413 "*Non-nil means various templates prompt for user definable comments."
d2ddb974
KH
1414 :type 'boolean
1415 :group 'vhdl-comment)
1416
5eabfe72 1417(defcustom vhdl-inline-comment-column 40
3dcb36b7
JB
1418 "*Column to indent and align inline comments to.
1419Overrides local option `comment-column'.
5eabfe72 1420
3dcb36b7
JB
1421NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1422 \"Activate Options\"."
d2ddb974
KH
1423 :type 'integer
1424 :group 'vhdl-comment)
1425
1426(defcustom vhdl-end-comment-column 79
5eabfe72
KH
1427 "*End of comment column.
1428Comments that exceed this column number are wrapped.
1429
3dcb36b7
JB
1430NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1431 \"Activate Options\"."
d2ddb974
KH
1432 :type 'integer
1433 :group 'vhdl-comment)
1434
5eabfe72 1435(defvar end-comment-column)
d2ddb974
KH
1436
1437
5eabfe72
KH
1438(defgroup vhdl-align nil
1439 "Customizations for alignment."
d2ddb974
KH
1440 :group 'vhdl)
1441
5eabfe72
KH
1442(defcustom vhdl-auto-align t
1443 "*Non-nil means align some templates automatically after generation."
d2ddb974 1444 :type 'boolean
5eabfe72
KH
1445 :group 'vhdl-align)
1446
1447(defcustom vhdl-align-groups t
1448 "*Non-nil means align groups of code lines separately.
3dcb36b7
JB
1449A group of code lines is a region of consecutive lines between two lines that
1450match the regexp in option `vhdl-align-group-separate'."
1451 :type 'boolean
1452 :group 'vhdl-align)
1453
1454(defcustom vhdl-align-group-separate "^\\s-*$"
1455 "*Regexp for matching a line that separates groups of lines for alignment.
1456Examples:
1457 \"^\\s-*$\": matches an empty line
1458 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1459 :type 'regexp
1460 :group 'vhdl-align)
1461
1462(defcustom vhdl-align-same-indent t
1463 "*Non-nil means align blocks with same indent separately.
1464When a region or the entire buffer is aligned, the code is divided into
1465blocks of same indent which are aligned separately (except for argument/port
1466lists). This gives nicer alignment in most cases.
1467Option `vhdl-align-groups' still applies within these blocks."
5eabfe72
KH
1468 :type 'boolean
1469 :group 'vhdl-align)
1470
1471
1472(defgroup vhdl-highlight nil
1473 "Customizations for highlighting."
1474 :group 'vhdl)
d2ddb974
KH
1475
1476(defcustom vhdl-highlight-keywords t
5eabfe72
KH
1477 "*Non-nil means highlight VHDL keywords and other standardized words.
1478The following faces are used:
0a2e512a
RF
1479 `font-lock-keyword-face' : keywords
1480 `font-lock-type-face' : standardized types
1481 `vhdl-font-lock-attribute-face': standardized attributes
1482 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1483 `vhdl-font-lock-function-face' : standardized function and package names
5eabfe72
KH
1484
1485NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1486 entry \"Fontify Buffer\")."
d2ddb974 1487 :type 'boolean
5eabfe72 1488 :set (lambda (variable value)
0a2e512a 1489 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1490 :group 'vhdl-highlight)
1491
5eabfe72
KH
1492(defcustom vhdl-highlight-names t
1493 "*Non-nil means highlight declaration names and construct labels.
1494The following faces are used:
3dcb36b7 1495 `font-lock-function-name-face' : names in declarations of units,
5eabfe72 1496 subprograms, components, as well as labels of VHDL constructs
3dcb36b7 1497 `font-lock-type-face' : names in type/nature declarations
0a2e512a 1498 `vhdl-font-lock-attribute-face': names in attribute declarations
3dcb36b7 1499 `font-lock-variable-name-face' : names in declarations of signals,
5eabfe72
KH
1500 variables, constants, subprogram parameters, generics, and ports
1501
1502NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1503 entry \"Fontify Buffer\")."
d2ddb974 1504 :type 'boolean
5eabfe72 1505 :set (lambda (variable value)
0a2e512a 1506 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1507 :group 'vhdl-highlight)
1508
5eabfe72
KH
1509(defcustom vhdl-highlight-special-words nil
1510 "*Non-nil means highlight words with special syntax.
3dcb36b7
JB
1511The words with syntax and color specified in option `vhdl-special-syntax-alist'
1512are highlighted accordingly.
5eabfe72
KH
1513Can be used for visual support of naming conventions.
1514
1515NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1516 entry \"Fontify Buffer\")."
d2ddb974 1517 :type 'boolean
5eabfe72 1518 :set (lambda (variable value)
0a2e512a 1519 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1520 :group 'vhdl-highlight)
1521
5eabfe72
KH
1522(defcustom vhdl-highlight-forbidden-words nil
1523 "*Non-nil means highlight forbidden words.
3dcb36b7
JB
1524The reserved words specified in option `vhdl-forbidden-words' or having the
1525syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
0a2e512a 1526warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
5eabfe72
KH
1527use them.
1528
1529NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1530 entry \"Fontify Buffer\")."
d2ddb974 1531 :type 'boolean
5eabfe72 1532 :set (lambda (variable value)
0a2e512a 1533 (vhdl-custom-set variable value
5eabfe72 1534 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1535 :group 'vhdl-highlight)
1536
5eabfe72
KH
1537(defcustom vhdl-highlight-verilog-keywords nil
1538 "*Non-nil means highlight Verilog keywords as reserved words.
1539Verilog keywords are highlighted in a warning color (face
0a2e512a 1540`vhdl-font-lock-reserved-words-face') to indicate not to use them.
2f402702 1541
5eabfe72 1542NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1543 entry \"Fontify Buffer\")."
d2ddb974 1544 :type 'boolean
5eabfe72 1545 :set (lambda (variable value)
0a2e512a 1546 (vhdl-custom-set variable value
5eabfe72 1547 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1548 :group 'vhdl-highlight)
1549
5eabfe72
KH
1550(defcustom vhdl-highlight-translate-off nil
1551 "*Non-nil means background-highlight code excluded from translation.
1552That is, all code between \"-- pragma translate_off\" and
1553\"-- pragma translate_on\" is highlighted using a different background color
0a2e512a 1554\(face `vhdl-font-lock-translate-off-face').
5eabfe72 1555Note: this might slow down on-the-fly fontification (and thus editing).
d2ddb974 1556
5eabfe72 1557NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1558 entry \"Fontify Buffer\")."
5eabfe72
KH
1559 :type 'boolean
1560 :set (lambda (variable value)
0a2e512a 1561 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1562 :group 'vhdl-highlight)
1563
5eabfe72
KH
1564(defcustom vhdl-highlight-case-sensitive nil
1565 "*Non-nil means consider case for highlighting.
1566Possible trade-off:
1567 non-nil also upper-case VHDL words are highlighted, but case of words with
1568 special syntax is not considered
1569 nil only lower-case VHDL words are highlighted, but case of words with
1570 special syntax is considered
3dcb36b7 1571Overrides local option `font-lock-keywords-case-fold-search'.
5eabfe72
KH
1572
1573NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1574 entry \"Fontify Buffer\")."
5eabfe72
KH
1575 :type 'boolean
1576 :group 'vhdl-highlight)
d2ddb974 1577
3dcb36b7
JB
1578(defcustom vhdl-special-syntax-alist
1579 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1580 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1581 ("variable" "\\w+_v" "Grey50" "Grey80"))
5eabfe72 1582 "*List of special syntax to be highlighted.
3dcb36b7 1583If option `vhdl-highlight-special-words' is non-nil, words with the specified
5eabfe72
KH
1584syntax (as regular expression) are highlighted in the corresponding color.
1585
1586 Name : string of words and spaces
1587 Regexp : regular expression describing word syntax
1588 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1589 Color (light): foreground color for light background
1590 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1591 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1592 Color (dark) : foreground color for dark background
1593 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1594 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1595
1596Can be used for visual support of naming conventions, such as highlighting
3dcb36b7 1597different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
5eabfe72 1598\"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
3dcb36b7 1599common substrings or name suffices.
5eabfe72 1600For each entry, a new face is generated with the specified colors and name
0a2e512a 1601\"vhdl-font-lock-\" + name + \"-face\".
5eabfe72
KH
1602
1603NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1604 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
5eabfe72
KH
1605 :type '(repeat (list :tag "Face" :indent 2
1606 (string :tag "Name ")
1607 (regexp :tag "Regexp " "\\w+_")
1608 (string :tag "Color (light)")
1609 (string :tag "Color (dark) ")))
1610 :set (lambda (variable value)
0a2e512a 1611 (vhdl-custom-set variable value 'vhdl-font-lock-init))
5eabfe72 1612 :group 'vhdl-highlight)
d2ddb974 1613
5eabfe72
KH
1614(defcustom vhdl-forbidden-words '()
1615 "*List of forbidden words to be highlighted.
3dcb36b7 1616If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
5eabfe72
KH
1617words are highlighted in a warning color to indicate not to use them.
1618
1619NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1620 entry \"Fontify Buffer\")."
5eabfe72
KH
1621 :type '(repeat (string :format "%v"))
1622 :set (lambda (variable value)
0a2e512a 1623 (vhdl-custom-set variable value
5eabfe72
KH
1624 'vhdl-words-init 'vhdl-font-lock-init))
1625 :group 'vhdl-highlight)
d2ddb974 1626
5eabfe72
KH
1627(defcustom vhdl-forbidden-syntax ""
1628 "*Syntax of forbidden words to be highlighted.
3dcb36b7 1629If option `vhdl-highlight-forbidden-words' is non-nil, words with this
5eabfe72
KH
1630syntax are highlighted in a warning color to indicate not to use them.
1631Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1632highlights identifiers with 10 or more characters).
d2ddb974 1633
5eabfe72 1634NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1635 entry \"Fontify Buffer\")."
d2ddb974 1636 :type 'regexp
5eabfe72 1637 :set (lambda (variable value)
0a2e512a 1638 (vhdl-custom-set variable value
5eabfe72
KH
1639 'vhdl-words-init 'vhdl-font-lock-init))
1640 :group 'vhdl-highlight)
d2ddb974 1641
3dcb36b7
JB
1642(defcustom vhdl-directive-keywords '("pragma" "synopsys")
1643 "*List of compiler directive keywords recognized for highlighting.
d2ddb974 1644
3dcb36b7
JB
1645NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1646 entry \"Fontify Buffer\")."
1647 :type '(repeat (string :format "%v"))
1648 :set (lambda (variable value)
1649 (vhdl-custom-set variable value
1650 'vhdl-words-init 'vhdl-font-lock-init))
1651 :group 'vhdl-highlight)
1652
1653
1654(defgroup vhdl-speedbar nil
1655 "Customizations for speedbar."
d2ddb974
KH
1656 :group 'vhdl)
1657
3dcb36b7
JB
1658(defcustom vhdl-speedbar-auto-open nil
1659 "*Non-nil means automatically open speedbar at startup.
5eabfe72 1660Alternatively, the speedbar can be opened from the VHDL menu."
d2ddb974 1661 :type 'boolean
3dcb36b7
JB
1662 :group 'vhdl-speedbar)
1663
1664(defcustom vhdl-speedbar-display-mode 'files
1665 "*Specifies the default displaying mode when opening speedbar.
1666Alternatively, the displaying mode can be selected from the speedbar menu or
1667by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1668 :type '(choice (const :tag "Files" files)
1669 (const :tag "Directory hierarchy" directory)
1670 (const :tag "Project hierarchy" project))
1671 :group 'vhdl-speedbar)
1672
1673(defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1674 "*Limits scanning of large files and netlists.
1675Design units: maximum file size to scan for design units
1676Hierarchy (instances of subcomponents):
1677 File size: maximum file size to scan for instances (in bytes)
1678 Instances per arch: maximum number of instances to scan per architecture
1679
1680\"None\" always means that there is no limit.
1681In case of files not or incompletely scanned, a warning message and the file
1682names are printed out.
1683Background: scanning for instances is considerably slower than scanning for
1684design units, especially when there are many instances. These limits should
1685prevent the scanning of large netlists."
1686 :type '(list (choice :tag "Design units"
1687 :format "%t : %[Value Menu%] %v"
1688 (const :tag "None" nil)
1689 (integer :tag "File size"))
1690 (list :tag "Hierarchy" :indent 2
1691 (choice :tag "File size"
1692 :format "%t : %[Value Menu%] %v"
1693 (const :tag "None" nil)
1694 (integer :tag "Size "))
1695 (choice :tag "Instances per arch"
1696 (const :tag "None" nil)
1697 (integer :tag "Number "))))
1698 :group 'vhdl-speedbar)
1699
1700(defcustom vhdl-speedbar-jump-to-unit t
1701 "*Non-nil means jump to the design unit code when opened in a buffer.
1702The buffer cursor position is left unchanged otherwise."
1703 :type 'boolean
1704 :group 'vhdl-speedbar)
d2ddb974 1705
3dcb36b7
JB
1706(defcustom vhdl-speedbar-update-on-saving t
1707 "*Automatically update design hierarchy when buffer is saved."
d2ddb974 1708 :type 'boolean
3dcb36b7
JB
1709 :group 'vhdl-speedbar)
1710
1711(defcustom vhdl-speedbar-save-cache '(hierarchy display)
1712 "*Automatically save modified hierarchy caches when exiting Emacs.
1713 Hierarchy: design hierarchy information
1714 Display: displaying information (which design units to expand)"
1715 :type '(set (const :tag "Hierarchy" hierarchy)
1716 (const :tag "Display" display))
1717 :group 'vhdl-speedbar)
1718
1719(defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1720 "*Name of file for saving hierarchy cache.
1721\"\\1\" is replaced by the project name if a project is specified,
1722\"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1723different users to have cache files in the same directory). Can also have
1724an absolute path (i.e. all caches can be stored in one global directory)."
1725 :type 'string
1726 :group 'vhdl-speedbar)
d2ddb974 1727
3dcb36b7
JB
1728
1729(defgroup vhdl-menu nil
1730 "Customizations for menues."
1731 :group 'vhdl)
5eabfe72
KH
1732
1733(defcustom vhdl-index-menu nil
1734 "*Non-nil means add an index menu for a source file when loading.
1735Alternatively, the speedbar can be used. Note that the index menu scans a file
3dcb36b7 1736when it is opened, while speedbar only scans the file upon request."
5eabfe72
KH
1737 :type 'boolean
1738 :group 'vhdl-menu)
1739
1740(defcustom vhdl-source-file-menu nil
1741 "*Non-nil means add a menu of all source files in current directory.
1742Alternatively, the speedbar can be used."
1743 :type 'boolean
1744 :group 'vhdl-menu)
1745
1746(defcustom vhdl-hideshow-menu nil
3dcb36b7
JB
1747 "*Non-nil means add hideshow menu and functionality at startup.
1748Hideshow can also be enabled from the VHDL Mode menu.
1749Hideshow allows hiding code of various VHDL constructs.
5eabfe72 1750
3dcb36b7
JB
1751NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1752 \"Activate Options\"."
5eabfe72
KH
1753 :type 'boolean
1754 :group 'vhdl-menu)
1755
1756(defcustom vhdl-hide-all-init nil
1757 "*Non-nil means hide all design units initially after a file is loaded."
d2ddb974
KH
1758 :type 'boolean
1759 :group 'vhdl-menu)
1760
1761
1762(defgroup vhdl-print nil
1763 "Customizations for printing."
1764 :group 'vhdl)
1765
1766(defcustom vhdl-print-two-column t
5eabfe72 1767 "*Non-nil means print code in two columns and landscape format.
3dcb36b7
JB
1768Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1769prints VHDL files in a nice two-column landscape style.
5eabfe72
KH
1770
1771NOTE: Activate the new setting by restarting Emacs.
1772 Overrides `ps-print' settings locally."
1773 :type 'boolean
1774 :group 'vhdl-print)
1775
1776(defcustom vhdl-print-customize-faces t
1777 "*Non-nil means use an optimized set of faces for postscript printing.
1778
1779NOTE: Activate the new setting by restarting Emacs.
1780 Overrides `ps-print' settings locally."
d2ddb974
KH
1781 :type 'boolean
1782 :group 'vhdl-print)
1783
1784
1785(defgroup vhdl-misc nil
1786 "Miscellaneous customizations."
1787 :group 'vhdl)
1788
1789(defcustom vhdl-intelligent-tab t
5eabfe72 1790 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
d2ddb974
KH
1791That is, if preceeding character is part of a word then complete word,
1792else if not at beginning of line then insert tab,
1793else if last command was a `TAB' or `RET' then dedent one step,
5eabfe72 1794else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
d2ddb974 1795If nil, TAB always indents current line (i.e. `TAB' is bound to
3dcb36b7
JB
1796`indent-according-to-mode').
1797
1798NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1799 \"Activate Options\"."
1800 :type 'boolean
1801 :group 'vhdl-misc)
5eabfe72 1802
3dcb36b7
JB
1803(defcustom vhdl-indent-syntax-based t
1804 "*Non-nil means indent lines of code based on their syntactic context.
1805Otherwise, a line is indented like the previous nonblank line. This can be
1806useful in large files where syntax-based indentation gets very slow."
d2ddb974
KH
1807 :type 'boolean
1808 :group 'vhdl-misc)
1809
5eabfe72
KH
1810(defcustom vhdl-word-completion-case-sensitive nil
1811 "*Non-nil means word completion using `TAB' is case sensitive.
1812That is, `TAB' completes words that start with the same letters and case.
1813Otherwise, case is ignored."
1814 :type 'boolean
d2ddb974
KH
1815 :group 'vhdl-misc)
1816
1817(defcustom vhdl-word-completion-in-minibuffer t
5eabfe72
KH
1818 "*Non-nil enables word completion in minibuffer (for template prompts).
1819
1820NOTE: Activate the new setting by restarting Emacs."
d2ddb974
KH
1821 :type 'boolean
1822 :group 'vhdl-misc)
1823
1824(defcustom vhdl-underscore-is-part-of-word nil
5eabfe72 1825 "*Non-nil means consider the underscore character `_' as part of word.
d2ddb974 1826An identifier containing underscores is then treated as a single word in
5eabfe72
KH
1827select and move operations. All parts of an identifier separated by underscore
1828are treated as single words otherwise.
1829
3dcb36b7
JB
1830NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1831 \"Activate Options\"."
d2ddb974 1832 :type 'boolean
5eabfe72 1833 :set (lambda (variable value)
0a2e512a 1834 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
d2ddb974
KH
1835 :group 'vhdl-misc)
1836
3dcb36b7
JB
1837
1838(defgroup vhdl-related nil
5eabfe72
KH
1839 "Related general customizations."
1840 :group 'vhdl)
1841
3dcb36b7
JB
1842;; add related general customizations
1843(custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1844(if vhdl-xemacs
1845 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1846 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1847(custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1848(custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1849(custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1850(unless vhdl-xemacs
1851 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1852(custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1853(custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1854(custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1855
5eabfe72
KH
1856;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1857;; Internal variables
1858
3dcb36b7
JB
1859(defvar vhdl-menu-max-size 20
1860 "*Specifies the maximum size of a menu before splitting it into submenues.")
5eabfe72
KH
1861
1862(defvar vhdl-progress-interval 1
1863 "*Interval used to update progress status during long operations.
1864If a number, percentage complete gets updated after each interval of
3dcb36b7 1865that many seconds. To inhibit all messages, set this option to nil.")
d2ddb974
KH
1866
1867(defvar vhdl-inhibit-startup-warnings-p nil
1868 "*If non-nil, inhibits start up compatibility warnings.")
1869
1870(defvar vhdl-strict-syntax-p nil
1871 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1872If the syntactic symbol for a particular line does not match a symbol
1873in the offsets alist, an error is generated, otherwise no error is
1874reported and the syntactic symbol is ignored.")
1875
1876(defvar vhdl-echo-syntactic-information-p nil
1877 "*If non-nil, syntactic info is echoed when the line is indented.")
1878
1879(defconst vhdl-offsets-alist-default
0a2e512a
RF
1880 '((string . -1000)
1881 (cpp-macro . -1000)
1882 (block-open . 0)
1883 (block-close . 0)
1884 (statement . 0)
1885 (statement-cont . vhdl-lineup-statement-cont)
d2ddb974
KH
1886 (statement-block-intro . +)
1887 (statement-case-intro . +)
0a2e512a
RF
1888 (case-alternative . +)
1889 (comment . vhdl-lineup-comment)
1890 (arglist-intro . +)
1891 (arglist-cont . 0)
d2ddb974 1892 (arglist-cont-nonempty . vhdl-lineup-arglist)
0a2e512a
RF
1893 (arglist-close . vhdl-lineup-arglist)
1894 (entity . 0)
1895 (configuration . 0)
1896 (package . 0)
1897 (architecture . 0)
1898 (package-body . 0)
d2ddb974
KH
1899 )
1900 "Default settings for offsets of syntactic elements.
1901Do not change this constant! See the variable `vhdl-offsets-alist' for
1902more information.")
1903
1904(defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1905 "*Association list of syntactic element symbols and indentation offsets.
1906As described below, each cons cell in this list has the form:
1907
1908 (SYNTACTIC-SYMBOL . OFFSET)
1909
5eabfe72 1910When a line is indented, `vhdl-mode' first determines the syntactic
d2ddb974
KH
1911context of the line by generating a list of symbols called syntactic
1912elements. This list can contain more than one syntactic element and
1913the global variable `vhdl-syntactic-context' contains the context list
1914for the line being indented. Each element in this list is actually a
1915cons cell of the syntactic symbol and a buffer position. This buffer
1916position is call the relative indent point for the line. Some
1917syntactic symbols may not have a relative indent point associated with
1918them.
1919
5eabfe72 1920After the syntactic context list for a line is generated, `vhdl-mode'
d2ddb974
KH
1921calculates the absolute indentation for the line by looking at each
1922syntactic element in the list. First, it compares the syntactic
1923element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1924finds a match, it adds the OFFSET to the column of the relative indent
1925point. The sum of this calculation for each element in the syntactic
1926list is the absolute offset for line being indented.
1927
1928If the syntactic element does not match any in the `vhdl-offsets-alist',
1929an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1930the element is ignored.
1931
1932Actually, OFFSET can be an integer, a function, a variable, or one of
1933the following symbols: `+', `-', `++', or `--'. These latter
1934designate positive or negative multiples of `vhdl-basic-offset',
5eabfe72 1935respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
d2ddb974
KH
1936called with a single argument containing the cons of the syntactic
1937element symbol and the relative indent point. The function should
1938return an integer offset.
1939
1940Here is the current list of valid syntactic element symbols:
1941
1942 string -- inside multi-line string
1943 block-open -- statement block open
1944 block-close -- statement block close
1945 statement -- a VHDL statement
1946 statement-cont -- a continuation of a VHDL statement
1947 statement-block-intro -- the first line in a new statement block
1948 statement-case-intro -- the first line in a case alternative block
1949 case-alternative -- a case statement alternative clause
1950 comment -- a line containing only a comment
1951 arglist-intro -- the first line in an argument list
1952 arglist-cont -- subsequent argument list lines when no
1953 arguments follow on the same line as the
1954 the arglist opening paren
1955 arglist-cont-nonempty -- subsequent argument list lines when at
1956 least one argument follows on the same
1957 line as the arglist opening paren
1958 arglist-close -- the solo close paren of an argument list
1959 entity -- inside an entity declaration
1960 configuration -- inside a configuration declaration
1961 package -- inside a package declaration
1962 architecture -- inside an architecture body
5eabfe72 1963 package-body -- inside a package body")
d2ddb974
KH
1964
1965(defvar vhdl-comment-only-line-offset 0
1966 "*Extra offset for line which contains only the start of a comment.
1967Can contain an integer or a cons cell of the form:
1968
1969 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1970
1971Where NON-ANCHORED-OFFSET is the amount of offset given to
1972non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1973the amount of offset to give column-zero anchored comment-only lines.
1974Just an integer as value is equivalent to (<val> . 0)")
1975
1976(defvar vhdl-special-indent-hook nil
1977 "*Hook for user defined special indentation adjustments.
1978This hook gets called after a line is indented by the mode.")
1979
1980(defvar vhdl-style-alist
1981 '(("IEEE"
1982 (vhdl-basic-offset . 4)
3dcb36b7 1983 (vhdl-offsets-alist . ())))
d2ddb974
KH
1984 "Styles of Indentation.
1985Elements of this alist are of the form:
1986
1987 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1988
1989where STYLE-STRING is a short descriptive string used to select a
5eabfe72 1990style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
d2ddb974
KH
1991value for that variable when using the selected style.
1992
1993There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1994case, the VALUE is a list containing elements of the form:
1995
1996 (SYNTACTIC-SYMBOL . VALUE)
1997
1998as described in `vhdl-offsets-alist'. These are passed directly to
1999`vhdl-set-offset' so there is no need to set every syntactic symbol in
2000your style, only those that are different from the default.")
2001
2002;; dynamically append the default value of most variables
2003(or (assoc "Default" vhdl-style-alist)
2004 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2005 vhdl-strict-syntax-p
2006 vhdl-echo-syntactic-information-p
2007 vhdl-basic-offset
2008 vhdl-offsets-alist
2009 vhdl-comment-only-line-offset))
2010 (default (cons "Default"
2011 (mapcar
2012 (function
2013 (lambda (var)
5eabfe72 2014 (cons var (symbol-value var))))
d2ddb974
KH
2015 varlist))))
2016 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2017
2018(defvar vhdl-mode-hook nil
2019 "*Hook called by `vhdl-mode'.")
2020
2021
5eabfe72 2022;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2023;;; Required packages
5eabfe72 2024;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5eabfe72 2025
3dcb36b7 2026;; mandatory
5eabfe72 2027(require 'assoc)
3dcb36b7
JB
2028(require 'compile) ; XEmacs
2029(require 'easymenu)
2030(require 'hippie-exp)
2031
2032;; optional (minimize warning messages during compile)
2033(eval-when-compile
2034 (require 'font-lock)
2035 (require 'ps-print)
2036 (require 'speedbar))
5eabfe72
KH
2037
2038
2039;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2040;;; Compatibility
5eabfe72 2041;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 2042
3dcb36b7
JB
2043;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2044;; XEmacs compatibility
d2ddb974 2045
3dcb36b7 2046;; active regions
d2ddb974 2047(defun vhdl-keep-region-active ()
5eabfe72
KH
2048 "Do whatever is necessary to keep the region active in XEmacs.
2049Ignore byte-compiler warnings you might see."
d2ddb974
KH
2050 (and (boundp 'zmacs-region-stays)
2051 (setq zmacs-region-stays t)))
2052
3dcb36b7 2053;; `wildcard-to-regexp' is included only in XEmacs 21
5eabfe72
KH
2054(unless (fboundp 'wildcard-to-regexp)
2055 (defun wildcard-to-regexp (wildcard)
2056 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2057 (let* ((i (string-match "[*?]" wildcard))
2058 (result (substring wildcard 0 i))
2059 (len (length wildcard)))
2060 (when i
2061 (while (< i len)
2062 (let ((ch (aref wildcard i)))
2063 (setq result (concat result
2064 (cond ((eq ch ?*) "[^\000]*")
2065 ((eq ch ??) "[^\000]")
2066 (t (char-to-string ch)))))
2067 (setq i (1+ i)))))
2068 (concat "\\`" result "\\'"))))
2069
3dcb36b7
JB
2070;; `regexp-opt' undefined (`xemacs-devel' not installed)
2071;; `regexp-opt' accelerates fontification by 10-20%
2072(unless (fboundp 'regexp-opt)
2073; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2074 (defun regexp-opt (strings &optional paren)
2075 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2076 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2077
2078;; `match-string-no-properties' undefined (XEmacs, what else?)
2079(unless (fboundp 'match-string-no-properties)
2080 (defalias 'match-string-no-properties 'match-string))
2081
2082;; `subst-char-in-string' undefined (XEmacs)
2083(unless (fboundp 'subst-char-in-string)
2084 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2085 (let ((i (length string))
2086 (newstr (if inplace string (copy-sequence string))))
2087 (while (> i 0)
2088 (setq i (1- i))
2089 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2090 newstr)))
2091
2092;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2093(when (and vhdl-xemacs (string< itimer-version "1.09")
2094 (not noninteractive))
2095 (load "itimer")
2096 (when (string< itimer-version "1.09")
2097 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2098 (beep) (sit-for 5)))
2099
2100;; `file-expand-wildcards' undefined (XEmacs)
2101(unless (fboundp 'file-expand-wildcards)
2102 (defun file-expand-wildcards (pattern &optional full)
2103 "Taken from Emacs' `files.el'."
2104 (let* ((nondir (file-name-nondirectory pattern))
2105 (dirpart (file-name-directory pattern))
2106 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2107 (mapcar 'file-name-as-directory
2108 (file-expand-wildcards (directory-file-name dirpart)))
2109 (list dirpart)))
2110 contents)
2111 (while dirs
2112 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2113 (file-directory-p (directory-file-name (car dirs))))
2114 (let ((this-dir-contents
2115 (delq nil
2116 (mapcar #'(lambda (name)
2117 (unless (string-match "\\`\\.\\.?\\'"
2118 (file-name-nondirectory name))
2119 name))
2120 (directory-files (or (car dirs) ".") full
2121 (wildcard-to-regexp nondir))))))
2122 (setq contents
2123 (nconc
2124 (if (and (car dirs) (not full))
2125 (mapcar (function (lambda (name) (concat (car dirs) name)))
2126 this-dir-contents)
2127 this-dir-contents)
2128 contents))))
2129 (setq dirs (cdr dirs)))
2130 contents)))
5eabfe72 2131
0a2e512a
RF
2132;; `member-ignore-case' undefined (XEmacs)
2133(unless (fboundp 'member-ignore-case)
2134 (defalias 'member-ignore-case 'member))
2135
5eabfe72 2136;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2137;; Compatibility with older VHDL Mode versions
5eabfe72 2138
3dcb36b7
JB
2139(defvar vhdl-warnings nil
2140 "Warnings to tell the user during start up.")
d2ddb974 2141
3dcb36b7
JB
2142(defun vhdl-run-when-idle (secs repeat function)
2143 "Wait until idle, then run FUNCTION."
4bcb9c95 2144 (if (fboundp 'start-itimer)
3dcb36b7
JB
2145 (start-itimer "vhdl-mode" function secs repeat t)
2146; (run-with-idle-timer secs repeat function)))
2147 ;; explicitely activate timer (necessary when Emacs is already idle)
2148 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2149
2150(defun vhdl-warning-when-idle (&rest args)
2151 "Wait until idle, then print out warning STRING and beep."
2152 (if noninteractive
2153 (vhdl-warning (apply 'format args) t)
2154 (unless vhdl-warnings
2155 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2156 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2157
2158(defun vhdl-warning (string &optional nobeep)
2159 "Print out warning STRING and beep."
29a4e67d 2160 (message "WARNING: %s" string)
3dcb36b7 2161 (unless (or nobeep noninteractive) (beep)))
d2ddb974 2162
3dcb36b7
JB
2163(defun vhdl-print-warnings ()
2164 "Print out messages in variable `vhdl-warnings'."
2165 (let ((no-warnings (length vhdl-warnings)))
2166 (setq vhdl-warnings (nreverse vhdl-warnings))
2167 (while vhdl-warnings
29a4e67d 2168 (message "WARNING: %s" (car vhdl-warnings))
3dcb36b7
JB
2169 (setq vhdl-warnings (cdr vhdl-warnings)))
2170 (beep)
2171 (when (> no-warnings 1)
2172 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2173
2174;; Backward compatibility checks and fixes
2175;; option `vhdl-compiler' changed format
2176(unless (stringp vhdl-compiler)
2177 (setq vhdl-compiler "ModelSim")
2178 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2179
2180;; option `vhdl-standard' changed format
2181(unless (listp vhdl-standard)
2182 (setq vhdl-standard '(87 nil))
2183 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2184
2185;; option `vhdl-model-alist' changed format
2186(when (= (length (car vhdl-model-alist)) 3)
2187 (let ((old-alist vhdl-model-alist)
2188 new-alist)
2189 (while old-alist
2190 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2191 (setq old-alist (cdr old-alist)))
2192 (setq vhdl-model-alist (nreverse new-alist)))
2193 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2194
2195;; option `vhdl-project-alist' changed format
2196(when (= (length (car vhdl-project-alist)) 3)
2197 (let ((old-alist vhdl-project-alist)
2198 new-alist)
2199 (while old-alist
2200 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2201 (setq old-alist (cdr old-alist)))
2202 (setq vhdl-project-alist (nreverse new-alist)))
2203 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2204
2205;; option `vhdl-project-alist' changed format (3.31.1)
2206(when (= (length (car vhdl-project-alist)) 4)
2207 (let ((old-alist vhdl-project-alist)
2208 new-alist elem)
2209 (while old-alist
2210 (setq elem (car old-alist))
2211 (setq new-alist
2212 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2213 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2214 new-alist))
2215 (setq old-alist (cdr old-alist)))
2216 (setq vhdl-project-alist (nreverse new-alist)))
2217 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2218
2219;; option `vhdl-project-alist' changed format (3.31.12)
2220(when (= (length (car vhdl-project-alist)) 10)
2221 (let ((tmp-alist vhdl-project-alist))
2222 (while tmp-alist
2223 (setcdr (nthcdr 3 (car tmp-alist))
2224 (cons "" (nthcdr 4 (car tmp-alist))))
2225 (setq tmp-alist (cdr tmp-alist))))
2226 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2227
2228;; option `vhdl-compiler-alist' changed format (3.31.1)
2229(when (= (length (car vhdl-compiler-alist)) 7)
2230 (let ((old-alist vhdl-compiler-alist)
2231 new-alist elem)
2232 (while old-alist
2233 (setq elem (car old-alist))
2234 (setq new-alist
2235 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2236 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2237 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2238 (nth 5 elem) (nth 6 elem) nil)
2239 new-alist))
2240 (setq old-alist (cdr old-alist)))
2241 (setq vhdl-compiler-alist (nreverse new-alist)))
2242 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2243
2244;; option `vhdl-compiler-alist' changed format (3.31.10)
2245(when (= (length (car vhdl-compiler-alist)) 12)
2246 (let ((tmp-alist vhdl-compiler-alist))
2247 (while tmp-alist
2248 (setcdr (nthcdr 4 (car tmp-alist))
2249 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2250 (setq tmp-alist (cdr tmp-alist))))
2251 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2252
2253;; option `vhdl-compiler-alist' changed format (3.31.11)
2254(when (= (length (car vhdl-compiler-alist)) 13)
2255 (let ((tmp-alist vhdl-compiler-alist))
2256 (while tmp-alist
2257 (setcdr (nthcdr 3 (car tmp-alist))
2258 (cons "" (nthcdr 4 (car tmp-alist))))
2259 (setq tmp-alist (cdr tmp-alist))))
2260 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2261
2262;; option `vhdl-compiler-alist' changed format (3.32.7)
2263(when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2264 (let ((tmp-alist vhdl-compiler-alist))
2265 (while tmp-alist
2266 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2267 '(0 . nil))
2268 (setq tmp-alist (cdr tmp-alist))))
2269 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2270
2271;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2272(when (equal vhdl-project "")
2273 (setq vhdl-project nil)
2274 (customize-save-variable 'vhdl-project vhdl-project))
2275
2276;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2277(when (stringp vhdl-project-file-name)
2278 (setq vhdl-project-file-name (list vhdl-project-file-name))
2279 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2280
2281;; option `speedbar-indentation-width': introduced in speedbar 0.10
2282(if (not (boundp 'speedbar-indentation-width))
2283 (defvar speedbar-indentation-width 2)
2284 ;; set default to 2 if not already customized
2285 (unless (get 'speedbar-indentation-width 'saved-value)
2286 (setq speedbar-indentation-width 2)))
2287
2288
2289;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2290;;; Help functions / inline substitutions / macros
2291;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2292
2293(defun vhdl-standard-p (standard)
2294 "Check if STANDARD is specified as used standard."
2295 (or (eq standard (car vhdl-standard))
2296 (memq standard (cadr vhdl-standard))))
2297
2298(defun vhdl-project-p (&optional warning)
2299 "Return non-nil if a project is displayed, i.e. directories or files are
2300specified."
2301 (if (assoc vhdl-project vhdl-project-alist)
2302 vhdl-project
2303 (when (and vhdl-project warning)
2304 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2305 nil))
2306
2307(defun vhdl-resolve-env-variable (string)
2308 "Resolve environment variables in STRING."
2309 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2310 (setq string (concat (match-string 1 string)
2311 (getenv (match-string 2 string))
2312 (match-string 4 string))))
2313 string)
2314
2315(defun vhdl-default-directory ()
2316 "Return the default directory of the current project or the directory of the
2317current buffer if no project is defined."
2318 (if (vhdl-project-p)
2319 (expand-file-name (vhdl-resolve-env-variable
2320 (nth 1 (aget vhdl-project-alist vhdl-project))))
2321 default-directory))
2322
2323(defmacro vhdl-prepare-search-1 (&rest body)
2324 "Enable case insensitive search and switch to syntax table that includes '_',
2325then execute BODY, and finally restore the old environment. Used for
2326consistent searching."
2327 `(let ((case-fold-search t) ; case insensitive search
2328 (current-syntax-table (syntax-table))
2329 result
2330 (restore-prog ; program to restore enviroment
2331 '(progn
2332 ;; restore syntax table
2333 (set-syntax-table current-syntax-table))))
2334 ;; use extended syntax table
2335 (set-syntax-table vhdl-mode-ext-syntax-table)
2336 ;; execute BODY safely
2337 (setq result
2338 (condition-case info
2339 (progn ,@body)
2340 (error (eval restore-prog) ; restore environment on error
2341 (error (cadr info))))) ; pass error up
2342 ;; restore environment
2343 (eval restore-prog)
2344 result))
2345
2346(defmacro vhdl-prepare-search-2 (&rest body)
2347 "Enable case insensitive search, switch to syntax table that includes '_',
2348and remove `intangible' overlays, then execute BODY, and finally restore the
2349old environment. Used for consistent searching."
2350 `(let ((case-fold-search t) ; case insensitive search
2351 (current-syntax-table (syntax-table))
2352 result overlay-all-list overlay-intangible-list overlay
2353 (restore-prog ; program to restore enviroment
2354 '(progn
2355 ;; restore syntax table
2356 (set-syntax-table current-syntax-table)
2357 ;; restore `intangible' overlays
2358 (when (fboundp 'overlay-lists)
2359 (while overlay-intangible-list
2360 (overlay-put (car overlay-intangible-list) 'intangible t)
2361 (setq overlay-intangible-list
2362 (cdr overlay-intangible-list)))))))
2363 ;; use extended syntax table
2364 (set-syntax-table vhdl-mode-ext-syntax-table)
2365 ;; remove `intangible' overlays
2366 (when (fboundp 'overlay-lists)
2367 (setq overlay-all-list (overlay-lists))
2368 (setq overlay-all-list
2369 (append (car overlay-all-list) (cdr overlay-all-list)))
2370 (while overlay-all-list
2371 (setq overlay (car overlay-all-list))
2372 (when (memq 'intangible (overlay-properties overlay))
2373 (setq overlay-intangible-list
2374 (cons overlay overlay-intangible-list))
2375 (overlay-put overlay 'intangible nil))
2376 (setq overlay-all-list (cdr overlay-all-list))))
2377 ;; execute BODY safely
2378 (setq result
2379 (condition-case info
2380 (progn ,@body)
2381 (error (eval restore-prog) ; restore environment on error
2382 (error (cadr info))))) ; pass error up
2383 ;; restore environment
2384 (eval restore-prog)
2385 result))
2386
2387(defmacro vhdl-visit-file (file-name issue-error &rest body)
2388 "Visit file FILE-NAME and execute BODY."
2389 `(if (null ,file-name)
2390 (progn ,@body)
2391 (unless (file-directory-p ,file-name)
2392 (let ((source-buffer (current-buffer))
2393 (visiting-buffer (find-buffer-visiting ,file-name))
2394 file-opened)
2395 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2396 (condition-case ()
2397 (progn (set-buffer (create-file-buffer ,file-name))
2398 (setq file-opened t)
2399 (vhdl-insert-file-contents ,file-name)
2400 (modify-syntax-entry ?\- ". 12" (syntax-table))
2401 (modify-syntax-entry ?\n ">" (syntax-table))
2402 (modify-syntax-entry ?\^M ">" (syntax-table))
2403 (modify-syntax-entry ?_ "w" (syntax-table))
2404 t)
2405 (error
2406 (if ,issue-error
2407 (progn
2408 (when file-opened (kill-buffer (current-buffer)))
2409 (set-buffer source-buffer)
ec3ec9cc 2410 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
3dcb36b7
JB
2411 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2412 nil))))
2413 (condition-case info
2414 (progn ,@body)
2415 (error
2416 (if ,issue-error
2417 (progn
2418 (when file-opened (kill-buffer (current-buffer)))
2419 (set-buffer source-buffer)
2420 (error (cadr info)))
2421 (vhdl-warning (cadr info))))))
2422 (when file-opened (kill-buffer (current-buffer)))
2423 (set-buffer source-buffer)))))
2424
2425(defun vhdl-insert-file-contents (filename)
2426 "Nicked from `insert-file-contents-literally', but allow coding system
2427conversion."
2428 (let ((format-alist nil)
2429 (after-insert-file-functions nil)
2430 (jka-compr-compression-info-list nil))
2431 (insert-file-contents filename t)))
2432
2433(defun vhdl-sort-alist (alist)
2434 "Sort alist."
2435 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2436
2437(defun vhdl-get-subdirs (directory)
2438 "Recursively get subdirectories of DIRECTORY."
2439 (let ((dir-list (list (file-name-as-directory directory)))
2440 file-list)
2441 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2442 (while file-list
2443 (when (file-directory-p (car file-list))
2444 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2445 (setq file-list (cdr file-list)))
2446 dir-list))
2447
2448(defun vhdl-aput (alist-symbol key &optional value)
2449 "As `aput', but delete key-value pair if VALUE is nil."
2450 (if value
2451 (aput alist-symbol key value)
2452 (adelete alist-symbol key)))
2453
2454(defun vhdl-delete (elt list)
2455 "Delete by side effect the first occurrence of ELT as a member of LIST."
2456 (setq list (cons nil list))
2457 (let ((list1 list))
2458 (while (and (cdr list1) (not (equal elt (cadr list1))))
2459 (setq list1 (cdr list1)))
2460 (when list
2461 (setcdr list1 (cddr list1))))
2462 (cdr list))
2463
2464(defun vhdl-speedbar-refresh (&optional key)
2465 "Refresh directory or project with name KEY."
2466 (when (and (boundp 'speedbar-frame)
2467 (frame-live-p speedbar-frame))
2468 (let ((pos (point))
2469 (last-frame (selected-frame)))
2470 (if (null key)
2471 (speedbar-refresh)
2472 (select-frame speedbar-frame)
2473 (when (save-excursion
2474 (goto-char (point-min))
2475 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2476 (goto-char (match-end 1))
2477 (speedbar-do-function-pointer)
2478 (backward-char 2)
2479 (speedbar-do-function-pointer)
2480 (message "Refreshing speedbar...done"))
2481 (select-frame last-frame)))))
2482
2483(defun vhdl-show-messages ()
2484 "Get *Messages* buffer to show recent messages."
2485 (interactive)
2486 (display-buffer (if vhdl-xemacs " *Message-Log*" "*Messages*")))
2487
2488(defun vhdl-use-direct-instantiation ()
2489 "Return whether direct instantiation is used."
2490 (or (eq vhdl-use-direct-instantiation 'always)
2491 (and (eq vhdl-use-direct-instantiation 'standard)
2492 (not (vhdl-standard-p '87)))))
2493
2494(defun vhdl-max-marker (marker1 marker2)
2495 "Return larger marker."
2496 (if (> marker1 marker2) marker1 marker2))
2497
2498(defun vhdl-goto-marker (marker)
2499 "Goto marker in appropriate buffer."
2500 (when (markerp marker)
2501 (set-buffer (marker-buffer marker)))
2502 (goto-char marker))
2503
2504(defun vhdl-menu-split (list title)
2505 "Split menu LIST into several submenues, if number of
2506elements > `vhdl-menu-max-size'."
2507 (if (> (length list) vhdl-menu-max-size)
2508 (let ((remain list)
2509 (result '())
2510 (sublist '())
2511 (menuno 1)
2512 (i 0))
2513 (while remain
2514 (setq sublist (cons (car remain) sublist))
2515 (setq remain (cdr remain))
2516 (setq i (+ i 1))
2517 (if (= i vhdl-menu-max-size)
2518 (progn
2519 (setq result (cons (cons (format "%s %s" title menuno)
2520 (nreverse sublist)) result))
2521 (setq i 0)
2522 (setq menuno (+ menuno 1))
2523 (setq sublist '()))))
2524 (and sublist
2525 (setq result (cons (cons (format "%s %s" title menuno)
2526 (nreverse sublist)) result)))
2527 (nreverse result))
2528 list))
2529
2530
2531;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2532;;; Bindings
2533;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2534
2535;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2536;; Key bindings
2537
2538(defvar vhdl-template-map nil
2539 "Keymap for VHDL templates.")
2540
2541(defun vhdl-template-map-init ()
2542 "Initialize `vhdl-template-map'."
2543 (setq vhdl-template-map (make-sparse-keymap))
2544 ;; key bindings for VHDL templates
2545 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2546 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2547 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2548 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2549 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2550 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2551 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2552 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2553 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
5eabfe72
KH
2554 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2555 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2556 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2557 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2558 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2559 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2560 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2561 (define-key vhdl-template-map "el" 'vhdl-template-else)
2562 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2563 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2564 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2565 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2566 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2567 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2568 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2569 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2570 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2571 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2572 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2573 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2574 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2575 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2576 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2577 (define-key vhdl-template-map "li" 'vhdl-template-library)
2578 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2579 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2580 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2581 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2582 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2583 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2584 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2585 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2586 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2587 (define-key vhdl-template-map "po" 'vhdl-template-port)
2588 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2589 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2590 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2591 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2592 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2593 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2594 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2595 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2596 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2597 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2598 (define-key vhdl-template-map "us" 'vhdl-template-use)
2599 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2600 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2601 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2602 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2603 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2604 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2605 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2606 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2607 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2608 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2609 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2610 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2611 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2612 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2613 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2614 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2615 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2616 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2617 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2618 (when (vhdl-standard-p 'ams)
2619 (define-key vhdl-template-map "br" 'vhdl-template-break)
2620 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2621 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2622 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2623 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2624 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2625 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2626 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2627 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2628 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2629 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2630 )
2631 (when (vhdl-standard-p 'math)
2632 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2633 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2634 ))
2635
2636;; initialize template map for VHDL Mode
2637(vhdl-template-map-init)
2638
2639(defun vhdl-function-name (prefix string &optional postfix)
2640 "Generate a Lisp function name.
2641PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2642STRING are replaced by `-' and substrings are converted to lower case."
2643 (let ((name prefix))
2644 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2645 (setq name
2646 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2647 (setq string (substring string (match-beginning 2))))
2648 (when postfix (setq name (concat name "-" postfix)))
2649 (intern name)))
2650
3dcb36b7 2651(defvar vhdl-model-map nil
5eabfe72
KH
2652 "Keymap for VHDL models.")
2653
2654(defun vhdl-model-map-init ()
2655 "Initialize `vhdl-model-map'."
2656 (setq vhdl-model-map (make-sparse-keymap))
2657 ;; key bindings for VHDL models
2658 (let ((model-alist vhdl-model-alist) model)
2659 (while model-alist
2660 (setq model (car model-alist))
2661 (define-key vhdl-model-map (nth 2 model)
2662 (vhdl-function-name "vhdl-model" (nth 0 model)))
2663 (setq model-alist (cdr model-alist)))))
2664
2665;; initialize user model map for VHDL Mode
2666(vhdl-model-map-init)
d2ddb974 2667
3dcb36b7 2668(defvar vhdl-mode-map nil
d2ddb974
KH
2669 "Keymap for VHDL Mode.")
2670
5eabfe72
KH
2671(defun vhdl-mode-map-init ()
2672 "Initialize `vhdl-mode-map'."
d2ddb974 2673 (setq vhdl-mode-map (make-sparse-keymap))
5eabfe72 2674 ;; template key bindings
0a2e512a 2675 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
5eabfe72 2676 ;; model key bindings
0a2e512a 2677 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
d2ddb974 2678 ;; standard key bindings
0a2e512a
RF
2679 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2680 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2681 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2682 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2683 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2684 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2685 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
3dcb36b7 2686 (unless vhdl-xemacs ; would override `M-backspace' in XEmacs
0a2e512a
RF
2687 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2688 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2689 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
5eabfe72 2690 ;; backspace/delete key bindings
0a2e512a 2691 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
3dcb36b7 2692 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
0a2e512a 2693 (define-key vhdl-mode-map [delete] 'delete-char)
3dcb36b7 2694 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
5eabfe72 2695 ;; mode specific key bindings
3dcb36b7
JB
2696 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2697 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2698 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2699 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2700 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2701 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2702 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
0a2e512a 2703 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
5eabfe72 2704 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
3dcb36b7 2705 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
5eabfe72
KH
2706 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2707 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2708 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2709 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2710 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2711 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2712 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
3dcb36b7 2713 (if vhdl-xemacs ; `... C-g' not allowed in XEmacs
5eabfe72
KH
2714 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2715 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
3dcb36b7 2716 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
5eabfe72
KH
2717 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2718 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
3dcb36b7
JB
2719 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2720 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2721 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2722 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2723 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2724 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2725 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2726 (define-key vhdl-mode-map "\C-c\C-c\C-n" 'vhdl-compose-new-component)
2727 (define-key vhdl-mode-map "\C-c\C-c\C-p" 'vhdl-compose-place-component)
2728 (define-key vhdl-mode-map "\C-c\C-c\C-w" 'vhdl-compose-wire-components)
0a2e512a 2729 (define-key vhdl-mode-map "\C-c\C-c\C-f" 'vhdl-compose-configuration)
3dcb36b7
JB
2730 (define-key vhdl-mode-map "\C-c\C-c\C-k" 'vhdl-compose-components-package)
2731 (define-key vhdl-mode-map "\C-cc" 'vhdl-comment-uncomment-region)
0a2e512a
RF
2732 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2733 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
3dcb36b7
JB
2734 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2735 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
0a2e512a 2736 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
3dcb36b7
JB
2737 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2738 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2739 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2740 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2741 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2742 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2743 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2744 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2745 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2746 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2747 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2748 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2749 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2750 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2751 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
5eabfe72
KH
2752 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2753 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2754 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2755 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2756 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2757 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2758 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2759 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2760 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
3dcb36b7
JB
2761 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2762 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2763 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2764 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2765 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
0a2e512a
RF
2766 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2767 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
3dcb36b7
JB
2768 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2769 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
0a2e512a
RF
2770 (define-key vhdl-mode-map "\C-cf" 'vhdl-fontify-buffer)
2771 (define-key vhdl-mode-map "\C-cs" 'vhdl-statistics-buffer)
2772 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2773 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2774 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2775 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
5eabfe72 2776 ;; insert commands bindings
3dcb36b7 2777 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
5eabfe72
KH
2778 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2779 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2780 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2781 ;; electric key bindings
0a2e512a
RF
2782 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2783 (when vhdl-intelligent-tab
2784 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2785 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2786 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2787 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2788 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2789 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2790 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2791 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2792 (define-key vhdl-mode-map "." 'vhdl-electric-period)
5eabfe72 2793 (when (vhdl-standard-p 'ams)
0a2e512a 2794 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
5eabfe72
KH
2795
2796;; initialize mode map for VHDL Mode
2797(vhdl-mode-map-init)
d2ddb974
KH
2798
2799;; define special minibuffer keymap for enabling word completion in minibuffer
2800;; (useful in template generator prompts)
4bcb9c95
SM
2801(defvar vhdl-minibuffer-local-map
2802 (let ((map (make-sparse-keymap)))
2803 (set-keymap-parent map minibuffer-local-map)
2804 (when vhdl-word-completion-in-minibuffer
2805 (define-key map "\t" 'vhdl-minibuffer-tab))
2806 map)
d2ddb974
KH
2807 "Keymap for minibuffer used in VHDL Mode.")
2808
5eabfe72
KH
2809;; set up electric character functions to work with
2810;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2811(mapcar
2812 (function
2813 (lambda (sym)
2814 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2815 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2816 '(vhdl-electric-space
2817 vhdl-electric-tab
2818 vhdl-electric-return
2819 vhdl-electric-dash
2820 vhdl-electric-open-bracket
2821 vhdl-electric-close-bracket
2822 vhdl-electric-quote
2823 vhdl-electric-semicolon
2824 vhdl-electric-comma
2825 vhdl-electric-period
2826 vhdl-electric-equal))
2827
3dcb36b7
JB
2828;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2829;; Syntax table
2830
d2ddb974 2831(defvar vhdl-mode-syntax-table nil
5eabfe72 2832 "Syntax table used in `vhdl-mode' buffers.")
d2ddb974 2833
3dcb36b7
JB
2834(defvar vhdl-mode-ext-syntax-table nil
2835 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2836
5eabfe72
KH
2837(defun vhdl-mode-syntax-table-init ()
2838 "Initialize `vhdl-mode-syntax-table'."
d2ddb974 2839 (setq vhdl-mode-syntax-table (make-syntax-table))
5eabfe72
KH
2840 ;; define punctuation
2841 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2842 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2843 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2844 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2845 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2846 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2847 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2848 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2849 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2850 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2851 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2852 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2853 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2854 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2855 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2856 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2857 ;; define string
2858 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2859 ;; define underscore
2860 (when vhdl-underscore-is-part-of-word
3dcb36b7 2861 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
5eabfe72
KH
2862 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2863 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2864 ;; and \n and \^M end a comment
2865 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2866 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2867 ;; define parentheses to match
2868 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2869 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2870 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2871 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2872 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
3dcb36b7
JB
2873 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2874 ;; extended syntax table including '_' (for simpler search regexps)
2875 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2876 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
5eabfe72
KH
2877
2878;; initialize syntax table for VHDL Mode
2879(vhdl-mode-syntax-table-init)
2880
d2ddb974
KH
2881(defvar vhdl-syntactic-context nil
2882 "Buffer local variable containing syntactic analysis list.")
2883(make-variable-buffer-local 'vhdl-syntactic-context)
2884
5eabfe72 2885;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2886;; Abbrev ook bindings
d2ddb974
KH
2887
2888(defvar vhdl-mode-abbrev-table nil
5eabfe72
KH
2889 "Abbrev table to use in `vhdl-mode' buffers.")
2890
2891(defun vhdl-mode-abbrev-table-init ()
2892 "Initialize `vhdl-mode-abbrev-table'."
2893 (when vhdl-mode-abbrev-table (clear-abbrev-table vhdl-mode-abbrev-table))
2894 (define-abbrev-table 'vhdl-mode-abbrev-table
2895 (append
2896 (when (memq 'vhdl vhdl-electric-keywords)
2897 ;; VHDL'93 keywords
2898 '(
0a2e512a
RF
2899 ("--" "" vhdl-template-display-comment-hook 0)
2900 ("abs" "" vhdl-template-default-hook 0)
2901 ("access" "" vhdl-template-default-hook 0)
2902 ("after" "" vhdl-template-default-hook 0)
2903 ("alias" "" vhdl-template-alias-hook 0)
2904 ("all" "" vhdl-template-default-hook 0)
2905 ("and" "" vhdl-template-default-hook 0)
2906 ("arch" "" vhdl-template-architecture-hook 0)
2907 ("architecture" "" vhdl-template-architecture-hook 0)
2908 ("array" "" vhdl-template-default-hook 0)
2909 ("assert" "" vhdl-template-assert-hook 0)
2910 ("attr" "" vhdl-template-attribute-hook 0)
2911 ("attribute" "" vhdl-template-attribute-hook 0)
2912 ("begin" "" vhdl-template-default-indent-hook 0)
2913 ("block" "" vhdl-template-block-hook 0)
2914 ("body" "" vhdl-template-default-hook 0)
2915 ("buffer" "" vhdl-template-default-hook 0)
2916 ("bus" "" vhdl-template-default-hook 0)
2917 ("case" "" vhdl-template-case-hook 0)
2918 ("comp" "" vhdl-template-component-hook 0)
2919 ("component" "" vhdl-template-component-hook 0)
2920 ("cond" "" vhdl-template-conditional-signal-asst-hook 0)
2921 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0)
2922 ("conf" "" vhdl-template-configuration-hook 0)
2923 ("configuration" "" vhdl-template-configuration-hook 0)
2924 ("cons" "" vhdl-template-constant-hook 0)
2925 ("constant" "" vhdl-template-constant-hook 0)
2926 ("disconnect" "" vhdl-template-disconnect-hook 0)
2927 ("downto" "" vhdl-template-default-hook 0)
2928 ("else" "" vhdl-template-else-hook 0)
2929 ("elseif" "" vhdl-template-elsif-hook 0)
2930 ("elsif" "" vhdl-template-elsif-hook 0)
2931 ("end" "" vhdl-template-default-indent-hook 0)
2932 ("entity" "" vhdl-template-entity-hook 0)
2933 ("exit" "" vhdl-template-exit-hook 0)
2934 ("file" "" vhdl-template-file-hook 0)
2935 ("for" "" vhdl-template-for-hook 0)
2936 ("func" "" vhdl-template-function-hook 0)
2937 ("function" "" vhdl-template-function-hook 0)
2938 ("generic" "" vhdl-template-generic-hook 0)
2939 ("group" "" vhdl-template-group-hook 0)
2940 ("guarded" "" vhdl-template-default-hook 0)
2941 ("if" "" vhdl-template-if-hook 0)
2942 ("impure" "" vhdl-template-default-hook 0)
2943 ("in" "" vhdl-template-default-hook 0)
2944 ("inertial" "" vhdl-template-default-hook 0)
2945 ("inout" "" vhdl-template-default-hook 0)
2946 ("inst" "" vhdl-template-instance-hook 0)
2947 ("instance" "" vhdl-template-instance-hook 0)
2948 ("is" "" vhdl-template-default-hook 0)
2949 ("label" "" vhdl-template-default-hook 0)
2950 ("library" "" vhdl-template-library-hook 0)
2951 ("linkage" "" vhdl-template-default-hook 0)
2952 ("literal" "" vhdl-template-default-hook 0)
2953 ("loop" "" vhdl-template-bare-loop-hook 0)
2954 ("map" "" vhdl-template-map-hook 0)
2955 ("mod" "" vhdl-template-default-hook 0)
2956 ("nand" "" vhdl-template-default-hook 0)
2957 ("new" "" vhdl-template-default-hook 0)
2958 ("next" "" vhdl-template-next-hook 0)
2959 ("nor" "" vhdl-template-default-hook 0)
2960 ("not" "" vhdl-template-default-hook 0)
2961 ("null" "" vhdl-template-default-hook 0)
2962 ("of" "" vhdl-template-default-hook 0)
2963 ("on" "" vhdl-template-default-hook 0)
2964 ("open" "" vhdl-template-default-hook 0)
2965 ("or" "" vhdl-template-default-hook 0)
2966 ("others" "" vhdl-template-others-hook 0)
2967 ("out" "" vhdl-template-default-hook 0)
2968 ("pack" "" vhdl-template-package-hook 0)
2969 ("package" "" vhdl-template-package-hook 0)
2970 ("port" "" vhdl-template-port-hook 0)
2971 ("postponed" "" vhdl-template-default-hook 0)
2972 ("procedure" "" vhdl-template-procedure-hook 0)
2973 ("process" "" vhdl-template-process-hook 0)
2974 ("pure" "" vhdl-template-default-hook 0)
2975 ("range" "" vhdl-template-default-hook 0)
2976 ("record" "" vhdl-template-default-hook 0)
2977 ("register" "" vhdl-template-default-hook 0)
2978 ("reject" "" vhdl-template-default-hook 0)
2979 ("rem" "" vhdl-template-default-hook 0)
2980 ("report" "" vhdl-template-report-hook 0)
2981 ("return" "" vhdl-template-return-hook 0)
2982 ("rol" "" vhdl-template-default-hook 0)
2983 ("ror" "" vhdl-template-default-hook 0)
2984 ("select" "" vhdl-template-selected-signal-asst-hook 0)
2985 ("severity" "" vhdl-template-default-hook 0)
2986 ("shared" "" vhdl-template-default-hook 0)
2987 ("sig" "" vhdl-template-signal-hook 0)
2988 ("signal" "" vhdl-template-signal-hook 0)
2989 ("sla" "" vhdl-template-default-hook 0)
2990 ("sll" "" vhdl-template-default-hook 0)
2991 ("sra" "" vhdl-template-default-hook 0)
2992 ("srl" "" vhdl-template-default-hook 0)
2993 ("subtype" "" vhdl-template-subtype-hook 0)
2994 ("then" "" vhdl-template-default-hook 0)
2995 ("to" "" vhdl-template-default-hook 0)
2996 ("transport" "" vhdl-template-default-hook 0)
2997 ("type" "" vhdl-template-type-hook 0)
2998 ("unaffected" "" vhdl-template-default-hook 0)
2999 ("units" "" vhdl-template-default-hook 0)
3000 ("until" "" vhdl-template-default-hook 0)
3001 ("use" "" vhdl-template-use-hook 0)
3002 ("var" "" vhdl-template-variable-hook 0)
3003 ("variable" "" vhdl-template-variable-hook 0)
3004 ("wait" "" vhdl-template-wait-hook 0)
3005 ("when" "" vhdl-template-when-hook 0)
3006 ("while" "" vhdl-template-while-loop-hook 0)
3007 ("with" "" vhdl-template-with-hook 0)
3008 ("xnor" "" vhdl-template-default-hook 0)
3009 ("xor" "" vhdl-template-default-hook 0)
5eabfe72
KH
3010 ))
3011 ;; VHDL-AMS keywords
3012 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3013 '(
0a2e512a
RF
3014 ("across" "" vhdl-template-default-hook 0)
3015 ("break" "" vhdl-template-break-hook 0)
3016 ("limit" "" vhdl-template-limit-hook 0)
3017 ("nature" "" vhdl-template-nature-hook 0)
3018 ("noise" "" vhdl-template-default-hook 0)
3019 ("procedural" "" vhdl-template-procedural-hook 0)
3020 ("quantity" "" vhdl-template-quantity-hook 0)
3021 ("reference" "" vhdl-template-default-hook 0)
3022 ("spectrum" "" vhdl-template-default-hook 0)
3023 ("subnature" "" vhdl-template-subnature-hook 0)
3024 ("terminal" "" vhdl-template-terminal-hook 0)
3025 ("through" "" vhdl-template-default-hook 0)
3026 ("tolerance" "" vhdl-template-default-hook 0)
5eabfe72
KH
3027 ))
3028 ;; user model keywords
3029 (when (memq 'user vhdl-electric-keywords)
3030 (let ((alist vhdl-model-alist)
3031 abbrev-list keyword)
3032 (while alist
3033 (setq keyword (nth 3 (car alist)))
3034 (unless (equal keyword "")
3035 (setq abbrev-list
3036 (cons (list keyword ""
3037 (vhdl-function-name
0a2e512a 3038 "vhdl-model" (nth 0 (car alist)) "hook") 0)
5eabfe72
KH
3039 abbrev-list)))
3040 (setq alist (cdr alist)))
3041 abbrev-list)))))
3042
3043;; initialize abbrev table for VHDL Mode
3044(vhdl-mode-abbrev-table-init)
3045
3046;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3047;; Template completion lists
3048
3049(defvar vhdl-template-construct-alist nil
3050 "List of built-in construct templates.")
3051
3052(defun vhdl-template-construct-alist-init ()
3053 "Initialize `vhdl-template-construct-alist'."
3054 (setq
3055 vhdl-template-construct-alist
3056 (append
3057 '(
3058 ("alias declaration" vhdl-template-alias)
3059 ("architecture body" vhdl-template-architecture)
3060 ("assertion" vhdl-template-assert)
3061 ("attribute declaration" vhdl-template-attribute-decl)
3062 ("attribute specification" vhdl-template-attribute-spec)
3063 ("block configuration" vhdl-template-block-configuration)
3064 ("block statement" vhdl-template-block)
3065 ("case statement" vhdl-template-case-is)
3066 ("component configuration" vhdl-template-component-conf)
3067 ("component declaration" vhdl-template-component-decl)
3068 ("component instantiation statement" vhdl-template-component-inst)
3069 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3070 ("configuration declaration" vhdl-template-configuration-decl)
3071 ("configuration specification" vhdl-template-configuration-spec)
3072 ("constant declaration" vhdl-template-constant)
3073 ("disconnection specification" vhdl-template-disconnect)
3074 ("entity declaration" vhdl-template-entity)
3075 ("exit statement" vhdl-template-exit)
3076 ("file declaration" vhdl-template-file)
3077 ("generate statement" vhdl-template-generate)
3078 ("generic clause" vhdl-template-generic)
3079 ("group declaration" vhdl-template-group-decl)
3080 ("group template declaration" vhdl-template-group-template)
3081 ("if statement" vhdl-template-if-then)
3082 ("library clause" vhdl-template-library)
3083 ("loop statement" vhdl-template-loop)
3084 ("next statement" vhdl-template-next)
3085 ("package declaration" vhdl-template-package-decl)
3086 ("package body" vhdl-template-package-body)
3087 ("port clause" vhdl-template-port)
3088 ("process statement" vhdl-template-process)
3089 ("report statement" vhdl-template-report)
3090 ("return statement" vhdl-template-return)
3091 ("selected signal assignment" vhdl-template-selected-signal-asst)
3092 ("signal declaration" vhdl-template-signal)
3093 ("subprogram declaration" vhdl-template-subprogram-decl)
3094 ("subprogram body" vhdl-template-subprogram-body)
3095 ("subtype declaration" vhdl-template-subtype)
3096 ("type declaration" vhdl-template-type)
3097 ("use clause" vhdl-template-use)
3098 ("variable declaration" vhdl-template-variable)
3099 ("wait statement" vhdl-template-wait)
3100 )
3101 (when (vhdl-standard-p 'ams)
3102 '(
3103 ("break statement" vhdl-template-break)
3104 ("nature declaration" vhdl-template-nature)
3105 ("quantity declaration" vhdl-template-quantity)
3106 ("simultaneous case statement" vhdl-template-case-use)
3107 ("simultaneous if statement" vhdl-template-if-use)
3108 ("simultaneous procedural statement" vhdl-template-procedural)
3109 ("step limit specification" vhdl-template-limit)
3110 ("subnature declaration" vhdl-template-subnature)
3111 ("terminal declaration" vhdl-template-terminal)
3112 )))))
d2ddb974 3113
5eabfe72
KH
3114;; initialize for VHDL Mode
3115(vhdl-template-construct-alist-init)
3116
3117(defvar vhdl-template-package-alist nil
3118 "List of built-in package templates.")
3119
3120(defun vhdl-template-package-alist-init ()
3121 "Initialize `vhdl-template-package-alist'."
3122 (setq
3123 vhdl-template-package-alist
3124 (append
3125 '(
3126 ("numeric_bit" vhdl-template-package-numeric-bit)
3127 ("numeric_std" vhdl-template-package-numeric-std)
3128 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3129 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3130 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3131 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3132 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3133 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3134 ("textio" vhdl-template-package-textio)
3135 )
3136 (when (vhdl-standard-p 'math)
3137 '(
3138 ("math_complex" vhdl-template-package-math-complex)
3139 ("math_real" vhdl-template-package-math-real)
3140 )))))
d2ddb974 3141
5eabfe72
KH
3142;; initialize for VHDL Mode
3143(vhdl-template-package-alist-init)
d2ddb974 3144
5eabfe72 3145(defvar vhdl-template-directive-alist
3dcb36b7
JB
3146 '(
3147 ("translate_on" vhdl-template-directive-translate-on)
3148 ("translate_off" vhdl-template-directive-translate-off)
3149 ("synthesis_on" vhdl-template-directive-synthesis-on)
3150 ("synthesis_off" vhdl-template-directive-synthesis-off)
3151 )
5eabfe72 3152 "List of built-in directive templates.")
d2ddb974 3153
5eabfe72
KH
3154
3155;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3156;;; Menues
3157;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3158
3159;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
3160;; VHDL menu (using `easy-menu.el')
3161
5eabfe72
KH
3162(defun vhdl-customize ()
3163 "Call the customize function with `vhdl' as argument."
3164 (interactive)
3165 (customize-browse 'vhdl))
3166
5eabfe72
KH
3167(defun vhdl-create-mode-menu ()
3168 "Create VHDL Mode menu."
3dcb36b7
JB
3169 `("VHDL"
3170 ,(append
3171 '("Project"
3172 ["None" (vhdl-set-project "")
3173 :style radio :selected (null vhdl-project)]
3174 "--")
3175 ;; add menu entries for defined projects
3176 (let ((project-alist vhdl-project-alist) menu-list name)
3177 (while project-alist
3178 (setq name (caar project-alist))
3179 (setq menu-list
3180 (cons `[,name (vhdl-set-project ,name)
3181 :style radio :selected (equal ,name vhdl-project)]
3182 menu-list))
3183 (setq project-alist (cdr project-alist)))
3184 (setq menu-list
3185 (if vhdl-project-sort
3186 (sort menu-list
3187 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3188 (nreverse menu-list)))
3189 (vhdl-menu-split menu-list "Project"))
3190 '("--" "--"
3191 ["Select Project..." vhdl-set-project t]
0a2e512a 3192 ["Set As Default Project" vhdl-set-default-project t]
3dcb36b7
JB
3193 "--"
3194 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3195 ["Import Project..." vhdl-import-project
3196 :keys "C-c C-p C-m" :active t]
3197 ["Export Project" vhdl-export-project vhdl-project]
3198 "--"
3199 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
d2ddb974 3200 "--"
3dcb36b7
JB
3201 ("Compile"
3202 ["Compile Buffer" vhdl-compile t]
3203 ["Stop Compilation" kill-compilation t]
3204 "--"
3205 ["Make" vhdl-make t]
3206 ["Generate Makefile" vhdl-generate-makefile t]
3207 "--"
3208 ["Next Error" next-error t]
3209 ["Previous Error" previous-error t]
3210 ["First Error" first-error t]
3211 "--"
3212 ,(append
3213 '("Compiler")
3214 ;; add menu entries for defined compilers
3215 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3216 (while comp-alist
3217 (setq name (caar comp-alist))
3218 (setq menu-list
3219 (cons `[,name (setq vhdl-compiler ,name)
3220 :style radio :selected (equal ,name vhdl-compiler)]
3221 menu-list))
3222 (setq comp-alist (cdr comp-alist)))
3223 (setq menu-list (nreverse menu-list))
3224 (vhdl-menu-split menu-list "Compiler"))
3225 '("--" "--"
3226 ["Select Compiler..." vhdl-set-compiler t]
3227 "--"
3228 ["Customize Compiler..."
3229 (customize-option 'vhdl-compiler-alist) t])))
5eabfe72 3230 "--"
3dcb36b7
JB
3231 ,(append
3232 '("Template"
3233 ("VHDL Construct 1"
3234 ["Alias" vhdl-template-alias t]
3235 ["Architecture" vhdl-template-architecture t]
3236 ["Assert" vhdl-template-assert t]
3237 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3238 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3239 ["Block" vhdl-template-block t]
3240 ["Case" vhdl-template-case-is t]
3241 ["Component (Decl)" vhdl-template-component-decl t]
3242 ["(Component) Instance" vhdl-template-component-inst t]
3243 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3244 ["Configuration (Block)" vhdl-template-block-configuration t]
3245 ["Configuration (Comp)" vhdl-template-component-conf t]
3246 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3247 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3248 ["Constant" vhdl-template-constant t]
3249 ["Disconnect" vhdl-template-disconnect t]
3250 ["Else" vhdl-template-else t]
3251 ["Elsif" vhdl-template-elsif t]
3252 ["Entity" vhdl-template-entity t]
3253 ["Exit" vhdl-template-exit t]
3254 ["File" vhdl-template-file t]
3255 ["For (Generate)" vhdl-template-for-generate t]
3256 ["For (Loop)" vhdl-template-for-loop t]
3257 ["Function (Body)" vhdl-template-function-body t]
3258 ["Function (Decl)" vhdl-template-function-decl t]
3259 ["Generic" vhdl-template-generic t]
3260 ["Group (Decl)" vhdl-template-group-decl t]
3261 ["Group (Template)" vhdl-template-group-template t])
3262 ("VHDL Construct 2"
3263 ["If (Generate)" vhdl-template-if-generate t]
3264 ["If (Then)" vhdl-template-if-then t]
3265 ["Library" vhdl-template-library t]
3266 ["Loop" vhdl-template-bare-loop t]
3267 ["Map" vhdl-template-map t]
3268 ["Next" vhdl-template-next t]
3269 ["Others (Aggregate)" vhdl-template-others t]
3270 ["Package (Decl)" vhdl-template-package-decl t]
3271 ["Package (Body)" vhdl-template-package-body t]
3272 ["Port" vhdl-template-port t]
3273 ["Procedure (Body)" vhdl-template-procedure-body t]
3274 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3275 ["Process (Comb)" vhdl-template-process-comb t]
3276 ["Process (Seq)" vhdl-template-process-seq t]
3277 ["Report" vhdl-template-report t]
3278 ["Return" vhdl-template-return t]
3279 ["Select" vhdl-template-selected-signal-asst t]
3280 ["Signal" vhdl-template-signal t]
3281 ["Subtype" vhdl-template-subtype t]
3282 ["Type" vhdl-template-type t]
3283 ["Use" vhdl-template-use t]
3284 ["Variable" vhdl-template-variable t]
3285 ["Wait" vhdl-template-wait t]
3286 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3287 ["When" vhdl-template-when t]
3288 ["While (Loop)" vhdl-template-while-loop t]
3289 ["With" vhdl-template-with t]))
3290 (when (vhdl-standard-p 'ams)
3291 '(("VHDL-AMS Construct"
3292 ["Break" vhdl-template-break t]
3293 ["Case (Use)" vhdl-template-case-use t]
3294 ["If (Use)" vhdl-template-if-use t]
3295 ["Limit" vhdl-template-limit t]
3296 ["Nature" vhdl-template-nature t]
3297 ["Procedural" vhdl-template-procedural t]
3298 ["Quantity (Free)" vhdl-template-quantity-free t]
3299 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3300 ["Quantity (Source)" vhdl-template-quantity-source t]
3301 ["Subnature" vhdl-template-subnature t]
3302 ["Terminal" vhdl-template-terminal t])))
3303 '(["Insert Construct..." vhdl-template-insert-construct
3304 :keys "C-c C-i C-t"]
3305 "--")
3306 (list
3307 (append
3308 '("Package")
3309 (when (vhdl-standard-p 'math)
3310 '(["math_complex" vhdl-template-package-math-complex t]
3311 ["math_real" vhdl-template-package-math-real t]))
3312 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3313 ["numeric_std" vhdl-template-package-numeric-std t]
3314 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3315 ["textio" vhdl-template-package-textio t]
3316 "--"
3317 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3318 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3319 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3320 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3321 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3322 "--"
3323 ["Insert Package..." vhdl-template-insert-package
3324 :keys "C-c C-i C-p"])))
3325 '(("Directive"
3326 ["translate_on" vhdl-template-directive-translate-on t]
3327 ["translate_off" vhdl-template-directive-translate-off t]
3328 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3329 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3330 "--"
3331 ["Insert Directive..." vhdl-template-insert-directive
3332 :keys "C-c C-i C-d"])
5eabfe72 3333 "--"
3dcb36b7
JB
3334 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3335 ["Insert Footer" vhdl-template-footer t]
3336 ["Insert Date" vhdl-template-insert-date t]
3337 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
5eabfe72 3338 "--"
3dcb36b7
JB
3339 ["Query Next Prompt" vhdl-template-search-prompt t]))
3340 ,(append
3341 '("Model")
3342 ;; add menu entries for defined models
3343 (let ((model-alist vhdl-model-alist) menu-list model)
3344 (while model-alist
3345 (setq model (car model-alist))
3346 (setq menu-list
3347 (cons
3348 (vector
3349 (nth 0 model)
3350 (vhdl-function-name "vhdl-model" (nth 0 model))
3351 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3352 menu-list))
3353 (setq model-alist (cdr model-alist)))
3354 (setq menu-list (nreverse menu-list))
3355 (vhdl-menu-split menu-list "Model"))
3356 '("--" "--"
3357 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3358 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3359 ("Port"
5eabfe72 3360 ["Copy" vhdl-port-copy t]
d2ddb974 3361 "--"
5eabfe72
KH
3362 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3363 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3364 ["Paste As Instance" vhdl-port-paste-instance
3365 :keys "C-c C-p C-i" :active vhdl-port-list]
3366 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3367 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3368 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3dcb36b7 3369 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
d2ddb974 3370 "--"
3dcb36b7
JB
3371 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3372 "--"
3373 ["Flatten" vhdl-port-flatten
3374 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3375 ["Reverse Direction" vhdl-port-reverse-direction
3376 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3377 ("Compose"
3378 ["New Component" vhdl-compose-new-component t]
0a2e512a 3379 ["Copy Component" vhdl-port-copy t]
3dcb36b7
JB
3380 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3381 ["Wire Components" vhdl-compose-wire-components t]
3382 "--"
0a2e512a 3383 ["Generate Configuration" vhdl-compose-configuration t]
3dcb36b7
JB
3384 ["Generate Components Package" vhdl-compose-components-package t])
3385 ("Subprogram"
3386 ["Copy" vhdl-subprog-copy t]
3387 "--"
3388 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3389 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3390 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3391 "--"
3392 ["Flatten" vhdl-subprog-flatten
3393 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3394 "--"
3395 ("Comment"
5eabfe72
KH
3396 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3397 "--"
3398 ["Insert Inline Comment" vhdl-comment-append-inline t]
3399 ["Insert Horizontal Line" vhdl-comment-display-line t]
3400 ["Insert Display Comment" vhdl-comment-display t]
3401 "--"
3402 ["Fill Comment" fill-paragraph t]
3403 ["Fill Comment Region" fill-region (mark)]
3404 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3dcb36b7
JB
3405 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3406 ("Line"
5eabfe72
KH
3407 ["Kill" vhdl-line-kill t]
3408 ["Copy" vhdl-line-copy t]
3409 ["Yank" vhdl-line-yank t]
3410 ["Expand" vhdl-line-expand t]
3411 "--"
3412 ["Transpose Next" vhdl-line-transpose-next t]
3413 ["Transpose Prev" vhdl-line-transpose-previous t]
3414 ["Open" vhdl-line-open t]
3dcb36b7 3415 ["Join" vhdl-delete-indentation t]
5eabfe72
KH
3416 "--"
3417 ["Goto" goto-line t]
3dcb36b7
JB
3418 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3419 ("Move"
5eabfe72
KH
3420 ["Forward Statement" vhdl-end-of-statement t]
3421 ["Backward Statement" vhdl-beginning-of-statement t]
3422 ["Forward Expression" vhdl-forward-sexp t]
3423 ["Backward Expression" vhdl-backward-sexp t]
3dcb36b7
JB
3424 ["Forward Same Indent" vhdl-forward-same-indent t]
3425 ["Backward Same Indent" vhdl-backward-same-indent t]
5eabfe72
KH
3426 ["Forward Function" vhdl-end-of-defun t]
3427 ["Backward Function" vhdl-beginning-of-defun t]
3dcb36b7
JB
3428 ["Mark Function" vhdl-mark-defun t])
3429 "--"
3430 ("Indent"
3431 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3432 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
5eabfe72 3433 ["Region" vhdl-indent-region (mark)]
3dcb36b7
JB
3434 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3435 ("Align"
5eabfe72 3436 ["Group" vhdl-align-group t]
3dcb36b7
JB
3437 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3438 ["List" vhdl-align-list t]
3439 ["Declarations" vhdl-align-declarations t]
3440 ["Region" vhdl-align-region (mark)]
3441 ["Buffer" vhdl-align-buffer t]
5eabfe72
KH
3442 "--"
3443 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3444 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3dcb36b7
JB
3445 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3446 ("Fill"
3447 ["List" vhdl-fill-list t]
3448 ["Group" vhdl-fill-group t]
3449 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3450 ["Region" vhdl-fill-region (mark)])
3451 ("Beautify"
3452 ["Region" vhdl-beautify-region (mark)]
3453 ["Buffer" vhdl-beautify-buffer t])
3454 ("Fix"
3455 ["Generic/Port Clause" vhdl-fix-clause t]
5eabfe72 3456 "--"
3dcb36b7
JB
3457 ["Case Region" vhdl-fix-case-region (mark)]
3458 ["Case Buffer" vhdl-fix-case-buffer t]
3459 "--"
3460 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3461 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3462 "--"
3463 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3464 ("Update"
3465 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3466 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3467 "--"
3468 ["Fontify Buffer" vhdl-fontify-buffer t]
3469 ["Statistics Buffer" vhdl-statistics-buffer t]
3470 ["Show Messages" vhdl-show-messages t]
3471 ["Syntactic Info" vhdl-show-syntactic-information t]
3472 "--"
3473 ["Speedbar" vhdl-speedbar t]
3474 ["Hide/Show" vhdl-hs-minor-mode t]
3475 "--"
3476 ("Documentation"
5eabfe72 3477 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3dcb36b7 3478 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
5eabfe72 3479 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3dcb36b7
JB
3480 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3481 ["Version" vhdl-version t]
3482 ["Bug Report..." vhdl-submit-bug-report t]
3483 "--"
3484 ("Options"
3485 ("Mode"
3486 ["Electric Mode"
3487 (progn (customize-set-variable 'vhdl-electric-mode
3488 (not vhdl-electric-mode))
3489 (vhdl-mode-line-update))
3490 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3491 ["Stutter Mode"
3492 (progn (customize-set-variable 'vhdl-stutter-mode
3493 (not vhdl-stutter-mode))
3494 (vhdl-mode-line-update))
3495 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3496 ["Indent Tabs Mode"
3497 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3498 (not vhdl-indent-tabs-mode))
3499 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3500 :style toggle :selected vhdl-indent-tabs-mode]
3501 "--"
3502 ["Customize Group..." (customize-group 'vhdl-mode) t])
3503 ("Project"
3504 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3505 ,(append
3506 '("Selected Project at Startup"
3507 ["None" (progn (customize-set-variable 'vhdl-project nil)
3508 (vhdl-set-project ""))
3509 :style radio :selected (null vhdl-project)]
3510 "--")
3511 ;; add menu entries for defined projects
3512 (let ((project-alist vhdl-project-alist) menu-list name)
3513 (while project-alist
3514 (setq name (caar project-alist))
3515 (setq menu-list
3516 (cons `[,name (progn (customize-set-variable
3517 'vhdl-project ,name)
3518 (vhdl-set-project ,name))
3519 :style radio :selected (equal ,name vhdl-project)]
3520 menu-list))
3521 (setq project-alist (cdr project-alist)))
3522 (setq menu-list (nreverse menu-list))
3523 (vhdl-menu-split menu-list "Project")))
3524 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3525 ("Auto Load Setup File"
3526 ["At Startup"
3527 (customize-set-variable 'vhdl-project-auto-load
3528 (if (memq 'startup vhdl-project-auto-load)
3529 (delq 'startup vhdl-project-auto-load)
3530 (cons 'startup vhdl-project-auto-load)))
3531 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3532 ["Sort Projects"
3533 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3534 :style toggle :selected vhdl-project-sort]
3535 "--"
3536 ["Customize Group..." (customize-group 'vhdl-project) t])
3537 ("Compiler"
3538 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3539 ,(append
3540 '("Selected Compiler at Startup")
3541 ;; add menu entries for defined compilers
3542 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3543 (while comp-alist
3544 (setq name (caar comp-alist))
3545 (setq menu-list
3546 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3547 :style radio :selected (equal ,name vhdl-compiler)]
3548 menu-list))
3549 (setq comp-alist (cdr comp-alist)))
3550 (setq menu-list (nreverse menu-list))
3551 (vhdl-menu-split menu-list "Compler")))
3552 ["Use Local Error Regexp"
3553 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3554 (not vhdl-compile-use-local-error-regexp))
3555 :style toggle :selected vhdl-compile-use-local-error-regexp]
3556 ["Makefile Generation Hook..."
3557 (customize-option 'vhdl-makefile-generation-hook) t]
3558 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3559 "--"
3560 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3561 ("Style"
3562 ("VHDL Standard"
3563 ["VHDL'87"
3564 (progn (customize-set-variable 'vhdl-standard
3565 (list '87 (cadr vhdl-standard)))
3566 (vhdl-activate-customizations))
3567 :style radio :selected (eq '87 (car vhdl-standard))]
3568 ["VHDL'93"
3569 (progn (customize-set-variable 'vhdl-standard
3570 (list '93 (cadr vhdl-standard)))
3571 (vhdl-activate-customizations))
3572 :style radio :selected (eq '93 (car vhdl-standard))]
3573 "--"
3574 ["VHDL-AMS"
3575 (progn (customize-set-variable
3576 'vhdl-standard (list (car vhdl-standard)
3577 (if (memq 'ams (cadr vhdl-standard))
3578 (delq 'ams (cadr vhdl-standard))
3579 (cons 'ams (cadr vhdl-standard)))))
3580 (vhdl-activate-customizations))
3581 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3582 ["Math Packages"
3583 (progn (customize-set-variable
3584 'vhdl-standard (list (car vhdl-standard)
3585 (if (memq 'math (cadr vhdl-standard))
3586 (delq 'math (cadr vhdl-standard))
3587 (cons 'math (cadr vhdl-standard)))))
3588 (vhdl-activate-customizations))
3589 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3590 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3591 ["Upper Case Keywords"
3592 (customize-set-variable 'vhdl-upper-case-keywords
3593 (not vhdl-upper-case-keywords))
3594 :style toggle :selected vhdl-upper-case-keywords]
3595 ["Upper Case Types"
3596 (customize-set-variable 'vhdl-upper-case-types
3597 (not vhdl-upper-case-types))
3598 :style toggle :selected vhdl-upper-case-types]
3599 ["Upper Case Attributes"
3600 (customize-set-variable 'vhdl-upper-case-attributes
3601 (not vhdl-upper-case-attributes))
3602 :style toggle :selected vhdl-upper-case-attributes]
3603 ["Upper Case Enumeration Values"
3604 (customize-set-variable 'vhdl-upper-case-enum-values
3605 (not vhdl-upper-case-enum-values))
3606 :style toggle :selected vhdl-upper-case-enum-values]
3607 ["Upper Case Constants"
3608 (customize-set-variable 'vhdl-upper-case-constants
3609 (not vhdl-upper-case-constants))
3610 :style toggle :selected vhdl-upper-case-constants]
3611 ("Use Direct Instantiation"
3612 ["Never"
3613 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3614 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3615 ["Standard"
3616 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3617 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3618 ["Always"
3619 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3620 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3621 "--"
3622 ["Customize Group..." (customize-group 'vhdl-style) t])
3623 ("Naming"
3624 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3625 ["Architecture File Name..."
3626 (customize-option 'vhdl-architecture-file-name) t]
0a2e512a
RF
3627 ["Configuration File Name..."
3628 (customize-option 'vhdl-configuration-file-name) t]
3dcb36b7
JB
3629 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3630 ("File Name Case"
3631 ["As Is"
3632 (customize-set-variable 'vhdl-file-name-case 'identity)
3633 :style radio :selected (eq 'identity vhdl-file-name-case)]
3634 ["Lower Case"
3635 (customize-set-variable 'vhdl-file-name-case 'downcase)
3636 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3637 ["Upper Case"
3638 (customize-set-variable 'vhdl-file-name-case 'upcase)
3639 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3640 ["Capitalize"
3641 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3642 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3643 "--"
3644 ["Customize Group..." (customize-group 'vhdl-naming) t])
3645 ("Template"
3646 ("Electric Keywords"
3647 ["VHDL Keywords"
3648 (customize-set-variable 'vhdl-electric-keywords
3649 (if (memq 'vhdl vhdl-electric-keywords)
3650 (delq 'vhdl vhdl-electric-keywords)
3651 (cons 'vhdl vhdl-electric-keywords)))
3652 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3653 ["User Model Keywords"
3654 (customize-set-variable 'vhdl-electric-keywords
3655 (if (memq 'user vhdl-electric-keywords)
3656 (delq 'user vhdl-electric-keywords)
3657 (cons 'user vhdl-electric-keywords)))
3658 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3659 ("Insert Optional Labels"
3660 ["None"
3661 (customize-set-variable 'vhdl-optional-labels 'none)
3662 :style radio :selected (eq 'none vhdl-optional-labels)]
3663 ["Processes Only"
3664 (customize-set-variable 'vhdl-optional-labels 'process)
3665 :style radio :selected (eq 'process vhdl-optional-labels)]
3666 ["All Constructs"
3667 (customize-set-variable 'vhdl-optional-labels 'all)
3668 :style radio :selected (eq 'all vhdl-optional-labels)])
3669 ("Insert Empty Lines"
3670 ["None"
3671 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3672 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3673 ["Design Units Only"
3674 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3675 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3676 ["All Constructs"
3677 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3678 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3679 ["Argument List Indent"
3680 (customize-set-variable 'vhdl-argument-list-indent
3681 (not vhdl-argument-list-indent))
3682 :style toggle :selected vhdl-argument-list-indent]
3683 ["Association List with Formals"
3684 (customize-set-variable 'vhdl-association-list-with-formals
3685 (not vhdl-association-list-with-formals))
3686 :style toggle :selected vhdl-association-list-with-formals]
3687 ["Conditions in Parenthesis"
3688 (customize-set-variable 'vhdl-conditions-in-parenthesis
3689 (not vhdl-conditions-in-parenthesis))
3690 :style toggle :selected vhdl-conditions-in-parenthesis]
3691 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3692 ["One String..." (customize-option 'vhdl-one-string) t]
3693 ("File Header"
3694 ["Header String..." (customize-option 'vhdl-file-header) t]
3695 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3696 ["Company Name..." (customize-option 'vhdl-company-name) t]
3697 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3698 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3699 ["Date Format..." (customize-option 'vhdl-date-format) t]
3700 ["Modify Date Prefix String..."
3701 (customize-option 'vhdl-modify-date-prefix-string) t]
3702 ["Modify Date on Saving"
3703 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3704 (not vhdl-modify-date-on-saving))
3705 (vhdl-activate-customizations))
3706 :style toggle :selected vhdl-modify-date-on-saving])
3707 ("Sequential Process"
3708 ("Kind of Reset"
3709 ["None"
3710 (customize-set-variable 'vhdl-reset-kind 'none)
3711 :style radio :selected (eq 'none vhdl-reset-kind)]
3712 ["Synchronous"
3713 (customize-set-variable 'vhdl-reset-kind 'sync)
3714 :style radio :selected (eq 'sync vhdl-reset-kind)]
3715 ["Asynchronous"
3716 (customize-set-variable 'vhdl-reset-kind 'async)
3717 :style radio :selected (eq 'async vhdl-reset-kind)])
3718 ["Reset is Active High"
3719 (customize-set-variable 'vhdl-reset-active-high
3720 (not vhdl-reset-active-high))
3721 :style toggle :selected vhdl-reset-active-high]
3722 ["Use Rising Clock Edge"
3723 (customize-set-variable 'vhdl-clock-rising-edge
3724 (not vhdl-clock-rising-edge))
3725 :style toggle :selected vhdl-clock-rising-edge]
3726 ("Clock Edge Condition"
3727 ["Standard"
3728 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3729 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3730 ["Function \"rising_edge\""
3731 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3732 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3733 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3734 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3735 "--"
3736 ["Customize Group..." (customize-group 'vhdl-template) t])
3737 ("Model"
3738 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3739 ("Port"
3740 ["Include Port Comments"
3741 (customize-set-variable 'vhdl-include-port-comments
3742 (not vhdl-include-port-comments))
3743 :style toggle :selected vhdl-include-port-comments]
3744 ["Include Direction Comments"
3745 (customize-set-variable 'vhdl-include-direction-comments
3746 (not vhdl-include-direction-comments))
3747 :style toggle :selected vhdl-include-direction-comments]
3748 ["Include Type Comments"
3749 (customize-set-variable 'vhdl-include-type-comments
3750 (not vhdl-include-type-comments))
3751 :style toggle :selected vhdl-include-type-comments]
3752 ("Include Group Comments"
3753 ["Never"
3754 (customize-set-variable 'vhdl-include-group-comments 'never)
3755 :style radio :selected (eq 'never vhdl-include-group-comments)]
3756 ["Declarations"
3757 (customize-set-variable 'vhdl-include-group-comments 'decl)
3758 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3759 ["Always"
3760 (customize-set-variable 'vhdl-include-group-comments 'always)
3761 :style radio :selected (eq 'always vhdl-include-group-comments)])
3762 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3763 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3764 ("Testbench"
3765 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3766 ["Architecture Name..."
3767 (customize-option 'vhdl-testbench-architecture-name) t]
3768 ["Configuration Name..."
3769 (customize-option 'vhdl-testbench-configuration-name) t]
3770 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3771 ["Include Header"
3772 (customize-set-variable 'vhdl-testbench-include-header
3773 (not vhdl-testbench-include-header))
3774 :style toggle :selected vhdl-testbench-include-header]
3775 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3776 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3777 ["Initialize Signals"
3778 (customize-set-variable 'vhdl-testbench-initialize-signals
3779 (not vhdl-testbench-initialize-signals))
3780 :style toggle :selected vhdl-testbench-initialize-signals]
3781 ["Include Library Clause"
3782 (customize-set-variable 'vhdl-testbench-include-library
3783 (not vhdl-testbench-include-library))
3784 :style toggle :selected vhdl-testbench-include-library]
3785 ["Include Configuration"
3786 (customize-set-variable 'vhdl-testbench-include-configuration
3787 (not vhdl-testbench-include-configuration))
3788 :style toggle :selected vhdl-testbench-include-configuration]
3789 ("Create Files"
3790 ["None"
3791 (customize-set-variable 'vhdl-testbench-create-files 'none)
3792 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3793 ["Single"
3794 (customize-set-variable 'vhdl-testbench-create-files 'single)
3795 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3796 ["Separate"
3797 (customize-set-variable 'vhdl-testbench-create-files 'separate)
0a2e512a
RF
3798 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3799 ["Testbench Entity File Name..."
3800 (customize-option 'vhdl-testbench-entity-file-name) t]
3801 ["Testbench Architecture File Name..."
3802 (customize-option 'vhdl-testbench-architecture-file-name) t])
3dcb36b7
JB
3803 "--"
3804 ["Customize Group..." (customize-group 'vhdl-port) t])
3805 ("Compose"
0a2e512a
RF
3806 ["Architecture Name..."
3807 (customize-option 'vhdl-compose-architecture-name) t]
3808 ["Configuration Name..."
3809 (customize-option 'vhdl-compose-configuration-name) t]
3810 ["Components Package Name..."
3811 (customize-option 'vhdl-components-package-name) t]
3812 ["Use Components Package"
3813 (customize-set-variable 'vhdl-use-components-package
3814 (not vhdl-use-components-package))
3815 :style toggle :selected vhdl-use-components-package]
3816 ["Include Header"
3817 (customize-set-variable 'vhdl-compose-include-header
3818 (not vhdl-compose-include-header))
3819 :style toggle :selected vhdl-compose-include-header]
3820 ("Create Entity/Architecture Files"
3dcb36b7
JB
3821 ["None"
3822 (customize-set-variable 'vhdl-compose-create-files 'none)
3823 :style radio :selected (eq 'none vhdl-compose-create-files)]
3824 ["Single"
3825 (customize-set-variable 'vhdl-compose-create-files 'single)
3826 :style radio :selected (eq 'single vhdl-compose-create-files)]
3827 ["Separate"
3828 (customize-set-variable 'vhdl-compose-create-files 'separate)
3829 :style radio :selected (eq 'separate vhdl-compose-create-files)])
0a2e512a
RF
3830 ["Create Configuration File"
3831 (customize-set-variable 'vhdl-compose-configuration-create-file
3832 (not vhdl-compose-configuration-create-file))
3833 :style toggle :selected vhdl-compose-configuration-create-file]
3834 ["Hierarchical Configuration"
3835 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3836 (not vhdl-compose-configuration-hierarchical))
3837 :style toggle :selected vhdl-compose-configuration-hierarchical]
3838 ["Use Subconfiguration"
3839 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3840 (not vhdl-compose-configuration-use-subconfiguration))
3841 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3dcb36b7
JB
3842 "--"
3843 ["Customize Group..." (customize-group 'vhdl-compose) t])
3844 ("Comment"
3845 ["Self Insert Comments"
3846 (customize-set-variable 'vhdl-self-insert-comments
3847 (not vhdl-self-insert-comments))
3848 :style toggle :selected vhdl-self-insert-comments]
3849 ["Prompt for Comments"
3850 (customize-set-variable 'vhdl-prompt-for-comments
3851 (not vhdl-prompt-for-comments))
3852 :style toggle :selected vhdl-prompt-for-comments]
3853 ["Inline Comment Column..."
3854 (customize-option 'vhdl-inline-comment-column) t]
3855 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3856 "--"
3857 ["Customize Group..." (customize-group 'vhdl-comment) t])
3858 ("Align"
3859 ["Auto Align Templates"
3860 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3861 :style toggle :selected vhdl-auto-align]
3862 ["Align Line Groups"
3863 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3864 :style toggle :selected vhdl-align-groups]
3865 ["Group Separation String..."
3866 (customize-set-variable 'vhdl-align-group-separate) t]
3867 ["Align Lines with Same Indent"
3868 (customize-set-variable 'vhdl-align-same-indent
3869 (not vhdl-align-same-indent))
3870 :style toggle :selected vhdl-align-same-indent]
3871 "--"
3872 ["Customize Group..." (customize-group 'vhdl-align) t])
3873 ("Highlight"
3874 ["Highlighting On/Off..."
3875 (customize-option
4bcb9c95
SM
3876 (if (fboundp 'global-font-lock-mode)
3877 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3dcb36b7
JB
3878 ["Highlight Keywords"
3879 (progn (customize-set-variable 'vhdl-highlight-keywords
3880 (not vhdl-highlight-keywords))
3881 (vhdl-fontify-buffer))
3882 :style toggle :selected vhdl-highlight-keywords]
3883 ["Highlight Names"
3884 (progn (customize-set-variable 'vhdl-highlight-names
3885 (not vhdl-highlight-names))
3886 (vhdl-fontify-buffer))
3887 :style toggle :selected vhdl-highlight-names]
3888 ["Highlight Special Words"
3889 (progn (customize-set-variable 'vhdl-highlight-special-words
3890 (not vhdl-highlight-special-words))
3891 (vhdl-fontify-buffer))
3892 :style toggle :selected vhdl-highlight-special-words]
3893 ["Highlight Forbidden Words"
3894 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3895 (not vhdl-highlight-forbidden-words))
3896 (vhdl-fontify-buffer))
3897 :style toggle :selected vhdl-highlight-forbidden-words]
3898 ["Highlight Verilog Keywords"
3899 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3900 (not vhdl-highlight-verilog-keywords))
3901 (vhdl-fontify-buffer))
3902 :style toggle :selected vhdl-highlight-verilog-keywords]
3903 ["Highlight \"translate_off\""
3904 (progn (customize-set-variable 'vhdl-highlight-translate-off
3905 (not vhdl-highlight-translate-off))
3906 (vhdl-fontify-buffer))
3907 :style toggle :selected vhdl-highlight-translate-off]
3908 ["Case Sensitive Highlighting"
3909 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3910 (not vhdl-highlight-case-sensitive))
3911 (vhdl-fontify-buffer))
3912 :style toggle :selected vhdl-highlight-case-sensitive]
3913 ["Special Syntax Definition..."
3914 (customize-option 'vhdl-special-syntax-alist) t]
3915 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3916 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3917 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3918 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3919 "--"
3920 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3921 ("Speedbar"
3922 ["Auto Open at Startup"
3923 (customize-set-variable 'vhdl-speedbar-auto-open
3924 (not vhdl-speedbar-auto-open))
3925 :style toggle :selected vhdl-speedbar-auto-open]
3926 ("Default Displaying Mode"
3927 ["Files"
3928 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3929 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3930 ["Directory Hierarchy"
3931 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3932 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3933 ["Project Hierarchy"
3934 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3935 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3936 ["Indentation Offset..."
3937 (customize-option 'speedbar-indentation-width) t]
3938 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3939 ["Jump to Unit when Opening"
3940 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3941 (not vhdl-speedbar-jump-to-unit))
3942 :style toggle :selected vhdl-speedbar-jump-to-unit]
3943 ["Update Hierarchy on File Saving"
3944 (customize-set-variable 'vhdl-speedbar-update-on-saving
3945 (not vhdl-speedbar-update-on-saving))
3946 :style toggle :selected vhdl-speedbar-update-on-saving]
3947 ("Save in Cache File"
3948 ["Hierarchy Information"
3949 (customize-set-variable 'vhdl-speedbar-save-cache
3950 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3951 (delq 'hierarchy vhdl-speedbar-save-cache)
3952 (cons 'hierarchy vhdl-speedbar-save-cache)))
3953 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3954 ["Displaying Status"
3955 (customize-set-variable 'vhdl-speedbar-save-cache
3956 (if (memq 'display vhdl-speedbar-save-cache)
3957 (delq 'display vhdl-speedbar-save-cache)
3958 (cons 'display vhdl-speedbar-save-cache)))
3959 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3960 ["Cache File Name..."
3961 (customize-option 'vhdl-speedbar-cache-file-name) t]
3962 "--"
3963 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3964 ("Menu"
3965 ["Add Index Menu when Loading File"
3966 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3967 (vhdl-index-menu-init))
3968 :style toggle :selected vhdl-index-menu]
3969 ["Add Source File Menu when Loading File"
3970 (progn (customize-set-variable 'vhdl-source-file-menu
3971 (not vhdl-source-file-menu))
3972 (vhdl-add-source-files-menu))
3973 :style toggle :selected vhdl-source-file-menu]
3974 ["Add Hideshow Menu at Startup"
3975 (progn (customize-set-variable 'vhdl-hideshow-menu
3976 (not vhdl-hideshow-menu))
3977 (vhdl-activate-customizations))
3978 :style toggle :selected vhdl-hideshow-menu]
3979 ["Hide Everything Initially"
3980 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3981 :style toggle :selected vhdl-hide-all-init]
3982 "--"
3983 ["Customize Group..." (customize-group 'vhdl-menu) t])
3984 ("Print"
3985 ["In Two Column Format"
3986 (progn (customize-set-variable 'vhdl-print-two-column
3987 (not vhdl-print-two-column))
3988 (message "Activate new setting by saving options and restarting Emacs"))
3989 :style toggle :selected vhdl-print-two-column]
3990 ["Use Customized Faces"
3991 (progn (customize-set-variable 'vhdl-print-customize-faces
3992 (not vhdl-print-customize-faces))
3993 (message "Activate new setting by saving options and restarting Emacs"))
3994 :style toggle :selected vhdl-print-customize-faces]
3995 "--"
3996 ["Customize Group..." (customize-group 'vhdl-print) t])
3997 ("Miscellaneous"
3998 ["Use Intelligent Tab"
3999 (progn (customize-set-variable 'vhdl-intelligent-tab
4000 (not vhdl-intelligent-tab))
4001 (vhdl-activate-customizations))
4002 :style toggle :selected vhdl-intelligent-tab]
4003 ["Indent Syntax-Based"
4004 (customize-set-variable 'vhdl-indent-syntax-based
4005 (not vhdl-indent-syntax-based))
4006 :style toggle :selected vhdl-indent-syntax-based]
4007 ["Word Completion is Case Sensitive"
4008 (customize-set-variable 'vhdl-word-completion-case-sensitive
4009 (not vhdl-word-completion-case-sensitive))
4010 :style toggle :selected vhdl-word-completion-case-sensitive]
4011 ["Word Completion in Minibuffer"
4012 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4013 (not vhdl-word-completion-in-minibuffer))
4014 (message "Activate new setting by saving options and restarting Emacs"))
4015 :style toggle :selected vhdl-word-completion-in-minibuffer]
4016 ["Underscore is Part of Word"
4017 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4018 (not vhdl-underscore-is-part-of-word))
4019 (vhdl-activate-customizations))
4020 :style toggle :selected vhdl-underscore-is-part-of-word]
4021 "--"
4022 ["Customize Group..." (customize-group 'vhdl-misc) t])
4023 ["Related..." (customize-browse 'vhdl-related) t]
d2ddb974 4024 "--"
3dcb36b7
JB
4025 ["Save Options" customize-save-customized t]
4026 ["Activate Options" vhdl-activate-customizations t]
4027 ["Browse Options..." vhdl-customize t])))
5eabfe72
KH
4028
4029(defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4030 "VHDL Mode menu.")
4031
4032(defun vhdl-update-mode-menu ()
3dcb36b7 4033 "Update VHDL Mode menu."
5eabfe72
KH
4034 (interactive)
4035 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4036 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4037 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4038 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4039 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
d2ddb974 4040
5eabfe72
KH
4041;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4042;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
d2ddb974 4043
3dcb36b7 4044(defconst vhdl-imenu-generic-expression
d2ddb974 4045 '(
5eabfe72
KH
4046 ("Subprogram"
4047 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4048 4)
4049 ("Instance"
4050 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4051 1)
4052 ("Component"
4053 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4054 2)
5eabfe72
KH
4055 ("Procedural"
4056 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4057 1)
4058 ("Process"
4059 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4060 1)
4061 ("Block"
4062 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4063 1)
4064 ("Package"
4065 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4066 3)
d2ddb974
KH
4067 ("Configuration"
4068 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4069 2)
5eabfe72
KH
4070 ("Architecture"
4071 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4072 2)
5eabfe72
KH
4073 ("Entity"
4074 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4075 2)
d2ddb974
KH
4076 )
4077 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4078
5eabfe72
KH
4079(defun vhdl-index-menu-init ()
4080 "Initialize index menu."
4081 (set (make-local-variable 'imenu-case-fold-search) t)
4082 (set (make-local-variable 'imenu-generic-expression)
4083 vhdl-imenu-generic-expression)
3dcb36b7 4084 (when (and vhdl-index-menu (fboundp 'imenu))
5eabfe72
KH
4085 (if (or (not (boundp 'font-lock-maximum-size))
4086 (> font-lock-maximum-size (buffer-size)))
4087 (imenu-add-to-menubar "Index")
4088 (message "Scanning buffer for index...buffer too big"))))
d2ddb974 4089
3dcb36b7 4090;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
4091;; Source file menu (using `easy-menu.el')
4092
5eabfe72
KH
4093(defvar vhdl-sources-menu nil)
4094
4095(defun vhdl-directory-files (directory &optional full match)
4096 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4097message."
3dcb36b7
JB
4098 (if (not (file-directory-p directory))
4099 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4100 (let ((dir (directory-files directory full match)))
4101 (setq dir (delete "." dir))
4102 (setq dir (delete ".." dir))
4103 dir)))
5eabfe72
KH
4104
4105(defun vhdl-get-source-files (&optional full directory)
4106 "Get list of VHDL source files in DIRECTORY or current directory."
4107 (let ((mode-alist auto-mode-alist)
4108 filename-regexp)
4109 ;; create regular expressions for matching file names
3dcb36b7 4110 (setq filename-regexp "\\`[^.].*\\(")
5eabfe72 4111 (while mode-alist
3dcb36b7 4112 (when (eq (cdar mode-alist) 'vhdl-mode)
5eabfe72 4113 (setq filename-regexp
3dcb36b7 4114 (concat filename-regexp (caar mode-alist) "\\|")))
5eabfe72
KH
4115 (setq mode-alist (cdr mode-alist)))
4116 (setq filename-regexp
4117 (concat (substring filename-regexp 0
4118 (string-match "\\\\|$" filename-regexp)) "\\)"))
4119 ;; find files
3dcb36b7
JB
4120 (vhdl-directory-files
4121 (or directory default-directory) full filename-regexp)))
d2ddb974
KH
4122
4123(defun vhdl-add-source-files-menu ()
5eabfe72
KH
4124 "Scan directory for all VHDL source files and generate menu.
4125The directory of the current source file is scanned."
d2ddb974
KH
4126 (interactive)
4127 (message "Scanning directory for source files ...")
5eabfe72 4128 (let ((newmap (current-local-map))
5eabfe72
KH
4129 (file-list (vhdl-get-source-files))
4130 menu-list found)
4131 ;; Create list for menu
4132 (setq found nil)
4133 (while file-list
4134 (setq found t)
4135 (setq menu-list (cons (vector (car file-list)
4136 (list 'find-file (car file-list)) t)
4137 menu-list))
4138 (setq file-list (cdr file-list)))
3dcb36b7 4139 (setq menu-list (vhdl-menu-split menu-list "Sources"))
5eabfe72
KH
4140 (when found (setq menu-list (cons "--" menu-list)))
4141 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4142 (setq menu-list (cons "Sources" menu-list))
d2ddb974 4143 ;; Create menu
5eabfe72
KH
4144 (easy-menu-add menu-list)
4145 (easy-menu-define vhdl-sources-menu newmap
4146 "VHDL source files menu" menu-list))
d2ddb974
KH
4147 (message ""))
4148
d2ddb974 4149
5eabfe72 4150;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4151;;; Mode definition
5eabfe72
KH
4152;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4153;; performs all buffer local initializations
4154
1c36bac6 4155;;;###autoload
d2ddb974
KH
4156(defun vhdl-mode ()
4157 "Major mode for editing VHDL code.
4158
4159Usage:
4160------
4161
3dcb36b7
JB
4162 TEMPLATE INSERTION (electrification):
4163 After typing a VHDL keyword and entering `SPC', you are prompted for
4164 arguments while a template is generated for that VHDL construct. Typing
4165 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4166 template generation. Optional arguments are indicated by square
4167 brackets and removed if the queried string is left empty. Prompts for
4168 mandatory arguments remain in the code if the queried string is left
4169 empty. They can be queried again by `C-c C-t C-q'. Enabled
4170 electrification is indicated by `/e' in the modeline.
4171
4172 Typing `M-SPC' after a keyword inserts a space without calling the
4173 template generator. Automatic template generation (i.e.
4174 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4175 setting option `vhdl-electric-mode' (see OPTIONS).
4176
4177 Template generators can be invoked from the VHDL menu, by key
4178 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4179 the keyword (i.e. first word of menu entry not in parenthesis) and
4180 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4181 conf, comp, cons, func, inst, pack, sig, var.
4182
4183 Template styles can be customized in customization group
4184 `vhdl-template' \(see OPTIONS).
4185
4186
4187 HEADER INSERTION:
4188 A file header can be inserted by `C-c C-t C-h'. A file footer
4189 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4190 See customization group `vhdl-header'.
4191
4192
4193 STUTTERING:
4194 Double striking of some keys inserts cumbersome VHDL syntax elements.
4195 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4196 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4197 the modeline. The stuttering keys and their effects are:
4198
4199 ;; --> \" : \" [ --> ( -- --> comment
4200 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4201 .. --> \" => \" ] --> ) --- --> horizontal line
4202 ,, --> \" <= \" ]] --> ] ---- --> display comment
4203 == --> \" == \" '' --> \\\"
4204
4205
4206 WORD COMPLETION:
4207 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4208 word in the buffer that starts alike, inserts it and adjusts case.
4209 Re-typing `TAB' toggles through alternative word completions. This also
4210 works in the minibuffer (i.e. in template generator prompts).
4211
4212 Typing `TAB' after `(' looks for and inserts complete parenthesized
4213 expressions (e.g. for array index ranges). All keywords as well as
4214 standard types and subprograms of VHDL have predefined abbreviations
4215 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4216 beginning with \"std\").
4217
4218 Typing `TAB' after a non-word character indents the line if at the
4219 beginning of a line (i.e. no preceding non-blank characters), and
4220 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4221 stop.
4222
4223
4224 COMMENTS:
4225 `--' puts a single comment.
4226 `---' draws a horizontal line for separating code segments.
4227 `----' inserts a display comment, i.e. two horizontal lines
4228 with a comment in between.
4229 `--CR' comments out code on that line. Re-hitting CR comments
4230 out following lines.
4231 `C-c c' comments out a region if not commented out,
4232 uncomments a region if already commented out.
4233
4234 You are prompted for comments after object definitions (i.e. signals,
4235 variables, constants, ports) and after subprogram and process
4236 specifications if option `vhdl-prompt-for-comments' is non-nil.
4237 Comments are automatically inserted as additional labels (e.g. after
4238 begin statements) and as help comments if `vhdl-self-insert-comments' is
4239 non-nil.
4240
4241 Inline comments (i.e. comments after a piece of code on the same line)
4242 are indented at least to `vhdl-inline-comment-column'. Comments go at
4243 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4244 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4245 in a comment automatically opens a new comment line. `M-q' re-fills
4246 multi-line comments.
4247
4248
4249 INDENTATION:
4250 `TAB' indents a line if at the beginning of the line. The amount of
4251 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4252 always indents the current line (is bound to `TAB' if option
4253 `vhdl-intelligent-tab' is nil).
4254
4255 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4256 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4257 indented normally (nil) or relative to the opening parenthesis (non-nil)
4258 according to option `vhdl-argument-list-indent'.
4259
4260 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4261 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4262 and vice versa.
4263
4264 Syntax-based indentation can be very slow in large files. Option
4265 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4266
4267
4268 ALIGNMENT:
4269 The alignment functions align operators, keywords, and inline comments
4270 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4271 separated by blank lines, `C-c C-a C-i' a block of lines with same
4272 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4273 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4274 C-a C-d' all lines within the declarative part of a design unit. `C-c
4275 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4276 for a group of lines, and `C-c C-a M-c' for a region.
4277
4278 If option `vhdl-align-groups' is non-nil, groups of code lines
4279 separated by special lines (see option `vhdl-align-group-separate') are
4280 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4281 blocks of lines with same indent are aligned separately. Some templates
4282 are automatically aligned after generation if option `vhdl-auto-align'
4283 is non-nil.
4284
4285 Alignment tries to align inline comments at
4286 `vhdl-inline-comment-column' and tries inline comment not to exceed
4287 `vhdl-end-comment-column'.
4288
4289 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4290 symbols are surrounded by one space, and multiple spaces are eliminated.
4291
4292
0a2e512a
RF
4293 CODE FILLING:
4294 Code filling allows to condense code (e.g. sensitivity lists or port
4295 maps) by removing comments and newlines and re-wrapping so that all
4296 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4297 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4298 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4299 `C-c C-f M-f' an entire region.
3dcb36b7
JB
4300
4301
4302 CODE BEAUTIFICATION:
4303 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4304 buffer respectively. This inludes indentation, alignment, and case
4305 fixing. Code beautification can also be run non-interactively using the
4306 command:
4307
4308 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4309
4310
4311 PORT TRANSLATION:
4312 Generic and port clauses from entity or component declarations can be
4313 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4314 as component instantiations and corresponding internal constants and
4315 signals, as a generic map with constants as actual generics, and as
4316 internal signal initializations (menu).
4317
4318 To include formals in component instantiations, see option
4319 `vhdl-association-list-with-formals'. To include comments in pasting,
4320 see options `vhdl-include-...-comments'.
4321
4322 A clause with several generic/port names on the same line can be
4323 flattened (`C-c C-p C-f') so that only one name per line exists. The
0a2e512a
RF
4324 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4325 outputs and vice versa, which can be useful in testbenches. (This
4326 reversion is done on the internal data structure and is only reflected
4327 in subsequent paste operations.)
3dcb36b7
JB
4328
4329 Names for actual ports, instances, testbenches, and
4330 design-under-test instances can be derived from existing names according
4331 to options `vhdl-...-name'. See customization group `vhdl-port'.
4332
4333
0a2e512a
RF
4334 SUBPROGRAM TRANSLATION:
4335 Similar functionality exists for copying/pasting the interface of
4336 subprograms (function/procedure). A subprogram interface can be copied
4337 and then pasted as a subprogram declaration, body or call (uses
4338 association list with formals).
3dcb36b7
JB
4339
4340
4341 TESTBENCH GENERATION:
4342 A copied port can also be pasted as a testbench. The generated
4343 testbench includes an entity, an architecture, and an optional
4344 configuration. The architecture contains the component declaration and
4345 instantiation of the DUT as well as internal constant and signal
4346 declarations. Additional user-defined templates can be inserted. The
4347 names used for entity/architecture/configuration/DUT as well as the file
4348 structure to be generated can be customized. See customization group
4349 `vhdl-testbench'.
4350
4351
4352 KEY BINDINGS:
4353 Key bindings (`C-c ...') exist for most commands (see in menu).
4354
4355
4356 VHDL MENU:
4357 All commands can be found in the VHDL menu including their key bindings.
4358
4359
4360 FILE BROWSER:
4361 The speedbar allows browsing of directories and file contents. It can
4362 be accessed from the VHDL menu and is automatically opened if option
4363 `vhdl-speedbar-auto-open' is non-nil.
4364
4365 In speedbar, open files and directories with `mouse-2' on the name and
4366 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4367
4368
4369 DESIGN HIERARCHY BROWSER:
4370 The speedbar can also be used for browsing the hierarchy of design units
4371 contained in the source files of the current directory or the specified
4372 projects (see option `vhdl-project-alist').
4373
4374 The speedbar can be switched between file, directory hierarchy and
4375 project hierarchy browsing mode in the speedbar menu or by typing `f',
4376 `h' or `H' in speedbar.
4377
4378 In speedbar, open design units with `mouse-2' on the name and browse
4379 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4380 from entities and components (in packages). Individual design units and
4381 complete designs can directly be compiled (\"Make\" menu entry).
4382
4383 The hierarchy is automatically updated upon saving a modified source
4384 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4385 hierarchy is only updated for projects that have been opened once in the
4386 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4387 options in group `vhdl-speedbar').
4388
4389 Simple design consistency checks are done during scanning, such as
4390 multiple declarations of the same unit or missing primary units that are
4391 required by secondary units.
4392
4393
0a2e512a
RF
4394 STRUCTURAL COMPOSITION:
4395 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4396 for a new component. Subcomponents (i.e. component declaration and
4397 instantiation) can be automatically placed from a previously read port
4398 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4399 all subcomponents can be automatically connected using internal signals
4400 and ports (`C-c C-c C-w') following these rules:
4401 - subcomponent actual ports with same name are considered to be
4402 connected by a signal (internal signal or port)
4403 - signals that are only inputs to subcomponents are considered as
4404 inputs to this component -> input port created
4405 - signals that are only outputs from subcomponents are considered as
4406 outputs from this component -> output port created
4407 - signals that are inputs to AND outputs from subcomponents are
4408 considered as internal connections -> internal signal created
84c98ace 4409
0a2e512a
RF
4410 Purpose: With appropriate naming conventions it is possible to
4411 create higher design levels with only a few mouse clicks or key
4412 strokes. A new design level can be created by simply generating a new
4413 component, placing the required subcomponents from the hierarchy
4414 browser, and wiring everything automatically.
84c98ace 4415
0a2e512a
RF
4416 Note: Automatic wiring only works reliably on templates of new
4417 components and component instantiations that were created by VHDL mode.
84c98ace 4418
0a2e512a
RF
4419 Component declarations can be placed in a components package (option
4420 `vhdl-use-components-package') which can be automatically generated for
4421 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4422 component instantiation is also supported (option
4423 `vhdl-use-direct-instantiation').
4424
4425| Configuration declarations can automatically be generated either from
4426| the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4427| the speedbar menu (for the architecture under the cursor). The
4428| configurations can optionally be hierarchical (i.e. include all
4429| component levels of a hierarchical design, option
4430| `vhdl-compose-configuration-hierarchical') or include subconfigurations
4431| (option `vhdl-compose-configuration-use-subconfiguration'). For
4432| subcomponents in hierarchical configurations, the most-recently-analyzed
4433| (mra) architecture is selected. If another architecture is desired, it
4434| can be marked as most-recently-analyzed (speedbar menu) before
4435| generating the configuration.
3dcb36b7 4436|
0a2e512a
RF
4437| Note: Configurations of subcomponents (i.e. hierarchical configuration
4438| declarations) are currently not considered when displaying
4439| configurations in speedbar.
84c98ace 4440
0a2e512a 4441 See the options group `vhdl-compose' for all relevant user options.
3dcb36b7
JB
4442
4443
4444 SOURCE FILE COMPILATION:
4445 The syntax of the current buffer can be analyzed by calling a VHDL
4446 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4447 option `vhdl-compiler'. The available compilers are listed in option
4448 `vhdl-compiler-alist' including all required compilation command,
4449 command options, compilation directory, and error message syntax
4450 information. New compilers can be added.
4451
4452 All the source files of an entire design can be compiled by the `make'
4453 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4454
4455
4456 MAKEFILE GENERATION:
4457 Makefiles can be generated automatically by an internal generation
4458 routine (`C-c M-k'). The library unit dependency information is
4459 obtained from the hierarchy browser. Makefile generation can be
4460 customized for each compiler in option `vhdl-compiler-alist'.
4461
4462 Makefile generation can also be run non-interactively using the
4463 command:
4464
4465 emacs -batch -l ~/.emacs -l vhdl-mode
4466 [-compiler compilername] [-project projectname]
4467 -f vhdl-generate-makefile
4468
4469 The Makefile's default target \"all\" compiles the entire design, the
4470 target \"clean\" removes it and the target \"library\" creates the
4471 library directory if not existent. The Makefile also includes a target
4472 for each primary library unit which allows selective compilation of this
4473 unit, its secondary units and its subhierarchy (example: compilation of
4474 a design specified by a configuration). User specific parts can be
4475 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4476
4477 Limitations:
4478 - Only library units and dependencies within the current library are
4479 considered. Makefiles for designs that span multiple libraries are
4480 not (yet) supported.
4481 - Only one-level configurations are supported (also hierarchical),
4482 but configurations that go down several levels are not.
4483 - The \"others\" keyword in configurations is not supported.
4484
4485
4486 PROJECTS:
4487 Projects can be defined in option `vhdl-project-alist' and a current
4488 project be selected using option `vhdl-project' (permanently) or from
4489 the menu or speedbar (temporarily). For each project, title and
4490 description strings (for the file headers), source files/directories
4491 (for the hierarchy browser and Makefile generation), library name, and
4492 compiler-dependent options, exceptions and compilation directory can be
4493 specified. Compilation settings overwrite the settings of option
4494 `vhdl-compiler-alist'.
4495
4496 Project setups can be exported (i.e. written to a file) and imported.
4497 Imported setups are not automatically saved in `vhdl-project-alist' but
4498 can be saved afterwards in its customization buffer. When starting
4499 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4500 vhdl-mode\") in a directory with an existing project setup file, it is
4501 automatically loaded and its project activated if option
4502 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4503 files can be specified in option `vhdl-project-file-name'. Multiple
4504 project setups can be automatically loaded from global directories.
4505 This is an alternative to specifying project setups with option
4506 `vhdl-project-alist'.
4507
4508
4509 SPECIAL MENUES:
4510 As an alternative to the speedbar, an index menu can be added (set
4511 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4512 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4513 file) for browsing the file contents (is not populated if buffer is
4514 larger than `font-lock-maximum-size'). Also, a source file menu can be
4515 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4516 current directory for VHDL source files.
4517
4518
4519 VHDL STANDARDS:
4520 The VHDL standards to be used are specified in option `vhdl-standard'.
4521 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4522
4523
4524 KEYWORD CASE:
4525 Lower and upper case for keywords and standardized types, attributes,
4526 and enumeration values is supported. If the option
4527 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4528 lower case and are converted into upper case automatically (not for
4529 types, attributes, and enumeration values). The case of keywords,
4530 types, attributes,and enumeration values can be fixed for an entire
4531 region (menu) or buffer (`C-c C-x C-c') according to the options
4532 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4533
4534
4535 HIGHLIGHTING (fontification):
4536 Keywords and standardized types, attributes, enumeration values, and
4537 function names (controlled by option `vhdl-highlight-keywords'), as well
4538 as comments, strings, and template prompts are highlighted using
4539 different colors. Unit, subprogram, signal, variable, constant,
4540 parameter and generic/port names in declarations as well as labels are
4541 highlighted if option `vhdl-highlight-names' is non-nil.
4542
4543 Additional reserved words or words with a forbidden syntax (e.g. words
4544 that should be avoided) can be specified in option
4545 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4546 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4547 keywords are highlighted as forbidden words if option
4548 `vhdl-highlight-verilog-keywords' is non-nil.
4549
4550 Words with special syntax can be highlighted by specifying their
4551 syntax and color in option `vhdl-special-syntax-alist' and by setting
4552 option `vhdl-highlight-special-words' to non-nil. This allows to
4553 establish some naming conventions (e.g. to distinguish different kinds
4554 of signals or other objects by using name suffices) and to support them
4555 visually.
4556
4557 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4558 to support case-sensitive highlighting. However, keywords are then only
4559 highlighted if written in lower case.
4560
4561 Code between \"translate_off\" and \"translate_on\" pragmas is
4562 highlighted using a different background color if option
4563 `vhdl-highlight-translate-off' is non-nil.
4564
4565 For documentation and customization of the used colors see
4566 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4567 highlighting of matching parenthesis, see customization group
4568 `paren-showing'. Automatic buffer highlighting is turned on/off by
4569 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4570
4571
4572 USER MODELS:
4573 VHDL models (templates) can be specified by the user and made accessible
4574 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4575 electrification. See option `vhdl-model-alist'.
4576
4577
4578 HIDE/SHOW:
4579 The code of blocks, processes, subprograms, component declarations and
4580 instantiations, generic/port clauses, and configuration declarations can
4581 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4582 the code (see customization group `vhdl-menu'). XEmacs: limited
4583 functionality due to old `hideshow.el' package.
4584
4585
4586 CODE UPDATING:
4587 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4588 current process, `C-c C-u M-s' of all processes in the current buffer.
4589 Limitations:
4590 - Only declared local signals (ports, signals declared in
4591 architecture and blocks) are automatically inserted.
4592 - Global signals declared in packages are not automatically inserted.
4593 Insert them once manually (will be kept afterwards).
4594 - Out parameters of procedures are considered to be read.
4595 Use option `vhdl-entity-file-name' to specify the entity file name
4596 \(used to obtain the port names).
4597
4598
4599 CODE FIXING:
4600 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4601 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4602
4603
4604 PRINTING:
4605 Postscript printing with different faces (an optimized set of faces is
4606 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4607 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4608 postscript printing commands. Option `vhdl-print-two-column' defines
4609 appropriate default settings for nice landscape two-column printing.
4610 The paper format can be set by option `ps-paper-type'. Do not forget to
4611 switch `ps-print-color-p' to nil for printing on black-and-white
4612 printers.
4613
4614
4615 OPTIONS:
4616 User options allow customization of VHDL Mode. All options are
4617 accessible from the \"Options\" menu entry. Simple options (switches
4618 and choices) can directly be changed, while for complex options a
4619 customization buffer is opened. Changed options can be saved for future
4620 sessions using the \"Save Options\" menu entry.
4621
4622 Options and their detailed descriptions can also be accessed by using
4623 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4624 customize-group' for groups). Some customizations only take effect
4625 after some action (read the NOTE in the option documentation).
4626 Customization can also be done globally (i.e. site-wide, read the
4627 INSTALL file).
4628
4629 Not all options are described in this documentation, so go and see
4630 what other useful user options there are (`M-x vhdl-customize' or menu)!
4631
4632
4633 FILE EXTENSIONS:
4634 As default, files with extensions \".vhd\" and \".vhdl\" are
4635 automatically recognized as VHDL source files. To add an extension
4636 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4637
4638 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4639
4640
4641 HINTS:
4642 - To start Emacs with open VHDL hierarchy browser without having to load
4643 a VHDL file first, use the command:
4644
4645 emacs -l vhdl-mode -f speedbar-frame-mode
4646
4647 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4648
4649 - Some features only work on properly indented code.
4650
4651
4652 RELEASE NOTES:
4653 See also the release notes (menu) for added features in new releases.
d2ddb974
KH
4654
4655
4656Maintenance:
4657------------
4658
3dcb36b7 4659To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
d2ddb974
KH
4660Add a description of the problem and include a reproducible test case.
4661
3dcb36b7 4662Questions and enhancement requests can be sent to <reto@gnu.org>.
d2ddb974
KH
4663
4664The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
3dcb36b7
JB
4665The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4666releases. You are kindly invited to participate in beta testing. Subscribe
4667to above mailing lists by sending an email to <reto@gnu.org>.
d2ddb974 4668
3dcb36b7
JB
4669VHDL Mode is officially distributed at
4670http://opensource.ethz.ch/emacs/vhdl-mode.html
4671where the latest version can be found.
d2ddb974
KH
4672
4673
3dcb36b7
JB
4674Known problems:
4675---------------
d2ddb974 4676
5eabfe72 4677- Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
3dcb36b7
JB
4678- XEmacs: Incorrect start-up when automatically opening speedbar.
4679- XEmacs: Indentation in XEmacs 21.4 (and higher).
d2ddb974
KH
4680
4681
3dcb36b7
JB
4682 The VHDL Mode Authors
4683 Reto Zimmermann and Rod Whitby
5eabfe72 4684
d2ddb974
KH
4685Key bindings:
4686-------------
4687
4688\\{vhdl-mode-map}"
4689 (interactive)
4690 (kill-all-local-variables)
d2ddb974
KH
4691 (setq major-mode 'vhdl-mode)
4692 (setq mode-name "VHDL")
5eabfe72
KH
4693
4694 ;; set maps and tables
d2ddb974 4695 (use-local-map vhdl-mode-map)
5eabfe72
KH
4696 (set-syntax-table vhdl-mode-syntax-table)
4697 (setq local-abbrev-table vhdl-mode-abbrev-table)
4698
3dcb36b7 4699 ;; set local variables
5eabfe72
KH
4700 (set (make-local-variable 'paragraph-start)
4701 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
d2ddb974
KH
4702 (set (make-local-variable 'paragraph-separate) paragraph-start)
4703 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
cf98062a 4704 (set (make-local-variable 'require-final-newline)
0a2e512a 4705 (if vhdl-emacs-22 mode-require-final-newline t))
d2ddb974
KH
4706 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4707 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4708 (set (make-local-variable 'comment-start) "--")
4709 (set (make-local-variable 'comment-end) "")
0a2e512a
RF
4710 (when vhdl-emacs-21
4711 (set (make-local-variable 'comment-padding) ""))
5eabfe72 4712 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
d2ddb974
KH
4713 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4714 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
5eabfe72 4715 (set (make-local-variable 'comment-multi-line) nil)
d2ddb974 4716 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
5eabfe72 4717 (set (make-local-variable 'hippie-expand-verbose) nil)
d2ddb974
KH
4718
4719 ;; setup the comment indent variable in a Emacs version portable way
4720 ;; ignore any byte compiler warnings you might get here
5eabfe72
KH
4721 (when (boundp 'comment-indent-function)
4722 (make-local-variable 'comment-indent-function)
4723 (setq comment-indent-function 'vhdl-comment-indent))
d2ddb974
KH
4724
4725 ;; initialize font locking
5eabfe72
KH
4726 (set (make-local-variable 'font-lock-defaults)
4727 (list
3dcb36b7 4728 '(nil vhdl-font-lock-keywords) nil
5eabfe72
KH
4729 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4730 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
3dcb36b7
JB
4731 (unless vhdl-emacs-21
4732 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4733 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4734 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4735; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4736 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4737; (turn-on-font-lock)
d2ddb974
KH
4738
4739 ;; variables for source file compilation
3dcb36b7
JB
4740 (when vhdl-compile-use-local-error-regexp
4741 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4742 (set (make-local-variable 'compilation-file-regexp-alist) nil))
5eabfe72
KH
4743
4744 ;; add index menu
4745 (vhdl-index-menu-init)
4746 ;; add source file menu
d2ddb974 4747 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
5eabfe72
KH
4748 ;; add VHDL menu
4749 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4750 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4751 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4752 ;; initialize hideshow and add menu
5eabfe72 4753 (vhdl-hideshow-init)
d2ddb974
KH
4754 (run-hooks 'menu-bar-update-hook)
4755
5eabfe72
KH
4756 ;; miscellaneous
4757 (vhdl-ps-print-init)
3dcb36b7 4758 (vhdl-write-file-hooks-init)
5eabfe72 4759 (vhdl-mode-line-update)
3dcb36b7
JB
4760 (message "VHDL Mode %s.%s" vhdl-version
4761 (if noninteractive "" " See menu for documentation and release notes."))
5eabfe72
KH
4762
4763 ;; run hooks
0a2e512a
RF
4764 (if vhdl-emacs-22
4765 (run-mode-hooks 'vhdl-mode-hook)
4766 (run-hooks 'vhdl-mode-hook)))
5eabfe72
KH
4767
4768(defun vhdl-activate-customizations ()
4769 "Activate all customizations on local variables."
4770 (interactive)
4771 (vhdl-mode-map-init)
4772 (use-local-map vhdl-mode-map)
4773 (set-syntax-table vhdl-mode-syntax-table)
4774 (setq comment-column vhdl-inline-comment-column)
4775 (setq end-comment-column vhdl-end-comment-column)
3dcb36b7 4776 (vhdl-write-file-hooks-init)
5eabfe72
KH
4777 (vhdl-update-mode-menu)
4778 (vhdl-hideshow-init)
4779 (run-hooks 'menu-bar-update-hook)
4780 (vhdl-mode-line-update))
4781
3dcb36b7
JB
4782(defun vhdl-write-file-hooks-init ()
4783 "Add/remove hooks when buffer is saved."
5eabfe72
KH
4784 (if vhdl-modify-date-on-saving
4785 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
3dcb36b7
JB
4786 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4787 (make-local-variable 'after-save-hook)
4788 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4789
4790(defun vhdl-process-command-line-option (option)
4791 "Process command line options for VHDL Mode."
4792 (cond
4793 ;; set compiler
4794 ((equal option "-compiler")
4795 (vhdl-set-compiler (car command-line-args-left))
4796 (setq command-line-args-left (cdr command-line-args-left)))
4797 ;; set project
4798 ((equal option "-project")
4799 (vhdl-set-project (car command-line-args-left))
4800 (setq command-line-args-left (cdr command-line-args-left)))))
4801
4802;; make Emacs process VHDL Mode options
4803(setq command-switch-alist
4804 (append command-switch-alist
4805 '(("-compiler" . vhdl-process-command-line-option)
4806 ("-project" . vhdl-process-command-line-option))))
5eabfe72
KH
4807
4808
4809;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4810;;; Keywords and standardized words
5eabfe72
KH
4811;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4812
3dcb36b7
JB
4813(defconst vhdl-93-keywords
4814 '(
4815 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4816 "assert" "attribute"
4817 "begin" "block" "body" "buffer" "bus"
4818 "case" "component" "configuration" "constant"
4819 "disconnect" "downto"
4820 "else" "elsif" "end" "entity" "exit"
4821 "file" "for" "function"
4822 "generate" "generic" "group" "guarded"
4823 "if" "impure" "in" "inertial" "inout" "is"
4824 "label" "library" "linkage" "literal" "loop"
4825 "map" "mod"
4826 "nand" "new" "next" "nor" "not" "null"
4827 "of" "on" "open" "or" "others" "out"
4828 "package" "port" "postponed" "procedure" "process" "pure"
4829 "range" "record" "register" "reject" "rem" "report" "return"
4830 "rol" "ror"
4831 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4832 "then" "to" "transport" "type"
4833 "unaffected" "units" "until" "use"
4834 "variable"
4835 "wait" "when" "while" "with"
4836 "xnor" "xor"
4837 )
4838 "List of VHDL'93 keywords.")
d2ddb974 4839
5eabfe72
KH
4840(defconst vhdl-ams-keywords
4841 '(
4842 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4843 "reference" "spectrum" "subnature" "terminal" "through"
4844 "tolerance"
4845 )
4846 "List of VHDL-AMS keywords.")
d2ddb974 4847
5eabfe72
KH
4848(defconst vhdl-verilog-keywords
4849 '(
4850 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4851 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4852 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4853 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4854 "endprimitive" "endspecify" "endtable" "endtask" "event"
4855 "for" "force" "forever" "fork" "function"
4856 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4857 "macromodule" "makefile" "medium" "module"
4858 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4859 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4860 "pullup"
4861 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4862 "rtranif0" "rtranif1"
4863 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4864 "strong1" "supply" "supply0" "supply1"
4865 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4866 "triand" "trior" "trireg"
4867 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4868 )
4869 "List of Verilog keywords as candidate for additional reserved words.")
d2ddb974 4870
5eabfe72
KH
4871(defconst vhdl-93-types
4872 '(
4873 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4874 "real" "time" "natural" "positive" "string" "line" "text" "side"
4875 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4876 "std_logic" "std_logic_vector"
4877 "std_ulogic" "std_ulogic_vector"
4878 )
4879 "List of VHDL'93 standardized types.")
d2ddb974 4880
5eabfe72
KH
4881(defconst vhdl-ams-types
4882 '(
4883 "domain_type" "real_vector"
3dcb36b7
JB
4884 ;; from `nature_pkg' package
4885 "voltage" "current" "electrical" "position" "velocity" "force"
4886 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4887 "pressure" "flowrate" "fluid"
4888 )
5eabfe72 4889 "List of VHDL-AMS standardized types.")
d2ddb974 4890
5eabfe72
KH
4891(defconst vhdl-math-types
4892 '(
4893 "complex" "complex_polar"
4894 )
4895 "List of Math Packages standardized types.")
d2ddb974 4896
5eabfe72
KH
4897(defconst vhdl-93-attributes
4898 '(
4899 "base" "left" "right" "high" "low" "pos" "val" "succ"
4900 "pred" "leftof" "rightof" "range" "reverse_range"
4901 "length" "delayed" "stable" "quiet" "transaction"
4902 "event" "active" "last_event" "last_active" "last_value"
4903 "driving" "driving_value" "ascending" "value" "image"
4904 "simple_name" "instance_name" "path_name"
4905 "foreign"
4906 )
4907 "List of VHDL'93 standardized attributes.")
d2ddb974 4908
5eabfe72
KH
4909(defconst vhdl-ams-attributes
4910 '(
4911 "across" "through"
4912 "reference" "contribution" "tolerance"
4913 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4914 "ramp" "slew"
4915 )
4916 "List of VHDL-AMS standardized attributes.")
d2ddb974 4917
5eabfe72
KH
4918(defconst vhdl-93-enum-values
4919 '(
4920 "true" "false"
4921 "note" "warning" "error" "failure"
4922 "read_mode" "write_mode" "append_mode"
4923 "open_ok" "status_error" "name_error" "mode_error"
4924 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4925 "right" "left"
4926 )
4927 "List of VHDL'93 standardized enumeration values.")
d2ddb974 4928
5eabfe72
KH
4929(defconst vhdl-ams-enum-values
4930 '(
4931 "quiescent_domain" "time_domain" "frequency_domain"
3dcb36b7
JB
4932 ;; from `nature_pkg' package
4933 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5eabfe72
KH
4934 )
4935 "List of VHDL-AMS standardized enumeration values.")
4936
4937(defconst vhdl-math-constants
4938 '(
4939 "math_e" "math_1_over_e"
4940 "math_pi" "math_two_pi" "math_1_over_pi"
4941 "math_half_pi" "math_q_pi" "math_3_half_pi"
4942 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4943 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4944 "math_deg_to_rad" "math_rad_to_deg"
4945 "cbase_1" "cbase_j" "czero"
4946 )
4947 "List of Math Packages standardized constants.")
4948
4949(defconst vhdl-93-functions
4950 '(
4951 "now" "resolved" "rising_edge" "falling_edge"
4952 "read" "readline" "write" "writeline" "endfile"
4953 "resize" "is_X" "std_match"
4954 "shift_left" "shift_right" "rotate_left" "rotate_right"
4955 "to_unsigned" "to_signed" "to_integer"
4956 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4957 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4958 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4959 "shl" "shr" "ext" "sxt"
3dcb36b7 4960 "deallocate"
5eabfe72
KH
4961 )
4962 "List of VHDL'93 standardized functions.")
4963
4964(defconst vhdl-ams-functions
4965 '(
4966 "frequency"
4967 )
4968 "List of VHDL-AMS standardized functions.")
4969
4970(defconst vhdl-math-functions
4971 '(
4972 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4973 "sqrt" "cbrt" "exp" "log"
4974 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4975 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4976 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4977 )
4978 "List of Math Packages standardized functions.")
4979
4980(defconst vhdl-93-packages
4981 '(
4982 "std_logic_1164" "numeric_std" "numeric_bit"
4983 "standard" "textio"
4984 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4985 "std_logic_misc" "std_logic_textio"
4986 "ieee" "std" "work"
4987 )
4988 "List of VHDL'93 standardized packages and libraries.")
4989
3dcb36b7
JB
4990(defconst vhdl-ams-packages
4991 '(
4992 ;; from `nature_pkg' package
4993 "nature_pkg"
4994 )
4995 "List of VHDL-AMS standardized packages and libraries.")
4996
5eabfe72
KH
4997(defconst vhdl-math-packages
4998 '(
4999 "math_real" "math_complex"
5000 )
5001 "List of Math Packages standardized packages and libraries.")
5002
5003(defvar vhdl-keywords nil
5004 "List of VHDL keywords.")
5005
5006(defvar vhdl-types nil
5007 "List of VHDL standardized types.")
5008
5009(defvar vhdl-attributes nil
5010 "List of VHDL standardized attributes.")
5011
5012(defvar vhdl-enum-values nil
5013 "List of VHDL standardized enumeration values.")
5014
5015(defvar vhdl-constants nil
5016 "List of VHDL standardized constants.")
5017
5018(defvar vhdl-functions nil
5019 "List of VHDL standardized functions.")
5020
5021(defvar vhdl-packages nil
5022 "List of VHDL standardized packages and libraries.")
5023
5024(defvar vhdl-reserved-words nil
5025 "List of additional reserved words.")
5026
5027(defvar vhdl-keywords-regexp nil
5028 "Regexp for VHDL keywords.")
5029
5030(defvar vhdl-types-regexp nil
5031 "Regexp for VHDL standardized types.")
5032
5033(defvar vhdl-attributes-regexp nil
5034 "Regexp for VHDL standardized attributes.")
5035
5036(defvar vhdl-enum-values-regexp nil
5037 "Regexp for VHDL standardized enumeration values.")
5038
5039(defvar vhdl-functions-regexp nil
5040 "Regexp for VHDL standardized functions.")
5041
5042(defvar vhdl-packages-regexp nil
5043 "Regexp for VHDL standardized packages and libraries.")
5044
5045(defvar vhdl-reserved-words-regexp nil
5046 "Regexp for additional reserved words.")
5047
3dcb36b7
JB
5048(defvar vhdl-directive-keywords-regexp nil
5049 "Regexp for compiler directive keywords.")
5050
5eabfe72
KH
5051(defun vhdl-words-init ()
5052 "Initialize reserved words."
5053 (setq vhdl-keywords
5054 (append vhdl-93-keywords
5055 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5056 (setq vhdl-types
5057 (append vhdl-93-types
5058 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5059 (when (vhdl-standard-p 'math) vhdl-math-types)))
5060 (setq vhdl-attributes
5061 (append vhdl-93-attributes
5062 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5063 (setq vhdl-enum-values
5064 (append vhdl-93-enum-values
5065 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5066 (setq vhdl-constants
5067 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5068 (setq vhdl-functions
5069 (append vhdl-93-functions
5070 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5071 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5072 (setq vhdl-packages
5073 (append vhdl-93-packages
3dcb36b7 5074 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5eabfe72
KH
5075 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5076 (setq vhdl-reserved-words
5077 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5078 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5079 '("")))
5080 (setq vhdl-keywords-regexp
5081 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5082 (setq vhdl-types-regexp
5083 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5084 (setq vhdl-attributes-regexp
5085 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5086 (setq vhdl-enum-values-regexp
5087 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5088 (setq vhdl-functions-regexp
5089 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5090 (setq vhdl-packages-regexp
5091 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5092 (setq vhdl-reserved-words-regexp
5093 (concat "\\<\\("
5094 (unless (equal vhdl-forbidden-syntax "")
5095 (concat vhdl-forbidden-syntax "\\|"))
5096 (regexp-opt vhdl-reserved-words)
5097 "\\)\\>"))
3dcb36b7
JB
5098 (setq vhdl-directive-keywords-regexp
5099 (concat "\\<\\(" (mapconcat 'regexp-quote
5100 vhdl-directive-keywords "\\|") "\\)\\>"))
5eabfe72
KH
5101 (vhdl-abbrev-list-init))
5102
5103;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5104;; Words to expand
5105
5106(defvar vhdl-abbrev-list nil
5107 "Predefined abbreviations for VHDL.")
5108
5109(defun vhdl-abbrev-list-init ()
5110 (setq vhdl-abbrev-list
5111 (append
5112 (list vhdl-upper-case-keywords) vhdl-keywords
5113 (list vhdl-upper-case-types) vhdl-types
5114 (list vhdl-upper-case-attributes) vhdl-attributes
5115 (list vhdl-upper-case-enum-values) vhdl-enum-values
5116 (list vhdl-upper-case-constants) vhdl-constants
5117 (list nil) vhdl-functions
5118 (list nil) vhdl-packages)))
5119
5120;; initialize reserved words for VHDL Mode
5121(vhdl-words-init)
5122
5123
5124;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 5125;;; Indentation
5eabfe72
KH
5126;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5127
5128;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
5129;; Syntax analysis
5130
5131;; constant regular expressions for looking at various constructs
5132
5133(defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5134 "Regexp describing a VHDL symbol.
5135We cannot use just `word' syntax class since `_' cannot be in word
5136class. Putting underscore in word class breaks forward word movement
5137behavior that users are familiar with.")
5138
5139(defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5140 "Regexp describing a case statement header key.")
5141
5142(defconst vhdl-label-key
5143 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5144 "Regexp describing a VHDL label.")
5145
5146;; Macro definitions:
5147
5148(defmacro vhdl-point (position)
5eabfe72
KH
5149 "Return the value of point at certain commonly referenced POSITIONs.
5150POSITION can be one of the following symbols:
5151
5152bol -- beginning of line
5153eol -- end of line
5154bod -- beginning of defun
5155boi -- back to indentation
5156eoi -- last whitespace on line
5157ionl -- indentation of next line
5158iopl -- indentation of previous line
5159bonl -- beginning of next line
5160bopl -- beginning of previous line
5161
5162This function does not modify point or mark."
d2ddb974 5163 (or (and (eq 'quote (car-safe position))
3dcb36b7
JB
5164 (null (cddr position)))
5165 (error "ERROR: Bad buffer position requested: %s" position))
d2ddb974 5166 (setq position (nth 1 position))
d4a5b644
GM
5167 `(let ((here (point)))
5168 ,@(cond
5169 ((eq position 'bol) '((beginning-of-line)))
5170 ((eq position 'eol) '((end-of-line)))
5171 ((eq position 'bod) '((save-match-data
5172 (vhdl-beginning-of-defun))))
5173 ((eq position 'boi) '((back-to-indentation)))
3dcb36b7 5174 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
d4a5b644
GM
5175 ((eq position 'bonl) '((forward-line 1)))
5176 ((eq position 'bopl) '((forward-line -1)))
5177 ((eq position 'iopl)
5178 '((forward-line -1)
5179 (back-to-indentation)))
5180 ((eq position 'ionl)
5181 '((forward-line 1)
5182 (back-to-indentation)))
3dcb36b7 5183 (t (error "ERROR: Unknown buffer position requested: %s" position))
d4a5b644
GM
5184 )
5185 (prog1
5186 (point)
5187 (goto-char here))
5188 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5189 ;; doesn't hurt for v19
5190 ,@nil
5191 ))
d2ddb974
KH
5192
5193(defmacro vhdl-safe (&rest body)
5eabfe72 5194 "Safely execute BODY, return nil if an error occurred."
d4a5b644
GM
5195 `(condition-case nil
5196 (progn ,@body)
5197 (error nil)))
d2ddb974
KH
5198
5199(defmacro vhdl-add-syntax (symbol &optional relpos)
5eabfe72
KH
5200 "A simple macro to append the syntax in SYMBOL to the syntax list.
5201Try to increase performance by using this macro."
d4a5b644
GM
5202 `(setq vhdl-syntactic-context
5203 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
d2ddb974
KH
5204
5205(defmacro vhdl-has-syntax (symbol)
5eabfe72
KH
5206 "A simple macro to return check the syntax list.
5207Try to increase performance by using this macro."
d4a5b644 5208 `(assoc ,symbol vhdl-syntactic-context))
d2ddb974
KH
5209
5210;; Syntactic element offset manipulation:
5211
5212(defun vhdl-read-offset (langelem)
5eabfe72 5213 "Read new offset value for LANGELEM from minibuffer.
2e8b9c7d 5214Return a valid value only."
d2ddb974
KH
5215 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5216 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5217 (prompt "Offset: ")
5218 offset input interned)
5219 (while (not offset)
5220 (setq input (read-string prompt oldoff)
5221 offset (cond ((string-equal "+" input) '+)
5222 ((string-equal "-" input) '-)
5223 ((string-equal "++" input) '++)
5224 ((string-equal "--" input) '--)
5225 ((string-match "^-?[0-9]+$" input)
027a4b6b 5226 (string-to-number input))
d2ddb974
KH
5227 ((fboundp (setq interned (intern input)))
5228 interned)
5229 ((boundp interned) interned)
5230 ;; error, but don't signal one, keep trying
5231 ;; to read an input value
5232 (t (ding)
5233 (setq prompt errmsg)
5234 nil))))
5235 offset))
5236
5237(defun vhdl-set-offset (symbol offset &optional add-p)
5238 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5239SYMBOL is the syntactic element symbol to change and OFFSET is the new
5240offset for that syntactic element. Optional ADD says to add SYMBOL to
5241`vhdl-offsets-alist' if it doesn't already appear there."
5242 (interactive
5243 (let* ((langelem
5244 (intern (completing-read
5245 (concat "Syntactic symbol to change"
5246 (if current-prefix-arg " or add" "")
5247 ": ")
5248 (mapcar
5249 (function
5250 (lambda (langelem)
5251 (cons (format "%s" (car langelem)) nil)))
5252 vhdl-offsets-alist)
5253 nil (not current-prefix-arg)
5254 ;; initial contents tries to be the last element
5255 ;; on the syntactic analysis list for the current
5256 ;; line
5257 (let* ((syntax (vhdl-get-syntactic-context))
5258 (len (length syntax))
5259 (ic (format "%s" (car (nth (1- len) syntax)))))
5eabfe72 5260 ic)
d2ddb974
KH
5261 )))
5262 (offset (vhdl-read-offset langelem)))
5263 (list langelem offset current-prefix-arg)))
5264 ;; sanity check offset
5265 (or (eq offset '+)
5266 (eq offset '-)
5267 (eq offset '++)
5268 (eq offset '--)
5269 (integerp offset)
5270 (fboundp offset)
5271 (boundp offset)
3dcb36b7 5272 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
d2ddb974
KH
5273 offset))
5274 (let ((entry (assq symbol vhdl-offsets-alist)))
5275 (if entry
5276 (setcdr entry offset)
5277 (if add-p
5eabfe72
KH
5278 (setq vhdl-offsets-alist
5279 (cons (cons symbol offset) vhdl-offsets-alist))
3dcb36b7 5280 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
d2ddb974
KH
5281 (vhdl-keep-region-active))
5282
5283(defun vhdl-set-style (style &optional local)
5eabfe72 5284 "Set `vhdl-mode' variables to use one of several different indentation styles.
d2ddb974
KH
5285STYLE is a string representing the desired style and optional LOCAL is
5286a flag which, if non-nil, means to make the style variables being
5287changed buffer local, instead of the default, which is to set the
5288global variables. Interactively, the flag comes from the prefix
5289argument. The styles are chosen from the `vhdl-style-alist' variable."
5290 (interactive (list (completing-read "Use which VHDL indentation style? "
5eabfe72 5291 vhdl-style-alist nil t)
d2ddb974
KH
5292 current-prefix-arg))
5293 (let ((vars (cdr (assoc style vhdl-style-alist))))
5294 (or vars
3dcb36b7 5295 (error "ERROR: Invalid VHDL indentation style `%s'" style))
d2ddb974
KH
5296 ;; set all the variables
5297 (mapcar
5298 (function
5299 (lambda (varentry)
5300 (let ((var (car varentry))
5301 (val (cdr varentry)))
5302 (and local
5303 (make-local-variable var))
5304 ;; special case for vhdl-offsets-alist
5305 (if (not (eq var 'vhdl-offsets-alist))
5306 (set var val)
5307 ;; reset vhdl-offsets-alist to the default value first
5308 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5309 ;; now set the langelems that are different
5310 (mapcar
5311 (function
5312 (lambda (langentry)
5313 (let ((langelem (car langentry))
5314 (offset (cdr langentry)))
5315 (vhdl-set-offset langelem offset)
5316 )))
5317 val))
5318 )))
5319 vars))
5320 (vhdl-keep-region-active))
5321
5322(defun vhdl-get-offset (langelem)
5eabfe72
KH
5323 "Get offset from LANGELEM which is a cons cell of the form:
5324\(SYMBOL . RELPOS). The symbol is matched against
5325vhdl-offsets-alist and the offset found there is either returned,
5326or added to the indentation at RELPOS. If RELPOS is nil, then
5327the offset is simply returned."
d2ddb974
KH
5328 (let* ((symbol (car langelem))
5329 (relpos (cdr langelem))
5330 (match (assq symbol vhdl-offsets-alist))
5331 (offset (cdr-safe match)))
5332 ;; offset can be a number, a function, a variable, or one of the
5333 ;; symbols + or -
5334 (cond
5335 ((not match)
5336 (if vhdl-strict-syntax-p
3dcb36b7 5337 (error "ERROR: Don't know how to indent a %s" symbol)
d2ddb974
KH
5338 (setq offset 0
5339 relpos 0)))
5340 ((eq offset '+) (setq offset vhdl-basic-offset))
5341 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5342 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5343 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5344 ((and (not (numberp offset))
5345 (fboundp offset))
5346 (setq offset (funcall offset langelem)))
5347 ((not (numberp offset))
5348 (setq offset (eval offset)))
5349 )
5350 (+ (if (and relpos
5351 (< relpos (vhdl-point 'bol)))
5352 (save-excursion
5353 (goto-char relpos)
5354 (current-column))
5355 0)
5356 offset)))
5357
5358;; Syntactic support functions:
5359
3dcb36b7
JB
5360(defun vhdl-in-comment-p ()
5361 "Check if point is in a comment."
5362 (eq (vhdl-in-literal) 'comment))
5363
5364(defun vhdl-in-string-p ()
5365 "Check if point is in a string."
5366 (eq (vhdl-in-literal) 'string))
d2ddb974 5367
3dcb36b7 5368(defun vhdl-in-literal ()
5eabfe72 5369 "Determine if point is in a VHDL literal."
d2ddb974 5370 (save-excursion
5eabfe72 5371 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
d2ddb974
KH
5372 (cond
5373 ((nth 3 state) 'string)
5374 ((nth 4 state) 'comment)
0a2e512a 5375 ((vhdl-beginning-of-macro) 'pound)
5eabfe72 5376 (t nil)))))
d2ddb974 5377
3dcb36b7
JB
5378(defun vhdl-forward-comment (&optional direction)
5379 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5380negative, skip forward otherwise."
5381 (interactive "p")
5382 (if (and direction (< direction 0))
5383 ;; skip backwards
5384 (progn
5385 (skip-chars-backward " \t\n")
5386 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5387 (goto-char (match-beginning 3))
5388 (skip-chars-backward " \t\n")))
5389 ;; skip forwards
5390 (skip-chars-forward " \t\n")
5391 (while (looking-at "--.*")
5392 (goto-char (match-end 0))
5393 (skip-chars-forward " \t\n"))))
5394
5395;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5396(unless (and vhdl-xemacs (string< "21.2" emacs-version))
5397 (defalias 'vhdl-forward-comment 'forward-comment))
5398
d2ddb974
KH
5399;; This is the best we can do in Win-Emacs.
5400(defun vhdl-win-il (&optional lim)
5eabfe72 5401 "Determine if point is in a VHDL literal."
d2ddb974
KH
5402 (save-excursion
5403 (let* ((here (point))
5404 (state nil)
5405 (match nil)
5406 (lim (or lim (vhdl-point 'bod))))
5407 (goto-char lim )
5408 (while (< (point) here)
5409 (setq match
5410 (and (re-search-forward "--\\|[\"']"
5411 here 'move)
5412 (buffer-substring (match-beginning 0) (match-end 0))))
5413 (setq state
5414 (cond
5415 ;; no match
5416 ((null match) nil)
5417 ;; looking at the opening of a VHDL style comment
5418 ((string= "--" match)
5419 (if (<= here (progn (end-of-line) (point))) 'comment))
5420 ;; looking at the opening of a double quote string
5421 ((string= "\"" match)
5422 (if (not (save-restriction
5423 ;; this seems to be necessary since the
5424 ;; re-search-forward will not work without it
5425 (narrow-to-region (point) here)
5426 (re-search-forward
5427 ;; this regexp matches a double quote
5428 ;; which is preceded by an even number
5429 ;; of backslashes, including zero
5430 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5431 'string))
5432 ;; looking at the opening of a single quote string
5433 ((string= "'" match)
5434 (if (not (save-restriction
5435 ;; see comments from above
5436 (narrow-to-region (point) here)
5437 (re-search-forward
5438 ;; this matches a single quote which is
5439 ;; preceded by zero or two backslashes.
5440 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5441 here 'move)))
5442 'string))
5443 (t nil)))
5444 ) ; end-while
5445 state)))
5446
5eabfe72 5447(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5448 (fset 'vhdl-in-literal 'vhdl-win-il))
5449
5450;; Skipping of "syntactic whitespace". Syntactic whitespace is
5451;; defined as lexical whitespace or comments. Search no farther back
5452;; or forward than optional LIM. If LIM is omitted, (point-min) is
5453;; used for backward skipping, (point-max) is used for forward
5454;; skipping.
5455
5456(defun vhdl-forward-syntactic-ws (&optional lim)
5eabfe72 5457 "Forward skip of syntactic whitespace."
0a2e512a
RF
5458 (let* ((here (point-max))
5459 (hugenum (point-max)))
5460 (while (/= here (point))
5461 (setq here (point))
5462 (vhdl-forward-comment hugenum)
5463 ;; skip preprocessor directives
5464 (when (and (eq (char-after) ?#)
5465 (= (vhdl-point 'boi) (point)))
5466 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5467 (= (forward-line 1) 0)))
5468 (end-of-line)))
5469 (if lim (goto-char (min (point) lim)))))
5470
d2ddb974
KH
5471
5472;; This is the best we can do in Win-Emacs.
5473(defun vhdl-win-fsws (&optional lim)
5eabfe72 5474 "Forward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5475 (let ((lim (or lim (point-max)))
5476 stop)
5477 (while (not stop)
5478 (skip-chars-forward " \t\n\r\f" lim)
5479 (cond
5480 ;; vhdl comment
5481 ((looking-at "--") (end-of-line))
5482 ;; none of the above
3dcb36b7 5483 (t (setq stop t))))))
d2ddb974 5484
5eabfe72 5485(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5486 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5487
0a2e512a
RF
5488(defun vhdl-beginning-of-macro (&optional lim)
5489 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5490 (let ((here (point)))
5491 (beginning-of-line)
5492 (while (eq (char-before (1- (point))) ?\\)
5493 (forward-line -1))
5494 (back-to-indentation)
5495 (if (and (<= (point) here)
5496 (eq (char-after) ?#))
5497 t
5498 (goto-char here)
5499 nil)))
5500
d2ddb974 5501(defun vhdl-backward-syntactic-ws (&optional lim)
5eabfe72 5502 "Backward skip over syntactic whitespace."
0a2e512a
RF
5503 (let* ((here (point-min))
5504 (hugenum (- (point-max))))
5505 (while (/= here (point))
5506 (setq here (point))
5507 (vhdl-forward-comment hugenum)
5508 (vhdl-beginning-of-macro))
5509 (if lim (goto-char (max (point) lim)))))
d2ddb974
KH
5510
5511;; This is the best we can do in Win-Emacs.
5512(defun vhdl-win-bsws (&optional lim)
5eabfe72 5513 "Backward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5514 (let ((lim (or lim (vhdl-point 'bod)))
5515 stop)
5516 (while (not stop)
5517 (skip-chars-backward " \t\n\r\f" lim)
5518 (cond
5519 ;; vhdl comment
3dcb36b7 5520 ((eq (vhdl-in-literal) 'comment)
d2ddb974
KH
5521 (skip-chars-backward "^-" lim)
5522 (skip-chars-backward "-" lim)
5523 (while (not (or (and (= (following-char) ?-)
5524 (= (char-after (1+ (point))) ?-))
5525 (<= (point) lim)))
5526 (skip-chars-backward "^-" lim)
5527 (skip-chars-backward "-" lim)))
5528 ;; none of the above
3dcb36b7 5529 (t (setq stop t))))))
d2ddb974 5530
5eabfe72 5531(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5532 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5533
5534;; Functions to help finding the correct indentation column:
5535
5536(defun vhdl-first-word (point)
5537 "If the keyword at POINT is at boi, then return (current-column) at
5538that point, else nil."
5539 (save-excursion
5540 (and (goto-char point)
5541 (eq (point) (vhdl-point 'boi))
5542 (current-column))))
5543
5544(defun vhdl-last-word (point)
5545 "If the keyword at POINT is at eoi, then return (current-column) at
5546that point, else nil."
5547 (save-excursion
5548 (and (goto-char point)
5549 (save-excursion (or (eq (progn (forward-sexp) (point))
5550 (vhdl-point 'eoi))
5551 (looking-at "\\s-*\\(--\\)?")))
5552 (current-column))))
5553
5554;; Core syntactic evaluation functions:
5555
5556(defconst vhdl-libunit-re
5557 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5558
5559(defun vhdl-libunit-p ()
5560 (and
5561 (save-excursion
5562 (forward-sexp)
5563 (skip-chars-forward " \t\n")
5564 (not (looking-at "is\\b[^_]")))
5565 (save-excursion
5566 (backward-sexp)
5567 (and (not (looking-at "use\\b[^_]"))
5568 (progn
5569 (forward-sexp)
5570 (vhdl-forward-syntactic-ws)
5571 (/= (following-char) ?:))))
5572 ))
5573
5574(defconst vhdl-defun-re
5eabfe72 5575 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
d2ddb974
KH
5576
5577(defun vhdl-defun-p ()
5578 (save-excursion
5eabfe72
KH
5579 (if (looking-at "block\\|process\\|procedural")
5580 ;; "block", "process", "procedural":
d2ddb974
KH
5581 (save-excursion
5582 (backward-sexp)
5583 (not (looking-at "end\\s-+\\w")))
5584 ;; "architecture", "configuration", "entity",
5585 ;; "package", "procedure", "function":
5586 t)))
5587
5588(defun vhdl-corresponding-defun ()
5589 "If the word at the current position corresponds to a \"defun\"
5590keyword, then return a string that can be used to find the
5591corresponding \"begin\" keyword, else return nil."
5592 (save-excursion
5593 (and (looking-at vhdl-defun-re)
5594 (vhdl-defun-p)
5eabfe72
KH
5595 (if (looking-at "block\\|process\\|procedural")
5596 ;; "block", "process". "procedural:
d2ddb974
KH
5597 (buffer-substring (match-beginning 0) (match-end 0))
5598 ;; "architecture", "configuration", "entity", "package",
5599 ;; "procedure", "function":
5600 "is"))))
5601
5602(defconst vhdl-begin-fwd-re
5eabfe72 5603 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
d2ddb974
KH
5604 "A regular expression for searching forward that matches all known
5605\"begin\" keywords.")
5606
5607(defconst vhdl-begin-bwd-re
5eabfe72 5608 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
d2ddb974
KH
5609 "A regular expression for searching backward that matches all known
5610\"begin\" keywords.")
5611
5612(defun vhdl-begin-p (&optional lim)
5613 "Return t if we are looking at a real \"begin\" keyword.
5614Assumes that the caller will make sure that we are looking at
5615vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5616the middle of an identifier that just happens to contain a \"begin\"
5617keyword."
5618 (cond
5619 ;; "[architecture|case|configuration|entity|package|
5620 ;; procedure|function] ... is":
5621 ((and (looking-at "i")
5622 (save-excursion
5623 ;; Skip backward over first sexp (needed to skip over a
5624 ;; procedure interface list, and is harmless in other
5625 ;; situations). Note that we need "return" in the
5626 ;; following search list so that we don't run into
5627 ;; semicolons in the function interface list.
5628 (backward-sexp)
5629 (let (foundp)
5630 (while (and (not foundp)
5631 (re-search-backward
5eabfe72 5632 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
d2ddb974
KH
5633 lim 'move))
5634 (if (or (= (preceding-char) ?_)
3dcb36b7 5635 (vhdl-in-literal))
d2ddb974
KH
5636 (backward-char)
5637 (setq foundp t))))
5638 (and (/= (following-char) ?\;)
5eabfe72 5639 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
d2ddb974
KH
5640 t)
5641 ;; "begin", "then":
5642 ((looking-at "be\\|t")
5643 t)
5644 ;; "else":
5645 ((and (looking-at "e")
5646 ;; make sure that the "else" isn't inside a
5647 ;; conditional signal assignment.
5648 (save-excursion
5649 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5650 (or (eq (following-char) ?\;)
5651 (eq (point) lim))))
5652 t)
5eabfe72 5653 ;; "block", "generate", "loop", "process", "procedural",
d2ddb974
KH
5654 ;; "units", "record":
5655 ((and (looking-at "bl\\|[glpur]")
5656 (save-excursion
5657 (backward-sexp)
5658 (not (looking-at "end\\s-+\\w"))))
5659 t)
5660 ;; "component":
5661 ((and (looking-at "c")
5662 (save-excursion
5663 (backward-sexp)
5664 (not (looking-at "end\\s-+\\w")))
5665 ;; look out for the dreaded entity class in an attribute
5666 (save-excursion
5667 (vhdl-backward-syntactic-ws lim)
5668 (/= (preceding-char) ?:)))
5669 t)
5670 ;; "for" (inside configuration declaration):
5671 ((and (looking-at "f")
5672 (save-excursion
5673 (backward-sexp)
5674 (not (looking-at "end\\s-+\\w")))
5675 (vhdl-has-syntax 'configuration))
5676 t)
5677 ))
5678
5679(defun vhdl-corresponding-mid (&optional lim)
5680 (cond
5eabfe72 5681 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
d2ddb974
KH
5682 "begin")
5683 ((looking-at "then")
5684 "<else>")
5685 (t
5686 "end")))
5687
5688(defun vhdl-corresponding-end (&optional lim)
5689 "If the word at the current position corresponds to a \"begin\"
5690keyword, then return a vector containing enough information to find
5691the corresponding \"end\" keyword, else return nil. The keyword to
5692search forward for is aref 0. The column in which the keyword must
5693appear is aref 1 or nil if any column is suitable.
5694Assumes that the caller will make sure that we are not in the middle
5695of an identifier that just happens to contain a \"begin\" keyword."
5696 (save-excursion
5697 (and (looking-at vhdl-begin-fwd-re)
5698 (/= (preceding-char) ?_)
3dcb36b7 5699 (not (vhdl-in-literal))
d2ddb974
KH
5700 (vhdl-begin-p lim)
5701 (cond
5702 ;; "is", "generate", "loop":
5703 ((looking-at "[igl]")
5704 (vector "end"
5705 (and (vhdl-last-word (point))
5706 (or (vhdl-first-word (point))
5707 (save-excursion
5708 (vhdl-beginning-of-statement-1 lim)
5709 (vhdl-backward-skip-label lim)
5710 (vhdl-first-word (point)))))))
5711 ;; "begin", "else", "for":
5712 ((looking-at "be\\|[ef]")
5713 (vector "end"
5714 (and (vhdl-last-word (point))
5715 (or (vhdl-first-word (point))
5716 (save-excursion
5717 (vhdl-beginning-of-statement-1 lim)
5718 (vhdl-backward-skip-label lim)
5719 (vhdl-first-word (point)))))))
5720 ;; "component", "units", "record":
5721 ((looking-at "[cur]")
5722 ;; The first end found will close the block
5723 (vector "end" nil))
5eabfe72 5724 ;; "block", "process", "procedural":
d2ddb974
KH
5725 ((looking-at "bl\\|p")
5726 (vector "end"
5727 (or (vhdl-first-word (point))
5728 (save-excursion
5729 (vhdl-beginning-of-statement-1 lim)
5730 (vhdl-backward-skip-label lim)
5731 (vhdl-first-word (point))))))
5732 ;; "then":
5733 ((looking-at "t")
5734 (vector "elsif\\|else\\|end\\s-+if"
5735 (and (vhdl-last-word (point))
5736 (or (vhdl-first-word (point))
5737 (save-excursion
5738 (vhdl-beginning-of-statement-1 lim)
5739 (vhdl-backward-skip-label lim)
5740 (vhdl-first-word (point)))))))
5741 ))))
5742
5743(defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5744
5745(defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5746
5747(defun vhdl-end-p (&optional lim)
5748 "Return t if we are looking at a real \"end\" keyword.
5749Assumes that the caller will make sure that we are looking at
5750vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5751the middle of an identifier that just happens to contain an \"end\"
5752keyword."
5753 (or (not (looking-at "else"))
5754 ;; make sure that the "else" isn't inside a conditional signal
5755 ;; assignment.
5756 (save-excursion
5757 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5758 (or (eq (following-char) ?\;)
0a2e512a
RF
5759 (eq (point) lim)
5760 (vhdl-in-literal)))))
d2ddb974
KH
5761
5762(defun vhdl-corresponding-begin (&optional lim)
5763 "If the word at the current position corresponds to an \"end\"
5764keyword, then return a vector containing enough information to find
5765the corresponding \"begin\" keyword, else return nil. The keyword to
3dcb36b7 5766search backward for is aref 0. The column in which the keyword must
d2ddb974
KH
5767appear is aref 1 or nil if any column is suitable. The supplementary
5768keyword to search forward for is aref 2 or nil if this is not
5769required. If aref 3 is t, then the \"begin\" keyword may be found in
5770the middle of a statement.
5771Assumes that the caller will make sure that we are not in the middle
5772of an identifier that just happens to contain an \"end\" keyword."
5773 (save-excursion
5774 (let (pos)
5775 (if (and (looking-at vhdl-end-fwd-re)
3dcb36b7 5776 (not (vhdl-in-literal))
d2ddb974
KH
5777 (vhdl-end-p lim))
5778 (if (looking-at "el")
5779 ;; "else", "elsif":
5780 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5781 ;; "end ...":
5782 (setq pos (point))
5783 (forward-sexp)
5784 (skip-chars-forward " \t\n")
5785 (cond
5786 ;; "end if":
5787 ((looking-at "if\\b[^_]")
5788 (vector "else\\|elsif\\|if"
5789 (vhdl-first-word pos)
5790 "else\\|then" nil))
5791 ;; "end component":
5792 ((looking-at "component\\b[^_]")
5793 (vector (buffer-substring (match-beginning 1)
5794 (match-end 1))
5795 (vhdl-first-word pos)
5796 nil nil))
5797 ;; "end units", "end record":
5798 ((looking-at "\\(units\\|record\\)\\b[^_]")
5799 (vector (buffer-substring (match-beginning 1)
5800 (match-end 1))
5801 (vhdl-first-word pos)
5802 nil t))
5eabfe72
KH
5803 ;; "end block", "end process", "end procedural":
5804 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
d2ddb974
KH
5805 (vector "begin" (vhdl-first-word pos) nil nil))
5806 ;; "end case":
5807 ((looking-at "case\\b[^_]")
5808 (vector "case" (vhdl-first-word pos) "is" nil))
5809 ;; "end generate":
5810 ((looking-at "generate\\b[^_]")
5811 (vector "generate\\|for\\|if"
5812 (vhdl-first-word pos)
5813 "generate" nil))
5814 ;; "end loop":
5815 ((looking-at "loop\\b[^_]")
5816 (vector "loop\\|while\\|for"
5817 (vhdl-first-word pos)
5818 "loop" nil))
5819 ;; "end for" (inside configuration declaration):
5820 ((looking-at "for\\b[^_]")
5821 (vector "for" (vhdl-first-word pos) nil nil))
5822 ;; "end [id]":
5823 (t
5824 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5825 (vhdl-first-word pos)
5826 ;; return an alist of (statement . keyword) mappings
5827 '(
5828 ;; "begin ... end [id]":
0a2e512a 5829 ("begin" . nil)
d2ddb974 5830 ;; "architecture ... is ... begin ... end [id]":
0a2e512a 5831 ("architecture" . "is")
d2ddb974
KH
5832 ;; "configuration ... is ... end [id]":
5833 ("configuration" . "is")
5834 ;; "entity ... is ... end [id]":
0a2e512a 5835 ("entity" . "is")
d2ddb974 5836 ;; "package ... is ... end [id]":
0a2e512a 5837 ("package" . "is")
d2ddb974
KH
5838 ;; "procedure ... is ... begin ... end [id]":
5839 ("procedure" . "is")
5840 ;; "function ... is ... begin ... end [id]":
5841 ("function" . "is")
5842 )
5843 nil))
5844 ))) ; "end ..."
5845 )))
5846
5847(defconst vhdl-leader-re
5eabfe72 5848 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
d2ddb974
KH
5849
5850(defun vhdl-end-of-leader ()
5851 (save-excursion
5eabfe72 5852 (cond ((looking-at "block\\|process\\|procedural")
d2ddb974
KH
5853 (if (save-excursion
5854 (forward-sexp)
5855 (skip-chars-forward " \t\n")
5856 (= (following-char) ?\())
5857 (forward-sexp 2)
5858 (forward-sexp))
3dcb36b7
JB
5859 (when (looking-at "[ \t\n]*is")
5860 (goto-char (match-end 0)))
d2ddb974
KH
5861 (point))
5862 ((looking-at "component")
5863 (forward-sexp 2)
3dcb36b7
JB
5864 (when (looking-at "[ \t\n]*is")
5865 (goto-char (match-end 0)))
d2ddb974
KH
5866 (point))
5867 ((looking-at "for")
5868 (forward-sexp 2)
5869 (skip-chars-forward " \t\n")
5870 (while (looking-at "[,:(]")
5871 (forward-sexp)
5872 (skip-chars-forward " \t\n"))
5873 (point))
5874 (t nil)
5875 )))
5876
5877(defconst vhdl-trailer-re
0a2e512a 5878 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
d2ddb974
KH
5879
5880(defconst vhdl-statement-fwd-re
5881 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5882 "A regular expression for searching forward that matches all known
5883\"statement\" keywords.")
5884
5885(defconst vhdl-statement-bwd-re
5886 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5887 "A regular expression for searching backward that matches all known
5888\"statement\" keywords.")
5889
5890(defun vhdl-statement-p (&optional lim)
5891 "Return t if we are looking at a real \"statement\" keyword.
5892Assumes that the caller will make sure that we are looking at
5eabfe72
KH
5893vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5894in the middle of an identifier that just happens to contain a
5895\"statement\" keyword."
d2ddb974
KH
5896 (cond
5897 ;; "for" ... "generate":
5898 ((and (looking-at "f")
5899 ;; Make sure it's the start of a parameter specification.
5900 (save-excursion
5901 (forward-sexp 2)
5902 (skip-chars-forward " \t\n")
5903 (looking-at "in\\b[^_]"))
5904 ;; Make sure it's not an "end for".
5905 (save-excursion
5906 (backward-sexp)
5907 (not (looking-at "end\\s-+\\w"))))
5908 t)
5909 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5910 ((and (looking-at "i")
5911 ;; Make sure it's not an "end if".
5912 (save-excursion
5913 (backward-sexp)
5914 (not (looking-at "end\\s-+\\w"))))
5915 t)
5916 ;; "while" ... "loop":
5917 ((looking-at "w")
5918 t)
5919 ))
5920
5921(defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5922 "Regexp describing a case statement alternative key.")
5923
5924(defun vhdl-case-alternative-p (&optional lim)
5925 "Return t if we are looking at a real case alternative.
5926Assumes that the caller will make sure that we are looking at
5927vhdl-case-alternative-re, and are not inside a literal, and that
5928we are not in the middle of an identifier that just happens to
5929contain a \"when\" keyword."
5930 (save-excursion
5931 (let (foundp)
5932 (while (and (not foundp)
5933 (re-search-backward ";\\|<=" lim 'move))
5934 (if (or (= (preceding-char) ?_)
3dcb36b7 5935 (vhdl-in-literal))
d2ddb974
KH
5936 (backward-char)
5937 (setq foundp t)))
5938 (or (eq (following-char) ?\;)
5939 (eq (point) lim)))
5940 ))
5941
5942;; Core syntactic movement functions:
5943
5944(defconst vhdl-b-t-b-re
5945 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5946
5947(defun vhdl-backward-to-block (&optional lim)
5948 "Move backward to the previous \"begin\" or \"end\" keyword."
5949 (let (foundp)
5950 (while (and (not foundp)
5951 (re-search-backward vhdl-b-t-b-re lim 'move))
5952 (if (or (= (preceding-char) ?_)
3dcb36b7 5953 (vhdl-in-literal))
d2ddb974
KH
5954 (backward-char)
5955 (cond
5956 ;; "begin" keyword:
5957 ((and (looking-at vhdl-begin-fwd-re)
5958 (/= (preceding-char) ?_)
5959 (vhdl-begin-p lim))
5960 (setq foundp 'begin))
5961 ;; "end" keyword:
5962 ((and (looking-at vhdl-end-fwd-re)
5963 (/= (preceding-char) ?_)
5964 (vhdl-end-p lim))
5965 (setq foundp 'end))
5966 ))
5967 )
5968 foundp
5969 ))
5970
5971(defun vhdl-forward-sexp (&optional count lim)
5972 "Move forward across one balanced expression (sexp).
5973With COUNT, do it that many times."
5974 (interactive "p")
5975 (let ((count (or count 1))
5976 (case-fold-search t)
5977 end-vec target)
5978 (save-excursion
5979 (while (> count 0)
5980 ;; skip whitespace
5981 (skip-chars-forward " \t\n")
5982 ;; Check for an unbalanced "end" keyword
5983 (if (and (looking-at vhdl-end-fwd-re)
5984 (/= (preceding-char) ?_)
3dcb36b7 5985 (not (vhdl-in-literal))
d2ddb974
KH
5986 (vhdl-end-p lim)
5987 (not (looking-at "else")))
5988 (error
3dcb36b7 5989 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
d2ddb974
KH
5990 ;; If the current keyword is a "begin" keyword, then find the
5991 ;; corresponding "end" keyword.
5992 (if (setq end-vec (vhdl-corresponding-end lim))
5993 (let (
5994 ;; end-re is the statement keyword to search for
5995 (end-re
5996 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5997 ;; column is either the statement keyword target column
5998 ;; or nil
5999 (column (aref end-vec 1))
6000 (eol (vhdl-point 'eol))
6001 foundp literal placeholder)
6002 ;; Look for the statement keyword.
6003 (while (and (not foundp)
6004 (re-search-forward end-re nil t)
6005 (setq placeholder (match-end 1))
6006 (goto-char (match-beginning 0)))
6007 ;; If we are in a literal, or not in the right target
6008 ;; column and not on the same line as the begin, then
6009 ;; try again.
6010 (if (or (and column
6011 (/= (current-indentation) column)
6012 (> (point) eol))
6013 (= (preceding-char) ?_)
3dcb36b7 6014 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6015 (if (eq literal 'comment)
6016 (end-of-line)
6017 (forward-char))
6018 ;; An "else" keyword corresponds to both the opening brace
6019 ;; of the following sexp and the closing brace of the
6020 ;; previous sexp.
6021 (if (not (looking-at "else"))
6022 (goto-char placeholder))
6023 (setq foundp t))
6024 )
6025 (if (not foundp)
3dcb36b7 6026 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
d2ddb974
KH
6027 )
6028 ;; If the current keyword is not a "begin" keyword, then just
6029 ;; perform the normal forward-sexp.
6030 (forward-sexp)
6031 )
6032 (setq count (1- count))
6033 )
6034 (setq target (point)))
6035 (goto-char target)
6036 nil))
6037
6038(defun vhdl-backward-sexp (&optional count lim)
6039 "Move backward across one balanced expression (sexp).
6040With COUNT, do it that many times. LIM bounds any required backward
6041searches."
6042 (interactive "p")
6043 (let ((count (or count 1))
6044 (case-fold-search t)
6045 begin-vec target)
6046 (save-excursion
6047 (while (> count 0)
6048 ;; Perform the normal backward-sexp, unless we are looking at
6049 ;; "else" - an "else" keyword corresponds to both the opening brace
6050 ;; of the following sexp and the closing brace of the previous sexp.
6051 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6052 (/= (preceding-char) ?_)
3dcb36b7 6053 (not (vhdl-in-literal)))
d2ddb974
KH
6054 nil
6055 (backward-sexp)
6056 (if (and (looking-at vhdl-begin-fwd-re)
6057 (/= (preceding-char) ?_)
3dcb36b7 6058 (not (vhdl-in-literal))
d2ddb974 6059 (vhdl-begin-p lim))
3dcb36b7 6060 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
d2ddb974
KH
6061 ;; If the current keyword is an "end" keyword, then find the
6062 ;; corresponding "begin" keyword.
6063 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6064 (/= (preceding-char) ?_))
6065 (let (
6066 ;; begin-re is the statement keyword to search for
6067 (begin-re
6068 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6069 ;; column is either the statement keyword target column
6070 ;; or nil
6071 (column (aref begin-vec 1))
6072 ;; internal-p controls where the statement keyword can
6073 ;; be found.
6074 (internal-p (aref begin-vec 3))
6075 (last-backward (point)) last-forward
6076 foundp literal keyword)
6077 ;; Look for the statement keyword.
6078 (while (and (not foundp)
6079 (re-search-backward begin-re lim t)
6080 (setq keyword
6081 (buffer-substring (match-beginning 1)
6082 (match-end 1))))
6083 ;; If we are in a literal or in the wrong column,
6084 ;; then try again.
6085 (if (or (and column
6086 (and (/= (current-indentation) column)
6087 ;; possibly accept current-column as
6088 ;; well as current-indentation.
6089 (or (not internal-p)
6090 (/= (current-column) column))))
6091 (= (preceding-char) ?_)
3dcb36b7 6092 (vhdl-in-literal))
d2ddb974
KH
6093 (backward-char)
6094 ;; If there is a supplementary keyword, then
6095 ;; search forward for it.
6096 (if (and (setq begin-re (aref begin-vec 2))
6097 (or (not (listp begin-re))
6098 ;; If begin-re is an alist, then find the
6099 ;; element corresponding to the actual
6100 ;; keyword that we found.
6101 (progn
6102 (setq begin-re
6103 (assoc keyword begin-re))
6104 (and begin-re
6105 (setq begin-re (cdr begin-re))))))
6106 (and
6107 (setq begin-re
6108 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6109 (save-excursion
6110 (setq last-forward (point))
6111 ;; Look for the supplementary keyword
6112 ;; (bounded by the backward search start
6113 ;; point).
6114 (while (and (not foundp)
6115 (re-search-forward begin-re
6116 last-backward t)
6117 (goto-char (match-beginning 1)))
6118 ;; If we are in a literal, then try again.
6119 (if (or (= (preceding-char) ?_)
6120 (setq literal
3dcb36b7 6121 (vhdl-in-literal)))
d2ddb974
KH
6122 (if (eq literal 'comment)
6123 (goto-char
6124 (min (vhdl-point 'eol) last-backward))
6125 (forward-char))
6126 ;; We have found the supplementary keyword.
6127 ;; Save the position of the keyword in foundp.
6128 (setq foundp (point)))
6129 )
6130 foundp)
6131 ;; If the supplementary keyword was found, then
6132 ;; move point to the supplementary keyword.
6133 (goto-char foundp))
6134 ;; If there was no supplementary keyword, then
6135 ;; point is already at the statement keyword.
6136 (setq foundp t)))
6137 ) ; end of the search for the statement keyword
6138 (if (not foundp)
3dcb36b7 6139 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
d2ddb974
KH
6140 ))
6141 (setq count (1- count))
6142 )
6143 (setq target (point)))
6144 (goto-char target)
6145 nil))
6146
6147(defun vhdl-backward-up-list (&optional count limit)
6148 "Move backward out of one level of blocks.
6149With argument, do this that many times."
6150 (interactive "p")
6151 (let ((count (or count 1))
6152 target)
6153 (save-excursion
6154 (while (> count 0)
6155 (if (looking-at vhdl-defun-re)
3dcb36b7 6156 (error "ERROR: Unbalanced blocks"))
d2ddb974
KH
6157 (vhdl-backward-to-block limit)
6158 (setq count (1- count)))
6159 (setq target (point)))
6160 (goto-char target)))
6161
6162(defun vhdl-end-of-defun (&optional count)
6163 "Move forward to the end of a VHDL defun."
6164 (interactive)
6165 (let ((case-fold-search t))
6166 (vhdl-beginning-of-defun)
5eabfe72 6167 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6168 (re-search-forward "\\bis\\b"))
6169 (vhdl-forward-sexp)))
6170
6171(defun vhdl-mark-defun ()
6172 "Put mark at end of this \"defun\", point at beginning."
6173 (interactive)
6174 (let ((case-fold-search t))
6175 (push-mark)
6176 (vhdl-beginning-of-defun)
6177 (push-mark)
5eabfe72 6178 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6179 (re-search-forward "\\bis\\b"))
6180 (vhdl-forward-sexp)
6181 (exchange-point-and-mark)))
6182
6183(defun vhdl-beginning-of-libunit ()
6184 "Move backward to the beginning of a VHDL library unit.
6185Returns the location of the corresponding begin keyword, unless search
5eabfe72
KH
6186stops due to beginning or end of buffer.
6187Note that if point is between the \"libunit\" keyword and the
6188corresponding \"begin\" keyword, then that libunit will not be
a3dd3c0e
JB
6189recognized, and the search will continue backwards. If point is
6190at the \"begin\" keyword, then the defun will be recognized. The
5eabfe72 6191returned point is at the first character of the \"libunit\" keyword."
d2ddb974
KH
6192 (let ((last-forward (point))
6193 (last-backward
6194 ;; Just in case we are actually sitting on the "begin"
6195 ;; keyword, allow for the keyword and an extra character,
6196 ;; as this will be used when looking forward for the
6197 ;; "begin" keyword.
6198 (save-excursion (forward-word 1) (1+ (point))))
6199 foundp literal placeholder)
6200 ;; Find the "libunit" keyword.
6201 (while (and (not foundp)
6202 (re-search-backward vhdl-libunit-re nil 'move))
6203 ;; If we are in a literal, or not at a real libunit, then try again.
6204 (if (or (= (preceding-char) ?_)
3dcb36b7 6205 (vhdl-in-literal)
d2ddb974
KH
6206 (not (vhdl-libunit-p)))
6207 (backward-char)
6208 ;; Find the corresponding "begin" keyword.
6209 (setq last-forward (point))
6210 (while (and (not foundp)
6211 (re-search-forward "\\bis\\b[^_]" last-backward t)
6212 (setq placeholder (match-beginning 0)))
6213 (if (or (= (preceding-char) ?_)
3dcb36b7 6214 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6215 ;; It wasn't a real keyword, so keep searching.
6216 (if (eq literal 'comment)
6217 (goto-char
6218 (min (vhdl-point 'eol) last-backward))
6219 (forward-char))
6220 ;; We have found the begin keyword, loop will exit.
6221 (setq foundp placeholder)))
6222 ;; Go back to the libunit keyword
6223 (goto-char last-forward)))
6224 foundp))
6225
6226(defun vhdl-beginning-of-defun (&optional count)
6227 "Move backward to the beginning of a VHDL defun.
6228With argument, do it that many times.
6229Returns the location of the corresponding begin keyword, unless search
6230stops due to beginning or end of buffer."
6231 ;; Note that if point is between the "defun" keyword and the
6232 ;; corresponding "begin" keyword, then that defun will not be
0a2e512a
RF
6233 ;; recognized, and the search will continue backwards. If point is
6234 ;; at the "begin" keyword, then the defun will be recognized. The
d2ddb974
KH
6235 ;; returned point is at the first character of the "defun" keyword.
6236 (interactive "p")
6237 (let ((count (or count 1))
6238 (case-fold-search t)
6239 (last-forward (point))
6240 foundp)
6241 (while (> count 0)
6242 (setq foundp nil)
6243 (goto-char last-forward)
6244 (let ((last-backward
6245 ;; Just in case we are actually sitting on the "begin"
6246 ;; keyword, allow for the keyword and an extra character,
6247 ;; as this will be used when looking forward for the
6248 ;; "begin" keyword.
6249 (save-excursion (forward-word 1) (1+ (point))))
6250 begin-string literal)
6251 (while (and (not foundp)
6252 (re-search-backward vhdl-defun-re nil 'move))
6253 ;; If we are in a literal, then try again.
6254 (if (or (= (preceding-char) ?_)
3dcb36b7 6255 (vhdl-in-literal))
d2ddb974
KH
6256 (backward-char)
6257 (if (setq begin-string (vhdl-corresponding-defun))
6258 ;; This is a real defun keyword.
6259 ;; Find the corresponding "begin" keyword.
6260 ;; Look for the begin keyword.
6261 (progn
6262 ;; Save the search start point.
6263 (setq last-forward (point))
6264 (while (and (not foundp)
6265 (search-forward begin-string last-backward t))
6266 (if (or (= (preceding-char) ?_)
6267 (save-match-data
3dcb36b7 6268 (setq literal (vhdl-in-literal))))
d2ddb974
KH
6269 ;; It wasn't a real keyword, so keep searching.
6270 (if (eq literal 'comment)
6271 (goto-char
6272 (min (vhdl-point 'eol) last-backward))
6273 (forward-char))
6274 ;; We have found the begin keyword, loop will exit.
6275 (setq foundp (match-beginning 0)))
6276 )
6277 ;; Go back to the defun keyword
6278 (goto-char last-forward)) ; end search for begin keyword
6279 ))
6280 ) ; end of the search for the defun keyword
6281 )
6282 (setq count (1- count))
6283 )
6284 (vhdl-keep-region-active)
6285 foundp))
6286
8d422bd5 6287(defun vhdl-beginning-of-statement (&optional count lim interactive)
d2ddb974
KH
6288 "Go to the beginning of the innermost VHDL statement.
6289With prefix arg, go back N - 1 statements. If already at the
6290beginning of a statement then go to the beginning of the preceding
6291one. If within a string or comment, or next to a comment (only
6292whitespace between), move by sentences instead of statements.
6293
8d422bd5 6294When called from a program, this function takes 3 optional args: the
0a2e512a
RF
6295prefix arg, a buffer position limit which is the farthest back to
6296search, and an argument indicating an interactive call."
8d422bd5 6297 (interactive "p\np")
d2ddb974
KH
6298 (let ((count (or count 1))
6299 (case-fold-search t)
6300 (lim (or lim (point-min)))
6301 (here (point))
6302 state)
6303 (save-excursion
6304 (goto-char lim)
6305 (setq state (parse-partial-sexp (point) here nil nil)))
8d422bd5 6306 (if (and interactive
d2ddb974
KH
6307 (or (nth 3 state)
6308 (nth 4 state)
6309 (looking-at (concat "[ \t]*" comment-start-skip))))
6310 (forward-sentence (- count))
6311 (while (> count 0)
6312 (vhdl-beginning-of-statement-1 lim)
6313 (setq count (1- count))))
6314 ;; its possible we've been left up-buf of lim
6315 (goto-char (max (point) lim))
6316 )
6317 (vhdl-keep-region-active))
6318
6319(defconst vhdl-e-o-s-re
6320 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6321
6322(defun vhdl-end-of-statement ()
6323 "Very simple implementation."
6324 (interactive)
6325 (re-search-forward vhdl-e-o-s-re))
6326
6327(defconst vhdl-b-o-s-re
6328 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6329 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6330
6331(defun vhdl-beginning-of-statement-1 (&optional lim)
5eabfe72
KH
6332 "Move to the start of the current statement, or the previous
6333statement if already at the beginning of one."
d2ddb974
KH
6334 (let ((lim (or lim (point-min)))
6335 (here (point))
6336 (pos (point))
6337 donep)
6338 ;; go backwards one balanced expression, but be careful of
6339 ;; unbalanced paren being reached
6340 (if (not (vhdl-safe (progn (backward-sexp) t)))
6341 (progn
6342 (backward-up-list 1)
6343 (forward-char)
6344 (vhdl-forward-syntactic-ws here)
6345 (setq donep t)))
6346 (while (and (not donep)
6347 (not (bobp))
6348 ;; look backwards for a statement boundary
6349 (re-search-backward vhdl-b-o-s-re lim 'move))
6350 (if (or (= (preceding-char) ?_)
3dcb36b7 6351 (vhdl-in-literal))
d2ddb974
KH
6352 (backward-char)
6353 (cond
6354 ;; If we are looking at an open paren, then stop after it
6355 ((eq (following-char) ?\()
6356 (forward-char)
6357 (vhdl-forward-syntactic-ws here)
6358 (setq donep t))
6359 ;; If we are looking at a close paren, then skip it
6360 ((eq (following-char) ?\))
6361 (forward-char)
6362 (setq pos (point))
6363 (backward-sexp)
6364 (if (< (point) lim)
6365 (progn (goto-char pos)
6366 (vhdl-forward-syntactic-ws here)
6367 (setq donep t))))
6368 ;; If we are looking at a semicolon, then stop
6369 ((eq (following-char) ?\;)
6370 (progn
6371 (forward-char)
6372 (vhdl-forward-syntactic-ws here)
6373 (setq donep t)))
6374 ;; If we are looking at a "begin", then stop
6375 ((and (looking-at vhdl-begin-fwd-re)
6376 (/= (preceding-char) ?_)
6377 (vhdl-begin-p nil))
6378 ;; If it's a leader "begin", then find the
6379 ;; right place
6380 (if (looking-at vhdl-leader-re)
6381 (save-excursion
6382 ;; set a default stop point at the begin
6383 (setq pos (point))
6384 ;; is the start point inside the leader area ?
6385 (goto-char (vhdl-end-of-leader))
6386 (vhdl-forward-syntactic-ws here)
6387 (if (< (point) here)
6388 ;; start point was not inside leader area
6389 ;; set stop point at word after leader
6390 (setq pos (point))))
6391 (forward-word 1)
6392 (vhdl-forward-syntactic-ws here)
6393 (setq pos (point)))
6394 (goto-char pos)
6395 (setq donep t))
6396 ;; If we are looking at a "statement", then stop
6397 ((and (looking-at vhdl-statement-fwd-re)
6398 (/= (preceding-char) ?_)
6399 (vhdl-statement-p nil))
6400 (setq donep t))
6401 ;; If we are looking at a case alternative key, then stop
5eabfe72
KH
6402 ((and (looking-at vhdl-case-alternative-re)
6403 (vhdl-case-alternative-p lim))
d2ddb974
KH
6404 (save-excursion
6405 ;; set a default stop point at the when
6406 (setq pos (point))
6407 ;; is the start point inside the case alternative key ?
6408 (looking-at vhdl-case-alternative-re)
6409 (goto-char (match-end 0))
6410 (vhdl-forward-syntactic-ws here)
6411 (if (< (point) here)
6412 ;; start point was not inside the case alternative key
6413 ;; set stop point at word after case alternative keyleader
6414 (setq pos (point))))
6415 (goto-char pos)
6416 (setq donep t))
6417 ;; Bogus find, continue
6418 (t
6419 (backward-char)))))
6420 ))
6421
6422;; Defuns for calculating the current syntactic state:
6423
6424(defun vhdl-get-library-unit (bod placeholder)
5eabfe72
KH
6425 "If there is an enclosing library unit at bod, with it's \"begin\"
6426keyword at placeholder, then return the library unit type."
d2ddb974
KH
6427 (let ((here (vhdl-point 'bol)))
6428 (if (save-excursion
6429 (goto-char placeholder)
6430 (vhdl-safe (vhdl-forward-sexp 1 bod))
6431 (<= here (point)))
6432 (save-excursion
6433 (goto-char bod)
6434 (cond
6435 ((looking-at "e") 'entity)
6436 ((looking-at "a") 'architecture)
6437 ((looking-at "c") 'configuration)
6438 ((looking-at "p")
6439 (save-excursion
6440 (goto-char bod)
6441 (forward-sexp)
6442 (vhdl-forward-syntactic-ws here)
6443 (if (looking-at "body\\b[^_]")
6444 'package-body 'package))))))
6445 ))
6446
6447(defun vhdl-get-block-state (&optional lim)
5eabfe72
KH
6448 "Finds and records all the closest opens.
6449lim is the furthest back we need to search (it should be the
6450previous libunit keyword)."
d2ddb974
KH
6451 (let ((here (point))
6452 (lim (or lim (point-min)))
6453 keyword sexp-start sexp-mid sexp-end
6454 preceding-sexp containing-sexp
6455 containing-begin containing-mid containing-paren)
6456 (save-excursion
6457 ;; Find the containing-paren, and use that as the limit
6458 (if (setq containing-paren
6459 (save-restriction
6460 (narrow-to-region lim (point))
6461 (vhdl-safe (scan-lists (point) -1 1))))
6462 (setq lim containing-paren))
6463 ;; Look backwards for "begin" and "end" keywords.
6464 (while (and (> (point) lim)
6465 (not containing-sexp))
6466 (setq keyword (vhdl-backward-to-block lim))
6467 (cond
6468 ((eq keyword 'begin)
6469 ;; Found a "begin" keyword
6470 (setq sexp-start (point))
6471 (setq sexp-mid (vhdl-corresponding-mid lim))
6472 (setq sexp-end (vhdl-safe
6473 (save-excursion
6474 (vhdl-forward-sexp 1 lim) (point))))
6475 (if (and sexp-end (<= sexp-end here))
6476 ;; we want to record this sexp, but we only want to
6477 ;; record the last-most of any of them before here
6478 (or preceding-sexp
6479 (setq preceding-sexp sexp-start))
6480 ;; we're contained in this sexp so put sexp-start on
6481 ;; front of list
6482 (setq containing-sexp sexp-start)
6483 (setq containing-mid sexp-mid)
6484 (setq containing-begin t)))
6485 ((eq keyword 'end)
6486 ;; Found an "end" keyword
6487 (forward-sexp)
6488 (setq sexp-end (point))
6489 (setq sexp-mid nil)
6490 (setq sexp-start
6491 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6492 (progn (backward-sexp) (point))))
6493 ;; we want to record this sexp, but we only want to
6494 ;; record the last-most of any of them before here
6495 (or preceding-sexp
6496 (setq preceding-sexp sexp-start)))
6497 )))
6498 ;; Check if the containing-paren should be the containing-sexp
6499 (if (and containing-paren
6500 (or (null containing-sexp)
6501 (< containing-sexp containing-paren)))
6502 (setq containing-sexp containing-paren
6503 preceding-sexp nil
6504 containing-begin nil
6505 containing-mid nil))
6506 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6507 ))
6508
6509
6510(defconst vhdl-s-c-a-re
6511 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6512
6513(defun vhdl-skip-case-alternative (&optional lim)
5eabfe72
KH
6514 "Skip forward over case/when bodies, with optional maximal
6515limit. If no next case alternative is found, nil is returned and point
6516is not moved."
d2ddb974
KH
6517 (let ((lim (or lim (point-max)))
6518 (here (point))
6519 donep foundp)
6520 (while (and (< (point) lim)
6521 (not donep))
6522 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6523 (save-match-data
6524 (not (vhdl-in-literal)))
6525 (/= (match-beginning 0) here))
6526 (progn
6527 (goto-char (match-beginning 0))
6528 (cond
6529 ((and (looking-at "case")
6530 (re-search-forward "\\bis[^_]" lim t))
6531 (backward-sexp)
6532 (vhdl-forward-sexp))
6533 (t
6534 (setq donep t
6535 foundp t))))))
6536 (if (not foundp)
6537 (goto-char here))
6538 foundp))
6539
6540(defun vhdl-backward-skip-label (&optional lim)
5eabfe72
KH
6541 "Skip backward over a label, with optional maximal
6542limit. If label is not found, nil is returned and point
6543is not moved."
d2ddb974
KH
6544 (let ((lim (or lim (point-min)))
6545 placeholder)
6546 (if (save-excursion
6547 (vhdl-backward-syntactic-ws lim)
6548 (and (eq (preceding-char) ?:)
6549 (progn
6550 (backward-sexp)
6551 (setq placeholder (point))
6552 (looking-at vhdl-label-key))))
6553 (goto-char placeholder))
6554 ))
6555
6556(defun vhdl-forward-skip-label (&optional lim)
5eabfe72
KH
6557 "Skip forward over a label, with optional maximal
6558limit. If label is not found, nil is returned and point
6559is not moved."
d2ddb974
KH
6560 (let ((lim (or lim (point-max))))
6561 (if (looking-at vhdl-label-key)
6562 (progn
6563 (goto-char (match-end 0))
6564 (vhdl-forward-syntactic-ws lim)))
6565 ))
6566
6567(defun vhdl-get-syntactic-context ()
5eabfe72 6568 "Guess the syntactic description of the current line of VHDL code."
d2ddb974
KH
6569 (save-excursion
6570 (save-restriction
6571 (beginning-of-line)
6572 (let* ((indent-point (point))
6573 (case-fold-search t)
6574 vec literal containing-sexp preceding-sexp
6575 containing-begin containing-mid containing-leader
6576 char-before-ip char-after-ip begin-after-ip end-after-ip
6577 placeholder lim library-unit
6578 )
6579
6580 ;; Reset the syntactic context
6581 (setq vhdl-syntactic-context nil)
6582
6583 (save-excursion
6584 ;; Move to the start of the previous library unit, and
6585 ;; record the position of the "begin" keyword.
6586 (setq placeholder (vhdl-beginning-of-libunit))
6587 ;; The position of the "libunit" keyword gives us a gross
6588 ;; limit point.
6589 (setq lim (point))
6590 )
6591
6592 ;; If there is a previous library unit, and we are enclosed by
6593 ;; it, then set the syntax accordingly.
6594 (and placeholder
6595 (setq library-unit (vhdl-get-library-unit lim placeholder))
6596 (vhdl-add-syntax library-unit lim))
6597
6598 ;; Find the surrounding state.
6599 (if (setq vec (vhdl-get-block-state lim))
6600 (progn
6601 (setq containing-sexp (aref vec 0))
6602 (setq preceding-sexp (aref vec 1))
6603 (setq containing-begin (aref vec 2))
6604 (setq containing-mid (aref vec 3))
6605 ))
6606
6607 ;; set the limit on the farthest back we need to search
6608 (setq lim (if containing-sexp
6609 (save-excursion
6610 (goto-char containing-sexp)
6611 ;; set containing-leader if required
6612 (if (looking-at vhdl-leader-re)
6613 (setq containing-leader (vhdl-end-of-leader)))
6614 (vhdl-point 'bol))
6615 (point-min)))
6616
6617 ;; cache char before and after indent point, and move point to
6618 ;; the most likely position to perform the majority of tests
6619 (goto-char indent-point)
6620 (skip-chars-forward " \t")
3dcb36b7 6621 (setq literal (vhdl-in-literal))
d2ddb974
KH
6622 (setq char-after-ip (following-char))
6623 (setq begin-after-ip (and
6624 (not literal)
6625 (looking-at vhdl-begin-fwd-re)
6626 (vhdl-begin-p)))
6627 (setq end-after-ip (and
6628 (not literal)
6629 (looking-at vhdl-end-fwd-re)
6630 (vhdl-end-p)))
6631 (vhdl-backward-syntactic-ws lim)
6632 (setq char-before-ip (preceding-char))
6633 (goto-char indent-point)
6634 (skip-chars-forward " \t")
6635
6636 ;; now figure out syntactic qualities of the current line
6637 (cond
6638 ;; CASE 1: in a string or comment.
6639 ((memq literal '(string comment))
6640 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6641 ;; CASE 2: Line is at top level.
6642 ((null containing-sexp)
6643 ;; Find the point to which indentation will be relative
6644 (save-excursion
6645 (if (null preceding-sexp)
6646 ;; CASE 2X.1
6647 ;; no preceding-sexp -> use the preceding statement
6648 (vhdl-beginning-of-statement-1 lim)
6649 ;; CASE 2X.2
6650 ;; if there is a preceding-sexp then indent relative to it
6651 (goto-char preceding-sexp)
6652 ;; if not at boi, then the block-opening keyword is
6653 ;; probably following a label, so we need a different
6654 ;; relpos
6655 (if (/= (point) (vhdl-point 'boi))
6656 ;; CASE 2X.3
6657 (vhdl-beginning-of-statement-1 lim)))
6658 ;; v-b-o-s could have left us at point-min
6659 (and (bobp)
6660 ;; CASE 2X.4
6661 (vhdl-forward-syntactic-ws indent-point))
6662 (setq placeholder (point)))
6663 (cond
6664 ;; CASE 2A : we are looking at a block-open
6665 (begin-after-ip
6666 (vhdl-add-syntax 'block-open placeholder))
6667 ;; CASE 2B: we are looking at a block-close
6668 (end-after-ip
6669 (vhdl-add-syntax 'block-close placeholder))
6670 ;; CASE 2C: we are looking at a top-level statement
6671 ((progn
6672 (vhdl-backward-syntactic-ws lim)
6673 (or (bobp)
6674 (= (preceding-char) ?\;)))
6675 (vhdl-add-syntax 'statement placeholder))
6676 ;; CASE 2D: we are looking at a top-level statement-cont
6677 (t
6678 (vhdl-beginning-of-statement-1 lim)
6679 ;; v-b-o-s could have left us at point-min
6680 (and (bobp)
6681 ;; CASE 2D.1
6682 (vhdl-forward-syntactic-ws indent-point))
6683 (vhdl-add-syntax 'statement-cont (point)))
6684 )) ; end CASE 2
6685 ;; CASE 3: line is inside parentheses. Most likely we are
6686 ;; either in a subprogram argument (interface) list, or a
6687 ;; continued expression containing parentheses.
6688 ((null containing-begin)
6689 (vhdl-backward-syntactic-ws containing-sexp)
6690 (cond
6691 ;; CASE 3A: we are looking at the arglist closing paren
6692 ((eq char-after-ip ?\))
6693 (goto-char containing-sexp)
6694 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6695 ;; CASE 3B: we are looking at the first argument in an empty
6696 ;; argument list.
6697 ((eq char-before-ip ?\()
6698 (goto-char containing-sexp)
6699 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6700 ;; CASE 3C: we are looking at an arglist continuation line,
6701 ;; but the preceding argument is on the same line as the
6702 ;; opening paren. This case includes multi-line
6703 ;; expression paren groupings.
6704 ((and (save-excursion
6705 (goto-char (1+ containing-sexp))
6706 (skip-chars-forward " \t")
6707 (not (eolp))
6708 (not (looking-at "--")))
6709 (save-excursion
6710 (vhdl-beginning-of-statement-1 containing-sexp)
6711 (skip-chars-backward " \t(")
6712 (<= (point) containing-sexp)))
6713 (goto-char containing-sexp)
6714 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6715 ;; CASE 3D: we are looking at just a normal arglist
6716 ;; continuation line
6717 (t (vhdl-beginning-of-statement-1 containing-sexp)
6718 (vhdl-forward-syntactic-ws indent-point)
6719 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6720 ))
6721 ;; CASE 4: A block mid open
6722 ((and begin-after-ip
6723 (looking-at containing-mid))
6724 (goto-char containing-sexp)
6725 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6726 (if (looking-at vhdl-trailer-re)
6727 ;; CASE 4.1
6728 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6729 (vhdl-backward-skip-label (vhdl-point 'boi))
6730 (vhdl-add-syntax 'block-open (point)))
6731 ;; CASE 5: block close brace
6732 (end-after-ip
6733 (goto-char containing-sexp)
6734 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6735 (if (looking-at vhdl-trailer-re)
6736 ;; CASE 5.1
6737 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6738 (vhdl-backward-skip-label (vhdl-point 'boi))
6739 (vhdl-add-syntax 'block-close (point)))
6740 ;; CASE 6: A continued statement
6741 ((and (/= char-before-ip ?\;)
6742 ;; check it's not a trailer begin keyword, or a begin
6743 ;; keyword immediately following a label.
6744 (not (and begin-after-ip
6745 (or (looking-at vhdl-trailer-re)
6746 (save-excursion
6747 (vhdl-backward-skip-label containing-sexp)))))
6748 ;; check it's not a statement keyword
6749 (not (and (looking-at vhdl-statement-fwd-re)
6750 (vhdl-statement-p)))
6751 ;; see if the b-o-s is before the indent point
6752 (> indent-point
6753 (save-excursion
6754 (vhdl-beginning-of-statement-1 containing-sexp)
6755 ;; If we ended up after a leader, then this will
6756 ;; move us forward to the start of the first
6757 ;; statement. Note that a containing sexp here is
6758 ;; always a keyword, not a paren, so this will
6759 ;; have no effect if we hit the containing-sexp.
6760 (vhdl-forward-syntactic-ws indent-point)
6761 (setq placeholder (point))))
6762 ;; check it's not a block-intro
6763 (/= placeholder containing-sexp)
6764 ;; check it's not a case block-intro
6765 (save-excursion
6766 (goto-char placeholder)
6767 (or (not (looking-at vhdl-case-alternative-re))
6768 (> (match-end 0) indent-point))))
6769 ;; Make placeholder skip a label, but only if it puts us
6770 ;; before the indent point at the start of a line.
6771 (let ((new placeholder))
6772 (if (and (> indent-point
6773 (save-excursion
6774 (goto-char placeholder)
6775 (vhdl-forward-skip-label indent-point)
6776 (setq new (point))))
6777 (save-excursion
6778 (goto-char new)
6779 (eq new (progn (back-to-indentation) (point)))))
6780 (setq placeholder new)))
6781 (vhdl-add-syntax 'statement-cont placeholder)
6782 (if begin-after-ip
6783 (vhdl-add-syntax 'block-open)))
6784 ;; Statement. But what kind?
6785 ;; CASE 7: A case alternative key
6786 ((and (looking-at vhdl-case-alternative-re)
6787 (vhdl-case-alternative-p containing-sexp))
6788 ;; for a case alternative key, we set relpos to the first
6789 ;; non-whitespace char on the line containing the "case"
6790 ;; keyword.
6791 (goto-char containing-sexp)
6792 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6793 (if (looking-at vhdl-trailer-re)
6794 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6795 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6796 ;; CASE 8: statement catchall
6797 (t
6798 ;; we know its a statement, but we need to find out if it is
6799 ;; the first statement in a block
6800 (if containing-leader
6801 (goto-char containing-leader)
6802 (goto-char containing-sexp)
6803 ;; Note that a containing sexp here is always a keyword,
6804 ;; not a paren, so skip over the keyword.
6805 (forward-sexp))
6806 ;; move to the start of the first statement
6807 (vhdl-forward-syntactic-ws indent-point)
6808 (setq placeholder (point))
6809 ;; we want to ignore case alternatives keys when skipping forward
6810 (let (incase-p)
6811 (while (looking-at vhdl-case-alternative-re)
6812 (setq incase-p (point))
6813 ;; we also want to skip over the body of the
6814 ;; case/when statement if that doesn't put us at
6815 ;; after the indent-point
6816 (while (vhdl-skip-case-alternative indent-point))
6817 ;; set up the match end
6818 (looking-at vhdl-case-alternative-re)
6819 (goto-char (match-end 0))
6820 ;; move to the start of the first case alternative statement
6821 (vhdl-forward-syntactic-ws indent-point)
6822 (setq placeholder (point)))
6823 (cond
6824 ;; CASE 8A: we saw a case/when statement so we must be
6825 ;; in a switch statement. find out if we are at the
6826 ;; statement just after a case alternative key
6827 ((and incase-p
6828 (= (point) indent-point))
6829 ;; relpos is the "when" keyword
6830 (vhdl-add-syntax 'statement-case-intro incase-p))
6831 ;; CASE 8B: any old statement
6832 ((< (point) indent-point)
6833 ;; relpos is the first statement of the block
6834 (vhdl-add-syntax 'statement placeholder)
6835 (if begin-after-ip
6836 (vhdl-add-syntax 'block-open)))
6837 ;; CASE 8C: first statement in a block
6838 (t
6839 (goto-char containing-sexp)
6840 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6841 (if (looking-at vhdl-trailer-re)
6842 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6843 (vhdl-backward-skip-label (vhdl-point 'boi))
6844 (vhdl-add-syntax 'statement-block-intro (point))
6845 (if begin-after-ip
6846 (vhdl-add-syntax 'block-open)))
6847 )))
6848 )
6849
6850 ;; now we need to look at any modifiers
6851 (goto-char indent-point)
6852 (skip-chars-forward " \t")
6853 (if (looking-at "--")
6854 (vhdl-add-syntax 'comment))
0a2e512a
RF
6855 (if (eq literal 'pound)
6856 (vhdl-add-syntax 'cpp-macro))
d2ddb974
KH
6857 ;; return the syntax
6858 vhdl-syntactic-context))))
6859
6860;; Standard indentation line-ups:
6861
6862(defun vhdl-lineup-arglist (langelem)
5eabfe72
KH
6863 "Lineup the current arglist line with the arglist appearing just
6864after the containing paren which starts the arglist."
d2ddb974
KH
6865 (save-excursion
6866 (let* ((containing-sexp
6867 (save-excursion
6868 ;; arglist-cont-nonempty gives relpos ==
6869 ;; to boi of containing-sexp paren. This
6870 ;; is good when offset is +, but bad
6871 ;; when it is vhdl-lineup-arglist, so we
6872 ;; have to special case a kludge here.
6873 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6874 (progn
6875 (beginning-of-line)
6876 (backward-up-list 1)
6877 (skip-chars-forward " \t" (vhdl-point 'eol)))
6878 (goto-char (cdr langelem)))
6879 (point)))
6880 (cs-curcol (save-excursion
6881 (goto-char (cdr langelem))
6882 (current-column))))
6883 (if (save-excursion
6884 (beginning-of-line)
6885 (looking-at "[ \t]*)"))
6886 (progn (goto-char (match-end 0))
6887 (backward-sexp)
6888 (forward-char)
6889 (vhdl-forward-syntactic-ws)
6890 (- (current-column) cs-curcol))
6891 (goto-char containing-sexp)
6892 (or (eolp)
6893 (let ((eol (vhdl-point 'eol))
6894 (here (progn
6895 (forward-char)
6896 (skip-chars-forward " \t")
6897 (point))))
6898 (vhdl-forward-syntactic-ws)
6899 (if (< (point) eol)
6900 (goto-char here))))
6901 (- (current-column) cs-curcol)
6902 ))))
6903
6904(defun vhdl-lineup-arglist-intro (langelem)
5eabfe72 6905 "Lineup an arglist-intro line to just after the open paren."
d2ddb974
KH
6906 (save-excursion
6907 (let ((cs-curcol (save-excursion
6908 (goto-char (cdr langelem))
6909 (current-column)))
6910 (ce-curcol (save-excursion
6911 (beginning-of-line)
6912 (backward-up-list 1)
6913 (skip-chars-forward " \t" (vhdl-point 'eol))
6914 (current-column))))
6915 (- ce-curcol cs-curcol -1))))
6916
6917(defun vhdl-lineup-comment (langelem)
5eabfe72
KH
6918 "Support old behavior for comment indentation. We look at
6919vhdl-comment-only-line-offset to decide how to indent comment
6920only-lines."
d2ddb974
KH
6921 (save-excursion
6922 (back-to-indentation)
6923 ;; at or to the right of comment-column
6924 (if (>= (current-column) comment-column)
6925 (vhdl-comment-indent)
6926 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6927 (if (not (bolp))
6928 (or (car-safe vhdl-comment-only-line-offset)
6929 vhdl-comment-only-line-offset)
6930 (or (cdr-safe vhdl-comment-only-line-offset)
6931 (car-safe vhdl-comment-only-line-offset)
0a2e512a 6932 -1000 ;jam it against the left side
d2ddb974
KH
6933 )))))
6934
6935(defun vhdl-lineup-statement-cont (langelem)
5eabfe72 6936 "Line up statement-cont after the assignment operator."
d2ddb974
KH
6937 (save-excursion
6938 (let* ((relpos (cdr langelem))
6939 (assignp (save-excursion
6940 (goto-char (vhdl-point 'boi))
6941 (and (re-search-forward "\\(<\\|:\\)="
6942 (vhdl-point 'eol) t)
6943 (- (point) (vhdl-point 'boi)))))
6944 (curcol (progn
6945 (goto-char relpos)
6946 (current-column)))
6947 foundp)
6948 (while (and (not foundp)
6949 (< (point) (vhdl-point 'eol)))
6950 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
3dcb36b7 6951 (if (vhdl-in-literal)
d2ddb974
KH
6952 (forward-char)
6953 (if (= (preceding-char) ?\()
6954 ;; skip over any parenthesized expressions
6955 (goto-char (min (vhdl-point 'eol)
6956 (scan-lists (point) 1 1)))
6957 ;; found an assignment operator (not at eol)
6958 (setq foundp (not (looking-at "\\s-*$"))))))
6959 (if (not foundp)
6960 ;; there's no assignment operator on the line
6961 vhdl-basic-offset
6962 ;; calculate indentation column after assign and ws, unless
6963 ;; our line contains an assignment operator
6964 (if (not assignp)
6965 (progn
6966 (forward-char)
6967 (skip-chars-forward " \t")
6968 (setq assignp 0)))
6969 (- (current-column) assignp curcol))
6970 )))
6971
5eabfe72 6972;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 6973;; Progress reporting
d2ddb974 6974
3dcb36b7
JB
6975(defvar vhdl-progress-info nil
6976 "Array variable for progress information: 0 begin, 1 end, 2 time.")
5eabfe72 6977
3dcb36b7
JB
6978(defun vhdl-update-progress-info (string pos)
6979 "Update progress information."
6980 (when (and vhdl-progress-info (not noninteractive)
6981 (< vhdl-progress-interval
6982 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6983 (message (concat string "... (%2d%s)")
6984 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6985 (- (aref vhdl-progress-info 1)
6986 (aref vhdl-progress-info 0))) "%")
6987 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
5eabfe72 6988
3dcb36b7
JB
6989;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6990;; Indentation commands
5eabfe72
KH
6991
6992(defun vhdl-electric-tab (&optional prefix-arg)
6993 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7
JB
6994else if right of non whitespace on line then insert tab,
6995else if last command was a tab or return then dedent one step or if a comment
6996toggle between normal indent and inline comment indent,
d2ddb974
KH
6997else indent `correctly'."
6998 (interactive "*P")
3dcb36b7
JB
6999 (vhdl-prepare-search-2
7000 (cond
7001 ;; expand word
7002 ((= (char-syntax (preceding-char)) ?w)
7003 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7004 (case-replace nil)
7005 (hippie-expand-only-buffers
7006 (or (and (boundp 'hippie-expand-only-buffers)
7007 hippie-expand-only-buffers)
7008 '(vhdl-mode))))
7009 (vhdl-expand-abbrev prefix-arg)))
7010 ;; expand parenthesis
7011 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7012 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7013 (case-replace nil))
7014 (vhdl-expand-paren prefix-arg)))
7015 ;; insert tab
7016 ((> (current-column) (current-indentation))
7017 (insert-tab))
7018 ;; toggle comment indent
7019 ((and (looking-at "--")
7020 (or (eq last-command 'vhdl-electric-tab)
7021 (eq last-command 'vhdl-electric-return)))
7022 (cond ((= (current-indentation) 0) ; no indent
7023 (indent-to 1)
7024 (indent-according-to-mode))
7025 ((< (current-indentation) comment-column) ; normal indent
7026 (indent-to comment-column)
7027 (indent-according-to-mode))
7028 (t ; inline comment indent
7029 (kill-line -0))))
7030 ;; dedent
7031 ((and (>= (current-indentation) vhdl-basic-offset)
7032 (or (eq last-command 'vhdl-electric-tab)
7033 (eq last-command 'vhdl-electric-return)))
7034 (backward-delete-char-untabify vhdl-basic-offset nil))
7035 ;; indent line
7036 (t (indent-according-to-mode)))
5eabfe72
KH
7037 (setq this-command 'vhdl-electric-tab)))
7038
7039(defun vhdl-electric-return ()
d2ddb974
KH
7040 "newline-and-indent or indent-new-comment-line if in comment and preceding
7041character is a space."
7042 (interactive)
7043 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7044 (indent-new-comment-line)
3dcb36b7
JB
7045 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7046 (vhdl-fix-case-word -1))
5eabfe72
KH
7047 (newline-and-indent)))
7048
d2ddb974 7049(defun vhdl-indent-line ()
5eabfe72 7050 "Indent the current line as VHDL code. Returns the amount of
d2ddb974
KH
7051indentation change."
7052 (interactive)
3dcb36b7 7053 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
d2ddb974 7054 (pos (- (point-max) (point)))
3dcb36b7
JB
7055 (indent
7056 (if syntax
7057 ;; indent syntax-based
7058 (if (and (eq (caar syntax) 'comment)
7059 (>= (vhdl-get-offset (car syntax)) comment-column))
7060 ;; special case: comments at or right of comment-column
7061 (vhdl-get-offset (car syntax))
7062 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7063 ;; indent like previous nonblank line
7064 (save-excursion (beginning-of-line)
7065 (re-search-backward "^[^\n]" nil t)
7066 (current-indentation))))
5eabfe72 7067 (shift-amt (- indent (current-indentation))))
d2ddb974
KH
7068 (and vhdl-echo-syntactic-information-p
7069 (message "syntax: %s, indent= %d" syntax indent))
5eabfe72 7070 (unless (zerop shift-amt)
d2ddb974
KH
7071 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7072 (beginning-of-line)
7073 (indent-to indent))
7074 (if (< (point) (vhdl-point 'boi))
7075 (back-to-indentation)
7076 ;; If initial point was within line's indentation, position after
7077 ;; the indentation. Else stay at same point in text.
5eabfe72
KH
7078 (when (> (- (point-max) pos) (point))
7079 (goto-char (- (point-max) pos))))
d2ddb974 7080 (run-hooks 'vhdl-special-indent-hook)
3dcb36b7 7081 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
d2ddb974
KH
7082 shift-amt))
7083
3dcb36b7 7084(defun vhdl-indent-region (beg end column)
5eabfe72
KH
7085 "Indent region as VHDL code.
7086Adds progress reporting to `indent-region'."
7087 (interactive "r\nP")
3dcb36b7
JB
7088 (when vhdl-progress-interval
7089 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7090 (count-lines (point-min) end) 0)))
7091 (indent-region beg end column)
5eabfe72
KH
7092 (when vhdl-progress-interval (message "Indenting...done"))
7093 (setq vhdl-progress-info nil))
d2ddb974 7094
3dcb36b7
JB
7095(defun vhdl-indent-buffer ()
7096 "Indent whole buffer as VHDL code.
7097Calls `indent-region' for whole buffer and adds progress reporting."
7098 (interactive)
7099 (vhdl-indent-region (point-min) (point-max) nil))
7100
7101(defun vhdl-indent-group ()
7102 "Indent group of lines between empty lines."
7103 (interactive)
7104 (let ((beg (save-excursion
7105 (if (re-search-backward vhdl-align-group-separate nil t)
7106 (point-marker)
7107 (point-min-marker))))
7108 (end (save-excursion
7109 (if (re-search-forward vhdl-align-group-separate nil t)
7110 (point-marker)
7111 (point-max-marker)))))
7112 (vhdl-indent-region beg end nil)))
7113
d2ddb974
KH
7114(defun vhdl-indent-sexp (&optional endpos)
7115 "Indent each line of the list starting just after point.
7116If optional arg ENDPOS is given, indent each line, stopping when
7117ENDPOS is encountered."
7118 (interactive)
7119 (save-excursion
7120 (let ((beg (point))
5eabfe72 7121 (end (progn (vhdl-forward-sexp nil endpos) (point))))
d2ddb974
KH
7122 (indent-region beg end nil))))
7123
5eabfe72 7124;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
7125;; Miscellaneous commands
7126
7127(defun vhdl-show-syntactic-information ()
7128 "Show syntactic information for current line."
7129 (interactive)
3dcb36b7 7130 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
d2ddb974
KH
7131 (vhdl-keep-region-active))
7132
7133;; Verification and regression functions:
7134
7135(defun vhdl-regress-line (&optional arg)
7136 "Check syntactic information for current line."
7137 (interactive "P")
7138 (let ((expected (save-excursion
7139 (end-of-line)
5eabfe72
KH
7140 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7141 (forward-char 4)
7142 (read (current-buffer)))))
d2ddb974
KH
7143 (actual (vhdl-get-syntactic-context))
7144 (expurgated))
7145 ;; remove the library unit symbols
7146 (mapcar
7147 (function
7148 (lambda (elt)
7149 (if (memq (car elt) '(entity configuration package
7150 package-body architecture))
7151 nil
7152 (setq expurgated (append expurgated (list elt))))))
7153 actual)
7154 (if (and (not arg) expected (listp expected))
7155 (if (not (equal expected expurgated))
3dcb36b7 7156 (error "ERROR: Should be: %s, is: %s" expected expurgated))
d2ddb974
KH
7157 (save-excursion
7158 (beginning-of-line)
5eabfe72
KH
7159 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7160 (end-of-line)
7161 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7162 (kill-line))
7163 (insert " -- ")
7164 (insert (format "%s" expurgated))))))
d2ddb974
KH
7165 (vhdl-keep-region-active))
7166
7167
5eabfe72
KH
7168;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7169;;; Alignment, whitespace fixup, beautifying
7170;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7171
3dcb36b7 7172(defconst vhdl-align-alist
d2ddb974
KH
7173 '(
7174 ;; after some keywords
3dcb36b7
JB
7175 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7176 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
d2ddb974 7177 ;; before ':'
5eabfe72 7178 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
d2ddb974 7179 ;; after direction specifications
5eabfe72
KH
7180 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7181 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7182 ;; before "==", ":=", "=>", and "<="
3dcb36b7 7183 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
5eabfe72 7184 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
3dcb36b7 7185 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
d2ddb974
KH
7186 ;; before some keywords
7187 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
d2ddb974
KH
7188 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7189 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
3dcb36b7
JB
7190 ;; before "=>" since "when/else ... =>" can occur
7191 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
d2ddb974 7192 )
5eabfe72 7193 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
d2ddb974
KH
7194It is searched in order. If REGEXP is found anywhere in the first
7195line of a region to be aligned, ALIGN-PATTERN will be used for that
7196region. ALIGN-PATTERN must include the whitespace to be expanded or
5eabfe72
KH
7197contracted. It may also provide regexps for the text surrounding the
7198whitespace. SUBEXP specifies which sub-expression of
d2ddb974
KH
7199ALIGN-PATTERN matches the white space to be expanded/contracted.")
7200
3dcb36b7
JB
7201;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7202;; Align code
7203
d2ddb974
KH
7204(defvar vhdl-align-try-all-clauses t
7205 "If REGEXP is not found on the first line of the region that clause
5eabfe72 7206is ignored. If this variable is non-nil, then the clause is tried anyway.")
d2ddb974 7207
3dcb36b7
JB
7208(defun vhdl-do-group (function &optional spacing)
7209 "Apply FUNCTION on group of lines between empty lines."
7210 (let
7211 ;; search for group beginning
7212 ((beg (save-excursion
7213 (if (re-search-backward vhdl-align-group-separate nil t)
7214 (progn (beginning-of-line 2) (back-to-indentation) (point))
7215 (point-min))))
7216 ;; search for group end
7217 (end (save-excursion
7218 (if (re-search-forward vhdl-align-group-separate nil t)
7219 (progn (beginning-of-line) (point))
7220 (point-max)))))
7221 ;; run FUNCTION
7222 (funcall function beg end spacing)))
7223
7224(defun vhdl-do-list (function &optional spacing)
7225 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7226parentheses."
7227 (let (beg end)
7228 (save-excursion
7229 ;; search for beginning of balanced group of parentheses
7230 (setq beg (vhdl-re-search-backward "[()]" nil t))
7231 (while (looking-at ")")
7232 (forward-char) (backward-sexp)
7233 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7234 ;; search for end of balanced group of parentheses
7235 (when beg
7236 (forward-list)
7237 (setq end (point))
7238 (goto-char (1+ beg))
7239 (skip-chars-forward " \t\n")
7240 (setq beg (point))))
7241 ;; run FUNCTION
7242 (if beg
7243 (funcall function beg end spacing)
7244 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7245
7246(defun vhdl-do-same-indent (function &optional spacing)
7247 "Apply FUNCTION to block of lines with same indent."
7248 (let ((indent (current-indentation))
7249 beg end)
7250 ;; search for first line with same indent
7251 (save-excursion
7252 (while (and (not (bobp))
7253 (or (looking-at "^\\s-*\\(--.*\\)?$")
7254 (= (current-indentation) indent)))
7255 (unless (looking-at "^\\s-*$")
7256 (back-to-indentation) (setq beg (point)))
7257 (beginning-of-line -0)))
7258 ;; search for last line with same indent
7259 (save-excursion
7260 (while (and (not (eobp))
7261 (or (looking-at "^\\s-*\\(--.*\\)?$")
7262 (= (current-indentation) indent)))
7263 (if (looking-at "^\\s-*$")
7264 (beginning-of-line 2)
7265 (beginning-of-line 2)
7266 (setq end (point)))))
7267 ;; run FUNCTION
7268 (funcall function beg end spacing)))
7269
7270(defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
d2ddb974 7271 "Attempt to align a range of lines based on the content of the
5eabfe72
KH
7272lines. The definition of `alignment-list' determines the matching
7273order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7274is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
d2ddb974
KH
7275indentation is done before aligning."
7276 (interactive "r\np")
5eabfe72
KH
7277 (setq alignment-list (or alignment-list vhdl-align-alist))
7278 (setq spacing (or spacing 1))
d2ddb974
KH
7279 (save-excursion
7280 (let (bol indent)
7281 (goto-char end)
7282 (setq end (point-marker))
7283 (goto-char begin)
5eabfe72 7284 (setq bol (setq begin (progn (beginning-of-line) (point))))
3dcb36b7 7285; (untabify bol end)
5eabfe72
KH
7286 (when indent
7287 (indent-region bol end nil))))
3dcb36b7
JB
7288 (let ((copy (copy-alist alignment-list)))
7289 (vhdl-prepare-search-2
5eabfe72
KH
7290 (while copy
7291 (save-excursion
7292 (goto-char begin)
7293 (let (element
7294 (eol (save-excursion (progn (end-of-line) (point)))))
7295 (setq element (nth 0 copy))
7296 (when (and (or (and (listp (car element))
7297 (memq major-mode (car element)))
7298 (eq major-mode (car element)))
7299 (or vhdl-align-try-all-clauses
7300 (re-search-forward (car (cdr element)) eol t)))
3dcb36b7 7301 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
5eabfe72
KH
7302 (car (cdr (cdr (cdr element)))) spacing))
7303 (setq copy (cdr copy))))))))
7304
3dcb36b7 7305(defun vhdl-align-region-2 (begin end match &optional substr spacing)
d2ddb974
KH
7306 "Align a range of lines from BEGIN to END. The regular expression
7307MATCH must match exactly one fields: the whitespace to be
7308contracted/expanded. The alignment column will equal the
7309rightmost column of the widest whitespace block. SPACING is
7310the amount of extra spaces to add to the calculated maximum required.
7311SPACING defaults to 1 so that at least one space is inserted after
7312the token in MATCH."
5eabfe72
KH
7313 (setq spacing (or spacing 1))
7314 (setq substr (or substr 1))
d2ddb974
KH
7315 (save-excursion
7316 (let (distance (max 0) (lines 0) bol eol width)
7317 ;; Determine the greatest whitespace distance to the alignment
7318 ;; character
7319 (goto-char begin)
7320 (setq eol (progn (end-of-line) (point))
5eabfe72 7321 bol (setq begin (progn (beginning-of-line) (point))))
d2ddb974 7322 (while (< bol end)
5eabfe72
KH
7323 (save-excursion
7324 (when (and (re-search-forward match eol t)
3dcb36b7 7325 (not (vhdl-in-literal)))
5eabfe72
KH
7326 (setq distance (- (match-beginning substr) bol))
7327 (when (> distance max)
7328 (setq max distance))))
7329 (forward-line)
7330 (setq bol (point)
7331 eol (save-excursion (end-of-line) (point)))
7332 (setq lines (1+ lines)))
d2ddb974
KH
7333 ;; Now insert enough maxs to push each assignment operator to
7334 ;; the same column. We need to use 'lines' as a counter, since
7335 ;; the location of the mark may change
7336 (goto-char (setq bol begin))
5eabfe72 7337 (setq eol (save-excursion (end-of-line) (point)))
d2ddb974 7338 (while (> lines 0)
5eabfe72 7339 (when (and (re-search-forward match eol t)
3dcb36b7 7340 (not (vhdl-in-literal)))
5eabfe72
KH
7341 (setq width (- (match-end substr) (match-beginning substr)))
7342 (setq distance (- (match-beginning substr) bol))
7343 (goto-char (match-beginning substr))
7344 (delete-char width)
7345 (insert-char ? (+ (- max distance) spacing)))
7346 (beginning-of-line)
7347 (forward-line)
7348 (setq bol (point)
7349 eol (save-excursion (end-of-line) (point)))
7350 (setq lines (1- lines))))))
7351
3dcb36b7
JB
7352(defun vhdl-align-region-groups (beg end &optional spacing
7353 no-message no-comments)
7354 "Align region, treat groups of lines separately."
d2ddb974 7355 (interactive "r\nP")
5eabfe72 7356 (save-excursion
3dcb36b7 7357 (let (orig pos)
5eabfe72
KH
7358 (goto-char beg)
7359 (beginning-of-line)
3dcb36b7 7360 (setq orig (point-marker))
5eabfe72
KH
7361 (setq beg (point))
7362 (goto-char end)
7363 (setq end (point-marker))
7364 (untabify beg end)
3dcb36b7
JB
7365 (unless no-message
7366 (when vhdl-progress-interval
7367 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7368 (count-lines (point-min) end) 0))))
5eabfe72
KH
7369 (vhdl-fixup-whitespace-region beg end t)
7370 (goto-char beg)
7371 (if (not vhdl-align-groups)
7372 ;; align entire region
3dcb36b7
JB
7373 (progn (vhdl-align-region-1 beg end spacing)
7374 (unless no-comments
7375 (vhdl-align-inline-comment-region-1 beg end)))
5eabfe72
KH
7376 ;; align groups
7377 (while (and (< beg end)
3dcb36b7 7378 (re-search-forward vhdl-align-group-separate end t))
5eabfe72 7379 (setq pos (point-marker))
3dcb36b7
JB
7380 (vhdl-align-region-1 beg pos spacing)
7381 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7382 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
5eabfe72
KH
7383 (setq beg (1+ pos))
7384 (goto-char beg))
7385 ;; align last group
7386 (when (< beg end)
3dcb36b7
JB
7387 (vhdl-align-region-1 beg end spacing)
7388 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7389 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7390 (when vhdl-indent-tabs-mode
7391 (tabify orig end))
7392 (unless no-message
7393 (when vhdl-progress-interval (message "Aligning...done"))
7394 (setq vhdl-progress-info nil)))))
7395
7396(defun vhdl-align-region (beg end &optional spacing)
7397 "Align region, treat blocks with same indent and argument lists separately."
7398 (interactive "r\nP")
7399 (if (not vhdl-align-same-indent)
7400 ;; align entire region
7401 (vhdl-align-region-groups beg end spacing)
7402 ;; align blocks with same indent and argument lists
7403 (save-excursion
7404 (let ((cur-beg beg)
7405 indent cur-end)
7406 (when vhdl-progress-interval
7407 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7408 (count-lines (point-min) end) 0)))
7409 (goto-char end)
7410 (setq end (point-marker))
7411 (goto-char cur-beg)
7412 (while (< (point) end)
7413 ;; is argument list opening?
7414 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7415 (point) (vhdl-point 'eol)))))
7416 ;; determine region for argument list
7417 (progn (goto-char cur-beg)
7418 (forward-sexp)
7419 (setq cur-end (point))
7420 (beginning-of-line 2))
7421 ;; determine region with same indent
7422 (setq indent (current-indentation))
7423 (setq cur-beg (point))
7424 (setq cur-end (vhdl-point 'bonl))
7425 (beginning-of-line 2)
7426 (while (and (< (point) end)
7427 (or (looking-at "^\\s-*\\(--.*\\)?$")
7428 (= (current-indentation) indent))
7429 (<= (save-excursion
7430 (nth 0 (parse-partial-sexp
7431 (point) (vhdl-point 'eol)))) 0))
7432 (unless (looking-at "^\\s-*$")
7433 (setq cur-end (vhdl-point 'bonl)))
7434 (beginning-of-line 2)))
7435 ;; align region
7436 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7437 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7438 (when vhdl-progress-interval (message "Aligning...done"))
7439 (setq vhdl-progress-info nil)))))
5eabfe72
KH
7440
7441(defun vhdl-align-group (&optional spacing)
7442 "Align group of lines between empty lines."
7443 (interactive)
3dcb36b7 7444 (vhdl-do-group 'vhdl-align-region spacing))
5eabfe72 7445
3dcb36b7
JB
7446(defun vhdl-align-list (&optional spacing)
7447 "Align the lines of a list surrounded by a balanced group of parentheses."
5eabfe72 7448 (interactive)
3dcb36b7
JB
7449 (vhdl-do-list 'vhdl-align-region-groups spacing))
7450
7451(defun vhdl-align-same-indent (&optional spacing)
7452 "Align block of lines with same indent."
7453 (interactive)
7454 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7455
7456(defun vhdl-align-declarations (&optional spacing)
7457 "Align the lines within the declarative part of a design unit."
7458 (interactive)
7459 (let (beg end)
7460 (vhdl-prepare-search-2
7461 (save-excursion
7462 ;; search for declarative part
7463 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7464 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7465 (setq beg (point))
7466 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7467 (setq end (point)))))
7468 (if beg
7469 (vhdl-align-region-groups beg end spacing)
7470 (error "ERROR: Not within the declarative part of a design unit"))))
7471
7472(defun vhdl-align-buffer ()
7473 "Align buffer."
7474 (interactive)
7475 (vhdl-align-region (point-min) (point-max)))
7476
7477;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7478;; Align inline comments
7479
7480(defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7481 "Align inline comments in region."
7482 (save-excursion
7483 (let ((start-max comment-column)
7484 (length-max 0)
7485 comment-list start-list tmp-list start length
7486 cur-start prev-start no-code)
7487 (setq spacing (or spacing 2))
7488 (vhdl-prepare-search-2
7489 (goto-char beg)
7490 ;; search for comment start positions and lengths
7491 (while (< (point) end)
7492 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7493 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7494 (not (save-excursion (goto-char (match-beginning 2))
7495 (vhdl-in-literal))))
7496 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7497 (setq length (- (match-end 2) (match-beginning 2)))
7498 (setq start-max (max start start-max))
7499 (setq length-max (max length length-max))
7500 (setq comment-list (cons (cons start length) comment-list)))
7501 (beginning-of-line 2))
7502 (setq comment-list
7503 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7504 ;; reduce start positions
7505 (setq start-list (list (caar comment-list)))
7506 (setq comment-list (cdr comment-list))
7507 (while comment-list
7508 (unless (or (= (caar comment-list) (car start-list))
7509 (<= (+ (car start-list) (cdar comment-list))
7510 end-comment-column))
7511 (setq start-list (cons (caar comment-list) start-list)))
7512 (setq comment-list (cdr comment-list)))
7513 ;; align lines as nicely as possible
7514 (goto-char beg)
7515 (while (< (point) end)
7516 (setq cur-start nil)
7517 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7518 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7519 (not (save-excursion
7520 (goto-char (match-beginning 3))
7521 (vhdl-in-literal))))
7522 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7523 (>= (- (match-end 2) (match-beginning 2))
7524 comment-column))))
7525 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7526 (setq length (- (match-end 3) (match-beginning 3)))
7527 (setq no-code (= (match-beginning 1) (match-end 1)))
7528 ;; insert minimum whitespace
7529 (goto-char (match-end 2))
7530 (delete-region (match-beginning 2) (match-end 2))
7531 (insert-char ?\ spacing)
7532 (setq tmp-list start-list)
7533 ;; insert additional whitespace to align
7534 (setq cur-start
7535 (cond
7536 ;; align comment-only line to inline comment of previous line
7537 ((and no-code prev-start
7538 (<= length (- end-comment-column prev-start)))
7539 prev-start)
7540 ;; align all comments at `start-max' if this is possible
7541 ((<= (+ start-max length-max) end-comment-column)
7542 start-max)
7543 ;; align at `comment-column' if possible
7544 ((and (<= start comment-column)
7545 (<= length (- end-comment-column comment-column)))
7546 comment-column)
7547 ;; align at left-most possible start position otherwise
7548 (t
7549 (while (and tmp-list (< (car tmp-list) start))
7550 (setq tmp-list (cdr tmp-list)))
7551 (car tmp-list))))
7552 (indent-to cur-start))
7553 (setq prev-start cur-start)
7554 (beginning-of-line 2))))))
d2ddb974 7555
5eabfe72
KH
7556(defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7557 "Align inline comments within a region. Groups of code lines separated by
7558empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
d2ddb974 7559 (interactive "r\nP")
5eabfe72 7560 (save-excursion
3dcb36b7 7561 (let (orig pos)
5eabfe72
KH
7562 (goto-char beg)
7563 (beginning-of-line)
3dcb36b7 7564 (setq orig (point-marker))
5eabfe72
KH
7565 (setq beg (point))
7566 (goto-char end)
7567 (setq end (point-marker))
7568 (untabify beg end)
7569 (unless no-message (message "Aligning inline comments..."))
7570 (goto-char beg)
7571 (if (not vhdl-align-groups)
7572 ;; align entire region
7573 (vhdl-align-inline-comment-region-1 beg end spacing)
7574 ;; align groups
3dcb36b7
JB
7575 (while (and (< beg end)
7576 (re-search-forward vhdl-align-group-separate end t))
5eabfe72
KH
7577 (setq pos (point-marker))
7578 (vhdl-align-inline-comment-region-1 beg pos spacing)
7579 (setq beg (1+ pos))
7580 (goto-char beg))
7581 ;; align last group
7582 (when (< beg end)
3dcb36b7
JB
7583 (vhdl-align-inline-comment-region-1 beg end spacing)))
7584 (when vhdl-indent-tabs-mode
7585 (tabify orig end))
7586 (unless no-message (message "Aligning inline comments...done")))))
5eabfe72
KH
7587
7588(defun vhdl-align-inline-comment-group (&optional spacing)
7589 "Align inline comments within a group of lines between empty lines."
7590 (interactive)
7591 (save-excursion
7592 (let ((start (point))
7593 beg end)
3dcb36b7 7594 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
5eabfe72
KH
7595 (point-marker) (point-max)))
7596 (goto-char start)
3dcb36b7
JB
7597 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7598 (point) (point-min)))
5eabfe72
KH
7599 (untabify beg end)
7600 (message "Aligning inline comments...")
7601 (vhdl-align-inline-comment-region-1 beg end)
3dcb36b7
JB
7602 (when vhdl-indent-tabs-mode
7603 (tabify beg end))
5eabfe72
KH
7604 (message "Aligning inline comments...done"))))
7605
7606(defun vhdl-align-inline-comment-buffer ()
7607 "Align inline comments within buffer. Groups of code lines separated by
7608empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7609 (interactive)
7610 (vhdl-align-inline-comment-region (point-min) (point-max)))
7611
3dcb36b7
JB
7612;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7613;; Fixup whitespace
7614
5eabfe72
KH
7615(defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7616 "Fixup whitespace in region. Surround operator symbols by one space,
7617eliminate multiple spaces (except at beginning of line), eliminate spaces at
3dcb36b7 7618end of line, do nothing in comments and strings."
5eabfe72
KH
7619 (interactive "r")
7620 (unless no-message (message "Fixing up whitespace..."))
7621 (save-excursion
7622 (goto-char end)
7623 (setq end (point-marker))
5eabfe72
KH
7624 ;; have no space before and one space after `,' and ';'
7625 (goto-char beg)
0a2e512a 7626 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
3dcb36b7
JB
7627 (if (match-string 1)
7628 (goto-char (match-end 1))
7629 (replace-match "\\3 " nil nil nil 3)))
7630 ;; have no space after `('
7631 (goto-char beg)
0a2e512a 7632 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
3dcb36b7
JB
7633 (if (match-string 1)
7634 (goto-char (match-end 1))
7635 (replace-match "\\2")))
7636 ;; have no space before `)'
7637 (goto-char beg)
0a2e512a 7638 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
3dcb36b7
JB
7639 (if (match-string 1)
7640 (goto-char (match-end 1))
7641 (replace-match "\\2")))
7642 ;; surround operator symbols by one space
7643 (goto-char beg)
0a2e512a 7644 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
3dcb36b7
JB
7645 (if (match-string 1)
7646 (goto-char (match-end 1))
0a2e512a
RF
7647 (replace-match "\\3 \\4 \\5")
7648 (goto-char (match-end 2))))
5eabfe72
KH
7649 ;; eliminate multiple spaces and spaces at end of line
7650 (goto-char beg)
7651 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
3dcb36b7 7652 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
5eabfe72
KH
7653 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7654 (progn (replace-match "" nil nil) t))
7655 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7656 (progn (replace-match ";" nil nil) t))
7657 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7658 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
3dcb36b7 7659 (progn (replace-match " " nil nil) t))
5eabfe72 7660 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
3dcb36b7 7661 (progn (replace-match " " nil nil) t))
0a2e512a
RF
7662; (re-search-forward "[^ \t-]+" end t))))
7663 (re-search-forward "[^ \t\"-]+" end t))))
5eabfe72
KH
7664 (unless no-message (message "Fixing up whitespace...done")))
7665
7666(defun vhdl-fixup-whitespace-buffer ()
7667 "Fixup whitespace in buffer. Surround operator symbols by one space,
7668eliminate multiple spaces (except at beginning of line), eliminate spaces at
7669end of line, do nothing in comments."
7670 (interactive)
7671 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7672
3dcb36b7
JB
7673;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7674;; Beautify
7675
5eabfe72
KH
7676(defun vhdl-beautify-region (beg end)
7677 "Beautify region by applying indentation, whitespace fixup, alignment, and
3dcb36b7
JB
7678case fixing to a region. Calls functions `vhdl-indent-buffer',
7679`vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
5eabfe72
KH
7680`vhdl-fix-case-buffer'."
7681 (interactive "r")
3dcb36b7 7682 (setq end (save-excursion (goto-char end) (point-marker)))
5eabfe72
KH
7683 (vhdl-indent-region beg end nil)
7684 (let ((vhdl-align-groups t))
3dcb36b7 7685 (vhdl-align-region beg end))
5eabfe72
KH
7686 (vhdl-fix-case-region beg end))
7687
7688(defun vhdl-beautify-buffer ()
7689 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7690case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7691buffer."
7692 (interactive)
3dcb36b7
JB
7693 (vhdl-beautify-region (point-min) (point-max))
7694 (when noninteractive (save-buffer)))
7695
7696;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7697;; Code filling
7698
7699(defun vhdl-fill-region (beg end &optional arg)
7700 "Fill lines for a region of code."
8d422bd5 7701 (interactive "r\np")
3dcb36b7
JB
7702 (save-excursion
7703 (goto-char beg)
f35aff82 7704 (let ((margin (if arg (current-indentation) (current-column))))
3dcb36b7
JB
7705 (goto-char end)
7706 (setq end (point-marker))
7707 ;; remove inline comments, newlines and whitespace
7708 (vhdl-comment-kill-region beg end)
7709 (vhdl-comment-kill-inline-region beg end)
7710 (subst-char-in-region beg (1- end) ?\n ?\ )
7711 (vhdl-fixup-whitespace-region beg end)
7712 ;; wrap and end-comment-column
7713 (goto-char beg)
7714 (while (re-search-forward "\\s-" end t)
7715 (when(> (current-column) vhdl-end-comment-column)
7716 (backward-char)
7717 (when (re-search-backward "\\s-" beg t)
7718 (replace-match "\n")
7719 (indent-to margin)))))))
7720
7721(defun vhdl-fill-group ()
7722 "Fill group of lines between empty lines."
7723 (interactive)
7724 (vhdl-do-group 'vhdl-fill-region))
7725
7726(defun vhdl-fill-list ()
7727 "Fill the lines of a list surrounded by a balanced group of parentheses."
7728 (interactive)
7729 (vhdl-do-list 'vhdl-fill-region))
7730
7731(defun vhdl-fill-same-indent ()
7732 "Fill the lines of block of lines with same indent."
7733 (interactive)
7734 (vhdl-do-same-indent 'vhdl-fill-region))
7735
7736
7737;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7738;;; Code updating/fixing
7739;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7740
7741;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7742;; Sensitivity list update
7743
7744;; Strategy:
7745;; - no sensitivity list is generated for processes with wait statements
7746;; - otherwise, do the following:
7747;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7748;; 2. scan for all signals already in the sensitivity list (in order to catch
7749;; manually entered global signals)
7750;; 3. signals from 1. and 2. form the list of visible signals
7751;; 4. search for if/elsif conditions containing an event (sequential code)
7752;; 5. scan for strings that are within syntactical regions where signals are
7753;; read but not within sequential code, and that correspond to visible
7754;; signals
7755;; 6. replace sensitivity list by list of signals from 5.
7756
7757(defun vhdl-update-sensitivity-list-process ()
7758 "Update sensitivity list of current process."
7759 (interactive)
7760 (save-excursion
7761 (vhdl-prepare-search-2
7762 (end-of-line)
7763 ;; look whether in process
7764 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7765 (equal (upcase (match-string 2)) "PROCESS")
7766 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7767 (error "ERROR: Not within a process")
7768 (message "Updating sensitivity list...")
7769 (vhdl-update-sensitivity-list)
7770 (message "Updating sensitivity list...done")))))
7771
7772(defun vhdl-update-sensitivity-list-buffer ()
7773 "Update sensitivity list of all processes in current buffer."
7774 (interactive)
7775 (save-excursion
7776 (vhdl-prepare-search-2
7777 (goto-char (point-min))
7778 (message "Updating sensitivity lists...")
7779 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7780 (goto-char (match-beginning 0))
0a2e512a 7781 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
3dcb36b7
JB
7782 (message "Updating sensitivity lists...done"))))
7783
7784(defun vhdl-update-sensitivity-list ()
7785 "Update sensitivity list."
7786 (let ((proc-beg (point))
7787 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7788 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7789 seq-region-list)
7790 (cond
7791 ;; search for wait statement (no sensitivity list allowed)
7792 ((progn (goto-char proc-mid)
7793 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7794 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7795 ;; combinational process (update sensitivity list)
7796 (t
7797 (let
7798 ;; scan for visible signals
7799 ((visible-list (vhdl-get-visible-signals))
7800 ;; define syntactic regions where signals are read
7801 (scan-regions-list
7802 '(;; right-hand side of signal/variable assignment
7803 ;; (special case: "<=" is relational operator in a condition)
7804 ((re-search-forward "[<:]=" proc-end t)
7805 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7806 ;; if condition
7807 ((re-search-forward "^\\s-*if\\>" proc-end t)
7808 (re-search-forward "\\<then\\>" proc-end t))
7809 ;; elsif condition
7810 ((re-search-forward "\\<elsif\\>" proc-end t)
7811 (re-search-forward "\\<then\\>" proc-end t))
7812 ;; while loop condition
7813 ((re-search-forward "^\\s-*while\\>" proc-end t)
7814 (re-search-forward "\\<loop\\>" proc-end t))
7815 ;; exit/next condition
7816 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7817 (re-search-forward ";" proc-end t))
7818 ;; assert condition
7819 ((re-search-forward "\\<assert\\>" proc-end t)
7820 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7821 ;; case expression
7822 ((re-search-forward "^\\s-*case\\>" proc-end t)
7823 (re-search-forward "\\<is\\>" proc-end t))
7824 ;; parameter list of procedure call
0a2e512a
RF
7825 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7826 (1- (point)))
7827 (progn (backward-char) (forward-sexp)
7828 (while (looking-at "(") (forward-sexp)) (point)))))
3dcb36b7
JB
7829 name read-list sens-list signal-list
7830 sens-beg sens-end beg end margin)
7831 ;; scan for signals in old sensitivity list
7832 (goto-char proc-beg)
7833 (re-search-forward "\\<process\\>" proc-mid t)
7834 (if (not (looking-at "[ \t\n]*("))
7835 (setq sens-beg (point))
7836 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7837 (goto-char (match-end 1))
7838 (forward-sexp)
7839 (setq sens-end (1- (point)))
7840 (goto-char sens-beg)
7841 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7842 (setq sens-list
7843 (cons (downcase (match-string 0)) sens-list))
7844 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7845 (setq signal-list (append visible-list sens-list))
7846 ;; search for sequential parts
7847 (goto-char proc-mid)
7848 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7849 (setq end (re-search-forward "\\<then\\>" proc-end t))
7850 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7851 (goto-char end)
7852 (backward-word 1)
7853 (vhdl-forward-sexp)
7854 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7855 (beginning-of-line)))
7856 ;; scan for signals read in process
7857 (while scan-regions-list
7858 (goto-char proc-mid)
7859 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7860 (setq end (eval (nth 1 (car scan-regions-list)))))
7861 (goto-char beg)
7862 (unless (or (vhdl-in-literal)
7863 (and seq-region-list
7864 (let ((tmp-list seq-region-list))
7865 (while (and tmp-list
7866 (< (point) (caar tmp-list)))
7867 (setq tmp-list (cdr tmp-list)))
7868 (and tmp-list (< (point) (cdar tmp-list))))))
0a2e512a 7869 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
3dcb36b7 7870 (setq name (match-string 1))
0a2e512a
RF
7871 (when (and (not (match-string 4)) ; not when formal parameter
7872 (not (and (match-string 3) ; not event attribute
7873 (not (member (downcase (match-string 3))
7874 '("event" "last_event" "transaction")))))
7875 (member (downcase name) signal-list))
7876 (unless (member-ignore-case name read-list)
7877 (setq read-list (cons name read-list))))
7878 (goto-char (match-end 1)))))
3dcb36b7
JB
7879 (setq scan-regions-list (cdr scan-regions-list)))
7880 ;; update sensitivity list
7881 (goto-char sens-beg)
7882 (if sens-end
7883 (delete-region sens-beg sens-end)
7884 (when read-list
7885 (insert " ()") (backward-char)))
7886 (setq read-list (sort read-list 'string<))
7887 (when read-list
7888 (setq margin (current-column))
7889 (insert (car read-list))
7890 (setq read-list (cdr read-list))
7891 (while read-list
7892 (insert ",")
7893 (if (<= (+ (current-column) (length (car read-list)) 2)
7894 end-comment-column)
7895 (insert " ")
7896 (insert "\n") (indent-to margin))
7897 (insert (car read-list))
7898 (setq read-list (cdr read-list)))))))))
7899
7900(defun vhdl-get-visible-signals ()
7901 "Get all signals visible in the current block."
0a2e512a
RF
7902 (let (beg end signal-list entity-name file-name)
7903 (vhdl-prepare-search-2
7904 ;; get entity name
7905 (save-excursion
7906 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
3dcb36b7 7907 (not (equal "END" (upcase (match-string 1))))
0a2e512a
RF
7908 (setq entity-name (match-string 2)))
7909 (error "ERROR: Not within an architecture")))
7910 ;; search for signals declared in entity port clause
7911 (save-excursion
7912 (goto-char (point-min))
7913 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7914 (setq file-name
7915 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7916 "." (file-name-extension (buffer-file-name)))))
7917 (vhdl-visit-file
7918 file-name t
7919 (vhdl-prepare-search-2
7920 (goto-char (point-min))
7921 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7922 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7923 (when (setq beg (re-search-forward
7924 "^\\s-*port[ \t\n]*("
7925 (save-excursion
7926 (re-search-forward "^end\\>" nil t)) t))
7927 (setq end (save-excursion
7928 (backward-char) (forward-sexp) (point)))
7929 (vhdl-forward-syntactic-ws)
7930 (while (< (point) end)
7931 (when (looking-at "signal[ \t\n]+")
7932 (goto-char (match-end 0)))
7933 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7934 (setq signal-list
7935 (cons (downcase (match-string 1)) signal-list))
7936 (goto-char (match-end 0))
7937 (vhdl-forward-syntactic-ws))
7938 (re-search-forward ";" end 1)
7939 (vhdl-forward-syntactic-ws)))))))
7940 ;; search for signals declared in architecture declarative part
7941 (save-excursion
7942 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7943 (not (equal "END" (upcase (match-string 1))))
7944 (setq end (re-search-forward "^begin\\>" nil t))))
7945 (error "ERROR: No architecture declarative part found")
7946 ;; scan for all declared signal and alias names
7947 (goto-char beg)
7948 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7949 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7950 (if (match-string 2)
7951 ;; scan signal name
7952 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7953 (setq signal-list
7954 (cons (downcase (match-string 1)) signal-list))
7955 (goto-char (match-end 0)))
7956 ;; scan alias name, check is alias of (declared) signal
7957 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7958 (member (downcase (match-string 2)) signal-list))
7959 (setq signal-list
7960 (cons (downcase (match-string 1)) signal-list))
7961 (goto-char (match-end 0))))
7962 (setq beg (point))))))
7963 ;; search for signals declared in surrounding block declarative parts
7964 (save-excursion
7965 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7966 (match-string 2))
7967 (goto-char (match-end 2))
7968 (vhdl-backward-sexp)
7969 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7970 beg)
7971 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7972 ;; scan for all declared signal names
7973 (goto-char beg)
7974 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7975 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7976 (if (match-string 2)
7977 ;; scan signal name
7978 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7979 (setq signal-list
7980 (cons (downcase (match-string 1)) signal-list))
7981 (goto-char (match-end 0)))
7982 ;; scan alias name, check is alias of (declared) signal
7983 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7984 (member (downcase (match-string 2)) signal-list))
7985 (setq signal-list
7986 (cons (downcase (match-string 1)) signal-list))
7987 (goto-char (match-end 0))))))
7988 (goto-char beg)))
7989 signal-list)))
3dcb36b7
JB
7990
7991;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7992;; Generic/port clause fixing
7993
7994(defun vhdl-fix-clause ()
7995 "Fix closing parenthesis within generic/port clause."
7996 (interactive)
7997 (save-excursion
7998 (vhdl-prepare-search-2
7999 (let ((pos (point))
8000 beg end)
8001 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
8002 (error "ERROR: Not within a generic/port clause")
8003 ;; search for end of clause
8004 (goto-char (match-end 0))
8005 (setq beg (1- (point)))
8006 (vhdl-forward-syntactic-ws)
8007 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
8008 (goto-char (1- (match-end 0)))
8009 (setq end (point-marker))
8010 (forward-char)
8011 (vhdl-forward-syntactic-ws))
8012 (goto-char end)
8013 (when (> pos (save-excursion (end-of-line) (point)))
8014 (error "ERROR: Not within a generic/port clause"))
8015 ;; delete closing parenthesis on separate line (not supported style)
8016 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8017 (vhdl-line-kill)
8018 (vhdl-backward-syntactic-ws)
8019 (setq end (point-marker))
8020 (insert ";"))
8021 ;; delete superfluous parentheses
8022 (while (progn (goto-char beg)
8023 (condition-case () (forward-sexp)
8024 (error (goto-char (point-max))))
8025 (< (point) end))
8026 (delete-backward-char 1))
8027 ;; add closing parenthesis
8028 (when (> (point) end)
8029 (goto-char end)
8030 (insert ")")))))))
8031
8032;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8033;; Miscellaneous
8034
8035(defun vhdl-remove-trailing-spaces ()
8036 "Remove trailing spaces in the whole buffer."
8037 (interactive)
8038 (save-match-data
8039 (save-excursion
8040 (goto-char (point-min))
8041 (while (re-search-forward "[ \t]+$" (point-max) t)
8042 (unless (vhdl-in-literal)
8043 (replace-match "" nil nil))))))
d2ddb974
KH
8044
8045
5eabfe72
KH
8046;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8047;;; Electrification
8048;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 8049
5eabfe72
KH
8050(defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8051 "Syntax of prompt inserted by template generators.")
8052
8053(defvar vhdl-template-invoked-by-hook nil
8054 "Indicates whether a template has been invoked by a hook or by key or menu.
8055Used for undoing after template abortion.")
8056
8057;; correct different behavior of function `unread-command-events' in XEmacs
3dcb36b7 8058(defun vhdl-character-to-event (arg))
5eabfe72 8059(defalias 'vhdl-character-to-event
4bcb9c95 8060 (if (fboundp 'character-to-event) 'character-to-event 'identity))
3dcb36b7
JB
8061
8062(defun vhdl-work-library ()
8063 "Return the working library name of the current project or \"work\" if no
8064project is defined."
8065 (vhdl-resolve-env-variable
8066 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
5eabfe72
KH
8067
8068;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8069;; Enabling/disabling
8070
8071(defun vhdl-mode-line-update ()
8072 "Update the modeline string for VHDL major mode."
8073 (setq mode-name (concat "VHDL"
8074 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
8075 (and vhdl-electric-mode "e")
8076 (and vhdl-stutter-mode "s")))
3dcb36b7 8077 (force-mode-line-update t))
5eabfe72
KH
8078
8079(defun vhdl-electric-mode (arg)
8080 "Toggle VHDL electric mode.
8081Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8082 (interactive "P")
8083 (setq vhdl-electric-mode
8084 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
8085 ((> arg 0) t) (t nil)))
8086 (vhdl-mode-line-update))
8087
8088(defun vhdl-stutter-mode (arg)
8089 "Toggle VHDL stuttering mode.
8090Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8091 (interactive "P")
8092 (setq vhdl-stutter-mode
8093 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
8094 ((> arg 0) t) (t nil)))
8095 (vhdl-mode-line-update))
8096
8097;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8098;; Stuttering
d2ddb974 8099
5eabfe72
KH
8100(defun vhdl-electric-dash (count)
8101 "-- starts a comment, --- draws a horizontal line,
8102---- starts a display comment"
d2ddb974 8103 (interactive "p")
3dcb36b7 8104 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
5eabfe72
KH
8105 (cond
8106 ((and abbrev-start-location (= abbrev-start-location (point)))
8107 (setq abbrev-start-location nil)
8108 (goto-char last-abbrev-location)
8109 (beginning-of-line nil)
8110 (vhdl-comment-display))
8111 ((/= (preceding-char) ?-) ; standard dash (minus)
d2ddb974 8112 (self-insert-command count))
5eabfe72
KH
8113 (t (self-insert-command count)
8114 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8115 (let ((next-input (read-char)))
8116 (if (= next-input ?-) ; triple dash
8117 (progn
8118 (vhdl-comment-display-line)
8119 (message
8120 "Enter '-' for display comment, else continue coding")
8121 (let ((next-input (read-char)))
8122 (if (= next-input ?-) ; four dashes
8123 (vhdl-comment-display t)
8124 (setq unread-command-events ; pushback the char
8125 (list (vhdl-character-to-event next-input))))))
8126 (setq unread-command-events ; pushback the char
8127 (list (vhdl-character-to-event next-input)))
8128 (vhdl-comment-insert)))))
8129 (self-insert-command count)))
8130
8131(defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
d2ddb974 8132 (interactive "p")
3dcb36b7 8133 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8134 (if (= (preceding-char) ?\()
8135 (progn (delete-char -1) (insert-char ?\[ 1))
8136 (insert-char ?\( 1))
8137 (self-insert-command count)))
d2ddb974 8138
5eabfe72 8139(defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
d2ddb974 8140 (interactive "p")
3dcb36b7 8141 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974 8142 (progn
5eabfe72
KH
8143 (if (= (preceding-char) ?\))
8144 (progn (delete-char -1) (insert-char ?\] 1))
8145 (insert-char ?\) 1))
8146 (blink-matching-open))
8147 (self-insert-command count)))
d2ddb974 8148
5eabfe72 8149(defun vhdl-electric-quote (count) "'' --> \""
d2ddb974 8150 (interactive "p")
3dcb36b7 8151 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8152 (if (= (preceding-char) last-input-char)
8153 (progn (delete-backward-char 1) (insert-char ?\" 1))
8154 (insert-char ?\' 1))
8155 (self-insert-command count)))
d2ddb974 8156
5eabfe72 8157(defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
d2ddb974 8158 (interactive "p")
3dcb36b7 8159 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8160 (cond ((= (preceding-char) last-input-char)
8161 (progn (delete-char -1)
3dcb36b7 8162 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8163 (insert ": ")
8164 (setq this-command 'vhdl-electric-colon)))
8165 ((and
8166 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8167 (progn (delete-char -1) (insert "= ")))
8168 (t (insert-char ?\; 1)))
8169 (self-insert-command count)))
8170
8171(defun vhdl-electric-comma (count) "',,' --> ' <= '"
d2ddb974 8172 (interactive "p")
3dcb36b7 8173 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974
KH
8174 (cond ((= (preceding-char) last-input-char)
8175 (progn (delete-char -1)
3dcb36b7 8176 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8177 (insert "<= ")))
5eabfe72
KH
8178 (t (insert-char ?\, 1)))
8179 (self-insert-command count)))
d2ddb974 8180
5eabfe72 8181(defun vhdl-electric-period (count) "'..' --> ' => '"
d2ddb974 8182 (interactive "p")
3dcb36b7 8183 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974
KH
8184 (cond ((= (preceding-char) last-input-char)
8185 (progn (delete-char -1)
3dcb36b7 8186 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8187 (insert "=> ")))
5eabfe72
KH
8188 (t (insert-char ?\. 1)))
8189 (self-insert-command count)))
d2ddb974 8190
5eabfe72 8191(defun vhdl-electric-equal (count) "'==' --> ' == '"
d2ddb974 8192 (interactive "p")
3dcb36b7 8193 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8194 (cond ((= (preceding-char) last-input-char)
8195 (progn (delete-char -1)
3dcb36b7 8196 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8197 (insert "== ")))
8198 (t (insert-char ?\= 1)))
8199 (self-insert-command count)))
d2ddb974 8200
5eabfe72 8201;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
8202;; VHDL templates
8203
5eabfe72
KH
8204(defun vhdl-template-paired-parens ()
8205 "Insert a pair of round parentheses, placing point between them."
d2ddb974 8206 (interactive)
5eabfe72
KH
8207 (insert "()")
8208 (backward-char))
d2ddb974 8209
5eabfe72
KH
8210(defun vhdl-template-alias ()
8211 "Insert alias declaration."
d2ddb974 8212 (interactive)
5eabfe72
KH
8213 (let ((start (point)))
8214 (vhdl-insert-keyword "ALIAS ")
8215 (when (vhdl-template-field "name" nil t start (point))
8216 (insert " : ")
8217 (unless (vhdl-template-field
8218 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8219 nil t)
3dcb36b7 8220 (delete-backward-char 3))
5eabfe72
KH
8221 (vhdl-insert-keyword " IS ")
8222 (vhdl-template-field "name" ";")
8223 (vhdl-comment-insert-inline))))
8224
8225(defun vhdl-template-architecture ()
8226 "Insert architecture."
8227 (interactive)
8228 (let ((margin (current-indentation))
8229 (start (point))
3dcb36b7 8230 arch-name)
d2ddb974 8231 (vhdl-insert-keyword "ARCHITECTURE ")
5eabfe72
KH
8232 (when (setq arch-name
8233 (vhdl-template-field "name" nil t start (point)))
d2ddb974 8234 (vhdl-insert-keyword " OF ")
3dcb36b7
JB
8235 (if (save-excursion
8236 (vhdl-prepare-search-1
8237 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8238 (insert (match-string 1))
5eabfe72 8239 (vhdl-template-field "entity name"))
3dcb36b7 8240 (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8241 (vhdl-template-begin-end
8242 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8243 (memq vhdl-insert-empty-lines '(unit all))))))
d2ddb974 8244
5eabfe72 8245(defun vhdl-template-array (kind &optional secondary)
d2ddb974
KH
8246 "Insert array type definition."
8247 (interactive)
5eabfe72
KH
8248 (let ((start (point)))
8249 (vhdl-insert-keyword "ARRAY (")
8250 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8251 secondary)
8252 (vhdl-insert-keyword ") OF ")
8253 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8254 (vhdl-insert-keyword ";"))))
8255
8256(defun vhdl-template-assert ()
8257 "Insert an assertion statement."
8258 (interactive)
8259 (let ((start (point)))
8260 (vhdl-insert-keyword "ASSERT ")
8261 (when vhdl-conditions-in-parenthesis (insert "("))
8262 (when (vhdl-template-field "condition (negated)" nil t start (point))
8263 (when vhdl-conditions-in-parenthesis (insert ")"))
8264 (setq start (point))
8265 (vhdl-insert-keyword " REPORT ")
8266 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8267 (delete-region start (point)))
8268 (setq start (point))
8269 (vhdl-insert-keyword " SEVERITY ")
8270 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8271 (delete-region start (point)))
8272 (insert ";"))))
8273
8274(defun vhdl-template-attribute ()
8275 "Insert an attribute declaration or specification."
8276 (interactive)
8277 (if (eq (vhdl-decision-query
8278 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8279 (vhdl-template-attribute-spec)
8280 (vhdl-template-attribute-decl)))
d2ddb974 8281
5eabfe72
KH
8282(defun vhdl-template-attribute-decl ()
8283 "Insert an attribute declaration."
d2ddb974 8284 (interactive)
5eabfe72
KH
8285 (let ((start (point)))
8286 (vhdl-insert-keyword "ATTRIBUTE ")
8287 (when (vhdl-template-field "name" " : " t start (point))
8288 (vhdl-template-field "type" ";")
8289 (vhdl-comment-insert-inline))))
8290
8291(defun vhdl-template-attribute-spec ()
8292 "Insert an attribute specification."
8293 (interactive)
8294 (let ((start (point)))
8295 (vhdl-insert-keyword "ATTRIBUTE ")
8296 (when (vhdl-template-field "name" nil t start (point))
8297 (vhdl-insert-keyword " OF ")
8298 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8299 (vhdl-template-field "entity class")
8300 (vhdl-insert-keyword " IS ")
8301 (vhdl-template-field "expression" ";"))))
d2ddb974 8302
5eabfe72
KH
8303(defun vhdl-template-block ()
8304 "Insert a block."
d2ddb974 8305 (interactive)
5eabfe72
KH
8306 (let ((margin (current-indentation))
8307 (start (point))
8308 label)
8309 (vhdl-insert-keyword ": BLOCK ")
8310 (goto-char start)
8311 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8312 (forward-word 1)
8313 (forward-char 1)
d2ddb974 8314 (insert "(")
5eabfe72
KH
8315 (if (vhdl-template-field "[guard expression]" nil t)
8316 (insert ")")
8317 (delete-char -2))
8318 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 8319 (insert "\n")
5eabfe72
KH
8320 (vhdl-template-begin-end "BLOCK" label margin)
8321 (vhdl-comment-block))))
d2ddb974 8322
5eabfe72 8323(defun vhdl-template-block-configuration ()
d2ddb974
KH
8324 "Insert a block configuration statement."
8325 (interactive)
5eabfe72
KH
8326 (let ((margin (current-indentation))
8327 (start (point)))
d2ddb974 8328 (vhdl-insert-keyword "FOR ")
5eabfe72 8329 (when (vhdl-template-field "block name" nil t start (point))
d2ddb974
KH
8330 (vhdl-insert-keyword "\n\n")
8331 (indent-to margin)
8332 (vhdl-insert-keyword "END FOR;")
8333 (end-of-line 0)
5eabfe72 8334 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8335
5eabfe72
KH
8336(defun vhdl-template-break ()
8337 "Insert a break statement."
d2ddb974 8338 (interactive)
5eabfe72
KH
8339 (let (position)
8340 (vhdl-insert-keyword "BREAK")
8341 (setq position (point))
8342 (insert " ")
8343 (while (or
8344 (progn (vhdl-insert-keyword "FOR ")
8345 (if (vhdl-template-field "[quantity name]" " USE " t)
8346 (progn (vhdl-template-field "quantity name" " => ") t)
8347 (kill-word -1) nil))
8348 (vhdl-template-field "[quantity name]" " => " t))
8349 (vhdl-template-field "expression")
8350 (setq position (point))
8351 (insert ", "))
8352 (delete-region position (point))
8353 (unless (vhdl-sequential-statement-p)
8354 (vhdl-insert-keyword " ON ")
8355 (if (vhdl-template-field "[sensitivity list]" nil t)
8356 (setq position (point))
8357 (delete-region position (point))))
8358 (vhdl-insert-keyword " WHEN ")
8359 (when vhdl-conditions-in-parenthesis (insert "("))
8360 (if (vhdl-template-field "[condition]" nil t)
8361 (when vhdl-conditions-in-parenthesis (insert ")"))
8362 (delete-region position (point)))
8363 (insert ";")))
8364
8365(defun vhdl-template-case (&optional kind)
8366 "Insert a case statement."
8367 (interactive)
8368 (let ((margin (current-indentation))
8369 (start (point))
8370 label)
8371 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8372 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8373 (vhdl-insert-keyword "CASE ")
8374 (vhdl-insert-keyword ": CASE ")
8375 (goto-char start)
8376 (setq label (vhdl-template-field "[label]" nil t))
8377 (unless label (delete-char 2))
8378 (forward-word 1)
8379 (forward-char 1))
8380 (when (vhdl-template-field "expression" nil t start (point))
8381 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
d2ddb974 8382 (indent-to margin)
5eabfe72
KH
8383 (vhdl-insert-keyword "END CASE")
8384 (when label (insert " " label))
8385 (insert ";")
d2ddb974
KH
8386 (forward-line -1)
8387 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8388 (vhdl-insert-keyword "WHEN ")
8389 (let ((position (point)))
8390 (insert " => ;\n")
8391 (indent-to (+ margin vhdl-basic-offset))
8392 (vhdl-insert-keyword "WHEN OTHERS => null;")
8393 (goto-char position)))))
d2ddb974 8394
5eabfe72
KH
8395(defun vhdl-template-case-is ()
8396 "Insert a sequential case statement."
d2ddb974 8397 (interactive)
5eabfe72
KH
8398 (vhdl-template-case 'is))
8399
8400(defun vhdl-template-case-use ()
8401 "Insert a simultaneous case statement."
8402 (interactive)
8403 (vhdl-template-case 'use))
8404
8405(defun vhdl-template-component ()
8406 "Insert a component declaration."
8407 (interactive)
8408 (vhdl-template-component-decl))
8409
8410(defun vhdl-template-component-conf ()
8411 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8412since these are almost equivalent)."
8413 (interactive)
8414 (let ((margin (current-indentation))
8415 (result (vhdl-template-configuration-spec t)))
8416 (when result
8417 (insert "\n")
8418 (indent-to margin)
8419 (vhdl-insert-keyword "END FOR;")
8420 (when (eq result 'no-use)
8421 (end-of-line -0)))))
8422
8423(defun vhdl-template-component-decl ()
8424 "Insert a component declaration."
8425 (interactive)
8426 (let ((margin (current-indentation))
8427 (start (point))
8428 name end-column)
d2ddb974 8429 (vhdl-insert-keyword "COMPONENT ")
5eabfe72 8430 (when (setq name (vhdl-template-field "name" nil t start (point)))
3dcb36b7 8431 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
d2ddb974
KH
8432 (insert "\n\n")
8433 (indent-to margin)
5eabfe72
KH
8434 (vhdl-insert-keyword "END COMPONENT")
8435 (unless (vhdl-standard-p '87) (insert " " name))
8436 (insert ";")
8437 (setq end-column (current-column))
d2ddb974
KH
8438 (end-of-line -0)
8439 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 8440 (vhdl-template-generic-list t t)
d2ddb974
KH
8441 (insert "\n")
8442 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8443 (vhdl-template-port-list t)
8444 (beginning-of-line 2)
8445 (forward-char end-column))))
d2ddb974 8446
5eabfe72
KH
8447(defun vhdl-template-component-inst ()
8448 "Insert a component instantiation statement."
d2ddb974 8449 (interactive)
5eabfe72
KH
8450 (let ((margin (current-indentation))
8451 (start (point))
8452 unit position)
8453 (when (vhdl-template-field "instance label" nil t start (point))
8454 (insert ": ")
3dcb36b7 8455 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
8456 (vhdl-template-field "component name")
8457 ;; direct instantiation
8458 (setq unit (vhdl-template-field
8459 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8460 (setq unit (upcase (or unit "")))
8461 (cond ((equal unit "ENTITY")
3dcb36b7
JB
8462 (vhdl-template-field "library name" "." nil nil nil nil
8463 (vhdl-work-library))
5eabfe72
KH
8464 (vhdl-template-field "entity name" "(")
8465 (if (vhdl-template-field "[architecture name]" nil t)
8466 (insert ")")
8467 (delete-char -1)))
8468 ((equal unit "CONFIGURATION")
3dcb36b7
JB
8469 (vhdl-template-field "library name" "." nil nil nil nil
8470 (vhdl-work-library))
5eabfe72
KH
8471 (vhdl-template-field "configuration name"))
8472 (t (vhdl-template-field "component name"))))
8473 (insert "\n")
d2ddb974 8474 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8475 (setq position (point))
8476 (vhdl-insert-keyword "GENERIC ")
8477 (when (vhdl-template-map position t t)
8478 (insert "\n")
8479 (indent-to (+ margin vhdl-basic-offset)))
8480 (setq position (point))
8481 (vhdl-insert-keyword "PORT ")
8482 (unless (vhdl-template-map position t t)
8483 (kill-line -0)
8484 (delete-char -1))
8485 (insert ";"))))
d2ddb974 8486
5eabfe72
KH
8487(defun vhdl-template-conditional-signal-asst ()
8488 "Insert a conditional signal assignment."
d2ddb974 8489 (interactive)
5eabfe72 8490 (when (vhdl-template-field "target signal")
d2ddb974 8491 (insert " <= ")
5eabfe72
KH
8492; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8493; (insert " "))
d2ddb974 8494 (let ((margin (current-column))
5eabfe72
KH
8495 (start (point))
8496 position)
8497 (vhdl-template-field "waveform")
8498 (setq position (point))
d2ddb974 8499 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8500 (when vhdl-conditions-in-parenthesis (insert "("))
8501 (while (and (vhdl-template-field "[condition]" nil t)
8502 (progn
8503 (when vhdl-conditions-in-parenthesis (insert ")"))
8504 (setq position (point))
8505 (vhdl-insert-keyword " ELSE")
8506 (insert "\n")
8507 (indent-to margin)
8508 (vhdl-template-field "[waveform]" nil t)))
8509 (setq position (point))
d2ddb974 8510 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8511 (when vhdl-conditions-in-parenthesis (insert "(")))
8512 (delete-region position (point))
d2ddb974 8513 (insert ";")
3dcb36b7 8514 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 8515
5eabfe72
KH
8516(defun vhdl-template-configuration ()
8517 "Insert a configuration specification if within an architecture,
d2ddb974
KH
8518a block or component configuration if within a configuration declaration,
8519a configuration declaration if not within a design unit."
8520 (interactive)
3dcb36b7
JB
8521 (vhdl-prepare-search-1
8522 (cond
8523 ((and (save-excursion ; architecture body
8524 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8525 (equal "ARCHITECTURE" (upcase (match-string 1))))
8526 (vhdl-template-configuration-spec))
8527 ((and (save-excursion ; configuration declaration
8528 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8529 (equal "CONFIGURATION" (upcase (match-string 1))))
8530 (if (eq (vhdl-decision-query
8531 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8532 (vhdl-template-component-conf)
8533 (vhdl-template-block-configuration)))
8534 (t (vhdl-template-configuration-decl))))) ; otherwise
5eabfe72
KH
8535
8536(defun vhdl-template-configuration-spec (&optional optional-use)
8537 "Insert a configuration specification."
d2ddb974 8538 (interactive)
5eabfe72
KH
8539 (let ((margin (current-indentation))
8540 (start (point))
8541 aspect position)
d2ddb974 8542 (vhdl-insert-keyword "FOR ")
3dcb36b7 8543 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
5eabfe72 8544 t start (point))
3dcb36b7 8545 (vhdl-template-field "component name" "\n")
d2ddb974 8546 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8547 (setq start (point))
8548 (vhdl-insert-keyword "USE ")
8549 (if (and optional-use
8550 (not (setq aspect (vhdl-template-field
8551 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8552 (progn (delete-region start (point)) 'no-use)
8553 (unless optional-use
8554 (setq aspect (vhdl-template-field
8555 "ENTITY | CONFIGURATION | OPEN" " ")))
8556 (setq aspect (upcase (or aspect "")))
8557 (cond ((equal aspect "ENTITY")
3dcb36b7
JB
8558 (vhdl-template-field "library name" "." nil nil nil nil
8559 (vhdl-work-library))
5eabfe72
KH
8560 (vhdl-template-field "entity name" "(")
8561 (if (vhdl-template-field "[architecture name]" nil t)
8562 (insert ")")
d2ddb974 8563 (delete-char -1))
5eabfe72
KH
8564 (insert "\n")
8565 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8566 (setq position (point))
8567 (vhdl-insert-keyword "GENERIC ")
8568 (when (vhdl-template-map position t t)
8569 (insert "\n")
8570 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8571 (setq position (point))
8572 (vhdl-insert-keyword "PORT ")
8573 (unless (vhdl-template-map position t t)
8574 (kill-line -0)
8575 (delete-char -1))
8576 (insert ";")
8577 t)
8578 ((equal aspect "CONFIGURATION")
3dcb36b7
JB
8579 (vhdl-template-field "library name" "." nil nil nil nil
8580 (vhdl-work-library))
5eabfe72 8581 (vhdl-template-field "configuration name" ";"))
3dcb36b7 8582 (t (delete-backward-char 1) (insert ";") t))))))
5eabfe72 8583
d2ddb974 8584
5eabfe72
KH
8585(defun vhdl-template-configuration-decl ()
8586 "Insert a configuration declaration."
d2ddb974 8587 (interactive)
5eabfe72
KH
8588 (let ((margin (current-indentation))
8589 (start (point))
5eabfe72 8590 entity-exists string name position)
d2ddb974 8591 (vhdl-insert-keyword "CONFIGURATION ")
5eabfe72 8592 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974 8593 (vhdl-insert-keyword " OF ")
5eabfe72 8594 (save-excursion
3dcb36b7
JB
8595 (vhdl-prepare-search-1
8596 (setq entity-exists (vhdl-re-search-backward
5eabfe72
KH
8597 "\\<entity \\(\\w*\\) is\\>" nil t))
8598 (setq string (match-string 1))))
d2ddb974 8599 (if (and entity-exists (not (equal string "")))
5eabfe72
KH
8600 (insert string)
8601 (vhdl-template-field "entity name"))
8602 (vhdl-insert-keyword " IS\n")
8603 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8604 (indent-to (+ margin vhdl-basic-offset))
8605 (setq position (point))
8606 (insert "\n")
8607 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
d2ddb974
KH
8608 (indent-to margin)
8609 (vhdl-insert-keyword "END ")
5eabfe72
KH
8610 (unless (vhdl-standard-p '87)
8611 (vhdl-insert-keyword "CONFIGURATION "))
d2ddb974 8612 (insert name ";")
5eabfe72 8613 (goto-char position))))
d2ddb974 8614
5eabfe72
KH
8615(defun vhdl-template-constant ()
8616 "Insert a constant declaration."
8617 (interactive)
8618 (let ((start (point))
8619 (in-arglist (vhdl-in-argument-list-p)))
8620 (vhdl-insert-keyword "CONSTANT ")
8621 (when (vhdl-template-field "name" nil t start (point))
d2ddb974 8622 (insert " : ")
5eabfe72
KH
8623 (when in-arglist (vhdl-insert-keyword "IN "))
8624 (vhdl-template-field "type")
d2ddb974 8625 (if in-arglist
5eabfe72
KH
8626 (progn (insert ";")
8627 (vhdl-comment-insert-inline))
d2ddb974
KH
8628 (let ((position (point)))
8629 (insert " := ")
5eabfe72
KH
8630 (unless (vhdl-template-field "[initialization]" nil t)
8631 (delete-region position (point)))
8632 (insert ";")
8633 (vhdl-comment-insert-inline))))))
d2ddb974 8634
5eabfe72 8635(defun vhdl-template-default ()
d2ddb974
KH
8636 "Insert nothing."
8637 (interactive)
8638 (insert " ")
8639 (unexpand-abbrev)
8640 (backward-word 1)
8641 (vhdl-case-word 1)
5eabfe72 8642 (forward-char 1))
d2ddb974 8643
5eabfe72 8644(defun vhdl-template-default-indent ()
d2ddb974
KH
8645 "Insert nothing and indent."
8646 (interactive)
8647 (insert " ")
8648 (unexpand-abbrev)
8649 (backward-word 1)
8650 (vhdl-case-word 1)
8651 (forward-char 1)
3dcb36b7 8652 (indent-according-to-mode))
d2ddb974 8653
5eabfe72 8654(defun vhdl-template-disconnect ()
d2ddb974
KH
8655 "Insert a disconnect statement."
8656 (interactive)
5eabfe72
KH
8657 (let ((start (point)))
8658 (vhdl-insert-keyword "DISCONNECT ")
8659 (when (vhdl-template-field "signal names | OTHERS | ALL"
8660 " : " t start (point))
8661 (vhdl-template-field "type")
8662 (vhdl-insert-keyword " AFTER ")
8663 (vhdl-template-field "time expression" ";"))))
8664
8665(defun vhdl-template-else ()
d2ddb974
KH
8666 "Insert an else statement."
8667 (interactive)
3dcb36b7
JB
8668 (let (margin)
8669 (vhdl-prepare-search-1
5eabfe72 8670 (vhdl-insert-keyword "ELSE")
3dcb36b7
JB
8671 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8672 (equal "WHEN" (upcase (match-string 1))))
5eabfe72 8673 (insert " ")
3dcb36b7 8674 (indent-according-to-mode)
5eabfe72
KH
8675 (setq margin (current-indentation))
8676 (insert "\n")
8677 (indent-to (+ margin vhdl-basic-offset))))))
8678
8679(defun vhdl-template-elsif ()
d2ddb974
KH
8680 "Insert an elsif statement."
8681 (interactive)
5eabfe72
KH
8682 (let ((start (point))
8683 margin)
d2ddb974 8684 (vhdl-insert-keyword "ELSIF ")
3dcb36b7
JB
8685 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8686 (when vhdl-conditions-in-parenthesis (insert "("))
8687 (when (vhdl-template-field "condition" nil t start (point))
8688 (when vhdl-conditions-in-parenthesis (insert ")"))
8689 (indent-according-to-mode)
8690 (setq margin (current-indentation))
8691 (vhdl-insert-keyword
8692 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8693 (indent-to (+ margin vhdl-basic-offset))))))
d2ddb974 8694
5eabfe72
KH
8695(defun vhdl-template-entity ()
8696 "Insert an entity."
d2ddb974 8697 (interactive)
5eabfe72
KH
8698 (let ((margin (current-indentation))
8699 (start (point))
8700 name end-column)
d2ddb974 8701 (vhdl-insert-keyword "ENTITY ")
5eabfe72 8702 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974
KH
8703 (vhdl-insert-keyword " IS\n\n")
8704 (indent-to margin)
8705 (vhdl-insert-keyword "END ")
5eabfe72
KH
8706 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8707 (insert name ";")
8708 (setq end-column (current-column))
d2ddb974
KH
8709 (end-of-line -0)
8710 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8711 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8712 (indent-to (+ margin vhdl-basic-offset))
8713 (when (vhdl-template-generic-list t)
8714 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8715 (insert "\n")
8716 (indent-to (+ margin vhdl-basic-offset))
8717 (when (vhdl-template-port-list t)
8718 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8719 (beginning-of-line 2)
8720 (forward-char end-column))))
d2ddb974 8721
5eabfe72 8722(defun vhdl-template-exit ()
d2ddb974
KH
8723 "Insert an exit statement."
8724 (interactive)
5eabfe72
KH
8725 (let ((start (point)))
8726 (vhdl-insert-keyword "EXIT ")
3dcb36b7
JB
8727 (if (vhdl-template-field "[loop label]" nil t start (point))
8728 (let ((position (point)))
8729 (vhdl-insert-keyword " WHEN ")
8730 (when vhdl-conditions-in-parenthesis (insert "("))
8731 (if (vhdl-template-field "[condition]" nil t)
8732 (when vhdl-conditions-in-parenthesis (insert ")"))
8733 (delete-region position (point))))
d2ddb974 8734 (delete-char -1))
5eabfe72
KH
8735 (insert ";")))
8736
8737(defun vhdl-template-file ()
8738 "Insert a file declaration."
8739 (interactive)
8740 (let ((start (point)))
8741 (vhdl-insert-keyword "FILE ")
8742 (when (vhdl-template-field "name" nil t start (point))
8743 (insert " : ")
8744 (vhdl-template-field "type")
8745 (unless (vhdl-standard-p '87)
8746 (vhdl-insert-keyword " OPEN ")
8747 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8748 nil t)
3dcb36b7 8749 (delete-backward-char 6)))
5eabfe72
KH
8750 (vhdl-insert-keyword " IS ")
8751 (when (vhdl-standard-p '87)
8752 (vhdl-template-field "[IN | OUT]" " " t))
8753 (vhdl-template-field "filename-string" nil nil nil nil t)
8754 (insert ";")
8755 (vhdl-comment-insert-inline))))
d2ddb974 8756
5eabfe72
KH
8757(defun vhdl-template-for ()
8758 "Insert a block or component configuration if within a configuration
8759declaration, a configuration specification if within an architecture
3dcb36b7
JB
8760declarative part (and not within a subprogram), a for-loop if within a
8761sequential statement part (subprogram or process), and a for-generate
8762otherwise."
5eabfe72 8763 (interactive)
3dcb36b7
JB
8764 (vhdl-prepare-search-1
8765 (cond
8766 ((vhdl-sequential-statement-p) ; sequential statement
8767 (vhdl-template-for-loop))
8768 ((and (save-excursion ; configuration declaration
8769 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8770 (equal "CONFIGURATION" (upcase (match-string 1))))
8771 (if (eq (vhdl-decision-query
8772 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8773 (vhdl-template-component-conf)
8774 (vhdl-template-block-configuration)))
8775 ((and (save-excursion
8776 (re-search-backward ; architecture declarative part
8777 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8778 (equal "ARCHITECTURE" (upcase (match-string 1))))
8779 (vhdl-template-configuration-spec))
8780 (t (vhdl-template-for-generate))))) ; concurrent statement
5eabfe72
KH
8781
8782(defun vhdl-template-for-generate ()
8783 "Insert a for-generate."
d2ddb974 8784 (interactive)
5eabfe72
KH
8785 (let ((margin (current-indentation))
8786 (start (point))
3dcb36b7 8787 label position)
5eabfe72
KH
8788 (vhdl-insert-keyword ": FOR ")
8789 (setq position (point-marker))
8790 (goto-char start)
8791 (when (setq label (vhdl-template-field "label" nil t start position))
8792 (goto-char position)
8793 (vhdl-template-field "loop variable")
8794 (vhdl-insert-keyword " IN ")
8795 (vhdl-template-field "range")
8796 (vhdl-template-generate-body margin label))))
d2ddb974 8797
5eabfe72
KH
8798(defun vhdl-template-for-loop ()
8799 "Insert a for loop."
d2ddb974 8800 (interactive)
5eabfe72
KH
8801 (let ((margin (current-indentation))
8802 (start (point))
8803 label index)
8804 (if (not (eq vhdl-optional-labels 'all))
8805 (vhdl-insert-keyword "FOR ")
8806 (vhdl-insert-keyword ": FOR ")
8807 (goto-char start)
8808 (setq label (vhdl-template-field "[label]" nil t))
8809 (unless label (delete-char 2))
8810 (forward-word 1)
8811 (forward-char 1))
8812 (when (setq index (vhdl-template-field "loop variable"
8813 nil t start (point)))
d2ddb974 8814 (vhdl-insert-keyword " IN ")
5eabfe72 8815 (vhdl-template-field "range")
d2ddb974
KH
8816 (vhdl-insert-keyword " LOOP\n\n")
8817 (indent-to margin)
8818 (vhdl-insert-keyword "END LOOP")
5eabfe72
KH
8819 (if label
8820 (insert " " label ";")
d2ddb974 8821 (insert ";")
5eabfe72 8822 (when vhdl-self-insert-comments (insert " -- " index)))
d2ddb974 8823 (forward-line -1)
5eabfe72 8824 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8825
5eabfe72
KH
8826(defun vhdl-template-function (&optional kind)
8827 "Insert a function declaration or body."
d2ddb974 8828 (interactive)
5eabfe72
KH
8829 (let ((margin (current-indentation))
8830 (start (point))
8831 name)
8832 (vhdl-insert-keyword "FUNCTION ")
8833 (when (setq name (vhdl-template-field "name" nil t start (point)))
8834 (vhdl-template-argument-list t)
3dcb36b7 8835 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
d2ddb974 8836 (end-of-line)
5eabfe72 8837 (insert "\n")
d2ddb974 8838 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8839 (vhdl-insert-keyword "RETURN ")
8840 (vhdl-template-field "type")
8841 (if (if kind (eq kind 'body)
8842 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
3dcb36b7 8843 (progn (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8844 (vhdl-template-begin-end
8845 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8846 (vhdl-comment-block))
8847 (insert ";")))))
8848
8849(defun vhdl-template-function-decl ()
8850 "Insert a function declaration."
8851 (interactive)
8852 (vhdl-template-function 'decl))
d2ddb974 8853
5eabfe72
KH
8854(defun vhdl-template-function-body ()
8855 "Insert a function declaration."
d2ddb974 8856 (interactive)
5eabfe72
KH
8857 (vhdl-template-function 'body))
8858
8859(defun vhdl-template-generate ()
8860 "Insert a generation scheme."
8861 (interactive)
8862 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8863 (vhdl-template-if-generate)
8864 (vhdl-template-for-generate)))
d2ddb974 8865
5eabfe72
KH
8866(defun vhdl-template-generic ()
8867 "Insert generic declaration, or generic map in instantiation statements."
8868 (interactive)
3dcb36b7
JB
8869 (let ((start (point)))
8870 (vhdl-prepare-search-1
5eabfe72
KH
8871 (cond
8872 ((and (save-excursion ; entity declaration
8873 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8874 (equal "ENTITY" (upcase (match-string 1))))
8875 (vhdl-template-generic-list nil))
8876 ((or (save-excursion
8877 (or (beginning-of-line)
8878 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 8879 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
8880 (vhdl-insert-keyword "GENERIC ")
8881 (vhdl-template-map start))
8882 (t (vhdl-template-generic-list nil t))))))
8883
8884(defun vhdl-template-group ()
8885 "Insert group or group template declaration."
8886 (interactive)
8887 (let ((start (point)))
8888 (if (eq (vhdl-decision-query
8889 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8890 (vhdl-template-group-template)
8891 (vhdl-template-group-decl))))
8892
8893(defun vhdl-template-group-decl ()
8894 "Insert group declaration."
8895 (interactive)
8896 (let ((start (point)))
8897 (vhdl-insert-keyword "GROUP ")
8898 (when (vhdl-template-field "name" " : " t start (point))
8899 (vhdl-template-field "template name" " (")
8900 (vhdl-template-field "constituent list" ");")
8901 (vhdl-comment-insert-inline))))
8902
8903(defun vhdl-template-group-template ()
8904 "Insert group template declaration."
8905 (interactive)
8906 (let ((start (point)))
8907 (vhdl-insert-keyword "GROUP ")
8908 (when (vhdl-template-field "template name" nil t start (point))
8909 (vhdl-insert-keyword " IS (")
8910 (vhdl-template-field "entity class list" ");")
8911 (vhdl-comment-insert-inline))))
8912
5eabfe72
KH
8913(defun vhdl-template-if ()
8914 "Insert a sequential if statement or an if-generate statement."
8915 (interactive)
8916 (if (vhdl-sequential-statement-p)
8917 (vhdl-template-if-then)
8918 (if (and (vhdl-standard-p 'ams)
8919 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8920 (vhdl-template-if-use)
8921 (vhdl-template-if-generate))))
8922
8923(defun vhdl-template-if-generate ()
8924 "Insert an if-generate."
8925 (interactive)
8926 (let ((margin (current-indentation))
8927 (start (point))
3dcb36b7 8928 label position)
5eabfe72
KH
8929 (vhdl-insert-keyword ": IF ")
8930 (setq position (point-marker))
8931 (goto-char start)
8932 (when (setq label (vhdl-template-field "label" nil t start position))
8933 (goto-char position)
8934 (when vhdl-conditions-in-parenthesis (insert "("))
8935 (vhdl-template-field "condition")
8936 (when vhdl-conditions-in-parenthesis (insert ")"))
8937 (vhdl-template-generate-body margin label))))
d2ddb974 8938
5eabfe72
KH
8939(defun vhdl-template-if-then-use (kind)
8940 "Insert a sequential if statement."
8941 (interactive)
8942 (let ((margin (current-indentation))
8943 (start (point))
8944 label)
8945 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8946 (vhdl-insert-keyword "IF ")
8947 (vhdl-insert-keyword ": IF ")
8948 (goto-char start)
8949 (setq label (vhdl-template-field "[label]" nil t))
8950 (unless label (delete-char 2))
8951 (forward-word 1)
8952 (forward-char 1))
8953 (when vhdl-conditions-in-parenthesis (insert "("))
8954 (when (vhdl-template-field "condition" nil t start (point))
8955 (when vhdl-conditions-in-parenthesis (insert ")"))
8956 (vhdl-insert-keyword
8957 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
d2ddb974 8958 (indent-to margin)
5eabfe72
KH
8959 (vhdl-insert-keyword "END IF")
8960 (when label (insert " " label))
8961 (insert ";")
d2ddb974 8962 (forward-line -1)
5eabfe72
KH
8963 (indent-to (+ margin vhdl-basic-offset)))))
8964
8965(defun vhdl-template-if-then ()
8966 "Insert a sequential if statement."
8967 (interactive)
8968 (vhdl-template-if-then-use 'then))
8969
8970(defun vhdl-template-if-use ()
8971 "Insert a simultaneous if statement."
8972 (interactive)
8973 (vhdl-template-if-then-use 'use))
8974
8975(defun vhdl-template-instance ()
8976 "Insert a component instantiation statement."
8977 (interactive)
8978 (vhdl-template-component-inst))
d2ddb974 8979
5eabfe72 8980(defun vhdl-template-library ()
d2ddb974
KH
8981 "Insert a library specification."
8982 (interactive)
5eabfe72
KH
8983 (let ((margin (current-indentation))
8984 (start (point))
8985 name end-pos)
d2ddb974 8986 (vhdl-insert-keyword "LIBRARY ")
5eabfe72
KH
8987 (when (setq name (vhdl-template-field "names" nil t start (point)))
8988 (insert ";")
8989 (unless (string-match "," name)
8990 (setq end-pos (point))
8991 (insert "\n")
8992 (indent-to margin)
8993 (vhdl-insert-keyword "USE ")
8994 (insert name)
8995 (vhdl-insert-keyword "..ALL;")
8996 (backward-char 5)
8997 (if (vhdl-template-field "package name")
8998 (forward-char 5)
8999 (delete-region end-pos (+ (point) 5)))))))
9000
9001(defun vhdl-template-limit ()
9002 "Insert a limit."
d2ddb974 9003 (interactive)
5eabfe72
KH
9004 (let ((start (point)))
9005 (vhdl-insert-keyword "LIMIT ")
9006 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9007 t start (point))
9008 (vhdl-template-field "type")
9009 (vhdl-insert-keyword " WITH ")
9010 (vhdl-template-field "real expression" ";"))))
9011
9012(defun vhdl-template-loop ()
9013 "Insert a loop."
9014 (interactive)
9015 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9016 (cond ((eq char ?w)
9017 (vhdl-template-while-loop))
9018 ((eq char ?f)
9019 (vhdl-template-for-loop))
9020 (t (vhdl-template-bare-loop)))))
9021
9022(defun vhdl-template-bare-loop ()
9023 "Insert a loop."
9024 (interactive)
9025 (let ((margin (current-indentation))
9026 (start (point))
9027 label)
9028 (if (not (eq vhdl-optional-labels 'all))
9029 (vhdl-insert-keyword "LOOP ")
9030 (vhdl-insert-keyword ": LOOP ")
9031 (goto-char start)
9032 (setq label (vhdl-template-field "[label]" nil t))
9033 (unless label (delete-char 2))
9034 (forward-word 1)
9035 (delete-char 1))
d2ddb974
KH
9036 (insert "\n\n")
9037 (indent-to margin)
9038 (vhdl-insert-keyword "END LOOP")
5eabfe72 9039 (insert (if label (concat " " label ";") ";"))
d2ddb974 9040 (forward-line -1)
5eabfe72 9041 (indent-to (+ margin vhdl-basic-offset))))
d2ddb974 9042
5eabfe72
KH
9043(defun vhdl-template-map (&optional start optional secondary)
9044 "Insert a map specification with association list."
d2ddb974 9045 (interactive)
5eabfe72
KH
9046 (let ((start (or start (point)))
9047 margin end-pos)
9048 (vhdl-insert-keyword "MAP (")
9049 (if (not vhdl-association-list-with-formals)
9050 (if (vhdl-template-field
9051 (concat (and optional "[") "association list" (and optional "]"))
9052 ")" (or (not secondary) optional)
9053 (and (not secondary) start) (point))
9054 t
9055 (if (and optional secondary) (delete-region start (point)))
9056 nil)
9057 (if vhdl-argument-list-indent
9058 (setq margin (current-column))
9059 (setq margin (+ (current-indentation) vhdl-basic-offset))
9060 (insert "\n")
9061 (indent-to margin))
9062 (if (vhdl-template-field
9063 (concat (and optional "[") "formal" (and optional "]"))
9064 " => " (or (not secondary) optional)
9065 (and (not secondary) start) (point))
9066 (progn
9067 (vhdl-template-field "actual" ",")
9068 (setq end-pos (point))
9069 (insert "\n")
9070 (indent-to margin)
9071 (while (vhdl-template-field "[formal]" " => " t)
9072 (vhdl-template-field "actual" ",")
9073 (setq end-pos (point))
9074 (insert "\n")
9075 (indent-to margin))
9076 (delete-region end-pos (point))
3dcb36b7 9077 (delete-backward-char 1)
5eabfe72 9078 (insert ")")
3dcb36b7 9079 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9080 t)
9081 (when (and optional secondary) (delete-region start (point)))
9082 nil))))
d2ddb974 9083
5eabfe72 9084(defun vhdl-template-modify (&optional noerror)
d2ddb974
KH
9085 "Actualize modification date."
9086 (interactive)
3dcb36b7
JB
9087 (vhdl-prepare-search-2
9088 (save-excursion
9089 (goto-char (point-min))
9090 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9091 (progn (delete-region (point) (progn (end-of-line) (point)))
9092 (vhdl-template-insert-date))
9093 (unless noerror
9094 (error (concat "ERROR: Modification date prefix string \""
9095 vhdl-modify-date-prefix-string "\" not found")))))))
5eabfe72
KH
9096
9097(defun vhdl-template-modify-noerror ()
9098 "Call `vhdl-template-modify' with NOERROR non-nil."
9099 (vhdl-template-modify t))
9100
9101(defun vhdl-template-nature ()
9102 "Insert a nature declaration."
9103 (interactive)
9104 (let ((start (point))
9105 name mid-pos end-pos)
9106 (vhdl-insert-keyword "NATURE ")
9107 (when (setq name (vhdl-template-field "name" nil t start (point)))
9108 (vhdl-insert-keyword " IS ")
9109 (let ((definition
9110 (upcase
9111 (or (vhdl-template-field
9112 "across type | ARRAY | RECORD")
9113 ""))))
9114 (cond ((equal definition "")
9115 (insert ";"))
9116 ((equal definition "ARRAY")
9117 (kill-word -1)
9118 (vhdl-template-array 'nature t))
9119 ((equal definition "RECORD")
9120 (setq mid-pos (point-marker))
9121 (kill-word -1)
9122 (vhdl-template-record 'nature name t))
9123 (t
9124 (vhdl-insert-keyword " ACROSS ")
9125 (vhdl-template-field "through type")
9126 (vhdl-insert-keyword " THROUGH ")
9127 (vhdl-template-field "reference name")
9128 (vhdl-insert-keyword " REFERENCE;")))
9129 (when mid-pos
9130 (setq end-pos (point-marker))
9131 (goto-char mid-pos)
9132 (end-of-line))
9133 (vhdl-comment-insert-inline)
9134 (when end-pos (goto-char end-pos))))))
9135
9136(defun vhdl-template-next ()
9137 "Insert a next statement."
d2ddb974 9138 (interactive)
3dcb36b7
JB
9139 (let ((start (point)))
9140 (vhdl-insert-keyword "NEXT ")
9141 (if (vhdl-template-field "[loop label]" nil t start (point))
9142 (let ((position (point)))
9143 (vhdl-insert-keyword " WHEN ")
9144 (when vhdl-conditions-in-parenthesis (insert "("))
9145 (if (vhdl-template-field "[condition]" nil t)
9146 (when vhdl-conditions-in-parenthesis (insert ")"))
9147 (delete-region position (point))))
9148 (delete-char -1))
5eabfe72
KH
9149 (insert ";")))
9150
9151(defun vhdl-template-others ()
9152 "Insert an others aggregate."
9153 (interactive)
3dcb36b7
JB
9154 (let ((start (point)))
9155 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9156 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9157 (vhdl-insert-keyword "OTHERS => '")
9158 (when (vhdl-template-field "value" nil t start (point))
9159 (insert "')")))
9160 (vhdl-insert-keyword "OTHERS "))))
d2ddb974 9161
5eabfe72 9162(defun vhdl-template-package (&optional kind)
d2ddb974
KH
9163 "Insert a package specification or body."
9164 (interactive)
5eabfe72
KH
9165 (let ((margin (current-indentation))
9166 (start (point))
9167 name body position)
d2ddb974 9168 (vhdl-insert-keyword "PACKAGE ")
5eabfe72
KH
9169 (setq body (if kind (eq kind 'body)
9170 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
3dcb36b7
JB
9171 (when body
9172 (vhdl-insert-keyword "BODY ")
9173 (when (save-excursion
9174 (vhdl-prepare-search-1
9175 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9176 (insert (setq name (match-string 1)))))
9177 (when (or name
9178 (setq name (vhdl-template-field "name" nil t start (point))))
5eabfe72
KH
9179 (vhdl-insert-keyword " IS\n")
9180 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9181 (indent-to (+ margin vhdl-basic-offset))
9182 (setq position (point))
9183 (insert "\n")
9184 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9185 (indent-to margin)
9186 (vhdl-insert-keyword "END ")
9187 (unless (vhdl-standard-p '87)
9188 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9189 (insert (or name "") ";")
9190 (goto-char position))))
d2ddb974 9191
5eabfe72
KH
9192(defun vhdl-template-package-decl ()
9193 "Insert a package specification."
d2ddb974 9194 (interactive)
5eabfe72 9195 (vhdl-template-package 'decl))
d2ddb974 9196
5eabfe72
KH
9197(defun vhdl-template-package-body ()
9198 "Insert a package body."
d2ddb974 9199 (interactive)
5eabfe72 9200 (vhdl-template-package 'body))
d2ddb974 9201
5eabfe72
KH
9202(defun vhdl-template-port ()
9203 "Insert a port declaration, or port map in instantiation statements."
d2ddb974 9204 (interactive)
3dcb36b7
JB
9205 (let ((start (point)))
9206 (vhdl-prepare-search-1
5eabfe72
KH
9207 (cond
9208 ((and (save-excursion ; entity declaration
9209 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9210 (equal "ENTITY" (upcase (match-string 1))))
9211 (vhdl-template-port-list nil))
9212 ((or (save-excursion
9213 (or (beginning-of-line)
9214 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 9215 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
9216 (vhdl-insert-keyword "PORT ")
9217 (vhdl-template-map start))
9218 (t (vhdl-template-port-list nil))))))
9219
9220(defun vhdl-template-procedural ()
9221 "Insert a procedural."
9222 (interactive)
9223 (let ((margin (current-indentation))
9224 (start (point))
9225 (case-fold-search t)
9226 label)
9227 (vhdl-insert-keyword "PROCEDURAL ")
9228 (when (memq vhdl-optional-labels '(process all))
9229 (goto-char start)
9230 (insert ": ")
9231 (goto-char start)
9232 (setq label (vhdl-template-field "[label]" nil t))
9233 (unless label (delete-char 2))
9234 (forward-word 1)
9235 (forward-char 1))
9236 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
3dcb36b7 9237 (insert "\n")
5eabfe72
KH
9238 (vhdl-template-begin-end "PROCEDURAL" label margin)
9239 (vhdl-comment-block)))
9240
9241(defun vhdl-template-procedure (&optional kind)
9242 "Insert a procedure declaration or body."
9243 (interactive)
9244 (let ((margin (current-indentation))
9245 (start (point))
9246 name)
9247 (vhdl-insert-keyword "PROCEDURE ")
9248 (when (setq name (vhdl-template-field "name" nil t start (point)))
9249 (vhdl-template-argument-list)
9250 (if (if kind (eq kind 'body)
9251 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9252 (progn (vhdl-insert-keyword " IS")
9253 (when vhdl-auto-align
3dcb36b7
JB
9254 (vhdl-align-region-groups start (point) 1))
9255 (end-of-line) (insert "\n")
5eabfe72
KH
9256 (vhdl-template-begin-end
9257 (unless (vhdl-standard-p '87) "PROCEDURE")
9258 name margin)
9259 (vhdl-comment-block))
9260 (insert ";")
3dcb36b7 9261 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9262 (end-of-line)))))
9263
9264(defun vhdl-template-procedure-decl ()
9265 "Insert a procedure declaration."
9266 (interactive)
9267 (vhdl-template-procedure 'decl))
d2ddb974 9268
5eabfe72
KH
9269(defun vhdl-template-procedure-body ()
9270 "Insert a procedure body."
9271 (interactive)
9272 (vhdl-template-procedure 'body))
9273
9274(defun vhdl-template-process (&optional kind)
9275 "Insert a process."
9276 (interactive)
9277 (let ((margin (current-indentation))
9278 (start (point))
5eabfe72
KH
9279 label seq input-signals clock reset final-pos)
9280 (setq seq (if kind (eq kind 'seq)
9281 (eq (vhdl-decision-query
9282 "process" "(c)ombinational or (s)equential?" t) ?s)))
9283 (vhdl-insert-keyword "PROCESS ")
9284 (when (memq vhdl-optional-labels '(process all))
9285 (goto-char start)
9286 (insert ": ")
9287 (goto-char start)
9288 (setq label (vhdl-template-field "[label]" nil t))
9289 (unless label (delete-char 2))
9290 (forward-word 1)
9291 (forward-char 1))
9292 (insert "(")
9293 (if (not seq)
9294 (unless (setq input-signals
9295 (vhdl-template-field "[sensitivity list]" ")" t))
9296 (setq input-signals "")
9297 (delete-char -2))
9298 (setq clock (or (and (not (equal "" vhdl-clock-name))
9299 (progn (insert vhdl-clock-name) vhdl-clock-name))
9300 (vhdl-template-field "clock name") "<clock>"))
9301 (when (eq vhdl-reset-kind 'async)
9302 (insert ", ")
9303 (setq reset (or (and (not (equal "" vhdl-reset-name))
9304 (progn (insert vhdl-reset-name) vhdl-reset-name))
9305 (vhdl-template-field "reset name") "<reset>")))
9306 (insert ")"))
9307 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 9308 (insert "\n")
5eabfe72
KH
9309 (vhdl-template-begin-end "PROCESS" label margin)
9310 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9311 (when vhdl-prompt-for-comments
9312 (setq final-pos (point-marker))
3dcb36b7
JB
9313 (vhdl-prepare-search-2
9314 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9315 (vhdl-re-search-backward "\\<process\\>" nil t))
5eabfe72
KH
9316 (end-of-line -0)
9317 (if (bobp)
9318 (progn (insert "\n") (forward-line -1))
9319 (insert "\n"))
9320 (indent-to margin)
9321 (insert "-- purpose: ")
9322 (if (not (vhdl-template-field "[description]" nil t))
9323 (vhdl-line-kill-entire)
9324 (insert "\n")
9325 (indent-to margin)
9326 (insert "-- type : ")
9327 (insert (if seq "sequential" "combinational") "\n")
9328 (indent-to margin)
9329 (insert "-- inputs : ")
9330 (if (not seq)
9331 (insert input-signals)
9332 (insert clock ", ")
9333 (when reset (insert reset ", "))
9334 (unless (vhdl-template-field "[signal names]" nil t)
9335 (delete-char -2)))
9336 (insert "\n")
9337 (indent-to margin)
9338 (insert "-- outputs: ")
9339 (vhdl-template-field "[signal names]" nil t))))
9340 (goto-char final-pos))))
9341
9342(defun vhdl-template-process-comb ()
9343 "Insert a combinational process."
9344 (interactive)
9345 (vhdl-template-process 'comb))
9346
9347(defun vhdl-template-process-seq ()
9348 "Insert a sequential process."
9349 (interactive)
9350 (vhdl-template-process 'seq))
9351
9352(defun vhdl-template-quantity ()
9353 "Insert a quantity declaration."
9354 (interactive)
9355 (if (vhdl-in-argument-list-p)
9356 (let ((start (point)))
9357 (vhdl-insert-keyword "QUANTITY ")
9358 (when (vhdl-template-field "names" nil t start (point))
9359 (insert " : ")
9360 (vhdl-template-field "[IN | OUT]" " " t)
9361 (vhdl-template-field "type")
9362 (insert ";")
9363 (vhdl-comment-insert-inline)))
9364 (let ((char (vhdl-decision-query
9365 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9366 (cond ((eq char ?f) (vhdl-template-quantity-free))
9367 ((eq char ?b) (vhdl-template-quantity-branch))
9368 ((eq char ?s) (vhdl-template-quantity-source))
9369 (t (vhdl-template-undo (point) (point)))))))
9370
9371(defun vhdl-template-quantity-free ()
9372 "Insert a free quantity declaration."
9373 (interactive)
9374 (vhdl-insert-keyword "QUANTITY ")
9375 (vhdl-template-field "names")
9376 (insert " : ")
9377 (vhdl-template-field "type")
9378 (let ((position (point)))
9379 (insert " := ")
9380 (unless (vhdl-template-field "[initialization]" nil t)
9381 (delete-region position (point)))
9382 (insert ";")
9383 (vhdl-comment-insert-inline)))
9384
9385(defun vhdl-template-quantity-branch ()
9386 "Insert a branch quantity declaration."
9387 (interactive)
9388 (let (position)
9389 (vhdl-insert-keyword "QUANTITY ")
9390 (when (vhdl-template-field "[across names]" " " t)
9391 (vhdl-insert-keyword "ACROSS "))
9392 (when (vhdl-template-field "[through names]" " " t)
9393 (vhdl-insert-keyword "THROUGH "))
9394 (vhdl-template-field "plus terminal name")
9395 (setq position (point))
9396 (vhdl-insert-keyword " TO ")
9397 (unless (vhdl-template-field "[minus terminal name]" nil t)
9398 (delete-region position (point)))
9399 (insert ";")
9400 (vhdl-comment-insert-inline)))
9401
9402(defun vhdl-template-quantity-source ()
9403 "Insert a source quantity declaration."
9404 (interactive)
9405 (vhdl-insert-keyword "QUANTITY ")
9406 (vhdl-template-field "names")
9407 (insert " : ")
9408 (vhdl-template-field "type" " ")
9409 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9410 (progn (vhdl-insert-keyword "NOISE ")
9411 (vhdl-template-field "power expression"))
9412 (vhdl-insert-keyword "SPECTRUM ")
9413 (vhdl-template-field "magnitude expression" ", ")
9414 (vhdl-template-field "phase expression"))
9415 (insert ";")
9416 (vhdl-comment-insert-inline))
9417
9418(defun vhdl-template-record (kind &optional name secondary)
d2ddb974
KH
9419 "Insert a record type declaration."
9420 (interactive)
9421 (let ((margin (current-column))
9422 (start (point))
9423 (first t))
9424 (vhdl-insert-keyword "RECORD\n")
9425 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9426 (when (or (vhdl-template-field "element names"
9427 nil (not secondary) start (point))
9428 secondary)
9429 (while (or first (vhdl-template-field "[element names]" nil t))
9430 (insert " : ")
9431 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9432 (vhdl-comment-insert-inline)
9433 (insert "\n")
d2ddb974 9434 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 9435 (setq first nil))
d2ddb974
KH
9436 (kill-line -0)
9437 (indent-to margin)
5eabfe72
KH
9438 (vhdl-insert-keyword "END RECORD")
9439 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9440 (insert ";")
3dcb36b7 9441 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9442
5eabfe72
KH
9443(defun vhdl-template-report ()
9444 "Insert a report statement."
9445 (interactive)
9446 (let ((start (point)))
9447 (vhdl-insert-keyword "REPORT ")
9448 (if (equal "\"\"" (vhdl-template-field
9449 "string expression" nil t start (point) t))
3dcb36b7 9450 (delete-backward-char 2)
5eabfe72
KH
9451 (setq start (point))
9452 (vhdl-insert-keyword " SEVERITY ")
9453 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9454 (delete-region start (point)))
9455 (insert ";"))))
9456
9457(defun vhdl-template-return ()
d2ddb974
KH
9458 "Insert a return statement."
9459 (interactive)
3dcb36b7
JB
9460 (let ((start (point)))
9461 (vhdl-insert-keyword "RETURN ")
9462 (unless (vhdl-template-field "[expression]" nil t start (point))
9463 (delete-char -1))
9464 (insert ";")))
d2ddb974 9465
5eabfe72 9466(defun vhdl-template-selected-signal-asst ()
d2ddb974
KH
9467 "Insert a selected signal assignment."
9468 (interactive)
5eabfe72
KH
9469 (let ((margin (current-indentation))
9470 (start (point))
9471 (choices t))
d2ddb974 9472 (let ((position (point)))
5eabfe72 9473 (vhdl-insert-keyword " SELECT ")
d2ddb974
KH
9474 (goto-char position))
9475 (vhdl-insert-keyword "WITH ")
5eabfe72
KH
9476 (when (vhdl-template-field "selector expression"
9477 nil t start (+ (point) 7))
9478 (forward-word 1)
9479 (delete-char 1)
d2ddb974
KH
9480 (insert "\n")
9481 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9482 (vhdl-template-field "target signal" " <= ")
9483; (vhdl-template-field "[GUARDED] [TRANSPORT]")
d2ddb974
KH
9484 (insert "\n")
9485 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9486 (vhdl-template-field "waveform")
9487 (vhdl-insert-keyword " WHEN ")
9488 (vhdl-template-field "choices" ",")
9489 (insert "\n")
9490 (indent-to (+ margin vhdl-basic-offset))
9491 (while (and choices (vhdl-template-field "[waveform]" nil t))
d2ddb974 9492 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
9493 (if (setq choices (vhdl-template-field "[choices]" "," t))
9494 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9495 (vhdl-insert-keyword "OTHERS")))
9496 (when choices
d2ddb974
KH
9497 (fixup-whitespace)
9498 (delete-char -2))
9499 (insert ";")
3dcb36b7 9500 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9501
5eabfe72 9502(defun vhdl-template-signal ()
d2ddb974
KH
9503 "Insert a signal declaration."
9504 (interactive)
5eabfe72
KH
9505 (let ((start (point))
9506 (in-arglist (vhdl-in-argument-list-p)))
9507 (vhdl-insert-keyword "SIGNAL ")
9508 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9509 (insert " : ")
5eabfe72
KH
9510 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9511 (vhdl-template-field "type")
d2ddb974 9512 (if in-arglist
5eabfe72
KH
9513 (progn (insert ";")
9514 (vhdl-comment-insert-inline))
d2ddb974
KH
9515 (let ((position (point)))
9516 (insert " := ")
5eabfe72
KH
9517 (unless (vhdl-template-field "[initialization]" nil t)
9518 (delete-region position (point)))
9519 (insert ";")
9520 (vhdl-comment-insert-inline))))))
9521
9522(defun vhdl-template-subnature ()
9523 "Insert a subnature declaration."
9524 (interactive)
9525 (let ((start (point))
9526 position)
9527 (vhdl-insert-keyword "SUBNATURE ")
9528 (when (vhdl-template-field "name" nil t start (point))
9529 (vhdl-insert-keyword " IS ")
9530 (vhdl-template-field "nature" " (")
9531 (if (vhdl-template-field "[index range]" nil t)
9532 (insert ")")
9533 (delete-char -2))
9534 (setq position (point))
9535 (vhdl-insert-keyword " TOLERANCE ")
9536 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9537 nil t nil nil t))
9538 (delete-region position (point))
9539 (vhdl-insert-keyword " ACROSS ")
9540 (vhdl-template-field "string expression" nil nil nil nil t)
9541 (vhdl-insert-keyword " THROUGH"))
9542 (insert ";")
9543 (vhdl-comment-insert-inline))))
9544
9545(defun vhdl-template-subprogram-body ()
9546 "Insert a subprogram body."
9547 (interactive)
9548 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9549 (vhdl-template-function-body)
9550 (vhdl-template-procedure-body)))
d2ddb974 9551
5eabfe72
KH
9552(defun vhdl-template-subprogram-decl ()
9553 "Insert a subprogram declaration."
9554 (interactive)
9555 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9556 (vhdl-template-function-decl)
9557 (vhdl-template-procedure-decl)))
9558
9559(defun vhdl-template-subtype ()
d2ddb974
KH
9560 "Insert a subtype declaration."
9561 (interactive)
5eabfe72
KH
9562 (let ((start (point)))
9563 (vhdl-insert-keyword "SUBTYPE ")
9564 (when (vhdl-template-field "name" nil t start (point))
9565 (vhdl-insert-keyword " IS ")
9566 (vhdl-template-field "type" " ")
9567 (unless
9568 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
d2ddb974 9569 (delete-char -1))
5eabfe72
KH
9570 (insert ";")
9571 (vhdl-comment-insert-inline))))
d2ddb974 9572
5eabfe72
KH
9573(defun vhdl-template-terminal ()
9574 "Insert a terminal declaration."
d2ddb974 9575 (interactive)
5eabfe72
KH
9576 (let ((start (point)))
9577 (vhdl-insert-keyword "TERMINAL ")
9578 (when (vhdl-template-field "names" nil t start (point))
9579 (insert " : ")
9580 (vhdl-template-field "nature")
9581 (insert ";")
9582 (vhdl-comment-insert-inline))))
d2ddb974 9583
5eabfe72
KH
9584(defun vhdl-template-type ()
9585 "Insert a type declaration."
9586 (interactive)
9587 (let ((start (point))
9588 name mid-pos end-pos)
9589 (vhdl-insert-keyword "TYPE ")
9590 (when (setq name (vhdl-template-field "name" nil t start (point)))
9591 (vhdl-insert-keyword " IS ")
9592 (let ((definition
9593 (upcase
9594 (or (vhdl-template-field
9595 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9596 ""))))
9597 (cond ((equal definition "")
3dcb36b7 9598 (delete-backward-char 4)
5eabfe72
KH
9599 (insert ";"))
9600 ((equal definition "ARRAY")
9601 (kill-word -1)
9602 (vhdl-template-array 'type t))
9603 ((equal definition "RECORD")
9604 (setq mid-pos (point-marker))
9605 (kill-word -1)
9606 (vhdl-template-record 'type name t))
9607 ((equal definition "ACCESS")
9608 (insert " ")
9609 (vhdl-template-field "type" ";"))
9610 ((equal definition "FILE")
9611 (vhdl-insert-keyword " OF ")
9612 (vhdl-template-field "type" ";"))
9613 (t (insert ";")))
9614 (when mid-pos
9615 (setq end-pos (point-marker))
9616 (goto-char mid-pos)
9617 (end-of-line))
9618 (vhdl-comment-insert-inline)
9619 (when end-pos (goto-char end-pos))))))
9620
9621(defun vhdl-template-use ()
d2ddb974
KH
9622 "Insert a use clause."
9623 (interactive)
3dcb36b7
JB
9624 (let ((start (point)))
9625 (vhdl-prepare-search-1
5eabfe72
KH
9626 (vhdl-insert-keyword "USE ")
9627 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9628 (vhdl-insert-keyword "..ALL;")
9629 (backward-char 6)
9630 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9631 (forward-char 1)
9632 (vhdl-template-field "package name")
9633 (forward-char 5))))))
9634
9635(defun vhdl-template-variable ()
d2ddb974
KH
9636 "Insert a variable declaration."
9637 (interactive)
5eabfe72 9638 (let ((start (point))
5eabfe72 9639 (in-arglist (vhdl-in-argument-list-p)))
3dcb36b7 9640 (vhdl-prepare-search-2
5eabfe72 9641 (if (or (save-excursion
3dcb36b7 9642 (and (vhdl-re-search-backward
5eabfe72
KH
9643 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9644 nil t)
9645 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9646 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9647 (vhdl-insert-keyword "VARIABLE ")
9648 (vhdl-insert-keyword "SHARED VARIABLE ")))
9649 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9650 (insert " : ")
5eabfe72
KH
9651 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9652 (vhdl-template-field "type")
d2ddb974 9653 (if in-arglist
5eabfe72
KH
9654 (progn (insert ";")
9655 (vhdl-comment-insert-inline))
d2ddb974
KH
9656 (let ((position (point)))
9657 (insert " := ")
5eabfe72
KH
9658 (unless (vhdl-template-field "[initialization]" nil t)
9659 (delete-region position (point)))
9660 (insert ";")
9661 (vhdl-comment-insert-inline))))))
d2ddb974 9662
5eabfe72 9663(defun vhdl-template-wait ()
d2ddb974
KH
9664 "Insert a wait statement."
9665 (interactive)
9666 (vhdl-insert-keyword "WAIT ")
5eabfe72
KH
9667 (unless (vhdl-template-field
9668 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9669 nil t)
9670 (delete-char -1))
9671 (insert ";"))
d2ddb974 9672
5eabfe72 9673(defun vhdl-template-when ()
d2ddb974
KH
9674 "Indent correctly if within a case statement."
9675 (interactive)
9676 (let ((position (point))
5eabfe72 9677 margin)
3dcb36b7 9678 (vhdl-prepare-search-2
5eabfe72 9679 (if (and (= (current-column) (current-indentation))
3dcb36b7 9680 (vhdl-re-search-forward "\\<end\\>" nil t)
5eabfe72
KH
9681 (looking-at "\\s-*\\<case\\>"))
9682 (progn
9683 (setq margin (current-indentation))
9684 (goto-char position)
9685 (delete-horizontal-space)
9686 (indent-to (+ margin vhdl-basic-offset)))
9687 (goto-char position)))
9688 (vhdl-insert-keyword "WHEN ")))
9689
9690(defun vhdl-template-while-loop ()
9691 "Insert a while loop."
d2ddb974 9692 (interactive)
5eabfe72
KH
9693 (let* ((margin (current-indentation))
9694 (start (point))
9695 label)
9696 (if (not (eq vhdl-optional-labels 'all))
9697 (vhdl-insert-keyword "WHILE ")
9698 (vhdl-insert-keyword ": WHILE ")
9699 (goto-char start)
9700 (setq label (vhdl-template-field "[label]" nil t))
9701 (unless label (delete-char 2))
9702 (forward-word 1)
9703 (forward-char 1))
9704 (when vhdl-conditions-in-parenthesis (insert "("))
9705 (when (vhdl-template-field "condition" nil t start (point))
9706 (when vhdl-conditions-in-parenthesis (insert ")"))
d2ddb974
KH
9707 (vhdl-insert-keyword " LOOP\n\n")
9708 (indent-to margin)
9709 (vhdl-insert-keyword "END LOOP")
5eabfe72 9710 (insert (if label (concat " " label ";") ";"))
d2ddb974 9711 (forward-line -1)
5eabfe72 9712 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 9713
5eabfe72 9714(defun vhdl-template-with ()
d2ddb974
KH
9715 "Insert a with statement (i.e. selected signal assignment)."
9716 (interactive)
3dcb36b7
JB
9717 (vhdl-prepare-search-1
9718 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9719 (equal ";" (match-string 1)))
9720 (vhdl-template-selected-signal-asst)
9721 (vhdl-insert-keyword "WITH "))))
5eabfe72
KH
9722
9723;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9724;; Special templates
9725
9726(defun vhdl-template-clocked-wait ()
9727 "Insert a wait statement for rising/falling clock edge."
9728 (interactive)
9729 (let ((start (point))
9730 clock)
9731 (vhdl-insert-keyword "WAIT UNTIL ")
9732 (when (setq clock
9733 (or (and (not (equal "" vhdl-clock-name))
9734 (progn (insert vhdl-clock-name) vhdl-clock-name))
9735 (vhdl-template-field "clock name" nil t start (point))))
9736 (insert "'event")
9737 (vhdl-insert-keyword " AND ")
9738 (insert clock)
9739 (insert
9740 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9741 (vhdl-comment-insert-inline
9742 (concat (if vhdl-clock-rising-edge "rising" "falling")
9743 " clock edge")))))
9744
9745(defun vhdl-template-seq-process (clock reset)
9746 "Insert a template for the body of a sequential process."
9747 (let ((margin (current-indentation))
9748 position)
d2ddb974 9749 (vhdl-insert-keyword "IF ")
5eabfe72
KH
9750 (when (eq vhdl-reset-kind 'async)
9751 (insert reset " = "
9752 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9753 (vhdl-insert-keyword " THEN")
9754 (vhdl-comment-insert-inline
9755 (concat "asynchronous reset (active "
9756 (if vhdl-reset-active-high "high" "low") ")"))
9757 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9758 (setq position (point))
9759 (insert "\n") (indent-to margin)
9760 (vhdl-insert-keyword "ELSIF "))
9761 (if (eq vhdl-clock-edge-condition 'function)
9762 (insert (if vhdl-clock-rising-edge "rising" "falling")
9763 "_edge(" clock ")")
9764 (insert clock "'event")
9765 (vhdl-insert-keyword " AND ")
9766 (insert clock " = "
9767 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9768 (vhdl-insert-keyword " THEN")
9769 (vhdl-comment-insert-inline
9770 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9771 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9772 (when (eq vhdl-reset-kind 'sync)
9773 (vhdl-insert-keyword "IF ")
9774 (setq reset (or (and (not (equal "" vhdl-reset-name))
9775 (progn (insert vhdl-reset-name) vhdl-reset-name))
9776 (vhdl-template-field "reset name") "<reset>"))
9777 (insert " = "
9778 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9779 (vhdl-insert-keyword " THEN")
9780 (vhdl-comment-insert-inline
9781 (concat "synchronous reset (active "
9782 (if vhdl-reset-active-high "high" "low") ")"))
9783 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9784 (setq position (point))
9785 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9786 (vhdl-insert-keyword "ELSE")
9787 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9788 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9789 (vhdl-insert-keyword "END IF;"))
9790 (when (eq vhdl-reset-kind 'none)
9791 (setq position (point)))
9792 (insert "\n") (indent-to margin)
d2ddb974 9793 (vhdl-insert-keyword "END IF;")
5eabfe72
KH
9794 (goto-char position)
9795 reset))
d2ddb974 9796
5eabfe72
KH
9797(defun vhdl-template-standard-package (library package)
9798 "Insert specification of a standard package. Include a library
9799specification, if not already there."
3dcb36b7
JB
9800 (let ((margin (current-indentation)))
9801 (unless (equal library "std")
9802 (unless (or (save-excursion
9803 (vhdl-prepare-search-1
9804 (and (not (bobp))
9805 (re-search-backward
9806 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9807 library "\\|end\\)\\>") nil t)
9808 (match-string 2))))
9809 (equal (downcase library) "work"))
9810 (vhdl-insert-keyword "LIBRARY ")
0a2e512a
RF
9811 (insert library ";")
9812 (when package
9813 (insert "\n")
9814 (indent-to margin)))
9815 (when package
9816 (vhdl-insert-keyword "USE ")
9817 (insert library "." package)
9818 (vhdl-insert-keyword ".ALL;")))))
d2ddb974 9819
5eabfe72
KH
9820(defun vhdl-template-package-math-complex ()
9821 "Insert specification of `math_complex' package."
d2ddb974 9822 (interactive)
5eabfe72 9823 (vhdl-template-standard-package "ieee" "math_complex"))
d2ddb974 9824
5eabfe72
KH
9825(defun vhdl-template-package-math-real ()
9826 "Insert specification of `math_real' package."
d2ddb974 9827 (interactive)
5eabfe72 9828 (vhdl-template-standard-package "ieee" "math_real"))
d2ddb974 9829
5eabfe72
KH
9830(defun vhdl-template-package-numeric-bit ()
9831 "Insert specification of `numeric_bit' package."
d2ddb974 9832 (interactive)
5eabfe72 9833 (vhdl-template-standard-package "ieee" "numeric_bit"))
d2ddb974 9834
5eabfe72
KH
9835(defun vhdl-template-package-numeric-std ()
9836 "Insert specification of `numeric_std' package."
d2ddb974 9837 (interactive)
5eabfe72 9838 (vhdl-template-standard-package "ieee" "numeric_std"))
d2ddb974 9839
5eabfe72
KH
9840(defun vhdl-template-package-std-logic-1164 ()
9841 "Insert specification of `std_logic_1164' package."
9842 (interactive)
9843 (vhdl-template-standard-package "ieee" "std_logic_1164"))
d2ddb974 9844
5eabfe72
KH
9845(defun vhdl-template-package-std-logic-arith ()
9846 "Insert specification of `std_logic_arith' package."
9847 (interactive)
9848 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9849
9850(defun vhdl-template-package-std-logic-misc ()
9851 "Insert specification of `std_logic_misc' package."
9852 (interactive)
9853 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9854
9855(defun vhdl-template-package-std-logic-signed ()
9856 "Insert specification of `std_logic_signed' package."
9857 (interactive)
9858 (vhdl-template-standard-package "ieee" "std_logic_signed"))
d2ddb974 9859
5eabfe72
KH
9860(defun vhdl-template-package-std-logic-textio ()
9861 "Insert specification of `std_logic_textio' package."
9862 (interactive)
9863 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9864
9865(defun vhdl-template-package-std-logic-unsigned ()
9866 "Insert specification of `std_logic_unsigned' package."
9867 (interactive)
9868 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9869
9870(defun vhdl-template-package-textio ()
9871 "Insert specification of `textio' package."
9872 (interactive)
9873 (vhdl-template-standard-package "std" "textio"))
9874
9875(defun vhdl-template-directive (directive)
9876 "Insert directive."
9877 (unless (= (current-indentation) (current-column))
9878 (delete-horizontal-space)
9879 (insert " "))
9880 (insert "-- pragma " directive))
9881
9882(defun vhdl-template-directive-translate-on ()
9883 "Insert directive 'translate_on'."
9884 (interactive)
9885 (vhdl-template-directive "translate_on"))
9886
9887(defun vhdl-template-directive-translate-off ()
9888 "Insert directive 'translate_off'."
9889 (interactive)
9890 (vhdl-template-directive "translate_off"))
9891
9892(defun vhdl-template-directive-synthesis-on ()
9893 "Insert directive 'synthesis_on'."
9894 (interactive)
9895 (vhdl-template-directive "synthesis_on"))
9896
9897(defun vhdl-template-directive-synthesis-off ()
9898 "Insert directive 'synthesis_off'."
9899 (interactive)
9900 (vhdl-template-directive "synthesis_off"))
9901
3dcb36b7
JB
9902;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9903;; Header and footer templates
9904
9905(defun vhdl-template-header (&optional file-title)
9906 "Insert a VHDL file header."
9907 (interactive)
9908 (unless (equal vhdl-file-header "")
9909 (let (pos)
9910 (save-excursion
9911 (goto-char (point-min))
9912 (vhdl-insert-string-or-file vhdl-file-header)
9913 (setq pos (point-marker)))
9914 (vhdl-template-replace-header-keywords
9915 (point-min-marker) pos file-title))))
9916
9917(defun vhdl-template-footer ()
9918 "Insert a VHDL file footer."
9919 (interactive)
9920 (unless (equal vhdl-file-footer "")
9921 (let (pos)
9922 (save-excursion
9923 (goto-char (point-max))
9924 (setq pos (point-marker))
9925 (vhdl-insert-string-or-file vhdl-file-footer)
9926 (unless (= (preceding-char) ?\n)
9927 (insert "\n")))
9928 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9929
9930(defun vhdl-template-replace-header-keywords (beg end &optional file-title
9931 is-model)
9932 "Replace keywords in header and footer."
9933 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9934 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9935 pos)
9936 (vhdl-prepare-search-2
9937 (save-excursion
9938 (goto-char beg)
9939 (while (search-forward "<projectdesc>" end t)
9940 (replace-match project-desc t t))
9941 (goto-char beg)
9942 (while (search-forward "<filename>" end t)
9943 (replace-match (buffer-name) t t))
9944 (goto-char beg)
9945 (while (search-forward "<copyright>" end t)
9946 (replace-match vhdl-copyright-string t t))
9947 (goto-char beg)
9948 (while (search-forward "<author>" end t)
9949 (replace-match "" t t)
9950 (insert (user-full-name))
9951 (when user-mail-address (insert " <" user-mail-address ">")))
9952 (goto-char beg)
9953 (while (search-forward "<login>" end t)
9954 (replace-match (user-login-name) t t))
9955 (goto-char beg)
9956 (while (search-forward "<project>" end t)
9957 (replace-match project-title t t))
9958 (goto-char beg)
9959 (while (search-forward "<company>" end t)
9960 (replace-match vhdl-company-name t t))
9961 (goto-char beg)
9962 (while (search-forward "<platform>" end t)
9963 (replace-match vhdl-platform-spec t t))
9964 (goto-char beg)
9965 (while (search-forward "<standard>" end t)
9966 (replace-match
9967 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9968 ((vhdl-standard-p '93) "'93"))
9969 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9970 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9971 (goto-char beg)
9972 ;; Replace <RCS> with $, so that RCS for the source is
9973 ;; not over-enthusiastic with replacements
9974 (while (search-forward "<RCS>" end t)
9975 (replace-match "$" nil t))
9976 (goto-char beg)
9977 (while (search-forward "<date>" end t)
9978 (replace-match "" t t)
9979 (vhdl-template-insert-date))
9980 (goto-char beg)
9981 (while (search-forward "<year>" end t)
9982 (replace-match (format-time-string "%Y" nil) t t))
9983 (goto-char beg)
9984 (when file-title
9985 (while (search-forward "<title string>" end t)
9986 (replace-match file-title t t))
9987 (goto-char beg))
9988 (let (string)
9989 (while
9990 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9991 (setq string (read-string (concat (match-string 1) ": ")))
9992 (replace-match string t t)))
9993 (goto-char beg)
9994 (when (and (not is-model) (search-forward "<cursor>" end t))
9995 (replace-match "" t t)
9996 (setq pos (point))))
9997 (when pos (goto-char pos))
9998 (unless is-model
9999 (when (or (not project-title) (equal project-title ""))
10000 (message "You can specify a project title in user option `vhdl-project-alist'"))
10001 (when (or (not project-desc) (equal project-desc ""))
10002 (message "You can specify a project description in user option `vhdl-project-alist'"))
10003 (when (equal vhdl-platform-spec "")
10004 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10005 (when (equal vhdl-company-name "")
10006 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10007
5eabfe72
KH
10008;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10009;; Comment templates and functions
10010
10011(defun vhdl-comment-indent ()
10012 "Indent comments."
10013 (let* ((position (point))
10014 (col
10015 (progn
10016 (forward-line -1)
10017 (if (re-search-forward "--" position t)
10018 (- (current-column) 2) ; existing comment at bol stays there
10019 (goto-char position)
10020 (skip-chars-backward " \t")
10021 (max comment-column ; else indent to comment column
10022 (1+ (current-column))))))) ; except leave at least one space
10023 (goto-char position)
10024 col))
10025
10026(defun vhdl-comment-insert ()
d2ddb974 10027 "Start a comment at the end of the line.
5eabfe72
KH
10028If on line with code, indent at least `comment-column'.
10029If starting after end-comment-column, start a new line."
d2ddb974 10030 (interactive)
5eabfe72
KH
10031 (when (> (current-column) end-comment-column) (newline-and-indent))
10032 (if (or (looking-at "\\s-*$") ; end of line
d2ddb974
KH
10033 (and (not unread-command-events) ; called with key binding or menu
10034 (not (end-of-line))))
5eabfe72
KH
10035 (let (margin)
10036 (while (= (preceding-char) ?-) (delete-char -1))
d2ddb974 10037 (setq margin (current-column))
5eabfe72
KH
10038 (delete-horizontal-space)
10039 (if (bolp)
10040 (progn (indent-to margin) (insert "--"))
d2ddb974 10041 (insert " ")
5eabfe72
KH
10042 (indent-to comment-column)
10043 (insert "--"))
d2ddb974 10044 (if (not unread-command-events) (insert " ")))
5eabfe72 10045 ;; else code following current point implies commenting out code
d2ddb974
KH
10046 (let (next-input code)
10047 (while (= (preceding-char) ?-) (delete-char -2))
10048 (while (= (setq next-input (read-char)) 13) ; CR
5eabfe72 10049 (insert "--") ; or have a space after it?
d2ddb974
KH
10050 (forward-char -2)
10051 (forward-line 1)
10052 (message "Enter CR if commenting out a line of code.")
5eabfe72 10053 (setq code t))
3dcb36b7 10054 (unless code
5eabfe72 10055 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
d2ddb974 10056 (setq unread-command-events
5eabfe72 10057 (list (vhdl-character-to-event next-input)))))) ; pushback the char
d2ddb974 10058
5eabfe72 10059(defun vhdl-comment-display (&optional line-exists)
d2ddb974
KH
10060 "Add 2 comment lines at the current indent, making a display comment."
10061 (interactive)
5eabfe72 10062 (let ((margin (current-indentation)))
3dcb36b7 10063 (unless line-exists (vhdl-comment-display-line))
5eabfe72
KH
10064 (insert "\n") (indent-to margin)
10065 (insert "\n") (indent-to margin)
10066 (vhdl-comment-display-line)
10067 (end-of-line -0)
10068 (insert "-- ")))
10069
10070(defun vhdl-comment-display-line ()
d2ddb974
KH
10071 "Displays one line of dashes."
10072 (interactive)
10073 (while (= (preceding-char) ?-) (delete-char -2))
10074 (let* ((col (current-column))
10075 (len (- end-comment-column col)))
5eabfe72 10076 (insert-char ?- len)))
d2ddb974 10077
5eabfe72
KH
10078(defun vhdl-comment-append-inline ()
10079 "Append empty inline comment to current line."
10080 (interactive)
10081 (end-of-line)
10082 (delete-horizontal-space)
10083 (insert " ")
10084 (indent-to comment-column)
10085 (insert "-- "))
10086
10087(defun vhdl-comment-insert-inline (&optional string always-insert)
10088 "Insert inline comment."
10089 (when (or (and string (or vhdl-self-insert-comments always-insert))
10090 (and (not string) vhdl-prompt-for-comments))
10091 (let ((position (point)))
10092 (insert " ")
10093 (indent-to comment-column)
10094 (insert "-- ")
3dcb36b7
JB
10095 (if (not (or (and string (progn (insert string) t))
10096 (vhdl-template-field "[comment]" nil t)))
10097 (delete-region position (point))
10098 (while (= (preceding-char) ? ) (delete-backward-char 1))
10099; (when (> (current-column) end-comment-column)
10100; (setq position (point-marker))
10101; (re-search-backward "-- ")
10102; (insert "\n")
10103; (indent-to comment-column)
10104; (goto-char position))
10105 ))))
5eabfe72
KH
10106
10107(defun vhdl-comment-block ()
10108 "Insert comment for code block."
10109 (when vhdl-prompt-for-comments
3dcb36b7
JB
10110 (let ((final-pos (point-marker)))
10111 (vhdl-prepare-search-2
5eabfe72 10112 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
3dcb36b7 10113 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
5eabfe72
KH
10114 (let (margin)
10115 (back-to-indentation)
10116 (setq margin (current-column))
10117 (end-of-line -0)
10118 (if (bobp)
10119 (progn (insert "\n") (forward-line -1))
10120 (insert "\n"))
10121 (indent-to margin)
10122 (insert "-- purpose: ")
10123 (unless (vhdl-template-field "[description]" nil t)
10124 (vhdl-line-kill-entire)))))
10125 (goto-char final-pos))))
d2ddb974
KH
10126
10127(defun vhdl-comment-uncomment-region (beg end &optional arg)
5eabfe72 10128 "Comment out region if not commented out, uncomment otherwise."
d2ddb974 10129 (interactive "r\nP")
5eabfe72
KH
10130 (save-excursion
10131 (goto-char (1- end))
10132 (end-of-line)
10133 (setq end (point-marker))
10134 (goto-char beg)
10135 (beginning-of-line)
10136 (setq beg (point))
10137 (if (looking-at comment-start)
3dcb36b7 10138 (comment-region beg end '(4))
5eabfe72
KH
10139 (comment-region beg end))))
10140
10141(defun vhdl-comment-uncomment-line (&optional arg)
10142 "Comment out line if not commented out, uncomment otherwise."
d2ddb974 10143 (interactive "p")
5eabfe72
KH
10144 (save-excursion
10145 (beginning-of-line)
10146 (let ((position (point)))
10147 (forward-line (or arg 1))
10148 (vhdl-comment-uncomment-region position (point)))))
d2ddb974 10149
5eabfe72
KH
10150(defun vhdl-comment-kill-region (beg end)
10151 "Kill comments in region."
10152 (interactive "r")
10153 (save-excursion
10154 (goto-char end)
10155 (setq end (point-marker))
10156 (goto-char beg)
10157 (beginning-of-line)
10158 (while (< (point) end)
10159 (if (looking-at "^\\(\\s-*--.*\n\\)")
10160 (progn (delete-region (match-beginning 1) (match-end 1)))
10161 (beginning-of-line 2)))))
10162
10163(defun vhdl-comment-kill-inline-region (beg end)
10164 "Kill inline comments in region."
10165 (interactive "r")
10166 (save-excursion
10167 (goto-char end)
10168 (setq end (point-marker))
10169 (goto-char beg)
10170 (beginning-of-line)
10171 (while (< (point) end)
10172 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10173 (delete-region (match-beginning 1) (match-end 1)))
10174 (beginning-of-line 2))))
10175
10176;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10177;; Subtemplates
10178
10179(defun vhdl-template-begin-end (construct name margin &optional empty-lines)
d2ddb974
KH
10180 "Insert a begin ... end pair with optional name after the end.
10181Point is left between them."
5eabfe72 10182 (let (position)
5eabfe72 10183 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10184 (indent-to margin)
10185 (vhdl-insert-keyword "BEGIN")
5eabfe72
KH
10186 (when (and (or construct name) vhdl-self-insert-comments)
10187 (insert " --")
10188 (when construct (insert " ") (vhdl-insert-keyword construct))
10189 (when name (insert " " name)))
d2ddb974 10190 (insert "\n")
5eabfe72 10191 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974 10192 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
10193 (setq position (point))
10194 (insert "\n")
10195 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10196 (indent-to margin)
10197 (vhdl-insert-keyword "END")
5eabfe72
KH
10198 (when construct (insert " ") (vhdl-insert-keyword construct))
10199 (insert (if name (concat " " name) "") ";")
10200 (goto-char position)))
d2ddb974 10201
5eabfe72 10202(defun vhdl-template-argument-list (&optional is-function)
d2ddb974
KH
10203 "Read from user a procedure or function argument list."
10204 (insert " (")
d2ddb974 10205 (let ((margin (current-column))
5eabfe72
KH
10206 (start (point))
10207 (end-pos (point))
10208 not-empty interface semicolon-pos)
3dcb36b7 10209 (unless vhdl-argument-list-indent
5eabfe72
KH
10210 (setq margin (+ (current-indentation) vhdl-basic-offset))
10211 (insert "\n")
10212 (indent-to margin))
10213 (setq interface (vhdl-template-field
10214 (concat "[CONSTANT | SIGNAL"
10215 (unless is-function " | VARIABLE") "]") " " t))
10216 (while (vhdl-template-field "[names]" nil t)
10217 (setq not-empty t)
10218 (insert " : ")
3dcb36b7 10219 (unless is-function
5eabfe72
KH
10220 (if (and interface (equal (upcase interface) "CONSTANT"))
10221 (vhdl-insert-keyword "IN ")
10222 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10223 (vhdl-template-field "type")
10224 (setq semicolon-pos (point))
10225 (insert ";")
10226 (vhdl-comment-insert-inline)
10227 (setq end-pos (point))
10228 (insert "\n")
10229 (indent-to margin)
10230 (setq interface (vhdl-template-field
10231 (concat "[CONSTANT | SIGNAL"
10232 (unless is-function " | VARIABLE") "]") " " t)))
10233 (delete-region end-pos (point))
10234 (when semicolon-pos (goto-char semicolon-pos))
10235 (if not-empty
10236 (progn (delete-char 1) (insert ")"))
3dcb36b7 10237 (delete-backward-char 2))))
5eabfe72
KH
10238
10239(defun vhdl-template-generic-list (optional &optional no-value)
d2ddb974 10240 "Read from user a generic spec argument list."
5eabfe72 10241 (let (margin
d2ddb974 10242 (start (point)))
5eabfe72
KH
10243 (vhdl-insert-keyword "GENERIC (")
10244 (setq margin (current-column))
3dcb36b7 10245 (unless vhdl-argument-list-indent
5eabfe72
KH
10246 (let ((position (point)))
10247 (back-to-indentation)
10248 (setq margin (+ (current-column) vhdl-basic-offset))
10249 (goto-char position)
10250 (insert "\n")
10251 (indent-to margin)))
10252 (let ((vhdl-generics (vhdl-template-field
10253 (concat (and optional "[") "name"
10254 (and no-value "s") (and optional "]"))
10255 nil optional)))
10256 (if (not vhdl-generics)
d2ddb974 10257 (if optional
5eabfe72 10258 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10259 (unless vhdl-argument-list-indent
5eabfe72
KH
10260 (vhdl-line-kill-entire) (end-of-line -0)))
10261 (vhdl-template-undo start (point))
d2ddb974
KH
10262 nil )
10263 (insert " : ")
5eabfe72
KH
10264 (let (semicolon-pos end-pos)
10265 (while vhdl-generics
10266 (vhdl-template-field "type")
10267 (if no-value
10268 (progn (setq semicolon-pos (point))
10269 (insert ";"))
10270 (insert " := ")
10271 (unless (vhdl-template-field "[value]" nil t)
10272 (delete-char -4))
10273 (setq semicolon-pos (point))
10274 (insert ";"))
10275 (vhdl-comment-insert-inline)
10276 (setq end-pos (point))
10277 (insert "\n")
10278 (indent-to margin)
10279 (setq vhdl-generics (vhdl-template-field
10280 (concat "[name" (and no-value "s") "]")
10281 " : " t)))
10282 (delete-region end-pos (point))
10283 (goto-char semicolon-pos)
10284 (insert ")")
10285 (end-of-line)
3dcb36b7 10286 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
10287 t)))))
10288
10289(defun vhdl-template-port-list (optional)
10290 "Read from user a port spec argument list."
10291 (let ((start (point))
10292 margin vhdl-ports object)
10293 (vhdl-insert-keyword "PORT (")
10294 (setq margin (current-column))
3dcb36b7 10295 (unless vhdl-argument-list-indent
5eabfe72
KH
10296 (let ((position (point)))
10297 (back-to-indentation)
10298 (setq margin (+ (current-column) vhdl-basic-offset))
10299 (goto-char position)
10300 (insert "\n")
10301 (indent-to margin)))
10302 (when (vhdl-standard-p 'ams)
10303 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10304 " " t)))
10305 (setq vhdl-ports (vhdl-template-field
10306 (concat (and optional "[") "names" (and optional "]"))
10307 nil optional))
10308 (if (not vhdl-ports)
10309 (if optional
10310 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10311 (unless vhdl-argument-list-indent
5eabfe72
KH
10312 (vhdl-line-kill-entire) (end-of-line -0)))
10313 (vhdl-template-undo start (point))
10314 nil)
10315 (insert " : ")
10316 (let (semicolon-pos end-pos)
10317 (while vhdl-ports
10318 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10319 (vhdl-template-field "IN | OUT | INOUT" " "))
10320 ((equal "QUANTITY" (upcase object))
10321 (vhdl-template-field "[IN | OUT]" " " t)))
10322 (vhdl-template-field
10323 (if (and object (equal "TERMINAL" (upcase object)))
10324 "nature" "type"))
10325 (setq semicolon-pos (point))
10326 (insert ";")
10327 (vhdl-comment-insert-inline)
10328 (setq end-pos (point))
10329 (insert "\n")
10330 (indent-to margin)
10331 (when (vhdl-standard-p 'ams)
10332 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10333 " " t)))
10334 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10335 (delete-region end-pos (point))
10336 (goto-char semicolon-pos)
10337 (insert ")")
10338 (end-of-line)
3dcb36b7 10339 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
5eabfe72
KH
10340 t))))
10341
10342(defun vhdl-template-generate-body (margin label)
10343 "Insert body for generate template."
10344 (vhdl-insert-keyword " GENERATE")
3dcb36b7
JB
10345; (if (not (vhdl-standard-p '87))
10346; (vhdl-template-begin-end "GENERATE" label margin)
10347 (insert "\n\n")
10348 (indent-to margin)
10349 (vhdl-insert-keyword "END GENERATE ")
10350 (insert label ";")
10351 (end-of-line 0)
10352 (indent-to (+ margin vhdl-basic-offset)))
5eabfe72
KH
10353
10354(defun vhdl-template-insert-date ()
d2ddb974
KH
10355 "Insert date in appropriate format."
10356 (interactive)
5eabfe72
KH
10357 (insert
10358 (cond
3dcb36b7 10359 ;; 'american, 'european, 'scientific kept for backward compatibility
5eabfe72
KH
10360 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10361 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10362 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10363 (t (format-time-string vhdl-date-format nil)))))
10364
10365;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10366;; Help functions
10367
10368(defun vhdl-electric-space (count)
10369 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10370if in comment and past end-comment-column."
10371 (interactive "p")
10372 (cond ((vhdl-in-comment-p)
10373 (self-insert-command count)
10374 (cond ((>= (current-column) (+ 2 end-comment-column))
3dcb36b7
JB
10375 (backward-char 1)
10376 (skip-chars-backward "^ \t\n")
5eabfe72 10377 (indent-new-comment-line)
3dcb36b7 10378 (skip-chars-forward "^ \t\n")
5eabfe72
KH
10379 (forward-char 1))
10380 ((>= (current-column) end-comment-column)
10381 (indent-new-comment-line))
10382 (t nil)))
10383 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10384 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
3dcb36b7
JB
10385 (vhdl-prepare-search-1
10386 (or (expand-abbrev) (vhdl-fix-case-word -1)))
5eabfe72
KH
10387 (self-insert-command count))
10388 (t (self-insert-command count))))
10389
10390(defun vhdl-template-field (prompt &optional follow-string optional
10391 begin end is-string default)
10392 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10393If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10394an empty string is inserted, return nil and call `vhdl-template-undo' for
10395the region between BEGIN and END. IS-STRING indicates whether a string
10396with double-quotes is to be inserted. DEFAULT specifies a default string."
10397 (let ((position (point))
10398 string)
10399 (insert "<" prompt ">")
10400 (setq string
10401 (condition-case ()
10402 (read-from-minibuffer (concat prompt ": ")
10403 (or (and is-string '("\"\"" . 2)) default)
10404 vhdl-minibuffer-local-map)
10405 (quit (if (and optional begin end)
10406 (progn (beep) "")
10407 (keyboard-quit)))))
10408 (when (or (not (equal string "")) optional)
10409 (delete-region position (point)))
10410 (when (and (equal string "") optional begin end)
10411 (vhdl-template-undo begin end)
10412 (message "Template aborted"))
3dcb36b7 10413 (unless (equal string "")
5eabfe72
KH
10414 (insert string)
10415 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
3dcb36b7
JB
10416 vhdl-keywords-regexp)
10417 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10418 vhdl-types-regexp)
10419 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10420 (concat "'" vhdl-attributes-regexp))
10421 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10422 vhdl-enum-values-regexp))
5eabfe72
KH
10423 (when (or (not (equal string "")) (not optional))
10424 (insert (or follow-string "")))
10425 (if (equal string "") nil string)))
10426
10427(defun vhdl-decision-query (string prompt &optional optional)
10428 "Query a decision from the user."
10429 (let ((start (point)))
10430 (when string (vhdl-insert-keyword (concat string " ")))
10431 (message prompt)
10432 (let ((char (read-char)))
10433 (delete-region start (point))
10434 (if (and optional (eq char ?\r))
10435 (progn (insert " ")
10436 (unexpand-abbrev)
3dcb36b7 10437 (throw 'abort "ERROR: Template aborted"))
5eabfe72 10438 char))))
d2ddb974
KH
10439
10440(defun vhdl-insert-keyword (keyword)
5eabfe72
KH
10441 "Insert KEYWORD and adjust case."
10442 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
d2ddb974
KH
10443
10444(defun vhdl-case-keyword (keyword)
5eabfe72
KH
10445 "Adjust case of KEYWORD."
10446 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
d2ddb974
KH
10447
10448(defun vhdl-case-word (num)
5eabfe72
KH
10449 "Adjust case or following NUM words."
10450 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10451
10452(defun vhdl-minibuffer-tab (&optional prefix-arg)
10453 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7 10454else insert tab (used for word completion in VHDL minibuffer)."
5eabfe72 10455 (interactive "P")
3dcb36b7
JB
10456 (cond
10457 ;; expand word
10458 ((= (char-syntax (preceding-char)) ?w)
10459 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10460 (case-replace nil)
10461 (hippie-expand-only-buffers
10462 (or (and (boundp 'hippie-expand-only-buffers)
10463 hippie-expand-only-buffers)
10464 '(vhdl-mode))))
10465 (vhdl-expand-abbrev prefix-arg)))
10466 ;; expand parenthesis
10467 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10468 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10469 (case-replace nil))
10470 (vhdl-expand-paren prefix-arg)))
10471 ;; insert tab
10472 (t (insert-tab))))
5eabfe72
KH
10473
10474(defun vhdl-template-search-prompt ()
10475 "Search for left out template prompts and query again."
10476 (interactive)
3dcb36b7
JB
10477 (vhdl-prepare-search-2
10478 (when (or (re-search-forward
10479 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10480 (re-search-backward
10481 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10482 (let ((string (match-string 1)))
10483 (replace-match "")
10484 (vhdl-template-field string)))))
5eabfe72
KH
10485
10486(defun vhdl-template-undo (begin end)
10487 "Undo aborted template by deleting region and unexpanding the keyword."
10488 (cond (vhdl-template-invoked-by-hook
10489 (goto-char end)
10490 (insert " ")
10491 (delete-region begin end)
10492 (unexpand-abbrev))
10493 (t (delete-region begin end))))
10494
10495(defun vhdl-insert-string-or-file (string)
10496 "Insert STRING or file contents if STRING is an existing file name."
10497 (unless (equal string "")
3dcb36b7
JB
10498 (let ((file-name
10499 (progn (string-match "^\\([^\n]+\\)" string)
10500 (vhdl-resolve-env-variable (match-string 1 string)))))
10501 (if (file-exists-p file-name)
10502 (forward-char (cadr (insert-file-contents file-name)))
10503 (insert string)))))
10504
10505(defun vhdl-beginning-of-block ()
10506 "Move cursor to the beginning of the enclosing block."
10507 (let (pos)
10508 (save-excursion
10509 (beginning-of-line)
10510 ;; search backward for block beginning or end
10511 (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))
10512 ;; not consider subprogram declarations
10513 (or (and (match-string 5)
10514 (save-match-data
10515 (save-excursion
10516 (goto-char (match-end 5))
0a2e512a
RF
10517 (forward-word 1)
10518 (vhdl-forward-syntactic-ws)
10519 (when (looking-at "(")
10520 (forward-sexp))
3dcb36b7
JB
10521 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10522 (match-string 1)))
10523 ;; not consider configuration specifications
10524 (and (match-string 6)
10525 (save-match-data
10526 (save-excursion
10527 (vhdl-end-of-block)
10528 (beginning-of-line)
10529 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10530 (match-string 2))
10531 ;; skip subblock if block end found
10532 (vhdl-beginning-of-block)))
10533 (when pos (goto-char pos))))
10534
10535(defun vhdl-end-of-block ()
10536 "Move cursor to the end of the enclosing block."
10537 (let (pos)
10538 (save-excursion
10539 (end-of-line)
10540 ;; search forward for block beginning or end
10541 (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))
10542 ;; not consider subprogram declarations
10543 (or (and (match-string 5)
10544 (save-match-data
10545 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10546 (match-string 1)))
10547 ;; not consider configuration specifications
10548 (and (match-string 6)
10549 (save-match-data
10550 (save-excursion
10551 (vhdl-end-of-block)
10552 (beginning-of-line)
10553 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10554 (not (match-string 2)))
10555 ;; skip subblock if block beginning found
10556 (vhdl-end-of-block)))
10557 (when pos (goto-char pos))))
5eabfe72
KH
10558
10559(defun vhdl-sequential-statement-p ()
10560 "Check if point is within sequential statement part."
3dcb36b7
JB
10561 (let ((start (point)))
10562 (save-excursion
10563 (vhdl-prepare-search-2
10564 ;; is sequential statement if ...
10565 (and (re-search-backward "^\\s-*begin\\>" nil t)
10566 ;; ... point is between "begin" and "end" of ...
10567 (progn (vhdl-end-of-block)
10568 (< start (point)))
10569 ;; ... a sequential block
10570 (progn (vhdl-beginning-of-block)
10571 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
5eabfe72
KH
10572
10573(defun vhdl-in-argument-list-p ()
10574 "Check if within an argument list."
10575 (save-excursion
3dcb36b7
JB
10576 (vhdl-prepare-search-2
10577 (or (string-match "arglist"
10578 (format "%s" (caar (vhdl-get-syntactic-context))))
10579 (progn (beginning-of-line)
10580 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
5eabfe72
KH
10581
10582;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10583;; Abbrev hooks
10584
10585(defun vhdl-hooked-abbrev (func)
10586 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10587but not if inside a comment or quote)."
3dcb36b7 10588 (if (or (vhdl-in-literal)
5eabfe72
KH
10589 (save-excursion
10590 (forward-word -1)
10591 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10592 (progn
10593 (insert " ")
10594 (unexpand-abbrev)
10595 (delete-char -1))
10596 (if (not vhdl-electric-mode)
10597 (progn
10598 (insert " ")
10599 (unexpand-abbrev)
10600 (backward-word 1)
10601 (vhdl-case-word 1)
10602 (delete-char 1))
10603 (let ((invoke-char last-command-char)
10604 (abbrev-mode -1)
10605 (vhdl-template-invoked-by-hook t))
10606 (let ((caught (catch 'abort
10607 (funcall func))))
29a4e67d 10608 (when (stringp caught) (message "%s" caught)))
5eabfe72
KH
10609 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10610 ;; delete CR which is still in event queue
4bcb9c95 10611 (if (fboundp 'enqueue-eval-event)
5eabfe72
KH
10612 (enqueue-eval-event 'delete-char -1)
10613 (setq unread-command-events ; push back a delete char
10614 (list (vhdl-character-to-event ?\177))))))))
10615
10616(defun vhdl-template-alias-hook ()
10617 (vhdl-hooked-abbrev 'vhdl-template-alias))
10618(defun vhdl-template-architecture-hook ()
10619 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10620(defun vhdl-template-assert-hook ()
10621 (vhdl-hooked-abbrev 'vhdl-template-assert))
10622(defun vhdl-template-attribute-hook ()
10623 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10624(defun vhdl-template-block-hook ()
10625 (vhdl-hooked-abbrev 'vhdl-template-block))
10626(defun vhdl-template-break-hook ()
10627 (vhdl-hooked-abbrev 'vhdl-template-break))
10628(defun vhdl-template-case-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-case))
10630(defun vhdl-template-component-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-component))
10632(defun vhdl-template-instance-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-template-instance))
10634(defun vhdl-template-conditional-signal-asst-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10636(defun vhdl-template-configuration-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10638(defun vhdl-template-constant-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-constant))
10640(defun vhdl-template-disconnect-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10642(defun vhdl-template-display-comment-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-comment-display))
10644(defun vhdl-template-else-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-template-else))
10646(defun vhdl-template-elsif-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10648(defun vhdl-template-entity-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-entity))
10650(defun vhdl-template-exit-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-exit))
10652(defun vhdl-template-file-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-template-file))
10654(defun vhdl-template-for-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-template-for))
10656(defun vhdl-template-function-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-function))
10658(defun vhdl-template-generic-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-generic))
10660(defun vhdl-template-group-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-group))
10662(defun vhdl-template-library-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-library))
10664(defun vhdl-template-limit-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-limit))
10666(defun vhdl-template-if-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-if))
10668(defun vhdl-template-bare-loop-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10670(defun vhdl-template-map-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-map))
10672(defun vhdl-template-nature-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-nature))
10674(defun vhdl-template-next-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-next))
3dcb36b7
JB
10676(defun vhdl-template-others-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-others))
5eabfe72
KH
10678(defun vhdl-template-package-hook ()
10679 (vhdl-hooked-abbrev 'vhdl-template-package))
10680(defun vhdl-template-port-hook ()
10681 (vhdl-hooked-abbrev 'vhdl-template-port))
10682(defun vhdl-template-procedural-hook ()
10683 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10684(defun vhdl-template-procedure-hook ()
10685 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10686(defun vhdl-template-process-hook ()
10687 (vhdl-hooked-abbrev 'vhdl-template-process))
10688(defun vhdl-template-quantity-hook ()
10689 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10690(defun vhdl-template-report-hook ()
10691 (vhdl-hooked-abbrev 'vhdl-template-report))
10692(defun vhdl-template-return-hook ()
10693 (vhdl-hooked-abbrev 'vhdl-template-return))
10694(defun vhdl-template-selected-signal-asst-hook ()
10695 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10696(defun vhdl-template-signal-hook ()
10697 (vhdl-hooked-abbrev 'vhdl-template-signal))
10698(defun vhdl-template-subnature-hook ()
10699 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10700(defun vhdl-template-subtype-hook ()
10701 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10702(defun vhdl-template-terminal-hook ()
10703 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10704(defun vhdl-template-type-hook ()
10705 (vhdl-hooked-abbrev 'vhdl-template-type))
10706(defun vhdl-template-use-hook ()
10707 (vhdl-hooked-abbrev 'vhdl-template-use))
10708(defun vhdl-template-variable-hook ()
10709 (vhdl-hooked-abbrev 'vhdl-template-variable))
10710(defun vhdl-template-wait-hook ()
10711 (vhdl-hooked-abbrev 'vhdl-template-wait))
10712(defun vhdl-template-when-hook ()
10713 (vhdl-hooked-abbrev 'vhdl-template-when))
10714(defun vhdl-template-while-loop-hook ()
10715 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10716(defun vhdl-template-with-hook ()
10717 (vhdl-hooked-abbrev 'vhdl-template-with))
10718(defun vhdl-template-and-hook ()
10719 (vhdl-hooked-abbrev 'vhdl-template-and))
10720(defun vhdl-template-or-hook ()
10721 (vhdl-hooked-abbrev 'vhdl-template-or))
10722(defun vhdl-template-nand-hook ()
10723 (vhdl-hooked-abbrev 'vhdl-template-nand))
10724(defun vhdl-template-nor-hook ()
10725 (vhdl-hooked-abbrev 'vhdl-template-nor))
10726(defun vhdl-template-xor-hook ()
10727 (vhdl-hooked-abbrev 'vhdl-template-xor))
10728(defun vhdl-template-xnor-hook ()
10729 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10730(defun vhdl-template-not-hook ()
10731 (vhdl-hooked-abbrev 'vhdl-template-not))
10732
10733(defun vhdl-template-default-hook ()
10734 (vhdl-hooked-abbrev 'vhdl-template-default))
10735(defun vhdl-template-default-indent-hook ()
10736 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10737
10738;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10739;; Template insertion from completion list
10740
10741(defun vhdl-template-insert-construct (name)
10742 "Insert the built-in construct template with NAME."
10743 (interactive
10744 (list (let ((completion-ignore-case t))
10745 (completing-read "Construct name: "
10746 vhdl-template-construct-alist nil t))))
10747 (vhdl-template-insert-fun
3dcb36b7 10748 (cadr (assoc name vhdl-template-construct-alist))))
5eabfe72
KH
10749
10750(defun vhdl-template-insert-package (name)
10751 "Insert the built-in package template with NAME."
10752 (interactive
10753 (list (let ((completion-ignore-case t))
10754 (completing-read "Package name: "
10755 vhdl-template-package-alist nil t))))
10756 (vhdl-template-insert-fun
3dcb36b7 10757 (cadr (assoc name vhdl-template-package-alist))))
5eabfe72
KH
10758
10759(defun vhdl-template-insert-directive (name)
10760 "Insert the built-in directive template with NAME."
10761 (interactive
10762 (list (let ((completion-ignore-case t))
10763 (completing-read "Directive name: "
10764 vhdl-template-directive-alist nil t))))
10765 (vhdl-template-insert-fun
3dcb36b7 10766 (cadr (assoc name vhdl-template-directive-alist))))
5eabfe72
KH
10767
10768(defun vhdl-template-insert-fun (fun)
10769 "Call FUN to insert a built-in template."
10770 (let ((caught (catch 'abort (when fun (funcall fun)))))
29a4e67d 10771 (when (stringp caught) (message "%s" caught))))
5eabfe72
KH
10772
10773
10774;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10775;;; Models
10776;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10777
10778(defun vhdl-model-insert (model-name)
10779 "Insert the user model with name MODEL-NAME."
10780 (interactive
10781 (let ((completion-ignore-case t))
10782 (list (completing-read "Model name: " vhdl-model-alist))))
3dcb36b7 10783 (indent-according-to-mode)
5eabfe72
KH
10784 (let ((start (point-marker))
10785 (margin (current-indentation))
5eabfe72 10786 model position prompt string end)
3dcb36b7 10787 (vhdl-prepare-search-2
5eabfe72
KH
10788 (when (setq model (assoc model-name vhdl-model-alist))
10789 ;; insert model
10790 (beginning-of-line)
10791 (delete-horizontal-space)
10792 (goto-char start)
10793 (vhdl-insert-string-or-file (nth 1 model))
10794 (setq end (point-marker))
10795 ;; indent code
10796 (goto-char start)
10797 (beginning-of-line)
10798 (while (< (point) end)
10799 (unless (looking-at "^$")
10800 (insert-char ? margin))
10801 (beginning-of-line 2))
10802 (goto-char start)
10803 ;; insert clock
10804 (unless (equal "" vhdl-clock-name)
10805 (while (re-search-forward "<clock>" end t)
10806 (replace-match vhdl-clock-name)))
10807 (goto-char start)
10808 ;; insert reset
10809 (unless (equal "" vhdl-reset-name)
10810 (while (re-search-forward "<reset>" end t)
10811 (replace-match vhdl-reset-name)))
3dcb36b7
JB
10812 ;; replace header prompts
10813 (vhdl-template-replace-header-keywords start end nil t)
5eabfe72 10814 (goto-char start)
3dcb36b7 10815 ;; query other prompts
5eabfe72
KH
10816 (while (re-search-forward
10817 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10818 (unless (equal "cursor" (match-string 1))
10819 (setq position (match-beginning 1))
10820 (setq prompt (match-string 1))
10821 (replace-match "")
10822 (setq string (vhdl-template-field prompt nil t))
a5a08b1f 10823 ;; replace occurrences of same prompt
5eabfe72
KH
10824 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10825 (replace-match (or string "")))
10826 (goto-char position)))
10827 (goto-char start)
10828 ;; goto final position
10829 (if (re-search-forward "<cursor>" end t)
10830 (replace-match "")
10831 (goto-char end))))))
10832
10833(defun vhdl-model-defun ()
10834 "Define help and hook functions for user models."
10835 (let ((model-alist vhdl-model-alist)
10836 model-name model-keyword)
10837 (while model-alist
10838 ;; define functions for user models that can be invoked from menu and key
10839 ;; bindings and which themselves call `vhdl-model-insert' with the model
10840 ;; name as argument
10841 (setq model-name (nth 0 (car model-alist)))
d4a5b644
GM
10842 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10843 ,(concat "Insert model for \"" model-name "\".")
10844 (interactive)
10845 (vhdl-model-insert ,model-name)))
5eabfe72
KH
10846 ;; define hooks for user models that are invoked from keyword abbrevs
10847 (setq model-keyword (nth 3 (car model-alist)))
10848 (unless (equal model-keyword "")
d4a5b644
GM
10849 (eval `(defun
10850 ,(vhdl-function-name
10851 "vhdl-model" model-name "hook") ()
10852 (vhdl-hooked-abbrev
10853 ',(vhdl-function-name "vhdl-model" model-name)))))
5eabfe72
KH
10854 (setq model-alist (cdr model-alist)))))
10855
10856(vhdl-model-defun)
10857
10858
10859;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10860;;; Port translation
10861;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10862
10863(defvar vhdl-port-list nil
3dcb36b7 10864 "Variable to hold last port map parsed.")
5eabfe72 10865;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
10866;; (ent-name
10867;; ((generic-names) generic-type generic-init generic-comment group-comment)
10868;; ((port-names) port-object port-direct port-type port-comment group-comment)
10869;; (lib-name pack-key))
5eabfe72
KH
10870
10871(defun vhdl-parse-string (string &optional optional)
3dcb36b7 10872 "Check that the text following point matches the regexp in STRING."
5eabfe72 10873 (if (looking-at string)
3dcb36b7 10874 (goto-char (match-end 0))
5eabfe72 10875 (unless optional
3dcb36b7
JB
10876 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10877 (vhdl-current-line) string)))
5eabfe72
KH
10878 nil))
10879
0a2e512a 10880(defun vhdl-replace-string (regexp-cons string &optional adjust-case)
5eabfe72 10881 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
3dcb36b7 10882 (vhdl-prepare-search-1
5eabfe72 10883 (if (string-match (car regexp-cons) string)
0a2e512a
RF
10884 (if adjust-case
10885 (funcall vhdl-file-name-case
10886 (replace-match (cdr regexp-cons) t nil string))
10887 (replace-match (cdr regexp-cons) t nil string))
5eabfe72
KH
10888 string)))
10889
3dcb36b7
JB
10890(defun vhdl-parse-group-comment ()
10891 "Parse comment and empty lines between groups of lines."
10892 (let ((start (point))
10893 string)
10894 (vhdl-forward-comment (point-max))
10895 (setq string (buffer-substring-no-properties start (point)))
0a2e512a 10896 (vhdl-forward-syntactic-ws)
3dcb36b7
JB
10897 ;; strip off leading blanks and first newline
10898 (while (string-match "^\\(\\s-+\\)" string)
10899 (setq string (concat (substring string 0 (match-beginning 1))
10900 (substring string (match-end 1)))))
10901 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10902 (substring string 1)
10903 string)))
10904
10905(defun vhdl-paste-group-comment (string indent)
10906 "Paste comment and empty lines from STRING between groups of lines
10907with INDENT."
10908 (let ((pos (point-marker)))
10909 (when (> indent 0)
10910 (while (string-match "^\\(--\\)" string)
10911 (setq string (concat (substring string 0 (match-beginning 1))
10912 (make-string indent ? )
10913 (substring string (match-beginning 1))))))
10914 (beginning-of-line)
10915 (insert string)
10916 (goto-char pos)))
10917
10918(defvar vhdl-port-flattened nil
10919 "Indicates whether a port has been flattened.")
10920
10921(defun vhdl-port-flatten (&optional as-alist)
0a2e512a
RF
10922 "Flatten port list so that only one generic/port exists per line.
10923This operation is performed on an internally stored port and is only
10924reflected in a subsequent paste operation."
5eabfe72
KH
10925 (interactive)
10926 (if (not vhdl-port-list)
3dcb36b7 10927 (error "ERROR: No port has been read")
0a2e512a 10928 (message "Flattening port for next paste...")
5eabfe72
KH
10929 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10930 (old-vhdl-port-list (cdr vhdl-port-list))
10931 old-port-list new-port-list old-port new-port names)
10932 ;; traverse port list and flatten entries
3dcb36b7 10933 (while (cdr old-vhdl-port-list)
5eabfe72
KH
10934 (setq old-port-list (car old-vhdl-port-list))
10935 (setq new-port-list nil)
10936 (while old-port-list
10937 (setq old-port (car old-port-list))
10938 (setq names (car old-port))
10939 (while names
3dcb36b7
JB
10940 (setq new-port (cons (if as-alist (car names) (list (car names)))
10941 (cdr old-port)))
5eabfe72
KH
10942 (setq new-port-list (append new-port-list (list new-port)))
10943 (setq names (cdr names)))
10944 (setq old-port-list (cdr old-port-list)))
10945 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10946 (setq new-vhdl-port-list (append new-vhdl-port-list
10947 (list new-port-list))))
3dcb36b7
JB
10948 (setq vhdl-port-list
10949 (append new-vhdl-port-list (list old-vhdl-port-list))
10950 vhdl-port-flattened t)
0a2e512a 10951 (message "Flattening port for next paste...done"))))
5eabfe72 10952
3dcb36b7
JB
10953(defvar vhdl-port-reversed-direction nil
10954 "Indicates whether port directions are reversed.")
10955
10956(defun vhdl-port-reverse-direction ()
0a2e512a
RF
10957 "Reverse direction for all ports (useful in testbenches).
10958This operation is performed on an internally stored port and is only
10959reflected in a subsequent paste operation."
3dcb36b7
JB
10960 (interactive)
10961 (if (not vhdl-port-list)
10962 (error "ERROR: No port has been read")
0a2e512a 10963 (message "Reversing port directions for next paste...")
3dcb36b7
JB
10964 (let ((port-list (nth 2 vhdl-port-list))
10965 port-dir-car port-dir)
10966 ;; traverse port list and reverse directions
10967 (while port-list
10968 (setq port-dir-car (cddr (car port-list))
10969 port-dir (car port-dir-car))
10970 (setcar port-dir-car
10971 (cond ((equal port-dir "in") "out")
10972 ((equal port-dir "out") "in")
10973 (t port-dir)))
10974 (setq port-list (cdr port-list)))
10975 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
0a2e512a 10976 (message "Reversing port directions for next paste...done"))))
3dcb36b7 10977
5eabfe72
KH
10978(defun vhdl-port-copy ()
10979 "Get generic and port information from an entity or component declaration."
10980 (interactive)
5eabfe72 10981 (save-excursion
3dcb36b7
JB
10982 (let (parse-error end-of-list
10983 decl-type name generic-list port-list context-clause
10984 object names direct type init comment group-comment)
10985 (vhdl-prepare-search-2
5eabfe72
KH
10986 (setq
10987 parse-error
10988 (catch 'parse
10989 ;; check if within entity or component declaration
3dcb36b7 10990 (end-of-line)
5eabfe72
KH
10991 (when (or (not (re-search-backward
10992 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
3dcb36b7
JB
10993 (equal "END" (upcase (match-string 1))))
10994 (throw 'parse "ERROR: Not within an entity or component declaration"))
10995 (setq decl-type (downcase (match-string-no-properties 1)))
5eabfe72 10996 (forward-word 1)
3dcb36b7
JB
10997 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10998 (setq name (match-string-no-properties 1))
10999 (message "Reading port of %s \"%s\"..." decl-type name)
5eabfe72
KH
11000 (vhdl-forward-syntactic-ws)
11001 ;; parse generic clause
11002 (when (vhdl-parse-string "generic[ \t\n]*(" t)
3dcb36b7
JB
11003 ;; parse group comment and spacing
11004 (setq group-comment (vhdl-parse-group-comment))
11005 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72 11006 (while (not end-of-list)
0a2e512a
RF
11007 ;; parse names (accept extended identifiers)
11008 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
3dcb36b7 11009 (setq names (list (match-string-no-properties 1)))
5eabfe72 11010 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
3dcb36b7
JB
11011 (setq names
11012 (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
11013 ;; parse type
11014 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
3dcb36b7 11015 (setq type (match-string-no-properties 1))
5eabfe72
KH
11016 (setq comment nil)
11017 (while (looking-at "(")
11018 (setq type
11019 (concat type
3dcb36b7 11020 (buffer-substring-no-properties
5eabfe72
KH
11021 (point) (progn (forward-sexp) (point)))
11022 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
3dcb36b7 11023 (match-string-no-properties 1)))))
5eabfe72
KH
11024 ;; special case: closing parenthesis is on separate line
11025 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11026 (setq comment (substring type (match-beginning 2)))
11027 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 11028 ;; strip of trailing group-comment
5eabfe72
KH
11029 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11030 (setq type (substring type 0 (match-end 1)))
11031 ;; parse initialization expression
11032 (setq init nil)
11033 (when (vhdl-parse-string ":=[ \t\n]*" t)
11034 (vhdl-parse-string "\\([^();\n]*\\)")
3dcb36b7 11035 (setq init (match-string-no-properties 1))
5eabfe72
KH
11036 (while (looking-at "(")
11037 (setq init
11038 (concat init
3dcb36b7 11039 (buffer-substring-no-properties
5eabfe72
KH
11040 (point) (progn (forward-sexp) (point)))
11041 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 11042 (match-string-no-properties 1))))))
5eabfe72
KH
11043 ;; special case: closing parenthesis is on separate line
11044 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11045 (setq comment (substring init (match-beginning 2)))
11046 (setq init (substring init 0 (match-beginning 1)))
11047 (vhdl-forward-syntactic-ws))
11048 (skip-chars-forward " \t")
11049 ;; parse inline comment, special case: as above, no initial.
11050 (unless comment
11051 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11052 (match-string-no-properties 1))))
5eabfe72
KH
11053 (vhdl-forward-syntactic-ws)
11054 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11055 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11056 ;; parse inline comment
11057 (unless comment
11058 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11059 (match-string-no-properties 1))))
5eabfe72 11060 ;; save everything in list
3dcb36b7
JB
11061 (setq generic-list (append generic-list
11062 (list (list names type init
11063 comment group-comment))))
11064 ;; parse group comment and spacing
11065 (setq group-comment (vhdl-parse-group-comment))))
5eabfe72
KH
11066 ;; parse port clause
11067 (when (vhdl-parse-string "port[ \t\n]*(" t)
3dcb36b7
JB
11068 ;; parse group comment and spacing
11069 (setq group-comment (vhdl-parse-group-comment))
11070 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
11071 (while (not end-of-list)
11072 ;; parse object
11073 (setq object
0a2e512a 11074 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
3dcb36b7
JB
11075 (match-string-no-properties 1)))
11076 ;; parse names (accept extended identifiers)
11077 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11078 (setq names (list (match-string-no-properties 1)))
11079 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11080 (setq names (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
11081 ;; parse direction
11082 (vhdl-parse-string ":[ \t\n]*")
11083 (setq direct
0a2e512a 11084 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
3dcb36b7 11085 (match-string-no-properties 1)))
5eabfe72
KH
11086 ;; parse type
11087 (vhdl-parse-string "\\([^();\n]+\\)")
3dcb36b7 11088 (setq type (match-string-no-properties 1))
5eabfe72
KH
11089 (setq comment nil)
11090 (while (looking-at "(")
11091 (setq type (concat type
3dcb36b7 11092 (buffer-substring-no-properties
5eabfe72
KH
11093 (point) (progn (forward-sexp) (point)))
11094 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 11095 (match-string-no-properties 1)))))
5eabfe72 11096 ;; special case: closing parenthesis is on separate line
3dcb36b7 11097 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
5eabfe72
KH
11098 (setq comment (substring type (match-beginning 2)))
11099 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 11100 ;; strip of trailing group-comment
5eabfe72
KH
11101 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11102 (setq type (substring type 0 (match-end 1)))
11103 (vhdl-forward-syntactic-ws)
11104 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11105 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11106 ;; parse inline comment
11107 (unless comment
11108 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11109 (match-string-no-properties 1))))
5eabfe72 11110 ;; save everything in list
3dcb36b7
JB
11111 (setq port-list (append port-list
11112 (list (list names object direct type
11113 comment group-comment))))
11114 ;; parse group comment and spacing
11115 (setq group-comment (vhdl-parse-group-comment))))
11116; (vhdl-parse-string "end\\>")
11117 ;; parse context clause
11118 (setq context-clause (vhdl-scan-context-clause))
11119; ;; add surrounding package to context clause
11120; (when (and (equal decl-type "component")
11121; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11122; (setq context-clause
11123; (append context-clause
11124; (list (cons (vhdl-work-library)
11125; (match-string-no-properties 1))))))
11126 (message "Reading port of %s \"%s\"...done" decl-type name)
5eabfe72
KH
11127 nil)))
11128 ;; finish parsing
11129 (if parse-error
11130 (error parse-error)
3dcb36b7
JB
11131 (setq vhdl-port-list (list name generic-list port-list context-clause)
11132 vhdl-port-reversed-direction nil
11133 vhdl-port-flattened nil)))))
11134
11135(defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11136 "Paste a context clause."
11137 (let ((margin (current-indentation))
11138 (clause-list (nth 3 vhdl-port-list))
11139 clause)
11140 (while clause-list
11141 (setq clause (car clause-list))
11142 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11143 (downcase exclude-pack-name)))
11144 (save-excursion
11145 (re-search-backward
11146 (concat "^\\s-*use\\s-+" (car clause)
11147 "\." (cdr clause) "\\>") nil t)))
11148 (vhdl-template-standard-package (car clause) (cdr clause))
11149 (insert "\n"))
11150 (setq clause-list (cdr clause-list)))))
5eabfe72
KH
11151
11152(defun vhdl-port-paste-generic (&optional no-init)
11153 "Paste a generic clause."
11154 (let ((margin (current-indentation))
3dcb36b7
JB
11155 (generic-list (nth 1 vhdl-port-list))
11156 list-margin start names generic)
5eabfe72 11157 ;; paste generic clause
3dcb36b7 11158 (when generic-list
5eabfe72
KH
11159 (setq start (point))
11160 (vhdl-insert-keyword "GENERIC (")
11161 (unless vhdl-argument-list-indent
11162 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11163 (setq list-margin (current-column))
3dcb36b7
JB
11164 (while generic-list
11165 (setq generic (car generic-list))
11166 ;; paste group comment and spacing
11167 (when (memq vhdl-include-group-comments '(decl always))
11168 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72 11169 ;; paste names
5eabfe72
KH
11170 (setq names (nth 0 generic))
11171 (while names
11172 (insert (car names))
11173 (setq names (cdr names))
11174 (when names (insert ", ")))
11175 ;; paste type
11176 (insert " : " (nth 1 generic))
11177 ;; paste initialization
11178 (when (and (not no-init) (nth 2 generic))
11179 (insert " := " (nth 2 generic)))
3dcb36b7 11180 (unless (cdr generic-list) (insert ")"))
5eabfe72
KH
11181 (insert ";")
11182 ;; paste comment
11183 (when (and vhdl-include-port-comments (nth 3 generic))
11184 (vhdl-comment-insert-inline (nth 3 generic) t))
3dcb36b7
JB
11185 (setq generic-list (cdr generic-list))
11186 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72 11187 ;; align generic clause
3dcb36b7 11188 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
5eabfe72
KH
11189
11190(defun vhdl-port-paste-port ()
11191 "Paste a port clause."
11192 (let ((margin (current-indentation))
3dcb36b7
JB
11193 (port-list (nth 2 vhdl-port-list))
11194 list-margin start names port)
5eabfe72 11195 ;; paste port clause
3dcb36b7 11196 (when port-list
5eabfe72
KH
11197 (setq start (point))
11198 (vhdl-insert-keyword "PORT (")
11199 (unless vhdl-argument-list-indent
11200 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11201 (setq list-margin (current-column))
3dcb36b7
JB
11202 (while port-list
11203 (setq port (car port-list))
11204 ;; paste group comment and spacing
11205 (when (memq vhdl-include-group-comments '(decl always))
11206 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11207 ;; paste object
11208 (when (nth 1 port) (insert (nth 1 port) " "))
11209 ;; paste names
11210 (setq names (nth 0 port))
11211 (while names
11212 (insert (car names))
11213 (setq names (cdr names))
11214 (when names (insert ", ")))
11215 ;; paste direction
11216 (insert " : ")
11217 (when (nth 2 port) (insert (nth 2 port) " "))
11218 ;; paste type
11219 (insert (nth 3 port))
3dcb36b7 11220 (unless (cdr port-list) (insert ")"))
5eabfe72
KH
11221 (insert ";")
11222 ;; paste comment
11223 (when (and vhdl-include-port-comments (nth 4 port))
11224 (vhdl-comment-insert-inline (nth 4 port) t))
3dcb36b7
JB
11225 (setq port-list (cdr port-list))
11226 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72 11227 ;; align port clause
3dcb36b7 11228 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
5eabfe72 11229
3dcb36b7 11230(defun vhdl-port-paste-declaration (kind &optional no-indent)
5eabfe72 11231 "Paste as an entity or component declaration."
3dcb36b7 11232 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11233 (let ((margin (current-indentation))
11234 (name (nth 0 vhdl-port-list)))
11235 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11236 (insert name)
3dcb36b7
JB
11237 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11238 (vhdl-insert-keyword " IS"))
11239 ;; paste generic and port clause
5eabfe72
KH
11240 (when (nth 1 vhdl-port-list)
11241 (insert "\n")
11242 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11243 (insert "\n"))
11244 (indent-to (+ margin vhdl-basic-offset))
11245 (vhdl-port-paste-generic (eq kind 'component)))
11246 (when (nth 2 vhdl-port-list)
11247 (insert "\n")
11248 (when (and (memq vhdl-insert-empty-lines '(unit all))
11249 (eq kind 'entity))
11250 (insert "\n"))
11251 (indent-to (+ margin vhdl-basic-offset)))
11252 (vhdl-port-paste-port)
11253 (insert "\n")
11254 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11255 (insert "\n"))
11256 (indent-to margin)
11257 (vhdl-insert-keyword "END")
11258 (if (eq kind 'entity)
11259 (progn
11260 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11261 (insert " " name))
11262 (vhdl-insert-keyword " COMPONENT")
11263 (unless (vhdl-standard-p '87) (insert " " name)))
11264 (insert ";")))
11265
3dcb36b7 11266(defun vhdl-port-paste-entity (&optional no-indent)
5eabfe72
KH
11267 "Paste as an entity declaration."
11268 (interactive)
11269 (if (not vhdl-port-list)
3dcb36b7
JB
11270 (error "ERROR: No port read")
11271 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11272 (vhdl-port-paste-declaration 'entity no-indent)
11273 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
5eabfe72 11274
3dcb36b7 11275(defun vhdl-port-paste-component (&optional no-indent)
5eabfe72
KH
11276 "Paste as a component declaration."
11277 (interactive)
11278 (if (not vhdl-port-list)
3dcb36b7
JB
11279 (error "ERROR: No port read")
11280 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11281 (vhdl-port-paste-declaration 'component no-indent)
11282 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
5eabfe72
KH
11283
11284(defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11285 "Paste as a generic map."
11286 (interactive)
3dcb36b7 11287 (unless secondary (indent-according-to-mode))
5eabfe72
KH
11288 (let ((margin (current-indentation))
11289 list-margin start generic
3dcb36b7
JB
11290 (generic-list (nth 1 vhdl-port-list)))
11291 (when generic-list
5eabfe72
KH
11292 (setq start (point))
11293 (vhdl-insert-keyword "GENERIC MAP (")
11294 (if (not vhdl-association-list-with-formals)
11295 ;; paste list of actual generics
3dcb36b7
JB
11296 (while generic-list
11297 (insert (if no-constants
11298 (car (nth 0 (car generic-list)))
11299 (or (nth 2 (car generic-list)) " ")))
11300 (setq generic-list (cdr generic-list))
0a2e512a
RF
11301 (insert (if generic-list ", " ")"))
11302 (when (and (not generic-list) secondary
11303 (null (nth 2 vhdl-port-list)))
11304 (insert ";")))
5eabfe72 11305 (unless vhdl-argument-list-indent
3dcb36b7 11306 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11307 (setq list-margin (current-column))
3dcb36b7
JB
11308 (while generic-list
11309 (setq generic (car generic-list))
11310 ;; paste group comment and spacing
11311 (when (eq vhdl-include-group-comments 'always)
11312 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72
KH
11313 ;; paste formal and actual generic
11314 (insert (car (nth 0 generic)) " => "
11315 (if no-constants
11316 (car (nth 0 generic))
11317 (or (nth 2 generic) "")))
3dcb36b7
JB
11318 (setq generic-list (cdr generic-list))
11319 (insert (if generic-list "," ")"))
0a2e512a
RF
11320 (when (and (not generic-list) secondary
11321 (null (nth 2 vhdl-port-list)))
11322 (insert ";"))
5eabfe72 11323 ;; paste comment
3dcb36b7
JB
11324 (when (or vhdl-include-type-comments
11325 (and vhdl-include-port-comments (nth 3 generic)))
11326 (vhdl-comment-insert-inline
11327 (concat
11328 (when vhdl-include-type-comments
11329 (concat "[" (nth 1 generic) "] "))
11330 (when vhdl-include-port-comments (nth 3 generic))) t))
11331 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11332 ;; align generic map
11333 (when vhdl-auto-align
3dcb36b7 11334 (vhdl-align-region-groups start (point) 1 t))))))
5eabfe72
KH
11335
11336(defun vhdl-port-paste-port-map ()
11337 "Paste as a port map."
11338 (let ((margin (current-indentation))
11339 list-margin start port
3dcb36b7
JB
11340 (port-list (nth 2 vhdl-port-list)))
11341 (when port-list
5eabfe72
KH
11342 (setq start (point))
11343 (vhdl-insert-keyword "PORT MAP (")
11344 (if (not vhdl-association-list-with-formals)
11345 ;; paste list of actual ports
3dcb36b7 11346 (while port-list
5eabfe72 11347 (insert (vhdl-replace-string vhdl-actual-port-name
3dcb36b7
JB
11348 (car (nth 0 (car port-list)))))
11349 (setq port-list (cdr port-list))
0a2e512a 11350 (insert (if port-list ", " ")")))
5eabfe72 11351 (unless vhdl-argument-list-indent
3dcb36b7 11352 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11353 (setq list-margin (current-column))
3dcb36b7
JB
11354 (while port-list
11355 (setq port (car port-list))
11356 ;; paste group comment and spacing
11357 (when (eq vhdl-include-group-comments 'always)
11358 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11359 ;; paste formal and actual port
11360 (insert (car (nth 0 port)) " => ")
11361 (insert (vhdl-replace-string vhdl-actual-port-name
11362 (car (nth 0 port))))
3dcb36b7
JB
11363 (setq port-list (cdr port-list))
11364 (insert (if port-list "," ");"))
5eabfe72
KH
11365 ;; paste comment
11366 (when (or vhdl-include-direction-comments
3dcb36b7 11367 vhdl-include-type-comments
5eabfe72
KH
11368 (and vhdl-include-port-comments (nth 4 port)))
11369 (vhdl-comment-insert-inline
11370 (concat
3dcb36b7
JB
11371 (cond ((and vhdl-include-direction-comments
11372 vhdl-include-type-comments)
11373 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11374 (nth 3 port) "] "))
11375 ((and vhdl-include-direction-comments (nth 2 port))
11376 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11377 (vhdl-include-direction-comments " ")
11378 (vhdl-include-type-comments
11379 (concat "[" (nth 3 port) "] ")))
11380 (when vhdl-include-port-comments (nth 4 port))) t))
11381 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11382 ;; align port clause
11383 (when vhdl-auto-align
3dcb36b7 11384 (vhdl-align-region-groups start (point) 1))))))
5eabfe72 11385
3dcb36b7 11386(defun vhdl-port-paste-instance (&optional name no-indent title)
5eabfe72
KH
11387 "Paste as an instantiation."
11388 (interactive)
11389 (if (not vhdl-port-list)
3dcb36b7 11390 (error "ERROR: No port read")
5eabfe72
KH
11391 (let ((orig-vhdl-port-list vhdl-port-list))
11392 ;; flatten local copy of port list (must be flat for port mapping)
11393 (vhdl-port-flatten)
3dcb36b7
JB
11394 (unless no-indent (indent-according-to-mode))
11395 (let ((margin (current-indentation)))
5eabfe72 11396 ;; paste instantiation
3dcb36b7
JB
11397 (cond (name
11398 (insert name))
11399 ((equal (cdr vhdl-instance-name) "")
11400 (setq name (vhdl-template-field "instance name")))
11401 ((string-match "\%d" (cdr vhdl-instance-name))
11402 (let ((n 1))
11403 (while (save-excursion
11404 (setq name (format (vhdl-replace-string
11405 vhdl-instance-name
11406 (nth 0 vhdl-port-list)) n))
11407 (goto-char (point-min))
11408 (vhdl-re-search-forward name nil t))
11409 (setq n (1+ n)))
11410 (insert name)))
11411 (t (insert (vhdl-replace-string vhdl-instance-name
11412 (nth 0 vhdl-port-list)))))
11413 (message "Pasting port as instantiation \"%s\"..." name)
11414 (insert ": ")
11415 (when title
11416 (save-excursion
11417 (beginning-of-line)
11418 (indent-to vhdl-basic-offset)
11419 (insert "-- instance \"" name "\"\n")))
11420 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
11421 (insert (nth 0 vhdl-port-list))
11422 (vhdl-insert-keyword "ENTITY ")
3dcb36b7 11423 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
5eabfe72
KH
11424 (when (nth 1 vhdl-port-list)
11425 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11426 (vhdl-port-paste-generic-map t t))
11427 (when (nth 2 vhdl-port-list)
11428 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11429 (vhdl-port-paste-port-map))
0a2e512a
RF
11430 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11431 (insert ";"))
3dcb36b7
JB
11432 (message "Pasting port as instantiation \"%s\"...done" name))
11433 (setq vhdl-port-list orig-vhdl-port-list))))
11434
11435(defun vhdl-port-paste-constants (&optional no-indent)
11436 "Paste generics as constants."
11437 (interactive)
11438 (if (not vhdl-port-list)
11439 (error "ERROR: No port read")
11440 (let ((orig-vhdl-port-list vhdl-port-list))
11441 (message "Pasting port as constants...")
11442 ;; flatten local copy of port list (must be flat for constant initial.)
11443 (vhdl-port-flatten)
11444 (unless no-indent (indent-according-to-mode))
11445 (let ((margin (current-indentation))
11446 start generic name
11447 (generic-list (nth 1 vhdl-port-list)))
11448 (when generic-list
11449 (setq start (point))
11450 (while generic-list
11451 (setq generic (car generic-list))
11452 ;; paste group comment and spacing
11453 (when (memq vhdl-include-group-comments '(decl always))
11454 (vhdl-paste-group-comment (nth 4 generic) margin))
11455 (vhdl-insert-keyword "CONSTANT ")
11456 ;; paste generic constants
11457 (setq name (nth 0 generic))
11458 (when name
11459 (insert (car name))
11460 ;; paste type
11461 (insert " : " (nth 1 generic))
11462 ;; paste initialization
11463 (when (nth 2 generic)
11464 (insert " := " (nth 2 generic)))
11465 (insert ";")
11466 ;; paste comment
11467 (when (and vhdl-include-port-comments (nth 3 generic))
11468 (vhdl-comment-insert-inline (nth 3 generic) t))
11469 (setq generic-list (cdr generic-list))
11470 (when generic-list (insert "\n") (indent-to margin))))
11471 ;; align signal list
11472 (when vhdl-auto-align
11473 (vhdl-align-region-groups start (point) 1))))
11474 (message "Pasting port as constants...done")
5eabfe72
KH
11475 (setq vhdl-port-list orig-vhdl-port-list))))
11476
3dcb36b7 11477(defun vhdl-port-paste-signals (&optional initialize no-indent)
5eabfe72
KH
11478 "Paste ports as internal signals."
11479 (interactive)
11480 (if (not vhdl-port-list)
3dcb36b7 11481 (error "ERROR: No port read")
5eabfe72 11482 (message "Pasting port as signals...")
3dcb36b7 11483 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11484 (let ((margin (current-indentation))
11485 start port names
3dcb36b7
JB
11486 (port-list (nth 2 vhdl-port-list)))
11487 (when port-list
5eabfe72 11488 (setq start (point))
3dcb36b7
JB
11489 (while port-list
11490 (setq port (car port-list))
11491 ;; paste group comment and spacing
11492 (when (memq vhdl-include-group-comments '(decl always))
11493 (vhdl-paste-group-comment (nth 5 port) margin))
5eabfe72
KH
11494 ;; paste object
11495 (if (nth 1 port)
11496 (insert (nth 1 port) " ")
11497 (vhdl-insert-keyword "SIGNAL "))
11498 ;; paste actual port signals
11499 (setq names (nth 0 port))
11500 (while names
11501 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11502 (setq names (cdr names))
11503 (when names (insert ", ")))
11504 ;; paste type
11505 (insert " : " (nth 3 port))
11506 ;; paste initialization (inputs only)
3dcb36b7
JB
11507 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11508 (insert " := " (if (string-match "(.+)" (nth 3 port))
11509 "(others => '0')" "'0'")))
5eabfe72
KH
11510 (insert ";")
11511 ;; paste comment
3dcb36b7
JB
11512 (when (or vhdl-include-direction-comments
11513 (and vhdl-include-port-comments (nth 4 port)))
11514 (vhdl-comment-insert-inline
11515 (concat
11516 (cond ((and vhdl-include-direction-comments (nth 2 port))
11517 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11518 (vhdl-include-direction-comments " "))
11519 (when vhdl-include-port-comments (nth 4 port))) t))
11520 (setq port-list (cdr port-list))
11521 (when port-list (insert "\n") (indent-to margin)))
5eabfe72 11522 ;; align signal list
3dcb36b7 11523 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
5eabfe72
KH
11524 (message "Pasting port as signals...done")))
11525
3dcb36b7
JB
11526(defun vhdl-port-paste-initializations (&optional no-indent)
11527 "Paste ports as signal initializations."
5eabfe72
KH
11528 (interactive)
11529 (if (not vhdl-port-list)
3dcb36b7 11530 (error "ERROR: No port read")
5eabfe72 11531 (let ((orig-vhdl-port-list vhdl-port-list))
3dcb36b7
JB
11532 (message "Pasting port as initializations...")
11533 ;; flatten local copy of port list (must be flat for signal initial.)
5eabfe72 11534 (vhdl-port-flatten)
3dcb36b7 11535 (unless no-indent (indent-according-to-mode))
5eabfe72 11536 (let ((margin (current-indentation))
3dcb36b7
JB
11537 start port name
11538 (port-list (nth 2 vhdl-port-list)))
11539 (when port-list
5eabfe72 11540 (setq start (point))
3dcb36b7
JB
11541 (while port-list
11542 (setq port (car port-list))
11543 ;; paste actual port signal (inputs only)
11544 (when (equal "IN" (upcase (nth 2 port)))
11545 (setq name (car (nth 0 port)))
11546 (insert (vhdl-replace-string vhdl-actual-port-name name))
5eabfe72 11547 ;; paste initialization
3dcb36b7
JB
11548 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11549 "(others => '0')" "'0'") ";"))
11550 (setq port-list (cdr port-list))
11551 (when (and port-list
11552 (equal "IN" (upcase (nth 2 (car port-list)))))
11553 (insert "\n") (indent-to margin)))
11554 ;; align signal list
11555 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11556 (message "Pasting port as initializations...done")
5eabfe72
KH
11557 (setq vhdl-port-list orig-vhdl-port-list))))
11558
11559(defun vhdl-port-paste-testbench ()
3dcb36b7 11560 "Paste as a bare-bones testbench."
5eabfe72
KH
11561 (interactive)
11562 (if (not vhdl-port-list)
3dcb36b7 11563 (error "ERROR: No port read")
5eabfe72
KH
11564 (let ((case-fold-search t)
11565 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11566 (nth 0 vhdl-port-list)))
11567 (source-buffer (current-buffer))
3dcb36b7
JB
11568 arch-name config-name ent-file-name arch-file-name
11569 ent-buffer arch-buffer position)
5eabfe72 11570 ;; open entity file
3dcb36b7 11571 (unless (eq vhdl-testbench-create-files 'none)
5eabfe72 11572 (setq ent-file-name
0a2e512a
RF
11573 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11574 ent-name t)
11575 "." (file-name-extension (buffer-file-name))))
3dcb36b7 11576 (if (file-exists-p ent-file-name)
5eabfe72 11577 (if (y-or-n-p
3dcb36b7
JB
11578 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11579 (progn (find-file ent-file-name)
11580 (erase-buffer)
11581 (set-buffer-modified-p nil))
11582 (if (eq vhdl-testbench-create-files 'separate)
11583 (setq ent-file-name nil)
11584 (error "ERROR: Pasting port as testbench...aborted")))
11585 (find-file ent-file-name)))
11586 (unless (and (eq vhdl-testbench-create-files 'separate)
11587 (null ent-file-name))
11588 ;; paste entity header
11589 (if vhdl-testbench-include-header
11590 (progn (vhdl-template-header
11591 (concat "Testbench for design \""
11592 (nth 0 vhdl-port-list) "\""))
11593 (goto-char (point-max)))
11594 (vhdl-comment-display-line) (insert "\n\n"))
11595 ;; paste std_logic_1164 package
11596 (when vhdl-testbench-include-library
11597 (vhdl-template-package-std-logic-1164)
11598 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11599 ;; paste entity declaration
11600 (vhdl-insert-keyword "ENTITY ")
5eabfe72
KH
11601 (insert ent-name)
11602 (vhdl-insert-keyword " IS")
3dcb36b7 11603 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
5eabfe72 11604 (insert "\n")
3dcb36b7
JB
11605 (vhdl-insert-keyword "END ")
11606 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11607 (insert ent-name ";")
11608 (insert "\n\n")
11609 (vhdl-comment-display-line) (insert "\n"))
11610 ;; get architecture name
11611 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11612 (read-from-minibuffer "architecture name: "
11613 nil vhdl-minibuffer-local-map)
11614 (vhdl-replace-string vhdl-testbench-architecture-name
11615 (nth 0 vhdl-port-list))))
11616 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11617 ;; open architecture file
11618 (if (not (eq vhdl-testbench-create-files 'separate))
5eabfe72 11619 (insert "\n")
3dcb36b7
JB
11620 (setq ent-buffer (current-buffer))
11621 (setq arch-file-name
0a2e512a
RF
11622 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11623 (concat ent-name " " arch-name) t)
11624 "." (file-name-extension (buffer-file-name))))
3dcb36b7
JB
11625 (when (and (file-exists-p arch-file-name)
11626 (not (y-or-n-p (concat "File \"" arch-file-name
11627 "\" exists; overwrite? "))))
11628 (error "ERROR: Pasting port as testbench...aborted"))
11629 (find-file arch-file-name)
11630 (erase-buffer)
11631 (set-buffer-modified-p nil)
11632 ;; paste architecture header
11633 (if vhdl-testbench-include-header
11634 (progn (vhdl-template-header
11635 (concat "Testbench architecture for design \""
11636 (nth 0 vhdl-port-list) "\""))
11637 (goto-char (point-max)))
11638 (vhdl-comment-display-line) (insert "\n\n")))
11639 ;; paste architecture body
11640 (vhdl-insert-keyword "ARCHITECTURE ")
11641 (insert arch-name)
11642 (vhdl-insert-keyword " OF ")
11643 (insert ent-name)
11644 (vhdl-insert-keyword " IS")
11645 (insert "\n\n") (indent-to vhdl-basic-offset)
11646 ;; paste component declaration
11647 (unless (vhdl-use-direct-instantiation)
11648 (vhdl-port-paste-component t)
11649 (insert "\n\n") (indent-to vhdl-basic-offset))
11650 ;; paste constants
11651 (when (nth 1 vhdl-port-list)
11652 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11653 (vhdl-port-paste-constants t)
11654 (insert "\n\n") (indent-to vhdl-basic-offset))
11655 ;; paste internal signals
11656 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11657 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11658 (insert "\n")
11659 ;; paste custom declarations
11660 (unless (equal "" vhdl-testbench-declarations)
5eabfe72 11661 (insert "\n")
3dcb36b7
JB
11662 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11663 (setq position (point))
11664 (insert "\n\n")
11665 (vhdl-comment-display-line) (insert "\n")
11666 (when vhdl-testbench-include-configuration
11667 (setq config-name (vhdl-replace-string
11668 vhdl-testbench-configuration-name
11669 (concat ent-name " " arch-name)))
11670 (insert "\n")
11671 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11672 (vhdl-insert-keyword " OF ") (insert ent-name)
11673 (vhdl-insert-keyword " IS\n")
11674 (indent-to vhdl-basic-offset)
11675 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11676 (indent-to vhdl-basic-offset)
11677 (vhdl-insert-keyword "END FOR;\n")
11678 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11679 (vhdl-comment-display-line) (insert "\n"))
11680 (goto-char position)
11681 (vhdl-template-begin-end
11682 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11683 ;; paste instantiation
11684 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11685 (vhdl-port-paste-instance
11686 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11687 (insert "\n")
11688 ;; paste custom statements
11689 (unless (equal "" vhdl-testbench-statements)
11690 (insert "\n")
11691 (vhdl-insert-string-or-file vhdl-testbench-statements))
11692 (insert "\n")
11693 (indent-to vhdl-basic-offset)
11694 (unless (eq vhdl-testbench-create-files 'none)
11695 (setq arch-buffer (current-buffer))
11696 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11697 (set-buffer arch-buffer) (save-buffer))
29a4e67d 11698 (message "%s"
3dcb36b7
JB
11699 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11700 ent-name arch-name)
11701 (and ent-file-name
11702 (format "\n File created: \"%s\"" ent-file-name))
11703 (and arch-file-name
11704 (format "\n File created: \"%s\"" arch-file-name)))))))
5eabfe72
KH
11705
11706
11707;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11708;;; Subprogram interface translation
5eabfe72
KH
11709;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11710
3dcb36b7
JB
11711(defvar vhdl-subprog-list nil
11712 "Variable to hold last subprogram interface parsed.")
11713;; structure: (parenthesised expression means list of such entries)
11714;; (subprog-name kind
11715;; ((names) object direct type init comment group-comment)
11716;; return-type return-comment group-comment)
5eabfe72 11717
3dcb36b7
JB
11718(defvar vhdl-subprog-flattened nil
11719 "Indicates whether an subprogram interface has been flattened.")
5eabfe72 11720
3dcb36b7
JB
11721(defun vhdl-subprog-flatten ()
11722 "Flatten interface list so that only one parameter exists per line."
11723 (interactive)
11724 (if (not vhdl-subprog-list)
11725 (error "ERROR: No subprogram interface has been read")
11726 (message "Flattening subprogram interface...")
11727 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11728 new-subprog-list old-subprog new-subprog names)
11729 ;; traverse parameter list and flatten entries
11730 (while old-subprog-list
11731 (setq old-subprog (car old-subprog-list))
11732 (setq names (car old-subprog))
11733 (while names
11734 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11735 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11736 (setq names (cdr names)))
11737 (setq old-subprog-list (cdr old-subprog-list)))
11738 (setq vhdl-subprog-list
11739 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11740 new-subprog-list (nth 3 vhdl-subprog-list)
11741 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11742 vhdl-subprog-flattened t)
11743 (message "Flattening subprogram interface...done"))))
11744
11745(defun vhdl-subprog-copy ()
11746 "Get interface information from a subprogram specification."
11747 (interactive)
11748 (save-excursion
11749 (let (parse-error pos end-of-list
11750 name kind param-list object names direct type init
11751 comment group-comment
11752 return-type return-comment return-group-comment)
11753 (vhdl-prepare-search-2
11754 (setq
11755 parse-error
11756 (catch 'parse
11757 ;; check if within function declaration
11758 (setq pos (point))
11759 (end-of-line)
11760 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11761 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11762 (goto-char (match-end 0))
11763 (save-excursion (backward-char)
11764 (forward-sexp)
11765 (<= pos (point))))
11766 (throw 'parse "ERROR: Not within a subprogram specification"))
11767 (setq name (match-string-no-properties 5))
11768 (setq kind (if (match-string 2) 'procedure 'function))
11769 (setq end-of-list (not (match-string 7)))
11770 (message "Reading interface of subprogram \"%s\"..." name)
11771 ;; parse parameter list
11772 (setq group-comment (vhdl-parse-group-comment))
11773 (setq end-of-list (or end-of-list
11774 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11775 (while (not end-of-list)
11776 ;; parse object
11777 (setq object
11778 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11779 (match-string-no-properties 1)))
11780 ;; parse names (accept extended identifiers)
11781 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11782 (setq names (list (match-string-no-properties 1)))
11783 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11784 (setq names (append names (list (match-string-no-properties 1)))))
11785 ;; parse direction
11786 (vhdl-parse-string ":[ \t\n]*")
11787 (setq direct
11788 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11789 (match-string-no-properties 1)))
11790 ;; parse type
11791 (vhdl-parse-string "\\([^():;\n]+\\)")
11792 (setq type (match-string-no-properties 1))
11793 (setq comment nil)
11794 (while (looking-at "(")
11795 (setq type
11796 (concat type
11797 (buffer-substring-no-properties
11798 (point) (progn (forward-sexp) (point)))
11799 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11800 (match-string-no-properties 1)))))
11801 ;; special case: closing parenthesis is on separate line
11802 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11803 (setq comment (substring type (match-beginning 2)))
11804 (setq type (substring type 0 (match-beginning 1))))
11805 ;; strip off trailing group-comment
11806 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11807 (setq type (substring type 0 (match-end 1)))
11808 ;; parse initialization expression
11809 (setq init nil)
11810 (when (vhdl-parse-string ":=[ \t\n]*" t)
11811 (vhdl-parse-string "\\([^();\n]*\\)")
11812 (setq init (match-string-no-properties 1))
11813 (while (looking-at "(")
11814 (setq init
11815 (concat init
11816 (buffer-substring-no-properties
11817 (point) (progn (forward-sexp) (point)))
11818 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11819 (match-string-no-properties 1))))))
11820 ;; special case: closing parenthesis is on separate line
11821 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11822 (setq comment (substring init (match-beginning 2)))
11823 (setq init (substring init 0 (match-beginning 1)))
11824 (vhdl-forward-syntactic-ws))
11825 (skip-chars-forward " \t")
11826 ;; parse inline comment, special case: as above, no initial.
11827 (unless comment
11828 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11829 (match-string-no-properties 1))))
11830 (vhdl-forward-syntactic-ws)
11831 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11832 ;; parse inline comment
11833 (unless comment
11834 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11835 (match-string-no-properties 1))))
11836 (setq return-group-comment (vhdl-parse-group-comment))
11837 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11838 ;; parse return type
11839 (when (match-string 3)
11840 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11841 (setq return-type (match-string-no-properties 1))
11842 (when (and return-type
11843 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11844 (setq return-comment (substring return-type (match-beginning 2)))
11845 (setq return-type (substring return-type 0 (match-beginning 1))))
11846 ;; strip of trailing group-comment
11847 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11848 (setq return-type (substring return-type 0 (match-end 1)))
11849 ;; parse return comment
11850 (unless return-comment
11851 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11852 (match-string-no-properties 1)))))
11853 ;; parse inline comment
11854 (unless comment
11855 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11856 (match-string-no-properties 1))))
11857 ;; save everything in list
11858 (setq param-list (append param-list
11859 (list (list names object direct type init
11860 comment group-comment))))
11861 ;; parse group comment and spacing
11862 (setq group-comment (vhdl-parse-group-comment)))
11863 (message "Reading interface of subprogram \"%s\"...done" name)
11864 nil)))
11865 ;; finish parsing
11866 (if parse-error
11867 (error parse-error)
11868 (setq vhdl-subprog-list
11869 (list name kind param-list return-type return-comment
11870 return-group-comment)
11871 vhdl-subprog-flattened nil)))))
11872
11873(defun vhdl-subprog-paste-specification (kind)
11874 "Paste as a subprogram specification."
11875 (indent-according-to-mode)
11876 (let ((margin (current-column))
11877 (param-list (nth 2 vhdl-subprog-list))
11878 list-margin start names param)
11879 ;; paste keyword and name
11880 (vhdl-insert-keyword
11881 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11882 (insert (nth 0 vhdl-subprog-list))
11883 (if (not param-list)
11884 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11885 (setq start (point))
11886 ;; paste parameter list
11887 (insert " (")
11888 (unless vhdl-argument-list-indent
11889 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11890 (setq list-margin (current-column))
11891 (while param-list
11892 (setq param (car param-list))
11893 ;; paste group comment and spacing
11894 (when (memq vhdl-include-group-comments (list kind 'always))
11895 (vhdl-paste-group-comment (nth 6 param) list-margin))
11896 ;; paste object
11897 (when (nth 1 param) (insert (nth 1 param) " "))
11898 ;; paste names
11899 (setq names (nth 0 param))
11900 (while names
11901 (insert (car names))
11902 (setq names (cdr names))
11903 (when names (insert ", ")))
11904 ;; paste direction
11905 (insert " : ")
11906 (when (nth 2 param) (insert (nth 2 param) " "))
11907 ;; paste type
11908 (insert (nth 3 param))
11909 ;; paste initialization
11910 (when (nth 4 param) (insert " := " (nth 4 param)))
11911 ;; terminate line
11912 (if (cdr param-list)
11913 (insert ";")
11914 (insert ")")
11915 (when (null (nth 3 vhdl-subprog-list))
11916 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11917 ;; paste comment
11918 (when (and vhdl-include-port-comments (nth 5 param))
11919 (vhdl-comment-insert-inline (nth 5 param) t))
11920 (setq param-list (cdr param-list))
11921 (when param-list (insert "\n") (indent-to list-margin)))
11922 (when (nth 3 vhdl-subprog-list)
11923 (insert "\n") (indent-to list-margin)
11924 ;; paste group comment and spacing
11925 (when (memq vhdl-include-group-comments (list kind 'always))
11926 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11927 ;; paste return type
11928 (insert "return " (nth 3 vhdl-subprog-list))
0a2e512a 11929 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
3dcb36b7
JB
11930 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11931 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11932 ;; align parameter list
11933 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11934 ;; paste body
11935 (when (eq kind 'body)
11936 (insert "\n")
11937 (vhdl-template-begin-end
11938 (unless (vhdl-standard-p '87)
11939 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11940 (nth 0 vhdl-subprog-list) margin))))
11941
11942(defun vhdl-subprog-paste-declaration ()
11943 "Paste as a subprogram declaration."
11944 (interactive)
11945 (if (not vhdl-subprog-list)
11946 (error "ERROR: No subprogram interface read")
11947 (message "Pasting interface as subprogram declaration \"%s\"..."
11948 (car vhdl-subprog-list))
11949 ;; paste specification
11950 (vhdl-subprog-paste-specification 'decl)
11951 (message "Pasting interface as subprogram declaration \"%s\"...done"
11952 (car vhdl-subprog-list))))
11953
11954(defun vhdl-subprog-paste-body ()
11955 "Paste as a subprogram body."
11956 (interactive)
11957 (if (not vhdl-subprog-list)
11958 (error "ERROR: No subprogram interface read")
11959 (message "Pasting interface as subprogram body \"%s\"..."
11960 (car vhdl-subprog-list))
11961 ;; paste specification and body
11962 (vhdl-subprog-paste-specification 'body)
11963 (message "Pasting interface as subprogram body \"%s\"...done"
11964 (car vhdl-subprog-list))))
11965
11966(defun vhdl-subprog-paste-call ()
11967 "Paste as a subprogram call."
11968 (interactive)
11969 (if (not vhdl-subprog-list)
11970 (error "ERROR: No subprogram interface read")
11971 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11972 param-list margin list-margin param start)
11973 ;; flatten local copy of interface list (must be flat for parameter mapping)
11974 (vhdl-subprog-flatten)
11975 (setq param-list (nth 2 vhdl-subprog-list))
11976 (indent-according-to-mode)
11977 (setq margin (current-indentation))
11978 (message "Pasting interface as subprogram call \"%s\"..."
11979 (car vhdl-subprog-list))
11980 ;; paste name
11981 (insert (nth 0 vhdl-subprog-list))
11982 (if (not param-list)
11983 (insert ";")
11984 (setq start (point))
11985 ;; paste parameter list
11986 (insert " (")
11987 (unless vhdl-argument-list-indent
11988 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11989 (setq list-margin (current-column))
11990 (while param-list
11991 (setq param (car param-list))
11992 ;; paste group comment and spacing
11993 (when (eq vhdl-include-group-comments 'always)
11994 (vhdl-paste-group-comment (nth 6 param) list-margin))
11995 ;; paste formal port
11996 (insert (car (nth 0 param)) " => ")
11997 (setq param-list (cdr param-list))
11998 (insert (if param-list "," ");"))
11999 ;; paste comment
12000 (when (and vhdl-include-port-comments (nth 5 param))
12001 (vhdl-comment-insert-inline (nth 5 param)))
12002 (when param-list (insert "\n") (indent-to list-margin)))
12003 ;; align parameter list
12004 (when vhdl-auto-align
12005 (vhdl-align-region-groups start (point) 1)))
12006 (message "Pasting interface as subprogram call \"%s\"...done"
12007 (car vhdl-subprog-list))
12008 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12009
12010
12011;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12012;;; Miscellaneous
12013;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12014
12015;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12016;; Hippie expand customization
12017
12018(defvar vhdl-expand-upper-case nil)
12019
12020(defun vhdl-try-expand-abbrev (old)
12021 "Try expanding abbreviations from `vhdl-abbrev-list'."
12022 (unless old
12023 (he-init-string (he-dabbrev-beg) (point))
5eabfe72
KH
12024 (setq he-expand-list
12025 (let ((abbrev-list vhdl-abbrev-list)
12026 (sel-abbrev-list '()))
12027 (while abbrev-list
12028 (when (or (not (stringp (car abbrev-list)))
12029 (string-match
12030 (concat "^" he-search-string) (car abbrev-list)))
12031 (setq sel-abbrev-list
12032 (cons (car abbrev-list) sel-abbrev-list)))
12033 (setq abbrev-list (cdr abbrev-list)))
12034 (nreverse sel-abbrev-list))))
12035 (while (and he-expand-list
12036 (or (not (stringp (car he-expand-list)))
12037 (he-string-member (car he-expand-list) he-tried-table t)))
12038; (equal (car he-expand-list) he-search-string)))
12039 (unless (stringp (car he-expand-list))
12040 (setq vhdl-expand-upper-case (car he-expand-list)))
12041 (setq he-expand-list (cdr he-expand-list)))
12042 (if (null he-expand-list)
12043 (progn (when old (he-reset-string))
12044 nil)
12045 (he-substitute-string
12046 (if vhdl-expand-upper-case
12047 (upcase (car he-expand-list))
12048 (car he-expand-list))
12049 t)
12050 (setq he-expand-list (cdr he-expand-list))
12051 t))
12052
12053(defun vhdl-he-list-beg ()
12054 "Also looks at the word before `(' in order to better match parenthesized
12055expressions (e.g. for index ranges of types and signals)."
12056 (save-excursion
12057 (condition-case ()
12058 (progn (backward-up-list 1)
12059 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12060 (error ()))
12061 (point)))
12062
12063;; override `he-list-beg' from `hippie-exp'
12064(unless (and (boundp 'viper-mode) viper-mode)
5eabfe72
KH
12065 (defalias 'he-list-beg 'vhdl-he-list-beg))
12066
12067;; function for expanding abbrevs and dabbrevs
3dcb36b7 12068(defun vhdl-expand-abbrev (arg))
5eabfe72
KH
12069(fset 'vhdl-expand-abbrev (make-hippie-expand-function
12070 '(try-expand-dabbrev
12071 try-expand-dabbrev-all-buffers
12072 vhdl-try-expand-abbrev)))
12073
12074;; function for expanding parenthesis
3dcb36b7 12075(defun vhdl-expand-paren (arg))
5eabfe72
KH
12076(fset 'vhdl-expand-paren (make-hippie-expand-function
12077 '(try-expand-list
12078 try-expand-list-all-buffers)))
12079
12080;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12081;; Case fixing
d2ddb974
KH
12082
12083(defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12084 "Convert all words matching word-regexp in region to lower or upper case,
12085depending on parameter upper-case."
3dcb36b7 12086 (let ((case-replace nil)
5eabfe72 12087 (last-update 0))
3dcb36b7 12088 (vhdl-prepare-search-2
5eabfe72
KH
12089 (save-excursion
12090 (goto-char end)
12091 (setq end (point-marker))
12092 (goto-char beg)
12093 (while (re-search-forward word-regexp end t)
3dcb36b7 12094 (or (vhdl-in-literal)
5eabfe72
KH
12095 (if upper-case
12096 (upcase-word -1)
12097 (downcase-word -1)))
3dcb36b7 12098 (when (and count vhdl-progress-interval (not noninteractive)
5eabfe72
KH
12099 (< vhdl-progress-interval
12100 (- (nth 1 (current-time)) last-update)))
12101 (message "Fixing case... (%2d%s)"
12102 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12103 "%")
12104 (setq last-update (nth 1 (current-time)))))
3dcb36b7 12105 (goto-char end)))))
d2ddb974
KH
12106
12107(defun vhdl-fix-case-region (beg end &optional arg)
12108 "Convert all VHDL words in region to lower or upper case, depending on
3dcb36b7 12109options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974
KH
12110 (interactive "r\nP")
12111 (vhdl-fix-case-region-1
5eabfe72 12112 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
d2ddb974 12113 (vhdl-fix-case-region-1
5eabfe72 12114 beg end vhdl-upper-case-types vhdl-types-regexp 1)
d2ddb974 12115 (vhdl-fix-case-region-1
5eabfe72
KH
12116 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12117 (vhdl-fix-case-region-1
3dcb36b7
JB
12118 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12119 (when vhdl-progress-interval (message "Fixing case...done")))
d2ddb974 12120
5eabfe72
KH
12121(defun vhdl-fix-case-buffer ()
12122 "Convert all VHDL words in buffer to lower or upper case, depending on
3dcb36b7 12123options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974 12124 (interactive)
5eabfe72
KH
12125 (vhdl-fix-case-region (point-min) (point-max)))
12126
3dcb36b7
JB
12127(defun vhdl-fix-case-word (&optional arg)
12128 "Convert word after cursor to upper case if necessary."
12129 (interactive "p")
12130 (save-excursion
12131 (when arg (backward-word 1))
12132 (vhdl-prepare-search-1
12133 (when (and vhdl-upper-case-keywords
12134 (looking-at vhdl-keywords-regexp))
12135 (upcase-word 1))
12136 (when (and vhdl-upper-case-types
12137 (looking-at vhdl-types-regexp))
12138 (upcase-word 1))
12139 (when (and vhdl-upper-case-attributes
12140 (looking-at vhdl-attributes-regexp))
12141 (upcase-word 1))
12142 (when (and vhdl-upper-case-enum-values
12143 (looking-at vhdl-enum-values-regexp))
12144 (upcase-word 1)))))
12145
5eabfe72
KH
12146;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12147;; Line handling functions
d2ddb974
KH
12148
12149(defun vhdl-current-line ()
12150 "Return the line number of the line containing point."
12151 (save-restriction
12152 (widen)
0a2e512a
RF
12153 (save-excursion
12154 (beginning-of-line)
12155 (1+ (count-lines 1 (point))))))
d2ddb974 12156
5eabfe72 12157(defun vhdl-line-kill-entire (&optional arg)
d2ddb974 12158 "Delete entire line."
5eabfe72
KH
12159 (interactive "p")
12160 (beginning-of-line)
12161 (kill-line (or arg 1)))
12162
12163(defun vhdl-line-kill (&optional arg)
12164 "Kill current line."
12165 (interactive "p")
12166 (vhdl-line-kill-entire arg))
12167
12168(defun vhdl-line-copy (&optional arg)
12169 "Copy current line."
12170 (interactive "p")
12171 (save-excursion
12172 (beginning-of-line)
12173 (let ((position (point)))
12174 (forward-line (or arg 1))
12175 (copy-region-as-kill position (point)))))
12176
12177(defun vhdl-line-yank ()
12178 "Yank entire line."
d2ddb974 12179 (interactive)
5eabfe72
KH
12180 (beginning-of-line)
12181 (yank))
d2ddb974 12182
5eabfe72
KH
12183(defun vhdl-line-expand (&optional prefix-arg)
12184 "Hippie-expand current line."
12185 (interactive "P")
12186 (let ((case-fold-search t) (case-replace nil)
12187 (hippie-expand-try-functions-list
12188 '(try-expand-line try-expand-line-all-buffers)))
12189 (hippie-expand prefix-arg)))
12190
12191(defun vhdl-line-transpose-next (&optional arg)
12192 "Interchange this line with next line."
12193 (interactive "p")
12194 (forward-line 1)
12195 (transpose-lines (or arg 1))
12196 (forward-line -1))
12197
12198(defun vhdl-line-transpose-previous (&optional arg)
12199 "Interchange this line with previous line."
12200 (interactive "p")
12201 (forward-line 1)
12202 (transpose-lines (- 0 (or arg 0)))
12203 (forward-line -1))
12204
12205(defun vhdl-line-open ()
d2ddb974
KH
12206 "Open a new line and indent."
12207 (interactive)
5eabfe72
KH
12208 (end-of-line -0)
12209 (newline-and-indent))
d2ddb974 12210
3dcb36b7
JB
12211(defun vhdl-delete-indentation ()
12212 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12213it works within comments too."
12214 (interactive)
12215 (let ((fill-prefix "-- "))
12216 (delete-indentation)))
d2ddb974 12217
5eabfe72 12218;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12219;; Move functions
d2ddb974 12220
3dcb36b7
JB
12221(defun vhdl-forward-same-indent ()
12222 "Move forward to next line with same indent."
12223 (interactive)
12224 (let ((pos (point))
12225 (indent (current-indentation)))
12226 (beginning-of-line 2)
12227 (while (and (not (eobp))
12228 (or (looking-at "^\\s-*\\(--.*\\)?$")
12229 (> (current-indentation) indent)))
12230 (beginning-of-line 2))
12231 (if (= (current-indentation) indent)
12232 (back-to-indentation)
12233 (message "No following line with same indent found in this block")
12234 (goto-char pos)
12235 nil)))
5eabfe72 12236
3dcb36b7
JB
12237(defun vhdl-backward-same-indent ()
12238 "Move backward to previous line with same indent."
12239 (interactive)
12240 (let ((pos (point))
12241 (indent (current-indentation)))
12242 (beginning-of-line -0)
12243 (while (and (not (bobp))
12244 (or (looking-at "^\\s-*\\(--.*\\)?$")
12245 (> (current-indentation) indent)))
12246 (beginning-of-line -0))
12247 (if (= (current-indentation) indent)
12248 (back-to-indentation)
12249 (message "No preceding line with same indent found in this block")
12250 (goto-char pos)
12251 nil)))
5eabfe72
KH
12252
12253;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
12254;; Statistics
12255
12256(defun vhdl-statistics-buffer ()
12257 "Get some file statistics."
12258 (interactive)
12259 (let ((no-stats 0)
12260 (no-code-lines 0)
12261 (no-lines (count-lines (point-min) (point-max))))
12262 (save-excursion
12263 ;; count statements
12264 (goto-char (point-min))
12265 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12266 (if (match-string 1)
12267 (goto-char (match-end 1))
12268 (setq no-stats (1+ no-stats))))
12269 ;; count code lines
12270 (goto-char (point-min))
12271 (while (not (eobp))
12272 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12273 (setq no-code-lines (1+ no-code-lines)))
12274 (beginning-of-line 2)))
12275 ;; print results
12276 (message "\n\
12277File statistics: \"%s\"\n\
12278---------------------\n\
12279# statements : %5d\n\
12280# code lines : %5d\n\
12281# total lines : %5d\n\ "
0a2e512a
RF
12282 (buffer-file-name) no-stats no-code-lines no-lines)
12283 (unless vhdl-emacs-21 (vhdl-show-messages))))
3dcb36b7 12284
5eabfe72 12285;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12286;; Help functions
d2ddb974 12287
3dcb36b7
JB
12288(defun vhdl-re-search-forward (regexp &optional bound noerror count)
12289 "Like `re-search-forward', but does not match within literals."
12290 (let (pos)
12291 (save-excursion
12292 (while (and (setq pos (re-search-forward regexp bound noerror count))
12293 (vhdl-in-literal))))
12294 (when pos (goto-char pos))
12295 pos))
12296
12297(defun vhdl-re-search-backward (regexp &optional bound noerror count)
12298 "Like `re-search-backward', but does not match within literals."
12299 (let (pos)
12300 (save-excursion
12301 (while (and (setq pos (re-search-backward regexp bound noerror count))
12302 (vhdl-in-literal))))
12303 (when pos (goto-char pos))
12304 pos))
5eabfe72 12305
d2ddb974 12306
3dcb36b7
JB
12307;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12308;;; Project
12309;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12310
12311(defun vhdl-set-project (name)
12312 "Set current project to NAME."
12313 (interactive
12314 (list (let ((completion-ignore-case t))
12315 (completing-read "Project name: " vhdl-project-alist nil t))))
12316 (cond ((equal name "")
12317 (setq vhdl-project nil)
12318 (message "Current VHDL project: None"))
12319 ((assoc name vhdl-project-alist)
12320 (setq vhdl-project name)
12321 (message "Current VHDL project: \"%s\"" name))
12322 (t
12323 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12324 (vhdl-speedbar-update-current-project))
12325
0a2e512a
RF
12326(defun vhdl-set-default-project ()
12327 "Set current project as default on startup."
12328 (interactive)
12329 (customize-set-variable 'vhdl-project vhdl-project)
12330 (customize-save-customized))
12331
3dcb36b7
JB
12332(defun vhdl-toggle-project (name token indent)
12333 "Set current project to NAME or unset if NAME is current project."
12334 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12335
12336(defun vhdl-export-project (file-name)
12337 "Write project setup for current project."
12338 (interactive
12339 (let ((name (vhdl-resolve-env-variable
12340 (vhdl-replace-string
12341 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12342 (concat (subst-char-in-string
12343 ? ?_ (or (vhdl-project-p)
12344 (error "ERROR: No current project")))
12345 " " (user-login-name))))))
12346 (list (read-file-name
12347 "Write project file: "
12348 (when (file-name-absolute-p name) "") nil nil name))))
12349 (setq file-name (abbreviate-file-name file-name))
12350 (let ((orig-buffer (current-buffer)))
12351 (unless (file-exists-p (file-name-directory file-name))
12352 (make-directory (file-name-directory file-name) t))
12353 (if (not (file-writable-p file-name))
12354 (error "ERROR: File not writable: \"%s\"" file-name)
12355 (set-buffer (find-file-noselect file-name t t))
12356 (erase-buffer)
12357 (insert ";; -*- Emacs-Lisp -*-\n\n"
12358 ";;; " (file-name-nondirectory file-name)
12359 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12360 ";; Project : " vhdl-project "\n"
12361 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12362 (user-login-name) "\n\n\n"
12363 ";; project name\n"
12364 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12365 ";; project setup\n"
12366 "(aput 'vhdl-project-alist vhdl-project\n'")
12367 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12368 (insert ")\n")
12369 (save-buffer)
12370 (kill-buffer (current-buffer))
12371 (set-buffer orig-buffer))))
12372
12373(defun vhdl-import-project (file-name &optional auto not-make-current)
12374 "Read project setup and set current project."
12375 (interactive
12376 (let ((name (vhdl-resolve-env-variable
12377 (vhdl-replace-string
12378 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12379 (concat "" " " (user-login-name))))))
12380 (list (read-file-name
12381 "Read project file: " (when (file-name-absolute-p name) "") nil t
12382 (file-name-directory name)))))
12383 (when (file-exists-p file-name)
12384 (condition-case ()
12385 (let ((current-project vhdl-project))
12386 (load-file file-name)
12387 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12388 (adelete 'vhdl-project-alist vhdl-project)
0a2e512a 12389 (error ""))
3dcb36b7
JB
12390 (when not-make-current
12391 (setq vhdl-project current-project))
12392 (vhdl-update-mode-menu)
12393 (vhdl-speedbar-refresh)
12394 (unless not-make-current
12395 (message "Current VHDL project: \"%s\"%s"
12396 vhdl-project (if auto " (auto-loaded)" ""))))
12397 (error (vhdl-warning
12398 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12399
12400(defun vhdl-duplicate-project ()
12401 "Duplicate setup of current project."
5eabfe72 12402 (interactive)
3dcb36b7
JB
12403 (let ((new-name (read-from-minibuffer "New project name: "))
12404 (project-entry (aget vhdl-project-alist vhdl-project t)))
12405 (setq vhdl-project-alist
12406 (append vhdl-project-alist
12407 (list (cons new-name project-entry))))
12408 (vhdl-update-mode-menu)))
12409
12410(defun vhdl-auto-load-project ()
12411 "Automatically load project setup at startup."
12412 (let ((file-name-list vhdl-project-file-name)
12413 file-list list-length)
12414 (while file-name-list
12415 (setq file-list
12416 (append file-list
12417 (file-expand-wildcards
12418 (vhdl-resolve-env-variable
12419 (vhdl-replace-string
12420 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12421 (concat "\*" " " (user-login-name)))))))
12422 (setq list-length (or list-length (length file-list)))
12423 (setq file-name-list (cdr file-name-list)))
12424 (while file-list
12425 (vhdl-import-project (expand-file-name (car file-list)) t
12426 (not (> list-length 0)))
12427 (setq list-length (1- list-length))
12428 (setq file-list (cdr file-list)))))
12429
12430;; automatically load project setup when idle after startup
12431(when (memq 'startup vhdl-project-auto-load)
12432 (if noninteractive
12433 (vhdl-auto-load-project)
12434 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
5eabfe72
KH
12435
12436
12437;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12438;;; Hideshow
12439;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12440;; (using `hideshow.el')
d2ddb974 12441
3dcb36b7
JB
12442(defconst vhdl-hs-start-regexp
12443 (concat
12444 "\\(^\\)\\s-*\\("
12445 ;; generic/port clause
12446 "\\(generic\\|port\\)[ \t\n]*(\\|"
12447 ;; component
12448 "component\\>\\|"
12449 ;; component instantiation
12450 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12451 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12452 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12453 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12454 ;; subprogram
12455 "\\(function\\|procedure\\)\\>\\|"
12456 ;; process, block
12457 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12458 ;; configuration declaration
12459 "configuration\\>"
12460 "\\)")
12461 "Regexp to match start of construct to hide.")
12462
12463(defun vhdl-hs-forward-sexp-func (count)
12464 "Find end of construct to hide (for hideshow). Only searches forward."
12465 (let ((pos (point)))
12466 (vhdl-prepare-search-2
12467 (beginning-of-line)
12468 (cond
12469 ;; generic/port clause
12470 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12471 (goto-char (match-end 0))
12472 (backward-char)
12473 (forward-sexp))
12474 ;; component declaration
12475 ((looking-at "^\\s-*component\\>")
12476 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12477 ;; component instantiation
12478 ((looking-at
12479 (concat
12480 "^\\s-*\\w+\\s-*:[ \t\n]*"
12481 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12482 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12483 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12484 (goto-char (match-end 0))
12485 (backward-char)
12486 (forward-sexp)
12487 (setq pos (point))
12488 (vhdl-forward-syntactic-ws)
12489 (when (looking-at "port\\s-+map[ \t\n]*(")
12490 (goto-char (match-end 0))
12491 (backward-char)
12492 (forward-sexp)
12493 (setq pos (point)))
12494 (goto-char pos))
12495 ;; subprogram declaration/body
12496 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12497 (goto-char (match-end 0))
12498 (vhdl-forward-syntactic-ws)
12499 (when (looking-at "(")
12500 (forward-sexp))
12501 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12502 (vhdl-in-literal)))
12503 ;; subprogram body
12504 (when (match-string 2)
12505 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12506 (backward-word 1)
12507 (vhdl-forward-sexp)))
12508 ;; block (recursive)
12509 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12510 (goto-char (match-end 0))
12511 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12512 (match-beginning 2))
12513 (vhdl-hs-forward-sexp-func count)))
12514 ;; process
12515 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12516 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12517 ;; configuration declaration
12518 ((looking-at "^\\s-*configuration\\>")
12519 (forward-word 4)
12520 (vhdl-forward-sexp))
12521 (t (goto-char pos))))))
5eabfe72
KH
12522
12523(defun vhdl-hideshow-init ()
12524 "Initialize `hideshow'."
3dcb36b7
JB
12525 (when vhdl-hideshow-menu
12526 (vhdl-hs-minor-mode 1)))
12527
12528(defun vhdl-hs-minor-mode (&optional arg)
12529 "Toggle hideshow minor mode and update menu bar."
12530 (interactive "P")
12531 (require 'hideshow)
12532 ;; check for hideshow version 5.x
12533 (if (not (boundp 'hs-block-start-mdata-select))
12534 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12535 ;; initialize hideshow
12536 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12537 (setq hs-special-modes-alist
12538 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12539 'vhdl-hs-forward-sexp-func nil)
12540 hs-special-modes-alist)))
12541 (make-local-variable 'hs-minor-mode-hook)
12542 (if vhdl-hide-all-init
12543 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12544 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12545 (hs-minor-mode arg)
12546 (vhdl-mode-line-update))) ; hack to update menu bar
5eabfe72
KH
12547
12548
12549;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12550;;; Font locking
12551;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12552;; (using `font-lock.el')
12553
5eabfe72 12554;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12555;; Help functions
5eabfe72
KH
12556
12557(defun vhdl-within-translate-off ()
12558 "Return point if within translate-off region, else nil."
12559 (and (save-excursion
12560 (re-search-backward
12561 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12562 (equal "off" (match-string 1))
12563 (point)))
12564
12565(defun vhdl-start-translate-off (limit)
12566 "Return point before translate-off pragma if before LIMIT, else nil."
12567 (when (re-search-forward
12568 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12569 (match-beginning 0)))
12570
12571(defun vhdl-end-translate-off (limit)
12572 "Return point after translate-on pragma if before LIMIT, else nil."
12573 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12574
12575(defun vhdl-match-translate-off (limit)
12576 "Match a translate-off block, setting match-data and returning t, else nil."
12577 (when (< (point) limit)
12578 (let ((start (or (vhdl-within-translate-off)
12579 (vhdl-start-translate-off limit)))
12580 (case-fold-search t))
12581 (when start
12582 (let ((end (or (vhdl-end-translate-off limit) limit)))
12583 (set-match-data (list start end))
12584 (goto-char end))))))
12585
12586(defun vhdl-font-lock-match-item (limit)
12587 "Match, and move over, any declaration item after point. Adapted from
12588`font-lock-match-c-style-declaration-item-and-skip-to-next'."
12589 (condition-case nil
12590 (save-restriction
12591 (narrow-to-region (point-min) limit)
12592 ;; match item
3dcb36b7 12593 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
5eabfe72
KH
12594 (save-match-data
12595 (goto-char (match-end 1))
12596 ;; move to next item
0a2e512a
RF
12597 (if (looking-at "\\(\\s-*,\\)")
12598 (goto-char (match-end 1))
5eabfe72
KH
12599 (end-of-line) t))))
12600 (error t)))
12601
12602;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12603;; Syntax definitions
12604
5eabfe72
KH
12605(defconst vhdl-font-lock-syntactic-keywords
12606 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12607 "Mark single quotes as having string quote syntax in 'c' instances.")
12608
d2ddb974
KH
12609(defvar vhdl-font-lock-keywords nil
12610 "Regular expressions to highlight in VHDL Mode.")
12611
3dcb36b7
JB
12612(defvar vhdl-font-lock-keywords-0
12613 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12614 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12615This does highlighting of template prompts and directives (pragmas).")
d2ddb974 12616
5eabfe72 12617(defvar vhdl-font-lock-keywords-1 nil
3dcb36b7 12618 ;; set in `vhdl-font-lock-init' because dependent on user options
5eabfe72
KH
12619 "For consideration as a value of `vhdl-font-lock-keywords'.
12620This does highlighting of keywords and standard identifiers.")
12621
12622(defconst vhdl-font-lock-keywords-2
d2ddb974
KH
12623 (list
12624 ;; highlight names of units, subprograms, and components when declared
12625 (list
12626 (concat
12627 "^\\s-*\\("
3dcb36b7
JB
12628 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12629 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
d2ddb974 12630 "\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12631 5 'font-lock-function-name-face)
12632
12633 ;; highlight entity names of architectures and configurations
12634 (list
12635 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12636 2 'font-lock-function-name-face)
d2ddb974
KH
12637
12638 ;; highlight labels of common constructs
12639 (list
12640 (concat
3dcb36b7
JB
12641 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12642 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12643 "postponed\\|process\\|"
5eabfe72
KH
12644 (when (vhdl-standard-p 'ams) "procedural\\|")
12645 "with\\|while"
0a2e512a 12646 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
d2ddb974
KH
12647 1 'font-lock-function-name-face)
12648
5eabfe72 12649 ;; highlight label and component name of component instantiations
d2ddb974 12650 (list
5eabfe72 12651 (concat
3dcb36b7
JB
12652 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12653 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12654 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12655
12656 ;; highlight label and instantiated unit of component instantiations
12657 (list
12658 (concat
12659 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12660 "\\(component\\|configuration\\|entity\\)\\s-+"
12661 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12662 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12663 '(5 font-lock-function-name-face nil t)
12664 '(7 font-lock-function-name-face nil t))
d2ddb974
KH
12665
12666 ;; highlight names and labels at end of constructs
12667 (list
12668 (concat
5eabfe72
KH
12669 "^\\s-*end\\s-+\\(\\("
12670 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
3dcb36b7
JB
12671 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12672 "procedure\\|\\(postponed\\s-+\\)?process\\|"
5eabfe72
KH
12673 (when (vhdl-standard-p 'ams) "procedural\\|")
12674 "units"
3dcb36b7 12675 "\\)\\s-+\\)?\\(\\w*\\)")
5eabfe72
KH
12676 5 'font-lock-function-name-face)
12677
12678 ;; highlight labels in exit and next statements
12679 (list
12680 (concat
12681 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12682 3 'font-lock-function-name-face)
12683
12684 ;; highlight entity name in attribute specifications
12685 (list
12686 (concat
12687 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12688 1 'font-lock-function-name-face)
12689
3dcb36b7
JB
12690 ;; highlight labels in block and component specifications
12691 (list
12692 (concat
12693 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12694 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12695 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12696
12697 ;; highlight names in library clauses
12698 (list "^\\s-*library\\>"
12699 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12700
12701 ;; highlight names in use clauses
5eabfe72
KH
12702 (list
12703 (concat
3dcb36b7
JB
12704 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12705 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12706 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12707 '(7 font-lock-function-name-face nil t))
5eabfe72
KH
12708
12709 ;; highlight attribute name in attribute declarations/specifications
12710 (list
12711 (concat
12712 "^\\s-*attribute\\s-+\\(\\w+\\)")
0a2e512a 12713 1 'vhdl-font-lock-attribute-face)
5eabfe72
KH
12714
12715 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12716 (list
12717 (concat
3dcb36b7 12718 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12719 3 'font-lock-type-face)
12720
12721 ;; highlight signal/variable/constant declaration names
12722 (list "\\(:[^=]\\)"
12723 '(vhdl-font-lock-match-item
12724 (progn (goto-char (match-beginning 1))
12725 (skip-syntax-backward " ")
12726 (skip-syntax-backward "w_")
12727 (skip-syntax-backward " ")
12728 (while (= (preceding-char) ?,)
12729 (backward-char 1)
12730 (skip-syntax-backward " ")
12731 (skip-syntax-backward "w_")
12732 (skip-syntax-backward " ")))
12733; (skip-chars-backward "^-(\n\";")
12734 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12735
3dcb36b7
JB
12736 ;; highlight formal parameters in component instantiations and subprogram
12737 ;; calls
12738 (list "\\(=>\\)"
12739 '(vhdl-font-lock-match-item
12740 (progn (goto-char (match-beginning 1))
12741 (skip-syntax-backward " ")
12742 (while (= (preceding-char) ?\)) (backward-sexp))
12743 (skip-syntax-backward "w_")
12744 (skip-syntax-backward " ")
0a2e512a 12745 (when (memq (preceding-char) '(?n ?N ?|))
3dcb36b7
JB
12746 (goto-char (point-max))))
12747 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12748
12749 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12750 ;; variables
12751 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
5eabfe72
KH
12752 '(vhdl-font-lock-match-item
12753 (progn (goto-char (match-end 1)) (match-beginning 2))
12754 nil (1 font-lock-variable-name-face)))
d2ddb974 12755 )
5eabfe72
KH
12756 "For consideration as a value of `vhdl-font-lock-keywords'.
12757This does context sensitive highlighting of names and labels.")
d2ddb974 12758
5eabfe72 12759(defvar vhdl-font-lock-keywords-3 nil
3dcb36b7 12760 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12761 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72
KH
12762This does highlighting of words with special syntax.")
12763
12764(defvar vhdl-font-lock-keywords-4 nil
3dcb36b7 12765 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12766 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12767This does highlighting of additional reserved words.")
d2ddb974 12768
5eabfe72
KH
12769(defconst vhdl-font-lock-keywords-5
12770 ;; background highlight translate-off regions
0a2e512a 12771 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
5eabfe72
KH
12772 "For consideration as a value of `vhdl-font-lock-keywords'.
12773This does background highlighting of translate-off regions.")
12774
12775;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12776;; Font and color definitions
12777
0a2e512a 12778(defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
d2ddb974
KH
12779 "Face name to use for prompts.")
12780
0a2e512a 12781(defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
5eabfe72
KH
12782 "Face name to use for standardized attributes.")
12783
0a2e512a 12784(defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
5eabfe72 12785 "Face name to use for standardized enumeration values.")
d2ddb974 12786
0a2e512a 12787(defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
5eabfe72 12788 "Face name to use for standardized functions and packages.")
d2ddb974 12789
0a2e512a 12790(defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
5eabfe72 12791 "Face name to use for directives.")
d2ddb974 12792
0a2e512a 12793(defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
5eabfe72 12794 "Face name to use for additional reserved words.")
d2ddb974 12795
0a2e512a 12796(defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
5eabfe72 12797 "Face name to use for translate-off regions.")
d2ddb974 12798
5eabfe72
KH
12799;; face names to use for words with special syntax.
12800(let ((syntax-alist vhdl-special-syntax-alist)
12801 name)
12802 (while syntax-alist
0a2e512a
RF
12803 (setq name (vhdl-function-name
12804 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
d4a5b644
GM
12805 (eval `(defvar ,name ',name
12806 ,(concat "Face name to use for "
12807 (nth 0 (car syntax-alist)) ".")))
5eabfe72
KH
12808 (setq syntax-alist (cdr syntax-alist))))
12809
3dcb36b7 12810(defgroup vhdl-highlight-faces nil
5eabfe72
KH
12811 "Faces for highlighting."
12812 :group 'vhdl-highlight)
d2ddb974 12813
3dcb36b7
JB
12814;; add faces used from `font-lock'
12815(custom-add-to-group
12816 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12817(custom-add-to-group
12818 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12819(custom-add-to-group
12820 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12821(custom-add-to-group
12822 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12823(custom-add-to-group
12824 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12825(custom-add-to-group
12826 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12827
0a2e512a 12828(defface vhdl-font-lock-prompt-face
f47877ee 12829 '((((min-colors 88) (class color) (background light))
ea81d57e 12830 (:foreground "Red1" :bold t))
f47877ee 12831 (((class color) (background light)) (:foreground "Red" :bold t))
3dcb36b7 12832 (((class color) (background dark)) (:foreground "Pink" :bold t))
d2ddb974 12833 (t (:inverse-video t)))
5eabfe72
KH
12834 "Font lock mode face used to highlight prompts."
12835 :group 'vhdl-highlight-faces
d2ddb974
KH
12836 :group 'font-lock-highlighting-faces)
12837
0a2e512a 12838(defface vhdl-font-lock-attribute-face
5eabfe72
KH
12839 '((((class color) (background light)) (:foreground "Orchid"))
12840 (((class color) (background dark)) (:foreground "LightSteelBlue"))
3dcb36b7 12841 (t (:italic t :bold t)))
5eabfe72
KH
12842 "Font lock mode face used to highlight standardized attributes."
12843 :group 'vhdl-highlight-faces
d2ddb974
KH
12844 :group 'font-lock-highlighting-faces)
12845
0a2e512a 12846(defface vhdl-font-lock-enumvalue-face
3dcb36b7 12847 '((((class color) (background light)) (:foreground "SaddleBrown"))
5eabfe72 12848 (((class color) (background dark)) (:foreground "BurlyWood"))
3dcb36b7 12849 (t (:italic t :bold t)))
5eabfe72
KH
12850 "Font lock mode face used to highlight standardized enumeration values."
12851 :group 'vhdl-highlight-faces
d2ddb974
KH
12852 :group 'font-lock-highlighting-faces)
12853
0a2e512a 12854(defface vhdl-font-lock-function-face
3dcb36b7 12855 '((((class color) (background light)) (:foreground "Cyan4"))
5eabfe72 12856 (((class color) (background dark)) (:foreground "Orchid1"))
3dcb36b7 12857 (t (:italic t :bold t)))
5eabfe72
KH
12858 "Font lock mode face used to highlight standardized functions and packages."
12859 :group 'vhdl-highlight-faces
d2ddb974
KH
12860 :group 'font-lock-highlighting-faces)
12861
0a2e512a 12862(defface vhdl-font-lock-directive-face
5eabfe72
KH
12863 '((((class color) (background light)) (:foreground "CadetBlue"))
12864 (((class color) (background dark)) (:foreground "Aquamarine"))
3dcb36b7 12865 (t (:italic t :bold t)))
5eabfe72
KH
12866 "Font lock mode face used to highlight directives."
12867 :group 'vhdl-highlight-faces
d2ddb974
KH
12868 :group 'font-lock-highlighting-faces)
12869
0a2e512a 12870(defface vhdl-font-lock-reserved-words-face
3dcb36b7 12871 '((((class color) (background light)) (:foreground "Orange" :bold t))
5bb5087f 12872 (((min-colors 88) (class color) (background dark))
ea81d57e 12873 (:foreground "Yellow1" :bold t))
3dcb36b7 12874 (((class color) (background dark)) (:foreground "Yellow" :bold t))
d2ddb974 12875 (t ()))
5eabfe72
KH
12876 "Font lock mode face used to highlight additional reserved words."
12877 :group 'vhdl-highlight-faces
d2ddb974
KH
12878 :group 'font-lock-highlighting-faces)
12879
0a2e512a 12880(defface vhdl-font-lock-translate-off-face
5eabfe72
KH
12881 '((((class color) (background light)) (:background "LightGray"))
12882 (((class color) (background dark)) (:background "DimGray"))
d2ddb974 12883 (t ()))
5eabfe72
KH
12884 "Font lock mode face used to background highlight translate-off regions."
12885 :group 'vhdl-highlight-faces
d2ddb974
KH
12886 :group 'font-lock-highlighting-faces)
12887
5eabfe72
KH
12888;; font lock mode faces used to highlight words with special syntax.
12889(let ((syntax-alist vhdl-special-syntax-alist))
12890 (while syntax-alist
0a2e512a
RF
12891 (eval `(defface ,(vhdl-function-name
12892 "vhdl-font-lock" (caar syntax-alist) "face")
d4a5b644
GM
12893 '((((class color) (background light))
12894 (:foreground ,(nth 2 (car syntax-alist))))
12895 (((class color) (background dark))
12896 (:foreground ,(nth 3 (car syntax-alist))))
12897 (t ()))
12898 ,(concat "Font lock mode face used to highlight "
12899 (nth 0 (car syntax-alist)) ".")
12900 :group 'vhdl-highlight-faces
12901 :group 'font-lock-highlighting-faces))
5eabfe72
KH
12902 (setq syntax-alist (cdr syntax-alist))))
12903
12904;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12905;; Font lock initialization
12906
12907(defun vhdl-font-lock-init ()
5eabfe72 12908 "Initialize fontification."
0a2e512a 12909 ;; highlight template prompts and directives
3dcb36b7
JB
12910 (setq vhdl-font-lock-keywords-0
12911 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12912 vhdl-template-prompt-syntax ">\\)")
0a2e512a 12913 2 'vhdl-font-lock-prompt-face t)
3dcb36b7
JB
12914 (list (concat "--\\s-*"
12915 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
0a2e512a
RF
12916 2 'vhdl-font-lock-directive-face t)
12917 ;; highlight c-preprocessor directives
12918 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12919 '(1 font-lock-builtin-face)
12920 '(3 font-lock-variable-name-face nil t))))
5eabfe72
KH
12921 ;; highlight keywords and standardized types, attributes, enumeration
12922 ;; values, and subprograms
12923 (setq vhdl-font-lock-keywords-1
12924 (list
0a2e512a
RF
12925 (list (concat "'" vhdl-attributes-regexp)
12926 1 'vhdl-font-lock-attribute-face)
5eabfe72 12927 (list vhdl-types-regexp 1 'font-lock-type-face)
0a2e512a
RF
12928 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12929 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12930 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
5eabfe72
KH
12931 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12932 ;; highlight words with special syntax.
12933 (setq vhdl-font-lock-keywords-3
12934 (let ((syntax-alist vhdl-special-syntax-alist)
12935 keywords)
12936 (while syntax-alist
12937 (setq keywords
12938 (cons
12939 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12940 (vhdl-function-name
0a2e512a 12941 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
5eabfe72
KH
12942 keywords))
12943 (setq syntax-alist (cdr syntax-alist)))
12944 keywords))
12945 ;; highlight additional reserved words
12946 (setq vhdl-font-lock-keywords-4
0a2e512a
RF
12947 (list (list vhdl-reserved-words-regexp 1
12948 'vhdl-font-lock-reserved-words-face)))
5eabfe72 12949 ;; highlight everything together
d2ddb974 12950 (setq vhdl-font-lock-keywords
5eabfe72
KH
12951 (append
12952 vhdl-font-lock-keywords-0
12953 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12954 (when (or vhdl-highlight-forbidden-words
12955 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12956 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12957 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12958 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12959
12960;; initialize fontification for VHDL Mode
12961(vhdl-font-lock-init)
12962
12963(defun vhdl-fontify-buffer ()
12964 "Re-initialize fontification and fontify buffer."
12965 (interactive)
12966 (setq font-lock-defaults
12967 (list
12968 'vhdl-font-lock-keywords nil
12969 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12970 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12971 (when (fboundp 'font-lock-unset-defaults)
12972 (font-lock-unset-defaults)) ; not implemented in XEmacs
0a2e512a 12973 (font-lock-set-defaults)
3dcb36b7
JB
12974 (font-lock-mode nil)
12975 (font-lock-mode t))
5eabfe72
KH
12976
12977;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12978;; Initialization for postscript printing
12979
12980(defun vhdl-ps-print-settings ()
12981 "Initialize custom face and page settings for postscript printing."
12982 ;; define custom face settings
12983 (unless (or (not vhdl-print-customize-faces)
d2ddb974
KH
12984 ps-print-color-p)
12985 (set (make-local-variable 'ps-bold-faces)
0a2e512a
RF
12986 '(font-lock-keyword-face
12987 font-lock-type-face
12988 vhdl-font-lock-attribute-face
12989 vhdl-font-lock-enumvalue-face
12990 vhdl-font-lock-directive-face))
d2ddb974
KH
12991 (set (make-local-variable 'ps-italic-faces)
12992 '(font-lock-comment-face
0a2e512a
RF
12993 font-lock-function-name-face
12994 font-lock-type-face
12995 vhdl-font-lock-attribute-face
12996 vhdl-font-lock-enumvalue-face
12997 vhdl-font-lock-directive-face))
d2ddb974
KH
12998 (set (make-local-variable 'ps-underlined-faces)
12999 '(font-lock-string-face))
5eabfe72 13000 (setq ps-always-build-face-reference t))
d2ddb974
KH
13001 ;; define page settings, so that a line containing 79 characters (default)
13002 ;; fits into one column
5eabfe72
KH
13003 (when vhdl-print-two-column
13004 (set (make-local-variable 'ps-landscape-mode) t)
13005 (set (make-local-variable 'ps-number-of-columns) 2)
13006 (set (make-local-variable 'ps-font-size) 7.0)
13007 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13008 (set (make-local-variable 'ps-header-font-size) 9.0)
13009 (set (make-local-variable 'ps-header-offset) 12.0)
13010 (when (eq ps-paper-type 'letter)
13011 (set (make-local-variable 'ps-inter-column) 40.0)
13012 (set (make-local-variable 'ps-left-margin) 40.0)
13013 (set (make-local-variable 'ps-right-margin) 40.0))))
13014
13015(defun vhdl-ps-print-init ()
13016 "Initialize postscript printing."
3dcb36b7
JB
13017 (if vhdl-xemacs
13018 (when (boundp 'ps-print-color-p)
13019 (vhdl-ps-print-settings))
5eabfe72
KH
13020 (make-local-variable 'ps-print-hook)
13021 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13022
13023
13024;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13025;;; Hierarchy browser (using `speedbar.el')
13026;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13027;; Allows displaying the hierarchy of all VHDL design units contained in a
13028;; directory by using the speedbar.
13029
13030;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13031;; Variables
13032
13033(defvar vhdl-entity-alist nil
3dcb36b7
JB
13034 "Cache with entities and corresponding architectures for each
13035project/directory.")
5eabfe72 13036;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
13037;; (cache-key
13038;; (ent-key ent-name ent-file ent-line
13039;; (arch-key arch-name arch-file arch-line
13040;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
0a2e512a
RF
13041;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13042;; (lib-name pack-key))
13043;; mra-key (lib-name pack-key))
3dcb36b7
JB
13044
13045(defvar vhdl-config-alist nil
13046 "Cache with configurations for each project/directory.")
13047;; structure: (parenthesised expression means list of such entries)
13048;; (cache-key
13049;; (conf-key conf-name conf-file conf-line ent-key arch-key
13050;; (inst-key inst-comp-name inst-ent-key inst-arch-key
0a2e512a 13051;; inst-conf-key inst-lib-key)
3dcb36b7 13052;; (lib-name pack-key)))
5eabfe72
KH
13053
13054(defvar vhdl-package-alist nil
3dcb36b7 13055 "Cache with packages for each project/directory.")
5eabfe72 13056;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
13057;; (cache-key
13058;; (pack-key pack-name pack-file pack-line
13059;; (comp-key comp-name comp-file comp-line)
13060;; (func-key func-name func-file func-line)
13061;; (lib-name pack-key)
13062;; pack-body-file pack-body-line
13063;; (func-key func-name func-body-file func-body-line)
13064;; (lib-name pack-key)))
5eabfe72
KH
13065
13066(defvar vhdl-ent-inst-alist nil
3dcb36b7 13067 "Cache with instantiated entities for each project/directory.")
5eabfe72 13068;; structure: (parenthesised expression means list of such entries)
3dcb36b7 13069;; (cache-key (inst-ent-key))
5eabfe72 13070
3dcb36b7
JB
13071(defvar vhdl-file-alist nil
13072 "Cache with design units in each file for each project/directory.")
13073;; structure: (parenthesised expression means list of such entries)
13074;; (cache-key
13075;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
0a2e512a 13076;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
5eabfe72 13077
3dcb36b7
JB
13078(defvar vhdl-directory-alist nil
13079 "Cache with source directories for each project.")
13080;; structure: (parenthesised expression means list of such entries)
13081;; (cache-key (directory))
5eabfe72 13082
3dcb36b7 13083(defvar vhdl-speedbar-shown-unit-alist nil
5eabfe72
KH
13084 "Alist of design units simultaneously open in the current speedbar for each
13085directory and project.")
13086
3dcb36b7
JB
13087(defvar vhdl-speedbar-shown-project-list nil
13088 "List of projects simultaneously open in the current speedbar.")
5eabfe72 13089
3dcb36b7
JB
13090(defvar vhdl-updated-project-list nil
13091 "List of projects and directories with updated files.")
13092
13093(defvar vhdl-modified-file-list nil
13094 "List of modified files to be rescanned for hierarchy updating.")
13095
13096(defvar vhdl-speedbar-hierarchy-depth 0
13097 "Depth of instantiation hierarchy to display.")
13098
13099(defvar vhdl-speedbar-show-projects nil
13100 "Non-nil means project hierarchy is displayed in speedbar, directory
13101hierarchy otherwise.")
13102
13103(defun vhdl-get-end-of-unit ()
13104 "Return position of end of current unit."
13105 (let ((pos (point)))
13106 (save-excursion
13107 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13108 (save-excursion
13109 (goto-char (match-beginning 0))
13110 (vhdl-backward-syntactic-ws)
13111 (and (/= (preceding-char) ?\;) (not (bobp))))))
13112 (re-search-backward "^[ \t]*end\\>" pos 1)
13113 (point))))
13114
13115(defun vhdl-match-string-downcase (num &optional string)
13116 "Like `match-string-no-properties' with down-casing."
13117 (let ((match (match-string-no-properties num string)))
13118 (and match (downcase match))))
5eabfe72 13119
5eabfe72
KH
13120
13121;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13122;; Scan functions
13123
3dcb36b7
JB
13124(defun vhdl-scan-context-clause ()
13125 "Scan the context clause that preceeds a design unit."
13126 (let (lib-alist)
13127 (save-excursion
13128 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13129 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13130 (equal "USE" (upcase (match-string 1))))
13131 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13132 (setq lib-alist (cons (cons (match-string-no-properties 1)
13133 (vhdl-match-string-downcase 2))
13134 lib-alist))))))
13135 lib-alist))
13136
13137(defun vhdl-scan-directory-contents (name &optional project update num-string
13138 non-final)
13139 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
13140 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
5eabfe72
KH
13141; (unless (file-directory-p (match-string 1 name))
13142; (message "No such directory: \"%s\"" (match-string 1 name)))
3dcb36b7
JB
13143 (let* ((dir-name (match-string 1 name))
13144 (file-pattern (match-string 2 name))
13145 (is-directory (= 0 (length file-pattern)))
5eabfe72 13146 (file-list
3dcb36b7
JB
13147 (if update
13148 (list name)
13149 (if is-directory
13150 (vhdl-get-source-files t dir-name)
13151 (vhdl-directory-files
13152 dir-name t (wildcard-to-regexp file-pattern)))))
13153 (key (or project dir-name))
13154 (file-exclude-regexp
13155 (or (nth 3 (aget vhdl-project-alist project)) ""))
13156 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13157 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13158 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13159 ent-alist conf-alist pack-alist ent-inst-list file-alist
13160 tmp-list tmp-entry no-files files-exist big-files)
13161 (when (or project update)
13162 (setq ent-alist (aget vhdl-entity-alist key t)
13163 conf-alist (aget vhdl-config-alist key t)
13164 pack-alist (aget vhdl-package-alist key t)
13165 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13166 file-alist (aget vhdl-file-alist key t)))
5eabfe72
KH
13167 (when (and (not is-directory) (null file-list))
13168 (message "No such file: \"%s\"" name))
3dcb36b7
JB
13169 (setq files-exist file-list)
13170 (when file-list
13171 (setq no-files (length file-list))
13172 (message "Scanning %s %s\"%s\"..."
13173 (if is-directory "directory" "files") (or num-string "") name)
13174 ;; exclude files
13175 (unless (equal file-exclude-regexp "")
13176 (let ((case-fold-search nil)
13177 file-tmp-list)
13178 (while file-list
13179 (unless (string-match file-exclude-regexp (car file-list))
13180 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13181 (setq file-list (cdr file-list)))
13182 (setq file-list (nreverse file-tmp-list))))
13183 ;; do for all files
13184 (while file-list
13185 (unless noninteractive
5eabfe72
KH
13186 (message "Scanning %s %s\"%s\"... (%2d%s)"
13187 (if is-directory "directory" "files")
13188 (or num-string "") name
3dcb36b7
JB
13189 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13190 (let ((file-name (abbreviate-file-name (car file-list)))
13191 ent-list arch-list arch-ent-list conf-list
13192 pack-list pack-body-list inst-list inst-ent-list)
13193 ;; scan file
13194 (vhdl-visit-file
13195 file-name nil
13196 (vhdl-prepare-search-2
13197 (save-excursion
13198 ;; scan for design units
13199 (if (and limit-design-file-size
13200 (< limit-design-file-size (buffer-size)))
13201 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13202 (setq big-files t))
13203 ;; scan for entities
13204 (goto-char (point-min))
13205 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13206 (let* ((ent-name (match-string-no-properties 1))
13207 (ent-key (downcase ent-name))
13208 (ent-entry (aget ent-alist ent-key t))
3dcb36b7
JB
13209 (lib-alist (vhdl-scan-context-clause)))
13210 (if (nth 1 ent-entry)
13211 (vhdl-warning-when-idle
13212 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13213 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13214 file-name (vhdl-current-line))
13215 (setq ent-list (cons ent-key ent-list))
13216 (aput 'ent-alist ent-key
13217 (list ent-name file-name (vhdl-current-line)
0a2e512a
RF
13218 (nth 3 ent-entry) (nth 4 ent-entry)
13219 lib-alist)))))
3dcb36b7
JB
13220 ;; scan for architectures
13221 (goto-char (point-min))
0a2e512a 13222 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
3dcb36b7
JB
13223 (let* ((arch-name (match-string-no-properties 1))
13224 (arch-key (downcase arch-name))
13225 (ent-name (match-string-no-properties 2))
13226 (ent-key (downcase ent-name))
13227 (ent-entry (aget ent-alist ent-key t))
13228 (arch-alist (nth 3 ent-entry))
13229 (arch-entry (aget arch-alist arch-key t))
13230 (lib-arch-alist (vhdl-scan-context-clause)))
13231 (if arch-entry
13232 (vhdl-warning-when-idle
13233 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13234 arch-name ent-name (nth 1 arch-entry)
13235 (nth 2 arch-entry) file-name (vhdl-current-line))
13236 (setq arch-list (cons arch-key arch-list)
13237 arch-ent-list (cons ent-key arch-ent-list))
13238 (aput 'arch-alist arch-key
13239 (list arch-name file-name (vhdl-current-line) nil
13240 lib-arch-alist))
13241 (aput 'ent-alist ent-key
13242 (list (or (nth 0 ent-entry) ent-name)
13243 (nth 1 ent-entry) (nth 2 ent-entry)
13244 (vhdl-sort-alist arch-alist)
0a2e512a 13245 arch-key (nth 5 ent-entry))))))
3dcb36b7
JB
13246 ;; scan for configurations
13247 (goto-char (point-min))
13248 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13249 (let* ((conf-name (match-string-no-properties 1))
13250 (conf-key (downcase conf-name))
13251 (conf-entry (aget conf-alist conf-key t))
13252 (ent-name (match-string-no-properties 2))
13253 (ent-key (downcase ent-name))
13254 (lib-alist (vhdl-scan-context-clause))
13255 (conf-line (vhdl-current-line))
13256 (end-of-unit (vhdl-get-end-of-unit))
13257 arch-key comp-conf-list inst-key-list
13258 inst-comp-key inst-ent-key inst-arch-key
13259 inst-conf-key inst-lib-key)
13260 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13261 (setq arch-key (vhdl-match-string-downcase 1)))
13262 (if conf-entry
13263 (vhdl-warning-when-idle
13264 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13265 conf-name ent-name (nth 1 conf-entry)
13266 (nth 2 conf-entry) file-name conf-line)
13267 (setq conf-list (cons conf-key conf-list))
13268 ;; scan for subconfigurations and subentities
13269 (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)
13270 (setq inst-comp-key (vhdl-match-string-downcase 3)
13271 inst-key-list (split-string
13272 (vhdl-match-string-downcase 1)
13273 "[ \t\n]*,[ \t\n]*"))
13274 (vhdl-forward-syntactic-ws)
13275 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13276 (setq
13277 inst-lib-key (vhdl-match-string-downcase 3)
13278 inst-ent-key (and (match-string 2)
13279 (vhdl-match-string-downcase 4))
13280 inst-arch-key (and (match-string 2)
13281 (vhdl-match-string-downcase 6))
13282 inst-conf-key (and (not (match-string 2))
13283 (vhdl-match-string-downcase 4)))
13284 (while inst-key-list
13285 (setq comp-conf-list
13286 (cons (list (car inst-key-list)
13287 inst-comp-key inst-ent-key
13288 inst-arch-key inst-conf-key
13289 inst-lib-key)
13290 comp-conf-list))
13291 (setq inst-key-list (cdr inst-key-list)))))
13292 (aput 'conf-alist conf-key
13293 (list conf-name file-name conf-line ent-key
13294 arch-key comp-conf-list lib-alist)))))
13295 ;; scan for packages
13296 (goto-char (point-min))
13297 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13298 (let* ((pack-name (match-string-no-properties 2))
13299 (pack-key (downcase pack-name))
13300 (is-body (match-string-no-properties 1))
13301 (pack-entry (aget pack-alist pack-key t))
13302 (pack-line (vhdl-current-line))
13303 (end-of-unit (vhdl-get-end-of-unit))
13304 comp-name func-name comp-alist func-alist lib-alist)
13305 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13306 (vhdl-warning-when-idle
13307 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13308 (if is-body " body" "") pack-name
13309 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13310 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13311 file-name (vhdl-current-line))
13312 ;; scan for context clauses
13313 (setq lib-alist (vhdl-scan-context-clause))
13314 ;; scan for component and subprogram declarations/bodies
13315 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13316 (if (equal (upcase (match-string 1)) "COMPONENT")
13317 (setq comp-name (match-string-no-properties 2)
13318 comp-alist
13319 (cons (list (downcase comp-name) comp-name
13320 file-name (vhdl-current-line))
13321 comp-alist))
13322 (setq func-name (match-string-no-properties 2)
13323 func-alist
13324 (cons (list (downcase func-name) func-name
13325 file-name (vhdl-current-line))
13326 func-alist))))
13327 (setq func-alist (nreverse func-alist))
13328 (setq comp-alist (nreverse comp-alist))
13329 (if is-body
13330 (setq pack-body-list (cons pack-key pack-body-list))
13331 (setq pack-list (cons pack-key pack-list)))
13332 (aput
13333 'pack-alist pack-key
13334 (if is-body
13335 (list (or (nth 0 pack-entry) pack-name)
13336 (nth 1 pack-entry) (nth 2 pack-entry)
13337 (nth 3 pack-entry) (nth 4 pack-entry)
13338 (nth 5 pack-entry)
13339 file-name pack-line func-alist lib-alist)
13340 (list pack-name file-name pack-line
13341 comp-alist func-alist lib-alist
13342 (nth 6 pack-entry) (nth 7 pack-entry)
13343 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13344 ;; scan for hierarchy
13345 (if (and limit-hier-file-size
13346 (< limit-hier-file-size (buffer-size)))
13347 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13348 (setq big-files t))
13349 ;; scan for architectures
13350 (goto-char (point-min))
13351 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13352 (let* ((ent-name (match-string-no-properties 2))
13353 (ent-key (downcase ent-name))
13354 (arch-name (match-string-no-properties 1))
13355 (arch-key (downcase arch-name))
13356 (ent-entry (aget ent-alist ent-key t))
13357 (arch-alist (nth 3 ent-entry))
13358 (arch-entry (aget arch-alist arch-key t))
13359 (beg-of-unit (point))
13360 (end-of-unit (vhdl-get-end-of-unit))
13361 (inst-no 0)
0a2e512a 13362 inst-alist inst-path)
3dcb36b7
JB
13363 ;; scan for contained instantiations
13364 (while (and (re-search-forward
13365 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13366 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13367 "component[ \t\n]+\\(\\w+\\)\\|"
0a2e512a
RF
13368 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13369 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13370 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
3dcb36b7
JB
13371 (or (not limit-hier-inst-no)
13372 (<= (setq inst-no (1+ inst-no))
13373 limit-hier-inst-no)))
0a2e512a
RF
13374 (cond
13375 ;; block/generate beginning found
13376 ((match-string 14)
13377 (setq inst-path
13378 (cons (match-string-no-properties 1) inst-path)))
13379 ;; block/generate end found
13380 ((match-string 16)
13381 (setq inst-path (cdr inst-path)))
13382 ;; instantiation found
13383 (t
13384 (let* ((inst-name (match-string-no-properties 1))
13385 (inst-key (downcase inst-name))
13386 (inst-comp-name
13387 (or (match-string-no-properties 3)
13388 (match-string-no-properties 6)))
13389 (inst-ent-key
13390 (or (and (match-string 8)
13391 (vhdl-match-string-downcase 11))
13392 (and inst-comp-name
13393 (downcase inst-comp-name))))
13394 (inst-arch-key (vhdl-match-string-downcase 13))
13395 (inst-conf-key
13396 (and (not (match-string 8))
13397 (vhdl-match-string-downcase 11)))
13398 (inst-lib-key (vhdl-match-string-downcase 10)))
13399 (goto-char (match-end 1))
13400 (setq inst-list (cons inst-key inst-list)
13401 inst-ent-list
13402 (cons inst-ent-key inst-ent-list))
13403 (setq inst-alist
13404 (append
13405 inst-alist
13406 (list (list inst-key inst-name file-name
13407 (vhdl-current-line) inst-comp-name
13408 inst-ent-key inst-arch-key
13409 inst-conf-key inst-lib-key
13410 (reverse inst-path)))))))))
3dcb36b7
JB
13411 ;; scan for contained configuration specifications
13412 (goto-char beg-of-unit)
13413 (while (re-search-forward
13414 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13415 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
0a2e512a 13416 (let* ((inst-comp-name (match-string-no-properties 3))
3dcb36b7
JB
13417 (inst-ent-key
13418 (and (match-string 6)
13419 (vhdl-match-string-downcase 9)))
13420 (inst-arch-key (vhdl-match-string-downcase 11))
13421 (inst-conf-key
13422 (and (not (match-string 6))
13423 (vhdl-match-string-downcase 9)))
13424 (inst-lib-key (vhdl-match-string-downcase 8))
13425 (inst-key-list
13426 (split-string (vhdl-match-string-downcase 1)
13427 "[ \t\n]*,[ \t\n]*"))
13428 (tmp-inst-alist inst-alist)
13429 inst-entry)
13430 (while tmp-inst-alist
13431 (when (and (or (equal "all" (car inst-key-list))
13432 (member (nth 0 (car tmp-inst-alist))
13433 inst-key-list))
13434 (equal
13435 (downcase
13436 (or (nth 4 (car tmp-inst-alist)) ""))
13437 (downcase inst-comp-name)))
13438 (setq inst-entry (car tmp-inst-alist))
13439 (setq inst-ent-list
13440 (cons (or inst-ent-key (nth 5 inst-entry))
13441 (vhdl-delete
13442 (nth 5 inst-entry) inst-ent-list)))
13443 (setq inst-entry
13444 (list (nth 0 inst-entry) (nth 1 inst-entry)
13445 (nth 2 inst-entry) (nth 3 inst-entry)
13446 (nth 4 inst-entry)
13447 (or inst-ent-key (nth 5 inst-entry))
13448 (or inst-arch-key (nth 6 inst-entry))
13449 inst-conf-key inst-lib-key))
13450 (setcar tmp-inst-alist inst-entry))
13451 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13452 ;; save in cache
13453 (aput 'arch-alist arch-key
13454 (list (nth 0 arch-entry) (nth 1 arch-entry)
13455 (nth 2 arch-entry) inst-alist
13456 (nth 4 arch-entry)))
13457 (aput 'ent-alist ent-key
13458 (list (nth 0 ent-entry) (nth 1 ent-entry)
13459 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
0a2e512a 13460 (nth 4 ent-entry) (nth 5 ent-entry)))
3dcb36b7
JB
13461 (when (and limit-hier-inst-no
13462 (> inst-no limit-hier-inst-no))
13463 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13464 (setq big-files t))
13465 (goto-char end-of-unit))))
13466 ;; remember design units for this file
13467 (aput 'file-alist file-name
13468 (list ent-list arch-list arch-ent-list conf-list
13469 pack-list pack-body-list inst-list inst-ent-list))
13470 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13471 (setq file-list (cdr file-list))))
13472 (when (or (and (not project) files-exist)
13473 (and project (not non-final)))
13474 ;; consistency checks:
13475 ;; check whether each architecture has a corresponding entity
13476 (setq tmp-list ent-alist)
13477 (while tmp-list
13478 (when (null (nth 2 (car tmp-list)))
13479 (setq tmp-entry (car (nth 4 (car tmp-list))))
13480 (vhdl-warning-when-idle
13481 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13482 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13483 (nth 3 tmp-entry)))
13484 (setq tmp-list (cdr tmp-list)))
13485 ;; check whether configuration has a corresponding entity/architecture
13486 (setq tmp-list conf-alist)
13487 (while tmp-list
13488 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13489 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13490 (setq tmp-entry (car tmp-list))
13491 (vhdl-warning-when-idle
13492 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13493 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13494 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13495 (setq tmp-entry (car tmp-list))
13496 (vhdl-warning-when-idle
13497 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13498 (nth 1 tmp-entry) (nth 4 tmp-entry)
13499 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13500 (setq tmp-list (cdr tmp-list)))
13501 ;; check whether each package body has a package declaration
13502 (setq tmp-list pack-alist)
13503 (while tmp-list
13504 (when (null (nth 2 (car tmp-list)))
13505 (setq tmp-entry (car tmp-list))
13506 (vhdl-warning-when-idle
13507 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13508 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13509 (setq tmp-list (cdr tmp-list)))
13510 ;; sort lists
13511 (setq ent-alist (vhdl-sort-alist ent-alist))
13512 (setq conf-alist (vhdl-sort-alist conf-alist))
13513 (setq pack-alist (vhdl-sort-alist pack-alist))
13514 ;; remember updated directory/project
13515 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13516 ;; clear directory alists
13517 (unless project
13518 (adelete 'vhdl-entity-alist key)
13519 (adelete 'vhdl-config-alist key)
13520 (adelete 'vhdl-package-alist key)
13521 (adelete 'vhdl-ent-inst-alist key)
13522 (adelete 'vhdl-file-alist key))
13523 ;; put directory contents into cache
13524 (aput 'vhdl-entity-alist key ent-alist)
13525 (aput 'vhdl-config-alist key conf-alist)
13526 (aput 'vhdl-package-alist key pack-alist)
13527 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13528 (aput 'vhdl-file-alist key file-alist)
13529 ;; final messages
13530 (message "Scanning %s %s\"%s\"...done"
13531 (if is-directory "directory" "files") (or num-string "") name)
13532 (unless project (message "Scanning directory...done"))
13533 (when big-files
13534 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13535 ;; save cache when scanned non-interactively
13536 (when (or (not project) (not non-final))
13537 (when (and noninteractive vhdl-speedbar-save-cache)
13538 (vhdl-save-cache key)))
13539 t))
5eabfe72 13540
3dcb36b7 13541(defun vhdl-scan-project-contents (project)
5eabfe72
KH
13542 "Scan the contents of all VHDL files found in the directories and files
13543of PROJECT."
3dcb36b7
JB
13544 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13545 (default-dir (vhdl-resolve-env-variable
13546 (nth 1 (aget vhdl-project-alist project))))
13547 (file-exclude-regexp
13548 (or (nth 3 (aget vhdl-project-alist project)) ""))
13549 dir-list-tmp dir dir-name num-dir act-dir recursive)
13550 ;; clear project alists
13551 (adelete 'vhdl-entity-alist project)
13552 (adelete 'vhdl-config-alist project)
13553 (adelete 'vhdl-package-alist project)
13554 (adelete 'vhdl-ent-inst-alist project)
13555 (adelete 'vhdl-file-alist project)
13556 ;; expand directory names by default-directory
13557 (message "Collecting source files...")
13558 (while dir-list
13559 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13560 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13561 (setq recursive (match-string 1 dir)
13562 dir-name (match-string 3 dir))
13563 (setq dir-list-tmp
13564 (cons (concat recursive
13565 (if (file-name-absolute-p dir-name) "" default-dir)
13566 dir-name)
13567 dir-list-tmp))
13568 (setq dir-list (cdr dir-list)))
13569 ;; resolve path wildcards
5eabfe72
KH
13570 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13571 ;; expand directories
13572 (while dir-list-tmp
13573 (setq dir (car dir-list-tmp))
13574 ;; get subdirectories
3dcb36b7 13575 (if (string-match "-r \\(.*[/\\]\\)" dir)
5eabfe72
KH
13576 (setq dir-list (append dir-list (vhdl-get-subdirs
13577 (match-string 1 dir))))
13578 (setq dir-list (append dir-list (list dir))))
13579 (setq dir-list-tmp (cdr dir-list-tmp)))
3dcb36b7
JB
13580 ;; exclude files
13581 (unless (equal file-exclude-regexp "")
13582 (let ((case-fold-search nil))
13583 (while dir-list
13584 (unless (string-match file-exclude-regexp (car dir-list))
13585 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13586 (setq dir-list (cdr dir-list)))
13587 (setq dir-list (nreverse dir-list-tmp))))
13588 (message "Collecting source files...done")
13589 ;; scan for design units for each directory in DIR-LIST
13590 (setq dir-list-tmp nil
13591 num-dir (length dir-list)
5eabfe72
KH
13592 act-dir 1)
13593 (while dir-list
3dcb36b7
JB
13594 (setq dir-name (abbreviate-file-name
13595 (expand-file-name (car dir-list))))
13596 (vhdl-scan-directory-contents dir-name project nil
13597 (format "(%s/%s) " act-dir num-dir)
13598 (cdr dir-list))
13599 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
5eabfe72
KH
13600 (setq dir-list (cdr dir-list)
13601 act-dir (1+ act-dir)))
3dcb36b7
JB
13602 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13603 (message "Scanning project \"%s\"...done" project)))
13604
13605(defun vhdl-update-file-contents (file-name)
13606 "Update hierarchy information by contents of current buffer."
13607 (setq file-name (abbreviate-file-name file-name))
13608 (let* ((dir-name (file-name-directory file-name))
13609 (directory-alist vhdl-directory-alist)
13610 updated)
13611 (while directory-alist
13612 (when (member dir-name (nth 1 (car directory-alist)))
13613 (let* ((vhdl-project (nth 0 (car directory-alist)))
13614 (project (vhdl-project-p))
13615 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13616 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13617 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13618 (ent-inst-list (car (aget vhdl-ent-inst-alist
13619 (or project dir-name) t)))
13620 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13621 (file-entry (aget file-alist file-name t))
13622 (ent-list (nth 0 file-entry))
13623 (arch-list (nth 1 file-entry))
13624 (arch-ent-list (nth 2 file-entry))
13625 (conf-list (nth 3 file-entry))
13626 (pack-list (nth 4 file-entry))
13627 (pack-body-list (nth 5 file-entry))
13628 (inst-ent-list (nth 7 file-entry))
13629 (cache-key (or project dir-name))
13630 arch-alist key ent-key entry)
13631 ;; delete design units previously contained in this file:
13632 ;; entities
13633 (while ent-list
13634 (setq key (car ent-list)
13635 entry (aget ent-alist key t))
13636 (when (equal file-name (nth 1 entry))
13637 (if (nth 3 entry)
13638 (aput 'ent-alist key
13639 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13640 (adelete 'ent-alist key)))
13641 (setq ent-list (cdr ent-list)))
13642 ;; architectures
13643 (while arch-list
13644 (setq key (car arch-list)
13645 ent-key (car arch-ent-list)
13646 entry (aget ent-alist ent-key t)
13647 arch-alist (nth 3 entry))
13648 (when (equal file-name (nth 1 (aget arch-alist key t)))
13649 (adelete 'arch-alist key)
13650 (if (or (nth 1 entry) arch-alist)
13651 (aput 'ent-alist ent-key
13652 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
0a2e512a 13653 arch-alist (nth 4 entry) (nth 5 entry)))
3dcb36b7
JB
13654 (adelete 'ent-alist ent-key)))
13655 (setq arch-list (cdr arch-list)
13656 arch-ent-list (cdr arch-ent-list)))
13657 ;; configurations
13658 (while conf-list
13659 (setq key (car conf-list))
13660 (when (equal file-name (nth 1 (aget conf-alist key t)))
13661 (adelete 'conf-alist key))
13662 (setq conf-list (cdr conf-list)))
13663 ;; package declarations
13664 (while pack-list
13665 (setq key (car pack-list)
13666 entry (aget pack-alist key t))
13667 (when (equal file-name (nth 1 entry))
13668 (if (nth 6 entry)
13669 (aput 'pack-alist key
13670 (list (nth 0 entry) nil nil nil nil nil
13671 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13672 (nth 9 entry)))
13673 (adelete 'pack-alist key)))
13674 (setq pack-list (cdr pack-list)))
13675 ;; package bodies
13676 (while pack-body-list
13677 (setq key (car pack-body-list)
13678 entry (aget pack-alist key t))
13679 (when (equal file-name (nth 6 entry))
13680 (if (nth 1 entry)
13681 (aput 'pack-alist key
13682 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13683 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13684 nil nil nil nil))
13685 (adelete 'pack-alist key)))
13686 (setq pack-body-list (cdr pack-body-list)))
13687 ;; instantiated entities
13688 (while inst-ent-list
13689 (setq ent-inst-list
13690 (vhdl-delete (car inst-ent-list) ent-inst-list))
13691 (setq inst-ent-list (cdr inst-ent-list)))
13692 ;; update caches
13693 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13694 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13695 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13696 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13697 ;; scan file
13698 (vhdl-scan-directory-contents file-name project t)
13699 (when (or (and vhdl-speedbar-show-projects project)
13700 (and (not vhdl-speedbar-show-projects) (not project)))
13701 (vhdl-speedbar-refresh project))
13702 (setq updated t)))
13703 (setq directory-alist (cdr directory-alist)))
13704 updated))
13705
13706(defun vhdl-update-hierarchy ()
13707 "Update directory and hierarchy information in speedbar."
13708 (let ((file-list (reverse vhdl-modified-file-list))
13709 updated)
13710 (when (and vhdl-speedbar-update-on-saving file-list)
13711 (while file-list
13712 (setq updated
13713 (or (vhdl-update-file-contents (car file-list))
13714 updated))
13715 (setq file-list (cdr file-list)))
13716 (setq vhdl-modified-file-list nil)
0a2e512a 13717 (vhdl-speedbar-update-current-unit)
3dcb36b7
JB
13718 (when updated (message "Updating hierarchy...done")))))
13719
13720;; structure (parenthesised expression means list of such entries)
13721;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13722;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13723;; comp-lib-name level)
13724(defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13725 conf-inst-alist level indent
13726 &optional include-top ent-hier)
13727 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13728entity ENT-KEY."
13729 (let* ((ent-entry (aget ent-alist ent-key t))
13730 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13731 (cdar (last (nth 3 ent-entry)))))
13732 (inst-alist (nth 3 arch-entry))
13733 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13734 hier-list subcomp-list tmp-list inst-key inst-comp-name
13735 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
5eabfe72 13736 (when (= level 0) (message "Extract design hierarchy..."))
3dcb36b7
JB
13737 (when include-top
13738 (setq level (1+ level)))
13739 (when (member ent-key ent-hier)
13740 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13741 ;; check configured architecture (already checked during scanning)
13742; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13743; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13744 ;; process all instances
13745 (while inst-alist
13746 (setq inst-entry (car inst-alist)
13747 inst-key (nth 0 inst-entry)
13748 inst-comp-name (nth 4 inst-entry)
13749 inst-conf-key (nth 7 inst-entry))
13750 ;; search entry in configuration's instantiations list
13751 (setq tmp-list conf-inst-alist)
13752 (while (and tmp-list
13753 (not (and (member (nth 0 (car tmp-list))
13754 (list "all" inst-key))
13755 (equal (nth 1 (car tmp-list))
13756 (downcase (or inst-comp-name ""))))))
13757 (setq tmp-list (cdr tmp-list)))
13758 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13759 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13760 (when (and inst-conf-key (not inst-conf-entry))
13761 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13762 ;; determine entity
13763 (setq inst-ent-key
13764 (or (nth 2 (car tmp-list)) ; from configuration
13765 (nth 3 inst-conf-entry) ; from subconfiguration
13766 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13767 ; from configuration spec.
13768 (nth 5 inst-entry))) ; from direct instantiation
13769 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13770 ;; determine architecture
13771 (setq inst-arch-key
0a2e512a
RF
13772 (or (nth 3 (car tmp-list)) ; from configuration
13773 (nth 4 inst-conf-entry) ; from subconfiguration
13774 (nth 6 inst-entry) ; from direct instantiation
3dcb36b7 13775 (nth 4 (aget conf-alist (nth 7 inst-entry)))
0a2e512a
RF
13776 ; from configuration spec.
13777 (nth 4 inst-ent-entry) ; MRA
13778 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
3dcb36b7
JB
13779 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13780 ;; set library
13781 (setq inst-lib-key
0a2e512a
RF
13782 (or (nth 5 (car tmp-list)) ; from configuration
13783 (nth 8 inst-entry))) ; from direct instantiation
3dcb36b7
JB
13784 ;; gather information for this instance
13785 (setq comp-entry
13786 (list (nth 1 inst-entry)
13787 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13788 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13789 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13790 (or (nth 0 inst-arch-entry) inst-arch-key)
13791 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13792 (or (nth 0 inst-conf-entry) inst-conf-key)
13793 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13794 inst-lib-key level))
13795 ;; get subcomponent hierarchy
13796 (setq subcomp-list (vhdl-get-hierarchy
13797 ent-alist conf-alist
13798 inst-ent-key inst-arch-key inst-conf-key
13799 (nth 5 inst-conf-entry)
13800 (1+ level) indent nil (cons ent-key ent-hier)))
13801 ;; add to list
13802 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13803 (setq inst-alist (cdr inst-alist)))
13804 (when include-top
5eabfe72 13805 (setq hier-list
3dcb36b7
JB
13806 (cons (list nil nil (nth 0 ent-entry)
13807 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13808 (nth 0 arch-entry)
13809 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13810 nil nil
13811 nil (1- level))
13812 hier-list)))
13813 (when (or (= level 0) (and include-top (= level 1))) (message ""))
5eabfe72
KH
13814 hier-list))
13815
3dcb36b7
JB
13816(defun vhdl-get-instantiations (ent-key indent)
13817 "Get all instantiations of entity ENT-KEY."
13818 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
5eabfe72
KH
13819 arch-alist inst-alist ent-inst-list
13820 ent-entry arch-entry inst-entry)
13821 (while ent-alist
13822 (setq ent-entry (car ent-alist))
3dcb36b7 13823 (setq arch-alist (nth 4 ent-entry))
5eabfe72
KH
13824 (while arch-alist
13825 (setq arch-entry (car arch-alist))
3dcb36b7 13826 (setq inst-alist (nth 4 arch-entry))
5eabfe72
KH
13827 (while inst-alist
13828 (setq inst-entry (car inst-alist))
3dcb36b7 13829 (when (equal ent-key (nth 5 inst-entry))
5eabfe72 13830 (setq ent-inst-list
3dcb36b7
JB
13831 (cons (list (nth 1 inst-entry)
13832 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13833 (nth 1 ent-entry)
13834 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13835 (nth 1 arch-entry)
13836 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13837 ent-inst-list)))
5eabfe72
KH
13838 (setq inst-alist (cdr inst-alist)))
13839 (setq arch-alist (cdr arch-alist)))
13840 (setq ent-alist (cdr ent-alist)))
13841 (nreverse ent-inst-list)))
13842
13843;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
13844;; Caching in file
13845
13846(defun vhdl-save-caches ()
13847 "Save all updated hierarchy caches to file."
13848 (interactive)
13849 (condition-case nil
13850 (when vhdl-speedbar-save-cache
13851 ;; update hierarchy
13852 (vhdl-update-hierarchy)
13853 (let ((project-list vhdl-updated-project-list))
13854 (message "Saving hierarchy caches...")
13855 ;; write updated project caches
13856 (while project-list
13857 (vhdl-save-cache (car project-list))
13858 (setq project-list (cdr project-list)))
13859 (message "Saving hierarchy caches...done")))
13860 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13861 (sit-for 2)))))
13862
13863(defun vhdl-save-cache (key)
13864 "Save current hierarchy cache to file."
13865 (let* ((orig-buffer (current-buffer))
13866 (vhdl-project key)
13867 (project (vhdl-project-p))
13868 (default-directory key)
13869 (directory (abbreviate-file-name (vhdl-default-directory)))
13870 (file-name (vhdl-resolve-env-variable
13871 (vhdl-replace-string
13872 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13873 (concat
13874 (subst-char-in-string ? ?_ (or project "dir"))
13875 " " (user-login-name)))))
13876 (file-dir-name (expand-file-name file-name directory))
13877 (cache-key (or project directory))
13878 (key (if project "project" "directory")))
13879 (unless (file-exists-p (file-name-directory file-dir-name))
13880 (make-directory (file-name-directory file-dir-name) t))
13881 (if (not (file-writable-p file-dir-name))
13882 (progn (vhdl-warning (format "File not writable: \"%s\""
13883 (abbreviate-file-name file-dir-name)))
13884 (sit-for 2))
13885 (message "Saving cache: \"%s\"" file-dir-name)
13886 (set-buffer (find-file-noselect file-dir-name t t))
13887 (erase-buffer)
13888 (insert ";; -*- Emacs-Lisp -*-\n\n"
13889 ";;; " (file-name-nondirectory file-name)
13890 " - design hierarchy cache file for Emacs VHDL Mode "
13891 vhdl-version "\n")
13892 (insert "\n;; " (if project "Project " "Directory") " : ")
13893 (if project (insert project) (prin1 directory (current-buffer)))
13894 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13895 (user-login-name) "\n\n"
13896 "\n;; version number\n"
13897 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13898 "\n;; " (if project "project" "directory") " name"
13899 "\n(setq " key " ")
13900 (prin1 (or project directory) (current-buffer))
13901 (insert ")\n")
13902 (when (member 'hierarchy vhdl-speedbar-save-cache)
13903 (insert "\n;; entity and architecture cache\n"
13904 "(aput 'vhdl-entity-alist " key " '")
13905 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13906 (insert ")\n\n;; configuration cache\n"
13907 "(aput 'vhdl-config-alist " key " '")
13908 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13909 (insert ")\n\n;; package cache\n"
13910 "(aput 'vhdl-package-alist " key " '")
13911 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13912 (insert ")\n\n;; instantiated entities cache\n"
13913 "(aput 'vhdl-ent-inst-alist " key " '")
13914 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13915 (insert ")\n\n;; design units per file cache\n"
13916 "(aput 'vhdl-file-alist " key " '")
13917 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13918 (when project
13919 (insert ")\n\n;; source directories in project cache\n"
13920 "(aput 'vhdl-directory-alist " key " '")
13921 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13922 (insert ")\n"))
13923 (when (member 'display vhdl-speedbar-save-cache)
13924 (insert "\n;; shown design units cache\n"
13925 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13926 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13927 (current-buffer))
13928 (insert ")\n"))
13929 (setq vhdl-updated-project-list
13930 (delete cache-key vhdl-updated-project-list))
13931 (save-buffer)
13932 (kill-buffer (current-buffer))
13933 (set-buffer orig-buffer))))
13934
13935(defun vhdl-load-cache (key)
13936 "Load hierarchy cache information from file."
13937 (let* ((vhdl-project key)
13938 (default-directory key)
13939 (directory (vhdl-default-directory))
13940 (file-name (vhdl-resolve-env-variable
13941 (vhdl-replace-string
13942 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13943 (concat
13944 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13945 " " (user-login-name)))))
13946 (file-dir-name (expand-file-name file-name directory))
13947 vhdl-cache-version)
13948 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13949 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13950 (when (file-exists-p file-dir-name)
13951 (condition-case ()
13952 (progn (load-file file-dir-name)
13953 (string< (mapconcat
027a4b6b 13954 (lambda (a) (format "%3d" (string-to-number a)))
0a2e512a 13955 (split-string "3.33" "\\.") "")
3dcb36b7 13956 (mapconcat
027a4b6b 13957 (lambda (a) (format "%3d" (string-to-number a)))
3dcb36b7
JB
13958 (split-string vhdl-cache-version "\\.") "")))
13959 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13960 nil))))))
13961
13962(defun vhdl-require-hierarchy-info ()
13963 "Make sure that hierarchy information is available. Load cache or scan files
13964if required."
13965 (if (vhdl-project-p)
13966 (unless (or (assoc vhdl-project vhdl-file-alist)
13967 (vhdl-load-cache vhdl-project))
13968 (vhdl-scan-project-contents vhdl-project))
13969 (let ((directory (abbreviate-file-name default-directory)))
13970 (unless (or (assoc directory vhdl-file-alist)
13971 (vhdl-load-cache directory))
13972 (vhdl-scan-directory-contents directory)))))
13973
13974;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13975;; Add hierarchy browser functionality to speedbar
5eabfe72
KH
13976
13977(defvar vhdl-speedbar-key-map nil
13978 "Keymap used when in the VHDL hierarchy browser mode.")
13979
3dcb36b7 13980(defvar vhdl-speedbar-menu-items nil
5eabfe72
KH
13981 "Additional menu-items to add to speedbar frame.")
13982
13983(defun vhdl-speedbar-initialize ()
13984 "Initialize speedbar."
13985 ;; general settings
13986; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13987 ;; VHDL file extensions (extracted from `auto-mode-alist')
13988 (let ((mode-alist auto-mode-alist))
13989 (while mode-alist
3dcb36b7
JB
13990 (when (eq (cdar mode-alist) 'vhdl-mode)
13991 (speedbar-add-supported-extension (caar mode-alist)))
5eabfe72
KH
13992 (setq mode-alist (cdr mode-alist))))
13993 ;; hierarchy browser settings
13994 (when (boundp 'speedbar-mode-functions-list)
3dcb36b7 13995 ;; special functions
5eabfe72 13996 (speedbar-add-mode-functions-list
3dcb36b7 13997 '("vhdl directory"
5eabfe72
KH
13998 (speedbar-item-info . vhdl-speedbar-item-info)
13999 (speedbar-line-path . speedbar-files-line-path)))
3dcb36b7
JB
14000 (speedbar-add-mode-functions-list
14001 '("vhdl project"
14002 (speedbar-item-info . vhdl-speedbar-item-info)
14003 (speedbar-line-path . vhdl-speedbar-line-project)))
14004 ;; keymap
5eabfe72
KH
14005 (unless vhdl-speedbar-key-map
14006 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
14007 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14008 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14009 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
3dcb36b7
JB
14010 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14011 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14012 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14013 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14014 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
0a2e512a
RF
14015 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14016 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
3dcb36b7
JB
14017 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14018 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14019 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14020 (let ((key 0))
14021 (while (<= key 9)
14022 (define-key vhdl-speedbar-key-map (int-to-string key)
14023 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14024 (setq key (1+ key)))))
5eabfe72
KH
14025 (define-key speedbar-key-map "h"
14026 (lambda () (interactive)
3dcb36b7
JB
14027 (speedbar-change-initial-expansion-list "vhdl directory")))
14028 (define-key speedbar-key-map "H"
14029 (lambda () (interactive)
14030 (speedbar-change-initial-expansion-list "vhdl project")))
14031 ;; menu
14032 (unless vhdl-speedbar-menu-items
14033 (setq
14034 vhdl-speedbar-menu-items
14035 `(["Edit" speedbar-edit-line t]
14036 ["Expand" speedbar-expand-line
14037 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14038 ["Contract" vhdl-speedbar-contract-level t]
14039 ["Expand All" vhdl-speedbar-expand-all t]
14040 ["Contract All" vhdl-speedbar-contract-all t]
14041 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14042 (while (<= key 9)
14043 (setq menu-list
14044 (cons `[,(if (= key 0) "All" (int-to-string key))
14045 (vhdl-speedbar-set-depth ,key)
14046 :style radio
14047 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14048 :keys ,(int-to-string key)]
14049 menu-list))
14050 (setq key (1+ key)))
14051 (nreverse menu-list))
14052 "--"
14053 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14054 (or (vhdl-speedbar-check-unit 'entity)
14055 (vhdl-speedbar-check-unit 'subprogram))]
14056 ["Place Component" vhdl-speedbar-place-component
14057 (vhdl-speedbar-check-unit 'entity)]
0a2e512a
RF
14058 ["Generate Configuration" vhdl-speedbar-configuration
14059 (vhdl-speedbar-check-unit 'architecture)]
14060 ["Select as MRA" vhdl-speedbar-select-mra
14061 (vhdl-speedbar-check-unit 'architecture)]
3dcb36b7
JB
14062 ["Make" vhdl-speedbar-make-design
14063 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14064 ["Generate Makefile" vhdl-speedbar-generate-makefile
14065 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14066 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14067 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14068 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
14069 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14070 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14071 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
14072 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14073 ;; hook-ups
14074 (speedbar-add-expansion-list
14075 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14076 vhdl-speedbar-display-directory))
14077 (speedbar-add-expansion-list
14078 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14079 vhdl-speedbar-display-projects))
5eabfe72 14080 (setq speedbar-stealthy-function-list
3dcb36b7
JB
14081 (append
14082 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14083 ("vhdl project" vhdl-speedbar-update-current-project
14084 vhdl-speedbar-update-current-unit)
14085; ("files" (lambda () (setq speedbar-ignored-path-regexp
14086; (speedbar-extension-list-to-regex
14087; speedbar-ignored-path-expressions))))
14088 )
14089 speedbar-stealthy-function-list))
14090 (when (eq vhdl-speedbar-display-mode 'directory)
14091 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14092 (when (eq vhdl-speedbar-display-mode 'project)
14093 (setq speedbar-initial-expansion-list-name "vhdl project"))
14094 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
5eabfe72
KH
14095
14096(defun vhdl-speedbar (&optional arg)
14097 "Open/close speedbar."
d2ddb974 14098 (interactive)
5eabfe72 14099 (if (not (fboundp 'speedbar))
3dcb36b7
JB
14100 (error "WARNING: Speedbar is not available or not installed")
14101 (condition-case ()
5eabfe72 14102 (speedbar-frame-mode arg)
3dcb36b7 14103 (error (error "WARNING: An error occurred while opening speedbar")))))
5eabfe72
KH
14104
14105;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14106;; Display functions
14107
3dcb36b7
JB
14108(defvar vhdl-speedbar-last-selected-project nil
14109 "Name of last selected project.")
14110
5eabfe72
KH
14111;; macros must be defined in the file they are used (copied from `speedbar.el')
14112(defmacro speedbar-with-writable (&rest forms)
14113 "Allow the buffer to be writable and evaluate FORMS."
14114 (list 'let '((inhibit-read-only t))
14115 (cons 'progn forms)))
14116(put 'speedbar-with-writable 'lisp-indent-function 0)
14117
3dcb36b7 14118(defun vhdl-speedbar-display-directory (directory depth &optional rescan)
5eabfe72 14119 "Display directory and hierarchy information in speedbar."
3dcb36b7
JB
14120 (setq vhdl-speedbar-show-projects nil)
14121 (setq speedbar-ignored-path-regexp
14122 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
5eabfe72
KH
14123 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14124 (setq speedbar-last-selected-file nil)
14125 (speedbar-with-writable
3dcb36b7
JB
14126 (condition-case nil
14127 (progn
14128 ;; insert directory path
14129 (speedbar-directory-buttons directory depth)
14130 ;; insert subdirectories
14131 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14132 ;; scan and insert hierarchy of current directory
14133 (vhdl-speedbar-insert-dir-hierarchy directory depth
14134 speedbar-power-click)
14135 ;; expand subdirectories
14136 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14137 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14138
14139(defun vhdl-speedbar-display-projects (project depth &optional rescan)
14140 "Display projects and hierarchy information in speedbar."
14141 (setq vhdl-speedbar-show-projects t)
14142 (setq speedbar-ignored-path-regexp ".")
14143 (setq speedbar-last-selected-file nil)
14144 (setq vhdl-speedbar-last-selected-project nil)
14145 (speedbar-with-writable
14146 (condition-case nil
14147 ;; insert projects
14148 (vhdl-speedbar-insert-projects)
14149 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14150 (setq speedbar-full-text-cache nil)) ; prevent caching
14151
14152(defun vhdl-speedbar-insert-projects ()
14153 "Insert all projects in speedbar."
14154 (vhdl-speedbar-make-title-line "Projects:")
14155 (let ((project-alist (if vhdl-project-sort
14156 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14157 vhdl-project-alist))
14158 (vhdl-speedbar-update-current-unit nil))
14159 ;; insert projects
14160 (while project-alist
14161 (speedbar-make-tag-line
14162 'angle ?+ 'vhdl-speedbar-expand-project
14163 (caar project-alist) (caar project-alist)
14164 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14165 (setq project-alist (cdr project-alist)))
14166 (setq project-alist vhdl-project-alist)
14167 ;; expand projects
14168 (while project-alist
14169 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14170 (goto-char (point-min))
14171 (when (re-search-forward
14172 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14173 (goto-char (match-end 1))
14174 (speedbar-do-function-pointer)))
14175 (setq project-alist (cdr project-alist))))
14176; (vhdl-speedbar-update-current-project)
14177; (vhdl-speedbar-update-current-unit nil t)
14178 )
14179
14180(defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14181 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
14182otherwise use cached data."
14183 (when (or rescan (and (not (assoc project vhdl-file-alist))
14184 (not (vhdl-load-cache project))))
14185 (vhdl-scan-project-contents project))
14186 ;; insert design hierarchy
14187 (vhdl-speedbar-insert-hierarchy
14188 (aget vhdl-entity-alist project t)
14189 (aget vhdl-config-alist project t)
14190 (aget vhdl-package-alist project t)
14191 (car (aget vhdl-ent-inst-alist project t)) indent)
14192 (insert (int-to-string indent) ":\n")
14193 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14194 (put-text-property (1- (point)) (point) 'invisible nil)
14195 ;; expand design units
14196 (vhdl-speedbar-expand-units project))
14197
14198(defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14199 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14200otherwise use cached data."
14201 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14202 (not (vhdl-load-cache directory))))
14203 (vhdl-scan-directory-contents directory))
14204 ;; insert design hierarchy
14205 (vhdl-speedbar-insert-hierarchy
14206 (aget vhdl-entity-alist directory t)
14207 (aget vhdl-config-alist directory t)
14208 (aget vhdl-package-alist directory t)
14209 (car (aget vhdl-ent-inst-alist directory t)) depth)
14210 ;; expand design units
14211 (vhdl-speedbar-expand-units directory)
14212 (aput 'vhdl-directory-alist directory (list (list directory))))
14213
14214(defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
5eabfe72 14215 ent-inst-list depth)
3dcb36b7
JB
14216 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14217 (if (not (or ent-alist conf-alist pack-alist))
14218 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14219 (let (ent-entry conf-entry pack-entry)
5eabfe72
KH
14220 ;; insert entities
14221 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14222 (while ent-alist
14223 (setq ent-entry (car ent-alist))
14224 (speedbar-make-tag-line
14225 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
3dcb36b7
JB
14226 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14227 (cons (nth 2 ent-entry) (nth 3 ent-entry))
0a2e512a 14228 'vhdl-speedbar-entity-face depth)
3dcb36b7
JB
14229 (unless (nth 2 ent-entry)
14230 (end-of-line 0) (insert "!") (forward-char 1))
14231 (unless (member (nth 0 ent-entry) ent-inst-list)
5eabfe72
KH
14232 (end-of-line 0) (insert " (top)") (forward-char 1))
14233 (setq ent-alist (cdr ent-alist)))
3dcb36b7
JB
14234 ;; insert configurations
14235 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14236 (while conf-alist
14237 (setq conf-entry (car conf-alist))
14238 (speedbar-make-tag-line
14239 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14240 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14241 (cons (nth 2 conf-entry) (nth 3 conf-entry))
0a2e512a 14242 'vhdl-speedbar-configuration-face depth)
3dcb36b7 14243 (setq conf-alist (cdr conf-alist)))
5eabfe72
KH
14244 ;; insert packages
14245 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14246 (while pack-alist
14247 (setq pack-entry (car pack-alist))
14248 (vhdl-speedbar-make-pack-line
3dcb36b7
JB
14249 (nth 0 pack-entry) (nth 1 pack-entry)
14250 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14251 (cons (nth 7 pack-entry) (nth 8 pack-entry))
5eabfe72
KH
14252 depth)
14253 (setq pack-alist (cdr pack-alist))))))
14254
5eabfe72 14255(defun vhdl-speedbar-rescan-hierarchy ()
3dcb36b7 14256 "Rescan hierarchy for the directory or project under the cursor."
d2ddb974 14257 (interactive)
3dcb36b7
JB
14258 (let (key path)
14259 (cond
14260 ;; current project
14261 (vhdl-speedbar-show-projects
14262 (setq key (vhdl-speedbar-line-project))
14263 (vhdl-scan-project-contents key))
14264 ;; top-level directory
14265 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14266 (re-search-forward "[0-9]+:" nil t)
14267 (vhdl-scan-directory-contents
14268 (abbreviate-file-name (speedbar-line-path))))
14269 ;; current directory
14270 (t (setq path (speedbar-line-path))
14271 (string-match "^\\(.+[/\\]\\)" path)
14272 (vhdl-scan-directory-contents
14273 (abbreviate-file-name (match-string 1 path)))))
14274 (vhdl-speedbar-refresh key)))
5eabfe72
KH
14275
14276(defun vhdl-speedbar-expand-dirs (directory)
14277 "Expand subdirectories in DIRECTORY according to
14278 `speedbar-shown-directories'."
14279 ;; (nicked from `speedbar-default-directory-list')
3dcb36b7
JB
14280 (let ((sf (cdr (reverse speedbar-shown-directories)))
14281 (vhdl-speedbar-update-current-unit nil))
5eabfe72
KH
14282 (setq speedbar-shown-directories
14283 (list (expand-file-name default-directory)))
14284 (while sf
14285 (when (speedbar-goto-this-file (car sf))
14286 (beginning-of-line)
14287 (when (looking-at "[0-9]+:\\s-*<")
14288 (goto-char (match-end 0))
3dcb36b7
JB
14289 (speedbar-do-function-pointer)))
14290 (setq sf (cdr sf))))
14291 (vhdl-speedbar-update-current-unit nil t))
14292
14293(defun vhdl-speedbar-expand-units (key)
14294 "Expand design units in directory/project KEY according to
14295`vhdl-speedbar-shown-unit-alist'."
14296 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14297 (vhdl-speedbar-update-current-unit nil)
14298 vhdl-updated-project-list)
14299 (adelete 'vhdl-speedbar-shown-unit-alist key)
14300 (vhdl-prepare-search-1
14301 (while unit-alist ; expand units
14302 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14303 (beginning-of-line)
14304 (let ((arch-alist (nth 1 (car unit-alist)))
14305 position)
14306 (when (looking-at "^[0-9]+:\\s-*\\[")
14307 (goto-char (match-end 0))
14308 (setq position (point))
14309 (speedbar-do-function-pointer)
14310 (select-frame speedbar-frame)
14311 (while arch-alist ; expand architectures
14312 (goto-char position)
14313 (when (re-search-forward
14314 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14315 (car arch-alist) "\\>\\)") nil t)
14316 (beginning-of-line)
14317 (when (looking-at "^[0-9]+:\\s-*{")
14318 (goto-char (match-end 0))
14319 (speedbar-do-function-pointer)
14320 (select-frame speedbar-frame)))
14321 (setq arch-alist (cdr arch-alist))))
14322 (setq unit-alist (cdr unit-alist))))))
14323 (vhdl-speedbar-update-current-unit nil t))
14324
14325(defun vhdl-speedbar-contract-level ()
14326 "Contract current level in current directory/project."
14327 (interactive)
14328 (when (or (save-excursion
14329 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14330 (and (save-excursion
14331 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14332 (re-search-backward
14333 (format "^[0-%d]:\\s-*[[{<]-"
027a4b6b 14334 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
3dcb36b7
JB
14335 (goto-char (match-end 0))
14336 (speedbar-do-function-pointer)
14337 (speedbar-center-buffer-smartly)))
14338
14339(defun vhdl-speedbar-contract-all ()
14340 "Contract all expanded design units in current directory/project."
14341 (interactive)
14342 (if (and vhdl-speedbar-show-projects
14343 (save-excursion (beginning-of-line) (looking-at "^0:")))
14344 (progn (setq vhdl-speedbar-shown-project-list nil)
14345 (vhdl-speedbar-refresh))
14346 (let ((key (vhdl-speedbar-line-key)))
14347 (adelete 'vhdl-speedbar-shown-unit-alist key)
14348 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14349 (when (memq 'display vhdl-speedbar-save-cache)
14350 (add-to-list 'vhdl-updated-project-list key)))))
14351
14352(defun vhdl-speedbar-expand-all ()
14353 "Expand all design units in current directory/project."
14354 (interactive)
14355 (let* ((key (vhdl-speedbar-line-key))
14356 (ent-alist (aget vhdl-entity-alist key t))
14357 (conf-alist (aget vhdl-config-alist key t))
14358 (pack-alist (aget vhdl-package-alist key t))
14359 arch-alist unit-alist subunit-alist)
14360 (add-to-list 'vhdl-speedbar-shown-project-list key)
14361 (while ent-alist
14362 (setq arch-alist (nth 4 (car ent-alist)))
14363 (setq subunit-alist nil)
14364 (while arch-alist
14365 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14366 (setq arch-alist (cdr arch-alist)))
14367 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14368 (setq ent-alist (cdr ent-alist)))
14369 (while conf-alist
14370 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14371 (setq conf-alist (cdr conf-alist)))
14372 (while pack-alist
14373 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14374 (setq pack-alist (cdr pack-alist)))
14375 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14376 (vhdl-speedbar-refresh)
14377 (when (memq 'display vhdl-speedbar-save-cache)
14378 (add-to-list 'vhdl-updated-project-list key))))
14379
14380(defun vhdl-speedbar-expand-project (text token indent)
14381 "Expand/contract the project under the cursor."
14382 (cond
14383 ((string-match "+" text) ; expand project
14384 (speedbar-change-expand-button-char ?-)
14385 (unless (member token vhdl-speedbar-shown-project-list)
14386 (setq vhdl-speedbar-shown-project-list
14387 (cons token vhdl-speedbar-shown-project-list)))
14388 (speedbar-with-writable
14389 (save-excursion
14390 (end-of-line) (forward-char 1)
14391 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14392 speedbar-power-click))))
14393 ((string-match "-" text) ; contract project
14394 (speedbar-change-expand-button-char ?+)
14395 (setq vhdl-speedbar-shown-project-list
14396 (delete token vhdl-speedbar-shown-project-list))
14397 (speedbar-delete-subblock indent))
14398 (t (error "Nothing to display")))
14399 (when (equal (selected-frame) speedbar-frame)
14400 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14401
14402(defun vhdl-speedbar-expand-entity (text token indent)
14403 "Expand/contract the entity under the cursor."
14404 (cond
14405 ((string-match "+" text) ; expand entity
3dcb36b7
JB
14406 (let* ((key (vhdl-speedbar-line-key indent))
14407 (ent-alist (aget vhdl-entity-alist key t))
14408 (ent-entry (aget ent-alist token t))
14409 (arch-alist (nth 3 ent-entry))
5eabfe72 14410 (inst-alist (vhdl-get-instantiations token indent))
0a2e512a
RF
14411 (subpack-alist (nth 5 ent-entry))
14412 (multiple-arch (> (length arch-alist) 1))
3dcb36b7
JB
14413 arch-entry inst-entry)
14414 (if (not (or arch-alist inst-alist subpack-alist))
5eabfe72
KH
14415 (speedbar-change-expand-button-char ??)
14416 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14417 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14418 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14419 (aput 'unit-alist token nil)
14420 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72 14421 (speedbar-with-writable
3dcb36b7
JB
14422 (save-excursion
14423 (end-of-line) (forward-char 1)
14424 ;; insert architectures
14425 (when arch-alist
14426 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14427 (while arch-alist
14428 (setq arch-entry (car arch-alist))
14429 (speedbar-make-tag-line
14430 'curly ?+ 'vhdl-speedbar-expand-architecture
14431 (cons token (nth 0 arch-entry))
14432 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14433 (cons (nth 2 arch-entry) (nth 3 arch-entry))
0a2e512a
RF
14434 'vhdl-speedbar-architecture-face (1+ indent))
14435 (when (and multiple-arch
14436 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14437 (end-of-line 0) (insert " (mra)") (forward-char 1))
3dcb36b7
JB
14438 (setq arch-alist (cdr arch-alist)))
14439 ;; insert instantiations
14440 (when inst-alist
14441 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14442 (while inst-alist
14443 (setq inst-entry (car inst-alist))
14444 (vhdl-speedbar-make-inst-line
14445 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14446 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14447 nil nil nil (1+ indent) 0 " in ")
14448 (setq inst-alist (cdr inst-alist)))
14449 ;; insert required packages
14450 (vhdl-speedbar-insert-subpackages
14451 subpack-alist (1+ indent) indent)))
14452 (when (memq 'display vhdl-speedbar-save-cache)
14453 (add-to-list 'vhdl-updated-project-list key))
14454 (vhdl-speedbar-update-current-unit t t))))
5eabfe72
KH
14455 ((string-match "-" text) ; contract entity
14456 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14457 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14458 (let* ((key (vhdl-speedbar-line-key indent))
14459 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14460 (adelete 'unit-alist token)
14461 (if unit-alist
14462 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14463 (adelete 'vhdl-speedbar-shown-unit-alist key))
14464 (speedbar-delete-subblock indent)
14465 (when (memq 'display vhdl-speedbar-save-cache)
14466 (add-to-list 'vhdl-updated-project-list key))))
14467 (t (error "Nothing to display")))
14468 (when (equal (selected-frame) speedbar-frame)
14469 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14470
14471(defun vhdl-speedbar-expand-architecture (text token indent)
14472 "Expand/contract the architecture under the cursor."
14473 (cond
14474 ((string-match "+" text) ; expand architecture
3dcb36b7
JB
14475 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14476 (ent-alist (aget vhdl-entity-alist key t))
14477 (conf-alist (aget vhdl-config-alist key t))
14478 (hier-alist (vhdl-get-hierarchy
14479 ent-alist conf-alist (car token) (cdr token) nil nil
14480 0 (1- indent)))
14481 (ent-entry (aget ent-alist (car token) t))
14482 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14483 (subpack-alist (nth 4 arch-entry))
14484 entry)
14485 (if (not (or hier-alist subpack-alist))
14486 (speedbar-change-expand-button-char ??)
14487 (speedbar-change-expand-button-char ?-)
14488 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14489 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14490 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14491 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14492 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14493 (speedbar-with-writable
14494 (save-excursion
14495 (end-of-line) (forward-char 1)
14496 ;; insert instance hierarchy
14497 (when hier-alist
14498 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14499 (1+ indent)))
14500 (while hier-alist
14501 (setq entry (car hier-alist))
14502 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14503 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14504 (vhdl-speedbar-make-inst-line
14505 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14506 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14507 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14508 (setq hier-alist (cdr hier-alist)))
14509 ;; insert required packages
14510 (vhdl-speedbar-insert-subpackages
14511 subpack-alist (1+ indent) (1- indent))))
14512 (when (memq 'display vhdl-speedbar-save-cache)
14513 (add-to-list 'vhdl-updated-project-list key))
14514 (vhdl-speedbar-update-current-unit t t))))
14515 ((string-match "-" text) ; contract architecture
14516 (speedbar-change-expand-button-char ?+)
14517 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14518 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14519 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14520 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14521 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14522 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14523 (speedbar-delete-subblock indent)
14524 (when (memq 'display vhdl-speedbar-save-cache)
14525 (add-to-list 'vhdl-updated-project-list key))))
14526 (t (error "Nothing to display")))
14527 (when (equal (selected-frame) speedbar-frame)
14528 (speedbar-center-buffer-smartly)))
14529
14530(defun vhdl-speedbar-expand-config (text token indent)
14531 "Expand/contract the configuration under the cursor."
14532 (cond
14533 ((string-match "+" text) ; expand configuration
14534 (let* ((key (vhdl-speedbar-line-key indent))
14535 (conf-alist (aget vhdl-config-alist key t))
14536 (conf-entry (aget conf-alist token))
14537 (ent-alist (aget vhdl-entity-alist key t))
14538 (hier-alist (vhdl-get-hierarchy
14539 ent-alist conf-alist (nth 3 conf-entry)
14540 (nth 4 conf-entry) token (nth 5 conf-entry)
14541 0 indent t))
14542 (subpack-alist (nth 6 conf-entry))
14543 entry)
14544 (if (not (or hier-alist subpack-alist))
5eabfe72
KH
14545 (speedbar-change-expand-button-char ??)
14546 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14547 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14548 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14549 (aput 'unit-alist token nil)
14550 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72
KH
14551 (speedbar-with-writable
14552 (save-excursion
14553 (end-of-line) (forward-char 1)
14554 ;; insert instance hierarchy
14555 (when hier-alist
3dcb36b7 14556 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
5eabfe72 14557 (while hier-alist
3dcb36b7
JB
14558 (setq entry (car hier-alist))
14559 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14560 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
5eabfe72 14561 (vhdl-speedbar-make-inst-line
3dcb36b7
JB
14562 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14563 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14564 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14565 (setq hier-alist (cdr hier-alist)))
14566 ;; insert required packages
14567 (vhdl-speedbar-insert-subpackages
14568 subpack-alist (1+ indent) indent)))
14569 (when (memq 'display vhdl-speedbar-save-cache)
14570 (add-to-list 'vhdl-updated-project-list key))
14571 (vhdl-speedbar-update-current-unit t t))))
14572 ((string-match "-" text) ; contract configuration
5eabfe72 14573 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14574 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14575 (let* ((key (vhdl-speedbar-line-key indent))
14576 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14577 (adelete 'unit-alist token)
14578 (if unit-alist
14579 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14580 (adelete 'vhdl-speedbar-shown-unit-alist key))
14581 (speedbar-delete-subblock indent)
14582 (when (memq 'display vhdl-speedbar-save-cache)
14583 (add-to-list 'vhdl-updated-project-list key))))
14584 (t (error "Nothing to display")))
14585 (when (equal (selected-frame) speedbar-frame)
14586 (speedbar-center-buffer-smartly)))
14587
14588(defun vhdl-speedbar-expand-package (text token indent)
14589 "Expand/contract the package under the cursor."
14590 (cond
14591 ((string-match "+" text) ; expand package
14592 (let* ((key (vhdl-speedbar-line-key indent))
14593 (pack-alist (aget vhdl-package-alist key t))
14594 (pack-entry (aget pack-alist token t))
14595 (comp-alist (nth 3 pack-entry))
14596 (func-alist (nth 4 pack-entry))
14597 (func-body-alist (nth 8 pack-entry))
14598 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14599 comp-entry func-entry func-body-entry)
14600 (if (not (or comp-alist func-alist subpack-alist))
14601 (speedbar-change-expand-button-char ??)
14602 (speedbar-change-expand-button-char ?-)
14603 ;; add package to `vhdl-speedbar-shown-unit-alist'
14604 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14605 (aput 'unit-alist token nil)
14606 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14607 (speedbar-with-writable
14608 (save-excursion
14609 (end-of-line) (forward-char 1)
14610 ;; insert components
14611 (when comp-alist
14612 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14613 (while comp-alist
14614 (setq comp-entry (car comp-alist))
14615 (speedbar-make-tag-line
14616 nil nil nil
14617 (cons token (nth 0 comp-entry))
14618 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14619 (cons (nth 2 comp-entry) (nth 3 comp-entry))
0a2e512a 14620 'vhdl-speedbar-entity-face (1+ indent))
3dcb36b7
JB
14621 (setq comp-alist (cdr comp-alist)))
14622 ;; insert subprograms
14623 (when func-alist
14624 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14625 (while func-alist
14626 (setq func-entry (car func-alist)
14627 func-body-entry (aget func-body-alist (car func-entry) t))
14628 (when (nth 2 func-entry)
14629 (vhdl-speedbar-make-subprogram-line
14630 (nth 1 func-entry)
14631 (cons (nth 2 func-entry) (nth 3 func-entry))
14632 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14633 (1+ indent)))
14634 (setq func-alist (cdr func-alist)))
14635 ;; insert required packages
14636 (vhdl-speedbar-insert-subpackages
14637 subpack-alist (1+ indent) indent)))
14638 (when (memq 'display vhdl-speedbar-save-cache)
14639 (add-to-list 'vhdl-updated-project-list key))
14640 (vhdl-speedbar-update-current-unit t t))))
14641 ((string-match "-" text) ; contract package
14642 (speedbar-change-expand-button-char ?+)
14643 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14644 (let* ((key (vhdl-speedbar-line-key indent))
14645 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14646 (adelete 'unit-alist token)
14647 (if unit-alist
14648 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14649 (adelete 'vhdl-speedbar-shown-unit-alist key))
14650 (speedbar-delete-subblock indent)
14651 (when (memq 'display vhdl-speedbar-save-cache)
14652 (add-to-list 'vhdl-updated-project-list key))))
14653 (t (error "Nothing to display")))
14654 (when (equal (selected-frame) speedbar-frame)
14655 (speedbar-center-buffer-smartly)))
14656
14657(defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14658 "Insert required packages."
14659 (let* ((pack-alist (aget vhdl-package-alist
14660 (vhdl-speedbar-line-key dir-indent) t))
14661 pack-key lib-name pack-entry)
14662 (when subpack-alist
14663 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14664 (while subpack-alist
14665 (setq pack-key (cdar subpack-alist)
14666 lib-name (caar subpack-alist))
14667 (setq pack-entry (aget pack-alist pack-key t))
14668 (vhdl-speedbar-make-subpack-line
14669 (or (nth 0 pack-entry) pack-key) lib-name
0a2e512a
RF
14670 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14671 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
3dcb36b7 14672 (setq subpack-alist (cdr subpack-alist)))))
5eabfe72
KH
14673
14674;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14675;; Display help functions
14676
3dcb36b7
JB
14677(defvar vhdl-speedbar-update-current-unit t
14678 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14679
14680(defun vhdl-speedbar-update-current-project ()
14681 "Highlight project that is currently active."
14682 (when (and vhdl-speedbar-show-projects
14683 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14684 (and (boundp 'speedbar-frame)
14685 (frame-live-p speedbar-frame)))
14686 (let ((last-frame (selected-frame))
14687 (project-alist vhdl-project-alist)
14688 pos)
14689 (select-frame speedbar-frame)
14690 (speedbar-with-writable
14691 (save-excursion
14692 (while project-alist
14693 (goto-char (point-min))
14694 (when (re-search-forward
14695 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14696 (put-text-property (match-beginning 1) (match-end 1) 'face
14697 (if (equal (caar project-alist) vhdl-project)
14698 'speedbar-selected-face
14699 'speedbar-directory-face))
14700 (when (equal (caar project-alist) vhdl-project)
14701 (setq pos (1- (match-beginning 1)))))
14702 (setq project-alist (cdr project-alist))))
14703 (when pos (goto-char pos)))
14704 (select-frame last-frame)
14705 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14706 t)
14707
14708(defun vhdl-speedbar-update-current-unit (&optional no-position always)
5eabfe72
KH
14709 "Highlight all design units that are contained in the current file.
14710NO-POSITION non-nil means do not re-position cursor."
14711 (let ((last-frame (selected-frame))
3dcb36b7
JB
14712 (project-list vhdl-speedbar-shown-project-list)
14713 file-alist pos file-name)
5eabfe72 14714 ;; get current file name
3dcb36b7
JB
14715 (if (fboundp 'speedbar-select-attached-frame)
14716 (speedbar-select-attached-frame)
14717 (select-frame speedbar-attached-frame))
5eabfe72 14718 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
3dcb36b7
JB
14719 (when (and vhdl-speedbar-update-current-unit
14720 (or always (not (equal file-name speedbar-last-selected-file))))
14721 (if vhdl-speedbar-show-projects
14722 (while project-list
14723 (setq file-alist (append file-alist (aget vhdl-file-alist
14724 (car project-list) t)))
14725 (setq project-list (cdr project-list)))
14726 (setq file-alist (aget vhdl-file-alist
14727 (abbreviate-file-name default-directory) t)))
5eabfe72
KH
14728 (select-frame speedbar-frame)
14729 (set-buffer speedbar-buffer)
14730 (speedbar-with-writable
3dcb36b7 14731 (vhdl-prepare-search-1
5eabfe72
KH
14732 (save-excursion
14733 ;; unhighlight last units
3dcb36b7 14734 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
5eabfe72 14735 (vhdl-speedbar-update-units
3dcb36b7 14736 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14737 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
5eabfe72 14738 (vhdl-speedbar-update-units
3dcb36b7 14739 "{.} " (nth 1 file-entry)
0a2e512a 14740 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
5eabfe72 14741 (vhdl-speedbar-update-units
3dcb36b7 14742 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14743 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
5eabfe72 14744 (vhdl-speedbar-update-units
3dcb36b7 14745 "[]>] " (nth 4 file-entry)
0a2e512a 14746 speedbar-last-selected-file 'vhdl-speedbar-package-face)
5eabfe72 14747 (vhdl-speedbar-update-units
3dcb36b7 14748 "\\[.\\].+(" '("body")
0a2e512a 14749 speedbar-last-selected-file 'vhdl-speedbar-package-face)
3dcb36b7
JB
14750 (vhdl-speedbar-update-units
14751 "> " (nth 6 file-entry)
0a2e512a 14752 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
5eabfe72 14753 ;; highlight current units
3dcb36b7
JB
14754 (let* ((file-entry (aget file-alist file-name t)))
14755 (setq
14756 pos (vhdl-speedbar-update-units
14757 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14758 file-name 'vhdl-speedbar-entity-selected-face pos)
3dcb36b7
JB
14759 pos (vhdl-speedbar-update-units
14760 "{.} " (nth 1 file-entry)
0a2e512a 14761 file-name 'vhdl-speedbar-architecture-selected-face pos)
3dcb36b7
JB
14762 pos (vhdl-speedbar-update-units
14763 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14764 file-name 'vhdl-speedbar-configuration-selected-face pos)
3dcb36b7
JB
14765 pos (vhdl-speedbar-update-units
14766 "[]>] " (nth 4 file-entry)
0a2e512a 14767 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14768 pos (vhdl-speedbar-update-units
14769 "\\[.\\].+(" '("body")
0a2e512a 14770 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14771 pos (vhdl-speedbar-update-units
14772 "> " (nth 6 file-entry)
0a2e512a 14773 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
5eabfe72 14774 ;; move speedbar so the first highlighted unit is visible
3dcb36b7
JB
14775 (when (and pos (not no-position))
14776 (goto-char pos)
14777 (speedbar-center-buffer-smartly)
5eabfe72
KH
14778 (speedbar-position-cursor-on-line))
14779 (setq speedbar-last-selected-file file-name))
14780 (select-frame last-frame)
14781 t))
14782
3dcb36b7
JB
14783(defun vhdl-speedbar-update-units (text unit-list file-name face
14784 &optional pos)
5eabfe72 14785 "Help function to highlight design units."
3dcb36b7
JB
14786 (while unit-list
14787 (goto-char (point-min))
14788 (while (re-search-forward
14789 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14790 (when (equal file-name (car (get-text-property
14791 (match-beginning 1) 'speedbar-token)))
14792 (setq pos (or pos (point-marker)))
14793 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14794 (setq unit-list (cdr unit-list)))
14795 pos)
5eabfe72
KH
14796
14797(defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
3dcb36b7
JB
14798 ent-name ent-file-marker
14799 arch-name arch-file-marker
14800 conf-name conf-file-marker
14801 lib-name depth offset delimiter)
5eabfe72 14802 "Insert instantiation entry."
3dcb36b7
JB
14803 (let ((start (point))
14804 visible-start)
5eabfe72
KH
14805 (insert (int-to-string depth) ":")
14806 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14807 (setq visible-start (point))
14808 (insert-char ? (* depth speedbar-indentation-width))
14809 (while (> offset 0)
14810 (insert "|")
14811 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14812 (setq offset (1- offset)))
14813 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14814 (setq start (point))
3dcb36b7
JB
14815 (insert ">")
14816 (speedbar-make-button start (point) nil nil nil)
14817 (setq visible-start (point))
14818 (insert " ")
5eabfe72 14819 (setq start (point))
3dcb36b7
JB
14820 (if (not inst-name)
14821 (insert "(top)")
14822 (insert inst-name)
14823 (speedbar-make-button
0a2e512a 14824 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
3dcb36b7
JB
14825 'vhdl-speedbar-find-file inst-file-marker))
14826 (insert delimiter)
14827 (when ent-name
5eabfe72 14828 (setq start (point))
3dcb36b7 14829 (insert ent-name)
5eabfe72 14830 (speedbar-make-button
0a2e512a 14831 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
3dcb36b7
JB
14832 'vhdl-speedbar-find-file ent-file-marker)
14833 (when arch-name
14834 (insert " (")
14835 (setq start (point))
14836 (insert arch-name)
14837 (speedbar-make-button
0a2e512a 14838 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
3dcb36b7
JB
14839 'vhdl-speedbar-find-file arch-file-marker)
14840 (insert ")"))
14841 (when conf-name
14842 (insert " (")
14843 (setq start (point))
14844 (insert conf-name)
14845 (speedbar-make-button
0a2e512a 14846 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
3dcb36b7
JB
14847 'vhdl-speedbar-find-file conf-file-marker)
14848 (insert ")")))
14849 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
5eabfe72 14850 (setq start (point))
3dcb36b7
JB
14851 (insert " (" lib-name ")")
14852 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14853 'vhdl-speedbar-library-face))
5eabfe72 14854 (insert-char ?\n 1)
3dcb36b7 14855 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14856
3dcb36b7
JB
14857(defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14858 body-file-marker depth)
5eabfe72 14859 "Insert package entry."
3dcb36b7
JB
14860 (let ((start (point))
14861 visible-start)
5eabfe72
KH
14862 (insert (int-to-string depth) ":")
14863 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14864 (setq visible-start (point))
14865 (insert-char ? (* depth speedbar-indentation-width))
14866 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14867 (setq start (point))
3dcb36b7
JB
14868 (insert "[+]")
14869 (speedbar-make-button
14870 start (point) 'speedbar-button-face 'speedbar-highlight-face
14871 'vhdl-speedbar-expand-package pack-key)
14872 (setq visible-start (point))
14873 (insert-char ? 1 nil)
5eabfe72
KH
14874 (setq start (point))
14875 (insert pack-name)
14876 (speedbar-make-button
0a2e512a 14877 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14878 'vhdl-speedbar-find-file pack-file-marker)
3dcb36b7
JB
14879 (unless (car pack-file-marker)
14880 (insert "!"))
5eabfe72 14881 (when (car body-file-marker)
5eabfe72 14882 (insert " (")
5eabfe72
KH
14883 (setq start (point))
14884 (insert "body")
14885 (speedbar-make-button
0a2e512a 14886 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14887 'vhdl-speedbar-find-file body-file-marker)
3dcb36b7 14888 (insert ")"))
5eabfe72 14889 (insert-char ?\n 1)
3dcb36b7 14890 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14891
3dcb36b7 14892(defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
0a2e512a 14893 pack-body-file-marker depth)
3dcb36b7
JB
14894 "Insert used package entry."
14895 (let ((start (point))
14896 visible-start)
14897 (insert (int-to-string depth) ":")
14898 (put-text-property start (point) 'invisible t)
14899 (setq visible-start (point))
14900 (insert-char ? (* depth speedbar-indentation-width))
14901 (put-text-property visible-start (point) 'invisible nil)
14902 (setq start (point))
14903 (insert ">")
14904 (speedbar-make-button start (point) nil nil nil)
14905 (setq visible-start (point))
14906 (insert " ")
14907 (setq start (point))
14908 (insert pack-name)
14909 (speedbar-make-button
0a2e512a 14910 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
3dcb36b7 14911 'vhdl-speedbar-find-file pack-file-marker)
0a2e512a
RF
14912 (when (car pack-body-file-marker)
14913 (insert " (")
14914 (setq start (point))
14915 (insert "body")
14916 (speedbar-make-button
14917 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14918 'vhdl-speedbar-find-file pack-body-file-marker)
14919 (insert ")"))
3dcb36b7
JB
14920 (setq start (point))
14921 (insert " (" lib-name ")")
14922 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14923 'vhdl-speedbar-library-face)
3dcb36b7
JB
14924 (insert-char ?\n 1)
14925 (put-text-property visible-start (point) 'invisible nil)))
14926
14927(defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14928 func-body-file-marker
14929 depth)
14930 "Insert subprogram entry."
14931 (let ((start (point))
14932 visible-start)
5eabfe72
KH
14933 (insert (int-to-string depth) ":")
14934 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14935 (setq visible-start (point))
14936 (insert-char ? (* depth speedbar-indentation-width))
14937 (put-text-property visible-start (point) 'invisible nil)
14938 (setq start (point))
14939 (insert ">")
14940 (speedbar-make-button start (point) nil nil nil)
14941 (setq visible-start (point))
14942 (insert " ")
5eabfe72 14943 (setq start (point))
3dcb36b7
JB
14944 (insert func-name)
14945 (speedbar-make-button
0a2e512a 14946 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14947 'vhdl-speedbar-find-file func-file-marker)
14948 (when (car func-body-file-marker)
14949 (insert " (")
14950 (setq start (point))
14951 (insert "body")
14952 (speedbar-make-button
0a2e512a 14953 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14954 'vhdl-speedbar-find-file func-body-file-marker)
14955 (insert ")"))
14956 (insert-char ?\n 1)
14957 (put-text-property visible-start (point) 'invisible nil)))
14958
14959(defun vhdl-speedbar-make-title-line (text &optional depth)
14960 "Insert design unit title entry."
14961 (let ((start (point))
14962 visible-start)
14963 (when depth
14964 (insert (int-to-string depth) ":")
14965 (put-text-property start (point) 'invisible t))
14966 (setq visible-start (point))
14967 (insert-char ? (* (or depth 0) speedbar-indentation-width))
5eabfe72
KH
14968 (setq start (point))
14969 (insert text)
14970 (speedbar-make-button start (point) nil nil nil nil)
14971 (insert-char ?\n 1)
3dcb36b7 14972 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72
KH
14973
14974(defun vhdl-speedbar-insert-dirs (files level)
14975 "Insert subdirectories."
14976 (let ((dirs (car files)))
14977 (while dirs
14978 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14979 (car dirs) 'speedbar-dir-follow nil
14980 'speedbar-directory-face level)
14981 (setq dirs (cdr dirs)))))
14982
14983(defun vhdl-speedbar-dired (text token indent)
14984 "Speedbar click handler for directory expand button in hierarchy mode."
14985 (cond ((string-match "+" text) ; we have to expand this dir
14986 (setq speedbar-shown-directories
14987 (cons (expand-file-name
14988 (concat (speedbar-line-path indent) token "/"))
14989 speedbar-shown-directories))
14990 (speedbar-change-expand-button-char ?-)
14991 (speedbar-reset-scanners)
14992 (speedbar-with-writable
14993 (save-excursion
14994 (end-of-line) (forward-char 1)
14995 (vhdl-speedbar-insert-dirs
14996 (speedbar-file-lists
14997 (concat (speedbar-line-path indent) token "/"))
14998 (1+ indent))
14999 (speedbar-reset-scanners)
15000 (vhdl-speedbar-insert-dir-hierarchy
15001 (abbreviate-file-name
15002 (concat (speedbar-line-path indent) token "/"))
15003 (1+ indent) speedbar-power-click)))
3dcb36b7 15004 (vhdl-speedbar-update-current-unit t t))
5eabfe72
KH
15005 ((string-match "-" text) ; we have to contract this node
15006 (speedbar-reset-scanners)
15007 (let ((oldl speedbar-shown-directories)
15008 (newl nil)
15009 (td (expand-file-name
15010 (concat (speedbar-line-path indent) token))))
15011 (while oldl
15012 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15013 (setq newl (cons (car oldl) newl)))
15014 (setq oldl (cdr oldl)))
15015 (setq speedbar-shown-directories (nreverse newl)))
15016 (speedbar-change-expand-button-char ?+)
15017 (speedbar-delete-subblock indent))
3dcb36b7
JB
15018 (t (error "Nothing to display")))
15019 (when (equal (selected-frame) speedbar-frame)
15020 (speedbar-center-buffer-smartly)))
5eabfe72
KH
15021
15022(defun vhdl-speedbar-item-info ()
15023 "Derive and display information about this line item."
15024 (save-excursion
15025 (beginning-of-line)
15026 ;; skip invisible number info
3dcb36b7 15027 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
5eabfe72 15028 (cond
3dcb36b7
JB
15029 ;; project/directory entry
15030 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15031 (if vhdl-speedbar-show-projects
15032 (message "Project \"%s\"" (match-string-no-properties 1))
15033 (speedbar-files-item-info)))
5eabfe72 15034 ;; design unit entry
3dcb36b7
JB
15035 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15036 (goto-char (match-end 1))
5eabfe72
KH
15037 (let ((face (get-text-property (point) 'face)))
15038 (message
15039 "%s \"%s\" in \"%s\""
15040 ;; design unit kind
0a2e512a
RF
15041 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15042 (eq face 'vhdl-speedbar-entity-selected-face))
3dcb36b7 15043 (if (equal (match-string 2) ">") "Component" "Entity"))
0a2e512a
RF
15044 ((or (eq face 'vhdl-speedbar-architecture-face)
15045 (eq face 'vhdl-speedbar-architecture-selected-face))
5eabfe72 15046 "Architecture")
0a2e512a
RF
15047 ((or (eq face 'vhdl-speedbar-configuration-face)
15048 (eq face 'vhdl-speedbar-configuration-selected-face))
5eabfe72 15049 "Configuration")
0a2e512a
RF
15050 ((or (eq face 'vhdl-speedbar-package-face)
15051 (eq face 'vhdl-speedbar-package-selected-face))
5eabfe72 15052 "Package")
0a2e512a
RF
15053 ((or (eq face 'vhdl-speedbar-instantiation-face)
15054 (eq face 'vhdl-speedbar-instantiation-selected-face))
5eabfe72 15055 "Instantiation")
0a2e512a 15056 ((eq face 'vhdl-speedbar-subprogram-face)
3dcb36b7 15057 "Subprogram")
5eabfe72
KH
15058 (t ""))
15059 ;; design unit name
15060 (buffer-substring-no-properties
3dcb36b7
JB
15061 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15062 (match-end 1))
5eabfe72 15063 ;; file name
3dcb36b7
JB
15064 (file-relative-name
15065 (or (car (get-text-property (point) 'speedbar-token))
15066 "?")
15067 (vhdl-default-directory)))))
15068 (t (message "")))))
15069
15070(defun vhdl-speedbar-line-text ()
15071 "Calls `speedbar-line-text' and removes text properties."
15072 (let ((string (speedbar-line-text)))
15073 (set-text-properties 0 (length string) nil string)
15074 string))
5eabfe72 15075
0a2e512a
RF
15076(defun vhdl-speedbar-higher-text ()
15077 "Get speedbar-line-text of higher level."
15078 (let (depth string)
15079 (save-excursion
15080 (beginning-of-line)
15081 (looking-at "^\\([0-9]+\\):")
15082 (setq depth (string-to-number (match-string 1)))
15083 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15084 (setq string (match-string 1))
15085 (set-text-properties 0 (length string) nil string)
15086 string))))
15087
5eabfe72
KH
15088;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15089;; Help functions
d2ddb974 15090
3dcb36b7
JB
15091(defun vhdl-speedbar-line-key (&optional indent)
15092 "Get currently displayed directory of project name."
15093 (if vhdl-speedbar-show-projects
15094 (vhdl-speedbar-line-project)
15095 (abbreviate-file-name
15096 (file-name-as-directory (speedbar-line-path indent)))))
15097
15098(defun vhdl-speedbar-line-project (&optional indent)
15099 "Get currently displayed project name."
15100 (and vhdl-speedbar-show-projects
15101 (save-excursion
15102 (end-of-line)
15103 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15104 (match-string-no-properties 1))))
15105
15106(defun vhdl-add-modified-file ()
15107 "Add file to `vhdl-modified-file-list'."
15108 (when vhdl-file-alist
15109 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15110 nil)
5eabfe72
KH
15111
15112(defun vhdl-resolve-paths (path-list)
3dcb36b7
JB
15113 "Resolve path wildcards in PATH-LIST."
15114 (let (path-list-1 path-list-2 path-beg path-end dir)
15115 ;; eliminate non-existent directories
5eabfe72
KH
15116 (while path-list
15117 (setq dir (car path-list))
3dcb36b7
JB
15118 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15119 (if (file-directory-p (match-string 2 dir))
15120 (setq path-list-1 (cons dir path-list-1))
15121 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
5eabfe72 15122 (setq path-list (cdr path-list)))
3dcb36b7 15123 ;; resolve path wildcards
5eabfe72
KH
15124 (while path-list-1
15125 (setq dir (car path-list-1))
3dcb36b7 15126 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
5eabfe72
KH
15127 (progn
15128 (setq path-beg (match-string 1 dir)
15129 path-end (match-string 5 dir))
3dcb36b7 15130 (setq path-list-1
5eabfe72
KH
15131 (append
15132 (mapcar
15133 (function
15134 (lambda (var) (concat path-beg var path-end)))
15135 (let ((all-list (vhdl-directory-files
15136 (match-string 2 dir) t
15137 (concat "\\<" (wildcard-to-regexp
15138 (match-string 4 dir)))))
15139 dir-list)
15140 (while all-list
15141 (when (file-directory-p (car all-list))
15142 (setq dir-list (cons (car all-list) dir-list)))
15143 (setq all-list (cdr all-list)))
15144 dir-list))
3dcb36b7
JB
15145 (cdr path-list-1))))
15146 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
5eabfe72 15147 (when (file-directory-p (match-string 2 dir))
3dcb36b7
JB
15148 (setq path-list-2 (cons dir path-list-2)))
15149 (setq path-list-1 (cdr path-list-1))))
15150 (nreverse path-list-2)))
5eabfe72
KH
15151
15152(defun vhdl-speedbar-goto-this-unit (directory unit)
15153 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15154 (let ((dest (point)))
3dcb36b7 15155 (if (and (if vhdl-speedbar-show-projects
5eabfe72
KH
15156 (progn (goto-char (point-min)) t)
15157 (speedbar-goto-this-file directory))
15158 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15159 (progn (speedbar-position-cursor-on-line)
15160 t)
15161 (goto-char dest)
15162 nil)))
15163
15164(defun vhdl-speedbar-find-file (text token indent)
3dcb36b7
JB
15165 "When user clicks on TEXT, load file with name and position in TOKEN.
15166Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15167is already shown in a buffer."
5eabfe72 15168 (if (not (car token))
3dcb36b7
JB
15169 (error "ERROR: File cannot be found")
15170 (let ((buffer (get-file-buffer (car token))))
15171 (speedbar-find-file-in-frame (car token))
15172 (when (or vhdl-speedbar-jump-to-unit buffer)
15173 (goto-line (cdr token))
15174 (recenter))
15175 (vhdl-speedbar-update-current-unit t t)
15176 (speedbar-set-timer speedbar-update-speed)
15177 (speedbar-maybee-jump-to-attached-frame))))
5eabfe72
KH
15178
15179(defun vhdl-speedbar-port-copy ()
3dcb36b7 15180 "Copy the port of the entity/component or subprogram under the cursor."
5eabfe72 15181 (interactive)
3dcb36b7
JB
15182 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15183 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15184 (error "ERROR: No entity/component or subprogram under cursor")
15185 (beginning-of-line)
15186 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15187 (condition-case info
15188 (let ((token (get-text-property
15189 (match-beginning 3) 'speedbar-token)))
15190 (vhdl-visit-file (car token) t
15191 (progn (goto-line (cdr token))
15192 (end-of-line)
15193 (if is-entity
15194 (vhdl-port-copy)
15195 (vhdl-subprog-copy)))))
15196 (error (error "ERROR: %s not scanned successfully\n (%s)"
15197 (if is-entity "Port" "Interface") (cadr info))))
15198 (error "ERROR: No entity/component or subprogram on current line")))))
15199
15200(defun vhdl-speedbar-place-component ()
15201 "Place the entity/component under the cursor as component."
15202 (interactive)
15203 (if (not (vhdl-speedbar-check-unit 'entity))
5bb5087f 15204 (error "ERROR: No entity/component under cursor")
3dcb36b7
JB
15205 (vhdl-speedbar-port-copy)
15206 (if (fboundp 'speedbar-select-attached-frame)
15207 (speedbar-select-attached-frame)
15208 (select-frame speedbar-attached-frame))
15209 (vhdl-compose-place-component)
15210 (select-frame speedbar-frame)))
15211
0a2e512a
RF
15212(defun vhdl-speedbar-configuration ()
15213 "Generate configuration for the architecture under the cursor."
15214 (interactive)
15215 (if (not (vhdl-speedbar-check-unit 'architecture))
15216 (error "ERROR: No architecture under cursor")
15217 (let ((arch-name (vhdl-speedbar-line-text))
15218 (ent-name (vhdl-speedbar-higher-text)))
15219 (if (fboundp 'speedbar-select-attached-frame)
15220 (speedbar-select-attached-frame)
15221 (select-frame speedbar-attached-frame))
15222 (vhdl-compose-configuration ent-name arch-name))))
15223
15224(defun vhdl-speedbar-select-mra ()
15225 "Select the architecture under the cursor as MRA."
15226 (interactive)
15227 (if (not (vhdl-speedbar-check-unit 'architecture))
15228 (error "ERROR: No architecture under cursor")
15229 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15230 (ent-key (downcase (vhdl-speedbar-higher-text)))
15231 (ent-alist (aget vhdl-entity-alist
15232 (or (vhdl-project-p) default-directory) t))
15233 (ent-entry (aget ent-alist ent-key t)))
15234 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15235 (speedbar-refresh))))
15236
3dcb36b7
JB
15237(defun vhdl-speedbar-make-design ()
15238 "Make (compile) design unit or directory/project under the cursor."
15239 (interactive)
15240 (if (not (save-excursion (beginning-of-line)
15241 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15242 (error "ERROR: No primary design unit or directory/project under cursor")
15243 (let ((is-unit (match-string 2))
15244 (unit-name (vhdl-speedbar-line-text))
15245 (vhdl-project (vhdl-speedbar-line-project))
15246 (directory (file-name-as-directory
15247 (or (speedbar-line-file) (speedbar-line-path)))))
15248 (if (fboundp 'speedbar-select-attached-frame)
15249 (speedbar-select-attached-frame)
15250 (select-frame speedbar-attached-frame))
15251 (let ((default-directory directory))
15252 (vhdl-make (and is-unit unit-name))))))
15253
15254(defun vhdl-speedbar-generate-makefile ()
15255 "Generate Makefile for directory/project under the cursor."
15256 (interactive)
15257 (let ((vhdl-project (vhdl-speedbar-line-project))
15258 (default-directory (file-name-as-directory
15259 (or (speedbar-line-file) (speedbar-line-path)))))
15260 (vhdl-generate-makefile)))
15261
15262(defun vhdl-speedbar-check-unit (design-unit)
15263 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15264expansion function)."
15265 (save-excursion
15266 (speedbar-position-cursor-on-line)
15267 (cond ((eq design-unit 'entity)
15268 (memq (get-text-property (match-end 0) 'face)
0a2e512a
RF
15269 '(vhdl-speedbar-entity-face
15270 vhdl-speedbar-entity-selected-face)))
15271 ((eq design-unit 'architecture)
15272 (memq (get-text-property (match-end 0) 'face)
15273 '(vhdl-speedbar-architecture-face
15274 vhdl-speedbar-architecture-selected-face)))
3dcb36b7
JB
15275 ((eq design-unit 'subprogram)
15276 (eq (get-text-property (match-end 0) 'face)
0a2e512a 15277 'vhdl-speedbar-subprogram-face))
3dcb36b7
JB
15278 (t nil))))
15279
15280(defun vhdl-speedbar-set-depth (depth)
15281 "Set hierarchy display depth to DEPTH and refresh speedbar."
15282 (setq vhdl-speedbar-hierarchy-depth depth)
15283 (speedbar-refresh))
5eabfe72
KH
15284
15285;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15286;; Fontification
15287
0a2e512a 15288(defface vhdl-speedbar-entity-face
5eabfe72
KH
15289 '((((class color) (background light)) (:foreground "ForestGreen"))
15290 (((class color) (background dark)) (:foreground "PaleGreen")))
15291 "Face used for displaying entity names."
15292 :group 'speedbar-faces)
15293
0a2e512a 15294(defface vhdl-speedbar-architecture-face
f47877ee
DN
15295 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15296 (((class color) (background light)) (:foreground "Blue"))
84c98ace 15297
5eabfe72
KH
15298 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15299 "Face used for displaying architecture names."
15300 :group 'speedbar-faces)
d2ddb974 15301
0a2e512a 15302(defface vhdl-speedbar-configuration-face
5eabfe72
KH
15303 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15304 (((class color) (background dark)) (:foreground "Salmon")))
15305 "Face used for displaying configuration names."
15306 :group 'speedbar-faces)
15307
0a2e512a 15308(defface vhdl-speedbar-package-face
5eabfe72
KH
15309 '((((class color) (background light)) (:foreground "Grey50"))
15310 (((class color) (background dark)) (:foreground "Grey80")))
15311 "Face used for displaying package names."
15312 :group 'speedbar-faces)
15313
0a2e512a 15314(defface vhdl-speedbar-library-face
3dcb36b7
JB
15315 '((((class color) (background light)) (:foreground "Purple"))
15316 (((class color) (background dark)) (:foreground "Orchid1")))
15317 "Face used for displaying library names."
15318 :group 'speedbar-faces)
15319
0a2e512a 15320(defface vhdl-speedbar-instantiation-face
5eabfe72 15321 '((((class color) (background light)) (:foreground "Brown"))
ea81d57e 15322 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
5eabfe72
KH
15323 (((class color) (background dark)) (:foreground "Yellow")))
15324 "Face used for displaying instantiation names."
15325 :group 'speedbar-faces)
15326
0a2e512a 15327(defface vhdl-speedbar-subprogram-face
3dcb36b7
JB
15328 '((((class color) (background light)) (:foreground "Orchid4"))
15329 (((class color) (background dark)) (:foreground "BurlyWood2")))
15330 "Face used for displaying subprogram names."
15331 :group 'speedbar-faces)
15332
0a2e512a 15333(defface vhdl-speedbar-entity-selected-face
5eabfe72
KH
15334 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15335 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15336 "Face used for displaying entity names."
15337 :group 'speedbar-faces)
15338
0a2e512a 15339(defface vhdl-speedbar-architecture-selected-face
f47877ee
DN
15340 '((((min-colors 88) (class color) (background light)) (:foreground
15341 "Blue1" :underline t))
15342 (((class color) (background light)) (:foreground "Blue" :underline t))
5eabfe72
KH
15343 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15344 "Face used for displaying architecture names."
15345 :group 'speedbar-faces)
15346
0a2e512a 15347(defface vhdl-speedbar-configuration-selected-face
5eabfe72
KH
15348 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15349 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15350 "Face used for displaying configuration names."
15351 :group 'speedbar-faces)
15352
0a2e512a 15353(defface vhdl-speedbar-package-selected-face
5eabfe72
KH
15354 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15355 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15356 "Face used for displaying package names."
15357 :group 'speedbar-faces)
15358
0a2e512a 15359(defface vhdl-speedbar-instantiation-selected-face
5eabfe72
KH
15360 '((((class color) (background light)) (:foreground "Brown" :underline t))
15361 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15362 "Face used for displaying instantiation names."
15363 :group 'speedbar-faces)
15364
3dcb36b7
JB
15365;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15366;; Initialization
15367
15368;; add speedbar
15369(when (fboundp 'speedbar)
15370 (condition-case ()
15371 (when (and vhdl-speedbar-auto-open
15372 (not (and (boundp 'speedbar-frame)
15373 (frame-live-p speedbar-frame))))
15374 (speedbar-frame-mode 1)
15375 (if (fboundp 'speedbar-select-attached-frame)
15376 (speedbar-select-attached-frame)
15377 (select-frame speedbar-attached-frame)))
15378 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15379
15380;; initialize speedbar
15381(if (not (boundp 'speedbar-frame))
15382 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15383 (vhdl-speedbar-initialize)
15384 (when speedbar-frame (vhdl-speedbar-refresh)))
15385
15386
15387;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15388;;; Structural composition
15389;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15390
15391(defun vhdl-get-components-package-name ()
15392 "Return the name of the components package."
15393 (let ((project (vhdl-project-p)))
15394 (if project
15395 (vhdl-replace-string (car vhdl-components-package-name)
15396 (subst-char-in-string ? ?_ project))
15397 (cdr vhdl-components-package-name))))
15398
15399(defun vhdl-compose-new-component ()
15400 "Create entity and architecture for new component."
15401 (interactive)
15402 (let* ((case-fold-search t)
15403 (ent-name (read-from-minibuffer "entity name: "
15404 nil vhdl-minibuffer-local-map))
15405 (arch-name
15406 (if (equal (cdr vhdl-compose-architecture-name) "")
15407 (read-from-minibuffer "architecture name: "
15408 nil vhdl-minibuffer-local-map)
15409 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15410 ent-file-name arch-file-name ent-buffer arch-buffer project)
15411 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15412 ;; open entity file
15413 (unless (eq vhdl-compose-create-files 'none)
15414 (setq ent-file-name
0a2e512a 15415 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15416 "." (file-name-extension (buffer-file-name))))
15417 (when (and (file-exists-p ent-file-name)
15418 (not (y-or-n-p (concat "File \"" ent-file-name
15419 "\" exists; overwrite? "))))
15420 (error "ERROR: Creating component...aborted"))
15421 (find-file ent-file-name)
15422 (erase-buffer)
15423 (set-buffer-modified-p nil))
15424 ;; insert header
15425 (if vhdl-compose-include-header
15426 (progn (vhdl-template-header)
15427 (goto-char (point-max)))
15428 (vhdl-comment-display-line) (insert "\n\n"))
15429 ;; insert library clause
15430 (vhdl-template-package-std-logic-1164)
15431 (when vhdl-use-components-package
15432 (insert "\n")
15433 (vhdl-template-standard-package (vhdl-work-library)
15434 (vhdl-get-components-package-name)))
15435 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15436 ;; insert entity declaration
15437 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15438 (vhdl-insert-keyword " IS\n")
15439 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15440 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15441 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15442 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15443 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15444 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15445 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15446 (vhdl-insert-keyword "END ")
15447 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15448 (insert ent-name ";\n\n")
15449 (vhdl-comment-display-line) (insert "\n")
15450 ;; open architecture file
15451 (if (not (eq vhdl-compose-create-files 'separate))
15452 (insert "\n")
15453 (setq ent-buffer (current-buffer))
15454 (setq arch-file-name
15455 (concat (vhdl-replace-string vhdl-architecture-file-name
0a2e512a 15456 (concat ent-name " " arch-name) t)
3dcb36b7
JB
15457 "." (file-name-extension (buffer-file-name))))
15458 (when (and (file-exists-p arch-file-name)
15459 (not (y-or-n-p (concat "File \"" arch-file-name
15460 "\" exists; overwrite? "))))
15461 (error "ERROR: Creating component...aborted"))
15462 (find-file arch-file-name)
15463 (erase-buffer)
15464 (set-buffer-modified-p nil)
15465 ;; insert header
15466 (if vhdl-compose-include-header
15467 (progn (vhdl-template-header)
15468 (goto-char (point-max)))
15469 (vhdl-comment-display-line) (insert "\n\n")))
15470 ;; insert architecture body
15471 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15472 (vhdl-insert-keyword " OF ") (insert ent-name)
15473 (vhdl-insert-keyword " IS\n\n")
15474 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15475 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15476 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15477 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15478 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15479 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15480 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15481 (vhdl-insert-keyword "BEGIN")
15482 (when vhdl-self-insert-comments
15483 (insert " -- ")
15484 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15485 (insert arch-name))
15486 (insert "\n\n")
15487 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15488 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15489 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15490 (vhdl-insert-keyword "END ")
15491 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15492 (insert arch-name ";\n\n")
0a2e512a 15493 ;; insert footer and save
3dcb36b7
JB
15494 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15495 (vhdl-template-footer)
15496 (vhdl-comment-display-line) (insert "\n"))
15497 (goto-char (point-min))
15498 (setq arch-buffer (current-buffer))
15499 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15500 (set-buffer arch-buffer) (save-buffer)
29a4e67d 15501 (message "%s"
3dcb36b7
JB
15502 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15503 (and ent-file-name
15504 (format "\n File created: \"%s\"" ent-file-name))
15505 (and arch-file-name
15506 (format "\n File created: \"%s\"" arch-file-name))))))
15507
15508(defun vhdl-compose-place-component ()
15509 "Place new component by pasting current port as component declaration and
15510component instantiation."
15511 (interactive)
15512 (if (not vhdl-port-list)
15513 (error "ERROR: No port has been read")
15514 (save-excursion
15515 (vhdl-prepare-search-2
15516 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15517 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15518 (error "ERROR: No architecture found"))
15519 (let* ((ent-name (match-string 1))
15520 (ent-file-name
0a2e512a 15521 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15522 "." (file-name-extension (buffer-file-name))))
15523 (orig-buffer (current-buffer)))
15524 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15525 ;; place component declaration
15526 (unless (or vhdl-use-components-package
15527 (vhdl-use-direct-instantiation)
15528 (save-excursion
15529 (re-search-forward
15530 (concat "^\\s-*component\\s-+"
15531 (car vhdl-port-list) "\\>") nil t)))
15532 (re-search-forward "^begin\\>" nil)
15533 (beginning-of-line)
15534 (skip-chars-backward " \t\n")
15535 (insert "\n\n") (indent-to vhdl-basic-offset)
15536 (vhdl-port-paste-component t))
15537 ;; place component instantiation
15538 (re-search-forward "^end\\>" nil)
15539 (beginning-of-line)
15540 (skip-chars-backward " \t\n")
15541 (insert "\n\n") (indent-to vhdl-basic-offset)
15542 (vhdl-port-paste-instance nil t t)
15543 ;; place use clause for used packages
15544 (when (nth 3 vhdl-port-list)
15545 ;; open entity file
15546 (when (file-exists-p ent-file-name)
15547 (find-file ent-file-name))
15548 (goto-char (point-min))
15549 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15550 (error "ERROR: Entity not found: \"%s\"" ent-name))
15551 (goto-char (match-beginning 0))
15552 (if (and (save-excursion
15553 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15554 (match-string 1))
15555 (progn (goto-char (match-end 0))
15556 (beginning-of-line 2))
15557 (insert "\n")
15558 (backward-char))
15559 (vhdl-port-paste-context-clause)
15560 (switch-to-buffer orig-buffer))
15561 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15562
15563(defun vhdl-compose-wire-components ()
15564 "Connect components."
15565 (interactive)
15566 (save-excursion
15567 (vhdl-prepare-search-2
15568 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15569 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15570 (error "ERROR: No architecture found"))
15571 (let* ((ent-name (match-string 1))
15572 (ent-file-name
0a2e512a 15573 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15574 "." (file-name-extension (buffer-file-name))))
15575 (arch-decl-pos (point-marker))
15576 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15577 (arch-end-pos (re-search-forward "^end\\>" nil))
15578 (pack-name (vhdl-get-components-package-name))
15579 (pack-file-name
0a2e512a 15580 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15581 "." (file-name-extension (buffer-file-name))))
15582 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15583 port-alist generic-alist inst-alist
15584 signal-name signal-entry signal-alist local-list written-list
15585 single-in-list multi-in-list single-out-list multi-out-list
15586 constant-name constant-entry constant-alist single-list multi-list
15587 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15588 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15589 signal-beg-pos signal-pos
15590 constant-temp-pos port-temp-pos signal-temp-pos)
15591 (message "Wiring components...")
15592 ;; process all instances
15593 (goto-char arch-stat-pos)
15594 (while (re-search-forward
15595 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15596 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15597 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15598 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15599 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15600 (setq inst-name (match-string-no-properties 1)
15601 comp-name (match-string-no-properties 4)
15602 comp-ent-name (match-string-no-properties 12)
15603 has-generic (or (match-string 7) (match-string 17)))
15604 ;; get port ...
15605 (if comp-name
15606 ;; ... from component declaration
15607 (vhdl-visit-file
15608 (when vhdl-use-components-package pack-file-name) t
15609 (save-excursion
15610 (goto-char (point-min))
15611 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15612 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15613 (vhdl-port-copy)))
15614 ;; ... from entity declaration (direct instantiation)
15615 (setq comp-ent-file-name
0a2e512a 15616 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
3dcb36b7
JB
15617 "." (file-name-extension (buffer-file-name))))
15618 (vhdl-visit-file
15619 comp-ent-file-name t
15620 (save-excursion
15621 (goto-char (point-min))
15622 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15623 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15624 (vhdl-port-copy))))
15625 (vhdl-port-flatten t)
15626 (setq generic-alist (nth 1 vhdl-port-list)
0a2e512a
RF
15627 port-alist (nth 2 vhdl-port-list)
15628 vhdl-port-list nil)
3dcb36b7
JB
15629 (setq constant-alist nil
15630 signal-alist nil)
15631 (when has-generic
15632 ;; process all constants in generic map
15633 (vhdl-forward-syntactic-ws)
15634 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15635 (setq constant-name (match-string-no-properties 3))
15636 (setq constant-entry
15637 (cons constant-name
15638 (if (match-string 1)
15639 (or (aget generic-alist (match-string 2) t)
ec3ec9cc 15640 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15641 (cdar generic-alist))))
15642 (setq constant-alist (cons constant-entry constant-alist))
15643 (setq constant-name (downcase constant-name))
15644 (if (or (member constant-name single-list)
15645 (member constant-name multi-list))
15646 (progn (setq single-list (delete constant-name single-list))
15647 (add-to-list 'multi-list constant-name))
15648 (add-to-list 'single-list constant-name))
15649 (unless (match-string 1)
15650 (setq generic-alist (cdr generic-alist)))
15651 (vhdl-forward-syntactic-ws))
15652 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15653 ;; process all signals in port map
15654 (vhdl-forward-syntactic-ws)
15655 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15656 (setq signal-name (match-string-no-properties 3))
15657 (setq signal-entry (cons signal-name
15658 (if (match-string 1)
15659 (or (aget port-alist (match-string 2) t)
ec3ec9cc 15660 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15661 (cdar port-alist))))
15662 (setq signal-alist (cons signal-entry signal-alist))
15663 (setq signal-name (downcase signal-name))
15664 (if (equal (upcase (nth 2 signal-entry)) "IN")
15665 ;; input signal
15666 (cond
15667 ((member signal-name local-list)
15668 nil)
15669 ((or (member signal-name single-out-list)
15670 (member signal-name multi-out-list))
15671 (setq single-out-list (delete signal-name single-out-list))
15672 (setq multi-out-list (delete signal-name multi-out-list))
15673 (add-to-list 'local-list signal-name))
15674 ((member signal-name single-in-list)
15675 (setq single-in-list (delete signal-name single-in-list))
15676 (add-to-list 'multi-in-list signal-name))
15677 ((not (member signal-name multi-in-list))
15678 (add-to-list 'single-in-list signal-name)))
15679 ;; output signal
15680 (cond
15681 ((member signal-name local-list)
15682 nil)
15683 ((or (member signal-name single-in-list)
15684 (member signal-name multi-in-list))
15685 (setq single-in-list (delete signal-name single-in-list))
15686 (setq multi-in-list (delete signal-name multi-in-list))
15687 (add-to-list 'local-list signal-name))
15688 ((member signal-name single-out-list)
15689 (setq single-out-list (delete signal-name single-out-list))
15690 (add-to-list 'multi-out-list signal-name))
15691 ((not (member signal-name multi-out-list))
15692 (add-to-list 'single-out-list signal-name))))
15693 (unless (match-string 1)
15694 (setq port-alist (cdr port-alist)))
15695 (vhdl-forward-syntactic-ws))
15696 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15697 (nreverse signal-alist)) inst-alist)))
15698 ;; prepare signal insertion
15699 (vhdl-goto-marker arch-decl-pos)
15700 (forward-line 1)
15701 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15702 (setq signal-pos (point-marker))
15703 (while (progn (vhdl-forward-syntactic-ws)
15704 (looking-at "signal\\>"))
15705 (beginning-of-line 2)
15706 (delete-region signal-pos (point)))
15707 (setq signal-beg-pos signal-pos)
15708 ;; open entity file
15709 (when (file-exists-p ent-file-name)
15710 (find-file ent-file-name))
15711 (goto-char (point-min))
15712 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15713 (error "ERROR: Entity not found: \"%s\"" ent-name))
15714 ;; prepare generic clause insertion
15715 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15716 (match-string 1))
15717 (goto-char (match-beginning 0))
15718 (indent-to vhdl-basic-offset)
15719 (insert "generic ();\n\n")
15720 (backward-char 4))
15721 (backward-char)
15722 (setq generic-pos (point-marker))
15723 (forward-sexp) (end-of-line)
15724 (delete-region generic-pos (point)) (delete-char 1)
15725 (insert "(\n")
15726 (when multi-list
15727 (insert "\n")
15728 (indent-to (* 2 vhdl-basic-offset))
15729 (insert "-- global generics\n"))
15730 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15731 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15732 ;; prepare port clause insertion
15733 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15734 (match-string 1))
15735 (goto-char (match-beginning 0))
15736 (indent-to vhdl-basic-offset)
15737 (insert "port ();\n\n")
15738 (backward-char 4))
15739 (backward-char)
15740 (setq port-in-pos (point-marker))
15741 (forward-sexp) (end-of-line)
15742 (delete-region port-in-pos (point)) (delete-char 1)
15743 (insert "(\n")
15744 (when (or multi-in-list multi-out-list)
15745 (insert "\n")
15746 (indent-to (* 2 vhdl-basic-offset))
15747 (insert "-- global ports\n"))
15748 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15749 port-out-pos (point-marker) port-inst-pos (point-marker)
15750 port-end-pos (point-marker))
15751 ;; insert generics, ports and signals
15752 (setq inst-alist (nreverse inst-alist))
15753 (while inst-alist
15754 (setq inst-name (nth 0 (car inst-alist))
15755 constant-alist (nth 1 (car inst-alist))
15756 signal-alist (nth 2 (car inst-alist))
15757 constant-temp-pos generic-inst-pos
15758 port-temp-pos port-inst-pos
15759 signal-temp-pos signal-pos)
15760 ;; generics
15761 (while constant-alist
15762 (setq constant-name (downcase (caar constant-alist))
15763 constant-entry (car constant-alist))
15764 (cond ((member constant-name written-list)
15765 nil)
15766 ((member constant-name multi-list)
15767 (vhdl-goto-marker generic-pos)
15768 (setq generic-end-pos
15769 (vhdl-max-marker
15770 generic-end-pos
15771 (vhdl-compose-insert-generic constant-entry)))
15772 (setq generic-pos (point-marker))
15773 (add-to-list 'written-list constant-name))
15774 (t
15775 (vhdl-goto-marker
15776 (vhdl-max-marker generic-inst-pos generic-pos))
15777 (setq generic-end-pos
15778 (vhdl-compose-insert-generic constant-entry))
15779 (setq generic-inst-pos (point-marker))
15780 (add-to-list 'written-list constant-name)))
15781 (setq constant-alist (cdr constant-alist)))
15782 (when (/= constant-temp-pos generic-inst-pos)
15783 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15784 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15785 (insert "-- generics for \"" inst-name "\"\n")
15786 (vhdl-goto-marker generic-inst-pos))
15787 ;; ports and signals
15788 (while signal-alist
15789 (setq signal-name (downcase (caar signal-alist))
15790 signal-entry (car signal-alist))
15791 (cond ((member signal-name written-list)
15792 nil)
15793 ((member signal-name multi-in-list)
15794 (vhdl-goto-marker port-in-pos)
15795 (setq port-end-pos
15796 (vhdl-max-marker
15797 port-end-pos (vhdl-compose-insert-port signal-entry)))
15798 (setq port-in-pos (point-marker))
15799 (add-to-list 'written-list signal-name))
15800 ((member signal-name multi-out-list)
15801 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15802 (setq port-end-pos
15803 (vhdl-max-marker
15804 port-end-pos (vhdl-compose-insert-port signal-entry)))
15805 (setq port-out-pos (point-marker))
15806 (add-to-list 'written-list signal-name))
15807 ((or (member signal-name single-in-list)
15808 (member signal-name single-out-list))
15809 (vhdl-goto-marker
15810 (vhdl-max-marker
15811 port-inst-pos
15812 (vhdl-max-marker port-out-pos port-in-pos)))
15813 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15814 (setq port-inst-pos (point-marker))
15815 (add-to-list 'written-list signal-name))
15816 ((equal (upcase (nth 2 signal-entry)) "OUT")
15817 (vhdl-goto-marker signal-pos)
15818 (vhdl-compose-insert-signal signal-entry)
15819 (setq signal-pos (point-marker))
15820 (add-to-list 'written-list signal-name)))
15821 (setq signal-alist (cdr signal-alist)))
15822 (when (/= port-temp-pos port-inst-pos)
15823 (vhdl-goto-marker
15824 (vhdl-max-marker port-temp-pos
15825 (vhdl-max-marker port-in-pos port-out-pos)))
15826 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15827 (insert "-- ports to \"" inst-name "\"\n")
15828 (vhdl-goto-marker port-inst-pos))
15829 (when (/= signal-temp-pos signal-pos)
15830 (vhdl-goto-marker signal-temp-pos)
15831 (insert "\n") (indent-to vhdl-basic-offset)
15832 (insert "-- outputs of \"" inst-name "\"\n")
15833 (vhdl-goto-marker signal-pos))
15834 (setq inst-alist (cdr inst-alist)))
15835 ;; finalize generic/port clause
15836 (vhdl-goto-marker generic-end-pos) (backward-char)
15837 (when (= generic-beg-pos generic-end-pos)
15838 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15839 (insert ";") (backward-char))
15840 (insert ")")
15841 (vhdl-goto-marker port-end-pos) (backward-char)
15842 (when (= port-beg-pos port-end-pos)
15843 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15844 (insert ";") (backward-char))
15845 (insert ")")
15846 ;; align everything
15847 (when vhdl-auto-align
15848 (vhdl-goto-marker generic-beg-pos)
15849 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15850 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15851 (vhdl-goto-marker signal-beg-pos)
15852 (vhdl-align-region-groups signal-beg-pos signal-pos))
15853 (switch-to-buffer (marker-buffer signal-beg-pos))
15854 (message "Wiring components...done")))))
15855
15856(defun vhdl-compose-insert-generic (entry)
15857 "Insert ENTRY as generic declaration."
15858 (let (pos)
15859 (indent-to (* 2 vhdl-basic-offset))
15860 (insert (nth 0 entry) " : " (nth 1 entry))
15861 (when (nth 2 entry)
15862 (insert " := " (nth 2 entry)))
15863 (insert ";")
15864 (setq pos (point-marker))
15865 (when (and vhdl-include-port-comments (nth 3 entry))
15866 (vhdl-comment-insert-inline (nth 3 entry) t))
15867 (insert "\n")
15868 pos))
15869
15870(defun vhdl-compose-insert-port (entry)
15871 "Insert ENTRY as port declaration."
15872 (let (pos)
15873 (indent-to (* 2 vhdl-basic-offset))
15874 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15875 (setq pos (point-marker))
15876 (when (and vhdl-include-port-comments (nth 4 entry))
15877 (vhdl-comment-insert-inline (nth 4 entry) t))
15878 (insert "\n")
15879 pos))
15880
15881(defun vhdl-compose-insert-signal (entry)
15882 "Insert ENTRY as signal declaration."
15883 (indent-to vhdl-basic-offset)
15884 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15885 (when (and vhdl-include-port-comments (nth 4 entry))
15886 (vhdl-comment-insert-inline (nth 4 entry) t))
15887 (insert "\n"))
15888
15889(defun vhdl-compose-components-package ()
15890 "Generate a package containing component declarations for all entities in the
15891current project/directory."
15892 (interactive)
15893 (vhdl-require-hierarchy-info)
15894 (let* ((project (vhdl-project-p))
15895 (pack-name (vhdl-get-components-package-name))
15896 (pack-file-name
0a2e512a 15897 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15898 "." (file-name-extension (buffer-file-name))))
15899 (ent-alist (aget vhdl-entity-alist
15900 (or project default-directory) t))
15901 (lazy-lock-minimum-size 0)
15902 clause-pos component-pos)
15903 (message "Generating components package \"%s\"..." pack-name)
15904 ;; open package file
15905 (when (and (file-exists-p pack-file-name)
15906 (not (y-or-n-p (concat "File \"" pack-file-name
15907 "\" exists; overwrite? "))))
15908 (error "ERROR: Generating components package...aborted"))
15909 (find-file pack-file-name)
15910 (erase-buffer)
15911 ;; insert header
15912 (if vhdl-compose-include-header
15913 (progn (vhdl-template-header
15914 (concat "Components package (generated by Emacs VHDL Mode "
15915 vhdl-version ")"))
15916 (goto-char (point-max)))
15917 (vhdl-comment-display-line) (insert "\n\n"))
15918 ;; insert std_logic_1164 package
15919 (vhdl-template-package-std-logic-1164)
15920 (insert "\n") (setq clause-pos (point-marker))
15921 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15922 ;; insert package declaration
15923 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15924 (vhdl-insert-keyword " IS\n\n")
15925 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15926 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15927 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15928 (indent-to vhdl-basic-offset)
15929 (setq component-pos (point-marker))
15930 (insert "\n\n") (vhdl-insert-keyword "END ")
15931 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15932 (insert pack-name ";\n\n")
15933 ;; insert footer
15934 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15935 (vhdl-template-footer)
15936 (vhdl-comment-display-line) (insert "\n"))
15937 ;; insert component declarations
15938 (while ent-alist
15939 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15940 (progn (goto-line (nth 3 (car ent-alist)))
15941 (end-of-line)
15942 (vhdl-port-copy)))
15943 (goto-char component-pos)
15944 (vhdl-port-paste-component t)
15945 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15946 (setq component-pos (point-marker))
15947 (goto-char clause-pos)
15948 (vhdl-port-paste-context-clause pack-name)
15949 (setq clause-pos (point-marker))
15950 (setq ent-alist (cdr ent-alist)))
15951 (goto-char (point-min))
15952 (save-buffer)
15953 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15954 pack-name pack-file-name)))
15955
0a2e512a
RF
15956(defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15957 &optional insert-conf)
15958 "Generate block configuration for architecture."
15959 (let ((margin (current-indentation))
15960 (beg (save-excursion (beginning-of-line) (point)))
15961 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15962 ;; insert block configuration (for architecture)
15963 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15964 (setq margin (+ margin vhdl-basic-offset))
15965 ;; process all instances
15966 (while inst-alist
15967 (setq inst-entry (car inst-alist))
15968 ;; is component?
15969 (when (nth 4 inst-entry)
15970 (setq insert-conf t)
15971 (setq inst-path (nth 9 inst-entry))
15972 ;; skip common path with previous instance
15973 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15974 (setq inst-path (cdr inst-path)
15975 inst-prev-path (cdr inst-prev-path)))
15976 ;; insert block configuration end (for previous block/generate)
15977 (while inst-prev-path
15978 (setq margin (- margin vhdl-basic-offset))
15979 (indent-to margin)
15980 (vhdl-insert-keyword "END FOR;\n")
15981 (setq inst-prev-path (cdr inst-prev-path)))
15982 ;; insert block configuration beginning (for current block/generate)
15983 (indent-to margin)
15984 (while inst-path
15985 (setq margin (+ margin vhdl-basic-offset))
15986 (vhdl-insert-keyword "FOR ")
15987 (insert (car inst-path) "\n")
15988 (indent-to margin)
15989 (setq inst-path (cdr inst-path)))
15990 ;; insert component configuration beginning
15991 (vhdl-insert-keyword "FOR ")
15992 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15993 ;; find subconfiguration
15994 (setq conf-key (nth 7 inst-entry))
15995 (setq tmp-alist conf-alist)
15996 ;; use first configuration found for instance's entity
15997 (while (and tmp-alist (null conf-key))
15998 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15999 (setq conf-key (nth 0 (car tmp-alist))))
16000 (setq tmp-alist (cdr tmp-alist)))
16001 (setq conf-entry (aget conf-alist conf-key t))
16002 ;; insert binding indication ...
16003 ;; ... with subconfiguration (if exists)
16004 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
16005 (progn
16006 (indent-to (+ margin vhdl-basic-offset))
16007 (vhdl-insert-keyword "USE CONFIGURATION ")
16008 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16009 (insert ";\n"))
16010 ;; ... with entity (if exists)
16011 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16012 (when ent-entry
16013 (indent-to (+ margin vhdl-basic-offset))
16014 (vhdl-insert-keyword "USE ENTITY ")
16015 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16016 ;; insert architecture name (if architecture exists)
16017 (when (nth 3 ent-entry)
16018 (setq arch-name
16019 ;; choose architecture name a) from configuration,
16020 ;; b) from mra, or c) from first architecture
16021 (or (nth 0 (aget (nth 3 ent-entry)
16022 (or (nth 6 inst-entry)
16023 (nth 4 ent-entry)) t))
16024 (nth 1 (car (nth 3 ent-entry)))))
16025 (insert "(" arch-name ")"))
16026 (insert ";\n")
16027 ;; insert block configuration (for architecture of subcomponent)
16028 (when (and vhdl-compose-configuration-hierarchical
16029 (nth 3 ent-entry))
16030 (indent-to (+ margin vhdl-basic-offset))
16031 (vhdl-compose-configuration-architecture
16032 (nth 0 ent-entry) arch-name
16033 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16034 ;; insert component configuration end
16035 (indent-to margin)
16036 (vhdl-insert-keyword "END FOR;\n")
16037 (setq inst-prev-path (nth 9 inst-entry)))
16038 (setq inst-alist (cdr inst-alist)))
16039 ;; insert block configuration end (for block/generate)
16040 (while inst-prev-path
16041 (setq margin (- margin vhdl-basic-offset))
16042 (indent-to margin)
16043 (vhdl-insert-keyword "END FOR;\n")
16044 (setq inst-prev-path (cdr inst-prev-path)))
16045 (indent-to (- margin vhdl-basic-offset))
16046 ;; insert block configuration end or remove beginning (for architecture)
16047 (if insert-conf
16048 (vhdl-insert-keyword "END FOR;\n")
16049 (delete-region beg (point)))))
16050
16051(defun vhdl-compose-configuration (&optional ent-name arch-name)
16052 "Generate configuration declaration."
16053 (interactive)
16054 (vhdl-require-hierarchy-info)
16055 (let ((ent-alist (aget vhdl-entity-alist
16056 (or (vhdl-project-p) default-directory) t))
16057 (conf-alist (aget vhdl-config-alist
16058 (or (vhdl-project-p) default-directory) t))
16059 (from-speedbar ent-name)
16060 inst-alist conf-name conf-file-name pos)
16061 (vhdl-prepare-search-2
16062 ;; get entity and architecture name
16063 (unless ent-name
16064 (save-excursion
16065 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16066 (not (equal "END" (upcase (match-string 1))))
16067 (setq ent-name (match-string-no-properties 3))
16068 (setq arch-name (match-string-no-properties 2)))
16069 (error "ERROR: Not within an architecture"))))
16070 (setq conf-name (vhdl-replace-string
16071 vhdl-compose-configuration-name
16072 (concat ent-name " " arch-name)))
16073 (setq inst-alist
16074 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16075 (downcase arch-name) t))))
16076 (message "Generating configuration \"%s\"..." conf-name)
16077 (if vhdl-compose-configuration-create-file
16078 ;; open configuration file
16079 (progn
16080 (setq conf-file-name
16081 (concat (vhdl-replace-string vhdl-configuration-file-name
16082 conf-name t)
16083 "." (file-name-extension (buffer-file-name))))
16084 (when (and (file-exists-p conf-file-name)
16085 (not (y-or-n-p (concat "File \"" conf-file-name
16086 "\" exists; overwrite? "))))
16087 (error "ERROR: Creating configuration...aborted"))
16088 (find-file conf-file-name)
16089 (erase-buffer)
16090 (set-buffer-modified-p nil)
16091 ;; insert header
16092 (if vhdl-compose-include-header
16093 (progn (vhdl-template-header
16094 (concat "Configuration declaration for design \""
16095 ent-name "(" arch-name ")\""))
16096 (goto-char (point-max)))
16097 (vhdl-comment-display-line) (insert "\n\n")))
16098 ;; goto end of architecture
16099 (unless from-speedbar
16100 (re-search-forward "^end\\>" nil)
16101 (end-of-line) (insert "\n\n")
16102 (vhdl-comment-display-line) (insert "\n\n")))
16103 ;; insert library clause
16104 (setq pos (point))
16105 (vhdl-template-standard-package (vhdl-work-library) nil)
16106 (when (/= pos (point))
16107 (insert "\n\n"))
16108 ;; insert configuration
16109 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16110 (vhdl-insert-keyword " OF ") (insert ent-name)
16111 (vhdl-insert-keyword " IS\n")
16112 (indent-to vhdl-basic-offset)
16113 ;; insert block configuration (for architecture)
16114 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16115 (vhdl-insert-keyword "END ") (insert conf-name ";")
16116 (when conf-file-name
16117 ;; insert footer and save
16118 (insert "\n\n")
16119 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16120 (vhdl-template-footer)
16121 (vhdl-comment-display-line) (insert "\n"))
16122 (save-buffer))
29a4e67d 16123 (message "%s"
0a2e512a
RF
16124 (concat (format "Generating configuration \"%s\"...done" conf-name)
16125 (and conf-file-name
16126 (format "\n File created: \"%s\"" conf-file-name))))))
16127
3dcb36b7
JB
16128
16129;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16130;;; Compilation / Makefile generation
16131;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16132;; (using `compile.el')
16133
16134(defun vhdl-makefile-name ()
16135 "Return the Makefile name of the current project or the current compiler if
16136no project is defined."
16137 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16138 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16139 (vhdl-replace-string
16140 (cons "\\(.*\\)\n\\(.*\\)"
16141 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16142 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16143
16144(defun vhdl-compile-directory ()
16145 "Return the directory where compilation/make should be run."
16146 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16147 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16148 (directory (vhdl-resolve-env-variable
16149 (if project
16150 (vhdl-replace-string
16151 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16152 (nth 6 compiler)))))
16153 (file-name-as-directory
16154 (if (file-name-absolute-p directory)
16155 directory
16156 (expand-file-name directory (vhdl-default-directory))))))
16157
16158(defun vhdl-uniquify (in-list)
16159 "Remove duplicate elements from IN-LIST."
16160 (let (out-list)
16161 (while in-list
16162 (add-to-list 'out-list (car in-list))
16163 (setq in-list (cdr in-list)))
16164 out-list))
16165
16166(defun vhdl-set-compiler (name)
16167 "Set current compiler to NAME."
16168 (interactive
16169 (list (let ((completion-ignore-case t))
16170 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16171 (if (assoc name vhdl-compiler-alist)
16172 (progn (setq vhdl-compiler name)
16173 (message "Current compiler: \"%s\"" vhdl-compiler))
16174 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16175
16176;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16177;; Compilation
16178
16179(defun vhdl-compile-init ()
16180 "Initialize for compilation."
16181 (when (or (null compilation-error-regexp-alist)
16182 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16183 compilation-error-regexp-alist)))
16184 ;; `compilation-error-regexp-alist'
16185 (let ((commands-alist vhdl-compiler-alist)
16186 regexp-alist sublist)
16187 (while commands-alist
16188 (setq sublist (nth 11 (car commands-alist)))
16189 (unless (or (equal "" (car sublist))
16190 (assoc (car sublist) regexp-alist))
16191 (setq regexp-alist (cons (list (nth 0 sublist)
16192 (if (= 0 (nth 1 sublist))
16193 (if vhdl-xemacs 9 nil)
16194 (nth 1 sublist))
16195 (nth 2 sublist) (nth 3 sublist))
16196 regexp-alist)))
16197 (setq commands-alist (cdr commands-alist)))
16198 (setq compilation-error-regexp-alist
16199 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16200 ;; `compilation-file-regexp-alist'
16201 (let ((commands-alist vhdl-compiler-alist)
16202 regexp-alist sublist)
16203 ;; matches vhdl-mode file name output
16204 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16205 (while commands-alist
16206 (setq sublist (nth 12 (car commands-alist)))
16207 (unless (or (equal "" (car sublist))
16208 (assoc (car sublist) regexp-alist))
16209 (setq regexp-alist (cons sublist regexp-alist)))
16210 (setq commands-alist (cdr commands-alist)))
16211 (setq compilation-file-regexp-alist
16212 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16213
16214(defvar vhdl-compile-file-name nil
16215 "Name of file to be compiled.")
16216
16217(defun vhdl-compile-print-file-name ()
16218 "Function called within `compile' to print out file name for compilers that
16219do not print any file names."
16220 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16221
16222(defun vhdl-get-compile-options (project compiler file-name
16223 &optional file-options-only)
16224 "Get compiler options. Returning nil means do not compile this file."
16225 (let* ((compiler-options (nth 1 compiler))
16226 (project-entry (aget (nth 4 project) vhdl-compiler))
16227 (project-options (nth 0 project-entry))
16228 (exception-list (and file-name (nth 2 project-entry)))
16229 (work-library (vhdl-work-library))
16230 (case-fold-search nil)
16231 file-options)
16232 (while (and exception-list
16233 (not (string-match (caar exception-list) file-name)))
16234 (setq exception-list (cdr exception-list)))
16235 (if (and exception-list (not (cdar exception-list)))
16236 nil
16237 (if (and file-options-only (not exception-list))
16238 'default
16239 (setq file-options (cdar exception-list))
16240 ;; insert library name in compiler-specific options
16241 (setq compiler-options
16242 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16243 work-library))
16244 ;; insert compiler-specific options in project-specific options
16245 (when project-options
16246 (setq project-options
16247 (vhdl-replace-string
16248 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16249 (concat work-library "\n" compiler-options))))
16250 ;; insert project-specific options in file-specific options
16251 (when file-options
16252 (setq file-options
16253 (vhdl-replace-string
16254 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16255 (concat work-library "\n" compiler-options "\n"
16256 project-options))))
16257 ;; return options
16258 (or file-options project-options compiler-options)))))
16259
16260(defun vhdl-get-make-options (project compiler)
16261 "Get make options."
16262 (let* ((compiler-options (nth 3 compiler))
16263 (project-entry (aget (nth 4 project) vhdl-compiler))
16264 (project-options (nth 1 project-entry))
16265 (makefile-name (vhdl-makefile-name)))
16266 ;; insert Makefile name in compiler-specific options
16267 (setq compiler-options
16268 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16269 makefile-name))
16270 ;; insert compiler-specific options in project-specific options
16271 (when project-options
16272 (setq project-options
16273 (vhdl-replace-string
16274 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16275 (concat makefile-name "\n" compiler-options))))
16276 ;; return options
16277 (or project-options compiler-options)))
16278
16279(defun vhdl-compile ()
16280 "Compile current buffer using the VHDL compiler specified in
16281`vhdl-compiler'."
16282 (interactive)
16283 (vhdl-compile-init)
16284 (let* ((project (aget vhdl-project-alist vhdl-project))
16285 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16286 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16287 (command (nth 0 compiler))
16288 (file-name (buffer-file-name))
16289 (options (vhdl-get-compile-options project compiler file-name))
16290 (default-directory (vhdl-compile-directory))
16291 compilation-process-setup-function)
16292 (unless (file-directory-p default-directory)
16293 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16294 ;; put file name into quotes if it contains spaces
16295 (when (string-match " " file-name)
16296 (setq file-name (concat "\"" file-name "\"")))
16297 ;; print out file name if compiler does not
16298 (setq vhdl-compile-file-name (buffer-file-name))
16299 (when (and (= 0 (nth 1 (nth 10 compiler)))
16300 (= 0 (nth 1 (nth 11 compiler))))
16301 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16302 ;; run compilation
16303 (if options
16304 (when command
16305 (compile (concat command " " options " " file-name)))
16306 (vhdl-warning "Your project settings tell me not to compile this file"))))
16307
0a2e512a
RF
16308(defvar vhdl-make-target "all"
16309 "Default target for `vhdl-make' command.")
16310
3dcb36b7
JB
16311(defun vhdl-make (&optional target)
16312 "Call make command for compilation of all updated source files (requires
16313`Makefile'). Optional argument TARGET allows to compile the design
16314specified by a target."
16315 (interactive)
0a2e512a
RF
16316 (setq vhdl-make-target
16317 (or target (read-from-minibuffer "Target: " vhdl-make-target
16318 vhdl-minibuffer-local-map)))
3dcb36b7
JB
16319 (vhdl-compile-init)
16320 (let* ((project (aget vhdl-project-alist vhdl-project))
16321 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16322 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16323 (command (nth 2 compiler))
16324 (options (vhdl-get-make-options project compiler))
16325 (default-directory (vhdl-compile-directory)))
16326 (unless (file-directory-p default-directory)
16327 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16328 ;; run make
16329 (compile (concat (if (equal command "") "make" command)
0a2e512a 16330 " " options " " vhdl-make-target))))
3dcb36b7
JB
16331
16332;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16333;; Makefile generation
16334
16335(defun vhdl-generate-makefile ()
16336 "Generate `Makefile'."
16337 (interactive)
16338 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16339 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16340 (command (nth 4 compiler)))
16341 ;; generate makefile
16342 (if command
16343 (let ((default-directory (vhdl-compile-directory)))
16344 (compile (vhdl-replace-string
16345 (cons "\\(.*\\) \\(.*\\)" command)
16346 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16347 (vhdl-generate-makefile-1))))
16348
16349(defun vhdl-get-packages (lib-alist work-library)
16350 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16351 (let (pack-list)
16352 (while lib-alist
16353 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16354 (setq pack-list (cons (cdar lib-alist) pack-list)))
16355 (setq lib-alist (cdr lib-alist)))
16356 pack-list))
16357
16358(defun vhdl-generate-makefile-1 ()
16359 "Generate Makefile for current project or directory."
16360 ;; scan hierarchy if required
16361 (if (vhdl-project-p)
16362 (unless (or (assoc vhdl-project vhdl-file-alist)
16363 (vhdl-load-cache vhdl-project))
16364 (vhdl-scan-project-contents vhdl-project))
16365 (let ((directory (abbreviate-file-name default-directory)))
16366 (unless (or (assoc directory vhdl-file-alist)
16367 (vhdl-load-cache directory))
16368 (vhdl-scan-directory-contents directory))))
16369 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16370 (project (vhdl-project-p))
16371 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16372 (conf-alist (aget vhdl-config-alist (or project directory) t))
16373 (pack-alist (aget vhdl-package-alist (or project directory) t))
16374 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16375 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16376 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16377 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16378 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16379 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16380 (adjust-case (nth 5 regexp-list))
16381 (work-library (downcase (vhdl-work-library)))
16382 (compile-directory (expand-file-name (vhdl-compile-directory)
16383 default-directory))
16384 (makefile-name (vhdl-makefile-name))
16385 rule-alist arch-alist inst-alist
16386 target-list depend-list unit-list prim-list second-list subcomp-list
16387 lib-alist lib-body-alist pack-list all-pack-list
16388 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16389 conf-key conf-file-name pack-key pack-file-name
16390 ent-entry arch-entry conf-entry pack-entry inst-entry
16391 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16392 tmp-key tmp-list rule)
16393 ;; check prerequisites
16394 (unless (file-exists-p compile-directory)
16395 (make-directory compile-directory t))
16396 (unless regexp-list
16397 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16398 vhdl-compiler))
16399 (message "Generating makefile \"%s\"..." makefile-name)
16400 ;; rules for all entities
16401 (setq tmp-list ent-alist)
16402 (while ent-alist
16403 (setq ent-entry (car ent-alist)
16404 ent-key (nth 0 ent-entry))
16405 (when (nth 2 ent-entry)
16406 (setq ent-file-name (file-relative-name
16407 (nth 2 ent-entry) compile-directory)
16408 arch-alist (nth 4 ent-entry)
0a2e512a 16409 lib-alist (nth 6 ent-entry)
3dcb36b7
JB
16410 rule (aget rule-alist ent-file-name)
16411 target-list (nth 0 rule)
16412 depend-list (nth 1 rule)
16413 second-list nil
16414 subcomp-list nil)
16415 (setq tmp-key (vhdl-replace-string
16416 ent-regexp (funcall adjust-case ent-key)))
16417 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16418 ;; rule target for this entity
16419 (setq target-list (cons ent-key target-list))
16420 ;; rule dependencies for all used packages
16421 (setq pack-list (vhdl-get-packages lib-alist work-library))
16422 (setq depend-list (append depend-list pack-list))
16423 (setq all-pack-list pack-list)
16424 ;; add rule
16425 (aput 'rule-alist ent-file-name (list target-list depend-list))
16426 ;; rules for all corresponding architectures
16427 (while arch-alist
16428 (setq arch-entry (car arch-alist)
16429 arch-key (nth 0 arch-entry)
16430 ent-arch-key (concat ent-key "-" arch-key)
16431 arch-file-name (file-relative-name (nth 2 arch-entry)
16432 compile-directory)
16433 inst-alist (nth 4 arch-entry)
16434 lib-alist (nth 5 arch-entry)
16435 rule (aget rule-alist arch-file-name)
16436 target-list (nth 0 rule)
16437 depend-list (nth 1 rule))
16438 (setq tmp-key (vhdl-replace-string
16439 arch-regexp
16440 (funcall adjust-case (concat arch-key " " ent-key))))
16441 (setq unit-list
16442 (cons (cons ent-arch-key tmp-key) unit-list))
16443 (setq second-list (cons ent-arch-key second-list))
16444 ;; rule target for this architecture
16445 (setq target-list (cons ent-arch-key target-list))
16446 ;; rule dependency for corresponding entity
16447 (setq depend-list (cons ent-key depend-list))
16448 ;; rule dependencies for contained component instantiations
16449 (while inst-alist
16450 (setq inst-entry (car inst-alist))
16451 (when (or (null (nth 8 inst-entry))
16452 (equal (downcase (nth 8 inst-entry)) work-library))
16453 (setq inst-ent-key (or (nth 7 inst-entry)
16454 (nth 5 inst-entry)))
16455 (setq depend-list (cons inst-ent-key depend-list)
16456 subcomp-list (cons inst-ent-key subcomp-list)))
16457 (setq inst-alist (cdr inst-alist)))
16458 ;; rule dependencies for all used packages
16459 (setq pack-list (vhdl-get-packages lib-alist work-library))
16460 (setq depend-list (append depend-list pack-list))
16461 (setq all-pack-list (append all-pack-list pack-list))
16462 ;; add rule
16463 (aput 'rule-alist arch-file-name (list target-list depend-list))
16464 (setq arch-alist (cdr arch-alist)))
16465 (setq prim-list (cons (list ent-key second-list
16466 (append subcomp-list all-pack-list))
16467 prim-list)))
16468 (setq ent-alist (cdr ent-alist)))
16469 (setq ent-alist tmp-list)
16470 ;; rules for all configurations
16471 (setq tmp-list conf-alist)
16472 (while conf-alist
16473 (setq conf-entry (car conf-alist)
16474 conf-key (nth 0 conf-entry)
16475 conf-file-name (file-relative-name
16476 (nth 2 conf-entry) compile-directory)
16477 ent-key (nth 4 conf-entry)
16478 arch-key (nth 5 conf-entry)
16479 inst-alist (nth 6 conf-entry)
16480 lib-alist (nth 7 conf-entry)
16481 rule (aget rule-alist conf-file-name)
16482 target-list (nth 0 rule)
16483 depend-list (nth 1 rule)
16484 subcomp-list (list ent-key))
16485 (setq tmp-key (vhdl-replace-string
16486 conf-regexp (funcall adjust-case conf-key)))
16487 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16488 ;; rule target for this configuration
16489 (setq target-list (cons conf-key target-list))
16490 ;; rule dependency for corresponding entity and architecture
16491 (setq depend-list
16492 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16493 ;; rule dependencies for used packages
16494 (setq pack-list (vhdl-get-packages lib-alist work-library))
16495 (setq depend-list (append depend-list pack-list))
16496 ;; rule dependencies for contained component configurations
16497 (while inst-alist
16498 (setq inst-entry (car inst-alist))
16499 (setq inst-ent-key (nth 2 inst-entry)
16500; comp-arch-key (nth 2 inst-entry))
16501 inst-conf-key (nth 4 inst-entry))
16502 (when (equal (downcase (nth 5 inst-entry)) work-library)
16503 (when inst-ent-key
16504 (setq depend-list (cons inst-ent-key depend-list)
16505 subcomp-list (cons inst-ent-key subcomp-list)))
16506; (when comp-arch-key
16507; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16508; depend-list)))
16509 (when inst-conf-key
16510 (setq depend-list (cons inst-conf-key depend-list)
16511 subcomp-list (cons inst-conf-key subcomp-list))))
16512 (setq inst-alist (cdr inst-alist)))
16513 ;; add rule
16514 (aput 'rule-alist conf-file-name (list target-list depend-list))
16515 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16516 prim-list))
16517 (setq conf-alist (cdr conf-alist)))
16518 (setq conf-alist tmp-list)
16519 ;; rules for all packages
16520 (setq tmp-list pack-alist)
16521 (while pack-alist
16522 (setq pack-entry (car pack-alist)
16523 pack-key (nth 0 pack-entry)
16524 pack-body-key nil)
16525 (when (nth 2 pack-entry)
16526 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16527 compile-directory)
16528 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16529 rule (aget rule-alist pack-file-name)
16530 target-list (nth 0 rule) depend-list (nth 1 rule))
16531 (setq tmp-key (vhdl-replace-string
16532 pack-regexp (funcall adjust-case pack-key)))
16533 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16534 ;; rule target for this package
16535 (setq target-list (cons pack-key target-list))
16536 ;; rule dependencies for all used packages
16537 (setq pack-list (vhdl-get-packages lib-alist work-library))
16538 (setq depend-list (append depend-list pack-list))
16539 (setq all-pack-list pack-list)
16540 ;; add rule
16541 (aput 'rule-alist pack-file-name (list target-list depend-list))
16542 ;; rules for this package's body
16543 (when (nth 7 pack-entry)
16544 (setq pack-body-key (concat pack-key "-body")
16545 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16546 compile-directory)
16547 rule (aget rule-alist pack-body-file-name)
16548 target-list (nth 0 rule)
16549 depend-list (nth 1 rule))
16550 (setq tmp-key (vhdl-replace-string
16551 pack-body-regexp (funcall adjust-case pack-key)))
16552 (setq unit-list
16553 (cons (cons pack-body-key tmp-key) unit-list))
16554 ;; rule target for this package's body
16555 (setq target-list (cons pack-body-key target-list))
16556 ;; rule dependency for corresponding package declaration
16557 (setq depend-list (cons pack-key depend-list))
16558 ;; rule dependencies for all used packages
16559 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16560 (setq depend-list (append depend-list pack-list))
16561 (setq all-pack-list (append all-pack-list pack-list))
16562 ;; add rule
16563 (aput 'rule-alist pack-body-file-name
16564 (list target-list depend-list)))
16565 (setq prim-list
16566 (cons (list pack-key (when pack-body-key (list pack-body-key))
16567 all-pack-list)
16568 prim-list)))
16569 (setq pack-alist (cdr pack-alist)))
16570 (setq pack-alist tmp-list)
16571 ;; generate Makefile
16572 (let* ((project (aget vhdl-project-alist project))
16573 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16574 (compiler-id (nth 9 compiler))
16575 (library-directory
16576 (vhdl-resolve-env-variable
16577 (vhdl-replace-string
16578 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16579 compiler-id)))
16580 (makefile-path-name (expand-file-name
16581 makefile-name compile-directory))
16582 (orig-buffer (current-buffer))
16583 cell second-list subcomp-list options unit-key unit-name)
16584 ;; sort lists
16585 (setq unit-list (vhdl-sort-alist unit-list))
16586 (setq prim-list (vhdl-sort-alist prim-list))
16587 (setq tmp-list rule-alist)
16588 (while tmp-list ; pre-sort rule targets
16589 (setq cell (cdar tmp-list))
16590 (setcar cell (sort (car cell) 'string<))
16591 (setq tmp-list (cdr tmp-list)))
16592 (setq rule-alist ; sort by first rule target
16593 (sort rule-alist
16594 (function (lambda (a b)
16595 (string< (car (cadr a)) (car (cadr b)))))))
16596 ;; open and clear Makefile
16597 (set-buffer (find-file-noselect makefile-path-name t t))
16598 (erase-buffer)
16599 (insert "# -*- Makefile -*-\n"
16600 "### " (file-name-nondirectory makefile-name)
16601 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16602 "\n")
16603 (if project
16604 (insert "\n# Project : " (nth 0 project))
16605 (insert "\n# Directory : \"" directory "\""))
16606 (insert "\n# Platform : " vhdl-compiler
16607 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16608 (user-login-name) "\n")
16609 ;; insert compile and option variable settings
16610 (insert "\n\n# Define compilation command and options\n"
16611 "\nCOMPILE = " (nth 0 compiler)
16612 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16613 "\n")
16614 ;; insert library paths
16615 (setq library-directory
16616 (directory-file-name
16617 (if (file-name-absolute-p library-directory)
16618 library-directory
16619 (file-relative-name
16620 (expand-file-name library-directory directory)
16621 compile-directory))))
16622 (insert "\n\n# Define library paths\n"
16623 "\nLIBRARY-" work-library " = " library-directory "\n")
16624 ;; insert variable definitions for all library unit files
16625 (insert "\n\n# Define library unit files\n")
16626 (setq tmp-list unit-list)
16627 (while unit-list
16628 (insert "\nUNIT-" work-library "-" (caar unit-list)
16629 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16630 (setq unit-list (cdr unit-list)))
16631 ;; insert variable definition for list of all library unit files
16632 (insert "\n\n\n# Define list of all library unit files\n"
16633 "\nALL_UNITS =")
16634 (setq unit-list tmp-list)
16635 (while unit-list
16636 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16637 (setq unit-list (cdr unit-list)))
16638 (insert "\n")
16639 (setq unit-list tmp-list)
16640 ;; insert `make all' rule
16641 (insert "\n\n\n# Rule for compiling entire design\n"
16642 "\nall :"
16643 " \\\n\t\tlibrary"
16644 " \\\n\t\t$(ALL_UNITS)\n")
16645 ;; insert `make clean' rule
16646 (insert "\n\n# Rule for cleaning entire design\n"
16647 "\nclean : "
16648 "\n\t-rm -f $(ALL_UNITS)\n")
16649 ;; insert `make library' rule
16650 (insert "\n\n# Rule for creating library directory\n"
16651 "\nlibrary :"
16652 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16653 "\n$(LIBRARY-" work-library ") :"
16654 "\n\t"
16655 (vhdl-replace-string
16656 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16657 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16658 "\n")
16659 ;; insert rule for each library unit
16660 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16661 (while prim-list
16662 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16663 (setq subcomp-list
16664 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16665 (setq unit-key (caar prim-list)
16666 unit-name (or (nth 0 (aget ent-alist unit-key t))
16667 (nth 0 (aget conf-alist unit-key t))
16668 (nth 0 (aget pack-alist unit-key t))))
16669 (insert "\n" unit-key)
16670 (unless (equal unit-key unit-name)
16671 (insert " \\\n" unit-name))
16672 (insert " :"
16673 " \\\n\t\tlibrary"
16674 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16675 (while second-list
16676 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16677 (setq second-list (cdr second-list)))
16678 (while subcomp-list
0a2e512a
RF
16679 (when (and (assoc (car subcomp-list) unit-list)
16680 (not (equal unit-key (car subcomp-list))))
3dcb36b7
JB
16681 (insert " \\\n\t\t" (car subcomp-list)))
16682 (setq subcomp-list (cdr subcomp-list)))
16683 (insert "\n")
16684 (setq prim-list (cdr prim-list)))
16685 ;; insert rule for each library unit file
16686 (insert "\n\n# Rules for compiling single library unit files\n")
16687 (while rule-alist
16688 (setq rule (car rule-alist))
16689 ;; get compiler options for this file
16690 (setq options
16691 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16692 ;; insert rule if file is supposed to be compiled
16693 (setq target-list (nth 1 rule)
16694 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16695 ;; insert targets
16696 (setq tmp-list target-list)
16697 (while target-list
16698 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16699 (if (cdr target-list) " \\" " :"))
16700 (setq target-list (cdr target-list)))
16701 (setq target-list tmp-list)
16702 ;; insert file name as first dependency
16703 (insert " \\\n\t\t" (nth 0 rule))
16704 ;; insert dependencies (except if also target or unit does not exist)
16705 (while depend-list
16706 (when (and (not (member (car depend-list) target-list))
16707 (assoc (car depend-list) unit-list))
16708 (insert " \\\n\t\t"
16709 "$(UNIT-" work-library "-" (car depend-list) ")"))
16710 (setq depend-list (cdr depend-list)))
16711 ;; insert compile command
16712 (if options
16713 (insert "\n\t$(COMPILE) "
16714 (if (eq options 'default) "$(OPTIONS)" options) " "
16715 (nth 0 rule) "\n")
16716 (setq tmp-list target-list)
16717 (while target-list
16718 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16719 (if (cdr target-list) " \\" "\n"))
16720 (setq target-list (cdr target-list)))
16721 (setq target-list tmp-list))
16722 (setq rule-alist (cdr rule-alist)))
16723 (insert "\n\n### " makefile-name " ends here\n")
16724 ;; run Makefile generation hook
16725 (run-hooks 'vhdl-makefile-generation-hook)
16726 (message "Generating makefile \"%s\"...done" makefile-name)
16727 ;; save and close file
16728 (if (file-writable-p makefile-path-name)
16729 (progn (save-buffer)
16730 (kill-buffer (current-buffer))
16731 (set-buffer orig-buffer)
16732 (setq file-name-history
16733 (cons makefile-path-name file-name-history)))
16734 (vhdl-warning-when-idle
16735 (format "File not writable: \"%s\""
16736 (abbreviate-file-name makefile-path-name)))
16737 (switch-to-buffer (current-buffer))))))
16738
5eabfe72
KH
16739
16740;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16741;;; Bug reports
16742;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16743;; (using `reporter.el')
16744
3dcb36b7
JB
16745(defconst vhdl-mode-help-address
16746 "Reto Zimmermann <reto@gnu.org>"
d2ddb974
KH
16747 "Address for VHDL Mode bug reports.")
16748
3dcb36b7
JB
16749(defun vhdl-submit-bug-report ()
16750 "Submit via mail a bug report on VHDL Mode."
16751 (interactive)
16752 ;; load in reporter
16753 (and
16754 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16755 (let ((reporter-prompt-for-summary-p t))
16756 (reporter-submit-bug-report
16757 vhdl-mode-help-address
16758 (concat "VHDL Mode " vhdl-version)
16759 (list
16760 ;; report all important user options
16761 'vhdl-offsets-alist
16762 'vhdl-comment-only-line-offset
16763 'tab-width
16764 'vhdl-electric-mode
16765 'vhdl-stutter-mode
16766 'vhdl-indent-tabs-mode
16767 'vhdl-project-alist
16768 'vhdl-project
16769 'vhdl-project-file-name
16770 'vhdl-project-auto-load
16771 'vhdl-project-sort
16772 'vhdl-compiler-alist
16773 'vhdl-compiler
16774 'vhdl-compile-use-local-error-regexp
16775 'vhdl-makefile-generation-hook
16776 'vhdl-default-library
16777 'vhdl-standard
16778 'vhdl-basic-offset
16779 'vhdl-upper-case-keywords
16780 'vhdl-upper-case-types
16781 'vhdl-upper-case-attributes
16782 'vhdl-upper-case-enum-values
16783 'vhdl-upper-case-constants
16784 'vhdl-use-direct-instantiation
0a2e512a 16785 'vhdl-compose-configuration-name
3dcb36b7
JB
16786 'vhdl-entity-file-name
16787 'vhdl-architecture-file-name
0a2e512a 16788 'vhdl-configuration-file-name
3dcb36b7
JB
16789 'vhdl-package-file-name
16790 'vhdl-file-name-case
16791 'vhdl-electric-keywords
16792 'vhdl-optional-labels
16793 'vhdl-insert-empty-lines
16794 'vhdl-argument-list-indent
16795 'vhdl-association-list-with-formals
16796 'vhdl-conditions-in-parenthesis
16797 'vhdl-zero-string
16798 'vhdl-one-string
16799 'vhdl-file-header
16800 'vhdl-file-footer
16801 'vhdl-company-name
16802 'vhdl-copyright-string
16803 'vhdl-platform-spec
16804 'vhdl-date-format
16805 'vhdl-modify-date-prefix-string
16806 'vhdl-modify-date-on-saving
16807 'vhdl-reset-kind
16808 'vhdl-reset-active-high
16809 'vhdl-clock-rising-edge
16810 'vhdl-clock-edge-condition
16811 'vhdl-clock-name
16812 'vhdl-reset-name
16813 'vhdl-model-alist
16814 'vhdl-include-port-comments
16815 'vhdl-include-direction-comments
16816 'vhdl-include-type-comments
16817 'vhdl-include-group-comments
16818 'vhdl-actual-port-name
16819 'vhdl-instance-name
16820 'vhdl-testbench-entity-name
16821 'vhdl-testbench-architecture-name
16822 'vhdl-testbench-configuration-name
16823 'vhdl-testbench-dut-name
16824 'vhdl-testbench-include-header
16825 'vhdl-testbench-declarations
16826 'vhdl-testbench-statements
16827 'vhdl-testbench-initialize-signals
16828 'vhdl-testbench-include-library
16829 'vhdl-testbench-include-configuration
16830 'vhdl-testbench-create-files
0a2e512a
RF
16831 'vhdl-testbench-entity-file-name
16832 'vhdl-testbench-architecture-file-name
3dcb36b7 16833 'vhdl-compose-create-files
0a2e512a
RF
16834 'vhdl-compose-configuration-create-file
16835 'vhdl-compose-configuration-hierarchical
16836 'vhdl-compose-configuration-use-subconfiguration
3dcb36b7
JB
16837 'vhdl-compose-include-header
16838 'vhdl-compose-architecture-name
16839 'vhdl-components-package-name
16840 'vhdl-use-components-package
16841 'vhdl-self-insert-comments
16842 'vhdl-prompt-for-comments
16843 'vhdl-inline-comment-column
16844 'vhdl-end-comment-column
16845 'vhdl-auto-align
16846 'vhdl-align-groups
16847 'vhdl-align-group-separate
16848 'vhdl-align-same-indent
16849 'vhdl-highlight-keywords
16850 'vhdl-highlight-names
16851 'vhdl-highlight-special-words
16852 'vhdl-highlight-forbidden-words
16853 'vhdl-highlight-verilog-keywords
16854 'vhdl-highlight-translate-off
16855 'vhdl-highlight-case-sensitive
16856 'vhdl-special-syntax-alist
16857 'vhdl-forbidden-words
16858 'vhdl-forbidden-syntax
16859 'vhdl-directive-keywords
16860 'vhdl-speedbar-auto-open
16861 'vhdl-speedbar-display-mode
16862 'vhdl-speedbar-scan-limit
16863 'vhdl-speedbar-jump-to-unit
16864 'vhdl-speedbar-update-on-saving
16865 'vhdl-speedbar-save-cache
16866 'vhdl-speedbar-cache-file-name
16867 'vhdl-index-menu
16868 'vhdl-source-file-menu
16869 'vhdl-hideshow-menu
16870 'vhdl-hide-all-init
16871 'vhdl-print-two-column
16872 'vhdl-print-customize-faces
16873 'vhdl-intelligent-tab
16874 'vhdl-indent-syntax-based
16875 'vhdl-word-completion-case-sensitive
16876 'vhdl-word-completion-in-minibuffer
16877 'vhdl-underscore-is-part-of-word
16878 'vhdl-mode-hook)
16879 (function
16880 (lambda ()
16881 (insert
16882 (if vhdl-special-indent-hook
16883 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16884 "vhdl-special-indent-hook is set to '"
16885 (format "%s" vhdl-special-indent-hook)
16886 ".\nPerhaps this is your problem?\n"
16887 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16888 "\n"))))
16889 nil
16890 "Hi Reto,"))))
16891
16892
16893;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16894;;; Documentation
16895;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16896
16897(defconst vhdl-doc-release-notes nil
16898 "\
0a2e512a 16899Release Notes for VHDL Mode 3.33
3dcb36b7
JB
16900================================
16901
16902 - New Features
3dcb36b7 16903 - User Options
3dcb36b7
JB
16904
16905
16906New Features
16907------------
16908
0a2e512a
RF
16909CONFIGURATION DECLARATION GENERATION:
16910 - Automatic generation of a configuration declaration for a design.
16911 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
3dcb36b7
JB
16912
16913
16914User Options
16915------------
16916
0a2e512a
RF
16917`vhdl-configuration-file-name': (new)
16918 Specify how the configuration file name is obtained.
16919`vhdl-compose-configuration-name': (new)
16920 Specify how the configuration name is optained.
16921`vhdl-compose-configuration-create-file': (new)
16922 Specify whether a new file should be created for a configuration.
16923`vhdl-compose-configuration-hierarchical': (new)
16924 Specify whether hierarchical configurations should be created.
16925`vhdl-compose-configuration-use-subconfiguration': (new)
16926 Specify whether subconfigurations should be used inside configurations.
3dcb36b7
JB
16927")
16928
16929
16930(defconst vhdl-doc-keywords nil
16931 "\
16932Reserved words in VHDL
16933----------------------
16934
16935VHDL'93 (IEEE Std 1076-1993):
16936 `vhdl-93-keywords' : keywords
16937 `vhdl-93-types' : standardized types
16938 `vhdl-93-attributes' : standardized attributes
16939 `vhdl-93-enum-values' : standardized enumeration values
16940 `vhdl-93-functions' : standardized functions
16941 `vhdl-93-packages' : standardized packages and libraries
16942
16943VHDL-AMS (IEEE Std 1076.1):
16944 `vhdl-ams-keywords' : keywords
16945 `vhdl-ams-types' : standardized types
16946 `vhdl-ams-attributes' : standardized attributes
16947 `vhdl-ams-enum-values' : standardized enumeration values
16948 `vhdl-ams-functions' : standardized functions
16949
16950Math Packages (IEEE Std 1076.2):
16951 `vhdl-math-types' : standardized types
16952 `vhdl-math-constants' : standardized constants
16953 `vhdl-math-functions' : standardized functions
16954 `vhdl-math-packages' : standardized packages
16955
16956Forbidden words:
16957 `vhdl-verilog-keywords' : Verilog reserved words
16958
16959NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16960
16961
16962(defconst vhdl-doc-coding-style nil
16963 "\
16964For VHDL coding style and naming convention guidelines, see the following
16965references:
16966
16967\[1] Ben Cohen.
16968 \"VHDL Coding Styles and Methodologies\".
16969 Kluwer Academic Publishers, 1999.
16970 http://members.aol.com/vhdlcohen/vhdl/
16971
16972\[2] Michael Keating and Pierre Bricaud.
16973 \"Reuse Methodology Manual, Second Edition\".
16974 Kluwer Academic Publishers, 1999.
16975 http://www.openmore.com/openmore/rmm2.html
16976
16977\[3] European Space Agency.
16978 \"VHDL Modelling Guidelines\".
16979 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16980
16981Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16982to visually support naming conventions.")
16983
16984
d2ddb974
KH
16985(defun vhdl-version ()
16986 "Echo the current version of VHDL Mode in the minibuffer."
16987 (interactive)
3dcb36b7 16988 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
d2ddb974
KH
16989 (vhdl-keep-region-active))
16990
3dcb36b7
JB
16991(defun vhdl-doc-variable (variable)
16992 "Display VARIABLE's documentation in *Help* buffer."
16993 (interactive)
4bcb9c95
SM
16994 (unless vhdl-xemacs
16995 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
0a2e512a
RF
16996 (with-output-to-temp-buffer
16997 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7 16998 (princ (documentation-property variable 'variable-documentation))
4bcb9c95 16999 (with-current-buffer standard-output
3dcb36b7
JB
17000 (help-mode))
17001 (print-help-return-message)))
d2ddb974 17002
3dcb36b7
JB
17003(defun vhdl-doc-mode ()
17004 "Display VHDL Mode documentation in *Help* buffer."
d2ddb974 17005 (interactive)
4bcb9c95
SM
17006 (unless vhdl-xemacs
17007 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
0a2e512a
RF
17008 (with-output-to-temp-buffer
17009 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7
JB
17010 (princ mode-name)
17011 (princ " mode:\n")
17012 (princ (documentation 'vhdl-mode))
4bcb9c95 17013 (with-current-buffer standard-output
3dcb36b7
JB
17014 (help-mode))
17015 (print-help-return-message)))
d2ddb974
KH
17016
17017
5eabfe72 17018;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
17019
17020(provide 'vhdl-mode)
17021
4bcb9c95 17022;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
d2ddb974 17023;;; vhdl-mode.el ends here