Add details of Speedbar merge.
[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 12834 "Font lock mode face used to highlight prompts."
fa6674e3 12835 :group 'vhdl-highlight-faces)
d2ddb974 12836
0a2e512a 12837(defface vhdl-font-lock-attribute-face
5eabfe72
KH
12838 '((((class color) (background light)) (:foreground "Orchid"))
12839 (((class color) (background dark)) (:foreground "LightSteelBlue"))
3dcb36b7 12840 (t (:italic t :bold t)))
5eabfe72 12841 "Font lock mode face used to highlight standardized attributes."
fa6674e3 12842 :group 'vhdl-highlight-faces)
d2ddb974 12843
0a2e512a 12844(defface vhdl-font-lock-enumvalue-face
3dcb36b7 12845 '((((class color) (background light)) (:foreground "SaddleBrown"))
5eabfe72 12846 (((class color) (background dark)) (:foreground "BurlyWood"))
3dcb36b7 12847 (t (:italic t :bold t)))
5eabfe72 12848 "Font lock mode face used to highlight standardized enumeration values."
fa6674e3 12849 :group 'vhdl-highlight-faces)
d2ddb974 12850
0a2e512a 12851(defface vhdl-font-lock-function-face
3dcb36b7 12852 '((((class color) (background light)) (:foreground "Cyan4"))
5eabfe72 12853 (((class color) (background dark)) (:foreground "Orchid1"))
3dcb36b7 12854 (t (:italic t :bold t)))
5eabfe72 12855 "Font lock mode face used to highlight standardized functions and packages."
fa6674e3 12856 :group 'vhdl-highlight-faces)
d2ddb974 12857
0a2e512a 12858(defface vhdl-font-lock-directive-face
5eabfe72
KH
12859 '((((class color) (background light)) (:foreground "CadetBlue"))
12860 (((class color) (background dark)) (:foreground "Aquamarine"))
3dcb36b7 12861 (t (:italic t :bold t)))
5eabfe72 12862 "Font lock mode face used to highlight directives."
fa6674e3 12863 :group 'vhdl-highlight-faces)
d2ddb974 12864
0a2e512a 12865(defface vhdl-font-lock-reserved-words-face
3dcb36b7 12866 '((((class color) (background light)) (:foreground "Orange" :bold t))
5bb5087f 12867 (((min-colors 88) (class color) (background dark))
ea81d57e 12868 (:foreground "Yellow1" :bold t))
3dcb36b7 12869 (((class color) (background dark)) (:foreground "Yellow" :bold t))
d2ddb974 12870 (t ()))
5eabfe72 12871 "Font lock mode face used to highlight additional reserved words."
fa6674e3 12872 :group 'vhdl-highlight-faces)
d2ddb974 12873
0a2e512a 12874(defface vhdl-font-lock-translate-off-face
5eabfe72
KH
12875 '((((class color) (background light)) (:background "LightGray"))
12876 (((class color) (background dark)) (:background "DimGray"))
d2ddb974 12877 (t ()))
5eabfe72 12878 "Font lock mode face used to background highlight translate-off regions."
fa6674e3 12879 :group 'vhdl-highlight-faces)
d2ddb974 12880
5eabfe72
KH
12881;; font lock mode faces used to highlight words with special syntax.
12882(let ((syntax-alist vhdl-special-syntax-alist))
12883 (while syntax-alist
0a2e512a
RF
12884 (eval `(defface ,(vhdl-function-name
12885 "vhdl-font-lock" (caar syntax-alist) "face")
d4a5b644
GM
12886 '((((class color) (background light))
12887 (:foreground ,(nth 2 (car syntax-alist))))
12888 (((class color) (background dark))
12889 (:foreground ,(nth 3 (car syntax-alist))))
12890 (t ()))
12891 ,(concat "Font lock mode face used to highlight "
12892 (nth 0 (car syntax-alist)) ".")
fa6674e3 12893 :group 'vhdl-highlight-faces))
5eabfe72
KH
12894 (setq syntax-alist (cdr syntax-alist))))
12895
12896;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12897;; Font lock initialization
12898
12899(defun vhdl-font-lock-init ()
5eabfe72 12900 "Initialize fontification."
0a2e512a 12901 ;; highlight template prompts and directives
3dcb36b7
JB
12902 (setq vhdl-font-lock-keywords-0
12903 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12904 vhdl-template-prompt-syntax ">\\)")
0a2e512a 12905 2 'vhdl-font-lock-prompt-face t)
3dcb36b7
JB
12906 (list (concat "--\\s-*"
12907 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
0a2e512a
RF
12908 2 'vhdl-font-lock-directive-face t)
12909 ;; highlight c-preprocessor directives
12910 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12911 '(1 font-lock-builtin-face)
12912 '(3 font-lock-variable-name-face nil t))))
5eabfe72
KH
12913 ;; highlight keywords and standardized types, attributes, enumeration
12914 ;; values, and subprograms
12915 (setq vhdl-font-lock-keywords-1
12916 (list
0a2e512a
RF
12917 (list (concat "'" vhdl-attributes-regexp)
12918 1 'vhdl-font-lock-attribute-face)
5eabfe72 12919 (list vhdl-types-regexp 1 'font-lock-type-face)
0a2e512a
RF
12920 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12921 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12922 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
5eabfe72
KH
12923 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12924 ;; highlight words with special syntax.
12925 (setq vhdl-font-lock-keywords-3
12926 (let ((syntax-alist vhdl-special-syntax-alist)
12927 keywords)
12928 (while syntax-alist
12929 (setq keywords
12930 (cons
12931 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12932 (vhdl-function-name
0a2e512a 12933 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
5eabfe72
KH
12934 keywords))
12935 (setq syntax-alist (cdr syntax-alist)))
12936 keywords))
12937 ;; highlight additional reserved words
12938 (setq vhdl-font-lock-keywords-4
0a2e512a
RF
12939 (list (list vhdl-reserved-words-regexp 1
12940 'vhdl-font-lock-reserved-words-face)))
5eabfe72 12941 ;; highlight everything together
d2ddb974 12942 (setq vhdl-font-lock-keywords
5eabfe72
KH
12943 (append
12944 vhdl-font-lock-keywords-0
12945 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12946 (when (or vhdl-highlight-forbidden-words
12947 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12948 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12949 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12950 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12951
12952;; initialize fontification for VHDL Mode
12953(vhdl-font-lock-init)
12954
12955(defun vhdl-fontify-buffer ()
12956 "Re-initialize fontification and fontify buffer."
12957 (interactive)
12958 (setq font-lock-defaults
12959 (list
12960 'vhdl-font-lock-keywords nil
12961 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12962 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12963 (when (fboundp 'font-lock-unset-defaults)
12964 (font-lock-unset-defaults)) ; not implemented in XEmacs
0a2e512a 12965 (font-lock-set-defaults)
3dcb36b7
JB
12966 (font-lock-mode nil)
12967 (font-lock-mode t))
5eabfe72
KH
12968
12969;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12970;; Initialization for postscript printing
12971
12972(defun vhdl-ps-print-settings ()
12973 "Initialize custom face and page settings for postscript printing."
12974 ;; define custom face settings
12975 (unless (or (not vhdl-print-customize-faces)
d2ddb974
KH
12976 ps-print-color-p)
12977 (set (make-local-variable 'ps-bold-faces)
0a2e512a
RF
12978 '(font-lock-keyword-face
12979 font-lock-type-face
12980 vhdl-font-lock-attribute-face
12981 vhdl-font-lock-enumvalue-face
12982 vhdl-font-lock-directive-face))
d2ddb974
KH
12983 (set (make-local-variable 'ps-italic-faces)
12984 '(font-lock-comment-face
0a2e512a
RF
12985 font-lock-function-name-face
12986 font-lock-type-face
12987 vhdl-font-lock-attribute-face
12988 vhdl-font-lock-enumvalue-face
12989 vhdl-font-lock-directive-face))
d2ddb974
KH
12990 (set (make-local-variable 'ps-underlined-faces)
12991 '(font-lock-string-face))
5eabfe72 12992 (setq ps-always-build-face-reference t))
d2ddb974
KH
12993 ;; define page settings, so that a line containing 79 characters (default)
12994 ;; fits into one column
5eabfe72
KH
12995 (when vhdl-print-two-column
12996 (set (make-local-variable 'ps-landscape-mode) t)
12997 (set (make-local-variable 'ps-number-of-columns) 2)
12998 (set (make-local-variable 'ps-font-size) 7.0)
12999 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13000 (set (make-local-variable 'ps-header-font-size) 9.0)
13001 (set (make-local-variable 'ps-header-offset) 12.0)
13002 (when (eq ps-paper-type 'letter)
13003 (set (make-local-variable 'ps-inter-column) 40.0)
13004 (set (make-local-variable 'ps-left-margin) 40.0)
13005 (set (make-local-variable 'ps-right-margin) 40.0))))
13006
13007(defun vhdl-ps-print-init ()
13008 "Initialize postscript printing."
3dcb36b7
JB
13009 (if vhdl-xemacs
13010 (when (boundp 'ps-print-color-p)
13011 (vhdl-ps-print-settings))
5eabfe72
KH
13012 (make-local-variable 'ps-print-hook)
13013 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13014
13015
13016;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13017;;; Hierarchy browser (using `speedbar.el')
13018;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13019;; Allows displaying the hierarchy of all VHDL design units contained in a
13020;; directory by using the speedbar.
13021
13022;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13023;; Variables
13024
13025(defvar vhdl-entity-alist nil
3dcb36b7
JB
13026 "Cache with entities and corresponding architectures for each
13027project/directory.")
5eabfe72 13028;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
13029;; (cache-key
13030;; (ent-key ent-name ent-file ent-line
13031;; (arch-key arch-name arch-file arch-line
13032;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
0a2e512a
RF
13033;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13034;; (lib-name pack-key))
13035;; mra-key (lib-name pack-key))
3dcb36b7
JB
13036
13037(defvar vhdl-config-alist nil
13038 "Cache with configurations for each project/directory.")
13039;; structure: (parenthesised expression means list of such entries)
13040;; (cache-key
13041;; (conf-key conf-name conf-file conf-line ent-key arch-key
13042;; (inst-key inst-comp-name inst-ent-key inst-arch-key
0a2e512a 13043;; inst-conf-key inst-lib-key)
3dcb36b7 13044;; (lib-name pack-key)))
5eabfe72
KH
13045
13046(defvar vhdl-package-alist nil
3dcb36b7 13047 "Cache with packages for each project/directory.")
5eabfe72 13048;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
13049;; (cache-key
13050;; (pack-key pack-name pack-file pack-line
13051;; (comp-key comp-name comp-file comp-line)
13052;; (func-key func-name func-file func-line)
13053;; (lib-name pack-key)
13054;; pack-body-file pack-body-line
13055;; (func-key func-name func-body-file func-body-line)
13056;; (lib-name pack-key)))
5eabfe72
KH
13057
13058(defvar vhdl-ent-inst-alist nil
3dcb36b7 13059 "Cache with instantiated entities for each project/directory.")
5eabfe72 13060;; structure: (parenthesised expression means list of such entries)
3dcb36b7 13061;; (cache-key (inst-ent-key))
5eabfe72 13062
3dcb36b7
JB
13063(defvar vhdl-file-alist nil
13064 "Cache with design units in each file for each project/directory.")
13065;; structure: (parenthesised expression means list of such entries)
13066;; (cache-key
13067;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
0a2e512a 13068;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
5eabfe72 13069
3dcb36b7
JB
13070(defvar vhdl-directory-alist nil
13071 "Cache with source directories for each project.")
13072;; structure: (parenthesised expression means list of such entries)
13073;; (cache-key (directory))
5eabfe72 13074
3dcb36b7 13075(defvar vhdl-speedbar-shown-unit-alist nil
5eabfe72
KH
13076 "Alist of design units simultaneously open in the current speedbar for each
13077directory and project.")
13078
3dcb36b7
JB
13079(defvar vhdl-speedbar-shown-project-list nil
13080 "List of projects simultaneously open in the current speedbar.")
5eabfe72 13081
3dcb36b7
JB
13082(defvar vhdl-updated-project-list nil
13083 "List of projects and directories with updated files.")
13084
13085(defvar vhdl-modified-file-list nil
13086 "List of modified files to be rescanned for hierarchy updating.")
13087
13088(defvar vhdl-speedbar-hierarchy-depth 0
13089 "Depth of instantiation hierarchy to display.")
13090
13091(defvar vhdl-speedbar-show-projects nil
13092 "Non-nil means project hierarchy is displayed in speedbar, directory
13093hierarchy otherwise.")
13094
13095(defun vhdl-get-end-of-unit ()
13096 "Return position of end of current unit."
13097 (let ((pos (point)))
13098 (save-excursion
13099 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13100 (save-excursion
13101 (goto-char (match-beginning 0))
13102 (vhdl-backward-syntactic-ws)
13103 (and (/= (preceding-char) ?\;) (not (bobp))))))
13104 (re-search-backward "^[ \t]*end\\>" pos 1)
13105 (point))))
13106
13107(defun vhdl-match-string-downcase (num &optional string)
13108 "Like `match-string-no-properties' with down-casing."
13109 (let ((match (match-string-no-properties num string)))
13110 (and match (downcase match))))
5eabfe72 13111
5eabfe72
KH
13112
13113;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13114;; Scan functions
13115
3dcb36b7
JB
13116(defun vhdl-scan-context-clause ()
13117 "Scan the context clause that preceeds a design unit."
13118 (let (lib-alist)
13119 (save-excursion
13120 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13121 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13122 (equal "USE" (upcase (match-string 1))))
13123 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13124 (setq lib-alist (cons (cons (match-string-no-properties 1)
13125 (vhdl-match-string-downcase 2))
13126 lib-alist))))))
13127 lib-alist))
13128
13129(defun vhdl-scan-directory-contents (name &optional project update num-string
13130 non-final)
13131 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
13132 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
5eabfe72
KH
13133; (unless (file-directory-p (match-string 1 name))
13134; (message "No such directory: \"%s\"" (match-string 1 name)))
3dcb36b7
JB
13135 (let* ((dir-name (match-string 1 name))
13136 (file-pattern (match-string 2 name))
13137 (is-directory (= 0 (length file-pattern)))
5eabfe72 13138 (file-list
3dcb36b7
JB
13139 (if update
13140 (list name)
13141 (if is-directory
13142 (vhdl-get-source-files t dir-name)
13143 (vhdl-directory-files
13144 dir-name t (wildcard-to-regexp file-pattern)))))
13145 (key (or project dir-name))
13146 (file-exclude-regexp
13147 (or (nth 3 (aget vhdl-project-alist project)) ""))
13148 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13149 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13150 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13151 ent-alist conf-alist pack-alist ent-inst-list file-alist
13152 tmp-list tmp-entry no-files files-exist big-files)
13153 (when (or project update)
13154 (setq ent-alist (aget vhdl-entity-alist key t)
13155 conf-alist (aget vhdl-config-alist key t)
13156 pack-alist (aget vhdl-package-alist key t)
13157 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13158 file-alist (aget vhdl-file-alist key t)))
5eabfe72
KH
13159 (when (and (not is-directory) (null file-list))
13160 (message "No such file: \"%s\"" name))
3dcb36b7
JB
13161 (setq files-exist file-list)
13162 (when file-list
13163 (setq no-files (length file-list))
13164 (message "Scanning %s %s\"%s\"..."
13165 (if is-directory "directory" "files") (or num-string "") name)
13166 ;; exclude files
13167 (unless (equal file-exclude-regexp "")
13168 (let ((case-fold-search nil)
13169 file-tmp-list)
13170 (while file-list
13171 (unless (string-match file-exclude-regexp (car file-list))
13172 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13173 (setq file-list (cdr file-list)))
13174 (setq file-list (nreverse file-tmp-list))))
13175 ;; do for all files
13176 (while file-list
13177 (unless noninteractive
5eabfe72
KH
13178 (message "Scanning %s %s\"%s\"... (%2d%s)"
13179 (if is-directory "directory" "files")
13180 (or num-string "") name
3dcb36b7
JB
13181 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13182 (let ((file-name (abbreviate-file-name (car file-list)))
13183 ent-list arch-list arch-ent-list conf-list
13184 pack-list pack-body-list inst-list inst-ent-list)
13185 ;; scan file
13186 (vhdl-visit-file
13187 file-name nil
13188 (vhdl-prepare-search-2
13189 (save-excursion
13190 ;; scan for design units
13191 (if (and limit-design-file-size
13192 (< limit-design-file-size (buffer-size)))
13193 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13194 (setq big-files t))
13195 ;; scan for entities
13196 (goto-char (point-min))
13197 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13198 (let* ((ent-name (match-string-no-properties 1))
13199 (ent-key (downcase ent-name))
13200 (ent-entry (aget ent-alist ent-key t))
3dcb36b7
JB
13201 (lib-alist (vhdl-scan-context-clause)))
13202 (if (nth 1 ent-entry)
13203 (vhdl-warning-when-idle
13204 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13205 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13206 file-name (vhdl-current-line))
13207 (setq ent-list (cons ent-key ent-list))
13208 (aput 'ent-alist ent-key
13209 (list ent-name file-name (vhdl-current-line)
0a2e512a
RF
13210 (nth 3 ent-entry) (nth 4 ent-entry)
13211 lib-alist)))))
3dcb36b7
JB
13212 ;; scan for architectures
13213 (goto-char (point-min))
0a2e512a 13214 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
3dcb36b7
JB
13215 (let* ((arch-name (match-string-no-properties 1))
13216 (arch-key (downcase arch-name))
13217 (ent-name (match-string-no-properties 2))
13218 (ent-key (downcase ent-name))
13219 (ent-entry (aget ent-alist ent-key t))
13220 (arch-alist (nth 3 ent-entry))
13221 (arch-entry (aget arch-alist arch-key t))
13222 (lib-arch-alist (vhdl-scan-context-clause)))
13223 (if arch-entry
13224 (vhdl-warning-when-idle
13225 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13226 arch-name ent-name (nth 1 arch-entry)
13227 (nth 2 arch-entry) file-name (vhdl-current-line))
13228 (setq arch-list (cons arch-key arch-list)
13229 arch-ent-list (cons ent-key arch-ent-list))
13230 (aput 'arch-alist arch-key
13231 (list arch-name file-name (vhdl-current-line) nil
13232 lib-arch-alist))
13233 (aput 'ent-alist ent-key
13234 (list (or (nth 0 ent-entry) ent-name)
13235 (nth 1 ent-entry) (nth 2 ent-entry)
13236 (vhdl-sort-alist arch-alist)
0a2e512a 13237 arch-key (nth 5 ent-entry))))))
3dcb36b7
JB
13238 ;; scan for configurations
13239 (goto-char (point-min))
13240 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13241 (let* ((conf-name (match-string-no-properties 1))
13242 (conf-key (downcase conf-name))
13243 (conf-entry (aget conf-alist conf-key t))
13244 (ent-name (match-string-no-properties 2))
13245 (ent-key (downcase ent-name))
13246 (lib-alist (vhdl-scan-context-clause))
13247 (conf-line (vhdl-current-line))
13248 (end-of-unit (vhdl-get-end-of-unit))
13249 arch-key comp-conf-list inst-key-list
13250 inst-comp-key inst-ent-key inst-arch-key
13251 inst-conf-key inst-lib-key)
13252 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13253 (setq arch-key (vhdl-match-string-downcase 1)))
13254 (if conf-entry
13255 (vhdl-warning-when-idle
13256 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13257 conf-name ent-name (nth 1 conf-entry)
13258 (nth 2 conf-entry) file-name conf-line)
13259 (setq conf-list (cons conf-key conf-list))
13260 ;; scan for subconfigurations and subentities
13261 (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)
13262 (setq inst-comp-key (vhdl-match-string-downcase 3)
13263 inst-key-list (split-string
13264 (vhdl-match-string-downcase 1)
13265 "[ \t\n]*,[ \t\n]*"))
13266 (vhdl-forward-syntactic-ws)
13267 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13268 (setq
13269 inst-lib-key (vhdl-match-string-downcase 3)
13270 inst-ent-key (and (match-string 2)
13271 (vhdl-match-string-downcase 4))
13272 inst-arch-key (and (match-string 2)
13273 (vhdl-match-string-downcase 6))
13274 inst-conf-key (and (not (match-string 2))
13275 (vhdl-match-string-downcase 4)))
13276 (while inst-key-list
13277 (setq comp-conf-list
13278 (cons (list (car inst-key-list)
13279 inst-comp-key inst-ent-key
13280 inst-arch-key inst-conf-key
13281 inst-lib-key)
13282 comp-conf-list))
13283 (setq inst-key-list (cdr inst-key-list)))))
13284 (aput 'conf-alist conf-key
13285 (list conf-name file-name conf-line ent-key
13286 arch-key comp-conf-list lib-alist)))))
13287 ;; scan for packages
13288 (goto-char (point-min))
13289 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13290 (let* ((pack-name (match-string-no-properties 2))
13291 (pack-key (downcase pack-name))
13292 (is-body (match-string-no-properties 1))
13293 (pack-entry (aget pack-alist pack-key t))
13294 (pack-line (vhdl-current-line))
13295 (end-of-unit (vhdl-get-end-of-unit))
13296 comp-name func-name comp-alist func-alist lib-alist)
13297 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13298 (vhdl-warning-when-idle
13299 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13300 (if is-body " body" "") pack-name
13301 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13302 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13303 file-name (vhdl-current-line))
13304 ;; scan for context clauses
13305 (setq lib-alist (vhdl-scan-context-clause))
13306 ;; scan for component and subprogram declarations/bodies
13307 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13308 (if (equal (upcase (match-string 1)) "COMPONENT")
13309 (setq comp-name (match-string-no-properties 2)
13310 comp-alist
13311 (cons (list (downcase comp-name) comp-name
13312 file-name (vhdl-current-line))
13313 comp-alist))
13314 (setq func-name (match-string-no-properties 2)
13315 func-alist
13316 (cons (list (downcase func-name) func-name
13317 file-name (vhdl-current-line))
13318 func-alist))))
13319 (setq func-alist (nreverse func-alist))
13320 (setq comp-alist (nreverse comp-alist))
13321 (if is-body
13322 (setq pack-body-list (cons pack-key pack-body-list))
13323 (setq pack-list (cons pack-key pack-list)))
13324 (aput
13325 'pack-alist pack-key
13326 (if is-body
13327 (list (or (nth 0 pack-entry) pack-name)
13328 (nth 1 pack-entry) (nth 2 pack-entry)
13329 (nth 3 pack-entry) (nth 4 pack-entry)
13330 (nth 5 pack-entry)
13331 file-name pack-line func-alist lib-alist)
13332 (list pack-name file-name pack-line
13333 comp-alist func-alist lib-alist
13334 (nth 6 pack-entry) (nth 7 pack-entry)
13335 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13336 ;; scan for hierarchy
13337 (if (and limit-hier-file-size
13338 (< limit-hier-file-size (buffer-size)))
13339 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13340 (setq big-files t))
13341 ;; scan for architectures
13342 (goto-char (point-min))
13343 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13344 (let* ((ent-name (match-string-no-properties 2))
13345 (ent-key (downcase ent-name))
13346 (arch-name (match-string-no-properties 1))
13347 (arch-key (downcase arch-name))
13348 (ent-entry (aget ent-alist ent-key t))
13349 (arch-alist (nth 3 ent-entry))
13350 (arch-entry (aget arch-alist arch-key t))
13351 (beg-of-unit (point))
13352 (end-of-unit (vhdl-get-end-of-unit))
13353 (inst-no 0)
0a2e512a 13354 inst-alist inst-path)
3dcb36b7
JB
13355 ;; scan for contained instantiations
13356 (while (and (re-search-forward
13357 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13358 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13359 "component[ \t\n]+\\(\\w+\\)\\|"
0a2e512a
RF
13360 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13361 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13362 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
3dcb36b7
JB
13363 (or (not limit-hier-inst-no)
13364 (<= (setq inst-no (1+ inst-no))
13365 limit-hier-inst-no)))
0a2e512a
RF
13366 (cond
13367 ;; block/generate beginning found
13368 ((match-string 14)
13369 (setq inst-path
13370 (cons (match-string-no-properties 1) inst-path)))
13371 ;; block/generate end found
13372 ((match-string 16)
13373 (setq inst-path (cdr inst-path)))
13374 ;; instantiation found
13375 (t
13376 (let* ((inst-name (match-string-no-properties 1))
13377 (inst-key (downcase inst-name))
13378 (inst-comp-name
13379 (or (match-string-no-properties 3)
13380 (match-string-no-properties 6)))
13381 (inst-ent-key
13382 (or (and (match-string 8)
13383 (vhdl-match-string-downcase 11))
13384 (and inst-comp-name
13385 (downcase inst-comp-name))))
13386 (inst-arch-key (vhdl-match-string-downcase 13))
13387 (inst-conf-key
13388 (and (not (match-string 8))
13389 (vhdl-match-string-downcase 11)))
13390 (inst-lib-key (vhdl-match-string-downcase 10)))
13391 (goto-char (match-end 1))
13392 (setq inst-list (cons inst-key inst-list)
13393 inst-ent-list
13394 (cons inst-ent-key inst-ent-list))
13395 (setq inst-alist
13396 (append
13397 inst-alist
13398 (list (list inst-key inst-name file-name
13399 (vhdl-current-line) inst-comp-name
13400 inst-ent-key inst-arch-key
13401 inst-conf-key inst-lib-key
13402 (reverse inst-path)))))))))
3dcb36b7
JB
13403 ;; scan for contained configuration specifications
13404 (goto-char beg-of-unit)
13405 (while (re-search-forward
13406 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13407 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
0a2e512a 13408 (let* ((inst-comp-name (match-string-no-properties 3))
3dcb36b7
JB
13409 (inst-ent-key
13410 (and (match-string 6)
13411 (vhdl-match-string-downcase 9)))
13412 (inst-arch-key (vhdl-match-string-downcase 11))
13413 (inst-conf-key
13414 (and (not (match-string 6))
13415 (vhdl-match-string-downcase 9)))
13416 (inst-lib-key (vhdl-match-string-downcase 8))
13417 (inst-key-list
13418 (split-string (vhdl-match-string-downcase 1)
13419 "[ \t\n]*,[ \t\n]*"))
13420 (tmp-inst-alist inst-alist)
13421 inst-entry)
13422 (while tmp-inst-alist
13423 (when (and (or (equal "all" (car inst-key-list))
13424 (member (nth 0 (car tmp-inst-alist))
13425 inst-key-list))
13426 (equal
13427 (downcase
13428 (or (nth 4 (car tmp-inst-alist)) ""))
13429 (downcase inst-comp-name)))
13430 (setq inst-entry (car tmp-inst-alist))
13431 (setq inst-ent-list
13432 (cons (or inst-ent-key (nth 5 inst-entry))
13433 (vhdl-delete
13434 (nth 5 inst-entry) inst-ent-list)))
13435 (setq inst-entry
13436 (list (nth 0 inst-entry) (nth 1 inst-entry)
13437 (nth 2 inst-entry) (nth 3 inst-entry)
13438 (nth 4 inst-entry)
13439 (or inst-ent-key (nth 5 inst-entry))
13440 (or inst-arch-key (nth 6 inst-entry))
13441 inst-conf-key inst-lib-key))
13442 (setcar tmp-inst-alist inst-entry))
13443 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13444 ;; save in cache
13445 (aput 'arch-alist arch-key
13446 (list (nth 0 arch-entry) (nth 1 arch-entry)
13447 (nth 2 arch-entry) inst-alist
13448 (nth 4 arch-entry)))
13449 (aput 'ent-alist ent-key
13450 (list (nth 0 ent-entry) (nth 1 ent-entry)
13451 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
0a2e512a 13452 (nth 4 ent-entry) (nth 5 ent-entry)))
3dcb36b7
JB
13453 (when (and limit-hier-inst-no
13454 (> inst-no limit-hier-inst-no))
13455 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13456 (setq big-files t))
13457 (goto-char end-of-unit))))
13458 ;; remember design units for this file
13459 (aput 'file-alist file-name
13460 (list ent-list arch-list arch-ent-list conf-list
13461 pack-list pack-body-list inst-list inst-ent-list))
13462 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13463 (setq file-list (cdr file-list))))
13464 (when (or (and (not project) files-exist)
13465 (and project (not non-final)))
13466 ;; consistency checks:
13467 ;; check whether each architecture has a corresponding entity
13468 (setq tmp-list ent-alist)
13469 (while tmp-list
13470 (when (null (nth 2 (car tmp-list)))
13471 (setq tmp-entry (car (nth 4 (car tmp-list))))
13472 (vhdl-warning-when-idle
13473 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13474 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13475 (nth 3 tmp-entry)))
13476 (setq tmp-list (cdr tmp-list)))
13477 ;; check whether configuration has a corresponding entity/architecture
13478 (setq tmp-list conf-alist)
13479 (while tmp-list
13480 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13481 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13482 (setq tmp-entry (car tmp-list))
13483 (vhdl-warning-when-idle
13484 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13485 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13486 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13487 (setq tmp-entry (car tmp-list))
13488 (vhdl-warning-when-idle
13489 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13490 (nth 1 tmp-entry) (nth 4 tmp-entry)
13491 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13492 (setq tmp-list (cdr tmp-list)))
13493 ;; check whether each package body has a package declaration
13494 (setq tmp-list pack-alist)
13495 (while tmp-list
13496 (when (null (nth 2 (car tmp-list)))
13497 (setq tmp-entry (car tmp-list))
13498 (vhdl-warning-when-idle
13499 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13500 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13501 (setq tmp-list (cdr tmp-list)))
13502 ;; sort lists
13503 (setq ent-alist (vhdl-sort-alist ent-alist))
13504 (setq conf-alist (vhdl-sort-alist conf-alist))
13505 (setq pack-alist (vhdl-sort-alist pack-alist))
13506 ;; remember updated directory/project
13507 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13508 ;; clear directory alists
13509 (unless project
13510 (adelete 'vhdl-entity-alist key)
13511 (adelete 'vhdl-config-alist key)
13512 (adelete 'vhdl-package-alist key)
13513 (adelete 'vhdl-ent-inst-alist key)
13514 (adelete 'vhdl-file-alist key))
13515 ;; put directory contents into cache
13516 (aput 'vhdl-entity-alist key ent-alist)
13517 (aput 'vhdl-config-alist key conf-alist)
13518 (aput 'vhdl-package-alist key pack-alist)
13519 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13520 (aput 'vhdl-file-alist key file-alist)
13521 ;; final messages
13522 (message "Scanning %s %s\"%s\"...done"
13523 (if is-directory "directory" "files") (or num-string "") name)
13524 (unless project (message "Scanning directory...done"))
13525 (when big-files
13526 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13527 ;; save cache when scanned non-interactively
13528 (when (or (not project) (not non-final))
13529 (when (and noninteractive vhdl-speedbar-save-cache)
13530 (vhdl-save-cache key)))
13531 t))
5eabfe72 13532
3dcb36b7 13533(defun vhdl-scan-project-contents (project)
5eabfe72
KH
13534 "Scan the contents of all VHDL files found in the directories and files
13535of PROJECT."
3dcb36b7
JB
13536 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13537 (default-dir (vhdl-resolve-env-variable
13538 (nth 1 (aget vhdl-project-alist project))))
13539 (file-exclude-regexp
13540 (or (nth 3 (aget vhdl-project-alist project)) ""))
13541 dir-list-tmp dir dir-name num-dir act-dir recursive)
13542 ;; clear project alists
13543 (adelete 'vhdl-entity-alist project)
13544 (adelete 'vhdl-config-alist project)
13545 (adelete 'vhdl-package-alist project)
13546 (adelete 'vhdl-ent-inst-alist project)
13547 (adelete 'vhdl-file-alist project)
13548 ;; expand directory names by default-directory
13549 (message "Collecting source files...")
13550 (while dir-list
13551 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13552 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13553 (setq recursive (match-string 1 dir)
13554 dir-name (match-string 3 dir))
13555 (setq dir-list-tmp
13556 (cons (concat recursive
13557 (if (file-name-absolute-p dir-name) "" default-dir)
13558 dir-name)
13559 dir-list-tmp))
13560 (setq dir-list (cdr dir-list)))
13561 ;; resolve path wildcards
5eabfe72
KH
13562 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13563 ;; expand directories
13564 (while dir-list-tmp
13565 (setq dir (car dir-list-tmp))
13566 ;; get subdirectories
3dcb36b7 13567 (if (string-match "-r \\(.*[/\\]\\)" dir)
5eabfe72
KH
13568 (setq dir-list (append dir-list (vhdl-get-subdirs
13569 (match-string 1 dir))))
13570 (setq dir-list (append dir-list (list dir))))
13571 (setq dir-list-tmp (cdr dir-list-tmp)))
3dcb36b7
JB
13572 ;; exclude files
13573 (unless (equal file-exclude-regexp "")
13574 (let ((case-fold-search nil))
13575 (while dir-list
13576 (unless (string-match file-exclude-regexp (car dir-list))
13577 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13578 (setq dir-list (cdr dir-list)))
13579 (setq dir-list (nreverse dir-list-tmp))))
13580 (message "Collecting source files...done")
13581 ;; scan for design units for each directory in DIR-LIST
13582 (setq dir-list-tmp nil
13583 num-dir (length dir-list)
5eabfe72
KH
13584 act-dir 1)
13585 (while dir-list
3dcb36b7
JB
13586 (setq dir-name (abbreviate-file-name
13587 (expand-file-name (car dir-list))))
13588 (vhdl-scan-directory-contents dir-name project nil
13589 (format "(%s/%s) " act-dir num-dir)
13590 (cdr dir-list))
13591 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
5eabfe72
KH
13592 (setq dir-list (cdr dir-list)
13593 act-dir (1+ act-dir)))
3dcb36b7
JB
13594 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13595 (message "Scanning project \"%s\"...done" project)))
13596
13597(defun vhdl-update-file-contents (file-name)
13598 "Update hierarchy information by contents of current buffer."
13599 (setq file-name (abbreviate-file-name file-name))
13600 (let* ((dir-name (file-name-directory file-name))
13601 (directory-alist vhdl-directory-alist)
13602 updated)
13603 (while directory-alist
13604 (when (member dir-name (nth 1 (car directory-alist)))
13605 (let* ((vhdl-project (nth 0 (car directory-alist)))
13606 (project (vhdl-project-p))
13607 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13608 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13609 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13610 (ent-inst-list (car (aget vhdl-ent-inst-alist
13611 (or project dir-name) t)))
13612 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13613 (file-entry (aget file-alist file-name t))
13614 (ent-list (nth 0 file-entry))
13615 (arch-list (nth 1 file-entry))
13616 (arch-ent-list (nth 2 file-entry))
13617 (conf-list (nth 3 file-entry))
13618 (pack-list (nth 4 file-entry))
13619 (pack-body-list (nth 5 file-entry))
13620 (inst-ent-list (nth 7 file-entry))
13621 (cache-key (or project dir-name))
13622 arch-alist key ent-key entry)
13623 ;; delete design units previously contained in this file:
13624 ;; entities
13625 (while ent-list
13626 (setq key (car ent-list)
13627 entry (aget ent-alist key t))
13628 (when (equal file-name (nth 1 entry))
13629 (if (nth 3 entry)
13630 (aput 'ent-alist key
13631 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13632 (adelete 'ent-alist key)))
13633 (setq ent-list (cdr ent-list)))
13634 ;; architectures
13635 (while arch-list
13636 (setq key (car arch-list)
13637 ent-key (car arch-ent-list)
13638 entry (aget ent-alist ent-key t)
13639 arch-alist (nth 3 entry))
13640 (when (equal file-name (nth 1 (aget arch-alist key t)))
13641 (adelete 'arch-alist key)
13642 (if (or (nth 1 entry) arch-alist)
13643 (aput 'ent-alist ent-key
13644 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
0a2e512a 13645 arch-alist (nth 4 entry) (nth 5 entry)))
3dcb36b7
JB
13646 (adelete 'ent-alist ent-key)))
13647 (setq arch-list (cdr arch-list)
13648 arch-ent-list (cdr arch-ent-list)))
13649 ;; configurations
13650 (while conf-list
13651 (setq key (car conf-list))
13652 (when (equal file-name (nth 1 (aget conf-alist key t)))
13653 (adelete 'conf-alist key))
13654 (setq conf-list (cdr conf-list)))
13655 ;; package declarations
13656 (while pack-list
13657 (setq key (car pack-list)
13658 entry (aget pack-alist key t))
13659 (when (equal file-name (nth 1 entry))
13660 (if (nth 6 entry)
13661 (aput 'pack-alist key
13662 (list (nth 0 entry) nil nil nil nil nil
13663 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13664 (nth 9 entry)))
13665 (adelete 'pack-alist key)))
13666 (setq pack-list (cdr pack-list)))
13667 ;; package bodies
13668 (while pack-body-list
13669 (setq key (car pack-body-list)
13670 entry (aget pack-alist key t))
13671 (when (equal file-name (nth 6 entry))
13672 (if (nth 1 entry)
13673 (aput 'pack-alist key
13674 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13675 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13676 nil nil nil nil))
13677 (adelete 'pack-alist key)))
13678 (setq pack-body-list (cdr pack-body-list)))
13679 ;; instantiated entities
13680 (while inst-ent-list
13681 (setq ent-inst-list
13682 (vhdl-delete (car inst-ent-list) ent-inst-list))
13683 (setq inst-ent-list (cdr inst-ent-list)))
13684 ;; update caches
13685 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13686 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13687 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13688 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13689 ;; scan file
13690 (vhdl-scan-directory-contents file-name project t)
13691 (when (or (and vhdl-speedbar-show-projects project)
13692 (and (not vhdl-speedbar-show-projects) (not project)))
13693 (vhdl-speedbar-refresh project))
13694 (setq updated t)))
13695 (setq directory-alist (cdr directory-alist)))
13696 updated))
13697
13698(defun vhdl-update-hierarchy ()
13699 "Update directory and hierarchy information in speedbar."
13700 (let ((file-list (reverse vhdl-modified-file-list))
13701 updated)
13702 (when (and vhdl-speedbar-update-on-saving file-list)
13703 (while file-list
13704 (setq updated
13705 (or (vhdl-update-file-contents (car file-list))
13706 updated))
13707 (setq file-list (cdr file-list)))
13708 (setq vhdl-modified-file-list nil)
0a2e512a 13709 (vhdl-speedbar-update-current-unit)
3dcb36b7
JB
13710 (when updated (message "Updating hierarchy...done")))))
13711
13712;; structure (parenthesised expression means list of such entries)
13713;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13714;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13715;; comp-lib-name level)
13716(defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13717 conf-inst-alist level indent
13718 &optional include-top ent-hier)
13719 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13720entity ENT-KEY."
13721 (let* ((ent-entry (aget ent-alist ent-key t))
13722 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13723 (cdar (last (nth 3 ent-entry)))))
13724 (inst-alist (nth 3 arch-entry))
13725 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13726 hier-list subcomp-list tmp-list inst-key inst-comp-name
13727 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
5eabfe72 13728 (when (= level 0) (message "Extract design hierarchy..."))
3dcb36b7
JB
13729 (when include-top
13730 (setq level (1+ level)))
13731 (when (member ent-key ent-hier)
13732 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13733 ;; check configured architecture (already checked during scanning)
13734; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13735; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13736 ;; process all instances
13737 (while inst-alist
13738 (setq inst-entry (car inst-alist)
13739 inst-key (nth 0 inst-entry)
13740 inst-comp-name (nth 4 inst-entry)
13741 inst-conf-key (nth 7 inst-entry))
13742 ;; search entry in configuration's instantiations list
13743 (setq tmp-list conf-inst-alist)
13744 (while (and tmp-list
13745 (not (and (member (nth 0 (car tmp-list))
13746 (list "all" inst-key))
13747 (equal (nth 1 (car tmp-list))
13748 (downcase (or inst-comp-name ""))))))
13749 (setq tmp-list (cdr tmp-list)))
13750 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13751 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13752 (when (and inst-conf-key (not inst-conf-entry))
13753 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13754 ;; determine entity
13755 (setq inst-ent-key
13756 (or (nth 2 (car tmp-list)) ; from configuration
13757 (nth 3 inst-conf-entry) ; from subconfiguration
13758 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13759 ; from configuration spec.
13760 (nth 5 inst-entry))) ; from direct instantiation
13761 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13762 ;; determine architecture
13763 (setq inst-arch-key
0a2e512a
RF
13764 (or (nth 3 (car tmp-list)) ; from configuration
13765 (nth 4 inst-conf-entry) ; from subconfiguration
13766 (nth 6 inst-entry) ; from direct instantiation
3dcb36b7 13767 (nth 4 (aget conf-alist (nth 7 inst-entry)))
0a2e512a
RF
13768 ; from configuration spec.
13769 (nth 4 inst-ent-entry) ; MRA
13770 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
3dcb36b7
JB
13771 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13772 ;; set library
13773 (setq inst-lib-key
0a2e512a
RF
13774 (or (nth 5 (car tmp-list)) ; from configuration
13775 (nth 8 inst-entry))) ; from direct instantiation
3dcb36b7
JB
13776 ;; gather information for this instance
13777 (setq comp-entry
13778 (list (nth 1 inst-entry)
13779 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13780 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13781 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13782 (or (nth 0 inst-arch-entry) inst-arch-key)
13783 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13784 (or (nth 0 inst-conf-entry) inst-conf-key)
13785 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13786 inst-lib-key level))
13787 ;; get subcomponent hierarchy
13788 (setq subcomp-list (vhdl-get-hierarchy
13789 ent-alist conf-alist
13790 inst-ent-key inst-arch-key inst-conf-key
13791 (nth 5 inst-conf-entry)
13792 (1+ level) indent nil (cons ent-key ent-hier)))
13793 ;; add to list
13794 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13795 (setq inst-alist (cdr inst-alist)))
13796 (when include-top
5eabfe72 13797 (setq hier-list
3dcb36b7
JB
13798 (cons (list nil nil (nth 0 ent-entry)
13799 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13800 (nth 0 arch-entry)
13801 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13802 nil nil
13803 nil (1- level))
13804 hier-list)))
13805 (when (or (= level 0) (and include-top (= level 1))) (message ""))
5eabfe72
KH
13806 hier-list))
13807
3dcb36b7
JB
13808(defun vhdl-get-instantiations (ent-key indent)
13809 "Get all instantiations of entity ENT-KEY."
13810 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
5eabfe72
KH
13811 arch-alist inst-alist ent-inst-list
13812 ent-entry arch-entry inst-entry)
13813 (while ent-alist
13814 (setq ent-entry (car ent-alist))
3dcb36b7 13815 (setq arch-alist (nth 4 ent-entry))
5eabfe72
KH
13816 (while arch-alist
13817 (setq arch-entry (car arch-alist))
3dcb36b7 13818 (setq inst-alist (nth 4 arch-entry))
5eabfe72
KH
13819 (while inst-alist
13820 (setq inst-entry (car inst-alist))
3dcb36b7 13821 (when (equal ent-key (nth 5 inst-entry))
5eabfe72 13822 (setq ent-inst-list
3dcb36b7
JB
13823 (cons (list (nth 1 inst-entry)
13824 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13825 (nth 1 ent-entry)
13826 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13827 (nth 1 arch-entry)
13828 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13829 ent-inst-list)))
5eabfe72
KH
13830 (setq inst-alist (cdr inst-alist)))
13831 (setq arch-alist (cdr arch-alist)))
13832 (setq ent-alist (cdr ent-alist)))
13833 (nreverse ent-inst-list)))
13834
13835;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
13836;; Caching in file
13837
13838(defun vhdl-save-caches ()
13839 "Save all updated hierarchy caches to file."
13840 (interactive)
13841 (condition-case nil
13842 (when vhdl-speedbar-save-cache
13843 ;; update hierarchy
13844 (vhdl-update-hierarchy)
13845 (let ((project-list vhdl-updated-project-list))
13846 (message "Saving hierarchy caches...")
13847 ;; write updated project caches
13848 (while project-list
13849 (vhdl-save-cache (car project-list))
13850 (setq project-list (cdr project-list)))
13851 (message "Saving hierarchy caches...done")))
13852 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13853 (sit-for 2)))))
13854
13855(defun vhdl-save-cache (key)
13856 "Save current hierarchy cache to file."
13857 (let* ((orig-buffer (current-buffer))
13858 (vhdl-project key)
13859 (project (vhdl-project-p))
13860 (default-directory key)
13861 (directory (abbreviate-file-name (vhdl-default-directory)))
13862 (file-name (vhdl-resolve-env-variable
13863 (vhdl-replace-string
13864 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13865 (concat
13866 (subst-char-in-string ? ?_ (or project "dir"))
13867 " " (user-login-name)))))
13868 (file-dir-name (expand-file-name file-name directory))
13869 (cache-key (or project directory))
13870 (key (if project "project" "directory")))
13871 (unless (file-exists-p (file-name-directory file-dir-name))
13872 (make-directory (file-name-directory file-dir-name) t))
13873 (if (not (file-writable-p file-dir-name))
13874 (progn (vhdl-warning (format "File not writable: \"%s\""
13875 (abbreviate-file-name file-dir-name)))
13876 (sit-for 2))
13877 (message "Saving cache: \"%s\"" file-dir-name)
13878 (set-buffer (find-file-noselect file-dir-name t t))
13879 (erase-buffer)
13880 (insert ";; -*- Emacs-Lisp -*-\n\n"
13881 ";;; " (file-name-nondirectory file-name)
13882 " - design hierarchy cache file for Emacs VHDL Mode "
13883 vhdl-version "\n")
13884 (insert "\n;; " (if project "Project " "Directory") " : ")
13885 (if project (insert project) (prin1 directory (current-buffer)))
13886 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13887 (user-login-name) "\n\n"
13888 "\n;; version number\n"
13889 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13890 "\n;; " (if project "project" "directory") " name"
13891 "\n(setq " key " ")
13892 (prin1 (or project directory) (current-buffer))
13893 (insert ")\n")
13894 (when (member 'hierarchy vhdl-speedbar-save-cache)
13895 (insert "\n;; entity and architecture cache\n"
13896 "(aput 'vhdl-entity-alist " key " '")
13897 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13898 (insert ")\n\n;; configuration cache\n"
13899 "(aput 'vhdl-config-alist " key " '")
13900 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13901 (insert ")\n\n;; package cache\n"
13902 "(aput 'vhdl-package-alist " key " '")
13903 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13904 (insert ")\n\n;; instantiated entities cache\n"
13905 "(aput 'vhdl-ent-inst-alist " key " '")
13906 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13907 (insert ")\n\n;; design units per file cache\n"
13908 "(aput 'vhdl-file-alist " key " '")
13909 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13910 (when project
13911 (insert ")\n\n;; source directories in project cache\n"
13912 "(aput 'vhdl-directory-alist " key " '")
13913 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13914 (insert ")\n"))
13915 (when (member 'display vhdl-speedbar-save-cache)
13916 (insert "\n;; shown design units cache\n"
13917 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13918 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13919 (current-buffer))
13920 (insert ")\n"))
13921 (setq vhdl-updated-project-list
13922 (delete cache-key vhdl-updated-project-list))
13923 (save-buffer)
13924 (kill-buffer (current-buffer))
13925 (set-buffer orig-buffer))))
13926
13927(defun vhdl-load-cache (key)
13928 "Load hierarchy cache information from file."
13929 (let* ((vhdl-project key)
13930 (default-directory key)
13931 (directory (vhdl-default-directory))
13932 (file-name (vhdl-resolve-env-variable
13933 (vhdl-replace-string
13934 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13935 (concat
13936 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13937 " " (user-login-name)))))
13938 (file-dir-name (expand-file-name file-name directory))
13939 vhdl-cache-version)
13940 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13941 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13942 (when (file-exists-p file-dir-name)
13943 (condition-case ()
13944 (progn (load-file file-dir-name)
13945 (string< (mapconcat
027a4b6b 13946 (lambda (a) (format "%3d" (string-to-number a)))
0a2e512a 13947 (split-string "3.33" "\\.") "")
3dcb36b7 13948 (mapconcat
027a4b6b 13949 (lambda (a) (format "%3d" (string-to-number a)))
3dcb36b7
JB
13950 (split-string vhdl-cache-version "\\.") "")))
13951 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13952 nil))))))
13953
13954(defun vhdl-require-hierarchy-info ()
13955 "Make sure that hierarchy information is available. Load cache or scan files
13956if required."
13957 (if (vhdl-project-p)
13958 (unless (or (assoc vhdl-project vhdl-file-alist)
13959 (vhdl-load-cache vhdl-project))
13960 (vhdl-scan-project-contents vhdl-project))
13961 (let ((directory (abbreviate-file-name default-directory)))
13962 (unless (or (assoc directory vhdl-file-alist)
13963 (vhdl-load-cache directory))
13964 (vhdl-scan-directory-contents directory)))))
13965
13966;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13967;; Add hierarchy browser functionality to speedbar
5eabfe72
KH
13968
13969(defvar vhdl-speedbar-key-map nil
13970 "Keymap used when in the VHDL hierarchy browser mode.")
13971
3dcb36b7 13972(defvar vhdl-speedbar-menu-items nil
5eabfe72
KH
13973 "Additional menu-items to add to speedbar frame.")
13974
13975(defun vhdl-speedbar-initialize ()
13976 "Initialize speedbar."
13977 ;; general settings
13978; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13979 ;; VHDL file extensions (extracted from `auto-mode-alist')
13980 (let ((mode-alist auto-mode-alist))
13981 (while mode-alist
3dcb36b7
JB
13982 (when (eq (cdar mode-alist) 'vhdl-mode)
13983 (speedbar-add-supported-extension (caar mode-alist)))
5eabfe72
KH
13984 (setq mode-alist (cdr mode-alist))))
13985 ;; hierarchy browser settings
13986 (when (boundp 'speedbar-mode-functions-list)
3dcb36b7 13987 ;; special functions
5eabfe72 13988 (speedbar-add-mode-functions-list
3dcb36b7 13989 '("vhdl directory"
5eabfe72
KH
13990 (speedbar-item-info . vhdl-speedbar-item-info)
13991 (speedbar-line-path . speedbar-files-line-path)))
3dcb36b7
JB
13992 (speedbar-add-mode-functions-list
13993 '("vhdl project"
13994 (speedbar-item-info . vhdl-speedbar-item-info)
13995 (speedbar-line-path . vhdl-speedbar-line-project)))
13996 ;; keymap
5eabfe72
KH
13997 (unless vhdl-speedbar-key-map
13998 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13999 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14000 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14001 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
3dcb36b7
JB
14002 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14003 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14004 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14005 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14006 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
0a2e512a
RF
14007 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14008 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
3dcb36b7
JB
14009 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14010 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14011 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14012 (let ((key 0))
14013 (while (<= key 9)
14014 (define-key vhdl-speedbar-key-map (int-to-string key)
14015 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14016 (setq key (1+ key)))))
5eabfe72
KH
14017 (define-key speedbar-key-map "h"
14018 (lambda () (interactive)
3dcb36b7
JB
14019 (speedbar-change-initial-expansion-list "vhdl directory")))
14020 (define-key speedbar-key-map "H"
14021 (lambda () (interactive)
14022 (speedbar-change-initial-expansion-list "vhdl project")))
14023 ;; menu
14024 (unless vhdl-speedbar-menu-items
14025 (setq
14026 vhdl-speedbar-menu-items
14027 `(["Edit" speedbar-edit-line t]
14028 ["Expand" speedbar-expand-line
14029 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14030 ["Contract" vhdl-speedbar-contract-level t]
14031 ["Expand All" vhdl-speedbar-expand-all t]
14032 ["Contract All" vhdl-speedbar-contract-all t]
14033 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14034 (while (<= key 9)
14035 (setq menu-list
14036 (cons `[,(if (= key 0) "All" (int-to-string key))
14037 (vhdl-speedbar-set-depth ,key)
14038 :style radio
14039 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14040 :keys ,(int-to-string key)]
14041 menu-list))
14042 (setq key (1+ key)))
14043 (nreverse menu-list))
14044 "--"
14045 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14046 (or (vhdl-speedbar-check-unit 'entity)
14047 (vhdl-speedbar-check-unit 'subprogram))]
14048 ["Place Component" vhdl-speedbar-place-component
14049 (vhdl-speedbar-check-unit 'entity)]
0a2e512a
RF
14050 ["Generate Configuration" vhdl-speedbar-configuration
14051 (vhdl-speedbar-check-unit 'architecture)]
14052 ["Select as MRA" vhdl-speedbar-select-mra
14053 (vhdl-speedbar-check-unit 'architecture)]
3dcb36b7
JB
14054 ["Make" vhdl-speedbar-make-design
14055 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14056 ["Generate Makefile" vhdl-speedbar-generate-makefile
14057 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14058 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14059 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14060 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
14061 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14062 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14063 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
14064 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14065 ;; hook-ups
14066 (speedbar-add-expansion-list
14067 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14068 vhdl-speedbar-display-directory))
14069 (speedbar-add-expansion-list
14070 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14071 vhdl-speedbar-display-projects))
5eabfe72 14072 (setq speedbar-stealthy-function-list
3dcb36b7
JB
14073 (append
14074 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14075 ("vhdl project" vhdl-speedbar-update-current-project
14076 vhdl-speedbar-update-current-unit)
14077; ("files" (lambda () (setq speedbar-ignored-path-regexp
14078; (speedbar-extension-list-to-regex
14079; speedbar-ignored-path-expressions))))
14080 )
14081 speedbar-stealthy-function-list))
14082 (when (eq vhdl-speedbar-display-mode 'directory)
14083 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14084 (when (eq vhdl-speedbar-display-mode 'project)
14085 (setq speedbar-initial-expansion-list-name "vhdl project"))
14086 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
5eabfe72
KH
14087
14088(defun vhdl-speedbar (&optional arg)
14089 "Open/close speedbar."
d2ddb974 14090 (interactive)
5eabfe72 14091 (if (not (fboundp 'speedbar))
3dcb36b7
JB
14092 (error "WARNING: Speedbar is not available or not installed")
14093 (condition-case ()
5eabfe72 14094 (speedbar-frame-mode arg)
3dcb36b7 14095 (error (error "WARNING: An error occurred while opening speedbar")))))
5eabfe72
KH
14096
14097;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14098;; Display functions
14099
3dcb36b7
JB
14100(defvar vhdl-speedbar-last-selected-project nil
14101 "Name of last selected project.")
14102
5eabfe72
KH
14103;; macros must be defined in the file they are used (copied from `speedbar.el')
14104(defmacro speedbar-with-writable (&rest forms)
14105 "Allow the buffer to be writable and evaluate FORMS."
14106 (list 'let '((inhibit-read-only t))
14107 (cons 'progn forms)))
14108(put 'speedbar-with-writable 'lisp-indent-function 0)
14109
3dcb36b7 14110(defun vhdl-speedbar-display-directory (directory depth &optional rescan)
5eabfe72 14111 "Display directory and hierarchy information in speedbar."
3dcb36b7
JB
14112 (setq vhdl-speedbar-show-projects nil)
14113 (setq speedbar-ignored-path-regexp
14114 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
5eabfe72
KH
14115 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14116 (setq speedbar-last-selected-file nil)
14117 (speedbar-with-writable
3dcb36b7
JB
14118 (condition-case nil
14119 (progn
14120 ;; insert directory path
14121 (speedbar-directory-buttons directory depth)
14122 ;; insert subdirectories
14123 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14124 ;; scan and insert hierarchy of current directory
14125 (vhdl-speedbar-insert-dir-hierarchy directory depth
14126 speedbar-power-click)
14127 ;; expand subdirectories
14128 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14129 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14130
14131(defun vhdl-speedbar-display-projects (project depth &optional rescan)
14132 "Display projects and hierarchy information in speedbar."
14133 (setq vhdl-speedbar-show-projects t)
14134 (setq speedbar-ignored-path-regexp ".")
14135 (setq speedbar-last-selected-file nil)
14136 (setq vhdl-speedbar-last-selected-project nil)
14137 (speedbar-with-writable
14138 (condition-case nil
14139 ;; insert projects
14140 (vhdl-speedbar-insert-projects)
14141 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14142 (setq speedbar-full-text-cache nil)) ; prevent caching
14143
14144(defun vhdl-speedbar-insert-projects ()
14145 "Insert all projects in speedbar."
14146 (vhdl-speedbar-make-title-line "Projects:")
14147 (let ((project-alist (if vhdl-project-sort
14148 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14149 vhdl-project-alist))
14150 (vhdl-speedbar-update-current-unit nil))
14151 ;; insert projects
14152 (while project-alist
14153 (speedbar-make-tag-line
14154 'angle ?+ 'vhdl-speedbar-expand-project
14155 (caar project-alist) (caar project-alist)
14156 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14157 (setq project-alist (cdr project-alist)))
14158 (setq project-alist vhdl-project-alist)
14159 ;; expand projects
14160 (while project-alist
14161 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14162 (goto-char (point-min))
14163 (when (re-search-forward
14164 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14165 (goto-char (match-end 1))
14166 (speedbar-do-function-pointer)))
14167 (setq project-alist (cdr project-alist))))
14168; (vhdl-speedbar-update-current-project)
14169; (vhdl-speedbar-update-current-unit nil t)
14170 )
14171
14172(defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14173 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
14174otherwise use cached data."
14175 (when (or rescan (and (not (assoc project vhdl-file-alist))
14176 (not (vhdl-load-cache project))))
14177 (vhdl-scan-project-contents project))
14178 ;; insert design hierarchy
14179 (vhdl-speedbar-insert-hierarchy
14180 (aget vhdl-entity-alist project t)
14181 (aget vhdl-config-alist project t)
14182 (aget vhdl-package-alist project t)
14183 (car (aget vhdl-ent-inst-alist project t)) indent)
14184 (insert (int-to-string indent) ":\n")
14185 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14186 (put-text-property (1- (point)) (point) 'invisible nil)
14187 ;; expand design units
14188 (vhdl-speedbar-expand-units project))
14189
14190(defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14191 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14192otherwise use cached data."
14193 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14194 (not (vhdl-load-cache directory))))
14195 (vhdl-scan-directory-contents directory))
14196 ;; insert design hierarchy
14197 (vhdl-speedbar-insert-hierarchy
14198 (aget vhdl-entity-alist directory t)
14199 (aget vhdl-config-alist directory t)
14200 (aget vhdl-package-alist directory t)
14201 (car (aget vhdl-ent-inst-alist directory t)) depth)
14202 ;; expand design units
14203 (vhdl-speedbar-expand-units directory)
14204 (aput 'vhdl-directory-alist directory (list (list directory))))
14205
14206(defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
5eabfe72 14207 ent-inst-list depth)
3dcb36b7
JB
14208 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14209 (if (not (or ent-alist conf-alist pack-alist))
14210 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14211 (let (ent-entry conf-entry pack-entry)
5eabfe72
KH
14212 ;; insert entities
14213 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14214 (while ent-alist
14215 (setq ent-entry (car ent-alist))
14216 (speedbar-make-tag-line
14217 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
3dcb36b7
JB
14218 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14219 (cons (nth 2 ent-entry) (nth 3 ent-entry))
0a2e512a 14220 'vhdl-speedbar-entity-face depth)
3dcb36b7
JB
14221 (unless (nth 2 ent-entry)
14222 (end-of-line 0) (insert "!") (forward-char 1))
14223 (unless (member (nth 0 ent-entry) ent-inst-list)
5eabfe72
KH
14224 (end-of-line 0) (insert " (top)") (forward-char 1))
14225 (setq ent-alist (cdr ent-alist)))
3dcb36b7
JB
14226 ;; insert configurations
14227 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14228 (while conf-alist
14229 (setq conf-entry (car conf-alist))
14230 (speedbar-make-tag-line
14231 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14232 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14233 (cons (nth 2 conf-entry) (nth 3 conf-entry))
0a2e512a 14234 'vhdl-speedbar-configuration-face depth)
3dcb36b7 14235 (setq conf-alist (cdr conf-alist)))
5eabfe72
KH
14236 ;; insert packages
14237 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14238 (while pack-alist
14239 (setq pack-entry (car pack-alist))
14240 (vhdl-speedbar-make-pack-line
3dcb36b7
JB
14241 (nth 0 pack-entry) (nth 1 pack-entry)
14242 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14243 (cons (nth 7 pack-entry) (nth 8 pack-entry))
5eabfe72
KH
14244 depth)
14245 (setq pack-alist (cdr pack-alist))))))
14246
5eabfe72 14247(defun vhdl-speedbar-rescan-hierarchy ()
3dcb36b7 14248 "Rescan hierarchy for the directory or project under the cursor."
d2ddb974 14249 (interactive)
3dcb36b7
JB
14250 (let (key path)
14251 (cond
14252 ;; current project
14253 (vhdl-speedbar-show-projects
14254 (setq key (vhdl-speedbar-line-project))
14255 (vhdl-scan-project-contents key))
14256 ;; top-level directory
14257 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14258 (re-search-forward "[0-9]+:" nil t)
14259 (vhdl-scan-directory-contents
14260 (abbreviate-file-name (speedbar-line-path))))
14261 ;; current directory
14262 (t (setq path (speedbar-line-path))
14263 (string-match "^\\(.+[/\\]\\)" path)
14264 (vhdl-scan-directory-contents
14265 (abbreviate-file-name (match-string 1 path)))))
14266 (vhdl-speedbar-refresh key)))
5eabfe72
KH
14267
14268(defun vhdl-speedbar-expand-dirs (directory)
14269 "Expand subdirectories in DIRECTORY according to
14270 `speedbar-shown-directories'."
14271 ;; (nicked from `speedbar-default-directory-list')
3dcb36b7
JB
14272 (let ((sf (cdr (reverse speedbar-shown-directories)))
14273 (vhdl-speedbar-update-current-unit nil))
5eabfe72
KH
14274 (setq speedbar-shown-directories
14275 (list (expand-file-name default-directory)))
14276 (while sf
14277 (when (speedbar-goto-this-file (car sf))
14278 (beginning-of-line)
14279 (when (looking-at "[0-9]+:\\s-*<")
14280 (goto-char (match-end 0))
3dcb36b7
JB
14281 (speedbar-do-function-pointer)))
14282 (setq sf (cdr sf))))
14283 (vhdl-speedbar-update-current-unit nil t))
14284
14285(defun vhdl-speedbar-expand-units (key)
14286 "Expand design units in directory/project KEY according to
14287`vhdl-speedbar-shown-unit-alist'."
14288 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14289 (vhdl-speedbar-update-current-unit nil)
14290 vhdl-updated-project-list)
14291 (adelete 'vhdl-speedbar-shown-unit-alist key)
14292 (vhdl-prepare-search-1
14293 (while unit-alist ; expand units
14294 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14295 (beginning-of-line)
14296 (let ((arch-alist (nth 1 (car unit-alist)))
14297 position)
14298 (when (looking-at "^[0-9]+:\\s-*\\[")
14299 (goto-char (match-end 0))
14300 (setq position (point))
14301 (speedbar-do-function-pointer)
14302 (select-frame speedbar-frame)
14303 (while arch-alist ; expand architectures
14304 (goto-char position)
14305 (when (re-search-forward
14306 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14307 (car arch-alist) "\\>\\)") nil t)
14308 (beginning-of-line)
14309 (when (looking-at "^[0-9]+:\\s-*{")
14310 (goto-char (match-end 0))
14311 (speedbar-do-function-pointer)
14312 (select-frame speedbar-frame)))
14313 (setq arch-alist (cdr arch-alist))))
14314 (setq unit-alist (cdr unit-alist))))))
14315 (vhdl-speedbar-update-current-unit nil t))
14316
14317(defun vhdl-speedbar-contract-level ()
14318 "Contract current level in current directory/project."
14319 (interactive)
14320 (when (or (save-excursion
14321 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14322 (and (save-excursion
14323 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14324 (re-search-backward
14325 (format "^[0-%d]:\\s-*[[{<]-"
027a4b6b 14326 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
3dcb36b7
JB
14327 (goto-char (match-end 0))
14328 (speedbar-do-function-pointer)
14329 (speedbar-center-buffer-smartly)))
14330
14331(defun vhdl-speedbar-contract-all ()
14332 "Contract all expanded design units in current directory/project."
14333 (interactive)
14334 (if (and vhdl-speedbar-show-projects
14335 (save-excursion (beginning-of-line) (looking-at "^0:")))
14336 (progn (setq vhdl-speedbar-shown-project-list nil)
14337 (vhdl-speedbar-refresh))
14338 (let ((key (vhdl-speedbar-line-key)))
14339 (adelete 'vhdl-speedbar-shown-unit-alist key)
14340 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14341 (when (memq 'display vhdl-speedbar-save-cache)
14342 (add-to-list 'vhdl-updated-project-list key)))))
14343
14344(defun vhdl-speedbar-expand-all ()
14345 "Expand all design units in current directory/project."
14346 (interactive)
14347 (let* ((key (vhdl-speedbar-line-key))
14348 (ent-alist (aget vhdl-entity-alist key t))
14349 (conf-alist (aget vhdl-config-alist key t))
14350 (pack-alist (aget vhdl-package-alist key t))
14351 arch-alist unit-alist subunit-alist)
14352 (add-to-list 'vhdl-speedbar-shown-project-list key)
14353 (while ent-alist
14354 (setq arch-alist (nth 4 (car ent-alist)))
14355 (setq subunit-alist nil)
14356 (while arch-alist
14357 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14358 (setq arch-alist (cdr arch-alist)))
14359 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14360 (setq ent-alist (cdr ent-alist)))
14361 (while conf-alist
14362 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14363 (setq conf-alist (cdr conf-alist)))
14364 (while pack-alist
14365 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14366 (setq pack-alist (cdr pack-alist)))
14367 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14368 (vhdl-speedbar-refresh)
14369 (when (memq 'display vhdl-speedbar-save-cache)
14370 (add-to-list 'vhdl-updated-project-list key))))
14371
14372(defun vhdl-speedbar-expand-project (text token indent)
14373 "Expand/contract the project under the cursor."
14374 (cond
14375 ((string-match "+" text) ; expand project
14376 (speedbar-change-expand-button-char ?-)
14377 (unless (member token vhdl-speedbar-shown-project-list)
14378 (setq vhdl-speedbar-shown-project-list
14379 (cons token vhdl-speedbar-shown-project-list)))
14380 (speedbar-with-writable
14381 (save-excursion
14382 (end-of-line) (forward-char 1)
14383 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14384 speedbar-power-click))))
14385 ((string-match "-" text) ; contract project
14386 (speedbar-change-expand-button-char ?+)
14387 (setq vhdl-speedbar-shown-project-list
14388 (delete token vhdl-speedbar-shown-project-list))
14389 (speedbar-delete-subblock indent))
14390 (t (error "Nothing to display")))
14391 (when (equal (selected-frame) speedbar-frame)
14392 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14393
14394(defun vhdl-speedbar-expand-entity (text token indent)
14395 "Expand/contract the entity under the cursor."
14396 (cond
14397 ((string-match "+" text) ; expand entity
3dcb36b7
JB
14398 (let* ((key (vhdl-speedbar-line-key indent))
14399 (ent-alist (aget vhdl-entity-alist key t))
14400 (ent-entry (aget ent-alist token t))
14401 (arch-alist (nth 3 ent-entry))
5eabfe72 14402 (inst-alist (vhdl-get-instantiations token indent))
0a2e512a
RF
14403 (subpack-alist (nth 5 ent-entry))
14404 (multiple-arch (> (length arch-alist) 1))
3dcb36b7
JB
14405 arch-entry inst-entry)
14406 (if (not (or arch-alist inst-alist subpack-alist))
5eabfe72
KH
14407 (speedbar-change-expand-button-char ??)
14408 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14409 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14410 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14411 (aput 'unit-alist token nil)
14412 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72 14413 (speedbar-with-writable
3dcb36b7
JB
14414 (save-excursion
14415 (end-of-line) (forward-char 1)
14416 ;; insert architectures
14417 (when arch-alist
14418 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14419 (while arch-alist
14420 (setq arch-entry (car arch-alist))
14421 (speedbar-make-tag-line
14422 'curly ?+ 'vhdl-speedbar-expand-architecture
14423 (cons token (nth 0 arch-entry))
14424 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14425 (cons (nth 2 arch-entry) (nth 3 arch-entry))
0a2e512a
RF
14426 'vhdl-speedbar-architecture-face (1+ indent))
14427 (when (and multiple-arch
14428 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14429 (end-of-line 0) (insert " (mra)") (forward-char 1))
3dcb36b7
JB
14430 (setq arch-alist (cdr arch-alist)))
14431 ;; insert instantiations
14432 (when inst-alist
14433 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14434 (while inst-alist
14435 (setq inst-entry (car inst-alist))
14436 (vhdl-speedbar-make-inst-line
14437 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14438 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14439 nil nil nil (1+ indent) 0 " in ")
14440 (setq inst-alist (cdr inst-alist)))
14441 ;; insert required packages
14442 (vhdl-speedbar-insert-subpackages
14443 subpack-alist (1+ indent) indent)))
14444 (when (memq 'display vhdl-speedbar-save-cache)
14445 (add-to-list 'vhdl-updated-project-list key))
14446 (vhdl-speedbar-update-current-unit t t))))
5eabfe72
KH
14447 ((string-match "-" text) ; contract entity
14448 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14449 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14450 (let* ((key (vhdl-speedbar-line-key indent))
14451 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14452 (adelete 'unit-alist token)
14453 (if unit-alist
14454 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14455 (adelete 'vhdl-speedbar-shown-unit-alist key))
14456 (speedbar-delete-subblock indent)
14457 (when (memq 'display vhdl-speedbar-save-cache)
14458 (add-to-list 'vhdl-updated-project-list key))))
14459 (t (error "Nothing to display")))
14460 (when (equal (selected-frame) speedbar-frame)
14461 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14462
14463(defun vhdl-speedbar-expand-architecture (text token indent)
14464 "Expand/contract the architecture under the cursor."
14465 (cond
14466 ((string-match "+" text) ; expand architecture
3dcb36b7
JB
14467 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14468 (ent-alist (aget vhdl-entity-alist key t))
14469 (conf-alist (aget vhdl-config-alist key t))
14470 (hier-alist (vhdl-get-hierarchy
14471 ent-alist conf-alist (car token) (cdr token) nil nil
14472 0 (1- indent)))
14473 (ent-entry (aget ent-alist (car token) t))
14474 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14475 (subpack-alist (nth 4 arch-entry))
14476 entry)
14477 (if (not (or hier-alist subpack-alist))
14478 (speedbar-change-expand-button-char ??)
14479 (speedbar-change-expand-button-char ?-)
14480 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14481 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14482 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14483 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14484 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14485 (speedbar-with-writable
14486 (save-excursion
14487 (end-of-line) (forward-char 1)
14488 ;; insert instance hierarchy
14489 (when hier-alist
14490 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14491 (1+ indent)))
14492 (while hier-alist
14493 (setq entry (car hier-alist))
14494 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14495 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14496 (vhdl-speedbar-make-inst-line
14497 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14498 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14499 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14500 (setq hier-alist (cdr hier-alist)))
14501 ;; insert required packages
14502 (vhdl-speedbar-insert-subpackages
14503 subpack-alist (1+ indent) (1- indent))))
14504 (when (memq 'display vhdl-speedbar-save-cache)
14505 (add-to-list 'vhdl-updated-project-list key))
14506 (vhdl-speedbar-update-current-unit t t))))
14507 ((string-match "-" text) ; contract architecture
14508 (speedbar-change-expand-button-char ?+)
14509 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14510 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14511 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14512 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14513 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14514 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14515 (speedbar-delete-subblock indent)
14516 (when (memq 'display vhdl-speedbar-save-cache)
14517 (add-to-list 'vhdl-updated-project-list key))))
14518 (t (error "Nothing to display")))
14519 (when (equal (selected-frame) speedbar-frame)
14520 (speedbar-center-buffer-smartly)))
14521
14522(defun vhdl-speedbar-expand-config (text token indent)
14523 "Expand/contract the configuration under the cursor."
14524 (cond
14525 ((string-match "+" text) ; expand configuration
14526 (let* ((key (vhdl-speedbar-line-key indent))
14527 (conf-alist (aget vhdl-config-alist key t))
14528 (conf-entry (aget conf-alist token))
14529 (ent-alist (aget vhdl-entity-alist key t))
14530 (hier-alist (vhdl-get-hierarchy
14531 ent-alist conf-alist (nth 3 conf-entry)
14532 (nth 4 conf-entry) token (nth 5 conf-entry)
14533 0 indent t))
14534 (subpack-alist (nth 6 conf-entry))
14535 entry)
14536 (if (not (or hier-alist subpack-alist))
5eabfe72
KH
14537 (speedbar-change-expand-button-char ??)
14538 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14539 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14540 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14541 (aput 'unit-alist token nil)
14542 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72
KH
14543 (speedbar-with-writable
14544 (save-excursion
14545 (end-of-line) (forward-char 1)
14546 ;; insert instance hierarchy
14547 (when hier-alist
3dcb36b7 14548 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
5eabfe72 14549 (while hier-alist
3dcb36b7
JB
14550 (setq entry (car hier-alist))
14551 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14552 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
5eabfe72 14553 (vhdl-speedbar-make-inst-line
3dcb36b7
JB
14554 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14555 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14556 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14557 (setq hier-alist (cdr hier-alist)))
14558 ;; insert required packages
14559 (vhdl-speedbar-insert-subpackages
14560 subpack-alist (1+ indent) indent)))
14561 (when (memq 'display vhdl-speedbar-save-cache)
14562 (add-to-list 'vhdl-updated-project-list key))
14563 (vhdl-speedbar-update-current-unit t t))))
14564 ((string-match "-" text) ; contract configuration
5eabfe72 14565 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14566 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14567 (let* ((key (vhdl-speedbar-line-key indent))
14568 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14569 (adelete 'unit-alist token)
14570 (if unit-alist
14571 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14572 (adelete 'vhdl-speedbar-shown-unit-alist key))
14573 (speedbar-delete-subblock indent)
14574 (when (memq 'display vhdl-speedbar-save-cache)
14575 (add-to-list 'vhdl-updated-project-list key))))
14576 (t (error "Nothing to display")))
14577 (when (equal (selected-frame) speedbar-frame)
14578 (speedbar-center-buffer-smartly)))
14579
14580(defun vhdl-speedbar-expand-package (text token indent)
14581 "Expand/contract the package under the cursor."
14582 (cond
14583 ((string-match "+" text) ; expand package
14584 (let* ((key (vhdl-speedbar-line-key indent))
14585 (pack-alist (aget vhdl-package-alist key t))
14586 (pack-entry (aget pack-alist token t))
14587 (comp-alist (nth 3 pack-entry))
14588 (func-alist (nth 4 pack-entry))
14589 (func-body-alist (nth 8 pack-entry))
14590 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14591 comp-entry func-entry func-body-entry)
14592 (if (not (or comp-alist func-alist subpack-alist))
14593 (speedbar-change-expand-button-char ??)
14594 (speedbar-change-expand-button-char ?-)
14595 ;; add package to `vhdl-speedbar-shown-unit-alist'
14596 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14597 (aput 'unit-alist token nil)
14598 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14599 (speedbar-with-writable
14600 (save-excursion
14601 (end-of-line) (forward-char 1)
14602 ;; insert components
14603 (when comp-alist
14604 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14605 (while comp-alist
14606 (setq comp-entry (car comp-alist))
14607 (speedbar-make-tag-line
14608 nil nil nil
14609 (cons token (nth 0 comp-entry))
14610 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14611 (cons (nth 2 comp-entry) (nth 3 comp-entry))
0a2e512a 14612 'vhdl-speedbar-entity-face (1+ indent))
3dcb36b7
JB
14613 (setq comp-alist (cdr comp-alist)))
14614 ;; insert subprograms
14615 (when func-alist
14616 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14617 (while func-alist
14618 (setq func-entry (car func-alist)
14619 func-body-entry (aget func-body-alist (car func-entry) t))
14620 (when (nth 2 func-entry)
14621 (vhdl-speedbar-make-subprogram-line
14622 (nth 1 func-entry)
14623 (cons (nth 2 func-entry) (nth 3 func-entry))
14624 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14625 (1+ indent)))
14626 (setq func-alist (cdr func-alist)))
14627 ;; insert required packages
14628 (vhdl-speedbar-insert-subpackages
14629 subpack-alist (1+ indent) indent)))
14630 (when (memq 'display vhdl-speedbar-save-cache)
14631 (add-to-list 'vhdl-updated-project-list key))
14632 (vhdl-speedbar-update-current-unit t t))))
14633 ((string-match "-" text) ; contract package
14634 (speedbar-change-expand-button-char ?+)
14635 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14636 (let* ((key (vhdl-speedbar-line-key indent))
14637 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14638 (adelete 'unit-alist token)
14639 (if unit-alist
14640 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14641 (adelete 'vhdl-speedbar-shown-unit-alist key))
14642 (speedbar-delete-subblock indent)
14643 (when (memq 'display vhdl-speedbar-save-cache)
14644 (add-to-list 'vhdl-updated-project-list key))))
14645 (t (error "Nothing to display")))
14646 (when (equal (selected-frame) speedbar-frame)
14647 (speedbar-center-buffer-smartly)))
14648
14649(defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14650 "Insert required packages."
14651 (let* ((pack-alist (aget vhdl-package-alist
14652 (vhdl-speedbar-line-key dir-indent) t))
14653 pack-key lib-name pack-entry)
14654 (when subpack-alist
14655 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14656 (while subpack-alist
14657 (setq pack-key (cdar subpack-alist)
14658 lib-name (caar subpack-alist))
14659 (setq pack-entry (aget pack-alist pack-key t))
14660 (vhdl-speedbar-make-subpack-line
14661 (or (nth 0 pack-entry) pack-key) lib-name
0a2e512a
RF
14662 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14663 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
3dcb36b7 14664 (setq subpack-alist (cdr subpack-alist)))))
5eabfe72
KH
14665
14666;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14667;; Display help functions
14668
3dcb36b7
JB
14669(defvar vhdl-speedbar-update-current-unit t
14670 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14671
14672(defun vhdl-speedbar-update-current-project ()
14673 "Highlight project that is currently active."
14674 (when (and vhdl-speedbar-show-projects
14675 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14676 (and (boundp 'speedbar-frame)
14677 (frame-live-p speedbar-frame)))
14678 (let ((last-frame (selected-frame))
14679 (project-alist vhdl-project-alist)
14680 pos)
14681 (select-frame speedbar-frame)
14682 (speedbar-with-writable
14683 (save-excursion
14684 (while project-alist
14685 (goto-char (point-min))
14686 (when (re-search-forward
14687 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14688 (put-text-property (match-beginning 1) (match-end 1) 'face
14689 (if (equal (caar project-alist) vhdl-project)
14690 'speedbar-selected-face
14691 'speedbar-directory-face))
14692 (when (equal (caar project-alist) vhdl-project)
14693 (setq pos (1- (match-beginning 1)))))
14694 (setq project-alist (cdr project-alist))))
14695 (when pos (goto-char pos)))
14696 (select-frame last-frame)
14697 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14698 t)
14699
14700(defun vhdl-speedbar-update-current-unit (&optional no-position always)
5eabfe72
KH
14701 "Highlight all design units that are contained in the current file.
14702NO-POSITION non-nil means do not re-position cursor."
14703 (let ((last-frame (selected-frame))
3dcb36b7
JB
14704 (project-list vhdl-speedbar-shown-project-list)
14705 file-alist pos file-name)
5eabfe72 14706 ;; get current file name
3dcb36b7
JB
14707 (if (fboundp 'speedbar-select-attached-frame)
14708 (speedbar-select-attached-frame)
14709 (select-frame speedbar-attached-frame))
5eabfe72 14710 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
3dcb36b7
JB
14711 (when (and vhdl-speedbar-update-current-unit
14712 (or always (not (equal file-name speedbar-last-selected-file))))
14713 (if vhdl-speedbar-show-projects
14714 (while project-list
14715 (setq file-alist (append file-alist (aget vhdl-file-alist
14716 (car project-list) t)))
14717 (setq project-list (cdr project-list)))
14718 (setq file-alist (aget vhdl-file-alist
14719 (abbreviate-file-name default-directory) t)))
5eabfe72
KH
14720 (select-frame speedbar-frame)
14721 (set-buffer speedbar-buffer)
14722 (speedbar-with-writable
3dcb36b7 14723 (vhdl-prepare-search-1
5eabfe72
KH
14724 (save-excursion
14725 ;; unhighlight last units
3dcb36b7 14726 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
5eabfe72 14727 (vhdl-speedbar-update-units
3dcb36b7 14728 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14729 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
5eabfe72 14730 (vhdl-speedbar-update-units
3dcb36b7 14731 "{.} " (nth 1 file-entry)
0a2e512a 14732 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
5eabfe72 14733 (vhdl-speedbar-update-units
3dcb36b7 14734 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14735 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
5eabfe72 14736 (vhdl-speedbar-update-units
3dcb36b7 14737 "[]>] " (nth 4 file-entry)
0a2e512a 14738 speedbar-last-selected-file 'vhdl-speedbar-package-face)
5eabfe72 14739 (vhdl-speedbar-update-units
3dcb36b7 14740 "\\[.\\].+(" '("body")
0a2e512a 14741 speedbar-last-selected-file 'vhdl-speedbar-package-face)
3dcb36b7
JB
14742 (vhdl-speedbar-update-units
14743 "> " (nth 6 file-entry)
0a2e512a 14744 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
5eabfe72 14745 ;; highlight current units
3dcb36b7
JB
14746 (let* ((file-entry (aget file-alist file-name t)))
14747 (setq
14748 pos (vhdl-speedbar-update-units
14749 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14750 file-name 'vhdl-speedbar-entity-selected-face pos)
3dcb36b7
JB
14751 pos (vhdl-speedbar-update-units
14752 "{.} " (nth 1 file-entry)
0a2e512a 14753 file-name 'vhdl-speedbar-architecture-selected-face pos)
3dcb36b7
JB
14754 pos (vhdl-speedbar-update-units
14755 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14756 file-name 'vhdl-speedbar-configuration-selected-face pos)
3dcb36b7
JB
14757 pos (vhdl-speedbar-update-units
14758 "[]>] " (nth 4 file-entry)
0a2e512a 14759 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14760 pos (vhdl-speedbar-update-units
14761 "\\[.\\].+(" '("body")
0a2e512a 14762 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14763 pos (vhdl-speedbar-update-units
14764 "> " (nth 6 file-entry)
0a2e512a 14765 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
5eabfe72 14766 ;; move speedbar so the first highlighted unit is visible
3dcb36b7
JB
14767 (when (and pos (not no-position))
14768 (goto-char pos)
14769 (speedbar-center-buffer-smartly)
5eabfe72
KH
14770 (speedbar-position-cursor-on-line))
14771 (setq speedbar-last-selected-file file-name))
14772 (select-frame last-frame)
14773 t))
14774
3dcb36b7
JB
14775(defun vhdl-speedbar-update-units (text unit-list file-name face
14776 &optional pos)
5eabfe72 14777 "Help function to highlight design units."
3dcb36b7
JB
14778 (while unit-list
14779 (goto-char (point-min))
14780 (while (re-search-forward
14781 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14782 (when (equal file-name (car (get-text-property
14783 (match-beginning 1) 'speedbar-token)))
14784 (setq pos (or pos (point-marker)))
14785 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14786 (setq unit-list (cdr unit-list)))
14787 pos)
5eabfe72
KH
14788
14789(defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
3dcb36b7
JB
14790 ent-name ent-file-marker
14791 arch-name arch-file-marker
14792 conf-name conf-file-marker
14793 lib-name depth offset delimiter)
5eabfe72 14794 "Insert instantiation entry."
3dcb36b7
JB
14795 (let ((start (point))
14796 visible-start)
5eabfe72
KH
14797 (insert (int-to-string depth) ":")
14798 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14799 (setq visible-start (point))
14800 (insert-char ? (* depth speedbar-indentation-width))
14801 (while (> offset 0)
14802 (insert "|")
14803 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14804 (setq offset (1- offset)))
14805 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14806 (setq start (point))
3dcb36b7
JB
14807 (insert ">")
14808 (speedbar-make-button start (point) nil nil nil)
14809 (setq visible-start (point))
14810 (insert " ")
5eabfe72 14811 (setq start (point))
3dcb36b7
JB
14812 (if (not inst-name)
14813 (insert "(top)")
14814 (insert inst-name)
14815 (speedbar-make-button
0a2e512a 14816 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
3dcb36b7
JB
14817 'vhdl-speedbar-find-file inst-file-marker))
14818 (insert delimiter)
14819 (when ent-name
5eabfe72 14820 (setq start (point))
3dcb36b7 14821 (insert ent-name)
5eabfe72 14822 (speedbar-make-button
0a2e512a 14823 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
3dcb36b7
JB
14824 'vhdl-speedbar-find-file ent-file-marker)
14825 (when arch-name
14826 (insert " (")
14827 (setq start (point))
14828 (insert arch-name)
14829 (speedbar-make-button
0a2e512a 14830 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
3dcb36b7
JB
14831 'vhdl-speedbar-find-file arch-file-marker)
14832 (insert ")"))
14833 (when conf-name
14834 (insert " (")
14835 (setq start (point))
14836 (insert conf-name)
14837 (speedbar-make-button
0a2e512a 14838 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
3dcb36b7
JB
14839 'vhdl-speedbar-find-file conf-file-marker)
14840 (insert ")")))
14841 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
5eabfe72 14842 (setq start (point))
3dcb36b7
JB
14843 (insert " (" lib-name ")")
14844 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14845 'vhdl-speedbar-library-face))
5eabfe72 14846 (insert-char ?\n 1)
3dcb36b7 14847 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14848
3dcb36b7
JB
14849(defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14850 body-file-marker depth)
5eabfe72 14851 "Insert package entry."
3dcb36b7
JB
14852 (let ((start (point))
14853 visible-start)
5eabfe72
KH
14854 (insert (int-to-string depth) ":")
14855 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14856 (setq visible-start (point))
14857 (insert-char ? (* depth speedbar-indentation-width))
14858 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14859 (setq start (point))
3dcb36b7
JB
14860 (insert "[+]")
14861 (speedbar-make-button
14862 start (point) 'speedbar-button-face 'speedbar-highlight-face
14863 'vhdl-speedbar-expand-package pack-key)
14864 (setq visible-start (point))
14865 (insert-char ? 1 nil)
5eabfe72
KH
14866 (setq start (point))
14867 (insert pack-name)
14868 (speedbar-make-button
0a2e512a 14869 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14870 'vhdl-speedbar-find-file pack-file-marker)
3dcb36b7
JB
14871 (unless (car pack-file-marker)
14872 (insert "!"))
5eabfe72 14873 (when (car body-file-marker)
5eabfe72 14874 (insert " (")
5eabfe72
KH
14875 (setq start (point))
14876 (insert "body")
14877 (speedbar-make-button
0a2e512a 14878 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14879 'vhdl-speedbar-find-file body-file-marker)
3dcb36b7 14880 (insert ")"))
5eabfe72 14881 (insert-char ?\n 1)
3dcb36b7 14882 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14883
3dcb36b7 14884(defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
0a2e512a 14885 pack-body-file-marker depth)
3dcb36b7
JB
14886 "Insert used package entry."
14887 (let ((start (point))
14888 visible-start)
14889 (insert (int-to-string depth) ":")
14890 (put-text-property start (point) 'invisible t)
14891 (setq visible-start (point))
14892 (insert-char ? (* depth speedbar-indentation-width))
14893 (put-text-property visible-start (point) 'invisible nil)
14894 (setq start (point))
14895 (insert ">")
14896 (speedbar-make-button start (point) nil nil nil)
14897 (setq visible-start (point))
14898 (insert " ")
14899 (setq start (point))
14900 (insert pack-name)
14901 (speedbar-make-button
0a2e512a 14902 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
3dcb36b7 14903 'vhdl-speedbar-find-file pack-file-marker)
0a2e512a
RF
14904 (when (car pack-body-file-marker)
14905 (insert " (")
14906 (setq start (point))
14907 (insert "body")
14908 (speedbar-make-button
14909 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14910 'vhdl-speedbar-find-file pack-body-file-marker)
14911 (insert ")"))
3dcb36b7
JB
14912 (setq start (point))
14913 (insert " (" lib-name ")")
14914 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14915 'vhdl-speedbar-library-face)
3dcb36b7
JB
14916 (insert-char ?\n 1)
14917 (put-text-property visible-start (point) 'invisible nil)))
14918
14919(defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14920 func-body-file-marker
14921 depth)
14922 "Insert subprogram entry."
14923 (let ((start (point))
14924 visible-start)
5eabfe72
KH
14925 (insert (int-to-string depth) ":")
14926 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14927 (setq visible-start (point))
14928 (insert-char ? (* depth speedbar-indentation-width))
14929 (put-text-property visible-start (point) 'invisible nil)
14930 (setq start (point))
14931 (insert ">")
14932 (speedbar-make-button start (point) nil nil nil)
14933 (setq visible-start (point))
14934 (insert " ")
5eabfe72 14935 (setq start (point))
3dcb36b7
JB
14936 (insert func-name)
14937 (speedbar-make-button
0a2e512a 14938 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14939 'vhdl-speedbar-find-file func-file-marker)
14940 (when (car func-body-file-marker)
14941 (insert " (")
14942 (setq start (point))
14943 (insert "body")
14944 (speedbar-make-button
0a2e512a 14945 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14946 'vhdl-speedbar-find-file func-body-file-marker)
14947 (insert ")"))
14948 (insert-char ?\n 1)
14949 (put-text-property visible-start (point) 'invisible nil)))
14950
14951(defun vhdl-speedbar-make-title-line (text &optional depth)
14952 "Insert design unit title entry."
14953 (let ((start (point))
14954 visible-start)
14955 (when depth
14956 (insert (int-to-string depth) ":")
14957 (put-text-property start (point) 'invisible t))
14958 (setq visible-start (point))
14959 (insert-char ? (* (or depth 0) speedbar-indentation-width))
5eabfe72
KH
14960 (setq start (point))
14961 (insert text)
14962 (speedbar-make-button start (point) nil nil nil nil)
14963 (insert-char ?\n 1)
3dcb36b7 14964 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72
KH
14965
14966(defun vhdl-speedbar-insert-dirs (files level)
14967 "Insert subdirectories."
14968 (let ((dirs (car files)))
14969 (while dirs
14970 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14971 (car dirs) 'speedbar-dir-follow nil
14972 'speedbar-directory-face level)
14973 (setq dirs (cdr dirs)))))
14974
14975(defun vhdl-speedbar-dired (text token indent)
14976 "Speedbar click handler for directory expand button in hierarchy mode."
14977 (cond ((string-match "+" text) ; we have to expand this dir
14978 (setq speedbar-shown-directories
14979 (cons (expand-file-name
14980 (concat (speedbar-line-path indent) token "/"))
14981 speedbar-shown-directories))
14982 (speedbar-change-expand-button-char ?-)
14983 (speedbar-reset-scanners)
14984 (speedbar-with-writable
14985 (save-excursion
14986 (end-of-line) (forward-char 1)
14987 (vhdl-speedbar-insert-dirs
14988 (speedbar-file-lists
14989 (concat (speedbar-line-path indent) token "/"))
14990 (1+ indent))
14991 (speedbar-reset-scanners)
14992 (vhdl-speedbar-insert-dir-hierarchy
14993 (abbreviate-file-name
14994 (concat (speedbar-line-path indent) token "/"))
14995 (1+ indent) speedbar-power-click)))
3dcb36b7 14996 (vhdl-speedbar-update-current-unit t t))
5eabfe72
KH
14997 ((string-match "-" text) ; we have to contract this node
14998 (speedbar-reset-scanners)
14999 (let ((oldl speedbar-shown-directories)
15000 (newl nil)
15001 (td (expand-file-name
15002 (concat (speedbar-line-path indent) token))))
15003 (while oldl
15004 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15005 (setq newl (cons (car oldl) newl)))
15006 (setq oldl (cdr oldl)))
15007 (setq speedbar-shown-directories (nreverse newl)))
15008 (speedbar-change-expand-button-char ?+)
15009 (speedbar-delete-subblock indent))
3dcb36b7
JB
15010 (t (error "Nothing to display")))
15011 (when (equal (selected-frame) speedbar-frame)
15012 (speedbar-center-buffer-smartly)))
5eabfe72
KH
15013
15014(defun vhdl-speedbar-item-info ()
15015 "Derive and display information about this line item."
15016 (save-excursion
15017 (beginning-of-line)
15018 ;; skip invisible number info
3dcb36b7 15019 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
5eabfe72 15020 (cond
3dcb36b7
JB
15021 ;; project/directory entry
15022 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15023 (if vhdl-speedbar-show-projects
15024 (message "Project \"%s\"" (match-string-no-properties 1))
15025 (speedbar-files-item-info)))
5eabfe72 15026 ;; design unit entry
3dcb36b7
JB
15027 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15028 (goto-char (match-end 1))
5eabfe72
KH
15029 (let ((face (get-text-property (point) 'face)))
15030 (message
15031 "%s \"%s\" in \"%s\""
15032 ;; design unit kind
0a2e512a
RF
15033 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15034 (eq face 'vhdl-speedbar-entity-selected-face))
3dcb36b7 15035 (if (equal (match-string 2) ">") "Component" "Entity"))
0a2e512a
RF
15036 ((or (eq face 'vhdl-speedbar-architecture-face)
15037 (eq face 'vhdl-speedbar-architecture-selected-face))
5eabfe72 15038 "Architecture")
0a2e512a
RF
15039 ((or (eq face 'vhdl-speedbar-configuration-face)
15040 (eq face 'vhdl-speedbar-configuration-selected-face))
5eabfe72 15041 "Configuration")
0a2e512a
RF
15042 ((or (eq face 'vhdl-speedbar-package-face)
15043 (eq face 'vhdl-speedbar-package-selected-face))
5eabfe72 15044 "Package")
0a2e512a
RF
15045 ((or (eq face 'vhdl-speedbar-instantiation-face)
15046 (eq face 'vhdl-speedbar-instantiation-selected-face))
5eabfe72 15047 "Instantiation")
0a2e512a 15048 ((eq face 'vhdl-speedbar-subprogram-face)
3dcb36b7 15049 "Subprogram")
5eabfe72
KH
15050 (t ""))
15051 ;; design unit name
15052 (buffer-substring-no-properties
3dcb36b7
JB
15053 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15054 (match-end 1))
5eabfe72 15055 ;; file name
3dcb36b7
JB
15056 (file-relative-name
15057 (or (car (get-text-property (point) 'speedbar-token))
15058 "?")
15059 (vhdl-default-directory)))))
15060 (t (message "")))))
15061
15062(defun vhdl-speedbar-line-text ()
15063 "Calls `speedbar-line-text' and removes text properties."
15064 (let ((string (speedbar-line-text)))
15065 (set-text-properties 0 (length string) nil string)
15066 string))
5eabfe72 15067
0a2e512a
RF
15068(defun vhdl-speedbar-higher-text ()
15069 "Get speedbar-line-text of higher level."
15070 (let (depth string)
15071 (save-excursion
15072 (beginning-of-line)
15073 (looking-at "^\\([0-9]+\\):")
15074 (setq depth (string-to-number (match-string 1)))
15075 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15076 (setq string (match-string 1))
15077 (set-text-properties 0 (length string) nil string)
15078 string))))
15079
5eabfe72
KH
15080;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15081;; Help functions
d2ddb974 15082
3dcb36b7
JB
15083(defun vhdl-speedbar-line-key (&optional indent)
15084 "Get currently displayed directory of project name."
15085 (if vhdl-speedbar-show-projects
15086 (vhdl-speedbar-line-project)
15087 (abbreviate-file-name
15088 (file-name-as-directory (speedbar-line-path indent)))))
15089
15090(defun vhdl-speedbar-line-project (&optional indent)
15091 "Get currently displayed project name."
15092 (and vhdl-speedbar-show-projects
15093 (save-excursion
15094 (end-of-line)
15095 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15096 (match-string-no-properties 1))))
15097
15098(defun vhdl-add-modified-file ()
15099 "Add file to `vhdl-modified-file-list'."
15100 (when vhdl-file-alist
15101 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15102 nil)
5eabfe72
KH
15103
15104(defun vhdl-resolve-paths (path-list)
3dcb36b7
JB
15105 "Resolve path wildcards in PATH-LIST."
15106 (let (path-list-1 path-list-2 path-beg path-end dir)
15107 ;; eliminate non-existent directories
5eabfe72
KH
15108 (while path-list
15109 (setq dir (car path-list))
3dcb36b7
JB
15110 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15111 (if (file-directory-p (match-string 2 dir))
15112 (setq path-list-1 (cons dir path-list-1))
15113 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
5eabfe72 15114 (setq path-list (cdr path-list)))
3dcb36b7 15115 ;; resolve path wildcards
5eabfe72
KH
15116 (while path-list-1
15117 (setq dir (car path-list-1))
3dcb36b7 15118 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
5eabfe72
KH
15119 (progn
15120 (setq path-beg (match-string 1 dir)
15121 path-end (match-string 5 dir))
3dcb36b7 15122 (setq path-list-1
5eabfe72
KH
15123 (append
15124 (mapcar
15125 (function
15126 (lambda (var) (concat path-beg var path-end)))
15127 (let ((all-list (vhdl-directory-files
15128 (match-string 2 dir) t
15129 (concat "\\<" (wildcard-to-regexp
15130 (match-string 4 dir)))))
15131 dir-list)
15132 (while all-list
15133 (when (file-directory-p (car all-list))
15134 (setq dir-list (cons (car all-list) dir-list)))
15135 (setq all-list (cdr all-list)))
15136 dir-list))
3dcb36b7
JB
15137 (cdr path-list-1))))
15138 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
5eabfe72 15139 (when (file-directory-p (match-string 2 dir))
3dcb36b7
JB
15140 (setq path-list-2 (cons dir path-list-2)))
15141 (setq path-list-1 (cdr path-list-1))))
15142 (nreverse path-list-2)))
5eabfe72
KH
15143
15144(defun vhdl-speedbar-goto-this-unit (directory unit)
15145 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15146 (let ((dest (point)))
3dcb36b7 15147 (if (and (if vhdl-speedbar-show-projects
5eabfe72
KH
15148 (progn (goto-char (point-min)) t)
15149 (speedbar-goto-this-file directory))
15150 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15151 (progn (speedbar-position-cursor-on-line)
15152 t)
15153 (goto-char dest)
15154 nil)))
15155
15156(defun vhdl-speedbar-find-file (text token indent)
3dcb36b7
JB
15157 "When user clicks on TEXT, load file with name and position in TOKEN.
15158Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15159is already shown in a buffer."
5eabfe72 15160 (if (not (car token))
3dcb36b7
JB
15161 (error "ERROR: File cannot be found")
15162 (let ((buffer (get-file-buffer (car token))))
15163 (speedbar-find-file-in-frame (car token))
15164 (when (or vhdl-speedbar-jump-to-unit buffer)
15165 (goto-line (cdr token))
15166 (recenter))
15167 (vhdl-speedbar-update-current-unit t t)
15168 (speedbar-set-timer speedbar-update-speed)
15169 (speedbar-maybee-jump-to-attached-frame))))
5eabfe72
KH
15170
15171(defun vhdl-speedbar-port-copy ()
3dcb36b7 15172 "Copy the port of the entity/component or subprogram under the cursor."
5eabfe72 15173 (interactive)
3dcb36b7
JB
15174 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15175 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15176 (error "ERROR: No entity/component or subprogram under cursor")
15177 (beginning-of-line)
15178 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15179 (condition-case info
15180 (let ((token (get-text-property
15181 (match-beginning 3) 'speedbar-token)))
15182 (vhdl-visit-file (car token) t
15183 (progn (goto-line (cdr token))
15184 (end-of-line)
15185 (if is-entity
15186 (vhdl-port-copy)
15187 (vhdl-subprog-copy)))))
15188 (error (error "ERROR: %s not scanned successfully\n (%s)"
15189 (if is-entity "Port" "Interface") (cadr info))))
15190 (error "ERROR: No entity/component or subprogram on current line")))))
15191
15192(defun vhdl-speedbar-place-component ()
15193 "Place the entity/component under the cursor as component."
15194 (interactive)
15195 (if (not (vhdl-speedbar-check-unit 'entity))
5bb5087f 15196 (error "ERROR: No entity/component under cursor")
3dcb36b7
JB
15197 (vhdl-speedbar-port-copy)
15198 (if (fboundp 'speedbar-select-attached-frame)
15199 (speedbar-select-attached-frame)
15200 (select-frame speedbar-attached-frame))
15201 (vhdl-compose-place-component)
15202 (select-frame speedbar-frame)))
15203
0a2e512a
RF
15204(defun vhdl-speedbar-configuration ()
15205 "Generate configuration for the architecture under the cursor."
15206 (interactive)
15207 (if (not (vhdl-speedbar-check-unit 'architecture))
15208 (error "ERROR: No architecture under cursor")
15209 (let ((arch-name (vhdl-speedbar-line-text))
15210 (ent-name (vhdl-speedbar-higher-text)))
15211 (if (fboundp 'speedbar-select-attached-frame)
15212 (speedbar-select-attached-frame)
15213 (select-frame speedbar-attached-frame))
15214 (vhdl-compose-configuration ent-name arch-name))))
15215
15216(defun vhdl-speedbar-select-mra ()
15217 "Select the architecture under the cursor as MRA."
15218 (interactive)
15219 (if (not (vhdl-speedbar-check-unit 'architecture))
15220 (error "ERROR: No architecture under cursor")
15221 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15222 (ent-key (downcase (vhdl-speedbar-higher-text)))
15223 (ent-alist (aget vhdl-entity-alist
15224 (or (vhdl-project-p) default-directory) t))
15225 (ent-entry (aget ent-alist ent-key t)))
15226 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15227 (speedbar-refresh))))
15228
3dcb36b7
JB
15229(defun vhdl-speedbar-make-design ()
15230 "Make (compile) design unit or directory/project under the cursor."
15231 (interactive)
15232 (if (not (save-excursion (beginning-of-line)
15233 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15234 (error "ERROR: No primary design unit or directory/project under cursor")
15235 (let ((is-unit (match-string 2))
15236 (unit-name (vhdl-speedbar-line-text))
15237 (vhdl-project (vhdl-speedbar-line-project))
15238 (directory (file-name-as-directory
15239 (or (speedbar-line-file) (speedbar-line-path)))))
15240 (if (fboundp 'speedbar-select-attached-frame)
15241 (speedbar-select-attached-frame)
15242 (select-frame speedbar-attached-frame))
15243 (let ((default-directory directory))
15244 (vhdl-make (and is-unit unit-name))))))
15245
15246(defun vhdl-speedbar-generate-makefile ()
15247 "Generate Makefile for directory/project under the cursor."
15248 (interactive)
15249 (let ((vhdl-project (vhdl-speedbar-line-project))
15250 (default-directory (file-name-as-directory
15251 (or (speedbar-line-file) (speedbar-line-path)))))
15252 (vhdl-generate-makefile)))
15253
15254(defun vhdl-speedbar-check-unit (design-unit)
15255 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15256expansion function)."
15257 (save-excursion
15258 (speedbar-position-cursor-on-line)
15259 (cond ((eq design-unit 'entity)
15260 (memq (get-text-property (match-end 0) 'face)
0a2e512a
RF
15261 '(vhdl-speedbar-entity-face
15262 vhdl-speedbar-entity-selected-face)))
15263 ((eq design-unit 'architecture)
15264 (memq (get-text-property (match-end 0) 'face)
15265 '(vhdl-speedbar-architecture-face
15266 vhdl-speedbar-architecture-selected-face)))
3dcb36b7
JB
15267 ((eq design-unit 'subprogram)
15268 (eq (get-text-property (match-end 0) 'face)
0a2e512a 15269 'vhdl-speedbar-subprogram-face))
3dcb36b7
JB
15270 (t nil))))
15271
15272(defun vhdl-speedbar-set-depth (depth)
15273 "Set hierarchy display depth to DEPTH and refresh speedbar."
15274 (setq vhdl-speedbar-hierarchy-depth depth)
15275 (speedbar-refresh))
5eabfe72
KH
15276
15277;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15278;; Fontification
15279
0a2e512a 15280(defface vhdl-speedbar-entity-face
5eabfe72
KH
15281 '((((class color) (background light)) (:foreground "ForestGreen"))
15282 (((class color) (background dark)) (:foreground "PaleGreen")))
15283 "Face used for displaying entity names."
15284 :group 'speedbar-faces)
15285
0a2e512a 15286(defface vhdl-speedbar-architecture-face
f47877ee
DN
15287 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15288 (((class color) (background light)) (:foreground "Blue"))
84c98ace 15289
5eabfe72
KH
15290 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15291 "Face used for displaying architecture names."
15292 :group 'speedbar-faces)
d2ddb974 15293
0a2e512a 15294(defface vhdl-speedbar-configuration-face
5eabfe72
KH
15295 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15296 (((class color) (background dark)) (:foreground "Salmon")))
15297 "Face used for displaying configuration names."
15298 :group 'speedbar-faces)
15299
0a2e512a 15300(defface vhdl-speedbar-package-face
5eabfe72
KH
15301 '((((class color) (background light)) (:foreground "Grey50"))
15302 (((class color) (background dark)) (:foreground "Grey80")))
15303 "Face used for displaying package names."
15304 :group 'speedbar-faces)
15305
0a2e512a 15306(defface vhdl-speedbar-library-face
3dcb36b7
JB
15307 '((((class color) (background light)) (:foreground "Purple"))
15308 (((class color) (background dark)) (:foreground "Orchid1")))
15309 "Face used for displaying library names."
15310 :group 'speedbar-faces)
15311
0a2e512a 15312(defface vhdl-speedbar-instantiation-face
5eabfe72 15313 '((((class color) (background light)) (:foreground "Brown"))
ea81d57e 15314 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
5eabfe72
KH
15315 (((class color) (background dark)) (:foreground "Yellow")))
15316 "Face used for displaying instantiation names."
15317 :group 'speedbar-faces)
15318
0a2e512a 15319(defface vhdl-speedbar-subprogram-face
3dcb36b7
JB
15320 '((((class color) (background light)) (:foreground "Orchid4"))
15321 (((class color) (background dark)) (:foreground "BurlyWood2")))
15322 "Face used for displaying subprogram names."
15323 :group 'speedbar-faces)
15324
0a2e512a 15325(defface vhdl-speedbar-entity-selected-face
5eabfe72
KH
15326 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15327 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15328 "Face used for displaying entity names."
15329 :group 'speedbar-faces)
15330
0a2e512a 15331(defface vhdl-speedbar-architecture-selected-face
f47877ee
DN
15332 '((((min-colors 88) (class color) (background light)) (:foreground
15333 "Blue1" :underline t))
15334 (((class color) (background light)) (:foreground "Blue" :underline t))
5eabfe72
KH
15335 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15336 "Face used for displaying architecture names."
15337 :group 'speedbar-faces)
15338
0a2e512a 15339(defface vhdl-speedbar-configuration-selected-face
5eabfe72
KH
15340 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15341 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15342 "Face used for displaying configuration names."
15343 :group 'speedbar-faces)
15344
0a2e512a 15345(defface vhdl-speedbar-package-selected-face
5eabfe72
KH
15346 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15347 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15348 "Face used for displaying package names."
15349 :group 'speedbar-faces)
15350
0a2e512a 15351(defface vhdl-speedbar-instantiation-selected-face
5eabfe72
KH
15352 '((((class color) (background light)) (:foreground "Brown" :underline t))
15353 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15354 "Face used for displaying instantiation names."
15355 :group 'speedbar-faces)
15356
3dcb36b7
JB
15357;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15358;; Initialization
15359
15360;; add speedbar
15361(when (fboundp 'speedbar)
15362 (condition-case ()
15363 (when (and vhdl-speedbar-auto-open
15364 (not (and (boundp 'speedbar-frame)
15365 (frame-live-p speedbar-frame))))
15366 (speedbar-frame-mode 1)
15367 (if (fboundp 'speedbar-select-attached-frame)
15368 (speedbar-select-attached-frame)
15369 (select-frame speedbar-attached-frame)))
15370 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15371
15372;; initialize speedbar
15373(if (not (boundp 'speedbar-frame))
15374 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15375 (vhdl-speedbar-initialize)
15376 (when speedbar-frame (vhdl-speedbar-refresh)))
15377
15378
15379;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15380;;; Structural composition
15381;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15382
15383(defun vhdl-get-components-package-name ()
15384 "Return the name of the components package."
15385 (let ((project (vhdl-project-p)))
15386 (if project
15387 (vhdl-replace-string (car vhdl-components-package-name)
15388 (subst-char-in-string ? ?_ project))
15389 (cdr vhdl-components-package-name))))
15390
15391(defun vhdl-compose-new-component ()
15392 "Create entity and architecture for new component."
15393 (interactive)
15394 (let* ((case-fold-search t)
15395 (ent-name (read-from-minibuffer "entity name: "
15396 nil vhdl-minibuffer-local-map))
15397 (arch-name
15398 (if (equal (cdr vhdl-compose-architecture-name) "")
15399 (read-from-minibuffer "architecture name: "
15400 nil vhdl-minibuffer-local-map)
15401 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15402 ent-file-name arch-file-name ent-buffer arch-buffer project)
15403 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15404 ;; open entity file
15405 (unless (eq vhdl-compose-create-files 'none)
15406 (setq ent-file-name
0a2e512a 15407 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15408 "." (file-name-extension (buffer-file-name))))
15409 (when (and (file-exists-p ent-file-name)
15410 (not (y-or-n-p (concat "File \"" ent-file-name
15411 "\" exists; overwrite? "))))
15412 (error "ERROR: Creating component...aborted"))
15413 (find-file ent-file-name)
15414 (erase-buffer)
15415 (set-buffer-modified-p nil))
15416 ;; insert header
15417 (if vhdl-compose-include-header
15418 (progn (vhdl-template-header)
15419 (goto-char (point-max)))
15420 (vhdl-comment-display-line) (insert "\n\n"))
15421 ;; insert library clause
15422 (vhdl-template-package-std-logic-1164)
15423 (when vhdl-use-components-package
15424 (insert "\n")
15425 (vhdl-template-standard-package (vhdl-work-library)
15426 (vhdl-get-components-package-name)))
15427 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15428 ;; insert entity declaration
15429 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15430 (vhdl-insert-keyword " IS\n")
15431 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15432 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15433 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15434 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15435 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15436 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15437 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15438 (vhdl-insert-keyword "END ")
15439 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15440 (insert ent-name ";\n\n")
15441 (vhdl-comment-display-line) (insert "\n")
15442 ;; open architecture file
15443 (if (not (eq vhdl-compose-create-files 'separate))
15444 (insert "\n")
15445 (setq ent-buffer (current-buffer))
15446 (setq arch-file-name
15447 (concat (vhdl-replace-string vhdl-architecture-file-name
0a2e512a 15448 (concat ent-name " " arch-name) t)
3dcb36b7
JB
15449 "." (file-name-extension (buffer-file-name))))
15450 (when (and (file-exists-p arch-file-name)
15451 (not (y-or-n-p (concat "File \"" arch-file-name
15452 "\" exists; overwrite? "))))
15453 (error "ERROR: Creating component...aborted"))
15454 (find-file arch-file-name)
15455 (erase-buffer)
15456 (set-buffer-modified-p nil)
15457 ;; insert header
15458 (if vhdl-compose-include-header
15459 (progn (vhdl-template-header)
15460 (goto-char (point-max)))
15461 (vhdl-comment-display-line) (insert "\n\n")))
15462 ;; insert architecture body
15463 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15464 (vhdl-insert-keyword " OF ") (insert ent-name)
15465 (vhdl-insert-keyword " IS\n\n")
15466 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15467 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15468 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15469 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15470 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15471 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15472 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15473 (vhdl-insert-keyword "BEGIN")
15474 (when vhdl-self-insert-comments
15475 (insert " -- ")
15476 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15477 (insert arch-name))
15478 (insert "\n\n")
15479 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15480 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15481 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15482 (vhdl-insert-keyword "END ")
15483 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15484 (insert arch-name ";\n\n")
0a2e512a 15485 ;; insert footer and save
3dcb36b7
JB
15486 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15487 (vhdl-template-footer)
15488 (vhdl-comment-display-line) (insert "\n"))
15489 (goto-char (point-min))
15490 (setq arch-buffer (current-buffer))
15491 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15492 (set-buffer arch-buffer) (save-buffer)
29a4e67d 15493 (message "%s"
3dcb36b7
JB
15494 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15495 (and ent-file-name
15496 (format "\n File created: \"%s\"" ent-file-name))
15497 (and arch-file-name
15498 (format "\n File created: \"%s\"" arch-file-name))))))
15499
15500(defun vhdl-compose-place-component ()
15501 "Place new component by pasting current port as component declaration and
15502component instantiation."
15503 (interactive)
15504 (if (not vhdl-port-list)
15505 (error "ERROR: No port has been read")
15506 (save-excursion
15507 (vhdl-prepare-search-2
15508 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15509 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15510 (error "ERROR: No architecture found"))
15511 (let* ((ent-name (match-string 1))
15512 (ent-file-name
0a2e512a 15513 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15514 "." (file-name-extension (buffer-file-name))))
15515 (orig-buffer (current-buffer)))
15516 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15517 ;; place component declaration
15518 (unless (or vhdl-use-components-package
15519 (vhdl-use-direct-instantiation)
15520 (save-excursion
15521 (re-search-forward
15522 (concat "^\\s-*component\\s-+"
15523 (car vhdl-port-list) "\\>") nil t)))
15524 (re-search-forward "^begin\\>" nil)
15525 (beginning-of-line)
15526 (skip-chars-backward " \t\n")
15527 (insert "\n\n") (indent-to vhdl-basic-offset)
15528 (vhdl-port-paste-component t))
15529 ;; place component instantiation
15530 (re-search-forward "^end\\>" nil)
15531 (beginning-of-line)
15532 (skip-chars-backward " \t\n")
15533 (insert "\n\n") (indent-to vhdl-basic-offset)
15534 (vhdl-port-paste-instance nil t t)
15535 ;; place use clause for used packages
15536 (when (nth 3 vhdl-port-list)
15537 ;; open entity file
15538 (when (file-exists-p ent-file-name)
15539 (find-file ent-file-name))
15540 (goto-char (point-min))
15541 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15542 (error "ERROR: Entity not found: \"%s\"" ent-name))
15543 (goto-char (match-beginning 0))
15544 (if (and (save-excursion
15545 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15546 (match-string 1))
15547 (progn (goto-char (match-end 0))
15548 (beginning-of-line 2))
15549 (insert "\n")
15550 (backward-char))
15551 (vhdl-port-paste-context-clause)
15552 (switch-to-buffer orig-buffer))
15553 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15554
15555(defun vhdl-compose-wire-components ()
15556 "Connect components."
15557 (interactive)
15558 (save-excursion
15559 (vhdl-prepare-search-2
15560 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15561 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15562 (error "ERROR: No architecture found"))
15563 (let* ((ent-name (match-string 1))
15564 (ent-file-name
0a2e512a 15565 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15566 "." (file-name-extension (buffer-file-name))))
15567 (arch-decl-pos (point-marker))
15568 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15569 (arch-end-pos (re-search-forward "^end\\>" nil))
15570 (pack-name (vhdl-get-components-package-name))
15571 (pack-file-name
0a2e512a 15572 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15573 "." (file-name-extension (buffer-file-name))))
15574 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15575 port-alist generic-alist inst-alist
15576 signal-name signal-entry signal-alist local-list written-list
15577 single-in-list multi-in-list single-out-list multi-out-list
15578 constant-name constant-entry constant-alist single-list multi-list
15579 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15580 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15581 signal-beg-pos signal-pos
15582 constant-temp-pos port-temp-pos signal-temp-pos)
15583 (message "Wiring components...")
15584 ;; process all instances
15585 (goto-char arch-stat-pos)
15586 (while (re-search-forward
15587 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15588 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15589 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15590 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15591 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15592 (setq inst-name (match-string-no-properties 1)
15593 comp-name (match-string-no-properties 4)
15594 comp-ent-name (match-string-no-properties 12)
15595 has-generic (or (match-string 7) (match-string 17)))
15596 ;; get port ...
15597 (if comp-name
15598 ;; ... from component declaration
15599 (vhdl-visit-file
15600 (when vhdl-use-components-package pack-file-name) t
15601 (save-excursion
15602 (goto-char (point-min))
15603 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15604 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15605 (vhdl-port-copy)))
15606 ;; ... from entity declaration (direct instantiation)
15607 (setq comp-ent-file-name
0a2e512a 15608 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
3dcb36b7
JB
15609 "." (file-name-extension (buffer-file-name))))
15610 (vhdl-visit-file
15611 comp-ent-file-name t
15612 (save-excursion
15613 (goto-char (point-min))
15614 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15615 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15616 (vhdl-port-copy))))
15617 (vhdl-port-flatten t)
15618 (setq generic-alist (nth 1 vhdl-port-list)
0a2e512a
RF
15619 port-alist (nth 2 vhdl-port-list)
15620 vhdl-port-list nil)
3dcb36b7
JB
15621 (setq constant-alist nil
15622 signal-alist nil)
15623 (when has-generic
15624 ;; process all constants in generic map
15625 (vhdl-forward-syntactic-ws)
15626 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15627 (setq constant-name (match-string-no-properties 3))
15628 (setq constant-entry
15629 (cons constant-name
15630 (if (match-string 1)
15631 (or (aget generic-alist (match-string 2) t)
ec3ec9cc 15632 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15633 (cdar generic-alist))))
15634 (setq constant-alist (cons constant-entry constant-alist))
15635 (setq constant-name (downcase constant-name))
15636 (if (or (member constant-name single-list)
15637 (member constant-name multi-list))
15638 (progn (setq single-list (delete constant-name single-list))
15639 (add-to-list 'multi-list constant-name))
15640 (add-to-list 'single-list constant-name))
15641 (unless (match-string 1)
15642 (setq generic-alist (cdr generic-alist)))
15643 (vhdl-forward-syntactic-ws))
15644 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15645 ;; process all signals in port map
15646 (vhdl-forward-syntactic-ws)
15647 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15648 (setq signal-name (match-string-no-properties 3))
15649 (setq signal-entry (cons signal-name
15650 (if (match-string 1)
15651 (or (aget port-alist (match-string 2) t)
ec3ec9cc 15652 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15653 (cdar port-alist))))
15654 (setq signal-alist (cons signal-entry signal-alist))
15655 (setq signal-name (downcase signal-name))
15656 (if (equal (upcase (nth 2 signal-entry)) "IN")
15657 ;; input signal
15658 (cond
15659 ((member signal-name local-list)
15660 nil)
15661 ((or (member signal-name single-out-list)
15662 (member signal-name multi-out-list))
15663 (setq single-out-list (delete signal-name single-out-list))
15664 (setq multi-out-list (delete signal-name multi-out-list))
15665 (add-to-list 'local-list signal-name))
15666 ((member signal-name single-in-list)
15667 (setq single-in-list (delete signal-name single-in-list))
15668 (add-to-list 'multi-in-list signal-name))
15669 ((not (member signal-name multi-in-list))
15670 (add-to-list 'single-in-list signal-name)))
15671 ;; output signal
15672 (cond
15673 ((member signal-name local-list)
15674 nil)
15675 ((or (member signal-name single-in-list)
15676 (member signal-name multi-in-list))
15677 (setq single-in-list (delete signal-name single-in-list))
15678 (setq multi-in-list (delete signal-name multi-in-list))
15679 (add-to-list 'local-list signal-name))
15680 ((member signal-name single-out-list)
15681 (setq single-out-list (delete signal-name single-out-list))
15682 (add-to-list 'multi-out-list signal-name))
15683 ((not (member signal-name multi-out-list))
15684 (add-to-list 'single-out-list signal-name))))
15685 (unless (match-string 1)
15686 (setq port-alist (cdr port-alist)))
15687 (vhdl-forward-syntactic-ws))
15688 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15689 (nreverse signal-alist)) inst-alist)))
15690 ;; prepare signal insertion
15691 (vhdl-goto-marker arch-decl-pos)
15692 (forward-line 1)
15693 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15694 (setq signal-pos (point-marker))
15695 (while (progn (vhdl-forward-syntactic-ws)
15696 (looking-at "signal\\>"))
15697 (beginning-of-line 2)
15698 (delete-region signal-pos (point)))
15699 (setq signal-beg-pos signal-pos)
15700 ;; open entity file
15701 (when (file-exists-p ent-file-name)
15702 (find-file ent-file-name))
15703 (goto-char (point-min))
15704 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15705 (error "ERROR: Entity not found: \"%s\"" ent-name))
15706 ;; prepare generic clause insertion
15707 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15708 (match-string 1))
15709 (goto-char (match-beginning 0))
15710 (indent-to vhdl-basic-offset)
15711 (insert "generic ();\n\n")
15712 (backward-char 4))
15713 (backward-char)
15714 (setq generic-pos (point-marker))
15715 (forward-sexp) (end-of-line)
15716 (delete-region generic-pos (point)) (delete-char 1)
15717 (insert "(\n")
15718 (when multi-list
15719 (insert "\n")
15720 (indent-to (* 2 vhdl-basic-offset))
15721 (insert "-- global generics\n"))
15722 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15723 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15724 ;; prepare port clause insertion
15725 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15726 (match-string 1))
15727 (goto-char (match-beginning 0))
15728 (indent-to vhdl-basic-offset)
15729 (insert "port ();\n\n")
15730 (backward-char 4))
15731 (backward-char)
15732 (setq port-in-pos (point-marker))
15733 (forward-sexp) (end-of-line)
15734 (delete-region port-in-pos (point)) (delete-char 1)
15735 (insert "(\n")
15736 (when (or multi-in-list multi-out-list)
15737 (insert "\n")
15738 (indent-to (* 2 vhdl-basic-offset))
15739 (insert "-- global ports\n"))
15740 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15741 port-out-pos (point-marker) port-inst-pos (point-marker)
15742 port-end-pos (point-marker))
15743 ;; insert generics, ports and signals
15744 (setq inst-alist (nreverse inst-alist))
15745 (while inst-alist
15746 (setq inst-name (nth 0 (car inst-alist))
15747 constant-alist (nth 1 (car inst-alist))
15748 signal-alist (nth 2 (car inst-alist))
15749 constant-temp-pos generic-inst-pos
15750 port-temp-pos port-inst-pos
15751 signal-temp-pos signal-pos)
15752 ;; generics
15753 (while constant-alist
15754 (setq constant-name (downcase (caar constant-alist))
15755 constant-entry (car constant-alist))
15756 (cond ((member constant-name written-list)
15757 nil)
15758 ((member constant-name multi-list)
15759 (vhdl-goto-marker generic-pos)
15760 (setq generic-end-pos
15761 (vhdl-max-marker
15762 generic-end-pos
15763 (vhdl-compose-insert-generic constant-entry)))
15764 (setq generic-pos (point-marker))
15765 (add-to-list 'written-list constant-name))
15766 (t
15767 (vhdl-goto-marker
15768 (vhdl-max-marker generic-inst-pos generic-pos))
15769 (setq generic-end-pos
15770 (vhdl-compose-insert-generic constant-entry))
15771 (setq generic-inst-pos (point-marker))
15772 (add-to-list 'written-list constant-name)))
15773 (setq constant-alist (cdr constant-alist)))
15774 (when (/= constant-temp-pos generic-inst-pos)
15775 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15776 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15777 (insert "-- generics for \"" inst-name "\"\n")
15778 (vhdl-goto-marker generic-inst-pos))
15779 ;; ports and signals
15780 (while signal-alist
15781 (setq signal-name (downcase (caar signal-alist))
15782 signal-entry (car signal-alist))
15783 (cond ((member signal-name written-list)
15784 nil)
15785 ((member signal-name multi-in-list)
15786 (vhdl-goto-marker port-in-pos)
15787 (setq port-end-pos
15788 (vhdl-max-marker
15789 port-end-pos (vhdl-compose-insert-port signal-entry)))
15790 (setq port-in-pos (point-marker))
15791 (add-to-list 'written-list signal-name))
15792 ((member signal-name multi-out-list)
15793 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15794 (setq port-end-pos
15795 (vhdl-max-marker
15796 port-end-pos (vhdl-compose-insert-port signal-entry)))
15797 (setq port-out-pos (point-marker))
15798 (add-to-list 'written-list signal-name))
15799 ((or (member signal-name single-in-list)
15800 (member signal-name single-out-list))
15801 (vhdl-goto-marker
15802 (vhdl-max-marker
15803 port-inst-pos
15804 (vhdl-max-marker port-out-pos port-in-pos)))
15805 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15806 (setq port-inst-pos (point-marker))
15807 (add-to-list 'written-list signal-name))
15808 ((equal (upcase (nth 2 signal-entry)) "OUT")
15809 (vhdl-goto-marker signal-pos)
15810 (vhdl-compose-insert-signal signal-entry)
15811 (setq signal-pos (point-marker))
15812 (add-to-list 'written-list signal-name)))
15813 (setq signal-alist (cdr signal-alist)))
15814 (when (/= port-temp-pos port-inst-pos)
15815 (vhdl-goto-marker
15816 (vhdl-max-marker port-temp-pos
15817 (vhdl-max-marker port-in-pos port-out-pos)))
15818 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15819 (insert "-- ports to \"" inst-name "\"\n")
15820 (vhdl-goto-marker port-inst-pos))
15821 (when (/= signal-temp-pos signal-pos)
15822 (vhdl-goto-marker signal-temp-pos)
15823 (insert "\n") (indent-to vhdl-basic-offset)
15824 (insert "-- outputs of \"" inst-name "\"\n")
15825 (vhdl-goto-marker signal-pos))
15826 (setq inst-alist (cdr inst-alist)))
15827 ;; finalize generic/port clause
15828 (vhdl-goto-marker generic-end-pos) (backward-char)
15829 (when (= generic-beg-pos generic-end-pos)
15830 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15831 (insert ";") (backward-char))
15832 (insert ")")
15833 (vhdl-goto-marker port-end-pos) (backward-char)
15834 (when (= port-beg-pos port-end-pos)
15835 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15836 (insert ";") (backward-char))
15837 (insert ")")
15838 ;; align everything
15839 (when vhdl-auto-align
15840 (vhdl-goto-marker generic-beg-pos)
15841 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15842 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15843 (vhdl-goto-marker signal-beg-pos)
15844 (vhdl-align-region-groups signal-beg-pos signal-pos))
15845 (switch-to-buffer (marker-buffer signal-beg-pos))
15846 (message "Wiring components...done")))))
15847
15848(defun vhdl-compose-insert-generic (entry)
15849 "Insert ENTRY as generic declaration."
15850 (let (pos)
15851 (indent-to (* 2 vhdl-basic-offset))
15852 (insert (nth 0 entry) " : " (nth 1 entry))
15853 (when (nth 2 entry)
15854 (insert " := " (nth 2 entry)))
15855 (insert ";")
15856 (setq pos (point-marker))
15857 (when (and vhdl-include-port-comments (nth 3 entry))
15858 (vhdl-comment-insert-inline (nth 3 entry) t))
15859 (insert "\n")
15860 pos))
15861
15862(defun vhdl-compose-insert-port (entry)
15863 "Insert ENTRY as port declaration."
15864 (let (pos)
15865 (indent-to (* 2 vhdl-basic-offset))
15866 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15867 (setq pos (point-marker))
15868 (when (and vhdl-include-port-comments (nth 4 entry))
15869 (vhdl-comment-insert-inline (nth 4 entry) t))
15870 (insert "\n")
15871 pos))
15872
15873(defun vhdl-compose-insert-signal (entry)
15874 "Insert ENTRY as signal declaration."
15875 (indent-to vhdl-basic-offset)
15876 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15877 (when (and vhdl-include-port-comments (nth 4 entry))
15878 (vhdl-comment-insert-inline (nth 4 entry) t))
15879 (insert "\n"))
15880
15881(defun vhdl-compose-components-package ()
15882 "Generate a package containing component declarations for all entities in the
15883current project/directory."
15884 (interactive)
15885 (vhdl-require-hierarchy-info)
15886 (let* ((project (vhdl-project-p))
15887 (pack-name (vhdl-get-components-package-name))
15888 (pack-file-name
0a2e512a 15889 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15890 "." (file-name-extension (buffer-file-name))))
15891 (ent-alist (aget vhdl-entity-alist
15892 (or project default-directory) t))
15893 (lazy-lock-minimum-size 0)
15894 clause-pos component-pos)
15895 (message "Generating components package \"%s\"..." pack-name)
15896 ;; open package file
15897 (when (and (file-exists-p pack-file-name)
15898 (not (y-or-n-p (concat "File \"" pack-file-name
15899 "\" exists; overwrite? "))))
15900 (error "ERROR: Generating components package...aborted"))
15901 (find-file pack-file-name)
15902 (erase-buffer)
15903 ;; insert header
15904 (if vhdl-compose-include-header
15905 (progn (vhdl-template-header
15906 (concat "Components package (generated by Emacs VHDL Mode "
15907 vhdl-version ")"))
15908 (goto-char (point-max)))
15909 (vhdl-comment-display-line) (insert "\n\n"))
15910 ;; insert std_logic_1164 package
15911 (vhdl-template-package-std-logic-1164)
15912 (insert "\n") (setq clause-pos (point-marker))
15913 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15914 ;; insert package declaration
15915 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15916 (vhdl-insert-keyword " IS\n\n")
15917 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15918 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15919 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15920 (indent-to vhdl-basic-offset)
15921 (setq component-pos (point-marker))
15922 (insert "\n\n") (vhdl-insert-keyword "END ")
15923 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15924 (insert pack-name ";\n\n")
15925 ;; insert footer
15926 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15927 (vhdl-template-footer)
15928 (vhdl-comment-display-line) (insert "\n"))
15929 ;; insert component declarations
15930 (while ent-alist
15931 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15932 (progn (goto-line (nth 3 (car ent-alist)))
15933 (end-of-line)
15934 (vhdl-port-copy)))
15935 (goto-char component-pos)
15936 (vhdl-port-paste-component t)
15937 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15938 (setq component-pos (point-marker))
15939 (goto-char clause-pos)
15940 (vhdl-port-paste-context-clause pack-name)
15941 (setq clause-pos (point-marker))
15942 (setq ent-alist (cdr ent-alist)))
15943 (goto-char (point-min))
15944 (save-buffer)
15945 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15946 pack-name pack-file-name)))
15947
0a2e512a
RF
15948(defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15949 &optional insert-conf)
15950 "Generate block configuration for architecture."
15951 (let ((margin (current-indentation))
15952 (beg (save-excursion (beginning-of-line) (point)))
15953 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15954 ;; insert block configuration (for architecture)
15955 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15956 (setq margin (+ margin vhdl-basic-offset))
15957 ;; process all instances
15958 (while inst-alist
15959 (setq inst-entry (car inst-alist))
15960 ;; is component?
15961 (when (nth 4 inst-entry)
15962 (setq insert-conf t)
15963 (setq inst-path (nth 9 inst-entry))
15964 ;; skip common path with previous instance
15965 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15966 (setq inst-path (cdr inst-path)
15967 inst-prev-path (cdr inst-prev-path)))
15968 ;; insert block configuration end (for previous block/generate)
15969 (while inst-prev-path
15970 (setq margin (- margin vhdl-basic-offset))
15971 (indent-to margin)
15972 (vhdl-insert-keyword "END FOR;\n")
15973 (setq inst-prev-path (cdr inst-prev-path)))
15974 ;; insert block configuration beginning (for current block/generate)
15975 (indent-to margin)
15976 (while inst-path
15977 (setq margin (+ margin vhdl-basic-offset))
15978 (vhdl-insert-keyword "FOR ")
15979 (insert (car inst-path) "\n")
15980 (indent-to margin)
15981 (setq inst-path (cdr inst-path)))
15982 ;; insert component configuration beginning
15983 (vhdl-insert-keyword "FOR ")
15984 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15985 ;; find subconfiguration
15986 (setq conf-key (nth 7 inst-entry))
15987 (setq tmp-alist conf-alist)
15988 ;; use first configuration found for instance's entity
15989 (while (and tmp-alist (null conf-key))
15990 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15991 (setq conf-key (nth 0 (car tmp-alist))))
15992 (setq tmp-alist (cdr tmp-alist)))
15993 (setq conf-entry (aget conf-alist conf-key t))
15994 ;; insert binding indication ...
15995 ;; ... with subconfiguration (if exists)
15996 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15997 (progn
15998 (indent-to (+ margin vhdl-basic-offset))
15999 (vhdl-insert-keyword "USE CONFIGURATION ")
16000 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16001 (insert ";\n"))
16002 ;; ... with entity (if exists)
16003 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16004 (when ent-entry
16005 (indent-to (+ margin vhdl-basic-offset))
16006 (vhdl-insert-keyword "USE ENTITY ")
16007 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16008 ;; insert architecture name (if architecture exists)
16009 (when (nth 3 ent-entry)
16010 (setq arch-name
16011 ;; choose architecture name a) from configuration,
16012 ;; b) from mra, or c) from first architecture
16013 (or (nth 0 (aget (nth 3 ent-entry)
16014 (or (nth 6 inst-entry)
16015 (nth 4 ent-entry)) t))
16016 (nth 1 (car (nth 3 ent-entry)))))
16017 (insert "(" arch-name ")"))
16018 (insert ";\n")
16019 ;; insert block configuration (for architecture of subcomponent)
16020 (when (and vhdl-compose-configuration-hierarchical
16021 (nth 3 ent-entry))
16022 (indent-to (+ margin vhdl-basic-offset))
16023 (vhdl-compose-configuration-architecture
16024 (nth 0 ent-entry) arch-name
16025 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16026 ;; insert component configuration end
16027 (indent-to margin)
16028 (vhdl-insert-keyword "END FOR;\n")
16029 (setq inst-prev-path (nth 9 inst-entry)))
16030 (setq inst-alist (cdr inst-alist)))
16031 ;; insert block configuration end (for block/generate)
16032 (while inst-prev-path
16033 (setq margin (- margin vhdl-basic-offset))
16034 (indent-to margin)
16035 (vhdl-insert-keyword "END FOR;\n")
16036 (setq inst-prev-path (cdr inst-prev-path)))
16037 (indent-to (- margin vhdl-basic-offset))
16038 ;; insert block configuration end or remove beginning (for architecture)
16039 (if insert-conf
16040 (vhdl-insert-keyword "END FOR;\n")
16041 (delete-region beg (point)))))
16042
16043(defun vhdl-compose-configuration (&optional ent-name arch-name)
16044 "Generate configuration declaration."
16045 (interactive)
16046 (vhdl-require-hierarchy-info)
16047 (let ((ent-alist (aget vhdl-entity-alist
16048 (or (vhdl-project-p) default-directory) t))
16049 (conf-alist (aget vhdl-config-alist
16050 (or (vhdl-project-p) default-directory) t))
16051 (from-speedbar ent-name)
16052 inst-alist conf-name conf-file-name pos)
16053 (vhdl-prepare-search-2
16054 ;; get entity and architecture name
16055 (unless ent-name
16056 (save-excursion
16057 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16058 (not (equal "END" (upcase (match-string 1))))
16059 (setq ent-name (match-string-no-properties 3))
16060 (setq arch-name (match-string-no-properties 2)))
16061 (error "ERROR: Not within an architecture"))))
16062 (setq conf-name (vhdl-replace-string
16063 vhdl-compose-configuration-name
16064 (concat ent-name " " arch-name)))
16065 (setq inst-alist
16066 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16067 (downcase arch-name) t))))
16068 (message "Generating configuration \"%s\"..." conf-name)
16069 (if vhdl-compose-configuration-create-file
16070 ;; open configuration file
16071 (progn
16072 (setq conf-file-name
16073 (concat (vhdl-replace-string vhdl-configuration-file-name
16074 conf-name t)
16075 "." (file-name-extension (buffer-file-name))))
16076 (when (and (file-exists-p conf-file-name)
16077 (not (y-or-n-p (concat "File \"" conf-file-name
16078 "\" exists; overwrite? "))))
16079 (error "ERROR: Creating configuration...aborted"))
16080 (find-file conf-file-name)
16081 (erase-buffer)
16082 (set-buffer-modified-p nil)
16083 ;; insert header
16084 (if vhdl-compose-include-header
16085 (progn (vhdl-template-header
16086 (concat "Configuration declaration for design \""
16087 ent-name "(" arch-name ")\""))
16088 (goto-char (point-max)))
16089 (vhdl-comment-display-line) (insert "\n\n")))
16090 ;; goto end of architecture
16091 (unless from-speedbar
16092 (re-search-forward "^end\\>" nil)
16093 (end-of-line) (insert "\n\n")
16094 (vhdl-comment-display-line) (insert "\n\n")))
16095 ;; insert library clause
16096 (setq pos (point))
16097 (vhdl-template-standard-package (vhdl-work-library) nil)
16098 (when (/= pos (point))
16099 (insert "\n\n"))
16100 ;; insert configuration
16101 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16102 (vhdl-insert-keyword " OF ") (insert ent-name)
16103 (vhdl-insert-keyword " IS\n")
16104 (indent-to vhdl-basic-offset)
16105 ;; insert block configuration (for architecture)
16106 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16107 (vhdl-insert-keyword "END ") (insert conf-name ";")
16108 (when conf-file-name
16109 ;; insert footer and save
16110 (insert "\n\n")
16111 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16112 (vhdl-template-footer)
16113 (vhdl-comment-display-line) (insert "\n"))
16114 (save-buffer))
29a4e67d 16115 (message "%s"
0a2e512a
RF
16116 (concat (format "Generating configuration \"%s\"...done" conf-name)
16117 (and conf-file-name
16118 (format "\n File created: \"%s\"" conf-file-name))))))
16119
3dcb36b7
JB
16120
16121;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16122;;; Compilation / Makefile generation
16123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16124;; (using `compile.el')
16125
16126(defun vhdl-makefile-name ()
16127 "Return the Makefile name of the current project or the current compiler if
16128no project is defined."
16129 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16130 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16131 (vhdl-replace-string
16132 (cons "\\(.*\\)\n\\(.*\\)"
16133 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16134 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16135
16136(defun vhdl-compile-directory ()
16137 "Return the directory where compilation/make should be run."
16138 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16139 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16140 (directory (vhdl-resolve-env-variable
16141 (if project
16142 (vhdl-replace-string
16143 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16144 (nth 6 compiler)))))
16145 (file-name-as-directory
16146 (if (file-name-absolute-p directory)
16147 directory
16148 (expand-file-name directory (vhdl-default-directory))))))
16149
16150(defun vhdl-uniquify (in-list)
16151 "Remove duplicate elements from IN-LIST."
16152 (let (out-list)
16153 (while in-list
16154 (add-to-list 'out-list (car in-list))
16155 (setq in-list (cdr in-list)))
16156 out-list))
16157
16158(defun vhdl-set-compiler (name)
16159 "Set current compiler to NAME."
16160 (interactive
16161 (list (let ((completion-ignore-case t))
16162 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16163 (if (assoc name vhdl-compiler-alist)
16164 (progn (setq vhdl-compiler name)
16165 (message "Current compiler: \"%s\"" vhdl-compiler))
16166 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16167
16168;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16169;; Compilation
16170
16171(defun vhdl-compile-init ()
16172 "Initialize for compilation."
16173 (when (or (null compilation-error-regexp-alist)
16174 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16175 compilation-error-regexp-alist)))
16176 ;; `compilation-error-regexp-alist'
16177 (let ((commands-alist vhdl-compiler-alist)
16178 regexp-alist sublist)
16179 (while commands-alist
16180 (setq sublist (nth 11 (car commands-alist)))
16181 (unless (or (equal "" (car sublist))
16182 (assoc (car sublist) regexp-alist))
16183 (setq regexp-alist (cons (list (nth 0 sublist)
16184 (if (= 0 (nth 1 sublist))
16185 (if vhdl-xemacs 9 nil)
16186 (nth 1 sublist))
16187 (nth 2 sublist) (nth 3 sublist))
16188 regexp-alist)))
16189 (setq commands-alist (cdr commands-alist)))
16190 (setq compilation-error-regexp-alist
16191 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16192 ;; `compilation-file-regexp-alist'
16193 (let ((commands-alist vhdl-compiler-alist)
16194 regexp-alist sublist)
16195 ;; matches vhdl-mode file name output
16196 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16197 (while commands-alist
16198 (setq sublist (nth 12 (car commands-alist)))
16199 (unless (or (equal "" (car sublist))
16200 (assoc (car sublist) regexp-alist))
16201 (setq regexp-alist (cons sublist regexp-alist)))
16202 (setq commands-alist (cdr commands-alist)))
16203 (setq compilation-file-regexp-alist
16204 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16205
16206(defvar vhdl-compile-file-name nil
16207 "Name of file to be compiled.")
16208
16209(defun vhdl-compile-print-file-name ()
16210 "Function called within `compile' to print out file name for compilers that
16211do not print any file names."
16212 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16213
16214(defun vhdl-get-compile-options (project compiler file-name
16215 &optional file-options-only)
16216 "Get compiler options. Returning nil means do not compile this file."
16217 (let* ((compiler-options (nth 1 compiler))
16218 (project-entry (aget (nth 4 project) vhdl-compiler))
16219 (project-options (nth 0 project-entry))
16220 (exception-list (and file-name (nth 2 project-entry)))
16221 (work-library (vhdl-work-library))
16222 (case-fold-search nil)
16223 file-options)
16224 (while (and exception-list
16225 (not (string-match (caar exception-list) file-name)))
16226 (setq exception-list (cdr exception-list)))
16227 (if (and exception-list (not (cdar exception-list)))
16228 nil
16229 (if (and file-options-only (not exception-list))
16230 'default
16231 (setq file-options (cdar exception-list))
16232 ;; insert library name in compiler-specific options
16233 (setq compiler-options
16234 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16235 work-library))
16236 ;; insert compiler-specific options in project-specific options
16237 (when project-options
16238 (setq project-options
16239 (vhdl-replace-string
16240 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16241 (concat work-library "\n" compiler-options))))
16242 ;; insert project-specific options in file-specific options
16243 (when file-options
16244 (setq file-options
16245 (vhdl-replace-string
16246 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16247 (concat work-library "\n" compiler-options "\n"
16248 project-options))))
16249 ;; return options
16250 (or file-options project-options compiler-options)))))
16251
16252(defun vhdl-get-make-options (project compiler)
16253 "Get make options."
16254 (let* ((compiler-options (nth 3 compiler))
16255 (project-entry (aget (nth 4 project) vhdl-compiler))
16256 (project-options (nth 1 project-entry))
16257 (makefile-name (vhdl-makefile-name)))
16258 ;; insert Makefile name in compiler-specific options
16259 (setq compiler-options
16260 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16261 makefile-name))
16262 ;; insert compiler-specific options in project-specific options
16263 (when project-options
16264 (setq project-options
16265 (vhdl-replace-string
16266 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16267 (concat makefile-name "\n" compiler-options))))
16268 ;; return options
16269 (or project-options compiler-options)))
16270
16271(defun vhdl-compile ()
16272 "Compile current buffer using the VHDL compiler specified in
16273`vhdl-compiler'."
16274 (interactive)
16275 (vhdl-compile-init)
16276 (let* ((project (aget vhdl-project-alist vhdl-project))
16277 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16278 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16279 (command (nth 0 compiler))
16280 (file-name (buffer-file-name))
16281 (options (vhdl-get-compile-options project compiler file-name))
16282 (default-directory (vhdl-compile-directory))
16283 compilation-process-setup-function)
16284 (unless (file-directory-p default-directory)
16285 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16286 ;; put file name into quotes if it contains spaces
16287 (when (string-match " " file-name)
16288 (setq file-name (concat "\"" file-name "\"")))
16289 ;; print out file name if compiler does not
16290 (setq vhdl-compile-file-name (buffer-file-name))
16291 (when (and (= 0 (nth 1 (nth 10 compiler)))
16292 (= 0 (nth 1 (nth 11 compiler))))
16293 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16294 ;; run compilation
16295 (if options
16296 (when command
16297 (compile (concat command " " options " " file-name)))
16298 (vhdl-warning "Your project settings tell me not to compile this file"))))
16299
0a2e512a
RF
16300(defvar vhdl-make-target "all"
16301 "Default target for `vhdl-make' command.")
16302
3dcb36b7
JB
16303(defun vhdl-make (&optional target)
16304 "Call make command for compilation of all updated source files (requires
16305`Makefile'). Optional argument TARGET allows to compile the design
16306specified by a target."
16307 (interactive)
0a2e512a
RF
16308 (setq vhdl-make-target
16309 (or target (read-from-minibuffer "Target: " vhdl-make-target
16310 vhdl-minibuffer-local-map)))
3dcb36b7
JB
16311 (vhdl-compile-init)
16312 (let* ((project (aget vhdl-project-alist vhdl-project))
16313 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16314 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16315 (command (nth 2 compiler))
16316 (options (vhdl-get-make-options project compiler))
16317 (default-directory (vhdl-compile-directory)))
16318 (unless (file-directory-p default-directory)
16319 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16320 ;; run make
16321 (compile (concat (if (equal command "") "make" command)
0a2e512a 16322 " " options " " vhdl-make-target))))
3dcb36b7
JB
16323
16324;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16325;; Makefile generation
16326
16327(defun vhdl-generate-makefile ()
16328 "Generate `Makefile'."
16329 (interactive)
16330 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16331 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16332 (command (nth 4 compiler)))
16333 ;; generate makefile
16334 (if command
16335 (let ((default-directory (vhdl-compile-directory)))
16336 (compile (vhdl-replace-string
16337 (cons "\\(.*\\) \\(.*\\)" command)
16338 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16339 (vhdl-generate-makefile-1))))
16340
16341(defun vhdl-get-packages (lib-alist work-library)
16342 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16343 (let (pack-list)
16344 (while lib-alist
16345 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16346 (setq pack-list (cons (cdar lib-alist) pack-list)))
16347 (setq lib-alist (cdr lib-alist)))
16348 pack-list))
16349
16350(defun vhdl-generate-makefile-1 ()
16351 "Generate Makefile for current project or directory."
16352 ;; scan hierarchy if required
16353 (if (vhdl-project-p)
16354 (unless (or (assoc vhdl-project vhdl-file-alist)
16355 (vhdl-load-cache vhdl-project))
16356 (vhdl-scan-project-contents vhdl-project))
16357 (let ((directory (abbreviate-file-name default-directory)))
16358 (unless (or (assoc directory vhdl-file-alist)
16359 (vhdl-load-cache directory))
16360 (vhdl-scan-directory-contents directory))))
16361 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16362 (project (vhdl-project-p))
16363 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16364 (conf-alist (aget vhdl-config-alist (or project directory) t))
16365 (pack-alist (aget vhdl-package-alist (or project directory) t))
16366 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16367 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16368 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16369 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16370 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16371 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16372 (adjust-case (nth 5 regexp-list))
16373 (work-library (downcase (vhdl-work-library)))
16374 (compile-directory (expand-file-name (vhdl-compile-directory)
16375 default-directory))
16376 (makefile-name (vhdl-makefile-name))
16377 rule-alist arch-alist inst-alist
16378 target-list depend-list unit-list prim-list second-list subcomp-list
16379 lib-alist lib-body-alist pack-list all-pack-list
16380 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16381 conf-key conf-file-name pack-key pack-file-name
16382 ent-entry arch-entry conf-entry pack-entry inst-entry
16383 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16384 tmp-key tmp-list rule)
16385 ;; check prerequisites
16386 (unless (file-exists-p compile-directory)
16387 (make-directory compile-directory t))
16388 (unless regexp-list
16389 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16390 vhdl-compiler))
16391 (message "Generating makefile \"%s\"..." makefile-name)
16392 ;; rules for all entities
16393 (setq tmp-list ent-alist)
16394 (while ent-alist
16395 (setq ent-entry (car ent-alist)
16396 ent-key (nth 0 ent-entry))
16397 (when (nth 2 ent-entry)
16398 (setq ent-file-name (file-relative-name
16399 (nth 2 ent-entry) compile-directory)
16400 arch-alist (nth 4 ent-entry)
0a2e512a 16401 lib-alist (nth 6 ent-entry)
3dcb36b7
JB
16402 rule (aget rule-alist ent-file-name)
16403 target-list (nth 0 rule)
16404 depend-list (nth 1 rule)
16405 second-list nil
16406 subcomp-list nil)
16407 (setq tmp-key (vhdl-replace-string
16408 ent-regexp (funcall adjust-case ent-key)))
16409 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16410 ;; rule target for this entity
16411 (setq target-list (cons ent-key target-list))
16412 ;; rule dependencies for all used packages
16413 (setq pack-list (vhdl-get-packages lib-alist work-library))
16414 (setq depend-list (append depend-list pack-list))
16415 (setq all-pack-list pack-list)
16416 ;; add rule
16417 (aput 'rule-alist ent-file-name (list target-list depend-list))
16418 ;; rules for all corresponding architectures
16419 (while arch-alist
16420 (setq arch-entry (car arch-alist)
16421 arch-key (nth 0 arch-entry)
16422 ent-arch-key (concat ent-key "-" arch-key)
16423 arch-file-name (file-relative-name (nth 2 arch-entry)
16424 compile-directory)
16425 inst-alist (nth 4 arch-entry)
16426 lib-alist (nth 5 arch-entry)
16427 rule (aget rule-alist arch-file-name)
16428 target-list (nth 0 rule)
16429 depend-list (nth 1 rule))
16430 (setq tmp-key (vhdl-replace-string
16431 arch-regexp
16432 (funcall adjust-case (concat arch-key " " ent-key))))
16433 (setq unit-list
16434 (cons (cons ent-arch-key tmp-key) unit-list))
16435 (setq second-list (cons ent-arch-key second-list))
16436 ;; rule target for this architecture
16437 (setq target-list (cons ent-arch-key target-list))
16438 ;; rule dependency for corresponding entity
16439 (setq depend-list (cons ent-key depend-list))
16440 ;; rule dependencies for contained component instantiations
16441 (while inst-alist
16442 (setq inst-entry (car inst-alist))
16443 (when (or (null (nth 8 inst-entry))
16444 (equal (downcase (nth 8 inst-entry)) work-library))
16445 (setq inst-ent-key (or (nth 7 inst-entry)
16446 (nth 5 inst-entry)))
16447 (setq depend-list (cons inst-ent-key depend-list)
16448 subcomp-list (cons inst-ent-key subcomp-list)))
16449 (setq inst-alist (cdr inst-alist)))
16450 ;; rule dependencies for all used packages
16451 (setq pack-list (vhdl-get-packages lib-alist work-library))
16452 (setq depend-list (append depend-list pack-list))
16453 (setq all-pack-list (append all-pack-list pack-list))
16454 ;; add rule
16455 (aput 'rule-alist arch-file-name (list target-list depend-list))
16456 (setq arch-alist (cdr arch-alist)))
16457 (setq prim-list (cons (list ent-key second-list
16458 (append subcomp-list all-pack-list))
16459 prim-list)))
16460 (setq ent-alist (cdr ent-alist)))
16461 (setq ent-alist tmp-list)
16462 ;; rules for all configurations
16463 (setq tmp-list conf-alist)
16464 (while conf-alist
16465 (setq conf-entry (car conf-alist)
16466 conf-key (nth 0 conf-entry)
16467 conf-file-name (file-relative-name
16468 (nth 2 conf-entry) compile-directory)
16469 ent-key (nth 4 conf-entry)
16470 arch-key (nth 5 conf-entry)
16471 inst-alist (nth 6 conf-entry)
16472 lib-alist (nth 7 conf-entry)
16473 rule (aget rule-alist conf-file-name)
16474 target-list (nth 0 rule)
16475 depend-list (nth 1 rule)
16476 subcomp-list (list ent-key))
16477 (setq tmp-key (vhdl-replace-string
16478 conf-regexp (funcall adjust-case conf-key)))
16479 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16480 ;; rule target for this configuration
16481 (setq target-list (cons conf-key target-list))
16482 ;; rule dependency for corresponding entity and architecture
16483 (setq depend-list
16484 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16485 ;; rule dependencies for used packages
16486 (setq pack-list (vhdl-get-packages lib-alist work-library))
16487 (setq depend-list (append depend-list pack-list))
16488 ;; rule dependencies for contained component configurations
16489 (while inst-alist
16490 (setq inst-entry (car inst-alist))
16491 (setq inst-ent-key (nth 2 inst-entry)
16492; comp-arch-key (nth 2 inst-entry))
16493 inst-conf-key (nth 4 inst-entry))
16494 (when (equal (downcase (nth 5 inst-entry)) work-library)
16495 (when inst-ent-key
16496 (setq depend-list (cons inst-ent-key depend-list)
16497 subcomp-list (cons inst-ent-key subcomp-list)))
16498; (when comp-arch-key
16499; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16500; depend-list)))
16501 (when inst-conf-key
16502 (setq depend-list (cons inst-conf-key depend-list)
16503 subcomp-list (cons inst-conf-key subcomp-list))))
16504 (setq inst-alist (cdr inst-alist)))
16505 ;; add rule
16506 (aput 'rule-alist conf-file-name (list target-list depend-list))
16507 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16508 prim-list))
16509 (setq conf-alist (cdr conf-alist)))
16510 (setq conf-alist tmp-list)
16511 ;; rules for all packages
16512 (setq tmp-list pack-alist)
16513 (while pack-alist
16514 (setq pack-entry (car pack-alist)
16515 pack-key (nth 0 pack-entry)
16516 pack-body-key nil)
16517 (when (nth 2 pack-entry)
16518 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16519 compile-directory)
16520 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16521 rule (aget rule-alist pack-file-name)
16522 target-list (nth 0 rule) depend-list (nth 1 rule))
16523 (setq tmp-key (vhdl-replace-string
16524 pack-regexp (funcall adjust-case pack-key)))
16525 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16526 ;; rule target for this package
16527 (setq target-list (cons pack-key target-list))
16528 ;; rule dependencies for all used packages
16529 (setq pack-list (vhdl-get-packages lib-alist work-library))
16530 (setq depend-list (append depend-list pack-list))
16531 (setq all-pack-list pack-list)
16532 ;; add rule
16533 (aput 'rule-alist pack-file-name (list target-list depend-list))
16534 ;; rules for this package's body
16535 (when (nth 7 pack-entry)
16536 (setq pack-body-key (concat pack-key "-body")
16537 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16538 compile-directory)
16539 rule (aget rule-alist pack-body-file-name)
16540 target-list (nth 0 rule)
16541 depend-list (nth 1 rule))
16542 (setq tmp-key (vhdl-replace-string
16543 pack-body-regexp (funcall adjust-case pack-key)))
16544 (setq unit-list
16545 (cons (cons pack-body-key tmp-key) unit-list))
16546 ;; rule target for this package's body
16547 (setq target-list (cons pack-body-key target-list))
16548 ;; rule dependency for corresponding package declaration
16549 (setq depend-list (cons pack-key depend-list))
16550 ;; rule dependencies for all used packages
16551 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16552 (setq depend-list (append depend-list pack-list))
16553 (setq all-pack-list (append all-pack-list pack-list))
16554 ;; add rule
16555 (aput 'rule-alist pack-body-file-name
16556 (list target-list depend-list)))
16557 (setq prim-list
16558 (cons (list pack-key (when pack-body-key (list pack-body-key))
16559 all-pack-list)
16560 prim-list)))
16561 (setq pack-alist (cdr pack-alist)))
16562 (setq pack-alist tmp-list)
16563 ;; generate Makefile
16564 (let* ((project (aget vhdl-project-alist project))
16565 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16566 (compiler-id (nth 9 compiler))
16567 (library-directory
16568 (vhdl-resolve-env-variable
16569 (vhdl-replace-string
16570 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16571 compiler-id)))
16572 (makefile-path-name (expand-file-name
16573 makefile-name compile-directory))
16574 (orig-buffer (current-buffer))
16575 cell second-list subcomp-list options unit-key unit-name)
16576 ;; sort lists
16577 (setq unit-list (vhdl-sort-alist unit-list))
16578 (setq prim-list (vhdl-sort-alist prim-list))
16579 (setq tmp-list rule-alist)
16580 (while tmp-list ; pre-sort rule targets
16581 (setq cell (cdar tmp-list))
16582 (setcar cell (sort (car cell) 'string<))
16583 (setq tmp-list (cdr tmp-list)))
16584 (setq rule-alist ; sort by first rule target
16585 (sort rule-alist
16586 (function (lambda (a b)
16587 (string< (car (cadr a)) (car (cadr b)))))))
16588 ;; open and clear Makefile
16589 (set-buffer (find-file-noselect makefile-path-name t t))
16590 (erase-buffer)
16591 (insert "# -*- Makefile -*-\n"
16592 "### " (file-name-nondirectory makefile-name)
16593 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16594 "\n")
16595 (if project
16596 (insert "\n# Project : " (nth 0 project))
16597 (insert "\n# Directory : \"" directory "\""))
16598 (insert "\n# Platform : " vhdl-compiler
16599 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16600 (user-login-name) "\n")
16601 ;; insert compile and option variable settings
16602 (insert "\n\n# Define compilation command and options\n"
16603 "\nCOMPILE = " (nth 0 compiler)
16604 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16605 "\n")
16606 ;; insert library paths
16607 (setq library-directory
16608 (directory-file-name
16609 (if (file-name-absolute-p library-directory)
16610 library-directory
16611 (file-relative-name
16612 (expand-file-name library-directory directory)
16613 compile-directory))))
16614 (insert "\n\n# Define library paths\n"
16615 "\nLIBRARY-" work-library " = " library-directory "\n")
16616 ;; insert variable definitions for all library unit files
16617 (insert "\n\n# Define library unit files\n")
16618 (setq tmp-list unit-list)
16619 (while unit-list
16620 (insert "\nUNIT-" work-library "-" (caar unit-list)
16621 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16622 (setq unit-list (cdr unit-list)))
16623 ;; insert variable definition for list of all library unit files
16624 (insert "\n\n\n# Define list of all library unit files\n"
16625 "\nALL_UNITS =")
16626 (setq unit-list tmp-list)
16627 (while unit-list
16628 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16629 (setq unit-list (cdr unit-list)))
16630 (insert "\n")
16631 (setq unit-list tmp-list)
16632 ;; insert `make all' rule
16633 (insert "\n\n\n# Rule for compiling entire design\n"
16634 "\nall :"
16635 " \\\n\t\tlibrary"
16636 " \\\n\t\t$(ALL_UNITS)\n")
16637 ;; insert `make clean' rule
16638 (insert "\n\n# Rule for cleaning entire design\n"
16639 "\nclean : "
16640 "\n\t-rm -f $(ALL_UNITS)\n")
16641 ;; insert `make library' rule
16642 (insert "\n\n# Rule for creating library directory\n"
16643 "\nlibrary :"
16644 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16645 "\n$(LIBRARY-" work-library ") :"
16646 "\n\t"
16647 (vhdl-replace-string
16648 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16649 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16650 "\n")
16651 ;; insert rule for each library unit
16652 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16653 (while prim-list
16654 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16655 (setq subcomp-list
16656 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16657 (setq unit-key (caar prim-list)
16658 unit-name (or (nth 0 (aget ent-alist unit-key t))
16659 (nth 0 (aget conf-alist unit-key t))
16660 (nth 0 (aget pack-alist unit-key t))))
16661 (insert "\n" unit-key)
16662 (unless (equal unit-key unit-name)
16663 (insert " \\\n" unit-name))
16664 (insert " :"
16665 " \\\n\t\tlibrary"
16666 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16667 (while second-list
16668 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16669 (setq second-list (cdr second-list)))
16670 (while subcomp-list
0a2e512a
RF
16671 (when (and (assoc (car subcomp-list) unit-list)
16672 (not (equal unit-key (car subcomp-list))))
3dcb36b7
JB
16673 (insert " \\\n\t\t" (car subcomp-list)))
16674 (setq subcomp-list (cdr subcomp-list)))
16675 (insert "\n")
16676 (setq prim-list (cdr prim-list)))
16677 ;; insert rule for each library unit file
16678 (insert "\n\n# Rules for compiling single library unit files\n")
16679 (while rule-alist
16680 (setq rule (car rule-alist))
16681 ;; get compiler options for this file
16682 (setq options
16683 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16684 ;; insert rule if file is supposed to be compiled
16685 (setq target-list (nth 1 rule)
16686 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16687 ;; insert targets
16688 (setq tmp-list target-list)
16689 (while target-list
16690 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16691 (if (cdr target-list) " \\" " :"))
16692 (setq target-list (cdr target-list)))
16693 (setq target-list tmp-list)
16694 ;; insert file name as first dependency
16695 (insert " \\\n\t\t" (nth 0 rule))
16696 ;; insert dependencies (except if also target or unit does not exist)
16697 (while depend-list
16698 (when (and (not (member (car depend-list) target-list))
16699 (assoc (car depend-list) unit-list))
16700 (insert " \\\n\t\t"
16701 "$(UNIT-" work-library "-" (car depend-list) ")"))
16702 (setq depend-list (cdr depend-list)))
16703 ;; insert compile command
16704 (if options
16705 (insert "\n\t$(COMPILE) "
16706 (if (eq options 'default) "$(OPTIONS)" options) " "
16707 (nth 0 rule) "\n")
16708 (setq tmp-list target-list)
16709 (while target-list
16710 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16711 (if (cdr target-list) " \\" "\n"))
16712 (setq target-list (cdr target-list)))
16713 (setq target-list tmp-list))
16714 (setq rule-alist (cdr rule-alist)))
16715 (insert "\n\n### " makefile-name " ends here\n")
16716 ;; run Makefile generation hook
16717 (run-hooks 'vhdl-makefile-generation-hook)
16718 (message "Generating makefile \"%s\"...done" makefile-name)
16719 ;; save and close file
16720 (if (file-writable-p makefile-path-name)
16721 (progn (save-buffer)
16722 (kill-buffer (current-buffer))
16723 (set-buffer orig-buffer)
16724 (setq file-name-history
16725 (cons makefile-path-name file-name-history)))
16726 (vhdl-warning-when-idle
16727 (format "File not writable: \"%s\""
16728 (abbreviate-file-name makefile-path-name)))
16729 (switch-to-buffer (current-buffer))))))
16730
5eabfe72
KH
16731
16732;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16733;;; Bug reports
16734;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16735;; (using `reporter.el')
16736
3dcb36b7
JB
16737(defconst vhdl-mode-help-address
16738 "Reto Zimmermann <reto@gnu.org>"
d2ddb974
KH
16739 "Address for VHDL Mode bug reports.")
16740
3dcb36b7
JB
16741(defun vhdl-submit-bug-report ()
16742 "Submit via mail a bug report on VHDL Mode."
16743 (interactive)
16744 ;; load in reporter
16745 (and
16746 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16747 (let ((reporter-prompt-for-summary-p t))
16748 (reporter-submit-bug-report
16749 vhdl-mode-help-address
16750 (concat "VHDL Mode " vhdl-version)
16751 (list
16752 ;; report all important user options
16753 'vhdl-offsets-alist
16754 'vhdl-comment-only-line-offset
16755 'tab-width
16756 'vhdl-electric-mode
16757 'vhdl-stutter-mode
16758 'vhdl-indent-tabs-mode
16759 'vhdl-project-alist
16760 'vhdl-project
16761 'vhdl-project-file-name
16762 'vhdl-project-auto-load
16763 'vhdl-project-sort
16764 'vhdl-compiler-alist
16765 'vhdl-compiler
16766 'vhdl-compile-use-local-error-regexp
16767 'vhdl-makefile-generation-hook
16768 'vhdl-default-library
16769 'vhdl-standard
16770 'vhdl-basic-offset
16771 'vhdl-upper-case-keywords
16772 'vhdl-upper-case-types
16773 'vhdl-upper-case-attributes
16774 'vhdl-upper-case-enum-values
16775 'vhdl-upper-case-constants
16776 'vhdl-use-direct-instantiation
0a2e512a 16777 'vhdl-compose-configuration-name
3dcb36b7
JB
16778 'vhdl-entity-file-name
16779 'vhdl-architecture-file-name
0a2e512a 16780 'vhdl-configuration-file-name
3dcb36b7
JB
16781 'vhdl-package-file-name
16782 'vhdl-file-name-case
16783 'vhdl-electric-keywords
16784 'vhdl-optional-labels
16785 'vhdl-insert-empty-lines
16786 'vhdl-argument-list-indent
16787 'vhdl-association-list-with-formals
16788 'vhdl-conditions-in-parenthesis
16789 'vhdl-zero-string
16790 'vhdl-one-string
16791 'vhdl-file-header
16792 'vhdl-file-footer
16793 'vhdl-company-name
16794 'vhdl-copyright-string
16795 'vhdl-platform-spec
16796 'vhdl-date-format
16797 'vhdl-modify-date-prefix-string
16798 'vhdl-modify-date-on-saving
16799 'vhdl-reset-kind
16800 'vhdl-reset-active-high
16801 'vhdl-clock-rising-edge
16802 'vhdl-clock-edge-condition
16803 'vhdl-clock-name
16804 'vhdl-reset-name
16805 'vhdl-model-alist
16806 'vhdl-include-port-comments
16807 'vhdl-include-direction-comments
16808 'vhdl-include-type-comments
16809 'vhdl-include-group-comments
16810 'vhdl-actual-port-name
16811 'vhdl-instance-name
16812 'vhdl-testbench-entity-name
16813 'vhdl-testbench-architecture-name
16814 'vhdl-testbench-configuration-name
16815 'vhdl-testbench-dut-name
16816 'vhdl-testbench-include-header
16817 'vhdl-testbench-declarations
16818 'vhdl-testbench-statements
16819 'vhdl-testbench-initialize-signals
16820 'vhdl-testbench-include-library
16821 'vhdl-testbench-include-configuration
16822 'vhdl-testbench-create-files
0a2e512a
RF
16823 'vhdl-testbench-entity-file-name
16824 'vhdl-testbench-architecture-file-name
3dcb36b7 16825 'vhdl-compose-create-files
0a2e512a
RF
16826 'vhdl-compose-configuration-create-file
16827 'vhdl-compose-configuration-hierarchical
16828 'vhdl-compose-configuration-use-subconfiguration
3dcb36b7
JB
16829 'vhdl-compose-include-header
16830 'vhdl-compose-architecture-name
16831 'vhdl-components-package-name
16832 'vhdl-use-components-package
16833 'vhdl-self-insert-comments
16834 'vhdl-prompt-for-comments
16835 'vhdl-inline-comment-column
16836 'vhdl-end-comment-column
16837 'vhdl-auto-align
16838 'vhdl-align-groups
16839 'vhdl-align-group-separate
16840 'vhdl-align-same-indent
16841 'vhdl-highlight-keywords
16842 'vhdl-highlight-names
16843 'vhdl-highlight-special-words
16844 'vhdl-highlight-forbidden-words
16845 'vhdl-highlight-verilog-keywords
16846 'vhdl-highlight-translate-off
16847 'vhdl-highlight-case-sensitive
16848 'vhdl-special-syntax-alist
16849 'vhdl-forbidden-words
16850 'vhdl-forbidden-syntax
16851 'vhdl-directive-keywords
16852 'vhdl-speedbar-auto-open
16853 'vhdl-speedbar-display-mode
16854 'vhdl-speedbar-scan-limit
16855 'vhdl-speedbar-jump-to-unit
16856 'vhdl-speedbar-update-on-saving
16857 'vhdl-speedbar-save-cache
16858 'vhdl-speedbar-cache-file-name
16859 'vhdl-index-menu
16860 'vhdl-source-file-menu
16861 'vhdl-hideshow-menu
16862 'vhdl-hide-all-init
16863 'vhdl-print-two-column
16864 'vhdl-print-customize-faces
16865 'vhdl-intelligent-tab
16866 'vhdl-indent-syntax-based
16867 'vhdl-word-completion-case-sensitive
16868 'vhdl-word-completion-in-minibuffer
16869 'vhdl-underscore-is-part-of-word
16870 'vhdl-mode-hook)
16871 (function
16872 (lambda ()
16873 (insert
16874 (if vhdl-special-indent-hook
16875 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16876 "vhdl-special-indent-hook is set to '"
16877 (format "%s" vhdl-special-indent-hook)
16878 ".\nPerhaps this is your problem?\n"
16879 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16880 "\n"))))
16881 nil
16882 "Hi Reto,"))))
16883
16884
16885;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16886;;; Documentation
16887;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16888
16889(defconst vhdl-doc-release-notes nil
16890 "\
0a2e512a 16891Release Notes for VHDL Mode 3.33
3dcb36b7
JB
16892================================
16893
16894 - New Features
3dcb36b7 16895 - User Options
3dcb36b7
JB
16896
16897
16898New Features
16899------------
16900
0a2e512a
RF
16901CONFIGURATION DECLARATION GENERATION:
16902 - Automatic generation of a configuration declaration for a design.
16903 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
3dcb36b7
JB
16904
16905
16906User Options
16907------------
16908
0a2e512a
RF
16909`vhdl-configuration-file-name': (new)
16910 Specify how the configuration file name is obtained.
16911`vhdl-compose-configuration-name': (new)
16912 Specify how the configuration name is optained.
16913`vhdl-compose-configuration-create-file': (new)
16914 Specify whether a new file should be created for a configuration.
16915`vhdl-compose-configuration-hierarchical': (new)
16916 Specify whether hierarchical configurations should be created.
16917`vhdl-compose-configuration-use-subconfiguration': (new)
16918 Specify whether subconfigurations should be used inside configurations.
3dcb36b7
JB
16919")
16920
16921
16922(defconst vhdl-doc-keywords nil
16923 "\
16924Reserved words in VHDL
16925----------------------
16926
16927VHDL'93 (IEEE Std 1076-1993):
16928 `vhdl-93-keywords' : keywords
16929 `vhdl-93-types' : standardized types
16930 `vhdl-93-attributes' : standardized attributes
16931 `vhdl-93-enum-values' : standardized enumeration values
16932 `vhdl-93-functions' : standardized functions
16933 `vhdl-93-packages' : standardized packages and libraries
16934
16935VHDL-AMS (IEEE Std 1076.1):
16936 `vhdl-ams-keywords' : keywords
16937 `vhdl-ams-types' : standardized types
16938 `vhdl-ams-attributes' : standardized attributes
16939 `vhdl-ams-enum-values' : standardized enumeration values
16940 `vhdl-ams-functions' : standardized functions
16941
16942Math Packages (IEEE Std 1076.2):
16943 `vhdl-math-types' : standardized types
16944 `vhdl-math-constants' : standardized constants
16945 `vhdl-math-functions' : standardized functions
16946 `vhdl-math-packages' : standardized packages
16947
16948Forbidden words:
16949 `vhdl-verilog-keywords' : Verilog reserved words
16950
16951NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16952
16953
16954(defconst vhdl-doc-coding-style nil
16955 "\
16956For VHDL coding style and naming convention guidelines, see the following
16957references:
16958
16959\[1] Ben Cohen.
16960 \"VHDL Coding Styles and Methodologies\".
16961 Kluwer Academic Publishers, 1999.
16962 http://members.aol.com/vhdlcohen/vhdl/
16963
16964\[2] Michael Keating and Pierre Bricaud.
16965 \"Reuse Methodology Manual, Second Edition\".
16966 Kluwer Academic Publishers, 1999.
16967 http://www.openmore.com/openmore/rmm2.html
16968
16969\[3] European Space Agency.
16970 \"VHDL Modelling Guidelines\".
16971 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16972
16973Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16974to visually support naming conventions.")
16975
16976
d2ddb974
KH
16977(defun vhdl-version ()
16978 "Echo the current version of VHDL Mode in the minibuffer."
16979 (interactive)
3dcb36b7 16980 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
d2ddb974
KH
16981 (vhdl-keep-region-active))
16982
3dcb36b7
JB
16983(defun vhdl-doc-variable (variable)
16984 "Display VARIABLE's documentation in *Help* buffer."
16985 (interactive)
4bcb9c95
SM
16986 (unless vhdl-xemacs
16987 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
0a2e512a
RF
16988 (with-output-to-temp-buffer
16989 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7 16990 (princ (documentation-property variable 'variable-documentation))
4bcb9c95 16991 (with-current-buffer standard-output
3dcb36b7
JB
16992 (help-mode))
16993 (print-help-return-message)))
d2ddb974 16994
3dcb36b7
JB
16995(defun vhdl-doc-mode ()
16996 "Display VHDL Mode documentation in *Help* buffer."
d2ddb974 16997 (interactive)
4bcb9c95
SM
16998 (unless vhdl-xemacs
16999 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
0a2e512a
RF
17000 (with-output-to-temp-buffer
17001 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7
JB
17002 (princ mode-name)
17003 (princ " mode:\n")
17004 (princ (documentation 'vhdl-mode))
4bcb9c95 17005 (with-current-buffer standard-output
3dcb36b7
JB
17006 (help-mode))
17007 (print-help-return-message)))
d2ddb974
KH
17008
17009
5eabfe72 17010;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
17011
17012(provide 'vhdl-mode)
17013
4bcb9c95 17014;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
d2ddb974 17015;;; vhdl-mode.el ends here