* configure.in: Don't double machfile in final message.
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
CommitLineData
d2ddb974
KH
1;;; vhdl-mode.el --- major mode for editing VHDL code
2
c9c18440 3;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
114f9c96 4;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
051897ff 5;; Free Software Foundation, Inc.
3dcb36b7
JB
6
7;; Authors: Reto Zimmermann <reto@gnu.org>
8;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
0a2e512a 9;; Maintainer: Reto Zimmermann <reto@gnu.org>
5eabfe72 10;; Keywords: languages vhdl
c9c18440 11;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
3dcb36b7 12
241760a3
SM
13;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
14;; file on 18/3/2008, and the maintainer agreed that when a bug is
15;; filed in the Emacs bug reporting system against this file, a copy
16;; of the bug report be sent to the maintainer's email address.
17
0a2e512a 18(defconst vhdl-version "3.33.6"
3dcb36b7
JB
19 "VHDL Mode version number.")
20
0a2e512a 21(defconst vhdl-time-stamp "2005-08-30"
3dcb36b7 22 "VHDL Mode time stamp for last update.")
d2ddb974
KH
23
24;; This file is part of GNU Emacs.
25
b1fc2b50 26;; GNU Emacs is free software: you can redistribute it and/or modify
d2ddb974 27;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
28;; the Free Software Foundation, either version 3 of the License, or
29;; (at your option) any later version.
d2ddb974
KH
30
31;; GNU Emacs is distributed in the hope that it will be useful,
32;; but WITHOUT ANY WARRANTY; without even the implied warranty of
33;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34;; GNU General Public License for more details.
35
36;; You should have received a copy of the GNU General Public License
b1fc2b50 37;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
d2ddb974 38
5eabfe72 39;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 40;;; Commentary:
5eabfe72 41;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
42
43;; This package provides an Emacs major mode for editing VHDL code.
44;; It includes the following features:
45
3dcb36b7
JB
46;; - Syntax highlighting
47;; - Indentation
48;; - Template insertion (electrification)
49;; - Insertion of file headers
5eabfe72 50;; - Insertion of user-specified models
3dcb36b7 51;; - Port translation / testbench generation
0a2e512a
RF
52;; - Structural composition
53;; - Configuration generation
3dcb36b7
JB
54;; - Sensitivity list updating
55;; - File browser
56;; - Design hierarchy browser
d2ddb974 57;; - Source file compilation (syntax analysis)
3dcb36b7
JB
58;; - Makefile generation
59;; - Code hiding
60;; - Word/keyword completion
61;; - Block commenting
62;; - Code fixing/alignment/beautification
63;; - Postscript printing
5eabfe72 64;; - VHDL'87/'93 and VHDL-AMS supported
3dcb36b7 65;; - Comprehensive menu
5eabfe72 66;; - Fully customizable
3dcb36b7 67;; - Works under GNU Emacs (recommended) and XEmacs
5eabfe72
KH
68
69;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 70;; Documentation
d2ddb974 71
3dcb36b7 72;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
d2ddb974 73
5eabfe72 74;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 75;; Emacs Versions
3dcb36b7 76
9e5538bc 77;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
3dcb36b7
JB
78;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
79
5eabfe72 80;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
81;; Installation
82
9e5538bc 83;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
3dcb36b7
JB
84
85;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
86;; or into an arbitrary directory that is added to the load path by the
87;; following line in your Emacs start-up file `.emacs':
88
89;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
d2ddb974 90
3dcb36b7
JB
91;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
92;; directory. Otherwise, byte-compile the source file:
93;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
94;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
95
96;; Add the following lines to the `site-start.el' file in the `site-lisp'
97;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
98;; (not required in Emacs 20.X):
99
100;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
101;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
102
103;; More detailed installation instructions are included in the official
104;; VHDL Mode distribution.
d2ddb974 105
5eabfe72 106;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 107;; Acknowledgements
d2ddb974
KH
108
109;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
5eabfe72 110;; and Steve Grout.
d2ddb974 111
5eabfe72 112;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
3dcb36b7 113;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
d2ddb974
KH
114
115;; Many thanks to all the users who sent me bug reports and enhancement
3dcb36b7
JB
116;; requests.
117;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
118;; enhancement suggestions and the fruitful discussions.
5eabfe72
KH
119;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
120;; Thanks to Ulf Klaperski for the indentation speedup hint.
121
122;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
123;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
124;; giving me the opportunity to develop this code.
125;; This work has been funded in part by MICROSWISS, a Microelectronics Program
126;; of the Swiss Government.
127
3dcb36b7 128;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
129
130;;; Code:
131
9e5538bc 132;; Emacs 21+ handling
f8246027 133(defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
0a2e512a 134 "Non-nil if GNU Emacs 21, 22, ... is used.")
f8246027 135(defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
0a2e512a 136 "Non-nil if GNU Emacs 22, ... is used.")
3dcb36b7 137
354617b5 138(defvar compilation-file-regexp-alist)
84c98ace
JB
139(defvar conf-alist)
140(defvar conf-entry)
141(defvar conf-key)
142(defvar ent-alist)
354617b5
JB
143(defvar itimer-version)
144(defvar lazy-lock-defer-contextually)
145(defvar lazy-lock-defer-on-scrolling)
146(defvar lazy-lock-defer-on-the-fly)
7bf42457
JB
147(defvar speedbar-attached-frame)
148
354617b5 149
5eabfe72
KH
150;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151;;; Variables
152;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 153
3dcb36b7 154;; help function for user options
5eabfe72
KH
155(defun vhdl-custom-set (variable value &rest functions)
156 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
157 (if (fboundp 'custom-set-default)
158 (custom-set-default variable value)
159 (set-default variable value))
160 (while functions
161 (when (fboundp (car functions)) (funcall (car functions)))
162 (setq functions (cdr functions))))
163
3dcb36b7
JB
164(defun vhdl-widget-directory-validate (widget)
165 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
166'/' or is empty)."
167 (let ((val (widget-value widget)))
168 (unless (string-match "^\\(\\|.*/\\)$" val)
169 (widget-put widget :error "Invalid directory entry: must end with '/'")
170 widget)))
171
172;; help string for user options
173(defconst vhdl-name-doc-string "
174
175FROM REGEXP is a regular expression matching the original name:
176 \".*\" matches the entire string
177 \"\\(...\\)\" matches a substring
178TO STRING specifies the string to be inserted as new name:
179 \"\\&\" means substitute entire matched text
180 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
181Examples:
182 \".*\" \"\\&\" inserts original string
183 \".*\" \"\\&_i\" attaches \"_i\" to original string
184 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
185 \".*\" \"foo\" inserts constant string \"foo\"
186 \".*\" \"\" inserts empty string")
187
5eabfe72
KH
188;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189;; User variables
d2ddb974
KH
190
191(defgroup vhdl nil
192 "Customizations for VHDL Mode."
193 :prefix "vhdl-"
42dfe0ad 194 :group 'languages
0a2e512a 195; :version "21.2" ; comment out for XEmacs
5eabfe72 196 )
d2ddb974
KH
197
198(defgroup vhdl-mode nil
199 "Customizations for modes."
200 :group 'vhdl)
201
5eabfe72
KH
202(defcustom vhdl-indent-tabs-mode nil
203 "*Non-nil means indentation can insert tabs.
d2ddb974
KH
204Overrides local variable `indent-tabs-mode'."
205 :type 'boolean
206 :group 'vhdl-mode)
207
208
209(defgroup vhdl-compile nil
210 "Customizations for compilation."
211 :group 'vhdl)
212
5eabfe72
KH
213(defcustom vhdl-compiler-alist
214 '(
3dcb36b7 215 ;; Cadence Leapfrog: cv -file test.vhd
5eabfe72 216 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
3dcb36b7
JB
217 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
218 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
219 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
220 ("\\1/entity" "\\2/\\1" "\\1/configuration"
221 "\\1/package" "\\1/body" downcase))
222 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
223 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
224 ;; (PLL_400X_TOP) is not declared [10.3].
225 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
226 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
227 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
0a2e512a
RF
228 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
229 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
5eabfe72 230 ;; Ikos Voyager: analyze test.vhd
3dcb36b7 231 ;; analyze test.vhd
5eabfe72 232 ;; E L4/C5: this library unit is inaccessible
3dcb36b7
JB
233 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
234 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
235 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
236 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
237 nil)
5eabfe72
KH
238 ;; ModelSim, Model Technology: vcom test.vhd
239 ;; ERROR: test.vhd(14): Unknown identifier: positiv
240 ;; WARNING[2]: test.vhd(85): Possible infinite loop
3dcb36b7
JB
241 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
242 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
243 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
244 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
245 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
246 "\\1/_primary.dat" "\\1/body.dat" downcase))
247 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
248 ;; test.vhd:34: error message
249 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
250 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
251 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
252 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
253 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
5eabfe72
KH
254 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
255 ;; ERROR: test.vhd(24): near "dnd": expecting: END
256 ;; WARNING[4]: test.vhd(30): A space is required between ...
3dcb36b7
JB
257 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
258 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
259 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
260 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
261 "\\1/_primary.dat" "\\1/body.dat" downcase))
262 ;; Savant: scram -publish-cc test.vhd
263 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
264 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
265 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
266 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
267 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
268 "\\1_config.vhdl" "\\1_package.vhdl"
269 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
270 ;; Simili: vhdlp -work test.vhd
271 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
272 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
273 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
274 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
275 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
276 "\\1/prim.var" "\\1/_body.var" downcase))
277 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
278 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
279 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
280 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
281 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
282 nil)
283 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
5eabfe72 284 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
3dcb36b7
JB
285 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
286 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
287 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
288 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
289 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
290 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
291 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
292 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
293 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
294 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
295 ;; Synplify:
296 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
297 ("Synplify" "n/a" "n/a" "make" "-f \\1"
298 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
299 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
300 nil)
5eabfe72 301 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
302 ;; Compiling "test.vhd" line 1...
303 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
304 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
305 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
306 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
307 ("^ *Compiling \"\\(.+\\)\" " 1)
308 nil)
309 ;; VeriBest: vc vhdl test.vhd
310 ;; (no file name printed out!)
311 ;; 32: Z <= A and BitA ;
312 ;; ^^^^
313 ;; [Error] Name BITA is unknown
314 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
315 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
316 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
317 nil)
5eabfe72 318 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
319 ;; Compiling "test.vhd" line 1...
320 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
321 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
322 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
323 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
324 ("^ *Compiling \"\\(.+\\)\" " 1)
325 nil)
5eabfe72
KH
326 )
327 "*List of available VHDL compilers and their properties.
328Each list entry specifies the following items for a compiler:
329Compiler:
3dcb36b7
JB
330 Compiler name : name used in option `vhdl-compiler' to choose compiler
331 Compile command : command used for source file compilation
332 Compile options : compile options (\"\\1\" inserts library name)
333 Make command : command used for compilation using a Makefile
334 Make options : make options (\"\\1\" inserts Makefile name)
335 Generate Makefile: use built-in function or command to generate a Makefile
336 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
337 Library command : command to create library directory \(\"\\1\" inserts
338 library directory, \"\\2\" inserts library name)
339 Compile directory: where compilation is run and the Makefile is placed
340 Library directory: directory of default library
341 Makefile name : name of Makefile (default is \"Makefile\")
342 ID string : compiler identification string (see `vhdl-project-alist')
343Error message:
0a2e512a 344 Regexp : regular expression to match error messages (*)
3dcb36b7
JB
345 File subexp index: index of subexpression that matches the file name
346 Line subexp index: index of subexpression that matches the line number
347 Column subexp idx: index of subexpression that matches the column number
348File message:
5eabfe72 349 Regexp : regular expression to match a file name message
3dcb36b7
JB
350 File subexp index: index of subexpression that matches the file name
351Unit-to-file name mapping: mapping of library unit names to names of files
352 generated by the compiler (used for Makefile generation)
353 To string : string a name is mapped to (\"\\1\" inserts the unit name,
354 \"\\2\" inserts the entity name for architectures)
355 Case adjustment : adjust case of inserted unit names
356
0a2e512a 357\(*) The regular expression must match the error message starting from the
84c98ace 358 beginning of the line (but not necessarily to the end of the line).
0a2e512a 359
3dcb36b7
JB
360Compile options allows insertion of the library name (see `vhdl-project-alist')
361in order to set the compilers library option (e.g. \"vcom -work my_lib\").
362
363For Makefile generation, the built-in function can be used (requires
364specification of the unit-to-file name mapping). Alternatively, an
365external command can be specified. Work directory allows specification of
366an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
367used for Makefile generation). To use another library name than \"work\",
368customize `vhdl-project-alist'. The library command is inserted in Makefiles
369to automatically create the library directory if not existent.
370
371Compile options, compile directory, library directory, and Makefile name are
372overwritten by the project settings if a project is defined (see
373`vhdl-project-alist'). Directory paths are relative to the source file
374directory.
5eabfe72
KH
375
376Some compilers do not include the file name in the error message, but print
377out a file name message in advance. In this case, set \"File Subexp Index\"
3dcb36b7
JB
378under \"Error Message\" to 0 and fill out the \"File Message\" entries.
379If no file name at all is printed out, set both \"File Message\" entries to 0
380\(a default file name message will be printed out instead, does not work in
381XEmacs).
5eabfe72
KH
382
383A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
3dcb36b7 384assigning its name to option `vhdl-compiler'.
5eabfe72 385
3dcb36b7
JB
386Please send any missing or erroneous compiler properties to the maintainer for
387updating.
388
0a2e512a
RF
389NOTE: Activate new error and file message regexps and reflect the new setting
390 in the choice list of option `vhdl-compiler' by restarting Emacs."
3dcb36b7
JB
391 :type '(repeat
392 (list :tag "Compiler" :indent 2
393 (string :tag "Compiler name ")
394 (string :tag "Compile command ")
395 (string :tag "Compile options " "-work \\1")
396 (string :tag "Make command " "make")
397 (string :tag "Make options " "-f \\1")
398 (choice :tag "Generate Makefile "
399 (const :tag "Built-in function" nil)
400 (string :tag "Command" "vmake \\2 > \\1"))
401 (string :tag "Library command " "mkdir \\1")
402 (directory :tag "Compile directory "
403 :validate vhdl-widget-directory-validate "./")
404 (directory :tag "Library directory "
405 :validate vhdl-widget-directory-validate "work/")
406 (file :tag "Makefile name " "Makefile")
407 (string :tag "ID string ")
408 (list :tag "Error message" :indent 4
409 (regexp :tag "Regexp ")
410 (integer :tag "File subexp index")
411 (integer :tag "Line subexp index")
412 (integer :tag "Column subexp idx"))
413 (list :tag "File message" :indent 4
414 (regexp :tag "Regexp ")
415 (integer :tag "File subexp index"))
416 (choice :tag "Unit-to-file name mapping"
417 :format "%t: %[Value Menu%] %v\n"
418 (const :tag "Not defined" nil)
419 (list :tag "To string" :indent 4
420 (string :tag "Entity " "\\1.vhd")
421 (string :tag "Architecture " "\\2_\\1.vhd")
422 (string :tag "Configuration " "\\1.vhd")
423 (string :tag "Package " "\\1.vhd")
424 (string :tag "Package Body " "\\1_body.vhd")
425 (choice :tag "Case adjustment "
426 (const :tag "None" identity)
427 (const :tag "Upcase" upcase)
428 (const :tag "Downcase" downcase))))))
5eabfe72 429 :set (lambda (variable value)
0a2e512a 430 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
5eabfe72
KH
431 :group 'vhdl-compile)
432
433(defcustom vhdl-compiler "ModelSim"
434 "*Specifies the VHDL compiler to be used for syntax analysis.
3dcb36b7
JB
435Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
436 :type (let ((alist vhdl-compiler-alist) list)
437 (while alist
438 (setq list (cons (list 'const (caar alist)) list))
439 (setq alist (cdr alist)))
440 (append '(choice) (nreverse list)))
441 :group 'vhdl-compile)
442
443(defcustom vhdl-compile-use-local-error-regexp t
444 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
445In this case, only error message regexps for VHDL compilers are active if
446compilation is started from a VHDL buffer. Otherwise, the error message
447regexps are appended to the predefined global regexps, and all regexps are
448active all the time. Note that by doing that, the predefined global regexps
449might result in erroneous parsing of error messages for some VHDL compilers.
450
451NOTE: Activate the new setting by restarting Emacs."
452 :type 'boolean
d2ddb974
KH
453 :group 'vhdl-compile)
454
3dcb36b7
JB
455(defcustom vhdl-makefile-generation-hook nil
456 "*Functions to run at the end of Makefile generation.
457Allows to insert user specific parts into a Makefile.
458
459Example:
460 \(lambda nil
461 \(re-search-backward \"^# Rule for compiling entire design\")
462 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
463 :type 'hook
464 :group 'vhdl-compile)
465
466(defcustom vhdl-default-library "work"
467 "*Name of default library.
468Is overwritten by project settings if a project is active."
d2ddb974
KH
469 :type 'string
470 :group 'vhdl-compile)
471
472
3dcb36b7
JB
473(defgroup vhdl-project nil
474 "Customizations for projects."
d2ddb974
KH
475 :group 'vhdl)
476
3dcb36b7
JB
477(defcustom vhdl-project-alist
478 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
479 "~/example1/" ("src/system/" "src/components/") ""
480 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
481 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
482 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
483 ("Example 2" "Individual source files, multiple compilers in different directories"
484 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
485 nil "\\1/" "work" "\\1/work/" "Makefile" "")
486 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
487 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
488 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
489-------------------------------------------------------------------------------
490-- This is a multi-line project description
491-- that can be used as a project dependent part of the file header.
492"))
493 "*List of projects and their properties.
494 Name : name used in option `vhdl-project' to choose project
495 Title : title of project (single-line string)
496 Default directory: default project directory (absolute path)
497 Sources : a) source files : path + \"/\" + file name
498 b) directory : path + \"/\"
499 c) directory tree: \"-r \" + path + \"/\"
500 Exclude regexp : matches file/directory names to be excluded as sources
501 Compile options : project-specific options for each compiler
502 Compiler name : name of compiler for which these options are valid
503 Compile options: project-specific compiler options
504 (\"\\1\" inserts library name, \"\\2\" default options)
505 Make options: project-specific make options
506 (\"\\1\" inserts Makefile name, \"\\2\" default options)
507 Exceptions : file-specific exceptions
508 File name regexp: matches file names for which exceptions are valid
509 - Options : file-specific compiler options string
510 (\"\\1\" inserts library name, \"\\2\" default options,
511 \"\\3\" project-specific options)
512 - Do not compile: do not compile this file (in Makefile)
513 Compile directory: where compilation is run and the Makefile is placed
514 \(\"\\1\" inserts compiler ID string)
515 Library name : name of library (default is \"work\")
516 Library directory: path to library (\"\\1\" inserts compiler ID string)
517 Makefile name : name of Makefile
518 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
519 Description : description of project (multi-line string)
520
521Project title and description are used to insert into the file header (see
522option `vhdl-file-header').
523
524The default directory must have an absolute path (use `M-TAB' for completion).
525All other paths can be absolute or relative to the default directory. All
526paths must end with '/'.
527
528The design units found in the sources (files and directories) are shown in the
529hierarchy browser. Path and file name can contain wildcards `*' and `?' as
530well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
531Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
532specified, the default directory is taken as source directory. Otherwise,
533the default directory is only taken as source directory if there is a sources
534entry with the empty string or \"./\". Exclude regexp allows to filter out
535specific file and directory names from the list of sources (e.g. CVS
536directories).
537
538Files are compiled in the compile directory. Makefiles are also placed into
539the compile directory. Library directory specifies which directory the
540compiler compiles into (used to generate the Makefile).
541
542Since different compile/library directories and Makefiles may exist for
543different compilers within one project, these paths and names allow the
544insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
545Compile options, compile directory, library directory, and Makefile name
546overwrite the settings of the current compiler.
547
548File-specific compiler options (highest priority) overwrite project-specific
549options which overwrite default options (lowest priority). Lower priority
550options can be inserted in higher priority options. This allows to reuse
551default options (e.g. \"-file\") in project- or file-specific options (e.g.
552\"-93 -file\").
553
554NOTE: Reflect the new setting in the choice list of option `vhdl-project'
555 by restarting Emacs."
556 :type `(repeat
557 (list :tag "Project" :indent 2
558 (string :tag "Name ")
559 (string :tag "Title ")
560 (directory :tag "Default directory"
561 :validate vhdl-widget-directory-validate
562 ,(abbreviate-file-name default-directory))
563 (repeat :tag "Sources " :indent 4
564 (directory :format " %v" "./"))
565 (regexp :tag "Exclude regexp ")
566 (repeat
567 :tag "Compile options " :indent 4
568 (list :tag "Compiler" :indent 6
569 ,(let ((alist vhdl-compiler-alist) list)
570 (while alist
571 (setq list (cons (list 'const (caar alist)) list))
572 (setq alist (cdr alist)))
573 (append '(choice :tag "Compiler name")
574 (nreverse list)))
575 (string :tag "Compile options" "\\2")
576 (string :tag "Make options " "\\2")
577 (repeat
578 :tag "Exceptions " :indent 8
579 (cons :format "%v"
580 (regexp :tag "File name regexp ")
581 (choice :format "%[Value Menu%] %v"
582 (string :tag "Options" "\\3")
583 (const :tag "Do not compile" nil))))))
584 (directory :tag "Compile directory"
585 :validate vhdl-widget-directory-validate "./")
586 (string :tag "Library name " "work")
587 (directory :tag "Library directory"
588 :validate vhdl-widget-directory-validate "work/")
589 (file :tag "Makefile name " "Makefile")
590 (string :tag "Description: (type `C-j' for newline)"
591 :format "%t\n%v\n")))
592 :set (lambda (variable value)
0a2e512a 593 (vhdl-custom-set variable value
3dcb36b7
JB
594 'vhdl-update-mode-menu
595 'vhdl-speedbar-refresh))
596 :group 'vhdl-project)
597
598(defcustom vhdl-project nil
599 "*Specifies the default for the current project.
600Select a project name from the ones defined in option `vhdl-project-alist'.
601Is used to determine the project title and description to be inserted in file
602headers and the source files/directories to be scanned in the hierarchy
603browser. The current project can also be changed temporarily in the menu."
604 :type (let ((alist vhdl-project-alist) list)
605 (while alist
606 (setq list (cons (list 'const (caar alist)) list))
607 (setq alist (cdr alist)))
608 (append '(choice (const :tag "None" nil) (const :tag "--"))
609 (nreverse list)))
610 :group 'vhdl-project)
611
612(defcustom vhdl-project-file-name '("\\1.prj")
613 "*List of file names/paths for importing/exporting project setups.
614\"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
615replaced by the user name (allows to have user-specific project setups).
616The first entry is used as file name to import/export individual project
617setups. All entries are used to automatically import project setups at
618startup (see option `vhdl-project-auto-load'). Projects loaded from the
619first entry are automatically made current. Hint: specify local project
620setups in first entry, global setups in following entries; loading a local
621project setup will make it current, while loading the global setups
622is done without changing the current project.
623Names can also have an absolute path (i.e. project setups can be stored
624in global directories)."
625 :type '(repeat (string :tag "File name" "\\1.prj"))
626 :group 'vhdl-project)
627
628(defcustom vhdl-project-auto-load '(startup)
629 "*Automatically load project setups from files.
630All project setup files that match the file names specified in option
631`vhdl-project-file-name' are automatically loaded. The project of the
632\(alphabetically) last loaded setup of the first `vhdl-project-file-name'
633entry is activated.
634A project setup file can be obtained by exporting a project (see menu).
635 At startup: project setup file is loaded at Emacs startup"
636 :type '(set (const :tag "At startup" startup))
637 :group 'vhdl-project)
638
639(defcustom vhdl-project-sort t
640 "*Non-nil means projects are displayed in alphabetical order."
641 :type 'boolean
642 :group 'vhdl-project)
643
644
645(defgroup vhdl-style nil
646 "Customizations for coding styles."
647 :group 'vhdl
648 :group 'vhdl-template
649 :group 'vhdl-port
650 :group 'vhdl-compose)
651
5eabfe72
KH
652(defcustom vhdl-standard '(87 nil)
653 "*VHDL standards used.
654Basic standard:
655 VHDL'87 : IEEE Std 1076-1987
656 VHDL'93 : IEEE Std 1076-1993
657Additional standards:
658 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
3dcb36b7 659 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
5eabfe72 660
3dcb36b7
JB
661NOTE: Activate the new setting in a VHDL buffer by using the menu entry
662 \"Activate Options\"."
5eabfe72
KH
663 :type '(list (choice :tag "Basic standard"
664 (const :tag "VHDL'87" 87)
665 (const :tag "VHDL'93" 93))
666 (set :tag "Additional standards" :indent 2
667 (const :tag "VHDL-AMS" ams)
3dcb36b7 668 (const :tag "Math packages" math)))
5eabfe72 669 :set (lambda (variable value)
0a2e512a 670 (vhdl-custom-set variable value
5eabfe72
KH
671 'vhdl-template-map-init
672 'vhdl-mode-abbrev-table-init
673 'vhdl-template-construct-alist-init
674 'vhdl-template-package-alist-init
675 'vhdl-update-mode-menu
676 'vhdl-words-init 'vhdl-font-lock-init))
677 :group 'vhdl-style)
678
679(defcustom vhdl-basic-offset 2
d2ddb974
KH
680 "*Amount of basic offset used for indentation.
681This value is used by + and - symbols in `vhdl-offsets-alist'."
682 :type 'integer
683 :group 'vhdl-style)
684
d2ddb974 685(defcustom vhdl-upper-case-keywords nil
5eabfe72
KH
686 "*Non-nil means convert keywords to upper case.
687This is done when typed or expanded or by the fix case functions."
d2ddb974 688 :type 'boolean
5eabfe72 689 :set (lambda (variable value)
0a2e512a 690 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 691 :group 'vhdl-style)
d2ddb974
KH
692
693(defcustom vhdl-upper-case-types nil
5eabfe72
KH
694 "*Non-nil means convert standardized types to upper case.
695This is done when expanded or by the fix case functions."
d2ddb974 696 :type 'boolean
5eabfe72 697 :set (lambda (variable value)
0a2e512a 698 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 699 :group 'vhdl-style)
d2ddb974
KH
700
701(defcustom vhdl-upper-case-attributes nil
5eabfe72
KH
702 "*Non-nil means convert standardized attributes to upper case.
703This is done when expanded or by the fix case functions."
d2ddb974 704 :type 'boolean
5eabfe72 705 :set (lambda (variable value)
0a2e512a 706 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 707 :group 'vhdl-style)
d2ddb974
KH
708
709(defcustom vhdl-upper-case-enum-values nil
5eabfe72
KH
710 "*Non-nil means convert standardized enumeration values to upper case.
711This is done when expanded or by the fix case functions."
d2ddb974 712 :type 'boolean
5eabfe72 713 :set (lambda (variable value)
0a2e512a 714 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72
KH
715 :group 'vhdl-style)
716
717(defcustom vhdl-upper-case-constants t
718 "*Non-nil means convert standardized constants to upper case.
719This is done when expanded."
720 :type 'boolean
721 :set (lambda (variable value)
0a2e512a 722 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 723 :group 'vhdl-style)
d2ddb974 724
3dcb36b7
JB
725(defcustom vhdl-use-direct-instantiation 'standard
726 "*Non-nil means use VHDL'93 direct component instantiation.
727 Never : never
728 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
729 Always : always"
730 :type '(choice (const :tag "Never" never)
731 (const :tag "Standard" standard)
732 (const :tag "Always" always))
733 :group 'vhdl-style)
734
735
736(defgroup vhdl-naming nil
737 "Customizations for naming conventions."
738 :group 'vhdl)
739
740(defcustom vhdl-entity-file-name '(".*" . "\\&")
741 (concat
742 "*Specifies how the entity file name is obtained.
743The entity file name can be obtained by modifying the entity name (e.g.
744attaching or stripping off a substring). The file extension is automatically
745taken from the file name of the current buffer."
746 vhdl-name-doc-string)
747 :type '(cons (regexp :tag "From regexp")
748 (string :tag "To string "))
749 :group 'vhdl-naming
750 :group 'vhdl-compose)
d2ddb974 751
3dcb36b7
JB
752(defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
753 (concat
754 "*Specifies how the architecture file name is obtained.
755The architecture file name can be obtained by modifying the entity
756and/or architecture name (e.g. attaching or stripping off a substring). The
0a2e512a
RF
757file extension is automatically taken from the file name of the current
758buffer. The string that is matched against the regexp is the concatenation
759of the entity and the architecture name separated by a space. This gives
760access to both names (see default setting as example)."
761 vhdl-name-doc-string)
762 :type '(cons (regexp :tag "From regexp")
763 (string :tag "To string "))
764 :group 'vhdl-naming
765 :group 'vhdl-compose)
766
767(defcustom vhdl-configuration-file-name '(".*" . "\\&")
768 (concat
769 "*Specifies how the configuration file name is obtained.
770The configuration file name can be obtained by modifying the configuration
771name (e.g. attaching or stripping off a substring). The file extension is
772automatically taken from the file name of the current buffer."
3dcb36b7
JB
773 vhdl-name-doc-string)
774 :type '(cons (regexp :tag "From regexp")
775 (string :tag "To string "))
776 :group 'vhdl-naming
777 :group 'vhdl-compose)
778
779(defcustom vhdl-package-file-name '(".*" . "\\&")
780 (concat
781 "*Specifies how the package file name is obtained.
782The package file name can be obtained by modifying the package name (e.g.
783attaching or stripping off a substring). The file extension is automatically
0a2e512a
RF
784taken from the file name of the current buffer. Package files can be created
785in a different directory by prepending a relative or absolute path to the
786file name."
3dcb36b7
JB
787 vhdl-name-doc-string)
788 :type '(cons (regexp :tag "From regexp")
789 (string :tag "To string "))
790 :group 'vhdl-naming
791 :group 'vhdl-compose)
792
793(defcustom vhdl-file-name-case 'identity
794 "*Specifies how to change case for obtaining file names.
795When deriving a file name from a VHDL unit name, case can be changed as
796follows:
797 As Is: case is not changed (taken as is)
798 Lower Case: whole name is changed to lower case
799 Upper Case: whole name is changed to upper case
800 Capitalize: first letter of each word in name is capitalized"
801 :type '(choice (const :tag "As Is" identity)
802 (const :tag "Lower Case" downcase)
803 (const :tag "Upper Case" upcase)
804 (const :tag "Capitalize" capitalize))
805 :group 'vhdl-naming
806 :group 'vhdl-compose)
807
808
809(defgroup vhdl-template nil
5eabfe72 810 "Customizations for electrification."
d2ddb974
KH
811 :group 'vhdl)
812
5eabfe72
KH
813(defcustom vhdl-electric-keywords '(vhdl user)
814 "*Type of keywords for which electrification is enabled.
815 VHDL keywords: invoke built-in templates
3dcb36b7 816 User keywords: invoke user models (see option `vhdl-model-alist')"
5eabfe72 817 :type '(set (const :tag "VHDL keywords" vhdl)
3dcb36b7 818 (const :tag "User model keywords" user))
5eabfe72 819 :set (lambda (variable value)
0a2e512a 820 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
3dcb36b7 821 :group 'vhdl-template)
5eabfe72
KH
822
823(defcustom vhdl-optional-labels 'process
824 "*Constructs for which labels are to be queried.
825Template generators prompt for optional labels for:
826 None : no constructs
827 Processes only: processes only (also procedurals in VHDL-AMS)
828 All constructs: all constructs with optional labels and keyword END"
829 :type '(choice (const :tag "None" none)
830 (const :tag "Processes only" process)
831 (const :tag "All constructs" all))
3dcb36b7 832 :group 'vhdl-template)
d2ddb974 833
5eabfe72
KH
834(defcustom vhdl-insert-empty-lines 'unit
835 "*Specifies whether to insert empty lines in some templates.
836This improves readability of code. Empty lines are inserted in:
837 None : no constructs
838 Design units only: entities, architectures, configurations, packages only
839 All constructs : also all constructs with BEGIN...END parts
840
3dcb36b7 841Replaces option `vhdl-additional-empty-lines'."
5eabfe72
KH
842 :type '(choice (const :tag "None" none)
843 (const :tag "Design units only" unit)
844 (const :tag "All constructs" all))
3dcb36b7
JB
845 :group 'vhdl-template
846 :group 'vhdl-port
847 :group 'vhdl-compose)
5eabfe72
KH
848
849(defcustom vhdl-argument-list-indent nil
850 "*Non-nil means indent argument lists relative to opening parenthesis.
851That is, argument, association, and port lists start on the same line as the
852opening parenthesis and subsequent lines are indented accordingly.
853Otherwise, lists start on a new line and are indented as normal code."
d2ddb974 854 :type 'boolean
3dcb36b7
JB
855 :group 'vhdl-template
856 :group 'vhdl-port
857 :group 'vhdl-compose)
d2ddb974 858
5eabfe72
KH
859(defcustom vhdl-association-list-with-formals t
860 "*Non-nil means write association lists with formal parameters.
3dcb36b7
JB
861Templates prompt for formal and actual parameters (ports/generics).
862When pasting component instantiations, formals are included.
5eabfe72 863If nil, only a list of actual parameters is entered."
d2ddb974 864 :type 'boolean
3dcb36b7
JB
865 :group 'vhdl-template
866 :group 'vhdl-port
867 :group 'vhdl-compose)
d2ddb974
KH
868
869(defcustom vhdl-conditions-in-parenthesis nil
5eabfe72 870 "*Non-nil means place parenthesis around condition expressions."
d2ddb974 871 :type 'boolean
3dcb36b7 872 :group 'vhdl-template)
d2ddb974 873
5eabfe72
KH
874(defcustom vhdl-zero-string "'0'"
875 "*String to use for a logic zero."
876 :type 'string
3dcb36b7 877 :group 'vhdl-template)
5eabfe72
KH
878
879(defcustom vhdl-one-string "'1'"
880 "*String to use for a logic one."
881 :type 'string
3dcb36b7 882 :group 'vhdl-template)
5eabfe72
KH
883
884
885(defgroup vhdl-header nil
886 "Customizations for file header."
3dcb36b7
JB
887 :group 'vhdl-template
888 :group 'vhdl-compose)
d2ddb974 889
5eabfe72
KH
890(defcustom vhdl-file-header "\
891-------------------------------------------------------------------------------
892-- Title : <title string>
893-- Project : <project>
894-------------------------------------------------------------------------------
895-- File : <filename>
896-- Author : <author>
897-- Company : <company>
3dcb36b7 898-- Created : <date>
5eabfe72
KH
899-- Last update: <date>
900-- Platform : <platform>
3dcb36b7 901-- Standard : <standard>
5eabfe72
KH
902<projectdesc>-------------------------------------------------------------------------------
903-- Description: <cursor>
3dcb36b7 904<copyright>-------------------------------------------------------------------------------
5eabfe72
KH
905-- Revisions :
906-- Date Version Author Description
907-- <date> 1.0 <login>\tCreated
908-------------------------------------------------------------------------------
909
910"
911 "*String or file to insert as file header.
912If the string specifies an existing file name, the contents of the file is
913inserted, otherwise the string itself is inserted as file header.
914Type `C-j' for newlines.
d2ddb974
KH
915If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
916if the header needs to be version controlled.
917
918The following keywords for template generation are supported:
3dcb36b7
JB
919 <filename> : replaced by the name of the buffer
920 <author> : replaced by the user name and email address
8fc29035 921 \(`user-full-name', `mail-host-address', `user-mail-address')
3dcb36b7
JB
922 <login> : replaced by user login name (`user-login-name')
923 <company> : replaced by contents of option `vhdl-company-name'
924 <date> : replaced by the current date
925 <year> : replaced by the current year
926 <project> : replaced by title of current project (`vhdl-project')
927 <projectdesc> : replaced by description of current project (`vhdl-project')
928 <copyright> : replaced by copyright string (`vhdl-copyright-string')
929 <platform> : replaced by contents of option `vhdl-platform-spec'
930 <standard> : replaced by the VHDL language standard(s) used
931 <... string> : replaced by a queried string (\"...\" is the prompt word)
932 <title string>: replaced by file title in automatically generated files
933 <cursor> : final cursor position
d2ddb974 934
5eabfe72
KH
935The (multi-line) project description <projectdesc> can be used as a project
936dependent part of the file header and can also contain the above keywords."
937 :type 'string
938 :group 'vhdl-header)
939
940(defcustom vhdl-file-footer ""
941 "*String or file to insert as file footer.
942If the string specifies an existing file name, the contents of the file is
943inserted, otherwise the string itself is inserted as file footer (i.e. at
944the end of the file).
3dcb36b7
JB
945Type `C-j' for newlines.
946The same keywords as in option `vhdl-file-header' can be used."
5eabfe72
KH
947 :type 'string
948 :group 'vhdl-header)
949
950(defcustom vhdl-company-name ""
3dcb36b7
JB
951 "*Name of company to insert in file header.
952See option `vhdl-file-header'."
953 :type 'string
954 :group 'vhdl-header)
955
956(defcustom vhdl-copyright-string "\
957-------------------------------------------------------------------------------
958-- Copyright (c) <year> <company>
959"
960 "*Copyright string to insert in file header.
961Can be multi-line string (type `C-j' for newline) and contain other file
962header keywords (see option `vhdl-file-header')."
5eabfe72
KH
963 :type 'string
964 :group 'vhdl-header)
965
966(defcustom vhdl-platform-spec ""
967 "*Specification of VHDL platform to insert in file header.
968The platform specification should contain names and versions of the
3dcb36b7
JB
969simulation and synthesis tools used.
970See option `vhdl-file-header'."
5eabfe72
KH
971 :type 'string
972 :group 'vhdl-header)
973
3dcb36b7 974(defcustom vhdl-date-format "%Y-%m-%d"
5eabfe72
KH
975 "*Specifies the date format to use in the header.
976This string is passed as argument to the command `format-time-string'.
977For more information on format strings, see the documentation for the
978`format-time-string' command (C-h f `format-time-string')."
979 :type 'string
980 :group 'vhdl-header)
d2ddb974 981
5eabfe72 982(defcustom vhdl-modify-date-prefix-string "-- Last update: "
d2ddb974 983 "*Prefix string of modification date in VHDL file header.
5eabfe72
KH
984If actualization of the modification date is called (menu,
985`\\[vhdl-template-modify]'), this string is searched and the rest
986of the line replaced by the current date."
d2ddb974 987 :type 'string
5eabfe72
KH
988 :group 'vhdl-header)
989
990(defcustom vhdl-modify-date-on-saving t
991 "*Non-nil means update the modification date when the buffer is saved.
992Calls function `\\[vhdl-template-modify]').
993
3dcb36b7
JB
994NOTE: Activate the new setting in a VHDL buffer by using the menu entry
995 \"Activate Options\"."
5eabfe72
KH
996 :type 'boolean
997 :group 'vhdl-header)
998
999
1000(defgroup vhdl-sequential-process nil
1001 "Customizations for sequential processes."
3dcb36b7 1002 :group 'vhdl-template)
d2ddb974 1003
5eabfe72
KH
1004(defcustom vhdl-reset-kind 'async
1005 "*Specifies which kind of reset to use in sequential processes."
1006 :type '(choice (const :tag "None" none)
1007 (const :tag "Synchronous" sync)
1008 (const :tag "Asynchronous" async))
1009 :group 'vhdl-sequential-process)
1010
1011(defcustom vhdl-reset-active-high nil
1012 "*Non-nil means reset in sequential processes is active high.
0404f77e 1013Otherwise, reset is active low."
5eabfe72
KH
1014 :type 'boolean
1015 :group 'vhdl-sequential-process)
1016
1017(defcustom vhdl-clock-rising-edge t
1018 "*Non-nil means rising edge of clock triggers sequential processes.
0404f77e 1019Otherwise, falling edge triggers."
5eabfe72
KH
1020 :type 'boolean
1021 :group 'vhdl-sequential-process)
1022
1023(defcustom vhdl-clock-edge-condition 'standard
1024 "*Syntax of the clock edge condition.
1025 Standard: \"clk'event and clk = '1'\"
1026 Function: \"rising_edge(clk)\""
1027 :type '(choice (const :tag "Standard" standard)
1028 (const :tag "Function" function))
1029 :group 'vhdl-sequential-process)
1030
1031(defcustom vhdl-clock-name ""
1032 "*Name of clock signal to use in templates."
d2ddb974 1033 :type 'string
5eabfe72 1034 :group 'vhdl-sequential-process)
d2ddb974 1035
5eabfe72
KH
1036(defcustom vhdl-reset-name ""
1037 "*Name of reset signal to use in templates."
d2ddb974 1038 :type 'string
5eabfe72
KH
1039 :group 'vhdl-sequential-process)
1040
1041
1042(defgroup vhdl-model nil
1043 "Customizations for user models."
1044 :group 'vhdl)
1045
1046(defcustom vhdl-model-alist
3dcb36b7 1047 '(("Example Model"
5eabfe72
KH
1048 "<label> : process (<clock>, <reset>)
1049begin -- process <label>
1050 if <reset> = '0' then -- asynchronous reset (active low)
1051 <cursor>
1052 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1053 if <enable> = '1' then -- synchronous load
84c98ace 1054
5eabfe72
KH
1055 end if;
1056 end if;
1057end process <label>;"
1058 "e" ""))
1059 "*List of user models.
1060VHDL models (templates) can be specified by the user in this list. They can be
1061invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1062electrification (i.e. overriding existing or creating new keywords, see
3dcb36b7 1063option `vhdl-electric-keywords').
5eabfe72
KH
1064 Name : name of model (string of words and spaces)
1065 String : string or name of file to be inserted as model (newline: `C-j')
1066 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1067 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1068 Keyword : keyword to invoke model
1069
1070The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1071A prompt that appears several times is queried once and replaced throughout
1072the model. Special prompts are:
1073 <clock> : name specified in `vhdl-clock-name' (if not empty)
1074 <reset> : name specified in `vhdl-reset-name' (if not empty)
1075 <cursor>: final cursor position
3dcb36b7
JB
1076File header prompts (see variable `vhdl-file-header') are automatically
1077replaced, so that user models can also be used to insert different types of
1078headers.
5eabfe72
KH
1079
1080If the string specifies an existing file name, the contents of the file is
1081inserted, otherwise the string itself is inserted.
1082The code within the models should be correctly indented.
1083Type `C-j' for newlines.
1084
3dcb36b7
JB
1085NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1086 \"Activate Options\"."
5eabfe72
KH
1087 :type '(repeat (list :tag "Model" :indent 2
1088 (string :tag "Name ")
1089 (string :tag "String : (type `C-j' for newline)"
1090 :format "%t\n%v")
3dcb36b7
JB
1091 (sexp :tag "Key binding" x)
1092 (string :tag "Keyword " :format "%t: %v\n")))
5eabfe72 1093 :set (lambda (variable value)
0a2e512a 1094 (vhdl-custom-set variable value
5eabfe72
KH
1095 'vhdl-model-map-init
1096 'vhdl-model-defun
1097 'vhdl-mode-abbrev-table-init
1098 'vhdl-update-mode-menu))
1099 :group 'vhdl-model)
1100
3dcb36b7 1101
0a2e512a
RF
1102(defgroup vhdl-compose nil
1103 "Customizations for structural composition."
1104 :group 'vhdl)
1105
1106(defcustom vhdl-compose-architecture-name '(".*" . "str")
1107 (concat
1108 "*Specifies how the component architecture name is obtained.
1109The component architecture name can be obtained by modifying the entity name
1110\(e.g. attaching or stripping off a substring).
1111If TO STRING is empty, the architecture name is queried."
1112 vhdl-name-doc-string)
1113 :type '(cons (regexp :tag "From regexp")
1114 (string :tag "To string "))
1115 :group 'vhdl-compose)
1116
1117(defcustom vhdl-compose-configuration-name
1118 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1119 (concat
1120 "*Specifies how the configuration name is obtained.
1121The configuration name can be obtained by modifying the entity and/or
1122architecture name (e.g. attaching or stripping off a substring). The string
1123that is matched against the regexp is the concatenation of the entity and the
1124architecture name separated by a space. This gives access to both names (see
1125default setting as example)."
1126 vhdl-name-doc-string)
1127 :type '(cons (regexp :tag "From regexp")
1128 (string :tag "To string "))
1129 :group 'vhdl-compose)
1130
1131(defcustom vhdl-components-package-name
1132 '((".*" . "\\&_components") . "components")
1133 (concat
1134 "*Specifies how the name for the components package is obtained.
1135The components package is a package containing all component declarations for
a4c6cfad 1136the current design. Its name can be obtained by modifying the project name
0a2e512a
RF
1137\(e.g. attaching or stripping off a substring). If no project is defined, the
1138DIRECTORY entry is chosen."
1139 vhdl-name-doc-string)
1140 :type '(cons (cons :tag "Project" :indent 2
1141 (regexp :tag "From regexp")
1142 (string :tag "To string "))
1143 (string :tag "Directory:\n String "))
1144 :group 'vhdl-compose)
1145
1146(defcustom vhdl-use-components-package nil
1147 "*Non-nil means use a separate components package for component declarations.
1148Otherwise, component declarations are inserted and searched for in the
1149architecture declarative parts."
1150 :type 'boolean
1151 :group 'vhdl-compose)
1152
1153(defcustom vhdl-compose-include-header t
1154 "*Non-nil means include a header in automatically generated files."
1155 :type 'boolean
1156 :group 'vhdl-compose)
1157
1158(defcustom vhdl-compose-create-files 'single
1159 "*Specifies whether new files should be created for the new component.
1160The component's entity and architecture are inserted:
1161 None : in current buffer
1162 Single file : in new single file
1163 Separate files: in two separate files
1164The file names are obtained from variables `vhdl-entity-file-name' and
1165`vhdl-architecture-file-name'."
1166 :type '(choice (const :tag "None" none)
1167 (const :tag "Single file" single)
1168 (const :tag "Separate files" separate))
1169 :group 'vhdl-compose)
1170
1171(defcustom vhdl-compose-configuration-create-file nil
1172 "*Specifies whether a new file should be created for the configuration.
1173If non-nil, a new file is created for the configuration.
1174The file name is obtained from variable `vhdl-configuration-file-name'."
1175 :type 'boolean
1176 :group 'vhdl-compose)
1177
1178(defcustom vhdl-compose-configuration-hierarchical t
1179 "*Specifies whether hierarchical configurations should be created.
1180If non-nil, automatically created configurations are hierarchical and include
1181the whole hierarchy of subcomponents. Otherwise the configuration only
1182includes one level of subcomponents."
1183 :type 'boolean
1184 :group 'vhdl-compose)
1185
1186(defcustom vhdl-compose-configuration-use-subconfiguration t
1187 "*Specifies whether subconfigurations should be used inside configurations.
1188If non-nil, automatically created configurations use configurations in binding
1189indications for subcomponents, if such configurations exist. Otherwise,
1190entities are used in binding indications for subcomponents."
1191 :type 'boolean
1192 :group 'vhdl-compose)
1193
1194
5eabfe72 1195(defgroup vhdl-port nil
3dcb36b7
JB
1196 "Customizations for port translation functions."
1197 :group 'vhdl
1198 :group 'vhdl-compose)
5eabfe72
KH
1199
1200(defcustom vhdl-include-port-comments nil
1201 "*Non-nil means include port comments when a port is pasted."
1202 :type 'boolean
1203 :group 'vhdl-port)
1204
1205(defcustom vhdl-include-direction-comments nil
3dcb36b7 1206 "*Non-nil means include port direction in instantiations as comments."
5eabfe72
KH
1207 :type 'boolean
1208 :group 'vhdl-port)
1209
3dcb36b7
JB
1210(defcustom vhdl-include-type-comments nil
1211 "*Non-nil means include generic/port type in instantiations as comments."
1212 :type 'boolean
1213 :group 'vhdl-port)
5eabfe72 1214
3dcb36b7
JB
1215(defcustom vhdl-include-group-comments 'never
1216 "*Specifies whether to include group comments and spacings.
1217The comments and empty lines between groups of ports are pasted:
1218 Never : never
1219 Declarations: in entity/component/constant/signal declarations only
1220 Always : also in generic/port maps"
1221 :type '(choice (const :tag "Never" never)
1222 (const :tag "Declarations" decl)
1223 (const :tag "Always" always))
1224 :group 'vhdl-port)
5eabfe72 1225
3dcb36b7 1226(defcustom vhdl-actual-port-name '(".*" . "\\&")
5eabfe72
KH
1227 (concat
1228 "*Specifies how actual port names are obtained from formal port names.
1229In a component instantiation, an actual port name can be obtained by
1230modifying the formal port name (e.g. attaching or stripping off a substring)."
1231 vhdl-name-doc-string)
3dcb36b7
JB
1232 :type '(cons (regexp :tag "From regexp")
1233 (string :tag "To string "))
5eabfe72
KH
1234 :group 'vhdl-port)
1235
3dcb36b7 1236(defcustom vhdl-instance-name '(".*" . "\\&_%d")
5eabfe72
KH
1237 (concat
1238 "*Specifies how an instance name is obtained.
1239The instance name can be obtained by modifying the name of the component to be
3dcb36b7
JB
1240instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1241by a unique number (starting with 1).
5eabfe72
KH
1242If TO STRING is empty, the instance name is queried."
1243 vhdl-name-doc-string)
3dcb36b7
JB
1244 :type '(cons (regexp :tag "From regexp")
1245 (string :tag "To string "))
1246 :group 'vhdl-port)
1247
1248
1249(defgroup vhdl-testbench nil
bc25429a 1250 "Customizations for testbench generation."
5eabfe72
KH
1251 :group 'vhdl-port)
1252
1253(defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1254 (concat
3dcb36b7
JB
1255 "*Specifies how the testbench entity name is obtained.
1256The entity name of a testbench can be obtained by modifying the name of
5eabfe72
KH
1257the component to be tested (e.g. attaching or stripping off a substring)."
1258 vhdl-name-doc-string)
3dcb36b7
JB
1259 :type '(cons (regexp :tag "From regexp")
1260 (string :tag "To string "))
1261 :group 'vhdl-testbench)
5eabfe72
KH
1262
1263(defcustom vhdl-testbench-architecture-name '(".*" . "")
1264 (concat
3dcb36b7
JB
1265 "*Specifies how the testbench architecture name is obtained.
1266The testbench architecture name can be obtained by modifying the name of
5eabfe72
KH
1267the component to be tested (e.g. attaching or stripping off a substring).
1268If TO STRING is empty, the architecture name is queried."
1269 vhdl-name-doc-string)
3dcb36b7
JB
1270 :type '(cons (regexp :tag "From regexp")
1271 (string :tag "To string "))
1272 :group 'vhdl-testbench)
1273
0a2e512a 1274(defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
3dcb36b7
JB
1275 (concat
1276 "*Specifies how the testbench configuration name is obtained.
1277The configuration name of a testbench can be obtained by modifying the entity
1278and/or architecture name (e.g. attaching or stripping off a substring). The
1279string that is matched against the regexp is the concatenation of the entity
1280and the architecture name separated by a space. This gives access to both
1281names (see default setting as example)."
1282 vhdl-name-doc-string)
1283 :type '(cons (regexp :tag "From regexp")
1284 (string :tag "To string "))
1285 :group 'vhdl-testbench)
5eabfe72
KH
1286
1287(defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1288 (concat
1289 "*Specifies how a DUT instance name is obtained.
1290The design-under-test instance name (i.e. the component instantiated in the
3dcb36b7 1291testbench) can be obtained by modifying the component name (e.g. attaching
5eabfe72
KH
1292or stripping off a substring)."
1293 vhdl-name-doc-string)
3dcb36b7
JB
1294 :type '(cons (regexp :tag "From regexp")
1295 (string :tag "To string "))
1296 :group 'vhdl-testbench)
5eabfe72 1297
3dcb36b7
JB
1298(defcustom vhdl-testbench-include-header t
1299 "*Non-nil means include a header in automatically generated files."
1300 :type 'boolean
1301 :group 'vhdl-testbench)
5eabfe72 1302
3dcb36b7
JB
1303(defcustom vhdl-testbench-declarations "\
1304 -- clock
1305 signal Clk : std_logic := '1';
1306"
1307 "*String or file to be inserted in the testbench declarative part.
5eabfe72 1308If the string specifies an existing file name, the contents of the file is
3dcb36b7 1309inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1310architecture before the BEGIN keyword.
1311Type `C-j' for newlines."
1312 :type 'string
3dcb36b7
JB
1313 :group 'vhdl-testbench)
1314
1315(defcustom vhdl-testbench-statements "\
1316 -- clock generation
1317 Clk <= not Clk after 10 ns;
5eabfe72 1318
3dcb36b7
JB
1319 -- waveform generation
1320 WaveGen_Proc: process
1321 begin
1322 -- insert signal assignments here
84c98ace 1323
3dcb36b7
JB
1324 wait until Clk = '1';
1325 end process WaveGen_Proc;
1326"
1327 "*String or file to be inserted in the testbench statement part.
5eabfe72 1328If the string specifies an existing file name, the contents of the file is
3dcb36b7 1329inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1330architecture before the END keyword.
1331Type `C-j' for newlines."
1332 :type 'string
3dcb36b7 1333 :group 'vhdl-testbench)
5eabfe72
KH
1334
1335(defcustom vhdl-testbench-initialize-signals nil
3dcb36b7 1336 "*Non-nil means initialize signals with `0' when declared in testbench."
5eabfe72 1337 :type 'boolean
3dcb36b7
JB
1338 :group 'vhdl-testbench)
1339
1340(defcustom vhdl-testbench-include-library t
1341 "*Non-nil means a library/use clause for std_logic_1164 is included."
1342 :type 'boolean
1343 :group 'vhdl-testbench)
1344
1345(defcustom vhdl-testbench-include-configuration t
1346 "*Non-nil means a testbench configuration is attached at the end."
1347 :type 'boolean
1348 :group 'vhdl-testbench)
5eabfe72
KH
1349
1350(defcustom vhdl-testbench-create-files 'single
3dcb36b7
JB
1351 "*Specifies whether new files should be created for the testbench.
1352testbench entity and architecture are inserted:
5eabfe72
KH
1353 None : in current buffer
1354 Single file : in new single file
1355 Separate files: in two separate files
0a2e512a
RF
1356The file names are obtained from variables `vhdl-testbench-entity-file-name'
1357and `vhdl-testbench-architecture-file-name'."
5eabfe72
KH
1358 :type '(choice (const :tag "None" none)
1359 (const :tag "Single file" single)
1360 (const :tag "Separate files" separate))
3dcb36b7
JB
1361 :group 'vhdl-testbench)
1362
0a2e512a 1363(defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
3dcb36b7 1364 (concat
0a2e512a
RF
1365 "*Specifies how the testbench entity file name is obtained.
1366The entity file name can be obtained by modifying the testbench entity name
1367\(e.g. attaching or stripping off a substring). The file extension is
1368automatically taken from the file name of the current buffer. Testbench
1369files can be created in a different directory by prepending a relative or
1370absolute path to the file name."
3dcb36b7
JB
1371 vhdl-name-doc-string)
1372 :type '(cons (regexp :tag "From regexp")
1373 (string :tag "To string "))
0a2e512a 1374 :group 'vhdl-testbench)
3dcb36b7 1375
0a2e512a 1376(defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
3dcb36b7 1377 (concat
0a2e512a
RF
1378 "*Specifies how the testbench architecture file name is obtained.
1379The architecture file name can be obtained by modifying the testbench entity
1380and/or architecture name (e.g. attaching or stripping off a substring). The
1381string that is matched against the regexp is the concatenation of the entity
1382and the architecture name separated by a space. This gives access to both
1383names (see default setting as example). Testbench files can be created in
1384a different directory by prepending a relative or absolute path to the file
1385name."
3dcb36b7 1386 vhdl-name-doc-string)
0a2e512a
RF
1387 :type '(cons (regexp :tag "From regexp")
1388 (string :tag "To string "))
1389 :group 'vhdl-testbench)
d2ddb974
KH
1390
1391
1392(defgroup vhdl-comment nil
1393 "Customizations for comments."
5eabfe72 1394 :group 'vhdl)
d2ddb974
KH
1395
1396(defcustom vhdl-self-insert-comments t
5eabfe72 1397 "*Non-nil means various templates automatically insert help comments."
d2ddb974
KH
1398 :type 'boolean
1399 :group 'vhdl-comment)
1400
1401(defcustom vhdl-prompt-for-comments t
5eabfe72 1402 "*Non-nil means various templates prompt for user definable comments."
d2ddb974
KH
1403 :type 'boolean
1404 :group 'vhdl-comment)
1405
5eabfe72 1406(defcustom vhdl-inline-comment-column 40
3dcb36b7
JB
1407 "*Column to indent and align inline comments to.
1408Overrides local option `comment-column'.
5eabfe72 1409
3dcb36b7
JB
1410NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1411 \"Activate Options\"."
d2ddb974
KH
1412 :type 'integer
1413 :group 'vhdl-comment)
1414
1415(defcustom vhdl-end-comment-column 79
5eabfe72
KH
1416 "*End of comment column.
1417Comments that exceed this column number are wrapped.
1418
3dcb36b7
JB
1419NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1420 \"Activate Options\"."
d2ddb974
KH
1421 :type 'integer
1422 :group 'vhdl-comment)
1423
5eabfe72 1424(defvar end-comment-column)
d2ddb974
KH
1425
1426
5eabfe72
KH
1427(defgroup vhdl-align nil
1428 "Customizations for alignment."
d2ddb974
KH
1429 :group 'vhdl)
1430
5eabfe72
KH
1431(defcustom vhdl-auto-align t
1432 "*Non-nil means align some templates automatically after generation."
d2ddb974 1433 :type 'boolean
5eabfe72
KH
1434 :group 'vhdl-align)
1435
1436(defcustom vhdl-align-groups t
1437 "*Non-nil means align groups of code lines separately.
3dcb36b7
JB
1438A group of code lines is a region of consecutive lines between two lines that
1439match the regexp in option `vhdl-align-group-separate'."
1440 :type 'boolean
1441 :group 'vhdl-align)
1442
1443(defcustom vhdl-align-group-separate "^\\s-*$"
1444 "*Regexp for matching a line that separates groups of lines for alignment.
1445Examples:
1446 \"^\\s-*$\": matches an empty line
1447 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1448 :type 'regexp
1449 :group 'vhdl-align)
1450
1451(defcustom vhdl-align-same-indent t
1452 "*Non-nil means align blocks with same indent separately.
1453When a region or the entire buffer is aligned, the code is divided into
1454blocks of same indent which are aligned separately (except for argument/port
1455lists). This gives nicer alignment in most cases.
1456Option `vhdl-align-groups' still applies within these blocks."
5eabfe72
KH
1457 :type 'boolean
1458 :group 'vhdl-align)
1459
1460
1461(defgroup vhdl-highlight nil
1462 "Customizations for highlighting."
1463 :group 'vhdl)
d2ddb974
KH
1464
1465(defcustom vhdl-highlight-keywords t
5eabfe72
KH
1466 "*Non-nil means highlight VHDL keywords and other standardized words.
1467The following faces are used:
0a2e512a
RF
1468 `font-lock-keyword-face' : keywords
1469 `font-lock-type-face' : standardized types
1470 `vhdl-font-lock-attribute-face': standardized attributes
1471 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1472 `vhdl-font-lock-function-face' : standardized function and package names
5eabfe72
KH
1473
1474NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1475 entry \"Fontify Buffer\")."
d2ddb974 1476 :type 'boolean
5eabfe72 1477 :set (lambda (variable value)
0a2e512a 1478 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1479 :group 'vhdl-highlight)
1480
5eabfe72
KH
1481(defcustom vhdl-highlight-names t
1482 "*Non-nil means highlight declaration names and construct labels.
1483The following faces are used:
3dcb36b7 1484 `font-lock-function-name-face' : names in declarations of units,
5eabfe72 1485 subprograms, components, as well as labels of VHDL constructs
3dcb36b7 1486 `font-lock-type-face' : names in type/nature declarations
0a2e512a 1487 `vhdl-font-lock-attribute-face': names in attribute declarations
3dcb36b7 1488 `font-lock-variable-name-face' : names in declarations of signals,
5eabfe72
KH
1489 variables, constants, subprogram parameters, generics, and ports
1490
1491NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1492 entry \"Fontify Buffer\")."
d2ddb974 1493 :type 'boolean
5eabfe72 1494 :set (lambda (variable value)
0a2e512a 1495 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1496 :group 'vhdl-highlight)
1497
5eabfe72
KH
1498(defcustom vhdl-highlight-special-words nil
1499 "*Non-nil means highlight words with special syntax.
3dcb36b7
JB
1500The words with syntax and color specified in option `vhdl-special-syntax-alist'
1501are highlighted accordingly.
5eabfe72
KH
1502Can be used for visual support of naming conventions.
1503
1504NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1505 entry \"Fontify Buffer\")."
d2ddb974 1506 :type 'boolean
5eabfe72 1507 :set (lambda (variable value)
0a2e512a 1508 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1509 :group 'vhdl-highlight)
1510
5eabfe72
KH
1511(defcustom vhdl-highlight-forbidden-words nil
1512 "*Non-nil means highlight forbidden words.
3dcb36b7
JB
1513The reserved words specified in option `vhdl-forbidden-words' or having the
1514syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
0a2e512a 1515warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
5eabfe72
KH
1516use them.
1517
1518NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1519 entry \"Fontify Buffer\")."
d2ddb974 1520 :type 'boolean
5eabfe72 1521 :set (lambda (variable value)
0a2e512a 1522 (vhdl-custom-set variable value
5eabfe72 1523 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1524 :group 'vhdl-highlight)
1525
5eabfe72
KH
1526(defcustom vhdl-highlight-verilog-keywords nil
1527 "*Non-nil means highlight Verilog keywords as reserved words.
1528Verilog keywords are highlighted in a warning color (face
0a2e512a 1529`vhdl-font-lock-reserved-words-face') to indicate not to use them.
2f402702 1530
5eabfe72 1531NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1532 entry \"Fontify Buffer\")."
d2ddb974 1533 :type 'boolean
5eabfe72 1534 :set (lambda (variable value)
0a2e512a 1535 (vhdl-custom-set variable value
5eabfe72 1536 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1537 :group 'vhdl-highlight)
1538
5eabfe72
KH
1539(defcustom vhdl-highlight-translate-off nil
1540 "*Non-nil means background-highlight code excluded from translation.
1541That is, all code between \"-- pragma translate_off\" and
1542\"-- pragma translate_on\" is highlighted using a different background color
0a2e512a 1543\(face `vhdl-font-lock-translate-off-face').
5eabfe72 1544Note: this might slow down on-the-fly fontification (and thus editing).
d2ddb974 1545
5eabfe72 1546NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1547 entry \"Fontify Buffer\")."
5eabfe72
KH
1548 :type 'boolean
1549 :set (lambda (variable value)
0a2e512a 1550 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1551 :group 'vhdl-highlight)
1552
5eabfe72
KH
1553(defcustom vhdl-highlight-case-sensitive nil
1554 "*Non-nil means consider case for highlighting.
1555Possible trade-off:
1556 non-nil also upper-case VHDL words are highlighted, but case of words with
1557 special syntax is not considered
1558 nil only lower-case VHDL words are highlighted, but case of words with
1559 special syntax is considered
3dcb36b7 1560Overrides local option `font-lock-keywords-case-fold-search'.
5eabfe72
KH
1561
1562NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1563 entry \"Fontify Buffer\")."
5eabfe72
KH
1564 :type 'boolean
1565 :group 'vhdl-highlight)
d2ddb974 1566
3dcb36b7
JB
1567(defcustom vhdl-special-syntax-alist
1568 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1569 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1570 ("variable" "\\w+_v" "Grey50" "Grey80"))
5eabfe72 1571 "*List of special syntax to be highlighted.
3dcb36b7 1572If option `vhdl-highlight-special-words' is non-nil, words with the specified
5eabfe72
KH
1573syntax (as regular expression) are highlighted in the corresponding color.
1574
1575 Name : string of words and spaces
1576 Regexp : regular expression describing word syntax
1577 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1578 Color (light): foreground color for light background
1579 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1580 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1581 Color (dark) : foreground color for dark background
1582 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1583 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1584
1585Can be used for visual support of naming conventions, such as highlighting
3dcb36b7 1586different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
5eabfe72 1587\"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
3dcb36b7 1588common substrings or name suffices.
5eabfe72 1589For each entry, a new face is generated with the specified colors and name
0a2e512a 1590\"vhdl-font-lock-\" + name + \"-face\".
5eabfe72
KH
1591
1592NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1593 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
5eabfe72
KH
1594 :type '(repeat (list :tag "Face" :indent 2
1595 (string :tag "Name ")
1596 (regexp :tag "Regexp " "\\w+_")
1597 (string :tag "Color (light)")
1598 (string :tag "Color (dark) ")))
1599 :set (lambda (variable value)
0a2e512a 1600 (vhdl-custom-set variable value 'vhdl-font-lock-init))
5eabfe72 1601 :group 'vhdl-highlight)
d2ddb974 1602
5eabfe72
KH
1603(defcustom vhdl-forbidden-words '()
1604 "*List of forbidden words to be highlighted.
3dcb36b7 1605If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
5eabfe72
KH
1606words are highlighted in a warning color to indicate not to use them.
1607
1608NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1609 entry \"Fontify Buffer\")."
5eabfe72
KH
1610 :type '(repeat (string :format "%v"))
1611 :set (lambda (variable value)
0a2e512a 1612 (vhdl-custom-set variable value
5eabfe72
KH
1613 'vhdl-words-init 'vhdl-font-lock-init))
1614 :group 'vhdl-highlight)
d2ddb974 1615
5eabfe72
KH
1616(defcustom vhdl-forbidden-syntax ""
1617 "*Syntax of forbidden words to be highlighted.
3dcb36b7 1618If option `vhdl-highlight-forbidden-words' is non-nil, words with this
5eabfe72
KH
1619syntax are highlighted in a warning color to indicate not to use them.
1620Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1621highlights identifiers with 10 or more characters).
d2ddb974 1622
5eabfe72 1623NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1624 entry \"Fontify Buffer\")."
d2ddb974 1625 :type 'regexp
5eabfe72 1626 :set (lambda (variable value)
0a2e512a 1627 (vhdl-custom-set variable value
5eabfe72
KH
1628 'vhdl-words-init 'vhdl-font-lock-init))
1629 :group 'vhdl-highlight)
d2ddb974 1630
3dcb36b7
JB
1631(defcustom vhdl-directive-keywords '("pragma" "synopsys")
1632 "*List of compiler directive keywords recognized for highlighting.
d2ddb974 1633
3dcb36b7
JB
1634NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1635 entry \"Fontify Buffer\")."
1636 :type '(repeat (string :format "%v"))
1637 :set (lambda (variable value)
1638 (vhdl-custom-set variable value
1639 'vhdl-words-init 'vhdl-font-lock-init))
1640 :group 'vhdl-highlight)
1641
1642
1643(defgroup vhdl-speedbar nil
1644 "Customizations for speedbar."
d2ddb974
KH
1645 :group 'vhdl)
1646
3dcb36b7
JB
1647(defcustom vhdl-speedbar-auto-open nil
1648 "*Non-nil means automatically open speedbar at startup.
5eabfe72 1649Alternatively, the speedbar can be opened from the VHDL menu."
d2ddb974 1650 :type 'boolean
3dcb36b7
JB
1651 :group 'vhdl-speedbar)
1652
1653(defcustom vhdl-speedbar-display-mode 'files
1654 "*Specifies the default displaying mode when opening speedbar.
1655Alternatively, the displaying mode can be selected from the speedbar menu or
1656by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1657 :type '(choice (const :tag "Files" files)
1658 (const :tag "Directory hierarchy" directory)
1659 (const :tag "Project hierarchy" project))
1660 :group 'vhdl-speedbar)
1661
1662(defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1663 "*Limits scanning of large files and netlists.
1664Design units: maximum file size to scan for design units
1665Hierarchy (instances of subcomponents):
1666 File size: maximum file size to scan for instances (in bytes)
1667 Instances per arch: maximum number of instances to scan per architecture
1668
1669\"None\" always means that there is no limit.
1670In case of files not or incompletely scanned, a warning message and the file
1671names are printed out.
1672Background: scanning for instances is considerably slower than scanning for
1673design units, especially when there are many instances. These limits should
1674prevent the scanning of large netlists."
1675 :type '(list (choice :tag "Design units"
1676 :format "%t : %[Value Menu%] %v"
1677 (const :tag "None" nil)
1678 (integer :tag "File size"))
1679 (list :tag "Hierarchy" :indent 2
1680 (choice :tag "File size"
1681 :format "%t : %[Value Menu%] %v"
1682 (const :tag "None" nil)
1683 (integer :tag "Size "))
1684 (choice :tag "Instances per arch"
1685 (const :tag "None" nil)
1686 (integer :tag "Number "))))
1687 :group 'vhdl-speedbar)
1688
1689(defcustom vhdl-speedbar-jump-to-unit t
1690 "*Non-nil means jump to the design unit code when opened in a buffer.
1691The buffer cursor position is left unchanged otherwise."
1692 :type 'boolean
1693 :group 'vhdl-speedbar)
d2ddb974 1694
3dcb36b7
JB
1695(defcustom vhdl-speedbar-update-on-saving t
1696 "*Automatically update design hierarchy when buffer is saved."
d2ddb974 1697 :type 'boolean
3dcb36b7
JB
1698 :group 'vhdl-speedbar)
1699
1700(defcustom vhdl-speedbar-save-cache '(hierarchy display)
1701 "*Automatically save modified hierarchy caches when exiting Emacs.
1702 Hierarchy: design hierarchy information
1703 Display: displaying information (which design units to expand)"
1704 :type '(set (const :tag "Hierarchy" hierarchy)
1705 (const :tag "Display" display))
1706 :group 'vhdl-speedbar)
1707
1708(defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1709 "*Name of file for saving hierarchy cache.
1710\"\\1\" is replaced by the project name if a project is specified,
1711\"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1712different users to have cache files in the same directory). Can also have
1713an absolute path (i.e. all caches can be stored in one global directory)."
1714 :type 'string
1715 :group 'vhdl-speedbar)
d2ddb974 1716
3dcb36b7
JB
1717
1718(defgroup vhdl-menu nil
1719 "Customizations for menues."
1720 :group 'vhdl)
5eabfe72
KH
1721
1722(defcustom vhdl-index-menu nil
1723 "*Non-nil means add an index menu for a source file when loading.
1724Alternatively, the speedbar can be used. Note that the index menu scans a file
3dcb36b7 1725when it is opened, while speedbar only scans the file upon request."
5eabfe72
KH
1726 :type 'boolean
1727 :group 'vhdl-menu)
1728
1729(defcustom vhdl-source-file-menu nil
1730 "*Non-nil means add a menu of all source files in current directory.
1731Alternatively, the speedbar can be used."
1732 :type 'boolean
1733 :group 'vhdl-menu)
1734
1735(defcustom vhdl-hideshow-menu nil
3dcb36b7
JB
1736 "*Non-nil means add hideshow menu and functionality at startup.
1737Hideshow can also be enabled from the VHDL Mode menu.
1738Hideshow allows hiding code of various VHDL constructs.
5eabfe72 1739
3dcb36b7
JB
1740NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1741 \"Activate Options\"."
5eabfe72
KH
1742 :type 'boolean
1743 :group 'vhdl-menu)
1744
1745(defcustom vhdl-hide-all-init nil
1746 "*Non-nil means hide all design units initially after a file is loaded."
d2ddb974
KH
1747 :type 'boolean
1748 :group 'vhdl-menu)
1749
1750
1751(defgroup vhdl-print nil
1752 "Customizations for printing."
1753 :group 'vhdl)
1754
1755(defcustom vhdl-print-two-column t
5eabfe72 1756 "*Non-nil means print code in two columns and landscape format.
3dcb36b7
JB
1757Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1758prints VHDL files in a nice two-column landscape style.
5eabfe72
KH
1759
1760NOTE: Activate the new setting by restarting Emacs.
1761 Overrides `ps-print' settings locally."
1762 :type 'boolean
1763 :group 'vhdl-print)
1764
1765(defcustom vhdl-print-customize-faces t
1766 "*Non-nil means use an optimized set of faces for postscript printing.
1767
1768NOTE: Activate the new setting by restarting Emacs.
1769 Overrides `ps-print' settings locally."
d2ddb974
KH
1770 :type 'boolean
1771 :group 'vhdl-print)
1772
1773
1774(defgroup vhdl-misc nil
1775 "Miscellaneous customizations."
1776 :group 'vhdl)
1777
1778(defcustom vhdl-intelligent-tab t
5eabfe72 1779 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
d2ddb974
KH
1780That is, if preceeding character is part of a word then complete word,
1781else if not at beginning of line then insert tab,
1782else if last command was a `TAB' or `RET' then dedent one step,
5eabfe72 1783else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
d2ddb974 1784If nil, TAB always indents current line (i.e. `TAB' is bound to
3dcb36b7
JB
1785`indent-according-to-mode').
1786
1787NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1788 \"Activate Options\"."
1789 :type 'boolean
1790 :group 'vhdl-misc)
5eabfe72 1791
3dcb36b7
JB
1792(defcustom vhdl-indent-syntax-based t
1793 "*Non-nil means indent lines of code based on their syntactic context.
1794Otherwise, a line is indented like the previous nonblank line. This can be
1795useful in large files where syntax-based indentation gets very slow."
d2ddb974
KH
1796 :type 'boolean
1797 :group 'vhdl-misc)
1798
5eabfe72
KH
1799(defcustom vhdl-word-completion-case-sensitive nil
1800 "*Non-nil means word completion using `TAB' is case sensitive.
1801That is, `TAB' completes words that start with the same letters and case.
1802Otherwise, case is ignored."
1803 :type 'boolean
d2ddb974
KH
1804 :group 'vhdl-misc)
1805
1806(defcustom vhdl-word-completion-in-minibuffer t
5eabfe72
KH
1807 "*Non-nil enables word completion in minibuffer (for template prompts).
1808
1809NOTE: Activate the new setting by restarting Emacs."
d2ddb974
KH
1810 :type 'boolean
1811 :group 'vhdl-misc)
1812
1813(defcustom vhdl-underscore-is-part-of-word nil
5eabfe72 1814 "*Non-nil means consider the underscore character `_' as part of word.
d2ddb974 1815An identifier containing underscores is then treated as a single word in
5eabfe72
KH
1816select and move operations. All parts of an identifier separated by underscore
1817are treated as single words otherwise.
1818
3dcb36b7
JB
1819NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1820 \"Activate Options\"."
d2ddb974 1821 :type 'boolean
5eabfe72 1822 :set (lambda (variable value)
0a2e512a 1823 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
d2ddb974
KH
1824 :group 'vhdl-misc)
1825
3dcb36b7
JB
1826
1827(defgroup vhdl-related nil
5eabfe72
KH
1828 "Related general customizations."
1829 :group 'vhdl)
1830
3dcb36b7
JB
1831;; add related general customizations
1832(custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
f8246027 1833(if (featurep 'xemacs)
3dcb36b7
JB
1834 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1835 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1836(custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1837(custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1838(custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
f8246027 1839(unless (featurep 'xemacs)
3dcb36b7
JB
1840 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1841(custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1842(custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1843(custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1844
5eabfe72
KH
1845;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1846;; Internal variables
1847
3dcb36b7
JB
1848(defvar vhdl-menu-max-size 20
1849 "*Specifies the maximum size of a menu before splitting it into submenues.")
5eabfe72
KH
1850
1851(defvar vhdl-progress-interval 1
1852 "*Interval used to update progress status during long operations.
1853If a number, percentage complete gets updated after each interval of
3dcb36b7 1854that many seconds. To inhibit all messages, set this option to nil.")
d2ddb974
KH
1855
1856(defvar vhdl-inhibit-startup-warnings-p nil
1857 "*If non-nil, inhibits start up compatibility warnings.")
1858
1859(defvar vhdl-strict-syntax-p nil
1860 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1861If the syntactic symbol for a particular line does not match a symbol
1862in the offsets alist, an error is generated, otherwise no error is
1863reported and the syntactic symbol is ignored.")
1864
1865(defvar vhdl-echo-syntactic-information-p nil
1866 "*If non-nil, syntactic info is echoed when the line is indented.")
1867
1868(defconst vhdl-offsets-alist-default
0a2e512a
RF
1869 '((string . -1000)
1870 (cpp-macro . -1000)
1871 (block-open . 0)
1872 (block-close . 0)
1873 (statement . 0)
1874 (statement-cont . vhdl-lineup-statement-cont)
d2ddb974
KH
1875 (statement-block-intro . +)
1876 (statement-case-intro . +)
0a2e512a
RF
1877 (case-alternative . +)
1878 (comment . vhdl-lineup-comment)
1879 (arglist-intro . +)
1880 (arglist-cont . 0)
d2ddb974 1881 (arglist-cont-nonempty . vhdl-lineup-arglist)
0a2e512a
RF
1882 (arglist-close . vhdl-lineup-arglist)
1883 (entity . 0)
1884 (configuration . 0)
1885 (package . 0)
1886 (architecture . 0)
1887 (package-body . 0)
d2ddb974
KH
1888 )
1889 "Default settings for offsets of syntactic elements.
1890Do not change this constant! See the variable `vhdl-offsets-alist' for
1891more information.")
1892
1893(defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1894 "*Association list of syntactic element symbols and indentation offsets.
1895As described below, each cons cell in this list has the form:
1896
1897 (SYNTACTIC-SYMBOL . OFFSET)
1898
5eabfe72 1899When a line is indented, `vhdl-mode' first determines the syntactic
d2ddb974
KH
1900context of the line by generating a list of symbols called syntactic
1901elements. This list can contain more than one syntactic element and
1902the global variable `vhdl-syntactic-context' contains the context list
1903for the line being indented. Each element in this list is actually a
1904cons cell of the syntactic symbol and a buffer position. This buffer
1905position is call the relative indent point for the line. Some
1906syntactic symbols may not have a relative indent point associated with
1907them.
1908
5eabfe72 1909After the syntactic context list for a line is generated, `vhdl-mode'
d2ddb974
KH
1910calculates the absolute indentation for the line by looking at each
1911syntactic element in the list. First, it compares the syntactic
1912element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1913finds a match, it adds the OFFSET to the column of the relative indent
1914point. The sum of this calculation for each element in the syntactic
1915list is the absolute offset for line being indented.
1916
1917If the syntactic element does not match any in the `vhdl-offsets-alist',
1918an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1919the element is ignored.
1920
1921Actually, OFFSET can be an integer, a function, a variable, or one of
1922the following symbols: `+', `-', `++', or `--'. These latter
1923designate positive or negative multiples of `vhdl-basic-offset',
5eabfe72 1924respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
d2ddb974
KH
1925called with a single argument containing the cons of the syntactic
1926element symbol and the relative indent point. The function should
1927return an integer offset.
1928
1929Here is the current list of valid syntactic element symbols:
1930
1931 string -- inside multi-line string
1932 block-open -- statement block open
1933 block-close -- statement block close
1934 statement -- a VHDL statement
1935 statement-cont -- a continuation of a VHDL statement
1936 statement-block-intro -- the first line in a new statement block
1937 statement-case-intro -- the first line in a case alternative block
1938 case-alternative -- a case statement alternative clause
1939 comment -- a line containing only a comment
1940 arglist-intro -- the first line in an argument list
1941 arglist-cont -- subsequent argument list lines when no
1942 arguments follow on the same line as the
1943 the arglist opening paren
1944 arglist-cont-nonempty -- subsequent argument list lines when at
1945 least one argument follows on the same
1946 line as the arglist opening paren
1947 arglist-close -- the solo close paren of an argument list
1948 entity -- inside an entity declaration
1949 configuration -- inside a configuration declaration
1950 package -- inside a package declaration
1951 architecture -- inside an architecture body
5eabfe72 1952 package-body -- inside a package body")
d2ddb974
KH
1953
1954(defvar vhdl-comment-only-line-offset 0
1955 "*Extra offset for line which contains only the start of a comment.
1956Can contain an integer or a cons cell of the form:
1957
1958 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1959
1960Where NON-ANCHORED-OFFSET is the amount of offset given to
1961non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1962the amount of offset to give column-zero anchored comment-only lines.
1963Just an integer as value is equivalent to (<val> . 0)")
1964
1965(defvar vhdl-special-indent-hook nil
1966 "*Hook for user defined special indentation adjustments.
1967This hook gets called after a line is indented by the mode.")
1968
1969(defvar vhdl-style-alist
1970 '(("IEEE"
1971 (vhdl-basic-offset . 4)
3dcb36b7 1972 (vhdl-offsets-alist . ())))
d2ddb974
KH
1973 "Styles of Indentation.
1974Elements of this alist are of the form:
1975
1976 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1977
1978where STYLE-STRING is a short descriptive string used to select a
5eabfe72 1979style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
d2ddb974
KH
1980value for that variable when using the selected style.
1981
1982There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1983case, the VALUE is a list containing elements of the form:
1984
1985 (SYNTACTIC-SYMBOL . VALUE)
1986
1987as described in `vhdl-offsets-alist'. These are passed directly to
1988`vhdl-set-offset' so there is no need to set every syntactic symbol in
1989your style, only those that are different from the default.")
1990
1991;; dynamically append the default value of most variables
1992(or (assoc "Default" vhdl-style-alist)
1993 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1994 vhdl-strict-syntax-p
1995 vhdl-echo-syntactic-information-p
1996 vhdl-basic-offset
1997 vhdl-offsets-alist
1998 vhdl-comment-only-line-offset))
1999 (default (cons "Default"
2000 (mapcar
2001 (function
2002 (lambda (var)
5eabfe72 2003 (cons var (symbol-value var))))
d2ddb974
KH
2004 varlist))))
2005 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2006
2007(defvar vhdl-mode-hook nil
2008 "*Hook called by `vhdl-mode'.")
2009
2010
5eabfe72 2011;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2012;;; Required packages
5eabfe72 2013;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5eabfe72 2014
3dcb36b7 2015;; mandatory
5eabfe72 2016(require 'assoc)
3dcb36b7
JB
2017(require 'compile) ; XEmacs
2018(require 'easymenu)
2019(require 'hippie-exp)
2020
2021;; optional (minimize warning messages during compile)
2022(eval-when-compile
2023 (require 'font-lock)
2024 (require 'ps-print)
2025 (require 'speedbar))
5eabfe72
KH
2026
2027
2028;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2029;;; Compatibility
5eabfe72 2030;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 2031
3dcb36b7
JB
2032;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2033;; XEmacs compatibility
d2ddb974 2034
3dcb36b7 2035;; active regions
d2ddb974 2036(defun vhdl-keep-region-active ()
5eabfe72
KH
2037 "Do whatever is necessary to keep the region active in XEmacs.
2038Ignore byte-compiler warnings you might see."
a445370f 2039 (and (featurep 'xemacs)
d2ddb974
KH
2040 (setq zmacs-region-stays t)))
2041
3dcb36b7 2042;; `wildcard-to-regexp' is included only in XEmacs 21
5eabfe72
KH
2043(unless (fboundp 'wildcard-to-regexp)
2044 (defun wildcard-to-regexp (wildcard)
2045 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2046 (let* ((i (string-match "[*?]" wildcard))
2047 (result (substring wildcard 0 i))
2048 (len (length wildcard)))
2049 (when i
2050 (while (< i len)
2051 (let ((ch (aref wildcard i)))
2052 (setq result (concat result
2053 (cond ((eq ch ?*) "[^\000]*")
2054 ((eq ch ??) "[^\000]")
2055 (t (char-to-string ch)))))
2056 (setq i (1+ i)))))
2057 (concat "\\`" result "\\'"))))
2058
3dcb36b7
JB
2059;; `regexp-opt' undefined (`xemacs-devel' not installed)
2060;; `regexp-opt' accelerates fontification by 10-20%
2061(unless (fboundp 'regexp-opt)
2062; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2063 (defun regexp-opt (strings &optional paren)
2064 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2065 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2066
2067;; `match-string-no-properties' undefined (XEmacs, what else?)
2068(unless (fboundp 'match-string-no-properties)
2069 (defalias 'match-string-no-properties 'match-string))
2070
2071;; `subst-char-in-string' undefined (XEmacs)
2072(unless (fboundp 'subst-char-in-string)
2073 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2074 (let ((i (length string))
2075 (newstr (if inplace string (copy-sequence string))))
2076 (while (> i 0)
2077 (setq i (1- i))
2078 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2079 newstr)))
2080
2081;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
f8246027 2082(when (and (featurep 'xemacs) (string< itimer-version "1.09")
3dcb36b7
JB
2083 (not noninteractive))
2084 (load "itimer")
2085 (when (string< itimer-version "1.09")
2086 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2087 (beep) (sit-for 5)))
2088
2089;; `file-expand-wildcards' undefined (XEmacs)
2090(unless (fboundp 'file-expand-wildcards)
2091 (defun file-expand-wildcards (pattern &optional full)
2092 "Taken from Emacs' `files.el'."
2093 (let* ((nondir (file-name-nondirectory pattern))
2094 (dirpart (file-name-directory pattern))
2095 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2096 (mapcar 'file-name-as-directory
2097 (file-expand-wildcards (directory-file-name dirpart)))
2098 (list dirpart)))
2099 contents)
2100 (while dirs
2101 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2102 (file-directory-p (directory-file-name (car dirs))))
2103 (let ((this-dir-contents
2104 (delq nil
2105 (mapcar #'(lambda (name)
2106 (unless (string-match "\\`\\.\\.?\\'"
2107 (file-name-nondirectory name))
2108 name))
2109 (directory-files (or (car dirs) ".") full
2110 (wildcard-to-regexp nondir))))))
2111 (setq contents
2112 (nconc
2113 (if (and (car dirs) (not full))
2114 (mapcar (function (lambda (name) (concat (car dirs) name)))
2115 this-dir-contents)
2116 this-dir-contents)
2117 contents))))
2118 (setq dirs (cdr dirs)))
2119 contents)))
5eabfe72 2120
0a2e512a
RF
2121;; `member-ignore-case' undefined (XEmacs)
2122(unless (fboundp 'member-ignore-case)
2123 (defalias 'member-ignore-case 'member))
2124
5eabfe72 2125;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2126;; Compatibility with older VHDL Mode versions
5eabfe72 2127
3dcb36b7
JB
2128(defvar vhdl-warnings nil
2129 "Warnings to tell the user during start up.")
d2ddb974 2130
3dcb36b7
JB
2131(defun vhdl-run-when-idle (secs repeat function)
2132 "Wait until idle, then run FUNCTION."
4bcb9c95 2133 (if (fboundp 'start-itimer)
3dcb36b7
JB
2134 (start-itimer "vhdl-mode" function secs repeat t)
2135; (run-with-idle-timer secs repeat function)))
2136 ;; explicitely activate timer (necessary when Emacs is already idle)
2137 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2138
2139(defun vhdl-warning-when-idle (&rest args)
2140 "Wait until idle, then print out warning STRING and beep."
2141 (if noninteractive
2142 (vhdl-warning (apply 'format args) t)
2143 (unless vhdl-warnings
2144 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2145 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2146
2147(defun vhdl-warning (string &optional nobeep)
2148 "Print out warning STRING and beep."
29a4e67d 2149 (message "WARNING: %s" string)
3dcb36b7 2150 (unless (or nobeep noninteractive) (beep)))
d2ddb974 2151
3dcb36b7
JB
2152(defun vhdl-print-warnings ()
2153 "Print out messages in variable `vhdl-warnings'."
2154 (let ((no-warnings (length vhdl-warnings)))
2155 (setq vhdl-warnings (nreverse vhdl-warnings))
2156 (while vhdl-warnings
29a4e67d 2157 (message "WARNING: %s" (car vhdl-warnings))
3dcb36b7
JB
2158 (setq vhdl-warnings (cdr vhdl-warnings)))
2159 (beep)
2160 (when (> no-warnings 1)
2161 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2162
2163;; Backward compatibility checks and fixes
2164;; option `vhdl-compiler' changed format
2165(unless (stringp vhdl-compiler)
2166 (setq vhdl-compiler "ModelSim")
2167 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2168
2169;; option `vhdl-standard' changed format
2170(unless (listp vhdl-standard)
2171 (setq vhdl-standard '(87 nil))
2172 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2173
2174;; option `vhdl-model-alist' changed format
2175(when (= (length (car vhdl-model-alist)) 3)
2176 (let ((old-alist vhdl-model-alist)
2177 new-alist)
2178 (while old-alist
2179 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2180 (setq old-alist (cdr old-alist)))
2181 (setq vhdl-model-alist (nreverse new-alist)))
2182 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2183
2184;; option `vhdl-project-alist' changed format
2185(when (= (length (car vhdl-project-alist)) 3)
2186 (let ((old-alist vhdl-project-alist)
2187 new-alist)
2188 (while old-alist
2189 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2190 (setq old-alist (cdr old-alist)))
2191 (setq vhdl-project-alist (nreverse new-alist)))
2192 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2193
2194;; option `vhdl-project-alist' changed format (3.31.1)
2195(when (= (length (car vhdl-project-alist)) 4)
2196 (let ((old-alist vhdl-project-alist)
2197 new-alist elem)
2198 (while old-alist
2199 (setq elem (car old-alist))
2200 (setq new-alist
2201 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2202 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2203 new-alist))
2204 (setq old-alist (cdr old-alist)))
2205 (setq vhdl-project-alist (nreverse new-alist)))
2206 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2207
2208;; option `vhdl-project-alist' changed format (3.31.12)
2209(when (= (length (car vhdl-project-alist)) 10)
2210 (let ((tmp-alist vhdl-project-alist))
2211 (while tmp-alist
2212 (setcdr (nthcdr 3 (car tmp-alist))
2213 (cons "" (nthcdr 4 (car tmp-alist))))
2214 (setq tmp-alist (cdr tmp-alist))))
2215 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2216
2217;; option `vhdl-compiler-alist' changed format (3.31.1)
2218(when (= (length (car vhdl-compiler-alist)) 7)
2219 (let ((old-alist vhdl-compiler-alist)
2220 new-alist elem)
2221 (while old-alist
2222 (setq elem (car old-alist))
2223 (setq new-alist
2224 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2225 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2226 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2227 (nth 5 elem) (nth 6 elem) nil)
2228 new-alist))
2229 (setq old-alist (cdr old-alist)))
2230 (setq vhdl-compiler-alist (nreverse new-alist)))
2231 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2232
2233;; option `vhdl-compiler-alist' changed format (3.31.10)
2234(when (= (length (car vhdl-compiler-alist)) 12)
2235 (let ((tmp-alist vhdl-compiler-alist))
2236 (while tmp-alist
2237 (setcdr (nthcdr 4 (car tmp-alist))
2238 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2239 (setq tmp-alist (cdr tmp-alist))))
2240 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2241
2242;; option `vhdl-compiler-alist' changed format (3.31.11)
2243(when (= (length (car vhdl-compiler-alist)) 13)
2244 (let ((tmp-alist vhdl-compiler-alist))
2245 (while tmp-alist
2246 (setcdr (nthcdr 3 (car tmp-alist))
2247 (cons "" (nthcdr 4 (car tmp-alist))))
2248 (setq tmp-alist (cdr tmp-alist))))
2249 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2250
2251;; option `vhdl-compiler-alist' changed format (3.32.7)
2252(when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2253 (let ((tmp-alist vhdl-compiler-alist))
2254 (while tmp-alist
2255 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2256 '(0 . nil))
2257 (setq tmp-alist (cdr tmp-alist))))
2258 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2259
2260;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2261(when (equal vhdl-project "")
2262 (setq vhdl-project nil)
2263 (customize-save-variable 'vhdl-project vhdl-project))
2264
2265;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2266(when (stringp vhdl-project-file-name)
2267 (setq vhdl-project-file-name (list vhdl-project-file-name))
2268 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2269
2270;; option `speedbar-indentation-width': introduced in speedbar 0.10
2271(if (not (boundp 'speedbar-indentation-width))
2272 (defvar speedbar-indentation-width 2)
2273 ;; set default to 2 if not already customized
2274 (unless (get 'speedbar-indentation-width 'saved-value)
2275 (setq speedbar-indentation-width 2)))
2276
2277
2278;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2279;;; Help functions / inline substitutions / macros
2280;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2281
2282(defun vhdl-standard-p (standard)
2283 "Check if STANDARD is specified as used standard."
2284 (or (eq standard (car vhdl-standard))
2285 (memq standard (cadr vhdl-standard))))
2286
2287(defun vhdl-project-p (&optional warning)
2288 "Return non-nil if a project is displayed, i.e. directories or files are
2289specified."
2290 (if (assoc vhdl-project vhdl-project-alist)
2291 vhdl-project
2292 (when (and vhdl-project warning)
2293 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2294 nil))
2295
2296(defun vhdl-resolve-env-variable (string)
2297 "Resolve environment variables in STRING."
2298 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2299 (setq string (concat (match-string 1 string)
2300 (getenv (match-string 2 string))
2301 (match-string 4 string))))
2302 string)
2303
2304(defun vhdl-default-directory ()
2305 "Return the default directory of the current project or the directory of the
2306current buffer if no project is defined."
2307 (if (vhdl-project-p)
2308 (expand-file-name (vhdl-resolve-env-variable
2309 (nth 1 (aget vhdl-project-alist vhdl-project))))
2310 default-directory))
2311
2312(defmacro vhdl-prepare-search-1 (&rest body)
2313 "Enable case insensitive search and switch to syntax table that includes '_',
2314then execute BODY, and finally restore the old environment. Used for
2315consistent searching."
68a47940 2316 `(let ((case-fold-search t)) ; case insensitive search
3dcb36b7 2317 ;; use extended syntax table
68a47940
SM
2318 (with-syntax-table vhdl-mode-ext-syntax-table
2319 ,@body)))
3dcb36b7
JB
2320
2321(defmacro vhdl-prepare-search-2 (&rest body)
2322 "Enable case insensitive search, switch to syntax table that includes '_',
2323and remove `intangible' overlays, then execute BODY, and finally restore the
2324old environment. Used for consistent searching."
68a47940 2325 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
3dcb36b7
JB
2326 `(let ((case-fold-search t) ; case insensitive search
2327 (current-syntax-table (syntax-table))
68a47940 2328 overlay-all-list overlay-intangible-list overlay)
3dcb36b7
JB
2329 ;; use extended syntax table
2330 (set-syntax-table vhdl-mode-ext-syntax-table)
2331 ;; remove `intangible' overlays
2332 (when (fboundp 'overlay-lists)
2333 (setq overlay-all-list (overlay-lists))
2334 (setq overlay-all-list
2335 (append (car overlay-all-list) (cdr overlay-all-list)))
2336 (while overlay-all-list
2337 (setq overlay (car overlay-all-list))
2338 (when (memq 'intangible (overlay-properties overlay))
2339 (setq overlay-intangible-list
2340 (cons overlay overlay-intangible-list))
2341 (overlay-put overlay 'intangible nil))
2342 (setq overlay-all-list (cdr overlay-all-list))))
2343 ;; execute BODY safely
68a47940
SM
2344 (unwind-protect
2345 (progn ,@body)
2346 ;; restore syntax table
2347 (set-syntax-table current-syntax-table)
2348 ;; restore `intangible' overlays
2349 (when (fboundp 'overlay-lists)
2350 (while overlay-intangible-list
2351 (overlay-put (car overlay-intangible-list) 'intangible t)
2352 (setq overlay-intangible-list
2353 (cdr overlay-intangible-list)))))))
3dcb36b7
JB
2354
2355(defmacro vhdl-visit-file (file-name issue-error &rest body)
2356 "Visit file FILE-NAME and execute BODY."
2357 `(if (null ,file-name)
2358 (progn ,@body)
2359 (unless (file-directory-p ,file-name)
2360 (let ((source-buffer (current-buffer))
2361 (visiting-buffer (find-buffer-visiting ,file-name))
2362 file-opened)
2363 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2364 (condition-case ()
2365 (progn (set-buffer (create-file-buffer ,file-name))
2366 (setq file-opened t)
2367 (vhdl-insert-file-contents ,file-name)
2368 (modify-syntax-entry ?\- ". 12" (syntax-table))
2369 (modify-syntax-entry ?\n ">" (syntax-table))
2370 (modify-syntax-entry ?\^M ">" (syntax-table))
2371 (modify-syntax-entry ?_ "w" (syntax-table))
2372 t)
2373 (error
2374 (if ,issue-error
2375 (progn
2376 (when file-opened (kill-buffer (current-buffer)))
2377 (set-buffer source-buffer)
ec3ec9cc 2378 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
3dcb36b7
JB
2379 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2380 nil))))
2381 (condition-case info
2382 (progn ,@body)
2383 (error
2384 (if ,issue-error
2385 (progn
2386 (when file-opened (kill-buffer (current-buffer)))
2387 (set-buffer source-buffer)
2388 (error (cadr info)))
2389 (vhdl-warning (cadr info))))))
2390 (when file-opened (kill-buffer (current-buffer)))
2391 (set-buffer source-buffer)))))
2392
2393(defun vhdl-insert-file-contents (filename)
2394 "Nicked from `insert-file-contents-literally', but allow coding system
2395conversion."
2396 (let ((format-alist nil)
2397 (after-insert-file-functions nil)
2398 (jka-compr-compression-info-list nil))
2399 (insert-file-contents filename t)))
2400
2401(defun vhdl-sort-alist (alist)
a4c6cfad 2402 "Sort ALIST."
3dcb36b7
JB
2403 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2404
2405(defun vhdl-get-subdirs (directory)
2406 "Recursively get subdirectories of DIRECTORY."
2407 (let ((dir-list (list (file-name-as-directory directory)))
2408 file-list)
2409 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2410 (while file-list
2411 (when (file-directory-p (car file-list))
2412 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2413 (setq file-list (cdr file-list)))
2414 dir-list))
2415
2416(defun vhdl-aput (alist-symbol key &optional value)
2417 "As `aput', but delete key-value pair if VALUE is nil."
2418 (if value
2419 (aput alist-symbol key value)
2420 (adelete alist-symbol key)))
2421
2422(defun vhdl-delete (elt list)
2423 "Delete by side effect the first occurrence of ELT as a member of LIST."
2424 (setq list (cons nil list))
2425 (let ((list1 list))
2426 (while (and (cdr list1) (not (equal elt (cadr list1))))
2427 (setq list1 (cdr list1)))
2428 (when list
2429 (setcdr list1 (cddr list1))))
2430 (cdr list))
2431
2432(defun vhdl-speedbar-refresh (&optional key)
2433 "Refresh directory or project with name KEY."
2434 (when (and (boundp 'speedbar-frame)
2435 (frame-live-p speedbar-frame))
2436 (let ((pos (point))
2437 (last-frame (selected-frame)))
2438 (if (null key)
2439 (speedbar-refresh)
2440 (select-frame speedbar-frame)
2441 (when (save-excursion
2442 (goto-char (point-min))
2443 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2444 (goto-char (match-end 1))
2445 (speedbar-do-function-pointer)
2446 (backward-char 2)
2447 (speedbar-do-function-pointer)
2448 (message "Refreshing speedbar...done"))
2449 (select-frame last-frame)))))
2450
2451(defun vhdl-show-messages ()
2452 "Get *Messages* buffer to show recent messages."
2453 (interactive)
f8246027 2454 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
3dcb36b7
JB
2455
2456(defun vhdl-use-direct-instantiation ()
2457 "Return whether direct instantiation is used."
2458 (or (eq vhdl-use-direct-instantiation 'always)
2459 (and (eq vhdl-use-direct-instantiation 'standard)
2460 (not (vhdl-standard-p '87)))))
2461
2462(defun vhdl-max-marker (marker1 marker2)
2463 "Return larger marker."
2464 (if (> marker1 marker2) marker1 marker2))
2465
2466(defun vhdl-goto-marker (marker)
2467 "Goto marker in appropriate buffer."
2468 (when (markerp marker)
2469 (set-buffer (marker-buffer marker)))
2470 (goto-char marker))
2471
2472(defun vhdl-menu-split (list title)
2473 "Split menu LIST into several submenues, if number of
2474elements > `vhdl-menu-max-size'."
2475 (if (> (length list) vhdl-menu-max-size)
2476 (let ((remain list)
2477 (result '())
2478 (sublist '())
2479 (menuno 1)
2480 (i 0))
2481 (while remain
2482 (setq sublist (cons (car remain) sublist))
2483 (setq remain (cdr remain))
2484 (setq i (+ i 1))
2485 (if (= i vhdl-menu-max-size)
2486 (progn
2487 (setq result (cons (cons (format "%s %s" title menuno)
2488 (nreverse sublist)) result))
2489 (setq i 0)
2490 (setq menuno (+ menuno 1))
2491 (setq sublist '()))))
2492 (and sublist
2493 (setq result (cons (cons (format "%s %s" title menuno)
2494 (nreverse sublist)) result)))
2495 (nreverse result))
2496 list))
2497
2498
2499;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2500;;; Bindings
2501;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2502
2503;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2504;; Key bindings
2505
2506(defvar vhdl-template-map nil
2507 "Keymap for VHDL templates.")
2508
2509(defun vhdl-template-map-init ()
2510 "Initialize `vhdl-template-map'."
2511 (setq vhdl-template-map (make-sparse-keymap))
2512 ;; key bindings for VHDL templates
2513 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2514 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2515 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2516 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2517 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2518 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2519 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2520 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2521 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
5eabfe72
KH
2522 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2523 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2524 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2525 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2526 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2527 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2528 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2529 (define-key vhdl-template-map "el" 'vhdl-template-else)
2530 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2531 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2532 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2533 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2534 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2535 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2536 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2537 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2538 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2539 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2540 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2541 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2542 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2543 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2544 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2545 (define-key vhdl-template-map "li" 'vhdl-template-library)
2546 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2547 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2548 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2549 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2550 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2551 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2552 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2553 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2554 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2555 (define-key vhdl-template-map "po" 'vhdl-template-port)
2556 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2557 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2558 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2559 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2560 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2561 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2562 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2563 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2564 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2565 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2566 (define-key vhdl-template-map "us" 'vhdl-template-use)
2567 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2568 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2569 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2570 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2571 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2572 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2573 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2574 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2575 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2576 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2577 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2578 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2579 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2580 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2581 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2582 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2583 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2584 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2585 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2586 (when (vhdl-standard-p 'ams)
2587 (define-key vhdl-template-map "br" 'vhdl-template-break)
2588 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2589 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2590 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2591 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2592 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2593 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2594 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2595 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2596 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2597 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2598 )
2599 (when (vhdl-standard-p 'math)
2600 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2601 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2602 ))
2603
2604;; initialize template map for VHDL Mode
2605(vhdl-template-map-init)
2606
2607(defun vhdl-function-name (prefix string &optional postfix)
2608 "Generate a Lisp function name.
2609PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2610STRING are replaced by `-' and substrings are converted to lower case."
2611 (let ((name prefix))
2612 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2613 (setq name
2614 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2615 (setq string (substring string (match-beginning 2))))
2616 (when postfix (setq name (concat name "-" postfix)))
2617 (intern name)))
2618
3dcb36b7 2619(defvar vhdl-model-map nil
5eabfe72
KH
2620 "Keymap for VHDL models.")
2621
2622(defun vhdl-model-map-init ()
2623 "Initialize `vhdl-model-map'."
2624 (setq vhdl-model-map (make-sparse-keymap))
2625 ;; key bindings for VHDL models
2626 (let ((model-alist vhdl-model-alist) model)
2627 (while model-alist
2628 (setq model (car model-alist))
2629 (define-key vhdl-model-map (nth 2 model)
2630 (vhdl-function-name "vhdl-model" (nth 0 model)))
2631 (setq model-alist (cdr model-alist)))))
2632
2633;; initialize user model map for VHDL Mode
2634(vhdl-model-map-init)
d2ddb974 2635
3dcb36b7 2636(defvar vhdl-mode-map nil
d2ddb974
KH
2637 "Keymap for VHDL Mode.")
2638
5eabfe72
KH
2639(defun vhdl-mode-map-init ()
2640 "Initialize `vhdl-mode-map'."
d2ddb974 2641 (setq vhdl-mode-map (make-sparse-keymap))
5eabfe72 2642 ;; template key bindings
0a2e512a 2643 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
5eabfe72 2644 ;; model key bindings
0a2e512a 2645 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
d2ddb974 2646 ;; standard key bindings
0a2e512a
RF
2647 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2648 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2649 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2650 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2651 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2652 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2653 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
f8246027 2654 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
0a2e512a
RF
2655 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2656 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2657 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
5eabfe72 2658 ;; backspace/delete key bindings
0a2e512a 2659 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
3dcb36b7 2660 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
0a2e512a 2661 (define-key vhdl-mode-map [delete] 'delete-char)
3dcb36b7 2662 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
5eabfe72 2663 ;; mode specific key bindings
3dcb36b7
JB
2664 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2665 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2666 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2667 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2668 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2669 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2670 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
0a2e512a 2671 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
5eabfe72 2672 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
3dcb36b7 2673 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
5eabfe72
KH
2674 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2675 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2676 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2677 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2678 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2679 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2680 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
f8246027 2681 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
5eabfe72
KH
2682 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2683 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
3dcb36b7 2684 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
5eabfe72
KH
2685 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2686 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
3dcb36b7
JB
2687 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2688 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2689 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2690 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2691 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2692 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2693 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
83a38a5a
SM
2694 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2695 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2696 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2697 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2698 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2699 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
0a2e512a
RF
2700 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2701 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
3dcb36b7
JB
2702 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2703 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
0a2e512a 2704 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
3dcb36b7
JB
2705 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2706 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2707 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2708 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2709 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2710 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2711 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2712 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2713 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2714 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2715 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2716 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2717 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2718 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2719 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
5eabfe72
KH
2720 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2721 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2722 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2723 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2724 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2725 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2726 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2727 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2728 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
3dcb36b7
JB
2729 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2730 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2731 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2732 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2733 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
0a2e512a
RF
2734 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2735 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
3dcb36b7
JB
2736 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2737 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
83a38a5a
SM
2738 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2739 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
0a2e512a
RF
2740 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2741 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2742 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2743 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
5eabfe72 2744 ;; insert commands bindings
3dcb36b7 2745 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
5eabfe72
KH
2746 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2747 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2748 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2749 ;; electric key bindings
0a2e512a
RF
2750 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2751 (when vhdl-intelligent-tab
2752 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2753 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2754 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2755 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2756 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2757 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2758 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2759 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2760 (define-key vhdl-mode-map "." 'vhdl-electric-period)
5eabfe72 2761 (when (vhdl-standard-p 'ams)
0a2e512a 2762 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
5eabfe72
KH
2763
2764;; initialize mode map for VHDL Mode
2765(vhdl-mode-map-init)
d2ddb974
KH
2766
2767;; define special minibuffer keymap for enabling word completion in minibuffer
2768;; (useful in template generator prompts)
4bcb9c95
SM
2769(defvar vhdl-minibuffer-local-map
2770 (let ((map (make-sparse-keymap)))
2771 (set-keymap-parent map minibuffer-local-map)
2772 (when vhdl-word-completion-in-minibuffer
2773 (define-key map "\t" 'vhdl-minibuffer-tab))
2774 map)
d2ddb974
KH
2775 "Keymap for minibuffer used in VHDL Mode.")
2776
5eabfe72
KH
2777;; set up electric character functions to work with
2778;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
51b5ad57 2779(mapc
5eabfe72
KH
2780 (function
2781 (lambda (sym)
2782 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2783 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2784 '(vhdl-electric-space
2785 vhdl-electric-tab
2786 vhdl-electric-return
2787 vhdl-electric-dash
2788 vhdl-electric-open-bracket
2789 vhdl-electric-close-bracket
2790 vhdl-electric-quote
2791 vhdl-electric-semicolon
2792 vhdl-electric-comma
2793 vhdl-electric-period
2794 vhdl-electric-equal))
2795
3dcb36b7
JB
2796;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2797;; Syntax table
2798
d2ddb974 2799(defvar vhdl-mode-syntax-table nil
5eabfe72 2800 "Syntax table used in `vhdl-mode' buffers.")
d2ddb974 2801
3dcb36b7
JB
2802(defvar vhdl-mode-ext-syntax-table nil
2803 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2804
5eabfe72
KH
2805(defun vhdl-mode-syntax-table-init ()
2806 "Initialize `vhdl-mode-syntax-table'."
d2ddb974 2807 (setq vhdl-mode-syntax-table (make-syntax-table))
5eabfe72
KH
2808 ;; define punctuation
2809 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2810 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2811 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2812 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2813 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2814 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2815 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2816 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2817 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2818 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2819 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2820 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2821 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2822 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2823 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2824 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2825 ;; define string
2826 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2827 ;; define underscore
2828 (when vhdl-underscore-is-part-of-word
3dcb36b7 2829 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
5eabfe72
KH
2830 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2831 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2832 ;; and \n and \^M end a comment
2833 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2834 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2835 ;; define parentheses to match
2836 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2837 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2838 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2839 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2840 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
3dcb36b7
JB
2841 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2842 ;; extended syntax table including '_' (for simpler search regexps)
2843 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2844 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
5eabfe72
KH
2845
2846;; initialize syntax table for VHDL Mode
2847(vhdl-mode-syntax-table-init)
2848
d2ddb974
KH
2849(defvar vhdl-syntactic-context nil
2850 "Buffer local variable containing syntactic analysis list.")
2851(make-variable-buffer-local 'vhdl-syntactic-context)
2852
5eabfe72 2853;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2854;; Abbrev ook bindings
d2ddb974
KH
2855
2856(defvar vhdl-mode-abbrev-table nil
5eabfe72
KH
2857 "Abbrev table to use in `vhdl-mode' buffers.")
2858
2859(defun vhdl-mode-abbrev-table-init ()
2860 "Initialize `vhdl-mode-abbrev-table'."
5eabfe72
KH
2861 (define-abbrev-table 'vhdl-mode-abbrev-table
2862 (append
2863 (when (memq 'vhdl vhdl-electric-keywords)
2864 ;; VHDL'93 keywords
86905e5b
SM
2865 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2866 '(
2867 ("--" . vhdl-template-display-comment-hook)
2868 ("abs" . vhdl-template-default-hook)
2869 ("access" . vhdl-template-default-hook)
2870 ("after" . vhdl-template-default-hook)
2871 ("alias" . vhdl-template-alias-hook)
2872 ("all" . vhdl-template-default-hook)
2873 ("and" . vhdl-template-default-hook)
2874 ("arch" . vhdl-template-architecture-hook)
2875 ("architecture" . vhdl-template-architecture-hook)
2876 ("array" . vhdl-template-default-hook)
2877 ("assert" . vhdl-template-assert-hook)
2878 ("attr" . vhdl-template-attribute-hook)
2879 ("attribute" . vhdl-template-attribute-hook)
2880 ("begin" . vhdl-template-default-indent-hook)
2881 ("block" . vhdl-template-block-hook)
2882 ("body" . vhdl-template-default-hook)
2883 ("buffer" . vhdl-template-default-hook)
2884 ("bus" . vhdl-template-default-hook)
2885 ("case" . vhdl-template-case-hook)
2886 ("comp" . vhdl-template-component-hook)
2887 ("component" . vhdl-template-component-hook)
2888 ("cond" . vhdl-template-conditional-signal-asst-hook)
2889 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2890 ("conf" . vhdl-template-configuration-hook)
2891 ("configuration" . vhdl-template-configuration-hook)
2892 ("cons" . vhdl-template-constant-hook)
2893 ("constant" . vhdl-template-constant-hook)
2894 ("disconnect" . vhdl-template-disconnect-hook)
2895 ("downto" . vhdl-template-default-hook)
2896 ("else" . vhdl-template-else-hook)
2897 ("elseif" . vhdl-template-elsif-hook)
2898 ("elsif" . vhdl-template-elsif-hook)
2899 ("end" . vhdl-template-default-indent-hook)
2900 ("entity" . vhdl-template-entity-hook)
2901 ("exit" . vhdl-template-exit-hook)
2902 ("file" . vhdl-template-file-hook)
2903 ("for" . vhdl-template-for-hook)
2904 ("func" . vhdl-template-function-hook)
2905 ("function" . vhdl-template-function-hook)
2906 ("generic" . vhdl-template-generic-hook)
2907 ("group" . vhdl-template-group-hook)
2908 ("guarded" . vhdl-template-default-hook)
2909 ("if" . vhdl-template-if-hook)
2910 ("impure" . vhdl-template-default-hook)
2911 ("in" . vhdl-template-default-hook)
2912 ("inertial" . vhdl-template-default-hook)
2913 ("inout" . vhdl-template-default-hook)
2914 ("inst" . vhdl-template-instance-hook)
2915 ("instance" . vhdl-template-instance-hook)
2916 ("is" . vhdl-template-default-hook)
2917 ("label" . vhdl-template-default-hook)
2918 ("library" . vhdl-template-library-hook)
2919 ("linkage" . vhdl-template-default-hook)
2920 ("literal" . vhdl-template-default-hook)
2921 ("loop" . vhdl-template-bare-loop-hook)
2922 ("map" . vhdl-template-map-hook)
2923 ("mod" . vhdl-template-default-hook)
2924 ("nand" . vhdl-template-default-hook)
2925 ("new" . vhdl-template-default-hook)
2926 ("next" . vhdl-template-next-hook)
2927 ("nor" . vhdl-template-default-hook)
2928 ("not" . vhdl-template-default-hook)
2929 ("null" . vhdl-template-default-hook)
2930 ("of" . vhdl-template-default-hook)
2931 ("on" . vhdl-template-default-hook)
2932 ("open" . vhdl-template-default-hook)
2933 ("or" . vhdl-template-default-hook)
2934 ("others" . vhdl-template-others-hook)
2935 ("out" . vhdl-template-default-hook)
2936 ("pack" . vhdl-template-package-hook)
2937 ("package" . vhdl-template-package-hook)
2938 ("port" . vhdl-template-port-hook)
2939 ("postponed" . vhdl-template-default-hook)
2940 ("procedure" . vhdl-template-procedure-hook)
2941 ("process" . vhdl-template-process-hook)
2942 ("pure" . vhdl-template-default-hook)
2943 ("range" . vhdl-template-default-hook)
2944 ("record" . vhdl-template-default-hook)
2945 ("register" . vhdl-template-default-hook)
2946 ("reject" . vhdl-template-default-hook)
2947 ("rem" . vhdl-template-default-hook)
2948 ("report" . vhdl-template-report-hook)
2949 ("return" . vhdl-template-return-hook)
2950 ("rol" . vhdl-template-default-hook)
2951 ("ror" . vhdl-template-default-hook)
2952 ("select" . vhdl-template-selected-signal-asst-hook)
2953 ("severity" . vhdl-template-default-hook)
2954 ("shared" . vhdl-template-default-hook)
2955 ("sig" . vhdl-template-signal-hook)
2956 ("signal" . vhdl-template-signal-hook)
2957 ("sla" . vhdl-template-default-hook)
2958 ("sll" . vhdl-template-default-hook)
2959 ("sra" . vhdl-template-default-hook)
2960 ("srl" . vhdl-template-default-hook)
2961 ("subtype" . vhdl-template-subtype-hook)
2962 ("then" . vhdl-template-default-hook)
2963 ("to" . vhdl-template-default-hook)
2964 ("transport" . vhdl-template-default-hook)
2965 ("type" . vhdl-template-type-hook)
2966 ("unaffected" . vhdl-template-default-hook)
2967 ("units" . vhdl-template-default-hook)
2968 ("until" . vhdl-template-default-hook)
2969 ("use" . vhdl-template-use-hook)
2970 ("var" . vhdl-template-variable-hook)
2971 ("variable" . vhdl-template-variable-hook)
2972 ("wait" . vhdl-template-wait-hook)
2973 ("when" . vhdl-template-when-hook)
2974 ("while" . vhdl-template-while-loop-hook)
2975 ("with" . vhdl-template-with-hook)
2976 ("xnor" . vhdl-template-default-hook)
2977 ("xor" . vhdl-template-default-hook)
2978 )))
5eabfe72
KH
2979 ;; VHDL-AMS keywords
2980 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
86905e5b
SM
2981 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2982 '(
2983 ("across" . vhdl-template-default-hook)
2984 ("break" . vhdl-template-break-hook)
2985 ("limit" . vhdl-template-limit-hook)
2986 ("nature" . vhdl-template-nature-hook)
2987 ("noise" . vhdl-template-default-hook)
2988 ("procedural" . vhdl-template-procedural-hook)
2989 ("quantity" . vhdl-template-quantity-hook)
2990 ("reference" . vhdl-template-default-hook)
2991 ("spectrum" . vhdl-template-default-hook)
2992 ("subnature" . vhdl-template-subnature-hook)
2993 ("terminal" . vhdl-template-terminal-hook)
2994 ("through" . vhdl-template-default-hook)
2995 ("tolerance" . vhdl-template-default-hook)
2996 )))
5eabfe72
KH
2997 ;; user model keywords
2998 (when (memq 'user vhdl-electric-keywords)
86905e5b
SM
2999 (let (abbrev-list keyword)
3000 (dolist (elem vhdl-model-alist)
3001 (setq keyword (nth 3 elem))
5eabfe72 3002 (unless (equal keyword "")
86905e5b
SM
3003 (push (list keyword ""
3004 (vhdl-function-name
3005 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3006 abbrev-list)))
5eabfe72
KH
3007 abbrev-list)))))
3008
3009;; initialize abbrev table for VHDL Mode
3010(vhdl-mode-abbrev-table-init)
3011
3012;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3013;; Template completion lists
3014
3015(defvar vhdl-template-construct-alist nil
3016 "List of built-in construct templates.")
3017
3018(defun vhdl-template-construct-alist-init ()
3019 "Initialize `vhdl-template-construct-alist'."
3020 (setq
3021 vhdl-template-construct-alist
3022 (append
3023 '(
3024 ("alias declaration" vhdl-template-alias)
3025 ("architecture body" vhdl-template-architecture)
3026 ("assertion" vhdl-template-assert)
3027 ("attribute declaration" vhdl-template-attribute-decl)
3028 ("attribute specification" vhdl-template-attribute-spec)
3029 ("block configuration" vhdl-template-block-configuration)
3030 ("block statement" vhdl-template-block)
3031 ("case statement" vhdl-template-case-is)
3032 ("component configuration" vhdl-template-component-conf)
3033 ("component declaration" vhdl-template-component-decl)
3034 ("component instantiation statement" vhdl-template-component-inst)
3035 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3036 ("configuration declaration" vhdl-template-configuration-decl)
3037 ("configuration specification" vhdl-template-configuration-spec)
3038 ("constant declaration" vhdl-template-constant)
3039 ("disconnection specification" vhdl-template-disconnect)
3040 ("entity declaration" vhdl-template-entity)
3041 ("exit statement" vhdl-template-exit)
3042 ("file declaration" vhdl-template-file)
3043 ("generate statement" vhdl-template-generate)
3044 ("generic clause" vhdl-template-generic)
3045 ("group declaration" vhdl-template-group-decl)
3046 ("group template declaration" vhdl-template-group-template)
3047 ("if statement" vhdl-template-if-then)
3048 ("library clause" vhdl-template-library)
3049 ("loop statement" vhdl-template-loop)
3050 ("next statement" vhdl-template-next)
3051 ("package declaration" vhdl-template-package-decl)
3052 ("package body" vhdl-template-package-body)
3053 ("port clause" vhdl-template-port)
3054 ("process statement" vhdl-template-process)
3055 ("report statement" vhdl-template-report)
3056 ("return statement" vhdl-template-return)
3057 ("selected signal assignment" vhdl-template-selected-signal-asst)
3058 ("signal declaration" vhdl-template-signal)
3059 ("subprogram declaration" vhdl-template-subprogram-decl)
3060 ("subprogram body" vhdl-template-subprogram-body)
3061 ("subtype declaration" vhdl-template-subtype)
3062 ("type declaration" vhdl-template-type)
3063 ("use clause" vhdl-template-use)
3064 ("variable declaration" vhdl-template-variable)
3065 ("wait statement" vhdl-template-wait)
3066 )
3067 (when (vhdl-standard-p 'ams)
3068 '(
3069 ("break statement" vhdl-template-break)
3070 ("nature declaration" vhdl-template-nature)
3071 ("quantity declaration" vhdl-template-quantity)
3072 ("simultaneous case statement" vhdl-template-case-use)
3073 ("simultaneous if statement" vhdl-template-if-use)
3074 ("simultaneous procedural statement" vhdl-template-procedural)
3075 ("step limit specification" vhdl-template-limit)
3076 ("subnature declaration" vhdl-template-subnature)
3077 ("terminal declaration" vhdl-template-terminal)
3078 )))))
d2ddb974 3079
5eabfe72
KH
3080;; initialize for VHDL Mode
3081(vhdl-template-construct-alist-init)
3082
3083(defvar vhdl-template-package-alist nil
3084 "List of built-in package templates.")
3085
3086(defun vhdl-template-package-alist-init ()
3087 "Initialize `vhdl-template-package-alist'."
3088 (setq
3089 vhdl-template-package-alist
3090 (append
3091 '(
3092 ("numeric_bit" vhdl-template-package-numeric-bit)
3093 ("numeric_std" vhdl-template-package-numeric-std)
3094 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3095 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3096 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3097 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3098 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3099 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3100 ("textio" vhdl-template-package-textio)
3101 )
3102 (when (vhdl-standard-p 'math)
3103 '(
3104 ("math_complex" vhdl-template-package-math-complex)
3105 ("math_real" vhdl-template-package-math-real)
3106 )))))
d2ddb974 3107
5eabfe72
KH
3108;; initialize for VHDL Mode
3109(vhdl-template-package-alist-init)
d2ddb974 3110
5eabfe72 3111(defvar vhdl-template-directive-alist
3dcb36b7
JB
3112 '(
3113 ("translate_on" vhdl-template-directive-translate-on)
3114 ("translate_off" vhdl-template-directive-translate-off)
3115 ("synthesis_on" vhdl-template-directive-synthesis-on)
3116 ("synthesis_off" vhdl-template-directive-synthesis-off)
3117 )
5eabfe72 3118 "List of built-in directive templates.")
d2ddb974 3119
5eabfe72
KH
3120
3121;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3122;;; Menues
3123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3124
3125;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
3126;; VHDL menu (using `easy-menu.el')
3127
5eabfe72
KH
3128(defun vhdl-customize ()
3129 "Call the customize function with `vhdl' as argument."
3130 (interactive)
3131 (customize-browse 'vhdl))
3132
5eabfe72
KH
3133(defun vhdl-create-mode-menu ()
3134 "Create VHDL Mode menu."
3dcb36b7
JB
3135 `("VHDL"
3136 ,(append
3137 '("Project"
3138 ["None" (vhdl-set-project "")
3139 :style radio :selected (null vhdl-project)]
3140 "--")
3141 ;; add menu entries for defined projects
3142 (let ((project-alist vhdl-project-alist) menu-list name)
3143 (while project-alist
3144 (setq name (caar project-alist))
3145 (setq menu-list
3146 (cons `[,name (vhdl-set-project ,name)
3147 :style radio :selected (equal ,name vhdl-project)]
3148 menu-list))
3149 (setq project-alist (cdr project-alist)))
3150 (setq menu-list
3151 (if vhdl-project-sort
3152 (sort menu-list
3153 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3154 (nreverse menu-list)))
3155 (vhdl-menu-split menu-list "Project"))
3156 '("--" "--"
3157 ["Select Project..." vhdl-set-project t]
0a2e512a 3158 ["Set As Default Project" vhdl-set-default-project t]
3dcb36b7
JB
3159 "--"
3160 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3161 ["Import Project..." vhdl-import-project
3162 :keys "C-c C-p C-m" :active t]
3163 ["Export Project" vhdl-export-project vhdl-project]
3164 "--"
3165 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
d2ddb974 3166 "--"
3dcb36b7
JB
3167 ("Compile"
3168 ["Compile Buffer" vhdl-compile t]
3169 ["Stop Compilation" kill-compilation t]
3170 "--"
3171 ["Make" vhdl-make t]
3172 ["Generate Makefile" vhdl-generate-makefile t]
3173 "--"
3174 ["Next Error" next-error t]
3175 ["Previous Error" previous-error t]
3176 ["First Error" first-error t]
3177 "--"
3178 ,(append
3179 '("Compiler")
3180 ;; add menu entries for defined compilers
3181 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3182 (while comp-alist
3183 (setq name (caar comp-alist))
3184 (setq menu-list
3185 (cons `[,name (setq vhdl-compiler ,name)
3186 :style radio :selected (equal ,name vhdl-compiler)]
3187 menu-list))
3188 (setq comp-alist (cdr comp-alist)))
3189 (setq menu-list (nreverse menu-list))
3190 (vhdl-menu-split menu-list "Compiler"))
3191 '("--" "--"
3192 ["Select Compiler..." vhdl-set-compiler t]
3193 "--"
3194 ["Customize Compiler..."
3195 (customize-option 'vhdl-compiler-alist) t])))
5eabfe72 3196 "--"
3dcb36b7
JB
3197 ,(append
3198 '("Template"
3199 ("VHDL Construct 1"
3200 ["Alias" vhdl-template-alias t]
3201 ["Architecture" vhdl-template-architecture t]
3202 ["Assert" vhdl-template-assert t]
3203 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3204 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3205 ["Block" vhdl-template-block t]
3206 ["Case" vhdl-template-case-is t]
3207 ["Component (Decl)" vhdl-template-component-decl t]
3208 ["(Component) Instance" vhdl-template-component-inst t]
3209 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3210 ["Configuration (Block)" vhdl-template-block-configuration t]
3211 ["Configuration (Comp)" vhdl-template-component-conf t]
3212 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3213 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3214 ["Constant" vhdl-template-constant t]
3215 ["Disconnect" vhdl-template-disconnect t]
3216 ["Else" vhdl-template-else t]
3217 ["Elsif" vhdl-template-elsif t]
3218 ["Entity" vhdl-template-entity t]
3219 ["Exit" vhdl-template-exit t]
3220 ["File" vhdl-template-file t]
3221 ["For (Generate)" vhdl-template-for-generate t]
3222 ["For (Loop)" vhdl-template-for-loop t]
3223 ["Function (Body)" vhdl-template-function-body t]
3224 ["Function (Decl)" vhdl-template-function-decl t]
3225 ["Generic" vhdl-template-generic t]
3226 ["Group (Decl)" vhdl-template-group-decl t]
3227 ["Group (Template)" vhdl-template-group-template t])
3228 ("VHDL Construct 2"
3229 ["If (Generate)" vhdl-template-if-generate t]
3230 ["If (Then)" vhdl-template-if-then t]
3231 ["Library" vhdl-template-library t]
3232 ["Loop" vhdl-template-bare-loop t]
3233 ["Map" vhdl-template-map t]
3234 ["Next" vhdl-template-next t]
3235 ["Others (Aggregate)" vhdl-template-others t]
3236 ["Package (Decl)" vhdl-template-package-decl t]
3237 ["Package (Body)" vhdl-template-package-body t]
3238 ["Port" vhdl-template-port t]
3239 ["Procedure (Body)" vhdl-template-procedure-body t]
3240 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3241 ["Process (Comb)" vhdl-template-process-comb t]
3242 ["Process (Seq)" vhdl-template-process-seq t]
3243 ["Report" vhdl-template-report t]
3244 ["Return" vhdl-template-return t]
3245 ["Select" vhdl-template-selected-signal-asst t]
3246 ["Signal" vhdl-template-signal t]
3247 ["Subtype" vhdl-template-subtype t]
3248 ["Type" vhdl-template-type t]
3249 ["Use" vhdl-template-use t]
3250 ["Variable" vhdl-template-variable t]
3251 ["Wait" vhdl-template-wait t]
3252 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3253 ["When" vhdl-template-when t]
3254 ["While (Loop)" vhdl-template-while-loop t]
3255 ["With" vhdl-template-with t]))
3256 (when (vhdl-standard-p 'ams)
3257 '(("VHDL-AMS Construct"
3258 ["Break" vhdl-template-break t]
3259 ["Case (Use)" vhdl-template-case-use t]
3260 ["If (Use)" vhdl-template-if-use t]
3261 ["Limit" vhdl-template-limit t]
3262 ["Nature" vhdl-template-nature t]
3263 ["Procedural" vhdl-template-procedural t]
3264 ["Quantity (Free)" vhdl-template-quantity-free t]
3265 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3266 ["Quantity (Source)" vhdl-template-quantity-source t]
3267 ["Subnature" vhdl-template-subnature t]
3268 ["Terminal" vhdl-template-terminal t])))
3269 '(["Insert Construct..." vhdl-template-insert-construct
3270 :keys "C-c C-i C-t"]
3271 "--")
3272 (list
3273 (append
3274 '("Package")
3275 (when (vhdl-standard-p 'math)
3276 '(["math_complex" vhdl-template-package-math-complex t]
3277 ["math_real" vhdl-template-package-math-real t]))
3278 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3279 ["numeric_std" vhdl-template-package-numeric-std t]
3280 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3281 ["textio" vhdl-template-package-textio t]
3282 "--"
3283 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3284 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3285 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3286 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3287 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3288 "--"
3289 ["Insert Package..." vhdl-template-insert-package
3290 :keys "C-c C-i C-p"])))
3291 '(("Directive"
3292 ["translate_on" vhdl-template-directive-translate-on t]
3293 ["translate_off" vhdl-template-directive-translate-off t]
3294 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3295 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3296 "--"
3297 ["Insert Directive..." vhdl-template-insert-directive
3298 :keys "C-c C-i C-d"])
5eabfe72 3299 "--"
3dcb36b7
JB
3300 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3301 ["Insert Footer" vhdl-template-footer t]
3302 ["Insert Date" vhdl-template-insert-date t]
3303 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
5eabfe72 3304 "--"
3dcb36b7
JB
3305 ["Query Next Prompt" vhdl-template-search-prompt t]))
3306 ,(append
3307 '("Model")
3308 ;; add menu entries for defined models
3309 (let ((model-alist vhdl-model-alist) menu-list model)
3310 (while model-alist
3311 (setq model (car model-alist))
3312 (setq menu-list
3313 (cons
3314 (vector
3315 (nth 0 model)
3316 (vhdl-function-name "vhdl-model" (nth 0 model))
3317 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3318 menu-list))
3319 (setq model-alist (cdr model-alist)))
3320 (setq menu-list (nreverse menu-list))
3321 (vhdl-menu-split menu-list "Model"))
3322 '("--" "--"
3323 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3324 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3325 ("Port"
5eabfe72 3326 ["Copy" vhdl-port-copy t]
d2ddb974 3327 "--"
5eabfe72
KH
3328 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3329 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3330 ["Paste As Instance" vhdl-port-paste-instance
3331 :keys "C-c C-p C-i" :active vhdl-port-list]
3332 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3333 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3334 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3dcb36b7 3335 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
d2ddb974 3336 "--"
3dcb36b7
JB
3337 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3338 "--"
3339 ["Flatten" vhdl-port-flatten
3340 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3341 ["Reverse Direction" vhdl-port-reverse-direction
3342 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3343 ("Compose"
3344 ["New Component" vhdl-compose-new-component t]
0a2e512a 3345 ["Copy Component" vhdl-port-copy t]
3dcb36b7
JB
3346 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3347 ["Wire Components" vhdl-compose-wire-components t]
3348 "--"
0a2e512a 3349 ["Generate Configuration" vhdl-compose-configuration t]
3dcb36b7
JB
3350 ["Generate Components Package" vhdl-compose-components-package t])
3351 ("Subprogram"
3352 ["Copy" vhdl-subprog-copy t]
3353 "--"
3354 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3355 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3356 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3357 "--"
3358 ["Flatten" vhdl-subprog-flatten
3359 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3360 "--"
3361 ("Comment"
5eabfe72
KH
3362 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3363 "--"
3364 ["Insert Inline Comment" vhdl-comment-append-inline t]
3365 ["Insert Horizontal Line" vhdl-comment-display-line t]
3366 ["Insert Display Comment" vhdl-comment-display t]
3367 "--"
3368 ["Fill Comment" fill-paragraph t]
3369 ["Fill Comment Region" fill-region (mark)]
3370 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3dcb36b7
JB
3371 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3372 ("Line"
5eabfe72
KH
3373 ["Kill" vhdl-line-kill t]
3374 ["Copy" vhdl-line-copy t]
3375 ["Yank" vhdl-line-yank t]
3376 ["Expand" vhdl-line-expand t]
3377 "--"
3378 ["Transpose Next" vhdl-line-transpose-next t]
3379 ["Transpose Prev" vhdl-line-transpose-previous t]
3380 ["Open" vhdl-line-open t]
3dcb36b7 3381 ["Join" vhdl-delete-indentation t]
5eabfe72
KH
3382 "--"
3383 ["Goto" goto-line t]
3dcb36b7
JB
3384 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3385 ("Move"
5eabfe72
KH
3386 ["Forward Statement" vhdl-end-of-statement t]
3387 ["Backward Statement" vhdl-beginning-of-statement t]
3388 ["Forward Expression" vhdl-forward-sexp t]
3389 ["Backward Expression" vhdl-backward-sexp t]
3dcb36b7
JB
3390 ["Forward Same Indent" vhdl-forward-same-indent t]
3391 ["Backward Same Indent" vhdl-backward-same-indent t]
5eabfe72
KH
3392 ["Forward Function" vhdl-end-of-defun t]
3393 ["Backward Function" vhdl-beginning-of-defun t]
3dcb36b7
JB
3394 ["Mark Function" vhdl-mark-defun t])
3395 "--"
3396 ("Indent"
3397 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3398 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
5eabfe72 3399 ["Region" vhdl-indent-region (mark)]
3dcb36b7
JB
3400 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3401 ("Align"
5eabfe72 3402 ["Group" vhdl-align-group t]
3dcb36b7
JB
3403 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3404 ["List" vhdl-align-list t]
3405 ["Declarations" vhdl-align-declarations t]
3406 ["Region" vhdl-align-region (mark)]
3407 ["Buffer" vhdl-align-buffer t]
5eabfe72
KH
3408 "--"
3409 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3410 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3dcb36b7
JB
3411 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3412 ("Fill"
3413 ["List" vhdl-fill-list t]
3414 ["Group" vhdl-fill-group t]
3415 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3416 ["Region" vhdl-fill-region (mark)])
3417 ("Beautify"
3418 ["Region" vhdl-beautify-region (mark)]
3419 ["Buffer" vhdl-beautify-buffer t])
3420 ("Fix"
3421 ["Generic/Port Clause" vhdl-fix-clause t]
5eabfe72 3422 "--"
3dcb36b7
JB
3423 ["Case Region" vhdl-fix-case-region (mark)]
3424 ["Case Buffer" vhdl-fix-case-buffer t]
3425 "--"
3426 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3427 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3428 "--"
3429 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3430 ("Update"
3431 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3432 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3433 "--"
3434 ["Fontify Buffer" vhdl-fontify-buffer t]
3435 ["Statistics Buffer" vhdl-statistics-buffer t]
3436 ["Show Messages" vhdl-show-messages t]
3437 ["Syntactic Info" vhdl-show-syntactic-information t]
3438 "--"
3439 ["Speedbar" vhdl-speedbar t]
3440 ["Hide/Show" vhdl-hs-minor-mode t]
3441 "--"
3442 ("Documentation"
5eabfe72 3443 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3dcb36b7 3444 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
5eabfe72 3445 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3dcb36b7
JB
3446 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3447 ["Version" vhdl-version t]
3448 ["Bug Report..." vhdl-submit-bug-report t]
3449 "--"
3450 ("Options"
3451 ("Mode"
3452 ["Electric Mode"
3453 (progn (customize-set-variable 'vhdl-electric-mode
56eb0904 3454 (not vhdl-electric-mode)))
3dcb36b7
JB
3455 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3456 ["Stutter Mode"
3457 (progn (customize-set-variable 'vhdl-stutter-mode
56eb0904 3458 (not vhdl-stutter-mode)))
3dcb36b7
JB
3459 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3460 ["Indent Tabs Mode"
3461 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3462 (not vhdl-indent-tabs-mode))
3463 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3464 :style toggle :selected vhdl-indent-tabs-mode]
3465 "--"
3466 ["Customize Group..." (customize-group 'vhdl-mode) t])
3467 ("Project"
3468 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3469 ,(append
3470 '("Selected Project at Startup"
3471 ["None" (progn (customize-set-variable 'vhdl-project nil)
3472 (vhdl-set-project ""))
3473 :style radio :selected (null vhdl-project)]
3474 "--")
3475 ;; add menu entries for defined projects
3476 (let ((project-alist vhdl-project-alist) menu-list name)
3477 (while project-alist
3478 (setq name (caar project-alist))
3479 (setq menu-list
3480 (cons `[,name (progn (customize-set-variable
3481 'vhdl-project ,name)
3482 (vhdl-set-project ,name))
3483 :style radio :selected (equal ,name vhdl-project)]
3484 menu-list))
3485 (setq project-alist (cdr project-alist)))
3486 (setq menu-list (nreverse menu-list))
3487 (vhdl-menu-split menu-list "Project")))
3488 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3489 ("Auto Load Setup File"
3490 ["At Startup"
3491 (customize-set-variable 'vhdl-project-auto-load
3492 (if (memq 'startup vhdl-project-auto-load)
3493 (delq 'startup vhdl-project-auto-load)
3494 (cons 'startup vhdl-project-auto-load)))
3495 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3496 ["Sort Projects"
3497 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3498 :style toggle :selected vhdl-project-sort]
3499 "--"
3500 ["Customize Group..." (customize-group 'vhdl-project) t])
3501 ("Compiler"
3502 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3503 ,(append
3504 '("Selected Compiler at Startup")
3505 ;; add menu entries for defined compilers
3506 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3507 (while comp-alist
3508 (setq name (caar comp-alist))
3509 (setq menu-list
3510 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3511 :style radio :selected (equal ,name vhdl-compiler)]
3512 menu-list))
3513 (setq comp-alist (cdr comp-alist)))
3514 (setq menu-list (nreverse menu-list))
3515 (vhdl-menu-split menu-list "Compler")))
3516 ["Use Local Error Regexp"
3517 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3518 (not vhdl-compile-use-local-error-regexp))
3519 :style toggle :selected vhdl-compile-use-local-error-regexp]
3520 ["Makefile Generation Hook..."
3521 (customize-option 'vhdl-makefile-generation-hook) t]
3522 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3523 "--"
3524 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3525 ("Style"
3526 ("VHDL Standard"
3527 ["VHDL'87"
3528 (progn (customize-set-variable 'vhdl-standard
3529 (list '87 (cadr vhdl-standard)))
3530 (vhdl-activate-customizations))
3531 :style radio :selected (eq '87 (car vhdl-standard))]
3532 ["VHDL'93"
3533 (progn (customize-set-variable 'vhdl-standard
3534 (list '93 (cadr vhdl-standard)))
3535 (vhdl-activate-customizations))
3536 :style radio :selected (eq '93 (car vhdl-standard))]
3537 "--"
3538 ["VHDL-AMS"
3539 (progn (customize-set-variable
3540 'vhdl-standard (list (car vhdl-standard)
3541 (if (memq 'ams (cadr vhdl-standard))
3542 (delq 'ams (cadr vhdl-standard))
3543 (cons 'ams (cadr vhdl-standard)))))
3544 (vhdl-activate-customizations))
3545 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3546 ["Math Packages"
3547 (progn (customize-set-variable
3548 'vhdl-standard (list (car vhdl-standard)
3549 (if (memq 'math (cadr vhdl-standard))
3550 (delq 'math (cadr vhdl-standard))
3551 (cons 'math (cadr vhdl-standard)))))
3552 (vhdl-activate-customizations))
3553 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3554 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3555 ["Upper Case Keywords"
3556 (customize-set-variable 'vhdl-upper-case-keywords
3557 (not vhdl-upper-case-keywords))
3558 :style toggle :selected vhdl-upper-case-keywords]
3559 ["Upper Case Types"
3560 (customize-set-variable 'vhdl-upper-case-types
3561 (not vhdl-upper-case-types))
3562 :style toggle :selected vhdl-upper-case-types]
3563 ["Upper Case Attributes"
3564 (customize-set-variable 'vhdl-upper-case-attributes
3565 (not vhdl-upper-case-attributes))
3566 :style toggle :selected vhdl-upper-case-attributes]
3567 ["Upper Case Enumeration Values"
3568 (customize-set-variable 'vhdl-upper-case-enum-values
3569 (not vhdl-upper-case-enum-values))
3570 :style toggle :selected vhdl-upper-case-enum-values]
3571 ["Upper Case Constants"
3572 (customize-set-variable 'vhdl-upper-case-constants
3573 (not vhdl-upper-case-constants))
3574 :style toggle :selected vhdl-upper-case-constants]
3575 ("Use Direct Instantiation"
3576 ["Never"
3577 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3578 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3579 ["Standard"
3580 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3581 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3582 ["Always"
3583 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3584 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3585 "--"
3586 ["Customize Group..." (customize-group 'vhdl-style) t])
3587 ("Naming"
3588 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3589 ["Architecture File Name..."
3590 (customize-option 'vhdl-architecture-file-name) t]
0a2e512a
RF
3591 ["Configuration File Name..."
3592 (customize-option 'vhdl-configuration-file-name) t]
3dcb36b7
JB
3593 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3594 ("File Name Case"
3595 ["As Is"
3596 (customize-set-variable 'vhdl-file-name-case 'identity)
3597 :style radio :selected (eq 'identity vhdl-file-name-case)]
3598 ["Lower Case"
3599 (customize-set-variable 'vhdl-file-name-case 'downcase)
3600 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3601 ["Upper Case"
3602 (customize-set-variable 'vhdl-file-name-case 'upcase)
3603 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3604 ["Capitalize"
3605 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3606 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3607 "--"
3608 ["Customize Group..." (customize-group 'vhdl-naming) t])
3609 ("Template"
3610 ("Electric Keywords"
3611 ["VHDL Keywords"
3612 (customize-set-variable 'vhdl-electric-keywords
3613 (if (memq 'vhdl vhdl-electric-keywords)
3614 (delq 'vhdl vhdl-electric-keywords)
3615 (cons 'vhdl vhdl-electric-keywords)))
3616 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3617 ["User Model Keywords"
3618 (customize-set-variable 'vhdl-electric-keywords
3619 (if (memq 'user vhdl-electric-keywords)
3620 (delq 'user vhdl-electric-keywords)
3621 (cons 'user vhdl-electric-keywords)))
3622 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3623 ("Insert Optional Labels"
3624 ["None"
3625 (customize-set-variable 'vhdl-optional-labels 'none)
3626 :style radio :selected (eq 'none vhdl-optional-labels)]
3627 ["Processes Only"
3628 (customize-set-variable 'vhdl-optional-labels 'process)
3629 :style radio :selected (eq 'process vhdl-optional-labels)]
3630 ["All Constructs"
3631 (customize-set-variable 'vhdl-optional-labels 'all)
3632 :style radio :selected (eq 'all vhdl-optional-labels)])
3633 ("Insert Empty Lines"
3634 ["None"
3635 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3636 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3637 ["Design Units Only"
3638 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3639 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3640 ["All Constructs"
3641 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3642 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3643 ["Argument List Indent"
3644 (customize-set-variable 'vhdl-argument-list-indent
3645 (not vhdl-argument-list-indent))
3646 :style toggle :selected vhdl-argument-list-indent]
3647 ["Association List with Formals"
3648 (customize-set-variable 'vhdl-association-list-with-formals
3649 (not vhdl-association-list-with-formals))
3650 :style toggle :selected vhdl-association-list-with-formals]
3651 ["Conditions in Parenthesis"
3652 (customize-set-variable 'vhdl-conditions-in-parenthesis
3653 (not vhdl-conditions-in-parenthesis))
3654 :style toggle :selected vhdl-conditions-in-parenthesis]
3655 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3656 ["One String..." (customize-option 'vhdl-one-string) t]
3657 ("File Header"
3658 ["Header String..." (customize-option 'vhdl-file-header) t]
3659 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3660 ["Company Name..." (customize-option 'vhdl-company-name) t]
3661 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3662 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3663 ["Date Format..." (customize-option 'vhdl-date-format) t]
3664 ["Modify Date Prefix String..."
3665 (customize-option 'vhdl-modify-date-prefix-string) t]
3666 ["Modify Date on Saving"
3667 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3668 (not vhdl-modify-date-on-saving))
3669 (vhdl-activate-customizations))
3670 :style toggle :selected vhdl-modify-date-on-saving])
3671 ("Sequential Process"
3672 ("Kind of Reset"
3673 ["None"
3674 (customize-set-variable 'vhdl-reset-kind 'none)
3675 :style radio :selected (eq 'none vhdl-reset-kind)]
3676 ["Synchronous"
3677 (customize-set-variable 'vhdl-reset-kind 'sync)
3678 :style radio :selected (eq 'sync vhdl-reset-kind)]
3679 ["Asynchronous"
3680 (customize-set-variable 'vhdl-reset-kind 'async)
3681 :style radio :selected (eq 'async vhdl-reset-kind)])
3682 ["Reset is Active High"
3683 (customize-set-variable 'vhdl-reset-active-high
3684 (not vhdl-reset-active-high))
3685 :style toggle :selected vhdl-reset-active-high]
3686 ["Use Rising Clock Edge"
3687 (customize-set-variable 'vhdl-clock-rising-edge
3688 (not vhdl-clock-rising-edge))
3689 :style toggle :selected vhdl-clock-rising-edge]
3690 ("Clock Edge Condition"
3691 ["Standard"
3692 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3693 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3694 ["Function \"rising_edge\""
3695 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3696 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3697 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3698 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3699 "--"
3700 ["Customize Group..." (customize-group 'vhdl-template) t])
3701 ("Model"
3702 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3703 ("Port"
3704 ["Include Port Comments"
3705 (customize-set-variable 'vhdl-include-port-comments
3706 (not vhdl-include-port-comments))
3707 :style toggle :selected vhdl-include-port-comments]
3708 ["Include Direction Comments"
3709 (customize-set-variable 'vhdl-include-direction-comments
3710 (not vhdl-include-direction-comments))
3711 :style toggle :selected vhdl-include-direction-comments]
3712 ["Include Type Comments"
3713 (customize-set-variable 'vhdl-include-type-comments
3714 (not vhdl-include-type-comments))
3715 :style toggle :selected vhdl-include-type-comments]
3716 ("Include Group Comments"
3717 ["Never"
3718 (customize-set-variable 'vhdl-include-group-comments 'never)
3719 :style radio :selected (eq 'never vhdl-include-group-comments)]
3720 ["Declarations"
3721 (customize-set-variable 'vhdl-include-group-comments 'decl)
3722 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3723 ["Always"
3724 (customize-set-variable 'vhdl-include-group-comments 'always)
3725 :style radio :selected (eq 'always vhdl-include-group-comments)])
3726 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3727 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3728 ("Testbench"
3729 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3730 ["Architecture Name..."
3731 (customize-option 'vhdl-testbench-architecture-name) t]
3732 ["Configuration Name..."
3733 (customize-option 'vhdl-testbench-configuration-name) t]
3734 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3735 ["Include Header"
3736 (customize-set-variable 'vhdl-testbench-include-header
3737 (not vhdl-testbench-include-header))
3738 :style toggle :selected vhdl-testbench-include-header]
3739 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3740 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3741 ["Initialize Signals"
3742 (customize-set-variable 'vhdl-testbench-initialize-signals
3743 (not vhdl-testbench-initialize-signals))
3744 :style toggle :selected vhdl-testbench-initialize-signals]
3745 ["Include Library Clause"
3746 (customize-set-variable 'vhdl-testbench-include-library
3747 (not vhdl-testbench-include-library))
3748 :style toggle :selected vhdl-testbench-include-library]
3749 ["Include Configuration"
3750 (customize-set-variable 'vhdl-testbench-include-configuration
3751 (not vhdl-testbench-include-configuration))
3752 :style toggle :selected vhdl-testbench-include-configuration]
3753 ("Create Files"
3754 ["None"
3755 (customize-set-variable 'vhdl-testbench-create-files 'none)
3756 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3757 ["Single"
3758 (customize-set-variable 'vhdl-testbench-create-files 'single)
3759 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3760 ["Separate"
3761 (customize-set-variable 'vhdl-testbench-create-files 'separate)
0a2e512a
RF
3762 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3763 ["Testbench Entity File Name..."
3764 (customize-option 'vhdl-testbench-entity-file-name) t]
3765 ["Testbench Architecture File Name..."
3766 (customize-option 'vhdl-testbench-architecture-file-name) t])
3dcb36b7
JB
3767 "--"
3768 ["Customize Group..." (customize-group 'vhdl-port) t])
3769 ("Compose"
0a2e512a
RF
3770 ["Architecture Name..."
3771 (customize-option 'vhdl-compose-architecture-name) t]
3772 ["Configuration Name..."
3773 (customize-option 'vhdl-compose-configuration-name) t]
3774 ["Components Package Name..."
3775 (customize-option 'vhdl-components-package-name) t]
3776 ["Use Components Package"
3777 (customize-set-variable 'vhdl-use-components-package
3778 (not vhdl-use-components-package))
3779 :style toggle :selected vhdl-use-components-package]
3780 ["Include Header"
3781 (customize-set-variable 'vhdl-compose-include-header
3782 (not vhdl-compose-include-header))
3783 :style toggle :selected vhdl-compose-include-header]
3784 ("Create Entity/Architecture Files"
3dcb36b7
JB
3785 ["None"
3786 (customize-set-variable 'vhdl-compose-create-files 'none)
3787 :style radio :selected (eq 'none vhdl-compose-create-files)]
3788 ["Single"
3789 (customize-set-variable 'vhdl-compose-create-files 'single)
3790 :style radio :selected (eq 'single vhdl-compose-create-files)]
3791 ["Separate"
3792 (customize-set-variable 'vhdl-compose-create-files 'separate)
3793 :style radio :selected (eq 'separate vhdl-compose-create-files)])
0a2e512a
RF
3794 ["Create Configuration File"
3795 (customize-set-variable 'vhdl-compose-configuration-create-file
3796 (not vhdl-compose-configuration-create-file))
3797 :style toggle :selected vhdl-compose-configuration-create-file]
3798 ["Hierarchical Configuration"
3799 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3800 (not vhdl-compose-configuration-hierarchical))
3801 :style toggle :selected vhdl-compose-configuration-hierarchical]
3802 ["Use Subconfiguration"
3803 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3804 (not vhdl-compose-configuration-use-subconfiguration))
3805 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3dcb36b7
JB
3806 "--"
3807 ["Customize Group..." (customize-group 'vhdl-compose) t])
3808 ("Comment"
3809 ["Self Insert Comments"
3810 (customize-set-variable 'vhdl-self-insert-comments
3811 (not vhdl-self-insert-comments))
3812 :style toggle :selected vhdl-self-insert-comments]
3813 ["Prompt for Comments"
3814 (customize-set-variable 'vhdl-prompt-for-comments
3815 (not vhdl-prompt-for-comments))
3816 :style toggle :selected vhdl-prompt-for-comments]
3817 ["Inline Comment Column..."
3818 (customize-option 'vhdl-inline-comment-column) t]
3819 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3820 "--"
3821 ["Customize Group..." (customize-group 'vhdl-comment) t])
3822 ("Align"
3823 ["Auto Align Templates"
3824 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3825 :style toggle :selected vhdl-auto-align]
3826 ["Align Line Groups"
3827 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3828 :style toggle :selected vhdl-align-groups]
3829 ["Group Separation String..."
3830 (customize-set-variable 'vhdl-align-group-separate) t]
3831 ["Align Lines with Same Indent"
3832 (customize-set-variable 'vhdl-align-same-indent
3833 (not vhdl-align-same-indent))
3834 :style toggle :selected vhdl-align-same-indent]
3835 "--"
3836 ["Customize Group..." (customize-group 'vhdl-align) t])
3837 ("Highlight"
3838 ["Highlighting On/Off..."
3839 (customize-option
4bcb9c95
SM
3840 (if (fboundp 'global-font-lock-mode)
3841 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3dcb36b7
JB
3842 ["Highlight Keywords"
3843 (progn (customize-set-variable 'vhdl-highlight-keywords
3844 (not vhdl-highlight-keywords))
3845 (vhdl-fontify-buffer))
3846 :style toggle :selected vhdl-highlight-keywords]
3847 ["Highlight Names"
3848 (progn (customize-set-variable 'vhdl-highlight-names
3849 (not vhdl-highlight-names))
3850 (vhdl-fontify-buffer))
3851 :style toggle :selected vhdl-highlight-names]
3852 ["Highlight Special Words"
3853 (progn (customize-set-variable 'vhdl-highlight-special-words
3854 (not vhdl-highlight-special-words))
3855 (vhdl-fontify-buffer))
3856 :style toggle :selected vhdl-highlight-special-words]
3857 ["Highlight Forbidden Words"
3858 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3859 (not vhdl-highlight-forbidden-words))
3860 (vhdl-fontify-buffer))
3861 :style toggle :selected vhdl-highlight-forbidden-words]
3862 ["Highlight Verilog Keywords"
3863 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3864 (not vhdl-highlight-verilog-keywords))
3865 (vhdl-fontify-buffer))
3866 :style toggle :selected vhdl-highlight-verilog-keywords]
3867 ["Highlight \"translate_off\""
3868 (progn (customize-set-variable 'vhdl-highlight-translate-off
3869 (not vhdl-highlight-translate-off))
3870 (vhdl-fontify-buffer))
3871 :style toggle :selected vhdl-highlight-translate-off]
3872 ["Case Sensitive Highlighting"
3873 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3874 (not vhdl-highlight-case-sensitive))
3875 (vhdl-fontify-buffer))
3876 :style toggle :selected vhdl-highlight-case-sensitive]
3877 ["Special Syntax Definition..."
3878 (customize-option 'vhdl-special-syntax-alist) t]
3879 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3880 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3881 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3882 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3883 "--"
3884 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3885 ("Speedbar"
3886 ["Auto Open at Startup"
3887 (customize-set-variable 'vhdl-speedbar-auto-open
3888 (not vhdl-speedbar-auto-open))
3889 :style toggle :selected vhdl-speedbar-auto-open]
3890 ("Default Displaying Mode"
3891 ["Files"
3892 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3893 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3894 ["Directory Hierarchy"
3895 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3896 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3897 ["Project Hierarchy"
3898 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3899 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3900 ["Indentation Offset..."
3901 (customize-option 'speedbar-indentation-width) t]
3902 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3903 ["Jump to Unit when Opening"
3904 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3905 (not vhdl-speedbar-jump-to-unit))
3906 :style toggle :selected vhdl-speedbar-jump-to-unit]
3907 ["Update Hierarchy on File Saving"
3908 (customize-set-variable 'vhdl-speedbar-update-on-saving
3909 (not vhdl-speedbar-update-on-saving))
3910 :style toggle :selected vhdl-speedbar-update-on-saving]
3911 ("Save in Cache File"
3912 ["Hierarchy Information"
3913 (customize-set-variable 'vhdl-speedbar-save-cache
3914 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3915 (delq 'hierarchy vhdl-speedbar-save-cache)
3916 (cons 'hierarchy vhdl-speedbar-save-cache)))
3917 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3918 ["Displaying Status"
3919 (customize-set-variable 'vhdl-speedbar-save-cache
3920 (if (memq 'display vhdl-speedbar-save-cache)
3921 (delq 'display vhdl-speedbar-save-cache)
3922 (cons 'display vhdl-speedbar-save-cache)))
3923 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3924 ["Cache File Name..."
3925 (customize-option 'vhdl-speedbar-cache-file-name) t]
3926 "--"
3927 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3928 ("Menu"
3929 ["Add Index Menu when Loading File"
3930 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3931 (vhdl-index-menu-init))
3932 :style toggle :selected vhdl-index-menu]
3933 ["Add Source File Menu when Loading File"
3934 (progn (customize-set-variable 'vhdl-source-file-menu
3935 (not vhdl-source-file-menu))
3936 (vhdl-add-source-files-menu))
3937 :style toggle :selected vhdl-source-file-menu]
3938 ["Add Hideshow Menu at Startup"
3939 (progn (customize-set-variable 'vhdl-hideshow-menu
3940 (not vhdl-hideshow-menu))
3941 (vhdl-activate-customizations))
3942 :style toggle :selected vhdl-hideshow-menu]
3943 ["Hide Everything Initially"
3944 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3945 :style toggle :selected vhdl-hide-all-init]
3946 "--"
3947 ["Customize Group..." (customize-group 'vhdl-menu) t])
3948 ("Print"
3949 ["In Two Column Format"
3950 (progn (customize-set-variable 'vhdl-print-two-column
3951 (not vhdl-print-two-column))
3952 (message "Activate new setting by saving options and restarting Emacs"))
3953 :style toggle :selected vhdl-print-two-column]
3954 ["Use Customized Faces"
3955 (progn (customize-set-variable 'vhdl-print-customize-faces
3956 (not vhdl-print-customize-faces))
3957 (message "Activate new setting by saving options and restarting Emacs"))
3958 :style toggle :selected vhdl-print-customize-faces]
3959 "--"
3960 ["Customize Group..." (customize-group 'vhdl-print) t])
3961 ("Miscellaneous"
3962 ["Use Intelligent Tab"
3963 (progn (customize-set-variable 'vhdl-intelligent-tab
3964 (not vhdl-intelligent-tab))
3965 (vhdl-activate-customizations))
3966 :style toggle :selected vhdl-intelligent-tab]
3967 ["Indent Syntax-Based"
3968 (customize-set-variable 'vhdl-indent-syntax-based
3969 (not vhdl-indent-syntax-based))
3970 :style toggle :selected vhdl-indent-syntax-based]
3971 ["Word Completion is Case Sensitive"
3972 (customize-set-variable 'vhdl-word-completion-case-sensitive
3973 (not vhdl-word-completion-case-sensitive))
3974 :style toggle :selected vhdl-word-completion-case-sensitive]
3975 ["Word Completion in Minibuffer"
3976 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3977 (not vhdl-word-completion-in-minibuffer))
3978 (message "Activate new setting by saving options and restarting Emacs"))
3979 :style toggle :selected vhdl-word-completion-in-minibuffer]
3980 ["Underscore is Part of Word"
3981 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3982 (not vhdl-underscore-is-part-of-word))
3983 (vhdl-activate-customizations))
3984 :style toggle :selected vhdl-underscore-is-part-of-word]
3985 "--"
3986 ["Customize Group..." (customize-group 'vhdl-misc) t])
3987 ["Related..." (customize-browse 'vhdl-related) t]
d2ddb974 3988 "--"
3dcb36b7
JB
3989 ["Save Options" customize-save-customized t]
3990 ["Activate Options" vhdl-activate-customizations t]
3991 ["Browse Options..." vhdl-customize t])))
5eabfe72
KH
3992
3993(defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3994 "VHDL Mode menu.")
3995
3996(defun vhdl-update-mode-menu ()
3dcb36b7 3997 "Update VHDL Mode menu."
5eabfe72
KH
3998 (interactive)
3999 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4000 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4001 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4002 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4003 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
d2ddb974 4004
5eabfe72
KH
4005;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4006;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
d2ddb974 4007
3dcb36b7 4008(defconst vhdl-imenu-generic-expression
d2ddb974 4009 '(
5eabfe72
KH
4010 ("Subprogram"
4011 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4012 4)
4013 ("Instance"
4014 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4015 1)
4016 ("Component"
4017 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4018 2)
5eabfe72
KH
4019 ("Procedural"
4020 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4021 1)
4022 ("Process"
4023 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4024 1)
4025 ("Block"
4026 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4027 1)
4028 ("Package"
4029 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4030 3)
d2ddb974
KH
4031 ("Configuration"
4032 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4033 2)
5eabfe72
KH
4034 ("Architecture"
4035 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4036 2)
5eabfe72
KH
4037 ("Entity"
4038 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4039 2)
d2ddb974
KH
4040 )
4041 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4042
5eabfe72
KH
4043(defun vhdl-index-menu-init ()
4044 "Initialize index menu."
4045 (set (make-local-variable 'imenu-case-fold-search) t)
4046 (set (make-local-variable 'imenu-generic-expression)
4047 vhdl-imenu-generic-expression)
3dcb36b7 4048 (when (and vhdl-index-menu (fboundp 'imenu))
5eabfe72
KH
4049 (if (or (not (boundp 'font-lock-maximum-size))
4050 (> font-lock-maximum-size (buffer-size)))
4051 (imenu-add-to-menubar "Index")
4052 (message "Scanning buffer for index...buffer too big"))))
d2ddb974 4053
3dcb36b7 4054;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
4055;; Source file menu (using `easy-menu.el')
4056
5eabfe72
KH
4057(defvar vhdl-sources-menu nil)
4058
4059(defun vhdl-directory-files (directory &optional full match)
4060 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4061message."
3dcb36b7
JB
4062 (if (not (file-directory-p directory))
4063 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4064 (let ((dir (directory-files directory full match)))
4065 (setq dir (delete "." dir))
4066 (setq dir (delete ".." dir))
4067 dir)))
5eabfe72
KH
4068
4069(defun vhdl-get-source-files (&optional full directory)
4070 "Get list of VHDL source files in DIRECTORY or current directory."
4071 (let ((mode-alist auto-mode-alist)
4072 filename-regexp)
4073 ;; create regular expressions for matching file names
3dcb36b7 4074 (setq filename-regexp "\\`[^.].*\\(")
5eabfe72 4075 (while mode-alist
3dcb36b7 4076 (when (eq (cdar mode-alist) 'vhdl-mode)
5eabfe72 4077 (setq filename-regexp
3dcb36b7 4078 (concat filename-regexp (caar mode-alist) "\\|")))
5eabfe72
KH
4079 (setq mode-alist (cdr mode-alist)))
4080 (setq filename-regexp
4081 (concat (substring filename-regexp 0
4082 (string-match "\\\\|$" filename-regexp)) "\\)"))
4083 ;; find files
3dcb36b7
JB
4084 (vhdl-directory-files
4085 (or directory default-directory) full filename-regexp)))
d2ddb974
KH
4086
4087(defun vhdl-add-source-files-menu ()
5eabfe72
KH
4088 "Scan directory for all VHDL source files and generate menu.
4089The directory of the current source file is scanned."
d2ddb974
KH
4090 (interactive)
4091 (message "Scanning directory for source files ...")
5eabfe72 4092 (let ((newmap (current-local-map))
5eabfe72
KH
4093 (file-list (vhdl-get-source-files))
4094 menu-list found)
4095 ;; Create list for menu
4096 (setq found nil)
4097 (while file-list
4098 (setq found t)
4099 (setq menu-list (cons (vector (car file-list)
4100 (list 'find-file (car file-list)) t)
4101 menu-list))
4102 (setq file-list (cdr file-list)))
3dcb36b7 4103 (setq menu-list (vhdl-menu-split menu-list "Sources"))
5eabfe72
KH
4104 (when found (setq menu-list (cons "--" menu-list)))
4105 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4106 (setq menu-list (cons "Sources" menu-list))
d2ddb974 4107 ;; Create menu
5eabfe72
KH
4108 (easy-menu-add menu-list)
4109 (easy-menu-define vhdl-sources-menu newmap
4110 "VHDL source files menu" menu-list))
d2ddb974
KH
4111 (message ""))
4112
d2ddb974 4113
5eabfe72 4114;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4115;;; Mode definition
5eabfe72
KH
4116;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4117;; performs all buffer local initializations
4118
1c36bac6 4119;;;###autoload
d2ddb974
KH
4120(defun vhdl-mode ()
4121 "Major mode for editing VHDL code.
4122
4123Usage:
4124------
4125
3dcb36b7
JB
4126 TEMPLATE INSERTION (electrification):
4127 After typing a VHDL keyword and entering `SPC', you are prompted for
4128 arguments while a template is generated for that VHDL construct. Typing
4129 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4130 template generation. Optional arguments are indicated by square
4131 brackets and removed if the queried string is left empty. Prompts for
4132 mandatory arguments remain in the code if the queried string is left
4133 empty. They can be queried again by `C-c C-t C-q'. Enabled
4134 electrification is indicated by `/e' in the modeline.
4135
4136 Typing `M-SPC' after a keyword inserts a space without calling the
4137 template generator. Automatic template generation (i.e.
4138 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4139 setting option `vhdl-electric-mode' (see OPTIONS).
4140
4141 Template generators can be invoked from the VHDL menu, by key
4142 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4143 the keyword (i.e. first word of menu entry not in parenthesis) and
4144 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4145 conf, comp, cons, func, inst, pack, sig, var.
4146
4147 Template styles can be customized in customization group
4148 `vhdl-template' \(see OPTIONS).
4149
4150
4151 HEADER INSERTION:
4152 A file header can be inserted by `C-c C-t C-h'. A file footer
4153 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4154 See customization group `vhdl-header'.
4155
4156
4157 STUTTERING:
4158 Double striking of some keys inserts cumbersome VHDL syntax elements.
4159 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4160 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4161 the modeline. The stuttering keys and their effects are:
4162
4163 ;; --> \" : \" [ --> ( -- --> comment
4164 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4165 .. --> \" => \" ] --> ) --- --> horizontal line
4166 ,, --> \" <= \" ]] --> ] ---- --> display comment
4167 == --> \" == \" '' --> \\\"
4168
4169
4170 WORD COMPLETION:
4171 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4172 word in the buffer that starts alike, inserts it and adjusts case.
4173 Re-typing `TAB' toggles through alternative word completions. This also
4174 works in the minibuffer (i.e. in template generator prompts).
4175
4176 Typing `TAB' after `(' looks for and inserts complete parenthesized
4177 expressions (e.g. for array index ranges). All keywords as well as
4178 standard types and subprograms of VHDL have predefined abbreviations
4179 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4180 beginning with \"std\").
4181
4182 Typing `TAB' after a non-word character indents the line if at the
4183 beginning of a line (i.e. no preceding non-blank characters), and
4184 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4185 stop.
4186
4187
4188 COMMENTS:
4189 `--' puts a single comment.
4190 `---' draws a horizontal line for separating code segments.
4191 `----' inserts a display comment, i.e. two horizontal lines
4192 with a comment in between.
4193 `--CR' comments out code on that line. Re-hitting CR comments
4194 out following lines.
4195 `C-c c' comments out a region if not commented out,
4196 uncomments a region if already commented out.
4197
4198 You are prompted for comments after object definitions (i.e. signals,
4199 variables, constants, ports) and after subprogram and process
4200 specifications if option `vhdl-prompt-for-comments' is non-nil.
4201 Comments are automatically inserted as additional labels (e.g. after
4202 begin statements) and as help comments if `vhdl-self-insert-comments' is
4203 non-nil.
4204
4205 Inline comments (i.e. comments after a piece of code on the same line)
4206 are indented at least to `vhdl-inline-comment-column'. Comments go at
4207 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4208 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4209 in a comment automatically opens a new comment line. `M-q' re-fills
4210 multi-line comments.
4211
4212
4213 INDENTATION:
4214 `TAB' indents a line if at the beginning of the line. The amount of
4215 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4216 always indents the current line (is bound to `TAB' if option
4217 `vhdl-intelligent-tab' is nil).
4218
4219 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4220 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4221 indented normally (nil) or relative to the opening parenthesis (non-nil)
4222 according to option `vhdl-argument-list-indent'.
4223
4224 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4225 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4226 and vice versa.
4227
4228 Syntax-based indentation can be very slow in large files. Option
4229 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4230
4231
4232 ALIGNMENT:
4233 The alignment functions align operators, keywords, and inline comments
4234 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4235 separated by blank lines, `C-c C-a C-i' a block of lines with same
4236 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4237 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4238 C-a C-d' all lines within the declarative part of a design unit. `C-c
4239 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4240 for a group of lines, and `C-c C-a M-c' for a region.
4241
4242 If option `vhdl-align-groups' is non-nil, groups of code lines
4243 separated by special lines (see option `vhdl-align-group-separate') are
4244 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4245 blocks of lines with same indent are aligned separately. Some templates
4246 are automatically aligned after generation if option `vhdl-auto-align'
4247 is non-nil.
4248
4249 Alignment tries to align inline comments at
4250 `vhdl-inline-comment-column' and tries inline comment not to exceed
4251 `vhdl-end-comment-column'.
4252
4253 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4254 symbols are surrounded by one space, and multiple spaces are eliminated.
4255
4256
0a2e512a
RF
4257 CODE FILLING:
4258 Code filling allows to condense code (e.g. sensitivity lists or port
4259 maps) by removing comments and newlines and re-wrapping so that all
4260 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4261 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4262 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4263 `C-c C-f M-f' an entire region.
3dcb36b7
JB
4264
4265
4266 CODE BEAUTIFICATION:
4267 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4268 buffer respectively. This inludes indentation, alignment, and case
4269 fixing. Code beautification can also be run non-interactively using the
4270 command:
4271
4272 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4273
4274
4275 PORT TRANSLATION:
4276 Generic and port clauses from entity or component declarations can be
4277 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4278 as component instantiations and corresponding internal constants and
4279 signals, as a generic map with constants as actual generics, and as
4280 internal signal initializations (menu).
4281
4282 To include formals in component instantiations, see option
4283 `vhdl-association-list-with-formals'. To include comments in pasting,
4284 see options `vhdl-include-...-comments'.
4285
4286 A clause with several generic/port names on the same line can be
4287 flattened (`C-c C-p C-f') so that only one name per line exists. The
0a2e512a
RF
4288 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4289 outputs and vice versa, which can be useful in testbenches. (This
4290 reversion is done on the internal data structure and is only reflected
4291 in subsequent paste operations.)
3dcb36b7
JB
4292
4293 Names for actual ports, instances, testbenches, and
4294 design-under-test instances can be derived from existing names according
4295 to options `vhdl-...-name'. See customization group `vhdl-port'.
4296
4297
0a2e512a
RF
4298 SUBPROGRAM TRANSLATION:
4299 Similar functionality exists for copying/pasting the interface of
4300 subprograms (function/procedure). A subprogram interface can be copied
4301 and then pasted as a subprogram declaration, body or call (uses
4302 association list with formals).
3dcb36b7
JB
4303
4304
4305 TESTBENCH GENERATION:
4306 A copied port can also be pasted as a testbench. The generated
4307 testbench includes an entity, an architecture, and an optional
4308 configuration. The architecture contains the component declaration and
4309 instantiation of the DUT as well as internal constant and signal
4310 declarations. Additional user-defined templates can be inserted. The
4311 names used for entity/architecture/configuration/DUT as well as the file
4312 structure to be generated can be customized. See customization group
4313 `vhdl-testbench'.
4314
4315
4316 KEY BINDINGS:
4317 Key bindings (`C-c ...') exist for most commands (see in menu).
4318
4319
4320 VHDL MENU:
4321 All commands can be found in the VHDL menu including their key bindings.
4322
4323
4324 FILE BROWSER:
4325 The speedbar allows browsing of directories and file contents. It can
4326 be accessed from the VHDL menu and is automatically opened if option
4327 `vhdl-speedbar-auto-open' is non-nil.
4328
4329 In speedbar, open files and directories with `mouse-2' on the name and
4330 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4331
4332
4333 DESIGN HIERARCHY BROWSER:
4334 The speedbar can also be used for browsing the hierarchy of design units
4335 contained in the source files of the current directory or the specified
4336 projects (see option `vhdl-project-alist').
4337
4338 The speedbar can be switched between file, directory hierarchy and
4339 project hierarchy browsing mode in the speedbar menu or by typing `f',
4340 `h' or `H' in speedbar.
4341
4342 In speedbar, open design units with `mouse-2' on the name and browse
4343 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4344 from entities and components (in packages). Individual design units and
4345 complete designs can directly be compiled (\"Make\" menu entry).
4346
4347 The hierarchy is automatically updated upon saving a modified source
4348 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4349 hierarchy is only updated for projects that have been opened once in the
4350 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4351 options in group `vhdl-speedbar').
4352
4353 Simple design consistency checks are done during scanning, such as
4354 multiple declarations of the same unit or missing primary units that are
4355 required by secondary units.
4356
4357
0a2e512a
RF
4358 STRUCTURAL COMPOSITION:
4359 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4360 for a new component. Subcomponents (i.e. component declaration and
4361 instantiation) can be automatically placed from a previously read port
4362 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4363 all subcomponents can be automatically connected using internal signals
4364 and ports (`C-c C-c C-w') following these rules:
4365 - subcomponent actual ports with same name are considered to be
4366 connected by a signal (internal signal or port)
4367 - signals that are only inputs to subcomponents are considered as
4368 inputs to this component -> input port created
4369 - signals that are only outputs from subcomponents are considered as
4370 outputs from this component -> output port created
4371 - signals that are inputs to AND outputs from subcomponents are
4372 considered as internal connections -> internal signal created
84c98ace 4373
0a2e512a
RF
4374 Purpose: With appropriate naming conventions it is possible to
4375 create higher design levels with only a few mouse clicks or key
4376 strokes. A new design level can be created by simply generating a new
4377 component, placing the required subcomponents from the hierarchy
4378 browser, and wiring everything automatically.
84c98ace 4379
0a2e512a
RF
4380 Note: Automatic wiring only works reliably on templates of new
4381 components and component instantiations that were created by VHDL mode.
84c98ace 4382
0a2e512a
RF
4383 Component declarations can be placed in a components package (option
4384 `vhdl-use-components-package') which can be automatically generated for
4385 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4386 component instantiation is also supported (option
4387 `vhdl-use-direct-instantiation').
4388
4389| Configuration declarations can automatically be generated either from
4390| the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4391| the speedbar menu (for the architecture under the cursor). The
4392| configurations can optionally be hierarchical (i.e. include all
4393| component levels of a hierarchical design, option
4394| `vhdl-compose-configuration-hierarchical') or include subconfigurations
4395| (option `vhdl-compose-configuration-use-subconfiguration'). For
4396| subcomponents in hierarchical configurations, the most-recently-analyzed
4397| (mra) architecture is selected. If another architecture is desired, it
4398| can be marked as most-recently-analyzed (speedbar menu) before
4399| generating the configuration.
3dcb36b7 4400|
0a2e512a
RF
4401| Note: Configurations of subcomponents (i.e. hierarchical configuration
4402| declarations) are currently not considered when displaying
4403| configurations in speedbar.
84c98ace 4404
0a2e512a 4405 See the options group `vhdl-compose' for all relevant user options.
3dcb36b7
JB
4406
4407
4408 SOURCE FILE COMPILATION:
4409 The syntax of the current buffer can be analyzed by calling a VHDL
4410 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4411 option `vhdl-compiler'. The available compilers are listed in option
4412 `vhdl-compiler-alist' including all required compilation command,
4413 command options, compilation directory, and error message syntax
4414 information. New compilers can be added.
4415
4416 All the source files of an entire design can be compiled by the `make'
4417 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4418
4419
4420 MAKEFILE GENERATION:
4421 Makefiles can be generated automatically by an internal generation
4422 routine (`C-c M-k'). The library unit dependency information is
4423 obtained from the hierarchy browser. Makefile generation can be
4424 customized for each compiler in option `vhdl-compiler-alist'.
4425
4426 Makefile generation can also be run non-interactively using the
4427 command:
4428
4429 emacs -batch -l ~/.emacs -l vhdl-mode
4430 [-compiler compilername] [-project projectname]
4431 -f vhdl-generate-makefile
4432
4433 The Makefile's default target \"all\" compiles the entire design, the
4434 target \"clean\" removes it and the target \"library\" creates the
4435 library directory if not existent. The Makefile also includes a target
4436 for each primary library unit which allows selective compilation of this
4437 unit, its secondary units and its subhierarchy (example: compilation of
4438 a design specified by a configuration). User specific parts can be
4439 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4440
4441 Limitations:
4442 - Only library units and dependencies within the current library are
4443 considered. Makefiles for designs that span multiple libraries are
4444 not (yet) supported.
4445 - Only one-level configurations are supported (also hierarchical),
4446 but configurations that go down several levels are not.
4447 - The \"others\" keyword in configurations is not supported.
4448
4449
4450 PROJECTS:
4451 Projects can be defined in option `vhdl-project-alist' and a current
4452 project be selected using option `vhdl-project' (permanently) or from
4453 the menu or speedbar (temporarily). For each project, title and
4454 description strings (for the file headers), source files/directories
4455 (for the hierarchy browser and Makefile generation), library name, and
4456 compiler-dependent options, exceptions and compilation directory can be
4457 specified. Compilation settings overwrite the settings of option
4458 `vhdl-compiler-alist'.
4459
4460 Project setups can be exported (i.e. written to a file) and imported.
4461 Imported setups are not automatically saved in `vhdl-project-alist' but
4462 can be saved afterwards in its customization buffer. When starting
4463 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4464 vhdl-mode\") in a directory with an existing project setup file, it is
4465 automatically loaded and its project activated if option
4466 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4467 files can be specified in option `vhdl-project-file-name'. Multiple
4468 project setups can be automatically loaded from global directories.
4469 This is an alternative to specifying project setups with option
4470 `vhdl-project-alist'.
4471
4472
4473 SPECIAL MENUES:
4474 As an alternative to the speedbar, an index menu can be added (set
4475 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4476 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4477 file) for browsing the file contents (is not populated if buffer is
4478 larger than `font-lock-maximum-size'). Also, a source file menu can be
4479 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4480 current directory for VHDL source files.
4481
4482
4483 VHDL STANDARDS:
4484 The VHDL standards to be used are specified in option `vhdl-standard'.
4485 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4486
4487
4488 KEYWORD CASE:
4489 Lower and upper case for keywords and standardized types, attributes,
4490 and enumeration values is supported. If the option
4491 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4492 lower case and are converted into upper case automatically (not for
4493 types, attributes, and enumeration values). The case of keywords,
4494 types, attributes,and enumeration values can be fixed for an entire
4495 region (menu) or buffer (`C-c C-x C-c') according to the options
4496 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4497
4498
4499 HIGHLIGHTING (fontification):
4500 Keywords and standardized types, attributes, enumeration values, and
4501 function names (controlled by option `vhdl-highlight-keywords'), as well
4502 as comments, strings, and template prompts are highlighted using
4503 different colors. Unit, subprogram, signal, variable, constant,
4504 parameter and generic/port names in declarations as well as labels are
4505 highlighted if option `vhdl-highlight-names' is non-nil.
4506
4507 Additional reserved words or words with a forbidden syntax (e.g. words
4508 that should be avoided) can be specified in option
4509 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4510 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4511 keywords are highlighted as forbidden words if option
4512 `vhdl-highlight-verilog-keywords' is non-nil.
4513
4514 Words with special syntax can be highlighted by specifying their
4515 syntax and color in option `vhdl-special-syntax-alist' and by setting
4516 option `vhdl-highlight-special-words' to non-nil. This allows to
4517 establish some naming conventions (e.g. to distinguish different kinds
4518 of signals or other objects by using name suffices) and to support them
4519 visually.
4520
4521 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4522 to support case-sensitive highlighting. However, keywords are then only
4523 highlighted if written in lower case.
4524
4525 Code between \"translate_off\" and \"translate_on\" pragmas is
4526 highlighted using a different background color if option
4527 `vhdl-highlight-translate-off' is non-nil.
4528
4529 For documentation and customization of the used colors see
4530 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4531 highlighting of matching parenthesis, see customization group
4532 `paren-showing'. Automatic buffer highlighting is turned on/off by
4533 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4534
4535
4536 USER MODELS:
4537 VHDL models (templates) can be specified by the user and made accessible
4538 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4539 electrification. See option `vhdl-model-alist'.
4540
4541
4542 HIDE/SHOW:
4543 The code of blocks, processes, subprograms, component declarations and
4544 instantiations, generic/port clauses, and configuration declarations can
4545 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4546 the code (see customization group `vhdl-menu'). XEmacs: limited
4547 functionality due to old `hideshow.el' package.
4548
4549
4550 CODE UPDATING:
4551 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4552 current process, `C-c C-u M-s' of all processes in the current buffer.
4553 Limitations:
4554 - Only declared local signals (ports, signals declared in
4555 architecture and blocks) are automatically inserted.
4556 - Global signals declared in packages are not automatically inserted.
4557 Insert them once manually (will be kept afterwards).
4558 - Out parameters of procedures are considered to be read.
4559 Use option `vhdl-entity-file-name' to specify the entity file name
4560 \(used to obtain the port names).
4561
4562
4563 CODE FIXING:
4564 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4565 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4566
4567
4568 PRINTING:
4569 Postscript printing with different faces (an optimized set of faces is
4570 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4571 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4572 postscript printing commands. Option `vhdl-print-two-column' defines
4573 appropriate default settings for nice landscape two-column printing.
4574 The paper format can be set by option `ps-paper-type'. Do not forget to
4575 switch `ps-print-color-p' to nil for printing on black-and-white
4576 printers.
4577
4578
4579 OPTIONS:
4580 User options allow customization of VHDL Mode. All options are
4581 accessible from the \"Options\" menu entry. Simple options (switches
4582 and choices) can directly be changed, while for complex options a
4583 customization buffer is opened. Changed options can be saved for future
4584 sessions using the \"Save Options\" menu entry.
4585
4586 Options and their detailed descriptions can also be accessed by using
4587 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4588 customize-group' for groups). Some customizations only take effect
4589 after some action (read the NOTE in the option documentation).
4590 Customization can also be done globally (i.e. site-wide, read the
4591 INSTALL file).
4592
4593 Not all options are described in this documentation, so go and see
4594 what other useful user options there are (`M-x vhdl-customize' or menu)!
4595
4596
4597 FILE EXTENSIONS:
4598 As default, files with extensions \".vhd\" and \".vhdl\" are
4599 automatically recognized as VHDL source files. To add an extension
4600 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4601
4602 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4603
4604
4605 HINTS:
4606 - To start Emacs with open VHDL hierarchy browser without having to load
4607 a VHDL file first, use the command:
4608
4609 emacs -l vhdl-mode -f speedbar-frame-mode
4610
4611 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4612
4613 - Some features only work on properly indented code.
4614
4615
4616 RELEASE NOTES:
4617 See also the release notes (menu) for added features in new releases.
d2ddb974
KH
4618
4619
4620Maintenance:
4621------------
4622
3dcb36b7 4623To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
d2ddb974
KH
4624Add a description of the problem and include a reproducible test case.
4625
3dcb36b7 4626Questions and enhancement requests can be sent to <reto@gnu.org>.
d2ddb974
KH
4627
4628The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
3dcb36b7
JB
4629The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4630releases. You are kindly invited to participate in beta testing. Subscribe
4631to above mailing lists by sending an email to <reto@gnu.org>.
d2ddb974 4632
3dcb36b7 4633VHDL Mode is officially distributed at
855b42a2 4634URL `http://opensource.ethz.ch/emacs/vhdl-mode.html'
3dcb36b7 4635where the latest version can be found.
d2ddb974
KH
4636
4637
3dcb36b7
JB
4638Known problems:
4639---------------
d2ddb974 4640
5eabfe72 4641- Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
3dcb36b7
JB
4642- XEmacs: Incorrect start-up when automatically opening speedbar.
4643- XEmacs: Indentation in XEmacs 21.4 (and higher).
d2ddb974
KH
4644
4645
3dcb36b7
JB
4646 The VHDL Mode Authors
4647 Reto Zimmermann and Rod Whitby
5eabfe72 4648
d2ddb974
KH
4649Key bindings:
4650-------------
4651
4652\\{vhdl-mode-map}"
4653 (interactive)
4654 (kill-all-local-variables)
d2ddb974 4655 (setq major-mode 'vhdl-mode)
56eb0904
SM
4656 (setq mode-name '("VHDL"
4657 (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4658 (vhdl-electric-mode "e")
4659 (vhdl-stutter-mode "s")))
5eabfe72
KH
4660
4661 ;; set maps and tables
d2ddb974 4662 (use-local-map vhdl-mode-map)
5eabfe72
KH
4663 (set-syntax-table vhdl-mode-syntax-table)
4664 (setq local-abbrev-table vhdl-mode-abbrev-table)
4665
3dcb36b7 4666 ;; set local variables
5eabfe72
KH
4667 (set (make-local-variable 'paragraph-start)
4668 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
d2ddb974
KH
4669 (set (make-local-variable 'paragraph-separate) paragraph-start)
4670 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
cf98062a 4671 (set (make-local-variable 'require-final-newline)
0a2e512a 4672 (if vhdl-emacs-22 mode-require-final-newline t))
d2ddb974
KH
4673 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4674 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4675 (set (make-local-variable 'comment-start) "--")
4676 (set (make-local-variable 'comment-end) "")
0a2e512a
RF
4677 (when vhdl-emacs-21
4678 (set (make-local-variable 'comment-padding) ""))
5eabfe72 4679 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
d2ddb974
KH
4680 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4681 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
5eabfe72 4682 (set (make-local-variable 'comment-multi-line) nil)
d2ddb974 4683 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
5eabfe72 4684 (set (make-local-variable 'hippie-expand-verbose) nil)
d2ddb974
KH
4685
4686 ;; setup the comment indent variable in a Emacs version portable way
4687 ;; ignore any byte compiler warnings you might get here
5eabfe72
KH
4688 (when (boundp 'comment-indent-function)
4689 (make-local-variable 'comment-indent-function)
4690 (setq comment-indent-function 'vhdl-comment-indent))
d2ddb974
KH
4691
4692 ;; initialize font locking
5eabfe72
KH
4693 (set (make-local-variable 'font-lock-defaults)
4694 (list
3dcb36b7 4695 '(nil vhdl-font-lock-keywords) nil
cf38dd42
SM
4696 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4697 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4698 (set (make-local-variable 'syntax-propertize-function)
4699 (syntax-propertize-rules
4700 ;; Mark single quotes as having string quote syntax in
4701 ;; 'c' instances.
4702 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4703 (set (make-local-variable 'font-lock-syntactic-keywords)
4704 vhdl-font-lock-syntactic-keywords))
3dcb36b7
JB
4705 (unless vhdl-emacs-21
4706 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4707 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4708 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4709; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4710 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4711; (turn-on-font-lock)
d2ddb974
KH
4712
4713 ;; variables for source file compilation
3dcb36b7
JB
4714 (when vhdl-compile-use-local-error-regexp
4715 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4716 (set (make-local-variable 'compilation-file-regexp-alist) nil))
5eabfe72
KH
4717
4718 ;; add index menu
4719 (vhdl-index-menu-init)
4720 ;; add source file menu
d2ddb974 4721 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
5eabfe72
KH
4722 ;; add VHDL menu
4723 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4724 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4725 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4726 ;; initialize hideshow and add menu
5eabfe72 4727 (vhdl-hideshow-init)
d2ddb974
KH
4728 (run-hooks 'menu-bar-update-hook)
4729
5eabfe72
KH
4730 ;; miscellaneous
4731 (vhdl-ps-print-init)
3dcb36b7 4732 (vhdl-write-file-hooks-init)
3dcb36b7
JB
4733 (message "VHDL Mode %s.%s" vhdl-version
4734 (if noninteractive "" " See menu for documentation and release notes."))
5eabfe72
KH
4735
4736 ;; run hooks
0a2e512a
RF
4737 (if vhdl-emacs-22
4738 (run-mode-hooks 'vhdl-mode-hook)
4739 (run-hooks 'vhdl-mode-hook)))
5eabfe72
KH
4740
4741(defun vhdl-activate-customizations ()
4742 "Activate all customizations on local variables."
4743 (interactive)
4744 (vhdl-mode-map-init)
4745 (use-local-map vhdl-mode-map)
4746 (set-syntax-table vhdl-mode-syntax-table)
4747 (setq comment-column vhdl-inline-comment-column)
4748 (setq end-comment-column vhdl-end-comment-column)
3dcb36b7 4749 (vhdl-write-file-hooks-init)
5eabfe72
KH
4750 (vhdl-update-mode-menu)
4751 (vhdl-hideshow-init)
56eb0904 4752 (run-hooks 'menu-bar-update-hook))
5eabfe72 4753
3dcb36b7
JB
4754(defun vhdl-write-file-hooks-init ()
4755 "Add/remove hooks when buffer is saved."
5eabfe72
KH
4756 (if vhdl-modify-date-on-saving
4757 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
3dcb36b7
JB
4758 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4759 (make-local-variable 'after-save-hook)
4760 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4761
4762(defun vhdl-process-command-line-option (option)
4763 "Process command line options for VHDL Mode."
4764 (cond
4765 ;; set compiler
4766 ((equal option "-compiler")
4767 (vhdl-set-compiler (car command-line-args-left))
4768 (setq command-line-args-left (cdr command-line-args-left)))
4769 ;; set project
4770 ((equal option "-project")
4771 (vhdl-set-project (car command-line-args-left))
4772 (setq command-line-args-left (cdr command-line-args-left)))))
4773
4774;; make Emacs process VHDL Mode options
4775(setq command-switch-alist
4776 (append command-switch-alist
4777 '(("-compiler" . vhdl-process-command-line-option)
4778 ("-project" . vhdl-process-command-line-option))))
5eabfe72
KH
4779
4780
4781;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4782;;; Keywords and standardized words
5eabfe72
KH
4783;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4784
3dcb36b7
JB
4785(defconst vhdl-93-keywords
4786 '(
4787 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4788 "assert" "attribute"
4789 "begin" "block" "body" "buffer" "bus"
4790 "case" "component" "configuration" "constant"
4791 "disconnect" "downto"
4792 "else" "elsif" "end" "entity" "exit"
4793 "file" "for" "function"
4794 "generate" "generic" "group" "guarded"
4795 "if" "impure" "in" "inertial" "inout" "is"
4796 "label" "library" "linkage" "literal" "loop"
4797 "map" "mod"
4798 "nand" "new" "next" "nor" "not" "null"
4799 "of" "on" "open" "or" "others" "out"
4800 "package" "port" "postponed" "procedure" "process" "pure"
4801 "range" "record" "register" "reject" "rem" "report" "return"
4802 "rol" "ror"
4803 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4804 "then" "to" "transport" "type"
4805 "unaffected" "units" "until" "use"
4806 "variable"
4807 "wait" "when" "while" "with"
4808 "xnor" "xor"
4809 )
4810 "List of VHDL'93 keywords.")
d2ddb974 4811
5eabfe72
KH
4812(defconst vhdl-ams-keywords
4813 '(
4814 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4815 "reference" "spectrum" "subnature" "terminal" "through"
4816 "tolerance"
4817 )
4818 "List of VHDL-AMS keywords.")
d2ddb974 4819
5eabfe72
KH
4820(defconst vhdl-verilog-keywords
4821 '(
4822 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4823 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4824 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4825 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4826 "endprimitive" "endspecify" "endtable" "endtask" "event"
4827 "for" "force" "forever" "fork" "function"
4828 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4829 "macromodule" "makefile" "medium" "module"
4830 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4831 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4832 "pullup"
4833 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4834 "rtranif0" "rtranif1"
4835 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4836 "strong1" "supply" "supply0" "supply1"
4837 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4838 "triand" "trior" "trireg"
4839 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4840 )
4841 "List of Verilog keywords as candidate for additional reserved words.")
d2ddb974 4842
5eabfe72
KH
4843(defconst vhdl-93-types
4844 '(
4845 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4846 "real" "time" "natural" "positive" "string" "line" "text" "side"
4847 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4848 "std_logic" "std_logic_vector"
4849 "std_ulogic" "std_ulogic_vector"
4850 )
4851 "List of VHDL'93 standardized types.")
d2ddb974 4852
5eabfe72
KH
4853(defconst vhdl-ams-types
4854 '(
4855 "domain_type" "real_vector"
3dcb36b7
JB
4856 ;; from `nature_pkg' package
4857 "voltage" "current" "electrical" "position" "velocity" "force"
4858 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4859 "pressure" "flowrate" "fluid"
4860 )
5eabfe72 4861 "List of VHDL-AMS standardized types.")
d2ddb974 4862
5eabfe72
KH
4863(defconst vhdl-math-types
4864 '(
4865 "complex" "complex_polar"
4866 )
4867 "List of Math Packages standardized types.")
d2ddb974 4868
5eabfe72
KH
4869(defconst vhdl-93-attributes
4870 '(
4871 "base" "left" "right" "high" "low" "pos" "val" "succ"
4872 "pred" "leftof" "rightof" "range" "reverse_range"
4873 "length" "delayed" "stable" "quiet" "transaction"
4874 "event" "active" "last_event" "last_active" "last_value"
4875 "driving" "driving_value" "ascending" "value" "image"
4876 "simple_name" "instance_name" "path_name"
4877 "foreign"
4878 )
4879 "List of VHDL'93 standardized attributes.")
d2ddb974 4880
5eabfe72
KH
4881(defconst vhdl-ams-attributes
4882 '(
4883 "across" "through"
4884 "reference" "contribution" "tolerance"
4885 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4886 "ramp" "slew"
4887 )
4888 "List of VHDL-AMS standardized attributes.")
d2ddb974 4889
5eabfe72
KH
4890(defconst vhdl-93-enum-values
4891 '(
4892 "true" "false"
4893 "note" "warning" "error" "failure"
4894 "read_mode" "write_mode" "append_mode"
4895 "open_ok" "status_error" "name_error" "mode_error"
4896 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4897 "right" "left"
4898 )
4899 "List of VHDL'93 standardized enumeration values.")
d2ddb974 4900
5eabfe72
KH
4901(defconst vhdl-ams-enum-values
4902 '(
4903 "quiescent_domain" "time_domain" "frequency_domain"
3dcb36b7
JB
4904 ;; from `nature_pkg' package
4905 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5eabfe72
KH
4906 )
4907 "List of VHDL-AMS standardized enumeration values.")
4908
4909(defconst vhdl-math-constants
4910 '(
4911 "math_e" "math_1_over_e"
4912 "math_pi" "math_two_pi" "math_1_over_pi"
4913 "math_half_pi" "math_q_pi" "math_3_half_pi"
4914 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4915 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4916 "math_deg_to_rad" "math_rad_to_deg"
4917 "cbase_1" "cbase_j" "czero"
4918 )
4919 "List of Math Packages standardized constants.")
4920
4921(defconst vhdl-93-functions
4922 '(
4923 "now" "resolved" "rising_edge" "falling_edge"
4924 "read" "readline" "write" "writeline" "endfile"
4925 "resize" "is_X" "std_match"
4926 "shift_left" "shift_right" "rotate_left" "rotate_right"
4927 "to_unsigned" "to_signed" "to_integer"
4928 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4929 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4930 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4931 "shl" "shr" "ext" "sxt"
3dcb36b7 4932 "deallocate"
5eabfe72
KH
4933 )
4934 "List of VHDL'93 standardized functions.")
4935
4936(defconst vhdl-ams-functions
4937 '(
4938 "frequency"
4939 )
4940 "List of VHDL-AMS standardized functions.")
4941
4942(defconst vhdl-math-functions
4943 '(
4944 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4945 "sqrt" "cbrt" "exp" "log"
4946 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4947 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4948 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4949 )
4950 "List of Math Packages standardized functions.")
4951
4952(defconst vhdl-93-packages
4953 '(
4954 "std_logic_1164" "numeric_std" "numeric_bit"
4955 "standard" "textio"
4956 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4957 "std_logic_misc" "std_logic_textio"
4958 "ieee" "std" "work"
4959 )
4960 "List of VHDL'93 standardized packages and libraries.")
4961
3dcb36b7
JB
4962(defconst vhdl-ams-packages
4963 '(
4964 ;; from `nature_pkg' package
4965 "nature_pkg"
4966 )
4967 "List of VHDL-AMS standardized packages and libraries.")
4968
5eabfe72
KH
4969(defconst vhdl-math-packages
4970 '(
4971 "math_real" "math_complex"
4972 )
4973 "List of Math Packages standardized packages and libraries.")
4974
4975(defvar vhdl-keywords nil
4976 "List of VHDL keywords.")
4977
4978(defvar vhdl-types nil
4979 "List of VHDL standardized types.")
4980
4981(defvar vhdl-attributes nil
4982 "List of VHDL standardized attributes.")
4983
4984(defvar vhdl-enum-values nil
4985 "List of VHDL standardized enumeration values.")
4986
4987(defvar vhdl-constants nil
4988 "List of VHDL standardized constants.")
4989
4990(defvar vhdl-functions nil
4991 "List of VHDL standardized functions.")
4992
4993(defvar vhdl-packages nil
4994 "List of VHDL standardized packages and libraries.")
4995
4996(defvar vhdl-reserved-words nil
4997 "List of additional reserved words.")
4998
4999(defvar vhdl-keywords-regexp nil
5000 "Regexp for VHDL keywords.")
5001
5002(defvar vhdl-types-regexp nil
5003 "Regexp for VHDL standardized types.")
5004
5005(defvar vhdl-attributes-regexp nil
5006 "Regexp for VHDL standardized attributes.")
5007
5008(defvar vhdl-enum-values-regexp nil
5009 "Regexp for VHDL standardized enumeration values.")
5010
5011(defvar vhdl-functions-regexp nil
5012 "Regexp for VHDL standardized functions.")
5013
5014(defvar vhdl-packages-regexp nil
5015 "Regexp for VHDL standardized packages and libraries.")
5016
5017(defvar vhdl-reserved-words-regexp nil
5018 "Regexp for additional reserved words.")
5019
3dcb36b7
JB
5020(defvar vhdl-directive-keywords-regexp nil
5021 "Regexp for compiler directive keywords.")
5022
5eabfe72
KH
5023(defun vhdl-words-init ()
5024 "Initialize reserved words."
5025 (setq vhdl-keywords
5026 (append vhdl-93-keywords
5027 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5028 (setq vhdl-types
5029 (append vhdl-93-types
5030 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5031 (when (vhdl-standard-p 'math) vhdl-math-types)))
5032 (setq vhdl-attributes
5033 (append vhdl-93-attributes
5034 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5035 (setq vhdl-enum-values
5036 (append vhdl-93-enum-values
5037 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5038 (setq vhdl-constants
5039 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5040 (setq vhdl-functions
5041 (append vhdl-93-functions
5042 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5043 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5044 (setq vhdl-packages
5045 (append vhdl-93-packages
3dcb36b7 5046 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5eabfe72
KH
5047 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5048 (setq vhdl-reserved-words
5049 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5050 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5051 '("")))
5052 (setq vhdl-keywords-regexp
5053 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5054 (setq vhdl-types-regexp
5055 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5056 (setq vhdl-attributes-regexp
5057 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5058 (setq vhdl-enum-values-regexp
5059 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5060 (setq vhdl-functions-regexp
5061 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5062 (setq vhdl-packages-regexp
5063 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5064 (setq vhdl-reserved-words-regexp
5065 (concat "\\<\\("
5066 (unless (equal vhdl-forbidden-syntax "")
5067 (concat vhdl-forbidden-syntax "\\|"))
5068 (regexp-opt vhdl-reserved-words)
5069 "\\)\\>"))
3dcb36b7
JB
5070 (setq vhdl-directive-keywords-regexp
5071 (concat "\\<\\(" (mapconcat 'regexp-quote
5072 vhdl-directive-keywords "\\|") "\\)\\>"))
5eabfe72
KH
5073 (vhdl-abbrev-list-init))
5074
5075;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5076;; Words to expand
5077
5078(defvar vhdl-abbrev-list nil
5079 "Predefined abbreviations for VHDL.")
5080
5081(defun vhdl-abbrev-list-init ()
5082 (setq vhdl-abbrev-list
5083 (append
5084 (list vhdl-upper-case-keywords) vhdl-keywords
5085 (list vhdl-upper-case-types) vhdl-types
5086 (list vhdl-upper-case-attributes) vhdl-attributes
5087 (list vhdl-upper-case-enum-values) vhdl-enum-values
5088 (list vhdl-upper-case-constants) vhdl-constants
5089 (list nil) vhdl-functions
5090 (list nil) vhdl-packages)))
5091
5092;; initialize reserved words for VHDL Mode
5093(vhdl-words-init)
5094
5095
5096;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 5097;;; Indentation
5eabfe72
KH
5098;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5099
5100;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
5101;; Syntax analysis
5102
5103;; constant regular expressions for looking at various constructs
5104
5105(defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5106 "Regexp describing a VHDL symbol.
5107We cannot use just `word' syntax class since `_' cannot be in word
5108class. Putting underscore in word class breaks forward word movement
5109behavior that users are familiar with.")
5110
5111(defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5112 "Regexp describing a case statement header key.")
5113
5114(defconst vhdl-label-key
5115 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5116 "Regexp describing a VHDL label.")
5117
5118;; Macro definitions:
5119
5120(defmacro vhdl-point (position)
5eabfe72
KH
5121 "Return the value of point at certain commonly referenced POSITIONs.
5122POSITION can be one of the following symbols:
5123
5124bol -- beginning of line
5125eol -- end of line
5126bod -- beginning of defun
5127boi -- back to indentation
5128eoi -- last whitespace on line
5129ionl -- indentation of next line
5130iopl -- indentation of previous line
5131bonl -- beginning of next line
5132bopl -- beginning of previous line
5133
5134This function does not modify point or mark."
d2ddb974 5135 (or (and (eq 'quote (car-safe position))
3dcb36b7
JB
5136 (null (cddr position)))
5137 (error "ERROR: Bad buffer position requested: %s" position))
d2ddb974 5138 (setq position (nth 1 position))
d4a5b644
GM
5139 `(let ((here (point)))
5140 ,@(cond
5141 ((eq position 'bol) '((beginning-of-line)))
5142 ((eq position 'eol) '((end-of-line)))
5143 ((eq position 'bod) '((save-match-data
5144 (vhdl-beginning-of-defun))))
5145 ((eq position 'boi) '((back-to-indentation)))
3dcb36b7 5146 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
d4a5b644
GM
5147 ((eq position 'bonl) '((forward-line 1)))
5148 ((eq position 'bopl) '((forward-line -1)))
5149 ((eq position 'iopl)
5150 '((forward-line -1)
5151 (back-to-indentation)))
5152 ((eq position 'ionl)
5153 '((forward-line 1)
5154 (back-to-indentation)))
3dcb36b7 5155 (t (error "ERROR: Unknown buffer position requested: %s" position))
d4a5b644
GM
5156 )
5157 (prog1
5158 (point)
5159 (goto-char here))
5160 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5161 ;; doesn't hurt for v19
5162 ,@nil
5163 ))
d2ddb974
KH
5164
5165(defmacro vhdl-safe (&rest body)
5eabfe72 5166 "Safely execute BODY, return nil if an error occurred."
d4a5b644
GM
5167 `(condition-case nil
5168 (progn ,@body)
5169 (error nil)))
d2ddb974
KH
5170
5171(defmacro vhdl-add-syntax (symbol &optional relpos)
5eabfe72
KH
5172 "A simple macro to append the syntax in SYMBOL to the syntax list.
5173Try to increase performance by using this macro."
d4a5b644
GM
5174 `(setq vhdl-syntactic-context
5175 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
d2ddb974
KH
5176
5177(defmacro vhdl-has-syntax (symbol)
5eabfe72
KH
5178 "A simple macro to return check the syntax list.
5179Try to increase performance by using this macro."
d4a5b644 5180 `(assoc ,symbol vhdl-syntactic-context))
d2ddb974
KH
5181
5182;; Syntactic element offset manipulation:
5183
5184(defun vhdl-read-offset (langelem)
5eabfe72 5185 "Read new offset value for LANGELEM from minibuffer.
2e8b9c7d 5186Return a valid value only."
d2ddb974
KH
5187 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5188 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5189 (prompt "Offset: ")
5190 offset input interned)
5191 (while (not offset)
5192 (setq input (read-string prompt oldoff)
5193 offset (cond ((string-equal "+" input) '+)
5194 ((string-equal "-" input) '-)
5195 ((string-equal "++" input) '++)
5196 ((string-equal "--" input) '--)
5197 ((string-match "^-?[0-9]+$" input)
027a4b6b 5198 (string-to-number input))
d2ddb974
KH
5199 ((fboundp (setq interned (intern input)))
5200 interned)
5201 ((boundp interned) interned)
5202 ;; error, but don't signal one, keep trying
5203 ;; to read an input value
5204 (t (ding)
5205 (setq prompt errmsg)
5206 nil))))
5207 offset))
5208
5209(defun vhdl-set-offset (symbol offset &optional add-p)
5210 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5211SYMBOL is the syntactic element symbol to change and OFFSET is the new
a4c6cfad 5212offset for that syntactic element. Optional ADD-P says to add SYMBOL to
d2ddb974
KH
5213`vhdl-offsets-alist' if it doesn't already appear there."
5214 (interactive
5215 (let* ((langelem
5216 (intern (completing-read
5217 (concat "Syntactic symbol to change"
5218 (if current-prefix-arg " or add" "")
5219 ": ")
5220 (mapcar
5221 (function
5222 (lambda (langelem)
5223 (cons (format "%s" (car langelem)) nil)))
5224 vhdl-offsets-alist)
5225 nil (not current-prefix-arg)
5226 ;; initial contents tries to be the last element
5227 ;; on the syntactic analysis list for the current
5228 ;; line
5229 (let* ((syntax (vhdl-get-syntactic-context))
5230 (len (length syntax))
5231 (ic (format "%s" (car (nth (1- len) syntax)))))
5eabfe72 5232 ic)
d2ddb974
KH
5233 )))
5234 (offset (vhdl-read-offset langelem)))
5235 (list langelem offset current-prefix-arg)))
5236 ;; sanity check offset
5237 (or (eq offset '+)
5238 (eq offset '-)
5239 (eq offset '++)
5240 (eq offset '--)
5241 (integerp offset)
5242 (fboundp offset)
5243 (boundp offset)
3dcb36b7 5244 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
d2ddb974
KH
5245 offset))
5246 (let ((entry (assq symbol vhdl-offsets-alist)))
5247 (if entry
5248 (setcdr entry offset)
5249 (if add-p
5eabfe72
KH
5250 (setq vhdl-offsets-alist
5251 (cons (cons symbol offset) vhdl-offsets-alist))
3dcb36b7 5252 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
d2ddb974
KH
5253 (vhdl-keep-region-active))
5254
5255(defun vhdl-set-style (style &optional local)
5eabfe72 5256 "Set `vhdl-mode' variables to use one of several different indentation styles.
d2ddb974
KH
5257STYLE is a string representing the desired style and optional LOCAL is
5258a flag which, if non-nil, means to make the style variables being
5259changed buffer local, instead of the default, which is to set the
5260global variables. Interactively, the flag comes from the prefix
5261argument. The styles are chosen from the `vhdl-style-alist' variable."
5262 (interactive (list (completing-read "Use which VHDL indentation style? "
5eabfe72 5263 vhdl-style-alist nil t)
d2ddb974
KH
5264 current-prefix-arg))
5265 (let ((vars (cdr (assoc style vhdl-style-alist))))
5266 (or vars
3dcb36b7 5267 (error "ERROR: Invalid VHDL indentation style `%s'" style))
d2ddb974 5268 ;; set all the variables
51b5ad57 5269 (mapc
d2ddb974
KH
5270 (function
5271 (lambda (varentry)
5272 (let ((var (car varentry))
5273 (val (cdr varentry)))
5274 (and local
5275 (make-local-variable var))
5276 ;; special case for vhdl-offsets-alist
5277 (if (not (eq var 'vhdl-offsets-alist))
5278 (set var val)
5279 ;; reset vhdl-offsets-alist to the default value first
5280 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5281 ;; now set the langelems that are different
5282 (mapcar
5283 (function
5284 (lambda (langentry)
5285 (let ((langelem (car langentry))
5286 (offset (cdr langentry)))
5287 (vhdl-set-offset langelem offset)
5288 )))
5289 val))
5290 )))
5291 vars))
5292 (vhdl-keep-region-active))
5293
5294(defun vhdl-get-offset (langelem)
5eabfe72
KH
5295 "Get offset from LANGELEM which is a cons cell of the form:
5296\(SYMBOL . RELPOS). The symbol is matched against
5297vhdl-offsets-alist and the offset found there is either returned,
5298or added to the indentation at RELPOS. If RELPOS is nil, then
5299the offset is simply returned."
d2ddb974
KH
5300 (let* ((symbol (car langelem))
5301 (relpos (cdr langelem))
5302 (match (assq symbol vhdl-offsets-alist))
5303 (offset (cdr-safe match)))
5304 ;; offset can be a number, a function, a variable, or one of the
5305 ;; symbols + or -
5306 (cond
5307 ((not match)
5308 (if vhdl-strict-syntax-p
3dcb36b7 5309 (error "ERROR: Don't know how to indent a %s" symbol)
d2ddb974
KH
5310 (setq offset 0
5311 relpos 0)))
5312 ((eq offset '+) (setq offset vhdl-basic-offset))
5313 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5314 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5315 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5316 ((and (not (numberp offset))
5317 (fboundp offset))
5318 (setq offset (funcall offset langelem)))
5319 ((not (numberp offset))
5320 (setq offset (eval offset)))
5321 )
5322 (+ (if (and relpos
5323 (< relpos (vhdl-point 'bol)))
5324 (save-excursion
5325 (goto-char relpos)
5326 (current-column))
5327 0)
5328 offset)))
5329
5330;; Syntactic support functions:
5331
3dcb36b7
JB
5332(defun vhdl-in-comment-p ()
5333 "Check if point is in a comment."
5334 (eq (vhdl-in-literal) 'comment))
5335
5336(defun vhdl-in-string-p ()
5337 "Check if point is in a string."
5338 (eq (vhdl-in-literal) 'string))
d2ddb974 5339
3dcb36b7 5340(defun vhdl-in-literal ()
5eabfe72 5341 "Determine if point is in a VHDL literal."
d2ddb974 5342 (save-excursion
5eabfe72 5343 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
d2ddb974
KH
5344 (cond
5345 ((nth 3 state) 'string)
5346 ((nth 4 state) 'comment)
0a2e512a 5347 ((vhdl-beginning-of-macro) 'pound)
5eabfe72 5348 (t nil)))))
d2ddb974 5349
3dcb36b7
JB
5350(defun vhdl-forward-comment (&optional direction)
5351 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5352negative, skip forward otherwise."
5353 (interactive "p")
5354 (if (and direction (< direction 0))
5355 ;; skip backwards
5356 (progn
5357 (skip-chars-backward " \t\n")
5358 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5359 (goto-char (match-beginning 3))
5360 (skip-chars-backward " \t\n")))
5361 ;; skip forwards
5362 (skip-chars-forward " \t\n")
5363 (while (looking-at "--.*")
5364 (goto-char (match-end 0))
5365 (skip-chars-forward " \t\n"))))
5366
5367;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
f8246027 5368(unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
3dcb36b7
JB
5369 (defalias 'vhdl-forward-comment 'forward-comment))
5370
d2ddb974
KH
5371;; This is the best we can do in Win-Emacs.
5372(defun vhdl-win-il (&optional lim)
5eabfe72 5373 "Determine if point is in a VHDL literal."
d2ddb974
KH
5374 (save-excursion
5375 (let* ((here (point))
5376 (state nil)
5377 (match nil)
5378 (lim (or lim (vhdl-point 'bod))))
5379 (goto-char lim )
5380 (while (< (point) here)
5381 (setq match
5382 (and (re-search-forward "--\\|[\"']"
5383 here 'move)
5384 (buffer-substring (match-beginning 0) (match-end 0))))
5385 (setq state
5386 (cond
5387 ;; no match
5388 ((null match) nil)
5389 ;; looking at the opening of a VHDL style comment
5390 ((string= "--" match)
5391 (if (<= here (progn (end-of-line) (point))) 'comment))
5392 ;; looking at the opening of a double quote string
5393 ((string= "\"" match)
5394 (if (not (save-restriction
5395 ;; this seems to be necessary since the
5396 ;; re-search-forward will not work without it
5397 (narrow-to-region (point) here)
5398 (re-search-forward
5399 ;; this regexp matches a double quote
5400 ;; which is preceded by an even number
5401 ;; of backslashes, including zero
5402 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5403 'string))
5404 ;; looking at the opening of a single quote string
5405 ((string= "'" match)
5406 (if (not (save-restriction
5407 ;; see comments from above
5408 (narrow-to-region (point) here)
5409 (re-search-forward
5410 ;; this matches a single quote which is
5411 ;; preceded by zero or two backslashes.
5412 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5413 here 'move)))
5414 'string))
5415 (t nil)))
5416 ) ; end-while
5417 state)))
5418
5eabfe72 5419(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5420 (fset 'vhdl-in-literal 'vhdl-win-il))
5421
5422;; Skipping of "syntactic whitespace". Syntactic whitespace is
5423;; defined as lexical whitespace or comments. Search no farther back
5424;; or forward than optional LIM. If LIM is omitted, (point-min) is
5425;; used for backward skipping, (point-max) is used for forward
5426;; skipping.
5427
5428(defun vhdl-forward-syntactic-ws (&optional lim)
5eabfe72 5429 "Forward skip of syntactic whitespace."
0a2e512a
RF
5430 (let* ((here (point-max))
5431 (hugenum (point-max)))
5432 (while (/= here (point))
5433 (setq here (point))
5434 (vhdl-forward-comment hugenum)
5435 ;; skip preprocessor directives
5436 (when (and (eq (char-after) ?#)
5437 (= (vhdl-point 'boi) (point)))
5438 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5439 (= (forward-line 1) 0)))
5440 (end-of-line)))
5441 (if lim (goto-char (min (point) lim)))))
5442
d2ddb974
KH
5443
5444;; This is the best we can do in Win-Emacs.
5445(defun vhdl-win-fsws (&optional lim)
5eabfe72 5446 "Forward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5447 (let ((lim (or lim (point-max)))
5448 stop)
5449 (while (not stop)
5450 (skip-chars-forward " \t\n\r\f" lim)
5451 (cond
5452 ;; vhdl comment
5453 ((looking-at "--") (end-of-line))
5454 ;; none of the above
3dcb36b7 5455 (t (setq stop t))))))
d2ddb974 5456
5eabfe72 5457(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5458 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5459
0a2e512a
RF
5460(defun vhdl-beginning-of-macro (&optional lim)
5461 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5462 (let ((here (point)))
5463 (beginning-of-line)
5464 (while (eq (char-before (1- (point))) ?\\)
5465 (forward-line -1))
5466 (back-to-indentation)
5467 (if (and (<= (point) here)
5468 (eq (char-after) ?#))
5469 t
5470 (goto-char here)
5471 nil)))
5472
d2ddb974 5473(defun vhdl-backward-syntactic-ws (&optional lim)
5eabfe72 5474 "Backward skip over syntactic whitespace."
0a2e512a
RF
5475 (let* ((here (point-min))
5476 (hugenum (- (point-max))))
5477 (while (/= here (point))
5478 (setq here (point))
5479 (vhdl-forward-comment hugenum)
5480 (vhdl-beginning-of-macro))
5481 (if lim (goto-char (max (point) lim)))))
d2ddb974
KH
5482
5483;; This is the best we can do in Win-Emacs.
5484(defun vhdl-win-bsws (&optional lim)
5eabfe72 5485 "Backward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5486 (let ((lim (or lim (vhdl-point 'bod)))
5487 stop)
5488 (while (not stop)
5489 (skip-chars-backward " \t\n\r\f" lim)
5490 (cond
5491 ;; vhdl comment
3dcb36b7 5492 ((eq (vhdl-in-literal) 'comment)
d2ddb974
KH
5493 (skip-chars-backward "^-" lim)
5494 (skip-chars-backward "-" lim)
5495 (while (not (or (and (= (following-char) ?-)
5496 (= (char-after (1+ (point))) ?-))
5497 (<= (point) lim)))
5498 (skip-chars-backward "^-" lim)
5499 (skip-chars-backward "-" lim)))
5500 ;; none of the above
3dcb36b7 5501 (t (setq stop t))))))
d2ddb974 5502
5eabfe72 5503(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5504 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5505
5506;; Functions to help finding the correct indentation column:
5507
5508(defun vhdl-first-word (point)
5509 "If the keyword at POINT is at boi, then return (current-column) at
5510that point, else nil."
5511 (save-excursion
5512 (and (goto-char point)
5513 (eq (point) (vhdl-point 'boi))
5514 (current-column))))
5515
5516(defun vhdl-last-word (point)
5517 "If the keyword at POINT is at eoi, then return (current-column) at
5518that point, else nil."
5519 (save-excursion
5520 (and (goto-char point)
5521 (save-excursion (or (eq (progn (forward-sexp) (point))
5522 (vhdl-point 'eoi))
5523 (looking-at "\\s-*\\(--\\)?")))
5524 (current-column))))
5525
5526;; Core syntactic evaluation functions:
5527
5528(defconst vhdl-libunit-re
5529 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5530
5531(defun vhdl-libunit-p ()
5532 (and
5533 (save-excursion
5534 (forward-sexp)
5535 (skip-chars-forward " \t\n")
5536 (not (looking-at "is\\b[^_]")))
5537 (save-excursion
5538 (backward-sexp)
5539 (and (not (looking-at "use\\b[^_]"))
5540 (progn
5541 (forward-sexp)
5542 (vhdl-forward-syntactic-ws)
5543 (/= (following-char) ?:))))
5544 ))
5545
5546(defconst vhdl-defun-re
5eabfe72 5547 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
d2ddb974
KH
5548
5549(defun vhdl-defun-p ()
5550 (save-excursion
5eabfe72
KH
5551 (if (looking-at "block\\|process\\|procedural")
5552 ;; "block", "process", "procedural":
d2ddb974
KH
5553 (save-excursion
5554 (backward-sexp)
5555 (not (looking-at "end\\s-+\\w")))
5556 ;; "architecture", "configuration", "entity",
5557 ;; "package", "procedure", "function":
5558 t)))
5559
5560(defun vhdl-corresponding-defun ()
5561 "If the word at the current position corresponds to a \"defun\"
5562keyword, then return a string that can be used to find the
5563corresponding \"begin\" keyword, else return nil."
5564 (save-excursion
5565 (and (looking-at vhdl-defun-re)
5566 (vhdl-defun-p)
5eabfe72
KH
5567 (if (looking-at "block\\|process\\|procedural")
5568 ;; "block", "process". "procedural:
d2ddb974
KH
5569 (buffer-substring (match-beginning 0) (match-end 0))
5570 ;; "architecture", "configuration", "entity", "package",
5571 ;; "procedure", "function":
5572 "is"))))
5573
5574(defconst vhdl-begin-fwd-re
5eabfe72 5575 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
d2ddb974
KH
5576 "A regular expression for searching forward that matches all known
5577\"begin\" keywords.")
5578
5579(defconst vhdl-begin-bwd-re
5eabfe72 5580 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
d2ddb974
KH
5581 "A regular expression for searching backward that matches all known
5582\"begin\" keywords.")
5583
5584(defun vhdl-begin-p (&optional lim)
5585 "Return t if we are looking at a real \"begin\" keyword.
5586Assumes that the caller will make sure that we are looking at
5587vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5588the middle of an identifier that just happens to contain a \"begin\"
5589keyword."
5590 (cond
5591 ;; "[architecture|case|configuration|entity|package|
5592 ;; procedure|function] ... is":
5593 ((and (looking-at "i")
5594 (save-excursion
5595 ;; Skip backward over first sexp (needed to skip over a
5596 ;; procedure interface list, and is harmless in other
5597 ;; situations). Note that we need "return" in the
5598 ;; following search list so that we don't run into
5599 ;; semicolons in the function interface list.
5600 (backward-sexp)
5601 (let (foundp)
5602 (while (and (not foundp)
5603 (re-search-backward
5eabfe72 5604 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
d2ddb974
KH
5605 lim 'move))
5606 (if (or (= (preceding-char) ?_)
3dcb36b7 5607 (vhdl-in-literal))
d2ddb974
KH
5608 (backward-char)
5609 (setq foundp t))))
5610 (and (/= (following-char) ?\;)
5eabfe72 5611 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
d2ddb974
KH
5612 t)
5613 ;; "begin", "then":
5614 ((looking-at "be\\|t")
5615 t)
5616 ;; "else":
5617 ((and (looking-at "e")
5618 ;; make sure that the "else" isn't inside a
5619 ;; conditional signal assignment.
5620 (save-excursion
5621 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5622 (or (eq (following-char) ?\;)
5623 (eq (point) lim))))
5624 t)
5eabfe72 5625 ;; "block", "generate", "loop", "process", "procedural",
d2ddb974
KH
5626 ;; "units", "record":
5627 ((and (looking-at "bl\\|[glpur]")
5628 (save-excursion
5629 (backward-sexp)
5630 (not (looking-at "end\\s-+\\w"))))
5631 t)
5632 ;; "component":
5633 ((and (looking-at "c")
5634 (save-excursion
5635 (backward-sexp)
5636 (not (looking-at "end\\s-+\\w")))
5637 ;; look out for the dreaded entity class in an attribute
5638 (save-excursion
5639 (vhdl-backward-syntactic-ws lim)
5640 (/= (preceding-char) ?:)))
5641 t)
5642 ;; "for" (inside configuration declaration):
5643 ((and (looking-at "f")
5644 (save-excursion
5645 (backward-sexp)
5646 (not (looking-at "end\\s-+\\w")))
5647 (vhdl-has-syntax 'configuration))
5648 t)
5649 ))
5650
5651(defun vhdl-corresponding-mid (&optional lim)
5652 (cond
5eabfe72 5653 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
d2ddb974
KH
5654 "begin")
5655 ((looking-at "then")
5656 "<else>")
5657 (t
5658 "end")))
5659
5660(defun vhdl-corresponding-end (&optional lim)
5661 "If the word at the current position corresponds to a \"begin\"
5662keyword, then return a vector containing enough information to find
5663the corresponding \"end\" keyword, else return nil. The keyword to
5664search forward for is aref 0. The column in which the keyword must
5665appear is aref 1 or nil if any column is suitable.
5666Assumes that the caller will make sure that we are not in the middle
5667of an identifier that just happens to contain a \"begin\" keyword."
5668 (save-excursion
5669 (and (looking-at vhdl-begin-fwd-re)
5670 (/= (preceding-char) ?_)
3dcb36b7 5671 (not (vhdl-in-literal))
d2ddb974
KH
5672 (vhdl-begin-p lim)
5673 (cond
5674 ;; "is", "generate", "loop":
5675 ((looking-at "[igl]")
5676 (vector "end"
5677 (and (vhdl-last-word (point))
5678 (or (vhdl-first-word (point))
5679 (save-excursion
5680 (vhdl-beginning-of-statement-1 lim)
5681 (vhdl-backward-skip-label lim)
5682 (vhdl-first-word (point)))))))
5683 ;; "begin", "else", "for":
5684 ((looking-at "be\\|[ef]")
5685 (vector "end"
5686 (and (vhdl-last-word (point))
5687 (or (vhdl-first-word (point))
5688 (save-excursion
5689 (vhdl-beginning-of-statement-1 lim)
5690 (vhdl-backward-skip-label lim)
5691 (vhdl-first-word (point)))))))
5692 ;; "component", "units", "record":
5693 ((looking-at "[cur]")
5694 ;; The first end found will close the block
5695 (vector "end" nil))
5eabfe72 5696 ;; "block", "process", "procedural":
d2ddb974
KH
5697 ((looking-at "bl\\|p")
5698 (vector "end"
5699 (or (vhdl-first-word (point))
5700 (save-excursion
5701 (vhdl-beginning-of-statement-1 lim)
5702 (vhdl-backward-skip-label lim)
5703 (vhdl-first-word (point))))))
5704 ;; "then":
5705 ((looking-at "t")
5706 (vector "elsif\\|else\\|end\\s-+if"
5707 (and (vhdl-last-word (point))
5708 (or (vhdl-first-word (point))
5709 (save-excursion
5710 (vhdl-beginning-of-statement-1 lim)
5711 (vhdl-backward-skip-label lim)
5712 (vhdl-first-word (point)))))))
5713 ))))
5714
5715(defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5716
5717(defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5718
5719(defun vhdl-end-p (&optional lim)
5720 "Return t if we are looking at a real \"end\" keyword.
5721Assumes that the caller will make sure that we are looking at
5722vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5723the middle of an identifier that just happens to contain an \"end\"
5724keyword."
5725 (or (not (looking-at "else"))
5726 ;; make sure that the "else" isn't inside a conditional signal
5727 ;; assignment.
5728 (save-excursion
5729 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5730 (or (eq (following-char) ?\;)
0a2e512a
RF
5731 (eq (point) lim)
5732 (vhdl-in-literal)))))
d2ddb974
KH
5733
5734(defun vhdl-corresponding-begin (&optional lim)
5735 "If the word at the current position corresponds to an \"end\"
5736keyword, then return a vector containing enough information to find
5737the corresponding \"begin\" keyword, else return nil. The keyword to
a4c6cfad 5738search backward for is aref 0. The column in which the keyword must
d2ddb974
KH
5739appear is aref 1 or nil if any column is suitable. The supplementary
5740keyword to search forward for is aref 2 or nil if this is not
5741required. If aref 3 is t, then the \"begin\" keyword may be found in
5742the middle of a statement.
5743Assumes that the caller will make sure that we are not in the middle
5744of an identifier that just happens to contain an \"end\" keyword."
5745 (save-excursion
5746 (let (pos)
5747 (if (and (looking-at vhdl-end-fwd-re)
3dcb36b7 5748 (not (vhdl-in-literal))
d2ddb974
KH
5749 (vhdl-end-p lim))
5750 (if (looking-at "el")
5751 ;; "else", "elsif":
5752 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5753 ;; "end ...":
5754 (setq pos (point))
5755 (forward-sexp)
5756 (skip-chars-forward " \t\n")
5757 (cond
5758 ;; "end if":
5759 ((looking-at "if\\b[^_]")
5760 (vector "else\\|elsif\\|if"
5761 (vhdl-first-word pos)
5762 "else\\|then" nil))
5763 ;; "end component":
5764 ((looking-at "component\\b[^_]")
5765 (vector (buffer-substring (match-beginning 1)
5766 (match-end 1))
5767 (vhdl-first-word pos)
5768 nil nil))
5769 ;; "end units", "end record":
5770 ((looking-at "\\(units\\|record\\)\\b[^_]")
5771 (vector (buffer-substring (match-beginning 1)
5772 (match-end 1))
5773 (vhdl-first-word pos)
5774 nil t))
5eabfe72
KH
5775 ;; "end block", "end process", "end procedural":
5776 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
d2ddb974
KH
5777 (vector "begin" (vhdl-first-word pos) nil nil))
5778 ;; "end case":
5779 ((looking-at "case\\b[^_]")
5780 (vector "case" (vhdl-first-word pos) "is" nil))
5781 ;; "end generate":
5782 ((looking-at "generate\\b[^_]")
5783 (vector "generate\\|for\\|if"
5784 (vhdl-first-word pos)
5785 "generate" nil))
5786 ;; "end loop":
5787 ((looking-at "loop\\b[^_]")
5788 (vector "loop\\|while\\|for"
5789 (vhdl-first-word pos)
5790 "loop" nil))
5791 ;; "end for" (inside configuration declaration):
5792 ((looking-at "for\\b[^_]")
5793 (vector "for" (vhdl-first-word pos) nil nil))
5794 ;; "end [id]":
5795 (t
5796 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5797 (vhdl-first-word pos)
5798 ;; return an alist of (statement . keyword) mappings
5799 '(
5800 ;; "begin ... end [id]":
0a2e512a 5801 ("begin" . nil)
d2ddb974 5802 ;; "architecture ... is ... begin ... end [id]":
0a2e512a 5803 ("architecture" . "is")
d2ddb974
KH
5804 ;; "configuration ... is ... end [id]":
5805 ("configuration" . "is")
5806 ;; "entity ... is ... end [id]":
0a2e512a 5807 ("entity" . "is")
d2ddb974 5808 ;; "package ... is ... end [id]":
0a2e512a 5809 ("package" . "is")
d2ddb974
KH
5810 ;; "procedure ... is ... begin ... end [id]":
5811 ("procedure" . "is")
5812 ;; "function ... is ... begin ... end [id]":
5813 ("function" . "is")
5814 )
5815 nil))
5816 ))) ; "end ..."
5817 )))
5818
5819(defconst vhdl-leader-re
5eabfe72 5820 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
d2ddb974
KH
5821
5822(defun vhdl-end-of-leader ()
5823 (save-excursion
5eabfe72 5824 (cond ((looking-at "block\\|process\\|procedural")
d2ddb974
KH
5825 (if (save-excursion
5826 (forward-sexp)
5827 (skip-chars-forward " \t\n")
5828 (= (following-char) ?\())
5829 (forward-sexp 2)
5830 (forward-sexp))
3dcb36b7
JB
5831 (when (looking-at "[ \t\n]*is")
5832 (goto-char (match-end 0)))
d2ddb974
KH
5833 (point))
5834 ((looking-at "component")
5835 (forward-sexp 2)
3dcb36b7
JB
5836 (when (looking-at "[ \t\n]*is")
5837 (goto-char (match-end 0)))
d2ddb974
KH
5838 (point))
5839 ((looking-at "for")
5840 (forward-sexp 2)
5841 (skip-chars-forward " \t\n")
5842 (while (looking-at "[,:(]")
5843 (forward-sexp)
5844 (skip-chars-forward " \t\n"))
5845 (point))
5846 (t nil)
5847 )))
5848
5849(defconst vhdl-trailer-re
0a2e512a 5850 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
d2ddb974
KH
5851
5852(defconst vhdl-statement-fwd-re
5853 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5854 "A regular expression for searching forward that matches all known
5855\"statement\" keywords.")
5856
5857(defconst vhdl-statement-bwd-re
5858 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5859 "A regular expression for searching backward that matches all known
5860\"statement\" keywords.")
5861
5862(defun vhdl-statement-p (&optional lim)
5863 "Return t if we are looking at a real \"statement\" keyword.
5864Assumes that the caller will make sure that we are looking at
5eabfe72
KH
5865vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5866in the middle of an identifier that just happens to contain a
5867\"statement\" keyword."
d2ddb974
KH
5868 (cond
5869 ;; "for" ... "generate":
5870 ((and (looking-at "f")
5871 ;; Make sure it's the start of a parameter specification.
5872 (save-excursion
5873 (forward-sexp 2)
5874 (skip-chars-forward " \t\n")
5875 (looking-at "in\\b[^_]"))
5876 ;; Make sure it's not an "end for".
5877 (save-excursion
5878 (backward-sexp)
5879 (not (looking-at "end\\s-+\\w"))))
5880 t)
5881 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5882 ((and (looking-at "i")
5883 ;; Make sure it's not an "end if".
5884 (save-excursion
5885 (backward-sexp)
5886 (not (looking-at "end\\s-+\\w"))))
5887 t)
5888 ;; "while" ... "loop":
5889 ((looking-at "w")
5890 t)
5891 ))
5892
5893(defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5894 "Regexp describing a case statement alternative key.")
5895
5896(defun vhdl-case-alternative-p (&optional lim)
5897 "Return t if we are looking at a real case alternative.
5898Assumes that the caller will make sure that we are looking at
5899vhdl-case-alternative-re, and are not inside a literal, and that
5900we are not in the middle of an identifier that just happens to
5901contain a \"when\" keyword."
5902 (save-excursion
5903 (let (foundp)
5904 (while (and (not foundp)
5905 (re-search-backward ";\\|<=" lim 'move))
5906 (if (or (= (preceding-char) ?_)
3dcb36b7 5907 (vhdl-in-literal))
d2ddb974
KH
5908 (backward-char)
5909 (setq foundp t)))
5910 (or (eq (following-char) ?\;)
5911 (eq (point) lim)))
5912 ))
5913
5914;; Core syntactic movement functions:
5915
5916(defconst vhdl-b-t-b-re
5917 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5918
5919(defun vhdl-backward-to-block (&optional lim)
5920 "Move backward to the previous \"begin\" or \"end\" keyword."
5921 (let (foundp)
5922 (while (and (not foundp)
5923 (re-search-backward vhdl-b-t-b-re lim 'move))
5924 (if (or (= (preceding-char) ?_)
3dcb36b7 5925 (vhdl-in-literal))
d2ddb974
KH
5926 (backward-char)
5927 (cond
5928 ;; "begin" keyword:
5929 ((and (looking-at vhdl-begin-fwd-re)
5930 (/= (preceding-char) ?_)
5931 (vhdl-begin-p lim))
5932 (setq foundp 'begin))
5933 ;; "end" keyword:
5934 ((and (looking-at vhdl-end-fwd-re)
5935 (/= (preceding-char) ?_)
5936 (vhdl-end-p lim))
5937 (setq foundp 'end))
5938 ))
5939 )
5940 foundp
5941 ))
5942
5943(defun vhdl-forward-sexp (&optional count lim)
5944 "Move forward across one balanced expression (sexp).
5945With COUNT, do it that many times."
5946 (interactive "p")
5947 (let ((count (or count 1))
5948 (case-fold-search t)
5949 end-vec target)
5950 (save-excursion
5951 (while (> count 0)
5952 ;; skip whitespace
5953 (skip-chars-forward " \t\n")
5954 ;; Check for an unbalanced "end" keyword
5955 (if (and (looking-at vhdl-end-fwd-re)
5956 (/= (preceding-char) ?_)
3dcb36b7 5957 (not (vhdl-in-literal))
d2ddb974
KH
5958 (vhdl-end-p lim)
5959 (not (looking-at "else")))
5960 (error
3dcb36b7 5961 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
d2ddb974
KH
5962 ;; If the current keyword is a "begin" keyword, then find the
5963 ;; corresponding "end" keyword.
5964 (if (setq end-vec (vhdl-corresponding-end lim))
5965 (let (
5966 ;; end-re is the statement keyword to search for
5967 (end-re
5968 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5969 ;; column is either the statement keyword target column
5970 ;; or nil
5971 (column (aref end-vec 1))
5972 (eol (vhdl-point 'eol))
5973 foundp literal placeholder)
5974 ;; Look for the statement keyword.
5975 (while (and (not foundp)
5976 (re-search-forward end-re nil t)
5977 (setq placeholder (match-end 1))
5978 (goto-char (match-beginning 0)))
5979 ;; If we are in a literal, or not in the right target
5980 ;; column and not on the same line as the begin, then
5981 ;; try again.
5982 (if (or (and column
5983 (/= (current-indentation) column)
5984 (> (point) eol))
5985 (= (preceding-char) ?_)
3dcb36b7 5986 (setq literal (vhdl-in-literal)))
d2ddb974
KH
5987 (if (eq literal 'comment)
5988 (end-of-line)
5989 (forward-char))
5990 ;; An "else" keyword corresponds to both the opening brace
5991 ;; of the following sexp and the closing brace of the
5992 ;; previous sexp.
5993 (if (not (looking-at "else"))
5994 (goto-char placeholder))
5995 (setq foundp t))
5996 )
5997 (if (not foundp)
3dcb36b7 5998 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
d2ddb974
KH
5999 )
6000 ;; If the current keyword is not a "begin" keyword, then just
6001 ;; perform the normal forward-sexp.
6002 (forward-sexp)
6003 )
6004 (setq count (1- count))
6005 )
6006 (setq target (point)))
6007 (goto-char target)
6008 nil))
6009
6010(defun vhdl-backward-sexp (&optional count lim)
6011 "Move backward across one balanced expression (sexp).
6012With COUNT, do it that many times. LIM bounds any required backward
6013searches."
6014 (interactive "p")
6015 (let ((count (or count 1))
6016 (case-fold-search t)
6017 begin-vec target)
6018 (save-excursion
6019 (while (> count 0)
6020 ;; Perform the normal backward-sexp, unless we are looking at
6021 ;; "else" - an "else" keyword corresponds to both the opening brace
6022 ;; of the following sexp and the closing brace of the previous sexp.
6023 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6024 (/= (preceding-char) ?_)
3dcb36b7 6025 (not (vhdl-in-literal)))
d2ddb974
KH
6026 nil
6027 (backward-sexp)
6028 (if (and (looking-at vhdl-begin-fwd-re)
6029 (/= (preceding-char) ?_)
3dcb36b7 6030 (not (vhdl-in-literal))
d2ddb974 6031 (vhdl-begin-p lim))
3dcb36b7 6032 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
d2ddb974
KH
6033 ;; If the current keyword is an "end" keyword, then find the
6034 ;; corresponding "begin" keyword.
6035 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6036 (/= (preceding-char) ?_))
6037 (let (
6038 ;; begin-re is the statement keyword to search for
6039 (begin-re
6040 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6041 ;; column is either the statement keyword target column
6042 ;; or nil
6043 (column (aref begin-vec 1))
6044 ;; internal-p controls where the statement keyword can
6045 ;; be found.
6046 (internal-p (aref begin-vec 3))
6047 (last-backward (point)) last-forward
6048 foundp literal keyword)
6049 ;; Look for the statement keyword.
6050 (while (and (not foundp)
6051 (re-search-backward begin-re lim t)
6052 (setq keyword
6053 (buffer-substring (match-beginning 1)
6054 (match-end 1))))
6055 ;; If we are in a literal or in the wrong column,
6056 ;; then try again.
6057 (if (or (and column
6058 (and (/= (current-indentation) column)
6059 ;; possibly accept current-column as
6060 ;; well as current-indentation.
6061 (or (not internal-p)
6062 (/= (current-column) column))))
6063 (= (preceding-char) ?_)
3dcb36b7 6064 (vhdl-in-literal))
d2ddb974
KH
6065 (backward-char)
6066 ;; If there is a supplementary keyword, then
6067 ;; search forward for it.
6068 (if (and (setq begin-re (aref begin-vec 2))
6069 (or (not (listp begin-re))
6070 ;; If begin-re is an alist, then find the
6071 ;; element corresponding to the actual
6072 ;; keyword that we found.
6073 (progn
6074 (setq begin-re
6075 (assoc keyword begin-re))
6076 (and begin-re
6077 (setq begin-re (cdr begin-re))))))
6078 (and
6079 (setq begin-re
6080 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6081 (save-excursion
6082 (setq last-forward (point))
6083 ;; Look for the supplementary keyword
6084 ;; (bounded by the backward search start
6085 ;; point).
6086 (while (and (not foundp)
6087 (re-search-forward begin-re
6088 last-backward t)
6089 (goto-char (match-beginning 1)))
6090 ;; If we are in a literal, then try again.
6091 (if (or (= (preceding-char) ?_)
6092 (setq literal
3dcb36b7 6093 (vhdl-in-literal)))
d2ddb974
KH
6094 (if (eq literal 'comment)
6095 (goto-char
6096 (min (vhdl-point 'eol) last-backward))
6097 (forward-char))
6098 ;; We have found the supplementary keyword.
6099 ;; Save the position of the keyword in foundp.
6100 (setq foundp (point)))
6101 )
6102 foundp)
6103 ;; If the supplementary keyword was found, then
6104 ;; move point to the supplementary keyword.
6105 (goto-char foundp))
6106 ;; If there was no supplementary keyword, then
6107 ;; point is already at the statement keyword.
6108 (setq foundp t)))
6109 ) ; end of the search for the statement keyword
6110 (if (not foundp)
3dcb36b7 6111 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
d2ddb974
KH
6112 ))
6113 (setq count (1- count))
6114 )
6115 (setq target (point)))
6116 (goto-char target)
6117 nil))
6118
6119(defun vhdl-backward-up-list (&optional count limit)
6120 "Move backward out of one level of blocks.
6121With argument, do this that many times."
6122 (interactive "p")
6123 (let ((count (or count 1))
6124 target)
6125 (save-excursion
6126 (while (> count 0)
6127 (if (looking-at vhdl-defun-re)
3dcb36b7 6128 (error "ERROR: Unbalanced blocks"))
d2ddb974
KH
6129 (vhdl-backward-to-block limit)
6130 (setq count (1- count)))
6131 (setq target (point)))
6132 (goto-char target)))
6133
6134(defun vhdl-end-of-defun (&optional count)
6135 "Move forward to the end of a VHDL defun."
6136 (interactive)
6137 (let ((case-fold-search t))
6138 (vhdl-beginning-of-defun)
5eabfe72 6139 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6140 (re-search-forward "\\bis\\b"))
6141 (vhdl-forward-sexp)))
6142
6143(defun vhdl-mark-defun ()
6144 "Put mark at end of this \"defun\", point at beginning."
6145 (interactive)
6146 (let ((case-fold-search t))
6147 (push-mark)
6148 (vhdl-beginning-of-defun)
6149 (push-mark)
5eabfe72 6150 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6151 (re-search-forward "\\bis\\b"))
6152 (vhdl-forward-sexp)
6153 (exchange-point-and-mark)))
6154
6155(defun vhdl-beginning-of-libunit ()
6156 "Move backward to the beginning of a VHDL library unit.
6157Returns the location of the corresponding begin keyword, unless search
5eabfe72
KH
6158stops due to beginning or end of buffer.
6159Note that if point is between the \"libunit\" keyword and the
6160corresponding \"begin\" keyword, then that libunit will not be
a3dd3c0e
JB
6161recognized, and the search will continue backwards. If point is
6162at the \"begin\" keyword, then the defun will be recognized. The
5eabfe72 6163returned point is at the first character of the \"libunit\" keyword."
d2ddb974
KH
6164 (let ((last-forward (point))
6165 (last-backward
6166 ;; Just in case we are actually sitting on the "begin"
6167 ;; keyword, allow for the keyword and an extra character,
6168 ;; as this will be used when looking forward for the
6169 ;; "begin" keyword.
6170 (save-excursion (forward-word 1) (1+ (point))))
6171 foundp literal placeholder)
6172 ;; Find the "libunit" keyword.
6173 (while (and (not foundp)
6174 (re-search-backward vhdl-libunit-re nil 'move))
6175 ;; If we are in a literal, or not at a real libunit, then try again.
6176 (if (or (= (preceding-char) ?_)
3dcb36b7 6177 (vhdl-in-literal)
d2ddb974
KH
6178 (not (vhdl-libunit-p)))
6179 (backward-char)
6180 ;; Find the corresponding "begin" keyword.
6181 (setq last-forward (point))
6182 (while (and (not foundp)
6183 (re-search-forward "\\bis\\b[^_]" last-backward t)
6184 (setq placeholder (match-beginning 0)))
6185 (if (or (= (preceding-char) ?_)
3dcb36b7 6186 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6187 ;; It wasn't a real keyword, so keep searching.
6188 (if (eq literal 'comment)
6189 (goto-char
6190 (min (vhdl-point 'eol) last-backward))
6191 (forward-char))
6192 ;; We have found the begin keyword, loop will exit.
6193 (setq foundp placeholder)))
6194 ;; Go back to the libunit keyword
6195 (goto-char last-forward)))
6196 foundp))
6197
6198(defun vhdl-beginning-of-defun (&optional count)
6199 "Move backward to the beginning of a VHDL defun.
6200With argument, do it that many times.
6201Returns the location of the corresponding begin keyword, unless search
6202stops due to beginning or end of buffer."
6203 ;; Note that if point is between the "defun" keyword and the
6204 ;; corresponding "begin" keyword, then that defun will not be
0a2e512a
RF
6205 ;; recognized, and the search will continue backwards. If point is
6206 ;; at the "begin" keyword, then the defun will be recognized. The
d2ddb974
KH
6207 ;; returned point is at the first character of the "defun" keyword.
6208 (interactive "p")
6209 (let ((count (or count 1))
6210 (case-fold-search t)
6211 (last-forward (point))
6212 foundp)
6213 (while (> count 0)
6214 (setq foundp nil)
6215 (goto-char last-forward)
6216 (let ((last-backward
6217 ;; Just in case we are actually sitting on the "begin"
6218 ;; keyword, allow for the keyword and an extra character,
6219 ;; as this will be used when looking forward for the
6220 ;; "begin" keyword.
6221 (save-excursion (forward-word 1) (1+ (point))))
6222 begin-string literal)
6223 (while (and (not foundp)
6224 (re-search-backward vhdl-defun-re nil 'move))
6225 ;; If we are in a literal, then try again.
6226 (if (or (= (preceding-char) ?_)
3dcb36b7 6227 (vhdl-in-literal))
d2ddb974
KH
6228 (backward-char)
6229 (if (setq begin-string (vhdl-corresponding-defun))
6230 ;; This is a real defun keyword.
6231 ;; Find the corresponding "begin" keyword.
6232 ;; Look for the begin keyword.
6233 (progn
6234 ;; Save the search start point.
6235 (setq last-forward (point))
6236 (while (and (not foundp)
6237 (search-forward begin-string last-backward t))
6238 (if (or (= (preceding-char) ?_)
6239 (save-match-data
3dcb36b7 6240 (setq literal (vhdl-in-literal))))
d2ddb974
KH
6241 ;; It wasn't a real keyword, so keep searching.
6242 (if (eq literal 'comment)
6243 (goto-char
6244 (min (vhdl-point 'eol) last-backward))
6245 (forward-char))
6246 ;; We have found the begin keyword, loop will exit.
6247 (setq foundp (match-beginning 0)))
6248 )
6249 ;; Go back to the defun keyword
6250 (goto-char last-forward)) ; end search for begin keyword
6251 ))
6252 ) ; end of the search for the defun keyword
6253 )
6254 (setq count (1- count))
6255 )
6256 (vhdl-keep-region-active)
6257 foundp))
6258
8d422bd5 6259(defun vhdl-beginning-of-statement (&optional count lim interactive)
d2ddb974
KH
6260 "Go to the beginning of the innermost VHDL statement.
6261With prefix arg, go back N - 1 statements. If already at the
6262beginning of a statement then go to the beginning of the preceding
6263one. If within a string or comment, or next to a comment (only
6264whitespace between), move by sentences instead of statements.
6265
8d422bd5 6266When called from a program, this function takes 3 optional args: the
0a2e512a
RF
6267prefix arg, a buffer position limit which is the farthest back to
6268search, and an argument indicating an interactive call."
8d422bd5 6269 (interactive "p\np")
d2ddb974
KH
6270 (let ((count (or count 1))
6271 (case-fold-search t)
6272 (lim (or lim (point-min)))
6273 (here (point))
6274 state)
6275 (save-excursion
6276 (goto-char lim)
6277 (setq state (parse-partial-sexp (point) here nil nil)))
8d422bd5 6278 (if (and interactive
d2ddb974
KH
6279 (or (nth 3 state)
6280 (nth 4 state)
6281 (looking-at (concat "[ \t]*" comment-start-skip))))
6282 (forward-sentence (- count))
6283 (while (> count 0)
6284 (vhdl-beginning-of-statement-1 lim)
6285 (setq count (1- count))))
6286 ;; its possible we've been left up-buf of lim
6287 (goto-char (max (point) lim))
6288 )
6289 (vhdl-keep-region-active))
6290
6291(defconst vhdl-e-o-s-re
6292 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6293
6294(defun vhdl-end-of-statement ()
6295 "Very simple implementation."
6296 (interactive)
6297 (re-search-forward vhdl-e-o-s-re))
6298
6299(defconst vhdl-b-o-s-re
6300 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6301 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6302
6303(defun vhdl-beginning-of-statement-1 (&optional lim)
5eabfe72
KH
6304 "Move to the start of the current statement, or the previous
6305statement if already at the beginning of one."
d2ddb974
KH
6306 (let ((lim (or lim (point-min)))
6307 (here (point))
6308 (pos (point))
6309 donep)
6310 ;; go backwards one balanced expression, but be careful of
6311 ;; unbalanced paren being reached
6312 (if (not (vhdl-safe (progn (backward-sexp) t)))
6313 (progn
6314 (backward-up-list 1)
6315 (forward-char)
6316 (vhdl-forward-syntactic-ws here)
6317 (setq donep t)))
6318 (while (and (not donep)
6319 (not (bobp))
6320 ;; look backwards for a statement boundary
6321 (re-search-backward vhdl-b-o-s-re lim 'move))
6322 (if (or (= (preceding-char) ?_)
3dcb36b7 6323 (vhdl-in-literal))
d2ddb974
KH
6324 (backward-char)
6325 (cond
6326 ;; If we are looking at an open paren, then stop after it
6327 ((eq (following-char) ?\()
6328 (forward-char)
6329 (vhdl-forward-syntactic-ws here)
6330 (setq donep t))
6331 ;; If we are looking at a close paren, then skip it
6332 ((eq (following-char) ?\))
6333 (forward-char)
6334 (setq pos (point))
6335 (backward-sexp)
6336 (if (< (point) lim)
6337 (progn (goto-char pos)
6338 (vhdl-forward-syntactic-ws here)
6339 (setq donep t))))
6340 ;; If we are looking at a semicolon, then stop
6341 ((eq (following-char) ?\;)
6342 (progn
6343 (forward-char)
6344 (vhdl-forward-syntactic-ws here)
6345 (setq donep t)))
6346 ;; If we are looking at a "begin", then stop
6347 ((and (looking-at vhdl-begin-fwd-re)
6348 (/= (preceding-char) ?_)
6349 (vhdl-begin-p nil))
6350 ;; If it's a leader "begin", then find the
6351 ;; right place
6352 (if (looking-at vhdl-leader-re)
6353 (save-excursion
6354 ;; set a default stop point at the begin
6355 (setq pos (point))
6356 ;; is the start point inside the leader area ?
6357 (goto-char (vhdl-end-of-leader))
6358 (vhdl-forward-syntactic-ws here)
6359 (if (< (point) here)
6360 ;; start point was not inside leader area
6361 ;; set stop point at word after leader
6362 (setq pos (point))))
6363 (forward-word 1)
6364 (vhdl-forward-syntactic-ws here)
6365 (setq pos (point)))
6366 (goto-char pos)
6367 (setq donep t))
6368 ;; If we are looking at a "statement", then stop
6369 ((and (looking-at vhdl-statement-fwd-re)
6370 (/= (preceding-char) ?_)
6371 (vhdl-statement-p nil))
6372 (setq donep t))
6373 ;; If we are looking at a case alternative key, then stop
5eabfe72
KH
6374 ((and (looking-at vhdl-case-alternative-re)
6375 (vhdl-case-alternative-p lim))
d2ddb974
KH
6376 (save-excursion
6377 ;; set a default stop point at the when
6378 (setq pos (point))
6379 ;; is the start point inside the case alternative key ?
6380 (looking-at vhdl-case-alternative-re)
6381 (goto-char (match-end 0))
6382 (vhdl-forward-syntactic-ws here)
6383 (if (< (point) here)
6384 ;; start point was not inside the case alternative key
6385 ;; set stop point at word after case alternative keyleader
6386 (setq pos (point))))
6387 (goto-char pos)
6388 (setq donep t))
6389 ;; Bogus find, continue
6390 (t
6391 (backward-char)))))
6392 ))
6393
6394;; Defuns for calculating the current syntactic state:
6395
6396(defun vhdl-get-library-unit (bod placeholder)
a4c6cfad
JB
6397 "If there is an enclosing library unit at BOD, with its \"begin\"
6398keyword at PLACEHOLDER, then return the library unit type."
d2ddb974
KH
6399 (let ((here (vhdl-point 'bol)))
6400 (if (save-excursion
6401 (goto-char placeholder)
6402 (vhdl-safe (vhdl-forward-sexp 1 bod))
6403 (<= here (point)))
6404 (save-excursion
6405 (goto-char bod)
6406 (cond
6407 ((looking-at "e") 'entity)
6408 ((looking-at "a") 'architecture)
6409 ((looking-at "c") 'configuration)
6410 ((looking-at "p")
6411 (save-excursion
6412 (goto-char bod)
6413 (forward-sexp)
6414 (vhdl-forward-syntactic-ws here)
6415 (if (looking-at "body\\b[^_]")
6416 'package-body 'package))))))
6417 ))
6418
6419(defun vhdl-get-block-state (&optional lim)
5eabfe72 6420 "Finds and records all the closest opens.
a4c6cfad 6421LIM is the furthest back we need to search (it should be the
5eabfe72 6422previous libunit keyword)."
d2ddb974
KH
6423 (let ((here (point))
6424 (lim (or lim (point-min)))
6425 keyword sexp-start sexp-mid sexp-end
6426 preceding-sexp containing-sexp
6427 containing-begin containing-mid containing-paren)
6428 (save-excursion
6429 ;; Find the containing-paren, and use that as the limit
6430 (if (setq containing-paren
6431 (save-restriction
6432 (narrow-to-region lim (point))
6433 (vhdl-safe (scan-lists (point) -1 1))))
6434 (setq lim containing-paren))
6435 ;; Look backwards for "begin" and "end" keywords.
6436 (while (and (> (point) lim)
6437 (not containing-sexp))
6438 (setq keyword (vhdl-backward-to-block lim))
6439 (cond
6440 ((eq keyword 'begin)
6441 ;; Found a "begin" keyword
6442 (setq sexp-start (point))
6443 (setq sexp-mid (vhdl-corresponding-mid lim))
6444 (setq sexp-end (vhdl-safe
6445 (save-excursion
6446 (vhdl-forward-sexp 1 lim) (point))))
6447 (if (and sexp-end (<= sexp-end here))
6448 ;; we want to record this sexp, but we only want to
6449 ;; record the last-most of any of them before here
6450 (or preceding-sexp
6451 (setq preceding-sexp sexp-start))
6452 ;; we're contained in this sexp so put sexp-start on
6453 ;; front of list
6454 (setq containing-sexp sexp-start)
6455 (setq containing-mid sexp-mid)
6456 (setq containing-begin t)))
6457 ((eq keyword 'end)
6458 ;; Found an "end" keyword
6459 (forward-sexp)
6460 (setq sexp-end (point))
6461 (setq sexp-mid nil)
6462 (setq sexp-start
6463 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6464 (progn (backward-sexp) (point))))
6465 ;; we want to record this sexp, but we only want to
6466 ;; record the last-most of any of them before here
6467 (or preceding-sexp
6468 (setq preceding-sexp sexp-start)))
6469 )))
6470 ;; Check if the containing-paren should be the containing-sexp
6471 (if (and containing-paren
6472 (or (null containing-sexp)
6473 (< containing-sexp containing-paren)))
6474 (setq containing-sexp containing-paren
6475 preceding-sexp nil
6476 containing-begin nil
6477 containing-mid nil))
6478 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6479 ))
6480
6481
6482(defconst vhdl-s-c-a-re
6483 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6484
6485(defun vhdl-skip-case-alternative (&optional lim)
5eabfe72 6486 "Skip forward over case/when bodies, with optional maximal
a4c6cfad
JB
6487limit. If no next case alternative is found, nil is returned and
6488point is not moved."
d2ddb974
KH
6489 (let ((lim (or lim (point-max)))
6490 (here (point))
6491 donep foundp)
6492 (while (and (< (point) lim)
6493 (not donep))
6494 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6495 (save-match-data
6496 (not (vhdl-in-literal)))
6497 (/= (match-beginning 0) here))
6498 (progn
6499 (goto-char (match-beginning 0))
6500 (cond
6501 ((and (looking-at "case")
6502 (re-search-forward "\\bis[^_]" lim t))
6503 (backward-sexp)
6504 (vhdl-forward-sexp))
6505 (t
6506 (setq donep t
6507 foundp t))))))
6508 (if (not foundp)
6509 (goto-char here))
6510 foundp))
6511
6512(defun vhdl-backward-skip-label (&optional lim)
5eabfe72 6513 "Skip backward over a label, with optional maximal
a4c6cfad 6514limit. If label is not found, nil is returned and point
5eabfe72 6515is not moved."
d2ddb974
KH
6516 (let ((lim (or lim (point-min)))
6517 placeholder)
6518 (if (save-excursion
6519 (vhdl-backward-syntactic-ws lim)
6520 (and (eq (preceding-char) ?:)
6521 (progn
6522 (backward-sexp)
6523 (setq placeholder (point))
6524 (looking-at vhdl-label-key))))
6525 (goto-char placeholder))
6526 ))
6527
6528(defun vhdl-forward-skip-label (&optional lim)
5eabfe72
KH
6529 "Skip forward over a label, with optional maximal
6530limit. If label is not found, nil is returned and point
6531is not moved."
d2ddb974
KH
6532 (let ((lim (or lim (point-max))))
6533 (if (looking-at vhdl-label-key)
6534 (progn
6535 (goto-char (match-end 0))
6536 (vhdl-forward-syntactic-ws lim)))
6537 ))
6538
6539(defun vhdl-get-syntactic-context ()
5eabfe72 6540 "Guess the syntactic description of the current line of VHDL code."
d2ddb974
KH
6541 (save-excursion
6542 (save-restriction
6543 (beginning-of-line)
6544 (let* ((indent-point (point))
6545 (case-fold-search t)
6546 vec literal containing-sexp preceding-sexp
6547 containing-begin containing-mid containing-leader
6548 char-before-ip char-after-ip begin-after-ip end-after-ip
6549 placeholder lim library-unit
6550 )
6551
6552 ;; Reset the syntactic context
6553 (setq vhdl-syntactic-context nil)
6554
6555 (save-excursion
6556 ;; Move to the start of the previous library unit, and
6557 ;; record the position of the "begin" keyword.
6558 (setq placeholder (vhdl-beginning-of-libunit))
6559 ;; The position of the "libunit" keyword gives us a gross
6560 ;; limit point.
6561 (setq lim (point))
6562 )
6563
6564 ;; If there is a previous library unit, and we are enclosed by
6565 ;; it, then set the syntax accordingly.
6566 (and placeholder
6567 (setq library-unit (vhdl-get-library-unit lim placeholder))
6568 (vhdl-add-syntax library-unit lim))
6569
6570 ;; Find the surrounding state.
6571 (if (setq vec (vhdl-get-block-state lim))
6572 (progn
6573 (setq containing-sexp (aref vec 0))
6574 (setq preceding-sexp (aref vec 1))
6575 (setq containing-begin (aref vec 2))
6576 (setq containing-mid (aref vec 3))
6577 ))
6578
6579 ;; set the limit on the farthest back we need to search
6580 (setq lim (if containing-sexp
6581 (save-excursion
6582 (goto-char containing-sexp)
6583 ;; set containing-leader if required
6584 (if (looking-at vhdl-leader-re)
6585 (setq containing-leader (vhdl-end-of-leader)))
6586 (vhdl-point 'bol))
6587 (point-min)))
6588
6589 ;; cache char before and after indent point, and move point to
6590 ;; the most likely position to perform the majority of tests
6591 (goto-char indent-point)
6592 (skip-chars-forward " \t")
3dcb36b7 6593 (setq literal (vhdl-in-literal))
d2ddb974
KH
6594 (setq char-after-ip (following-char))
6595 (setq begin-after-ip (and
6596 (not literal)
6597 (looking-at vhdl-begin-fwd-re)
6598 (vhdl-begin-p)))
6599 (setq end-after-ip (and
6600 (not literal)
6601 (looking-at vhdl-end-fwd-re)
6602 (vhdl-end-p)))
6603 (vhdl-backward-syntactic-ws lim)
6604 (setq char-before-ip (preceding-char))
6605 (goto-char indent-point)
6606 (skip-chars-forward " \t")
6607
6608 ;; now figure out syntactic qualities of the current line
6609 (cond
6610 ;; CASE 1: in a string or comment.
6611 ((memq literal '(string comment))
6612 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6613 ;; CASE 2: Line is at top level.
6614 ((null containing-sexp)
6615 ;; Find the point to which indentation will be relative
6616 (save-excursion
6617 (if (null preceding-sexp)
6618 ;; CASE 2X.1
6619 ;; no preceding-sexp -> use the preceding statement
6620 (vhdl-beginning-of-statement-1 lim)
6621 ;; CASE 2X.2
6622 ;; if there is a preceding-sexp then indent relative to it
6623 (goto-char preceding-sexp)
6624 ;; if not at boi, then the block-opening keyword is
6625 ;; probably following a label, so we need a different
6626 ;; relpos
6627 (if (/= (point) (vhdl-point 'boi))
6628 ;; CASE 2X.3
6629 (vhdl-beginning-of-statement-1 lim)))
6630 ;; v-b-o-s could have left us at point-min
6631 (and (bobp)
6632 ;; CASE 2X.4
6633 (vhdl-forward-syntactic-ws indent-point))
6634 (setq placeholder (point)))
6635 (cond
6636 ;; CASE 2A : we are looking at a block-open
6637 (begin-after-ip
6638 (vhdl-add-syntax 'block-open placeholder))
6639 ;; CASE 2B: we are looking at a block-close
6640 (end-after-ip
6641 (vhdl-add-syntax 'block-close placeholder))
6642 ;; CASE 2C: we are looking at a top-level statement
6643 ((progn
6644 (vhdl-backward-syntactic-ws lim)
6645 (or (bobp)
6646 (= (preceding-char) ?\;)))
6647 (vhdl-add-syntax 'statement placeholder))
6648 ;; CASE 2D: we are looking at a top-level statement-cont
6649 (t
6650 (vhdl-beginning-of-statement-1 lim)
6651 ;; v-b-o-s could have left us at point-min
6652 (and (bobp)
6653 ;; CASE 2D.1
6654 (vhdl-forward-syntactic-ws indent-point))
6655 (vhdl-add-syntax 'statement-cont (point)))
6656 )) ; end CASE 2
6657 ;; CASE 3: line is inside parentheses. Most likely we are
6658 ;; either in a subprogram argument (interface) list, or a
6659 ;; continued expression containing parentheses.
6660 ((null containing-begin)
6661 (vhdl-backward-syntactic-ws containing-sexp)
6662 (cond
6663 ;; CASE 3A: we are looking at the arglist closing paren
6664 ((eq char-after-ip ?\))
6665 (goto-char containing-sexp)
6666 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6667 ;; CASE 3B: we are looking at the first argument in an empty
6668 ;; argument list.
6669 ((eq char-before-ip ?\()
6670 (goto-char containing-sexp)
6671 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6672 ;; CASE 3C: we are looking at an arglist continuation line,
6673 ;; but the preceding argument is on the same line as the
6674 ;; opening paren. This case includes multi-line
6675 ;; expression paren groupings.
6676 ((and (save-excursion
6677 (goto-char (1+ containing-sexp))
6678 (skip-chars-forward " \t")
6679 (not (eolp))
6680 (not (looking-at "--")))
6681 (save-excursion
6682 (vhdl-beginning-of-statement-1 containing-sexp)
6683 (skip-chars-backward " \t(")
6684 (<= (point) containing-sexp)))
6685 (goto-char containing-sexp)
6686 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6687 ;; CASE 3D: we are looking at just a normal arglist
6688 ;; continuation line
6689 (t (vhdl-beginning-of-statement-1 containing-sexp)
6690 (vhdl-forward-syntactic-ws indent-point)
6691 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6692 ))
6693 ;; CASE 4: A block mid open
6694 ((and begin-after-ip
6695 (looking-at containing-mid))
6696 (goto-char containing-sexp)
6697 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6698 (if (looking-at vhdl-trailer-re)
6699 ;; CASE 4.1
6700 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6701 (vhdl-backward-skip-label (vhdl-point 'boi))
6702 (vhdl-add-syntax 'block-open (point)))
6703 ;; CASE 5: block close brace
6704 (end-after-ip
6705 (goto-char containing-sexp)
6706 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6707 (if (looking-at vhdl-trailer-re)
6708 ;; CASE 5.1
6709 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6710 (vhdl-backward-skip-label (vhdl-point 'boi))
6711 (vhdl-add-syntax 'block-close (point)))
6712 ;; CASE 6: A continued statement
6713 ((and (/= char-before-ip ?\;)
6714 ;; check it's not a trailer begin keyword, or a begin
6715 ;; keyword immediately following a label.
6716 (not (and begin-after-ip
6717 (or (looking-at vhdl-trailer-re)
6718 (save-excursion
6719 (vhdl-backward-skip-label containing-sexp)))))
6720 ;; check it's not a statement keyword
6721 (not (and (looking-at vhdl-statement-fwd-re)
6722 (vhdl-statement-p)))
6723 ;; see if the b-o-s is before the indent point
6724 (> indent-point
6725 (save-excursion
6726 (vhdl-beginning-of-statement-1 containing-sexp)
6727 ;; If we ended up after a leader, then this will
6728 ;; move us forward to the start of the first
6729 ;; statement. Note that a containing sexp here is
6730 ;; always a keyword, not a paren, so this will
6731 ;; have no effect if we hit the containing-sexp.
6732 (vhdl-forward-syntactic-ws indent-point)
6733 (setq placeholder (point))))
6734 ;; check it's not a block-intro
6735 (/= placeholder containing-sexp)
6736 ;; check it's not a case block-intro
6737 (save-excursion
6738 (goto-char placeholder)
6739 (or (not (looking-at vhdl-case-alternative-re))
6740 (> (match-end 0) indent-point))))
6741 ;; Make placeholder skip a label, but only if it puts us
6742 ;; before the indent point at the start of a line.
6743 (let ((new placeholder))
6744 (if (and (> indent-point
6745 (save-excursion
6746 (goto-char placeholder)
6747 (vhdl-forward-skip-label indent-point)
6748 (setq new (point))))
6749 (save-excursion
6750 (goto-char new)
6751 (eq new (progn (back-to-indentation) (point)))))
6752 (setq placeholder new)))
6753 (vhdl-add-syntax 'statement-cont placeholder)
6754 (if begin-after-ip
6755 (vhdl-add-syntax 'block-open)))
6756 ;; Statement. But what kind?
6757 ;; CASE 7: A case alternative key
6758 ((and (looking-at vhdl-case-alternative-re)
6759 (vhdl-case-alternative-p containing-sexp))
6760 ;; for a case alternative key, we set relpos to the first
6761 ;; non-whitespace char on the line containing the "case"
6762 ;; keyword.
6763 (goto-char containing-sexp)
6764 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6765 (if (looking-at vhdl-trailer-re)
6766 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6767 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6768 ;; CASE 8: statement catchall
6769 (t
6770 ;; we know its a statement, but we need to find out if it is
6771 ;; the first statement in a block
6772 (if containing-leader
6773 (goto-char containing-leader)
6774 (goto-char containing-sexp)
6775 ;; Note that a containing sexp here is always a keyword,
6776 ;; not a paren, so skip over the keyword.
6777 (forward-sexp))
6778 ;; move to the start of the first statement
6779 (vhdl-forward-syntactic-ws indent-point)
6780 (setq placeholder (point))
6781 ;; we want to ignore case alternatives keys when skipping forward
6782 (let (incase-p)
6783 (while (looking-at vhdl-case-alternative-re)
6784 (setq incase-p (point))
6785 ;; we also want to skip over the body of the
6786 ;; case/when statement if that doesn't put us at
6787 ;; after the indent-point
6788 (while (vhdl-skip-case-alternative indent-point))
6789 ;; set up the match end
6790 (looking-at vhdl-case-alternative-re)
6791 (goto-char (match-end 0))
6792 ;; move to the start of the first case alternative statement
6793 (vhdl-forward-syntactic-ws indent-point)
6794 (setq placeholder (point)))
6795 (cond
6796 ;; CASE 8A: we saw a case/when statement so we must be
6797 ;; in a switch statement. find out if we are at the
6798 ;; statement just after a case alternative key
6799 ((and incase-p
6800 (= (point) indent-point))
6801 ;; relpos is the "when" keyword
6802 (vhdl-add-syntax 'statement-case-intro incase-p))
6803 ;; CASE 8B: any old statement
6804 ((< (point) indent-point)
6805 ;; relpos is the first statement of the block
6806 (vhdl-add-syntax 'statement placeholder)
6807 (if begin-after-ip
6808 (vhdl-add-syntax 'block-open)))
6809 ;; CASE 8C: first statement in a block
6810 (t
6811 (goto-char containing-sexp)
6812 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6813 (if (looking-at vhdl-trailer-re)
6814 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6815 (vhdl-backward-skip-label (vhdl-point 'boi))
6816 (vhdl-add-syntax 'statement-block-intro (point))
6817 (if begin-after-ip
6818 (vhdl-add-syntax 'block-open)))
6819 )))
6820 )
6821
6822 ;; now we need to look at any modifiers
6823 (goto-char indent-point)
6824 (skip-chars-forward " \t")
6825 (if (looking-at "--")
6826 (vhdl-add-syntax 'comment))
0a2e512a
RF
6827 (if (eq literal 'pound)
6828 (vhdl-add-syntax 'cpp-macro))
d2ddb974
KH
6829 ;; return the syntax
6830 vhdl-syntactic-context))))
6831
6832;; Standard indentation line-ups:
6833
6834(defun vhdl-lineup-arglist (langelem)
5eabfe72
KH
6835 "Lineup the current arglist line with the arglist appearing just
6836after the containing paren which starts the arglist."
d2ddb974
KH
6837 (save-excursion
6838 (let* ((containing-sexp
6839 (save-excursion
6840 ;; arglist-cont-nonempty gives relpos ==
6841 ;; to boi of containing-sexp paren. This
6842 ;; is good when offset is +, but bad
6843 ;; when it is vhdl-lineup-arglist, so we
6844 ;; have to special case a kludge here.
6845 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6846 (progn
6847 (beginning-of-line)
6848 (backward-up-list 1)
6849 (skip-chars-forward " \t" (vhdl-point 'eol)))
6850 (goto-char (cdr langelem)))
6851 (point)))
6852 (cs-curcol (save-excursion
6853 (goto-char (cdr langelem))
6854 (current-column))))
6855 (if (save-excursion
6856 (beginning-of-line)
6857 (looking-at "[ \t]*)"))
6858 (progn (goto-char (match-end 0))
6859 (backward-sexp)
6860 (forward-char)
6861 (vhdl-forward-syntactic-ws)
6862 (- (current-column) cs-curcol))
6863 (goto-char containing-sexp)
6864 (or (eolp)
6865 (let ((eol (vhdl-point 'eol))
6866 (here (progn
6867 (forward-char)
6868 (skip-chars-forward " \t")
6869 (point))))
6870 (vhdl-forward-syntactic-ws)
6871 (if (< (point) eol)
6872 (goto-char here))))
6873 (- (current-column) cs-curcol)
6874 ))))
6875
6876(defun vhdl-lineup-arglist-intro (langelem)
5eabfe72 6877 "Lineup an arglist-intro line to just after the open paren."
d2ddb974
KH
6878 (save-excursion
6879 (let ((cs-curcol (save-excursion
6880 (goto-char (cdr langelem))
6881 (current-column)))
6882 (ce-curcol (save-excursion
6883 (beginning-of-line)
6884 (backward-up-list 1)
6885 (skip-chars-forward " \t" (vhdl-point 'eol))
6886 (current-column))))
6887 (- ce-curcol cs-curcol -1))))
6888
6889(defun vhdl-lineup-comment (langelem)
5eabfe72
KH
6890 "Support old behavior for comment indentation. We look at
6891vhdl-comment-only-line-offset to decide how to indent comment
6892only-lines."
d2ddb974
KH
6893 (save-excursion
6894 (back-to-indentation)
6895 ;; at or to the right of comment-column
6896 (if (>= (current-column) comment-column)
6897 (vhdl-comment-indent)
6898 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6899 (if (not (bolp))
6900 (or (car-safe vhdl-comment-only-line-offset)
6901 vhdl-comment-only-line-offset)
6902 (or (cdr-safe vhdl-comment-only-line-offset)
6903 (car-safe vhdl-comment-only-line-offset)
0a2e512a 6904 -1000 ;jam it against the left side
d2ddb974
KH
6905 )))))
6906
6907(defun vhdl-lineup-statement-cont (langelem)
5eabfe72 6908 "Line up statement-cont after the assignment operator."
d2ddb974
KH
6909 (save-excursion
6910 (let* ((relpos (cdr langelem))
6911 (assignp (save-excursion
6912 (goto-char (vhdl-point 'boi))
6913 (and (re-search-forward "\\(<\\|:\\)="
6914 (vhdl-point 'eol) t)
6915 (- (point) (vhdl-point 'boi)))))
6916 (curcol (progn
6917 (goto-char relpos)
6918 (current-column)))
6919 foundp)
6920 (while (and (not foundp)
6921 (< (point) (vhdl-point 'eol)))
6922 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
3dcb36b7 6923 (if (vhdl-in-literal)
d2ddb974
KH
6924 (forward-char)
6925 (if (= (preceding-char) ?\()
6926 ;; skip over any parenthesized expressions
6927 (goto-char (min (vhdl-point 'eol)
6928 (scan-lists (point) 1 1)))
6929 ;; found an assignment operator (not at eol)
6930 (setq foundp (not (looking-at "\\s-*$"))))))
6931 (if (not foundp)
6932 ;; there's no assignment operator on the line
6933 vhdl-basic-offset
6934 ;; calculate indentation column after assign and ws, unless
6935 ;; our line contains an assignment operator
6936 (if (not assignp)
6937 (progn
6938 (forward-char)
6939 (skip-chars-forward " \t")
6940 (setq assignp 0)))
6941 (- (current-column) assignp curcol))
6942 )))
6943
5eabfe72 6944;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 6945;; Progress reporting
d2ddb974 6946
3dcb36b7
JB
6947(defvar vhdl-progress-info nil
6948 "Array variable for progress information: 0 begin, 1 end, 2 time.")
5eabfe72 6949
3dcb36b7
JB
6950(defun vhdl-update-progress-info (string pos)
6951 "Update progress information."
6952 (when (and vhdl-progress-info (not noninteractive)
6953 (< vhdl-progress-interval
6954 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
b0cf7916
JB
6955 (let ((delta (- (aref vhdl-progress-info 1)
6956 (aref vhdl-progress-info 0))))
6957 (if (= 0 delta)
6958 (message (concat string "... (100%s)") "%")
6959 (message (concat string "... (%2d%s)")
6960 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6961 delta) "%")))
3dcb36b7 6962 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
5eabfe72 6963
3dcb36b7
JB
6964;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6965;; Indentation commands
5eabfe72
KH
6966
6967(defun vhdl-electric-tab (&optional prefix-arg)
6968 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7
JB
6969else if right of non whitespace on line then insert tab,
6970else if last command was a tab or return then dedent one step or if a comment
6971toggle between normal indent and inline comment indent,
d2ddb974
KH
6972else indent `correctly'."
6973 (interactive "*P")
3dcb36b7
JB
6974 (vhdl-prepare-search-2
6975 (cond
75e0af77
DN
6976 ;; indent region if region is active
6977 ((and (not (featurep 'xemacs)) (use-region-p))
6978 (vhdl-indent-region (region-beginning) (region-end) nil))
3dcb36b7
JB
6979 ;; expand word
6980 ((= (char-syntax (preceding-char)) ?w)
6981 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6982 (case-replace nil)
6983 (hippie-expand-only-buffers
6984 (or (and (boundp 'hippie-expand-only-buffers)
6985 hippie-expand-only-buffers)
6986 '(vhdl-mode))))
6987 (vhdl-expand-abbrev prefix-arg)))
6988 ;; expand parenthesis
6989 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6990 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6991 (case-replace nil))
6992 (vhdl-expand-paren prefix-arg)))
6993 ;; insert tab
6994 ((> (current-column) (current-indentation))
6995 (insert-tab))
6996 ;; toggle comment indent
6997 ((and (looking-at "--")
6998 (or (eq last-command 'vhdl-electric-tab)
6999 (eq last-command 'vhdl-electric-return)))
7000 (cond ((= (current-indentation) 0) ; no indent
7001 (indent-to 1)
7002 (indent-according-to-mode))
7003 ((< (current-indentation) comment-column) ; normal indent
7004 (indent-to comment-column)
7005 (indent-according-to-mode))
7006 (t ; inline comment indent
453cfeb3 7007 (delete-region (line-beginning-position) (point)))))
3dcb36b7
JB
7008 ;; dedent
7009 ((and (>= (current-indentation) vhdl-basic-offset)
7010 (or (eq last-command 'vhdl-electric-tab)
7011 (eq last-command 'vhdl-electric-return)))
7012 (backward-delete-char-untabify vhdl-basic-offset nil))
7013 ;; indent line
7014 (t (indent-according-to-mode)))
5eabfe72
KH
7015 (setq this-command 'vhdl-electric-tab)))
7016
7017(defun vhdl-electric-return ()
d2ddb974
KH
7018 "newline-and-indent or indent-new-comment-line if in comment and preceding
7019character is a space."
7020 (interactive)
7021 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7022 (indent-new-comment-line)
3dcb36b7
JB
7023 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7024 (vhdl-fix-case-word -1))
5eabfe72
KH
7025 (newline-and-indent)))
7026
d2ddb974 7027(defun vhdl-indent-line ()
5eabfe72 7028 "Indent the current line as VHDL code. Returns the amount of
d2ddb974
KH
7029indentation change."
7030 (interactive)
3dcb36b7 7031 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
d2ddb974 7032 (pos (- (point-max) (point)))
3dcb36b7
JB
7033 (indent
7034 (if syntax
7035 ;; indent syntax-based
7036 (if (and (eq (caar syntax) 'comment)
7037 (>= (vhdl-get-offset (car syntax)) comment-column))
7038 ;; special case: comments at or right of comment-column
7039 (vhdl-get-offset (car syntax))
7040 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7041 ;; indent like previous nonblank line
7042 (save-excursion (beginning-of-line)
7043 (re-search-backward "^[^\n]" nil t)
7044 (current-indentation))))
5eabfe72 7045 (shift-amt (- indent (current-indentation))))
d2ddb974
KH
7046 (and vhdl-echo-syntactic-information-p
7047 (message "syntax: %s, indent= %d" syntax indent))
5eabfe72 7048 (unless (zerop shift-amt)
d2ddb974
KH
7049 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7050 (beginning-of-line)
7051 (indent-to indent))
7052 (if (< (point) (vhdl-point 'boi))
7053 (back-to-indentation)
7054 ;; If initial point was within line's indentation, position after
7055 ;; the indentation. Else stay at same point in text.
5eabfe72
KH
7056 (when (> (- (point-max) pos) (point))
7057 (goto-char (- (point-max) pos))))
d2ddb974 7058 (run-hooks 'vhdl-special-indent-hook)
3dcb36b7 7059 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
d2ddb974
KH
7060 shift-amt))
7061
3dcb36b7 7062(defun vhdl-indent-region (beg end column)
5eabfe72
KH
7063 "Indent region as VHDL code.
7064Adds progress reporting to `indent-region'."
7065 (interactive "r\nP")
3dcb36b7
JB
7066 (when vhdl-progress-interval
7067 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7068 (count-lines (point-min) end) 0)))
7069 (indent-region beg end column)
5eabfe72
KH
7070 (when vhdl-progress-interval (message "Indenting...done"))
7071 (setq vhdl-progress-info nil))
d2ddb974 7072
3dcb36b7
JB
7073(defun vhdl-indent-buffer ()
7074 "Indent whole buffer as VHDL code.
7075Calls `indent-region' for whole buffer and adds progress reporting."
7076 (interactive)
7077 (vhdl-indent-region (point-min) (point-max) nil))
7078
7079(defun vhdl-indent-group ()
7080 "Indent group of lines between empty lines."
7081 (interactive)
7082 (let ((beg (save-excursion
7083 (if (re-search-backward vhdl-align-group-separate nil t)
7084 (point-marker)
7085 (point-min-marker))))
7086 (end (save-excursion
7087 (if (re-search-forward vhdl-align-group-separate nil t)
7088 (point-marker)
7089 (point-max-marker)))))
7090 (vhdl-indent-region beg end nil)))
7091
d2ddb974
KH
7092(defun vhdl-indent-sexp (&optional endpos)
7093 "Indent each line of the list starting just after point.
7094If optional arg ENDPOS is given, indent each line, stopping when
7095ENDPOS is encountered."
7096 (interactive)
7097 (save-excursion
7098 (let ((beg (point))
5eabfe72 7099 (end (progn (vhdl-forward-sexp nil endpos) (point))))
d2ddb974
KH
7100 (indent-region beg end nil))))
7101
5eabfe72 7102;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
7103;; Miscellaneous commands
7104
7105(defun vhdl-show-syntactic-information ()
7106 "Show syntactic information for current line."
7107 (interactive)
3dcb36b7 7108 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
d2ddb974
KH
7109 (vhdl-keep-region-active))
7110
7111;; Verification and regression functions:
7112
7113(defun vhdl-regress-line (&optional arg)
7114 "Check syntactic information for current line."
7115 (interactive "P")
7116 (let ((expected (save-excursion
7117 (end-of-line)
5eabfe72
KH
7118 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7119 (forward-char 4)
7120 (read (current-buffer)))))
d2ddb974
KH
7121 (actual (vhdl-get-syntactic-context))
7122 (expurgated))
7123 ;; remove the library unit symbols
51b5ad57 7124 (mapc
d2ddb974
KH
7125 (function
7126 (lambda (elt)
7127 (if (memq (car elt) '(entity configuration package
7128 package-body architecture))
7129 nil
7130 (setq expurgated (append expurgated (list elt))))))
7131 actual)
7132 (if (and (not arg) expected (listp expected))
7133 (if (not (equal expected expurgated))
3dcb36b7 7134 (error "ERROR: Should be: %s, is: %s" expected expurgated))
d2ddb974
KH
7135 (save-excursion
7136 (beginning-of-line)
5eabfe72
KH
7137 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7138 (end-of-line)
7139 (if (search-backward " -- ((" (vhdl-point 'bol) t)
453cfeb3 7140 (delete-region (point) (line-end-position)))
5eabfe72
KH
7141 (insert " -- ")
7142 (insert (format "%s" expurgated))))))
d2ddb974
KH
7143 (vhdl-keep-region-active))
7144
7145
5eabfe72
KH
7146;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7147;;; Alignment, whitespace fixup, beautifying
7148;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7149
3dcb36b7 7150(defconst vhdl-align-alist
d2ddb974
KH
7151 '(
7152 ;; after some keywords
3dcb36b7
JB
7153 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7154 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
d2ddb974 7155 ;; before ':'
5eabfe72 7156 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
d2ddb974 7157 ;; after direction specifications
5eabfe72
KH
7158 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7159 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7160 ;; before "==", ":=", "=>", and "<="
3dcb36b7 7161 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
5eabfe72 7162 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
3dcb36b7 7163 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
d2ddb974
KH
7164 ;; before some keywords
7165 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
d2ddb974
KH
7166 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7167 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
3dcb36b7
JB
7168 ;; before "=>" since "when/else ... =>" can occur
7169 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
d2ddb974 7170 )
5eabfe72 7171 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
d2ddb974
KH
7172It is searched in order. If REGEXP is found anywhere in the first
7173line of a region to be aligned, ALIGN-PATTERN will be used for that
7174region. ALIGN-PATTERN must include the whitespace to be expanded or
5eabfe72
KH
7175contracted. It may also provide regexps for the text surrounding the
7176whitespace. SUBEXP specifies which sub-expression of
d2ddb974
KH
7177ALIGN-PATTERN matches the white space to be expanded/contracted.")
7178
3dcb36b7
JB
7179;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7180;; Align code
7181
d2ddb974
KH
7182(defvar vhdl-align-try-all-clauses t
7183 "If REGEXP is not found on the first line of the region that clause
5eabfe72 7184is ignored. If this variable is non-nil, then the clause is tried anyway.")
d2ddb974 7185
3dcb36b7
JB
7186(defun vhdl-do-group (function &optional spacing)
7187 "Apply FUNCTION on group of lines between empty lines."
7188 (let
7189 ;; search for group beginning
7190 ((beg (save-excursion
7191 (if (re-search-backward vhdl-align-group-separate nil t)
7192 (progn (beginning-of-line 2) (back-to-indentation) (point))
7193 (point-min))))
7194 ;; search for group end
7195 (end (save-excursion
7196 (if (re-search-forward vhdl-align-group-separate nil t)
7197 (progn (beginning-of-line) (point))
7198 (point-max)))))
7199 ;; run FUNCTION
7200 (funcall function beg end spacing)))
7201
7202(defun vhdl-do-list (function &optional spacing)
7203 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7204parentheses."
7205 (let (beg end)
7206 (save-excursion
7207 ;; search for beginning of balanced group of parentheses
7208 (setq beg (vhdl-re-search-backward "[()]" nil t))
7209 (while (looking-at ")")
7210 (forward-char) (backward-sexp)
7211 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7212 ;; search for end of balanced group of parentheses
7213 (when beg
7214 (forward-list)
7215 (setq end (point))
7216 (goto-char (1+ beg))
7217 (skip-chars-forward " \t\n")
7218 (setq beg (point))))
7219 ;; run FUNCTION
7220 (if beg
7221 (funcall function beg end spacing)
7222 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7223
7224(defun vhdl-do-same-indent (function &optional spacing)
7225 "Apply FUNCTION to block of lines with same indent."
7226 (let ((indent (current-indentation))
7227 beg end)
7228 ;; search for first line with same indent
7229 (save-excursion
7230 (while (and (not (bobp))
7231 (or (looking-at "^\\s-*\\(--.*\\)?$")
7232 (= (current-indentation) indent)))
7233 (unless (looking-at "^\\s-*$")
7234 (back-to-indentation) (setq beg (point)))
7235 (beginning-of-line -0)))
7236 ;; search for last line with same indent
7237 (save-excursion
7238 (while (and (not (eobp))
7239 (or (looking-at "^\\s-*\\(--.*\\)?$")
7240 (= (current-indentation) indent)))
7241 (if (looking-at "^\\s-*$")
7242 (beginning-of-line 2)
7243 (beginning-of-line 2)
7244 (setq end (point)))))
7245 ;; run FUNCTION
7246 (funcall function beg end spacing)))
7247
7248(defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
d2ddb974 7249 "Attempt to align a range of lines based on the content of the
5eabfe72
KH
7250lines. The definition of `alignment-list' determines the matching
7251order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7252is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
d2ddb974
KH
7253indentation is done before aligning."
7254 (interactive "r\np")
5eabfe72
KH
7255 (setq alignment-list (or alignment-list vhdl-align-alist))
7256 (setq spacing (or spacing 1))
d2ddb974
KH
7257 (save-excursion
7258 (let (bol indent)
7259 (goto-char end)
7260 (setq end (point-marker))
7261 (goto-char begin)
5eabfe72 7262 (setq bol (setq begin (progn (beginning-of-line) (point))))
3dcb36b7 7263; (untabify bol end)
5eabfe72
KH
7264 (when indent
7265 (indent-region bol end nil))))
3dcb36b7
JB
7266 (let ((copy (copy-alist alignment-list)))
7267 (vhdl-prepare-search-2
5eabfe72
KH
7268 (while copy
7269 (save-excursion
7270 (goto-char begin)
7271 (let (element
e180ab9f 7272 (eol (point-at-eol)))
5eabfe72
KH
7273 (setq element (nth 0 copy))
7274 (when (and (or (and (listp (car element))
7275 (memq major-mode (car element)))
7276 (eq major-mode (car element)))
7277 (or vhdl-align-try-all-clauses
7278 (re-search-forward (car (cdr element)) eol t)))
3dcb36b7 7279 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
5eabfe72
KH
7280 (car (cdr (cdr (cdr element)))) spacing))
7281 (setq copy (cdr copy))))))))
7282
3dcb36b7 7283(defun vhdl-align-region-2 (begin end match &optional substr spacing)
d2ddb974 7284 "Align a range of lines from BEGIN to END. The regular expression
a4c6cfad 7285MATCH must match exactly one field: the whitespace to be
d2ddb974 7286contracted/expanded. The alignment column will equal the
a4c6cfad 7287rightmost column of the widest whitespace block. SPACING is
d2ddb974
KH
7288the amount of extra spaces to add to the calculated maximum required.
7289SPACING defaults to 1 so that at least one space is inserted after
7290the token in MATCH."
5eabfe72
KH
7291 (setq spacing (or spacing 1))
7292 (setq substr (or substr 1))
d2ddb974
KH
7293 (save-excursion
7294 (let (distance (max 0) (lines 0) bol eol width)
7295 ;; Determine the greatest whitespace distance to the alignment
7296 ;; character
7297 (goto-char begin)
e180ab9f 7298 (setq eol (point-at-eol)
5eabfe72 7299 bol (setq begin (progn (beginning-of-line) (point))))
d2ddb974 7300 (while (< bol end)
5eabfe72
KH
7301 (save-excursion
7302 (when (and (re-search-forward match eol t)
3dcb36b7 7303 (not (vhdl-in-literal)))
5eabfe72
KH
7304 (setq distance (- (match-beginning substr) bol))
7305 (when (> distance max)
7306 (setq max distance))))
7307 (forward-line)
7308 (setq bol (point)
e180ab9f 7309 eol (point-at-eol))
5eabfe72 7310 (setq lines (1+ lines)))
d2ddb974
KH
7311 ;; Now insert enough maxs to push each assignment operator to
7312 ;; the same column. We need to use 'lines' as a counter, since
7313 ;; the location of the mark may change
7314 (goto-char (setq bol begin))
e180ab9f 7315 (setq eol (point-at-eol))
d2ddb974 7316 (while (> lines 0)
5eabfe72 7317 (when (and (re-search-forward match eol t)
3dcb36b7 7318 (not (vhdl-in-literal)))
5eabfe72
KH
7319 (setq width (- (match-end substr) (match-beginning substr)))
7320 (setq distance (- (match-beginning substr) bol))
7321 (goto-char (match-beginning substr))
7322 (delete-char width)
7323 (insert-char ? (+ (- max distance) spacing)))
7324 (beginning-of-line)
7325 (forward-line)
7326 (setq bol (point)
e180ab9f 7327 eol (point-at-eol))
5eabfe72
KH
7328 (setq lines (1- lines))))))
7329
3dcb36b7
JB
7330(defun vhdl-align-region-groups (beg end &optional spacing
7331 no-message no-comments)
7332 "Align region, treat groups of lines separately."
d2ddb974 7333 (interactive "r\nP")
5eabfe72 7334 (save-excursion
3dcb36b7 7335 (let (orig pos)
5eabfe72
KH
7336 (goto-char beg)
7337 (beginning-of-line)
3dcb36b7 7338 (setq orig (point-marker))
5eabfe72
KH
7339 (setq beg (point))
7340 (goto-char end)
7341 (setq end (point-marker))
7342 (untabify beg end)
3dcb36b7
JB
7343 (unless no-message
7344 (when vhdl-progress-interval
7345 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7346 (count-lines (point-min) end) 0))))
5eabfe72
KH
7347 (vhdl-fixup-whitespace-region beg end t)
7348 (goto-char beg)
7349 (if (not vhdl-align-groups)
7350 ;; align entire region
3dcb36b7
JB
7351 (progn (vhdl-align-region-1 beg end spacing)
7352 (unless no-comments
7353 (vhdl-align-inline-comment-region-1 beg end)))
5eabfe72
KH
7354 ;; align groups
7355 (while (and (< beg end)
3dcb36b7 7356 (re-search-forward vhdl-align-group-separate end t))
5eabfe72 7357 (setq pos (point-marker))
3dcb36b7
JB
7358 (vhdl-align-region-1 beg pos spacing)
7359 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7360 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
5eabfe72
KH
7361 (setq beg (1+ pos))
7362 (goto-char beg))
7363 ;; align last group
7364 (when (< beg end)
3dcb36b7
JB
7365 (vhdl-align-region-1 beg end spacing)
7366 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7367 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7368 (when vhdl-indent-tabs-mode
7369 (tabify orig end))
7370 (unless no-message
7371 (when vhdl-progress-interval (message "Aligning...done"))
7372 (setq vhdl-progress-info nil)))))
7373
7374(defun vhdl-align-region (beg end &optional spacing)
7375 "Align region, treat blocks with same indent and argument lists separately."
7376 (interactive "r\nP")
7377 (if (not vhdl-align-same-indent)
7378 ;; align entire region
7379 (vhdl-align-region-groups beg end spacing)
7380 ;; align blocks with same indent and argument lists
7381 (save-excursion
7382 (let ((cur-beg beg)
7383 indent cur-end)
7384 (when vhdl-progress-interval
7385 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7386 (count-lines (point-min) end) 0)))
7387 (goto-char end)
7388 (setq end (point-marker))
7389 (goto-char cur-beg)
7390 (while (< (point) end)
7391 ;; is argument list opening?
7392 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7393 (point) (vhdl-point 'eol)))))
7394 ;; determine region for argument list
7395 (progn (goto-char cur-beg)
7396 (forward-sexp)
7397 (setq cur-end (point))
7398 (beginning-of-line 2))
7399 ;; determine region with same indent
7400 (setq indent (current-indentation))
7401 (setq cur-beg (point))
7402 (setq cur-end (vhdl-point 'bonl))
7403 (beginning-of-line 2)
7404 (while (and (< (point) end)
7405 (or (looking-at "^\\s-*\\(--.*\\)?$")
7406 (= (current-indentation) indent))
7407 (<= (save-excursion
7408 (nth 0 (parse-partial-sexp
7409 (point) (vhdl-point 'eol)))) 0))
7410 (unless (looking-at "^\\s-*$")
7411 (setq cur-end (vhdl-point 'bonl)))
7412 (beginning-of-line 2)))
7413 ;; align region
7414 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7415 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7416 (when vhdl-progress-interval (message "Aligning...done"))
7417 (setq vhdl-progress-info nil)))))
5eabfe72
KH
7418
7419(defun vhdl-align-group (&optional spacing)
7420 "Align group of lines between empty lines."
7421 (interactive)
3dcb36b7 7422 (vhdl-do-group 'vhdl-align-region spacing))
5eabfe72 7423
3dcb36b7
JB
7424(defun vhdl-align-list (&optional spacing)
7425 "Align the lines of a list surrounded by a balanced group of parentheses."
5eabfe72 7426 (interactive)
3dcb36b7
JB
7427 (vhdl-do-list 'vhdl-align-region-groups spacing))
7428
7429(defun vhdl-align-same-indent (&optional spacing)
7430 "Align block of lines with same indent."
7431 (interactive)
7432 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7433
7434(defun vhdl-align-declarations (&optional spacing)
7435 "Align the lines within the declarative part of a design unit."
7436 (interactive)
7437 (let (beg end)
7438 (vhdl-prepare-search-2
7439 (save-excursion
7440 ;; search for declarative part
7441 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7442 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7443 (setq beg (point))
7444 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7445 (setq end (point)))))
7446 (if beg
7447 (vhdl-align-region-groups beg end spacing)
7448 (error "ERROR: Not within the declarative part of a design unit"))))
7449
7450(defun vhdl-align-buffer ()
7451 "Align buffer."
7452 (interactive)
7453 (vhdl-align-region (point-min) (point-max)))
7454
7455;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7456;; Align inline comments
7457
7458(defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7459 "Align inline comments in region."
7460 (save-excursion
7461 (let ((start-max comment-column)
7462 (length-max 0)
7463 comment-list start-list tmp-list start length
7464 cur-start prev-start no-code)
7465 (setq spacing (or spacing 2))
7466 (vhdl-prepare-search-2
7467 (goto-char beg)
7468 ;; search for comment start positions and lengths
7469 (while (< (point) end)
7470 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7471 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7472 (not (save-excursion (goto-char (match-beginning 2))
7473 (vhdl-in-literal))))
7474 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7475 (setq length (- (match-end 2) (match-beginning 2)))
7476 (setq start-max (max start start-max))
7477 (setq length-max (max length length-max))
7478 (setq comment-list (cons (cons start length) comment-list)))
7479 (beginning-of-line 2))
7480 (setq comment-list
7481 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7482 ;; reduce start positions
7483 (setq start-list (list (caar comment-list)))
7484 (setq comment-list (cdr comment-list))
7485 (while comment-list
7486 (unless (or (= (caar comment-list) (car start-list))
7487 (<= (+ (car start-list) (cdar comment-list))
7488 end-comment-column))
7489 (setq start-list (cons (caar comment-list) start-list)))
7490 (setq comment-list (cdr comment-list)))
7491 ;; align lines as nicely as possible
7492 (goto-char beg)
7493 (while (< (point) end)
7494 (setq cur-start nil)
7495 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7496 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7497 (not (save-excursion
7498 (goto-char (match-beginning 3))
7499 (vhdl-in-literal))))
7500 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7501 (>= (- (match-end 2) (match-beginning 2))
7502 comment-column))))
7503 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7504 (setq length (- (match-end 3) (match-beginning 3)))
7505 (setq no-code (= (match-beginning 1) (match-end 1)))
7506 ;; insert minimum whitespace
7507 (goto-char (match-end 2))
7508 (delete-region (match-beginning 2) (match-end 2))
7509 (insert-char ?\ spacing)
7510 (setq tmp-list start-list)
7511 ;; insert additional whitespace to align
7512 (setq cur-start
7513 (cond
7514 ;; align comment-only line to inline comment of previous line
7515 ((and no-code prev-start
7516 (<= length (- end-comment-column prev-start)))
7517 prev-start)
7518 ;; align all comments at `start-max' if this is possible
7519 ((<= (+ start-max length-max) end-comment-column)
7520 start-max)
7521 ;; align at `comment-column' if possible
7522 ((and (<= start comment-column)
7523 (<= length (- end-comment-column comment-column)))
7524 comment-column)
7525 ;; align at left-most possible start position otherwise
7526 (t
7527 (while (and tmp-list (< (car tmp-list) start))
7528 (setq tmp-list (cdr tmp-list)))
7529 (car tmp-list))))
7530 (indent-to cur-start))
7531 (setq prev-start cur-start)
7532 (beginning-of-line 2))))))
d2ddb974 7533
5eabfe72
KH
7534(defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7535 "Align inline comments within a region. Groups of code lines separated by
7536empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
d2ddb974 7537 (interactive "r\nP")
5eabfe72 7538 (save-excursion
3dcb36b7 7539 (let (orig pos)
5eabfe72
KH
7540 (goto-char beg)
7541 (beginning-of-line)
3dcb36b7 7542 (setq orig (point-marker))
5eabfe72
KH
7543 (setq beg (point))
7544 (goto-char end)
7545 (setq end (point-marker))
7546 (untabify beg end)
7547 (unless no-message (message "Aligning inline comments..."))
7548 (goto-char beg)
7549 (if (not vhdl-align-groups)
7550 ;; align entire region
7551 (vhdl-align-inline-comment-region-1 beg end spacing)
7552 ;; align groups
3dcb36b7
JB
7553 (while (and (< beg end)
7554 (re-search-forward vhdl-align-group-separate end t))
5eabfe72
KH
7555 (setq pos (point-marker))
7556 (vhdl-align-inline-comment-region-1 beg pos spacing)
7557 (setq beg (1+ pos))
7558 (goto-char beg))
7559 ;; align last group
7560 (when (< beg end)
3dcb36b7
JB
7561 (vhdl-align-inline-comment-region-1 beg end spacing)))
7562 (when vhdl-indent-tabs-mode
7563 (tabify orig end))
7564 (unless no-message (message "Aligning inline comments...done")))))
5eabfe72
KH
7565
7566(defun vhdl-align-inline-comment-group (&optional spacing)
7567 "Align inline comments within a group of lines between empty lines."
7568 (interactive)
7569 (save-excursion
7570 (let ((start (point))
7571 beg end)
3dcb36b7 7572 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
5eabfe72
KH
7573 (point-marker) (point-max)))
7574 (goto-char start)
3dcb36b7
JB
7575 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7576 (point) (point-min)))
5eabfe72
KH
7577 (untabify beg end)
7578 (message "Aligning inline comments...")
7579 (vhdl-align-inline-comment-region-1 beg end)
3dcb36b7
JB
7580 (when vhdl-indent-tabs-mode
7581 (tabify beg end))
5eabfe72
KH
7582 (message "Aligning inline comments...done"))))
7583
7584(defun vhdl-align-inline-comment-buffer ()
7585 "Align inline comments within buffer. Groups of code lines separated by
7586empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7587 (interactive)
7588 (vhdl-align-inline-comment-region (point-min) (point-max)))
7589
3dcb36b7
JB
7590;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7591;; Fixup whitespace
7592
5eabfe72
KH
7593(defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7594 "Fixup whitespace in region. Surround operator symbols by one space,
7595eliminate multiple spaces (except at beginning of line), eliminate spaces at
3dcb36b7 7596end of line, do nothing in comments and strings."
5eabfe72
KH
7597 (interactive "r")
7598 (unless no-message (message "Fixing up whitespace..."))
7599 (save-excursion
7600 (goto-char end)
7601 (setq end (point-marker))
5eabfe72
KH
7602 ;; have no space before and one space after `,' and ';'
7603 (goto-char beg)
0a2e512a 7604 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
3dcb36b7
JB
7605 (if (match-string 1)
7606 (goto-char (match-end 1))
7607 (replace-match "\\3 " nil nil nil 3)))
7608 ;; have no space after `('
7609 (goto-char beg)
0a2e512a 7610 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
3dcb36b7
JB
7611 (if (match-string 1)
7612 (goto-char (match-end 1))
7613 (replace-match "\\2")))
7614 ;; have no space before `)'
7615 (goto-char beg)
0a2e512a 7616 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
3dcb36b7
JB
7617 (if (match-string 1)
7618 (goto-char (match-end 1))
7619 (replace-match "\\2")))
7620 ;; surround operator symbols by one space
7621 (goto-char beg)
0a2e512a 7622 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
3dcb36b7
JB
7623 (if (match-string 1)
7624 (goto-char (match-end 1))
0a2e512a
RF
7625 (replace-match "\\3 \\4 \\5")
7626 (goto-char (match-end 2))))
5eabfe72
KH
7627 ;; eliminate multiple spaces and spaces at end of line
7628 (goto-char beg)
7629 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
3dcb36b7 7630 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
5eabfe72
KH
7631 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7632 (progn (replace-match "" nil nil) t))
7633 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7634 (progn (replace-match ";" nil nil) t))
7635 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7636 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
3dcb36b7 7637 (progn (replace-match " " nil nil) t))
5eabfe72 7638 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
3dcb36b7 7639 (progn (replace-match " " nil nil) t))
0a2e512a
RF
7640; (re-search-forward "[^ \t-]+" end t))))
7641 (re-search-forward "[^ \t\"-]+" end t))))
5eabfe72
KH
7642 (unless no-message (message "Fixing up whitespace...done")))
7643
7644(defun vhdl-fixup-whitespace-buffer ()
7645 "Fixup whitespace in buffer. Surround operator symbols by one space,
7646eliminate multiple spaces (except at beginning of line), eliminate spaces at
7647end of line, do nothing in comments."
7648 (interactive)
7649 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7650
3dcb36b7
JB
7651;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7652;; Beautify
7653
5eabfe72
KH
7654(defun vhdl-beautify-region (beg end)
7655 "Beautify region by applying indentation, whitespace fixup, alignment, and
3dcb36b7
JB
7656case fixing to a region. Calls functions `vhdl-indent-buffer',
7657`vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
5eabfe72
KH
7658`vhdl-fix-case-buffer'."
7659 (interactive "r")
3dcb36b7 7660 (setq end (save-excursion (goto-char end) (point-marker)))
5eabfe72
KH
7661 (vhdl-indent-region beg end nil)
7662 (let ((vhdl-align-groups t))
3dcb36b7 7663 (vhdl-align-region beg end))
5eabfe72
KH
7664 (vhdl-fix-case-region beg end))
7665
7666(defun vhdl-beautify-buffer ()
7667 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7668case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7669buffer."
7670 (interactive)
3dcb36b7
JB
7671 (vhdl-beautify-region (point-min) (point-max))
7672 (when noninteractive (save-buffer)))
7673
7674;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7675;; Code filling
7676
7677(defun vhdl-fill-region (beg end &optional arg)
7678 "Fill lines for a region of code."
8d422bd5 7679 (interactive "r\np")
3dcb36b7
JB
7680 (save-excursion
7681 (goto-char beg)
f35aff82 7682 (let ((margin (if arg (current-indentation) (current-column))))
3dcb36b7
JB
7683 (goto-char end)
7684 (setq end (point-marker))
7685 ;; remove inline comments, newlines and whitespace
7686 (vhdl-comment-kill-region beg end)
7687 (vhdl-comment-kill-inline-region beg end)
7688 (subst-char-in-region beg (1- end) ?\n ?\ )
7689 (vhdl-fixup-whitespace-region beg end)
7690 ;; wrap and end-comment-column
7691 (goto-char beg)
7692 (while (re-search-forward "\\s-" end t)
7693 (when(> (current-column) vhdl-end-comment-column)
7694 (backward-char)
7695 (when (re-search-backward "\\s-" beg t)
7696 (replace-match "\n")
7697 (indent-to margin)))))))
7698
7699(defun vhdl-fill-group ()
7700 "Fill group of lines between empty lines."
7701 (interactive)
7702 (vhdl-do-group 'vhdl-fill-region))
7703
7704(defun vhdl-fill-list ()
7705 "Fill the lines of a list surrounded by a balanced group of parentheses."
7706 (interactive)
7707 (vhdl-do-list 'vhdl-fill-region))
7708
7709(defun vhdl-fill-same-indent ()
7710 "Fill the lines of block of lines with same indent."
7711 (interactive)
7712 (vhdl-do-same-indent 'vhdl-fill-region))
7713
7714
7715;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7716;;; Code updating/fixing
7717;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7718
7719;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7720;; Sensitivity list update
7721
7722;; Strategy:
7723;; - no sensitivity list is generated for processes with wait statements
7724;; - otherwise, do the following:
7725;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7726;; 2. scan for all signals already in the sensitivity list (in order to catch
7727;; manually entered global signals)
7728;; 3. signals from 1. and 2. form the list of visible signals
7729;; 4. search for if/elsif conditions containing an event (sequential code)
7730;; 5. scan for strings that are within syntactical regions where signals are
7731;; read but not within sequential code, and that correspond to visible
7732;; signals
7733;; 6. replace sensitivity list by list of signals from 5.
7734
7735(defun vhdl-update-sensitivity-list-process ()
7736 "Update sensitivity list of current process."
7737 (interactive)
7738 (save-excursion
7739 (vhdl-prepare-search-2
7740 (end-of-line)
7741 ;; look whether in process
7742 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7743 (equal (upcase (match-string 2)) "PROCESS")
7744 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7745 (error "ERROR: Not within a process")
7746 (message "Updating sensitivity list...")
7747 (vhdl-update-sensitivity-list)
7748 (message "Updating sensitivity list...done")))))
7749
7750(defun vhdl-update-sensitivity-list-buffer ()
7751 "Update sensitivity list of all processes in current buffer."
7752 (interactive)
7753 (save-excursion
7754 (vhdl-prepare-search-2
7755 (goto-char (point-min))
7756 (message "Updating sensitivity lists...")
7757 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7758 (goto-char (match-beginning 0))
0a2e512a 7759 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
3dcb36b7
JB
7760 (message "Updating sensitivity lists...done"))))
7761
7762(defun vhdl-update-sensitivity-list ()
7763 "Update sensitivity list."
7764 (let ((proc-beg (point))
7765 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7766 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7767 seq-region-list)
7768 (cond
7769 ;; search for wait statement (no sensitivity list allowed)
7770 ((progn (goto-char proc-mid)
7771 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7772 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7773 ;; combinational process (update sensitivity list)
7774 (t
7775 (let
7776 ;; scan for visible signals
7777 ((visible-list (vhdl-get-visible-signals))
7778 ;; define syntactic regions where signals are read
7779 (scan-regions-list
7780 '(;; right-hand side of signal/variable assignment
7781 ;; (special case: "<=" is relational operator in a condition)
7782 ((re-search-forward "[<:]=" proc-end t)
7783 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7784 ;; if condition
7785 ((re-search-forward "^\\s-*if\\>" proc-end t)
7786 (re-search-forward "\\<then\\>" proc-end t))
7787 ;; elsif condition
7788 ((re-search-forward "\\<elsif\\>" proc-end t)
7789 (re-search-forward "\\<then\\>" proc-end t))
7790 ;; while loop condition
7791 ((re-search-forward "^\\s-*while\\>" proc-end t)
7792 (re-search-forward "\\<loop\\>" proc-end t))
7793 ;; exit/next condition
7794 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7795 (re-search-forward ";" proc-end t))
7796 ;; assert condition
7797 ((re-search-forward "\\<assert\\>" proc-end t)
7798 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7799 ;; case expression
7800 ((re-search-forward "^\\s-*case\\>" proc-end t)
7801 (re-search-forward "\\<is\\>" proc-end t))
7802 ;; parameter list of procedure call
0a2e512a
RF
7803 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7804 (1- (point)))
7805 (progn (backward-char) (forward-sexp)
7806 (while (looking-at "(") (forward-sexp)) (point)))))
3dcb36b7
JB
7807 name read-list sens-list signal-list
7808 sens-beg sens-end beg end margin)
7809 ;; scan for signals in old sensitivity list
7810 (goto-char proc-beg)
7811 (re-search-forward "\\<process\\>" proc-mid t)
7812 (if (not (looking-at "[ \t\n]*("))
7813 (setq sens-beg (point))
7814 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7815 (goto-char (match-end 1))
7816 (forward-sexp)
7817 (setq sens-end (1- (point)))
7818 (goto-char sens-beg)
7819 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7820 (setq sens-list
7821 (cons (downcase (match-string 0)) sens-list))
7822 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7823 (setq signal-list (append visible-list sens-list))
7824 ;; search for sequential parts
7825 (goto-char proc-mid)
7826 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7827 (setq end (re-search-forward "\\<then\\>" proc-end t))
7828 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7829 (goto-char end)
7830 (backward-word 1)
7831 (vhdl-forward-sexp)
7832 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7833 (beginning-of-line)))
7834 ;; scan for signals read in process
7835 (while scan-regions-list
7836 (goto-char proc-mid)
7837 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7838 (setq end (eval (nth 1 (car scan-regions-list)))))
7839 (goto-char beg)
7840 (unless (or (vhdl-in-literal)
7841 (and seq-region-list
7842 (let ((tmp-list seq-region-list))
7843 (while (and tmp-list
7844 (< (point) (caar tmp-list)))
7845 (setq tmp-list (cdr tmp-list)))
7846 (and tmp-list (< (point) (cdar tmp-list))))))
0a2e512a 7847 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
3dcb36b7 7848 (setq name (match-string 1))
0a2e512a
RF
7849 (when (and (not (match-string 4)) ; not when formal parameter
7850 (not (and (match-string 3) ; not event attribute
7851 (not (member (downcase (match-string 3))
7852 '("event" "last_event" "transaction")))))
7853 (member (downcase name) signal-list))
7854 (unless (member-ignore-case name read-list)
7855 (setq read-list (cons name read-list))))
7856 (goto-char (match-end 1)))))
3dcb36b7
JB
7857 (setq scan-regions-list (cdr scan-regions-list)))
7858 ;; update sensitivity list
7859 (goto-char sens-beg)
7860 (if sens-end
7861 (delete-region sens-beg sens-end)
7862 (when read-list
7863 (insert " ()") (backward-char)))
7864 (setq read-list (sort read-list 'string<))
7865 (when read-list
7866 (setq margin (current-column))
7867 (insert (car read-list))
7868 (setq read-list (cdr read-list))
7869 (while read-list
7870 (insert ",")
7871 (if (<= (+ (current-column) (length (car read-list)) 2)
7872 end-comment-column)
7873 (insert " ")
7874 (insert "\n") (indent-to margin))
7875 (insert (car read-list))
7876 (setq read-list (cdr read-list)))))))))
7877
7878(defun vhdl-get-visible-signals ()
7879 "Get all signals visible in the current block."
0a2e512a
RF
7880 (let (beg end signal-list entity-name file-name)
7881 (vhdl-prepare-search-2
7882 ;; get entity name
7883 (save-excursion
7884 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
3dcb36b7 7885 (not (equal "END" (upcase (match-string 1))))
0a2e512a
RF
7886 (setq entity-name (match-string 2)))
7887 (error "ERROR: Not within an architecture")))
7888 ;; search for signals declared in entity port clause
7889 (save-excursion
7890 (goto-char (point-min))
7891 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7892 (setq file-name
7893 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7894 "." (file-name-extension (buffer-file-name)))))
7895 (vhdl-visit-file
7896 file-name t
7897 (vhdl-prepare-search-2
7898 (goto-char (point-min))
7899 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7900 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7901 (when (setq beg (re-search-forward
7902 "^\\s-*port[ \t\n]*("
7903 (save-excursion
7904 (re-search-forward "^end\\>" nil t)) t))
7905 (setq end (save-excursion
7906 (backward-char) (forward-sexp) (point)))
7907 (vhdl-forward-syntactic-ws)
7908 (while (< (point) end)
7909 (when (looking-at "signal[ \t\n]+")
7910 (goto-char (match-end 0)))
7911 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7912 (setq signal-list
7913 (cons (downcase (match-string 1)) signal-list))
7914 (goto-char (match-end 0))
7915 (vhdl-forward-syntactic-ws))
7916 (re-search-forward ";" end 1)
7917 (vhdl-forward-syntactic-ws)))))))
7918 ;; search for signals declared in architecture declarative part
7919 (save-excursion
7920 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7921 (not (equal "END" (upcase (match-string 1))))
7922 (setq end (re-search-forward "^begin\\>" nil t))))
7923 (error "ERROR: No architecture declarative part found")
7924 ;; scan for all declared signal and alias names
7925 (goto-char beg)
7926 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7927 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7928 (if (match-string 2)
7929 ;; scan signal name
7930 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7931 (setq signal-list
7932 (cons (downcase (match-string 1)) signal-list))
7933 (goto-char (match-end 0)))
7934 ;; scan alias name, check is alias of (declared) signal
7935 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7936 (member (downcase (match-string 2)) signal-list))
7937 (setq signal-list
7938 (cons (downcase (match-string 1)) signal-list))
7939 (goto-char (match-end 0))))
7940 (setq beg (point))))))
7941 ;; search for signals declared in surrounding block declarative parts
7942 (save-excursion
7943 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7944 (match-string 2))
7945 (goto-char (match-end 2))
7946 (vhdl-backward-sexp)
7947 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7948 beg)
7949 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7950 ;; scan for all declared signal names
7951 (goto-char beg)
7952 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7953 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7954 (if (match-string 2)
7955 ;; scan signal name
7956 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7957 (setq signal-list
7958 (cons (downcase (match-string 1)) signal-list))
7959 (goto-char (match-end 0)))
7960 ;; scan alias name, check is alias of (declared) signal
7961 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7962 (member (downcase (match-string 2)) signal-list))
7963 (setq signal-list
7964 (cons (downcase (match-string 1)) signal-list))
7965 (goto-char (match-end 0))))))
7966 (goto-char beg)))
7967 signal-list)))
3dcb36b7
JB
7968
7969;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7970;; Generic/port clause fixing
7971
7972(defun vhdl-fix-clause ()
7973 "Fix closing parenthesis within generic/port clause."
7974 (interactive)
7975 (save-excursion
7976 (vhdl-prepare-search-2
7977 (let ((pos (point))
7978 beg end)
7979 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7980 (error "ERROR: Not within a generic/port clause")
7981 ;; search for end of clause
7982 (goto-char (match-end 0))
7983 (setq beg (1- (point)))
7984 (vhdl-forward-syntactic-ws)
7985 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7986 (goto-char (1- (match-end 0)))
7987 (setq end (point-marker))
7988 (forward-char)
7989 (vhdl-forward-syntactic-ws))
7990 (goto-char end)
e180ab9f 7991 (when (> pos (point-at-eol))
3dcb36b7
JB
7992 (error "ERROR: Not within a generic/port clause"))
7993 ;; delete closing parenthesis on separate line (not supported style)
7994 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7995 (vhdl-line-kill)
7996 (vhdl-backward-syntactic-ws)
7997 (setq end (point-marker))
7998 (insert ";"))
7999 ;; delete superfluous parentheses
8000 (while (progn (goto-char beg)
8001 (condition-case () (forward-sexp)
8002 (error (goto-char (point-max))))
8003 (< (point) end))
d355a0b7 8004 (delete-char -1))
3dcb36b7
JB
8005 ;; add closing parenthesis
8006 (when (> (point) end)
8007 (goto-char end)
8008 (insert ")")))))))
8009
8010;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8011;; Miscellaneous
8012
8013(defun vhdl-remove-trailing-spaces ()
8014 "Remove trailing spaces in the whole buffer."
8015 (interactive)
8016 (save-match-data
8017 (save-excursion
8018 (goto-char (point-min))
8019 (while (re-search-forward "[ \t]+$" (point-max) t)
8020 (unless (vhdl-in-literal)
8021 (replace-match "" nil nil))))))
d2ddb974
KH
8022
8023
5eabfe72
KH
8024;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8025;;; Electrification
8026;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 8027
5eabfe72
KH
8028(defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8029 "Syntax of prompt inserted by template generators.")
8030
8031(defvar vhdl-template-invoked-by-hook nil
8032 "Indicates whether a template has been invoked by a hook or by key or menu.
8033Used for undoing after template abortion.")
8034
8035;; correct different behavior of function `unread-command-events' in XEmacs
3dcb36b7 8036(defun vhdl-character-to-event (arg))
5eabfe72 8037(defalias 'vhdl-character-to-event
4bcb9c95 8038 (if (fboundp 'character-to-event) 'character-to-event 'identity))
3dcb36b7
JB
8039
8040(defun vhdl-work-library ()
8041 "Return the working library name of the current project or \"work\" if no
8042project is defined."
8043 (vhdl-resolve-env-variable
8044 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
5eabfe72
KH
8045
8046;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8047;; Enabling/disabling
8048
56eb0904 8049(define-minor-mode vhdl-electric-mode
5eabfe72
KH
8050 "Toggle VHDL electric mode.
8051Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
56eb0904 8052 :global t)
5eabfe72 8053
56eb0904 8054(define-minor-mode vhdl-stutter-mode
5eabfe72
KH
8055 "Toggle VHDL stuttering mode.
8056Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
56eb0904 8057 :global t)
5eabfe72
KH
8058
8059;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8060;; Stuttering
d2ddb974 8061
5eabfe72
KH
8062(defun vhdl-electric-dash (count)
8063 "-- starts a comment, --- draws a horizontal line,
a4c6cfad 8064---- starts a display comment."
d2ddb974 8065 (interactive "p")
3dcb36b7 8066 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
5eabfe72
KH
8067 (cond
8068 ((and abbrev-start-location (= abbrev-start-location (point)))
8069 (setq abbrev-start-location nil)
8070 (goto-char last-abbrev-location)
8071 (beginning-of-line nil)
8072 (vhdl-comment-display))
8073 ((/= (preceding-char) ?-) ; standard dash (minus)
d2ddb974 8074 (self-insert-command count))
5eabfe72
KH
8075 (t (self-insert-command count)
8076 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8077 (let ((next-input (read-char)))
8078 (if (= next-input ?-) ; triple dash
8079 (progn
8080 (vhdl-comment-display-line)
8081 (message
8082 "Enter '-' for display comment, else continue coding")
8083 (let ((next-input (read-char)))
8084 (if (= next-input ?-) ; four dashes
8085 (vhdl-comment-display t)
8086 (setq unread-command-events ; pushback the char
8087 (list (vhdl-character-to-event next-input))))))
8088 (setq unread-command-events ; pushback the char
8089 (list (vhdl-character-to-event next-input)))
8090 (vhdl-comment-insert)))))
8091 (self-insert-command count)))
8092
8093(defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
d2ddb974 8094 (interactive "p")
3dcb36b7 8095 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8096 (if (= (preceding-char) ?\()
8097 (progn (delete-char -1) (insert-char ?\[ 1))
8098 (insert-char ?\( 1))
8099 (self-insert-command count)))
d2ddb974 8100
5eabfe72 8101(defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
d2ddb974 8102 (interactive "p")
3dcb36b7 8103 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974 8104 (progn
5eabfe72
KH
8105 (if (= (preceding-char) ?\))
8106 (progn (delete-char -1) (insert-char ?\] 1))
8107 (insert-char ?\) 1))
8108 (blink-matching-open))
8109 (self-insert-command count)))
d2ddb974 8110
5eabfe72 8111(defun vhdl-electric-quote (count) "'' --> \""
d2ddb974 8112 (interactive "p")
3dcb36b7 8113 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8114 (if (= (preceding-char) last-input-event)
d355a0b7 8115 (progn (delete-char -1) (insert-char ?\" 1))
5eabfe72
KH
8116 (insert-char ?\' 1))
8117 (self-insert-command count)))
d2ddb974 8118
5eabfe72 8119(defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
d2ddb974 8120 (interactive "p")
3dcb36b7 8121 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8122 (cond ((= (preceding-char) last-input-event)
5eabfe72 8123 (progn (delete-char -1)
3dcb36b7 8124 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8125 (insert ": ")
8126 (setq this-command 'vhdl-electric-colon)))
8127 ((and
8128 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8129 (progn (delete-char -1) (insert "= ")))
8130 (t (insert-char ?\; 1)))
8131 (self-insert-command count)))
8132
8133(defun vhdl-electric-comma (count) "',,' --> ' <= '"
d2ddb974 8134 (interactive "p")
3dcb36b7 8135 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8136 (cond ((= (preceding-char) last-input-event)
d2ddb974 8137 (progn (delete-char -1)
3dcb36b7 8138 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8139 (insert "<= ")))
5eabfe72
KH
8140 (t (insert-char ?\, 1)))
8141 (self-insert-command count)))
d2ddb974 8142
5eabfe72 8143(defun vhdl-electric-period (count) "'..' --> ' => '"
d2ddb974 8144 (interactive "p")
3dcb36b7 8145 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8146 (cond ((= (preceding-char) last-input-event)
d2ddb974 8147 (progn (delete-char -1)
3dcb36b7 8148 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8149 (insert "=> ")))
5eabfe72
KH
8150 (t (insert-char ?\. 1)))
8151 (self-insert-command count)))
d2ddb974 8152
5eabfe72 8153(defun vhdl-electric-equal (count) "'==' --> ' == '"
d2ddb974 8154 (interactive "p")
3dcb36b7 8155 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8156 (cond ((= (preceding-char) last-input-event)
5eabfe72 8157 (progn (delete-char -1)
3dcb36b7 8158 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8159 (insert "== ")))
8160 (t (insert-char ?\= 1)))
8161 (self-insert-command count)))
d2ddb974 8162
5eabfe72 8163;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
8164;; VHDL templates
8165
5eabfe72
KH
8166(defun vhdl-template-paired-parens ()
8167 "Insert a pair of round parentheses, placing point between them."
d2ddb974 8168 (interactive)
5eabfe72
KH
8169 (insert "()")
8170 (backward-char))
d2ddb974 8171
5eabfe72
KH
8172(defun vhdl-template-alias ()
8173 "Insert alias declaration."
d2ddb974 8174 (interactive)
5eabfe72
KH
8175 (let ((start (point)))
8176 (vhdl-insert-keyword "ALIAS ")
8177 (when (vhdl-template-field "name" nil t start (point))
8178 (insert " : ")
8179 (unless (vhdl-template-field
8180 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8181 nil t)
d355a0b7 8182 (delete-char -3))
5eabfe72
KH
8183 (vhdl-insert-keyword " IS ")
8184 (vhdl-template-field "name" ";")
8185 (vhdl-comment-insert-inline))))
8186
8187(defun vhdl-template-architecture ()
8188 "Insert architecture."
8189 (interactive)
8190 (let ((margin (current-indentation))
8191 (start (point))
3dcb36b7 8192 arch-name)
d2ddb974 8193 (vhdl-insert-keyword "ARCHITECTURE ")
5eabfe72
KH
8194 (when (setq arch-name
8195 (vhdl-template-field "name" nil t start (point)))
d2ddb974 8196 (vhdl-insert-keyword " OF ")
3dcb36b7
JB
8197 (if (save-excursion
8198 (vhdl-prepare-search-1
8199 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8200 (insert (match-string 1))
5eabfe72 8201 (vhdl-template-field "entity name"))
3dcb36b7 8202 (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8203 (vhdl-template-begin-end
8204 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8205 (memq vhdl-insert-empty-lines '(unit all))))))
d2ddb974 8206
5eabfe72 8207(defun vhdl-template-array (kind &optional secondary)
d2ddb974
KH
8208 "Insert array type definition."
8209 (interactive)
5eabfe72
KH
8210 (let ((start (point)))
8211 (vhdl-insert-keyword "ARRAY (")
8212 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8213 secondary)
8214 (vhdl-insert-keyword ") OF ")
8215 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8216 (vhdl-insert-keyword ";"))))
8217
8218(defun vhdl-template-assert ()
8219 "Insert an assertion statement."
8220 (interactive)
8221 (let ((start (point)))
8222 (vhdl-insert-keyword "ASSERT ")
8223 (when vhdl-conditions-in-parenthesis (insert "("))
8224 (when (vhdl-template-field "condition (negated)" nil t start (point))
8225 (when vhdl-conditions-in-parenthesis (insert ")"))
8226 (setq start (point))
8227 (vhdl-insert-keyword " REPORT ")
8228 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8229 (delete-region start (point)))
8230 (setq start (point))
8231 (vhdl-insert-keyword " SEVERITY ")
8232 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8233 (delete-region start (point)))
8234 (insert ";"))))
8235
8236(defun vhdl-template-attribute ()
8237 "Insert an attribute declaration or specification."
8238 (interactive)
8239 (if (eq (vhdl-decision-query
8240 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8241 (vhdl-template-attribute-spec)
8242 (vhdl-template-attribute-decl)))
d2ddb974 8243
5eabfe72
KH
8244(defun vhdl-template-attribute-decl ()
8245 "Insert an attribute declaration."
d2ddb974 8246 (interactive)
5eabfe72
KH
8247 (let ((start (point)))
8248 (vhdl-insert-keyword "ATTRIBUTE ")
8249 (when (vhdl-template-field "name" " : " t start (point))
8250 (vhdl-template-field "type" ";")
8251 (vhdl-comment-insert-inline))))
8252
8253(defun vhdl-template-attribute-spec ()
8254 "Insert an attribute specification."
8255 (interactive)
8256 (let ((start (point)))
8257 (vhdl-insert-keyword "ATTRIBUTE ")
8258 (when (vhdl-template-field "name" nil t start (point))
8259 (vhdl-insert-keyword " OF ")
8260 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8261 (vhdl-template-field "entity class")
8262 (vhdl-insert-keyword " IS ")
8263 (vhdl-template-field "expression" ";"))))
d2ddb974 8264
5eabfe72
KH
8265(defun vhdl-template-block ()
8266 "Insert a block."
d2ddb974 8267 (interactive)
5eabfe72
KH
8268 (let ((margin (current-indentation))
8269 (start (point))
8270 label)
8271 (vhdl-insert-keyword ": BLOCK ")
8272 (goto-char start)
8273 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8274 (forward-word 1)
8275 (forward-char 1)
d2ddb974 8276 (insert "(")
5eabfe72
KH
8277 (if (vhdl-template-field "[guard expression]" nil t)
8278 (insert ")")
8279 (delete-char -2))
8280 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 8281 (insert "\n")
5eabfe72
KH
8282 (vhdl-template-begin-end "BLOCK" label margin)
8283 (vhdl-comment-block))))
d2ddb974 8284
5eabfe72 8285(defun vhdl-template-block-configuration ()
d2ddb974
KH
8286 "Insert a block configuration statement."
8287 (interactive)
5eabfe72
KH
8288 (let ((margin (current-indentation))
8289 (start (point)))
d2ddb974 8290 (vhdl-insert-keyword "FOR ")
5eabfe72 8291 (when (vhdl-template-field "block name" nil t start (point))
d2ddb974
KH
8292 (vhdl-insert-keyword "\n\n")
8293 (indent-to margin)
8294 (vhdl-insert-keyword "END FOR;")
8295 (end-of-line 0)
5eabfe72 8296 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8297
5eabfe72
KH
8298(defun vhdl-template-break ()
8299 "Insert a break statement."
d2ddb974 8300 (interactive)
5eabfe72
KH
8301 (let (position)
8302 (vhdl-insert-keyword "BREAK")
8303 (setq position (point))
8304 (insert " ")
8305 (while (or
8306 (progn (vhdl-insert-keyword "FOR ")
8307 (if (vhdl-template-field "[quantity name]" " USE " t)
8308 (progn (vhdl-template-field "quantity name" " => ") t)
453cfeb3
CY
8309 (delete-region (point)
8310 (progn (forward-word -1) (point)))
8311 nil))
5eabfe72
KH
8312 (vhdl-template-field "[quantity name]" " => " t))
8313 (vhdl-template-field "expression")
8314 (setq position (point))
8315 (insert ", "))
8316 (delete-region position (point))
8317 (unless (vhdl-sequential-statement-p)
8318 (vhdl-insert-keyword " ON ")
8319 (if (vhdl-template-field "[sensitivity list]" nil t)
8320 (setq position (point))
8321 (delete-region position (point))))
8322 (vhdl-insert-keyword " WHEN ")
8323 (when vhdl-conditions-in-parenthesis (insert "("))
8324 (if (vhdl-template-field "[condition]" nil t)
8325 (when vhdl-conditions-in-parenthesis (insert ")"))
8326 (delete-region position (point)))
8327 (insert ";")))
8328
8329(defun vhdl-template-case (&optional kind)
8330 "Insert a case statement."
8331 (interactive)
8332 (let ((margin (current-indentation))
8333 (start (point))
8334 label)
8335 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8336 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8337 (vhdl-insert-keyword "CASE ")
8338 (vhdl-insert-keyword ": CASE ")
8339 (goto-char start)
8340 (setq label (vhdl-template-field "[label]" nil t))
8341 (unless label (delete-char 2))
8342 (forward-word 1)
8343 (forward-char 1))
8344 (when (vhdl-template-field "expression" nil t start (point))
8345 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
d2ddb974 8346 (indent-to margin)
5eabfe72
KH
8347 (vhdl-insert-keyword "END CASE")
8348 (when label (insert " " label))
8349 (insert ";")
d2ddb974
KH
8350 (forward-line -1)
8351 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8352 (vhdl-insert-keyword "WHEN ")
8353 (let ((position (point)))
8354 (insert " => ;\n")
8355 (indent-to (+ margin vhdl-basic-offset))
8356 (vhdl-insert-keyword "WHEN OTHERS => null;")
8357 (goto-char position)))))
d2ddb974 8358
5eabfe72
KH
8359(defun vhdl-template-case-is ()
8360 "Insert a sequential case statement."
d2ddb974 8361 (interactive)
5eabfe72
KH
8362 (vhdl-template-case 'is))
8363
8364(defun vhdl-template-case-use ()
8365 "Insert a simultaneous case statement."
8366 (interactive)
8367 (vhdl-template-case 'use))
8368
8369(defun vhdl-template-component ()
8370 "Insert a component declaration."
8371 (interactive)
8372 (vhdl-template-component-decl))
8373
8374(defun vhdl-template-component-conf ()
8375 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8376since these are almost equivalent)."
8377 (interactive)
8378 (let ((margin (current-indentation))
8379 (result (vhdl-template-configuration-spec t)))
8380 (when result
8381 (insert "\n")
8382 (indent-to margin)
8383 (vhdl-insert-keyword "END FOR;")
8384 (when (eq result 'no-use)
8385 (end-of-line -0)))))
8386
8387(defun vhdl-template-component-decl ()
8388 "Insert a component declaration."
8389 (interactive)
8390 (let ((margin (current-indentation))
8391 (start (point))
8392 name end-column)
d2ddb974 8393 (vhdl-insert-keyword "COMPONENT ")
5eabfe72 8394 (when (setq name (vhdl-template-field "name" nil t start (point)))
3dcb36b7 8395 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
d2ddb974
KH
8396 (insert "\n\n")
8397 (indent-to margin)
5eabfe72
KH
8398 (vhdl-insert-keyword "END COMPONENT")
8399 (unless (vhdl-standard-p '87) (insert " " name))
8400 (insert ";")
8401 (setq end-column (current-column))
d2ddb974
KH
8402 (end-of-line -0)
8403 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 8404 (vhdl-template-generic-list t t)
d2ddb974
KH
8405 (insert "\n")
8406 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8407 (vhdl-template-port-list t)
8408 (beginning-of-line 2)
8409 (forward-char end-column))))
d2ddb974 8410
5eabfe72
KH
8411(defun vhdl-template-component-inst ()
8412 "Insert a component instantiation statement."
d2ddb974 8413 (interactive)
5eabfe72
KH
8414 (let ((margin (current-indentation))
8415 (start (point))
8416 unit position)
8417 (when (vhdl-template-field "instance label" nil t start (point))
8418 (insert ": ")
3dcb36b7 8419 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
8420 (vhdl-template-field "component name")
8421 ;; direct instantiation
8422 (setq unit (vhdl-template-field
8423 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8424 (setq unit (upcase (or unit "")))
8425 (cond ((equal unit "ENTITY")
3dcb36b7
JB
8426 (vhdl-template-field "library name" "." nil nil nil nil
8427 (vhdl-work-library))
5eabfe72
KH
8428 (vhdl-template-field "entity name" "(")
8429 (if (vhdl-template-field "[architecture name]" nil t)
8430 (insert ")")
8431 (delete-char -1)))
8432 ((equal unit "CONFIGURATION")
3dcb36b7
JB
8433 (vhdl-template-field "library name" "." nil nil nil nil
8434 (vhdl-work-library))
5eabfe72
KH
8435 (vhdl-template-field "configuration name"))
8436 (t (vhdl-template-field "component name"))))
8437 (insert "\n")
d2ddb974 8438 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8439 (setq position (point))
8440 (vhdl-insert-keyword "GENERIC ")
8441 (when (vhdl-template-map position t t)
8442 (insert "\n")
8443 (indent-to (+ margin vhdl-basic-offset)))
8444 (setq position (point))
8445 (vhdl-insert-keyword "PORT ")
8446 (unless (vhdl-template-map position t t)
453cfeb3 8447 (delete-region (line-beginning-position) (point))
5eabfe72
KH
8448 (delete-char -1))
8449 (insert ";"))))
d2ddb974 8450
5eabfe72
KH
8451(defun vhdl-template-conditional-signal-asst ()
8452 "Insert a conditional signal assignment."
d2ddb974 8453 (interactive)
5eabfe72 8454 (when (vhdl-template-field "target signal")
d2ddb974 8455 (insert " <= ")
5eabfe72
KH
8456; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8457; (insert " "))
d2ddb974 8458 (let ((margin (current-column))
5eabfe72
KH
8459 (start (point))
8460 position)
8461 (vhdl-template-field "waveform")
8462 (setq position (point))
d2ddb974 8463 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8464 (when vhdl-conditions-in-parenthesis (insert "("))
8465 (while (and (vhdl-template-field "[condition]" nil t)
8466 (progn
8467 (when vhdl-conditions-in-parenthesis (insert ")"))
8468 (setq position (point))
8469 (vhdl-insert-keyword " ELSE")
8470 (insert "\n")
8471 (indent-to margin)
8472 (vhdl-template-field "[waveform]" nil t)))
8473 (setq position (point))
d2ddb974 8474 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8475 (when vhdl-conditions-in-parenthesis (insert "(")))
8476 (delete-region position (point))
d2ddb974 8477 (insert ";")
3dcb36b7 8478 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 8479
5eabfe72
KH
8480(defun vhdl-template-configuration ()
8481 "Insert a configuration specification if within an architecture,
d2ddb974
KH
8482a block or component configuration if within a configuration declaration,
8483a configuration declaration if not within a design unit."
8484 (interactive)
3dcb36b7
JB
8485 (vhdl-prepare-search-1
8486 (cond
8487 ((and (save-excursion ; architecture body
8488 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8489 (equal "ARCHITECTURE" (upcase (match-string 1))))
8490 (vhdl-template-configuration-spec))
8491 ((and (save-excursion ; configuration declaration
8492 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8493 (equal "CONFIGURATION" (upcase (match-string 1))))
8494 (if (eq (vhdl-decision-query
8495 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8496 (vhdl-template-component-conf)
8497 (vhdl-template-block-configuration)))
8498 (t (vhdl-template-configuration-decl))))) ; otherwise
5eabfe72
KH
8499
8500(defun vhdl-template-configuration-spec (&optional optional-use)
8501 "Insert a configuration specification."
d2ddb974 8502 (interactive)
5eabfe72
KH
8503 (let ((margin (current-indentation))
8504 (start (point))
8505 aspect position)
d2ddb974 8506 (vhdl-insert-keyword "FOR ")
3dcb36b7 8507 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
5eabfe72 8508 t start (point))
3dcb36b7 8509 (vhdl-template-field "component name" "\n")
d2ddb974 8510 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8511 (setq start (point))
8512 (vhdl-insert-keyword "USE ")
8513 (if (and optional-use
8514 (not (setq aspect (vhdl-template-field
8515 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8516 (progn (delete-region start (point)) 'no-use)
8517 (unless optional-use
8518 (setq aspect (vhdl-template-field
8519 "ENTITY | CONFIGURATION | OPEN" " ")))
8520 (setq aspect (upcase (or aspect "")))
8521 (cond ((equal aspect "ENTITY")
3dcb36b7
JB
8522 (vhdl-template-field "library name" "." nil nil nil nil
8523 (vhdl-work-library))
5eabfe72
KH
8524 (vhdl-template-field "entity name" "(")
8525 (if (vhdl-template-field "[architecture name]" nil t)
8526 (insert ")")
d2ddb974 8527 (delete-char -1))
5eabfe72
KH
8528 (insert "\n")
8529 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8530 (setq position (point))
8531 (vhdl-insert-keyword "GENERIC ")
8532 (when (vhdl-template-map position t t)
8533 (insert "\n")
8534 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8535 (setq position (point))
8536 (vhdl-insert-keyword "PORT ")
8537 (unless (vhdl-template-map position t t)
453cfeb3 8538 (delete-region (line-beginning-position) (point))
5eabfe72
KH
8539 (delete-char -1))
8540 (insert ";")
8541 t)
8542 ((equal aspect "CONFIGURATION")
3dcb36b7
JB
8543 (vhdl-template-field "library name" "." nil nil nil nil
8544 (vhdl-work-library))
5eabfe72 8545 (vhdl-template-field "configuration name" ";"))
d355a0b7 8546 (t (delete-char -1) (insert ";") t))))))
5eabfe72 8547
d2ddb974 8548
5eabfe72
KH
8549(defun vhdl-template-configuration-decl ()
8550 "Insert a configuration declaration."
d2ddb974 8551 (interactive)
5eabfe72
KH
8552 (let ((margin (current-indentation))
8553 (start (point))
5eabfe72 8554 entity-exists string name position)
d2ddb974 8555 (vhdl-insert-keyword "CONFIGURATION ")
5eabfe72 8556 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974 8557 (vhdl-insert-keyword " OF ")
5eabfe72 8558 (save-excursion
3dcb36b7
JB
8559 (vhdl-prepare-search-1
8560 (setq entity-exists (vhdl-re-search-backward
5eabfe72
KH
8561 "\\<entity \\(\\w*\\) is\\>" nil t))
8562 (setq string (match-string 1))))
d2ddb974 8563 (if (and entity-exists (not (equal string "")))
5eabfe72
KH
8564 (insert string)
8565 (vhdl-template-field "entity name"))
8566 (vhdl-insert-keyword " IS\n")
8567 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8568 (indent-to (+ margin vhdl-basic-offset))
8569 (setq position (point))
8570 (insert "\n")
8571 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
d2ddb974
KH
8572 (indent-to margin)
8573 (vhdl-insert-keyword "END ")
5eabfe72
KH
8574 (unless (vhdl-standard-p '87)
8575 (vhdl-insert-keyword "CONFIGURATION "))
d2ddb974 8576 (insert name ";")
5eabfe72 8577 (goto-char position))))
d2ddb974 8578
5eabfe72
KH
8579(defun vhdl-template-constant ()
8580 "Insert a constant declaration."
8581 (interactive)
8582 (let ((start (point))
8583 (in-arglist (vhdl-in-argument-list-p)))
8584 (vhdl-insert-keyword "CONSTANT ")
8585 (when (vhdl-template-field "name" nil t start (point))
d2ddb974 8586 (insert " : ")
5eabfe72
KH
8587 (when in-arglist (vhdl-insert-keyword "IN "))
8588 (vhdl-template-field "type")
d2ddb974 8589 (if in-arglist
5eabfe72
KH
8590 (progn (insert ";")
8591 (vhdl-comment-insert-inline))
d2ddb974
KH
8592 (let ((position (point)))
8593 (insert " := ")
5eabfe72
KH
8594 (unless (vhdl-template-field "[initialization]" nil t)
8595 (delete-region position (point)))
8596 (insert ";")
8597 (vhdl-comment-insert-inline))))))
d2ddb974 8598
5eabfe72 8599(defun vhdl-template-default ()
d2ddb974
KH
8600 "Insert nothing."
8601 (interactive)
8602 (insert " ")
8603 (unexpand-abbrev)
8604 (backward-word 1)
8605 (vhdl-case-word 1)
5eabfe72 8606 (forward-char 1))
d2ddb974 8607
5eabfe72 8608(defun vhdl-template-default-indent ()
d2ddb974
KH
8609 "Insert nothing and indent."
8610 (interactive)
8611 (insert " ")
8612 (unexpand-abbrev)
8613 (backward-word 1)
8614 (vhdl-case-word 1)
8615 (forward-char 1)
3dcb36b7 8616 (indent-according-to-mode))
d2ddb974 8617
5eabfe72 8618(defun vhdl-template-disconnect ()
d2ddb974
KH
8619 "Insert a disconnect statement."
8620 (interactive)
5eabfe72
KH
8621 (let ((start (point)))
8622 (vhdl-insert-keyword "DISCONNECT ")
8623 (when (vhdl-template-field "signal names | OTHERS | ALL"
8624 " : " t start (point))
8625 (vhdl-template-field "type")
8626 (vhdl-insert-keyword " AFTER ")
8627 (vhdl-template-field "time expression" ";"))))
8628
8629(defun vhdl-template-else ()
d2ddb974
KH
8630 "Insert an else statement."
8631 (interactive)
3dcb36b7
JB
8632 (let (margin)
8633 (vhdl-prepare-search-1
5eabfe72 8634 (vhdl-insert-keyword "ELSE")
3dcb36b7
JB
8635 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8636 (equal "WHEN" (upcase (match-string 1))))
5eabfe72 8637 (insert " ")
3dcb36b7 8638 (indent-according-to-mode)
5eabfe72
KH
8639 (setq margin (current-indentation))
8640 (insert "\n")
8641 (indent-to (+ margin vhdl-basic-offset))))))
8642
8643(defun vhdl-template-elsif ()
d2ddb974
KH
8644 "Insert an elsif statement."
8645 (interactive)
5eabfe72
KH
8646 (let ((start (point))
8647 margin)
d2ddb974 8648 (vhdl-insert-keyword "ELSIF ")
3dcb36b7
JB
8649 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8650 (when vhdl-conditions-in-parenthesis (insert "("))
8651 (when (vhdl-template-field "condition" nil t start (point))
8652 (when vhdl-conditions-in-parenthesis (insert ")"))
8653 (indent-according-to-mode)
8654 (setq margin (current-indentation))
8655 (vhdl-insert-keyword
8656 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8657 (indent-to (+ margin vhdl-basic-offset))))))
d2ddb974 8658
5eabfe72
KH
8659(defun vhdl-template-entity ()
8660 "Insert an entity."
d2ddb974 8661 (interactive)
5eabfe72
KH
8662 (let ((margin (current-indentation))
8663 (start (point))
8664 name end-column)
d2ddb974 8665 (vhdl-insert-keyword "ENTITY ")
5eabfe72 8666 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974
KH
8667 (vhdl-insert-keyword " IS\n\n")
8668 (indent-to margin)
8669 (vhdl-insert-keyword "END ")
5eabfe72
KH
8670 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8671 (insert name ";")
8672 (setq end-column (current-column))
d2ddb974
KH
8673 (end-of-line -0)
8674 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8675 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8676 (indent-to (+ margin vhdl-basic-offset))
8677 (when (vhdl-template-generic-list t)
8678 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8679 (insert "\n")
8680 (indent-to (+ margin vhdl-basic-offset))
8681 (when (vhdl-template-port-list t)
8682 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8683 (beginning-of-line 2)
8684 (forward-char end-column))))
d2ddb974 8685
5eabfe72 8686(defun vhdl-template-exit ()
d2ddb974
KH
8687 "Insert an exit statement."
8688 (interactive)
5eabfe72
KH
8689 (let ((start (point)))
8690 (vhdl-insert-keyword "EXIT ")
3dcb36b7
JB
8691 (if (vhdl-template-field "[loop label]" nil t start (point))
8692 (let ((position (point)))
8693 (vhdl-insert-keyword " WHEN ")
8694 (when vhdl-conditions-in-parenthesis (insert "("))
8695 (if (vhdl-template-field "[condition]" nil t)
8696 (when vhdl-conditions-in-parenthesis (insert ")"))
8697 (delete-region position (point))))
d2ddb974 8698 (delete-char -1))
5eabfe72
KH
8699 (insert ";")))
8700
8701(defun vhdl-template-file ()
8702 "Insert a file declaration."
8703 (interactive)
8704 (let ((start (point)))
8705 (vhdl-insert-keyword "FILE ")
8706 (when (vhdl-template-field "name" nil t start (point))
8707 (insert " : ")
8708 (vhdl-template-field "type")
8709 (unless (vhdl-standard-p '87)
8710 (vhdl-insert-keyword " OPEN ")
8711 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8712 nil t)
d355a0b7 8713 (delete-char -6)))
5eabfe72
KH
8714 (vhdl-insert-keyword " IS ")
8715 (when (vhdl-standard-p '87)
8716 (vhdl-template-field "[IN | OUT]" " " t))
8717 (vhdl-template-field "filename-string" nil nil nil nil t)
8718 (insert ";")
8719 (vhdl-comment-insert-inline))))
d2ddb974 8720
5eabfe72
KH
8721(defun vhdl-template-for ()
8722 "Insert a block or component configuration if within a configuration
8723declaration, a configuration specification if within an architecture
3dcb36b7
JB
8724declarative part (and not within a subprogram), a for-loop if within a
8725sequential statement part (subprogram or process), and a for-generate
8726otherwise."
5eabfe72 8727 (interactive)
3dcb36b7
JB
8728 (vhdl-prepare-search-1
8729 (cond
8730 ((vhdl-sequential-statement-p) ; sequential statement
8731 (vhdl-template-for-loop))
8732 ((and (save-excursion ; configuration declaration
8733 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8734 (equal "CONFIGURATION" (upcase (match-string 1))))
8735 (if (eq (vhdl-decision-query
8736 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8737 (vhdl-template-component-conf)
8738 (vhdl-template-block-configuration)))
8739 ((and (save-excursion
8740 (re-search-backward ; architecture declarative part
8741 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8742 (equal "ARCHITECTURE" (upcase (match-string 1))))
8743 (vhdl-template-configuration-spec))
8744 (t (vhdl-template-for-generate))))) ; concurrent statement
5eabfe72
KH
8745
8746(defun vhdl-template-for-generate ()
8747 "Insert a for-generate."
d2ddb974 8748 (interactive)
5eabfe72
KH
8749 (let ((margin (current-indentation))
8750 (start (point))
3dcb36b7 8751 label position)
5eabfe72
KH
8752 (vhdl-insert-keyword ": FOR ")
8753 (setq position (point-marker))
8754 (goto-char start)
8755 (when (setq label (vhdl-template-field "label" nil t start position))
8756 (goto-char position)
8757 (vhdl-template-field "loop variable")
8758 (vhdl-insert-keyword " IN ")
8759 (vhdl-template-field "range")
8760 (vhdl-template-generate-body margin label))))
d2ddb974 8761
5eabfe72
KH
8762(defun vhdl-template-for-loop ()
8763 "Insert a for loop."
d2ddb974 8764 (interactive)
5eabfe72
KH
8765 (let ((margin (current-indentation))
8766 (start (point))
8767 label index)
8768 (if (not (eq vhdl-optional-labels 'all))
8769 (vhdl-insert-keyword "FOR ")
8770 (vhdl-insert-keyword ": FOR ")
8771 (goto-char start)
8772 (setq label (vhdl-template-field "[label]" nil t))
8773 (unless label (delete-char 2))
8774 (forward-word 1)
8775 (forward-char 1))
8776 (when (setq index (vhdl-template-field "loop variable"
8777 nil t start (point)))
d2ddb974 8778 (vhdl-insert-keyword " IN ")
5eabfe72 8779 (vhdl-template-field "range")
d2ddb974
KH
8780 (vhdl-insert-keyword " LOOP\n\n")
8781 (indent-to margin)
8782 (vhdl-insert-keyword "END LOOP")
5eabfe72
KH
8783 (if label
8784 (insert " " label ";")
d2ddb974 8785 (insert ";")
5eabfe72 8786 (when vhdl-self-insert-comments (insert " -- " index)))
d2ddb974 8787 (forward-line -1)
5eabfe72 8788 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8789
5eabfe72
KH
8790(defun vhdl-template-function (&optional kind)
8791 "Insert a function declaration or body."
d2ddb974 8792 (interactive)
5eabfe72
KH
8793 (let ((margin (current-indentation))
8794 (start (point))
8795 name)
8796 (vhdl-insert-keyword "FUNCTION ")
8797 (when (setq name (vhdl-template-field "name" nil t start (point)))
8798 (vhdl-template-argument-list t)
3dcb36b7 8799 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
d2ddb974 8800 (end-of-line)
5eabfe72 8801 (insert "\n")
d2ddb974 8802 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8803 (vhdl-insert-keyword "RETURN ")
8804 (vhdl-template-field "type")
8805 (if (if kind (eq kind 'body)
8806 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
3dcb36b7 8807 (progn (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8808 (vhdl-template-begin-end
8809 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8810 (vhdl-comment-block))
8811 (insert ";")))))
8812
8813(defun vhdl-template-function-decl ()
8814 "Insert a function declaration."
8815 (interactive)
8816 (vhdl-template-function 'decl))
d2ddb974 8817
5eabfe72
KH
8818(defun vhdl-template-function-body ()
8819 "Insert a function declaration."
d2ddb974 8820 (interactive)
5eabfe72
KH
8821 (vhdl-template-function 'body))
8822
8823(defun vhdl-template-generate ()
8824 "Insert a generation scheme."
8825 (interactive)
8826 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8827 (vhdl-template-if-generate)
8828 (vhdl-template-for-generate)))
d2ddb974 8829
5eabfe72
KH
8830(defun vhdl-template-generic ()
8831 "Insert generic declaration, or generic map in instantiation statements."
8832 (interactive)
3dcb36b7
JB
8833 (let ((start (point)))
8834 (vhdl-prepare-search-1
5eabfe72
KH
8835 (cond
8836 ((and (save-excursion ; entity declaration
8837 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8838 (equal "ENTITY" (upcase (match-string 1))))
8839 (vhdl-template-generic-list nil))
8840 ((or (save-excursion
8841 (or (beginning-of-line)
8842 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 8843 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
8844 (vhdl-insert-keyword "GENERIC ")
8845 (vhdl-template-map start))
8846 (t (vhdl-template-generic-list nil t))))))
8847
8848(defun vhdl-template-group ()
8849 "Insert group or group template declaration."
8850 (interactive)
8851 (let ((start (point)))
8852 (if (eq (vhdl-decision-query
8853 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8854 (vhdl-template-group-template)
8855 (vhdl-template-group-decl))))
8856
8857(defun vhdl-template-group-decl ()
8858 "Insert group declaration."
8859 (interactive)
8860 (let ((start (point)))
8861 (vhdl-insert-keyword "GROUP ")
8862 (when (vhdl-template-field "name" " : " t start (point))
8863 (vhdl-template-field "template name" " (")
8864 (vhdl-template-field "constituent list" ");")
8865 (vhdl-comment-insert-inline))))
8866
8867(defun vhdl-template-group-template ()
8868 "Insert group template declaration."
8869 (interactive)
8870 (let ((start (point)))
8871 (vhdl-insert-keyword "GROUP ")
8872 (when (vhdl-template-field "template name" nil t start (point))
8873 (vhdl-insert-keyword " IS (")
8874 (vhdl-template-field "entity class list" ");")
8875 (vhdl-comment-insert-inline))))
8876
5eabfe72
KH
8877(defun vhdl-template-if ()
8878 "Insert a sequential if statement or an if-generate statement."
8879 (interactive)
8880 (if (vhdl-sequential-statement-p)
8881 (vhdl-template-if-then)
8882 (if (and (vhdl-standard-p 'ams)
8883 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8884 (vhdl-template-if-use)
8885 (vhdl-template-if-generate))))
8886
8887(defun vhdl-template-if-generate ()
8888 "Insert an if-generate."
8889 (interactive)
8890 (let ((margin (current-indentation))
8891 (start (point))
3dcb36b7 8892 label position)
5eabfe72
KH
8893 (vhdl-insert-keyword ": IF ")
8894 (setq position (point-marker))
8895 (goto-char start)
8896 (when (setq label (vhdl-template-field "label" nil t start position))
8897 (goto-char position)
8898 (when vhdl-conditions-in-parenthesis (insert "("))
8899 (vhdl-template-field "condition")
8900 (when vhdl-conditions-in-parenthesis (insert ")"))
8901 (vhdl-template-generate-body margin label))))
d2ddb974 8902
5eabfe72
KH
8903(defun vhdl-template-if-then-use (kind)
8904 "Insert a sequential if statement."
8905 (interactive)
8906 (let ((margin (current-indentation))
8907 (start (point))
8908 label)
8909 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8910 (vhdl-insert-keyword "IF ")
8911 (vhdl-insert-keyword ": IF ")
8912 (goto-char start)
8913 (setq label (vhdl-template-field "[label]" nil t))
8914 (unless label (delete-char 2))
8915 (forward-word 1)
8916 (forward-char 1))
8917 (when vhdl-conditions-in-parenthesis (insert "("))
8918 (when (vhdl-template-field "condition" nil t start (point))
8919 (when vhdl-conditions-in-parenthesis (insert ")"))
8920 (vhdl-insert-keyword
8921 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
d2ddb974 8922 (indent-to margin)
5eabfe72
KH
8923 (vhdl-insert-keyword "END IF")
8924 (when label (insert " " label))
8925 (insert ";")
d2ddb974 8926 (forward-line -1)
5eabfe72
KH
8927 (indent-to (+ margin vhdl-basic-offset)))))
8928
8929(defun vhdl-template-if-then ()
8930 "Insert a sequential if statement."
8931 (interactive)
8932 (vhdl-template-if-then-use 'then))
8933
8934(defun vhdl-template-if-use ()
8935 "Insert a simultaneous if statement."
8936 (interactive)
8937 (vhdl-template-if-then-use 'use))
8938
8939(defun vhdl-template-instance ()
8940 "Insert a component instantiation statement."
8941 (interactive)
8942 (vhdl-template-component-inst))
d2ddb974 8943
5eabfe72 8944(defun vhdl-template-library ()
d2ddb974
KH
8945 "Insert a library specification."
8946 (interactive)
5eabfe72
KH
8947 (let ((margin (current-indentation))
8948 (start (point))
8949 name end-pos)
d2ddb974 8950 (vhdl-insert-keyword "LIBRARY ")
5eabfe72
KH
8951 (when (setq name (vhdl-template-field "names" nil t start (point)))
8952 (insert ";")
8953 (unless (string-match "," name)
8954 (setq end-pos (point))
8955 (insert "\n")
8956 (indent-to margin)
8957 (vhdl-insert-keyword "USE ")
8958 (insert name)
8959 (vhdl-insert-keyword "..ALL;")
8960 (backward-char 5)
8961 (if (vhdl-template-field "package name")
8962 (forward-char 5)
8963 (delete-region end-pos (+ (point) 5)))))))
8964
8965(defun vhdl-template-limit ()
8966 "Insert a limit."
d2ddb974 8967 (interactive)
5eabfe72
KH
8968 (let ((start (point)))
8969 (vhdl-insert-keyword "LIMIT ")
8970 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8971 t start (point))
8972 (vhdl-template-field "type")
8973 (vhdl-insert-keyword " WITH ")
8974 (vhdl-template-field "real expression" ";"))))
8975
8976(defun vhdl-template-loop ()
8977 "Insert a loop."
8978 (interactive)
8979 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8980 (cond ((eq char ?w)
8981 (vhdl-template-while-loop))
8982 ((eq char ?f)
8983 (vhdl-template-for-loop))
8984 (t (vhdl-template-bare-loop)))))
8985
8986(defun vhdl-template-bare-loop ()
8987 "Insert a loop."
8988 (interactive)
8989 (let ((margin (current-indentation))
8990 (start (point))
8991 label)
8992 (if (not (eq vhdl-optional-labels 'all))
8993 (vhdl-insert-keyword "LOOP ")
8994 (vhdl-insert-keyword ": LOOP ")
8995 (goto-char start)
8996 (setq label (vhdl-template-field "[label]" nil t))
8997 (unless label (delete-char 2))
8998 (forward-word 1)
8999 (delete-char 1))
d2ddb974
KH
9000 (insert "\n\n")
9001 (indent-to margin)
9002 (vhdl-insert-keyword "END LOOP")
5eabfe72 9003 (insert (if label (concat " " label ";") ";"))
d2ddb974 9004 (forward-line -1)
5eabfe72 9005 (indent-to (+ margin vhdl-basic-offset))))
d2ddb974 9006
5eabfe72
KH
9007(defun vhdl-template-map (&optional start optional secondary)
9008 "Insert a map specification with association list."
d2ddb974 9009 (interactive)
5eabfe72
KH
9010 (let ((start (or start (point)))
9011 margin end-pos)
9012 (vhdl-insert-keyword "MAP (")
9013 (if (not vhdl-association-list-with-formals)
9014 (if (vhdl-template-field
9015 (concat (and optional "[") "association list" (and optional "]"))
9016 ")" (or (not secondary) optional)
9017 (and (not secondary) start) (point))
9018 t
9019 (if (and optional secondary) (delete-region start (point)))
9020 nil)
9021 (if vhdl-argument-list-indent
9022 (setq margin (current-column))
9023 (setq margin (+ (current-indentation) vhdl-basic-offset))
9024 (insert "\n")
9025 (indent-to margin))
9026 (if (vhdl-template-field
9027 (concat (and optional "[") "formal" (and optional "]"))
9028 " => " (or (not secondary) optional)
9029 (and (not secondary) start) (point))
9030 (progn
9031 (vhdl-template-field "actual" ",")
9032 (setq end-pos (point))
9033 (insert "\n")
9034 (indent-to margin)
9035 (while (vhdl-template-field "[formal]" " => " t)
9036 (vhdl-template-field "actual" ",")
9037 (setq end-pos (point))
9038 (insert "\n")
9039 (indent-to margin))
9040 (delete-region end-pos (point))
d355a0b7 9041 (delete-char -1)
5eabfe72 9042 (insert ")")
3dcb36b7 9043 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9044 t)
9045 (when (and optional secondary) (delete-region start (point)))
9046 nil))))
d2ddb974 9047
5eabfe72 9048(defun vhdl-template-modify (&optional noerror)
d2ddb974
KH
9049 "Actualize modification date."
9050 (interactive)
3dcb36b7
JB
9051 (vhdl-prepare-search-2
9052 (save-excursion
9053 (goto-char (point-min))
9054 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9055 (progn (delete-region (point) (progn (end-of-line) (point)))
9056 (vhdl-template-insert-date))
9057 (unless noerror
a867ead0
DG
9058 (error "ERROR: Modification date prefix string \"%s\" not found"
9059 vhdl-modify-date-prefix-string))))))
9060
5eabfe72
KH
9061
9062(defun vhdl-template-modify-noerror ()
9063 "Call `vhdl-template-modify' with NOERROR non-nil."
9064 (vhdl-template-modify t))
9065
9066(defun vhdl-template-nature ()
9067 "Insert a nature declaration."
9068 (interactive)
9069 (let ((start (point))
9070 name mid-pos end-pos)
9071 (vhdl-insert-keyword "NATURE ")
9072 (when (setq name (vhdl-template-field "name" nil t start (point)))
9073 (vhdl-insert-keyword " IS ")
9074 (let ((definition
9075 (upcase
9076 (or (vhdl-template-field
9077 "across type | ARRAY | RECORD")
9078 ""))))
9079 (cond ((equal definition "")
9080 (insert ";"))
9081 ((equal definition "ARRAY")
453cfeb3 9082 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9083 (vhdl-template-array 'nature t))
9084 ((equal definition "RECORD")
9085 (setq mid-pos (point-marker))
453cfeb3 9086 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9087 (vhdl-template-record 'nature name t))
9088 (t
9089 (vhdl-insert-keyword " ACROSS ")
9090 (vhdl-template-field "through type")
9091 (vhdl-insert-keyword " THROUGH ")
9092 (vhdl-template-field "reference name")
9093 (vhdl-insert-keyword " REFERENCE;")))
9094 (when mid-pos
9095 (setq end-pos (point-marker))
9096 (goto-char mid-pos)
9097 (end-of-line))
9098 (vhdl-comment-insert-inline)
9099 (when end-pos (goto-char end-pos))))))
9100
9101(defun vhdl-template-next ()
9102 "Insert a next statement."
d2ddb974 9103 (interactive)
3dcb36b7
JB
9104 (let ((start (point)))
9105 (vhdl-insert-keyword "NEXT ")
9106 (if (vhdl-template-field "[loop label]" nil t start (point))
9107 (let ((position (point)))
9108 (vhdl-insert-keyword " WHEN ")
9109 (when vhdl-conditions-in-parenthesis (insert "("))
9110 (if (vhdl-template-field "[condition]" nil t)
9111 (when vhdl-conditions-in-parenthesis (insert ")"))
9112 (delete-region position (point))))
9113 (delete-char -1))
5eabfe72
KH
9114 (insert ";")))
9115
9116(defun vhdl-template-others ()
9117 "Insert an others aggregate."
9118 (interactive)
3dcb36b7
JB
9119 (let ((start (point)))
9120 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9121 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9122 (vhdl-insert-keyword "OTHERS => '")
9123 (when (vhdl-template-field "value" nil t start (point))
9124 (insert "')")))
9125 (vhdl-insert-keyword "OTHERS "))))
d2ddb974 9126
5eabfe72 9127(defun vhdl-template-package (&optional kind)
d2ddb974
KH
9128 "Insert a package specification or body."
9129 (interactive)
5eabfe72
KH
9130 (let ((margin (current-indentation))
9131 (start (point))
9132 name body position)
d2ddb974 9133 (vhdl-insert-keyword "PACKAGE ")
5eabfe72
KH
9134 (setq body (if kind (eq kind 'body)
9135 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
3dcb36b7
JB
9136 (when body
9137 (vhdl-insert-keyword "BODY ")
9138 (when (save-excursion
9139 (vhdl-prepare-search-1
9140 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9141 (insert (setq name (match-string 1)))))
9142 (when (or name
9143 (setq name (vhdl-template-field "name" nil t start (point))))
5eabfe72
KH
9144 (vhdl-insert-keyword " IS\n")
9145 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9146 (indent-to (+ margin vhdl-basic-offset))
9147 (setq position (point))
9148 (insert "\n")
9149 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9150 (indent-to margin)
9151 (vhdl-insert-keyword "END ")
9152 (unless (vhdl-standard-p '87)
9153 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9154 (insert (or name "") ";")
9155 (goto-char position))))
d2ddb974 9156
5eabfe72
KH
9157(defun vhdl-template-package-decl ()
9158 "Insert a package specification."
d2ddb974 9159 (interactive)
5eabfe72 9160 (vhdl-template-package 'decl))
d2ddb974 9161
5eabfe72
KH
9162(defun vhdl-template-package-body ()
9163 "Insert a package body."
d2ddb974 9164 (interactive)
5eabfe72 9165 (vhdl-template-package 'body))
d2ddb974 9166
5eabfe72
KH
9167(defun vhdl-template-port ()
9168 "Insert a port declaration, or port map in instantiation statements."
d2ddb974 9169 (interactive)
3dcb36b7
JB
9170 (let ((start (point)))
9171 (vhdl-prepare-search-1
5eabfe72
KH
9172 (cond
9173 ((and (save-excursion ; entity declaration
9174 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9175 (equal "ENTITY" (upcase (match-string 1))))
9176 (vhdl-template-port-list nil))
9177 ((or (save-excursion
9178 (or (beginning-of-line)
9179 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 9180 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
9181 (vhdl-insert-keyword "PORT ")
9182 (vhdl-template-map start))
9183 (t (vhdl-template-port-list nil))))))
9184
9185(defun vhdl-template-procedural ()
9186 "Insert a procedural."
9187 (interactive)
9188 (let ((margin (current-indentation))
9189 (start (point))
9190 (case-fold-search t)
9191 label)
9192 (vhdl-insert-keyword "PROCEDURAL ")
9193 (when (memq vhdl-optional-labels '(process all))
9194 (goto-char start)
9195 (insert ": ")
9196 (goto-char start)
9197 (setq label (vhdl-template-field "[label]" nil t))
9198 (unless label (delete-char 2))
9199 (forward-word 1)
9200 (forward-char 1))
9201 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
3dcb36b7 9202 (insert "\n")
5eabfe72
KH
9203 (vhdl-template-begin-end "PROCEDURAL" label margin)
9204 (vhdl-comment-block)))
9205
9206(defun vhdl-template-procedure (&optional kind)
9207 "Insert a procedure declaration or body."
9208 (interactive)
9209 (let ((margin (current-indentation))
9210 (start (point))
9211 name)
9212 (vhdl-insert-keyword "PROCEDURE ")
9213 (when (setq name (vhdl-template-field "name" nil t start (point)))
9214 (vhdl-template-argument-list)
9215 (if (if kind (eq kind 'body)
9216 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9217 (progn (vhdl-insert-keyword " IS")
9218 (when vhdl-auto-align
3dcb36b7
JB
9219 (vhdl-align-region-groups start (point) 1))
9220 (end-of-line) (insert "\n")
5eabfe72
KH
9221 (vhdl-template-begin-end
9222 (unless (vhdl-standard-p '87) "PROCEDURE")
9223 name margin)
9224 (vhdl-comment-block))
9225 (insert ";")
3dcb36b7 9226 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9227 (end-of-line)))))
9228
9229(defun vhdl-template-procedure-decl ()
9230 "Insert a procedure declaration."
9231 (interactive)
9232 (vhdl-template-procedure 'decl))
d2ddb974 9233
5eabfe72
KH
9234(defun vhdl-template-procedure-body ()
9235 "Insert a procedure body."
9236 (interactive)
9237 (vhdl-template-procedure 'body))
9238
9239(defun vhdl-template-process (&optional kind)
9240 "Insert a process."
9241 (interactive)
9242 (let ((margin (current-indentation))
9243 (start (point))
5eabfe72
KH
9244 label seq input-signals clock reset final-pos)
9245 (setq seq (if kind (eq kind 'seq)
9246 (eq (vhdl-decision-query
9247 "process" "(c)ombinational or (s)equential?" t) ?s)))
9248 (vhdl-insert-keyword "PROCESS ")
9249 (when (memq vhdl-optional-labels '(process all))
9250 (goto-char start)
9251 (insert ": ")
9252 (goto-char start)
9253 (setq label (vhdl-template-field "[label]" nil t))
9254 (unless label (delete-char 2))
9255 (forward-word 1)
9256 (forward-char 1))
9257 (insert "(")
9258 (if (not seq)
9259 (unless (setq input-signals
9260 (vhdl-template-field "[sensitivity list]" ")" t))
9261 (setq input-signals "")
9262 (delete-char -2))
9263 (setq clock (or (and (not (equal "" vhdl-clock-name))
9264 (progn (insert vhdl-clock-name) vhdl-clock-name))
9265 (vhdl-template-field "clock name") "<clock>"))
9266 (when (eq vhdl-reset-kind 'async)
9267 (insert ", ")
9268 (setq reset (or (and (not (equal "" vhdl-reset-name))
9269 (progn (insert vhdl-reset-name) vhdl-reset-name))
9270 (vhdl-template-field "reset name") "<reset>")))
9271 (insert ")"))
9272 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 9273 (insert "\n")
5eabfe72
KH
9274 (vhdl-template-begin-end "PROCESS" label margin)
9275 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9276 (when vhdl-prompt-for-comments
9277 (setq final-pos (point-marker))
3dcb36b7
JB
9278 (vhdl-prepare-search-2
9279 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9280 (vhdl-re-search-backward "\\<process\\>" nil t))
5eabfe72
KH
9281 (end-of-line -0)
9282 (if (bobp)
9283 (progn (insert "\n") (forward-line -1))
9284 (insert "\n"))
9285 (indent-to margin)
9286 (insert "-- purpose: ")
9287 (if (not (vhdl-template-field "[description]" nil t))
9288 (vhdl-line-kill-entire)
9289 (insert "\n")
9290 (indent-to margin)
9291 (insert "-- type : ")
9292 (insert (if seq "sequential" "combinational") "\n")
9293 (indent-to margin)
9294 (insert "-- inputs : ")
9295 (if (not seq)
9296 (insert input-signals)
9297 (insert clock ", ")
9298 (when reset (insert reset ", "))
9299 (unless (vhdl-template-field "[signal names]" nil t)
9300 (delete-char -2)))
9301 (insert "\n")
9302 (indent-to margin)
9303 (insert "-- outputs: ")
9304 (vhdl-template-field "[signal names]" nil t))))
9305 (goto-char final-pos))))
9306
9307(defun vhdl-template-process-comb ()
9308 "Insert a combinational process."
9309 (interactive)
9310 (vhdl-template-process 'comb))
9311
9312(defun vhdl-template-process-seq ()
9313 "Insert a sequential process."
9314 (interactive)
9315 (vhdl-template-process 'seq))
9316
9317(defun vhdl-template-quantity ()
9318 "Insert a quantity declaration."
9319 (interactive)
9320 (if (vhdl-in-argument-list-p)
9321 (let ((start (point)))
9322 (vhdl-insert-keyword "QUANTITY ")
9323 (when (vhdl-template-field "names" nil t start (point))
9324 (insert " : ")
9325 (vhdl-template-field "[IN | OUT]" " " t)
9326 (vhdl-template-field "type")
9327 (insert ";")
9328 (vhdl-comment-insert-inline)))
9329 (let ((char (vhdl-decision-query
9330 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9331 (cond ((eq char ?f) (vhdl-template-quantity-free))
9332 ((eq char ?b) (vhdl-template-quantity-branch))
9333 ((eq char ?s) (vhdl-template-quantity-source))
9334 (t (vhdl-template-undo (point) (point)))))))
9335
9336(defun vhdl-template-quantity-free ()
9337 "Insert a free quantity declaration."
9338 (interactive)
9339 (vhdl-insert-keyword "QUANTITY ")
9340 (vhdl-template-field "names")
9341 (insert " : ")
9342 (vhdl-template-field "type")
9343 (let ((position (point)))
9344 (insert " := ")
9345 (unless (vhdl-template-field "[initialization]" nil t)
9346 (delete-region position (point)))
9347 (insert ";")
9348 (vhdl-comment-insert-inline)))
9349
9350(defun vhdl-template-quantity-branch ()
9351 "Insert a branch quantity declaration."
9352 (interactive)
9353 (let (position)
9354 (vhdl-insert-keyword "QUANTITY ")
9355 (when (vhdl-template-field "[across names]" " " t)
9356 (vhdl-insert-keyword "ACROSS "))
9357 (when (vhdl-template-field "[through names]" " " t)
9358 (vhdl-insert-keyword "THROUGH "))
9359 (vhdl-template-field "plus terminal name")
9360 (setq position (point))
9361 (vhdl-insert-keyword " TO ")
9362 (unless (vhdl-template-field "[minus terminal name]" nil t)
9363 (delete-region position (point)))
9364 (insert ";")
9365 (vhdl-comment-insert-inline)))
9366
9367(defun vhdl-template-quantity-source ()
9368 "Insert a source quantity declaration."
9369 (interactive)
9370 (vhdl-insert-keyword "QUANTITY ")
9371 (vhdl-template-field "names")
9372 (insert " : ")
9373 (vhdl-template-field "type" " ")
9374 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9375 (progn (vhdl-insert-keyword "NOISE ")
9376 (vhdl-template-field "power expression"))
9377 (vhdl-insert-keyword "SPECTRUM ")
9378 (vhdl-template-field "magnitude expression" ", ")
9379 (vhdl-template-field "phase expression"))
9380 (insert ";")
9381 (vhdl-comment-insert-inline))
9382
9383(defun vhdl-template-record (kind &optional name secondary)
d2ddb974
KH
9384 "Insert a record type declaration."
9385 (interactive)
9386 (let ((margin (current-column))
9387 (start (point))
9388 (first t))
9389 (vhdl-insert-keyword "RECORD\n")
9390 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9391 (when (or (vhdl-template-field "element names"
9392 nil (not secondary) start (point))
9393 secondary)
9394 (while (or first (vhdl-template-field "[element names]" nil t))
9395 (insert " : ")
9396 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9397 (vhdl-comment-insert-inline)
9398 (insert "\n")
d2ddb974 9399 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 9400 (setq first nil))
453cfeb3 9401 (delete-region (line-beginning-position) (point))
d2ddb974 9402 (indent-to margin)
5eabfe72
KH
9403 (vhdl-insert-keyword "END RECORD")
9404 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9405 (insert ";")
3dcb36b7 9406 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9407
5eabfe72
KH
9408(defun vhdl-template-report ()
9409 "Insert a report statement."
9410 (interactive)
9411 (let ((start (point)))
9412 (vhdl-insert-keyword "REPORT ")
9413 (if (equal "\"\"" (vhdl-template-field
9414 "string expression" nil t start (point) t))
d355a0b7 9415 (delete-char -2)
5eabfe72
KH
9416 (setq start (point))
9417 (vhdl-insert-keyword " SEVERITY ")
9418 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9419 (delete-region start (point)))
9420 (insert ";"))))
9421
9422(defun vhdl-template-return ()
d2ddb974
KH
9423 "Insert a return statement."
9424 (interactive)
3dcb36b7
JB
9425 (let ((start (point)))
9426 (vhdl-insert-keyword "RETURN ")
9427 (unless (vhdl-template-field "[expression]" nil t start (point))
9428 (delete-char -1))
9429 (insert ";")))
d2ddb974 9430
5eabfe72 9431(defun vhdl-template-selected-signal-asst ()
d2ddb974
KH
9432 "Insert a selected signal assignment."
9433 (interactive)
5eabfe72
KH
9434 (let ((margin (current-indentation))
9435 (start (point))
9436 (choices t))
d2ddb974 9437 (let ((position (point)))
5eabfe72 9438 (vhdl-insert-keyword " SELECT ")
d2ddb974
KH
9439 (goto-char position))
9440 (vhdl-insert-keyword "WITH ")
5eabfe72
KH
9441 (when (vhdl-template-field "selector expression"
9442 nil t start (+ (point) 7))
9443 (forward-word 1)
9444 (delete-char 1)
d2ddb974
KH
9445 (insert "\n")
9446 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9447 (vhdl-template-field "target signal" " <= ")
9448; (vhdl-template-field "[GUARDED] [TRANSPORT]")
d2ddb974
KH
9449 (insert "\n")
9450 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9451 (vhdl-template-field "waveform")
9452 (vhdl-insert-keyword " WHEN ")
9453 (vhdl-template-field "choices" ",")
9454 (insert "\n")
9455 (indent-to (+ margin vhdl-basic-offset))
9456 (while (and choices (vhdl-template-field "[waveform]" nil t))
d2ddb974 9457 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
9458 (if (setq choices (vhdl-template-field "[choices]" "," t))
9459 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9460 (vhdl-insert-keyword "OTHERS")))
9461 (when choices
d2ddb974
KH
9462 (fixup-whitespace)
9463 (delete-char -2))
9464 (insert ";")
3dcb36b7 9465 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9466
5eabfe72 9467(defun vhdl-template-signal ()
d2ddb974
KH
9468 "Insert a signal declaration."
9469 (interactive)
5eabfe72
KH
9470 (let ((start (point))
9471 (in-arglist (vhdl-in-argument-list-p)))
9472 (vhdl-insert-keyword "SIGNAL ")
9473 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9474 (insert " : ")
5eabfe72
KH
9475 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9476 (vhdl-template-field "type")
d2ddb974 9477 (if in-arglist
5eabfe72
KH
9478 (progn (insert ";")
9479 (vhdl-comment-insert-inline))
d2ddb974
KH
9480 (let ((position (point)))
9481 (insert " := ")
5eabfe72
KH
9482 (unless (vhdl-template-field "[initialization]" nil t)
9483 (delete-region position (point)))
9484 (insert ";")
9485 (vhdl-comment-insert-inline))))))
9486
9487(defun vhdl-template-subnature ()
9488 "Insert a subnature declaration."
9489 (interactive)
9490 (let ((start (point))
9491 position)
9492 (vhdl-insert-keyword "SUBNATURE ")
9493 (when (vhdl-template-field "name" nil t start (point))
9494 (vhdl-insert-keyword " IS ")
9495 (vhdl-template-field "nature" " (")
9496 (if (vhdl-template-field "[index range]" nil t)
9497 (insert ")")
9498 (delete-char -2))
9499 (setq position (point))
9500 (vhdl-insert-keyword " TOLERANCE ")
9501 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9502 nil t nil nil t))
9503 (delete-region position (point))
9504 (vhdl-insert-keyword " ACROSS ")
9505 (vhdl-template-field "string expression" nil nil nil nil t)
9506 (vhdl-insert-keyword " THROUGH"))
9507 (insert ";")
9508 (vhdl-comment-insert-inline))))
9509
9510(defun vhdl-template-subprogram-body ()
9511 "Insert a subprogram body."
9512 (interactive)
9513 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9514 (vhdl-template-function-body)
9515 (vhdl-template-procedure-body)))
d2ddb974 9516
5eabfe72
KH
9517(defun vhdl-template-subprogram-decl ()
9518 "Insert a subprogram declaration."
9519 (interactive)
9520 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9521 (vhdl-template-function-decl)
9522 (vhdl-template-procedure-decl)))
9523
9524(defun vhdl-template-subtype ()
d2ddb974
KH
9525 "Insert a subtype declaration."
9526 (interactive)
5eabfe72
KH
9527 (let ((start (point)))
9528 (vhdl-insert-keyword "SUBTYPE ")
9529 (when (vhdl-template-field "name" nil t start (point))
9530 (vhdl-insert-keyword " IS ")
9531 (vhdl-template-field "type" " ")
9532 (unless
9533 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
d2ddb974 9534 (delete-char -1))
5eabfe72
KH
9535 (insert ";")
9536 (vhdl-comment-insert-inline))))
d2ddb974 9537
5eabfe72
KH
9538(defun vhdl-template-terminal ()
9539 "Insert a terminal declaration."
d2ddb974 9540 (interactive)
5eabfe72
KH
9541 (let ((start (point)))
9542 (vhdl-insert-keyword "TERMINAL ")
9543 (when (vhdl-template-field "names" nil t start (point))
9544 (insert " : ")
9545 (vhdl-template-field "nature")
9546 (insert ";")
9547 (vhdl-comment-insert-inline))))
d2ddb974 9548
5eabfe72
KH
9549(defun vhdl-template-type ()
9550 "Insert a type declaration."
9551 (interactive)
9552 (let ((start (point))
9553 name mid-pos end-pos)
9554 (vhdl-insert-keyword "TYPE ")
9555 (when (setq name (vhdl-template-field "name" nil t start (point)))
9556 (vhdl-insert-keyword " IS ")
9557 (let ((definition
9558 (upcase
9559 (or (vhdl-template-field
9560 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9561 ""))))
9562 (cond ((equal definition "")
d355a0b7 9563 (delete-char -4)
5eabfe72
KH
9564 (insert ";"))
9565 ((equal definition "ARRAY")
453cfeb3 9566 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9567 (vhdl-template-array 'type t))
9568 ((equal definition "RECORD")
9569 (setq mid-pos (point-marker))
453cfeb3 9570 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9571 (vhdl-template-record 'type name t))
9572 ((equal definition "ACCESS")
9573 (insert " ")
9574 (vhdl-template-field "type" ";"))
9575 ((equal definition "FILE")
9576 (vhdl-insert-keyword " OF ")
9577 (vhdl-template-field "type" ";"))
9578 (t (insert ";")))
9579 (when mid-pos
9580 (setq end-pos (point-marker))
9581 (goto-char mid-pos)
9582 (end-of-line))
9583 (vhdl-comment-insert-inline)
9584 (when end-pos (goto-char end-pos))))))
9585
9586(defun vhdl-template-use ()
d2ddb974
KH
9587 "Insert a use clause."
9588 (interactive)
3dcb36b7
JB
9589 (let ((start (point)))
9590 (vhdl-prepare-search-1
5eabfe72
KH
9591 (vhdl-insert-keyword "USE ")
9592 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9593 (vhdl-insert-keyword "..ALL;")
9594 (backward-char 6)
9595 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9596 (forward-char 1)
9597 (vhdl-template-field "package name")
9598 (forward-char 5))))))
9599
9600(defun vhdl-template-variable ()
d2ddb974
KH
9601 "Insert a variable declaration."
9602 (interactive)
5eabfe72 9603 (let ((start (point))
5eabfe72 9604 (in-arglist (vhdl-in-argument-list-p)))
3dcb36b7 9605 (vhdl-prepare-search-2
5eabfe72 9606 (if (or (save-excursion
3dcb36b7 9607 (and (vhdl-re-search-backward
5eabfe72
KH
9608 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9609 nil t)
9610 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9611 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9612 (vhdl-insert-keyword "VARIABLE ")
9613 (vhdl-insert-keyword "SHARED VARIABLE ")))
9614 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9615 (insert " : ")
5eabfe72
KH
9616 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9617 (vhdl-template-field "type")
d2ddb974 9618 (if in-arglist
5eabfe72
KH
9619 (progn (insert ";")
9620 (vhdl-comment-insert-inline))
d2ddb974
KH
9621 (let ((position (point)))
9622 (insert " := ")
5eabfe72
KH
9623 (unless (vhdl-template-field "[initialization]" nil t)
9624 (delete-region position (point)))
9625 (insert ";")
9626 (vhdl-comment-insert-inline))))))
d2ddb974 9627
5eabfe72 9628(defun vhdl-template-wait ()
d2ddb974
KH
9629 "Insert a wait statement."
9630 (interactive)
9631 (vhdl-insert-keyword "WAIT ")
5eabfe72
KH
9632 (unless (vhdl-template-field
9633 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9634 nil t)
9635 (delete-char -1))
9636 (insert ";"))
d2ddb974 9637
5eabfe72 9638(defun vhdl-template-when ()
d2ddb974
KH
9639 "Indent correctly if within a case statement."
9640 (interactive)
9641 (let ((position (point))
5eabfe72 9642 margin)
3dcb36b7 9643 (vhdl-prepare-search-2
5eabfe72 9644 (if (and (= (current-column) (current-indentation))
3dcb36b7 9645 (vhdl-re-search-forward "\\<end\\>" nil t)
5eabfe72
KH
9646 (looking-at "\\s-*\\<case\\>"))
9647 (progn
9648 (setq margin (current-indentation))
9649 (goto-char position)
9650 (delete-horizontal-space)
9651 (indent-to (+ margin vhdl-basic-offset)))
9652 (goto-char position)))
9653 (vhdl-insert-keyword "WHEN ")))
9654
9655(defun vhdl-template-while-loop ()
9656 "Insert a while loop."
d2ddb974 9657 (interactive)
5eabfe72
KH
9658 (let* ((margin (current-indentation))
9659 (start (point))
9660 label)
9661 (if (not (eq vhdl-optional-labels 'all))
9662 (vhdl-insert-keyword "WHILE ")
9663 (vhdl-insert-keyword ": WHILE ")
9664 (goto-char start)
9665 (setq label (vhdl-template-field "[label]" nil t))
9666 (unless label (delete-char 2))
9667 (forward-word 1)
9668 (forward-char 1))
9669 (when vhdl-conditions-in-parenthesis (insert "("))
9670 (when (vhdl-template-field "condition" nil t start (point))
9671 (when vhdl-conditions-in-parenthesis (insert ")"))
d2ddb974
KH
9672 (vhdl-insert-keyword " LOOP\n\n")
9673 (indent-to margin)
9674 (vhdl-insert-keyword "END LOOP")
5eabfe72 9675 (insert (if label (concat " " label ";") ";"))
d2ddb974 9676 (forward-line -1)
5eabfe72 9677 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 9678
5eabfe72 9679(defun vhdl-template-with ()
d2ddb974
KH
9680 "Insert a with statement (i.e. selected signal assignment)."
9681 (interactive)
3dcb36b7
JB
9682 (vhdl-prepare-search-1
9683 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9684 (equal ";" (match-string 1)))
9685 (vhdl-template-selected-signal-asst)
9686 (vhdl-insert-keyword "WITH "))))
5eabfe72
KH
9687
9688;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9689;; Special templates
9690
9691(defun vhdl-template-clocked-wait ()
9692 "Insert a wait statement for rising/falling clock edge."
9693 (interactive)
9694 (let ((start (point))
9695 clock)
9696 (vhdl-insert-keyword "WAIT UNTIL ")
9697 (when (setq clock
9698 (or (and (not (equal "" vhdl-clock-name))
9699 (progn (insert vhdl-clock-name) vhdl-clock-name))
9700 (vhdl-template-field "clock name" nil t start (point))))
9701 (insert "'event")
9702 (vhdl-insert-keyword " AND ")
9703 (insert clock)
9704 (insert
9705 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9706 (vhdl-comment-insert-inline
9707 (concat (if vhdl-clock-rising-edge "rising" "falling")
9708 " clock edge")))))
9709
9710(defun vhdl-template-seq-process (clock reset)
9711 "Insert a template for the body of a sequential process."
9712 (let ((margin (current-indentation))
9713 position)
d2ddb974 9714 (vhdl-insert-keyword "IF ")
5eabfe72
KH
9715 (when (eq vhdl-reset-kind 'async)
9716 (insert reset " = "
9717 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9718 (vhdl-insert-keyword " THEN")
9719 (vhdl-comment-insert-inline
9720 (concat "asynchronous reset (active "
9721 (if vhdl-reset-active-high "high" "low") ")"))
9722 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9723 (setq position (point))
9724 (insert "\n") (indent-to margin)
9725 (vhdl-insert-keyword "ELSIF "))
9726 (if (eq vhdl-clock-edge-condition 'function)
9727 (insert (if vhdl-clock-rising-edge "rising" "falling")
9728 "_edge(" clock ")")
9729 (insert clock "'event")
9730 (vhdl-insert-keyword " AND ")
9731 (insert clock " = "
9732 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9733 (vhdl-insert-keyword " THEN")
9734 (vhdl-comment-insert-inline
9735 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9736 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9737 (when (eq vhdl-reset-kind 'sync)
9738 (vhdl-insert-keyword "IF ")
9739 (setq reset (or (and (not (equal "" vhdl-reset-name))
9740 (progn (insert vhdl-reset-name) vhdl-reset-name))
9741 (vhdl-template-field "reset name") "<reset>"))
9742 (insert " = "
9743 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9744 (vhdl-insert-keyword " THEN")
9745 (vhdl-comment-insert-inline
9746 (concat "synchronous reset (active "
9747 (if vhdl-reset-active-high "high" "low") ")"))
9748 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9749 (setq position (point))
9750 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9751 (vhdl-insert-keyword "ELSE")
9752 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9753 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9754 (vhdl-insert-keyword "END IF;"))
9755 (when (eq vhdl-reset-kind 'none)
9756 (setq position (point)))
9757 (insert "\n") (indent-to margin)
d2ddb974 9758 (vhdl-insert-keyword "END IF;")
5eabfe72
KH
9759 (goto-char position)
9760 reset))
d2ddb974 9761
5eabfe72
KH
9762(defun vhdl-template-standard-package (library package)
9763 "Insert specification of a standard package. Include a library
9764specification, if not already there."
3dcb36b7
JB
9765 (let ((margin (current-indentation)))
9766 (unless (equal library "std")
9767 (unless (or (save-excursion
9768 (vhdl-prepare-search-1
9769 (and (not (bobp))
9770 (re-search-backward
9771 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9772 library "\\|end\\)\\>") nil t)
9773 (match-string 2))))
9774 (equal (downcase library) "work"))
9775 (vhdl-insert-keyword "LIBRARY ")
0a2e512a
RF
9776 (insert library ";")
9777 (when package
9778 (insert "\n")
9779 (indent-to margin)))
9780 (when package
9781 (vhdl-insert-keyword "USE ")
9782 (insert library "." package)
9783 (vhdl-insert-keyword ".ALL;")))))
d2ddb974 9784
5eabfe72
KH
9785(defun vhdl-template-package-math-complex ()
9786 "Insert specification of `math_complex' package."
d2ddb974 9787 (interactive)
5eabfe72 9788 (vhdl-template-standard-package "ieee" "math_complex"))
d2ddb974 9789
5eabfe72
KH
9790(defun vhdl-template-package-math-real ()
9791 "Insert specification of `math_real' package."
d2ddb974 9792 (interactive)
5eabfe72 9793 (vhdl-template-standard-package "ieee" "math_real"))
d2ddb974 9794
5eabfe72
KH
9795(defun vhdl-template-package-numeric-bit ()
9796 "Insert specification of `numeric_bit' package."
d2ddb974 9797 (interactive)
5eabfe72 9798 (vhdl-template-standard-package "ieee" "numeric_bit"))
d2ddb974 9799
5eabfe72
KH
9800(defun vhdl-template-package-numeric-std ()
9801 "Insert specification of `numeric_std' package."
d2ddb974 9802 (interactive)
5eabfe72 9803 (vhdl-template-standard-package "ieee" "numeric_std"))
d2ddb974 9804
5eabfe72
KH
9805(defun vhdl-template-package-std-logic-1164 ()
9806 "Insert specification of `std_logic_1164' package."
9807 (interactive)
9808 (vhdl-template-standard-package "ieee" "std_logic_1164"))
d2ddb974 9809
5eabfe72
KH
9810(defun vhdl-template-package-std-logic-arith ()
9811 "Insert specification of `std_logic_arith' package."
9812 (interactive)
9813 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9814
9815(defun vhdl-template-package-std-logic-misc ()
9816 "Insert specification of `std_logic_misc' package."
9817 (interactive)
9818 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9819
9820(defun vhdl-template-package-std-logic-signed ()
9821 "Insert specification of `std_logic_signed' package."
9822 (interactive)
9823 (vhdl-template-standard-package "ieee" "std_logic_signed"))
d2ddb974 9824
5eabfe72
KH
9825(defun vhdl-template-package-std-logic-textio ()
9826 "Insert specification of `std_logic_textio' package."
9827 (interactive)
9828 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9829
9830(defun vhdl-template-package-std-logic-unsigned ()
9831 "Insert specification of `std_logic_unsigned' package."
9832 (interactive)
9833 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9834
9835(defun vhdl-template-package-textio ()
9836 "Insert specification of `textio' package."
9837 (interactive)
9838 (vhdl-template-standard-package "std" "textio"))
9839
9840(defun vhdl-template-directive (directive)
9841 "Insert directive."
9842 (unless (= (current-indentation) (current-column))
9843 (delete-horizontal-space)
9844 (insert " "))
9845 (insert "-- pragma " directive))
9846
9847(defun vhdl-template-directive-translate-on ()
9848 "Insert directive 'translate_on'."
9849 (interactive)
9850 (vhdl-template-directive "translate_on"))
9851
9852(defun vhdl-template-directive-translate-off ()
9853 "Insert directive 'translate_off'."
9854 (interactive)
9855 (vhdl-template-directive "translate_off"))
9856
9857(defun vhdl-template-directive-synthesis-on ()
9858 "Insert directive 'synthesis_on'."
9859 (interactive)
9860 (vhdl-template-directive "synthesis_on"))
9861
9862(defun vhdl-template-directive-synthesis-off ()
9863 "Insert directive 'synthesis_off'."
9864 (interactive)
9865 (vhdl-template-directive "synthesis_off"))
9866
3dcb36b7
JB
9867;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9868;; Header and footer templates
9869
9870(defun vhdl-template-header (&optional file-title)
9871 "Insert a VHDL file header."
9872 (interactive)
9873 (unless (equal vhdl-file-header "")
9874 (let (pos)
9875 (save-excursion
9876 (goto-char (point-min))
9877 (vhdl-insert-string-or-file vhdl-file-header)
9878 (setq pos (point-marker)))
9879 (vhdl-template-replace-header-keywords
9880 (point-min-marker) pos file-title))))
9881
9882(defun vhdl-template-footer ()
9883 "Insert a VHDL file footer."
9884 (interactive)
9885 (unless (equal vhdl-file-footer "")
9886 (let (pos)
9887 (save-excursion
9888 (goto-char (point-max))
9889 (setq pos (point-marker))
9890 (vhdl-insert-string-or-file vhdl-file-footer)
9891 (unless (= (preceding-char) ?\n)
9892 (insert "\n")))
9893 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9894
9895(defun vhdl-template-replace-header-keywords (beg end &optional file-title
9896 is-model)
9897 "Replace keywords in header and footer."
9898 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9899 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9900 pos)
9901 (vhdl-prepare-search-2
9902 (save-excursion
9903 (goto-char beg)
9904 (while (search-forward "<projectdesc>" end t)
9905 (replace-match project-desc t t))
9906 (goto-char beg)
9907 (while (search-forward "<filename>" end t)
9908 (replace-match (buffer-name) t t))
9909 (goto-char beg)
9910 (while (search-forward "<copyright>" end t)
9911 (replace-match vhdl-copyright-string t t))
9912 (goto-char beg)
9913 (while (search-forward "<author>" end t)
9914 (replace-match "" t t)
9915 (insert (user-full-name))
9916 (when user-mail-address (insert " <" user-mail-address ">")))
9917 (goto-char beg)
9918 (while (search-forward "<login>" end t)
9919 (replace-match (user-login-name) t t))
9920 (goto-char beg)
9921 (while (search-forward "<project>" end t)
9922 (replace-match project-title t t))
9923 (goto-char beg)
9924 (while (search-forward "<company>" end t)
9925 (replace-match vhdl-company-name t t))
9926 (goto-char beg)
9927 (while (search-forward "<platform>" end t)
9928 (replace-match vhdl-platform-spec t t))
9929 (goto-char beg)
9930 (while (search-forward "<standard>" end t)
9931 (replace-match
9932 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9933 ((vhdl-standard-p '93) "'93"))
9934 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9935 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9936 (goto-char beg)
9937 ;; Replace <RCS> with $, so that RCS for the source is
9938 ;; not over-enthusiastic with replacements
9939 (while (search-forward "<RCS>" end t)
9940 (replace-match "$" nil t))
9941 (goto-char beg)
9942 (while (search-forward "<date>" end t)
9943 (replace-match "" t t)
9944 (vhdl-template-insert-date))
9945 (goto-char beg)
9946 (while (search-forward "<year>" end t)
9947 (replace-match (format-time-string "%Y" nil) t t))
9948 (goto-char beg)
9949 (when file-title
9950 (while (search-forward "<title string>" end t)
9951 (replace-match file-title t t))
9952 (goto-char beg))
9953 (let (string)
9954 (while
9955 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9956 (setq string (read-string (concat (match-string 1) ": ")))
9957 (replace-match string t t)))
9958 (goto-char beg)
9959 (when (and (not is-model) (search-forward "<cursor>" end t))
9960 (replace-match "" t t)
9961 (setq pos (point))))
9962 (when pos (goto-char pos))
9963 (unless is-model
9964 (when (or (not project-title) (equal project-title ""))
9965 (message "You can specify a project title in user option `vhdl-project-alist'"))
9966 (when (or (not project-desc) (equal project-desc ""))
9967 (message "You can specify a project description in user option `vhdl-project-alist'"))
9968 (when (equal vhdl-platform-spec "")
9969 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9970 (when (equal vhdl-company-name "")
9971 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9972
5eabfe72
KH
9973;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9974;; Comment templates and functions
9975
9976(defun vhdl-comment-indent ()
9977 "Indent comments."
9978 (let* ((position (point))
9979 (col
9980 (progn
9981 (forward-line -1)
9982 (if (re-search-forward "--" position t)
9983 (- (current-column) 2) ; existing comment at bol stays there
9984 (goto-char position)
9985 (skip-chars-backward " \t")
9986 (max comment-column ; else indent to comment column
9987 (1+ (current-column))))))) ; except leave at least one space
9988 (goto-char position)
9989 col))
9990
9991(defun vhdl-comment-insert ()
d2ddb974 9992 "Start a comment at the end of the line.
5eabfe72
KH
9993If on line with code, indent at least `comment-column'.
9994If starting after end-comment-column, start a new line."
d2ddb974 9995 (interactive)
5eabfe72
KH
9996 (when (> (current-column) end-comment-column) (newline-and-indent))
9997 (if (or (looking-at "\\s-*$") ; end of line
d2ddb974
KH
9998 (and (not unread-command-events) ; called with key binding or menu
9999 (not (end-of-line))))
5eabfe72
KH
10000 (let (margin)
10001 (while (= (preceding-char) ?-) (delete-char -1))
d2ddb974 10002 (setq margin (current-column))
5eabfe72
KH
10003 (delete-horizontal-space)
10004 (if (bolp)
10005 (progn (indent-to margin) (insert "--"))
d2ddb974 10006 (insert " ")
5eabfe72
KH
10007 (indent-to comment-column)
10008 (insert "--"))
d2ddb974 10009 (if (not unread-command-events) (insert " ")))
5eabfe72 10010 ;; else code following current point implies commenting out code
d2ddb974
KH
10011 (let (next-input code)
10012 (while (= (preceding-char) ?-) (delete-char -2))
10013 (while (= (setq next-input (read-char)) 13) ; CR
5eabfe72 10014 (insert "--") ; or have a space after it?
d2ddb974
KH
10015 (forward-char -2)
10016 (forward-line 1)
10017 (message "Enter CR if commenting out a line of code.")
5eabfe72 10018 (setq code t))
3dcb36b7 10019 (unless code
5eabfe72 10020 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
d2ddb974 10021 (setq unread-command-events
5eabfe72 10022 (list (vhdl-character-to-event next-input)))))) ; pushback the char
d2ddb974 10023
5eabfe72 10024(defun vhdl-comment-display (&optional line-exists)
d2ddb974
KH
10025 "Add 2 comment lines at the current indent, making a display comment."
10026 (interactive)
5eabfe72 10027 (let ((margin (current-indentation)))
3dcb36b7 10028 (unless line-exists (vhdl-comment-display-line))
5eabfe72
KH
10029 (insert "\n") (indent-to margin)
10030 (insert "\n") (indent-to margin)
10031 (vhdl-comment-display-line)
10032 (end-of-line -0)
10033 (insert "-- ")))
10034
10035(defun vhdl-comment-display-line ()
d2ddb974
KH
10036 "Displays one line of dashes."
10037 (interactive)
10038 (while (= (preceding-char) ?-) (delete-char -2))
10039 (let* ((col (current-column))
10040 (len (- end-comment-column col)))
5eabfe72 10041 (insert-char ?- len)))
d2ddb974 10042
5eabfe72
KH
10043(defun vhdl-comment-append-inline ()
10044 "Append empty inline comment to current line."
10045 (interactive)
10046 (end-of-line)
10047 (delete-horizontal-space)
10048 (insert " ")
10049 (indent-to comment-column)
10050 (insert "-- "))
10051
10052(defun vhdl-comment-insert-inline (&optional string always-insert)
10053 "Insert inline comment."
10054 (when (or (and string (or vhdl-self-insert-comments always-insert))
10055 (and (not string) vhdl-prompt-for-comments))
10056 (let ((position (point)))
10057 (insert " ")
10058 (indent-to comment-column)
10059 (insert "-- ")
3dcb36b7
JB
10060 (if (not (or (and string (progn (insert string) t))
10061 (vhdl-template-field "[comment]" nil t)))
10062 (delete-region position (point))
d355a0b7
SM
10063 (while (= (preceding-char) ?\ ) (delete-char -1))
10064 ;; (when (> (current-column) end-comment-column)
10065 ;; (setq position (point-marker))
10066 ;; (re-search-backward "-- ")
10067 ;; (insert "\n")
10068 ;; (indent-to comment-column)
10069 ;; (goto-char position))
3dcb36b7 10070 ))))
5eabfe72
KH
10071
10072(defun vhdl-comment-block ()
10073 "Insert comment for code block."
10074 (when vhdl-prompt-for-comments
3dcb36b7
JB
10075 (let ((final-pos (point-marker)))
10076 (vhdl-prepare-search-2
5eabfe72 10077 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
3dcb36b7 10078 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
5eabfe72
KH
10079 (let (margin)
10080 (back-to-indentation)
10081 (setq margin (current-column))
10082 (end-of-line -0)
10083 (if (bobp)
10084 (progn (insert "\n") (forward-line -1))
10085 (insert "\n"))
10086 (indent-to margin)
10087 (insert "-- purpose: ")
10088 (unless (vhdl-template-field "[description]" nil t)
10089 (vhdl-line-kill-entire)))))
10090 (goto-char final-pos))))
d2ddb974
KH
10091
10092(defun vhdl-comment-uncomment-region (beg end &optional arg)
5eabfe72 10093 "Comment out region if not commented out, uncomment otherwise."
d2ddb974 10094 (interactive "r\nP")
5eabfe72
KH
10095 (save-excursion
10096 (goto-char (1- end))
10097 (end-of-line)
10098 (setq end (point-marker))
10099 (goto-char beg)
10100 (beginning-of-line)
10101 (setq beg (point))
10102 (if (looking-at comment-start)
3dcb36b7 10103 (comment-region beg end '(4))
5eabfe72
KH
10104 (comment-region beg end))))
10105
10106(defun vhdl-comment-uncomment-line (&optional arg)
10107 "Comment out line if not commented out, uncomment otherwise."
d2ddb974 10108 (interactive "p")
5eabfe72
KH
10109 (save-excursion
10110 (beginning-of-line)
10111 (let ((position (point)))
10112 (forward-line (or arg 1))
10113 (vhdl-comment-uncomment-region position (point)))))
d2ddb974 10114
5eabfe72
KH
10115(defun vhdl-comment-kill-region (beg end)
10116 "Kill comments in region."
10117 (interactive "r")
10118 (save-excursion
10119 (goto-char end)
10120 (setq end (point-marker))
10121 (goto-char beg)
10122 (beginning-of-line)
10123 (while (< (point) end)
10124 (if (looking-at "^\\(\\s-*--.*\n\\)")
10125 (progn (delete-region (match-beginning 1) (match-end 1)))
10126 (beginning-of-line 2)))))
10127
10128(defun vhdl-comment-kill-inline-region (beg end)
10129 "Kill inline comments in region."
10130 (interactive "r")
10131 (save-excursion
10132 (goto-char end)
10133 (setq end (point-marker))
10134 (goto-char beg)
10135 (beginning-of-line)
10136 (while (< (point) end)
10137 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10138 (delete-region (match-beginning 1) (match-end 1)))
10139 (beginning-of-line 2))))
10140
10141;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10142;; Subtemplates
10143
10144(defun vhdl-template-begin-end (construct name margin &optional empty-lines)
d2ddb974
KH
10145 "Insert a begin ... end pair with optional name after the end.
10146Point is left between them."
5eabfe72 10147 (let (position)
5eabfe72 10148 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10149 (indent-to margin)
10150 (vhdl-insert-keyword "BEGIN")
5eabfe72
KH
10151 (when (and (or construct name) vhdl-self-insert-comments)
10152 (insert " --")
10153 (when construct (insert " ") (vhdl-insert-keyword construct))
10154 (when name (insert " " name)))
d2ddb974 10155 (insert "\n")
5eabfe72 10156 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974 10157 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
10158 (setq position (point))
10159 (insert "\n")
10160 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10161 (indent-to margin)
10162 (vhdl-insert-keyword "END")
5eabfe72
KH
10163 (when construct (insert " ") (vhdl-insert-keyword construct))
10164 (insert (if name (concat " " name) "") ";")
10165 (goto-char position)))
d2ddb974 10166
5eabfe72 10167(defun vhdl-template-argument-list (&optional is-function)
d2ddb974
KH
10168 "Read from user a procedure or function argument list."
10169 (insert " (")
d2ddb974 10170 (let ((margin (current-column))
5eabfe72
KH
10171 (start (point))
10172 (end-pos (point))
10173 not-empty interface semicolon-pos)
3dcb36b7 10174 (unless vhdl-argument-list-indent
5eabfe72
KH
10175 (setq margin (+ (current-indentation) vhdl-basic-offset))
10176 (insert "\n")
10177 (indent-to margin))
10178 (setq interface (vhdl-template-field
10179 (concat "[CONSTANT | SIGNAL"
10180 (unless is-function " | VARIABLE") "]") " " t))
10181 (while (vhdl-template-field "[names]" nil t)
10182 (setq not-empty t)
10183 (insert " : ")
3dcb36b7 10184 (unless is-function
5eabfe72
KH
10185 (if (and interface (equal (upcase interface) "CONSTANT"))
10186 (vhdl-insert-keyword "IN ")
10187 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10188 (vhdl-template-field "type")
10189 (setq semicolon-pos (point))
10190 (insert ";")
10191 (vhdl-comment-insert-inline)
10192 (setq end-pos (point))
10193 (insert "\n")
10194 (indent-to margin)
10195 (setq interface (vhdl-template-field
10196 (concat "[CONSTANT | SIGNAL"
10197 (unless is-function " | VARIABLE") "]") " " t)))
10198 (delete-region end-pos (point))
10199 (when semicolon-pos (goto-char semicolon-pos))
10200 (if not-empty
10201 (progn (delete-char 1) (insert ")"))
d355a0b7 10202 (delete-char -2))))
5eabfe72
KH
10203
10204(defun vhdl-template-generic-list (optional &optional no-value)
d2ddb974 10205 "Read from user a generic spec argument list."
5eabfe72 10206 (let (margin
d2ddb974 10207 (start (point)))
5eabfe72
KH
10208 (vhdl-insert-keyword "GENERIC (")
10209 (setq margin (current-column))
3dcb36b7 10210 (unless vhdl-argument-list-indent
5eabfe72
KH
10211 (let ((position (point)))
10212 (back-to-indentation)
10213 (setq margin (+ (current-column) vhdl-basic-offset))
10214 (goto-char position)
10215 (insert "\n")
10216 (indent-to margin)))
10217 (let ((vhdl-generics (vhdl-template-field
10218 (concat (and optional "[") "name"
10219 (and no-value "s") (and optional "]"))
10220 nil optional)))
10221 (if (not vhdl-generics)
d2ddb974 10222 (if optional
5eabfe72 10223 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10224 (unless vhdl-argument-list-indent
5eabfe72
KH
10225 (vhdl-line-kill-entire) (end-of-line -0)))
10226 (vhdl-template-undo start (point))
d2ddb974
KH
10227 nil )
10228 (insert " : ")
5eabfe72
KH
10229 (let (semicolon-pos end-pos)
10230 (while vhdl-generics
10231 (vhdl-template-field "type")
10232 (if no-value
10233 (progn (setq semicolon-pos (point))
10234 (insert ";"))
10235 (insert " := ")
10236 (unless (vhdl-template-field "[value]" nil t)
10237 (delete-char -4))
10238 (setq semicolon-pos (point))
10239 (insert ";"))
10240 (vhdl-comment-insert-inline)
10241 (setq end-pos (point))
10242 (insert "\n")
10243 (indent-to margin)
10244 (setq vhdl-generics (vhdl-template-field
10245 (concat "[name" (and no-value "s") "]")
10246 " : " t)))
10247 (delete-region end-pos (point))
10248 (goto-char semicolon-pos)
10249 (insert ")")
10250 (end-of-line)
3dcb36b7 10251 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
10252 t)))))
10253
10254(defun vhdl-template-port-list (optional)
10255 "Read from user a port spec argument list."
10256 (let ((start (point))
10257 margin vhdl-ports object)
10258 (vhdl-insert-keyword "PORT (")
10259 (setq margin (current-column))
3dcb36b7 10260 (unless vhdl-argument-list-indent
5eabfe72
KH
10261 (let ((position (point)))
10262 (back-to-indentation)
10263 (setq margin (+ (current-column) vhdl-basic-offset))
10264 (goto-char position)
10265 (insert "\n")
10266 (indent-to margin)))
10267 (when (vhdl-standard-p 'ams)
10268 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10269 " " t)))
10270 (setq vhdl-ports (vhdl-template-field
10271 (concat (and optional "[") "names" (and optional "]"))
10272 nil optional))
10273 (if (not vhdl-ports)
10274 (if optional
10275 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10276 (unless vhdl-argument-list-indent
5eabfe72
KH
10277 (vhdl-line-kill-entire) (end-of-line -0)))
10278 (vhdl-template-undo start (point))
10279 nil)
10280 (insert " : ")
10281 (let (semicolon-pos end-pos)
10282 (while vhdl-ports
10283 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10284 (vhdl-template-field "IN | OUT | INOUT" " "))
10285 ((equal "QUANTITY" (upcase object))
10286 (vhdl-template-field "[IN | OUT]" " " t)))
10287 (vhdl-template-field
10288 (if (and object (equal "TERMINAL" (upcase object)))
10289 "nature" "type"))
10290 (setq semicolon-pos (point))
10291 (insert ";")
10292 (vhdl-comment-insert-inline)
10293 (setq end-pos (point))
10294 (insert "\n")
10295 (indent-to margin)
10296 (when (vhdl-standard-p 'ams)
10297 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10298 " " t)))
10299 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10300 (delete-region end-pos (point))
10301 (goto-char semicolon-pos)
10302 (insert ")")
10303 (end-of-line)
3dcb36b7 10304 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
5eabfe72
KH
10305 t))))
10306
10307(defun vhdl-template-generate-body (margin label)
10308 "Insert body for generate template."
10309 (vhdl-insert-keyword " GENERATE")
3dcb36b7
JB
10310; (if (not (vhdl-standard-p '87))
10311; (vhdl-template-begin-end "GENERATE" label margin)
10312 (insert "\n\n")
10313 (indent-to margin)
10314 (vhdl-insert-keyword "END GENERATE ")
10315 (insert label ";")
10316 (end-of-line 0)
10317 (indent-to (+ margin vhdl-basic-offset)))
5eabfe72
KH
10318
10319(defun vhdl-template-insert-date ()
d2ddb974
KH
10320 "Insert date in appropriate format."
10321 (interactive)
5eabfe72
KH
10322 (insert
10323 (cond
3dcb36b7 10324 ;; 'american, 'european, 'scientific kept for backward compatibility
5eabfe72
KH
10325 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10326 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10327 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10328 (t (format-time-string vhdl-date-format nil)))))
10329
10330;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10331;; Help functions
10332
10333(defun vhdl-electric-space (count)
10334 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10335if in comment and past end-comment-column."
10336 (interactive "p")
10337 (cond ((vhdl-in-comment-p)
10338 (self-insert-command count)
10339 (cond ((>= (current-column) (+ 2 end-comment-column))
3dcb36b7
JB
10340 (backward-char 1)
10341 (skip-chars-backward "^ \t\n")
5eabfe72 10342 (indent-new-comment-line)
3dcb36b7 10343 (skip-chars-forward "^ \t\n")
5eabfe72
KH
10344 (forward-char 1))
10345 ((>= (current-column) end-comment-column)
10346 (indent-new-comment-line))
10347 (t nil)))
10348 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10349 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
3dcb36b7
JB
10350 (vhdl-prepare-search-1
10351 (or (expand-abbrev) (vhdl-fix-case-word -1)))
5eabfe72
KH
10352 (self-insert-command count))
10353 (t (self-insert-command count))))
10354
10355(defun vhdl-template-field (prompt &optional follow-string optional
10356 begin end is-string default)
10357 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10358If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10359an empty string is inserted, return nil and call `vhdl-template-undo' for
10360the region between BEGIN and END. IS-STRING indicates whether a string
10361with double-quotes is to be inserted. DEFAULT specifies a default string."
10362 (let ((position (point))
10363 string)
10364 (insert "<" prompt ">")
10365 (setq string
10366 (condition-case ()
10367 (read-from-minibuffer (concat prompt ": ")
10368 (or (and is-string '("\"\"" . 2)) default)
10369 vhdl-minibuffer-local-map)
10370 (quit (if (and optional begin end)
10371 (progn (beep) "")
10372 (keyboard-quit)))))
10373 (when (or (not (equal string "")) optional)
10374 (delete-region position (point)))
10375 (when (and (equal string "") optional begin end)
10376 (vhdl-template-undo begin end)
10377 (message "Template aborted"))
3dcb36b7 10378 (unless (equal string "")
5eabfe72
KH
10379 (insert string)
10380 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
3dcb36b7
JB
10381 vhdl-keywords-regexp)
10382 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10383 vhdl-types-regexp)
10384 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10385 (concat "'" vhdl-attributes-regexp))
10386 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10387 vhdl-enum-values-regexp))
5eabfe72
KH
10388 (when (or (not (equal string "")) (not optional))
10389 (insert (or follow-string "")))
10390 (if (equal string "") nil string)))
10391
10392(defun vhdl-decision-query (string prompt &optional optional)
10393 "Query a decision from the user."
10394 (let ((start (point)))
10395 (when string (vhdl-insert-keyword (concat string " ")))
274f1353 10396 (message "%s" (or prompt ""))
5eabfe72
KH
10397 (let ((char (read-char)))
10398 (delete-region start (point))
10399 (if (and optional (eq char ?\r))
10400 (progn (insert " ")
10401 (unexpand-abbrev)
3dcb36b7 10402 (throw 'abort "ERROR: Template aborted"))
5eabfe72 10403 char))))
d2ddb974
KH
10404
10405(defun vhdl-insert-keyword (keyword)
5eabfe72
KH
10406 "Insert KEYWORD and adjust case."
10407 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
d2ddb974
KH
10408
10409(defun vhdl-case-keyword (keyword)
5eabfe72
KH
10410 "Adjust case of KEYWORD."
10411 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
d2ddb974
KH
10412
10413(defun vhdl-case-word (num)
a4c6cfad 10414 "Adjust case of following NUM words."
5eabfe72
KH
10415 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10416
10417(defun vhdl-minibuffer-tab (&optional prefix-arg)
10418 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7 10419else insert tab (used for word completion in VHDL minibuffer)."
5eabfe72 10420 (interactive "P")
3dcb36b7
JB
10421 (cond
10422 ;; expand word
10423 ((= (char-syntax (preceding-char)) ?w)
10424 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10425 (case-replace nil)
10426 (hippie-expand-only-buffers
10427 (or (and (boundp 'hippie-expand-only-buffers)
10428 hippie-expand-only-buffers)
10429 '(vhdl-mode))))
10430 (vhdl-expand-abbrev prefix-arg)))
10431 ;; expand parenthesis
10432 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10433 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10434 (case-replace nil))
10435 (vhdl-expand-paren prefix-arg)))
10436 ;; insert tab
10437 (t (insert-tab))))
5eabfe72
KH
10438
10439(defun vhdl-template-search-prompt ()
10440 "Search for left out template prompts and query again."
10441 (interactive)
3dcb36b7
JB
10442 (vhdl-prepare-search-2
10443 (when (or (re-search-forward
10444 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10445 (re-search-backward
10446 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10447 (let ((string (match-string 1)))
10448 (replace-match "")
10449 (vhdl-template-field string)))))
5eabfe72
KH
10450
10451(defun vhdl-template-undo (begin end)
10452 "Undo aborted template by deleting region and unexpanding the keyword."
10453 (cond (vhdl-template-invoked-by-hook
10454 (goto-char end)
10455 (insert " ")
10456 (delete-region begin end)
10457 (unexpand-abbrev))
10458 (t (delete-region begin end))))
10459
10460(defun vhdl-insert-string-or-file (string)
10461 "Insert STRING or file contents if STRING is an existing file name."
10462 (unless (equal string "")
3dcb36b7
JB
10463 (let ((file-name
10464 (progn (string-match "^\\([^\n]+\\)" string)
10465 (vhdl-resolve-env-variable (match-string 1 string)))))
10466 (if (file-exists-p file-name)
10467 (forward-char (cadr (insert-file-contents file-name)))
10468 (insert string)))))
10469
10470(defun vhdl-beginning-of-block ()
10471 "Move cursor to the beginning of the enclosing block."
10472 (let (pos)
10473 (save-excursion
10474 (beginning-of-line)
10475 ;; search backward for block beginning or end
10476 (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))
10477 ;; not consider subprogram declarations
10478 (or (and (match-string 5)
10479 (save-match-data
10480 (save-excursion
10481 (goto-char (match-end 5))
0a2e512a
RF
10482 (forward-word 1)
10483 (vhdl-forward-syntactic-ws)
10484 (when (looking-at "(")
10485 (forward-sexp))
3dcb36b7
JB
10486 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10487 (match-string 1)))
10488 ;; not consider configuration specifications
10489 (and (match-string 6)
10490 (save-match-data
10491 (save-excursion
10492 (vhdl-end-of-block)
10493 (beginning-of-line)
10494 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10495 (match-string 2))
10496 ;; skip subblock if block end found
10497 (vhdl-beginning-of-block)))
10498 (when pos (goto-char pos))))
10499
10500(defun vhdl-end-of-block ()
10501 "Move cursor to the end of the enclosing block."
10502 (let (pos)
10503 (save-excursion
10504 (end-of-line)
10505 ;; search forward for block beginning or end
10506 (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))
10507 ;; not consider subprogram declarations
10508 (or (and (match-string 5)
10509 (save-match-data
10510 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10511 (match-string 1)))
10512 ;; not consider configuration specifications
10513 (and (match-string 6)
10514 (save-match-data
10515 (save-excursion
10516 (vhdl-end-of-block)
10517 (beginning-of-line)
10518 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10519 (not (match-string 2)))
10520 ;; skip subblock if block beginning found
10521 (vhdl-end-of-block)))
10522 (when pos (goto-char pos))))
5eabfe72
KH
10523
10524(defun vhdl-sequential-statement-p ()
10525 "Check if point is within sequential statement part."
3dcb36b7
JB
10526 (let ((start (point)))
10527 (save-excursion
10528 (vhdl-prepare-search-2
10529 ;; is sequential statement if ...
10530 (and (re-search-backward "^\\s-*begin\\>" nil t)
10531 ;; ... point is between "begin" and "end" of ...
10532 (progn (vhdl-end-of-block)
10533 (< start (point)))
10534 ;; ... a sequential block
10535 (progn (vhdl-beginning-of-block)
10536 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
5eabfe72
KH
10537
10538(defun vhdl-in-argument-list-p ()
10539 "Check if within an argument list."
10540 (save-excursion
3dcb36b7
JB
10541 (vhdl-prepare-search-2
10542 (or (string-match "arglist"
10543 (format "%s" (caar (vhdl-get-syntactic-context))))
10544 (progn (beginning-of-line)
10545 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
5eabfe72
KH
10546
10547;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10548;; Abbrev hooks
10549
10550(defun vhdl-hooked-abbrev (func)
10551 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
a4c6cfad 10552but not if inside a comment or quote."
3dcb36b7 10553 (if (or (vhdl-in-literal)
5eabfe72
KH
10554 (save-excursion
10555 (forward-word -1)
10556 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10557 (progn
10558 (insert " ")
10559 (unexpand-abbrev)
10560 (delete-char -1))
10561 (if (not vhdl-electric-mode)
10562 (progn
10563 (insert " ")
10564 (unexpand-abbrev)
10565 (backward-word 1)
10566 (vhdl-case-word 1)
10567 (delete-char 1))
1ba983e8 10568 (let ((invoke-char last-command-event)
5eabfe72
KH
10569 (abbrev-mode -1)
10570 (vhdl-template-invoked-by-hook t))
10571 (let ((caught (catch 'abort
10572 (funcall func))))
29a4e67d 10573 (when (stringp caught) (message "%s" caught)))
5eabfe72
KH
10574 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10575 ;; delete CR which is still in event queue
4bcb9c95 10576 (if (fboundp 'enqueue-eval-event)
5eabfe72
KH
10577 (enqueue-eval-event 'delete-char -1)
10578 (setq unread-command-events ; push back a delete char
10579 (list (vhdl-character-to-event ?\177))))))))
10580
10581(defun vhdl-template-alias-hook ()
10582 (vhdl-hooked-abbrev 'vhdl-template-alias))
10583(defun vhdl-template-architecture-hook ()
10584 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10585(defun vhdl-template-assert-hook ()
10586 (vhdl-hooked-abbrev 'vhdl-template-assert))
10587(defun vhdl-template-attribute-hook ()
10588 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10589(defun vhdl-template-block-hook ()
10590 (vhdl-hooked-abbrev 'vhdl-template-block))
10591(defun vhdl-template-break-hook ()
10592 (vhdl-hooked-abbrev 'vhdl-template-break))
10593(defun vhdl-template-case-hook ()
10594 (vhdl-hooked-abbrev 'vhdl-template-case))
10595(defun vhdl-template-component-hook ()
10596 (vhdl-hooked-abbrev 'vhdl-template-component))
10597(defun vhdl-template-instance-hook ()
10598 (vhdl-hooked-abbrev 'vhdl-template-instance))
10599(defun vhdl-template-conditional-signal-asst-hook ()
10600 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10601(defun vhdl-template-configuration-hook ()
10602 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10603(defun vhdl-template-constant-hook ()
10604 (vhdl-hooked-abbrev 'vhdl-template-constant))
10605(defun vhdl-template-disconnect-hook ()
10606 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10607(defun vhdl-template-display-comment-hook ()
10608 (vhdl-hooked-abbrev 'vhdl-comment-display))
10609(defun vhdl-template-else-hook ()
10610 (vhdl-hooked-abbrev 'vhdl-template-else))
10611(defun vhdl-template-elsif-hook ()
10612 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10613(defun vhdl-template-entity-hook ()
10614 (vhdl-hooked-abbrev 'vhdl-template-entity))
10615(defun vhdl-template-exit-hook ()
10616 (vhdl-hooked-abbrev 'vhdl-template-exit))
10617(defun vhdl-template-file-hook ()
10618 (vhdl-hooked-abbrev 'vhdl-template-file))
10619(defun vhdl-template-for-hook ()
10620 (vhdl-hooked-abbrev 'vhdl-template-for))
10621(defun vhdl-template-function-hook ()
10622 (vhdl-hooked-abbrev 'vhdl-template-function))
10623(defun vhdl-template-generic-hook ()
10624 (vhdl-hooked-abbrev 'vhdl-template-generic))
10625(defun vhdl-template-group-hook ()
10626 (vhdl-hooked-abbrev 'vhdl-template-group))
10627(defun vhdl-template-library-hook ()
10628 (vhdl-hooked-abbrev 'vhdl-template-library))
10629(defun vhdl-template-limit-hook ()
10630 (vhdl-hooked-abbrev 'vhdl-template-limit))
10631(defun vhdl-template-if-hook ()
10632 (vhdl-hooked-abbrev 'vhdl-template-if))
10633(defun vhdl-template-bare-loop-hook ()
10634 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10635(defun vhdl-template-map-hook ()
10636 (vhdl-hooked-abbrev 'vhdl-template-map))
10637(defun vhdl-template-nature-hook ()
10638 (vhdl-hooked-abbrev 'vhdl-template-nature))
10639(defun vhdl-template-next-hook ()
10640 (vhdl-hooked-abbrev 'vhdl-template-next))
3dcb36b7
JB
10641(defun vhdl-template-others-hook ()
10642 (vhdl-hooked-abbrev 'vhdl-template-others))
5eabfe72
KH
10643(defun vhdl-template-package-hook ()
10644 (vhdl-hooked-abbrev 'vhdl-template-package))
10645(defun vhdl-template-port-hook ()
10646 (vhdl-hooked-abbrev 'vhdl-template-port))
10647(defun vhdl-template-procedural-hook ()
10648 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10649(defun vhdl-template-procedure-hook ()
10650 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10651(defun vhdl-template-process-hook ()
10652 (vhdl-hooked-abbrev 'vhdl-template-process))
10653(defun vhdl-template-quantity-hook ()
10654 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10655(defun vhdl-template-report-hook ()
10656 (vhdl-hooked-abbrev 'vhdl-template-report))
10657(defun vhdl-template-return-hook ()
10658 (vhdl-hooked-abbrev 'vhdl-template-return))
10659(defun vhdl-template-selected-signal-asst-hook ()
10660 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10661(defun vhdl-template-signal-hook ()
10662 (vhdl-hooked-abbrev 'vhdl-template-signal))
10663(defun vhdl-template-subnature-hook ()
10664 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10665(defun vhdl-template-subtype-hook ()
10666 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10667(defun vhdl-template-terminal-hook ()
10668 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10669(defun vhdl-template-type-hook ()
10670 (vhdl-hooked-abbrev 'vhdl-template-type))
10671(defun vhdl-template-use-hook ()
10672 (vhdl-hooked-abbrev 'vhdl-template-use))
10673(defun vhdl-template-variable-hook ()
10674 (vhdl-hooked-abbrev 'vhdl-template-variable))
10675(defun vhdl-template-wait-hook ()
10676 (vhdl-hooked-abbrev 'vhdl-template-wait))
10677(defun vhdl-template-when-hook ()
10678 (vhdl-hooked-abbrev 'vhdl-template-when))
10679(defun vhdl-template-while-loop-hook ()
10680 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10681(defun vhdl-template-with-hook ()
10682 (vhdl-hooked-abbrev 'vhdl-template-with))
10683(defun vhdl-template-and-hook ()
10684 (vhdl-hooked-abbrev 'vhdl-template-and))
10685(defun vhdl-template-or-hook ()
10686 (vhdl-hooked-abbrev 'vhdl-template-or))
10687(defun vhdl-template-nand-hook ()
10688 (vhdl-hooked-abbrev 'vhdl-template-nand))
10689(defun vhdl-template-nor-hook ()
10690 (vhdl-hooked-abbrev 'vhdl-template-nor))
10691(defun vhdl-template-xor-hook ()
10692 (vhdl-hooked-abbrev 'vhdl-template-xor))
10693(defun vhdl-template-xnor-hook ()
10694 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10695(defun vhdl-template-not-hook ()
10696 (vhdl-hooked-abbrev 'vhdl-template-not))
10697
10698(defun vhdl-template-default-hook ()
10699 (vhdl-hooked-abbrev 'vhdl-template-default))
10700(defun vhdl-template-default-indent-hook ()
10701 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10702
10703;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10704;; Template insertion from completion list
10705
10706(defun vhdl-template-insert-construct (name)
10707 "Insert the built-in construct template with NAME."
10708 (interactive
10709 (list (let ((completion-ignore-case t))
10710 (completing-read "Construct name: "
10711 vhdl-template-construct-alist nil t))))
10712 (vhdl-template-insert-fun
3dcb36b7 10713 (cadr (assoc name vhdl-template-construct-alist))))
5eabfe72
KH
10714
10715(defun vhdl-template-insert-package (name)
10716 "Insert the built-in package template with NAME."
10717 (interactive
10718 (list (let ((completion-ignore-case t))
10719 (completing-read "Package name: "
10720 vhdl-template-package-alist nil t))))
10721 (vhdl-template-insert-fun
3dcb36b7 10722 (cadr (assoc name vhdl-template-package-alist))))
5eabfe72
KH
10723
10724(defun vhdl-template-insert-directive (name)
10725 "Insert the built-in directive template with NAME."
10726 (interactive
10727 (list (let ((completion-ignore-case t))
10728 (completing-read "Directive name: "
10729 vhdl-template-directive-alist nil t))))
10730 (vhdl-template-insert-fun
3dcb36b7 10731 (cadr (assoc name vhdl-template-directive-alist))))
5eabfe72
KH
10732
10733(defun vhdl-template-insert-fun (fun)
10734 "Call FUN to insert a built-in template."
10735 (let ((caught (catch 'abort (when fun (funcall fun)))))
29a4e67d 10736 (when (stringp caught) (message "%s" caught))))
5eabfe72
KH
10737
10738
10739;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10740;;; Models
10741;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10742
10743(defun vhdl-model-insert (model-name)
10744 "Insert the user model with name MODEL-NAME."
10745 (interactive
10746 (let ((completion-ignore-case t))
10747 (list (completing-read "Model name: " vhdl-model-alist))))
3dcb36b7 10748 (indent-according-to-mode)
5eabfe72
KH
10749 (let ((start (point-marker))
10750 (margin (current-indentation))
5eabfe72 10751 model position prompt string end)
3dcb36b7 10752 (vhdl-prepare-search-2
5eabfe72
KH
10753 (when (setq model (assoc model-name vhdl-model-alist))
10754 ;; insert model
10755 (beginning-of-line)
10756 (delete-horizontal-space)
10757 (goto-char start)
10758 (vhdl-insert-string-or-file (nth 1 model))
10759 (setq end (point-marker))
10760 ;; indent code
10761 (goto-char start)
10762 (beginning-of-line)
10763 (while (< (point) end)
10764 (unless (looking-at "^$")
10765 (insert-char ? margin))
10766 (beginning-of-line 2))
10767 (goto-char start)
10768 ;; insert clock
10769 (unless (equal "" vhdl-clock-name)
10770 (while (re-search-forward "<clock>" end t)
10771 (replace-match vhdl-clock-name)))
10772 (goto-char start)
10773 ;; insert reset
10774 (unless (equal "" vhdl-reset-name)
10775 (while (re-search-forward "<reset>" end t)
10776 (replace-match vhdl-reset-name)))
3dcb36b7
JB
10777 ;; replace header prompts
10778 (vhdl-template-replace-header-keywords start end nil t)
5eabfe72 10779 (goto-char start)
3dcb36b7 10780 ;; query other prompts
5eabfe72
KH
10781 (while (re-search-forward
10782 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10783 (unless (equal "cursor" (match-string 1))
10784 (setq position (match-beginning 1))
10785 (setq prompt (match-string 1))
10786 (replace-match "")
10787 (setq string (vhdl-template-field prompt nil t))
a5a08b1f 10788 ;; replace occurrences of same prompt
5eabfe72
KH
10789 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10790 (replace-match (or string "")))
10791 (goto-char position)))
10792 (goto-char start)
10793 ;; goto final position
10794 (if (re-search-forward "<cursor>" end t)
10795 (replace-match "")
10796 (goto-char end))))))
10797
10798(defun vhdl-model-defun ()
10799 "Define help and hook functions for user models."
10800 (let ((model-alist vhdl-model-alist)
10801 model-name model-keyword)
10802 (while model-alist
10803 ;; define functions for user models that can be invoked from menu and key
10804 ;; bindings and which themselves call `vhdl-model-insert' with the model
10805 ;; name as argument
10806 (setq model-name (nth 0 (car model-alist)))
d4a5b644
GM
10807 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10808 ,(concat "Insert model for \"" model-name "\".")
10809 (interactive)
10810 (vhdl-model-insert ,model-name)))
5eabfe72
KH
10811 ;; define hooks for user models that are invoked from keyword abbrevs
10812 (setq model-keyword (nth 3 (car model-alist)))
10813 (unless (equal model-keyword "")
d4a5b644
GM
10814 (eval `(defun
10815 ,(vhdl-function-name
10816 "vhdl-model" model-name "hook") ()
10817 (vhdl-hooked-abbrev
10818 ',(vhdl-function-name "vhdl-model" model-name)))))
5eabfe72
KH
10819 (setq model-alist (cdr model-alist)))))
10820
10821(vhdl-model-defun)
10822
10823
10824;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10825;;; Port translation
10826;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10827
10828(defvar vhdl-port-list nil
3dcb36b7 10829 "Variable to hold last port map parsed.")
5eabfe72 10830;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
10831;; (ent-name
10832;; ((generic-names) generic-type generic-init generic-comment group-comment)
10833;; ((port-names) port-object port-direct port-type port-comment group-comment)
10834;; (lib-name pack-key))
5eabfe72
KH
10835
10836(defun vhdl-parse-string (string &optional optional)
3dcb36b7 10837 "Check that the text following point matches the regexp in STRING."
5eabfe72 10838 (if (looking-at string)
3dcb36b7 10839 (goto-char (match-end 0))
5eabfe72 10840 (unless optional
3dcb36b7
JB
10841 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10842 (vhdl-current-line) string)))
5eabfe72
KH
10843 nil))
10844
0a2e512a 10845(defun vhdl-replace-string (regexp-cons string &optional adjust-case)
5eabfe72 10846 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
3dcb36b7 10847 (vhdl-prepare-search-1
5eabfe72 10848 (if (string-match (car regexp-cons) string)
0a2e512a
RF
10849 (if adjust-case
10850 (funcall vhdl-file-name-case
10851 (replace-match (cdr regexp-cons) t nil string))
10852 (replace-match (cdr regexp-cons) t nil string))
5eabfe72
KH
10853 string)))
10854
3dcb36b7
JB
10855(defun vhdl-parse-group-comment ()
10856 "Parse comment and empty lines between groups of lines."
10857 (let ((start (point))
10858 string)
10859 (vhdl-forward-comment (point-max))
10860 (setq string (buffer-substring-no-properties start (point)))
0a2e512a 10861 (vhdl-forward-syntactic-ws)
3dcb36b7
JB
10862 ;; strip off leading blanks and first newline
10863 (while (string-match "^\\(\\s-+\\)" string)
10864 (setq string (concat (substring string 0 (match-beginning 1))
10865 (substring string (match-end 1)))))
10866 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10867 (substring string 1)
10868 string)))
10869
10870(defun vhdl-paste-group-comment (string indent)
10871 "Paste comment and empty lines from STRING between groups of lines
10872with INDENT."
10873 (let ((pos (point-marker)))
10874 (when (> indent 0)
10875 (while (string-match "^\\(--\\)" string)
10876 (setq string (concat (substring string 0 (match-beginning 1))
10877 (make-string indent ? )
10878 (substring string (match-beginning 1))))))
10879 (beginning-of-line)
10880 (insert string)
10881 (goto-char pos)))
10882
10883(defvar vhdl-port-flattened nil
10884 "Indicates whether a port has been flattened.")
10885
10886(defun vhdl-port-flatten (&optional as-alist)
0a2e512a
RF
10887 "Flatten port list so that only one generic/port exists per line.
10888This operation is performed on an internally stored port and is only
10889reflected in a subsequent paste operation."
5eabfe72
KH
10890 (interactive)
10891 (if (not vhdl-port-list)
3dcb36b7 10892 (error "ERROR: No port has been read")
0a2e512a 10893 (message "Flattening port for next paste...")
5eabfe72
KH
10894 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10895 (old-vhdl-port-list (cdr vhdl-port-list))
10896 old-port-list new-port-list old-port new-port names)
10897 ;; traverse port list and flatten entries
3dcb36b7 10898 (while (cdr old-vhdl-port-list)
5eabfe72
KH
10899 (setq old-port-list (car old-vhdl-port-list))
10900 (setq new-port-list nil)
10901 (while old-port-list
10902 (setq old-port (car old-port-list))
10903 (setq names (car old-port))
10904 (while names
3dcb36b7
JB
10905 (setq new-port (cons (if as-alist (car names) (list (car names)))
10906 (cdr old-port)))
5eabfe72
KH
10907 (setq new-port-list (append new-port-list (list new-port)))
10908 (setq names (cdr names)))
10909 (setq old-port-list (cdr old-port-list)))
10910 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10911 (setq new-vhdl-port-list (append new-vhdl-port-list
10912 (list new-port-list))))
3dcb36b7
JB
10913 (setq vhdl-port-list
10914 (append new-vhdl-port-list (list old-vhdl-port-list))
10915 vhdl-port-flattened t)
0a2e512a 10916 (message "Flattening port for next paste...done"))))
5eabfe72 10917
3dcb36b7
JB
10918(defvar vhdl-port-reversed-direction nil
10919 "Indicates whether port directions are reversed.")
10920
10921(defun vhdl-port-reverse-direction ()
0a2e512a
RF
10922 "Reverse direction for all ports (useful in testbenches).
10923This operation is performed on an internally stored port and is only
10924reflected in a subsequent paste operation."
3dcb36b7
JB
10925 (interactive)
10926 (if (not vhdl-port-list)
10927 (error "ERROR: No port has been read")
0a2e512a 10928 (message "Reversing port directions for next paste...")
3dcb36b7
JB
10929 (let ((port-list (nth 2 vhdl-port-list))
10930 port-dir-car port-dir)
10931 ;; traverse port list and reverse directions
10932 (while port-list
10933 (setq port-dir-car (cddr (car port-list))
10934 port-dir (car port-dir-car))
10935 (setcar port-dir-car
10936 (cond ((equal port-dir "in") "out")
10937 ((equal port-dir "out") "in")
10938 (t port-dir)))
10939 (setq port-list (cdr port-list)))
10940 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
0a2e512a 10941 (message "Reversing port directions for next paste...done"))))
3dcb36b7 10942
5eabfe72
KH
10943(defun vhdl-port-copy ()
10944 "Get generic and port information from an entity or component declaration."
10945 (interactive)
5eabfe72 10946 (save-excursion
3dcb36b7
JB
10947 (let (parse-error end-of-list
10948 decl-type name generic-list port-list context-clause
10949 object names direct type init comment group-comment)
10950 (vhdl-prepare-search-2
5eabfe72
KH
10951 (setq
10952 parse-error
10953 (catch 'parse
10954 ;; check if within entity or component declaration
3dcb36b7 10955 (end-of-line)
5eabfe72
KH
10956 (when (or (not (re-search-backward
10957 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
3dcb36b7
JB
10958 (equal "END" (upcase (match-string 1))))
10959 (throw 'parse "ERROR: Not within an entity or component declaration"))
10960 (setq decl-type (downcase (match-string-no-properties 1)))
5eabfe72 10961 (forward-word 1)
3dcb36b7
JB
10962 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10963 (setq name (match-string-no-properties 1))
10964 (message "Reading port of %s \"%s\"..." decl-type name)
5eabfe72
KH
10965 (vhdl-forward-syntactic-ws)
10966 ;; parse generic clause
10967 (when (vhdl-parse-string "generic[ \t\n]*(" t)
3dcb36b7
JB
10968 ;; parse group comment and spacing
10969 (setq group-comment (vhdl-parse-group-comment))
10970 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72 10971 (while (not end-of-list)
0a2e512a
RF
10972 ;; parse names (accept extended identifiers)
10973 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
3dcb36b7 10974 (setq names (list (match-string-no-properties 1)))
5eabfe72 10975 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
3dcb36b7
JB
10976 (setq names
10977 (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
10978 ;; parse type
10979 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
3dcb36b7 10980 (setq type (match-string-no-properties 1))
5eabfe72
KH
10981 (setq comment nil)
10982 (while (looking-at "(")
10983 (setq type
10984 (concat type
3dcb36b7 10985 (buffer-substring-no-properties
5eabfe72
KH
10986 (point) (progn (forward-sexp) (point)))
10987 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
3dcb36b7 10988 (match-string-no-properties 1)))))
5eabfe72
KH
10989 ;; special case: closing parenthesis is on separate line
10990 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10991 (setq comment (substring type (match-beginning 2)))
10992 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 10993 ;; strip of trailing group-comment
5eabfe72
KH
10994 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10995 (setq type (substring type 0 (match-end 1)))
10996 ;; parse initialization expression
10997 (setq init nil)
10998 (when (vhdl-parse-string ":=[ \t\n]*" t)
10999 (vhdl-parse-string "\\([^();\n]*\\)")
3dcb36b7 11000 (setq init (match-string-no-properties 1))
5eabfe72
KH
11001 (while (looking-at "(")
11002 (setq init
11003 (concat init
3dcb36b7 11004 (buffer-substring-no-properties
5eabfe72
KH
11005 (point) (progn (forward-sexp) (point)))
11006 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 11007 (match-string-no-properties 1))))))
5eabfe72
KH
11008 ;; special case: closing parenthesis is on separate line
11009 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11010 (setq comment (substring init (match-beginning 2)))
11011 (setq init (substring init 0 (match-beginning 1)))
11012 (vhdl-forward-syntactic-ws))
11013 (skip-chars-forward " \t")
11014 ;; parse inline comment, special case: as above, no initial.
11015 (unless comment
11016 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11017 (match-string-no-properties 1))))
5eabfe72
KH
11018 (vhdl-forward-syntactic-ws)
11019 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11020 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11021 ;; parse inline comment
11022 (unless comment
11023 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11024 (match-string-no-properties 1))))
5eabfe72 11025 ;; save everything in list
3dcb36b7
JB
11026 (setq generic-list (append generic-list
11027 (list (list names type init
11028 comment group-comment))))
11029 ;; parse group comment and spacing
11030 (setq group-comment (vhdl-parse-group-comment))))
5eabfe72
KH
11031 ;; parse port clause
11032 (when (vhdl-parse-string "port[ \t\n]*(" t)
3dcb36b7
JB
11033 ;; parse group comment and spacing
11034 (setq group-comment (vhdl-parse-group-comment))
11035 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
11036 (while (not end-of-list)
11037 ;; parse object
11038 (setq object
0a2e512a 11039 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
3dcb36b7
JB
11040 (match-string-no-properties 1)))
11041 ;; parse names (accept extended identifiers)
11042 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11043 (setq names (list (match-string-no-properties 1)))
11044 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11045 (setq names (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
11046 ;; parse direction
11047 (vhdl-parse-string ":[ \t\n]*")
11048 (setq direct
0a2e512a 11049 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
3dcb36b7 11050 (match-string-no-properties 1)))
5eabfe72
KH
11051 ;; parse type
11052 (vhdl-parse-string "\\([^();\n]+\\)")
3dcb36b7 11053 (setq type (match-string-no-properties 1))
5eabfe72
KH
11054 (setq comment nil)
11055 (while (looking-at "(")
11056 (setq type (concat type
3dcb36b7 11057 (buffer-substring-no-properties
5eabfe72
KH
11058 (point) (progn (forward-sexp) (point)))
11059 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 11060 (match-string-no-properties 1)))))
5eabfe72 11061 ;; special case: closing parenthesis is on separate line
3dcb36b7 11062 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
5eabfe72
KH
11063 (setq comment (substring type (match-beginning 2)))
11064 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 11065 ;; strip of trailing group-comment
5eabfe72
KH
11066 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11067 (setq type (substring type 0 (match-end 1)))
11068 (vhdl-forward-syntactic-ws)
11069 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11070 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11071 ;; parse inline comment
11072 (unless comment
11073 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11074 (match-string-no-properties 1))))
5eabfe72 11075 ;; save everything in list
3dcb36b7
JB
11076 (setq port-list (append port-list
11077 (list (list names object direct type
11078 comment group-comment))))
11079 ;; parse group comment and spacing
11080 (setq group-comment (vhdl-parse-group-comment))))
11081; (vhdl-parse-string "end\\>")
11082 ;; parse context clause
11083 (setq context-clause (vhdl-scan-context-clause))
11084; ;; add surrounding package to context clause
11085; (when (and (equal decl-type "component")
11086; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11087; (setq context-clause
11088; (append context-clause
11089; (list (cons (vhdl-work-library)
11090; (match-string-no-properties 1))))))
11091 (message "Reading port of %s \"%s\"...done" decl-type name)
5eabfe72
KH
11092 nil)))
11093 ;; finish parsing
11094 (if parse-error
11095 (error parse-error)
3dcb36b7
JB
11096 (setq vhdl-port-list (list name generic-list port-list context-clause)
11097 vhdl-port-reversed-direction nil
11098 vhdl-port-flattened nil)))))
11099
11100(defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11101 "Paste a context clause."
11102 (let ((margin (current-indentation))
11103 (clause-list (nth 3 vhdl-port-list))
11104 clause)
11105 (while clause-list
11106 (setq clause (car clause-list))
11107 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11108 (downcase exclude-pack-name)))
11109 (save-excursion
11110 (re-search-backward
11111 (concat "^\\s-*use\\s-+" (car clause)
11112 "\." (cdr clause) "\\>") nil t)))
11113 (vhdl-template-standard-package (car clause) (cdr clause))
11114 (insert "\n"))
11115 (setq clause-list (cdr clause-list)))))
5eabfe72
KH
11116
11117(defun vhdl-port-paste-generic (&optional no-init)
11118 "Paste a generic clause."
11119 (let ((margin (current-indentation))
3dcb36b7
JB
11120 (generic-list (nth 1 vhdl-port-list))
11121 list-margin start names generic)
5eabfe72 11122 ;; paste generic clause
3dcb36b7 11123 (when generic-list
5eabfe72
KH
11124 (setq start (point))
11125 (vhdl-insert-keyword "GENERIC (")
11126 (unless vhdl-argument-list-indent
11127 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11128 (setq list-margin (current-column))
3dcb36b7
JB
11129 (while generic-list
11130 (setq generic (car generic-list))
11131 ;; paste group comment and spacing
11132 (when (memq vhdl-include-group-comments '(decl always))
11133 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72 11134 ;; paste names
5eabfe72
KH
11135 (setq names (nth 0 generic))
11136 (while names
11137 (insert (car names))
11138 (setq names (cdr names))
11139 (when names (insert ", ")))
11140 ;; paste type
11141 (insert " : " (nth 1 generic))
11142 ;; paste initialization
11143 (when (and (not no-init) (nth 2 generic))
11144 (insert " := " (nth 2 generic)))
3dcb36b7 11145 (unless (cdr generic-list) (insert ")"))
5eabfe72
KH
11146 (insert ";")
11147 ;; paste comment
11148 (when (and vhdl-include-port-comments (nth 3 generic))
11149 (vhdl-comment-insert-inline (nth 3 generic) t))
3dcb36b7
JB
11150 (setq generic-list (cdr generic-list))
11151 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72 11152 ;; align generic clause
3dcb36b7 11153 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
5eabfe72
KH
11154
11155(defun vhdl-port-paste-port ()
11156 "Paste a port clause."
11157 (let ((margin (current-indentation))
3dcb36b7
JB
11158 (port-list (nth 2 vhdl-port-list))
11159 list-margin start names port)
5eabfe72 11160 ;; paste port clause
3dcb36b7 11161 (when port-list
5eabfe72
KH
11162 (setq start (point))
11163 (vhdl-insert-keyword "PORT (")
11164 (unless vhdl-argument-list-indent
11165 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11166 (setq list-margin (current-column))
3dcb36b7
JB
11167 (while port-list
11168 (setq port (car port-list))
11169 ;; paste group comment and spacing
11170 (when (memq vhdl-include-group-comments '(decl always))
11171 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11172 ;; paste object
11173 (when (nth 1 port) (insert (nth 1 port) " "))
11174 ;; paste names
11175 (setq names (nth 0 port))
11176 (while names
11177 (insert (car names))
11178 (setq names (cdr names))
11179 (when names (insert ", ")))
11180 ;; paste direction
11181 (insert " : ")
11182 (when (nth 2 port) (insert (nth 2 port) " "))
11183 ;; paste type
11184 (insert (nth 3 port))
3dcb36b7 11185 (unless (cdr port-list) (insert ")"))
5eabfe72
KH
11186 (insert ";")
11187 ;; paste comment
11188 (when (and vhdl-include-port-comments (nth 4 port))
11189 (vhdl-comment-insert-inline (nth 4 port) t))
3dcb36b7
JB
11190 (setq port-list (cdr port-list))
11191 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72 11192 ;; align port clause
3dcb36b7 11193 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
5eabfe72 11194
3dcb36b7 11195(defun vhdl-port-paste-declaration (kind &optional no-indent)
5eabfe72 11196 "Paste as an entity or component declaration."
3dcb36b7 11197 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11198 (let ((margin (current-indentation))
11199 (name (nth 0 vhdl-port-list)))
11200 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11201 (insert name)
3dcb36b7
JB
11202 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11203 (vhdl-insert-keyword " IS"))
11204 ;; paste generic and port clause
5eabfe72
KH
11205 (when (nth 1 vhdl-port-list)
11206 (insert "\n")
11207 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11208 (insert "\n"))
11209 (indent-to (+ margin vhdl-basic-offset))
11210 (vhdl-port-paste-generic (eq kind 'component)))
11211 (when (nth 2 vhdl-port-list)
11212 (insert "\n")
11213 (when (and (memq vhdl-insert-empty-lines '(unit all))
11214 (eq kind 'entity))
11215 (insert "\n"))
11216 (indent-to (+ margin vhdl-basic-offset)))
11217 (vhdl-port-paste-port)
11218 (insert "\n")
11219 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11220 (insert "\n"))
11221 (indent-to margin)
11222 (vhdl-insert-keyword "END")
11223 (if (eq kind 'entity)
11224 (progn
11225 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11226 (insert " " name))
11227 (vhdl-insert-keyword " COMPONENT")
11228 (unless (vhdl-standard-p '87) (insert " " name)))
11229 (insert ";")))
11230
3dcb36b7 11231(defun vhdl-port-paste-entity (&optional no-indent)
5eabfe72
KH
11232 "Paste as an entity declaration."
11233 (interactive)
11234 (if (not vhdl-port-list)
3dcb36b7
JB
11235 (error "ERROR: No port read")
11236 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11237 (vhdl-port-paste-declaration 'entity no-indent)
11238 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
5eabfe72 11239
3dcb36b7 11240(defun vhdl-port-paste-component (&optional no-indent)
5eabfe72
KH
11241 "Paste as a component declaration."
11242 (interactive)
11243 (if (not vhdl-port-list)
3dcb36b7
JB
11244 (error "ERROR: No port read")
11245 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11246 (vhdl-port-paste-declaration 'component no-indent)
11247 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
5eabfe72
KH
11248
11249(defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11250 "Paste as a generic map."
11251 (interactive)
3dcb36b7 11252 (unless secondary (indent-according-to-mode))
5eabfe72
KH
11253 (let ((margin (current-indentation))
11254 list-margin start generic
3dcb36b7
JB
11255 (generic-list (nth 1 vhdl-port-list)))
11256 (when generic-list
5eabfe72
KH
11257 (setq start (point))
11258 (vhdl-insert-keyword "GENERIC MAP (")
11259 (if (not vhdl-association-list-with-formals)
11260 ;; paste list of actual generics
3dcb36b7
JB
11261 (while generic-list
11262 (insert (if no-constants
11263 (car (nth 0 (car generic-list)))
11264 (or (nth 2 (car generic-list)) " ")))
11265 (setq generic-list (cdr generic-list))
0a2e512a
RF
11266 (insert (if generic-list ", " ")"))
11267 (when (and (not generic-list) secondary
11268 (null (nth 2 vhdl-port-list)))
11269 (insert ";")))
5eabfe72 11270 (unless vhdl-argument-list-indent
3dcb36b7 11271 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11272 (setq list-margin (current-column))
3dcb36b7
JB
11273 (while generic-list
11274 (setq generic (car generic-list))
11275 ;; paste group comment and spacing
11276 (when (eq vhdl-include-group-comments 'always)
11277 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72
KH
11278 ;; paste formal and actual generic
11279 (insert (car (nth 0 generic)) " => "
11280 (if no-constants
11281 (car (nth 0 generic))
11282 (or (nth 2 generic) "")))
3dcb36b7
JB
11283 (setq generic-list (cdr generic-list))
11284 (insert (if generic-list "," ")"))
0a2e512a
RF
11285 (when (and (not generic-list) secondary
11286 (null (nth 2 vhdl-port-list)))
11287 (insert ";"))
5eabfe72 11288 ;; paste comment
3dcb36b7
JB
11289 (when (or vhdl-include-type-comments
11290 (and vhdl-include-port-comments (nth 3 generic)))
11291 (vhdl-comment-insert-inline
11292 (concat
11293 (when vhdl-include-type-comments
11294 (concat "[" (nth 1 generic) "] "))
11295 (when vhdl-include-port-comments (nth 3 generic))) t))
11296 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11297 ;; align generic map
11298 (when vhdl-auto-align
3dcb36b7 11299 (vhdl-align-region-groups start (point) 1 t))))))
5eabfe72
KH
11300
11301(defun vhdl-port-paste-port-map ()
11302 "Paste as a port map."
11303 (let ((margin (current-indentation))
11304 list-margin start port
3dcb36b7
JB
11305 (port-list (nth 2 vhdl-port-list)))
11306 (when port-list
5eabfe72
KH
11307 (setq start (point))
11308 (vhdl-insert-keyword "PORT MAP (")
11309 (if (not vhdl-association-list-with-formals)
11310 ;; paste list of actual ports
3dcb36b7 11311 (while port-list
5eabfe72 11312 (insert (vhdl-replace-string vhdl-actual-port-name
3dcb36b7
JB
11313 (car (nth 0 (car port-list)))))
11314 (setq port-list (cdr port-list))
0a2e512a 11315 (insert (if port-list ", " ")")))
5eabfe72 11316 (unless vhdl-argument-list-indent
3dcb36b7 11317 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11318 (setq list-margin (current-column))
3dcb36b7
JB
11319 (while port-list
11320 (setq port (car port-list))
11321 ;; paste group comment and spacing
11322 (when (eq vhdl-include-group-comments 'always)
11323 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11324 ;; paste formal and actual port
11325 (insert (car (nth 0 port)) " => ")
11326 (insert (vhdl-replace-string vhdl-actual-port-name
11327 (car (nth 0 port))))
3dcb36b7
JB
11328 (setq port-list (cdr port-list))
11329 (insert (if port-list "," ");"))
5eabfe72
KH
11330 ;; paste comment
11331 (when (or vhdl-include-direction-comments
3dcb36b7 11332 vhdl-include-type-comments
5eabfe72
KH
11333 (and vhdl-include-port-comments (nth 4 port)))
11334 (vhdl-comment-insert-inline
11335 (concat
3dcb36b7
JB
11336 (cond ((and vhdl-include-direction-comments
11337 vhdl-include-type-comments)
11338 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11339 (nth 3 port) "] "))
11340 ((and vhdl-include-direction-comments (nth 2 port))
11341 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11342 (vhdl-include-direction-comments " ")
11343 (vhdl-include-type-comments
11344 (concat "[" (nth 3 port) "] ")))
11345 (when vhdl-include-port-comments (nth 4 port))) t))
11346 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11347 ;; align port clause
11348 (when vhdl-auto-align
3dcb36b7 11349 (vhdl-align-region-groups start (point) 1))))))
5eabfe72 11350
3dcb36b7 11351(defun vhdl-port-paste-instance (&optional name no-indent title)
5eabfe72
KH
11352 "Paste as an instantiation."
11353 (interactive)
11354 (if (not vhdl-port-list)
3dcb36b7 11355 (error "ERROR: No port read")
5eabfe72
KH
11356 (let ((orig-vhdl-port-list vhdl-port-list))
11357 ;; flatten local copy of port list (must be flat for port mapping)
11358 (vhdl-port-flatten)
3dcb36b7
JB
11359 (unless no-indent (indent-according-to-mode))
11360 (let ((margin (current-indentation)))
5eabfe72 11361 ;; paste instantiation
3dcb36b7
JB
11362 (cond (name
11363 (insert name))
11364 ((equal (cdr vhdl-instance-name) "")
11365 (setq name (vhdl-template-field "instance name")))
11366 ((string-match "\%d" (cdr vhdl-instance-name))
11367 (let ((n 1))
11368 (while (save-excursion
11369 (setq name (format (vhdl-replace-string
11370 vhdl-instance-name
11371 (nth 0 vhdl-port-list)) n))
11372 (goto-char (point-min))
11373 (vhdl-re-search-forward name nil t))
11374 (setq n (1+ n)))
11375 (insert name)))
11376 (t (insert (vhdl-replace-string vhdl-instance-name
11377 (nth 0 vhdl-port-list)))))
11378 (message "Pasting port as instantiation \"%s\"..." name)
11379 (insert ": ")
11380 (when title
11381 (save-excursion
11382 (beginning-of-line)
11383 (indent-to vhdl-basic-offset)
11384 (insert "-- instance \"" name "\"\n")))
11385 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
11386 (insert (nth 0 vhdl-port-list))
11387 (vhdl-insert-keyword "ENTITY ")
3dcb36b7 11388 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
5eabfe72
KH
11389 (when (nth 1 vhdl-port-list)
11390 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11391 (vhdl-port-paste-generic-map t t))
11392 (when (nth 2 vhdl-port-list)
11393 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11394 (vhdl-port-paste-port-map))
0a2e512a
RF
11395 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11396 (insert ";"))
3dcb36b7
JB
11397 (message "Pasting port as instantiation \"%s\"...done" name))
11398 (setq vhdl-port-list orig-vhdl-port-list))))
11399
11400(defun vhdl-port-paste-constants (&optional no-indent)
11401 "Paste generics as constants."
11402 (interactive)
11403 (if (not vhdl-port-list)
11404 (error "ERROR: No port read")
11405 (let ((orig-vhdl-port-list vhdl-port-list))
11406 (message "Pasting port as constants...")
11407 ;; flatten local copy of port list (must be flat for constant initial.)
11408 (vhdl-port-flatten)
11409 (unless no-indent (indent-according-to-mode))
11410 (let ((margin (current-indentation))
11411 start generic name
11412 (generic-list (nth 1 vhdl-port-list)))
11413 (when generic-list
11414 (setq start (point))
11415 (while generic-list
11416 (setq generic (car generic-list))
11417 ;; paste group comment and spacing
11418 (when (memq vhdl-include-group-comments '(decl always))
11419 (vhdl-paste-group-comment (nth 4 generic) margin))
11420 (vhdl-insert-keyword "CONSTANT ")
11421 ;; paste generic constants
11422 (setq name (nth 0 generic))
11423 (when name
11424 (insert (car name))
11425 ;; paste type
11426 (insert " : " (nth 1 generic))
11427 ;; paste initialization
11428 (when (nth 2 generic)
11429 (insert " := " (nth 2 generic)))
11430 (insert ";")
11431 ;; paste comment
11432 (when (and vhdl-include-port-comments (nth 3 generic))
11433 (vhdl-comment-insert-inline (nth 3 generic) t))
11434 (setq generic-list (cdr generic-list))
11435 (when generic-list (insert "\n") (indent-to margin))))
11436 ;; align signal list
11437 (when vhdl-auto-align
11438 (vhdl-align-region-groups start (point) 1))))
11439 (message "Pasting port as constants...done")
5eabfe72
KH
11440 (setq vhdl-port-list orig-vhdl-port-list))))
11441
3dcb36b7 11442(defun vhdl-port-paste-signals (&optional initialize no-indent)
5eabfe72
KH
11443 "Paste ports as internal signals."
11444 (interactive)
11445 (if (not vhdl-port-list)
3dcb36b7 11446 (error "ERROR: No port read")
5eabfe72 11447 (message "Pasting port as signals...")
3dcb36b7 11448 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11449 (let ((margin (current-indentation))
11450 start port names
3dcb36b7
JB
11451 (port-list (nth 2 vhdl-port-list)))
11452 (when port-list
5eabfe72 11453 (setq start (point))
3dcb36b7
JB
11454 (while port-list
11455 (setq port (car port-list))
11456 ;; paste group comment and spacing
11457 (when (memq vhdl-include-group-comments '(decl always))
11458 (vhdl-paste-group-comment (nth 5 port) margin))
5eabfe72
KH
11459 ;; paste object
11460 (if (nth 1 port)
11461 (insert (nth 1 port) " ")
11462 (vhdl-insert-keyword "SIGNAL "))
11463 ;; paste actual port signals
11464 (setq names (nth 0 port))
11465 (while names
11466 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11467 (setq names (cdr names))
11468 (when names (insert ", ")))
11469 ;; paste type
11470 (insert " : " (nth 3 port))
11471 ;; paste initialization (inputs only)
3dcb36b7
JB
11472 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11473 (insert " := " (if (string-match "(.+)" (nth 3 port))
11474 "(others => '0')" "'0'")))
5eabfe72
KH
11475 (insert ";")
11476 ;; paste comment
3dcb36b7
JB
11477 (when (or vhdl-include-direction-comments
11478 (and vhdl-include-port-comments (nth 4 port)))
11479 (vhdl-comment-insert-inline
11480 (concat
11481 (cond ((and vhdl-include-direction-comments (nth 2 port))
11482 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11483 (vhdl-include-direction-comments " "))
11484 (when vhdl-include-port-comments (nth 4 port))) t))
11485 (setq port-list (cdr port-list))
11486 (when port-list (insert "\n") (indent-to margin)))
5eabfe72 11487 ;; align signal list
3dcb36b7 11488 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
5eabfe72
KH
11489 (message "Pasting port as signals...done")))
11490
3dcb36b7
JB
11491(defun vhdl-port-paste-initializations (&optional no-indent)
11492 "Paste ports as signal initializations."
5eabfe72
KH
11493 (interactive)
11494 (if (not vhdl-port-list)
3dcb36b7 11495 (error "ERROR: No port read")
5eabfe72 11496 (let ((orig-vhdl-port-list vhdl-port-list))
3dcb36b7
JB
11497 (message "Pasting port as initializations...")
11498 ;; flatten local copy of port list (must be flat for signal initial.)
5eabfe72 11499 (vhdl-port-flatten)
3dcb36b7 11500 (unless no-indent (indent-according-to-mode))
5eabfe72 11501 (let ((margin (current-indentation))
3dcb36b7
JB
11502 start port name
11503 (port-list (nth 2 vhdl-port-list)))
11504 (when port-list
5eabfe72 11505 (setq start (point))
3dcb36b7
JB
11506 (while port-list
11507 (setq port (car port-list))
11508 ;; paste actual port signal (inputs only)
11509 (when (equal "IN" (upcase (nth 2 port)))
11510 (setq name (car (nth 0 port)))
11511 (insert (vhdl-replace-string vhdl-actual-port-name name))
5eabfe72 11512 ;; paste initialization
3dcb36b7
JB
11513 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11514 "(others => '0')" "'0'") ";"))
11515 (setq port-list (cdr port-list))
11516 (when (and port-list
11517 (equal "IN" (upcase (nth 2 (car port-list)))))
11518 (insert "\n") (indent-to margin)))
11519 ;; align signal list
11520 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11521 (message "Pasting port as initializations...done")
5eabfe72
KH
11522 (setq vhdl-port-list orig-vhdl-port-list))))
11523
11524(defun vhdl-port-paste-testbench ()
3dcb36b7 11525 "Paste as a bare-bones testbench."
5eabfe72
KH
11526 (interactive)
11527 (if (not vhdl-port-list)
3dcb36b7 11528 (error "ERROR: No port read")
5eabfe72
KH
11529 (let ((case-fold-search t)
11530 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11531 (nth 0 vhdl-port-list)))
11532 (source-buffer (current-buffer))
3dcb36b7
JB
11533 arch-name config-name ent-file-name arch-file-name
11534 ent-buffer arch-buffer position)
5eabfe72 11535 ;; open entity file
3dcb36b7 11536 (unless (eq vhdl-testbench-create-files 'none)
5eabfe72 11537 (setq ent-file-name
0a2e512a
RF
11538 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11539 ent-name t)
11540 "." (file-name-extension (buffer-file-name))))
3dcb36b7 11541 (if (file-exists-p ent-file-name)
5eabfe72 11542 (if (y-or-n-p
3dcb36b7
JB
11543 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11544 (progn (find-file ent-file-name)
11545 (erase-buffer)
11546 (set-buffer-modified-p nil))
11547 (if (eq vhdl-testbench-create-files 'separate)
11548 (setq ent-file-name nil)
11549 (error "ERROR: Pasting port as testbench...aborted")))
11550 (find-file ent-file-name)))
11551 (unless (and (eq vhdl-testbench-create-files 'separate)
11552 (null ent-file-name))
11553 ;; paste entity header
11554 (if vhdl-testbench-include-header
11555 (progn (vhdl-template-header
11556 (concat "Testbench for design \""
11557 (nth 0 vhdl-port-list) "\""))
11558 (goto-char (point-max)))
11559 (vhdl-comment-display-line) (insert "\n\n"))
11560 ;; paste std_logic_1164 package
11561 (when vhdl-testbench-include-library
11562 (vhdl-template-package-std-logic-1164)
11563 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11564 ;; paste entity declaration
11565 (vhdl-insert-keyword "ENTITY ")
5eabfe72
KH
11566 (insert ent-name)
11567 (vhdl-insert-keyword " IS")
3dcb36b7 11568 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
5eabfe72 11569 (insert "\n")
3dcb36b7
JB
11570 (vhdl-insert-keyword "END ")
11571 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11572 (insert ent-name ";")
11573 (insert "\n\n")
11574 (vhdl-comment-display-line) (insert "\n"))
11575 ;; get architecture name
11576 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11577 (read-from-minibuffer "architecture name: "
11578 nil vhdl-minibuffer-local-map)
11579 (vhdl-replace-string vhdl-testbench-architecture-name
11580 (nth 0 vhdl-port-list))))
11581 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11582 ;; open architecture file
11583 (if (not (eq vhdl-testbench-create-files 'separate))
5eabfe72 11584 (insert "\n")
3dcb36b7
JB
11585 (setq ent-buffer (current-buffer))
11586 (setq arch-file-name
0a2e512a
RF
11587 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11588 (concat ent-name " " arch-name) t)
11589 "." (file-name-extension (buffer-file-name))))
3dcb36b7
JB
11590 (when (and (file-exists-p arch-file-name)
11591 (not (y-or-n-p (concat "File \"" arch-file-name
11592 "\" exists; overwrite? "))))
11593 (error "ERROR: Pasting port as testbench...aborted"))
11594 (find-file arch-file-name)
11595 (erase-buffer)
11596 (set-buffer-modified-p nil)
11597 ;; paste architecture header
11598 (if vhdl-testbench-include-header
11599 (progn (vhdl-template-header
11600 (concat "Testbench architecture for design \""
11601 (nth 0 vhdl-port-list) "\""))
11602 (goto-char (point-max)))
11603 (vhdl-comment-display-line) (insert "\n\n")))
11604 ;; paste architecture body
11605 (vhdl-insert-keyword "ARCHITECTURE ")
11606 (insert arch-name)
11607 (vhdl-insert-keyword " OF ")
11608 (insert ent-name)
11609 (vhdl-insert-keyword " IS")
11610 (insert "\n\n") (indent-to vhdl-basic-offset)
11611 ;; paste component declaration
11612 (unless (vhdl-use-direct-instantiation)
11613 (vhdl-port-paste-component t)
11614 (insert "\n\n") (indent-to vhdl-basic-offset))
11615 ;; paste constants
11616 (when (nth 1 vhdl-port-list)
11617 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11618 (vhdl-port-paste-constants t)
11619 (insert "\n\n") (indent-to vhdl-basic-offset))
11620 ;; paste internal signals
11621 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11622 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11623 (insert "\n")
11624 ;; paste custom declarations
11625 (unless (equal "" vhdl-testbench-declarations)
5eabfe72 11626 (insert "\n")
3dcb36b7
JB
11627 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11628 (setq position (point))
11629 (insert "\n\n")
11630 (vhdl-comment-display-line) (insert "\n")
11631 (when vhdl-testbench-include-configuration
11632 (setq config-name (vhdl-replace-string
11633 vhdl-testbench-configuration-name
11634 (concat ent-name " " arch-name)))
11635 (insert "\n")
11636 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11637 (vhdl-insert-keyword " OF ") (insert ent-name)
11638 (vhdl-insert-keyword " IS\n")
11639 (indent-to vhdl-basic-offset)
11640 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11641 (indent-to vhdl-basic-offset)
11642 (vhdl-insert-keyword "END FOR;\n")
11643 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11644 (vhdl-comment-display-line) (insert "\n"))
11645 (goto-char position)
11646 (vhdl-template-begin-end
11647 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11648 ;; paste instantiation
11649 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11650 (vhdl-port-paste-instance
11651 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11652 (insert "\n")
11653 ;; paste custom statements
11654 (unless (equal "" vhdl-testbench-statements)
11655 (insert "\n")
11656 (vhdl-insert-string-or-file vhdl-testbench-statements))
11657 (insert "\n")
11658 (indent-to vhdl-basic-offset)
11659 (unless (eq vhdl-testbench-create-files 'none)
11660 (setq arch-buffer (current-buffer))
11661 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11662 (set-buffer arch-buffer) (save-buffer))
29a4e67d 11663 (message "%s"
3dcb36b7
JB
11664 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11665 ent-name arch-name)
11666 (and ent-file-name
11667 (format "\n File created: \"%s\"" ent-file-name))
11668 (and arch-file-name
11669 (format "\n File created: \"%s\"" arch-file-name)))))))
5eabfe72
KH
11670
11671
11672;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11673;;; Subprogram interface translation
5eabfe72
KH
11674;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11675
3dcb36b7
JB
11676(defvar vhdl-subprog-list nil
11677 "Variable to hold last subprogram interface parsed.")
11678;; structure: (parenthesised expression means list of such entries)
11679;; (subprog-name kind
11680;; ((names) object direct type init comment group-comment)
11681;; return-type return-comment group-comment)
5eabfe72 11682
3dcb36b7
JB
11683(defvar vhdl-subprog-flattened nil
11684 "Indicates whether an subprogram interface has been flattened.")
5eabfe72 11685
3dcb36b7
JB
11686(defun vhdl-subprog-flatten ()
11687 "Flatten interface list so that only one parameter exists per line."
11688 (interactive)
11689 (if (not vhdl-subprog-list)
11690 (error "ERROR: No subprogram interface has been read")
11691 (message "Flattening subprogram interface...")
11692 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11693 new-subprog-list old-subprog new-subprog names)
11694 ;; traverse parameter list and flatten entries
11695 (while old-subprog-list
11696 (setq old-subprog (car old-subprog-list))
11697 (setq names (car old-subprog))
11698 (while names
11699 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11700 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11701 (setq names (cdr names)))
11702 (setq old-subprog-list (cdr old-subprog-list)))
11703 (setq vhdl-subprog-list
11704 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11705 new-subprog-list (nth 3 vhdl-subprog-list)
11706 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11707 vhdl-subprog-flattened t)
11708 (message "Flattening subprogram interface...done"))))
11709
11710(defun vhdl-subprog-copy ()
11711 "Get interface information from a subprogram specification."
11712 (interactive)
11713 (save-excursion
11714 (let (parse-error pos end-of-list
11715 name kind param-list object names direct type init
11716 comment group-comment
11717 return-type return-comment return-group-comment)
11718 (vhdl-prepare-search-2
11719 (setq
11720 parse-error
11721 (catch 'parse
11722 ;; check if within function declaration
11723 (setq pos (point))
11724 (end-of-line)
11725 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11726 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11727 (goto-char (match-end 0))
11728 (save-excursion (backward-char)
11729 (forward-sexp)
11730 (<= pos (point))))
11731 (throw 'parse "ERROR: Not within a subprogram specification"))
11732 (setq name (match-string-no-properties 5))
11733 (setq kind (if (match-string 2) 'procedure 'function))
11734 (setq end-of-list (not (match-string 7)))
11735 (message "Reading interface of subprogram \"%s\"..." name)
11736 ;; parse parameter list
11737 (setq group-comment (vhdl-parse-group-comment))
11738 (setq end-of-list (or end-of-list
11739 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11740 (while (not end-of-list)
11741 ;; parse object
11742 (setq object
11743 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11744 (match-string-no-properties 1)))
11745 ;; parse names (accept extended identifiers)
11746 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11747 (setq names (list (match-string-no-properties 1)))
11748 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11749 (setq names (append names (list (match-string-no-properties 1)))))
11750 ;; parse direction
11751 (vhdl-parse-string ":[ \t\n]*")
11752 (setq direct
11753 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11754 (match-string-no-properties 1)))
11755 ;; parse type
11756 (vhdl-parse-string "\\([^():;\n]+\\)")
11757 (setq type (match-string-no-properties 1))
11758 (setq comment nil)
11759 (while (looking-at "(")
11760 (setq type
11761 (concat type
11762 (buffer-substring-no-properties
11763 (point) (progn (forward-sexp) (point)))
11764 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11765 (match-string-no-properties 1)))))
11766 ;; special case: closing parenthesis is on separate line
11767 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11768 (setq comment (substring type (match-beginning 2)))
11769 (setq type (substring type 0 (match-beginning 1))))
11770 ;; strip off trailing group-comment
11771 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11772 (setq type (substring type 0 (match-end 1)))
11773 ;; parse initialization expression
11774 (setq init nil)
11775 (when (vhdl-parse-string ":=[ \t\n]*" t)
11776 (vhdl-parse-string "\\([^();\n]*\\)")
11777 (setq init (match-string-no-properties 1))
11778 (while (looking-at "(")
11779 (setq init
11780 (concat init
11781 (buffer-substring-no-properties
11782 (point) (progn (forward-sexp) (point)))
11783 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11784 (match-string-no-properties 1))))))
11785 ;; special case: closing parenthesis is on separate line
11786 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11787 (setq comment (substring init (match-beginning 2)))
11788 (setq init (substring init 0 (match-beginning 1)))
11789 (vhdl-forward-syntactic-ws))
11790 (skip-chars-forward " \t")
11791 ;; parse inline comment, special case: as above, no initial.
11792 (unless comment
11793 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11794 (match-string-no-properties 1))))
11795 (vhdl-forward-syntactic-ws)
11796 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11797 ;; parse inline comment
11798 (unless comment
11799 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11800 (match-string-no-properties 1))))
11801 (setq return-group-comment (vhdl-parse-group-comment))
11802 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11803 ;; parse return type
11804 (when (match-string 3)
11805 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11806 (setq return-type (match-string-no-properties 1))
11807 (when (and return-type
11808 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11809 (setq return-comment (substring return-type (match-beginning 2)))
11810 (setq return-type (substring return-type 0 (match-beginning 1))))
11811 ;; strip of trailing group-comment
11812 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11813 (setq return-type (substring return-type 0 (match-end 1)))
11814 ;; parse return comment
11815 (unless return-comment
11816 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11817 (match-string-no-properties 1)))))
11818 ;; parse inline comment
11819 (unless comment
11820 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11821 (match-string-no-properties 1))))
11822 ;; save everything in list
11823 (setq param-list (append param-list
11824 (list (list names object direct type init
11825 comment group-comment))))
11826 ;; parse group comment and spacing
11827 (setq group-comment (vhdl-parse-group-comment)))
11828 (message "Reading interface of subprogram \"%s\"...done" name)
11829 nil)))
11830 ;; finish parsing
11831 (if parse-error
11832 (error parse-error)
11833 (setq vhdl-subprog-list
11834 (list name kind param-list return-type return-comment
11835 return-group-comment)
11836 vhdl-subprog-flattened nil)))))
11837
11838(defun vhdl-subprog-paste-specification (kind)
11839 "Paste as a subprogram specification."
11840 (indent-according-to-mode)
11841 (let ((margin (current-column))
11842 (param-list (nth 2 vhdl-subprog-list))
11843 list-margin start names param)
11844 ;; paste keyword and name
11845 (vhdl-insert-keyword
11846 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11847 (insert (nth 0 vhdl-subprog-list))
11848 (if (not param-list)
11849 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11850 (setq start (point))
11851 ;; paste parameter list
11852 (insert " (")
11853 (unless vhdl-argument-list-indent
11854 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11855 (setq list-margin (current-column))
11856 (while param-list
11857 (setq param (car param-list))
11858 ;; paste group comment and spacing
11859 (when (memq vhdl-include-group-comments (list kind 'always))
11860 (vhdl-paste-group-comment (nth 6 param) list-margin))
11861 ;; paste object
11862 (when (nth 1 param) (insert (nth 1 param) " "))
11863 ;; paste names
11864 (setq names (nth 0 param))
11865 (while names
11866 (insert (car names))
11867 (setq names (cdr names))
11868 (when names (insert ", ")))
11869 ;; paste direction
11870 (insert " : ")
11871 (when (nth 2 param) (insert (nth 2 param) " "))
11872 ;; paste type
11873 (insert (nth 3 param))
11874 ;; paste initialization
11875 (when (nth 4 param) (insert " := " (nth 4 param)))
11876 ;; terminate line
11877 (if (cdr param-list)
11878 (insert ";")
11879 (insert ")")
11880 (when (null (nth 3 vhdl-subprog-list))
11881 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11882 ;; paste comment
11883 (when (and vhdl-include-port-comments (nth 5 param))
11884 (vhdl-comment-insert-inline (nth 5 param) t))
11885 (setq param-list (cdr param-list))
11886 (when param-list (insert "\n") (indent-to list-margin)))
11887 (when (nth 3 vhdl-subprog-list)
11888 (insert "\n") (indent-to list-margin)
11889 ;; paste group comment and spacing
11890 (when (memq vhdl-include-group-comments (list kind 'always))
11891 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11892 ;; paste return type
11893 (insert "return " (nth 3 vhdl-subprog-list))
0a2e512a 11894 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
3dcb36b7
JB
11895 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11896 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11897 ;; align parameter list
11898 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11899 ;; paste body
11900 (when (eq kind 'body)
11901 (insert "\n")
11902 (vhdl-template-begin-end
11903 (unless (vhdl-standard-p '87)
11904 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11905 (nth 0 vhdl-subprog-list) margin))))
11906
11907(defun vhdl-subprog-paste-declaration ()
11908 "Paste as a subprogram declaration."
11909 (interactive)
11910 (if (not vhdl-subprog-list)
11911 (error "ERROR: No subprogram interface read")
11912 (message "Pasting interface as subprogram declaration \"%s\"..."
11913 (car vhdl-subprog-list))
11914 ;; paste specification
11915 (vhdl-subprog-paste-specification 'decl)
11916 (message "Pasting interface as subprogram declaration \"%s\"...done"
11917 (car vhdl-subprog-list))))
11918
11919(defun vhdl-subprog-paste-body ()
11920 "Paste as a subprogram body."
11921 (interactive)
11922 (if (not vhdl-subprog-list)
11923 (error "ERROR: No subprogram interface read")
11924 (message "Pasting interface as subprogram body \"%s\"..."
11925 (car vhdl-subprog-list))
11926 ;; paste specification and body
11927 (vhdl-subprog-paste-specification 'body)
11928 (message "Pasting interface as subprogram body \"%s\"...done"
11929 (car vhdl-subprog-list))))
11930
11931(defun vhdl-subprog-paste-call ()
11932 "Paste as a subprogram call."
11933 (interactive)
11934 (if (not vhdl-subprog-list)
11935 (error "ERROR: No subprogram interface read")
11936 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11937 param-list margin list-margin param start)
11938 ;; flatten local copy of interface list (must be flat for parameter mapping)
11939 (vhdl-subprog-flatten)
11940 (setq param-list (nth 2 vhdl-subprog-list))
11941 (indent-according-to-mode)
11942 (setq margin (current-indentation))
11943 (message "Pasting interface as subprogram call \"%s\"..."
11944 (car vhdl-subprog-list))
11945 ;; paste name
11946 (insert (nth 0 vhdl-subprog-list))
11947 (if (not param-list)
11948 (insert ";")
11949 (setq start (point))
11950 ;; paste parameter list
11951 (insert " (")
11952 (unless vhdl-argument-list-indent
11953 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11954 (setq list-margin (current-column))
11955 (while param-list
11956 (setq param (car param-list))
11957 ;; paste group comment and spacing
11958 (when (eq vhdl-include-group-comments 'always)
11959 (vhdl-paste-group-comment (nth 6 param) list-margin))
11960 ;; paste formal port
11961 (insert (car (nth 0 param)) " => ")
11962 (setq param-list (cdr param-list))
11963 (insert (if param-list "," ");"))
11964 ;; paste comment
11965 (when (and vhdl-include-port-comments (nth 5 param))
11966 (vhdl-comment-insert-inline (nth 5 param)))
11967 (when param-list (insert "\n") (indent-to list-margin)))
11968 ;; align parameter list
11969 (when vhdl-auto-align
11970 (vhdl-align-region-groups start (point) 1)))
11971 (message "Pasting interface as subprogram call \"%s\"...done"
11972 (car vhdl-subprog-list))
11973 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11974
11975
11976;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11977;;; Miscellaneous
11978;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11979
11980;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11981;; Hippie expand customization
11982
11983(defvar vhdl-expand-upper-case nil)
11984
11985(defun vhdl-try-expand-abbrev (old)
11986 "Try expanding abbreviations from `vhdl-abbrev-list'."
11987 (unless old
11988 (he-init-string (he-dabbrev-beg) (point))
5eabfe72
KH
11989 (setq he-expand-list
11990 (let ((abbrev-list vhdl-abbrev-list)
11991 (sel-abbrev-list '()))
11992 (while abbrev-list
11993 (when (or (not (stringp (car abbrev-list)))
11994 (string-match
11995 (concat "^" he-search-string) (car abbrev-list)))
11996 (setq sel-abbrev-list
11997 (cons (car abbrev-list) sel-abbrev-list)))
11998 (setq abbrev-list (cdr abbrev-list)))
11999 (nreverse sel-abbrev-list))))
12000 (while (and he-expand-list
12001 (or (not (stringp (car he-expand-list)))
12002 (he-string-member (car he-expand-list) he-tried-table t)))
12003; (equal (car he-expand-list) he-search-string)))
12004 (unless (stringp (car he-expand-list))
12005 (setq vhdl-expand-upper-case (car he-expand-list)))
12006 (setq he-expand-list (cdr he-expand-list)))
12007 (if (null he-expand-list)
12008 (progn (when old (he-reset-string))
12009 nil)
12010 (he-substitute-string
12011 (if vhdl-expand-upper-case
12012 (upcase (car he-expand-list))
12013 (car he-expand-list))
12014 t)
12015 (setq he-expand-list (cdr he-expand-list))
12016 t))
12017
12018(defun vhdl-he-list-beg ()
12019 "Also looks at the word before `(' in order to better match parenthesized
12020expressions (e.g. for index ranges of types and signals)."
12021 (save-excursion
12022 (condition-case ()
12023 (progn (backward-up-list 1)
12024 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12025 (error ()))
12026 (point)))
12027
12028;; override `he-list-beg' from `hippie-exp'
12029(unless (and (boundp 'viper-mode) viper-mode)
5eabfe72
KH
12030 (defalias 'he-list-beg 'vhdl-he-list-beg))
12031
12032;; function for expanding abbrevs and dabbrevs
3dcb36b7 12033(defun vhdl-expand-abbrev (arg))
5eabfe72
KH
12034(fset 'vhdl-expand-abbrev (make-hippie-expand-function
12035 '(try-expand-dabbrev
12036 try-expand-dabbrev-all-buffers
12037 vhdl-try-expand-abbrev)))
12038
12039;; function for expanding parenthesis
3dcb36b7 12040(defun vhdl-expand-paren (arg))
5eabfe72
KH
12041(fset 'vhdl-expand-paren (make-hippie-expand-function
12042 '(try-expand-list
12043 try-expand-list-all-buffers)))
12044
12045;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12046;; Case fixing
d2ddb974
KH
12047
12048(defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
a4c6cfad
JB
12049 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12050depending on parameter UPPER-CASE."
3dcb36b7 12051 (let ((case-replace nil)
5eabfe72 12052 (last-update 0))
3dcb36b7 12053 (vhdl-prepare-search-2
5eabfe72
KH
12054 (save-excursion
12055 (goto-char end)
12056 (setq end (point-marker))
12057 (goto-char beg)
12058 (while (re-search-forward word-regexp end t)
3dcb36b7 12059 (or (vhdl-in-literal)
5eabfe72
KH
12060 (if upper-case
12061 (upcase-word -1)
12062 (downcase-word -1)))
3dcb36b7 12063 (when (and count vhdl-progress-interval (not noninteractive)
5eabfe72
KH
12064 (< vhdl-progress-interval
12065 (- (nth 1 (current-time)) last-update)))
12066 (message "Fixing case... (%2d%s)"
12067 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12068 "%")
12069 (setq last-update (nth 1 (current-time)))))
3dcb36b7 12070 (goto-char end)))))
d2ddb974
KH
12071
12072(defun vhdl-fix-case-region (beg end &optional arg)
12073 "Convert all VHDL words in region to lower or upper case, depending on
3dcb36b7 12074options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974
KH
12075 (interactive "r\nP")
12076 (vhdl-fix-case-region-1
5eabfe72 12077 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
d2ddb974 12078 (vhdl-fix-case-region-1
5eabfe72 12079 beg end vhdl-upper-case-types vhdl-types-regexp 1)
d2ddb974 12080 (vhdl-fix-case-region-1
5eabfe72
KH
12081 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12082 (vhdl-fix-case-region-1
3dcb36b7
JB
12083 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12084 (when vhdl-progress-interval (message "Fixing case...done")))
d2ddb974 12085
5eabfe72
KH
12086(defun vhdl-fix-case-buffer ()
12087 "Convert all VHDL words in buffer to lower or upper case, depending on
3dcb36b7 12088options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974 12089 (interactive)
5eabfe72
KH
12090 (vhdl-fix-case-region (point-min) (point-max)))
12091
3dcb36b7
JB
12092(defun vhdl-fix-case-word (&optional arg)
12093 "Convert word after cursor to upper case if necessary."
12094 (interactive "p")
12095 (save-excursion
12096 (when arg (backward-word 1))
12097 (vhdl-prepare-search-1
12098 (when (and vhdl-upper-case-keywords
12099 (looking-at vhdl-keywords-regexp))
12100 (upcase-word 1))
12101 (when (and vhdl-upper-case-types
12102 (looking-at vhdl-types-regexp))
12103 (upcase-word 1))
12104 (when (and vhdl-upper-case-attributes
12105 (looking-at vhdl-attributes-regexp))
12106 (upcase-word 1))
12107 (when (and vhdl-upper-case-enum-values
12108 (looking-at vhdl-enum-values-regexp))
12109 (upcase-word 1)))))
12110
5eabfe72
KH
12111;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12112;; Line handling functions
d2ddb974
KH
12113
12114(defun vhdl-current-line ()
12115 "Return the line number of the line containing point."
12116 (save-restriction
12117 (widen)
9b026d9f 12118 (1+ (count-lines (point-min) (point-at-bol)))))
d2ddb974 12119
5eabfe72 12120(defun vhdl-line-kill-entire (&optional arg)
d2ddb974 12121 "Delete entire line."
5eabfe72
KH
12122 (interactive "p")
12123 (beginning-of-line)
12124 (kill-line (or arg 1)))
12125
12126(defun vhdl-line-kill (&optional arg)
12127 "Kill current line."
12128 (interactive "p")
12129 (vhdl-line-kill-entire arg))
12130
12131(defun vhdl-line-copy (&optional arg)
12132 "Copy current line."
12133 (interactive "p")
12134 (save-excursion
9b026d9f 12135 (let ((position (point-at-bol)))
5eabfe72
KH
12136 (forward-line (or arg 1))
12137 (copy-region-as-kill position (point)))))
12138
12139(defun vhdl-line-yank ()
12140 "Yank entire line."
d2ddb974 12141 (interactive)
5eabfe72
KH
12142 (beginning-of-line)
12143 (yank))
d2ddb974 12144
5eabfe72
KH
12145(defun vhdl-line-expand (&optional prefix-arg)
12146 "Hippie-expand current line."
12147 (interactive "P")
12148 (let ((case-fold-search t) (case-replace nil)
12149 (hippie-expand-try-functions-list
12150 '(try-expand-line try-expand-line-all-buffers)))
12151 (hippie-expand prefix-arg)))
12152
12153(defun vhdl-line-transpose-next (&optional arg)
12154 "Interchange this line with next line."
12155 (interactive "p")
12156 (forward-line 1)
12157 (transpose-lines (or arg 1))
12158 (forward-line -1))
12159
12160(defun vhdl-line-transpose-previous (&optional arg)
12161 "Interchange this line with previous line."
12162 (interactive "p")
12163 (forward-line 1)
12164 (transpose-lines (- 0 (or arg 0)))
12165 (forward-line -1))
12166
12167(defun vhdl-line-open ()
d2ddb974
KH
12168 "Open a new line and indent."
12169 (interactive)
5eabfe72
KH
12170 (end-of-line -0)
12171 (newline-and-indent))
d2ddb974 12172
3dcb36b7
JB
12173(defun vhdl-delete-indentation ()
12174 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12175it works within comments too."
12176 (interactive)
12177 (let ((fill-prefix "-- "))
12178 (delete-indentation)))
d2ddb974 12179
5eabfe72 12180;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12181;; Move functions
d2ddb974 12182
3dcb36b7
JB
12183(defun vhdl-forward-same-indent ()
12184 "Move forward to next line with same indent."
12185 (interactive)
12186 (let ((pos (point))
12187 (indent (current-indentation)))
12188 (beginning-of-line 2)
12189 (while (and (not (eobp))
12190 (or (looking-at "^\\s-*\\(--.*\\)?$")
12191 (> (current-indentation) indent)))
12192 (beginning-of-line 2))
12193 (if (= (current-indentation) indent)
12194 (back-to-indentation)
12195 (message "No following line with same indent found in this block")
12196 (goto-char pos)
12197 nil)))
5eabfe72 12198
3dcb36b7
JB
12199(defun vhdl-backward-same-indent ()
12200 "Move backward to previous line with same indent."
12201 (interactive)
12202 (let ((pos (point))
12203 (indent (current-indentation)))
12204 (beginning-of-line -0)
12205 (while (and (not (bobp))
12206 (or (looking-at "^\\s-*\\(--.*\\)?$")
12207 (> (current-indentation) indent)))
12208 (beginning-of-line -0))
12209 (if (= (current-indentation) indent)
12210 (back-to-indentation)
12211 (message "No preceding line with same indent found in this block")
12212 (goto-char pos)
12213 nil)))
5eabfe72
KH
12214
12215;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
12216;; Statistics
12217
12218(defun vhdl-statistics-buffer ()
12219 "Get some file statistics."
12220 (interactive)
12221 (let ((no-stats 0)
12222 (no-code-lines 0)
12223 (no-lines (count-lines (point-min) (point-max))))
12224 (save-excursion
12225 ;; count statements
12226 (goto-char (point-min))
12227 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12228 (if (match-string 1)
12229 (goto-char (match-end 1))
12230 (setq no-stats (1+ no-stats))))
12231 ;; count code lines
12232 (goto-char (point-min))
12233 (while (not (eobp))
12234 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12235 (setq no-code-lines (1+ no-code-lines)))
12236 (beginning-of-line 2)))
12237 ;; print results
12238 (message "\n\
12239File statistics: \"%s\"\n\
12240---------------------\n\
12241# statements : %5d\n\
12242# code lines : %5d\n\
12243# total lines : %5d\n\ "
0a2e512a
RF
12244 (buffer-file-name) no-stats no-code-lines no-lines)
12245 (unless vhdl-emacs-21 (vhdl-show-messages))))
3dcb36b7 12246
5eabfe72 12247;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12248;; Help functions
d2ddb974 12249
3dcb36b7
JB
12250(defun vhdl-re-search-forward (regexp &optional bound noerror count)
12251 "Like `re-search-forward', but does not match within literals."
12252 (let (pos)
12253 (save-excursion
12254 (while (and (setq pos (re-search-forward regexp bound noerror count))
12255 (vhdl-in-literal))))
12256 (when pos (goto-char pos))
12257 pos))
12258
12259(defun vhdl-re-search-backward (regexp &optional bound noerror count)
12260 "Like `re-search-backward', but does not match within literals."
12261 (let (pos)
12262 (save-excursion
12263 (while (and (setq pos (re-search-backward regexp bound noerror count))
12264 (vhdl-in-literal))))
12265 (when pos (goto-char pos))
12266 pos))
5eabfe72 12267
d2ddb974 12268
3dcb36b7
JB
12269;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12270;;; Project
12271;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12272
12273(defun vhdl-set-project (name)
12274 "Set current project to NAME."
12275 (interactive
12276 (list (let ((completion-ignore-case t))
12277 (completing-read "Project name: " vhdl-project-alist nil t))))
12278 (cond ((equal name "")
12279 (setq vhdl-project nil)
12280 (message "Current VHDL project: None"))
12281 ((assoc name vhdl-project-alist)
12282 (setq vhdl-project name)
12283 (message "Current VHDL project: \"%s\"" name))
12284 (t
12285 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12286 (vhdl-speedbar-update-current-project))
12287
0a2e512a
RF
12288(defun vhdl-set-default-project ()
12289 "Set current project as default on startup."
12290 (interactive)
12291 (customize-set-variable 'vhdl-project vhdl-project)
12292 (customize-save-customized))
12293
3dcb36b7
JB
12294(defun vhdl-toggle-project (name token indent)
12295 "Set current project to NAME or unset if NAME is current project."
12296 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12297
12298(defun vhdl-export-project (file-name)
12299 "Write project setup for current project."
12300 (interactive
12301 (let ((name (vhdl-resolve-env-variable
12302 (vhdl-replace-string
12303 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12304 (concat (subst-char-in-string
12305 ? ?_ (or (vhdl-project-p)
12306 (error "ERROR: No current project")))
12307 " " (user-login-name))))))
12308 (list (read-file-name
12309 "Write project file: "
12310 (when (file-name-absolute-p name) "") nil nil name))))
12311 (setq file-name (abbreviate-file-name file-name))
12312 (let ((orig-buffer (current-buffer)))
12313 (unless (file-exists-p (file-name-directory file-name))
12314 (make-directory (file-name-directory file-name) t))
12315 (if (not (file-writable-p file-name))
12316 (error "ERROR: File not writable: \"%s\"" file-name)
12317 (set-buffer (find-file-noselect file-name t t))
12318 (erase-buffer)
12319 (insert ";; -*- Emacs-Lisp -*-\n\n"
12320 ";;; " (file-name-nondirectory file-name)
12321 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12322 ";; Project : " vhdl-project "\n"
12323 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12324 (user-login-name) "\n\n\n"
12325 ";; project name\n"
12326 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12327 ";; project setup\n"
12328 "(aput 'vhdl-project-alist vhdl-project\n'")
12329 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12330 (insert ")\n")
12331 (save-buffer)
12332 (kill-buffer (current-buffer))
12333 (set-buffer orig-buffer))))
12334
12335(defun vhdl-import-project (file-name &optional auto not-make-current)
12336 "Read project setup and set current project."
12337 (interactive
12338 (let ((name (vhdl-resolve-env-variable
12339 (vhdl-replace-string
12340 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12341 (concat "" " " (user-login-name))))))
12342 (list (read-file-name
12343 "Read project file: " (when (file-name-absolute-p name) "") nil t
12344 (file-name-directory name)))))
12345 (when (file-exists-p file-name)
12346 (condition-case ()
12347 (let ((current-project vhdl-project))
12348 (load-file file-name)
12349 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12350 (adelete 'vhdl-project-alist vhdl-project)
0a2e512a 12351 (error ""))
3dcb36b7
JB
12352 (when not-make-current
12353 (setq vhdl-project current-project))
12354 (vhdl-update-mode-menu)
12355 (vhdl-speedbar-refresh)
12356 (unless not-make-current
12357 (message "Current VHDL project: \"%s\"%s"
12358 vhdl-project (if auto " (auto-loaded)" ""))))
12359 (error (vhdl-warning
12360 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12361
12362(defun vhdl-duplicate-project ()
12363 "Duplicate setup of current project."
5eabfe72 12364 (interactive)
3dcb36b7
JB
12365 (let ((new-name (read-from-minibuffer "New project name: "))
12366 (project-entry (aget vhdl-project-alist vhdl-project t)))
12367 (setq vhdl-project-alist
12368 (append vhdl-project-alist
12369 (list (cons new-name project-entry))))
12370 (vhdl-update-mode-menu)))
12371
12372(defun vhdl-auto-load-project ()
12373 "Automatically load project setup at startup."
12374 (let ((file-name-list vhdl-project-file-name)
12375 file-list list-length)
12376 (while file-name-list
12377 (setq file-list
12378 (append file-list
12379 (file-expand-wildcards
12380 (vhdl-resolve-env-variable
12381 (vhdl-replace-string
12382 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12383 (concat "\*" " " (user-login-name)))))))
12384 (setq list-length (or list-length (length file-list)))
12385 (setq file-name-list (cdr file-name-list)))
12386 (while file-list
12387 (vhdl-import-project (expand-file-name (car file-list)) t
12388 (not (> list-length 0)))
12389 (setq list-length (1- list-length))
12390 (setq file-list (cdr file-list)))))
12391
12392;; automatically load project setup when idle after startup
12393(when (memq 'startup vhdl-project-auto-load)
12394 (if noninteractive
12395 (vhdl-auto-load-project)
12396 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
5eabfe72
KH
12397
12398
12399;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12400;;; Hideshow
12401;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12402;; (using `hideshow.el')
d2ddb974 12403
3dcb36b7
JB
12404(defconst vhdl-hs-start-regexp
12405 (concat
12406 "\\(^\\)\\s-*\\("
12407 ;; generic/port clause
12408 "\\(generic\\|port\\)[ \t\n]*(\\|"
12409 ;; component
12410 "component\\>\\|"
12411 ;; component instantiation
12412 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12413 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12414 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12415 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12416 ;; subprogram
12417 "\\(function\\|procedure\\)\\>\\|"
12418 ;; process, block
12419 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12420 ;; configuration declaration
12421 "configuration\\>"
12422 "\\)")
12423 "Regexp to match start of construct to hide.")
12424
12425(defun vhdl-hs-forward-sexp-func (count)
a4c6cfad 12426 "Find end of construct to hide (for hideshow). Only searches forward."
3dcb36b7
JB
12427 (let ((pos (point)))
12428 (vhdl-prepare-search-2
12429 (beginning-of-line)
12430 (cond
12431 ;; generic/port clause
12432 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12433 (goto-char (match-end 0))
12434 (backward-char)
12435 (forward-sexp))
12436 ;; component declaration
12437 ((looking-at "^\\s-*component\\>")
12438 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12439 ;; component instantiation
12440 ((looking-at
12441 (concat
12442 "^\\s-*\\w+\\s-*:[ \t\n]*"
12443 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12444 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12445 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12446 (goto-char (match-end 0))
12447 (backward-char)
12448 (forward-sexp)
12449 (setq pos (point))
12450 (vhdl-forward-syntactic-ws)
12451 (when (looking-at "port\\s-+map[ \t\n]*(")
12452 (goto-char (match-end 0))
12453 (backward-char)
12454 (forward-sexp)
12455 (setq pos (point)))
12456 (goto-char pos))
12457 ;; subprogram declaration/body
12458 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12459 (goto-char (match-end 0))
12460 (vhdl-forward-syntactic-ws)
12461 (when (looking-at "(")
12462 (forward-sexp))
12463 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12464 (vhdl-in-literal)))
12465 ;; subprogram body
12466 (when (match-string 2)
12467 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12468 (backward-word 1)
12469 (vhdl-forward-sexp)))
12470 ;; block (recursive)
12471 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12472 (goto-char (match-end 0))
12473 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12474 (match-beginning 2))
12475 (vhdl-hs-forward-sexp-func count)))
12476 ;; process
12477 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12478 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12479 ;; configuration declaration
12480 ((looking-at "^\\s-*configuration\\>")
12481 (forward-word 4)
12482 (vhdl-forward-sexp))
12483 (t (goto-char pos))))))
5eabfe72
KH
12484
12485(defun vhdl-hideshow-init ()
12486 "Initialize `hideshow'."
3dcb36b7
JB
12487 (when vhdl-hideshow-menu
12488 (vhdl-hs-minor-mode 1)))
12489
12490(defun vhdl-hs-minor-mode (&optional arg)
12491 "Toggle hideshow minor mode and update menu bar."
12492 (interactive "P")
12493 (require 'hideshow)
12494 ;; check for hideshow version 5.x
12495 (if (not (boundp 'hs-block-start-mdata-select))
12496 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12497 ;; initialize hideshow
12498 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12499 (setq hs-special-modes-alist
12500 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12501 'vhdl-hs-forward-sexp-func nil)
12502 hs-special-modes-alist)))
12503 (make-local-variable 'hs-minor-mode-hook)
12504 (if vhdl-hide-all-init
12505 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12506 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12507 (hs-minor-mode arg)
56eb0904 12508 (force-mode-line-update))) ; hack to update menu bar
5eabfe72
KH
12509
12510
12511;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12512;;; Font locking
12513;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12514;; (using `font-lock.el')
12515
5eabfe72 12516;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12517;; Help functions
5eabfe72
KH
12518
12519(defun vhdl-within-translate-off ()
12520 "Return point if within translate-off region, else nil."
12521 (and (save-excursion
12522 (re-search-backward
12523 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12524 (equal "off" (match-string 1))
12525 (point)))
12526
12527(defun vhdl-start-translate-off (limit)
12528 "Return point before translate-off pragma if before LIMIT, else nil."
12529 (when (re-search-forward
12530 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12531 (match-beginning 0)))
12532
12533(defun vhdl-end-translate-off (limit)
12534 "Return point after translate-on pragma if before LIMIT, else nil."
12535 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12536
12537(defun vhdl-match-translate-off (limit)
12538 "Match a translate-off block, setting match-data and returning t, else nil."
12539 (when (< (point) limit)
12540 (let ((start (or (vhdl-within-translate-off)
12541 (vhdl-start-translate-off limit)))
12542 (case-fold-search t))
12543 (when start
12544 (let ((end (or (vhdl-end-translate-off limit) limit)))
12545 (set-match-data (list start end))
12546 (goto-char end))))))
12547
12548(defun vhdl-font-lock-match-item (limit)
a4c6cfad 12549 "Match, and move over, any declaration item after point. Adapted from
5eabfe72
KH
12550`font-lock-match-c-style-declaration-item-and-skip-to-next'."
12551 (condition-case nil
12552 (save-restriction
12553 (narrow-to-region (point-min) limit)
12554 ;; match item
3dcb36b7 12555 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
5eabfe72
KH
12556 (save-match-data
12557 (goto-char (match-end 1))
12558 ;; move to next item
0a2e512a
RF
12559 (if (looking-at "\\(\\s-*,\\)")
12560 (goto-char (match-end 1))
5eabfe72
KH
12561 (end-of-line) t))))
12562 (error t)))
12563
12564;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12565;; Syntax definitions
12566
5eabfe72
KH
12567(defconst vhdl-font-lock-syntactic-keywords
12568 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12569 "Mark single quotes as having string quote syntax in 'c' instances.")
12570
d2ddb974
KH
12571(defvar vhdl-font-lock-keywords nil
12572 "Regular expressions to highlight in VHDL Mode.")
12573
3dcb36b7
JB
12574(defvar vhdl-font-lock-keywords-0
12575 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12576 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12577This does highlighting of template prompts and directives (pragmas).")
d2ddb974 12578
5eabfe72 12579(defvar vhdl-font-lock-keywords-1 nil
3dcb36b7 12580 ;; set in `vhdl-font-lock-init' because dependent on user options
5eabfe72
KH
12581 "For consideration as a value of `vhdl-font-lock-keywords'.
12582This does highlighting of keywords and standard identifiers.")
12583
12584(defconst vhdl-font-lock-keywords-2
d2ddb974
KH
12585 (list
12586 ;; highlight names of units, subprograms, and components when declared
12587 (list
12588 (concat
12589 "^\\s-*\\("
3dcb36b7
JB
12590 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12591 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
d2ddb974 12592 "\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12593 5 'font-lock-function-name-face)
12594
12595 ;; highlight entity names of architectures and configurations
12596 (list
12597 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12598 2 'font-lock-function-name-face)
d2ddb974
KH
12599
12600 ;; highlight labels of common constructs
12601 (list
12602 (concat
3dcb36b7
JB
12603 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12604 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12605 "postponed\\|process\\|"
5eabfe72
KH
12606 (when (vhdl-standard-p 'ams) "procedural\\|")
12607 "with\\|while"
0a2e512a 12608 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
d2ddb974
KH
12609 1 'font-lock-function-name-face)
12610
5eabfe72 12611 ;; highlight label and component name of component instantiations
d2ddb974 12612 (list
5eabfe72 12613 (concat
3dcb36b7
JB
12614 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12615 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12616 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12617
12618 ;; highlight label and instantiated unit of component instantiations
12619 (list
12620 (concat
12621 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12622 "\\(component\\|configuration\\|entity\\)\\s-+"
12623 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12624 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12625 '(5 font-lock-function-name-face nil t)
12626 '(7 font-lock-function-name-face nil t))
d2ddb974
KH
12627
12628 ;; highlight names and labels at end of constructs
12629 (list
12630 (concat
5eabfe72
KH
12631 "^\\s-*end\\s-+\\(\\("
12632 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
3dcb36b7
JB
12633 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12634 "procedure\\|\\(postponed\\s-+\\)?process\\|"
5eabfe72
KH
12635 (when (vhdl-standard-p 'ams) "procedural\\|")
12636 "units"
3dcb36b7 12637 "\\)\\s-+\\)?\\(\\w*\\)")
5eabfe72
KH
12638 5 'font-lock-function-name-face)
12639
12640 ;; highlight labels in exit and next statements
12641 (list
12642 (concat
12643 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12644 3 'font-lock-function-name-face)
12645
12646 ;; highlight entity name in attribute specifications
12647 (list
12648 (concat
12649 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12650 1 'font-lock-function-name-face)
12651
3dcb36b7
JB
12652 ;; highlight labels in block and component specifications
12653 (list
12654 (concat
12655 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12656 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12657 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12658
12659 ;; highlight names in library clauses
12660 (list "^\\s-*library\\>"
12661 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12662
12663 ;; highlight names in use clauses
5eabfe72
KH
12664 (list
12665 (concat
3dcb36b7
JB
12666 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12667 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12668 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12669 '(7 font-lock-function-name-face nil t))
5eabfe72
KH
12670
12671 ;; highlight attribute name in attribute declarations/specifications
12672 (list
12673 (concat
12674 "^\\s-*attribute\\s-+\\(\\w+\\)")
0a2e512a 12675 1 'vhdl-font-lock-attribute-face)
5eabfe72
KH
12676
12677 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12678 (list
12679 (concat
3dcb36b7 12680 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12681 3 'font-lock-type-face)
12682
12683 ;; highlight signal/variable/constant declaration names
12684 (list "\\(:[^=]\\)"
12685 '(vhdl-font-lock-match-item
12686 (progn (goto-char (match-beginning 1))
12687 (skip-syntax-backward " ")
12688 (skip-syntax-backward "w_")
12689 (skip-syntax-backward " ")
12690 (while (= (preceding-char) ?,)
12691 (backward-char 1)
12692 (skip-syntax-backward " ")
12693 (skip-syntax-backward "w_")
12694 (skip-syntax-backward " ")))
12695; (skip-chars-backward "^-(\n\";")
12696 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12697
3dcb36b7
JB
12698 ;; highlight formal parameters in component instantiations and subprogram
12699 ;; calls
12700 (list "\\(=>\\)"
12701 '(vhdl-font-lock-match-item
12702 (progn (goto-char (match-beginning 1))
12703 (skip-syntax-backward " ")
12704 (while (= (preceding-char) ?\)) (backward-sexp))
12705 (skip-syntax-backward "w_")
12706 (skip-syntax-backward " ")
0a2e512a 12707 (when (memq (preceding-char) '(?n ?N ?|))
3dcb36b7
JB
12708 (goto-char (point-max))))
12709 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12710
12711 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12712 ;; variables
12713 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
5eabfe72
KH
12714 '(vhdl-font-lock-match-item
12715 (progn (goto-char (match-end 1)) (match-beginning 2))
12716 nil (1 font-lock-variable-name-face)))
d2ddb974 12717 )
5eabfe72
KH
12718 "For consideration as a value of `vhdl-font-lock-keywords'.
12719This does context sensitive highlighting of names and labels.")
d2ddb974 12720
5eabfe72 12721(defvar vhdl-font-lock-keywords-3 nil
3dcb36b7 12722 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12723 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72
KH
12724This does highlighting of words with special syntax.")
12725
12726(defvar vhdl-font-lock-keywords-4 nil
3dcb36b7 12727 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12728 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12729This does highlighting of additional reserved words.")
d2ddb974 12730
5eabfe72
KH
12731(defconst vhdl-font-lock-keywords-5
12732 ;; background highlight translate-off regions
0a2e512a 12733 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
5eabfe72
KH
12734 "For consideration as a value of `vhdl-font-lock-keywords'.
12735This does background highlighting of translate-off regions.")
12736
12737;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12738;; Font and color definitions
12739
0a2e512a 12740(defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
d2ddb974
KH
12741 "Face name to use for prompts.")
12742
0a2e512a 12743(defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
5eabfe72
KH
12744 "Face name to use for standardized attributes.")
12745
0a2e512a 12746(defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
5eabfe72 12747 "Face name to use for standardized enumeration values.")
d2ddb974 12748
0a2e512a 12749(defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
5eabfe72 12750 "Face name to use for standardized functions and packages.")
d2ddb974 12751
0a2e512a 12752(defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
5eabfe72 12753 "Face name to use for directives.")
d2ddb974 12754
0a2e512a 12755(defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
5eabfe72 12756 "Face name to use for additional reserved words.")
d2ddb974 12757
0a2e512a 12758(defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
5eabfe72 12759 "Face name to use for translate-off regions.")
d2ddb974 12760
5eabfe72
KH
12761;; face names to use for words with special syntax.
12762(let ((syntax-alist vhdl-special-syntax-alist)
12763 name)
12764 (while syntax-alist
0a2e512a
RF
12765 (setq name (vhdl-function-name
12766 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
d4a5b644
GM
12767 (eval `(defvar ,name ',name
12768 ,(concat "Face name to use for "
12769 (nth 0 (car syntax-alist)) ".")))
5eabfe72
KH
12770 (setq syntax-alist (cdr syntax-alist))))
12771
3dcb36b7 12772(defgroup vhdl-highlight-faces nil
5eabfe72
KH
12773 "Faces for highlighting."
12774 :group 'vhdl-highlight)
d2ddb974 12775
3dcb36b7
JB
12776;; add faces used from `font-lock'
12777(custom-add-to-group
12778 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12779(custom-add-to-group
12780 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12781(custom-add-to-group
12782 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12783(custom-add-to-group
12784 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12785(custom-add-to-group
12786 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12787(custom-add-to-group
12788 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12789
0a2e512a 12790(defface vhdl-font-lock-prompt-face
f47877ee 12791 '((((min-colors 88) (class color) (background light))
ea81d57e 12792 (:foreground "Red1" :bold t))
f47877ee 12793 (((class color) (background light)) (:foreground "Red" :bold t))
3dcb36b7 12794 (((class color) (background dark)) (:foreground "Pink" :bold t))
d2ddb974 12795 (t (:inverse-video t)))
5eabfe72 12796 "Font lock mode face used to highlight prompts."
fa6674e3 12797 :group 'vhdl-highlight-faces)
d2ddb974 12798
0a2e512a 12799(defface vhdl-font-lock-attribute-face
5eabfe72
KH
12800 '((((class color) (background light)) (:foreground "Orchid"))
12801 (((class color) (background dark)) (:foreground "LightSteelBlue"))
3dcb36b7 12802 (t (:italic t :bold t)))
5eabfe72 12803 "Font lock mode face used to highlight standardized attributes."
fa6674e3 12804 :group 'vhdl-highlight-faces)
d2ddb974 12805
0a2e512a 12806(defface vhdl-font-lock-enumvalue-face
3dcb36b7 12807 '((((class color) (background light)) (:foreground "SaddleBrown"))
5eabfe72 12808 (((class color) (background dark)) (:foreground "BurlyWood"))
3dcb36b7 12809 (t (:italic t :bold t)))
5eabfe72 12810 "Font lock mode face used to highlight standardized enumeration values."
fa6674e3 12811 :group 'vhdl-highlight-faces)
d2ddb974 12812
0a2e512a 12813(defface vhdl-font-lock-function-face
3dcb36b7 12814 '((((class color) (background light)) (:foreground "Cyan4"))
5eabfe72 12815 (((class color) (background dark)) (:foreground "Orchid1"))
3dcb36b7 12816 (t (:italic t :bold t)))
5eabfe72 12817 "Font lock mode face used to highlight standardized functions and packages."
fa6674e3 12818 :group 'vhdl-highlight-faces)
d2ddb974 12819
0a2e512a 12820(defface vhdl-font-lock-directive-face
5eabfe72
KH
12821 '((((class color) (background light)) (:foreground "CadetBlue"))
12822 (((class color) (background dark)) (:foreground "Aquamarine"))
3dcb36b7 12823 (t (:italic t :bold t)))
5eabfe72 12824 "Font lock mode face used to highlight directives."
fa6674e3 12825 :group 'vhdl-highlight-faces)
d2ddb974 12826
0a2e512a 12827(defface vhdl-font-lock-reserved-words-face
3dcb36b7 12828 '((((class color) (background light)) (:foreground "Orange" :bold t))
5bb5087f 12829 (((min-colors 88) (class color) (background dark))
ea81d57e 12830 (:foreground "Yellow1" :bold t))
3dcb36b7 12831 (((class color) (background dark)) (:foreground "Yellow" :bold t))
d2ddb974 12832 (t ()))
5eabfe72 12833 "Font lock mode face used to highlight additional reserved words."
fa6674e3 12834 :group 'vhdl-highlight-faces)
d2ddb974 12835
0a2e512a 12836(defface vhdl-font-lock-translate-off-face
5eabfe72
KH
12837 '((((class color) (background light)) (:background "LightGray"))
12838 (((class color) (background dark)) (:background "DimGray"))
d2ddb974 12839 (t ()))
5eabfe72 12840 "Font lock mode face used to background highlight translate-off regions."
fa6674e3 12841 :group 'vhdl-highlight-faces)
d2ddb974 12842
5eabfe72
KH
12843;; font lock mode faces used to highlight words with special syntax.
12844(let ((syntax-alist vhdl-special-syntax-alist))
12845 (while syntax-alist
0a2e512a
RF
12846 (eval `(defface ,(vhdl-function-name
12847 "vhdl-font-lock" (caar syntax-alist) "face")
d4a5b644
GM
12848 '((((class color) (background light))
12849 (:foreground ,(nth 2 (car syntax-alist))))
12850 (((class color) (background dark))
12851 (:foreground ,(nth 3 (car syntax-alist))))
12852 (t ()))
12853 ,(concat "Font lock mode face used to highlight "
12854 (nth 0 (car syntax-alist)) ".")
fa6674e3 12855 :group 'vhdl-highlight-faces))
5eabfe72
KH
12856 (setq syntax-alist (cdr syntax-alist))))
12857
12858;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12859;; Font lock initialization
12860
12861(defun vhdl-font-lock-init ()
5eabfe72 12862 "Initialize fontification."
0a2e512a 12863 ;; highlight template prompts and directives
3dcb36b7
JB
12864 (setq vhdl-font-lock-keywords-0
12865 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12866 vhdl-template-prompt-syntax ">\\)")
0a2e512a 12867 2 'vhdl-font-lock-prompt-face t)
3dcb36b7
JB
12868 (list (concat "--\\s-*"
12869 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
0a2e512a
RF
12870 2 'vhdl-font-lock-directive-face t)
12871 ;; highlight c-preprocessor directives
12872 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12873 '(1 font-lock-builtin-face)
12874 '(3 font-lock-variable-name-face nil t))))
5eabfe72
KH
12875 ;; highlight keywords and standardized types, attributes, enumeration
12876 ;; values, and subprograms
12877 (setq vhdl-font-lock-keywords-1
12878 (list
0a2e512a
RF
12879 (list (concat "'" vhdl-attributes-regexp)
12880 1 'vhdl-font-lock-attribute-face)
5eabfe72 12881 (list vhdl-types-regexp 1 'font-lock-type-face)
0a2e512a
RF
12882 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12883 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12884 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
5eabfe72
KH
12885 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12886 ;; highlight words with special syntax.
12887 (setq vhdl-font-lock-keywords-3
12888 (let ((syntax-alist vhdl-special-syntax-alist)
12889 keywords)
12890 (while syntax-alist
12891 (setq keywords
12892 (cons
12893 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12894 (vhdl-function-name
0a2e512a 12895 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
5eabfe72
KH
12896 keywords))
12897 (setq syntax-alist (cdr syntax-alist)))
12898 keywords))
12899 ;; highlight additional reserved words
12900 (setq vhdl-font-lock-keywords-4
0a2e512a
RF
12901 (list (list vhdl-reserved-words-regexp 1
12902 'vhdl-font-lock-reserved-words-face)))
5eabfe72 12903 ;; highlight everything together
d2ddb974 12904 (setq vhdl-font-lock-keywords
5eabfe72
KH
12905 (append
12906 vhdl-font-lock-keywords-0
12907 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12908 (when (or vhdl-highlight-forbidden-words
12909 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12910 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12911 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12912 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12913
12914;; initialize fontification for VHDL Mode
12915(vhdl-font-lock-init)
12916
12917(defun vhdl-fontify-buffer ()
12918 "Re-initialize fontification and fontify buffer."
12919 (interactive)
12920 (setq font-lock-defaults
cf38dd42
SM
12921 `(vhdl-font-lock-keywords
12922 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
12923 beginning-of-line))
5eabfe72
KH
12924 (when (fboundp 'font-lock-unset-defaults)
12925 (font-lock-unset-defaults)) ; not implemented in XEmacs
0a2e512a 12926 (font-lock-set-defaults)
3dcb36b7
JB
12927 (font-lock-mode nil)
12928 (font-lock-mode t))
5eabfe72
KH
12929
12930;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12931;; Initialization for postscript printing
12932
12933(defun vhdl-ps-print-settings ()
12934 "Initialize custom face and page settings for postscript printing."
12935 ;; define custom face settings
12936 (unless (or (not vhdl-print-customize-faces)
d2ddb974
KH
12937 ps-print-color-p)
12938 (set (make-local-variable 'ps-bold-faces)
0a2e512a
RF
12939 '(font-lock-keyword-face
12940 font-lock-type-face
12941 vhdl-font-lock-attribute-face
12942 vhdl-font-lock-enumvalue-face
12943 vhdl-font-lock-directive-face))
d2ddb974
KH
12944 (set (make-local-variable 'ps-italic-faces)
12945 '(font-lock-comment-face
0a2e512a
RF
12946 font-lock-function-name-face
12947 font-lock-type-face
12948 vhdl-font-lock-attribute-face
12949 vhdl-font-lock-enumvalue-face
12950 vhdl-font-lock-directive-face))
d2ddb974
KH
12951 (set (make-local-variable 'ps-underlined-faces)
12952 '(font-lock-string-face))
5eabfe72 12953 (setq ps-always-build-face-reference t))
d2ddb974
KH
12954 ;; define page settings, so that a line containing 79 characters (default)
12955 ;; fits into one column
5eabfe72
KH
12956 (when vhdl-print-two-column
12957 (set (make-local-variable 'ps-landscape-mode) t)
12958 (set (make-local-variable 'ps-number-of-columns) 2)
12959 (set (make-local-variable 'ps-font-size) 7.0)
12960 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12961 (set (make-local-variable 'ps-header-font-size) 9.0)
12962 (set (make-local-variable 'ps-header-offset) 12.0)
12963 (when (eq ps-paper-type 'letter)
12964 (set (make-local-variable 'ps-inter-column) 40.0)
12965 (set (make-local-variable 'ps-left-margin) 40.0)
12966 (set (make-local-variable 'ps-right-margin) 40.0))))
12967
12968(defun vhdl-ps-print-init ()
12969 "Initialize postscript printing."
f8246027 12970 (if (featurep 'xemacs)
3dcb36b7
JB
12971 (when (boundp 'ps-print-color-p)
12972 (vhdl-ps-print-settings))
5eabfe72
KH
12973 (make-local-variable 'ps-print-hook)
12974 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12975
12976
12977;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12978;;; Hierarchy browser (using `speedbar.el')
12979;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12980;; Allows displaying the hierarchy of all VHDL design units contained in a
12981;; directory by using the speedbar.
12982
12983;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12984;; Variables
12985
12986(defvar vhdl-entity-alist nil
3dcb36b7
JB
12987 "Cache with entities and corresponding architectures for each
12988project/directory.")
5eabfe72 12989;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12990;; (cache-key
12991;; (ent-key ent-name ent-file ent-line
12992;; (arch-key arch-name arch-file arch-line
12993;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
0a2e512a
RF
12994;; inst-arch-key inst-conf-key inst-lib-key inst-path)
12995;; (lib-name pack-key))
12996;; mra-key (lib-name pack-key))
3dcb36b7
JB
12997
12998(defvar vhdl-config-alist nil
12999 "Cache with configurations for each project/directory.")
13000;; structure: (parenthesised expression means list of such entries)
13001;; (cache-key
13002;; (conf-key conf-name conf-file conf-line ent-key arch-key
13003;; (inst-key inst-comp-name inst-ent-key inst-arch-key
0a2e512a 13004;; inst-conf-key inst-lib-key)
3dcb36b7 13005;; (lib-name pack-key)))
5eabfe72
KH
13006
13007(defvar vhdl-package-alist nil
3dcb36b7 13008 "Cache with packages for each project/directory.")
5eabfe72 13009;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
13010;; (cache-key
13011;; (pack-key pack-name pack-file pack-line
13012;; (comp-key comp-name comp-file comp-line)
13013;; (func-key func-name func-file func-line)
13014;; (lib-name pack-key)
13015;; pack-body-file pack-body-line
13016;; (func-key func-name func-body-file func-body-line)
13017;; (lib-name pack-key)))
5eabfe72
KH
13018
13019(defvar vhdl-ent-inst-alist nil
3dcb36b7 13020 "Cache with instantiated entities for each project/directory.")
5eabfe72 13021;; structure: (parenthesised expression means list of such entries)
3dcb36b7 13022;; (cache-key (inst-ent-key))
5eabfe72 13023
3dcb36b7
JB
13024(defvar vhdl-file-alist nil
13025 "Cache with design units in each file for each project/directory.")
13026;; structure: (parenthesised expression means list of such entries)
13027;; (cache-key
13028;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
0a2e512a 13029;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
5eabfe72 13030
3dcb36b7
JB
13031(defvar vhdl-directory-alist nil
13032 "Cache with source directories for each project.")
13033;; structure: (parenthesised expression means list of such entries)
13034;; (cache-key (directory))
5eabfe72 13035
3dcb36b7 13036(defvar vhdl-speedbar-shown-unit-alist nil
5eabfe72
KH
13037 "Alist of design units simultaneously open in the current speedbar for each
13038directory and project.")
13039
3dcb36b7
JB
13040(defvar vhdl-speedbar-shown-project-list nil
13041 "List of projects simultaneously open in the current speedbar.")
5eabfe72 13042
3dcb36b7
JB
13043(defvar vhdl-updated-project-list nil
13044 "List of projects and directories with updated files.")
13045
13046(defvar vhdl-modified-file-list nil
13047 "List of modified files to be rescanned for hierarchy updating.")
13048
13049(defvar vhdl-speedbar-hierarchy-depth 0
13050 "Depth of instantiation hierarchy to display.")
13051
13052(defvar vhdl-speedbar-show-projects nil
13053 "Non-nil means project hierarchy is displayed in speedbar, directory
13054hierarchy otherwise.")
13055
13056(defun vhdl-get-end-of-unit ()
13057 "Return position of end of current unit."
13058 (let ((pos (point)))
13059 (save-excursion
13060 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13061 (save-excursion
13062 (goto-char (match-beginning 0))
13063 (vhdl-backward-syntactic-ws)
13064 (and (/= (preceding-char) ?\;) (not (bobp))))))
13065 (re-search-backward "^[ \t]*end\\>" pos 1)
13066 (point))))
13067
13068(defun vhdl-match-string-downcase (num &optional string)
13069 "Like `match-string-no-properties' with down-casing."
13070 (let ((match (match-string-no-properties num string)))
13071 (and match (downcase match))))
5eabfe72 13072
5eabfe72
KH
13073
13074;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13075;; Scan functions
13076
3dcb36b7
JB
13077(defun vhdl-scan-context-clause ()
13078 "Scan the context clause that preceeds a design unit."
13079 (let (lib-alist)
13080 (save-excursion
13081 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13082 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13083 (equal "USE" (upcase (match-string 1))))
13084 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13085 (setq lib-alist (cons (cons (match-string-no-properties 1)
13086 (vhdl-match-string-downcase 2))
13087 lib-alist))))))
13088 lib-alist))
13089
13090(defun vhdl-scan-directory-contents (name &optional project update num-string
13091 non-final)
a4c6cfad 13092 "Scan contents of VHDL files in directory or file pattern NAME."
3dcb36b7 13093 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
5eabfe72
KH
13094; (unless (file-directory-p (match-string 1 name))
13095; (message "No such directory: \"%s\"" (match-string 1 name)))
3dcb36b7
JB
13096 (let* ((dir-name (match-string 1 name))
13097 (file-pattern (match-string 2 name))
13098 (is-directory (= 0 (length file-pattern)))
5eabfe72 13099 (file-list
3dcb36b7
JB
13100 (if update
13101 (list name)
13102 (if is-directory
13103 (vhdl-get-source-files t dir-name)
13104 (vhdl-directory-files
13105 dir-name t (wildcard-to-regexp file-pattern)))))
13106 (key (or project dir-name))
13107 (file-exclude-regexp
13108 (or (nth 3 (aget vhdl-project-alist project)) ""))
13109 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13110 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13111 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13112 ent-alist conf-alist pack-alist ent-inst-list file-alist
13113 tmp-list tmp-entry no-files files-exist big-files)
13114 (when (or project update)
13115 (setq ent-alist (aget vhdl-entity-alist key t)
13116 conf-alist (aget vhdl-config-alist key t)
13117 pack-alist (aget vhdl-package-alist key t)
13118 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13119 file-alist (aget vhdl-file-alist key t)))
5eabfe72
KH
13120 (when (and (not is-directory) (null file-list))
13121 (message "No such file: \"%s\"" name))
3dcb36b7
JB
13122 (setq files-exist file-list)
13123 (when file-list
13124 (setq no-files (length file-list))
13125 (message "Scanning %s %s\"%s\"..."
13126 (if is-directory "directory" "files") (or num-string "") name)
13127 ;; exclude files
13128 (unless (equal file-exclude-regexp "")
13129 (let ((case-fold-search nil)
13130 file-tmp-list)
13131 (while file-list
13132 (unless (string-match file-exclude-regexp (car file-list))
13133 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13134 (setq file-list (cdr file-list)))
13135 (setq file-list (nreverse file-tmp-list))))
13136 ;; do for all files
13137 (while file-list
13138 (unless noninteractive
5eabfe72
KH
13139 (message "Scanning %s %s\"%s\"... (%2d%s)"
13140 (if is-directory "directory" "files")
13141 (or num-string "") name
3dcb36b7
JB
13142 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13143 (let ((file-name (abbreviate-file-name (car file-list)))
13144 ent-list arch-list arch-ent-list conf-list
13145 pack-list pack-body-list inst-list inst-ent-list)
13146 ;; scan file
13147 (vhdl-visit-file
13148 file-name nil
13149 (vhdl-prepare-search-2
13150 (save-excursion
13151 ;; scan for design units
13152 (if (and limit-design-file-size
13153 (< limit-design-file-size (buffer-size)))
13154 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13155 (setq big-files t))
13156 ;; scan for entities
13157 (goto-char (point-min))
13158 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13159 (let* ((ent-name (match-string-no-properties 1))
13160 (ent-key (downcase ent-name))
13161 (ent-entry (aget ent-alist ent-key t))
3dcb36b7
JB
13162 (lib-alist (vhdl-scan-context-clause)))
13163 (if (nth 1 ent-entry)
13164 (vhdl-warning-when-idle
13165 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13166 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13167 file-name (vhdl-current-line))
13168 (setq ent-list (cons ent-key ent-list))
13169 (aput 'ent-alist ent-key
13170 (list ent-name file-name (vhdl-current-line)
0a2e512a
RF
13171 (nth 3 ent-entry) (nth 4 ent-entry)
13172 lib-alist)))))
3dcb36b7
JB
13173 ;; scan for architectures
13174 (goto-char (point-min))
0a2e512a 13175 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
3dcb36b7
JB
13176 (let* ((arch-name (match-string-no-properties 1))
13177 (arch-key (downcase arch-name))
13178 (ent-name (match-string-no-properties 2))
13179 (ent-key (downcase ent-name))
13180 (ent-entry (aget ent-alist ent-key t))
13181 (arch-alist (nth 3 ent-entry))
13182 (arch-entry (aget arch-alist arch-key t))
13183 (lib-arch-alist (vhdl-scan-context-clause)))
13184 (if arch-entry
13185 (vhdl-warning-when-idle
13186 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13187 arch-name ent-name (nth 1 arch-entry)
13188 (nth 2 arch-entry) file-name (vhdl-current-line))
13189 (setq arch-list (cons arch-key arch-list)
13190 arch-ent-list (cons ent-key arch-ent-list))
13191 (aput 'arch-alist arch-key
13192 (list arch-name file-name (vhdl-current-line) nil
13193 lib-arch-alist))
13194 (aput 'ent-alist ent-key
13195 (list (or (nth 0 ent-entry) ent-name)
13196 (nth 1 ent-entry) (nth 2 ent-entry)
13197 (vhdl-sort-alist arch-alist)
0a2e512a 13198 arch-key (nth 5 ent-entry))))))
3dcb36b7
JB
13199 ;; scan for configurations
13200 (goto-char (point-min))
13201 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13202 (let* ((conf-name (match-string-no-properties 1))
13203 (conf-key (downcase conf-name))
13204 (conf-entry (aget conf-alist conf-key t))
13205 (ent-name (match-string-no-properties 2))
13206 (ent-key (downcase ent-name))
13207 (lib-alist (vhdl-scan-context-clause))
13208 (conf-line (vhdl-current-line))
13209 (end-of-unit (vhdl-get-end-of-unit))
13210 arch-key comp-conf-list inst-key-list
13211 inst-comp-key inst-ent-key inst-arch-key
13212 inst-conf-key inst-lib-key)
13213 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13214 (setq arch-key (vhdl-match-string-downcase 1)))
13215 (if conf-entry
13216 (vhdl-warning-when-idle
13217 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13218 conf-name ent-name (nth 1 conf-entry)
13219 (nth 2 conf-entry) file-name conf-line)
13220 (setq conf-list (cons conf-key conf-list))
13221 ;; scan for subconfigurations and subentities
13222 (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)
13223 (setq inst-comp-key (vhdl-match-string-downcase 3)
13224 inst-key-list (split-string
13225 (vhdl-match-string-downcase 1)
13226 "[ \t\n]*,[ \t\n]*"))
13227 (vhdl-forward-syntactic-ws)
13228 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13229 (setq
13230 inst-lib-key (vhdl-match-string-downcase 3)
13231 inst-ent-key (and (match-string 2)
13232 (vhdl-match-string-downcase 4))
13233 inst-arch-key (and (match-string 2)
13234 (vhdl-match-string-downcase 6))
13235 inst-conf-key (and (not (match-string 2))
13236 (vhdl-match-string-downcase 4)))
13237 (while inst-key-list
13238 (setq comp-conf-list
13239 (cons (list (car inst-key-list)
13240 inst-comp-key inst-ent-key
13241 inst-arch-key inst-conf-key
13242 inst-lib-key)
13243 comp-conf-list))
13244 (setq inst-key-list (cdr inst-key-list)))))
13245 (aput 'conf-alist conf-key
13246 (list conf-name file-name conf-line ent-key
13247 arch-key comp-conf-list lib-alist)))))
13248 ;; scan for packages
13249 (goto-char (point-min))
13250 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13251 (let* ((pack-name (match-string-no-properties 2))
13252 (pack-key (downcase pack-name))
13253 (is-body (match-string-no-properties 1))
13254 (pack-entry (aget pack-alist pack-key t))
13255 (pack-line (vhdl-current-line))
13256 (end-of-unit (vhdl-get-end-of-unit))
13257 comp-name func-name comp-alist func-alist lib-alist)
13258 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13259 (vhdl-warning-when-idle
13260 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13261 (if is-body " body" "") pack-name
13262 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13263 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13264 file-name (vhdl-current-line))
13265 ;; scan for context clauses
13266 (setq lib-alist (vhdl-scan-context-clause))
13267 ;; scan for component and subprogram declarations/bodies
13268 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13269 (if (equal (upcase (match-string 1)) "COMPONENT")
13270 (setq comp-name (match-string-no-properties 2)
13271 comp-alist
13272 (cons (list (downcase comp-name) comp-name
13273 file-name (vhdl-current-line))
13274 comp-alist))
13275 (setq func-name (match-string-no-properties 2)
13276 func-alist
13277 (cons (list (downcase func-name) func-name
13278 file-name (vhdl-current-line))
13279 func-alist))))
13280 (setq func-alist (nreverse func-alist))
13281 (setq comp-alist (nreverse comp-alist))
13282 (if is-body
13283 (setq pack-body-list (cons pack-key pack-body-list))
13284 (setq pack-list (cons pack-key pack-list)))
13285 (aput
13286 'pack-alist pack-key
13287 (if is-body
13288 (list (or (nth 0 pack-entry) pack-name)
13289 (nth 1 pack-entry) (nth 2 pack-entry)
13290 (nth 3 pack-entry) (nth 4 pack-entry)
13291 (nth 5 pack-entry)
13292 file-name pack-line func-alist lib-alist)
13293 (list pack-name file-name pack-line
13294 comp-alist func-alist lib-alist
13295 (nth 6 pack-entry) (nth 7 pack-entry)
13296 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13297 ;; scan for hierarchy
13298 (if (and limit-hier-file-size
13299 (< limit-hier-file-size (buffer-size)))
13300 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13301 (setq big-files t))
13302 ;; scan for architectures
13303 (goto-char (point-min))
13304 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13305 (let* ((ent-name (match-string-no-properties 2))
13306 (ent-key (downcase ent-name))
13307 (arch-name (match-string-no-properties 1))
13308 (arch-key (downcase arch-name))
13309 (ent-entry (aget ent-alist ent-key t))
13310 (arch-alist (nth 3 ent-entry))
13311 (arch-entry (aget arch-alist arch-key t))
13312 (beg-of-unit (point))
13313 (end-of-unit (vhdl-get-end-of-unit))
13314 (inst-no 0)
0a2e512a 13315 inst-alist inst-path)
3dcb36b7
JB
13316 ;; scan for contained instantiations
13317 (while (and (re-search-forward
13318 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13319 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13320 "component[ \t\n]+\\(\\w+\\)\\|"
0a2e512a
RF
13321 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13322 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13323 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
3dcb36b7
JB
13324 (or (not limit-hier-inst-no)
13325 (<= (setq inst-no (1+ inst-no))
13326 limit-hier-inst-no)))
0a2e512a
RF
13327 (cond
13328 ;; block/generate beginning found
13329 ((match-string 14)
13330 (setq inst-path
13331 (cons (match-string-no-properties 1) inst-path)))
13332 ;; block/generate end found
13333 ((match-string 16)
13334 (setq inst-path (cdr inst-path)))
13335 ;; instantiation found
13336 (t
13337 (let* ((inst-name (match-string-no-properties 1))
13338 (inst-key (downcase inst-name))
13339 (inst-comp-name
13340 (or (match-string-no-properties 3)
13341 (match-string-no-properties 6)))
13342 (inst-ent-key
13343 (or (and (match-string 8)
13344 (vhdl-match-string-downcase 11))
13345 (and inst-comp-name
13346 (downcase inst-comp-name))))
13347 (inst-arch-key (vhdl-match-string-downcase 13))
13348 (inst-conf-key
13349 (and (not (match-string 8))
13350 (vhdl-match-string-downcase 11)))
13351 (inst-lib-key (vhdl-match-string-downcase 10)))
13352 (goto-char (match-end 1))
13353 (setq inst-list (cons inst-key inst-list)
13354 inst-ent-list
13355 (cons inst-ent-key inst-ent-list))
13356 (setq inst-alist
13357 (append
13358 inst-alist
13359 (list (list inst-key inst-name file-name
13360 (vhdl-current-line) inst-comp-name
13361 inst-ent-key inst-arch-key
13362 inst-conf-key inst-lib-key
13363 (reverse inst-path)))))))))
3dcb36b7
JB
13364 ;; scan for contained configuration specifications
13365 (goto-char beg-of-unit)
13366 (while (re-search-forward
13367 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13368 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
0a2e512a 13369 (let* ((inst-comp-name (match-string-no-properties 3))
3dcb36b7
JB
13370 (inst-ent-key
13371 (and (match-string 6)
13372 (vhdl-match-string-downcase 9)))
13373 (inst-arch-key (vhdl-match-string-downcase 11))
13374 (inst-conf-key
13375 (and (not (match-string 6))
13376 (vhdl-match-string-downcase 9)))
13377 (inst-lib-key (vhdl-match-string-downcase 8))
13378 (inst-key-list
13379 (split-string (vhdl-match-string-downcase 1)
13380 "[ \t\n]*,[ \t\n]*"))
13381 (tmp-inst-alist inst-alist)
13382 inst-entry)
13383 (while tmp-inst-alist
13384 (when (and (or (equal "all" (car inst-key-list))
13385 (member (nth 0 (car tmp-inst-alist))
13386 inst-key-list))
13387 (equal
13388 (downcase
13389 (or (nth 4 (car tmp-inst-alist)) ""))
13390 (downcase inst-comp-name)))
13391 (setq inst-entry (car tmp-inst-alist))
13392 (setq inst-ent-list
13393 (cons (or inst-ent-key (nth 5 inst-entry))
13394 (vhdl-delete
13395 (nth 5 inst-entry) inst-ent-list)))
13396 (setq inst-entry
13397 (list (nth 0 inst-entry) (nth 1 inst-entry)
13398 (nth 2 inst-entry) (nth 3 inst-entry)
13399 (nth 4 inst-entry)
13400 (or inst-ent-key (nth 5 inst-entry))
13401 (or inst-arch-key (nth 6 inst-entry))
13402 inst-conf-key inst-lib-key))
13403 (setcar tmp-inst-alist inst-entry))
13404 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13405 ;; save in cache
13406 (aput 'arch-alist arch-key
13407 (list (nth 0 arch-entry) (nth 1 arch-entry)
13408 (nth 2 arch-entry) inst-alist
13409 (nth 4 arch-entry)))
13410 (aput 'ent-alist ent-key
13411 (list (nth 0 ent-entry) (nth 1 ent-entry)
13412 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
0a2e512a 13413 (nth 4 ent-entry) (nth 5 ent-entry)))
3dcb36b7
JB
13414 (when (and limit-hier-inst-no
13415 (> inst-no limit-hier-inst-no))
13416 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13417 (setq big-files t))
13418 (goto-char end-of-unit))))
13419 ;; remember design units for this file
13420 (aput 'file-alist file-name
13421 (list ent-list arch-list arch-ent-list conf-list
13422 pack-list pack-body-list inst-list inst-ent-list))
13423 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13424 (setq file-list (cdr file-list))))
13425 (when (or (and (not project) files-exist)
13426 (and project (not non-final)))
13427 ;; consistency checks:
13428 ;; check whether each architecture has a corresponding entity
13429 (setq tmp-list ent-alist)
13430 (while tmp-list
13431 (when (null (nth 2 (car tmp-list)))
13432 (setq tmp-entry (car (nth 4 (car tmp-list))))
13433 (vhdl-warning-when-idle
13434 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13435 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13436 (nth 3 tmp-entry)))
13437 (setq tmp-list (cdr tmp-list)))
13438 ;; check whether configuration has a corresponding entity/architecture
13439 (setq tmp-list conf-alist)
13440 (while tmp-list
13441 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13442 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13443 (setq tmp-entry (car tmp-list))
13444 (vhdl-warning-when-idle
13445 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13446 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13447 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13448 (setq tmp-entry (car tmp-list))
13449 (vhdl-warning-when-idle
13450 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13451 (nth 1 tmp-entry) (nth 4 tmp-entry)
13452 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13453 (setq tmp-list (cdr tmp-list)))
13454 ;; check whether each package body has a package declaration
13455 (setq tmp-list pack-alist)
13456 (while tmp-list
13457 (when (null (nth 2 (car tmp-list)))
13458 (setq tmp-entry (car tmp-list))
13459 (vhdl-warning-when-idle
13460 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13461 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13462 (setq tmp-list (cdr tmp-list)))
13463 ;; sort lists
13464 (setq ent-alist (vhdl-sort-alist ent-alist))
13465 (setq conf-alist (vhdl-sort-alist conf-alist))
13466 (setq pack-alist (vhdl-sort-alist pack-alist))
13467 ;; remember updated directory/project
13468 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13469 ;; clear directory alists
13470 (unless project
13471 (adelete 'vhdl-entity-alist key)
13472 (adelete 'vhdl-config-alist key)
13473 (adelete 'vhdl-package-alist key)
13474 (adelete 'vhdl-ent-inst-alist key)
13475 (adelete 'vhdl-file-alist key))
13476 ;; put directory contents into cache
13477 (aput 'vhdl-entity-alist key ent-alist)
13478 (aput 'vhdl-config-alist key conf-alist)
13479 (aput 'vhdl-package-alist key pack-alist)
13480 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13481 (aput 'vhdl-file-alist key file-alist)
13482 ;; final messages
13483 (message "Scanning %s %s\"%s\"...done"
13484 (if is-directory "directory" "files") (or num-string "") name)
13485 (unless project (message "Scanning directory...done"))
13486 (when big-files
13487 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13488 ;; save cache when scanned non-interactively
13489 (when (or (not project) (not non-final))
13490 (when (and noninteractive vhdl-speedbar-save-cache)
13491 (vhdl-save-cache key)))
13492 t))
5eabfe72 13493
3dcb36b7 13494(defun vhdl-scan-project-contents (project)
5eabfe72
KH
13495 "Scan the contents of all VHDL files found in the directories and files
13496of PROJECT."
3dcb36b7
JB
13497 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13498 (default-dir (vhdl-resolve-env-variable
13499 (nth 1 (aget vhdl-project-alist project))))
13500 (file-exclude-regexp
13501 (or (nth 3 (aget vhdl-project-alist project)) ""))
13502 dir-list-tmp dir dir-name num-dir act-dir recursive)
13503 ;; clear project alists
13504 (adelete 'vhdl-entity-alist project)
13505 (adelete 'vhdl-config-alist project)
13506 (adelete 'vhdl-package-alist project)
13507 (adelete 'vhdl-ent-inst-alist project)
13508 (adelete 'vhdl-file-alist project)
13509 ;; expand directory names by default-directory
13510 (message "Collecting source files...")
13511 (while dir-list
13512 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13513 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13514 (setq recursive (match-string 1 dir)
13515 dir-name (match-string 3 dir))
13516 (setq dir-list-tmp
13517 (cons (concat recursive
13518 (if (file-name-absolute-p dir-name) "" default-dir)
13519 dir-name)
13520 dir-list-tmp))
13521 (setq dir-list (cdr dir-list)))
13522 ;; resolve path wildcards
5eabfe72
KH
13523 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13524 ;; expand directories
13525 (while dir-list-tmp
13526 (setq dir (car dir-list-tmp))
13527 ;; get subdirectories
3dcb36b7 13528 (if (string-match "-r \\(.*[/\\]\\)" dir)
5eabfe72
KH
13529 (setq dir-list (append dir-list (vhdl-get-subdirs
13530 (match-string 1 dir))))
13531 (setq dir-list (append dir-list (list dir))))
13532 (setq dir-list-tmp (cdr dir-list-tmp)))
3dcb36b7
JB
13533 ;; exclude files
13534 (unless (equal file-exclude-regexp "")
13535 (let ((case-fold-search nil))
13536 (while dir-list
13537 (unless (string-match file-exclude-regexp (car dir-list))
13538 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13539 (setq dir-list (cdr dir-list)))
13540 (setq dir-list (nreverse dir-list-tmp))))
13541 (message "Collecting source files...done")
13542 ;; scan for design units for each directory in DIR-LIST
13543 (setq dir-list-tmp nil
13544 num-dir (length dir-list)
5eabfe72
KH
13545 act-dir 1)
13546 (while dir-list
3dcb36b7
JB
13547 (setq dir-name (abbreviate-file-name
13548 (expand-file-name (car dir-list))))
13549 (vhdl-scan-directory-contents dir-name project nil
13550 (format "(%s/%s) " act-dir num-dir)
13551 (cdr dir-list))
13552 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
5eabfe72
KH
13553 (setq dir-list (cdr dir-list)
13554 act-dir (1+ act-dir)))
3dcb36b7
JB
13555 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13556 (message "Scanning project \"%s\"...done" project)))
13557
13558(defun vhdl-update-file-contents (file-name)
13559 "Update hierarchy information by contents of current buffer."
13560 (setq file-name (abbreviate-file-name file-name))
13561 (let* ((dir-name (file-name-directory file-name))
13562 (directory-alist vhdl-directory-alist)
13563 updated)
13564 (while directory-alist
13565 (when (member dir-name (nth 1 (car directory-alist)))
13566 (let* ((vhdl-project (nth 0 (car directory-alist)))
13567 (project (vhdl-project-p))
13568 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13569 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13570 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13571 (ent-inst-list (car (aget vhdl-ent-inst-alist
13572 (or project dir-name) t)))
13573 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13574 (file-entry (aget file-alist file-name t))
13575 (ent-list (nth 0 file-entry))
13576 (arch-list (nth 1 file-entry))
13577 (arch-ent-list (nth 2 file-entry))
13578 (conf-list (nth 3 file-entry))
13579 (pack-list (nth 4 file-entry))
13580 (pack-body-list (nth 5 file-entry))
13581 (inst-ent-list (nth 7 file-entry))
13582 (cache-key (or project dir-name))
13583 arch-alist key ent-key entry)
13584 ;; delete design units previously contained in this file:
13585 ;; entities
13586 (while ent-list
13587 (setq key (car ent-list)
13588 entry (aget ent-alist key t))
13589 (when (equal file-name (nth 1 entry))
13590 (if (nth 3 entry)
13591 (aput 'ent-alist key
13592 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13593 (adelete 'ent-alist key)))
13594 (setq ent-list (cdr ent-list)))
13595 ;; architectures
13596 (while arch-list
13597 (setq key (car arch-list)
13598 ent-key (car arch-ent-list)
13599 entry (aget ent-alist ent-key t)
13600 arch-alist (nth 3 entry))
13601 (when (equal file-name (nth 1 (aget arch-alist key t)))
13602 (adelete 'arch-alist key)
13603 (if (or (nth 1 entry) arch-alist)
13604 (aput 'ent-alist ent-key
13605 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
0a2e512a 13606 arch-alist (nth 4 entry) (nth 5 entry)))
3dcb36b7
JB
13607 (adelete 'ent-alist ent-key)))
13608 (setq arch-list (cdr arch-list)
13609 arch-ent-list (cdr arch-ent-list)))
13610 ;; configurations
13611 (while conf-list
13612 (setq key (car conf-list))
13613 (when (equal file-name (nth 1 (aget conf-alist key t)))
13614 (adelete 'conf-alist key))
13615 (setq conf-list (cdr conf-list)))
13616 ;; package declarations
13617 (while pack-list
13618 (setq key (car pack-list)
13619 entry (aget pack-alist key t))
13620 (when (equal file-name (nth 1 entry))
13621 (if (nth 6 entry)
13622 (aput 'pack-alist key
13623 (list (nth 0 entry) nil nil nil nil nil
13624 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13625 (nth 9 entry)))
13626 (adelete 'pack-alist key)))
13627 (setq pack-list (cdr pack-list)))
13628 ;; package bodies
13629 (while pack-body-list
13630 (setq key (car pack-body-list)
13631 entry (aget pack-alist key t))
13632 (when (equal file-name (nth 6 entry))
13633 (if (nth 1 entry)
13634 (aput 'pack-alist key
13635 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13636 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13637 nil nil nil nil))
13638 (adelete 'pack-alist key)))
13639 (setq pack-body-list (cdr pack-body-list)))
13640 ;; instantiated entities
13641 (while inst-ent-list
13642 (setq ent-inst-list
13643 (vhdl-delete (car inst-ent-list) ent-inst-list))
13644 (setq inst-ent-list (cdr inst-ent-list)))
13645 ;; update caches
13646 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13647 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13648 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13649 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13650 ;; scan file
13651 (vhdl-scan-directory-contents file-name project t)
13652 (when (or (and vhdl-speedbar-show-projects project)
13653 (and (not vhdl-speedbar-show-projects) (not project)))
13654 (vhdl-speedbar-refresh project))
13655 (setq updated t)))
13656 (setq directory-alist (cdr directory-alist)))
13657 updated))
13658
13659(defun vhdl-update-hierarchy ()
13660 "Update directory and hierarchy information in speedbar."
13661 (let ((file-list (reverse vhdl-modified-file-list))
13662 updated)
13663 (when (and vhdl-speedbar-update-on-saving file-list)
13664 (while file-list
13665 (setq updated
13666 (or (vhdl-update-file-contents (car file-list))
13667 updated))
13668 (setq file-list (cdr file-list)))
13669 (setq vhdl-modified-file-list nil)
0a2e512a 13670 (vhdl-speedbar-update-current-unit)
3dcb36b7
JB
13671 (when updated (message "Updating hierarchy...done")))))
13672
13673;; structure (parenthesised expression means list of such entries)
13674;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13675;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13676;; comp-lib-name level)
13677(defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13678 conf-inst-alist level indent
13679 &optional include-top ent-hier)
13680 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13681entity ENT-KEY."
13682 (let* ((ent-entry (aget ent-alist ent-key t))
13683 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13684 (cdar (last (nth 3 ent-entry)))))
13685 (inst-alist (nth 3 arch-entry))
13686 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13687 hier-list subcomp-list tmp-list inst-key inst-comp-name
13688 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
5eabfe72 13689 (when (= level 0) (message "Extract design hierarchy..."))
3dcb36b7
JB
13690 (when include-top
13691 (setq level (1+ level)))
13692 (when (member ent-key ent-hier)
13693 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13694 ;; check configured architecture (already checked during scanning)
13695; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13696; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13697 ;; process all instances
13698 (while inst-alist
13699 (setq inst-entry (car inst-alist)
13700 inst-key (nth 0 inst-entry)
13701 inst-comp-name (nth 4 inst-entry)
13702 inst-conf-key (nth 7 inst-entry))
13703 ;; search entry in configuration's instantiations list
13704 (setq tmp-list conf-inst-alist)
13705 (while (and tmp-list
13706 (not (and (member (nth 0 (car tmp-list))
13707 (list "all" inst-key))
13708 (equal (nth 1 (car tmp-list))
13709 (downcase (or inst-comp-name ""))))))
13710 (setq tmp-list (cdr tmp-list)))
13711 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13712 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13713 (when (and inst-conf-key (not inst-conf-entry))
13714 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13715 ;; determine entity
13716 (setq inst-ent-key
13717 (or (nth 2 (car tmp-list)) ; from configuration
13718 (nth 3 inst-conf-entry) ; from subconfiguration
13719 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13720 ; from configuration spec.
13721 (nth 5 inst-entry))) ; from direct instantiation
13722 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13723 ;; determine architecture
13724 (setq inst-arch-key
0a2e512a
RF
13725 (or (nth 3 (car tmp-list)) ; from configuration
13726 (nth 4 inst-conf-entry) ; from subconfiguration
13727 (nth 6 inst-entry) ; from direct instantiation
3dcb36b7 13728 (nth 4 (aget conf-alist (nth 7 inst-entry)))
0a2e512a
RF
13729 ; from configuration spec.
13730 (nth 4 inst-ent-entry) ; MRA
13731 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
3dcb36b7
JB
13732 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13733 ;; set library
13734 (setq inst-lib-key
0a2e512a
RF
13735 (or (nth 5 (car tmp-list)) ; from configuration
13736 (nth 8 inst-entry))) ; from direct instantiation
3dcb36b7
JB
13737 ;; gather information for this instance
13738 (setq comp-entry
13739 (list (nth 1 inst-entry)
13740 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13741 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13742 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13743 (or (nth 0 inst-arch-entry) inst-arch-key)
13744 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13745 (or (nth 0 inst-conf-entry) inst-conf-key)
13746 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13747 inst-lib-key level))
13748 ;; get subcomponent hierarchy
13749 (setq subcomp-list (vhdl-get-hierarchy
13750 ent-alist conf-alist
13751 inst-ent-key inst-arch-key inst-conf-key
13752 (nth 5 inst-conf-entry)
13753 (1+ level) indent nil (cons ent-key ent-hier)))
13754 ;; add to list
13755 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13756 (setq inst-alist (cdr inst-alist)))
13757 (when include-top
5eabfe72 13758 (setq hier-list
3dcb36b7
JB
13759 (cons (list nil nil (nth 0 ent-entry)
13760 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13761 (nth 0 arch-entry)
13762 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13763 nil nil
13764 nil (1- level))
13765 hier-list)))
13766 (when (or (= level 0) (and include-top (= level 1))) (message ""))
5eabfe72
KH
13767 hier-list))
13768
3dcb36b7
JB
13769(defun vhdl-get-instantiations (ent-key indent)
13770 "Get all instantiations of entity ENT-KEY."
13771 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
5eabfe72
KH
13772 arch-alist inst-alist ent-inst-list
13773 ent-entry arch-entry inst-entry)
13774 (while ent-alist
13775 (setq ent-entry (car ent-alist))
3dcb36b7 13776 (setq arch-alist (nth 4 ent-entry))
5eabfe72
KH
13777 (while arch-alist
13778 (setq arch-entry (car arch-alist))
3dcb36b7 13779 (setq inst-alist (nth 4 arch-entry))
5eabfe72
KH
13780 (while inst-alist
13781 (setq inst-entry (car inst-alist))
3dcb36b7 13782 (when (equal ent-key (nth 5 inst-entry))
5eabfe72 13783 (setq ent-inst-list
3dcb36b7
JB
13784 (cons (list (nth 1 inst-entry)
13785 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13786 (nth 1 ent-entry)
13787 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13788 (nth 1 arch-entry)
13789 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13790 ent-inst-list)))
5eabfe72
KH
13791 (setq inst-alist (cdr inst-alist)))
13792 (setq arch-alist (cdr arch-alist)))
13793 (setq ent-alist (cdr ent-alist)))
13794 (nreverse ent-inst-list)))
13795
13796;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
13797;; Caching in file
13798
13799(defun vhdl-save-caches ()
13800 "Save all updated hierarchy caches to file."
13801 (interactive)
13802 (condition-case nil
13803 (when vhdl-speedbar-save-cache
13804 ;; update hierarchy
13805 (vhdl-update-hierarchy)
13806 (let ((project-list vhdl-updated-project-list))
13807 (message "Saving hierarchy caches...")
13808 ;; write updated project caches
13809 (while project-list
13810 (vhdl-save-cache (car project-list))
13811 (setq project-list (cdr project-list)))
13812 (message "Saving hierarchy caches...done")))
b65d82ca 13813 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
3dcb36b7
JB
13814 (sit-for 2)))))
13815
13816(defun vhdl-save-cache (key)
13817 "Save current hierarchy cache to file."
13818 (let* ((orig-buffer (current-buffer))
13819 (vhdl-project key)
13820 (project (vhdl-project-p))
13821 (default-directory key)
13822 (directory (abbreviate-file-name (vhdl-default-directory)))
13823 (file-name (vhdl-resolve-env-variable
13824 (vhdl-replace-string
13825 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13826 (concat
13827 (subst-char-in-string ? ?_ (or project "dir"))
13828 " " (user-login-name)))))
13829 (file-dir-name (expand-file-name file-name directory))
13830 (cache-key (or project directory))
13831 (key (if project "project" "directory")))
13832 (unless (file-exists-p (file-name-directory file-dir-name))
13833 (make-directory (file-name-directory file-dir-name) t))
13834 (if (not (file-writable-p file-dir-name))
13835 (progn (vhdl-warning (format "File not writable: \"%s\""
13836 (abbreviate-file-name file-dir-name)))
13837 (sit-for 2))
13838 (message "Saving cache: \"%s\"" file-dir-name)
13839 (set-buffer (find-file-noselect file-dir-name t t))
13840 (erase-buffer)
13841 (insert ";; -*- Emacs-Lisp -*-\n\n"
13842 ";;; " (file-name-nondirectory file-name)
13843 " - design hierarchy cache file for Emacs VHDL Mode "
13844 vhdl-version "\n")
13845 (insert "\n;; " (if project "Project " "Directory") " : ")
13846 (if project (insert project) (prin1 directory (current-buffer)))
13847 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13848 (user-login-name) "\n\n"
13849 "\n;; version number\n"
13850 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13851 "\n;; " (if project "project" "directory") " name"
13852 "\n(setq " key " ")
13853 (prin1 (or project directory) (current-buffer))
13854 (insert ")\n")
13855 (when (member 'hierarchy vhdl-speedbar-save-cache)
13856 (insert "\n;; entity and architecture cache\n"
13857 "(aput 'vhdl-entity-alist " key " '")
13858 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13859 (insert ")\n\n;; configuration cache\n"
13860 "(aput 'vhdl-config-alist " key " '")
13861 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13862 (insert ")\n\n;; package cache\n"
13863 "(aput 'vhdl-package-alist " key " '")
13864 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13865 (insert ")\n\n;; instantiated entities cache\n"
13866 "(aput 'vhdl-ent-inst-alist " key " '")
13867 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13868 (insert ")\n\n;; design units per file cache\n"
13869 "(aput 'vhdl-file-alist " key " '")
13870 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13871 (when project
13872 (insert ")\n\n;; source directories in project cache\n"
13873 "(aput 'vhdl-directory-alist " key " '")
13874 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13875 (insert ")\n"))
13876 (when (member 'display vhdl-speedbar-save-cache)
13877 (insert "\n;; shown design units cache\n"
13878 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13879 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13880 (current-buffer))
13881 (insert ")\n"))
13882 (setq vhdl-updated-project-list
13883 (delete cache-key vhdl-updated-project-list))
13884 (save-buffer)
13885 (kill-buffer (current-buffer))
13886 (set-buffer orig-buffer))))
13887
13888(defun vhdl-load-cache (key)
13889 "Load hierarchy cache information from file."
13890 (let* ((vhdl-project key)
13891 (default-directory key)
13892 (directory (vhdl-default-directory))
13893 (file-name (vhdl-resolve-env-variable
13894 (vhdl-replace-string
13895 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13896 (concat
13897 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13898 " " (user-login-name)))))
13899 (file-dir-name (expand-file-name file-name directory))
13900 vhdl-cache-version)
13901 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13902 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13903 (when (file-exists-p file-dir-name)
13904 (condition-case ()
13905 (progn (load-file file-dir-name)
13906 (string< (mapconcat
027a4b6b 13907 (lambda (a) (format "%3d" (string-to-number a)))
0a2e512a 13908 (split-string "3.33" "\\.") "")
3dcb36b7 13909 (mapconcat
027a4b6b 13910 (lambda (a) (format "%3d" (string-to-number a)))
3dcb36b7
JB
13911 (split-string vhdl-cache-version "\\.") "")))
13912 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13913 nil))))))
13914
13915(defun vhdl-require-hierarchy-info ()
13916 "Make sure that hierarchy information is available. Load cache or scan files
13917if required."
13918 (if (vhdl-project-p)
13919 (unless (or (assoc vhdl-project vhdl-file-alist)
13920 (vhdl-load-cache vhdl-project))
13921 (vhdl-scan-project-contents vhdl-project))
13922 (let ((directory (abbreviate-file-name default-directory)))
13923 (unless (or (assoc directory vhdl-file-alist)
13924 (vhdl-load-cache directory))
13925 (vhdl-scan-directory-contents directory)))))
13926
13927;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13928;; Add hierarchy browser functionality to speedbar
5eabfe72
KH
13929
13930(defvar vhdl-speedbar-key-map nil
13931 "Keymap used when in the VHDL hierarchy browser mode.")
13932
3dcb36b7 13933(defvar vhdl-speedbar-menu-items nil
5eabfe72
KH
13934 "Additional menu-items to add to speedbar frame.")
13935
13936(defun vhdl-speedbar-initialize ()
13937 "Initialize speedbar."
13938 ;; general settings
13939; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13940 ;; VHDL file extensions (extracted from `auto-mode-alist')
13941 (let ((mode-alist auto-mode-alist))
13942 (while mode-alist
3dcb36b7
JB
13943 (when (eq (cdar mode-alist) 'vhdl-mode)
13944 (speedbar-add-supported-extension (caar mode-alist)))
5eabfe72
KH
13945 (setq mode-alist (cdr mode-alist))))
13946 ;; hierarchy browser settings
13947 (when (boundp 'speedbar-mode-functions-list)
3dcb36b7 13948 ;; special functions
5eabfe72 13949 (speedbar-add-mode-functions-list
3dcb36b7 13950 '("vhdl directory"
5eabfe72 13951 (speedbar-item-info . vhdl-speedbar-item-info)
7752250e 13952 (speedbar-line-directory . speedbar-files-line-path)))
3dcb36b7
JB
13953 (speedbar-add-mode-functions-list
13954 '("vhdl project"
13955 (speedbar-item-info . vhdl-speedbar-item-info)
7752250e 13956 (speedbar-line-directory . vhdl-speedbar-line-project)))
3dcb36b7 13957 ;; keymap
5eabfe72
KH
13958 (unless vhdl-speedbar-key-map
13959 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13960 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13961 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13962 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
3dcb36b7
JB
13963 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13964 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13965 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13966 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13967 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
0a2e512a
RF
13968 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13969 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
3dcb36b7
JB
13970 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13971 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13972 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13973 (let ((key 0))
13974 (while (<= key 9)
13975 (define-key vhdl-speedbar-key-map (int-to-string key)
13976 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13977 (setq key (1+ key)))))
5eabfe72
KH
13978 (define-key speedbar-key-map "h"
13979 (lambda () (interactive)
3dcb36b7
JB
13980 (speedbar-change-initial-expansion-list "vhdl directory")))
13981 (define-key speedbar-key-map "H"
13982 (lambda () (interactive)
13983 (speedbar-change-initial-expansion-list "vhdl project")))
13984 ;; menu
13985 (unless vhdl-speedbar-menu-items
13986 (setq
13987 vhdl-speedbar-menu-items
13988 `(["Edit" speedbar-edit-line t]
13989 ["Expand" speedbar-expand-line
13990 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13991 ["Contract" vhdl-speedbar-contract-level t]
13992 ["Expand All" vhdl-speedbar-expand-all t]
13993 ["Contract All" vhdl-speedbar-contract-all t]
13994 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13995 (while (<= key 9)
13996 (setq menu-list
13997 (cons `[,(if (= key 0) "All" (int-to-string key))
13998 (vhdl-speedbar-set-depth ,key)
13999 :style radio
14000 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14001 :keys ,(int-to-string key)]
14002 menu-list))
14003 (setq key (1+ key)))
14004 (nreverse menu-list))
14005 "--"
14006 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14007 (or (vhdl-speedbar-check-unit 'entity)
14008 (vhdl-speedbar-check-unit 'subprogram))]
14009 ["Place Component" vhdl-speedbar-place-component
14010 (vhdl-speedbar-check-unit 'entity)]
0a2e512a
RF
14011 ["Generate Configuration" vhdl-speedbar-configuration
14012 (vhdl-speedbar-check-unit 'architecture)]
14013 ["Select as MRA" vhdl-speedbar-select-mra
14014 (vhdl-speedbar-check-unit 'architecture)]
3dcb36b7
JB
14015 ["Make" vhdl-speedbar-make-design
14016 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14017 ["Generate Makefile" vhdl-speedbar-generate-makefile
14018 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14019 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14020 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
f8246027 14021 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
3dcb36b7
JB
14022 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14023 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
f8246027 14024 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
3dcb36b7
JB
14025 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14026 ;; hook-ups
14027 (speedbar-add-expansion-list
14028 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14029 vhdl-speedbar-display-directory))
14030 (speedbar-add-expansion-list
14031 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14032 vhdl-speedbar-display-projects))
5eabfe72 14033 (setq speedbar-stealthy-function-list
3dcb36b7
JB
14034 (append
14035 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14036 ("vhdl project" vhdl-speedbar-update-current-project
14037 vhdl-speedbar-update-current-unit)
14038; ("files" (lambda () (setq speedbar-ignored-path-regexp
14039; (speedbar-extension-list-to-regex
14040; speedbar-ignored-path-expressions))))
14041 )
14042 speedbar-stealthy-function-list))
14043 (when (eq vhdl-speedbar-display-mode 'directory)
14044 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14045 (when (eq vhdl-speedbar-display-mode 'project)
14046 (setq speedbar-initial-expansion-list-name "vhdl project"))
14047 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
5eabfe72
KH
14048
14049(defun vhdl-speedbar (&optional arg)
14050 "Open/close speedbar."
d2ddb974 14051 (interactive)
5eabfe72 14052 (if (not (fboundp 'speedbar))
3dcb36b7
JB
14053 (error "WARNING: Speedbar is not available or not installed")
14054 (condition-case ()
5eabfe72 14055 (speedbar-frame-mode arg)
3dcb36b7 14056 (error (error "WARNING: An error occurred while opening speedbar")))))
5eabfe72
KH
14057
14058;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14059;; Display functions
14060
3dcb36b7
JB
14061(defvar vhdl-speedbar-last-selected-project nil
14062 "Name of last selected project.")
14063
5eabfe72
KH
14064;; macros must be defined in the file they are used (copied from `speedbar.el')
14065(defmacro speedbar-with-writable (&rest forms)
14066 "Allow the buffer to be writable and evaluate FORMS."
14067 (list 'let '((inhibit-read-only t))
14068 (cons 'progn forms)))
14069(put 'speedbar-with-writable 'lisp-indent-function 0)
14070
3dcb36b7 14071(defun vhdl-speedbar-display-directory (directory depth &optional rescan)
5eabfe72 14072 "Display directory and hierarchy information in speedbar."
3dcb36b7 14073 (setq vhdl-speedbar-show-projects nil)
f8262222
RS
14074 (setq speedbar-ignored-directory-regexp
14075 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
5eabfe72
KH
14076 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14077 (setq speedbar-last-selected-file nil)
14078 (speedbar-with-writable
3dcb36b7
JB
14079 (condition-case nil
14080 (progn
14081 ;; insert directory path
14082 (speedbar-directory-buttons directory depth)
14083 ;; insert subdirectories
14084 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14085 ;; scan and insert hierarchy of current directory
14086 (vhdl-speedbar-insert-dir-hierarchy directory depth
14087 speedbar-power-click)
14088 ;; expand subdirectories
14089 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14090 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14091
14092(defun vhdl-speedbar-display-projects (project depth &optional rescan)
14093 "Display projects and hierarchy information in speedbar."
14094 (setq vhdl-speedbar-show-projects t)
f8262222 14095 (setq speedbar-ignored-directory-regexp ".")
3dcb36b7
JB
14096 (setq speedbar-last-selected-file nil)
14097 (setq vhdl-speedbar-last-selected-project nil)
14098 (speedbar-with-writable
14099 (condition-case nil
14100 ;; insert projects
14101 (vhdl-speedbar-insert-projects)
14102 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14103 (setq speedbar-full-text-cache nil)) ; prevent caching
14104
14105(defun vhdl-speedbar-insert-projects ()
14106 "Insert all projects in speedbar."
14107 (vhdl-speedbar-make-title-line "Projects:")
14108 (let ((project-alist (if vhdl-project-sort
14109 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14110 vhdl-project-alist))
14111 (vhdl-speedbar-update-current-unit nil))
14112 ;; insert projects
14113 (while project-alist
14114 (speedbar-make-tag-line
14115 'angle ?+ 'vhdl-speedbar-expand-project
14116 (caar project-alist) (caar project-alist)
14117 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14118 (setq project-alist (cdr project-alist)))
14119 (setq project-alist vhdl-project-alist)
14120 ;; expand projects
14121 (while project-alist
14122 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14123 (goto-char (point-min))
14124 (when (re-search-forward
14125 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14126 (goto-char (match-end 1))
14127 (speedbar-do-function-pointer)))
14128 (setq project-alist (cdr project-alist))))
14129; (vhdl-speedbar-update-current-project)
14130; (vhdl-speedbar-update-current-unit nil t)
14131 )
14132
14133(defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
a4c6cfad 14134 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
3dcb36b7
JB
14135otherwise use cached data."
14136 (when (or rescan (and (not (assoc project vhdl-file-alist))
14137 (not (vhdl-load-cache project))))
14138 (vhdl-scan-project-contents project))
14139 ;; insert design hierarchy
14140 (vhdl-speedbar-insert-hierarchy
14141 (aget vhdl-entity-alist project t)
14142 (aget vhdl-config-alist project t)
14143 (aget vhdl-package-alist project t)
14144 (car (aget vhdl-ent-inst-alist project t)) indent)
14145 (insert (int-to-string indent) ":\n")
14146 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14147 (put-text-property (1- (point)) (point) 'invisible nil)
14148 ;; expand design units
14149 (vhdl-speedbar-expand-units project))
14150
14151(defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14152 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14153otherwise use cached data."
14154 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14155 (not (vhdl-load-cache directory))))
14156 (vhdl-scan-directory-contents directory))
14157 ;; insert design hierarchy
14158 (vhdl-speedbar-insert-hierarchy
14159 (aget vhdl-entity-alist directory t)
14160 (aget vhdl-config-alist directory t)
14161 (aget vhdl-package-alist directory t)
14162 (car (aget vhdl-ent-inst-alist directory t)) depth)
14163 ;; expand design units
14164 (vhdl-speedbar-expand-units directory)
14165 (aput 'vhdl-directory-alist directory (list (list directory))))
14166
14167(defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
5eabfe72 14168 ent-inst-list depth)
3dcb36b7
JB
14169 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14170 (if (not (or ent-alist conf-alist pack-alist))
14171 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14172 (let (ent-entry conf-entry pack-entry)
5eabfe72
KH
14173 ;; insert entities
14174 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14175 (while ent-alist
14176 (setq ent-entry (car ent-alist))
14177 (speedbar-make-tag-line
14178 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
3dcb36b7
JB
14179 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14180 (cons (nth 2 ent-entry) (nth 3 ent-entry))
0a2e512a 14181 'vhdl-speedbar-entity-face depth)
3dcb36b7
JB
14182 (unless (nth 2 ent-entry)
14183 (end-of-line 0) (insert "!") (forward-char 1))
14184 (unless (member (nth 0 ent-entry) ent-inst-list)
5eabfe72
KH
14185 (end-of-line 0) (insert " (top)") (forward-char 1))
14186 (setq ent-alist (cdr ent-alist)))
3dcb36b7
JB
14187 ;; insert configurations
14188 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14189 (while conf-alist
14190 (setq conf-entry (car conf-alist))
14191 (speedbar-make-tag-line
14192 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14193 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14194 (cons (nth 2 conf-entry) (nth 3 conf-entry))
0a2e512a 14195 'vhdl-speedbar-configuration-face depth)
3dcb36b7 14196 (setq conf-alist (cdr conf-alist)))
5eabfe72
KH
14197 ;; insert packages
14198 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14199 (while pack-alist
14200 (setq pack-entry (car pack-alist))
14201 (vhdl-speedbar-make-pack-line
3dcb36b7
JB
14202 (nth 0 pack-entry) (nth 1 pack-entry)
14203 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14204 (cons (nth 7 pack-entry) (nth 8 pack-entry))
5eabfe72
KH
14205 depth)
14206 (setq pack-alist (cdr pack-alist))))))
14207
5eabfe72 14208(defun vhdl-speedbar-rescan-hierarchy ()
3dcb36b7 14209 "Rescan hierarchy for the directory or project under the cursor."
d2ddb974 14210 (interactive)
3dcb36b7
JB
14211 (let (key path)
14212 (cond
14213 ;; current project
14214 (vhdl-speedbar-show-projects
14215 (setq key (vhdl-speedbar-line-project))
14216 (vhdl-scan-project-contents key))
14217 ;; top-level directory
14218 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14219 (re-search-forward "[0-9]+:" nil t)
14220 (vhdl-scan-directory-contents
7752250e 14221 (abbreviate-file-name (speedbar-line-directory))))
3dcb36b7 14222 ;; current directory
7752250e 14223 (t (setq path (speedbar-line-directory))
3dcb36b7
JB
14224 (string-match "^\\(.+[/\\]\\)" path)
14225 (vhdl-scan-directory-contents
14226 (abbreviate-file-name (match-string 1 path)))))
14227 (vhdl-speedbar-refresh key)))
5eabfe72
KH
14228
14229(defun vhdl-speedbar-expand-dirs (directory)
14230 "Expand subdirectories in DIRECTORY according to
14231 `speedbar-shown-directories'."
14232 ;; (nicked from `speedbar-default-directory-list')
3dcb36b7
JB
14233 (let ((sf (cdr (reverse speedbar-shown-directories)))
14234 (vhdl-speedbar-update-current-unit nil))
5eabfe72
KH
14235 (setq speedbar-shown-directories
14236 (list (expand-file-name default-directory)))
14237 (while sf
14238 (when (speedbar-goto-this-file (car sf))
14239 (beginning-of-line)
14240 (when (looking-at "[0-9]+:\\s-*<")
14241 (goto-char (match-end 0))
3dcb36b7
JB
14242 (speedbar-do-function-pointer)))
14243 (setq sf (cdr sf))))
14244 (vhdl-speedbar-update-current-unit nil t))
14245
14246(defun vhdl-speedbar-expand-units (key)
14247 "Expand design units in directory/project KEY according to
14248`vhdl-speedbar-shown-unit-alist'."
14249 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14250 (vhdl-speedbar-update-current-unit nil)
14251 vhdl-updated-project-list)
14252 (adelete 'vhdl-speedbar-shown-unit-alist key)
14253 (vhdl-prepare-search-1
14254 (while unit-alist ; expand units
14255 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14256 (beginning-of-line)
14257 (let ((arch-alist (nth 1 (car unit-alist)))
14258 position)
14259 (when (looking-at "^[0-9]+:\\s-*\\[")
14260 (goto-char (match-end 0))
14261 (setq position (point))
14262 (speedbar-do-function-pointer)
14263 (select-frame speedbar-frame)
14264 (while arch-alist ; expand architectures
14265 (goto-char position)
14266 (when (re-search-forward
14267 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14268 (car arch-alist) "\\>\\)") nil t)
14269 (beginning-of-line)
14270 (when (looking-at "^[0-9]+:\\s-*{")
14271 (goto-char (match-end 0))
14272 (speedbar-do-function-pointer)
14273 (select-frame speedbar-frame)))
14274 (setq arch-alist (cdr arch-alist))))
14275 (setq unit-alist (cdr unit-alist))))))
14276 (vhdl-speedbar-update-current-unit nil t))
14277
14278(defun vhdl-speedbar-contract-level ()
14279 "Contract current level in current directory/project."
14280 (interactive)
14281 (when (or (save-excursion
14282 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14283 (and (save-excursion
14284 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14285 (re-search-backward
14286 (format "^[0-%d]:\\s-*[[{<]-"
027a4b6b 14287 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
3dcb36b7
JB
14288 (goto-char (match-end 0))
14289 (speedbar-do-function-pointer)
14290 (speedbar-center-buffer-smartly)))
14291
14292(defun vhdl-speedbar-contract-all ()
14293 "Contract all expanded design units in current directory/project."
14294 (interactive)
14295 (if (and vhdl-speedbar-show-projects
14296 (save-excursion (beginning-of-line) (looking-at "^0:")))
14297 (progn (setq vhdl-speedbar-shown-project-list nil)
14298 (vhdl-speedbar-refresh))
14299 (let ((key (vhdl-speedbar-line-key)))
14300 (adelete 'vhdl-speedbar-shown-unit-alist key)
14301 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14302 (when (memq 'display vhdl-speedbar-save-cache)
14303 (add-to-list 'vhdl-updated-project-list key)))))
14304
14305(defun vhdl-speedbar-expand-all ()
14306 "Expand all design units in current directory/project."
14307 (interactive)
14308 (let* ((key (vhdl-speedbar-line-key))
14309 (ent-alist (aget vhdl-entity-alist key t))
14310 (conf-alist (aget vhdl-config-alist key t))
14311 (pack-alist (aget vhdl-package-alist key t))
14312 arch-alist unit-alist subunit-alist)
14313 (add-to-list 'vhdl-speedbar-shown-project-list key)
14314 (while ent-alist
14315 (setq arch-alist (nth 4 (car ent-alist)))
14316 (setq subunit-alist nil)
14317 (while arch-alist
14318 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14319 (setq arch-alist (cdr arch-alist)))
14320 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14321 (setq ent-alist (cdr ent-alist)))
14322 (while conf-alist
14323 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14324 (setq conf-alist (cdr conf-alist)))
14325 (while pack-alist
14326 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14327 (setq pack-alist (cdr pack-alist)))
14328 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14329 (vhdl-speedbar-refresh)
14330 (when (memq 'display vhdl-speedbar-save-cache)
14331 (add-to-list 'vhdl-updated-project-list key))))
14332
14333(defun vhdl-speedbar-expand-project (text token indent)
14334 "Expand/contract the project under the cursor."
14335 (cond
14336 ((string-match "+" text) ; expand project
14337 (speedbar-change-expand-button-char ?-)
14338 (unless (member token vhdl-speedbar-shown-project-list)
14339 (setq vhdl-speedbar-shown-project-list
14340 (cons token vhdl-speedbar-shown-project-list)))
14341 (speedbar-with-writable
14342 (save-excursion
14343 (end-of-line) (forward-char 1)
14344 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14345 speedbar-power-click))))
14346 ((string-match "-" text) ; contract project
14347 (speedbar-change-expand-button-char ?+)
14348 (setq vhdl-speedbar-shown-project-list
14349 (delete token vhdl-speedbar-shown-project-list))
14350 (speedbar-delete-subblock indent))
14351 (t (error "Nothing to display")))
14352 (when (equal (selected-frame) speedbar-frame)
14353 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14354
14355(defun vhdl-speedbar-expand-entity (text token indent)
14356 "Expand/contract the entity under the cursor."
14357 (cond
14358 ((string-match "+" text) ; expand entity
3dcb36b7
JB
14359 (let* ((key (vhdl-speedbar-line-key indent))
14360 (ent-alist (aget vhdl-entity-alist key t))
14361 (ent-entry (aget ent-alist token t))
14362 (arch-alist (nth 3 ent-entry))
5eabfe72 14363 (inst-alist (vhdl-get-instantiations token indent))
0a2e512a
RF
14364 (subpack-alist (nth 5 ent-entry))
14365 (multiple-arch (> (length arch-alist) 1))
3dcb36b7
JB
14366 arch-entry inst-entry)
14367 (if (not (or arch-alist inst-alist subpack-alist))
5eabfe72
KH
14368 (speedbar-change-expand-button-char ??)
14369 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14370 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14371 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14372 (aput 'unit-alist token nil)
14373 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72 14374 (speedbar-with-writable
3dcb36b7
JB
14375 (save-excursion
14376 (end-of-line) (forward-char 1)
14377 ;; insert architectures
14378 (when arch-alist
14379 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14380 (while arch-alist
14381 (setq arch-entry (car arch-alist))
14382 (speedbar-make-tag-line
14383 'curly ?+ 'vhdl-speedbar-expand-architecture
14384 (cons token (nth 0 arch-entry))
14385 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14386 (cons (nth 2 arch-entry) (nth 3 arch-entry))
0a2e512a
RF
14387 'vhdl-speedbar-architecture-face (1+ indent))
14388 (when (and multiple-arch
14389 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14390 (end-of-line 0) (insert " (mra)") (forward-char 1))
3dcb36b7
JB
14391 (setq arch-alist (cdr arch-alist)))
14392 ;; insert instantiations
14393 (when inst-alist
14394 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14395 (while inst-alist
14396 (setq inst-entry (car inst-alist))
14397 (vhdl-speedbar-make-inst-line
14398 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14399 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14400 nil nil nil (1+ indent) 0 " in ")
14401 (setq inst-alist (cdr inst-alist)))
14402 ;; insert required packages
14403 (vhdl-speedbar-insert-subpackages
14404 subpack-alist (1+ indent) indent)))
14405 (when (memq 'display vhdl-speedbar-save-cache)
14406 (add-to-list 'vhdl-updated-project-list key))
14407 (vhdl-speedbar-update-current-unit t t))))
5eabfe72
KH
14408 ((string-match "-" text) ; contract entity
14409 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14410 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14411 (let* ((key (vhdl-speedbar-line-key indent))
14412 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14413 (adelete 'unit-alist token)
14414 (if unit-alist
14415 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14416 (adelete 'vhdl-speedbar-shown-unit-alist key))
14417 (speedbar-delete-subblock indent)
14418 (when (memq 'display vhdl-speedbar-save-cache)
14419 (add-to-list 'vhdl-updated-project-list key))))
14420 (t (error "Nothing to display")))
14421 (when (equal (selected-frame) speedbar-frame)
14422 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14423
14424(defun vhdl-speedbar-expand-architecture (text token indent)
14425 "Expand/contract the architecture under the cursor."
14426 (cond
14427 ((string-match "+" text) ; expand architecture
3dcb36b7
JB
14428 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14429 (ent-alist (aget vhdl-entity-alist key t))
14430 (conf-alist (aget vhdl-config-alist key t))
14431 (hier-alist (vhdl-get-hierarchy
14432 ent-alist conf-alist (car token) (cdr token) nil nil
14433 0 (1- indent)))
14434 (ent-entry (aget ent-alist (car token) t))
14435 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14436 (subpack-alist (nth 4 arch-entry))
14437 entry)
14438 (if (not (or hier-alist subpack-alist))
14439 (speedbar-change-expand-button-char ??)
14440 (speedbar-change-expand-button-char ?-)
14441 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14442 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14443 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14444 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14445 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14446 (speedbar-with-writable
14447 (save-excursion
14448 (end-of-line) (forward-char 1)
14449 ;; insert instance hierarchy
14450 (when hier-alist
14451 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14452 (1+ indent)))
14453 (while hier-alist
14454 (setq entry (car hier-alist))
14455 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14456 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14457 (vhdl-speedbar-make-inst-line
14458 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14459 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14460 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14461 (setq hier-alist (cdr hier-alist)))
14462 ;; insert required packages
14463 (vhdl-speedbar-insert-subpackages
14464 subpack-alist (1+ indent) (1- indent))))
14465 (when (memq 'display vhdl-speedbar-save-cache)
14466 (add-to-list 'vhdl-updated-project-list key))
14467 (vhdl-speedbar-update-current-unit t t))))
14468 ((string-match "-" text) ; contract architecture
14469 (speedbar-change-expand-button-char ?+)
14470 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14471 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14472 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14473 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14474 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14475 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14476 (speedbar-delete-subblock indent)
14477 (when (memq 'display vhdl-speedbar-save-cache)
14478 (add-to-list 'vhdl-updated-project-list key))))
14479 (t (error "Nothing to display")))
14480 (when (equal (selected-frame) speedbar-frame)
14481 (speedbar-center-buffer-smartly)))
14482
14483(defun vhdl-speedbar-expand-config (text token indent)
14484 "Expand/contract the configuration under the cursor."
14485 (cond
14486 ((string-match "+" text) ; expand configuration
14487 (let* ((key (vhdl-speedbar-line-key indent))
14488 (conf-alist (aget vhdl-config-alist key t))
14489 (conf-entry (aget conf-alist token))
14490 (ent-alist (aget vhdl-entity-alist key t))
14491 (hier-alist (vhdl-get-hierarchy
14492 ent-alist conf-alist (nth 3 conf-entry)
14493 (nth 4 conf-entry) token (nth 5 conf-entry)
14494 0 indent t))
14495 (subpack-alist (nth 6 conf-entry))
14496 entry)
14497 (if (not (or hier-alist subpack-alist))
5eabfe72
KH
14498 (speedbar-change-expand-button-char ??)
14499 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14500 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14501 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14502 (aput 'unit-alist token nil)
14503 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72
KH
14504 (speedbar-with-writable
14505 (save-excursion
14506 (end-of-line) (forward-char 1)
14507 ;; insert instance hierarchy
14508 (when hier-alist
3dcb36b7 14509 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
5eabfe72 14510 (while hier-alist
3dcb36b7
JB
14511 (setq entry (car hier-alist))
14512 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14513 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
5eabfe72 14514 (vhdl-speedbar-make-inst-line
3dcb36b7
JB
14515 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14516 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14517 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14518 (setq hier-alist (cdr hier-alist)))
14519 ;; insert required packages
14520 (vhdl-speedbar-insert-subpackages
14521 subpack-alist (1+ indent) indent)))
14522 (when (memq 'display vhdl-speedbar-save-cache)
14523 (add-to-list 'vhdl-updated-project-list key))
14524 (vhdl-speedbar-update-current-unit t t))))
14525 ((string-match "-" text) ; contract configuration
5eabfe72 14526 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14527 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14528 (let* ((key (vhdl-speedbar-line-key indent))
14529 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14530 (adelete 'unit-alist token)
14531 (if unit-alist
14532 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14533 (adelete 'vhdl-speedbar-shown-unit-alist key))
14534 (speedbar-delete-subblock indent)
14535 (when (memq 'display vhdl-speedbar-save-cache)
14536 (add-to-list 'vhdl-updated-project-list key))))
14537 (t (error "Nothing to display")))
14538 (when (equal (selected-frame) speedbar-frame)
14539 (speedbar-center-buffer-smartly)))
14540
14541(defun vhdl-speedbar-expand-package (text token indent)
14542 "Expand/contract the package under the cursor."
14543 (cond
14544 ((string-match "+" text) ; expand package
14545 (let* ((key (vhdl-speedbar-line-key indent))
14546 (pack-alist (aget vhdl-package-alist key t))
14547 (pack-entry (aget pack-alist token t))
14548 (comp-alist (nth 3 pack-entry))
14549 (func-alist (nth 4 pack-entry))
14550 (func-body-alist (nth 8 pack-entry))
14551 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14552 comp-entry func-entry func-body-entry)
14553 (if (not (or comp-alist func-alist subpack-alist))
14554 (speedbar-change-expand-button-char ??)
14555 (speedbar-change-expand-button-char ?-)
14556 ;; add package to `vhdl-speedbar-shown-unit-alist'
14557 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14558 (aput 'unit-alist token nil)
14559 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14560 (speedbar-with-writable
14561 (save-excursion
14562 (end-of-line) (forward-char 1)
14563 ;; insert components
14564 (when comp-alist
14565 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14566 (while comp-alist
14567 (setq comp-entry (car comp-alist))
14568 (speedbar-make-tag-line
14569 nil nil nil
14570 (cons token (nth 0 comp-entry))
14571 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14572 (cons (nth 2 comp-entry) (nth 3 comp-entry))
0a2e512a 14573 'vhdl-speedbar-entity-face (1+ indent))
3dcb36b7
JB
14574 (setq comp-alist (cdr comp-alist)))
14575 ;; insert subprograms
14576 (when func-alist
14577 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14578 (while func-alist
14579 (setq func-entry (car func-alist)
14580 func-body-entry (aget func-body-alist (car func-entry) t))
14581 (when (nth 2 func-entry)
14582 (vhdl-speedbar-make-subprogram-line
14583 (nth 1 func-entry)
14584 (cons (nth 2 func-entry) (nth 3 func-entry))
14585 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14586 (1+ indent)))
14587 (setq func-alist (cdr func-alist)))
14588 ;; insert required packages
14589 (vhdl-speedbar-insert-subpackages
14590 subpack-alist (1+ indent) indent)))
14591 (when (memq 'display vhdl-speedbar-save-cache)
14592 (add-to-list 'vhdl-updated-project-list key))
14593 (vhdl-speedbar-update-current-unit t t))))
14594 ((string-match "-" text) ; contract package
14595 (speedbar-change-expand-button-char ?+)
14596 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14597 (let* ((key (vhdl-speedbar-line-key indent))
14598 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14599 (adelete 'unit-alist token)
14600 (if unit-alist
14601 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14602 (adelete 'vhdl-speedbar-shown-unit-alist key))
14603 (speedbar-delete-subblock indent)
14604 (when (memq 'display vhdl-speedbar-save-cache)
14605 (add-to-list 'vhdl-updated-project-list key))))
14606 (t (error "Nothing to display")))
14607 (when (equal (selected-frame) speedbar-frame)
14608 (speedbar-center-buffer-smartly)))
14609
14610(defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14611 "Insert required packages."
14612 (let* ((pack-alist (aget vhdl-package-alist
14613 (vhdl-speedbar-line-key dir-indent) t))
14614 pack-key lib-name pack-entry)
14615 (when subpack-alist
14616 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14617 (while subpack-alist
14618 (setq pack-key (cdar subpack-alist)
14619 lib-name (caar subpack-alist))
14620 (setq pack-entry (aget pack-alist pack-key t))
14621 (vhdl-speedbar-make-subpack-line
14622 (or (nth 0 pack-entry) pack-key) lib-name
0a2e512a
RF
14623 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14624 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
3dcb36b7 14625 (setq subpack-alist (cdr subpack-alist)))))
5eabfe72
KH
14626
14627;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14628;; Display help functions
14629
3dcb36b7
JB
14630(defvar vhdl-speedbar-update-current-unit t
14631 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14632
14633(defun vhdl-speedbar-update-current-project ()
14634 "Highlight project that is currently active."
14635 (when (and vhdl-speedbar-show-projects
14636 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14637 (and (boundp 'speedbar-frame)
14638 (frame-live-p speedbar-frame)))
14639 (let ((last-frame (selected-frame))
14640 (project-alist vhdl-project-alist)
14641 pos)
14642 (select-frame speedbar-frame)
14643 (speedbar-with-writable
14644 (save-excursion
14645 (while project-alist
14646 (goto-char (point-min))
14647 (when (re-search-forward
14648 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14649 (put-text-property (match-beginning 1) (match-end 1) 'face
14650 (if (equal (caar project-alist) vhdl-project)
14651 'speedbar-selected-face
14652 'speedbar-directory-face))
14653 (when (equal (caar project-alist) vhdl-project)
14654 (setq pos (1- (match-beginning 1)))))
14655 (setq project-alist (cdr project-alist))))
14656 (when pos (goto-char pos)))
14657 (select-frame last-frame)
14658 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14659 t)
14660
14661(defun vhdl-speedbar-update-current-unit (&optional no-position always)
5eabfe72
KH
14662 "Highlight all design units that are contained in the current file.
14663NO-POSITION non-nil means do not re-position cursor."
14664 (let ((last-frame (selected-frame))
3dcb36b7
JB
14665 (project-list vhdl-speedbar-shown-project-list)
14666 file-alist pos file-name)
5eabfe72 14667 ;; get current file name
3dcb36b7
JB
14668 (if (fboundp 'speedbar-select-attached-frame)
14669 (speedbar-select-attached-frame)
14670 (select-frame speedbar-attached-frame))
5eabfe72 14671 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
3dcb36b7
JB
14672 (when (and vhdl-speedbar-update-current-unit
14673 (or always (not (equal file-name speedbar-last-selected-file))))
14674 (if vhdl-speedbar-show-projects
14675 (while project-list
14676 (setq file-alist (append file-alist (aget vhdl-file-alist
14677 (car project-list) t)))
14678 (setq project-list (cdr project-list)))
14679 (setq file-alist (aget vhdl-file-alist
14680 (abbreviate-file-name default-directory) t)))
5eabfe72
KH
14681 (select-frame speedbar-frame)
14682 (set-buffer speedbar-buffer)
14683 (speedbar-with-writable
3dcb36b7 14684 (vhdl-prepare-search-1
5eabfe72
KH
14685 (save-excursion
14686 ;; unhighlight last units
3dcb36b7 14687 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
5eabfe72 14688 (vhdl-speedbar-update-units
3dcb36b7 14689 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14690 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
5eabfe72 14691 (vhdl-speedbar-update-units
3dcb36b7 14692 "{.} " (nth 1 file-entry)
0a2e512a 14693 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
5eabfe72 14694 (vhdl-speedbar-update-units
3dcb36b7 14695 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14696 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
5eabfe72 14697 (vhdl-speedbar-update-units
3dcb36b7 14698 "[]>] " (nth 4 file-entry)
0a2e512a 14699 speedbar-last-selected-file 'vhdl-speedbar-package-face)
5eabfe72 14700 (vhdl-speedbar-update-units
3dcb36b7 14701 "\\[.\\].+(" '("body")
0a2e512a 14702 speedbar-last-selected-file 'vhdl-speedbar-package-face)
3dcb36b7
JB
14703 (vhdl-speedbar-update-units
14704 "> " (nth 6 file-entry)
0a2e512a 14705 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
5eabfe72 14706 ;; highlight current units
3dcb36b7
JB
14707 (let* ((file-entry (aget file-alist file-name t)))
14708 (setq
14709 pos (vhdl-speedbar-update-units
14710 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14711 file-name 'vhdl-speedbar-entity-selected-face pos)
3dcb36b7
JB
14712 pos (vhdl-speedbar-update-units
14713 "{.} " (nth 1 file-entry)
0a2e512a 14714 file-name 'vhdl-speedbar-architecture-selected-face pos)
3dcb36b7
JB
14715 pos (vhdl-speedbar-update-units
14716 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14717 file-name 'vhdl-speedbar-configuration-selected-face pos)
3dcb36b7
JB
14718 pos (vhdl-speedbar-update-units
14719 "[]>] " (nth 4 file-entry)
0a2e512a 14720 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14721 pos (vhdl-speedbar-update-units
14722 "\\[.\\].+(" '("body")
0a2e512a 14723 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14724 pos (vhdl-speedbar-update-units
14725 "> " (nth 6 file-entry)
0a2e512a 14726 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
5eabfe72 14727 ;; move speedbar so the first highlighted unit is visible
3dcb36b7
JB
14728 (when (and pos (not no-position))
14729 (goto-char pos)
14730 (speedbar-center-buffer-smartly)
5eabfe72
KH
14731 (speedbar-position-cursor-on-line))
14732 (setq speedbar-last-selected-file file-name))
14733 (select-frame last-frame)
14734 t))
14735
3dcb36b7
JB
14736(defun vhdl-speedbar-update-units (text unit-list file-name face
14737 &optional pos)
5eabfe72 14738 "Help function to highlight design units."
3dcb36b7
JB
14739 (while unit-list
14740 (goto-char (point-min))
14741 (while (re-search-forward
14742 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14743 (when (equal file-name (car (get-text-property
14744 (match-beginning 1) 'speedbar-token)))
14745 (setq pos (or pos (point-marker)))
14746 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14747 (setq unit-list (cdr unit-list)))
14748 pos)
5eabfe72
KH
14749
14750(defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
3dcb36b7
JB
14751 ent-name ent-file-marker
14752 arch-name arch-file-marker
14753 conf-name conf-file-marker
14754 lib-name depth offset delimiter)
5eabfe72 14755 "Insert instantiation entry."
3dcb36b7
JB
14756 (let ((start (point))
14757 visible-start)
5eabfe72
KH
14758 (insert (int-to-string depth) ":")
14759 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14760 (setq visible-start (point))
14761 (insert-char ? (* depth speedbar-indentation-width))
14762 (while (> offset 0)
14763 (insert "|")
14764 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14765 (setq offset (1- offset)))
14766 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14767 (setq start (point))
3dcb36b7
JB
14768 (insert ">")
14769 (speedbar-make-button start (point) nil nil nil)
14770 (setq visible-start (point))
14771 (insert " ")
5eabfe72 14772 (setq start (point))
3dcb36b7
JB
14773 (if (not inst-name)
14774 (insert "(top)")
14775 (insert inst-name)
14776 (speedbar-make-button
0a2e512a 14777 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
3dcb36b7
JB
14778 'vhdl-speedbar-find-file inst-file-marker))
14779 (insert delimiter)
14780 (when ent-name
5eabfe72 14781 (setq start (point))
3dcb36b7 14782 (insert ent-name)
5eabfe72 14783 (speedbar-make-button
0a2e512a 14784 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
3dcb36b7
JB
14785 'vhdl-speedbar-find-file ent-file-marker)
14786 (when arch-name
14787 (insert " (")
14788 (setq start (point))
14789 (insert arch-name)
14790 (speedbar-make-button
0a2e512a 14791 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
3dcb36b7
JB
14792 'vhdl-speedbar-find-file arch-file-marker)
14793 (insert ")"))
14794 (when conf-name
14795 (insert " (")
14796 (setq start (point))
14797 (insert conf-name)
14798 (speedbar-make-button
0a2e512a 14799 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
3dcb36b7
JB
14800 'vhdl-speedbar-find-file conf-file-marker)
14801 (insert ")")))
14802 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
5eabfe72 14803 (setq start (point))
3dcb36b7
JB
14804 (insert " (" lib-name ")")
14805 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14806 'vhdl-speedbar-library-face))
5eabfe72 14807 (insert-char ?\n 1)
3dcb36b7 14808 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14809
3dcb36b7
JB
14810(defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14811 body-file-marker depth)
5eabfe72 14812 "Insert package entry."
3dcb36b7
JB
14813 (let ((start (point))
14814 visible-start)
5eabfe72
KH
14815 (insert (int-to-string depth) ":")
14816 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14817 (setq visible-start (point))
14818 (insert-char ? (* depth speedbar-indentation-width))
14819 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14820 (setq start (point))
3dcb36b7
JB
14821 (insert "[+]")
14822 (speedbar-make-button
14823 start (point) 'speedbar-button-face 'speedbar-highlight-face
14824 'vhdl-speedbar-expand-package pack-key)
14825 (setq visible-start (point))
14826 (insert-char ? 1 nil)
5eabfe72
KH
14827 (setq start (point))
14828 (insert pack-name)
14829 (speedbar-make-button
0a2e512a 14830 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14831 'vhdl-speedbar-find-file pack-file-marker)
3dcb36b7
JB
14832 (unless (car pack-file-marker)
14833 (insert "!"))
5eabfe72 14834 (when (car body-file-marker)
5eabfe72 14835 (insert " (")
5eabfe72
KH
14836 (setq start (point))
14837 (insert "body")
14838 (speedbar-make-button
0a2e512a 14839 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14840 'vhdl-speedbar-find-file body-file-marker)
3dcb36b7 14841 (insert ")"))
5eabfe72 14842 (insert-char ?\n 1)
3dcb36b7 14843 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14844
3dcb36b7 14845(defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
0a2e512a 14846 pack-body-file-marker depth)
3dcb36b7
JB
14847 "Insert used package entry."
14848 (let ((start (point))
14849 visible-start)
14850 (insert (int-to-string depth) ":")
14851 (put-text-property start (point) 'invisible t)
14852 (setq visible-start (point))
14853 (insert-char ? (* depth speedbar-indentation-width))
14854 (put-text-property visible-start (point) 'invisible nil)
14855 (setq start (point))
14856 (insert ">")
14857 (speedbar-make-button start (point) nil nil nil)
14858 (setq visible-start (point))
14859 (insert " ")
14860 (setq start (point))
14861 (insert pack-name)
14862 (speedbar-make-button
0a2e512a 14863 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
3dcb36b7 14864 'vhdl-speedbar-find-file pack-file-marker)
0a2e512a
RF
14865 (when (car pack-body-file-marker)
14866 (insert " (")
14867 (setq start (point))
14868 (insert "body")
14869 (speedbar-make-button
14870 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14871 'vhdl-speedbar-find-file pack-body-file-marker)
14872 (insert ")"))
3dcb36b7
JB
14873 (setq start (point))
14874 (insert " (" lib-name ")")
14875 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14876 'vhdl-speedbar-library-face)
3dcb36b7
JB
14877 (insert-char ?\n 1)
14878 (put-text-property visible-start (point) 'invisible nil)))
14879
14880(defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14881 func-body-file-marker
14882 depth)
14883 "Insert subprogram entry."
14884 (let ((start (point))
14885 visible-start)
5eabfe72
KH
14886 (insert (int-to-string depth) ":")
14887 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14888 (setq visible-start (point))
14889 (insert-char ? (* depth speedbar-indentation-width))
14890 (put-text-property visible-start (point) 'invisible nil)
14891 (setq start (point))
14892 (insert ">")
14893 (speedbar-make-button start (point) nil nil nil)
14894 (setq visible-start (point))
14895 (insert " ")
5eabfe72 14896 (setq start (point))
3dcb36b7
JB
14897 (insert func-name)
14898 (speedbar-make-button
0a2e512a 14899 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14900 'vhdl-speedbar-find-file func-file-marker)
14901 (when (car func-body-file-marker)
14902 (insert " (")
14903 (setq start (point))
14904 (insert "body")
14905 (speedbar-make-button
0a2e512a 14906 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14907 'vhdl-speedbar-find-file func-body-file-marker)
14908 (insert ")"))
14909 (insert-char ?\n 1)
14910 (put-text-property visible-start (point) 'invisible nil)))
14911
14912(defun vhdl-speedbar-make-title-line (text &optional depth)
14913 "Insert design unit title entry."
14914 (let ((start (point))
14915 visible-start)
14916 (when depth
14917 (insert (int-to-string depth) ":")
14918 (put-text-property start (point) 'invisible t))
14919 (setq visible-start (point))
14920 (insert-char ? (* (or depth 0) speedbar-indentation-width))
5eabfe72
KH
14921 (setq start (point))
14922 (insert text)
14923 (speedbar-make-button start (point) nil nil nil nil)
14924 (insert-char ?\n 1)
3dcb36b7 14925 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72
KH
14926
14927(defun vhdl-speedbar-insert-dirs (files level)
14928 "Insert subdirectories."
14929 (let ((dirs (car files)))
14930 (while dirs
14931 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14932 (car dirs) 'speedbar-dir-follow nil
14933 'speedbar-directory-face level)
14934 (setq dirs (cdr dirs)))))
14935
14936(defun vhdl-speedbar-dired (text token indent)
14937 "Speedbar click handler for directory expand button in hierarchy mode."
14938 (cond ((string-match "+" text) ; we have to expand this dir
14939 (setq speedbar-shown-directories
14940 (cons (expand-file-name
7752250e 14941 (concat (speedbar-line-directory indent) token "/"))
5eabfe72
KH
14942 speedbar-shown-directories))
14943 (speedbar-change-expand-button-char ?-)
14944 (speedbar-reset-scanners)
14945 (speedbar-with-writable
14946 (save-excursion
14947 (end-of-line) (forward-char 1)
14948 (vhdl-speedbar-insert-dirs
14949 (speedbar-file-lists
7752250e 14950 (concat (speedbar-line-directory indent) token "/"))
5eabfe72
KH
14951 (1+ indent))
14952 (speedbar-reset-scanners)
14953 (vhdl-speedbar-insert-dir-hierarchy
14954 (abbreviate-file-name
7752250e 14955 (concat (speedbar-line-directory indent) token "/"))
5eabfe72 14956 (1+ indent) speedbar-power-click)))
3dcb36b7 14957 (vhdl-speedbar-update-current-unit t t))
5eabfe72
KH
14958 ((string-match "-" text) ; we have to contract this node
14959 (speedbar-reset-scanners)
14960 (let ((oldl speedbar-shown-directories)
14961 (newl nil)
14962 (td (expand-file-name
7752250e 14963 (concat (speedbar-line-directory indent) token))))
5eabfe72
KH
14964 (while oldl
14965 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14966 (setq newl (cons (car oldl) newl)))
14967 (setq oldl (cdr oldl)))
14968 (setq speedbar-shown-directories (nreverse newl)))
14969 (speedbar-change-expand-button-char ?+)
14970 (speedbar-delete-subblock indent))
3dcb36b7
JB
14971 (t (error "Nothing to display")))
14972 (when (equal (selected-frame) speedbar-frame)
14973 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14974
14975(defun vhdl-speedbar-item-info ()
14976 "Derive and display information about this line item."
14977 (save-excursion
14978 (beginning-of-line)
14979 ;; skip invisible number info
3dcb36b7 14980 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
5eabfe72 14981 (cond
3dcb36b7
JB
14982 ;; project/directory entry
14983 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14984 (if vhdl-speedbar-show-projects
14985 (message "Project \"%s\"" (match-string-no-properties 1))
14986 (speedbar-files-item-info)))
5eabfe72 14987 ;; design unit entry
3dcb36b7
JB
14988 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14989 (goto-char (match-end 1))
5eabfe72
KH
14990 (let ((face (get-text-property (point) 'face)))
14991 (message
14992 "%s \"%s\" in \"%s\""
14993 ;; design unit kind
0a2e512a
RF
14994 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14995 (eq face 'vhdl-speedbar-entity-selected-face))
3dcb36b7 14996 (if (equal (match-string 2) ">") "Component" "Entity"))
0a2e512a
RF
14997 ((or (eq face 'vhdl-speedbar-architecture-face)
14998 (eq face 'vhdl-speedbar-architecture-selected-face))
5eabfe72 14999 "Architecture")
0a2e512a
RF
15000 ((or (eq face 'vhdl-speedbar-configuration-face)
15001 (eq face 'vhdl-speedbar-configuration-selected-face))
5eabfe72 15002 "Configuration")
0a2e512a
RF
15003 ((or (eq face 'vhdl-speedbar-package-face)
15004 (eq face 'vhdl-speedbar-package-selected-face))
5eabfe72 15005 "Package")
0a2e512a
RF
15006 ((or (eq face 'vhdl-speedbar-instantiation-face)
15007 (eq face 'vhdl-speedbar-instantiation-selected-face))
5eabfe72 15008 "Instantiation")
0a2e512a 15009 ((eq face 'vhdl-speedbar-subprogram-face)
3dcb36b7 15010 "Subprogram")
5eabfe72
KH
15011 (t ""))
15012 ;; design unit name
15013 (buffer-substring-no-properties
3dcb36b7
JB
15014 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15015 (match-end 1))
5eabfe72 15016 ;; file name
3dcb36b7
JB
15017 (file-relative-name
15018 (or (car (get-text-property (point) 'speedbar-token))
15019 "?")
15020 (vhdl-default-directory)))))
15021 (t (message "")))))
15022
15023(defun vhdl-speedbar-line-text ()
15024 "Calls `speedbar-line-text' and removes text properties."
15025 (let ((string (speedbar-line-text)))
15026 (set-text-properties 0 (length string) nil string)
15027 string))
5eabfe72 15028
0a2e512a
RF
15029(defun vhdl-speedbar-higher-text ()
15030 "Get speedbar-line-text of higher level."
15031 (let (depth string)
15032 (save-excursion
15033 (beginning-of-line)
15034 (looking-at "^\\([0-9]+\\):")
15035 (setq depth (string-to-number (match-string 1)))
15036 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15037 (setq string (match-string 1))
15038 (set-text-properties 0 (length string) nil string)
15039 string))))
15040
5eabfe72
KH
15041;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15042;; Help functions
d2ddb974 15043
3dcb36b7
JB
15044(defun vhdl-speedbar-line-key (&optional indent)
15045 "Get currently displayed directory of project name."
15046 (if vhdl-speedbar-show-projects
15047 (vhdl-speedbar-line-project)
15048 (abbreviate-file-name
7752250e 15049 (file-name-as-directory (speedbar-line-directory indent)))))
3dcb36b7
JB
15050
15051(defun vhdl-speedbar-line-project (&optional indent)
15052 "Get currently displayed project name."
15053 (and vhdl-speedbar-show-projects
15054 (save-excursion
15055 (end-of-line)
15056 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15057 (match-string-no-properties 1))))
15058
15059(defun vhdl-add-modified-file ()
15060 "Add file to `vhdl-modified-file-list'."
15061 (when vhdl-file-alist
15062 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15063 nil)
5eabfe72
KH
15064
15065(defun vhdl-resolve-paths (path-list)
3dcb36b7
JB
15066 "Resolve path wildcards in PATH-LIST."
15067 (let (path-list-1 path-list-2 path-beg path-end dir)
15068 ;; eliminate non-existent directories
5eabfe72
KH
15069 (while path-list
15070 (setq dir (car path-list))
3dcb36b7
JB
15071 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15072 (if (file-directory-p (match-string 2 dir))
15073 (setq path-list-1 (cons dir path-list-1))
15074 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
5eabfe72 15075 (setq path-list (cdr path-list)))
3dcb36b7 15076 ;; resolve path wildcards
5eabfe72
KH
15077 (while path-list-1
15078 (setq dir (car path-list-1))
3dcb36b7 15079 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
5eabfe72
KH
15080 (progn
15081 (setq path-beg (match-string 1 dir)
15082 path-end (match-string 5 dir))
3dcb36b7 15083 (setq path-list-1
5eabfe72
KH
15084 (append
15085 (mapcar
15086 (function
15087 (lambda (var) (concat path-beg var path-end)))
15088 (let ((all-list (vhdl-directory-files
15089 (match-string 2 dir) t
15090 (concat "\\<" (wildcard-to-regexp
15091 (match-string 4 dir)))))
15092 dir-list)
15093 (while all-list
15094 (when (file-directory-p (car all-list))
15095 (setq dir-list (cons (car all-list) dir-list)))
15096 (setq all-list (cdr all-list)))
15097 dir-list))
3dcb36b7
JB
15098 (cdr path-list-1))))
15099 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
5eabfe72 15100 (when (file-directory-p (match-string 2 dir))
3dcb36b7
JB
15101 (setq path-list-2 (cons dir path-list-2)))
15102 (setq path-list-1 (cdr path-list-1))))
15103 (nreverse path-list-2)))
5eabfe72
KH
15104
15105(defun vhdl-speedbar-goto-this-unit (directory unit)
15106 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15107 (let ((dest (point)))
3dcb36b7 15108 (if (and (if vhdl-speedbar-show-projects
5eabfe72
KH
15109 (progn (goto-char (point-min)) t)
15110 (speedbar-goto-this-file directory))
15111 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15112 (progn (speedbar-position-cursor-on-line)
15113 t)
15114 (goto-char dest)
15115 nil)))
15116
15117(defun vhdl-speedbar-find-file (text token indent)
3dcb36b7
JB
15118 "When user clicks on TEXT, load file with name and position in TOKEN.
15119Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15120is already shown in a buffer."
5eabfe72 15121 (if (not (car token))
3dcb36b7
JB
15122 (error "ERROR: File cannot be found")
15123 (let ((buffer (get-file-buffer (car token))))
15124 (speedbar-find-file-in-frame (car token))
15125 (when (or vhdl-speedbar-jump-to-unit buffer)
e6ce8c42
GM
15126 (goto-char (point-min))
15127 (forward-line (1- (cdr token)))
3dcb36b7
JB
15128 (recenter))
15129 (vhdl-speedbar-update-current-unit t t)
051897ff 15130 (speedbar-set-timer dframe-update-speed)
3dcb36b7 15131 (speedbar-maybee-jump-to-attached-frame))))
5eabfe72
KH
15132
15133(defun vhdl-speedbar-port-copy ()
3dcb36b7 15134 "Copy the port of the entity/component or subprogram under the cursor."
5eabfe72 15135 (interactive)
3dcb36b7
JB
15136 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15137 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15138 (error "ERROR: No entity/component or subprogram under cursor")
15139 (beginning-of-line)
15140 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15141 (condition-case info
15142 (let ((token (get-text-property
15143 (match-beginning 3) 'speedbar-token)))
15144 (vhdl-visit-file (car token) t
e6ce8c42
GM
15145 (progn (goto-char (point-min))
15146 (forward-line (1- (cdr token)))
3dcb36b7
JB
15147 (end-of-line)
15148 (if is-entity
15149 (vhdl-port-copy)
15150 (vhdl-subprog-copy)))))
15151 (error (error "ERROR: %s not scanned successfully\n (%s)"
15152 (if is-entity "Port" "Interface") (cadr info))))
15153 (error "ERROR: No entity/component or subprogram on current line")))))
15154
15155(defun vhdl-speedbar-place-component ()
15156 "Place the entity/component under the cursor as component."
15157 (interactive)
15158 (if (not (vhdl-speedbar-check-unit 'entity))
5bb5087f 15159 (error "ERROR: No entity/component under cursor")
3dcb36b7
JB
15160 (vhdl-speedbar-port-copy)
15161 (if (fboundp 'speedbar-select-attached-frame)
15162 (speedbar-select-attached-frame)
15163 (select-frame speedbar-attached-frame))
15164 (vhdl-compose-place-component)
15165 (select-frame speedbar-frame)))
15166
0a2e512a
RF
15167(defun vhdl-speedbar-configuration ()
15168 "Generate configuration for the architecture under the cursor."
15169 (interactive)
15170 (if (not (vhdl-speedbar-check-unit 'architecture))
15171 (error "ERROR: No architecture under cursor")
15172 (let ((arch-name (vhdl-speedbar-line-text))
15173 (ent-name (vhdl-speedbar-higher-text)))
15174 (if (fboundp 'speedbar-select-attached-frame)
15175 (speedbar-select-attached-frame)
15176 (select-frame speedbar-attached-frame))
15177 (vhdl-compose-configuration ent-name arch-name))))
15178
15179(defun vhdl-speedbar-select-mra ()
15180 "Select the architecture under the cursor as MRA."
15181 (interactive)
15182 (if (not (vhdl-speedbar-check-unit 'architecture))
15183 (error "ERROR: No architecture under cursor")
15184 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15185 (ent-key (downcase (vhdl-speedbar-higher-text)))
15186 (ent-alist (aget vhdl-entity-alist
15187 (or (vhdl-project-p) default-directory) t))
15188 (ent-entry (aget ent-alist ent-key t)))
15189 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15190 (speedbar-refresh))))
15191
3dcb36b7
JB
15192(defun vhdl-speedbar-make-design ()
15193 "Make (compile) design unit or directory/project under the cursor."
15194 (interactive)
15195 (if (not (save-excursion (beginning-of-line)
15196 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15197 (error "ERROR: No primary design unit or directory/project under cursor")
15198 (let ((is-unit (match-string 2))
15199 (unit-name (vhdl-speedbar-line-text))
15200 (vhdl-project (vhdl-speedbar-line-project))
15201 (directory (file-name-as-directory
7752250e 15202 (or (speedbar-line-file) (speedbar-line-directory)))))
3dcb36b7
JB
15203 (if (fboundp 'speedbar-select-attached-frame)
15204 (speedbar-select-attached-frame)
15205 (select-frame speedbar-attached-frame))
15206 (let ((default-directory directory))
15207 (vhdl-make (and is-unit unit-name))))))
15208
15209(defun vhdl-speedbar-generate-makefile ()
15210 "Generate Makefile for directory/project under the cursor."
15211 (interactive)
15212 (let ((vhdl-project (vhdl-speedbar-line-project))
15213 (default-directory (file-name-as-directory
7752250e 15214 (or (speedbar-line-file) (speedbar-line-directory)))))
3dcb36b7
JB
15215 (vhdl-generate-makefile)))
15216
15217(defun vhdl-speedbar-check-unit (design-unit)
15218 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15219expansion function)."
15220 (save-excursion
15221 (speedbar-position-cursor-on-line)
15222 (cond ((eq design-unit 'entity)
15223 (memq (get-text-property (match-end 0) 'face)
0a2e512a
RF
15224 '(vhdl-speedbar-entity-face
15225 vhdl-speedbar-entity-selected-face)))
15226 ((eq design-unit 'architecture)
15227 (memq (get-text-property (match-end 0) 'face)
15228 '(vhdl-speedbar-architecture-face
15229 vhdl-speedbar-architecture-selected-face)))
3dcb36b7
JB
15230 ((eq design-unit 'subprogram)
15231 (eq (get-text-property (match-end 0) 'face)
0a2e512a 15232 'vhdl-speedbar-subprogram-face))
3dcb36b7
JB
15233 (t nil))))
15234
15235(defun vhdl-speedbar-set-depth (depth)
15236 "Set hierarchy display depth to DEPTH and refresh speedbar."
15237 (setq vhdl-speedbar-hierarchy-depth depth)
15238 (speedbar-refresh))
5eabfe72
KH
15239
15240;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15241;; Fontification
15242
0a2e512a 15243(defface vhdl-speedbar-entity-face
5eabfe72
KH
15244 '((((class color) (background light)) (:foreground "ForestGreen"))
15245 (((class color) (background dark)) (:foreground "PaleGreen")))
15246 "Face used for displaying entity names."
15247 :group 'speedbar-faces)
15248
0a2e512a 15249(defface vhdl-speedbar-architecture-face
f47877ee
DN
15250 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15251 (((class color) (background light)) (:foreground "Blue"))
84c98ace 15252
5eabfe72
KH
15253 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15254 "Face used for displaying architecture names."
15255 :group 'speedbar-faces)
d2ddb974 15256
0a2e512a 15257(defface vhdl-speedbar-configuration-face
5eabfe72
KH
15258 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15259 (((class color) (background dark)) (:foreground "Salmon")))
15260 "Face used for displaying configuration names."
15261 :group 'speedbar-faces)
15262
0a2e512a 15263(defface vhdl-speedbar-package-face
5eabfe72
KH
15264 '((((class color) (background light)) (:foreground "Grey50"))
15265 (((class color) (background dark)) (:foreground "Grey80")))
15266 "Face used for displaying package names."
15267 :group 'speedbar-faces)
15268
0a2e512a 15269(defface vhdl-speedbar-library-face
3dcb36b7
JB
15270 '((((class color) (background light)) (:foreground "Purple"))
15271 (((class color) (background dark)) (:foreground "Orchid1")))
15272 "Face used for displaying library names."
15273 :group 'speedbar-faces)
15274
0a2e512a 15275(defface vhdl-speedbar-instantiation-face
5eabfe72 15276 '((((class color) (background light)) (:foreground "Brown"))
ea81d57e 15277 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
5eabfe72
KH
15278 (((class color) (background dark)) (:foreground "Yellow")))
15279 "Face used for displaying instantiation names."
15280 :group 'speedbar-faces)
15281
0a2e512a 15282(defface vhdl-speedbar-subprogram-face
3dcb36b7
JB
15283 '((((class color) (background light)) (:foreground "Orchid4"))
15284 (((class color) (background dark)) (:foreground "BurlyWood2")))
15285 "Face used for displaying subprogram names."
15286 :group 'speedbar-faces)
15287
0a2e512a 15288(defface vhdl-speedbar-entity-selected-face
5eabfe72
KH
15289 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15290 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15291 "Face used for displaying entity names."
15292 :group 'speedbar-faces)
15293
0a2e512a 15294(defface vhdl-speedbar-architecture-selected-face
f47877ee
DN
15295 '((((min-colors 88) (class color) (background light)) (:foreground
15296 "Blue1" :underline t))
15297 (((class color) (background light)) (:foreground "Blue" :underline t))
5eabfe72
KH
15298 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15299 "Face used for displaying architecture names."
15300 :group 'speedbar-faces)
15301
0a2e512a 15302(defface vhdl-speedbar-configuration-selected-face
5eabfe72
KH
15303 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15304 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15305 "Face used for displaying configuration names."
15306 :group 'speedbar-faces)
15307
0a2e512a 15308(defface vhdl-speedbar-package-selected-face
5eabfe72
KH
15309 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15310 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15311 "Face used for displaying package names."
15312 :group 'speedbar-faces)
15313
0a2e512a 15314(defface vhdl-speedbar-instantiation-selected-face
5eabfe72
KH
15315 '((((class color) (background light)) (:foreground "Brown" :underline t))
15316 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15317 "Face used for displaying instantiation names."
15318 :group 'speedbar-faces)
15319
3dcb36b7
JB
15320;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15321;; Initialization
15322
15323;; add speedbar
15324(when (fboundp 'speedbar)
15325 (condition-case ()
15326 (when (and vhdl-speedbar-auto-open
15327 (not (and (boundp 'speedbar-frame)
15328 (frame-live-p speedbar-frame))))
15329 (speedbar-frame-mode 1)
15330 (if (fboundp 'speedbar-select-attached-frame)
15331 (speedbar-select-attached-frame)
15332 (select-frame speedbar-attached-frame)))
15333 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15334
15335;; initialize speedbar
15336(if (not (boundp 'speedbar-frame))
15337 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15338 (vhdl-speedbar-initialize)
15339 (when speedbar-frame (vhdl-speedbar-refresh)))
15340
15341
15342;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15343;;; Structural composition
15344;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15345
15346(defun vhdl-get-components-package-name ()
15347 "Return the name of the components package."
15348 (let ((project (vhdl-project-p)))
15349 (if project
15350 (vhdl-replace-string (car vhdl-components-package-name)
15351 (subst-char-in-string ? ?_ project))
15352 (cdr vhdl-components-package-name))))
15353
15354(defun vhdl-compose-new-component ()
15355 "Create entity and architecture for new component."
15356 (interactive)
15357 (let* ((case-fold-search t)
15358 (ent-name (read-from-minibuffer "entity name: "
15359 nil vhdl-minibuffer-local-map))
15360 (arch-name
15361 (if (equal (cdr vhdl-compose-architecture-name) "")
15362 (read-from-minibuffer "architecture name: "
15363 nil vhdl-minibuffer-local-map)
15364 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15365 ent-file-name arch-file-name ent-buffer arch-buffer project)
15366 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15367 ;; open entity file
15368 (unless (eq vhdl-compose-create-files 'none)
15369 (setq ent-file-name
0a2e512a 15370 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15371 "." (file-name-extension (buffer-file-name))))
15372 (when (and (file-exists-p ent-file-name)
15373 (not (y-or-n-p (concat "File \"" ent-file-name
15374 "\" exists; overwrite? "))))
15375 (error "ERROR: Creating component...aborted"))
15376 (find-file ent-file-name)
15377 (erase-buffer)
15378 (set-buffer-modified-p nil))
15379 ;; insert header
15380 (if vhdl-compose-include-header
15381 (progn (vhdl-template-header)
15382 (goto-char (point-max)))
15383 (vhdl-comment-display-line) (insert "\n\n"))
15384 ;; insert library clause
15385 (vhdl-template-package-std-logic-1164)
15386 (when vhdl-use-components-package
15387 (insert "\n")
15388 (vhdl-template-standard-package (vhdl-work-library)
15389 (vhdl-get-components-package-name)))
15390 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15391 ;; insert entity declaration
15392 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15393 (vhdl-insert-keyword " IS\n")
15394 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15395 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15396 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15397 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15398 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15399 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15400 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15401 (vhdl-insert-keyword "END ")
15402 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15403 (insert ent-name ";\n\n")
15404 (vhdl-comment-display-line) (insert "\n")
15405 ;; open architecture file
15406 (if (not (eq vhdl-compose-create-files 'separate))
15407 (insert "\n")
15408 (setq ent-buffer (current-buffer))
15409 (setq arch-file-name
15410 (concat (vhdl-replace-string vhdl-architecture-file-name
0a2e512a 15411 (concat ent-name " " arch-name) t)
3dcb36b7
JB
15412 "." (file-name-extension (buffer-file-name))))
15413 (when (and (file-exists-p arch-file-name)
15414 (not (y-or-n-p (concat "File \"" arch-file-name
15415 "\" exists; overwrite? "))))
15416 (error "ERROR: Creating component...aborted"))
15417 (find-file arch-file-name)
15418 (erase-buffer)
15419 (set-buffer-modified-p nil)
15420 ;; insert header
15421 (if vhdl-compose-include-header
15422 (progn (vhdl-template-header)
15423 (goto-char (point-max)))
15424 (vhdl-comment-display-line) (insert "\n\n")))
15425 ;; insert architecture body
15426 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15427 (vhdl-insert-keyword " OF ") (insert ent-name)
15428 (vhdl-insert-keyword " IS\n\n")
15429 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15430 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15431 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15432 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15433 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15434 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15435 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15436 (vhdl-insert-keyword "BEGIN")
15437 (when vhdl-self-insert-comments
15438 (insert " -- ")
15439 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15440 (insert arch-name))
15441 (insert "\n\n")
15442 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15443 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15444 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15445 (vhdl-insert-keyword "END ")
15446 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15447 (insert arch-name ";\n\n")
0a2e512a 15448 ;; insert footer and save
3dcb36b7
JB
15449 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15450 (vhdl-template-footer)
15451 (vhdl-comment-display-line) (insert "\n"))
15452 (goto-char (point-min))
15453 (setq arch-buffer (current-buffer))
15454 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15455 (set-buffer arch-buffer) (save-buffer)
29a4e67d 15456 (message "%s"
3dcb36b7
JB
15457 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15458 (and ent-file-name
15459 (format "\n File created: \"%s\"" ent-file-name))
15460 (and arch-file-name
15461 (format "\n File created: \"%s\"" arch-file-name))))))
15462
15463(defun vhdl-compose-place-component ()
15464 "Place new component by pasting current port as component declaration and
15465component instantiation."
15466 (interactive)
15467 (if (not vhdl-port-list)
15468 (error "ERROR: No port has been read")
15469 (save-excursion
15470 (vhdl-prepare-search-2
15471 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15472 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15473 (error "ERROR: No architecture found"))
15474 (let* ((ent-name (match-string 1))
15475 (ent-file-name
0a2e512a 15476 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15477 "." (file-name-extension (buffer-file-name))))
15478 (orig-buffer (current-buffer)))
15479 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15480 ;; place component declaration
15481 (unless (or vhdl-use-components-package
15482 (vhdl-use-direct-instantiation)
15483 (save-excursion
15484 (re-search-forward
15485 (concat "^\\s-*component\\s-+"
15486 (car vhdl-port-list) "\\>") nil t)))
15487 (re-search-forward "^begin\\>" nil)
15488 (beginning-of-line)
15489 (skip-chars-backward " \t\n")
15490 (insert "\n\n") (indent-to vhdl-basic-offset)
15491 (vhdl-port-paste-component t))
15492 ;; place component instantiation
15493 (re-search-forward "^end\\>" nil)
15494 (beginning-of-line)
15495 (skip-chars-backward " \t\n")
15496 (insert "\n\n") (indent-to vhdl-basic-offset)
15497 (vhdl-port-paste-instance nil t t)
15498 ;; place use clause for used packages
15499 (when (nth 3 vhdl-port-list)
15500 ;; open entity file
15501 (when (file-exists-p ent-file-name)
15502 (find-file ent-file-name))
15503 (goto-char (point-min))
15504 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15505 (error "ERROR: Entity not found: \"%s\"" ent-name))
15506 (goto-char (match-beginning 0))
15507 (if (and (save-excursion
15508 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15509 (match-string 1))
15510 (progn (goto-char (match-end 0))
15511 (beginning-of-line 2))
15512 (insert "\n")
15513 (backward-char))
15514 (vhdl-port-paste-context-clause)
15515 (switch-to-buffer orig-buffer))
15516 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15517
15518(defun vhdl-compose-wire-components ()
15519 "Connect components."
15520 (interactive)
15521 (save-excursion
15522 (vhdl-prepare-search-2
15523 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15524 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15525 (error "ERROR: No architecture found"))
15526 (let* ((ent-name (match-string 1))
15527 (ent-file-name
0a2e512a 15528 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15529 "." (file-name-extension (buffer-file-name))))
15530 (arch-decl-pos (point-marker))
15531 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15532 (arch-end-pos (re-search-forward "^end\\>" nil))
15533 (pack-name (vhdl-get-components-package-name))
15534 (pack-file-name
0a2e512a 15535 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15536 "." (file-name-extension (buffer-file-name))))
15537 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15538 port-alist generic-alist inst-alist
15539 signal-name signal-entry signal-alist local-list written-list
15540 single-in-list multi-in-list single-out-list multi-out-list
15541 constant-name constant-entry constant-alist single-list multi-list
15542 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15543 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15544 signal-beg-pos signal-pos
15545 constant-temp-pos port-temp-pos signal-temp-pos)
15546 (message "Wiring components...")
15547 ;; process all instances
15548 (goto-char arch-stat-pos)
15549 (while (re-search-forward
15550 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15551 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15552 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15553 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15554 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15555 (setq inst-name (match-string-no-properties 1)
15556 comp-name (match-string-no-properties 4)
15557 comp-ent-name (match-string-no-properties 12)
15558 has-generic (or (match-string 7) (match-string 17)))
15559 ;; get port ...
15560 (if comp-name
15561 ;; ... from component declaration
15562 (vhdl-visit-file
15563 (when vhdl-use-components-package pack-file-name) t
15564 (save-excursion
15565 (goto-char (point-min))
15566 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15567 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15568 (vhdl-port-copy)))
15569 ;; ... from entity declaration (direct instantiation)
15570 (setq comp-ent-file-name
0a2e512a 15571 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
3dcb36b7
JB
15572 "." (file-name-extension (buffer-file-name))))
15573 (vhdl-visit-file
15574 comp-ent-file-name t
15575 (save-excursion
15576 (goto-char (point-min))
15577 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15578 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15579 (vhdl-port-copy))))
15580 (vhdl-port-flatten t)
15581 (setq generic-alist (nth 1 vhdl-port-list)
0a2e512a
RF
15582 port-alist (nth 2 vhdl-port-list)
15583 vhdl-port-list nil)
3dcb36b7
JB
15584 (setq constant-alist nil
15585 signal-alist nil)
15586 (when has-generic
15587 ;; process all constants in generic map
15588 (vhdl-forward-syntactic-ws)
15589 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15590 (setq constant-name (match-string-no-properties 3))
15591 (setq constant-entry
15592 (cons constant-name
15593 (if (match-string 1)
15594 (or (aget generic-alist (match-string 2) t)
ec3ec9cc 15595 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15596 (cdar generic-alist))))
15597 (setq constant-alist (cons constant-entry constant-alist))
15598 (setq constant-name (downcase constant-name))
15599 (if (or (member constant-name single-list)
15600 (member constant-name multi-list))
15601 (progn (setq single-list (delete constant-name single-list))
15602 (add-to-list 'multi-list constant-name))
15603 (add-to-list 'single-list constant-name))
15604 (unless (match-string 1)
15605 (setq generic-alist (cdr generic-alist)))
15606 (vhdl-forward-syntactic-ws))
15607 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15608 ;; process all signals in port map
15609 (vhdl-forward-syntactic-ws)
15610 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15611 (setq signal-name (match-string-no-properties 3))
15612 (setq signal-entry (cons signal-name
15613 (if (match-string 1)
15614 (or (aget port-alist (match-string 2) t)
ec3ec9cc 15615 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15616 (cdar port-alist))))
15617 (setq signal-alist (cons signal-entry signal-alist))
15618 (setq signal-name (downcase signal-name))
15619 (if (equal (upcase (nth 2 signal-entry)) "IN")
15620 ;; input signal
15621 (cond
15622 ((member signal-name local-list)
15623 nil)
15624 ((or (member signal-name single-out-list)
15625 (member signal-name multi-out-list))
15626 (setq single-out-list (delete signal-name single-out-list))
15627 (setq multi-out-list (delete signal-name multi-out-list))
15628 (add-to-list 'local-list signal-name))
15629 ((member signal-name single-in-list)
15630 (setq single-in-list (delete signal-name single-in-list))
15631 (add-to-list 'multi-in-list signal-name))
15632 ((not (member signal-name multi-in-list))
15633 (add-to-list 'single-in-list signal-name)))
15634 ;; output signal
15635 (cond
15636 ((member signal-name local-list)
15637 nil)
15638 ((or (member signal-name single-in-list)
15639 (member signal-name multi-in-list))
15640 (setq single-in-list (delete signal-name single-in-list))
15641 (setq multi-in-list (delete signal-name multi-in-list))
15642 (add-to-list 'local-list signal-name))
15643 ((member signal-name single-out-list)
15644 (setq single-out-list (delete signal-name single-out-list))
15645 (add-to-list 'multi-out-list signal-name))
15646 ((not (member signal-name multi-out-list))
15647 (add-to-list 'single-out-list signal-name))))
15648 (unless (match-string 1)
15649 (setq port-alist (cdr port-alist)))
15650 (vhdl-forward-syntactic-ws))
15651 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15652 (nreverse signal-alist)) inst-alist)))
15653 ;; prepare signal insertion
15654 (vhdl-goto-marker arch-decl-pos)
15655 (forward-line 1)
15656 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15657 (setq signal-pos (point-marker))
15658 (while (progn (vhdl-forward-syntactic-ws)
15659 (looking-at "signal\\>"))
15660 (beginning-of-line 2)
15661 (delete-region signal-pos (point)))
15662 (setq signal-beg-pos signal-pos)
15663 ;; open entity file
15664 (when (file-exists-p ent-file-name)
15665 (find-file ent-file-name))
15666 (goto-char (point-min))
15667 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15668 (error "ERROR: Entity not found: \"%s\"" ent-name))
15669 ;; prepare generic clause insertion
15670 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15671 (match-string 1))
15672 (goto-char (match-beginning 0))
15673 (indent-to vhdl-basic-offset)
15674 (insert "generic ();\n\n")
15675 (backward-char 4))
15676 (backward-char)
15677 (setq generic-pos (point-marker))
15678 (forward-sexp) (end-of-line)
15679 (delete-region generic-pos (point)) (delete-char 1)
15680 (insert "(\n")
15681 (when multi-list
15682 (insert "\n")
15683 (indent-to (* 2 vhdl-basic-offset))
15684 (insert "-- global generics\n"))
15685 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15686 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15687 ;; prepare port clause insertion
15688 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15689 (match-string 1))
15690 (goto-char (match-beginning 0))
15691 (indent-to vhdl-basic-offset)
15692 (insert "port ();\n\n")
15693 (backward-char 4))
15694 (backward-char)
15695 (setq port-in-pos (point-marker))
15696 (forward-sexp) (end-of-line)
15697 (delete-region port-in-pos (point)) (delete-char 1)
15698 (insert "(\n")
15699 (when (or multi-in-list multi-out-list)
15700 (insert "\n")
15701 (indent-to (* 2 vhdl-basic-offset))
15702 (insert "-- global ports\n"))
15703 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15704 port-out-pos (point-marker) port-inst-pos (point-marker)
15705 port-end-pos (point-marker))
15706 ;; insert generics, ports and signals
15707 (setq inst-alist (nreverse inst-alist))
15708 (while inst-alist
15709 (setq inst-name (nth 0 (car inst-alist))
15710 constant-alist (nth 1 (car inst-alist))
15711 signal-alist (nth 2 (car inst-alist))
15712 constant-temp-pos generic-inst-pos
15713 port-temp-pos port-inst-pos
15714 signal-temp-pos signal-pos)
15715 ;; generics
15716 (while constant-alist
15717 (setq constant-name (downcase (caar constant-alist))
15718 constant-entry (car constant-alist))
15719 (cond ((member constant-name written-list)
15720 nil)
15721 ((member constant-name multi-list)
15722 (vhdl-goto-marker generic-pos)
15723 (setq generic-end-pos
15724 (vhdl-max-marker
15725 generic-end-pos
15726 (vhdl-compose-insert-generic constant-entry)))
15727 (setq generic-pos (point-marker))
15728 (add-to-list 'written-list constant-name))
15729 (t
15730 (vhdl-goto-marker
15731 (vhdl-max-marker generic-inst-pos generic-pos))
15732 (setq generic-end-pos
15733 (vhdl-compose-insert-generic constant-entry))
15734 (setq generic-inst-pos (point-marker))
15735 (add-to-list 'written-list constant-name)))
15736 (setq constant-alist (cdr constant-alist)))
15737 (when (/= constant-temp-pos generic-inst-pos)
15738 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15739 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15740 (insert "-- generics for \"" inst-name "\"\n")
15741 (vhdl-goto-marker generic-inst-pos))
15742 ;; ports and signals
15743 (while signal-alist
15744 (setq signal-name (downcase (caar signal-alist))
15745 signal-entry (car signal-alist))
15746 (cond ((member signal-name written-list)
15747 nil)
15748 ((member signal-name multi-in-list)
15749 (vhdl-goto-marker port-in-pos)
15750 (setq port-end-pos
15751 (vhdl-max-marker
15752 port-end-pos (vhdl-compose-insert-port signal-entry)))
15753 (setq port-in-pos (point-marker))
15754 (add-to-list 'written-list signal-name))
15755 ((member signal-name multi-out-list)
15756 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15757 (setq port-end-pos
15758 (vhdl-max-marker
15759 port-end-pos (vhdl-compose-insert-port signal-entry)))
15760 (setq port-out-pos (point-marker))
15761 (add-to-list 'written-list signal-name))
15762 ((or (member signal-name single-in-list)
15763 (member signal-name single-out-list))
15764 (vhdl-goto-marker
15765 (vhdl-max-marker
15766 port-inst-pos
15767 (vhdl-max-marker port-out-pos port-in-pos)))
15768 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15769 (setq port-inst-pos (point-marker))
15770 (add-to-list 'written-list signal-name))
15771 ((equal (upcase (nth 2 signal-entry)) "OUT")
15772 (vhdl-goto-marker signal-pos)
15773 (vhdl-compose-insert-signal signal-entry)
15774 (setq signal-pos (point-marker))
15775 (add-to-list 'written-list signal-name)))
15776 (setq signal-alist (cdr signal-alist)))
15777 (when (/= port-temp-pos port-inst-pos)
15778 (vhdl-goto-marker
15779 (vhdl-max-marker port-temp-pos
15780 (vhdl-max-marker port-in-pos port-out-pos)))
15781 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15782 (insert "-- ports to \"" inst-name "\"\n")
15783 (vhdl-goto-marker port-inst-pos))
15784 (when (/= signal-temp-pos signal-pos)
15785 (vhdl-goto-marker signal-temp-pos)
15786 (insert "\n") (indent-to vhdl-basic-offset)
15787 (insert "-- outputs of \"" inst-name "\"\n")
15788 (vhdl-goto-marker signal-pos))
15789 (setq inst-alist (cdr inst-alist)))
15790 ;; finalize generic/port clause
15791 (vhdl-goto-marker generic-end-pos) (backward-char)
15792 (when (= generic-beg-pos generic-end-pos)
15793 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15794 (insert ";") (backward-char))
15795 (insert ")")
15796 (vhdl-goto-marker port-end-pos) (backward-char)
15797 (when (= port-beg-pos port-end-pos)
15798 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15799 (insert ";") (backward-char))
15800 (insert ")")
15801 ;; align everything
15802 (when vhdl-auto-align
15803 (vhdl-goto-marker generic-beg-pos)
15804 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15805 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15806 (vhdl-goto-marker signal-beg-pos)
15807 (vhdl-align-region-groups signal-beg-pos signal-pos))
15808 (switch-to-buffer (marker-buffer signal-beg-pos))
15809 (message "Wiring components...done")))))
15810
15811(defun vhdl-compose-insert-generic (entry)
15812 "Insert ENTRY as generic declaration."
15813 (let (pos)
15814 (indent-to (* 2 vhdl-basic-offset))
15815 (insert (nth 0 entry) " : " (nth 1 entry))
15816 (when (nth 2 entry)
15817 (insert " := " (nth 2 entry)))
15818 (insert ";")
15819 (setq pos (point-marker))
15820 (when (and vhdl-include-port-comments (nth 3 entry))
15821 (vhdl-comment-insert-inline (nth 3 entry) t))
15822 (insert "\n")
15823 pos))
15824
15825(defun vhdl-compose-insert-port (entry)
15826 "Insert ENTRY as port declaration."
15827 (let (pos)
15828 (indent-to (* 2 vhdl-basic-offset))
15829 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15830 (setq pos (point-marker))
15831 (when (and vhdl-include-port-comments (nth 4 entry))
15832 (vhdl-comment-insert-inline (nth 4 entry) t))
15833 (insert "\n")
15834 pos))
15835
15836(defun vhdl-compose-insert-signal (entry)
15837 "Insert ENTRY as signal declaration."
15838 (indent-to vhdl-basic-offset)
15839 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15840 (when (and vhdl-include-port-comments (nth 4 entry))
15841 (vhdl-comment-insert-inline (nth 4 entry) t))
15842 (insert "\n"))
15843
15844(defun vhdl-compose-components-package ()
15845 "Generate a package containing component declarations for all entities in the
15846current project/directory."
15847 (interactive)
15848 (vhdl-require-hierarchy-info)
15849 (let* ((project (vhdl-project-p))
15850 (pack-name (vhdl-get-components-package-name))
15851 (pack-file-name
0a2e512a 15852 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15853 "." (file-name-extension (buffer-file-name))))
15854 (ent-alist (aget vhdl-entity-alist
15855 (or project default-directory) t))
15856 (lazy-lock-minimum-size 0)
15857 clause-pos component-pos)
15858 (message "Generating components package \"%s\"..." pack-name)
15859 ;; open package file
15860 (when (and (file-exists-p pack-file-name)
15861 (not (y-or-n-p (concat "File \"" pack-file-name
15862 "\" exists; overwrite? "))))
15863 (error "ERROR: Generating components package...aborted"))
15864 (find-file pack-file-name)
15865 (erase-buffer)
15866 ;; insert header
15867 (if vhdl-compose-include-header
15868 (progn (vhdl-template-header
15869 (concat "Components package (generated by Emacs VHDL Mode "
15870 vhdl-version ")"))
15871 (goto-char (point-max)))
15872 (vhdl-comment-display-line) (insert "\n\n"))
15873 ;; insert std_logic_1164 package
15874 (vhdl-template-package-std-logic-1164)
15875 (insert "\n") (setq clause-pos (point-marker))
15876 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15877 ;; insert package declaration
15878 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15879 (vhdl-insert-keyword " IS\n\n")
15880 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15881 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15882 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15883 (indent-to vhdl-basic-offset)
15884 (setq component-pos (point-marker))
15885 (insert "\n\n") (vhdl-insert-keyword "END ")
15886 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15887 (insert pack-name ";\n\n")
15888 ;; insert footer
15889 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15890 (vhdl-template-footer)
15891 (vhdl-comment-display-line) (insert "\n"))
15892 ;; insert component declarations
15893 (while ent-alist
15894 (vhdl-visit-file (nth 2 (car ent-alist)) nil
e6ce8c42
GM
15895 (progn (goto-char (point-min))
15896 (forward-line (1- (nth 3 (car ent-alist))))
3dcb36b7
JB
15897 (end-of-line)
15898 (vhdl-port-copy)))
15899 (goto-char component-pos)
15900 (vhdl-port-paste-component t)
15901 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15902 (setq component-pos (point-marker))
15903 (goto-char clause-pos)
15904 (vhdl-port-paste-context-clause pack-name)
15905 (setq clause-pos (point-marker))
15906 (setq ent-alist (cdr ent-alist)))
15907 (goto-char (point-min))
15908 (save-buffer)
15909 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15910 pack-name pack-file-name)))
15911
0a2e512a
RF
15912(defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15913 &optional insert-conf)
15914 "Generate block configuration for architecture."
15915 (let ((margin (current-indentation))
e180ab9f 15916 (beg (point-at-bol))
0a2e512a
RF
15917 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15918 ;; insert block configuration (for architecture)
15919 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15920 (setq margin (+ margin vhdl-basic-offset))
15921 ;; process all instances
15922 (while inst-alist
15923 (setq inst-entry (car inst-alist))
15924 ;; is component?
15925 (when (nth 4 inst-entry)
15926 (setq insert-conf t)
15927 (setq inst-path (nth 9 inst-entry))
15928 ;; skip common path with previous instance
15929 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15930 (setq inst-path (cdr inst-path)
15931 inst-prev-path (cdr inst-prev-path)))
15932 ;; insert block configuration end (for previous block/generate)
15933 (while inst-prev-path
15934 (setq margin (- margin vhdl-basic-offset))
15935 (indent-to margin)
15936 (vhdl-insert-keyword "END FOR;\n")
15937 (setq inst-prev-path (cdr inst-prev-path)))
15938 ;; insert block configuration beginning (for current block/generate)
15939 (indent-to margin)
15940 (while inst-path
15941 (setq margin (+ margin vhdl-basic-offset))
15942 (vhdl-insert-keyword "FOR ")
15943 (insert (car inst-path) "\n")
15944 (indent-to margin)
15945 (setq inst-path (cdr inst-path)))
15946 ;; insert component configuration beginning
15947 (vhdl-insert-keyword "FOR ")
15948 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15949 ;; find subconfiguration
15950 (setq conf-key (nth 7 inst-entry))
15951 (setq tmp-alist conf-alist)
15952 ;; use first configuration found for instance's entity
15953 (while (and tmp-alist (null conf-key))
15954 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15955 (setq conf-key (nth 0 (car tmp-alist))))
15956 (setq tmp-alist (cdr tmp-alist)))
15957 (setq conf-entry (aget conf-alist conf-key t))
15958 ;; insert binding indication ...
15959 ;; ... with subconfiguration (if exists)
15960 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15961 (progn
15962 (indent-to (+ margin vhdl-basic-offset))
15963 (vhdl-insert-keyword "USE CONFIGURATION ")
15964 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15965 (insert ";\n"))
15966 ;; ... with entity (if exists)
15967 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15968 (when ent-entry
15969 (indent-to (+ margin vhdl-basic-offset))
15970 (vhdl-insert-keyword "USE ENTITY ")
15971 (insert (vhdl-work-library) "." (nth 0 ent-entry))
15972 ;; insert architecture name (if architecture exists)
15973 (when (nth 3 ent-entry)
15974 (setq arch-name
15975 ;; choose architecture name a) from configuration,
15976 ;; b) from mra, or c) from first architecture
15977 (or (nth 0 (aget (nth 3 ent-entry)
15978 (or (nth 6 inst-entry)
15979 (nth 4 ent-entry)) t))
15980 (nth 1 (car (nth 3 ent-entry)))))
15981 (insert "(" arch-name ")"))
15982 (insert ";\n")
15983 ;; insert block configuration (for architecture of subcomponent)
15984 (when (and vhdl-compose-configuration-hierarchical
15985 (nth 3 ent-entry))
15986 (indent-to (+ margin vhdl-basic-offset))
15987 (vhdl-compose-configuration-architecture
15988 (nth 0 ent-entry) arch-name
15989 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
15990 ;; insert component configuration end
15991 (indent-to margin)
15992 (vhdl-insert-keyword "END FOR;\n")
15993 (setq inst-prev-path (nth 9 inst-entry)))
15994 (setq inst-alist (cdr inst-alist)))
15995 ;; insert block configuration end (for block/generate)
15996 (while inst-prev-path
15997 (setq margin (- margin vhdl-basic-offset))
15998 (indent-to margin)
15999 (vhdl-insert-keyword "END FOR;\n")
16000 (setq inst-prev-path (cdr inst-prev-path)))
16001 (indent-to (- margin vhdl-basic-offset))
16002 ;; insert block configuration end or remove beginning (for architecture)
16003 (if insert-conf
16004 (vhdl-insert-keyword "END FOR;\n")
16005 (delete-region beg (point)))))
16006
16007(defun vhdl-compose-configuration (&optional ent-name arch-name)
16008 "Generate configuration declaration."
16009 (interactive)
16010 (vhdl-require-hierarchy-info)
16011 (let ((ent-alist (aget vhdl-entity-alist
16012 (or (vhdl-project-p) default-directory) t))
16013 (conf-alist (aget vhdl-config-alist
16014 (or (vhdl-project-p) default-directory) t))
16015 (from-speedbar ent-name)
16016 inst-alist conf-name conf-file-name pos)
16017 (vhdl-prepare-search-2
16018 ;; get entity and architecture name
16019 (unless ent-name
16020 (save-excursion
16021 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16022 (not (equal "END" (upcase (match-string 1))))
16023 (setq ent-name (match-string-no-properties 3))
16024 (setq arch-name (match-string-no-properties 2)))
16025 (error "ERROR: Not within an architecture"))))
16026 (setq conf-name (vhdl-replace-string
16027 vhdl-compose-configuration-name
16028 (concat ent-name " " arch-name)))
16029 (setq inst-alist
16030 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16031 (downcase arch-name) t))))
16032 (message "Generating configuration \"%s\"..." conf-name)
16033 (if vhdl-compose-configuration-create-file
16034 ;; open configuration file
16035 (progn
16036 (setq conf-file-name
16037 (concat (vhdl-replace-string vhdl-configuration-file-name
16038 conf-name t)
16039 "." (file-name-extension (buffer-file-name))))
16040 (when (and (file-exists-p conf-file-name)
16041 (not (y-or-n-p (concat "File \"" conf-file-name
16042 "\" exists; overwrite? "))))
16043 (error "ERROR: Creating configuration...aborted"))
16044 (find-file conf-file-name)
16045 (erase-buffer)
16046 (set-buffer-modified-p nil)
16047 ;; insert header
16048 (if vhdl-compose-include-header
16049 (progn (vhdl-template-header
16050 (concat "Configuration declaration for design \""
16051 ent-name "(" arch-name ")\""))
16052 (goto-char (point-max)))
16053 (vhdl-comment-display-line) (insert "\n\n")))
16054 ;; goto end of architecture
16055 (unless from-speedbar
16056 (re-search-forward "^end\\>" nil)
16057 (end-of-line) (insert "\n\n")
16058 (vhdl-comment-display-line) (insert "\n\n")))
16059 ;; insert library clause
16060 (setq pos (point))
16061 (vhdl-template-standard-package (vhdl-work-library) nil)
16062 (when (/= pos (point))
16063 (insert "\n\n"))
16064 ;; insert configuration
16065 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16066 (vhdl-insert-keyword " OF ") (insert ent-name)
16067 (vhdl-insert-keyword " IS\n")
16068 (indent-to vhdl-basic-offset)
16069 ;; insert block configuration (for architecture)
16070 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16071 (vhdl-insert-keyword "END ") (insert conf-name ";")
16072 (when conf-file-name
16073 ;; insert footer and save
16074 (insert "\n\n")
16075 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16076 (vhdl-template-footer)
16077 (vhdl-comment-display-line) (insert "\n"))
16078 (save-buffer))
29a4e67d 16079 (message "%s"
0a2e512a
RF
16080 (concat (format "Generating configuration \"%s\"...done" conf-name)
16081 (and conf-file-name
16082 (format "\n File created: \"%s\"" conf-file-name))))))
16083
3dcb36b7
JB
16084
16085;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16086;;; Compilation / Makefile generation
16087;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16088;; (using `compile.el')
16089
16090(defun vhdl-makefile-name ()
16091 "Return the Makefile name of the current project or the current compiler if
16092no project is defined."
16093 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16094 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16095 (vhdl-replace-string
16096 (cons "\\(.*\\)\n\\(.*\\)"
16097 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16098 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16099
16100(defun vhdl-compile-directory ()
16101 "Return the directory where compilation/make should be run."
16102 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16103 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16104 (directory (vhdl-resolve-env-variable
16105 (if project
16106 (vhdl-replace-string
16107 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16108 (nth 6 compiler)))))
16109 (file-name-as-directory
16110 (if (file-name-absolute-p directory)
16111 directory
16112 (expand-file-name directory (vhdl-default-directory))))))
16113
16114(defun vhdl-uniquify (in-list)
16115 "Remove duplicate elements from IN-LIST."
16116 (let (out-list)
16117 (while in-list
16118 (add-to-list 'out-list (car in-list))
16119 (setq in-list (cdr in-list)))
16120 out-list))
16121
16122(defun vhdl-set-compiler (name)
16123 "Set current compiler to NAME."
16124 (interactive
16125 (list (let ((completion-ignore-case t))
16126 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16127 (if (assoc name vhdl-compiler-alist)
16128 (progn (setq vhdl-compiler name)
16129 (message "Current compiler: \"%s\"" vhdl-compiler))
16130 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16131
16132;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16133;; Compilation
16134
16135(defun vhdl-compile-init ()
16136 "Initialize for compilation."
16137 (when (or (null compilation-error-regexp-alist)
16138 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16139 compilation-error-regexp-alist)))
16140 ;; `compilation-error-regexp-alist'
16141 (let ((commands-alist vhdl-compiler-alist)
16142 regexp-alist sublist)
16143 (while commands-alist
16144 (setq sublist (nth 11 (car commands-alist)))
16145 (unless (or (equal "" (car sublist))
16146 (assoc (car sublist) regexp-alist))
16147 (setq regexp-alist (cons (list (nth 0 sublist)
16148 (if (= 0 (nth 1 sublist))
f8246027 16149 (if (featurep 'xemacs) 9 nil)
3dcb36b7
JB
16150 (nth 1 sublist))
16151 (nth 2 sublist) (nth 3 sublist))
16152 regexp-alist)))
16153 (setq commands-alist (cdr commands-alist)))
16154 (setq compilation-error-regexp-alist
16155 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16156 ;; `compilation-file-regexp-alist'
16157 (let ((commands-alist vhdl-compiler-alist)
16158 regexp-alist sublist)
16159 ;; matches vhdl-mode file name output
16160 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16161 (while commands-alist
16162 (setq sublist (nth 12 (car commands-alist)))
16163 (unless (or (equal "" (car sublist))
16164 (assoc (car sublist) regexp-alist))
16165 (setq regexp-alist (cons sublist regexp-alist)))
16166 (setq commands-alist (cdr commands-alist)))
16167 (setq compilation-file-regexp-alist
16168 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16169
16170(defvar vhdl-compile-file-name nil
16171 "Name of file to be compiled.")
16172
16173(defun vhdl-compile-print-file-name ()
16174 "Function called within `compile' to print out file name for compilers that
16175do not print any file names."
16176 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16177
16178(defun vhdl-get-compile-options (project compiler file-name
16179 &optional file-options-only)
16180 "Get compiler options. Returning nil means do not compile this file."
16181 (let* ((compiler-options (nth 1 compiler))
16182 (project-entry (aget (nth 4 project) vhdl-compiler))
16183 (project-options (nth 0 project-entry))
16184 (exception-list (and file-name (nth 2 project-entry)))
16185 (work-library (vhdl-work-library))
16186 (case-fold-search nil)
16187 file-options)
16188 (while (and exception-list
16189 (not (string-match (caar exception-list) file-name)))
16190 (setq exception-list (cdr exception-list)))
16191 (if (and exception-list (not (cdar exception-list)))
16192 nil
16193 (if (and file-options-only (not exception-list))
16194 'default
16195 (setq file-options (cdar exception-list))
16196 ;; insert library name in compiler-specific options
16197 (setq compiler-options
16198 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16199 work-library))
16200 ;; insert compiler-specific options in project-specific options
16201 (when project-options
16202 (setq project-options
16203 (vhdl-replace-string
16204 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16205 (concat work-library "\n" compiler-options))))
16206 ;; insert project-specific options in file-specific options
16207 (when file-options
16208 (setq file-options
16209 (vhdl-replace-string
16210 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16211 (concat work-library "\n" compiler-options "\n"
16212 project-options))))
16213 ;; return options
16214 (or file-options project-options compiler-options)))))
16215
16216(defun vhdl-get-make-options (project compiler)
16217 "Get make options."
16218 (let* ((compiler-options (nth 3 compiler))
16219 (project-entry (aget (nth 4 project) vhdl-compiler))
16220 (project-options (nth 1 project-entry))
16221 (makefile-name (vhdl-makefile-name)))
16222 ;; insert Makefile name in compiler-specific options
16223 (setq compiler-options
16224 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16225 makefile-name))
16226 ;; insert compiler-specific options in project-specific options
16227 (when project-options
16228 (setq project-options
16229 (vhdl-replace-string
16230 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16231 (concat makefile-name "\n" compiler-options))))
16232 ;; return options
16233 (or project-options compiler-options)))
16234
16235(defun vhdl-compile ()
16236 "Compile current buffer using the VHDL compiler specified in
16237`vhdl-compiler'."
16238 (interactive)
16239 (vhdl-compile-init)
16240 (let* ((project (aget vhdl-project-alist vhdl-project))
16241 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16242 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16243 (command (nth 0 compiler))
16244 (file-name (buffer-file-name))
16245 (options (vhdl-get-compile-options project compiler file-name))
16246 (default-directory (vhdl-compile-directory))
16247 compilation-process-setup-function)
16248 (unless (file-directory-p default-directory)
16249 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16250 ;; put file name into quotes if it contains spaces
16251 (when (string-match " " file-name)
16252 (setq file-name (concat "\"" file-name "\"")))
16253 ;; print out file name if compiler does not
16254 (setq vhdl-compile-file-name (buffer-file-name))
16255 (when (and (= 0 (nth 1 (nth 10 compiler)))
16256 (= 0 (nth 1 (nth 11 compiler))))
16257 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16258 ;; run compilation
16259 (if options
16260 (when command
16261 (compile (concat command " " options " " file-name)))
16262 (vhdl-warning "Your project settings tell me not to compile this file"))))
16263
0a2e512a
RF
16264(defvar vhdl-make-target "all"
16265 "Default target for `vhdl-make' command.")
16266
3dcb36b7
JB
16267(defun vhdl-make (&optional target)
16268 "Call make command for compilation of all updated source files (requires
16269`Makefile'). Optional argument TARGET allows to compile the design
16270specified by a target."
16271 (interactive)
0a2e512a
RF
16272 (setq vhdl-make-target
16273 (or target (read-from-minibuffer "Target: " vhdl-make-target
16274 vhdl-minibuffer-local-map)))
3dcb36b7
JB
16275 (vhdl-compile-init)
16276 (let* ((project (aget vhdl-project-alist vhdl-project))
16277 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16278 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16279 (command (nth 2 compiler))
16280 (options (vhdl-get-make-options project compiler))
16281 (default-directory (vhdl-compile-directory)))
16282 (unless (file-directory-p default-directory)
16283 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16284 ;; run make
16285 (compile (concat (if (equal command "") "make" command)
0a2e512a 16286 " " options " " vhdl-make-target))))
3dcb36b7
JB
16287
16288;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16289;; Makefile generation
16290
16291(defun vhdl-generate-makefile ()
16292 "Generate `Makefile'."
16293 (interactive)
16294 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16295 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16296 (command (nth 4 compiler)))
16297 ;; generate makefile
16298 (if command
16299 (let ((default-directory (vhdl-compile-directory)))
16300 (compile (vhdl-replace-string
16301 (cons "\\(.*\\) \\(.*\\)" command)
16302 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16303 (vhdl-generate-makefile-1))))
16304
16305(defun vhdl-get-packages (lib-alist work-library)
16306 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16307 (let (pack-list)
16308 (while lib-alist
16309 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16310 (setq pack-list (cons (cdar lib-alist) pack-list)))
16311 (setq lib-alist (cdr lib-alist)))
16312 pack-list))
16313
16314(defun vhdl-generate-makefile-1 ()
16315 "Generate Makefile for current project or directory."
16316 ;; scan hierarchy if required
16317 (if (vhdl-project-p)
16318 (unless (or (assoc vhdl-project vhdl-file-alist)
16319 (vhdl-load-cache vhdl-project))
16320 (vhdl-scan-project-contents vhdl-project))
16321 (let ((directory (abbreviate-file-name default-directory)))
16322 (unless (or (assoc directory vhdl-file-alist)
16323 (vhdl-load-cache directory))
16324 (vhdl-scan-directory-contents directory))))
16325 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16326 (project (vhdl-project-p))
16327 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16328 (conf-alist (aget vhdl-config-alist (or project directory) t))
16329 (pack-alist (aget vhdl-package-alist (or project directory) t))
16330 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16331 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16332 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16333 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16334 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16335 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16336 (adjust-case (nth 5 regexp-list))
16337 (work-library (downcase (vhdl-work-library)))
16338 (compile-directory (expand-file-name (vhdl-compile-directory)
16339 default-directory))
16340 (makefile-name (vhdl-makefile-name))
16341 rule-alist arch-alist inst-alist
16342 target-list depend-list unit-list prim-list second-list subcomp-list
16343 lib-alist lib-body-alist pack-list all-pack-list
16344 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16345 conf-key conf-file-name pack-key pack-file-name
16346 ent-entry arch-entry conf-entry pack-entry inst-entry
16347 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16348 tmp-key tmp-list rule)
16349 ;; check prerequisites
16350 (unless (file-exists-p compile-directory)
16351 (make-directory compile-directory t))
16352 (unless regexp-list
16353 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16354 vhdl-compiler))
16355 (message "Generating makefile \"%s\"..." makefile-name)
16356 ;; rules for all entities
16357 (setq tmp-list ent-alist)
16358 (while ent-alist
16359 (setq ent-entry (car ent-alist)
16360 ent-key (nth 0 ent-entry))
16361 (when (nth 2 ent-entry)
16362 (setq ent-file-name (file-relative-name
16363 (nth 2 ent-entry) compile-directory)
16364 arch-alist (nth 4 ent-entry)
0a2e512a 16365 lib-alist (nth 6 ent-entry)
3dcb36b7
JB
16366 rule (aget rule-alist ent-file-name)
16367 target-list (nth 0 rule)
16368 depend-list (nth 1 rule)
16369 second-list nil
16370 subcomp-list nil)
16371 (setq tmp-key (vhdl-replace-string
16372 ent-regexp (funcall adjust-case ent-key)))
16373 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16374 ;; rule target for this entity
16375 (setq target-list (cons ent-key target-list))
16376 ;; rule dependencies for all used packages
16377 (setq pack-list (vhdl-get-packages lib-alist work-library))
16378 (setq depend-list (append depend-list pack-list))
16379 (setq all-pack-list pack-list)
16380 ;; add rule
16381 (aput 'rule-alist ent-file-name (list target-list depend-list))
16382 ;; rules for all corresponding architectures
16383 (while arch-alist
16384 (setq arch-entry (car arch-alist)
16385 arch-key (nth 0 arch-entry)
16386 ent-arch-key (concat ent-key "-" arch-key)
16387 arch-file-name (file-relative-name (nth 2 arch-entry)
16388 compile-directory)
16389 inst-alist (nth 4 arch-entry)
16390 lib-alist (nth 5 arch-entry)
16391 rule (aget rule-alist arch-file-name)
16392 target-list (nth 0 rule)
16393 depend-list (nth 1 rule))
16394 (setq tmp-key (vhdl-replace-string
16395 arch-regexp
16396 (funcall adjust-case (concat arch-key " " ent-key))))
16397 (setq unit-list
16398 (cons (cons ent-arch-key tmp-key) unit-list))
16399 (setq second-list (cons ent-arch-key second-list))
16400 ;; rule target for this architecture
16401 (setq target-list (cons ent-arch-key target-list))
16402 ;; rule dependency for corresponding entity
16403 (setq depend-list (cons ent-key depend-list))
16404 ;; rule dependencies for contained component instantiations
16405 (while inst-alist
16406 (setq inst-entry (car inst-alist))
16407 (when (or (null (nth 8 inst-entry))
16408 (equal (downcase (nth 8 inst-entry)) work-library))
16409 (setq inst-ent-key (or (nth 7 inst-entry)
16410 (nth 5 inst-entry)))
16411 (setq depend-list (cons inst-ent-key depend-list)
16412 subcomp-list (cons inst-ent-key subcomp-list)))
16413 (setq inst-alist (cdr inst-alist)))
16414 ;; rule dependencies for all used packages
16415 (setq pack-list (vhdl-get-packages lib-alist work-library))
16416 (setq depend-list (append depend-list pack-list))
16417 (setq all-pack-list (append all-pack-list pack-list))
16418 ;; add rule
16419 (aput 'rule-alist arch-file-name (list target-list depend-list))
16420 (setq arch-alist (cdr arch-alist)))
16421 (setq prim-list (cons (list ent-key second-list
16422 (append subcomp-list all-pack-list))
16423 prim-list)))
16424 (setq ent-alist (cdr ent-alist)))
16425 (setq ent-alist tmp-list)
16426 ;; rules for all configurations
16427 (setq tmp-list conf-alist)
16428 (while conf-alist
16429 (setq conf-entry (car conf-alist)
16430 conf-key (nth 0 conf-entry)
16431 conf-file-name (file-relative-name
16432 (nth 2 conf-entry) compile-directory)
16433 ent-key (nth 4 conf-entry)
16434 arch-key (nth 5 conf-entry)
16435 inst-alist (nth 6 conf-entry)
16436 lib-alist (nth 7 conf-entry)
16437 rule (aget rule-alist conf-file-name)
16438 target-list (nth 0 rule)
16439 depend-list (nth 1 rule)
16440 subcomp-list (list ent-key))
16441 (setq tmp-key (vhdl-replace-string
16442 conf-regexp (funcall adjust-case conf-key)))
16443 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16444 ;; rule target for this configuration
16445 (setq target-list (cons conf-key target-list))
16446 ;; rule dependency for corresponding entity and architecture
16447 (setq depend-list
16448 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16449 ;; rule dependencies for used packages
16450 (setq pack-list (vhdl-get-packages lib-alist work-library))
16451 (setq depend-list (append depend-list pack-list))
16452 ;; rule dependencies for contained component configurations
16453 (while inst-alist
16454 (setq inst-entry (car inst-alist))
16455 (setq inst-ent-key (nth 2 inst-entry)
16456; comp-arch-key (nth 2 inst-entry))
16457 inst-conf-key (nth 4 inst-entry))
16458 (when (equal (downcase (nth 5 inst-entry)) work-library)
16459 (when inst-ent-key
16460 (setq depend-list (cons inst-ent-key depend-list)
16461 subcomp-list (cons inst-ent-key subcomp-list)))
16462; (when comp-arch-key
16463; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16464; depend-list)))
16465 (when inst-conf-key
16466 (setq depend-list (cons inst-conf-key depend-list)
16467 subcomp-list (cons inst-conf-key subcomp-list))))
16468 (setq inst-alist (cdr inst-alist)))
16469 ;; add rule
16470 (aput 'rule-alist conf-file-name (list target-list depend-list))
16471 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16472 prim-list))
16473 (setq conf-alist (cdr conf-alist)))
16474 (setq conf-alist tmp-list)
16475 ;; rules for all packages
16476 (setq tmp-list pack-alist)
16477 (while pack-alist
16478 (setq pack-entry (car pack-alist)
16479 pack-key (nth 0 pack-entry)
16480 pack-body-key nil)
16481 (when (nth 2 pack-entry)
16482 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16483 compile-directory)
16484 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16485 rule (aget rule-alist pack-file-name)
16486 target-list (nth 0 rule) depend-list (nth 1 rule))
16487 (setq tmp-key (vhdl-replace-string
16488 pack-regexp (funcall adjust-case pack-key)))
16489 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16490 ;; rule target for this package
16491 (setq target-list (cons pack-key target-list))
16492 ;; rule dependencies for all used packages
16493 (setq pack-list (vhdl-get-packages lib-alist work-library))
16494 (setq depend-list (append depend-list pack-list))
16495 (setq all-pack-list pack-list)
16496 ;; add rule
16497 (aput 'rule-alist pack-file-name (list target-list depend-list))
16498 ;; rules for this package's body
16499 (when (nth 7 pack-entry)
16500 (setq pack-body-key (concat pack-key "-body")
16501 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16502 compile-directory)
16503 rule (aget rule-alist pack-body-file-name)
16504 target-list (nth 0 rule)
16505 depend-list (nth 1 rule))
16506 (setq tmp-key (vhdl-replace-string
16507 pack-body-regexp (funcall adjust-case pack-key)))
16508 (setq unit-list
16509 (cons (cons pack-body-key tmp-key) unit-list))
16510 ;; rule target for this package's body
16511 (setq target-list (cons pack-body-key target-list))
16512 ;; rule dependency for corresponding package declaration
16513 (setq depend-list (cons pack-key depend-list))
16514 ;; rule dependencies for all used packages
16515 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16516 (setq depend-list (append depend-list pack-list))
16517 (setq all-pack-list (append all-pack-list pack-list))
16518 ;; add rule
16519 (aput 'rule-alist pack-body-file-name
16520 (list target-list depend-list)))
16521 (setq prim-list
16522 (cons (list pack-key (when pack-body-key (list pack-body-key))
16523 all-pack-list)
16524 prim-list)))
16525 (setq pack-alist (cdr pack-alist)))
16526 (setq pack-alist tmp-list)
16527 ;; generate Makefile
16528 (let* ((project (aget vhdl-project-alist project))
16529 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16530 (compiler-id (nth 9 compiler))
16531 (library-directory
16532 (vhdl-resolve-env-variable
16533 (vhdl-replace-string
16534 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16535 compiler-id)))
16536 (makefile-path-name (expand-file-name
16537 makefile-name compile-directory))
16538 (orig-buffer (current-buffer))
16539 cell second-list subcomp-list options unit-key unit-name)
16540 ;; sort lists
16541 (setq unit-list (vhdl-sort-alist unit-list))
16542 (setq prim-list (vhdl-sort-alist prim-list))
16543 (setq tmp-list rule-alist)
16544 (while tmp-list ; pre-sort rule targets
16545 (setq cell (cdar tmp-list))
16546 (setcar cell (sort (car cell) 'string<))
16547 (setq tmp-list (cdr tmp-list)))
16548 (setq rule-alist ; sort by first rule target
16549 (sort rule-alist
16550 (function (lambda (a b)
16551 (string< (car (cadr a)) (car (cadr b)))))))
16552 ;; open and clear Makefile
16553 (set-buffer (find-file-noselect makefile-path-name t t))
16554 (erase-buffer)
16555 (insert "# -*- Makefile -*-\n"
16556 "### " (file-name-nondirectory makefile-name)
16557 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16558 "\n")
16559 (if project
16560 (insert "\n# Project : " (nth 0 project))
16561 (insert "\n# Directory : \"" directory "\""))
16562 (insert "\n# Platform : " vhdl-compiler
16563 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16564 (user-login-name) "\n")
16565 ;; insert compile and option variable settings
16566 (insert "\n\n# Define compilation command and options\n"
16567 "\nCOMPILE = " (nth 0 compiler)
16568 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16569 "\n")
16570 ;; insert library paths
16571 (setq library-directory
16572 (directory-file-name
16573 (if (file-name-absolute-p library-directory)
16574 library-directory
16575 (file-relative-name
16576 (expand-file-name library-directory directory)
16577 compile-directory))))
16578 (insert "\n\n# Define library paths\n"
16579 "\nLIBRARY-" work-library " = " library-directory "\n")
16580 ;; insert variable definitions for all library unit files
16581 (insert "\n\n# Define library unit files\n")
16582 (setq tmp-list unit-list)
16583 (while unit-list
16584 (insert "\nUNIT-" work-library "-" (caar unit-list)
16585 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16586 (setq unit-list (cdr unit-list)))
16587 ;; insert variable definition for list of all library unit files
16588 (insert "\n\n\n# Define list of all library unit files\n"
16589 "\nALL_UNITS =")
16590 (setq unit-list tmp-list)
16591 (while unit-list
16592 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16593 (setq unit-list (cdr unit-list)))
16594 (insert "\n")
16595 (setq unit-list tmp-list)
16596 ;; insert `make all' rule
16597 (insert "\n\n\n# Rule for compiling entire design\n"
16598 "\nall :"
16599 " \\\n\t\tlibrary"
16600 " \\\n\t\t$(ALL_UNITS)\n")
16601 ;; insert `make clean' rule
16602 (insert "\n\n# Rule for cleaning entire design\n"
16603 "\nclean : "
16604 "\n\t-rm -f $(ALL_UNITS)\n")
16605 ;; insert `make library' rule
16606 (insert "\n\n# Rule for creating library directory\n"
16607 "\nlibrary :"
16608 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16609 "\n$(LIBRARY-" work-library ") :"
16610 "\n\t"
16611 (vhdl-replace-string
16612 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16613 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16614 "\n")
16615 ;; insert rule for each library unit
16616 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16617 (while prim-list
16618 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16619 (setq subcomp-list
16620 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16621 (setq unit-key (caar prim-list)
16622 unit-name (or (nth 0 (aget ent-alist unit-key t))
16623 (nth 0 (aget conf-alist unit-key t))
16624 (nth 0 (aget pack-alist unit-key t))))
16625 (insert "\n" unit-key)
16626 (unless (equal unit-key unit-name)
16627 (insert " \\\n" unit-name))
16628 (insert " :"
16629 " \\\n\t\tlibrary"
16630 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16631 (while second-list
16632 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16633 (setq second-list (cdr second-list)))
16634 (while subcomp-list
0a2e512a
RF
16635 (when (and (assoc (car subcomp-list) unit-list)
16636 (not (equal unit-key (car subcomp-list))))
3dcb36b7
JB
16637 (insert " \\\n\t\t" (car subcomp-list)))
16638 (setq subcomp-list (cdr subcomp-list)))
16639 (insert "\n")
16640 (setq prim-list (cdr prim-list)))
16641 ;; insert rule for each library unit file
16642 (insert "\n\n# Rules for compiling single library unit files\n")
16643 (while rule-alist
16644 (setq rule (car rule-alist))
16645 ;; get compiler options for this file
16646 (setq options
16647 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16648 ;; insert rule if file is supposed to be compiled
16649 (setq target-list (nth 1 rule)
16650 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16651 ;; insert targets
16652 (setq tmp-list target-list)
16653 (while target-list
16654 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16655 (if (cdr target-list) " \\" " :"))
16656 (setq target-list (cdr target-list)))
16657 (setq target-list tmp-list)
16658 ;; insert file name as first dependency
16659 (insert " \\\n\t\t" (nth 0 rule))
16660 ;; insert dependencies (except if also target or unit does not exist)
16661 (while depend-list
16662 (when (and (not (member (car depend-list) target-list))
16663 (assoc (car depend-list) unit-list))
16664 (insert " \\\n\t\t"
16665 "$(UNIT-" work-library "-" (car depend-list) ")"))
16666 (setq depend-list (cdr depend-list)))
16667 ;; insert compile command
16668 (if options
16669 (insert "\n\t$(COMPILE) "
16670 (if (eq options 'default) "$(OPTIONS)" options) " "
16671 (nth 0 rule) "\n")
16672 (setq tmp-list target-list)
16673 (while target-list
16674 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16675 (if (cdr target-list) " \\" "\n"))
16676 (setq target-list (cdr target-list)))
16677 (setq target-list tmp-list))
16678 (setq rule-alist (cdr rule-alist)))
16679 (insert "\n\n### " makefile-name " ends here\n")
16680 ;; run Makefile generation hook
16681 (run-hooks 'vhdl-makefile-generation-hook)
16682 (message "Generating makefile \"%s\"...done" makefile-name)
16683 ;; save and close file
16684 (if (file-writable-p makefile-path-name)
16685 (progn (save-buffer)
16686 (kill-buffer (current-buffer))
16687 (set-buffer orig-buffer)
7cd80673 16688 (add-to-history 'file-name-history makefile-path-name))
3dcb36b7
JB
16689 (vhdl-warning-when-idle
16690 (format "File not writable: \"%s\""
16691 (abbreviate-file-name makefile-path-name)))
16692 (switch-to-buffer (current-buffer))))))
16693
5eabfe72
KH
16694
16695;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16696;;; Bug reports
16697;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16698;; (using `reporter.el')
16699
3dcb36b7
JB
16700(defconst vhdl-mode-help-address
16701 "Reto Zimmermann <reto@gnu.org>"
d2ddb974
KH
16702 "Address for VHDL Mode bug reports.")
16703
3dcb36b7
JB
16704(defun vhdl-submit-bug-report ()
16705 "Submit via mail a bug report on VHDL Mode."
16706 (interactive)
16707 ;; load in reporter
16708 (and
16709 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16710 (let ((reporter-prompt-for-summary-p t))
16711 (reporter-submit-bug-report
16712 vhdl-mode-help-address
16713 (concat "VHDL Mode " vhdl-version)
16714 (list
16715 ;; report all important user options
16716 'vhdl-offsets-alist
16717 'vhdl-comment-only-line-offset
16718 'tab-width
16719 'vhdl-electric-mode
16720 'vhdl-stutter-mode
16721 'vhdl-indent-tabs-mode
16722 'vhdl-project-alist
16723 'vhdl-project
16724 'vhdl-project-file-name
16725 'vhdl-project-auto-load
16726 'vhdl-project-sort
16727 'vhdl-compiler-alist
16728 'vhdl-compiler
16729 'vhdl-compile-use-local-error-regexp
16730 'vhdl-makefile-generation-hook
16731 'vhdl-default-library
16732 'vhdl-standard
16733 'vhdl-basic-offset
16734 'vhdl-upper-case-keywords
16735 'vhdl-upper-case-types
16736 'vhdl-upper-case-attributes
16737 'vhdl-upper-case-enum-values
16738 'vhdl-upper-case-constants
16739 'vhdl-use-direct-instantiation
0a2e512a 16740 'vhdl-compose-configuration-name
3dcb36b7
JB
16741 'vhdl-entity-file-name
16742 'vhdl-architecture-file-name
0a2e512a 16743 'vhdl-configuration-file-name
3dcb36b7
JB
16744 'vhdl-package-file-name
16745 'vhdl-file-name-case
16746 'vhdl-electric-keywords
16747 'vhdl-optional-labels
16748 'vhdl-insert-empty-lines
16749 'vhdl-argument-list-indent
16750 'vhdl-association-list-with-formals
16751 'vhdl-conditions-in-parenthesis
16752 'vhdl-zero-string
16753 'vhdl-one-string
16754 'vhdl-file-header
16755 'vhdl-file-footer
16756 'vhdl-company-name
16757 'vhdl-copyright-string
16758 'vhdl-platform-spec
16759 'vhdl-date-format
16760 'vhdl-modify-date-prefix-string
16761 'vhdl-modify-date-on-saving
16762 'vhdl-reset-kind
16763 'vhdl-reset-active-high
16764 'vhdl-clock-rising-edge
16765 'vhdl-clock-edge-condition
16766 'vhdl-clock-name
16767 'vhdl-reset-name
16768 'vhdl-model-alist
16769 'vhdl-include-port-comments
16770 'vhdl-include-direction-comments
16771 'vhdl-include-type-comments
16772 'vhdl-include-group-comments
16773 'vhdl-actual-port-name
16774 'vhdl-instance-name
16775 'vhdl-testbench-entity-name
16776 'vhdl-testbench-architecture-name
16777 'vhdl-testbench-configuration-name
16778 'vhdl-testbench-dut-name
16779 'vhdl-testbench-include-header
16780 'vhdl-testbench-declarations
16781 'vhdl-testbench-statements
16782 'vhdl-testbench-initialize-signals
16783 'vhdl-testbench-include-library
16784 'vhdl-testbench-include-configuration
16785 'vhdl-testbench-create-files
0a2e512a
RF
16786 'vhdl-testbench-entity-file-name
16787 'vhdl-testbench-architecture-file-name
3dcb36b7 16788 'vhdl-compose-create-files
0a2e512a
RF
16789 'vhdl-compose-configuration-create-file
16790 'vhdl-compose-configuration-hierarchical
16791 'vhdl-compose-configuration-use-subconfiguration
3dcb36b7
JB
16792 'vhdl-compose-include-header
16793 'vhdl-compose-architecture-name
16794 'vhdl-components-package-name
16795 'vhdl-use-components-package
16796 'vhdl-self-insert-comments
16797 'vhdl-prompt-for-comments
16798 'vhdl-inline-comment-column
16799 'vhdl-end-comment-column
16800 'vhdl-auto-align
16801 'vhdl-align-groups
16802 'vhdl-align-group-separate
16803 'vhdl-align-same-indent
16804 'vhdl-highlight-keywords
16805 'vhdl-highlight-names
16806 'vhdl-highlight-special-words
16807 'vhdl-highlight-forbidden-words
16808 'vhdl-highlight-verilog-keywords
16809 'vhdl-highlight-translate-off
16810 'vhdl-highlight-case-sensitive
16811 'vhdl-special-syntax-alist
16812 'vhdl-forbidden-words
16813 'vhdl-forbidden-syntax
16814 'vhdl-directive-keywords
16815 'vhdl-speedbar-auto-open
16816 'vhdl-speedbar-display-mode
16817 'vhdl-speedbar-scan-limit
16818 'vhdl-speedbar-jump-to-unit
16819 'vhdl-speedbar-update-on-saving
16820 'vhdl-speedbar-save-cache
16821 'vhdl-speedbar-cache-file-name
16822 'vhdl-index-menu
16823 'vhdl-source-file-menu
16824 'vhdl-hideshow-menu
16825 'vhdl-hide-all-init
16826 'vhdl-print-two-column
16827 'vhdl-print-customize-faces
16828 'vhdl-intelligent-tab
16829 'vhdl-indent-syntax-based
16830 'vhdl-word-completion-case-sensitive
16831 'vhdl-word-completion-in-minibuffer
16832 'vhdl-underscore-is-part-of-word
16833 'vhdl-mode-hook)
16834 (function
16835 (lambda ()
16836 (insert
16837 (if vhdl-special-indent-hook
16838 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16839 "vhdl-special-indent-hook is set to '"
16840 (format "%s" vhdl-special-indent-hook)
16841 ".\nPerhaps this is your problem?\n"
16842 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16843 "\n"))))
16844 nil
16845 "Hi Reto,"))))
16846
16847
16848;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16849;;; Documentation
16850;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16851
16852(defconst vhdl-doc-release-notes nil
16853 "\
0a2e512a 16854Release Notes for VHDL Mode 3.33
3dcb36b7
JB
16855================================
16856
16857 - New Features
3dcb36b7 16858 - User Options
3dcb36b7
JB
16859
16860
16861New Features
16862------------
16863
0a2e512a
RF
16864CONFIGURATION DECLARATION GENERATION:
16865 - Automatic generation of a configuration declaration for a design.
16866 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
3dcb36b7
JB
16867
16868
16869User Options
16870------------
16871
0a2e512a
RF
16872`vhdl-configuration-file-name': (new)
16873 Specify how the configuration file name is obtained.
16874`vhdl-compose-configuration-name': (new)
16875 Specify how the configuration name is optained.
16876`vhdl-compose-configuration-create-file': (new)
16877 Specify whether a new file should be created for a configuration.
16878`vhdl-compose-configuration-hierarchical': (new)
16879 Specify whether hierarchical configurations should be created.
16880`vhdl-compose-configuration-use-subconfiguration': (new)
16881 Specify whether subconfigurations should be used inside configurations.
3dcb36b7
JB
16882")
16883
16884
16885(defconst vhdl-doc-keywords nil
16886 "\
16887Reserved words in VHDL
16888----------------------
16889
16890VHDL'93 (IEEE Std 1076-1993):
16891 `vhdl-93-keywords' : keywords
16892 `vhdl-93-types' : standardized types
16893 `vhdl-93-attributes' : standardized attributes
16894 `vhdl-93-enum-values' : standardized enumeration values
16895 `vhdl-93-functions' : standardized functions
16896 `vhdl-93-packages' : standardized packages and libraries
16897
16898VHDL-AMS (IEEE Std 1076.1):
16899 `vhdl-ams-keywords' : keywords
16900 `vhdl-ams-types' : standardized types
16901 `vhdl-ams-attributes' : standardized attributes
16902 `vhdl-ams-enum-values' : standardized enumeration values
16903 `vhdl-ams-functions' : standardized functions
16904
16905Math Packages (IEEE Std 1076.2):
16906 `vhdl-math-types' : standardized types
16907 `vhdl-math-constants' : standardized constants
16908 `vhdl-math-functions' : standardized functions
16909 `vhdl-math-packages' : standardized packages
16910
16911Forbidden words:
16912 `vhdl-verilog-keywords' : Verilog reserved words
16913
16914NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16915
16916
16917(defconst vhdl-doc-coding-style nil
16918 "\
16919For VHDL coding style and naming convention guidelines, see the following
16920references:
16921
16922\[1] Ben Cohen.
16923 \"VHDL Coding Styles and Methodologies\".
16924 Kluwer Academic Publishers, 1999.
16925 http://members.aol.com/vhdlcohen/vhdl/
16926
16927\[2] Michael Keating and Pierre Bricaud.
16928 \"Reuse Methodology Manual, Second Edition\".
16929 Kluwer Academic Publishers, 1999.
16930 http://www.openmore.com/openmore/rmm2.html
16931
16932\[3] European Space Agency.
16933 \"VHDL Modelling Guidelines\".
16934 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16935
16936Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16937to visually support naming conventions.")
16938
16939
d2ddb974
KH
16940(defun vhdl-version ()
16941 "Echo the current version of VHDL Mode in the minibuffer."
16942 (interactive)
3dcb36b7 16943 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
d2ddb974
KH
16944 (vhdl-keep-region-active))
16945
3dcb36b7
JB
16946(defun vhdl-doc-variable (variable)
16947 "Display VARIABLE's documentation in *Help* buffer."
16948 (interactive)
f8246027 16949 (unless (featurep 'xemacs)
4bcb9c95 16950 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
0a2e512a
RF
16951 (with-output-to-temp-buffer
16952 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7 16953 (princ (documentation-property variable 'variable-documentation))
4bcb9c95 16954 (with-current-buffer standard-output
3dcb36b7 16955 (help-mode))
d5d105e8 16956 (help-print-return-message)))
d2ddb974 16957
3dcb36b7
JB
16958(defun vhdl-doc-mode ()
16959 "Display VHDL Mode documentation in *Help* buffer."
d2ddb974 16960 (interactive)
f8246027 16961 (unless (featurep 'xemacs)
4bcb9c95 16962 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
0a2e512a
RF
16963 (with-output-to-temp-buffer
16964 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7
JB
16965 (princ mode-name)
16966 (princ " mode:\n")
16967 (princ (documentation 'vhdl-mode))
4bcb9c95 16968 (with-current-buffer standard-output
3dcb36b7 16969 (help-mode))
d5d105e8 16970 (help-print-return-message)))
d2ddb974
KH
16971
16972
5eabfe72 16973;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16974
16975(provide 'vhdl-mode)
16976
16977;;; vhdl-mode.el ends here